file_name
stringlengths 5
52
| name
stringlengths 4
95
| original_source_type
stringlengths 0
23k
| source_type
stringlengths 9
23k
| source_definition
stringlengths 9
57.9k
| source
dict | source_range
dict | file_context
stringlengths 0
721k
| dependencies
dict | opens_and_abbrevs
listlengths 2
94
| vconfig
dict | interleaved
bool 1
class | verbose_type
stringlengths 1
7.42k
| effect
stringclasses 118
values | effect_flags
sequencelengths 0
2
| mutual_with
sequencelengths 0
11
| ideal_premises
sequencelengths 0
236
| proof_features
sequencelengths 0
1
| is_simple_lemma
bool 2
classes | is_div
bool 2
classes | is_proof
bool 2
classes | is_simply_typed
bool 2
classes | is_type
bool 2
classes | partial_definition
stringlengths 5
3.99k
| completed_definiton
stringlengths 1
1.63M
| isa_cross_project_example
bool 1
class |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Hacl.Spec.K256.PrecompTable.fst | Hacl.Spec.K256.PrecompTable.create5_lseq | val create5_lseq (x0 x1 x2 x3 x4: uint64) : lseq uint64 5 | val create5_lseq (x0 x1 x2 x3 x4: uint64) : lseq uint64 5 | let create5_lseq (x0 x1 x2 x3 x4:uint64) : lseq uint64 5 =
let l = [x0; x1; x2; x3; x4] in
assert_norm (FL.length l = 5);
Seq.seq_of_list l | {
"file_name": "code/k256/Hacl.Spec.K256.PrecompTable.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 19,
"end_line": 19,
"start_col": 0,
"start_line": 16
} | module Hacl.Spec.K256.PrecompTable
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Hacl.Spec.K256.Field52.Definitions
open Hacl.Impl.K256.Point
module S = Spec.K256
module FL = FStar.List.Tot
module SPT = Hacl.Spec.PrecompBaseTable
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0" | {
"checked_file": "/",
"dependencies": [
"Spec.K256.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.PrecompBaseTable.fsti.checked",
"Hacl.Spec.K256.Field52.Definitions.fst.checked",
"Hacl.Impl.K256.Point.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.Spec.K256.PrecompTable.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.PrecompBaseTable",
"short_module": "SPT"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FL"
},
{
"abbrev": true,
"full_module": "Spec.K256",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256.Point",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256.Field52.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FL"
},
{
"abbrev": true,
"full_module": "Spec.K256",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256.Point",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256.Field52.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
x0: Lib.IntTypes.uint64 ->
x1: Lib.IntTypes.uint64 ->
x2: Lib.IntTypes.uint64 ->
x3: Lib.IntTypes.uint64 ->
x4: Lib.IntTypes.uint64
-> Lib.Sequence.lseq Lib.IntTypes.uint64 5 | Prims.Tot | [
"total"
] | [] | [
"Lib.IntTypes.uint64",
"FStar.Seq.Base.seq_of_list",
"Prims.unit",
"FStar.Pervasives.assert_norm",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"FStar.List.Tot.Base.length",
"Prims.list",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U64",
"Lib.IntTypes.SEC",
"Prims.Cons",
"Prims.Nil",
"Lib.Sequence.lseq"
] | [] | false | false | false | false | false | let create5_lseq (x0 x1 x2 x3 x4: uint64) : lseq uint64 5 =
| let l = [x0; x1; x2; x3; x4] in
assert_norm (FL.length l = 5);
Seq.seq_of_list l | false |
Hacl.Spec.K256.PrecompTable.fst | Hacl.Spec.K256.PrecompTable.lemma_mod_pow2_sub | val lemma_mod_pow2_sub: x:nat -> a:nat -> b:nat ->
Lemma (x / pow2 a % pow2 b * pow2 a == x % pow2 (a + b) - x % pow2 a) | val lemma_mod_pow2_sub: x:nat -> a:nat -> b:nat ->
Lemma (x / pow2 a % pow2 b * pow2 a == x % pow2 (a + b) - x % pow2 a) | let lemma_mod_pow2_sub x a b =
calc (==) {
x / pow2 a % pow2 b * pow2 a;
(==) { Math.Lemmas.pow2_modulo_division_lemma_1 x a (a + b) }
x % pow2 (a + b) / pow2 a * pow2 a;
(==) { Math.Lemmas.euclidean_division_definition (x % pow2 (a + b)) (pow2 a) }
x % pow2 (a + b) - x % pow2 (a + b) % pow2 a;
(==) { Math.Lemmas.pow2_modulo_modulo_lemma_1 x a (a + b) }
x % pow2 (a + b) - x % pow2 a;
} | {
"file_name": "code/k256/Hacl.Spec.K256.PrecompTable.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 3,
"end_line": 88,
"start_col": 0,
"start_line": 79
} | module Hacl.Spec.K256.PrecompTable
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Hacl.Spec.K256.Field52.Definitions
open Hacl.Impl.K256.Point
module S = Spec.K256
module FL = FStar.List.Tot
module SPT = Hacl.Spec.PrecompBaseTable
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let create5_lseq (x0 x1 x2 x3 x4:uint64) : lseq uint64 5 =
let l = [x0; x1; x2; x3; x4] in
assert_norm (FL.length l = 5);
Seq.seq_of_list l
val create5_lemma (x0 x1 x2 x3 x4:uint64) :
Lemma (let s = create5_lseq x0 x1 x2 x3 x4 in
s.[0] == x0 /\ s.[1] == x1 /\ s.[2] == x2 /\ s.[3] == x3 /\ s.[4] == x4)
let create5_lemma x0 x1 x2 x3 x4 =
Seq.elim_of_list [x0; x1; x2; x3; x4]
//-----------------------------------
noextract
let list_as_felem5 (f:felem_list) : felem5 =
let x = Seq.seq_of_list f <: lseq uint64 5 in
as_felem5_lseq x
val felem_to_list_index_lemma: x:S.felem ->
Lemma (let (f0, f1, f2, f3, f4) = list_as_felem5 (felem_to_list x) in
let x0 = x % pow52 in
let x1 = x / pow52 % pow52 in
let x2 = x / pow104 % pow52 in
let x3 = x / pow156 % pow52 in
let x4 = x / pow208 in
v f0 == x0 /\ v f1 == x1 /\ v f2 == x2 /\ v f3 == x3 /\ v f4 == x4)
let felem_to_list_index_lemma x =
let x0 = x % pow52 in
let x1 = x / pow52 % pow52 in
let x2 = x / pow104 % pow52 in
let x3 = x / pow156 % pow52 in
let x4 = x / pow208 in
let f = felem_to_list x in
let (f0, f1, f2, f3, f4) = list_as_felem5 f in
create5_lemma (u64 x0) (u64 x1) (u64 x2) (u64 x3) (u64 x4);
assert (v f0 == x0 /\ v f1 == x1 /\ v f2 == x2 /\ v f3 == x3 /\ v f4 == x4)
val felem_to_list_lemma_fits: x:S.felem ->
Lemma (felem_fits5 (list_as_felem5 (felem_to_list x)) (1, 1, 1, 1, 1))
let felem_to_list_lemma_fits x =
felem_to_list_index_lemma x;
let x0 = x % pow52 in
let x1 = x / pow52 % pow52 in
let x2 = x / pow104 % pow52 in
let x3 = x / pow156 % pow52 in
let x4 = x / pow208 in
assert (felem_fits1 (u64 x0) 1);
assert (felem_fits1 (u64 x1) 1);
assert (felem_fits1 (u64 x2) 1);
assert (felem_fits1 (u64 x3) 1);
Math.Lemmas.lemma_div_lt_nat x 256 208;
assert (felem_fits_last1 (u64 x4) 1)
val lemma_mod_pow2_sub: x:nat -> a:nat -> b:nat ->
Lemma (x / pow2 a % pow2 b * pow2 a == x % pow2 (a + b) - x % pow2 a) | {
"checked_file": "/",
"dependencies": [
"Spec.K256.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.PrecompBaseTable.fsti.checked",
"Hacl.Spec.K256.Field52.Definitions.fst.checked",
"Hacl.Impl.K256.Point.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.Spec.K256.PrecompTable.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.PrecompBaseTable",
"short_module": "SPT"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FL"
},
{
"abbrev": true,
"full_module": "Spec.K256",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256.Point",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256.Field52.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FL"
},
{
"abbrev": true,
"full_module": "Spec.K256",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256.Point",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256.Field52.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: Prims.nat -> a: Prims.nat -> b: Prims.nat
-> FStar.Pervasives.Lemma
(ensures
(x / Prims.pow2 a % Prims.pow2 b) * Prims.pow2 a == x % Prims.pow2 (a + b) - x % Prims.pow2 a) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.nat",
"FStar.Calc.calc_finish",
"Prims.int",
"Prims.eq2",
"FStar.Mul.op_Star",
"Prims.op_Modulus",
"Prims.op_Division",
"Prims.pow2",
"Prims.op_Subtraction",
"Prims.op_Addition",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"Prims.unit",
"FStar.Calc.calc_step",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"FStar.Math.Lemmas.pow2_modulo_division_lemma_1",
"Prims.squash",
"FStar.Math.Lemmas.euclidean_division_definition",
"FStar.Math.Lemmas.pow2_modulo_modulo_lemma_1"
] | [] | false | false | true | false | false | let lemma_mod_pow2_sub x a b =
| calc ( == ) {
(x / pow2 a % pow2 b) * pow2 a;
( == ) { Math.Lemmas.pow2_modulo_division_lemma_1 x a (a + b) }
(x % pow2 (a + b) / pow2 a) * pow2 a;
( == ) { Math.Lemmas.euclidean_division_definition (x % pow2 (a + b)) (pow2 a) }
x % pow2 (a + b) - x % pow2 (a + b) % pow2 a;
( == ) { Math.Lemmas.pow2_modulo_modulo_lemma_1 x a (a + b) }
x % pow2 (a + b) - x % pow2 a;
} | false |
Hacl.Spec.K256.PrecompTable.fst | Hacl.Spec.K256.PrecompTable.list_as_felem5 | val list_as_felem5 (f: felem_list) : felem5 | val list_as_felem5 (f: felem_list) : felem5 | let list_as_felem5 (f:felem_list) : felem5 =
let x = Seq.seq_of_list f <: lseq uint64 5 in
as_felem5_lseq x | {
"file_name": "code/k256/Hacl.Spec.K256.PrecompTable.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 18,
"end_line": 33,
"start_col": 0,
"start_line": 31
} | module Hacl.Spec.K256.PrecompTable
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Hacl.Spec.K256.Field52.Definitions
open Hacl.Impl.K256.Point
module S = Spec.K256
module FL = FStar.List.Tot
module SPT = Hacl.Spec.PrecompBaseTable
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let create5_lseq (x0 x1 x2 x3 x4:uint64) : lseq uint64 5 =
let l = [x0; x1; x2; x3; x4] in
assert_norm (FL.length l = 5);
Seq.seq_of_list l
val create5_lemma (x0 x1 x2 x3 x4:uint64) :
Lemma (let s = create5_lseq x0 x1 x2 x3 x4 in
s.[0] == x0 /\ s.[1] == x1 /\ s.[2] == x2 /\ s.[3] == x3 /\ s.[4] == x4)
let create5_lemma x0 x1 x2 x3 x4 =
Seq.elim_of_list [x0; x1; x2; x3; x4]
//----------------------------------- | {
"checked_file": "/",
"dependencies": [
"Spec.K256.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.PrecompBaseTable.fsti.checked",
"Hacl.Spec.K256.Field52.Definitions.fst.checked",
"Hacl.Impl.K256.Point.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.Spec.K256.PrecompTable.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.PrecompBaseTable",
"short_module": "SPT"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FL"
},
{
"abbrev": true,
"full_module": "Spec.K256",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256.Point",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256.Field52.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FL"
},
{
"abbrev": true,
"full_module": "Spec.K256",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256.Point",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256.Field52.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | f: Hacl.Spec.K256.PrecompTable.felem_list -> Hacl.Spec.K256.Field52.Definitions.felem5 | Prims.Tot | [
"total"
] | [] | [
"Hacl.Spec.K256.PrecompTable.felem_list",
"Hacl.Impl.K256.Point.as_felem5_lseq",
"Lib.Sequence.lseq",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U64",
"Lib.IntTypes.SEC",
"FStar.Seq.Base.seq_of_list",
"Lib.IntTypes.uint64",
"Hacl.Spec.K256.Field52.Definitions.felem5"
] | [] | false | false | false | true | false | let list_as_felem5 (f: felem_list) : felem5 =
| let x = Seq.seq_of_list f <: lseq uint64 5 in
as_felem5_lseq x | false |
Hacl.Spec.K256.PrecompTable.fst | Hacl.Spec.K256.PrecompTable.felem_to_list_index_lemma | val felem_to_list_index_lemma: x:S.felem ->
Lemma (let (f0, f1, f2, f3, f4) = list_as_felem5 (felem_to_list x) in
let x0 = x % pow52 in
let x1 = x / pow52 % pow52 in
let x2 = x / pow104 % pow52 in
let x3 = x / pow156 % pow52 in
let x4 = x / pow208 in
v f0 == x0 /\ v f1 == x1 /\ v f2 == x2 /\ v f3 == x3 /\ v f4 == x4) | val felem_to_list_index_lemma: x:S.felem ->
Lemma (let (f0, f1, f2, f3, f4) = list_as_felem5 (felem_to_list x) in
let x0 = x % pow52 in
let x1 = x / pow52 % pow52 in
let x2 = x / pow104 % pow52 in
let x3 = x / pow156 % pow52 in
let x4 = x / pow208 in
v f0 == x0 /\ v f1 == x1 /\ v f2 == x2 /\ v f3 == x3 /\ v f4 == x4) | let felem_to_list_index_lemma x =
let x0 = x % pow52 in
let x1 = x / pow52 % pow52 in
let x2 = x / pow104 % pow52 in
let x3 = x / pow156 % pow52 in
let x4 = x / pow208 in
let f = felem_to_list x in
let (f0, f1, f2, f3, f4) = list_as_felem5 f in
create5_lemma (u64 x0) (u64 x1) (u64 x2) (u64 x3) (u64 x4);
assert (v f0 == x0 /\ v f1 == x1 /\ v f2 == x2 /\ v f3 == x3 /\ v f4 == x4) | {
"file_name": "code/k256/Hacl.Spec.K256.PrecompTable.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 77,
"end_line": 55,
"start_col": 0,
"start_line": 45
} | module Hacl.Spec.K256.PrecompTable
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Hacl.Spec.K256.Field52.Definitions
open Hacl.Impl.K256.Point
module S = Spec.K256
module FL = FStar.List.Tot
module SPT = Hacl.Spec.PrecompBaseTable
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let create5_lseq (x0 x1 x2 x3 x4:uint64) : lseq uint64 5 =
let l = [x0; x1; x2; x3; x4] in
assert_norm (FL.length l = 5);
Seq.seq_of_list l
val create5_lemma (x0 x1 x2 x3 x4:uint64) :
Lemma (let s = create5_lseq x0 x1 x2 x3 x4 in
s.[0] == x0 /\ s.[1] == x1 /\ s.[2] == x2 /\ s.[3] == x3 /\ s.[4] == x4)
let create5_lemma x0 x1 x2 x3 x4 =
Seq.elim_of_list [x0; x1; x2; x3; x4]
//-----------------------------------
noextract
let list_as_felem5 (f:felem_list) : felem5 =
let x = Seq.seq_of_list f <: lseq uint64 5 in
as_felem5_lseq x
val felem_to_list_index_lemma: x:S.felem ->
Lemma (let (f0, f1, f2, f3, f4) = list_as_felem5 (felem_to_list x) in
let x0 = x % pow52 in
let x1 = x / pow52 % pow52 in
let x2 = x / pow104 % pow52 in
let x3 = x / pow156 % pow52 in
let x4 = x / pow208 in
v f0 == x0 /\ v f1 == x1 /\ v f2 == x2 /\ v f3 == x3 /\ v f4 == x4) | {
"checked_file": "/",
"dependencies": [
"Spec.K256.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.PrecompBaseTable.fsti.checked",
"Hacl.Spec.K256.Field52.Definitions.fst.checked",
"Hacl.Impl.K256.Point.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.Spec.K256.PrecompTable.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.PrecompBaseTable",
"short_module": "SPT"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FL"
},
{
"abbrev": true,
"full_module": "Spec.K256",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256.Point",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256.Field52.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FL"
},
{
"abbrev": true,
"full_module": "Spec.K256",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256.Point",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256.Field52.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: Spec.K256.PointOps.felem
-> FStar.Pervasives.Lemma
(ensures
(let _ =
Hacl.Spec.K256.PrecompTable.list_as_felem5 (Hacl.Spec.K256.PrecompTable.felem_to_list x)
in
(let FStar.Pervasives.Native.Mktuple5 #_ #_ #_ #_ #_ f0 f1 f2 f3 f4 = _ in
let x0 = x % Hacl.Spec.K256.Field52.Definitions.pow52 in
let x1 =
x / Hacl.Spec.K256.Field52.Definitions.pow52 % Hacl.Spec.K256.Field52.Definitions.pow52
in
let x2 =
x / Hacl.Spec.K256.Field52.Definitions.pow104 % Hacl.Spec.K256.Field52.Definitions.pow52
in
let x3 =
x / Hacl.Spec.K256.Field52.Definitions.pow156 % Hacl.Spec.K256.Field52.Definitions.pow52
in
let x4 = x / Hacl.Spec.K256.Field52.Definitions.pow208 in
Lib.IntTypes.v f0 == x0 /\ Lib.IntTypes.v f1 == x1 /\ Lib.IntTypes.v f2 == x2 /\
Lib.IntTypes.v f3 == x3 /\ Lib.IntTypes.v f4 == x4)
<:
Type0)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Spec.K256.PointOps.felem",
"Lib.IntTypes.uint64",
"Prims._assert",
"Prims.l_and",
"Prims.eq2",
"Prims.int",
"Lib.IntTypes.v",
"Lib.IntTypes.U64",
"Lib.IntTypes.SEC",
"Prims.unit",
"Hacl.Spec.K256.PrecompTable.create5_lemma",
"Lib.IntTypes.u64",
"Hacl.Spec.K256.Field52.Definitions.felem5",
"Hacl.Spec.K256.PrecompTable.list_as_felem5",
"Hacl.Spec.K256.PrecompTable.felem_list",
"Hacl.Spec.K256.PrecompTable.felem_to_list",
"Prims.op_Division",
"Hacl.Spec.K256.Field52.Definitions.pow208",
"Prims.op_Modulus",
"Hacl.Spec.K256.Field52.Definitions.pow156",
"Hacl.Spec.K256.Field52.Definitions.pow52",
"Hacl.Spec.K256.Field52.Definitions.pow104"
] | [] | false | false | true | false | false | let felem_to_list_index_lemma x =
| let x0 = x % pow52 in
let x1 = x / pow52 % pow52 in
let x2 = x / pow104 % pow52 in
let x3 = x / pow156 % pow52 in
let x4 = x / pow208 in
let f = felem_to_list x in
let f0, f1, f2, f3, f4 = list_as_felem5 f in
create5_lemma (u64 x0) (u64 x1) (u64 x2) (u64 x3) (u64 x4);
assert (v f0 == x0 /\ v f1 == x1 /\ v f2 == x2 /\ v f3 == x3 /\ v f4 == x4) | false |
Hacl.Spec.K256.PrecompTable.fst | Hacl.Spec.K256.PrecompTable.felem_to_list_lemma_fits | val felem_to_list_lemma_fits: x:S.felem ->
Lemma (felem_fits5 (list_as_felem5 (felem_to_list x)) (1, 1, 1, 1, 1)) | val felem_to_list_lemma_fits: x:S.felem ->
Lemma (felem_fits5 (list_as_felem5 (felem_to_list x)) (1, 1, 1, 1, 1)) | let felem_to_list_lemma_fits x =
felem_to_list_index_lemma x;
let x0 = x % pow52 in
let x1 = x / pow52 % pow52 in
let x2 = x / pow104 % pow52 in
let x3 = x / pow156 % pow52 in
let x4 = x / pow208 in
assert (felem_fits1 (u64 x0) 1);
assert (felem_fits1 (u64 x1) 1);
assert (felem_fits1 (u64 x2) 1);
assert (felem_fits1 (u64 x3) 1);
Math.Lemmas.lemma_div_lt_nat x 256 208;
assert (felem_fits_last1 (u64 x4) 1) | {
"file_name": "code/k256/Hacl.Spec.K256.PrecompTable.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 38,
"end_line": 73,
"start_col": 0,
"start_line": 61
} | module Hacl.Spec.K256.PrecompTable
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Hacl.Spec.K256.Field52.Definitions
open Hacl.Impl.K256.Point
module S = Spec.K256
module FL = FStar.List.Tot
module SPT = Hacl.Spec.PrecompBaseTable
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let create5_lseq (x0 x1 x2 x3 x4:uint64) : lseq uint64 5 =
let l = [x0; x1; x2; x3; x4] in
assert_norm (FL.length l = 5);
Seq.seq_of_list l
val create5_lemma (x0 x1 x2 x3 x4:uint64) :
Lemma (let s = create5_lseq x0 x1 x2 x3 x4 in
s.[0] == x0 /\ s.[1] == x1 /\ s.[2] == x2 /\ s.[3] == x3 /\ s.[4] == x4)
let create5_lemma x0 x1 x2 x3 x4 =
Seq.elim_of_list [x0; x1; x2; x3; x4]
//-----------------------------------
noextract
let list_as_felem5 (f:felem_list) : felem5 =
let x = Seq.seq_of_list f <: lseq uint64 5 in
as_felem5_lseq x
val felem_to_list_index_lemma: x:S.felem ->
Lemma (let (f0, f1, f2, f3, f4) = list_as_felem5 (felem_to_list x) in
let x0 = x % pow52 in
let x1 = x / pow52 % pow52 in
let x2 = x / pow104 % pow52 in
let x3 = x / pow156 % pow52 in
let x4 = x / pow208 in
v f0 == x0 /\ v f1 == x1 /\ v f2 == x2 /\ v f3 == x3 /\ v f4 == x4)
let felem_to_list_index_lemma x =
let x0 = x % pow52 in
let x1 = x / pow52 % pow52 in
let x2 = x / pow104 % pow52 in
let x3 = x / pow156 % pow52 in
let x4 = x / pow208 in
let f = felem_to_list x in
let (f0, f1, f2, f3, f4) = list_as_felem5 f in
create5_lemma (u64 x0) (u64 x1) (u64 x2) (u64 x3) (u64 x4);
assert (v f0 == x0 /\ v f1 == x1 /\ v f2 == x2 /\ v f3 == x3 /\ v f4 == x4)
val felem_to_list_lemma_fits: x:S.felem ->
Lemma (felem_fits5 (list_as_felem5 (felem_to_list x)) (1, 1, 1, 1, 1)) | {
"checked_file": "/",
"dependencies": [
"Spec.K256.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.PrecompBaseTable.fsti.checked",
"Hacl.Spec.K256.Field52.Definitions.fst.checked",
"Hacl.Impl.K256.Point.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.Spec.K256.PrecompTable.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.PrecompBaseTable",
"short_module": "SPT"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FL"
},
{
"abbrev": true,
"full_module": "Spec.K256",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256.Point",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256.Field52.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FL"
},
{
"abbrev": true,
"full_module": "Spec.K256",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256.Point",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256.Field52.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: Spec.K256.PointOps.felem
-> FStar.Pervasives.Lemma
(ensures
Hacl.Spec.K256.Field52.Definitions.felem_fits5 (Hacl.Spec.K256.PrecompTable.list_as_felem5 (Hacl.Spec.K256.PrecompTable.felem_to_list
x))
(1,
1,
1,
1,
1)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Spec.K256.PointOps.felem",
"Prims._assert",
"Prims.b2t",
"Hacl.Spec.K256.Field52.Definitions.felem_fits_last1",
"Lib.IntTypes.u64",
"Prims.unit",
"FStar.Math.Lemmas.lemma_div_lt_nat",
"Hacl.Spec.K256.Field52.Definitions.felem_fits1",
"Prims.int",
"Prims.op_Division",
"Hacl.Spec.K256.Field52.Definitions.pow208",
"Prims.op_Modulus",
"Hacl.Spec.K256.Field52.Definitions.pow156",
"Hacl.Spec.K256.Field52.Definitions.pow52",
"Hacl.Spec.K256.Field52.Definitions.pow104",
"Hacl.Spec.K256.PrecompTable.felem_to_list_index_lemma"
] | [] | true | false | true | false | false | let felem_to_list_lemma_fits x =
| felem_to_list_index_lemma x;
let x0 = x % pow52 in
let x1 = x / pow52 % pow52 in
let x2 = x / pow104 % pow52 in
let x3 = x / pow156 % pow52 in
let x4 = x / pow208 in
assert (felem_fits1 (u64 x0) 1);
assert (felem_fits1 (u64 x1) 1);
assert (felem_fits1 (u64 x2) 1);
assert (felem_fits1 (u64 x3) 1);
Math.Lemmas.lemma_div_lt_nat x 256 208;
assert (felem_fits_last1 (u64 x4) 1) | false |
LowParse.Spec.Int.fst | LowParse.Spec.Int.tot_parse_u8 | val tot_parse_u8: tot_parser parse_u8_kind U8.t | val tot_parse_u8: tot_parser parse_u8_kind U8.t | let tot_parse_u8 =
decode_u8_injective ();
tot_make_total_constant_size_parser 1 U8.t decode_u8 | {
"file_name": "src/lowparse/LowParse.Spec.Int.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 54,
"end_line": 15,
"start_col": 0,
"start_line": 13
} | module LowParse.Spec.Int
open LowParse.Spec.Combinators
let decode_u8
(b: bytes { Seq.length b == 1 } )
: Tot U8.t
= Seq.index b 0
let decode_u8_injective () : Lemma
(make_total_constant_size_parser_precond 1 U8.t decode_u8)
= () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Seq.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "LowParse.Spec.Int.fst"
} | [
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.Endianness",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | LowParse.Spec.Base.tot_parser LowParse.Spec.Int.parse_u8_kind FStar.UInt8.t | Prims.Tot | [
"total"
] | [] | [
"LowParse.Spec.Combinators.tot_make_total_constant_size_parser",
"FStar.UInt8.t",
"LowParse.Spec.Int.decode_u8",
"Prims.unit",
"LowParse.Spec.Int.decode_u8_injective"
] | [] | false | false | false | true | false | let tot_parse_u8 =
| decode_u8_injective ();
tot_make_total_constant_size_parser 1 U8.t decode_u8 | false |
Hacl.Spec.K256.PrecompTable.fst | Hacl.Spec.K256.PrecompTable.create5_lemma | val create5_lemma (x0 x1 x2 x3 x4:uint64) :
Lemma (let s = create5_lseq x0 x1 x2 x3 x4 in
s.[0] == x0 /\ s.[1] == x1 /\ s.[2] == x2 /\ s.[3] == x3 /\ s.[4] == x4) | val create5_lemma (x0 x1 x2 x3 x4:uint64) :
Lemma (let s = create5_lseq x0 x1 x2 x3 x4 in
s.[0] == x0 /\ s.[1] == x1 /\ s.[2] == x2 /\ s.[3] == x3 /\ s.[4] == x4) | let create5_lemma x0 x1 x2 x3 x4 =
Seq.elim_of_list [x0; x1; x2; x3; x4] | {
"file_name": "code/k256/Hacl.Spec.K256.PrecompTable.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 39,
"end_line": 26,
"start_col": 0,
"start_line": 25
} | module Hacl.Spec.K256.PrecompTable
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Hacl.Spec.K256.Field52.Definitions
open Hacl.Impl.K256.Point
module S = Spec.K256
module FL = FStar.List.Tot
module SPT = Hacl.Spec.PrecompBaseTable
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let create5_lseq (x0 x1 x2 x3 x4:uint64) : lseq uint64 5 =
let l = [x0; x1; x2; x3; x4] in
assert_norm (FL.length l = 5);
Seq.seq_of_list l
val create5_lemma (x0 x1 x2 x3 x4:uint64) :
Lemma (let s = create5_lseq x0 x1 x2 x3 x4 in | {
"checked_file": "/",
"dependencies": [
"Spec.K256.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.PrecompBaseTable.fsti.checked",
"Hacl.Spec.K256.Field52.Definitions.fst.checked",
"Hacl.Impl.K256.Point.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.Spec.K256.PrecompTable.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.PrecompBaseTable",
"short_module": "SPT"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FL"
},
{
"abbrev": true,
"full_module": "Spec.K256",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256.Point",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256.Field52.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FL"
},
{
"abbrev": true,
"full_module": "Spec.K256",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256.Point",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256.Field52.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
x0: Lib.IntTypes.uint64 ->
x1: Lib.IntTypes.uint64 ->
x2: Lib.IntTypes.uint64 ->
x3: Lib.IntTypes.uint64 ->
x4: Lib.IntTypes.uint64
-> FStar.Pervasives.Lemma
(ensures
(let s = Hacl.Spec.K256.PrecompTable.create5_lseq x0 x1 x2 x3 x4 in
s.[ 0 ] == x0 /\ s.[ 1 ] == x1 /\ s.[ 2 ] == x2 /\ s.[ 3 ] == x3 /\ s.[ 4 ] == x4)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Lib.IntTypes.uint64",
"FStar.Seq.Properties.elim_of_list",
"Prims.Cons",
"Prims.Nil",
"Prims.unit"
] | [] | true | false | true | false | false | let create5_lemma x0 x1 x2 x3 x4 =
| Seq.elim_of_list [x0; x1; x2; x3; x4] | false |
LowParse.Spec.Int.fst | LowParse.Spec.Int.decode_u16 | val decode_u16 (b: bytes{Seq.length b == 2}) : GTot U16.t | val decode_u16 (b: bytes{Seq.length b == 2}) : GTot U16.t | let decode_u16
(b: bytes { Seq.length b == 2 } )
: GTot U16.t
= E.lemma_be_to_n_is_bounded b;
U16.uint_to_t (E.be_to_n b) | {
"file_name": "src/lowparse/LowParse.Spec.Int.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 29,
"end_line": 35,
"start_col": 0,
"start_line": 31
} | module LowParse.Spec.Int
open LowParse.Spec.Combinators
let decode_u8
(b: bytes { Seq.length b == 1 } )
: Tot U8.t
= Seq.index b 0
let decode_u8_injective () : Lemma
(make_total_constant_size_parser_precond 1 U8.t decode_u8)
= ()
let tot_parse_u8 =
decode_u8_injective ();
tot_make_total_constant_size_parser 1 U8.t decode_u8
let parse_u8_spec
b
=
Seq.lemma_index_slice b 0 1 0;
E.reveal_be_to_n (Seq.slice b 0 1);
E.reveal_be_to_n (Seq.slice (Seq.slice b 0 1) 0 0)
let parse_u8_spec' b = ()
let serialize_u8 =
Seq.create 1
let serialize_u8_spec x = () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Seq.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "LowParse.Spec.Int.fst"
} | [
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.Endianness",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | b: LowParse.Bytes.bytes{FStar.Seq.Base.length b == 2} -> Prims.GTot FStar.UInt16.t | Prims.GTot | [
"sometrivial"
] | [] | [
"LowParse.Bytes.bytes",
"Prims.eq2",
"Prims.int",
"FStar.Seq.Base.length",
"LowParse.Bytes.byte",
"FStar.UInt16.uint_to_t",
"FStar.Endianness.be_to_n",
"Prims.unit",
"FStar.Endianness.lemma_be_to_n_is_bounded",
"FStar.UInt16.t"
] | [] | false | false | false | false | false | let decode_u16 (b: bytes{Seq.length b == 2}) : GTot U16.t =
| E.lemma_be_to_n_is_bounded b;
U16.uint_to_t (E.be_to_n b) | false |
LowParse.Spec.Int.fst | LowParse.Spec.Int.parse_u32 | val parse_u32: parser parse_u32_kind U32.t | val parse_u32: parser parse_u32_kind U32.t | let parse_u32 =
decode_u32_injective ();
make_total_constant_size_parser 4 U32.t decode_u32 | {
"file_name": "src/lowparse/LowParse.Spec.Int.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 52,
"end_line": 97,
"start_col": 0,
"start_line": 95
} | module LowParse.Spec.Int
open LowParse.Spec.Combinators
let decode_u8
(b: bytes { Seq.length b == 1 } )
: Tot U8.t
= Seq.index b 0
let decode_u8_injective () : Lemma
(make_total_constant_size_parser_precond 1 U8.t decode_u8)
= ()
let tot_parse_u8 =
decode_u8_injective ();
tot_make_total_constant_size_parser 1 U8.t decode_u8
let parse_u8_spec
b
=
Seq.lemma_index_slice b 0 1 0;
E.reveal_be_to_n (Seq.slice b 0 1);
E.reveal_be_to_n (Seq.slice (Seq.slice b 0 1) 0 0)
let parse_u8_spec' b = ()
let serialize_u8 =
Seq.create 1
let serialize_u8_spec x = ()
let decode_u16
(b: bytes { Seq.length b == 2 } )
: GTot U16.t
= E.lemma_be_to_n_is_bounded b;
U16.uint_to_t (E.be_to_n b)
let decode_u16_injective'
(b1: bytes { Seq.length b1 == 2 } )
(b2: bytes { Seq.length b2 == 2 } )
: Lemma
(decode_u16 b1 == decode_u16 b2 ==> Seq.equal b1 b2)
= if decode_u16 b1 = decode_u16 b2
then begin
E.lemma_be_to_n_is_bounded b1;
E.lemma_be_to_n_is_bounded b2;
assert (U32.v (U32.uint_to_t (E.be_to_n b1)) == E.be_to_n b1);
assert (U32.v (U32.uint_to_t (E.be_to_n b2)) == E.be_to_n b2);
assert (E.be_to_n b1 == E.be_to_n b2);
E.be_to_n_inj b1 b2
end else ()
let decode_u16_injective
()
: Lemma
(make_total_constant_size_parser_precond 2 U16.t decode_u16)
= Classical.forall_intro_2 decode_u16_injective'
let parse_u16 =
decode_u16_injective ();
make_total_constant_size_parser 2 U16.t decode_u16
let parse_u16_spec
b
=
E.lemma_be_to_n_is_bounded (Seq.slice b 0 2)
let serialize_u16 =
(fun (x: U16.t) -> E.n_to_be 2 (U16.v x))
let decode_u32
(b: bytes { Seq.length b == 4 } )
: GTot U32.t
= E.lemma_be_to_n_is_bounded b;
U32.uint_to_t (E.be_to_n b)
let decode_u32_injective'
(b1: bytes { Seq.length b1 == 4 } )
(b2: bytes { Seq.length b2 == 4 } )
: Lemma
(decode_u32 b1 == decode_u32 b2 ==> Seq.equal b1 b2)
= if decode_u32 b1 = decode_u32 b2
then begin
E.lemma_be_to_n_is_bounded b1;
E.lemma_be_to_n_is_bounded b2;
assert (U32.v (U32.uint_to_t (E.be_to_n b1)) == E.be_to_n b1);
assert (U32.v (U32.uint_to_t (E.be_to_n b2)) == E.be_to_n b2);
assert (E.be_to_n b1 == E.be_to_n b2);
E.be_to_n_inj b1 b2
end else ()
let decode_u32_injective () : Lemma
(make_total_constant_size_parser_precond 4 U32.t decode_u32)
= Classical.forall_intro_2 decode_u32_injective' | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Seq.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "LowParse.Spec.Int.fst"
} | [
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.Endianness",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | LowParse.Spec.Base.parser LowParse.Spec.Int.parse_u32_kind FStar.UInt32.t | Prims.Tot | [
"total"
] | [] | [
"LowParse.Spec.Combinators.make_total_constant_size_parser",
"FStar.UInt32.t",
"LowParse.Spec.Int.decode_u32",
"Prims.unit",
"LowParse.Spec.Int.decode_u32_injective"
] | [] | false | false | false | true | false | let parse_u32 =
| decode_u32_injective ();
make_total_constant_size_parser 4 U32.t decode_u32 | false |
LowParse.Spec.Int.fst | LowParse.Spec.Int.decode_u16_injective' | val decode_u16_injective' (b1: bytes{Seq.length b1 == 2}) (b2: bytes{Seq.length b2 == 2})
: Lemma (decode_u16 b1 == decode_u16 b2 ==> Seq.equal b1 b2) | val decode_u16_injective' (b1: bytes{Seq.length b1 == 2}) (b2: bytes{Seq.length b2 == 2})
: Lemma (decode_u16 b1 == decode_u16 b2 ==> Seq.equal b1 b2) | let decode_u16_injective'
(b1: bytes { Seq.length b1 == 2 } )
(b2: bytes { Seq.length b2 == 2 } )
: Lemma
(decode_u16 b1 == decode_u16 b2 ==> Seq.equal b1 b2)
= if decode_u16 b1 = decode_u16 b2
then begin
E.lemma_be_to_n_is_bounded b1;
E.lemma_be_to_n_is_bounded b2;
assert (U32.v (U32.uint_to_t (E.be_to_n b1)) == E.be_to_n b1);
assert (U32.v (U32.uint_to_t (E.be_to_n b2)) == E.be_to_n b2);
assert (E.be_to_n b1 == E.be_to_n b2);
E.be_to_n_inj b1 b2
end else () | {
"file_name": "src/lowparse/LowParse.Spec.Int.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 13,
"end_line": 50,
"start_col": 0,
"start_line": 37
} | module LowParse.Spec.Int
open LowParse.Spec.Combinators
let decode_u8
(b: bytes { Seq.length b == 1 } )
: Tot U8.t
= Seq.index b 0
let decode_u8_injective () : Lemma
(make_total_constant_size_parser_precond 1 U8.t decode_u8)
= ()
let tot_parse_u8 =
decode_u8_injective ();
tot_make_total_constant_size_parser 1 U8.t decode_u8
let parse_u8_spec
b
=
Seq.lemma_index_slice b 0 1 0;
E.reveal_be_to_n (Seq.slice b 0 1);
E.reveal_be_to_n (Seq.slice (Seq.slice b 0 1) 0 0)
let parse_u8_spec' b = ()
let serialize_u8 =
Seq.create 1
let serialize_u8_spec x = ()
let decode_u16
(b: bytes { Seq.length b == 2 } )
: GTot U16.t
= E.lemma_be_to_n_is_bounded b;
U16.uint_to_t (E.be_to_n b) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Seq.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "LowParse.Spec.Int.fst"
} | [
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.Endianness",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
b1: LowParse.Bytes.bytes{FStar.Seq.Base.length b1 == 2} ->
b2: LowParse.Bytes.bytes{FStar.Seq.Base.length b2 == 2}
-> FStar.Pervasives.Lemma
(ensures
LowParse.Spec.Int.decode_u16 b1 == LowParse.Spec.Int.decode_u16 b2 ==>
FStar.Seq.Base.equal b1 b2) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"LowParse.Bytes.bytes",
"Prims.eq2",
"Prims.int",
"FStar.Seq.Base.length",
"LowParse.Bytes.byte",
"Prims.op_Equality",
"FStar.UInt16.t",
"LowParse.Spec.Int.decode_u16",
"FStar.Endianness.be_to_n_inj",
"Prims.unit",
"Prims._assert",
"Prims.nat",
"FStar.Endianness.be_to_n",
"Prims.l_or",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"FStar.UInt.size",
"FStar.UInt32.n",
"FStar.UInt32.v",
"FStar.UInt32.uint_to_t",
"FStar.Endianness.lemma_be_to_n_is_bounded",
"Prims.bool",
"Prims.l_True",
"Prims.squash",
"Prims.l_imp",
"FStar.Seq.Base.equal",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let decode_u16_injective' (b1: bytes{Seq.length b1 == 2}) (b2: bytes{Seq.length b2 == 2})
: Lemma (decode_u16 b1 == decode_u16 b2 ==> Seq.equal b1 b2) =
| if decode_u16 b1 = decode_u16 b2
then
(E.lemma_be_to_n_is_bounded b1;
E.lemma_be_to_n_is_bounded b2;
assert (U32.v (U32.uint_to_t (E.be_to_n b1)) == E.be_to_n b1);
assert (U32.v (U32.uint_to_t (E.be_to_n b2)) == E.be_to_n b2);
assert (E.be_to_n b1 == E.be_to_n b2);
E.be_to_n_inj b1 b2) | false |
Steel.Memory.fst | Steel.Memory.fresh_invariant | val fresh_invariant (e:inames) (p:slprop) (ctx:list pre_inv)
: action_except (i:inv p { not (mem_inv e i) /\ fresh_wrt ctx (name_of_inv i) }) e p (fun _ -> emp) | val fresh_invariant (e:inames) (p:slprop) (ctx:list pre_inv)
: action_except (i:inv p { not (mem_inv e i) /\ fresh_wrt ctx (name_of_inv i) }) e p (fun _ -> emp) | let fresh_invariant (e:inames) (p:slprop) (ctx:list pre_inv) (frame:slprop)
: MstTot (i:inv p { not (mem_inv e i) /\ fresh_wrt ctx (name_of_inv i)}) e p (fun _ -> emp) frame (fun _ -> True) (fun _ _ _ -> True)
= let m0 = NMSTTotal.get () in
recall_all ctx;
ac_reasoning_for_m_frame_preserving p frame (locks_invariant e m0) m0;
assert (interp (p `star` locks_invariant e m0) m0);
let r = new_invariant_tot_action e p m0 in
let ( i, m1 ) = r in
assert (i == List.Tot.length m0.locks);
assert (not (Set.mem i e));
assert (mem_evolves m0 m1);
NMSTTotal.put #full_mem #mem_evolves m1;
iname_for_p_stable i p;
let w = NMSTTotal.witness full_mem mem_evolves (iname_for_p_mem i p) in
let w0 = NMSTTotal.witness full_mem mem_evolves (name_is_ok i) in
(| hide i, w0, w |) | {
"file_name": "lib/steel/Steel.Memory.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 23,
"end_line": 1288,
"start_col": 0,
"start_line": 1273
} | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Memory
module F = FStar.FunctionalExtensionality
open FStar.FunctionalExtensionality
open FStar.PCM
module H = Steel.Heap
noeq
type lock_state : Type u#(a + 1) =
| Invariant : inv:H.slprop u#a -> lock_state
let lock_store : Type u#(a+1) = list (lock_state u#a)
noeq
type mem : Type u#(a + 1) =
{
ctr: nat;
heap: H.heap u#a;
locks: lock_store u#a;
}
let heap_of_mem (x:mem) : H.heap = x.heap
let mem_of_heap (h:H.heap) : mem = {
ctr = 0;
heap = h;
locks = []
}
let mem_set_heap (m:mem) (h:H.heap) : mem = {
ctr = m.ctr;
heap = h;
locks = m.locks;
}
let core_mem (m:mem) : mem = mem_of_heap (heap_of_mem m)
let core_mem_invol m = ()
let disjoint (m0 m1:mem u#h)
: prop
= m0.ctr == m1.ctr /\
H.disjoint m0.heap m1.heap /\
m0.locks == m1.locks
let disjoint_sym m0 m1 = ()
let join m0 m1 = {
ctr = m0.ctr;
heap = H.join m0.heap m1.heap;
locks = m0.locks
}
let join_commutative m0 m1 =
H.join_commutative m0.heap m1.heap
let disjoint_join m0 m1 m2 =
H.disjoint_join m0.heap m1.heap m2.heap
let join_associative m0 m1 m2 =
H.join_associative m0.heap m1.heap m2.heap
let slprop = H.slprop
let interp p m = H.interp p m.heap
let equiv p1 p2 = forall m. interp p1 m <==> interp p2 m
let slprop_extensionality p q =
assert (forall m. interp p m <==> interp q m);
let aux (h:H.heap)
: Lemma (H.interp p h <==> H.interp q h)
[SMTPat (H.interp p h)]
= let m : mem = { ctr = 0; heap = h; locks = [] } in
assert (interp p m <==> interp q m)
in
assert (forall h. H.interp p h <==> H.interp q h);
Steel.Heap.slprop_extensionality p q
let reveal_equiv p1 p2 = ()
let core_ref = H.core_ref
let core_ref_null = H.core_ref_null
let core_ref_is_null r = H.core_ref_is_null r
let emp : slprop u#a = H.emp
let pure = H.pure
let pts_to = H.pts_to
let h_and = H.h_and
let h_or = H.h_or
let star = H.star
let wand = H.wand
let h_exists = H.h_exists
let h_forall = H.h_forall
////////////////////////////////////////////////////////////////////////////////
//properties of equiv
////////////////////////////////////////////////////////////////////////////////
let equiv_symmetric (p1 p2:slprop u#a) = H.equiv_symmetric p1 p2
#push-options "--warn_error -271"
let equiv_heap_iff_equiv (p1 p2:slprop u#a)
: Lemma (ensures (H.equiv p1 p2 <==> equiv p1 p2))
[SMTPat (equiv p1 p2)]
= let aux_lr ()
: Lemma
(requires H.equiv p1 p2)
(ensures equiv p1 p2)
[SMTPat ()]
= ()
in
let aux_rl_helper1 (h:H.heap)
: Lemma
(requires equiv p1 p2 /\ H.interp p1 h)
(ensures H.interp p2 h)
[SMTPat ()]
= assert (interp p2 (mem_of_heap h))
in
let aux_rl_helper2 (h:H.heap)
: Lemma
(requires equiv p1 p2 /\ H.interp p2 h)
(ensures H.interp p1 h)
[SMTPat ()]
= assert (interp p2 (mem_of_heap h))
in
let aux_rl ()
: Lemma
(requires equiv p1 p2)
(ensures H.equiv p1 p2)
[SMTPat ()]
= () in
()
let equiv_heap_iff_equiv_forall ()
: Lemma (ensures (forall p1 p2. H.equiv p1 p2 <==> equiv p1 p2))
= let aux p1 p2
: Lemma (ensures (H.equiv p1 p2 <==> equiv p1 p2))
[SMTPat ()]
= equiv_heap_iff_equiv p1 p2
in
()
#pop-options
let equiv_extensional_on_star (p1 p2 p3:slprop u#a) =
equiv_heap_iff_equiv_forall ();
H.equiv_extensional_on_star p1 p2 p3
let emp_unit p = H.emp_unit p
let intro_emp m = H.intro_emp (heap_of_mem m)
let pure_equiv p q = H.pure_equiv p q
let pure_interp q m = H.pure_interp q (heap_of_mem m)
let pure_star_interp p q m = H.pure_star_interp p q (heap_of_mem m)
////////////////////////////////////////////////////////////////////////////////
//pts_to
////////////////////////////////////////////////////////////////////////////////
let pts_to_compatible #a #pcm x v0 v1 m
= H.pts_to_compatible #a #pcm x v0 v1 (heap_of_mem m)
let pts_to_compatible_equiv #a #pcm x v0 v1
= H.pts_to_compatible_equiv #a #pcm x v0 v1
let pts_to_not_null #a #pcm x v m
= H.pts_to_not_null #a #pcm x v (heap_of_mem m)
////////////////////////////////////////////////////////////////////////////////
// star
////////////////////////////////////////////////////////////////////////////////
let intro_star p q mp mq =
H.intro_star p q (heap_of_mem mp) (heap_of_mem mq)
let elim_star p q m =
let h = heap_of_mem m in
H.elim_star p q h;
assert (exists hl hr. H.disjoint hl hr /\ H.join hl hr == h /\ H.interp p hl /\ H.interp q hr);
let hl = FStar.IndefiniteDescription.indefinite_description_tot H.heap (fun hl ->
exists hr. H.disjoint hl hr /\ H.join hl hr == h /\ H.interp p hl /\ H.interp q hr) in
let hr = FStar.IndefiniteDescription.indefinite_description_tot H.heap (fun hr ->
H.disjoint hl hr /\ H.join hl hr == h /\ H.interp p hl /\ H.interp q hr) in
let ml = mem_set_heap m hl in
let mr = mem_set_heap m hr in
assert (disjoint ml mr);
assert (m == join ml mr);
assert (interp p ml);
assert (interp q mr);
()
let interp_star
(p q: slprop)
(m: mem)
: Lemma
(interp (p `star` q) m <==> (exists (mp: mem) (mq: mem) . disjoint mp mq /\ interp p mp /\ interp q mq /\ join mp mq == m))
= let left = interp (p `star` q) m in
let right = exists (mp: mem) (mq: mem) . disjoint mp mq /\ interp p mp /\ interp q mq /\ join mp mq == m in
let f ()
: Lemma
(requires left)
(ensures right)
=
elim_star p q m
in
let g ()
: Lemma
(requires right)
(ensures left)
=
Classical.exists_elim left #_ #(fun mp -> exists (mq: mem) . disjoint mp mq /\ interp p mp /\ interp q mq /\ join mp mq == m) () (fun mp ->
Classical.exists_elim left #_ #(fun mq -> disjoint mp mq /\ interp p mp /\ interp q mq /\ join mp mq == m) () (fun mq ->
intro_star p q mp mq
)
)
in
Classical.move_requires f ();
Classical.move_requires g ()
let star_commutative (p1 p2:slprop) =
H.star_commutative p1 p2
let star_associative (p1 p2 p3:slprop) =
H.star_associative p1 p2 p3
let star_congruence (p1 p2 p3 p4:slprop) =
equiv_heap_iff_equiv_forall ();
H.star_congruence p1 p2 p3 p4
let affine_star (p q:slprop) (m:mem) =
H.affine_star p q (heap_of_mem m)
////////////////////////////////////////////////////////////////////////////////
// Invariants on the lock store
////////////////////////////////////////////////////////////////////////////////
let iname = nat
module S = FStar.Set
module L = FStar.List.Tot
module W = FStar.Witnessed.Core
let rec lock_store_invariant (e:inames) (l:lock_store u#a) : slprop u#a =
let current_addr = L.length l - 1 in
match l with
| [] -> emp
| Invariant p :: tl ->
if current_addr `S.mem` e then
lock_store_invariant e tl
else
p `star` lock_store_invariant e tl
let lock_i (i:iname) (l:lock_store { i < L.length l }) =
let ix = L.length l - i - 1 in
L.index l ix
let iname_for_p (i:iname) (p:slprop) : W.s_predicate lock_store =
fun l ->
i < L.length l /\
(lock_i i l).inv == p
let lock_store_evolves : FStar.Preorder.preorder lock_store =
fun (l1 l2 : lock_store) ->
L.length l2 >= L.length l1 /\
(forall (i:nat{i < L.length l1}).
(lock_i i l1).inv == (lock_i i l2).inv)
let inames_in (e:inames) (l:lock_store) : prop = forall i. Set.mem i e ==> i < L.length l
let inames_ok e m = inames_in e m.locks
let inames_ok_empty m = ()
let extend_lock_store (e:inames) (l:lock_store{e `inames_in` l}) (p:slprop)
: i:iname &
l':lock_store {
lock_store_invariant e l' == p `star` lock_store_invariant e l /\
iname_for_p i p l'
}
= (| L.length l, Invariant p :: l |)
let set_add (i:iname) (s:inames) = Set.union (Set.singleton i) s
let rec move_invariant (e:inames) (l:lock_store) (p:slprop)
(i:iname{iname_for_p i p l /\ ~(i `Set.mem` e)})
: Lemma (H.equiv (lock_store_invariant e l)
(p `star` lock_store_invariant (set_add i e) l))
= let rec aux (i:iname) (m:lock_store)
: Lemma (requires i >= L.length m)
(ensures (lock_store_invariant e m `H.equiv` lock_store_invariant (set_add i e) m))
= match m with
| [] -> ()
| Invariant p::tl ->
aux i tl;
H.star_congruence p (lock_store_invariant e tl) p (lock_store_invariant (set_add i e) tl)
in
let current_addr = L.length l - 1 in
match l with
| [] -> ()
| Invariant q::tl ->
if i = current_addr
then begin
assert (lock_store_invariant e l == p `star` lock_store_invariant e tl);
aux i tl;
H.star_congruence p (lock_store_invariant e tl) p (lock_store_invariant (set_add i e) tl);
()
end
else begin
move_invariant e tl p i;
assert (lock_store_invariant e tl `equiv`
(p `star` lock_store_invariant (set_add i e) tl));
H.star_congruence q (lock_store_invariant e tl) q (p `star` lock_store_invariant (set_add i e) tl);
if Set.mem current_addr e
then ()
else begin
let r = lock_store_invariant (set_add i e) tl in
assert (lock_store_invariant e l `equiv`
(q `star` (p `star` r)));
H.star_associative q p r;
H.star_commutative q p;
H.star_congruence (q `star` p) r (p `star` q) r;
H.star_associative p q r
end
end
let heap_ctr_valid (ctr:nat) (h:H.heap u#a) : prop =
h `H.free_above_addr` ctr
let ctr_validity (ctr:nat) (h:H.heap) : slprop =
H.pure (heap_ctr_valid ctr h)
let locks_invariant (e:inames) (m:mem u#a) : slprop u#a =
lock_store_invariant e m.locks
`star`
ctr_validity m.ctr (heap_of_mem m)
let full_mem_pred (m:mem) = H.full_heap_pred (heap_of_mem m)
(***** Following lemmas are needed in Steel.Effect *****)
let core_mem_interp (hp:slprop u#a) (m:mem u#a) = ()
let interp_depends_only_on (hp:slprop u#a) = H.interp_depends_only_on hp
let a_mem_prop_as_a_heap_prop
(sl: slprop u#a)
(f: a_mem_prop sl)
: Tot (H.a_heap_prop u#a)
=
let g (h: H.heap u#a) : Tot prop = interp sl (mem_of_heap h) /\ f (mem_of_heap h) in
let phi0 (h0 h1: H.heap u#a) : Lemma
(requires (g h0 /\ H.disjoint h0 h1))
(ensures (g h0 /\ H.disjoint h0 h1 /\ g (H.join h0 h1)))
= assert (mem_of_heap (H.join h0 h1) == mem_of_heap h0 `join` mem_of_heap h1);
interp_depends_only_on sl
in
let phi1 (h0 h1: H.heap u#a) : Lemma
(ensures ((g h0 /\ H.disjoint h0 h1) ==> g (H.join h0 h1)))
=
Classical.move_requires (phi0 h0) h1
in
Classical.forall_intro_2 phi1;
g
let refine_slprop sl f = H.as_slprop (a_mem_prop_as_a_heap_prop sl f)
let interp_refine_slprop sl f m =
assert ((interp sl m /\ f m) <==> interp sl (core_mem m) /\ f (core_mem m))
let dep_hprop
(s: slprop)
(f: (hmem s -> Tot slprop))
(h: H.heap)
: Tot prop
= exists (h1: H.heap) . exists (h2: H.heap) . interp s (mem_of_heap h1) /\ H.disjoint h1 h2 /\ interp (f (mem_of_heap h1)) (mem_of_heap h2) /\ h == h1 `H.join` h2
let dep_hprop_is_affine0
(s: slprop)
(f: (hmem s -> Tot slprop))
(h h': H.heap)
(sq' : squash (dep_hprop s f h /\ H.disjoint h h'))
: Lemma
(H.disjoint h h' /\ dep_hprop s f (H.join h h'))
=
let p2 (h h1 h2: H.heap) : Tot prop =
interp s (mem_of_heap h1) /\
H.disjoint h1 h2 /\ interp (f (mem_of_heap h1)) (mem_of_heap h2) /\ h == h1 `H.join` h2
in
let p1 (h h1: H.heap) : Tot prop =
(exists h2 . p2 h h1 h2)
in
let h1 =
FStar.IndefiniteDescription.indefinite_description_ghost H.heap (p1 h)
in
let h2 =
FStar.IndefiniteDescription.indefinite_description_ghost H.heap (p2 h h1)
in
H.disjoint_join h' h1 h2;
assert (H.disjoint h2 h');
let h2' = H.join h2 h' in
H.join_commutative h2 h' ;
assert (h2' == H.join h' h2);
assert (H.disjoint h1 h2');
assert (mem_of_heap h2' == mem_of_heap h2 `join` mem_of_heap h');
interp_depends_only_on (f (mem_of_heap h1));
assert (interp (f (mem_of_heap h1)) (mem_of_heap h2'));
H.join_commutative h1 h2;
H.join_associative h' h2 h1;
H.join_commutative h' h;
H.join_commutative h2' h1;
assert (H.join h h' == h1 `H.join` h2')
let impl_intro_gen (#p: Type0) (#q: Type0) ($prf: (squash p -> Lemma (q )))
: Lemma (p ==> q)
= Classical.impl_intro_gen #p #(fun _ -> q) prf
let dep_hprop_is_affine1
(s: slprop)
(f: (hmem s -> Tot slprop))
(h0 h1: H.heap)
: Lemma
((dep_hprop s f h0 /\ H.disjoint h0 h1) ==> (H.disjoint h0 h1 /\ dep_hprop s f (H.join h0 h1)))
= impl_intro_gen (dep_hprop_is_affine0 s f h0 h1)
let dep_hprop_is_affine
(s: slprop)
(f: (hmem s -> Tot slprop))
: Lemma
(H.heap_prop_is_affine (dep_hprop s f))
= Classical.forall_intro_2 (dep_hprop_is_affine1 s f)
let sdep
(s: slprop)
(f: (hmem s -> Tot slprop))
: Tot slprop
=
dep_hprop_is_affine s f;
H.as_slprop (dep_hprop s f)
let interp_sdep
(s: slprop)
(f: (hmem s -> Tot slprop))
(m: mem)
: Lemma
(requires (dep_slprop_is_affine s f))
(ensures (
interp (sdep s f) m <==> (exists m1 m2 . interp s m1 /\ interp (f m1) m2 /\ disjoint m1 m2 /\ join m1 m2 == m)
))
=
dep_hprop_is_affine s f;
assert (forall m1 m2 . (interp s m1 /\ interp (f m1) m2 /\ disjoint m1 m2 /\ join m1 m2 == m) ==> (
interp s (mem_of_heap m1.heap) /\ interp (f (mem_of_heap m1.heap)) (mem_of_heap m2.heap) /\
H.disjoint m1.heap m2.heap /\
H.join m1.heap m2.heap == m.heap
));
interp_depends_only_on s;
Classical.forall_intro (fun m -> interp_depends_only_on (f m));
assert (forall h1 h2 . (interp s (mem_of_heap h1) /\ interp (f (mem_of_heap h1)) (mem_of_heap h2) /\ H.disjoint h1 h2 /\ H.join h1 h2 == m.heap) ==> (
core_mem (mem_of_heap h1) == core_mem (mem_set_heap m h1) /\
interp s (core_mem (mem_of_heap h1)) /\
interp s (mem_set_heap m h1) /\
core_mem (mem_of_heap h1) == core_mem (mem_set_heap m h1) /\
f (mem_set_heap m h1) `equiv` f (mem_of_heap h1) /\
interp (f (mem_set_heap m h1)) (mem_of_heap h2) /\
interp (f (mem_set_heap m h1)) (mem_set_heap m h2) /\
disjoint (mem_set_heap m h1) (mem_set_heap m h2) /\
join (mem_set_heap m h1) (mem_set_heap m h2) == m
));
()
let h_exists_cong (#a:Type) (p q : a -> slprop)
: Lemma
(requires (forall x. p x `equiv` q x))
(ensures (h_exists p `equiv` h_exists q))
= equiv_heap_iff_equiv_forall ();
H.h_exists_cong p q
let intro_h_exists #a x p m = H.intro_h_exists x p (heap_of_mem m)
let elim_h_exists (#a:_) (p:a -> slprop) (m:mem) = H.elim_h_exists p (heap_of_mem m)
let intro_h_forall (#a:_) (p:a -> slprop) (m:mem) = H.intro_h_forall p (heap_of_mem m)
let elim_h_forall (#a:_) (p:a -> slprop) (m:mem) (x:a) = H.elim_h_forall p (heap_of_mem m) x
let intro_h_and (p q: slprop) (m:mem) = H.intro_h_and p q (heap_of_mem m)
let elim_h_and (p q: slprop) (m:mem) = H.elim_h_and p q (heap_of_mem m)
let intro_h_or_left (p q: slprop) (m:mem) = H.intro_h_or_left p q (heap_of_mem m)
let intro_h_or_right (p q: slprop) (m:mem) = H.intro_h_or_right p q (heap_of_mem m)
let elim_h_or (p q: slprop) (m:mem) = H.elim_h_or p q (heap_of_mem m)
let intro_wand (p1 p2: slprop u#a) (m:mem) =
introduce
(forall m1. m `disjoint` m1 /\ interp p1 m1 ==> interp p2 (join m m1))
==> interp (wand p1 p2) m
with _. (
assert (forall m1. m `disjoint` m1 /\ interp p1 m1 ==> interp p2 (join m m1));
H.intro_wand p1 p2 (heap_of_mem m);
let h = heap_of_mem m in
assert ((forall h1. h `H.disjoint` h1 /\ H.interp p1 h1 ==> H.interp p2 (H.join h h1))
==> H.interp (wand p1 p2) h);
introduce forall h1. (h `H.disjoint` h1 /\ H.interp p1 h1 ==> H.interp p2 (H.join h h1))
with (
introduce (h `H.disjoint` h1 /\ H.interp p1 h1) ==> H.interp p2 (H.join h h1)
with _. (
assert (h `H.disjoint` h1);
let m1 = {
ctr = m.ctr;
heap = h1;
locks = m.locks
}
in assert (m `disjoint` m1)
)
)
)
(** Eliminating a wand by proving a heap that satisfies the LHS **)
let elim_wand (p1 p2: slprop u#a) (m:mem) (m1:mem) = H.elim_wand p1 p2 (heap_of_mem m) (heap_of_mem m1)
////////////////////////////////////////////////////////////////////////////////
// Preorders and effects
////////////////////////////////////////////////////////////////////////////////
module PP = Steel.Preorder
let mem_evolves =
fun (m0 m1:full_mem) ->
H.heap_evolves (heap_of_mem m0) (heap_of_mem m1) /\
m0.ctr <= m1.ctr /\
lock_store_evolves m0.locks m1.locks
(** See [Steel.Heap.is_frame_preserving]. We add in [lock_invariants] now *)
let preserves_frame (e:inames) (pre post:slprop) (m0 m1:mem) =
forall (frame:slprop).
interp ((pre `star` frame) `star` locks_invariant e m0) m0 ==>
(interp ((post `star` frame) `star` locks_invariant e m1) m1 /\
(forall (f_frame:mprop frame). f_frame (core_mem m0) == f_frame (core_mem m1)))
(**
This is a version of MstTot with frame quantified, as part of preserves_frame
*)
effect MstTotNF (a:Type u#a) (except:inames) (expects:slprop u#1) (provides: a -> slprop u#1) =
NMSTTotal.NMSTATETOT a (full_mem u#1) mem_evolves
(requires fun m0 ->
inames_ok except m0 /\
interp (expects `star` locks_invariant except m0) m0)
(ensures fun m0 x m1 ->
inames_ok except m1 /\
interp (provides x `star` locks_invariant except m1) m1 /\
preserves_frame except expects (provides x) m0 m1)
////////////////////////////////////////////////////////////////////////////////
// Lifting heap actions
////////////////////////////////////////////////////////////////////////////////
(**
Heap actions come in two equivalent flavors:
- one that take an explicit frame as argument (action_with_frame)
- and one that quantify over all the frame
We therefore define two lift routes:
- a direct route for those with explicit frame
- via MstTotNF for the rest
*)
let tot_pre_action_nf_except (e:inames) (fp:slprop u#a) (a:Type u#b) (fp':a -> slprop u#a) =
hmem_with_inv_except e fp ->
(x:a & hmem_with_inv_except e (fp' x))
let tot_pre_action_nf = tot_pre_action_nf_except S.empty
let ac_reasoning_for_m_frame_preserving
(p q r:slprop u#a) (m:mem u#a)
: Lemma
(requires interp ((p `star` q) `star` r) m)
(ensures interp (p `star` r) m)
= calc (equiv) {
(p `star` q) `star` r;
(equiv) { star_commutative p q;
equiv_extensional_on_star (p `star` q) (q `star` p) r }
(q `star` p) `star` r;
(equiv) { star_associative q p r }
q `star` (p `star` r);
};
assert (interp (q `star` (p `star` r)) m);
affine_star q (p `star` r) m
let is_frame_preserving
(#e:inames)
(#a:Type u#b)
(#fp:slprop u#a)
(#fp':a -> slprop u#a)
(f:tot_pre_action_nf_except e fp a fp') =
forall (frame:slprop u#a) (m0:hmem_with_inv_except e (fp `star` frame)).
(ac_reasoning_for_m_frame_preserving fp frame (locks_invariant e m0) m0;
let (| x, m1 |) = f m0 in
interp ((fp' x `star` frame) `star` locks_invariant e m1) m1 /\
mem_evolves m0 m1 /\
(forall (mp:mprop frame). mp (core_mem m0) == mp (core_mem m1)))
let tot_action_nf_except (e:inames) (fp:slprop u#a) (a:Type u#b) (fp':a -> slprop u#a) =
f:tot_pre_action_nf_except e fp a fp'{ is_frame_preserving f }
let tot_action_nf = tot_action_nf_except S.empty
let linv e (m:mem) = locks_invariant e m
let hheap_of_hmem #fp #e (m:hmem_with_inv_except e fp)
: h:H.hheap (fp `star` linv e m) { h `H.free_above_addr` m.ctr}
= let h = heap_of_mem m in
H.pure_interp (heap_ctr_valid m.ctr (heap_of_mem m)) h;
h
let hmem_of_hheap #e (#fp0 #fp1:slprop) (m:hmem_with_inv_except e fp0)
(h:H.full_hheap (fp1 `star` linv e m) {
h `Heap.free_above_addr` m.ctr
})
: m1:hmem_with_inv_except e fp1{linv e m `equiv` linv e m1}
= let m1 : mem = { m with heap = h } in
assert (interp (fp1 `star` linv e m) m1);
star_commutative fp1 (linv e m);
assert (interp (linv e m `star` fp1) m1);
assert (linv e m1 == (lock_store_invariant e m1.locks)
`star` ctr_validity m1.ctr (heap_of_mem m1));
assert (linv e m == (lock_store_invariant e m1.locks)
`star` ctr_validity m1.ctr (heap_of_mem m));
H.pure_interp (heap_ctr_valid m1.ctr (heap_of_mem m))
(heap_of_mem m);
assert (heap_ctr_valid m1.ctr (heap_of_mem m) <==>
heap_ctr_valid m1.ctr (heap_of_mem m1));
H.pure_equiv (heap_ctr_valid m1.ctr (heap_of_mem m))
(heap_ctr_valid m1.ctr (heap_of_mem m1));
H.star_congruence (lock_store_invariant e m1.locks)
(ctr_validity m1.ctr (heap_of_mem m1))
(lock_store_invariant e m1.locks)
(ctr_validity m1.ctr (heap_of_mem m));
assert (linv e m `equiv` linv e m1);
let _ = equiv_extensional_on_star (linv e m) (linv e m1) fp1 in
assert ((linv e m `star` fp1) `equiv` (linv e m1 `star` fp1));
assert (interp (linv e m1 `star` fp1) m1);
star_commutative (linv e m1) fp1;
assert (interp (fp1 `star` linv e m1) m1);
m1
let with_inv_except (m:mem) e (fp:slprop) = interp (fp `star` locks_invariant e m) m
#push-options "--warn_error -271"
let as_hprop (frame:slprop) (mp:mprop frame)
: hp:H.hprop frame{forall m. mp (core_mem m) == hp (heap_of_mem m)}
= let f = fun h -> mp (mem_of_heap h) in
assert (forall m. mp (core_mem m) == f (heap_of_mem m));
let aux (m0:H.hheap frame) (m1:H.heap{H.disjoint m0 m1})
: Lemma
(ensures (mem_of_heap (H.join m0 m1) == join (mem_of_heap m0) (mem_of_heap m1)))
[SMTPat ()]
= ()
in
f
let mprop_preservation_of_hprop_preservation
(p:slprop) (m0 m1:mem)
: Lemma
(requires (forall (hp:H.hprop p). hp (heap_of_mem m0) == hp (heap_of_mem m1)))
(ensures (forall (mp:mprop p). mp (core_mem m0) == mp (core_mem m1)))
= let aux (mp:mprop p)
: Lemma (mp (core_mem m0) == mp (core_mem m1))
[SMTPat()]
= assert (as_hprop p mp (heap_of_mem m0) == as_hprop p mp (heap_of_mem m1))
in
()
let lift_heap_action (#fp:slprop) (#a:Type) (#fp':a -> slprop)
(e:inames)
($f:H.action fp a fp')
: tot_action_nf_except e fp a fp'
= let g : tot_pre_action_nf_except e fp a fp' = fun m ->
let h0 = hheap_of_hmem m in
let (| x, h' |) = f h0 in
(| x, hmem_of_hheap m h' |)
in
let aux (frame:slprop) (m0:hmem_with_inv_except e (fp `star` frame))
: Lemma
(ensures
(ac_reasoning_for_m_frame_preserving fp frame (locks_invariant e m0) m0;
let (| x, m1 |) = g m0 in
interp ((fp' x `star` frame) `star` locks_invariant e m1) m1 /\
mem_evolves m0 m1 /\
(forall (mp:mprop frame). mp (core_mem m0) == mp (core_mem m1))))
[SMTPat ()]
= ac_reasoning_for_m_frame_preserving fp frame (locks_invariant e m0) m0;
let (| x, m1 |) = g m0 in
let h0 = hheap_of_hmem m0 in
let (| x', h1 |) = f h0 in
H.action_framing f (linv e m0) h0;
assert (x == x');
star_associative fp frame (linv e m0);
H.action_framing f (frame `star` linv e m0) h0;
assert (H.interp ((fp' x) `star` (frame `star` linv e m0)) h1);
star_associative (fp' x) frame (linv e m0);
assert (H.interp ((fp' x `star` frame) `star` linv e m0) h1);
let h1' : H.hheap ((fp' x `star` frame) `star` linv e m0) = h1 in
assert (m1 == hmem_of_hheap m0 h1');
assert (with_inv_except m1 e (fp' x `star` frame));
assert (forall (hp:H.hprop frame). hp h0 == hp h1);
mprop_preservation_of_hprop_preservation frame m0 m1;
()
in
assert (is_frame_preserving g);
g
let frame_preserving_respects_preorder #a #e #fp #fp' ($f:tot_action_nf_except e fp a fp') (m0:hmem_with_inv_except e fp)
: Lemma (let (| x, m1 |) = f m0 in
mem_evolves m0 m1)
= let aux (frame:slprop) (m0:hmem_with_inv_except e (fp `star` frame))
: Lemma
(ac_reasoning_for_m_frame_preserving fp frame (locks_invariant e m0) m0;
let (| x, m1 |) = f m0 in
interp ((fp' x `star` frame) `star` locks_invariant e m1) m1 /\
mem_evolves m0 m1)
= ()
in
H.emp_unit fp;
assert (interp (fp `star` linv e m0) m0);
H.star_congruence (fp `star` emp) (linv e m0) fp (linv e m0);
assert (interp ((fp `star` emp) `star` linv e m0) m0);
aux emp m0
let lift_tot_action_nf #a #e #fp #fp' ($f:tot_action_nf_except e fp a fp')
: MstTotNF a e fp fp'
= let m0 = NMSTTotal.get () in
let m0' : hmem_with_inv_except e fp = m0 in
let r = f m0' in
let (| x, m1 |) = r in
let m1' : hmem_with_inv_except e (fp' x) = m1 in
assert (is_frame_preserving f);
assert (m1 == dsnd (f m0));
frame_preserving_respects_preorder f m0;
NMSTTotal.put #_ #(mem_evolves) m1;
x
let lift_tot_action #a #e #fp #fp'
($f:tot_action_nf_except e fp a fp')
(frame:slprop)
: MstTot a e fp fp' frame (fun _ -> True) (fun _ _ _ -> True)
= let m0 = NMSTTotal.get #(full_mem) #_ () in
ac_reasoning_for_m_frame_preserving fp frame (locks_invariant e m0) m0;
assert (interp (fp `star` frame `star` locks_invariant e m0) m0);
assert (interp (fp `star` locks_invariant e m0) m0);
lift_tot_action_nf f
(**
Now defining the lift for heap actions with explicit frame
*)
let tot_action_with_frame_except
(e:inames)
(fp:slprop u#a)
(a:Type u#b)
(fp':a -> slprop u#a)
= frame:slprop u#a ->
m0:hmem_with_inv_except e (fp `star` frame) ->
Pure (x:a & hmem_with_inv_except e (fp' x `star` frame))
(requires True)
(ensures fun (| x, m1 |) ->
mem_evolves m0 m1 /\
(forall (mp:mprop frame). mp (core_mem m0) == mp (core_mem m1)))
let tot_action_with_frame = tot_action_with_frame_except S.empty
let lift_heap_action_with_frame
(#fp:slprop u#a)
(#a:Type u#b)
(#fp':a -> slprop u#a)
(e:inames)
($f:H.action_with_frame fp a fp')
: tot_action_with_frame_except e fp a fp'
= fun frame m0 ->
let h0 = hheap_of_hmem m0 in
calc (equiv) {
fp `star` frame `star` locks_invariant e m0;
(equiv) { star_associative fp frame (locks_invariant e m0) }
fp `star` (frame `star` locks_invariant e m0);
};
assert (H.interp (fp `star` frame `star` locks_invariant e m0) h0);
assert (H.interp (fp `star` (frame `star` locks_invariant e m0)) h0);
//key: apply the heap action with frame * locks_invariant e m0
let (| x, h1 |) = f (frame `star` locks_invariant e m0) h0 in
calc (equiv) {
fp' x `star` (frame `star` locks_invariant e m0);
(equiv) { star_associative (fp' x) frame (locks_invariant e m0) }
fp' x `star` frame `star` locks_invariant e m0;
};
assert (H.interp (fp' x `star` (frame `star` locks_invariant e m0)) h1);
assert (H.interp (fp' x `star` frame `star` locks_invariant e m0) h1);
let m1 = hmem_of_hheap m0 h1 in
assert (mem_evolves m0 m1);
mprop_preservation_of_hprop_preservation (frame `star` locks_invariant e m0) m0 m1;
assert (forall (mp:mprop frame). mp (core_mem m0) == mp (core_mem m1));
(| x, m1 |)
let lift_tot_action_with_frame #a #e #fp #fp'
($f:tot_action_with_frame_except e fp a fp')
(frame:slprop)
: MstTot a e fp fp' frame (fun _ -> True) (fun _ _ _ -> True)
= let m0 = NMSTTotal.get () in
assert (inames_ok e m0);
ac_reasoning_for_m_frame_preserving fp frame (locks_invariant e m0) m0;
assert (interp (fp `star` frame `star` locks_invariant e m0) m0);
assert (interp (fp `star` locks_invariant e m0) m0);
let m0' : hmem_with_inv_except e fp = m0 in
let r = f frame m0' in
let (| x, m1 |) = r in
ac_reasoning_for_m_frame_preserving (fp' x) frame (locks_invariant e m1) m1;
assert (interp (fp' x `star` frame `star` locks_invariant e m1) m1);
assert (interp (fp' x `star` locks_invariant e m1) m1);
let m1' : hmem_with_inv_except e (fp' x) = m1 in
NMSTTotal.put #_ #(mem_evolves) m1;
x
let sel_action #a #pcm e r v0
= lift_tot_action (lift_heap_action e (H.sel_action #a #pcm r v0))
let upd_action #a #pcm e r v0 v1
= lift_tot_action (lift_heap_action e (H.upd_action #a #pcm r v0 v1))
let free_action #a #pcm e r v0
= lift_tot_action (lift_heap_action e (H.free_action #a #pcm r v0))
let split_action #a #pcm e r v0 v1
= lift_tot_action (lift_heap_action e (H.split_action #a #pcm r v0 v1))
let gather_action #a #pcm e r v0 v1
= lift_tot_action (lift_heap_action e (H.gather_action #a #pcm r v0 v1))
let weaken (p q r:slprop) (h:H.hheap (p `star` q) { H.stronger q r })
: H.hheap (p `star` r)
= H.weaken p q r h; h
let weaken_pure (q r: prop)
: Lemma
(requires (q ==> r))
(ensures H.stronger (H.pure q) (H.pure r))
= let aux (h:H.heap)
: Lemma (ensures (H.interp (H.pure q) h ==> H.interp (H.pure r) h))
[SMTPat ()]
= H.pure_interp q h;
H.pure_interp r h
in
()
let inc_ctr (#p:slprop) #e (m:hmem_with_inv_except e p)
: m':hmem_with_inv_except e p{m'.ctr = m.ctr + 1 /\ H.stronger (linv e m) (linv e m')}
= let m' : mem = { m with ctr = m.ctr + 1} in
assert (interp (p `star` linv e m) m');
assert (linv e m == lock_store_invariant e m.locks
`star`
ctr_validity m.ctr (heap_of_mem m));
assert (linv e m' == lock_store_invariant e m.locks
`star`
ctr_validity (m.ctr + 1) (heap_of_mem m));
H.weaken_free_above (heap_of_mem m) m.ctr (m.ctr + 1);
weaken_pure (heap_ctr_valid m.ctr (heap_of_mem m))
(heap_ctr_valid (m.ctr + 1) (heap_of_mem m));
assert (H.stronger
(ctr_validity m.ctr (heap_of_mem m))
(ctr_validity (m.ctr + 1) (heap_of_mem m)));
H.star_associative p (lock_store_invariant e m.locks)
(ctr_validity m.ctr (heap_of_mem m));
H.stronger_star (lock_store_invariant e m.locks)
(ctr_validity m.ctr (heap_of_mem m))
(ctr_validity (m.ctr + 1) (heap_of_mem m));
H.weaken (p `star` lock_store_invariant e m.locks)
(ctr_validity m.ctr (heap_of_mem m))
(ctr_validity (m.ctr + 1) (heap_of_mem m))
(heap_of_mem m');
H.star_associative p (lock_store_invariant e m.locks)
(ctr_validity (m.ctr + 1) (heap_of_mem m));
let m' : hmem_with_inv_except e p = m' in
m'
let frame_related_mems (fp0 fp1:slprop u#a) e (m0:hmem_with_inv_except e fp0) (m1:hmem_with_inv_except e fp1) =
forall (frame:slprop u#a).
interp ((fp0 `star` frame) `star` linv e m0) m0 ==>
interp ((fp1 `star` frame) `star` linv e m1) m1 /\
mem_evolves m0 m1 /\
(forall (mp:mprop frame). mp (core_mem m0) == mp (core_mem m1))
let refined_pre_action e (fp0:slprop) (a:Type) (fp1:a -> slprop) =
m0:hmem_with_inv_except e fp0 ->
Pure (x:a &
hmem_with_inv_except e (fp1 x))
(requires True)
(ensures fun (| x, m1 |) ->
frame_related_mems fp0 (fp1 x) e m0 m1)
let refined_pre_action_as_action (#fp0:slprop) (#a:Type) (#fp1:a -> slprop)
#e ($f:refined_pre_action e fp0 a fp1)
: tot_action_nf_except e fp0 a fp1
= let g : tot_pre_action_nf_except e fp0 a fp1 = fun m -> f m in
let aux (frame:slprop)
(m0:hmem_with_inv_except e (fp0 `star` frame))
: Lemma
(ensures
(ac_reasoning_for_m_frame_preserving fp0 frame (locks_invariant e m0) m0;
let (| x, m1 |) = g m0 in
interp ((fp1 x `star` frame) `star` locks_invariant e m1) m1 /\
mem_evolves m0 m1 /\
(forall (mp:mprop frame). mp (core_mem m0) == mp (core_mem m1))))
[SMTPat ()]
= ac_reasoning_for_m_frame_preserving fp0 frame (locks_invariant e m0) m0;
let (| x', m1' |) = g m0 in
let (| x, m1 |) = f m0 in
assert (x == x' /\ m1 == m1')
in
g
let alloc_action #a #pcm e x
= let f : refined_pre_action e emp (ref a pcm) (fun r -> pts_to r x)
= fun m0 ->
(* NS: 9/29/22 I needed to annotate h : Heap.full_heap, for use with the Core checker
which generates a guard for checking the implicit pattern "dot" term in the dependent
pair pattern on the next line. That guard expects `h` to be a full_heap, which is it,
because it is a projection of m0. However, this is not reflected in `h`'s type. So,
the Core checker, which produces a guard for the pat_dot_term in isolation, cannot
recheck the term. If we were to fold in the checking of pat_dot_terms and their guards
with the rest of the VC, this would work. *)
let h : Heap.full_heap = hheap_of_hmem m0 in
let (|r, h'|) = H.extend #a #pcm x m0.ctr h in
let m' : hmem_with_inv_except e emp = inc_ctr m0 in
let h' : H.hheap (pts_to #a #pcm r x `star` linv e m') = weaken _ (linv e m0) (linv e m') h' in
let m1 : hmem_with_inv_except e (pts_to #a #pcm r x) = hmem_of_hheap m' h' in
assert (forall frame. H.frame_related_heaps h h' emp (pts_to #a #pcm r x) frame true);
let aux (frame:slprop)
: Lemma
(requires
interp ((emp `star` frame) `star` linv e m0) m0)
(ensures
interp ((pts_to #a #pcm r x `star` frame) `star` linv e m1) m1 /\
mem_evolves m0 m1 /\
(forall (mp:mprop frame). mp (core_mem m0) == mp (core_mem m1)))
[SMTPat (emp `star` frame)]
= star_associative emp frame (linv e m0);
assert (H.interp (emp `star` (frame `star` linv e m0)) h);
assert (H.interp (pts_to #a #pcm r x `star` (frame `star` linv e m0)) h');
star_associative (pts_to #a #pcm r x) frame (linv e m0);
assert (H.interp ((pts_to #a #pcm r x `star` frame) `star` linv e m0) h');
assert (H.stronger (linv e m0) (linv e m'));
assert (H.equiv (linv e m') (linv e m1));
assert (H.stronger (linv e m0) (linv e m1));
let h' : H.hheap ((pts_to #a #pcm r x `star` frame) `star` linv e m1) = weaken _ (linv e m0) (linv e m1) h' in
assert (H.interp ((pts_to #a #pcm r x `star` frame) `star` linv e m1) h');
assert (forall (mp:H.hprop frame). mp h == mp h');
mprop_preservation_of_hprop_preservation frame m0 m1;
assert (forall (mp:mprop frame). mp (core_mem m0) == mp (core_mem m1))
in
assert (frame_related_mems emp (pts_to r x) e m0 m1);
(| r, m1 |)
in
lift_tot_action (refined_pre_action_as_action f)
let select_refine #a #p e r x f
= lift_tot_action (lift_heap_action e (H.select_refine #a #p r x f))
let upd_gen #a #p e r x y f
= lift_tot_action (lift_heap_action e (H.upd_gen_action r x y f))
////////////////////////////////////////////////////////////////////////////////
// witness / recall
////////////////////////////////////////////////////////////////////////////////
let witnessed_ref #a #pcm (r:ref a pcm) (fact:property a) (m:full_mem)
= H.witnessed_ref #a #pcm r fact (heap_of_mem m)
let witnessed_ref_stability #a #pcm (r:ref a pcm) (fact:property a)
: Lemma
(requires FStar.Preorder.stable fact (Steel.Preorder.preorder_of_pcm pcm))
(ensures FStar.Preorder.stable (witnessed_ref r fact) mem_evolves)
= H.witnessed_ref_stability #a #pcm r fact
let witnessed (#a:Type u#1)
(#pcm:pcm a)
(r:ref a pcm)
(fact:property a)
= W.witnessed _ mem_evolves (witnessed_ref r fact)
let rearrange_pqr_prq (p q r:slprop)
: Lemma (((p `star` q) `star` r) `equiv`
((p `star` r) `star` q))
= calc (equiv)
{
(p `star` q) `star` r;
(equiv) { star_associative p q r }
p `star` (q `star` r);
(equiv) {
star_commutative q r;
star_congruence p (q `star` r) p (r `star` q)
}
p `star` (r `star` q);
(equiv) { star_associative p r q }
(p `star` r) `star` q;
}
let preserves_frame_cong (e:inames) (p q:slprop) (r s:slprop) (m0 m1:mem)
: Lemma
(requires p `equiv` r /\ q `equiv` s /\ preserves_frame e p q m0 m1)
(ensures
preserves_frame e r s m0 m1)
= let aux0 (p q r s:slprop)
: Lemma
(requires p `equiv` s)
(ensures (((p `star` q) `star` r) `equiv`
((s `star` q) `star` r)))
= star_congruence p q s q;
star_congruence (p `star` q) r (s `star` q) r
in
let aux (frame:slprop)
: Lemma (requires interp ((r `star` frame) `star` locks_invariant e m0) m0)
(ensures interp ((s `star` frame) `star` locks_invariant e m1) m1 /\
interp ((p `star` frame) `star` locks_invariant e m0) m0)
[SMTPat (r `star` frame)]
= aux0 p frame (locks_invariant e m0) r;
aux0 q frame (locks_invariant e m1) s;
assert (((p `star` frame) `star` locks_invariant e m0) `equiv`
((r `star` frame) `star` locks_invariant e m0));
assert (interp ((p `star` frame) `star` locks_invariant e m0) m0);
assert (interp ((q `star` frame) `star` locks_invariant e m1) m1);
assert (((q `star` frame) `star` locks_invariant e m1) `equiv`
((s `star` frame) `star` locks_invariant e m1));
()
in
()
let pure_true_equiv (p:slprop)
: Lemma ((p `star` pure True) `equiv` p)
= FStar.Classical.forall_intro (pure_star_interp p True);
emp_unit p;
assert ((p `star` pure True) `equiv` p)
let preserves_frame_star_pure (e:inames) (p q:slprop) (r s:prop) (m:mem)
: Lemma
(requires r /\ s)
(ensures
preserves_frame e p q m m <==>
preserves_frame e (p `star` pure r) (q `star` pure s) m m)
= pure_equiv r True;
star_congruence p (pure r) p (pure True);
pure_equiv s True;
star_congruence q (pure s) q (pure True);
pure_true_equiv p;
pure_true_equiv q;
let fwd ()
: Lemma
(requires preserves_frame e p q m m)
(ensures preserves_frame e (p `star` pure r) (q `star` pure s) m m)
[SMTPat ()]
= preserves_frame_cong e p q (p `star` pure r) (q `star` pure s) m m
in
let bk ()
: Lemma
(requires preserves_frame e (p `star` pure r) (q `star` pure s) m m)
(ensures preserves_frame e p q m m)
[SMTPat ()]
= preserves_frame_cong e (p `star` pure r) (q `star` pure s) p q m m
in
()
let witness (#a:Type) (#pcm:pcm a)
(e:inames)
(r:erased (ref a pcm))
(fact:stable_property pcm)
(v:Ghost.erased a)
(_:squash (forall z. compatible pcm v z ==> fact z))
(frame:slprop)
: MstTot (witnessed r fact) e
(pts_to r v)
(fun _ -> pts_to r v) frame
(fun _ -> True)
(fun _ _ _ -> True)
= let m0 = NMSTTotal.get () in
let _ : unit =
let hr : H.ref a pcm = r in
let v' = H.sel_v hr v (heap_of_mem m0) in
assert (interp (H.ptr hr) m0 /\ H.sel #a #pcm hr (heap_of_mem m0) == v');
assert (compatible pcm v v');
assert (fact v');
assert (witnessed_ref r fact m0);
witnessed_ref_stability r fact;
assert (FStar.Preorder.stable (witnessed_ref r fact) mem_evolves)
in
let w = NMSTTotal.witness _ mem_evolves (witnessed_ref r fact) in
w
let recall (#a:Type u#1) (#pcm:pcm a) (#fact:property a)
(e:inames)
(r:erased (ref a pcm))
(v:Ghost.erased a)
(w:witnessed r fact)
(frame:slprop)
= let m0 = NMSTTotal.get () in
NMSTTotal.recall _ mem_evolves (witnessed_ref r fact) w;
let hr : H.ref a pcm = r in
assert (witnessed_ref r fact m0);
let v1 = H.sel_v hr v (heap_of_mem m0) in
assert (compatible pcm v v1);
assert (H.sel hr (heap_of_mem m0) == v1);
assert (fact v1);
assert (interp ((pts_to r v `star` frame) `star` locks_invariant e m0) m0);
emp_unit ((pts_to r v `star` frame) `star` locks_invariant e m0);
pure_star_interp ((pts_to r v `star` frame) `star` locks_invariant e m0) (fact v1) m0;
assert (interp (((pts_to r v `star` frame)
`star` locks_invariant e m0)
`star` pure (fact v1)) m0);
rearrange_pqr_prq (pts_to r v `star` frame)
(locks_invariant e m0)
(pure (fact v1));
assert (interp (((pts_to r v `star` frame) `star` pure (fact v1))
`star` locks_invariant e m0) m0);
rearrange_pqr_prq (pts_to r v) frame (pure (fact v1));
star_congruence ((pts_to r v `star` frame) `star` pure (fact v1))
(locks_invariant e m0)
((pts_to r v `star` pure (fact v1)) `star` frame)
(locks_invariant e m0);
Ghost.hide v1
let iname_for_p_mem (i:iname) (p:slprop) : W.s_predicate mem =
fun m -> iname_for_p i p m.locks
let iname_for_p_stable (i:iname) (p:slprop)
: Lemma (W.stable full_mem mem_evolves (iname_for_p_mem i p))
= ()
let ( >--> ) (i:iname) (p:slprop) : Type0 = W.witnessed full_mem mem_evolves (iname_for_p_mem i p)
let hmem_with_inv_equiv e (m:mem) (p:slprop)
: Lemma (interp (p `star` linv e m) m <==>
interp (p `star` lock_store_invariant e m.locks) m /\
heap_ctr_valid m.ctr (heap_of_mem m))
= calc (<==>) {
interp (p `star` linv e m) m;
(<==>) { H.star_associative p (lock_store_invariant e m.locks) (ctr_validity m.ctr (heap_of_mem m)) }
interp ((p `star` lock_store_invariant e m.locks) `star` ctr_validity m.ctr (heap_of_mem m)) m;
(<==>) { H.pure_star_interp (p `star` lock_store_invariant e m.locks) (heap_ctr_valid m.ctr (heap_of_mem m)) (heap_of_mem m) }
interp ((p `star` lock_store_invariant e m.locks) `star` emp) m /\
(heap_ctr_valid m.ctr (heap_of_mem m));
(<==>) { H.emp_unit (p `star` lock_store_invariant e m.locks) }
interp (p `star` lock_store_invariant e m.locks) m /\
(heap_ctr_valid m.ctr (heap_of_mem m));
}
let new_invariant_tot_action (e:inames) (p:slprop) (m0:hmem_with_inv_except e p{ e `inames_in` m0.locks })
: Pure (iname & hmem_with_inv_except e emp)
(requires True)
(ensures fun (i, m1) ->
iname_for_p_mem i p m1 /\
frame_related_mems p emp e m0 m1 /\
mem_evolves m0 m1)
= let (| i, l1 |) = extend_lock_store e m0.locks p in
let m1 = { m0 with locks = l1 } in
assert (lock_store_invariant e m1.locks ==
p `star` lock_store_invariant e m0.locks);
calc (equiv) {
linv e m1;
(equiv) {}
(lock_store_invariant e m1.locks
`star`
ctr_validity m1.ctr (heap_of_mem m1));
(equiv) {}
((p `star` lock_store_invariant e m0.locks)
`star`
ctr_validity m1.ctr (heap_of_mem m1));
(equiv) {
H.star_associative p (lock_store_invariant e m0.locks) (ctr_validity m1.ctr (heap_of_mem m1))
}
(p `star` (lock_store_invariant e m0.locks
`star`
ctr_validity m1.ctr (heap_of_mem m1)));
(equiv) { }
(p `star` linv e m0);
};
assert (iname_for_p_mem i p m1);
assert (lock_store_evolves m0.locks l1);
assert (mem_evolves m0 m1);
hmem_with_inv_equiv e m0 p;
assert (interp (p `star` lock_store_invariant e m0.locks) m1);
assert (interp (lock_store_invariant e m1.locks) m1);
H.emp_unit (lock_store_invariant e m1.locks);
H.star_commutative (lock_store_invariant e m1.locks) emp;
assert (interp (emp `star` lock_store_invariant e m1.locks) m1);
hmem_with_inv_equiv e m1 emp;
let m1 : hmem_with_inv_except e emp = m1 in
let aux (frame:slprop)
: Lemma
(requires interp ((p `star` frame) `star` linv e m0) m0)
(ensures interp ((emp `star` frame) `star` linv e m1) m1 /\
mem_evolves m0 m1 /\
(forall (mp:mprop frame). mp (core_mem m0) <==> mp (core_mem m1)))
[SMTPat (p `star` frame)]
= assert (interp ((p `star` frame) `star` linv e m0) m1);
calc (equiv) {
((p `star` frame) `star` linv e m0);
(equiv) {
H.star_commutative p frame;
H.star_congruence (p `star` frame) (linv e m0) (frame `star` p) (linv e m0);
H.star_associative frame p (linv e m0)
}
(frame `star` (p `star` linv e m0));
(equiv) {
H.star_congruence frame (p `star` linv e m0) frame (linv e m1)
}
(frame `star` linv e m1);
(equiv) {
H.emp_unit (frame `star` linv e m1);
H.star_commutative (frame `star` linv e m1) emp;
H.star_associative emp frame (linv e m1)
}
((emp `star` frame) `star` linv e m1);
};
assert (interp ((emp `star` frame) `star` linv e m1) m1)
in
assert (frame_related_mems p emp e m0 m1);
( i, m1 )
let name_is_ok (i:iname) (m0:full_mem u#1) : prop = i < List.Tot.length m0.locks
let witnessed_name_is_ok (i:iname) = W.witnessed full_mem mem_evolves (name_is_ok i)
let pre_inv = i:erased iname & witnessed_name_is_ok i
let inv (p:slprop u#1) = i:erased iname & witnessed_name_is_ok i & (i >--> p)
let pre_inv_of_inv #p (i:inv p) = let (|i, w, _|) = i in (|i,w|)
let name_of_pre_inv (i:pre_inv) = dfst i
let rec recall_all (ctx:list pre_inv)
: NMSTTotal.NMSTATETOT unit (full_mem u#1) mem_evolves
(requires fun _ -> True)
(ensures fun m0 _ m1 -> m0==m1 /\ (forall i. i `List.Tot.memP` ctx ==> name_is_ok (name_of_pre_inv i) m0))
= match ctx with
| [] -> ()
| hd::tl ->
let (| q, i |) = hd in
let i : W.witnessed full_mem mem_evolves (name_is_ok q) = i in
NMSTTotal.recall _ mem_evolves (name_is_ok q) i;
recall_all tl | {
"checked_file": "/",
"dependencies": [
"Steel.Preorder.fst.checked",
"Steel.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Witnessed.Core.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.PCM.fst.checked",
"FStar.NMSTTotal.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Memory.fst"
} | [
{
"abbrev": true,
"full_module": "Steel.Preorder",
"short_module": "PP"
},
{
"abbrev": true,
"full_module": "FStar.Witnessed.Core",
"short_module": "W"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "Steel.Heap",
"short_module": "H"
},
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "F"
},
{
"abbrev": true,
"full_module": "FStar.Set",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.PCM",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | e: Steel.Memory.inames -> p: Steel.Memory.slprop -> ctx: Prims.list Steel.Memory.pre_inv
-> Steel.Memory.action_except (i:
Steel.Memory.inv p
{ Prims.op_Negation (FStar.Ghost.reveal (Steel.Memory.mem_inv e i)) /\
Steel.Memory.fresh_wrt ctx (Steel.Memory.name_of_inv i) })
e
p
(fun _ -> Steel.Memory.emp) | Prims.Tot | [
"total"
] | [] | [
"Steel.Memory.inames",
"Steel.Memory.slprop",
"Prims.list",
"Steel.Memory.pre_inv",
"Steel.Memory.iname",
"Steel.Memory.hmem_with_inv_except",
"Steel.Memory.emp",
"FStar.Pervasives.Mkdtuple3",
"FStar.Ghost.erased",
"Steel.Memory.witnessed_name_is_ok",
"FStar.Ghost.reveal",
"Steel.Memory.op_Greater_Subtraction_Subtraction_Greater",
"FStar.Ghost.hide",
"Steel.Memory.inv",
"Prims.l_and",
"Prims.b2t",
"Prims.op_Negation",
"Prims.bool",
"Steel.Memory.mem_inv",
"Steel.Memory.fresh_wrt",
"Steel.Memory.name_of_inv",
"FStar.Witnessed.Core.witnessed",
"Steel.Memory.full_mem",
"Steel.Memory.mem_evolves",
"Steel.Memory.name_is_ok",
"FStar.NMSTTotal.witness",
"Steel.Memory.iname_for_p_mem",
"Prims.unit",
"Steel.Memory.iname_for_p_stable",
"FStar.NMSTTotal.put",
"Prims._assert",
"FStar.Set.mem",
"FStar.Set.set",
"Prims.eq2",
"Prims.nat",
"FStar.List.Tot.Base.length",
"Steel.Memory.lock_state",
"Steel.Memory.__proj__Mkmem__item__locks",
"FStar.Pervasives.Native.tuple2",
"Steel.Memory.new_invariant_tot_action",
"Steel.Memory.interp",
"Steel.Memory.star",
"Steel.Memory.locks_invariant",
"Steel.Memory.ac_reasoning_for_m_frame_preserving",
"Steel.Memory.recall_all",
"FStar.NMSTTotal.get",
"Steel.Memory.mem",
"Prims.l_True",
"Prims.prop"
] | [] | false | false | false | false | false | let fresh_invariant (e: inames) (p: slprop) (ctx: list pre_inv) (frame: slprop)
: MstTot (i: inv p {not (mem_inv e i) /\ fresh_wrt ctx (name_of_inv i)})
e
p
(fun _ -> emp)
frame
(fun _ -> True)
(fun _ _ _ -> True) =
| let m0 = NMSTTotal.get () in
recall_all ctx;
ac_reasoning_for_m_frame_preserving p frame (locks_invariant e m0) m0;
assert (interp (p `star` (locks_invariant e m0)) m0);
let r = new_invariant_tot_action e p m0 in
let i, m1 = r in
assert (i == List.Tot.length m0.locks);
assert (not (Set.mem i e));
assert (mem_evolves m0 m1);
NMSTTotal.put #full_mem #mem_evolves m1;
iname_for_p_stable i p;
let w = NMSTTotal.witness full_mem mem_evolves (iname_for_p_mem i p) in
let w0 = NMSTTotal.witness full_mem mem_evolves (name_is_ok i) in
(| hide i, w0, w |) | false |
Hacl.Spec.Poly1305.Field32xN.Lemmas.fst | Hacl.Spec.Poly1305.Field32xN.Lemmas.load_felem5_lemma | val load_felem5_lemma:
#w:lanes
-> lo:uint64xN w
-> hi:uint64xN w ->
Lemma
(let f = load_felem5 #w lo hi in
felem_fits5 f (1, 1, 1, 1, 1) /\
felem_less5 f (pow2 128) /\
feval5 f == createi #Vec.pfelem w
(fun i -> (uint64xN_v hi).[i] * pow2 64 + (uint64xN_v lo).[i])) | val load_felem5_lemma:
#w:lanes
-> lo:uint64xN w
-> hi:uint64xN w ->
Lemma
(let f = load_felem5 #w lo hi in
felem_fits5 f (1, 1, 1, 1, 1) /\
felem_less5 f (pow2 128) /\
feval5 f == createi #Vec.pfelem w
(fun i -> (uint64xN_v hi).[i] * pow2 64 + (uint64xN_v lo).[i])) | let load_felem5_lemma #w lo hi =
let f = load_felem5 #w lo hi in
assert_norm (pow2 64 * pow2 64 = pow2 128);
assert_norm (pow2 128 < Vec.prime);
let res = createi #Vec.pfelem w
(fun i -> (uint64xN_v hi).[i] * pow2 64 + (uint64xN_v lo).[i]) in
match w with
| 1 ->
load_felem5_lemma_i #w lo hi 0;
eq_intro (feval5 f) res
| 2 ->
load_felem5_lemma_i #w lo hi 0;
load_felem5_lemma_i #w lo hi 1;
eq_intro (feval5 f) res
| 4 ->
load_felem5_lemma_i #w lo hi 0;
load_felem5_lemma_i #w lo hi 1;
load_felem5_lemma_i #w lo hi 2;
load_felem5_lemma_i #w lo hi 3;
eq_intro (feval5 f) res | {
"file_name": "code/poly1305/Hacl.Spec.Poly1305.Field32xN.Lemmas.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 27,
"end_line": 654,
"start_col": 0,
"start_line": 634
} | module Hacl.Spec.Poly1305.Field32xN.Lemmas
open Lib.IntTypes
open Lib.IntVector
open Lib.Sequence
open FStar.Mul
open Hacl.Spec.Poly1305.Field32xN
open Hacl.Poly1305.Field32xN.Lemmas0
open Hacl.Poly1305.Field32xN.Lemmas1
open Hacl.Poly1305.Field32xN.Lemmas2
module Vec = Hacl.Spec.Poly1305.Vec
#set-options "--z3rlimit 100 --max_fuel 0 --initial_ifuel 1 --max_ifuel 1 --using_facts_from '* -FStar.Seq'"
val lemma_feval_is_fas_nat_i:
#w:lanes
-> f:felem5 w{felem_less5 f (pow2 128)}
-> i:size_nat{i < w} ->
Lemma ((feval5 f).[i] == (fas_nat5 f).[i])
let lemma_feval_is_fas_nat_i #w f i =
assert_norm (pow2 128 < Vec.prime);
assert ((feval5 f).[i] == (as_nat5 (transpose f).[i]) % Vec.prime);
FStar.Math.Lemmas.modulo_lemma (as_nat5 (transpose f).[i]) Vec.prime
val lemma_feval_is_fas_nat:
#w:lanes
-> f:felem5 w{felem_less5 f (pow2 128)} ->
Lemma (forall (i:nat). i < w ==> (fas_nat5 f).[i] == (feval5 f).[i])
let lemma_feval_is_fas_nat #w f =
FStar.Classical.forall_intro (lemma_feval_is_fas_nat_i #w f)
val precomp_r5_fits_lemma:
#w:lanes
-> r:felem5 w{felem_fits5 r (1, 1, 1, 1, 1)} ->
Lemma (felem_fits5 (precomp_r5 #w r) (5, 5, 5, 5, 5))
[SMTPat (precomp_r5 #w r)]
let precomp_r5_fits_lemma #w r =
FStar.Classical.forall_intro (precomp_r5_as_tup64 #w r)
val precomp_r5_fits_lemma2:
#w:lanes
-> r:felem5 w{felem_fits5 r (2, 2, 2, 2, 2)} ->
Lemma (felem_fits5 (precomp_r5 #w r) (10, 10, 10, 10, 10))
[SMTPat (precomp_r5 #w r)]
let precomp_r5_fits_lemma2 #w r =
FStar.Classical.forall_intro (precomp_r5_as_tup64 #w r)
val precomp_r5_zeros: w:lanes -> Lemma
(let r = (zero w, zero w, zero w, zero w, zero w) in
precomp_r5 r == (zero w, zero w, zero w, zero w, zero w))
let precomp_r5_zeros w =
let r = (zero w, zero w, zero w, zero w, zero w) in
let (r0, r1, r2, r3, r4) = precomp_r5 r in
let aux (i:nat{i < w}) : Lemma ((vec_v (vec_smul_mod (zero w) (u64 5))).[i] == u64 0) = () in
Classical.forall_intro aux;
eq_intro (vec_v (vec_smul_mod (zero w) (u64 5))) (vec_v (zero w));
vecv_extensionality (vec_smul_mod (zero w) (u64 5)) (zero w)
val fadd5_fits_lemma:
#w:lanes
-> f1:felem5 w{felem_fits5 f1 (2,2,2,2,2)}
-> f2:felem5 w{felem_fits5 f2 (1,1,1,1,1)} ->
Lemma (felem_fits5 (fadd5 f1 f2) (3,3,3,3,3))
[SMTPat (fadd5 f1 f2)]
let fadd5_fits_lemma #w f1 f2 =
let (f10, f11, f12, f13, f14) = f1 in
let (f20, f21, f22, f23, f24) = f2 in
let o = fadd5 f1 f2 in
vec_add_mod_lemma f10 f20;
vec_add_mod_lemma f11 f21;
vec_add_mod_lemma f12 f22;
vec_add_mod_lemma f13 f23;
vec_add_mod_lemma f14 f24
val fadd5_eval_lemma:
#w:lanes
-> f1:felem5 w{felem_fits5 f1 (2,2,2,2,2)}
-> f2:felem5 w{felem_fits5 f2 (1,1,1,1,1)} ->
Lemma (feval5 (fadd5 f1 f2) == map2 Vec.pfadd (feval5 f1) (feval5 f2))
[SMTPat (fadd5 f1 f2)]
let fadd5_eval_lemma #w f1 f2 =
let o = fadd5 f1 f2 in
FStar.Classical.forall_intro (fadd5_eval_lemma_i f1 f2);
eq_intro (feval5 o) (map2 Vec.pfadd (feval5 f1) (feval5 f2))
val mul_felem5_fits_lemma:
#w:lanes
-> f1:felem5 w{felem_fits5 f1 (3, 3, 3, 3, 3)}
-> r:felem5 w{felem_fits5 r (2, 2, 2, 2, 2)}
-> r5:felem5 w{felem_fits5 r5 (10, 10, 10, 10, 10)} ->
Lemma (felem_wide_fits5 (mul_felem5 #w f1 r r5) (126, 102, 78, 54, 30))
[SMTPat (mul_felem5 #w f1 r r5)]
let mul_felem5_fits_lemma #w f1 r r5 =
let (r0, r1, r2, r3, r4) = r in
let (f10, f11, f12, f13, f14) = f1 in
let (r50, r51, r52, r53, r54) = r5 in
let (a0,a1,a2,a3,a4) = smul_felem5 #w f10 (r0,r1,r2,r3,r4) in
smul_felem5_fits_lemma #w #3 #(2,2,2,2,2) f10 (r0,r1,r2,r3,r4);
let (a10,a11,a12,a13,a14) = smul_add_felem5 #w f11 (r54,r0,r1,r2,r3) (a0,a1,a2,a3,a4) in
smul_add_felem5_fits_lemma #w #3 #(10,2,2,2,2) #(6,6,6,6,6) f11 (r54,r0,r1,r2,r3) (a0,a1,a2,a3,a4);
let (a20,a21,a22,a23,a24) = smul_add_felem5 #w f12 (r53,r54,r0,r1,r2) (a10,a11,a12,a13,a14) in
smul_add_felem5_fits_lemma #w #3 #(10,10,2,2,2) #(36,12,12,12,12) f12 (r53,r54,r0,r1,r2) (a10,a11,a12,a13,a14);
let (a30,a31,a32,a33,a34) = smul_add_felem5 #w f13 (r52,r53,r54,r0,r1) (a20,a21,a22,a23,a24) in
smul_add_felem5_fits_lemma #w #3 #(10,10,10,2,2) #(66,42,18,18,18) f13 (r52,r53,r54,r0,r1) (a20,a21,a22,a23,a24);
let (a40,a41,a42,a43,a44) = smul_add_felem5 #w f14 (r51,r52,r53,r54,r0) (a30,a31,a32,a33,a34) in
smul_add_felem5_fits_lemma #w #3 #(10,10,10,10,2) #(96,72,48,24,24) f14 (r51,r52,r53,r54,r0) (a30,a31,a32,a33,a34)
val mul_felem5_eval_lemma_i:
#w:lanes
-> f1:felem5 w{felem_fits5 f1 (3, 3, 3, 3, 3)}
-> r:felem5 w{felem_fits5 r (2, 2, 2, 2, 2)}
-> r5:felem5 w{felem_fits5 r5 (10, 10, 10, 10, 10) /\ r5 == precomp_r5 r}
-> i:nat{i < w} ->
Lemma ((feval5 (mul_felem5 #w f1 r r5)).[i] == (feval5 f1).[i] `Vec.pfmul` (feval5 r).[i])
let mul_felem5_eval_lemma_i #w f1 r r5 i =
let (r0, r1, r2, r3, r4) = r in
let (f10, f11, f12, f13, f14) = f1 in
let (r50, r51, r52, r53, r54) = r5 in
let (a0,a1,a2,a3,a4) = smul_felem5 #w f10 (r0,r1,r2,r3,r4) in
smul_felem5_eval_lemma #w #3 #(2,2,2,2,2) f10 (r0,r1,r2,r3,r4);
smul_felem5_fits_lemma #w #3 #(2,2,2,2,2) f10 (r0,r1,r2,r3,r4);
assert ((fas_nat5 (a0,a1,a2,a3,a4)).[i] == (uint64xN_v f10).[i] * (fas_nat5 (r0,r1,r2,r3,r4)).[i]);
let (a10,a11,a12,a13,a14) = smul_add_felem5 #w f11 (r54,r0,r1,r2,r3) (a0,a1,a2,a3,a4) in
smul_add_felem5_eval_lemma #w #3 #(10,2,2,2,2) #(6,6,6,6,6) f11 (r54,r0,r1,r2,r3) (a0,a1,a2,a3,a4);
smul_add_felem5_fits_lemma #w #3 #(10,2,2,2,2) #(6,6,6,6,6) f11 (r54,r0,r1,r2,r3) (a0,a1,a2,a3,a4);
assert ((fas_nat5 (a10,a11,a12,a13,a14)).[i] == (fas_nat5 (a0,a1,a2,a3,a4)).[i] + (uint64xN_v f11).[i] * (fas_nat5 (r54,r0,r1,r2,r3)).[i]);
let (a20,a21,a22,a23,a24) = smul_add_felem5 #w f12 (r53,r54,r0,r1,r2) (a10,a11,a12,a13,a14) in
smul_add_felem5_eval_lemma #w #3 #(10,10,2,2,2) #(36,12,12,12,12) f12 (r53,r54,r0,r1,r2) (a10,a11,a12,a13,a14);
smul_add_felem5_fits_lemma #w #3 #(10,10,2,2,2) #(36,12,12,12,12) f12 (r53,r54,r0,r1,r2) (a10,a11,a12,a13,a14);
assert ((fas_nat5 (a20,a21,a22,a23,a24)).[i] == (fas_nat5 (a10,a11,a12,a13,a14)).[i] + (uint64xN_v f12).[i] * (fas_nat5 (r53,r54,r0,r1,r2)).[i]);
let (a30,a31,a32,a33,a34) = smul_add_felem5 #w f13 (r52,r53,r54,r0,r1) (a20,a21,a22,a23,a24) in
smul_add_felem5_eval_lemma #w #3 #(10,10,10,2,2) #(66,42,18,18,18) f13 (r52,r53,r54,r0,r1) (a20,a21,a22,a23,a24);
smul_add_felem5_fits_lemma #w #3 #(10,10,10,2,2) #(66,42,18,18,18) f13 (r52,r53,r54,r0,r1) (a20,a21,a22,a23,a24);
assert ((fas_nat5 (a30,a31,a32,a33,a34)).[i] == (fas_nat5 (a20,a21,a22,a23,a24)).[i] + (uint64xN_v f13).[i] * (fas_nat5 (r52,r53,r54,r0,r1)).[i]);
let (a40,a41,a42,a43,a44) = smul_add_felem5 #w f14 (r51,r52,r53,r54,r0) (a30,a31,a32,a33,a34) in
smul_add_felem5_eval_lemma #w #3 #(10,10,10,10,2) #(96,72,48,24,24) f14 (r51,r52,r53,r54,r0) (a30,a31,a32,a33,a34);
smul_add_felem5_fits_lemma #w #3 #(10,10,10,10,2) #(96,72,48,24,24) f14 (r51,r52,r53,r54,r0) (a30,a31,a32,a33,a34);
assert ((fas_nat5 (a40,a41,a42,a43,a44)).[i] == (fas_nat5 (a30,a31,a32,a33,a34)).[i] + (uint64xN_v f14).[i] * (fas_nat5 (r51,r52,r53,r54,r0)).[i]);
assert ((fas_nat5 (a40,a41,a42,a43,a44)).[i] ==
(uint64xN_v f10).[i] * (fas_nat5 (r0,r1,r2,r3,r4)).[i] +
(uint64xN_v f11).[i] * (fas_nat5 (r54,r0,r1,r2,r3)).[i] +
(uint64xN_v f12).[i] * (fas_nat5 (r53,r54,r0,r1,r2)).[i] +
(uint64xN_v f13).[i] * (fas_nat5 (r52,r53,r54,r0,r1)).[i] +
(uint64xN_v f14).[i] * (fas_nat5 (r51,r52,r53,r54,r0)).[i]);
mul_felem5_eval_as_tup64 #w f1 r r5 i;
mul_felem5_lemma (as_tup64_i f1 i) (as_tup64_i r i)
val mul_felem5_eval_lemma:
#w:lanes
-> f1:felem5 w{felem_fits5 f1 (3, 3, 3, 3, 3)}
-> r:felem5 w{felem_fits5 r (2, 2, 2, 2, 2)}
-> r5:felem5 w{felem_fits5 r5 (10, 10, 10, 10, 10) /\ r5 == precomp_r5 r} ->
Lemma (feval5 (mul_felem5 #w f1 r r5) == map2 (Vec.pfmul) (feval5 f1) (feval5 r))
[SMTPat (mul_felem5 #w f1 r r5)]
let mul_felem5_eval_lemma #w f1 r r5 =
let tmp = map2 (Vec.pfmul) (feval5 f1) (feval5 r) in
FStar.Classical.forall_intro (mul_felem5_eval_lemma_i #w f1 r r5);
eq_intro (feval5 (mul_felem5 #w f1 r r5)) tmp
val fmul_r5_fits_lemma:
#w:lanes
-> f1:felem5 w{felem_fits5 f1 (3, 3, 3, 3, 3)}
-> r:felem5 w{felem_fits5 r (2, 2, 2, 2, 2)}
-> r5:felem5 w{felem_fits5 r5 (10, 10, 10, 10, 10)} ->
Lemma (felem_fits5 (fmul_r5 #w f1 r r5) (1, 2, 1, 1, 2))
[SMTPat (fmul_r5 #w f1 r r5)]
let fmul_r5_fits_lemma #w f1 r r5 =
let tmp = mul_felem5 f1 r r5 in
mul_felem5_fits_lemma #w f1 r r5;
let res = carry_wide_felem5 tmp in
carry_wide_felem5_fits_lemma #w tmp
val fmul_r5_eval_lemma:
#w:lanes
-> f1:felem5 w{felem_fits5 f1 (3, 3, 3, 3, 3)}
-> r:felem5 w{felem_fits5 r (2, 2, 2, 2, 2)}
-> r5:felem5 w{felem_fits5 r5 (10, 10, 10, 10, 10) /\ r5 == precomp_r5 r} ->
Lemma (feval5 (fmul_r5 #w f1 r r5) == map2 (Vec.pfmul) (feval5 f1) (feval5 r))
[SMTPat (fmul_r5 #w f1 r r5)]
let fmul_r5_eval_lemma #w f1 r r5 =
let tmp = mul_felem5 f1 r r5 in
mul_felem5_eval_lemma #w f1 r r5;
let res = carry_wide_felem5 tmp in
carry_wide_felem5_eval_lemma #w tmp
val fadd_mul_r5_fits_lemma:
#w:lanes
-> acc:felem5 w{felem_fits5 acc (2, 2, 2, 2, 2)}
-> f1:felem5 w{felem_fits5 f1 (1, 1, 1, 1, 1)}
-> r:felem5 w{felem_fits5 r (1, 1, 1, 1, 1)}
-> r5:felem5 w{felem_fits5 r5 (5, 5, 5, 5, 5)} ->
Lemma (felem_fits5 (fadd_mul_r5 acc f1 r r5) (1, 2, 1, 1, 2))
[SMTPat (fadd_mul_r5 acc f1 r r5)]
let fadd_mul_r5_fits_lemma #w acc f1 r r5 =
let acc1 = fadd5 acc f1 in
fadd5_fits_lemma #w acc f1;
let tmp = mul_felem5 acc1 r r5 in
mul_felem5_fits_lemma #w acc1 r r5;
let res = carry_wide_felem5 tmp in
carry_wide_felem5_fits_lemma #w tmp
val fadd_mul_r5_eval_lemma:
#w:lanes
-> acc:felem5 w{felem_fits5 acc (2, 2, 2, 2, 2)}
-> f1:felem5 w{felem_fits5 f1 (1, 1, 1, 1, 1)}
-> r:felem5 w{felem_fits5 r (1, 1, 1, 1, 1)}
-> r5:felem5 w{felem_fits5 r5 (5, 5, 5, 5, 5) /\ r5 == precomp_r5 r} ->
Lemma (feval5 (fadd_mul_r5 acc f1 r r5) ==
map2 (Vec.pfmul) (map2 (Vec.pfadd) (feval5 acc) (feval5 f1)) (feval5 r))
[SMTPat (fadd_mul_r5 acc f1 r r5)]
let fadd_mul_r5_eval_lemma #w acc f1 r r5 =
let acc1 = fadd5 acc f1 in
fadd5_eval_lemma #w acc f1;
let tmp = mul_felem5 acc1 r r5 in
mul_felem5_eval_lemma #w acc1 r r5;
let res = carry_wide_felem5 tmp in
carry_wide_felem5_eval_lemma #w tmp
val reduce_felem5_eval_lemma:
#w:lanes
-> f:felem5 w{felem_fits5 f (2, 2, 2, 2, 2)} ->
Lemma
(felem_fits5 (reduce_felem5 f) (1, 1, 1, 1, 1) /\
(feval5 f).[0] == (fas_nat5 (reduce_felem5 f)).[0])
[SMTPat (reduce_felem5 f)]
let reduce_felem5_eval_lemma #w f =
carry_full_felem5_eval_lemma f;
carry_full_felem5_fits_lemma f;
let f = carry_full_felem5 f in
carry_reduce_felem5_lemma #w f;
subtract_p5_felem5_lemma #w (carry_full_felem5 f)
val fmul_r2_normalize50:
acc:felem5 2
-> r:felem5 2
-> r2:felem5 2 ->
Pure (felem5 2)
(requires
felem_fits5 acc (3, 3, 3, 3, 3) /\
felem_fits5 r (1, 1, 1, 1, 1) /\
felem_fits5 r2 (2, 2, 2, 2, 2) /\
feval5 r2 == Vec.compute_r2 (feval5 r).[0])
(ensures fun a ->
let fr21 = create2 (feval5 r2).[0] (feval5 r).[0] in
feval5 a == Vec.fmul (feval5 acc) fr21 /\
felem_fits5 a (1, 2, 1, 1, 2))
let fmul_r2_normalize50 (a0, a1, a2, a3, a4) (r0, r1, r2, r3, r4) (r20, r21, r22, r23, r24) =
let r210 = vec_interleave_low r20 r0 in
vec_interleave_low_lemma2 r20 r0;
let r211 = vec_interleave_low r21 r1 in
vec_interleave_low_lemma2 r21 r1;
let r212 = vec_interleave_low r22 r2 in
vec_interleave_low_lemma2 r22 r2;
let r213 = vec_interleave_low r23 r3 in
vec_interleave_low_lemma2 r23 r3;
let r214 = vec_interleave_low r24 r4 in
vec_interleave_low_lemma2 r24 r4;
let acc = (a0, a1, a2, a3, a4) in
let fr = (r0, r1, r2, r3, r4) in
let fr2 = (r20, r21, r22, r23, r24) in
assert ((feval5 fr2).[0] == Vec.pfmul ((feval5 fr).[0]) ((feval5 fr).[0]));
let fr21 = (r210, r211, r212, r213, r214) in
eq_intro (feval5 fr21) (create2 (feval5 fr2).[0] (feval5 fr).[0]);
assert (feval5 fr21 == create2 (feval5 fr2).[0] (feval5 fr).[0]);
assert (felem_fits5 fr21 (2, 2, 2, 2, 2));
let fr215 = precomp_r5 #2 fr21 in
let a = fmul_r5 #2 acc fr21 fr215 in
fmul_r5_eval_lemma acc fr21 fr215;
fmul_r5_fits_lemma acc fr21 fr215;
assert (feval5 a == Vec.fmul (feval5 acc) (feval5 fr21));
assert (felem_fits5 a (1, 2, 1, 1, 2));
a
#push-options "--z3rlimit 150"
val fmul_r2_normalize51:
a:felem5 2
-> fa1:felem5 2 ->
Pure (felem5 2)
(requires
felem_fits5 a (1, 2, 1, 1, 2) /\
felem_fits5 fa1 (1, 2, 1, 1, 2) /\
feval5 fa1 == create2 (feval5 a).[1] (feval5 a).[1])
(ensures fun out ->
(feval5 out).[0] == Vec.pfadd (feval5 a).[0] (feval5 a).[1] /\
felem_fits5 out (2, 4, 2, 2, 4))
let fmul_r2_normalize51 a fa1 =
let (a0, a1, a2, a3, a4) = a in
let (a10, a11, a12, a13, a14) = fa1 in
let o0 = vec_add_mod a0 a10 in
let o1 = vec_add_mod a1 a11 in
let o2 = vec_add_mod a2 a12 in
let o3 = vec_add_mod a3 a13 in
let o4 = vec_add_mod a4 a14 in
let out = (o0, o1, o2, o3, o4) in
let (a0, a1, a2, a3, a4) = as_tup64_i a 0 in
let (a10, a11, a12, a13, a14) = as_tup64_i fa1 0 in
let (o0, o1, o2, o3, o4) = as_tup64_i out 0 in
FStar.Math.Lemmas.modulo_lemma (v a0 + v a10) (pow2 64);
FStar.Math.Lemmas.modulo_lemma (v a1 + v a11) (pow2 64);
FStar.Math.Lemmas.modulo_lemma (v a2 + v a12) (pow2 64);
FStar.Math.Lemmas.modulo_lemma (v a3 + v a13) (pow2 64);
FStar.Math.Lemmas.modulo_lemma (v a4 + v a14) (pow2 64);
assert (felem_fits5 out (2, 4, 2, 2, 4));
calc (==) {
((feval5 a).[0] + (feval5 a).[1]) % Vec.prime;
(==) { }
(as_nat5 (a0, a1, a2, a3, a4) % Vec.prime + as_nat5 (a10, a11, a12, a13, a14) % Vec.prime) % Vec.prime;
(==) { FStar.Math.Lemmas.lemma_mod_plus_distr_l
(as_nat5 (a0, a1, a2, a3, a4)) (as_nat5 (a10, a11, a12, a13, a14)) Vec.prime;
FStar.Math.Lemmas.lemma_mod_plus_distr_r
(as_nat5 (a0, a1, a2, a3, a4) % Vec.prime) (as_nat5 (a10, a11, a12, a13, a14)) Vec.prime }
(as_nat5 (a0, a1, a2, a3, a4) + as_nat5 (a10, a11, a12, a13, a14)) % Vec.prime;
(==) { }
(feval5 out).[0];
};
out
#pop-options
val fmul_r2_normalize5_lemma:
acc:felem5 2
-> r:felem5 2
-> r2:felem5 2 ->
Lemma
(requires
felem_fits5 acc (3, 3, 3, 3, 3) /\
felem_fits5 r (1, 1, 1, 1, 1) /\
felem_fits5 r2 (2, 2, 2, 2, 2) /\
feval5 r2 == Vec.compute_r2 (feval5 r).[0])
(ensures
(let out = fmul_r2_normalize5 acc r r2 in
felem_fits5 out (2, 1, 1, 1, 1) /\
(feval5 out).[0] == Vec.normalize_2 (feval5 r).[0] (feval5 acc)))
[SMTPat (fmul_r2_normalize5 acc r r2)]
let fmul_r2_normalize5_lemma acc r r2 =
let a = fmul_r2_normalize50 acc r r2 in
let (a0, a1, a2, a3, a4) = a in
let a10 = vec_interleave_high a0 a0 in
vec_interleave_high_lemma2 a0 a0;
let a11 = vec_interleave_high a1 a1 in
vec_interleave_high_lemma2 a1 a1;
let a12 = vec_interleave_high a2 a2 in
vec_interleave_high_lemma2 a2 a2;
let a13 = vec_interleave_high a3 a3 in
vec_interleave_high_lemma2 a3 a3;
let a14 = vec_interleave_high a4 a4 in
vec_interleave_high_lemma2 a4 a4;
let fa1 = (a10, a11, a12, a13, a14) in
eq_intro (feval5 fa1) (create2 (feval5 a).[1] (feval5 a).[1]);
assert (feval5 fa1 == create2 (feval5 a).[1] (feval5 a).[1]);
assert (felem_fits5 fa1 (1, 2, 1, 1, 2));
let out = fmul_r2_normalize51 a fa1 in
assert ((feval5 out).[0] == Vec.pfadd (feval5 a).[0] (feval5 a).[1]);
let res = carry_full_felem5 out in
carry_full_felem5_lemma out
val fmul_r4_normalize50:
acc:felem5 4
-> r:felem5 4
-> r2:felem5 4
-> r3:felem5 4
-> r4:felem5 4 ->
Pure (felem5 4)
(requires
felem_fits5 acc (3, 3, 3, 3, 3) /\
felem_fits5 r (1, 1, 1, 1, 1) /\
felem_fits5 r2 (2, 2, 2, 2, 2) /\
felem_fits5 r3 (2, 2, 2, 2, 2) /\
felem_fits5 r4 (2, 2, 2, 2, 2) /\
feval5 r2 == Vec.fmul (feval5 r) (feval5 r) /\
feval5 r3 == Vec.fmul (feval5 r2) (feval5 r) /\
feval5 r4 == Vec.compute_r4 (feval5 r).[0])
(ensures fun out ->
let fr4321 = create4 (feval5 r4).[0] (feval5 r3).[0] (feval5 r2).[0] (feval5 r).[0] in
feval5 out == Vec.fmul (feval5 acc) fr4321 /\
felem_fits5 out (1, 2, 1, 1, 2))
let fmul_r4_normalize50 acc fr fr2 fr3 fr4 =
let (r10, r11, r12, r13, r14) = fr in
let (r20, r21, r22, r23, r24) = fr2 in
let (r30, r31, r32, r33, r34) = fr3 in
let (r40, r41, r42, r43, r44) = fr4 in
let (a0, a1, a2, a3, a4) = acc in
let v12120 = vec_interleave_low r20 r10 in
vec_interleave_low_lemma_uint64_4 r20 r10;
let v34340 = vec_interleave_low r40 r30 in
vec_interleave_low_lemma_uint64_4 r40 r30;
let r12340 = vec_interleave_low_n 2 v34340 v12120 in
vec_interleave_low_n_lemma_uint64_4_2 v34340 v12120;
let v12121 = vec_interleave_low r21 r11 in
vec_interleave_low_lemma_uint64_4 r21 r11;
let v34341 = vec_interleave_low r41 r31 in
vec_interleave_low_lemma_uint64_4 r41 r31;
let r12341 = vec_interleave_low_n 2 v34341 v12121 in
vec_interleave_low_n_lemma_uint64_4_2 v34341 v12121;
let v12122 = vec_interleave_low r22 r12 in
vec_interleave_low_lemma_uint64_4 r22 r12;
let v34342 = vec_interleave_low r42 r32 in
vec_interleave_low_lemma_uint64_4 r42 r32;
let r12342 = vec_interleave_low_n 2 v34342 v12122 in
vec_interleave_low_n_lemma_uint64_4_2 v34342 v12122;
let v12123 = vec_interleave_low r23 r13 in
vec_interleave_low_lemma_uint64_4 r23 r13;
let v34343 = vec_interleave_low r43 r33 in
vec_interleave_low_lemma_uint64_4 r43 r33;
let r12343 = vec_interleave_low_n 2 v34343 v12123 in
vec_interleave_low_n_lemma_uint64_4_2 v34343 v12123;
let v12124 = vec_interleave_low r24 r14 in
vec_interleave_low_lemma_uint64_4 r24 r14;
let v34344 = vec_interleave_low r44 r34 in
vec_interleave_low_lemma_uint64_4 r44 r34;
let r12344 = vec_interleave_low_n 2 v34344 v12124 in
vec_interleave_low_n_lemma_uint64_4_2 v34344 v12124;
let fr1234 = (r12340, r12341, r12342, r12343, r12344) in
eq_intro (feval5 fr1234) (create4 (feval5 fr4).[0] (feval5 fr3).[0] (feval5 fr2).[0] (feval5 fr).[0]);
let fr12345 = precomp_r5 #4 fr1234 in
let out = fmul_r5 #4 acc fr1234 fr12345 in
fmul_r5_eval_lemma acc fr1234 fr12345;
fmul_r5_fits_lemma acc fr1234 fr12345;
out
val lemma_fmul_r4_normalize51:
#m:scale32{m <= 2}
-> o:uint64xN 4{felem_fits1 o m} ->
Lemma
(let v00 = vec_interleave_high_n 2 o o in
let v10 = vec_add_mod o v00 in
let v10h = vec_interleave_high v10 v10 in
let v20 = vec_add_mod v10 v10h in
felem_fits1 v20 (4 * m) /\
(uint64xN_v v20).[0] == (uint64xN_v o).[0] + (uint64xN_v o).[1] + (uint64xN_v o).[2] + (uint64xN_v o).[3])
let lemma_fmul_r4_normalize51 #m o =
let v00 = vec_interleave_high_n 2 o o in
vec_interleave_high_n_lemma_uint64_4_2 o o;
let (o0, o1, o2, o3) = ((vec_v o).[0], (vec_v o).[1], (vec_v o).[2], (vec_v o).[3]) in
assert (vec_v v00 == create4 o2 o3 o2 o3);
let v10 = vec_add_mod o v00 in
FStar.Math.Lemmas.modulo_lemma (v o0 + v o2) (pow2 64);
FStar.Math.Lemmas.modulo_lemma (v o1 + v o3) (pow2 64);
assert (v (vec_v v10).[0] == v o0 + v o2);
assert (v (vec_v v10).[1] == v o1 + v o3);
let v10h = vec_interleave_high v10 v10 in
vec_interleave_high_lemma_uint64_4 v10 v10;
assert (v (vec_v v10h).[0] == v (vec_v v10).[1]);
let v20 = vec_add_mod v10 v10h in
FStar.Math.Lemmas.modulo_lemma (v o0 + v o2 + v o1 + v o3) (pow2 64)
val lemma_fmul_r4_normalize51_expand:
v2:felem5 4
-> out:felem5 4 ->
Lemma
(requires
(let (v20, v21, v22, v23, v24) = v2 in
let (o0, o1, o2, o3, o4) = out in
(uint64xN_v v20).[0] == (uint64xN_v o0).[0] + (uint64xN_v o0).[1] + (uint64xN_v o0).[2] + (uint64xN_v o0).[3] /\
(uint64xN_v v21).[0] == (uint64xN_v o1).[0] + (uint64xN_v o1).[1] + (uint64xN_v o1).[2] + (uint64xN_v o1).[3] /\
(uint64xN_v v22).[0] == (uint64xN_v o2).[0] + (uint64xN_v o2).[1] + (uint64xN_v o2).[2] + (uint64xN_v o2).[3] /\
(uint64xN_v v23).[0] == (uint64xN_v o3).[0] + (uint64xN_v o3).[1] + (uint64xN_v o3).[2] + (uint64xN_v o3).[3] /\
(uint64xN_v v24).[0] == (uint64xN_v o4).[0] + (uint64xN_v o4).[1] + (uint64xN_v o4).[2] + (uint64xN_v o4).[3]))
(ensures
(let (v20, v21, v22, v23, v24) = v2 in
let (o0, o1, o2, o3, o4) = out in
(feval5 v2).[0] == Vec.pfadd (Vec.pfadd (Vec.pfadd (feval5 out).[0] (feval5 out).[1]) (feval5 out).[2]) (feval5 out).[3]))
let lemma_fmul_r4_normalize51_expand v2 out =
let (v20, v21, v22, v23, v24) = as_tup64_i v2 0 in
let (o0, o1, o2, o3, o4) = out in
calc (==) {
as_nat5 (v20, v21, v22, v23, v24) % Vec.prime;
(==) { }
(as_nat5 (as_tup64_i out 0) + as_nat5 (as_tup64_i out 1) + as_nat5 (as_tup64_i out 2) + as_nat5 (as_tup64_i out 3)) % Vec.prime;
(==) { FStar.Math.Lemmas.lemma_mod_plus_distr_l (as_nat5 (as_tup64_i out 0) + as_nat5 (as_tup64_i out 1))
(as_nat5 (as_tup64_i out 2) + as_nat5 (as_tup64_i out 3)) Vec.prime }
((as_nat5 (as_tup64_i out 0) + as_nat5 (as_tup64_i out 1)) % Vec.prime + as_nat5 (as_tup64_i out 2) + as_nat5 (as_tup64_i out 3)) % Vec.prime;
(==) { FStar.Math.Lemmas.modulo_distributivity (as_nat5 (as_tup64_i out 0)) (as_nat5 (as_tup64_i out 1)) Vec.prime }
(((feval5 out).[0] + (feval5 out).[1]) % Vec.prime + as_nat5 (as_tup64_i out 2) + as_nat5 (as_tup64_i out 3)) % Vec.prime;
(==) { FStar.Math.Lemmas.lemma_mod_plus_distr_l (((feval5 out).[0] + (feval5 out).[1]) % Vec.prime + as_nat5 (as_tup64_i out 2))
(as_nat5 (as_tup64_i out 3)) Vec.prime }
((((feval5 out).[0] + (feval5 out).[1]) % Vec.prime + as_nat5 (as_tup64_i out 2)) % Vec.prime + as_nat5 (as_tup64_i out 3)) % Vec.prime;
(==) { FStar.Math.Lemmas.lemma_mod_plus_distr_r (((feval5 out).[0] + (feval5 out).[1]) % Vec.prime) (as_nat5 (as_tup64_i out 2)) Vec.prime }
((((feval5 out).[0] + (feval5 out).[1]) % Vec.prime + (feval5 out).[2]) % Vec.prime + as_nat5 (as_tup64_i out 3)) % Vec.prime;
(==) { FStar.Math.Lemmas.lemma_mod_plus_distr_r ((((feval5 out).[0] + (feval5 out).[1]) % Vec.prime + (feval5 out).[2]) % Vec.prime)
(as_nat5 (as_tup64_i out 3)) Vec.prime }
((((feval5 out).[0] + (feval5 out).[1]) % Vec.prime + (feval5 out).[2]) % Vec.prime + (feval5 out).[3]) % Vec.prime;
};
assert ((feval5 v2).[0] ==
((((feval5 out).[0] + (feval5 out).[1]) % Vec.prime + (feval5 out).[2]) % Vec.prime + (feval5 out).[3]) % Vec.prime)
val fmul_r4_normalize51: a:felem5 4 ->
Pure (felem5 4)
(requires felem_fits5 a (1, 2, 1, 1, 2))
(ensures fun res ->
felem_fits5 res (4, 8, 4, 4, 8) /\
(feval5 res).[0] == Vec.pfadd (Vec.pfadd (Vec.pfadd (feval5 a).[0] (feval5 a).[1]) (feval5 a).[2]) (feval5 a).[3])
let fmul_r4_normalize51 fa =
let (o0, o1, o2, o3, o4) = fa in
let v00 = vec_interleave_high_n 2 o0 o0 in
let v10 = vec_add_mod o0 v00 in
let v10h = vec_interleave_high v10 v10 in
let v20 = vec_add_mod v10 v10h in
lemma_fmul_r4_normalize51 #1 o0;
let v01 = vec_interleave_high_n 2 o1 o1 in
let v11 = vec_add_mod o1 v01 in
let v11h = vec_interleave_high v11 v11 in
let v21 = vec_add_mod v11 v11h in
lemma_fmul_r4_normalize51 #2 o1;
let v02 = vec_interleave_high_n 2 o2 o2 in
let v12 = vec_add_mod o2 v02 in
let v12h = vec_interleave_high v12 v12 in
let v22 = vec_add_mod v12 v12h in
lemma_fmul_r4_normalize51 #1 o2;
let v03 = vec_interleave_high_n 2 o3 o3 in
let v13 = vec_add_mod o3 v03 in
let v13h = vec_interleave_high v13 v13 in
let v23 = vec_add_mod v13 v13h in
lemma_fmul_r4_normalize51 #1 o3;
let v04 = vec_interleave_high_n 2 o4 o4 in
let v14 = vec_add_mod o4 v04 in
let v14h = vec_interleave_high v14 v14 in
let v24 = vec_add_mod v14 v14h in
lemma_fmul_r4_normalize51 #2 o4;
let res = (v20, v21, v22, v23, v24) in
lemma_fmul_r4_normalize51_expand res fa;
res
val fmul_r4_normalize5_lemma:
acc:felem5 4
-> r:felem5 4
-> r_5:felem5 4
-> r4:felem5 4 ->
Lemma
(requires
felem_fits5 acc (3, 3, 3, 3, 3) /\
felem_fits5 r (1, 1, 1, 1, 1) /\
felem_fits5 r4 (2, 2, 2, 2, 2) /\
r_5 == precomp_r5 r /\
feval5 r4 == Vec.compute_r4 (feval5 r).[0])
(ensures
(let out = fmul_r4_normalize5 acc r r_5 r4 in
felem_fits5 out (2, 1, 1, 1, 1) /\
(feval5 out).[0] == Vec.normalize_4 (feval5 r).[0] (feval5 acc)))
[SMTPat (fmul_r4_normalize5 acc r r_5 r4)]
#restart-solver
#push-options "--z3rlimit 500"
let fmul_r4_normalize5_lemma acc fr fr_5 fr4 =
let fr2 = fmul_r5 #4 fr fr fr_5 in
let fr3 = fmul_r5 #4 fr2 fr fr_5 in
let out = fmul_r4_normalize50 acc fr fr2 fr3 fr4 in
let v2 = fmul_r4_normalize51 out in
let res = carry_full_felem5 v2 in
carry_full_felem5_lemma v2
#pop-options
val load_felem5_lemma:
#w:lanes
-> lo:uint64xN w
-> hi:uint64xN w ->
Lemma
(let f = load_felem5 #w lo hi in
felem_fits5 f (1, 1, 1, 1, 1) /\
felem_less5 f (pow2 128) /\
feval5 f == createi #Vec.pfelem w
(fun i -> (uint64xN_v hi).[i] * pow2 64 + (uint64xN_v lo).[i])) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.Poly1305.Vec.fst.checked",
"Hacl.Spec.Poly1305.Field32xN.fst.checked",
"Hacl.Poly1305.Field32xN.Lemmas2.fst.checked",
"Hacl.Poly1305.Field32xN.Lemmas1.fst.checked",
"Hacl.Poly1305.Field32xN.Lemmas0.fst.checked",
"Hacl.Impl.Poly1305.Lemmas.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Poly1305.Field32xN.Lemmas.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Poly1305.Vec",
"short_module": "Vec"
},
{
"abbrev": false,
"full_module": "Hacl.Poly1305.Field32xN.Lemmas2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Poly1305.Field32xN.Lemmas1",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Poly1305.Field32xN.Lemmas0",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Poly1305.Field32xN",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Poly1305.Field32xN",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Poly1305.Field32xN",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | lo: Hacl.Spec.Poly1305.Field32xN.uint64xN w -> hi: Hacl.Spec.Poly1305.Field32xN.uint64xN w
-> FStar.Pervasives.Lemma
(ensures
(let f = Hacl.Spec.Poly1305.Field32xN.load_felem5 lo hi in
Hacl.Spec.Poly1305.Field32xN.felem_fits5 f (1, 1, 1, 1, 1) /\
Hacl.Spec.Poly1305.Field32xN.felem_less5 f (Prims.pow2 128) /\
Hacl.Spec.Poly1305.Field32xN.feval5 f ==
Lib.Sequence.createi w
(fun i ->
(Hacl.Spec.Poly1305.Field32xN.uint64xN_v hi).[ i ] * Prims.pow2 64 +
(Hacl.Spec.Poly1305.Field32xN.uint64xN_v lo).[ i ]))) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Hacl.Spec.Poly1305.Field32xN.lanes",
"Hacl.Spec.Poly1305.Field32xN.uint64xN",
"Lib.Sequence.eq_intro",
"Hacl.Spec.Poly1305.Vec.pfelem",
"Hacl.Spec.Poly1305.Field32xN.feval5",
"Prims.unit",
"Hacl.Poly1305.Field32xN.Lemmas2.load_felem5_lemma_i",
"Lib.Sequence.lseq",
"Prims.l_Forall",
"Prims.nat",
"Prims.l_imp",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.eq2",
"Lib.Sequence.index",
"Prims.op_Addition",
"Prims.op_Multiply",
"Hacl.Spec.Poly1305.Field32xN.uint64xN_v",
"Prims.pow2",
"Lib.Sequence.createi",
"FStar.Mul.op_Star",
"Lib.Sequence.op_String_Access",
"FStar.Pervasives.assert_norm",
"Hacl.Spec.Poly1305.Vec.prime",
"Prims.op_Equality",
"Prims.int",
"Hacl.Spec.Poly1305.Field32xN.felem5",
"Hacl.Spec.Poly1305.Field32xN.load_felem5"
] | [] | false | false | true | false | false | let load_felem5_lemma #w lo hi =
| let f = load_felem5 #w lo hi in
assert_norm (pow2 64 * pow2 64 = pow2 128);
assert_norm (pow2 128 < Vec.prime);
let res =
createi #Vec.pfelem w (fun i -> (uint64xN_v hi).[ i ] * pow2 64 + (uint64xN_v lo).[ i ])
in
match w with
| 1 ->
load_felem5_lemma_i #w lo hi 0;
eq_intro (feval5 f) res
| 2 ->
load_felem5_lemma_i #w lo hi 0;
load_felem5_lemma_i #w lo hi 1;
eq_intro (feval5 f) res
| 4 ->
load_felem5_lemma_i #w lo hi 0;
load_felem5_lemma_i #w lo hi 1;
load_felem5_lemma_i #w lo hi 2;
load_felem5_lemma_i #w lo hi 3;
eq_intro (feval5 f) res | false |
LowParse.Spec.Int.fst | LowParse.Spec.Int.decode_u8 | val decode_u8 (b: bytes{Seq.length b == 1}) : Tot U8.t | val decode_u8 (b: bytes{Seq.length b == 1}) : Tot U8.t | let decode_u8
(b: bytes { Seq.length b == 1 } )
: Tot U8.t
= Seq.index b 0 | {
"file_name": "src/lowparse/LowParse.Spec.Int.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 15,
"end_line": 7,
"start_col": 0,
"start_line": 4
} | module LowParse.Spec.Int
open LowParse.Spec.Combinators | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Seq.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "LowParse.Spec.Int.fst"
} | [
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.Endianness",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | b: LowParse.Bytes.bytes{FStar.Seq.Base.length b == 1} -> FStar.UInt8.t | Prims.Tot | [
"total"
] | [] | [
"LowParse.Bytes.bytes",
"Prims.eq2",
"Prims.int",
"FStar.Seq.Base.length",
"LowParse.Bytes.byte",
"FStar.Seq.Base.index",
"FStar.UInt8.t"
] | [] | false | false | false | false | false | let decode_u8 (b: bytes{Seq.length b == 1}) : Tot U8.t =
| Seq.index b 0 | false |
LowParse.Spec.Int.fst | LowParse.Spec.Int.serialize_u16 | val serialize_u16 : serializer parse_u16 | val serialize_u16 : serializer parse_u16 | let serialize_u16 =
(fun (x: U16.t) -> E.n_to_be 2 (U16.v x)) | {
"file_name": "src/lowparse/LowParse.Spec.Int.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 43,
"end_line": 68,
"start_col": 0,
"start_line": 67
} | module LowParse.Spec.Int
open LowParse.Spec.Combinators
let decode_u8
(b: bytes { Seq.length b == 1 } )
: Tot U8.t
= Seq.index b 0
let decode_u8_injective () : Lemma
(make_total_constant_size_parser_precond 1 U8.t decode_u8)
= ()
let tot_parse_u8 =
decode_u8_injective ();
tot_make_total_constant_size_parser 1 U8.t decode_u8
let parse_u8_spec
b
=
Seq.lemma_index_slice b 0 1 0;
E.reveal_be_to_n (Seq.slice b 0 1);
E.reveal_be_to_n (Seq.slice (Seq.slice b 0 1) 0 0)
let parse_u8_spec' b = ()
let serialize_u8 =
Seq.create 1
let serialize_u8_spec x = ()
let decode_u16
(b: bytes { Seq.length b == 2 } )
: GTot U16.t
= E.lemma_be_to_n_is_bounded b;
U16.uint_to_t (E.be_to_n b)
let decode_u16_injective'
(b1: bytes { Seq.length b1 == 2 } )
(b2: bytes { Seq.length b2 == 2 } )
: Lemma
(decode_u16 b1 == decode_u16 b2 ==> Seq.equal b1 b2)
= if decode_u16 b1 = decode_u16 b2
then begin
E.lemma_be_to_n_is_bounded b1;
E.lemma_be_to_n_is_bounded b2;
assert (U32.v (U32.uint_to_t (E.be_to_n b1)) == E.be_to_n b1);
assert (U32.v (U32.uint_to_t (E.be_to_n b2)) == E.be_to_n b2);
assert (E.be_to_n b1 == E.be_to_n b2);
E.be_to_n_inj b1 b2
end else ()
let decode_u16_injective
()
: Lemma
(make_total_constant_size_parser_precond 2 U16.t decode_u16)
= Classical.forall_intro_2 decode_u16_injective'
let parse_u16 =
decode_u16_injective ();
make_total_constant_size_parser 2 U16.t decode_u16
let parse_u16_spec
b
=
E.lemma_be_to_n_is_bounded (Seq.slice b 0 2) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Seq.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "LowParse.Spec.Int.fst"
} | [
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.Endianness",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | LowParse.Spec.Base.serializer LowParse.Spec.Int.parse_u16 | Prims.Tot | [
"total"
] | [] | [
"FStar.UInt16.t",
"FStar.Endianness.n_to_be",
"FStar.UInt16.v",
"FStar.Endianness.bytes",
"Prims.l_and",
"Prims.eq2",
"Prims.nat",
"FStar.Seq.Base.length",
"FStar.UInt8.t",
"FStar.Endianness.be_to_n"
] | [] | false | false | false | true | false | let serialize_u16 =
| (fun (x: U16.t) -> E.n_to_be 2 (U16.v x)) | false |
LowParse.Spec.Int.fst | LowParse.Spec.Int.serialize_u8 | val serialize_u8 : serializer parse_u8 | val serialize_u8 : serializer parse_u8 | let serialize_u8 =
Seq.create 1 | {
"file_name": "src/lowparse/LowParse.Spec.Int.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 14,
"end_line": 27,
"start_col": 0,
"start_line": 26
} | module LowParse.Spec.Int
open LowParse.Spec.Combinators
let decode_u8
(b: bytes { Seq.length b == 1 } )
: Tot U8.t
= Seq.index b 0
let decode_u8_injective () : Lemma
(make_total_constant_size_parser_precond 1 U8.t decode_u8)
= ()
let tot_parse_u8 =
decode_u8_injective ();
tot_make_total_constant_size_parser 1 U8.t decode_u8
let parse_u8_spec
b
=
Seq.lemma_index_slice b 0 1 0;
E.reveal_be_to_n (Seq.slice b 0 1);
E.reveal_be_to_n (Seq.slice (Seq.slice b 0 1) 0 0)
let parse_u8_spec' b = () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Seq.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "LowParse.Spec.Int.fst"
} | [
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.Endianness",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | LowParse.Spec.Base.serializer LowParse.Spec.Int.parse_u8 | Prims.Tot | [
"total"
] | [] | [
"FStar.Seq.Base.create",
"LowParse.Bytes.byte"
] | [] | false | false | false | true | false | let serialize_u8 =
| Seq.create 1 | false |
LowParse.Spec.Int.fst | LowParse.Spec.Int.parse_u64 | val parse_u64: parser parse_u64_kind U64.t | val parse_u64: parser parse_u64_kind U64.t | let parse_u64 =
decode_u64_injective ();
make_total_constant_size_parser 8 U64.t decode_u64 | {
"file_name": "src/lowparse/LowParse.Spec.Int.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 52,
"end_line": 134,
"start_col": 0,
"start_line": 132
} | module LowParse.Spec.Int
open LowParse.Spec.Combinators
let decode_u8
(b: bytes { Seq.length b == 1 } )
: Tot U8.t
= Seq.index b 0
let decode_u8_injective () : Lemma
(make_total_constant_size_parser_precond 1 U8.t decode_u8)
= ()
let tot_parse_u8 =
decode_u8_injective ();
tot_make_total_constant_size_parser 1 U8.t decode_u8
let parse_u8_spec
b
=
Seq.lemma_index_slice b 0 1 0;
E.reveal_be_to_n (Seq.slice b 0 1);
E.reveal_be_to_n (Seq.slice (Seq.slice b 0 1) 0 0)
let parse_u8_spec' b = ()
let serialize_u8 =
Seq.create 1
let serialize_u8_spec x = ()
let decode_u16
(b: bytes { Seq.length b == 2 } )
: GTot U16.t
= E.lemma_be_to_n_is_bounded b;
U16.uint_to_t (E.be_to_n b)
let decode_u16_injective'
(b1: bytes { Seq.length b1 == 2 } )
(b2: bytes { Seq.length b2 == 2 } )
: Lemma
(decode_u16 b1 == decode_u16 b2 ==> Seq.equal b1 b2)
= if decode_u16 b1 = decode_u16 b2
then begin
E.lemma_be_to_n_is_bounded b1;
E.lemma_be_to_n_is_bounded b2;
assert (U32.v (U32.uint_to_t (E.be_to_n b1)) == E.be_to_n b1);
assert (U32.v (U32.uint_to_t (E.be_to_n b2)) == E.be_to_n b2);
assert (E.be_to_n b1 == E.be_to_n b2);
E.be_to_n_inj b1 b2
end else ()
let decode_u16_injective
()
: Lemma
(make_total_constant_size_parser_precond 2 U16.t decode_u16)
= Classical.forall_intro_2 decode_u16_injective'
let parse_u16 =
decode_u16_injective ();
make_total_constant_size_parser 2 U16.t decode_u16
let parse_u16_spec
b
=
E.lemma_be_to_n_is_bounded (Seq.slice b 0 2)
let serialize_u16 =
(fun (x: U16.t) -> E.n_to_be 2 (U16.v x))
let decode_u32
(b: bytes { Seq.length b == 4 } )
: GTot U32.t
= E.lemma_be_to_n_is_bounded b;
U32.uint_to_t (E.be_to_n b)
let decode_u32_injective'
(b1: bytes { Seq.length b1 == 4 } )
(b2: bytes { Seq.length b2 == 4 } )
: Lemma
(decode_u32 b1 == decode_u32 b2 ==> Seq.equal b1 b2)
= if decode_u32 b1 = decode_u32 b2
then begin
E.lemma_be_to_n_is_bounded b1;
E.lemma_be_to_n_is_bounded b2;
assert (U32.v (U32.uint_to_t (E.be_to_n b1)) == E.be_to_n b1);
assert (U32.v (U32.uint_to_t (E.be_to_n b2)) == E.be_to_n b2);
assert (E.be_to_n b1 == E.be_to_n b2);
E.be_to_n_inj b1 b2
end else ()
let decode_u32_injective () : Lemma
(make_total_constant_size_parser_precond 4 U32.t decode_u32)
= Classical.forall_intro_2 decode_u32_injective'
let parse_u32 =
decode_u32_injective ();
make_total_constant_size_parser 4 U32.t decode_u32
let parse_u32_spec
b
=
E.lemma_be_to_n_is_bounded (Seq.slice b 0 4)
let serialize_u32 =
(fun (x: U32.t) -> E.n_to_be 4 (U32.v x))
let decode_u64
(b: bytes { Seq.length b == 8 } )
: GTot U64.t
= E.lemma_be_to_n_is_bounded b;
U64.uint_to_t (E.be_to_n b)
let decode_u64_injective'
(b1: bytes { Seq.length b1 == 8 } )
(b2: bytes { Seq.length b2 == 8 } )
: Lemma
(decode_u64 b1 == decode_u64 b2 ==> Seq.equal b1 b2)
= if decode_u64 b1 = decode_u64 b2
then begin
E.lemma_be_to_n_is_bounded b1;
E.lemma_be_to_n_is_bounded b2;
assert (U64.v (U64.uint_to_t (E.be_to_n b1)) == E.be_to_n b1);
assert (U64.v (U64.uint_to_t (E.be_to_n b2)) == E.be_to_n b2);
assert (E.be_to_n b1 == E.be_to_n b2);
E.be_to_n_inj b1 b2
end else ()
let decode_u64_injective () : Lemma
(make_total_constant_size_parser_precond 8 U64.t decode_u64)
= Classical.forall_intro_2 decode_u64_injective' | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Seq.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "LowParse.Spec.Int.fst"
} | [
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.Endianness",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | LowParse.Spec.Base.parser LowParse.Spec.Int.parse_u64_kind FStar.UInt64.t | Prims.Tot | [
"total"
] | [] | [
"LowParse.Spec.Combinators.make_total_constant_size_parser",
"FStar.UInt64.t",
"LowParse.Spec.Int.decode_u64",
"Prims.unit",
"LowParse.Spec.Int.decode_u64_injective"
] | [] | false | false | false | true | false | let parse_u64 =
| decode_u64_injective ();
make_total_constant_size_parser 8 U64.t decode_u64 | false |
LowParse.Spec.Int.fst | LowParse.Spec.Int.decode_u32_injective | val decode_u32_injective: Prims.unit
-> Lemma (make_total_constant_size_parser_precond 4 U32.t decode_u32) | val decode_u32_injective: Prims.unit
-> Lemma (make_total_constant_size_parser_precond 4 U32.t decode_u32) | let decode_u32_injective () : Lemma
(make_total_constant_size_parser_precond 4 U32.t decode_u32)
= Classical.forall_intro_2 decode_u32_injective' | {
"file_name": "src/lowparse/LowParse.Spec.Int.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 48,
"end_line": 93,
"start_col": 0,
"start_line": 91
} | module LowParse.Spec.Int
open LowParse.Spec.Combinators
let decode_u8
(b: bytes { Seq.length b == 1 } )
: Tot U8.t
= Seq.index b 0
let decode_u8_injective () : Lemma
(make_total_constant_size_parser_precond 1 U8.t decode_u8)
= ()
let tot_parse_u8 =
decode_u8_injective ();
tot_make_total_constant_size_parser 1 U8.t decode_u8
let parse_u8_spec
b
=
Seq.lemma_index_slice b 0 1 0;
E.reveal_be_to_n (Seq.slice b 0 1);
E.reveal_be_to_n (Seq.slice (Seq.slice b 0 1) 0 0)
let parse_u8_spec' b = ()
let serialize_u8 =
Seq.create 1
let serialize_u8_spec x = ()
let decode_u16
(b: bytes { Seq.length b == 2 } )
: GTot U16.t
= E.lemma_be_to_n_is_bounded b;
U16.uint_to_t (E.be_to_n b)
let decode_u16_injective'
(b1: bytes { Seq.length b1 == 2 } )
(b2: bytes { Seq.length b2 == 2 } )
: Lemma
(decode_u16 b1 == decode_u16 b2 ==> Seq.equal b1 b2)
= if decode_u16 b1 = decode_u16 b2
then begin
E.lemma_be_to_n_is_bounded b1;
E.lemma_be_to_n_is_bounded b2;
assert (U32.v (U32.uint_to_t (E.be_to_n b1)) == E.be_to_n b1);
assert (U32.v (U32.uint_to_t (E.be_to_n b2)) == E.be_to_n b2);
assert (E.be_to_n b1 == E.be_to_n b2);
E.be_to_n_inj b1 b2
end else ()
let decode_u16_injective
()
: Lemma
(make_total_constant_size_parser_precond 2 U16.t decode_u16)
= Classical.forall_intro_2 decode_u16_injective'
let parse_u16 =
decode_u16_injective ();
make_total_constant_size_parser 2 U16.t decode_u16
let parse_u16_spec
b
=
E.lemma_be_to_n_is_bounded (Seq.slice b 0 2)
let serialize_u16 =
(fun (x: U16.t) -> E.n_to_be 2 (U16.v x))
let decode_u32
(b: bytes { Seq.length b == 4 } )
: GTot U32.t
= E.lemma_be_to_n_is_bounded b;
U32.uint_to_t (E.be_to_n b)
let decode_u32_injective'
(b1: bytes { Seq.length b1 == 4 } )
(b2: bytes { Seq.length b2 == 4 } )
: Lemma
(decode_u32 b1 == decode_u32 b2 ==> Seq.equal b1 b2)
= if decode_u32 b1 = decode_u32 b2
then begin
E.lemma_be_to_n_is_bounded b1;
E.lemma_be_to_n_is_bounded b2;
assert (U32.v (U32.uint_to_t (E.be_to_n b1)) == E.be_to_n b1);
assert (U32.v (U32.uint_to_t (E.be_to_n b2)) == E.be_to_n b2);
assert (E.be_to_n b1 == E.be_to_n b2);
E.be_to_n_inj b1 b2
end else () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Seq.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "LowParse.Spec.Int.fst"
} | [
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.Endianness",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit
-> FStar.Pervasives.Lemma
(ensures
LowParse.Spec.Combinators.make_total_constant_size_parser_precond 4
FStar.UInt32.t
LowParse.Spec.Int.decode_u32) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.unit",
"FStar.Classical.forall_intro_2",
"LowParse.Bytes.bytes",
"Prims.eq2",
"Prims.int",
"FStar.Seq.Base.length",
"LowParse.Bytes.byte",
"Prims.l_imp",
"FStar.UInt32.t",
"LowParse.Spec.Int.decode_u32",
"FStar.Seq.Base.equal",
"LowParse.Spec.Int.decode_u32_injective'",
"Prims.l_True",
"Prims.squash",
"LowParse.Spec.Combinators.make_total_constant_size_parser_precond",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let decode_u32_injective () : Lemma (make_total_constant_size_parser_precond 4 U32.t decode_u32) =
| Classical.forall_intro_2 decode_u32_injective' | false |
LowParse.Spec.Int.fst | LowParse.Spec.Int.decode_u16_injective | val decode_u16_injective: Prims.unit
-> Lemma (make_total_constant_size_parser_precond 2 U16.t decode_u16) | val decode_u16_injective: Prims.unit
-> Lemma (make_total_constant_size_parser_precond 2 U16.t decode_u16) | let decode_u16_injective
()
: Lemma
(make_total_constant_size_parser_precond 2 U16.t decode_u16)
= Classical.forall_intro_2 decode_u16_injective' | {
"file_name": "src/lowparse/LowParse.Spec.Int.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 48,
"end_line": 56,
"start_col": 0,
"start_line": 52
} | module LowParse.Spec.Int
open LowParse.Spec.Combinators
let decode_u8
(b: bytes { Seq.length b == 1 } )
: Tot U8.t
= Seq.index b 0
let decode_u8_injective () : Lemma
(make_total_constant_size_parser_precond 1 U8.t decode_u8)
= ()
let tot_parse_u8 =
decode_u8_injective ();
tot_make_total_constant_size_parser 1 U8.t decode_u8
let parse_u8_spec
b
=
Seq.lemma_index_slice b 0 1 0;
E.reveal_be_to_n (Seq.slice b 0 1);
E.reveal_be_to_n (Seq.slice (Seq.slice b 0 1) 0 0)
let parse_u8_spec' b = ()
let serialize_u8 =
Seq.create 1
let serialize_u8_spec x = ()
let decode_u16
(b: bytes { Seq.length b == 2 } )
: GTot U16.t
= E.lemma_be_to_n_is_bounded b;
U16.uint_to_t (E.be_to_n b)
let decode_u16_injective'
(b1: bytes { Seq.length b1 == 2 } )
(b2: bytes { Seq.length b2 == 2 } )
: Lemma
(decode_u16 b1 == decode_u16 b2 ==> Seq.equal b1 b2)
= if decode_u16 b1 = decode_u16 b2
then begin
E.lemma_be_to_n_is_bounded b1;
E.lemma_be_to_n_is_bounded b2;
assert (U32.v (U32.uint_to_t (E.be_to_n b1)) == E.be_to_n b1);
assert (U32.v (U32.uint_to_t (E.be_to_n b2)) == E.be_to_n b2);
assert (E.be_to_n b1 == E.be_to_n b2);
E.be_to_n_inj b1 b2
end else () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Seq.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "LowParse.Spec.Int.fst"
} | [
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.Endianness",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit
-> FStar.Pervasives.Lemma
(ensures
LowParse.Spec.Combinators.make_total_constant_size_parser_precond 2
FStar.UInt16.t
LowParse.Spec.Int.decode_u16) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.unit",
"FStar.Classical.forall_intro_2",
"LowParse.Bytes.bytes",
"Prims.eq2",
"Prims.int",
"FStar.Seq.Base.length",
"LowParse.Bytes.byte",
"Prims.l_imp",
"FStar.UInt16.t",
"LowParse.Spec.Int.decode_u16",
"FStar.Seq.Base.equal",
"LowParse.Spec.Int.decode_u16_injective'",
"Prims.l_True",
"Prims.squash",
"LowParse.Spec.Combinators.make_total_constant_size_parser_precond",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let decode_u16_injective () : Lemma (make_total_constant_size_parser_precond 2 U16.t decode_u16) =
| Classical.forall_intro_2 decode_u16_injective' | false |
LowParse.Spec.Int.fst | LowParse.Spec.Int.serialize_u32 | val serialize_u32 : serializer parse_u32 | val serialize_u32 : serializer parse_u32 | let serialize_u32 =
(fun (x: U32.t) -> E.n_to_be 4 (U32.v x)) | {
"file_name": "src/lowparse/LowParse.Spec.Int.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 43,
"end_line": 105,
"start_col": 0,
"start_line": 104
} | module LowParse.Spec.Int
open LowParse.Spec.Combinators
let decode_u8
(b: bytes { Seq.length b == 1 } )
: Tot U8.t
= Seq.index b 0
let decode_u8_injective () : Lemma
(make_total_constant_size_parser_precond 1 U8.t decode_u8)
= ()
let tot_parse_u8 =
decode_u8_injective ();
tot_make_total_constant_size_parser 1 U8.t decode_u8
let parse_u8_spec
b
=
Seq.lemma_index_slice b 0 1 0;
E.reveal_be_to_n (Seq.slice b 0 1);
E.reveal_be_to_n (Seq.slice (Seq.slice b 0 1) 0 0)
let parse_u8_spec' b = ()
let serialize_u8 =
Seq.create 1
let serialize_u8_spec x = ()
let decode_u16
(b: bytes { Seq.length b == 2 } )
: GTot U16.t
= E.lemma_be_to_n_is_bounded b;
U16.uint_to_t (E.be_to_n b)
let decode_u16_injective'
(b1: bytes { Seq.length b1 == 2 } )
(b2: bytes { Seq.length b2 == 2 } )
: Lemma
(decode_u16 b1 == decode_u16 b2 ==> Seq.equal b1 b2)
= if decode_u16 b1 = decode_u16 b2
then begin
E.lemma_be_to_n_is_bounded b1;
E.lemma_be_to_n_is_bounded b2;
assert (U32.v (U32.uint_to_t (E.be_to_n b1)) == E.be_to_n b1);
assert (U32.v (U32.uint_to_t (E.be_to_n b2)) == E.be_to_n b2);
assert (E.be_to_n b1 == E.be_to_n b2);
E.be_to_n_inj b1 b2
end else ()
let decode_u16_injective
()
: Lemma
(make_total_constant_size_parser_precond 2 U16.t decode_u16)
= Classical.forall_intro_2 decode_u16_injective'
let parse_u16 =
decode_u16_injective ();
make_total_constant_size_parser 2 U16.t decode_u16
let parse_u16_spec
b
=
E.lemma_be_to_n_is_bounded (Seq.slice b 0 2)
let serialize_u16 =
(fun (x: U16.t) -> E.n_to_be 2 (U16.v x))
let decode_u32
(b: bytes { Seq.length b == 4 } )
: GTot U32.t
= E.lemma_be_to_n_is_bounded b;
U32.uint_to_t (E.be_to_n b)
let decode_u32_injective'
(b1: bytes { Seq.length b1 == 4 } )
(b2: bytes { Seq.length b2 == 4 } )
: Lemma
(decode_u32 b1 == decode_u32 b2 ==> Seq.equal b1 b2)
= if decode_u32 b1 = decode_u32 b2
then begin
E.lemma_be_to_n_is_bounded b1;
E.lemma_be_to_n_is_bounded b2;
assert (U32.v (U32.uint_to_t (E.be_to_n b1)) == E.be_to_n b1);
assert (U32.v (U32.uint_to_t (E.be_to_n b2)) == E.be_to_n b2);
assert (E.be_to_n b1 == E.be_to_n b2);
E.be_to_n_inj b1 b2
end else ()
let decode_u32_injective () : Lemma
(make_total_constant_size_parser_precond 4 U32.t decode_u32)
= Classical.forall_intro_2 decode_u32_injective'
let parse_u32 =
decode_u32_injective ();
make_total_constant_size_parser 4 U32.t decode_u32
let parse_u32_spec
b
=
E.lemma_be_to_n_is_bounded (Seq.slice b 0 4) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Seq.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "LowParse.Spec.Int.fst"
} | [
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.Endianness",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | LowParse.Spec.Base.serializer LowParse.Spec.Int.parse_u32 | Prims.Tot | [
"total"
] | [] | [
"FStar.UInt32.t",
"FStar.Endianness.n_to_be",
"FStar.UInt32.v",
"FStar.Endianness.bytes",
"Prims.l_and",
"Prims.eq2",
"Prims.nat",
"FStar.Seq.Base.length",
"FStar.UInt8.t",
"FStar.Endianness.be_to_n"
] | [] | false | false | false | true | false | let serialize_u32 =
| (fun (x: U32.t) -> E.n_to_be 4 (U32.v x)) | false |
LowParse.Spec.Int.fst | LowParse.Spec.Int.decode_u64 | val decode_u64 (b: bytes{Seq.length b == 8}) : GTot U64.t | val decode_u64 (b: bytes{Seq.length b == 8}) : GTot U64.t | let decode_u64
(b: bytes { Seq.length b == 8 } )
: GTot U64.t
= E.lemma_be_to_n_is_bounded b;
U64.uint_to_t (E.be_to_n b) | {
"file_name": "src/lowparse/LowParse.Spec.Int.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 29,
"end_line": 111,
"start_col": 0,
"start_line": 107
} | module LowParse.Spec.Int
open LowParse.Spec.Combinators
let decode_u8
(b: bytes { Seq.length b == 1 } )
: Tot U8.t
= Seq.index b 0
let decode_u8_injective () : Lemma
(make_total_constant_size_parser_precond 1 U8.t decode_u8)
= ()
let tot_parse_u8 =
decode_u8_injective ();
tot_make_total_constant_size_parser 1 U8.t decode_u8
let parse_u8_spec
b
=
Seq.lemma_index_slice b 0 1 0;
E.reveal_be_to_n (Seq.slice b 0 1);
E.reveal_be_to_n (Seq.slice (Seq.slice b 0 1) 0 0)
let parse_u8_spec' b = ()
let serialize_u8 =
Seq.create 1
let serialize_u8_spec x = ()
let decode_u16
(b: bytes { Seq.length b == 2 } )
: GTot U16.t
= E.lemma_be_to_n_is_bounded b;
U16.uint_to_t (E.be_to_n b)
let decode_u16_injective'
(b1: bytes { Seq.length b1 == 2 } )
(b2: bytes { Seq.length b2 == 2 } )
: Lemma
(decode_u16 b1 == decode_u16 b2 ==> Seq.equal b1 b2)
= if decode_u16 b1 = decode_u16 b2
then begin
E.lemma_be_to_n_is_bounded b1;
E.lemma_be_to_n_is_bounded b2;
assert (U32.v (U32.uint_to_t (E.be_to_n b1)) == E.be_to_n b1);
assert (U32.v (U32.uint_to_t (E.be_to_n b2)) == E.be_to_n b2);
assert (E.be_to_n b1 == E.be_to_n b2);
E.be_to_n_inj b1 b2
end else ()
let decode_u16_injective
()
: Lemma
(make_total_constant_size_parser_precond 2 U16.t decode_u16)
= Classical.forall_intro_2 decode_u16_injective'
let parse_u16 =
decode_u16_injective ();
make_total_constant_size_parser 2 U16.t decode_u16
let parse_u16_spec
b
=
E.lemma_be_to_n_is_bounded (Seq.slice b 0 2)
let serialize_u16 =
(fun (x: U16.t) -> E.n_to_be 2 (U16.v x))
let decode_u32
(b: bytes { Seq.length b == 4 } )
: GTot U32.t
= E.lemma_be_to_n_is_bounded b;
U32.uint_to_t (E.be_to_n b)
let decode_u32_injective'
(b1: bytes { Seq.length b1 == 4 } )
(b2: bytes { Seq.length b2 == 4 } )
: Lemma
(decode_u32 b1 == decode_u32 b2 ==> Seq.equal b1 b2)
= if decode_u32 b1 = decode_u32 b2
then begin
E.lemma_be_to_n_is_bounded b1;
E.lemma_be_to_n_is_bounded b2;
assert (U32.v (U32.uint_to_t (E.be_to_n b1)) == E.be_to_n b1);
assert (U32.v (U32.uint_to_t (E.be_to_n b2)) == E.be_to_n b2);
assert (E.be_to_n b1 == E.be_to_n b2);
E.be_to_n_inj b1 b2
end else ()
let decode_u32_injective () : Lemma
(make_total_constant_size_parser_precond 4 U32.t decode_u32)
= Classical.forall_intro_2 decode_u32_injective'
let parse_u32 =
decode_u32_injective ();
make_total_constant_size_parser 4 U32.t decode_u32
let parse_u32_spec
b
=
E.lemma_be_to_n_is_bounded (Seq.slice b 0 4)
let serialize_u32 =
(fun (x: U32.t) -> E.n_to_be 4 (U32.v x)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Seq.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "LowParse.Spec.Int.fst"
} | [
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.Endianness",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | b: LowParse.Bytes.bytes{FStar.Seq.Base.length b == 8} -> Prims.GTot FStar.UInt64.t | Prims.GTot | [
"sometrivial"
] | [] | [
"LowParse.Bytes.bytes",
"Prims.eq2",
"Prims.int",
"FStar.Seq.Base.length",
"LowParse.Bytes.byte",
"FStar.UInt64.uint_to_t",
"FStar.Endianness.be_to_n",
"Prims.unit",
"FStar.Endianness.lemma_be_to_n_is_bounded",
"FStar.UInt64.t"
] | [] | false | false | false | false | false | let decode_u64 (b: bytes{Seq.length b == 8}) : GTot U64.t =
| E.lemma_be_to_n_is_bounded b;
U64.uint_to_t (E.be_to_n b) | false |
LowParse.Spec.Int.fst | LowParse.Spec.Int.decode_u32_injective' | val decode_u32_injective' (b1: bytes{Seq.length b1 == 4}) (b2: bytes{Seq.length b2 == 4})
: Lemma (decode_u32 b1 == decode_u32 b2 ==> Seq.equal b1 b2) | val decode_u32_injective' (b1: bytes{Seq.length b1 == 4}) (b2: bytes{Seq.length b2 == 4})
: Lemma (decode_u32 b1 == decode_u32 b2 ==> Seq.equal b1 b2) | let decode_u32_injective'
(b1: bytes { Seq.length b1 == 4 } )
(b2: bytes { Seq.length b2 == 4 } )
: Lemma
(decode_u32 b1 == decode_u32 b2 ==> Seq.equal b1 b2)
= if decode_u32 b1 = decode_u32 b2
then begin
E.lemma_be_to_n_is_bounded b1;
E.lemma_be_to_n_is_bounded b2;
assert (U32.v (U32.uint_to_t (E.be_to_n b1)) == E.be_to_n b1);
assert (U32.v (U32.uint_to_t (E.be_to_n b2)) == E.be_to_n b2);
assert (E.be_to_n b1 == E.be_to_n b2);
E.be_to_n_inj b1 b2
end else () | {
"file_name": "src/lowparse/LowParse.Spec.Int.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 13,
"end_line": 89,
"start_col": 0,
"start_line": 76
} | module LowParse.Spec.Int
open LowParse.Spec.Combinators
let decode_u8
(b: bytes { Seq.length b == 1 } )
: Tot U8.t
= Seq.index b 0
let decode_u8_injective () : Lemma
(make_total_constant_size_parser_precond 1 U8.t decode_u8)
= ()
let tot_parse_u8 =
decode_u8_injective ();
tot_make_total_constant_size_parser 1 U8.t decode_u8
let parse_u8_spec
b
=
Seq.lemma_index_slice b 0 1 0;
E.reveal_be_to_n (Seq.slice b 0 1);
E.reveal_be_to_n (Seq.slice (Seq.slice b 0 1) 0 0)
let parse_u8_spec' b = ()
let serialize_u8 =
Seq.create 1
let serialize_u8_spec x = ()
let decode_u16
(b: bytes { Seq.length b == 2 } )
: GTot U16.t
= E.lemma_be_to_n_is_bounded b;
U16.uint_to_t (E.be_to_n b)
let decode_u16_injective'
(b1: bytes { Seq.length b1 == 2 } )
(b2: bytes { Seq.length b2 == 2 } )
: Lemma
(decode_u16 b1 == decode_u16 b2 ==> Seq.equal b1 b2)
= if decode_u16 b1 = decode_u16 b2
then begin
E.lemma_be_to_n_is_bounded b1;
E.lemma_be_to_n_is_bounded b2;
assert (U32.v (U32.uint_to_t (E.be_to_n b1)) == E.be_to_n b1);
assert (U32.v (U32.uint_to_t (E.be_to_n b2)) == E.be_to_n b2);
assert (E.be_to_n b1 == E.be_to_n b2);
E.be_to_n_inj b1 b2
end else ()
let decode_u16_injective
()
: Lemma
(make_total_constant_size_parser_precond 2 U16.t decode_u16)
= Classical.forall_intro_2 decode_u16_injective'
let parse_u16 =
decode_u16_injective ();
make_total_constant_size_parser 2 U16.t decode_u16
let parse_u16_spec
b
=
E.lemma_be_to_n_is_bounded (Seq.slice b 0 2)
let serialize_u16 =
(fun (x: U16.t) -> E.n_to_be 2 (U16.v x))
let decode_u32
(b: bytes { Seq.length b == 4 } )
: GTot U32.t
= E.lemma_be_to_n_is_bounded b;
U32.uint_to_t (E.be_to_n b) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Seq.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "LowParse.Spec.Int.fst"
} | [
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.Endianness",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
b1: LowParse.Bytes.bytes{FStar.Seq.Base.length b1 == 4} ->
b2: LowParse.Bytes.bytes{FStar.Seq.Base.length b2 == 4}
-> FStar.Pervasives.Lemma
(ensures
LowParse.Spec.Int.decode_u32 b1 == LowParse.Spec.Int.decode_u32 b2 ==>
FStar.Seq.Base.equal b1 b2) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"LowParse.Bytes.bytes",
"Prims.eq2",
"Prims.int",
"FStar.Seq.Base.length",
"LowParse.Bytes.byte",
"Prims.op_Equality",
"FStar.UInt32.t",
"LowParse.Spec.Int.decode_u32",
"FStar.Endianness.be_to_n_inj",
"Prims.unit",
"Prims._assert",
"Prims.nat",
"FStar.Endianness.be_to_n",
"Prims.l_or",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"FStar.UInt.size",
"FStar.UInt32.n",
"FStar.UInt32.v",
"FStar.UInt32.uint_to_t",
"FStar.Endianness.lemma_be_to_n_is_bounded",
"Prims.bool",
"Prims.l_True",
"Prims.squash",
"Prims.l_imp",
"FStar.Seq.Base.equal",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let decode_u32_injective' (b1: bytes{Seq.length b1 == 4}) (b2: bytes{Seq.length b2 == 4})
: Lemma (decode_u32 b1 == decode_u32 b2 ==> Seq.equal b1 b2) =
| if decode_u32 b1 = decode_u32 b2
then
(E.lemma_be_to_n_is_bounded b1;
E.lemma_be_to_n_is_bounded b2;
assert (U32.v (U32.uint_to_t (E.be_to_n b1)) == E.be_to_n b1);
assert (U32.v (U32.uint_to_t (E.be_to_n b2)) == E.be_to_n b2);
assert (E.be_to_n b1 == E.be_to_n b2);
E.be_to_n_inj b1 b2) | false |
LowParse.Spec.Int.fst | LowParse.Spec.Int.parse_u16 | val parse_u16: parser parse_u16_kind U16.t | val parse_u16: parser parse_u16_kind U16.t | let parse_u16 =
decode_u16_injective ();
make_total_constant_size_parser 2 U16.t decode_u16 | {
"file_name": "src/lowparse/LowParse.Spec.Int.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 52,
"end_line": 60,
"start_col": 0,
"start_line": 58
} | module LowParse.Spec.Int
open LowParse.Spec.Combinators
let decode_u8
(b: bytes { Seq.length b == 1 } )
: Tot U8.t
= Seq.index b 0
let decode_u8_injective () : Lemma
(make_total_constant_size_parser_precond 1 U8.t decode_u8)
= ()
let tot_parse_u8 =
decode_u8_injective ();
tot_make_total_constant_size_parser 1 U8.t decode_u8
let parse_u8_spec
b
=
Seq.lemma_index_slice b 0 1 0;
E.reveal_be_to_n (Seq.slice b 0 1);
E.reveal_be_to_n (Seq.slice (Seq.slice b 0 1) 0 0)
let parse_u8_spec' b = ()
let serialize_u8 =
Seq.create 1
let serialize_u8_spec x = ()
let decode_u16
(b: bytes { Seq.length b == 2 } )
: GTot U16.t
= E.lemma_be_to_n_is_bounded b;
U16.uint_to_t (E.be_to_n b)
let decode_u16_injective'
(b1: bytes { Seq.length b1 == 2 } )
(b2: bytes { Seq.length b2 == 2 } )
: Lemma
(decode_u16 b1 == decode_u16 b2 ==> Seq.equal b1 b2)
= if decode_u16 b1 = decode_u16 b2
then begin
E.lemma_be_to_n_is_bounded b1;
E.lemma_be_to_n_is_bounded b2;
assert (U32.v (U32.uint_to_t (E.be_to_n b1)) == E.be_to_n b1);
assert (U32.v (U32.uint_to_t (E.be_to_n b2)) == E.be_to_n b2);
assert (E.be_to_n b1 == E.be_to_n b2);
E.be_to_n_inj b1 b2
end else ()
let decode_u16_injective
()
: Lemma
(make_total_constant_size_parser_precond 2 U16.t decode_u16)
= Classical.forall_intro_2 decode_u16_injective' | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Seq.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "LowParse.Spec.Int.fst"
} | [
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.Endianness",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | LowParse.Spec.Base.parser LowParse.Spec.Int.parse_u16_kind FStar.UInt16.t | Prims.Tot | [
"total"
] | [] | [
"LowParse.Spec.Combinators.make_total_constant_size_parser",
"FStar.UInt16.t",
"LowParse.Spec.Int.decode_u16",
"Prims.unit",
"LowParse.Spec.Int.decode_u16_injective"
] | [] | false | false | false | true | false | let parse_u16 =
| decode_u16_injective ();
make_total_constant_size_parser 2 U16.t decode_u16 | false |
Hacl.Spec.K256.PrecompTable.fst | Hacl.Spec.K256.PrecompTable.proj_point_to_list_sub | val proj_point_to_list_sub: p:S.proj_point -> Lemma
(let (px, py, pz) = p in
let px_list = felem_to_list px in
let py_list = felem_to_list py in
let pz_list = felem_to_list pz in
let p_list = FL.(px_list @ py_list @ pz_list) in
let p_lseq = Seq.seq_of_list p_list <: lseq uint64 15 in
let px_lseq = Seq.seq_of_list px_list <: lseq uint64 5 in
let py_lseq = Seq.seq_of_list py_list <: lseq uint64 5 in
let pz_lseq = Seq.seq_of_list pz_list <: lseq uint64 5 in
sub p_lseq 0 5 == px_lseq /\
sub p_lseq 5 5 == py_lseq /\
sub p_lseq 10 5 == pz_lseq) | val proj_point_to_list_sub: p:S.proj_point -> Lemma
(let (px, py, pz) = p in
let px_list = felem_to_list px in
let py_list = felem_to_list py in
let pz_list = felem_to_list pz in
let p_list = FL.(px_list @ py_list @ pz_list) in
let p_lseq = Seq.seq_of_list p_list <: lseq uint64 15 in
let px_lseq = Seq.seq_of_list px_list <: lseq uint64 5 in
let py_lseq = Seq.seq_of_list py_list <: lseq uint64 5 in
let pz_lseq = Seq.seq_of_list pz_list <: lseq uint64 5 in
sub p_lseq 0 5 == px_lseq /\
sub p_lseq 5 5 == py_lseq /\
sub p_lseq 10 5 == pz_lseq) | let proj_point_to_list_sub p =
let (px, py, pz) = p in
let px_list = felem_to_list px in
let py_list = felem_to_list py in
let pz_list = felem_to_list pz in
FL.append_assoc px_list py_list pz_list;
SPT.seq_of_list_append_lemma px_list py_list;
SPT.seq_of_list_append_lemma FL.(px_list @ py_list) pz_list | {
"file_name": "code/k256/Hacl.Spec.K256.PrecompTable.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 61,
"end_line": 143,
"start_col": 0,
"start_line": 135
} | module Hacl.Spec.K256.PrecompTable
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Hacl.Spec.K256.Field52.Definitions
open Hacl.Impl.K256.Point
module S = Spec.K256
module FL = FStar.List.Tot
module SPT = Hacl.Spec.PrecompBaseTable
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let create5_lseq (x0 x1 x2 x3 x4:uint64) : lseq uint64 5 =
let l = [x0; x1; x2; x3; x4] in
assert_norm (FL.length l = 5);
Seq.seq_of_list l
val create5_lemma (x0 x1 x2 x3 x4:uint64) :
Lemma (let s = create5_lseq x0 x1 x2 x3 x4 in
s.[0] == x0 /\ s.[1] == x1 /\ s.[2] == x2 /\ s.[3] == x3 /\ s.[4] == x4)
let create5_lemma x0 x1 x2 x3 x4 =
Seq.elim_of_list [x0; x1; x2; x3; x4]
//-----------------------------------
noextract
let list_as_felem5 (f:felem_list) : felem5 =
let x = Seq.seq_of_list f <: lseq uint64 5 in
as_felem5_lseq x
val felem_to_list_index_lemma: x:S.felem ->
Lemma (let (f0, f1, f2, f3, f4) = list_as_felem5 (felem_to_list x) in
let x0 = x % pow52 in
let x1 = x / pow52 % pow52 in
let x2 = x / pow104 % pow52 in
let x3 = x / pow156 % pow52 in
let x4 = x / pow208 in
v f0 == x0 /\ v f1 == x1 /\ v f2 == x2 /\ v f3 == x3 /\ v f4 == x4)
let felem_to_list_index_lemma x =
let x0 = x % pow52 in
let x1 = x / pow52 % pow52 in
let x2 = x / pow104 % pow52 in
let x3 = x / pow156 % pow52 in
let x4 = x / pow208 in
let f = felem_to_list x in
let (f0, f1, f2, f3, f4) = list_as_felem5 f in
create5_lemma (u64 x0) (u64 x1) (u64 x2) (u64 x3) (u64 x4);
assert (v f0 == x0 /\ v f1 == x1 /\ v f2 == x2 /\ v f3 == x3 /\ v f4 == x4)
val felem_to_list_lemma_fits: x:S.felem ->
Lemma (felem_fits5 (list_as_felem5 (felem_to_list x)) (1, 1, 1, 1, 1))
let felem_to_list_lemma_fits x =
felem_to_list_index_lemma x;
let x0 = x % pow52 in
let x1 = x / pow52 % pow52 in
let x2 = x / pow104 % pow52 in
let x3 = x / pow156 % pow52 in
let x4 = x / pow208 in
assert (felem_fits1 (u64 x0) 1);
assert (felem_fits1 (u64 x1) 1);
assert (felem_fits1 (u64 x2) 1);
assert (felem_fits1 (u64 x3) 1);
Math.Lemmas.lemma_div_lt_nat x 256 208;
assert (felem_fits_last1 (u64 x4) 1)
val lemma_mod_pow2_sub: x:nat -> a:nat -> b:nat ->
Lemma (x / pow2 a % pow2 b * pow2 a == x % pow2 (a + b) - x % pow2 a)
let lemma_mod_pow2_sub x a b =
calc (==) {
x / pow2 a % pow2 b * pow2 a;
(==) { Math.Lemmas.pow2_modulo_division_lemma_1 x a (a + b) }
x % pow2 (a + b) / pow2 a * pow2 a;
(==) { Math.Lemmas.euclidean_division_definition (x % pow2 (a + b)) (pow2 a) }
x % pow2 (a + b) - x % pow2 (a + b) % pow2 a;
(==) { Math.Lemmas.pow2_modulo_modulo_lemma_1 x a (a + b) }
x % pow2 (a + b) - x % pow2 a;
}
val felem_to_list_lemma_eval: x:S.felem ->
Lemma (as_nat5 (list_as_felem5 (felem_to_list x)) == x)
let felem_to_list_lemma_eval x =
felem_to_list_index_lemma x;
let x0 = x % pow52 in
let x1 = x / pow52 % pow52 in
let x2 = x / pow104 % pow52 in
let x3 = x / pow156 % pow52 in
let x4 = x / pow208 in
let (f0, f1, f2, f3, f4) = list_as_felem5 (felem_to_list x) in
let nat_x = as_nat5 (f0, f1, f2, f3, f4) in
assert (nat_x == x0 + x1 * pow52 + x2 * pow104 + x3 * pow156 + x4 * pow208);
calc (==) {
x0 + x1 * pow52 + x2 * pow104 + x3 * pow156 + x4 * pow208;
(==) { }
x0 + x1 * pow52 + x2 * pow104 + (x / pow156 % pow52) * pow156 + x / pow208 * pow208;
(==) { lemma_mod_pow2_sub x 156 52 }
x0 + x1 * pow52 + x2 * pow104 + x % pow208 - x % pow156 + x / pow208 * pow208;
(==) { Math.Lemmas.euclidean_division_definition x pow208 }
x0 + x1 * pow52 + (x / pow104 % pow52) * pow104 - x % pow156 + x;
(==) { lemma_mod_pow2_sub x 104 52 }
x0 + (x / pow52 % pow52) * pow52 - x % pow104 + x;
(==) { lemma_mod_pow2_sub x 52 52 }
x;
}
//--------------------------------------------
val proj_point_to_list_sub: p:S.proj_point -> Lemma
(let (px, py, pz) = p in
let px_list = felem_to_list px in
let py_list = felem_to_list py in
let pz_list = felem_to_list pz in
let p_list = FL.(px_list @ py_list @ pz_list) in
let p_lseq = Seq.seq_of_list p_list <: lseq uint64 15 in
let px_lseq = Seq.seq_of_list px_list <: lseq uint64 5 in
let py_lseq = Seq.seq_of_list py_list <: lseq uint64 5 in
let pz_lseq = Seq.seq_of_list pz_list <: lseq uint64 5 in
sub p_lseq 0 5 == px_lseq /\
sub p_lseq 5 5 == py_lseq /\
sub p_lseq 10 5 == pz_lseq) | {
"checked_file": "/",
"dependencies": [
"Spec.K256.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.PrecompBaseTable.fsti.checked",
"Hacl.Spec.K256.Field52.Definitions.fst.checked",
"Hacl.Impl.K256.Point.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.Spec.K256.PrecompTable.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.PrecompBaseTable",
"short_module": "SPT"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FL"
},
{
"abbrev": true,
"full_module": "Spec.K256",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256.Point",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256.Field52.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FL"
},
{
"abbrev": true,
"full_module": "Spec.K256",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256.Point",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256.Field52.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | p: Spec.K256.PointOps.proj_point
-> FStar.Pervasives.Lemma
(ensures
(let _ = p in
(let FStar.Pervasives.Native.Mktuple3 #_ #_ #_ px py pz = _ in
let px_list = Hacl.Spec.K256.PrecompTable.felem_to_list px in
let py_list = Hacl.Spec.K256.PrecompTable.felem_to_list py in
let pz_list = Hacl.Spec.K256.PrecompTable.felem_to_list pz in
let p_list = px_list @ py_list @ pz_list in
let p_lseq =
FStar.Seq.Base.seq_of_list p_list <: Lib.Sequence.lseq Lib.IntTypes.uint64 15
in
let px_lseq =
FStar.Seq.Base.seq_of_list px_list <: Lib.Sequence.lseq Lib.IntTypes.uint64 5
in
let py_lseq =
FStar.Seq.Base.seq_of_list py_list <: Lib.Sequence.lseq Lib.IntTypes.uint64 5
in
let pz_lseq =
FStar.Seq.Base.seq_of_list pz_list <: Lib.Sequence.lseq Lib.IntTypes.uint64 5
in
Lib.Sequence.sub p_lseq 0 5 == px_lseq /\ Lib.Sequence.sub p_lseq 5 5 == py_lseq /\
Lib.Sequence.sub p_lseq 10 5 == pz_lseq)
<:
Type0)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Spec.K256.PointOps.proj_point",
"Spec.K256.PointOps.felem",
"Hacl.Spec.PrecompBaseTable.seq_of_list_append_lemma",
"Lib.IntTypes.uint64",
"FStar.List.Tot.Base.op_At",
"Prims.unit",
"FStar.List.Tot.Properties.append_assoc",
"Hacl.Spec.K256.PrecompTable.felem_list",
"Hacl.Spec.K256.PrecompTable.felem_to_list"
] | [] | false | false | true | false | false | let proj_point_to_list_sub p =
| let px, py, pz = p in
let px_list = felem_to_list px in
let py_list = felem_to_list py in
let pz_list = felem_to_list pz in
FL.append_assoc px_list py_list pz_list;
SPT.seq_of_list_append_lemma px_list py_list;
SPT.seq_of_list_append_lemma FL.(px_list @ py_list) pz_list | false |
LowParse.Spec.Int.fst | LowParse.Spec.Int.decode_u64_le_injective' | val decode_u64_le_injective' (b1: bytes{Seq.length b1 == 8}) (b2: bytes{Seq.length b2 == 8})
: Lemma (decode_u64_le b1 == decode_u64_le b2 ==> Seq.equal b1 b2) | val decode_u64_le_injective' (b1: bytes{Seq.length b1 == 8}) (b2: bytes{Seq.length b2 == 8})
: Lemma (decode_u64_le b1 == decode_u64_le b2 ==> Seq.equal b1 b2) | let decode_u64_le_injective'
(b1: bytes { Seq.length b1 == 8 } )
(b2: bytes { Seq.length b2 == 8 } )
: Lemma
(decode_u64_le b1 == decode_u64_le b2 ==> Seq.equal b1 b2)
= if decode_u64_le b1 = decode_u64_le b2
then begin
E.lemma_le_to_n_is_bounded b1;
E.lemma_le_to_n_is_bounded b2;
assert (U64.v (U64.uint_to_t (E.le_to_n b1)) == E.le_to_n b1);
assert (U64.v (U64.uint_to_t (E.le_to_n b2)) == E.le_to_n b2);
assert (E.le_to_n b1 == E.le_to_n b2);
E.le_to_n_inj b1 b2
end else () | {
"file_name": "src/lowparse/LowParse.Spec.Int.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 13,
"end_line": 162,
"start_col": 0,
"start_line": 149
} | module LowParse.Spec.Int
open LowParse.Spec.Combinators
let decode_u8
(b: bytes { Seq.length b == 1 } )
: Tot U8.t
= Seq.index b 0
let decode_u8_injective () : Lemma
(make_total_constant_size_parser_precond 1 U8.t decode_u8)
= ()
let tot_parse_u8 =
decode_u8_injective ();
tot_make_total_constant_size_parser 1 U8.t decode_u8
let parse_u8_spec
b
=
Seq.lemma_index_slice b 0 1 0;
E.reveal_be_to_n (Seq.slice b 0 1);
E.reveal_be_to_n (Seq.slice (Seq.slice b 0 1) 0 0)
let parse_u8_spec' b = ()
let serialize_u8 =
Seq.create 1
let serialize_u8_spec x = ()
let decode_u16
(b: bytes { Seq.length b == 2 } )
: GTot U16.t
= E.lemma_be_to_n_is_bounded b;
U16.uint_to_t (E.be_to_n b)
let decode_u16_injective'
(b1: bytes { Seq.length b1 == 2 } )
(b2: bytes { Seq.length b2 == 2 } )
: Lemma
(decode_u16 b1 == decode_u16 b2 ==> Seq.equal b1 b2)
= if decode_u16 b1 = decode_u16 b2
then begin
E.lemma_be_to_n_is_bounded b1;
E.lemma_be_to_n_is_bounded b2;
assert (U32.v (U32.uint_to_t (E.be_to_n b1)) == E.be_to_n b1);
assert (U32.v (U32.uint_to_t (E.be_to_n b2)) == E.be_to_n b2);
assert (E.be_to_n b1 == E.be_to_n b2);
E.be_to_n_inj b1 b2
end else ()
let decode_u16_injective
()
: Lemma
(make_total_constant_size_parser_precond 2 U16.t decode_u16)
= Classical.forall_intro_2 decode_u16_injective'
let parse_u16 =
decode_u16_injective ();
make_total_constant_size_parser 2 U16.t decode_u16
let parse_u16_spec
b
=
E.lemma_be_to_n_is_bounded (Seq.slice b 0 2)
let serialize_u16 =
(fun (x: U16.t) -> E.n_to_be 2 (U16.v x))
let decode_u32
(b: bytes { Seq.length b == 4 } )
: GTot U32.t
= E.lemma_be_to_n_is_bounded b;
U32.uint_to_t (E.be_to_n b)
let decode_u32_injective'
(b1: bytes { Seq.length b1 == 4 } )
(b2: bytes { Seq.length b2 == 4 } )
: Lemma
(decode_u32 b1 == decode_u32 b2 ==> Seq.equal b1 b2)
= if decode_u32 b1 = decode_u32 b2
then begin
E.lemma_be_to_n_is_bounded b1;
E.lemma_be_to_n_is_bounded b2;
assert (U32.v (U32.uint_to_t (E.be_to_n b1)) == E.be_to_n b1);
assert (U32.v (U32.uint_to_t (E.be_to_n b2)) == E.be_to_n b2);
assert (E.be_to_n b1 == E.be_to_n b2);
E.be_to_n_inj b1 b2
end else ()
let decode_u32_injective () : Lemma
(make_total_constant_size_parser_precond 4 U32.t decode_u32)
= Classical.forall_intro_2 decode_u32_injective'
let parse_u32 =
decode_u32_injective ();
make_total_constant_size_parser 4 U32.t decode_u32
let parse_u32_spec
b
=
E.lemma_be_to_n_is_bounded (Seq.slice b 0 4)
let serialize_u32 =
(fun (x: U32.t) -> E.n_to_be 4 (U32.v x))
let decode_u64
(b: bytes { Seq.length b == 8 } )
: GTot U64.t
= E.lemma_be_to_n_is_bounded b;
U64.uint_to_t (E.be_to_n b)
let decode_u64_injective'
(b1: bytes { Seq.length b1 == 8 } )
(b2: bytes { Seq.length b2 == 8 } )
: Lemma
(decode_u64 b1 == decode_u64 b2 ==> Seq.equal b1 b2)
= if decode_u64 b1 = decode_u64 b2
then begin
E.lemma_be_to_n_is_bounded b1;
E.lemma_be_to_n_is_bounded b2;
assert (U64.v (U64.uint_to_t (E.be_to_n b1)) == E.be_to_n b1);
assert (U64.v (U64.uint_to_t (E.be_to_n b2)) == E.be_to_n b2);
assert (E.be_to_n b1 == E.be_to_n b2);
E.be_to_n_inj b1 b2
end else ()
let decode_u64_injective () : Lemma
(make_total_constant_size_parser_precond 8 U64.t decode_u64)
= Classical.forall_intro_2 decode_u64_injective'
let parse_u64 =
decode_u64_injective ();
make_total_constant_size_parser 8 U64.t decode_u64
let parse_u64_spec
b
= E.lemma_be_to_n_is_bounded (Seq.slice b 0 8)
let serialize_u64 =
(fun (x: U64.t) -> E.n_to_be 8 (U64.v x))
let decode_u64_le
(b: bytes { Seq.length b == 8 } )
: GTot U64.t
= E.lemma_le_to_n_is_bounded b;
U64.uint_to_t (E.le_to_n b) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Seq.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "LowParse.Spec.Int.fst"
} | [
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.Endianness",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
b1: LowParse.Bytes.bytes{FStar.Seq.Base.length b1 == 8} ->
b2: LowParse.Bytes.bytes{FStar.Seq.Base.length b2 == 8}
-> FStar.Pervasives.Lemma
(ensures
LowParse.Spec.Int.decode_u64_le b1 == LowParse.Spec.Int.decode_u64_le b2 ==>
FStar.Seq.Base.equal b1 b2) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"LowParse.Bytes.bytes",
"Prims.eq2",
"Prims.int",
"FStar.Seq.Base.length",
"LowParse.Bytes.byte",
"Prims.op_Equality",
"FStar.UInt64.t",
"LowParse.Spec.Int.decode_u64_le",
"FStar.Endianness.le_to_n_inj",
"Prims.unit",
"Prims._assert",
"Prims.nat",
"FStar.Endianness.le_to_n",
"Prims.l_or",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"FStar.UInt.size",
"FStar.UInt64.n",
"FStar.UInt64.v",
"FStar.UInt64.uint_to_t",
"FStar.Endianness.lemma_le_to_n_is_bounded",
"Prims.bool",
"Prims.l_True",
"Prims.squash",
"Prims.l_imp",
"FStar.Seq.Base.equal",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let decode_u64_le_injective' (b1: bytes{Seq.length b1 == 8}) (b2: bytes{Seq.length b2 == 8})
: Lemma (decode_u64_le b1 == decode_u64_le b2 ==> Seq.equal b1 b2) =
| if decode_u64_le b1 = decode_u64_le b2
then
(E.lemma_le_to_n_is_bounded b1;
E.lemma_le_to_n_is_bounded b2;
assert (U64.v (U64.uint_to_t (E.le_to_n b1)) == E.le_to_n b1);
assert (U64.v (U64.uint_to_t (E.le_to_n b2)) == E.le_to_n b2);
assert (E.le_to_n b1 == E.le_to_n b2);
E.le_to_n_inj b1 b2) | false |
LowParse.Spec.Int.fst | LowParse.Spec.Int.parse_u32_spec | val parse_u32_spec
(b: bytes)
: Lemma
(requires (Seq.length b >= 4))
(ensures (
let pp = parse parse_u32 b in
Some? pp /\ (
let (Some (v, consumed)) = pp in
U32.v v == E.be_to_n (Seq.slice b 0 4)
))) | val parse_u32_spec
(b: bytes)
: Lemma
(requires (Seq.length b >= 4))
(ensures (
let pp = parse parse_u32 b in
Some? pp /\ (
let (Some (v, consumed)) = pp in
U32.v v == E.be_to_n (Seq.slice b 0 4)
))) | let parse_u32_spec
b
=
E.lemma_be_to_n_is_bounded (Seq.slice b 0 4) | {
"file_name": "src/lowparse/LowParse.Spec.Int.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 46,
"end_line": 102,
"start_col": 0,
"start_line": 99
} | module LowParse.Spec.Int
open LowParse.Spec.Combinators
let decode_u8
(b: bytes { Seq.length b == 1 } )
: Tot U8.t
= Seq.index b 0
let decode_u8_injective () : Lemma
(make_total_constant_size_parser_precond 1 U8.t decode_u8)
= ()
let tot_parse_u8 =
decode_u8_injective ();
tot_make_total_constant_size_parser 1 U8.t decode_u8
let parse_u8_spec
b
=
Seq.lemma_index_slice b 0 1 0;
E.reveal_be_to_n (Seq.slice b 0 1);
E.reveal_be_to_n (Seq.slice (Seq.slice b 0 1) 0 0)
let parse_u8_spec' b = ()
let serialize_u8 =
Seq.create 1
let serialize_u8_spec x = ()
let decode_u16
(b: bytes { Seq.length b == 2 } )
: GTot U16.t
= E.lemma_be_to_n_is_bounded b;
U16.uint_to_t (E.be_to_n b)
let decode_u16_injective'
(b1: bytes { Seq.length b1 == 2 } )
(b2: bytes { Seq.length b2 == 2 } )
: Lemma
(decode_u16 b1 == decode_u16 b2 ==> Seq.equal b1 b2)
= if decode_u16 b1 = decode_u16 b2
then begin
E.lemma_be_to_n_is_bounded b1;
E.lemma_be_to_n_is_bounded b2;
assert (U32.v (U32.uint_to_t (E.be_to_n b1)) == E.be_to_n b1);
assert (U32.v (U32.uint_to_t (E.be_to_n b2)) == E.be_to_n b2);
assert (E.be_to_n b1 == E.be_to_n b2);
E.be_to_n_inj b1 b2
end else ()
let decode_u16_injective
()
: Lemma
(make_total_constant_size_parser_precond 2 U16.t decode_u16)
= Classical.forall_intro_2 decode_u16_injective'
let parse_u16 =
decode_u16_injective ();
make_total_constant_size_parser 2 U16.t decode_u16
let parse_u16_spec
b
=
E.lemma_be_to_n_is_bounded (Seq.slice b 0 2)
let serialize_u16 =
(fun (x: U16.t) -> E.n_to_be 2 (U16.v x))
let decode_u32
(b: bytes { Seq.length b == 4 } )
: GTot U32.t
= E.lemma_be_to_n_is_bounded b;
U32.uint_to_t (E.be_to_n b)
let decode_u32_injective'
(b1: bytes { Seq.length b1 == 4 } )
(b2: bytes { Seq.length b2 == 4 } )
: Lemma
(decode_u32 b1 == decode_u32 b2 ==> Seq.equal b1 b2)
= if decode_u32 b1 = decode_u32 b2
then begin
E.lemma_be_to_n_is_bounded b1;
E.lemma_be_to_n_is_bounded b2;
assert (U32.v (U32.uint_to_t (E.be_to_n b1)) == E.be_to_n b1);
assert (U32.v (U32.uint_to_t (E.be_to_n b2)) == E.be_to_n b2);
assert (E.be_to_n b1 == E.be_to_n b2);
E.be_to_n_inj b1 b2
end else ()
let decode_u32_injective () : Lemma
(make_total_constant_size_parser_precond 4 U32.t decode_u32)
= Classical.forall_intro_2 decode_u32_injective'
let parse_u32 =
decode_u32_injective ();
make_total_constant_size_parser 4 U32.t decode_u32 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Seq.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "LowParse.Spec.Int.fst"
} | [
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.Endianness",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | b: LowParse.Bytes.bytes
-> FStar.Pervasives.Lemma (requires FStar.Seq.Base.length b >= 4)
(ensures
(let pp = LowParse.Spec.Base.parse LowParse.Spec.Int.parse_u32 b in
Some? pp /\
(let _ = pp in
(let FStar.Pervasives.Native.Some #_ (FStar.Pervasives.Native.Mktuple2 #_ #_ v _) = _ in
FStar.UInt32.v v == FStar.Endianness.be_to_n (FStar.Seq.Base.slice b 0 4))
<:
Prims.logical))) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"LowParse.Bytes.bytes",
"FStar.Endianness.lemma_be_to_n_is_bounded",
"FStar.Seq.Base.slice",
"LowParse.Bytes.byte",
"Prims.unit"
] | [] | true | false | true | false | false | let parse_u32_spec b =
| E.lemma_be_to_n_is_bounded (Seq.slice b 0 4) | false |
LowParse.Spec.Int.fst | LowParse.Spec.Int.parse_u8_spec | val parse_u8_spec
(b: bytes)
: Lemma
(requires (Seq.length b >= 1))
(ensures (
let pp = parse parse_u8 b in
Some? pp /\ (
let (Some (v, consumed)) = pp in
U8.v v == E.be_to_n (Seq.slice b 0 1)
))) | val parse_u8_spec
(b: bytes)
: Lemma
(requires (Seq.length b >= 1))
(ensures (
let pp = parse parse_u8 b in
Some? pp /\ (
let (Some (v, consumed)) = pp in
U8.v v == E.be_to_n (Seq.slice b 0 1)
))) | let parse_u8_spec
b
=
Seq.lemma_index_slice b 0 1 0;
E.reveal_be_to_n (Seq.slice b 0 1);
E.reveal_be_to_n (Seq.slice (Seq.slice b 0 1) 0 0) | {
"file_name": "src/lowparse/LowParse.Spec.Int.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 52,
"end_line": 22,
"start_col": 0,
"start_line": 17
} | module LowParse.Spec.Int
open LowParse.Spec.Combinators
let decode_u8
(b: bytes { Seq.length b == 1 } )
: Tot U8.t
= Seq.index b 0
let decode_u8_injective () : Lemma
(make_total_constant_size_parser_precond 1 U8.t decode_u8)
= ()
let tot_parse_u8 =
decode_u8_injective ();
tot_make_total_constant_size_parser 1 U8.t decode_u8 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Seq.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "LowParse.Spec.Int.fst"
} | [
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.Endianness",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | b: LowParse.Bytes.bytes
-> FStar.Pervasives.Lemma (requires FStar.Seq.Base.length b >= 1)
(ensures
(let pp = LowParse.Spec.Base.parse LowParse.Spec.Int.parse_u8 b in
Some? pp /\
(let _ = pp in
(let FStar.Pervasives.Native.Some #_ (FStar.Pervasives.Native.Mktuple2 #_ #_ v _) = _ in
FStar.UInt8.v v == FStar.Endianness.be_to_n (FStar.Seq.Base.slice b 0 1))
<:
Prims.logical))) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"LowParse.Bytes.bytes",
"FStar.Endianness.reveal_be_to_n",
"FStar.Seq.Base.slice",
"LowParse.Bytes.byte",
"Prims.unit",
"FStar.Seq.Base.lemma_index_slice"
] | [] | true | false | true | false | false | let parse_u8_spec b =
| Seq.lemma_index_slice b 0 1 0;
E.reveal_be_to_n (Seq.slice b 0 1);
E.reveal_be_to_n (Seq.slice (Seq.slice b 0 1) 0 0) | false |
LowParse.Spec.Int.fst | LowParse.Spec.Int.decode_u64_injective' | val decode_u64_injective' (b1: bytes{Seq.length b1 == 8}) (b2: bytes{Seq.length b2 == 8})
: Lemma (decode_u64 b1 == decode_u64 b2 ==> Seq.equal b1 b2) | val decode_u64_injective' (b1: bytes{Seq.length b1 == 8}) (b2: bytes{Seq.length b2 == 8})
: Lemma (decode_u64 b1 == decode_u64 b2 ==> Seq.equal b1 b2) | let decode_u64_injective'
(b1: bytes { Seq.length b1 == 8 } )
(b2: bytes { Seq.length b2 == 8 } )
: Lemma
(decode_u64 b1 == decode_u64 b2 ==> Seq.equal b1 b2)
= if decode_u64 b1 = decode_u64 b2
then begin
E.lemma_be_to_n_is_bounded b1;
E.lemma_be_to_n_is_bounded b2;
assert (U64.v (U64.uint_to_t (E.be_to_n b1)) == E.be_to_n b1);
assert (U64.v (U64.uint_to_t (E.be_to_n b2)) == E.be_to_n b2);
assert (E.be_to_n b1 == E.be_to_n b2);
E.be_to_n_inj b1 b2
end else () | {
"file_name": "src/lowparse/LowParse.Spec.Int.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 13,
"end_line": 126,
"start_col": 0,
"start_line": 113
} | module LowParse.Spec.Int
open LowParse.Spec.Combinators
let decode_u8
(b: bytes { Seq.length b == 1 } )
: Tot U8.t
= Seq.index b 0
let decode_u8_injective () : Lemma
(make_total_constant_size_parser_precond 1 U8.t decode_u8)
= ()
let tot_parse_u8 =
decode_u8_injective ();
tot_make_total_constant_size_parser 1 U8.t decode_u8
let parse_u8_spec
b
=
Seq.lemma_index_slice b 0 1 0;
E.reveal_be_to_n (Seq.slice b 0 1);
E.reveal_be_to_n (Seq.slice (Seq.slice b 0 1) 0 0)
let parse_u8_spec' b = ()
let serialize_u8 =
Seq.create 1
let serialize_u8_spec x = ()
let decode_u16
(b: bytes { Seq.length b == 2 } )
: GTot U16.t
= E.lemma_be_to_n_is_bounded b;
U16.uint_to_t (E.be_to_n b)
let decode_u16_injective'
(b1: bytes { Seq.length b1 == 2 } )
(b2: bytes { Seq.length b2 == 2 } )
: Lemma
(decode_u16 b1 == decode_u16 b2 ==> Seq.equal b1 b2)
= if decode_u16 b1 = decode_u16 b2
then begin
E.lemma_be_to_n_is_bounded b1;
E.lemma_be_to_n_is_bounded b2;
assert (U32.v (U32.uint_to_t (E.be_to_n b1)) == E.be_to_n b1);
assert (U32.v (U32.uint_to_t (E.be_to_n b2)) == E.be_to_n b2);
assert (E.be_to_n b1 == E.be_to_n b2);
E.be_to_n_inj b1 b2
end else ()
let decode_u16_injective
()
: Lemma
(make_total_constant_size_parser_precond 2 U16.t decode_u16)
= Classical.forall_intro_2 decode_u16_injective'
let parse_u16 =
decode_u16_injective ();
make_total_constant_size_parser 2 U16.t decode_u16
let parse_u16_spec
b
=
E.lemma_be_to_n_is_bounded (Seq.slice b 0 2)
let serialize_u16 =
(fun (x: U16.t) -> E.n_to_be 2 (U16.v x))
let decode_u32
(b: bytes { Seq.length b == 4 } )
: GTot U32.t
= E.lemma_be_to_n_is_bounded b;
U32.uint_to_t (E.be_to_n b)
let decode_u32_injective'
(b1: bytes { Seq.length b1 == 4 } )
(b2: bytes { Seq.length b2 == 4 } )
: Lemma
(decode_u32 b1 == decode_u32 b2 ==> Seq.equal b1 b2)
= if decode_u32 b1 = decode_u32 b2
then begin
E.lemma_be_to_n_is_bounded b1;
E.lemma_be_to_n_is_bounded b2;
assert (U32.v (U32.uint_to_t (E.be_to_n b1)) == E.be_to_n b1);
assert (U32.v (U32.uint_to_t (E.be_to_n b2)) == E.be_to_n b2);
assert (E.be_to_n b1 == E.be_to_n b2);
E.be_to_n_inj b1 b2
end else ()
let decode_u32_injective () : Lemma
(make_total_constant_size_parser_precond 4 U32.t decode_u32)
= Classical.forall_intro_2 decode_u32_injective'
let parse_u32 =
decode_u32_injective ();
make_total_constant_size_parser 4 U32.t decode_u32
let parse_u32_spec
b
=
E.lemma_be_to_n_is_bounded (Seq.slice b 0 4)
let serialize_u32 =
(fun (x: U32.t) -> E.n_to_be 4 (U32.v x))
let decode_u64
(b: bytes { Seq.length b == 8 } )
: GTot U64.t
= E.lemma_be_to_n_is_bounded b;
U64.uint_to_t (E.be_to_n b) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Seq.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "LowParse.Spec.Int.fst"
} | [
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.Endianness",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
b1: LowParse.Bytes.bytes{FStar.Seq.Base.length b1 == 8} ->
b2: LowParse.Bytes.bytes{FStar.Seq.Base.length b2 == 8}
-> FStar.Pervasives.Lemma
(ensures
LowParse.Spec.Int.decode_u64 b1 == LowParse.Spec.Int.decode_u64 b2 ==>
FStar.Seq.Base.equal b1 b2) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"LowParse.Bytes.bytes",
"Prims.eq2",
"Prims.int",
"FStar.Seq.Base.length",
"LowParse.Bytes.byte",
"Prims.op_Equality",
"FStar.UInt64.t",
"LowParse.Spec.Int.decode_u64",
"FStar.Endianness.be_to_n_inj",
"Prims.unit",
"Prims._assert",
"Prims.nat",
"FStar.Endianness.be_to_n",
"Prims.l_or",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"FStar.UInt.size",
"FStar.UInt64.n",
"FStar.UInt64.v",
"FStar.UInt64.uint_to_t",
"FStar.Endianness.lemma_be_to_n_is_bounded",
"Prims.bool",
"Prims.l_True",
"Prims.squash",
"Prims.l_imp",
"FStar.Seq.Base.equal",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let decode_u64_injective' (b1: bytes{Seq.length b1 == 8}) (b2: bytes{Seq.length b2 == 8})
: Lemma (decode_u64 b1 == decode_u64 b2 ==> Seq.equal b1 b2) =
| if decode_u64 b1 = decode_u64 b2
then
(E.lemma_be_to_n_is_bounded b1;
E.lemma_be_to_n_is_bounded b2;
assert (U64.v (U64.uint_to_t (E.be_to_n b1)) == E.be_to_n b1);
assert (U64.v (U64.uint_to_t (E.be_to_n b2)) == E.be_to_n b2);
assert (E.be_to_n b1 == E.be_to_n b2);
E.be_to_n_inj b1 b2) | false |
LowParse.Spec.Int.fst | LowParse.Spec.Int.decode_u32 | val decode_u32 (b: bytes{Seq.length b == 4}) : GTot U32.t | val decode_u32 (b: bytes{Seq.length b == 4}) : GTot U32.t | let decode_u32
(b: bytes { Seq.length b == 4 } )
: GTot U32.t
= E.lemma_be_to_n_is_bounded b;
U32.uint_to_t (E.be_to_n b) | {
"file_name": "src/lowparse/LowParse.Spec.Int.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 29,
"end_line": 74,
"start_col": 0,
"start_line": 70
} | module LowParse.Spec.Int
open LowParse.Spec.Combinators
let decode_u8
(b: bytes { Seq.length b == 1 } )
: Tot U8.t
= Seq.index b 0
let decode_u8_injective () : Lemma
(make_total_constant_size_parser_precond 1 U8.t decode_u8)
= ()
let tot_parse_u8 =
decode_u8_injective ();
tot_make_total_constant_size_parser 1 U8.t decode_u8
let parse_u8_spec
b
=
Seq.lemma_index_slice b 0 1 0;
E.reveal_be_to_n (Seq.slice b 0 1);
E.reveal_be_to_n (Seq.slice (Seq.slice b 0 1) 0 0)
let parse_u8_spec' b = ()
let serialize_u8 =
Seq.create 1
let serialize_u8_spec x = ()
let decode_u16
(b: bytes { Seq.length b == 2 } )
: GTot U16.t
= E.lemma_be_to_n_is_bounded b;
U16.uint_to_t (E.be_to_n b)
let decode_u16_injective'
(b1: bytes { Seq.length b1 == 2 } )
(b2: bytes { Seq.length b2 == 2 } )
: Lemma
(decode_u16 b1 == decode_u16 b2 ==> Seq.equal b1 b2)
= if decode_u16 b1 = decode_u16 b2
then begin
E.lemma_be_to_n_is_bounded b1;
E.lemma_be_to_n_is_bounded b2;
assert (U32.v (U32.uint_to_t (E.be_to_n b1)) == E.be_to_n b1);
assert (U32.v (U32.uint_to_t (E.be_to_n b2)) == E.be_to_n b2);
assert (E.be_to_n b1 == E.be_to_n b2);
E.be_to_n_inj b1 b2
end else ()
let decode_u16_injective
()
: Lemma
(make_total_constant_size_parser_precond 2 U16.t decode_u16)
= Classical.forall_intro_2 decode_u16_injective'
let parse_u16 =
decode_u16_injective ();
make_total_constant_size_parser 2 U16.t decode_u16
let parse_u16_spec
b
=
E.lemma_be_to_n_is_bounded (Seq.slice b 0 2)
let serialize_u16 =
(fun (x: U16.t) -> E.n_to_be 2 (U16.v x)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Seq.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "LowParse.Spec.Int.fst"
} | [
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.Endianness",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | b: LowParse.Bytes.bytes{FStar.Seq.Base.length b == 4} -> Prims.GTot FStar.UInt32.t | Prims.GTot | [
"sometrivial"
] | [] | [
"LowParse.Bytes.bytes",
"Prims.eq2",
"Prims.int",
"FStar.Seq.Base.length",
"LowParse.Bytes.byte",
"FStar.UInt32.uint_to_t",
"FStar.Endianness.be_to_n",
"Prims.unit",
"FStar.Endianness.lemma_be_to_n_is_bounded",
"FStar.UInt32.t"
] | [] | false | false | false | false | false | let decode_u32 (b: bytes{Seq.length b == 4}) : GTot U32.t =
| E.lemma_be_to_n_is_bounded b;
U32.uint_to_t (E.be_to_n b) | false |
LowParse.Spec.Int.fst | LowParse.Spec.Int.parse_u16_spec | val parse_u16_spec
(b: bytes)
: Lemma
(requires (Seq.length b >= 2))
(ensures (
let pp = parse parse_u16 b in
Some? pp /\ (
let (Some (v, consumed)) = pp in
U16.v v == E.be_to_n (Seq.slice b 0 2)
))) | val parse_u16_spec
(b: bytes)
: Lemma
(requires (Seq.length b >= 2))
(ensures (
let pp = parse parse_u16 b in
Some? pp /\ (
let (Some (v, consumed)) = pp in
U16.v v == E.be_to_n (Seq.slice b 0 2)
))) | let parse_u16_spec
b
=
E.lemma_be_to_n_is_bounded (Seq.slice b 0 2) | {
"file_name": "src/lowparse/LowParse.Spec.Int.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 46,
"end_line": 65,
"start_col": 0,
"start_line": 62
} | module LowParse.Spec.Int
open LowParse.Spec.Combinators
let decode_u8
(b: bytes { Seq.length b == 1 } )
: Tot U8.t
= Seq.index b 0
let decode_u8_injective () : Lemma
(make_total_constant_size_parser_precond 1 U8.t decode_u8)
= ()
let tot_parse_u8 =
decode_u8_injective ();
tot_make_total_constant_size_parser 1 U8.t decode_u8
let parse_u8_spec
b
=
Seq.lemma_index_slice b 0 1 0;
E.reveal_be_to_n (Seq.slice b 0 1);
E.reveal_be_to_n (Seq.slice (Seq.slice b 0 1) 0 0)
let parse_u8_spec' b = ()
let serialize_u8 =
Seq.create 1
let serialize_u8_spec x = ()
let decode_u16
(b: bytes { Seq.length b == 2 } )
: GTot U16.t
= E.lemma_be_to_n_is_bounded b;
U16.uint_to_t (E.be_to_n b)
let decode_u16_injective'
(b1: bytes { Seq.length b1 == 2 } )
(b2: bytes { Seq.length b2 == 2 } )
: Lemma
(decode_u16 b1 == decode_u16 b2 ==> Seq.equal b1 b2)
= if decode_u16 b1 = decode_u16 b2
then begin
E.lemma_be_to_n_is_bounded b1;
E.lemma_be_to_n_is_bounded b2;
assert (U32.v (U32.uint_to_t (E.be_to_n b1)) == E.be_to_n b1);
assert (U32.v (U32.uint_to_t (E.be_to_n b2)) == E.be_to_n b2);
assert (E.be_to_n b1 == E.be_to_n b2);
E.be_to_n_inj b1 b2
end else ()
let decode_u16_injective
()
: Lemma
(make_total_constant_size_parser_precond 2 U16.t decode_u16)
= Classical.forall_intro_2 decode_u16_injective'
let parse_u16 =
decode_u16_injective ();
make_total_constant_size_parser 2 U16.t decode_u16 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Seq.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "LowParse.Spec.Int.fst"
} | [
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.Endianness",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | b: LowParse.Bytes.bytes
-> FStar.Pervasives.Lemma (requires FStar.Seq.Base.length b >= 2)
(ensures
(let pp = LowParse.Spec.Base.parse LowParse.Spec.Int.parse_u16 b in
Some? pp /\
(let _ = pp in
(let FStar.Pervasives.Native.Some #_ (FStar.Pervasives.Native.Mktuple2 #_ #_ v _) = _ in
FStar.UInt16.v v == FStar.Endianness.be_to_n (FStar.Seq.Base.slice b 0 2))
<:
Prims.logical))) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"LowParse.Bytes.bytes",
"FStar.Endianness.lemma_be_to_n_is_bounded",
"FStar.Seq.Base.slice",
"LowParse.Bytes.byte",
"Prims.unit"
] | [] | true | false | true | false | false | let parse_u16_spec b =
| E.lemma_be_to_n_is_bounded (Seq.slice b 0 2) | false |
Steel.Memory.fst | Steel.Memory.lift_tot_action_with_frame | val lift_tot_action_with_frame
(#a #e #fp #fp': _)
($f: tot_action_with_frame_except e fp a fp')
(frame: slprop)
: MstTot a e fp fp' frame (fun _ -> True) (fun _ _ _ -> True) | val lift_tot_action_with_frame
(#a #e #fp #fp': _)
($f: tot_action_with_frame_except e fp a fp')
(frame: slprop)
: MstTot a e fp fp' frame (fun _ -> True) (fun _ _ _ -> True) | let lift_tot_action_with_frame #a #e #fp #fp'
($f:tot_action_with_frame_except e fp a fp')
(frame:slprop)
: MstTot a e fp fp' frame (fun _ -> True) (fun _ _ _ -> True)
= let m0 = NMSTTotal.get () in
assert (inames_ok e m0);
ac_reasoning_for_m_frame_preserving fp frame (locks_invariant e m0) m0;
assert (interp (fp `star` frame `star` locks_invariant e m0) m0);
assert (interp (fp `star` locks_invariant e m0) m0);
let m0' : hmem_with_inv_except e fp = m0 in
let r = f frame m0' in
let (| x, m1 |) = r in
ac_reasoning_for_m_frame_preserving (fp' x) frame (locks_invariant e m1) m1;
assert (interp (fp' x `star` frame `star` locks_invariant e m1) m1);
assert (interp (fp' x `star` locks_invariant e m1) m1);
let m1' : hmem_with_inv_except e (fp' x) = m1 in
NMSTTotal.put #_ #(mem_evolves) m1;
x | {
"file_name": "lib/steel/Steel.Memory.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 5,
"end_line": 841,
"start_col": 0,
"start_line": 824
} | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Memory
module F = FStar.FunctionalExtensionality
open FStar.FunctionalExtensionality
open FStar.PCM
module H = Steel.Heap
noeq
type lock_state : Type u#(a + 1) =
| Invariant : inv:H.slprop u#a -> lock_state
let lock_store : Type u#(a+1) = list (lock_state u#a)
noeq
type mem : Type u#(a + 1) =
{
ctr: nat;
heap: H.heap u#a;
locks: lock_store u#a;
}
let heap_of_mem (x:mem) : H.heap = x.heap
let mem_of_heap (h:H.heap) : mem = {
ctr = 0;
heap = h;
locks = []
}
let mem_set_heap (m:mem) (h:H.heap) : mem = {
ctr = m.ctr;
heap = h;
locks = m.locks;
}
let core_mem (m:mem) : mem = mem_of_heap (heap_of_mem m)
let core_mem_invol m = ()
let disjoint (m0 m1:mem u#h)
: prop
= m0.ctr == m1.ctr /\
H.disjoint m0.heap m1.heap /\
m0.locks == m1.locks
let disjoint_sym m0 m1 = ()
let join m0 m1 = {
ctr = m0.ctr;
heap = H.join m0.heap m1.heap;
locks = m0.locks
}
let join_commutative m0 m1 =
H.join_commutative m0.heap m1.heap
let disjoint_join m0 m1 m2 =
H.disjoint_join m0.heap m1.heap m2.heap
let join_associative m0 m1 m2 =
H.join_associative m0.heap m1.heap m2.heap
let slprop = H.slprop
let interp p m = H.interp p m.heap
let equiv p1 p2 = forall m. interp p1 m <==> interp p2 m
let slprop_extensionality p q =
assert (forall m. interp p m <==> interp q m);
let aux (h:H.heap)
: Lemma (H.interp p h <==> H.interp q h)
[SMTPat (H.interp p h)]
= let m : mem = { ctr = 0; heap = h; locks = [] } in
assert (interp p m <==> interp q m)
in
assert (forall h. H.interp p h <==> H.interp q h);
Steel.Heap.slprop_extensionality p q
let reveal_equiv p1 p2 = ()
let core_ref = H.core_ref
let core_ref_null = H.core_ref_null
let core_ref_is_null r = H.core_ref_is_null r
let emp : slprop u#a = H.emp
let pure = H.pure
let pts_to = H.pts_to
let h_and = H.h_and
let h_or = H.h_or
let star = H.star
let wand = H.wand
let h_exists = H.h_exists
let h_forall = H.h_forall
////////////////////////////////////////////////////////////////////////////////
//properties of equiv
////////////////////////////////////////////////////////////////////////////////
let equiv_symmetric (p1 p2:slprop u#a) = H.equiv_symmetric p1 p2
#push-options "--warn_error -271"
let equiv_heap_iff_equiv (p1 p2:slprop u#a)
: Lemma (ensures (H.equiv p1 p2 <==> equiv p1 p2))
[SMTPat (equiv p1 p2)]
= let aux_lr ()
: Lemma
(requires H.equiv p1 p2)
(ensures equiv p1 p2)
[SMTPat ()]
= ()
in
let aux_rl_helper1 (h:H.heap)
: Lemma
(requires equiv p1 p2 /\ H.interp p1 h)
(ensures H.interp p2 h)
[SMTPat ()]
= assert (interp p2 (mem_of_heap h))
in
let aux_rl_helper2 (h:H.heap)
: Lemma
(requires equiv p1 p2 /\ H.interp p2 h)
(ensures H.interp p1 h)
[SMTPat ()]
= assert (interp p2 (mem_of_heap h))
in
let aux_rl ()
: Lemma
(requires equiv p1 p2)
(ensures H.equiv p1 p2)
[SMTPat ()]
= () in
()
let equiv_heap_iff_equiv_forall ()
: Lemma (ensures (forall p1 p2. H.equiv p1 p2 <==> equiv p1 p2))
= let aux p1 p2
: Lemma (ensures (H.equiv p1 p2 <==> equiv p1 p2))
[SMTPat ()]
= equiv_heap_iff_equiv p1 p2
in
()
#pop-options
let equiv_extensional_on_star (p1 p2 p3:slprop u#a) =
equiv_heap_iff_equiv_forall ();
H.equiv_extensional_on_star p1 p2 p3
let emp_unit p = H.emp_unit p
let intro_emp m = H.intro_emp (heap_of_mem m)
let pure_equiv p q = H.pure_equiv p q
let pure_interp q m = H.pure_interp q (heap_of_mem m)
let pure_star_interp p q m = H.pure_star_interp p q (heap_of_mem m)
////////////////////////////////////////////////////////////////////////////////
//pts_to
////////////////////////////////////////////////////////////////////////////////
let pts_to_compatible #a #pcm x v0 v1 m
= H.pts_to_compatible #a #pcm x v0 v1 (heap_of_mem m)
let pts_to_compatible_equiv #a #pcm x v0 v1
= H.pts_to_compatible_equiv #a #pcm x v0 v1
let pts_to_not_null #a #pcm x v m
= H.pts_to_not_null #a #pcm x v (heap_of_mem m)
////////////////////////////////////////////////////////////////////////////////
// star
////////////////////////////////////////////////////////////////////////////////
let intro_star p q mp mq =
H.intro_star p q (heap_of_mem mp) (heap_of_mem mq)
let elim_star p q m =
let h = heap_of_mem m in
H.elim_star p q h;
assert (exists hl hr. H.disjoint hl hr /\ H.join hl hr == h /\ H.interp p hl /\ H.interp q hr);
let hl = FStar.IndefiniteDescription.indefinite_description_tot H.heap (fun hl ->
exists hr. H.disjoint hl hr /\ H.join hl hr == h /\ H.interp p hl /\ H.interp q hr) in
let hr = FStar.IndefiniteDescription.indefinite_description_tot H.heap (fun hr ->
H.disjoint hl hr /\ H.join hl hr == h /\ H.interp p hl /\ H.interp q hr) in
let ml = mem_set_heap m hl in
let mr = mem_set_heap m hr in
assert (disjoint ml mr);
assert (m == join ml mr);
assert (interp p ml);
assert (interp q mr);
()
let interp_star
(p q: slprop)
(m: mem)
: Lemma
(interp (p `star` q) m <==> (exists (mp: mem) (mq: mem) . disjoint mp mq /\ interp p mp /\ interp q mq /\ join mp mq == m))
= let left = interp (p `star` q) m in
let right = exists (mp: mem) (mq: mem) . disjoint mp mq /\ interp p mp /\ interp q mq /\ join mp mq == m in
let f ()
: Lemma
(requires left)
(ensures right)
=
elim_star p q m
in
let g ()
: Lemma
(requires right)
(ensures left)
=
Classical.exists_elim left #_ #(fun mp -> exists (mq: mem) . disjoint mp mq /\ interp p mp /\ interp q mq /\ join mp mq == m) () (fun mp ->
Classical.exists_elim left #_ #(fun mq -> disjoint mp mq /\ interp p mp /\ interp q mq /\ join mp mq == m) () (fun mq ->
intro_star p q mp mq
)
)
in
Classical.move_requires f ();
Classical.move_requires g ()
let star_commutative (p1 p2:slprop) =
H.star_commutative p1 p2
let star_associative (p1 p2 p3:slprop) =
H.star_associative p1 p2 p3
let star_congruence (p1 p2 p3 p4:slprop) =
equiv_heap_iff_equiv_forall ();
H.star_congruence p1 p2 p3 p4
let affine_star (p q:slprop) (m:mem) =
H.affine_star p q (heap_of_mem m)
////////////////////////////////////////////////////////////////////////////////
// Invariants on the lock store
////////////////////////////////////////////////////////////////////////////////
let iname = nat
module S = FStar.Set
module L = FStar.List.Tot
module W = FStar.Witnessed.Core
let rec lock_store_invariant (e:inames) (l:lock_store u#a) : slprop u#a =
let current_addr = L.length l - 1 in
match l with
| [] -> emp
| Invariant p :: tl ->
if current_addr `S.mem` e then
lock_store_invariant e tl
else
p `star` lock_store_invariant e tl
let lock_i (i:iname) (l:lock_store { i < L.length l }) =
let ix = L.length l - i - 1 in
L.index l ix
let iname_for_p (i:iname) (p:slprop) : W.s_predicate lock_store =
fun l ->
i < L.length l /\
(lock_i i l).inv == p
let lock_store_evolves : FStar.Preorder.preorder lock_store =
fun (l1 l2 : lock_store) ->
L.length l2 >= L.length l1 /\
(forall (i:nat{i < L.length l1}).
(lock_i i l1).inv == (lock_i i l2).inv)
let inames_in (e:inames) (l:lock_store) : prop = forall i. Set.mem i e ==> i < L.length l
let inames_ok e m = inames_in e m.locks
let inames_ok_empty m = ()
let extend_lock_store (e:inames) (l:lock_store{e `inames_in` l}) (p:slprop)
: i:iname &
l':lock_store {
lock_store_invariant e l' == p `star` lock_store_invariant e l /\
iname_for_p i p l'
}
= (| L.length l, Invariant p :: l |)
let set_add (i:iname) (s:inames) = Set.union (Set.singleton i) s
let rec move_invariant (e:inames) (l:lock_store) (p:slprop)
(i:iname{iname_for_p i p l /\ ~(i `Set.mem` e)})
: Lemma (H.equiv (lock_store_invariant e l)
(p `star` lock_store_invariant (set_add i e) l))
= let rec aux (i:iname) (m:lock_store)
: Lemma (requires i >= L.length m)
(ensures (lock_store_invariant e m `H.equiv` lock_store_invariant (set_add i e) m))
= match m with
| [] -> ()
| Invariant p::tl ->
aux i tl;
H.star_congruence p (lock_store_invariant e tl) p (lock_store_invariant (set_add i e) tl)
in
let current_addr = L.length l - 1 in
match l with
| [] -> ()
| Invariant q::tl ->
if i = current_addr
then begin
assert (lock_store_invariant e l == p `star` lock_store_invariant e tl);
aux i tl;
H.star_congruence p (lock_store_invariant e tl) p (lock_store_invariant (set_add i e) tl);
()
end
else begin
move_invariant e tl p i;
assert (lock_store_invariant e tl `equiv`
(p `star` lock_store_invariant (set_add i e) tl));
H.star_congruence q (lock_store_invariant e tl) q (p `star` lock_store_invariant (set_add i e) tl);
if Set.mem current_addr e
then ()
else begin
let r = lock_store_invariant (set_add i e) tl in
assert (lock_store_invariant e l `equiv`
(q `star` (p `star` r)));
H.star_associative q p r;
H.star_commutative q p;
H.star_congruence (q `star` p) r (p `star` q) r;
H.star_associative p q r
end
end
let heap_ctr_valid (ctr:nat) (h:H.heap u#a) : prop =
h `H.free_above_addr` ctr
let ctr_validity (ctr:nat) (h:H.heap) : slprop =
H.pure (heap_ctr_valid ctr h)
let locks_invariant (e:inames) (m:mem u#a) : slprop u#a =
lock_store_invariant e m.locks
`star`
ctr_validity m.ctr (heap_of_mem m)
let full_mem_pred (m:mem) = H.full_heap_pred (heap_of_mem m)
(***** Following lemmas are needed in Steel.Effect *****)
let core_mem_interp (hp:slprop u#a) (m:mem u#a) = ()
let interp_depends_only_on (hp:slprop u#a) = H.interp_depends_only_on hp
let a_mem_prop_as_a_heap_prop
(sl: slprop u#a)
(f: a_mem_prop sl)
: Tot (H.a_heap_prop u#a)
=
let g (h: H.heap u#a) : Tot prop = interp sl (mem_of_heap h) /\ f (mem_of_heap h) in
let phi0 (h0 h1: H.heap u#a) : Lemma
(requires (g h0 /\ H.disjoint h0 h1))
(ensures (g h0 /\ H.disjoint h0 h1 /\ g (H.join h0 h1)))
= assert (mem_of_heap (H.join h0 h1) == mem_of_heap h0 `join` mem_of_heap h1);
interp_depends_only_on sl
in
let phi1 (h0 h1: H.heap u#a) : Lemma
(ensures ((g h0 /\ H.disjoint h0 h1) ==> g (H.join h0 h1)))
=
Classical.move_requires (phi0 h0) h1
in
Classical.forall_intro_2 phi1;
g
let refine_slprop sl f = H.as_slprop (a_mem_prop_as_a_heap_prop sl f)
let interp_refine_slprop sl f m =
assert ((interp sl m /\ f m) <==> interp sl (core_mem m) /\ f (core_mem m))
let dep_hprop
(s: slprop)
(f: (hmem s -> Tot slprop))
(h: H.heap)
: Tot prop
= exists (h1: H.heap) . exists (h2: H.heap) . interp s (mem_of_heap h1) /\ H.disjoint h1 h2 /\ interp (f (mem_of_heap h1)) (mem_of_heap h2) /\ h == h1 `H.join` h2
let dep_hprop_is_affine0
(s: slprop)
(f: (hmem s -> Tot slprop))
(h h': H.heap)
(sq' : squash (dep_hprop s f h /\ H.disjoint h h'))
: Lemma
(H.disjoint h h' /\ dep_hprop s f (H.join h h'))
=
let p2 (h h1 h2: H.heap) : Tot prop =
interp s (mem_of_heap h1) /\
H.disjoint h1 h2 /\ interp (f (mem_of_heap h1)) (mem_of_heap h2) /\ h == h1 `H.join` h2
in
let p1 (h h1: H.heap) : Tot prop =
(exists h2 . p2 h h1 h2)
in
let h1 =
FStar.IndefiniteDescription.indefinite_description_ghost H.heap (p1 h)
in
let h2 =
FStar.IndefiniteDescription.indefinite_description_ghost H.heap (p2 h h1)
in
H.disjoint_join h' h1 h2;
assert (H.disjoint h2 h');
let h2' = H.join h2 h' in
H.join_commutative h2 h' ;
assert (h2' == H.join h' h2);
assert (H.disjoint h1 h2');
assert (mem_of_heap h2' == mem_of_heap h2 `join` mem_of_heap h');
interp_depends_only_on (f (mem_of_heap h1));
assert (interp (f (mem_of_heap h1)) (mem_of_heap h2'));
H.join_commutative h1 h2;
H.join_associative h' h2 h1;
H.join_commutative h' h;
H.join_commutative h2' h1;
assert (H.join h h' == h1 `H.join` h2')
let impl_intro_gen (#p: Type0) (#q: Type0) ($prf: (squash p -> Lemma (q )))
: Lemma (p ==> q)
= Classical.impl_intro_gen #p #(fun _ -> q) prf
let dep_hprop_is_affine1
(s: slprop)
(f: (hmem s -> Tot slprop))
(h0 h1: H.heap)
: Lemma
((dep_hprop s f h0 /\ H.disjoint h0 h1) ==> (H.disjoint h0 h1 /\ dep_hprop s f (H.join h0 h1)))
= impl_intro_gen (dep_hprop_is_affine0 s f h0 h1)
let dep_hprop_is_affine
(s: slprop)
(f: (hmem s -> Tot slprop))
: Lemma
(H.heap_prop_is_affine (dep_hprop s f))
= Classical.forall_intro_2 (dep_hprop_is_affine1 s f)
let sdep
(s: slprop)
(f: (hmem s -> Tot slprop))
: Tot slprop
=
dep_hprop_is_affine s f;
H.as_slprop (dep_hprop s f)
let interp_sdep
(s: slprop)
(f: (hmem s -> Tot slprop))
(m: mem)
: Lemma
(requires (dep_slprop_is_affine s f))
(ensures (
interp (sdep s f) m <==> (exists m1 m2 . interp s m1 /\ interp (f m1) m2 /\ disjoint m1 m2 /\ join m1 m2 == m)
))
=
dep_hprop_is_affine s f;
assert (forall m1 m2 . (interp s m1 /\ interp (f m1) m2 /\ disjoint m1 m2 /\ join m1 m2 == m) ==> (
interp s (mem_of_heap m1.heap) /\ interp (f (mem_of_heap m1.heap)) (mem_of_heap m2.heap) /\
H.disjoint m1.heap m2.heap /\
H.join m1.heap m2.heap == m.heap
));
interp_depends_only_on s;
Classical.forall_intro (fun m -> interp_depends_only_on (f m));
assert (forall h1 h2 . (interp s (mem_of_heap h1) /\ interp (f (mem_of_heap h1)) (mem_of_heap h2) /\ H.disjoint h1 h2 /\ H.join h1 h2 == m.heap) ==> (
core_mem (mem_of_heap h1) == core_mem (mem_set_heap m h1) /\
interp s (core_mem (mem_of_heap h1)) /\
interp s (mem_set_heap m h1) /\
core_mem (mem_of_heap h1) == core_mem (mem_set_heap m h1) /\
f (mem_set_heap m h1) `equiv` f (mem_of_heap h1) /\
interp (f (mem_set_heap m h1)) (mem_of_heap h2) /\
interp (f (mem_set_heap m h1)) (mem_set_heap m h2) /\
disjoint (mem_set_heap m h1) (mem_set_heap m h2) /\
join (mem_set_heap m h1) (mem_set_heap m h2) == m
));
()
let h_exists_cong (#a:Type) (p q : a -> slprop)
: Lemma
(requires (forall x. p x `equiv` q x))
(ensures (h_exists p `equiv` h_exists q))
= equiv_heap_iff_equiv_forall ();
H.h_exists_cong p q
let intro_h_exists #a x p m = H.intro_h_exists x p (heap_of_mem m)
let elim_h_exists (#a:_) (p:a -> slprop) (m:mem) = H.elim_h_exists p (heap_of_mem m)
let intro_h_forall (#a:_) (p:a -> slprop) (m:mem) = H.intro_h_forall p (heap_of_mem m)
let elim_h_forall (#a:_) (p:a -> slprop) (m:mem) (x:a) = H.elim_h_forall p (heap_of_mem m) x
let intro_h_and (p q: slprop) (m:mem) = H.intro_h_and p q (heap_of_mem m)
let elim_h_and (p q: slprop) (m:mem) = H.elim_h_and p q (heap_of_mem m)
let intro_h_or_left (p q: slprop) (m:mem) = H.intro_h_or_left p q (heap_of_mem m)
let intro_h_or_right (p q: slprop) (m:mem) = H.intro_h_or_right p q (heap_of_mem m)
let elim_h_or (p q: slprop) (m:mem) = H.elim_h_or p q (heap_of_mem m)
let intro_wand (p1 p2: slprop u#a) (m:mem) =
introduce
(forall m1. m `disjoint` m1 /\ interp p1 m1 ==> interp p2 (join m m1))
==> interp (wand p1 p2) m
with _. (
assert (forall m1. m `disjoint` m1 /\ interp p1 m1 ==> interp p2 (join m m1));
H.intro_wand p1 p2 (heap_of_mem m);
let h = heap_of_mem m in
assert ((forall h1. h `H.disjoint` h1 /\ H.interp p1 h1 ==> H.interp p2 (H.join h h1))
==> H.interp (wand p1 p2) h);
introduce forall h1. (h `H.disjoint` h1 /\ H.interp p1 h1 ==> H.interp p2 (H.join h h1))
with (
introduce (h `H.disjoint` h1 /\ H.interp p1 h1) ==> H.interp p2 (H.join h h1)
with _. (
assert (h `H.disjoint` h1);
let m1 = {
ctr = m.ctr;
heap = h1;
locks = m.locks
}
in assert (m `disjoint` m1)
)
)
)
(** Eliminating a wand by proving a heap that satisfies the LHS **)
let elim_wand (p1 p2: slprop u#a) (m:mem) (m1:mem) = H.elim_wand p1 p2 (heap_of_mem m) (heap_of_mem m1)
////////////////////////////////////////////////////////////////////////////////
// Preorders and effects
////////////////////////////////////////////////////////////////////////////////
module PP = Steel.Preorder
let mem_evolves =
fun (m0 m1:full_mem) ->
H.heap_evolves (heap_of_mem m0) (heap_of_mem m1) /\
m0.ctr <= m1.ctr /\
lock_store_evolves m0.locks m1.locks
(** See [Steel.Heap.is_frame_preserving]. We add in [lock_invariants] now *)
let preserves_frame (e:inames) (pre post:slprop) (m0 m1:mem) =
forall (frame:slprop).
interp ((pre `star` frame) `star` locks_invariant e m0) m0 ==>
(interp ((post `star` frame) `star` locks_invariant e m1) m1 /\
(forall (f_frame:mprop frame). f_frame (core_mem m0) == f_frame (core_mem m1)))
(**
This is a version of MstTot with frame quantified, as part of preserves_frame
*)
effect MstTotNF (a:Type u#a) (except:inames) (expects:slprop u#1) (provides: a -> slprop u#1) =
NMSTTotal.NMSTATETOT a (full_mem u#1) mem_evolves
(requires fun m0 ->
inames_ok except m0 /\
interp (expects `star` locks_invariant except m0) m0)
(ensures fun m0 x m1 ->
inames_ok except m1 /\
interp (provides x `star` locks_invariant except m1) m1 /\
preserves_frame except expects (provides x) m0 m1)
////////////////////////////////////////////////////////////////////////////////
// Lifting heap actions
////////////////////////////////////////////////////////////////////////////////
(**
Heap actions come in two equivalent flavors:
- one that take an explicit frame as argument (action_with_frame)
- and one that quantify over all the frame
We therefore define two lift routes:
- a direct route for those with explicit frame
- via MstTotNF for the rest
*)
let tot_pre_action_nf_except (e:inames) (fp:slprop u#a) (a:Type u#b) (fp':a -> slprop u#a) =
hmem_with_inv_except e fp ->
(x:a & hmem_with_inv_except e (fp' x))
let tot_pre_action_nf = tot_pre_action_nf_except S.empty
let ac_reasoning_for_m_frame_preserving
(p q r:slprop u#a) (m:mem u#a)
: Lemma
(requires interp ((p `star` q) `star` r) m)
(ensures interp (p `star` r) m)
= calc (equiv) {
(p `star` q) `star` r;
(equiv) { star_commutative p q;
equiv_extensional_on_star (p `star` q) (q `star` p) r }
(q `star` p) `star` r;
(equiv) { star_associative q p r }
q `star` (p `star` r);
};
assert (interp (q `star` (p `star` r)) m);
affine_star q (p `star` r) m
let is_frame_preserving
(#e:inames)
(#a:Type u#b)
(#fp:slprop u#a)
(#fp':a -> slprop u#a)
(f:tot_pre_action_nf_except e fp a fp') =
forall (frame:slprop u#a) (m0:hmem_with_inv_except e (fp `star` frame)).
(ac_reasoning_for_m_frame_preserving fp frame (locks_invariant e m0) m0;
let (| x, m1 |) = f m0 in
interp ((fp' x `star` frame) `star` locks_invariant e m1) m1 /\
mem_evolves m0 m1 /\
(forall (mp:mprop frame). mp (core_mem m0) == mp (core_mem m1)))
let tot_action_nf_except (e:inames) (fp:slprop u#a) (a:Type u#b) (fp':a -> slprop u#a) =
f:tot_pre_action_nf_except e fp a fp'{ is_frame_preserving f }
let tot_action_nf = tot_action_nf_except S.empty
let linv e (m:mem) = locks_invariant e m
let hheap_of_hmem #fp #e (m:hmem_with_inv_except e fp)
: h:H.hheap (fp `star` linv e m) { h `H.free_above_addr` m.ctr}
= let h = heap_of_mem m in
H.pure_interp (heap_ctr_valid m.ctr (heap_of_mem m)) h;
h
let hmem_of_hheap #e (#fp0 #fp1:slprop) (m:hmem_with_inv_except e fp0)
(h:H.full_hheap (fp1 `star` linv e m) {
h `Heap.free_above_addr` m.ctr
})
: m1:hmem_with_inv_except e fp1{linv e m `equiv` linv e m1}
= let m1 : mem = { m with heap = h } in
assert (interp (fp1 `star` linv e m) m1);
star_commutative fp1 (linv e m);
assert (interp (linv e m `star` fp1) m1);
assert (linv e m1 == (lock_store_invariant e m1.locks)
`star` ctr_validity m1.ctr (heap_of_mem m1));
assert (linv e m == (lock_store_invariant e m1.locks)
`star` ctr_validity m1.ctr (heap_of_mem m));
H.pure_interp (heap_ctr_valid m1.ctr (heap_of_mem m))
(heap_of_mem m);
assert (heap_ctr_valid m1.ctr (heap_of_mem m) <==>
heap_ctr_valid m1.ctr (heap_of_mem m1));
H.pure_equiv (heap_ctr_valid m1.ctr (heap_of_mem m))
(heap_ctr_valid m1.ctr (heap_of_mem m1));
H.star_congruence (lock_store_invariant e m1.locks)
(ctr_validity m1.ctr (heap_of_mem m1))
(lock_store_invariant e m1.locks)
(ctr_validity m1.ctr (heap_of_mem m));
assert (linv e m `equiv` linv e m1);
let _ = equiv_extensional_on_star (linv e m) (linv e m1) fp1 in
assert ((linv e m `star` fp1) `equiv` (linv e m1 `star` fp1));
assert (interp (linv e m1 `star` fp1) m1);
star_commutative (linv e m1) fp1;
assert (interp (fp1 `star` linv e m1) m1);
m1
let with_inv_except (m:mem) e (fp:slprop) = interp (fp `star` locks_invariant e m) m
#push-options "--warn_error -271"
let as_hprop (frame:slprop) (mp:mprop frame)
: hp:H.hprop frame{forall m. mp (core_mem m) == hp (heap_of_mem m)}
= let f = fun h -> mp (mem_of_heap h) in
assert (forall m. mp (core_mem m) == f (heap_of_mem m));
let aux (m0:H.hheap frame) (m1:H.heap{H.disjoint m0 m1})
: Lemma
(ensures (mem_of_heap (H.join m0 m1) == join (mem_of_heap m0) (mem_of_heap m1)))
[SMTPat ()]
= ()
in
f
let mprop_preservation_of_hprop_preservation
(p:slprop) (m0 m1:mem)
: Lemma
(requires (forall (hp:H.hprop p). hp (heap_of_mem m0) == hp (heap_of_mem m1)))
(ensures (forall (mp:mprop p). mp (core_mem m0) == mp (core_mem m1)))
= let aux (mp:mprop p)
: Lemma (mp (core_mem m0) == mp (core_mem m1))
[SMTPat()]
= assert (as_hprop p mp (heap_of_mem m0) == as_hprop p mp (heap_of_mem m1))
in
()
let lift_heap_action (#fp:slprop) (#a:Type) (#fp':a -> slprop)
(e:inames)
($f:H.action fp a fp')
: tot_action_nf_except e fp a fp'
= let g : tot_pre_action_nf_except e fp a fp' = fun m ->
let h0 = hheap_of_hmem m in
let (| x, h' |) = f h0 in
(| x, hmem_of_hheap m h' |)
in
let aux (frame:slprop) (m0:hmem_with_inv_except e (fp `star` frame))
: Lemma
(ensures
(ac_reasoning_for_m_frame_preserving fp frame (locks_invariant e m0) m0;
let (| x, m1 |) = g m0 in
interp ((fp' x `star` frame) `star` locks_invariant e m1) m1 /\
mem_evolves m0 m1 /\
(forall (mp:mprop frame). mp (core_mem m0) == mp (core_mem m1))))
[SMTPat ()]
= ac_reasoning_for_m_frame_preserving fp frame (locks_invariant e m0) m0;
let (| x, m1 |) = g m0 in
let h0 = hheap_of_hmem m0 in
let (| x', h1 |) = f h0 in
H.action_framing f (linv e m0) h0;
assert (x == x');
star_associative fp frame (linv e m0);
H.action_framing f (frame `star` linv e m0) h0;
assert (H.interp ((fp' x) `star` (frame `star` linv e m0)) h1);
star_associative (fp' x) frame (linv e m0);
assert (H.interp ((fp' x `star` frame) `star` linv e m0) h1);
let h1' : H.hheap ((fp' x `star` frame) `star` linv e m0) = h1 in
assert (m1 == hmem_of_hheap m0 h1');
assert (with_inv_except m1 e (fp' x `star` frame));
assert (forall (hp:H.hprop frame). hp h0 == hp h1);
mprop_preservation_of_hprop_preservation frame m0 m1;
()
in
assert (is_frame_preserving g);
g
let frame_preserving_respects_preorder #a #e #fp #fp' ($f:tot_action_nf_except e fp a fp') (m0:hmem_with_inv_except e fp)
: Lemma (let (| x, m1 |) = f m0 in
mem_evolves m0 m1)
= let aux (frame:slprop) (m0:hmem_with_inv_except e (fp `star` frame))
: Lemma
(ac_reasoning_for_m_frame_preserving fp frame (locks_invariant e m0) m0;
let (| x, m1 |) = f m0 in
interp ((fp' x `star` frame) `star` locks_invariant e m1) m1 /\
mem_evolves m0 m1)
= ()
in
H.emp_unit fp;
assert (interp (fp `star` linv e m0) m0);
H.star_congruence (fp `star` emp) (linv e m0) fp (linv e m0);
assert (interp ((fp `star` emp) `star` linv e m0) m0);
aux emp m0
let lift_tot_action_nf #a #e #fp #fp' ($f:tot_action_nf_except e fp a fp')
: MstTotNF a e fp fp'
= let m0 = NMSTTotal.get () in
let m0' : hmem_with_inv_except e fp = m0 in
let r = f m0' in
let (| x, m1 |) = r in
let m1' : hmem_with_inv_except e (fp' x) = m1 in
assert (is_frame_preserving f);
assert (m1 == dsnd (f m0));
frame_preserving_respects_preorder f m0;
NMSTTotal.put #_ #(mem_evolves) m1;
x
let lift_tot_action #a #e #fp #fp'
($f:tot_action_nf_except e fp a fp')
(frame:slprop)
: MstTot a e fp fp' frame (fun _ -> True) (fun _ _ _ -> True)
= let m0 = NMSTTotal.get #(full_mem) #_ () in
ac_reasoning_for_m_frame_preserving fp frame (locks_invariant e m0) m0;
assert (interp (fp `star` frame `star` locks_invariant e m0) m0);
assert (interp (fp `star` locks_invariant e m0) m0);
lift_tot_action_nf f
(**
Now defining the lift for heap actions with explicit frame
*)
let tot_action_with_frame_except
(e:inames)
(fp:slprop u#a)
(a:Type u#b)
(fp':a -> slprop u#a)
= frame:slprop u#a ->
m0:hmem_with_inv_except e (fp `star` frame) ->
Pure (x:a & hmem_with_inv_except e (fp' x `star` frame))
(requires True)
(ensures fun (| x, m1 |) ->
mem_evolves m0 m1 /\
(forall (mp:mprop frame). mp (core_mem m0) == mp (core_mem m1)))
let tot_action_with_frame = tot_action_with_frame_except S.empty
let lift_heap_action_with_frame
(#fp:slprop u#a)
(#a:Type u#b)
(#fp':a -> slprop u#a)
(e:inames)
($f:H.action_with_frame fp a fp')
: tot_action_with_frame_except e fp a fp'
= fun frame m0 ->
let h0 = hheap_of_hmem m0 in
calc (equiv) {
fp `star` frame `star` locks_invariant e m0;
(equiv) { star_associative fp frame (locks_invariant e m0) }
fp `star` (frame `star` locks_invariant e m0);
};
assert (H.interp (fp `star` frame `star` locks_invariant e m0) h0);
assert (H.interp (fp `star` (frame `star` locks_invariant e m0)) h0);
//key: apply the heap action with frame * locks_invariant e m0
let (| x, h1 |) = f (frame `star` locks_invariant e m0) h0 in
calc (equiv) {
fp' x `star` (frame `star` locks_invariant e m0);
(equiv) { star_associative (fp' x) frame (locks_invariant e m0) }
fp' x `star` frame `star` locks_invariant e m0;
};
assert (H.interp (fp' x `star` (frame `star` locks_invariant e m0)) h1);
assert (H.interp (fp' x `star` frame `star` locks_invariant e m0) h1);
let m1 = hmem_of_hheap m0 h1 in
assert (mem_evolves m0 m1);
mprop_preservation_of_hprop_preservation (frame `star` locks_invariant e m0) m0 m1;
assert (forall (mp:mprop frame). mp (core_mem m0) == mp (core_mem m1));
(| x, m1 |) | {
"checked_file": "/",
"dependencies": [
"Steel.Preorder.fst.checked",
"Steel.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Witnessed.Core.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.PCM.fst.checked",
"FStar.NMSTTotal.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Memory.fst"
} | [
{
"abbrev": true,
"full_module": "Steel.Preorder",
"short_module": "PP"
},
{
"abbrev": true,
"full_module": "FStar.Witnessed.Core",
"short_module": "W"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Set",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Set",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Steel.Heap",
"short_module": "H"
},
{
"abbrev": false,
"full_module": "FStar.PCM",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "F"
},
{
"abbrev": false,
"full_module": "FStar.PCM",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | $f: Steel.Memory.tot_action_with_frame_except e fp a fp' -> frame: Steel.Memory.slprop
-> Steel.Memory.MstTot a | Steel.Memory.MstTot | [] | [] | [
"Steel.Memory.inames",
"Steel.Memory.slprop",
"Steel.Memory.tot_action_with_frame_except",
"Steel.Memory.hmem_with_inv_except",
"Steel.Memory.star",
"Prims.unit",
"FStar.NMSTTotal.put",
"Steel.Memory.full_mem",
"Steel.Memory.mem_evolves",
"Prims._assert",
"Steel.Memory.interp",
"Steel.Memory.locks_invariant",
"Steel.Memory.ac_reasoning_for_m_frame_preserving",
"Prims.dtuple2",
"Steel.Memory.inames_ok",
"FStar.NMSTTotal.get",
"Steel.Memory.mem",
"Prims.l_True",
"Prims.prop"
] | [] | false | true | false | false | false | let lift_tot_action_with_frame
#a
#e
#fp
#fp'
($f: tot_action_with_frame_except e fp a fp')
(frame: slprop)
: MstTot a e fp fp' frame (fun _ -> True) (fun _ _ _ -> True) =
| let m0 = NMSTTotal.get () in
assert (inames_ok e m0);
ac_reasoning_for_m_frame_preserving fp frame (locks_invariant e m0) m0;
assert (interp ((fp `star` frame) `star` (locks_invariant e m0)) m0);
assert (interp (fp `star` (locks_invariant e m0)) m0);
let m0':hmem_with_inv_except e fp = m0 in
let r = f frame m0' in
let (| x , m1 |) = r in
ac_reasoning_for_m_frame_preserving (fp' x) frame (locks_invariant e m1) m1;
assert (interp (((fp' x) `star` frame) `star` (locks_invariant e m1)) m1);
assert (interp ((fp' x) `star` (locks_invariant e m1)) m1);
let m1':hmem_with_inv_except e (fp' x) = m1 in
NMSTTotal.put #_ #(mem_evolves) m1;
x | false |
LowParse.Spec.Int.fst | LowParse.Spec.Int.decode_u64_le | val decode_u64_le (b: bytes{Seq.length b == 8}) : GTot U64.t | val decode_u64_le (b: bytes{Seq.length b == 8}) : GTot U64.t | let decode_u64_le
(b: bytes { Seq.length b == 8 } )
: GTot U64.t
= E.lemma_le_to_n_is_bounded b;
U64.uint_to_t (E.le_to_n b) | {
"file_name": "src/lowparse/LowParse.Spec.Int.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 29,
"end_line": 147,
"start_col": 0,
"start_line": 143
} | module LowParse.Spec.Int
open LowParse.Spec.Combinators
let decode_u8
(b: bytes { Seq.length b == 1 } )
: Tot U8.t
= Seq.index b 0
let decode_u8_injective () : Lemma
(make_total_constant_size_parser_precond 1 U8.t decode_u8)
= ()
let tot_parse_u8 =
decode_u8_injective ();
tot_make_total_constant_size_parser 1 U8.t decode_u8
let parse_u8_spec
b
=
Seq.lemma_index_slice b 0 1 0;
E.reveal_be_to_n (Seq.slice b 0 1);
E.reveal_be_to_n (Seq.slice (Seq.slice b 0 1) 0 0)
let parse_u8_spec' b = ()
let serialize_u8 =
Seq.create 1
let serialize_u8_spec x = ()
let decode_u16
(b: bytes { Seq.length b == 2 } )
: GTot U16.t
= E.lemma_be_to_n_is_bounded b;
U16.uint_to_t (E.be_to_n b)
let decode_u16_injective'
(b1: bytes { Seq.length b1 == 2 } )
(b2: bytes { Seq.length b2 == 2 } )
: Lemma
(decode_u16 b1 == decode_u16 b2 ==> Seq.equal b1 b2)
= if decode_u16 b1 = decode_u16 b2
then begin
E.lemma_be_to_n_is_bounded b1;
E.lemma_be_to_n_is_bounded b2;
assert (U32.v (U32.uint_to_t (E.be_to_n b1)) == E.be_to_n b1);
assert (U32.v (U32.uint_to_t (E.be_to_n b2)) == E.be_to_n b2);
assert (E.be_to_n b1 == E.be_to_n b2);
E.be_to_n_inj b1 b2
end else ()
let decode_u16_injective
()
: Lemma
(make_total_constant_size_parser_precond 2 U16.t decode_u16)
= Classical.forall_intro_2 decode_u16_injective'
let parse_u16 =
decode_u16_injective ();
make_total_constant_size_parser 2 U16.t decode_u16
let parse_u16_spec
b
=
E.lemma_be_to_n_is_bounded (Seq.slice b 0 2)
let serialize_u16 =
(fun (x: U16.t) -> E.n_to_be 2 (U16.v x))
let decode_u32
(b: bytes { Seq.length b == 4 } )
: GTot U32.t
= E.lemma_be_to_n_is_bounded b;
U32.uint_to_t (E.be_to_n b)
let decode_u32_injective'
(b1: bytes { Seq.length b1 == 4 } )
(b2: bytes { Seq.length b2 == 4 } )
: Lemma
(decode_u32 b1 == decode_u32 b2 ==> Seq.equal b1 b2)
= if decode_u32 b1 = decode_u32 b2
then begin
E.lemma_be_to_n_is_bounded b1;
E.lemma_be_to_n_is_bounded b2;
assert (U32.v (U32.uint_to_t (E.be_to_n b1)) == E.be_to_n b1);
assert (U32.v (U32.uint_to_t (E.be_to_n b2)) == E.be_to_n b2);
assert (E.be_to_n b1 == E.be_to_n b2);
E.be_to_n_inj b1 b2
end else ()
let decode_u32_injective () : Lemma
(make_total_constant_size_parser_precond 4 U32.t decode_u32)
= Classical.forall_intro_2 decode_u32_injective'
let parse_u32 =
decode_u32_injective ();
make_total_constant_size_parser 4 U32.t decode_u32
let parse_u32_spec
b
=
E.lemma_be_to_n_is_bounded (Seq.slice b 0 4)
let serialize_u32 =
(fun (x: U32.t) -> E.n_to_be 4 (U32.v x))
let decode_u64
(b: bytes { Seq.length b == 8 } )
: GTot U64.t
= E.lemma_be_to_n_is_bounded b;
U64.uint_to_t (E.be_to_n b)
let decode_u64_injective'
(b1: bytes { Seq.length b1 == 8 } )
(b2: bytes { Seq.length b2 == 8 } )
: Lemma
(decode_u64 b1 == decode_u64 b2 ==> Seq.equal b1 b2)
= if decode_u64 b1 = decode_u64 b2
then begin
E.lemma_be_to_n_is_bounded b1;
E.lemma_be_to_n_is_bounded b2;
assert (U64.v (U64.uint_to_t (E.be_to_n b1)) == E.be_to_n b1);
assert (U64.v (U64.uint_to_t (E.be_to_n b2)) == E.be_to_n b2);
assert (E.be_to_n b1 == E.be_to_n b2);
E.be_to_n_inj b1 b2
end else ()
let decode_u64_injective () : Lemma
(make_total_constant_size_parser_precond 8 U64.t decode_u64)
= Classical.forall_intro_2 decode_u64_injective'
let parse_u64 =
decode_u64_injective ();
make_total_constant_size_parser 8 U64.t decode_u64
let parse_u64_spec
b
= E.lemma_be_to_n_is_bounded (Seq.slice b 0 8)
let serialize_u64 =
(fun (x: U64.t) -> E.n_to_be 8 (U64.v x)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Seq.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "LowParse.Spec.Int.fst"
} | [
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.Endianness",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | b: LowParse.Bytes.bytes{FStar.Seq.Base.length b == 8} -> Prims.GTot FStar.UInt64.t | Prims.GTot | [
"sometrivial"
] | [] | [
"LowParse.Bytes.bytes",
"Prims.eq2",
"Prims.int",
"FStar.Seq.Base.length",
"LowParse.Bytes.byte",
"FStar.UInt64.uint_to_t",
"FStar.Endianness.le_to_n",
"Prims.unit",
"FStar.Endianness.lemma_le_to_n_is_bounded",
"FStar.UInt64.t"
] | [] | false | false | false | false | false | let decode_u64_le (b: bytes{Seq.length b == 8}) : GTot U64.t =
| E.lemma_le_to_n_is_bounded b;
U64.uint_to_t (E.le_to_n b) | false |
LowParse.Spec.Int.fst | LowParse.Spec.Int.parse_u64_le | val parse_u64_le: parser parse_u64_kind U64.t | val parse_u64_le: parser parse_u64_kind U64.t | let parse_u64_le =
decode_u64_le_injective ();
make_total_constant_size_parser 8 U64.t decode_u64_le | {
"file_name": "src/lowparse/LowParse.Spec.Int.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 55,
"end_line": 170,
"start_col": 0,
"start_line": 168
} | module LowParse.Spec.Int
open LowParse.Spec.Combinators
let decode_u8
(b: bytes { Seq.length b == 1 } )
: Tot U8.t
= Seq.index b 0
let decode_u8_injective () : Lemma
(make_total_constant_size_parser_precond 1 U8.t decode_u8)
= ()
let tot_parse_u8 =
decode_u8_injective ();
tot_make_total_constant_size_parser 1 U8.t decode_u8
let parse_u8_spec
b
=
Seq.lemma_index_slice b 0 1 0;
E.reveal_be_to_n (Seq.slice b 0 1);
E.reveal_be_to_n (Seq.slice (Seq.slice b 0 1) 0 0)
let parse_u8_spec' b = ()
let serialize_u8 =
Seq.create 1
let serialize_u8_spec x = ()
let decode_u16
(b: bytes { Seq.length b == 2 } )
: GTot U16.t
= E.lemma_be_to_n_is_bounded b;
U16.uint_to_t (E.be_to_n b)
let decode_u16_injective'
(b1: bytes { Seq.length b1 == 2 } )
(b2: bytes { Seq.length b2 == 2 } )
: Lemma
(decode_u16 b1 == decode_u16 b2 ==> Seq.equal b1 b2)
= if decode_u16 b1 = decode_u16 b2
then begin
E.lemma_be_to_n_is_bounded b1;
E.lemma_be_to_n_is_bounded b2;
assert (U32.v (U32.uint_to_t (E.be_to_n b1)) == E.be_to_n b1);
assert (U32.v (U32.uint_to_t (E.be_to_n b2)) == E.be_to_n b2);
assert (E.be_to_n b1 == E.be_to_n b2);
E.be_to_n_inj b1 b2
end else ()
let decode_u16_injective
()
: Lemma
(make_total_constant_size_parser_precond 2 U16.t decode_u16)
= Classical.forall_intro_2 decode_u16_injective'
let parse_u16 =
decode_u16_injective ();
make_total_constant_size_parser 2 U16.t decode_u16
let parse_u16_spec
b
=
E.lemma_be_to_n_is_bounded (Seq.slice b 0 2)
let serialize_u16 =
(fun (x: U16.t) -> E.n_to_be 2 (U16.v x))
let decode_u32
(b: bytes { Seq.length b == 4 } )
: GTot U32.t
= E.lemma_be_to_n_is_bounded b;
U32.uint_to_t (E.be_to_n b)
let decode_u32_injective'
(b1: bytes { Seq.length b1 == 4 } )
(b2: bytes { Seq.length b2 == 4 } )
: Lemma
(decode_u32 b1 == decode_u32 b2 ==> Seq.equal b1 b2)
= if decode_u32 b1 = decode_u32 b2
then begin
E.lemma_be_to_n_is_bounded b1;
E.lemma_be_to_n_is_bounded b2;
assert (U32.v (U32.uint_to_t (E.be_to_n b1)) == E.be_to_n b1);
assert (U32.v (U32.uint_to_t (E.be_to_n b2)) == E.be_to_n b2);
assert (E.be_to_n b1 == E.be_to_n b2);
E.be_to_n_inj b1 b2
end else ()
let decode_u32_injective () : Lemma
(make_total_constant_size_parser_precond 4 U32.t decode_u32)
= Classical.forall_intro_2 decode_u32_injective'
let parse_u32 =
decode_u32_injective ();
make_total_constant_size_parser 4 U32.t decode_u32
let parse_u32_spec
b
=
E.lemma_be_to_n_is_bounded (Seq.slice b 0 4)
let serialize_u32 =
(fun (x: U32.t) -> E.n_to_be 4 (U32.v x))
let decode_u64
(b: bytes { Seq.length b == 8 } )
: GTot U64.t
= E.lemma_be_to_n_is_bounded b;
U64.uint_to_t (E.be_to_n b)
let decode_u64_injective'
(b1: bytes { Seq.length b1 == 8 } )
(b2: bytes { Seq.length b2 == 8 } )
: Lemma
(decode_u64 b1 == decode_u64 b2 ==> Seq.equal b1 b2)
= if decode_u64 b1 = decode_u64 b2
then begin
E.lemma_be_to_n_is_bounded b1;
E.lemma_be_to_n_is_bounded b2;
assert (U64.v (U64.uint_to_t (E.be_to_n b1)) == E.be_to_n b1);
assert (U64.v (U64.uint_to_t (E.be_to_n b2)) == E.be_to_n b2);
assert (E.be_to_n b1 == E.be_to_n b2);
E.be_to_n_inj b1 b2
end else ()
let decode_u64_injective () : Lemma
(make_total_constant_size_parser_precond 8 U64.t decode_u64)
= Classical.forall_intro_2 decode_u64_injective'
let parse_u64 =
decode_u64_injective ();
make_total_constant_size_parser 8 U64.t decode_u64
let parse_u64_spec
b
= E.lemma_be_to_n_is_bounded (Seq.slice b 0 8)
let serialize_u64 =
(fun (x: U64.t) -> E.n_to_be 8 (U64.v x))
let decode_u64_le
(b: bytes { Seq.length b == 8 } )
: GTot U64.t
= E.lemma_le_to_n_is_bounded b;
U64.uint_to_t (E.le_to_n b)
let decode_u64_le_injective'
(b1: bytes { Seq.length b1 == 8 } )
(b2: bytes { Seq.length b2 == 8 } )
: Lemma
(decode_u64_le b1 == decode_u64_le b2 ==> Seq.equal b1 b2)
= if decode_u64_le b1 = decode_u64_le b2
then begin
E.lemma_le_to_n_is_bounded b1;
E.lemma_le_to_n_is_bounded b2;
assert (U64.v (U64.uint_to_t (E.le_to_n b1)) == E.le_to_n b1);
assert (U64.v (U64.uint_to_t (E.le_to_n b2)) == E.le_to_n b2);
assert (E.le_to_n b1 == E.le_to_n b2);
E.le_to_n_inj b1 b2
end else ()
let decode_u64_le_injective () : Lemma
(make_total_constant_size_parser_precond 8 U64.t decode_u64_le)
= Classical.forall_intro_2 decode_u64_le_injective' | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Seq.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "LowParse.Spec.Int.fst"
} | [
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.Endianness",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | LowParse.Spec.Base.parser LowParse.Spec.Int.parse_u64_kind FStar.UInt64.t | Prims.Tot | [
"total"
] | [] | [
"LowParse.Spec.Combinators.make_total_constant_size_parser",
"FStar.UInt64.t",
"LowParse.Spec.Int.decode_u64_le",
"Prims.unit",
"LowParse.Spec.Int.decode_u64_le_injective"
] | [] | false | false | false | true | false | let parse_u64_le =
| decode_u64_le_injective ();
make_total_constant_size_parser 8 U64.t decode_u64_le | false |
LowParse.Spec.Int.fst | LowParse.Spec.Int.decode_u64_injective | val decode_u64_injective: Prims.unit
-> Lemma (make_total_constant_size_parser_precond 8 U64.t decode_u64) | val decode_u64_injective: Prims.unit
-> Lemma (make_total_constant_size_parser_precond 8 U64.t decode_u64) | let decode_u64_injective () : Lemma
(make_total_constant_size_parser_precond 8 U64.t decode_u64)
= Classical.forall_intro_2 decode_u64_injective' | {
"file_name": "src/lowparse/LowParse.Spec.Int.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 48,
"end_line": 130,
"start_col": 0,
"start_line": 128
} | module LowParse.Spec.Int
open LowParse.Spec.Combinators
let decode_u8
(b: bytes { Seq.length b == 1 } )
: Tot U8.t
= Seq.index b 0
let decode_u8_injective () : Lemma
(make_total_constant_size_parser_precond 1 U8.t decode_u8)
= ()
let tot_parse_u8 =
decode_u8_injective ();
tot_make_total_constant_size_parser 1 U8.t decode_u8
let parse_u8_spec
b
=
Seq.lemma_index_slice b 0 1 0;
E.reveal_be_to_n (Seq.slice b 0 1);
E.reveal_be_to_n (Seq.slice (Seq.slice b 0 1) 0 0)
let parse_u8_spec' b = ()
let serialize_u8 =
Seq.create 1
let serialize_u8_spec x = ()
let decode_u16
(b: bytes { Seq.length b == 2 } )
: GTot U16.t
= E.lemma_be_to_n_is_bounded b;
U16.uint_to_t (E.be_to_n b)
let decode_u16_injective'
(b1: bytes { Seq.length b1 == 2 } )
(b2: bytes { Seq.length b2 == 2 } )
: Lemma
(decode_u16 b1 == decode_u16 b2 ==> Seq.equal b1 b2)
= if decode_u16 b1 = decode_u16 b2
then begin
E.lemma_be_to_n_is_bounded b1;
E.lemma_be_to_n_is_bounded b2;
assert (U32.v (U32.uint_to_t (E.be_to_n b1)) == E.be_to_n b1);
assert (U32.v (U32.uint_to_t (E.be_to_n b2)) == E.be_to_n b2);
assert (E.be_to_n b1 == E.be_to_n b2);
E.be_to_n_inj b1 b2
end else ()
let decode_u16_injective
()
: Lemma
(make_total_constant_size_parser_precond 2 U16.t decode_u16)
= Classical.forall_intro_2 decode_u16_injective'
let parse_u16 =
decode_u16_injective ();
make_total_constant_size_parser 2 U16.t decode_u16
let parse_u16_spec
b
=
E.lemma_be_to_n_is_bounded (Seq.slice b 0 2)
let serialize_u16 =
(fun (x: U16.t) -> E.n_to_be 2 (U16.v x))
let decode_u32
(b: bytes { Seq.length b == 4 } )
: GTot U32.t
= E.lemma_be_to_n_is_bounded b;
U32.uint_to_t (E.be_to_n b)
let decode_u32_injective'
(b1: bytes { Seq.length b1 == 4 } )
(b2: bytes { Seq.length b2 == 4 } )
: Lemma
(decode_u32 b1 == decode_u32 b2 ==> Seq.equal b1 b2)
= if decode_u32 b1 = decode_u32 b2
then begin
E.lemma_be_to_n_is_bounded b1;
E.lemma_be_to_n_is_bounded b2;
assert (U32.v (U32.uint_to_t (E.be_to_n b1)) == E.be_to_n b1);
assert (U32.v (U32.uint_to_t (E.be_to_n b2)) == E.be_to_n b2);
assert (E.be_to_n b1 == E.be_to_n b2);
E.be_to_n_inj b1 b2
end else ()
let decode_u32_injective () : Lemma
(make_total_constant_size_parser_precond 4 U32.t decode_u32)
= Classical.forall_intro_2 decode_u32_injective'
let parse_u32 =
decode_u32_injective ();
make_total_constant_size_parser 4 U32.t decode_u32
let parse_u32_spec
b
=
E.lemma_be_to_n_is_bounded (Seq.slice b 0 4)
let serialize_u32 =
(fun (x: U32.t) -> E.n_to_be 4 (U32.v x))
let decode_u64
(b: bytes { Seq.length b == 8 } )
: GTot U64.t
= E.lemma_be_to_n_is_bounded b;
U64.uint_to_t (E.be_to_n b)
let decode_u64_injective'
(b1: bytes { Seq.length b1 == 8 } )
(b2: bytes { Seq.length b2 == 8 } )
: Lemma
(decode_u64 b1 == decode_u64 b2 ==> Seq.equal b1 b2)
= if decode_u64 b1 = decode_u64 b2
then begin
E.lemma_be_to_n_is_bounded b1;
E.lemma_be_to_n_is_bounded b2;
assert (U64.v (U64.uint_to_t (E.be_to_n b1)) == E.be_to_n b1);
assert (U64.v (U64.uint_to_t (E.be_to_n b2)) == E.be_to_n b2);
assert (E.be_to_n b1 == E.be_to_n b2);
E.be_to_n_inj b1 b2
end else () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Seq.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "LowParse.Spec.Int.fst"
} | [
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.Endianness",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit
-> FStar.Pervasives.Lemma
(ensures
LowParse.Spec.Combinators.make_total_constant_size_parser_precond 8
FStar.UInt64.t
LowParse.Spec.Int.decode_u64) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.unit",
"FStar.Classical.forall_intro_2",
"LowParse.Bytes.bytes",
"Prims.eq2",
"Prims.int",
"FStar.Seq.Base.length",
"LowParse.Bytes.byte",
"Prims.l_imp",
"FStar.UInt64.t",
"LowParse.Spec.Int.decode_u64",
"FStar.Seq.Base.equal",
"LowParse.Spec.Int.decode_u64_injective'",
"Prims.l_True",
"Prims.squash",
"LowParse.Spec.Combinators.make_total_constant_size_parser_precond",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let decode_u64_injective () : Lemma (make_total_constant_size_parser_precond 8 U64.t decode_u64) =
| Classical.forall_intro_2 decode_u64_injective' | false |
LowParse.Spec.Int.fst | LowParse.Spec.Int.parse_u64_spec | val parse_u64_spec
(b: bytes)
: Lemma
(requires (Seq.length b >= 8))
(ensures (
let pp = parse parse_u64 b in
Some? pp /\ (
let (Some (v, consumed)) = pp in
U64.v v == E.be_to_n (Seq.slice b 0 8)
))) | val parse_u64_spec
(b: bytes)
: Lemma
(requires (Seq.length b >= 8))
(ensures (
let pp = parse parse_u64 b in
Some? pp /\ (
let (Some (v, consumed)) = pp in
U64.v v == E.be_to_n (Seq.slice b 0 8)
))) | let parse_u64_spec
b
= E.lemma_be_to_n_is_bounded (Seq.slice b 0 8) | {
"file_name": "src/lowparse/LowParse.Spec.Int.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 46,
"end_line": 138,
"start_col": 0,
"start_line": 136
} | module LowParse.Spec.Int
open LowParse.Spec.Combinators
let decode_u8
(b: bytes { Seq.length b == 1 } )
: Tot U8.t
= Seq.index b 0
let decode_u8_injective () : Lemma
(make_total_constant_size_parser_precond 1 U8.t decode_u8)
= ()
let tot_parse_u8 =
decode_u8_injective ();
tot_make_total_constant_size_parser 1 U8.t decode_u8
let parse_u8_spec
b
=
Seq.lemma_index_slice b 0 1 0;
E.reveal_be_to_n (Seq.slice b 0 1);
E.reveal_be_to_n (Seq.slice (Seq.slice b 0 1) 0 0)
let parse_u8_spec' b = ()
let serialize_u8 =
Seq.create 1
let serialize_u8_spec x = ()
let decode_u16
(b: bytes { Seq.length b == 2 } )
: GTot U16.t
= E.lemma_be_to_n_is_bounded b;
U16.uint_to_t (E.be_to_n b)
let decode_u16_injective'
(b1: bytes { Seq.length b1 == 2 } )
(b2: bytes { Seq.length b2 == 2 } )
: Lemma
(decode_u16 b1 == decode_u16 b2 ==> Seq.equal b1 b2)
= if decode_u16 b1 = decode_u16 b2
then begin
E.lemma_be_to_n_is_bounded b1;
E.lemma_be_to_n_is_bounded b2;
assert (U32.v (U32.uint_to_t (E.be_to_n b1)) == E.be_to_n b1);
assert (U32.v (U32.uint_to_t (E.be_to_n b2)) == E.be_to_n b2);
assert (E.be_to_n b1 == E.be_to_n b2);
E.be_to_n_inj b1 b2
end else ()
let decode_u16_injective
()
: Lemma
(make_total_constant_size_parser_precond 2 U16.t decode_u16)
= Classical.forall_intro_2 decode_u16_injective'
let parse_u16 =
decode_u16_injective ();
make_total_constant_size_parser 2 U16.t decode_u16
let parse_u16_spec
b
=
E.lemma_be_to_n_is_bounded (Seq.slice b 0 2)
let serialize_u16 =
(fun (x: U16.t) -> E.n_to_be 2 (U16.v x))
let decode_u32
(b: bytes { Seq.length b == 4 } )
: GTot U32.t
= E.lemma_be_to_n_is_bounded b;
U32.uint_to_t (E.be_to_n b)
let decode_u32_injective'
(b1: bytes { Seq.length b1 == 4 } )
(b2: bytes { Seq.length b2 == 4 } )
: Lemma
(decode_u32 b1 == decode_u32 b2 ==> Seq.equal b1 b2)
= if decode_u32 b1 = decode_u32 b2
then begin
E.lemma_be_to_n_is_bounded b1;
E.lemma_be_to_n_is_bounded b2;
assert (U32.v (U32.uint_to_t (E.be_to_n b1)) == E.be_to_n b1);
assert (U32.v (U32.uint_to_t (E.be_to_n b2)) == E.be_to_n b2);
assert (E.be_to_n b1 == E.be_to_n b2);
E.be_to_n_inj b1 b2
end else ()
let decode_u32_injective () : Lemma
(make_total_constant_size_parser_precond 4 U32.t decode_u32)
= Classical.forall_intro_2 decode_u32_injective'
let parse_u32 =
decode_u32_injective ();
make_total_constant_size_parser 4 U32.t decode_u32
let parse_u32_spec
b
=
E.lemma_be_to_n_is_bounded (Seq.slice b 0 4)
let serialize_u32 =
(fun (x: U32.t) -> E.n_to_be 4 (U32.v x))
let decode_u64
(b: bytes { Seq.length b == 8 } )
: GTot U64.t
= E.lemma_be_to_n_is_bounded b;
U64.uint_to_t (E.be_to_n b)
let decode_u64_injective'
(b1: bytes { Seq.length b1 == 8 } )
(b2: bytes { Seq.length b2 == 8 } )
: Lemma
(decode_u64 b1 == decode_u64 b2 ==> Seq.equal b1 b2)
= if decode_u64 b1 = decode_u64 b2
then begin
E.lemma_be_to_n_is_bounded b1;
E.lemma_be_to_n_is_bounded b2;
assert (U64.v (U64.uint_to_t (E.be_to_n b1)) == E.be_to_n b1);
assert (U64.v (U64.uint_to_t (E.be_to_n b2)) == E.be_to_n b2);
assert (E.be_to_n b1 == E.be_to_n b2);
E.be_to_n_inj b1 b2
end else ()
let decode_u64_injective () : Lemma
(make_total_constant_size_parser_precond 8 U64.t decode_u64)
= Classical.forall_intro_2 decode_u64_injective'
let parse_u64 =
decode_u64_injective ();
make_total_constant_size_parser 8 U64.t decode_u64 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Seq.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "LowParse.Spec.Int.fst"
} | [
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.Endianness",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | b: LowParse.Bytes.bytes
-> FStar.Pervasives.Lemma (requires FStar.Seq.Base.length b >= 8)
(ensures
(let pp = LowParse.Spec.Base.parse LowParse.Spec.Int.parse_u64 b in
Some? pp /\
(let _ = pp in
(let FStar.Pervasives.Native.Some #_ (FStar.Pervasives.Native.Mktuple2 #_ #_ v _) = _ in
FStar.UInt64.v v == FStar.Endianness.be_to_n (FStar.Seq.Base.slice b 0 8))
<:
Prims.logical))) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"LowParse.Bytes.bytes",
"FStar.Endianness.lemma_be_to_n_is_bounded",
"FStar.Seq.Base.slice",
"LowParse.Bytes.byte",
"Prims.unit"
] | [] | true | false | true | false | false | let parse_u64_spec b =
| E.lemma_be_to_n_is_bounded (Seq.slice b 0 8) | false |
LowParse.Spec.Int.fst | LowParse.Spec.Int.serialize_u64 | val serialize_u64 : serializer parse_u64 | val serialize_u64 : serializer parse_u64 | let serialize_u64 =
(fun (x: U64.t) -> E.n_to_be 8 (U64.v x)) | {
"file_name": "src/lowparse/LowParse.Spec.Int.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 43,
"end_line": 141,
"start_col": 0,
"start_line": 140
} | module LowParse.Spec.Int
open LowParse.Spec.Combinators
let decode_u8
(b: bytes { Seq.length b == 1 } )
: Tot U8.t
= Seq.index b 0
let decode_u8_injective () : Lemma
(make_total_constant_size_parser_precond 1 U8.t decode_u8)
= ()
let tot_parse_u8 =
decode_u8_injective ();
tot_make_total_constant_size_parser 1 U8.t decode_u8
let parse_u8_spec
b
=
Seq.lemma_index_slice b 0 1 0;
E.reveal_be_to_n (Seq.slice b 0 1);
E.reveal_be_to_n (Seq.slice (Seq.slice b 0 1) 0 0)
let parse_u8_spec' b = ()
let serialize_u8 =
Seq.create 1
let serialize_u8_spec x = ()
let decode_u16
(b: bytes { Seq.length b == 2 } )
: GTot U16.t
= E.lemma_be_to_n_is_bounded b;
U16.uint_to_t (E.be_to_n b)
let decode_u16_injective'
(b1: bytes { Seq.length b1 == 2 } )
(b2: bytes { Seq.length b2 == 2 } )
: Lemma
(decode_u16 b1 == decode_u16 b2 ==> Seq.equal b1 b2)
= if decode_u16 b1 = decode_u16 b2
then begin
E.lemma_be_to_n_is_bounded b1;
E.lemma_be_to_n_is_bounded b2;
assert (U32.v (U32.uint_to_t (E.be_to_n b1)) == E.be_to_n b1);
assert (U32.v (U32.uint_to_t (E.be_to_n b2)) == E.be_to_n b2);
assert (E.be_to_n b1 == E.be_to_n b2);
E.be_to_n_inj b1 b2
end else ()
let decode_u16_injective
()
: Lemma
(make_total_constant_size_parser_precond 2 U16.t decode_u16)
= Classical.forall_intro_2 decode_u16_injective'
let parse_u16 =
decode_u16_injective ();
make_total_constant_size_parser 2 U16.t decode_u16
let parse_u16_spec
b
=
E.lemma_be_to_n_is_bounded (Seq.slice b 0 2)
let serialize_u16 =
(fun (x: U16.t) -> E.n_to_be 2 (U16.v x))
let decode_u32
(b: bytes { Seq.length b == 4 } )
: GTot U32.t
= E.lemma_be_to_n_is_bounded b;
U32.uint_to_t (E.be_to_n b)
let decode_u32_injective'
(b1: bytes { Seq.length b1 == 4 } )
(b2: bytes { Seq.length b2 == 4 } )
: Lemma
(decode_u32 b1 == decode_u32 b2 ==> Seq.equal b1 b2)
= if decode_u32 b1 = decode_u32 b2
then begin
E.lemma_be_to_n_is_bounded b1;
E.lemma_be_to_n_is_bounded b2;
assert (U32.v (U32.uint_to_t (E.be_to_n b1)) == E.be_to_n b1);
assert (U32.v (U32.uint_to_t (E.be_to_n b2)) == E.be_to_n b2);
assert (E.be_to_n b1 == E.be_to_n b2);
E.be_to_n_inj b1 b2
end else ()
let decode_u32_injective () : Lemma
(make_total_constant_size_parser_precond 4 U32.t decode_u32)
= Classical.forall_intro_2 decode_u32_injective'
let parse_u32 =
decode_u32_injective ();
make_total_constant_size_parser 4 U32.t decode_u32
let parse_u32_spec
b
=
E.lemma_be_to_n_is_bounded (Seq.slice b 0 4)
let serialize_u32 =
(fun (x: U32.t) -> E.n_to_be 4 (U32.v x))
let decode_u64
(b: bytes { Seq.length b == 8 } )
: GTot U64.t
= E.lemma_be_to_n_is_bounded b;
U64.uint_to_t (E.be_to_n b)
let decode_u64_injective'
(b1: bytes { Seq.length b1 == 8 } )
(b2: bytes { Seq.length b2 == 8 } )
: Lemma
(decode_u64 b1 == decode_u64 b2 ==> Seq.equal b1 b2)
= if decode_u64 b1 = decode_u64 b2
then begin
E.lemma_be_to_n_is_bounded b1;
E.lemma_be_to_n_is_bounded b2;
assert (U64.v (U64.uint_to_t (E.be_to_n b1)) == E.be_to_n b1);
assert (U64.v (U64.uint_to_t (E.be_to_n b2)) == E.be_to_n b2);
assert (E.be_to_n b1 == E.be_to_n b2);
E.be_to_n_inj b1 b2
end else ()
let decode_u64_injective () : Lemma
(make_total_constant_size_parser_precond 8 U64.t decode_u64)
= Classical.forall_intro_2 decode_u64_injective'
let parse_u64 =
decode_u64_injective ();
make_total_constant_size_parser 8 U64.t decode_u64
let parse_u64_spec
b
= E.lemma_be_to_n_is_bounded (Seq.slice b 0 8) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Seq.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "LowParse.Spec.Int.fst"
} | [
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.Endianness",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | LowParse.Spec.Base.serializer LowParse.Spec.Int.parse_u64 | Prims.Tot | [
"total"
] | [] | [
"FStar.UInt64.t",
"FStar.Endianness.n_to_be",
"FStar.UInt64.v",
"FStar.Endianness.bytes",
"Prims.l_and",
"Prims.eq2",
"Prims.nat",
"FStar.Seq.Base.length",
"FStar.UInt8.t",
"FStar.Endianness.be_to_n"
] | [] | false | false | false | true | false | let serialize_u64 =
| (fun (x: U64.t) -> E.n_to_be 8 (U64.v x)) | false |
Vale.X64.Memory_Sems.fst | Vale.X64.Memory_Sems.same_domain | val same_domain (h:vale_heap) (m:S.machine_heap) : prop0 | val same_domain (h:vale_heap) (m:S.machine_heap) : prop0 | let same_domain h m = Set.equal (IB.addrs_set (_ih h)) (Map.domain m) | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory_Sems.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 69,
"end_line": 21,
"start_col": 0,
"start_line": 21
} | module Vale.X64.Memory_Sems
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.Def.Words_s
module I = Vale.Interop
module S = Vale.X64.Machine_Semantics_s
module MB = LowStar.Monotonic.Buffer
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
friend Vale.X64.Memory
module IB = Vale.Interop.Base | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Memory.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.BufferViewStore.fsti.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Memory_Sems.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | h: Vale.Arch.HeapImpl.vale_heap -> m: Vale.Arch.MachineHeap_s.machine_heap -> Vale.Def.Prop_s.prop0 | Prims.Tot | [
"total"
] | [] | [
"Vale.Arch.HeapImpl.vale_heap",
"Vale.Arch.MachineHeap_s.machine_heap",
"FStar.Set.equal",
"Prims.int",
"Vale.Interop.Heap_s.addrs_set",
"Vale.Arch.HeapImpl._ih",
"FStar.Map.domain",
"Vale.Def.Types_s.nat8",
"Vale.Def.Prop_s.prop0"
] | [] | false | false | false | true | false | let same_domain h m =
| Set.equal (IB.addrs_set (_ih h)) (Map.domain m) | false |
LowParse.Spec.Int.fst | LowParse.Spec.Int.decode_u64_le_injective | val decode_u64_le_injective: Prims.unit
-> Lemma (make_total_constant_size_parser_precond 8 U64.t decode_u64_le) | val decode_u64_le_injective: Prims.unit
-> Lemma (make_total_constant_size_parser_precond 8 U64.t decode_u64_le) | let decode_u64_le_injective () : Lemma
(make_total_constant_size_parser_precond 8 U64.t decode_u64_le)
= Classical.forall_intro_2 decode_u64_le_injective' | {
"file_name": "src/lowparse/LowParse.Spec.Int.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 51,
"end_line": 166,
"start_col": 0,
"start_line": 164
} | module LowParse.Spec.Int
open LowParse.Spec.Combinators
let decode_u8
(b: bytes { Seq.length b == 1 } )
: Tot U8.t
= Seq.index b 0
let decode_u8_injective () : Lemma
(make_total_constant_size_parser_precond 1 U8.t decode_u8)
= ()
let tot_parse_u8 =
decode_u8_injective ();
tot_make_total_constant_size_parser 1 U8.t decode_u8
let parse_u8_spec
b
=
Seq.lemma_index_slice b 0 1 0;
E.reveal_be_to_n (Seq.slice b 0 1);
E.reveal_be_to_n (Seq.slice (Seq.slice b 0 1) 0 0)
let parse_u8_spec' b = ()
let serialize_u8 =
Seq.create 1
let serialize_u8_spec x = ()
let decode_u16
(b: bytes { Seq.length b == 2 } )
: GTot U16.t
= E.lemma_be_to_n_is_bounded b;
U16.uint_to_t (E.be_to_n b)
let decode_u16_injective'
(b1: bytes { Seq.length b1 == 2 } )
(b2: bytes { Seq.length b2 == 2 } )
: Lemma
(decode_u16 b1 == decode_u16 b2 ==> Seq.equal b1 b2)
= if decode_u16 b1 = decode_u16 b2
then begin
E.lemma_be_to_n_is_bounded b1;
E.lemma_be_to_n_is_bounded b2;
assert (U32.v (U32.uint_to_t (E.be_to_n b1)) == E.be_to_n b1);
assert (U32.v (U32.uint_to_t (E.be_to_n b2)) == E.be_to_n b2);
assert (E.be_to_n b1 == E.be_to_n b2);
E.be_to_n_inj b1 b2
end else ()
let decode_u16_injective
()
: Lemma
(make_total_constant_size_parser_precond 2 U16.t decode_u16)
= Classical.forall_intro_2 decode_u16_injective'
let parse_u16 =
decode_u16_injective ();
make_total_constant_size_parser 2 U16.t decode_u16
let parse_u16_spec
b
=
E.lemma_be_to_n_is_bounded (Seq.slice b 0 2)
let serialize_u16 =
(fun (x: U16.t) -> E.n_to_be 2 (U16.v x))
let decode_u32
(b: bytes { Seq.length b == 4 } )
: GTot U32.t
= E.lemma_be_to_n_is_bounded b;
U32.uint_to_t (E.be_to_n b)
let decode_u32_injective'
(b1: bytes { Seq.length b1 == 4 } )
(b2: bytes { Seq.length b2 == 4 } )
: Lemma
(decode_u32 b1 == decode_u32 b2 ==> Seq.equal b1 b2)
= if decode_u32 b1 = decode_u32 b2
then begin
E.lemma_be_to_n_is_bounded b1;
E.lemma_be_to_n_is_bounded b2;
assert (U32.v (U32.uint_to_t (E.be_to_n b1)) == E.be_to_n b1);
assert (U32.v (U32.uint_to_t (E.be_to_n b2)) == E.be_to_n b2);
assert (E.be_to_n b1 == E.be_to_n b2);
E.be_to_n_inj b1 b2
end else ()
let decode_u32_injective () : Lemma
(make_total_constant_size_parser_precond 4 U32.t decode_u32)
= Classical.forall_intro_2 decode_u32_injective'
let parse_u32 =
decode_u32_injective ();
make_total_constant_size_parser 4 U32.t decode_u32
let parse_u32_spec
b
=
E.lemma_be_to_n_is_bounded (Seq.slice b 0 4)
let serialize_u32 =
(fun (x: U32.t) -> E.n_to_be 4 (U32.v x))
let decode_u64
(b: bytes { Seq.length b == 8 } )
: GTot U64.t
= E.lemma_be_to_n_is_bounded b;
U64.uint_to_t (E.be_to_n b)
let decode_u64_injective'
(b1: bytes { Seq.length b1 == 8 } )
(b2: bytes { Seq.length b2 == 8 } )
: Lemma
(decode_u64 b1 == decode_u64 b2 ==> Seq.equal b1 b2)
= if decode_u64 b1 = decode_u64 b2
then begin
E.lemma_be_to_n_is_bounded b1;
E.lemma_be_to_n_is_bounded b2;
assert (U64.v (U64.uint_to_t (E.be_to_n b1)) == E.be_to_n b1);
assert (U64.v (U64.uint_to_t (E.be_to_n b2)) == E.be_to_n b2);
assert (E.be_to_n b1 == E.be_to_n b2);
E.be_to_n_inj b1 b2
end else ()
let decode_u64_injective () : Lemma
(make_total_constant_size_parser_precond 8 U64.t decode_u64)
= Classical.forall_intro_2 decode_u64_injective'
let parse_u64 =
decode_u64_injective ();
make_total_constant_size_parser 8 U64.t decode_u64
let parse_u64_spec
b
= E.lemma_be_to_n_is_bounded (Seq.slice b 0 8)
let serialize_u64 =
(fun (x: U64.t) -> E.n_to_be 8 (U64.v x))
let decode_u64_le
(b: bytes { Seq.length b == 8 } )
: GTot U64.t
= E.lemma_le_to_n_is_bounded b;
U64.uint_to_t (E.le_to_n b)
let decode_u64_le_injective'
(b1: bytes { Seq.length b1 == 8 } )
(b2: bytes { Seq.length b2 == 8 } )
: Lemma
(decode_u64_le b1 == decode_u64_le b2 ==> Seq.equal b1 b2)
= if decode_u64_le b1 = decode_u64_le b2
then begin
E.lemma_le_to_n_is_bounded b1;
E.lemma_le_to_n_is_bounded b2;
assert (U64.v (U64.uint_to_t (E.le_to_n b1)) == E.le_to_n b1);
assert (U64.v (U64.uint_to_t (E.le_to_n b2)) == E.le_to_n b2);
assert (E.le_to_n b1 == E.le_to_n b2);
E.le_to_n_inj b1 b2
end else () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Seq.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "LowParse.Spec.Int.fst"
} | [
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.Endianness",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit
-> FStar.Pervasives.Lemma
(ensures
LowParse.Spec.Combinators.make_total_constant_size_parser_precond 8
FStar.UInt64.t
LowParse.Spec.Int.decode_u64_le) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.unit",
"FStar.Classical.forall_intro_2",
"LowParse.Bytes.bytes",
"Prims.eq2",
"Prims.int",
"FStar.Seq.Base.length",
"LowParse.Bytes.byte",
"Prims.l_imp",
"FStar.UInt64.t",
"LowParse.Spec.Int.decode_u64_le",
"FStar.Seq.Base.equal",
"LowParse.Spec.Int.decode_u64_le_injective'",
"Prims.l_True",
"Prims.squash",
"LowParse.Spec.Combinators.make_total_constant_size_parser_precond",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let decode_u64_le_injective ()
: Lemma (make_total_constant_size_parser_precond 8 U64.t decode_u64_le) =
| Classical.forall_intro_2 decode_u64_le_injective' | false |
LowParse.Spec.Int.fst | LowParse.Spec.Int.parse_u64_le_spec | val parse_u64_le_spec
(b: bytes)
: Lemma
(requires (Seq.length b >= 8))
(ensures (
let pp = parse parse_u64_le b in
Some? pp /\ (
let (Some (v, consumed)) = pp in
U64.v v == E.le_to_n (Seq.slice b 0 8)
))) | val parse_u64_le_spec
(b: bytes)
: Lemma
(requires (Seq.length b >= 8))
(ensures (
let pp = parse parse_u64_le b in
Some? pp /\ (
let (Some (v, consumed)) = pp in
U64.v v == E.le_to_n (Seq.slice b 0 8)
))) | let parse_u64_le_spec
b
= E.lemma_le_to_n_is_bounded (Seq.slice b 0 8) | {
"file_name": "src/lowparse/LowParse.Spec.Int.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 46,
"end_line": 174,
"start_col": 0,
"start_line": 172
} | module LowParse.Spec.Int
open LowParse.Spec.Combinators
let decode_u8
(b: bytes { Seq.length b == 1 } )
: Tot U8.t
= Seq.index b 0
let decode_u8_injective () : Lemma
(make_total_constant_size_parser_precond 1 U8.t decode_u8)
= ()
let tot_parse_u8 =
decode_u8_injective ();
tot_make_total_constant_size_parser 1 U8.t decode_u8
let parse_u8_spec
b
=
Seq.lemma_index_slice b 0 1 0;
E.reveal_be_to_n (Seq.slice b 0 1);
E.reveal_be_to_n (Seq.slice (Seq.slice b 0 1) 0 0)
let parse_u8_spec' b = ()
let serialize_u8 =
Seq.create 1
let serialize_u8_spec x = ()
let decode_u16
(b: bytes { Seq.length b == 2 } )
: GTot U16.t
= E.lemma_be_to_n_is_bounded b;
U16.uint_to_t (E.be_to_n b)
let decode_u16_injective'
(b1: bytes { Seq.length b1 == 2 } )
(b2: bytes { Seq.length b2 == 2 } )
: Lemma
(decode_u16 b1 == decode_u16 b2 ==> Seq.equal b1 b2)
= if decode_u16 b1 = decode_u16 b2
then begin
E.lemma_be_to_n_is_bounded b1;
E.lemma_be_to_n_is_bounded b2;
assert (U32.v (U32.uint_to_t (E.be_to_n b1)) == E.be_to_n b1);
assert (U32.v (U32.uint_to_t (E.be_to_n b2)) == E.be_to_n b2);
assert (E.be_to_n b1 == E.be_to_n b2);
E.be_to_n_inj b1 b2
end else ()
let decode_u16_injective
()
: Lemma
(make_total_constant_size_parser_precond 2 U16.t decode_u16)
= Classical.forall_intro_2 decode_u16_injective'
let parse_u16 =
decode_u16_injective ();
make_total_constant_size_parser 2 U16.t decode_u16
let parse_u16_spec
b
=
E.lemma_be_to_n_is_bounded (Seq.slice b 0 2)
let serialize_u16 =
(fun (x: U16.t) -> E.n_to_be 2 (U16.v x))
let decode_u32
(b: bytes { Seq.length b == 4 } )
: GTot U32.t
= E.lemma_be_to_n_is_bounded b;
U32.uint_to_t (E.be_to_n b)
let decode_u32_injective'
(b1: bytes { Seq.length b1 == 4 } )
(b2: bytes { Seq.length b2 == 4 } )
: Lemma
(decode_u32 b1 == decode_u32 b2 ==> Seq.equal b1 b2)
= if decode_u32 b1 = decode_u32 b2
then begin
E.lemma_be_to_n_is_bounded b1;
E.lemma_be_to_n_is_bounded b2;
assert (U32.v (U32.uint_to_t (E.be_to_n b1)) == E.be_to_n b1);
assert (U32.v (U32.uint_to_t (E.be_to_n b2)) == E.be_to_n b2);
assert (E.be_to_n b1 == E.be_to_n b2);
E.be_to_n_inj b1 b2
end else ()
let decode_u32_injective () : Lemma
(make_total_constant_size_parser_precond 4 U32.t decode_u32)
= Classical.forall_intro_2 decode_u32_injective'
let parse_u32 =
decode_u32_injective ();
make_total_constant_size_parser 4 U32.t decode_u32
let parse_u32_spec
b
=
E.lemma_be_to_n_is_bounded (Seq.slice b 0 4)
let serialize_u32 =
(fun (x: U32.t) -> E.n_to_be 4 (U32.v x))
let decode_u64
(b: bytes { Seq.length b == 8 } )
: GTot U64.t
= E.lemma_be_to_n_is_bounded b;
U64.uint_to_t (E.be_to_n b)
let decode_u64_injective'
(b1: bytes { Seq.length b1 == 8 } )
(b2: bytes { Seq.length b2 == 8 } )
: Lemma
(decode_u64 b1 == decode_u64 b2 ==> Seq.equal b1 b2)
= if decode_u64 b1 = decode_u64 b2
then begin
E.lemma_be_to_n_is_bounded b1;
E.lemma_be_to_n_is_bounded b2;
assert (U64.v (U64.uint_to_t (E.be_to_n b1)) == E.be_to_n b1);
assert (U64.v (U64.uint_to_t (E.be_to_n b2)) == E.be_to_n b2);
assert (E.be_to_n b1 == E.be_to_n b2);
E.be_to_n_inj b1 b2
end else ()
let decode_u64_injective () : Lemma
(make_total_constant_size_parser_precond 8 U64.t decode_u64)
= Classical.forall_intro_2 decode_u64_injective'
let parse_u64 =
decode_u64_injective ();
make_total_constant_size_parser 8 U64.t decode_u64
let parse_u64_spec
b
= E.lemma_be_to_n_is_bounded (Seq.slice b 0 8)
let serialize_u64 =
(fun (x: U64.t) -> E.n_to_be 8 (U64.v x))
let decode_u64_le
(b: bytes { Seq.length b == 8 } )
: GTot U64.t
= E.lemma_le_to_n_is_bounded b;
U64.uint_to_t (E.le_to_n b)
let decode_u64_le_injective'
(b1: bytes { Seq.length b1 == 8 } )
(b2: bytes { Seq.length b2 == 8 } )
: Lemma
(decode_u64_le b1 == decode_u64_le b2 ==> Seq.equal b1 b2)
= if decode_u64_le b1 = decode_u64_le b2
then begin
E.lemma_le_to_n_is_bounded b1;
E.lemma_le_to_n_is_bounded b2;
assert (U64.v (U64.uint_to_t (E.le_to_n b1)) == E.le_to_n b1);
assert (U64.v (U64.uint_to_t (E.le_to_n b2)) == E.le_to_n b2);
assert (E.le_to_n b1 == E.le_to_n b2);
E.le_to_n_inj b1 b2
end else ()
let decode_u64_le_injective () : Lemma
(make_total_constant_size_parser_precond 8 U64.t decode_u64_le)
= Classical.forall_intro_2 decode_u64_le_injective'
let parse_u64_le =
decode_u64_le_injective ();
make_total_constant_size_parser 8 U64.t decode_u64_le | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Seq.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "LowParse.Spec.Int.fst"
} | [
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.Endianness",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | b: LowParse.Bytes.bytes
-> FStar.Pervasives.Lemma (requires FStar.Seq.Base.length b >= 8)
(ensures
(let pp = LowParse.Spec.Base.parse LowParse.Spec.Int.parse_u64_le b in
Some? pp /\
(let _ = pp in
(let FStar.Pervasives.Native.Some #_ (FStar.Pervasives.Native.Mktuple2 #_ #_ v _) = _ in
FStar.UInt64.v v == FStar.Endianness.le_to_n (FStar.Seq.Base.slice b 0 8))
<:
Prims.logical))) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"LowParse.Bytes.bytes",
"FStar.Endianness.lemma_le_to_n_is_bounded",
"FStar.Seq.Base.slice",
"LowParse.Bytes.byte",
"Prims.unit"
] | [] | true | false | true | false | false | let parse_u64_le_spec b =
| E.lemma_le_to_n_is_bounded (Seq.slice b 0 8) | false |
LowParse.Spec.Int.fst | LowParse.Spec.Int.serialize_u64_le | val serialize_u64_le : serializer parse_u64_le | val serialize_u64_le : serializer parse_u64_le | let serialize_u64_le =
(fun (x: U64.t) -> E.n_to_le 8 (U64.v x)) | {
"file_name": "src/lowparse/LowParse.Spec.Int.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 43,
"end_line": 177,
"start_col": 0,
"start_line": 176
} | module LowParse.Spec.Int
open LowParse.Spec.Combinators
let decode_u8
(b: bytes { Seq.length b == 1 } )
: Tot U8.t
= Seq.index b 0
let decode_u8_injective () : Lemma
(make_total_constant_size_parser_precond 1 U8.t decode_u8)
= ()
let tot_parse_u8 =
decode_u8_injective ();
tot_make_total_constant_size_parser 1 U8.t decode_u8
let parse_u8_spec
b
=
Seq.lemma_index_slice b 0 1 0;
E.reveal_be_to_n (Seq.slice b 0 1);
E.reveal_be_to_n (Seq.slice (Seq.slice b 0 1) 0 0)
let parse_u8_spec' b = ()
let serialize_u8 =
Seq.create 1
let serialize_u8_spec x = ()
let decode_u16
(b: bytes { Seq.length b == 2 } )
: GTot U16.t
= E.lemma_be_to_n_is_bounded b;
U16.uint_to_t (E.be_to_n b)
let decode_u16_injective'
(b1: bytes { Seq.length b1 == 2 } )
(b2: bytes { Seq.length b2 == 2 } )
: Lemma
(decode_u16 b1 == decode_u16 b2 ==> Seq.equal b1 b2)
= if decode_u16 b1 = decode_u16 b2
then begin
E.lemma_be_to_n_is_bounded b1;
E.lemma_be_to_n_is_bounded b2;
assert (U32.v (U32.uint_to_t (E.be_to_n b1)) == E.be_to_n b1);
assert (U32.v (U32.uint_to_t (E.be_to_n b2)) == E.be_to_n b2);
assert (E.be_to_n b1 == E.be_to_n b2);
E.be_to_n_inj b1 b2
end else ()
let decode_u16_injective
()
: Lemma
(make_total_constant_size_parser_precond 2 U16.t decode_u16)
= Classical.forall_intro_2 decode_u16_injective'
let parse_u16 =
decode_u16_injective ();
make_total_constant_size_parser 2 U16.t decode_u16
let parse_u16_spec
b
=
E.lemma_be_to_n_is_bounded (Seq.slice b 0 2)
let serialize_u16 =
(fun (x: U16.t) -> E.n_to_be 2 (U16.v x))
let decode_u32
(b: bytes { Seq.length b == 4 } )
: GTot U32.t
= E.lemma_be_to_n_is_bounded b;
U32.uint_to_t (E.be_to_n b)
let decode_u32_injective'
(b1: bytes { Seq.length b1 == 4 } )
(b2: bytes { Seq.length b2 == 4 } )
: Lemma
(decode_u32 b1 == decode_u32 b2 ==> Seq.equal b1 b2)
= if decode_u32 b1 = decode_u32 b2
then begin
E.lemma_be_to_n_is_bounded b1;
E.lemma_be_to_n_is_bounded b2;
assert (U32.v (U32.uint_to_t (E.be_to_n b1)) == E.be_to_n b1);
assert (U32.v (U32.uint_to_t (E.be_to_n b2)) == E.be_to_n b2);
assert (E.be_to_n b1 == E.be_to_n b2);
E.be_to_n_inj b1 b2
end else ()
let decode_u32_injective () : Lemma
(make_total_constant_size_parser_precond 4 U32.t decode_u32)
= Classical.forall_intro_2 decode_u32_injective'
let parse_u32 =
decode_u32_injective ();
make_total_constant_size_parser 4 U32.t decode_u32
let parse_u32_spec
b
=
E.lemma_be_to_n_is_bounded (Seq.slice b 0 4)
let serialize_u32 =
(fun (x: U32.t) -> E.n_to_be 4 (U32.v x))
let decode_u64
(b: bytes { Seq.length b == 8 } )
: GTot U64.t
= E.lemma_be_to_n_is_bounded b;
U64.uint_to_t (E.be_to_n b)
let decode_u64_injective'
(b1: bytes { Seq.length b1 == 8 } )
(b2: bytes { Seq.length b2 == 8 } )
: Lemma
(decode_u64 b1 == decode_u64 b2 ==> Seq.equal b1 b2)
= if decode_u64 b1 = decode_u64 b2
then begin
E.lemma_be_to_n_is_bounded b1;
E.lemma_be_to_n_is_bounded b2;
assert (U64.v (U64.uint_to_t (E.be_to_n b1)) == E.be_to_n b1);
assert (U64.v (U64.uint_to_t (E.be_to_n b2)) == E.be_to_n b2);
assert (E.be_to_n b1 == E.be_to_n b2);
E.be_to_n_inj b1 b2
end else ()
let decode_u64_injective () : Lemma
(make_total_constant_size_parser_precond 8 U64.t decode_u64)
= Classical.forall_intro_2 decode_u64_injective'
let parse_u64 =
decode_u64_injective ();
make_total_constant_size_parser 8 U64.t decode_u64
let parse_u64_spec
b
= E.lemma_be_to_n_is_bounded (Seq.slice b 0 8)
let serialize_u64 =
(fun (x: U64.t) -> E.n_to_be 8 (U64.v x))
let decode_u64_le
(b: bytes { Seq.length b == 8 } )
: GTot U64.t
= E.lemma_le_to_n_is_bounded b;
U64.uint_to_t (E.le_to_n b)
let decode_u64_le_injective'
(b1: bytes { Seq.length b1 == 8 } )
(b2: bytes { Seq.length b2 == 8 } )
: Lemma
(decode_u64_le b1 == decode_u64_le b2 ==> Seq.equal b1 b2)
= if decode_u64_le b1 = decode_u64_le b2
then begin
E.lemma_le_to_n_is_bounded b1;
E.lemma_le_to_n_is_bounded b2;
assert (U64.v (U64.uint_to_t (E.le_to_n b1)) == E.le_to_n b1);
assert (U64.v (U64.uint_to_t (E.le_to_n b2)) == E.le_to_n b2);
assert (E.le_to_n b1 == E.le_to_n b2);
E.le_to_n_inj b1 b2
end else ()
let decode_u64_le_injective () : Lemma
(make_total_constant_size_parser_precond 8 U64.t decode_u64_le)
= Classical.forall_intro_2 decode_u64_le_injective'
let parse_u64_le =
decode_u64_le_injective ();
make_total_constant_size_parser 8 U64.t decode_u64_le
let parse_u64_le_spec
b
= E.lemma_le_to_n_is_bounded (Seq.slice b 0 8) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Seq.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "LowParse.Spec.Int.fst"
} | [
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.Endianness",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | LowParse.Spec.Base.serializer LowParse.Spec.Int.parse_u64_le | Prims.Tot | [
"total"
] | [] | [
"FStar.UInt64.t",
"FStar.Endianness.n_to_le",
"FStar.UInt64.v",
"FStar.Endianness.bytes",
"Prims.l_and",
"Prims.eq2",
"Prims.nat",
"FStar.Seq.Base.length",
"FStar.UInt8.t",
"FStar.Endianness.le_to_n"
] | [] | false | false | false | true | false | let serialize_u64_le =
| (fun (x: U64.t) -> E.n_to_le 8 (U64.v x)) | false |
Vale.X64.Memory_Sems.fst | Vale.X64.Memory_Sems.buffer_info_has_addr | val buffer_info_has_addr : bi: Vale.Arch.HeapImpl.buffer_info -> a: Prims.int -> Prims.logical | let buffer_info_has_addr (bi:buffer_info) (a:int) =
let b = bi.bi_buffer in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
addr <= a /\ a < addr + len | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory_Sems.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 29,
"end_line": 52,
"start_col": 0,
"start_line": 48
} | module Vale.X64.Memory_Sems
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.Def.Words_s
module I = Vale.Interop
module S = Vale.X64.Machine_Semantics_s
module MB = LowStar.Monotonic.Buffer
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
friend Vale.X64.Memory
module IB = Vale.Interop.Base
let same_domain h m = Set.equal (IB.addrs_set (_ih h)) (Map.domain m)
let lemma_same_domains h m1 m2 = ()
let get_heap h = I.down_mem (_ih h)
let upd_heap h m = mi_heap_upd h m
//let lemma_upd_get_heap h = I.down_up_identity (_ih h)
let lemma_get_upd_heap h m = I.up_down_identity (_ih h) m
let lemma_heap_impl = ()
let lemma_heap_get_heap h = ()
let lemma_heap_taint h = ()
//let lemma_heap_upd_heap h mh mt = ()
[@"opaque_to_smt"]
let rec set_of_range (a:int) (n:nat) : Pure (Set.set int)
(requires True)
(ensures fun s -> (forall (i:int).{:pattern Set.mem i s} Set.mem i s <==> a <= i /\ i < a + n))
=
if n = 0 then Set.empty else Set.union (set_of_range a (n - 1)) (Set.singleton (a + n - 1)) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Memory.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.BufferViewStore.fsti.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Memory_Sems.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | bi: Vale.Arch.HeapImpl.buffer_info -> a: Prims.int -> Prims.logical | Prims.Tot | [
"total"
] | [] | [
"Vale.Arch.HeapImpl.buffer_info",
"Prims.int",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"Prims.op_Addition",
"Prims.nat",
"LowStar.BufferView.Down.length",
"FStar.UInt8.t",
"Vale.Interop.Types.get_downview",
"Vale.Interop.Types.__proj__Buffer__item__src",
"Vale.Interop.Types.b8_preorder",
"Vale.Interop.Types.__proj__Buffer__item__writeable",
"Vale.Interop.Types.base_typ_as_type",
"Vale.Interop.Types.__proj__Buffer__item__bsrc",
"Vale.Def.Words_s.nat64",
"Vale.Interop.Heap_s.global_addrs_map",
"Vale.Arch.HeapImpl.buffer",
"Vale.Arch.HeapImpl.__proj__Mkbuffer_info__item__bi_typ",
"Vale.Arch.HeapImpl.__proj__Mkbuffer_info__item__bi_buffer",
"Prims.logical"
] | [] | false | false | false | true | true | let buffer_info_has_addr (bi: buffer_info) (a: int) =
| let b = bi.bi_buffer in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
addr <= a /\ a < addr + len | false |
|
Vale.X64.Memory_Sems.fst | Vale.X64.Memory_Sems.make_owns | val make_owns (h: vale_heap) (bs: Seq.seq buffer_info) (n: nat{n <= Seq.length bs})
: GTot ((int -> option (n: nat{n < Seq.length bs})) & (heaplet_id -> Set.set int)) | val make_owns (h: vale_heap) (bs: Seq.seq buffer_info) (n: nat{n <= Seq.length bs})
: GTot ((int -> option (n: nat{n < Seq.length bs})) & (heaplet_id -> Set.set int)) | let make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
make_owns_rec h bs n | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory_Sems.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 22,
"end_line": 79,
"start_col": 0,
"start_line": 76
} | module Vale.X64.Memory_Sems
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.Def.Words_s
module I = Vale.Interop
module S = Vale.X64.Machine_Semantics_s
module MB = LowStar.Monotonic.Buffer
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
friend Vale.X64.Memory
module IB = Vale.Interop.Base
let same_domain h m = Set.equal (IB.addrs_set (_ih h)) (Map.domain m)
let lemma_same_domains h m1 m2 = ()
let get_heap h = I.down_mem (_ih h)
let upd_heap h m = mi_heap_upd h m
//let lemma_upd_get_heap h = I.down_up_identity (_ih h)
let lemma_get_upd_heap h m = I.up_down_identity (_ih h) m
let lemma_heap_impl = ()
let lemma_heap_get_heap h = ()
let lemma_heap_taint h = ()
//let lemma_heap_upd_heap h mh mt = ()
[@"opaque_to_smt"]
let rec set_of_range (a:int) (n:nat) : Pure (Set.set int)
(requires True)
(ensures fun s -> (forall (i:int).{:pattern Set.mem i s} Set.mem i s <==> a <= i /\ i < a + n))
=
if n = 0 then Set.empty else Set.union (set_of_range a (n - 1)) (Set.singleton (a + n - 1))
let buffer_info_has_addr (bi:buffer_info) (a:int) =
let b = bi.bi_buffer in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
addr <= a /\ a < addr + len
let buffer_info_has_addr_opt (bi:option buffer_info) (a:int) =
match bi with
| None -> False
| Some bi -> buffer_info_has_addr bi a
#set-options "--z3rlimit 100"
let rec make_owns_rec (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
if n = 0 then ((fun _ -> None), (fun _ -> Set.empty)) else
let (m0, s0) = make_owns_rec h bs (n - 1) in
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let s i = if i = hi then Set.union (s0 i) s_b else s0 i in
let m a = if addr <= a && a < addr + len then Some (n - 1) else m0 a in
(m, s) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Memory.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.BufferViewStore.fsti.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Memory_Sems.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_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
}
] | {
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
h: Vale.Arch.HeapImpl.vale_heap ->
bs: FStar.Seq.Base.seq Vale.Arch.HeapImpl.buffer_info ->
n: Prims.nat{n <= FStar.Seq.Base.length bs}
-> Prims.GTot
((_: Prims.int -> FStar.Pervasives.Native.option (n: Prims.nat{n < FStar.Seq.Base.length bs})) *
(_: Vale.Arch.HeapImpl.heaplet_id -> FStar.Set.set Prims.int)) | Prims.GTot | [
"sometrivial"
] | [] | [
"Vale.Arch.HeapImpl.vale_heap",
"FStar.Seq.Base.seq",
"Vale.Arch.HeapImpl.buffer_info",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.Seq.Base.length",
"Vale.X64.Memory_Sems.make_owns_rec",
"FStar.Pervasives.Native.tuple2",
"Prims.int",
"FStar.Pervasives.Native.option",
"Prims.op_LessThan",
"Vale.Arch.HeapImpl.heaplet_id",
"FStar.Set.set"
] | [] | false | false | false | false | false | let make_owns (h: vale_heap) (bs: Seq.seq buffer_info) (n: nat{n <= Seq.length bs})
: GTot ((int -> option (n: nat{n < Seq.length bs})) & (heaplet_id -> Set.set int)) =
| make_owns_rec h bs n | false |
Vale.X64.Memory_Sems.fst | Vale.X64.Memory_Sems.destroy_heaplets | val destroy_heaplets (h1:vale_full_heap) : GTot vale_full_heap | val destroy_heaplets (h1:vale_full_heap) : GTot vale_full_heap | let destroy_heaplets h1 =
h1 | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory_Sems.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 4,
"end_line": 189,
"start_col": 0,
"start_line": 188
} | module Vale.X64.Memory_Sems
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.Def.Words_s
module I = Vale.Interop
module S = Vale.X64.Machine_Semantics_s
module MB = LowStar.Monotonic.Buffer
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
friend Vale.X64.Memory
module IB = Vale.Interop.Base
let same_domain h m = Set.equal (IB.addrs_set (_ih h)) (Map.domain m)
let lemma_same_domains h m1 m2 = ()
let get_heap h = I.down_mem (_ih h)
let upd_heap h m = mi_heap_upd h m
//let lemma_upd_get_heap h = I.down_up_identity (_ih h)
let lemma_get_upd_heap h m = I.up_down_identity (_ih h) m
let lemma_heap_impl = ()
let lemma_heap_get_heap h = ()
let lemma_heap_taint h = ()
//let lemma_heap_upd_heap h mh mt = ()
[@"opaque_to_smt"]
let rec set_of_range (a:int) (n:nat) : Pure (Set.set int)
(requires True)
(ensures fun s -> (forall (i:int).{:pattern Set.mem i s} Set.mem i s <==> a <= i /\ i < a + n))
=
if n = 0 then Set.empty else Set.union (set_of_range a (n - 1)) (Set.singleton (a + n - 1))
let buffer_info_has_addr (bi:buffer_info) (a:int) =
let b = bi.bi_buffer in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
addr <= a /\ a < addr + len
let buffer_info_has_addr_opt (bi:option buffer_info) (a:int) =
match bi with
| None -> False
| Some bi -> buffer_info_has_addr bi a
#set-options "--z3rlimit 100"
let rec make_owns_rec (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
if n = 0 then ((fun _ -> None), (fun _ -> Set.empty)) else
let (m0, s0) = make_owns_rec h bs (n - 1) in
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let s i = if i = hi then Set.union (s0 i) s_b else s0 i in
let m a = if addr <= a && a < addr + len then Some (n - 1) else m0 a in
(m, s)
[@"opaque_to_smt"]
let make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
make_owns_rec h bs n
let rec lemma_make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n <= Seq.length bs /\
(forall (i:nat).{:pattern Seq.index bs i} i < Seq.length bs ==> buffer_readable h (Seq.index bs i).bi_buffer) /\
(forall (i1 i2:nat).{:pattern (Seq.index bs i1); (Seq.index bs i2)}
i1 < Seq.length bs /\ i2 < Seq.length bs ==> buffer_info_disjoint (Seq.index bs i1) (Seq.index bs i2))
)
(ensures (
let (m, s) = make_owns h bs n in
(forall (i:heaplet_id) (a:int).{:pattern Set.mem a (s i)}
(Set.mem a (s i) <==> Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (m a) == Some i) /\
(Set.mem a (s i) ==> buffer_info_has_addr_opt (Option.mapTot (fun n -> Seq.index bs n) (m a)) a) /\
(Set.mem a (s i) ==> Set.mem a (Map.domain h.mh))
) /\
(forall (k:nat) (a:int).{:pattern Set.mem a (s (Seq.index bs k).bi_heaplet)}
k < n /\ buffer_info_has_addr (Seq.index bs k) a ==> Set.mem a (s (Seq.index bs k).bi_heaplet))
))
=
reveal_opaque (`%make_owns) make_owns;
if n = 0 then () else
let _ = make_owns h bs (n - 1) in
let (m, s) = make_owns h bs n in
lemma_make_owns h bs (n - 1);
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let lem1 (a:int) : Lemma
(requires Set.mem a s_b)
(ensures Set.mem a (Map.domain h.mh))
[SMTPat (Set.mem a (Map.domain h.mh))]
=
I.addrs_set_mem h.ih b a
in
let lem2 (i:heaplet_id) (a:int) : Lemma
(requires i =!= hi /\ Set.mem a (Set.intersect s_b (s i)))
(ensures False)
[SMTPat (Set.mem a (s i))]
=
reveal_opaque (`%addr_map_pred) addr_map_pred
in
()
#push-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_loc_mutable_buffers_rec (l:list buffer_info) (s:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n + List.length l == Seq.length s /\
list_to_seq_post l s n
)
(ensures (
let modloc = loc_mutable_buffers l in
forall (i:nat).{:pattern Seq.index s i} n <= i /\ i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes modloc (loc_buffer bi.bi_buffer))
))
(decreases l)
=
match l with
| [] -> ()
| h::t -> lemma_loc_mutable_buffers_rec t s (n + 1)
#pop-options
let lemma_loc_mutable_buffers (l:list buffer_info) : Lemma
(ensures (
let s = list_to_seq l in
forall (i:nat).{:pattern Seq.index s i} i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes (loc_mutable_buffers l) (loc_buffer bi.bi_buffer))
))
=
lemma_list_to_seq l;
lemma_loc_mutable_buffers_rec l (list_to_seq l) 0
let create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let modloc = loc_mutable_buffers buffers in
let layout1 = h1.vf_layout in
let layin1 = layout1.vl_inner in
let (hmap, hsets) = make_owns h1.vf_heap bs (Seq.length bs) in
let hmap a = Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (hmap a) in
let l = {
vl_heaplets_initialized = true;
vl_heaplet_map = hmap;
vl_heaplet_sets = hsets;
vl_old_heap = h1.vf_heap;
vl_buffers = bs;
vl_mod_loc = modloc;
} in
let layout2 = {layout1 with vl_inner = l} in
let h2 = {
vf_layout = layout2;
vf_heap = h1.vf_heap;
vf_heaplets = h1.vf_heaplets;
} in
h2
let lemma_create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let h2 = create_heaplets buffers h1 in
assert (h2.vf_layout.vl_inner.vl_buffers == bs); // REVIEW: why is this necessary, even with extra ifuel?
lemma_make_owns h1.vf_heap bs (Seq.length bs);
lemma_loc_mutable_buffers buffers;
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
() | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Memory.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.BufferViewStore.fsti.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Memory_Sems.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_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
}
] | {
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | h1: Vale.Arch.HeapImpl.vale_full_heap -> Prims.GTot Vale.Arch.HeapImpl.vale_full_heap | Prims.GTot | [
"sometrivial"
] | [] | [
"Vale.Arch.HeapImpl.vale_full_heap"
] | [] | false | false | false | false | false | let destroy_heaplets h1 =
| h1 | false |
Vale.X64.Memory_Sems.fst | Vale.X64.Memory_Sems.get_heap | val get_heap (h:vale_heap) : GTot (m:S.machine_heap{same_domain h m}) | val get_heap (h:vale_heap) : GTot (m:S.machine_heap{same_domain h m}) | let get_heap h = I.down_mem (_ih h) | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory_Sems.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 35,
"end_line": 25,
"start_col": 0,
"start_line": 25
} | module Vale.X64.Memory_Sems
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.Def.Words_s
module I = Vale.Interop
module S = Vale.X64.Machine_Semantics_s
module MB = LowStar.Monotonic.Buffer
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
friend Vale.X64.Memory
module IB = Vale.Interop.Base
let same_domain h m = Set.equal (IB.addrs_set (_ih h)) (Map.domain m)
let lemma_same_domains h m1 m2 = () | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Memory.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.BufferViewStore.fsti.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Memory_Sems.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | h: Vale.Arch.HeapImpl.vale_heap
-> Prims.GTot (m: Vale.Arch.MachineHeap_s.machine_heap{Vale.X64.Memory_Sems.same_domain h m}) | Prims.GTot | [
"sometrivial"
] | [] | [
"Vale.Arch.HeapImpl.vale_heap",
"Vale.Interop.down_mem",
"Vale.Arch.HeapImpl._ih",
"Vale.Arch.MachineHeap_s.machine_heap",
"Vale.X64.Memory_Sems.same_domain"
] | [] | false | false | false | false | false | let get_heap h =
| I.down_mem (_ih h) | false |
Vale.X64.Memory_Sems.fst | Vale.X64.Memory_Sems.create_heaplets | val create_heaplets (buffers:list buffer_info) (h1:vale_full_heap) : GTot vale_full_heap | val create_heaplets (buffers:list buffer_info) (h1:vale_full_heap) : GTot vale_full_heap | let create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let modloc = loc_mutable_buffers buffers in
let layout1 = h1.vf_layout in
let layin1 = layout1.vl_inner in
let (hmap, hsets) = make_owns h1.vf_heap bs (Seq.length bs) in
let hmap a = Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (hmap a) in
let l = {
vl_heaplets_initialized = true;
vl_heaplet_map = hmap;
vl_heaplet_sets = hsets;
vl_old_heap = h1.vf_heap;
vl_buffers = bs;
vl_mod_loc = modloc;
} in
let layout2 = {layout1 with vl_inner = l} in
let h2 = {
vf_layout = layout2;
vf_heap = h1.vf_heap;
vf_heaplets = h1.vf_heaplets;
} in
h2 | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory_Sems.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 4,
"end_line": 177,
"start_col": 0,
"start_line": 156
} | module Vale.X64.Memory_Sems
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.Def.Words_s
module I = Vale.Interop
module S = Vale.X64.Machine_Semantics_s
module MB = LowStar.Monotonic.Buffer
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
friend Vale.X64.Memory
module IB = Vale.Interop.Base
let same_domain h m = Set.equal (IB.addrs_set (_ih h)) (Map.domain m)
let lemma_same_domains h m1 m2 = ()
let get_heap h = I.down_mem (_ih h)
let upd_heap h m = mi_heap_upd h m
//let lemma_upd_get_heap h = I.down_up_identity (_ih h)
let lemma_get_upd_heap h m = I.up_down_identity (_ih h) m
let lemma_heap_impl = ()
let lemma_heap_get_heap h = ()
let lemma_heap_taint h = ()
//let lemma_heap_upd_heap h mh mt = ()
[@"opaque_to_smt"]
let rec set_of_range (a:int) (n:nat) : Pure (Set.set int)
(requires True)
(ensures fun s -> (forall (i:int).{:pattern Set.mem i s} Set.mem i s <==> a <= i /\ i < a + n))
=
if n = 0 then Set.empty else Set.union (set_of_range a (n - 1)) (Set.singleton (a + n - 1))
let buffer_info_has_addr (bi:buffer_info) (a:int) =
let b = bi.bi_buffer in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
addr <= a /\ a < addr + len
let buffer_info_has_addr_opt (bi:option buffer_info) (a:int) =
match bi with
| None -> False
| Some bi -> buffer_info_has_addr bi a
#set-options "--z3rlimit 100"
let rec make_owns_rec (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
if n = 0 then ((fun _ -> None), (fun _ -> Set.empty)) else
let (m0, s0) = make_owns_rec h bs (n - 1) in
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let s i = if i = hi then Set.union (s0 i) s_b else s0 i in
let m a = if addr <= a && a < addr + len then Some (n - 1) else m0 a in
(m, s)
[@"opaque_to_smt"]
let make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
make_owns_rec h bs n
let rec lemma_make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n <= Seq.length bs /\
(forall (i:nat).{:pattern Seq.index bs i} i < Seq.length bs ==> buffer_readable h (Seq.index bs i).bi_buffer) /\
(forall (i1 i2:nat).{:pattern (Seq.index bs i1); (Seq.index bs i2)}
i1 < Seq.length bs /\ i2 < Seq.length bs ==> buffer_info_disjoint (Seq.index bs i1) (Seq.index bs i2))
)
(ensures (
let (m, s) = make_owns h bs n in
(forall (i:heaplet_id) (a:int).{:pattern Set.mem a (s i)}
(Set.mem a (s i) <==> Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (m a) == Some i) /\
(Set.mem a (s i) ==> buffer_info_has_addr_opt (Option.mapTot (fun n -> Seq.index bs n) (m a)) a) /\
(Set.mem a (s i) ==> Set.mem a (Map.domain h.mh))
) /\
(forall (k:nat) (a:int).{:pattern Set.mem a (s (Seq.index bs k).bi_heaplet)}
k < n /\ buffer_info_has_addr (Seq.index bs k) a ==> Set.mem a (s (Seq.index bs k).bi_heaplet))
))
=
reveal_opaque (`%make_owns) make_owns;
if n = 0 then () else
let _ = make_owns h bs (n - 1) in
let (m, s) = make_owns h bs n in
lemma_make_owns h bs (n - 1);
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let lem1 (a:int) : Lemma
(requires Set.mem a s_b)
(ensures Set.mem a (Map.domain h.mh))
[SMTPat (Set.mem a (Map.domain h.mh))]
=
I.addrs_set_mem h.ih b a
in
let lem2 (i:heaplet_id) (a:int) : Lemma
(requires i =!= hi /\ Set.mem a (Set.intersect s_b (s i)))
(ensures False)
[SMTPat (Set.mem a (s i))]
=
reveal_opaque (`%addr_map_pred) addr_map_pred
in
()
#push-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_loc_mutable_buffers_rec (l:list buffer_info) (s:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n + List.length l == Seq.length s /\
list_to_seq_post l s n
)
(ensures (
let modloc = loc_mutable_buffers l in
forall (i:nat).{:pattern Seq.index s i} n <= i /\ i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes modloc (loc_buffer bi.bi_buffer))
))
(decreases l)
=
match l with
| [] -> ()
| h::t -> lemma_loc_mutable_buffers_rec t s (n + 1)
#pop-options
let lemma_loc_mutable_buffers (l:list buffer_info) : Lemma
(ensures (
let s = list_to_seq l in
forall (i:nat).{:pattern Seq.index s i} i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes (loc_mutable_buffers l) (loc_buffer bi.bi_buffer))
))
=
lemma_list_to_seq l;
lemma_loc_mutable_buffers_rec l (list_to_seq l) 0 | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Memory.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.BufferViewStore.fsti.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Memory_Sems.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_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
}
] | {
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | buffers: Prims.list Vale.Arch.HeapImpl.buffer_info -> h1: Vale.Arch.HeapImpl.vale_full_heap
-> Prims.GTot Vale.Arch.HeapImpl.vale_full_heap | Prims.GTot | [
"sometrivial"
] | [] | [
"Prims.list",
"Vale.Arch.HeapImpl.buffer_info",
"Vale.Arch.HeapImpl.vale_full_heap",
"Prims.int",
"FStar.Pervasives.Native.option",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Seq.Base.length",
"Vale.Arch.HeapImpl.heaplet_id",
"FStar.Set.set",
"Vale.Arch.HeapImpl.Mkvale_full_heap",
"Vale.Arch.HeapImpl.__proj__Mkvale_full_heap__item__vf_heap",
"Vale.Arch.HeapImpl.__proj__Mkvale_full_heap__item__vf_heaplets",
"Vale.Arch.HeapImpl.vale_heap_layout",
"Vale.Arch.HeapImpl.Mkvale_heap_layout",
"Vale.Arch.HeapImpl.__proj__Mkvale_heap_layout__item__vl_taint",
"Vale.Arch.HeapImpl.vale_heap_layout_inner",
"Vale.Arch.HeapImpl.Mkvale_heap_layout_inner",
"FStar.Option.mapTot",
"Vale.Arch.HeapImpl.__proj__Mkbuffer_info__item__bi_heaplet",
"FStar.Seq.Base.index",
"FStar.Pervasives.Native.tuple2",
"Vale.X64.Memory_Sems.make_owns",
"Vale.Arch.HeapImpl.__proj__Mkvale_heap_layout__item__vl_inner",
"Vale.Arch.HeapImpl.__proj__Mkvale_full_heap__item__vf_layout",
"Vale.X64.Memory.loc",
"Vale.X64.Memory.loc_mutable_buffers",
"FStar.Seq.Base.seq",
"Vale.Lib.Seqs.list_to_seq"
] | [] | false | false | false | false | false | let create_heaplets buffers h1 =
| let bs = list_to_seq buffers in
let modloc = loc_mutable_buffers buffers in
let layout1 = h1.vf_layout in
let layin1 = layout1.vl_inner in
let hmap, hsets = make_owns h1.vf_heap bs (Seq.length bs) in
let hmap a = Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (hmap a) in
let l =
{
vl_heaplets_initialized = true;
vl_heaplet_map = hmap;
vl_heaplet_sets = hsets;
vl_old_heap = h1.vf_heap;
vl_buffers = bs;
vl_mod_loc = modloc
}
in
let layout2 = { layout1 with vl_inner = l } in
let h2 = { vf_layout = layout2; vf_heap = h1.vf_heap; vf_heaplets = h1.vf_heaplets } in
h2 | false |
Vale.X64.Memory_Sems.fst | Vale.X64.Memory_Sems.lemma_get_upd_heap | val lemma_get_upd_heap (h:vale_heap) (m:S.machine_heap) : Lemma
(requires is_machine_heap_update (get_heap h) m)
(ensures get_heap (upd_heap h m) == m) | val lemma_get_upd_heap (h:vale_heap) (m:S.machine_heap) : Lemma
(requires is_machine_heap_update (get_heap h) m)
(ensures get_heap (upd_heap h m) == m) | let lemma_get_upd_heap h m = I.up_down_identity (_ih h) m | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory_Sems.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 57,
"end_line": 31,
"start_col": 0,
"start_line": 31
} | module Vale.X64.Memory_Sems
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.Def.Words_s
module I = Vale.Interop
module S = Vale.X64.Machine_Semantics_s
module MB = LowStar.Monotonic.Buffer
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
friend Vale.X64.Memory
module IB = Vale.Interop.Base
let same_domain h m = Set.equal (IB.addrs_set (_ih h)) (Map.domain m)
let lemma_same_domains h m1 m2 = ()
let get_heap h = I.down_mem (_ih h)
let upd_heap h m = mi_heap_upd h m
//let lemma_upd_get_heap h = I.down_up_identity (_ih h) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Memory.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.BufferViewStore.fsti.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Memory_Sems.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | h: Vale.Arch.HeapImpl.vale_heap -> m: Vale.Arch.MachineHeap_s.machine_heap
-> FStar.Pervasives.Lemma
(requires Vale.Arch.MachineHeap_s.is_machine_heap_update (Vale.X64.Memory_Sems.get_heap h) m)
(ensures Vale.X64.Memory_Sems.get_heap (Vale.X64.Memory_Sems.upd_heap h m) == m) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Arch.HeapImpl.vale_heap",
"Vale.Arch.MachineHeap_s.machine_heap",
"Vale.Interop.up_down_identity",
"Vale.Arch.HeapImpl._ih",
"Prims.unit"
] | [] | true | false | true | false | false | let lemma_get_upd_heap h m =
| I.up_down_identity (_ih h) m | false |
Vale.X64.Memory_Sems.fst | Vale.X64.Memory_Sems.set_of_range | val set_of_range (a: int) (n: nat)
: Pure (Set.set int)
(requires True)
(ensures
fun s -> (forall (i: int). {:pattern Set.mem i s} Set.mem i s <==> a <= i /\ i < a + n)) | val set_of_range (a: int) (n: nat)
: Pure (Set.set int)
(requires True)
(ensures
fun s -> (forall (i: int). {:pattern Set.mem i s} Set.mem i s <==> a <= i /\ i < a + n)) | let rec set_of_range (a:int) (n:nat) : Pure (Set.set int)
(requires True)
(ensures fun s -> (forall (i:int).{:pattern Set.mem i s} Set.mem i s <==> a <= i /\ i < a + n))
=
if n = 0 then Set.empty else Set.union (set_of_range a (n - 1)) (Set.singleton (a + n - 1)) | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory_Sems.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 93,
"end_line": 46,
"start_col": 0,
"start_line": 42
} | module Vale.X64.Memory_Sems
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.Def.Words_s
module I = Vale.Interop
module S = Vale.X64.Machine_Semantics_s
module MB = LowStar.Monotonic.Buffer
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
friend Vale.X64.Memory
module IB = Vale.Interop.Base
let same_domain h m = Set.equal (IB.addrs_set (_ih h)) (Map.domain m)
let lemma_same_domains h m1 m2 = ()
let get_heap h = I.down_mem (_ih h)
let upd_heap h m = mi_heap_upd h m
//let lemma_upd_get_heap h = I.down_up_identity (_ih h)
let lemma_get_upd_heap h m = I.up_down_identity (_ih h) m
let lemma_heap_impl = ()
let lemma_heap_get_heap h = ()
let lemma_heap_taint h = ()
//let lemma_heap_upd_heap h mh mt = () | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Memory.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.BufferViewStore.fsti.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Memory_Sems.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Prims.int -> n: Prims.nat -> Prims.Pure (FStar.Set.set Prims.int) | Prims.Pure | [] | [] | [
"Prims.int",
"Prims.nat",
"Prims.op_Equality",
"FStar.Set.empty",
"Prims.bool",
"FStar.Set.union",
"Vale.X64.Memory_Sems.set_of_range",
"Prims.op_Subtraction",
"FStar.Set.singleton",
"Prims.op_Addition",
"FStar.Set.set",
"Prims.l_True",
"Prims.l_Forall",
"Prims.l_iff",
"Prims.b2t",
"FStar.Set.mem",
"Prims.l_and",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan"
] | [
"recursion"
] | false | false | false | false | false | let rec set_of_range (a: int) (n: nat)
: Pure (Set.set int)
(requires True)
(ensures
fun s -> (forall (i: int). {:pattern Set.mem i s} Set.mem i s <==> a <= i /\ i < a + n)) =
| if n = 0 then Set.empty else Set.union (set_of_range a (n - 1)) (Set.singleton (a + n - 1)) | false |
Vale.X64.Memory_Sems.fst | Vale.X64.Memory_Sems.buffer_info_has_addr_opt | val buffer_info_has_addr_opt : bi: FStar.Pervasives.Native.option Vale.Arch.HeapImpl.buffer_info -> a: Prims.int -> Prims.logical | let buffer_info_has_addr_opt (bi:option buffer_info) (a:int) =
match bi with
| None -> False
| Some bi -> buffer_info_has_addr bi a | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory_Sems.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 40,
"end_line": 57,
"start_col": 0,
"start_line": 54
} | module Vale.X64.Memory_Sems
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.Def.Words_s
module I = Vale.Interop
module S = Vale.X64.Machine_Semantics_s
module MB = LowStar.Monotonic.Buffer
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
friend Vale.X64.Memory
module IB = Vale.Interop.Base
let same_domain h m = Set.equal (IB.addrs_set (_ih h)) (Map.domain m)
let lemma_same_domains h m1 m2 = ()
let get_heap h = I.down_mem (_ih h)
let upd_heap h m = mi_heap_upd h m
//let lemma_upd_get_heap h = I.down_up_identity (_ih h)
let lemma_get_upd_heap h m = I.up_down_identity (_ih h) m
let lemma_heap_impl = ()
let lemma_heap_get_heap h = ()
let lemma_heap_taint h = ()
//let lemma_heap_upd_heap h mh mt = ()
[@"opaque_to_smt"]
let rec set_of_range (a:int) (n:nat) : Pure (Set.set int)
(requires True)
(ensures fun s -> (forall (i:int).{:pattern Set.mem i s} Set.mem i s <==> a <= i /\ i < a + n))
=
if n = 0 then Set.empty else Set.union (set_of_range a (n - 1)) (Set.singleton (a + n - 1))
let buffer_info_has_addr (bi:buffer_info) (a:int) =
let b = bi.bi_buffer in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
addr <= a /\ a < addr + len | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Memory.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.BufferViewStore.fsti.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Memory_Sems.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | bi: FStar.Pervasives.Native.option Vale.Arch.HeapImpl.buffer_info -> a: Prims.int -> Prims.logical | Prims.Tot | [
"total"
] | [] | [
"FStar.Pervasives.Native.option",
"Vale.Arch.HeapImpl.buffer_info",
"Prims.int",
"Prims.l_False",
"Vale.X64.Memory_Sems.buffer_info_has_addr",
"Prims.logical"
] | [] | false | false | false | true | true | let buffer_info_has_addr_opt (bi: option buffer_info) (a: int) =
| match bi with
| None -> False
| Some bi -> buffer_info_has_addr bi a | false |
|
Vale.X64.Memory_Sems.fst | Vale.X64.Memory_Sems.upd_heap | val upd_heap (h:vale_heap) (m:S.machine_heap{is_machine_heap_update (get_heap h) m}) : GTot vale_heap | val upd_heap (h:vale_heap) (m:S.machine_heap{is_machine_heap_update (get_heap h) m}) : GTot vale_heap | let upd_heap h m = mi_heap_upd h m | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory_Sems.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 34,
"end_line": 27,
"start_col": 0,
"start_line": 27
} | module Vale.X64.Memory_Sems
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.Def.Words_s
module I = Vale.Interop
module S = Vale.X64.Machine_Semantics_s
module MB = LowStar.Monotonic.Buffer
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
friend Vale.X64.Memory
module IB = Vale.Interop.Base
let same_domain h m = Set.equal (IB.addrs_set (_ih h)) (Map.domain m)
let lemma_same_domains h m1 m2 = ()
let get_heap h = I.down_mem (_ih h) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Memory.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.BufferViewStore.fsti.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Memory_Sems.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
h: Vale.Arch.HeapImpl.vale_heap ->
m:
Vale.Arch.MachineHeap_s.machine_heap
{Vale.Arch.MachineHeap_s.is_machine_heap_update (Vale.X64.Memory_Sems.get_heap h) m}
-> Prims.GTot Vale.Arch.HeapImpl.vale_heap | Prims.GTot | [
"sometrivial"
] | [] | [
"Vale.Arch.HeapImpl.vale_heap",
"Vale.Arch.MachineHeap_s.machine_heap",
"Vale.Arch.MachineHeap_s.is_machine_heap_update",
"Vale.X64.Memory_Sems.get_heap",
"Vale.Arch.HeapImpl.mi_heap_upd"
] | [] | false | false | false | false | false | let upd_heap h m =
| mi_heap_upd h m | false |
Vale.X64.Memory_Sems.fst | Vale.X64.Memory_Sems.lemma_loc_mutable_buffers | val lemma_loc_mutable_buffers (l: list buffer_info)
: Lemma
(ensures
(let s = list_to_seq l in
forall (i: nat). {:pattern Seq.index s i}
i < Seq.length s ==>
(let bi = Seq.index s i in
bi.bi_mutable == Mutable ==>
loc_includes (loc_mutable_buffers l) (loc_buffer bi.bi_buffer)))) | val lemma_loc_mutable_buffers (l: list buffer_info)
: Lemma
(ensures
(let s = list_to_seq l in
forall (i: nat). {:pattern Seq.index s i}
i < Seq.length s ==>
(let bi = Seq.index s i in
bi.bi_mutable == Mutable ==>
loc_includes (loc_mutable_buffers l) (loc_buffer bi.bi_buffer)))) | let lemma_loc_mutable_buffers (l:list buffer_info) : Lemma
(ensures (
let s = list_to_seq l in
forall (i:nat).{:pattern Seq.index s i} i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes (loc_mutable_buffers l) (loc_buffer bi.bi_buffer))
))
=
lemma_list_to_seq l;
lemma_loc_mutable_buffers_rec l (list_to_seq l) 0 | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory_Sems.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 51,
"end_line": 154,
"start_col": 0,
"start_line": 145
} | module Vale.X64.Memory_Sems
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.Def.Words_s
module I = Vale.Interop
module S = Vale.X64.Machine_Semantics_s
module MB = LowStar.Monotonic.Buffer
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
friend Vale.X64.Memory
module IB = Vale.Interop.Base
let same_domain h m = Set.equal (IB.addrs_set (_ih h)) (Map.domain m)
let lemma_same_domains h m1 m2 = ()
let get_heap h = I.down_mem (_ih h)
let upd_heap h m = mi_heap_upd h m
//let lemma_upd_get_heap h = I.down_up_identity (_ih h)
let lemma_get_upd_heap h m = I.up_down_identity (_ih h) m
let lemma_heap_impl = ()
let lemma_heap_get_heap h = ()
let lemma_heap_taint h = ()
//let lemma_heap_upd_heap h mh mt = ()
[@"opaque_to_smt"]
let rec set_of_range (a:int) (n:nat) : Pure (Set.set int)
(requires True)
(ensures fun s -> (forall (i:int).{:pattern Set.mem i s} Set.mem i s <==> a <= i /\ i < a + n))
=
if n = 0 then Set.empty else Set.union (set_of_range a (n - 1)) (Set.singleton (a + n - 1))
let buffer_info_has_addr (bi:buffer_info) (a:int) =
let b = bi.bi_buffer in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
addr <= a /\ a < addr + len
let buffer_info_has_addr_opt (bi:option buffer_info) (a:int) =
match bi with
| None -> False
| Some bi -> buffer_info_has_addr bi a
#set-options "--z3rlimit 100"
let rec make_owns_rec (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
if n = 0 then ((fun _ -> None), (fun _ -> Set.empty)) else
let (m0, s0) = make_owns_rec h bs (n - 1) in
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let s i = if i = hi then Set.union (s0 i) s_b else s0 i in
let m a = if addr <= a && a < addr + len then Some (n - 1) else m0 a in
(m, s)
[@"opaque_to_smt"]
let make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
make_owns_rec h bs n
let rec lemma_make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n <= Seq.length bs /\
(forall (i:nat).{:pattern Seq.index bs i} i < Seq.length bs ==> buffer_readable h (Seq.index bs i).bi_buffer) /\
(forall (i1 i2:nat).{:pattern (Seq.index bs i1); (Seq.index bs i2)}
i1 < Seq.length bs /\ i2 < Seq.length bs ==> buffer_info_disjoint (Seq.index bs i1) (Seq.index bs i2))
)
(ensures (
let (m, s) = make_owns h bs n in
(forall (i:heaplet_id) (a:int).{:pattern Set.mem a (s i)}
(Set.mem a (s i) <==> Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (m a) == Some i) /\
(Set.mem a (s i) ==> buffer_info_has_addr_opt (Option.mapTot (fun n -> Seq.index bs n) (m a)) a) /\
(Set.mem a (s i) ==> Set.mem a (Map.domain h.mh))
) /\
(forall (k:nat) (a:int).{:pattern Set.mem a (s (Seq.index bs k).bi_heaplet)}
k < n /\ buffer_info_has_addr (Seq.index bs k) a ==> Set.mem a (s (Seq.index bs k).bi_heaplet))
))
=
reveal_opaque (`%make_owns) make_owns;
if n = 0 then () else
let _ = make_owns h bs (n - 1) in
let (m, s) = make_owns h bs n in
lemma_make_owns h bs (n - 1);
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let lem1 (a:int) : Lemma
(requires Set.mem a s_b)
(ensures Set.mem a (Map.domain h.mh))
[SMTPat (Set.mem a (Map.domain h.mh))]
=
I.addrs_set_mem h.ih b a
in
let lem2 (i:heaplet_id) (a:int) : Lemma
(requires i =!= hi /\ Set.mem a (Set.intersect s_b (s i)))
(ensures False)
[SMTPat (Set.mem a (s i))]
=
reveal_opaque (`%addr_map_pred) addr_map_pred
in
()
#push-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_loc_mutable_buffers_rec (l:list buffer_info) (s:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n + List.length l == Seq.length s /\
list_to_seq_post l s n
)
(ensures (
let modloc = loc_mutable_buffers l in
forall (i:nat).{:pattern Seq.index s i} n <= i /\ i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes modloc (loc_buffer bi.bi_buffer))
))
(decreases l)
=
match l with
| [] -> ()
| h::t -> lemma_loc_mutable_buffers_rec t s (n + 1)
#pop-options | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Memory.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.BufferViewStore.fsti.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Memory_Sems.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_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
}
] | {
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | l: Prims.list Vale.Arch.HeapImpl.buffer_info
-> FStar.Pervasives.Lemma
(ensures
(let s = Vale.Lib.Seqs.list_to_seq l in
forall (i: Prims.nat). {:pattern FStar.Seq.Base.index s i}
i < FStar.Seq.Base.length s ==>
(let bi = FStar.Seq.Base.index s i in
Mkbuffer_info?.bi_mutable bi == Vale.Arch.HeapImpl.Mutable ==>
Vale.X64.Memory.loc_includes (Vale.X64.Memory.loc_mutable_buffers l)
(Vale.X64.Memory.loc_buffer (Mkbuffer_info?.bi_buffer bi))))) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.list",
"Vale.Arch.HeapImpl.buffer_info",
"Vale.X64.Memory_Sems.lemma_loc_mutable_buffers_rec",
"Vale.Lib.Seqs.list_to_seq",
"Prims.unit",
"Vale.Lib.Seqs.lemma_list_to_seq",
"Prims.l_True",
"Prims.squash",
"Prims.l_Forall",
"Prims.nat",
"Prims.l_imp",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Seq.Base.length",
"Prims.eq2",
"Vale.Arch.HeapImpl.mutability",
"Vale.Arch.HeapImpl.__proj__Mkbuffer_info__item__bi_mutable",
"Vale.Arch.HeapImpl.Mutable",
"Vale.X64.Memory.loc_includes",
"Vale.X64.Memory.loc_mutable_buffers",
"Vale.X64.Memory.loc_buffer",
"Vale.Arch.HeapImpl.__proj__Mkbuffer_info__item__bi_typ",
"Vale.Arch.HeapImpl.__proj__Mkbuffer_info__item__bi_buffer",
"FStar.Seq.Base.index",
"FStar.Seq.Base.seq",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let lemma_loc_mutable_buffers (l: list buffer_info)
: Lemma
(ensures
(let s = list_to_seq l in
forall (i: nat). {:pattern Seq.index s i}
i < Seq.length s ==>
(let bi = Seq.index s i in
bi.bi_mutable == Mutable ==>
loc_includes (loc_mutable_buffers l) (loc_buffer bi.bi_buffer)))) =
| lemma_list_to_seq l;
lemma_loc_mutable_buffers_rec l (list_to_seq l) 0 | false |
Steel.Memory.fst | Steel.Memory.with_invariant | val with_invariant (#a:Type)
(#fp:slprop)
(#fp':a -> slprop)
(#opened_invariants:inames)
(#p:slprop)
(i:inv p{not (mem_inv opened_invariants i)})
(f:action_except a (add_inv opened_invariants i) (p `star` fp) (fun x -> p `star` fp' x))
: action_except a opened_invariants fp fp' | val with_invariant (#a:Type)
(#fp:slprop)
(#fp':a -> slprop)
(#opened_invariants:inames)
(#p:slprop)
(i:inv p{not (mem_inv opened_invariants i)})
(f:action_except a (add_inv opened_invariants i) (p `star` fp) (fun x -> p `star` fp' x))
: action_except a opened_invariants fp fp' | let with_invariant (#a:Type)
(#fp:slprop)
(#fp':a -> slprop)
(#opened_invariants:inames)
(#p:slprop)
(i:inv p{not (mem_inv opened_invariants i)})
(f:action_except a (add_inv opened_invariants i) (p `star` fp) (fun x -> p `star` fp' x))
(frame:slprop)
: MstTot a opened_invariants fp fp' frame (fun _ -> True) (fun _ _ _ -> True)
= let m0 = NMSTTotal.get () in
NMSTTotal.recall _ mem_evolves (iname_for_p_mem (name_of_inv i) p) (token_of_inv i);
assert (iname_for_p (name_of_inv i) p m0.locks);
assert (interp (fp `star` frame `star` locks_invariant opened_invariants m0) m0);
assert (interp (fp `star` frame `star`
(lock_store_invariant opened_invariants m0.locks `star`
ctr_validity m0.ctr (heap_of_mem m0))) m0);
move_invariant opened_invariants m0.locks p (name_of_inv i);
assert (lock_store_invariant opened_invariants m0.locks `equiv`
(p `star` lock_store_invariant (set_add (name_of_inv i) opened_invariants) m0.locks));
with_inv_helper
fp
frame
(lock_store_invariant opened_invariants m0.locks)
(ctr_validity m0.ctr (heap_of_mem m0))
p
(lock_store_invariant (set_add (name_of_inv i) opened_invariants) m0.locks);
assert (interp (p `star` fp `star` frame `star` locks_invariant (set_add (name_of_inv i) opened_invariants) m0) m0);
let r = f frame in
let m1 : full_mem = NMSTTotal.get () in
assert (interp (p `star` fp' r `star` frame `star` locks_invariant (set_add (name_of_inv i) opened_invariants) m1) m1);
assert (interp (p `star` fp' r `star` frame `star`
(lock_store_invariant (set_add (name_of_inv i) opened_invariants) m1.locks `star`
ctr_validity m1.ctr (heap_of_mem m1))) m1);
NMSTTotal.recall _ mem_evolves (iname_for_p_mem (name_of_inv i) p) (token_of_inv i);
move_invariant opened_invariants m1.locks p (name_of_inv i);
assert (lock_store_invariant opened_invariants m1.locks `equiv`
(p `star` lock_store_invariant (set_add (name_of_inv i) opened_invariants) m1.locks));
with_inv_helper
(fp' r)
frame
(lock_store_invariant opened_invariants m1.locks)
(ctr_validity m1.ctr (heap_of_mem m1))
p
(lock_store_invariant (set_add (name_of_inv i) opened_invariants) m1.locks);
assert (interp (fp' r `star` frame `star` locks_invariant opened_invariants m1) m1);
assert (inames_ok opened_invariants m1);
r | {
"file_name": "lib/steel/Steel.Memory.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 5,
"end_line": 1489,
"start_col": 0,
"start_line": 1432
} | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Memory
module F = FStar.FunctionalExtensionality
open FStar.FunctionalExtensionality
open FStar.PCM
module H = Steel.Heap
noeq
type lock_state : Type u#(a + 1) =
| Invariant : inv:H.slprop u#a -> lock_state
let lock_store : Type u#(a+1) = list (lock_state u#a)
noeq
type mem : Type u#(a + 1) =
{
ctr: nat;
heap: H.heap u#a;
locks: lock_store u#a;
}
let heap_of_mem (x:mem) : H.heap = x.heap
let mem_of_heap (h:H.heap) : mem = {
ctr = 0;
heap = h;
locks = []
}
let mem_set_heap (m:mem) (h:H.heap) : mem = {
ctr = m.ctr;
heap = h;
locks = m.locks;
}
let core_mem (m:mem) : mem = mem_of_heap (heap_of_mem m)
let core_mem_invol m = ()
let disjoint (m0 m1:mem u#h)
: prop
= m0.ctr == m1.ctr /\
H.disjoint m0.heap m1.heap /\
m0.locks == m1.locks
let disjoint_sym m0 m1 = ()
let join m0 m1 = {
ctr = m0.ctr;
heap = H.join m0.heap m1.heap;
locks = m0.locks
}
let join_commutative m0 m1 =
H.join_commutative m0.heap m1.heap
let disjoint_join m0 m1 m2 =
H.disjoint_join m0.heap m1.heap m2.heap
let join_associative m0 m1 m2 =
H.join_associative m0.heap m1.heap m2.heap
let slprop = H.slprop
let interp p m = H.interp p m.heap
let equiv p1 p2 = forall m. interp p1 m <==> interp p2 m
let slprop_extensionality p q =
assert (forall m. interp p m <==> interp q m);
let aux (h:H.heap)
: Lemma (H.interp p h <==> H.interp q h)
[SMTPat (H.interp p h)]
= let m : mem = { ctr = 0; heap = h; locks = [] } in
assert (interp p m <==> interp q m)
in
assert (forall h. H.interp p h <==> H.interp q h);
Steel.Heap.slprop_extensionality p q
let reveal_equiv p1 p2 = ()
let core_ref = H.core_ref
let core_ref_null = H.core_ref_null
let core_ref_is_null r = H.core_ref_is_null r
let emp : slprop u#a = H.emp
let pure = H.pure
let pts_to = H.pts_to
let h_and = H.h_and
let h_or = H.h_or
let star = H.star
let wand = H.wand
let h_exists = H.h_exists
let h_forall = H.h_forall
////////////////////////////////////////////////////////////////////////////////
//properties of equiv
////////////////////////////////////////////////////////////////////////////////
let equiv_symmetric (p1 p2:slprop u#a) = H.equiv_symmetric p1 p2
#push-options "--warn_error -271"
let equiv_heap_iff_equiv (p1 p2:slprop u#a)
: Lemma (ensures (H.equiv p1 p2 <==> equiv p1 p2))
[SMTPat (equiv p1 p2)]
= let aux_lr ()
: Lemma
(requires H.equiv p1 p2)
(ensures equiv p1 p2)
[SMTPat ()]
= ()
in
let aux_rl_helper1 (h:H.heap)
: Lemma
(requires equiv p1 p2 /\ H.interp p1 h)
(ensures H.interp p2 h)
[SMTPat ()]
= assert (interp p2 (mem_of_heap h))
in
let aux_rl_helper2 (h:H.heap)
: Lemma
(requires equiv p1 p2 /\ H.interp p2 h)
(ensures H.interp p1 h)
[SMTPat ()]
= assert (interp p2 (mem_of_heap h))
in
let aux_rl ()
: Lemma
(requires equiv p1 p2)
(ensures H.equiv p1 p2)
[SMTPat ()]
= () in
()
let equiv_heap_iff_equiv_forall ()
: Lemma (ensures (forall p1 p2. H.equiv p1 p2 <==> equiv p1 p2))
= let aux p1 p2
: Lemma (ensures (H.equiv p1 p2 <==> equiv p1 p2))
[SMTPat ()]
= equiv_heap_iff_equiv p1 p2
in
()
#pop-options
let equiv_extensional_on_star (p1 p2 p3:slprop u#a) =
equiv_heap_iff_equiv_forall ();
H.equiv_extensional_on_star p1 p2 p3
let emp_unit p = H.emp_unit p
let intro_emp m = H.intro_emp (heap_of_mem m)
let pure_equiv p q = H.pure_equiv p q
let pure_interp q m = H.pure_interp q (heap_of_mem m)
let pure_star_interp p q m = H.pure_star_interp p q (heap_of_mem m)
////////////////////////////////////////////////////////////////////////////////
//pts_to
////////////////////////////////////////////////////////////////////////////////
let pts_to_compatible #a #pcm x v0 v1 m
= H.pts_to_compatible #a #pcm x v0 v1 (heap_of_mem m)
let pts_to_compatible_equiv #a #pcm x v0 v1
= H.pts_to_compatible_equiv #a #pcm x v0 v1
let pts_to_not_null #a #pcm x v m
= H.pts_to_not_null #a #pcm x v (heap_of_mem m)
////////////////////////////////////////////////////////////////////////////////
// star
////////////////////////////////////////////////////////////////////////////////
let intro_star p q mp mq =
H.intro_star p q (heap_of_mem mp) (heap_of_mem mq)
let elim_star p q m =
let h = heap_of_mem m in
H.elim_star p q h;
assert (exists hl hr. H.disjoint hl hr /\ H.join hl hr == h /\ H.interp p hl /\ H.interp q hr);
let hl = FStar.IndefiniteDescription.indefinite_description_tot H.heap (fun hl ->
exists hr. H.disjoint hl hr /\ H.join hl hr == h /\ H.interp p hl /\ H.interp q hr) in
let hr = FStar.IndefiniteDescription.indefinite_description_tot H.heap (fun hr ->
H.disjoint hl hr /\ H.join hl hr == h /\ H.interp p hl /\ H.interp q hr) in
let ml = mem_set_heap m hl in
let mr = mem_set_heap m hr in
assert (disjoint ml mr);
assert (m == join ml mr);
assert (interp p ml);
assert (interp q mr);
()
let interp_star
(p q: slprop)
(m: mem)
: Lemma
(interp (p `star` q) m <==> (exists (mp: mem) (mq: mem) . disjoint mp mq /\ interp p mp /\ interp q mq /\ join mp mq == m))
= let left = interp (p `star` q) m in
let right = exists (mp: mem) (mq: mem) . disjoint mp mq /\ interp p mp /\ interp q mq /\ join mp mq == m in
let f ()
: Lemma
(requires left)
(ensures right)
=
elim_star p q m
in
let g ()
: Lemma
(requires right)
(ensures left)
=
Classical.exists_elim left #_ #(fun mp -> exists (mq: mem) . disjoint mp mq /\ interp p mp /\ interp q mq /\ join mp mq == m) () (fun mp ->
Classical.exists_elim left #_ #(fun mq -> disjoint mp mq /\ interp p mp /\ interp q mq /\ join mp mq == m) () (fun mq ->
intro_star p q mp mq
)
)
in
Classical.move_requires f ();
Classical.move_requires g ()
let star_commutative (p1 p2:slprop) =
H.star_commutative p1 p2
let star_associative (p1 p2 p3:slprop) =
H.star_associative p1 p2 p3
let star_congruence (p1 p2 p3 p4:slprop) =
equiv_heap_iff_equiv_forall ();
H.star_congruence p1 p2 p3 p4
let affine_star (p q:slprop) (m:mem) =
H.affine_star p q (heap_of_mem m)
////////////////////////////////////////////////////////////////////////////////
// Invariants on the lock store
////////////////////////////////////////////////////////////////////////////////
let iname = nat
module S = FStar.Set
module L = FStar.List.Tot
module W = FStar.Witnessed.Core
let rec lock_store_invariant (e:inames) (l:lock_store u#a) : slprop u#a =
let current_addr = L.length l - 1 in
match l with
| [] -> emp
| Invariant p :: tl ->
if current_addr `S.mem` e then
lock_store_invariant e tl
else
p `star` lock_store_invariant e tl
let lock_i (i:iname) (l:lock_store { i < L.length l }) =
let ix = L.length l - i - 1 in
L.index l ix
let iname_for_p (i:iname) (p:slprop) : W.s_predicate lock_store =
fun l ->
i < L.length l /\
(lock_i i l).inv == p
let lock_store_evolves : FStar.Preorder.preorder lock_store =
fun (l1 l2 : lock_store) ->
L.length l2 >= L.length l1 /\
(forall (i:nat{i < L.length l1}).
(lock_i i l1).inv == (lock_i i l2).inv)
let inames_in (e:inames) (l:lock_store) : prop = forall i. Set.mem i e ==> i < L.length l
let inames_ok e m = inames_in e m.locks
let inames_ok_empty m = ()
let extend_lock_store (e:inames) (l:lock_store{e `inames_in` l}) (p:slprop)
: i:iname &
l':lock_store {
lock_store_invariant e l' == p `star` lock_store_invariant e l /\
iname_for_p i p l'
}
= (| L.length l, Invariant p :: l |)
let set_add (i:iname) (s:inames) = Set.union (Set.singleton i) s
let rec move_invariant (e:inames) (l:lock_store) (p:slprop)
(i:iname{iname_for_p i p l /\ ~(i `Set.mem` e)})
: Lemma (H.equiv (lock_store_invariant e l)
(p `star` lock_store_invariant (set_add i e) l))
= let rec aux (i:iname) (m:lock_store)
: Lemma (requires i >= L.length m)
(ensures (lock_store_invariant e m `H.equiv` lock_store_invariant (set_add i e) m))
= match m with
| [] -> ()
| Invariant p::tl ->
aux i tl;
H.star_congruence p (lock_store_invariant e tl) p (lock_store_invariant (set_add i e) tl)
in
let current_addr = L.length l - 1 in
match l with
| [] -> ()
| Invariant q::tl ->
if i = current_addr
then begin
assert (lock_store_invariant e l == p `star` lock_store_invariant e tl);
aux i tl;
H.star_congruence p (lock_store_invariant e tl) p (lock_store_invariant (set_add i e) tl);
()
end
else begin
move_invariant e tl p i;
assert (lock_store_invariant e tl `equiv`
(p `star` lock_store_invariant (set_add i e) tl));
H.star_congruence q (lock_store_invariant e tl) q (p `star` lock_store_invariant (set_add i e) tl);
if Set.mem current_addr e
then ()
else begin
let r = lock_store_invariant (set_add i e) tl in
assert (lock_store_invariant e l `equiv`
(q `star` (p `star` r)));
H.star_associative q p r;
H.star_commutative q p;
H.star_congruence (q `star` p) r (p `star` q) r;
H.star_associative p q r
end
end
let heap_ctr_valid (ctr:nat) (h:H.heap u#a) : prop =
h `H.free_above_addr` ctr
let ctr_validity (ctr:nat) (h:H.heap) : slprop =
H.pure (heap_ctr_valid ctr h)
let locks_invariant (e:inames) (m:mem u#a) : slprop u#a =
lock_store_invariant e m.locks
`star`
ctr_validity m.ctr (heap_of_mem m)
let full_mem_pred (m:mem) = H.full_heap_pred (heap_of_mem m)
(***** Following lemmas are needed in Steel.Effect *****)
let core_mem_interp (hp:slprop u#a) (m:mem u#a) = ()
let interp_depends_only_on (hp:slprop u#a) = H.interp_depends_only_on hp
let a_mem_prop_as_a_heap_prop
(sl: slprop u#a)
(f: a_mem_prop sl)
: Tot (H.a_heap_prop u#a)
=
let g (h: H.heap u#a) : Tot prop = interp sl (mem_of_heap h) /\ f (mem_of_heap h) in
let phi0 (h0 h1: H.heap u#a) : Lemma
(requires (g h0 /\ H.disjoint h0 h1))
(ensures (g h0 /\ H.disjoint h0 h1 /\ g (H.join h0 h1)))
= assert (mem_of_heap (H.join h0 h1) == mem_of_heap h0 `join` mem_of_heap h1);
interp_depends_only_on sl
in
let phi1 (h0 h1: H.heap u#a) : Lemma
(ensures ((g h0 /\ H.disjoint h0 h1) ==> g (H.join h0 h1)))
=
Classical.move_requires (phi0 h0) h1
in
Classical.forall_intro_2 phi1;
g
let refine_slprop sl f = H.as_slprop (a_mem_prop_as_a_heap_prop sl f)
let interp_refine_slprop sl f m =
assert ((interp sl m /\ f m) <==> interp sl (core_mem m) /\ f (core_mem m))
let dep_hprop
(s: slprop)
(f: (hmem s -> Tot slprop))
(h: H.heap)
: Tot prop
= exists (h1: H.heap) . exists (h2: H.heap) . interp s (mem_of_heap h1) /\ H.disjoint h1 h2 /\ interp (f (mem_of_heap h1)) (mem_of_heap h2) /\ h == h1 `H.join` h2
let dep_hprop_is_affine0
(s: slprop)
(f: (hmem s -> Tot slprop))
(h h': H.heap)
(sq' : squash (dep_hprop s f h /\ H.disjoint h h'))
: Lemma
(H.disjoint h h' /\ dep_hprop s f (H.join h h'))
=
let p2 (h h1 h2: H.heap) : Tot prop =
interp s (mem_of_heap h1) /\
H.disjoint h1 h2 /\ interp (f (mem_of_heap h1)) (mem_of_heap h2) /\ h == h1 `H.join` h2
in
let p1 (h h1: H.heap) : Tot prop =
(exists h2 . p2 h h1 h2)
in
let h1 =
FStar.IndefiniteDescription.indefinite_description_ghost H.heap (p1 h)
in
let h2 =
FStar.IndefiniteDescription.indefinite_description_ghost H.heap (p2 h h1)
in
H.disjoint_join h' h1 h2;
assert (H.disjoint h2 h');
let h2' = H.join h2 h' in
H.join_commutative h2 h' ;
assert (h2' == H.join h' h2);
assert (H.disjoint h1 h2');
assert (mem_of_heap h2' == mem_of_heap h2 `join` mem_of_heap h');
interp_depends_only_on (f (mem_of_heap h1));
assert (interp (f (mem_of_heap h1)) (mem_of_heap h2'));
H.join_commutative h1 h2;
H.join_associative h' h2 h1;
H.join_commutative h' h;
H.join_commutative h2' h1;
assert (H.join h h' == h1 `H.join` h2')
let impl_intro_gen (#p: Type0) (#q: Type0) ($prf: (squash p -> Lemma (q )))
: Lemma (p ==> q)
= Classical.impl_intro_gen #p #(fun _ -> q) prf
let dep_hprop_is_affine1
(s: slprop)
(f: (hmem s -> Tot slprop))
(h0 h1: H.heap)
: Lemma
((dep_hprop s f h0 /\ H.disjoint h0 h1) ==> (H.disjoint h0 h1 /\ dep_hprop s f (H.join h0 h1)))
= impl_intro_gen (dep_hprop_is_affine0 s f h0 h1)
let dep_hprop_is_affine
(s: slprop)
(f: (hmem s -> Tot slprop))
: Lemma
(H.heap_prop_is_affine (dep_hprop s f))
= Classical.forall_intro_2 (dep_hprop_is_affine1 s f)
let sdep
(s: slprop)
(f: (hmem s -> Tot slprop))
: Tot slprop
=
dep_hprop_is_affine s f;
H.as_slprop (dep_hprop s f)
let interp_sdep
(s: slprop)
(f: (hmem s -> Tot slprop))
(m: mem)
: Lemma
(requires (dep_slprop_is_affine s f))
(ensures (
interp (sdep s f) m <==> (exists m1 m2 . interp s m1 /\ interp (f m1) m2 /\ disjoint m1 m2 /\ join m1 m2 == m)
))
=
dep_hprop_is_affine s f;
assert (forall m1 m2 . (interp s m1 /\ interp (f m1) m2 /\ disjoint m1 m2 /\ join m1 m2 == m) ==> (
interp s (mem_of_heap m1.heap) /\ interp (f (mem_of_heap m1.heap)) (mem_of_heap m2.heap) /\
H.disjoint m1.heap m2.heap /\
H.join m1.heap m2.heap == m.heap
));
interp_depends_only_on s;
Classical.forall_intro (fun m -> interp_depends_only_on (f m));
assert (forall h1 h2 . (interp s (mem_of_heap h1) /\ interp (f (mem_of_heap h1)) (mem_of_heap h2) /\ H.disjoint h1 h2 /\ H.join h1 h2 == m.heap) ==> (
core_mem (mem_of_heap h1) == core_mem (mem_set_heap m h1) /\
interp s (core_mem (mem_of_heap h1)) /\
interp s (mem_set_heap m h1) /\
core_mem (mem_of_heap h1) == core_mem (mem_set_heap m h1) /\
f (mem_set_heap m h1) `equiv` f (mem_of_heap h1) /\
interp (f (mem_set_heap m h1)) (mem_of_heap h2) /\
interp (f (mem_set_heap m h1)) (mem_set_heap m h2) /\
disjoint (mem_set_heap m h1) (mem_set_heap m h2) /\
join (mem_set_heap m h1) (mem_set_heap m h2) == m
));
()
let h_exists_cong (#a:Type) (p q : a -> slprop)
: Lemma
(requires (forall x. p x `equiv` q x))
(ensures (h_exists p `equiv` h_exists q))
= equiv_heap_iff_equiv_forall ();
H.h_exists_cong p q
let intro_h_exists #a x p m = H.intro_h_exists x p (heap_of_mem m)
let elim_h_exists (#a:_) (p:a -> slprop) (m:mem) = H.elim_h_exists p (heap_of_mem m)
let intro_h_forall (#a:_) (p:a -> slprop) (m:mem) = H.intro_h_forall p (heap_of_mem m)
let elim_h_forall (#a:_) (p:a -> slprop) (m:mem) (x:a) = H.elim_h_forall p (heap_of_mem m) x
let intro_h_and (p q: slprop) (m:mem) = H.intro_h_and p q (heap_of_mem m)
let elim_h_and (p q: slprop) (m:mem) = H.elim_h_and p q (heap_of_mem m)
let intro_h_or_left (p q: slprop) (m:mem) = H.intro_h_or_left p q (heap_of_mem m)
let intro_h_or_right (p q: slprop) (m:mem) = H.intro_h_or_right p q (heap_of_mem m)
let elim_h_or (p q: slprop) (m:mem) = H.elim_h_or p q (heap_of_mem m)
let intro_wand (p1 p2: slprop u#a) (m:mem) =
introduce
(forall m1. m `disjoint` m1 /\ interp p1 m1 ==> interp p2 (join m m1))
==> interp (wand p1 p2) m
with _. (
assert (forall m1. m `disjoint` m1 /\ interp p1 m1 ==> interp p2 (join m m1));
H.intro_wand p1 p2 (heap_of_mem m);
let h = heap_of_mem m in
assert ((forall h1. h `H.disjoint` h1 /\ H.interp p1 h1 ==> H.interp p2 (H.join h h1))
==> H.interp (wand p1 p2) h);
introduce forall h1. (h `H.disjoint` h1 /\ H.interp p1 h1 ==> H.interp p2 (H.join h h1))
with (
introduce (h `H.disjoint` h1 /\ H.interp p1 h1) ==> H.interp p2 (H.join h h1)
with _. (
assert (h `H.disjoint` h1);
let m1 = {
ctr = m.ctr;
heap = h1;
locks = m.locks
}
in assert (m `disjoint` m1)
)
)
)
(** Eliminating a wand by proving a heap that satisfies the LHS **)
let elim_wand (p1 p2: slprop u#a) (m:mem) (m1:mem) = H.elim_wand p1 p2 (heap_of_mem m) (heap_of_mem m1)
////////////////////////////////////////////////////////////////////////////////
// Preorders and effects
////////////////////////////////////////////////////////////////////////////////
module PP = Steel.Preorder
let mem_evolves =
fun (m0 m1:full_mem) ->
H.heap_evolves (heap_of_mem m0) (heap_of_mem m1) /\
m0.ctr <= m1.ctr /\
lock_store_evolves m0.locks m1.locks
(** See [Steel.Heap.is_frame_preserving]. We add in [lock_invariants] now *)
let preserves_frame (e:inames) (pre post:slprop) (m0 m1:mem) =
forall (frame:slprop).
interp ((pre `star` frame) `star` locks_invariant e m0) m0 ==>
(interp ((post `star` frame) `star` locks_invariant e m1) m1 /\
(forall (f_frame:mprop frame). f_frame (core_mem m0) == f_frame (core_mem m1)))
(**
This is a version of MstTot with frame quantified, as part of preserves_frame
*)
effect MstTotNF (a:Type u#a) (except:inames) (expects:slprop u#1) (provides: a -> slprop u#1) =
NMSTTotal.NMSTATETOT a (full_mem u#1) mem_evolves
(requires fun m0 ->
inames_ok except m0 /\
interp (expects `star` locks_invariant except m0) m0)
(ensures fun m0 x m1 ->
inames_ok except m1 /\
interp (provides x `star` locks_invariant except m1) m1 /\
preserves_frame except expects (provides x) m0 m1)
////////////////////////////////////////////////////////////////////////////////
// Lifting heap actions
////////////////////////////////////////////////////////////////////////////////
(**
Heap actions come in two equivalent flavors:
- one that take an explicit frame as argument (action_with_frame)
- and one that quantify over all the frame
We therefore define two lift routes:
- a direct route for those with explicit frame
- via MstTotNF for the rest
*)
let tot_pre_action_nf_except (e:inames) (fp:slprop u#a) (a:Type u#b) (fp':a -> slprop u#a) =
hmem_with_inv_except e fp ->
(x:a & hmem_with_inv_except e (fp' x))
let tot_pre_action_nf = tot_pre_action_nf_except S.empty
let ac_reasoning_for_m_frame_preserving
(p q r:slprop u#a) (m:mem u#a)
: Lemma
(requires interp ((p `star` q) `star` r) m)
(ensures interp (p `star` r) m)
= calc (equiv) {
(p `star` q) `star` r;
(equiv) { star_commutative p q;
equiv_extensional_on_star (p `star` q) (q `star` p) r }
(q `star` p) `star` r;
(equiv) { star_associative q p r }
q `star` (p `star` r);
};
assert (interp (q `star` (p `star` r)) m);
affine_star q (p `star` r) m
let is_frame_preserving
(#e:inames)
(#a:Type u#b)
(#fp:slprop u#a)
(#fp':a -> slprop u#a)
(f:tot_pre_action_nf_except e fp a fp') =
forall (frame:slprop u#a) (m0:hmem_with_inv_except e (fp `star` frame)).
(ac_reasoning_for_m_frame_preserving fp frame (locks_invariant e m0) m0;
let (| x, m1 |) = f m0 in
interp ((fp' x `star` frame) `star` locks_invariant e m1) m1 /\
mem_evolves m0 m1 /\
(forall (mp:mprop frame). mp (core_mem m0) == mp (core_mem m1)))
let tot_action_nf_except (e:inames) (fp:slprop u#a) (a:Type u#b) (fp':a -> slprop u#a) =
f:tot_pre_action_nf_except e fp a fp'{ is_frame_preserving f }
let tot_action_nf = tot_action_nf_except S.empty
let linv e (m:mem) = locks_invariant e m
let hheap_of_hmem #fp #e (m:hmem_with_inv_except e fp)
: h:H.hheap (fp `star` linv e m) { h `H.free_above_addr` m.ctr}
= let h = heap_of_mem m in
H.pure_interp (heap_ctr_valid m.ctr (heap_of_mem m)) h;
h
let hmem_of_hheap #e (#fp0 #fp1:slprop) (m:hmem_with_inv_except e fp0)
(h:H.full_hheap (fp1 `star` linv e m) {
h `Heap.free_above_addr` m.ctr
})
: m1:hmem_with_inv_except e fp1{linv e m `equiv` linv e m1}
= let m1 : mem = { m with heap = h } in
assert (interp (fp1 `star` linv e m) m1);
star_commutative fp1 (linv e m);
assert (interp (linv e m `star` fp1) m1);
assert (linv e m1 == (lock_store_invariant e m1.locks)
`star` ctr_validity m1.ctr (heap_of_mem m1));
assert (linv e m == (lock_store_invariant e m1.locks)
`star` ctr_validity m1.ctr (heap_of_mem m));
H.pure_interp (heap_ctr_valid m1.ctr (heap_of_mem m))
(heap_of_mem m);
assert (heap_ctr_valid m1.ctr (heap_of_mem m) <==>
heap_ctr_valid m1.ctr (heap_of_mem m1));
H.pure_equiv (heap_ctr_valid m1.ctr (heap_of_mem m))
(heap_ctr_valid m1.ctr (heap_of_mem m1));
H.star_congruence (lock_store_invariant e m1.locks)
(ctr_validity m1.ctr (heap_of_mem m1))
(lock_store_invariant e m1.locks)
(ctr_validity m1.ctr (heap_of_mem m));
assert (linv e m `equiv` linv e m1);
let _ = equiv_extensional_on_star (linv e m) (linv e m1) fp1 in
assert ((linv e m `star` fp1) `equiv` (linv e m1 `star` fp1));
assert (interp (linv e m1 `star` fp1) m1);
star_commutative (linv e m1) fp1;
assert (interp (fp1 `star` linv e m1) m1);
m1
let with_inv_except (m:mem) e (fp:slprop) = interp (fp `star` locks_invariant e m) m
#push-options "--warn_error -271"
let as_hprop (frame:slprop) (mp:mprop frame)
: hp:H.hprop frame{forall m. mp (core_mem m) == hp (heap_of_mem m)}
= let f = fun h -> mp (mem_of_heap h) in
assert (forall m. mp (core_mem m) == f (heap_of_mem m));
let aux (m0:H.hheap frame) (m1:H.heap{H.disjoint m0 m1})
: Lemma
(ensures (mem_of_heap (H.join m0 m1) == join (mem_of_heap m0) (mem_of_heap m1)))
[SMTPat ()]
= ()
in
f
let mprop_preservation_of_hprop_preservation
(p:slprop) (m0 m1:mem)
: Lemma
(requires (forall (hp:H.hprop p). hp (heap_of_mem m0) == hp (heap_of_mem m1)))
(ensures (forall (mp:mprop p). mp (core_mem m0) == mp (core_mem m1)))
= let aux (mp:mprop p)
: Lemma (mp (core_mem m0) == mp (core_mem m1))
[SMTPat()]
= assert (as_hprop p mp (heap_of_mem m0) == as_hprop p mp (heap_of_mem m1))
in
()
let lift_heap_action (#fp:slprop) (#a:Type) (#fp':a -> slprop)
(e:inames)
($f:H.action fp a fp')
: tot_action_nf_except e fp a fp'
= let g : tot_pre_action_nf_except e fp a fp' = fun m ->
let h0 = hheap_of_hmem m in
let (| x, h' |) = f h0 in
(| x, hmem_of_hheap m h' |)
in
let aux (frame:slprop) (m0:hmem_with_inv_except e (fp `star` frame))
: Lemma
(ensures
(ac_reasoning_for_m_frame_preserving fp frame (locks_invariant e m0) m0;
let (| x, m1 |) = g m0 in
interp ((fp' x `star` frame) `star` locks_invariant e m1) m1 /\
mem_evolves m0 m1 /\
(forall (mp:mprop frame). mp (core_mem m0) == mp (core_mem m1))))
[SMTPat ()]
= ac_reasoning_for_m_frame_preserving fp frame (locks_invariant e m0) m0;
let (| x, m1 |) = g m0 in
let h0 = hheap_of_hmem m0 in
let (| x', h1 |) = f h0 in
H.action_framing f (linv e m0) h0;
assert (x == x');
star_associative fp frame (linv e m0);
H.action_framing f (frame `star` linv e m0) h0;
assert (H.interp ((fp' x) `star` (frame `star` linv e m0)) h1);
star_associative (fp' x) frame (linv e m0);
assert (H.interp ((fp' x `star` frame) `star` linv e m0) h1);
let h1' : H.hheap ((fp' x `star` frame) `star` linv e m0) = h1 in
assert (m1 == hmem_of_hheap m0 h1');
assert (with_inv_except m1 e (fp' x `star` frame));
assert (forall (hp:H.hprop frame). hp h0 == hp h1);
mprop_preservation_of_hprop_preservation frame m0 m1;
()
in
assert (is_frame_preserving g);
g
let frame_preserving_respects_preorder #a #e #fp #fp' ($f:tot_action_nf_except e fp a fp') (m0:hmem_with_inv_except e fp)
: Lemma (let (| x, m1 |) = f m0 in
mem_evolves m0 m1)
= let aux (frame:slprop) (m0:hmem_with_inv_except e (fp `star` frame))
: Lemma
(ac_reasoning_for_m_frame_preserving fp frame (locks_invariant e m0) m0;
let (| x, m1 |) = f m0 in
interp ((fp' x `star` frame) `star` locks_invariant e m1) m1 /\
mem_evolves m0 m1)
= ()
in
H.emp_unit fp;
assert (interp (fp `star` linv e m0) m0);
H.star_congruence (fp `star` emp) (linv e m0) fp (linv e m0);
assert (interp ((fp `star` emp) `star` linv e m0) m0);
aux emp m0
let lift_tot_action_nf #a #e #fp #fp' ($f:tot_action_nf_except e fp a fp')
: MstTotNF a e fp fp'
= let m0 = NMSTTotal.get () in
let m0' : hmem_with_inv_except e fp = m0 in
let r = f m0' in
let (| x, m1 |) = r in
let m1' : hmem_with_inv_except e (fp' x) = m1 in
assert (is_frame_preserving f);
assert (m1 == dsnd (f m0));
frame_preserving_respects_preorder f m0;
NMSTTotal.put #_ #(mem_evolves) m1;
x
let lift_tot_action #a #e #fp #fp'
($f:tot_action_nf_except e fp a fp')
(frame:slprop)
: MstTot a e fp fp' frame (fun _ -> True) (fun _ _ _ -> True)
= let m0 = NMSTTotal.get #(full_mem) #_ () in
ac_reasoning_for_m_frame_preserving fp frame (locks_invariant e m0) m0;
assert (interp (fp `star` frame `star` locks_invariant e m0) m0);
assert (interp (fp `star` locks_invariant e m0) m0);
lift_tot_action_nf f
(**
Now defining the lift for heap actions with explicit frame
*)
let tot_action_with_frame_except
(e:inames)
(fp:slprop u#a)
(a:Type u#b)
(fp':a -> slprop u#a)
= frame:slprop u#a ->
m0:hmem_with_inv_except e (fp `star` frame) ->
Pure (x:a & hmem_with_inv_except e (fp' x `star` frame))
(requires True)
(ensures fun (| x, m1 |) ->
mem_evolves m0 m1 /\
(forall (mp:mprop frame). mp (core_mem m0) == mp (core_mem m1)))
let tot_action_with_frame = tot_action_with_frame_except S.empty
let lift_heap_action_with_frame
(#fp:slprop u#a)
(#a:Type u#b)
(#fp':a -> slprop u#a)
(e:inames)
($f:H.action_with_frame fp a fp')
: tot_action_with_frame_except e fp a fp'
= fun frame m0 ->
let h0 = hheap_of_hmem m0 in
calc (equiv) {
fp `star` frame `star` locks_invariant e m0;
(equiv) { star_associative fp frame (locks_invariant e m0) }
fp `star` (frame `star` locks_invariant e m0);
};
assert (H.interp (fp `star` frame `star` locks_invariant e m0) h0);
assert (H.interp (fp `star` (frame `star` locks_invariant e m0)) h0);
//key: apply the heap action with frame * locks_invariant e m0
let (| x, h1 |) = f (frame `star` locks_invariant e m0) h0 in
calc (equiv) {
fp' x `star` (frame `star` locks_invariant e m0);
(equiv) { star_associative (fp' x) frame (locks_invariant e m0) }
fp' x `star` frame `star` locks_invariant e m0;
};
assert (H.interp (fp' x `star` (frame `star` locks_invariant e m0)) h1);
assert (H.interp (fp' x `star` frame `star` locks_invariant e m0) h1);
let m1 = hmem_of_hheap m0 h1 in
assert (mem_evolves m0 m1);
mprop_preservation_of_hprop_preservation (frame `star` locks_invariant e m0) m0 m1;
assert (forall (mp:mprop frame). mp (core_mem m0) == mp (core_mem m1));
(| x, m1 |)
let lift_tot_action_with_frame #a #e #fp #fp'
($f:tot_action_with_frame_except e fp a fp')
(frame:slprop)
: MstTot a e fp fp' frame (fun _ -> True) (fun _ _ _ -> True)
= let m0 = NMSTTotal.get () in
assert (inames_ok e m0);
ac_reasoning_for_m_frame_preserving fp frame (locks_invariant e m0) m0;
assert (interp (fp `star` frame `star` locks_invariant e m0) m0);
assert (interp (fp `star` locks_invariant e m0) m0);
let m0' : hmem_with_inv_except e fp = m0 in
let r = f frame m0' in
let (| x, m1 |) = r in
ac_reasoning_for_m_frame_preserving (fp' x) frame (locks_invariant e m1) m1;
assert (interp (fp' x `star` frame `star` locks_invariant e m1) m1);
assert (interp (fp' x `star` locks_invariant e m1) m1);
let m1' : hmem_with_inv_except e (fp' x) = m1 in
NMSTTotal.put #_ #(mem_evolves) m1;
x
let sel_action #a #pcm e r v0
= lift_tot_action (lift_heap_action e (H.sel_action #a #pcm r v0))
let upd_action #a #pcm e r v0 v1
= lift_tot_action (lift_heap_action e (H.upd_action #a #pcm r v0 v1))
let free_action #a #pcm e r v0
= lift_tot_action (lift_heap_action e (H.free_action #a #pcm r v0))
let split_action #a #pcm e r v0 v1
= lift_tot_action (lift_heap_action e (H.split_action #a #pcm r v0 v1))
let gather_action #a #pcm e r v0 v1
= lift_tot_action (lift_heap_action e (H.gather_action #a #pcm r v0 v1))
let weaken (p q r:slprop) (h:H.hheap (p `star` q) { H.stronger q r })
: H.hheap (p `star` r)
= H.weaken p q r h; h
let weaken_pure (q r: prop)
: Lemma
(requires (q ==> r))
(ensures H.stronger (H.pure q) (H.pure r))
= let aux (h:H.heap)
: Lemma (ensures (H.interp (H.pure q) h ==> H.interp (H.pure r) h))
[SMTPat ()]
= H.pure_interp q h;
H.pure_interp r h
in
()
let inc_ctr (#p:slprop) #e (m:hmem_with_inv_except e p)
: m':hmem_with_inv_except e p{m'.ctr = m.ctr + 1 /\ H.stronger (linv e m) (linv e m')}
= let m' : mem = { m with ctr = m.ctr + 1} in
assert (interp (p `star` linv e m) m');
assert (linv e m == lock_store_invariant e m.locks
`star`
ctr_validity m.ctr (heap_of_mem m));
assert (linv e m' == lock_store_invariant e m.locks
`star`
ctr_validity (m.ctr + 1) (heap_of_mem m));
H.weaken_free_above (heap_of_mem m) m.ctr (m.ctr + 1);
weaken_pure (heap_ctr_valid m.ctr (heap_of_mem m))
(heap_ctr_valid (m.ctr + 1) (heap_of_mem m));
assert (H.stronger
(ctr_validity m.ctr (heap_of_mem m))
(ctr_validity (m.ctr + 1) (heap_of_mem m)));
H.star_associative p (lock_store_invariant e m.locks)
(ctr_validity m.ctr (heap_of_mem m));
H.stronger_star (lock_store_invariant e m.locks)
(ctr_validity m.ctr (heap_of_mem m))
(ctr_validity (m.ctr + 1) (heap_of_mem m));
H.weaken (p `star` lock_store_invariant e m.locks)
(ctr_validity m.ctr (heap_of_mem m))
(ctr_validity (m.ctr + 1) (heap_of_mem m))
(heap_of_mem m');
H.star_associative p (lock_store_invariant e m.locks)
(ctr_validity (m.ctr + 1) (heap_of_mem m));
let m' : hmem_with_inv_except e p = m' in
m'
let frame_related_mems (fp0 fp1:slprop u#a) e (m0:hmem_with_inv_except e fp0) (m1:hmem_with_inv_except e fp1) =
forall (frame:slprop u#a).
interp ((fp0 `star` frame) `star` linv e m0) m0 ==>
interp ((fp1 `star` frame) `star` linv e m1) m1 /\
mem_evolves m0 m1 /\
(forall (mp:mprop frame). mp (core_mem m0) == mp (core_mem m1))
let refined_pre_action e (fp0:slprop) (a:Type) (fp1:a -> slprop) =
m0:hmem_with_inv_except e fp0 ->
Pure (x:a &
hmem_with_inv_except e (fp1 x))
(requires True)
(ensures fun (| x, m1 |) ->
frame_related_mems fp0 (fp1 x) e m0 m1)
let refined_pre_action_as_action (#fp0:slprop) (#a:Type) (#fp1:a -> slprop)
#e ($f:refined_pre_action e fp0 a fp1)
: tot_action_nf_except e fp0 a fp1
= let g : tot_pre_action_nf_except e fp0 a fp1 = fun m -> f m in
let aux (frame:slprop)
(m0:hmem_with_inv_except e (fp0 `star` frame))
: Lemma
(ensures
(ac_reasoning_for_m_frame_preserving fp0 frame (locks_invariant e m0) m0;
let (| x, m1 |) = g m0 in
interp ((fp1 x `star` frame) `star` locks_invariant e m1) m1 /\
mem_evolves m0 m1 /\
(forall (mp:mprop frame). mp (core_mem m0) == mp (core_mem m1))))
[SMTPat ()]
= ac_reasoning_for_m_frame_preserving fp0 frame (locks_invariant e m0) m0;
let (| x', m1' |) = g m0 in
let (| x, m1 |) = f m0 in
assert (x == x' /\ m1 == m1')
in
g
let alloc_action #a #pcm e x
= let f : refined_pre_action e emp (ref a pcm) (fun r -> pts_to r x)
= fun m0 ->
(* NS: 9/29/22 I needed to annotate h : Heap.full_heap, for use with the Core checker
which generates a guard for checking the implicit pattern "dot" term in the dependent
pair pattern on the next line. That guard expects `h` to be a full_heap, which is it,
because it is a projection of m0. However, this is not reflected in `h`'s type. So,
the Core checker, which produces a guard for the pat_dot_term in isolation, cannot
recheck the term. If we were to fold in the checking of pat_dot_terms and their guards
with the rest of the VC, this would work. *)
let h : Heap.full_heap = hheap_of_hmem m0 in
let (|r, h'|) = H.extend #a #pcm x m0.ctr h in
let m' : hmem_with_inv_except e emp = inc_ctr m0 in
let h' : H.hheap (pts_to #a #pcm r x `star` linv e m') = weaken _ (linv e m0) (linv e m') h' in
let m1 : hmem_with_inv_except e (pts_to #a #pcm r x) = hmem_of_hheap m' h' in
assert (forall frame. H.frame_related_heaps h h' emp (pts_to #a #pcm r x) frame true);
let aux (frame:slprop)
: Lemma
(requires
interp ((emp `star` frame) `star` linv e m0) m0)
(ensures
interp ((pts_to #a #pcm r x `star` frame) `star` linv e m1) m1 /\
mem_evolves m0 m1 /\
(forall (mp:mprop frame). mp (core_mem m0) == mp (core_mem m1)))
[SMTPat (emp `star` frame)]
= star_associative emp frame (linv e m0);
assert (H.interp (emp `star` (frame `star` linv e m0)) h);
assert (H.interp (pts_to #a #pcm r x `star` (frame `star` linv e m0)) h');
star_associative (pts_to #a #pcm r x) frame (linv e m0);
assert (H.interp ((pts_to #a #pcm r x `star` frame) `star` linv e m0) h');
assert (H.stronger (linv e m0) (linv e m'));
assert (H.equiv (linv e m') (linv e m1));
assert (H.stronger (linv e m0) (linv e m1));
let h' : H.hheap ((pts_to #a #pcm r x `star` frame) `star` linv e m1) = weaken _ (linv e m0) (linv e m1) h' in
assert (H.interp ((pts_to #a #pcm r x `star` frame) `star` linv e m1) h');
assert (forall (mp:H.hprop frame). mp h == mp h');
mprop_preservation_of_hprop_preservation frame m0 m1;
assert (forall (mp:mprop frame). mp (core_mem m0) == mp (core_mem m1))
in
assert (frame_related_mems emp (pts_to r x) e m0 m1);
(| r, m1 |)
in
lift_tot_action (refined_pre_action_as_action f)
let select_refine #a #p e r x f
= lift_tot_action (lift_heap_action e (H.select_refine #a #p r x f))
let upd_gen #a #p e r x y f
= lift_tot_action (lift_heap_action e (H.upd_gen_action r x y f))
////////////////////////////////////////////////////////////////////////////////
// witness / recall
////////////////////////////////////////////////////////////////////////////////
let witnessed_ref #a #pcm (r:ref a pcm) (fact:property a) (m:full_mem)
= H.witnessed_ref #a #pcm r fact (heap_of_mem m)
let witnessed_ref_stability #a #pcm (r:ref a pcm) (fact:property a)
: Lemma
(requires FStar.Preorder.stable fact (Steel.Preorder.preorder_of_pcm pcm))
(ensures FStar.Preorder.stable (witnessed_ref r fact) mem_evolves)
= H.witnessed_ref_stability #a #pcm r fact
let witnessed (#a:Type u#1)
(#pcm:pcm a)
(r:ref a pcm)
(fact:property a)
= W.witnessed _ mem_evolves (witnessed_ref r fact)
let rearrange_pqr_prq (p q r:slprop)
: Lemma (((p `star` q) `star` r) `equiv`
((p `star` r) `star` q))
= calc (equiv)
{
(p `star` q) `star` r;
(equiv) { star_associative p q r }
p `star` (q `star` r);
(equiv) {
star_commutative q r;
star_congruence p (q `star` r) p (r `star` q)
}
p `star` (r `star` q);
(equiv) { star_associative p r q }
(p `star` r) `star` q;
}
let preserves_frame_cong (e:inames) (p q:slprop) (r s:slprop) (m0 m1:mem)
: Lemma
(requires p `equiv` r /\ q `equiv` s /\ preserves_frame e p q m0 m1)
(ensures
preserves_frame e r s m0 m1)
= let aux0 (p q r s:slprop)
: Lemma
(requires p `equiv` s)
(ensures (((p `star` q) `star` r) `equiv`
((s `star` q) `star` r)))
= star_congruence p q s q;
star_congruence (p `star` q) r (s `star` q) r
in
let aux (frame:slprop)
: Lemma (requires interp ((r `star` frame) `star` locks_invariant e m0) m0)
(ensures interp ((s `star` frame) `star` locks_invariant e m1) m1 /\
interp ((p `star` frame) `star` locks_invariant e m0) m0)
[SMTPat (r `star` frame)]
= aux0 p frame (locks_invariant e m0) r;
aux0 q frame (locks_invariant e m1) s;
assert (((p `star` frame) `star` locks_invariant e m0) `equiv`
((r `star` frame) `star` locks_invariant e m0));
assert (interp ((p `star` frame) `star` locks_invariant e m0) m0);
assert (interp ((q `star` frame) `star` locks_invariant e m1) m1);
assert (((q `star` frame) `star` locks_invariant e m1) `equiv`
((s `star` frame) `star` locks_invariant e m1));
()
in
()
let pure_true_equiv (p:slprop)
: Lemma ((p `star` pure True) `equiv` p)
= FStar.Classical.forall_intro (pure_star_interp p True);
emp_unit p;
assert ((p `star` pure True) `equiv` p)
let preserves_frame_star_pure (e:inames) (p q:slprop) (r s:prop) (m:mem)
: Lemma
(requires r /\ s)
(ensures
preserves_frame e p q m m <==>
preserves_frame e (p `star` pure r) (q `star` pure s) m m)
= pure_equiv r True;
star_congruence p (pure r) p (pure True);
pure_equiv s True;
star_congruence q (pure s) q (pure True);
pure_true_equiv p;
pure_true_equiv q;
let fwd ()
: Lemma
(requires preserves_frame e p q m m)
(ensures preserves_frame e (p `star` pure r) (q `star` pure s) m m)
[SMTPat ()]
= preserves_frame_cong e p q (p `star` pure r) (q `star` pure s) m m
in
let bk ()
: Lemma
(requires preserves_frame e (p `star` pure r) (q `star` pure s) m m)
(ensures preserves_frame e p q m m)
[SMTPat ()]
= preserves_frame_cong e (p `star` pure r) (q `star` pure s) p q m m
in
()
let witness (#a:Type) (#pcm:pcm a)
(e:inames)
(r:erased (ref a pcm))
(fact:stable_property pcm)
(v:Ghost.erased a)
(_:squash (forall z. compatible pcm v z ==> fact z))
(frame:slprop)
: MstTot (witnessed r fact) e
(pts_to r v)
(fun _ -> pts_to r v) frame
(fun _ -> True)
(fun _ _ _ -> True)
= let m0 = NMSTTotal.get () in
let _ : unit =
let hr : H.ref a pcm = r in
let v' = H.sel_v hr v (heap_of_mem m0) in
assert (interp (H.ptr hr) m0 /\ H.sel #a #pcm hr (heap_of_mem m0) == v');
assert (compatible pcm v v');
assert (fact v');
assert (witnessed_ref r fact m0);
witnessed_ref_stability r fact;
assert (FStar.Preorder.stable (witnessed_ref r fact) mem_evolves)
in
let w = NMSTTotal.witness _ mem_evolves (witnessed_ref r fact) in
w
let recall (#a:Type u#1) (#pcm:pcm a) (#fact:property a)
(e:inames)
(r:erased (ref a pcm))
(v:Ghost.erased a)
(w:witnessed r fact)
(frame:slprop)
= let m0 = NMSTTotal.get () in
NMSTTotal.recall _ mem_evolves (witnessed_ref r fact) w;
let hr : H.ref a pcm = r in
assert (witnessed_ref r fact m0);
let v1 = H.sel_v hr v (heap_of_mem m0) in
assert (compatible pcm v v1);
assert (H.sel hr (heap_of_mem m0) == v1);
assert (fact v1);
assert (interp ((pts_to r v `star` frame) `star` locks_invariant e m0) m0);
emp_unit ((pts_to r v `star` frame) `star` locks_invariant e m0);
pure_star_interp ((pts_to r v `star` frame) `star` locks_invariant e m0) (fact v1) m0;
assert (interp (((pts_to r v `star` frame)
`star` locks_invariant e m0)
`star` pure (fact v1)) m0);
rearrange_pqr_prq (pts_to r v `star` frame)
(locks_invariant e m0)
(pure (fact v1));
assert (interp (((pts_to r v `star` frame) `star` pure (fact v1))
`star` locks_invariant e m0) m0);
rearrange_pqr_prq (pts_to r v) frame (pure (fact v1));
star_congruence ((pts_to r v `star` frame) `star` pure (fact v1))
(locks_invariant e m0)
((pts_to r v `star` pure (fact v1)) `star` frame)
(locks_invariant e m0);
Ghost.hide v1
let iname_for_p_mem (i:iname) (p:slprop) : W.s_predicate mem =
fun m -> iname_for_p i p m.locks
let iname_for_p_stable (i:iname) (p:slprop)
: Lemma (W.stable full_mem mem_evolves (iname_for_p_mem i p))
= ()
let ( >--> ) (i:iname) (p:slprop) : Type0 = W.witnessed full_mem mem_evolves (iname_for_p_mem i p)
let hmem_with_inv_equiv e (m:mem) (p:slprop)
: Lemma (interp (p `star` linv e m) m <==>
interp (p `star` lock_store_invariant e m.locks) m /\
heap_ctr_valid m.ctr (heap_of_mem m))
= calc (<==>) {
interp (p `star` linv e m) m;
(<==>) { H.star_associative p (lock_store_invariant e m.locks) (ctr_validity m.ctr (heap_of_mem m)) }
interp ((p `star` lock_store_invariant e m.locks) `star` ctr_validity m.ctr (heap_of_mem m)) m;
(<==>) { H.pure_star_interp (p `star` lock_store_invariant e m.locks) (heap_ctr_valid m.ctr (heap_of_mem m)) (heap_of_mem m) }
interp ((p `star` lock_store_invariant e m.locks) `star` emp) m /\
(heap_ctr_valid m.ctr (heap_of_mem m));
(<==>) { H.emp_unit (p `star` lock_store_invariant e m.locks) }
interp (p `star` lock_store_invariant e m.locks) m /\
(heap_ctr_valid m.ctr (heap_of_mem m));
}
let new_invariant_tot_action (e:inames) (p:slprop) (m0:hmem_with_inv_except e p{ e `inames_in` m0.locks })
: Pure (iname & hmem_with_inv_except e emp)
(requires True)
(ensures fun (i, m1) ->
iname_for_p_mem i p m1 /\
frame_related_mems p emp e m0 m1 /\
mem_evolves m0 m1)
= let (| i, l1 |) = extend_lock_store e m0.locks p in
let m1 = { m0 with locks = l1 } in
assert (lock_store_invariant e m1.locks ==
p `star` lock_store_invariant e m0.locks);
calc (equiv) {
linv e m1;
(equiv) {}
(lock_store_invariant e m1.locks
`star`
ctr_validity m1.ctr (heap_of_mem m1));
(equiv) {}
((p `star` lock_store_invariant e m0.locks)
`star`
ctr_validity m1.ctr (heap_of_mem m1));
(equiv) {
H.star_associative p (lock_store_invariant e m0.locks) (ctr_validity m1.ctr (heap_of_mem m1))
}
(p `star` (lock_store_invariant e m0.locks
`star`
ctr_validity m1.ctr (heap_of_mem m1)));
(equiv) { }
(p `star` linv e m0);
};
assert (iname_for_p_mem i p m1);
assert (lock_store_evolves m0.locks l1);
assert (mem_evolves m0 m1);
hmem_with_inv_equiv e m0 p;
assert (interp (p `star` lock_store_invariant e m0.locks) m1);
assert (interp (lock_store_invariant e m1.locks) m1);
H.emp_unit (lock_store_invariant e m1.locks);
H.star_commutative (lock_store_invariant e m1.locks) emp;
assert (interp (emp `star` lock_store_invariant e m1.locks) m1);
hmem_with_inv_equiv e m1 emp;
let m1 : hmem_with_inv_except e emp = m1 in
let aux (frame:slprop)
: Lemma
(requires interp ((p `star` frame) `star` linv e m0) m0)
(ensures interp ((emp `star` frame) `star` linv e m1) m1 /\
mem_evolves m0 m1 /\
(forall (mp:mprop frame). mp (core_mem m0) <==> mp (core_mem m1)))
[SMTPat (p `star` frame)]
= assert (interp ((p `star` frame) `star` linv e m0) m1);
calc (equiv) {
((p `star` frame) `star` linv e m0);
(equiv) {
H.star_commutative p frame;
H.star_congruence (p `star` frame) (linv e m0) (frame `star` p) (linv e m0);
H.star_associative frame p (linv e m0)
}
(frame `star` (p `star` linv e m0));
(equiv) {
H.star_congruence frame (p `star` linv e m0) frame (linv e m1)
}
(frame `star` linv e m1);
(equiv) {
H.emp_unit (frame `star` linv e m1);
H.star_commutative (frame `star` linv e m1) emp;
H.star_associative emp frame (linv e m1)
}
((emp `star` frame) `star` linv e m1);
};
assert (interp ((emp `star` frame) `star` linv e m1) m1)
in
assert (frame_related_mems p emp e m0 m1);
( i, m1 )
let name_is_ok (i:iname) (m0:full_mem u#1) : prop = i < List.Tot.length m0.locks
let witnessed_name_is_ok (i:iname) = W.witnessed full_mem mem_evolves (name_is_ok i)
let pre_inv = i:erased iname & witnessed_name_is_ok i
let inv (p:slprop u#1) = i:erased iname & witnessed_name_is_ok i & (i >--> p)
let pre_inv_of_inv #p (i:inv p) = let (|i, w, _|) = i in (|i,w|)
let name_of_pre_inv (i:pre_inv) = dfst i
let rec recall_all (ctx:list pre_inv)
: NMSTTotal.NMSTATETOT unit (full_mem u#1) mem_evolves
(requires fun _ -> True)
(ensures fun m0 _ m1 -> m0==m1 /\ (forall i. i `List.Tot.memP` ctx ==> name_is_ok (name_of_pre_inv i) m0))
= match ctx with
| [] -> ()
| hd::tl ->
let (| q, i |) = hd in
let i : W.witnessed full_mem mem_evolves (name_is_ok q) = i in
NMSTTotal.recall _ mem_evolves (name_is_ok q) i;
recall_all tl
let fresh_invariant (e:inames) (p:slprop) (ctx:list pre_inv) (frame:slprop)
: MstTot (i:inv p { not (mem_inv e i) /\ fresh_wrt ctx (name_of_inv i)}) e p (fun _ -> emp) frame (fun _ -> True) (fun _ _ _ -> True)
= let m0 = NMSTTotal.get () in
recall_all ctx;
ac_reasoning_for_m_frame_preserving p frame (locks_invariant e m0) m0;
assert (interp (p `star` locks_invariant e m0) m0);
let r = new_invariant_tot_action e p m0 in
let ( i, m1 ) = r in
assert (i == List.Tot.length m0.locks);
assert (not (Set.mem i e));
assert (mem_evolves m0 m1);
NMSTTotal.put #full_mem #mem_evolves m1;
iname_for_p_stable i p;
let w = NMSTTotal.witness full_mem mem_evolves (iname_for_p_mem i p) in
let w0 = NMSTTotal.witness full_mem mem_evolves (name_is_ok i) in
(| hide i, w0, w |)
let new_invariant (e:inames) (p:slprop) (frame:slprop)
: MstTot (inv p) e p (fun _ -> emp) frame (fun _ -> True) (fun _ _ _ -> True)
= fresh_invariant e p [] frame
let rearrange_invariant (p q r : slprop) (q0 q1:slprop)
: Lemma
(requires q `equiv` (q0 `star` q1))
(ensures (p `star` (q `star` r)) `equiv`
((q0 `star` p) `star` (q1 `star` r)))
= calc (equiv)
{
p `star` (q `star` r);
(equiv)
{
calc (equiv)
{
(q `star` r);
(equiv) {
star_congruence q r (q0 `star` q1) r
}
(q0 `star` q1) `star` r;
};
star_congruence p (q `star` r) p ((q0 `star` q1) `star` r)
}
(p `star` ((q0 `star` q1) `star` r));
(equiv) {
star_associative q0 q1 r;
star_congruence p ((q0 `star` q1) `star` r)
p (q0 `star` (q1 `star` r));
star_associative p q0 (q1 `star` r)
}
(p `star` q0) `star` (q1 `star` r);
(equiv) {
star_commutative p q0;
star_congruence (p `star` q0) (q1 `star` r)
(q0 `star` p) (q1 `star` r)
}
(q0 `star` p) `star` (q1 `star` r);
}
let preserves_frame_invariant (fp fp':slprop)
(opened_invariants:inames)
(p:slprop)
(i:inv p{not (mem_inv opened_invariants i)})
(m0:hmem_with_inv_except (add_inv opened_invariants i) (p `star` fp))
(m1:mem)
: Lemma
(requires preserves_frame (set_add (name_of_inv i) opened_invariants) (p `star` fp) (p `star` fp') m0 m1 /\
interp (fp' `star` linv opened_invariants m1) m1 /\
inames_ok opened_invariants m1 /\
(lock_store_invariant opened_invariants m0.locks `equiv`
(p `star` lock_store_invariant (set_add (name_of_inv i) opened_invariants) m0.locks)) /\
(lock_store_invariant opened_invariants m1.locks `equiv`
(p `star` lock_store_invariant (set_add (name_of_inv i) opened_invariants) m1.locks)))
(ensures preserves_frame opened_invariants fp fp' m0 m1)
=
let aux (frame:slprop)
: Lemma
(requires
interp ((fp `star` frame) `star` linv opened_invariants m0) m0)
(ensures
interp ((fp' `star` frame) `star` linv opened_invariants m1) m1 /\
(forall (f_frame:mprop frame). f_frame (core_mem m0) == f_frame (core_mem m1)))
[SMTPat()]
= rearrange_invariant (fp `star` frame) (lock_store_invariant opened_invariants m0.locks) (ctr_validity m0.ctr (heap_of_mem m0))
p (lock_store_invariant (set_add (name_of_inv i) opened_invariants) m0.locks);
assert (interp ((p `star` (fp `star` frame)) `star` linv (set_add (name_of_inv i) opened_invariants) m0) m0);
star_associative p fp frame;
star_congruence (p `star` (fp `star` frame)) (linv (set_add (name_of_inv i) opened_invariants) m0)
((p `star` fp) `star` frame) (linv (set_add (name_of_inv i) opened_invariants) m0);
assert (interp (((p `star` fp) `star` frame) `star` linv (set_add (name_of_inv i) opened_invariants) m0) m0);
assert (interp (((p `star` fp') `star` frame) `star` linv (set_add (name_of_inv i) opened_invariants) m1) m1);
star_associative p fp' frame;
star_congruence ((p `star` fp') `star` frame) (linv (set_add (name_of_inv i) opened_invariants) m1)
(p `star` (fp' `star` frame)) (linv (set_add (name_of_inv i) opened_invariants) m1);
assert (interp ((p `star` (fp' `star` frame)) `star` linv (set_add (name_of_inv i) opened_invariants) m1) m1);
rearrange_invariant (fp' `star` frame) (lock_store_invariant opened_invariants m1.locks) (ctr_validity m1.ctr (heap_of_mem m1))
p (lock_store_invariant (set_add (name_of_inv i) opened_invariants) m1.locks);
assert (interp ((fp' `star` frame) `star` linv opened_invariants m1) m1);
()
in
()
let equiv_ext_right (p q r:slprop)
: Lemma
(requires q `equiv` r)
(ensures (p `star` q) `equiv` (p `star` r))
= calc (equiv) {
p `star` q;
(equiv) { star_commutative p q }
q `star` p;
(equiv) { equiv_extensional_on_star q r p }
r `star` p;
(equiv) { star_commutative p r }
p `star` r;
}
let with_inv_helper (fp frame ls1 ctr p ls2:slprop)
: Lemma
(requires ls1 `equiv` (p `star` ls2))
(ensures
(fp `star` frame `star` (ls1 `star` ctr)) `equiv`
(p `star` fp `star` frame `star` (ls2 `star` ctr)))
= calc (equiv) {
ls1 `star` ctr;
(equiv) { equiv_extensional_on_star ls1 (p `star` ls2) ctr }
p `star` ls2 `star` ctr;
};
calc (equiv) {
p `star` ls2 `star` ctr;
(equiv) { star_associative p ls2 ctr }
p `star` (ls2 `star` ctr);
};
calc (equiv) {
fp `star` frame `star` p;
(equiv) { star_commutative (fp `star` frame) p }
p `star` (fp `star` frame);
(equiv) { star_associative p fp frame }
p `star` fp `star` frame;
};
calc (equiv) {
fp `star` frame `star` (ls1 `star` ctr);
(equiv) { equiv_ext_right (fp `star` frame)
(ls1 `star` ctr)
(p `star` ls2 `star` ctr) }
(fp `star` frame) `star` (p `star` ls2 `star` ctr);
(equiv) { equiv_ext_right (fp `star` frame)
(p `star` ls2 `star` ctr)
(p `star` (ls2 `star` ctr)) }
(fp `star` frame) `star` (p `star` (ls2 `star` ctr));
(equiv) { star_associative (fp `star` frame) p (ls2 `star` ctr) }
(fp `star` frame `star` p) `star` (ls2 `star` ctr);
(equiv) { equiv_extensional_on_star
(fp `star` frame `star` p)
(p `star` fp `star` frame)
(ls2 `star` ctr) }
(p `star` fp `star` frame) `star` (ls2 `star` ctr);
}
let token_of_inv #p (i:inv p) : (name_of_inv i >--> p) = let (| _, _, tok |) = i in tok | {
"checked_file": "/",
"dependencies": [
"Steel.Preorder.fst.checked",
"Steel.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Witnessed.Core.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.PCM.fst.checked",
"FStar.NMSTTotal.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Memory.fst"
} | [
{
"abbrev": true,
"full_module": "Steel.Preorder",
"short_module": "PP"
},
{
"abbrev": true,
"full_module": "FStar.Witnessed.Core",
"short_module": "W"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "Steel.Heap",
"short_module": "H"
},
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "F"
},
{
"abbrev": true,
"full_module": "FStar.Set",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.PCM",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
i:
Steel.Memory.inv p
{Prims.op_Negation (FStar.Ghost.reveal (Steel.Memory.mem_inv opened_invariants i))} ->
f:
Steel.Memory.action_except a
(Steel.Memory.add_inv opened_invariants i)
(Steel.Memory.star p fp)
(fun x -> Steel.Memory.star p (fp' x))
-> Steel.Memory.action_except a opened_invariants fp fp' | Prims.Tot | [
"total"
] | [] | [
"Steel.Memory.slprop",
"Steel.Memory.inames",
"Steel.Memory.inv",
"Prims.b2t",
"Prims.op_Negation",
"FStar.Ghost.reveal",
"Prims.bool",
"Steel.Memory.mem_inv",
"Steel.Memory.action_except",
"Steel.Memory.add_inv",
"Steel.Memory.star",
"Prims.unit",
"Prims._assert",
"Steel.Memory.inames_ok",
"Steel.Memory.interp",
"Steel.Memory.locks_invariant",
"Steel.Memory.with_inv_helper",
"Steel.Memory.lock_store_invariant",
"Steel.Memory.__proj__Mkmem__item__locks",
"Steel.Memory.ctr_validity",
"Steel.Memory.__proj__Mkmem__item__ctr",
"Steel.Memory.heap_of_mem",
"FStar.Ghost.hide",
"FStar.Set.set",
"Steel.Memory.iname",
"Steel.Memory.set_add",
"Steel.Memory.name_of_inv",
"Steel.Memory.equiv",
"Steel.Memory.move_invariant",
"FStar.NMSTTotal.recall",
"Steel.Memory.full_mem",
"Steel.Memory.mem_evolves",
"Steel.Memory.iname_for_p_mem",
"Steel.Memory.token_of_inv",
"FStar.NMSTTotal.get",
"Steel.Memory.iname_for_p",
"Steel.Memory.mem",
"Prims.l_True",
"Prims.prop"
] | [] | false | false | false | false | false | let with_invariant
(#a: Type)
(#fp: slprop)
(#fp': (a -> slprop))
(#opened_invariants: inames)
(#p: slprop)
(i: inv p {not (mem_inv opened_invariants i)})
(f: action_except a (add_inv opened_invariants i) (p `star` fp) (fun x -> p `star` (fp' x)))
(frame: slprop)
: MstTot a opened_invariants fp fp' frame (fun _ -> True) (fun _ _ _ -> True) =
| let m0 = NMSTTotal.get () in
NMSTTotal.recall _ mem_evolves (iname_for_p_mem (name_of_inv i) p) (token_of_inv i);
assert (iname_for_p (name_of_inv i) p m0.locks);
assert (interp ((fp `star` frame) `star` (locks_invariant opened_invariants m0)) m0);
assert (interp ((fp `star` frame)
`star`
((lock_store_invariant opened_invariants m0.locks)
`star`
(ctr_validity m0.ctr (heap_of_mem m0))))
m0);
move_invariant opened_invariants m0.locks p (name_of_inv i);
assert ((lock_store_invariant opened_invariants m0.locks)
`equiv`
(p `star` (lock_store_invariant (set_add (name_of_inv i) opened_invariants) m0.locks)));
with_inv_helper fp
frame
(lock_store_invariant opened_invariants m0.locks)
(ctr_validity m0.ctr (heap_of_mem m0))
p
(lock_store_invariant (set_add (name_of_inv i) opened_invariants) m0.locks);
assert (interp (((p `star` fp) `star` frame)
`star`
(locks_invariant (set_add (name_of_inv i) opened_invariants) m0))
m0);
let r = f frame in
let m1:full_mem = NMSTTotal.get () in
assert (interp (((p `star` (fp' r)) `star` frame)
`star`
(locks_invariant (set_add (name_of_inv i) opened_invariants) m1))
m1);
assert (interp (((p `star` (fp' r)) `star` frame)
`star`
((lock_store_invariant (set_add (name_of_inv i) opened_invariants) m1.locks)
`star`
(ctr_validity m1.ctr (heap_of_mem m1))))
m1);
NMSTTotal.recall _ mem_evolves (iname_for_p_mem (name_of_inv i) p) (token_of_inv i);
move_invariant opened_invariants m1.locks p (name_of_inv i);
assert ((lock_store_invariant opened_invariants m1.locks)
`equiv`
(p `star` (lock_store_invariant (set_add (name_of_inv i) opened_invariants) m1.locks)));
with_inv_helper (fp' r)
frame
(lock_store_invariant opened_invariants m1.locks)
(ctr_validity m1.ctr (heap_of_mem m1))
p
(lock_store_invariant (set_add (name_of_inv i) opened_invariants) m1.locks);
assert (interp (((fp' r) `star` frame) `star` (locks_invariant opened_invariants m1)) m1);
assert (inames_ok opened_invariants m1);
r | false |
Vale.X64.Memory_Sems.fst | Vale.X64.Memory_Sems.make_owns_rec | val make_owns_rec (h: vale_heap) (bs: Seq.seq buffer_info) (n: nat{n <= Seq.length bs})
: GTot ((int -> option (n: nat{n < Seq.length bs})) & (heaplet_id -> Set.set int)) | val make_owns_rec (h: vale_heap) (bs: Seq.seq buffer_info) (n: nat{n <= Seq.length bs})
: GTot ((int -> option (n: nat{n < Seq.length bs})) & (heaplet_id -> Set.set int)) | let rec make_owns_rec (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
if n = 0 then ((fun _ -> None), (fun _ -> Set.empty)) else
let (m0, s0) = make_owns_rec h bs (n - 1) in
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let s i = if i = hi then Set.union (s0 i) s_b else s0 i in
let m a = if addr <= a && a < addr + len then Some (n - 1) else m0 a in
(m, s) | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory_Sems.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 8,
"end_line": 73,
"start_col": 0,
"start_line": 60
} | module Vale.X64.Memory_Sems
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.Def.Words_s
module I = Vale.Interop
module S = Vale.X64.Machine_Semantics_s
module MB = LowStar.Monotonic.Buffer
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
friend Vale.X64.Memory
module IB = Vale.Interop.Base
let same_domain h m = Set.equal (IB.addrs_set (_ih h)) (Map.domain m)
let lemma_same_domains h m1 m2 = ()
let get_heap h = I.down_mem (_ih h)
let upd_heap h m = mi_heap_upd h m
//let lemma_upd_get_heap h = I.down_up_identity (_ih h)
let lemma_get_upd_heap h m = I.up_down_identity (_ih h) m
let lemma_heap_impl = ()
let lemma_heap_get_heap h = ()
let lemma_heap_taint h = ()
//let lemma_heap_upd_heap h mh mt = ()
[@"opaque_to_smt"]
let rec set_of_range (a:int) (n:nat) : Pure (Set.set int)
(requires True)
(ensures fun s -> (forall (i:int).{:pattern Set.mem i s} Set.mem i s <==> a <= i /\ i < a + n))
=
if n = 0 then Set.empty else Set.union (set_of_range a (n - 1)) (Set.singleton (a + n - 1))
let buffer_info_has_addr (bi:buffer_info) (a:int) =
let b = bi.bi_buffer in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
addr <= a /\ a < addr + len
let buffer_info_has_addr_opt (bi:option buffer_info) (a:int) =
match bi with
| None -> False
| Some bi -> buffer_info_has_addr bi a | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Memory.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.BufferViewStore.fsti.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Memory_Sems.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_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
}
] | {
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
h: Vale.Arch.HeapImpl.vale_heap ->
bs: FStar.Seq.Base.seq Vale.Arch.HeapImpl.buffer_info ->
n: Prims.nat{n <= FStar.Seq.Base.length bs}
-> Prims.GTot
((_: Prims.int -> FStar.Pervasives.Native.option (n: Prims.nat{n < FStar.Seq.Base.length bs})) *
(_: Vale.Arch.HeapImpl.heaplet_id -> FStar.Set.set Prims.int)) | Prims.GTot | [
"sometrivial"
] | [] | [
"Vale.Arch.HeapImpl.vale_heap",
"FStar.Seq.Base.seq",
"Vale.Arch.HeapImpl.buffer_info",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.Seq.Base.length",
"Prims.op_Equality",
"Prims.int",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Pervasives.Native.option",
"Prims.op_LessThan",
"Vale.Arch.HeapImpl.heaplet_id",
"FStar.Set.set",
"FStar.Pervasives.Native.None",
"FStar.Set.empty",
"Prims.bool",
"Prims.op_AmpAmp",
"Prims.op_Addition",
"FStar.Pervasives.Native.Some",
"Prims.op_Subtraction",
"FStar.Set.union",
"Vale.X64.Memory_Sems.set_of_range",
"LowStar.BufferView.Down.length",
"FStar.UInt8.t",
"Vale.Interop.Types.get_downview",
"Vale.Interop.Types.__proj__Buffer__item__src",
"Vale.Interop.Types.b8_preorder",
"Vale.Interop.Types.__proj__Buffer__item__writeable",
"Vale.Interop.Types.base_typ_as_type",
"Vale.Interop.Types.__proj__Buffer__item__bsrc",
"Vale.Def.Words_s.nat64",
"Vale.Interop.Heap_s.global_addrs_map",
"Vale.Arch.HeapImpl.__proj__Mkbuffer_info__item__bi_heaplet",
"Vale.Arch.HeapImpl.buffer",
"Vale.Arch.HeapImpl.__proj__Mkbuffer_info__item__bi_typ",
"Vale.Arch.HeapImpl.__proj__Mkbuffer_info__item__bi_buffer",
"FStar.Seq.Base.index",
"FStar.Pervasives.Native.tuple2",
"Vale.X64.Memory_Sems.make_owns_rec"
] | [
"recursion"
] | false | false | false | false | false | let rec make_owns_rec (h: vale_heap) (bs: Seq.seq buffer_info) (n: nat{n <= Seq.length bs})
: GTot ((int -> option (n: nat{n < Seq.length bs})) & (heaplet_id -> Set.set int)) =
| if n = 0
then ((fun _ -> None), (fun _ -> Set.empty))
else
let m0, s0 = make_owns_rec h bs (n - 1) in
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let s i = if i = hi then Set.union (s0 i) s_b else s0 i in
let m a = if addr <= a && a < addr + len then Some (n - 1) else m0 a in
(m, s) | false |
Vale.X64.Memory_Sems.fst | Vale.X64.Memory_Sems.lemma_create_heaplets | val lemma_create_heaplets (buffers:list buffer_info) (h1:vale_full_heap) : Lemma
(requires
mem_inv h1 /\
is_initial_heap h1.vf_layout h1.vf_heap /\
init_heaplets_req h1.vf_heap (list_to_seq buffers)
)
(ensures (
let h2 = create_heaplets buffers h1 in
let bs = list_to_seq buffers in
h1.vf_heap == h2.vf_heap /\
h1.vf_heaplets == h2.vf_heaplets /\
h1.vf_layout.vl_taint == h2.vf_layout.vl_taint /\
get_heaplet_id h1.vf_heap == None /\
layout_heaplets_initialized h2.vf_layout.vl_inner /\
layout_modifies_loc h2.vf_layout.vl_inner == loc_mutable_buffers buffers /\
layout_old_heap h2.vf_layout.vl_inner == h1.vf_heap /\
layout_buffers h2.vf_layout.vl_inner == bs /\
(forall (i:nat).{:pattern Seq.index bs i} i < Seq.length bs ==> (
let Mkbuffer_info t b hid _ mut = Seq.index bs i in
valid_layout_buffer_id t b h2.vf_layout (Some hid) false /\
valid_layout_buffer_id t b h2.vf_layout (Some hid) (mut = Mutable))) /\
(forall (i:heaplet_id).{:pattern Map16.sel h2.vf_heaplets i}
get_heaplet_id (Map16.sel h2.vf_heaplets i) == Some i /\
heaps_match bs h1.vf_layout.vl_taint h1.vf_heap (Map16.sel h2.vf_heaplets i) i) /\
mem_inv h2
)) | val lemma_create_heaplets (buffers:list buffer_info) (h1:vale_full_heap) : Lemma
(requires
mem_inv h1 /\
is_initial_heap h1.vf_layout h1.vf_heap /\
init_heaplets_req h1.vf_heap (list_to_seq buffers)
)
(ensures (
let h2 = create_heaplets buffers h1 in
let bs = list_to_seq buffers in
h1.vf_heap == h2.vf_heap /\
h1.vf_heaplets == h2.vf_heaplets /\
h1.vf_layout.vl_taint == h2.vf_layout.vl_taint /\
get_heaplet_id h1.vf_heap == None /\
layout_heaplets_initialized h2.vf_layout.vl_inner /\
layout_modifies_loc h2.vf_layout.vl_inner == loc_mutable_buffers buffers /\
layout_old_heap h2.vf_layout.vl_inner == h1.vf_heap /\
layout_buffers h2.vf_layout.vl_inner == bs /\
(forall (i:nat).{:pattern Seq.index bs i} i < Seq.length bs ==> (
let Mkbuffer_info t b hid _ mut = Seq.index bs i in
valid_layout_buffer_id t b h2.vf_layout (Some hid) false /\
valid_layout_buffer_id t b h2.vf_layout (Some hid) (mut = Mutable))) /\
(forall (i:heaplet_id).{:pattern Map16.sel h2.vf_heaplets i}
get_heaplet_id (Map16.sel h2.vf_heaplets i) == Some i /\
heaps_match bs h1.vf_layout.vl_taint h1.vf_heap (Map16.sel h2.vf_heaplets i) i) /\
mem_inv h2
)) | let lemma_create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let h2 = create_heaplets buffers h1 in
assert (h2.vf_layout.vl_inner.vl_buffers == bs); // REVIEW: why is this necessary, even with extra ifuel?
lemma_make_owns h1.vf_heap bs (Seq.length bs);
lemma_loc_mutable_buffers buffers;
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
() | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory_Sems.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 4,
"end_line": 186,
"start_col": 0,
"start_line": 179
} | module Vale.X64.Memory_Sems
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.Def.Words_s
module I = Vale.Interop
module S = Vale.X64.Machine_Semantics_s
module MB = LowStar.Monotonic.Buffer
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
friend Vale.X64.Memory
module IB = Vale.Interop.Base
let same_domain h m = Set.equal (IB.addrs_set (_ih h)) (Map.domain m)
let lemma_same_domains h m1 m2 = ()
let get_heap h = I.down_mem (_ih h)
let upd_heap h m = mi_heap_upd h m
//let lemma_upd_get_heap h = I.down_up_identity (_ih h)
let lemma_get_upd_heap h m = I.up_down_identity (_ih h) m
let lemma_heap_impl = ()
let lemma_heap_get_heap h = ()
let lemma_heap_taint h = ()
//let lemma_heap_upd_heap h mh mt = ()
[@"opaque_to_smt"]
let rec set_of_range (a:int) (n:nat) : Pure (Set.set int)
(requires True)
(ensures fun s -> (forall (i:int).{:pattern Set.mem i s} Set.mem i s <==> a <= i /\ i < a + n))
=
if n = 0 then Set.empty else Set.union (set_of_range a (n - 1)) (Set.singleton (a + n - 1))
let buffer_info_has_addr (bi:buffer_info) (a:int) =
let b = bi.bi_buffer in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
addr <= a /\ a < addr + len
let buffer_info_has_addr_opt (bi:option buffer_info) (a:int) =
match bi with
| None -> False
| Some bi -> buffer_info_has_addr bi a
#set-options "--z3rlimit 100"
let rec make_owns_rec (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
if n = 0 then ((fun _ -> None), (fun _ -> Set.empty)) else
let (m0, s0) = make_owns_rec h bs (n - 1) in
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let s i = if i = hi then Set.union (s0 i) s_b else s0 i in
let m a = if addr <= a && a < addr + len then Some (n - 1) else m0 a in
(m, s)
[@"opaque_to_smt"]
let make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
make_owns_rec h bs n
let rec lemma_make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n <= Seq.length bs /\
(forall (i:nat).{:pattern Seq.index bs i} i < Seq.length bs ==> buffer_readable h (Seq.index bs i).bi_buffer) /\
(forall (i1 i2:nat).{:pattern (Seq.index bs i1); (Seq.index bs i2)}
i1 < Seq.length bs /\ i2 < Seq.length bs ==> buffer_info_disjoint (Seq.index bs i1) (Seq.index bs i2))
)
(ensures (
let (m, s) = make_owns h bs n in
(forall (i:heaplet_id) (a:int).{:pattern Set.mem a (s i)}
(Set.mem a (s i) <==> Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (m a) == Some i) /\
(Set.mem a (s i) ==> buffer_info_has_addr_opt (Option.mapTot (fun n -> Seq.index bs n) (m a)) a) /\
(Set.mem a (s i) ==> Set.mem a (Map.domain h.mh))
) /\
(forall (k:nat) (a:int).{:pattern Set.mem a (s (Seq.index bs k).bi_heaplet)}
k < n /\ buffer_info_has_addr (Seq.index bs k) a ==> Set.mem a (s (Seq.index bs k).bi_heaplet))
))
=
reveal_opaque (`%make_owns) make_owns;
if n = 0 then () else
let _ = make_owns h bs (n - 1) in
let (m, s) = make_owns h bs n in
lemma_make_owns h bs (n - 1);
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let lem1 (a:int) : Lemma
(requires Set.mem a s_b)
(ensures Set.mem a (Map.domain h.mh))
[SMTPat (Set.mem a (Map.domain h.mh))]
=
I.addrs_set_mem h.ih b a
in
let lem2 (i:heaplet_id) (a:int) : Lemma
(requires i =!= hi /\ Set.mem a (Set.intersect s_b (s i)))
(ensures False)
[SMTPat (Set.mem a (s i))]
=
reveal_opaque (`%addr_map_pred) addr_map_pred
in
()
#push-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_loc_mutable_buffers_rec (l:list buffer_info) (s:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n + List.length l == Seq.length s /\
list_to_seq_post l s n
)
(ensures (
let modloc = loc_mutable_buffers l in
forall (i:nat).{:pattern Seq.index s i} n <= i /\ i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes modloc (loc_buffer bi.bi_buffer))
))
(decreases l)
=
match l with
| [] -> ()
| h::t -> lemma_loc_mutable_buffers_rec t s (n + 1)
#pop-options
let lemma_loc_mutable_buffers (l:list buffer_info) : Lemma
(ensures (
let s = list_to_seq l in
forall (i:nat).{:pattern Seq.index s i} i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes (loc_mutable_buffers l) (loc_buffer bi.bi_buffer))
))
=
lemma_list_to_seq l;
lemma_loc_mutable_buffers_rec l (list_to_seq l) 0
let create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let modloc = loc_mutable_buffers buffers in
let layout1 = h1.vf_layout in
let layin1 = layout1.vl_inner in
let (hmap, hsets) = make_owns h1.vf_heap bs (Seq.length bs) in
let hmap a = Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (hmap a) in
let l = {
vl_heaplets_initialized = true;
vl_heaplet_map = hmap;
vl_heaplet_sets = hsets;
vl_old_heap = h1.vf_heap;
vl_buffers = bs;
vl_mod_loc = modloc;
} in
let layout2 = {layout1 with vl_inner = l} in
let h2 = {
vf_layout = layout2;
vf_heap = h1.vf_heap;
vf_heaplets = h1.vf_heaplets;
} in
h2 | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Memory.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.BufferViewStore.fsti.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Memory_Sems.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_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
}
] | {
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | buffers: Prims.list Vale.Arch.HeapImpl.buffer_info -> h1: Vale.Arch.HeapImpl.vale_full_heap
-> FStar.Pervasives.Lemma
(requires
Vale.X64.Memory.mem_inv h1 /\
Vale.X64.Memory.is_initial_heap (Mkvale_full_heap?.vf_layout h1)
(Mkvale_full_heap?.vf_heap h1) /\
Vale.X64.Memory.init_heaplets_req (Mkvale_full_heap?.vf_heap h1)
(Vale.Lib.Seqs.list_to_seq buffers))
(ensures
(let h2 = Vale.X64.Memory_Sems.create_heaplets buffers h1 in
let bs = Vale.Lib.Seqs.list_to_seq buffers in
Mkvale_full_heap?.vf_heap h1 == Mkvale_full_heap?.vf_heap h2 /\
Mkvale_full_heap?.vf_heaplets h1 == Mkvale_full_heap?.vf_heaplets h2 /\
Mkvale_heap_layout?.vl_taint (Mkvale_full_heap?.vf_layout h1) ==
Mkvale_heap_layout?.vl_taint (Mkvale_full_heap?.vf_layout h2) /\
Vale.X64.Memory.get_heaplet_id (Mkvale_full_heap?.vf_heap h1) ==
FStar.Pervasives.Native.None /\
Vale.X64.Memory.layout_heaplets_initialized (Mkvale_heap_layout?.vl_inner (Mkvale_full_heap?.vf_layout
h2)) /\
Vale.X64.Memory.layout_modifies_loc (Mkvale_heap_layout?.vl_inner (Mkvale_full_heap?.vf_layout
h2)) ==
Vale.X64.Memory.loc_mutable_buffers buffers /\
Vale.X64.Memory.layout_old_heap (Mkvale_heap_layout?.vl_inner (Mkvale_full_heap?.vf_layout
h2)) ==
Mkvale_full_heap?.vf_heap h1 /\
Vale.X64.Memory.layout_buffers (Mkvale_heap_layout?.vl_inner (Mkvale_full_heap?.vf_layout h2
)) ==
bs /\
(forall (i: Prims.nat). {:pattern FStar.Seq.Base.index bs i}
i < FStar.Seq.Base.length bs ==>
(let _ = FStar.Seq.Base.index bs i in
(let
{ bi_typ = t ; bi_buffer = b ; bi_heaplet = hid ; bi_taint = _ ; bi_mutable = mut
} =
_
in
Vale.X64.Memory.valid_layout_buffer_id t
b
(Mkvale_full_heap?.vf_layout h2)
(FStar.Pervasives.Native.Some hid)
false /\
Vale.X64.Memory.valid_layout_buffer_id t
b
(Mkvale_full_heap?.vf_layout h2)
(FStar.Pervasives.Native.Some hid)
(mut = Vale.Arch.HeapImpl.Mutable))
<:
Prims.logical)) /\
(forall (i: Vale.Arch.HeapImpl.heaplet_id).
{:pattern Vale.Lib.Map16.sel (Mkvale_full_heap?.vf_heaplets h2) i}
Vale.X64.Memory.get_heaplet_id (Vale.Lib.Map16.sel (Mkvale_full_heap?.vf_heaplets h2)
i) ==
FStar.Pervasives.Native.Some i /\
Vale.X64.Memory.heaps_match bs
(Mkvale_heap_layout?.vl_taint (Mkvale_full_heap?.vf_layout h1))
(Mkvale_full_heap?.vf_heap h1)
(Vale.Lib.Map16.sel (Mkvale_full_heap?.vf_heaplets h2) i)
i) /\ Vale.X64.Memory.mem_inv h2)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.list",
"Vale.Arch.HeapImpl.buffer_info",
"Vale.Arch.HeapImpl.vale_full_heap",
"Prims.unit",
"FStar.Pervasives.reveal_opaque",
"Vale.Arch.HeapTypes_s.base_typ",
"Vale.X64.Memory.buffer",
"Vale.Arch.HeapImpl.vale_heap_layout",
"FStar.Pervasives.Native.option",
"Vale.Arch.HeapImpl.heaplet_id",
"Prims.bool",
"Vale.Def.Prop_s.prop0",
"Vale.X64.Memory.valid_layout_buffer_id",
"Vale.X64.Memory_Sems.lemma_loc_mutable_buffers",
"Vale.X64.Memory_Sems.lemma_make_owns",
"Vale.Arch.HeapImpl.__proj__Mkvale_full_heap__item__vf_heap",
"FStar.Seq.Base.length",
"Prims._assert",
"Prims.eq2",
"FStar.Seq.Base.seq",
"Vale.Arch.HeapImpl.__proj__Mkvale_heap_layout_inner__item__vl_buffers",
"Vale.Arch.HeapImpl.__proj__Mkvale_heap_layout__item__vl_inner",
"Vale.Arch.HeapImpl.__proj__Mkvale_full_heap__item__vf_layout",
"Vale.X64.Memory_Sems.create_heaplets",
"Vale.Lib.Seqs.list_to_seq"
] | [] | true | false | true | false | false | let lemma_create_heaplets buffers h1 =
| let bs = list_to_seq buffers in
let h2 = create_heaplets buffers h1 in
assert (h2.vf_layout.vl_inner.vl_buffers == bs);
lemma_make_owns h1.vf_heap bs (Seq.length bs);
lemma_loc_mutable_buffers buffers;
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
() | false |
Vale.X64.Memory_Sems.fst | Vale.X64.Memory_Sems.heap_shift | val heap_shift (m1 m2:S.machine_heap) (base:int) (n:nat) : Lemma
(requires (forall i. 0 <= i /\ i < n ==> m1.[base + i] == m2.[base + i]))
(ensures (forall i. {:pattern (m1.[i])} base <= i /\ i < base + n ==> m1.[i] == m2.[i])) | val heap_shift (m1 m2:S.machine_heap) (base:int) (n:nat) : Lemma
(requires (forall i. 0 <= i /\ i < n ==> m1.[base + i] == m2.[base + i]))
(ensures (forall i. {:pattern (m1.[i])} base <= i /\ i < base + n ==> m1.[i] == m2.[i])) | let heap_shift m1 m2 base n =
assert (forall i. base <= i /\ i < base + n ==>
m1.[base + (i - base)] == m2.[base + (i - base)]) | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory_Sems.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 53,
"end_line": 201,
"start_col": 0,
"start_line": 199
} | module Vale.X64.Memory_Sems
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.Def.Words_s
module I = Vale.Interop
module S = Vale.X64.Machine_Semantics_s
module MB = LowStar.Monotonic.Buffer
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
friend Vale.X64.Memory
module IB = Vale.Interop.Base
let same_domain h m = Set.equal (IB.addrs_set (_ih h)) (Map.domain m)
let lemma_same_domains h m1 m2 = ()
let get_heap h = I.down_mem (_ih h)
let upd_heap h m = mi_heap_upd h m
//let lemma_upd_get_heap h = I.down_up_identity (_ih h)
let lemma_get_upd_heap h m = I.up_down_identity (_ih h) m
let lemma_heap_impl = ()
let lemma_heap_get_heap h = ()
let lemma_heap_taint h = ()
//let lemma_heap_upd_heap h mh mt = ()
[@"opaque_to_smt"]
let rec set_of_range (a:int) (n:nat) : Pure (Set.set int)
(requires True)
(ensures fun s -> (forall (i:int).{:pattern Set.mem i s} Set.mem i s <==> a <= i /\ i < a + n))
=
if n = 0 then Set.empty else Set.union (set_of_range a (n - 1)) (Set.singleton (a + n - 1))
let buffer_info_has_addr (bi:buffer_info) (a:int) =
let b = bi.bi_buffer in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
addr <= a /\ a < addr + len
let buffer_info_has_addr_opt (bi:option buffer_info) (a:int) =
match bi with
| None -> False
| Some bi -> buffer_info_has_addr bi a
#set-options "--z3rlimit 100"
let rec make_owns_rec (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
if n = 0 then ((fun _ -> None), (fun _ -> Set.empty)) else
let (m0, s0) = make_owns_rec h bs (n - 1) in
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let s i = if i = hi then Set.union (s0 i) s_b else s0 i in
let m a = if addr <= a && a < addr + len then Some (n - 1) else m0 a in
(m, s)
[@"opaque_to_smt"]
let make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
make_owns_rec h bs n
let rec lemma_make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n <= Seq.length bs /\
(forall (i:nat).{:pattern Seq.index bs i} i < Seq.length bs ==> buffer_readable h (Seq.index bs i).bi_buffer) /\
(forall (i1 i2:nat).{:pattern (Seq.index bs i1); (Seq.index bs i2)}
i1 < Seq.length bs /\ i2 < Seq.length bs ==> buffer_info_disjoint (Seq.index bs i1) (Seq.index bs i2))
)
(ensures (
let (m, s) = make_owns h bs n in
(forall (i:heaplet_id) (a:int).{:pattern Set.mem a (s i)}
(Set.mem a (s i) <==> Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (m a) == Some i) /\
(Set.mem a (s i) ==> buffer_info_has_addr_opt (Option.mapTot (fun n -> Seq.index bs n) (m a)) a) /\
(Set.mem a (s i) ==> Set.mem a (Map.domain h.mh))
) /\
(forall (k:nat) (a:int).{:pattern Set.mem a (s (Seq.index bs k).bi_heaplet)}
k < n /\ buffer_info_has_addr (Seq.index bs k) a ==> Set.mem a (s (Seq.index bs k).bi_heaplet))
))
=
reveal_opaque (`%make_owns) make_owns;
if n = 0 then () else
let _ = make_owns h bs (n - 1) in
let (m, s) = make_owns h bs n in
lemma_make_owns h bs (n - 1);
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let lem1 (a:int) : Lemma
(requires Set.mem a s_b)
(ensures Set.mem a (Map.domain h.mh))
[SMTPat (Set.mem a (Map.domain h.mh))]
=
I.addrs_set_mem h.ih b a
in
let lem2 (i:heaplet_id) (a:int) : Lemma
(requires i =!= hi /\ Set.mem a (Set.intersect s_b (s i)))
(ensures False)
[SMTPat (Set.mem a (s i))]
=
reveal_opaque (`%addr_map_pred) addr_map_pred
in
()
#push-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_loc_mutable_buffers_rec (l:list buffer_info) (s:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n + List.length l == Seq.length s /\
list_to_seq_post l s n
)
(ensures (
let modloc = loc_mutable_buffers l in
forall (i:nat).{:pattern Seq.index s i} n <= i /\ i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes modloc (loc_buffer bi.bi_buffer))
))
(decreases l)
=
match l with
| [] -> ()
| h::t -> lemma_loc_mutable_buffers_rec t s (n + 1)
#pop-options
let lemma_loc_mutable_buffers (l:list buffer_info) : Lemma
(ensures (
let s = list_to_seq l in
forall (i:nat).{:pattern Seq.index s i} i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes (loc_mutable_buffers l) (loc_buffer bi.bi_buffer))
))
=
lemma_list_to_seq l;
lemma_loc_mutable_buffers_rec l (list_to_seq l) 0
let create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let modloc = loc_mutable_buffers buffers in
let layout1 = h1.vf_layout in
let layin1 = layout1.vl_inner in
let (hmap, hsets) = make_owns h1.vf_heap bs (Seq.length bs) in
let hmap a = Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (hmap a) in
let l = {
vl_heaplets_initialized = true;
vl_heaplet_map = hmap;
vl_heaplet_sets = hsets;
vl_old_heap = h1.vf_heap;
vl_buffers = bs;
vl_mod_loc = modloc;
} in
let layout2 = {layout1 with vl_inner = l} in
let h2 = {
vf_layout = layout2;
vf_heap = h1.vf_heap;
vf_heaplets = h1.vf_heaplets;
} in
h2
let lemma_create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let h2 = create_heaplets buffers h1 in
assert (h2.vf_layout.vl_inner.vl_buffers == bs); // REVIEW: why is this necessary, even with extra ifuel?
lemma_make_owns h1.vf_heap bs (Seq.length bs);
lemma_loc_mutable_buffers buffers;
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
let destroy_heaplets h1 =
h1
let lemma_destroy_heaplets h1 =
()
val heap_shift (m1 m2:S.machine_heap) (base:int) (n:nat) : Lemma
(requires (forall i. 0 <= i /\ i < n ==> m1.[base + i] == m2.[base + i]))
(ensures (forall i. {:pattern (m1.[i])} base <= i /\ i < base + n ==> m1.[i] == m2.[i])) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Memory.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.BufferViewStore.fsti.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Memory_Sems.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_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
}
] | {
"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": "boxwrap",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
m1: Vale.Arch.MachineHeap_s.machine_heap ->
m2: Vale.Arch.MachineHeap_s.machine_heap ->
base: Prims.int ->
n: Prims.nat
-> FStar.Pervasives.Lemma
(requires forall (i: Prims.int). 0 <= i /\ i < n ==> m1.[ base + i ] == m2.[ base + i ])
(ensures
forall (i: Prims.int). {:pattern m1.[ i ]}
base <= i /\ i < base + n ==> m1.[ i ] == m2.[ i ]) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Arch.MachineHeap_s.machine_heap",
"Prims.int",
"Prims.nat",
"Prims._assert",
"Prims.l_Forall",
"Prims.l_imp",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"Prims.op_Addition",
"Prims.eq2",
"Vale.Def.Types_s.nat8",
"Vale.X64.Memory.op_String_Access",
"Prims.op_Subtraction",
"Prims.unit"
] | [] | false | false | true | false | false | let heap_shift m1 m2 base n =
| assert (forall i. base <= i /\ i < base + n ==> m1.[ base + (i - base) ] == m2.[ base + (i - base) ]
) | false |
Vale.X64.Memory_Sems.fst | Vale.X64.Memory_Sems.length_up64 | val length_up64 (b: buffer64) (h: vale_heap) (k: nat{k < buffer_length b}) (i: nat{i < 8})
: Lemma (scale8 k + i <= DV.length (get_downview b.bsrc)) | val length_up64 (b: buffer64) (h: vale_heap) (k: nat{k < buffer_length b}) (i: nat{i < 8})
: Lemma (scale8 k + i <= DV.length (get_downview b.bsrc)) | let length_up64 (b:buffer64) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 8}) : Lemma
(scale8 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint64_view in
UV.length_eq vb | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory_Sems.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 17,
"end_line": 231,
"start_col": 0,
"start_line": 228
} | module Vale.X64.Memory_Sems
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.Def.Words_s
module I = Vale.Interop
module S = Vale.X64.Machine_Semantics_s
module MB = LowStar.Monotonic.Buffer
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
friend Vale.X64.Memory
module IB = Vale.Interop.Base
let same_domain h m = Set.equal (IB.addrs_set (_ih h)) (Map.domain m)
let lemma_same_domains h m1 m2 = ()
let get_heap h = I.down_mem (_ih h)
let upd_heap h m = mi_heap_upd h m
//let lemma_upd_get_heap h = I.down_up_identity (_ih h)
let lemma_get_upd_heap h m = I.up_down_identity (_ih h) m
let lemma_heap_impl = ()
let lemma_heap_get_heap h = ()
let lemma_heap_taint h = ()
//let lemma_heap_upd_heap h mh mt = ()
[@"opaque_to_smt"]
let rec set_of_range (a:int) (n:nat) : Pure (Set.set int)
(requires True)
(ensures fun s -> (forall (i:int).{:pattern Set.mem i s} Set.mem i s <==> a <= i /\ i < a + n))
=
if n = 0 then Set.empty else Set.union (set_of_range a (n - 1)) (Set.singleton (a + n - 1))
let buffer_info_has_addr (bi:buffer_info) (a:int) =
let b = bi.bi_buffer in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
addr <= a /\ a < addr + len
let buffer_info_has_addr_opt (bi:option buffer_info) (a:int) =
match bi with
| None -> False
| Some bi -> buffer_info_has_addr bi a
#set-options "--z3rlimit 100"
let rec make_owns_rec (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
if n = 0 then ((fun _ -> None), (fun _ -> Set.empty)) else
let (m0, s0) = make_owns_rec h bs (n - 1) in
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let s i = if i = hi then Set.union (s0 i) s_b else s0 i in
let m a = if addr <= a && a < addr + len then Some (n - 1) else m0 a in
(m, s)
[@"opaque_to_smt"]
let make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
make_owns_rec h bs n
let rec lemma_make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n <= Seq.length bs /\
(forall (i:nat).{:pattern Seq.index bs i} i < Seq.length bs ==> buffer_readable h (Seq.index bs i).bi_buffer) /\
(forall (i1 i2:nat).{:pattern (Seq.index bs i1); (Seq.index bs i2)}
i1 < Seq.length bs /\ i2 < Seq.length bs ==> buffer_info_disjoint (Seq.index bs i1) (Seq.index bs i2))
)
(ensures (
let (m, s) = make_owns h bs n in
(forall (i:heaplet_id) (a:int).{:pattern Set.mem a (s i)}
(Set.mem a (s i) <==> Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (m a) == Some i) /\
(Set.mem a (s i) ==> buffer_info_has_addr_opt (Option.mapTot (fun n -> Seq.index bs n) (m a)) a) /\
(Set.mem a (s i) ==> Set.mem a (Map.domain h.mh))
) /\
(forall (k:nat) (a:int).{:pattern Set.mem a (s (Seq.index bs k).bi_heaplet)}
k < n /\ buffer_info_has_addr (Seq.index bs k) a ==> Set.mem a (s (Seq.index bs k).bi_heaplet))
))
=
reveal_opaque (`%make_owns) make_owns;
if n = 0 then () else
let _ = make_owns h bs (n - 1) in
let (m, s) = make_owns h bs n in
lemma_make_owns h bs (n - 1);
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let lem1 (a:int) : Lemma
(requires Set.mem a s_b)
(ensures Set.mem a (Map.domain h.mh))
[SMTPat (Set.mem a (Map.domain h.mh))]
=
I.addrs_set_mem h.ih b a
in
let lem2 (i:heaplet_id) (a:int) : Lemma
(requires i =!= hi /\ Set.mem a (Set.intersect s_b (s i)))
(ensures False)
[SMTPat (Set.mem a (s i))]
=
reveal_opaque (`%addr_map_pred) addr_map_pred
in
()
#push-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_loc_mutable_buffers_rec (l:list buffer_info) (s:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n + List.length l == Seq.length s /\
list_to_seq_post l s n
)
(ensures (
let modloc = loc_mutable_buffers l in
forall (i:nat).{:pattern Seq.index s i} n <= i /\ i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes modloc (loc_buffer bi.bi_buffer))
))
(decreases l)
=
match l with
| [] -> ()
| h::t -> lemma_loc_mutable_buffers_rec t s (n + 1)
#pop-options
let lemma_loc_mutable_buffers (l:list buffer_info) : Lemma
(ensures (
let s = list_to_seq l in
forall (i:nat).{:pattern Seq.index s i} i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes (loc_mutable_buffers l) (loc_buffer bi.bi_buffer))
))
=
lemma_list_to_seq l;
lemma_loc_mutable_buffers_rec l (list_to_seq l) 0
let create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let modloc = loc_mutable_buffers buffers in
let layout1 = h1.vf_layout in
let layin1 = layout1.vl_inner in
let (hmap, hsets) = make_owns h1.vf_heap bs (Seq.length bs) in
let hmap a = Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (hmap a) in
let l = {
vl_heaplets_initialized = true;
vl_heaplet_map = hmap;
vl_heaplet_sets = hsets;
vl_old_heap = h1.vf_heap;
vl_buffers = bs;
vl_mod_loc = modloc;
} in
let layout2 = {layout1 with vl_inner = l} in
let h2 = {
vf_layout = layout2;
vf_heap = h1.vf_heap;
vf_heaplets = h1.vf_heaplets;
} in
h2
let lemma_create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let h2 = create_heaplets buffers h1 in
assert (h2.vf_layout.vl_inner.vl_buffers == bs); // REVIEW: why is this necessary, even with extra ifuel?
lemma_make_owns h1.vf_heap bs (Seq.length bs);
lemma_loc_mutable_buffers buffers;
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
let destroy_heaplets h1 =
h1
let lemma_destroy_heaplets h1 =
()
val heap_shift (m1 m2:S.machine_heap) (base:int) (n:nat) : Lemma
(requires (forall i. 0 <= i /\ i < n ==> m1.[base + i] == m2.[base + i]))
(ensures (forall i. {:pattern (m1.[i])} base <= i /\ i < base + n ==> m1.[i] == m2.[i]))
#push-options "--smtencoding.l_arith_repr boxwrap"
let heap_shift m1 m2 base n =
assert (forall i. base <= i /\ i < base + n ==>
m1.[base + (i - base)] == m2.[base + (i - base)])
#pop-options
val same_mem_eq_slices64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 8 + 8 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8)))
let same_mem_eq_slices64 b i v k h1 h2 mem1 mem2 =
let t = TUInt64 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Memory.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.BufferViewStore.fsti.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Memory_Sems.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_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
}
] | {
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
b: Vale.X64.Memory.buffer64 ->
h: Vale.Arch.HeapImpl.vale_heap ->
k: Prims.nat{k < Vale.X64.Memory.buffer_length b} ->
i: Prims.nat{i < 8}
-> FStar.Pervasives.Lemma
(ensures
Vale.X64.Memory.scale8 k + i <=
LowStar.BufferView.Down.length (Vale.Interop.Types.get_downview (Buffer?.bsrc b))) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.X64.Memory.buffer64",
"Vale.Arch.HeapImpl.vale_heap",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Vale.X64.Memory.buffer_length",
"Vale.X64.Memory.vuint64",
"LowStar.BufferView.Up.length_eq",
"FStar.UInt64.t",
"LowStar.BufferView.Up.buffer",
"LowStar.BufferView.Up.mk_buffer",
"FStar.UInt8.t",
"Vale.Interop.Types.get_downview",
"Vale.Interop.Types.__proj__Buffer__item__src",
"Vale.Interop.Types.b8_preorder",
"Vale.Interop.Types.__proj__Buffer__item__writeable",
"Vale.Interop.Types.base_typ_as_type",
"Vale.Interop.Types.__proj__Buffer__item__bsrc",
"Vale.X64.Memory.uint64_view",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition",
"Vale.X64.Memory.scale8",
"LowStar.BufferView.Down.length",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let length_up64 (b: buffer64) (h: vale_heap) (k: nat{k < buffer_length b}) (i: nat{i < 8})
: Lemma (scale8 k + i <= DV.length (get_downview b.bsrc)) =
| let vb = UV.mk_buffer (get_downview b.bsrc) uint64_view in
UV.length_eq vb | false |
Vale.X64.Memory_Sems.fst | Vale.X64.Memory_Sems.lemma_loc_mutable_buffers_rec | val lemma_loc_mutable_buffers_rec (l: list buffer_info) (s: Seq.seq buffer_info) (n: nat)
: Lemma (requires n + List.length l == Seq.length s /\ list_to_seq_post l s n)
(ensures
(let modloc = loc_mutable_buffers l in
forall (i: nat). {:pattern Seq.index s i}
n <= i /\ i < Seq.length s ==>
(let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes modloc (loc_buffer bi.bi_buffer))))
(decreases l) | val lemma_loc_mutable_buffers_rec (l: list buffer_info) (s: Seq.seq buffer_info) (n: nat)
: Lemma (requires n + List.length l == Seq.length s /\ list_to_seq_post l s n)
(ensures
(let modloc = loc_mutable_buffers l in
forall (i: nat). {:pattern Seq.index s i}
n <= i /\ i < Seq.length s ==>
(let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes modloc (loc_buffer bi.bi_buffer))))
(decreases l) | let rec lemma_loc_mutable_buffers_rec (l:list buffer_info) (s:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n + List.length l == Seq.length s /\
list_to_seq_post l s n
)
(ensures (
let modloc = loc_mutable_buffers l in
forall (i:nat).{:pattern Seq.index s i} n <= i /\ i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes modloc (loc_buffer bi.bi_buffer))
))
(decreases l)
=
match l with
| [] -> ()
| h::t -> lemma_loc_mutable_buffers_rec t s (n + 1) | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory_Sems.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 53,
"end_line": 142,
"start_col": 0,
"start_line": 127
} | module Vale.X64.Memory_Sems
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.Def.Words_s
module I = Vale.Interop
module S = Vale.X64.Machine_Semantics_s
module MB = LowStar.Monotonic.Buffer
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
friend Vale.X64.Memory
module IB = Vale.Interop.Base
let same_domain h m = Set.equal (IB.addrs_set (_ih h)) (Map.domain m)
let lemma_same_domains h m1 m2 = ()
let get_heap h = I.down_mem (_ih h)
let upd_heap h m = mi_heap_upd h m
//let lemma_upd_get_heap h = I.down_up_identity (_ih h)
let lemma_get_upd_heap h m = I.up_down_identity (_ih h) m
let lemma_heap_impl = ()
let lemma_heap_get_heap h = ()
let lemma_heap_taint h = ()
//let lemma_heap_upd_heap h mh mt = ()
[@"opaque_to_smt"]
let rec set_of_range (a:int) (n:nat) : Pure (Set.set int)
(requires True)
(ensures fun s -> (forall (i:int).{:pattern Set.mem i s} Set.mem i s <==> a <= i /\ i < a + n))
=
if n = 0 then Set.empty else Set.union (set_of_range a (n - 1)) (Set.singleton (a + n - 1))
let buffer_info_has_addr (bi:buffer_info) (a:int) =
let b = bi.bi_buffer in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
addr <= a /\ a < addr + len
let buffer_info_has_addr_opt (bi:option buffer_info) (a:int) =
match bi with
| None -> False
| Some bi -> buffer_info_has_addr bi a
#set-options "--z3rlimit 100"
let rec make_owns_rec (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
if n = 0 then ((fun _ -> None), (fun _ -> Set.empty)) else
let (m0, s0) = make_owns_rec h bs (n - 1) in
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let s i = if i = hi then Set.union (s0 i) s_b else s0 i in
let m a = if addr <= a && a < addr + len then Some (n - 1) else m0 a in
(m, s)
[@"opaque_to_smt"]
let make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
make_owns_rec h bs n
let rec lemma_make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n <= Seq.length bs /\
(forall (i:nat).{:pattern Seq.index bs i} i < Seq.length bs ==> buffer_readable h (Seq.index bs i).bi_buffer) /\
(forall (i1 i2:nat).{:pattern (Seq.index bs i1); (Seq.index bs i2)}
i1 < Seq.length bs /\ i2 < Seq.length bs ==> buffer_info_disjoint (Seq.index bs i1) (Seq.index bs i2))
)
(ensures (
let (m, s) = make_owns h bs n in
(forall (i:heaplet_id) (a:int).{:pattern Set.mem a (s i)}
(Set.mem a (s i) <==> Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (m a) == Some i) /\
(Set.mem a (s i) ==> buffer_info_has_addr_opt (Option.mapTot (fun n -> Seq.index bs n) (m a)) a) /\
(Set.mem a (s i) ==> Set.mem a (Map.domain h.mh))
) /\
(forall (k:nat) (a:int).{:pattern Set.mem a (s (Seq.index bs k).bi_heaplet)}
k < n /\ buffer_info_has_addr (Seq.index bs k) a ==> Set.mem a (s (Seq.index bs k).bi_heaplet))
))
=
reveal_opaque (`%make_owns) make_owns;
if n = 0 then () else
let _ = make_owns h bs (n - 1) in
let (m, s) = make_owns h bs n in
lemma_make_owns h bs (n - 1);
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let lem1 (a:int) : Lemma
(requires Set.mem a s_b)
(ensures Set.mem a (Map.domain h.mh))
[SMTPat (Set.mem a (Map.domain h.mh))]
=
I.addrs_set_mem h.ih b a
in
let lem2 (i:heaplet_id) (a:int) : Lemma
(requires i =!= hi /\ Set.mem a (Set.intersect s_b (s i)))
(ensures False)
[SMTPat (Set.mem a (s i))]
=
reveal_opaque (`%addr_map_pred) addr_map_pred
in
() | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Memory.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.BufferViewStore.fsti.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Memory_Sems.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 1,
"initial_ifuel": 2,
"max_fuel": 1,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
l: Prims.list Vale.Arch.HeapImpl.buffer_info ->
s: FStar.Seq.Base.seq Vale.Arch.HeapImpl.buffer_info ->
n: Prims.nat
-> FStar.Pervasives.Lemma
(requires
n + FStar.List.Tot.Base.length l == FStar.Seq.Base.length s /\
Vale.Lib.Seqs.list_to_seq_post l s n)
(ensures
(let modloc = Vale.X64.Memory.loc_mutable_buffers l in
forall (i: Prims.nat). {:pattern FStar.Seq.Base.index s i}
n <= i /\ i < FStar.Seq.Base.length s ==>
(let bi = FStar.Seq.Base.index s i in
Mkbuffer_info?.bi_mutable bi == Vale.Arch.HeapImpl.Mutable ==>
Vale.X64.Memory.loc_includes modloc
(Vale.X64.Memory.loc_buffer (Mkbuffer_info?.bi_buffer bi)))))
(decreases l) | FStar.Pervasives.Lemma | [
"lemma",
""
] | [] | [
"Prims.list",
"Vale.Arch.HeapImpl.buffer_info",
"FStar.Seq.Base.seq",
"Prims.nat",
"Vale.X64.Memory_Sems.lemma_loc_mutable_buffers_rec",
"Prims.op_Addition",
"Prims.unit",
"Prims.l_and",
"Prims.eq2",
"Prims.int",
"FStar.List.Tot.Base.length",
"FStar.Seq.Base.length",
"Vale.Lib.Seqs.list_to_seq_post",
"Prims.squash",
"Prims.l_Forall",
"Prims.l_imp",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"Vale.Arch.HeapImpl.mutability",
"Vale.Arch.HeapImpl.__proj__Mkbuffer_info__item__bi_mutable",
"Vale.Arch.HeapImpl.Mutable",
"Vale.X64.Memory.loc_includes",
"Vale.X64.Memory.loc_buffer",
"Vale.Arch.HeapImpl.__proj__Mkbuffer_info__item__bi_typ",
"Vale.Arch.HeapImpl.__proj__Mkbuffer_info__item__bi_buffer",
"FStar.Seq.Base.index",
"Vale.X64.Memory.loc",
"Vale.X64.Memory.loc_mutable_buffers",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [
"recursion"
] | false | false | true | false | false | let rec lemma_loc_mutable_buffers_rec (l: list buffer_info) (s: Seq.seq buffer_info) (n: nat)
: Lemma (requires n + List.length l == Seq.length s /\ list_to_seq_post l s n)
(ensures
(let modloc = loc_mutable_buffers l in
forall (i: nat). {:pattern Seq.index s i}
n <= i /\ i < Seq.length s ==>
(let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes modloc (loc_buffer bi.bi_buffer))))
(decreases l) =
| match l with
| [] -> ()
| h :: t -> lemma_loc_mutable_buffers_rec t s (n + 1) | false |
Vale.X64.Memory_Sems.fst | Vale.X64.Memory_Sems.written_buffer_down64 | val written_buffer_down64
(b: buffer64{buffer_writeable b})
(i: nat{i < buffer_length b})
(v: nat64)
(h: vale_heap)
: Lemma (requires List.memP b (IB.ptrs_of_mem (_ih h)))
(ensures
(let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
forall j. {:pattern (mem1.[ j ])\/(mem2.[ j ])}
(base <= j /\ j < base + scale8 i) \/
(base + scale8 (i + 1) <= j /\ j < base + scale8 n) ==>
mem1.[ j ] == mem2.[ j ])) | val written_buffer_down64
(b: buffer64{buffer_writeable b})
(i: nat{i < buffer_length b})
(v: nat64)
(h: vale_heap)
: Lemma (requires List.memP b (IB.ptrs_of_mem (_ih h)))
(ensures
(let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
forall j. {:pattern (mem1.[ j ])\/(mem2.[ j ])}
(base <= j /\ j < base + scale8 i) \/
(base + scale8 (i + 1) <= j /\ j < base + scale8 n) ==>
mem1.[ j ] == mem2.[ j ])) | let written_buffer_down64 (b:buffer64{buffer_writeable b}) (i:nat{i < buffer_length b}) (v:nat64) (h:vale_heap)
: Lemma
(requires List.memP b (IB.ptrs_of_mem (_ih h)))
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
(base <= j /\ j < base + scale8 i) \/
(base + scale8 (i+1) <= j /\ j < base + scale8 n) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
written_buffer_down64_aux1 b i v h base 0 h1 mem1 mem2;
written_buffer_down64_aux2 b i v h base n (i+1) h1 mem1 mem2 | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory_Sems.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 64,
"end_line": 337,
"start_col": 0,
"start_line": 318
} | module Vale.X64.Memory_Sems
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.Def.Words_s
module I = Vale.Interop
module S = Vale.X64.Machine_Semantics_s
module MB = LowStar.Monotonic.Buffer
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
friend Vale.X64.Memory
module IB = Vale.Interop.Base
let same_domain h m = Set.equal (IB.addrs_set (_ih h)) (Map.domain m)
let lemma_same_domains h m1 m2 = ()
let get_heap h = I.down_mem (_ih h)
let upd_heap h m = mi_heap_upd h m
//let lemma_upd_get_heap h = I.down_up_identity (_ih h)
let lemma_get_upd_heap h m = I.up_down_identity (_ih h) m
let lemma_heap_impl = ()
let lemma_heap_get_heap h = ()
let lemma_heap_taint h = ()
//let lemma_heap_upd_heap h mh mt = ()
[@"opaque_to_smt"]
let rec set_of_range (a:int) (n:nat) : Pure (Set.set int)
(requires True)
(ensures fun s -> (forall (i:int).{:pattern Set.mem i s} Set.mem i s <==> a <= i /\ i < a + n))
=
if n = 0 then Set.empty else Set.union (set_of_range a (n - 1)) (Set.singleton (a + n - 1))
let buffer_info_has_addr (bi:buffer_info) (a:int) =
let b = bi.bi_buffer in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
addr <= a /\ a < addr + len
let buffer_info_has_addr_opt (bi:option buffer_info) (a:int) =
match bi with
| None -> False
| Some bi -> buffer_info_has_addr bi a
#set-options "--z3rlimit 100"
let rec make_owns_rec (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
if n = 0 then ((fun _ -> None), (fun _ -> Set.empty)) else
let (m0, s0) = make_owns_rec h bs (n - 1) in
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let s i = if i = hi then Set.union (s0 i) s_b else s0 i in
let m a = if addr <= a && a < addr + len then Some (n - 1) else m0 a in
(m, s)
[@"opaque_to_smt"]
let make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
make_owns_rec h bs n
let rec lemma_make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n <= Seq.length bs /\
(forall (i:nat).{:pattern Seq.index bs i} i < Seq.length bs ==> buffer_readable h (Seq.index bs i).bi_buffer) /\
(forall (i1 i2:nat).{:pattern (Seq.index bs i1); (Seq.index bs i2)}
i1 < Seq.length bs /\ i2 < Seq.length bs ==> buffer_info_disjoint (Seq.index bs i1) (Seq.index bs i2))
)
(ensures (
let (m, s) = make_owns h bs n in
(forall (i:heaplet_id) (a:int).{:pattern Set.mem a (s i)}
(Set.mem a (s i) <==> Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (m a) == Some i) /\
(Set.mem a (s i) ==> buffer_info_has_addr_opt (Option.mapTot (fun n -> Seq.index bs n) (m a)) a) /\
(Set.mem a (s i) ==> Set.mem a (Map.domain h.mh))
) /\
(forall (k:nat) (a:int).{:pattern Set.mem a (s (Seq.index bs k).bi_heaplet)}
k < n /\ buffer_info_has_addr (Seq.index bs k) a ==> Set.mem a (s (Seq.index bs k).bi_heaplet))
))
=
reveal_opaque (`%make_owns) make_owns;
if n = 0 then () else
let _ = make_owns h bs (n - 1) in
let (m, s) = make_owns h bs n in
lemma_make_owns h bs (n - 1);
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let lem1 (a:int) : Lemma
(requires Set.mem a s_b)
(ensures Set.mem a (Map.domain h.mh))
[SMTPat (Set.mem a (Map.domain h.mh))]
=
I.addrs_set_mem h.ih b a
in
let lem2 (i:heaplet_id) (a:int) : Lemma
(requires i =!= hi /\ Set.mem a (Set.intersect s_b (s i)))
(ensures False)
[SMTPat (Set.mem a (s i))]
=
reveal_opaque (`%addr_map_pred) addr_map_pred
in
()
#push-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_loc_mutable_buffers_rec (l:list buffer_info) (s:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n + List.length l == Seq.length s /\
list_to_seq_post l s n
)
(ensures (
let modloc = loc_mutable_buffers l in
forall (i:nat).{:pattern Seq.index s i} n <= i /\ i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes modloc (loc_buffer bi.bi_buffer))
))
(decreases l)
=
match l with
| [] -> ()
| h::t -> lemma_loc_mutable_buffers_rec t s (n + 1)
#pop-options
let lemma_loc_mutable_buffers (l:list buffer_info) : Lemma
(ensures (
let s = list_to_seq l in
forall (i:nat).{:pattern Seq.index s i} i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes (loc_mutable_buffers l) (loc_buffer bi.bi_buffer))
))
=
lemma_list_to_seq l;
lemma_loc_mutable_buffers_rec l (list_to_seq l) 0
let create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let modloc = loc_mutable_buffers buffers in
let layout1 = h1.vf_layout in
let layin1 = layout1.vl_inner in
let (hmap, hsets) = make_owns h1.vf_heap bs (Seq.length bs) in
let hmap a = Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (hmap a) in
let l = {
vl_heaplets_initialized = true;
vl_heaplet_map = hmap;
vl_heaplet_sets = hsets;
vl_old_heap = h1.vf_heap;
vl_buffers = bs;
vl_mod_loc = modloc;
} in
let layout2 = {layout1 with vl_inner = l} in
let h2 = {
vf_layout = layout2;
vf_heap = h1.vf_heap;
vf_heaplets = h1.vf_heaplets;
} in
h2
let lemma_create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let h2 = create_heaplets buffers h1 in
assert (h2.vf_layout.vl_inner.vl_buffers == bs); // REVIEW: why is this necessary, even with extra ifuel?
lemma_make_owns h1.vf_heap bs (Seq.length bs);
lemma_loc_mutable_buffers buffers;
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
let destroy_heaplets h1 =
h1
let lemma_destroy_heaplets h1 =
()
val heap_shift (m1 m2:S.machine_heap) (base:int) (n:nat) : Lemma
(requires (forall i. 0 <= i /\ i < n ==> m1.[base + i] == m2.[base + i]))
(ensures (forall i. {:pattern (m1.[i])} base <= i /\ i < base + n ==> m1.[i] == m2.[i]))
#push-options "--smtencoding.l_arith_repr boxwrap"
let heap_shift m1 m2 base n =
assert (forall i. base <= i /\ i < base + n ==>
m1.[base + (i - base)] == m2.[base + (i - base)])
#pop-options
val same_mem_eq_slices64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 8 + 8 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8)))
let same_mem_eq_slices64 b i v k h1 h2 mem1 mem2 =
let t = TUInt64 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up64 (b:buffer64) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 8}) : Lemma
(scale8 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint64_view in
UV.length_eq vb
val same_mem_get_heap_val64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale8 k in
forall (x:int).{:pattern (mem1.[x])} ptr <= x /\ x < ptr + 8 ==> mem1.[x] == mem2.[x]))
let same_mem_get_heap_val64 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale8 k in
let addr = buffer_addr b h1 in
let aux (x:int{ptr <= x /\ x < ptr + 8}) : Lemma (mem1.[x] == mem2.[x]) =
let i = x - ptr in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices64 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8) (k * 8 + 8)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8) (k * 8 + 8)) in
assert (Seq.index s1 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i));
length_up64 b h1 k i;
assert (mem1.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i)));
assert (Seq.index s2 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i));
length_up64 b h2 k i;
assert (mem2.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i)))
in
Classical.forall_intro aux;
assert (forall i. addr + (scale8 k + i) == ptr + i)
let rec written_buffer_down64_aux1
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(k:nat) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j.{:pattern (mem1.[j]) \/ (mem2.[j])}
base <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem1.[j])}
j >= base /\ j < base + scale8 i ==>
mem1.[j] == mem2.[j]))
(decreases %[i-k]) =
if k >= i then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux1 b i v h base (k+1) h1 mem1 mem2
end
let rec written_buffer_down64_aux2
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(n:nat{n == buffer_length b})
(k:nat{k > i}) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
base + scale8 (i+1) <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
j >= base + scale8 (i+1) /\ j < base + scale8 n ==>
mem1.[j] == mem2.[j]))
(decreases %[n-k]) =
if k >= n then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux2 b i v h base n (k+1) h1 mem1 mem2
end | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Memory.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.BufferViewStore.fsti.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Memory_Sems.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_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
}
] | {
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
b: Vale.X64.Memory.buffer64{Vale.X64.Memory.buffer_writeable b} ->
i: Prims.nat{i < Vale.X64.Memory.buffer_length b} ->
v: Vale.Def.Words_s.nat64 ->
h: Vale.Arch.HeapImpl.vale_heap
-> FStar.Pervasives.Lemma
(requires
FStar.List.Tot.Base.memP b (Vale.Interop.Heap_s.ptrs_of_mem (Vale.Arch.HeapImpl._ih h)))
(ensures
(let mem1 = Vale.Interop.down_mem (Vale.Arch.HeapImpl._ih h) in
let h1 = Vale.X64.Memory.buffer_write b i v h in
let mem2 = Vale.Interop.down_mem (Vale.Arch.HeapImpl._ih h1) in
let base = Vale.X64.Memory.buffer_addr b h in
let n = Vale.X64.Memory.buffer_length b in
forall (j: Prims.int). {:pattern mem1.[ j ]\/mem2.[ j ]}
base <= j /\ j < base + Vale.X64.Memory.scale8 i \/
base + Vale.X64.Memory.scale8 (i + 1) <= j /\ j < base + Vale.X64.Memory.scale8 n ==>
mem1.[ j ] == mem2.[ j ])) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.X64.Memory.buffer64",
"Vale.X64.Memory.buffer_writeable",
"Vale.X64.Memory.vuint64",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Vale.X64.Memory.buffer_length",
"Vale.Def.Words_s.nat64",
"Vale.Arch.HeapImpl.vale_heap",
"Vale.X64.Memory_Sems.written_buffer_down64_aux2",
"Prims.op_Addition",
"Prims.unit",
"Vale.X64.Memory_Sems.written_buffer_down64_aux1",
"Prims.int",
"Vale.X64.Memory.buffer_addr",
"Vale.Arch.MachineHeap_s.machine_heap",
"Vale.Interop.Heap_s.correct_down",
"Vale.Arch.HeapImpl._ih",
"Vale.Interop.down_mem",
"Vale.X64.Memory.buffer_write",
"FStar.List.Tot.Base.memP",
"Vale.Interop.Types.b8",
"Vale.Interop.Heap_s.ptrs_of_mem",
"Prims.squash",
"Prims.l_Forall",
"Prims.l_imp",
"Prims.l_or",
"Prims.l_and",
"Prims.op_LessThanOrEqual",
"Vale.X64.Memory.scale8",
"Prims.eq2",
"Vale.Def.Types_s.nat8",
"Vale.X64.Memory.op_String_Access",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let written_buffer_down64
(b: buffer64{buffer_writeable b})
(i: nat{i < buffer_length b})
(v: nat64)
(h: vale_heap)
: Lemma (requires List.memP b (IB.ptrs_of_mem (_ih h)))
(ensures
(let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
forall j. {:pattern (mem1.[ j ])\/(mem2.[ j ])}
(base <= j /\ j < base + scale8 i) \/
(base + scale8 (i + 1) <= j /\ j < base + scale8 n) ==>
mem1.[ j ] == mem2.[ j ])) =
| let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
written_buffer_down64_aux1 b i v h base 0 h1 mem1 mem2;
written_buffer_down64_aux2 b i v h base n (i + 1) h1 mem1 mem2 | false |
Vale.X64.Memory_Sems.fst | Vale.X64.Memory_Sems.length_up128 | val length_up128 (b: buffer128) (h: vale_heap) (k: nat{k < buffer_length b}) (i: nat{i < 16})
: Lemma (scale16 k + i <= DV.length (get_downview b.bsrc)) | val length_up128 (b: buffer128) (h: vale_heap) (k: nat{k < buffer_length b}) (i: nat{i < 16})
: Lemma (scale16 k + i <= DV.length (get_downview b.bsrc)) | let length_up128 (b:buffer128) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 16}) : Lemma
(scale16 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint128_view in
UV.length_eq vb | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory_Sems.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 17,
"end_line": 508,
"start_col": 0,
"start_line": 505
} | module Vale.X64.Memory_Sems
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.Def.Words_s
module I = Vale.Interop
module S = Vale.X64.Machine_Semantics_s
module MB = LowStar.Monotonic.Buffer
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
friend Vale.X64.Memory
module IB = Vale.Interop.Base
let same_domain h m = Set.equal (IB.addrs_set (_ih h)) (Map.domain m)
let lemma_same_domains h m1 m2 = ()
let get_heap h = I.down_mem (_ih h)
let upd_heap h m = mi_heap_upd h m
//let lemma_upd_get_heap h = I.down_up_identity (_ih h)
let lemma_get_upd_heap h m = I.up_down_identity (_ih h) m
let lemma_heap_impl = ()
let lemma_heap_get_heap h = ()
let lemma_heap_taint h = ()
//let lemma_heap_upd_heap h mh mt = ()
[@"opaque_to_smt"]
let rec set_of_range (a:int) (n:nat) : Pure (Set.set int)
(requires True)
(ensures fun s -> (forall (i:int).{:pattern Set.mem i s} Set.mem i s <==> a <= i /\ i < a + n))
=
if n = 0 then Set.empty else Set.union (set_of_range a (n - 1)) (Set.singleton (a + n - 1))
let buffer_info_has_addr (bi:buffer_info) (a:int) =
let b = bi.bi_buffer in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
addr <= a /\ a < addr + len
let buffer_info_has_addr_opt (bi:option buffer_info) (a:int) =
match bi with
| None -> False
| Some bi -> buffer_info_has_addr bi a
#set-options "--z3rlimit 100"
let rec make_owns_rec (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
if n = 0 then ((fun _ -> None), (fun _ -> Set.empty)) else
let (m0, s0) = make_owns_rec h bs (n - 1) in
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let s i = if i = hi then Set.union (s0 i) s_b else s0 i in
let m a = if addr <= a && a < addr + len then Some (n - 1) else m0 a in
(m, s)
[@"opaque_to_smt"]
let make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
make_owns_rec h bs n
let rec lemma_make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n <= Seq.length bs /\
(forall (i:nat).{:pattern Seq.index bs i} i < Seq.length bs ==> buffer_readable h (Seq.index bs i).bi_buffer) /\
(forall (i1 i2:nat).{:pattern (Seq.index bs i1); (Seq.index bs i2)}
i1 < Seq.length bs /\ i2 < Seq.length bs ==> buffer_info_disjoint (Seq.index bs i1) (Seq.index bs i2))
)
(ensures (
let (m, s) = make_owns h bs n in
(forall (i:heaplet_id) (a:int).{:pattern Set.mem a (s i)}
(Set.mem a (s i) <==> Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (m a) == Some i) /\
(Set.mem a (s i) ==> buffer_info_has_addr_opt (Option.mapTot (fun n -> Seq.index bs n) (m a)) a) /\
(Set.mem a (s i) ==> Set.mem a (Map.domain h.mh))
) /\
(forall (k:nat) (a:int).{:pattern Set.mem a (s (Seq.index bs k).bi_heaplet)}
k < n /\ buffer_info_has_addr (Seq.index bs k) a ==> Set.mem a (s (Seq.index bs k).bi_heaplet))
))
=
reveal_opaque (`%make_owns) make_owns;
if n = 0 then () else
let _ = make_owns h bs (n - 1) in
let (m, s) = make_owns h bs n in
lemma_make_owns h bs (n - 1);
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let lem1 (a:int) : Lemma
(requires Set.mem a s_b)
(ensures Set.mem a (Map.domain h.mh))
[SMTPat (Set.mem a (Map.domain h.mh))]
=
I.addrs_set_mem h.ih b a
in
let lem2 (i:heaplet_id) (a:int) : Lemma
(requires i =!= hi /\ Set.mem a (Set.intersect s_b (s i)))
(ensures False)
[SMTPat (Set.mem a (s i))]
=
reveal_opaque (`%addr_map_pred) addr_map_pred
in
()
#push-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_loc_mutable_buffers_rec (l:list buffer_info) (s:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n + List.length l == Seq.length s /\
list_to_seq_post l s n
)
(ensures (
let modloc = loc_mutable_buffers l in
forall (i:nat).{:pattern Seq.index s i} n <= i /\ i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes modloc (loc_buffer bi.bi_buffer))
))
(decreases l)
=
match l with
| [] -> ()
| h::t -> lemma_loc_mutable_buffers_rec t s (n + 1)
#pop-options
let lemma_loc_mutable_buffers (l:list buffer_info) : Lemma
(ensures (
let s = list_to_seq l in
forall (i:nat).{:pattern Seq.index s i} i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes (loc_mutable_buffers l) (loc_buffer bi.bi_buffer))
))
=
lemma_list_to_seq l;
lemma_loc_mutable_buffers_rec l (list_to_seq l) 0
let create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let modloc = loc_mutable_buffers buffers in
let layout1 = h1.vf_layout in
let layin1 = layout1.vl_inner in
let (hmap, hsets) = make_owns h1.vf_heap bs (Seq.length bs) in
let hmap a = Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (hmap a) in
let l = {
vl_heaplets_initialized = true;
vl_heaplet_map = hmap;
vl_heaplet_sets = hsets;
vl_old_heap = h1.vf_heap;
vl_buffers = bs;
vl_mod_loc = modloc;
} in
let layout2 = {layout1 with vl_inner = l} in
let h2 = {
vf_layout = layout2;
vf_heap = h1.vf_heap;
vf_heaplets = h1.vf_heaplets;
} in
h2
let lemma_create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let h2 = create_heaplets buffers h1 in
assert (h2.vf_layout.vl_inner.vl_buffers == bs); // REVIEW: why is this necessary, even with extra ifuel?
lemma_make_owns h1.vf_heap bs (Seq.length bs);
lemma_loc_mutable_buffers buffers;
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
let destroy_heaplets h1 =
h1
let lemma_destroy_heaplets h1 =
()
val heap_shift (m1 m2:S.machine_heap) (base:int) (n:nat) : Lemma
(requires (forall i. 0 <= i /\ i < n ==> m1.[base + i] == m2.[base + i]))
(ensures (forall i. {:pattern (m1.[i])} base <= i /\ i < base + n ==> m1.[i] == m2.[i]))
#push-options "--smtencoding.l_arith_repr boxwrap"
let heap_shift m1 m2 base n =
assert (forall i. base <= i /\ i < base + n ==>
m1.[base + (i - base)] == m2.[base + (i - base)])
#pop-options
val same_mem_eq_slices64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 8 + 8 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8)))
let same_mem_eq_slices64 b i v k h1 h2 mem1 mem2 =
let t = TUInt64 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up64 (b:buffer64) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 8}) : Lemma
(scale8 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint64_view in
UV.length_eq vb
val same_mem_get_heap_val64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale8 k in
forall (x:int).{:pattern (mem1.[x])} ptr <= x /\ x < ptr + 8 ==> mem1.[x] == mem2.[x]))
let same_mem_get_heap_val64 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale8 k in
let addr = buffer_addr b h1 in
let aux (x:int{ptr <= x /\ x < ptr + 8}) : Lemma (mem1.[x] == mem2.[x]) =
let i = x - ptr in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices64 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8) (k * 8 + 8)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8) (k * 8 + 8)) in
assert (Seq.index s1 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i));
length_up64 b h1 k i;
assert (mem1.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i)));
assert (Seq.index s2 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i));
length_up64 b h2 k i;
assert (mem2.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i)))
in
Classical.forall_intro aux;
assert (forall i. addr + (scale8 k + i) == ptr + i)
let rec written_buffer_down64_aux1
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(k:nat) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j.{:pattern (mem1.[j]) \/ (mem2.[j])}
base <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem1.[j])}
j >= base /\ j < base + scale8 i ==>
mem1.[j] == mem2.[j]))
(decreases %[i-k]) =
if k >= i then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux1 b i v h base (k+1) h1 mem1 mem2
end
let rec written_buffer_down64_aux2
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(n:nat{n == buffer_length b})
(k:nat{k > i}) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
base + scale8 (i+1) <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
j >= base + scale8 (i+1) /\ j < base + scale8 n ==>
mem1.[j] == mem2.[j]))
(decreases %[n-k]) =
if k >= n then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux2 b i v h base n (k+1) h1 mem1 mem2
end
let written_buffer_down64 (b:buffer64{buffer_writeable b}) (i:nat{i < buffer_length b}) (v:nat64) (h:vale_heap)
: Lemma
(requires List.memP b (IB.ptrs_of_mem (_ih h)))
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
(base <= j /\ j < base + scale8 i) \/
(base + scale8 (i+1) <= j /\ j < base + scale8 n) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
written_buffer_down64_aux1 b i v h base 0 h1 mem1 mem2;
written_buffer_down64_aux2 b i v h base n (i+1) h1 mem1 mem2
let unwritten_buffer_down (t:base_typ) (b:buffer t{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:base_typ_as_vale_type t)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall (a:b8{List.memP a (IB.ptrs_of_mem (_ih h)) /\ a =!= b}) j. {:pattern mem1.[j]; List.memP a (IB.ptrs_of_mem (_ih h)) \/ mem2.[j]; List.memP a (IB.ptrs_of_mem (_ih h))}
let base = (IB.addrs_of_mem (_ih h)) a in
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==> mem1.[j] == mem2.[j]))
= let aux (a:b8{a =!= b /\ List.memP a (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let base = (IB.addrs_of_mem (_ih h)) a in
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall j.
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==>
mem1.[j] == mem2.[j]))
= let db = get_downview a.bsrc in
if DV.length db = 0 then ()
else
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = (IB.addrs_of_mem (_ih h)) a in
let s0 = DV.as_seq (IB.hs_of_mem (_ih h)) db in
let s1 = DV.as_seq (IB.hs_of_mem (_ih h1)) db in
opaque_assert (`%IB.list_disjoint_or_eq) IB.list_disjoint_or_eq IB.list_disjoint_or_eq_def (MB.disjoint a.bsrc b.bsrc);
lemma_dv_equal (IB.down_view a.src) a.bsrc (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1));
assert (Seq.equal s0 s1);
assert (forall (j:int).{:pattern (mem1.[j])}
base <= j /\ j < base + Seq.length s0 ==> v_to_typ TUInt8 (Seq.index s0 (j - base)) == mem1.[j]);
heap_shift mem1 mem2 base (DV.length db)
in
Classical.forall_intro aux
let store_buffer_down64_mem
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
forall (j:int). {:pattern mem1.[j] \/ mem2.[j]}
j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
let aux (j:int)
: Lemma
(j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j])
=
I.addrs_set_lemma_all ();
if j >= base && j < base + DV.length (get_downview b.bsrc) then begin
written_buffer_down64 b i v h;
length_t_eq (TUInt64) b
end
else if not (I.valid_addr (_ih h) j)
then I.same_unspecified_down (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1)) (IB.ptrs_of_mem (_ih h))
else unwritten_buffer_down TUInt64 b i v h
in
Classical.forall_intro aux
let store_buffer_aux_down64_mem (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
forall j. {:pattern mem1.[j] \/ mem2.[j]}
j < ptr \/ j >= ptr + 8 ==>
mem1.[j] == mem2.[j]))
= let t = TUInt64 in
let h1 = store_mem t ptr v h in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
store_buffer_write t ptr v h;
assert (buffer_addr b h + scale8 i == ptr);
assert (buffer_addr b h + scale8 (i+1) == ptr + 8);
store_buffer_down64_mem b i v h
let store_buffer_aux_down64_mem2 (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
S.get_heap_val64 ptr mem2 == v))
= let t = TUInt64 in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
let h1 = store_mem t ptr v h in
let mem2 = I.down_mem (_ih h1) in
store_buffer_write t ptr v h;
assert (Seq.index (buffer_as_seq h1 b) i == v);
index64_get_heap_val64 h1 b mem2 i
let in_bounds64 (h:vale_heap) (b:buffer64) (i:nat{i < buffer_length b})
: Lemma (scale8 i + 8 <= DV.length (get_downview b.bsrc))
=
length_t_eq TUInt64 b
let bytes_valid64 ptr h =
reveal_opaque (`%S.valid_addr64) S.valid_addr64;
let t = TUInt64 in
let b = get_addr_ptr t ptr h in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
in_bounds64 h b i;
I.addrs_set_mem (_ih h) b ptr;
I.addrs_set_mem (_ih h) b (ptr+1);
I.addrs_set_mem (_ih h) b (ptr+2);
I.addrs_set_mem (_ih h) b (ptr+3);
I.addrs_set_mem (_ih h) b (ptr+4);
I.addrs_set_mem (_ih h) b (ptr+5);
I.addrs_set_mem (_ih h) b (ptr+6);
I.addrs_set_mem (_ih h) b (ptr+7)
val same_mem_get_heap_val128 (b:buffer128)
(i:nat{i < buffer_length b})
(v:quad32)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1)) /\ buffer_writeable b})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale16 k in
forall i.{:pattern mem1.[i]} i >= ptr /\ i < ptr+16 ==> mem1.[i] == mem2.[i]))
val same_mem_eq_slices128 (b:buffer128)
(i:nat{i < buffer_length b})
(v:quad32)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1)) /\ buffer_writeable b})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 16 + 16 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 16) (k * 16 + 16) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 16) (k * 16 + 16)))
let same_mem_eq_slices128 b i v k h1 h2 mem1 mem2 =
let t = TUInt128 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Memory.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.BufferViewStore.fsti.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Memory_Sems.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_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
}
] | {
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
b: Vale.X64.Memory.buffer128 ->
h: Vale.Arch.HeapImpl.vale_heap ->
k: Prims.nat{k < Vale.X64.Memory.buffer_length b} ->
i: Prims.nat{i < 16}
-> FStar.Pervasives.Lemma
(ensures
Vale.X64.Memory.scale16 k + i <=
LowStar.BufferView.Down.length (Vale.Interop.Types.get_downview (Buffer?.bsrc b))) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.X64.Memory.buffer128",
"Vale.Arch.HeapImpl.vale_heap",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Vale.X64.Memory.buffer_length",
"Vale.X64.Memory.vuint128",
"LowStar.BufferView.Up.length_eq",
"Vale.Def.Types_s.quad32",
"LowStar.BufferView.Up.buffer",
"LowStar.BufferView.Up.mk_buffer",
"FStar.UInt8.t",
"Vale.Interop.Types.get_downview",
"Vale.Interop.Types.__proj__Buffer__item__src",
"Vale.Interop.Types.b8_preorder",
"Vale.Interop.Types.__proj__Buffer__item__writeable",
"Vale.Interop.Types.base_typ_as_type",
"Vale.Interop.Types.__proj__Buffer__item__bsrc",
"Vale.X64.Memory.uint128_view",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition",
"Vale.X64.Memory.scale16",
"LowStar.BufferView.Down.length",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let length_up128 (b: buffer128) (h: vale_heap) (k: nat{k < buffer_length b}) (i: nat{i < 16})
: Lemma (scale16 k + i <= DV.length (get_downview b.bsrc)) =
| let vb = UV.mk_buffer (get_downview b.bsrc) uint128_view in
UV.length_eq vb | false |
Selectors.LList2.fst | Selectors.LList2.is_nil' | val is_nil' (#opened: _) (#a: Type0) (ptr: t a)
: SteelGhost unit
opened
(llist ptr)
(fun _ -> llist ptr)
(requires fun _ -> True)
(ensures
fun h0 _ h1 ->
let res = is_null ptr in
(res == true <==> ptr == null_llist #a) /\ v_llist ptr h0 == v_llist ptr h1 /\
res == Nil? (v_llist ptr h1)) | val is_nil' (#opened: _) (#a: Type0) (ptr: t a)
: SteelGhost unit
opened
(llist ptr)
(fun _ -> llist ptr)
(requires fun _ -> True)
(ensures
fun h0 _ h1 ->
let res = is_null ptr in
(res == true <==> ptr == null_llist #a) /\ v_llist ptr h0 == v_llist ptr h1 /\
res == Nil? (v_llist ptr h1)) | let is_nil' (#opened: _) (#a:Type0) (ptr:t a)
: SteelGhost unit opened (llist ptr) (fun _ -> llist ptr)
(requires fun _ -> True)
(ensures fun h0 _ h1 ->
let res = is_null ptr in
(res == true <==> ptr == null_llist #a) /\
v_llist ptr h0 == v_llist ptr h1 /\
res == Nil? (v_llist ptr h1))
=
let res = is_null ptr in
llist0_of_llist ptr;
if res
then begin
change_equal_slprop
(llist0 ptr)
(emp `vrewrite` v_null_rewrite a);
elim_vrewrite emp (v_null_rewrite a);
intro_vrewrite emp (v_null_rewrite a);
change_equal_slprop
(emp `vrewrite` v_null_rewrite a)
(llist0 ptr)
end else begin
change_equal_slprop
(llist0 ptr)
((vptr ptr `vdep` llist_vdep ptr) `vrewrite` llist_vrewrite ptr);
elim_vrewrite (vptr ptr `vdep` llist_vdep ptr) (llist_vrewrite ptr);
intro_vrewrite (vptr ptr `vdep` llist_vdep ptr) (llist_vrewrite ptr);
change_equal_slprop
((vptr ptr `vdep` llist_vdep ptr) `vrewrite` llist_vrewrite ptr)
(llist0 ptr)
end;
llist_of_llist0 ptr | {
"file_name": "share/steel/examples/steel/Selectors.LList2.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 21,
"end_line": 265,
"start_col": 0,
"start_line": 234
} | module Selectors.LList2
open Steel.FractionalPermission
module Mem = Steel.Memory
#push-options "--__no_positivity"
noeq
type cell (a: Type0) = {
tail_fuel: Ghost.erased nat;
next: ref (cell a);
data: a;
}
#pop-options
let next #a (c:cell a) : t a = c.next
let data #a (c:cell a) : a = c.data
let mk_cell #a (n: t a) (d:a) = {
tail_fuel = Ghost.hide 0;
next = n;
data = d
}
let null_llist #a = null
let is_null #a ptr = is_null ptr
let v_null_rewrite
(a: Type0)
(_: t_of emp)
: GTot (list a)
= []
let v_c
(n: Ghost.erased nat)
(#a: Type0)
(r: t a)
(c: normal (t_of (vptr r)))
: GTot prop
= (Ghost.reveal c.tail_fuel < Ghost.reveal n) == true // to ensure vprop termination
let v_c_dep
(n: Ghost.erased nat)
(#a: Type0)
(r: t a)
(nllist: (n': Ghost.erased nat) -> (r: t a { Ghost.reveal n' < Ghost.reveal n }) -> Pure vprop (requires True) (ensures (fun y -> t_of y == list a)))
(c: normal (t_of (vrefine (vptr r) (v_c n r))))
: Tot vprop
= nllist c.tail_fuel c.next
let v_c_l_rewrite
(n: Ghost.erased nat)
(#a: Type0)
(r: t a)
(nllist: (n': Ghost.erased nat) -> (r: t a { Ghost.reveal n' < Ghost.reveal n }) -> Pure vprop (requires True) (ensures (fun y -> t_of y == list a)))
(res: normal (t_of ((vptr r `vrefine` v_c n r) `vdep` v_c_dep n r nllist)))
: Tot (list a)
= let (| c, l |) = res in
c.data :: l
let rec nllist
(a: Type0)
(n: Ghost.erased nat)
(r: t a)
: Pure vprop
(requires True)
(ensures (fun y -> t_of y == list a))
(decreases (Ghost.reveal n))
= if is_null r
then emp `vrewrite` v_null_rewrite a
else ((vptr r `vrefine` v_c n r) `vdep` v_c_dep n r (nllist a)) `vrewrite` v_c_l_rewrite n r (nllist a)
let nllist_eq_not_null
(a: Type0)
(n: Ghost.erased nat)
(r: t a)
: Lemma
(requires (is_null r == false))
(ensures (
nllist a n r == ((vptr r `vrefine` v_c n r) `vdep` v_c_dep n r (nllist a)) `vrewrite` v_c_l_rewrite n r (nllist a)
))
= assert_norm (nllist a n r ==
begin if is_null r
then emp `vrewrite` v_null_rewrite a
else ((vptr r `vrefine` v_c n r) `vdep` v_c_dep n r (nllist a)) `vrewrite` v_c_l_rewrite n r (nllist a)
end
)
let llist_vdep
(#a: Type0)
(r: t a)
(c: normal (t_of (vptr r)))
: Tot vprop
= nllist a c.tail_fuel c.next
let llist_vrewrite
(#a: Type0)
(r: t a)
(cl: normal (t_of (vptr r `vdep` llist_vdep r)))
: GTot (list a)
= (dfst cl).data :: dsnd cl
let llist0
(#a: Type0)
(r: t a)
: Pure vprop
(requires True)
(ensures (fun y -> t_of y == list a))
= if is_null r
then emp `vrewrite` v_null_rewrite a
else (vptr r `vdep` llist_vdep r) `vrewrite` llist_vrewrite r
let nllist_of_llist0
(#opened: _)
(#a: Type0)
(r: t a)
: SteelGhost (Ghost.erased nat) opened
(llist0 r)
(fun res -> nllist a res r)
(fun _ -> True)
(fun h0 res h1 ->
h0 (llist0 r) == h1 (nllist a res r)
)
=
if is_null r
then begin
let res = Ghost.hide 0 in
change_equal_slprop
(llist0 r)
(nllist a res r);
res
end else begin
change_equal_slprop
(llist0 r)
((vptr r `vdep` llist_vdep r) `vrewrite` llist_vrewrite r);
elim_vrewrite (vptr r `vdep` llist_vdep r) (llist_vrewrite r);
let gk : normal (Ghost.erased (t_of (vptr r))) = elim_vdep (vptr r) (llist_vdep r) in
let res = Ghost.hide (Ghost.reveal (Ghost.reveal gk).tail_fuel + 1) in
intro_vrefine (vptr r) (v_c res r);
intro_vdep
(vptr r `vrefine` v_c res r)
(llist_vdep r (Ghost.reveal gk))
(v_c_dep res r (nllist a));
intro_vrewrite ((vptr r `vrefine` v_c res r) `vdep` v_c_dep res r (nllist a)) (v_c_l_rewrite res r (nllist a));
nllist_eq_not_null a res r;
change_equal_slprop
(((vptr r `vrefine` v_c res r) `vdep` v_c_dep res r (nllist a)) `vrewrite` v_c_l_rewrite res r (nllist a))
(nllist a res r);
res
end
let llist0_of_nllist
(#opened: _)
(#a: Type0)
(n: Ghost.erased nat)
(r: t a)
: SteelGhost unit opened
(nllist a n r)
(fun _ -> llist0 r)
(fun _ -> True)
(fun h0 res h1 ->
h1 (llist0 r) == h0 (nllist a n r)
)
=
if is_null r
then begin
change_equal_slprop
(nllist a n r)
(llist0 r);
()
end else begin
nllist_eq_not_null a n r;
change_equal_slprop
(nllist a n r)
(((vptr r `vrefine` v_c n r) `vdep` v_c_dep n r (nllist a)) `vrewrite` v_c_l_rewrite n r (nllist a));
elim_vrewrite ((vptr r `vrefine` v_c n r) `vdep` v_c_dep n r (nllist a)) (v_c_l_rewrite n r (nllist a));
let gk = elim_vdep (vptr r `vrefine` v_c n r) (v_c_dep n r (nllist a)) in
elim_vrefine (vptr r) (v_c n r);
intro_vdep
(vptr r)
(v_c_dep n r (nllist a) (Ghost.reveal gk))
(llist_vdep r);
intro_vrewrite (vptr r `vdep` llist_vdep r) (llist_vrewrite r);
change_equal_slprop
((vptr r `vdep` llist_vdep r) `vrewrite` llist_vrewrite r)
(llist0 r)
end
let llist_sl
#a r
= hp_of (llist0 r)
let llist_sel
#a r
= fun m -> sel_of (llist0 r) m // eta necessary because sel_of is GTot
let llist_of_llist0
(#opened: _)
(#a: Type)
(r: t a)
: SteelGhost unit opened
(llist0 r)
(fun _ -> llist r)
(fun _ -> True)
(fun h0 _ h1 -> h1 (llist r) == h0 (llist0 r))
=
change_slprop_rel
(llist0 r)
(llist r)
(fun x y -> x == y)
(fun _ -> ())
let llist0_of_llist
(#opened: _)
(#a: Type)
(r: t a)
: SteelGhost unit opened
(llist r)
(fun _ -> llist0 r)
(fun _ -> True)
(fun h0 _ h1 -> h1 (llist0 r) == h0 (llist r))
=
change_slprop_rel
(llist r)
(llist0 r)
(fun x y -> x == y)
(fun _ -> ())
let intro_llist_nil a =
intro_vrewrite emp (v_null_rewrite a);
change_equal_slprop
(emp `vrewrite` v_null_rewrite a)
(llist0 (null_llist #a));
llist_of_llist0 (null_llist #a) | {
"checked_file": "/",
"dependencies": [
"Steel.Memory.fsti.checked",
"Steel.FractionalPermission.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": true,
"source_file": "Selectors.LList2.fst"
} | [
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Steel.Reference",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Selectors",
"short_module": null
},
{
"abbrev": false,
"full_module": "Selectors",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | ptr: Selectors.LList2.t a -> Steel.Effect.Atomic.SteelGhost Prims.unit | Steel.Effect.Atomic.SteelGhost | [] | [] | [
"Steel.Memory.inames",
"Selectors.LList2.t",
"Selectors.LList2.llist_of_llist0",
"Prims.unit",
"Steel.Effect.Atomic.change_equal_slprop",
"Steel.Effect.Common.vrewrite",
"Steel.Effect.Common.emp",
"Prims.list",
"Selectors.LList2.v_null_rewrite",
"Selectors.LList2.llist0",
"Steel.Effect.Atomic.intro_vrewrite",
"Steel.Effect.Atomic.elim_vrewrite",
"Prims.bool",
"Steel.Effect.Common.vdep",
"Steel.Reference.vptr",
"Selectors.LList2.cell",
"Selectors.LList2.llist_vdep",
"Selectors.LList2.llist_vrewrite",
"Selectors.LList2.llist0_of_llist",
"Prims.l_iff",
"Prims.b2t",
"Prims.eq2",
"Selectors.LList2.null_llist",
"Selectors.LList2.is_null",
"Selectors.LList2.llist",
"Steel.Effect.Common.vprop",
"Steel.Effect.Common.rmem",
"Prims.l_True",
"Prims.l_and",
"Selectors.LList2.v_llist",
"Prims.uu___is_Nil"
] | [] | false | true | false | false | false | let is_nil' (#opened: _) (#a: Type0) (ptr: t a)
: SteelGhost unit
opened
(llist ptr)
(fun _ -> llist ptr)
(requires fun _ -> True)
(ensures
fun h0 _ h1 ->
let res = is_null ptr in
(res == true <==> ptr == null_llist #a) /\ v_llist ptr h0 == v_llist ptr h1 /\
res == Nil? (v_llist ptr h1)) =
| let res = is_null ptr in
llist0_of_llist ptr;
if res
then
(change_equal_slprop (llist0 ptr) (emp `vrewrite` (v_null_rewrite a));
elim_vrewrite emp (v_null_rewrite a);
intro_vrewrite emp (v_null_rewrite a);
change_equal_slprop (emp `vrewrite` (v_null_rewrite a)) (llist0 ptr))
else
(change_equal_slprop (llist0 ptr)
(((vptr ptr) `vdep` (llist_vdep ptr)) `vrewrite` (llist_vrewrite ptr));
elim_vrewrite ((vptr ptr) `vdep` (llist_vdep ptr)) (llist_vrewrite ptr);
intro_vrewrite ((vptr ptr) `vdep` (llist_vdep ptr)) (llist_vrewrite ptr);
change_equal_slprop (((vptr ptr) `vdep` (llist_vdep ptr)) `vrewrite` (llist_vrewrite ptr))
(llist0 ptr));
llist_of_llist0 ptr | false |
Vale.X64.Memory_Sems.fst | Vale.X64.Memory_Sems.store_buffer_aux_down64_mem | val store_buffer_aux_down64_mem (ptr: int) (v: nat64) (h: vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures
(let mem1 = I.down_mem (_ih h) in
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
forall j. {:pattern mem1.[ j ]\/mem2.[ j ]}
j < ptr \/ j >= ptr + 8 ==> mem1.[ j ] == mem2.[ j ])) | val store_buffer_aux_down64_mem (ptr: int) (v: nat64) (h: vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures
(let mem1 = I.down_mem (_ih h) in
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
forall j. {:pattern mem1.[ j ]\/mem2.[ j ]}
j < ptr \/ j >= ptr + 8 ==> mem1.[ j ] == mem2.[ j ])) | let store_buffer_aux_down64_mem (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
forall j. {:pattern mem1.[j] \/ mem2.[j]}
j < ptr \/ j >= ptr + 8 ==>
mem1.[j] == mem2.[j]))
= let t = TUInt64 in
let h1 = store_mem t ptr v h in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
store_buffer_write t ptr v h;
assert (buffer_addr b h + scale8 i == ptr);
assert (buffer_addr b h + scale8 (i+1) == ptr + 8);
store_buffer_down64_mem b i v h | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory_Sems.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 35,
"end_line": 431,
"start_col": 0,
"start_line": 414
} | module Vale.X64.Memory_Sems
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.Def.Words_s
module I = Vale.Interop
module S = Vale.X64.Machine_Semantics_s
module MB = LowStar.Monotonic.Buffer
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
friend Vale.X64.Memory
module IB = Vale.Interop.Base
let same_domain h m = Set.equal (IB.addrs_set (_ih h)) (Map.domain m)
let lemma_same_domains h m1 m2 = ()
let get_heap h = I.down_mem (_ih h)
let upd_heap h m = mi_heap_upd h m
//let lemma_upd_get_heap h = I.down_up_identity (_ih h)
let lemma_get_upd_heap h m = I.up_down_identity (_ih h) m
let lemma_heap_impl = ()
let lemma_heap_get_heap h = ()
let lemma_heap_taint h = ()
//let lemma_heap_upd_heap h mh mt = ()
[@"opaque_to_smt"]
let rec set_of_range (a:int) (n:nat) : Pure (Set.set int)
(requires True)
(ensures fun s -> (forall (i:int).{:pattern Set.mem i s} Set.mem i s <==> a <= i /\ i < a + n))
=
if n = 0 then Set.empty else Set.union (set_of_range a (n - 1)) (Set.singleton (a + n - 1))
let buffer_info_has_addr (bi:buffer_info) (a:int) =
let b = bi.bi_buffer in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
addr <= a /\ a < addr + len
let buffer_info_has_addr_opt (bi:option buffer_info) (a:int) =
match bi with
| None -> False
| Some bi -> buffer_info_has_addr bi a
#set-options "--z3rlimit 100"
let rec make_owns_rec (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
if n = 0 then ((fun _ -> None), (fun _ -> Set.empty)) else
let (m0, s0) = make_owns_rec h bs (n - 1) in
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let s i = if i = hi then Set.union (s0 i) s_b else s0 i in
let m a = if addr <= a && a < addr + len then Some (n - 1) else m0 a in
(m, s)
[@"opaque_to_smt"]
let make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
make_owns_rec h bs n
let rec lemma_make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n <= Seq.length bs /\
(forall (i:nat).{:pattern Seq.index bs i} i < Seq.length bs ==> buffer_readable h (Seq.index bs i).bi_buffer) /\
(forall (i1 i2:nat).{:pattern (Seq.index bs i1); (Seq.index bs i2)}
i1 < Seq.length bs /\ i2 < Seq.length bs ==> buffer_info_disjoint (Seq.index bs i1) (Seq.index bs i2))
)
(ensures (
let (m, s) = make_owns h bs n in
(forall (i:heaplet_id) (a:int).{:pattern Set.mem a (s i)}
(Set.mem a (s i) <==> Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (m a) == Some i) /\
(Set.mem a (s i) ==> buffer_info_has_addr_opt (Option.mapTot (fun n -> Seq.index bs n) (m a)) a) /\
(Set.mem a (s i) ==> Set.mem a (Map.domain h.mh))
) /\
(forall (k:nat) (a:int).{:pattern Set.mem a (s (Seq.index bs k).bi_heaplet)}
k < n /\ buffer_info_has_addr (Seq.index bs k) a ==> Set.mem a (s (Seq.index bs k).bi_heaplet))
))
=
reveal_opaque (`%make_owns) make_owns;
if n = 0 then () else
let _ = make_owns h bs (n - 1) in
let (m, s) = make_owns h bs n in
lemma_make_owns h bs (n - 1);
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let lem1 (a:int) : Lemma
(requires Set.mem a s_b)
(ensures Set.mem a (Map.domain h.mh))
[SMTPat (Set.mem a (Map.domain h.mh))]
=
I.addrs_set_mem h.ih b a
in
let lem2 (i:heaplet_id) (a:int) : Lemma
(requires i =!= hi /\ Set.mem a (Set.intersect s_b (s i)))
(ensures False)
[SMTPat (Set.mem a (s i))]
=
reveal_opaque (`%addr_map_pred) addr_map_pred
in
()
#push-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_loc_mutable_buffers_rec (l:list buffer_info) (s:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n + List.length l == Seq.length s /\
list_to_seq_post l s n
)
(ensures (
let modloc = loc_mutable_buffers l in
forall (i:nat).{:pattern Seq.index s i} n <= i /\ i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes modloc (loc_buffer bi.bi_buffer))
))
(decreases l)
=
match l with
| [] -> ()
| h::t -> lemma_loc_mutable_buffers_rec t s (n + 1)
#pop-options
let lemma_loc_mutable_buffers (l:list buffer_info) : Lemma
(ensures (
let s = list_to_seq l in
forall (i:nat).{:pattern Seq.index s i} i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes (loc_mutable_buffers l) (loc_buffer bi.bi_buffer))
))
=
lemma_list_to_seq l;
lemma_loc_mutable_buffers_rec l (list_to_seq l) 0
let create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let modloc = loc_mutable_buffers buffers in
let layout1 = h1.vf_layout in
let layin1 = layout1.vl_inner in
let (hmap, hsets) = make_owns h1.vf_heap bs (Seq.length bs) in
let hmap a = Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (hmap a) in
let l = {
vl_heaplets_initialized = true;
vl_heaplet_map = hmap;
vl_heaplet_sets = hsets;
vl_old_heap = h1.vf_heap;
vl_buffers = bs;
vl_mod_loc = modloc;
} in
let layout2 = {layout1 with vl_inner = l} in
let h2 = {
vf_layout = layout2;
vf_heap = h1.vf_heap;
vf_heaplets = h1.vf_heaplets;
} in
h2
let lemma_create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let h2 = create_heaplets buffers h1 in
assert (h2.vf_layout.vl_inner.vl_buffers == bs); // REVIEW: why is this necessary, even with extra ifuel?
lemma_make_owns h1.vf_heap bs (Seq.length bs);
lemma_loc_mutable_buffers buffers;
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
let destroy_heaplets h1 =
h1
let lemma_destroy_heaplets h1 =
()
val heap_shift (m1 m2:S.machine_heap) (base:int) (n:nat) : Lemma
(requires (forall i. 0 <= i /\ i < n ==> m1.[base + i] == m2.[base + i]))
(ensures (forall i. {:pattern (m1.[i])} base <= i /\ i < base + n ==> m1.[i] == m2.[i]))
#push-options "--smtencoding.l_arith_repr boxwrap"
let heap_shift m1 m2 base n =
assert (forall i. base <= i /\ i < base + n ==>
m1.[base + (i - base)] == m2.[base + (i - base)])
#pop-options
val same_mem_eq_slices64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 8 + 8 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8)))
let same_mem_eq_slices64 b i v k h1 h2 mem1 mem2 =
let t = TUInt64 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up64 (b:buffer64) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 8}) : Lemma
(scale8 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint64_view in
UV.length_eq vb
val same_mem_get_heap_val64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale8 k in
forall (x:int).{:pattern (mem1.[x])} ptr <= x /\ x < ptr + 8 ==> mem1.[x] == mem2.[x]))
let same_mem_get_heap_val64 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale8 k in
let addr = buffer_addr b h1 in
let aux (x:int{ptr <= x /\ x < ptr + 8}) : Lemma (mem1.[x] == mem2.[x]) =
let i = x - ptr in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices64 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8) (k * 8 + 8)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8) (k * 8 + 8)) in
assert (Seq.index s1 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i));
length_up64 b h1 k i;
assert (mem1.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i)));
assert (Seq.index s2 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i));
length_up64 b h2 k i;
assert (mem2.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i)))
in
Classical.forall_intro aux;
assert (forall i. addr + (scale8 k + i) == ptr + i)
let rec written_buffer_down64_aux1
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(k:nat) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j.{:pattern (mem1.[j]) \/ (mem2.[j])}
base <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem1.[j])}
j >= base /\ j < base + scale8 i ==>
mem1.[j] == mem2.[j]))
(decreases %[i-k]) =
if k >= i then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux1 b i v h base (k+1) h1 mem1 mem2
end
let rec written_buffer_down64_aux2
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(n:nat{n == buffer_length b})
(k:nat{k > i}) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
base + scale8 (i+1) <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
j >= base + scale8 (i+1) /\ j < base + scale8 n ==>
mem1.[j] == mem2.[j]))
(decreases %[n-k]) =
if k >= n then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux2 b i v h base n (k+1) h1 mem1 mem2
end
let written_buffer_down64 (b:buffer64{buffer_writeable b}) (i:nat{i < buffer_length b}) (v:nat64) (h:vale_heap)
: Lemma
(requires List.memP b (IB.ptrs_of_mem (_ih h)))
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
(base <= j /\ j < base + scale8 i) \/
(base + scale8 (i+1) <= j /\ j < base + scale8 n) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
written_buffer_down64_aux1 b i v h base 0 h1 mem1 mem2;
written_buffer_down64_aux2 b i v h base n (i+1) h1 mem1 mem2
let unwritten_buffer_down (t:base_typ) (b:buffer t{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:base_typ_as_vale_type t)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall (a:b8{List.memP a (IB.ptrs_of_mem (_ih h)) /\ a =!= b}) j. {:pattern mem1.[j]; List.memP a (IB.ptrs_of_mem (_ih h)) \/ mem2.[j]; List.memP a (IB.ptrs_of_mem (_ih h))}
let base = (IB.addrs_of_mem (_ih h)) a in
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==> mem1.[j] == mem2.[j]))
= let aux (a:b8{a =!= b /\ List.memP a (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let base = (IB.addrs_of_mem (_ih h)) a in
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall j.
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==>
mem1.[j] == mem2.[j]))
= let db = get_downview a.bsrc in
if DV.length db = 0 then ()
else
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = (IB.addrs_of_mem (_ih h)) a in
let s0 = DV.as_seq (IB.hs_of_mem (_ih h)) db in
let s1 = DV.as_seq (IB.hs_of_mem (_ih h1)) db in
opaque_assert (`%IB.list_disjoint_or_eq) IB.list_disjoint_or_eq IB.list_disjoint_or_eq_def (MB.disjoint a.bsrc b.bsrc);
lemma_dv_equal (IB.down_view a.src) a.bsrc (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1));
assert (Seq.equal s0 s1);
assert (forall (j:int).{:pattern (mem1.[j])}
base <= j /\ j < base + Seq.length s0 ==> v_to_typ TUInt8 (Seq.index s0 (j - base)) == mem1.[j]);
heap_shift mem1 mem2 base (DV.length db)
in
Classical.forall_intro aux
let store_buffer_down64_mem
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
forall (j:int). {:pattern mem1.[j] \/ mem2.[j]}
j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
let aux (j:int)
: Lemma
(j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j])
=
I.addrs_set_lemma_all ();
if j >= base && j < base + DV.length (get_downview b.bsrc) then begin
written_buffer_down64 b i v h;
length_t_eq (TUInt64) b
end
else if not (I.valid_addr (_ih h) j)
then I.same_unspecified_down (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1)) (IB.ptrs_of_mem (_ih h))
else unwritten_buffer_down TUInt64 b i v h
in
Classical.forall_intro aux | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Memory.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.BufferViewStore.fsti.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Memory_Sems.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_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
}
] | {
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
ptr: Prims.int ->
v: Vale.Def.Words_s.nat64 ->
h: Vale.Arch.HeapImpl.vale_heap{Vale.X64.Memory.writeable_mem64 ptr h}
-> FStar.Pervasives.Lemma
(ensures
(let mem1 = Vale.Interop.down_mem (Vale.Arch.HeapImpl._ih h) in
let h1 = Vale.X64.Memory.store_mem Vale.Arch.HeapTypes_s.TUInt64 ptr v h in
let mem2 = Vale.Interop.down_mem (Vale.Arch.HeapImpl._ih h1) in
forall (j: Prims.int). {:pattern mem1.[ j ]\/mem2.[ j ]}
j < ptr \/ j >= ptr + 8 ==> mem1.[ j ] == mem2.[ j ])) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.int",
"Vale.Def.Words_s.nat64",
"Vale.Arch.HeapImpl.vale_heap",
"Prims.b2t",
"Vale.X64.Memory.writeable_mem64",
"Vale.X64.Memory_Sems.store_buffer_down64_mem",
"Prims.unit",
"Prims._assert",
"Prims.eq2",
"Prims.op_Addition",
"Vale.X64.Memory.buffer_addr",
"Vale.X64.Memory.scale8",
"Vale.X64.Memory.store_buffer_write",
"Prims.nat",
"Vale.X64.Memory.get_addr_in_ptr",
"Vale.X64.Memory.buffer_length",
"Vale.X64.Memory.length_t_eq",
"Vale.Arch.HeapImpl.buffer",
"FStar.Pervasives.Native.__proj__Some__item__v",
"Vale.X64.Memory.buffer",
"Vale.X64.Memory.find_writeable_buffer",
"Vale.X64.Memory.store_mem",
"Vale.Arch.HeapTypes_s.base_typ",
"Vale.Arch.HeapTypes_s.TUInt64",
"Prims.l_True",
"Prims.squash",
"Prims.l_Forall",
"Prims.l_imp",
"Prims.l_or",
"Prims.op_LessThan",
"Prims.op_GreaterThanOrEqual",
"Vale.Def.Types_s.nat8",
"Vale.X64.Memory.op_String_Access",
"Vale.Arch.MachineHeap_s.machine_heap",
"Vale.Interop.Heap_s.correct_down",
"Vale.Arch.HeapImpl._ih",
"Vale.Interop.down_mem",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let store_buffer_aux_down64_mem (ptr: int) (v: nat64) (h: vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures
(let mem1 = I.down_mem (_ih h) in
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
forall j. {:pattern mem1.[ j ]\/mem2.[ j ]}
j < ptr \/ j >= ptr + 8 ==> mem1.[ j ] == mem2.[ j ])) =
| let t = TUInt64 in
let h1 = store_mem t ptr v h in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
store_buffer_write t ptr v h;
assert (buffer_addr b h + scale8 i == ptr);
assert (buffer_addr b h + scale8 (i + 1) == ptr + 8);
store_buffer_down64_mem b i v h | false |
Vale.X64.Memory_Sems.fst | Vale.X64.Memory_Sems.written_buffer_down64_aux1 | val written_buffer_down64_aux1
(b: buffer64{buffer_writeable b})
(i: nat{i < buffer_length b})
(v: nat64)
(h: vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base: nat{base == buffer_addr b h})
(k: nat)
(h1: vale_heap{h1 == buffer_write b i v h})
(mem1: S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:
S.machine_heap
{ IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[ j ])\/(mem2.[ j ])}
base <= j /\ j < base + k * 8 ==> mem1.[ j ] == mem2.[ j ]) })
: Lemma
(ensures
(forall j. {:pattern (mem1.[ j ])\/(mem1.[ j ])}
j >= base /\ j < base + scale8 i ==> mem1.[ j ] == mem2.[ j ])) (decreases %[i - k]) | val written_buffer_down64_aux1
(b: buffer64{buffer_writeable b})
(i: nat{i < buffer_length b})
(v: nat64)
(h: vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base: nat{base == buffer_addr b h})
(k: nat)
(h1: vale_heap{h1 == buffer_write b i v h})
(mem1: S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:
S.machine_heap
{ IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[ j ])\/(mem2.[ j ])}
base <= j /\ j < base + k * 8 ==> mem1.[ j ] == mem2.[ j ]) })
: Lemma
(ensures
(forall j. {:pattern (mem1.[ j ])\/(mem1.[ j ])}
j >= base /\ j < base + scale8 i ==> mem1.[ j ] == mem2.[ j ])) (decreases %[i - k]) | let rec written_buffer_down64_aux1
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(k:nat) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j.{:pattern (mem1.[j]) \/ (mem2.[j])}
base <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem1.[j])}
j >= base /\ j < base + scale8 i ==>
mem1.[j] == mem2.[j]))
(decreases %[i-k]) =
if k >= i then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux1 b i v h base (k+1) h1 mem1 mem2
end | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory_Sems.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 7,
"end_line": 290,
"start_col": 0,
"start_line": 267
} | module Vale.X64.Memory_Sems
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.Def.Words_s
module I = Vale.Interop
module S = Vale.X64.Machine_Semantics_s
module MB = LowStar.Monotonic.Buffer
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
friend Vale.X64.Memory
module IB = Vale.Interop.Base
let same_domain h m = Set.equal (IB.addrs_set (_ih h)) (Map.domain m)
let lemma_same_domains h m1 m2 = ()
let get_heap h = I.down_mem (_ih h)
let upd_heap h m = mi_heap_upd h m
//let lemma_upd_get_heap h = I.down_up_identity (_ih h)
let lemma_get_upd_heap h m = I.up_down_identity (_ih h) m
let lemma_heap_impl = ()
let lemma_heap_get_heap h = ()
let lemma_heap_taint h = ()
//let lemma_heap_upd_heap h mh mt = ()
[@"opaque_to_smt"]
let rec set_of_range (a:int) (n:nat) : Pure (Set.set int)
(requires True)
(ensures fun s -> (forall (i:int).{:pattern Set.mem i s} Set.mem i s <==> a <= i /\ i < a + n))
=
if n = 0 then Set.empty else Set.union (set_of_range a (n - 1)) (Set.singleton (a + n - 1))
let buffer_info_has_addr (bi:buffer_info) (a:int) =
let b = bi.bi_buffer in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
addr <= a /\ a < addr + len
let buffer_info_has_addr_opt (bi:option buffer_info) (a:int) =
match bi with
| None -> False
| Some bi -> buffer_info_has_addr bi a
#set-options "--z3rlimit 100"
let rec make_owns_rec (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
if n = 0 then ((fun _ -> None), (fun _ -> Set.empty)) else
let (m0, s0) = make_owns_rec h bs (n - 1) in
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let s i = if i = hi then Set.union (s0 i) s_b else s0 i in
let m a = if addr <= a && a < addr + len then Some (n - 1) else m0 a in
(m, s)
[@"opaque_to_smt"]
let make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
make_owns_rec h bs n
let rec lemma_make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n <= Seq.length bs /\
(forall (i:nat).{:pattern Seq.index bs i} i < Seq.length bs ==> buffer_readable h (Seq.index bs i).bi_buffer) /\
(forall (i1 i2:nat).{:pattern (Seq.index bs i1); (Seq.index bs i2)}
i1 < Seq.length bs /\ i2 < Seq.length bs ==> buffer_info_disjoint (Seq.index bs i1) (Seq.index bs i2))
)
(ensures (
let (m, s) = make_owns h bs n in
(forall (i:heaplet_id) (a:int).{:pattern Set.mem a (s i)}
(Set.mem a (s i) <==> Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (m a) == Some i) /\
(Set.mem a (s i) ==> buffer_info_has_addr_opt (Option.mapTot (fun n -> Seq.index bs n) (m a)) a) /\
(Set.mem a (s i) ==> Set.mem a (Map.domain h.mh))
) /\
(forall (k:nat) (a:int).{:pattern Set.mem a (s (Seq.index bs k).bi_heaplet)}
k < n /\ buffer_info_has_addr (Seq.index bs k) a ==> Set.mem a (s (Seq.index bs k).bi_heaplet))
))
=
reveal_opaque (`%make_owns) make_owns;
if n = 0 then () else
let _ = make_owns h bs (n - 1) in
let (m, s) = make_owns h bs n in
lemma_make_owns h bs (n - 1);
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let lem1 (a:int) : Lemma
(requires Set.mem a s_b)
(ensures Set.mem a (Map.domain h.mh))
[SMTPat (Set.mem a (Map.domain h.mh))]
=
I.addrs_set_mem h.ih b a
in
let lem2 (i:heaplet_id) (a:int) : Lemma
(requires i =!= hi /\ Set.mem a (Set.intersect s_b (s i)))
(ensures False)
[SMTPat (Set.mem a (s i))]
=
reveal_opaque (`%addr_map_pred) addr_map_pred
in
()
#push-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_loc_mutable_buffers_rec (l:list buffer_info) (s:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n + List.length l == Seq.length s /\
list_to_seq_post l s n
)
(ensures (
let modloc = loc_mutable_buffers l in
forall (i:nat).{:pattern Seq.index s i} n <= i /\ i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes modloc (loc_buffer bi.bi_buffer))
))
(decreases l)
=
match l with
| [] -> ()
| h::t -> lemma_loc_mutable_buffers_rec t s (n + 1)
#pop-options
let lemma_loc_mutable_buffers (l:list buffer_info) : Lemma
(ensures (
let s = list_to_seq l in
forall (i:nat).{:pattern Seq.index s i} i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes (loc_mutable_buffers l) (loc_buffer bi.bi_buffer))
))
=
lemma_list_to_seq l;
lemma_loc_mutable_buffers_rec l (list_to_seq l) 0
let create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let modloc = loc_mutable_buffers buffers in
let layout1 = h1.vf_layout in
let layin1 = layout1.vl_inner in
let (hmap, hsets) = make_owns h1.vf_heap bs (Seq.length bs) in
let hmap a = Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (hmap a) in
let l = {
vl_heaplets_initialized = true;
vl_heaplet_map = hmap;
vl_heaplet_sets = hsets;
vl_old_heap = h1.vf_heap;
vl_buffers = bs;
vl_mod_loc = modloc;
} in
let layout2 = {layout1 with vl_inner = l} in
let h2 = {
vf_layout = layout2;
vf_heap = h1.vf_heap;
vf_heaplets = h1.vf_heaplets;
} in
h2
let lemma_create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let h2 = create_heaplets buffers h1 in
assert (h2.vf_layout.vl_inner.vl_buffers == bs); // REVIEW: why is this necessary, even with extra ifuel?
lemma_make_owns h1.vf_heap bs (Seq.length bs);
lemma_loc_mutable_buffers buffers;
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
let destroy_heaplets h1 =
h1
let lemma_destroy_heaplets h1 =
()
val heap_shift (m1 m2:S.machine_heap) (base:int) (n:nat) : Lemma
(requires (forall i. 0 <= i /\ i < n ==> m1.[base + i] == m2.[base + i]))
(ensures (forall i. {:pattern (m1.[i])} base <= i /\ i < base + n ==> m1.[i] == m2.[i]))
#push-options "--smtencoding.l_arith_repr boxwrap"
let heap_shift m1 m2 base n =
assert (forall i. base <= i /\ i < base + n ==>
m1.[base + (i - base)] == m2.[base + (i - base)])
#pop-options
val same_mem_eq_slices64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 8 + 8 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8)))
let same_mem_eq_slices64 b i v k h1 h2 mem1 mem2 =
let t = TUInt64 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up64 (b:buffer64) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 8}) : Lemma
(scale8 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint64_view in
UV.length_eq vb
val same_mem_get_heap_val64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale8 k in
forall (x:int).{:pattern (mem1.[x])} ptr <= x /\ x < ptr + 8 ==> mem1.[x] == mem2.[x]))
let same_mem_get_heap_val64 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale8 k in
let addr = buffer_addr b h1 in
let aux (x:int{ptr <= x /\ x < ptr + 8}) : Lemma (mem1.[x] == mem2.[x]) =
let i = x - ptr in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices64 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8) (k * 8 + 8)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8) (k * 8 + 8)) in
assert (Seq.index s1 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i));
length_up64 b h1 k i;
assert (mem1.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i)));
assert (Seq.index s2 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i));
length_up64 b h2 k i;
assert (mem2.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i)))
in
Classical.forall_intro aux;
assert (forall i. addr + (scale8 k + i) == ptr + i) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Memory.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.BufferViewStore.fsti.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Memory_Sems.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_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
}
] | {
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
b: Vale.X64.Memory.buffer64{Vale.X64.Memory.buffer_writeable b} ->
i: Prims.nat{i < Vale.X64.Memory.buffer_length b} ->
v: Vale.Def.Words_s.nat64 ->
h:
Vale.Arch.HeapImpl.vale_heap
{FStar.List.Tot.Base.memP b (Vale.Interop.Heap_s.ptrs_of_mem (Vale.Arch.HeapImpl._ih h))} ->
base: Prims.nat{base == Vale.X64.Memory.buffer_addr b h} ->
k: Prims.nat ->
h1: Vale.Arch.HeapImpl.vale_heap{h1 == Vale.X64.Memory.buffer_write b i v h} ->
mem1:
Vale.Arch.MachineHeap_s.machine_heap
{Vale.Interop.Heap_s.correct_down (Vale.Arch.HeapImpl._ih h) mem1} ->
mem2:
Vale.Arch.MachineHeap_s.machine_heap
{ Vale.Interop.Heap_s.correct_down (Vale.Arch.HeapImpl._ih h1) mem2 /\
(forall (j: Prims.int). {:pattern mem1.[ j ]\/mem2.[ j ]}
base <= j /\ j < base + k * 8 ==> mem1.[ j ] == mem2.[ j ]) }
-> FStar.Pervasives.Lemma
(ensures
forall (j: Prims.int). {:pattern mem1.[ j ]\/mem1.[ j ]}
j >= base /\ j < base + Vale.X64.Memory.scale8 i ==> mem1.[ j ] == mem2.[ j ])
(decreases i - k) | FStar.Pervasives.Lemma | [
"lemma",
""
] | [] | [
"Vale.X64.Memory.buffer64",
"Vale.X64.Memory.buffer_writeable",
"Vale.X64.Memory.vuint64",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Vale.X64.Memory.buffer_length",
"Vale.Def.Words_s.nat64",
"Vale.Arch.HeapImpl.vale_heap",
"FStar.List.Tot.Base.memP",
"Vale.Interop.Types.b8",
"Vale.Interop.Heap_s.ptrs_of_mem",
"Vale.Arch.HeapImpl._ih",
"Prims.eq2",
"Prims.int",
"Vale.X64.Memory.buffer_addr",
"Vale.X64.Memory.buffer_write",
"Vale.Arch.MachineHeap_s.machine_heap",
"Vale.Interop.Heap_s.correct_down",
"Prims.l_and",
"Prims.l_Forall",
"Prims.l_imp",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition",
"FStar.Mul.op_Star",
"Vale.Def.Types_s.nat8",
"Vale.X64.Memory.op_String_Access",
"Prims.op_GreaterThanOrEqual",
"Prims.bool",
"Vale.X64.Memory_Sems.written_buffer_down64_aux1",
"Prims.unit",
"Vale.X64.Memory_Sems.heap_shift",
"Vale.X64.Memory_Sems.same_mem_get_heap_val64",
"Vale.X64.Memory.scale8",
"Prims.l_True",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [
"recursion"
] | false | false | true | false | false | let rec written_buffer_down64_aux1
(b: buffer64{buffer_writeable b})
(i: nat{i < buffer_length b})
(v: nat64)
(h: vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base: nat{base == buffer_addr b h})
(k: nat)
(h1: vale_heap{h1 == buffer_write b i v h})
(mem1: S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:
S.machine_heap
{ IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[ j ])\/(mem2.[ j ])}
base <= j /\ j < base + k * 8 ==> mem1.[ j ] == mem2.[ j ]) })
: Lemma
(ensures
(forall j. {:pattern (mem1.[ j ])\/(mem1.[ j ])}
j >= base /\ j < base + scale8 i ==> mem1.[ j ] == mem2.[ j ])) (decreases %[i - k]) =
| if k >= i
then ()
else
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux1 b i v h base (k + 1) h1 mem1 mem2 | false |
Vale.X64.Memory_Sems.fst | Vale.X64.Memory_Sems.bytes_valid64 | val bytes_valid64 (i:int) (m:vale_heap) : Lemma
(requires valid_mem64 i m)
(ensures S.valid_addr64 i (get_heap m))
[SMTPat (S.valid_addr64 i (get_heap m))] | val bytes_valid64 (i:int) (m:vale_heap) : Lemma
(requires valid_mem64 i m)
(ensures S.valid_addr64 i (get_heap m))
[SMTPat (S.valid_addr64 i (get_heap m))] | let bytes_valid64 ptr h =
reveal_opaque (`%S.valid_addr64) S.valid_addr64;
let t = TUInt64 in
let b = get_addr_ptr t ptr h in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
in_bounds64 h b i;
I.addrs_set_mem (_ih h) b ptr;
I.addrs_set_mem (_ih h) b (ptr+1);
I.addrs_set_mem (_ih h) b (ptr+2);
I.addrs_set_mem (_ih h) b (ptr+3);
I.addrs_set_mem (_ih h) b (ptr+4);
I.addrs_set_mem (_ih h) b (ptr+5);
I.addrs_set_mem (_ih h) b (ptr+6);
I.addrs_set_mem (_ih h) b (ptr+7) | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory_Sems.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 36,
"end_line": 467,
"start_col": 0,
"start_line": 454
} | module Vale.X64.Memory_Sems
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.Def.Words_s
module I = Vale.Interop
module S = Vale.X64.Machine_Semantics_s
module MB = LowStar.Monotonic.Buffer
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
friend Vale.X64.Memory
module IB = Vale.Interop.Base
let same_domain h m = Set.equal (IB.addrs_set (_ih h)) (Map.domain m)
let lemma_same_domains h m1 m2 = ()
let get_heap h = I.down_mem (_ih h)
let upd_heap h m = mi_heap_upd h m
//let lemma_upd_get_heap h = I.down_up_identity (_ih h)
let lemma_get_upd_heap h m = I.up_down_identity (_ih h) m
let lemma_heap_impl = ()
let lemma_heap_get_heap h = ()
let lemma_heap_taint h = ()
//let lemma_heap_upd_heap h mh mt = ()
[@"opaque_to_smt"]
let rec set_of_range (a:int) (n:nat) : Pure (Set.set int)
(requires True)
(ensures fun s -> (forall (i:int).{:pattern Set.mem i s} Set.mem i s <==> a <= i /\ i < a + n))
=
if n = 0 then Set.empty else Set.union (set_of_range a (n - 1)) (Set.singleton (a + n - 1))
let buffer_info_has_addr (bi:buffer_info) (a:int) =
let b = bi.bi_buffer in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
addr <= a /\ a < addr + len
let buffer_info_has_addr_opt (bi:option buffer_info) (a:int) =
match bi with
| None -> False
| Some bi -> buffer_info_has_addr bi a
#set-options "--z3rlimit 100"
let rec make_owns_rec (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
if n = 0 then ((fun _ -> None), (fun _ -> Set.empty)) else
let (m0, s0) = make_owns_rec h bs (n - 1) in
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let s i = if i = hi then Set.union (s0 i) s_b else s0 i in
let m a = if addr <= a && a < addr + len then Some (n - 1) else m0 a in
(m, s)
[@"opaque_to_smt"]
let make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
make_owns_rec h bs n
let rec lemma_make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n <= Seq.length bs /\
(forall (i:nat).{:pattern Seq.index bs i} i < Seq.length bs ==> buffer_readable h (Seq.index bs i).bi_buffer) /\
(forall (i1 i2:nat).{:pattern (Seq.index bs i1); (Seq.index bs i2)}
i1 < Seq.length bs /\ i2 < Seq.length bs ==> buffer_info_disjoint (Seq.index bs i1) (Seq.index bs i2))
)
(ensures (
let (m, s) = make_owns h bs n in
(forall (i:heaplet_id) (a:int).{:pattern Set.mem a (s i)}
(Set.mem a (s i) <==> Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (m a) == Some i) /\
(Set.mem a (s i) ==> buffer_info_has_addr_opt (Option.mapTot (fun n -> Seq.index bs n) (m a)) a) /\
(Set.mem a (s i) ==> Set.mem a (Map.domain h.mh))
) /\
(forall (k:nat) (a:int).{:pattern Set.mem a (s (Seq.index bs k).bi_heaplet)}
k < n /\ buffer_info_has_addr (Seq.index bs k) a ==> Set.mem a (s (Seq.index bs k).bi_heaplet))
))
=
reveal_opaque (`%make_owns) make_owns;
if n = 0 then () else
let _ = make_owns h bs (n - 1) in
let (m, s) = make_owns h bs n in
lemma_make_owns h bs (n - 1);
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let lem1 (a:int) : Lemma
(requires Set.mem a s_b)
(ensures Set.mem a (Map.domain h.mh))
[SMTPat (Set.mem a (Map.domain h.mh))]
=
I.addrs_set_mem h.ih b a
in
let lem2 (i:heaplet_id) (a:int) : Lemma
(requires i =!= hi /\ Set.mem a (Set.intersect s_b (s i)))
(ensures False)
[SMTPat (Set.mem a (s i))]
=
reveal_opaque (`%addr_map_pred) addr_map_pred
in
()
#push-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_loc_mutable_buffers_rec (l:list buffer_info) (s:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n + List.length l == Seq.length s /\
list_to_seq_post l s n
)
(ensures (
let modloc = loc_mutable_buffers l in
forall (i:nat).{:pattern Seq.index s i} n <= i /\ i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes modloc (loc_buffer bi.bi_buffer))
))
(decreases l)
=
match l with
| [] -> ()
| h::t -> lemma_loc_mutable_buffers_rec t s (n + 1)
#pop-options
let lemma_loc_mutable_buffers (l:list buffer_info) : Lemma
(ensures (
let s = list_to_seq l in
forall (i:nat).{:pattern Seq.index s i} i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes (loc_mutable_buffers l) (loc_buffer bi.bi_buffer))
))
=
lemma_list_to_seq l;
lemma_loc_mutable_buffers_rec l (list_to_seq l) 0
let create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let modloc = loc_mutable_buffers buffers in
let layout1 = h1.vf_layout in
let layin1 = layout1.vl_inner in
let (hmap, hsets) = make_owns h1.vf_heap bs (Seq.length bs) in
let hmap a = Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (hmap a) in
let l = {
vl_heaplets_initialized = true;
vl_heaplet_map = hmap;
vl_heaplet_sets = hsets;
vl_old_heap = h1.vf_heap;
vl_buffers = bs;
vl_mod_loc = modloc;
} in
let layout2 = {layout1 with vl_inner = l} in
let h2 = {
vf_layout = layout2;
vf_heap = h1.vf_heap;
vf_heaplets = h1.vf_heaplets;
} in
h2
let lemma_create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let h2 = create_heaplets buffers h1 in
assert (h2.vf_layout.vl_inner.vl_buffers == bs); // REVIEW: why is this necessary, even with extra ifuel?
lemma_make_owns h1.vf_heap bs (Seq.length bs);
lemma_loc_mutable_buffers buffers;
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
let destroy_heaplets h1 =
h1
let lemma_destroy_heaplets h1 =
()
val heap_shift (m1 m2:S.machine_heap) (base:int) (n:nat) : Lemma
(requires (forall i. 0 <= i /\ i < n ==> m1.[base + i] == m2.[base + i]))
(ensures (forall i. {:pattern (m1.[i])} base <= i /\ i < base + n ==> m1.[i] == m2.[i]))
#push-options "--smtencoding.l_arith_repr boxwrap"
let heap_shift m1 m2 base n =
assert (forall i. base <= i /\ i < base + n ==>
m1.[base + (i - base)] == m2.[base + (i - base)])
#pop-options
val same_mem_eq_slices64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 8 + 8 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8)))
let same_mem_eq_slices64 b i v k h1 h2 mem1 mem2 =
let t = TUInt64 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up64 (b:buffer64) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 8}) : Lemma
(scale8 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint64_view in
UV.length_eq vb
val same_mem_get_heap_val64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale8 k in
forall (x:int).{:pattern (mem1.[x])} ptr <= x /\ x < ptr + 8 ==> mem1.[x] == mem2.[x]))
let same_mem_get_heap_val64 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale8 k in
let addr = buffer_addr b h1 in
let aux (x:int{ptr <= x /\ x < ptr + 8}) : Lemma (mem1.[x] == mem2.[x]) =
let i = x - ptr in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices64 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8) (k * 8 + 8)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8) (k * 8 + 8)) in
assert (Seq.index s1 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i));
length_up64 b h1 k i;
assert (mem1.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i)));
assert (Seq.index s2 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i));
length_up64 b h2 k i;
assert (mem2.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i)))
in
Classical.forall_intro aux;
assert (forall i. addr + (scale8 k + i) == ptr + i)
let rec written_buffer_down64_aux1
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(k:nat) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j.{:pattern (mem1.[j]) \/ (mem2.[j])}
base <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem1.[j])}
j >= base /\ j < base + scale8 i ==>
mem1.[j] == mem2.[j]))
(decreases %[i-k]) =
if k >= i then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux1 b i v h base (k+1) h1 mem1 mem2
end
let rec written_buffer_down64_aux2
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(n:nat{n == buffer_length b})
(k:nat{k > i}) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
base + scale8 (i+1) <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
j >= base + scale8 (i+1) /\ j < base + scale8 n ==>
mem1.[j] == mem2.[j]))
(decreases %[n-k]) =
if k >= n then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux2 b i v h base n (k+1) h1 mem1 mem2
end
let written_buffer_down64 (b:buffer64{buffer_writeable b}) (i:nat{i < buffer_length b}) (v:nat64) (h:vale_heap)
: Lemma
(requires List.memP b (IB.ptrs_of_mem (_ih h)))
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
(base <= j /\ j < base + scale8 i) \/
(base + scale8 (i+1) <= j /\ j < base + scale8 n) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
written_buffer_down64_aux1 b i v h base 0 h1 mem1 mem2;
written_buffer_down64_aux2 b i v h base n (i+1) h1 mem1 mem2
let unwritten_buffer_down (t:base_typ) (b:buffer t{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:base_typ_as_vale_type t)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall (a:b8{List.memP a (IB.ptrs_of_mem (_ih h)) /\ a =!= b}) j. {:pattern mem1.[j]; List.memP a (IB.ptrs_of_mem (_ih h)) \/ mem2.[j]; List.memP a (IB.ptrs_of_mem (_ih h))}
let base = (IB.addrs_of_mem (_ih h)) a in
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==> mem1.[j] == mem2.[j]))
= let aux (a:b8{a =!= b /\ List.memP a (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let base = (IB.addrs_of_mem (_ih h)) a in
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall j.
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==>
mem1.[j] == mem2.[j]))
= let db = get_downview a.bsrc in
if DV.length db = 0 then ()
else
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = (IB.addrs_of_mem (_ih h)) a in
let s0 = DV.as_seq (IB.hs_of_mem (_ih h)) db in
let s1 = DV.as_seq (IB.hs_of_mem (_ih h1)) db in
opaque_assert (`%IB.list_disjoint_or_eq) IB.list_disjoint_or_eq IB.list_disjoint_or_eq_def (MB.disjoint a.bsrc b.bsrc);
lemma_dv_equal (IB.down_view a.src) a.bsrc (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1));
assert (Seq.equal s0 s1);
assert (forall (j:int).{:pattern (mem1.[j])}
base <= j /\ j < base + Seq.length s0 ==> v_to_typ TUInt8 (Seq.index s0 (j - base)) == mem1.[j]);
heap_shift mem1 mem2 base (DV.length db)
in
Classical.forall_intro aux
let store_buffer_down64_mem
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
forall (j:int). {:pattern mem1.[j] \/ mem2.[j]}
j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
let aux (j:int)
: Lemma
(j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j])
=
I.addrs_set_lemma_all ();
if j >= base && j < base + DV.length (get_downview b.bsrc) then begin
written_buffer_down64 b i v h;
length_t_eq (TUInt64) b
end
else if not (I.valid_addr (_ih h) j)
then I.same_unspecified_down (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1)) (IB.ptrs_of_mem (_ih h))
else unwritten_buffer_down TUInt64 b i v h
in
Classical.forall_intro aux
let store_buffer_aux_down64_mem (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
forall j. {:pattern mem1.[j] \/ mem2.[j]}
j < ptr \/ j >= ptr + 8 ==>
mem1.[j] == mem2.[j]))
= let t = TUInt64 in
let h1 = store_mem t ptr v h in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
store_buffer_write t ptr v h;
assert (buffer_addr b h + scale8 i == ptr);
assert (buffer_addr b h + scale8 (i+1) == ptr + 8);
store_buffer_down64_mem b i v h
let store_buffer_aux_down64_mem2 (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
S.get_heap_val64 ptr mem2 == v))
= let t = TUInt64 in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
let h1 = store_mem t ptr v h in
let mem2 = I.down_mem (_ih h1) in
store_buffer_write t ptr v h;
assert (Seq.index (buffer_as_seq h1 b) i == v);
index64_get_heap_val64 h1 b mem2 i
let in_bounds64 (h:vale_heap) (b:buffer64) (i:nat{i < buffer_length b})
: Lemma (scale8 i + 8 <= DV.length (get_downview b.bsrc))
=
length_t_eq TUInt64 b | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Memory.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.BufferViewStore.fsti.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Memory_Sems.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_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
}
] | {
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | i: Prims.int -> m: Vale.Arch.HeapImpl.vale_heap
-> FStar.Pervasives.Lemma (requires Vale.X64.Memory.valid_mem64 i m)
(ensures Vale.Arch.MachineHeap_s.valid_addr64 i (Vale.X64.Memory_Sems.get_heap m))
[SMTPat (Vale.Arch.MachineHeap_s.valid_addr64 i (Vale.X64.Memory_Sems.get_heap m))] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.int",
"Vale.Arch.HeapImpl.vale_heap",
"Vale.Interop.addrs_set_mem",
"Vale.Arch.HeapImpl._ih",
"Prims.op_Addition",
"Prims.unit",
"Vale.X64.Memory_Sems.in_bounds64",
"Prims.nat",
"Vale.X64.Memory.get_addr_in_ptr",
"Vale.X64.Memory.buffer_length",
"Vale.X64.Memory.buffer_addr",
"Vale.Arch.HeapImpl.buffer",
"Vale.X64.Memory.get_addr_ptr",
"Vale.Arch.HeapTypes_s.base_typ",
"Vale.Arch.HeapTypes_s.TUInt64",
"FStar.Pervasives.reveal_opaque",
"Vale.Arch.MachineHeap_s.machine_heap",
"Prims.bool",
"Vale.Arch.MachineHeap_s.valid_addr64"
] | [] | true | false | true | false | false | let bytes_valid64 ptr h =
| reveal_opaque (`%S.valid_addr64) S.valid_addr64;
let t = TUInt64 in
let b = get_addr_ptr t ptr h in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
in_bounds64 h b i;
I.addrs_set_mem (_ih h) b ptr;
I.addrs_set_mem (_ih h) b (ptr + 1);
I.addrs_set_mem (_ih h) b (ptr + 2);
I.addrs_set_mem (_ih h) b (ptr + 3);
I.addrs_set_mem (_ih h) b (ptr + 4);
I.addrs_set_mem (_ih h) b (ptr + 5);
I.addrs_set_mem (_ih h) b (ptr + 6);
I.addrs_set_mem (_ih h) b (ptr + 7) | false |
Vale.X64.Memory_Sems.fst | Vale.X64.Memory_Sems.in_bounds64 | val in_bounds64 (h: vale_heap) (b: buffer64) (i: nat{i < buffer_length b})
: Lemma (scale8 i + 8 <= DV.length (get_downview b.bsrc)) | val in_bounds64 (h: vale_heap) (b: buffer64) (i: nat{i < buffer_length b})
: Lemma (scale8 i + 8 <= DV.length (get_downview b.bsrc)) | let in_bounds64 (h:vale_heap) (b:buffer64) (i:nat{i < buffer_length b})
: Lemma (scale8 i + 8 <= DV.length (get_downview b.bsrc))
=
length_t_eq TUInt64 b | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory_Sems.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 23,
"end_line": 452,
"start_col": 0,
"start_line": 449
} | module Vale.X64.Memory_Sems
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.Def.Words_s
module I = Vale.Interop
module S = Vale.X64.Machine_Semantics_s
module MB = LowStar.Monotonic.Buffer
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
friend Vale.X64.Memory
module IB = Vale.Interop.Base
let same_domain h m = Set.equal (IB.addrs_set (_ih h)) (Map.domain m)
let lemma_same_domains h m1 m2 = ()
let get_heap h = I.down_mem (_ih h)
let upd_heap h m = mi_heap_upd h m
//let lemma_upd_get_heap h = I.down_up_identity (_ih h)
let lemma_get_upd_heap h m = I.up_down_identity (_ih h) m
let lemma_heap_impl = ()
let lemma_heap_get_heap h = ()
let lemma_heap_taint h = ()
//let lemma_heap_upd_heap h mh mt = ()
[@"opaque_to_smt"]
let rec set_of_range (a:int) (n:nat) : Pure (Set.set int)
(requires True)
(ensures fun s -> (forall (i:int).{:pattern Set.mem i s} Set.mem i s <==> a <= i /\ i < a + n))
=
if n = 0 then Set.empty else Set.union (set_of_range a (n - 1)) (Set.singleton (a + n - 1))
let buffer_info_has_addr (bi:buffer_info) (a:int) =
let b = bi.bi_buffer in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
addr <= a /\ a < addr + len
let buffer_info_has_addr_opt (bi:option buffer_info) (a:int) =
match bi with
| None -> False
| Some bi -> buffer_info_has_addr bi a
#set-options "--z3rlimit 100"
let rec make_owns_rec (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
if n = 0 then ((fun _ -> None), (fun _ -> Set.empty)) else
let (m0, s0) = make_owns_rec h bs (n - 1) in
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let s i = if i = hi then Set.union (s0 i) s_b else s0 i in
let m a = if addr <= a && a < addr + len then Some (n - 1) else m0 a in
(m, s)
[@"opaque_to_smt"]
let make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
make_owns_rec h bs n
let rec lemma_make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n <= Seq.length bs /\
(forall (i:nat).{:pattern Seq.index bs i} i < Seq.length bs ==> buffer_readable h (Seq.index bs i).bi_buffer) /\
(forall (i1 i2:nat).{:pattern (Seq.index bs i1); (Seq.index bs i2)}
i1 < Seq.length bs /\ i2 < Seq.length bs ==> buffer_info_disjoint (Seq.index bs i1) (Seq.index bs i2))
)
(ensures (
let (m, s) = make_owns h bs n in
(forall (i:heaplet_id) (a:int).{:pattern Set.mem a (s i)}
(Set.mem a (s i) <==> Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (m a) == Some i) /\
(Set.mem a (s i) ==> buffer_info_has_addr_opt (Option.mapTot (fun n -> Seq.index bs n) (m a)) a) /\
(Set.mem a (s i) ==> Set.mem a (Map.domain h.mh))
) /\
(forall (k:nat) (a:int).{:pattern Set.mem a (s (Seq.index bs k).bi_heaplet)}
k < n /\ buffer_info_has_addr (Seq.index bs k) a ==> Set.mem a (s (Seq.index bs k).bi_heaplet))
))
=
reveal_opaque (`%make_owns) make_owns;
if n = 0 then () else
let _ = make_owns h bs (n - 1) in
let (m, s) = make_owns h bs n in
lemma_make_owns h bs (n - 1);
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let lem1 (a:int) : Lemma
(requires Set.mem a s_b)
(ensures Set.mem a (Map.domain h.mh))
[SMTPat (Set.mem a (Map.domain h.mh))]
=
I.addrs_set_mem h.ih b a
in
let lem2 (i:heaplet_id) (a:int) : Lemma
(requires i =!= hi /\ Set.mem a (Set.intersect s_b (s i)))
(ensures False)
[SMTPat (Set.mem a (s i))]
=
reveal_opaque (`%addr_map_pred) addr_map_pred
in
()
#push-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_loc_mutable_buffers_rec (l:list buffer_info) (s:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n + List.length l == Seq.length s /\
list_to_seq_post l s n
)
(ensures (
let modloc = loc_mutable_buffers l in
forall (i:nat).{:pattern Seq.index s i} n <= i /\ i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes modloc (loc_buffer bi.bi_buffer))
))
(decreases l)
=
match l with
| [] -> ()
| h::t -> lemma_loc_mutable_buffers_rec t s (n + 1)
#pop-options
let lemma_loc_mutable_buffers (l:list buffer_info) : Lemma
(ensures (
let s = list_to_seq l in
forall (i:nat).{:pattern Seq.index s i} i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes (loc_mutable_buffers l) (loc_buffer bi.bi_buffer))
))
=
lemma_list_to_seq l;
lemma_loc_mutable_buffers_rec l (list_to_seq l) 0
let create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let modloc = loc_mutable_buffers buffers in
let layout1 = h1.vf_layout in
let layin1 = layout1.vl_inner in
let (hmap, hsets) = make_owns h1.vf_heap bs (Seq.length bs) in
let hmap a = Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (hmap a) in
let l = {
vl_heaplets_initialized = true;
vl_heaplet_map = hmap;
vl_heaplet_sets = hsets;
vl_old_heap = h1.vf_heap;
vl_buffers = bs;
vl_mod_loc = modloc;
} in
let layout2 = {layout1 with vl_inner = l} in
let h2 = {
vf_layout = layout2;
vf_heap = h1.vf_heap;
vf_heaplets = h1.vf_heaplets;
} in
h2
let lemma_create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let h2 = create_heaplets buffers h1 in
assert (h2.vf_layout.vl_inner.vl_buffers == bs); // REVIEW: why is this necessary, even with extra ifuel?
lemma_make_owns h1.vf_heap bs (Seq.length bs);
lemma_loc_mutable_buffers buffers;
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
let destroy_heaplets h1 =
h1
let lemma_destroy_heaplets h1 =
()
val heap_shift (m1 m2:S.machine_heap) (base:int) (n:nat) : Lemma
(requires (forall i. 0 <= i /\ i < n ==> m1.[base + i] == m2.[base + i]))
(ensures (forall i. {:pattern (m1.[i])} base <= i /\ i < base + n ==> m1.[i] == m2.[i]))
#push-options "--smtencoding.l_arith_repr boxwrap"
let heap_shift m1 m2 base n =
assert (forall i. base <= i /\ i < base + n ==>
m1.[base + (i - base)] == m2.[base + (i - base)])
#pop-options
val same_mem_eq_slices64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 8 + 8 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8)))
let same_mem_eq_slices64 b i v k h1 h2 mem1 mem2 =
let t = TUInt64 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up64 (b:buffer64) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 8}) : Lemma
(scale8 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint64_view in
UV.length_eq vb
val same_mem_get_heap_val64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale8 k in
forall (x:int).{:pattern (mem1.[x])} ptr <= x /\ x < ptr + 8 ==> mem1.[x] == mem2.[x]))
let same_mem_get_heap_val64 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale8 k in
let addr = buffer_addr b h1 in
let aux (x:int{ptr <= x /\ x < ptr + 8}) : Lemma (mem1.[x] == mem2.[x]) =
let i = x - ptr in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices64 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8) (k * 8 + 8)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8) (k * 8 + 8)) in
assert (Seq.index s1 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i));
length_up64 b h1 k i;
assert (mem1.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i)));
assert (Seq.index s2 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i));
length_up64 b h2 k i;
assert (mem2.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i)))
in
Classical.forall_intro aux;
assert (forall i. addr + (scale8 k + i) == ptr + i)
let rec written_buffer_down64_aux1
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(k:nat) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j.{:pattern (mem1.[j]) \/ (mem2.[j])}
base <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem1.[j])}
j >= base /\ j < base + scale8 i ==>
mem1.[j] == mem2.[j]))
(decreases %[i-k]) =
if k >= i then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux1 b i v h base (k+1) h1 mem1 mem2
end
let rec written_buffer_down64_aux2
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(n:nat{n == buffer_length b})
(k:nat{k > i}) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
base + scale8 (i+1) <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
j >= base + scale8 (i+1) /\ j < base + scale8 n ==>
mem1.[j] == mem2.[j]))
(decreases %[n-k]) =
if k >= n then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux2 b i v h base n (k+1) h1 mem1 mem2
end
let written_buffer_down64 (b:buffer64{buffer_writeable b}) (i:nat{i < buffer_length b}) (v:nat64) (h:vale_heap)
: Lemma
(requires List.memP b (IB.ptrs_of_mem (_ih h)))
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
(base <= j /\ j < base + scale8 i) \/
(base + scale8 (i+1) <= j /\ j < base + scale8 n) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
written_buffer_down64_aux1 b i v h base 0 h1 mem1 mem2;
written_buffer_down64_aux2 b i v h base n (i+1) h1 mem1 mem2
let unwritten_buffer_down (t:base_typ) (b:buffer t{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:base_typ_as_vale_type t)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall (a:b8{List.memP a (IB.ptrs_of_mem (_ih h)) /\ a =!= b}) j. {:pattern mem1.[j]; List.memP a (IB.ptrs_of_mem (_ih h)) \/ mem2.[j]; List.memP a (IB.ptrs_of_mem (_ih h))}
let base = (IB.addrs_of_mem (_ih h)) a in
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==> mem1.[j] == mem2.[j]))
= let aux (a:b8{a =!= b /\ List.memP a (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let base = (IB.addrs_of_mem (_ih h)) a in
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall j.
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==>
mem1.[j] == mem2.[j]))
= let db = get_downview a.bsrc in
if DV.length db = 0 then ()
else
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = (IB.addrs_of_mem (_ih h)) a in
let s0 = DV.as_seq (IB.hs_of_mem (_ih h)) db in
let s1 = DV.as_seq (IB.hs_of_mem (_ih h1)) db in
opaque_assert (`%IB.list_disjoint_or_eq) IB.list_disjoint_or_eq IB.list_disjoint_or_eq_def (MB.disjoint a.bsrc b.bsrc);
lemma_dv_equal (IB.down_view a.src) a.bsrc (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1));
assert (Seq.equal s0 s1);
assert (forall (j:int).{:pattern (mem1.[j])}
base <= j /\ j < base + Seq.length s0 ==> v_to_typ TUInt8 (Seq.index s0 (j - base)) == mem1.[j]);
heap_shift mem1 mem2 base (DV.length db)
in
Classical.forall_intro aux
let store_buffer_down64_mem
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
forall (j:int). {:pattern mem1.[j] \/ mem2.[j]}
j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
let aux (j:int)
: Lemma
(j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j])
=
I.addrs_set_lemma_all ();
if j >= base && j < base + DV.length (get_downview b.bsrc) then begin
written_buffer_down64 b i v h;
length_t_eq (TUInt64) b
end
else if not (I.valid_addr (_ih h) j)
then I.same_unspecified_down (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1)) (IB.ptrs_of_mem (_ih h))
else unwritten_buffer_down TUInt64 b i v h
in
Classical.forall_intro aux
let store_buffer_aux_down64_mem (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
forall j. {:pattern mem1.[j] \/ mem2.[j]}
j < ptr \/ j >= ptr + 8 ==>
mem1.[j] == mem2.[j]))
= let t = TUInt64 in
let h1 = store_mem t ptr v h in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
store_buffer_write t ptr v h;
assert (buffer_addr b h + scale8 i == ptr);
assert (buffer_addr b h + scale8 (i+1) == ptr + 8);
store_buffer_down64_mem b i v h
let store_buffer_aux_down64_mem2 (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
S.get_heap_val64 ptr mem2 == v))
= let t = TUInt64 in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
let h1 = store_mem t ptr v h in
let mem2 = I.down_mem (_ih h1) in
store_buffer_write t ptr v h;
assert (Seq.index (buffer_as_seq h1 b) i == v);
index64_get_heap_val64 h1 b mem2 i | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Memory.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.BufferViewStore.fsti.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Memory_Sems.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_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
}
] | {
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
h: Vale.Arch.HeapImpl.vale_heap ->
b: Vale.X64.Memory.buffer64 ->
i: Prims.nat{i < Vale.X64.Memory.buffer_length b}
-> FStar.Pervasives.Lemma
(ensures
Vale.X64.Memory.scale8 i + 8 <=
LowStar.BufferView.Down.length (Vale.Interop.Types.get_downview (Buffer?.bsrc b))) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Arch.HeapImpl.vale_heap",
"Vale.X64.Memory.buffer64",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Vale.X64.Memory.buffer_length",
"Vale.X64.Memory.vuint64",
"Vale.X64.Memory.length_t_eq",
"Vale.Arch.HeapTypes_s.TUInt64",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition",
"Vale.X64.Memory.scale8",
"LowStar.BufferView.Down.length",
"FStar.UInt8.t",
"Vale.Interop.Types.get_downview",
"Vale.Interop.Types.__proj__Buffer__item__src",
"Vale.Interop.Types.b8_preorder",
"Vale.Interop.Types.__proj__Buffer__item__writeable",
"Vale.Interop.Types.base_typ_as_type",
"Vale.Interop.Types.__proj__Buffer__item__bsrc",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let in_bounds64 (h: vale_heap) (b: buffer64) (i: nat{i < buffer_length b})
: Lemma (scale8 i + 8 <= DV.length (get_downview b.bsrc)) =
| length_t_eq TUInt64 b | false |
Vale.X64.Memory_Sems.fst | Vale.X64.Memory_Sems.store_buffer_aux_down64_mem2 | val store_buffer_aux_down64_mem2 (ptr: int) (v: nat64) (h: vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures
(let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
S.get_heap_val64 ptr mem2 == v)) | val store_buffer_aux_down64_mem2 (ptr: int) (v: nat64) (h: vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures
(let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
S.get_heap_val64 ptr mem2 == v)) | let store_buffer_aux_down64_mem2 (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
S.get_heap_val64 ptr mem2 == v))
= let t = TUInt64 in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
let h1 = store_mem t ptr v h in
let mem2 = I.down_mem (_ih h1) in
store_buffer_write t ptr v h;
assert (Seq.index (buffer_as_seq h1 b) i == v);
index64_get_heap_val64 h1 b mem2 i | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory_Sems.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 38,
"end_line": 447,
"start_col": 0,
"start_line": 433
} | module Vale.X64.Memory_Sems
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.Def.Words_s
module I = Vale.Interop
module S = Vale.X64.Machine_Semantics_s
module MB = LowStar.Monotonic.Buffer
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
friend Vale.X64.Memory
module IB = Vale.Interop.Base
let same_domain h m = Set.equal (IB.addrs_set (_ih h)) (Map.domain m)
let lemma_same_domains h m1 m2 = ()
let get_heap h = I.down_mem (_ih h)
let upd_heap h m = mi_heap_upd h m
//let lemma_upd_get_heap h = I.down_up_identity (_ih h)
let lemma_get_upd_heap h m = I.up_down_identity (_ih h) m
let lemma_heap_impl = ()
let lemma_heap_get_heap h = ()
let lemma_heap_taint h = ()
//let lemma_heap_upd_heap h mh mt = ()
[@"opaque_to_smt"]
let rec set_of_range (a:int) (n:nat) : Pure (Set.set int)
(requires True)
(ensures fun s -> (forall (i:int).{:pattern Set.mem i s} Set.mem i s <==> a <= i /\ i < a + n))
=
if n = 0 then Set.empty else Set.union (set_of_range a (n - 1)) (Set.singleton (a + n - 1))
let buffer_info_has_addr (bi:buffer_info) (a:int) =
let b = bi.bi_buffer in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
addr <= a /\ a < addr + len
let buffer_info_has_addr_opt (bi:option buffer_info) (a:int) =
match bi with
| None -> False
| Some bi -> buffer_info_has_addr bi a
#set-options "--z3rlimit 100"
let rec make_owns_rec (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
if n = 0 then ((fun _ -> None), (fun _ -> Set.empty)) else
let (m0, s0) = make_owns_rec h bs (n - 1) in
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let s i = if i = hi then Set.union (s0 i) s_b else s0 i in
let m a = if addr <= a && a < addr + len then Some (n - 1) else m0 a in
(m, s)
[@"opaque_to_smt"]
let make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
make_owns_rec h bs n
let rec lemma_make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n <= Seq.length bs /\
(forall (i:nat).{:pattern Seq.index bs i} i < Seq.length bs ==> buffer_readable h (Seq.index bs i).bi_buffer) /\
(forall (i1 i2:nat).{:pattern (Seq.index bs i1); (Seq.index bs i2)}
i1 < Seq.length bs /\ i2 < Seq.length bs ==> buffer_info_disjoint (Seq.index bs i1) (Seq.index bs i2))
)
(ensures (
let (m, s) = make_owns h bs n in
(forall (i:heaplet_id) (a:int).{:pattern Set.mem a (s i)}
(Set.mem a (s i) <==> Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (m a) == Some i) /\
(Set.mem a (s i) ==> buffer_info_has_addr_opt (Option.mapTot (fun n -> Seq.index bs n) (m a)) a) /\
(Set.mem a (s i) ==> Set.mem a (Map.domain h.mh))
) /\
(forall (k:nat) (a:int).{:pattern Set.mem a (s (Seq.index bs k).bi_heaplet)}
k < n /\ buffer_info_has_addr (Seq.index bs k) a ==> Set.mem a (s (Seq.index bs k).bi_heaplet))
))
=
reveal_opaque (`%make_owns) make_owns;
if n = 0 then () else
let _ = make_owns h bs (n - 1) in
let (m, s) = make_owns h bs n in
lemma_make_owns h bs (n - 1);
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let lem1 (a:int) : Lemma
(requires Set.mem a s_b)
(ensures Set.mem a (Map.domain h.mh))
[SMTPat (Set.mem a (Map.domain h.mh))]
=
I.addrs_set_mem h.ih b a
in
let lem2 (i:heaplet_id) (a:int) : Lemma
(requires i =!= hi /\ Set.mem a (Set.intersect s_b (s i)))
(ensures False)
[SMTPat (Set.mem a (s i))]
=
reveal_opaque (`%addr_map_pred) addr_map_pred
in
()
#push-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_loc_mutable_buffers_rec (l:list buffer_info) (s:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n + List.length l == Seq.length s /\
list_to_seq_post l s n
)
(ensures (
let modloc = loc_mutable_buffers l in
forall (i:nat).{:pattern Seq.index s i} n <= i /\ i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes modloc (loc_buffer bi.bi_buffer))
))
(decreases l)
=
match l with
| [] -> ()
| h::t -> lemma_loc_mutable_buffers_rec t s (n + 1)
#pop-options
let lemma_loc_mutable_buffers (l:list buffer_info) : Lemma
(ensures (
let s = list_to_seq l in
forall (i:nat).{:pattern Seq.index s i} i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes (loc_mutable_buffers l) (loc_buffer bi.bi_buffer))
))
=
lemma_list_to_seq l;
lemma_loc_mutable_buffers_rec l (list_to_seq l) 0
let create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let modloc = loc_mutable_buffers buffers in
let layout1 = h1.vf_layout in
let layin1 = layout1.vl_inner in
let (hmap, hsets) = make_owns h1.vf_heap bs (Seq.length bs) in
let hmap a = Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (hmap a) in
let l = {
vl_heaplets_initialized = true;
vl_heaplet_map = hmap;
vl_heaplet_sets = hsets;
vl_old_heap = h1.vf_heap;
vl_buffers = bs;
vl_mod_loc = modloc;
} in
let layout2 = {layout1 with vl_inner = l} in
let h2 = {
vf_layout = layout2;
vf_heap = h1.vf_heap;
vf_heaplets = h1.vf_heaplets;
} in
h2
let lemma_create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let h2 = create_heaplets buffers h1 in
assert (h2.vf_layout.vl_inner.vl_buffers == bs); // REVIEW: why is this necessary, even with extra ifuel?
lemma_make_owns h1.vf_heap bs (Seq.length bs);
lemma_loc_mutable_buffers buffers;
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
let destroy_heaplets h1 =
h1
let lemma_destroy_heaplets h1 =
()
val heap_shift (m1 m2:S.machine_heap) (base:int) (n:nat) : Lemma
(requires (forall i. 0 <= i /\ i < n ==> m1.[base + i] == m2.[base + i]))
(ensures (forall i. {:pattern (m1.[i])} base <= i /\ i < base + n ==> m1.[i] == m2.[i]))
#push-options "--smtencoding.l_arith_repr boxwrap"
let heap_shift m1 m2 base n =
assert (forall i. base <= i /\ i < base + n ==>
m1.[base + (i - base)] == m2.[base + (i - base)])
#pop-options
val same_mem_eq_slices64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 8 + 8 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8)))
let same_mem_eq_slices64 b i v k h1 h2 mem1 mem2 =
let t = TUInt64 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up64 (b:buffer64) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 8}) : Lemma
(scale8 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint64_view in
UV.length_eq vb
val same_mem_get_heap_val64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale8 k in
forall (x:int).{:pattern (mem1.[x])} ptr <= x /\ x < ptr + 8 ==> mem1.[x] == mem2.[x]))
let same_mem_get_heap_val64 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale8 k in
let addr = buffer_addr b h1 in
let aux (x:int{ptr <= x /\ x < ptr + 8}) : Lemma (mem1.[x] == mem2.[x]) =
let i = x - ptr in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices64 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8) (k * 8 + 8)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8) (k * 8 + 8)) in
assert (Seq.index s1 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i));
length_up64 b h1 k i;
assert (mem1.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i)));
assert (Seq.index s2 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i));
length_up64 b h2 k i;
assert (mem2.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i)))
in
Classical.forall_intro aux;
assert (forall i. addr + (scale8 k + i) == ptr + i)
let rec written_buffer_down64_aux1
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(k:nat) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j.{:pattern (mem1.[j]) \/ (mem2.[j])}
base <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem1.[j])}
j >= base /\ j < base + scale8 i ==>
mem1.[j] == mem2.[j]))
(decreases %[i-k]) =
if k >= i then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux1 b i v h base (k+1) h1 mem1 mem2
end
let rec written_buffer_down64_aux2
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(n:nat{n == buffer_length b})
(k:nat{k > i}) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
base + scale8 (i+1) <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
j >= base + scale8 (i+1) /\ j < base + scale8 n ==>
mem1.[j] == mem2.[j]))
(decreases %[n-k]) =
if k >= n then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux2 b i v h base n (k+1) h1 mem1 mem2
end
let written_buffer_down64 (b:buffer64{buffer_writeable b}) (i:nat{i < buffer_length b}) (v:nat64) (h:vale_heap)
: Lemma
(requires List.memP b (IB.ptrs_of_mem (_ih h)))
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
(base <= j /\ j < base + scale8 i) \/
(base + scale8 (i+1) <= j /\ j < base + scale8 n) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
written_buffer_down64_aux1 b i v h base 0 h1 mem1 mem2;
written_buffer_down64_aux2 b i v h base n (i+1) h1 mem1 mem2
let unwritten_buffer_down (t:base_typ) (b:buffer t{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:base_typ_as_vale_type t)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall (a:b8{List.memP a (IB.ptrs_of_mem (_ih h)) /\ a =!= b}) j. {:pattern mem1.[j]; List.memP a (IB.ptrs_of_mem (_ih h)) \/ mem2.[j]; List.memP a (IB.ptrs_of_mem (_ih h))}
let base = (IB.addrs_of_mem (_ih h)) a in
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==> mem1.[j] == mem2.[j]))
= let aux (a:b8{a =!= b /\ List.memP a (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let base = (IB.addrs_of_mem (_ih h)) a in
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall j.
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==>
mem1.[j] == mem2.[j]))
= let db = get_downview a.bsrc in
if DV.length db = 0 then ()
else
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = (IB.addrs_of_mem (_ih h)) a in
let s0 = DV.as_seq (IB.hs_of_mem (_ih h)) db in
let s1 = DV.as_seq (IB.hs_of_mem (_ih h1)) db in
opaque_assert (`%IB.list_disjoint_or_eq) IB.list_disjoint_or_eq IB.list_disjoint_or_eq_def (MB.disjoint a.bsrc b.bsrc);
lemma_dv_equal (IB.down_view a.src) a.bsrc (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1));
assert (Seq.equal s0 s1);
assert (forall (j:int).{:pattern (mem1.[j])}
base <= j /\ j < base + Seq.length s0 ==> v_to_typ TUInt8 (Seq.index s0 (j - base)) == mem1.[j]);
heap_shift mem1 mem2 base (DV.length db)
in
Classical.forall_intro aux
let store_buffer_down64_mem
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
forall (j:int). {:pattern mem1.[j] \/ mem2.[j]}
j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
let aux (j:int)
: Lemma
(j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j])
=
I.addrs_set_lemma_all ();
if j >= base && j < base + DV.length (get_downview b.bsrc) then begin
written_buffer_down64 b i v h;
length_t_eq (TUInt64) b
end
else if not (I.valid_addr (_ih h) j)
then I.same_unspecified_down (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1)) (IB.ptrs_of_mem (_ih h))
else unwritten_buffer_down TUInt64 b i v h
in
Classical.forall_intro aux
let store_buffer_aux_down64_mem (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
forall j. {:pattern mem1.[j] \/ mem2.[j]}
j < ptr \/ j >= ptr + 8 ==>
mem1.[j] == mem2.[j]))
= let t = TUInt64 in
let h1 = store_mem t ptr v h in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
store_buffer_write t ptr v h;
assert (buffer_addr b h + scale8 i == ptr);
assert (buffer_addr b h + scale8 (i+1) == ptr + 8);
store_buffer_down64_mem b i v h | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Memory.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.BufferViewStore.fsti.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Memory_Sems.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_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
}
] | {
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
ptr: Prims.int ->
v: Vale.Def.Words_s.nat64 ->
h: Vale.Arch.HeapImpl.vale_heap{Vale.X64.Memory.writeable_mem64 ptr h}
-> FStar.Pervasives.Lemma
(ensures
(let h1 = Vale.X64.Memory.store_mem Vale.Arch.HeapTypes_s.TUInt64 ptr v h in
let mem2 = Vale.Interop.down_mem (Vale.Arch.HeapImpl._ih h1) in
Vale.Arch.MachineHeap_s.get_heap_val64 ptr mem2 == v)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.int",
"Vale.Def.Words_s.nat64",
"Vale.Arch.HeapImpl.vale_heap",
"Prims.b2t",
"Vale.X64.Memory.writeable_mem64",
"Vale.X64.Memory.index64_get_heap_val64",
"Prims.unit",
"Prims._assert",
"Prims.eq2",
"Vale.X64.Memory.base_typ_as_vale_type",
"FStar.Seq.Base.index",
"Vale.X64.Memory.buffer_as_seq",
"Vale.X64.Memory.store_buffer_write",
"Vale.Arch.MachineHeap_s.machine_heap",
"Vale.Interop.Heap_s.correct_down",
"Vale.Arch.HeapImpl._ih",
"Vale.Interop.down_mem",
"Vale.X64.Memory.store_mem",
"Prims.nat",
"Vale.X64.Memory.get_addr_in_ptr",
"Vale.X64.Memory.buffer_length",
"Vale.X64.Memory.buffer_addr",
"Vale.X64.Memory.length_t_eq",
"Vale.Arch.HeapImpl.buffer",
"FStar.Pervasives.Native.__proj__Some__item__v",
"Vale.X64.Memory.buffer",
"Vale.X64.Memory.find_writeable_buffer",
"Vale.Arch.HeapTypes_s.base_typ",
"Vale.Arch.HeapTypes_s.TUInt64",
"Prims.l_True",
"Prims.squash",
"Vale.Arch.MachineHeap_s.get_heap_val64",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let store_buffer_aux_down64_mem2 (ptr: int) (v: nat64) (h: vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures
(let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
S.get_heap_val64 ptr mem2 == v)) =
| let t = TUInt64 in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
let h1 = store_mem t ptr v h in
let mem2 = I.down_mem (_ih h1) in
store_buffer_write t ptr v h;
assert (Seq.index (buffer_as_seq h1 b) i == v);
index64_get_heap_val64 h1 b mem2 i | false |
PulseCore.MonotonicStateMonad.fst | PulseCore.MonotonicStateMonad.mst | val mst (#s:Type u#s)
(rel:FStar.Preorder.preorder s)
(a:Type u#a)
(pre:s -> prop)
(post:s -> a -> s -> prop)
: Type u#(max a s) | val mst (#s:Type u#s)
(rel:FStar.Preorder.preorder s)
(a:Type u#a)
(pre:s -> prop)
(post:s -> a -> s -> prop)
: Type u#(max a s) | let mst (#s:Type u#s)
(rel:FStar.Preorder.preorder s)
(a:Type u#a)
(pre:s -> prop)
(post:s -> a -> s -> prop)
= s0:s { pre s0 }
-> Tot (
res:(a & s) {
post s0 res._1 res._2 /\
rel s0 res._2
}
) | {
"file_name": "lib/pulse_core/PulseCore.MonotonicStateMonad.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 5,
"end_line": 15,
"start_col": 0,
"start_line": 4
} | module PulseCore.MonotonicStateMonad
open FStar.Preorder | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.MSTTotal.fst.checked"
],
"interface_file": true,
"source_file": "PulseCore.MonotonicStateMonad.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.MSTTotal",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.MSTTotal",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "PulseCore",
"short_module": null
},
{
"abbrev": false,
"full_module": "PulseCore",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
rel: FStar.Preorder.preorder s ->
a: Type ->
pre: (_: s -> Prims.prop) ->
post: (_: s -> _: a -> _: s -> Prims.prop)
-> Type | Prims.Tot | [
"total"
] | [] | [
"FStar.Preorder.preorder",
"Prims.prop",
"FStar.Pervasives.Native.tuple2",
"Prims.l_and",
"FStar.Pervasives.Native.__proj__Mktuple2__item___1",
"FStar.Pervasives.Native.__proj__Mktuple2__item___2"
] | [] | false | false | false | true | true | let mst
(#s: Type u#s)
(rel: FStar.Preorder.preorder s)
(a: Type u#a)
(pre: (s -> prop))
(post: (s -> a -> s -> prop))
=
| s0: s{pre s0} -> Tot (res: (a & s){post s0 res._1 res._2 /\ rel s0 res._2}) | false |
Vale.X64.Memory_Sems.fst | Vale.X64.Memory_Sems.same_mem_eq_slices64 | val same_mem_eq_slices64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 8 + 8 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8))) | val same_mem_eq_slices64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 8 + 8 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8))) | let same_mem_eq_slices64 b i v k h1 h2 mem1 mem2 =
let t = TUInt64 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory_Sems.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 19,
"end_line": 226,
"start_col": 0,
"start_line": 218
} | module Vale.X64.Memory_Sems
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.Def.Words_s
module I = Vale.Interop
module S = Vale.X64.Machine_Semantics_s
module MB = LowStar.Monotonic.Buffer
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
friend Vale.X64.Memory
module IB = Vale.Interop.Base
let same_domain h m = Set.equal (IB.addrs_set (_ih h)) (Map.domain m)
let lemma_same_domains h m1 m2 = ()
let get_heap h = I.down_mem (_ih h)
let upd_heap h m = mi_heap_upd h m
//let lemma_upd_get_heap h = I.down_up_identity (_ih h)
let lemma_get_upd_heap h m = I.up_down_identity (_ih h) m
let lemma_heap_impl = ()
let lemma_heap_get_heap h = ()
let lemma_heap_taint h = ()
//let lemma_heap_upd_heap h mh mt = ()
[@"opaque_to_smt"]
let rec set_of_range (a:int) (n:nat) : Pure (Set.set int)
(requires True)
(ensures fun s -> (forall (i:int).{:pattern Set.mem i s} Set.mem i s <==> a <= i /\ i < a + n))
=
if n = 0 then Set.empty else Set.union (set_of_range a (n - 1)) (Set.singleton (a + n - 1))
let buffer_info_has_addr (bi:buffer_info) (a:int) =
let b = bi.bi_buffer in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
addr <= a /\ a < addr + len
let buffer_info_has_addr_opt (bi:option buffer_info) (a:int) =
match bi with
| None -> False
| Some bi -> buffer_info_has_addr bi a
#set-options "--z3rlimit 100"
let rec make_owns_rec (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
if n = 0 then ((fun _ -> None), (fun _ -> Set.empty)) else
let (m0, s0) = make_owns_rec h bs (n - 1) in
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let s i = if i = hi then Set.union (s0 i) s_b else s0 i in
let m a = if addr <= a && a < addr + len then Some (n - 1) else m0 a in
(m, s)
[@"opaque_to_smt"]
let make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
make_owns_rec h bs n
let rec lemma_make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n <= Seq.length bs /\
(forall (i:nat).{:pattern Seq.index bs i} i < Seq.length bs ==> buffer_readable h (Seq.index bs i).bi_buffer) /\
(forall (i1 i2:nat).{:pattern (Seq.index bs i1); (Seq.index bs i2)}
i1 < Seq.length bs /\ i2 < Seq.length bs ==> buffer_info_disjoint (Seq.index bs i1) (Seq.index bs i2))
)
(ensures (
let (m, s) = make_owns h bs n in
(forall (i:heaplet_id) (a:int).{:pattern Set.mem a (s i)}
(Set.mem a (s i) <==> Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (m a) == Some i) /\
(Set.mem a (s i) ==> buffer_info_has_addr_opt (Option.mapTot (fun n -> Seq.index bs n) (m a)) a) /\
(Set.mem a (s i) ==> Set.mem a (Map.domain h.mh))
) /\
(forall (k:nat) (a:int).{:pattern Set.mem a (s (Seq.index bs k).bi_heaplet)}
k < n /\ buffer_info_has_addr (Seq.index bs k) a ==> Set.mem a (s (Seq.index bs k).bi_heaplet))
))
=
reveal_opaque (`%make_owns) make_owns;
if n = 0 then () else
let _ = make_owns h bs (n - 1) in
let (m, s) = make_owns h bs n in
lemma_make_owns h bs (n - 1);
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let lem1 (a:int) : Lemma
(requires Set.mem a s_b)
(ensures Set.mem a (Map.domain h.mh))
[SMTPat (Set.mem a (Map.domain h.mh))]
=
I.addrs_set_mem h.ih b a
in
let lem2 (i:heaplet_id) (a:int) : Lemma
(requires i =!= hi /\ Set.mem a (Set.intersect s_b (s i)))
(ensures False)
[SMTPat (Set.mem a (s i))]
=
reveal_opaque (`%addr_map_pred) addr_map_pred
in
()
#push-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_loc_mutable_buffers_rec (l:list buffer_info) (s:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n + List.length l == Seq.length s /\
list_to_seq_post l s n
)
(ensures (
let modloc = loc_mutable_buffers l in
forall (i:nat).{:pattern Seq.index s i} n <= i /\ i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes modloc (loc_buffer bi.bi_buffer))
))
(decreases l)
=
match l with
| [] -> ()
| h::t -> lemma_loc_mutable_buffers_rec t s (n + 1)
#pop-options
let lemma_loc_mutable_buffers (l:list buffer_info) : Lemma
(ensures (
let s = list_to_seq l in
forall (i:nat).{:pattern Seq.index s i} i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes (loc_mutable_buffers l) (loc_buffer bi.bi_buffer))
))
=
lemma_list_to_seq l;
lemma_loc_mutable_buffers_rec l (list_to_seq l) 0
let create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let modloc = loc_mutable_buffers buffers in
let layout1 = h1.vf_layout in
let layin1 = layout1.vl_inner in
let (hmap, hsets) = make_owns h1.vf_heap bs (Seq.length bs) in
let hmap a = Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (hmap a) in
let l = {
vl_heaplets_initialized = true;
vl_heaplet_map = hmap;
vl_heaplet_sets = hsets;
vl_old_heap = h1.vf_heap;
vl_buffers = bs;
vl_mod_loc = modloc;
} in
let layout2 = {layout1 with vl_inner = l} in
let h2 = {
vf_layout = layout2;
vf_heap = h1.vf_heap;
vf_heaplets = h1.vf_heaplets;
} in
h2
let lemma_create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let h2 = create_heaplets buffers h1 in
assert (h2.vf_layout.vl_inner.vl_buffers == bs); // REVIEW: why is this necessary, even with extra ifuel?
lemma_make_owns h1.vf_heap bs (Seq.length bs);
lemma_loc_mutable_buffers buffers;
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
let destroy_heaplets h1 =
h1
let lemma_destroy_heaplets h1 =
()
val heap_shift (m1 m2:S.machine_heap) (base:int) (n:nat) : Lemma
(requires (forall i. 0 <= i /\ i < n ==> m1.[base + i] == m2.[base + i]))
(ensures (forall i. {:pattern (m1.[i])} base <= i /\ i < base + n ==> m1.[i] == m2.[i]))
#push-options "--smtencoding.l_arith_repr boxwrap"
let heap_shift m1 m2 base n =
assert (forall i. base <= i /\ i < base + n ==>
m1.[base + (i - base)] == m2.[base + (i - base)])
#pop-options
val same_mem_eq_slices64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 8 + 8 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8))) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Memory.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.BufferViewStore.fsti.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Memory_Sems.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_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
}
] | {
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
b: Vale.X64.Memory.buffer64{Vale.X64.Memory.buffer_writeable b} ->
i: Prims.nat{i < Vale.X64.Memory.buffer_length b} ->
v: Vale.Def.Words_s.nat64 ->
k: Prims.nat{k < Vale.X64.Memory.buffer_length b} ->
h1:
Vale.Arch.HeapImpl.vale_heap
{FStar.List.Tot.Base.memP b (Vale.Interop.Heap_s.ptrs_of_mem (Vale.Arch.HeapImpl._ih h1))} ->
h2: Vale.Arch.HeapImpl.vale_heap{h2 == Vale.X64.Memory.buffer_write b i v h1} ->
mem1:
Vale.Arch.MachineHeap_s.machine_heap
{Vale.Interop.Heap_s.correct_down_p (Vale.Arch.HeapImpl._ih h1) mem1 b} ->
mem2:
Vale.Arch.MachineHeap_s.machine_heap
{Vale.Interop.Heap_s.correct_down_p (Vale.Arch.HeapImpl._ih h2) mem2 b}
-> FStar.Pervasives.Lemma
(requires
FStar.Seq.Base.index (Vale.X64.Memory.buffer_as_seq h1 b) k ==
FStar.Seq.Base.index (Vale.X64.Memory.buffer_as_seq h2 b) k)
(ensures
k * 8 + 8 <=
LowStar.BufferView.Down.length (Vale.Interop.Types.get_downview (Buffer?.bsrc b)) /\
FStar.Seq.Base.slice (LowStar.BufferView.Down.as_seq (Vale.Interop.Heap_s.hs_of_mem (Vale.Arch.HeapImpl._ih
h1))
(Vale.Interop.Types.get_downview (Buffer?.bsrc b)))
(k * 8)
(k * 8 + 8) ==
FStar.Seq.Base.slice (LowStar.BufferView.Down.as_seq (Vale.Interop.Heap_s.hs_of_mem (Vale.Arch.HeapImpl._ih
h2))
(Vale.Interop.Types.get_downview (Buffer?.bsrc b)))
(k * 8)
(k * 8 + 8)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.X64.Memory.buffer64",
"Vale.X64.Memory.buffer_writeable",
"Vale.X64.Memory.vuint64",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Vale.X64.Memory.buffer_length",
"Vale.Def.Words_s.nat64",
"Vale.Arch.HeapImpl.vale_heap",
"FStar.List.Tot.Base.memP",
"Vale.Interop.Types.b8",
"Vale.Interop.Heap_s.ptrs_of_mem",
"Vale.Arch.HeapImpl._ih",
"Prims.eq2",
"Vale.X64.Memory.buffer_write",
"Vale.Arch.MachineHeap_s.machine_heap",
"Vale.Interop.Heap_s.correct_down_p",
"LowStar.BufferView.Up.length_eq",
"Vale.Interop.Types.base_typ_as_type",
"Prims.unit",
"LowStar.BufferView.Up.put_sel",
"Vale.Interop.Heap_s.hs_of_mem",
"LowStar.BufferView.Up.as_seq_sel",
"LowStar.BufferView.Up.buffer",
"LowStar.BufferView.Up.mk_buffer",
"FStar.UInt8.t",
"Vale.X64.Memory.uint_view",
"LowStar.BufferView.Down.buffer",
"Vale.Interop.Types.get_downview",
"Vale.Interop.Types.__proj__Buffer__item__src",
"Vale.Interop.Types.b8_preorder",
"Vale.Interop.Types.__proj__Buffer__item__writeable",
"Vale.Interop.Types.__proj__Buffer__item__bsrc",
"Vale.Arch.HeapTypes_s.base_typ",
"Vale.Arch.HeapTypes_s.TUInt64"
] | [] | true | false | true | false | false | let same_mem_eq_slices64 b i v k h1 h2 mem1 mem2 =
| let t = TUInt64 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub | false |
Vale.X64.Memory_Sems.fst | Vale.X64.Memory_Sems.equiv_load_mem128 | val equiv_load_mem128 (ptr:int) (m:vale_heap) : Lemma
(requires valid_mem128 ptr m)
(ensures load_mem128 ptr m == S.get_heap_val128 ptr (get_heap m)) | val equiv_load_mem128 (ptr:int) (m:vale_heap) : Lemma
(requires valid_mem128 ptr m)
(ensures load_mem128 ptr m == S.get_heap_val128 ptr (get_heap m)) | let equiv_load_mem128 ptr h =
equiv_load_mem128_aux ptr h | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory_Sems.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 29,
"end_line": 753,
"start_col": 0,
"start_line": 752
} | module Vale.X64.Memory_Sems
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.Def.Words_s
module I = Vale.Interop
module S = Vale.X64.Machine_Semantics_s
module MB = LowStar.Monotonic.Buffer
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
friend Vale.X64.Memory
module IB = Vale.Interop.Base
let same_domain h m = Set.equal (IB.addrs_set (_ih h)) (Map.domain m)
let lemma_same_domains h m1 m2 = ()
let get_heap h = I.down_mem (_ih h)
let upd_heap h m = mi_heap_upd h m
//let lemma_upd_get_heap h = I.down_up_identity (_ih h)
let lemma_get_upd_heap h m = I.up_down_identity (_ih h) m
let lemma_heap_impl = ()
let lemma_heap_get_heap h = ()
let lemma_heap_taint h = ()
//let lemma_heap_upd_heap h mh mt = ()
[@"opaque_to_smt"]
let rec set_of_range (a:int) (n:nat) : Pure (Set.set int)
(requires True)
(ensures fun s -> (forall (i:int).{:pattern Set.mem i s} Set.mem i s <==> a <= i /\ i < a + n))
=
if n = 0 then Set.empty else Set.union (set_of_range a (n - 1)) (Set.singleton (a + n - 1))
let buffer_info_has_addr (bi:buffer_info) (a:int) =
let b = bi.bi_buffer in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
addr <= a /\ a < addr + len
let buffer_info_has_addr_opt (bi:option buffer_info) (a:int) =
match bi with
| None -> False
| Some bi -> buffer_info_has_addr bi a
#set-options "--z3rlimit 100"
let rec make_owns_rec (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
if n = 0 then ((fun _ -> None), (fun _ -> Set.empty)) else
let (m0, s0) = make_owns_rec h bs (n - 1) in
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let s i = if i = hi then Set.union (s0 i) s_b else s0 i in
let m a = if addr <= a && a < addr + len then Some (n - 1) else m0 a in
(m, s)
[@"opaque_to_smt"]
let make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
make_owns_rec h bs n
let rec lemma_make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n <= Seq.length bs /\
(forall (i:nat).{:pattern Seq.index bs i} i < Seq.length bs ==> buffer_readable h (Seq.index bs i).bi_buffer) /\
(forall (i1 i2:nat).{:pattern (Seq.index bs i1); (Seq.index bs i2)}
i1 < Seq.length bs /\ i2 < Seq.length bs ==> buffer_info_disjoint (Seq.index bs i1) (Seq.index bs i2))
)
(ensures (
let (m, s) = make_owns h bs n in
(forall (i:heaplet_id) (a:int).{:pattern Set.mem a (s i)}
(Set.mem a (s i) <==> Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (m a) == Some i) /\
(Set.mem a (s i) ==> buffer_info_has_addr_opt (Option.mapTot (fun n -> Seq.index bs n) (m a)) a) /\
(Set.mem a (s i) ==> Set.mem a (Map.domain h.mh))
) /\
(forall (k:nat) (a:int).{:pattern Set.mem a (s (Seq.index bs k).bi_heaplet)}
k < n /\ buffer_info_has_addr (Seq.index bs k) a ==> Set.mem a (s (Seq.index bs k).bi_heaplet))
))
=
reveal_opaque (`%make_owns) make_owns;
if n = 0 then () else
let _ = make_owns h bs (n - 1) in
let (m, s) = make_owns h bs n in
lemma_make_owns h bs (n - 1);
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let lem1 (a:int) : Lemma
(requires Set.mem a s_b)
(ensures Set.mem a (Map.domain h.mh))
[SMTPat (Set.mem a (Map.domain h.mh))]
=
I.addrs_set_mem h.ih b a
in
let lem2 (i:heaplet_id) (a:int) : Lemma
(requires i =!= hi /\ Set.mem a (Set.intersect s_b (s i)))
(ensures False)
[SMTPat (Set.mem a (s i))]
=
reveal_opaque (`%addr_map_pred) addr_map_pred
in
()
#push-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_loc_mutable_buffers_rec (l:list buffer_info) (s:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n + List.length l == Seq.length s /\
list_to_seq_post l s n
)
(ensures (
let modloc = loc_mutable_buffers l in
forall (i:nat).{:pattern Seq.index s i} n <= i /\ i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes modloc (loc_buffer bi.bi_buffer))
))
(decreases l)
=
match l with
| [] -> ()
| h::t -> lemma_loc_mutable_buffers_rec t s (n + 1)
#pop-options
let lemma_loc_mutable_buffers (l:list buffer_info) : Lemma
(ensures (
let s = list_to_seq l in
forall (i:nat).{:pattern Seq.index s i} i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes (loc_mutable_buffers l) (loc_buffer bi.bi_buffer))
))
=
lemma_list_to_seq l;
lemma_loc_mutable_buffers_rec l (list_to_seq l) 0
let create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let modloc = loc_mutable_buffers buffers in
let layout1 = h1.vf_layout in
let layin1 = layout1.vl_inner in
let (hmap, hsets) = make_owns h1.vf_heap bs (Seq.length bs) in
let hmap a = Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (hmap a) in
let l = {
vl_heaplets_initialized = true;
vl_heaplet_map = hmap;
vl_heaplet_sets = hsets;
vl_old_heap = h1.vf_heap;
vl_buffers = bs;
vl_mod_loc = modloc;
} in
let layout2 = {layout1 with vl_inner = l} in
let h2 = {
vf_layout = layout2;
vf_heap = h1.vf_heap;
vf_heaplets = h1.vf_heaplets;
} in
h2
let lemma_create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let h2 = create_heaplets buffers h1 in
assert (h2.vf_layout.vl_inner.vl_buffers == bs); // REVIEW: why is this necessary, even with extra ifuel?
lemma_make_owns h1.vf_heap bs (Seq.length bs);
lemma_loc_mutable_buffers buffers;
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
let destroy_heaplets h1 =
h1
let lemma_destroy_heaplets h1 =
()
val heap_shift (m1 m2:S.machine_heap) (base:int) (n:nat) : Lemma
(requires (forall i. 0 <= i /\ i < n ==> m1.[base + i] == m2.[base + i]))
(ensures (forall i. {:pattern (m1.[i])} base <= i /\ i < base + n ==> m1.[i] == m2.[i]))
#push-options "--smtencoding.l_arith_repr boxwrap"
let heap_shift m1 m2 base n =
assert (forall i. base <= i /\ i < base + n ==>
m1.[base + (i - base)] == m2.[base + (i - base)])
#pop-options
val same_mem_eq_slices64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 8 + 8 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8)))
let same_mem_eq_slices64 b i v k h1 h2 mem1 mem2 =
let t = TUInt64 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up64 (b:buffer64) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 8}) : Lemma
(scale8 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint64_view in
UV.length_eq vb
val same_mem_get_heap_val64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale8 k in
forall (x:int).{:pattern (mem1.[x])} ptr <= x /\ x < ptr + 8 ==> mem1.[x] == mem2.[x]))
let same_mem_get_heap_val64 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale8 k in
let addr = buffer_addr b h1 in
let aux (x:int{ptr <= x /\ x < ptr + 8}) : Lemma (mem1.[x] == mem2.[x]) =
let i = x - ptr in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices64 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8) (k * 8 + 8)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8) (k * 8 + 8)) in
assert (Seq.index s1 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i));
length_up64 b h1 k i;
assert (mem1.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i)));
assert (Seq.index s2 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i));
length_up64 b h2 k i;
assert (mem2.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i)))
in
Classical.forall_intro aux;
assert (forall i. addr + (scale8 k + i) == ptr + i)
let rec written_buffer_down64_aux1
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(k:nat) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j.{:pattern (mem1.[j]) \/ (mem2.[j])}
base <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem1.[j])}
j >= base /\ j < base + scale8 i ==>
mem1.[j] == mem2.[j]))
(decreases %[i-k]) =
if k >= i then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux1 b i v h base (k+1) h1 mem1 mem2
end
let rec written_buffer_down64_aux2
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(n:nat{n == buffer_length b})
(k:nat{k > i}) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
base + scale8 (i+1) <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
j >= base + scale8 (i+1) /\ j < base + scale8 n ==>
mem1.[j] == mem2.[j]))
(decreases %[n-k]) =
if k >= n then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux2 b i v h base n (k+1) h1 mem1 mem2
end
let written_buffer_down64 (b:buffer64{buffer_writeable b}) (i:nat{i < buffer_length b}) (v:nat64) (h:vale_heap)
: Lemma
(requires List.memP b (IB.ptrs_of_mem (_ih h)))
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
(base <= j /\ j < base + scale8 i) \/
(base + scale8 (i+1) <= j /\ j < base + scale8 n) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
written_buffer_down64_aux1 b i v h base 0 h1 mem1 mem2;
written_buffer_down64_aux2 b i v h base n (i+1) h1 mem1 mem2
let unwritten_buffer_down (t:base_typ) (b:buffer t{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:base_typ_as_vale_type t)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall (a:b8{List.memP a (IB.ptrs_of_mem (_ih h)) /\ a =!= b}) j. {:pattern mem1.[j]; List.memP a (IB.ptrs_of_mem (_ih h)) \/ mem2.[j]; List.memP a (IB.ptrs_of_mem (_ih h))}
let base = (IB.addrs_of_mem (_ih h)) a in
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==> mem1.[j] == mem2.[j]))
= let aux (a:b8{a =!= b /\ List.memP a (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let base = (IB.addrs_of_mem (_ih h)) a in
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall j.
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==>
mem1.[j] == mem2.[j]))
= let db = get_downview a.bsrc in
if DV.length db = 0 then ()
else
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = (IB.addrs_of_mem (_ih h)) a in
let s0 = DV.as_seq (IB.hs_of_mem (_ih h)) db in
let s1 = DV.as_seq (IB.hs_of_mem (_ih h1)) db in
opaque_assert (`%IB.list_disjoint_or_eq) IB.list_disjoint_or_eq IB.list_disjoint_or_eq_def (MB.disjoint a.bsrc b.bsrc);
lemma_dv_equal (IB.down_view a.src) a.bsrc (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1));
assert (Seq.equal s0 s1);
assert (forall (j:int).{:pattern (mem1.[j])}
base <= j /\ j < base + Seq.length s0 ==> v_to_typ TUInt8 (Seq.index s0 (j - base)) == mem1.[j]);
heap_shift mem1 mem2 base (DV.length db)
in
Classical.forall_intro aux
let store_buffer_down64_mem
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
forall (j:int). {:pattern mem1.[j] \/ mem2.[j]}
j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
let aux (j:int)
: Lemma
(j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j])
=
I.addrs_set_lemma_all ();
if j >= base && j < base + DV.length (get_downview b.bsrc) then begin
written_buffer_down64 b i v h;
length_t_eq (TUInt64) b
end
else if not (I.valid_addr (_ih h) j)
then I.same_unspecified_down (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1)) (IB.ptrs_of_mem (_ih h))
else unwritten_buffer_down TUInt64 b i v h
in
Classical.forall_intro aux
let store_buffer_aux_down64_mem (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
forall j. {:pattern mem1.[j] \/ mem2.[j]}
j < ptr \/ j >= ptr + 8 ==>
mem1.[j] == mem2.[j]))
= let t = TUInt64 in
let h1 = store_mem t ptr v h in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
store_buffer_write t ptr v h;
assert (buffer_addr b h + scale8 i == ptr);
assert (buffer_addr b h + scale8 (i+1) == ptr + 8);
store_buffer_down64_mem b i v h
let store_buffer_aux_down64_mem2 (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
S.get_heap_val64 ptr mem2 == v))
= let t = TUInt64 in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
let h1 = store_mem t ptr v h in
let mem2 = I.down_mem (_ih h1) in
store_buffer_write t ptr v h;
assert (Seq.index (buffer_as_seq h1 b) i == v);
index64_get_heap_val64 h1 b mem2 i
let in_bounds64 (h:vale_heap) (b:buffer64) (i:nat{i < buffer_length b})
: Lemma (scale8 i + 8 <= DV.length (get_downview b.bsrc))
=
length_t_eq TUInt64 b
let bytes_valid64 ptr h =
reveal_opaque (`%S.valid_addr64) S.valid_addr64;
let t = TUInt64 in
let b = get_addr_ptr t ptr h in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
in_bounds64 h b i;
I.addrs_set_mem (_ih h) b ptr;
I.addrs_set_mem (_ih h) b (ptr+1);
I.addrs_set_mem (_ih h) b (ptr+2);
I.addrs_set_mem (_ih h) b (ptr+3);
I.addrs_set_mem (_ih h) b (ptr+4);
I.addrs_set_mem (_ih h) b (ptr+5);
I.addrs_set_mem (_ih h) b (ptr+6);
I.addrs_set_mem (_ih h) b (ptr+7)
val same_mem_get_heap_val128 (b:buffer128)
(i:nat{i < buffer_length b})
(v:quad32)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1)) /\ buffer_writeable b})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale16 k in
forall i.{:pattern mem1.[i]} i >= ptr /\ i < ptr+16 ==> mem1.[i] == mem2.[i]))
val same_mem_eq_slices128 (b:buffer128)
(i:nat{i < buffer_length b})
(v:quad32)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1)) /\ buffer_writeable b})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 16 + 16 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 16) (k * 16 + 16) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 16) (k * 16 + 16)))
let same_mem_eq_slices128 b i v k h1 h2 mem1 mem2 =
let t = TUInt128 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up128 (b:buffer128) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 16}) : Lemma
(scale16 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint128_view in
UV.length_eq vb
let same_mem_get_heap_val128 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale16 k in
let addr = buffer_addr b h1 in
let aux (i:nat{ptr <= i /\ i < ptr+16}) : Lemma (mem1.[i] == mem2.[i]) =
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint128_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices128 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16) (k * 16 + 16)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16) (k * 16 + 16)) in
assert (Seq.index s1 (i - ptr) == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16 + (i-ptr)));
length_up128 b h1 k (i-ptr);
assert (mem1.[i] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16 + (i-ptr))));
assert (Seq.index s2 (i-ptr) == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16 + (i-ptr)));
length_up128 b h2 k (i-ptr);
assert (mem2.[addr+(scale16 k + (i-ptr))] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16 + (i-ptr))));
assert (forall i. addr + (scale16 k + (i-ptr)) == i)
in
Classical.forall_intro aux
let in_bounds128 (h:vale_heap) (b:buffer128) (i:nat{i < buffer_length b}) : Lemma
(scale16 i + 16 <= DV.length (get_downview b.bsrc))
=
length_t_eq TUInt128 b
#push-options "--z3rlimit 20"
#restart-solver
let bytes_valid128 ptr h =
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
IB.list_disjoint_or_eq_reveal ();
let t = TUInt128 in
let b = get_addr_ptr t ptr h in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
in_bounds128 h b i;
I.addrs_set_mem (_ih h) b ptr;
I.addrs_set_mem (_ih h) b (ptr+1);
I.addrs_set_mem (_ih h) b (ptr+2);
I.addrs_set_mem (_ih h) b (ptr+3);
I.addrs_set_mem (_ih h) b (ptr+4);
I.addrs_set_mem (_ih h) b (ptr+5);
I.addrs_set_mem (_ih h) b (ptr+6);
I.addrs_set_mem (_ih h) b (ptr+7);
I.addrs_set_mem (_ih h) b (ptr+8);
I.addrs_set_mem (_ih h) b (ptr+9);
I.addrs_set_mem (_ih h) b (ptr+10);
I.addrs_set_mem (_ih h) b (ptr+11);
I.addrs_set_mem (_ih h) b (ptr+12);
I.addrs_set_mem (_ih h) b (ptr+13);
I.addrs_set_mem (_ih h) b (ptr+14);
I.addrs_set_mem (_ih h) b (ptr+15)
#pop-options
let equiv_load_mem64 ptr h =
let t = TUInt64 in
let b = get_addr_ptr t ptr h in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
let addr = buffer_addr b h in
let contents = DV.as_seq (_ih h).IB.hs (get_downview b.bsrc) in
let heap = get_heap h in
index64_get_heap_val64 h b heap i;
lemma_load_mem64 b i h
//let low_lemma_valid_mem64 b i h =
// lemma_valid_mem64 b i h;
// bytes_valid64 (buffer_addr b h + scale8 i) h
//let low_lemma_load_mem64 b i h =
// lemma_valid_mem64 b i h;
// lemma_load_mem64 b i h;
// equiv_load_mem64 (buffer_addr b h + scale8 i) h
//let same_domain_update64 b i v h =
// low_lemma_valid_mem64 b i h;
// Vale.Arch.MachineHeap.same_domain_update64 (buffer_addr b h + scale8 i) v (get_heap h)
open Vale.X64.BufferViewStore
let low_lemma_store_mem64_aux
(b:buffer64)
(heap:S.machine_heap)
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{buffer_readable h b /\ buffer_writeable b})
: Lemma
(requires IB.correct_down_p (_ih h) heap b)
(ensures (let heap' = S.update_heap64 (buffer_addr b h + scale8 i) v heap in
let h' = store_mem64 (buffer_addr b h + scale8 i) v h in
(_ih h').IB.hs == DV.upd_seq (_ih h).IB.hs (get_downview b.bsrc) (I.get_seq_heap heap' (_ih h).IB.addrs b))) =
let ptr = buffer_addr b h + scale8 i in
let heap' = S.update_heap64 ptr v heap in
let h' = store_mem64 ptr v h in
lemma_store_mem64 b i v h;
length_t_eq TUInt64 b;
bv_upd_update_heap64 b heap i v (_ih h);
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db Vale.Interop.Views.up_view64 in
assert (UV.upd (_ih h).IB.hs bv i (UInt64.uint_to_t v) == (_ih h').IB.hs)
val valid_state_store_mem64_aux: (i:nat) -> (v:nat64) -> (h:vale_heap) -> Lemma
(requires writeable_mem64 i h)
(ensures (
let heap = get_heap h in
let heap' = S.update_heap64 i v heap in
let h' = store_mem64 i v h in
heap' == I.down_mem (_ih h')
))
let valid_state_store_mem64_aux i v h =
let heap = get_heap h in
let heap' = S.update_heap64 i v heap in
let h1 = store_mem TUInt64 i v h in
store_buffer_aux_down64_mem i v h;
store_buffer_aux_down64_mem2 i v h;
let mem1 = heap' in
let mem2 = I.down_mem (_ih h1) in
let aux () : Lemma (forall j. mem1.[j] == mem2.[j]) =
Vale.Arch.MachineHeap.same_mem_get_heap_val64 i mem1 mem2;
Vale.Arch.MachineHeap.correct_update_get64 i v heap;
Vale.Arch.MachineHeap.frame_update_heap64 i v heap
in let aux2 () : Lemma (Set.equal (Map.domain mem1) (Map.domain mem2)) =
bytes_valid64 i h;
Vale.Arch.MachineHeap.same_domain_update64 i v heap
in aux(); aux2();
Map.lemma_equal_intro mem1 mem2
let low_lemma_load_mem64_full b i vfh t hid =
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
#push-options "--z3rlimit 20"
#restart-solver
let low_lemma_store_mem64 b i v h =
lemma_writeable_mem64 b i h;
lemma_store_mem64 b i v h;
valid_state_store_mem64_aux (buffer_addr b h + scale8 i) v h;
let heap = get_heap h in
let heap' = S.update_heap64 (buffer_addr b h + scale8 i) v heap in
low_lemma_store_mem64_aux b heap i v h;
Vale.Arch.MachineHeap.frame_update_heap64 (buffer_addr b h + scale8 i) v heap;
in_bounds64 h b i;
I.addrs_set_lemma_all ();
I.update_buffer_up_mem (_ih h) b heap heap'
#pop-options
#set-options "--z3rlimit 100"
#restart-solver
let lemma_is_full_update
(vfh:vale_full_heap) (h hk hk':vale_heap) (k:heaplet_id) (mh mh' mhk mhk':machine_heap) (mt mt':memtaint)
(t:base_typ) (b:buffer t) (ptr:int) (v_size:nat)
(index:nat) (v:base_typ_as_vale_type t) (tn:taint)
: Lemma
(requires
vfh.vf_layout.vl_inner.vl_heaplets_initialized /\
mem_inv vfh /\
buffer_readable hk b /\
buffer_writeable b /\
index < Seq.length (buffer_as_seq hk b) /\
mt == vfh.vf_layout.vl_taint /\
h == vfh.vf_heap /\
hk == Map16.sel vfh.vf_heaplets k /\
mh == h.mh /\
mhk == hk.mh /\
ptr == buffer_addr b hk + scale_by v_size index /\
mt' == S.update_n ptr v_size (heap_taint (coerce vfh)) tn /\
hk' == buffer_write b index v hk /\
valid_layout_buffer b vfh.vf_layout hk true /\
valid_taint_buf b hk mt tn /\
is_machine_heap_update mh mh' /\ upd_heap h mh' == buffer_write b index v h /\
is_machine_heap_update mhk mhk' /\ upd_heap hk mhk' == buffer_write b index v hk /\
(forall j.{:pattern mh.[j] \/ mh'.[j]} j < ptr \/ j >= ptr + v_size ==> mh.[j] == mh'.[j]) /\
(forall j.{:pattern mhk.[j] \/ mhk'.[j]} j < ptr \/ j >= ptr + v_size ==> mhk.[j] == mhk'.[j]) /\
0 <= scale_by v_size index /\ scale_by v_size index + v_size <= DV.length (get_downview b.bsrc) /\
(forall i.{:pattern mh'.[i] \/ mhk'.[i]} i >= ptr /\ i < ptr + v_size ==> mh'.[i] == mhk'.[i]) /\
True
)
(ensures is_full_update vfh hk' k mh' mt')
=
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
let vfh' = coerce (heap_upd (coerce vfh) mh' mt') in
let dom_upd = Set.intersect (vfh.vf_layout.vl_inner.vl_heaplet_sets k) (Map.domain mhk) in
let mhk'' = Map.concat mhk (Map.restrict dom_upd mh') in
assert (Map.equal mhk'' mhk');
let unchanged (j:heaplet_id) : Lemma
(requires j =!= k)
(ensures Map16.sel vfh'.vf_heaplets j == Map16.sel vfh.vf_heaplets j)
[SMTPat (Map16.sel vfh'.vf_heaplets j)]
=
assert (Map.equal (Map16.sel vfh'.vf_heaplets j).mh (Map16.sel vfh.vf_heaplets j).mh);
I.down_up_identity (Map16.sel vfh.vf_heaplets j).ih;
()
in
assert (Map16.equal vfh'.vf_heaplets (Map16.upd vfh.vf_heaplets k hk'));
assert (Map.equal mt' mt);
Vale.Interop.Heap_s.list_disjoint_or_eq_reveal ();
()
let low_lemma_store_mem64_full b i v vfh t hid =
let (h, mt, hk) = (vfh.vf_heap, vfh.vf_layout.vl_taint, Map16.get vfh.vf_heaplets hid) in
let ptr = buffer_addr b hk + scale8 i in
let mh' = S.update_heap64 ptr v (heap_get (coerce vfh)) in
let mt' = S.update_n ptr 8 (heap_taint (coerce vfh)) t in
let hk' = buffer_write b i v hk in
let mhk' = S.update_heap64 ptr v (get_heap hk) in
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
low_lemma_store_mem64 b i v h;
low_lemma_store_mem64 b i v (Map16.get vfh.vf_heaplets hid);
Vale.Arch.MachineHeap.frame_update_heap64 ptr v h.mh;
Vale.Arch.MachineHeap.frame_update_heap64 ptr v hk.mh;
in_bounds64 hk b i;
Vale.Arch.MachineHeap.same_mem_get_heap_val64 ptr mh' mhk';
lemma_is_full_update vfh h hk hk' hid h.mh mh' hk.mh mhk' mt mt' TUInt64 b ptr 8 i v t;
()
val low_lemma_valid_mem128 (b:buffer128) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b
)
(ensures
S.valid_addr128 (buffer_addr b h + scale16 i) (get_heap h)
)
let low_lemma_valid_mem128 b i h =
lemma_valid_mem128 b i h;
bytes_valid128 (buffer_addr b h + scale16 i) h
val equiv_load_mem128_aux: (ptr:int) -> (h:vale_heap) -> Lemma
(requires valid_mem128 ptr h)
(ensures load_mem128 ptr h == S.get_heap_val128 ptr (get_heap h))
let equiv_load_mem128_aux ptr h =
let t = TUInt128 in
let b = get_addr_ptr t ptr h in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
let addr = buffer_addr b h in
let contents = DV.as_seq (_ih h).IB.hs (get_downview b.bsrc) in
let heap = get_heap h in
S.get_heap_val128_reveal ();
index128_get_heap_val128 h b heap i;
lemma_load_mem128 b i h | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Memory.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.BufferViewStore.fsti.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Memory_Sems.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.BufferViewStore",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_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
}
] | {
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | ptr: Prims.int -> m: Vale.Arch.HeapImpl.vale_heap
-> FStar.Pervasives.Lemma (requires Vale.X64.Memory.valid_mem128 ptr m)
(ensures
Vale.X64.Memory.load_mem128 ptr m ==
Vale.Arch.MachineHeap_s.get_heap_val128 ptr (Vale.X64.Memory_Sems.get_heap m)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.int",
"Vale.Arch.HeapImpl.vale_heap",
"Vale.X64.Memory_Sems.equiv_load_mem128_aux",
"Prims.unit"
] | [] | true | false | true | false | false | let equiv_load_mem128 ptr h =
| equiv_load_mem128_aux ptr h | false |
Vale.X64.Memory_Sems.fst | Vale.X64.Memory_Sems.bytes_valid128 | val bytes_valid128 (i:int) (m:vale_heap) : Lemma
(requires valid_mem128 i m)
(ensures S.valid_addr128 i (get_heap m))
[SMTPat (S.valid_addr128 i (get_heap m))] | val bytes_valid128 (i:int) (m:vale_heap) : Lemma
(requires valid_mem128 i m)
(ensures S.valid_addr128 i (get_heap m))
[SMTPat (S.valid_addr128 i (get_heap m))] | let bytes_valid128 ptr h =
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
IB.list_disjoint_or_eq_reveal ();
let t = TUInt128 in
let b = get_addr_ptr t ptr h in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
in_bounds128 h b i;
I.addrs_set_mem (_ih h) b ptr;
I.addrs_set_mem (_ih h) b (ptr+1);
I.addrs_set_mem (_ih h) b (ptr+2);
I.addrs_set_mem (_ih h) b (ptr+3);
I.addrs_set_mem (_ih h) b (ptr+4);
I.addrs_set_mem (_ih h) b (ptr+5);
I.addrs_set_mem (_ih h) b (ptr+6);
I.addrs_set_mem (_ih h) b (ptr+7);
I.addrs_set_mem (_ih h) b (ptr+8);
I.addrs_set_mem (_ih h) b (ptr+9);
I.addrs_set_mem (_ih h) b (ptr+10);
I.addrs_set_mem (_ih h) b (ptr+11);
I.addrs_set_mem (_ih h) b (ptr+12);
I.addrs_set_mem (_ih h) b (ptr+13);
I.addrs_set_mem (_ih h) b (ptr+14);
I.addrs_set_mem (_ih h) b (ptr+15) | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory_Sems.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 36,
"end_line": 560,
"start_col": 0,
"start_line": 538
} | module Vale.X64.Memory_Sems
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.Def.Words_s
module I = Vale.Interop
module S = Vale.X64.Machine_Semantics_s
module MB = LowStar.Monotonic.Buffer
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
friend Vale.X64.Memory
module IB = Vale.Interop.Base
let same_domain h m = Set.equal (IB.addrs_set (_ih h)) (Map.domain m)
let lemma_same_domains h m1 m2 = ()
let get_heap h = I.down_mem (_ih h)
let upd_heap h m = mi_heap_upd h m
//let lemma_upd_get_heap h = I.down_up_identity (_ih h)
let lemma_get_upd_heap h m = I.up_down_identity (_ih h) m
let lemma_heap_impl = ()
let lemma_heap_get_heap h = ()
let lemma_heap_taint h = ()
//let lemma_heap_upd_heap h mh mt = ()
[@"opaque_to_smt"]
let rec set_of_range (a:int) (n:nat) : Pure (Set.set int)
(requires True)
(ensures fun s -> (forall (i:int).{:pattern Set.mem i s} Set.mem i s <==> a <= i /\ i < a + n))
=
if n = 0 then Set.empty else Set.union (set_of_range a (n - 1)) (Set.singleton (a + n - 1))
let buffer_info_has_addr (bi:buffer_info) (a:int) =
let b = bi.bi_buffer in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
addr <= a /\ a < addr + len
let buffer_info_has_addr_opt (bi:option buffer_info) (a:int) =
match bi with
| None -> False
| Some bi -> buffer_info_has_addr bi a
#set-options "--z3rlimit 100"
let rec make_owns_rec (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
if n = 0 then ((fun _ -> None), (fun _ -> Set.empty)) else
let (m0, s0) = make_owns_rec h bs (n - 1) in
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let s i = if i = hi then Set.union (s0 i) s_b else s0 i in
let m a = if addr <= a && a < addr + len then Some (n - 1) else m0 a in
(m, s)
[@"opaque_to_smt"]
let make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
make_owns_rec h bs n
let rec lemma_make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n <= Seq.length bs /\
(forall (i:nat).{:pattern Seq.index bs i} i < Seq.length bs ==> buffer_readable h (Seq.index bs i).bi_buffer) /\
(forall (i1 i2:nat).{:pattern (Seq.index bs i1); (Seq.index bs i2)}
i1 < Seq.length bs /\ i2 < Seq.length bs ==> buffer_info_disjoint (Seq.index bs i1) (Seq.index bs i2))
)
(ensures (
let (m, s) = make_owns h bs n in
(forall (i:heaplet_id) (a:int).{:pattern Set.mem a (s i)}
(Set.mem a (s i) <==> Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (m a) == Some i) /\
(Set.mem a (s i) ==> buffer_info_has_addr_opt (Option.mapTot (fun n -> Seq.index bs n) (m a)) a) /\
(Set.mem a (s i) ==> Set.mem a (Map.domain h.mh))
) /\
(forall (k:nat) (a:int).{:pattern Set.mem a (s (Seq.index bs k).bi_heaplet)}
k < n /\ buffer_info_has_addr (Seq.index bs k) a ==> Set.mem a (s (Seq.index bs k).bi_heaplet))
))
=
reveal_opaque (`%make_owns) make_owns;
if n = 0 then () else
let _ = make_owns h bs (n - 1) in
let (m, s) = make_owns h bs n in
lemma_make_owns h bs (n - 1);
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let lem1 (a:int) : Lemma
(requires Set.mem a s_b)
(ensures Set.mem a (Map.domain h.mh))
[SMTPat (Set.mem a (Map.domain h.mh))]
=
I.addrs_set_mem h.ih b a
in
let lem2 (i:heaplet_id) (a:int) : Lemma
(requires i =!= hi /\ Set.mem a (Set.intersect s_b (s i)))
(ensures False)
[SMTPat (Set.mem a (s i))]
=
reveal_opaque (`%addr_map_pred) addr_map_pred
in
()
#push-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_loc_mutable_buffers_rec (l:list buffer_info) (s:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n + List.length l == Seq.length s /\
list_to_seq_post l s n
)
(ensures (
let modloc = loc_mutable_buffers l in
forall (i:nat).{:pattern Seq.index s i} n <= i /\ i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes modloc (loc_buffer bi.bi_buffer))
))
(decreases l)
=
match l with
| [] -> ()
| h::t -> lemma_loc_mutable_buffers_rec t s (n + 1)
#pop-options
let lemma_loc_mutable_buffers (l:list buffer_info) : Lemma
(ensures (
let s = list_to_seq l in
forall (i:nat).{:pattern Seq.index s i} i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes (loc_mutable_buffers l) (loc_buffer bi.bi_buffer))
))
=
lemma_list_to_seq l;
lemma_loc_mutable_buffers_rec l (list_to_seq l) 0
let create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let modloc = loc_mutable_buffers buffers in
let layout1 = h1.vf_layout in
let layin1 = layout1.vl_inner in
let (hmap, hsets) = make_owns h1.vf_heap bs (Seq.length bs) in
let hmap a = Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (hmap a) in
let l = {
vl_heaplets_initialized = true;
vl_heaplet_map = hmap;
vl_heaplet_sets = hsets;
vl_old_heap = h1.vf_heap;
vl_buffers = bs;
vl_mod_loc = modloc;
} in
let layout2 = {layout1 with vl_inner = l} in
let h2 = {
vf_layout = layout2;
vf_heap = h1.vf_heap;
vf_heaplets = h1.vf_heaplets;
} in
h2
let lemma_create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let h2 = create_heaplets buffers h1 in
assert (h2.vf_layout.vl_inner.vl_buffers == bs); // REVIEW: why is this necessary, even with extra ifuel?
lemma_make_owns h1.vf_heap bs (Seq.length bs);
lemma_loc_mutable_buffers buffers;
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
let destroy_heaplets h1 =
h1
let lemma_destroy_heaplets h1 =
()
val heap_shift (m1 m2:S.machine_heap) (base:int) (n:nat) : Lemma
(requires (forall i. 0 <= i /\ i < n ==> m1.[base + i] == m2.[base + i]))
(ensures (forall i. {:pattern (m1.[i])} base <= i /\ i < base + n ==> m1.[i] == m2.[i]))
#push-options "--smtencoding.l_arith_repr boxwrap"
let heap_shift m1 m2 base n =
assert (forall i. base <= i /\ i < base + n ==>
m1.[base + (i - base)] == m2.[base + (i - base)])
#pop-options
val same_mem_eq_slices64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 8 + 8 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8)))
let same_mem_eq_slices64 b i v k h1 h2 mem1 mem2 =
let t = TUInt64 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up64 (b:buffer64) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 8}) : Lemma
(scale8 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint64_view in
UV.length_eq vb
val same_mem_get_heap_val64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale8 k in
forall (x:int).{:pattern (mem1.[x])} ptr <= x /\ x < ptr + 8 ==> mem1.[x] == mem2.[x]))
let same_mem_get_heap_val64 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale8 k in
let addr = buffer_addr b h1 in
let aux (x:int{ptr <= x /\ x < ptr + 8}) : Lemma (mem1.[x] == mem2.[x]) =
let i = x - ptr in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices64 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8) (k * 8 + 8)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8) (k * 8 + 8)) in
assert (Seq.index s1 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i));
length_up64 b h1 k i;
assert (mem1.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i)));
assert (Seq.index s2 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i));
length_up64 b h2 k i;
assert (mem2.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i)))
in
Classical.forall_intro aux;
assert (forall i. addr + (scale8 k + i) == ptr + i)
let rec written_buffer_down64_aux1
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(k:nat) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j.{:pattern (mem1.[j]) \/ (mem2.[j])}
base <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem1.[j])}
j >= base /\ j < base + scale8 i ==>
mem1.[j] == mem2.[j]))
(decreases %[i-k]) =
if k >= i then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux1 b i v h base (k+1) h1 mem1 mem2
end
let rec written_buffer_down64_aux2
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(n:nat{n == buffer_length b})
(k:nat{k > i}) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
base + scale8 (i+1) <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
j >= base + scale8 (i+1) /\ j < base + scale8 n ==>
mem1.[j] == mem2.[j]))
(decreases %[n-k]) =
if k >= n then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux2 b i v h base n (k+1) h1 mem1 mem2
end
let written_buffer_down64 (b:buffer64{buffer_writeable b}) (i:nat{i < buffer_length b}) (v:nat64) (h:vale_heap)
: Lemma
(requires List.memP b (IB.ptrs_of_mem (_ih h)))
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
(base <= j /\ j < base + scale8 i) \/
(base + scale8 (i+1) <= j /\ j < base + scale8 n) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
written_buffer_down64_aux1 b i v h base 0 h1 mem1 mem2;
written_buffer_down64_aux2 b i v h base n (i+1) h1 mem1 mem2
let unwritten_buffer_down (t:base_typ) (b:buffer t{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:base_typ_as_vale_type t)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall (a:b8{List.memP a (IB.ptrs_of_mem (_ih h)) /\ a =!= b}) j. {:pattern mem1.[j]; List.memP a (IB.ptrs_of_mem (_ih h)) \/ mem2.[j]; List.memP a (IB.ptrs_of_mem (_ih h))}
let base = (IB.addrs_of_mem (_ih h)) a in
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==> mem1.[j] == mem2.[j]))
= let aux (a:b8{a =!= b /\ List.memP a (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let base = (IB.addrs_of_mem (_ih h)) a in
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall j.
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==>
mem1.[j] == mem2.[j]))
= let db = get_downview a.bsrc in
if DV.length db = 0 then ()
else
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = (IB.addrs_of_mem (_ih h)) a in
let s0 = DV.as_seq (IB.hs_of_mem (_ih h)) db in
let s1 = DV.as_seq (IB.hs_of_mem (_ih h1)) db in
opaque_assert (`%IB.list_disjoint_or_eq) IB.list_disjoint_or_eq IB.list_disjoint_or_eq_def (MB.disjoint a.bsrc b.bsrc);
lemma_dv_equal (IB.down_view a.src) a.bsrc (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1));
assert (Seq.equal s0 s1);
assert (forall (j:int).{:pattern (mem1.[j])}
base <= j /\ j < base + Seq.length s0 ==> v_to_typ TUInt8 (Seq.index s0 (j - base)) == mem1.[j]);
heap_shift mem1 mem2 base (DV.length db)
in
Classical.forall_intro aux
let store_buffer_down64_mem
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
forall (j:int). {:pattern mem1.[j] \/ mem2.[j]}
j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
let aux (j:int)
: Lemma
(j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j])
=
I.addrs_set_lemma_all ();
if j >= base && j < base + DV.length (get_downview b.bsrc) then begin
written_buffer_down64 b i v h;
length_t_eq (TUInt64) b
end
else if not (I.valid_addr (_ih h) j)
then I.same_unspecified_down (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1)) (IB.ptrs_of_mem (_ih h))
else unwritten_buffer_down TUInt64 b i v h
in
Classical.forall_intro aux
let store_buffer_aux_down64_mem (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
forall j. {:pattern mem1.[j] \/ mem2.[j]}
j < ptr \/ j >= ptr + 8 ==>
mem1.[j] == mem2.[j]))
= let t = TUInt64 in
let h1 = store_mem t ptr v h in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
store_buffer_write t ptr v h;
assert (buffer_addr b h + scale8 i == ptr);
assert (buffer_addr b h + scale8 (i+1) == ptr + 8);
store_buffer_down64_mem b i v h
let store_buffer_aux_down64_mem2 (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
S.get_heap_val64 ptr mem2 == v))
= let t = TUInt64 in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
let h1 = store_mem t ptr v h in
let mem2 = I.down_mem (_ih h1) in
store_buffer_write t ptr v h;
assert (Seq.index (buffer_as_seq h1 b) i == v);
index64_get_heap_val64 h1 b mem2 i
let in_bounds64 (h:vale_heap) (b:buffer64) (i:nat{i < buffer_length b})
: Lemma (scale8 i + 8 <= DV.length (get_downview b.bsrc))
=
length_t_eq TUInt64 b
let bytes_valid64 ptr h =
reveal_opaque (`%S.valid_addr64) S.valid_addr64;
let t = TUInt64 in
let b = get_addr_ptr t ptr h in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
in_bounds64 h b i;
I.addrs_set_mem (_ih h) b ptr;
I.addrs_set_mem (_ih h) b (ptr+1);
I.addrs_set_mem (_ih h) b (ptr+2);
I.addrs_set_mem (_ih h) b (ptr+3);
I.addrs_set_mem (_ih h) b (ptr+4);
I.addrs_set_mem (_ih h) b (ptr+5);
I.addrs_set_mem (_ih h) b (ptr+6);
I.addrs_set_mem (_ih h) b (ptr+7)
val same_mem_get_heap_val128 (b:buffer128)
(i:nat{i < buffer_length b})
(v:quad32)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1)) /\ buffer_writeable b})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale16 k in
forall i.{:pattern mem1.[i]} i >= ptr /\ i < ptr+16 ==> mem1.[i] == mem2.[i]))
val same_mem_eq_slices128 (b:buffer128)
(i:nat{i < buffer_length b})
(v:quad32)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1)) /\ buffer_writeable b})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 16 + 16 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 16) (k * 16 + 16) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 16) (k * 16 + 16)))
let same_mem_eq_slices128 b i v k h1 h2 mem1 mem2 =
let t = TUInt128 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up128 (b:buffer128) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 16}) : Lemma
(scale16 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint128_view in
UV.length_eq vb
let same_mem_get_heap_val128 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale16 k in
let addr = buffer_addr b h1 in
let aux (i:nat{ptr <= i /\ i < ptr+16}) : Lemma (mem1.[i] == mem2.[i]) =
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint128_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices128 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16) (k * 16 + 16)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16) (k * 16 + 16)) in
assert (Seq.index s1 (i - ptr) == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16 + (i-ptr)));
length_up128 b h1 k (i-ptr);
assert (mem1.[i] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16 + (i-ptr))));
assert (Seq.index s2 (i-ptr) == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16 + (i-ptr)));
length_up128 b h2 k (i-ptr);
assert (mem2.[addr+(scale16 k + (i-ptr))] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16 + (i-ptr))));
assert (forall i. addr + (scale16 k + (i-ptr)) == i)
in
Classical.forall_intro aux
let in_bounds128 (h:vale_heap) (b:buffer128) (i:nat{i < buffer_length b}) : Lemma
(scale16 i + 16 <= DV.length (get_downview b.bsrc))
=
length_t_eq TUInt128 b
#push-options "--z3rlimit 20" | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Memory.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.BufferViewStore.fsti.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Memory_Sems.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_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
}
] | {
"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": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | i: Prims.int -> m: Vale.Arch.HeapImpl.vale_heap
-> FStar.Pervasives.Lemma (requires Vale.X64.Memory.valid_mem128 i m)
(ensures Vale.Arch.MachineHeap_s.valid_addr128 i (Vale.X64.Memory_Sems.get_heap m))
[SMTPat (Vale.Arch.MachineHeap_s.valid_addr128 i (Vale.X64.Memory_Sems.get_heap m))] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.int",
"Vale.Arch.HeapImpl.vale_heap",
"Vale.Interop.addrs_set_mem",
"Vale.Arch.HeapImpl._ih",
"Prims.op_Addition",
"Prims.unit",
"Vale.X64.Memory_Sems.in_bounds128",
"Prims.nat",
"Vale.X64.Memory.get_addr_in_ptr",
"Vale.X64.Memory.buffer_length",
"Vale.X64.Memory.buffer_addr",
"Vale.Arch.HeapImpl.buffer",
"Vale.X64.Memory.get_addr_ptr",
"Vale.Arch.HeapTypes_s.base_typ",
"Vale.Arch.HeapTypes_s.TUInt128",
"Vale.Interop.Heap_s.list_disjoint_or_eq_reveal",
"FStar.Pervasives.reveal_opaque",
"Vale.Arch.MachineHeap_s.machine_heap",
"Prims.bool",
"Vale.Arch.MachineHeap_s.valid_addr128"
] | [] | true | false | true | false | false | let bytes_valid128 ptr h =
| reveal_opaque (`%S.valid_addr128) S.valid_addr128;
IB.list_disjoint_or_eq_reveal ();
let t = TUInt128 in
let b = get_addr_ptr t ptr h in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
in_bounds128 h b i;
I.addrs_set_mem (_ih h) b ptr;
I.addrs_set_mem (_ih h) b (ptr + 1);
I.addrs_set_mem (_ih h) b (ptr + 2);
I.addrs_set_mem (_ih h) b (ptr + 3);
I.addrs_set_mem (_ih h) b (ptr + 4);
I.addrs_set_mem (_ih h) b (ptr + 5);
I.addrs_set_mem (_ih h) b (ptr + 6);
I.addrs_set_mem (_ih h) b (ptr + 7);
I.addrs_set_mem (_ih h) b (ptr + 8);
I.addrs_set_mem (_ih h) b (ptr + 9);
I.addrs_set_mem (_ih h) b (ptr + 10);
I.addrs_set_mem (_ih h) b (ptr + 11);
I.addrs_set_mem (_ih h) b (ptr + 12);
I.addrs_set_mem (_ih h) b (ptr + 13);
I.addrs_set_mem (_ih h) b (ptr + 14);
I.addrs_set_mem (_ih h) b (ptr + 15) | false |
Vale.X64.Memory_Sems.fst | Vale.X64.Memory_Sems.in_bounds128 | val in_bounds128 (h: vale_heap) (b: buffer128) (i: nat{i < buffer_length b})
: Lemma (scale16 i + 16 <= DV.length (get_downview b.bsrc)) | val in_bounds128 (h: vale_heap) (b: buffer128) (i: nat{i < buffer_length b})
: Lemma (scale16 i + 16 <= DV.length (get_downview b.bsrc)) | let in_bounds128 (h:vale_heap) (b:buffer128) (i:nat{i < buffer_length b}) : Lemma
(scale16 i + 16 <= DV.length (get_downview b.bsrc))
=
length_t_eq TUInt128 b | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory_Sems.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 24,
"end_line": 534,
"start_col": 0,
"start_line": 531
} | module Vale.X64.Memory_Sems
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.Def.Words_s
module I = Vale.Interop
module S = Vale.X64.Machine_Semantics_s
module MB = LowStar.Monotonic.Buffer
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
friend Vale.X64.Memory
module IB = Vale.Interop.Base
let same_domain h m = Set.equal (IB.addrs_set (_ih h)) (Map.domain m)
let lemma_same_domains h m1 m2 = ()
let get_heap h = I.down_mem (_ih h)
let upd_heap h m = mi_heap_upd h m
//let lemma_upd_get_heap h = I.down_up_identity (_ih h)
let lemma_get_upd_heap h m = I.up_down_identity (_ih h) m
let lemma_heap_impl = ()
let lemma_heap_get_heap h = ()
let lemma_heap_taint h = ()
//let lemma_heap_upd_heap h mh mt = ()
[@"opaque_to_smt"]
let rec set_of_range (a:int) (n:nat) : Pure (Set.set int)
(requires True)
(ensures fun s -> (forall (i:int).{:pattern Set.mem i s} Set.mem i s <==> a <= i /\ i < a + n))
=
if n = 0 then Set.empty else Set.union (set_of_range a (n - 1)) (Set.singleton (a + n - 1))
let buffer_info_has_addr (bi:buffer_info) (a:int) =
let b = bi.bi_buffer in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
addr <= a /\ a < addr + len
let buffer_info_has_addr_opt (bi:option buffer_info) (a:int) =
match bi with
| None -> False
| Some bi -> buffer_info_has_addr bi a
#set-options "--z3rlimit 100"
let rec make_owns_rec (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
if n = 0 then ((fun _ -> None), (fun _ -> Set.empty)) else
let (m0, s0) = make_owns_rec h bs (n - 1) in
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let s i = if i = hi then Set.union (s0 i) s_b else s0 i in
let m a = if addr <= a && a < addr + len then Some (n - 1) else m0 a in
(m, s)
[@"opaque_to_smt"]
let make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
make_owns_rec h bs n
let rec lemma_make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n <= Seq.length bs /\
(forall (i:nat).{:pattern Seq.index bs i} i < Seq.length bs ==> buffer_readable h (Seq.index bs i).bi_buffer) /\
(forall (i1 i2:nat).{:pattern (Seq.index bs i1); (Seq.index bs i2)}
i1 < Seq.length bs /\ i2 < Seq.length bs ==> buffer_info_disjoint (Seq.index bs i1) (Seq.index bs i2))
)
(ensures (
let (m, s) = make_owns h bs n in
(forall (i:heaplet_id) (a:int).{:pattern Set.mem a (s i)}
(Set.mem a (s i) <==> Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (m a) == Some i) /\
(Set.mem a (s i) ==> buffer_info_has_addr_opt (Option.mapTot (fun n -> Seq.index bs n) (m a)) a) /\
(Set.mem a (s i) ==> Set.mem a (Map.domain h.mh))
) /\
(forall (k:nat) (a:int).{:pattern Set.mem a (s (Seq.index bs k).bi_heaplet)}
k < n /\ buffer_info_has_addr (Seq.index bs k) a ==> Set.mem a (s (Seq.index bs k).bi_heaplet))
))
=
reveal_opaque (`%make_owns) make_owns;
if n = 0 then () else
let _ = make_owns h bs (n - 1) in
let (m, s) = make_owns h bs n in
lemma_make_owns h bs (n - 1);
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let lem1 (a:int) : Lemma
(requires Set.mem a s_b)
(ensures Set.mem a (Map.domain h.mh))
[SMTPat (Set.mem a (Map.domain h.mh))]
=
I.addrs_set_mem h.ih b a
in
let lem2 (i:heaplet_id) (a:int) : Lemma
(requires i =!= hi /\ Set.mem a (Set.intersect s_b (s i)))
(ensures False)
[SMTPat (Set.mem a (s i))]
=
reveal_opaque (`%addr_map_pred) addr_map_pred
in
()
#push-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_loc_mutable_buffers_rec (l:list buffer_info) (s:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n + List.length l == Seq.length s /\
list_to_seq_post l s n
)
(ensures (
let modloc = loc_mutable_buffers l in
forall (i:nat).{:pattern Seq.index s i} n <= i /\ i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes modloc (loc_buffer bi.bi_buffer))
))
(decreases l)
=
match l with
| [] -> ()
| h::t -> lemma_loc_mutable_buffers_rec t s (n + 1)
#pop-options
let lemma_loc_mutable_buffers (l:list buffer_info) : Lemma
(ensures (
let s = list_to_seq l in
forall (i:nat).{:pattern Seq.index s i} i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes (loc_mutable_buffers l) (loc_buffer bi.bi_buffer))
))
=
lemma_list_to_seq l;
lemma_loc_mutable_buffers_rec l (list_to_seq l) 0
let create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let modloc = loc_mutable_buffers buffers in
let layout1 = h1.vf_layout in
let layin1 = layout1.vl_inner in
let (hmap, hsets) = make_owns h1.vf_heap bs (Seq.length bs) in
let hmap a = Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (hmap a) in
let l = {
vl_heaplets_initialized = true;
vl_heaplet_map = hmap;
vl_heaplet_sets = hsets;
vl_old_heap = h1.vf_heap;
vl_buffers = bs;
vl_mod_loc = modloc;
} in
let layout2 = {layout1 with vl_inner = l} in
let h2 = {
vf_layout = layout2;
vf_heap = h1.vf_heap;
vf_heaplets = h1.vf_heaplets;
} in
h2
let lemma_create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let h2 = create_heaplets buffers h1 in
assert (h2.vf_layout.vl_inner.vl_buffers == bs); // REVIEW: why is this necessary, even with extra ifuel?
lemma_make_owns h1.vf_heap bs (Seq.length bs);
lemma_loc_mutable_buffers buffers;
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
let destroy_heaplets h1 =
h1
let lemma_destroy_heaplets h1 =
()
val heap_shift (m1 m2:S.machine_heap) (base:int) (n:nat) : Lemma
(requires (forall i. 0 <= i /\ i < n ==> m1.[base + i] == m2.[base + i]))
(ensures (forall i. {:pattern (m1.[i])} base <= i /\ i < base + n ==> m1.[i] == m2.[i]))
#push-options "--smtencoding.l_arith_repr boxwrap"
let heap_shift m1 m2 base n =
assert (forall i. base <= i /\ i < base + n ==>
m1.[base + (i - base)] == m2.[base + (i - base)])
#pop-options
val same_mem_eq_slices64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 8 + 8 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8)))
let same_mem_eq_slices64 b i v k h1 h2 mem1 mem2 =
let t = TUInt64 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up64 (b:buffer64) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 8}) : Lemma
(scale8 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint64_view in
UV.length_eq vb
val same_mem_get_heap_val64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale8 k in
forall (x:int).{:pattern (mem1.[x])} ptr <= x /\ x < ptr + 8 ==> mem1.[x] == mem2.[x]))
let same_mem_get_heap_val64 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale8 k in
let addr = buffer_addr b h1 in
let aux (x:int{ptr <= x /\ x < ptr + 8}) : Lemma (mem1.[x] == mem2.[x]) =
let i = x - ptr in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices64 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8) (k * 8 + 8)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8) (k * 8 + 8)) in
assert (Seq.index s1 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i));
length_up64 b h1 k i;
assert (mem1.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i)));
assert (Seq.index s2 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i));
length_up64 b h2 k i;
assert (mem2.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i)))
in
Classical.forall_intro aux;
assert (forall i. addr + (scale8 k + i) == ptr + i)
let rec written_buffer_down64_aux1
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(k:nat) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j.{:pattern (mem1.[j]) \/ (mem2.[j])}
base <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem1.[j])}
j >= base /\ j < base + scale8 i ==>
mem1.[j] == mem2.[j]))
(decreases %[i-k]) =
if k >= i then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux1 b i v h base (k+1) h1 mem1 mem2
end
let rec written_buffer_down64_aux2
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(n:nat{n == buffer_length b})
(k:nat{k > i}) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
base + scale8 (i+1) <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
j >= base + scale8 (i+1) /\ j < base + scale8 n ==>
mem1.[j] == mem2.[j]))
(decreases %[n-k]) =
if k >= n then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux2 b i v h base n (k+1) h1 mem1 mem2
end
let written_buffer_down64 (b:buffer64{buffer_writeable b}) (i:nat{i < buffer_length b}) (v:nat64) (h:vale_heap)
: Lemma
(requires List.memP b (IB.ptrs_of_mem (_ih h)))
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
(base <= j /\ j < base + scale8 i) \/
(base + scale8 (i+1) <= j /\ j < base + scale8 n) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
written_buffer_down64_aux1 b i v h base 0 h1 mem1 mem2;
written_buffer_down64_aux2 b i v h base n (i+1) h1 mem1 mem2
let unwritten_buffer_down (t:base_typ) (b:buffer t{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:base_typ_as_vale_type t)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall (a:b8{List.memP a (IB.ptrs_of_mem (_ih h)) /\ a =!= b}) j. {:pattern mem1.[j]; List.memP a (IB.ptrs_of_mem (_ih h)) \/ mem2.[j]; List.memP a (IB.ptrs_of_mem (_ih h))}
let base = (IB.addrs_of_mem (_ih h)) a in
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==> mem1.[j] == mem2.[j]))
= let aux (a:b8{a =!= b /\ List.memP a (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let base = (IB.addrs_of_mem (_ih h)) a in
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall j.
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==>
mem1.[j] == mem2.[j]))
= let db = get_downview a.bsrc in
if DV.length db = 0 then ()
else
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = (IB.addrs_of_mem (_ih h)) a in
let s0 = DV.as_seq (IB.hs_of_mem (_ih h)) db in
let s1 = DV.as_seq (IB.hs_of_mem (_ih h1)) db in
opaque_assert (`%IB.list_disjoint_or_eq) IB.list_disjoint_or_eq IB.list_disjoint_or_eq_def (MB.disjoint a.bsrc b.bsrc);
lemma_dv_equal (IB.down_view a.src) a.bsrc (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1));
assert (Seq.equal s0 s1);
assert (forall (j:int).{:pattern (mem1.[j])}
base <= j /\ j < base + Seq.length s0 ==> v_to_typ TUInt8 (Seq.index s0 (j - base)) == mem1.[j]);
heap_shift mem1 mem2 base (DV.length db)
in
Classical.forall_intro aux
let store_buffer_down64_mem
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
forall (j:int). {:pattern mem1.[j] \/ mem2.[j]}
j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
let aux (j:int)
: Lemma
(j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j])
=
I.addrs_set_lemma_all ();
if j >= base && j < base + DV.length (get_downview b.bsrc) then begin
written_buffer_down64 b i v h;
length_t_eq (TUInt64) b
end
else if not (I.valid_addr (_ih h) j)
then I.same_unspecified_down (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1)) (IB.ptrs_of_mem (_ih h))
else unwritten_buffer_down TUInt64 b i v h
in
Classical.forall_intro aux
let store_buffer_aux_down64_mem (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
forall j. {:pattern mem1.[j] \/ mem2.[j]}
j < ptr \/ j >= ptr + 8 ==>
mem1.[j] == mem2.[j]))
= let t = TUInt64 in
let h1 = store_mem t ptr v h in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
store_buffer_write t ptr v h;
assert (buffer_addr b h + scale8 i == ptr);
assert (buffer_addr b h + scale8 (i+1) == ptr + 8);
store_buffer_down64_mem b i v h
let store_buffer_aux_down64_mem2 (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
S.get_heap_val64 ptr mem2 == v))
= let t = TUInt64 in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
let h1 = store_mem t ptr v h in
let mem2 = I.down_mem (_ih h1) in
store_buffer_write t ptr v h;
assert (Seq.index (buffer_as_seq h1 b) i == v);
index64_get_heap_val64 h1 b mem2 i
let in_bounds64 (h:vale_heap) (b:buffer64) (i:nat{i < buffer_length b})
: Lemma (scale8 i + 8 <= DV.length (get_downview b.bsrc))
=
length_t_eq TUInt64 b
let bytes_valid64 ptr h =
reveal_opaque (`%S.valid_addr64) S.valid_addr64;
let t = TUInt64 in
let b = get_addr_ptr t ptr h in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
in_bounds64 h b i;
I.addrs_set_mem (_ih h) b ptr;
I.addrs_set_mem (_ih h) b (ptr+1);
I.addrs_set_mem (_ih h) b (ptr+2);
I.addrs_set_mem (_ih h) b (ptr+3);
I.addrs_set_mem (_ih h) b (ptr+4);
I.addrs_set_mem (_ih h) b (ptr+5);
I.addrs_set_mem (_ih h) b (ptr+6);
I.addrs_set_mem (_ih h) b (ptr+7)
val same_mem_get_heap_val128 (b:buffer128)
(i:nat{i < buffer_length b})
(v:quad32)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1)) /\ buffer_writeable b})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale16 k in
forall i.{:pattern mem1.[i]} i >= ptr /\ i < ptr+16 ==> mem1.[i] == mem2.[i]))
val same_mem_eq_slices128 (b:buffer128)
(i:nat{i < buffer_length b})
(v:quad32)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1)) /\ buffer_writeable b})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 16 + 16 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 16) (k * 16 + 16) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 16) (k * 16 + 16)))
let same_mem_eq_slices128 b i v k h1 h2 mem1 mem2 =
let t = TUInt128 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up128 (b:buffer128) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 16}) : Lemma
(scale16 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint128_view in
UV.length_eq vb
let same_mem_get_heap_val128 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale16 k in
let addr = buffer_addr b h1 in
let aux (i:nat{ptr <= i /\ i < ptr+16}) : Lemma (mem1.[i] == mem2.[i]) =
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint128_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices128 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16) (k * 16 + 16)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16) (k * 16 + 16)) in
assert (Seq.index s1 (i - ptr) == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16 + (i-ptr)));
length_up128 b h1 k (i-ptr);
assert (mem1.[i] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16 + (i-ptr))));
assert (Seq.index s2 (i-ptr) == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16 + (i-ptr)));
length_up128 b h2 k (i-ptr);
assert (mem2.[addr+(scale16 k + (i-ptr))] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16 + (i-ptr))));
assert (forall i. addr + (scale16 k + (i-ptr)) == i)
in
Classical.forall_intro aux | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Memory.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.BufferViewStore.fsti.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Memory_Sems.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_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
}
] | {
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
h: Vale.Arch.HeapImpl.vale_heap ->
b: Vale.X64.Memory.buffer128 ->
i: Prims.nat{i < Vale.X64.Memory.buffer_length b}
-> FStar.Pervasives.Lemma
(ensures
Vale.X64.Memory.scale16 i + 16 <=
LowStar.BufferView.Down.length (Vale.Interop.Types.get_downview (Buffer?.bsrc b))) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Arch.HeapImpl.vale_heap",
"Vale.X64.Memory.buffer128",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Vale.X64.Memory.buffer_length",
"Vale.X64.Memory.vuint128",
"Vale.X64.Memory.length_t_eq",
"Vale.Arch.HeapTypes_s.TUInt128",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition",
"Vale.X64.Memory.scale16",
"LowStar.BufferView.Down.length",
"FStar.UInt8.t",
"Vale.Interop.Types.get_downview",
"Vale.Interop.Types.__proj__Buffer__item__src",
"Vale.Interop.Types.b8_preorder",
"Vale.Interop.Types.__proj__Buffer__item__writeable",
"Vale.Interop.Types.base_typ_as_type",
"Vale.Interop.Types.__proj__Buffer__item__bsrc",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let in_bounds128 (h: vale_heap) (b: buffer128) (i: nat{i < buffer_length b})
: Lemma (scale16 i + 16 <= DV.length (get_downview b.bsrc)) =
| length_t_eq TUInt128 b | false |
Vale.X64.Memory_Sems.fst | Vale.X64.Memory_Sems.written_buffer_down64_aux2 | val written_buffer_down64_aux2
(b: buffer64{buffer_writeable b})
(i: nat{i < buffer_length b})
(v: nat64)
(h: vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base: nat{base == buffer_addr b h})
(n: nat{n == buffer_length b})
(k: nat{k > i})
(h1: vale_heap{h1 == buffer_write b i v h})
(mem1: S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:
S.machine_heap
{ IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[ j ])\/(mem2.[ j ])}
base + scale8 (i + 1) <= j /\ j < base + k * 8 ==> mem1.[ j ] == mem2.[ j ]) })
: Lemma
(ensures
(forall j. {:pattern (mem1.[ j ])\/(mem2.[ j ])}
j >= base + scale8 (i + 1) /\ j < base + scale8 n ==> mem1.[ j ] == mem2.[ j ]))
(decreases %[n - k]) | val written_buffer_down64_aux2
(b: buffer64{buffer_writeable b})
(i: nat{i < buffer_length b})
(v: nat64)
(h: vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base: nat{base == buffer_addr b h})
(n: nat{n == buffer_length b})
(k: nat{k > i})
(h1: vale_heap{h1 == buffer_write b i v h})
(mem1: S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:
S.machine_heap
{ IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[ j ])\/(mem2.[ j ])}
base + scale8 (i + 1) <= j /\ j < base + k * 8 ==> mem1.[ j ] == mem2.[ j ]) })
: Lemma
(ensures
(forall j. {:pattern (mem1.[ j ])\/(mem2.[ j ])}
j >= base + scale8 (i + 1) /\ j < base + scale8 n ==> mem1.[ j ] == mem2.[ j ]))
(decreases %[n - k]) | let rec written_buffer_down64_aux2
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(n:nat{n == buffer_length b})
(k:nat{k > i}) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
base + scale8 (i+1) <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
j >= base + scale8 (i+1) /\ j < base + scale8 n ==>
mem1.[j] == mem2.[j]))
(decreases %[n-k]) =
if k >= n then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux2 b i v h base n (k+1) h1 mem1 mem2
end | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory_Sems.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 7,
"end_line": 316,
"start_col": 0,
"start_line": 292
} | module Vale.X64.Memory_Sems
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.Def.Words_s
module I = Vale.Interop
module S = Vale.X64.Machine_Semantics_s
module MB = LowStar.Monotonic.Buffer
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
friend Vale.X64.Memory
module IB = Vale.Interop.Base
let same_domain h m = Set.equal (IB.addrs_set (_ih h)) (Map.domain m)
let lemma_same_domains h m1 m2 = ()
let get_heap h = I.down_mem (_ih h)
let upd_heap h m = mi_heap_upd h m
//let lemma_upd_get_heap h = I.down_up_identity (_ih h)
let lemma_get_upd_heap h m = I.up_down_identity (_ih h) m
let lemma_heap_impl = ()
let lemma_heap_get_heap h = ()
let lemma_heap_taint h = ()
//let lemma_heap_upd_heap h mh mt = ()
[@"opaque_to_smt"]
let rec set_of_range (a:int) (n:nat) : Pure (Set.set int)
(requires True)
(ensures fun s -> (forall (i:int).{:pattern Set.mem i s} Set.mem i s <==> a <= i /\ i < a + n))
=
if n = 0 then Set.empty else Set.union (set_of_range a (n - 1)) (Set.singleton (a + n - 1))
let buffer_info_has_addr (bi:buffer_info) (a:int) =
let b = bi.bi_buffer in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
addr <= a /\ a < addr + len
let buffer_info_has_addr_opt (bi:option buffer_info) (a:int) =
match bi with
| None -> False
| Some bi -> buffer_info_has_addr bi a
#set-options "--z3rlimit 100"
let rec make_owns_rec (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
if n = 0 then ((fun _ -> None), (fun _ -> Set.empty)) else
let (m0, s0) = make_owns_rec h bs (n - 1) in
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let s i = if i = hi then Set.union (s0 i) s_b else s0 i in
let m a = if addr <= a && a < addr + len then Some (n - 1) else m0 a in
(m, s)
[@"opaque_to_smt"]
let make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
make_owns_rec h bs n
let rec lemma_make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n <= Seq.length bs /\
(forall (i:nat).{:pattern Seq.index bs i} i < Seq.length bs ==> buffer_readable h (Seq.index bs i).bi_buffer) /\
(forall (i1 i2:nat).{:pattern (Seq.index bs i1); (Seq.index bs i2)}
i1 < Seq.length bs /\ i2 < Seq.length bs ==> buffer_info_disjoint (Seq.index bs i1) (Seq.index bs i2))
)
(ensures (
let (m, s) = make_owns h bs n in
(forall (i:heaplet_id) (a:int).{:pattern Set.mem a (s i)}
(Set.mem a (s i) <==> Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (m a) == Some i) /\
(Set.mem a (s i) ==> buffer_info_has_addr_opt (Option.mapTot (fun n -> Seq.index bs n) (m a)) a) /\
(Set.mem a (s i) ==> Set.mem a (Map.domain h.mh))
) /\
(forall (k:nat) (a:int).{:pattern Set.mem a (s (Seq.index bs k).bi_heaplet)}
k < n /\ buffer_info_has_addr (Seq.index bs k) a ==> Set.mem a (s (Seq.index bs k).bi_heaplet))
))
=
reveal_opaque (`%make_owns) make_owns;
if n = 0 then () else
let _ = make_owns h bs (n - 1) in
let (m, s) = make_owns h bs n in
lemma_make_owns h bs (n - 1);
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let lem1 (a:int) : Lemma
(requires Set.mem a s_b)
(ensures Set.mem a (Map.domain h.mh))
[SMTPat (Set.mem a (Map.domain h.mh))]
=
I.addrs_set_mem h.ih b a
in
let lem2 (i:heaplet_id) (a:int) : Lemma
(requires i =!= hi /\ Set.mem a (Set.intersect s_b (s i)))
(ensures False)
[SMTPat (Set.mem a (s i))]
=
reveal_opaque (`%addr_map_pred) addr_map_pred
in
()
#push-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_loc_mutable_buffers_rec (l:list buffer_info) (s:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n + List.length l == Seq.length s /\
list_to_seq_post l s n
)
(ensures (
let modloc = loc_mutable_buffers l in
forall (i:nat).{:pattern Seq.index s i} n <= i /\ i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes modloc (loc_buffer bi.bi_buffer))
))
(decreases l)
=
match l with
| [] -> ()
| h::t -> lemma_loc_mutable_buffers_rec t s (n + 1)
#pop-options
let lemma_loc_mutable_buffers (l:list buffer_info) : Lemma
(ensures (
let s = list_to_seq l in
forall (i:nat).{:pattern Seq.index s i} i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes (loc_mutable_buffers l) (loc_buffer bi.bi_buffer))
))
=
lemma_list_to_seq l;
lemma_loc_mutable_buffers_rec l (list_to_seq l) 0
let create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let modloc = loc_mutable_buffers buffers in
let layout1 = h1.vf_layout in
let layin1 = layout1.vl_inner in
let (hmap, hsets) = make_owns h1.vf_heap bs (Seq.length bs) in
let hmap a = Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (hmap a) in
let l = {
vl_heaplets_initialized = true;
vl_heaplet_map = hmap;
vl_heaplet_sets = hsets;
vl_old_heap = h1.vf_heap;
vl_buffers = bs;
vl_mod_loc = modloc;
} in
let layout2 = {layout1 with vl_inner = l} in
let h2 = {
vf_layout = layout2;
vf_heap = h1.vf_heap;
vf_heaplets = h1.vf_heaplets;
} in
h2
let lemma_create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let h2 = create_heaplets buffers h1 in
assert (h2.vf_layout.vl_inner.vl_buffers == bs); // REVIEW: why is this necessary, even with extra ifuel?
lemma_make_owns h1.vf_heap bs (Seq.length bs);
lemma_loc_mutable_buffers buffers;
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
let destroy_heaplets h1 =
h1
let lemma_destroy_heaplets h1 =
()
val heap_shift (m1 m2:S.machine_heap) (base:int) (n:nat) : Lemma
(requires (forall i. 0 <= i /\ i < n ==> m1.[base + i] == m2.[base + i]))
(ensures (forall i. {:pattern (m1.[i])} base <= i /\ i < base + n ==> m1.[i] == m2.[i]))
#push-options "--smtencoding.l_arith_repr boxwrap"
let heap_shift m1 m2 base n =
assert (forall i. base <= i /\ i < base + n ==>
m1.[base + (i - base)] == m2.[base + (i - base)])
#pop-options
val same_mem_eq_slices64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 8 + 8 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8)))
let same_mem_eq_slices64 b i v k h1 h2 mem1 mem2 =
let t = TUInt64 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up64 (b:buffer64) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 8}) : Lemma
(scale8 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint64_view in
UV.length_eq vb
val same_mem_get_heap_val64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale8 k in
forall (x:int).{:pattern (mem1.[x])} ptr <= x /\ x < ptr + 8 ==> mem1.[x] == mem2.[x]))
let same_mem_get_heap_val64 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale8 k in
let addr = buffer_addr b h1 in
let aux (x:int{ptr <= x /\ x < ptr + 8}) : Lemma (mem1.[x] == mem2.[x]) =
let i = x - ptr in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices64 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8) (k * 8 + 8)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8) (k * 8 + 8)) in
assert (Seq.index s1 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i));
length_up64 b h1 k i;
assert (mem1.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i)));
assert (Seq.index s2 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i));
length_up64 b h2 k i;
assert (mem2.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i)))
in
Classical.forall_intro aux;
assert (forall i. addr + (scale8 k + i) == ptr + i)
let rec written_buffer_down64_aux1
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(k:nat) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j.{:pattern (mem1.[j]) \/ (mem2.[j])}
base <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem1.[j])}
j >= base /\ j < base + scale8 i ==>
mem1.[j] == mem2.[j]))
(decreases %[i-k]) =
if k >= i then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux1 b i v h base (k+1) h1 mem1 mem2
end | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Memory.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.BufferViewStore.fsti.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Memory_Sems.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_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
}
] | {
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
b: Vale.X64.Memory.buffer64{Vale.X64.Memory.buffer_writeable b} ->
i: Prims.nat{i < Vale.X64.Memory.buffer_length b} ->
v: Vale.Def.Words_s.nat64 ->
h:
Vale.Arch.HeapImpl.vale_heap
{FStar.List.Tot.Base.memP b (Vale.Interop.Heap_s.ptrs_of_mem (Vale.Arch.HeapImpl._ih h))} ->
base: Prims.nat{base == Vale.X64.Memory.buffer_addr b h} ->
n: Prims.nat{n == Vale.X64.Memory.buffer_length b} ->
k: Prims.nat{k > i} ->
h1: Vale.Arch.HeapImpl.vale_heap{h1 == Vale.X64.Memory.buffer_write b i v h} ->
mem1:
Vale.Arch.MachineHeap_s.machine_heap
{Vale.Interop.Heap_s.correct_down (Vale.Arch.HeapImpl._ih h) mem1} ->
mem2:
Vale.Arch.MachineHeap_s.machine_heap
{ Vale.Interop.Heap_s.correct_down (Vale.Arch.HeapImpl._ih h1) mem2 /\
(forall (j: Prims.int). {:pattern mem1.[ j ]\/mem2.[ j ]}
base + Vale.X64.Memory.scale8 (i + 1) <= j /\ j < base + k * 8 ==>
mem1.[ j ] == mem2.[ j ]) }
-> FStar.Pervasives.Lemma
(ensures
forall (j: Prims.int). {:pattern mem1.[ j ]\/mem2.[ j ]}
j >= base + Vale.X64.Memory.scale8 (i + 1) /\ j < base + Vale.X64.Memory.scale8 n ==>
mem1.[ j ] == mem2.[ j ]) (decreases n - k) | FStar.Pervasives.Lemma | [
"lemma",
""
] | [] | [
"Vale.X64.Memory.buffer64",
"Vale.X64.Memory.buffer_writeable",
"Vale.X64.Memory.vuint64",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Vale.X64.Memory.buffer_length",
"Vale.Def.Words_s.nat64",
"Vale.Arch.HeapImpl.vale_heap",
"FStar.List.Tot.Base.memP",
"Vale.Interop.Types.b8",
"Vale.Interop.Heap_s.ptrs_of_mem",
"Vale.Arch.HeapImpl._ih",
"Prims.eq2",
"Prims.int",
"Vale.X64.Memory.buffer_addr",
"Prims.op_GreaterThan",
"Vale.X64.Memory.buffer_write",
"Vale.Arch.MachineHeap_s.machine_heap",
"Vale.Interop.Heap_s.correct_down",
"Prims.l_and",
"Prims.l_Forall",
"Prims.l_imp",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition",
"Vale.X64.Memory.scale8",
"FStar.Mul.op_Star",
"Vale.Def.Types_s.nat8",
"Vale.X64.Memory.op_String_Access",
"Prims.op_GreaterThanOrEqual",
"Prims.bool",
"Vale.X64.Memory_Sems.written_buffer_down64_aux2",
"Prims.unit",
"Vale.X64.Memory_Sems.heap_shift",
"Vale.X64.Memory_Sems.same_mem_get_heap_val64",
"Prims.l_True",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [
"recursion"
] | false | false | true | false | false | let rec written_buffer_down64_aux2
(b: buffer64{buffer_writeable b})
(i: nat{i < buffer_length b})
(v: nat64)
(h: vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base: nat{base == buffer_addr b h})
(n: nat{n == buffer_length b})
(k: nat{k > i})
(h1: vale_heap{h1 == buffer_write b i v h})
(mem1: S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:
S.machine_heap
{ IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[ j ])\/(mem2.[ j ])}
base + scale8 (i + 1) <= j /\ j < base + k * 8 ==> mem1.[ j ] == mem2.[ j ]) })
: Lemma
(ensures
(forall j. {:pattern (mem1.[ j ])\/(mem2.[ j ])}
j >= base + scale8 (i + 1) /\ j < base + scale8 n ==> mem1.[ j ] == mem2.[ j ]))
(decreases %[n - k]) =
| if k >= n
then ()
else
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux2 b i v h base n (k + 1) h1 mem1 mem2 | false |
Vale.X64.Memory_Sems.fst | Vale.X64.Memory_Sems.store_buffer_down64_mem | val store_buffer_down64_mem
(b: buffer64{buffer_writeable b})
(i: nat{i < buffer_length b})
(v: nat64)
(h: vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures
(let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
forall (j: int). {:pattern mem1.[ j ]\/mem2.[ j ]}
j < base + scale8 i \/ j >= base + scale8 (i + 1) ==> mem1.[ j ] == mem2.[ j ])) | val store_buffer_down64_mem
(b: buffer64{buffer_writeable b})
(i: nat{i < buffer_length b})
(v: nat64)
(h: vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures
(let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
forall (j: int). {:pattern mem1.[ j ]\/mem2.[ j ]}
j < base + scale8 i \/ j >= base + scale8 (i + 1) ==> mem1.[ j ] == mem2.[ j ])) | let store_buffer_down64_mem
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
forall (j:int). {:pattern mem1.[j] \/ mem2.[j]}
j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
let aux (j:int)
: Lemma
(j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j])
=
I.addrs_set_lemma_all ();
if j >= base && j < base + DV.length (get_downview b.bsrc) then begin
written_buffer_down64 b i v h;
length_t_eq (TUInt64) b
end
else if not (I.valid_addr (_ih h) j)
then I.same_unspecified_down (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1)) (IB.ptrs_of_mem (_ih h))
else unwritten_buffer_down TUInt64 b i v h
in
Classical.forall_intro aux | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory_Sems.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 30,
"end_line": 412,
"start_col": 0,
"start_line": 379
} | module Vale.X64.Memory_Sems
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.Def.Words_s
module I = Vale.Interop
module S = Vale.X64.Machine_Semantics_s
module MB = LowStar.Monotonic.Buffer
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
friend Vale.X64.Memory
module IB = Vale.Interop.Base
let same_domain h m = Set.equal (IB.addrs_set (_ih h)) (Map.domain m)
let lemma_same_domains h m1 m2 = ()
let get_heap h = I.down_mem (_ih h)
let upd_heap h m = mi_heap_upd h m
//let lemma_upd_get_heap h = I.down_up_identity (_ih h)
let lemma_get_upd_heap h m = I.up_down_identity (_ih h) m
let lemma_heap_impl = ()
let lemma_heap_get_heap h = ()
let lemma_heap_taint h = ()
//let lemma_heap_upd_heap h mh mt = ()
[@"opaque_to_smt"]
let rec set_of_range (a:int) (n:nat) : Pure (Set.set int)
(requires True)
(ensures fun s -> (forall (i:int).{:pattern Set.mem i s} Set.mem i s <==> a <= i /\ i < a + n))
=
if n = 0 then Set.empty else Set.union (set_of_range a (n - 1)) (Set.singleton (a + n - 1))
let buffer_info_has_addr (bi:buffer_info) (a:int) =
let b = bi.bi_buffer in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
addr <= a /\ a < addr + len
let buffer_info_has_addr_opt (bi:option buffer_info) (a:int) =
match bi with
| None -> False
| Some bi -> buffer_info_has_addr bi a
#set-options "--z3rlimit 100"
let rec make_owns_rec (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
if n = 0 then ((fun _ -> None), (fun _ -> Set.empty)) else
let (m0, s0) = make_owns_rec h bs (n - 1) in
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let s i = if i = hi then Set.union (s0 i) s_b else s0 i in
let m a = if addr <= a && a < addr + len then Some (n - 1) else m0 a in
(m, s)
[@"opaque_to_smt"]
let make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
make_owns_rec h bs n
let rec lemma_make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n <= Seq.length bs /\
(forall (i:nat).{:pattern Seq.index bs i} i < Seq.length bs ==> buffer_readable h (Seq.index bs i).bi_buffer) /\
(forall (i1 i2:nat).{:pattern (Seq.index bs i1); (Seq.index bs i2)}
i1 < Seq.length bs /\ i2 < Seq.length bs ==> buffer_info_disjoint (Seq.index bs i1) (Seq.index bs i2))
)
(ensures (
let (m, s) = make_owns h bs n in
(forall (i:heaplet_id) (a:int).{:pattern Set.mem a (s i)}
(Set.mem a (s i) <==> Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (m a) == Some i) /\
(Set.mem a (s i) ==> buffer_info_has_addr_opt (Option.mapTot (fun n -> Seq.index bs n) (m a)) a) /\
(Set.mem a (s i) ==> Set.mem a (Map.domain h.mh))
) /\
(forall (k:nat) (a:int).{:pattern Set.mem a (s (Seq.index bs k).bi_heaplet)}
k < n /\ buffer_info_has_addr (Seq.index bs k) a ==> Set.mem a (s (Seq.index bs k).bi_heaplet))
))
=
reveal_opaque (`%make_owns) make_owns;
if n = 0 then () else
let _ = make_owns h bs (n - 1) in
let (m, s) = make_owns h bs n in
lemma_make_owns h bs (n - 1);
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let lem1 (a:int) : Lemma
(requires Set.mem a s_b)
(ensures Set.mem a (Map.domain h.mh))
[SMTPat (Set.mem a (Map.domain h.mh))]
=
I.addrs_set_mem h.ih b a
in
let lem2 (i:heaplet_id) (a:int) : Lemma
(requires i =!= hi /\ Set.mem a (Set.intersect s_b (s i)))
(ensures False)
[SMTPat (Set.mem a (s i))]
=
reveal_opaque (`%addr_map_pred) addr_map_pred
in
()
#push-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_loc_mutable_buffers_rec (l:list buffer_info) (s:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n + List.length l == Seq.length s /\
list_to_seq_post l s n
)
(ensures (
let modloc = loc_mutable_buffers l in
forall (i:nat).{:pattern Seq.index s i} n <= i /\ i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes modloc (loc_buffer bi.bi_buffer))
))
(decreases l)
=
match l with
| [] -> ()
| h::t -> lemma_loc_mutable_buffers_rec t s (n + 1)
#pop-options
let lemma_loc_mutable_buffers (l:list buffer_info) : Lemma
(ensures (
let s = list_to_seq l in
forall (i:nat).{:pattern Seq.index s i} i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes (loc_mutable_buffers l) (loc_buffer bi.bi_buffer))
))
=
lemma_list_to_seq l;
lemma_loc_mutable_buffers_rec l (list_to_seq l) 0
let create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let modloc = loc_mutable_buffers buffers in
let layout1 = h1.vf_layout in
let layin1 = layout1.vl_inner in
let (hmap, hsets) = make_owns h1.vf_heap bs (Seq.length bs) in
let hmap a = Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (hmap a) in
let l = {
vl_heaplets_initialized = true;
vl_heaplet_map = hmap;
vl_heaplet_sets = hsets;
vl_old_heap = h1.vf_heap;
vl_buffers = bs;
vl_mod_loc = modloc;
} in
let layout2 = {layout1 with vl_inner = l} in
let h2 = {
vf_layout = layout2;
vf_heap = h1.vf_heap;
vf_heaplets = h1.vf_heaplets;
} in
h2
let lemma_create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let h2 = create_heaplets buffers h1 in
assert (h2.vf_layout.vl_inner.vl_buffers == bs); // REVIEW: why is this necessary, even with extra ifuel?
lemma_make_owns h1.vf_heap bs (Seq.length bs);
lemma_loc_mutable_buffers buffers;
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
let destroy_heaplets h1 =
h1
let lemma_destroy_heaplets h1 =
()
val heap_shift (m1 m2:S.machine_heap) (base:int) (n:nat) : Lemma
(requires (forall i. 0 <= i /\ i < n ==> m1.[base + i] == m2.[base + i]))
(ensures (forall i. {:pattern (m1.[i])} base <= i /\ i < base + n ==> m1.[i] == m2.[i]))
#push-options "--smtencoding.l_arith_repr boxwrap"
let heap_shift m1 m2 base n =
assert (forall i. base <= i /\ i < base + n ==>
m1.[base + (i - base)] == m2.[base + (i - base)])
#pop-options
val same_mem_eq_slices64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 8 + 8 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8)))
let same_mem_eq_slices64 b i v k h1 h2 mem1 mem2 =
let t = TUInt64 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up64 (b:buffer64) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 8}) : Lemma
(scale8 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint64_view in
UV.length_eq vb
val same_mem_get_heap_val64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale8 k in
forall (x:int).{:pattern (mem1.[x])} ptr <= x /\ x < ptr + 8 ==> mem1.[x] == mem2.[x]))
let same_mem_get_heap_val64 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale8 k in
let addr = buffer_addr b h1 in
let aux (x:int{ptr <= x /\ x < ptr + 8}) : Lemma (mem1.[x] == mem2.[x]) =
let i = x - ptr in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices64 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8) (k * 8 + 8)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8) (k * 8 + 8)) in
assert (Seq.index s1 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i));
length_up64 b h1 k i;
assert (mem1.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i)));
assert (Seq.index s2 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i));
length_up64 b h2 k i;
assert (mem2.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i)))
in
Classical.forall_intro aux;
assert (forall i. addr + (scale8 k + i) == ptr + i)
let rec written_buffer_down64_aux1
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(k:nat) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j.{:pattern (mem1.[j]) \/ (mem2.[j])}
base <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem1.[j])}
j >= base /\ j < base + scale8 i ==>
mem1.[j] == mem2.[j]))
(decreases %[i-k]) =
if k >= i then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux1 b i v h base (k+1) h1 mem1 mem2
end
let rec written_buffer_down64_aux2
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(n:nat{n == buffer_length b})
(k:nat{k > i}) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
base + scale8 (i+1) <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
j >= base + scale8 (i+1) /\ j < base + scale8 n ==>
mem1.[j] == mem2.[j]))
(decreases %[n-k]) =
if k >= n then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux2 b i v h base n (k+1) h1 mem1 mem2
end
let written_buffer_down64 (b:buffer64{buffer_writeable b}) (i:nat{i < buffer_length b}) (v:nat64) (h:vale_heap)
: Lemma
(requires List.memP b (IB.ptrs_of_mem (_ih h)))
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
(base <= j /\ j < base + scale8 i) \/
(base + scale8 (i+1) <= j /\ j < base + scale8 n) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
written_buffer_down64_aux1 b i v h base 0 h1 mem1 mem2;
written_buffer_down64_aux2 b i v h base n (i+1) h1 mem1 mem2
let unwritten_buffer_down (t:base_typ) (b:buffer t{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:base_typ_as_vale_type t)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall (a:b8{List.memP a (IB.ptrs_of_mem (_ih h)) /\ a =!= b}) j. {:pattern mem1.[j]; List.memP a (IB.ptrs_of_mem (_ih h)) \/ mem2.[j]; List.memP a (IB.ptrs_of_mem (_ih h))}
let base = (IB.addrs_of_mem (_ih h)) a in
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==> mem1.[j] == mem2.[j]))
= let aux (a:b8{a =!= b /\ List.memP a (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let base = (IB.addrs_of_mem (_ih h)) a in
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall j.
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==>
mem1.[j] == mem2.[j]))
= let db = get_downview a.bsrc in
if DV.length db = 0 then ()
else
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = (IB.addrs_of_mem (_ih h)) a in
let s0 = DV.as_seq (IB.hs_of_mem (_ih h)) db in
let s1 = DV.as_seq (IB.hs_of_mem (_ih h1)) db in
opaque_assert (`%IB.list_disjoint_or_eq) IB.list_disjoint_or_eq IB.list_disjoint_or_eq_def (MB.disjoint a.bsrc b.bsrc);
lemma_dv_equal (IB.down_view a.src) a.bsrc (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1));
assert (Seq.equal s0 s1);
assert (forall (j:int).{:pattern (mem1.[j])}
base <= j /\ j < base + Seq.length s0 ==> v_to_typ TUInt8 (Seq.index s0 (j - base)) == mem1.[j]);
heap_shift mem1 mem2 base (DV.length db)
in
Classical.forall_intro aux | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Memory.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.BufferViewStore.fsti.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Memory_Sems.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_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
}
] | {
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
b: Vale.X64.Memory.buffer64{Vale.X64.Memory.buffer_writeable b} ->
i: Prims.nat{i < Vale.X64.Memory.buffer_length b} ->
v: Vale.Def.Words_s.nat64 ->
h:
Vale.Arch.HeapImpl.vale_heap
{FStar.List.Tot.Base.memP b (Vale.Interop.Heap_s.ptrs_of_mem (Vale.Arch.HeapImpl._ih h))}
-> FStar.Pervasives.Lemma
(ensures
(let mem1 = Vale.Interop.down_mem (Vale.Arch.HeapImpl._ih h) in
let h1 = Vale.X64.Memory.buffer_write b i v h in
let mem2 = Vale.Interop.down_mem (Vale.Arch.HeapImpl._ih h1) in
let base = Vale.X64.Memory.buffer_addr b h in
forall (j: Prims.int). {:pattern mem1.[ j ]\/mem2.[ j ]}
j < base + Vale.X64.Memory.scale8 i \/ j >= base + Vale.X64.Memory.scale8 (i + 1) ==>
mem1.[ j ] == mem2.[ j ])) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.X64.Memory.buffer64",
"Vale.X64.Memory.buffer_writeable",
"Vale.X64.Memory.vuint64",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Vale.X64.Memory.buffer_length",
"Vale.Def.Words_s.nat64",
"Vale.Arch.HeapImpl.vale_heap",
"FStar.List.Tot.Base.memP",
"Vale.Interop.Types.b8",
"Vale.Interop.Heap_s.ptrs_of_mem",
"Vale.Arch.HeapImpl._ih",
"FStar.Classical.forall_intro",
"Prims.int",
"Prims.l_imp",
"Prims.l_or",
"Prims.op_Addition",
"Vale.X64.Memory.scale8",
"Prims.op_GreaterThanOrEqual",
"Prims.eq2",
"Vale.Def.Types_s.nat8",
"Vale.X64.Memory.op_String_Access",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Vale.X64.Memory.scale_by",
"Vale.Def.Words_s.nat8",
"FStar.Map.sel",
"Prims.Nil",
"FStar.Pervasives.pattern",
"Prims.op_AmpAmp",
"LowStar.BufferView.Down.length",
"FStar.UInt8.t",
"Vale.Interop.Types.get_downview",
"Vale.Interop.Types.__proj__Buffer__item__src",
"Vale.Interop.Types.b8_preorder",
"Vale.Interop.Types.__proj__Buffer__item__writeable",
"Vale.Interop.Types.base_typ_as_type",
"Vale.Interop.Types.__proj__Buffer__item__bsrc",
"Vale.X64.Memory.length_t_eq",
"Vale.Arch.HeapTypes_s.TUInt64",
"Vale.X64.Memory_Sems.written_buffer_down64",
"Prims.bool",
"Prims.op_Negation",
"Vale.Interop.valid_addr",
"Vale.Interop.same_unspecified_down",
"Vale.Interop.Heap_s.hs_of_mem",
"Vale.X64.Memory_Sems.unwritten_buffer_down",
"Vale.Interop.addrs_set_lemma_all",
"Vale.X64.Memory.buffer_addr",
"Vale.Arch.MachineHeap_s.machine_heap",
"Vale.Interop.Heap_s.correct_down",
"Vale.Interop.down_mem",
"Vale.X64.Memory.buffer_write",
"Prims.l_Forall"
] | [] | false | false | true | false | false | let store_buffer_down64_mem
(b: buffer64{buffer_writeable b})
(i: nat{i < buffer_length b})
(v: nat64)
(h: vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures
(let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
forall (j: int). {:pattern mem1.[ j ]\/mem2.[ j ]}
j < base + scale8 i \/ j >= base + scale8 (i + 1) ==> mem1.[ j ] == mem2.[ j ])) =
| let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
let aux (j: int)
: Lemma (j < base + scale8 i \/ j >= base + scale8 (i + 1) ==> mem1.[ j ] == mem2.[ j ]) =
I.addrs_set_lemma_all ();
if j >= base && j < base + DV.length (get_downview b.bsrc)
then
(written_buffer_down64 b i v h;
length_t_eq (TUInt64) b)
else
if not (I.valid_addr (_ih h) j)
then
I.same_unspecified_down (IB.hs_of_mem (_ih h))
(IB.hs_of_mem (_ih h1))
(IB.ptrs_of_mem (_ih h))
else unwritten_buffer_down TUInt64 b i v h
in
Classical.forall_intro aux | false |
PulseCore.MonotonicStateMonad.fst | PulseCore.MonotonicStateMonad.return | val return (#s:Type u#s)
(#rel:preorder s)
(#a:Type u#a)
(x:a)
: mst rel a (fun _ -> True) (fun s0 v s1 -> x == v /\ s0 == s1) | val return (#s:Type u#s)
(#rel:preorder s)
(#a:Type u#a)
(x:a)
: mst rel a (fun _ -> True) (fun s0 v s1 -> x == v /\ s0 == s1) | let return x
= fun s0 -> x, s0 | {
"file_name": "lib/pulse_core/PulseCore.MonotonicStateMonad.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 17,
"end_line": 37,
"start_col": 0,
"start_line": 36
} | module PulseCore.MonotonicStateMonad
open FStar.Preorder
module M = FStar.MSTTotal
let mst (#s:Type u#s)
(rel:FStar.Preorder.preorder s)
(a:Type u#a)
(pre:s -> prop)
(post:s -> a -> s -> prop)
= s0:s { pre s0 }
-> Tot (
res:(a & s) {
post s0 res._1 res._2 /\
rel s0 res._2
}
)
assume (* to interoperate with a definition of a similar module in FStar.MSTTotal *)
val reify_ (#s:Type u#2) (#rel:FStar.Preorder.preorder s)
(#a:Type u#a) (#pre:s -> prop) (#post:s -> a -> s -> prop)
($f:unit -> M.MSTATETOT a s rel pre post)
: M.repr a s rel pre post
let of_msttotal (#s:Type u#2) (rel:FStar.Preorder.preorder s)
(a:Type u#a) (pre:s -> prop) (post:s -> a -> s -> prop)
(f:unit -> M.MSTATETOT a s rel pre post)
: mst rel a pre post
= let f = reify_ f in
fun s -> f s
let to_msttotal (#s:Type u#2) (rel:FStar.Preorder.preorder s)
(a:Type u#a) (pre:s -> prop) (post:s -> a -> s -> prop)
(f:mst rel a pre post)
: M.MSTATETOT a s rel pre post
= M.MSTATETOT?.reflect (fun s -> f s) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.MSTTotal.fst.checked"
],
"interface_file": true,
"source_file": "PulseCore.MonotonicStateMonad.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.MSTTotal",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.MSTTotal",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "PulseCore",
"short_module": null
},
{
"abbrev": false,
"full_module": "PulseCore",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: a
-> PulseCore.MonotonicStateMonad.mst rel
a
(fun _ -> Prims.l_True)
(fun s0 v s1 -> x == v /\ s0 == s1) | Prims.Tot | [
"total"
] | [] | [
"FStar.Preorder.preorder",
"Prims.l_True",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Pervasives.Native.tuple2",
"Prims.l_and",
"Prims.eq2",
"Prims.prop",
"FStar.Pervasives.Native.__proj__Mktuple2__item___1",
"FStar.Pervasives.Native.__proj__Mktuple2__item___2"
] | [] | false | false | false | false | false | let return x =
| fun s0 -> x, s0 | false |
PulseCore.MonotonicStateMonad.fst | PulseCore.MonotonicStateMonad.to_msttotal | val to_msttotal (#s:Type u#2) (rel:FStar.Preorder.preorder s)
(a:Type u#a) (pre:s -> prop) (post:s -> a -> s -> prop)
(f:mst rel a pre post)
: M.MSTATETOT a s rel pre post | val to_msttotal (#s:Type u#2) (rel:FStar.Preorder.preorder s)
(a:Type u#a) (pre:s -> prop) (post:s -> a -> s -> prop)
(f:mst rel a pre post)
: M.MSTATETOT a s rel pre post | let to_msttotal (#s:Type u#2) (rel:FStar.Preorder.preorder s)
(a:Type u#a) (pre:s -> prop) (post:s -> a -> s -> prop)
(f:mst rel a pre post)
: M.MSTATETOT a s rel pre post
= M.MSTATETOT?.reflect (fun s -> f s) | {
"file_name": "lib/pulse_core/PulseCore.MonotonicStateMonad.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 37,
"end_line": 34,
"start_col": 0,
"start_line": 30
} | module PulseCore.MonotonicStateMonad
open FStar.Preorder
module M = FStar.MSTTotal
let mst (#s:Type u#s)
(rel:FStar.Preorder.preorder s)
(a:Type u#a)
(pre:s -> prop)
(post:s -> a -> s -> prop)
= s0:s { pre s0 }
-> Tot (
res:(a & s) {
post s0 res._1 res._2 /\
rel s0 res._2
}
)
assume (* to interoperate with a definition of a similar module in FStar.MSTTotal *)
val reify_ (#s:Type u#2) (#rel:FStar.Preorder.preorder s)
(#a:Type u#a) (#pre:s -> prop) (#post:s -> a -> s -> prop)
($f:unit -> M.MSTATETOT a s rel pre post)
: M.repr a s rel pre post
let of_msttotal (#s:Type u#2) (rel:FStar.Preorder.preorder s)
(a:Type u#a) (pre:s -> prop) (post:s -> a -> s -> prop)
(f:unit -> M.MSTATETOT a s rel pre post)
: mst rel a pre post
= let f = reify_ f in
fun s -> f s | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.MSTTotal.fst.checked"
],
"interface_file": true,
"source_file": "PulseCore.MonotonicStateMonad.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.MSTTotal",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.MSTTotal",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "PulseCore",
"short_module": null
},
{
"abbrev": false,
"full_module": "PulseCore",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
rel: FStar.Preorder.preorder s ->
a: Type ->
pre: (_: s -> Prims.prop) ->
post: (_: s -> _: a -> _: s -> Prims.prop) ->
f: PulseCore.MonotonicStateMonad.mst rel a pre post
-> FStar.MSTTotal.MSTATETOT a | FStar.MSTTotal.MSTATETOT | [] | [] | [
"FStar.Preorder.preorder",
"Prims.prop",
"PulseCore.MonotonicStateMonad.mst",
"FStar.Pervasives.Native.tuple2"
] | [] | false | true | false | false | false | let to_msttotal
(#s: Type u#2)
(rel: FStar.Preorder.preorder s)
(a: Type u#a)
(pre: (s -> prop))
(post: (s -> a -> s -> prop))
(f: mst rel a pre post)
: M.MSTATETOT a s rel pre post =
| M.MSTATETOT?.reflect (fun s -> f s) | false |
PulseCore.MonotonicStateMonad.fst | PulseCore.MonotonicStateMonad.of_msttotal | val of_msttotal (#s:Type u#2) (rel:FStar.Preorder.preorder s)
(a:Type u#a) (pre:s -> prop) (post:s -> a -> s -> prop)
(f:unit -> M.MSTATETOT a s rel pre post)
: mst rel a pre post | val of_msttotal (#s:Type u#2) (rel:FStar.Preorder.preorder s)
(a:Type u#a) (pre:s -> prop) (post:s -> a -> s -> prop)
(f:unit -> M.MSTATETOT a s rel pre post)
: mst rel a pre post | let of_msttotal (#s:Type u#2) (rel:FStar.Preorder.preorder s)
(a:Type u#a) (pre:s -> prop) (post:s -> a -> s -> prop)
(f:unit -> M.MSTATETOT a s rel pre post)
: mst rel a pre post
= let f = reify_ f in
fun s -> f s | {
"file_name": "lib/pulse_core/PulseCore.MonotonicStateMonad.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 14,
"end_line": 28,
"start_col": 0,
"start_line": 23
} | module PulseCore.MonotonicStateMonad
open FStar.Preorder
module M = FStar.MSTTotal
let mst (#s:Type u#s)
(rel:FStar.Preorder.preorder s)
(a:Type u#a)
(pre:s -> prop)
(post:s -> a -> s -> prop)
= s0:s { pre s0 }
-> Tot (
res:(a & s) {
post s0 res._1 res._2 /\
rel s0 res._2
}
)
assume (* to interoperate with a definition of a similar module in FStar.MSTTotal *)
val reify_ (#s:Type u#2) (#rel:FStar.Preorder.preorder s)
(#a:Type u#a) (#pre:s -> prop) (#post:s -> a -> s -> prop)
($f:unit -> M.MSTATETOT a s rel pre post)
: M.repr a s rel pre post | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.MSTTotal.fst.checked"
],
"interface_file": true,
"source_file": "PulseCore.MonotonicStateMonad.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.MSTTotal",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.MSTTotal",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "PulseCore",
"short_module": null
},
{
"abbrev": false,
"full_module": "PulseCore",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
rel: FStar.Preorder.preorder s ->
a: Type ->
pre: (_: s -> Prims.prop) ->
post: (_: s -> _: a -> _: s -> Prims.prop) ->
f: (_: Prims.unit -> FStar.MSTTotal.MSTATETOT a)
-> PulseCore.MonotonicStateMonad.mst rel a pre post | Prims.Tot | [
"total"
] | [] | [
"FStar.Preorder.preorder",
"Prims.prop",
"Prims.unit",
"FStar.Pervasives.Native.tuple2",
"Prims.l_and",
"FStar.Pervasives.Native.__proj__Mktuple2__item___1",
"FStar.Pervasives.Native.__proj__Mktuple2__item___2",
"FStar.MSTTotal.repr",
"PulseCore.MonotonicStateMonad.reify_",
"PulseCore.MonotonicStateMonad.mst"
] | [] | false | false | false | false | false | let of_msttotal
(#s: Type u#2)
(rel: FStar.Preorder.preorder s)
(a: Type u#a)
(pre: (s -> prop))
(post: (s -> a -> s -> prop))
(f: (unit -> M.MSTATETOT a s rel pre post))
: mst rel a pre post =
| let f = reify_ f in
fun s -> f s | false |
Vale.X64.Memory_Sems.fst | Vale.X64.Memory_Sems.low_lemma_load_mem64_full | val low_lemma_load_mem64_full (b:buffer64) (i:nat) (vfh:vale_full_heap) (t:taint) (hid:heaplet_id) : Lemma
(requires (
let (h, mt) = (Map16.get vfh.vf_heaplets hid, vfh.vf_layout.vl_taint) in
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b /\
valid_layout_buffer b vfh.vf_layout h false /\
valid_taint_buf64 b h mt t /\
mem_inv vfh
))
(ensures (
let (h, mt) = (Map16.get vfh.vf_heaplets hid, vfh.vf_layout.vl_taint) in
let ptr = buffer_addr b h + scale8 i in
is_full_read vfh.vf_heap h b i /\
// valid_addr64 ptr (heap_get (coerce vfh)) /\
valid_mem64 ptr vfh.vf_heap /\
valid_taint_buf64 b vfh.vf_heap mt t
)) | val low_lemma_load_mem64_full (b:buffer64) (i:nat) (vfh:vale_full_heap) (t:taint) (hid:heaplet_id) : Lemma
(requires (
let (h, mt) = (Map16.get vfh.vf_heaplets hid, vfh.vf_layout.vl_taint) in
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b /\
valid_layout_buffer b vfh.vf_layout h false /\
valid_taint_buf64 b h mt t /\
mem_inv vfh
))
(ensures (
let (h, mt) = (Map16.get vfh.vf_heaplets hid, vfh.vf_layout.vl_taint) in
let ptr = buffer_addr b h + scale8 i in
is_full_read vfh.vf_heap h b i /\
// valid_addr64 ptr (heap_get (coerce vfh)) /\
valid_mem64 ptr vfh.vf_heap /\
valid_taint_buf64 b vfh.vf_heap mt t
)) | let low_lemma_load_mem64_full b i vfh t hid =
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
() | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory_Sems.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 4,
"end_line": 638,
"start_col": 0,
"start_line": 636
} | module Vale.X64.Memory_Sems
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.Def.Words_s
module I = Vale.Interop
module S = Vale.X64.Machine_Semantics_s
module MB = LowStar.Monotonic.Buffer
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
friend Vale.X64.Memory
module IB = Vale.Interop.Base
let same_domain h m = Set.equal (IB.addrs_set (_ih h)) (Map.domain m)
let lemma_same_domains h m1 m2 = ()
let get_heap h = I.down_mem (_ih h)
let upd_heap h m = mi_heap_upd h m
//let lemma_upd_get_heap h = I.down_up_identity (_ih h)
let lemma_get_upd_heap h m = I.up_down_identity (_ih h) m
let lemma_heap_impl = ()
let lemma_heap_get_heap h = ()
let lemma_heap_taint h = ()
//let lemma_heap_upd_heap h mh mt = ()
[@"opaque_to_smt"]
let rec set_of_range (a:int) (n:nat) : Pure (Set.set int)
(requires True)
(ensures fun s -> (forall (i:int).{:pattern Set.mem i s} Set.mem i s <==> a <= i /\ i < a + n))
=
if n = 0 then Set.empty else Set.union (set_of_range a (n - 1)) (Set.singleton (a + n - 1))
let buffer_info_has_addr (bi:buffer_info) (a:int) =
let b = bi.bi_buffer in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
addr <= a /\ a < addr + len
let buffer_info_has_addr_opt (bi:option buffer_info) (a:int) =
match bi with
| None -> False
| Some bi -> buffer_info_has_addr bi a
#set-options "--z3rlimit 100"
let rec make_owns_rec (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
if n = 0 then ((fun _ -> None), (fun _ -> Set.empty)) else
let (m0, s0) = make_owns_rec h bs (n - 1) in
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let s i = if i = hi then Set.union (s0 i) s_b else s0 i in
let m a = if addr <= a && a < addr + len then Some (n - 1) else m0 a in
(m, s)
[@"opaque_to_smt"]
let make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
make_owns_rec h bs n
let rec lemma_make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n <= Seq.length bs /\
(forall (i:nat).{:pattern Seq.index bs i} i < Seq.length bs ==> buffer_readable h (Seq.index bs i).bi_buffer) /\
(forall (i1 i2:nat).{:pattern (Seq.index bs i1); (Seq.index bs i2)}
i1 < Seq.length bs /\ i2 < Seq.length bs ==> buffer_info_disjoint (Seq.index bs i1) (Seq.index bs i2))
)
(ensures (
let (m, s) = make_owns h bs n in
(forall (i:heaplet_id) (a:int).{:pattern Set.mem a (s i)}
(Set.mem a (s i) <==> Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (m a) == Some i) /\
(Set.mem a (s i) ==> buffer_info_has_addr_opt (Option.mapTot (fun n -> Seq.index bs n) (m a)) a) /\
(Set.mem a (s i) ==> Set.mem a (Map.domain h.mh))
) /\
(forall (k:nat) (a:int).{:pattern Set.mem a (s (Seq.index bs k).bi_heaplet)}
k < n /\ buffer_info_has_addr (Seq.index bs k) a ==> Set.mem a (s (Seq.index bs k).bi_heaplet))
))
=
reveal_opaque (`%make_owns) make_owns;
if n = 0 then () else
let _ = make_owns h bs (n - 1) in
let (m, s) = make_owns h bs n in
lemma_make_owns h bs (n - 1);
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let lem1 (a:int) : Lemma
(requires Set.mem a s_b)
(ensures Set.mem a (Map.domain h.mh))
[SMTPat (Set.mem a (Map.domain h.mh))]
=
I.addrs_set_mem h.ih b a
in
let lem2 (i:heaplet_id) (a:int) : Lemma
(requires i =!= hi /\ Set.mem a (Set.intersect s_b (s i)))
(ensures False)
[SMTPat (Set.mem a (s i))]
=
reveal_opaque (`%addr_map_pred) addr_map_pred
in
()
#push-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_loc_mutable_buffers_rec (l:list buffer_info) (s:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n + List.length l == Seq.length s /\
list_to_seq_post l s n
)
(ensures (
let modloc = loc_mutable_buffers l in
forall (i:nat).{:pattern Seq.index s i} n <= i /\ i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes modloc (loc_buffer bi.bi_buffer))
))
(decreases l)
=
match l with
| [] -> ()
| h::t -> lemma_loc_mutable_buffers_rec t s (n + 1)
#pop-options
let lemma_loc_mutable_buffers (l:list buffer_info) : Lemma
(ensures (
let s = list_to_seq l in
forall (i:nat).{:pattern Seq.index s i} i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes (loc_mutable_buffers l) (loc_buffer bi.bi_buffer))
))
=
lemma_list_to_seq l;
lemma_loc_mutable_buffers_rec l (list_to_seq l) 0
let create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let modloc = loc_mutable_buffers buffers in
let layout1 = h1.vf_layout in
let layin1 = layout1.vl_inner in
let (hmap, hsets) = make_owns h1.vf_heap bs (Seq.length bs) in
let hmap a = Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (hmap a) in
let l = {
vl_heaplets_initialized = true;
vl_heaplet_map = hmap;
vl_heaplet_sets = hsets;
vl_old_heap = h1.vf_heap;
vl_buffers = bs;
vl_mod_loc = modloc;
} in
let layout2 = {layout1 with vl_inner = l} in
let h2 = {
vf_layout = layout2;
vf_heap = h1.vf_heap;
vf_heaplets = h1.vf_heaplets;
} in
h2
let lemma_create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let h2 = create_heaplets buffers h1 in
assert (h2.vf_layout.vl_inner.vl_buffers == bs); // REVIEW: why is this necessary, even with extra ifuel?
lemma_make_owns h1.vf_heap bs (Seq.length bs);
lemma_loc_mutable_buffers buffers;
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
let destroy_heaplets h1 =
h1
let lemma_destroy_heaplets h1 =
()
val heap_shift (m1 m2:S.machine_heap) (base:int) (n:nat) : Lemma
(requires (forall i. 0 <= i /\ i < n ==> m1.[base + i] == m2.[base + i]))
(ensures (forall i. {:pattern (m1.[i])} base <= i /\ i < base + n ==> m1.[i] == m2.[i]))
#push-options "--smtencoding.l_arith_repr boxwrap"
let heap_shift m1 m2 base n =
assert (forall i. base <= i /\ i < base + n ==>
m1.[base + (i - base)] == m2.[base + (i - base)])
#pop-options
val same_mem_eq_slices64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 8 + 8 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8)))
let same_mem_eq_slices64 b i v k h1 h2 mem1 mem2 =
let t = TUInt64 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up64 (b:buffer64) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 8}) : Lemma
(scale8 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint64_view in
UV.length_eq vb
val same_mem_get_heap_val64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale8 k in
forall (x:int).{:pattern (mem1.[x])} ptr <= x /\ x < ptr + 8 ==> mem1.[x] == mem2.[x]))
let same_mem_get_heap_val64 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale8 k in
let addr = buffer_addr b h1 in
let aux (x:int{ptr <= x /\ x < ptr + 8}) : Lemma (mem1.[x] == mem2.[x]) =
let i = x - ptr in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices64 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8) (k * 8 + 8)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8) (k * 8 + 8)) in
assert (Seq.index s1 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i));
length_up64 b h1 k i;
assert (mem1.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i)));
assert (Seq.index s2 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i));
length_up64 b h2 k i;
assert (mem2.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i)))
in
Classical.forall_intro aux;
assert (forall i. addr + (scale8 k + i) == ptr + i)
let rec written_buffer_down64_aux1
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(k:nat) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j.{:pattern (mem1.[j]) \/ (mem2.[j])}
base <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem1.[j])}
j >= base /\ j < base + scale8 i ==>
mem1.[j] == mem2.[j]))
(decreases %[i-k]) =
if k >= i then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux1 b i v h base (k+1) h1 mem1 mem2
end
let rec written_buffer_down64_aux2
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(n:nat{n == buffer_length b})
(k:nat{k > i}) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
base + scale8 (i+1) <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
j >= base + scale8 (i+1) /\ j < base + scale8 n ==>
mem1.[j] == mem2.[j]))
(decreases %[n-k]) =
if k >= n then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux2 b i v h base n (k+1) h1 mem1 mem2
end
let written_buffer_down64 (b:buffer64{buffer_writeable b}) (i:nat{i < buffer_length b}) (v:nat64) (h:vale_heap)
: Lemma
(requires List.memP b (IB.ptrs_of_mem (_ih h)))
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
(base <= j /\ j < base + scale8 i) \/
(base + scale8 (i+1) <= j /\ j < base + scale8 n) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
written_buffer_down64_aux1 b i v h base 0 h1 mem1 mem2;
written_buffer_down64_aux2 b i v h base n (i+1) h1 mem1 mem2
let unwritten_buffer_down (t:base_typ) (b:buffer t{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:base_typ_as_vale_type t)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall (a:b8{List.memP a (IB.ptrs_of_mem (_ih h)) /\ a =!= b}) j. {:pattern mem1.[j]; List.memP a (IB.ptrs_of_mem (_ih h)) \/ mem2.[j]; List.memP a (IB.ptrs_of_mem (_ih h))}
let base = (IB.addrs_of_mem (_ih h)) a in
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==> mem1.[j] == mem2.[j]))
= let aux (a:b8{a =!= b /\ List.memP a (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let base = (IB.addrs_of_mem (_ih h)) a in
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall j.
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==>
mem1.[j] == mem2.[j]))
= let db = get_downview a.bsrc in
if DV.length db = 0 then ()
else
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = (IB.addrs_of_mem (_ih h)) a in
let s0 = DV.as_seq (IB.hs_of_mem (_ih h)) db in
let s1 = DV.as_seq (IB.hs_of_mem (_ih h1)) db in
opaque_assert (`%IB.list_disjoint_or_eq) IB.list_disjoint_or_eq IB.list_disjoint_or_eq_def (MB.disjoint a.bsrc b.bsrc);
lemma_dv_equal (IB.down_view a.src) a.bsrc (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1));
assert (Seq.equal s0 s1);
assert (forall (j:int).{:pattern (mem1.[j])}
base <= j /\ j < base + Seq.length s0 ==> v_to_typ TUInt8 (Seq.index s0 (j - base)) == mem1.[j]);
heap_shift mem1 mem2 base (DV.length db)
in
Classical.forall_intro aux
let store_buffer_down64_mem
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
forall (j:int). {:pattern mem1.[j] \/ mem2.[j]}
j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
let aux (j:int)
: Lemma
(j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j])
=
I.addrs_set_lemma_all ();
if j >= base && j < base + DV.length (get_downview b.bsrc) then begin
written_buffer_down64 b i v h;
length_t_eq (TUInt64) b
end
else if not (I.valid_addr (_ih h) j)
then I.same_unspecified_down (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1)) (IB.ptrs_of_mem (_ih h))
else unwritten_buffer_down TUInt64 b i v h
in
Classical.forall_intro aux
let store_buffer_aux_down64_mem (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
forall j. {:pattern mem1.[j] \/ mem2.[j]}
j < ptr \/ j >= ptr + 8 ==>
mem1.[j] == mem2.[j]))
= let t = TUInt64 in
let h1 = store_mem t ptr v h in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
store_buffer_write t ptr v h;
assert (buffer_addr b h + scale8 i == ptr);
assert (buffer_addr b h + scale8 (i+1) == ptr + 8);
store_buffer_down64_mem b i v h
let store_buffer_aux_down64_mem2 (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
S.get_heap_val64 ptr mem2 == v))
= let t = TUInt64 in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
let h1 = store_mem t ptr v h in
let mem2 = I.down_mem (_ih h1) in
store_buffer_write t ptr v h;
assert (Seq.index (buffer_as_seq h1 b) i == v);
index64_get_heap_val64 h1 b mem2 i
let in_bounds64 (h:vale_heap) (b:buffer64) (i:nat{i < buffer_length b})
: Lemma (scale8 i + 8 <= DV.length (get_downview b.bsrc))
=
length_t_eq TUInt64 b
let bytes_valid64 ptr h =
reveal_opaque (`%S.valid_addr64) S.valid_addr64;
let t = TUInt64 in
let b = get_addr_ptr t ptr h in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
in_bounds64 h b i;
I.addrs_set_mem (_ih h) b ptr;
I.addrs_set_mem (_ih h) b (ptr+1);
I.addrs_set_mem (_ih h) b (ptr+2);
I.addrs_set_mem (_ih h) b (ptr+3);
I.addrs_set_mem (_ih h) b (ptr+4);
I.addrs_set_mem (_ih h) b (ptr+5);
I.addrs_set_mem (_ih h) b (ptr+6);
I.addrs_set_mem (_ih h) b (ptr+7)
val same_mem_get_heap_val128 (b:buffer128)
(i:nat{i < buffer_length b})
(v:quad32)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1)) /\ buffer_writeable b})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale16 k in
forall i.{:pattern mem1.[i]} i >= ptr /\ i < ptr+16 ==> mem1.[i] == mem2.[i]))
val same_mem_eq_slices128 (b:buffer128)
(i:nat{i < buffer_length b})
(v:quad32)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1)) /\ buffer_writeable b})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 16 + 16 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 16) (k * 16 + 16) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 16) (k * 16 + 16)))
let same_mem_eq_slices128 b i v k h1 h2 mem1 mem2 =
let t = TUInt128 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up128 (b:buffer128) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 16}) : Lemma
(scale16 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint128_view in
UV.length_eq vb
let same_mem_get_heap_val128 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale16 k in
let addr = buffer_addr b h1 in
let aux (i:nat{ptr <= i /\ i < ptr+16}) : Lemma (mem1.[i] == mem2.[i]) =
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint128_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices128 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16) (k * 16 + 16)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16) (k * 16 + 16)) in
assert (Seq.index s1 (i - ptr) == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16 + (i-ptr)));
length_up128 b h1 k (i-ptr);
assert (mem1.[i] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16 + (i-ptr))));
assert (Seq.index s2 (i-ptr) == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16 + (i-ptr)));
length_up128 b h2 k (i-ptr);
assert (mem2.[addr+(scale16 k + (i-ptr))] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16 + (i-ptr))));
assert (forall i. addr + (scale16 k + (i-ptr)) == i)
in
Classical.forall_intro aux
let in_bounds128 (h:vale_heap) (b:buffer128) (i:nat{i < buffer_length b}) : Lemma
(scale16 i + 16 <= DV.length (get_downview b.bsrc))
=
length_t_eq TUInt128 b
#push-options "--z3rlimit 20"
#restart-solver
let bytes_valid128 ptr h =
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
IB.list_disjoint_or_eq_reveal ();
let t = TUInt128 in
let b = get_addr_ptr t ptr h in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
in_bounds128 h b i;
I.addrs_set_mem (_ih h) b ptr;
I.addrs_set_mem (_ih h) b (ptr+1);
I.addrs_set_mem (_ih h) b (ptr+2);
I.addrs_set_mem (_ih h) b (ptr+3);
I.addrs_set_mem (_ih h) b (ptr+4);
I.addrs_set_mem (_ih h) b (ptr+5);
I.addrs_set_mem (_ih h) b (ptr+6);
I.addrs_set_mem (_ih h) b (ptr+7);
I.addrs_set_mem (_ih h) b (ptr+8);
I.addrs_set_mem (_ih h) b (ptr+9);
I.addrs_set_mem (_ih h) b (ptr+10);
I.addrs_set_mem (_ih h) b (ptr+11);
I.addrs_set_mem (_ih h) b (ptr+12);
I.addrs_set_mem (_ih h) b (ptr+13);
I.addrs_set_mem (_ih h) b (ptr+14);
I.addrs_set_mem (_ih h) b (ptr+15)
#pop-options
let equiv_load_mem64 ptr h =
let t = TUInt64 in
let b = get_addr_ptr t ptr h in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
let addr = buffer_addr b h in
let contents = DV.as_seq (_ih h).IB.hs (get_downview b.bsrc) in
let heap = get_heap h in
index64_get_heap_val64 h b heap i;
lemma_load_mem64 b i h
//let low_lemma_valid_mem64 b i h =
// lemma_valid_mem64 b i h;
// bytes_valid64 (buffer_addr b h + scale8 i) h
//let low_lemma_load_mem64 b i h =
// lemma_valid_mem64 b i h;
// lemma_load_mem64 b i h;
// equiv_load_mem64 (buffer_addr b h + scale8 i) h
//let same_domain_update64 b i v h =
// low_lemma_valid_mem64 b i h;
// Vale.Arch.MachineHeap.same_domain_update64 (buffer_addr b h + scale8 i) v (get_heap h)
open Vale.X64.BufferViewStore
let low_lemma_store_mem64_aux
(b:buffer64)
(heap:S.machine_heap)
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{buffer_readable h b /\ buffer_writeable b})
: Lemma
(requires IB.correct_down_p (_ih h) heap b)
(ensures (let heap' = S.update_heap64 (buffer_addr b h + scale8 i) v heap in
let h' = store_mem64 (buffer_addr b h + scale8 i) v h in
(_ih h').IB.hs == DV.upd_seq (_ih h).IB.hs (get_downview b.bsrc) (I.get_seq_heap heap' (_ih h).IB.addrs b))) =
let ptr = buffer_addr b h + scale8 i in
let heap' = S.update_heap64 ptr v heap in
let h' = store_mem64 ptr v h in
lemma_store_mem64 b i v h;
length_t_eq TUInt64 b;
bv_upd_update_heap64 b heap i v (_ih h);
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db Vale.Interop.Views.up_view64 in
assert (UV.upd (_ih h).IB.hs bv i (UInt64.uint_to_t v) == (_ih h').IB.hs)
val valid_state_store_mem64_aux: (i:nat) -> (v:nat64) -> (h:vale_heap) -> Lemma
(requires writeable_mem64 i h)
(ensures (
let heap = get_heap h in
let heap' = S.update_heap64 i v heap in
let h' = store_mem64 i v h in
heap' == I.down_mem (_ih h')
))
let valid_state_store_mem64_aux i v h =
let heap = get_heap h in
let heap' = S.update_heap64 i v heap in
let h1 = store_mem TUInt64 i v h in
store_buffer_aux_down64_mem i v h;
store_buffer_aux_down64_mem2 i v h;
let mem1 = heap' in
let mem2 = I.down_mem (_ih h1) in
let aux () : Lemma (forall j. mem1.[j] == mem2.[j]) =
Vale.Arch.MachineHeap.same_mem_get_heap_val64 i mem1 mem2;
Vale.Arch.MachineHeap.correct_update_get64 i v heap;
Vale.Arch.MachineHeap.frame_update_heap64 i v heap
in let aux2 () : Lemma (Set.equal (Map.domain mem1) (Map.domain mem2)) =
bytes_valid64 i h;
Vale.Arch.MachineHeap.same_domain_update64 i v heap
in aux(); aux2();
Map.lemma_equal_intro mem1 mem2 | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Memory.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.BufferViewStore.fsti.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Memory_Sems.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.BufferViewStore",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_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
}
] | {
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
b: Vale.X64.Memory.buffer64 ->
i: Prims.nat ->
vfh: Vale.Arch.HeapImpl.vale_full_heap ->
t: Vale.Arch.HeapTypes_s.taint ->
hid: Vale.Arch.HeapImpl.heaplet_id
-> FStar.Pervasives.Lemma
(requires
(let _ =
Vale.Lib.Map16.get (Mkvale_full_heap?.vf_heaplets vfh) hid,
Mkvale_heap_layout?.vl_taint (Mkvale_full_heap?.vf_layout vfh)
in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ h mt = _ in
i < FStar.Seq.Base.length (Vale.X64.Memory.buffer_as_seq h b) /\
Vale.X64.Memory.buffer_readable h b /\
Vale.X64.Memory.valid_layout_buffer b (Mkvale_full_heap?.vf_layout vfh) h false /\
Vale.X64.Memory.valid_taint_buf64 b h mt t /\ Vale.X64.Memory.mem_inv vfh)
<:
Type0))
(ensures
(let _ =
Vale.Lib.Map16.get (Mkvale_full_heap?.vf_heaplets vfh) hid,
Mkvale_heap_layout?.vl_taint (Mkvale_full_heap?.vf_layout vfh)
in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ h mt = _ in
let ptr = Vale.X64.Memory.buffer_addr b h + Vale.X64.Memory.scale8 i in
Vale.X64.Memory_Sems.is_full_read (Mkvale_full_heap?.vf_heap vfh) h b i /\
Vale.X64.Memory.valid_mem64 ptr (Mkvale_full_heap?.vf_heap vfh) /\
Vale.X64.Memory.valid_taint_buf64 b (Mkvale_full_heap?.vf_heap vfh) mt t)
<:
Type0)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.X64.Memory.buffer64",
"Prims.nat",
"Vale.Arch.HeapImpl.vale_full_heap",
"Vale.Arch.HeapTypes_s.taint",
"Vale.Arch.HeapImpl.heaplet_id",
"Prims.unit",
"FStar.Pervasives.reveal_opaque",
"Vale.Arch.HeapTypes_s.base_typ",
"Vale.X64.Memory.buffer",
"Vale.Arch.HeapImpl.vale_heap_layout",
"FStar.Pervasives.Native.option",
"Prims.bool",
"Vale.Def.Prop_s.prop0",
"Vale.X64.Memory.valid_layout_buffer_id"
] | [] | true | false | true | false | false | let low_lemma_load_mem64_full b i vfh t hid =
| reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
() | false |
PulseCore.MonotonicStateMonad.fst | PulseCore.MonotonicStateMonad.witnessed | val witnessed (#s:Type u#s) (p: s -> prop) : Type0 | val witnessed (#s:Type u#s) (p: s -> prop) : Type0 | let witnessed p
= unit | {
"file_name": "lib/pulse_core/PulseCore.MonotonicStateMonad.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 6,
"end_line": 54,
"start_col": 0,
"start_line": 53
} | module PulseCore.MonotonicStateMonad
open FStar.Preorder
module M = FStar.MSTTotal
let mst (#s:Type u#s)
(rel:FStar.Preorder.preorder s)
(a:Type u#a)
(pre:s -> prop)
(post:s -> a -> s -> prop)
= s0:s { pre s0 }
-> Tot (
res:(a & s) {
post s0 res._1 res._2 /\
rel s0 res._2
}
)
assume (* to interoperate with a definition of a similar module in FStar.MSTTotal *)
val reify_ (#s:Type u#2) (#rel:FStar.Preorder.preorder s)
(#a:Type u#a) (#pre:s -> prop) (#post:s -> a -> s -> prop)
($f:unit -> M.MSTATETOT a s rel pre post)
: M.repr a s rel pre post
let of_msttotal (#s:Type u#2) (rel:FStar.Preorder.preorder s)
(a:Type u#a) (pre:s -> prop) (post:s -> a -> s -> prop)
(f:unit -> M.MSTATETOT a s rel pre post)
: mst rel a pre post
= let f = reify_ f in
fun s -> f s
let to_msttotal (#s:Type u#2) (rel:FStar.Preorder.preorder s)
(a:Type u#a) (pre:s -> prop) (post:s -> a -> s -> prop)
(f:mst rel a pre post)
: M.MSTATETOT a s rel pre post
= M.MSTATETOT?.reflect (fun s -> f s)
let return x
= fun s0 -> x, s0
let bind f g
= fun s0 ->
let x, s1 = f s0 in
g x s1
let weaken f
= fun s -> f s
let get _
= fun s -> s, s
let put v
= fun _ -> (), v | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.MSTTotal.fst.checked"
],
"interface_file": true,
"source_file": "PulseCore.MonotonicStateMonad.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.MSTTotal",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.MSTTotal",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "PulseCore",
"short_module": null
},
{
"abbrev": false,
"full_module": "PulseCore",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | p: (_: s -> Prims.prop) -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Prims.prop",
"Prims.unit"
] | [] | false | false | false | true | true | let witnessed p =
| unit | false |
Vale.X64.Memory_Sems.fst | Vale.X64.Memory_Sems.low_lemma_valid_mem128 | val low_lemma_valid_mem128 (b:buffer128) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b
)
(ensures
S.valid_addr128 (buffer_addr b h + scale16 i) (get_heap h)
) | val low_lemma_valid_mem128 (b:buffer128) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b
)
(ensures
S.valid_addr128 (buffer_addr b h + scale16 i) (get_heap h)
) | let low_lemma_valid_mem128 b i h =
lemma_valid_mem128 b i h;
bytes_valid128 (buffer_addr b h + scale16 i) h | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory_Sems.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 48,
"end_line": 735,
"start_col": 0,
"start_line": 733
} | module Vale.X64.Memory_Sems
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.Def.Words_s
module I = Vale.Interop
module S = Vale.X64.Machine_Semantics_s
module MB = LowStar.Monotonic.Buffer
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
friend Vale.X64.Memory
module IB = Vale.Interop.Base
let same_domain h m = Set.equal (IB.addrs_set (_ih h)) (Map.domain m)
let lemma_same_domains h m1 m2 = ()
let get_heap h = I.down_mem (_ih h)
let upd_heap h m = mi_heap_upd h m
//let lemma_upd_get_heap h = I.down_up_identity (_ih h)
let lemma_get_upd_heap h m = I.up_down_identity (_ih h) m
let lemma_heap_impl = ()
let lemma_heap_get_heap h = ()
let lemma_heap_taint h = ()
//let lemma_heap_upd_heap h mh mt = ()
[@"opaque_to_smt"]
let rec set_of_range (a:int) (n:nat) : Pure (Set.set int)
(requires True)
(ensures fun s -> (forall (i:int).{:pattern Set.mem i s} Set.mem i s <==> a <= i /\ i < a + n))
=
if n = 0 then Set.empty else Set.union (set_of_range a (n - 1)) (Set.singleton (a + n - 1))
let buffer_info_has_addr (bi:buffer_info) (a:int) =
let b = bi.bi_buffer in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
addr <= a /\ a < addr + len
let buffer_info_has_addr_opt (bi:option buffer_info) (a:int) =
match bi with
| None -> False
| Some bi -> buffer_info_has_addr bi a
#set-options "--z3rlimit 100"
let rec make_owns_rec (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
if n = 0 then ((fun _ -> None), (fun _ -> Set.empty)) else
let (m0, s0) = make_owns_rec h bs (n - 1) in
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let s i = if i = hi then Set.union (s0 i) s_b else s0 i in
let m a = if addr <= a && a < addr + len then Some (n - 1) else m0 a in
(m, s)
[@"opaque_to_smt"]
let make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
make_owns_rec h bs n
let rec lemma_make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n <= Seq.length bs /\
(forall (i:nat).{:pattern Seq.index bs i} i < Seq.length bs ==> buffer_readable h (Seq.index bs i).bi_buffer) /\
(forall (i1 i2:nat).{:pattern (Seq.index bs i1); (Seq.index bs i2)}
i1 < Seq.length bs /\ i2 < Seq.length bs ==> buffer_info_disjoint (Seq.index bs i1) (Seq.index bs i2))
)
(ensures (
let (m, s) = make_owns h bs n in
(forall (i:heaplet_id) (a:int).{:pattern Set.mem a (s i)}
(Set.mem a (s i) <==> Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (m a) == Some i) /\
(Set.mem a (s i) ==> buffer_info_has_addr_opt (Option.mapTot (fun n -> Seq.index bs n) (m a)) a) /\
(Set.mem a (s i) ==> Set.mem a (Map.domain h.mh))
) /\
(forall (k:nat) (a:int).{:pattern Set.mem a (s (Seq.index bs k).bi_heaplet)}
k < n /\ buffer_info_has_addr (Seq.index bs k) a ==> Set.mem a (s (Seq.index bs k).bi_heaplet))
))
=
reveal_opaque (`%make_owns) make_owns;
if n = 0 then () else
let _ = make_owns h bs (n - 1) in
let (m, s) = make_owns h bs n in
lemma_make_owns h bs (n - 1);
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let lem1 (a:int) : Lemma
(requires Set.mem a s_b)
(ensures Set.mem a (Map.domain h.mh))
[SMTPat (Set.mem a (Map.domain h.mh))]
=
I.addrs_set_mem h.ih b a
in
let lem2 (i:heaplet_id) (a:int) : Lemma
(requires i =!= hi /\ Set.mem a (Set.intersect s_b (s i)))
(ensures False)
[SMTPat (Set.mem a (s i))]
=
reveal_opaque (`%addr_map_pred) addr_map_pred
in
()
#push-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_loc_mutable_buffers_rec (l:list buffer_info) (s:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n + List.length l == Seq.length s /\
list_to_seq_post l s n
)
(ensures (
let modloc = loc_mutable_buffers l in
forall (i:nat).{:pattern Seq.index s i} n <= i /\ i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes modloc (loc_buffer bi.bi_buffer))
))
(decreases l)
=
match l with
| [] -> ()
| h::t -> lemma_loc_mutable_buffers_rec t s (n + 1)
#pop-options
let lemma_loc_mutable_buffers (l:list buffer_info) : Lemma
(ensures (
let s = list_to_seq l in
forall (i:nat).{:pattern Seq.index s i} i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes (loc_mutable_buffers l) (loc_buffer bi.bi_buffer))
))
=
lemma_list_to_seq l;
lemma_loc_mutable_buffers_rec l (list_to_seq l) 0
let create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let modloc = loc_mutable_buffers buffers in
let layout1 = h1.vf_layout in
let layin1 = layout1.vl_inner in
let (hmap, hsets) = make_owns h1.vf_heap bs (Seq.length bs) in
let hmap a = Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (hmap a) in
let l = {
vl_heaplets_initialized = true;
vl_heaplet_map = hmap;
vl_heaplet_sets = hsets;
vl_old_heap = h1.vf_heap;
vl_buffers = bs;
vl_mod_loc = modloc;
} in
let layout2 = {layout1 with vl_inner = l} in
let h2 = {
vf_layout = layout2;
vf_heap = h1.vf_heap;
vf_heaplets = h1.vf_heaplets;
} in
h2
let lemma_create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let h2 = create_heaplets buffers h1 in
assert (h2.vf_layout.vl_inner.vl_buffers == bs); // REVIEW: why is this necessary, even with extra ifuel?
lemma_make_owns h1.vf_heap bs (Seq.length bs);
lemma_loc_mutable_buffers buffers;
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
let destroy_heaplets h1 =
h1
let lemma_destroy_heaplets h1 =
()
val heap_shift (m1 m2:S.machine_heap) (base:int) (n:nat) : Lemma
(requires (forall i. 0 <= i /\ i < n ==> m1.[base + i] == m2.[base + i]))
(ensures (forall i. {:pattern (m1.[i])} base <= i /\ i < base + n ==> m1.[i] == m2.[i]))
#push-options "--smtencoding.l_arith_repr boxwrap"
let heap_shift m1 m2 base n =
assert (forall i. base <= i /\ i < base + n ==>
m1.[base + (i - base)] == m2.[base + (i - base)])
#pop-options
val same_mem_eq_slices64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 8 + 8 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8)))
let same_mem_eq_slices64 b i v k h1 h2 mem1 mem2 =
let t = TUInt64 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up64 (b:buffer64) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 8}) : Lemma
(scale8 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint64_view in
UV.length_eq vb
val same_mem_get_heap_val64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale8 k in
forall (x:int).{:pattern (mem1.[x])} ptr <= x /\ x < ptr + 8 ==> mem1.[x] == mem2.[x]))
let same_mem_get_heap_val64 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale8 k in
let addr = buffer_addr b h1 in
let aux (x:int{ptr <= x /\ x < ptr + 8}) : Lemma (mem1.[x] == mem2.[x]) =
let i = x - ptr in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices64 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8) (k * 8 + 8)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8) (k * 8 + 8)) in
assert (Seq.index s1 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i));
length_up64 b h1 k i;
assert (mem1.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i)));
assert (Seq.index s2 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i));
length_up64 b h2 k i;
assert (mem2.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i)))
in
Classical.forall_intro aux;
assert (forall i. addr + (scale8 k + i) == ptr + i)
let rec written_buffer_down64_aux1
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(k:nat) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j.{:pattern (mem1.[j]) \/ (mem2.[j])}
base <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem1.[j])}
j >= base /\ j < base + scale8 i ==>
mem1.[j] == mem2.[j]))
(decreases %[i-k]) =
if k >= i then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux1 b i v h base (k+1) h1 mem1 mem2
end
let rec written_buffer_down64_aux2
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(n:nat{n == buffer_length b})
(k:nat{k > i}) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
base + scale8 (i+1) <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
j >= base + scale8 (i+1) /\ j < base + scale8 n ==>
mem1.[j] == mem2.[j]))
(decreases %[n-k]) =
if k >= n then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux2 b i v h base n (k+1) h1 mem1 mem2
end
let written_buffer_down64 (b:buffer64{buffer_writeable b}) (i:nat{i < buffer_length b}) (v:nat64) (h:vale_heap)
: Lemma
(requires List.memP b (IB.ptrs_of_mem (_ih h)))
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
(base <= j /\ j < base + scale8 i) \/
(base + scale8 (i+1) <= j /\ j < base + scale8 n) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
written_buffer_down64_aux1 b i v h base 0 h1 mem1 mem2;
written_buffer_down64_aux2 b i v h base n (i+1) h1 mem1 mem2
let unwritten_buffer_down (t:base_typ) (b:buffer t{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:base_typ_as_vale_type t)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall (a:b8{List.memP a (IB.ptrs_of_mem (_ih h)) /\ a =!= b}) j. {:pattern mem1.[j]; List.memP a (IB.ptrs_of_mem (_ih h)) \/ mem2.[j]; List.memP a (IB.ptrs_of_mem (_ih h))}
let base = (IB.addrs_of_mem (_ih h)) a in
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==> mem1.[j] == mem2.[j]))
= let aux (a:b8{a =!= b /\ List.memP a (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let base = (IB.addrs_of_mem (_ih h)) a in
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall j.
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==>
mem1.[j] == mem2.[j]))
= let db = get_downview a.bsrc in
if DV.length db = 0 then ()
else
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = (IB.addrs_of_mem (_ih h)) a in
let s0 = DV.as_seq (IB.hs_of_mem (_ih h)) db in
let s1 = DV.as_seq (IB.hs_of_mem (_ih h1)) db in
opaque_assert (`%IB.list_disjoint_or_eq) IB.list_disjoint_or_eq IB.list_disjoint_or_eq_def (MB.disjoint a.bsrc b.bsrc);
lemma_dv_equal (IB.down_view a.src) a.bsrc (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1));
assert (Seq.equal s0 s1);
assert (forall (j:int).{:pattern (mem1.[j])}
base <= j /\ j < base + Seq.length s0 ==> v_to_typ TUInt8 (Seq.index s0 (j - base)) == mem1.[j]);
heap_shift mem1 mem2 base (DV.length db)
in
Classical.forall_intro aux
let store_buffer_down64_mem
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
forall (j:int). {:pattern mem1.[j] \/ mem2.[j]}
j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
let aux (j:int)
: Lemma
(j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j])
=
I.addrs_set_lemma_all ();
if j >= base && j < base + DV.length (get_downview b.bsrc) then begin
written_buffer_down64 b i v h;
length_t_eq (TUInt64) b
end
else if not (I.valid_addr (_ih h) j)
then I.same_unspecified_down (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1)) (IB.ptrs_of_mem (_ih h))
else unwritten_buffer_down TUInt64 b i v h
in
Classical.forall_intro aux
let store_buffer_aux_down64_mem (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
forall j. {:pattern mem1.[j] \/ mem2.[j]}
j < ptr \/ j >= ptr + 8 ==>
mem1.[j] == mem2.[j]))
= let t = TUInt64 in
let h1 = store_mem t ptr v h in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
store_buffer_write t ptr v h;
assert (buffer_addr b h + scale8 i == ptr);
assert (buffer_addr b h + scale8 (i+1) == ptr + 8);
store_buffer_down64_mem b i v h
let store_buffer_aux_down64_mem2 (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
S.get_heap_val64 ptr mem2 == v))
= let t = TUInt64 in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
let h1 = store_mem t ptr v h in
let mem2 = I.down_mem (_ih h1) in
store_buffer_write t ptr v h;
assert (Seq.index (buffer_as_seq h1 b) i == v);
index64_get_heap_val64 h1 b mem2 i
let in_bounds64 (h:vale_heap) (b:buffer64) (i:nat{i < buffer_length b})
: Lemma (scale8 i + 8 <= DV.length (get_downview b.bsrc))
=
length_t_eq TUInt64 b
let bytes_valid64 ptr h =
reveal_opaque (`%S.valid_addr64) S.valid_addr64;
let t = TUInt64 in
let b = get_addr_ptr t ptr h in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
in_bounds64 h b i;
I.addrs_set_mem (_ih h) b ptr;
I.addrs_set_mem (_ih h) b (ptr+1);
I.addrs_set_mem (_ih h) b (ptr+2);
I.addrs_set_mem (_ih h) b (ptr+3);
I.addrs_set_mem (_ih h) b (ptr+4);
I.addrs_set_mem (_ih h) b (ptr+5);
I.addrs_set_mem (_ih h) b (ptr+6);
I.addrs_set_mem (_ih h) b (ptr+7)
val same_mem_get_heap_val128 (b:buffer128)
(i:nat{i < buffer_length b})
(v:quad32)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1)) /\ buffer_writeable b})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale16 k in
forall i.{:pattern mem1.[i]} i >= ptr /\ i < ptr+16 ==> mem1.[i] == mem2.[i]))
val same_mem_eq_slices128 (b:buffer128)
(i:nat{i < buffer_length b})
(v:quad32)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1)) /\ buffer_writeable b})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 16 + 16 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 16) (k * 16 + 16) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 16) (k * 16 + 16)))
let same_mem_eq_slices128 b i v k h1 h2 mem1 mem2 =
let t = TUInt128 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up128 (b:buffer128) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 16}) : Lemma
(scale16 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint128_view in
UV.length_eq vb
let same_mem_get_heap_val128 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale16 k in
let addr = buffer_addr b h1 in
let aux (i:nat{ptr <= i /\ i < ptr+16}) : Lemma (mem1.[i] == mem2.[i]) =
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint128_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices128 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16) (k * 16 + 16)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16) (k * 16 + 16)) in
assert (Seq.index s1 (i - ptr) == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16 + (i-ptr)));
length_up128 b h1 k (i-ptr);
assert (mem1.[i] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16 + (i-ptr))));
assert (Seq.index s2 (i-ptr) == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16 + (i-ptr)));
length_up128 b h2 k (i-ptr);
assert (mem2.[addr+(scale16 k + (i-ptr))] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16 + (i-ptr))));
assert (forall i. addr + (scale16 k + (i-ptr)) == i)
in
Classical.forall_intro aux
let in_bounds128 (h:vale_heap) (b:buffer128) (i:nat{i < buffer_length b}) : Lemma
(scale16 i + 16 <= DV.length (get_downview b.bsrc))
=
length_t_eq TUInt128 b
#push-options "--z3rlimit 20"
#restart-solver
let bytes_valid128 ptr h =
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
IB.list_disjoint_or_eq_reveal ();
let t = TUInt128 in
let b = get_addr_ptr t ptr h in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
in_bounds128 h b i;
I.addrs_set_mem (_ih h) b ptr;
I.addrs_set_mem (_ih h) b (ptr+1);
I.addrs_set_mem (_ih h) b (ptr+2);
I.addrs_set_mem (_ih h) b (ptr+3);
I.addrs_set_mem (_ih h) b (ptr+4);
I.addrs_set_mem (_ih h) b (ptr+5);
I.addrs_set_mem (_ih h) b (ptr+6);
I.addrs_set_mem (_ih h) b (ptr+7);
I.addrs_set_mem (_ih h) b (ptr+8);
I.addrs_set_mem (_ih h) b (ptr+9);
I.addrs_set_mem (_ih h) b (ptr+10);
I.addrs_set_mem (_ih h) b (ptr+11);
I.addrs_set_mem (_ih h) b (ptr+12);
I.addrs_set_mem (_ih h) b (ptr+13);
I.addrs_set_mem (_ih h) b (ptr+14);
I.addrs_set_mem (_ih h) b (ptr+15)
#pop-options
let equiv_load_mem64 ptr h =
let t = TUInt64 in
let b = get_addr_ptr t ptr h in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
let addr = buffer_addr b h in
let contents = DV.as_seq (_ih h).IB.hs (get_downview b.bsrc) in
let heap = get_heap h in
index64_get_heap_val64 h b heap i;
lemma_load_mem64 b i h
//let low_lemma_valid_mem64 b i h =
// lemma_valid_mem64 b i h;
// bytes_valid64 (buffer_addr b h + scale8 i) h
//let low_lemma_load_mem64 b i h =
// lemma_valid_mem64 b i h;
// lemma_load_mem64 b i h;
// equiv_load_mem64 (buffer_addr b h + scale8 i) h
//let same_domain_update64 b i v h =
// low_lemma_valid_mem64 b i h;
// Vale.Arch.MachineHeap.same_domain_update64 (buffer_addr b h + scale8 i) v (get_heap h)
open Vale.X64.BufferViewStore
let low_lemma_store_mem64_aux
(b:buffer64)
(heap:S.machine_heap)
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{buffer_readable h b /\ buffer_writeable b})
: Lemma
(requires IB.correct_down_p (_ih h) heap b)
(ensures (let heap' = S.update_heap64 (buffer_addr b h + scale8 i) v heap in
let h' = store_mem64 (buffer_addr b h + scale8 i) v h in
(_ih h').IB.hs == DV.upd_seq (_ih h).IB.hs (get_downview b.bsrc) (I.get_seq_heap heap' (_ih h).IB.addrs b))) =
let ptr = buffer_addr b h + scale8 i in
let heap' = S.update_heap64 ptr v heap in
let h' = store_mem64 ptr v h in
lemma_store_mem64 b i v h;
length_t_eq TUInt64 b;
bv_upd_update_heap64 b heap i v (_ih h);
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db Vale.Interop.Views.up_view64 in
assert (UV.upd (_ih h).IB.hs bv i (UInt64.uint_to_t v) == (_ih h').IB.hs)
val valid_state_store_mem64_aux: (i:nat) -> (v:nat64) -> (h:vale_heap) -> Lemma
(requires writeable_mem64 i h)
(ensures (
let heap = get_heap h in
let heap' = S.update_heap64 i v heap in
let h' = store_mem64 i v h in
heap' == I.down_mem (_ih h')
))
let valid_state_store_mem64_aux i v h =
let heap = get_heap h in
let heap' = S.update_heap64 i v heap in
let h1 = store_mem TUInt64 i v h in
store_buffer_aux_down64_mem i v h;
store_buffer_aux_down64_mem2 i v h;
let mem1 = heap' in
let mem2 = I.down_mem (_ih h1) in
let aux () : Lemma (forall j. mem1.[j] == mem2.[j]) =
Vale.Arch.MachineHeap.same_mem_get_heap_val64 i mem1 mem2;
Vale.Arch.MachineHeap.correct_update_get64 i v heap;
Vale.Arch.MachineHeap.frame_update_heap64 i v heap
in let aux2 () : Lemma (Set.equal (Map.domain mem1) (Map.domain mem2)) =
bytes_valid64 i h;
Vale.Arch.MachineHeap.same_domain_update64 i v heap
in aux(); aux2();
Map.lemma_equal_intro mem1 mem2
let low_lemma_load_mem64_full b i vfh t hid =
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
#push-options "--z3rlimit 20"
#restart-solver
let low_lemma_store_mem64 b i v h =
lemma_writeable_mem64 b i h;
lemma_store_mem64 b i v h;
valid_state_store_mem64_aux (buffer_addr b h + scale8 i) v h;
let heap = get_heap h in
let heap' = S.update_heap64 (buffer_addr b h + scale8 i) v heap in
low_lemma_store_mem64_aux b heap i v h;
Vale.Arch.MachineHeap.frame_update_heap64 (buffer_addr b h + scale8 i) v heap;
in_bounds64 h b i;
I.addrs_set_lemma_all ();
I.update_buffer_up_mem (_ih h) b heap heap'
#pop-options
#set-options "--z3rlimit 100"
#restart-solver
let lemma_is_full_update
(vfh:vale_full_heap) (h hk hk':vale_heap) (k:heaplet_id) (mh mh' mhk mhk':machine_heap) (mt mt':memtaint)
(t:base_typ) (b:buffer t) (ptr:int) (v_size:nat)
(index:nat) (v:base_typ_as_vale_type t) (tn:taint)
: Lemma
(requires
vfh.vf_layout.vl_inner.vl_heaplets_initialized /\
mem_inv vfh /\
buffer_readable hk b /\
buffer_writeable b /\
index < Seq.length (buffer_as_seq hk b) /\
mt == vfh.vf_layout.vl_taint /\
h == vfh.vf_heap /\
hk == Map16.sel vfh.vf_heaplets k /\
mh == h.mh /\
mhk == hk.mh /\
ptr == buffer_addr b hk + scale_by v_size index /\
mt' == S.update_n ptr v_size (heap_taint (coerce vfh)) tn /\
hk' == buffer_write b index v hk /\
valid_layout_buffer b vfh.vf_layout hk true /\
valid_taint_buf b hk mt tn /\
is_machine_heap_update mh mh' /\ upd_heap h mh' == buffer_write b index v h /\
is_machine_heap_update mhk mhk' /\ upd_heap hk mhk' == buffer_write b index v hk /\
(forall j.{:pattern mh.[j] \/ mh'.[j]} j < ptr \/ j >= ptr + v_size ==> mh.[j] == mh'.[j]) /\
(forall j.{:pattern mhk.[j] \/ mhk'.[j]} j < ptr \/ j >= ptr + v_size ==> mhk.[j] == mhk'.[j]) /\
0 <= scale_by v_size index /\ scale_by v_size index + v_size <= DV.length (get_downview b.bsrc) /\
(forall i.{:pattern mh'.[i] \/ mhk'.[i]} i >= ptr /\ i < ptr + v_size ==> mh'.[i] == mhk'.[i]) /\
True
)
(ensures is_full_update vfh hk' k mh' mt')
=
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
let vfh' = coerce (heap_upd (coerce vfh) mh' mt') in
let dom_upd = Set.intersect (vfh.vf_layout.vl_inner.vl_heaplet_sets k) (Map.domain mhk) in
let mhk'' = Map.concat mhk (Map.restrict dom_upd mh') in
assert (Map.equal mhk'' mhk');
let unchanged (j:heaplet_id) : Lemma
(requires j =!= k)
(ensures Map16.sel vfh'.vf_heaplets j == Map16.sel vfh.vf_heaplets j)
[SMTPat (Map16.sel vfh'.vf_heaplets j)]
=
assert (Map.equal (Map16.sel vfh'.vf_heaplets j).mh (Map16.sel vfh.vf_heaplets j).mh);
I.down_up_identity (Map16.sel vfh.vf_heaplets j).ih;
()
in
assert (Map16.equal vfh'.vf_heaplets (Map16.upd vfh.vf_heaplets k hk'));
assert (Map.equal mt' mt);
Vale.Interop.Heap_s.list_disjoint_or_eq_reveal ();
()
let low_lemma_store_mem64_full b i v vfh t hid =
let (h, mt, hk) = (vfh.vf_heap, vfh.vf_layout.vl_taint, Map16.get vfh.vf_heaplets hid) in
let ptr = buffer_addr b hk + scale8 i in
let mh' = S.update_heap64 ptr v (heap_get (coerce vfh)) in
let mt' = S.update_n ptr 8 (heap_taint (coerce vfh)) t in
let hk' = buffer_write b i v hk in
let mhk' = S.update_heap64 ptr v (get_heap hk) in
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
low_lemma_store_mem64 b i v h;
low_lemma_store_mem64 b i v (Map16.get vfh.vf_heaplets hid);
Vale.Arch.MachineHeap.frame_update_heap64 ptr v h.mh;
Vale.Arch.MachineHeap.frame_update_heap64 ptr v hk.mh;
in_bounds64 hk b i;
Vale.Arch.MachineHeap.same_mem_get_heap_val64 ptr mh' mhk';
lemma_is_full_update vfh h hk hk' hid h.mh mh' hk.mh mhk' mt mt' TUInt64 b ptr 8 i v t;
()
val low_lemma_valid_mem128 (b:buffer128) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b
)
(ensures
S.valid_addr128 (buffer_addr b h + scale16 i) (get_heap h)
) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Memory.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.BufferViewStore.fsti.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Memory_Sems.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.BufferViewStore",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_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
}
] | {
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | b: Vale.X64.Memory.buffer128 -> i: Prims.nat -> h: Vale.Arch.HeapImpl.vale_heap
-> FStar.Pervasives.Lemma
(requires
i < FStar.Seq.Base.length (Vale.X64.Memory.buffer_as_seq h b) /\
Vale.X64.Memory.buffer_readable h b)
(ensures
Vale.Arch.MachineHeap_s.valid_addr128 (Vale.X64.Memory.buffer_addr b h +
Vale.X64.Memory.scale16 i)
(Vale.X64.Memory_Sems.get_heap h)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.X64.Memory.buffer128",
"Prims.nat",
"Vale.Arch.HeapImpl.vale_heap",
"Vale.X64.Memory_Sems.bytes_valid128",
"Prims.op_Addition",
"Vale.X64.Memory.buffer_addr",
"Vale.X64.Memory.vuint128",
"Vale.X64.Memory.scale16",
"Prims.unit",
"Vale.X64.Memory.lemma_valid_mem128"
] | [] | true | false | true | false | false | let low_lemma_valid_mem128 b i h =
| lemma_valid_mem128 b i h;
bytes_valid128 (buffer_addr b h + scale16 i) h | false |
Vale.X64.Memory_Sems.fst | Vale.X64.Memory_Sems.same_mem_get_heap_val64 | val same_mem_get_heap_val64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale8 k in
forall (x:int).{:pattern (mem1.[x])} ptr <= x /\ x < ptr + 8 ==> mem1.[x] == mem2.[x])) | val same_mem_get_heap_val64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale8 k in
forall (x:int).{:pattern (mem1.[x])} ptr <= x /\ x < ptr + 8 ==> mem1.[x] == mem2.[x])) | let same_mem_get_heap_val64 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale8 k in
let addr = buffer_addr b h1 in
let aux (x:int{ptr <= x /\ x < ptr + 8}) : Lemma (mem1.[x] == mem2.[x]) =
let i = x - ptr in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices64 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8) (k * 8 + 8)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8) (k * 8 + 8)) in
assert (Seq.index s1 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i));
length_up64 b h1 k i;
assert (mem1.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i)));
assert (Seq.index s2 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i));
length_up64 b h2 k i;
assert (mem2.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i)))
in
Classical.forall_intro aux;
assert (forall i. addr + (scale8 k + i) == ptr + i) | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory_Sems.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 53,
"end_line": 265,
"start_col": 0,
"start_line": 245
} | module Vale.X64.Memory_Sems
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.Def.Words_s
module I = Vale.Interop
module S = Vale.X64.Machine_Semantics_s
module MB = LowStar.Monotonic.Buffer
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
friend Vale.X64.Memory
module IB = Vale.Interop.Base
let same_domain h m = Set.equal (IB.addrs_set (_ih h)) (Map.domain m)
let lemma_same_domains h m1 m2 = ()
let get_heap h = I.down_mem (_ih h)
let upd_heap h m = mi_heap_upd h m
//let lemma_upd_get_heap h = I.down_up_identity (_ih h)
let lemma_get_upd_heap h m = I.up_down_identity (_ih h) m
let lemma_heap_impl = ()
let lemma_heap_get_heap h = ()
let lemma_heap_taint h = ()
//let lemma_heap_upd_heap h mh mt = ()
[@"opaque_to_smt"]
let rec set_of_range (a:int) (n:nat) : Pure (Set.set int)
(requires True)
(ensures fun s -> (forall (i:int).{:pattern Set.mem i s} Set.mem i s <==> a <= i /\ i < a + n))
=
if n = 0 then Set.empty else Set.union (set_of_range a (n - 1)) (Set.singleton (a + n - 1))
let buffer_info_has_addr (bi:buffer_info) (a:int) =
let b = bi.bi_buffer in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
addr <= a /\ a < addr + len
let buffer_info_has_addr_opt (bi:option buffer_info) (a:int) =
match bi with
| None -> False
| Some bi -> buffer_info_has_addr bi a
#set-options "--z3rlimit 100"
let rec make_owns_rec (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
if n = 0 then ((fun _ -> None), (fun _ -> Set.empty)) else
let (m0, s0) = make_owns_rec h bs (n - 1) in
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let s i = if i = hi then Set.union (s0 i) s_b else s0 i in
let m a = if addr <= a && a < addr + len then Some (n - 1) else m0 a in
(m, s)
[@"opaque_to_smt"]
let make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
make_owns_rec h bs n
let rec lemma_make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n <= Seq.length bs /\
(forall (i:nat).{:pattern Seq.index bs i} i < Seq.length bs ==> buffer_readable h (Seq.index bs i).bi_buffer) /\
(forall (i1 i2:nat).{:pattern (Seq.index bs i1); (Seq.index bs i2)}
i1 < Seq.length bs /\ i2 < Seq.length bs ==> buffer_info_disjoint (Seq.index bs i1) (Seq.index bs i2))
)
(ensures (
let (m, s) = make_owns h bs n in
(forall (i:heaplet_id) (a:int).{:pattern Set.mem a (s i)}
(Set.mem a (s i) <==> Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (m a) == Some i) /\
(Set.mem a (s i) ==> buffer_info_has_addr_opt (Option.mapTot (fun n -> Seq.index bs n) (m a)) a) /\
(Set.mem a (s i) ==> Set.mem a (Map.domain h.mh))
) /\
(forall (k:nat) (a:int).{:pattern Set.mem a (s (Seq.index bs k).bi_heaplet)}
k < n /\ buffer_info_has_addr (Seq.index bs k) a ==> Set.mem a (s (Seq.index bs k).bi_heaplet))
))
=
reveal_opaque (`%make_owns) make_owns;
if n = 0 then () else
let _ = make_owns h bs (n - 1) in
let (m, s) = make_owns h bs n in
lemma_make_owns h bs (n - 1);
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let lem1 (a:int) : Lemma
(requires Set.mem a s_b)
(ensures Set.mem a (Map.domain h.mh))
[SMTPat (Set.mem a (Map.domain h.mh))]
=
I.addrs_set_mem h.ih b a
in
let lem2 (i:heaplet_id) (a:int) : Lemma
(requires i =!= hi /\ Set.mem a (Set.intersect s_b (s i)))
(ensures False)
[SMTPat (Set.mem a (s i))]
=
reveal_opaque (`%addr_map_pred) addr_map_pred
in
()
#push-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_loc_mutable_buffers_rec (l:list buffer_info) (s:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n + List.length l == Seq.length s /\
list_to_seq_post l s n
)
(ensures (
let modloc = loc_mutable_buffers l in
forall (i:nat).{:pattern Seq.index s i} n <= i /\ i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes modloc (loc_buffer bi.bi_buffer))
))
(decreases l)
=
match l with
| [] -> ()
| h::t -> lemma_loc_mutable_buffers_rec t s (n + 1)
#pop-options
let lemma_loc_mutable_buffers (l:list buffer_info) : Lemma
(ensures (
let s = list_to_seq l in
forall (i:nat).{:pattern Seq.index s i} i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes (loc_mutable_buffers l) (loc_buffer bi.bi_buffer))
))
=
lemma_list_to_seq l;
lemma_loc_mutable_buffers_rec l (list_to_seq l) 0
let create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let modloc = loc_mutable_buffers buffers in
let layout1 = h1.vf_layout in
let layin1 = layout1.vl_inner in
let (hmap, hsets) = make_owns h1.vf_heap bs (Seq.length bs) in
let hmap a = Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (hmap a) in
let l = {
vl_heaplets_initialized = true;
vl_heaplet_map = hmap;
vl_heaplet_sets = hsets;
vl_old_heap = h1.vf_heap;
vl_buffers = bs;
vl_mod_loc = modloc;
} in
let layout2 = {layout1 with vl_inner = l} in
let h2 = {
vf_layout = layout2;
vf_heap = h1.vf_heap;
vf_heaplets = h1.vf_heaplets;
} in
h2
let lemma_create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let h2 = create_heaplets buffers h1 in
assert (h2.vf_layout.vl_inner.vl_buffers == bs); // REVIEW: why is this necessary, even with extra ifuel?
lemma_make_owns h1.vf_heap bs (Seq.length bs);
lemma_loc_mutable_buffers buffers;
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
let destroy_heaplets h1 =
h1
let lemma_destroy_heaplets h1 =
()
val heap_shift (m1 m2:S.machine_heap) (base:int) (n:nat) : Lemma
(requires (forall i. 0 <= i /\ i < n ==> m1.[base + i] == m2.[base + i]))
(ensures (forall i. {:pattern (m1.[i])} base <= i /\ i < base + n ==> m1.[i] == m2.[i]))
#push-options "--smtencoding.l_arith_repr boxwrap"
let heap_shift m1 m2 base n =
assert (forall i. base <= i /\ i < base + n ==>
m1.[base + (i - base)] == m2.[base + (i - base)])
#pop-options
val same_mem_eq_slices64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 8 + 8 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8)))
let same_mem_eq_slices64 b i v k h1 h2 mem1 mem2 =
let t = TUInt64 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up64 (b:buffer64) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 8}) : Lemma
(scale8 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint64_view in
UV.length_eq vb
val same_mem_get_heap_val64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale8 k in
forall (x:int).{:pattern (mem1.[x])} ptr <= x /\ x < ptr + 8 ==> mem1.[x] == mem2.[x])) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Memory.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.BufferViewStore.fsti.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Memory_Sems.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_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
}
] | {
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
b: Vale.X64.Memory.buffer64{Vale.X64.Memory.buffer_writeable b} ->
i: Prims.nat{i < Vale.X64.Memory.buffer_length b} ->
v: Vale.Def.Words_s.nat64 ->
k: Prims.nat{k < Vale.X64.Memory.buffer_length b} ->
h1:
Vale.Arch.HeapImpl.vale_heap
{FStar.List.Tot.Base.memP b (Vale.Interop.Heap_s.ptrs_of_mem (Vale.Arch.HeapImpl._ih h1))} ->
h2: Vale.Arch.HeapImpl.vale_heap{h2 == Vale.X64.Memory.buffer_write b i v h1} ->
mem1:
Vale.Arch.MachineHeap_s.machine_heap
{Vale.Interop.Heap_s.correct_down_p (Vale.Arch.HeapImpl._ih h1) mem1 b} ->
mem2:
Vale.Arch.MachineHeap_s.machine_heap
{Vale.Interop.Heap_s.correct_down_p (Vale.Arch.HeapImpl._ih h2) mem2 b}
-> FStar.Pervasives.Lemma
(requires
FStar.Seq.Base.index (Vale.X64.Memory.buffer_as_seq h1 b) k ==
FStar.Seq.Base.index (Vale.X64.Memory.buffer_as_seq h2 b) k)
(ensures
(let ptr = Vale.X64.Memory.buffer_addr b h1 + Vale.X64.Memory.scale8 k in
forall (x: Prims.int). {:pattern mem1.[ x ]}
ptr <= x /\ x < ptr + 8 ==> mem1.[ x ] == mem2.[ x ])) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.X64.Memory.buffer64",
"Vale.X64.Memory.buffer_writeable",
"Vale.X64.Memory.vuint64",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Vale.X64.Memory.buffer_length",
"Vale.Def.Words_s.nat64",
"Vale.Arch.HeapImpl.vale_heap",
"FStar.List.Tot.Base.memP",
"Vale.Interop.Types.b8",
"Vale.Interop.Heap_s.ptrs_of_mem",
"Vale.Arch.HeapImpl._ih",
"Prims.eq2",
"Vale.X64.Memory.buffer_write",
"Vale.Arch.MachineHeap_s.machine_heap",
"Vale.Interop.Heap_s.correct_down_p",
"Prims._assert",
"Prims.l_Forall",
"Prims.int",
"Prims.op_Addition",
"Vale.X64.Memory.scale8",
"Prims.unit",
"FStar.Classical.forall_intro",
"Prims.l_and",
"Prims.op_LessThanOrEqual",
"Vale.Def.Types_s.nat8",
"Vale.X64.Memory.op_String_Access",
"Prims.l_True",
"Prims.squash",
"Vale.Def.Words_s.nat8",
"FStar.Map.sel",
"Prims.Nil",
"FStar.Pervasives.pattern",
"Prims.l_or",
"FStar.UInt.size",
"FStar.UInt8.n",
"Prims.op_GreaterThanOrEqual",
"Vale.Def.Words_s.pow2_8",
"FStar.UInt8.v",
"FStar.Seq.Base.index",
"FStar.UInt8.t",
"LowStar.BufferView.Down.as_seq",
"Vale.Interop.Heap_s.hs_of_mem",
"FStar.Mul.op_Star",
"Vale.X64.Memory_Sems.length_up64",
"FStar.Seq.Base.seq",
"FStar.Seq.Base.slice",
"Vale.X64.Memory_Sems.same_mem_eq_slices64",
"LowStar.BufferView.Up.as_seq_sel",
"FStar.UInt64.t",
"LowStar.BufferView.Up.buffer",
"LowStar.BufferView.Up.mk_buffer",
"Vale.X64.Memory.uint64_view",
"LowStar.BufferView.Down.buffer",
"Vale.Interop.Types.get_downview",
"Vale.Interop.Types.__proj__Buffer__item__src",
"Vale.Interop.Types.b8_preorder",
"Vale.Interop.Types.__proj__Buffer__item__writeable",
"Vale.Interop.Types.base_typ_as_type",
"Vale.Interop.Types.__proj__Buffer__item__bsrc",
"Prims.op_Subtraction",
"Vale.X64.Memory.buffer_addr"
] | [] | false | false | true | false | false | let same_mem_get_heap_val64 b j v k h1 h2 mem1 mem2 =
| let ptr = buffer_addr b h1 + scale8 k in
let addr = buffer_addr b h1 in
let aux (x: int{ptr <= x /\ x < ptr + 8}) : Lemma (mem1.[ x ] == mem2.[ x ]) =
let i = x - ptr in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices64 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8) (k * 8 + 8)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8) (k * 8 + 8)) in
assert (Seq.index s1 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i));
length_up64 b h1 k i;
assert (mem1.[ addr + (scale8 k + i) ] ==
UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i)));
assert (Seq.index s2 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i));
length_up64 b h2 k i;
assert (mem2.[ addr + (scale8 k + i) ] ==
UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i)))
in
Classical.forall_intro aux;
assert (forall i. addr + (scale8 k + i) == ptr + i) | false |
PulseCore.MonotonicStateMonad.fst | PulseCore.MonotonicStateMonad.get | val get (#s:Type u#s) (#rel:preorder s) (_:unit)
: mst rel s (fun _ -> True) (fun s0 x s1 -> s0 == s1 /\ x == s0) | val get (#s:Type u#s) (#rel:preorder s) (_:unit)
: mst rel s (fun _ -> True) (fun s0 x s1 -> s0 == s1 /\ x == s0) | let get _
= fun s -> s, s | {
"file_name": "lib/pulse_core/PulseCore.MonotonicStateMonad.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 15,
"end_line": 48,
"start_col": 0,
"start_line": 47
} | module PulseCore.MonotonicStateMonad
open FStar.Preorder
module M = FStar.MSTTotal
let mst (#s:Type u#s)
(rel:FStar.Preorder.preorder s)
(a:Type u#a)
(pre:s -> prop)
(post:s -> a -> s -> prop)
= s0:s { pre s0 }
-> Tot (
res:(a & s) {
post s0 res._1 res._2 /\
rel s0 res._2
}
)
assume (* to interoperate with a definition of a similar module in FStar.MSTTotal *)
val reify_ (#s:Type u#2) (#rel:FStar.Preorder.preorder s)
(#a:Type u#a) (#pre:s -> prop) (#post:s -> a -> s -> prop)
($f:unit -> M.MSTATETOT a s rel pre post)
: M.repr a s rel pre post
let of_msttotal (#s:Type u#2) (rel:FStar.Preorder.preorder s)
(a:Type u#a) (pre:s -> prop) (post:s -> a -> s -> prop)
(f:unit -> M.MSTATETOT a s rel pre post)
: mst rel a pre post
= let f = reify_ f in
fun s -> f s
let to_msttotal (#s:Type u#2) (rel:FStar.Preorder.preorder s)
(a:Type u#a) (pre:s -> prop) (post:s -> a -> s -> prop)
(f:mst rel a pre post)
: M.MSTATETOT a s rel pre post
= M.MSTATETOT?.reflect (fun s -> f s)
let return x
= fun s0 -> x, s0
let bind f g
= fun s0 ->
let x, s1 = f s0 in
g x s1
let weaken f
= fun s -> f s | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.MSTTotal.fst.checked"
],
"interface_file": true,
"source_file": "PulseCore.MonotonicStateMonad.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.MSTTotal",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.MSTTotal",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "PulseCore",
"short_module": null
},
{
"abbrev": false,
"full_module": "PulseCore",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit
-> PulseCore.MonotonicStateMonad.mst rel
s
(fun _ -> Prims.l_True)
(fun s0 x s1 -> s0 == s1 /\ x == s0) | Prims.Tot | [
"total"
] | [] | [
"FStar.Preorder.preorder",
"Prims.unit",
"Prims.l_True",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Pervasives.Native.tuple2",
"Prims.l_and",
"Prims.eq2",
"Prims.prop",
"FStar.Pervasives.Native.__proj__Mktuple2__item___1",
"FStar.Pervasives.Native.__proj__Mktuple2__item___2"
] | [] | false | false | false | false | false | let get _ =
| fun s -> s, s | false |
PulseCore.MonotonicStateMonad.fst | PulseCore.MonotonicStateMonad.bind | val bind
(#s:Type u#s)
(#a:Type u#a)
(#b:Type u#b)
(#rel:preorder s)
(#req_f:req_t s)
(#ens_f:ens_t s a)
(#req_g:a -> req_t s)
(#ens_g:a -> ens_t s b)
(f:mst rel a req_f ens_f)
(g:(x:a -> mst rel b (req_g x) (ens_g x)))
: mst rel b
(fun s0 -> req_f s0 /\ (forall x s1. ens_f s0 x s1 ==> (req_g x) s1))
(fun s0 r s2 -> req_f s0 /\ (exists x s1. ens_f s0 x s1 /\ (req_g x) s1 /\ (ens_g x) s1 r s2)) | val bind
(#s:Type u#s)
(#a:Type u#a)
(#b:Type u#b)
(#rel:preorder s)
(#req_f:req_t s)
(#ens_f:ens_t s a)
(#req_g:a -> req_t s)
(#ens_g:a -> ens_t s b)
(f:mst rel a req_f ens_f)
(g:(x:a -> mst rel b (req_g x) (ens_g x)))
: mst rel b
(fun s0 -> req_f s0 /\ (forall x s1. ens_f s0 x s1 ==> (req_g x) s1))
(fun s0 r s2 -> req_f s0 /\ (exists x s1. ens_f s0 x s1 /\ (req_g x) s1 /\ (ens_g x) s1 r s2)) | let bind f g
= fun s0 ->
let x, s1 = f s0 in
g x s1 | {
"file_name": "lib/pulse_core/PulseCore.MonotonicStateMonad.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 10,
"end_line": 42,
"start_col": 0,
"start_line": 39
} | module PulseCore.MonotonicStateMonad
open FStar.Preorder
module M = FStar.MSTTotal
let mst (#s:Type u#s)
(rel:FStar.Preorder.preorder s)
(a:Type u#a)
(pre:s -> prop)
(post:s -> a -> s -> prop)
= s0:s { pre s0 }
-> Tot (
res:(a & s) {
post s0 res._1 res._2 /\
rel s0 res._2
}
)
assume (* to interoperate with a definition of a similar module in FStar.MSTTotal *)
val reify_ (#s:Type u#2) (#rel:FStar.Preorder.preorder s)
(#a:Type u#a) (#pre:s -> prop) (#post:s -> a -> s -> prop)
($f:unit -> M.MSTATETOT a s rel pre post)
: M.repr a s rel pre post
let of_msttotal (#s:Type u#2) (rel:FStar.Preorder.preorder s)
(a:Type u#a) (pre:s -> prop) (post:s -> a -> s -> prop)
(f:unit -> M.MSTATETOT a s rel pre post)
: mst rel a pre post
= let f = reify_ f in
fun s -> f s
let to_msttotal (#s:Type u#2) (rel:FStar.Preorder.preorder s)
(a:Type u#a) (pre:s -> prop) (post:s -> a -> s -> prop)
(f:mst rel a pre post)
: M.MSTATETOT a s rel pre post
= M.MSTATETOT?.reflect (fun s -> f s)
let return x
= fun s0 -> x, s0 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.MSTTotal.fst.checked"
],
"interface_file": true,
"source_file": "PulseCore.MonotonicStateMonad.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.MSTTotal",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.MSTTotal",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "PulseCore",
"short_module": null
},
{
"abbrev": false,
"full_module": "PulseCore",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
f: PulseCore.MonotonicStateMonad.mst rel a req_f ens_f ->
g: (x: a -> PulseCore.MonotonicStateMonad.mst rel b (req_g x) (ens_g x))
-> PulseCore.MonotonicStateMonad.mst rel
b
(fun s0 -> req_f s0 /\ (forall (x: a) (s1: s). ens_f s0 x s1 ==> req_g x s1))
(fun s0 r s2 ->
req_f s0 /\ (exists (x: a) (s1: s). ens_f s0 x s1 /\ req_g x s1 /\ ens_g x s1 r s2)) | Prims.Tot | [
"total"
] | [] | [
"FStar.Preorder.preorder",
"PulseCore.MonotonicStateMonad.req_t",
"PulseCore.MonotonicStateMonad.ens_t",
"PulseCore.MonotonicStateMonad.mst",
"Prims.l_and",
"Prims.l_Forall",
"Prims.l_imp",
"FStar.Pervasives.Native.tuple2",
"Prims.l_Exists",
"FStar.Pervasives.Native.__proj__Mktuple2__item___1",
"FStar.Pervasives.Native.__proj__Mktuple2__item___2",
"Prims.prop"
] | [] | false | false | false | false | false | let bind f g =
| fun s0 ->
let x, s1 = f s0 in
g x s1 | false |
PulseCore.MonotonicStateMonad.fst | PulseCore.MonotonicStateMonad.weaken | val weaken
(#s:Type u#s)
(#rel:preorder s)
(#a:Type u#a)
(#req_f:req_t s)
(#ens_f:ens_t s a)
(#req_g:req_t s)
(#ens_g:ens_t s a)
(f:mst rel a req_f ens_f)
: Pure (mst rel a req_g ens_g)
(requires
(forall s. req_g s ==> req_f s) /\
(forall s0 x s1. (req_g s0 /\ ens_f s0 x s1) ==> ens_g s0 x s1))
(ensures fun _ -> True) | val weaken
(#s:Type u#s)
(#rel:preorder s)
(#a:Type u#a)
(#req_f:req_t s)
(#ens_f:ens_t s a)
(#req_g:req_t s)
(#ens_g:ens_t s a)
(f:mst rel a req_f ens_f)
: Pure (mst rel a req_g ens_g)
(requires
(forall s. req_g s ==> req_f s) /\
(forall s0 x s1. (req_g s0 /\ ens_f s0 x s1) ==> ens_g s0 x s1))
(ensures fun _ -> True) | let weaken f
= fun s -> f s | {
"file_name": "lib/pulse_core/PulseCore.MonotonicStateMonad.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 14,
"end_line": 45,
"start_col": 0,
"start_line": 44
} | module PulseCore.MonotonicStateMonad
open FStar.Preorder
module M = FStar.MSTTotal
let mst (#s:Type u#s)
(rel:FStar.Preorder.preorder s)
(a:Type u#a)
(pre:s -> prop)
(post:s -> a -> s -> prop)
= s0:s { pre s0 }
-> Tot (
res:(a & s) {
post s0 res._1 res._2 /\
rel s0 res._2
}
)
assume (* to interoperate with a definition of a similar module in FStar.MSTTotal *)
val reify_ (#s:Type u#2) (#rel:FStar.Preorder.preorder s)
(#a:Type u#a) (#pre:s -> prop) (#post:s -> a -> s -> prop)
($f:unit -> M.MSTATETOT a s rel pre post)
: M.repr a s rel pre post
let of_msttotal (#s:Type u#2) (rel:FStar.Preorder.preorder s)
(a:Type u#a) (pre:s -> prop) (post:s -> a -> s -> prop)
(f:unit -> M.MSTATETOT a s rel pre post)
: mst rel a pre post
= let f = reify_ f in
fun s -> f s
let to_msttotal (#s:Type u#2) (rel:FStar.Preorder.preorder s)
(a:Type u#a) (pre:s -> prop) (post:s -> a -> s -> prop)
(f:mst rel a pre post)
: M.MSTATETOT a s rel pre post
= M.MSTATETOT?.reflect (fun s -> f s)
let return x
= fun s0 -> x, s0
let bind f g
= fun s0 ->
let x, s1 = f s0 in
g x s1 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.MSTTotal.fst.checked"
],
"interface_file": true,
"source_file": "PulseCore.MonotonicStateMonad.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.MSTTotal",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.MSTTotal",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "PulseCore",
"short_module": null
},
{
"abbrev": false,
"full_module": "PulseCore",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | f: PulseCore.MonotonicStateMonad.mst rel a req_f ens_f
-> Prims.Pure (PulseCore.MonotonicStateMonad.mst rel a req_g ens_g) | Prims.Pure | [] | [] | [
"FStar.Preorder.preorder",
"PulseCore.MonotonicStateMonad.req_t",
"PulseCore.MonotonicStateMonad.ens_t",
"PulseCore.MonotonicStateMonad.mst",
"FStar.Pervasives.Native.tuple2",
"Prims.l_and",
"FStar.Pervasives.Native.__proj__Mktuple2__item___1",
"FStar.Pervasives.Native.__proj__Mktuple2__item___2"
] | [] | false | false | false | false | false | let weaken f =
| fun s -> f s | false |
Vale.X64.Memory_Sems.fst | Vale.X64.Memory_Sems.equiv_load_mem64 | val equiv_load_mem64 (ptr:int) (m:vale_heap) : Lemma
(requires valid_mem64 ptr m)
(ensures load_mem64 ptr m == S.get_heap_val64 ptr (get_heap m)) | val equiv_load_mem64 (ptr:int) (m:vale_heap) : Lemma
(requires valid_mem64 ptr m)
(ensures load_mem64 ptr m == S.get_heap_val64 ptr (get_heap m)) | let equiv_load_mem64 ptr h =
let t = TUInt64 in
let b = get_addr_ptr t ptr h in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
let addr = buffer_addr b h in
let contents = DV.as_seq (_ih h).IB.hs (get_downview b.bsrc) in
let heap = get_heap h in
index64_get_heap_val64 h b heap i;
lemma_load_mem64 b i h | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory_Sems.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 24,
"end_line": 571,
"start_col": 0,
"start_line": 563
} | module Vale.X64.Memory_Sems
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.Def.Words_s
module I = Vale.Interop
module S = Vale.X64.Machine_Semantics_s
module MB = LowStar.Monotonic.Buffer
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
friend Vale.X64.Memory
module IB = Vale.Interop.Base
let same_domain h m = Set.equal (IB.addrs_set (_ih h)) (Map.domain m)
let lemma_same_domains h m1 m2 = ()
let get_heap h = I.down_mem (_ih h)
let upd_heap h m = mi_heap_upd h m
//let lemma_upd_get_heap h = I.down_up_identity (_ih h)
let lemma_get_upd_heap h m = I.up_down_identity (_ih h) m
let lemma_heap_impl = ()
let lemma_heap_get_heap h = ()
let lemma_heap_taint h = ()
//let lemma_heap_upd_heap h mh mt = ()
[@"opaque_to_smt"]
let rec set_of_range (a:int) (n:nat) : Pure (Set.set int)
(requires True)
(ensures fun s -> (forall (i:int).{:pattern Set.mem i s} Set.mem i s <==> a <= i /\ i < a + n))
=
if n = 0 then Set.empty else Set.union (set_of_range a (n - 1)) (Set.singleton (a + n - 1))
let buffer_info_has_addr (bi:buffer_info) (a:int) =
let b = bi.bi_buffer in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
addr <= a /\ a < addr + len
let buffer_info_has_addr_opt (bi:option buffer_info) (a:int) =
match bi with
| None -> False
| Some bi -> buffer_info_has_addr bi a
#set-options "--z3rlimit 100"
let rec make_owns_rec (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
if n = 0 then ((fun _ -> None), (fun _ -> Set.empty)) else
let (m0, s0) = make_owns_rec h bs (n - 1) in
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let s i = if i = hi then Set.union (s0 i) s_b else s0 i in
let m a = if addr <= a && a < addr + len then Some (n - 1) else m0 a in
(m, s)
[@"opaque_to_smt"]
let make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
make_owns_rec h bs n
let rec lemma_make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n <= Seq.length bs /\
(forall (i:nat).{:pattern Seq.index bs i} i < Seq.length bs ==> buffer_readable h (Seq.index bs i).bi_buffer) /\
(forall (i1 i2:nat).{:pattern (Seq.index bs i1); (Seq.index bs i2)}
i1 < Seq.length bs /\ i2 < Seq.length bs ==> buffer_info_disjoint (Seq.index bs i1) (Seq.index bs i2))
)
(ensures (
let (m, s) = make_owns h bs n in
(forall (i:heaplet_id) (a:int).{:pattern Set.mem a (s i)}
(Set.mem a (s i) <==> Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (m a) == Some i) /\
(Set.mem a (s i) ==> buffer_info_has_addr_opt (Option.mapTot (fun n -> Seq.index bs n) (m a)) a) /\
(Set.mem a (s i) ==> Set.mem a (Map.domain h.mh))
) /\
(forall (k:nat) (a:int).{:pattern Set.mem a (s (Seq.index bs k).bi_heaplet)}
k < n /\ buffer_info_has_addr (Seq.index bs k) a ==> Set.mem a (s (Seq.index bs k).bi_heaplet))
))
=
reveal_opaque (`%make_owns) make_owns;
if n = 0 then () else
let _ = make_owns h bs (n - 1) in
let (m, s) = make_owns h bs n in
lemma_make_owns h bs (n - 1);
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let lem1 (a:int) : Lemma
(requires Set.mem a s_b)
(ensures Set.mem a (Map.domain h.mh))
[SMTPat (Set.mem a (Map.domain h.mh))]
=
I.addrs_set_mem h.ih b a
in
let lem2 (i:heaplet_id) (a:int) : Lemma
(requires i =!= hi /\ Set.mem a (Set.intersect s_b (s i)))
(ensures False)
[SMTPat (Set.mem a (s i))]
=
reveal_opaque (`%addr_map_pred) addr_map_pred
in
()
#push-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_loc_mutable_buffers_rec (l:list buffer_info) (s:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n + List.length l == Seq.length s /\
list_to_seq_post l s n
)
(ensures (
let modloc = loc_mutable_buffers l in
forall (i:nat).{:pattern Seq.index s i} n <= i /\ i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes modloc (loc_buffer bi.bi_buffer))
))
(decreases l)
=
match l with
| [] -> ()
| h::t -> lemma_loc_mutable_buffers_rec t s (n + 1)
#pop-options
let lemma_loc_mutable_buffers (l:list buffer_info) : Lemma
(ensures (
let s = list_to_seq l in
forall (i:nat).{:pattern Seq.index s i} i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes (loc_mutable_buffers l) (loc_buffer bi.bi_buffer))
))
=
lemma_list_to_seq l;
lemma_loc_mutable_buffers_rec l (list_to_seq l) 0
let create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let modloc = loc_mutable_buffers buffers in
let layout1 = h1.vf_layout in
let layin1 = layout1.vl_inner in
let (hmap, hsets) = make_owns h1.vf_heap bs (Seq.length bs) in
let hmap a = Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (hmap a) in
let l = {
vl_heaplets_initialized = true;
vl_heaplet_map = hmap;
vl_heaplet_sets = hsets;
vl_old_heap = h1.vf_heap;
vl_buffers = bs;
vl_mod_loc = modloc;
} in
let layout2 = {layout1 with vl_inner = l} in
let h2 = {
vf_layout = layout2;
vf_heap = h1.vf_heap;
vf_heaplets = h1.vf_heaplets;
} in
h2
let lemma_create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let h2 = create_heaplets buffers h1 in
assert (h2.vf_layout.vl_inner.vl_buffers == bs); // REVIEW: why is this necessary, even with extra ifuel?
lemma_make_owns h1.vf_heap bs (Seq.length bs);
lemma_loc_mutable_buffers buffers;
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
let destroy_heaplets h1 =
h1
let lemma_destroy_heaplets h1 =
()
val heap_shift (m1 m2:S.machine_heap) (base:int) (n:nat) : Lemma
(requires (forall i. 0 <= i /\ i < n ==> m1.[base + i] == m2.[base + i]))
(ensures (forall i. {:pattern (m1.[i])} base <= i /\ i < base + n ==> m1.[i] == m2.[i]))
#push-options "--smtencoding.l_arith_repr boxwrap"
let heap_shift m1 m2 base n =
assert (forall i. base <= i /\ i < base + n ==>
m1.[base + (i - base)] == m2.[base + (i - base)])
#pop-options
val same_mem_eq_slices64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 8 + 8 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8)))
let same_mem_eq_slices64 b i v k h1 h2 mem1 mem2 =
let t = TUInt64 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up64 (b:buffer64) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 8}) : Lemma
(scale8 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint64_view in
UV.length_eq vb
val same_mem_get_heap_val64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale8 k in
forall (x:int).{:pattern (mem1.[x])} ptr <= x /\ x < ptr + 8 ==> mem1.[x] == mem2.[x]))
let same_mem_get_heap_val64 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale8 k in
let addr = buffer_addr b h1 in
let aux (x:int{ptr <= x /\ x < ptr + 8}) : Lemma (mem1.[x] == mem2.[x]) =
let i = x - ptr in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices64 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8) (k * 8 + 8)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8) (k * 8 + 8)) in
assert (Seq.index s1 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i));
length_up64 b h1 k i;
assert (mem1.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i)));
assert (Seq.index s2 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i));
length_up64 b h2 k i;
assert (mem2.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i)))
in
Classical.forall_intro aux;
assert (forall i. addr + (scale8 k + i) == ptr + i)
let rec written_buffer_down64_aux1
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(k:nat) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j.{:pattern (mem1.[j]) \/ (mem2.[j])}
base <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem1.[j])}
j >= base /\ j < base + scale8 i ==>
mem1.[j] == mem2.[j]))
(decreases %[i-k]) =
if k >= i then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux1 b i v h base (k+1) h1 mem1 mem2
end
let rec written_buffer_down64_aux2
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(n:nat{n == buffer_length b})
(k:nat{k > i}) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
base + scale8 (i+1) <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
j >= base + scale8 (i+1) /\ j < base + scale8 n ==>
mem1.[j] == mem2.[j]))
(decreases %[n-k]) =
if k >= n then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux2 b i v h base n (k+1) h1 mem1 mem2
end
let written_buffer_down64 (b:buffer64{buffer_writeable b}) (i:nat{i < buffer_length b}) (v:nat64) (h:vale_heap)
: Lemma
(requires List.memP b (IB.ptrs_of_mem (_ih h)))
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
(base <= j /\ j < base + scale8 i) \/
(base + scale8 (i+1) <= j /\ j < base + scale8 n) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
written_buffer_down64_aux1 b i v h base 0 h1 mem1 mem2;
written_buffer_down64_aux2 b i v h base n (i+1) h1 mem1 mem2
let unwritten_buffer_down (t:base_typ) (b:buffer t{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:base_typ_as_vale_type t)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall (a:b8{List.memP a (IB.ptrs_of_mem (_ih h)) /\ a =!= b}) j. {:pattern mem1.[j]; List.memP a (IB.ptrs_of_mem (_ih h)) \/ mem2.[j]; List.memP a (IB.ptrs_of_mem (_ih h))}
let base = (IB.addrs_of_mem (_ih h)) a in
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==> mem1.[j] == mem2.[j]))
= let aux (a:b8{a =!= b /\ List.memP a (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let base = (IB.addrs_of_mem (_ih h)) a in
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall j.
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==>
mem1.[j] == mem2.[j]))
= let db = get_downview a.bsrc in
if DV.length db = 0 then ()
else
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = (IB.addrs_of_mem (_ih h)) a in
let s0 = DV.as_seq (IB.hs_of_mem (_ih h)) db in
let s1 = DV.as_seq (IB.hs_of_mem (_ih h1)) db in
opaque_assert (`%IB.list_disjoint_or_eq) IB.list_disjoint_or_eq IB.list_disjoint_or_eq_def (MB.disjoint a.bsrc b.bsrc);
lemma_dv_equal (IB.down_view a.src) a.bsrc (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1));
assert (Seq.equal s0 s1);
assert (forall (j:int).{:pattern (mem1.[j])}
base <= j /\ j < base + Seq.length s0 ==> v_to_typ TUInt8 (Seq.index s0 (j - base)) == mem1.[j]);
heap_shift mem1 mem2 base (DV.length db)
in
Classical.forall_intro aux
let store_buffer_down64_mem
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
forall (j:int). {:pattern mem1.[j] \/ mem2.[j]}
j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
let aux (j:int)
: Lemma
(j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j])
=
I.addrs_set_lemma_all ();
if j >= base && j < base + DV.length (get_downview b.bsrc) then begin
written_buffer_down64 b i v h;
length_t_eq (TUInt64) b
end
else if not (I.valid_addr (_ih h) j)
then I.same_unspecified_down (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1)) (IB.ptrs_of_mem (_ih h))
else unwritten_buffer_down TUInt64 b i v h
in
Classical.forall_intro aux
let store_buffer_aux_down64_mem (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
forall j. {:pattern mem1.[j] \/ mem2.[j]}
j < ptr \/ j >= ptr + 8 ==>
mem1.[j] == mem2.[j]))
= let t = TUInt64 in
let h1 = store_mem t ptr v h in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
store_buffer_write t ptr v h;
assert (buffer_addr b h + scale8 i == ptr);
assert (buffer_addr b h + scale8 (i+1) == ptr + 8);
store_buffer_down64_mem b i v h
let store_buffer_aux_down64_mem2 (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
S.get_heap_val64 ptr mem2 == v))
= let t = TUInt64 in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
let h1 = store_mem t ptr v h in
let mem2 = I.down_mem (_ih h1) in
store_buffer_write t ptr v h;
assert (Seq.index (buffer_as_seq h1 b) i == v);
index64_get_heap_val64 h1 b mem2 i
let in_bounds64 (h:vale_heap) (b:buffer64) (i:nat{i < buffer_length b})
: Lemma (scale8 i + 8 <= DV.length (get_downview b.bsrc))
=
length_t_eq TUInt64 b
let bytes_valid64 ptr h =
reveal_opaque (`%S.valid_addr64) S.valid_addr64;
let t = TUInt64 in
let b = get_addr_ptr t ptr h in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
in_bounds64 h b i;
I.addrs_set_mem (_ih h) b ptr;
I.addrs_set_mem (_ih h) b (ptr+1);
I.addrs_set_mem (_ih h) b (ptr+2);
I.addrs_set_mem (_ih h) b (ptr+3);
I.addrs_set_mem (_ih h) b (ptr+4);
I.addrs_set_mem (_ih h) b (ptr+5);
I.addrs_set_mem (_ih h) b (ptr+6);
I.addrs_set_mem (_ih h) b (ptr+7)
val same_mem_get_heap_val128 (b:buffer128)
(i:nat{i < buffer_length b})
(v:quad32)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1)) /\ buffer_writeable b})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale16 k in
forall i.{:pattern mem1.[i]} i >= ptr /\ i < ptr+16 ==> mem1.[i] == mem2.[i]))
val same_mem_eq_slices128 (b:buffer128)
(i:nat{i < buffer_length b})
(v:quad32)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1)) /\ buffer_writeable b})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 16 + 16 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 16) (k * 16 + 16) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 16) (k * 16 + 16)))
let same_mem_eq_slices128 b i v k h1 h2 mem1 mem2 =
let t = TUInt128 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up128 (b:buffer128) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 16}) : Lemma
(scale16 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint128_view in
UV.length_eq vb
let same_mem_get_heap_val128 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale16 k in
let addr = buffer_addr b h1 in
let aux (i:nat{ptr <= i /\ i < ptr+16}) : Lemma (mem1.[i] == mem2.[i]) =
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint128_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices128 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16) (k * 16 + 16)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16) (k * 16 + 16)) in
assert (Seq.index s1 (i - ptr) == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16 + (i-ptr)));
length_up128 b h1 k (i-ptr);
assert (mem1.[i] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16 + (i-ptr))));
assert (Seq.index s2 (i-ptr) == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16 + (i-ptr)));
length_up128 b h2 k (i-ptr);
assert (mem2.[addr+(scale16 k + (i-ptr))] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16 + (i-ptr))));
assert (forall i. addr + (scale16 k + (i-ptr)) == i)
in
Classical.forall_intro aux
let in_bounds128 (h:vale_heap) (b:buffer128) (i:nat{i < buffer_length b}) : Lemma
(scale16 i + 16 <= DV.length (get_downview b.bsrc))
=
length_t_eq TUInt128 b
#push-options "--z3rlimit 20"
#restart-solver
let bytes_valid128 ptr h =
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
IB.list_disjoint_or_eq_reveal ();
let t = TUInt128 in
let b = get_addr_ptr t ptr h in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
in_bounds128 h b i;
I.addrs_set_mem (_ih h) b ptr;
I.addrs_set_mem (_ih h) b (ptr+1);
I.addrs_set_mem (_ih h) b (ptr+2);
I.addrs_set_mem (_ih h) b (ptr+3);
I.addrs_set_mem (_ih h) b (ptr+4);
I.addrs_set_mem (_ih h) b (ptr+5);
I.addrs_set_mem (_ih h) b (ptr+6);
I.addrs_set_mem (_ih h) b (ptr+7);
I.addrs_set_mem (_ih h) b (ptr+8);
I.addrs_set_mem (_ih h) b (ptr+9);
I.addrs_set_mem (_ih h) b (ptr+10);
I.addrs_set_mem (_ih h) b (ptr+11);
I.addrs_set_mem (_ih h) b (ptr+12);
I.addrs_set_mem (_ih h) b (ptr+13);
I.addrs_set_mem (_ih h) b (ptr+14);
I.addrs_set_mem (_ih h) b (ptr+15)
#pop-options | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Memory.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.BufferViewStore.fsti.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Memory_Sems.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_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
}
] | {
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | ptr: Prims.int -> m: Vale.Arch.HeapImpl.vale_heap
-> FStar.Pervasives.Lemma (requires Vale.X64.Memory.valid_mem64 ptr m)
(ensures
Vale.X64.Memory.load_mem64 ptr m ==
Vale.Arch.MachineHeap_s.get_heap_val64 ptr (Vale.X64.Memory_Sems.get_heap m)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.int",
"Vale.Arch.HeapImpl.vale_heap",
"Vale.X64.Memory.lemma_load_mem64",
"Prims.unit",
"Vale.X64.Memory.index64_get_heap_val64",
"Vale.Arch.MachineHeap_s.machine_heap",
"Vale.X64.Memory_Sems.same_domain",
"Vale.X64.Memory_Sems.get_heap",
"FStar.Seq.Properties.lseq",
"FStar.UInt8.t",
"LowStar.BufferView.Down.length",
"Vale.Interop.Types.get_downview",
"Vale.Interop.Types.__proj__Buffer__item__src",
"Vale.Interop.Types.b8_preorder",
"Vale.Interop.Types.__proj__Buffer__item__writeable",
"Vale.Interop.Types.base_typ_as_type",
"Vale.Interop.Types.__proj__Buffer__item__bsrc",
"LowStar.BufferView.Down.as_seq",
"Vale.Interop.Heap_s.__proj__InteropHeap__item__hs",
"Vale.Arch.HeapImpl._ih",
"Vale.X64.Memory.buffer_addr",
"Prims.nat",
"Vale.X64.Memory.get_addr_in_ptr",
"Vale.X64.Memory.buffer_length",
"Vale.Arch.HeapImpl.buffer",
"Vale.X64.Memory.get_addr_ptr",
"Vale.Arch.HeapTypes_s.base_typ",
"Vale.Arch.HeapTypes_s.TUInt64"
] | [] | true | false | true | false | false | let equiv_load_mem64 ptr h =
| let t = TUInt64 in
let b = get_addr_ptr t ptr h in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
let addr = buffer_addr b h in
let contents = DV.as_seq (_ih h).IB.hs (get_downview b.bsrc) in
let heap = get_heap h in
index64_get_heap_val64 h b heap i;
lemma_load_mem64 b i h | false |
Vale.X64.Memory_Sems.fst | Vale.X64.Memory_Sems.unwritten_buffer_down | val unwritten_buffer_down
(t: base_typ)
(b: buffer t {buffer_writeable b})
(i: nat{i < buffer_length b})
(v: base_typ_as_vale_type t)
(h: vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures
(let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall (a: b8{List.memP a (IB.ptrs_of_mem (_ih h)) /\ a =!= b}) j.
{:pattern
mem1.[ j ]; List.memP a (IB.ptrs_of_mem (_ih h))\/mem2.[ j ];
List.memP a (IB.ptrs_of_mem (_ih h))}
let base = (IB.addrs_of_mem (_ih h)) a in
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==> mem1.[ j ] == mem2.[ j ])) | val unwritten_buffer_down
(t: base_typ)
(b: buffer t {buffer_writeable b})
(i: nat{i < buffer_length b})
(v: base_typ_as_vale_type t)
(h: vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures
(let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall (a: b8{List.memP a (IB.ptrs_of_mem (_ih h)) /\ a =!= b}) j.
{:pattern
mem1.[ j ]; List.memP a (IB.ptrs_of_mem (_ih h))\/mem2.[ j ];
List.memP a (IB.ptrs_of_mem (_ih h))}
let base = (IB.addrs_of_mem (_ih h)) a in
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==> mem1.[ j ] == mem2.[ j ])) | let unwritten_buffer_down (t:base_typ) (b:buffer t{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:base_typ_as_vale_type t)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall (a:b8{List.memP a (IB.ptrs_of_mem (_ih h)) /\ a =!= b}) j. {:pattern mem1.[j]; List.memP a (IB.ptrs_of_mem (_ih h)) \/ mem2.[j]; List.memP a (IB.ptrs_of_mem (_ih h))}
let base = (IB.addrs_of_mem (_ih h)) a in
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==> mem1.[j] == mem2.[j]))
= let aux (a:b8{a =!= b /\ List.memP a (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let base = (IB.addrs_of_mem (_ih h)) a in
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall j.
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==>
mem1.[j] == mem2.[j]))
= let db = get_downview a.bsrc in
if DV.length db = 0 then ()
else
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = (IB.addrs_of_mem (_ih h)) a in
let s0 = DV.as_seq (IB.hs_of_mem (_ih h)) db in
let s1 = DV.as_seq (IB.hs_of_mem (_ih h1)) db in
opaque_assert (`%IB.list_disjoint_or_eq) IB.list_disjoint_or_eq IB.list_disjoint_or_eq_def (MB.disjoint a.bsrc b.bsrc);
lemma_dv_equal (IB.down_view a.src) a.bsrc (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1));
assert (Seq.equal s0 s1);
assert (forall (j:int).{:pattern (mem1.[j])}
base <= j /\ j < base + Seq.length s0 ==> v_to_typ TUInt8 (Seq.index s0 (j - base)) == mem1.[j]);
heap_shift mem1 mem2 base (DV.length db)
in
Classical.forall_intro aux | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory_Sems.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 30,
"end_line": 377,
"start_col": 0,
"start_line": 339
} | module Vale.X64.Memory_Sems
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.Def.Words_s
module I = Vale.Interop
module S = Vale.X64.Machine_Semantics_s
module MB = LowStar.Monotonic.Buffer
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
friend Vale.X64.Memory
module IB = Vale.Interop.Base
let same_domain h m = Set.equal (IB.addrs_set (_ih h)) (Map.domain m)
let lemma_same_domains h m1 m2 = ()
let get_heap h = I.down_mem (_ih h)
let upd_heap h m = mi_heap_upd h m
//let lemma_upd_get_heap h = I.down_up_identity (_ih h)
let lemma_get_upd_heap h m = I.up_down_identity (_ih h) m
let lemma_heap_impl = ()
let lemma_heap_get_heap h = ()
let lemma_heap_taint h = ()
//let lemma_heap_upd_heap h mh mt = ()
[@"opaque_to_smt"]
let rec set_of_range (a:int) (n:nat) : Pure (Set.set int)
(requires True)
(ensures fun s -> (forall (i:int).{:pattern Set.mem i s} Set.mem i s <==> a <= i /\ i < a + n))
=
if n = 0 then Set.empty else Set.union (set_of_range a (n - 1)) (Set.singleton (a + n - 1))
let buffer_info_has_addr (bi:buffer_info) (a:int) =
let b = bi.bi_buffer in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
addr <= a /\ a < addr + len
let buffer_info_has_addr_opt (bi:option buffer_info) (a:int) =
match bi with
| None -> False
| Some bi -> buffer_info_has_addr bi a
#set-options "--z3rlimit 100"
let rec make_owns_rec (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
if n = 0 then ((fun _ -> None), (fun _ -> Set.empty)) else
let (m0, s0) = make_owns_rec h bs (n - 1) in
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let s i = if i = hi then Set.union (s0 i) s_b else s0 i in
let m a = if addr <= a && a < addr + len then Some (n - 1) else m0 a in
(m, s)
[@"opaque_to_smt"]
let make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
make_owns_rec h bs n
let rec lemma_make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n <= Seq.length bs /\
(forall (i:nat).{:pattern Seq.index bs i} i < Seq.length bs ==> buffer_readable h (Seq.index bs i).bi_buffer) /\
(forall (i1 i2:nat).{:pattern (Seq.index bs i1); (Seq.index bs i2)}
i1 < Seq.length bs /\ i2 < Seq.length bs ==> buffer_info_disjoint (Seq.index bs i1) (Seq.index bs i2))
)
(ensures (
let (m, s) = make_owns h bs n in
(forall (i:heaplet_id) (a:int).{:pattern Set.mem a (s i)}
(Set.mem a (s i) <==> Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (m a) == Some i) /\
(Set.mem a (s i) ==> buffer_info_has_addr_opt (Option.mapTot (fun n -> Seq.index bs n) (m a)) a) /\
(Set.mem a (s i) ==> Set.mem a (Map.domain h.mh))
) /\
(forall (k:nat) (a:int).{:pattern Set.mem a (s (Seq.index bs k).bi_heaplet)}
k < n /\ buffer_info_has_addr (Seq.index bs k) a ==> Set.mem a (s (Seq.index bs k).bi_heaplet))
))
=
reveal_opaque (`%make_owns) make_owns;
if n = 0 then () else
let _ = make_owns h bs (n - 1) in
let (m, s) = make_owns h bs n in
lemma_make_owns h bs (n - 1);
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let lem1 (a:int) : Lemma
(requires Set.mem a s_b)
(ensures Set.mem a (Map.domain h.mh))
[SMTPat (Set.mem a (Map.domain h.mh))]
=
I.addrs_set_mem h.ih b a
in
let lem2 (i:heaplet_id) (a:int) : Lemma
(requires i =!= hi /\ Set.mem a (Set.intersect s_b (s i)))
(ensures False)
[SMTPat (Set.mem a (s i))]
=
reveal_opaque (`%addr_map_pred) addr_map_pred
in
()
#push-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_loc_mutable_buffers_rec (l:list buffer_info) (s:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n + List.length l == Seq.length s /\
list_to_seq_post l s n
)
(ensures (
let modloc = loc_mutable_buffers l in
forall (i:nat).{:pattern Seq.index s i} n <= i /\ i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes modloc (loc_buffer bi.bi_buffer))
))
(decreases l)
=
match l with
| [] -> ()
| h::t -> lemma_loc_mutable_buffers_rec t s (n + 1)
#pop-options
let lemma_loc_mutable_buffers (l:list buffer_info) : Lemma
(ensures (
let s = list_to_seq l in
forall (i:nat).{:pattern Seq.index s i} i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes (loc_mutable_buffers l) (loc_buffer bi.bi_buffer))
))
=
lemma_list_to_seq l;
lemma_loc_mutable_buffers_rec l (list_to_seq l) 0
let create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let modloc = loc_mutable_buffers buffers in
let layout1 = h1.vf_layout in
let layin1 = layout1.vl_inner in
let (hmap, hsets) = make_owns h1.vf_heap bs (Seq.length bs) in
let hmap a = Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (hmap a) in
let l = {
vl_heaplets_initialized = true;
vl_heaplet_map = hmap;
vl_heaplet_sets = hsets;
vl_old_heap = h1.vf_heap;
vl_buffers = bs;
vl_mod_loc = modloc;
} in
let layout2 = {layout1 with vl_inner = l} in
let h2 = {
vf_layout = layout2;
vf_heap = h1.vf_heap;
vf_heaplets = h1.vf_heaplets;
} in
h2
let lemma_create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let h2 = create_heaplets buffers h1 in
assert (h2.vf_layout.vl_inner.vl_buffers == bs); // REVIEW: why is this necessary, even with extra ifuel?
lemma_make_owns h1.vf_heap bs (Seq.length bs);
lemma_loc_mutable_buffers buffers;
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
let destroy_heaplets h1 =
h1
let lemma_destroy_heaplets h1 =
()
val heap_shift (m1 m2:S.machine_heap) (base:int) (n:nat) : Lemma
(requires (forall i. 0 <= i /\ i < n ==> m1.[base + i] == m2.[base + i]))
(ensures (forall i. {:pattern (m1.[i])} base <= i /\ i < base + n ==> m1.[i] == m2.[i]))
#push-options "--smtencoding.l_arith_repr boxwrap"
let heap_shift m1 m2 base n =
assert (forall i. base <= i /\ i < base + n ==>
m1.[base + (i - base)] == m2.[base + (i - base)])
#pop-options
val same_mem_eq_slices64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 8 + 8 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8)))
let same_mem_eq_slices64 b i v k h1 h2 mem1 mem2 =
let t = TUInt64 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up64 (b:buffer64) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 8}) : Lemma
(scale8 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint64_view in
UV.length_eq vb
val same_mem_get_heap_val64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale8 k in
forall (x:int).{:pattern (mem1.[x])} ptr <= x /\ x < ptr + 8 ==> mem1.[x] == mem2.[x]))
let same_mem_get_heap_val64 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale8 k in
let addr = buffer_addr b h1 in
let aux (x:int{ptr <= x /\ x < ptr + 8}) : Lemma (mem1.[x] == mem2.[x]) =
let i = x - ptr in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices64 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8) (k * 8 + 8)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8) (k * 8 + 8)) in
assert (Seq.index s1 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i));
length_up64 b h1 k i;
assert (mem1.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i)));
assert (Seq.index s2 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i));
length_up64 b h2 k i;
assert (mem2.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i)))
in
Classical.forall_intro aux;
assert (forall i. addr + (scale8 k + i) == ptr + i)
let rec written_buffer_down64_aux1
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(k:nat) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j.{:pattern (mem1.[j]) \/ (mem2.[j])}
base <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem1.[j])}
j >= base /\ j < base + scale8 i ==>
mem1.[j] == mem2.[j]))
(decreases %[i-k]) =
if k >= i then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux1 b i v h base (k+1) h1 mem1 mem2
end
let rec written_buffer_down64_aux2
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(n:nat{n == buffer_length b})
(k:nat{k > i}) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
base + scale8 (i+1) <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
j >= base + scale8 (i+1) /\ j < base + scale8 n ==>
mem1.[j] == mem2.[j]))
(decreases %[n-k]) =
if k >= n then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux2 b i v h base n (k+1) h1 mem1 mem2
end
let written_buffer_down64 (b:buffer64{buffer_writeable b}) (i:nat{i < buffer_length b}) (v:nat64) (h:vale_heap)
: Lemma
(requires List.memP b (IB.ptrs_of_mem (_ih h)))
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
(base <= j /\ j < base + scale8 i) \/
(base + scale8 (i+1) <= j /\ j < base + scale8 n) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
written_buffer_down64_aux1 b i v h base 0 h1 mem1 mem2;
written_buffer_down64_aux2 b i v h base n (i+1) h1 mem1 mem2 | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Memory.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.BufferViewStore.fsti.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Memory_Sems.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_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
}
] | {
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
t: Vale.Arch.HeapTypes_s.base_typ ->
b: Vale.Arch.HeapImpl.buffer t {Vale.X64.Memory.buffer_writeable b} ->
i: Prims.nat{i < Vale.X64.Memory.buffer_length b} ->
v: Vale.X64.Memory.base_typ_as_vale_type t ->
h:
Vale.Arch.HeapImpl.vale_heap
{FStar.List.Tot.Base.memP b (Vale.Interop.Heap_s.ptrs_of_mem (Vale.Arch.HeapImpl._ih h))}
-> FStar.Pervasives.Lemma
(ensures
(let mem1 = Vale.Interop.down_mem (Vale.Arch.HeapImpl._ih h) in
let h1 = Vale.X64.Memory.buffer_write b i v h in
let mem2 = Vale.Interop.down_mem (Vale.Arch.HeapImpl._ih h1) in
forall (a:
Vale.X64.Memory.b8
{ FStar.List.Tot.Base.memP a
(Vale.Interop.Heap_s.ptrs_of_mem (Vale.Arch.HeapImpl._ih h)) /\ ~(a == b) })
(j: Prims.int).
{:pattern
mem1.[ j ];
FStar.List.Tot.Base.memP a (Vale.Interop.Heap_s.ptrs_of_mem (Vale.Arch.HeapImpl._ih h))\/mem2.[
j ];
FStar.List.Tot.Base.memP a (Vale.Interop.Heap_s.ptrs_of_mem (Vale.Arch.HeapImpl._ih h))}
let base = Vale.Interop.Heap_s.addrs_of_mem (Vale.Arch.HeapImpl._ih h) a in
j >= base /\
j <
base + LowStar.BufferView.Down.length (Vale.Interop.Types.get_downview (Buffer?.bsrc a)) ==>
mem1.[ j ] == mem2.[ j ])) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Arch.HeapTypes_s.base_typ",
"Vale.Arch.HeapImpl.buffer",
"Vale.X64.Memory.buffer_writeable",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Vale.X64.Memory.buffer_length",
"Vale.X64.Memory.base_typ_as_vale_type",
"Vale.Arch.HeapImpl.vale_heap",
"FStar.List.Tot.Base.memP",
"Vale.Interop.Types.b8",
"Vale.Interop.Heap_s.ptrs_of_mem",
"Vale.Arch.HeapImpl._ih",
"FStar.Classical.forall_intro",
"Vale.X64.Memory.b8",
"Prims.l_and",
"Prims.l_not",
"Prims.eq2",
"Prims.l_Forall",
"Prims.int",
"Prims.l_imp",
"Prims.op_GreaterThanOrEqual",
"Vale.Interop.Heap_s.addrs_of_mem",
"Prims.op_Addition",
"LowStar.BufferView.Down.length",
"FStar.UInt8.t",
"Vale.Interop.Types.get_downview",
"Vale.Interop.Types.__proj__Buffer__item__src",
"Vale.Interop.Types.b8_preorder",
"Vale.Interop.Types.__proj__Buffer__item__writeable",
"Vale.Interop.Types.base_typ_as_type",
"Vale.Interop.Types.__proj__Buffer__item__bsrc",
"Vale.Def.Types_s.nat8",
"Vale.X64.Memory.op_String_Access",
"Vale.Interop.down_mem",
"Vale.X64.Memory.buffer_write",
"Vale.Interop.Heap_s.__proj__InteropHeap__item__ptrs",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Vale.Interop.Heap_s.__proj__InteropHeap__item__addrs",
"Vale.Def.Words_s.nat8",
"FStar.Map.sel",
"Prims.Nil",
"FStar.Pervasives.pattern",
"Prims.op_Equality",
"Prims.bool",
"Vale.X64.Memory_Sems.heap_shift",
"Prims._assert",
"Prims.op_LessThanOrEqual",
"FStar.Seq.Base.length",
"Prims.l_or",
"Vale.Def.Words_s.pow2_8",
"Vale.X64.Memory.v_to_typ",
"Vale.Arch.HeapTypes_s.TUInt8",
"FStar.Seq.Base.index",
"Prims.op_Subtraction",
"FStar.Seq.Base.equal",
"Vale.Lib.BufferViewHelpers.lemma_dv_equal",
"Vale.Interop.Types.down_view",
"Vale.Interop.Heap_s.hs_of_mem",
"Vale.Def.Opaque_s.opaque_assert",
"Prims.list",
"Prims.logical",
"Vale.Interop.Heap_s.list_disjoint_or_eq",
"Vale.Interop.Heap_s.list_disjoint_or_eq_def",
"LowStar.Monotonic.Buffer.disjoint",
"FStar.Seq.Properties.lseq",
"LowStar.BufferView.Down.as_seq",
"Vale.Def.Words_s.nat64",
"Vale.Arch.MachineHeap_s.machine_heap",
"Vale.Interop.Heap_s.correct_down",
"LowStar.BufferView.Down.buffer"
] | [] | false | false | true | false | false | let unwritten_buffer_down
(t: base_typ)
(b: buffer t {buffer_writeable b})
(i: nat{i < buffer_length b})
(v: base_typ_as_vale_type t)
(h: vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures
(let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall (a: b8{List.memP a (IB.ptrs_of_mem (_ih h)) /\ a =!= b}) j.
{:pattern
mem1.[ j ]; List.memP a (IB.ptrs_of_mem (_ih h))\/mem2.[ j ];
List.memP a (IB.ptrs_of_mem (_ih h))}
let base = (IB.addrs_of_mem (_ih h)) a in
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==> mem1.[ j ] == mem2.[ j ])) =
| let aux (a: b8{a =!= b /\ List.memP a (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures
(let base = (IB.addrs_of_mem (_ih h)) a in
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall j.
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==> mem1.[ j ] == mem2.[ j ])) =
let db = get_downview a.bsrc in
if DV.length db = 0
then ()
else
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = (IB.addrs_of_mem (_ih h)) a in
let s0 = DV.as_seq (IB.hs_of_mem (_ih h)) db in
let s1 = DV.as_seq (IB.hs_of_mem (_ih h1)) db in
opaque_assert (`%IB.list_disjoint_or_eq)
IB.list_disjoint_or_eq
IB.list_disjoint_or_eq_def
(MB.disjoint a.bsrc b.bsrc);
lemma_dv_equal (IB.down_view a.src) a.bsrc (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1));
assert (Seq.equal s0 s1);
assert (forall (j: int). {:pattern (mem1.[ j ])}
base <= j /\ j < base + Seq.length s0 ==>
v_to_typ TUInt8 (Seq.index s0 (j - base)) == mem1.[ j ]);
heap_shift mem1 mem2 base (DV.length db)
in
Classical.forall_intro aux | false |
Vale.X64.Memory_Sems.fst | Vale.X64.Memory_Sems.low_lemma_store_mem64 | val low_lemma_store_mem64 (b:buffer64) (i:nat) (v:nat64) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b /\
buffer_writeable b
)
(ensures (
let m = S.update_heap64 (buffer_addr b h + scale8 i) v (get_heap h) in
is_machine_heap_update (get_heap h) m /\ upd_heap h m == buffer_write b i v h
)) | val low_lemma_store_mem64 (b:buffer64) (i:nat) (v:nat64) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b /\
buffer_writeable b
)
(ensures (
let m = S.update_heap64 (buffer_addr b h + scale8 i) v (get_heap h) in
is_machine_heap_update (get_heap h) m /\ upd_heap h m == buffer_write b i v h
)) | let low_lemma_store_mem64 b i v h =
lemma_writeable_mem64 b i h;
lemma_store_mem64 b i v h;
valid_state_store_mem64_aux (buffer_addr b h + scale8 i) v h;
let heap = get_heap h in
let heap' = S.update_heap64 (buffer_addr b h + scale8 i) v heap in
low_lemma_store_mem64_aux b heap i v h;
Vale.Arch.MachineHeap.frame_update_heap64 (buffer_addr b h + scale8 i) v heap;
in_bounds64 h b i;
I.addrs_set_lemma_all ();
I.update_buffer_up_mem (_ih h) b heap heap' | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory_Sems.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 45,
"end_line": 652,
"start_col": 0,
"start_line": 642
} | module Vale.X64.Memory_Sems
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.Def.Words_s
module I = Vale.Interop
module S = Vale.X64.Machine_Semantics_s
module MB = LowStar.Monotonic.Buffer
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
friend Vale.X64.Memory
module IB = Vale.Interop.Base
let same_domain h m = Set.equal (IB.addrs_set (_ih h)) (Map.domain m)
let lemma_same_domains h m1 m2 = ()
let get_heap h = I.down_mem (_ih h)
let upd_heap h m = mi_heap_upd h m
//let lemma_upd_get_heap h = I.down_up_identity (_ih h)
let lemma_get_upd_heap h m = I.up_down_identity (_ih h) m
let lemma_heap_impl = ()
let lemma_heap_get_heap h = ()
let lemma_heap_taint h = ()
//let lemma_heap_upd_heap h mh mt = ()
[@"opaque_to_smt"]
let rec set_of_range (a:int) (n:nat) : Pure (Set.set int)
(requires True)
(ensures fun s -> (forall (i:int).{:pattern Set.mem i s} Set.mem i s <==> a <= i /\ i < a + n))
=
if n = 0 then Set.empty else Set.union (set_of_range a (n - 1)) (Set.singleton (a + n - 1))
let buffer_info_has_addr (bi:buffer_info) (a:int) =
let b = bi.bi_buffer in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
addr <= a /\ a < addr + len
let buffer_info_has_addr_opt (bi:option buffer_info) (a:int) =
match bi with
| None -> False
| Some bi -> buffer_info_has_addr bi a
#set-options "--z3rlimit 100"
let rec make_owns_rec (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
if n = 0 then ((fun _ -> None), (fun _ -> Set.empty)) else
let (m0, s0) = make_owns_rec h bs (n - 1) in
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let s i = if i = hi then Set.union (s0 i) s_b else s0 i in
let m a = if addr <= a && a < addr + len then Some (n - 1) else m0 a in
(m, s)
[@"opaque_to_smt"]
let make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
make_owns_rec h bs n
let rec lemma_make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n <= Seq.length bs /\
(forall (i:nat).{:pattern Seq.index bs i} i < Seq.length bs ==> buffer_readable h (Seq.index bs i).bi_buffer) /\
(forall (i1 i2:nat).{:pattern (Seq.index bs i1); (Seq.index bs i2)}
i1 < Seq.length bs /\ i2 < Seq.length bs ==> buffer_info_disjoint (Seq.index bs i1) (Seq.index bs i2))
)
(ensures (
let (m, s) = make_owns h bs n in
(forall (i:heaplet_id) (a:int).{:pattern Set.mem a (s i)}
(Set.mem a (s i) <==> Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (m a) == Some i) /\
(Set.mem a (s i) ==> buffer_info_has_addr_opt (Option.mapTot (fun n -> Seq.index bs n) (m a)) a) /\
(Set.mem a (s i) ==> Set.mem a (Map.domain h.mh))
) /\
(forall (k:nat) (a:int).{:pattern Set.mem a (s (Seq.index bs k).bi_heaplet)}
k < n /\ buffer_info_has_addr (Seq.index bs k) a ==> Set.mem a (s (Seq.index bs k).bi_heaplet))
))
=
reveal_opaque (`%make_owns) make_owns;
if n = 0 then () else
let _ = make_owns h bs (n - 1) in
let (m, s) = make_owns h bs n in
lemma_make_owns h bs (n - 1);
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let lem1 (a:int) : Lemma
(requires Set.mem a s_b)
(ensures Set.mem a (Map.domain h.mh))
[SMTPat (Set.mem a (Map.domain h.mh))]
=
I.addrs_set_mem h.ih b a
in
let lem2 (i:heaplet_id) (a:int) : Lemma
(requires i =!= hi /\ Set.mem a (Set.intersect s_b (s i)))
(ensures False)
[SMTPat (Set.mem a (s i))]
=
reveal_opaque (`%addr_map_pred) addr_map_pred
in
()
#push-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_loc_mutable_buffers_rec (l:list buffer_info) (s:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n + List.length l == Seq.length s /\
list_to_seq_post l s n
)
(ensures (
let modloc = loc_mutable_buffers l in
forall (i:nat).{:pattern Seq.index s i} n <= i /\ i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes modloc (loc_buffer bi.bi_buffer))
))
(decreases l)
=
match l with
| [] -> ()
| h::t -> lemma_loc_mutable_buffers_rec t s (n + 1)
#pop-options
let lemma_loc_mutable_buffers (l:list buffer_info) : Lemma
(ensures (
let s = list_to_seq l in
forall (i:nat).{:pattern Seq.index s i} i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes (loc_mutable_buffers l) (loc_buffer bi.bi_buffer))
))
=
lemma_list_to_seq l;
lemma_loc_mutable_buffers_rec l (list_to_seq l) 0
let create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let modloc = loc_mutable_buffers buffers in
let layout1 = h1.vf_layout in
let layin1 = layout1.vl_inner in
let (hmap, hsets) = make_owns h1.vf_heap bs (Seq.length bs) in
let hmap a = Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (hmap a) in
let l = {
vl_heaplets_initialized = true;
vl_heaplet_map = hmap;
vl_heaplet_sets = hsets;
vl_old_heap = h1.vf_heap;
vl_buffers = bs;
vl_mod_loc = modloc;
} in
let layout2 = {layout1 with vl_inner = l} in
let h2 = {
vf_layout = layout2;
vf_heap = h1.vf_heap;
vf_heaplets = h1.vf_heaplets;
} in
h2
let lemma_create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let h2 = create_heaplets buffers h1 in
assert (h2.vf_layout.vl_inner.vl_buffers == bs); // REVIEW: why is this necessary, even with extra ifuel?
lemma_make_owns h1.vf_heap bs (Seq.length bs);
lemma_loc_mutable_buffers buffers;
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
let destroy_heaplets h1 =
h1
let lemma_destroy_heaplets h1 =
()
val heap_shift (m1 m2:S.machine_heap) (base:int) (n:nat) : Lemma
(requires (forall i. 0 <= i /\ i < n ==> m1.[base + i] == m2.[base + i]))
(ensures (forall i. {:pattern (m1.[i])} base <= i /\ i < base + n ==> m1.[i] == m2.[i]))
#push-options "--smtencoding.l_arith_repr boxwrap"
let heap_shift m1 m2 base n =
assert (forall i. base <= i /\ i < base + n ==>
m1.[base + (i - base)] == m2.[base + (i - base)])
#pop-options
val same_mem_eq_slices64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 8 + 8 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8)))
let same_mem_eq_slices64 b i v k h1 h2 mem1 mem2 =
let t = TUInt64 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up64 (b:buffer64) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 8}) : Lemma
(scale8 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint64_view in
UV.length_eq vb
val same_mem_get_heap_val64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale8 k in
forall (x:int).{:pattern (mem1.[x])} ptr <= x /\ x < ptr + 8 ==> mem1.[x] == mem2.[x]))
let same_mem_get_heap_val64 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale8 k in
let addr = buffer_addr b h1 in
let aux (x:int{ptr <= x /\ x < ptr + 8}) : Lemma (mem1.[x] == mem2.[x]) =
let i = x - ptr in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices64 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8) (k * 8 + 8)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8) (k * 8 + 8)) in
assert (Seq.index s1 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i));
length_up64 b h1 k i;
assert (mem1.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i)));
assert (Seq.index s2 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i));
length_up64 b h2 k i;
assert (mem2.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i)))
in
Classical.forall_intro aux;
assert (forall i. addr + (scale8 k + i) == ptr + i)
let rec written_buffer_down64_aux1
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(k:nat) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j.{:pattern (mem1.[j]) \/ (mem2.[j])}
base <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem1.[j])}
j >= base /\ j < base + scale8 i ==>
mem1.[j] == mem2.[j]))
(decreases %[i-k]) =
if k >= i then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux1 b i v h base (k+1) h1 mem1 mem2
end
let rec written_buffer_down64_aux2
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(n:nat{n == buffer_length b})
(k:nat{k > i}) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
base + scale8 (i+1) <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
j >= base + scale8 (i+1) /\ j < base + scale8 n ==>
mem1.[j] == mem2.[j]))
(decreases %[n-k]) =
if k >= n then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux2 b i v h base n (k+1) h1 mem1 mem2
end
let written_buffer_down64 (b:buffer64{buffer_writeable b}) (i:nat{i < buffer_length b}) (v:nat64) (h:vale_heap)
: Lemma
(requires List.memP b (IB.ptrs_of_mem (_ih h)))
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
(base <= j /\ j < base + scale8 i) \/
(base + scale8 (i+1) <= j /\ j < base + scale8 n) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
written_buffer_down64_aux1 b i v h base 0 h1 mem1 mem2;
written_buffer_down64_aux2 b i v h base n (i+1) h1 mem1 mem2
let unwritten_buffer_down (t:base_typ) (b:buffer t{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:base_typ_as_vale_type t)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall (a:b8{List.memP a (IB.ptrs_of_mem (_ih h)) /\ a =!= b}) j. {:pattern mem1.[j]; List.memP a (IB.ptrs_of_mem (_ih h)) \/ mem2.[j]; List.memP a (IB.ptrs_of_mem (_ih h))}
let base = (IB.addrs_of_mem (_ih h)) a in
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==> mem1.[j] == mem2.[j]))
= let aux (a:b8{a =!= b /\ List.memP a (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let base = (IB.addrs_of_mem (_ih h)) a in
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall j.
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==>
mem1.[j] == mem2.[j]))
= let db = get_downview a.bsrc in
if DV.length db = 0 then ()
else
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = (IB.addrs_of_mem (_ih h)) a in
let s0 = DV.as_seq (IB.hs_of_mem (_ih h)) db in
let s1 = DV.as_seq (IB.hs_of_mem (_ih h1)) db in
opaque_assert (`%IB.list_disjoint_or_eq) IB.list_disjoint_or_eq IB.list_disjoint_or_eq_def (MB.disjoint a.bsrc b.bsrc);
lemma_dv_equal (IB.down_view a.src) a.bsrc (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1));
assert (Seq.equal s0 s1);
assert (forall (j:int).{:pattern (mem1.[j])}
base <= j /\ j < base + Seq.length s0 ==> v_to_typ TUInt8 (Seq.index s0 (j - base)) == mem1.[j]);
heap_shift mem1 mem2 base (DV.length db)
in
Classical.forall_intro aux
let store_buffer_down64_mem
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
forall (j:int). {:pattern mem1.[j] \/ mem2.[j]}
j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
let aux (j:int)
: Lemma
(j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j])
=
I.addrs_set_lemma_all ();
if j >= base && j < base + DV.length (get_downview b.bsrc) then begin
written_buffer_down64 b i v h;
length_t_eq (TUInt64) b
end
else if not (I.valid_addr (_ih h) j)
then I.same_unspecified_down (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1)) (IB.ptrs_of_mem (_ih h))
else unwritten_buffer_down TUInt64 b i v h
in
Classical.forall_intro aux
let store_buffer_aux_down64_mem (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
forall j. {:pattern mem1.[j] \/ mem2.[j]}
j < ptr \/ j >= ptr + 8 ==>
mem1.[j] == mem2.[j]))
= let t = TUInt64 in
let h1 = store_mem t ptr v h in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
store_buffer_write t ptr v h;
assert (buffer_addr b h + scale8 i == ptr);
assert (buffer_addr b h + scale8 (i+1) == ptr + 8);
store_buffer_down64_mem b i v h
let store_buffer_aux_down64_mem2 (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
S.get_heap_val64 ptr mem2 == v))
= let t = TUInt64 in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
let h1 = store_mem t ptr v h in
let mem2 = I.down_mem (_ih h1) in
store_buffer_write t ptr v h;
assert (Seq.index (buffer_as_seq h1 b) i == v);
index64_get_heap_val64 h1 b mem2 i
let in_bounds64 (h:vale_heap) (b:buffer64) (i:nat{i < buffer_length b})
: Lemma (scale8 i + 8 <= DV.length (get_downview b.bsrc))
=
length_t_eq TUInt64 b
let bytes_valid64 ptr h =
reveal_opaque (`%S.valid_addr64) S.valid_addr64;
let t = TUInt64 in
let b = get_addr_ptr t ptr h in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
in_bounds64 h b i;
I.addrs_set_mem (_ih h) b ptr;
I.addrs_set_mem (_ih h) b (ptr+1);
I.addrs_set_mem (_ih h) b (ptr+2);
I.addrs_set_mem (_ih h) b (ptr+3);
I.addrs_set_mem (_ih h) b (ptr+4);
I.addrs_set_mem (_ih h) b (ptr+5);
I.addrs_set_mem (_ih h) b (ptr+6);
I.addrs_set_mem (_ih h) b (ptr+7)
val same_mem_get_heap_val128 (b:buffer128)
(i:nat{i < buffer_length b})
(v:quad32)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1)) /\ buffer_writeable b})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale16 k in
forall i.{:pattern mem1.[i]} i >= ptr /\ i < ptr+16 ==> mem1.[i] == mem2.[i]))
val same_mem_eq_slices128 (b:buffer128)
(i:nat{i < buffer_length b})
(v:quad32)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1)) /\ buffer_writeable b})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 16 + 16 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 16) (k * 16 + 16) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 16) (k * 16 + 16)))
let same_mem_eq_slices128 b i v k h1 h2 mem1 mem2 =
let t = TUInt128 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up128 (b:buffer128) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 16}) : Lemma
(scale16 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint128_view in
UV.length_eq vb
let same_mem_get_heap_val128 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale16 k in
let addr = buffer_addr b h1 in
let aux (i:nat{ptr <= i /\ i < ptr+16}) : Lemma (mem1.[i] == mem2.[i]) =
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint128_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices128 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16) (k * 16 + 16)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16) (k * 16 + 16)) in
assert (Seq.index s1 (i - ptr) == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16 + (i-ptr)));
length_up128 b h1 k (i-ptr);
assert (mem1.[i] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16 + (i-ptr))));
assert (Seq.index s2 (i-ptr) == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16 + (i-ptr)));
length_up128 b h2 k (i-ptr);
assert (mem2.[addr+(scale16 k + (i-ptr))] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16 + (i-ptr))));
assert (forall i. addr + (scale16 k + (i-ptr)) == i)
in
Classical.forall_intro aux
let in_bounds128 (h:vale_heap) (b:buffer128) (i:nat{i < buffer_length b}) : Lemma
(scale16 i + 16 <= DV.length (get_downview b.bsrc))
=
length_t_eq TUInt128 b
#push-options "--z3rlimit 20"
#restart-solver
let bytes_valid128 ptr h =
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
IB.list_disjoint_or_eq_reveal ();
let t = TUInt128 in
let b = get_addr_ptr t ptr h in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
in_bounds128 h b i;
I.addrs_set_mem (_ih h) b ptr;
I.addrs_set_mem (_ih h) b (ptr+1);
I.addrs_set_mem (_ih h) b (ptr+2);
I.addrs_set_mem (_ih h) b (ptr+3);
I.addrs_set_mem (_ih h) b (ptr+4);
I.addrs_set_mem (_ih h) b (ptr+5);
I.addrs_set_mem (_ih h) b (ptr+6);
I.addrs_set_mem (_ih h) b (ptr+7);
I.addrs_set_mem (_ih h) b (ptr+8);
I.addrs_set_mem (_ih h) b (ptr+9);
I.addrs_set_mem (_ih h) b (ptr+10);
I.addrs_set_mem (_ih h) b (ptr+11);
I.addrs_set_mem (_ih h) b (ptr+12);
I.addrs_set_mem (_ih h) b (ptr+13);
I.addrs_set_mem (_ih h) b (ptr+14);
I.addrs_set_mem (_ih h) b (ptr+15)
#pop-options
let equiv_load_mem64 ptr h =
let t = TUInt64 in
let b = get_addr_ptr t ptr h in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
let addr = buffer_addr b h in
let contents = DV.as_seq (_ih h).IB.hs (get_downview b.bsrc) in
let heap = get_heap h in
index64_get_heap_val64 h b heap i;
lemma_load_mem64 b i h
//let low_lemma_valid_mem64 b i h =
// lemma_valid_mem64 b i h;
// bytes_valid64 (buffer_addr b h + scale8 i) h
//let low_lemma_load_mem64 b i h =
// lemma_valid_mem64 b i h;
// lemma_load_mem64 b i h;
// equiv_load_mem64 (buffer_addr b h + scale8 i) h
//let same_domain_update64 b i v h =
// low_lemma_valid_mem64 b i h;
// Vale.Arch.MachineHeap.same_domain_update64 (buffer_addr b h + scale8 i) v (get_heap h)
open Vale.X64.BufferViewStore
let low_lemma_store_mem64_aux
(b:buffer64)
(heap:S.machine_heap)
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{buffer_readable h b /\ buffer_writeable b})
: Lemma
(requires IB.correct_down_p (_ih h) heap b)
(ensures (let heap' = S.update_heap64 (buffer_addr b h + scale8 i) v heap in
let h' = store_mem64 (buffer_addr b h + scale8 i) v h in
(_ih h').IB.hs == DV.upd_seq (_ih h).IB.hs (get_downview b.bsrc) (I.get_seq_heap heap' (_ih h).IB.addrs b))) =
let ptr = buffer_addr b h + scale8 i in
let heap' = S.update_heap64 ptr v heap in
let h' = store_mem64 ptr v h in
lemma_store_mem64 b i v h;
length_t_eq TUInt64 b;
bv_upd_update_heap64 b heap i v (_ih h);
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db Vale.Interop.Views.up_view64 in
assert (UV.upd (_ih h).IB.hs bv i (UInt64.uint_to_t v) == (_ih h').IB.hs)
val valid_state_store_mem64_aux: (i:nat) -> (v:nat64) -> (h:vale_heap) -> Lemma
(requires writeable_mem64 i h)
(ensures (
let heap = get_heap h in
let heap' = S.update_heap64 i v heap in
let h' = store_mem64 i v h in
heap' == I.down_mem (_ih h')
))
let valid_state_store_mem64_aux i v h =
let heap = get_heap h in
let heap' = S.update_heap64 i v heap in
let h1 = store_mem TUInt64 i v h in
store_buffer_aux_down64_mem i v h;
store_buffer_aux_down64_mem2 i v h;
let mem1 = heap' in
let mem2 = I.down_mem (_ih h1) in
let aux () : Lemma (forall j. mem1.[j] == mem2.[j]) =
Vale.Arch.MachineHeap.same_mem_get_heap_val64 i mem1 mem2;
Vale.Arch.MachineHeap.correct_update_get64 i v heap;
Vale.Arch.MachineHeap.frame_update_heap64 i v heap
in let aux2 () : Lemma (Set.equal (Map.domain mem1) (Map.domain mem2)) =
bytes_valid64 i h;
Vale.Arch.MachineHeap.same_domain_update64 i v heap
in aux(); aux2();
Map.lemma_equal_intro mem1 mem2
let low_lemma_load_mem64_full b i vfh t hid =
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
#push-options "--z3rlimit 20" | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Memory.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.BufferViewStore.fsti.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Memory_Sems.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.BufferViewStore",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_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
}
] | {
"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": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
b: Vale.X64.Memory.buffer64 ->
i: Prims.nat ->
v: Vale.Def.Words_s.nat64 ->
h: Vale.Arch.HeapImpl.vale_heap
-> FStar.Pervasives.Lemma
(requires
i < FStar.Seq.Base.length (Vale.X64.Memory.buffer_as_seq h b) /\
Vale.X64.Memory.buffer_readable h b /\ Vale.X64.Memory.buffer_writeable b)
(ensures
(let m =
Vale.Arch.MachineHeap_s.update_heap64 (Vale.X64.Memory.buffer_addr b h +
Vale.X64.Memory.scale8 i)
v
(Vale.X64.Memory_Sems.get_heap h)
in
Vale.Arch.MachineHeap_s.is_machine_heap_update (Vale.X64.Memory_Sems.get_heap h) m /\
Vale.X64.Memory_Sems.upd_heap h m == Vale.X64.Memory.buffer_write b i v h)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.X64.Memory.buffer64",
"Prims.nat",
"Vale.Def.Words_s.nat64",
"Vale.Arch.HeapImpl.vale_heap",
"Vale.Interop.update_buffer_up_mem",
"Vale.Arch.HeapImpl._ih",
"Prims.unit",
"Vale.Interop.addrs_set_lemma_all",
"Vale.X64.Memory_Sems.in_bounds64",
"Vale.Arch.MachineHeap.frame_update_heap64",
"Prims.op_Addition",
"Vale.X64.Memory.buffer_addr",
"Vale.X64.Memory.vuint64",
"Vale.X64.Memory.scale8",
"Vale.X64.Memory_Sems.low_lemma_store_mem64_aux",
"Vale.Arch.MachineHeap_s.machine_heap",
"Vale.Arch.MachineHeap_s.update_heap64",
"Vale.X64.Memory_Sems.same_domain",
"Vale.X64.Memory_Sems.get_heap",
"Vale.X64.Memory_Sems.valid_state_store_mem64_aux",
"Vale.X64.Memory.lemma_store_mem64",
"Vale.X64.Memory.lemma_writeable_mem64"
] | [] | true | false | true | false | false | let low_lemma_store_mem64 b i v h =
| lemma_writeable_mem64 b i h;
lemma_store_mem64 b i v h;
valid_state_store_mem64_aux (buffer_addr b h + scale8 i) v h;
let heap = get_heap h in
let heap' = S.update_heap64 (buffer_addr b h + scale8 i) v heap in
low_lemma_store_mem64_aux b heap i v h;
Vale.Arch.MachineHeap.frame_update_heap64 (buffer_addr b h + scale8 i) v heap;
in_bounds64 h b i;
I.addrs_set_lemma_all ();
I.update_buffer_up_mem (_ih h) b heap heap' | false |
PulseCore.MonotonicStateMonad.fst | PulseCore.MonotonicStateMonad.put | val put (#s:Type u#s) (#rel:preorder s) (v:s)
: mst rel unit (fun s0 -> rel s0 v /\ True) (fun s0 x s1 -> v == s1) | val put (#s:Type u#s) (#rel:preorder s) (v:s)
: mst rel unit (fun s0 -> rel s0 v /\ True) (fun s0 x s1 -> v == s1) | let put v
= fun _ -> (), v | {
"file_name": "lib/pulse_core/PulseCore.MonotonicStateMonad.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 17,
"end_line": 51,
"start_col": 0,
"start_line": 50
} | module PulseCore.MonotonicStateMonad
open FStar.Preorder
module M = FStar.MSTTotal
let mst (#s:Type u#s)
(rel:FStar.Preorder.preorder s)
(a:Type u#a)
(pre:s -> prop)
(post:s -> a -> s -> prop)
= s0:s { pre s0 }
-> Tot (
res:(a & s) {
post s0 res._1 res._2 /\
rel s0 res._2
}
)
assume (* to interoperate with a definition of a similar module in FStar.MSTTotal *)
val reify_ (#s:Type u#2) (#rel:FStar.Preorder.preorder s)
(#a:Type u#a) (#pre:s -> prop) (#post:s -> a -> s -> prop)
($f:unit -> M.MSTATETOT a s rel pre post)
: M.repr a s rel pre post
let of_msttotal (#s:Type u#2) (rel:FStar.Preorder.preorder s)
(a:Type u#a) (pre:s -> prop) (post:s -> a -> s -> prop)
(f:unit -> M.MSTATETOT a s rel pre post)
: mst rel a pre post
= let f = reify_ f in
fun s -> f s
let to_msttotal (#s:Type u#2) (rel:FStar.Preorder.preorder s)
(a:Type u#a) (pre:s -> prop) (post:s -> a -> s -> prop)
(f:mst rel a pre post)
: M.MSTATETOT a s rel pre post
= M.MSTATETOT?.reflect (fun s -> f s)
let return x
= fun s0 -> x, s0
let bind f g
= fun s0 ->
let x, s1 = f s0 in
g x s1
let weaken f
= fun s -> f s
let get _
= fun s -> s, s | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.MSTTotal.fst.checked"
],
"interface_file": true,
"source_file": "PulseCore.MonotonicStateMonad.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.MSTTotal",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.MSTTotal",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "PulseCore",
"short_module": null
},
{
"abbrev": false,
"full_module": "PulseCore",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | v: s
-> PulseCore.MonotonicStateMonad.mst rel
Prims.unit
(fun s0 -> rel s0 v /\ Prims.l_True)
(fun _ _ s1 -> v == s1) | Prims.Tot | [
"total"
] | [] | [
"FStar.Preorder.preorder",
"Prims.l_and",
"Prims.l_True",
"FStar.Pervasives.Native.Mktuple2",
"Prims.unit",
"FStar.Pervasives.Native.tuple2",
"Prims.eq2",
"Prims.prop",
"FStar.Pervasives.Native.__proj__Mktuple2__item___1",
"FStar.Pervasives.Native.__proj__Mktuple2__item___2"
] | [] | false | false | false | false | false | let put v =
| fun _ -> (), v | false |
PulseCore.MonotonicStateMonad.fst | PulseCore.MonotonicStateMonad.witness | val witness (#s:Type u#s) (#rel:preorder s) (p: s -> prop { stable p rel })
: mst rel (witnessed p) (fun s0 -> p s0) (fun s0 x s1 -> s0 == s1) | val witness (#s:Type u#s) (#rel:preorder s) (p: s -> prop { stable p rel })
: mst rel (witnessed p) (fun s0 -> p s0) (fun s0 x s1 -> s0 == s1) | let witness p
= fun s -> (), s | {
"file_name": "lib/pulse_core/PulseCore.MonotonicStateMonad.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 16,
"end_line": 57,
"start_col": 0,
"start_line": 56
} | module PulseCore.MonotonicStateMonad
open FStar.Preorder
module M = FStar.MSTTotal
let mst (#s:Type u#s)
(rel:FStar.Preorder.preorder s)
(a:Type u#a)
(pre:s -> prop)
(post:s -> a -> s -> prop)
= s0:s { pre s0 }
-> Tot (
res:(a & s) {
post s0 res._1 res._2 /\
rel s0 res._2
}
)
assume (* to interoperate with a definition of a similar module in FStar.MSTTotal *)
val reify_ (#s:Type u#2) (#rel:FStar.Preorder.preorder s)
(#a:Type u#a) (#pre:s -> prop) (#post:s -> a -> s -> prop)
($f:unit -> M.MSTATETOT a s rel pre post)
: M.repr a s rel pre post
let of_msttotal (#s:Type u#2) (rel:FStar.Preorder.preorder s)
(a:Type u#a) (pre:s -> prop) (post:s -> a -> s -> prop)
(f:unit -> M.MSTATETOT a s rel pre post)
: mst rel a pre post
= let f = reify_ f in
fun s -> f s
let to_msttotal (#s:Type u#2) (rel:FStar.Preorder.preorder s)
(a:Type u#a) (pre:s -> prop) (post:s -> a -> s -> prop)
(f:mst rel a pre post)
: M.MSTATETOT a s rel pre post
= M.MSTATETOT?.reflect (fun s -> f s)
let return x
= fun s0 -> x, s0
let bind f g
= fun s0 ->
let x, s1 = f s0 in
g x s1
let weaken f
= fun s -> f s
let get _
= fun s -> s, s
let put v
= fun _ -> (), v
let witnessed p
= unit | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.MSTTotal.fst.checked"
],
"interface_file": true,
"source_file": "PulseCore.MonotonicStateMonad.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.MSTTotal",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.MSTTotal",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "PulseCore",
"short_module": null
},
{
"abbrev": false,
"full_module": "PulseCore",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | p: (_: s -> Prims.prop){FStar.Preorder.stable p rel}
-> PulseCore.MonotonicStateMonad.mst rel
(PulseCore.MonotonicStateMonad.witnessed p)
(fun s0 -> p s0)
(fun s0 _ s1 -> s0 == s1) | Prims.Tot | [
"total"
] | [] | [
"FStar.Preorder.preorder",
"Prims.prop",
"FStar.Preorder.stable",
"FStar.Pervasives.Native.Mktuple2",
"PulseCore.MonotonicStateMonad.witnessed",
"FStar.Pervasives.Native.tuple2",
"Prims.l_and",
"Prims.eq2",
"FStar.Pervasives.Native.__proj__Mktuple2__item___1",
"FStar.Pervasives.Native.__proj__Mktuple2__item___2"
] | [] | false | false | false | false | false | let witness p =
| fun s -> (), s | false |
Vale.X64.Memory_Sems.fst | Vale.X64.Memory_Sems.valid_state_store_mem64_aux | val valid_state_store_mem64_aux: (i:nat) -> (v:nat64) -> (h:vale_heap) -> Lemma
(requires writeable_mem64 i h)
(ensures (
let heap = get_heap h in
let heap' = S.update_heap64 i v heap in
let h' = store_mem64 i v h in
heap' == I.down_mem (_ih h')
)) | val valid_state_store_mem64_aux: (i:nat) -> (v:nat64) -> (h:vale_heap) -> Lemma
(requires writeable_mem64 i h)
(ensures (
let heap = get_heap h in
let heap' = S.update_heap64 i v heap in
let h' = store_mem64 i v h in
heap' == I.down_mem (_ih h')
)) | let valid_state_store_mem64_aux i v h =
let heap = get_heap h in
let heap' = S.update_heap64 i v heap in
let h1 = store_mem TUInt64 i v h in
store_buffer_aux_down64_mem i v h;
store_buffer_aux_down64_mem2 i v h;
let mem1 = heap' in
let mem2 = I.down_mem (_ih h1) in
let aux () : Lemma (forall j. mem1.[j] == mem2.[j]) =
Vale.Arch.MachineHeap.same_mem_get_heap_val64 i mem1 mem2;
Vale.Arch.MachineHeap.correct_update_get64 i v heap;
Vale.Arch.MachineHeap.frame_update_heap64 i v heap
in let aux2 () : Lemma (Set.equal (Map.domain mem1) (Map.domain mem2)) =
bytes_valid64 i h;
Vale.Arch.MachineHeap.same_domain_update64 i v heap
in aux(); aux2();
Map.lemma_equal_intro mem1 mem2 | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory_Sems.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 33,
"end_line": 634,
"start_col": 0,
"start_line": 618
} | module Vale.X64.Memory_Sems
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.Def.Words_s
module I = Vale.Interop
module S = Vale.X64.Machine_Semantics_s
module MB = LowStar.Monotonic.Buffer
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
friend Vale.X64.Memory
module IB = Vale.Interop.Base
let same_domain h m = Set.equal (IB.addrs_set (_ih h)) (Map.domain m)
let lemma_same_domains h m1 m2 = ()
let get_heap h = I.down_mem (_ih h)
let upd_heap h m = mi_heap_upd h m
//let lemma_upd_get_heap h = I.down_up_identity (_ih h)
let lemma_get_upd_heap h m = I.up_down_identity (_ih h) m
let lemma_heap_impl = ()
let lemma_heap_get_heap h = ()
let lemma_heap_taint h = ()
//let lemma_heap_upd_heap h mh mt = ()
[@"opaque_to_smt"]
let rec set_of_range (a:int) (n:nat) : Pure (Set.set int)
(requires True)
(ensures fun s -> (forall (i:int).{:pattern Set.mem i s} Set.mem i s <==> a <= i /\ i < a + n))
=
if n = 0 then Set.empty else Set.union (set_of_range a (n - 1)) (Set.singleton (a + n - 1))
let buffer_info_has_addr (bi:buffer_info) (a:int) =
let b = bi.bi_buffer in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
addr <= a /\ a < addr + len
let buffer_info_has_addr_opt (bi:option buffer_info) (a:int) =
match bi with
| None -> False
| Some bi -> buffer_info_has_addr bi a
#set-options "--z3rlimit 100"
let rec make_owns_rec (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
if n = 0 then ((fun _ -> None), (fun _ -> Set.empty)) else
let (m0, s0) = make_owns_rec h bs (n - 1) in
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let s i = if i = hi then Set.union (s0 i) s_b else s0 i in
let m a = if addr <= a && a < addr + len then Some (n - 1) else m0 a in
(m, s)
[@"opaque_to_smt"]
let make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
make_owns_rec h bs n
let rec lemma_make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n <= Seq.length bs /\
(forall (i:nat).{:pattern Seq.index bs i} i < Seq.length bs ==> buffer_readable h (Seq.index bs i).bi_buffer) /\
(forall (i1 i2:nat).{:pattern (Seq.index bs i1); (Seq.index bs i2)}
i1 < Seq.length bs /\ i2 < Seq.length bs ==> buffer_info_disjoint (Seq.index bs i1) (Seq.index bs i2))
)
(ensures (
let (m, s) = make_owns h bs n in
(forall (i:heaplet_id) (a:int).{:pattern Set.mem a (s i)}
(Set.mem a (s i) <==> Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (m a) == Some i) /\
(Set.mem a (s i) ==> buffer_info_has_addr_opt (Option.mapTot (fun n -> Seq.index bs n) (m a)) a) /\
(Set.mem a (s i) ==> Set.mem a (Map.domain h.mh))
) /\
(forall (k:nat) (a:int).{:pattern Set.mem a (s (Seq.index bs k).bi_heaplet)}
k < n /\ buffer_info_has_addr (Seq.index bs k) a ==> Set.mem a (s (Seq.index bs k).bi_heaplet))
))
=
reveal_opaque (`%make_owns) make_owns;
if n = 0 then () else
let _ = make_owns h bs (n - 1) in
let (m, s) = make_owns h bs n in
lemma_make_owns h bs (n - 1);
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let lem1 (a:int) : Lemma
(requires Set.mem a s_b)
(ensures Set.mem a (Map.domain h.mh))
[SMTPat (Set.mem a (Map.domain h.mh))]
=
I.addrs_set_mem h.ih b a
in
let lem2 (i:heaplet_id) (a:int) : Lemma
(requires i =!= hi /\ Set.mem a (Set.intersect s_b (s i)))
(ensures False)
[SMTPat (Set.mem a (s i))]
=
reveal_opaque (`%addr_map_pred) addr_map_pred
in
()
#push-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_loc_mutable_buffers_rec (l:list buffer_info) (s:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n + List.length l == Seq.length s /\
list_to_seq_post l s n
)
(ensures (
let modloc = loc_mutable_buffers l in
forall (i:nat).{:pattern Seq.index s i} n <= i /\ i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes modloc (loc_buffer bi.bi_buffer))
))
(decreases l)
=
match l with
| [] -> ()
| h::t -> lemma_loc_mutable_buffers_rec t s (n + 1)
#pop-options
let lemma_loc_mutable_buffers (l:list buffer_info) : Lemma
(ensures (
let s = list_to_seq l in
forall (i:nat).{:pattern Seq.index s i} i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes (loc_mutable_buffers l) (loc_buffer bi.bi_buffer))
))
=
lemma_list_to_seq l;
lemma_loc_mutable_buffers_rec l (list_to_seq l) 0
let create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let modloc = loc_mutable_buffers buffers in
let layout1 = h1.vf_layout in
let layin1 = layout1.vl_inner in
let (hmap, hsets) = make_owns h1.vf_heap bs (Seq.length bs) in
let hmap a = Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (hmap a) in
let l = {
vl_heaplets_initialized = true;
vl_heaplet_map = hmap;
vl_heaplet_sets = hsets;
vl_old_heap = h1.vf_heap;
vl_buffers = bs;
vl_mod_loc = modloc;
} in
let layout2 = {layout1 with vl_inner = l} in
let h2 = {
vf_layout = layout2;
vf_heap = h1.vf_heap;
vf_heaplets = h1.vf_heaplets;
} in
h2
let lemma_create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let h2 = create_heaplets buffers h1 in
assert (h2.vf_layout.vl_inner.vl_buffers == bs); // REVIEW: why is this necessary, even with extra ifuel?
lemma_make_owns h1.vf_heap bs (Seq.length bs);
lemma_loc_mutable_buffers buffers;
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
let destroy_heaplets h1 =
h1
let lemma_destroy_heaplets h1 =
()
val heap_shift (m1 m2:S.machine_heap) (base:int) (n:nat) : Lemma
(requires (forall i. 0 <= i /\ i < n ==> m1.[base + i] == m2.[base + i]))
(ensures (forall i. {:pattern (m1.[i])} base <= i /\ i < base + n ==> m1.[i] == m2.[i]))
#push-options "--smtencoding.l_arith_repr boxwrap"
let heap_shift m1 m2 base n =
assert (forall i. base <= i /\ i < base + n ==>
m1.[base + (i - base)] == m2.[base + (i - base)])
#pop-options
val same_mem_eq_slices64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 8 + 8 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8)))
let same_mem_eq_slices64 b i v k h1 h2 mem1 mem2 =
let t = TUInt64 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up64 (b:buffer64) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 8}) : Lemma
(scale8 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint64_view in
UV.length_eq vb
val same_mem_get_heap_val64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale8 k in
forall (x:int).{:pattern (mem1.[x])} ptr <= x /\ x < ptr + 8 ==> mem1.[x] == mem2.[x]))
let same_mem_get_heap_val64 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale8 k in
let addr = buffer_addr b h1 in
let aux (x:int{ptr <= x /\ x < ptr + 8}) : Lemma (mem1.[x] == mem2.[x]) =
let i = x - ptr in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices64 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8) (k * 8 + 8)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8) (k * 8 + 8)) in
assert (Seq.index s1 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i));
length_up64 b h1 k i;
assert (mem1.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i)));
assert (Seq.index s2 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i));
length_up64 b h2 k i;
assert (mem2.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i)))
in
Classical.forall_intro aux;
assert (forall i. addr + (scale8 k + i) == ptr + i)
let rec written_buffer_down64_aux1
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(k:nat) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j.{:pattern (mem1.[j]) \/ (mem2.[j])}
base <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem1.[j])}
j >= base /\ j < base + scale8 i ==>
mem1.[j] == mem2.[j]))
(decreases %[i-k]) =
if k >= i then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux1 b i v h base (k+1) h1 mem1 mem2
end
let rec written_buffer_down64_aux2
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(n:nat{n == buffer_length b})
(k:nat{k > i}) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
base + scale8 (i+1) <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
j >= base + scale8 (i+1) /\ j < base + scale8 n ==>
mem1.[j] == mem2.[j]))
(decreases %[n-k]) =
if k >= n then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux2 b i v h base n (k+1) h1 mem1 mem2
end
let written_buffer_down64 (b:buffer64{buffer_writeable b}) (i:nat{i < buffer_length b}) (v:nat64) (h:vale_heap)
: Lemma
(requires List.memP b (IB.ptrs_of_mem (_ih h)))
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
(base <= j /\ j < base + scale8 i) \/
(base + scale8 (i+1) <= j /\ j < base + scale8 n) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
written_buffer_down64_aux1 b i v h base 0 h1 mem1 mem2;
written_buffer_down64_aux2 b i v h base n (i+1) h1 mem1 mem2
let unwritten_buffer_down (t:base_typ) (b:buffer t{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:base_typ_as_vale_type t)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall (a:b8{List.memP a (IB.ptrs_of_mem (_ih h)) /\ a =!= b}) j. {:pattern mem1.[j]; List.memP a (IB.ptrs_of_mem (_ih h)) \/ mem2.[j]; List.memP a (IB.ptrs_of_mem (_ih h))}
let base = (IB.addrs_of_mem (_ih h)) a in
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==> mem1.[j] == mem2.[j]))
= let aux (a:b8{a =!= b /\ List.memP a (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let base = (IB.addrs_of_mem (_ih h)) a in
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall j.
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==>
mem1.[j] == mem2.[j]))
= let db = get_downview a.bsrc in
if DV.length db = 0 then ()
else
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = (IB.addrs_of_mem (_ih h)) a in
let s0 = DV.as_seq (IB.hs_of_mem (_ih h)) db in
let s1 = DV.as_seq (IB.hs_of_mem (_ih h1)) db in
opaque_assert (`%IB.list_disjoint_or_eq) IB.list_disjoint_or_eq IB.list_disjoint_or_eq_def (MB.disjoint a.bsrc b.bsrc);
lemma_dv_equal (IB.down_view a.src) a.bsrc (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1));
assert (Seq.equal s0 s1);
assert (forall (j:int).{:pattern (mem1.[j])}
base <= j /\ j < base + Seq.length s0 ==> v_to_typ TUInt8 (Seq.index s0 (j - base)) == mem1.[j]);
heap_shift mem1 mem2 base (DV.length db)
in
Classical.forall_intro aux
let store_buffer_down64_mem
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
forall (j:int). {:pattern mem1.[j] \/ mem2.[j]}
j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
let aux (j:int)
: Lemma
(j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j])
=
I.addrs_set_lemma_all ();
if j >= base && j < base + DV.length (get_downview b.bsrc) then begin
written_buffer_down64 b i v h;
length_t_eq (TUInt64) b
end
else if not (I.valid_addr (_ih h) j)
then I.same_unspecified_down (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1)) (IB.ptrs_of_mem (_ih h))
else unwritten_buffer_down TUInt64 b i v h
in
Classical.forall_intro aux
let store_buffer_aux_down64_mem (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
forall j. {:pattern mem1.[j] \/ mem2.[j]}
j < ptr \/ j >= ptr + 8 ==>
mem1.[j] == mem2.[j]))
= let t = TUInt64 in
let h1 = store_mem t ptr v h in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
store_buffer_write t ptr v h;
assert (buffer_addr b h + scale8 i == ptr);
assert (buffer_addr b h + scale8 (i+1) == ptr + 8);
store_buffer_down64_mem b i v h
let store_buffer_aux_down64_mem2 (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
S.get_heap_val64 ptr mem2 == v))
= let t = TUInt64 in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
let h1 = store_mem t ptr v h in
let mem2 = I.down_mem (_ih h1) in
store_buffer_write t ptr v h;
assert (Seq.index (buffer_as_seq h1 b) i == v);
index64_get_heap_val64 h1 b mem2 i
let in_bounds64 (h:vale_heap) (b:buffer64) (i:nat{i < buffer_length b})
: Lemma (scale8 i + 8 <= DV.length (get_downview b.bsrc))
=
length_t_eq TUInt64 b
let bytes_valid64 ptr h =
reveal_opaque (`%S.valid_addr64) S.valid_addr64;
let t = TUInt64 in
let b = get_addr_ptr t ptr h in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
in_bounds64 h b i;
I.addrs_set_mem (_ih h) b ptr;
I.addrs_set_mem (_ih h) b (ptr+1);
I.addrs_set_mem (_ih h) b (ptr+2);
I.addrs_set_mem (_ih h) b (ptr+3);
I.addrs_set_mem (_ih h) b (ptr+4);
I.addrs_set_mem (_ih h) b (ptr+5);
I.addrs_set_mem (_ih h) b (ptr+6);
I.addrs_set_mem (_ih h) b (ptr+7)
val same_mem_get_heap_val128 (b:buffer128)
(i:nat{i < buffer_length b})
(v:quad32)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1)) /\ buffer_writeable b})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale16 k in
forall i.{:pattern mem1.[i]} i >= ptr /\ i < ptr+16 ==> mem1.[i] == mem2.[i]))
val same_mem_eq_slices128 (b:buffer128)
(i:nat{i < buffer_length b})
(v:quad32)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1)) /\ buffer_writeable b})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 16 + 16 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 16) (k * 16 + 16) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 16) (k * 16 + 16)))
let same_mem_eq_slices128 b i v k h1 h2 mem1 mem2 =
let t = TUInt128 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up128 (b:buffer128) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 16}) : Lemma
(scale16 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint128_view in
UV.length_eq vb
let same_mem_get_heap_val128 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale16 k in
let addr = buffer_addr b h1 in
let aux (i:nat{ptr <= i /\ i < ptr+16}) : Lemma (mem1.[i] == mem2.[i]) =
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint128_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices128 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16) (k * 16 + 16)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16) (k * 16 + 16)) in
assert (Seq.index s1 (i - ptr) == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16 + (i-ptr)));
length_up128 b h1 k (i-ptr);
assert (mem1.[i] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16 + (i-ptr))));
assert (Seq.index s2 (i-ptr) == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16 + (i-ptr)));
length_up128 b h2 k (i-ptr);
assert (mem2.[addr+(scale16 k + (i-ptr))] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16 + (i-ptr))));
assert (forall i. addr + (scale16 k + (i-ptr)) == i)
in
Classical.forall_intro aux
let in_bounds128 (h:vale_heap) (b:buffer128) (i:nat{i < buffer_length b}) : Lemma
(scale16 i + 16 <= DV.length (get_downview b.bsrc))
=
length_t_eq TUInt128 b
#push-options "--z3rlimit 20"
#restart-solver
let bytes_valid128 ptr h =
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
IB.list_disjoint_or_eq_reveal ();
let t = TUInt128 in
let b = get_addr_ptr t ptr h in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
in_bounds128 h b i;
I.addrs_set_mem (_ih h) b ptr;
I.addrs_set_mem (_ih h) b (ptr+1);
I.addrs_set_mem (_ih h) b (ptr+2);
I.addrs_set_mem (_ih h) b (ptr+3);
I.addrs_set_mem (_ih h) b (ptr+4);
I.addrs_set_mem (_ih h) b (ptr+5);
I.addrs_set_mem (_ih h) b (ptr+6);
I.addrs_set_mem (_ih h) b (ptr+7);
I.addrs_set_mem (_ih h) b (ptr+8);
I.addrs_set_mem (_ih h) b (ptr+9);
I.addrs_set_mem (_ih h) b (ptr+10);
I.addrs_set_mem (_ih h) b (ptr+11);
I.addrs_set_mem (_ih h) b (ptr+12);
I.addrs_set_mem (_ih h) b (ptr+13);
I.addrs_set_mem (_ih h) b (ptr+14);
I.addrs_set_mem (_ih h) b (ptr+15)
#pop-options
let equiv_load_mem64 ptr h =
let t = TUInt64 in
let b = get_addr_ptr t ptr h in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
let addr = buffer_addr b h in
let contents = DV.as_seq (_ih h).IB.hs (get_downview b.bsrc) in
let heap = get_heap h in
index64_get_heap_val64 h b heap i;
lemma_load_mem64 b i h
//let low_lemma_valid_mem64 b i h =
// lemma_valid_mem64 b i h;
// bytes_valid64 (buffer_addr b h + scale8 i) h
//let low_lemma_load_mem64 b i h =
// lemma_valid_mem64 b i h;
// lemma_load_mem64 b i h;
// equiv_load_mem64 (buffer_addr b h + scale8 i) h
//let same_domain_update64 b i v h =
// low_lemma_valid_mem64 b i h;
// Vale.Arch.MachineHeap.same_domain_update64 (buffer_addr b h + scale8 i) v (get_heap h)
open Vale.X64.BufferViewStore
let low_lemma_store_mem64_aux
(b:buffer64)
(heap:S.machine_heap)
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{buffer_readable h b /\ buffer_writeable b})
: Lemma
(requires IB.correct_down_p (_ih h) heap b)
(ensures (let heap' = S.update_heap64 (buffer_addr b h + scale8 i) v heap in
let h' = store_mem64 (buffer_addr b h + scale8 i) v h in
(_ih h').IB.hs == DV.upd_seq (_ih h).IB.hs (get_downview b.bsrc) (I.get_seq_heap heap' (_ih h).IB.addrs b))) =
let ptr = buffer_addr b h + scale8 i in
let heap' = S.update_heap64 ptr v heap in
let h' = store_mem64 ptr v h in
lemma_store_mem64 b i v h;
length_t_eq TUInt64 b;
bv_upd_update_heap64 b heap i v (_ih h);
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db Vale.Interop.Views.up_view64 in
assert (UV.upd (_ih h).IB.hs bv i (UInt64.uint_to_t v) == (_ih h').IB.hs)
val valid_state_store_mem64_aux: (i:nat) -> (v:nat64) -> (h:vale_heap) -> Lemma
(requires writeable_mem64 i h)
(ensures (
let heap = get_heap h in
let heap' = S.update_heap64 i v heap in
let h' = store_mem64 i v h in
heap' == I.down_mem (_ih h')
)) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Memory.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.BufferViewStore.fsti.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Memory_Sems.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.BufferViewStore",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_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
}
] | {
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | i: Prims.nat -> v: Vale.Def.Words_s.nat64 -> h: Vale.Arch.HeapImpl.vale_heap
-> FStar.Pervasives.Lemma (requires Vale.X64.Memory.writeable_mem64 i h)
(ensures
(let heap = Vale.X64.Memory_Sems.get_heap h in
let heap' = Vale.Arch.MachineHeap_s.update_heap64 i v heap in
let h' = Vale.X64.Memory.store_mem64 i v h in
heap' == Vale.Interop.down_mem (Vale.Arch.HeapImpl._ih h'))) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.nat",
"Vale.Def.Words_s.nat64",
"Vale.Arch.HeapImpl.vale_heap",
"FStar.Map.lemma_equal_intro",
"Prims.int",
"Vale.Def.Types_s.nat8",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"FStar.Set.equal",
"FStar.Map.domain",
"Vale.Def.Words_s.nat8",
"Prims.Nil",
"FStar.Pervasives.pattern",
"Vale.Arch.MachineHeap.same_domain_update64",
"Vale.X64.Memory_Sems.bytes_valid64",
"Prims.l_Forall",
"Prims.eq2",
"FStar.Map.sel",
"Vale.Arch.MachineHeap.frame_update_heap64",
"Vale.Arch.MachineHeap.correct_update_get64",
"Vale.Arch.MachineHeap.same_mem_get_heap_val64",
"Vale.X64.Memory.op_String_Access",
"Vale.Arch.MachineHeap_s.machine_heap",
"Vale.Interop.Heap_s.correct_down",
"Vale.Arch.HeapImpl._ih",
"Vale.Interop.down_mem",
"Vale.X64.Memory_Sems.store_buffer_aux_down64_mem2",
"Vale.X64.Memory_Sems.store_buffer_aux_down64_mem",
"Vale.X64.Memory.store_mem",
"Vale.Arch.HeapTypes_s.TUInt64",
"Vale.Arch.MachineHeap_s.update_heap64",
"Vale.X64.Memory_Sems.same_domain",
"Vale.X64.Memory_Sems.get_heap"
] | [] | false | false | true | false | false | let valid_state_store_mem64_aux i v h =
| let heap = get_heap h in
let heap' = S.update_heap64 i v heap in
let h1 = store_mem TUInt64 i v h in
store_buffer_aux_down64_mem i v h;
store_buffer_aux_down64_mem2 i v h;
let mem1 = heap' in
let mem2 = I.down_mem (_ih h1) in
let aux () : Lemma (forall j. mem1.[ j ] == mem2.[ j ]) =
Vale.Arch.MachineHeap.same_mem_get_heap_val64 i mem1 mem2;
Vale.Arch.MachineHeap.correct_update_get64 i v heap;
Vale.Arch.MachineHeap.frame_update_heap64 i v heap
in
let aux2 () : Lemma (Set.equal (Map.domain mem1) (Map.domain mem2)) =
bytes_valid64 i h;
Vale.Arch.MachineHeap.same_domain_update64 i v heap
in
aux ();
aux2 ();
Map.lemma_equal_intro mem1 mem2 | false |
Vale.X64.Memory_Sems.fst | Vale.X64.Memory_Sems.same_mem_eq_slices128 | val same_mem_eq_slices128 (b:buffer128)
(i:nat{i < buffer_length b})
(v:quad32)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1)) /\ buffer_writeable b})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 16 + 16 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 16) (k * 16 + 16) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 16) (k * 16 + 16))) | val same_mem_eq_slices128 (b:buffer128)
(i:nat{i < buffer_length b})
(v:quad32)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1)) /\ buffer_writeable b})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 16 + 16 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 16) (k * 16 + 16) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 16) (k * 16 + 16))) | let same_mem_eq_slices128 b i v k h1 h2 mem1 mem2 =
let t = TUInt128 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory_Sems.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 19,
"end_line": 503,
"start_col": 0,
"start_line": 495
} | module Vale.X64.Memory_Sems
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.Def.Words_s
module I = Vale.Interop
module S = Vale.X64.Machine_Semantics_s
module MB = LowStar.Monotonic.Buffer
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
friend Vale.X64.Memory
module IB = Vale.Interop.Base
let same_domain h m = Set.equal (IB.addrs_set (_ih h)) (Map.domain m)
let lemma_same_domains h m1 m2 = ()
let get_heap h = I.down_mem (_ih h)
let upd_heap h m = mi_heap_upd h m
//let lemma_upd_get_heap h = I.down_up_identity (_ih h)
let lemma_get_upd_heap h m = I.up_down_identity (_ih h) m
let lemma_heap_impl = ()
let lemma_heap_get_heap h = ()
let lemma_heap_taint h = ()
//let lemma_heap_upd_heap h mh mt = ()
[@"opaque_to_smt"]
let rec set_of_range (a:int) (n:nat) : Pure (Set.set int)
(requires True)
(ensures fun s -> (forall (i:int).{:pattern Set.mem i s} Set.mem i s <==> a <= i /\ i < a + n))
=
if n = 0 then Set.empty else Set.union (set_of_range a (n - 1)) (Set.singleton (a + n - 1))
let buffer_info_has_addr (bi:buffer_info) (a:int) =
let b = bi.bi_buffer in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
addr <= a /\ a < addr + len
let buffer_info_has_addr_opt (bi:option buffer_info) (a:int) =
match bi with
| None -> False
| Some bi -> buffer_info_has_addr bi a
#set-options "--z3rlimit 100"
let rec make_owns_rec (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
if n = 0 then ((fun _ -> None), (fun _ -> Set.empty)) else
let (m0, s0) = make_owns_rec h bs (n - 1) in
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let s i = if i = hi then Set.union (s0 i) s_b else s0 i in
let m a = if addr <= a && a < addr + len then Some (n - 1) else m0 a in
(m, s)
[@"opaque_to_smt"]
let make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
make_owns_rec h bs n
let rec lemma_make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n <= Seq.length bs /\
(forall (i:nat).{:pattern Seq.index bs i} i < Seq.length bs ==> buffer_readable h (Seq.index bs i).bi_buffer) /\
(forall (i1 i2:nat).{:pattern (Seq.index bs i1); (Seq.index bs i2)}
i1 < Seq.length bs /\ i2 < Seq.length bs ==> buffer_info_disjoint (Seq.index bs i1) (Seq.index bs i2))
)
(ensures (
let (m, s) = make_owns h bs n in
(forall (i:heaplet_id) (a:int).{:pattern Set.mem a (s i)}
(Set.mem a (s i) <==> Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (m a) == Some i) /\
(Set.mem a (s i) ==> buffer_info_has_addr_opt (Option.mapTot (fun n -> Seq.index bs n) (m a)) a) /\
(Set.mem a (s i) ==> Set.mem a (Map.domain h.mh))
) /\
(forall (k:nat) (a:int).{:pattern Set.mem a (s (Seq.index bs k).bi_heaplet)}
k < n /\ buffer_info_has_addr (Seq.index bs k) a ==> Set.mem a (s (Seq.index bs k).bi_heaplet))
))
=
reveal_opaque (`%make_owns) make_owns;
if n = 0 then () else
let _ = make_owns h bs (n - 1) in
let (m, s) = make_owns h bs n in
lemma_make_owns h bs (n - 1);
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let lem1 (a:int) : Lemma
(requires Set.mem a s_b)
(ensures Set.mem a (Map.domain h.mh))
[SMTPat (Set.mem a (Map.domain h.mh))]
=
I.addrs_set_mem h.ih b a
in
let lem2 (i:heaplet_id) (a:int) : Lemma
(requires i =!= hi /\ Set.mem a (Set.intersect s_b (s i)))
(ensures False)
[SMTPat (Set.mem a (s i))]
=
reveal_opaque (`%addr_map_pred) addr_map_pred
in
()
#push-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_loc_mutable_buffers_rec (l:list buffer_info) (s:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n + List.length l == Seq.length s /\
list_to_seq_post l s n
)
(ensures (
let modloc = loc_mutable_buffers l in
forall (i:nat).{:pattern Seq.index s i} n <= i /\ i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes modloc (loc_buffer bi.bi_buffer))
))
(decreases l)
=
match l with
| [] -> ()
| h::t -> lemma_loc_mutable_buffers_rec t s (n + 1)
#pop-options
let lemma_loc_mutable_buffers (l:list buffer_info) : Lemma
(ensures (
let s = list_to_seq l in
forall (i:nat).{:pattern Seq.index s i} i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes (loc_mutable_buffers l) (loc_buffer bi.bi_buffer))
))
=
lemma_list_to_seq l;
lemma_loc_mutable_buffers_rec l (list_to_seq l) 0
let create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let modloc = loc_mutable_buffers buffers in
let layout1 = h1.vf_layout in
let layin1 = layout1.vl_inner in
let (hmap, hsets) = make_owns h1.vf_heap bs (Seq.length bs) in
let hmap a = Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (hmap a) in
let l = {
vl_heaplets_initialized = true;
vl_heaplet_map = hmap;
vl_heaplet_sets = hsets;
vl_old_heap = h1.vf_heap;
vl_buffers = bs;
vl_mod_loc = modloc;
} in
let layout2 = {layout1 with vl_inner = l} in
let h2 = {
vf_layout = layout2;
vf_heap = h1.vf_heap;
vf_heaplets = h1.vf_heaplets;
} in
h2
let lemma_create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let h2 = create_heaplets buffers h1 in
assert (h2.vf_layout.vl_inner.vl_buffers == bs); // REVIEW: why is this necessary, even with extra ifuel?
lemma_make_owns h1.vf_heap bs (Seq.length bs);
lemma_loc_mutable_buffers buffers;
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
let destroy_heaplets h1 =
h1
let lemma_destroy_heaplets h1 =
()
val heap_shift (m1 m2:S.machine_heap) (base:int) (n:nat) : Lemma
(requires (forall i. 0 <= i /\ i < n ==> m1.[base + i] == m2.[base + i]))
(ensures (forall i. {:pattern (m1.[i])} base <= i /\ i < base + n ==> m1.[i] == m2.[i]))
#push-options "--smtencoding.l_arith_repr boxwrap"
let heap_shift m1 m2 base n =
assert (forall i. base <= i /\ i < base + n ==>
m1.[base + (i - base)] == m2.[base + (i - base)])
#pop-options
val same_mem_eq_slices64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 8 + 8 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8)))
let same_mem_eq_slices64 b i v k h1 h2 mem1 mem2 =
let t = TUInt64 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up64 (b:buffer64) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 8}) : Lemma
(scale8 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint64_view in
UV.length_eq vb
val same_mem_get_heap_val64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale8 k in
forall (x:int).{:pattern (mem1.[x])} ptr <= x /\ x < ptr + 8 ==> mem1.[x] == mem2.[x]))
let same_mem_get_heap_val64 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale8 k in
let addr = buffer_addr b h1 in
let aux (x:int{ptr <= x /\ x < ptr + 8}) : Lemma (mem1.[x] == mem2.[x]) =
let i = x - ptr in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices64 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8) (k * 8 + 8)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8) (k * 8 + 8)) in
assert (Seq.index s1 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i));
length_up64 b h1 k i;
assert (mem1.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i)));
assert (Seq.index s2 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i));
length_up64 b h2 k i;
assert (mem2.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i)))
in
Classical.forall_intro aux;
assert (forall i. addr + (scale8 k + i) == ptr + i)
let rec written_buffer_down64_aux1
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(k:nat) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j.{:pattern (mem1.[j]) \/ (mem2.[j])}
base <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem1.[j])}
j >= base /\ j < base + scale8 i ==>
mem1.[j] == mem2.[j]))
(decreases %[i-k]) =
if k >= i then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux1 b i v h base (k+1) h1 mem1 mem2
end
let rec written_buffer_down64_aux2
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(n:nat{n == buffer_length b})
(k:nat{k > i}) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
base + scale8 (i+1) <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
j >= base + scale8 (i+1) /\ j < base + scale8 n ==>
mem1.[j] == mem2.[j]))
(decreases %[n-k]) =
if k >= n then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux2 b i v h base n (k+1) h1 mem1 mem2
end
let written_buffer_down64 (b:buffer64{buffer_writeable b}) (i:nat{i < buffer_length b}) (v:nat64) (h:vale_heap)
: Lemma
(requires List.memP b (IB.ptrs_of_mem (_ih h)))
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
(base <= j /\ j < base + scale8 i) \/
(base + scale8 (i+1) <= j /\ j < base + scale8 n) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
written_buffer_down64_aux1 b i v h base 0 h1 mem1 mem2;
written_buffer_down64_aux2 b i v h base n (i+1) h1 mem1 mem2
let unwritten_buffer_down (t:base_typ) (b:buffer t{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:base_typ_as_vale_type t)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall (a:b8{List.memP a (IB.ptrs_of_mem (_ih h)) /\ a =!= b}) j. {:pattern mem1.[j]; List.memP a (IB.ptrs_of_mem (_ih h)) \/ mem2.[j]; List.memP a (IB.ptrs_of_mem (_ih h))}
let base = (IB.addrs_of_mem (_ih h)) a in
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==> mem1.[j] == mem2.[j]))
= let aux (a:b8{a =!= b /\ List.memP a (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let base = (IB.addrs_of_mem (_ih h)) a in
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall j.
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==>
mem1.[j] == mem2.[j]))
= let db = get_downview a.bsrc in
if DV.length db = 0 then ()
else
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = (IB.addrs_of_mem (_ih h)) a in
let s0 = DV.as_seq (IB.hs_of_mem (_ih h)) db in
let s1 = DV.as_seq (IB.hs_of_mem (_ih h1)) db in
opaque_assert (`%IB.list_disjoint_or_eq) IB.list_disjoint_or_eq IB.list_disjoint_or_eq_def (MB.disjoint a.bsrc b.bsrc);
lemma_dv_equal (IB.down_view a.src) a.bsrc (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1));
assert (Seq.equal s0 s1);
assert (forall (j:int).{:pattern (mem1.[j])}
base <= j /\ j < base + Seq.length s0 ==> v_to_typ TUInt8 (Seq.index s0 (j - base)) == mem1.[j]);
heap_shift mem1 mem2 base (DV.length db)
in
Classical.forall_intro aux
let store_buffer_down64_mem
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
forall (j:int). {:pattern mem1.[j] \/ mem2.[j]}
j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
let aux (j:int)
: Lemma
(j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j])
=
I.addrs_set_lemma_all ();
if j >= base && j < base + DV.length (get_downview b.bsrc) then begin
written_buffer_down64 b i v h;
length_t_eq (TUInt64) b
end
else if not (I.valid_addr (_ih h) j)
then I.same_unspecified_down (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1)) (IB.ptrs_of_mem (_ih h))
else unwritten_buffer_down TUInt64 b i v h
in
Classical.forall_intro aux
let store_buffer_aux_down64_mem (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
forall j. {:pattern mem1.[j] \/ mem2.[j]}
j < ptr \/ j >= ptr + 8 ==>
mem1.[j] == mem2.[j]))
= let t = TUInt64 in
let h1 = store_mem t ptr v h in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
store_buffer_write t ptr v h;
assert (buffer_addr b h + scale8 i == ptr);
assert (buffer_addr b h + scale8 (i+1) == ptr + 8);
store_buffer_down64_mem b i v h
let store_buffer_aux_down64_mem2 (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
S.get_heap_val64 ptr mem2 == v))
= let t = TUInt64 in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
let h1 = store_mem t ptr v h in
let mem2 = I.down_mem (_ih h1) in
store_buffer_write t ptr v h;
assert (Seq.index (buffer_as_seq h1 b) i == v);
index64_get_heap_val64 h1 b mem2 i
let in_bounds64 (h:vale_heap) (b:buffer64) (i:nat{i < buffer_length b})
: Lemma (scale8 i + 8 <= DV.length (get_downview b.bsrc))
=
length_t_eq TUInt64 b
let bytes_valid64 ptr h =
reveal_opaque (`%S.valid_addr64) S.valid_addr64;
let t = TUInt64 in
let b = get_addr_ptr t ptr h in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
in_bounds64 h b i;
I.addrs_set_mem (_ih h) b ptr;
I.addrs_set_mem (_ih h) b (ptr+1);
I.addrs_set_mem (_ih h) b (ptr+2);
I.addrs_set_mem (_ih h) b (ptr+3);
I.addrs_set_mem (_ih h) b (ptr+4);
I.addrs_set_mem (_ih h) b (ptr+5);
I.addrs_set_mem (_ih h) b (ptr+6);
I.addrs_set_mem (_ih h) b (ptr+7)
val same_mem_get_heap_val128 (b:buffer128)
(i:nat{i < buffer_length b})
(v:quad32)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1)) /\ buffer_writeable b})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale16 k in
forall i.{:pattern mem1.[i]} i >= ptr /\ i < ptr+16 ==> mem1.[i] == mem2.[i]))
val same_mem_eq_slices128 (b:buffer128)
(i:nat{i < buffer_length b})
(v:quad32)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1)) /\ buffer_writeable b})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 16 + 16 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 16) (k * 16 + 16) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 16) (k * 16 + 16))) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Memory.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.BufferViewStore.fsti.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Memory_Sems.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_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
}
] | {
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
b: Vale.X64.Memory.buffer128 ->
i: Prims.nat{i < Vale.X64.Memory.buffer_length b} ->
v: Vale.X64.Memory.quad32 ->
k: Prims.nat{k < Vale.X64.Memory.buffer_length b} ->
h1:
Vale.Arch.HeapImpl.vale_heap
{ FStar.List.Tot.Base.memP b (Vale.Interop.Heap_s.ptrs_of_mem (Vale.Arch.HeapImpl._ih h1)) /\
Vale.X64.Memory.buffer_writeable b } ->
h2: Vale.Arch.HeapImpl.vale_heap{h2 == Vale.X64.Memory.buffer_write b i v h1} ->
mem1:
Vale.Arch.MachineHeap_s.machine_heap
{Vale.Interop.Heap_s.correct_down_p (Vale.Arch.HeapImpl._ih h1) mem1 b} ->
mem2:
Vale.Arch.MachineHeap_s.machine_heap
{Vale.Interop.Heap_s.correct_down_p (Vale.Arch.HeapImpl._ih h2) mem2 b}
-> FStar.Pervasives.Lemma
(requires
FStar.Seq.Base.index (Vale.X64.Memory.buffer_as_seq h1 b) k ==
FStar.Seq.Base.index (Vale.X64.Memory.buffer_as_seq h2 b) k)
(ensures
k * 16 + 16 <=
LowStar.BufferView.Down.length (Vale.Interop.Types.get_downview (Buffer?.bsrc b)) /\
FStar.Seq.Base.slice (LowStar.BufferView.Down.as_seq (Vale.Interop.Heap_s.hs_of_mem (Vale.Arch.HeapImpl._ih
h1))
(Vale.Interop.Types.get_downview (Buffer?.bsrc b)))
(k * 16)
(k * 16 + 16) ==
FStar.Seq.Base.slice (LowStar.BufferView.Down.as_seq (Vale.Interop.Heap_s.hs_of_mem (Vale.Arch.HeapImpl._ih
h2))
(Vale.Interop.Types.get_downview (Buffer?.bsrc b)))
(k * 16)
(k * 16 + 16)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.X64.Memory.buffer128",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Vale.X64.Memory.buffer_length",
"Vale.X64.Memory.vuint128",
"Vale.X64.Memory.quad32",
"Vale.Arch.HeapImpl.vale_heap",
"Prims.l_and",
"FStar.List.Tot.Base.memP",
"Vale.Interop.Types.b8",
"Vale.Interop.Heap_s.ptrs_of_mem",
"Vale.Arch.HeapImpl._ih",
"Vale.X64.Memory.buffer_writeable",
"Prims.eq2",
"Vale.X64.Memory.buffer_write",
"Vale.Arch.MachineHeap_s.machine_heap",
"Vale.Interop.Heap_s.correct_down_p",
"LowStar.BufferView.Up.length_eq",
"Vale.Interop.Types.base_typ_as_type",
"Prims.unit",
"LowStar.BufferView.Up.put_sel",
"Vale.Interop.Heap_s.hs_of_mem",
"LowStar.BufferView.Up.as_seq_sel",
"LowStar.BufferView.Up.buffer",
"LowStar.BufferView.Up.mk_buffer",
"FStar.UInt8.t",
"Vale.X64.Memory.uint_view",
"LowStar.BufferView.Down.buffer",
"Vale.Interop.Types.get_downview",
"Vale.Interop.Types.__proj__Buffer__item__src",
"Vale.Interop.Types.b8_preorder",
"Vale.Interop.Types.__proj__Buffer__item__writeable",
"Vale.Interop.Types.__proj__Buffer__item__bsrc",
"Vale.Arch.HeapTypes_s.base_typ",
"Vale.Arch.HeapTypes_s.TUInt128"
] | [] | true | false | true | false | false | let same_mem_eq_slices128 b i v k h1 h2 mem1 mem2 =
| let t = TUInt128 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub | false |
Vale.X64.Memory_Sems.fst | Vale.X64.Memory_Sems.lemma_make_owns | val lemma_make_owns (h: vale_heap) (bs: Seq.seq buffer_info) (n: nat)
: Lemma
(requires
n <= Seq.length bs /\
(forall (i: nat). {:pattern Seq.index bs i}
i < Seq.length bs ==> buffer_readable h (Seq.index bs i).bi_buffer) /\
(forall (i1: nat) (i2: nat). {:pattern (Seq.index bs i1); (Seq.index bs i2)}
i1 < Seq.length bs /\ i2 < Seq.length bs ==>
buffer_info_disjoint (Seq.index bs i1) (Seq.index bs i2)))
(ensures
(let m, s = make_owns h bs n in
(forall (i: heaplet_id) (a: int). {:pattern Set.mem a (s i)}
(Set.mem a (s i) <==>
Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (m a) == Some i) /\
(Set.mem a (s i) ==>
buffer_info_has_addr_opt (Option.mapTot (fun n -> Seq.index bs n) (m a)) a) /\
(Set.mem a (s i) ==> Set.mem a (Map.domain h.mh))) /\
(forall (k: nat) (a: int). {:pattern Set.mem a (s (Seq.index bs k).bi_heaplet)}
k < n /\ buffer_info_has_addr (Seq.index bs k) a ==>
Set.mem a (s (Seq.index bs k).bi_heaplet)))) | val lemma_make_owns (h: vale_heap) (bs: Seq.seq buffer_info) (n: nat)
: Lemma
(requires
n <= Seq.length bs /\
(forall (i: nat). {:pattern Seq.index bs i}
i < Seq.length bs ==> buffer_readable h (Seq.index bs i).bi_buffer) /\
(forall (i1: nat) (i2: nat). {:pattern (Seq.index bs i1); (Seq.index bs i2)}
i1 < Seq.length bs /\ i2 < Seq.length bs ==>
buffer_info_disjoint (Seq.index bs i1) (Seq.index bs i2)))
(ensures
(let m, s = make_owns h bs n in
(forall (i: heaplet_id) (a: int). {:pattern Set.mem a (s i)}
(Set.mem a (s i) <==>
Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (m a) == Some i) /\
(Set.mem a (s i) ==>
buffer_info_has_addr_opt (Option.mapTot (fun n -> Seq.index bs n) (m a)) a) /\
(Set.mem a (s i) ==> Set.mem a (Map.domain h.mh))) /\
(forall (k: nat) (a: int). {:pattern Set.mem a (s (Seq.index bs k).bi_heaplet)}
k < n /\ buffer_info_has_addr (Seq.index bs k) a ==>
Set.mem a (s (Seq.index bs k).bi_heaplet)))) | let rec lemma_make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n <= Seq.length bs /\
(forall (i:nat).{:pattern Seq.index bs i} i < Seq.length bs ==> buffer_readable h (Seq.index bs i).bi_buffer) /\
(forall (i1 i2:nat).{:pattern (Seq.index bs i1); (Seq.index bs i2)}
i1 < Seq.length bs /\ i2 < Seq.length bs ==> buffer_info_disjoint (Seq.index bs i1) (Seq.index bs i2))
)
(ensures (
let (m, s) = make_owns h bs n in
(forall (i:heaplet_id) (a:int).{:pattern Set.mem a (s i)}
(Set.mem a (s i) <==> Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (m a) == Some i) /\
(Set.mem a (s i) ==> buffer_info_has_addr_opt (Option.mapTot (fun n -> Seq.index bs n) (m a)) a) /\
(Set.mem a (s i) ==> Set.mem a (Map.domain h.mh))
) /\
(forall (k:nat) (a:int).{:pattern Set.mem a (s (Seq.index bs k).bi_heaplet)}
k < n /\ buffer_info_has_addr (Seq.index bs k) a ==> Set.mem a (s (Seq.index bs k).bi_heaplet))
))
=
reveal_opaque (`%make_owns) make_owns;
if n = 0 then () else
let _ = make_owns h bs (n - 1) in
let (m, s) = make_owns h bs n in
lemma_make_owns h bs (n - 1);
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let lem1 (a:int) : Lemma
(requires Set.mem a s_b)
(ensures Set.mem a (Map.domain h.mh))
[SMTPat (Set.mem a (Map.domain h.mh))]
=
I.addrs_set_mem h.ih b a
in
let lem2 (i:heaplet_id) (a:int) : Lemma
(requires i =!= hi /\ Set.mem a (Set.intersect s_b (s i)))
(ensures False)
[SMTPat (Set.mem a (s i))]
=
reveal_opaque (`%addr_map_pred) addr_map_pred
in
() | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory_Sems.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 4,
"end_line": 124,
"start_col": 0,
"start_line": 81
} | module Vale.X64.Memory_Sems
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.Def.Words_s
module I = Vale.Interop
module S = Vale.X64.Machine_Semantics_s
module MB = LowStar.Monotonic.Buffer
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
friend Vale.X64.Memory
module IB = Vale.Interop.Base
let same_domain h m = Set.equal (IB.addrs_set (_ih h)) (Map.domain m)
let lemma_same_domains h m1 m2 = ()
let get_heap h = I.down_mem (_ih h)
let upd_heap h m = mi_heap_upd h m
//let lemma_upd_get_heap h = I.down_up_identity (_ih h)
let lemma_get_upd_heap h m = I.up_down_identity (_ih h) m
let lemma_heap_impl = ()
let lemma_heap_get_heap h = ()
let lemma_heap_taint h = ()
//let lemma_heap_upd_heap h mh mt = ()
[@"opaque_to_smt"]
let rec set_of_range (a:int) (n:nat) : Pure (Set.set int)
(requires True)
(ensures fun s -> (forall (i:int).{:pattern Set.mem i s} Set.mem i s <==> a <= i /\ i < a + n))
=
if n = 0 then Set.empty else Set.union (set_of_range a (n - 1)) (Set.singleton (a + n - 1))
let buffer_info_has_addr (bi:buffer_info) (a:int) =
let b = bi.bi_buffer in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
addr <= a /\ a < addr + len
let buffer_info_has_addr_opt (bi:option buffer_info) (a:int) =
match bi with
| None -> False
| Some bi -> buffer_info_has_addr bi a
#set-options "--z3rlimit 100"
let rec make_owns_rec (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
if n = 0 then ((fun _ -> None), (fun _ -> Set.empty)) else
let (m0, s0) = make_owns_rec h bs (n - 1) in
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let s i = if i = hi then Set.union (s0 i) s_b else s0 i in
let m a = if addr <= a && a < addr + len then Some (n - 1) else m0 a in
(m, s)
[@"opaque_to_smt"]
let make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
make_owns_rec h bs n | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Memory.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.BufferViewStore.fsti.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Memory_Sems.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_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
}
] | {
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
h: Vale.Arch.HeapImpl.vale_heap ->
bs: FStar.Seq.Base.seq Vale.Arch.HeapImpl.buffer_info ->
n: Prims.nat
-> FStar.Pervasives.Lemma
(requires
n <= FStar.Seq.Base.length bs /\
(forall (i: Prims.nat). {:pattern FStar.Seq.Base.index bs i}
i < FStar.Seq.Base.length bs ==>
Vale.X64.Memory.buffer_readable h (Mkbuffer_info?.bi_buffer (FStar.Seq.Base.index bs i))
) /\
(forall (i1: Prims.nat) (i2: Prims.nat).
{:pattern FStar.Seq.Base.index bs i1; FStar.Seq.Base.index bs i2}
i1 < FStar.Seq.Base.length bs /\ i2 < FStar.Seq.Base.length bs ==>
Vale.X64.Memory.buffer_info_disjoint (FStar.Seq.Base.index bs i1)
(FStar.Seq.Base.index bs i2)))
(ensures
(let _ = Vale.X64.Memory_Sems.make_owns h bs n in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ m s = _ in
(forall (i: Vale.Arch.HeapImpl.heaplet_id) (a: Prims.int).
{:pattern FStar.Set.mem a (s i)}
(FStar.Set.mem a (s i) <==>
FStar.Option.mapTot (fun n ->
Mkbuffer_info?.bi_heaplet (FStar.Seq.Base.index bs n))
(m a) ==
FStar.Pervasives.Native.Some i) /\
(FStar.Set.mem a (s i) ==>
Vale.X64.Memory_Sems.buffer_info_has_addr_opt (FStar.Option.mapTot (fun n ->
FStar.Seq.Base.index bs n)
(m a))
a) /\
(FStar.Set.mem a (s i) ==> FStar.Set.mem a (FStar.Map.domain (ValeHeap?.mh h)))) /\
(forall (k: Prims.nat) (a: Prims.int).
{:pattern
FStar.Set.mem a (s (Mkbuffer_info?.bi_heaplet (FStar.Seq.Base.index bs k)))}
k < n /\ Vale.X64.Memory_Sems.buffer_info_has_addr (FStar.Seq.Base.index bs k) a ==>
FStar.Set.mem a (s (Mkbuffer_info?.bi_heaplet (FStar.Seq.Base.index bs k)))))
<:
Type0)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Arch.HeapImpl.vale_heap",
"FStar.Seq.Base.seq",
"Vale.Arch.HeapImpl.buffer_info",
"Prims.nat",
"Prims.op_Equality",
"Prims.int",
"Prims.bool",
"FStar.Pervasives.Native.option",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Seq.Base.length",
"Vale.Arch.HeapImpl.heaplet_id",
"FStar.Set.set",
"Prims.unit",
"Prims.l_and",
"Prims.l_not",
"Prims.eq2",
"FStar.Set.mem",
"FStar.Set.intersect",
"Prims.squash",
"Prims.l_False",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"Prims.Nil",
"FStar.Pervasives.reveal_opaque",
"Vale.Interop.Types.b8",
"Vale.Def.Words_s.nat64",
"Prims.logical",
"Vale.Interop.Types.addr_map_pred",
"FStar.Map.domain",
"Vale.Def.Words_s.nat8",
"Vale.Arch.HeapImpl.__proj__ValeHeap__item__mh",
"Vale.Interop.addrs_set_mem",
"FStar.Ghost.reveal",
"Vale.Interop.Heap_s.interop_heap",
"Vale.Arch.HeapImpl.__proj__ValeHeap__item__ih",
"Vale.Def.Types_s.nat8",
"Vale.X64.Memory_Sems.set_of_range",
"LowStar.BufferView.Down.length",
"FStar.UInt8.t",
"Vale.Interop.Types.get_downview",
"Vale.Interop.Types.__proj__Buffer__item__src",
"Vale.Interop.Types.b8_preorder",
"Vale.Interop.Types.__proj__Buffer__item__writeable",
"Vale.Interop.Types.base_typ_as_type",
"Vale.Interop.Types.__proj__Buffer__item__bsrc",
"Vale.Interop.Heap_s.global_addrs_map",
"Vale.Arch.HeapImpl.__proj__Mkbuffer_info__item__bi_heaplet",
"Vale.Arch.HeapImpl.buffer",
"Vale.Arch.HeapImpl.__proj__Mkbuffer_info__item__bi_typ",
"Vale.Arch.HeapImpl.__proj__Mkbuffer_info__item__bi_buffer",
"FStar.Seq.Base.index",
"Prims.op_Subtraction",
"Vale.X64.Memory_Sems.lemma_make_owns",
"FStar.Pervasives.Native.tuple2",
"Vale.X64.Memory_Sems.make_owns",
"Prims.op_LessThanOrEqual",
"Prims.l_Forall",
"Prims.l_imp",
"Vale.X64.Memory.buffer_readable",
"Vale.X64.Memory.buffer_info_disjoint",
"Prims.l_iff",
"FStar.Option.mapTot",
"FStar.Pervasives.Native.Some",
"Vale.X64.Memory_Sems.buffer_info_has_addr_opt",
"Vale.X64.Memory_Sems.buffer_info_has_addr"
] | [
"recursion"
] | false | false | true | false | false | let rec lemma_make_owns (h: vale_heap) (bs: Seq.seq buffer_info) (n: nat)
: Lemma
(requires
n <= Seq.length bs /\
(forall (i: nat). {:pattern Seq.index bs i}
i < Seq.length bs ==> buffer_readable h (Seq.index bs i).bi_buffer) /\
(forall (i1: nat) (i2: nat). {:pattern (Seq.index bs i1); (Seq.index bs i2)}
i1 < Seq.length bs /\ i2 < Seq.length bs ==>
buffer_info_disjoint (Seq.index bs i1) (Seq.index bs i2)))
(ensures
(let m, s = make_owns h bs n in
(forall (i: heaplet_id) (a: int). {:pattern Set.mem a (s i)}
(Set.mem a (s i) <==>
Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (m a) == Some i) /\
(Set.mem a (s i) ==>
buffer_info_has_addr_opt (Option.mapTot (fun n -> Seq.index bs n) (m a)) a) /\
(Set.mem a (s i) ==> Set.mem a (Map.domain h.mh))) /\
(forall (k: nat) (a: int). {:pattern Set.mem a (s (Seq.index bs k).bi_heaplet)}
k < n /\ buffer_info_has_addr (Seq.index bs k) a ==>
Set.mem a (s (Seq.index bs k).bi_heaplet)))) =
| reveal_opaque (`%make_owns) make_owns;
if n = 0
then ()
else
let _ = make_owns h bs (n - 1) in
let m, s = make_owns h bs n in
lemma_make_owns h bs (n - 1);
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let lem1 (a: int)
: Lemma (requires Set.mem a s_b)
(ensures Set.mem a (Map.domain h.mh))
[SMTPat (Set.mem a (Map.domain h.mh))] =
I.addrs_set_mem h.ih b a
in
let lem2 (i: heaplet_id) (a: int)
: Lemma (requires i =!= hi /\ Set.mem a (Set.intersect s_b (s i)))
(ensures False)
[SMTPat (Set.mem a (s i))] =
reveal_opaque (`%addr_map_pred) addr_map_pred
in
() | false |
Vale.X64.Memory_Sems.fst | Vale.X64.Memory_Sems.equiv_load_mem128_aux | val equiv_load_mem128_aux: (ptr:int) -> (h:vale_heap) -> Lemma
(requires valid_mem128 ptr h)
(ensures load_mem128 ptr h == S.get_heap_val128 ptr (get_heap h)) | val equiv_load_mem128_aux: (ptr:int) -> (h:vale_heap) -> Lemma
(requires valid_mem128 ptr h)
(ensures load_mem128 ptr h == S.get_heap_val128 ptr (get_heap h)) | let equiv_load_mem128_aux ptr h =
let t = TUInt128 in
let b = get_addr_ptr t ptr h in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
let addr = buffer_addr b h in
let contents = DV.as_seq (_ih h).IB.hs (get_downview b.bsrc) in
let heap = get_heap h in
S.get_heap_val128_reveal ();
index128_get_heap_val128 h b heap i;
lemma_load_mem128 b i h | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory_Sems.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 25,
"end_line": 750,
"start_col": 0,
"start_line": 741
} | module Vale.X64.Memory_Sems
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.Def.Words_s
module I = Vale.Interop
module S = Vale.X64.Machine_Semantics_s
module MB = LowStar.Monotonic.Buffer
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
friend Vale.X64.Memory
module IB = Vale.Interop.Base
let same_domain h m = Set.equal (IB.addrs_set (_ih h)) (Map.domain m)
let lemma_same_domains h m1 m2 = ()
let get_heap h = I.down_mem (_ih h)
let upd_heap h m = mi_heap_upd h m
//let lemma_upd_get_heap h = I.down_up_identity (_ih h)
let lemma_get_upd_heap h m = I.up_down_identity (_ih h) m
let lemma_heap_impl = ()
let lemma_heap_get_heap h = ()
let lemma_heap_taint h = ()
//let lemma_heap_upd_heap h mh mt = ()
[@"opaque_to_smt"]
let rec set_of_range (a:int) (n:nat) : Pure (Set.set int)
(requires True)
(ensures fun s -> (forall (i:int).{:pattern Set.mem i s} Set.mem i s <==> a <= i /\ i < a + n))
=
if n = 0 then Set.empty else Set.union (set_of_range a (n - 1)) (Set.singleton (a + n - 1))
let buffer_info_has_addr (bi:buffer_info) (a:int) =
let b = bi.bi_buffer in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
addr <= a /\ a < addr + len
let buffer_info_has_addr_opt (bi:option buffer_info) (a:int) =
match bi with
| None -> False
| Some bi -> buffer_info_has_addr bi a
#set-options "--z3rlimit 100"
let rec make_owns_rec (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
if n = 0 then ((fun _ -> None), (fun _ -> Set.empty)) else
let (m0, s0) = make_owns_rec h bs (n - 1) in
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let s i = if i = hi then Set.union (s0 i) s_b else s0 i in
let m a = if addr <= a && a < addr + len then Some (n - 1) else m0 a in
(m, s)
[@"opaque_to_smt"]
let make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
make_owns_rec h bs n
let rec lemma_make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n <= Seq.length bs /\
(forall (i:nat).{:pattern Seq.index bs i} i < Seq.length bs ==> buffer_readable h (Seq.index bs i).bi_buffer) /\
(forall (i1 i2:nat).{:pattern (Seq.index bs i1); (Seq.index bs i2)}
i1 < Seq.length bs /\ i2 < Seq.length bs ==> buffer_info_disjoint (Seq.index bs i1) (Seq.index bs i2))
)
(ensures (
let (m, s) = make_owns h bs n in
(forall (i:heaplet_id) (a:int).{:pattern Set.mem a (s i)}
(Set.mem a (s i) <==> Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (m a) == Some i) /\
(Set.mem a (s i) ==> buffer_info_has_addr_opt (Option.mapTot (fun n -> Seq.index bs n) (m a)) a) /\
(Set.mem a (s i) ==> Set.mem a (Map.domain h.mh))
) /\
(forall (k:nat) (a:int).{:pattern Set.mem a (s (Seq.index bs k).bi_heaplet)}
k < n /\ buffer_info_has_addr (Seq.index bs k) a ==> Set.mem a (s (Seq.index bs k).bi_heaplet))
))
=
reveal_opaque (`%make_owns) make_owns;
if n = 0 then () else
let _ = make_owns h bs (n - 1) in
let (m, s) = make_owns h bs n in
lemma_make_owns h bs (n - 1);
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let lem1 (a:int) : Lemma
(requires Set.mem a s_b)
(ensures Set.mem a (Map.domain h.mh))
[SMTPat (Set.mem a (Map.domain h.mh))]
=
I.addrs_set_mem h.ih b a
in
let lem2 (i:heaplet_id) (a:int) : Lemma
(requires i =!= hi /\ Set.mem a (Set.intersect s_b (s i)))
(ensures False)
[SMTPat (Set.mem a (s i))]
=
reveal_opaque (`%addr_map_pred) addr_map_pred
in
()
#push-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_loc_mutable_buffers_rec (l:list buffer_info) (s:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n + List.length l == Seq.length s /\
list_to_seq_post l s n
)
(ensures (
let modloc = loc_mutable_buffers l in
forall (i:nat).{:pattern Seq.index s i} n <= i /\ i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes modloc (loc_buffer bi.bi_buffer))
))
(decreases l)
=
match l with
| [] -> ()
| h::t -> lemma_loc_mutable_buffers_rec t s (n + 1)
#pop-options
let lemma_loc_mutable_buffers (l:list buffer_info) : Lemma
(ensures (
let s = list_to_seq l in
forall (i:nat).{:pattern Seq.index s i} i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes (loc_mutable_buffers l) (loc_buffer bi.bi_buffer))
))
=
lemma_list_to_seq l;
lemma_loc_mutable_buffers_rec l (list_to_seq l) 0
let create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let modloc = loc_mutable_buffers buffers in
let layout1 = h1.vf_layout in
let layin1 = layout1.vl_inner in
let (hmap, hsets) = make_owns h1.vf_heap bs (Seq.length bs) in
let hmap a = Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (hmap a) in
let l = {
vl_heaplets_initialized = true;
vl_heaplet_map = hmap;
vl_heaplet_sets = hsets;
vl_old_heap = h1.vf_heap;
vl_buffers = bs;
vl_mod_loc = modloc;
} in
let layout2 = {layout1 with vl_inner = l} in
let h2 = {
vf_layout = layout2;
vf_heap = h1.vf_heap;
vf_heaplets = h1.vf_heaplets;
} in
h2
let lemma_create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let h2 = create_heaplets buffers h1 in
assert (h2.vf_layout.vl_inner.vl_buffers == bs); // REVIEW: why is this necessary, even with extra ifuel?
lemma_make_owns h1.vf_heap bs (Seq.length bs);
lemma_loc_mutable_buffers buffers;
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
let destroy_heaplets h1 =
h1
let lemma_destroy_heaplets h1 =
()
val heap_shift (m1 m2:S.machine_heap) (base:int) (n:nat) : Lemma
(requires (forall i. 0 <= i /\ i < n ==> m1.[base + i] == m2.[base + i]))
(ensures (forall i. {:pattern (m1.[i])} base <= i /\ i < base + n ==> m1.[i] == m2.[i]))
#push-options "--smtencoding.l_arith_repr boxwrap"
let heap_shift m1 m2 base n =
assert (forall i. base <= i /\ i < base + n ==>
m1.[base + (i - base)] == m2.[base + (i - base)])
#pop-options
val same_mem_eq_slices64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 8 + 8 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8)))
let same_mem_eq_slices64 b i v k h1 h2 mem1 mem2 =
let t = TUInt64 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up64 (b:buffer64) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 8}) : Lemma
(scale8 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint64_view in
UV.length_eq vb
val same_mem_get_heap_val64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale8 k in
forall (x:int).{:pattern (mem1.[x])} ptr <= x /\ x < ptr + 8 ==> mem1.[x] == mem2.[x]))
let same_mem_get_heap_val64 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale8 k in
let addr = buffer_addr b h1 in
let aux (x:int{ptr <= x /\ x < ptr + 8}) : Lemma (mem1.[x] == mem2.[x]) =
let i = x - ptr in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices64 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8) (k * 8 + 8)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8) (k * 8 + 8)) in
assert (Seq.index s1 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i));
length_up64 b h1 k i;
assert (mem1.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i)));
assert (Seq.index s2 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i));
length_up64 b h2 k i;
assert (mem2.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i)))
in
Classical.forall_intro aux;
assert (forall i. addr + (scale8 k + i) == ptr + i)
let rec written_buffer_down64_aux1
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(k:nat) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j.{:pattern (mem1.[j]) \/ (mem2.[j])}
base <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem1.[j])}
j >= base /\ j < base + scale8 i ==>
mem1.[j] == mem2.[j]))
(decreases %[i-k]) =
if k >= i then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux1 b i v h base (k+1) h1 mem1 mem2
end
let rec written_buffer_down64_aux2
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(n:nat{n == buffer_length b})
(k:nat{k > i}) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
base + scale8 (i+1) <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
j >= base + scale8 (i+1) /\ j < base + scale8 n ==>
mem1.[j] == mem2.[j]))
(decreases %[n-k]) =
if k >= n then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux2 b i v h base n (k+1) h1 mem1 mem2
end
let written_buffer_down64 (b:buffer64{buffer_writeable b}) (i:nat{i < buffer_length b}) (v:nat64) (h:vale_heap)
: Lemma
(requires List.memP b (IB.ptrs_of_mem (_ih h)))
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
(base <= j /\ j < base + scale8 i) \/
(base + scale8 (i+1) <= j /\ j < base + scale8 n) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
written_buffer_down64_aux1 b i v h base 0 h1 mem1 mem2;
written_buffer_down64_aux2 b i v h base n (i+1) h1 mem1 mem2
let unwritten_buffer_down (t:base_typ) (b:buffer t{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:base_typ_as_vale_type t)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall (a:b8{List.memP a (IB.ptrs_of_mem (_ih h)) /\ a =!= b}) j. {:pattern mem1.[j]; List.memP a (IB.ptrs_of_mem (_ih h)) \/ mem2.[j]; List.memP a (IB.ptrs_of_mem (_ih h))}
let base = (IB.addrs_of_mem (_ih h)) a in
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==> mem1.[j] == mem2.[j]))
= let aux (a:b8{a =!= b /\ List.memP a (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let base = (IB.addrs_of_mem (_ih h)) a in
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall j.
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==>
mem1.[j] == mem2.[j]))
= let db = get_downview a.bsrc in
if DV.length db = 0 then ()
else
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = (IB.addrs_of_mem (_ih h)) a in
let s0 = DV.as_seq (IB.hs_of_mem (_ih h)) db in
let s1 = DV.as_seq (IB.hs_of_mem (_ih h1)) db in
opaque_assert (`%IB.list_disjoint_or_eq) IB.list_disjoint_or_eq IB.list_disjoint_or_eq_def (MB.disjoint a.bsrc b.bsrc);
lemma_dv_equal (IB.down_view a.src) a.bsrc (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1));
assert (Seq.equal s0 s1);
assert (forall (j:int).{:pattern (mem1.[j])}
base <= j /\ j < base + Seq.length s0 ==> v_to_typ TUInt8 (Seq.index s0 (j - base)) == mem1.[j]);
heap_shift mem1 mem2 base (DV.length db)
in
Classical.forall_intro aux
let store_buffer_down64_mem
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
forall (j:int). {:pattern mem1.[j] \/ mem2.[j]}
j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
let aux (j:int)
: Lemma
(j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j])
=
I.addrs_set_lemma_all ();
if j >= base && j < base + DV.length (get_downview b.bsrc) then begin
written_buffer_down64 b i v h;
length_t_eq (TUInt64) b
end
else if not (I.valid_addr (_ih h) j)
then I.same_unspecified_down (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1)) (IB.ptrs_of_mem (_ih h))
else unwritten_buffer_down TUInt64 b i v h
in
Classical.forall_intro aux
let store_buffer_aux_down64_mem (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
forall j. {:pattern mem1.[j] \/ mem2.[j]}
j < ptr \/ j >= ptr + 8 ==>
mem1.[j] == mem2.[j]))
= let t = TUInt64 in
let h1 = store_mem t ptr v h in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
store_buffer_write t ptr v h;
assert (buffer_addr b h + scale8 i == ptr);
assert (buffer_addr b h + scale8 (i+1) == ptr + 8);
store_buffer_down64_mem b i v h
let store_buffer_aux_down64_mem2 (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
S.get_heap_val64 ptr mem2 == v))
= let t = TUInt64 in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
let h1 = store_mem t ptr v h in
let mem2 = I.down_mem (_ih h1) in
store_buffer_write t ptr v h;
assert (Seq.index (buffer_as_seq h1 b) i == v);
index64_get_heap_val64 h1 b mem2 i
let in_bounds64 (h:vale_heap) (b:buffer64) (i:nat{i < buffer_length b})
: Lemma (scale8 i + 8 <= DV.length (get_downview b.bsrc))
=
length_t_eq TUInt64 b
let bytes_valid64 ptr h =
reveal_opaque (`%S.valid_addr64) S.valid_addr64;
let t = TUInt64 in
let b = get_addr_ptr t ptr h in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
in_bounds64 h b i;
I.addrs_set_mem (_ih h) b ptr;
I.addrs_set_mem (_ih h) b (ptr+1);
I.addrs_set_mem (_ih h) b (ptr+2);
I.addrs_set_mem (_ih h) b (ptr+3);
I.addrs_set_mem (_ih h) b (ptr+4);
I.addrs_set_mem (_ih h) b (ptr+5);
I.addrs_set_mem (_ih h) b (ptr+6);
I.addrs_set_mem (_ih h) b (ptr+7)
val same_mem_get_heap_val128 (b:buffer128)
(i:nat{i < buffer_length b})
(v:quad32)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1)) /\ buffer_writeable b})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale16 k in
forall i.{:pattern mem1.[i]} i >= ptr /\ i < ptr+16 ==> mem1.[i] == mem2.[i]))
val same_mem_eq_slices128 (b:buffer128)
(i:nat{i < buffer_length b})
(v:quad32)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1)) /\ buffer_writeable b})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 16 + 16 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 16) (k * 16 + 16) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 16) (k * 16 + 16)))
let same_mem_eq_slices128 b i v k h1 h2 mem1 mem2 =
let t = TUInt128 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up128 (b:buffer128) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 16}) : Lemma
(scale16 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint128_view in
UV.length_eq vb
let same_mem_get_heap_val128 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale16 k in
let addr = buffer_addr b h1 in
let aux (i:nat{ptr <= i /\ i < ptr+16}) : Lemma (mem1.[i] == mem2.[i]) =
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint128_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices128 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16) (k * 16 + 16)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16) (k * 16 + 16)) in
assert (Seq.index s1 (i - ptr) == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16 + (i-ptr)));
length_up128 b h1 k (i-ptr);
assert (mem1.[i] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16 + (i-ptr))));
assert (Seq.index s2 (i-ptr) == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16 + (i-ptr)));
length_up128 b h2 k (i-ptr);
assert (mem2.[addr+(scale16 k + (i-ptr))] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16 + (i-ptr))));
assert (forall i. addr + (scale16 k + (i-ptr)) == i)
in
Classical.forall_intro aux
let in_bounds128 (h:vale_heap) (b:buffer128) (i:nat{i < buffer_length b}) : Lemma
(scale16 i + 16 <= DV.length (get_downview b.bsrc))
=
length_t_eq TUInt128 b
#push-options "--z3rlimit 20"
#restart-solver
let bytes_valid128 ptr h =
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
IB.list_disjoint_or_eq_reveal ();
let t = TUInt128 in
let b = get_addr_ptr t ptr h in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
in_bounds128 h b i;
I.addrs_set_mem (_ih h) b ptr;
I.addrs_set_mem (_ih h) b (ptr+1);
I.addrs_set_mem (_ih h) b (ptr+2);
I.addrs_set_mem (_ih h) b (ptr+3);
I.addrs_set_mem (_ih h) b (ptr+4);
I.addrs_set_mem (_ih h) b (ptr+5);
I.addrs_set_mem (_ih h) b (ptr+6);
I.addrs_set_mem (_ih h) b (ptr+7);
I.addrs_set_mem (_ih h) b (ptr+8);
I.addrs_set_mem (_ih h) b (ptr+9);
I.addrs_set_mem (_ih h) b (ptr+10);
I.addrs_set_mem (_ih h) b (ptr+11);
I.addrs_set_mem (_ih h) b (ptr+12);
I.addrs_set_mem (_ih h) b (ptr+13);
I.addrs_set_mem (_ih h) b (ptr+14);
I.addrs_set_mem (_ih h) b (ptr+15)
#pop-options
let equiv_load_mem64 ptr h =
let t = TUInt64 in
let b = get_addr_ptr t ptr h in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
let addr = buffer_addr b h in
let contents = DV.as_seq (_ih h).IB.hs (get_downview b.bsrc) in
let heap = get_heap h in
index64_get_heap_val64 h b heap i;
lemma_load_mem64 b i h
//let low_lemma_valid_mem64 b i h =
// lemma_valid_mem64 b i h;
// bytes_valid64 (buffer_addr b h + scale8 i) h
//let low_lemma_load_mem64 b i h =
// lemma_valid_mem64 b i h;
// lemma_load_mem64 b i h;
// equiv_load_mem64 (buffer_addr b h + scale8 i) h
//let same_domain_update64 b i v h =
// low_lemma_valid_mem64 b i h;
// Vale.Arch.MachineHeap.same_domain_update64 (buffer_addr b h + scale8 i) v (get_heap h)
open Vale.X64.BufferViewStore
let low_lemma_store_mem64_aux
(b:buffer64)
(heap:S.machine_heap)
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{buffer_readable h b /\ buffer_writeable b})
: Lemma
(requires IB.correct_down_p (_ih h) heap b)
(ensures (let heap' = S.update_heap64 (buffer_addr b h + scale8 i) v heap in
let h' = store_mem64 (buffer_addr b h + scale8 i) v h in
(_ih h').IB.hs == DV.upd_seq (_ih h).IB.hs (get_downview b.bsrc) (I.get_seq_heap heap' (_ih h).IB.addrs b))) =
let ptr = buffer_addr b h + scale8 i in
let heap' = S.update_heap64 ptr v heap in
let h' = store_mem64 ptr v h in
lemma_store_mem64 b i v h;
length_t_eq TUInt64 b;
bv_upd_update_heap64 b heap i v (_ih h);
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db Vale.Interop.Views.up_view64 in
assert (UV.upd (_ih h).IB.hs bv i (UInt64.uint_to_t v) == (_ih h').IB.hs)
val valid_state_store_mem64_aux: (i:nat) -> (v:nat64) -> (h:vale_heap) -> Lemma
(requires writeable_mem64 i h)
(ensures (
let heap = get_heap h in
let heap' = S.update_heap64 i v heap in
let h' = store_mem64 i v h in
heap' == I.down_mem (_ih h')
))
let valid_state_store_mem64_aux i v h =
let heap = get_heap h in
let heap' = S.update_heap64 i v heap in
let h1 = store_mem TUInt64 i v h in
store_buffer_aux_down64_mem i v h;
store_buffer_aux_down64_mem2 i v h;
let mem1 = heap' in
let mem2 = I.down_mem (_ih h1) in
let aux () : Lemma (forall j. mem1.[j] == mem2.[j]) =
Vale.Arch.MachineHeap.same_mem_get_heap_val64 i mem1 mem2;
Vale.Arch.MachineHeap.correct_update_get64 i v heap;
Vale.Arch.MachineHeap.frame_update_heap64 i v heap
in let aux2 () : Lemma (Set.equal (Map.domain mem1) (Map.domain mem2)) =
bytes_valid64 i h;
Vale.Arch.MachineHeap.same_domain_update64 i v heap
in aux(); aux2();
Map.lemma_equal_intro mem1 mem2
let low_lemma_load_mem64_full b i vfh t hid =
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
#push-options "--z3rlimit 20"
#restart-solver
let low_lemma_store_mem64 b i v h =
lemma_writeable_mem64 b i h;
lemma_store_mem64 b i v h;
valid_state_store_mem64_aux (buffer_addr b h + scale8 i) v h;
let heap = get_heap h in
let heap' = S.update_heap64 (buffer_addr b h + scale8 i) v heap in
low_lemma_store_mem64_aux b heap i v h;
Vale.Arch.MachineHeap.frame_update_heap64 (buffer_addr b h + scale8 i) v heap;
in_bounds64 h b i;
I.addrs_set_lemma_all ();
I.update_buffer_up_mem (_ih h) b heap heap'
#pop-options
#set-options "--z3rlimit 100"
#restart-solver
let lemma_is_full_update
(vfh:vale_full_heap) (h hk hk':vale_heap) (k:heaplet_id) (mh mh' mhk mhk':machine_heap) (mt mt':memtaint)
(t:base_typ) (b:buffer t) (ptr:int) (v_size:nat)
(index:nat) (v:base_typ_as_vale_type t) (tn:taint)
: Lemma
(requires
vfh.vf_layout.vl_inner.vl_heaplets_initialized /\
mem_inv vfh /\
buffer_readable hk b /\
buffer_writeable b /\
index < Seq.length (buffer_as_seq hk b) /\
mt == vfh.vf_layout.vl_taint /\
h == vfh.vf_heap /\
hk == Map16.sel vfh.vf_heaplets k /\
mh == h.mh /\
mhk == hk.mh /\
ptr == buffer_addr b hk + scale_by v_size index /\
mt' == S.update_n ptr v_size (heap_taint (coerce vfh)) tn /\
hk' == buffer_write b index v hk /\
valid_layout_buffer b vfh.vf_layout hk true /\
valid_taint_buf b hk mt tn /\
is_machine_heap_update mh mh' /\ upd_heap h mh' == buffer_write b index v h /\
is_machine_heap_update mhk mhk' /\ upd_heap hk mhk' == buffer_write b index v hk /\
(forall j.{:pattern mh.[j] \/ mh'.[j]} j < ptr \/ j >= ptr + v_size ==> mh.[j] == mh'.[j]) /\
(forall j.{:pattern mhk.[j] \/ mhk'.[j]} j < ptr \/ j >= ptr + v_size ==> mhk.[j] == mhk'.[j]) /\
0 <= scale_by v_size index /\ scale_by v_size index + v_size <= DV.length (get_downview b.bsrc) /\
(forall i.{:pattern mh'.[i] \/ mhk'.[i]} i >= ptr /\ i < ptr + v_size ==> mh'.[i] == mhk'.[i]) /\
True
)
(ensures is_full_update vfh hk' k mh' mt')
=
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
let vfh' = coerce (heap_upd (coerce vfh) mh' mt') in
let dom_upd = Set.intersect (vfh.vf_layout.vl_inner.vl_heaplet_sets k) (Map.domain mhk) in
let mhk'' = Map.concat mhk (Map.restrict dom_upd mh') in
assert (Map.equal mhk'' mhk');
let unchanged (j:heaplet_id) : Lemma
(requires j =!= k)
(ensures Map16.sel vfh'.vf_heaplets j == Map16.sel vfh.vf_heaplets j)
[SMTPat (Map16.sel vfh'.vf_heaplets j)]
=
assert (Map.equal (Map16.sel vfh'.vf_heaplets j).mh (Map16.sel vfh.vf_heaplets j).mh);
I.down_up_identity (Map16.sel vfh.vf_heaplets j).ih;
()
in
assert (Map16.equal vfh'.vf_heaplets (Map16.upd vfh.vf_heaplets k hk'));
assert (Map.equal mt' mt);
Vale.Interop.Heap_s.list_disjoint_or_eq_reveal ();
()
let low_lemma_store_mem64_full b i v vfh t hid =
let (h, mt, hk) = (vfh.vf_heap, vfh.vf_layout.vl_taint, Map16.get vfh.vf_heaplets hid) in
let ptr = buffer_addr b hk + scale8 i in
let mh' = S.update_heap64 ptr v (heap_get (coerce vfh)) in
let mt' = S.update_n ptr 8 (heap_taint (coerce vfh)) t in
let hk' = buffer_write b i v hk in
let mhk' = S.update_heap64 ptr v (get_heap hk) in
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
low_lemma_store_mem64 b i v h;
low_lemma_store_mem64 b i v (Map16.get vfh.vf_heaplets hid);
Vale.Arch.MachineHeap.frame_update_heap64 ptr v h.mh;
Vale.Arch.MachineHeap.frame_update_heap64 ptr v hk.mh;
in_bounds64 hk b i;
Vale.Arch.MachineHeap.same_mem_get_heap_val64 ptr mh' mhk';
lemma_is_full_update vfh h hk hk' hid h.mh mh' hk.mh mhk' mt mt' TUInt64 b ptr 8 i v t;
()
val low_lemma_valid_mem128 (b:buffer128) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b
)
(ensures
S.valid_addr128 (buffer_addr b h + scale16 i) (get_heap h)
)
let low_lemma_valid_mem128 b i h =
lemma_valid_mem128 b i h;
bytes_valid128 (buffer_addr b h + scale16 i) h
val equiv_load_mem128_aux: (ptr:int) -> (h:vale_heap) -> Lemma
(requires valid_mem128 ptr h)
(ensures load_mem128 ptr h == S.get_heap_val128 ptr (get_heap h)) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Memory.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.BufferViewStore.fsti.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Memory_Sems.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.BufferViewStore",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_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
}
] | {
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | ptr: Prims.int -> h: Vale.Arch.HeapImpl.vale_heap
-> FStar.Pervasives.Lemma (requires Vale.X64.Memory.valid_mem128 ptr h)
(ensures
Vale.X64.Memory.load_mem128 ptr h ==
Vale.Arch.MachineHeap_s.get_heap_val128 ptr (Vale.X64.Memory_Sems.get_heap h)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.int",
"Vale.Arch.HeapImpl.vale_heap",
"Vale.X64.Memory.lemma_load_mem128",
"Prims.unit",
"Vale.X64.Memory.index128_get_heap_val128",
"Vale.Arch.MachineHeap_s.get_heap_val128_reveal",
"Vale.Arch.MachineHeap_s.machine_heap",
"Vale.X64.Memory_Sems.same_domain",
"Vale.X64.Memory_Sems.get_heap",
"FStar.Seq.Properties.lseq",
"FStar.UInt8.t",
"LowStar.BufferView.Down.length",
"Vale.Interop.Types.get_downview",
"Vale.Interop.Types.__proj__Buffer__item__src",
"Vale.Interop.Types.b8_preorder",
"Vale.Interop.Types.__proj__Buffer__item__writeable",
"Vale.Interop.Types.base_typ_as_type",
"Vale.Interop.Types.__proj__Buffer__item__bsrc",
"LowStar.BufferView.Down.as_seq",
"Vale.Interop.Heap_s.__proj__InteropHeap__item__hs",
"Vale.Arch.HeapImpl._ih",
"Vale.X64.Memory.buffer_addr",
"Prims.nat",
"Vale.X64.Memory.get_addr_in_ptr",
"Vale.X64.Memory.buffer_length",
"Vale.Arch.HeapImpl.buffer",
"Vale.X64.Memory.get_addr_ptr",
"Vale.Arch.HeapTypes_s.base_typ",
"Vale.Arch.HeapTypes_s.TUInt128"
] | [] | true | false | true | false | false | let equiv_load_mem128_aux ptr h =
| let t = TUInt128 in
let b = get_addr_ptr t ptr h in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
let addr = buffer_addr b h in
let contents = DV.as_seq (_ih h).IB.hs (get_downview b.bsrc) in
let heap = get_heap h in
S.get_heap_val128_reveal ();
index128_get_heap_val128 h b heap i;
lemma_load_mem128 b i h | false |
LowStar.Literal.fsti | LowStar.Literal.ascii_char | val ascii_char : Type0 | let ascii_char = c:Char.char{is_ascii_char c} | {
"file_name": "ulib/LowStar.Literal.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 45,
"end_line": 38,
"start_col": 0,
"start_line": 38
} | module LowStar.Literal
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
open FStar.Mul
/// This module enables clients to make use of string literals in Low* as
/// shorthand syntax for immutable, always-live uint8 buffers. See
/// LowStar.printf for writing and printing string literals.
/// .. note::
///
/// This module supersedes ``C.String``.
/// As a reminder, the F* compiler enforces that string literals are UTF-8
/// encoded, and list_of_string returns the corresponding sequence of Unicode
/// scalar values (see https://erratique.ch/software/uucp/doc/Uucp.html#uminimal) for an excellent
/// crash course on Unicode.
/// When compiling with KaRaMeL, string literals are printed as series of bytes,
/// where non-alphanumeric characters are hex-encoded. For instance, if after reading
/// the C standard, the user writes ``let x = "🤮"``, then KaRaMeL will generate
/// ``const char *x = "\xf0\x9f\xa4\xae"``.
/// String literals as buffers
/// --------------------------
/// Therefore, in order to talk about the interpretation of a string literal as
/// a series of bytes, we need to define the serialization of Unicode scalar values
/// (as returned by ``String.list_of_string``) into bytes. This is a commendable and
/// noble goal, but instead, we choose to restrict ourselves to the ASCII subset of
/// UTF-8, where the byte encoding of a scalar value is the identity.
let is_ascii_char (c: Char.char) = UInt32.lt (Char.u32_of_char c) 0x80ul | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int.Cast.Full.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Char.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.Literal.fsti"
} | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Type0 | Prims.Tot | [
"total"
] | [] | [
"FStar.Char.char",
"Prims.b2t",
"LowStar.Literal.is_ascii_char"
] | [] | false | false | false | true | true | let ascii_char =
| c: Char.char{is_ascii_char c} | false |
|
LowStar.Literal.fsti | LowStar.Literal.is_ascii_char | val is_ascii_char : c: FStar.Char.char -> Prims.bool | let is_ascii_char (c: Char.char) = UInt32.lt (Char.u32_of_char c) 0x80ul | {
"file_name": "ulib/LowStar.Literal.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 72,
"end_line": 36,
"start_col": 0,
"start_line": 36
} | module LowStar.Literal
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
open FStar.Mul
/// This module enables clients to make use of string literals in Low* as
/// shorthand syntax for immutable, always-live uint8 buffers. See
/// LowStar.printf for writing and printing string literals.
/// .. note::
///
/// This module supersedes ``C.String``.
/// As a reminder, the F* compiler enforces that string literals are UTF-8
/// encoded, and list_of_string returns the corresponding sequence of Unicode
/// scalar values (see https://erratique.ch/software/uucp/doc/Uucp.html#uminimal) for an excellent
/// crash course on Unicode.
/// When compiling with KaRaMeL, string literals are printed as series of bytes,
/// where non-alphanumeric characters are hex-encoded. For instance, if after reading
/// the C standard, the user writes ``let x = "🤮"``, then KaRaMeL will generate
/// ``const char *x = "\xf0\x9f\xa4\xae"``.
/// String literals as buffers
/// --------------------------
/// Therefore, in order to talk about the interpretation of a string literal as
/// a series of bytes, we need to define the serialization of Unicode scalar values
/// (as returned by ``String.list_of_string``) into bytes. This is a commendable and
/// noble goal, but instead, we choose to restrict ourselves to the ASCII subset of | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int.Cast.Full.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Char.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.Literal.fsti"
} | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | c: FStar.Char.char -> Prims.bool | Prims.Tot | [
"total"
] | [] | [
"FStar.Char.char",
"FStar.UInt32.lt",
"FStar.Char.u32_of_char",
"FStar.UInt32.__uint_to_t",
"Prims.bool"
] | [] | false | false | false | true | false | let is_ascii_char (c: Char.char) =
| UInt32.lt (Char.u32_of_char c) 0x80ul | false |
|
LowStar.Literal.fsti | LowStar.Literal.is_ascii_string | val is_ascii_string : s: Prims.string -> Prims.bool | let is_ascii_string (s: string) =
List.Tot.for_all is_ascii_char (String.list_of_string s) | {
"file_name": "ulib/LowStar.Literal.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 58,
"end_line": 41,
"start_col": 0,
"start_line": 40
} | module LowStar.Literal
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
open FStar.Mul
/// This module enables clients to make use of string literals in Low* as
/// shorthand syntax for immutable, always-live uint8 buffers. See
/// LowStar.printf for writing and printing string literals.
/// .. note::
///
/// This module supersedes ``C.String``.
/// As a reminder, the F* compiler enforces that string literals are UTF-8
/// encoded, and list_of_string returns the corresponding sequence of Unicode
/// scalar values (see https://erratique.ch/software/uucp/doc/Uucp.html#uminimal) for an excellent
/// crash course on Unicode.
/// When compiling with KaRaMeL, string literals are printed as series of bytes,
/// where non-alphanumeric characters are hex-encoded. For instance, if after reading
/// the C standard, the user writes ``let x = "🤮"``, then KaRaMeL will generate
/// ``const char *x = "\xf0\x9f\xa4\xae"``.
/// String literals as buffers
/// --------------------------
/// Therefore, in order to talk about the interpretation of a string literal as
/// a series of bytes, we need to define the serialization of Unicode scalar values
/// (as returned by ``String.list_of_string``) into bytes. This is a commendable and
/// noble goal, but instead, we choose to restrict ourselves to the ASCII subset of
/// UTF-8, where the byte encoding of a scalar value is the identity.
let is_ascii_char (c: Char.char) = UInt32.lt (Char.u32_of_char c) 0x80ul
let ascii_char = c:Char.char{is_ascii_char c} | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int.Cast.Full.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Char.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.Literal.fsti"
} | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: Prims.string -> Prims.bool | Prims.Tot | [
"total"
] | [] | [
"Prims.string",
"FStar.List.Tot.Base.for_all",
"FStar.String.char",
"LowStar.Literal.is_ascii_char",
"FStar.String.list_of_string",
"Prims.bool"
] | [] | false | false | false | true | false | let is_ascii_string (s: string) =
| List.Tot.for_all is_ascii_char (String.list_of_string s) | false |
|
LowStar.Literal.fsti | LowStar.Literal.ascii_string | val ascii_string : Type0 | let ascii_string = s:string{is_ascii_string s} | {
"file_name": "ulib/LowStar.Literal.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 46,
"end_line": 43,
"start_col": 0,
"start_line": 43
} | module LowStar.Literal
module B = LowStar.Buffer
module IB = LowStar.ImmutableBuffer
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
open FStar.Mul
/// This module enables clients to make use of string literals in Low* as
/// shorthand syntax for immutable, always-live uint8 buffers. See
/// LowStar.printf for writing and printing string literals.
/// .. note::
///
/// This module supersedes ``C.String``.
/// As a reminder, the F* compiler enforces that string literals are UTF-8
/// encoded, and list_of_string returns the corresponding sequence of Unicode
/// scalar values (see https://erratique.ch/software/uucp/doc/Uucp.html#uminimal) for an excellent
/// crash course on Unicode.
/// When compiling with KaRaMeL, string literals are printed as series of bytes,
/// where non-alphanumeric characters are hex-encoded. For instance, if after reading
/// the C standard, the user writes ``let x = "🤮"``, then KaRaMeL will generate
/// ``const char *x = "\xf0\x9f\xa4\xae"``.
/// String literals as buffers
/// --------------------------
/// Therefore, in order to talk about the interpretation of a string literal as
/// a series of bytes, we need to define the serialization of Unicode scalar values
/// (as returned by ``String.list_of_string``) into bytes. This is a commendable and
/// noble goal, but instead, we choose to restrict ourselves to the ASCII subset of
/// UTF-8, where the byte encoding of a scalar value is the identity.
let is_ascii_char (c: Char.char) = UInt32.lt (Char.u32_of_char c) 0x80ul
let ascii_char = c:Char.char{is_ascii_char c}
let is_ascii_string (s: string) =
List.Tot.for_all is_ascii_char (String.list_of_string s) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int.Cast.Full.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Char.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.Literal.fsti"
} | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "IB"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Type0 | Prims.Tot | [
"total"
] | [] | [
"Prims.string",
"Prims.b2t",
"LowStar.Literal.is_ascii_string"
] | [] | false | false | false | true | true | let ascii_string =
| s: string{is_ascii_string s} | false |
|
Vale.X64.Memory_Sems.fst | Vale.X64.Memory_Sems.low_lemma_load_mem128 | val low_lemma_load_mem128 (b:buffer128) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b
)
(ensures
S.get_heap_val128 (buffer_addr b h + scale16 i) (get_heap h) == buffer_read b i h
) | val low_lemma_load_mem128 (b:buffer128) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b
)
(ensures
S.get_heap_val128 (buffer_addr b h + scale16 i) (get_heap h) == buffer_read b i h
) | let low_lemma_load_mem128 b i h =
lemma_valid_mem128 b i h;
lemma_load_mem128 b i h;
equiv_load_mem128_aux (buffer_addr b h + scale16 i) h | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory_Sems.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 55,
"end_line": 767,
"start_col": 0,
"start_line": 764
} | module Vale.X64.Memory_Sems
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.Def.Words_s
module I = Vale.Interop
module S = Vale.X64.Machine_Semantics_s
module MB = LowStar.Monotonic.Buffer
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
friend Vale.X64.Memory
module IB = Vale.Interop.Base
let same_domain h m = Set.equal (IB.addrs_set (_ih h)) (Map.domain m)
let lemma_same_domains h m1 m2 = ()
let get_heap h = I.down_mem (_ih h)
let upd_heap h m = mi_heap_upd h m
//let lemma_upd_get_heap h = I.down_up_identity (_ih h)
let lemma_get_upd_heap h m = I.up_down_identity (_ih h) m
let lemma_heap_impl = ()
let lemma_heap_get_heap h = ()
let lemma_heap_taint h = ()
//let lemma_heap_upd_heap h mh mt = ()
[@"opaque_to_smt"]
let rec set_of_range (a:int) (n:nat) : Pure (Set.set int)
(requires True)
(ensures fun s -> (forall (i:int).{:pattern Set.mem i s} Set.mem i s <==> a <= i /\ i < a + n))
=
if n = 0 then Set.empty else Set.union (set_of_range a (n - 1)) (Set.singleton (a + n - 1))
let buffer_info_has_addr (bi:buffer_info) (a:int) =
let b = bi.bi_buffer in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
addr <= a /\ a < addr + len
let buffer_info_has_addr_opt (bi:option buffer_info) (a:int) =
match bi with
| None -> False
| Some bi -> buffer_info_has_addr bi a
#set-options "--z3rlimit 100"
let rec make_owns_rec (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
if n = 0 then ((fun _ -> None), (fun _ -> Set.empty)) else
let (m0, s0) = make_owns_rec h bs (n - 1) in
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let s i = if i = hi then Set.union (s0 i) s_b else s0 i in
let m a = if addr <= a && a < addr + len then Some (n - 1) else m0 a in
(m, s)
[@"opaque_to_smt"]
let make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
make_owns_rec h bs n
let rec lemma_make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n <= Seq.length bs /\
(forall (i:nat).{:pattern Seq.index bs i} i < Seq.length bs ==> buffer_readable h (Seq.index bs i).bi_buffer) /\
(forall (i1 i2:nat).{:pattern (Seq.index bs i1); (Seq.index bs i2)}
i1 < Seq.length bs /\ i2 < Seq.length bs ==> buffer_info_disjoint (Seq.index bs i1) (Seq.index bs i2))
)
(ensures (
let (m, s) = make_owns h bs n in
(forall (i:heaplet_id) (a:int).{:pattern Set.mem a (s i)}
(Set.mem a (s i) <==> Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (m a) == Some i) /\
(Set.mem a (s i) ==> buffer_info_has_addr_opt (Option.mapTot (fun n -> Seq.index bs n) (m a)) a) /\
(Set.mem a (s i) ==> Set.mem a (Map.domain h.mh))
) /\
(forall (k:nat) (a:int).{:pattern Set.mem a (s (Seq.index bs k).bi_heaplet)}
k < n /\ buffer_info_has_addr (Seq.index bs k) a ==> Set.mem a (s (Seq.index bs k).bi_heaplet))
))
=
reveal_opaque (`%make_owns) make_owns;
if n = 0 then () else
let _ = make_owns h bs (n - 1) in
let (m, s) = make_owns h bs n in
lemma_make_owns h bs (n - 1);
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let lem1 (a:int) : Lemma
(requires Set.mem a s_b)
(ensures Set.mem a (Map.domain h.mh))
[SMTPat (Set.mem a (Map.domain h.mh))]
=
I.addrs_set_mem h.ih b a
in
let lem2 (i:heaplet_id) (a:int) : Lemma
(requires i =!= hi /\ Set.mem a (Set.intersect s_b (s i)))
(ensures False)
[SMTPat (Set.mem a (s i))]
=
reveal_opaque (`%addr_map_pred) addr_map_pred
in
()
#push-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_loc_mutable_buffers_rec (l:list buffer_info) (s:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n + List.length l == Seq.length s /\
list_to_seq_post l s n
)
(ensures (
let modloc = loc_mutable_buffers l in
forall (i:nat).{:pattern Seq.index s i} n <= i /\ i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes modloc (loc_buffer bi.bi_buffer))
))
(decreases l)
=
match l with
| [] -> ()
| h::t -> lemma_loc_mutable_buffers_rec t s (n + 1)
#pop-options
let lemma_loc_mutable_buffers (l:list buffer_info) : Lemma
(ensures (
let s = list_to_seq l in
forall (i:nat).{:pattern Seq.index s i} i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes (loc_mutable_buffers l) (loc_buffer bi.bi_buffer))
))
=
lemma_list_to_seq l;
lemma_loc_mutable_buffers_rec l (list_to_seq l) 0
let create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let modloc = loc_mutable_buffers buffers in
let layout1 = h1.vf_layout in
let layin1 = layout1.vl_inner in
let (hmap, hsets) = make_owns h1.vf_heap bs (Seq.length bs) in
let hmap a = Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (hmap a) in
let l = {
vl_heaplets_initialized = true;
vl_heaplet_map = hmap;
vl_heaplet_sets = hsets;
vl_old_heap = h1.vf_heap;
vl_buffers = bs;
vl_mod_loc = modloc;
} in
let layout2 = {layout1 with vl_inner = l} in
let h2 = {
vf_layout = layout2;
vf_heap = h1.vf_heap;
vf_heaplets = h1.vf_heaplets;
} in
h2
let lemma_create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let h2 = create_heaplets buffers h1 in
assert (h2.vf_layout.vl_inner.vl_buffers == bs); // REVIEW: why is this necessary, even with extra ifuel?
lemma_make_owns h1.vf_heap bs (Seq.length bs);
lemma_loc_mutable_buffers buffers;
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
let destroy_heaplets h1 =
h1
let lemma_destroy_heaplets h1 =
()
val heap_shift (m1 m2:S.machine_heap) (base:int) (n:nat) : Lemma
(requires (forall i. 0 <= i /\ i < n ==> m1.[base + i] == m2.[base + i]))
(ensures (forall i. {:pattern (m1.[i])} base <= i /\ i < base + n ==> m1.[i] == m2.[i]))
#push-options "--smtencoding.l_arith_repr boxwrap"
let heap_shift m1 m2 base n =
assert (forall i. base <= i /\ i < base + n ==>
m1.[base + (i - base)] == m2.[base + (i - base)])
#pop-options
val same_mem_eq_slices64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 8 + 8 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8)))
let same_mem_eq_slices64 b i v k h1 h2 mem1 mem2 =
let t = TUInt64 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up64 (b:buffer64) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 8}) : Lemma
(scale8 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint64_view in
UV.length_eq vb
val same_mem_get_heap_val64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale8 k in
forall (x:int).{:pattern (mem1.[x])} ptr <= x /\ x < ptr + 8 ==> mem1.[x] == mem2.[x]))
let same_mem_get_heap_val64 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale8 k in
let addr = buffer_addr b h1 in
let aux (x:int{ptr <= x /\ x < ptr + 8}) : Lemma (mem1.[x] == mem2.[x]) =
let i = x - ptr in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices64 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8) (k * 8 + 8)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8) (k * 8 + 8)) in
assert (Seq.index s1 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i));
length_up64 b h1 k i;
assert (mem1.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i)));
assert (Seq.index s2 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i));
length_up64 b h2 k i;
assert (mem2.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i)))
in
Classical.forall_intro aux;
assert (forall i. addr + (scale8 k + i) == ptr + i)
let rec written_buffer_down64_aux1
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(k:nat) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j.{:pattern (mem1.[j]) \/ (mem2.[j])}
base <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem1.[j])}
j >= base /\ j < base + scale8 i ==>
mem1.[j] == mem2.[j]))
(decreases %[i-k]) =
if k >= i then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux1 b i v h base (k+1) h1 mem1 mem2
end
let rec written_buffer_down64_aux2
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(n:nat{n == buffer_length b})
(k:nat{k > i}) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
base + scale8 (i+1) <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
j >= base + scale8 (i+1) /\ j < base + scale8 n ==>
mem1.[j] == mem2.[j]))
(decreases %[n-k]) =
if k >= n then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux2 b i v h base n (k+1) h1 mem1 mem2
end
let written_buffer_down64 (b:buffer64{buffer_writeable b}) (i:nat{i < buffer_length b}) (v:nat64) (h:vale_heap)
: Lemma
(requires List.memP b (IB.ptrs_of_mem (_ih h)))
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
(base <= j /\ j < base + scale8 i) \/
(base + scale8 (i+1) <= j /\ j < base + scale8 n) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
written_buffer_down64_aux1 b i v h base 0 h1 mem1 mem2;
written_buffer_down64_aux2 b i v h base n (i+1) h1 mem1 mem2
let unwritten_buffer_down (t:base_typ) (b:buffer t{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:base_typ_as_vale_type t)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall (a:b8{List.memP a (IB.ptrs_of_mem (_ih h)) /\ a =!= b}) j. {:pattern mem1.[j]; List.memP a (IB.ptrs_of_mem (_ih h)) \/ mem2.[j]; List.memP a (IB.ptrs_of_mem (_ih h))}
let base = (IB.addrs_of_mem (_ih h)) a in
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==> mem1.[j] == mem2.[j]))
= let aux (a:b8{a =!= b /\ List.memP a (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let base = (IB.addrs_of_mem (_ih h)) a in
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall j.
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==>
mem1.[j] == mem2.[j]))
= let db = get_downview a.bsrc in
if DV.length db = 0 then ()
else
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = (IB.addrs_of_mem (_ih h)) a in
let s0 = DV.as_seq (IB.hs_of_mem (_ih h)) db in
let s1 = DV.as_seq (IB.hs_of_mem (_ih h1)) db in
opaque_assert (`%IB.list_disjoint_or_eq) IB.list_disjoint_or_eq IB.list_disjoint_or_eq_def (MB.disjoint a.bsrc b.bsrc);
lemma_dv_equal (IB.down_view a.src) a.bsrc (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1));
assert (Seq.equal s0 s1);
assert (forall (j:int).{:pattern (mem1.[j])}
base <= j /\ j < base + Seq.length s0 ==> v_to_typ TUInt8 (Seq.index s0 (j - base)) == mem1.[j]);
heap_shift mem1 mem2 base (DV.length db)
in
Classical.forall_intro aux
let store_buffer_down64_mem
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
forall (j:int). {:pattern mem1.[j] \/ mem2.[j]}
j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
let aux (j:int)
: Lemma
(j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j])
=
I.addrs_set_lemma_all ();
if j >= base && j < base + DV.length (get_downview b.bsrc) then begin
written_buffer_down64 b i v h;
length_t_eq (TUInt64) b
end
else if not (I.valid_addr (_ih h) j)
then I.same_unspecified_down (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1)) (IB.ptrs_of_mem (_ih h))
else unwritten_buffer_down TUInt64 b i v h
in
Classical.forall_intro aux
let store_buffer_aux_down64_mem (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
forall j. {:pattern mem1.[j] \/ mem2.[j]}
j < ptr \/ j >= ptr + 8 ==>
mem1.[j] == mem2.[j]))
= let t = TUInt64 in
let h1 = store_mem t ptr v h in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
store_buffer_write t ptr v h;
assert (buffer_addr b h + scale8 i == ptr);
assert (buffer_addr b h + scale8 (i+1) == ptr + 8);
store_buffer_down64_mem b i v h
let store_buffer_aux_down64_mem2 (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
S.get_heap_val64 ptr mem2 == v))
= let t = TUInt64 in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
let h1 = store_mem t ptr v h in
let mem2 = I.down_mem (_ih h1) in
store_buffer_write t ptr v h;
assert (Seq.index (buffer_as_seq h1 b) i == v);
index64_get_heap_val64 h1 b mem2 i
let in_bounds64 (h:vale_heap) (b:buffer64) (i:nat{i < buffer_length b})
: Lemma (scale8 i + 8 <= DV.length (get_downview b.bsrc))
=
length_t_eq TUInt64 b
let bytes_valid64 ptr h =
reveal_opaque (`%S.valid_addr64) S.valid_addr64;
let t = TUInt64 in
let b = get_addr_ptr t ptr h in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
in_bounds64 h b i;
I.addrs_set_mem (_ih h) b ptr;
I.addrs_set_mem (_ih h) b (ptr+1);
I.addrs_set_mem (_ih h) b (ptr+2);
I.addrs_set_mem (_ih h) b (ptr+3);
I.addrs_set_mem (_ih h) b (ptr+4);
I.addrs_set_mem (_ih h) b (ptr+5);
I.addrs_set_mem (_ih h) b (ptr+6);
I.addrs_set_mem (_ih h) b (ptr+7)
val same_mem_get_heap_val128 (b:buffer128)
(i:nat{i < buffer_length b})
(v:quad32)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1)) /\ buffer_writeable b})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale16 k in
forall i.{:pattern mem1.[i]} i >= ptr /\ i < ptr+16 ==> mem1.[i] == mem2.[i]))
val same_mem_eq_slices128 (b:buffer128)
(i:nat{i < buffer_length b})
(v:quad32)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1)) /\ buffer_writeable b})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 16 + 16 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 16) (k * 16 + 16) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 16) (k * 16 + 16)))
let same_mem_eq_slices128 b i v k h1 h2 mem1 mem2 =
let t = TUInt128 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up128 (b:buffer128) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 16}) : Lemma
(scale16 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint128_view in
UV.length_eq vb
let same_mem_get_heap_val128 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale16 k in
let addr = buffer_addr b h1 in
let aux (i:nat{ptr <= i /\ i < ptr+16}) : Lemma (mem1.[i] == mem2.[i]) =
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint128_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices128 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16) (k * 16 + 16)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16) (k * 16 + 16)) in
assert (Seq.index s1 (i - ptr) == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16 + (i-ptr)));
length_up128 b h1 k (i-ptr);
assert (mem1.[i] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16 + (i-ptr))));
assert (Seq.index s2 (i-ptr) == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16 + (i-ptr)));
length_up128 b h2 k (i-ptr);
assert (mem2.[addr+(scale16 k + (i-ptr))] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16 + (i-ptr))));
assert (forall i. addr + (scale16 k + (i-ptr)) == i)
in
Classical.forall_intro aux
let in_bounds128 (h:vale_heap) (b:buffer128) (i:nat{i < buffer_length b}) : Lemma
(scale16 i + 16 <= DV.length (get_downview b.bsrc))
=
length_t_eq TUInt128 b
#push-options "--z3rlimit 20"
#restart-solver
let bytes_valid128 ptr h =
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
IB.list_disjoint_or_eq_reveal ();
let t = TUInt128 in
let b = get_addr_ptr t ptr h in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
in_bounds128 h b i;
I.addrs_set_mem (_ih h) b ptr;
I.addrs_set_mem (_ih h) b (ptr+1);
I.addrs_set_mem (_ih h) b (ptr+2);
I.addrs_set_mem (_ih h) b (ptr+3);
I.addrs_set_mem (_ih h) b (ptr+4);
I.addrs_set_mem (_ih h) b (ptr+5);
I.addrs_set_mem (_ih h) b (ptr+6);
I.addrs_set_mem (_ih h) b (ptr+7);
I.addrs_set_mem (_ih h) b (ptr+8);
I.addrs_set_mem (_ih h) b (ptr+9);
I.addrs_set_mem (_ih h) b (ptr+10);
I.addrs_set_mem (_ih h) b (ptr+11);
I.addrs_set_mem (_ih h) b (ptr+12);
I.addrs_set_mem (_ih h) b (ptr+13);
I.addrs_set_mem (_ih h) b (ptr+14);
I.addrs_set_mem (_ih h) b (ptr+15)
#pop-options
let equiv_load_mem64 ptr h =
let t = TUInt64 in
let b = get_addr_ptr t ptr h in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
let addr = buffer_addr b h in
let contents = DV.as_seq (_ih h).IB.hs (get_downview b.bsrc) in
let heap = get_heap h in
index64_get_heap_val64 h b heap i;
lemma_load_mem64 b i h
//let low_lemma_valid_mem64 b i h =
// lemma_valid_mem64 b i h;
// bytes_valid64 (buffer_addr b h + scale8 i) h
//let low_lemma_load_mem64 b i h =
// lemma_valid_mem64 b i h;
// lemma_load_mem64 b i h;
// equiv_load_mem64 (buffer_addr b h + scale8 i) h
//let same_domain_update64 b i v h =
// low_lemma_valid_mem64 b i h;
// Vale.Arch.MachineHeap.same_domain_update64 (buffer_addr b h + scale8 i) v (get_heap h)
open Vale.X64.BufferViewStore
let low_lemma_store_mem64_aux
(b:buffer64)
(heap:S.machine_heap)
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{buffer_readable h b /\ buffer_writeable b})
: Lemma
(requires IB.correct_down_p (_ih h) heap b)
(ensures (let heap' = S.update_heap64 (buffer_addr b h + scale8 i) v heap in
let h' = store_mem64 (buffer_addr b h + scale8 i) v h in
(_ih h').IB.hs == DV.upd_seq (_ih h).IB.hs (get_downview b.bsrc) (I.get_seq_heap heap' (_ih h).IB.addrs b))) =
let ptr = buffer_addr b h + scale8 i in
let heap' = S.update_heap64 ptr v heap in
let h' = store_mem64 ptr v h in
lemma_store_mem64 b i v h;
length_t_eq TUInt64 b;
bv_upd_update_heap64 b heap i v (_ih h);
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db Vale.Interop.Views.up_view64 in
assert (UV.upd (_ih h).IB.hs bv i (UInt64.uint_to_t v) == (_ih h').IB.hs)
val valid_state_store_mem64_aux: (i:nat) -> (v:nat64) -> (h:vale_heap) -> Lemma
(requires writeable_mem64 i h)
(ensures (
let heap = get_heap h in
let heap' = S.update_heap64 i v heap in
let h' = store_mem64 i v h in
heap' == I.down_mem (_ih h')
))
let valid_state_store_mem64_aux i v h =
let heap = get_heap h in
let heap' = S.update_heap64 i v heap in
let h1 = store_mem TUInt64 i v h in
store_buffer_aux_down64_mem i v h;
store_buffer_aux_down64_mem2 i v h;
let mem1 = heap' in
let mem2 = I.down_mem (_ih h1) in
let aux () : Lemma (forall j. mem1.[j] == mem2.[j]) =
Vale.Arch.MachineHeap.same_mem_get_heap_val64 i mem1 mem2;
Vale.Arch.MachineHeap.correct_update_get64 i v heap;
Vale.Arch.MachineHeap.frame_update_heap64 i v heap
in let aux2 () : Lemma (Set.equal (Map.domain mem1) (Map.domain mem2)) =
bytes_valid64 i h;
Vale.Arch.MachineHeap.same_domain_update64 i v heap
in aux(); aux2();
Map.lemma_equal_intro mem1 mem2
let low_lemma_load_mem64_full b i vfh t hid =
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
#push-options "--z3rlimit 20"
#restart-solver
let low_lemma_store_mem64 b i v h =
lemma_writeable_mem64 b i h;
lemma_store_mem64 b i v h;
valid_state_store_mem64_aux (buffer_addr b h + scale8 i) v h;
let heap = get_heap h in
let heap' = S.update_heap64 (buffer_addr b h + scale8 i) v heap in
low_lemma_store_mem64_aux b heap i v h;
Vale.Arch.MachineHeap.frame_update_heap64 (buffer_addr b h + scale8 i) v heap;
in_bounds64 h b i;
I.addrs_set_lemma_all ();
I.update_buffer_up_mem (_ih h) b heap heap'
#pop-options
#set-options "--z3rlimit 100"
#restart-solver
let lemma_is_full_update
(vfh:vale_full_heap) (h hk hk':vale_heap) (k:heaplet_id) (mh mh' mhk mhk':machine_heap) (mt mt':memtaint)
(t:base_typ) (b:buffer t) (ptr:int) (v_size:nat)
(index:nat) (v:base_typ_as_vale_type t) (tn:taint)
: Lemma
(requires
vfh.vf_layout.vl_inner.vl_heaplets_initialized /\
mem_inv vfh /\
buffer_readable hk b /\
buffer_writeable b /\
index < Seq.length (buffer_as_seq hk b) /\
mt == vfh.vf_layout.vl_taint /\
h == vfh.vf_heap /\
hk == Map16.sel vfh.vf_heaplets k /\
mh == h.mh /\
mhk == hk.mh /\
ptr == buffer_addr b hk + scale_by v_size index /\
mt' == S.update_n ptr v_size (heap_taint (coerce vfh)) tn /\
hk' == buffer_write b index v hk /\
valid_layout_buffer b vfh.vf_layout hk true /\
valid_taint_buf b hk mt tn /\
is_machine_heap_update mh mh' /\ upd_heap h mh' == buffer_write b index v h /\
is_machine_heap_update mhk mhk' /\ upd_heap hk mhk' == buffer_write b index v hk /\
(forall j.{:pattern mh.[j] \/ mh'.[j]} j < ptr \/ j >= ptr + v_size ==> mh.[j] == mh'.[j]) /\
(forall j.{:pattern mhk.[j] \/ mhk'.[j]} j < ptr \/ j >= ptr + v_size ==> mhk.[j] == mhk'.[j]) /\
0 <= scale_by v_size index /\ scale_by v_size index + v_size <= DV.length (get_downview b.bsrc) /\
(forall i.{:pattern mh'.[i] \/ mhk'.[i]} i >= ptr /\ i < ptr + v_size ==> mh'.[i] == mhk'.[i]) /\
True
)
(ensures is_full_update vfh hk' k mh' mt')
=
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
let vfh' = coerce (heap_upd (coerce vfh) mh' mt') in
let dom_upd = Set.intersect (vfh.vf_layout.vl_inner.vl_heaplet_sets k) (Map.domain mhk) in
let mhk'' = Map.concat mhk (Map.restrict dom_upd mh') in
assert (Map.equal mhk'' mhk');
let unchanged (j:heaplet_id) : Lemma
(requires j =!= k)
(ensures Map16.sel vfh'.vf_heaplets j == Map16.sel vfh.vf_heaplets j)
[SMTPat (Map16.sel vfh'.vf_heaplets j)]
=
assert (Map.equal (Map16.sel vfh'.vf_heaplets j).mh (Map16.sel vfh.vf_heaplets j).mh);
I.down_up_identity (Map16.sel vfh.vf_heaplets j).ih;
()
in
assert (Map16.equal vfh'.vf_heaplets (Map16.upd vfh.vf_heaplets k hk'));
assert (Map.equal mt' mt);
Vale.Interop.Heap_s.list_disjoint_or_eq_reveal ();
()
let low_lemma_store_mem64_full b i v vfh t hid =
let (h, mt, hk) = (vfh.vf_heap, vfh.vf_layout.vl_taint, Map16.get vfh.vf_heaplets hid) in
let ptr = buffer_addr b hk + scale8 i in
let mh' = S.update_heap64 ptr v (heap_get (coerce vfh)) in
let mt' = S.update_n ptr 8 (heap_taint (coerce vfh)) t in
let hk' = buffer_write b i v hk in
let mhk' = S.update_heap64 ptr v (get_heap hk) in
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
low_lemma_store_mem64 b i v h;
low_lemma_store_mem64 b i v (Map16.get vfh.vf_heaplets hid);
Vale.Arch.MachineHeap.frame_update_heap64 ptr v h.mh;
Vale.Arch.MachineHeap.frame_update_heap64 ptr v hk.mh;
in_bounds64 hk b i;
Vale.Arch.MachineHeap.same_mem_get_heap_val64 ptr mh' mhk';
lemma_is_full_update vfh h hk hk' hid h.mh mh' hk.mh mhk' mt mt' TUInt64 b ptr 8 i v t;
()
val low_lemma_valid_mem128 (b:buffer128) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b
)
(ensures
S.valid_addr128 (buffer_addr b h + scale16 i) (get_heap h)
)
let low_lemma_valid_mem128 b i h =
lemma_valid_mem128 b i h;
bytes_valid128 (buffer_addr b h + scale16 i) h
val equiv_load_mem128_aux: (ptr:int) -> (h:vale_heap) -> Lemma
(requires valid_mem128 ptr h)
(ensures load_mem128 ptr h == S.get_heap_val128 ptr (get_heap h))
let equiv_load_mem128_aux ptr h =
let t = TUInt128 in
let b = get_addr_ptr t ptr h in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
let addr = buffer_addr b h in
let contents = DV.as_seq (_ih h).IB.hs (get_downview b.bsrc) in
let heap = get_heap h in
S.get_heap_val128_reveal ();
index128_get_heap_val128 h b heap i;
lemma_load_mem128 b i h
let equiv_load_mem128 ptr h =
equiv_load_mem128_aux ptr h
val low_lemma_load_mem128 (b:buffer128) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b
)
(ensures
S.get_heap_val128 (buffer_addr b h + scale16 i) (get_heap h) == buffer_read b i h
) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Memory.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.BufferViewStore.fsti.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Memory_Sems.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.BufferViewStore",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_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
}
] | {
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | b: Vale.X64.Memory.buffer128 -> i: Prims.nat -> h: Vale.Arch.HeapImpl.vale_heap
-> FStar.Pervasives.Lemma
(requires
i < FStar.Seq.Base.length (Vale.X64.Memory.buffer_as_seq h b) /\
Vale.X64.Memory.buffer_readable h b)
(ensures
Vale.Arch.MachineHeap_s.get_heap_val128 (Vale.X64.Memory.buffer_addr b h +
Vale.X64.Memory.scale16 i)
(Vale.X64.Memory_Sems.get_heap h) ==
Vale.X64.Memory.buffer_read b i h) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.X64.Memory.buffer128",
"Prims.nat",
"Vale.Arch.HeapImpl.vale_heap",
"Vale.X64.Memory_Sems.equiv_load_mem128_aux",
"Prims.op_Addition",
"Vale.X64.Memory.buffer_addr",
"Vale.X64.Memory.vuint128",
"Vale.X64.Memory.scale16",
"Prims.unit",
"Vale.X64.Memory.lemma_load_mem128",
"Vale.X64.Memory.lemma_valid_mem128"
] | [] | true | false | true | false | false | let low_lemma_load_mem128 b i h =
| lemma_valid_mem128 b i h;
lemma_load_mem128 b i h;
equiv_load_mem128_aux (buffer_addr b h + scale16 i) h | false |
Vale.X64.Memory_Sems.fst | Vale.X64.Memory_Sems.low_lemma_valid_mem128_64 | val low_lemma_valid_mem128_64 (b:buffer128) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b
)
(ensures
S.valid_addr64 (buffer_addr b h + scale16 i) (get_heap h) /\
S.valid_addr64 (buffer_addr b h + scale16 i + 8) (get_heap h)
) | val low_lemma_valid_mem128_64 (b:buffer128) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b
)
(ensures
S.valid_addr64 (buffer_addr b h + scale16 i) (get_heap h) /\
S.valid_addr64 (buffer_addr b h + scale16 i + 8) (get_heap h)
) | let low_lemma_valid_mem128_64 b i h =
reveal_opaque (`%S.valid_addr64) S.valid_addr64;
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
low_lemma_valid_mem128 b i h;
let ptr = buffer_addr b h + scale16 i in
assert (buffer_addr b h + scale16 i + 8 = ptr + 8) | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory_Sems.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 52,
"end_line": 1015,
"start_col": 0,
"start_line": 1010
} | module Vale.X64.Memory_Sems
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.Def.Words_s
module I = Vale.Interop
module S = Vale.X64.Machine_Semantics_s
module MB = LowStar.Monotonic.Buffer
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
friend Vale.X64.Memory
module IB = Vale.Interop.Base
let same_domain h m = Set.equal (IB.addrs_set (_ih h)) (Map.domain m)
let lemma_same_domains h m1 m2 = ()
let get_heap h = I.down_mem (_ih h)
let upd_heap h m = mi_heap_upd h m
//let lemma_upd_get_heap h = I.down_up_identity (_ih h)
let lemma_get_upd_heap h m = I.up_down_identity (_ih h) m
let lemma_heap_impl = ()
let lemma_heap_get_heap h = ()
let lemma_heap_taint h = ()
//let lemma_heap_upd_heap h mh mt = ()
[@"opaque_to_smt"]
let rec set_of_range (a:int) (n:nat) : Pure (Set.set int)
(requires True)
(ensures fun s -> (forall (i:int).{:pattern Set.mem i s} Set.mem i s <==> a <= i /\ i < a + n))
=
if n = 0 then Set.empty else Set.union (set_of_range a (n - 1)) (Set.singleton (a + n - 1))
let buffer_info_has_addr (bi:buffer_info) (a:int) =
let b = bi.bi_buffer in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
addr <= a /\ a < addr + len
let buffer_info_has_addr_opt (bi:option buffer_info) (a:int) =
match bi with
| None -> False
| Some bi -> buffer_info_has_addr bi a
#set-options "--z3rlimit 100"
let rec make_owns_rec (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
if n = 0 then ((fun _ -> None), (fun _ -> Set.empty)) else
let (m0, s0) = make_owns_rec h bs (n - 1) in
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let s i = if i = hi then Set.union (s0 i) s_b else s0 i in
let m a = if addr <= a && a < addr + len then Some (n - 1) else m0 a in
(m, s)
[@"opaque_to_smt"]
let make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
make_owns_rec h bs n
let rec lemma_make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n <= Seq.length bs /\
(forall (i:nat).{:pattern Seq.index bs i} i < Seq.length bs ==> buffer_readable h (Seq.index bs i).bi_buffer) /\
(forall (i1 i2:nat).{:pattern (Seq.index bs i1); (Seq.index bs i2)}
i1 < Seq.length bs /\ i2 < Seq.length bs ==> buffer_info_disjoint (Seq.index bs i1) (Seq.index bs i2))
)
(ensures (
let (m, s) = make_owns h bs n in
(forall (i:heaplet_id) (a:int).{:pattern Set.mem a (s i)}
(Set.mem a (s i) <==> Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (m a) == Some i) /\
(Set.mem a (s i) ==> buffer_info_has_addr_opt (Option.mapTot (fun n -> Seq.index bs n) (m a)) a) /\
(Set.mem a (s i) ==> Set.mem a (Map.domain h.mh))
) /\
(forall (k:nat) (a:int).{:pattern Set.mem a (s (Seq.index bs k).bi_heaplet)}
k < n /\ buffer_info_has_addr (Seq.index bs k) a ==> Set.mem a (s (Seq.index bs k).bi_heaplet))
))
=
reveal_opaque (`%make_owns) make_owns;
if n = 0 then () else
let _ = make_owns h bs (n - 1) in
let (m, s) = make_owns h bs n in
lemma_make_owns h bs (n - 1);
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let lem1 (a:int) : Lemma
(requires Set.mem a s_b)
(ensures Set.mem a (Map.domain h.mh))
[SMTPat (Set.mem a (Map.domain h.mh))]
=
I.addrs_set_mem h.ih b a
in
let lem2 (i:heaplet_id) (a:int) : Lemma
(requires i =!= hi /\ Set.mem a (Set.intersect s_b (s i)))
(ensures False)
[SMTPat (Set.mem a (s i))]
=
reveal_opaque (`%addr_map_pred) addr_map_pred
in
()
#push-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_loc_mutable_buffers_rec (l:list buffer_info) (s:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n + List.length l == Seq.length s /\
list_to_seq_post l s n
)
(ensures (
let modloc = loc_mutable_buffers l in
forall (i:nat).{:pattern Seq.index s i} n <= i /\ i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes modloc (loc_buffer bi.bi_buffer))
))
(decreases l)
=
match l with
| [] -> ()
| h::t -> lemma_loc_mutable_buffers_rec t s (n + 1)
#pop-options
let lemma_loc_mutable_buffers (l:list buffer_info) : Lemma
(ensures (
let s = list_to_seq l in
forall (i:nat).{:pattern Seq.index s i} i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes (loc_mutable_buffers l) (loc_buffer bi.bi_buffer))
))
=
lemma_list_to_seq l;
lemma_loc_mutable_buffers_rec l (list_to_seq l) 0
let create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let modloc = loc_mutable_buffers buffers in
let layout1 = h1.vf_layout in
let layin1 = layout1.vl_inner in
let (hmap, hsets) = make_owns h1.vf_heap bs (Seq.length bs) in
let hmap a = Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (hmap a) in
let l = {
vl_heaplets_initialized = true;
vl_heaplet_map = hmap;
vl_heaplet_sets = hsets;
vl_old_heap = h1.vf_heap;
vl_buffers = bs;
vl_mod_loc = modloc;
} in
let layout2 = {layout1 with vl_inner = l} in
let h2 = {
vf_layout = layout2;
vf_heap = h1.vf_heap;
vf_heaplets = h1.vf_heaplets;
} in
h2
let lemma_create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let h2 = create_heaplets buffers h1 in
assert (h2.vf_layout.vl_inner.vl_buffers == bs); // REVIEW: why is this necessary, even with extra ifuel?
lemma_make_owns h1.vf_heap bs (Seq.length bs);
lemma_loc_mutable_buffers buffers;
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
let destroy_heaplets h1 =
h1
let lemma_destroy_heaplets h1 =
()
val heap_shift (m1 m2:S.machine_heap) (base:int) (n:nat) : Lemma
(requires (forall i. 0 <= i /\ i < n ==> m1.[base + i] == m2.[base + i]))
(ensures (forall i. {:pattern (m1.[i])} base <= i /\ i < base + n ==> m1.[i] == m2.[i]))
#push-options "--smtencoding.l_arith_repr boxwrap"
let heap_shift m1 m2 base n =
assert (forall i. base <= i /\ i < base + n ==>
m1.[base + (i - base)] == m2.[base + (i - base)])
#pop-options
val same_mem_eq_slices64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 8 + 8 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8)))
let same_mem_eq_slices64 b i v k h1 h2 mem1 mem2 =
let t = TUInt64 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up64 (b:buffer64) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 8}) : Lemma
(scale8 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint64_view in
UV.length_eq vb
val same_mem_get_heap_val64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale8 k in
forall (x:int).{:pattern (mem1.[x])} ptr <= x /\ x < ptr + 8 ==> mem1.[x] == mem2.[x]))
let same_mem_get_heap_val64 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale8 k in
let addr = buffer_addr b h1 in
let aux (x:int{ptr <= x /\ x < ptr + 8}) : Lemma (mem1.[x] == mem2.[x]) =
let i = x - ptr in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices64 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8) (k * 8 + 8)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8) (k * 8 + 8)) in
assert (Seq.index s1 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i));
length_up64 b h1 k i;
assert (mem1.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i)));
assert (Seq.index s2 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i));
length_up64 b h2 k i;
assert (mem2.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i)))
in
Classical.forall_intro aux;
assert (forall i. addr + (scale8 k + i) == ptr + i)
let rec written_buffer_down64_aux1
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(k:nat) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j.{:pattern (mem1.[j]) \/ (mem2.[j])}
base <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem1.[j])}
j >= base /\ j < base + scale8 i ==>
mem1.[j] == mem2.[j]))
(decreases %[i-k]) =
if k >= i then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux1 b i v h base (k+1) h1 mem1 mem2
end
let rec written_buffer_down64_aux2
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(n:nat{n == buffer_length b})
(k:nat{k > i}) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
base + scale8 (i+1) <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
j >= base + scale8 (i+1) /\ j < base + scale8 n ==>
mem1.[j] == mem2.[j]))
(decreases %[n-k]) =
if k >= n then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux2 b i v h base n (k+1) h1 mem1 mem2
end
let written_buffer_down64 (b:buffer64{buffer_writeable b}) (i:nat{i < buffer_length b}) (v:nat64) (h:vale_heap)
: Lemma
(requires List.memP b (IB.ptrs_of_mem (_ih h)))
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
(base <= j /\ j < base + scale8 i) \/
(base + scale8 (i+1) <= j /\ j < base + scale8 n) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
written_buffer_down64_aux1 b i v h base 0 h1 mem1 mem2;
written_buffer_down64_aux2 b i v h base n (i+1) h1 mem1 mem2
let unwritten_buffer_down (t:base_typ) (b:buffer t{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:base_typ_as_vale_type t)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall (a:b8{List.memP a (IB.ptrs_of_mem (_ih h)) /\ a =!= b}) j. {:pattern mem1.[j]; List.memP a (IB.ptrs_of_mem (_ih h)) \/ mem2.[j]; List.memP a (IB.ptrs_of_mem (_ih h))}
let base = (IB.addrs_of_mem (_ih h)) a in
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==> mem1.[j] == mem2.[j]))
= let aux (a:b8{a =!= b /\ List.memP a (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let base = (IB.addrs_of_mem (_ih h)) a in
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall j.
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==>
mem1.[j] == mem2.[j]))
= let db = get_downview a.bsrc in
if DV.length db = 0 then ()
else
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = (IB.addrs_of_mem (_ih h)) a in
let s0 = DV.as_seq (IB.hs_of_mem (_ih h)) db in
let s1 = DV.as_seq (IB.hs_of_mem (_ih h1)) db in
opaque_assert (`%IB.list_disjoint_or_eq) IB.list_disjoint_or_eq IB.list_disjoint_or_eq_def (MB.disjoint a.bsrc b.bsrc);
lemma_dv_equal (IB.down_view a.src) a.bsrc (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1));
assert (Seq.equal s0 s1);
assert (forall (j:int).{:pattern (mem1.[j])}
base <= j /\ j < base + Seq.length s0 ==> v_to_typ TUInt8 (Seq.index s0 (j - base)) == mem1.[j]);
heap_shift mem1 mem2 base (DV.length db)
in
Classical.forall_intro aux
let store_buffer_down64_mem
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
forall (j:int). {:pattern mem1.[j] \/ mem2.[j]}
j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
let aux (j:int)
: Lemma
(j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j])
=
I.addrs_set_lemma_all ();
if j >= base && j < base + DV.length (get_downview b.bsrc) then begin
written_buffer_down64 b i v h;
length_t_eq (TUInt64) b
end
else if not (I.valid_addr (_ih h) j)
then I.same_unspecified_down (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1)) (IB.ptrs_of_mem (_ih h))
else unwritten_buffer_down TUInt64 b i v h
in
Classical.forall_intro aux
let store_buffer_aux_down64_mem (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
forall j. {:pattern mem1.[j] \/ mem2.[j]}
j < ptr \/ j >= ptr + 8 ==>
mem1.[j] == mem2.[j]))
= let t = TUInt64 in
let h1 = store_mem t ptr v h in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
store_buffer_write t ptr v h;
assert (buffer_addr b h + scale8 i == ptr);
assert (buffer_addr b h + scale8 (i+1) == ptr + 8);
store_buffer_down64_mem b i v h
let store_buffer_aux_down64_mem2 (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
S.get_heap_val64 ptr mem2 == v))
= let t = TUInt64 in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
let h1 = store_mem t ptr v h in
let mem2 = I.down_mem (_ih h1) in
store_buffer_write t ptr v h;
assert (Seq.index (buffer_as_seq h1 b) i == v);
index64_get_heap_val64 h1 b mem2 i
let in_bounds64 (h:vale_heap) (b:buffer64) (i:nat{i < buffer_length b})
: Lemma (scale8 i + 8 <= DV.length (get_downview b.bsrc))
=
length_t_eq TUInt64 b
let bytes_valid64 ptr h =
reveal_opaque (`%S.valid_addr64) S.valid_addr64;
let t = TUInt64 in
let b = get_addr_ptr t ptr h in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
in_bounds64 h b i;
I.addrs_set_mem (_ih h) b ptr;
I.addrs_set_mem (_ih h) b (ptr+1);
I.addrs_set_mem (_ih h) b (ptr+2);
I.addrs_set_mem (_ih h) b (ptr+3);
I.addrs_set_mem (_ih h) b (ptr+4);
I.addrs_set_mem (_ih h) b (ptr+5);
I.addrs_set_mem (_ih h) b (ptr+6);
I.addrs_set_mem (_ih h) b (ptr+7)
val same_mem_get_heap_val128 (b:buffer128)
(i:nat{i < buffer_length b})
(v:quad32)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1)) /\ buffer_writeable b})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale16 k in
forall i.{:pattern mem1.[i]} i >= ptr /\ i < ptr+16 ==> mem1.[i] == mem2.[i]))
val same_mem_eq_slices128 (b:buffer128)
(i:nat{i < buffer_length b})
(v:quad32)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1)) /\ buffer_writeable b})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 16 + 16 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 16) (k * 16 + 16) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 16) (k * 16 + 16)))
let same_mem_eq_slices128 b i v k h1 h2 mem1 mem2 =
let t = TUInt128 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up128 (b:buffer128) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 16}) : Lemma
(scale16 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint128_view in
UV.length_eq vb
let same_mem_get_heap_val128 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale16 k in
let addr = buffer_addr b h1 in
let aux (i:nat{ptr <= i /\ i < ptr+16}) : Lemma (mem1.[i] == mem2.[i]) =
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint128_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices128 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16) (k * 16 + 16)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16) (k * 16 + 16)) in
assert (Seq.index s1 (i - ptr) == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16 + (i-ptr)));
length_up128 b h1 k (i-ptr);
assert (mem1.[i] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16 + (i-ptr))));
assert (Seq.index s2 (i-ptr) == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16 + (i-ptr)));
length_up128 b h2 k (i-ptr);
assert (mem2.[addr+(scale16 k + (i-ptr))] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16 + (i-ptr))));
assert (forall i. addr + (scale16 k + (i-ptr)) == i)
in
Classical.forall_intro aux
let in_bounds128 (h:vale_heap) (b:buffer128) (i:nat{i < buffer_length b}) : Lemma
(scale16 i + 16 <= DV.length (get_downview b.bsrc))
=
length_t_eq TUInt128 b
#push-options "--z3rlimit 20"
#restart-solver
let bytes_valid128 ptr h =
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
IB.list_disjoint_or_eq_reveal ();
let t = TUInt128 in
let b = get_addr_ptr t ptr h in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
in_bounds128 h b i;
I.addrs_set_mem (_ih h) b ptr;
I.addrs_set_mem (_ih h) b (ptr+1);
I.addrs_set_mem (_ih h) b (ptr+2);
I.addrs_set_mem (_ih h) b (ptr+3);
I.addrs_set_mem (_ih h) b (ptr+4);
I.addrs_set_mem (_ih h) b (ptr+5);
I.addrs_set_mem (_ih h) b (ptr+6);
I.addrs_set_mem (_ih h) b (ptr+7);
I.addrs_set_mem (_ih h) b (ptr+8);
I.addrs_set_mem (_ih h) b (ptr+9);
I.addrs_set_mem (_ih h) b (ptr+10);
I.addrs_set_mem (_ih h) b (ptr+11);
I.addrs_set_mem (_ih h) b (ptr+12);
I.addrs_set_mem (_ih h) b (ptr+13);
I.addrs_set_mem (_ih h) b (ptr+14);
I.addrs_set_mem (_ih h) b (ptr+15)
#pop-options
let equiv_load_mem64 ptr h =
let t = TUInt64 in
let b = get_addr_ptr t ptr h in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
let addr = buffer_addr b h in
let contents = DV.as_seq (_ih h).IB.hs (get_downview b.bsrc) in
let heap = get_heap h in
index64_get_heap_val64 h b heap i;
lemma_load_mem64 b i h
//let low_lemma_valid_mem64 b i h =
// lemma_valid_mem64 b i h;
// bytes_valid64 (buffer_addr b h + scale8 i) h
//let low_lemma_load_mem64 b i h =
// lemma_valid_mem64 b i h;
// lemma_load_mem64 b i h;
// equiv_load_mem64 (buffer_addr b h + scale8 i) h
//let same_domain_update64 b i v h =
// low_lemma_valid_mem64 b i h;
// Vale.Arch.MachineHeap.same_domain_update64 (buffer_addr b h + scale8 i) v (get_heap h)
open Vale.X64.BufferViewStore
let low_lemma_store_mem64_aux
(b:buffer64)
(heap:S.machine_heap)
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{buffer_readable h b /\ buffer_writeable b})
: Lemma
(requires IB.correct_down_p (_ih h) heap b)
(ensures (let heap' = S.update_heap64 (buffer_addr b h + scale8 i) v heap in
let h' = store_mem64 (buffer_addr b h + scale8 i) v h in
(_ih h').IB.hs == DV.upd_seq (_ih h).IB.hs (get_downview b.bsrc) (I.get_seq_heap heap' (_ih h).IB.addrs b))) =
let ptr = buffer_addr b h + scale8 i in
let heap' = S.update_heap64 ptr v heap in
let h' = store_mem64 ptr v h in
lemma_store_mem64 b i v h;
length_t_eq TUInt64 b;
bv_upd_update_heap64 b heap i v (_ih h);
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db Vale.Interop.Views.up_view64 in
assert (UV.upd (_ih h).IB.hs bv i (UInt64.uint_to_t v) == (_ih h').IB.hs)
val valid_state_store_mem64_aux: (i:nat) -> (v:nat64) -> (h:vale_heap) -> Lemma
(requires writeable_mem64 i h)
(ensures (
let heap = get_heap h in
let heap' = S.update_heap64 i v heap in
let h' = store_mem64 i v h in
heap' == I.down_mem (_ih h')
))
let valid_state_store_mem64_aux i v h =
let heap = get_heap h in
let heap' = S.update_heap64 i v heap in
let h1 = store_mem TUInt64 i v h in
store_buffer_aux_down64_mem i v h;
store_buffer_aux_down64_mem2 i v h;
let mem1 = heap' in
let mem2 = I.down_mem (_ih h1) in
let aux () : Lemma (forall j. mem1.[j] == mem2.[j]) =
Vale.Arch.MachineHeap.same_mem_get_heap_val64 i mem1 mem2;
Vale.Arch.MachineHeap.correct_update_get64 i v heap;
Vale.Arch.MachineHeap.frame_update_heap64 i v heap
in let aux2 () : Lemma (Set.equal (Map.domain mem1) (Map.domain mem2)) =
bytes_valid64 i h;
Vale.Arch.MachineHeap.same_domain_update64 i v heap
in aux(); aux2();
Map.lemma_equal_intro mem1 mem2
let low_lemma_load_mem64_full b i vfh t hid =
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
#push-options "--z3rlimit 20"
#restart-solver
let low_lemma_store_mem64 b i v h =
lemma_writeable_mem64 b i h;
lemma_store_mem64 b i v h;
valid_state_store_mem64_aux (buffer_addr b h + scale8 i) v h;
let heap = get_heap h in
let heap' = S.update_heap64 (buffer_addr b h + scale8 i) v heap in
low_lemma_store_mem64_aux b heap i v h;
Vale.Arch.MachineHeap.frame_update_heap64 (buffer_addr b h + scale8 i) v heap;
in_bounds64 h b i;
I.addrs_set_lemma_all ();
I.update_buffer_up_mem (_ih h) b heap heap'
#pop-options
#set-options "--z3rlimit 100"
#restart-solver
let lemma_is_full_update
(vfh:vale_full_heap) (h hk hk':vale_heap) (k:heaplet_id) (mh mh' mhk mhk':machine_heap) (mt mt':memtaint)
(t:base_typ) (b:buffer t) (ptr:int) (v_size:nat)
(index:nat) (v:base_typ_as_vale_type t) (tn:taint)
: Lemma
(requires
vfh.vf_layout.vl_inner.vl_heaplets_initialized /\
mem_inv vfh /\
buffer_readable hk b /\
buffer_writeable b /\
index < Seq.length (buffer_as_seq hk b) /\
mt == vfh.vf_layout.vl_taint /\
h == vfh.vf_heap /\
hk == Map16.sel vfh.vf_heaplets k /\
mh == h.mh /\
mhk == hk.mh /\
ptr == buffer_addr b hk + scale_by v_size index /\
mt' == S.update_n ptr v_size (heap_taint (coerce vfh)) tn /\
hk' == buffer_write b index v hk /\
valid_layout_buffer b vfh.vf_layout hk true /\
valid_taint_buf b hk mt tn /\
is_machine_heap_update mh mh' /\ upd_heap h mh' == buffer_write b index v h /\
is_machine_heap_update mhk mhk' /\ upd_heap hk mhk' == buffer_write b index v hk /\
(forall j.{:pattern mh.[j] \/ mh'.[j]} j < ptr \/ j >= ptr + v_size ==> mh.[j] == mh'.[j]) /\
(forall j.{:pattern mhk.[j] \/ mhk'.[j]} j < ptr \/ j >= ptr + v_size ==> mhk.[j] == mhk'.[j]) /\
0 <= scale_by v_size index /\ scale_by v_size index + v_size <= DV.length (get_downview b.bsrc) /\
(forall i.{:pattern mh'.[i] \/ mhk'.[i]} i >= ptr /\ i < ptr + v_size ==> mh'.[i] == mhk'.[i]) /\
True
)
(ensures is_full_update vfh hk' k mh' mt')
=
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
let vfh' = coerce (heap_upd (coerce vfh) mh' mt') in
let dom_upd = Set.intersect (vfh.vf_layout.vl_inner.vl_heaplet_sets k) (Map.domain mhk) in
let mhk'' = Map.concat mhk (Map.restrict dom_upd mh') in
assert (Map.equal mhk'' mhk');
let unchanged (j:heaplet_id) : Lemma
(requires j =!= k)
(ensures Map16.sel vfh'.vf_heaplets j == Map16.sel vfh.vf_heaplets j)
[SMTPat (Map16.sel vfh'.vf_heaplets j)]
=
assert (Map.equal (Map16.sel vfh'.vf_heaplets j).mh (Map16.sel vfh.vf_heaplets j).mh);
I.down_up_identity (Map16.sel vfh.vf_heaplets j).ih;
()
in
assert (Map16.equal vfh'.vf_heaplets (Map16.upd vfh.vf_heaplets k hk'));
assert (Map.equal mt' mt);
Vale.Interop.Heap_s.list_disjoint_or_eq_reveal ();
()
let low_lemma_store_mem64_full b i v vfh t hid =
let (h, mt, hk) = (vfh.vf_heap, vfh.vf_layout.vl_taint, Map16.get vfh.vf_heaplets hid) in
let ptr = buffer_addr b hk + scale8 i in
let mh' = S.update_heap64 ptr v (heap_get (coerce vfh)) in
let mt' = S.update_n ptr 8 (heap_taint (coerce vfh)) t in
let hk' = buffer_write b i v hk in
let mhk' = S.update_heap64 ptr v (get_heap hk) in
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
low_lemma_store_mem64 b i v h;
low_lemma_store_mem64 b i v (Map16.get vfh.vf_heaplets hid);
Vale.Arch.MachineHeap.frame_update_heap64 ptr v h.mh;
Vale.Arch.MachineHeap.frame_update_heap64 ptr v hk.mh;
in_bounds64 hk b i;
Vale.Arch.MachineHeap.same_mem_get_heap_val64 ptr mh' mhk';
lemma_is_full_update vfh h hk hk' hid h.mh mh' hk.mh mhk' mt mt' TUInt64 b ptr 8 i v t;
()
val low_lemma_valid_mem128 (b:buffer128) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b
)
(ensures
S.valid_addr128 (buffer_addr b h + scale16 i) (get_heap h)
)
let low_lemma_valid_mem128 b i h =
lemma_valid_mem128 b i h;
bytes_valid128 (buffer_addr b h + scale16 i) h
val equiv_load_mem128_aux: (ptr:int) -> (h:vale_heap) -> Lemma
(requires valid_mem128 ptr h)
(ensures load_mem128 ptr h == S.get_heap_val128 ptr (get_heap h))
let equiv_load_mem128_aux ptr h =
let t = TUInt128 in
let b = get_addr_ptr t ptr h in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
let addr = buffer_addr b h in
let contents = DV.as_seq (_ih h).IB.hs (get_downview b.bsrc) in
let heap = get_heap h in
S.get_heap_val128_reveal ();
index128_get_heap_val128 h b heap i;
lemma_load_mem128 b i h
let equiv_load_mem128 ptr h =
equiv_load_mem128_aux ptr h
val low_lemma_load_mem128 (b:buffer128) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b
)
(ensures
S.get_heap_val128 (buffer_addr b h + scale16 i) (get_heap h) == buffer_read b i h
)
let low_lemma_load_mem128 b i h =
lemma_valid_mem128 b i h;
lemma_load_mem128 b i h;
equiv_load_mem128_aux (buffer_addr b h + scale16 i) h
//let same_domain_update128 b i v h =
// low_lemma_valid_mem128 b i h;
// Vale.Arch.MachineHeap.same_domain_update128 (buffer_addr b h + scale16 i) v (get_heap h)
let low_lemma_store_mem128_aux
(b:buffer128)
(heap:S.machine_heap)
(i:nat{i < buffer_length b})
(v:quad32)
(h:vale_heap{buffer_readable h b /\ buffer_writeable b})
: Lemma
(requires IB.correct_down_p (_ih h) heap b)
(ensures (let heap' = S.update_heap128 (buffer_addr b h + scale16 i) v heap in
let h' = store_mem128 (buffer_addr b h + scale16 i) v h in
(_ih h').IB.hs == DV.upd_seq (_ih h).IB.hs (get_downview b.bsrc) (I.get_seq_heap heap' (_ih h).IB.addrs b))) =
let ptr = buffer_addr b h + scale16 i in
let heap' = S.update_heap128 ptr v heap in
let h' = store_mem128 ptr v h in
lemma_store_mem128 b i v h;
length_t_eq TUInt128 b;
bv_upd_update_heap128 b heap i v (_ih h);
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db Vale.Interop.Views.up_view128 in
assert (UV.upd (_ih h).IB.hs bv i v == (_ih h').IB.hs)
val valid_state_store_mem128_aux (i:int) (v:quad32) (h:vale_heap) : Lemma
(requires writeable_mem128 i h)
(ensures (
let heap = get_heap h in
let heap' = S.update_heap128 i v heap in
let h' = store_mem128 i v h in
heap' == I.down_mem (_ih h')
))
#restart-solver
let rec written_buffer_down128_aux1
(b:buffer128{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:quad32)
(h:vale_heap{List.memP b (_ih h).IB.ptrs})
(base:nat{base == buffer_addr b h})
(k:nat) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j.{:pattern (mem1.[j]) \/ (mem2.[j])}
base <= j /\ j < base + k * 16 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem1.[j])}
j >= base /\ j < base + scale16 i ==>
mem1.[j] == mem2.[j]))
(decreases %[i-k]) =
if k >= i then ()
else begin
let ptr = base + scale16 k in
same_mem_get_heap_val128 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 16;
written_buffer_down128_aux1 b i v h base (k+1) h1 mem1 mem2
end
#restart-solver
let rec written_buffer_down128_aux2
(b:buffer128{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:quad32)
(h:vale_heap{List.memP b (_ih h).IB.ptrs})
(base:nat{base == buffer_addr b h})
(n:nat{n == buffer_length b})
(k:nat{k > i}) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
base + scale16 (i+1) <= j /\ j < base + k * 16 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
j >= base + scale16 (i+1) /\ j < base + scale16 n ==>
mem1.[j] == mem2.[j]))
(decreases %[n-k]) =
if k >= n then ()
else begin
let ptr = base + scale16 k in
same_mem_get_heap_val128 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 16;
written_buffer_down128_aux2 b i v h base n (k+1) h1 mem1 mem2
end
let written_buffer_down128 (b:buffer128) (i:nat{i < buffer_length b}) (v:quad32) (h:vale_heap)
: Lemma
(requires List.memP b (_ih h).IB.ptrs /\ buffer_writeable b)
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
(base <= j /\ j < base + scale16 i) \/
(base + scale16 (i+1) <= j /\ j < base + scale16 n) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
written_buffer_down128_aux1 b i v h base 0 h1 mem1 mem2;
written_buffer_down128_aux2 b i v h base n (i+1) h1 mem1 mem2
let store_buffer_down128_mem
(b:buffer128{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:quad32)
(h:vale_heap{List.memP b (_ih h).IB.ptrs})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
forall (j:int). {:pattern mem1.[j] \/ mem2.[j]}
j < base + scale16 i \/ j >= base + scale16 (i+1) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
let aux (j:int)
: Lemma
(j < base + scale16 i \/ j >= base + scale16 (i+1) ==>
mem1.[j] == mem2.[j])
=
I.addrs_set_lemma_all ();
if j >= base && j < base + DV.length (get_downview b.bsrc) then begin
written_buffer_down128 b i v h;
length_t_eq TUInt128 b
end
else if not (I.valid_addr (_ih h) j)
then I.same_unspecified_down (_ih h).IB.hs (_ih h1).IB.hs (_ih h).IB.ptrs
else unwritten_buffer_down TUInt128 b i v h
in
Classical.forall_intro aux
let store_buffer_aux_down128_mem (ptr:int) (v:quad32) (h:vale_heap{writeable_mem128 ptr h})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = store_mem TUInt128 ptr v h in
let mem2 = I.down_mem (_ih h1) in
forall j. {:pattern mem1.[j] \/ mem2.[j]}
j < ptr \/ j >= ptr + 16 ==>
mem1.[j] == mem2.[j]))
= let t = TUInt128 in
let h1 = store_mem t ptr v h in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
store_buffer_write t ptr v h;
assert (buffer_addr b h + scale16 i == ptr);
assert (buffer_addr b h + scale16 (i+1) == ptr + 16);
store_buffer_down128_mem b i v h
let store_buffer_aux_down128_mem2 (ptr:int) (v:quad32) (h:vale_heap{writeable_mem128 ptr h})
: Lemma
(ensures (
let h1 = store_mem TUInt128 ptr v h in
let mem2 = I.down_mem (_ih h1) in
Mkfour
(S.get_heap_val32 ptr mem2)
(S.get_heap_val32 (ptr+4) mem2)
(S.get_heap_val32 (ptr+8) mem2)
(S.get_heap_val32 (ptr+12) mem2)
== v)) =
let t = TUInt128 in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
let h1 = store_mem t ptr v h in
let mem2 = I.down_mem (_ih h1) in
store_buffer_write t ptr v h;
assert (Seq.index (buffer_as_seq h1 b) i == v);
index128_get_heap_val128 h1 b mem2 i
let valid_state_store_mem128_aux i v h =
let heap = get_heap h in
let heap' = S.update_heap128 i v heap in
let h1 = store_mem TUInt128 i v h in
store_buffer_aux_down128_mem i v h;
store_buffer_aux_down128_mem2 i v h;
let mem1 = heap' in
let mem2 = I.down_mem (_ih h1) in
let aux () : Lemma (forall j. mem1.[j] == mem2.[j]) =
Vale.Arch.MachineHeap.correct_update_get128 i v heap;
Vale.X64.Machine_Semantics_s.get_heap_val128_reveal ();
Vale.Arch.MachineHeap.same_mem_get_heap_val32 i mem1 mem2;
Vale.Arch.MachineHeap.same_mem_get_heap_val32 (i+4) mem1 mem2;
Vale.Arch.MachineHeap.same_mem_get_heap_val32 (i+8) mem1 mem2;
Vale.Arch.MachineHeap.same_mem_get_heap_val32 (i+12) mem1 mem2;
Vale.Arch.MachineHeap.frame_update_heap128 i v heap
in
let aux2 () : Lemma (Set.equal (Map.domain mem1) (Map.domain mem2)) =
bytes_valid128 i h;
Vale.Arch.MachineHeap.same_domain_update128 i v heap
in aux (); aux2 ();
Map.lemma_equal_intro mem1 mem2
let low_lemma_load_mem128_full b i vfh t hid =
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
let low_lemma_store_mem128 b i v h =
lemma_valid_mem128 b i h;
lemma_store_mem128 b i v h;
valid_state_store_mem128_aux (buffer_addr b h + scale16 i) v h;
let heap = get_heap h in
let heap' = S.update_heap128 (buffer_addr b h + scale16 i) v heap in
let h' = store_mem128 (buffer_addr b h + scale16 i) v h in
low_lemma_store_mem128_aux b heap i v h;
Vale.Arch.MachineHeap.frame_update_heap128 (buffer_addr b h + scale16 i) v heap;
in_bounds128 h b i;
I.addrs_set_lemma_all ();
I.update_buffer_up_mem (_ih h) b heap heap'
let low_lemma_store_mem128_full b i v vfh t hid =
let (h, mt, hk) = (vfh.vf_heap, vfh.vf_layout.vl_taint, Map16.get vfh.vf_heaplets hid) in
let ptr = buffer_addr b hk + scale16 i in
let mh' = S.update_heap128 ptr v (heap_get (coerce vfh)) in
let mt' = S.update_n ptr 16 (heap_taint (coerce vfh)) t in
let hk' = buffer_write b i v hk in
let mhk' = S.update_heap128 ptr v (get_heap hk) in
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
low_lemma_store_mem128 b i v h;
low_lemma_store_mem128 b i v (Map16.get vfh.vf_heaplets hid);
Vale.Arch.MachineHeap.frame_update_heap128 ptr v h.mh;
Vale.Arch.MachineHeap.frame_update_heap128 ptr v hk.mh;
in_bounds128 hk b i;
Vale.Arch.MachineHeap.same_mem_get_heap_val128 ptr mh' mhk';
lemma_is_full_update vfh h hk hk' hid h.mh mh' hk.mh mhk' mt mt' TUInt128 b ptr 16 i v t;
() | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Memory.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.BufferViewStore.fsti.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Memory_Sems.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.BufferViewStore",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_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
}
] | {
"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": "boxwrap",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | b: Vale.X64.Memory.buffer128 -> i: Prims.nat -> h: Vale.Arch.HeapImpl.vale_heap
-> FStar.Pervasives.Lemma
(requires
i < FStar.Seq.Base.length (Vale.X64.Memory.buffer_as_seq h b) /\
Vale.X64.Memory.buffer_readable h b)
(ensures
Vale.Arch.MachineHeap_s.valid_addr64 (Vale.X64.Memory.buffer_addr b h +
Vale.X64.Memory.scale16 i)
(Vale.X64.Memory_Sems.get_heap h) /\
Vale.Arch.MachineHeap_s.valid_addr64 (Vale.X64.Memory.buffer_addr b h +
Vale.X64.Memory.scale16 i +
8)
(Vale.X64.Memory_Sems.get_heap h)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.X64.Memory.buffer128",
"Prims.nat",
"Vale.Arch.HeapImpl.vale_heap",
"Prims._assert",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"Prims.op_Addition",
"Vale.X64.Memory.buffer_addr",
"Vale.X64.Memory.vuint128",
"Vale.X64.Memory.scale16",
"Prims.unit",
"Vale.X64.Memory_Sems.low_lemma_valid_mem128",
"FStar.Pervasives.reveal_opaque",
"Vale.Arch.MachineHeap_s.machine_heap",
"Prims.bool",
"Vale.Arch.MachineHeap_s.valid_addr128",
"Vale.Arch.MachineHeap_s.valid_addr64"
] | [] | true | false | true | false | false | let low_lemma_valid_mem128_64 b i h =
| reveal_opaque (`%S.valid_addr64) S.valid_addr64;
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
low_lemma_valid_mem128 b i h;
let ptr = buffer_addr b h + scale16 i in
assert (buffer_addr b h + scale16 i + 8 = ptr + 8) | false |
Vale.X64.Memory_Sems.fst | Vale.X64.Memory_Sems.low_lemma_store_mem128_aux | val low_lemma_store_mem128_aux
(b: buffer128)
(heap: S.machine_heap)
(i: nat{i < buffer_length b})
(v: quad32)
(h: vale_heap{buffer_readable h b /\ buffer_writeable b})
: Lemma (requires IB.correct_down_p (_ih h) heap b)
(ensures
(let heap' = S.update_heap128 (buffer_addr b h + scale16 i) v heap in
let h' = store_mem128 (buffer_addr b h + scale16 i) v h in
(_ih h').IB.hs ==
DV.upd_seq (_ih h).IB.hs (get_downview b.bsrc) (I.get_seq_heap heap' (_ih h).IB.addrs b))) | val low_lemma_store_mem128_aux
(b: buffer128)
(heap: S.machine_heap)
(i: nat{i < buffer_length b})
(v: quad32)
(h: vale_heap{buffer_readable h b /\ buffer_writeable b})
: Lemma (requires IB.correct_down_p (_ih h) heap b)
(ensures
(let heap' = S.update_heap128 (buffer_addr b h + scale16 i) v heap in
let h' = store_mem128 (buffer_addr b h + scale16 i) v h in
(_ih h').IB.hs ==
DV.upd_seq (_ih h).IB.hs (get_downview b.bsrc) (I.get_seq_heap heap' (_ih h).IB.addrs b))) | let low_lemma_store_mem128_aux
(b:buffer128)
(heap:S.machine_heap)
(i:nat{i < buffer_length b})
(v:quad32)
(h:vale_heap{buffer_readable h b /\ buffer_writeable b})
: Lemma
(requires IB.correct_down_p (_ih h) heap b)
(ensures (let heap' = S.update_heap128 (buffer_addr b h + scale16 i) v heap in
let h' = store_mem128 (buffer_addr b h + scale16 i) v h in
(_ih h').IB.hs == DV.upd_seq (_ih h).IB.hs (get_downview b.bsrc) (I.get_seq_heap heap' (_ih h).IB.addrs b))) =
let ptr = buffer_addr b h + scale16 i in
let heap' = S.update_heap128 ptr v heap in
let h' = store_mem128 ptr v h in
lemma_store_mem128 b i v h;
length_t_eq TUInt128 b;
bv_upd_update_heap128 b heap i v (_ih h);
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db Vale.Interop.Views.up_view128 in
assert (UV.upd (_ih h).IB.hs bv i v == (_ih h').IB.hs) | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory_Sems.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 57,
"end_line": 792,
"start_col": 0,
"start_line": 773
} | module Vale.X64.Memory_Sems
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.Def.Words_s
module I = Vale.Interop
module S = Vale.X64.Machine_Semantics_s
module MB = LowStar.Monotonic.Buffer
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
friend Vale.X64.Memory
module IB = Vale.Interop.Base
let same_domain h m = Set.equal (IB.addrs_set (_ih h)) (Map.domain m)
let lemma_same_domains h m1 m2 = ()
let get_heap h = I.down_mem (_ih h)
let upd_heap h m = mi_heap_upd h m
//let lemma_upd_get_heap h = I.down_up_identity (_ih h)
let lemma_get_upd_heap h m = I.up_down_identity (_ih h) m
let lemma_heap_impl = ()
let lemma_heap_get_heap h = ()
let lemma_heap_taint h = ()
//let lemma_heap_upd_heap h mh mt = ()
[@"opaque_to_smt"]
let rec set_of_range (a:int) (n:nat) : Pure (Set.set int)
(requires True)
(ensures fun s -> (forall (i:int).{:pattern Set.mem i s} Set.mem i s <==> a <= i /\ i < a + n))
=
if n = 0 then Set.empty else Set.union (set_of_range a (n - 1)) (Set.singleton (a + n - 1))
let buffer_info_has_addr (bi:buffer_info) (a:int) =
let b = bi.bi_buffer in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
addr <= a /\ a < addr + len
let buffer_info_has_addr_opt (bi:option buffer_info) (a:int) =
match bi with
| None -> False
| Some bi -> buffer_info_has_addr bi a
#set-options "--z3rlimit 100"
let rec make_owns_rec (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
if n = 0 then ((fun _ -> None), (fun _ -> Set.empty)) else
let (m0, s0) = make_owns_rec h bs (n - 1) in
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let s i = if i = hi then Set.union (s0 i) s_b else s0 i in
let m a = if addr <= a && a < addr + len then Some (n - 1) else m0 a in
(m, s)
[@"opaque_to_smt"]
let make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
make_owns_rec h bs n
let rec lemma_make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n <= Seq.length bs /\
(forall (i:nat).{:pattern Seq.index bs i} i < Seq.length bs ==> buffer_readable h (Seq.index bs i).bi_buffer) /\
(forall (i1 i2:nat).{:pattern (Seq.index bs i1); (Seq.index bs i2)}
i1 < Seq.length bs /\ i2 < Seq.length bs ==> buffer_info_disjoint (Seq.index bs i1) (Seq.index bs i2))
)
(ensures (
let (m, s) = make_owns h bs n in
(forall (i:heaplet_id) (a:int).{:pattern Set.mem a (s i)}
(Set.mem a (s i) <==> Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (m a) == Some i) /\
(Set.mem a (s i) ==> buffer_info_has_addr_opt (Option.mapTot (fun n -> Seq.index bs n) (m a)) a) /\
(Set.mem a (s i) ==> Set.mem a (Map.domain h.mh))
) /\
(forall (k:nat) (a:int).{:pattern Set.mem a (s (Seq.index bs k).bi_heaplet)}
k < n /\ buffer_info_has_addr (Seq.index bs k) a ==> Set.mem a (s (Seq.index bs k).bi_heaplet))
))
=
reveal_opaque (`%make_owns) make_owns;
if n = 0 then () else
let _ = make_owns h bs (n - 1) in
let (m, s) = make_owns h bs n in
lemma_make_owns h bs (n - 1);
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let lem1 (a:int) : Lemma
(requires Set.mem a s_b)
(ensures Set.mem a (Map.domain h.mh))
[SMTPat (Set.mem a (Map.domain h.mh))]
=
I.addrs_set_mem h.ih b a
in
let lem2 (i:heaplet_id) (a:int) : Lemma
(requires i =!= hi /\ Set.mem a (Set.intersect s_b (s i)))
(ensures False)
[SMTPat (Set.mem a (s i))]
=
reveal_opaque (`%addr_map_pred) addr_map_pred
in
()
#push-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_loc_mutable_buffers_rec (l:list buffer_info) (s:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n + List.length l == Seq.length s /\
list_to_seq_post l s n
)
(ensures (
let modloc = loc_mutable_buffers l in
forall (i:nat).{:pattern Seq.index s i} n <= i /\ i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes modloc (loc_buffer bi.bi_buffer))
))
(decreases l)
=
match l with
| [] -> ()
| h::t -> lemma_loc_mutable_buffers_rec t s (n + 1)
#pop-options
let lemma_loc_mutable_buffers (l:list buffer_info) : Lemma
(ensures (
let s = list_to_seq l in
forall (i:nat).{:pattern Seq.index s i} i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes (loc_mutable_buffers l) (loc_buffer bi.bi_buffer))
))
=
lemma_list_to_seq l;
lemma_loc_mutable_buffers_rec l (list_to_seq l) 0
let create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let modloc = loc_mutable_buffers buffers in
let layout1 = h1.vf_layout in
let layin1 = layout1.vl_inner in
let (hmap, hsets) = make_owns h1.vf_heap bs (Seq.length bs) in
let hmap a = Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (hmap a) in
let l = {
vl_heaplets_initialized = true;
vl_heaplet_map = hmap;
vl_heaplet_sets = hsets;
vl_old_heap = h1.vf_heap;
vl_buffers = bs;
vl_mod_loc = modloc;
} in
let layout2 = {layout1 with vl_inner = l} in
let h2 = {
vf_layout = layout2;
vf_heap = h1.vf_heap;
vf_heaplets = h1.vf_heaplets;
} in
h2
let lemma_create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let h2 = create_heaplets buffers h1 in
assert (h2.vf_layout.vl_inner.vl_buffers == bs); // REVIEW: why is this necessary, even with extra ifuel?
lemma_make_owns h1.vf_heap bs (Seq.length bs);
lemma_loc_mutable_buffers buffers;
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
let destroy_heaplets h1 =
h1
let lemma_destroy_heaplets h1 =
()
val heap_shift (m1 m2:S.machine_heap) (base:int) (n:nat) : Lemma
(requires (forall i. 0 <= i /\ i < n ==> m1.[base + i] == m2.[base + i]))
(ensures (forall i. {:pattern (m1.[i])} base <= i /\ i < base + n ==> m1.[i] == m2.[i]))
#push-options "--smtencoding.l_arith_repr boxwrap"
let heap_shift m1 m2 base n =
assert (forall i. base <= i /\ i < base + n ==>
m1.[base + (i - base)] == m2.[base + (i - base)])
#pop-options
val same_mem_eq_slices64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 8 + 8 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8)))
let same_mem_eq_slices64 b i v k h1 h2 mem1 mem2 =
let t = TUInt64 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up64 (b:buffer64) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 8}) : Lemma
(scale8 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint64_view in
UV.length_eq vb
val same_mem_get_heap_val64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale8 k in
forall (x:int).{:pattern (mem1.[x])} ptr <= x /\ x < ptr + 8 ==> mem1.[x] == mem2.[x]))
let same_mem_get_heap_val64 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale8 k in
let addr = buffer_addr b h1 in
let aux (x:int{ptr <= x /\ x < ptr + 8}) : Lemma (mem1.[x] == mem2.[x]) =
let i = x - ptr in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices64 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8) (k * 8 + 8)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8) (k * 8 + 8)) in
assert (Seq.index s1 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i));
length_up64 b h1 k i;
assert (mem1.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i)));
assert (Seq.index s2 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i));
length_up64 b h2 k i;
assert (mem2.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i)))
in
Classical.forall_intro aux;
assert (forall i. addr + (scale8 k + i) == ptr + i)
let rec written_buffer_down64_aux1
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(k:nat) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j.{:pattern (mem1.[j]) \/ (mem2.[j])}
base <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem1.[j])}
j >= base /\ j < base + scale8 i ==>
mem1.[j] == mem2.[j]))
(decreases %[i-k]) =
if k >= i then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux1 b i v h base (k+1) h1 mem1 mem2
end
let rec written_buffer_down64_aux2
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(n:nat{n == buffer_length b})
(k:nat{k > i}) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
base + scale8 (i+1) <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
j >= base + scale8 (i+1) /\ j < base + scale8 n ==>
mem1.[j] == mem2.[j]))
(decreases %[n-k]) =
if k >= n then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux2 b i v h base n (k+1) h1 mem1 mem2
end
let written_buffer_down64 (b:buffer64{buffer_writeable b}) (i:nat{i < buffer_length b}) (v:nat64) (h:vale_heap)
: Lemma
(requires List.memP b (IB.ptrs_of_mem (_ih h)))
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
(base <= j /\ j < base + scale8 i) \/
(base + scale8 (i+1) <= j /\ j < base + scale8 n) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
written_buffer_down64_aux1 b i v h base 0 h1 mem1 mem2;
written_buffer_down64_aux2 b i v h base n (i+1) h1 mem1 mem2
let unwritten_buffer_down (t:base_typ) (b:buffer t{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:base_typ_as_vale_type t)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall (a:b8{List.memP a (IB.ptrs_of_mem (_ih h)) /\ a =!= b}) j. {:pattern mem1.[j]; List.memP a (IB.ptrs_of_mem (_ih h)) \/ mem2.[j]; List.memP a (IB.ptrs_of_mem (_ih h))}
let base = (IB.addrs_of_mem (_ih h)) a in
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==> mem1.[j] == mem2.[j]))
= let aux (a:b8{a =!= b /\ List.memP a (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let base = (IB.addrs_of_mem (_ih h)) a in
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall j.
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==>
mem1.[j] == mem2.[j]))
= let db = get_downview a.bsrc in
if DV.length db = 0 then ()
else
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = (IB.addrs_of_mem (_ih h)) a in
let s0 = DV.as_seq (IB.hs_of_mem (_ih h)) db in
let s1 = DV.as_seq (IB.hs_of_mem (_ih h1)) db in
opaque_assert (`%IB.list_disjoint_or_eq) IB.list_disjoint_or_eq IB.list_disjoint_or_eq_def (MB.disjoint a.bsrc b.bsrc);
lemma_dv_equal (IB.down_view a.src) a.bsrc (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1));
assert (Seq.equal s0 s1);
assert (forall (j:int).{:pattern (mem1.[j])}
base <= j /\ j < base + Seq.length s0 ==> v_to_typ TUInt8 (Seq.index s0 (j - base)) == mem1.[j]);
heap_shift mem1 mem2 base (DV.length db)
in
Classical.forall_intro aux
let store_buffer_down64_mem
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
forall (j:int). {:pattern mem1.[j] \/ mem2.[j]}
j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
let aux (j:int)
: Lemma
(j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j])
=
I.addrs_set_lemma_all ();
if j >= base && j < base + DV.length (get_downview b.bsrc) then begin
written_buffer_down64 b i v h;
length_t_eq (TUInt64) b
end
else if not (I.valid_addr (_ih h) j)
then I.same_unspecified_down (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1)) (IB.ptrs_of_mem (_ih h))
else unwritten_buffer_down TUInt64 b i v h
in
Classical.forall_intro aux
let store_buffer_aux_down64_mem (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
forall j. {:pattern mem1.[j] \/ mem2.[j]}
j < ptr \/ j >= ptr + 8 ==>
mem1.[j] == mem2.[j]))
= let t = TUInt64 in
let h1 = store_mem t ptr v h in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
store_buffer_write t ptr v h;
assert (buffer_addr b h + scale8 i == ptr);
assert (buffer_addr b h + scale8 (i+1) == ptr + 8);
store_buffer_down64_mem b i v h
let store_buffer_aux_down64_mem2 (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
S.get_heap_val64 ptr mem2 == v))
= let t = TUInt64 in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
let h1 = store_mem t ptr v h in
let mem2 = I.down_mem (_ih h1) in
store_buffer_write t ptr v h;
assert (Seq.index (buffer_as_seq h1 b) i == v);
index64_get_heap_val64 h1 b mem2 i
let in_bounds64 (h:vale_heap) (b:buffer64) (i:nat{i < buffer_length b})
: Lemma (scale8 i + 8 <= DV.length (get_downview b.bsrc))
=
length_t_eq TUInt64 b
let bytes_valid64 ptr h =
reveal_opaque (`%S.valid_addr64) S.valid_addr64;
let t = TUInt64 in
let b = get_addr_ptr t ptr h in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
in_bounds64 h b i;
I.addrs_set_mem (_ih h) b ptr;
I.addrs_set_mem (_ih h) b (ptr+1);
I.addrs_set_mem (_ih h) b (ptr+2);
I.addrs_set_mem (_ih h) b (ptr+3);
I.addrs_set_mem (_ih h) b (ptr+4);
I.addrs_set_mem (_ih h) b (ptr+5);
I.addrs_set_mem (_ih h) b (ptr+6);
I.addrs_set_mem (_ih h) b (ptr+7)
val same_mem_get_heap_val128 (b:buffer128)
(i:nat{i < buffer_length b})
(v:quad32)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1)) /\ buffer_writeable b})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale16 k in
forall i.{:pattern mem1.[i]} i >= ptr /\ i < ptr+16 ==> mem1.[i] == mem2.[i]))
val same_mem_eq_slices128 (b:buffer128)
(i:nat{i < buffer_length b})
(v:quad32)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1)) /\ buffer_writeable b})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 16 + 16 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 16) (k * 16 + 16) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 16) (k * 16 + 16)))
let same_mem_eq_slices128 b i v k h1 h2 mem1 mem2 =
let t = TUInt128 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up128 (b:buffer128) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 16}) : Lemma
(scale16 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint128_view in
UV.length_eq vb
let same_mem_get_heap_val128 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale16 k in
let addr = buffer_addr b h1 in
let aux (i:nat{ptr <= i /\ i < ptr+16}) : Lemma (mem1.[i] == mem2.[i]) =
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint128_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices128 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16) (k * 16 + 16)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16) (k * 16 + 16)) in
assert (Seq.index s1 (i - ptr) == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16 + (i-ptr)));
length_up128 b h1 k (i-ptr);
assert (mem1.[i] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16 + (i-ptr))));
assert (Seq.index s2 (i-ptr) == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16 + (i-ptr)));
length_up128 b h2 k (i-ptr);
assert (mem2.[addr+(scale16 k + (i-ptr))] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16 + (i-ptr))));
assert (forall i. addr + (scale16 k + (i-ptr)) == i)
in
Classical.forall_intro aux
let in_bounds128 (h:vale_heap) (b:buffer128) (i:nat{i < buffer_length b}) : Lemma
(scale16 i + 16 <= DV.length (get_downview b.bsrc))
=
length_t_eq TUInt128 b
#push-options "--z3rlimit 20"
#restart-solver
let bytes_valid128 ptr h =
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
IB.list_disjoint_or_eq_reveal ();
let t = TUInt128 in
let b = get_addr_ptr t ptr h in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
in_bounds128 h b i;
I.addrs_set_mem (_ih h) b ptr;
I.addrs_set_mem (_ih h) b (ptr+1);
I.addrs_set_mem (_ih h) b (ptr+2);
I.addrs_set_mem (_ih h) b (ptr+3);
I.addrs_set_mem (_ih h) b (ptr+4);
I.addrs_set_mem (_ih h) b (ptr+5);
I.addrs_set_mem (_ih h) b (ptr+6);
I.addrs_set_mem (_ih h) b (ptr+7);
I.addrs_set_mem (_ih h) b (ptr+8);
I.addrs_set_mem (_ih h) b (ptr+9);
I.addrs_set_mem (_ih h) b (ptr+10);
I.addrs_set_mem (_ih h) b (ptr+11);
I.addrs_set_mem (_ih h) b (ptr+12);
I.addrs_set_mem (_ih h) b (ptr+13);
I.addrs_set_mem (_ih h) b (ptr+14);
I.addrs_set_mem (_ih h) b (ptr+15)
#pop-options
let equiv_load_mem64 ptr h =
let t = TUInt64 in
let b = get_addr_ptr t ptr h in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
let addr = buffer_addr b h in
let contents = DV.as_seq (_ih h).IB.hs (get_downview b.bsrc) in
let heap = get_heap h in
index64_get_heap_val64 h b heap i;
lemma_load_mem64 b i h
//let low_lemma_valid_mem64 b i h =
// lemma_valid_mem64 b i h;
// bytes_valid64 (buffer_addr b h + scale8 i) h
//let low_lemma_load_mem64 b i h =
// lemma_valid_mem64 b i h;
// lemma_load_mem64 b i h;
// equiv_load_mem64 (buffer_addr b h + scale8 i) h
//let same_domain_update64 b i v h =
// low_lemma_valid_mem64 b i h;
// Vale.Arch.MachineHeap.same_domain_update64 (buffer_addr b h + scale8 i) v (get_heap h)
open Vale.X64.BufferViewStore
let low_lemma_store_mem64_aux
(b:buffer64)
(heap:S.machine_heap)
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{buffer_readable h b /\ buffer_writeable b})
: Lemma
(requires IB.correct_down_p (_ih h) heap b)
(ensures (let heap' = S.update_heap64 (buffer_addr b h + scale8 i) v heap in
let h' = store_mem64 (buffer_addr b h + scale8 i) v h in
(_ih h').IB.hs == DV.upd_seq (_ih h).IB.hs (get_downview b.bsrc) (I.get_seq_heap heap' (_ih h).IB.addrs b))) =
let ptr = buffer_addr b h + scale8 i in
let heap' = S.update_heap64 ptr v heap in
let h' = store_mem64 ptr v h in
lemma_store_mem64 b i v h;
length_t_eq TUInt64 b;
bv_upd_update_heap64 b heap i v (_ih h);
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db Vale.Interop.Views.up_view64 in
assert (UV.upd (_ih h).IB.hs bv i (UInt64.uint_to_t v) == (_ih h').IB.hs)
val valid_state_store_mem64_aux: (i:nat) -> (v:nat64) -> (h:vale_heap) -> Lemma
(requires writeable_mem64 i h)
(ensures (
let heap = get_heap h in
let heap' = S.update_heap64 i v heap in
let h' = store_mem64 i v h in
heap' == I.down_mem (_ih h')
))
let valid_state_store_mem64_aux i v h =
let heap = get_heap h in
let heap' = S.update_heap64 i v heap in
let h1 = store_mem TUInt64 i v h in
store_buffer_aux_down64_mem i v h;
store_buffer_aux_down64_mem2 i v h;
let mem1 = heap' in
let mem2 = I.down_mem (_ih h1) in
let aux () : Lemma (forall j. mem1.[j] == mem2.[j]) =
Vale.Arch.MachineHeap.same_mem_get_heap_val64 i mem1 mem2;
Vale.Arch.MachineHeap.correct_update_get64 i v heap;
Vale.Arch.MachineHeap.frame_update_heap64 i v heap
in let aux2 () : Lemma (Set.equal (Map.domain mem1) (Map.domain mem2)) =
bytes_valid64 i h;
Vale.Arch.MachineHeap.same_domain_update64 i v heap
in aux(); aux2();
Map.lemma_equal_intro mem1 mem2
let low_lemma_load_mem64_full b i vfh t hid =
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
#push-options "--z3rlimit 20"
#restart-solver
let low_lemma_store_mem64 b i v h =
lemma_writeable_mem64 b i h;
lemma_store_mem64 b i v h;
valid_state_store_mem64_aux (buffer_addr b h + scale8 i) v h;
let heap = get_heap h in
let heap' = S.update_heap64 (buffer_addr b h + scale8 i) v heap in
low_lemma_store_mem64_aux b heap i v h;
Vale.Arch.MachineHeap.frame_update_heap64 (buffer_addr b h + scale8 i) v heap;
in_bounds64 h b i;
I.addrs_set_lemma_all ();
I.update_buffer_up_mem (_ih h) b heap heap'
#pop-options
#set-options "--z3rlimit 100"
#restart-solver
let lemma_is_full_update
(vfh:vale_full_heap) (h hk hk':vale_heap) (k:heaplet_id) (mh mh' mhk mhk':machine_heap) (mt mt':memtaint)
(t:base_typ) (b:buffer t) (ptr:int) (v_size:nat)
(index:nat) (v:base_typ_as_vale_type t) (tn:taint)
: Lemma
(requires
vfh.vf_layout.vl_inner.vl_heaplets_initialized /\
mem_inv vfh /\
buffer_readable hk b /\
buffer_writeable b /\
index < Seq.length (buffer_as_seq hk b) /\
mt == vfh.vf_layout.vl_taint /\
h == vfh.vf_heap /\
hk == Map16.sel vfh.vf_heaplets k /\
mh == h.mh /\
mhk == hk.mh /\
ptr == buffer_addr b hk + scale_by v_size index /\
mt' == S.update_n ptr v_size (heap_taint (coerce vfh)) tn /\
hk' == buffer_write b index v hk /\
valid_layout_buffer b vfh.vf_layout hk true /\
valid_taint_buf b hk mt tn /\
is_machine_heap_update mh mh' /\ upd_heap h mh' == buffer_write b index v h /\
is_machine_heap_update mhk mhk' /\ upd_heap hk mhk' == buffer_write b index v hk /\
(forall j.{:pattern mh.[j] \/ mh'.[j]} j < ptr \/ j >= ptr + v_size ==> mh.[j] == mh'.[j]) /\
(forall j.{:pattern mhk.[j] \/ mhk'.[j]} j < ptr \/ j >= ptr + v_size ==> mhk.[j] == mhk'.[j]) /\
0 <= scale_by v_size index /\ scale_by v_size index + v_size <= DV.length (get_downview b.bsrc) /\
(forall i.{:pattern mh'.[i] \/ mhk'.[i]} i >= ptr /\ i < ptr + v_size ==> mh'.[i] == mhk'.[i]) /\
True
)
(ensures is_full_update vfh hk' k mh' mt')
=
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
let vfh' = coerce (heap_upd (coerce vfh) mh' mt') in
let dom_upd = Set.intersect (vfh.vf_layout.vl_inner.vl_heaplet_sets k) (Map.domain mhk) in
let mhk'' = Map.concat mhk (Map.restrict dom_upd mh') in
assert (Map.equal mhk'' mhk');
let unchanged (j:heaplet_id) : Lemma
(requires j =!= k)
(ensures Map16.sel vfh'.vf_heaplets j == Map16.sel vfh.vf_heaplets j)
[SMTPat (Map16.sel vfh'.vf_heaplets j)]
=
assert (Map.equal (Map16.sel vfh'.vf_heaplets j).mh (Map16.sel vfh.vf_heaplets j).mh);
I.down_up_identity (Map16.sel vfh.vf_heaplets j).ih;
()
in
assert (Map16.equal vfh'.vf_heaplets (Map16.upd vfh.vf_heaplets k hk'));
assert (Map.equal mt' mt);
Vale.Interop.Heap_s.list_disjoint_or_eq_reveal ();
()
let low_lemma_store_mem64_full b i v vfh t hid =
let (h, mt, hk) = (vfh.vf_heap, vfh.vf_layout.vl_taint, Map16.get vfh.vf_heaplets hid) in
let ptr = buffer_addr b hk + scale8 i in
let mh' = S.update_heap64 ptr v (heap_get (coerce vfh)) in
let mt' = S.update_n ptr 8 (heap_taint (coerce vfh)) t in
let hk' = buffer_write b i v hk in
let mhk' = S.update_heap64 ptr v (get_heap hk) in
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
low_lemma_store_mem64 b i v h;
low_lemma_store_mem64 b i v (Map16.get vfh.vf_heaplets hid);
Vale.Arch.MachineHeap.frame_update_heap64 ptr v h.mh;
Vale.Arch.MachineHeap.frame_update_heap64 ptr v hk.mh;
in_bounds64 hk b i;
Vale.Arch.MachineHeap.same_mem_get_heap_val64 ptr mh' mhk';
lemma_is_full_update vfh h hk hk' hid h.mh mh' hk.mh mhk' mt mt' TUInt64 b ptr 8 i v t;
()
val low_lemma_valid_mem128 (b:buffer128) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b
)
(ensures
S.valid_addr128 (buffer_addr b h + scale16 i) (get_heap h)
)
let low_lemma_valid_mem128 b i h =
lemma_valid_mem128 b i h;
bytes_valid128 (buffer_addr b h + scale16 i) h
val equiv_load_mem128_aux: (ptr:int) -> (h:vale_heap) -> Lemma
(requires valid_mem128 ptr h)
(ensures load_mem128 ptr h == S.get_heap_val128 ptr (get_heap h))
let equiv_load_mem128_aux ptr h =
let t = TUInt128 in
let b = get_addr_ptr t ptr h in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
let addr = buffer_addr b h in
let contents = DV.as_seq (_ih h).IB.hs (get_downview b.bsrc) in
let heap = get_heap h in
S.get_heap_val128_reveal ();
index128_get_heap_val128 h b heap i;
lemma_load_mem128 b i h
let equiv_load_mem128 ptr h =
equiv_load_mem128_aux ptr h
val low_lemma_load_mem128 (b:buffer128) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b
)
(ensures
S.get_heap_val128 (buffer_addr b h + scale16 i) (get_heap h) == buffer_read b i h
)
let low_lemma_load_mem128 b i h =
lemma_valid_mem128 b i h;
lemma_load_mem128 b i h;
equiv_load_mem128_aux (buffer_addr b h + scale16 i) h
//let same_domain_update128 b i v h =
// low_lemma_valid_mem128 b i h;
// Vale.Arch.MachineHeap.same_domain_update128 (buffer_addr b h + scale16 i) v (get_heap h) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Memory.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.BufferViewStore.fsti.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Memory_Sems.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.BufferViewStore",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_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
}
] | {
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
b: Vale.X64.Memory.buffer128 ->
heap: Vale.Arch.MachineHeap_s.machine_heap ->
i: Prims.nat{i < Vale.X64.Memory.buffer_length b} ->
v: Vale.X64.Memory.quad32 ->
h:
Vale.Arch.HeapImpl.vale_heap
{Vale.X64.Memory.buffer_readable h b /\ Vale.X64.Memory.buffer_writeable b}
-> FStar.Pervasives.Lemma
(requires Vale.Interop.Heap_s.correct_down_p (Vale.Arch.HeapImpl._ih h) heap b)
(ensures
(let heap' =
Vale.Arch.MachineHeap_s.update_heap128 (Vale.X64.Memory.buffer_addr b h +
Vale.X64.Memory.scale16 i)
v
heap
in
let h' =
Vale.X64.Memory.store_mem128 (Vale.X64.Memory.buffer_addr b h +
Vale.X64.Memory.scale16 i)
v
h
in
InteropHeap?.hs (Vale.Arch.HeapImpl._ih h') ==
LowStar.BufferView.Down.upd_seq (InteropHeap?.hs (Vale.Arch.HeapImpl._ih h))
(Vale.Interop.Types.get_downview (Buffer?.bsrc b))
(Vale.Interop.get_seq_heap heap' (InteropHeap?.addrs (Vale.Arch.HeapImpl._ih h)) b))) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.X64.Memory.buffer128",
"Vale.Arch.MachineHeap_s.machine_heap",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Vale.X64.Memory.buffer_length",
"Vale.X64.Memory.vuint128",
"Vale.X64.Memory.quad32",
"Vale.Arch.HeapImpl.vale_heap",
"Prims.l_and",
"Vale.X64.Memory.buffer_readable",
"Vale.X64.Memory.buffer_writeable",
"Prims._assert",
"Prims.eq2",
"FStar.Monotonic.HyperStack.mem",
"LowStar.BufferView.Up.upd",
"Vale.Def.Types_s.quad32",
"Vale.Interop.Heap_s.__proj__InteropHeap__item__hs",
"Vale.Arch.HeapImpl._ih",
"LowStar.BufferView.Up.buffer",
"LowStar.BufferView.Up.mk_buffer",
"FStar.UInt8.t",
"Vale.Interop.Views.up_view128",
"LowStar.BufferView.Down.buffer",
"Vale.Interop.Types.get_downview",
"Vale.Interop.Types.__proj__Buffer__item__src",
"Vale.Interop.Types.b8_preorder",
"Vale.Interop.Types.__proj__Buffer__item__writeable",
"Vale.Interop.Types.base_typ_as_type",
"Vale.Interop.Types.__proj__Buffer__item__bsrc",
"Prims.unit",
"Vale.X64.BufferViewStore.bv_upd_update_heap128",
"Vale.X64.Memory.length_t_eq",
"Vale.Arch.HeapTypes_s.TUInt128",
"Vale.X64.Memory.lemma_store_mem128",
"Vale.X64.Memory.store_mem128",
"Vale.Arch.MachineHeap_s.update_heap128",
"Prims.int",
"Prims.op_Addition",
"Vale.X64.Memory.buffer_addr",
"Vale.X64.Memory.scale16",
"Vale.Interop.Heap_s.correct_down_p",
"Prims.squash",
"LowStar.BufferView.Down.upd_seq",
"Vale.Interop.get_seq_heap",
"Vale.Interop.Heap_s.__proj__InteropHeap__item__addrs",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let low_lemma_store_mem128_aux
(b: buffer128)
(heap: S.machine_heap)
(i: nat{i < buffer_length b})
(v: quad32)
(h: vale_heap{buffer_readable h b /\ buffer_writeable b})
: Lemma (requires IB.correct_down_p (_ih h) heap b)
(ensures
(let heap' = S.update_heap128 (buffer_addr b h + scale16 i) v heap in
let h' = store_mem128 (buffer_addr b h + scale16 i) v h in
(_ih h').IB.hs ==
DV.upd_seq (_ih h).IB.hs (get_downview b.bsrc) (I.get_seq_heap heap' (_ih h).IB.addrs b))) =
| let ptr = buffer_addr b h + scale16 i in
let heap' = S.update_heap128 ptr v heap in
let h' = store_mem128 ptr v h in
lemma_store_mem128 b i v h;
length_t_eq TUInt128 b;
bv_upd_update_heap128 b heap i v (_ih h);
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db Vale.Interop.Views.up_view128 in
assert (UV.upd (_ih h).IB.hs bv i v == (_ih h').IB.hs) | false |
Vale.X64.Memory_Sems.fst | Vale.X64.Memory_Sems.low_lemma_load_mem128_full | val low_lemma_load_mem128_full (b:buffer128) (i:nat) (vfh:vale_full_heap) (t:taint) (hid:heaplet_id) : Lemma
(requires (
let (h, mt) = (Map16.get vfh.vf_heaplets hid, vfh.vf_layout.vl_taint) in
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b /\
valid_layout_buffer b vfh.vf_layout h false /\
valid_taint_buf128 b h mt t /\
mem_inv vfh
))
(ensures (
let (h, mt) = (Map16.get vfh.vf_heaplets hid, vfh.vf_layout.vl_taint) in
let ptr = buffer_addr b h + scale16 i in
is_full_read vfh.vf_heap h b i /\
valid_mem128 ptr vfh.vf_heap /\
valid_taint_buf128 b vfh.vf_heap mt t
)) | val low_lemma_load_mem128_full (b:buffer128) (i:nat) (vfh:vale_full_heap) (t:taint) (hid:heaplet_id) : Lemma
(requires (
let (h, mt) = (Map16.get vfh.vf_heaplets hid, vfh.vf_layout.vl_taint) in
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b /\
valid_layout_buffer b vfh.vf_layout h false /\
valid_taint_buf128 b h mt t /\
mem_inv vfh
))
(ensures (
let (h, mt) = (Map16.get vfh.vf_heaplets hid, vfh.vf_layout.vl_taint) in
let ptr = buffer_addr b h + scale16 i in
is_full_read vfh.vf_heap h b i /\
valid_mem128 ptr vfh.vf_heap /\
valid_taint_buf128 b vfh.vf_heap mt t
)) | let low_lemma_load_mem128_full b i vfh t hid =
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
() | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory_Sems.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 4,
"end_line": 977,
"start_col": 0,
"start_line": 975
} | module Vale.X64.Memory_Sems
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.Def.Words_s
module I = Vale.Interop
module S = Vale.X64.Machine_Semantics_s
module MB = LowStar.Monotonic.Buffer
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
friend Vale.X64.Memory
module IB = Vale.Interop.Base
let same_domain h m = Set.equal (IB.addrs_set (_ih h)) (Map.domain m)
let lemma_same_domains h m1 m2 = ()
let get_heap h = I.down_mem (_ih h)
let upd_heap h m = mi_heap_upd h m
//let lemma_upd_get_heap h = I.down_up_identity (_ih h)
let lemma_get_upd_heap h m = I.up_down_identity (_ih h) m
let lemma_heap_impl = ()
let lemma_heap_get_heap h = ()
let lemma_heap_taint h = ()
//let lemma_heap_upd_heap h mh mt = ()
[@"opaque_to_smt"]
let rec set_of_range (a:int) (n:nat) : Pure (Set.set int)
(requires True)
(ensures fun s -> (forall (i:int).{:pattern Set.mem i s} Set.mem i s <==> a <= i /\ i < a + n))
=
if n = 0 then Set.empty else Set.union (set_of_range a (n - 1)) (Set.singleton (a + n - 1))
let buffer_info_has_addr (bi:buffer_info) (a:int) =
let b = bi.bi_buffer in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
addr <= a /\ a < addr + len
let buffer_info_has_addr_opt (bi:option buffer_info) (a:int) =
match bi with
| None -> False
| Some bi -> buffer_info_has_addr bi a
#set-options "--z3rlimit 100"
let rec make_owns_rec (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
if n = 0 then ((fun _ -> None), (fun _ -> Set.empty)) else
let (m0, s0) = make_owns_rec h bs (n - 1) in
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let s i = if i = hi then Set.union (s0 i) s_b else s0 i in
let m a = if addr <= a && a < addr + len then Some (n - 1) else m0 a in
(m, s)
[@"opaque_to_smt"]
let make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
make_owns_rec h bs n
let rec lemma_make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n <= Seq.length bs /\
(forall (i:nat).{:pattern Seq.index bs i} i < Seq.length bs ==> buffer_readable h (Seq.index bs i).bi_buffer) /\
(forall (i1 i2:nat).{:pattern (Seq.index bs i1); (Seq.index bs i2)}
i1 < Seq.length bs /\ i2 < Seq.length bs ==> buffer_info_disjoint (Seq.index bs i1) (Seq.index bs i2))
)
(ensures (
let (m, s) = make_owns h bs n in
(forall (i:heaplet_id) (a:int).{:pattern Set.mem a (s i)}
(Set.mem a (s i) <==> Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (m a) == Some i) /\
(Set.mem a (s i) ==> buffer_info_has_addr_opt (Option.mapTot (fun n -> Seq.index bs n) (m a)) a) /\
(Set.mem a (s i) ==> Set.mem a (Map.domain h.mh))
) /\
(forall (k:nat) (a:int).{:pattern Set.mem a (s (Seq.index bs k).bi_heaplet)}
k < n /\ buffer_info_has_addr (Seq.index bs k) a ==> Set.mem a (s (Seq.index bs k).bi_heaplet))
))
=
reveal_opaque (`%make_owns) make_owns;
if n = 0 then () else
let _ = make_owns h bs (n - 1) in
let (m, s) = make_owns h bs n in
lemma_make_owns h bs (n - 1);
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let lem1 (a:int) : Lemma
(requires Set.mem a s_b)
(ensures Set.mem a (Map.domain h.mh))
[SMTPat (Set.mem a (Map.domain h.mh))]
=
I.addrs_set_mem h.ih b a
in
let lem2 (i:heaplet_id) (a:int) : Lemma
(requires i =!= hi /\ Set.mem a (Set.intersect s_b (s i)))
(ensures False)
[SMTPat (Set.mem a (s i))]
=
reveal_opaque (`%addr_map_pred) addr_map_pred
in
()
#push-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_loc_mutable_buffers_rec (l:list buffer_info) (s:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n + List.length l == Seq.length s /\
list_to_seq_post l s n
)
(ensures (
let modloc = loc_mutable_buffers l in
forall (i:nat).{:pattern Seq.index s i} n <= i /\ i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes modloc (loc_buffer bi.bi_buffer))
))
(decreases l)
=
match l with
| [] -> ()
| h::t -> lemma_loc_mutable_buffers_rec t s (n + 1)
#pop-options
let lemma_loc_mutable_buffers (l:list buffer_info) : Lemma
(ensures (
let s = list_to_seq l in
forall (i:nat).{:pattern Seq.index s i} i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes (loc_mutable_buffers l) (loc_buffer bi.bi_buffer))
))
=
lemma_list_to_seq l;
lemma_loc_mutable_buffers_rec l (list_to_seq l) 0
let create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let modloc = loc_mutable_buffers buffers in
let layout1 = h1.vf_layout in
let layin1 = layout1.vl_inner in
let (hmap, hsets) = make_owns h1.vf_heap bs (Seq.length bs) in
let hmap a = Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (hmap a) in
let l = {
vl_heaplets_initialized = true;
vl_heaplet_map = hmap;
vl_heaplet_sets = hsets;
vl_old_heap = h1.vf_heap;
vl_buffers = bs;
vl_mod_loc = modloc;
} in
let layout2 = {layout1 with vl_inner = l} in
let h2 = {
vf_layout = layout2;
vf_heap = h1.vf_heap;
vf_heaplets = h1.vf_heaplets;
} in
h2
let lemma_create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let h2 = create_heaplets buffers h1 in
assert (h2.vf_layout.vl_inner.vl_buffers == bs); // REVIEW: why is this necessary, even with extra ifuel?
lemma_make_owns h1.vf_heap bs (Seq.length bs);
lemma_loc_mutable_buffers buffers;
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
let destroy_heaplets h1 =
h1
let lemma_destroy_heaplets h1 =
()
val heap_shift (m1 m2:S.machine_heap) (base:int) (n:nat) : Lemma
(requires (forall i. 0 <= i /\ i < n ==> m1.[base + i] == m2.[base + i]))
(ensures (forall i. {:pattern (m1.[i])} base <= i /\ i < base + n ==> m1.[i] == m2.[i]))
#push-options "--smtencoding.l_arith_repr boxwrap"
let heap_shift m1 m2 base n =
assert (forall i. base <= i /\ i < base + n ==>
m1.[base + (i - base)] == m2.[base + (i - base)])
#pop-options
val same_mem_eq_slices64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 8 + 8 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8)))
let same_mem_eq_slices64 b i v k h1 h2 mem1 mem2 =
let t = TUInt64 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up64 (b:buffer64) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 8}) : Lemma
(scale8 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint64_view in
UV.length_eq vb
val same_mem_get_heap_val64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale8 k in
forall (x:int).{:pattern (mem1.[x])} ptr <= x /\ x < ptr + 8 ==> mem1.[x] == mem2.[x]))
let same_mem_get_heap_val64 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale8 k in
let addr = buffer_addr b h1 in
let aux (x:int{ptr <= x /\ x < ptr + 8}) : Lemma (mem1.[x] == mem2.[x]) =
let i = x - ptr in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices64 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8) (k * 8 + 8)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8) (k * 8 + 8)) in
assert (Seq.index s1 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i));
length_up64 b h1 k i;
assert (mem1.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i)));
assert (Seq.index s2 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i));
length_up64 b h2 k i;
assert (mem2.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i)))
in
Classical.forall_intro aux;
assert (forall i. addr + (scale8 k + i) == ptr + i)
let rec written_buffer_down64_aux1
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(k:nat) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j.{:pattern (mem1.[j]) \/ (mem2.[j])}
base <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem1.[j])}
j >= base /\ j < base + scale8 i ==>
mem1.[j] == mem2.[j]))
(decreases %[i-k]) =
if k >= i then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux1 b i v h base (k+1) h1 mem1 mem2
end
let rec written_buffer_down64_aux2
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(n:nat{n == buffer_length b})
(k:nat{k > i}) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
base + scale8 (i+1) <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
j >= base + scale8 (i+1) /\ j < base + scale8 n ==>
mem1.[j] == mem2.[j]))
(decreases %[n-k]) =
if k >= n then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux2 b i v h base n (k+1) h1 mem1 mem2
end
let written_buffer_down64 (b:buffer64{buffer_writeable b}) (i:nat{i < buffer_length b}) (v:nat64) (h:vale_heap)
: Lemma
(requires List.memP b (IB.ptrs_of_mem (_ih h)))
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
(base <= j /\ j < base + scale8 i) \/
(base + scale8 (i+1) <= j /\ j < base + scale8 n) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
written_buffer_down64_aux1 b i v h base 0 h1 mem1 mem2;
written_buffer_down64_aux2 b i v h base n (i+1) h1 mem1 mem2
let unwritten_buffer_down (t:base_typ) (b:buffer t{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:base_typ_as_vale_type t)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall (a:b8{List.memP a (IB.ptrs_of_mem (_ih h)) /\ a =!= b}) j. {:pattern mem1.[j]; List.memP a (IB.ptrs_of_mem (_ih h)) \/ mem2.[j]; List.memP a (IB.ptrs_of_mem (_ih h))}
let base = (IB.addrs_of_mem (_ih h)) a in
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==> mem1.[j] == mem2.[j]))
= let aux (a:b8{a =!= b /\ List.memP a (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let base = (IB.addrs_of_mem (_ih h)) a in
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall j.
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==>
mem1.[j] == mem2.[j]))
= let db = get_downview a.bsrc in
if DV.length db = 0 then ()
else
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = (IB.addrs_of_mem (_ih h)) a in
let s0 = DV.as_seq (IB.hs_of_mem (_ih h)) db in
let s1 = DV.as_seq (IB.hs_of_mem (_ih h1)) db in
opaque_assert (`%IB.list_disjoint_or_eq) IB.list_disjoint_or_eq IB.list_disjoint_or_eq_def (MB.disjoint a.bsrc b.bsrc);
lemma_dv_equal (IB.down_view a.src) a.bsrc (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1));
assert (Seq.equal s0 s1);
assert (forall (j:int).{:pattern (mem1.[j])}
base <= j /\ j < base + Seq.length s0 ==> v_to_typ TUInt8 (Seq.index s0 (j - base)) == mem1.[j]);
heap_shift mem1 mem2 base (DV.length db)
in
Classical.forall_intro aux
let store_buffer_down64_mem
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
forall (j:int). {:pattern mem1.[j] \/ mem2.[j]}
j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
let aux (j:int)
: Lemma
(j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j])
=
I.addrs_set_lemma_all ();
if j >= base && j < base + DV.length (get_downview b.bsrc) then begin
written_buffer_down64 b i v h;
length_t_eq (TUInt64) b
end
else if not (I.valid_addr (_ih h) j)
then I.same_unspecified_down (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1)) (IB.ptrs_of_mem (_ih h))
else unwritten_buffer_down TUInt64 b i v h
in
Classical.forall_intro aux
let store_buffer_aux_down64_mem (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
forall j. {:pattern mem1.[j] \/ mem2.[j]}
j < ptr \/ j >= ptr + 8 ==>
mem1.[j] == mem2.[j]))
= let t = TUInt64 in
let h1 = store_mem t ptr v h in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
store_buffer_write t ptr v h;
assert (buffer_addr b h + scale8 i == ptr);
assert (buffer_addr b h + scale8 (i+1) == ptr + 8);
store_buffer_down64_mem b i v h
let store_buffer_aux_down64_mem2 (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
S.get_heap_val64 ptr mem2 == v))
= let t = TUInt64 in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
let h1 = store_mem t ptr v h in
let mem2 = I.down_mem (_ih h1) in
store_buffer_write t ptr v h;
assert (Seq.index (buffer_as_seq h1 b) i == v);
index64_get_heap_val64 h1 b mem2 i
let in_bounds64 (h:vale_heap) (b:buffer64) (i:nat{i < buffer_length b})
: Lemma (scale8 i + 8 <= DV.length (get_downview b.bsrc))
=
length_t_eq TUInt64 b
let bytes_valid64 ptr h =
reveal_opaque (`%S.valid_addr64) S.valid_addr64;
let t = TUInt64 in
let b = get_addr_ptr t ptr h in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
in_bounds64 h b i;
I.addrs_set_mem (_ih h) b ptr;
I.addrs_set_mem (_ih h) b (ptr+1);
I.addrs_set_mem (_ih h) b (ptr+2);
I.addrs_set_mem (_ih h) b (ptr+3);
I.addrs_set_mem (_ih h) b (ptr+4);
I.addrs_set_mem (_ih h) b (ptr+5);
I.addrs_set_mem (_ih h) b (ptr+6);
I.addrs_set_mem (_ih h) b (ptr+7)
val same_mem_get_heap_val128 (b:buffer128)
(i:nat{i < buffer_length b})
(v:quad32)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1)) /\ buffer_writeable b})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale16 k in
forall i.{:pattern mem1.[i]} i >= ptr /\ i < ptr+16 ==> mem1.[i] == mem2.[i]))
val same_mem_eq_slices128 (b:buffer128)
(i:nat{i < buffer_length b})
(v:quad32)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1)) /\ buffer_writeable b})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 16 + 16 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 16) (k * 16 + 16) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 16) (k * 16 + 16)))
let same_mem_eq_slices128 b i v k h1 h2 mem1 mem2 =
let t = TUInt128 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up128 (b:buffer128) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 16}) : Lemma
(scale16 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint128_view in
UV.length_eq vb
let same_mem_get_heap_val128 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale16 k in
let addr = buffer_addr b h1 in
let aux (i:nat{ptr <= i /\ i < ptr+16}) : Lemma (mem1.[i] == mem2.[i]) =
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint128_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices128 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16) (k * 16 + 16)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16) (k * 16 + 16)) in
assert (Seq.index s1 (i - ptr) == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16 + (i-ptr)));
length_up128 b h1 k (i-ptr);
assert (mem1.[i] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16 + (i-ptr))));
assert (Seq.index s2 (i-ptr) == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16 + (i-ptr)));
length_up128 b h2 k (i-ptr);
assert (mem2.[addr+(scale16 k + (i-ptr))] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16 + (i-ptr))));
assert (forall i. addr + (scale16 k + (i-ptr)) == i)
in
Classical.forall_intro aux
let in_bounds128 (h:vale_heap) (b:buffer128) (i:nat{i < buffer_length b}) : Lemma
(scale16 i + 16 <= DV.length (get_downview b.bsrc))
=
length_t_eq TUInt128 b
#push-options "--z3rlimit 20"
#restart-solver
let bytes_valid128 ptr h =
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
IB.list_disjoint_or_eq_reveal ();
let t = TUInt128 in
let b = get_addr_ptr t ptr h in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
in_bounds128 h b i;
I.addrs_set_mem (_ih h) b ptr;
I.addrs_set_mem (_ih h) b (ptr+1);
I.addrs_set_mem (_ih h) b (ptr+2);
I.addrs_set_mem (_ih h) b (ptr+3);
I.addrs_set_mem (_ih h) b (ptr+4);
I.addrs_set_mem (_ih h) b (ptr+5);
I.addrs_set_mem (_ih h) b (ptr+6);
I.addrs_set_mem (_ih h) b (ptr+7);
I.addrs_set_mem (_ih h) b (ptr+8);
I.addrs_set_mem (_ih h) b (ptr+9);
I.addrs_set_mem (_ih h) b (ptr+10);
I.addrs_set_mem (_ih h) b (ptr+11);
I.addrs_set_mem (_ih h) b (ptr+12);
I.addrs_set_mem (_ih h) b (ptr+13);
I.addrs_set_mem (_ih h) b (ptr+14);
I.addrs_set_mem (_ih h) b (ptr+15)
#pop-options
let equiv_load_mem64 ptr h =
let t = TUInt64 in
let b = get_addr_ptr t ptr h in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
let addr = buffer_addr b h in
let contents = DV.as_seq (_ih h).IB.hs (get_downview b.bsrc) in
let heap = get_heap h in
index64_get_heap_val64 h b heap i;
lemma_load_mem64 b i h
//let low_lemma_valid_mem64 b i h =
// lemma_valid_mem64 b i h;
// bytes_valid64 (buffer_addr b h + scale8 i) h
//let low_lemma_load_mem64 b i h =
// lemma_valid_mem64 b i h;
// lemma_load_mem64 b i h;
// equiv_load_mem64 (buffer_addr b h + scale8 i) h
//let same_domain_update64 b i v h =
// low_lemma_valid_mem64 b i h;
// Vale.Arch.MachineHeap.same_domain_update64 (buffer_addr b h + scale8 i) v (get_heap h)
open Vale.X64.BufferViewStore
let low_lemma_store_mem64_aux
(b:buffer64)
(heap:S.machine_heap)
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{buffer_readable h b /\ buffer_writeable b})
: Lemma
(requires IB.correct_down_p (_ih h) heap b)
(ensures (let heap' = S.update_heap64 (buffer_addr b h + scale8 i) v heap in
let h' = store_mem64 (buffer_addr b h + scale8 i) v h in
(_ih h').IB.hs == DV.upd_seq (_ih h).IB.hs (get_downview b.bsrc) (I.get_seq_heap heap' (_ih h).IB.addrs b))) =
let ptr = buffer_addr b h + scale8 i in
let heap' = S.update_heap64 ptr v heap in
let h' = store_mem64 ptr v h in
lemma_store_mem64 b i v h;
length_t_eq TUInt64 b;
bv_upd_update_heap64 b heap i v (_ih h);
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db Vale.Interop.Views.up_view64 in
assert (UV.upd (_ih h).IB.hs bv i (UInt64.uint_to_t v) == (_ih h').IB.hs)
val valid_state_store_mem64_aux: (i:nat) -> (v:nat64) -> (h:vale_heap) -> Lemma
(requires writeable_mem64 i h)
(ensures (
let heap = get_heap h in
let heap' = S.update_heap64 i v heap in
let h' = store_mem64 i v h in
heap' == I.down_mem (_ih h')
))
let valid_state_store_mem64_aux i v h =
let heap = get_heap h in
let heap' = S.update_heap64 i v heap in
let h1 = store_mem TUInt64 i v h in
store_buffer_aux_down64_mem i v h;
store_buffer_aux_down64_mem2 i v h;
let mem1 = heap' in
let mem2 = I.down_mem (_ih h1) in
let aux () : Lemma (forall j. mem1.[j] == mem2.[j]) =
Vale.Arch.MachineHeap.same_mem_get_heap_val64 i mem1 mem2;
Vale.Arch.MachineHeap.correct_update_get64 i v heap;
Vale.Arch.MachineHeap.frame_update_heap64 i v heap
in let aux2 () : Lemma (Set.equal (Map.domain mem1) (Map.domain mem2)) =
bytes_valid64 i h;
Vale.Arch.MachineHeap.same_domain_update64 i v heap
in aux(); aux2();
Map.lemma_equal_intro mem1 mem2
let low_lemma_load_mem64_full b i vfh t hid =
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
#push-options "--z3rlimit 20"
#restart-solver
let low_lemma_store_mem64 b i v h =
lemma_writeable_mem64 b i h;
lemma_store_mem64 b i v h;
valid_state_store_mem64_aux (buffer_addr b h + scale8 i) v h;
let heap = get_heap h in
let heap' = S.update_heap64 (buffer_addr b h + scale8 i) v heap in
low_lemma_store_mem64_aux b heap i v h;
Vale.Arch.MachineHeap.frame_update_heap64 (buffer_addr b h + scale8 i) v heap;
in_bounds64 h b i;
I.addrs_set_lemma_all ();
I.update_buffer_up_mem (_ih h) b heap heap'
#pop-options
#set-options "--z3rlimit 100"
#restart-solver
let lemma_is_full_update
(vfh:vale_full_heap) (h hk hk':vale_heap) (k:heaplet_id) (mh mh' mhk mhk':machine_heap) (mt mt':memtaint)
(t:base_typ) (b:buffer t) (ptr:int) (v_size:nat)
(index:nat) (v:base_typ_as_vale_type t) (tn:taint)
: Lemma
(requires
vfh.vf_layout.vl_inner.vl_heaplets_initialized /\
mem_inv vfh /\
buffer_readable hk b /\
buffer_writeable b /\
index < Seq.length (buffer_as_seq hk b) /\
mt == vfh.vf_layout.vl_taint /\
h == vfh.vf_heap /\
hk == Map16.sel vfh.vf_heaplets k /\
mh == h.mh /\
mhk == hk.mh /\
ptr == buffer_addr b hk + scale_by v_size index /\
mt' == S.update_n ptr v_size (heap_taint (coerce vfh)) tn /\
hk' == buffer_write b index v hk /\
valid_layout_buffer b vfh.vf_layout hk true /\
valid_taint_buf b hk mt tn /\
is_machine_heap_update mh mh' /\ upd_heap h mh' == buffer_write b index v h /\
is_machine_heap_update mhk mhk' /\ upd_heap hk mhk' == buffer_write b index v hk /\
(forall j.{:pattern mh.[j] \/ mh'.[j]} j < ptr \/ j >= ptr + v_size ==> mh.[j] == mh'.[j]) /\
(forall j.{:pattern mhk.[j] \/ mhk'.[j]} j < ptr \/ j >= ptr + v_size ==> mhk.[j] == mhk'.[j]) /\
0 <= scale_by v_size index /\ scale_by v_size index + v_size <= DV.length (get_downview b.bsrc) /\
(forall i.{:pattern mh'.[i] \/ mhk'.[i]} i >= ptr /\ i < ptr + v_size ==> mh'.[i] == mhk'.[i]) /\
True
)
(ensures is_full_update vfh hk' k mh' mt')
=
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
let vfh' = coerce (heap_upd (coerce vfh) mh' mt') in
let dom_upd = Set.intersect (vfh.vf_layout.vl_inner.vl_heaplet_sets k) (Map.domain mhk) in
let mhk'' = Map.concat mhk (Map.restrict dom_upd mh') in
assert (Map.equal mhk'' mhk');
let unchanged (j:heaplet_id) : Lemma
(requires j =!= k)
(ensures Map16.sel vfh'.vf_heaplets j == Map16.sel vfh.vf_heaplets j)
[SMTPat (Map16.sel vfh'.vf_heaplets j)]
=
assert (Map.equal (Map16.sel vfh'.vf_heaplets j).mh (Map16.sel vfh.vf_heaplets j).mh);
I.down_up_identity (Map16.sel vfh.vf_heaplets j).ih;
()
in
assert (Map16.equal vfh'.vf_heaplets (Map16.upd vfh.vf_heaplets k hk'));
assert (Map.equal mt' mt);
Vale.Interop.Heap_s.list_disjoint_or_eq_reveal ();
()
let low_lemma_store_mem64_full b i v vfh t hid =
let (h, mt, hk) = (vfh.vf_heap, vfh.vf_layout.vl_taint, Map16.get vfh.vf_heaplets hid) in
let ptr = buffer_addr b hk + scale8 i in
let mh' = S.update_heap64 ptr v (heap_get (coerce vfh)) in
let mt' = S.update_n ptr 8 (heap_taint (coerce vfh)) t in
let hk' = buffer_write b i v hk in
let mhk' = S.update_heap64 ptr v (get_heap hk) in
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
low_lemma_store_mem64 b i v h;
low_lemma_store_mem64 b i v (Map16.get vfh.vf_heaplets hid);
Vale.Arch.MachineHeap.frame_update_heap64 ptr v h.mh;
Vale.Arch.MachineHeap.frame_update_heap64 ptr v hk.mh;
in_bounds64 hk b i;
Vale.Arch.MachineHeap.same_mem_get_heap_val64 ptr mh' mhk';
lemma_is_full_update vfh h hk hk' hid h.mh mh' hk.mh mhk' mt mt' TUInt64 b ptr 8 i v t;
()
val low_lemma_valid_mem128 (b:buffer128) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b
)
(ensures
S.valid_addr128 (buffer_addr b h + scale16 i) (get_heap h)
)
let low_lemma_valid_mem128 b i h =
lemma_valid_mem128 b i h;
bytes_valid128 (buffer_addr b h + scale16 i) h
val equiv_load_mem128_aux: (ptr:int) -> (h:vale_heap) -> Lemma
(requires valid_mem128 ptr h)
(ensures load_mem128 ptr h == S.get_heap_val128 ptr (get_heap h))
let equiv_load_mem128_aux ptr h =
let t = TUInt128 in
let b = get_addr_ptr t ptr h in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
let addr = buffer_addr b h in
let contents = DV.as_seq (_ih h).IB.hs (get_downview b.bsrc) in
let heap = get_heap h in
S.get_heap_val128_reveal ();
index128_get_heap_val128 h b heap i;
lemma_load_mem128 b i h
let equiv_load_mem128 ptr h =
equiv_load_mem128_aux ptr h
val low_lemma_load_mem128 (b:buffer128) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b
)
(ensures
S.get_heap_val128 (buffer_addr b h + scale16 i) (get_heap h) == buffer_read b i h
)
let low_lemma_load_mem128 b i h =
lemma_valid_mem128 b i h;
lemma_load_mem128 b i h;
equiv_load_mem128_aux (buffer_addr b h + scale16 i) h
//let same_domain_update128 b i v h =
// low_lemma_valid_mem128 b i h;
// Vale.Arch.MachineHeap.same_domain_update128 (buffer_addr b h + scale16 i) v (get_heap h)
let low_lemma_store_mem128_aux
(b:buffer128)
(heap:S.machine_heap)
(i:nat{i < buffer_length b})
(v:quad32)
(h:vale_heap{buffer_readable h b /\ buffer_writeable b})
: Lemma
(requires IB.correct_down_p (_ih h) heap b)
(ensures (let heap' = S.update_heap128 (buffer_addr b h + scale16 i) v heap in
let h' = store_mem128 (buffer_addr b h + scale16 i) v h in
(_ih h').IB.hs == DV.upd_seq (_ih h).IB.hs (get_downview b.bsrc) (I.get_seq_heap heap' (_ih h).IB.addrs b))) =
let ptr = buffer_addr b h + scale16 i in
let heap' = S.update_heap128 ptr v heap in
let h' = store_mem128 ptr v h in
lemma_store_mem128 b i v h;
length_t_eq TUInt128 b;
bv_upd_update_heap128 b heap i v (_ih h);
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db Vale.Interop.Views.up_view128 in
assert (UV.upd (_ih h).IB.hs bv i v == (_ih h').IB.hs)
val valid_state_store_mem128_aux (i:int) (v:quad32) (h:vale_heap) : Lemma
(requires writeable_mem128 i h)
(ensures (
let heap = get_heap h in
let heap' = S.update_heap128 i v heap in
let h' = store_mem128 i v h in
heap' == I.down_mem (_ih h')
))
#restart-solver
let rec written_buffer_down128_aux1
(b:buffer128{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:quad32)
(h:vale_heap{List.memP b (_ih h).IB.ptrs})
(base:nat{base == buffer_addr b h})
(k:nat) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j.{:pattern (mem1.[j]) \/ (mem2.[j])}
base <= j /\ j < base + k * 16 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem1.[j])}
j >= base /\ j < base + scale16 i ==>
mem1.[j] == mem2.[j]))
(decreases %[i-k]) =
if k >= i then ()
else begin
let ptr = base + scale16 k in
same_mem_get_heap_val128 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 16;
written_buffer_down128_aux1 b i v h base (k+1) h1 mem1 mem2
end
#restart-solver
let rec written_buffer_down128_aux2
(b:buffer128{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:quad32)
(h:vale_heap{List.memP b (_ih h).IB.ptrs})
(base:nat{base == buffer_addr b h})
(n:nat{n == buffer_length b})
(k:nat{k > i}) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
base + scale16 (i+1) <= j /\ j < base + k * 16 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
j >= base + scale16 (i+1) /\ j < base + scale16 n ==>
mem1.[j] == mem2.[j]))
(decreases %[n-k]) =
if k >= n then ()
else begin
let ptr = base + scale16 k in
same_mem_get_heap_val128 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 16;
written_buffer_down128_aux2 b i v h base n (k+1) h1 mem1 mem2
end
let written_buffer_down128 (b:buffer128) (i:nat{i < buffer_length b}) (v:quad32) (h:vale_heap)
: Lemma
(requires List.memP b (_ih h).IB.ptrs /\ buffer_writeable b)
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
(base <= j /\ j < base + scale16 i) \/
(base + scale16 (i+1) <= j /\ j < base + scale16 n) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
written_buffer_down128_aux1 b i v h base 0 h1 mem1 mem2;
written_buffer_down128_aux2 b i v h base n (i+1) h1 mem1 mem2
let store_buffer_down128_mem
(b:buffer128{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:quad32)
(h:vale_heap{List.memP b (_ih h).IB.ptrs})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
forall (j:int). {:pattern mem1.[j] \/ mem2.[j]}
j < base + scale16 i \/ j >= base + scale16 (i+1) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
let aux (j:int)
: Lemma
(j < base + scale16 i \/ j >= base + scale16 (i+1) ==>
mem1.[j] == mem2.[j])
=
I.addrs_set_lemma_all ();
if j >= base && j < base + DV.length (get_downview b.bsrc) then begin
written_buffer_down128 b i v h;
length_t_eq TUInt128 b
end
else if not (I.valid_addr (_ih h) j)
then I.same_unspecified_down (_ih h).IB.hs (_ih h1).IB.hs (_ih h).IB.ptrs
else unwritten_buffer_down TUInt128 b i v h
in
Classical.forall_intro aux
let store_buffer_aux_down128_mem (ptr:int) (v:quad32) (h:vale_heap{writeable_mem128 ptr h})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = store_mem TUInt128 ptr v h in
let mem2 = I.down_mem (_ih h1) in
forall j. {:pattern mem1.[j] \/ mem2.[j]}
j < ptr \/ j >= ptr + 16 ==>
mem1.[j] == mem2.[j]))
= let t = TUInt128 in
let h1 = store_mem t ptr v h in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
store_buffer_write t ptr v h;
assert (buffer_addr b h + scale16 i == ptr);
assert (buffer_addr b h + scale16 (i+1) == ptr + 16);
store_buffer_down128_mem b i v h
let store_buffer_aux_down128_mem2 (ptr:int) (v:quad32) (h:vale_heap{writeable_mem128 ptr h})
: Lemma
(ensures (
let h1 = store_mem TUInt128 ptr v h in
let mem2 = I.down_mem (_ih h1) in
Mkfour
(S.get_heap_val32 ptr mem2)
(S.get_heap_val32 (ptr+4) mem2)
(S.get_heap_val32 (ptr+8) mem2)
(S.get_heap_val32 (ptr+12) mem2)
== v)) =
let t = TUInt128 in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
let h1 = store_mem t ptr v h in
let mem2 = I.down_mem (_ih h1) in
store_buffer_write t ptr v h;
assert (Seq.index (buffer_as_seq h1 b) i == v);
index128_get_heap_val128 h1 b mem2 i
let valid_state_store_mem128_aux i v h =
let heap = get_heap h in
let heap' = S.update_heap128 i v heap in
let h1 = store_mem TUInt128 i v h in
store_buffer_aux_down128_mem i v h;
store_buffer_aux_down128_mem2 i v h;
let mem1 = heap' in
let mem2 = I.down_mem (_ih h1) in
let aux () : Lemma (forall j. mem1.[j] == mem2.[j]) =
Vale.Arch.MachineHeap.correct_update_get128 i v heap;
Vale.X64.Machine_Semantics_s.get_heap_val128_reveal ();
Vale.Arch.MachineHeap.same_mem_get_heap_val32 i mem1 mem2;
Vale.Arch.MachineHeap.same_mem_get_heap_val32 (i+4) mem1 mem2;
Vale.Arch.MachineHeap.same_mem_get_heap_val32 (i+8) mem1 mem2;
Vale.Arch.MachineHeap.same_mem_get_heap_val32 (i+12) mem1 mem2;
Vale.Arch.MachineHeap.frame_update_heap128 i v heap
in
let aux2 () : Lemma (Set.equal (Map.domain mem1) (Map.domain mem2)) =
bytes_valid128 i h;
Vale.Arch.MachineHeap.same_domain_update128 i v heap
in aux (); aux2 ();
Map.lemma_equal_intro mem1 mem2 | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Memory.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.BufferViewStore.fsti.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Memory_Sems.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.BufferViewStore",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_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
}
] | {
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
b: Vale.X64.Memory.buffer128 ->
i: Prims.nat ->
vfh: Vale.Arch.HeapImpl.vale_full_heap ->
t: Vale.Arch.HeapTypes_s.taint ->
hid: Vale.Arch.HeapImpl.heaplet_id
-> FStar.Pervasives.Lemma
(requires
(let _ =
Vale.Lib.Map16.get (Mkvale_full_heap?.vf_heaplets vfh) hid,
Mkvale_heap_layout?.vl_taint (Mkvale_full_heap?.vf_layout vfh)
in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ h mt = _ in
i < FStar.Seq.Base.length (Vale.X64.Memory.buffer_as_seq h b) /\
Vale.X64.Memory.buffer_readable h b /\
Vale.X64.Memory.valid_layout_buffer b (Mkvale_full_heap?.vf_layout vfh) h false /\
Vale.X64.Memory.valid_taint_buf128 b h mt t /\ Vale.X64.Memory.mem_inv vfh)
<:
Type0))
(ensures
(let _ =
Vale.Lib.Map16.get (Mkvale_full_heap?.vf_heaplets vfh) hid,
Mkvale_heap_layout?.vl_taint (Mkvale_full_heap?.vf_layout vfh)
in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ h mt = _ in
let ptr = Vale.X64.Memory.buffer_addr b h + Vale.X64.Memory.scale16 i in
Vale.X64.Memory_Sems.is_full_read (Mkvale_full_heap?.vf_heap vfh) h b i /\
Vale.X64.Memory.valid_mem128 ptr (Mkvale_full_heap?.vf_heap vfh) /\
Vale.X64.Memory.valid_taint_buf128 b (Mkvale_full_heap?.vf_heap vfh) mt t)
<:
Type0)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.X64.Memory.buffer128",
"Prims.nat",
"Vale.Arch.HeapImpl.vale_full_heap",
"Vale.Arch.HeapTypes_s.taint",
"Vale.Arch.HeapImpl.heaplet_id",
"Prims.unit",
"FStar.Pervasives.reveal_opaque",
"Vale.Arch.HeapTypes_s.base_typ",
"Vale.X64.Memory.buffer",
"Vale.Arch.HeapImpl.vale_heap_layout",
"FStar.Pervasives.Native.option",
"Prims.bool",
"Vale.Def.Prop_s.prop0",
"Vale.X64.Memory.valid_layout_buffer_id"
] | [] | true | false | true | false | false | let low_lemma_load_mem128_full b i vfh t hid =
| reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
() | false |
Vale.X64.Memory_Sems.fst | Vale.X64.Memory_Sems.store_buffer_down128_mem | val store_buffer_down128_mem
(b: buffer128{buffer_writeable b})
(i: nat{i < buffer_length b})
(v: quad32)
(h: vale_heap{List.memP b (_ih h).IB.ptrs})
: Lemma
(ensures
(let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
forall (j: int). {:pattern mem1.[ j ]\/mem2.[ j ]}
j < base + scale16 i \/ j >= base + scale16 (i + 1) ==> mem1.[ j ] == mem2.[ j ])) | val store_buffer_down128_mem
(b: buffer128{buffer_writeable b})
(i: nat{i < buffer_length b})
(v: quad32)
(h: vale_heap{List.memP b (_ih h).IB.ptrs})
: Lemma
(ensures
(let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
forall (j: int). {:pattern mem1.[ j ]\/mem2.[ j ]}
j < base + scale16 i \/ j >= base + scale16 (i + 1) ==> mem1.[ j ] == mem2.[ j ])) | let store_buffer_down128_mem
(b:buffer128{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:quad32)
(h:vale_heap{List.memP b (_ih h).IB.ptrs})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
forall (j:int). {:pattern mem1.[j] \/ mem2.[j]}
j < base + scale16 i \/ j >= base + scale16 (i+1) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
let aux (j:int)
: Lemma
(j < base + scale16 i \/ j >= base + scale16 (i+1) ==>
mem1.[j] == mem2.[j])
=
I.addrs_set_lemma_all ();
if j >= base && j < base + DV.length (get_downview b.bsrc) then begin
written_buffer_down128 b i v h;
length_t_eq TUInt128 b
end
else if not (I.valid_addr (_ih h) j)
then I.same_unspecified_down (_ih h).IB.hs (_ih h1).IB.hs (_ih h).IB.ptrs
else unwritten_buffer_down TUInt128 b i v h
in
Classical.forall_intro aux | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory_Sems.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 30,
"end_line": 910,
"start_col": 0,
"start_line": 877
} | module Vale.X64.Memory_Sems
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.Def.Words_s
module I = Vale.Interop
module S = Vale.X64.Machine_Semantics_s
module MB = LowStar.Monotonic.Buffer
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
friend Vale.X64.Memory
module IB = Vale.Interop.Base
let same_domain h m = Set.equal (IB.addrs_set (_ih h)) (Map.domain m)
let lemma_same_domains h m1 m2 = ()
let get_heap h = I.down_mem (_ih h)
let upd_heap h m = mi_heap_upd h m
//let lemma_upd_get_heap h = I.down_up_identity (_ih h)
let lemma_get_upd_heap h m = I.up_down_identity (_ih h) m
let lemma_heap_impl = ()
let lemma_heap_get_heap h = ()
let lemma_heap_taint h = ()
//let lemma_heap_upd_heap h mh mt = ()
[@"opaque_to_smt"]
let rec set_of_range (a:int) (n:nat) : Pure (Set.set int)
(requires True)
(ensures fun s -> (forall (i:int).{:pattern Set.mem i s} Set.mem i s <==> a <= i /\ i < a + n))
=
if n = 0 then Set.empty else Set.union (set_of_range a (n - 1)) (Set.singleton (a + n - 1))
let buffer_info_has_addr (bi:buffer_info) (a:int) =
let b = bi.bi_buffer in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
addr <= a /\ a < addr + len
let buffer_info_has_addr_opt (bi:option buffer_info) (a:int) =
match bi with
| None -> False
| Some bi -> buffer_info_has_addr bi a
#set-options "--z3rlimit 100"
let rec make_owns_rec (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
if n = 0 then ((fun _ -> None), (fun _ -> Set.empty)) else
let (m0, s0) = make_owns_rec h bs (n - 1) in
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let s i = if i = hi then Set.union (s0 i) s_b else s0 i in
let m a = if addr <= a && a < addr + len then Some (n - 1) else m0 a in
(m, s)
[@"opaque_to_smt"]
let make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
make_owns_rec h bs n
let rec lemma_make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n <= Seq.length bs /\
(forall (i:nat).{:pattern Seq.index bs i} i < Seq.length bs ==> buffer_readable h (Seq.index bs i).bi_buffer) /\
(forall (i1 i2:nat).{:pattern (Seq.index bs i1); (Seq.index bs i2)}
i1 < Seq.length bs /\ i2 < Seq.length bs ==> buffer_info_disjoint (Seq.index bs i1) (Seq.index bs i2))
)
(ensures (
let (m, s) = make_owns h bs n in
(forall (i:heaplet_id) (a:int).{:pattern Set.mem a (s i)}
(Set.mem a (s i) <==> Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (m a) == Some i) /\
(Set.mem a (s i) ==> buffer_info_has_addr_opt (Option.mapTot (fun n -> Seq.index bs n) (m a)) a) /\
(Set.mem a (s i) ==> Set.mem a (Map.domain h.mh))
) /\
(forall (k:nat) (a:int).{:pattern Set.mem a (s (Seq.index bs k).bi_heaplet)}
k < n /\ buffer_info_has_addr (Seq.index bs k) a ==> Set.mem a (s (Seq.index bs k).bi_heaplet))
))
=
reveal_opaque (`%make_owns) make_owns;
if n = 0 then () else
let _ = make_owns h bs (n - 1) in
let (m, s) = make_owns h bs n in
lemma_make_owns h bs (n - 1);
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let lem1 (a:int) : Lemma
(requires Set.mem a s_b)
(ensures Set.mem a (Map.domain h.mh))
[SMTPat (Set.mem a (Map.domain h.mh))]
=
I.addrs_set_mem h.ih b a
in
let lem2 (i:heaplet_id) (a:int) : Lemma
(requires i =!= hi /\ Set.mem a (Set.intersect s_b (s i)))
(ensures False)
[SMTPat (Set.mem a (s i))]
=
reveal_opaque (`%addr_map_pred) addr_map_pred
in
()
#push-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_loc_mutable_buffers_rec (l:list buffer_info) (s:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n + List.length l == Seq.length s /\
list_to_seq_post l s n
)
(ensures (
let modloc = loc_mutable_buffers l in
forall (i:nat).{:pattern Seq.index s i} n <= i /\ i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes modloc (loc_buffer bi.bi_buffer))
))
(decreases l)
=
match l with
| [] -> ()
| h::t -> lemma_loc_mutable_buffers_rec t s (n + 1)
#pop-options
let lemma_loc_mutable_buffers (l:list buffer_info) : Lemma
(ensures (
let s = list_to_seq l in
forall (i:nat).{:pattern Seq.index s i} i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes (loc_mutable_buffers l) (loc_buffer bi.bi_buffer))
))
=
lemma_list_to_seq l;
lemma_loc_mutable_buffers_rec l (list_to_seq l) 0
let create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let modloc = loc_mutable_buffers buffers in
let layout1 = h1.vf_layout in
let layin1 = layout1.vl_inner in
let (hmap, hsets) = make_owns h1.vf_heap bs (Seq.length bs) in
let hmap a = Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (hmap a) in
let l = {
vl_heaplets_initialized = true;
vl_heaplet_map = hmap;
vl_heaplet_sets = hsets;
vl_old_heap = h1.vf_heap;
vl_buffers = bs;
vl_mod_loc = modloc;
} in
let layout2 = {layout1 with vl_inner = l} in
let h2 = {
vf_layout = layout2;
vf_heap = h1.vf_heap;
vf_heaplets = h1.vf_heaplets;
} in
h2
let lemma_create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let h2 = create_heaplets buffers h1 in
assert (h2.vf_layout.vl_inner.vl_buffers == bs); // REVIEW: why is this necessary, even with extra ifuel?
lemma_make_owns h1.vf_heap bs (Seq.length bs);
lemma_loc_mutable_buffers buffers;
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
let destroy_heaplets h1 =
h1
let lemma_destroy_heaplets h1 =
()
val heap_shift (m1 m2:S.machine_heap) (base:int) (n:nat) : Lemma
(requires (forall i. 0 <= i /\ i < n ==> m1.[base + i] == m2.[base + i]))
(ensures (forall i. {:pattern (m1.[i])} base <= i /\ i < base + n ==> m1.[i] == m2.[i]))
#push-options "--smtencoding.l_arith_repr boxwrap"
let heap_shift m1 m2 base n =
assert (forall i. base <= i /\ i < base + n ==>
m1.[base + (i - base)] == m2.[base + (i - base)])
#pop-options
val same_mem_eq_slices64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 8 + 8 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8)))
let same_mem_eq_slices64 b i v k h1 h2 mem1 mem2 =
let t = TUInt64 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up64 (b:buffer64) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 8}) : Lemma
(scale8 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint64_view in
UV.length_eq vb
val same_mem_get_heap_val64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale8 k in
forall (x:int).{:pattern (mem1.[x])} ptr <= x /\ x < ptr + 8 ==> mem1.[x] == mem2.[x]))
let same_mem_get_heap_val64 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale8 k in
let addr = buffer_addr b h1 in
let aux (x:int{ptr <= x /\ x < ptr + 8}) : Lemma (mem1.[x] == mem2.[x]) =
let i = x - ptr in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices64 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8) (k * 8 + 8)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8) (k * 8 + 8)) in
assert (Seq.index s1 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i));
length_up64 b h1 k i;
assert (mem1.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i)));
assert (Seq.index s2 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i));
length_up64 b h2 k i;
assert (mem2.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i)))
in
Classical.forall_intro aux;
assert (forall i. addr + (scale8 k + i) == ptr + i)
let rec written_buffer_down64_aux1
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(k:nat) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j.{:pattern (mem1.[j]) \/ (mem2.[j])}
base <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem1.[j])}
j >= base /\ j < base + scale8 i ==>
mem1.[j] == mem2.[j]))
(decreases %[i-k]) =
if k >= i then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux1 b i v h base (k+1) h1 mem1 mem2
end
let rec written_buffer_down64_aux2
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(n:nat{n == buffer_length b})
(k:nat{k > i}) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
base + scale8 (i+1) <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
j >= base + scale8 (i+1) /\ j < base + scale8 n ==>
mem1.[j] == mem2.[j]))
(decreases %[n-k]) =
if k >= n then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux2 b i v h base n (k+1) h1 mem1 mem2
end
let written_buffer_down64 (b:buffer64{buffer_writeable b}) (i:nat{i < buffer_length b}) (v:nat64) (h:vale_heap)
: Lemma
(requires List.memP b (IB.ptrs_of_mem (_ih h)))
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
(base <= j /\ j < base + scale8 i) \/
(base + scale8 (i+1) <= j /\ j < base + scale8 n) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
written_buffer_down64_aux1 b i v h base 0 h1 mem1 mem2;
written_buffer_down64_aux2 b i v h base n (i+1) h1 mem1 mem2
let unwritten_buffer_down (t:base_typ) (b:buffer t{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:base_typ_as_vale_type t)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall (a:b8{List.memP a (IB.ptrs_of_mem (_ih h)) /\ a =!= b}) j. {:pattern mem1.[j]; List.memP a (IB.ptrs_of_mem (_ih h)) \/ mem2.[j]; List.memP a (IB.ptrs_of_mem (_ih h))}
let base = (IB.addrs_of_mem (_ih h)) a in
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==> mem1.[j] == mem2.[j]))
= let aux (a:b8{a =!= b /\ List.memP a (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let base = (IB.addrs_of_mem (_ih h)) a in
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall j.
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==>
mem1.[j] == mem2.[j]))
= let db = get_downview a.bsrc in
if DV.length db = 0 then ()
else
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = (IB.addrs_of_mem (_ih h)) a in
let s0 = DV.as_seq (IB.hs_of_mem (_ih h)) db in
let s1 = DV.as_seq (IB.hs_of_mem (_ih h1)) db in
opaque_assert (`%IB.list_disjoint_or_eq) IB.list_disjoint_or_eq IB.list_disjoint_or_eq_def (MB.disjoint a.bsrc b.bsrc);
lemma_dv_equal (IB.down_view a.src) a.bsrc (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1));
assert (Seq.equal s0 s1);
assert (forall (j:int).{:pattern (mem1.[j])}
base <= j /\ j < base + Seq.length s0 ==> v_to_typ TUInt8 (Seq.index s0 (j - base)) == mem1.[j]);
heap_shift mem1 mem2 base (DV.length db)
in
Classical.forall_intro aux
let store_buffer_down64_mem
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
forall (j:int). {:pattern mem1.[j] \/ mem2.[j]}
j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
let aux (j:int)
: Lemma
(j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j])
=
I.addrs_set_lemma_all ();
if j >= base && j < base + DV.length (get_downview b.bsrc) then begin
written_buffer_down64 b i v h;
length_t_eq (TUInt64) b
end
else if not (I.valid_addr (_ih h) j)
then I.same_unspecified_down (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1)) (IB.ptrs_of_mem (_ih h))
else unwritten_buffer_down TUInt64 b i v h
in
Classical.forall_intro aux
let store_buffer_aux_down64_mem (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
forall j. {:pattern mem1.[j] \/ mem2.[j]}
j < ptr \/ j >= ptr + 8 ==>
mem1.[j] == mem2.[j]))
= let t = TUInt64 in
let h1 = store_mem t ptr v h in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
store_buffer_write t ptr v h;
assert (buffer_addr b h + scale8 i == ptr);
assert (buffer_addr b h + scale8 (i+1) == ptr + 8);
store_buffer_down64_mem b i v h
let store_buffer_aux_down64_mem2 (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
S.get_heap_val64 ptr mem2 == v))
= let t = TUInt64 in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
let h1 = store_mem t ptr v h in
let mem2 = I.down_mem (_ih h1) in
store_buffer_write t ptr v h;
assert (Seq.index (buffer_as_seq h1 b) i == v);
index64_get_heap_val64 h1 b mem2 i
let in_bounds64 (h:vale_heap) (b:buffer64) (i:nat{i < buffer_length b})
: Lemma (scale8 i + 8 <= DV.length (get_downview b.bsrc))
=
length_t_eq TUInt64 b
let bytes_valid64 ptr h =
reveal_opaque (`%S.valid_addr64) S.valid_addr64;
let t = TUInt64 in
let b = get_addr_ptr t ptr h in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
in_bounds64 h b i;
I.addrs_set_mem (_ih h) b ptr;
I.addrs_set_mem (_ih h) b (ptr+1);
I.addrs_set_mem (_ih h) b (ptr+2);
I.addrs_set_mem (_ih h) b (ptr+3);
I.addrs_set_mem (_ih h) b (ptr+4);
I.addrs_set_mem (_ih h) b (ptr+5);
I.addrs_set_mem (_ih h) b (ptr+6);
I.addrs_set_mem (_ih h) b (ptr+7)
val same_mem_get_heap_val128 (b:buffer128)
(i:nat{i < buffer_length b})
(v:quad32)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1)) /\ buffer_writeable b})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale16 k in
forall i.{:pattern mem1.[i]} i >= ptr /\ i < ptr+16 ==> mem1.[i] == mem2.[i]))
val same_mem_eq_slices128 (b:buffer128)
(i:nat{i < buffer_length b})
(v:quad32)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1)) /\ buffer_writeable b})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 16 + 16 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 16) (k * 16 + 16) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 16) (k * 16 + 16)))
let same_mem_eq_slices128 b i v k h1 h2 mem1 mem2 =
let t = TUInt128 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up128 (b:buffer128) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 16}) : Lemma
(scale16 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint128_view in
UV.length_eq vb
let same_mem_get_heap_val128 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale16 k in
let addr = buffer_addr b h1 in
let aux (i:nat{ptr <= i /\ i < ptr+16}) : Lemma (mem1.[i] == mem2.[i]) =
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint128_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices128 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16) (k * 16 + 16)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16) (k * 16 + 16)) in
assert (Seq.index s1 (i - ptr) == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16 + (i-ptr)));
length_up128 b h1 k (i-ptr);
assert (mem1.[i] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16 + (i-ptr))));
assert (Seq.index s2 (i-ptr) == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16 + (i-ptr)));
length_up128 b h2 k (i-ptr);
assert (mem2.[addr+(scale16 k + (i-ptr))] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16 + (i-ptr))));
assert (forall i. addr + (scale16 k + (i-ptr)) == i)
in
Classical.forall_intro aux
let in_bounds128 (h:vale_heap) (b:buffer128) (i:nat{i < buffer_length b}) : Lemma
(scale16 i + 16 <= DV.length (get_downview b.bsrc))
=
length_t_eq TUInt128 b
#push-options "--z3rlimit 20"
#restart-solver
let bytes_valid128 ptr h =
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
IB.list_disjoint_or_eq_reveal ();
let t = TUInt128 in
let b = get_addr_ptr t ptr h in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
in_bounds128 h b i;
I.addrs_set_mem (_ih h) b ptr;
I.addrs_set_mem (_ih h) b (ptr+1);
I.addrs_set_mem (_ih h) b (ptr+2);
I.addrs_set_mem (_ih h) b (ptr+3);
I.addrs_set_mem (_ih h) b (ptr+4);
I.addrs_set_mem (_ih h) b (ptr+5);
I.addrs_set_mem (_ih h) b (ptr+6);
I.addrs_set_mem (_ih h) b (ptr+7);
I.addrs_set_mem (_ih h) b (ptr+8);
I.addrs_set_mem (_ih h) b (ptr+9);
I.addrs_set_mem (_ih h) b (ptr+10);
I.addrs_set_mem (_ih h) b (ptr+11);
I.addrs_set_mem (_ih h) b (ptr+12);
I.addrs_set_mem (_ih h) b (ptr+13);
I.addrs_set_mem (_ih h) b (ptr+14);
I.addrs_set_mem (_ih h) b (ptr+15)
#pop-options
let equiv_load_mem64 ptr h =
let t = TUInt64 in
let b = get_addr_ptr t ptr h in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
let addr = buffer_addr b h in
let contents = DV.as_seq (_ih h).IB.hs (get_downview b.bsrc) in
let heap = get_heap h in
index64_get_heap_val64 h b heap i;
lemma_load_mem64 b i h
//let low_lemma_valid_mem64 b i h =
// lemma_valid_mem64 b i h;
// bytes_valid64 (buffer_addr b h + scale8 i) h
//let low_lemma_load_mem64 b i h =
// lemma_valid_mem64 b i h;
// lemma_load_mem64 b i h;
// equiv_load_mem64 (buffer_addr b h + scale8 i) h
//let same_domain_update64 b i v h =
// low_lemma_valid_mem64 b i h;
// Vale.Arch.MachineHeap.same_domain_update64 (buffer_addr b h + scale8 i) v (get_heap h)
open Vale.X64.BufferViewStore
let low_lemma_store_mem64_aux
(b:buffer64)
(heap:S.machine_heap)
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{buffer_readable h b /\ buffer_writeable b})
: Lemma
(requires IB.correct_down_p (_ih h) heap b)
(ensures (let heap' = S.update_heap64 (buffer_addr b h + scale8 i) v heap in
let h' = store_mem64 (buffer_addr b h + scale8 i) v h in
(_ih h').IB.hs == DV.upd_seq (_ih h).IB.hs (get_downview b.bsrc) (I.get_seq_heap heap' (_ih h).IB.addrs b))) =
let ptr = buffer_addr b h + scale8 i in
let heap' = S.update_heap64 ptr v heap in
let h' = store_mem64 ptr v h in
lemma_store_mem64 b i v h;
length_t_eq TUInt64 b;
bv_upd_update_heap64 b heap i v (_ih h);
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db Vale.Interop.Views.up_view64 in
assert (UV.upd (_ih h).IB.hs bv i (UInt64.uint_to_t v) == (_ih h').IB.hs)
val valid_state_store_mem64_aux: (i:nat) -> (v:nat64) -> (h:vale_heap) -> Lemma
(requires writeable_mem64 i h)
(ensures (
let heap = get_heap h in
let heap' = S.update_heap64 i v heap in
let h' = store_mem64 i v h in
heap' == I.down_mem (_ih h')
))
let valid_state_store_mem64_aux i v h =
let heap = get_heap h in
let heap' = S.update_heap64 i v heap in
let h1 = store_mem TUInt64 i v h in
store_buffer_aux_down64_mem i v h;
store_buffer_aux_down64_mem2 i v h;
let mem1 = heap' in
let mem2 = I.down_mem (_ih h1) in
let aux () : Lemma (forall j. mem1.[j] == mem2.[j]) =
Vale.Arch.MachineHeap.same_mem_get_heap_val64 i mem1 mem2;
Vale.Arch.MachineHeap.correct_update_get64 i v heap;
Vale.Arch.MachineHeap.frame_update_heap64 i v heap
in let aux2 () : Lemma (Set.equal (Map.domain mem1) (Map.domain mem2)) =
bytes_valid64 i h;
Vale.Arch.MachineHeap.same_domain_update64 i v heap
in aux(); aux2();
Map.lemma_equal_intro mem1 mem2
let low_lemma_load_mem64_full b i vfh t hid =
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
#push-options "--z3rlimit 20"
#restart-solver
let low_lemma_store_mem64 b i v h =
lemma_writeable_mem64 b i h;
lemma_store_mem64 b i v h;
valid_state_store_mem64_aux (buffer_addr b h + scale8 i) v h;
let heap = get_heap h in
let heap' = S.update_heap64 (buffer_addr b h + scale8 i) v heap in
low_lemma_store_mem64_aux b heap i v h;
Vale.Arch.MachineHeap.frame_update_heap64 (buffer_addr b h + scale8 i) v heap;
in_bounds64 h b i;
I.addrs_set_lemma_all ();
I.update_buffer_up_mem (_ih h) b heap heap'
#pop-options
#set-options "--z3rlimit 100"
#restart-solver
let lemma_is_full_update
(vfh:vale_full_heap) (h hk hk':vale_heap) (k:heaplet_id) (mh mh' mhk mhk':machine_heap) (mt mt':memtaint)
(t:base_typ) (b:buffer t) (ptr:int) (v_size:nat)
(index:nat) (v:base_typ_as_vale_type t) (tn:taint)
: Lemma
(requires
vfh.vf_layout.vl_inner.vl_heaplets_initialized /\
mem_inv vfh /\
buffer_readable hk b /\
buffer_writeable b /\
index < Seq.length (buffer_as_seq hk b) /\
mt == vfh.vf_layout.vl_taint /\
h == vfh.vf_heap /\
hk == Map16.sel vfh.vf_heaplets k /\
mh == h.mh /\
mhk == hk.mh /\
ptr == buffer_addr b hk + scale_by v_size index /\
mt' == S.update_n ptr v_size (heap_taint (coerce vfh)) tn /\
hk' == buffer_write b index v hk /\
valid_layout_buffer b vfh.vf_layout hk true /\
valid_taint_buf b hk mt tn /\
is_machine_heap_update mh mh' /\ upd_heap h mh' == buffer_write b index v h /\
is_machine_heap_update mhk mhk' /\ upd_heap hk mhk' == buffer_write b index v hk /\
(forall j.{:pattern mh.[j] \/ mh'.[j]} j < ptr \/ j >= ptr + v_size ==> mh.[j] == mh'.[j]) /\
(forall j.{:pattern mhk.[j] \/ mhk'.[j]} j < ptr \/ j >= ptr + v_size ==> mhk.[j] == mhk'.[j]) /\
0 <= scale_by v_size index /\ scale_by v_size index + v_size <= DV.length (get_downview b.bsrc) /\
(forall i.{:pattern mh'.[i] \/ mhk'.[i]} i >= ptr /\ i < ptr + v_size ==> mh'.[i] == mhk'.[i]) /\
True
)
(ensures is_full_update vfh hk' k mh' mt')
=
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
let vfh' = coerce (heap_upd (coerce vfh) mh' mt') in
let dom_upd = Set.intersect (vfh.vf_layout.vl_inner.vl_heaplet_sets k) (Map.domain mhk) in
let mhk'' = Map.concat mhk (Map.restrict dom_upd mh') in
assert (Map.equal mhk'' mhk');
let unchanged (j:heaplet_id) : Lemma
(requires j =!= k)
(ensures Map16.sel vfh'.vf_heaplets j == Map16.sel vfh.vf_heaplets j)
[SMTPat (Map16.sel vfh'.vf_heaplets j)]
=
assert (Map.equal (Map16.sel vfh'.vf_heaplets j).mh (Map16.sel vfh.vf_heaplets j).mh);
I.down_up_identity (Map16.sel vfh.vf_heaplets j).ih;
()
in
assert (Map16.equal vfh'.vf_heaplets (Map16.upd vfh.vf_heaplets k hk'));
assert (Map.equal mt' mt);
Vale.Interop.Heap_s.list_disjoint_or_eq_reveal ();
()
let low_lemma_store_mem64_full b i v vfh t hid =
let (h, mt, hk) = (vfh.vf_heap, vfh.vf_layout.vl_taint, Map16.get vfh.vf_heaplets hid) in
let ptr = buffer_addr b hk + scale8 i in
let mh' = S.update_heap64 ptr v (heap_get (coerce vfh)) in
let mt' = S.update_n ptr 8 (heap_taint (coerce vfh)) t in
let hk' = buffer_write b i v hk in
let mhk' = S.update_heap64 ptr v (get_heap hk) in
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
low_lemma_store_mem64 b i v h;
low_lemma_store_mem64 b i v (Map16.get vfh.vf_heaplets hid);
Vale.Arch.MachineHeap.frame_update_heap64 ptr v h.mh;
Vale.Arch.MachineHeap.frame_update_heap64 ptr v hk.mh;
in_bounds64 hk b i;
Vale.Arch.MachineHeap.same_mem_get_heap_val64 ptr mh' mhk';
lemma_is_full_update vfh h hk hk' hid h.mh mh' hk.mh mhk' mt mt' TUInt64 b ptr 8 i v t;
()
val low_lemma_valid_mem128 (b:buffer128) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b
)
(ensures
S.valid_addr128 (buffer_addr b h + scale16 i) (get_heap h)
)
let low_lemma_valid_mem128 b i h =
lemma_valid_mem128 b i h;
bytes_valid128 (buffer_addr b h + scale16 i) h
val equiv_load_mem128_aux: (ptr:int) -> (h:vale_heap) -> Lemma
(requires valid_mem128 ptr h)
(ensures load_mem128 ptr h == S.get_heap_val128 ptr (get_heap h))
let equiv_load_mem128_aux ptr h =
let t = TUInt128 in
let b = get_addr_ptr t ptr h in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
let addr = buffer_addr b h in
let contents = DV.as_seq (_ih h).IB.hs (get_downview b.bsrc) in
let heap = get_heap h in
S.get_heap_val128_reveal ();
index128_get_heap_val128 h b heap i;
lemma_load_mem128 b i h
let equiv_load_mem128 ptr h =
equiv_load_mem128_aux ptr h
val low_lemma_load_mem128 (b:buffer128) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b
)
(ensures
S.get_heap_val128 (buffer_addr b h + scale16 i) (get_heap h) == buffer_read b i h
)
let low_lemma_load_mem128 b i h =
lemma_valid_mem128 b i h;
lemma_load_mem128 b i h;
equiv_load_mem128_aux (buffer_addr b h + scale16 i) h
//let same_domain_update128 b i v h =
// low_lemma_valid_mem128 b i h;
// Vale.Arch.MachineHeap.same_domain_update128 (buffer_addr b h + scale16 i) v (get_heap h)
let low_lemma_store_mem128_aux
(b:buffer128)
(heap:S.machine_heap)
(i:nat{i < buffer_length b})
(v:quad32)
(h:vale_heap{buffer_readable h b /\ buffer_writeable b})
: Lemma
(requires IB.correct_down_p (_ih h) heap b)
(ensures (let heap' = S.update_heap128 (buffer_addr b h + scale16 i) v heap in
let h' = store_mem128 (buffer_addr b h + scale16 i) v h in
(_ih h').IB.hs == DV.upd_seq (_ih h).IB.hs (get_downview b.bsrc) (I.get_seq_heap heap' (_ih h).IB.addrs b))) =
let ptr = buffer_addr b h + scale16 i in
let heap' = S.update_heap128 ptr v heap in
let h' = store_mem128 ptr v h in
lemma_store_mem128 b i v h;
length_t_eq TUInt128 b;
bv_upd_update_heap128 b heap i v (_ih h);
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db Vale.Interop.Views.up_view128 in
assert (UV.upd (_ih h).IB.hs bv i v == (_ih h').IB.hs)
val valid_state_store_mem128_aux (i:int) (v:quad32) (h:vale_heap) : Lemma
(requires writeable_mem128 i h)
(ensures (
let heap = get_heap h in
let heap' = S.update_heap128 i v heap in
let h' = store_mem128 i v h in
heap' == I.down_mem (_ih h')
))
#restart-solver
let rec written_buffer_down128_aux1
(b:buffer128{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:quad32)
(h:vale_heap{List.memP b (_ih h).IB.ptrs})
(base:nat{base == buffer_addr b h})
(k:nat) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j.{:pattern (mem1.[j]) \/ (mem2.[j])}
base <= j /\ j < base + k * 16 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem1.[j])}
j >= base /\ j < base + scale16 i ==>
mem1.[j] == mem2.[j]))
(decreases %[i-k]) =
if k >= i then ()
else begin
let ptr = base + scale16 k in
same_mem_get_heap_val128 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 16;
written_buffer_down128_aux1 b i v h base (k+1) h1 mem1 mem2
end
#restart-solver
let rec written_buffer_down128_aux2
(b:buffer128{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:quad32)
(h:vale_heap{List.memP b (_ih h).IB.ptrs})
(base:nat{base == buffer_addr b h})
(n:nat{n == buffer_length b})
(k:nat{k > i}) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
base + scale16 (i+1) <= j /\ j < base + k * 16 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
j >= base + scale16 (i+1) /\ j < base + scale16 n ==>
mem1.[j] == mem2.[j]))
(decreases %[n-k]) =
if k >= n then ()
else begin
let ptr = base + scale16 k in
same_mem_get_heap_val128 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 16;
written_buffer_down128_aux2 b i v h base n (k+1) h1 mem1 mem2
end
let written_buffer_down128 (b:buffer128) (i:nat{i < buffer_length b}) (v:quad32) (h:vale_heap)
: Lemma
(requires List.memP b (_ih h).IB.ptrs /\ buffer_writeable b)
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
(base <= j /\ j < base + scale16 i) \/
(base + scale16 (i+1) <= j /\ j < base + scale16 n) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
written_buffer_down128_aux1 b i v h base 0 h1 mem1 mem2;
written_buffer_down128_aux2 b i v h base n (i+1) h1 mem1 mem2 | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Memory.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.BufferViewStore.fsti.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Memory_Sems.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.BufferViewStore",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_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
}
] | {
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
b: Vale.X64.Memory.buffer128{Vale.X64.Memory.buffer_writeable b} ->
i: Prims.nat{i < Vale.X64.Memory.buffer_length b} ->
v: Vale.X64.Memory.quad32 ->
h:
Vale.Arch.HeapImpl.vale_heap
{FStar.List.Tot.Base.memP b (InteropHeap?.ptrs (Vale.Arch.HeapImpl._ih h))}
-> FStar.Pervasives.Lemma
(ensures
(let mem1 = Vale.Interop.down_mem (Vale.Arch.HeapImpl._ih h) in
let h1 = Vale.X64.Memory.buffer_write b i v h in
let mem2 = Vale.Interop.down_mem (Vale.Arch.HeapImpl._ih h1) in
let base = Vale.X64.Memory.buffer_addr b h in
forall (j: Prims.int). {:pattern mem1.[ j ]\/mem2.[ j ]}
j < base + Vale.X64.Memory.scale16 i \/ j >= base + Vale.X64.Memory.scale16 (i + 1) ==>
mem1.[ j ] == mem2.[ j ])) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.X64.Memory.buffer128",
"Vale.X64.Memory.buffer_writeable",
"Vale.X64.Memory.vuint128",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Vale.X64.Memory.buffer_length",
"Vale.X64.Memory.quad32",
"Vale.Arch.HeapImpl.vale_heap",
"FStar.List.Tot.Base.memP",
"Vale.Interop.Types.b8",
"Vale.Interop.Heap_s.__proj__InteropHeap__item__ptrs",
"Vale.Arch.HeapImpl._ih",
"FStar.Classical.forall_intro",
"Prims.int",
"Prims.l_imp",
"Prims.l_or",
"Prims.op_Addition",
"Vale.X64.Memory.scale16",
"Prims.op_GreaterThanOrEqual",
"Prims.eq2",
"Vale.Def.Types_s.nat8",
"Vale.X64.Memory.op_String_Access",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Vale.X64.Memory.scale_by",
"Vale.Def.Words_s.nat8",
"FStar.Map.sel",
"Prims.Nil",
"FStar.Pervasives.pattern",
"Prims.op_AmpAmp",
"LowStar.BufferView.Down.length",
"FStar.UInt8.t",
"Vale.Interop.Types.get_downview",
"Vale.Interop.Types.__proj__Buffer__item__src",
"Vale.Interop.Types.b8_preorder",
"Vale.Interop.Types.__proj__Buffer__item__writeable",
"Vale.Interop.Types.base_typ_as_type",
"Vale.Interop.Types.__proj__Buffer__item__bsrc",
"Vale.X64.Memory.length_t_eq",
"Vale.Arch.HeapTypes_s.TUInt128",
"Vale.X64.Memory_Sems.written_buffer_down128",
"Prims.bool",
"Prims.op_Negation",
"Vale.Interop.valid_addr",
"Vale.Interop.same_unspecified_down",
"Vale.Interop.Heap_s.__proj__InteropHeap__item__hs",
"Vale.X64.Memory_Sems.unwritten_buffer_down",
"Vale.Interop.addrs_set_lemma_all",
"Vale.X64.Memory.buffer_addr",
"Vale.Arch.MachineHeap_s.machine_heap",
"Vale.Interop.Heap_s.correct_down",
"Vale.Interop.down_mem",
"Vale.X64.Memory.buffer_write",
"Prims.l_Forall"
] | [] | false | false | true | false | false | let store_buffer_down128_mem
(b: buffer128{buffer_writeable b})
(i: nat{i < buffer_length b})
(v: quad32)
(h: vale_heap{List.memP b (_ih h).IB.ptrs})
: Lemma
(ensures
(let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
forall (j: int). {:pattern mem1.[ j ]\/mem2.[ j ]}
j < base + scale16 i \/ j >= base + scale16 (i + 1) ==> mem1.[ j ] == mem2.[ j ])) =
| let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
let aux (j: int)
: Lemma (j < base + scale16 i \/ j >= base + scale16 (i + 1) ==> mem1.[ j ] == mem2.[ j ]) =
I.addrs_set_lemma_all ();
if j >= base && j < base + DV.length (get_downview b.bsrc)
then
(written_buffer_down128 b i v h;
length_t_eq TUInt128 b)
else
if not (I.valid_addr (_ih h) j)
then I.same_unspecified_down (_ih h).IB.hs (_ih h1).IB.hs (_ih h).IB.ptrs
else unwritten_buffer_down TUInt128 b i v h
in
Classical.forall_intro aux | false |
Vale.X64.Memory_Sems.fst | Vale.X64.Memory_Sems.written_buffer_down128 | val written_buffer_down128 (b: buffer128) (i: nat{i < buffer_length b}) (v: quad32) (h: vale_heap)
: Lemma (requires List.memP b (_ih h).IB.ptrs /\ buffer_writeable b)
(ensures
(let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
forall j. {:pattern (mem1.[ j ])\/(mem2.[ j ])}
(base <= j /\ j < base + scale16 i) \/
(base + scale16 (i + 1) <= j /\ j < base + scale16 n) ==>
mem1.[ j ] == mem2.[ j ])) | val written_buffer_down128 (b: buffer128) (i: nat{i < buffer_length b}) (v: quad32) (h: vale_heap)
: Lemma (requires List.memP b (_ih h).IB.ptrs /\ buffer_writeable b)
(ensures
(let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
forall j. {:pattern (mem1.[ j ])\/(mem2.[ j ])}
(base <= j /\ j < base + scale16 i) \/
(base + scale16 (i + 1) <= j /\ j < base + scale16 n) ==>
mem1.[ j ] == mem2.[ j ])) | let written_buffer_down128 (b:buffer128) (i:nat{i < buffer_length b}) (v:quad32) (h:vale_heap)
: Lemma
(requires List.memP b (_ih h).IB.ptrs /\ buffer_writeable b)
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
(base <= j /\ j < base + scale16 i) \/
(base + scale16 (i+1) <= j /\ j < base + scale16 n) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
written_buffer_down128_aux1 b i v h base 0 h1 mem1 mem2;
written_buffer_down128_aux2 b i v h base n (i+1) h1 mem1 mem2 | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory_Sems.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 65,
"end_line": 875,
"start_col": 0,
"start_line": 856
} | module Vale.X64.Memory_Sems
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.Def.Words_s
module I = Vale.Interop
module S = Vale.X64.Machine_Semantics_s
module MB = LowStar.Monotonic.Buffer
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
friend Vale.X64.Memory
module IB = Vale.Interop.Base
let same_domain h m = Set.equal (IB.addrs_set (_ih h)) (Map.domain m)
let lemma_same_domains h m1 m2 = ()
let get_heap h = I.down_mem (_ih h)
let upd_heap h m = mi_heap_upd h m
//let lemma_upd_get_heap h = I.down_up_identity (_ih h)
let lemma_get_upd_heap h m = I.up_down_identity (_ih h) m
let lemma_heap_impl = ()
let lemma_heap_get_heap h = ()
let lemma_heap_taint h = ()
//let lemma_heap_upd_heap h mh mt = ()
[@"opaque_to_smt"]
let rec set_of_range (a:int) (n:nat) : Pure (Set.set int)
(requires True)
(ensures fun s -> (forall (i:int).{:pattern Set.mem i s} Set.mem i s <==> a <= i /\ i < a + n))
=
if n = 0 then Set.empty else Set.union (set_of_range a (n - 1)) (Set.singleton (a + n - 1))
let buffer_info_has_addr (bi:buffer_info) (a:int) =
let b = bi.bi_buffer in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
addr <= a /\ a < addr + len
let buffer_info_has_addr_opt (bi:option buffer_info) (a:int) =
match bi with
| None -> False
| Some bi -> buffer_info_has_addr bi a
#set-options "--z3rlimit 100"
let rec make_owns_rec (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
if n = 0 then ((fun _ -> None), (fun _ -> Set.empty)) else
let (m0, s0) = make_owns_rec h bs (n - 1) in
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let s i = if i = hi then Set.union (s0 i) s_b else s0 i in
let m a = if addr <= a && a < addr + len then Some (n - 1) else m0 a in
(m, s)
[@"opaque_to_smt"]
let make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
make_owns_rec h bs n
let rec lemma_make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n <= Seq.length bs /\
(forall (i:nat).{:pattern Seq.index bs i} i < Seq.length bs ==> buffer_readable h (Seq.index bs i).bi_buffer) /\
(forall (i1 i2:nat).{:pattern (Seq.index bs i1); (Seq.index bs i2)}
i1 < Seq.length bs /\ i2 < Seq.length bs ==> buffer_info_disjoint (Seq.index bs i1) (Seq.index bs i2))
)
(ensures (
let (m, s) = make_owns h bs n in
(forall (i:heaplet_id) (a:int).{:pattern Set.mem a (s i)}
(Set.mem a (s i) <==> Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (m a) == Some i) /\
(Set.mem a (s i) ==> buffer_info_has_addr_opt (Option.mapTot (fun n -> Seq.index bs n) (m a)) a) /\
(Set.mem a (s i) ==> Set.mem a (Map.domain h.mh))
) /\
(forall (k:nat) (a:int).{:pattern Set.mem a (s (Seq.index bs k).bi_heaplet)}
k < n /\ buffer_info_has_addr (Seq.index bs k) a ==> Set.mem a (s (Seq.index bs k).bi_heaplet))
))
=
reveal_opaque (`%make_owns) make_owns;
if n = 0 then () else
let _ = make_owns h bs (n - 1) in
let (m, s) = make_owns h bs n in
lemma_make_owns h bs (n - 1);
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let lem1 (a:int) : Lemma
(requires Set.mem a s_b)
(ensures Set.mem a (Map.domain h.mh))
[SMTPat (Set.mem a (Map.domain h.mh))]
=
I.addrs_set_mem h.ih b a
in
let lem2 (i:heaplet_id) (a:int) : Lemma
(requires i =!= hi /\ Set.mem a (Set.intersect s_b (s i)))
(ensures False)
[SMTPat (Set.mem a (s i))]
=
reveal_opaque (`%addr_map_pred) addr_map_pred
in
()
#push-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_loc_mutable_buffers_rec (l:list buffer_info) (s:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n + List.length l == Seq.length s /\
list_to_seq_post l s n
)
(ensures (
let modloc = loc_mutable_buffers l in
forall (i:nat).{:pattern Seq.index s i} n <= i /\ i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes modloc (loc_buffer bi.bi_buffer))
))
(decreases l)
=
match l with
| [] -> ()
| h::t -> lemma_loc_mutable_buffers_rec t s (n + 1)
#pop-options
let lemma_loc_mutable_buffers (l:list buffer_info) : Lemma
(ensures (
let s = list_to_seq l in
forall (i:nat).{:pattern Seq.index s i} i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes (loc_mutable_buffers l) (loc_buffer bi.bi_buffer))
))
=
lemma_list_to_seq l;
lemma_loc_mutable_buffers_rec l (list_to_seq l) 0
let create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let modloc = loc_mutable_buffers buffers in
let layout1 = h1.vf_layout in
let layin1 = layout1.vl_inner in
let (hmap, hsets) = make_owns h1.vf_heap bs (Seq.length bs) in
let hmap a = Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (hmap a) in
let l = {
vl_heaplets_initialized = true;
vl_heaplet_map = hmap;
vl_heaplet_sets = hsets;
vl_old_heap = h1.vf_heap;
vl_buffers = bs;
vl_mod_loc = modloc;
} in
let layout2 = {layout1 with vl_inner = l} in
let h2 = {
vf_layout = layout2;
vf_heap = h1.vf_heap;
vf_heaplets = h1.vf_heaplets;
} in
h2
let lemma_create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let h2 = create_heaplets buffers h1 in
assert (h2.vf_layout.vl_inner.vl_buffers == bs); // REVIEW: why is this necessary, even with extra ifuel?
lemma_make_owns h1.vf_heap bs (Seq.length bs);
lemma_loc_mutable_buffers buffers;
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
let destroy_heaplets h1 =
h1
let lemma_destroy_heaplets h1 =
()
val heap_shift (m1 m2:S.machine_heap) (base:int) (n:nat) : Lemma
(requires (forall i. 0 <= i /\ i < n ==> m1.[base + i] == m2.[base + i]))
(ensures (forall i. {:pattern (m1.[i])} base <= i /\ i < base + n ==> m1.[i] == m2.[i]))
#push-options "--smtencoding.l_arith_repr boxwrap"
let heap_shift m1 m2 base n =
assert (forall i. base <= i /\ i < base + n ==>
m1.[base + (i - base)] == m2.[base + (i - base)])
#pop-options
val same_mem_eq_slices64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 8 + 8 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8)))
let same_mem_eq_slices64 b i v k h1 h2 mem1 mem2 =
let t = TUInt64 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up64 (b:buffer64) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 8}) : Lemma
(scale8 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint64_view in
UV.length_eq vb
val same_mem_get_heap_val64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale8 k in
forall (x:int).{:pattern (mem1.[x])} ptr <= x /\ x < ptr + 8 ==> mem1.[x] == mem2.[x]))
let same_mem_get_heap_val64 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale8 k in
let addr = buffer_addr b h1 in
let aux (x:int{ptr <= x /\ x < ptr + 8}) : Lemma (mem1.[x] == mem2.[x]) =
let i = x - ptr in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices64 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8) (k * 8 + 8)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8) (k * 8 + 8)) in
assert (Seq.index s1 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i));
length_up64 b h1 k i;
assert (mem1.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i)));
assert (Seq.index s2 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i));
length_up64 b h2 k i;
assert (mem2.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i)))
in
Classical.forall_intro aux;
assert (forall i. addr + (scale8 k + i) == ptr + i)
let rec written_buffer_down64_aux1
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(k:nat) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j.{:pattern (mem1.[j]) \/ (mem2.[j])}
base <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem1.[j])}
j >= base /\ j < base + scale8 i ==>
mem1.[j] == mem2.[j]))
(decreases %[i-k]) =
if k >= i then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux1 b i v h base (k+1) h1 mem1 mem2
end
let rec written_buffer_down64_aux2
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(n:nat{n == buffer_length b})
(k:nat{k > i}) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
base + scale8 (i+1) <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
j >= base + scale8 (i+1) /\ j < base + scale8 n ==>
mem1.[j] == mem2.[j]))
(decreases %[n-k]) =
if k >= n then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux2 b i v h base n (k+1) h1 mem1 mem2
end
let written_buffer_down64 (b:buffer64{buffer_writeable b}) (i:nat{i < buffer_length b}) (v:nat64) (h:vale_heap)
: Lemma
(requires List.memP b (IB.ptrs_of_mem (_ih h)))
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
(base <= j /\ j < base + scale8 i) \/
(base + scale8 (i+1) <= j /\ j < base + scale8 n) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
written_buffer_down64_aux1 b i v h base 0 h1 mem1 mem2;
written_buffer_down64_aux2 b i v h base n (i+1) h1 mem1 mem2
let unwritten_buffer_down (t:base_typ) (b:buffer t{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:base_typ_as_vale_type t)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall (a:b8{List.memP a (IB.ptrs_of_mem (_ih h)) /\ a =!= b}) j. {:pattern mem1.[j]; List.memP a (IB.ptrs_of_mem (_ih h)) \/ mem2.[j]; List.memP a (IB.ptrs_of_mem (_ih h))}
let base = (IB.addrs_of_mem (_ih h)) a in
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==> mem1.[j] == mem2.[j]))
= let aux (a:b8{a =!= b /\ List.memP a (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let base = (IB.addrs_of_mem (_ih h)) a in
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall j.
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==>
mem1.[j] == mem2.[j]))
= let db = get_downview a.bsrc in
if DV.length db = 0 then ()
else
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = (IB.addrs_of_mem (_ih h)) a in
let s0 = DV.as_seq (IB.hs_of_mem (_ih h)) db in
let s1 = DV.as_seq (IB.hs_of_mem (_ih h1)) db in
opaque_assert (`%IB.list_disjoint_or_eq) IB.list_disjoint_or_eq IB.list_disjoint_or_eq_def (MB.disjoint a.bsrc b.bsrc);
lemma_dv_equal (IB.down_view a.src) a.bsrc (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1));
assert (Seq.equal s0 s1);
assert (forall (j:int).{:pattern (mem1.[j])}
base <= j /\ j < base + Seq.length s0 ==> v_to_typ TUInt8 (Seq.index s0 (j - base)) == mem1.[j]);
heap_shift mem1 mem2 base (DV.length db)
in
Classical.forall_intro aux
let store_buffer_down64_mem
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
forall (j:int). {:pattern mem1.[j] \/ mem2.[j]}
j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
let aux (j:int)
: Lemma
(j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j])
=
I.addrs_set_lemma_all ();
if j >= base && j < base + DV.length (get_downview b.bsrc) then begin
written_buffer_down64 b i v h;
length_t_eq (TUInt64) b
end
else if not (I.valid_addr (_ih h) j)
then I.same_unspecified_down (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1)) (IB.ptrs_of_mem (_ih h))
else unwritten_buffer_down TUInt64 b i v h
in
Classical.forall_intro aux
let store_buffer_aux_down64_mem (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
forall j. {:pattern mem1.[j] \/ mem2.[j]}
j < ptr \/ j >= ptr + 8 ==>
mem1.[j] == mem2.[j]))
= let t = TUInt64 in
let h1 = store_mem t ptr v h in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
store_buffer_write t ptr v h;
assert (buffer_addr b h + scale8 i == ptr);
assert (buffer_addr b h + scale8 (i+1) == ptr + 8);
store_buffer_down64_mem b i v h
let store_buffer_aux_down64_mem2 (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
S.get_heap_val64 ptr mem2 == v))
= let t = TUInt64 in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
let h1 = store_mem t ptr v h in
let mem2 = I.down_mem (_ih h1) in
store_buffer_write t ptr v h;
assert (Seq.index (buffer_as_seq h1 b) i == v);
index64_get_heap_val64 h1 b mem2 i
let in_bounds64 (h:vale_heap) (b:buffer64) (i:nat{i < buffer_length b})
: Lemma (scale8 i + 8 <= DV.length (get_downview b.bsrc))
=
length_t_eq TUInt64 b
let bytes_valid64 ptr h =
reveal_opaque (`%S.valid_addr64) S.valid_addr64;
let t = TUInt64 in
let b = get_addr_ptr t ptr h in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
in_bounds64 h b i;
I.addrs_set_mem (_ih h) b ptr;
I.addrs_set_mem (_ih h) b (ptr+1);
I.addrs_set_mem (_ih h) b (ptr+2);
I.addrs_set_mem (_ih h) b (ptr+3);
I.addrs_set_mem (_ih h) b (ptr+4);
I.addrs_set_mem (_ih h) b (ptr+5);
I.addrs_set_mem (_ih h) b (ptr+6);
I.addrs_set_mem (_ih h) b (ptr+7)
val same_mem_get_heap_val128 (b:buffer128)
(i:nat{i < buffer_length b})
(v:quad32)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1)) /\ buffer_writeable b})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale16 k in
forall i.{:pattern mem1.[i]} i >= ptr /\ i < ptr+16 ==> mem1.[i] == mem2.[i]))
val same_mem_eq_slices128 (b:buffer128)
(i:nat{i < buffer_length b})
(v:quad32)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1)) /\ buffer_writeable b})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 16 + 16 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 16) (k * 16 + 16) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 16) (k * 16 + 16)))
let same_mem_eq_slices128 b i v k h1 h2 mem1 mem2 =
let t = TUInt128 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up128 (b:buffer128) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 16}) : Lemma
(scale16 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint128_view in
UV.length_eq vb
let same_mem_get_heap_val128 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale16 k in
let addr = buffer_addr b h1 in
let aux (i:nat{ptr <= i /\ i < ptr+16}) : Lemma (mem1.[i] == mem2.[i]) =
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint128_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices128 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16) (k * 16 + 16)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16) (k * 16 + 16)) in
assert (Seq.index s1 (i - ptr) == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16 + (i-ptr)));
length_up128 b h1 k (i-ptr);
assert (mem1.[i] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16 + (i-ptr))));
assert (Seq.index s2 (i-ptr) == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16 + (i-ptr)));
length_up128 b h2 k (i-ptr);
assert (mem2.[addr+(scale16 k + (i-ptr))] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16 + (i-ptr))));
assert (forall i. addr + (scale16 k + (i-ptr)) == i)
in
Classical.forall_intro aux
let in_bounds128 (h:vale_heap) (b:buffer128) (i:nat{i < buffer_length b}) : Lemma
(scale16 i + 16 <= DV.length (get_downview b.bsrc))
=
length_t_eq TUInt128 b
#push-options "--z3rlimit 20"
#restart-solver
let bytes_valid128 ptr h =
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
IB.list_disjoint_or_eq_reveal ();
let t = TUInt128 in
let b = get_addr_ptr t ptr h in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
in_bounds128 h b i;
I.addrs_set_mem (_ih h) b ptr;
I.addrs_set_mem (_ih h) b (ptr+1);
I.addrs_set_mem (_ih h) b (ptr+2);
I.addrs_set_mem (_ih h) b (ptr+3);
I.addrs_set_mem (_ih h) b (ptr+4);
I.addrs_set_mem (_ih h) b (ptr+5);
I.addrs_set_mem (_ih h) b (ptr+6);
I.addrs_set_mem (_ih h) b (ptr+7);
I.addrs_set_mem (_ih h) b (ptr+8);
I.addrs_set_mem (_ih h) b (ptr+9);
I.addrs_set_mem (_ih h) b (ptr+10);
I.addrs_set_mem (_ih h) b (ptr+11);
I.addrs_set_mem (_ih h) b (ptr+12);
I.addrs_set_mem (_ih h) b (ptr+13);
I.addrs_set_mem (_ih h) b (ptr+14);
I.addrs_set_mem (_ih h) b (ptr+15)
#pop-options
let equiv_load_mem64 ptr h =
let t = TUInt64 in
let b = get_addr_ptr t ptr h in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
let addr = buffer_addr b h in
let contents = DV.as_seq (_ih h).IB.hs (get_downview b.bsrc) in
let heap = get_heap h in
index64_get_heap_val64 h b heap i;
lemma_load_mem64 b i h
//let low_lemma_valid_mem64 b i h =
// lemma_valid_mem64 b i h;
// bytes_valid64 (buffer_addr b h + scale8 i) h
//let low_lemma_load_mem64 b i h =
// lemma_valid_mem64 b i h;
// lemma_load_mem64 b i h;
// equiv_load_mem64 (buffer_addr b h + scale8 i) h
//let same_domain_update64 b i v h =
// low_lemma_valid_mem64 b i h;
// Vale.Arch.MachineHeap.same_domain_update64 (buffer_addr b h + scale8 i) v (get_heap h)
open Vale.X64.BufferViewStore
let low_lemma_store_mem64_aux
(b:buffer64)
(heap:S.machine_heap)
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{buffer_readable h b /\ buffer_writeable b})
: Lemma
(requires IB.correct_down_p (_ih h) heap b)
(ensures (let heap' = S.update_heap64 (buffer_addr b h + scale8 i) v heap in
let h' = store_mem64 (buffer_addr b h + scale8 i) v h in
(_ih h').IB.hs == DV.upd_seq (_ih h).IB.hs (get_downview b.bsrc) (I.get_seq_heap heap' (_ih h).IB.addrs b))) =
let ptr = buffer_addr b h + scale8 i in
let heap' = S.update_heap64 ptr v heap in
let h' = store_mem64 ptr v h in
lemma_store_mem64 b i v h;
length_t_eq TUInt64 b;
bv_upd_update_heap64 b heap i v (_ih h);
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db Vale.Interop.Views.up_view64 in
assert (UV.upd (_ih h).IB.hs bv i (UInt64.uint_to_t v) == (_ih h').IB.hs)
val valid_state_store_mem64_aux: (i:nat) -> (v:nat64) -> (h:vale_heap) -> Lemma
(requires writeable_mem64 i h)
(ensures (
let heap = get_heap h in
let heap' = S.update_heap64 i v heap in
let h' = store_mem64 i v h in
heap' == I.down_mem (_ih h')
))
let valid_state_store_mem64_aux i v h =
let heap = get_heap h in
let heap' = S.update_heap64 i v heap in
let h1 = store_mem TUInt64 i v h in
store_buffer_aux_down64_mem i v h;
store_buffer_aux_down64_mem2 i v h;
let mem1 = heap' in
let mem2 = I.down_mem (_ih h1) in
let aux () : Lemma (forall j. mem1.[j] == mem2.[j]) =
Vale.Arch.MachineHeap.same_mem_get_heap_val64 i mem1 mem2;
Vale.Arch.MachineHeap.correct_update_get64 i v heap;
Vale.Arch.MachineHeap.frame_update_heap64 i v heap
in let aux2 () : Lemma (Set.equal (Map.domain mem1) (Map.domain mem2)) =
bytes_valid64 i h;
Vale.Arch.MachineHeap.same_domain_update64 i v heap
in aux(); aux2();
Map.lemma_equal_intro mem1 mem2
let low_lemma_load_mem64_full b i vfh t hid =
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
#push-options "--z3rlimit 20"
#restart-solver
let low_lemma_store_mem64 b i v h =
lemma_writeable_mem64 b i h;
lemma_store_mem64 b i v h;
valid_state_store_mem64_aux (buffer_addr b h + scale8 i) v h;
let heap = get_heap h in
let heap' = S.update_heap64 (buffer_addr b h + scale8 i) v heap in
low_lemma_store_mem64_aux b heap i v h;
Vale.Arch.MachineHeap.frame_update_heap64 (buffer_addr b h + scale8 i) v heap;
in_bounds64 h b i;
I.addrs_set_lemma_all ();
I.update_buffer_up_mem (_ih h) b heap heap'
#pop-options
#set-options "--z3rlimit 100"
#restart-solver
let lemma_is_full_update
(vfh:vale_full_heap) (h hk hk':vale_heap) (k:heaplet_id) (mh mh' mhk mhk':machine_heap) (mt mt':memtaint)
(t:base_typ) (b:buffer t) (ptr:int) (v_size:nat)
(index:nat) (v:base_typ_as_vale_type t) (tn:taint)
: Lemma
(requires
vfh.vf_layout.vl_inner.vl_heaplets_initialized /\
mem_inv vfh /\
buffer_readable hk b /\
buffer_writeable b /\
index < Seq.length (buffer_as_seq hk b) /\
mt == vfh.vf_layout.vl_taint /\
h == vfh.vf_heap /\
hk == Map16.sel vfh.vf_heaplets k /\
mh == h.mh /\
mhk == hk.mh /\
ptr == buffer_addr b hk + scale_by v_size index /\
mt' == S.update_n ptr v_size (heap_taint (coerce vfh)) tn /\
hk' == buffer_write b index v hk /\
valid_layout_buffer b vfh.vf_layout hk true /\
valid_taint_buf b hk mt tn /\
is_machine_heap_update mh mh' /\ upd_heap h mh' == buffer_write b index v h /\
is_machine_heap_update mhk mhk' /\ upd_heap hk mhk' == buffer_write b index v hk /\
(forall j.{:pattern mh.[j] \/ mh'.[j]} j < ptr \/ j >= ptr + v_size ==> mh.[j] == mh'.[j]) /\
(forall j.{:pattern mhk.[j] \/ mhk'.[j]} j < ptr \/ j >= ptr + v_size ==> mhk.[j] == mhk'.[j]) /\
0 <= scale_by v_size index /\ scale_by v_size index + v_size <= DV.length (get_downview b.bsrc) /\
(forall i.{:pattern mh'.[i] \/ mhk'.[i]} i >= ptr /\ i < ptr + v_size ==> mh'.[i] == mhk'.[i]) /\
True
)
(ensures is_full_update vfh hk' k mh' mt')
=
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
let vfh' = coerce (heap_upd (coerce vfh) mh' mt') in
let dom_upd = Set.intersect (vfh.vf_layout.vl_inner.vl_heaplet_sets k) (Map.domain mhk) in
let mhk'' = Map.concat mhk (Map.restrict dom_upd mh') in
assert (Map.equal mhk'' mhk');
let unchanged (j:heaplet_id) : Lemma
(requires j =!= k)
(ensures Map16.sel vfh'.vf_heaplets j == Map16.sel vfh.vf_heaplets j)
[SMTPat (Map16.sel vfh'.vf_heaplets j)]
=
assert (Map.equal (Map16.sel vfh'.vf_heaplets j).mh (Map16.sel vfh.vf_heaplets j).mh);
I.down_up_identity (Map16.sel vfh.vf_heaplets j).ih;
()
in
assert (Map16.equal vfh'.vf_heaplets (Map16.upd vfh.vf_heaplets k hk'));
assert (Map.equal mt' mt);
Vale.Interop.Heap_s.list_disjoint_or_eq_reveal ();
()
let low_lemma_store_mem64_full b i v vfh t hid =
let (h, mt, hk) = (vfh.vf_heap, vfh.vf_layout.vl_taint, Map16.get vfh.vf_heaplets hid) in
let ptr = buffer_addr b hk + scale8 i in
let mh' = S.update_heap64 ptr v (heap_get (coerce vfh)) in
let mt' = S.update_n ptr 8 (heap_taint (coerce vfh)) t in
let hk' = buffer_write b i v hk in
let mhk' = S.update_heap64 ptr v (get_heap hk) in
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
low_lemma_store_mem64 b i v h;
low_lemma_store_mem64 b i v (Map16.get vfh.vf_heaplets hid);
Vale.Arch.MachineHeap.frame_update_heap64 ptr v h.mh;
Vale.Arch.MachineHeap.frame_update_heap64 ptr v hk.mh;
in_bounds64 hk b i;
Vale.Arch.MachineHeap.same_mem_get_heap_val64 ptr mh' mhk';
lemma_is_full_update vfh h hk hk' hid h.mh mh' hk.mh mhk' mt mt' TUInt64 b ptr 8 i v t;
()
val low_lemma_valid_mem128 (b:buffer128) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b
)
(ensures
S.valid_addr128 (buffer_addr b h + scale16 i) (get_heap h)
)
let low_lemma_valid_mem128 b i h =
lemma_valid_mem128 b i h;
bytes_valid128 (buffer_addr b h + scale16 i) h
val equiv_load_mem128_aux: (ptr:int) -> (h:vale_heap) -> Lemma
(requires valid_mem128 ptr h)
(ensures load_mem128 ptr h == S.get_heap_val128 ptr (get_heap h))
let equiv_load_mem128_aux ptr h =
let t = TUInt128 in
let b = get_addr_ptr t ptr h in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
let addr = buffer_addr b h in
let contents = DV.as_seq (_ih h).IB.hs (get_downview b.bsrc) in
let heap = get_heap h in
S.get_heap_val128_reveal ();
index128_get_heap_val128 h b heap i;
lemma_load_mem128 b i h
let equiv_load_mem128 ptr h =
equiv_load_mem128_aux ptr h
val low_lemma_load_mem128 (b:buffer128) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b
)
(ensures
S.get_heap_val128 (buffer_addr b h + scale16 i) (get_heap h) == buffer_read b i h
)
let low_lemma_load_mem128 b i h =
lemma_valid_mem128 b i h;
lemma_load_mem128 b i h;
equiv_load_mem128_aux (buffer_addr b h + scale16 i) h
//let same_domain_update128 b i v h =
// low_lemma_valid_mem128 b i h;
// Vale.Arch.MachineHeap.same_domain_update128 (buffer_addr b h + scale16 i) v (get_heap h)
let low_lemma_store_mem128_aux
(b:buffer128)
(heap:S.machine_heap)
(i:nat{i < buffer_length b})
(v:quad32)
(h:vale_heap{buffer_readable h b /\ buffer_writeable b})
: Lemma
(requires IB.correct_down_p (_ih h) heap b)
(ensures (let heap' = S.update_heap128 (buffer_addr b h + scale16 i) v heap in
let h' = store_mem128 (buffer_addr b h + scale16 i) v h in
(_ih h').IB.hs == DV.upd_seq (_ih h).IB.hs (get_downview b.bsrc) (I.get_seq_heap heap' (_ih h).IB.addrs b))) =
let ptr = buffer_addr b h + scale16 i in
let heap' = S.update_heap128 ptr v heap in
let h' = store_mem128 ptr v h in
lemma_store_mem128 b i v h;
length_t_eq TUInt128 b;
bv_upd_update_heap128 b heap i v (_ih h);
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db Vale.Interop.Views.up_view128 in
assert (UV.upd (_ih h).IB.hs bv i v == (_ih h').IB.hs)
val valid_state_store_mem128_aux (i:int) (v:quad32) (h:vale_heap) : Lemma
(requires writeable_mem128 i h)
(ensures (
let heap = get_heap h in
let heap' = S.update_heap128 i v heap in
let h' = store_mem128 i v h in
heap' == I.down_mem (_ih h')
))
#restart-solver
let rec written_buffer_down128_aux1
(b:buffer128{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:quad32)
(h:vale_heap{List.memP b (_ih h).IB.ptrs})
(base:nat{base == buffer_addr b h})
(k:nat) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j.{:pattern (mem1.[j]) \/ (mem2.[j])}
base <= j /\ j < base + k * 16 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem1.[j])}
j >= base /\ j < base + scale16 i ==>
mem1.[j] == mem2.[j]))
(decreases %[i-k]) =
if k >= i then ()
else begin
let ptr = base + scale16 k in
same_mem_get_heap_val128 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 16;
written_buffer_down128_aux1 b i v h base (k+1) h1 mem1 mem2
end
#restart-solver
let rec written_buffer_down128_aux2
(b:buffer128{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:quad32)
(h:vale_heap{List.memP b (_ih h).IB.ptrs})
(base:nat{base == buffer_addr b h})
(n:nat{n == buffer_length b})
(k:nat{k > i}) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
base + scale16 (i+1) <= j /\ j < base + k * 16 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
j >= base + scale16 (i+1) /\ j < base + scale16 n ==>
mem1.[j] == mem2.[j]))
(decreases %[n-k]) =
if k >= n then ()
else begin
let ptr = base + scale16 k in
same_mem_get_heap_val128 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 16;
written_buffer_down128_aux2 b i v h base n (k+1) h1 mem1 mem2
end | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Memory.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.BufferViewStore.fsti.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Memory_Sems.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.BufferViewStore",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_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
}
] | {
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
b: Vale.X64.Memory.buffer128 ->
i: Prims.nat{i < Vale.X64.Memory.buffer_length b} ->
v: Vale.X64.Memory.quad32 ->
h: Vale.Arch.HeapImpl.vale_heap
-> FStar.Pervasives.Lemma
(requires
FStar.List.Tot.Base.memP b (InteropHeap?.ptrs (Vale.Arch.HeapImpl._ih h)) /\
Vale.X64.Memory.buffer_writeable b)
(ensures
(let mem1 = Vale.Interop.down_mem (Vale.Arch.HeapImpl._ih h) in
let h1 = Vale.X64.Memory.buffer_write b i v h in
let mem2 = Vale.Interop.down_mem (Vale.Arch.HeapImpl._ih h1) in
let base = Vale.X64.Memory.buffer_addr b h in
let n = Vale.X64.Memory.buffer_length b in
forall (j: Prims.int). {:pattern mem1.[ j ]\/mem2.[ j ]}
base <= j /\ j < base + Vale.X64.Memory.scale16 i \/
base + Vale.X64.Memory.scale16 (i + 1) <= j /\ j < base + Vale.X64.Memory.scale16 n ==>
mem1.[ j ] == mem2.[ j ])) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.X64.Memory.buffer128",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Vale.X64.Memory.buffer_length",
"Vale.X64.Memory.vuint128",
"Vale.X64.Memory.quad32",
"Vale.Arch.HeapImpl.vale_heap",
"Vale.X64.Memory_Sems.written_buffer_down128_aux2",
"Prims.op_Addition",
"Prims.unit",
"Vale.X64.Memory_Sems.written_buffer_down128_aux1",
"Prims.int",
"Vale.X64.Memory.buffer_addr",
"Vale.Arch.MachineHeap_s.machine_heap",
"Vale.Interop.Heap_s.correct_down",
"Vale.Arch.HeapImpl._ih",
"Vale.Interop.down_mem",
"Vale.X64.Memory.buffer_write",
"Prims.l_and",
"FStar.List.Tot.Base.memP",
"Vale.Interop.Types.b8",
"Vale.Interop.Heap_s.__proj__InteropHeap__item__ptrs",
"Vale.X64.Memory.buffer_writeable",
"Prims.squash",
"Prims.l_Forall",
"Prims.l_imp",
"Prims.l_or",
"Prims.op_LessThanOrEqual",
"Vale.X64.Memory.scale16",
"Prims.eq2",
"Vale.Def.Types_s.nat8",
"Vale.X64.Memory.op_String_Access",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let written_buffer_down128 (b: buffer128) (i: nat{i < buffer_length b}) (v: quad32) (h: vale_heap)
: Lemma (requires List.memP b (_ih h).IB.ptrs /\ buffer_writeable b)
(ensures
(let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
forall j. {:pattern (mem1.[ j ])\/(mem2.[ j ])}
(base <= j /\ j < base + scale16 i) \/
(base + scale16 (i + 1) <= j /\ j < base + scale16 n) ==>
mem1.[ j ] == mem2.[ j ])) =
| let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
written_buffer_down128_aux1 b i v h base 0 h1 mem1 mem2;
written_buffer_down128_aux2 b i v h base n (i + 1) h1 mem1 mem2 | false |
Vale.X64.Memory_Sems.fst | Vale.X64.Memory_Sems.written_buffer_down128_aux1 | val written_buffer_down128_aux1
(b: buffer128{buffer_writeable b})
(i: nat{i < buffer_length b})
(v: quad32)
(h: vale_heap{List.memP b (_ih h).IB.ptrs})
(base: nat{base == buffer_addr b h})
(k: nat)
(h1: vale_heap{h1 == buffer_write b i v h})
(mem1: S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:
S.machine_heap
{ IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[ j ])\/(mem2.[ j ])}
base <= j /\ j < base + k * 16 ==> mem1.[ j ] == mem2.[ j ]) })
: Lemma
(ensures
(forall j. {:pattern (mem1.[ j ])\/(mem1.[ j ])}
j >= base /\ j < base + scale16 i ==> mem1.[ j ] == mem2.[ j ])) (decreases %[i - k]) | val written_buffer_down128_aux1
(b: buffer128{buffer_writeable b})
(i: nat{i < buffer_length b})
(v: quad32)
(h: vale_heap{List.memP b (_ih h).IB.ptrs})
(base: nat{base == buffer_addr b h})
(k: nat)
(h1: vale_heap{h1 == buffer_write b i v h})
(mem1: S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:
S.machine_heap
{ IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[ j ])\/(mem2.[ j ])}
base <= j /\ j < base + k * 16 ==> mem1.[ j ] == mem2.[ j ]) })
: Lemma
(ensures
(forall j. {:pattern (mem1.[ j ])\/(mem1.[ j ])}
j >= base /\ j < base + scale16 i ==> mem1.[ j ] == mem2.[ j ])) (decreases %[i - k]) | let rec written_buffer_down128_aux1
(b:buffer128{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:quad32)
(h:vale_heap{List.memP b (_ih h).IB.ptrs})
(base:nat{base == buffer_addr b h})
(k:nat) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j.{:pattern (mem1.[j]) \/ (mem2.[j])}
base <= j /\ j < base + k * 16 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem1.[j])}
j >= base /\ j < base + scale16 i ==>
mem1.[j] == mem2.[j]))
(decreases %[i-k]) =
if k >= i then ()
else begin
let ptr = base + scale16 k in
same_mem_get_heap_val128 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 16;
written_buffer_down128_aux1 b i v h base (k+1) h1 mem1 mem2
end | {
"file_name": "vale/code/arch/x64/Vale.X64.Memory_Sems.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 7,
"end_line": 827,
"start_col": 0,
"start_line": 804
} | module Vale.X64.Memory_Sems
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.Def.Words_s
module I = Vale.Interop
module S = Vale.X64.Machine_Semantics_s
module MB = LowStar.Monotonic.Buffer
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
open Vale.Lib.BufferViewHelpers
open Vale.Arch.HeapImpl
open Vale.Arch.Heap
friend Vale.X64.Memory
module IB = Vale.Interop.Base
let same_domain h m = Set.equal (IB.addrs_set (_ih h)) (Map.domain m)
let lemma_same_domains h m1 m2 = ()
let get_heap h = I.down_mem (_ih h)
let upd_heap h m = mi_heap_upd h m
//let lemma_upd_get_heap h = I.down_up_identity (_ih h)
let lemma_get_upd_heap h m = I.up_down_identity (_ih h) m
let lemma_heap_impl = ()
let lemma_heap_get_heap h = ()
let lemma_heap_taint h = ()
//let lemma_heap_upd_heap h mh mt = ()
[@"opaque_to_smt"]
let rec set_of_range (a:int) (n:nat) : Pure (Set.set int)
(requires True)
(ensures fun s -> (forall (i:int).{:pattern Set.mem i s} Set.mem i s <==> a <= i /\ i < a + n))
=
if n = 0 then Set.empty else Set.union (set_of_range a (n - 1)) (Set.singleton (a + n - 1))
let buffer_info_has_addr (bi:buffer_info) (a:int) =
let b = bi.bi_buffer in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
addr <= a /\ a < addr + len
let buffer_info_has_addr_opt (bi:option buffer_info) (a:int) =
match bi with
| None -> False
| Some bi -> buffer_info_has_addr bi a
#set-options "--z3rlimit 100"
let rec make_owns_rec (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
if n = 0 then ((fun _ -> None), (fun _ -> Set.empty)) else
let (m0, s0) = make_owns_rec h bs (n - 1) in
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let s i = if i = hi then Set.union (s0 i) s_b else s0 i in
let m a = if addr <= a && a < addr + len then Some (n - 1) else m0 a in
(m, s)
[@"opaque_to_smt"]
let make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat{n <= Seq.length bs}) :
GTot ((int -> option (n:nat{n < Seq.length bs})) & (heaplet_id -> Set.set int))
=
make_owns_rec h bs n
let rec lemma_make_owns (h:vale_heap) (bs:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n <= Seq.length bs /\
(forall (i:nat).{:pattern Seq.index bs i} i < Seq.length bs ==> buffer_readable h (Seq.index bs i).bi_buffer) /\
(forall (i1 i2:nat).{:pattern (Seq.index bs i1); (Seq.index bs i2)}
i1 < Seq.length bs /\ i2 < Seq.length bs ==> buffer_info_disjoint (Seq.index bs i1) (Seq.index bs i2))
)
(ensures (
let (m, s) = make_owns h bs n in
(forall (i:heaplet_id) (a:int).{:pattern Set.mem a (s i)}
(Set.mem a (s i) <==> Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (m a) == Some i) /\
(Set.mem a (s i) ==> buffer_info_has_addr_opt (Option.mapTot (fun n -> Seq.index bs n) (m a)) a) /\
(Set.mem a (s i) ==> Set.mem a (Map.domain h.mh))
) /\
(forall (k:nat) (a:int).{:pattern Set.mem a (s (Seq.index bs k).bi_heaplet)}
k < n /\ buffer_info_has_addr (Seq.index bs k) a ==> Set.mem a (s (Seq.index bs k).bi_heaplet))
))
=
reveal_opaque (`%make_owns) make_owns;
if n = 0 then () else
let _ = make_owns h bs (n - 1) in
let (m, s) = make_owns h bs n in
lemma_make_owns h bs (n - 1);
let bi = Seq.index bs (n - 1) in
let b = bi.bi_buffer in
let hi = bi.bi_heaplet in
let addr = Vale.Interop.Heap_s.global_addrs_map b in
let len = DV.length (get_downview b.bsrc) in
let s_b = set_of_range addr len in
let lem1 (a:int) : Lemma
(requires Set.mem a s_b)
(ensures Set.mem a (Map.domain h.mh))
[SMTPat (Set.mem a (Map.domain h.mh))]
=
I.addrs_set_mem h.ih b a
in
let lem2 (i:heaplet_id) (a:int) : Lemma
(requires i =!= hi /\ Set.mem a (Set.intersect s_b (s i)))
(ensures False)
[SMTPat (Set.mem a (s i))]
=
reveal_opaque (`%addr_map_pred) addr_map_pred
in
()
#push-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_loc_mutable_buffers_rec (l:list buffer_info) (s:Seq.seq buffer_info) (n:nat) : Lemma
(requires
n + List.length l == Seq.length s /\
list_to_seq_post l s n
)
(ensures (
let modloc = loc_mutable_buffers l in
forall (i:nat).{:pattern Seq.index s i} n <= i /\ i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes modloc (loc_buffer bi.bi_buffer))
))
(decreases l)
=
match l with
| [] -> ()
| h::t -> lemma_loc_mutable_buffers_rec t s (n + 1)
#pop-options
let lemma_loc_mutable_buffers (l:list buffer_info) : Lemma
(ensures (
let s = list_to_seq l in
forall (i:nat).{:pattern Seq.index s i} i < Seq.length s ==> (
let bi = Seq.index s i in
bi.bi_mutable == Mutable ==> loc_includes (loc_mutable_buffers l) (loc_buffer bi.bi_buffer))
))
=
lemma_list_to_seq l;
lemma_loc_mutable_buffers_rec l (list_to_seq l) 0
let create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let modloc = loc_mutable_buffers buffers in
let layout1 = h1.vf_layout in
let layin1 = layout1.vl_inner in
let (hmap, hsets) = make_owns h1.vf_heap bs (Seq.length bs) in
let hmap a = Option.mapTot (fun n -> (Seq.index bs n).bi_heaplet) (hmap a) in
let l = {
vl_heaplets_initialized = true;
vl_heaplet_map = hmap;
vl_heaplet_sets = hsets;
vl_old_heap = h1.vf_heap;
vl_buffers = bs;
vl_mod_loc = modloc;
} in
let layout2 = {layout1 with vl_inner = l} in
let h2 = {
vf_layout = layout2;
vf_heap = h1.vf_heap;
vf_heaplets = h1.vf_heaplets;
} in
h2
let lemma_create_heaplets buffers h1 =
let bs = list_to_seq buffers in
let h2 = create_heaplets buffers h1 in
assert (h2.vf_layout.vl_inner.vl_buffers == bs); // REVIEW: why is this necessary, even with extra ifuel?
lemma_make_owns h1.vf_heap bs (Seq.length bs);
lemma_loc_mutable_buffers buffers;
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
let destroy_heaplets h1 =
h1
let lemma_destroy_heaplets h1 =
()
val heap_shift (m1 m2:S.machine_heap) (base:int) (n:nat) : Lemma
(requires (forall i. 0 <= i /\ i < n ==> m1.[base + i] == m2.[base + i]))
(ensures (forall i. {:pattern (m1.[i])} base <= i /\ i < base + n ==> m1.[i] == m2.[i]))
#push-options "--smtencoding.l_arith_repr boxwrap"
let heap_shift m1 m2 base n =
assert (forall i. base <= i /\ i < base + n ==>
m1.[base + (i - base)] == m2.[base + (i - base)])
#pop-options
val same_mem_eq_slices64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 8 + 8 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 8) (k * 8 + 8)))
let same_mem_eq_slices64 b i v k h1 h2 mem1 mem2 =
let t = TUInt64 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up64 (b:buffer64) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 8}) : Lemma
(scale8 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint64_view in
UV.length_eq vb
val same_mem_get_heap_val64 (b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1))})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale8 k in
forall (x:int).{:pattern (mem1.[x])} ptr <= x /\ x < ptr + 8 ==> mem1.[x] == mem2.[x]))
let same_mem_get_heap_val64 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale8 k in
let addr = buffer_addr b h1 in
let aux (x:int{ptr <= x /\ x < ptr + 8}) : Lemma (mem1.[x] == mem2.[x]) =
let i = x - ptr in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint64_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices64 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8) (k * 8 + 8)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8) (k * 8 + 8)) in
assert (Seq.index s1 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i));
length_up64 b h1 k i;
assert (mem1.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 8 + i)));
assert (Seq.index s2 i == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i));
length_up64 b h2 k i;
assert (mem2.[addr+(scale8 k + i)] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 8 + i)))
in
Classical.forall_intro aux;
assert (forall i. addr + (scale8 k + i) == ptr + i)
let rec written_buffer_down64_aux1
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(k:nat) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j.{:pattern (mem1.[j]) \/ (mem2.[j])}
base <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem1.[j])}
j >= base /\ j < base + scale8 i ==>
mem1.[j] == mem2.[j]))
(decreases %[i-k]) =
if k >= i then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux1 b i v h base (k+1) h1 mem1 mem2
end
let rec written_buffer_down64_aux2
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
(base:nat{base == buffer_addr b h})
(n:nat{n == buffer_length b})
(k:nat{k > i}) (h1:vale_heap{h1 == buffer_write b i v h})
(mem1:S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:S.machine_heap{IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
base + scale8 (i+1) <= j /\ j < base + k * 8 ==>
mem1.[j] == mem2.[j])})
: Lemma
(ensures (forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
j >= base + scale8 (i+1) /\ j < base + scale8 n ==>
mem1.[j] == mem2.[j]))
(decreases %[n-k]) =
if k >= n then ()
else begin
let ptr = base + scale8 k in
same_mem_get_heap_val64 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 8;
written_buffer_down64_aux2 b i v h base n (k+1) h1 mem1 mem2
end
let written_buffer_down64 (b:buffer64{buffer_writeable b}) (i:nat{i < buffer_length b}) (v:nat64) (h:vale_heap)
: Lemma
(requires List.memP b (IB.ptrs_of_mem (_ih h)))
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
forall j. {:pattern (mem1.[j]) \/ (mem2.[j])}
(base <= j /\ j < base + scale8 i) \/
(base + scale8 (i+1) <= j /\ j < base + scale8 n) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
written_buffer_down64_aux1 b i v h base 0 h1 mem1 mem2;
written_buffer_down64_aux2 b i v h base n (i+1) h1 mem1 mem2
let unwritten_buffer_down (t:base_typ) (b:buffer t{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:base_typ_as_vale_type t)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall (a:b8{List.memP a (IB.ptrs_of_mem (_ih h)) /\ a =!= b}) j. {:pattern mem1.[j]; List.memP a (IB.ptrs_of_mem (_ih h)) \/ mem2.[j]; List.memP a (IB.ptrs_of_mem (_ih h))}
let base = (IB.addrs_of_mem (_ih h)) a in
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==> mem1.[j] == mem2.[j]))
= let aux (a:b8{a =!= b /\ List.memP a (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let base = (IB.addrs_of_mem (_ih h)) a in
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
forall j.
j >= base /\ j < base + DV.length (get_downview a.bsrc) ==>
mem1.[j] == mem2.[j]))
= let db = get_downview a.bsrc in
if DV.length db = 0 then ()
else
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = (IB.addrs_of_mem (_ih h)) a in
let s0 = DV.as_seq (IB.hs_of_mem (_ih h)) db in
let s1 = DV.as_seq (IB.hs_of_mem (_ih h1)) db in
opaque_assert (`%IB.list_disjoint_or_eq) IB.list_disjoint_or_eq IB.list_disjoint_or_eq_def (MB.disjoint a.bsrc b.bsrc);
lemma_dv_equal (IB.down_view a.src) a.bsrc (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1));
assert (Seq.equal s0 s1);
assert (forall (j:int).{:pattern (mem1.[j])}
base <= j /\ j < base + Seq.length s0 ==> v_to_typ TUInt8 (Seq.index s0 (j - base)) == mem1.[j]);
heap_shift mem1 mem2 base (DV.length db)
in
Classical.forall_intro aux
let store_buffer_down64_mem
(b:buffer64{buffer_writeable b})
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h))})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
forall (j:int). {:pattern mem1.[j] \/ mem2.[j]}
j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j]))
= let mem1 = I.down_mem (_ih h) in
let h1 = buffer_write b i v h in
let mem2 = I.down_mem (_ih h1) in
let base = buffer_addr b h in
let n = buffer_length b in
let aux (j:int)
: Lemma
(j < base + scale8 i \/ j >= base + scale8 (i+1) ==>
mem1.[j] == mem2.[j])
=
I.addrs_set_lemma_all ();
if j >= base && j < base + DV.length (get_downview b.bsrc) then begin
written_buffer_down64 b i v h;
length_t_eq (TUInt64) b
end
else if not (I.valid_addr (_ih h) j)
then I.same_unspecified_down (IB.hs_of_mem (_ih h)) (IB.hs_of_mem (_ih h1)) (IB.ptrs_of_mem (_ih h))
else unwritten_buffer_down TUInt64 b i v h
in
Classical.forall_intro aux
let store_buffer_aux_down64_mem (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let mem1 = I.down_mem (_ih h) in
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
forall j. {:pattern mem1.[j] \/ mem2.[j]}
j < ptr \/ j >= ptr + 8 ==>
mem1.[j] == mem2.[j]))
= let t = TUInt64 in
let h1 = store_mem t ptr v h in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
store_buffer_write t ptr v h;
assert (buffer_addr b h + scale8 i == ptr);
assert (buffer_addr b h + scale8 (i+1) == ptr + 8);
store_buffer_down64_mem b i v h
let store_buffer_aux_down64_mem2 (ptr:int) (v:nat64) (h:vale_heap{writeable_mem64 ptr h})
: Lemma
(ensures (
let h1 = store_mem (TUInt64) ptr v h in
let mem2 = I.down_mem (_ih h1) in
S.get_heap_val64 ptr mem2 == v))
= let t = TUInt64 in
let b = Some?.v (find_writeable_buffer t ptr h) in
length_t_eq t b;
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
let h1 = store_mem t ptr v h in
let mem2 = I.down_mem (_ih h1) in
store_buffer_write t ptr v h;
assert (Seq.index (buffer_as_seq h1 b) i == v);
index64_get_heap_val64 h1 b mem2 i
let in_bounds64 (h:vale_heap) (b:buffer64) (i:nat{i < buffer_length b})
: Lemma (scale8 i + 8 <= DV.length (get_downview b.bsrc))
=
length_t_eq TUInt64 b
let bytes_valid64 ptr h =
reveal_opaque (`%S.valid_addr64) S.valid_addr64;
let t = TUInt64 in
let b = get_addr_ptr t ptr h in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
in_bounds64 h b i;
I.addrs_set_mem (_ih h) b ptr;
I.addrs_set_mem (_ih h) b (ptr+1);
I.addrs_set_mem (_ih h) b (ptr+2);
I.addrs_set_mem (_ih h) b (ptr+3);
I.addrs_set_mem (_ih h) b (ptr+4);
I.addrs_set_mem (_ih h) b (ptr+5);
I.addrs_set_mem (_ih h) b (ptr+6);
I.addrs_set_mem (_ih h) b (ptr+7)
val same_mem_get_heap_val128 (b:buffer128)
(i:nat{i < buffer_length b})
(v:quad32)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1)) /\ buffer_writeable b})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (let ptr = buffer_addr b h1 + scale16 k in
forall i.{:pattern mem1.[i]} i >= ptr /\ i < ptr+16 ==> mem1.[i] == mem2.[i]))
val same_mem_eq_slices128 (b:buffer128)
(i:nat{i < buffer_length b})
(v:quad32)
(k:nat{k < buffer_length b})
(h1:vale_heap{List.memP b (IB.ptrs_of_mem (_ih h1)) /\ buffer_writeable b})
(h2:vale_heap{h2 == buffer_write b i v h1})
(mem1:S.machine_heap{IB.correct_down_p (_ih h1) mem1 b})
(mem2:S.machine_heap{IB.correct_down_p (_ih h2) mem2 b}) : Lemma
(requires (Seq.index (buffer_as_seq h1 b) k == Seq.index (buffer_as_seq h2 b) k))
(ensures (
k * 16 + 16 <= DV.length (get_downview b.bsrc) /\
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) (get_downview b.bsrc)) (k * 16) (k * 16 + 16) ==
Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) (get_downview b.bsrc)) (k * 16) (k * 16 + 16)))
let same_mem_eq_slices128 b i v k h1 h2 mem1 mem2 =
let t = TUInt128 in
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db (uint_view t) in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.put_sel (IB.hs_of_mem (_ih h2)) ub k;
UV.length_eq ub
let length_up128 (b:buffer128) (h:vale_heap) (k:nat{k < buffer_length b}) (i:nat{i < 16}) : Lemma
(scale16 k + i <= DV.length (get_downview b.bsrc)) =
let vb = UV.mk_buffer (get_downview b.bsrc) uint128_view in
UV.length_eq vb
let same_mem_get_heap_val128 b j v k h1 h2 mem1 mem2 =
let ptr = buffer_addr b h1 + scale16 k in
let addr = buffer_addr b h1 in
let aux (i:nat{ptr <= i /\ i < ptr+16}) : Lemma (mem1.[i] == mem2.[i]) =
let db = get_downview b.bsrc in
let ub = UV.mk_buffer db uint128_view in
UV.as_seq_sel (IB.hs_of_mem (_ih h1)) ub k;
UV.as_seq_sel (IB.hs_of_mem (_ih h2)) ub k;
same_mem_eq_slices128 b j v k h1 h2 mem1 mem2;
let s1 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16) (k * 16 + 16)) in
let s2 = (Seq.slice (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16) (k * 16 + 16)) in
assert (Seq.index s1 (i - ptr) == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16 + (i-ptr)));
length_up128 b h1 k (i-ptr);
assert (mem1.[i] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h1)) db) (k * 16 + (i-ptr))));
assert (Seq.index s2 (i-ptr) == Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16 + (i-ptr)));
length_up128 b h2 k (i-ptr);
assert (mem2.[addr+(scale16 k + (i-ptr))] == UInt8.v (Seq.index (DV.as_seq (IB.hs_of_mem (_ih h2)) db) (k * 16 + (i-ptr))));
assert (forall i. addr + (scale16 k + (i-ptr)) == i)
in
Classical.forall_intro aux
let in_bounds128 (h:vale_heap) (b:buffer128) (i:nat{i < buffer_length b}) : Lemma
(scale16 i + 16 <= DV.length (get_downview b.bsrc))
=
length_t_eq TUInt128 b
#push-options "--z3rlimit 20"
#restart-solver
let bytes_valid128 ptr h =
reveal_opaque (`%S.valid_addr128) S.valid_addr128;
IB.list_disjoint_or_eq_reveal ();
let t = TUInt128 in
let b = get_addr_ptr t ptr h in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
in_bounds128 h b i;
I.addrs_set_mem (_ih h) b ptr;
I.addrs_set_mem (_ih h) b (ptr+1);
I.addrs_set_mem (_ih h) b (ptr+2);
I.addrs_set_mem (_ih h) b (ptr+3);
I.addrs_set_mem (_ih h) b (ptr+4);
I.addrs_set_mem (_ih h) b (ptr+5);
I.addrs_set_mem (_ih h) b (ptr+6);
I.addrs_set_mem (_ih h) b (ptr+7);
I.addrs_set_mem (_ih h) b (ptr+8);
I.addrs_set_mem (_ih h) b (ptr+9);
I.addrs_set_mem (_ih h) b (ptr+10);
I.addrs_set_mem (_ih h) b (ptr+11);
I.addrs_set_mem (_ih h) b (ptr+12);
I.addrs_set_mem (_ih h) b (ptr+13);
I.addrs_set_mem (_ih h) b (ptr+14);
I.addrs_set_mem (_ih h) b (ptr+15)
#pop-options
let equiv_load_mem64 ptr h =
let t = TUInt64 in
let b = get_addr_ptr t ptr h in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
let addr = buffer_addr b h in
let contents = DV.as_seq (_ih h).IB.hs (get_downview b.bsrc) in
let heap = get_heap h in
index64_get_heap_val64 h b heap i;
lemma_load_mem64 b i h
//let low_lemma_valid_mem64 b i h =
// lemma_valid_mem64 b i h;
// bytes_valid64 (buffer_addr b h + scale8 i) h
//let low_lemma_load_mem64 b i h =
// lemma_valid_mem64 b i h;
// lemma_load_mem64 b i h;
// equiv_load_mem64 (buffer_addr b h + scale8 i) h
//let same_domain_update64 b i v h =
// low_lemma_valid_mem64 b i h;
// Vale.Arch.MachineHeap.same_domain_update64 (buffer_addr b h + scale8 i) v (get_heap h)
open Vale.X64.BufferViewStore
let low_lemma_store_mem64_aux
(b:buffer64)
(heap:S.machine_heap)
(i:nat{i < buffer_length b})
(v:nat64)
(h:vale_heap{buffer_readable h b /\ buffer_writeable b})
: Lemma
(requires IB.correct_down_p (_ih h) heap b)
(ensures (let heap' = S.update_heap64 (buffer_addr b h + scale8 i) v heap in
let h' = store_mem64 (buffer_addr b h + scale8 i) v h in
(_ih h').IB.hs == DV.upd_seq (_ih h).IB.hs (get_downview b.bsrc) (I.get_seq_heap heap' (_ih h).IB.addrs b))) =
let ptr = buffer_addr b h + scale8 i in
let heap' = S.update_heap64 ptr v heap in
let h' = store_mem64 ptr v h in
lemma_store_mem64 b i v h;
length_t_eq TUInt64 b;
bv_upd_update_heap64 b heap i v (_ih h);
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db Vale.Interop.Views.up_view64 in
assert (UV.upd (_ih h).IB.hs bv i (UInt64.uint_to_t v) == (_ih h').IB.hs)
val valid_state_store_mem64_aux: (i:nat) -> (v:nat64) -> (h:vale_heap) -> Lemma
(requires writeable_mem64 i h)
(ensures (
let heap = get_heap h in
let heap' = S.update_heap64 i v heap in
let h' = store_mem64 i v h in
heap' == I.down_mem (_ih h')
))
let valid_state_store_mem64_aux i v h =
let heap = get_heap h in
let heap' = S.update_heap64 i v heap in
let h1 = store_mem TUInt64 i v h in
store_buffer_aux_down64_mem i v h;
store_buffer_aux_down64_mem2 i v h;
let mem1 = heap' in
let mem2 = I.down_mem (_ih h1) in
let aux () : Lemma (forall j. mem1.[j] == mem2.[j]) =
Vale.Arch.MachineHeap.same_mem_get_heap_val64 i mem1 mem2;
Vale.Arch.MachineHeap.correct_update_get64 i v heap;
Vale.Arch.MachineHeap.frame_update_heap64 i v heap
in let aux2 () : Lemma (Set.equal (Map.domain mem1) (Map.domain mem2)) =
bytes_valid64 i h;
Vale.Arch.MachineHeap.same_domain_update64 i v heap
in aux(); aux2();
Map.lemma_equal_intro mem1 mem2
let low_lemma_load_mem64_full b i vfh t hid =
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
()
#push-options "--z3rlimit 20"
#restart-solver
let low_lemma_store_mem64 b i v h =
lemma_writeable_mem64 b i h;
lemma_store_mem64 b i v h;
valid_state_store_mem64_aux (buffer_addr b h + scale8 i) v h;
let heap = get_heap h in
let heap' = S.update_heap64 (buffer_addr b h + scale8 i) v heap in
low_lemma_store_mem64_aux b heap i v h;
Vale.Arch.MachineHeap.frame_update_heap64 (buffer_addr b h + scale8 i) v heap;
in_bounds64 h b i;
I.addrs_set_lemma_all ();
I.update_buffer_up_mem (_ih h) b heap heap'
#pop-options
#set-options "--z3rlimit 100"
#restart-solver
let lemma_is_full_update
(vfh:vale_full_heap) (h hk hk':vale_heap) (k:heaplet_id) (mh mh' mhk mhk':machine_heap) (mt mt':memtaint)
(t:base_typ) (b:buffer t) (ptr:int) (v_size:nat)
(index:nat) (v:base_typ_as_vale_type t) (tn:taint)
: Lemma
(requires
vfh.vf_layout.vl_inner.vl_heaplets_initialized /\
mem_inv vfh /\
buffer_readable hk b /\
buffer_writeable b /\
index < Seq.length (buffer_as_seq hk b) /\
mt == vfh.vf_layout.vl_taint /\
h == vfh.vf_heap /\
hk == Map16.sel vfh.vf_heaplets k /\
mh == h.mh /\
mhk == hk.mh /\
ptr == buffer_addr b hk + scale_by v_size index /\
mt' == S.update_n ptr v_size (heap_taint (coerce vfh)) tn /\
hk' == buffer_write b index v hk /\
valid_layout_buffer b vfh.vf_layout hk true /\
valid_taint_buf b hk mt tn /\
is_machine_heap_update mh mh' /\ upd_heap h mh' == buffer_write b index v h /\
is_machine_heap_update mhk mhk' /\ upd_heap hk mhk' == buffer_write b index v hk /\
(forall j.{:pattern mh.[j] \/ mh'.[j]} j < ptr \/ j >= ptr + v_size ==> mh.[j] == mh'.[j]) /\
(forall j.{:pattern mhk.[j] \/ mhk'.[j]} j < ptr \/ j >= ptr + v_size ==> mhk.[j] == mhk'.[j]) /\
0 <= scale_by v_size index /\ scale_by v_size index + v_size <= DV.length (get_downview b.bsrc) /\
(forall i.{:pattern mh'.[i] \/ mhk'.[i]} i >= ptr /\ i < ptr + v_size ==> mh'.[i] == mhk'.[i]) /\
True
)
(ensures is_full_update vfh hk' k mh' mt')
=
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
let vfh' = coerce (heap_upd (coerce vfh) mh' mt') in
let dom_upd = Set.intersect (vfh.vf_layout.vl_inner.vl_heaplet_sets k) (Map.domain mhk) in
let mhk'' = Map.concat mhk (Map.restrict dom_upd mh') in
assert (Map.equal mhk'' mhk');
let unchanged (j:heaplet_id) : Lemma
(requires j =!= k)
(ensures Map16.sel vfh'.vf_heaplets j == Map16.sel vfh.vf_heaplets j)
[SMTPat (Map16.sel vfh'.vf_heaplets j)]
=
assert (Map.equal (Map16.sel vfh'.vf_heaplets j).mh (Map16.sel vfh.vf_heaplets j).mh);
I.down_up_identity (Map16.sel vfh.vf_heaplets j).ih;
()
in
assert (Map16.equal vfh'.vf_heaplets (Map16.upd vfh.vf_heaplets k hk'));
assert (Map.equal mt' mt);
Vale.Interop.Heap_s.list_disjoint_or_eq_reveal ();
()
let low_lemma_store_mem64_full b i v vfh t hid =
let (h, mt, hk) = (vfh.vf_heap, vfh.vf_layout.vl_taint, Map16.get vfh.vf_heaplets hid) in
let ptr = buffer_addr b hk + scale8 i in
let mh' = S.update_heap64 ptr v (heap_get (coerce vfh)) in
let mt' = S.update_n ptr 8 (heap_taint (coerce vfh)) t in
let hk' = buffer_write b i v hk in
let mhk' = S.update_heap64 ptr v (get_heap hk) in
reveal_opaque (`%valid_layout_buffer_id) valid_layout_buffer_id;
low_lemma_store_mem64 b i v h;
low_lemma_store_mem64 b i v (Map16.get vfh.vf_heaplets hid);
Vale.Arch.MachineHeap.frame_update_heap64 ptr v h.mh;
Vale.Arch.MachineHeap.frame_update_heap64 ptr v hk.mh;
in_bounds64 hk b i;
Vale.Arch.MachineHeap.same_mem_get_heap_val64 ptr mh' mhk';
lemma_is_full_update vfh h hk hk' hid h.mh mh' hk.mh mhk' mt mt' TUInt64 b ptr 8 i v t;
()
val low_lemma_valid_mem128 (b:buffer128) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b
)
(ensures
S.valid_addr128 (buffer_addr b h + scale16 i) (get_heap h)
)
let low_lemma_valid_mem128 b i h =
lemma_valid_mem128 b i h;
bytes_valid128 (buffer_addr b h + scale16 i) h
val equiv_load_mem128_aux: (ptr:int) -> (h:vale_heap) -> Lemma
(requires valid_mem128 ptr h)
(ensures load_mem128 ptr h == S.get_heap_val128 ptr (get_heap h))
let equiv_load_mem128_aux ptr h =
let t = TUInt128 in
let b = get_addr_ptr t ptr h in
let i = get_addr_in_ptr t (buffer_length b) (buffer_addr b h) ptr 0 in
let addr = buffer_addr b h in
let contents = DV.as_seq (_ih h).IB.hs (get_downview b.bsrc) in
let heap = get_heap h in
S.get_heap_val128_reveal ();
index128_get_heap_val128 h b heap i;
lemma_load_mem128 b i h
let equiv_load_mem128 ptr h =
equiv_load_mem128_aux ptr h
val low_lemma_load_mem128 (b:buffer128) (i:nat) (h:vale_heap) : Lemma
(requires
i < Seq.length (buffer_as_seq h b) /\
buffer_readable h b
)
(ensures
S.get_heap_val128 (buffer_addr b h + scale16 i) (get_heap h) == buffer_read b i h
)
let low_lemma_load_mem128 b i h =
lemma_valid_mem128 b i h;
lemma_load_mem128 b i h;
equiv_load_mem128_aux (buffer_addr b h + scale16 i) h
//let same_domain_update128 b i v h =
// low_lemma_valid_mem128 b i h;
// Vale.Arch.MachineHeap.same_domain_update128 (buffer_addr b h + scale16 i) v (get_heap h)
let low_lemma_store_mem128_aux
(b:buffer128)
(heap:S.machine_heap)
(i:nat{i < buffer_length b})
(v:quad32)
(h:vale_heap{buffer_readable h b /\ buffer_writeable b})
: Lemma
(requires IB.correct_down_p (_ih h) heap b)
(ensures (let heap' = S.update_heap128 (buffer_addr b h + scale16 i) v heap in
let h' = store_mem128 (buffer_addr b h + scale16 i) v h in
(_ih h').IB.hs == DV.upd_seq (_ih h).IB.hs (get_downview b.bsrc) (I.get_seq_heap heap' (_ih h).IB.addrs b))) =
let ptr = buffer_addr b h + scale16 i in
let heap' = S.update_heap128 ptr v heap in
let h' = store_mem128 ptr v h in
lemma_store_mem128 b i v h;
length_t_eq TUInt128 b;
bv_upd_update_heap128 b heap i v (_ih h);
let db = get_downview b.bsrc in
let bv = UV.mk_buffer db Vale.Interop.Views.up_view128 in
assert (UV.upd (_ih h).IB.hs bv i v == (_ih h').IB.hs)
val valid_state_store_mem128_aux (i:int) (v:quad32) (h:vale_heap) : Lemma
(requires writeable_mem128 i h)
(ensures (
let heap = get_heap h in
let heap' = S.update_heap128 i v heap in
let h' = store_mem128 i v h in
heap' == I.down_mem (_ih h')
)) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Memory.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.BufferViewStore.fsti.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Heap_s.fst.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.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.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.MachineHeap.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.X64.Memory_Sems.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.BufferViewStore",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Interop.Base",
"short_module": "IB"
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.BufferViewHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Lib.Map16",
"short_module": "Map16"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.MachineHeap_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_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
}
] | {
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
b: Vale.X64.Memory.buffer128{Vale.X64.Memory.buffer_writeable b} ->
i: Prims.nat{i < Vale.X64.Memory.buffer_length b} ->
v: Vale.X64.Memory.quad32 ->
h:
Vale.Arch.HeapImpl.vale_heap
{FStar.List.Tot.Base.memP b (InteropHeap?.ptrs (Vale.Arch.HeapImpl._ih h))} ->
base: Prims.nat{base == Vale.X64.Memory.buffer_addr b h} ->
k: Prims.nat ->
h1: Vale.Arch.HeapImpl.vale_heap{h1 == Vale.X64.Memory.buffer_write b i v h} ->
mem1:
Vale.Arch.MachineHeap_s.machine_heap
{Vale.Interop.Heap_s.correct_down (Vale.Arch.HeapImpl._ih h) mem1} ->
mem2:
Vale.Arch.MachineHeap_s.machine_heap
{ Vale.Interop.Heap_s.correct_down (Vale.Arch.HeapImpl._ih h1) mem2 /\
(forall (j: Prims.int). {:pattern mem1.[ j ]\/mem2.[ j ]}
base <= j /\ j < base + k * 16 ==> mem1.[ j ] == mem2.[ j ]) }
-> FStar.Pervasives.Lemma
(ensures
forall (j: Prims.int). {:pattern mem1.[ j ]\/mem1.[ j ]}
j >= base /\ j < base + Vale.X64.Memory.scale16 i ==> mem1.[ j ] == mem2.[ j ])
(decreases i - k) | FStar.Pervasives.Lemma | [
"lemma",
""
] | [] | [
"Vale.X64.Memory.buffer128",
"Vale.X64.Memory.buffer_writeable",
"Vale.X64.Memory.vuint128",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Vale.X64.Memory.buffer_length",
"Vale.X64.Memory.quad32",
"Vale.Arch.HeapImpl.vale_heap",
"FStar.List.Tot.Base.memP",
"Vale.Interop.Types.b8",
"Vale.Interop.Heap_s.__proj__InteropHeap__item__ptrs",
"Vale.Arch.HeapImpl._ih",
"Prims.eq2",
"Prims.int",
"Vale.X64.Memory.buffer_addr",
"Vale.X64.Memory.buffer_write",
"Vale.Arch.MachineHeap_s.machine_heap",
"Vale.Interop.Heap_s.correct_down",
"Prims.l_and",
"Prims.l_Forall",
"Prims.l_imp",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition",
"FStar.Mul.op_Star",
"Vale.Def.Types_s.nat8",
"Vale.X64.Memory.op_String_Access",
"Prims.op_GreaterThanOrEqual",
"Prims.bool",
"Vale.X64.Memory_Sems.written_buffer_down128_aux1",
"Prims.unit",
"Vale.X64.Memory_Sems.heap_shift",
"Vale.X64.Memory_Sems.same_mem_get_heap_val128",
"Vale.X64.Memory.scale16",
"Prims.l_True",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [
"recursion"
] | false | false | true | false | false | let rec written_buffer_down128_aux1
(b: buffer128{buffer_writeable b})
(i: nat{i < buffer_length b})
(v: quad32)
(h: vale_heap{List.memP b (_ih h).IB.ptrs})
(base: nat{base == buffer_addr b h})
(k: nat)
(h1: vale_heap{h1 == buffer_write b i v h})
(mem1: S.machine_heap{IB.correct_down (_ih h) mem1})
(mem2:
S.machine_heap
{ IB.correct_down (_ih h1) mem2 /\
(forall j. {:pattern (mem1.[ j ])\/(mem2.[ j ])}
base <= j /\ j < base + k * 16 ==> mem1.[ j ] == mem2.[ j ]) })
: Lemma
(ensures
(forall j. {:pattern (mem1.[ j ])\/(mem1.[ j ])}
j >= base /\ j < base + scale16 i ==> mem1.[ j ] == mem2.[ j ])) (decreases %[i - k]) =
| if k >= i
then ()
else
let ptr = base + scale16 k in
same_mem_get_heap_val128 b i v k h h1 mem1 mem2;
heap_shift mem1 mem2 ptr 16;
written_buffer_down128_aux1 b i v h base (k + 1) h1 mem1 mem2 | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.