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
listlengths
0
2
mutual_with
listlengths
0
11
ideal_premises
listlengths
0
236
proof_features
listlengths
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
FStar.Krml.Endianness.fst
FStar.Krml.Endianness.n_to_le_le_to_n
val n_to_le_le_to_n (len: U32.t) (s: Seq.seq U8.t) : Lemma (requires (Seq.length s == U32.v len)) (ensures (le_to_n s < pow2 (8 `Prims.op_Multiply` (U32.v len)) /\ n_to_le len (le_to_n s) == s)) [SMTPat (n_to_le len (le_to_n s))]
val n_to_le_le_to_n (len: U32.t) (s: Seq.seq U8.t) : Lemma (requires (Seq.length s == U32.v len)) (ensures (le_to_n s < pow2 (8 `Prims.op_Multiply` (U32.v len)) /\ n_to_le len (le_to_n s) == s)) [SMTPat (n_to_le len (le_to_n s))]
let n_to_le_le_to_n (len: U32.t) (s: Seq.seq U8.t) : Lemma (requires (Seq.length s == U32.v len)) (ensures ( le_to_n s < pow2 (8 `Prims.op_Multiply` U32.v len) /\ n_to_le len (le_to_n s) == s )) [SMTPat (n_to_le len (le_to_n s))] = lemma_le_to_n_is_bounded s; le_to_n_inj s (n_to_le len (le_to_n s))
{ "file_name": "krmllib/FStar.Krml.Endianness.fst", "git_rev": "da1e941b2fcb196aa5d1e34941aa00b4c67ac321", "git_url": "https://github.com/FStarLang/karamel.git", "project_name": "karamel" }
{ "end_col": 41, "end_line": 192, "start_col": 0, "start_line": 184 }
module FStar.Krml.Endianness open FStar.Mul open FStar.HyperStack.All module U8 = FStar.UInt8 module U32 = FStar.UInt32 module U64 = FStar.UInt64 module Math = FStar.Math.Lemmas module S = FStar.Seq (* Selectively imported from Hacl*'s FStar.Endianness.fst library, with several name changes *) inline_for_extraction noextract type bytes = S.seq U8.t /// lt_to_n interprets a byte sequence as a little-endian natural number [@(deprecated "FStar.Endianness.le_to_n")] val le_to_n : b:bytes -> Tot nat (decreases (S.length b)) let rec le_to_n b = if S.length b = 0 then 0 else U8.v (S.head b) + pow2 8 * le_to_n (S.tail b) /// be_to_n interprets a byte sequence as a big-endian natural number [@(deprecated "FStar.Endianness.be_to_n")] val be_to_n : b:bytes -> Tot nat (decreases (S.length b)) let rec be_to_n b = if S.length b = 0 then 0 else U8.v (S.last b) + pow2 8 * be_to_n (S.slice b 0 (S.length b - 1)) [@(deprecated "FStar.Endianness.lemma_euclidean_division")] private val lemma_euclidean_division: r:nat -> b:nat -> q:pos -> Lemma (requires (r < q)) (ensures (r + q * b < q * (b+1))) let lemma_euclidean_division r b q = () [@(deprecated "FStar.Endianness.lemma_factorise")] private val lemma_factorise: a:nat -> b:nat -> Lemma (a + a * b == a * (b + 1)) let lemma_factorise a b = () [@(deprecated "FStar.Endianness.lemma_le_to_n_is_bounded")] val lemma_le_to_n_is_bounded: b:bytes -> Lemma (requires True) (ensures (le_to_n b < pow2 (8 * Seq.length b))) (decreases (Seq.length b)) let rec lemma_le_to_n_is_bounded b = if Seq.length b = 0 then () else begin let s = Seq.slice b 1 (Seq.length b) in assert(Seq.length s = Seq.length b - 1); lemma_le_to_n_is_bounded s; assert(UInt8.v (Seq.index b 0) < pow2 8); assert(le_to_n s < pow2 (8 * Seq.length s)); assert(le_to_n b < pow2 8 + pow2 8 * pow2 (8 * (Seq.length b - 1))); lemma_euclidean_division (UInt8.v (Seq.index b 0)) (le_to_n s) (pow2 8); assert(le_to_n b <= pow2 8 * (le_to_n s + 1)); assert(le_to_n b <= pow2 8 * pow2 (8 * (Seq.length b - 1))); Math.Lemmas.pow2_plus 8 (8 * (Seq.length b - 1)); lemma_factorise 8 (Seq.length b - 1) end [@(deprecated "FStar.Endianness.lemma_be_to_n_is_bounded")] val lemma_be_to_n_is_bounded: b:bytes -> Lemma (requires True) (ensures (be_to_n b < pow2 (8 * Seq.length b))) (decreases (Seq.length b)) let rec lemma_be_to_n_is_bounded b = if Seq.length b = 0 then () else begin let s = Seq.slice b 0 (Seq.length b - 1) in assert(Seq.length s = Seq.length b - 1); lemma_be_to_n_is_bounded s; assert(UInt8.v (Seq.last b) < pow2 8); assert(be_to_n s < pow2 (8 * Seq.length s)); assert(be_to_n b < pow2 8 + pow2 8 * pow2 (8 * (Seq.length b - 1))); lemma_euclidean_division (UInt8.v (Seq.last b)) (be_to_n s) (pow2 8); assert(be_to_n b <= pow2 8 * (be_to_n s + 1)); assert(be_to_n b <= pow2 8 * pow2 (8 * (Seq.length b - 1))); Math.Lemmas.pow2_plus 8 (8 * (Seq.length b - 1)); lemma_factorise 8 (Seq.length b - 1) end /// n_to_le encodes a number as a little-endian byte sequence of a fixed, /// sufficiently large length [@(deprecated "FStar.Endianness.n_to_le")] val n_to_le : len:U32.t -> n:nat{n < pow2 (8 * U32.v len)} -> Tot (b:bytes{S.length b == U32.v len /\ n == le_to_n b}) (decreases (U32.v len)) let rec n_to_le len n = if len = 0ul then S.empty else let len = U32.(len -^ 1ul) in let byte = U8.uint_to_t (n % 256) in let n' = n / 256 in Math.pow2_plus 8 (8 * U32.v len); assert(n' < pow2 (8 * U32.v len )); let b' = n_to_le len n' in let b = S.cons byte b' in S.lemma_eq_intro b' (S.tail b); b /// n_to_be encodes a numbers as a big-endian byte sequence of a fixed, /// sufficiently large length [@(deprecated "FStar.Endianness.n_to_be")] val n_to_be: len:U32.t -> n:nat{n < pow2 (8 * U32.v len)} -> Tot (b:bytes{S.length b == U32.v len /\ n == be_to_n b}) (decreases (U32.v len)) let rec n_to_be len n = if len = 0ul then S.empty else let len = U32.(len -^ 1ul) in let byte = U8.uint_to_t (n % 256) in let n' = n / 256 in Math.pow2_plus 8 (8 * U32.v len); assert(n' < pow2 (8 * U32.v len )); let b' = n_to_be len n' in let b'' = S.create 1 byte in let b = S.append b' b'' in S.lemma_eq_intro b' (S.slice b 0 (U32.v len)); b [@(deprecated "FStar.Endianness.n_to_le_inj")] let n_to_le_inj (len:U32.t) (n1 n2: (n:nat{n < pow2 (8 * U32.v len)})) : Lemma (requires (n_to_le len n1 == n_to_le len n2)) (ensures (n1 == n2)) = // this lemma easily follows from le_to_n . (n_to_le len) == id, the inversion // proof in the spec for n_to_le () [@(deprecated "FStar.Endianness.n_to_be_inj")] let n_to_be_inj (len:U32.t) (n1 n2: (n:nat{n < pow2 (8 * U32.v len)})) : Lemma (requires (n_to_be len n1 == n_to_be len n2)) (ensures (n1 == n2)) = () [@(deprecated "FStar.Endianness.be_to_n_inj")] let rec be_to_n_inj (b1 b2: Seq.seq U8.t) : Lemma (requires (Seq.length b1 == Seq.length b2 /\ be_to_n b1 == be_to_n b2)) (ensures (Seq.equal b1 b2)) (decreases (Seq.length b1)) = if Seq.length b1 = 0 then () else begin be_to_n_inj (Seq.slice b1 0 (Seq.length b1 - 1)) (Seq.slice b2 0 (Seq.length b2 - 1)); Seq.lemma_split b1 (Seq.length b1 - 1); Seq.lemma_split b2 (Seq.length b2 - 1) end [@(deprecated "FStar.Endianness.le_to_n_inj")] let rec le_to_n_inj (b1 b2: Seq.seq U8.t) : Lemma (requires (Seq.length b1 == Seq.length b2 /\ le_to_n b1 == le_to_n b2)) (ensures (Seq.equal b1 b2)) (decreases (Seq.length b1)) = if Seq.length b1 = 0 then () else begin le_to_n_inj (Seq.slice b1 1 (Seq.length b1)) (Seq.slice b2 1 (Seq.length b2)); Seq.lemma_split b1 1; Seq.lemma_split b2 1 end [@(deprecated "FStar.Endianness.n_to_be_be_to_n")] let n_to_be_be_to_n (len: U32.t) (s: Seq.seq U8.t) : Lemma (requires (Seq.length s == U32.v len)) (ensures ( be_to_n s < pow2 (8 `Prims.op_Multiply` U32.v len) /\ n_to_be len (be_to_n s) == s )) [SMTPat (n_to_be len (be_to_n s))] = lemma_be_to_n_is_bounded s; be_to_n_inj s (n_to_be len (be_to_n s))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.All.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "FStar.Krml.Endianness.fst" }
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Math.Lemmas", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Krml", "short_module": null }, { "abbrev": false, "full_module": "FStar.Krml", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
len: FStar.UInt32.t -> s: FStar.Seq.Base.seq FStar.UInt8.t -> FStar.Pervasives.Lemma (requires FStar.Seq.Base.length s == FStar.UInt32.v len) (ensures FStar.Krml.Endianness.le_to_n s < Prims.pow2 (8 * FStar.UInt32.v len) /\ FStar.Krml.Endianness.n_to_le len (FStar.Krml.Endianness.le_to_n s) == s) [SMTPat (FStar.Krml.Endianness.n_to_le len (FStar.Krml.Endianness.le_to_n s))]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "FStar.UInt32.t", "FStar.Seq.Base.seq", "FStar.UInt8.t", "FStar.Krml.Endianness.le_to_n_inj", "FStar.Krml.Endianness.n_to_le", "FStar.Krml.Endianness.le_to_n", "Prims.unit", "FStar.Krml.Endianness.lemma_le_to_n_is_bounded", "Prims.eq2", "Prims.int", "Prims.l_or", "Prims.b2t", "Prims.op_GreaterThanOrEqual", "FStar.UInt.size", "FStar.UInt32.n", "FStar.Seq.Base.length", "FStar.UInt32.v", "Prims.squash", "Prims.l_and", "Prims.op_LessThan", "Prims.pow2", "Prims.op_Multiply", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat", "FStar.Krml.Endianness.bytes", "Prims.nat", "Prims.Nil" ]
[]
true
false
true
false
false
let n_to_le_le_to_n (len: U32.t) (s: Seq.seq U8.t) : Lemma (requires (Seq.length s == U32.v len)) (ensures (le_to_n s < pow2 (8 `Prims.op_Multiply` (U32.v len)) /\ n_to_le len (le_to_n s) == s)) [SMTPat (n_to_le len (le_to_n s))] =
lemma_le_to_n_is_bounded s; le_to_n_inj s (n_to_le len (le_to_n s))
false
FStar.Krml.Endianness.fst
FStar.Krml.Endianness.n_to_be_be_to_n
val n_to_be_be_to_n (len: U32.t) (s: Seq.seq U8.t) : Lemma (requires (Seq.length s == U32.v len)) (ensures (be_to_n s < pow2 (8 `Prims.op_Multiply` (U32.v len)) /\ n_to_be len (be_to_n s) == s)) [SMTPat (n_to_be len (be_to_n s))]
val n_to_be_be_to_n (len: U32.t) (s: Seq.seq U8.t) : Lemma (requires (Seq.length s == U32.v len)) (ensures (be_to_n s < pow2 (8 `Prims.op_Multiply` (U32.v len)) /\ n_to_be len (be_to_n s) == s)) [SMTPat (n_to_be len (be_to_n s))]
let n_to_be_be_to_n (len: U32.t) (s: Seq.seq U8.t) : Lemma (requires (Seq.length s == U32.v len)) (ensures ( be_to_n s < pow2 (8 `Prims.op_Multiply` U32.v len) /\ n_to_be len (be_to_n s) == s )) [SMTPat (n_to_be len (be_to_n s))] = lemma_be_to_n_is_bounded s; be_to_n_inj s (n_to_be len (be_to_n s))
{ "file_name": "krmllib/FStar.Krml.Endianness.fst", "git_rev": "da1e941b2fcb196aa5d1e34941aa00b4c67ac321", "git_url": "https://github.com/FStarLang/karamel.git", "project_name": "karamel" }
{ "end_col": 41, "end_line": 181, "start_col": 0, "start_line": 173 }
module FStar.Krml.Endianness open FStar.Mul open FStar.HyperStack.All module U8 = FStar.UInt8 module U32 = FStar.UInt32 module U64 = FStar.UInt64 module Math = FStar.Math.Lemmas module S = FStar.Seq (* Selectively imported from Hacl*'s FStar.Endianness.fst library, with several name changes *) inline_for_extraction noextract type bytes = S.seq U8.t /// lt_to_n interprets a byte sequence as a little-endian natural number [@(deprecated "FStar.Endianness.le_to_n")] val le_to_n : b:bytes -> Tot nat (decreases (S.length b)) let rec le_to_n b = if S.length b = 0 then 0 else U8.v (S.head b) + pow2 8 * le_to_n (S.tail b) /// be_to_n interprets a byte sequence as a big-endian natural number [@(deprecated "FStar.Endianness.be_to_n")] val be_to_n : b:bytes -> Tot nat (decreases (S.length b)) let rec be_to_n b = if S.length b = 0 then 0 else U8.v (S.last b) + pow2 8 * be_to_n (S.slice b 0 (S.length b - 1)) [@(deprecated "FStar.Endianness.lemma_euclidean_division")] private val lemma_euclidean_division: r:nat -> b:nat -> q:pos -> Lemma (requires (r < q)) (ensures (r + q * b < q * (b+1))) let lemma_euclidean_division r b q = () [@(deprecated "FStar.Endianness.lemma_factorise")] private val lemma_factorise: a:nat -> b:nat -> Lemma (a + a * b == a * (b + 1)) let lemma_factorise a b = () [@(deprecated "FStar.Endianness.lemma_le_to_n_is_bounded")] val lemma_le_to_n_is_bounded: b:bytes -> Lemma (requires True) (ensures (le_to_n b < pow2 (8 * Seq.length b))) (decreases (Seq.length b)) let rec lemma_le_to_n_is_bounded b = if Seq.length b = 0 then () else begin let s = Seq.slice b 1 (Seq.length b) in assert(Seq.length s = Seq.length b - 1); lemma_le_to_n_is_bounded s; assert(UInt8.v (Seq.index b 0) < pow2 8); assert(le_to_n s < pow2 (8 * Seq.length s)); assert(le_to_n b < pow2 8 + pow2 8 * pow2 (8 * (Seq.length b - 1))); lemma_euclidean_division (UInt8.v (Seq.index b 0)) (le_to_n s) (pow2 8); assert(le_to_n b <= pow2 8 * (le_to_n s + 1)); assert(le_to_n b <= pow2 8 * pow2 (8 * (Seq.length b - 1))); Math.Lemmas.pow2_plus 8 (8 * (Seq.length b - 1)); lemma_factorise 8 (Seq.length b - 1) end [@(deprecated "FStar.Endianness.lemma_be_to_n_is_bounded")] val lemma_be_to_n_is_bounded: b:bytes -> Lemma (requires True) (ensures (be_to_n b < pow2 (8 * Seq.length b))) (decreases (Seq.length b)) let rec lemma_be_to_n_is_bounded b = if Seq.length b = 0 then () else begin let s = Seq.slice b 0 (Seq.length b - 1) in assert(Seq.length s = Seq.length b - 1); lemma_be_to_n_is_bounded s; assert(UInt8.v (Seq.last b) < pow2 8); assert(be_to_n s < pow2 (8 * Seq.length s)); assert(be_to_n b < pow2 8 + pow2 8 * pow2 (8 * (Seq.length b - 1))); lemma_euclidean_division (UInt8.v (Seq.last b)) (be_to_n s) (pow2 8); assert(be_to_n b <= pow2 8 * (be_to_n s + 1)); assert(be_to_n b <= pow2 8 * pow2 (8 * (Seq.length b - 1))); Math.Lemmas.pow2_plus 8 (8 * (Seq.length b - 1)); lemma_factorise 8 (Seq.length b - 1) end /// n_to_le encodes a number as a little-endian byte sequence of a fixed, /// sufficiently large length [@(deprecated "FStar.Endianness.n_to_le")] val n_to_le : len:U32.t -> n:nat{n < pow2 (8 * U32.v len)} -> Tot (b:bytes{S.length b == U32.v len /\ n == le_to_n b}) (decreases (U32.v len)) let rec n_to_le len n = if len = 0ul then S.empty else let len = U32.(len -^ 1ul) in let byte = U8.uint_to_t (n % 256) in let n' = n / 256 in Math.pow2_plus 8 (8 * U32.v len); assert(n' < pow2 (8 * U32.v len )); let b' = n_to_le len n' in let b = S.cons byte b' in S.lemma_eq_intro b' (S.tail b); b /// n_to_be encodes a numbers as a big-endian byte sequence of a fixed, /// sufficiently large length [@(deprecated "FStar.Endianness.n_to_be")] val n_to_be: len:U32.t -> n:nat{n < pow2 (8 * U32.v len)} -> Tot (b:bytes{S.length b == U32.v len /\ n == be_to_n b}) (decreases (U32.v len)) let rec n_to_be len n = if len = 0ul then S.empty else let len = U32.(len -^ 1ul) in let byte = U8.uint_to_t (n % 256) in let n' = n / 256 in Math.pow2_plus 8 (8 * U32.v len); assert(n' < pow2 (8 * U32.v len )); let b' = n_to_be len n' in let b'' = S.create 1 byte in let b = S.append b' b'' in S.lemma_eq_intro b' (S.slice b 0 (U32.v len)); b [@(deprecated "FStar.Endianness.n_to_le_inj")] let n_to_le_inj (len:U32.t) (n1 n2: (n:nat{n < pow2 (8 * U32.v len)})) : Lemma (requires (n_to_le len n1 == n_to_le len n2)) (ensures (n1 == n2)) = // this lemma easily follows from le_to_n . (n_to_le len) == id, the inversion // proof in the spec for n_to_le () [@(deprecated "FStar.Endianness.n_to_be_inj")] let n_to_be_inj (len:U32.t) (n1 n2: (n:nat{n < pow2 (8 * U32.v len)})) : Lemma (requires (n_to_be len n1 == n_to_be len n2)) (ensures (n1 == n2)) = () [@(deprecated "FStar.Endianness.be_to_n_inj")] let rec be_to_n_inj (b1 b2: Seq.seq U8.t) : Lemma (requires (Seq.length b1 == Seq.length b2 /\ be_to_n b1 == be_to_n b2)) (ensures (Seq.equal b1 b2)) (decreases (Seq.length b1)) = if Seq.length b1 = 0 then () else begin be_to_n_inj (Seq.slice b1 0 (Seq.length b1 - 1)) (Seq.slice b2 0 (Seq.length b2 - 1)); Seq.lemma_split b1 (Seq.length b1 - 1); Seq.lemma_split b2 (Seq.length b2 - 1) end [@(deprecated "FStar.Endianness.le_to_n_inj")] let rec le_to_n_inj (b1 b2: Seq.seq U8.t) : Lemma (requires (Seq.length b1 == Seq.length b2 /\ le_to_n b1 == le_to_n b2)) (ensures (Seq.equal b1 b2)) (decreases (Seq.length b1)) = if Seq.length b1 = 0 then () else begin le_to_n_inj (Seq.slice b1 1 (Seq.length b1)) (Seq.slice b2 1 (Seq.length b2)); Seq.lemma_split b1 1; Seq.lemma_split b2 1 end
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.All.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "FStar.Krml.Endianness.fst" }
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Math.Lemmas", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Krml", "short_module": null }, { "abbrev": false, "full_module": "FStar.Krml", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
len: FStar.UInt32.t -> s: FStar.Seq.Base.seq FStar.UInt8.t -> FStar.Pervasives.Lemma (requires FStar.Seq.Base.length s == FStar.UInt32.v len) (ensures FStar.Krml.Endianness.be_to_n s < Prims.pow2 (8 * FStar.UInt32.v len) /\ FStar.Krml.Endianness.n_to_be len (FStar.Krml.Endianness.be_to_n s) == s) [SMTPat (FStar.Krml.Endianness.n_to_be len (FStar.Krml.Endianness.be_to_n s))]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "FStar.UInt32.t", "FStar.Seq.Base.seq", "FStar.UInt8.t", "FStar.Krml.Endianness.be_to_n_inj", "FStar.Krml.Endianness.n_to_be", "FStar.Krml.Endianness.be_to_n", "Prims.unit", "FStar.Krml.Endianness.lemma_be_to_n_is_bounded", "Prims.eq2", "Prims.int", "Prims.l_or", "Prims.b2t", "Prims.op_GreaterThanOrEqual", "FStar.UInt.size", "FStar.UInt32.n", "FStar.Seq.Base.length", "FStar.UInt32.v", "Prims.squash", "Prims.l_and", "Prims.op_LessThan", "Prims.pow2", "Prims.op_Multiply", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat", "FStar.Krml.Endianness.bytes", "Prims.nat", "Prims.Nil" ]
[]
true
false
true
false
false
let n_to_be_be_to_n (len: U32.t) (s: Seq.seq U8.t) : Lemma (requires (Seq.length s == U32.v len)) (ensures (be_to_n s < pow2 (8 `Prims.op_Multiply` (U32.v len)) /\ n_to_be len (be_to_n s) == s)) [SMTPat (n_to_be len (be_to_n s))] =
lemma_be_to_n_is_bounded s; be_to_n_inj s (n_to_be len (be_to_n s))
false
Hacl.Spec.Bignum.Multiplication.fst
Hacl.Spec.Bignum.Multiplication.bn_mul1_add_in_place_lemma
val bn_mul1_add_in_place_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> l:limb t -> acc:lbignum t aLen -> Lemma (let (c, res) = bn_mul1_add_in_place a l acc in v c * pow2 (bits t * aLen) + bn_v res == bn_v acc + bn_v a * v l)
val bn_mul1_add_in_place_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> l:limb t -> acc:lbignum t aLen -> Lemma (let (c, res) = bn_mul1_add_in_place a l acc in v c * pow2 (bits t * aLen) + bn_v res == bn_v acc + bn_v a * v l)
let bn_mul1_add_in_place_lemma #t #aLen a l acc = let (c, res) = bn_mul1_add_in_place a l acc in bn_mul1_add_in_place_lemma_loop a l acc aLen
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Multiplication.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 46, "end_line": 307, "start_col": 0, "start_line": 305 }
module Hacl.Spec.Bignum.Multiplication open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.LoopCombinators open Hacl.Spec.Bignum.Definitions open Hacl.Spec.Bignum.Base open Hacl.Spec.Lib #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" val bn_mul1_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> l:limb t -> i:size_nat{i < aLen} -> c:limb t -> limb t & limb t // carry & out let bn_mul1_f #t #aLen a l i c = mul_wide_add a.[i] l c val bn_mul1: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> l:limb t -> limb t & lbignum t aLen let bn_mul1 #t #aLen a l = generate_elems aLen aLen (bn_mul1_f a l) (uint #t 0) val bn_mul1_add_in_place_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> l:limb t -> acc:lbignum t aLen -> i:size_nat{i < aLen} -> c:limb t -> limb t & limb t // carry & out let bn_mul1_add_in_place_f #t #aLen a l acc i c = mul_wide_add2 a.[i] l c acc.[i] val bn_mul1_add_in_place: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> l:limb t -> acc:lbignum t aLen -> limb t & lbignum t aLen let bn_mul1_add_in_place #t #aLen a l acc = generate_elems aLen aLen (bn_mul1_add_in_place_f a l acc) (uint #t 0) val bn_mul1_lshift_add: #t:limb_t -> #aLen:size_nat -> #resLen:size_nat -> a:lbignum t aLen -> b_j:limb t -> j:size_nat{j + aLen <= resLen} -> res:lbignum t resLen -> limb t & lbignum t resLen let bn_mul1_lshift_add #t #aLen #resLen a b_j j res = let res' = sub res j aLen in let c, res' = bn_mul1_add_in_place a b_j res' in let res = update_sub res j aLen res' in c, res val bn_mul_: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat{aLen + bLen <= max_size_t} -> a:lbignum t aLen -> b:lbignum t bLen -> j:size_nat{j < bLen} -> res:lbignum t (aLen + bLen) -> lbignum t (aLen + bLen) let bn_mul_ #t #aLen #bLen a b j res = let c, res = bn_mul1_lshift_add a b.[j] j res in res.[aLen + j] <- c val bn_mul: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat{aLen + bLen <= max_size_t} -> a:lbignum t aLen -> b:lbignum t bLen -> lbignum t (aLen + bLen) let bn_mul #t #aLen #bLen a b = let res = create (aLen + bLen) (uint #t 0) in repeati bLen (bn_mul_ a b) res val bn_mul1_lemma_loop_step: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> l:limb t -> i:pos{i <= aLen} -> c1_res1:generate_elem_a (limb t) (limb t) aLen (i - 1) -> Lemma (requires (let (c1, res1) = c1_res1 in v c1 * pow2 (bits t * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen a (i - 1) * v l)) (ensures (let (c1, res1) = c1_res1 in let (c, res) = generate_elem_f aLen (bn_mul1_f a l) (i - 1) (c1, res1) in v c * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen a i * v l)) let bn_mul1_lemma_loop_step #t #aLen a l i (c1, res1) = let pbits = bits t in let b1 = pow2 (pbits * (i - 1)) in let b2 = pow2 (pbits * i) in let (c, res) = generate_elem_f aLen (bn_mul1_f a l) (i - 1) (c1, res1) in let c, e = mul_wide_add a.[i - 1] l c1 in assert (v e + v c * pow2 pbits == v a.[i - 1] * v l + v c1); calc (==) { v c * b2 + bn_v #t #i res; (==) { bn_eval_snoc #t #(i - 1) res1 e } v c * b2 + bn_v #t #(i - 1) res1 + v e * b1; (==) { } v c * b2 + eval_ aLen a (i - 1) * v l -(v e + v c * pow2 pbits - v a.[i - 1] * v l) * b1 + v e * b1; (==) { Math.Lemmas.distributivity_add_left (v e) (v c * pow2 pbits - v a.[i - 1] * v l) b1 } v c * b2 + eval_ aLen a (i - 1) * v l - (v c * pow2 pbits - v a.[i - 1] * v l) * b1; (==) { Math.Lemmas.distributivity_sub_left (v c * pow2 pbits) (v a.[i - 1] * v l) b1 } v c * b2 + eval_ aLen a (i - 1) * v l - v c * pow2 pbits * b1 + v a.[i - 1] * v l * b1; (==) { Math.Lemmas.paren_mul_right (v c) (pow2 pbits) b1; Math.Lemmas.pow2_plus pbits (pbits * (i - 1)) } eval_ aLen a (i - 1) * v l + v a.[i - 1] * v l * b1; (==) { Math.Lemmas.paren_mul_right (v a.[i - 1]) (v l) b1 } eval_ aLen a (i - 1) * v l + v a.[i - 1] * (b1 * v l); (==) { Math.Lemmas.paren_mul_right (v a.[i - 1]) b1 (v l) } eval_ aLen a (i - 1) * v l + v a.[i - 1] * b1 * v l; (==) { Math.Lemmas.distributivity_add_left (eval_ aLen a (i - 1)) (v a.[i - 1] * b1) (v l) } (eval_ aLen a (i - 1) + v a.[i - 1] * b1) * v l; (==) { bn_eval_unfold_i a i } eval_ aLen a i * v l; }; assert (v c * b2 + bn_v #t #i res == eval_ aLen a i * v l) val bn_mul1_lemma_loop: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> l:limb t -> i:nat{i <= aLen} -> Lemma (let (c, res) : generate_elem_a (limb t) (limb t) aLen i = generate_elems aLen i (bn_mul1_f a l) (uint #t 0) in v c * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen a i * v l) let rec bn_mul1_lemma_loop #t #aLen a l i = let pbits = bits t in let (c, res) : generate_elem_a (limb t) (limb t) aLen i = generate_elems aLen i (bn_mul1_f a l) (uint #t 0) in if i = 0 then begin eq_generate_elems0 aLen i (bn_mul1_f a l) (uint #t 0); assert (c == uint #t 0 /\ res == Seq.empty); bn_eval0 #t #0 res; assert_norm (pow2 0 = 1); bn_eval0 a; () end else begin let (c1, res1) : generate_elem_a (limb t) (limb t) aLen (i - 1) = generate_elems aLen (i - 1) (bn_mul1_f a l) (uint #t 0) in generate_elems_unfold aLen i (bn_mul1_f a l) (uint #t 0) (i - 1); assert (generate_elems aLen i (bn_mul1_f a l) (uint #t 0) == generate_elem_f aLen (bn_mul1_f a l) (i - 1) (generate_elems aLen (i - 1) (bn_mul1_f a l) (uint #t 0))); assert ((c, res) == generate_elem_f aLen (bn_mul1_f a l) (i - 1) (c1, res1)); bn_mul1_lemma_loop a l (i - 1); assert (v c1 * pow2 (pbits * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen a (i - 1) * v l); bn_mul1_lemma_loop_step a l i (c1, res1); assert (v c * pow2 (pbits * i) + bn_v #t #i res == eval_ aLen a i * v l); () end val bn_mul1_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> l:limb t -> Lemma (let (c, res) = bn_mul1 a l in v c * pow2 (bits t * aLen) + bn_v res == bn_v a * v l) let bn_mul1_lemma #t #aLen a l = let (c, res) = bn_mul1 a l in bn_mul1_lemma_loop a l aLen #push-options "--z3rlimit 150" val bn_mul1_add_in_place_lemma_loop_step: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> l:limb t -> acc:lbignum t aLen -> i:pos{i <= aLen} -> c1_res1:generate_elem_a (limb t) (limb t) aLen (i - 1) -> Lemma (requires (let (c1, res1) = c1_res1 in v c1 * pow2 (bits t * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen acc (i - 1) + eval_ aLen a (i - 1) * v l)) (ensures (let (c1, res1) = c1_res1 in let (c, res) = generate_elem_f aLen (bn_mul1_add_in_place_f a l acc) (i - 1) (c1, res1) in v c * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen acc i + eval_ aLen a i * v l)) let bn_mul1_add_in_place_lemma_loop_step #t #aLen a l acc i (c1, res1) = let pbits = bits t in let b1 = pow2 (pbits * (i - 1)) in let b2 = pow2 (pbits * i) in let (c, res) = generate_elem_f aLen (bn_mul1_add_in_place_f a l acc) (i - 1) (c1, res1) in let c, e = mul_wide_add2 a.[i - 1] l c1 acc.[i - 1] in assert (v e + v c * pow2 pbits == v a.[i - 1] * v l + v c1 + v acc.[i - 1]); calc (==) { v c * b2 + bn_v #t #i res; (==) { bn_eval_snoc #t #(i - 1) res1 e } v c * b2 + bn_v #t #(i - 1) res1 + v e * b1; (==) { } v c * b2 + eval_ aLen acc (i - 1) + eval_ aLen a (i - 1) * v l - (v e + v c * pow2 pbits - v a.[i - 1] * v l - v acc.[i - 1]) * b1 + v e * b1; (==) { Math.Lemmas.distributivity_add_left (v e) (v c * pow2 pbits - v a.[i - 1] * v l - v acc.[i - 1]) b1 } v c * b2 + eval_ aLen acc (i - 1) + eval_ aLen a (i - 1) * v l - (v c * pow2 pbits - v a.[i - 1] * v l - v acc.[i - 1]) * b1; (==) { Math.Lemmas.distributivity_sub_left (v c * pow2 pbits) (v a.[i - 1] * v l + v acc.[i - 1]) b1 } v c * b2 + eval_ aLen acc (i - 1) + eval_ aLen a (i - 1) * v l - (v c * pow2 pbits) * b1 + (v a.[i - 1] * v l + v acc.[i - 1]) * b1; (==) { Math.Lemmas.paren_mul_right (v c) (pow2 pbits) b1; Math.Lemmas.pow2_plus pbits (pbits * (i - 1)) } eval_ aLen acc (i - 1) + eval_ aLen a (i - 1) * v l + (v a.[i - 1] * v l + v acc.[i - 1]) * b1; (==) { Math.Lemmas.distributivity_add_left (v a.[i - 1] * v l) (v acc.[i - 1]) b1 } eval_ aLen acc (i - 1) + eval_ aLen a (i - 1) * v l + v a.[i - 1] * v l * b1 + v acc.[i - 1] * b1; (==) { bn_eval_unfold_i acc i } eval_ aLen acc i + eval_ aLen a (i - 1) * v l + v a.[i - 1] * v l * b1; (==) { Math.Lemmas.paren_mul_right (v a.[i - 1]) (v l) b1 } eval_ aLen acc i + eval_ aLen a (i - 1) * v l + v a.[i - 1] * (b1 * v l); (==) { Math.Lemmas.paren_mul_right (v a.[i - 1]) b1 (v l) } eval_ aLen acc i + eval_ aLen a (i - 1) * v l + v a.[i - 1] * b1 * v l; (==) { Math.Lemmas.distributivity_add_left (eval_ aLen a (i - 1)) (v a.[i - 1] * b1) (v l) } eval_ aLen acc i + (eval_ aLen a (i - 1) + v a.[i - 1] * b1) * v l; (==) { bn_eval_unfold_i a i } eval_ aLen acc i + eval_ aLen a i * v l; }; assert (v c * b2 + bn_v #t #i res == eval_ aLen acc i + eval_ aLen a i * v l) #pop-options val bn_mul1_add_in_place_lemma_loop: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> l:limb t -> acc:lbignum t aLen -> i:nat{i <= aLen} -> Lemma (let (c, res) : generate_elem_a (limb t) (limb t) aLen i = generate_elems aLen i (bn_mul1_add_in_place_f a l acc) (uint #t 0) in v c * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen acc i + eval_ aLen a i * v l) let rec bn_mul1_add_in_place_lemma_loop #t #aLen a l acc i = let pbits = bits t in let (c, res) : generate_elem_a (limb t) (limb t) aLen i = generate_elems aLen i (bn_mul1_add_in_place_f a l acc) (uint #t 0) in if i = 0 then begin eq_generate_elems0 aLen i (bn_mul1_add_in_place_f a l acc) (uint #t 0); assert (c == uint #t 0 /\ res == Seq.empty); bn_eval0 #t #0 res; assert_norm (pow2 0 = 1); bn_eval0 a; bn_eval0 acc; () end else begin let (c1, res1) : generate_elem_a (limb t) (limb t) aLen (i - 1) = generate_elems aLen (i - 1) (bn_mul1_add_in_place_f a l acc) (uint #t 0) in generate_elems_unfold aLen i (bn_mul1_add_in_place_f a l acc) (uint #t 0) (i - 1); assert (generate_elems aLen i (bn_mul1_add_in_place_f a l acc) (uint #t 0) == generate_elem_f aLen (bn_mul1_add_in_place_f a l acc) (i - 1) (generate_elems aLen (i - 1) (bn_mul1_add_in_place_f a l acc) (uint #t 0))); assert ((c, res) == generate_elem_f aLen (bn_mul1_add_in_place_f a l acc) (i - 1) (c1, res1)); bn_mul1_add_in_place_lemma_loop a l acc (i - 1); assert (v c1 * pow2 (pbits * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen acc (i - 1) + eval_ aLen a (i - 1) * v l); bn_mul1_add_in_place_lemma_loop_step a l acc i (c1, res1); assert (v c * pow2 (pbits * i) + bn_v #t #i res == eval_ aLen acc i + eval_ aLen a i * v l); () end val bn_mul1_add_in_place_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> l:limb t -> acc:lbignum t aLen -> Lemma (let (c, res) = bn_mul1_add_in_place a l acc in v c * pow2 (bits t * aLen) + bn_v res == bn_v acc + bn_v a * v l)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Lib.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Bignum.Multiplication.fst" }
[ { "abbrev": false, "full_module": "Hacl.Spec.Lib", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Base", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> l: Hacl.Spec.Bignum.Definitions.limb t -> acc: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> FStar.Pervasives.Lemma (ensures (let _ = Hacl.Spec.Bignum.Multiplication.bn_mul1_add_in_place a l acc in (let FStar.Pervasives.Native.Mktuple2 #_ #_ c res = _ in Lib.IntTypes.v c * Prims.pow2 (Lib.IntTypes.bits t * aLen) + Hacl.Spec.Bignum.Definitions.bn_v res == Hacl.Spec.Bignum.Definitions.bn_v acc + Hacl.Spec.Bignum.Definitions.bn_v a * Lib.IntTypes.v l) <: Type0))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Lib.IntTypes.size_nat", "Hacl.Spec.Bignum.Definitions.lbignum", "Hacl.Spec.Bignum.Definitions.limb", "Hacl.Spec.Bignum.Multiplication.bn_mul1_add_in_place_lemma_loop", "Prims.unit", "FStar.Pervasives.Native.tuple2", "Hacl.Spec.Bignum.Multiplication.bn_mul1_add_in_place" ]
[]
false
false
true
false
false
let bn_mul1_add_in_place_lemma #t #aLen a l acc =
let c, res = bn_mul1_add_in_place a l acc in bn_mul1_add_in_place_lemma_loop a l acc aLen
false
FStar.Krml.Endianness.fst
FStar.Krml.Endianness.uint64_of_le
val uint64_of_le : b: FStar.Krml.Endianness.bytes{FStar.Seq.Base.length b = 8} -> FStar.UInt64.t
let uint64_of_le (b: bytes { S.length b = 8 }) = let n = le_to_n b in lemma_le_to_n_is_bounded b; UInt64.uint_to_t n
{ "file_name": "krmllib/FStar.Krml.Endianness.fst", "git_rev": "da1e941b2fcb196aa5d1e34941aa00b4c67ac321", "git_url": "https://github.com/FStarLang/karamel.git", "project_name": "karamel" }
{ "end_col": 20, "end_line": 220, "start_col": 0, "start_line": 217 }
module FStar.Krml.Endianness open FStar.Mul open FStar.HyperStack.All module U8 = FStar.UInt8 module U32 = FStar.UInt32 module U64 = FStar.UInt64 module Math = FStar.Math.Lemmas module S = FStar.Seq (* Selectively imported from Hacl*'s FStar.Endianness.fst library, with several name changes *) inline_for_extraction noextract type bytes = S.seq U8.t /// lt_to_n interprets a byte sequence as a little-endian natural number [@(deprecated "FStar.Endianness.le_to_n")] val le_to_n : b:bytes -> Tot nat (decreases (S.length b)) let rec le_to_n b = if S.length b = 0 then 0 else U8.v (S.head b) + pow2 8 * le_to_n (S.tail b) /// be_to_n interprets a byte sequence as a big-endian natural number [@(deprecated "FStar.Endianness.be_to_n")] val be_to_n : b:bytes -> Tot nat (decreases (S.length b)) let rec be_to_n b = if S.length b = 0 then 0 else U8.v (S.last b) + pow2 8 * be_to_n (S.slice b 0 (S.length b - 1)) [@(deprecated "FStar.Endianness.lemma_euclidean_division")] private val lemma_euclidean_division: r:nat -> b:nat -> q:pos -> Lemma (requires (r < q)) (ensures (r + q * b < q * (b+1))) let lemma_euclidean_division r b q = () [@(deprecated "FStar.Endianness.lemma_factorise")] private val lemma_factorise: a:nat -> b:nat -> Lemma (a + a * b == a * (b + 1)) let lemma_factorise a b = () [@(deprecated "FStar.Endianness.lemma_le_to_n_is_bounded")] val lemma_le_to_n_is_bounded: b:bytes -> Lemma (requires True) (ensures (le_to_n b < pow2 (8 * Seq.length b))) (decreases (Seq.length b)) let rec lemma_le_to_n_is_bounded b = if Seq.length b = 0 then () else begin let s = Seq.slice b 1 (Seq.length b) in assert(Seq.length s = Seq.length b - 1); lemma_le_to_n_is_bounded s; assert(UInt8.v (Seq.index b 0) < pow2 8); assert(le_to_n s < pow2 (8 * Seq.length s)); assert(le_to_n b < pow2 8 + pow2 8 * pow2 (8 * (Seq.length b - 1))); lemma_euclidean_division (UInt8.v (Seq.index b 0)) (le_to_n s) (pow2 8); assert(le_to_n b <= pow2 8 * (le_to_n s + 1)); assert(le_to_n b <= pow2 8 * pow2 (8 * (Seq.length b - 1))); Math.Lemmas.pow2_plus 8 (8 * (Seq.length b - 1)); lemma_factorise 8 (Seq.length b - 1) end [@(deprecated "FStar.Endianness.lemma_be_to_n_is_bounded")] val lemma_be_to_n_is_bounded: b:bytes -> Lemma (requires True) (ensures (be_to_n b < pow2 (8 * Seq.length b))) (decreases (Seq.length b)) let rec lemma_be_to_n_is_bounded b = if Seq.length b = 0 then () else begin let s = Seq.slice b 0 (Seq.length b - 1) in assert(Seq.length s = Seq.length b - 1); lemma_be_to_n_is_bounded s; assert(UInt8.v (Seq.last b) < pow2 8); assert(be_to_n s < pow2 (8 * Seq.length s)); assert(be_to_n b < pow2 8 + pow2 8 * pow2 (8 * (Seq.length b - 1))); lemma_euclidean_division (UInt8.v (Seq.last b)) (be_to_n s) (pow2 8); assert(be_to_n b <= pow2 8 * (be_to_n s + 1)); assert(be_to_n b <= pow2 8 * pow2 (8 * (Seq.length b - 1))); Math.Lemmas.pow2_plus 8 (8 * (Seq.length b - 1)); lemma_factorise 8 (Seq.length b - 1) end /// n_to_le encodes a number as a little-endian byte sequence of a fixed, /// sufficiently large length [@(deprecated "FStar.Endianness.n_to_le")] val n_to_le : len:U32.t -> n:nat{n < pow2 (8 * U32.v len)} -> Tot (b:bytes{S.length b == U32.v len /\ n == le_to_n b}) (decreases (U32.v len)) let rec n_to_le len n = if len = 0ul then S.empty else let len = U32.(len -^ 1ul) in let byte = U8.uint_to_t (n % 256) in let n' = n / 256 in Math.pow2_plus 8 (8 * U32.v len); assert(n' < pow2 (8 * U32.v len )); let b' = n_to_le len n' in let b = S.cons byte b' in S.lemma_eq_intro b' (S.tail b); b /// n_to_be encodes a numbers as a big-endian byte sequence of a fixed, /// sufficiently large length [@(deprecated "FStar.Endianness.n_to_be")] val n_to_be: len:U32.t -> n:nat{n < pow2 (8 * U32.v len)} -> Tot (b:bytes{S.length b == U32.v len /\ n == be_to_n b}) (decreases (U32.v len)) let rec n_to_be len n = if len = 0ul then S.empty else let len = U32.(len -^ 1ul) in let byte = U8.uint_to_t (n % 256) in let n' = n / 256 in Math.pow2_plus 8 (8 * U32.v len); assert(n' < pow2 (8 * U32.v len )); let b' = n_to_be len n' in let b'' = S.create 1 byte in let b = S.append b' b'' in S.lemma_eq_intro b' (S.slice b 0 (U32.v len)); b [@(deprecated "FStar.Endianness.n_to_le_inj")] let n_to_le_inj (len:U32.t) (n1 n2: (n:nat{n < pow2 (8 * U32.v len)})) : Lemma (requires (n_to_le len n1 == n_to_le len n2)) (ensures (n1 == n2)) = // this lemma easily follows from le_to_n . (n_to_le len) == id, the inversion // proof in the spec for n_to_le () [@(deprecated "FStar.Endianness.n_to_be_inj")] let n_to_be_inj (len:U32.t) (n1 n2: (n:nat{n < pow2 (8 * U32.v len)})) : Lemma (requires (n_to_be len n1 == n_to_be len n2)) (ensures (n1 == n2)) = () [@(deprecated "FStar.Endianness.be_to_n_inj")] let rec be_to_n_inj (b1 b2: Seq.seq U8.t) : Lemma (requires (Seq.length b1 == Seq.length b2 /\ be_to_n b1 == be_to_n b2)) (ensures (Seq.equal b1 b2)) (decreases (Seq.length b1)) = if Seq.length b1 = 0 then () else begin be_to_n_inj (Seq.slice b1 0 (Seq.length b1 - 1)) (Seq.slice b2 0 (Seq.length b2 - 1)); Seq.lemma_split b1 (Seq.length b1 - 1); Seq.lemma_split b2 (Seq.length b2 - 1) end [@(deprecated "FStar.Endianness.le_to_n_inj")] let rec le_to_n_inj (b1 b2: Seq.seq U8.t) : Lemma (requires (Seq.length b1 == Seq.length b2 /\ le_to_n b1 == le_to_n b2)) (ensures (Seq.equal b1 b2)) (decreases (Seq.length b1)) = if Seq.length b1 = 0 then () else begin le_to_n_inj (Seq.slice b1 1 (Seq.length b1)) (Seq.slice b2 1 (Seq.length b2)); Seq.lemma_split b1 1; Seq.lemma_split b2 1 end [@(deprecated "FStar.Endianness.n_to_be_be_to_n")] let n_to_be_be_to_n (len: U32.t) (s: Seq.seq U8.t) : Lemma (requires (Seq.length s == U32.v len)) (ensures ( be_to_n s < pow2 (8 `Prims.op_Multiply` U32.v len) /\ n_to_be len (be_to_n s) == s )) [SMTPat (n_to_be len (be_to_n s))] = lemma_be_to_n_is_bounded s; be_to_n_inj s (n_to_be len (be_to_n s)) [@(deprecated "FStar.Endianness.n_to_le_le_to_n")] let n_to_le_le_to_n (len: U32.t) (s: Seq.seq U8.t) : Lemma (requires (Seq.length s == U32.v len)) (ensures ( le_to_n s < pow2 (8 `Prims.op_Multiply` U32.v len) /\ n_to_le len (le_to_n s) == s )) [SMTPat (n_to_le len (le_to_n s))] = lemma_le_to_n_is_bounded s; le_to_n_inj s (n_to_le len (le_to_n s)) (** A series of specializations to deal with machine integers *) [@(deprecated "FStar.Endianness.uint32_of_le")] let uint32_of_le (b: bytes { S.length b = 4 }) = let n = le_to_n b in lemma_le_to_n_is_bounded b; UInt32.uint_to_t n [@(deprecated "FStar.Endianness.le_of_uint32")] let le_of_uint32 (x: UInt32.t): b:bytes{ S.length b = 4 } = n_to_le 4ul (UInt32.v x) [@(deprecated "FStar.Endianness.uint32_of_be")] let uint32_of_be (b: bytes { S.length b = 4 }) = let n = be_to_n b in lemma_be_to_n_is_bounded b; UInt32.uint_to_t n [@(deprecated "FStar.Endianness.be_of_uint32")] let be_of_uint32 (x: UInt32.t): b:bytes{ S.length b = 4 } = n_to_be 4ul (UInt32.v x)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.All.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "FStar.Krml.Endianness.fst" }
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Math.Lemmas", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Krml", "short_module": null }, { "abbrev": false, "full_module": "FStar.Krml", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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: FStar.Krml.Endianness.bytes{FStar.Seq.Base.length b = 8} -> FStar.UInt64.t
Prims.Tot
[ "total" ]
[]
[ "FStar.Krml.Endianness.bytes", "Prims.b2t", "Prims.op_Equality", "Prims.int", "FStar.Seq.Base.length", "FStar.UInt8.t", "FStar.UInt64.uint_to_t", "Prims.unit", "FStar.Krml.Endianness.lemma_le_to_n_is_bounded", "Prims.nat", "FStar.Krml.Endianness.le_to_n", "FStar.UInt64.t" ]
[]
false
false
false
false
false
let uint64_of_le (b: bytes{S.length b = 8}) =
let n = le_to_n b in lemma_le_to_n_is_bounded b; UInt64.uint_to_t n
false
FStar.Krml.Endianness.fst
FStar.Krml.Endianness.le_of_uint64
val le_of_uint64 (x: UInt64.t) : b: bytes{S.length b = 8}
val le_of_uint64 (x: UInt64.t) : b: bytes{S.length b = 8}
let le_of_uint64 (x: UInt64.t): b:bytes{ S.length b = 8 } = n_to_le 8ul (UInt64.v x)
{ "file_name": "krmllib/FStar.Krml.Endianness.fst", "git_rev": "da1e941b2fcb196aa5d1e34941aa00b4c67ac321", "git_url": "https://github.com/FStarLang/karamel.git", "project_name": "karamel" }
{ "end_col": 26, "end_line": 224, "start_col": 0, "start_line": 223 }
module FStar.Krml.Endianness open FStar.Mul open FStar.HyperStack.All module U8 = FStar.UInt8 module U32 = FStar.UInt32 module U64 = FStar.UInt64 module Math = FStar.Math.Lemmas module S = FStar.Seq (* Selectively imported from Hacl*'s FStar.Endianness.fst library, with several name changes *) inline_for_extraction noextract type bytes = S.seq U8.t /// lt_to_n interprets a byte sequence as a little-endian natural number [@(deprecated "FStar.Endianness.le_to_n")] val le_to_n : b:bytes -> Tot nat (decreases (S.length b)) let rec le_to_n b = if S.length b = 0 then 0 else U8.v (S.head b) + pow2 8 * le_to_n (S.tail b) /// be_to_n interprets a byte sequence as a big-endian natural number [@(deprecated "FStar.Endianness.be_to_n")] val be_to_n : b:bytes -> Tot nat (decreases (S.length b)) let rec be_to_n b = if S.length b = 0 then 0 else U8.v (S.last b) + pow2 8 * be_to_n (S.slice b 0 (S.length b - 1)) [@(deprecated "FStar.Endianness.lemma_euclidean_division")] private val lemma_euclidean_division: r:nat -> b:nat -> q:pos -> Lemma (requires (r < q)) (ensures (r + q * b < q * (b+1))) let lemma_euclidean_division r b q = () [@(deprecated "FStar.Endianness.lemma_factorise")] private val lemma_factorise: a:nat -> b:nat -> Lemma (a + a * b == a * (b + 1)) let lemma_factorise a b = () [@(deprecated "FStar.Endianness.lemma_le_to_n_is_bounded")] val lemma_le_to_n_is_bounded: b:bytes -> Lemma (requires True) (ensures (le_to_n b < pow2 (8 * Seq.length b))) (decreases (Seq.length b)) let rec lemma_le_to_n_is_bounded b = if Seq.length b = 0 then () else begin let s = Seq.slice b 1 (Seq.length b) in assert(Seq.length s = Seq.length b - 1); lemma_le_to_n_is_bounded s; assert(UInt8.v (Seq.index b 0) < pow2 8); assert(le_to_n s < pow2 (8 * Seq.length s)); assert(le_to_n b < pow2 8 + pow2 8 * pow2 (8 * (Seq.length b - 1))); lemma_euclidean_division (UInt8.v (Seq.index b 0)) (le_to_n s) (pow2 8); assert(le_to_n b <= pow2 8 * (le_to_n s + 1)); assert(le_to_n b <= pow2 8 * pow2 (8 * (Seq.length b - 1))); Math.Lemmas.pow2_plus 8 (8 * (Seq.length b - 1)); lemma_factorise 8 (Seq.length b - 1) end [@(deprecated "FStar.Endianness.lemma_be_to_n_is_bounded")] val lemma_be_to_n_is_bounded: b:bytes -> Lemma (requires True) (ensures (be_to_n b < pow2 (8 * Seq.length b))) (decreases (Seq.length b)) let rec lemma_be_to_n_is_bounded b = if Seq.length b = 0 then () else begin let s = Seq.slice b 0 (Seq.length b - 1) in assert(Seq.length s = Seq.length b - 1); lemma_be_to_n_is_bounded s; assert(UInt8.v (Seq.last b) < pow2 8); assert(be_to_n s < pow2 (8 * Seq.length s)); assert(be_to_n b < pow2 8 + pow2 8 * pow2 (8 * (Seq.length b - 1))); lemma_euclidean_division (UInt8.v (Seq.last b)) (be_to_n s) (pow2 8); assert(be_to_n b <= pow2 8 * (be_to_n s + 1)); assert(be_to_n b <= pow2 8 * pow2 (8 * (Seq.length b - 1))); Math.Lemmas.pow2_plus 8 (8 * (Seq.length b - 1)); lemma_factorise 8 (Seq.length b - 1) end /// n_to_le encodes a number as a little-endian byte sequence of a fixed, /// sufficiently large length [@(deprecated "FStar.Endianness.n_to_le")] val n_to_le : len:U32.t -> n:nat{n < pow2 (8 * U32.v len)} -> Tot (b:bytes{S.length b == U32.v len /\ n == le_to_n b}) (decreases (U32.v len)) let rec n_to_le len n = if len = 0ul then S.empty else let len = U32.(len -^ 1ul) in let byte = U8.uint_to_t (n % 256) in let n' = n / 256 in Math.pow2_plus 8 (8 * U32.v len); assert(n' < pow2 (8 * U32.v len )); let b' = n_to_le len n' in let b = S.cons byte b' in S.lemma_eq_intro b' (S.tail b); b /// n_to_be encodes a numbers as a big-endian byte sequence of a fixed, /// sufficiently large length [@(deprecated "FStar.Endianness.n_to_be")] val n_to_be: len:U32.t -> n:nat{n < pow2 (8 * U32.v len)} -> Tot (b:bytes{S.length b == U32.v len /\ n == be_to_n b}) (decreases (U32.v len)) let rec n_to_be len n = if len = 0ul then S.empty else let len = U32.(len -^ 1ul) in let byte = U8.uint_to_t (n % 256) in let n' = n / 256 in Math.pow2_plus 8 (8 * U32.v len); assert(n' < pow2 (8 * U32.v len )); let b' = n_to_be len n' in let b'' = S.create 1 byte in let b = S.append b' b'' in S.lemma_eq_intro b' (S.slice b 0 (U32.v len)); b [@(deprecated "FStar.Endianness.n_to_le_inj")] let n_to_le_inj (len:U32.t) (n1 n2: (n:nat{n < pow2 (8 * U32.v len)})) : Lemma (requires (n_to_le len n1 == n_to_le len n2)) (ensures (n1 == n2)) = // this lemma easily follows from le_to_n . (n_to_le len) == id, the inversion // proof in the spec for n_to_le () [@(deprecated "FStar.Endianness.n_to_be_inj")] let n_to_be_inj (len:U32.t) (n1 n2: (n:nat{n < pow2 (8 * U32.v len)})) : Lemma (requires (n_to_be len n1 == n_to_be len n2)) (ensures (n1 == n2)) = () [@(deprecated "FStar.Endianness.be_to_n_inj")] let rec be_to_n_inj (b1 b2: Seq.seq U8.t) : Lemma (requires (Seq.length b1 == Seq.length b2 /\ be_to_n b1 == be_to_n b2)) (ensures (Seq.equal b1 b2)) (decreases (Seq.length b1)) = if Seq.length b1 = 0 then () else begin be_to_n_inj (Seq.slice b1 0 (Seq.length b1 - 1)) (Seq.slice b2 0 (Seq.length b2 - 1)); Seq.lemma_split b1 (Seq.length b1 - 1); Seq.lemma_split b2 (Seq.length b2 - 1) end [@(deprecated "FStar.Endianness.le_to_n_inj")] let rec le_to_n_inj (b1 b2: Seq.seq U8.t) : Lemma (requires (Seq.length b1 == Seq.length b2 /\ le_to_n b1 == le_to_n b2)) (ensures (Seq.equal b1 b2)) (decreases (Seq.length b1)) = if Seq.length b1 = 0 then () else begin le_to_n_inj (Seq.slice b1 1 (Seq.length b1)) (Seq.slice b2 1 (Seq.length b2)); Seq.lemma_split b1 1; Seq.lemma_split b2 1 end [@(deprecated "FStar.Endianness.n_to_be_be_to_n")] let n_to_be_be_to_n (len: U32.t) (s: Seq.seq U8.t) : Lemma (requires (Seq.length s == U32.v len)) (ensures ( be_to_n s < pow2 (8 `Prims.op_Multiply` U32.v len) /\ n_to_be len (be_to_n s) == s )) [SMTPat (n_to_be len (be_to_n s))] = lemma_be_to_n_is_bounded s; be_to_n_inj s (n_to_be len (be_to_n s)) [@(deprecated "FStar.Endianness.n_to_le_le_to_n")] let n_to_le_le_to_n (len: U32.t) (s: Seq.seq U8.t) : Lemma (requires (Seq.length s == U32.v len)) (ensures ( le_to_n s < pow2 (8 `Prims.op_Multiply` U32.v len) /\ n_to_le len (le_to_n s) == s )) [SMTPat (n_to_le len (le_to_n s))] = lemma_le_to_n_is_bounded s; le_to_n_inj s (n_to_le len (le_to_n s)) (** A series of specializations to deal with machine integers *) [@(deprecated "FStar.Endianness.uint32_of_le")] let uint32_of_le (b: bytes { S.length b = 4 }) = let n = le_to_n b in lemma_le_to_n_is_bounded b; UInt32.uint_to_t n [@(deprecated "FStar.Endianness.le_of_uint32")] let le_of_uint32 (x: UInt32.t): b:bytes{ S.length b = 4 } = n_to_le 4ul (UInt32.v x) [@(deprecated "FStar.Endianness.uint32_of_be")] let uint32_of_be (b: bytes { S.length b = 4 }) = let n = be_to_n b in lemma_be_to_n_is_bounded b; UInt32.uint_to_t n [@(deprecated "FStar.Endianness.be_of_uint32")] let be_of_uint32 (x: UInt32.t): b:bytes{ S.length b = 4 } = n_to_be 4ul (UInt32.v x) [@(deprecated "FStar.Endianness.uint64_of_le")] let uint64_of_le (b: bytes { S.length b = 8 }) = let n = le_to_n b in lemma_le_to_n_is_bounded b; UInt64.uint_to_t n
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.All.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "FStar.Krml.Endianness.fst" }
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Math.Lemmas", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Krml", "short_module": null }, { "abbrev": false, "full_module": "FStar.Krml", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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: FStar.UInt64.t -> b: FStar.Krml.Endianness.bytes{FStar.Seq.Base.length b = 8}
Prims.Tot
[ "total" ]
[]
[ "FStar.UInt64.t", "FStar.Krml.Endianness.n_to_le", "FStar.UInt32.__uint_to_t", "FStar.UInt64.v", "FStar.Krml.Endianness.bytes", "Prims.b2t", "Prims.op_Equality", "Prims.int", "FStar.Seq.Base.length", "FStar.UInt8.t" ]
[]
false
false
false
false
false
let le_of_uint64 (x: UInt64.t) : b: bytes{S.length b = 8} =
n_to_le 8ul (UInt64.v x)
false
Steel.ST.HigherArray.fst
Steel.ST.HigherArray.intro_pts_to
val intro_pts_to (#opened: _) (#elt: Type u#1) (a: array elt) (#v: _) (p: P.perm) (s: Seq.seq elt) : STGhost unit opened (R.pts_to (ptr_of a).base v) (fun _ -> pts_to a p s) (v == mk_carrier (US.v (ptr_of a).base_len) (ptr_of a).offset s p /\ valid_perm (US.v (ptr_of a).base_len) (ptr_of a).offset (Seq.length s) p /\ Seq.length s == length a) (fun _ -> True)
val intro_pts_to (#opened: _) (#elt: Type u#1) (a: array elt) (#v: _) (p: P.perm) (s: Seq.seq elt) : STGhost unit opened (R.pts_to (ptr_of a).base v) (fun _ -> pts_to a p s) (v == mk_carrier (US.v (ptr_of a).base_len) (ptr_of a).offset s p /\ valid_perm (US.v (ptr_of a).base_len) (ptr_of a).offset (Seq.length s) p /\ Seq.length s == length a) (fun _ -> True)
let intro_pts_to (#opened: _) (#elt: Type u#1) (a: array elt) (#v: _) (p: P.perm) (s: Seq.seq elt) : STGhost unit opened (R.pts_to (ptr_of a).base v) (fun _ -> pts_to a p s) ( v == mk_carrier (US.v (ptr_of a).base_len) (ptr_of a).offset s p /\ valid_perm (US.v (ptr_of a).base_len) (ptr_of a).offset (Seq.length s) p /\ Seq.length s == length a ) (fun _ -> True) = change_r_pts_to (ptr_of a).base v (ptr_of a).base (mk_carrier (US.v (ptr_of a).base_len) (ptr_of a).offset s p); intro_pure _; rewrite (pts_to0 a p s) (pts_to a p s)
{ "file_name": "lib/steel/Steel.ST.HigherArray.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 18, "end_line": 165, "start_col": 0, "start_line": 152 }
(* Copyright 2022 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.ST.HigherArray module P = Steel.PCMFrac module R = Steel.ST.PCMReference module M = FStar.Map module PM = Steel.PCMMap [@@noextract_to "krml"] let index_t (len: Ghost.erased nat) : Tot Type0 = (i: nat { i < len }) [@@noextract_to "krml"] let carrier (elt: Type u#a) (len: Ghost.erased nat) : Tot Type = PM.map (index_t len) (P.fractional elt) [@@noextract_to "krml"] let pcm (elt: Type u#a) (len: Ghost.erased nat) : Tot (P.pcm (carrier elt len)) = PM.pointwise (index_t len) (P.pcm_frac #elt) [@@noextract_to "krml"] let one (#elt: Type) (#len: Ghost.erased nat) = (pcm elt len).P.p.P.one let composable (#elt: Type) (#len: Ghost.erased nat) = (pcm elt len).P.p.P.composable [@@noextract_to "krml"] let compose (#elt: Type) (#len: Ghost.erased nat) = (pcm elt len).P.p.P.op [@@noextract_to "krml"] let mk_carrier (#elt: Type) (len: nat) (offset: nat) (s: Seq.seq elt) (p: P.perm) : Tot (carrier elt len) = let f (i: nat) : Tot (P.fractional elt) = if offset + Seq.length s > len || i < offset || i >= offset + Seq.length s then None else Some (Seq.index s (i - offset), p) in M.map_literal f let mk_carrier_inj (#elt: Type) (len: nat) (offset: nat) (s1 s2: Seq.seq elt) (p1 p2: P.perm) : Lemma (requires ( mk_carrier len offset s1 p1 == mk_carrier len offset s2 p2 /\ offset + Seq.length s1 <= len /\ offset + Seq.length s2 <= len )) (ensures ( s1 `Seq.equal` s2 /\ (Seq.length s1 > 0 ==> p1 == p2) )) = assert (forall (i: nat) . i < Seq.length s1 ==> (M.sel (mk_carrier len offset s1 p1) (offset + i) == Some (Seq.index s1 i, p1))); assert (forall (i: nat) . i < Seq.length s2 ==> M.sel (mk_carrier len offset s2 p2) (offset + i) == Some (Seq.index s2 i, p2)) [@@erasable] let base_t (elt: Type u#a) : Tot Type0 = Ghost.erased (base_len: US.t & ref _ (pcm elt (US.v base_len))) let base_len (#elt: Type) (b: base_t elt) : GTot nat = US.v (dfst b) [@@noextract_to "krml"] noeq type ptr (elt: Type u#a) : Type0 = { base_len: Ghost.erased US.t; // U32.t to prove that A.read, A.write offset computation does not overflow. TODO: replace U32.t with size_t base: (r: ref _ (pcm elt (US.v base_len)) { core_ref_is_null r ==> US.v base_len == 0 }); offset: (offset: nat { offset <= US.v base_len }); } let null_ptr a = { base_len = 0sz; base = null #_ #(pcm a 0) ; offset = 0 } let is_null_ptr p = is_null p.base let base (#elt: Type) (p: ptr elt) : Tot (base_t elt) = (| Ghost.reveal p.base_len, p.base |) let offset (#elt: Type) (p: ptr elt) : Ghost nat (requires True) (ensures (fun offset -> offset <= base_len (base p))) = p.offset let ptr_base_offset_inj (#elt: Type) (p1 p2: ptr elt) : Lemma (requires ( base p1 == base p2 /\ offset p1 == offset p2 )) (ensures ( p1 == p2 )) = () let base_len_null_ptr _ = () let length_fits #elt a = () let valid_perm (len: nat) (offset: nat) (slice_len: nat) (p: P.perm) : Tot prop = let open FStar.Real in ((offset + slice_len <= len /\ slice_len > 0) ==> (p.P.v <=. one)) [@__reduce__] let pts_to0 (#elt: Type u#1) (a: array elt) (p: P.perm) (s: Seq.seq elt) : Tot vprop = R.pts_to (ptr_of a).base (mk_carrier (US.v (ptr_of a).base_len) (ptr_of a).offset s p) `star` pure ( valid_perm (US.v (ptr_of a).base_len) (ptr_of a).offset (Seq.length s) p /\ Seq.length s == length a ) let pts_to (#elt: Type u#1) (a: array elt) ([@@@ smt_fallback ] p: P.perm) ([@@@ smt_fallback ] s: Seq.seq elt) : Tot vprop = pts_to0 a p s // this lemma is necessary because Steel.PCMReference is marked unfold let change_r_pts_to (#opened: _) (#carrier: Type u#1) (#pcm: P.pcm carrier) (p: ref carrier pcm) (v: carrier) (#carrier': Type u#1) (#pcm': P.pcm carrier') (p': ref carrier' pcm') (v': carrier') : STGhost unit opened (R.pts_to p v) (fun _ -> R.pts_to p' v') (// keep on distinct lines for error messages carrier == carrier' /\ pcm == pcm' /\ p == p' /\ v == v') (fun _ -> True) = rewrite (R.pts_to p v) (R.pts_to p' v')
{ "checked_file": "/", "dependencies": [ "Steel.ST.PCMReference.fsti.checked", "Steel.ST.Loops.fsti.checked", "Steel.PCMMap.fst.checked", "Steel.PCMFrac.fst.checked", "Steel.Memory.fsti.checked", "prims.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Real.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Map.fsti.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Steel.ST.HigherArray.fst" }
[ { "abbrev": true, "full_module": "Steel.PCMMap", "short_module": "PM" }, { "abbrev": true, "full_module": "FStar.Map", "short_module": "M" }, { "abbrev": true, "full_module": "Steel.ST.PCMReference", "short_module": "R" }, { "abbrev": true, "full_module": "Steel.PCMFrac", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.ST.Util", "short_module": null }, { "abbrev": true, "full_module": "FStar.PtrdiffT", "short_module": "UP" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "US" }, { "abbrev": true, "full_module": "Steel.FractionalPermission", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Steel.ST.HigherArray.array elt -> p: Steel.FractionalPermission.perm -> s: FStar.Seq.Base.seq elt -> Steel.ST.Effect.Ghost.STGhost Prims.unit
Steel.ST.Effect.Ghost.STGhost
[]
[]
[ "Steel.Memory.inames", "Steel.ST.HigherArray.array", "Steel.ST.HigherArray.carrier", "FStar.Ghost.hide", "Prims.nat", "FStar.SizeT.v", "FStar.Ghost.reveal", "FStar.SizeT.t", "Steel.ST.HigherArray.__proj__Mkptr__item__base_len", "Steel.ST.HigherArray.ptr_of", "Steel.FractionalPermission.perm", "FStar.Seq.Base.seq", "Steel.ST.Util.rewrite", "Steel.ST.HigherArray.pts_to0", "Steel.ST.HigherArray.pts_to", "Prims.unit", "Steel.ST.Util.intro_pure", "Prims.l_and", "Steel.ST.HigherArray.valid_perm", "Steel.ST.HigherArray.__proj__Mkptr__item__offset", "FStar.Seq.Base.length", "Prims.eq2", "Steel.ST.HigherArray.length", "Steel.ST.HigherArray.change_r_pts_to", "Steel.ST.HigherArray.pcm", "Steel.ST.HigherArray.__proj__Mkptr__item__base", "Steel.ST.HigherArray.mk_carrier", "Steel.ST.PCMReference.pts_to", "Steel.Effect.Common.vprop", "Prims.l_True" ]
[]
false
true
false
false
false
let intro_pts_to (#opened: _) (#elt: Type u#1) (a: array elt) (#v: _) (p: P.perm) (s: Seq.seq elt) : STGhost unit opened (R.pts_to (ptr_of a).base v) (fun _ -> pts_to a p s) (v == mk_carrier (US.v (ptr_of a).base_len) (ptr_of a).offset s p /\ valid_perm (US.v (ptr_of a).base_len) (ptr_of a).offset (Seq.length s) p /\ Seq.length s == length a) (fun _ -> True) =
change_r_pts_to (ptr_of a).base v (ptr_of a).base (mk_carrier (US.v (ptr_of a).base_len) (ptr_of a).offset s p); intro_pure _; rewrite (pts_to0 a p s) (pts_to a p s)
false
Vale.AES.X64.GF128_Init.fsti
Vale.AES.X64.GF128_Init.va_req_Keyhash_init
val va_req_Keyhash_init (va_b0: va_code) (va_s0: va_state) (win: bool) (alg: algorithm) (key: (seq nat32)) (roundkeys_b hkeys_b: buffer128) : prop
val va_req_Keyhash_init (va_b0: va_code) (va_s0: va_state) (win: bool) (alg: algorithm) (key: (seq nat32)) (roundkeys_b hkeys_b: buffer128) : prop
let va_req_Keyhash_init (va_b0:va_code) (va_s0:va_state) (win:bool) (alg:algorithm) (key:(seq nat32)) (roundkeys_b:buffer128) (hkeys_b:buffer128) : prop = (va_require_total va_b0 (va_code_Keyhash_init win alg) va_s0 /\ va_get_ok va_s0 /\ (let (round_ptr:(va_int_range 0 18446744073709551615)) = (if win then va_get_reg64 rRcx va_s0 else va_get_reg64 rRdi va_s0) in let (hkey_ptr:(va_int_range 0 18446744073709551615)) = (if win then va_get_reg64 rRdx va_s0 else va_get_reg64 rRsi va_s0) in Vale.X64.Memory.is_initial_heap (va_get_mem_layout va_s0) (va_get_mem va_s0) /\ (aesni_enabled /\ pclmulqdq_enabled /\ avx_enabled /\ sse_enabled) /\ (alg = AES_128 \/ alg = AES_256) /\ Vale.X64.Decls.buffers_disjoint128 roundkeys_b hkeys_b /\ Vale.AES.AES_s.is_aes_key_LE alg key /\ Vale.X64.Decls.buffer128_as_seq (va_get_mem va_s0) roundkeys_b == Vale.AES.AES_s.key_to_round_keys_LE alg key /\ Vale.X64.Decls.validSrcAddrs128 (va_get_mem va_s0) round_ptr roundkeys_b (Vale.AES.AES_common_s.nr alg + 1) (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validDstAddrs128 (va_get_mem va_s0) hkey_ptr hkeys_b 8 (va_get_mem_layout va_s0) Secret))
{ "file_name": "obj/Vale.AES.X64.GF128_Init.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 38, "end_line": 52, "start_col": 0, "start_line": 39 }
module Vale.AES.X64.GF128_Init open Vale.Def.Words_s open Vale.Def.Words.Four_s open Vale.Def.Types_s open FStar.Seq open Vale.Arch.Types open Vale.Arch.HeapImpl open Vale.Math.Poly2_s open Vale.Math.Poly2 open Vale.Math.Poly2.Bits_s open Vale.Math.Poly2.Bits open Vale.Math.Poly2.Lemmas open Vale.AES.GF128_s open Vale.AES.GF128 open Vale.AES.GHash open Vale.AES.AES_s open Vale.AES.AES256_helpers open Vale.AES.X64.AES open Vale.X64.Machine_s open Vale.X64.Memory open Vale.X64.State open Vale.X64.Decls open Vale.X64.InsBasic open Vale.X64.InsMem open Vale.X64.InsVector open Vale.X64.InsAes open Vale.X64.QuickCode open Vale.X64.QuickCodes open Vale.X64.CPU_Features_s open Vale.AES.X64.PolyOps open Vale.AES.X64.GF128_Mul open Vale.AES.GHash open Vale.AES.OptPublic //-- Keyhash_init val va_code_Keyhash_init : win:bool -> alg:algorithm -> Tot va_code
{ "checked_file": "/", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.QuickCodes.fsti.checked", "Vale.X64.QuickCode.fst.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.InsVector.fsti.checked", "Vale.X64.InsMem.fsti.checked", "Vale.X64.InsBasic.fsti.checked", "Vale.X64.InsAes.fsti.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Decls.fsti.checked", "Vale.X64.CPU_Features_s.fst.checked", "Vale.Math.Poly2_s.fsti.checked", "Vale.Math.Poly2.Lemmas.fsti.checked", "Vale.Math.Poly2.Bits_s.fsti.checked", "Vale.Math.Poly2.Bits.fsti.checked", "Vale.Math.Poly2.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Arch.Types.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "Vale.AES.X64.PolyOps.fsti.checked", "Vale.AES.X64.GF128_Mul.fsti.checked", "Vale.AES.X64.AES.fsti.checked", "Vale.AES.OptPublic.fsti.checked", "Vale.AES.GHash.fsti.checked", "Vale.AES.GF128_s.fsti.checked", "Vale.AES.GF128.fsti.checked", "Vale.AES.AES_s.fst.checked", "Vale.AES.AES_common_s.fst.checked", "Vale.AES.AES256_helpers.fsti.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Vale.AES.X64.GF128_Init.fsti" }
[ { "abbrev": false, "full_module": "Vale.AES.OptPublic", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.X64.GF128_Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.X64.PolyOps", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.CPU_Features_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCodes", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsAes", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsVector", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsMem", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsBasic", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.X64.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES256_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
va_b0: Vale.X64.Decls.va_code -> va_s0: Vale.X64.Decls.va_state -> win: Prims.bool -> alg: Vale.AES.AES_common_s.algorithm -> key: FStar.Seq.Base.seq Vale.X64.Memory.nat32 -> roundkeys_b: Vale.X64.Memory.buffer128 -> hkeys_b: Vale.X64.Memory.buffer128 -> Prims.prop
Prims.Tot
[ "total" ]
[]
[ "Vale.X64.Decls.va_code", "Vale.X64.Decls.va_state", "Prims.bool", "Vale.AES.AES_common_s.algorithm", "FStar.Seq.Base.seq", "Vale.X64.Memory.nat32", "Vale.X64.Memory.buffer128", "Prims.l_and", "Vale.X64.Decls.va_require_total", "Vale.AES.X64.GF128_Init.va_code_Keyhash_init", "Prims.b2t", "Vale.X64.Decls.va_get_ok", "Vale.X64.Memory.is_initial_heap", "Vale.X64.Decls.va_get_mem_layout", "Vale.X64.Decls.va_get_mem", "Vale.X64.CPU_Features_s.aesni_enabled", "Vale.X64.CPU_Features_s.pclmulqdq_enabled", "Vale.X64.CPU_Features_s.avx_enabled", "Vale.X64.CPU_Features_s.sse_enabled", "Prims.l_or", "Prims.op_Equality", "Vale.AES.AES_common_s.AES_128", "Vale.AES.AES_common_s.AES_256", "Vale.X64.Decls.buffers_disjoint128", "Vale.AES.AES_s.is_aes_key_LE", "Prims.eq2", "Vale.Def.Types_s.quad32", "Vale.X64.Decls.buffer128_as_seq", "Vale.AES.AES_s.key_to_round_keys_LE", "Vale.X64.Decls.validSrcAddrs128", "Prims.op_Addition", "Vale.AES.AES_common_s.nr", "Vale.Arch.HeapTypes_s.Secret", "Vale.X64.Decls.validDstAddrs128", "Vale.X64.Decls.va_int_range", "Vale.X64.Decls.va_get_reg64", "Vale.X64.Machine_s.rRdx", "Vale.X64.Machine_s.rRsi", "Vale.X64.Machine_s.rRcx", "Vale.X64.Machine_s.rRdi", "Prims.prop" ]
[]
false
false
false
true
true
let va_req_Keyhash_init (va_b0: va_code) (va_s0: va_state) (win: bool) (alg: algorithm) (key: (seq nat32)) (roundkeys_b hkeys_b: buffer128) : prop =
(va_require_total va_b0 (va_code_Keyhash_init win alg) va_s0 /\ va_get_ok va_s0 /\ (let round_ptr:(va_int_range 0 18446744073709551615) = (if win then va_get_reg64 rRcx va_s0 else va_get_reg64 rRdi va_s0) in let hkey_ptr:(va_int_range 0 18446744073709551615) = (if win then va_get_reg64 rRdx va_s0 else va_get_reg64 rRsi va_s0) in Vale.X64.Memory.is_initial_heap (va_get_mem_layout va_s0) (va_get_mem va_s0) /\ (aesni_enabled /\ pclmulqdq_enabled /\ avx_enabled /\ sse_enabled) /\ (alg = AES_128 \/ alg = AES_256) /\ Vale.X64.Decls.buffers_disjoint128 roundkeys_b hkeys_b /\ Vale.AES.AES_s.is_aes_key_LE alg key /\ Vale.X64.Decls.buffer128_as_seq (va_get_mem va_s0) roundkeys_b == Vale.AES.AES_s.key_to_round_keys_LE alg key /\ Vale.X64.Decls.validSrcAddrs128 (va_get_mem va_s0) round_ptr roundkeys_b (Vale.AES.AES_common_s.nr alg + 1) (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validDstAddrs128 (va_get_mem va_s0) hkey_ptr hkeys_b 8 (va_get_mem_layout va_s0) Secret))
false
FStar.Krml.Endianness.fst
FStar.Krml.Endianness.n_to_le
val n_to_le : len:U32.t -> n:nat{n < pow2 (8 * U32.v len)} -> Tot (b:bytes{S.length b == U32.v len /\ n == le_to_n b}) (decreases (U32.v len))
val n_to_le : len:U32.t -> n:nat{n < pow2 (8 * U32.v len)} -> Tot (b:bytes{S.length b == U32.v len /\ n == le_to_n b}) (decreases (U32.v len))
let rec n_to_le len n = if len = 0ul then S.empty else let len = U32.(len -^ 1ul) in let byte = U8.uint_to_t (n % 256) in let n' = n / 256 in Math.pow2_plus 8 (8 * U32.v len); assert(n' < pow2 (8 * U32.v len )); let b' = n_to_le len n' in let b = S.cons byte b' in S.lemma_eq_intro b' (S.tail b); b
{ "file_name": "krmllib/FStar.Krml.Endianness.fst", "git_rev": "da1e941b2fcb196aa5d1e34941aa00b4c67ac321", "git_url": "https://github.com/FStarLang/karamel.git", "project_name": "karamel" }
{ "end_col": 5, "end_line": 104, "start_col": 0, "start_line": 92 }
module FStar.Krml.Endianness open FStar.Mul open FStar.HyperStack.All module U8 = FStar.UInt8 module U32 = FStar.UInt32 module U64 = FStar.UInt64 module Math = FStar.Math.Lemmas module S = FStar.Seq (* Selectively imported from Hacl*'s FStar.Endianness.fst library, with several name changes *) inline_for_extraction noextract type bytes = S.seq U8.t /// lt_to_n interprets a byte sequence as a little-endian natural number [@(deprecated "FStar.Endianness.le_to_n")] val le_to_n : b:bytes -> Tot nat (decreases (S.length b)) let rec le_to_n b = if S.length b = 0 then 0 else U8.v (S.head b) + pow2 8 * le_to_n (S.tail b) /// be_to_n interprets a byte sequence as a big-endian natural number [@(deprecated "FStar.Endianness.be_to_n")] val be_to_n : b:bytes -> Tot nat (decreases (S.length b)) let rec be_to_n b = if S.length b = 0 then 0 else U8.v (S.last b) + pow2 8 * be_to_n (S.slice b 0 (S.length b - 1)) [@(deprecated "FStar.Endianness.lemma_euclidean_division")] private val lemma_euclidean_division: r:nat -> b:nat -> q:pos -> Lemma (requires (r < q)) (ensures (r + q * b < q * (b+1))) let lemma_euclidean_division r b q = () [@(deprecated "FStar.Endianness.lemma_factorise")] private val lemma_factorise: a:nat -> b:nat -> Lemma (a + a * b == a * (b + 1)) let lemma_factorise a b = () [@(deprecated "FStar.Endianness.lemma_le_to_n_is_bounded")] val lemma_le_to_n_is_bounded: b:bytes -> Lemma (requires True) (ensures (le_to_n b < pow2 (8 * Seq.length b))) (decreases (Seq.length b)) let rec lemma_le_to_n_is_bounded b = if Seq.length b = 0 then () else begin let s = Seq.slice b 1 (Seq.length b) in assert(Seq.length s = Seq.length b - 1); lemma_le_to_n_is_bounded s; assert(UInt8.v (Seq.index b 0) < pow2 8); assert(le_to_n s < pow2 (8 * Seq.length s)); assert(le_to_n b < pow2 8 + pow2 8 * pow2 (8 * (Seq.length b - 1))); lemma_euclidean_division (UInt8.v (Seq.index b 0)) (le_to_n s) (pow2 8); assert(le_to_n b <= pow2 8 * (le_to_n s + 1)); assert(le_to_n b <= pow2 8 * pow2 (8 * (Seq.length b - 1))); Math.Lemmas.pow2_plus 8 (8 * (Seq.length b - 1)); lemma_factorise 8 (Seq.length b - 1) end [@(deprecated "FStar.Endianness.lemma_be_to_n_is_bounded")] val lemma_be_to_n_is_bounded: b:bytes -> Lemma (requires True) (ensures (be_to_n b < pow2 (8 * Seq.length b))) (decreases (Seq.length b)) let rec lemma_be_to_n_is_bounded b = if Seq.length b = 0 then () else begin let s = Seq.slice b 0 (Seq.length b - 1) in assert(Seq.length s = Seq.length b - 1); lemma_be_to_n_is_bounded s; assert(UInt8.v (Seq.last b) < pow2 8); assert(be_to_n s < pow2 (8 * Seq.length s)); assert(be_to_n b < pow2 8 + pow2 8 * pow2 (8 * (Seq.length b - 1))); lemma_euclidean_division (UInt8.v (Seq.last b)) (be_to_n s) (pow2 8); assert(be_to_n b <= pow2 8 * (be_to_n s + 1)); assert(be_to_n b <= pow2 8 * pow2 (8 * (Seq.length b - 1))); Math.Lemmas.pow2_plus 8 (8 * (Seq.length b - 1)); lemma_factorise 8 (Seq.length b - 1) end /// n_to_le encodes a number as a little-endian byte sequence of a fixed, /// sufficiently large length [@(deprecated "FStar.Endianness.n_to_le")] val n_to_le : len:U32.t -> n:nat{n < pow2 (8 * U32.v len)} -> Tot (b:bytes{S.length b == U32.v len /\ n == le_to_n b})
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.All.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "FStar.Krml.Endianness.fst" }
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Math.Lemmas", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Krml", "short_module": null }, { "abbrev": false, "full_module": "FStar.Krml", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
len: FStar.UInt32.t -> n: Prims.nat{n < Prims.pow2 (8 * FStar.UInt32.v len)} -> Prims.Tot (b: FStar.Krml.Endianness.bytes {FStar.Seq.Base.length b == FStar.UInt32.v len /\ n == FStar.Krml.Endianness.le_to_n b})
Prims.Tot
[ "total", "" ]
[]
[ "FStar.UInt32.t", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Prims.pow2", "FStar.Mul.op_Star", "FStar.UInt32.v", "Prims.op_Equality", "FStar.UInt32.__uint_to_t", "FStar.Seq.Base.empty", "FStar.UInt8.t", "Prims.bool", "Prims.unit", "FStar.Seq.Base.lemma_eq_intro", "FStar.Seq.Properties.tail", "FStar.Seq.Base.seq", "FStar.Seq.Base.cons", "FStar.Krml.Endianness.bytes", "Prims.l_and", "Prims.eq2", "Prims.int", "Prims.l_or", "Prims.op_GreaterThanOrEqual", "FStar.UInt.size", "FStar.Seq.Base.length", "FStar.Krml.Endianness.le_to_n", "FStar.Krml.Endianness.n_to_le", "Prims._assert", "FStar.Math.Lemmas.pow2_plus", "Prims.op_Division", "FStar.UInt8.uint_to_t", "Prims.op_Modulus", "FStar.UInt32.op_Subtraction_Hat", "FStar.UInt32.n" ]
[ "recursion" ]
false
false
false
false
false
let rec n_to_le len n =
if len = 0ul then S.empty else let len = let open U32 in len -^ 1ul in let byte = U8.uint_to_t (n % 256) in let n' = n / 256 in Math.pow2_plus 8 (8 * U32.v len); assert (n' < pow2 (8 * U32.v len)); let b' = n_to_le len n' in let b = S.cons byte b' in S.lemma_eq_intro b' (S.tail b); b
false
FStar.Krml.Endianness.fst
FStar.Krml.Endianness.uint64_of_be
val uint64_of_be : b: FStar.Krml.Endianness.bytes{FStar.Seq.Base.length b = 8} -> FStar.UInt64.t
let uint64_of_be (b: bytes { S.length b = 8 }) = let n = be_to_n b in lemma_be_to_n_is_bounded b; UInt64.uint_to_t n
{ "file_name": "krmllib/FStar.Krml.Endianness.fst", "git_rev": "da1e941b2fcb196aa5d1e34941aa00b4c67ac321", "git_url": "https://github.com/FStarLang/karamel.git", "project_name": "karamel" }
{ "end_col": 20, "end_line": 230, "start_col": 0, "start_line": 227 }
module FStar.Krml.Endianness open FStar.Mul open FStar.HyperStack.All module U8 = FStar.UInt8 module U32 = FStar.UInt32 module U64 = FStar.UInt64 module Math = FStar.Math.Lemmas module S = FStar.Seq (* Selectively imported from Hacl*'s FStar.Endianness.fst library, with several name changes *) inline_for_extraction noextract type bytes = S.seq U8.t /// lt_to_n interprets a byte sequence as a little-endian natural number [@(deprecated "FStar.Endianness.le_to_n")] val le_to_n : b:bytes -> Tot nat (decreases (S.length b)) let rec le_to_n b = if S.length b = 0 then 0 else U8.v (S.head b) + pow2 8 * le_to_n (S.tail b) /// be_to_n interprets a byte sequence as a big-endian natural number [@(deprecated "FStar.Endianness.be_to_n")] val be_to_n : b:bytes -> Tot nat (decreases (S.length b)) let rec be_to_n b = if S.length b = 0 then 0 else U8.v (S.last b) + pow2 8 * be_to_n (S.slice b 0 (S.length b - 1)) [@(deprecated "FStar.Endianness.lemma_euclidean_division")] private val lemma_euclidean_division: r:nat -> b:nat -> q:pos -> Lemma (requires (r < q)) (ensures (r + q * b < q * (b+1))) let lemma_euclidean_division r b q = () [@(deprecated "FStar.Endianness.lemma_factorise")] private val lemma_factorise: a:nat -> b:nat -> Lemma (a + a * b == a * (b + 1)) let lemma_factorise a b = () [@(deprecated "FStar.Endianness.lemma_le_to_n_is_bounded")] val lemma_le_to_n_is_bounded: b:bytes -> Lemma (requires True) (ensures (le_to_n b < pow2 (8 * Seq.length b))) (decreases (Seq.length b)) let rec lemma_le_to_n_is_bounded b = if Seq.length b = 0 then () else begin let s = Seq.slice b 1 (Seq.length b) in assert(Seq.length s = Seq.length b - 1); lemma_le_to_n_is_bounded s; assert(UInt8.v (Seq.index b 0) < pow2 8); assert(le_to_n s < pow2 (8 * Seq.length s)); assert(le_to_n b < pow2 8 + pow2 8 * pow2 (8 * (Seq.length b - 1))); lemma_euclidean_division (UInt8.v (Seq.index b 0)) (le_to_n s) (pow2 8); assert(le_to_n b <= pow2 8 * (le_to_n s + 1)); assert(le_to_n b <= pow2 8 * pow2 (8 * (Seq.length b - 1))); Math.Lemmas.pow2_plus 8 (8 * (Seq.length b - 1)); lemma_factorise 8 (Seq.length b - 1) end [@(deprecated "FStar.Endianness.lemma_be_to_n_is_bounded")] val lemma_be_to_n_is_bounded: b:bytes -> Lemma (requires True) (ensures (be_to_n b < pow2 (8 * Seq.length b))) (decreases (Seq.length b)) let rec lemma_be_to_n_is_bounded b = if Seq.length b = 0 then () else begin let s = Seq.slice b 0 (Seq.length b - 1) in assert(Seq.length s = Seq.length b - 1); lemma_be_to_n_is_bounded s; assert(UInt8.v (Seq.last b) < pow2 8); assert(be_to_n s < pow2 (8 * Seq.length s)); assert(be_to_n b < pow2 8 + pow2 8 * pow2 (8 * (Seq.length b - 1))); lemma_euclidean_division (UInt8.v (Seq.last b)) (be_to_n s) (pow2 8); assert(be_to_n b <= pow2 8 * (be_to_n s + 1)); assert(be_to_n b <= pow2 8 * pow2 (8 * (Seq.length b - 1))); Math.Lemmas.pow2_plus 8 (8 * (Seq.length b - 1)); lemma_factorise 8 (Seq.length b - 1) end /// n_to_le encodes a number as a little-endian byte sequence of a fixed, /// sufficiently large length [@(deprecated "FStar.Endianness.n_to_le")] val n_to_le : len:U32.t -> n:nat{n < pow2 (8 * U32.v len)} -> Tot (b:bytes{S.length b == U32.v len /\ n == le_to_n b}) (decreases (U32.v len)) let rec n_to_le len n = if len = 0ul then S.empty else let len = U32.(len -^ 1ul) in let byte = U8.uint_to_t (n % 256) in let n' = n / 256 in Math.pow2_plus 8 (8 * U32.v len); assert(n' < pow2 (8 * U32.v len )); let b' = n_to_le len n' in let b = S.cons byte b' in S.lemma_eq_intro b' (S.tail b); b /// n_to_be encodes a numbers as a big-endian byte sequence of a fixed, /// sufficiently large length [@(deprecated "FStar.Endianness.n_to_be")] val n_to_be: len:U32.t -> n:nat{n < pow2 (8 * U32.v len)} -> Tot (b:bytes{S.length b == U32.v len /\ n == be_to_n b}) (decreases (U32.v len)) let rec n_to_be len n = if len = 0ul then S.empty else let len = U32.(len -^ 1ul) in let byte = U8.uint_to_t (n % 256) in let n' = n / 256 in Math.pow2_plus 8 (8 * U32.v len); assert(n' < pow2 (8 * U32.v len )); let b' = n_to_be len n' in let b'' = S.create 1 byte in let b = S.append b' b'' in S.lemma_eq_intro b' (S.slice b 0 (U32.v len)); b [@(deprecated "FStar.Endianness.n_to_le_inj")] let n_to_le_inj (len:U32.t) (n1 n2: (n:nat{n < pow2 (8 * U32.v len)})) : Lemma (requires (n_to_le len n1 == n_to_le len n2)) (ensures (n1 == n2)) = // this lemma easily follows from le_to_n . (n_to_le len) == id, the inversion // proof in the spec for n_to_le () [@(deprecated "FStar.Endianness.n_to_be_inj")] let n_to_be_inj (len:U32.t) (n1 n2: (n:nat{n < pow2 (8 * U32.v len)})) : Lemma (requires (n_to_be len n1 == n_to_be len n2)) (ensures (n1 == n2)) = () [@(deprecated "FStar.Endianness.be_to_n_inj")] let rec be_to_n_inj (b1 b2: Seq.seq U8.t) : Lemma (requires (Seq.length b1 == Seq.length b2 /\ be_to_n b1 == be_to_n b2)) (ensures (Seq.equal b1 b2)) (decreases (Seq.length b1)) = if Seq.length b1 = 0 then () else begin be_to_n_inj (Seq.slice b1 0 (Seq.length b1 - 1)) (Seq.slice b2 0 (Seq.length b2 - 1)); Seq.lemma_split b1 (Seq.length b1 - 1); Seq.lemma_split b2 (Seq.length b2 - 1) end [@(deprecated "FStar.Endianness.le_to_n_inj")] let rec le_to_n_inj (b1 b2: Seq.seq U8.t) : Lemma (requires (Seq.length b1 == Seq.length b2 /\ le_to_n b1 == le_to_n b2)) (ensures (Seq.equal b1 b2)) (decreases (Seq.length b1)) = if Seq.length b1 = 0 then () else begin le_to_n_inj (Seq.slice b1 1 (Seq.length b1)) (Seq.slice b2 1 (Seq.length b2)); Seq.lemma_split b1 1; Seq.lemma_split b2 1 end [@(deprecated "FStar.Endianness.n_to_be_be_to_n")] let n_to_be_be_to_n (len: U32.t) (s: Seq.seq U8.t) : Lemma (requires (Seq.length s == U32.v len)) (ensures ( be_to_n s < pow2 (8 `Prims.op_Multiply` U32.v len) /\ n_to_be len (be_to_n s) == s )) [SMTPat (n_to_be len (be_to_n s))] = lemma_be_to_n_is_bounded s; be_to_n_inj s (n_to_be len (be_to_n s)) [@(deprecated "FStar.Endianness.n_to_le_le_to_n")] let n_to_le_le_to_n (len: U32.t) (s: Seq.seq U8.t) : Lemma (requires (Seq.length s == U32.v len)) (ensures ( le_to_n s < pow2 (8 `Prims.op_Multiply` U32.v len) /\ n_to_le len (le_to_n s) == s )) [SMTPat (n_to_le len (le_to_n s))] = lemma_le_to_n_is_bounded s; le_to_n_inj s (n_to_le len (le_to_n s)) (** A series of specializations to deal with machine integers *) [@(deprecated "FStar.Endianness.uint32_of_le")] let uint32_of_le (b: bytes { S.length b = 4 }) = let n = le_to_n b in lemma_le_to_n_is_bounded b; UInt32.uint_to_t n [@(deprecated "FStar.Endianness.le_of_uint32")] let le_of_uint32 (x: UInt32.t): b:bytes{ S.length b = 4 } = n_to_le 4ul (UInt32.v x) [@(deprecated "FStar.Endianness.uint32_of_be")] let uint32_of_be (b: bytes { S.length b = 4 }) = let n = be_to_n b in lemma_be_to_n_is_bounded b; UInt32.uint_to_t n [@(deprecated "FStar.Endianness.be_of_uint32")] let be_of_uint32 (x: UInt32.t): b:bytes{ S.length b = 4 } = n_to_be 4ul (UInt32.v x) [@(deprecated "FStar.Endianness.uint64_of_le")] let uint64_of_le (b: bytes { S.length b = 8 }) = let n = le_to_n b in lemma_le_to_n_is_bounded b; UInt64.uint_to_t n [@(deprecated "FStar.Endianness.le_of_uint64")] let le_of_uint64 (x: UInt64.t): b:bytes{ S.length b = 8 } = n_to_le 8ul (UInt64.v x)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.All.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "FStar.Krml.Endianness.fst" }
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Math.Lemmas", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Krml", "short_module": null }, { "abbrev": false, "full_module": "FStar.Krml", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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: FStar.Krml.Endianness.bytes{FStar.Seq.Base.length b = 8} -> FStar.UInt64.t
Prims.Tot
[ "total" ]
[]
[ "FStar.Krml.Endianness.bytes", "Prims.b2t", "Prims.op_Equality", "Prims.int", "FStar.Seq.Base.length", "FStar.UInt8.t", "FStar.UInt64.uint_to_t", "Prims.unit", "FStar.Krml.Endianness.lemma_be_to_n_is_bounded", "Prims.nat", "FStar.Krml.Endianness.be_to_n", "FStar.UInt64.t" ]
[]
false
false
false
false
false
let uint64_of_be (b: bytes{S.length b = 8}) =
let n = be_to_n b in lemma_be_to_n_is_bounded b; UInt64.uint_to_t n
false
Hacl.Spec.Bignum.Multiplication.fst
Hacl.Spec.Bignum.Multiplication.bn_mul_lemma_
val bn_mul_lemma_: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat{aLen + bLen <= max_size_t} -> a:lbignum t aLen -> b:lbignum t bLen -> j:size_nat{j < bLen} -> acc:lbignum t (aLen + bLen) -> Lemma (let res = bn_mul_ a b j acc in v res.[aLen + j] * pow2 (bits t * (aLen + j)) + eval_ (aLen + bLen) res (aLen + j) == eval_ (aLen + bLen) acc (aLen + j) + bn_v a * v b.[j] * pow2 (bits t * j))
val bn_mul_lemma_: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat{aLen + bLen <= max_size_t} -> a:lbignum t aLen -> b:lbignum t bLen -> j:size_nat{j < bLen} -> acc:lbignum t (aLen + bLen) -> Lemma (let res = bn_mul_ a b j acc in v res.[aLen + j] * pow2 (bits t * (aLen + j)) + eval_ (aLen + bLen) res (aLen + j) == eval_ (aLen + bLen) acc (aLen + j) + bn_v a * v b.[j] * pow2 (bits t * j))
let bn_mul_lemma_ #t #aLen #bLen a b j acc = let c, res = bn_mul1_lshift_add a b.[j] j acc in bn_mul1_lshift_add_lemma a b.[j] j acc; let res1 = res.[aLen + j] <- c in bn_eval_extensionality_j res res1 (aLen + j)
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Multiplication.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 46, "end_line": 376, "start_col": 0, "start_line": 371 }
module Hacl.Spec.Bignum.Multiplication open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.LoopCombinators open Hacl.Spec.Bignum.Definitions open Hacl.Spec.Bignum.Base open Hacl.Spec.Lib #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" val bn_mul1_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> l:limb t -> i:size_nat{i < aLen} -> c:limb t -> limb t & limb t // carry & out let bn_mul1_f #t #aLen a l i c = mul_wide_add a.[i] l c val bn_mul1: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> l:limb t -> limb t & lbignum t aLen let bn_mul1 #t #aLen a l = generate_elems aLen aLen (bn_mul1_f a l) (uint #t 0) val bn_mul1_add_in_place_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> l:limb t -> acc:lbignum t aLen -> i:size_nat{i < aLen} -> c:limb t -> limb t & limb t // carry & out let bn_mul1_add_in_place_f #t #aLen a l acc i c = mul_wide_add2 a.[i] l c acc.[i] val bn_mul1_add_in_place: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> l:limb t -> acc:lbignum t aLen -> limb t & lbignum t aLen let bn_mul1_add_in_place #t #aLen a l acc = generate_elems aLen aLen (bn_mul1_add_in_place_f a l acc) (uint #t 0) val bn_mul1_lshift_add: #t:limb_t -> #aLen:size_nat -> #resLen:size_nat -> a:lbignum t aLen -> b_j:limb t -> j:size_nat{j + aLen <= resLen} -> res:lbignum t resLen -> limb t & lbignum t resLen let bn_mul1_lshift_add #t #aLen #resLen a b_j j res = let res' = sub res j aLen in let c, res' = bn_mul1_add_in_place a b_j res' in let res = update_sub res j aLen res' in c, res val bn_mul_: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat{aLen + bLen <= max_size_t} -> a:lbignum t aLen -> b:lbignum t bLen -> j:size_nat{j < bLen} -> res:lbignum t (aLen + bLen) -> lbignum t (aLen + bLen) let bn_mul_ #t #aLen #bLen a b j res = let c, res = bn_mul1_lshift_add a b.[j] j res in res.[aLen + j] <- c val bn_mul: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat{aLen + bLen <= max_size_t} -> a:lbignum t aLen -> b:lbignum t bLen -> lbignum t (aLen + bLen) let bn_mul #t #aLen #bLen a b = let res = create (aLen + bLen) (uint #t 0) in repeati bLen (bn_mul_ a b) res val bn_mul1_lemma_loop_step: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> l:limb t -> i:pos{i <= aLen} -> c1_res1:generate_elem_a (limb t) (limb t) aLen (i - 1) -> Lemma (requires (let (c1, res1) = c1_res1 in v c1 * pow2 (bits t * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen a (i - 1) * v l)) (ensures (let (c1, res1) = c1_res1 in let (c, res) = generate_elem_f aLen (bn_mul1_f a l) (i - 1) (c1, res1) in v c * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen a i * v l)) let bn_mul1_lemma_loop_step #t #aLen a l i (c1, res1) = let pbits = bits t in let b1 = pow2 (pbits * (i - 1)) in let b2 = pow2 (pbits * i) in let (c, res) = generate_elem_f aLen (bn_mul1_f a l) (i - 1) (c1, res1) in let c, e = mul_wide_add a.[i - 1] l c1 in assert (v e + v c * pow2 pbits == v a.[i - 1] * v l + v c1); calc (==) { v c * b2 + bn_v #t #i res; (==) { bn_eval_snoc #t #(i - 1) res1 e } v c * b2 + bn_v #t #(i - 1) res1 + v e * b1; (==) { } v c * b2 + eval_ aLen a (i - 1) * v l -(v e + v c * pow2 pbits - v a.[i - 1] * v l) * b1 + v e * b1; (==) { Math.Lemmas.distributivity_add_left (v e) (v c * pow2 pbits - v a.[i - 1] * v l) b1 } v c * b2 + eval_ aLen a (i - 1) * v l - (v c * pow2 pbits - v a.[i - 1] * v l) * b1; (==) { Math.Lemmas.distributivity_sub_left (v c * pow2 pbits) (v a.[i - 1] * v l) b1 } v c * b2 + eval_ aLen a (i - 1) * v l - v c * pow2 pbits * b1 + v a.[i - 1] * v l * b1; (==) { Math.Lemmas.paren_mul_right (v c) (pow2 pbits) b1; Math.Lemmas.pow2_plus pbits (pbits * (i - 1)) } eval_ aLen a (i - 1) * v l + v a.[i - 1] * v l * b1; (==) { Math.Lemmas.paren_mul_right (v a.[i - 1]) (v l) b1 } eval_ aLen a (i - 1) * v l + v a.[i - 1] * (b1 * v l); (==) { Math.Lemmas.paren_mul_right (v a.[i - 1]) b1 (v l) } eval_ aLen a (i - 1) * v l + v a.[i - 1] * b1 * v l; (==) { Math.Lemmas.distributivity_add_left (eval_ aLen a (i - 1)) (v a.[i - 1] * b1) (v l) } (eval_ aLen a (i - 1) + v a.[i - 1] * b1) * v l; (==) { bn_eval_unfold_i a i } eval_ aLen a i * v l; }; assert (v c * b2 + bn_v #t #i res == eval_ aLen a i * v l) val bn_mul1_lemma_loop: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> l:limb t -> i:nat{i <= aLen} -> Lemma (let (c, res) : generate_elem_a (limb t) (limb t) aLen i = generate_elems aLen i (bn_mul1_f a l) (uint #t 0) in v c * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen a i * v l) let rec bn_mul1_lemma_loop #t #aLen a l i = let pbits = bits t in let (c, res) : generate_elem_a (limb t) (limb t) aLen i = generate_elems aLen i (bn_mul1_f a l) (uint #t 0) in if i = 0 then begin eq_generate_elems0 aLen i (bn_mul1_f a l) (uint #t 0); assert (c == uint #t 0 /\ res == Seq.empty); bn_eval0 #t #0 res; assert_norm (pow2 0 = 1); bn_eval0 a; () end else begin let (c1, res1) : generate_elem_a (limb t) (limb t) aLen (i - 1) = generate_elems aLen (i - 1) (bn_mul1_f a l) (uint #t 0) in generate_elems_unfold aLen i (bn_mul1_f a l) (uint #t 0) (i - 1); assert (generate_elems aLen i (bn_mul1_f a l) (uint #t 0) == generate_elem_f aLen (bn_mul1_f a l) (i - 1) (generate_elems aLen (i - 1) (bn_mul1_f a l) (uint #t 0))); assert ((c, res) == generate_elem_f aLen (bn_mul1_f a l) (i - 1) (c1, res1)); bn_mul1_lemma_loop a l (i - 1); assert (v c1 * pow2 (pbits * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen a (i - 1) * v l); bn_mul1_lemma_loop_step a l i (c1, res1); assert (v c * pow2 (pbits * i) + bn_v #t #i res == eval_ aLen a i * v l); () end val bn_mul1_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> l:limb t -> Lemma (let (c, res) = bn_mul1 a l in v c * pow2 (bits t * aLen) + bn_v res == bn_v a * v l) let bn_mul1_lemma #t #aLen a l = let (c, res) = bn_mul1 a l in bn_mul1_lemma_loop a l aLen #push-options "--z3rlimit 150" val bn_mul1_add_in_place_lemma_loop_step: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> l:limb t -> acc:lbignum t aLen -> i:pos{i <= aLen} -> c1_res1:generate_elem_a (limb t) (limb t) aLen (i - 1) -> Lemma (requires (let (c1, res1) = c1_res1 in v c1 * pow2 (bits t * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen acc (i - 1) + eval_ aLen a (i - 1) * v l)) (ensures (let (c1, res1) = c1_res1 in let (c, res) = generate_elem_f aLen (bn_mul1_add_in_place_f a l acc) (i - 1) (c1, res1) in v c * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen acc i + eval_ aLen a i * v l)) let bn_mul1_add_in_place_lemma_loop_step #t #aLen a l acc i (c1, res1) = let pbits = bits t in let b1 = pow2 (pbits * (i - 1)) in let b2 = pow2 (pbits * i) in let (c, res) = generate_elem_f aLen (bn_mul1_add_in_place_f a l acc) (i - 1) (c1, res1) in let c, e = mul_wide_add2 a.[i - 1] l c1 acc.[i - 1] in assert (v e + v c * pow2 pbits == v a.[i - 1] * v l + v c1 + v acc.[i - 1]); calc (==) { v c * b2 + bn_v #t #i res; (==) { bn_eval_snoc #t #(i - 1) res1 e } v c * b2 + bn_v #t #(i - 1) res1 + v e * b1; (==) { } v c * b2 + eval_ aLen acc (i - 1) + eval_ aLen a (i - 1) * v l - (v e + v c * pow2 pbits - v a.[i - 1] * v l - v acc.[i - 1]) * b1 + v e * b1; (==) { Math.Lemmas.distributivity_add_left (v e) (v c * pow2 pbits - v a.[i - 1] * v l - v acc.[i - 1]) b1 } v c * b2 + eval_ aLen acc (i - 1) + eval_ aLen a (i - 1) * v l - (v c * pow2 pbits - v a.[i - 1] * v l - v acc.[i - 1]) * b1; (==) { Math.Lemmas.distributivity_sub_left (v c * pow2 pbits) (v a.[i - 1] * v l + v acc.[i - 1]) b1 } v c * b2 + eval_ aLen acc (i - 1) + eval_ aLen a (i - 1) * v l - (v c * pow2 pbits) * b1 + (v a.[i - 1] * v l + v acc.[i - 1]) * b1; (==) { Math.Lemmas.paren_mul_right (v c) (pow2 pbits) b1; Math.Lemmas.pow2_plus pbits (pbits * (i - 1)) } eval_ aLen acc (i - 1) + eval_ aLen a (i - 1) * v l + (v a.[i - 1] * v l + v acc.[i - 1]) * b1; (==) { Math.Lemmas.distributivity_add_left (v a.[i - 1] * v l) (v acc.[i - 1]) b1 } eval_ aLen acc (i - 1) + eval_ aLen a (i - 1) * v l + v a.[i - 1] * v l * b1 + v acc.[i - 1] * b1; (==) { bn_eval_unfold_i acc i } eval_ aLen acc i + eval_ aLen a (i - 1) * v l + v a.[i - 1] * v l * b1; (==) { Math.Lemmas.paren_mul_right (v a.[i - 1]) (v l) b1 } eval_ aLen acc i + eval_ aLen a (i - 1) * v l + v a.[i - 1] * (b1 * v l); (==) { Math.Lemmas.paren_mul_right (v a.[i - 1]) b1 (v l) } eval_ aLen acc i + eval_ aLen a (i - 1) * v l + v a.[i - 1] * b1 * v l; (==) { Math.Lemmas.distributivity_add_left (eval_ aLen a (i - 1)) (v a.[i - 1] * b1) (v l) } eval_ aLen acc i + (eval_ aLen a (i - 1) + v a.[i - 1] * b1) * v l; (==) { bn_eval_unfold_i a i } eval_ aLen acc i + eval_ aLen a i * v l; }; assert (v c * b2 + bn_v #t #i res == eval_ aLen acc i + eval_ aLen a i * v l) #pop-options val bn_mul1_add_in_place_lemma_loop: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> l:limb t -> acc:lbignum t aLen -> i:nat{i <= aLen} -> Lemma (let (c, res) : generate_elem_a (limb t) (limb t) aLen i = generate_elems aLen i (bn_mul1_add_in_place_f a l acc) (uint #t 0) in v c * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen acc i + eval_ aLen a i * v l) let rec bn_mul1_add_in_place_lemma_loop #t #aLen a l acc i = let pbits = bits t in let (c, res) : generate_elem_a (limb t) (limb t) aLen i = generate_elems aLen i (bn_mul1_add_in_place_f a l acc) (uint #t 0) in if i = 0 then begin eq_generate_elems0 aLen i (bn_mul1_add_in_place_f a l acc) (uint #t 0); assert (c == uint #t 0 /\ res == Seq.empty); bn_eval0 #t #0 res; assert_norm (pow2 0 = 1); bn_eval0 a; bn_eval0 acc; () end else begin let (c1, res1) : generate_elem_a (limb t) (limb t) aLen (i - 1) = generate_elems aLen (i - 1) (bn_mul1_add_in_place_f a l acc) (uint #t 0) in generate_elems_unfold aLen i (bn_mul1_add_in_place_f a l acc) (uint #t 0) (i - 1); assert (generate_elems aLen i (bn_mul1_add_in_place_f a l acc) (uint #t 0) == generate_elem_f aLen (bn_mul1_add_in_place_f a l acc) (i - 1) (generate_elems aLen (i - 1) (bn_mul1_add_in_place_f a l acc) (uint #t 0))); assert ((c, res) == generate_elem_f aLen (bn_mul1_add_in_place_f a l acc) (i - 1) (c1, res1)); bn_mul1_add_in_place_lemma_loop a l acc (i - 1); assert (v c1 * pow2 (pbits * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen acc (i - 1) + eval_ aLen a (i - 1) * v l); bn_mul1_add_in_place_lemma_loop_step a l acc i (c1, res1); assert (v c * pow2 (pbits * i) + bn_v #t #i res == eval_ aLen acc i + eval_ aLen a i * v l); () end val bn_mul1_add_in_place_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> l:limb t -> acc:lbignum t aLen -> Lemma (let (c, res) = bn_mul1_add_in_place a l acc in v c * pow2 (bits t * aLen) + bn_v res == bn_v acc + bn_v a * v l) let bn_mul1_add_in_place_lemma #t #aLen a l acc = let (c, res) = bn_mul1_add_in_place a l acc in bn_mul1_add_in_place_lemma_loop a l acc aLen val bn_mul1_lshift_add_lemma: #t:limb_t -> #aLen:size_nat -> #resLen:size_nat -> a:lbignum t aLen -> b_j:limb t -> j:size_nat{j + aLen <= resLen} -> acc:lbignum t resLen -> Lemma (let (c, res) = bn_mul1_lshift_add a b_j j acc in v c * pow2 (bits t * (aLen + j)) + eval_ resLen res (aLen + j) == eval_ resLen acc (aLen + j) + bn_v a * v b_j * pow2 (bits t * j) /\ slice res (aLen + j) resLen == slice acc (aLen + j) resLen) let bn_mul1_lshift_add_lemma #t #aLen #resLen a b_j j acc = let pbits = bits t in let res1 = sub acc j aLen in let c, res2 = bn_mul1_add_in_place a b_j res1 in bn_mul1_add_in_place_lemma a b_j res1; assert (v c * pow2 (pbits * aLen) + bn_v res2 == bn_v res1 + bn_v a * v b_j); let res = update_sub acc j aLen res2 in bn_eval_split_i (sub res 0 (j + aLen)) j; bn_eval_extensionality_j res (sub res 0 (j + aLen)) (j + aLen); assert (eval_ resLen res (j + aLen) == bn_v #t #j (sub res 0 j) + pow2 (pbits * j) * bn_v res2); eq_intro (sub res 0 j) (sub acc 0 j); assert (bn_v #t #j (sub res 0 j) == bn_v #t #j (sub acc 0 j)); bn_eval_split_i (sub acc 0 (j + aLen)) j; bn_eval_extensionality_j acc (sub acc 0 (j + aLen)) (j + aLen); assert (eval_ resLen acc (j + aLen) == bn_v #t #j (sub acc 0 j) + pow2 (pbits * j) * bn_v res1); calc (==) { v c * pow2 (pbits * (aLen + j)) + eval_ resLen res (aLen + j); (==) { Math.Lemmas.pow2_plus (pbits * aLen) (pbits * j) } v c * (pow2 (pbits * aLen) * pow2 (pbits * j)) + eval_ resLen res (aLen + j); (==) { Math.Lemmas.paren_mul_right (v c) (pow2 (pbits * aLen)) (pow2 (pbits * j)) } v c * pow2 (pbits * aLen) * pow2 (pbits * j) + eval_ resLen res (aLen + j); (==) { } (bn_v res1 + bn_v a * v b_j - bn_v res2) * pow2 (pbits * j) + eval_ resLen res (aLen + j); (==) { } (bn_v res1 + bn_v a * v b_j - bn_v res2) * pow2 (pbits * j) + eval_ resLen acc (j + aLen) - pow2 (pbits * j) * bn_v res1 + pow2 (pbits * j) * bn_v res2; (==) { Math.Lemmas.distributivity_add_right (pow2 (pbits * j)) (bn_v res1) (bn_v a * v b_j - bn_v res2) } pow2 (pbits * j) * (bn_v a * v b_j - bn_v res2) + eval_ resLen acc (j + aLen) + pow2 (pbits * j) * bn_v res2; (==) { Math.Lemmas.distributivity_sub_right (pow2 (pbits * j)) (bn_v a * v b_j) (bn_v res2) } pow2 (pbits * j) * (bn_v a * v b_j) + eval_ resLen acc (j + aLen); }; assert (v c * pow2 (pbits * (aLen + j)) + eval_ resLen res (aLen + j) == eval_ resLen acc (aLen + j) + bn_v a * v b_j * pow2 (pbits * j)); eq_intro (slice res (aLen + j) resLen) (slice acc (aLen + j) resLen) val bn_mul_lemma_: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat{aLen + bLen <= max_size_t} -> a:lbignum t aLen -> b:lbignum t bLen -> j:size_nat{j < bLen} -> acc:lbignum t (aLen + bLen) -> Lemma (let res = bn_mul_ a b j acc in v res.[aLen + j] * pow2 (bits t * (aLen + j)) + eval_ (aLen + bLen) res (aLen + j) == eval_ (aLen + bLen) acc (aLen + j) + bn_v a * v b.[j] * pow2 (bits t * j))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Lib.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Bignum.Multiplication.fst" }
[ { "abbrev": false, "full_module": "Hacl.Spec.Lib", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Base", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> b: Hacl.Spec.Bignum.Definitions.lbignum t bLen -> j: Lib.IntTypes.size_nat{j < bLen} -> acc: Hacl.Spec.Bignum.Definitions.lbignum t (aLen + bLen) -> FStar.Pervasives.Lemma (ensures (let res = Hacl.Spec.Bignum.Multiplication.bn_mul_ a b j acc in Lib.IntTypes.v res.[ aLen + j ] * Prims.pow2 (Lib.IntTypes.bits t * (aLen + j)) + Hacl.Spec.Bignum.Definitions.eval_ (aLen + bLen) res (aLen + j) == Hacl.Spec.Bignum.Definitions.eval_ (aLen + bLen) acc (aLen + j) + (Hacl.Spec.Bignum.Definitions.bn_v a * Lib.IntTypes.v b.[ j ]) * Prims.pow2 (Lib.IntTypes.bits t * j)))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Lib.IntTypes.size_nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "Lib.IntTypes.max_size_t", "Hacl.Spec.Bignum.Definitions.lbignum", "Prims.op_LessThan", "Hacl.Spec.Bignum.Definitions.limb", "Hacl.Spec.Bignum.Definitions.bn_eval_extensionality_j", "Lib.Sequence.lseq", "Prims.l_and", "Prims.eq2", "FStar.Seq.Base.seq", "Lib.Sequence.to_seq", "FStar.Seq.Base.upd", "Lib.Sequence.index", "Prims.l_Forall", "Prims.nat", "Prims.op_Subtraction", "Prims.pow2", "Prims.l_imp", "Prims.op_disEquality", "Prims.l_or", "FStar.Seq.Base.index", "Lib.Sequence.op_String_Assignment", "Prims.unit", "Hacl.Spec.Bignum.Multiplication.bn_mul1_lshift_add_lemma", "Lib.Sequence.op_String_Access", "FStar.Pervasives.Native.tuple2", "Hacl.Spec.Bignum.Multiplication.bn_mul1_lshift_add" ]
[]
false
false
true
false
false
let bn_mul_lemma_ #t #aLen #bLen a b j acc =
let c, res = bn_mul1_lshift_add a b.[ j ] j acc in bn_mul1_lshift_add_lemma a b.[ j ] j acc; let res1 = res.[ aLen + j ] <- c in bn_eval_extensionality_j res res1 (aLen + j)
false
Vale.AES.X64.GF128_Init.fsti
Vale.AES.X64.GF128_Init.va_wp_Keyhash_init
val va_wp_Keyhash_init (win: bool) (alg: algorithm) (key: (seq nat32)) (roundkeys_b hkeys_b: buffer128) (va_s0: va_state) (va_k: (va_state -> unit -> Type0)) : Type0
val va_wp_Keyhash_init (win: bool) (alg: algorithm) (key: (seq nat32)) (roundkeys_b hkeys_b: buffer128) (va_s0: va_state) (va_k: (va_state -> unit -> Type0)) : Type0
let va_wp_Keyhash_init (win:bool) (alg:algorithm) (key:(seq nat32)) (roundkeys_b:buffer128) (hkeys_b:buffer128) (va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 = (va_get_ok va_s0 /\ (let (round_ptr:(va_int_range 0 18446744073709551615)) = va_if win (fun _ -> va_get_reg64 rRcx va_s0) (fun _ -> va_get_reg64 rRdi va_s0) in let (hkey_ptr:(va_int_range 0 18446744073709551615)) = va_if win (fun _ -> va_get_reg64 rRdx va_s0) (fun _ -> va_get_reg64 rRsi va_s0) in Vale.X64.Memory.is_initial_heap (va_get_mem_layout va_s0) (va_get_mem va_s0) /\ (aesni_enabled /\ pclmulqdq_enabled /\ avx_enabled /\ sse_enabled) /\ (alg = AES_128 \/ alg = AES_256) /\ Vale.X64.Decls.buffers_disjoint128 roundkeys_b hkeys_b /\ Vale.AES.AES_s.is_aes_key_LE alg key /\ Vale.X64.Decls.buffer128_as_seq (va_get_mem va_s0) roundkeys_b == Vale.AES.AES_s.key_to_round_keys_LE alg key /\ Vale.X64.Decls.validSrcAddrs128 (va_get_mem va_s0) round_ptr roundkeys_b (Vale.AES.AES_common_s.nr alg + 1) (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validDstAddrs128 (va_get_mem va_s0) hkey_ptr hkeys_b 8 (va_get_mem_layout va_s0) Secret) /\ (forall (va_x_mem:vale_heap) (va_x_rax:nat64) (va_x_rcx:nat64) (va_x_rdx:nat64) (va_x_r8:nat64) (va_x_r12:nat64) (va_x_heap1:vale_heap) (va_x_memLayout:vale_heap_layout) (va_x_xmm0:quad32) (va_x_xmm1:quad32) (va_x_xmm2:quad32) (va_x_xmm3:quad32) (va_x_xmm4:quad32) (va_x_xmm5:quad32) (va_x_xmm6:quad32) (va_x_efl:Vale.X64.Flags.t) . let va_sM = va_upd_flags va_x_efl (va_upd_xmm 6 va_x_xmm6 (va_upd_xmm 5 va_x_xmm5 (va_upd_xmm 4 va_x_xmm4 (va_upd_xmm 3 va_x_xmm3 (va_upd_xmm 2 va_x_xmm2 (va_upd_xmm 1 va_x_xmm1 (va_upd_xmm 0 va_x_xmm0 (va_upd_mem_layout va_x_memLayout (va_upd_mem_heaplet 1 va_x_heap1 (va_upd_reg64 rR12 va_x_r12 (va_upd_reg64 rR8 va_x_r8 (va_upd_reg64 rRdx va_x_rdx (va_upd_reg64 rRcx va_x_rcx (va_upd_reg64 rRax va_x_rax (va_upd_mem va_x_mem va_s0))))))))))))))) in va_get_ok va_sM /\ (let (round_ptr:(va_int_range 0 18446744073709551615)) = va_if win (fun _ -> va_get_reg64 rRcx va_s0) (fun _ -> va_get_reg64 rRdi va_s0) in let (hkey_ptr:(va_int_range 0 18446744073709551615)) = va_if win (fun _ -> va_get_reg64 rRdx va_s0) (fun _ -> va_get_reg64 rRsi va_s0) in Vale.X64.Decls.modifies_buffer128 hkeys_b (va_get_mem va_s0) (va_get_mem va_sM) /\ Vale.AES.OptPublic.hkeys_reqs_pub (Vale.X64.Decls.s128 (va_get_mem va_sM) hkeys_b) (Vale.Def.Types_s.reverse_bytes_quad32 (Vale.AES.AES_s.aes_encrypt_LE alg key (Vale.Def.Words_s.Mkfour #Vale.Def.Types_s.nat32 0 0 0 0))) /\ va_get_xmm 6 va_sM == va_get_xmm 6 va_s0 /\ va_get_reg64 rR12 va_sM == va_get_reg64 rR12 va_s0) ==> va_k va_sM (())))
{ "file_name": "obj/Vale.AES.X64.GF128_Init.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 88, "end_line": 129, "start_col": 0, "start_line": 100 }
module Vale.AES.X64.GF128_Init open Vale.Def.Words_s open Vale.Def.Words.Four_s open Vale.Def.Types_s open FStar.Seq open Vale.Arch.Types open Vale.Arch.HeapImpl open Vale.Math.Poly2_s open Vale.Math.Poly2 open Vale.Math.Poly2.Bits_s open Vale.Math.Poly2.Bits open Vale.Math.Poly2.Lemmas open Vale.AES.GF128_s open Vale.AES.GF128 open Vale.AES.GHash open Vale.AES.AES_s open Vale.AES.AES256_helpers open Vale.AES.X64.AES open Vale.X64.Machine_s open Vale.X64.Memory open Vale.X64.State open Vale.X64.Decls open Vale.X64.InsBasic open Vale.X64.InsMem open Vale.X64.InsVector open Vale.X64.InsAes open Vale.X64.QuickCode open Vale.X64.QuickCodes open Vale.X64.CPU_Features_s open Vale.AES.X64.PolyOps open Vale.AES.X64.GF128_Mul open Vale.AES.GHash open Vale.AES.OptPublic //-- Keyhash_init val va_code_Keyhash_init : win:bool -> alg:algorithm -> Tot va_code val va_codegen_success_Keyhash_init : win:bool -> alg:algorithm -> Tot va_pbool let va_req_Keyhash_init (va_b0:va_code) (va_s0:va_state) (win:bool) (alg:algorithm) (key:(seq nat32)) (roundkeys_b:buffer128) (hkeys_b:buffer128) : prop = (va_require_total va_b0 (va_code_Keyhash_init win alg) va_s0 /\ va_get_ok va_s0 /\ (let (round_ptr:(va_int_range 0 18446744073709551615)) = (if win then va_get_reg64 rRcx va_s0 else va_get_reg64 rRdi va_s0) in let (hkey_ptr:(va_int_range 0 18446744073709551615)) = (if win then va_get_reg64 rRdx va_s0 else va_get_reg64 rRsi va_s0) in Vale.X64.Memory.is_initial_heap (va_get_mem_layout va_s0) (va_get_mem va_s0) /\ (aesni_enabled /\ pclmulqdq_enabled /\ avx_enabled /\ sse_enabled) /\ (alg = AES_128 \/ alg = AES_256) /\ Vale.X64.Decls.buffers_disjoint128 roundkeys_b hkeys_b /\ Vale.AES.AES_s.is_aes_key_LE alg key /\ Vale.X64.Decls.buffer128_as_seq (va_get_mem va_s0) roundkeys_b == Vale.AES.AES_s.key_to_round_keys_LE alg key /\ Vale.X64.Decls.validSrcAddrs128 (va_get_mem va_s0) round_ptr roundkeys_b (Vale.AES.AES_common_s.nr alg + 1) (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validDstAddrs128 (va_get_mem va_s0) hkey_ptr hkeys_b 8 (va_get_mem_layout va_s0) Secret)) let va_ens_Keyhash_init (va_b0:va_code) (va_s0:va_state) (win:bool) (alg:algorithm) (key:(seq nat32)) (roundkeys_b:buffer128) (hkeys_b:buffer128) (va_sM:va_state) (va_fM:va_fuel) : prop = (va_req_Keyhash_init va_b0 va_s0 win alg key roundkeys_b hkeys_b /\ va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\ (let (round_ptr:(va_int_range 0 18446744073709551615)) = (if win then va_get_reg64 rRcx va_s0 else va_get_reg64 rRdi va_s0) in let (hkey_ptr:(va_int_range 0 18446744073709551615)) = (if win then va_get_reg64 rRdx va_s0 else va_get_reg64 rRsi va_s0) in Vale.X64.Decls.modifies_buffer128 hkeys_b (va_get_mem va_s0) (va_get_mem va_sM) /\ Vale.AES.OptPublic.hkeys_reqs_pub (Vale.X64.Decls.s128 (va_get_mem va_sM) hkeys_b) (Vale.Def.Types_s.reverse_bytes_quad32 (Vale.AES.AES_s.aes_encrypt_LE alg key (Vale.Def.Words_s.Mkfour #Vale.Def.Types_s.nat32 0 0 0 0))) /\ va_get_xmm 6 va_sM == va_get_xmm 6 va_s0 /\ va_get_reg64 rR12 va_sM == va_get_reg64 rR12 va_s0) /\ va_state_eq va_sM (va_update_flags va_sM (va_update_xmm 6 va_sM (va_update_xmm 5 va_sM (va_update_xmm 4 va_sM (va_update_xmm 3 va_sM (va_update_xmm 2 va_sM (va_update_xmm 1 va_sM (va_update_xmm 0 va_sM (va_update_mem_layout va_sM (va_update_mem_heaplet 1 va_sM (va_update_reg64 rR12 va_sM (va_update_reg64 rR8 va_sM (va_update_reg64 rRdx va_sM (va_update_reg64 rRcx va_sM (va_update_reg64 rRax va_sM (va_update_ok va_sM (va_update_mem va_sM va_s0)))))))))))))))))) val va_lemma_Keyhash_init : va_b0:va_code -> va_s0:va_state -> win:bool -> alg:algorithm -> key:(seq nat32) -> roundkeys_b:buffer128 -> hkeys_b:buffer128 -> Ghost (va_state & va_fuel) (requires (va_require_total va_b0 (va_code_Keyhash_init win alg) va_s0 /\ va_get_ok va_s0 /\ (let (round_ptr:(va_int_range 0 18446744073709551615)) = (if win then va_get_reg64 rRcx va_s0 else va_get_reg64 rRdi va_s0) in let (hkey_ptr:(va_int_range 0 18446744073709551615)) = (if win then va_get_reg64 rRdx va_s0 else va_get_reg64 rRsi va_s0) in Vale.X64.Memory.is_initial_heap (va_get_mem_layout va_s0) (va_get_mem va_s0) /\ (aesni_enabled /\ pclmulqdq_enabled /\ avx_enabled /\ sse_enabled) /\ (alg = AES_128 \/ alg = AES_256) /\ Vale.X64.Decls.buffers_disjoint128 roundkeys_b hkeys_b /\ Vale.AES.AES_s.is_aes_key_LE alg key /\ Vale.X64.Decls.buffer128_as_seq (va_get_mem va_s0) roundkeys_b == Vale.AES.AES_s.key_to_round_keys_LE alg key /\ Vale.X64.Decls.validSrcAddrs128 (va_get_mem va_s0) round_ptr roundkeys_b (Vale.AES.AES_common_s.nr alg + 1) (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validDstAddrs128 (va_get_mem va_s0) hkey_ptr hkeys_b 8 (va_get_mem_layout va_s0) Secret))) (ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\ (let (round_ptr:(va_int_range 0 18446744073709551615)) = (if win then va_get_reg64 rRcx va_s0 else va_get_reg64 rRdi va_s0) in let (hkey_ptr:(va_int_range 0 18446744073709551615)) = (if win then va_get_reg64 rRdx va_s0 else va_get_reg64 rRsi va_s0) in Vale.X64.Decls.modifies_buffer128 hkeys_b (va_get_mem va_s0) (va_get_mem va_sM) /\ Vale.AES.OptPublic.hkeys_reqs_pub (Vale.X64.Decls.s128 (va_get_mem va_sM) hkeys_b) (Vale.Def.Types_s.reverse_bytes_quad32 (Vale.AES.AES_s.aes_encrypt_LE alg key (Vale.Def.Words_s.Mkfour #Vale.Def.Types_s.nat32 0 0 0 0))) /\ va_get_xmm 6 va_sM == va_get_xmm 6 va_s0 /\ va_get_reg64 rR12 va_sM == va_get_reg64 rR12 va_s0) /\ va_state_eq va_sM (va_update_flags va_sM (va_update_xmm 6 va_sM (va_update_xmm 5 va_sM (va_update_xmm 4 va_sM (va_update_xmm 3 va_sM (va_update_xmm 2 va_sM (va_update_xmm 1 va_sM (va_update_xmm 0 va_sM (va_update_mem_layout va_sM (va_update_mem_heaplet 1 va_sM (va_update_reg64 rR12 va_sM (va_update_reg64 rR8 va_sM (va_update_reg64 rRdx va_sM (va_update_reg64 rRcx va_sM (va_update_reg64 rRax va_sM (va_update_ok va_sM (va_update_mem va_sM va_s0)))))))))))))))))))
{ "checked_file": "/", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.QuickCodes.fsti.checked", "Vale.X64.QuickCode.fst.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.InsVector.fsti.checked", "Vale.X64.InsMem.fsti.checked", "Vale.X64.InsBasic.fsti.checked", "Vale.X64.InsAes.fsti.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Decls.fsti.checked", "Vale.X64.CPU_Features_s.fst.checked", "Vale.Math.Poly2_s.fsti.checked", "Vale.Math.Poly2.Lemmas.fsti.checked", "Vale.Math.Poly2.Bits_s.fsti.checked", "Vale.Math.Poly2.Bits.fsti.checked", "Vale.Math.Poly2.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Arch.Types.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "Vale.AES.X64.PolyOps.fsti.checked", "Vale.AES.X64.GF128_Mul.fsti.checked", "Vale.AES.X64.AES.fsti.checked", "Vale.AES.OptPublic.fsti.checked", "Vale.AES.GHash.fsti.checked", "Vale.AES.GF128_s.fsti.checked", "Vale.AES.GF128.fsti.checked", "Vale.AES.AES_s.fst.checked", "Vale.AES.AES_common_s.fst.checked", "Vale.AES.AES256_helpers.fsti.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Vale.AES.X64.GF128_Init.fsti" }
[ { "abbrev": false, "full_module": "Vale.AES.OptPublic", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.X64.GF128_Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.X64.PolyOps", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.CPU_Features_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCodes", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsAes", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsVector", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsMem", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsBasic", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.X64.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES256_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
win: Prims.bool -> alg: Vale.AES.AES_common_s.algorithm -> key: FStar.Seq.Base.seq Vale.X64.Memory.nat32 -> roundkeys_b: Vale.X64.Memory.buffer128 -> hkeys_b: Vale.X64.Memory.buffer128 -> va_s0: Vale.X64.Decls.va_state -> va_k: (_: Vale.X64.Decls.va_state -> _: Prims.unit -> Type0) -> Type0
Prims.Tot
[ "total" ]
[]
[ "Prims.bool", "Vale.AES.AES_common_s.algorithm", "FStar.Seq.Base.seq", "Vale.X64.Memory.nat32", "Vale.X64.Memory.buffer128", "Vale.X64.Decls.va_state", "Prims.unit", "Prims.l_and", "Prims.b2t", "Vale.X64.Decls.va_get_ok", "Vale.X64.Memory.is_initial_heap", "Vale.X64.Decls.va_get_mem_layout", "Vale.X64.Decls.va_get_mem", "Vale.X64.CPU_Features_s.aesni_enabled", "Vale.X64.CPU_Features_s.pclmulqdq_enabled", "Vale.X64.CPU_Features_s.avx_enabled", "Vale.X64.CPU_Features_s.sse_enabled", "Prims.l_or", "Prims.op_Equality", "Vale.AES.AES_common_s.AES_128", "Vale.AES.AES_common_s.AES_256", "Vale.X64.Decls.buffers_disjoint128", "Vale.AES.AES_s.is_aes_key_LE", "Prims.eq2", "Vale.Def.Types_s.quad32", "Vale.X64.Decls.buffer128_as_seq", "Vale.AES.AES_s.key_to_round_keys_LE", "Vale.X64.Decls.validSrcAddrs128", "Prims.op_Addition", "Vale.AES.AES_common_s.nr", "Vale.Arch.HeapTypes_s.Secret", "Vale.X64.Decls.validDstAddrs128", "Vale.X64.Decls.va_int_range", "Vale.X64.Decls.va_if", "Vale.Def.Types_s.nat64", "Vale.X64.Decls.va_get_reg64", "Vale.X64.Machine_s.rRdx", "Prims.l_not", "Vale.X64.Machine_s.rRsi", "Vale.X64.Machine_s.rRcx", "Vale.X64.Machine_s.rRdi", "Prims.l_Forall", "Vale.X64.InsBasic.vale_heap", "Vale.X64.Memory.nat64", "Vale.Arch.HeapImpl.vale_heap_layout", "Vale.X64.Decls.quad32", "Vale.X64.Flags.t", "Prims.l_imp", "Vale.X64.Decls.modifies_buffer128", "Vale.AES.OptPublic.hkeys_reqs_pub", "Vale.X64.Decls.s128", "Vale.Def.Types_s.reverse_bytes_quad32", "Vale.AES.AES_s.aes_encrypt_LE", "Vale.Def.Words_s.Mkfour", "Vale.Def.Types_s.nat32", "Vale.X64.Decls.va_get_xmm", "Vale.X64.Machine_s.rR12", "Vale.X64.State.vale_state", "Vale.X64.Decls.va_upd_flags", "Vale.X64.Decls.va_upd_xmm", "Vale.X64.Decls.va_upd_mem_layout", "Vale.X64.Decls.va_upd_mem_heaplet", "Vale.X64.Decls.va_upd_reg64", "Vale.X64.Machine_s.rR8", "Vale.X64.Machine_s.rRax", "Vale.X64.Decls.va_upd_mem" ]
[]
false
false
false
true
true
let va_wp_Keyhash_init (win: bool) (alg: algorithm) (key: (seq nat32)) (roundkeys_b hkeys_b: buffer128) (va_s0: va_state) (va_k: (va_state -> unit -> Type0)) : Type0 =
(va_get_ok va_s0 /\ (let round_ptr:(va_int_range 0 18446744073709551615) = va_if win (fun _ -> va_get_reg64 rRcx va_s0) (fun _ -> va_get_reg64 rRdi va_s0) in let hkey_ptr:(va_int_range 0 18446744073709551615) = va_if win (fun _ -> va_get_reg64 rRdx va_s0) (fun _ -> va_get_reg64 rRsi va_s0) in Vale.X64.Memory.is_initial_heap (va_get_mem_layout va_s0) (va_get_mem va_s0) /\ (aesni_enabled /\ pclmulqdq_enabled /\ avx_enabled /\ sse_enabled) /\ (alg = AES_128 \/ alg = AES_256) /\ Vale.X64.Decls.buffers_disjoint128 roundkeys_b hkeys_b /\ Vale.AES.AES_s.is_aes_key_LE alg key /\ Vale.X64.Decls.buffer128_as_seq (va_get_mem va_s0) roundkeys_b == Vale.AES.AES_s.key_to_round_keys_LE alg key /\ Vale.X64.Decls.validSrcAddrs128 (va_get_mem va_s0) round_ptr roundkeys_b (Vale.AES.AES_common_s.nr alg + 1) (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validDstAddrs128 (va_get_mem va_s0) hkey_ptr hkeys_b 8 (va_get_mem_layout va_s0) Secret) /\ (forall (va_x_mem: vale_heap) (va_x_rax: nat64) (va_x_rcx: nat64) (va_x_rdx: nat64) (va_x_r8: nat64) (va_x_r12: nat64) (va_x_heap1: vale_heap) (va_x_memLayout: vale_heap_layout) (va_x_xmm0: quad32) (va_x_xmm1: quad32) (va_x_xmm2: quad32) (va_x_xmm3: quad32) (va_x_xmm4: quad32) (va_x_xmm5: quad32) (va_x_xmm6: quad32) (va_x_efl: Vale.X64.Flags.t). let va_sM = va_upd_flags va_x_efl (va_upd_xmm 6 va_x_xmm6 (va_upd_xmm 5 va_x_xmm5 (va_upd_xmm 4 va_x_xmm4 (va_upd_xmm 3 va_x_xmm3 (va_upd_xmm 2 va_x_xmm2 (va_upd_xmm 1 va_x_xmm1 (va_upd_xmm 0 va_x_xmm0 (va_upd_mem_layout va_x_memLayout (va_upd_mem_heaplet 1 va_x_heap1 (va_upd_reg64 rR12 va_x_r12 (va_upd_reg64 rR8 va_x_r8 (va_upd_reg64 rRdx va_x_rdx (va_upd_reg64 rRcx va_x_rcx (va_upd_reg64 rRax va_x_rax (va_upd_mem va_x_mem va_s0)))))))) ))))))) in va_get_ok va_sM /\ (let round_ptr:(va_int_range 0 18446744073709551615) = va_if win (fun _ -> va_get_reg64 rRcx va_s0) (fun _ -> va_get_reg64 rRdi va_s0) in let hkey_ptr:(va_int_range 0 18446744073709551615) = va_if win (fun _ -> va_get_reg64 rRdx va_s0) (fun _ -> va_get_reg64 rRsi va_s0) in Vale.X64.Decls.modifies_buffer128 hkeys_b (va_get_mem va_s0) (va_get_mem va_sM) /\ Vale.AES.OptPublic.hkeys_reqs_pub (Vale.X64.Decls.s128 (va_get_mem va_sM) hkeys_b) (Vale.Def.Types_s.reverse_bytes_quad32 (Vale.AES.AES_s.aes_encrypt_LE alg key (Vale.Def.Words_s.Mkfour #Vale.Def.Types_s.nat32 0 0 0 0))) /\ va_get_xmm 6 va_sM == va_get_xmm 6 va_s0 /\ va_get_reg64 rR12 va_sM == va_get_reg64 rR12 va_s0) ==> va_k va_sM (())))
false
FStar.Krml.Endianness.fst
FStar.Krml.Endianness.be_of_uint64
val be_of_uint64 (x: UInt64.t) : b: bytes{S.length b = 8}
val be_of_uint64 (x: UInt64.t) : b: bytes{S.length b = 8}
let be_of_uint64 (x: UInt64.t): b:bytes{ S.length b = 8 } = n_to_be 8ul (UInt64.v x)
{ "file_name": "krmllib/FStar.Krml.Endianness.fst", "git_rev": "da1e941b2fcb196aa5d1e34941aa00b4c67ac321", "git_url": "https://github.com/FStarLang/karamel.git", "project_name": "karamel" }
{ "end_col": 26, "end_line": 234, "start_col": 0, "start_line": 233 }
module FStar.Krml.Endianness open FStar.Mul open FStar.HyperStack.All module U8 = FStar.UInt8 module U32 = FStar.UInt32 module U64 = FStar.UInt64 module Math = FStar.Math.Lemmas module S = FStar.Seq (* Selectively imported from Hacl*'s FStar.Endianness.fst library, with several name changes *) inline_for_extraction noextract type bytes = S.seq U8.t /// lt_to_n interprets a byte sequence as a little-endian natural number [@(deprecated "FStar.Endianness.le_to_n")] val le_to_n : b:bytes -> Tot nat (decreases (S.length b)) let rec le_to_n b = if S.length b = 0 then 0 else U8.v (S.head b) + pow2 8 * le_to_n (S.tail b) /// be_to_n interprets a byte sequence as a big-endian natural number [@(deprecated "FStar.Endianness.be_to_n")] val be_to_n : b:bytes -> Tot nat (decreases (S.length b)) let rec be_to_n b = if S.length b = 0 then 0 else U8.v (S.last b) + pow2 8 * be_to_n (S.slice b 0 (S.length b - 1)) [@(deprecated "FStar.Endianness.lemma_euclidean_division")] private val lemma_euclidean_division: r:nat -> b:nat -> q:pos -> Lemma (requires (r < q)) (ensures (r + q * b < q * (b+1))) let lemma_euclidean_division r b q = () [@(deprecated "FStar.Endianness.lemma_factorise")] private val lemma_factorise: a:nat -> b:nat -> Lemma (a + a * b == a * (b + 1)) let lemma_factorise a b = () [@(deprecated "FStar.Endianness.lemma_le_to_n_is_bounded")] val lemma_le_to_n_is_bounded: b:bytes -> Lemma (requires True) (ensures (le_to_n b < pow2 (8 * Seq.length b))) (decreases (Seq.length b)) let rec lemma_le_to_n_is_bounded b = if Seq.length b = 0 then () else begin let s = Seq.slice b 1 (Seq.length b) in assert(Seq.length s = Seq.length b - 1); lemma_le_to_n_is_bounded s; assert(UInt8.v (Seq.index b 0) < pow2 8); assert(le_to_n s < pow2 (8 * Seq.length s)); assert(le_to_n b < pow2 8 + pow2 8 * pow2 (8 * (Seq.length b - 1))); lemma_euclidean_division (UInt8.v (Seq.index b 0)) (le_to_n s) (pow2 8); assert(le_to_n b <= pow2 8 * (le_to_n s + 1)); assert(le_to_n b <= pow2 8 * pow2 (8 * (Seq.length b - 1))); Math.Lemmas.pow2_plus 8 (8 * (Seq.length b - 1)); lemma_factorise 8 (Seq.length b - 1) end [@(deprecated "FStar.Endianness.lemma_be_to_n_is_bounded")] val lemma_be_to_n_is_bounded: b:bytes -> Lemma (requires True) (ensures (be_to_n b < pow2 (8 * Seq.length b))) (decreases (Seq.length b)) let rec lemma_be_to_n_is_bounded b = if Seq.length b = 0 then () else begin let s = Seq.slice b 0 (Seq.length b - 1) in assert(Seq.length s = Seq.length b - 1); lemma_be_to_n_is_bounded s; assert(UInt8.v (Seq.last b) < pow2 8); assert(be_to_n s < pow2 (8 * Seq.length s)); assert(be_to_n b < pow2 8 + pow2 8 * pow2 (8 * (Seq.length b - 1))); lemma_euclidean_division (UInt8.v (Seq.last b)) (be_to_n s) (pow2 8); assert(be_to_n b <= pow2 8 * (be_to_n s + 1)); assert(be_to_n b <= pow2 8 * pow2 (8 * (Seq.length b - 1))); Math.Lemmas.pow2_plus 8 (8 * (Seq.length b - 1)); lemma_factorise 8 (Seq.length b - 1) end /// n_to_le encodes a number as a little-endian byte sequence of a fixed, /// sufficiently large length [@(deprecated "FStar.Endianness.n_to_le")] val n_to_le : len:U32.t -> n:nat{n < pow2 (8 * U32.v len)} -> Tot (b:bytes{S.length b == U32.v len /\ n == le_to_n b}) (decreases (U32.v len)) let rec n_to_le len n = if len = 0ul then S.empty else let len = U32.(len -^ 1ul) in let byte = U8.uint_to_t (n % 256) in let n' = n / 256 in Math.pow2_plus 8 (8 * U32.v len); assert(n' < pow2 (8 * U32.v len )); let b' = n_to_le len n' in let b = S.cons byte b' in S.lemma_eq_intro b' (S.tail b); b /// n_to_be encodes a numbers as a big-endian byte sequence of a fixed, /// sufficiently large length [@(deprecated "FStar.Endianness.n_to_be")] val n_to_be: len:U32.t -> n:nat{n < pow2 (8 * U32.v len)} -> Tot (b:bytes{S.length b == U32.v len /\ n == be_to_n b}) (decreases (U32.v len)) let rec n_to_be len n = if len = 0ul then S.empty else let len = U32.(len -^ 1ul) in let byte = U8.uint_to_t (n % 256) in let n' = n / 256 in Math.pow2_plus 8 (8 * U32.v len); assert(n' < pow2 (8 * U32.v len )); let b' = n_to_be len n' in let b'' = S.create 1 byte in let b = S.append b' b'' in S.lemma_eq_intro b' (S.slice b 0 (U32.v len)); b [@(deprecated "FStar.Endianness.n_to_le_inj")] let n_to_le_inj (len:U32.t) (n1 n2: (n:nat{n < pow2 (8 * U32.v len)})) : Lemma (requires (n_to_le len n1 == n_to_le len n2)) (ensures (n1 == n2)) = // this lemma easily follows from le_to_n . (n_to_le len) == id, the inversion // proof in the spec for n_to_le () [@(deprecated "FStar.Endianness.n_to_be_inj")] let n_to_be_inj (len:U32.t) (n1 n2: (n:nat{n < pow2 (8 * U32.v len)})) : Lemma (requires (n_to_be len n1 == n_to_be len n2)) (ensures (n1 == n2)) = () [@(deprecated "FStar.Endianness.be_to_n_inj")] let rec be_to_n_inj (b1 b2: Seq.seq U8.t) : Lemma (requires (Seq.length b1 == Seq.length b2 /\ be_to_n b1 == be_to_n b2)) (ensures (Seq.equal b1 b2)) (decreases (Seq.length b1)) = if Seq.length b1 = 0 then () else begin be_to_n_inj (Seq.slice b1 0 (Seq.length b1 - 1)) (Seq.slice b2 0 (Seq.length b2 - 1)); Seq.lemma_split b1 (Seq.length b1 - 1); Seq.lemma_split b2 (Seq.length b2 - 1) end [@(deprecated "FStar.Endianness.le_to_n_inj")] let rec le_to_n_inj (b1 b2: Seq.seq U8.t) : Lemma (requires (Seq.length b1 == Seq.length b2 /\ le_to_n b1 == le_to_n b2)) (ensures (Seq.equal b1 b2)) (decreases (Seq.length b1)) = if Seq.length b1 = 0 then () else begin le_to_n_inj (Seq.slice b1 1 (Seq.length b1)) (Seq.slice b2 1 (Seq.length b2)); Seq.lemma_split b1 1; Seq.lemma_split b2 1 end [@(deprecated "FStar.Endianness.n_to_be_be_to_n")] let n_to_be_be_to_n (len: U32.t) (s: Seq.seq U8.t) : Lemma (requires (Seq.length s == U32.v len)) (ensures ( be_to_n s < pow2 (8 `Prims.op_Multiply` U32.v len) /\ n_to_be len (be_to_n s) == s )) [SMTPat (n_to_be len (be_to_n s))] = lemma_be_to_n_is_bounded s; be_to_n_inj s (n_to_be len (be_to_n s)) [@(deprecated "FStar.Endianness.n_to_le_le_to_n")] let n_to_le_le_to_n (len: U32.t) (s: Seq.seq U8.t) : Lemma (requires (Seq.length s == U32.v len)) (ensures ( le_to_n s < pow2 (8 `Prims.op_Multiply` U32.v len) /\ n_to_le len (le_to_n s) == s )) [SMTPat (n_to_le len (le_to_n s))] = lemma_le_to_n_is_bounded s; le_to_n_inj s (n_to_le len (le_to_n s)) (** A series of specializations to deal with machine integers *) [@(deprecated "FStar.Endianness.uint32_of_le")] let uint32_of_le (b: bytes { S.length b = 4 }) = let n = le_to_n b in lemma_le_to_n_is_bounded b; UInt32.uint_to_t n [@(deprecated "FStar.Endianness.le_of_uint32")] let le_of_uint32 (x: UInt32.t): b:bytes{ S.length b = 4 } = n_to_le 4ul (UInt32.v x) [@(deprecated "FStar.Endianness.uint32_of_be")] let uint32_of_be (b: bytes { S.length b = 4 }) = let n = be_to_n b in lemma_be_to_n_is_bounded b; UInt32.uint_to_t n [@(deprecated "FStar.Endianness.be_of_uint32")] let be_of_uint32 (x: UInt32.t): b:bytes{ S.length b = 4 } = n_to_be 4ul (UInt32.v x) [@(deprecated "FStar.Endianness.uint64_of_le")] let uint64_of_le (b: bytes { S.length b = 8 }) = let n = le_to_n b in lemma_le_to_n_is_bounded b; UInt64.uint_to_t n [@(deprecated "FStar.Endianness.le_of_uint64")] let le_of_uint64 (x: UInt64.t): b:bytes{ S.length b = 8 } = n_to_le 8ul (UInt64.v x) [@(deprecated "FStar.Endianness.uint64_of_be")] let uint64_of_be (b: bytes { S.length b = 8 }) = let n = be_to_n b in lemma_be_to_n_is_bounded b; UInt64.uint_to_t n
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.All.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "FStar.Krml.Endianness.fst" }
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Math.Lemmas", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Krml", "short_module": null }, { "abbrev": false, "full_module": "FStar.Krml", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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: FStar.UInt64.t -> b: FStar.Krml.Endianness.bytes{FStar.Seq.Base.length b = 8}
Prims.Tot
[ "total" ]
[]
[ "FStar.UInt64.t", "FStar.Krml.Endianness.n_to_be", "FStar.UInt32.__uint_to_t", "FStar.UInt64.v", "FStar.Krml.Endianness.bytes", "Prims.b2t", "Prims.op_Equality", "Prims.int", "FStar.Seq.Base.length", "FStar.UInt8.t" ]
[]
false
false
false
false
false
let be_of_uint64 (x: UInt64.t) : b: bytes{S.length b = 8} =
n_to_be 8ul (UInt64.v x)
false
FStar.Krml.Endianness.fst
FStar.Krml.Endianness.le_of_seq_uint32
val le_of_seq_uint32 (s: S.seq UInt32.t) : Tot (b: bytes{S.length b = 4 * S.length s}) (decreases (S.length s))
val le_of_seq_uint32 (s: S.seq UInt32.t) : Tot (b: bytes{S.length b = 4 * S.length s}) (decreases (S.length s))
let rec le_of_seq_uint32 (s: S.seq UInt32.t): Tot (b:bytes { S.length b = 4 * S.length s }) (decreases (S.length s)) = if S.length s = 0 then S.empty else S.append (le_of_uint32 (S.head s)) (le_of_seq_uint32 (S.tail s))
{ "file_name": "krmllib/FStar.Krml.Endianness.fst", "git_rev": "da1e941b2fcb196aa5d1e34941aa00b4c67ac321", "git_url": "https://github.com/FStarLang/karamel.git", "project_name": "karamel" }
{ "end_col": 68, "end_line": 254, "start_col": 0, "start_line": 247 }
module FStar.Krml.Endianness open FStar.Mul open FStar.HyperStack.All module U8 = FStar.UInt8 module U32 = FStar.UInt32 module U64 = FStar.UInt64 module Math = FStar.Math.Lemmas module S = FStar.Seq (* Selectively imported from Hacl*'s FStar.Endianness.fst library, with several name changes *) inline_for_extraction noextract type bytes = S.seq U8.t /// lt_to_n interprets a byte sequence as a little-endian natural number [@(deprecated "FStar.Endianness.le_to_n")] val le_to_n : b:bytes -> Tot nat (decreases (S.length b)) let rec le_to_n b = if S.length b = 0 then 0 else U8.v (S.head b) + pow2 8 * le_to_n (S.tail b) /// be_to_n interprets a byte sequence as a big-endian natural number [@(deprecated "FStar.Endianness.be_to_n")] val be_to_n : b:bytes -> Tot nat (decreases (S.length b)) let rec be_to_n b = if S.length b = 0 then 0 else U8.v (S.last b) + pow2 8 * be_to_n (S.slice b 0 (S.length b - 1)) [@(deprecated "FStar.Endianness.lemma_euclidean_division")] private val lemma_euclidean_division: r:nat -> b:nat -> q:pos -> Lemma (requires (r < q)) (ensures (r + q * b < q * (b+1))) let lemma_euclidean_division r b q = () [@(deprecated "FStar.Endianness.lemma_factorise")] private val lemma_factorise: a:nat -> b:nat -> Lemma (a + a * b == a * (b + 1)) let lemma_factorise a b = () [@(deprecated "FStar.Endianness.lemma_le_to_n_is_bounded")] val lemma_le_to_n_is_bounded: b:bytes -> Lemma (requires True) (ensures (le_to_n b < pow2 (8 * Seq.length b))) (decreases (Seq.length b)) let rec lemma_le_to_n_is_bounded b = if Seq.length b = 0 then () else begin let s = Seq.slice b 1 (Seq.length b) in assert(Seq.length s = Seq.length b - 1); lemma_le_to_n_is_bounded s; assert(UInt8.v (Seq.index b 0) < pow2 8); assert(le_to_n s < pow2 (8 * Seq.length s)); assert(le_to_n b < pow2 8 + pow2 8 * pow2 (8 * (Seq.length b - 1))); lemma_euclidean_division (UInt8.v (Seq.index b 0)) (le_to_n s) (pow2 8); assert(le_to_n b <= pow2 8 * (le_to_n s + 1)); assert(le_to_n b <= pow2 8 * pow2 (8 * (Seq.length b - 1))); Math.Lemmas.pow2_plus 8 (8 * (Seq.length b - 1)); lemma_factorise 8 (Seq.length b - 1) end [@(deprecated "FStar.Endianness.lemma_be_to_n_is_bounded")] val lemma_be_to_n_is_bounded: b:bytes -> Lemma (requires True) (ensures (be_to_n b < pow2 (8 * Seq.length b))) (decreases (Seq.length b)) let rec lemma_be_to_n_is_bounded b = if Seq.length b = 0 then () else begin let s = Seq.slice b 0 (Seq.length b - 1) in assert(Seq.length s = Seq.length b - 1); lemma_be_to_n_is_bounded s; assert(UInt8.v (Seq.last b) < pow2 8); assert(be_to_n s < pow2 (8 * Seq.length s)); assert(be_to_n b < pow2 8 + pow2 8 * pow2 (8 * (Seq.length b - 1))); lemma_euclidean_division (UInt8.v (Seq.last b)) (be_to_n s) (pow2 8); assert(be_to_n b <= pow2 8 * (be_to_n s + 1)); assert(be_to_n b <= pow2 8 * pow2 (8 * (Seq.length b - 1))); Math.Lemmas.pow2_plus 8 (8 * (Seq.length b - 1)); lemma_factorise 8 (Seq.length b - 1) end /// n_to_le encodes a number as a little-endian byte sequence of a fixed, /// sufficiently large length [@(deprecated "FStar.Endianness.n_to_le")] val n_to_le : len:U32.t -> n:nat{n < pow2 (8 * U32.v len)} -> Tot (b:bytes{S.length b == U32.v len /\ n == le_to_n b}) (decreases (U32.v len)) let rec n_to_le len n = if len = 0ul then S.empty else let len = U32.(len -^ 1ul) in let byte = U8.uint_to_t (n % 256) in let n' = n / 256 in Math.pow2_plus 8 (8 * U32.v len); assert(n' < pow2 (8 * U32.v len )); let b' = n_to_le len n' in let b = S.cons byte b' in S.lemma_eq_intro b' (S.tail b); b /// n_to_be encodes a numbers as a big-endian byte sequence of a fixed, /// sufficiently large length [@(deprecated "FStar.Endianness.n_to_be")] val n_to_be: len:U32.t -> n:nat{n < pow2 (8 * U32.v len)} -> Tot (b:bytes{S.length b == U32.v len /\ n == be_to_n b}) (decreases (U32.v len)) let rec n_to_be len n = if len = 0ul then S.empty else let len = U32.(len -^ 1ul) in let byte = U8.uint_to_t (n % 256) in let n' = n / 256 in Math.pow2_plus 8 (8 * U32.v len); assert(n' < pow2 (8 * U32.v len )); let b' = n_to_be len n' in let b'' = S.create 1 byte in let b = S.append b' b'' in S.lemma_eq_intro b' (S.slice b 0 (U32.v len)); b [@(deprecated "FStar.Endianness.n_to_le_inj")] let n_to_le_inj (len:U32.t) (n1 n2: (n:nat{n < pow2 (8 * U32.v len)})) : Lemma (requires (n_to_le len n1 == n_to_le len n2)) (ensures (n1 == n2)) = // this lemma easily follows from le_to_n . (n_to_le len) == id, the inversion // proof in the spec for n_to_le () [@(deprecated "FStar.Endianness.n_to_be_inj")] let n_to_be_inj (len:U32.t) (n1 n2: (n:nat{n < pow2 (8 * U32.v len)})) : Lemma (requires (n_to_be len n1 == n_to_be len n2)) (ensures (n1 == n2)) = () [@(deprecated "FStar.Endianness.be_to_n_inj")] let rec be_to_n_inj (b1 b2: Seq.seq U8.t) : Lemma (requires (Seq.length b1 == Seq.length b2 /\ be_to_n b1 == be_to_n b2)) (ensures (Seq.equal b1 b2)) (decreases (Seq.length b1)) = if Seq.length b1 = 0 then () else begin be_to_n_inj (Seq.slice b1 0 (Seq.length b1 - 1)) (Seq.slice b2 0 (Seq.length b2 - 1)); Seq.lemma_split b1 (Seq.length b1 - 1); Seq.lemma_split b2 (Seq.length b2 - 1) end [@(deprecated "FStar.Endianness.le_to_n_inj")] let rec le_to_n_inj (b1 b2: Seq.seq U8.t) : Lemma (requires (Seq.length b1 == Seq.length b2 /\ le_to_n b1 == le_to_n b2)) (ensures (Seq.equal b1 b2)) (decreases (Seq.length b1)) = if Seq.length b1 = 0 then () else begin le_to_n_inj (Seq.slice b1 1 (Seq.length b1)) (Seq.slice b2 1 (Seq.length b2)); Seq.lemma_split b1 1; Seq.lemma_split b2 1 end [@(deprecated "FStar.Endianness.n_to_be_be_to_n")] let n_to_be_be_to_n (len: U32.t) (s: Seq.seq U8.t) : Lemma (requires (Seq.length s == U32.v len)) (ensures ( be_to_n s < pow2 (8 `Prims.op_Multiply` U32.v len) /\ n_to_be len (be_to_n s) == s )) [SMTPat (n_to_be len (be_to_n s))] = lemma_be_to_n_is_bounded s; be_to_n_inj s (n_to_be len (be_to_n s)) [@(deprecated "FStar.Endianness.n_to_le_le_to_n")] let n_to_le_le_to_n (len: U32.t) (s: Seq.seq U8.t) : Lemma (requires (Seq.length s == U32.v len)) (ensures ( le_to_n s < pow2 (8 `Prims.op_Multiply` U32.v len) /\ n_to_le len (le_to_n s) == s )) [SMTPat (n_to_le len (le_to_n s))] = lemma_le_to_n_is_bounded s; le_to_n_inj s (n_to_le len (le_to_n s)) (** A series of specializations to deal with machine integers *) [@(deprecated "FStar.Endianness.uint32_of_le")] let uint32_of_le (b: bytes { S.length b = 4 }) = let n = le_to_n b in lemma_le_to_n_is_bounded b; UInt32.uint_to_t n [@(deprecated "FStar.Endianness.le_of_uint32")] let le_of_uint32 (x: UInt32.t): b:bytes{ S.length b = 4 } = n_to_le 4ul (UInt32.v x) [@(deprecated "FStar.Endianness.uint32_of_be")] let uint32_of_be (b: bytes { S.length b = 4 }) = let n = be_to_n b in lemma_be_to_n_is_bounded b; UInt32.uint_to_t n [@(deprecated "FStar.Endianness.be_of_uint32")] let be_of_uint32 (x: UInt32.t): b:bytes{ S.length b = 4 } = n_to_be 4ul (UInt32.v x) [@(deprecated "FStar.Endianness.uint64_of_le")] let uint64_of_le (b: bytes { S.length b = 8 }) = let n = le_to_n b in lemma_le_to_n_is_bounded b; UInt64.uint_to_t n [@(deprecated "FStar.Endianness.le_of_uint64")] let le_of_uint64 (x: UInt64.t): b:bytes{ S.length b = 8 } = n_to_le 8ul (UInt64.v x) [@(deprecated "FStar.Endianness.uint64_of_be")] let uint64_of_be (b: bytes { S.length b = 8 }) = let n = be_to_n b in lemma_be_to_n_is_bounded b; UInt64.uint_to_t n [@(deprecated "FStar.Endianness.be_of_uint64")] let be_of_uint64 (x: UInt64.t): b:bytes{ S.length b = 8 } = n_to_be 8ul (UInt64.v x) [@(deprecated "FStar.Endianness.seq_uint32_of_le")] let rec seq_uint32_of_le (l: nat) (b: bytes{ S.length b = 4 * l }): s:S.seq UInt32.t { S.length s = l } = if S.length b = 0 then S.empty else let hd, tl = Seq.split b 4 in S.cons (uint32_of_le hd) (seq_uint32_of_le (l - 1) tl)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.All.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "FStar.Krml.Endianness.fst" }
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Math.Lemmas", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Krml", "short_module": null }, { "abbrev": false, "full_module": "FStar.Krml", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s: FStar.Seq.Base.seq FStar.UInt32.t -> Prims.Tot (b: FStar.Krml.Endianness.bytes{FStar.Seq.Base.length b = 4 * FStar.Seq.Base.length s})
Prims.Tot
[ "total", "" ]
[]
[ "FStar.Seq.Base.seq", "FStar.UInt32.t", "Prims.op_Equality", "Prims.int", "FStar.Seq.Base.length", "FStar.Seq.Base.empty", "FStar.UInt8.t", "Prims.bool", "FStar.Seq.Base.append", "FStar.Krml.Endianness.le_of_uint32", "FStar.Seq.Properties.head", "FStar.Krml.Endianness.le_of_seq_uint32", "FStar.Seq.Properties.tail", "FStar.Krml.Endianness.bytes", "Prims.b2t", "FStar.Mul.op_Star" ]
[ "recursion" ]
false
false
false
false
false
let rec le_of_seq_uint32 (s: S.seq UInt32.t) : Tot (b: bytes{S.length b = 4 * S.length s}) (decreases (S.length s)) =
if S.length s = 0 then S.empty else S.append (le_of_uint32 (S.head s)) (le_of_seq_uint32 (S.tail s))
false
FStar.Krml.Endianness.fst
FStar.Krml.Endianness.be_of_uint32
val be_of_uint32 (x: UInt32.t) : b: bytes{S.length b = 4}
val be_of_uint32 (x: UInt32.t) : b: bytes{S.length b = 4}
let be_of_uint32 (x: UInt32.t): b:bytes{ S.length b = 4 } = n_to_be 4ul (UInt32.v x)
{ "file_name": "krmllib/FStar.Krml.Endianness.fst", "git_rev": "da1e941b2fcb196aa5d1e34941aa00b4c67ac321", "git_url": "https://github.com/FStarLang/karamel.git", "project_name": "karamel" }
{ "end_col": 26, "end_line": 214, "start_col": 0, "start_line": 213 }
module FStar.Krml.Endianness open FStar.Mul open FStar.HyperStack.All module U8 = FStar.UInt8 module U32 = FStar.UInt32 module U64 = FStar.UInt64 module Math = FStar.Math.Lemmas module S = FStar.Seq (* Selectively imported from Hacl*'s FStar.Endianness.fst library, with several name changes *) inline_for_extraction noextract type bytes = S.seq U8.t /// lt_to_n interprets a byte sequence as a little-endian natural number [@(deprecated "FStar.Endianness.le_to_n")] val le_to_n : b:bytes -> Tot nat (decreases (S.length b)) let rec le_to_n b = if S.length b = 0 then 0 else U8.v (S.head b) + pow2 8 * le_to_n (S.tail b) /// be_to_n interprets a byte sequence as a big-endian natural number [@(deprecated "FStar.Endianness.be_to_n")] val be_to_n : b:bytes -> Tot nat (decreases (S.length b)) let rec be_to_n b = if S.length b = 0 then 0 else U8.v (S.last b) + pow2 8 * be_to_n (S.slice b 0 (S.length b - 1)) [@(deprecated "FStar.Endianness.lemma_euclidean_division")] private val lemma_euclidean_division: r:nat -> b:nat -> q:pos -> Lemma (requires (r < q)) (ensures (r + q * b < q * (b+1))) let lemma_euclidean_division r b q = () [@(deprecated "FStar.Endianness.lemma_factorise")] private val lemma_factorise: a:nat -> b:nat -> Lemma (a + a * b == a * (b + 1)) let lemma_factorise a b = () [@(deprecated "FStar.Endianness.lemma_le_to_n_is_bounded")] val lemma_le_to_n_is_bounded: b:bytes -> Lemma (requires True) (ensures (le_to_n b < pow2 (8 * Seq.length b))) (decreases (Seq.length b)) let rec lemma_le_to_n_is_bounded b = if Seq.length b = 0 then () else begin let s = Seq.slice b 1 (Seq.length b) in assert(Seq.length s = Seq.length b - 1); lemma_le_to_n_is_bounded s; assert(UInt8.v (Seq.index b 0) < pow2 8); assert(le_to_n s < pow2 (8 * Seq.length s)); assert(le_to_n b < pow2 8 + pow2 8 * pow2 (8 * (Seq.length b - 1))); lemma_euclidean_division (UInt8.v (Seq.index b 0)) (le_to_n s) (pow2 8); assert(le_to_n b <= pow2 8 * (le_to_n s + 1)); assert(le_to_n b <= pow2 8 * pow2 (8 * (Seq.length b - 1))); Math.Lemmas.pow2_plus 8 (8 * (Seq.length b - 1)); lemma_factorise 8 (Seq.length b - 1) end [@(deprecated "FStar.Endianness.lemma_be_to_n_is_bounded")] val lemma_be_to_n_is_bounded: b:bytes -> Lemma (requires True) (ensures (be_to_n b < pow2 (8 * Seq.length b))) (decreases (Seq.length b)) let rec lemma_be_to_n_is_bounded b = if Seq.length b = 0 then () else begin let s = Seq.slice b 0 (Seq.length b - 1) in assert(Seq.length s = Seq.length b - 1); lemma_be_to_n_is_bounded s; assert(UInt8.v (Seq.last b) < pow2 8); assert(be_to_n s < pow2 (8 * Seq.length s)); assert(be_to_n b < pow2 8 + pow2 8 * pow2 (8 * (Seq.length b - 1))); lemma_euclidean_division (UInt8.v (Seq.last b)) (be_to_n s) (pow2 8); assert(be_to_n b <= pow2 8 * (be_to_n s + 1)); assert(be_to_n b <= pow2 8 * pow2 (8 * (Seq.length b - 1))); Math.Lemmas.pow2_plus 8 (8 * (Seq.length b - 1)); lemma_factorise 8 (Seq.length b - 1) end /// n_to_le encodes a number as a little-endian byte sequence of a fixed, /// sufficiently large length [@(deprecated "FStar.Endianness.n_to_le")] val n_to_le : len:U32.t -> n:nat{n < pow2 (8 * U32.v len)} -> Tot (b:bytes{S.length b == U32.v len /\ n == le_to_n b}) (decreases (U32.v len)) let rec n_to_le len n = if len = 0ul then S.empty else let len = U32.(len -^ 1ul) in let byte = U8.uint_to_t (n % 256) in let n' = n / 256 in Math.pow2_plus 8 (8 * U32.v len); assert(n' < pow2 (8 * U32.v len )); let b' = n_to_le len n' in let b = S.cons byte b' in S.lemma_eq_intro b' (S.tail b); b /// n_to_be encodes a numbers as a big-endian byte sequence of a fixed, /// sufficiently large length [@(deprecated "FStar.Endianness.n_to_be")] val n_to_be: len:U32.t -> n:nat{n < pow2 (8 * U32.v len)} -> Tot (b:bytes{S.length b == U32.v len /\ n == be_to_n b}) (decreases (U32.v len)) let rec n_to_be len n = if len = 0ul then S.empty else let len = U32.(len -^ 1ul) in let byte = U8.uint_to_t (n % 256) in let n' = n / 256 in Math.pow2_plus 8 (8 * U32.v len); assert(n' < pow2 (8 * U32.v len )); let b' = n_to_be len n' in let b'' = S.create 1 byte in let b = S.append b' b'' in S.lemma_eq_intro b' (S.slice b 0 (U32.v len)); b [@(deprecated "FStar.Endianness.n_to_le_inj")] let n_to_le_inj (len:U32.t) (n1 n2: (n:nat{n < pow2 (8 * U32.v len)})) : Lemma (requires (n_to_le len n1 == n_to_le len n2)) (ensures (n1 == n2)) = // this lemma easily follows from le_to_n . (n_to_le len) == id, the inversion // proof in the spec for n_to_le () [@(deprecated "FStar.Endianness.n_to_be_inj")] let n_to_be_inj (len:U32.t) (n1 n2: (n:nat{n < pow2 (8 * U32.v len)})) : Lemma (requires (n_to_be len n1 == n_to_be len n2)) (ensures (n1 == n2)) = () [@(deprecated "FStar.Endianness.be_to_n_inj")] let rec be_to_n_inj (b1 b2: Seq.seq U8.t) : Lemma (requires (Seq.length b1 == Seq.length b2 /\ be_to_n b1 == be_to_n b2)) (ensures (Seq.equal b1 b2)) (decreases (Seq.length b1)) = if Seq.length b1 = 0 then () else begin be_to_n_inj (Seq.slice b1 0 (Seq.length b1 - 1)) (Seq.slice b2 0 (Seq.length b2 - 1)); Seq.lemma_split b1 (Seq.length b1 - 1); Seq.lemma_split b2 (Seq.length b2 - 1) end [@(deprecated "FStar.Endianness.le_to_n_inj")] let rec le_to_n_inj (b1 b2: Seq.seq U8.t) : Lemma (requires (Seq.length b1 == Seq.length b2 /\ le_to_n b1 == le_to_n b2)) (ensures (Seq.equal b1 b2)) (decreases (Seq.length b1)) = if Seq.length b1 = 0 then () else begin le_to_n_inj (Seq.slice b1 1 (Seq.length b1)) (Seq.slice b2 1 (Seq.length b2)); Seq.lemma_split b1 1; Seq.lemma_split b2 1 end [@(deprecated "FStar.Endianness.n_to_be_be_to_n")] let n_to_be_be_to_n (len: U32.t) (s: Seq.seq U8.t) : Lemma (requires (Seq.length s == U32.v len)) (ensures ( be_to_n s < pow2 (8 `Prims.op_Multiply` U32.v len) /\ n_to_be len (be_to_n s) == s )) [SMTPat (n_to_be len (be_to_n s))] = lemma_be_to_n_is_bounded s; be_to_n_inj s (n_to_be len (be_to_n s)) [@(deprecated "FStar.Endianness.n_to_le_le_to_n")] let n_to_le_le_to_n (len: U32.t) (s: Seq.seq U8.t) : Lemma (requires (Seq.length s == U32.v len)) (ensures ( le_to_n s < pow2 (8 `Prims.op_Multiply` U32.v len) /\ n_to_le len (le_to_n s) == s )) [SMTPat (n_to_le len (le_to_n s))] = lemma_le_to_n_is_bounded s; le_to_n_inj s (n_to_le len (le_to_n s)) (** A series of specializations to deal with machine integers *) [@(deprecated "FStar.Endianness.uint32_of_le")] let uint32_of_le (b: bytes { S.length b = 4 }) = let n = le_to_n b in lemma_le_to_n_is_bounded b; UInt32.uint_to_t n [@(deprecated "FStar.Endianness.le_of_uint32")] let le_of_uint32 (x: UInt32.t): b:bytes{ S.length b = 4 } = n_to_le 4ul (UInt32.v x) [@(deprecated "FStar.Endianness.uint32_of_be")] let uint32_of_be (b: bytes { S.length b = 4 }) = let n = be_to_n b in lemma_be_to_n_is_bounded b; UInt32.uint_to_t n
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.All.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "FStar.Krml.Endianness.fst" }
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Math.Lemmas", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Krml", "short_module": null }, { "abbrev": false, "full_module": "FStar.Krml", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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: FStar.UInt32.t -> b: FStar.Krml.Endianness.bytes{FStar.Seq.Base.length b = 4}
Prims.Tot
[ "total" ]
[]
[ "FStar.UInt32.t", "FStar.Krml.Endianness.n_to_be", "FStar.UInt32.__uint_to_t", "FStar.UInt32.v", "FStar.Krml.Endianness.bytes", "Prims.b2t", "Prims.op_Equality", "Prims.int", "FStar.Seq.Base.length", "FStar.UInt8.t" ]
[]
false
false
false
false
false
let be_of_uint32 (x: UInt32.t) : b: bytes{S.length b = 4} =
n_to_be 4ul (UInt32.v x)
false
FStar.Krml.Endianness.fst
FStar.Krml.Endianness.le_of_seq_uint64
val le_of_seq_uint64 (s: S.seq UInt64.t) : Tot (b: bytes{S.length b = 8 * S.length s}) (decreases (S.length s))
val le_of_seq_uint64 (s: S.seq UInt64.t) : Tot (b: bytes{S.length b = 8 * S.length s}) (decreases (S.length s))
let rec le_of_seq_uint64 (s: S.seq UInt64.t): Tot (b:bytes { S.length b = 8 * S.length s }) (decreases (S.length s)) = if S.length s = 0 then S.empty else S.append (le_of_uint64 (S.head s)) (le_of_seq_uint64 (S.tail s))
{ "file_name": "krmllib/FStar.Krml.Endianness.fst", "git_rev": "da1e941b2fcb196aa5d1e34941aa00b4c67ac321", "git_url": "https://github.com/FStarLang/karamel.git", "project_name": "karamel" }
{ "end_col": 68, "end_line": 294, "start_col": 0, "start_line": 287 }
module FStar.Krml.Endianness open FStar.Mul open FStar.HyperStack.All module U8 = FStar.UInt8 module U32 = FStar.UInt32 module U64 = FStar.UInt64 module Math = FStar.Math.Lemmas module S = FStar.Seq (* Selectively imported from Hacl*'s FStar.Endianness.fst library, with several name changes *) inline_for_extraction noextract type bytes = S.seq U8.t /// lt_to_n interprets a byte sequence as a little-endian natural number [@(deprecated "FStar.Endianness.le_to_n")] val le_to_n : b:bytes -> Tot nat (decreases (S.length b)) let rec le_to_n b = if S.length b = 0 then 0 else U8.v (S.head b) + pow2 8 * le_to_n (S.tail b) /// be_to_n interprets a byte sequence as a big-endian natural number [@(deprecated "FStar.Endianness.be_to_n")] val be_to_n : b:bytes -> Tot nat (decreases (S.length b)) let rec be_to_n b = if S.length b = 0 then 0 else U8.v (S.last b) + pow2 8 * be_to_n (S.slice b 0 (S.length b - 1)) [@(deprecated "FStar.Endianness.lemma_euclidean_division")] private val lemma_euclidean_division: r:nat -> b:nat -> q:pos -> Lemma (requires (r < q)) (ensures (r + q * b < q * (b+1))) let lemma_euclidean_division r b q = () [@(deprecated "FStar.Endianness.lemma_factorise")] private val lemma_factorise: a:nat -> b:nat -> Lemma (a + a * b == a * (b + 1)) let lemma_factorise a b = () [@(deprecated "FStar.Endianness.lemma_le_to_n_is_bounded")] val lemma_le_to_n_is_bounded: b:bytes -> Lemma (requires True) (ensures (le_to_n b < pow2 (8 * Seq.length b))) (decreases (Seq.length b)) let rec lemma_le_to_n_is_bounded b = if Seq.length b = 0 then () else begin let s = Seq.slice b 1 (Seq.length b) in assert(Seq.length s = Seq.length b - 1); lemma_le_to_n_is_bounded s; assert(UInt8.v (Seq.index b 0) < pow2 8); assert(le_to_n s < pow2 (8 * Seq.length s)); assert(le_to_n b < pow2 8 + pow2 8 * pow2 (8 * (Seq.length b - 1))); lemma_euclidean_division (UInt8.v (Seq.index b 0)) (le_to_n s) (pow2 8); assert(le_to_n b <= pow2 8 * (le_to_n s + 1)); assert(le_to_n b <= pow2 8 * pow2 (8 * (Seq.length b - 1))); Math.Lemmas.pow2_plus 8 (8 * (Seq.length b - 1)); lemma_factorise 8 (Seq.length b - 1) end [@(deprecated "FStar.Endianness.lemma_be_to_n_is_bounded")] val lemma_be_to_n_is_bounded: b:bytes -> Lemma (requires True) (ensures (be_to_n b < pow2 (8 * Seq.length b))) (decreases (Seq.length b)) let rec lemma_be_to_n_is_bounded b = if Seq.length b = 0 then () else begin let s = Seq.slice b 0 (Seq.length b - 1) in assert(Seq.length s = Seq.length b - 1); lemma_be_to_n_is_bounded s; assert(UInt8.v (Seq.last b) < pow2 8); assert(be_to_n s < pow2 (8 * Seq.length s)); assert(be_to_n b < pow2 8 + pow2 8 * pow2 (8 * (Seq.length b - 1))); lemma_euclidean_division (UInt8.v (Seq.last b)) (be_to_n s) (pow2 8); assert(be_to_n b <= pow2 8 * (be_to_n s + 1)); assert(be_to_n b <= pow2 8 * pow2 (8 * (Seq.length b - 1))); Math.Lemmas.pow2_plus 8 (8 * (Seq.length b - 1)); lemma_factorise 8 (Seq.length b - 1) end /// n_to_le encodes a number as a little-endian byte sequence of a fixed, /// sufficiently large length [@(deprecated "FStar.Endianness.n_to_le")] val n_to_le : len:U32.t -> n:nat{n < pow2 (8 * U32.v len)} -> Tot (b:bytes{S.length b == U32.v len /\ n == le_to_n b}) (decreases (U32.v len)) let rec n_to_le len n = if len = 0ul then S.empty else let len = U32.(len -^ 1ul) in let byte = U8.uint_to_t (n % 256) in let n' = n / 256 in Math.pow2_plus 8 (8 * U32.v len); assert(n' < pow2 (8 * U32.v len )); let b' = n_to_le len n' in let b = S.cons byte b' in S.lemma_eq_intro b' (S.tail b); b /// n_to_be encodes a numbers as a big-endian byte sequence of a fixed, /// sufficiently large length [@(deprecated "FStar.Endianness.n_to_be")] val n_to_be: len:U32.t -> n:nat{n < pow2 (8 * U32.v len)} -> Tot (b:bytes{S.length b == U32.v len /\ n == be_to_n b}) (decreases (U32.v len)) let rec n_to_be len n = if len = 0ul then S.empty else let len = U32.(len -^ 1ul) in let byte = U8.uint_to_t (n % 256) in let n' = n / 256 in Math.pow2_plus 8 (8 * U32.v len); assert(n' < pow2 (8 * U32.v len )); let b' = n_to_be len n' in let b'' = S.create 1 byte in let b = S.append b' b'' in S.lemma_eq_intro b' (S.slice b 0 (U32.v len)); b [@(deprecated "FStar.Endianness.n_to_le_inj")] let n_to_le_inj (len:U32.t) (n1 n2: (n:nat{n < pow2 (8 * U32.v len)})) : Lemma (requires (n_to_le len n1 == n_to_le len n2)) (ensures (n1 == n2)) = // this lemma easily follows from le_to_n . (n_to_le len) == id, the inversion // proof in the spec for n_to_le () [@(deprecated "FStar.Endianness.n_to_be_inj")] let n_to_be_inj (len:U32.t) (n1 n2: (n:nat{n < pow2 (8 * U32.v len)})) : Lemma (requires (n_to_be len n1 == n_to_be len n2)) (ensures (n1 == n2)) = () [@(deprecated "FStar.Endianness.be_to_n_inj")] let rec be_to_n_inj (b1 b2: Seq.seq U8.t) : Lemma (requires (Seq.length b1 == Seq.length b2 /\ be_to_n b1 == be_to_n b2)) (ensures (Seq.equal b1 b2)) (decreases (Seq.length b1)) = if Seq.length b1 = 0 then () else begin be_to_n_inj (Seq.slice b1 0 (Seq.length b1 - 1)) (Seq.slice b2 0 (Seq.length b2 - 1)); Seq.lemma_split b1 (Seq.length b1 - 1); Seq.lemma_split b2 (Seq.length b2 - 1) end [@(deprecated "FStar.Endianness.le_to_n_inj")] let rec le_to_n_inj (b1 b2: Seq.seq U8.t) : Lemma (requires (Seq.length b1 == Seq.length b2 /\ le_to_n b1 == le_to_n b2)) (ensures (Seq.equal b1 b2)) (decreases (Seq.length b1)) = if Seq.length b1 = 0 then () else begin le_to_n_inj (Seq.slice b1 1 (Seq.length b1)) (Seq.slice b2 1 (Seq.length b2)); Seq.lemma_split b1 1; Seq.lemma_split b2 1 end [@(deprecated "FStar.Endianness.n_to_be_be_to_n")] let n_to_be_be_to_n (len: U32.t) (s: Seq.seq U8.t) : Lemma (requires (Seq.length s == U32.v len)) (ensures ( be_to_n s < pow2 (8 `Prims.op_Multiply` U32.v len) /\ n_to_be len (be_to_n s) == s )) [SMTPat (n_to_be len (be_to_n s))] = lemma_be_to_n_is_bounded s; be_to_n_inj s (n_to_be len (be_to_n s)) [@(deprecated "FStar.Endianness.n_to_le_le_to_n")] let n_to_le_le_to_n (len: U32.t) (s: Seq.seq U8.t) : Lemma (requires (Seq.length s == U32.v len)) (ensures ( le_to_n s < pow2 (8 `Prims.op_Multiply` U32.v len) /\ n_to_le len (le_to_n s) == s )) [SMTPat (n_to_le len (le_to_n s))] = lemma_le_to_n_is_bounded s; le_to_n_inj s (n_to_le len (le_to_n s)) (** A series of specializations to deal with machine integers *) [@(deprecated "FStar.Endianness.uint32_of_le")] let uint32_of_le (b: bytes { S.length b = 4 }) = let n = le_to_n b in lemma_le_to_n_is_bounded b; UInt32.uint_to_t n [@(deprecated "FStar.Endianness.le_of_uint32")] let le_of_uint32 (x: UInt32.t): b:bytes{ S.length b = 4 } = n_to_le 4ul (UInt32.v x) [@(deprecated "FStar.Endianness.uint32_of_be")] let uint32_of_be (b: bytes { S.length b = 4 }) = let n = be_to_n b in lemma_be_to_n_is_bounded b; UInt32.uint_to_t n [@(deprecated "FStar.Endianness.be_of_uint32")] let be_of_uint32 (x: UInt32.t): b:bytes{ S.length b = 4 } = n_to_be 4ul (UInt32.v x) [@(deprecated "FStar.Endianness.uint64_of_le")] let uint64_of_le (b: bytes { S.length b = 8 }) = let n = le_to_n b in lemma_le_to_n_is_bounded b; UInt64.uint_to_t n [@(deprecated "FStar.Endianness.le_of_uint64")] let le_of_uint64 (x: UInt64.t): b:bytes{ S.length b = 8 } = n_to_le 8ul (UInt64.v x) [@(deprecated "FStar.Endianness.uint64_of_be")] let uint64_of_be (b: bytes { S.length b = 8 }) = let n = be_to_n b in lemma_be_to_n_is_bounded b; UInt64.uint_to_t n [@(deprecated "FStar.Endianness.be_of_uint64")] let be_of_uint64 (x: UInt64.t): b:bytes{ S.length b = 8 } = n_to_be 8ul (UInt64.v x) [@(deprecated "FStar.Endianness.seq_uint32_of_le")] let rec seq_uint32_of_le (l: nat) (b: bytes{ S.length b = 4 * l }): s:S.seq UInt32.t { S.length s = l } = if S.length b = 0 then S.empty else let hd, tl = Seq.split b 4 in S.cons (uint32_of_le hd) (seq_uint32_of_le (l - 1) tl) [@(deprecated "FStar.Endianness.le_of_seq_uint32")] let rec le_of_seq_uint32 (s: S.seq UInt32.t): Tot (b:bytes { S.length b = 4 * S.length s }) (decreases (S.length s)) = if S.length s = 0 then S.empty else S.append (le_of_uint32 (S.head s)) (le_of_seq_uint32 (S.tail s)) [@(deprecated "FStar.Endianness.seq_uint32_of_be")] let rec seq_uint32_of_be (l: nat) (b: bytes{ S.length b = 4 * l }): s:S.seq UInt32.t { S.length s = l } = if S.length b = 0 then S.empty else let hd, tl = Seq.split b 4 in S.cons (uint32_of_be hd) (seq_uint32_of_be (l - 1) tl) [@(deprecated "FStar.Endianness.be_of_seq_uint32")] let rec be_of_seq_uint32 (s: S.seq UInt32.t): Tot (b:bytes { S.length b = 4 * S.length s }) (decreases (S.length s)) = if S.length s = 0 then S.empty else S.append (be_of_uint32 (S.head s)) (be_of_seq_uint32 (S.tail s)) [@(deprecated "FStar.Endianness.seq_uint64_of_le")] let rec seq_uint64_of_le (l: nat) (b: bytes{ S.length b = 8 * l }): s:S.seq UInt64.t { S.length s = l } = if S.length b = 0 then S.empty else let hd, tl = Seq.split b 8 in S.cons (uint64_of_le hd) (seq_uint64_of_le (l - 1) tl)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.All.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "FStar.Krml.Endianness.fst" }
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Math.Lemmas", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Krml", "short_module": null }, { "abbrev": false, "full_module": "FStar.Krml", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s: FStar.Seq.Base.seq FStar.UInt64.t -> Prims.Tot (b: FStar.Krml.Endianness.bytes{FStar.Seq.Base.length b = 8 * FStar.Seq.Base.length s})
Prims.Tot
[ "total", "" ]
[]
[ "FStar.Seq.Base.seq", "FStar.UInt64.t", "Prims.op_Equality", "Prims.int", "FStar.Seq.Base.length", "FStar.Seq.Base.empty", "FStar.UInt8.t", "Prims.bool", "FStar.Seq.Base.append", "FStar.Krml.Endianness.le_of_uint64", "FStar.Seq.Properties.head", "FStar.Krml.Endianness.le_of_seq_uint64", "FStar.Seq.Properties.tail", "FStar.Krml.Endianness.bytes", "Prims.b2t", "FStar.Mul.op_Star" ]
[ "recursion" ]
false
false
false
false
false
let rec le_of_seq_uint64 (s: S.seq UInt64.t) : Tot (b: bytes{S.length b = 8 * S.length s}) (decreases (S.length s)) =
if S.length s = 0 then S.empty else S.append (le_of_uint64 (S.head s)) (le_of_seq_uint64 (S.tail s))
false
FStar.Krml.Endianness.fst
FStar.Krml.Endianness.be_of_seq_uint32
val be_of_seq_uint32 (s: S.seq UInt32.t) : Tot (b: bytes{S.length b = 4 * S.length s}) (decreases (S.length s))
val be_of_seq_uint32 (s: S.seq UInt32.t) : Tot (b: bytes{S.length b = 4 * S.length s}) (decreases (S.length s))
let rec be_of_seq_uint32 (s: S.seq UInt32.t): Tot (b:bytes { S.length b = 4 * S.length s }) (decreases (S.length s)) = if S.length s = 0 then S.empty else S.append (be_of_uint32 (S.head s)) (be_of_seq_uint32 (S.tail s))
{ "file_name": "krmllib/FStar.Krml.Endianness.fst", "git_rev": "da1e941b2fcb196aa5d1e34941aa00b4c67ac321", "git_url": "https://github.com/FStarLang/karamel.git", "project_name": "karamel" }
{ "end_col": 68, "end_line": 274, "start_col": 0, "start_line": 267 }
module FStar.Krml.Endianness open FStar.Mul open FStar.HyperStack.All module U8 = FStar.UInt8 module U32 = FStar.UInt32 module U64 = FStar.UInt64 module Math = FStar.Math.Lemmas module S = FStar.Seq (* Selectively imported from Hacl*'s FStar.Endianness.fst library, with several name changes *) inline_for_extraction noextract type bytes = S.seq U8.t /// lt_to_n interprets a byte sequence as a little-endian natural number [@(deprecated "FStar.Endianness.le_to_n")] val le_to_n : b:bytes -> Tot nat (decreases (S.length b)) let rec le_to_n b = if S.length b = 0 then 0 else U8.v (S.head b) + pow2 8 * le_to_n (S.tail b) /// be_to_n interprets a byte sequence as a big-endian natural number [@(deprecated "FStar.Endianness.be_to_n")] val be_to_n : b:bytes -> Tot nat (decreases (S.length b)) let rec be_to_n b = if S.length b = 0 then 0 else U8.v (S.last b) + pow2 8 * be_to_n (S.slice b 0 (S.length b - 1)) [@(deprecated "FStar.Endianness.lemma_euclidean_division")] private val lemma_euclidean_division: r:nat -> b:nat -> q:pos -> Lemma (requires (r < q)) (ensures (r + q * b < q * (b+1))) let lemma_euclidean_division r b q = () [@(deprecated "FStar.Endianness.lemma_factorise")] private val lemma_factorise: a:nat -> b:nat -> Lemma (a + a * b == a * (b + 1)) let lemma_factorise a b = () [@(deprecated "FStar.Endianness.lemma_le_to_n_is_bounded")] val lemma_le_to_n_is_bounded: b:bytes -> Lemma (requires True) (ensures (le_to_n b < pow2 (8 * Seq.length b))) (decreases (Seq.length b)) let rec lemma_le_to_n_is_bounded b = if Seq.length b = 0 then () else begin let s = Seq.slice b 1 (Seq.length b) in assert(Seq.length s = Seq.length b - 1); lemma_le_to_n_is_bounded s; assert(UInt8.v (Seq.index b 0) < pow2 8); assert(le_to_n s < pow2 (8 * Seq.length s)); assert(le_to_n b < pow2 8 + pow2 8 * pow2 (8 * (Seq.length b - 1))); lemma_euclidean_division (UInt8.v (Seq.index b 0)) (le_to_n s) (pow2 8); assert(le_to_n b <= pow2 8 * (le_to_n s + 1)); assert(le_to_n b <= pow2 8 * pow2 (8 * (Seq.length b - 1))); Math.Lemmas.pow2_plus 8 (8 * (Seq.length b - 1)); lemma_factorise 8 (Seq.length b - 1) end [@(deprecated "FStar.Endianness.lemma_be_to_n_is_bounded")] val lemma_be_to_n_is_bounded: b:bytes -> Lemma (requires True) (ensures (be_to_n b < pow2 (8 * Seq.length b))) (decreases (Seq.length b)) let rec lemma_be_to_n_is_bounded b = if Seq.length b = 0 then () else begin let s = Seq.slice b 0 (Seq.length b - 1) in assert(Seq.length s = Seq.length b - 1); lemma_be_to_n_is_bounded s; assert(UInt8.v (Seq.last b) < pow2 8); assert(be_to_n s < pow2 (8 * Seq.length s)); assert(be_to_n b < pow2 8 + pow2 8 * pow2 (8 * (Seq.length b - 1))); lemma_euclidean_division (UInt8.v (Seq.last b)) (be_to_n s) (pow2 8); assert(be_to_n b <= pow2 8 * (be_to_n s + 1)); assert(be_to_n b <= pow2 8 * pow2 (8 * (Seq.length b - 1))); Math.Lemmas.pow2_plus 8 (8 * (Seq.length b - 1)); lemma_factorise 8 (Seq.length b - 1) end /// n_to_le encodes a number as a little-endian byte sequence of a fixed, /// sufficiently large length [@(deprecated "FStar.Endianness.n_to_le")] val n_to_le : len:U32.t -> n:nat{n < pow2 (8 * U32.v len)} -> Tot (b:bytes{S.length b == U32.v len /\ n == le_to_n b}) (decreases (U32.v len)) let rec n_to_le len n = if len = 0ul then S.empty else let len = U32.(len -^ 1ul) in let byte = U8.uint_to_t (n % 256) in let n' = n / 256 in Math.pow2_plus 8 (8 * U32.v len); assert(n' < pow2 (8 * U32.v len )); let b' = n_to_le len n' in let b = S.cons byte b' in S.lemma_eq_intro b' (S.tail b); b /// n_to_be encodes a numbers as a big-endian byte sequence of a fixed, /// sufficiently large length [@(deprecated "FStar.Endianness.n_to_be")] val n_to_be: len:U32.t -> n:nat{n < pow2 (8 * U32.v len)} -> Tot (b:bytes{S.length b == U32.v len /\ n == be_to_n b}) (decreases (U32.v len)) let rec n_to_be len n = if len = 0ul then S.empty else let len = U32.(len -^ 1ul) in let byte = U8.uint_to_t (n % 256) in let n' = n / 256 in Math.pow2_plus 8 (8 * U32.v len); assert(n' < pow2 (8 * U32.v len )); let b' = n_to_be len n' in let b'' = S.create 1 byte in let b = S.append b' b'' in S.lemma_eq_intro b' (S.slice b 0 (U32.v len)); b [@(deprecated "FStar.Endianness.n_to_le_inj")] let n_to_le_inj (len:U32.t) (n1 n2: (n:nat{n < pow2 (8 * U32.v len)})) : Lemma (requires (n_to_le len n1 == n_to_le len n2)) (ensures (n1 == n2)) = // this lemma easily follows from le_to_n . (n_to_le len) == id, the inversion // proof in the spec for n_to_le () [@(deprecated "FStar.Endianness.n_to_be_inj")] let n_to_be_inj (len:U32.t) (n1 n2: (n:nat{n < pow2 (8 * U32.v len)})) : Lemma (requires (n_to_be len n1 == n_to_be len n2)) (ensures (n1 == n2)) = () [@(deprecated "FStar.Endianness.be_to_n_inj")] let rec be_to_n_inj (b1 b2: Seq.seq U8.t) : Lemma (requires (Seq.length b1 == Seq.length b2 /\ be_to_n b1 == be_to_n b2)) (ensures (Seq.equal b1 b2)) (decreases (Seq.length b1)) = if Seq.length b1 = 0 then () else begin be_to_n_inj (Seq.slice b1 0 (Seq.length b1 - 1)) (Seq.slice b2 0 (Seq.length b2 - 1)); Seq.lemma_split b1 (Seq.length b1 - 1); Seq.lemma_split b2 (Seq.length b2 - 1) end [@(deprecated "FStar.Endianness.le_to_n_inj")] let rec le_to_n_inj (b1 b2: Seq.seq U8.t) : Lemma (requires (Seq.length b1 == Seq.length b2 /\ le_to_n b1 == le_to_n b2)) (ensures (Seq.equal b1 b2)) (decreases (Seq.length b1)) = if Seq.length b1 = 0 then () else begin le_to_n_inj (Seq.slice b1 1 (Seq.length b1)) (Seq.slice b2 1 (Seq.length b2)); Seq.lemma_split b1 1; Seq.lemma_split b2 1 end [@(deprecated "FStar.Endianness.n_to_be_be_to_n")] let n_to_be_be_to_n (len: U32.t) (s: Seq.seq U8.t) : Lemma (requires (Seq.length s == U32.v len)) (ensures ( be_to_n s < pow2 (8 `Prims.op_Multiply` U32.v len) /\ n_to_be len (be_to_n s) == s )) [SMTPat (n_to_be len (be_to_n s))] = lemma_be_to_n_is_bounded s; be_to_n_inj s (n_to_be len (be_to_n s)) [@(deprecated "FStar.Endianness.n_to_le_le_to_n")] let n_to_le_le_to_n (len: U32.t) (s: Seq.seq U8.t) : Lemma (requires (Seq.length s == U32.v len)) (ensures ( le_to_n s < pow2 (8 `Prims.op_Multiply` U32.v len) /\ n_to_le len (le_to_n s) == s )) [SMTPat (n_to_le len (le_to_n s))] = lemma_le_to_n_is_bounded s; le_to_n_inj s (n_to_le len (le_to_n s)) (** A series of specializations to deal with machine integers *) [@(deprecated "FStar.Endianness.uint32_of_le")] let uint32_of_le (b: bytes { S.length b = 4 }) = let n = le_to_n b in lemma_le_to_n_is_bounded b; UInt32.uint_to_t n [@(deprecated "FStar.Endianness.le_of_uint32")] let le_of_uint32 (x: UInt32.t): b:bytes{ S.length b = 4 } = n_to_le 4ul (UInt32.v x) [@(deprecated "FStar.Endianness.uint32_of_be")] let uint32_of_be (b: bytes { S.length b = 4 }) = let n = be_to_n b in lemma_be_to_n_is_bounded b; UInt32.uint_to_t n [@(deprecated "FStar.Endianness.be_of_uint32")] let be_of_uint32 (x: UInt32.t): b:bytes{ S.length b = 4 } = n_to_be 4ul (UInt32.v x) [@(deprecated "FStar.Endianness.uint64_of_le")] let uint64_of_le (b: bytes { S.length b = 8 }) = let n = le_to_n b in lemma_le_to_n_is_bounded b; UInt64.uint_to_t n [@(deprecated "FStar.Endianness.le_of_uint64")] let le_of_uint64 (x: UInt64.t): b:bytes{ S.length b = 8 } = n_to_le 8ul (UInt64.v x) [@(deprecated "FStar.Endianness.uint64_of_be")] let uint64_of_be (b: bytes { S.length b = 8 }) = let n = be_to_n b in lemma_be_to_n_is_bounded b; UInt64.uint_to_t n [@(deprecated "FStar.Endianness.be_of_uint64")] let be_of_uint64 (x: UInt64.t): b:bytes{ S.length b = 8 } = n_to_be 8ul (UInt64.v x) [@(deprecated "FStar.Endianness.seq_uint32_of_le")] let rec seq_uint32_of_le (l: nat) (b: bytes{ S.length b = 4 * l }): s:S.seq UInt32.t { S.length s = l } = if S.length b = 0 then S.empty else let hd, tl = Seq.split b 4 in S.cons (uint32_of_le hd) (seq_uint32_of_le (l - 1) tl) [@(deprecated "FStar.Endianness.le_of_seq_uint32")] let rec le_of_seq_uint32 (s: S.seq UInt32.t): Tot (b:bytes { S.length b = 4 * S.length s }) (decreases (S.length s)) = if S.length s = 0 then S.empty else S.append (le_of_uint32 (S.head s)) (le_of_seq_uint32 (S.tail s)) [@(deprecated "FStar.Endianness.seq_uint32_of_be")] let rec seq_uint32_of_be (l: nat) (b: bytes{ S.length b = 4 * l }): s:S.seq UInt32.t { S.length s = l } = if S.length b = 0 then S.empty else let hd, tl = Seq.split b 4 in S.cons (uint32_of_be hd) (seq_uint32_of_be (l - 1) tl)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.All.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "FStar.Krml.Endianness.fst" }
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Math.Lemmas", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Krml", "short_module": null }, { "abbrev": false, "full_module": "FStar.Krml", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s: FStar.Seq.Base.seq FStar.UInt32.t -> Prims.Tot (b: FStar.Krml.Endianness.bytes{FStar.Seq.Base.length b = 4 * FStar.Seq.Base.length s})
Prims.Tot
[ "total", "" ]
[]
[ "FStar.Seq.Base.seq", "FStar.UInt32.t", "Prims.op_Equality", "Prims.int", "FStar.Seq.Base.length", "FStar.Seq.Base.empty", "FStar.UInt8.t", "Prims.bool", "FStar.Seq.Base.append", "FStar.Krml.Endianness.be_of_uint32", "FStar.Seq.Properties.head", "FStar.Krml.Endianness.be_of_seq_uint32", "FStar.Seq.Properties.tail", "FStar.Krml.Endianness.bytes", "Prims.b2t", "FStar.Mul.op_Star" ]
[ "recursion" ]
false
false
false
false
false
let rec be_of_seq_uint32 (s: S.seq UInt32.t) : Tot (b: bytes{S.length b = 4 * S.length s}) (decreases (S.length s)) =
if S.length s = 0 then S.empty else S.append (be_of_uint32 (S.head s)) (be_of_seq_uint32 (S.tail s))
false
Vale.AES.X64.GF128_Init.fsti
Vale.AES.X64.GF128_Init.va_quick_Keyhash_init
val va_quick_Keyhash_init (win: bool) (alg: algorithm) (key: (seq nat32)) (roundkeys_b hkeys_b: buffer128) : (va_quickCode unit (va_code_Keyhash_init win alg))
val va_quick_Keyhash_init (win: bool) (alg: algorithm) (key: (seq nat32)) (roundkeys_b hkeys_b: buffer128) : (va_quickCode unit (va_code_Keyhash_init win alg))
let va_quick_Keyhash_init (win:bool) (alg:algorithm) (key:(seq nat32)) (roundkeys_b:buffer128) (hkeys_b:buffer128) : (va_quickCode unit (va_code_Keyhash_init win alg)) = (va_QProc (va_code_Keyhash_init win alg) ([va_Mod_flags; va_Mod_xmm 6; va_Mod_xmm 5; va_Mod_xmm 4; va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_xmm 0; va_Mod_mem_layout; va_Mod_mem_heaplet 1; va_Mod_reg64 rR12; va_Mod_reg64 rR8; va_Mod_reg64 rRdx; va_Mod_reg64 rRcx; va_Mod_reg64 rRax; va_Mod_mem]) (va_wp_Keyhash_init win alg key roundkeys_b hkeys_b) (va_wpProof_Keyhash_init win alg key roundkeys_b hkeys_b))
{ "file_name": "obj/Vale.AES.X64.GF128_Init.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 62, "end_line": 146, "start_col": 0, "start_line": 140 }
module Vale.AES.X64.GF128_Init open Vale.Def.Words_s open Vale.Def.Words.Four_s open Vale.Def.Types_s open FStar.Seq open Vale.Arch.Types open Vale.Arch.HeapImpl open Vale.Math.Poly2_s open Vale.Math.Poly2 open Vale.Math.Poly2.Bits_s open Vale.Math.Poly2.Bits open Vale.Math.Poly2.Lemmas open Vale.AES.GF128_s open Vale.AES.GF128 open Vale.AES.GHash open Vale.AES.AES_s open Vale.AES.AES256_helpers open Vale.AES.X64.AES open Vale.X64.Machine_s open Vale.X64.Memory open Vale.X64.State open Vale.X64.Decls open Vale.X64.InsBasic open Vale.X64.InsMem open Vale.X64.InsVector open Vale.X64.InsAes open Vale.X64.QuickCode open Vale.X64.QuickCodes open Vale.X64.CPU_Features_s open Vale.AES.X64.PolyOps open Vale.AES.X64.GF128_Mul open Vale.AES.GHash open Vale.AES.OptPublic //-- Keyhash_init val va_code_Keyhash_init : win:bool -> alg:algorithm -> Tot va_code val va_codegen_success_Keyhash_init : win:bool -> alg:algorithm -> Tot va_pbool let va_req_Keyhash_init (va_b0:va_code) (va_s0:va_state) (win:bool) (alg:algorithm) (key:(seq nat32)) (roundkeys_b:buffer128) (hkeys_b:buffer128) : prop = (va_require_total va_b0 (va_code_Keyhash_init win alg) va_s0 /\ va_get_ok va_s0 /\ (let (round_ptr:(va_int_range 0 18446744073709551615)) = (if win then va_get_reg64 rRcx va_s0 else va_get_reg64 rRdi va_s0) in let (hkey_ptr:(va_int_range 0 18446744073709551615)) = (if win then va_get_reg64 rRdx va_s0 else va_get_reg64 rRsi va_s0) in Vale.X64.Memory.is_initial_heap (va_get_mem_layout va_s0) (va_get_mem va_s0) /\ (aesni_enabled /\ pclmulqdq_enabled /\ avx_enabled /\ sse_enabled) /\ (alg = AES_128 \/ alg = AES_256) /\ Vale.X64.Decls.buffers_disjoint128 roundkeys_b hkeys_b /\ Vale.AES.AES_s.is_aes_key_LE alg key /\ Vale.X64.Decls.buffer128_as_seq (va_get_mem va_s0) roundkeys_b == Vale.AES.AES_s.key_to_round_keys_LE alg key /\ Vale.X64.Decls.validSrcAddrs128 (va_get_mem va_s0) round_ptr roundkeys_b (Vale.AES.AES_common_s.nr alg + 1) (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validDstAddrs128 (va_get_mem va_s0) hkey_ptr hkeys_b 8 (va_get_mem_layout va_s0) Secret)) let va_ens_Keyhash_init (va_b0:va_code) (va_s0:va_state) (win:bool) (alg:algorithm) (key:(seq nat32)) (roundkeys_b:buffer128) (hkeys_b:buffer128) (va_sM:va_state) (va_fM:va_fuel) : prop = (va_req_Keyhash_init va_b0 va_s0 win alg key roundkeys_b hkeys_b /\ va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\ (let (round_ptr:(va_int_range 0 18446744073709551615)) = (if win then va_get_reg64 rRcx va_s0 else va_get_reg64 rRdi va_s0) in let (hkey_ptr:(va_int_range 0 18446744073709551615)) = (if win then va_get_reg64 rRdx va_s0 else va_get_reg64 rRsi va_s0) in Vale.X64.Decls.modifies_buffer128 hkeys_b (va_get_mem va_s0) (va_get_mem va_sM) /\ Vale.AES.OptPublic.hkeys_reqs_pub (Vale.X64.Decls.s128 (va_get_mem va_sM) hkeys_b) (Vale.Def.Types_s.reverse_bytes_quad32 (Vale.AES.AES_s.aes_encrypt_LE alg key (Vale.Def.Words_s.Mkfour #Vale.Def.Types_s.nat32 0 0 0 0))) /\ va_get_xmm 6 va_sM == va_get_xmm 6 va_s0 /\ va_get_reg64 rR12 va_sM == va_get_reg64 rR12 va_s0) /\ va_state_eq va_sM (va_update_flags va_sM (va_update_xmm 6 va_sM (va_update_xmm 5 va_sM (va_update_xmm 4 va_sM (va_update_xmm 3 va_sM (va_update_xmm 2 va_sM (va_update_xmm 1 va_sM (va_update_xmm 0 va_sM (va_update_mem_layout va_sM (va_update_mem_heaplet 1 va_sM (va_update_reg64 rR12 va_sM (va_update_reg64 rR8 va_sM (va_update_reg64 rRdx va_sM (va_update_reg64 rRcx va_sM (va_update_reg64 rRax va_sM (va_update_ok va_sM (va_update_mem va_sM va_s0)))))))))))))))))) val va_lemma_Keyhash_init : va_b0:va_code -> va_s0:va_state -> win:bool -> alg:algorithm -> key:(seq nat32) -> roundkeys_b:buffer128 -> hkeys_b:buffer128 -> Ghost (va_state & va_fuel) (requires (va_require_total va_b0 (va_code_Keyhash_init win alg) va_s0 /\ va_get_ok va_s0 /\ (let (round_ptr:(va_int_range 0 18446744073709551615)) = (if win then va_get_reg64 rRcx va_s0 else va_get_reg64 rRdi va_s0) in let (hkey_ptr:(va_int_range 0 18446744073709551615)) = (if win then va_get_reg64 rRdx va_s0 else va_get_reg64 rRsi va_s0) in Vale.X64.Memory.is_initial_heap (va_get_mem_layout va_s0) (va_get_mem va_s0) /\ (aesni_enabled /\ pclmulqdq_enabled /\ avx_enabled /\ sse_enabled) /\ (alg = AES_128 \/ alg = AES_256) /\ Vale.X64.Decls.buffers_disjoint128 roundkeys_b hkeys_b /\ Vale.AES.AES_s.is_aes_key_LE alg key /\ Vale.X64.Decls.buffer128_as_seq (va_get_mem va_s0) roundkeys_b == Vale.AES.AES_s.key_to_round_keys_LE alg key /\ Vale.X64.Decls.validSrcAddrs128 (va_get_mem va_s0) round_ptr roundkeys_b (Vale.AES.AES_common_s.nr alg + 1) (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validDstAddrs128 (va_get_mem va_s0) hkey_ptr hkeys_b 8 (va_get_mem_layout va_s0) Secret))) (ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\ (let (round_ptr:(va_int_range 0 18446744073709551615)) = (if win then va_get_reg64 rRcx va_s0 else va_get_reg64 rRdi va_s0) in let (hkey_ptr:(va_int_range 0 18446744073709551615)) = (if win then va_get_reg64 rRdx va_s0 else va_get_reg64 rRsi va_s0) in Vale.X64.Decls.modifies_buffer128 hkeys_b (va_get_mem va_s0) (va_get_mem va_sM) /\ Vale.AES.OptPublic.hkeys_reqs_pub (Vale.X64.Decls.s128 (va_get_mem va_sM) hkeys_b) (Vale.Def.Types_s.reverse_bytes_quad32 (Vale.AES.AES_s.aes_encrypt_LE alg key (Vale.Def.Words_s.Mkfour #Vale.Def.Types_s.nat32 0 0 0 0))) /\ va_get_xmm 6 va_sM == va_get_xmm 6 va_s0 /\ va_get_reg64 rR12 va_sM == va_get_reg64 rR12 va_s0) /\ va_state_eq va_sM (va_update_flags va_sM (va_update_xmm 6 va_sM (va_update_xmm 5 va_sM (va_update_xmm 4 va_sM (va_update_xmm 3 va_sM (va_update_xmm 2 va_sM (va_update_xmm 1 va_sM (va_update_xmm 0 va_sM (va_update_mem_layout va_sM (va_update_mem_heaplet 1 va_sM (va_update_reg64 rR12 va_sM (va_update_reg64 rR8 va_sM (va_update_reg64 rRdx va_sM (va_update_reg64 rRcx va_sM (va_update_reg64 rRax va_sM (va_update_ok va_sM (va_update_mem va_sM va_s0))))))))))))))))))) [@ va_qattr] let va_wp_Keyhash_init (win:bool) (alg:algorithm) (key:(seq nat32)) (roundkeys_b:buffer128) (hkeys_b:buffer128) (va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 = (va_get_ok va_s0 /\ (let (round_ptr:(va_int_range 0 18446744073709551615)) = va_if win (fun _ -> va_get_reg64 rRcx va_s0) (fun _ -> va_get_reg64 rRdi va_s0) in let (hkey_ptr:(va_int_range 0 18446744073709551615)) = va_if win (fun _ -> va_get_reg64 rRdx va_s0) (fun _ -> va_get_reg64 rRsi va_s0) in Vale.X64.Memory.is_initial_heap (va_get_mem_layout va_s0) (va_get_mem va_s0) /\ (aesni_enabled /\ pclmulqdq_enabled /\ avx_enabled /\ sse_enabled) /\ (alg = AES_128 \/ alg = AES_256) /\ Vale.X64.Decls.buffers_disjoint128 roundkeys_b hkeys_b /\ Vale.AES.AES_s.is_aes_key_LE alg key /\ Vale.X64.Decls.buffer128_as_seq (va_get_mem va_s0) roundkeys_b == Vale.AES.AES_s.key_to_round_keys_LE alg key /\ Vale.X64.Decls.validSrcAddrs128 (va_get_mem va_s0) round_ptr roundkeys_b (Vale.AES.AES_common_s.nr alg + 1) (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validDstAddrs128 (va_get_mem va_s0) hkey_ptr hkeys_b 8 (va_get_mem_layout va_s0) Secret) /\ (forall (va_x_mem:vale_heap) (va_x_rax:nat64) (va_x_rcx:nat64) (va_x_rdx:nat64) (va_x_r8:nat64) (va_x_r12:nat64) (va_x_heap1:vale_heap) (va_x_memLayout:vale_heap_layout) (va_x_xmm0:quad32) (va_x_xmm1:quad32) (va_x_xmm2:quad32) (va_x_xmm3:quad32) (va_x_xmm4:quad32) (va_x_xmm5:quad32) (va_x_xmm6:quad32) (va_x_efl:Vale.X64.Flags.t) . let va_sM = va_upd_flags va_x_efl (va_upd_xmm 6 va_x_xmm6 (va_upd_xmm 5 va_x_xmm5 (va_upd_xmm 4 va_x_xmm4 (va_upd_xmm 3 va_x_xmm3 (va_upd_xmm 2 va_x_xmm2 (va_upd_xmm 1 va_x_xmm1 (va_upd_xmm 0 va_x_xmm0 (va_upd_mem_layout va_x_memLayout (va_upd_mem_heaplet 1 va_x_heap1 (va_upd_reg64 rR12 va_x_r12 (va_upd_reg64 rR8 va_x_r8 (va_upd_reg64 rRdx va_x_rdx (va_upd_reg64 rRcx va_x_rcx (va_upd_reg64 rRax va_x_rax (va_upd_mem va_x_mem va_s0))))))))))))))) in va_get_ok va_sM /\ (let (round_ptr:(va_int_range 0 18446744073709551615)) = va_if win (fun _ -> va_get_reg64 rRcx va_s0) (fun _ -> va_get_reg64 rRdi va_s0) in let (hkey_ptr:(va_int_range 0 18446744073709551615)) = va_if win (fun _ -> va_get_reg64 rRdx va_s0) (fun _ -> va_get_reg64 rRsi va_s0) in Vale.X64.Decls.modifies_buffer128 hkeys_b (va_get_mem va_s0) (va_get_mem va_sM) /\ Vale.AES.OptPublic.hkeys_reqs_pub (Vale.X64.Decls.s128 (va_get_mem va_sM) hkeys_b) (Vale.Def.Types_s.reverse_bytes_quad32 (Vale.AES.AES_s.aes_encrypt_LE alg key (Vale.Def.Words_s.Mkfour #Vale.Def.Types_s.nat32 0 0 0 0))) /\ va_get_xmm 6 va_sM == va_get_xmm 6 va_s0 /\ va_get_reg64 rR12 va_sM == va_get_reg64 rR12 va_s0) ==> va_k va_sM (()))) val va_wpProof_Keyhash_init : win:bool -> alg:algorithm -> key:(seq nat32) -> roundkeys_b:buffer128 -> hkeys_b:buffer128 -> va_s0:va_state -> va_k:(va_state -> unit -> Type0) -> Ghost (va_state & va_fuel & unit) (requires (va_t_require va_s0 /\ va_wp_Keyhash_init win alg key roundkeys_b hkeys_b va_s0 va_k)) (ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_Keyhash_init win alg) ([va_Mod_flags; va_Mod_xmm 6; va_Mod_xmm 5; va_Mod_xmm 4; va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_xmm 0; va_Mod_mem_layout; va_Mod_mem_heaplet 1; va_Mod_reg64 rR12; va_Mod_reg64 rR8; va_Mod_reg64 rRdx; va_Mod_reg64 rRcx; va_Mod_reg64 rRax; va_Mod_mem]) va_s0 va_k ((va_sM, va_f0, va_g))))
{ "checked_file": "/", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.QuickCodes.fsti.checked", "Vale.X64.QuickCode.fst.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.InsVector.fsti.checked", "Vale.X64.InsMem.fsti.checked", "Vale.X64.InsBasic.fsti.checked", "Vale.X64.InsAes.fsti.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Decls.fsti.checked", "Vale.X64.CPU_Features_s.fst.checked", "Vale.Math.Poly2_s.fsti.checked", "Vale.Math.Poly2.Lemmas.fsti.checked", "Vale.Math.Poly2.Bits_s.fsti.checked", "Vale.Math.Poly2.Bits.fsti.checked", "Vale.Math.Poly2.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Arch.Types.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "Vale.AES.X64.PolyOps.fsti.checked", "Vale.AES.X64.GF128_Mul.fsti.checked", "Vale.AES.X64.AES.fsti.checked", "Vale.AES.OptPublic.fsti.checked", "Vale.AES.GHash.fsti.checked", "Vale.AES.GF128_s.fsti.checked", "Vale.AES.GF128.fsti.checked", "Vale.AES.AES_s.fst.checked", "Vale.AES.AES_common_s.fst.checked", "Vale.AES.AES256_helpers.fsti.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Vale.AES.X64.GF128_Init.fsti" }
[ { "abbrev": false, "full_module": "Vale.AES.OptPublic", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.X64.GF128_Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.X64.PolyOps", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.CPU_Features_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCodes", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsAes", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsVector", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsMem", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsBasic", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.X64.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES256_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
win: Prims.bool -> alg: Vale.AES.AES_common_s.algorithm -> key: FStar.Seq.Base.seq Vale.X64.Memory.nat32 -> roundkeys_b: Vale.X64.Memory.buffer128 -> hkeys_b: Vale.X64.Memory.buffer128 -> Vale.X64.QuickCode.va_quickCode Prims.unit (Vale.AES.X64.GF128_Init.va_code_Keyhash_init win alg)
Prims.Tot
[ "total" ]
[]
[ "Prims.bool", "Vale.AES.AES_common_s.algorithm", "FStar.Seq.Base.seq", "Vale.X64.Memory.nat32", "Vale.X64.Memory.buffer128", "Vale.X64.QuickCode.va_QProc", "Prims.unit", "Vale.AES.X64.GF128_Init.va_code_Keyhash_init", "Prims.Cons", "Vale.X64.QuickCode.mod_t", "Vale.X64.QuickCode.va_Mod_flags", "Vale.X64.QuickCode.va_Mod_xmm", "Vale.X64.QuickCode.va_Mod_mem_layout", "Vale.X64.QuickCode.va_Mod_mem_heaplet", "Vale.X64.QuickCode.va_Mod_reg64", "Vale.X64.Machine_s.rR12", "Vale.X64.Machine_s.rR8", "Vale.X64.Machine_s.rRdx", "Vale.X64.Machine_s.rRcx", "Vale.X64.Machine_s.rRax", "Vale.X64.QuickCode.va_Mod_mem", "Prims.Nil", "Vale.AES.X64.GF128_Init.va_wp_Keyhash_init", "Vale.AES.X64.GF128_Init.va_wpProof_Keyhash_init", "Vale.X64.QuickCode.va_quickCode" ]
[]
false
false
false
false
false
let va_quick_Keyhash_init (win: bool) (alg: algorithm) (key: (seq nat32)) (roundkeys_b hkeys_b: buffer128) : (va_quickCode unit (va_code_Keyhash_init win alg)) =
(va_QProc (va_code_Keyhash_init win alg) ([ va_Mod_flags; va_Mod_xmm 6; va_Mod_xmm 5; va_Mod_xmm 4; va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_xmm 0; va_Mod_mem_layout; va_Mod_mem_heaplet 1; va_Mod_reg64 rR12; va_Mod_reg64 rR8; va_Mod_reg64 rRdx; va_Mod_reg64 rRcx; va_Mod_reg64 rRax; va_Mod_mem ]) (va_wp_Keyhash_init win alg key roundkeys_b hkeys_b) (va_wpProof_Keyhash_init win alg key roundkeys_b hkeys_b))
false
FStar.Krml.Endianness.fst
FStar.Krml.Endianness.seq_uint32_of_le
val seq_uint32_of_le (l: nat) (b: bytes{S.length b = 4 * l}) : s: S.seq UInt32.t {S.length s = l}
val seq_uint32_of_le (l: nat) (b: bytes{S.length b = 4 * l}) : s: S.seq UInt32.t {S.length s = l}
let rec seq_uint32_of_le (l: nat) (b: bytes{ S.length b = 4 * l }): s:S.seq UInt32.t { S.length s = l } = if S.length b = 0 then S.empty else let hd, tl = Seq.split b 4 in S.cons (uint32_of_le hd) (seq_uint32_of_le (l - 1) tl)
{ "file_name": "krmllib/FStar.Krml.Endianness.fst", "git_rev": "da1e941b2fcb196aa5d1e34941aa00b4c67ac321", "git_url": "https://github.com/FStarLang/karamel.git", "project_name": "karamel" }
{ "end_col": 58, "end_line": 244, "start_col": 0, "start_line": 237 }
module FStar.Krml.Endianness open FStar.Mul open FStar.HyperStack.All module U8 = FStar.UInt8 module U32 = FStar.UInt32 module U64 = FStar.UInt64 module Math = FStar.Math.Lemmas module S = FStar.Seq (* Selectively imported from Hacl*'s FStar.Endianness.fst library, with several name changes *) inline_for_extraction noextract type bytes = S.seq U8.t /// lt_to_n interprets a byte sequence as a little-endian natural number [@(deprecated "FStar.Endianness.le_to_n")] val le_to_n : b:bytes -> Tot nat (decreases (S.length b)) let rec le_to_n b = if S.length b = 0 then 0 else U8.v (S.head b) + pow2 8 * le_to_n (S.tail b) /// be_to_n interprets a byte sequence as a big-endian natural number [@(deprecated "FStar.Endianness.be_to_n")] val be_to_n : b:bytes -> Tot nat (decreases (S.length b)) let rec be_to_n b = if S.length b = 0 then 0 else U8.v (S.last b) + pow2 8 * be_to_n (S.slice b 0 (S.length b - 1)) [@(deprecated "FStar.Endianness.lemma_euclidean_division")] private val lemma_euclidean_division: r:nat -> b:nat -> q:pos -> Lemma (requires (r < q)) (ensures (r + q * b < q * (b+1))) let lemma_euclidean_division r b q = () [@(deprecated "FStar.Endianness.lemma_factorise")] private val lemma_factorise: a:nat -> b:nat -> Lemma (a + a * b == a * (b + 1)) let lemma_factorise a b = () [@(deprecated "FStar.Endianness.lemma_le_to_n_is_bounded")] val lemma_le_to_n_is_bounded: b:bytes -> Lemma (requires True) (ensures (le_to_n b < pow2 (8 * Seq.length b))) (decreases (Seq.length b)) let rec lemma_le_to_n_is_bounded b = if Seq.length b = 0 then () else begin let s = Seq.slice b 1 (Seq.length b) in assert(Seq.length s = Seq.length b - 1); lemma_le_to_n_is_bounded s; assert(UInt8.v (Seq.index b 0) < pow2 8); assert(le_to_n s < pow2 (8 * Seq.length s)); assert(le_to_n b < pow2 8 + pow2 8 * pow2 (8 * (Seq.length b - 1))); lemma_euclidean_division (UInt8.v (Seq.index b 0)) (le_to_n s) (pow2 8); assert(le_to_n b <= pow2 8 * (le_to_n s + 1)); assert(le_to_n b <= pow2 8 * pow2 (8 * (Seq.length b - 1))); Math.Lemmas.pow2_plus 8 (8 * (Seq.length b - 1)); lemma_factorise 8 (Seq.length b - 1) end [@(deprecated "FStar.Endianness.lemma_be_to_n_is_bounded")] val lemma_be_to_n_is_bounded: b:bytes -> Lemma (requires True) (ensures (be_to_n b < pow2 (8 * Seq.length b))) (decreases (Seq.length b)) let rec lemma_be_to_n_is_bounded b = if Seq.length b = 0 then () else begin let s = Seq.slice b 0 (Seq.length b - 1) in assert(Seq.length s = Seq.length b - 1); lemma_be_to_n_is_bounded s; assert(UInt8.v (Seq.last b) < pow2 8); assert(be_to_n s < pow2 (8 * Seq.length s)); assert(be_to_n b < pow2 8 + pow2 8 * pow2 (8 * (Seq.length b - 1))); lemma_euclidean_division (UInt8.v (Seq.last b)) (be_to_n s) (pow2 8); assert(be_to_n b <= pow2 8 * (be_to_n s + 1)); assert(be_to_n b <= pow2 8 * pow2 (8 * (Seq.length b - 1))); Math.Lemmas.pow2_plus 8 (8 * (Seq.length b - 1)); lemma_factorise 8 (Seq.length b - 1) end /// n_to_le encodes a number as a little-endian byte sequence of a fixed, /// sufficiently large length [@(deprecated "FStar.Endianness.n_to_le")] val n_to_le : len:U32.t -> n:nat{n < pow2 (8 * U32.v len)} -> Tot (b:bytes{S.length b == U32.v len /\ n == le_to_n b}) (decreases (U32.v len)) let rec n_to_le len n = if len = 0ul then S.empty else let len = U32.(len -^ 1ul) in let byte = U8.uint_to_t (n % 256) in let n' = n / 256 in Math.pow2_plus 8 (8 * U32.v len); assert(n' < pow2 (8 * U32.v len )); let b' = n_to_le len n' in let b = S.cons byte b' in S.lemma_eq_intro b' (S.tail b); b /// n_to_be encodes a numbers as a big-endian byte sequence of a fixed, /// sufficiently large length [@(deprecated "FStar.Endianness.n_to_be")] val n_to_be: len:U32.t -> n:nat{n < pow2 (8 * U32.v len)} -> Tot (b:bytes{S.length b == U32.v len /\ n == be_to_n b}) (decreases (U32.v len)) let rec n_to_be len n = if len = 0ul then S.empty else let len = U32.(len -^ 1ul) in let byte = U8.uint_to_t (n % 256) in let n' = n / 256 in Math.pow2_plus 8 (8 * U32.v len); assert(n' < pow2 (8 * U32.v len )); let b' = n_to_be len n' in let b'' = S.create 1 byte in let b = S.append b' b'' in S.lemma_eq_intro b' (S.slice b 0 (U32.v len)); b [@(deprecated "FStar.Endianness.n_to_le_inj")] let n_to_le_inj (len:U32.t) (n1 n2: (n:nat{n < pow2 (8 * U32.v len)})) : Lemma (requires (n_to_le len n1 == n_to_le len n2)) (ensures (n1 == n2)) = // this lemma easily follows from le_to_n . (n_to_le len) == id, the inversion // proof in the spec for n_to_le () [@(deprecated "FStar.Endianness.n_to_be_inj")] let n_to_be_inj (len:U32.t) (n1 n2: (n:nat{n < pow2 (8 * U32.v len)})) : Lemma (requires (n_to_be len n1 == n_to_be len n2)) (ensures (n1 == n2)) = () [@(deprecated "FStar.Endianness.be_to_n_inj")] let rec be_to_n_inj (b1 b2: Seq.seq U8.t) : Lemma (requires (Seq.length b1 == Seq.length b2 /\ be_to_n b1 == be_to_n b2)) (ensures (Seq.equal b1 b2)) (decreases (Seq.length b1)) = if Seq.length b1 = 0 then () else begin be_to_n_inj (Seq.slice b1 0 (Seq.length b1 - 1)) (Seq.slice b2 0 (Seq.length b2 - 1)); Seq.lemma_split b1 (Seq.length b1 - 1); Seq.lemma_split b2 (Seq.length b2 - 1) end [@(deprecated "FStar.Endianness.le_to_n_inj")] let rec le_to_n_inj (b1 b2: Seq.seq U8.t) : Lemma (requires (Seq.length b1 == Seq.length b2 /\ le_to_n b1 == le_to_n b2)) (ensures (Seq.equal b1 b2)) (decreases (Seq.length b1)) = if Seq.length b1 = 0 then () else begin le_to_n_inj (Seq.slice b1 1 (Seq.length b1)) (Seq.slice b2 1 (Seq.length b2)); Seq.lemma_split b1 1; Seq.lemma_split b2 1 end [@(deprecated "FStar.Endianness.n_to_be_be_to_n")] let n_to_be_be_to_n (len: U32.t) (s: Seq.seq U8.t) : Lemma (requires (Seq.length s == U32.v len)) (ensures ( be_to_n s < pow2 (8 `Prims.op_Multiply` U32.v len) /\ n_to_be len (be_to_n s) == s )) [SMTPat (n_to_be len (be_to_n s))] = lemma_be_to_n_is_bounded s; be_to_n_inj s (n_to_be len (be_to_n s)) [@(deprecated "FStar.Endianness.n_to_le_le_to_n")] let n_to_le_le_to_n (len: U32.t) (s: Seq.seq U8.t) : Lemma (requires (Seq.length s == U32.v len)) (ensures ( le_to_n s < pow2 (8 `Prims.op_Multiply` U32.v len) /\ n_to_le len (le_to_n s) == s )) [SMTPat (n_to_le len (le_to_n s))] = lemma_le_to_n_is_bounded s; le_to_n_inj s (n_to_le len (le_to_n s)) (** A series of specializations to deal with machine integers *) [@(deprecated "FStar.Endianness.uint32_of_le")] let uint32_of_le (b: bytes { S.length b = 4 }) = let n = le_to_n b in lemma_le_to_n_is_bounded b; UInt32.uint_to_t n [@(deprecated "FStar.Endianness.le_of_uint32")] let le_of_uint32 (x: UInt32.t): b:bytes{ S.length b = 4 } = n_to_le 4ul (UInt32.v x) [@(deprecated "FStar.Endianness.uint32_of_be")] let uint32_of_be (b: bytes { S.length b = 4 }) = let n = be_to_n b in lemma_be_to_n_is_bounded b; UInt32.uint_to_t n [@(deprecated "FStar.Endianness.be_of_uint32")] let be_of_uint32 (x: UInt32.t): b:bytes{ S.length b = 4 } = n_to_be 4ul (UInt32.v x) [@(deprecated "FStar.Endianness.uint64_of_le")] let uint64_of_le (b: bytes { S.length b = 8 }) = let n = le_to_n b in lemma_le_to_n_is_bounded b; UInt64.uint_to_t n [@(deprecated "FStar.Endianness.le_of_uint64")] let le_of_uint64 (x: UInt64.t): b:bytes{ S.length b = 8 } = n_to_le 8ul (UInt64.v x) [@(deprecated "FStar.Endianness.uint64_of_be")] let uint64_of_be (b: bytes { S.length b = 8 }) = let n = be_to_n b in lemma_be_to_n_is_bounded b; UInt64.uint_to_t n [@(deprecated "FStar.Endianness.be_of_uint64")] let be_of_uint64 (x: UInt64.t): b:bytes{ S.length b = 8 } = n_to_be 8ul (UInt64.v x)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.All.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "FStar.Krml.Endianness.fst" }
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Math.Lemmas", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Krml", "short_module": null }, { "abbrev": false, "full_module": "FStar.Krml", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
l: Prims.nat -> b: FStar.Krml.Endianness.bytes{FStar.Seq.Base.length b = 4 * l} -> s: FStar.Seq.Base.seq FStar.UInt32.t {FStar.Seq.Base.length s = l}
Prims.Tot
[ "total" ]
[]
[ "Prims.nat", "FStar.Krml.Endianness.bytes", "Prims.b2t", "Prims.op_Equality", "Prims.int", "FStar.Seq.Base.length", "FStar.UInt8.t", "FStar.Mul.op_Star", "FStar.Seq.Base.empty", "FStar.UInt32.t", "Prims.bool", "FStar.Seq.Base.seq", "FStar.Seq.Base.cons", "FStar.Krml.Endianness.uint32_of_le", "FStar.Krml.Endianness.seq_uint32_of_le", "Prims.op_Subtraction", "FStar.Pervasives.Native.tuple2", "FStar.Seq.Properties.split" ]
[ "recursion" ]
false
false
false
false
false
let rec seq_uint32_of_le (l: nat) (b: bytes{S.length b = 4 * l}) : s: S.seq UInt32.t {S.length s = l} =
if S.length b = 0 then S.empty else let hd, tl = Seq.split b 4 in S.cons (uint32_of_le hd) (seq_uint32_of_le (l - 1) tl)
false
FStar.Krml.Endianness.fst
FStar.Krml.Endianness.seq_uint64_of_le
val seq_uint64_of_le (l: nat) (b: bytes{S.length b = 8 * l}) : s: S.seq UInt64.t {S.length s = l}
val seq_uint64_of_le (l: nat) (b: bytes{S.length b = 8 * l}) : s: S.seq UInt64.t {S.length s = l}
let rec seq_uint64_of_le (l: nat) (b: bytes{ S.length b = 8 * l }): s:S.seq UInt64.t { S.length s = l } = if S.length b = 0 then S.empty else let hd, tl = Seq.split b 8 in S.cons (uint64_of_le hd) (seq_uint64_of_le (l - 1) tl)
{ "file_name": "krmllib/FStar.Krml.Endianness.fst", "git_rev": "da1e941b2fcb196aa5d1e34941aa00b4c67ac321", "git_url": "https://github.com/FStarLang/karamel.git", "project_name": "karamel" }
{ "end_col": 58, "end_line": 284, "start_col": 0, "start_line": 277 }
module FStar.Krml.Endianness open FStar.Mul open FStar.HyperStack.All module U8 = FStar.UInt8 module U32 = FStar.UInt32 module U64 = FStar.UInt64 module Math = FStar.Math.Lemmas module S = FStar.Seq (* Selectively imported from Hacl*'s FStar.Endianness.fst library, with several name changes *) inline_for_extraction noextract type bytes = S.seq U8.t /// lt_to_n interprets a byte sequence as a little-endian natural number [@(deprecated "FStar.Endianness.le_to_n")] val le_to_n : b:bytes -> Tot nat (decreases (S.length b)) let rec le_to_n b = if S.length b = 0 then 0 else U8.v (S.head b) + pow2 8 * le_to_n (S.tail b) /// be_to_n interprets a byte sequence as a big-endian natural number [@(deprecated "FStar.Endianness.be_to_n")] val be_to_n : b:bytes -> Tot nat (decreases (S.length b)) let rec be_to_n b = if S.length b = 0 then 0 else U8.v (S.last b) + pow2 8 * be_to_n (S.slice b 0 (S.length b - 1)) [@(deprecated "FStar.Endianness.lemma_euclidean_division")] private val lemma_euclidean_division: r:nat -> b:nat -> q:pos -> Lemma (requires (r < q)) (ensures (r + q * b < q * (b+1))) let lemma_euclidean_division r b q = () [@(deprecated "FStar.Endianness.lemma_factorise")] private val lemma_factorise: a:nat -> b:nat -> Lemma (a + a * b == a * (b + 1)) let lemma_factorise a b = () [@(deprecated "FStar.Endianness.lemma_le_to_n_is_bounded")] val lemma_le_to_n_is_bounded: b:bytes -> Lemma (requires True) (ensures (le_to_n b < pow2 (8 * Seq.length b))) (decreases (Seq.length b)) let rec lemma_le_to_n_is_bounded b = if Seq.length b = 0 then () else begin let s = Seq.slice b 1 (Seq.length b) in assert(Seq.length s = Seq.length b - 1); lemma_le_to_n_is_bounded s; assert(UInt8.v (Seq.index b 0) < pow2 8); assert(le_to_n s < pow2 (8 * Seq.length s)); assert(le_to_n b < pow2 8 + pow2 8 * pow2 (8 * (Seq.length b - 1))); lemma_euclidean_division (UInt8.v (Seq.index b 0)) (le_to_n s) (pow2 8); assert(le_to_n b <= pow2 8 * (le_to_n s + 1)); assert(le_to_n b <= pow2 8 * pow2 (8 * (Seq.length b - 1))); Math.Lemmas.pow2_plus 8 (8 * (Seq.length b - 1)); lemma_factorise 8 (Seq.length b - 1) end [@(deprecated "FStar.Endianness.lemma_be_to_n_is_bounded")] val lemma_be_to_n_is_bounded: b:bytes -> Lemma (requires True) (ensures (be_to_n b < pow2 (8 * Seq.length b))) (decreases (Seq.length b)) let rec lemma_be_to_n_is_bounded b = if Seq.length b = 0 then () else begin let s = Seq.slice b 0 (Seq.length b - 1) in assert(Seq.length s = Seq.length b - 1); lemma_be_to_n_is_bounded s; assert(UInt8.v (Seq.last b) < pow2 8); assert(be_to_n s < pow2 (8 * Seq.length s)); assert(be_to_n b < pow2 8 + pow2 8 * pow2 (8 * (Seq.length b - 1))); lemma_euclidean_division (UInt8.v (Seq.last b)) (be_to_n s) (pow2 8); assert(be_to_n b <= pow2 8 * (be_to_n s + 1)); assert(be_to_n b <= pow2 8 * pow2 (8 * (Seq.length b - 1))); Math.Lemmas.pow2_plus 8 (8 * (Seq.length b - 1)); lemma_factorise 8 (Seq.length b - 1) end /// n_to_le encodes a number as a little-endian byte sequence of a fixed, /// sufficiently large length [@(deprecated "FStar.Endianness.n_to_le")] val n_to_le : len:U32.t -> n:nat{n < pow2 (8 * U32.v len)} -> Tot (b:bytes{S.length b == U32.v len /\ n == le_to_n b}) (decreases (U32.v len)) let rec n_to_le len n = if len = 0ul then S.empty else let len = U32.(len -^ 1ul) in let byte = U8.uint_to_t (n % 256) in let n' = n / 256 in Math.pow2_plus 8 (8 * U32.v len); assert(n' < pow2 (8 * U32.v len )); let b' = n_to_le len n' in let b = S.cons byte b' in S.lemma_eq_intro b' (S.tail b); b /// n_to_be encodes a numbers as a big-endian byte sequence of a fixed, /// sufficiently large length [@(deprecated "FStar.Endianness.n_to_be")] val n_to_be: len:U32.t -> n:nat{n < pow2 (8 * U32.v len)} -> Tot (b:bytes{S.length b == U32.v len /\ n == be_to_n b}) (decreases (U32.v len)) let rec n_to_be len n = if len = 0ul then S.empty else let len = U32.(len -^ 1ul) in let byte = U8.uint_to_t (n % 256) in let n' = n / 256 in Math.pow2_plus 8 (8 * U32.v len); assert(n' < pow2 (8 * U32.v len )); let b' = n_to_be len n' in let b'' = S.create 1 byte in let b = S.append b' b'' in S.lemma_eq_intro b' (S.slice b 0 (U32.v len)); b [@(deprecated "FStar.Endianness.n_to_le_inj")] let n_to_le_inj (len:U32.t) (n1 n2: (n:nat{n < pow2 (8 * U32.v len)})) : Lemma (requires (n_to_le len n1 == n_to_le len n2)) (ensures (n1 == n2)) = // this lemma easily follows from le_to_n . (n_to_le len) == id, the inversion // proof in the spec for n_to_le () [@(deprecated "FStar.Endianness.n_to_be_inj")] let n_to_be_inj (len:U32.t) (n1 n2: (n:nat{n < pow2 (8 * U32.v len)})) : Lemma (requires (n_to_be len n1 == n_to_be len n2)) (ensures (n1 == n2)) = () [@(deprecated "FStar.Endianness.be_to_n_inj")] let rec be_to_n_inj (b1 b2: Seq.seq U8.t) : Lemma (requires (Seq.length b1 == Seq.length b2 /\ be_to_n b1 == be_to_n b2)) (ensures (Seq.equal b1 b2)) (decreases (Seq.length b1)) = if Seq.length b1 = 0 then () else begin be_to_n_inj (Seq.slice b1 0 (Seq.length b1 - 1)) (Seq.slice b2 0 (Seq.length b2 - 1)); Seq.lemma_split b1 (Seq.length b1 - 1); Seq.lemma_split b2 (Seq.length b2 - 1) end [@(deprecated "FStar.Endianness.le_to_n_inj")] let rec le_to_n_inj (b1 b2: Seq.seq U8.t) : Lemma (requires (Seq.length b1 == Seq.length b2 /\ le_to_n b1 == le_to_n b2)) (ensures (Seq.equal b1 b2)) (decreases (Seq.length b1)) = if Seq.length b1 = 0 then () else begin le_to_n_inj (Seq.slice b1 1 (Seq.length b1)) (Seq.slice b2 1 (Seq.length b2)); Seq.lemma_split b1 1; Seq.lemma_split b2 1 end [@(deprecated "FStar.Endianness.n_to_be_be_to_n")] let n_to_be_be_to_n (len: U32.t) (s: Seq.seq U8.t) : Lemma (requires (Seq.length s == U32.v len)) (ensures ( be_to_n s < pow2 (8 `Prims.op_Multiply` U32.v len) /\ n_to_be len (be_to_n s) == s )) [SMTPat (n_to_be len (be_to_n s))] = lemma_be_to_n_is_bounded s; be_to_n_inj s (n_to_be len (be_to_n s)) [@(deprecated "FStar.Endianness.n_to_le_le_to_n")] let n_to_le_le_to_n (len: U32.t) (s: Seq.seq U8.t) : Lemma (requires (Seq.length s == U32.v len)) (ensures ( le_to_n s < pow2 (8 `Prims.op_Multiply` U32.v len) /\ n_to_le len (le_to_n s) == s )) [SMTPat (n_to_le len (le_to_n s))] = lemma_le_to_n_is_bounded s; le_to_n_inj s (n_to_le len (le_to_n s)) (** A series of specializations to deal with machine integers *) [@(deprecated "FStar.Endianness.uint32_of_le")] let uint32_of_le (b: bytes { S.length b = 4 }) = let n = le_to_n b in lemma_le_to_n_is_bounded b; UInt32.uint_to_t n [@(deprecated "FStar.Endianness.le_of_uint32")] let le_of_uint32 (x: UInt32.t): b:bytes{ S.length b = 4 } = n_to_le 4ul (UInt32.v x) [@(deprecated "FStar.Endianness.uint32_of_be")] let uint32_of_be (b: bytes { S.length b = 4 }) = let n = be_to_n b in lemma_be_to_n_is_bounded b; UInt32.uint_to_t n [@(deprecated "FStar.Endianness.be_of_uint32")] let be_of_uint32 (x: UInt32.t): b:bytes{ S.length b = 4 } = n_to_be 4ul (UInt32.v x) [@(deprecated "FStar.Endianness.uint64_of_le")] let uint64_of_le (b: bytes { S.length b = 8 }) = let n = le_to_n b in lemma_le_to_n_is_bounded b; UInt64.uint_to_t n [@(deprecated "FStar.Endianness.le_of_uint64")] let le_of_uint64 (x: UInt64.t): b:bytes{ S.length b = 8 } = n_to_le 8ul (UInt64.v x) [@(deprecated "FStar.Endianness.uint64_of_be")] let uint64_of_be (b: bytes { S.length b = 8 }) = let n = be_to_n b in lemma_be_to_n_is_bounded b; UInt64.uint_to_t n [@(deprecated "FStar.Endianness.be_of_uint64")] let be_of_uint64 (x: UInt64.t): b:bytes{ S.length b = 8 } = n_to_be 8ul (UInt64.v x) [@(deprecated "FStar.Endianness.seq_uint32_of_le")] let rec seq_uint32_of_le (l: nat) (b: bytes{ S.length b = 4 * l }): s:S.seq UInt32.t { S.length s = l } = if S.length b = 0 then S.empty else let hd, tl = Seq.split b 4 in S.cons (uint32_of_le hd) (seq_uint32_of_le (l - 1) tl) [@(deprecated "FStar.Endianness.le_of_seq_uint32")] let rec le_of_seq_uint32 (s: S.seq UInt32.t): Tot (b:bytes { S.length b = 4 * S.length s }) (decreases (S.length s)) = if S.length s = 0 then S.empty else S.append (le_of_uint32 (S.head s)) (le_of_seq_uint32 (S.tail s)) [@(deprecated "FStar.Endianness.seq_uint32_of_be")] let rec seq_uint32_of_be (l: nat) (b: bytes{ S.length b = 4 * l }): s:S.seq UInt32.t { S.length s = l } = if S.length b = 0 then S.empty else let hd, tl = Seq.split b 4 in S.cons (uint32_of_be hd) (seq_uint32_of_be (l - 1) tl) [@(deprecated "FStar.Endianness.be_of_seq_uint32")] let rec be_of_seq_uint32 (s: S.seq UInt32.t): Tot (b:bytes { S.length b = 4 * S.length s }) (decreases (S.length s)) = if S.length s = 0 then S.empty else S.append (be_of_uint32 (S.head s)) (be_of_seq_uint32 (S.tail s))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.All.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "FStar.Krml.Endianness.fst" }
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Math.Lemmas", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Krml", "short_module": null }, { "abbrev": false, "full_module": "FStar.Krml", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
l: Prims.nat -> b: FStar.Krml.Endianness.bytes{FStar.Seq.Base.length b = 8 * l} -> s: FStar.Seq.Base.seq FStar.UInt64.t {FStar.Seq.Base.length s = l}
Prims.Tot
[ "total" ]
[]
[ "Prims.nat", "FStar.Krml.Endianness.bytes", "Prims.b2t", "Prims.op_Equality", "Prims.int", "FStar.Seq.Base.length", "FStar.UInt8.t", "FStar.Mul.op_Star", "FStar.Seq.Base.empty", "FStar.UInt64.t", "Prims.bool", "FStar.Seq.Base.seq", "FStar.Seq.Base.cons", "FStar.Krml.Endianness.uint64_of_le", "FStar.Krml.Endianness.seq_uint64_of_le", "Prims.op_Subtraction", "FStar.Pervasives.Native.tuple2", "FStar.Seq.Properties.split" ]
[ "recursion" ]
false
false
false
false
false
let rec seq_uint64_of_le (l: nat) (b: bytes{S.length b = 8 * l}) : s: S.seq UInt64.t {S.length s = l} =
if S.length b = 0 then S.empty else let hd, tl = Seq.split b 8 in S.cons (uint64_of_le hd) (seq_uint64_of_le (l - 1) tl)
false
FStar.Krml.Endianness.fst
FStar.Krml.Endianness.seq_uint32_of_be
val seq_uint32_of_be (l: nat) (b: bytes{S.length b = 4 * l}) : s: S.seq UInt32.t {S.length s = l}
val seq_uint32_of_be (l: nat) (b: bytes{S.length b = 4 * l}) : s: S.seq UInt32.t {S.length s = l}
let rec seq_uint32_of_be (l: nat) (b: bytes{ S.length b = 4 * l }): s:S.seq UInt32.t { S.length s = l } = if S.length b = 0 then S.empty else let hd, tl = Seq.split b 4 in S.cons (uint32_of_be hd) (seq_uint32_of_be (l - 1) tl)
{ "file_name": "krmllib/FStar.Krml.Endianness.fst", "git_rev": "da1e941b2fcb196aa5d1e34941aa00b4c67ac321", "git_url": "https://github.com/FStarLang/karamel.git", "project_name": "karamel" }
{ "end_col": 58, "end_line": 264, "start_col": 0, "start_line": 257 }
module FStar.Krml.Endianness open FStar.Mul open FStar.HyperStack.All module U8 = FStar.UInt8 module U32 = FStar.UInt32 module U64 = FStar.UInt64 module Math = FStar.Math.Lemmas module S = FStar.Seq (* Selectively imported from Hacl*'s FStar.Endianness.fst library, with several name changes *) inline_for_extraction noextract type bytes = S.seq U8.t /// lt_to_n interprets a byte sequence as a little-endian natural number [@(deprecated "FStar.Endianness.le_to_n")] val le_to_n : b:bytes -> Tot nat (decreases (S.length b)) let rec le_to_n b = if S.length b = 0 then 0 else U8.v (S.head b) + pow2 8 * le_to_n (S.tail b) /// be_to_n interprets a byte sequence as a big-endian natural number [@(deprecated "FStar.Endianness.be_to_n")] val be_to_n : b:bytes -> Tot nat (decreases (S.length b)) let rec be_to_n b = if S.length b = 0 then 0 else U8.v (S.last b) + pow2 8 * be_to_n (S.slice b 0 (S.length b - 1)) [@(deprecated "FStar.Endianness.lemma_euclidean_division")] private val lemma_euclidean_division: r:nat -> b:nat -> q:pos -> Lemma (requires (r < q)) (ensures (r + q * b < q * (b+1))) let lemma_euclidean_division r b q = () [@(deprecated "FStar.Endianness.lemma_factorise")] private val lemma_factorise: a:nat -> b:nat -> Lemma (a + a * b == a * (b + 1)) let lemma_factorise a b = () [@(deprecated "FStar.Endianness.lemma_le_to_n_is_bounded")] val lemma_le_to_n_is_bounded: b:bytes -> Lemma (requires True) (ensures (le_to_n b < pow2 (8 * Seq.length b))) (decreases (Seq.length b)) let rec lemma_le_to_n_is_bounded b = if Seq.length b = 0 then () else begin let s = Seq.slice b 1 (Seq.length b) in assert(Seq.length s = Seq.length b - 1); lemma_le_to_n_is_bounded s; assert(UInt8.v (Seq.index b 0) < pow2 8); assert(le_to_n s < pow2 (8 * Seq.length s)); assert(le_to_n b < pow2 8 + pow2 8 * pow2 (8 * (Seq.length b - 1))); lemma_euclidean_division (UInt8.v (Seq.index b 0)) (le_to_n s) (pow2 8); assert(le_to_n b <= pow2 8 * (le_to_n s + 1)); assert(le_to_n b <= pow2 8 * pow2 (8 * (Seq.length b - 1))); Math.Lemmas.pow2_plus 8 (8 * (Seq.length b - 1)); lemma_factorise 8 (Seq.length b - 1) end [@(deprecated "FStar.Endianness.lemma_be_to_n_is_bounded")] val lemma_be_to_n_is_bounded: b:bytes -> Lemma (requires True) (ensures (be_to_n b < pow2 (8 * Seq.length b))) (decreases (Seq.length b)) let rec lemma_be_to_n_is_bounded b = if Seq.length b = 0 then () else begin let s = Seq.slice b 0 (Seq.length b - 1) in assert(Seq.length s = Seq.length b - 1); lemma_be_to_n_is_bounded s; assert(UInt8.v (Seq.last b) < pow2 8); assert(be_to_n s < pow2 (8 * Seq.length s)); assert(be_to_n b < pow2 8 + pow2 8 * pow2 (8 * (Seq.length b - 1))); lemma_euclidean_division (UInt8.v (Seq.last b)) (be_to_n s) (pow2 8); assert(be_to_n b <= pow2 8 * (be_to_n s + 1)); assert(be_to_n b <= pow2 8 * pow2 (8 * (Seq.length b - 1))); Math.Lemmas.pow2_plus 8 (8 * (Seq.length b - 1)); lemma_factorise 8 (Seq.length b - 1) end /// n_to_le encodes a number as a little-endian byte sequence of a fixed, /// sufficiently large length [@(deprecated "FStar.Endianness.n_to_le")] val n_to_le : len:U32.t -> n:nat{n < pow2 (8 * U32.v len)} -> Tot (b:bytes{S.length b == U32.v len /\ n == le_to_n b}) (decreases (U32.v len)) let rec n_to_le len n = if len = 0ul then S.empty else let len = U32.(len -^ 1ul) in let byte = U8.uint_to_t (n % 256) in let n' = n / 256 in Math.pow2_plus 8 (8 * U32.v len); assert(n' < pow2 (8 * U32.v len )); let b' = n_to_le len n' in let b = S.cons byte b' in S.lemma_eq_intro b' (S.tail b); b /// n_to_be encodes a numbers as a big-endian byte sequence of a fixed, /// sufficiently large length [@(deprecated "FStar.Endianness.n_to_be")] val n_to_be: len:U32.t -> n:nat{n < pow2 (8 * U32.v len)} -> Tot (b:bytes{S.length b == U32.v len /\ n == be_to_n b}) (decreases (U32.v len)) let rec n_to_be len n = if len = 0ul then S.empty else let len = U32.(len -^ 1ul) in let byte = U8.uint_to_t (n % 256) in let n' = n / 256 in Math.pow2_plus 8 (8 * U32.v len); assert(n' < pow2 (8 * U32.v len )); let b' = n_to_be len n' in let b'' = S.create 1 byte in let b = S.append b' b'' in S.lemma_eq_intro b' (S.slice b 0 (U32.v len)); b [@(deprecated "FStar.Endianness.n_to_le_inj")] let n_to_le_inj (len:U32.t) (n1 n2: (n:nat{n < pow2 (8 * U32.v len)})) : Lemma (requires (n_to_le len n1 == n_to_le len n2)) (ensures (n1 == n2)) = // this lemma easily follows from le_to_n . (n_to_le len) == id, the inversion // proof in the spec for n_to_le () [@(deprecated "FStar.Endianness.n_to_be_inj")] let n_to_be_inj (len:U32.t) (n1 n2: (n:nat{n < pow2 (8 * U32.v len)})) : Lemma (requires (n_to_be len n1 == n_to_be len n2)) (ensures (n1 == n2)) = () [@(deprecated "FStar.Endianness.be_to_n_inj")] let rec be_to_n_inj (b1 b2: Seq.seq U8.t) : Lemma (requires (Seq.length b1 == Seq.length b2 /\ be_to_n b1 == be_to_n b2)) (ensures (Seq.equal b1 b2)) (decreases (Seq.length b1)) = if Seq.length b1 = 0 then () else begin be_to_n_inj (Seq.slice b1 0 (Seq.length b1 - 1)) (Seq.slice b2 0 (Seq.length b2 - 1)); Seq.lemma_split b1 (Seq.length b1 - 1); Seq.lemma_split b2 (Seq.length b2 - 1) end [@(deprecated "FStar.Endianness.le_to_n_inj")] let rec le_to_n_inj (b1 b2: Seq.seq U8.t) : Lemma (requires (Seq.length b1 == Seq.length b2 /\ le_to_n b1 == le_to_n b2)) (ensures (Seq.equal b1 b2)) (decreases (Seq.length b1)) = if Seq.length b1 = 0 then () else begin le_to_n_inj (Seq.slice b1 1 (Seq.length b1)) (Seq.slice b2 1 (Seq.length b2)); Seq.lemma_split b1 1; Seq.lemma_split b2 1 end [@(deprecated "FStar.Endianness.n_to_be_be_to_n")] let n_to_be_be_to_n (len: U32.t) (s: Seq.seq U8.t) : Lemma (requires (Seq.length s == U32.v len)) (ensures ( be_to_n s < pow2 (8 `Prims.op_Multiply` U32.v len) /\ n_to_be len (be_to_n s) == s )) [SMTPat (n_to_be len (be_to_n s))] = lemma_be_to_n_is_bounded s; be_to_n_inj s (n_to_be len (be_to_n s)) [@(deprecated "FStar.Endianness.n_to_le_le_to_n")] let n_to_le_le_to_n (len: U32.t) (s: Seq.seq U8.t) : Lemma (requires (Seq.length s == U32.v len)) (ensures ( le_to_n s < pow2 (8 `Prims.op_Multiply` U32.v len) /\ n_to_le len (le_to_n s) == s )) [SMTPat (n_to_le len (le_to_n s))] = lemma_le_to_n_is_bounded s; le_to_n_inj s (n_to_le len (le_to_n s)) (** A series of specializations to deal with machine integers *) [@(deprecated "FStar.Endianness.uint32_of_le")] let uint32_of_le (b: bytes { S.length b = 4 }) = let n = le_to_n b in lemma_le_to_n_is_bounded b; UInt32.uint_to_t n [@(deprecated "FStar.Endianness.le_of_uint32")] let le_of_uint32 (x: UInt32.t): b:bytes{ S.length b = 4 } = n_to_le 4ul (UInt32.v x) [@(deprecated "FStar.Endianness.uint32_of_be")] let uint32_of_be (b: bytes { S.length b = 4 }) = let n = be_to_n b in lemma_be_to_n_is_bounded b; UInt32.uint_to_t n [@(deprecated "FStar.Endianness.be_of_uint32")] let be_of_uint32 (x: UInt32.t): b:bytes{ S.length b = 4 } = n_to_be 4ul (UInt32.v x) [@(deprecated "FStar.Endianness.uint64_of_le")] let uint64_of_le (b: bytes { S.length b = 8 }) = let n = le_to_n b in lemma_le_to_n_is_bounded b; UInt64.uint_to_t n [@(deprecated "FStar.Endianness.le_of_uint64")] let le_of_uint64 (x: UInt64.t): b:bytes{ S.length b = 8 } = n_to_le 8ul (UInt64.v x) [@(deprecated "FStar.Endianness.uint64_of_be")] let uint64_of_be (b: bytes { S.length b = 8 }) = let n = be_to_n b in lemma_be_to_n_is_bounded b; UInt64.uint_to_t n [@(deprecated "FStar.Endianness.be_of_uint64")] let be_of_uint64 (x: UInt64.t): b:bytes{ S.length b = 8 } = n_to_be 8ul (UInt64.v x) [@(deprecated "FStar.Endianness.seq_uint32_of_le")] let rec seq_uint32_of_le (l: nat) (b: bytes{ S.length b = 4 * l }): s:S.seq UInt32.t { S.length s = l } = if S.length b = 0 then S.empty else let hd, tl = Seq.split b 4 in S.cons (uint32_of_le hd) (seq_uint32_of_le (l - 1) tl) [@(deprecated "FStar.Endianness.le_of_seq_uint32")] let rec le_of_seq_uint32 (s: S.seq UInt32.t): Tot (b:bytes { S.length b = 4 * S.length s }) (decreases (S.length s)) = if S.length s = 0 then S.empty else S.append (le_of_uint32 (S.head s)) (le_of_seq_uint32 (S.tail s))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.All.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "FStar.Krml.Endianness.fst" }
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Math.Lemmas", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Krml", "short_module": null }, { "abbrev": false, "full_module": "FStar.Krml", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
l: Prims.nat -> b: FStar.Krml.Endianness.bytes{FStar.Seq.Base.length b = 4 * l} -> s: FStar.Seq.Base.seq FStar.UInt32.t {FStar.Seq.Base.length s = l}
Prims.Tot
[ "total" ]
[]
[ "Prims.nat", "FStar.Krml.Endianness.bytes", "Prims.b2t", "Prims.op_Equality", "Prims.int", "FStar.Seq.Base.length", "FStar.UInt8.t", "FStar.Mul.op_Star", "FStar.Seq.Base.empty", "FStar.UInt32.t", "Prims.bool", "FStar.Seq.Base.seq", "FStar.Seq.Base.cons", "FStar.Krml.Endianness.uint32_of_be", "FStar.Krml.Endianness.seq_uint32_of_be", "Prims.op_Subtraction", "FStar.Pervasives.Native.tuple2", "FStar.Seq.Properties.split" ]
[ "recursion" ]
false
false
false
false
false
let rec seq_uint32_of_be (l: nat) (b: bytes{S.length b = 4 * l}) : s: S.seq UInt32.t {S.length s = l} =
if S.length b = 0 then S.empty else let hd, tl = Seq.split b 4 in S.cons (uint32_of_be hd) (seq_uint32_of_be (l - 1) tl)
false
Hacl.Spec.Bignum.Multiplication.fst
Hacl.Spec.Bignum.Multiplication.bn_mul_loop_lemma
val bn_mul_loop_lemma: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat{aLen + bLen <= max_size_t} -> a:lbignum t aLen -> b:lbignum t bLen -> i:nat{i <= bLen} -> Lemma (let res = create (aLen + bLen) (uint #t 0) in let resi = repeati i (bn_mul_ a b) res in eval_ (aLen + bLen) resi (aLen + i) == bn_v a * eval_ bLen b i)
val bn_mul_loop_lemma: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat{aLen + bLen <= max_size_t} -> a:lbignum t aLen -> b:lbignum t bLen -> i:nat{i <= bLen} -> Lemma (let res = create (aLen + bLen) (uint #t 0) in let resi = repeati i (bn_mul_ a b) res in eval_ (aLen + bLen) resi (aLen + i) == bn_v a * eval_ bLen b i)
let rec bn_mul_loop_lemma #t #aLen #bLen a b i = let res = create (aLen + bLen) (uint #t 0) in let resi = repeati i (bn_mul_ a b) res in if i = 0 then begin eq_repeati0 i (bn_mul_ a b) res; bn_eval0 b; bn_eval_zeroes #t (aLen + bLen) (aLen + i); () end else begin unfold_repeati i (bn_mul_ a b) res (i - 1); let resi1 = repeati (i - 1) (bn_mul_ a b) res in assert (resi == bn_mul_ a b (i - 1) resi1); bn_mul_loop_lemma a b (i - 1); assert (eval_ (aLen + bLen) resi1 (aLen + i - 1) == bn_v a * eval_ bLen b (i - 1)); bn_mul_loop_lemma_step a b i resi1; assert (eval_ (aLen + bLen) resi (aLen + i) == bn_v a * eval_ bLen b i); () end
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Multiplication.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 10, "end_line": 445, "start_col": 0, "start_line": 429 }
module Hacl.Spec.Bignum.Multiplication open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.LoopCombinators open Hacl.Spec.Bignum.Definitions open Hacl.Spec.Bignum.Base open Hacl.Spec.Lib #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" val bn_mul1_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> l:limb t -> i:size_nat{i < aLen} -> c:limb t -> limb t & limb t // carry & out let bn_mul1_f #t #aLen a l i c = mul_wide_add a.[i] l c val bn_mul1: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> l:limb t -> limb t & lbignum t aLen let bn_mul1 #t #aLen a l = generate_elems aLen aLen (bn_mul1_f a l) (uint #t 0) val bn_mul1_add_in_place_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> l:limb t -> acc:lbignum t aLen -> i:size_nat{i < aLen} -> c:limb t -> limb t & limb t // carry & out let bn_mul1_add_in_place_f #t #aLen a l acc i c = mul_wide_add2 a.[i] l c acc.[i] val bn_mul1_add_in_place: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> l:limb t -> acc:lbignum t aLen -> limb t & lbignum t aLen let bn_mul1_add_in_place #t #aLen a l acc = generate_elems aLen aLen (bn_mul1_add_in_place_f a l acc) (uint #t 0) val bn_mul1_lshift_add: #t:limb_t -> #aLen:size_nat -> #resLen:size_nat -> a:lbignum t aLen -> b_j:limb t -> j:size_nat{j + aLen <= resLen} -> res:lbignum t resLen -> limb t & lbignum t resLen let bn_mul1_lshift_add #t #aLen #resLen a b_j j res = let res' = sub res j aLen in let c, res' = bn_mul1_add_in_place a b_j res' in let res = update_sub res j aLen res' in c, res val bn_mul_: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat{aLen + bLen <= max_size_t} -> a:lbignum t aLen -> b:lbignum t bLen -> j:size_nat{j < bLen} -> res:lbignum t (aLen + bLen) -> lbignum t (aLen + bLen) let bn_mul_ #t #aLen #bLen a b j res = let c, res = bn_mul1_lshift_add a b.[j] j res in res.[aLen + j] <- c val bn_mul: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat{aLen + bLen <= max_size_t} -> a:lbignum t aLen -> b:lbignum t bLen -> lbignum t (aLen + bLen) let bn_mul #t #aLen #bLen a b = let res = create (aLen + bLen) (uint #t 0) in repeati bLen (bn_mul_ a b) res val bn_mul1_lemma_loop_step: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> l:limb t -> i:pos{i <= aLen} -> c1_res1:generate_elem_a (limb t) (limb t) aLen (i - 1) -> Lemma (requires (let (c1, res1) = c1_res1 in v c1 * pow2 (bits t * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen a (i - 1) * v l)) (ensures (let (c1, res1) = c1_res1 in let (c, res) = generate_elem_f aLen (bn_mul1_f a l) (i - 1) (c1, res1) in v c * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen a i * v l)) let bn_mul1_lemma_loop_step #t #aLen a l i (c1, res1) = let pbits = bits t in let b1 = pow2 (pbits * (i - 1)) in let b2 = pow2 (pbits * i) in let (c, res) = generate_elem_f aLen (bn_mul1_f a l) (i - 1) (c1, res1) in let c, e = mul_wide_add a.[i - 1] l c1 in assert (v e + v c * pow2 pbits == v a.[i - 1] * v l + v c1); calc (==) { v c * b2 + bn_v #t #i res; (==) { bn_eval_snoc #t #(i - 1) res1 e } v c * b2 + bn_v #t #(i - 1) res1 + v e * b1; (==) { } v c * b2 + eval_ aLen a (i - 1) * v l -(v e + v c * pow2 pbits - v a.[i - 1] * v l) * b1 + v e * b1; (==) { Math.Lemmas.distributivity_add_left (v e) (v c * pow2 pbits - v a.[i - 1] * v l) b1 } v c * b2 + eval_ aLen a (i - 1) * v l - (v c * pow2 pbits - v a.[i - 1] * v l) * b1; (==) { Math.Lemmas.distributivity_sub_left (v c * pow2 pbits) (v a.[i - 1] * v l) b1 } v c * b2 + eval_ aLen a (i - 1) * v l - v c * pow2 pbits * b1 + v a.[i - 1] * v l * b1; (==) { Math.Lemmas.paren_mul_right (v c) (pow2 pbits) b1; Math.Lemmas.pow2_plus pbits (pbits * (i - 1)) } eval_ aLen a (i - 1) * v l + v a.[i - 1] * v l * b1; (==) { Math.Lemmas.paren_mul_right (v a.[i - 1]) (v l) b1 } eval_ aLen a (i - 1) * v l + v a.[i - 1] * (b1 * v l); (==) { Math.Lemmas.paren_mul_right (v a.[i - 1]) b1 (v l) } eval_ aLen a (i - 1) * v l + v a.[i - 1] * b1 * v l; (==) { Math.Lemmas.distributivity_add_left (eval_ aLen a (i - 1)) (v a.[i - 1] * b1) (v l) } (eval_ aLen a (i - 1) + v a.[i - 1] * b1) * v l; (==) { bn_eval_unfold_i a i } eval_ aLen a i * v l; }; assert (v c * b2 + bn_v #t #i res == eval_ aLen a i * v l) val bn_mul1_lemma_loop: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> l:limb t -> i:nat{i <= aLen} -> Lemma (let (c, res) : generate_elem_a (limb t) (limb t) aLen i = generate_elems aLen i (bn_mul1_f a l) (uint #t 0) in v c * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen a i * v l) let rec bn_mul1_lemma_loop #t #aLen a l i = let pbits = bits t in let (c, res) : generate_elem_a (limb t) (limb t) aLen i = generate_elems aLen i (bn_mul1_f a l) (uint #t 0) in if i = 0 then begin eq_generate_elems0 aLen i (bn_mul1_f a l) (uint #t 0); assert (c == uint #t 0 /\ res == Seq.empty); bn_eval0 #t #0 res; assert_norm (pow2 0 = 1); bn_eval0 a; () end else begin let (c1, res1) : generate_elem_a (limb t) (limb t) aLen (i - 1) = generate_elems aLen (i - 1) (bn_mul1_f a l) (uint #t 0) in generate_elems_unfold aLen i (bn_mul1_f a l) (uint #t 0) (i - 1); assert (generate_elems aLen i (bn_mul1_f a l) (uint #t 0) == generate_elem_f aLen (bn_mul1_f a l) (i - 1) (generate_elems aLen (i - 1) (bn_mul1_f a l) (uint #t 0))); assert ((c, res) == generate_elem_f aLen (bn_mul1_f a l) (i - 1) (c1, res1)); bn_mul1_lemma_loop a l (i - 1); assert (v c1 * pow2 (pbits * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen a (i - 1) * v l); bn_mul1_lemma_loop_step a l i (c1, res1); assert (v c * pow2 (pbits * i) + bn_v #t #i res == eval_ aLen a i * v l); () end val bn_mul1_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> l:limb t -> Lemma (let (c, res) = bn_mul1 a l in v c * pow2 (bits t * aLen) + bn_v res == bn_v a * v l) let bn_mul1_lemma #t #aLen a l = let (c, res) = bn_mul1 a l in bn_mul1_lemma_loop a l aLen #push-options "--z3rlimit 150" val bn_mul1_add_in_place_lemma_loop_step: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> l:limb t -> acc:lbignum t aLen -> i:pos{i <= aLen} -> c1_res1:generate_elem_a (limb t) (limb t) aLen (i - 1) -> Lemma (requires (let (c1, res1) = c1_res1 in v c1 * pow2 (bits t * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen acc (i - 1) + eval_ aLen a (i - 1) * v l)) (ensures (let (c1, res1) = c1_res1 in let (c, res) = generate_elem_f aLen (bn_mul1_add_in_place_f a l acc) (i - 1) (c1, res1) in v c * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen acc i + eval_ aLen a i * v l)) let bn_mul1_add_in_place_lemma_loop_step #t #aLen a l acc i (c1, res1) = let pbits = bits t in let b1 = pow2 (pbits * (i - 1)) in let b2 = pow2 (pbits * i) in let (c, res) = generate_elem_f aLen (bn_mul1_add_in_place_f a l acc) (i - 1) (c1, res1) in let c, e = mul_wide_add2 a.[i - 1] l c1 acc.[i - 1] in assert (v e + v c * pow2 pbits == v a.[i - 1] * v l + v c1 + v acc.[i - 1]); calc (==) { v c * b2 + bn_v #t #i res; (==) { bn_eval_snoc #t #(i - 1) res1 e } v c * b2 + bn_v #t #(i - 1) res1 + v e * b1; (==) { } v c * b2 + eval_ aLen acc (i - 1) + eval_ aLen a (i - 1) * v l - (v e + v c * pow2 pbits - v a.[i - 1] * v l - v acc.[i - 1]) * b1 + v e * b1; (==) { Math.Lemmas.distributivity_add_left (v e) (v c * pow2 pbits - v a.[i - 1] * v l - v acc.[i - 1]) b1 } v c * b2 + eval_ aLen acc (i - 1) + eval_ aLen a (i - 1) * v l - (v c * pow2 pbits - v a.[i - 1] * v l - v acc.[i - 1]) * b1; (==) { Math.Lemmas.distributivity_sub_left (v c * pow2 pbits) (v a.[i - 1] * v l + v acc.[i - 1]) b1 } v c * b2 + eval_ aLen acc (i - 1) + eval_ aLen a (i - 1) * v l - (v c * pow2 pbits) * b1 + (v a.[i - 1] * v l + v acc.[i - 1]) * b1; (==) { Math.Lemmas.paren_mul_right (v c) (pow2 pbits) b1; Math.Lemmas.pow2_plus pbits (pbits * (i - 1)) } eval_ aLen acc (i - 1) + eval_ aLen a (i - 1) * v l + (v a.[i - 1] * v l + v acc.[i - 1]) * b1; (==) { Math.Lemmas.distributivity_add_left (v a.[i - 1] * v l) (v acc.[i - 1]) b1 } eval_ aLen acc (i - 1) + eval_ aLen a (i - 1) * v l + v a.[i - 1] * v l * b1 + v acc.[i - 1] * b1; (==) { bn_eval_unfold_i acc i } eval_ aLen acc i + eval_ aLen a (i - 1) * v l + v a.[i - 1] * v l * b1; (==) { Math.Lemmas.paren_mul_right (v a.[i - 1]) (v l) b1 } eval_ aLen acc i + eval_ aLen a (i - 1) * v l + v a.[i - 1] * (b1 * v l); (==) { Math.Lemmas.paren_mul_right (v a.[i - 1]) b1 (v l) } eval_ aLen acc i + eval_ aLen a (i - 1) * v l + v a.[i - 1] * b1 * v l; (==) { Math.Lemmas.distributivity_add_left (eval_ aLen a (i - 1)) (v a.[i - 1] * b1) (v l) } eval_ aLen acc i + (eval_ aLen a (i - 1) + v a.[i - 1] * b1) * v l; (==) { bn_eval_unfold_i a i } eval_ aLen acc i + eval_ aLen a i * v l; }; assert (v c * b2 + bn_v #t #i res == eval_ aLen acc i + eval_ aLen a i * v l) #pop-options val bn_mul1_add_in_place_lemma_loop: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> l:limb t -> acc:lbignum t aLen -> i:nat{i <= aLen} -> Lemma (let (c, res) : generate_elem_a (limb t) (limb t) aLen i = generate_elems aLen i (bn_mul1_add_in_place_f a l acc) (uint #t 0) in v c * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen acc i + eval_ aLen a i * v l) let rec bn_mul1_add_in_place_lemma_loop #t #aLen a l acc i = let pbits = bits t in let (c, res) : generate_elem_a (limb t) (limb t) aLen i = generate_elems aLen i (bn_mul1_add_in_place_f a l acc) (uint #t 0) in if i = 0 then begin eq_generate_elems0 aLen i (bn_mul1_add_in_place_f a l acc) (uint #t 0); assert (c == uint #t 0 /\ res == Seq.empty); bn_eval0 #t #0 res; assert_norm (pow2 0 = 1); bn_eval0 a; bn_eval0 acc; () end else begin let (c1, res1) : generate_elem_a (limb t) (limb t) aLen (i - 1) = generate_elems aLen (i - 1) (bn_mul1_add_in_place_f a l acc) (uint #t 0) in generate_elems_unfold aLen i (bn_mul1_add_in_place_f a l acc) (uint #t 0) (i - 1); assert (generate_elems aLen i (bn_mul1_add_in_place_f a l acc) (uint #t 0) == generate_elem_f aLen (bn_mul1_add_in_place_f a l acc) (i - 1) (generate_elems aLen (i - 1) (bn_mul1_add_in_place_f a l acc) (uint #t 0))); assert ((c, res) == generate_elem_f aLen (bn_mul1_add_in_place_f a l acc) (i - 1) (c1, res1)); bn_mul1_add_in_place_lemma_loop a l acc (i - 1); assert (v c1 * pow2 (pbits * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen acc (i - 1) + eval_ aLen a (i - 1) * v l); bn_mul1_add_in_place_lemma_loop_step a l acc i (c1, res1); assert (v c * pow2 (pbits * i) + bn_v #t #i res == eval_ aLen acc i + eval_ aLen a i * v l); () end val bn_mul1_add_in_place_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> l:limb t -> acc:lbignum t aLen -> Lemma (let (c, res) = bn_mul1_add_in_place a l acc in v c * pow2 (bits t * aLen) + bn_v res == bn_v acc + bn_v a * v l) let bn_mul1_add_in_place_lemma #t #aLen a l acc = let (c, res) = bn_mul1_add_in_place a l acc in bn_mul1_add_in_place_lemma_loop a l acc aLen val bn_mul1_lshift_add_lemma: #t:limb_t -> #aLen:size_nat -> #resLen:size_nat -> a:lbignum t aLen -> b_j:limb t -> j:size_nat{j + aLen <= resLen} -> acc:lbignum t resLen -> Lemma (let (c, res) = bn_mul1_lshift_add a b_j j acc in v c * pow2 (bits t * (aLen + j)) + eval_ resLen res (aLen + j) == eval_ resLen acc (aLen + j) + bn_v a * v b_j * pow2 (bits t * j) /\ slice res (aLen + j) resLen == slice acc (aLen + j) resLen) let bn_mul1_lshift_add_lemma #t #aLen #resLen a b_j j acc = let pbits = bits t in let res1 = sub acc j aLen in let c, res2 = bn_mul1_add_in_place a b_j res1 in bn_mul1_add_in_place_lemma a b_j res1; assert (v c * pow2 (pbits * aLen) + bn_v res2 == bn_v res1 + bn_v a * v b_j); let res = update_sub acc j aLen res2 in bn_eval_split_i (sub res 0 (j + aLen)) j; bn_eval_extensionality_j res (sub res 0 (j + aLen)) (j + aLen); assert (eval_ resLen res (j + aLen) == bn_v #t #j (sub res 0 j) + pow2 (pbits * j) * bn_v res2); eq_intro (sub res 0 j) (sub acc 0 j); assert (bn_v #t #j (sub res 0 j) == bn_v #t #j (sub acc 0 j)); bn_eval_split_i (sub acc 0 (j + aLen)) j; bn_eval_extensionality_j acc (sub acc 0 (j + aLen)) (j + aLen); assert (eval_ resLen acc (j + aLen) == bn_v #t #j (sub acc 0 j) + pow2 (pbits * j) * bn_v res1); calc (==) { v c * pow2 (pbits * (aLen + j)) + eval_ resLen res (aLen + j); (==) { Math.Lemmas.pow2_plus (pbits * aLen) (pbits * j) } v c * (pow2 (pbits * aLen) * pow2 (pbits * j)) + eval_ resLen res (aLen + j); (==) { Math.Lemmas.paren_mul_right (v c) (pow2 (pbits * aLen)) (pow2 (pbits * j)) } v c * pow2 (pbits * aLen) * pow2 (pbits * j) + eval_ resLen res (aLen + j); (==) { } (bn_v res1 + bn_v a * v b_j - bn_v res2) * pow2 (pbits * j) + eval_ resLen res (aLen + j); (==) { } (bn_v res1 + bn_v a * v b_j - bn_v res2) * pow2 (pbits * j) + eval_ resLen acc (j + aLen) - pow2 (pbits * j) * bn_v res1 + pow2 (pbits * j) * bn_v res2; (==) { Math.Lemmas.distributivity_add_right (pow2 (pbits * j)) (bn_v res1) (bn_v a * v b_j - bn_v res2) } pow2 (pbits * j) * (bn_v a * v b_j - bn_v res2) + eval_ resLen acc (j + aLen) + pow2 (pbits * j) * bn_v res2; (==) { Math.Lemmas.distributivity_sub_right (pow2 (pbits * j)) (bn_v a * v b_j) (bn_v res2) } pow2 (pbits * j) * (bn_v a * v b_j) + eval_ resLen acc (j + aLen); }; assert (v c * pow2 (pbits * (aLen + j)) + eval_ resLen res (aLen + j) == eval_ resLen acc (aLen + j) + bn_v a * v b_j * pow2 (pbits * j)); eq_intro (slice res (aLen + j) resLen) (slice acc (aLen + j) resLen) val bn_mul_lemma_: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat{aLen + bLen <= max_size_t} -> a:lbignum t aLen -> b:lbignum t bLen -> j:size_nat{j < bLen} -> acc:lbignum t (aLen + bLen) -> Lemma (let res = bn_mul_ a b j acc in v res.[aLen + j] * pow2 (bits t * (aLen + j)) + eval_ (aLen + bLen) res (aLen + j) == eval_ (aLen + bLen) acc (aLen + j) + bn_v a * v b.[j] * pow2 (bits t * j)) let bn_mul_lemma_ #t #aLen #bLen a b j acc = let c, res = bn_mul1_lshift_add a b.[j] j acc in bn_mul1_lshift_add_lemma a b.[j] j acc; let res1 = res.[aLen + j] <- c in bn_eval_extensionality_j res res1 (aLen + j) val bn_mul_loop_lemma_step: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat{aLen + bLen <= max_size_t} -> a:lbignum t aLen -> b:lbignum t bLen -> i:pos{i <= bLen} -> resi1:lbignum t (aLen + bLen) -> Lemma (requires eval_ (aLen + bLen) resi1 (aLen + i - 1) == bn_v a * eval_ bLen b (i - 1)) (ensures (let resi = bn_mul_ a b (i - 1) resi1 in eval_ (aLen + bLen) resi (aLen + i) == bn_v a * eval_ bLen b i)) let bn_mul_loop_lemma_step #t #aLen #bLen a b i resi1 = let pbits = bits t in let resi = bn_mul_ a b (i - 1) resi1 in bn_mul_lemma_ a b (i - 1) resi1; assert (v resi.[aLen + i - 1] * pow2 (pbits * (aLen + i - 1)) + eval_ (aLen + bLen) resi (aLen + i - 1) == eval_ (aLen + bLen) resi1 (aLen + i - 1) + bn_v a * v b.[i - 1] * (pow2 (pbits * (i - 1)))); calc (==) { eval_ (aLen + bLen) resi (aLen + i); (==) { bn_eval_unfold_i resi (aLen + i) } eval_ (aLen + bLen) resi (aLen + i - 1) + v resi.[aLen + i - 1] * pow2 (pbits * (aLen + i - 1)); (==) { } eval_ (aLen + bLen) resi1 (aLen + i - 1) + bn_v a * v b.[i - 1] * (pow2 (pbits * (i - 1))); (==) { } bn_v a * eval_ bLen b (i - 1) + bn_v a * v b.[i - 1] * (pow2 (pbits * (i - 1))); (==) { Math.Lemmas.paren_mul_right (bn_v a) (v b.[i - 1]) (pow2 (pbits * (i - 1))) } bn_v a * eval_ bLen b (i - 1) + bn_v a * (v b.[i - 1] * (pow2 (pbits * (i - 1)))); (==) { Math.Lemmas.distributivity_add_right (bn_v a) (eval_ bLen b (i - 1)) (v b.[i - 1] * (pow2 (pbits * (i - 1)))) } bn_v a * (eval_ bLen b (i - 1) + v b.[i - 1] * (pow2 (pbits * (i - 1)))); (==) { bn_eval_unfold_i b i } bn_v a * eval_ bLen b i; }; assert (eval_ (aLen + bLen) resi (aLen + i) == bn_v a * eval_ bLen b i) val bn_mul_loop_lemma: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat{aLen + bLen <= max_size_t} -> a:lbignum t aLen -> b:lbignum t bLen -> i:nat{i <= bLen} -> Lemma (let res = create (aLen + bLen) (uint #t 0) in let resi = repeati i (bn_mul_ a b) res in eval_ (aLen + bLen) resi (aLen + i) == bn_v a * eval_ bLen b i)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Lib.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Bignum.Multiplication.fst" }
[ { "abbrev": false, "full_module": "Hacl.Spec.Lib", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Base", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> b: Hacl.Spec.Bignum.Definitions.lbignum t bLen -> i: Prims.nat{i <= bLen} -> FStar.Pervasives.Lemma (ensures (let res = Lib.Sequence.create (aLen + bLen) (Lib.IntTypes.uint 0) in let resi = Lib.LoopCombinators.repeati i (Hacl.Spec.Bignum.Multiplication.bn_mul_ a b) res in Hacl.Spec.Bignum.Definitions.eval_ (aLen + bLen) resi (aLen + i) == Hacl.Spec.Bignum.Definitions.bn_v a * Hacl.Spec.Bignum.Definitions.eval_ bLen b i))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Lib.IntTypes.size_nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "Lib.IntTypes.max_size_t", "Hacl.Spec.Bignum.Definitions.lbignum", "Prims.nat", "Prims.op_Equality", "Prims.int", "Prims.unit", "Hacl.Spec.Bignum.Definitions.bn_eval_zeroes", "Hacl.Spec.Bignum.Definitions.bn_eval0", "Lib.LoopCombinators.eq_repeati0", "Hacl.Spec.Bignum.Multiplication.bn_mul_", "Prims.bool", "Prims._assert", "Prims.eq2", "Hacl.Spec.Bignum.Definitions.eval_", "FStar.Mul.op_Star", "Hacl.Spec.Bignum.Definitions.bn_v", "Hacl.Spec.Bignum.Multiplication.bn_mul_loop_lemma_step", "Prims.op_Subtraction", "Hacl.Spec.Bignum.Multiplication.bn_mul_loop_lemma", "Lib.LoopCombinators.repeati", "Lib.LoopCombinators.unfold_repeati", "Lib.Sequence.lseq", "Hacl.Spec.Bignum.Definitions.limb", "Prims.l_and", "FStar.Seq.Base.seq", "Lib.Sequence.to_seq", "FStar.Seq.Base.create", "Lib.IntTypes.mk_int", "Lib.IntTypes.SEC", "Prims.l_Forall", "Prims.l_imp", "Prims.op_LessThan", "Lib.Sequence.index", "Lib.Sequence.create", "Lib.IntTypes.uint" ]
[ "recursion" ]
false
false
true
false
false
let rec bn_mul_loop_lemma #t #aLen #bLen a b i =
let res = create (aLen + bLen) (uint #t 0) in let resi = repeati i (bn_mul_ a b) res in if i = 0 then (eq_repeati0 i (bn_mul_ a b) res; bn_eval0 b; bn_eval_zeroes #t (aLen + bLen) (aLen + i); ()) else (unfold_repeati i (bn_mul_ a b) res (i - 1); let resi1 = repeati (i - 1) (bn_mul_ a b) res in assert (resi == bn_mul_ a b (i - 1) resi1); bn_mul_loop_lemma a b (i - 1); assert (eval_ (aLen + bLen) resi1 (aLen + i - 1) == bn_v a * eval_ bLen b (i - 1)); bn_mul_loop_lemma_step a b i resi1; assert (eval_ (aLen + bLen) resi (aLen + i) == bn_v a * eval_ bLen b i); ())
false
FStar.Krml.Endianness.fst
FStar.Krml.Endianness.be_of_seq_uint64
val be_of_seq_uint64 (s: S.seq UInt64.t) : Tot (b: bytes{S.length b = 8 * S.length s}) (decreases (S.length s))
val be_of_seq_uint64 (s: S.seq UInt64.t) : Tot (b: bytes{S.length b = 8 * S.length s}) (decreases (S.length s))
let rec be_of_seq_uint64 (s: S.seq UInt64.t): Tot (b:bytes { S.length b = 8 * S.length s }) (decreases (S.length s)) = if S.length s = 0 then S.empty else S.append (be_of_uint64 (S.head s)) (be_of_seq_uint64 (S.tail s))
{ "file_name": "krmllib/FStar.Krml.Endianness.fst", "git_rev": "da1e941b2fcb196aa5d1e34941aa00b4c67ac321", "git_url": "https://github.com/FStarLang/karamel.git", "project_name": "karamel" }
{ "end_col": 68, "end_line": 314, "start_col": 0, "start_line": 307 }
module FStar.Krml.Endianness open FStar.Mul open FStar.HyperStack.All module U8 = FStar.UInt8 module U32 = FStar.UInt32 module U64 = FStar.UInt64 module Math = FStar.Math.Lemmas module S = FStar.Seq (* Selectively imported from Hacl*'s FStar.Endianness.fst library, with several name changes *) inline_for_extraction noextract type bytes = S.seq U8.t /// lt_to_n interprets a byte sequence as a little-endian natural number [@(deprecated "FStar.Endianness.le_to_n")] val le_to_n : b:bytes -> Tot nat (decreases (S.length b)) let rec le_to_n b = if S.length b = 0 then 0 else U8.v (S.head b) + pow2 8 * le_to_n (S.tail b) /// be_to_n interprets a byte sequence as a big-endian natural number [@(deprecated "FStar.Endianness.be_to_n")] val be_to_n : b:bytes -> Tot nat (decreases (S.length b)) let rec be_to_n b = if S.length b = 0 then 0 else U8.v (S.last b) + pow2 8 * be_to_n (S.slice b 0 (S.length b - 1)) [@(deprecated "FStar.Endianness.lemma_euclidean_division")] private val lemma_euclidean_division: r:nat -> b:nat -> q:pos -> Lemma (requires (r < q)) (ensures (r + q * b < q * (b+1))) let lemma_euclidean_division r b q = () [@(deprecated "FStar.Endianness.lemma_factorise")] private val lemma_factorise: a:nat -> b:nat -> Lemma (a + a * b == a * (b + 1)) let lemma_factorise a b = () [@(deprecated "FStar.Endianness.lemma_le_to_n_is_bounded")] val lemma_le_to_n_is_bounded: b:bytes -> Lemma (requires True) (ensures (le_to_n b < pow2 (8 * Seq.length b))) (decreases (Seq.length b)) let rec lemma_le_to_n_is_bounded b = if Seq.length b = 0 then () else begin let s = Seq.slice b 1 (Seq.length b) in assert(Seq.length s = Seq.length b - 1); lemma_le_to_n_is_bounded s; assert(UInt8.v (Seq.index b 0) < pow2 8); assert(le_to_n s < pow2 (8 * Seq.length s)); assert(le_to_n b < pow2 8 + pow2 8 * pow2 (8 * (Seq.length b - 1))); lemma_euclidean_division (UInt8.v (Seq.index b 0)) (le_to_n s) (pow2 8); assert(le_to_n b <= pow2 8 * (le_to_n s + 1)); assert(le_to_n b <= pow2 8 * pow2 (8 * (Seq.length b - 1))); Math.Lemmas.pow2_plus 8 (8 * (Seq.length b - 1)); lemma_factorise 8 (Seq.length b - 1) end [@(deprecated "FStar.Endianness.lemma_be_to_n_is_bounded")] val lemma_be_to_n_is_bounded: b:bytes -> Lemma (requires True) (ensures (be_to_n b < pow2 (8 * Seq.length b))) (decreases (Seq.length b)) let rec lemma_be_to_n_is_bounded b = if Seq.length b = 0 then () else begin let s = Seq.slice b 0 (Seq.length b - 1) in assert(Seq.length s = Seq.length b - 1); lemma_be_to_n_is_bounded s; assert(UInt8.v (Seq.last b) < pow2 8); assert(be_to_n s < pow2 (8 * Seq.length s)); assert(be_to_n b < pow2 8 + pow2 8 * pow2 (8 * (Seq.length b - 1))); lemma_euclidean_division (UInt8.v (Seq.last b)) (be_to_n s) (pow2 8); assert(be_to_n b <= pow2 8 * (be_to_n s + 1)); assert(be_to_n b <= pow2 8 * pow2 (8 * (Seq.length b - 1))); Math.Lemmas.pow2_plus 8 (8 * (Seq.length b - 1)); lemma_factorise 8 (Seq.length b - 1) end /// n_to_le encodes a number as a little-endian byte sequence of a fixed, /// sufficiently large length [@(deprecated "FStar.Endianness.n_to_le")] val n_to_le : len:U32.t -> n:nat{n < pow2 (8 * U32.v len)} -> Tot (b:bytes{S.length b == U32.v len /\ n == le_to_n b}) (decreases (U32.v len)) let rec n_to_le len n = if len = 0ul then S.empty else let len = U32.(len -^ 1ul) in let byte = U8.uint_to_t (n % 256) in let n' = n / 256 in Math.pow2_plus 8 (8 * U32.v len); assert(n' < pow2 (8 * U32.v len )); let b' = n_to_le len n' in let b = S.cons byte b' in S.lemma_eq_intro b' (S.tail b); b /// n_to_be encodes a numbers as a big-endian byte sequence of a fixed, /// sufficiently large length [@(deprecated "FStar.Endianness.n_to_be")] val n_to_be: len:U32.t -> n:nat{n < pow2 (8 * U32.v len)} -> Tot (b:bytes{S.length b == U32.v len /\ n == be_to_n b}) (decreases (U32.v len)) let rec n_to_be len n = if len = 0ul then S.empty else let len = U32.(len -^ 1ul) in let byte = U8.uint_to_t (n % 256) in let n' = n / 256 in Math.pow2_plus 8 (8 * U32.v len); assert(n' < pow2 (8 * U32.v len )); let b' = n_to_be len n' in let b'' = S.create 1 byte in let b = S.append b' b'' in S.lemma_eq_intro b' (S.slice b 0 (U32.v len)); b [@(deprecated "FStar.Endianness.n_to_le_inj")] let n_to_le_inj (len:U32.t) (n1 n2: (n:nat{n < pow2 (8 * U32.v len)})) : Lemma (requires (n_to_le len n1 == n_to_le len n2)) (ensures (n1 == n2)) = // this lemma easily follows from le_to_n . (n_to_le len) == id, the inversion // proof in the spec for n_to_le () [@(deprecated "FStar.Endianness.n_to_be_inj")] let n_to_be_inj (len:U32.t) (n1 n2: (n:nat{n < pow2 (8 * U32.v len)})) : Lemma (requires (n_to_be len n1 == n_to_be len n2)) (ensures (n1 == n2)) = () [@(deprecated "FStar.Endianness.be_to_n_inj")] let rec be_to_n_inj (b1 b2: Seq.seq U8.t) : Lemma (requires (Seq.length b1 == Seq.length b2 /\ be_to_n b1 == be_to_n b2)) (ensures (Seq.equal b1 b2)) (decreases (Seq.length b1)) = if Seq.length b1 = 0 then () else begin be_to_n_inj (Seq.slice b1 0 (Seq.length b1 - 1)) (Seq.slice b2 0 (Seq.length b2 - 1)); Seq.lemma_split b1 (Seq.length b1 - 1); Seq.lemma_split b2 (Seq.length b2 - 1) end [@(deprecated "FStar.Endianness.le_to_n_inj")] let rec le_to_n_inj (b1 b2: Seq.seq U8.t) : Lemma (requires (Seq.length b1 == Seq.length b2 /\ le_to_n b1 == le_to_n b2)) (ensures (Seq.equal b1 b2)) (decreases (Seq.length b1)) = if Seq.length b1 = 0 then () else begin le_to_n_inj (Seq.slice b1 1 (Seq.length b1)) (Seq.slice b2 1 (Seq.length b2)); Seq.lemma_split b1 1; Seq.lemma_split b2 1 end [@(deprecated "FStar.Endianness.n_to_be_be_to_n")] let n_to_be_be_to_n (len: U32.t) (s: Seq.seq U8.t) : Lemma (requires (Seq.length s == U32.v len)) (ensures ( be_to_n s < pow2 (8 `Prims.op_Multiply` U32.v len) /\ n_to_be len (be_to_n s) == s )) [SMTPat (n_to_be len (be_to_n s))] = lemma_be_to_n_is_bounded s; be_to_n_inj s (n_to_be len (be_to_n s)) [@(deprecated "FStar.Endianness.n_to_le_le_to_n")] let n_to_le_le_to_n (len: U32.t) (s: Seq.seq U8.t) : Lemma (requires (Seq.length s == U32.v len)) (ensures ( le_to_n s < pow2 (8 `Prims.op_Multiply` U32.v len) /\ n_to_le len (le_to_n s) == s )) [SMTPat (n_to_le len (le_to_n s))] = lemma_le_to_n_is_bounded s; le_to_n_inj s (n_to_le len (le_to_n s)) (** A series of specializations to deal with machine integers *) [@(deprecated "FStar.Endianness.uint32_of_le")] let uint32_of_le (b: bytes { S.length b = 4 }) = let n = le_to_n b in lemma_le_to_n_is_bounded b; UInt32.uint_to_t n [@(deprecated "FStar.Endianness.le_of_uint32")] let le_of_uint32 (x: UInt32.t): b:bytes{ S.length b = 4 } = n_to_le 4ul (UInt32.v x) [@(deprecated "FStar.Endianness.uint32_of_be")] let uint32_of_be (b: bytes { S.length b = 4 }) = let n = be_to_n b in lemma_be_to_n_is_bounded b; UInt32.uint_to_t n [@(deprecated "FStar.Endianness.be_of_uint32")] let be_of_uint32 (x: UInt32.t): b:bytes{ S.length b = 4 } = n_to_be 4ul (UInt32.v x) [@(deprecated "FStar.Endianness.uint64_of_le")] let uint64_of_le (b: bytes { S.length b = 8 }) = let n = le_to_n b in lemma_le_to_n_is_bounded b; UInt64.uint_to_t n [@(deprecated "FStar.Endianness.le_of_uint64")] let le_of_uint64 (x: UInt64.t): b:bytes{ S.length b = 8 } = n_to_le 8ul (UInt64.v x) [@(deprecated "FStar.Endianness.uint64_of_be")] let uint64_of_be (b: bytes { S.length b = 8 }) = let n = be_to_n b in lemma_be_to_n_is_bounded b; UInt64.uint_to_t n [@(deprecated "FStar.Endianness.be_of_uint64")] let be_of_uint64 (x: UInt64.t): b:bytes{ S.length b = 8 } = n_to_be 8ul (UInt64.v x) [@(deprecated "FStar.Endianness.seq_uint32_of_le")] let rec seq_uint32_of_le (l: nat) (b: bytes{ S.length b = 4 * l }): s:S.seq UInt32.t { S.length s = l } = if S.length b = 0 then S.empty else let hd, tl = Seq.split b 4 in S.cons (uint32_of_le hd) (seq_uint32_of_le (l - 1) tl) [@(deprecated "FStar.Endianness.le_of_seq_uint32")] let rec le_of_seq_uint32 (s: S.seq UInt32.t): Tot (b:bytes { S.length b = 4 * S.length s }) (decreases (S.length s)) = if S.length s = 0 then S.empty else S.append (le_of_uint32 (S.head s)) (le_of_seq_uint32 (S.tail s)) [@(deprecated "FStar.Endianness.seq_uint32_of_be")] let rec seq_uint32_of_be (l: nat) (b: bytes{ S.length b = 4 * l }): s:S.seq UInt32.t { S.length s = l } = if S.length b = 0 then S.empty else let hd, tl = Seq.split b 4 in S.cons (uint32_of_be hd) (seq_uint32_of_be (l - 1) tl) [@(deprecated "FStar.Endianness.be_of_seq_uint32")] let rec be_of_seq_uint32 (s: S.seq UInt32.t): Tot (b:bytes { S.length b = 4 * S.length s }) (decreases (S.length s)) = if S.length s = 0 then S.empty else S.append (be_of_uint32 (S.head s)) (be_of_seq_uint32 (S.tail s)) [@(deprecated "FStar.Endianness.seq_uint64_of_le")] let rec seq_uint64_of_le (l: nat) (b: bytes{ S.length b = 8 * l }): s:S.seq UInt64.t { S.length s = l } = if S.length b = 0 then S.empty else let hd, tl = Seq.split b 8 in S.cons (uint64_of_le hd) (seq_uint64_of_le (l - 1) tl) [@(deprecated "FStar.Endianness.le_of_seq_uint64")] let rec le_of_seq_uint64 (s: S.seq UInt64.t): Tot (b:bytes { S.length b = 8 * S.length s }) (decreases (S.length s)) = if S.length s = 0 then S.empty else S.append (le_of_uint64 (S.head s)) (le_of_seq_uint64 (S.tail s)) [@(deprecated "FStar.Endianness.seq_uint64_of_be")] let rec seq_uint64_of_be (l: nat) (b: bytes{ S.length b = 8 * l }): s:S.seq UInt64.t { S.length s = l } = if S.length b = 0 then S.empty else let hd, tl = Seq.split b 8 in S.cons (uint64_of_be hd) (seq_uint64_of_be (l - 1) tl)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.All.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "FStar.Krml.Endianness.fst" }
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Math.Lemmas", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Krml", "short_module": null }, { "abbrev": false, "full_module": "FStar.Krml", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s: FStar.Seq.Base.seq FStar.UInt64.t -> Prims.Tot (b: FStar.Krml.Endianness.bytes{FStar.Seq.Base.length b = 8 * FStar.Seq.Base.length s})
Prims.Tot
[ "total", "" ]
[]
[ "FStar.Seq.Base.seq", "FStar.UInt64.t", "Prims.op_Equality", "Prims.int", "FStar.Seq.Base.length", "FStar.Seq.Base.empty", "FStar.UInt8.t", "Prims.bool", "FStar.Seq.Base.append", "FStar.Krml.Endianness.be_of_uint64", "FStar.Seq.Properties.head", "FStar.Krml.Endianness.be_of_seq_uint64", "FStar.Seq.Properties.tail", "FStar.Krml.Endianness.bytes", "Prims.b2t", "FStar.Mul.op_Star" ]
[ "recursion" ]
false
false
false
false
false
let rec be_of_seq_uint64 (s: S.seq UInt64.t) : Tot (b: bytes{S.length b = 8 * S.length s}) (decreases (S.length s)) =
if S.length s = 0 then S.empty else S.append (be_of_uint64 (S.head s)) (be_of_seq_uint64 (S.tail s))
false
Hacl.Spec.Bignum.Multiplication.fst
Hacl.Spec.Bignum.Multiplication.bn_mul1_add_in_place_lemma_loop
val bn_mul1_add_in_place_lemma_loop: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> l:limb t -> acc:lbignum t aLen -> i:nat{i <= aLen} -> Lemma (let (c, res) : generate_elem_a (limb t) (limb t) aLen i = generate_elems aLen i (bn_mul1_add_in_place_f a l acc) (uint #t 0) in v c * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen acc i + eval_ aLen a i * v l)
val bn_mul1_add_in_place_lemma_loop: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> l:limb t -> acc:lbignum t aLen -> i:nat{i <= aLen} -> Lemma (let (c, res) : generate_elem_a (limb t) (limb t) aLen i = generate_elems aLen i (bn_mul1_add_in_place_f a l acc) (uint #t 0) in v c * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen acc i + eval_ aLen a i * v l)
let rec bn_mul1_add_in_place_lemma_loop #t #aLen a l acc i = let pbits = bits t in let (c, res) : generate_elem_a (limb t) (limb t) aLen i = generate_elems aLen i (bn_mul1_add_in_place_f a l acc) (uint #t 0) in if i = 0 then begin eq_generate_elems0 aLen i (bn_mul1_add_in_place_f a l acc) (uint #t 0); assert (c == uint #t 0 /\ res == Seq.empty); bn_eval0 #t #0 res; assert_norm (pow2 0 = 1); bn_eval0 a; bn_eval0 acc; () end else begin let (c1, res1) : generate_elem_a (limb t) (limb t) aLen (i - 1) = generate_elems aLen (i - 1) (bn_mul1_add_in_place_f a l acc) (uint #t 0) in generate_elems_unfold aLen i (bn_mul1_add_in_place_f a l acc) (uint #t 0) (i - 1); assert (generate_elems aLen i (bn_mul1_add_in_place_f a l acc) (uint #t 0) == generate_elem_f aLen (bn_mul1_add_in_place_f a l acc) (i - 1) (generate_elems aLen (i - 1) (bn_mul1_add_in_place_f a l acc) (uint #t 0))); assert ((c, res) == generate_elem_f aLen (bn_mul1_add_in_place_f a l acc) (i - 1) (c1, res1)); bn_mul1_add_in_place_lemma_loop a l acc (i - 1); assert (v c1 * pow2 (pbits * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen acc (i - 1) + eval_ aLen a (i - 1) * v l); bn_mul1_add_in_place_lemma_loop_step a l acc i (c1, res1); assert (v c * pow2 (pbits * i) + bn_v #t #i res == eval_ aLen acc i + eval_ aLen a i * v l); () end
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Multiplication.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 10, "end_line": 293, "start_col": 0, "start_line": 272 }
module Hacl.Spec.Bignum.Multiplication open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.LoopCombinators open Hacl.Spec.Bignum.Definitions open Hacl.Spec.Bignum.Base open Hacl.Spec.Lib #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" val bn_mul1_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> l:limb t -> i:size_nat{i < aLen} -> c:limb t -> limb t & limb t // carry & out let bn_mul1_f #t #aLen a l i c = mul_wide_add a.[i] l c val bn_mul1: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> l:limb t -> limb t & lbignum t aLen let bn_mul1 #t #aLen a l = generate_elems aLen aLen (bn_mul1_f a l) (uint #t 0) val bn_mul1_add_in_place_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> l:limb t -> acc:lbignum t aLen -> i:size_nat{i < aLen} -> c:limb t -> limb t & limb t // carry & out let bn_mul1_add_in_place_f #t #aLen a l acc i c = mul_wide_add2 a.[i] l c acc.[i] val bn_mul1_add_in_place: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> l:limb t -> acc:lbignum t aLen -> limb t & lbignum t aLen let bn_mul1_add_in_place #t #aLen a l acc = generate_elems aLen aLen (bn_mul1_add_in_place_f a l acc) (uint #t 0) val bn_mul1_lshift_add: #t:limb_t -> #aLen:size_nat -> #resLen:size_nat -> a:lbignum t aLen -> b_j:limb t -> j:size_nat{j + aLen <= resLen} -> res:lbignum t resLen -> limb t & lbignum t resLen let bn_mul1_lshift_add #t #aLen #resLen a b_j j res = let res' = sub res j aLen in let c, res' = bn_mul1_add_in_place a b_j res' in let res = update_sub res j aLen res' in c, res val bn_mul_: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat{aLen + bLen <= max_size_t} -> a:lbignum t aLen -> b:lbignum t bLen -> j:size_nat{j < bLen} -> res:lbignum t (aLen + bLen) -> lbignum t (aLen + bLen) let bn_mul_ #t #aLen #bLen a b j res = let c, res = bn_mul1_lshift_add a b.[j] j res in res.[aLen + j] <- c val bn_mul: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat{aLen + bLen <= max_size_t} -> a:lbignum t aLen -> b:lbignum t bLen -> lbignum t (aLen + bLen) let bn_mul #t #aLen #bLen a b = let res = create (aLen + bLen) (uint #t 0) in repeati bLen (bn_mul_ a b) res val bn_mul1_lemma_loop_step: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> l:limb t -> i:pos{i <= aLen} -> c1_res1:generate_elem_a (limb t) (limb t) aLen (i - 1) -> Lemma (requires (let (c1, res1) = c1_res1 in v c1 * pow2 (bits t * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen a (i - 1) * v l)) (ensures (let (c1, res1) = c1_res1 in let (c, res) = generate_elem_f aLen (bn_mul1_f a l) (i - 1) (c1, res1) in v c * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen a i * v l)) let bn_mul1_lemma_loop_step #t #aLen a l i (c1, res1) = let pbits = bits t in let b1 = pow2 (pbits * (i - 1)) in let b2 = pow2 (pbits * i) in let (c, res) = generate_elem_f aLen (bn_mul1_f a l) (i - 1) (c1, res1) in let c, e = mul_wide_add a.[i - 1] l c1 in assert (v e + v c * pow2 pbits == v a.[i - 1] * v l + v c1); calc (==) { v c * b2 + bn_v #t #i res; (==) { bn_eval_snoc #t #(i - 1) res1 e } v c * b2 + bn_v #t #(i - 1) res1 + v e * b1; (==) { } v c * b2 + eval_ aLen a (i - 1) * v l -(v e + v c * pow2 pbits - v a.[i - 1] * v l) * b1 + v e * b1; (==) { Math.Lemmas.distributivity_add_left (v e) (v c * pow2 pbits - v a.[i - 1] * v l) b1 } v c * b2 + eval_ aLen a (i - 1) * v l - (v c * pow2 pbits - v a.[i - 1] * v l) * b1; (==) { Math.Lemmas.distributivity_sub_left (v c * pow2 pbits) (v a.[i - 1] * v l) b1 } v c * b2 + eval_ aLen a (i - 1) * v l - v c * pow2 pbits * b1 + v a.[i - 1] * v l * b1; (==) { Math.Lemmas.paren_mul_right (v c) (pow2 pbits) b1; Math.Lemmas.pow2_plus pbits (pbits * (i - 1)) } eval_ aLen a (i - 1) * v l + v a.[i - 1] * v l * b1; (==) { Math.Lemmas.paren_mul_right (v a.[i - 1]) (v l) b1 } eval_ aLen a (i - 1) * v l + v a.[i - 1] * (b1 * v l); (==) { Math.Lemmas.paren_mul_right (v a.[i - 1]) b1 (v l) } eval_ aLen a (i - 1) * v l + v a.[i - 1] * b1 * v l; (==) { Math.Lemmas.distributivity_add_left (eval_ aLen a (i - 1)) (v a.[i - 1] * b1) (v l) } (eval_ aLen a (i - 1) + v a.[i - 1] * b1) * v l; (==) { bn_eval_unfold_i a i } eval_ aLen a i * v l; }; assert (v c * b2 + bn_v #t #i res == eval_ aLen a i * v l) val bn_mul1_lemma_loop: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> l:limb t -> i:nat{i <= aLen} -> Lemma (let (c, res) : generate_elem_a (limb t) (limb t) aLen i = generate_elems aLen i (bn_mul1_f a l) (uint #t 0) in v c * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen a i * v l) let rec bn_mul1_lemma_loop #t #aLen a l i = let pbits = bits t in let (c, res) : generate_elem_a (limb t) (limb t) aLen i = generate_elems aLen i (bn_mul1_f a l) (uint #t 0) in if i = 0 then begin eq_generate_elems0 aLen i (bn_mul1_f a l) (uint #t 0); assert (c == uint #t 0 /\ res == Seq.empty); bn_eval0 #t #0 res; assert_norm (pow2 0 = 1); bn_eval0 a; () end else begin let (c1, res1) : generate_elem_a (limb t) (limb t) aLen (i - 1) = generate_elems aLen (i - 1) (bn_mul1_f a l) (uint #t 0) in generate_elems_unfold aLen i (bn_mul1_f a l) (uint #t 0) (i - 1); assert (generate_elems aLen i (bn_mul1_f a l) (uint #t 0) == generate_elem_f aLen (bn_mul1_f a l) (i - 1) (generate_elems aLen (i - 1) (bn_mul1_f a l) (uint #t 0))); assert ((c, res) == generate_elem_f aLen (bn_mul1_f a l) (i - 1) (c1, res1)); bn_mul1_lemma_loop a l (i - 1); assert (v c1 * pow2 (pbits * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen a (i - 1) * v l); bn_mul1_lemma_loop_step a l i (c1, res1); assert (v c * pow2 (pbits * i) + bn_v #t #i res == eval_ aLen a i * v l); () end val bn_mul1_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> l:limb t -> Lemma (let (c, res) = bn_mul1 a l in v c * pow2 (bits t * aLen) + bn_v res == bn_v a * v l) let bn_mul1_lemma #t #aLen a l = let (c, res) = bn_mul1 a l in bn_mul1_lemma_loop a l aLen #push-options "--z3rlimit 150" val bn_mul1_add_in_place_lemma_loop_step: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> l:limb t -> acc:lbignum t aLen -> i:pos{i <= aLen} -> c1_res1:generate_elem_a (limb t) (limb t) aLen (i - 1) -> Lemma (requires (let (c1, res1) = c1_res1 in v c1 * pow2 (bits t * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen acc (i - 1) + eval_ aLen a (i - 1) * v l)) (ensures (let (c1, res1) = c1_res1 in let (c, res) = generate_elem_f aLen (bn_mul1_add_in_place_f a l acc) (i - 1) (c1, res1) in v c * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen acc i + eval_ aLen a i * v l)) let bn_mul1_add_in_place_lemma_loop_step #t #aLen a l acc i (c1, res1) = let pbits = bits t in let b1 = pow2 (pbits * (i - 1)) in let b2 = pow2 (pbits * i) in let (c, res) = generate_elem_f aLen (bn_mul1_add_in_place_f a l acc) (i - 1) (c1, res1) in let c, e = mul_wide_add2 a.[i - 1] l c1 acc.[i - 1] in assert (v e + v c * pow2 pbits == v a.[i - 1] * v l + v c1 + v acc.[i - 1]); calc (==) { v c * b2 + bn_v #t #i res; (==) { bn_eval_snoc #t #(i - 1) res1 e } v c * b2 + bn_v #t #(i - 1) res1 + v e * b1; (==) { } v c * b2 + eval_ aLen acc (i - 1) + eval_ aLen a (i - 1) * v l - (v e + v c * pow2 pbits - v a.[i - 1] * v l - v acc.[i - 1]) * b1 + v e * b1; (==) { Math.Lemmas.distributivity_add_left (v e) (v c * pow2 pbits - v a.[i - 1] * v l - v acc.[i - 1]) b1 } v c * b2 + eval_ aLen acc (i - 1) + eval_ aLen a (i - 1) * v l - (v c * pow2 pbits - v a.[i - 1] * v l - v acc.[i - 1]) * b1; (==) { Math.Lemmas.distributivity_sub_left (v c * pow2 pbits) (v a.[i - 1] * v l + v acc.[i - 1]) b1 } v c * b2 + eval_ aLen acc (i - 1) + eval_ aLen a (i - 1) * v l - (v c * pow2 pbits) * b1 + (v a.[i - 1] * v l + v acc.[i - 1]) * b1; (==) { Math.Lemmas.paren_mul_right (v c) (pow2 pbits) b1; Math.Lemmas.pow2_plus pbits (pbits * (i - 1)) } eval_ aLen acc (i - 1) + eval_ aLen a (i - 1) * v l + (v a.[i - 1] * v l + v acc.[i - 1]) * b1; (==) { Math.Lemmas.distributivity_add_left (v a.[i - 1] * v l) (v acc.[i - 1]) b1 } eval_ aLen acc (i - 1) + eval_ aLen a (i - 1) * v l + v a.[i - 1] * v l * b1 + v acc.[i - 1] * b1; (==) { bn_eval_unfold_i acc i } eval_ aLen acc i + eval_ aLen a (i - 1) * v l + v a.[i - 1] * v l * b1; (==) { Math.Lemmas.paren_mul_right (v a.[i - 1]) (v l) b1 } eval_ aLen acc i + eval_ aLen a (i - 1) * v l + v a.[i - 1] * (b1 * v l); (==) { Math.Lemmas.paren_mul_right (v a.[i - 1]) b1 (v l) } eval_ aLen acc i + eval_ aLen a (i - 1) * v l + v a.[i - 1] * b1 * v l; (==) { Math.Lemmas.distributivity_add_left (eval_ aLen a (i - 1)) (v a.[i - 1] * b1) (v l) } eval_ aLen acc i + (eval_ aLen a (i - 1) + v a.[i - 1] * b1) * v l; (==) { bn_eval_unfold_i a i } eval_ aLen acc i + eval_ aLen a i * v l; }; assert (v c * b2 + bn_v #t #i res == eval_ aLen acc i + eval_ aLen a i * v l) #pop-options val bn_mul1_add_in_place_lemma_loop: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> l:limb t -> acc:lbignum t aLen -> i:nat{i <= aLen} -> Lemma (let (c, res) : generate_elem_a (limb t) (limb t) aLen i = generate_elems aLen i (bn_mul1_add_in_place_f a l acc) (uint #t 0) in v c * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen acc i + eval_ aLen a i * v l)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Lib.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Bignum.Multiplication.fst" }
[ { "abbrev": false, "full_module": "Hacl.Spec.Lib", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Base", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> l: Hacl.Spec.Bignum.Definitions.limb t -> acc: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> i: Prims.nat{i <= aLen} -> FStar.Pervasives.Lemma (ensures (let _ = Hacl.Spec.Lib.generate_elems aLen i (Hacl.Spec.Bignum.Multiplication.bn_mul1_add_in_place_f a l acc) (Lib.IntTypes.uint 0) in (let FStar.Pervasives.Native.Mktuple2 #_ #_ c res = _ in let _ = _ in Lib.IntTypes.v c * Prims.pow2 (Lib.IntTypes.bits t * i) + Hacl.Spec.Bignum.Definitions.bn_v res == Hacl.Spec.Bignum.Definitions.eval_ aLen acc i + Hacl.Spec.Bignum.Definitions.eval_ aLen a i * Lib.IntTypes.v l) <: Type0))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Lib.IntTypes.size_nat", "Hacl.Spec.Bignum.Definitions.lbignum", "Hacl.Spec.Bignum.Definitions.limb", "Prims.nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "Lib.Sequence.seq", "Prims.eq2", "Lib.Sequence.length", "Prims.op_Equality", "Prims.int", "Prims.unit", "Hacl.Spec.Bignum.Definitions.bn_eval0", "FStar.Pervasives.assert_norm", "Prims.pow2", "Prims._assert", "Prims.l_and", "Lib.IntTypes.int_t", "Lib.IntTypes.SEC", "Lib.IntTypes.uint", "FStar.Seq.Base.seq", "Prims.l_or", "FStar.Seq.Base.length", "FStar.Seq.Base.empty", "Hacl.Spec.Lib.eq_generate_elems0", "Hacl.Spec.Bignum.Multiplication.bn_mul1_add_in_place_f", "Prims.bool", "Prims.op_Subtraction", "Prims.op_Addition", "FStar.Mul.op_Star", "Lib.IntTypes.v", "Hacl.Spec.Bignum.Definitions.bn_v", "Hacl.Spec.Bignum.Definitions.eval_", "Hacl.Spec.Bignum.Multiplication.bn_mul1_add_in_place_lemma_loop_step", "FStar.Pervasives.Native.Mktuple2", "Hacl.Spec.Bignum.Multiplication.bn_mul1_add_in_place_lemma_loop", "FStar.Pervasives.Native.tuple2", "Hacl.Spec.Lib.generate_elem_f", "Hacl.Spec.Lib.generate_elems", "Hacl.Spec.Lib.generate_elems_unfold", "Hacl.Spec.Lib.generate_elem_a", "Lib.IntTypes.bits" ]
[ "recursion" ]
false
false
true
false
false
let rec bn_mul1_add_in_place_lemma_loop #t #aLen a l acc i =
let pbits = bits t in let c, res:generate_elem_a (limb t) (limb t) aLen i = generate_elems aLen i (bn_mul1_add_in_place_f a l acc) (uint #t 0) in if i = 0 then (eq_generate_elems0 aLen i (bn_mul1_add_in_place_f a l acc) (uint #t 0); assert (c == uint #t 0 /\ res == Seq.empty); bn_eval0 #t #0 res; assert_norm (pow2 0 = 1); bn_eval0 a; bn_eval0 acc; ()) else let c1, res1:generate_elem_a (limb t) (limb t) aLen (i - 1) = generate_elems aLen (i - 1) (bn_mul1_add_in_place_f a l acc) (uint #t 0) in generate_elems_unfold aLen i (bn_mul1_add_in_place_f a l acc) (uint #t 0) (i - 1); assert (generate_elems aLen i (bn_mul1_add_in_place_f a l acc) (uint #t 0) == generate_elem_f aLen (bn_mul1_add_in_place_f a l acc) (i - 1) (generate_elems aLen (i - 1) (bn_mul1_add_in_place_f a l acc) (uint #t 0))); assert ((c, res) == generate_elem_f aLen (bn_mul1_add_in_place_f a l acc) (i - 1) (c1, res1)); bn_mul1_add_in_place_lemma_loop a l acc (i - 1); assert (v c1 * pow2 (pbits * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen acc (i - 1) + eval_ aLen a (i - 1) * v l); bn_mul1_add_in_place_lemma_loop_step a l acc i (c1, res1); assert (v c * pow2 (pbits * i) + bn_v #t #i res == eval_ aLen acc i + eval_ aLen a i * v l); ()
false
Hacl.Spec.Bignum.Multiplication.fst
Hacl.Spec.Bignum.Multiplication.bn_mul1_lemma_loop
val bn_mul1_lemma_loop: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> l:limb t -> i:nat{i <= aLen} -> Lemma (let (c, res) : generate_elem_a (limb t) (limb t) aLen i = generate_elems aLen i (bn_mul1_f a l) (uint #t 0) in v c * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen a i * v l)
val bn_mul1_lemma_loop: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> l:limb t -> i:nat{i <= aLen} -> Lemma (let (c, res) : generate_elem_a (limb t) (limb t) aLen i = generate_elems aLen i (bn_mul1_f a l) (uint #t 0) in v c * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen a i * v l)
let rec bn_mul1_lemma_loop #t #aLen a l i = let pbits = bits t in let (c, res) : generate_elem_a (limb t) (limb t) aLen i = generate_elems aLen i (bn_mul1_f a l) (uint #t 0) in if i = 0 then begin eq_generate_elems0 aLen i (bn_mul1_f a l) (uint #t 0); assert (c == uint #t 0 /\ res == Seq.empty); bn_eval0 #t #0 res; assert_norm (pow2 0 = 1); bn_eval0 a; () end else begin let (c1, res1) : generate_elem_a (limb t) (limb t) aLen (i - 1) = generate_elems aLen (i - 1) (bn_mul1_f a l) (uint #t 0) in generate_elems_unfold aLen i (bn_mul1_f a l) (uint #t 0) (i - 1); assert (generate_elems aLen i (bn_mul1_f a l) (uint #t 0) == generate_elem_f aLen (bn_mul1_f a l) (i - 1) (generate_elems aLen (i - 1) (bn_mul1_f a l) (uint #t 0))); assert ((c, res) == generate_elem_f aLen (bn_mul1_f a l) (i - 1) (c1, res1)); bn_mul1_lemma_loop a l (i - 1); assert (v c1 * pow2 (pbits * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen a (i - 1) * v l); bn_mul1_lemma_loop_step a l i (c1, res1); assert (v c * pow2 (pbits * i) + bn_v #t #i res == eval_ aLen a i * v l); () end
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Multiplication.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 10, "end_line": 189, "start_col": 0, "start_line": 169 }
module Hacl.Spec.Bignum.Multiplication open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.LoopCombinators open Hacl.Spec.Bignum.Definitions open Hacl.Spec.Bignum.Base open Hacl.Spec.Lib #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" val bn_mul1_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> l:limb t -> i:size_nat{i < aLen} -> c:limb t -> limb t & limb t // carry & out let bn_mul1_f #t #aLen a l i c = mul_wide_add a.[i] l c val bn_mul1: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> l:limb t -> limb t & lbignum t aLen let bn_mul1 #t #aLen a l = generate_elems aLen aLen (bn_mul1_f a l) (uint #t 0) val bn_mul1_add_in_place_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> l:limb t -> acc:lbignum t aLen -> i:size_nat{i < aLen} -> c:limb t -> limb t & limb t // carry & out let bn_mul1_add_in_place_f #t #aLen a l acc i c = mul_wide_add2 a.[i] l c acc.[i] val bn_mul1_add_in_place: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> l:limb t -> acc:lbignum t aLen -> limb t & lbignum t aLen let bn_mul1_add_in_place #t #aLen a l acc = generate_elems aLen aLen (bn_mul1_add_in_place_f a l acc) (uint #t 0) val bn_mul1_lshift_add: #t:limb_t -> #aLen:size_nat -> #resLen:size_nat -> a:lbignum t aLen -> b_j:limb t -> j:size_nat{j + aLen <= resLen} -> res:lbignum t resLen -> limb t & lbignum t resLen let bn_mul1_lshift_add #t #aLen #resLen a b_j j res = let res' = sub res j aLen in let c, res' = bn_mul1_add_in_place a b_j res' in let res = update_sub res j aLen res' in c, res val bn_mul_: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat{aLen + bLen <= max_size_t} -> a:lbignum t aLen -> b:lbignum t bLen -> j:size_nat{j < bLen} -> res:lbignum t (aLen + bLen) -> lbignum t (aLen + bLen) let bn_mul_ #t #aLen #bLen a b j res = let c, res = bn_mul1_lshift_add a b.[j] j res in res.[aLen + j] <- c val bn_mul: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat{aLen + bLen <= max_size_t} -> a:lbignum t aLen -> b:lbignum t bLen -> lbignum t (aLen + bLen) let bn_mul #t #aLen #bLen a b = let res = create (aLen + bLen) (uint #t 0) in repeati bLen (bn_mul_ a b) res val bn_mul1_lemma_loop_step: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> l:limb t -> i:pos{i <= aLen} -> c1_res1:generate_elem_a (limb t) (limb t) aLen (i - 1) -> Lemma (requires (let (c1, res1) = c1_res1 in v c1 * pow2 (bits t * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen a (i - 1) * v l)) (ensures (let (c1, res1) = c1_res1 in let (c, res) = generate_elem_f aLen (bn_mul1_f a l) (i - 1) (c1, res1) in v c * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen a i * v l)) let bn_mul1_lemma_loop_step #t #aLen a l i (c1, res1) = let pbits = bits t in let b1 = pow2 (pbits * (i - 1)) in let b2 = pow2 (pbits * i) in let (c, res) = generate_elem_f aLen (bn_mul1_f a l) (i - 1) (c1, res1) in let c, e = mul_wide_add a.[i - 1] l c1 in assert (v e + v c * pow2 pbits == v a.[i - 1] * v l + v c1); calc (==) { v c * b2 + bn_v #t #i res; (==) { bn_eval_snoc #t #(i - 1) res1 e } v c * b2 + bn_v #t #(i - 1) res1 + v e * b1; (==) { } v c * b2 + eval_ aLen a (i - 1) * v l -(v e + v c * pow2 pbits - v a.[i - 1] * v l) * b1 + v e * b1; (==) { Math.Lemmas.distributivity_add_left (v e) (v c * pow2 pbits - v a.[i - 1] * v l) b1 } v c * b2 + eval_ aLen a (i - 1) * v l - (v c * pow2 pbits - v a.[i - 1] * v l) * b1; (==) { Math.Lemmas.distributivity_sub_left (v c * pow2 pbits) (v a.[i - 1] * v l) b1 } v c * b2 + eval_ aLen a (i - 1) * v l - v c * pow2 pbits * b1 + v a.[i - 1] * v l * b1; (==) { Math.Lemmas.paren_mul_right (v c) (pow2 pbits) b1; Math.Lemmas.pow2_plus pbits (pbits * (i - 1)) } eval_ aLen a (i - 1) * v l + v a.[i - 1] * v l * b1; (==) { Math.Lemmas.paren_mul_right (v a.[i - 1]) (v l) b1 } eval_ aLen a (i - 1) * v l + v a.[i - 1] * (b1 * v l); (==) { Math.Lemmas.paren_mul_right (v a.[i - 1]) b1 (v l) } eval_ aLen a (i - 1) * v l + v a.[i - 1] * b1 * v l; (==) { Math.Lemmas.distributivity_add_left (eval_ aLen a (i - 1)) (v a.[i - 1] * b1) (v l) } (eval_ aLen a (i - 1) + v a.[i - 1] * b1) * v l; (==) { bn_eval_unfold_i a i } eval_ aLen a i * v l; }; assert (v c * b2 + bn_v #t #i res == eval_ aLen a i * v l) val bn_mul1_lemma_loop: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> l:limb t -> i:nat{i <= aLen} -> Lemma (let (c, res) : generate_elem_a (limb t) (limb t) aLen i = generate_elems aLen i (bn_mul1_f a l) (uint #t 0) in v c * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen a i * v l)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Lib.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Bignum.Multiplication.fst" }
[ { "abbrev": false, "full_module": "Hacl.Spec.Lib", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Base", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> l: Hacl.Spec.Bignum.Definitions.limb t -> i: Prims.nat{i <= aLen} -> FStar.Pervasives.Lemma (ensures (let _ = Hacl.Spec.Lib.generate_elems aLen i (Hacl.Spec.Bignum.Multiplication.bn_mul1_f a l) (Lib.IntTypes.uint 0) in (let FStar.Pervasives.Native.Mktuple2 #_ #_ c res = _ in let _ = _ in Lib.IntTypes.v c * Prims.pow2 (Lib.IntTypes.bits t * i) + Hacl.Spec.Bignum.Definitions.bn_v res == Hacl.Spec.Bignum.Definitions.eval_ aLen a i * Lib.IntTypes.v l) <: Type0))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Lib.IntTypes.size_nat", "Hacl.Spec.Bignum.Definitions.lbignum", "Hacl.Spec.Bignum.Definitions.limb", "Prims.nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "Lib.Sequence.seq", "Prims.eq2", "Lib.Sequence.length", "Prims.op_Equality", "Prims.int", "Prims.unit", "Hacl.Spec.Bignum.Definitions.bn_eval0", "FStar.Pervasives.assert_norm", "Prims.pow2", "Prims._assert", "Prims.l_and", "Lib.IntTypes.int_t", "Lib.IntTypes.SEC", "Lib.IntTypes.uint", "FStar.Seq.Base.seq", "Prims.l_or", "FStar.Seq.Base.length", "FStar.Seq.Base.empty", "Hacl.Spec.Lib.eq_generate_elems0", "Hacl.Spec.Bignum.Multiplication.bn_mul1_f", "Prims.bool", "Prims.op_Subtraction", "Prims.op_Addition", "FStar.Mul.op_Star", "Lib.IntTypes.v", "Hacl.Spec.Bignum.Definitions.bn_v", "Hacl.Spec.Bignum.Definitions.eval_", "Hacl.Spec.Bignum.Multiplication.bn_mul1_lemma_loop_step", "FStar.Pervasives.Native.Mktuple2", "Hacl.Spec.Bignum.Multiplication.bn_mul1_lemma_loop", "FStar.Pervasives.Native.tuple2", "Hacl.Spec.Lib.generate_elem_f", "Hacl.Spec.Lib.generate_elems", "Hacl.Spec.Lib.generate_elems_unfold", "Hacl.Spec.Lib.generate_elem_a", "Lib.IntTypes.bits" ]
[ "recursion" ]
false
false
true
false
false
let rec bn_mul1_lemma_loop #t #aLen a l i =
let pbits = bits t in let c, res:generate_elem_a (limb t) (limb t) aLen i = generate_elems aLen i (bn_mul1_f a l) (uint #t 0) in if i = 0 then (eq_generate_elems0 aLen i (bn_mul1_f a l) (uint #t 0); assert (c == uint #t 0 /\ res == Seq.empty); bn_eval0 #t #0 res; assert_norm (pow2 0 = 1); bn_eval0 a; ()) else let c1, res1:generate_elem_a (limb t) (limb t) aLen (i - 1) = generate_elems aLen (i - 1) (bn_mul1_f a l) (uint #t 0) in generate_elems_unfold aLen i (bn_mul1_f a l) (uint #t 0) (i - 1); assert (generate_elems aLen i (bn_mul1_f a l) (uint #t 0) == generate_elem_f aLen (bn_mul1_f a l) (i - 1) (generate_elems aLen (i - 1) (bn_mul1_f a l) (uint #t 0))); assert ((c, res) == generate_elem_f aLen (bn_mul1_f a l) (i - 1) (c1, res1)); bn_mul1_lemma_loop a l (i - 1); assert (v c1 * pow2 (pbits * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen a (i - 1) * v l); bn_mul1_lemma_loop_step a l i (c1, res1); assert (v c * pow2 (pbits * i) + bn_v #t #i res == eval_ aLen a i * v l); ()
false
FStar.Krml.Endianness.fst
FStar.Krml.Endianness.seq_uint64_of_be
val seq_uint64_of_be (l: nat) (b: bytes{S.length b = 8 * l}) : s: S.seq UInt64.t {S.length s = l}
val seq_uint64_of_be (l: nat) (b: bytes{S.length b = 8 * l}) : s: S.seq UInt64.t {S.length s = l}
let rec seq_uint64_of_be (l: nat) (b: bytes{ S.length b = 8 * l }): s:S.seq UInt64.t { S.length s = l } = if S.length b = 0 then S.empty else let hd, tl = Seq.split b 8 in S.cons (uint64_of_be hd) (seq_uint64_of_be (l - 1) tl)
{ "file_name": "krmllib/FStar.Krml.Endianness.fst", "git_rev": "da1e941b2fcb196aa5d1e34941aa00b4c67ac321", "git_url": "https://github.com/FStarLang/karamel.git", "project_name": "karamel" }
{ "end_col": 58, "end_line": 304, "start_col": 0, "start_line": 297 }
module FStar.Krml.Endianness open FStar.Mul open FStar.HyperStack.All module U8 = FStar.UInt8 module U32 = FStar.UInt32 module U64 = FStar.UInt64 module Math = FStar.Math.Lemmas module S = FStar.Seq (* Selectively imported from Hacl*'s FStar.Endianness.fst library, with several name changes *) inline_for_extraction noextract type bytes = S.seq U8.t /// lt_to_n interprets a byte sequence as a little-endian natural number [@(deprecated "FStar.Endianness.le_to_n")] val le_to_n : b:bytes -> Tot nat (decreases (S.length b)) let rec le_to_n b = if S.length b = 0 then 0 else U8.v (S.head b) + pow2 8 * le_to_n (S.tail b) /// be_to_n interprets a byte sequence as a big-endian natural number [@(deprecated "FStar.Endianness.be_to_n")] val be_to_n : b:bytes -> Tot nat (decreases (S.length b)) let rec be_to_n b = if S.length b = 0 then 0 else U8.v (S.last b) + pow2 8 * be_to_n (S.slice b 0 (S.length b - 1)) [@(deprecated "FStar.Endianness.lemma_euclidean_division")] private val lemma_euclidean_division: r:nat -> b:nat -> q:pos -> Lemma (requires (r < q)) (ensures (r + q * b < q * (b+1))) let lemma_euclidean_division r b q = () [@(deprecated "FStar.Endianness.lemma_factorise")] private val lemma_factorise: a:nat -> b:nat -> Lemma (a + a * b == a * (b + 1)) let lemma_factorise a b = () [@(deprecated "FStar.Endianness.lemma_le_to_n_is_bounded")] val lemma_le_to_n_is_bounded: b:bytes -> Lemma (requires True) (ensures (le_to_n b < pow2 (8 * Seq.length b))) (decreases (Seq.length b)) let rec lemma_le_to_n_is_bounded b = if Seq.length b = 0 then () else begin let s = Seq.slice b 1 (Seq.length b) in assert(Seq.length s = Seq.length b - 1); lemma_le_to_n_is_bounded s; assert(UInt8.v (Seq.index b 0) < pow2 8); assert(le_to_n s < pow2 (8 * Seq.length s)); assert(le_to_n b < pow2 8 + pow2 8 * pow2 (8 * (Seq.length b - 1))); lemma_euclidean_division (UInt8.v (Seq.index b 0)) (le_to_n s) (pow2 8); assert(le_to_n b <= pow2 8 * (le_to_n s + 1)); assert(le_to_n b <= pow2 8 * pow2 (8 * (Seq.length b - 1))); Math.Lemmas.pow2_plus 8 (8 * (Seq.length b - 1)); lemma_factorise 8 (Seq.length b - 1) end [@(deprecated "FStar.Endianness.lemma_be_to_n_is_bounded")] val lemma_be_to_n_is_bounded: b:bytes -> Lemma (requires True) (ensures (be_to_n b < pow2 (8 * Seq.length b))) (decreases (Seq.length b)) let rec lemma_be_to_n_is_bounded b = if Seq.length b = 0 then () else begin let s = Seq.slice b 0 (Seq.length b - 1) in assert(Seq.length s = Seq.length b - 1); lemma_be_to_n_is_bounded s; assert(UInt8.v (Seq.last b) < pow2 8); assert(be_to_n s < pow2 (8 * Seq.length s)); assert(be_to_n b < pow2 8 + pow2 8 * pow2 (8 * (Seq.length b - 1))); lemma_euclidean_division (UInt8.v (Seq.last b)) (be_to_n s) (pow2 8); assert(be_to_n b <= pow2 8 * (be_to_n s + 1)); assert(be_to_n b <= pow2 8 * pow2 (8 * (Seq.length b - 1))); Math.Lemmas.pow2_plus 8 (8 * (Seq.length b - 1)); lemma_factorise 8 (Seq.length b - 1) end /// n_to_le encodes a number as a little-endian byte sequence of a fixed, /// sufficiently large length [@(deprecated "FStar.Endianness.n_to_le")] val n_to_le : len:U32.t -> n:nat{n < pow2 (8 * U32.v len)} -> Tot (b:bytes{S.length b == U32.v len /\ n == le_to_n b}) (decreases (U32.v len)) let rec n_to_le len n = if len = 0ul then S.empty else let len = U32.(len -^ 1ul) in let byte = U8.uint_to_t (n % 256) in let n' = n / 256 in Math.pow2_plus 8 (8 * U32.v len); assert(n' < pow2 (8 * U32.v len )); let b' = n_to_le len n' in let b = S.cons byte b' in S.lemma_eq_intro b' (S.tail b); b /// n_to_be encodes a numbers as a big-endian byte sequence of a fixed, /// sufficiently large length [@(deprecated "FStar.Endianness.n_to_be")] val n_to_be: len:U32.t -> n:nat{n < pow2 (8 * U32.v len)} -> Tot (b:bytes{S.length b == U32.v len /\ n == be_to_n b}) (decreases (U32.v len)) let rec n_to_be len n = if len = 0ul then S.empty else let len = U32.(len -^ 1ul) in let byte = U8.uint_to_t (n % 256) in let n' = n / 256 in Math.pow2_plus 8 (8 * U32.v len); assert(n' < pow2 (8 * U32.v len )); let b' = n_to_be len n' in let b'' = S.create 1 byte in let b = S.append b' b'' in S.lemma_eq_intro b' (S.slice b 0 (U32.v len)); b [@(deprecated "FStar.Endianness.n_to_le_inj")] let n_to_le_inj (len:U32.t) (n1 n2: (n:nat{n < pow2 (8 * U32.v len)})) : Lemma (requires (n_to_le len n1 == n_to_le len n2)) (ensures (n1 == n2)) = // this lemma easily follows from le_to_n . (n_to_le len) == id, the inversion // proof in the spec for n_to_le () [@(deprecated "FStar.Endianness.n_to_be_inj")] let n_to_be_inj (len:U32.t) (n1 n2: (n:nat{n < pow2 (8 * U32.v len)})) : Lemma (requires (n_to_be len n1 == n_to_be len n2)) (ensures (n1 == n2)) = () [@(deprecated "FStar.Endianness.be_to_n_inj")] let rec be_to_n_inj (b1 b2: Seq.seq U8.t) : Lemma (requires (Seq.length b1 == Seq.length b2 /\ be_to_n b1 == be_to_n b2)) (ensures (Seq.equal b1 b2)) (decreases (Seq.length b1)) = if Seq.length b1 = 0 then () else begin be_to_n_inj (Seq.slice b1 0 (Seq.length b1 - 1)) (Seq.slice b2 0 (Seq.length b2 - 1)); Seq.lemma_split b1 (Seq.length b1 - 1); Seq.lemma_split b2 (Seq.length b2 - 1) end [@(deprecated "FStar.Endianness.le_to_n_inj")] let rec le_to_n_inj (b1 b2: Seq.seq U8.t) : Lemma (requires (Seq.length b1 == Seq.length b2 /\ le_to_n b1 == le_to_n b2)) (ensures (Seq.equal b1 b2)) (decreases (Seq.length b1)) = if Seq.length b1 = 0 then () else begin le_to_n_inj (Seq.slice b1 1 (Seq.length b1)) (Seq.slice b2 1 (Seq.length b2)); Seq.lemma_split b1 1; Seq.lemma_split b2 1 end [@(deprecated "FStar.Endianness.n_to_be_be_to_n")] let n_to_be_be_to_n (len: U32.t) (s: Seq.seq U8.t) : Lemma (requires (Seq.length s == U32.v len)) (ensures ( be_to_n s < pow2 (8 `Prims.op_Multiply` U32.v len) /\ n_to_be len (be_to_n s) == s )) [SMTPat (n_to_be len (be_to_n s))] = lemma_be_to_n_is_bounded s; be_to_n_inj s (n_to_be len (be_to_n s)) [@(deprecated "FStar.Endianness.n_to_le_le_to_n")] let n_to_le_le_to_n (len: U32.t) (s: Seq.seq U8.t) : Lemma (requires (Seq.length s == U32.v len)) (ensures ( le_to_n s < pow2 (8 `Prims.op_Multiply` U32.v len) /\ n_to_le len (le_to_n s) == s )) [SMTPat (n_to_le len (le_to_n s))] = lemma_le_to_n_is_bounded s; le_to_n_inj s (n_to_le len (le_to_n s)) (** A series of specializations to deal with machine integers *) [@(deprecated "FStar.Endianness.uint32_of_le")] let uint32_of_le (b: bytes { S.length b = 4 }) = let n = le_to_n b in lemma_le_to_n_is_bounded b; UInt32.uint_to_t n [@(deprecated "FStar.Endianness.le_of_uint32")] let le_of_uint32 (x: UInt32.t): b:bytes{ S.length b = 4 } = n_to_le 4ul (UInt32.v x) [@(deprecated "FStar.Endianness.uint32_of_be")] let uint32_of_be (b: bytes { S.length b = 4 }) = let n = be_to_n b in lemma_be_to_n_is_bounded b; UInt32.uint_to_t n [@(deprecated "FStar.Endianness.be_of_uint32")] let be_of_uint32 (x: UInt32.t): b:bytes{ S.length b = 4 } = n_to_be 4ul (UInt32.v x) [@(deprecated "FStar.Endianness.uint64_of_le")] let uint64_of_le (b: bytes { S.length b = 8 }) = let n = le_to_n b in lemma_le_to_n_is_bounded b; UInt64.uint_to_t n [@(deprecated "FStar.Endianness.le_of_uint64")] let le_of_uint64 (x: UInt64.t): b:bytes{ S.length b = 8 } = n_to_le 8ul (UInt64.v x) [@(deprecated "FStar.Endianness.uint64_of_be")] let uint64_of_be (b: bytes { S.length b = 8 }) = let n = be_to_n b in lemma_be_to_n_is_bounded b; UInt64.uint_to_t n [@(deprecated "FStar.Endianness.be_of_uint64")] let be_of_uint64 (x: UInt64.t): b:bytes{ S.length b = 8 } = n_to_be 8ul (UInt64.v x) [@(deprecated "FStar.Endianness.seq_uint32_of_le")] let rec seq_uint32_of_le (l: nat) (b: bytes{ S.length b = 4 * l }): s:S.seq UInt32.t { S.length s = l } = if S.length b = 0 then S.empty else let hd, tl = Seq.split b 4 in S.cons (uint32_of_le hd) (seq_uint32_of_le (l - 1) tl) [@(deprecated "FStar.Endianness.le_of_seq_uint32")] let rec le_of_seq_uint32 (s: S.seq UInt32.t): Tot (b:bytes { S.length b = 4 * S.length s }) (decreases (S.length s)) = if S.length s = 0 then S.empty else S.append (le_of_uint32 (S.head s)) (le_of_seq_uint32 (S.tail s)) [@(deprecated "FStar.Endianness.seq_uint32_of_be")] let rec seq_uint32_of_be (l: nat) (b: bytes{ S.length b = 4 * l }): s:S.seq UInt32.t { S.length s = l } = if S.length b = 0 then S.empty else let hd, tl = Seq.split b 4 in S.cons (uint32_of_be hd) (seq_uint32_of_be (l - 1) tl) [@(deprecated "FStar.Endianness.be_of_seq_uint32")] let rec be_of_seq_uint32 (s: S.seq UInt32.t): Tot (b:bytes { S.length b = 4 * S.length s }) (decreases (S.length s)) = if S.length s = 0 then S.empty else S.append (be_of_uint32 (S.head s)) (be_of_seq_uint32 (S.tail s)) [@(deprecated "FStar.Endianness.seq_uint64_of_le")] let rec seq_uint64_of_le (l: nat) (b: bytes{ S.length b = 8 * l }): s:S.seq UInt64.t { S.length s = l } = if S.length b = 0 then S.empty else let hd, tl = Seq.split b 8 in S.cons (uint64_of_le hd) (seq_uint64_of_le (l - 1) tl) [@(deprecated "FStar.Endianness.le_of_seq_uint64")] let rec le_of_seq_uint64 (s: S.seq UInt64.t): Tot (b:bytes { S.length b = 8 * S.length s }) (decreases (S.length s)) = if S.length s = 0 then S.empty else S.append (le_of_uint64 (S.head s)) (le_of_seq_uint64 (S.tail s))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.All.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "FStar.Krml.Endianness.fst" }
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Math.Lemmas", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Krml", "short_module": null }, { "abbrev": false, "full_module": "FStar.Krml", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
l: Prims.nat -> b: FStar.Krml.Endianness.bytes{FStar.Seq.Base.length b = 8 * l} -> s: FStar.Seq.Base.seq FStar.UInt64.t {FStar.Seq.Base.length s = l}
Prims.Tot
[ "total" ]
[]
[ "Prims.nat", "FStar.Krml.Endianness.bytes", "Prims.b2t", "Prims.op_Equality", "Prims.int", "FStar.Seq.Base.length", "FStar.UInt8.t", "FStar.Mul.op_Star", "FStar.Seq.Base.empty", "FStar.UInt64.t", "Prims.bool", "FStar.Seq.Base.seq", "FStar.Seq.Base.cons", "FStar.Krml.Endianness.uint64_of_be", "FStar.Krml.Endianness.seq_uint64_of_be", "Prims.op_Subtraction", "FStar.Pervasives.Native.tuple2", "FStar.Seq.Properties.split" ]
[ "recursion" ]
false
false
false
false
false
let rec seq_uint64_of_be (l: nat) (b: bytes{S.length b = 8 * l}) : s: S.seq UInt64.t {S.length s = l} =
if S.length b = 0 then S.empty else let hd, tl = Seq.split b 8 in S.cons (uint64_of_be hd) (seq_uint64_of_be (l - 1) tl)
false
FStar.Krml.Endianness.fst
FStar.Krml.Endianness.offset_uint32_be
val offset_uint32_be (b: bytes) (n i: nat) : Lemma (requires (S.length b = 4 * n /\ i < n)) (ensures (S.index (seq_uint32_of_be n b) i == uint32_of_be (S.slice b (4 * i) (4 * i + 4)))) (decreases (S.length b)) [SMTPat (S.index (seq_uint32_of_be n b) i)]
val offset_uint32_be (b: bytes) (n i: nat) : Lemma (requires (S.length b = 4 * n /\ i < n)) (ensures (S.index (seq_uint32_of_be n b) i == uint32_of_be (S.slice b (4 * i) (4 * i + 4)))) (decreases (S.length b)) [SMTPat (S.index (seq_uint32_of_be n b) i)]
let rec offset_uint32_be (b: bytes) (n: nat) (i: nat): Lemma (requires ( S.length b = 4 * n /\ i < n)) (ensures ( S.index (seq_uint32_of_be n b) i == uint32_of_be (S.slice b (4 * i) (4 * i + 4)))) (decreases ( S.length b)) [ SMTPat (S.index (seq_uint32_of_be n b) i) ] = if S.length b = 0 then false_elim () else let hd, tl = Seq.split b 4 in if i = 0 then () else offset_uint32_be tl (n - 1) (i - 1)
{ "file_name": "krmllib/FStar.Krml.Endianness.fst", "git_rev": "da1e941b2fcb196aa5d1e34941aa00b4c67ac321", "git_url": "https://github.com/FStarLang/karamel.git", "project_name": "karamel" }
{ "end_col": 41, "end_line": 338, "start_col": 0, "start_line": 320 }
module FStar.Krml.Endianness open FStar.Mul open FStar.HyperStack.All module U8 = FStar.UInt8 module U32 = FStar.UInt32 module U64 = FStar.UInt64 module Math = FStar.Math.Lemmas module S = FStar.Seq (* Selectively imported from Hacl*'s FStar.Endianness.fst library, with several name changes *) inline_for_extraction noextract type bytes = S.seq U8.t /// lt_to_n interprets a byte sequence as a little-endian natural number [@(deprecated "FStar.Endianness.le_to_n")] val le_to_n : b:bytes -> Tot nat (decreases (S.length b)) let rec le_to_n b = if S.length b = 0 then 0 else U8.v (S.head b) + pow2 8 * le_to_n (S.tail b) /// be_to_n interprets a byte sequence as a big-endian natural number [@(deprecated "FStar.Endianness.be_to_n")] val be_to_n : b:bytes -> Tot nat (decreases (S.length b)) let rec be_to_n b = if S.length b = 0 then 0 else U8.v (S.last b) + pow2 8 * be_to_n (S.slice b 0 (S.length b - 1)) [@(deprecated "FStar.Endianness.lemma_euclidean_division")] private val lemma_euclidean_division: r:nat -> b:nat -> q:pos -> Lemma (requires (r < q)) (ensures (r + q * b < q * (b+1))) let lemma_euclidean_division r b q = () [@(deprecated "FStar.Endianness.lemma_factorise")] private val lemma_factorise: a:nat -> b:nat -> Lemma (a + a * b == a * (b + 1)) let lemma_factorise a b = () [@(deprecated "FStar.Endianness.lemma_le_to_n_is_bounded")] val lemma_le_to_n_is_bounded: b:bytes -> Lemma (requires True) (ensures (le_to_n b < pow2 (8 * Seq.length b))) (decreases (Seq.length b)) let rec lemma_le_to_n_is_bounded b = if Seq.length b = 0 then () else begin let s = Seq.slice b 1 (Seq.length b) in assert(Seq.length s = Seq.length b - 1); lemma_le_to_n_is_bounded s; assert(UInt8.v (Seq.index b 0) < pow2 8); assert(le_to_n s < pow2 (8 * Seq.length s)); assert(le_to_n b < pow2 8 + pow2 8 * pow2 (8 * (Seq.length b - 1))); lemma_euclidean_division (UInt8.v (Seq.index b 0)) (le_to_n s) (pow2 8); assert(le_to_n b <= pow2 8 * (le_to_n s + 1)); assert(le_to_n b <= pow2 8 * pow2 (8 * (Seq.length b - 1))); Math.Lemmas.pow2_plus 8 (8 * (Seq.length b - 1)); lemma_factorise 8 (Seq.length b - 1) end [@(deprecated "FStar.Endianness.lemma_be_to_n_is_bounded")] val lemma_be_to_n_is_bounded: b:bytes -> Lemma (requires True) (ensures (be_to_n b < pow2 (8 * Seq.length b))) (decreases (Seq.length b)) let rec lemma_be_to_n_is_bounded b = if Seq.length b = 0 then () else begin let s = Seq.slice b 0 (Seq.length b - 1) in assert(Seq.length s = Seq.length b - 1); lemma_be_to_n_is_bounded s; assert(UInt8.v (Seq.last b) < pow2 8); assert(be_to_n s < pow2 (8 * Seq.length s)); assert(be_to_n b < pow2 8 + pow2 8 * pow2 (8 * (Seq.length b - 1))); lemma_euclidean_division (UInt8.v (Seq.last b)) (be_to_n s) (pow2 8); assert(be_to_n b <= pow2 8 * (be_to_n s + 1)); assert(be_to_n b <= pow2 8 * pow2 (8 * (Seq.length b - 1))); Math.Lemmas.pow2_plus 8 (8 * (Seq.length b - 1)); lemma_factorise 8 (Seq.length b - 1) end /// n_to_le encodes a number as a little-endian byte sequence of a fixed, /// sufficiently large length [@(deprecated "FStar.Endianness.n_to_le")] val n_to_le : len:U32.t -> n:nat{n < pow2 (8 * U32.v len)} -> Tot (b:bytes{S.length b == U32.v len /\ n == le_to_n b}) (decreases (U32.v len)) let rec n_to_le len n = if len = 0ul then S.empty else let len = U32.(len -^ 1ul) in let byte = U8.uint_to_t (n % 256) in let n' = n / 256 in Math.pow2_plus 8 (8 * U32.v len); assert(n' < pow2 (8 * U32.v len )); let b' = n_to_le len n' in let b = S.cons byte b' in S.lemma_eq_intro b' (S.tail b); b /// n_to_be encodes a numbers as a big-endian byte sequence of a fixed, /// sufficiently large length [@(deprecated "FStar.Endianness.n_to_be")] val n_to_be: len:U32.t -> n:nat{n < pow2 (8 * U32.v len)} -> Tot (b:bytes{S.length b == U32.v len /\ n == be_to_n b}) (decreases (U32.v len)) let rec n_to_be len n = if len = 0ul then S.empty else let len = U32.(len -^ 1ul) in let byte = U8.uint_to_t (n % 256) in let n' = n / 256 in Math.pow2_plus 8 (8 * U32.v len); assert(n' < pow2 (8 * U32.v len )); let b' = n_to_be len n' in let b'' = S.create 1 byte in let b = S.append b' b'' in S.lemma_eq_intro b' (S.slice b 0 (U32.v len)); b [@(deprecated "FStar.Endianness.n_to_le_inj")] let n_to_le_inj (len:U32.t) (n1 n2: (n:nat{n < pow2 (8 * U32.v len)})) : Lemma (requires (n_to_le len n1 == n_to_le len n2)) (ensures (n1 == n2)) = // this lemma easily follows from le_to_n . (n_to_le len) == id, the inversion // proof in the spec for n_to_le () [@(deprecated "FStar.Endianness.n_to_be_inj")] let n_to_be_inj (len:U32.t) (n1 n2: (n:nat{n < pow2 (8 * U32.v len)})) : Lemma (requires (n_to_be len n1 == n_to_be len n2)) (ensures (n1 == n2)) = () [@(deprecated "FStar.Endianness.be_to_n_inj")] let rec be_to_n_inj (b1 b2: Seq.seq U8.t) : Lemma (requires (Seq.length b1 == Seq.length b2 /\ be_to_n b1 == be_to_n b2)) (ensures (Seq.equal b1 b2)) (decreases (Seq.length b1)) = if Seq.length b1 = 0 then () else begin be_to_n_inj (Seq.slice b1 0 (Seq.length b1 - 1)) (Seq.slice b2 0 (Seq.length b2 - 1)); Seq.lemma_split b1 (Seq.length b1 - 1); Seq.lemma_split b2 (Seq.length b2 - 1) end [@(deprecated "FStar.Endianness.le_to_n_inj")] let rec le_to_n_inj (b1 b2: Seq.seq U8.t) : Lemma (requires (Seq.length b1 == Seq.length b2 /\ le_to_n b1 == le_to_n b2)) (ensures (Seq.equal b1 b2)) (decreases (Seq.length b1)) = if Seq.length b1 = 0 then () else begin le_to_n_inj (Seq.slice b1 1 (Seq.length b1)) (Seq.slice b2 1 (Seq.length b2)); Seq.lemma_split b1 1; Seq.lemma_split b2 1 end [@(deprecated "FStar.Endianness.n_to_be_be_to_n")] let n_to_be_be_to_n (len: U32.t) (s: Seq.seq U8.t) : Lemma (requires (Seq.length s == U32.v len)) (ensures ( be_to_n s < pow2 (8 `Prims.op_Multiply` U32.v len) /\ n_to_be len (be_to_n s) == s )) [SMTPat (n_to_be len (be_to_n s))] = lemma_be_to_n_is_bounded s; be_to_n_inj s (n_to_be len (be_to_n s)) [@(deprecated "FStar.Endianness.n_to_le_le_to_n")] let n_to_le_le_to_n (len: U32.t) (s: Seq.seq U8.t) : Lemma (requires (Seq.length s == U32.v len)) (ensures ( le_to_n s < pow2 (8 `Prims.op_Multiply` U32.v len) /\ n_to_le len (le_to_n s) == s )) [SMTPat (n_to_le len (le_to_n s))] = lemma_le_to_n_is_bounded s; le_to_n_inj s (n_to_le len (le_to_n s)) (** A series of specializations to deal with machine integers *) [@(deprecated "FStar.Endianness.uint32_of_le")] let uint32_of_le (b: bytes { S.length b = 4 }) = let n = le_to_n b in lemma_le_to_n_is_bounded b; UInt32.uint_to_t n [@(deprecated "FStar.Endianness.le_of_uint32")] let le_of_uint32 (x: UInt32.t): b:bytes{ S.length b = 4 } = n_to_le 4ul (UInt32.v x) [@(deprecated "FStar.Endianness.uint32_of_be")] let uint32_of_be (b: bytes { S.length b = 4 }) = let n = be_to_n b in lemma_be_to_n_is_bounded b; UInt32.uint_to_t n [@(deprecated "FStar.Endianness.be_of_uint32")] let be_of_uint32 (x: UInt32.t): b:bytes{ S.length b = 4 } = n_to_be 4ul (UInt32.v x) [@(deprecated "FStar.Endianness.uint64_of_le")] let uint64_of_le (b: bytes { S.length b = 8 }) = let n = le_to_n b in lemma_le_to_n_is_bounded b; UInt64.uint_to_t n [@(deprecated "FStar.Endianness.le_of_uint64")] let le_of_uint64 (x: UInt64.t): b:bytes{ S.length b = 8 } = n_to_le 8ul (UInt64.v x) [@(deprecated "FStar.Endianness.uint64_of_be")] let uint64_of_be (b: bytes { S.length b = 8 }) = let n = be_to_n b in lemma_be_to_n_is_bounded b; UInt64.uint_to_t n [@(deprecated "FStar.Endianness.be_of_uint64")] let be_of_uint64 (x: UInt64.t): b:bytes{ S.length b = 8 } = n_to_be 8ul (UInt64.v x) [@(deprecated "FStar.Endianness.seq_uint32_of_le")] let rec seq_uint32_of_le (l: nat) (b: bytes{ S.length b = 4 * l }): s:S.seq UInt32.t { S.length s = l } = if S.length b = 0 then S.empty else let hd, tl = Seq.split b 4 in S.cons (uint32_of_le hd) (seq_uint32_of_le (l - 1) tl) [@(deprecated "FStar.Endianness.le_of_seq_uint32")] let rec le_of_seq_uint32 (s: S.seq UInt32.t): Tot (b:bytes { S.length b = 4 * S.length s }) (decreases (S.length s)) = if S.length s = 0 then S.empty else S.append (le_of_uint32 (S.head s)) (le_of_seq_uint32 (S.tail s)) [@(deprecated "FStar.Endianness.seq_uint32_of_be")] let rec seq_uint32_of_be (l: nat) (b: bytes{ S.length b = 4 * l }): s:S.seq UInt32.t { S.length s = l } = if S.length b = 0 then S.empty else let hd, tl = Seq.split b 4 in S.cons (uint32_of_be hd) (seq_uint32_of_be (l - 1) tl) [@(deprecated "FStar.Endianness.be_of_seq_uint32")] let rec be_of_seq_uint32 (s: S.seq UInt32.t): Tot (b:bytes { S.length b = 4 * S.length s }) (decreases (S.length s)) = if S.length s = 0 then S.empty else S.append (be_of_uint32 (S.head s)) (be_of_seq_uint32 (S.tail s)) [@(deprecated "FStar.Endianness.seq_uint64_of_le")] let rec seq_uint64_of_le (l: nat) (b: bytes{ S.length b = 8 * l }): s:S.seq UInt64.t { S.length s = l } = if S.length b = 0 then S.empty else let hd, tl = Seq.split b 8 in S.cons (uint64_of_le hd) (seq_uint64_of_le (l - 1) tl) [@(deprecated "FStar.Endianness.le_of_seq_uint64")] let rec le_of_seq_uint64 (s: S.seq UInt64.t): Tot (b:bytes { S.length b = 8 * S.length s }) (decreases (S.length s)) = if S.length s = 0 then S.empty else S.append (le_of_uint64 (S.head s)) (le_of_seq_uint64 (S.tail s)) [@(deprecated "FStar.Endianness.seq_uint64_of_be")] let rec seq_uint64_of_be (l: nat) (b: bytes{ S.length b = 8 * l }): s:S.seq UInt64.t { S.length s = l } = if S.length b = 0 then S.empty else let hd, tl = Seq.split b 8 in S.cons (uint64_of_be hd) (seq_uint64_of_be (l - 1) tl) [@(deprecated "FStar.Endianness.be_of_seq_uint64")] let rec be_of_seq_uint64 (s: S.seq UInt64.t): Tot (b:bytes { S.length b = 8 * S.length s }) (decreases (S.length s)) = if S.length s = 0 then S.empty else S.append (be_of_uint64 (S.head s)) (be_of_seq_uint64 (S.tail s)) #set-options "--max_fuel 1 --max_ifuel 0 --z3rlimit 50"
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.All.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "FStar.Krml.Endianness.fst" }
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Math.Lemmas", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Krml", "short_module": null }, { "abbrev": false, "full_module": "FStar.Krml", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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": 1, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b: FStar.Krml.Endianness.bytes -> n: Prims.nat -> i: Prims.nat -> FStar.Pervasives.Lemma (requires FStar.Seq.Base.length b = 4 * n /\ i < n) (ensures FStar.Seq.Base.index (FStar.Krml.Endianness.seq_uint32_of_be n b) i == FStar.Krml.Endianness.uint32_of_be (FStar.Seq.Base.slice b (4 * i) (4 * i + 4))) (decreases FStar.Seq.Base.length b) [SMTPat (FStar.Seq.Base.index (FStar.Krml.Endianness.seq_uint32_of_be n b) i)]
FStar.Pervasives.Lemma
[ "lemma", "" ]
[]
[ "FStar.Krml.Endianness.bytes", "Prims.nat", "Prims.op_Equality", "Prims.int", "FStar.Seq.Base.length", "FStar.UInt8.t", "FStar.Pervasives.false_elim", "Prims.unit", "Prims.bool", "FStar.Seq.Base.seq", "FStar.Krml.Endianness.offset_uint32_be", "Prims.op_Subtraction", "FStar.Pervasives.Native.tuple2", "FStar.Seq.Properties.split", "Prims.l_and", "Prims.b2t", "FStar.Mul.op_Star", "Prims.op_LessThan", "Prims.squash", "Prims.eq2", "FStar.UInt32.t", "FStar.Seq.Base.index", "FStar.Krml.Endianness.seq_uint32_of_be", "FStar.Krml.Endianness.uint32_of_be", "FStar.Seq.Base.slice", "Prims.op_Addition", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat", "Prims.Nil" ]
[ "recursion" ]
false
false
true
false
false
let rec offset_uint32_be (b: bytes) (n i: nat) : Lemma (requires (S.length b = 4 * n /\ i < n)) (ensures (S.index (seq_uint32_of_be n b) i == uint32_of_be (S.slice b (4 * i) (4 * i + 4)))) (decreases (S.length b)) [SMTPat (S.index (seq_uint32_of_be n b) i)] =
if S.length b = 0 then false_elim () else let hd, tl = Seq.split b 4 in if i = 0 then () else offset_uint32_be tl (n - 1) (i - 1)
false
Hacl.Spec.Bignum.Multiplication.fst
Hacl.Spec.Bignum.Multiplication.bn_mul_loop_lemma_step
val bn_mul_loop_lemma_step: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat{aLen + bLen <= max_size_t} -> a:lbignum t aLen -> b:lbignum t bLen -> i:pos{i <= bLen} -> resi1:lbignum t (aLen + bLen) -> Lemma (requires eval_ (aLen + bLen) resi1 (aLen + i - 1) == bn_v a * eval_ bLen b (i - 1)) (ensures (let resi = bn_mul_ a b (i - 1) resi1 in eval_ (aLen + bLen) resi (aLen + i) == bn_v a * eval_ bLen b i))
val bn_mul_loop_lemma_step: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat{aLen + bLen <= max_size_t} -> a:lbignum t aLen -> b:lbignum t bLen -> i:pos{i <= bLen} -> resi1:lbignum t (aLen + bLen) -> Lemma (requires eval_ (aLen + bLen) resi1 (aLen + i - 1) == bn_v a * eval_ bLen b (i - 1)) (ensures (let resi = bn_mul_ a b (i - 1) resi1 in eval_ (aLen + bLen) resi (aLen + i) == bn_v a * eval_ bLen b i))
let bn_mul_loop_lemma_step #t #aLen #bLen a b i resi1 = let pbits = bits t in let resi = bn_mul_ a b (i - 1) resi1 in bn_mul_lemma_ a b (i - 1) resi1; assert (v resi.[aLen + i - 1] * pow2 (pbits * (aLen + i - 1)) + eval_ (aLen + bLen) resi (aLen + i - 1) == eval_ (aLen + bLen) resi1 (aLen + i - 1) + bn_v a * v b.[i - 1] * (pow2 (pbits * (i - 1)))); calc (==) { eval_ (aLen + bLen) resi (aLen + i); (==) { bn_eval_unfold_i resi (aLen + i) } eval_ (aLen + bLen) resi (aLen + i - 1) + v resi.[aLen + i - 1] * pow2 (pbits * (aLen + i - 1)); (==) { } eval_ (aLen + bLen) resi1 (aLen + i - 1) + bn_v a * v b.[i - 1] * (pow2 (pbits * (i - 1))); (==) { } bn_v a * eval_ bLen b (i - 1) + bn_v a * v b.[i - 1] * (pow2 (pbits * (i - 1))); (==) { Math.Lemmas.paren_mul_right (bn_v a) (v b.[i - 1]) (pow2 (pbits * (i - 1))) } bn_v a * eval_ bLen b (i - 1) + bn_v a * (v b.[i - 1] * (pow2 (pbits * (i - 1)))); (==) { Math.Lemmas.distributivity_add_right (bn_v a) (eval_ bLen b (i - 1)) (v b.[i - 1] * (pow2 (pbits * (i - 1)))) } bn_v a * (eval_ bLen b (i - 1) + v b.[i - 1] * (pow2 (pbits * (i - 1)))); (==) { bn_eval_unfold_i b i } bn_v a * eval_ bLen b i; }; assert (eval_ (aLen + bLen) resi (aLen + i) == bn_v a * eval_ bLen b i)
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Multiplication.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 73, "end_line": 415, "start_col": 0, "start_line": 392 }
module Hacl.Spec.Bignum.Multiplication open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.LoopCombinators open Hacl.Spec.Bignum.Definitions open Hacl.Spec.Bignum.Base open Hacl.Spec.Lib #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" val bn_mul1_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> l:limb t -> i:size_nat{i < aLen} -> c:limb t -> limb t & limb t // carry & out let bn_mul1_f #t #aLen a l i c = mul_wide_add a.[i] l c val bn_mul1: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> l:limb t -> limb t & lbignum t aLen let bn_mul1 #t #aLen a l = generate_elems aLen aLen (bn_mul1_f a l) (uint #t 0) val bn_mul1_add_in_place_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> l:limb t -> acc:lbignum t aLen -> i:size_nat{i < aLen} -> c:limb t -> limb t & limb t // carry & out let bn_mul1_add_in_place_f #t #aLen a l acc i c = mul_wide_add2 a.[i] l c acc.[i] val bn_mul1_add_in_place: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> l:limb t -> acc:lbignum t aLen -> limb t & lbignum t aLen let bn_mul1_add_in_place #t #aLen a l acc = generate_elems aLen aLen (bn_mul1_add_in_place_f a l acc) (uint #t 0) val bn_mul1_lshift_add: #t:limb_t -> #aLen:size_nat -> #resLen:size_nat -> a:lbignum t aLen -> b_j:limb t -> j:size_nat{j + aLen <= resLen} -> res:lbignum t resLen -> limb t & lbignum t resLen let bn_mul1_lshift_add #t #aLen #resLen a b_j j res = let res' = sub res j aLen in let c, res' = bn_mul1_add_in_place a b_j res' in let res = update_sub res j aLen res' in c, res val bn_mul_: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat{aLen + bLen <= max_size_t} -> a:lbignum t aLen -> b:lbignum t bLen -> j:size_nat{j < bLen} -> res:lbignum t (aLen + bLen) -> lbignum t (aLen + bLen) let bn_mul_ #t #aLen #bLen a b j res = let c, res = bn_mul1_lshift_add a b.[j] j res in res.[aLen + j] <- c val bn_mul: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat{aLen + bLen <= max_size_t} -> a:lbignum t aLen -> b:lbignum t bLen -> lbignum t (aLen + bLen) let bn_mul #t #aLen #bLen a b = let res = create (aLen + bLen) (uint #t 0) in repeati bLen (bn_mul_ a b) res val bn_mul1_lemma_loop_step: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> l:limb t -> i:pos{i <= aLen} -> c1_res1:generate_elem_a (limb t) (limb t) aLen (i - 1) -> Lemma (requires (let (c1, res1) = c1_res1 in v c1 * pow2 (bits t * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen a (i - 1) * v l)) (ensures (let (c1, res1) = c1_res1 in let (c, res) = generate_elem_f aLen (bn_mul1_f a l) (i - 1) (c1, res1) in v c * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen a i * v l)) let bn_mul1_lemma_loop_step #t #aLen a l i (c1, res1) = let pbits = bits t in let b1 = pow2 (pbits * (i - 1)) in let b2 = pow2 (pbits * i) in let (c, res) = generate_elem_f aLen (bn_mul1_f a l) (i - 1) (c1, res1) in let c, e = mul_wide_add a.[i - 1] l c1 in assert (v e + v c * pow2 pbits == v a.[i - 1] * v l + v c1); calc (==) { v c * b2 + bn_v #t #i res; (==) { bn_eval_snoc #t #(i - 1) res1 e } v c * b2 + bn_v #t #(i - 1) res1 + v e * b1; (==) { } v c * b2 + eval_ aLen a (i - 1) * v l -(v e + v c * pow2 pbits - v a.[i - 1] * v l) * b1 + v e * b1; (==) { Math.Lemmas.distributivity_add_left (v e) (v c * pow2 pbits - v a.[i - 1] * v l) b1 } v c * b2 + eval_ aLen a (i - 1) * v l - (v c * pow2 pbits - v a.[i - 1] * v l) * b1; (==) { Math.Lemmas.distributivity_sub_left (v c * pow2 pbits) (v a.[i - 1] * v l) b1 } v c * b2 + eval_ aLen a (i - 1) * v l - v c * pow2 pbits * b1 + v a.[i - 1] * v l * b1; (==) { Math.Lemmas.paren_mul_right (v c) (pow2 pbits) b1; Math.Lemmas.pow2_plus pbits (pbits * (i - 1)) } eval_ aLen a (i - 1) * v l + v a.[i - 1] * v l * b1; (==) { Math.Lemmas.paren_mul_right (v a.[i - 1]) (v l) b1 } eval_ aLen a (i - 1) * v l + v a.[i - 1] * (b1 * v l); (==) { Math.Lemmas.paren_mul_right (v a.[i - 1]) b1 (v l) } eval_ aLen a (i - 1) * v l + v a.[i - 1] * b1 * v l; (==) { Math.Lemmas.distributivity_add_left (eval_ aLen a (i - 1)) (v a.[i - 1] * b1) (v l) } (eval_ aLen a (i - 1) + v a.[i - 1] * b1) * v l; (==) { bn_eval_unfold_i a i } eval_ aLen a i * v l; }; assert (v c * b2 + bn_v #t #i res == eval_ aLen a i * v l) val bn_mul1_lemma_loop: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> l:limb t -> i:nat{i <= aLen} -> Lemma (let (c, res) : generate_elem_a (limb t) (limb t) aLen i = generate_elems aLen i (bn_mul1_f a l) (uint #t 0) in v c * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen a i * v l) let rec bn_mul1_lemma_loop #t #aLen a l i = let pbits = bits t in let (c, res) : generate_elem_a (limb t) (limb t) aLen i = generate_elems aLen i (bn_mul1_f a l) (uint #t 0) in if i = 0 then begin eq_generate_elems0 aLen i (bn_mul1_f a l) (uint #t 0); assert (c == uint #t 0 /\ res == Seq.empty); bn_eval0 #t #0 res; assert_norm (pow2 0 = 1); bn_eval0 a; () end else begin let (c1, res1) : generate_elem_a (limb t) (limb t) aLen (i - 1) = generate_elems aLen (i - 1) (bn_mul1_f a l) (uint #t 0) in generate_elems_unfold aLen i (bn_mul1_f a l) (uint #t 0) (i - 1); assert (generate_elems aLen i (bn_mul1_f a l) (uint #t 0) == generate_elem_f aLen (bn_mul1_f a l) (i - 1) (generate_elems aLen (i - 1) (bn_mul1_f a l) (uint #t 0))); assert ((c, res) == generate_elem_f aLen (bn_mul1_f a l) (i - 1) (c1, res1)); bn_mul1_lemma_loop a l (i - 1); assert (v c1 * pow2 (pbits * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen a (i - 1) * v l); bn_mul1_lemma_loop_step a l i (c1, res1); assert (v c * pow2 (pbits * i) + bn_v #t #i res == eval_ aLen a i * v l); () end val bn_mul1_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> l:limb t -> Lemma (let (c, res) = bn_mul1 a l in v c * pow2 (bits t * aLen) + bn_v res == bn_v a * v l) let bn_mul1_lemma #t #aLen a l = let (c, res) = bn_mul1 a l in bn_mul1_lemma_loop a l aLen #push-options "--z3rlimit 150" val bn_mul1_add_in_place_lemma_loop_step: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> l:limb t -> acc:lbignum t aLen -> i:pos{i <= aLen} -> c1_res1:generate_elem_a (limb t) (limb t) aLen (i - 1) -> Lemma (requires (let (c1, res1) = c1_res1 in v c1 * pow2 (bits t * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen acc (i - 1) + eval_ aLen a (i - 1) * v l)) (ensures (let (c1, res1) = c1_res1 in let (c, res) = generate_elem_f aLen (bn_mul1_add_in_place_f a l acc) (i - 1) (c1, res1) in v c * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen acc i + eval_ aLen a i * v l)) let bn_mul1_add_in_place_lemma_loop_step #t #aLen a l acc i (c1, res1) = let pbits = bits t in let b1 = pow2 (pbits * (i - 1)) in let b2 = pow2 (pbits * i) in let (c, res) = generate_elem_f aLen (bn_mul1_add_in_place_f a l acc) (i - 1) (c1, res1) in let c, e = mul_wide_add2 a.[i - 1] l c1 acc.[i - 1] in assert (v e + v c * pow2 pbits == v a.[i - 1] * v l + v c1 + v acc.[i - 1]); calc (==) { v c * b2 + bn_v #t #i res; (==) { bn_eval_snoc #t #(i - 1) res1 e } v c * b2 + bn_v #t #(i - 1) res1 + v e * b1; (==) { } v c * b2 + eval_ aLen acc (i - 1) + eval_ aLen a (i - 1) * v l - (v e + v c * pow2 pbits - v a.[i - 1] * v l - v acc.[i - 1]) * b1 + v e * b1; (==) { Math.Lemmas.distributivity_add_left (v e) (v c * pow2 pbits - v a.[i - 1] * v l - v acc.[i - 1]) b1 } v c * b2 + eval_ aLen acc (i - 1) + eval_ aLen a (i - 1) * v l - (v c * pow2 pbits - v a.[i - 1] * v l - v acc.[i - 1]) * b1; (==) { Math.Lemmas.distributivity_sub_left (v c * pow2 pbits) (v a.[i - 1] * v l + v acc.[i - 1]) b1 } v c * b2 + eval_ aLen acc (i - 1) + eval_ aLen a (i - 1) * v l - (v c * pow2 pbits) * b1 + (v a.[i - 1] * v l + v acc.[i - 1]) * b1; (==) { Math.Lemmas.paren_mul_right (v c) (pow2 pbits) b1; Math.Lemmas.pow2_plus pbits (pbits * (i - 1)) } eval_ aLen acc (i - 1) + eval_ aLen a (i - 1) * v l + (v a.[i - 1] * v l + v acc.[i - 1]) * b1; (==) { Math.Lemmas.distributivity_add_left (v a.[i - 1] * v l) (v acc.[i - 1]) b1 } eval_ aLen acc (i - 1) + eval_ aLen a (i - 1) * v l + v a.[i - 1] * v l * b1 + v acc.[i - 1] * b1; (==) { bn_eval_unfold_i acc i } eval_ aLen acc i + eval_ aLen a (i - 1) * v l + v a.[i - 1] * v l * b1; (==) { Math.Lemmas.paren_mul_right (v a.[i - 1]) (v l) b1 } eval_ aLen acc i + eval_ aLen a (i - 1) * v l + v a.[i - 1] * (b1 * v l); (==) { Math.Lemmas.paren_mul_right (v a.[i - 1]) b1 (v l) } eval_ aLen acc i + eval_ aLen a (i - 1) * v l + v a.[i - 1] * b1 * v l; (==) { Math.Lemmas.distributivity_add_left (eval_ aLen a (i - 1)) (v a.[i - 1] * b1) (v l) } eval_ aLen acc i + (eval_ aLen a (i - 1) + v a.[i - 1] * b1) * v l; (==) { bn_eval_unfold_i a i } eval_ aLen acc i + eval_ aLen a i * v l; }; assert (v c * b2 + bn_v #t #i res == eval_ aLen acc i + eval_ aLen a i * v l) #pop-options val bn_mul1_add_in_place_lemma_loop: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> l:limb t -> acc:lbignum t aLen -> i:nat{i <= aLen} -> Lemma (let (c, res) : generate_elem_a (limb t) (limb t) aLen i = generate_elems aLen i (bn_mul1_add_in_place_f a l acc) (uint #t 0) in v c * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen acc i + eval_ aLen a i * v l) let rec bn_mul1_add_in_place_lemma_loop #t #aLen a l acc i = let pbits = bits t in let (c, res) : generate_elem_a (limb t) (limb t) aLen i = generate_elems aLen i (bn_mul1_add_in_place_f a l acc) (uint #t 0) in if i = 0 then begin eq_generate_elems0 aLen i (bn_mul1_add_in_place_f a l acc) (uint #t 0); assert (c == uint #t 0 /\ res == Seq.empty); bn_eval0 #t #0 res; assert_norm (pow2 0 = 1); bn_eval0 a; bn_eval0 acc; () end else begin let (c1, res1) : generate_elem_a (limb t) (limb t) aLen (i - 1) = generate_elems aLen (i - 1) (bn_mul1_add_in_place_f a l acc) (uint #t 0) in generate_elems_unfold aLen i (bn_mul1_add_in_place_f a l acc) (uint #t 0) (i - 1); assert (generate_elems aLen i (bn_mul1_add_in_place_f a l acc) (uint #t 0) == generate_elem_f aLen (bn_mul1_add_in_place_f a l acc) (i - 1) (generate_elems aLen (i - 1) (bn_mul1_add_in_place_f a l acc) (uint #t 0))); assert ((c, res) == generate_elem_f aLen (bn_mul1_add_in_place_f a l acc) (i - 1) (c1, res1)); bn_mul1_add_in_place_lemma_loop a l acc (i - 1); assert (v c1 * pow2 (pbits * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen acc (i - 1) + eval_ aLen a (i - 1) * v l); bn_mul1_add_in_place_lemma_loop_step a l acc i (c1, res1); assert (v c * pow2 (pbits * i) + bn_v #t #i res == eval_ aLen acc i + eval_ aLen a i * v l); () end val bn_mul1_add_in_place_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> l:limb t -> acc:lbignum t aLen -> Lemma (let (c, res) = bn_mul1_add_in_place a l acc in v c * pow2 (bits t * aLen) + bn_v res == bn_v acc + bn_v a * v l) let bn_mul1_add_in_place_lemma #t #aLen a l acc = let (c, res) = bn_mul1_add_in_place a l acc in bn_mul1_add_in_place_lemma_loop a l acc aLen val bn_mul1_lshift_add_lemma: #t:limb_t -> #aLen:size_nat -> #resLen:size_nat -> a:lbignum t aLen -> b_j:limb t -> j:size_nat{j + aLen <= resLen} -> acc:lbignum t resLen -> Lemma (let (c, res) = bn_mul1_lshift_add a b_j j acc in v c * pow2 (bits t * (aLen + j)) + eval_ resLen res (aLen + j) == eval_ resLen acc (aLen + j) + bn_v a * v b_j * pow2 (bits t * j) /\ slice res (aLen + j) resLen == slice acc (aLen + j) resLen) let bn_mul1_lshift_add_lemma #t #aLen #resLen a b_j j acc = let pbits = bits t in let res1 = sub acc j aLen in let c, res2 = bn_mul1_add_in_place a b_j res1 in bn_mul1_add_in_place_lemma a b_j res1; assert (v c * pow2 (pbits * aLen) + bn_v res2 == bn_v res1 + bn_v a * v b_j); let res = update_sub acc j aLen res2 in bn_eval_split_i (sub res 0 (j + aLen)) j; bn_eval_extensionality_j res (sub res 0 (j + aLen)) (j + aLen); assert (eval_ resLen res (j + aLen) == bn_v #t #j (sub res 0 j) + pow2 (pbits * j) * bn_v res2); eq_intro (sub res 0 j) (sub acc 0 j); assert (bn_v #t #j (sub res 0 j) == bn_v #t #j (sub acc 0 j)); bn_eval_split_i (sub acc 0 (j + aLen)) j; bn_eval_extensionality_j acc (sub acc 0 (j + aLen)) (j + aLen); assert (eval_ resLen acc (j + aLen) == bn_v #t #j (sub acc 0 j) + pow2 (pbits * j) * bn_v res1); calc (==) { v c * pow2 (pbits * (aLen + j)) + eval_ resLen res (aLen + j); (==) { Math.Lemmas.pow2_plus (pbits * aLen) (pbits * j) } v c * (pow2 (pbits * aLen) * pow2 (pbits * j)) + eval_ resLen res (aLen + j); (==) { Math.Lemmas.paren_mul_right (v c) (pow2 (pbits * aLen)) (pow2 (pbits * j)) } v c * pow2 (pbits * aLen) * pow2 (pbits * j) + eval_ resLen res (aLen + j); (==) { } (bn_v res1 + bn_v a * v b_j - bn_v res2) * pow2 (pbits * j) + eval_ resLen res (aLen + j); (==) { } (bn_v res1 + bn_v a * v b_j - bn_v res2) * pow2 (pbits * j) + eval_ resLen acc (j + aLen) - pow2 (pbits * j) * bn_v res1 + pow2 (pbits * j) * bn_v res2; (==) { Math.Lemmas.distributivity_add_right (pow2 (pbits * j)) (bn_v res1) (bn_v a * v b_j - bn_v res2) } pow2 (pbits * j) * (bn_v a * v b_j - bn_v res2) + eval_ resLen acc (j + aLen) + pow2 (pbits * j) * bn_v res2; (==) { Math.Lemmas.distributivity_sub_right (pow2 (pbits * j)) (bn_v a * v b_j) (bn_v res2) } pow2 (pbits * j) * (bn_v a * v b_j) + eval_ resLen acc (j + aLen); }; assert (v c * pow2 (pbits * (aLen + j)) + eval_ resLen res (aLen + j) == eval_ resLen acc (aLen + j) + bn_v a * v b_j * pow2 (pbits * j)); eq_intro (slice res (aLen + j) resLen) (slice acc (aLen + j) resLen) val bn_mul_lemma_: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat{aLen + bLen <= max_size_t} -> a:lbignum t aLen -> b:lbignum t bLen -> j:size_nat{j < bLen} -> acc:lbignum t (aLen + bLen) -> Lemma (let res = bn_mul_ a b j acc in v res.[aLen + j] * pow2 (bits t * (aLen + j)) + eval_ (aLen + bLen) res (aLen + j) == eval_ (aLen + bLen) acc (aLen + j) + bn_v a * v b.[j] * pow2 (bits t * j)) let bn_mul_lemma_ #t #aLen #bLen a b j acc = let c, res = bn_mul1_lshift_add a b.[j] j acc in bn_mul1_lshift_add_lemma a b.[j] j acc; let res1 = res.[aLen + j] <- c in bn_eval_extensionality_j res res1 (aLen + j) val bn_mul_loop_lemma_step: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat{aLen + bLen <= max_size_t} -> a:lbignum t aLen -> b:lbignum t bLen -> i:pos{i <= bLen} -> resi1:lbignum t (aLen + bLen) -> Lemma (requires eval_ (aLen + bLen) resi1 (aLen + i - 1) == bn_v a * eval_ bLen b (i - 1)) (ensures (let resi = bn_mul_ a b (i - 1) resi1 in eval_ (aLen + bLen) resi (aLen + i) == bn_v a * eval_ bLen b i))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Lib.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Bignum.Multiplication.fst" }
[ { "abbrev": false, "full_module": "Hacl.Spec.Lib", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Base", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> b: Hacl.Spec.Bignum.Definitions.lbignum t bLen -> i: Prims.pos{i <= bLen} -> resi1: Hacl.Spec.Bignum.Definitions.lbignum t (aLen + bLen) -> FStar.Pervasives.Lemma (requires Hacl.Spec.Bignum.Definitions.eval_ (aLen + bLen) resi1 (aLen + i - 1) == Hacl.Spec.Bignum.Definitions.bn_v a * Hacl.Spec.Bignum.Definitions.eval_ bLen b (i - 1)) (ensures (let resi = Hacl.Spec.Bignum.Multiplication.bn_mul_ a b (i - 1) resi1 in Hacl.Spec.Bignum.Definitions.eval_ (aLen + bLen) resi (aLen + i) == Hacl.Spec.Bignum.Definitions.bn_v a * Hacl.Spec.Bignum.Definitions.eval_ bLen b i))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Lib.IntTypes.size_nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "Lib.IntTypes.max_size_t", "Hacl.Spec.Bignum.Definitions.lbignum", "Prims.pos", "Prims._assert", "Prims.eq2", "Prims.int", "Hacl.Spec.Bignum.Definitions.eval_", "FStar.Mul.op_Star", "Hacl.Spec.Bignum.Definitions.bn_v", "Prims.unit", "FStar.Calc.calc_finish", "Prims.nat", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "FStar.Calc.calc_step", "Prims.op_Subtraction", "Lib.IntTypes.v", "Lib.IntTypes.SEC", "Lib.Sequence.op_String_Access", "Hacl.Spec.Bignum.Definitions.limb", "Prims.pow2", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "Hacl.Spec.Bignum.Definitions.bn_eval_unfold_i", "Prims.squash", "FStar.Math.Lemmas.paren_mul_right", "FStar.Math.Lemmas.distributivity_add_right", "Hacl.Spec.Bignum.Multiplication.bn_mul_lemma_", "Hacl.Spec.Bignum.Multiplication.bn_mul_", "Lib.IntTypes.bits" ]
[]
false
false
true
false
false
let bn_mul_loop_lemma_step #t #aLen #bLen a b i resi1 =
let pbits = bits t in let resi = bn_mul_ a b (i - 1) resi1 in bn_mul_lemma_ a b (i - 1) resi1; assert (v resi.[ aLen + i - 1 ] * pow2 (pbits * (aLen + i - 1)) + eval_ (aLen + bLen) resi (aLen + i - 1) == eval_ (aLen + bLen) resi1 (aLen + i - 1) + (bn_v a * v b.[ i - 1 ]) * (pow2 (pbits * (i - 1)))); calc ( == ) { eval_ (aLen + bLen) resi (aLen + i); ( == ) { bn_eval_unfold_i resi (aLen + i) } eval_ (aLen + bLen) resi (aLen + i - 1) + v resi.[ aLen + i - 1 ] * pow2 (pbits * (aLen + i - 1)); ( == ) { () } eval_ (aLen + bLen) resi1 (aLen + i - 1) + (bn_v a * v b.[ i - 1 ]) * (pow2 (pbits * (i - 1))); ( == ) { () } bn_v a * eval_ bLen b (i - 1) + (bn_v a * v b.[ i - 1 ]) * (pow2 (pbits * (i - 1))); ( == ) { Math.Lemmas.paren_mul_right (bn_v a) (v b.[ i - 1 ]) (pow2 (pbits * (i - 1))) } bn_v a * eval_ bLen b (i - 1) + bn_v a * (v b.[ i - 1 ] * (pow2 (pbits * (i - 1)))); ( == ) { Math.Lemmas.distributivity_add_right (bn_v a) (eval_ bLen b (i - 1)) (v b.[ i - 1 ] * (pow2 (pbits * (i - 1)))) } bn_v a * (eval_ bLen b (i - 1) + v b.[ i - 1 ] * (pow2 (pbits * (i - 1)))); ( == ) { bn_eval_unfold_i b i } bn_v a * eval_ bLen b i; }; assert (eval_ (aLen + bLen) resi (aLen + i) == bn_v a * eval_ bLen b i)
false
Vale.AES.X64.GF128_Init.fsti
Vale.AES.X64.GF128_Init.va_ens_Keyhash_init
val va_ens_Keyhash_init (va_b0: va_code) (va_s0: va_state) (win: bool) (alg: algorithm) (key: (seq nat32)) (roundkeys_b hkeys_b: buffer128) (va_sM: va_state) (va_fM: va_fuel) : prop
val va_ens_Keyhash_init (va_b0: va_code) (va_s0: va_state) (win: bool) (alg: algorithm) (key: (seq nat32)) (roundkeys_b hkeys_b: buffer128) (va_sM: va_state) (va_fM: va_fuel) : prop
let va_ens_Keyhash_init (va_b0:va_code) (va_s0:va_state) (win:bool) (alg:algorithm) (key:(seq nat32)) (roundkeys_b:buffer128) (hkeys_b:buffer128) (va_sM:va_state) (va_fM:va_fuel) : prop = (va_req_Keyhash_init va_b0 va_s0 win alg key roundkeys_b hkeys_b /\ va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\ (let (round_ptr:(va_int_range 0 18446744073709551615)) = (if win then va_get_reg64 rRcx va_s0 else va_get_reg64 rRdi va_s0) in let (hkey_ptr:(va_int_range 0 18446744073709551615)) = (if win then va_get_reg64 rRdx va_s0 else va_get_reg64 rRsi va_s0) in Vale.X64.Decls.modifies_buffer128 hkeys_b (va_get_mem va_s0) (va_get_mem va_sM) /\ Vale.AES.OptPublic.hkeys_reqs_pub (Vale.X64.Decls.s128 (va_get_mem va_sM) hkeys_b) (Vale.Def.Types_s.reverse_bytes_quad32 (Vale.AES.AES_s.aes_encrypt_LE alg key (Vale.Def.Words_s.Mkfour #Vale.Def.Types_s.nat32 0 0 0 0))) /\ va_get_xmm 6 va_sM == va_get_xmm 6 va_s0 /\ va_get_reg64 rR12 va_sM == va_get_reg64 rR12 va_s0) /\ va_state_eq va_sM (va_update_flags va_sM (va_update_xmm 6 va_sM (va_update_xmm 5 va_sM (va_update_xmm 4 va_sM (va_update_xmm 3 va_sM (va_update_xmm 2 va_sM (va_update_xmm 1 va_sM (va_update_xmm 0 va_sM (va_update_mem_layout va_sM (va_update_mem_heaplet 1 va_sM (va_update_reg64 rR12 va_sM (va_update_reg64 rR8 va_sM (va_update_reg64 rRdx va_sM (va_update_reg64 rRcx va_sM (va_update_reg64 rRax va_sM (va_update_ok va_sM (va_update_mem va_sM va_s0))))))))))))))))))
{ "file_name": "obj/Vale.AES.X64.GF128_Init.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 96, "end_line": 68, "start_col": 0, "start_line": 53 }
module Vale.AES.X64.GF128_Init open Vale.Def.Words_s open Vale.Def.Words.Four_s open Vale.Def.Types_s open FStar.Seq open Vale.Arch.Types open Vale.Arch.HeapImpl open Vale.Math.Poly2_s open Vale.Math.Poly2 open Vale.Math.Poly2.Bits_s open Vale.Math.Poly2.Bits open Vale.Math.Poly2.Lemmas open Vale.AES.GF128_s open Vale.AES.GF128 open Vale.AES.GHash open Vale.AES.AES_s open Vale.AES.AES256_helpers open Vale.AES.X64.AES open Vale.X64.Machine_s open Vale.X64.Memory open Vale.X64.State open Vale.X64.Decls open Vale.X64.InsBasic open Vale.X64.InsMem open Vale.X64.InsVector open Vale.X64.InsAes open Vale.X64.QuickCode open Vale.X64.QuickCodes open Vale.X64.CPU_Features_s open Vale.AES.X64.PolyOps open Vale.AES.X64.GF128_Mul open Vale.AES.GHash open Vale.AES.OptPublic //-- Keyhash_init val va_code_Keyhash_init : win:bool -> alg:algorithm -> Tot va_code val va_codegen_success_Keyhash_init : win:bool -> alg:algorithm -> Tot va_pbool let va_req_Keyhash_init (va_b0:va_code) (va_s0:va_state) (win:bool) (alg:algorithm) (key:(seq nat32)) (roundkeys_b:buffer128) (hkeys_b:buffer128) : prop = (va_require_total va_b0 (va_code_Keyhash_init win alg) va_s0 /\ va_get_ok va_s0 /\ (let (round_ptr:(va_int_range 0 18446744073709551615)) = (if win then va_get_reg64 rRcx va_s0 else va_get_reg64 rRdi va_s0) in let (hkey_ptr:(va_int_range 0 18446744073709551615)) = (if win then va_get_reg64 rRdx va_s0 else va_get_reg64 rRsi va_s0) in Vale.X64.Memory.is_initial_heap (va_get_mem_layout va_s0) (va_get_mem va_s0) /\ (aesni_enabled /\ pclmulqdq_enabled /\ avx_enabled /\ sse_enabled) /\ (alg = AES_128 \/ alg = AES_256) /\ Vale.X64.Decls.buffers_disjoint128 roundkeys_b hkeys_b /\ Vale.AES.AES_s.is_aes_key_LE alg key /\ Vale.X64.Decls.buffer128_as_seq (va_get_mem va_s0) roundkeys_b == Vale.AES.AES_s.key_to_round_keys_LE alg key /\ Vale.X64.Decls.validSrcAddrs128 (va_get_mem va_s0) round_ptr roundkeys_b (Vale.AES.AES_common_s.nr alg + 1) (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validDstAddrs128 (va_get_mem va_s0) hkey_ptr hkeys_b 8
{ "checked_file": "/", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.QuickCodes.fsti.checked", "Vale.X64.QuickCode.fst.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.InsVector.fsti.checked", "Vale.X64.InsMem.fsti.checked", "Vale.X64.InsBasic.fsti.checked", "Vale.X64.InsAes.fsti.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Decls.fsti.checked", "Vale.X64.CPU_Features_s.fst.checked", "Vale.Math.Poly2_s.fsti.checked", "Vale.Math.Poly2.Lemmas.fsti.checked", "Vale.Math.Poly2.Bits_s.fsti.checked", "Vale.Math.Poly2.Bits.fsti.checked", "Vale.Math.Poly2.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Arch.Types.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "Vale.AES.X64.PolyOps.fsti.checked", "Vale.AES.X64.GF128_Mul.fsti.checked", "Vale.AES.X64.AES.fsti.checked", "Vale.AES.OptPublic.fsti.checked", "Vale.AES.GHash.fsti.checked", "Vale.AES.GF128_s.fsti.checked", "Vale.AES.GF128.fsti.checked", "Vale.AES.AES_s.fst.checked", "Vale.AES.AES_common_s.fst.checked", "Vale.AES.AES256_helpers.fsti.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Vale.AES.X64.GF128_Init.fsti" }
[ { "abbrev": false, "full_module": "Vale.AES.OptPublic", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.X64.GF128_Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.X64.PolyOps", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.CPU_Features_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCodes", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsAes", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsVector", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsMem", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsBasic", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.X64.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES256_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
va_b0: Vale.X64.Decls.va_code -> va_s0: Vale.X64.Decls.va_state -> win: Prims.bool -> alg: Vale.AES.AES_common_s.algorithm -> key: FStar.Seq.Base.seq Vale.X64.Memory.nat32 -> roundkeys_b: Vale.X64.Memory.buffer128 -> hkeys_b: Vale.X64.Memory.buffer128 -> va_sM: Vale.X64.Decls.va_state -> va_fM: Vale.X64.Decls.va_fuel -> Prims.prop
Prims.Tot
[ "total" ]
[]
[ "Vale.X64.Decls.va_code", "Vale.X64.Decls.va_state", "Prims.bool", "Vale.AES.AES_common_s.algorithm", "FStar.Seq.Base.seq", "Vale.X64.Memory.nat32", "Vale.X64.Memory.buffer128", "Vale.X64.Decls.va_fuel", "Prims.l_and", "Vale.AES.X64.GF128_Init.va_req_Keyhash_init", "Vale.X64.Decls.va_ensure_total", "Prims.b2t", "Vale.X64.Decls.va_get_ok", "Vale.X64.Decls.modifies_buffer128", "Vale.X64.Decls.va_get_mem", "Vale.AES.OptPublic.hkeys_reqs_pub", "Vale.X64.Decls.s128", "Vale.Def.Types_s.reverse_bytes_quad32", "Vale.AES.AES_s.aes_encrypt_LE", "Vale.Def.Words_s.Mkfour", "Vale.Def.Types_s.nat32", "Prims.eq2", "Vale.X64.Decls.quad32", "Vale.X64.Decls.va_get_xmm", "Vale.Def.Types_s.nat64", "Vale.X64.Decls.va_get_reg64", "Vale.X64.Machine_s.rR12", "Vale.X64.Decls.va_int_range", "Vale.X64.Machine_s.rRdx", "Vale.X64.Machine_s.rRsi", "Vale.X64.Machine_s.rRcx", "Vale.X64.Machine_s.rRdi", "Vale.X64.Decls.va_state_eq", "Vale.X64.Decls.va_update_flags", "Vale.X64.Decls.va_update_xmm", "Vale.X64.Decls.va_update_mem_layout", "Vale.X64.Decls.va_update_mem_heaplet", "Vale.X64.Decls.va_update_reg64", "Vale.X64.Machine_s.rR8", "Vale.X64.Machine_s.rRax", "Vale.X64.Decls.va_update_ok", "Vale.X64.Decls.va_update_mem", "Prims.prop" ]
[]
false
false
false
true
true
let va_ens_Keyhash_init (va_b0: va_code) (va_s0: va_state) (win: bool) (alg: algorithm) (key: (seq nat32)) (roundkeys_b hkeys_b: buffer128) (va_sM: va_state) (va_fM: va_fuel) : prop =
(va_req_Keyhash_init va_b0 va_s0 win alg key roundkeys_b hkeys_b /\ va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\ (let round_ptr:(va_int_range 0 18446744073709551615) = (if win then va_get_reg64 rRcx va_s0 else va_get_reg64 rRdi va_s0) in let hkey_ptr:(va_int_range 0 18446744073709551615) = (if win then va_get_reg64 rRdx va_s0 else va_get_reg64 rRsi va_s0) in Vale.X64.Decls.modifies_buffer128 hkeys_b (va_get_mem va_s0) (va_get_mem va_sM) /\ Vale.AES.OptPublic.hkeys_reqs_pub (Vale.X64.Decls.s128 (va_get_mem va_sM) hkeys_b) (Vale.Def.Types_s.reverse_bytes_quad32 (Vale.AES.AES_s.aes_encrypt_LE alg key (Vale.Def.Words_s.Mkfour #Vale.Def.Types_s.nat32 0 0 0 0))) /\ va_get_xmm 6 va_sM == va_get_xmm 6 va_s0 /\ va_get_reg64 rR12 va_sM == va_get_reg64 rR12 va_s0) /\ va_state_eq va_sM (va_update_flags va_sM (va_update_xmm 6 va_sM (va_update_xmm 5 va_sM (va_update_xmm 4 va_sM (va_update_xmm 3 va_sM (va_update_xmm 2 va_sM (va_update_xmm 1 va_sM (va_update_xmm 0 va_sM (va_update_mem_layout va_sM (va_update_mem_heaplet 1 va_sM (va_update_reg64 rR12 va_sM (va_update_reg64 rR8 va_sM (va_update_reg64 rRdx va_sM (va_update_reg64 rRcx va_sM (va_update_reg64 rRax va_sM (va_update_ok va_sM (va_update_mem va_sM va_s0)))))) ))))))))))))
false
FStar.Krml.Endianness.fst
FStar.Krml.Endianness.seq_uint32_of_be_be_of_seq_uint32
val seq_uint32_of_be_be_of_seq_uint32 (n: nat) (s: S.seq U32.t) : Lemma (requires (n == S.length s)) (ensures ((seq_uint32_of_be n (be_of_seq_uint32 s)) `S.equal` s)) (decreases n) [SMTPat (seq_uint32_of_be n (be_of_seq_uint32 s))]
val seq_uint32_of_be_be_of_seq_uint32 (n: nat) (s: S.seq U32.t) : Lemma (requires (n == S.length s)) (ensures ((seq_uint32_of_be n (be_of_seq_uint32 s)) `S.equal` s)) (decreases n) [SMTPat (seq_uint32_of_be n (be_of_seq_uint32 s))]
let rec seq_uint32_of_be_be_of_seq_uint32 (n: nat) (s: S.seq U32.t) : Lemma (requires (n == S.length s)) (ensures (seq_uint32_of_be n (be_of_seq_uint32 s) `S.equal` s)) (decreases n) [SMTPat (seq_uint32_of_be n (be_of_seq_uint32 s))] = if n = 0 then () else begin assert (s `S.equal` S.cons (S.head s) (S.tail s)); seq_uint32_of_be_be_of_seq_uint32 (n - 1) (S.tail s); let s' = be_of_seq_uint32 s in S.lemma_split s' 4; S.lemma_append_inj (S.slice s' 0 4) (S.slice s' 4 (S.length s')) (be_of_uint32 (S.head s)) (be_of_seq_uint32 (S.tail s)) end
{ "file_name": "krmllib/FStar.Krml.Endianness.fst", "git_rev": "da1e941b2fcb196aa5d1e34941aa00b4c67ac321", "git_url": "https://github.com/FStarLang/karamel.git", "project_name": "karamel" }
{ "end_col": 5, "end_line": 526, "start_col": 0, "start_line": 513 }
module FStar.Krml.Endianness open FStar.Mul open FStar.HyperStack.All module U8 = FStar.UInt8 module U32 = FStar.UInt32 module U64 = FStar.UInt64 module Math = FStar.Math.Lemmas module S = FStar.Seq (* Selectively imported from Hacl*'s FStar.Endianness.fst library, with several name changes *) inline_for_extraction noextract type bytes = S.seq U8.t /// lt_to_n interprets a byte sequence as a little-endian natural number [@(deprecated "FStar.Endianness.le_to_n")] val le_to_n : b:bytes -> Tot nat (decreases (S.length b)) let rec le_to_n b = if S.length b = 0 then 0 else U8.v (S.head b) + pow2 8 * le_to_n (S.tail b) /// be_to_n interprets a byte sequence as a big-endian natural number [@(deprecated "FStar.Endianness.be_to_n")] val be_to_n : b:bytes -> Tot nat (decreases (S.length b)) let rec be_to_n b = if S.length b = 0 then 0 else U8.v (S.last b) + pow2 8 * be_to_n (S.slice b 0 (S.length b - 1)) [@(deprecated "FStar.Endianness.lemma_euclidean_division")] private val lemma_euclidean_division: r:nat -> b:nat -> q:pos -> Lemma (requires (r < q)) (ensures (r + q * b < q * (b+1))) let lemma_euclidean_division r b q = () [@(deprecated "FStar.Endianness.lemma_factorise")] private val lemma_factorise: a:nat -> b:nat -> Lemma (a + a * b == a * (b + 1)) let lemma_factorise a b = () [@(deprecated "FStar.Endianness.lemma_le_to_n_is_bounded")] val lemma_le_to_n_is_bounded: b:bytes -> Lemma (requires True) (ensures (le_to_n b < pow2 (8 * Seq.length b))) (decreases (Seq.length b)) let rec lemma_le_to_n_is_bounded b = if Seq.length b = 0 then () else begin let s = Seq.slice b 1 (Seq.length b) in assert(Seq.length s = Seq.length b - 1); lemma_le_to_n_is_bounded s; assert(UInt8.v (Seq.index b 0) < pow2 8); assert(le_to_n s < pow2 (8 * Seq.length s)); assert(le_to_n b < pow2 8 + pow2 8 * pow2 (8 * (Seq.length b - 1))); lemma_euclidean_division (UInt8.v (Seq.index b 0)) (le_to_n s) (pow2 8); assert(le_to_n b <= pow2 8 * (le_to_n s + 1)); assert(le_to_n b <= pow2 8 * pow2 (8 * (Seq.length b - 1))); Math.Lemmas.pow2_plus 8 (8 * (Seq.length b - 1)); lemma_factorise 8 (Seq.length b - 1) end [@(deprecated "FStar.Endianness.lemma_be_to_n_is_bounded")] val lemma_be_to_n_is_bounded: b:bytes -> Lemma (requires True) (ensures (be_to_n b < pow2 (8 * Seq.length b))) (decreases (Seq.length b)) let rec lemma_be_to_n_is_bounded b = if Seq.length b = 0 then () else begin let s = Seq.slice b 0 (Seq.length b - 1) in assert(Seq.length s = Seq.length b - 1); lemma_be_to_n_is_bounded s; assert(UInt8.v (Seq.last b) < pow2 8); assert(be_to_n s < pow2 (8 * Seq.length s)); assert(be_to_n b < pow2 8 + pow2 8 * pow2 (8 * (Seq.length b - 1))); lemma_euclidean_division (UInt8.v (Seq.last b)) (be_to_n s) (pow2 8); assert(be_to_n b <= pow2 8 * (be_to_n s + 1)); assert(be_to_n b <= pow2 8 * pow2 (8 * (Seq.length b - 1))); Math.Lemmas.pow2_plus 8 (8 * (Seq.length b - 1)); lemma_factorise 8 (Seq.length b - 1) end /// n_to_le encodes a number as a little-endian byte sequence of a fixed, /// sufficiently large length [@(deprecated "FStar.Endianness.n_to_le")] val n_to_le : len:U32.t -> n:nat{n < pow2 (8 * U32.v len)} -> Tot (b:bytes{S.length b == U32.v len /\ n == le_to_n b}) (decreases (U32.v len)) let rec n_to_le len n = if len = 0ul then S.empty else let len = U32.(len -^ 1ul) in let byte = U8.uint_to_t (n % 256) in let n' = n / 256 in Math.pow2_plus 8 (8 * U32.v len); assert(n' < pow2 (8 * U32.v len )); let b' = n_to_le len n' in let b = S.cons byte b' in S.lemma_eq_intro b' (S.tail b); b /// n_to_be encodes a numbers as a big-endian byte sequence of a fixed, /// sufficiently large length [@(deprecated "FStar.Endianness.n_to_be")] val n_to_be: len:U32.t -> n:nat{n < pow2 (8 * U32.v len)} -> Tot (b:bytes{S.length b == U32.v len /\ n == be_to_n b}) (decreases (U32.v len)) let rec n_to_be len n = if len = 0ul then S.empty else let len = U32.(len -^ 1ul) in let byte = U8.uint_to_t (n % 256) in let n' = n / 256 in Math.pow2_plus 8 (8 * U32.v len); assert(n' < pow2 (8 * U32.v len )); let b' = n_to_be len n' in let b'' = S.create 1 byte in let b = S.append b' b'' in S.lemma_eq_intro b' (S.slice b 0 (U32.v len)); b [@(deprecated "FStar.Endianness.n_to_le_inj")] let n_to_le_inj (len:U32.t) (n1 n2: (n:nat{n < pow2 (8 * U32.v len)})) : Lemma (requires (n_to_le len n1 == n_to_le len n2)) (ensures (n1 == n2)) = // this lemma easily follows from le_to_n . (n_to_le len) == id, the inversion // proof in the spec for n_to_le () [@(deprecated "FStar.Endianness.n_to_be_inj")] let n_to_be_inj (len:U32.t) (n1 n2: (n:nat{n < pow2 (8 * U32.v len)})) : Lemma (requires (n_to_be len n1 == n_to_be len n2)) (ensures (n1 == n2)) = () [@(deprecated "FStar.Endianness.be_to_n_inj")] let rec be_to_n_inj (b1 b2: Seq.seq U8.t) : Lemma (requires (Seq.length b1 == Seq.length b2 /\ be_to_n b1 == be_to_n b2)) (ensures (Seq.equal b1 b2)) (decreases (Seq.length b1)) = if Seq.length b1 = 0 then () else begin be_to_n_inj (Seq.slice b1 0 (Seq.length b1 - 1)) (Seq.slice b2 0 (Seq.length b2 - 1)); Seq.lemma_split b1 (Seq.length b1 - 1); Seq.lemma_split b2 (Seq.length b2 - 1) end [@(deprecated "FStar.Endianness.le_to_n_inj")] let rec le_to_n_inj (b1 b2: Seq.seq U8.t) : Lemma (requires (Seq.length b1 == Seq.length b2 /\ le_to_n b1 == le_to_n b2)) (ensures (Seq.equal b1 b2)) (decreases (Seq.length b1)) = if Seq.length b1 = 0 then () else begin le_to_n_inj (Seq.slice b1 1 (Seq.length b1)) (Seq.slice b2 1 (Seq.length b2)); Seq.lemma_split b1 1; Seq.lemma_split b2 1 end [@(deprecated "FStar.Endianness.n_to_be_be_to_n")] let n_to_be_be_to_n (len: U32.t) (s: Seq.seq U8.t) : Lemma (requires (Seq.length s == U32.v len)) (ensures ( be_to_n s < pow2 (8 `Prims.op_Multiply` U32.v len) /\ n_to_be len (be_to_n s) == s )) [SMTPat (n_to_be len (be_to_n s))] = lemma_be_to_n_is_bounded s; be_to_n_inj s (n_to_be len (be_to_n s)) [@(deprecated "FStar.Endianness.n_to_le_le_to_n")] let n_to_le_le_to_n (len: U32.t) (s: Seq.seq U8.t) : Lemma (requires (Seq.length s == U32.v len)) (ensures ( le_to_n s < pow2 (8 `Prims.op_Multiply` U32.v len) /\ n_to_le len (le_to_n s) == s )) [SMTPat (n_to_le len (le_to_n s))] = lemma_le_to_n_is_bounded s; le_to_n_inj s (n_to_le len (le_to_n s)) (** A series of specializations to deal with machine integers *) [@(deprecated "FStar.Endianness.uint32_of_le")] let uint32_of_le (b: bytes { S.length b = 4 }) = let n = le_to_n b in lemma_le_to_n_is_bounded b; UInt32.uint_to_t n [@(deprecated "FStar.Endianness.le_of_uint32")] let le_of_uint32 (x: UInt32.t): b:bytes{ S.length b = 4 } = n_to_le 4ul (UInt32.v x) [@(deprecated "FStar.Endianness.uint32_of_be")] let uint32_of_be (b: bytes { S.length b = 4 }) = let n = be_to_n b in lemma_be_to_n_is_bounded b; UInt32.uint_to_t n [@(deprecated "FStar.Endianness.be_of_uint32")] let be_of_uint32 (x: UInt32.t): b:bytes{ S.length b = 4 } = n_to_be 4ul (UInt32.v x) [@(deprecated "FStar.Endianness.uint64_of_le")] let uint64_of_le (b: bytes { S.length b = 8 }) = let n = le_to_n b in lemma_le_to_n_is_bounded b; UInt64.uint_to_t n [@(deprecated "FStar.Endianness.le_of_uint64")] let le_of_uint64 (x: UInt64.t): b:bytes{ S.length b = 8 } = n_to_le 8ul (UInt64.v x) [@(deprecated "FStar.Endianness.uint64_of_be")] let uint64_of_be (b: bytes { S.length b = 8 }) = let n = be_to_n b in lemma_be_to_n_is_bounded b; UInt64.uint_to_t n [@(deprecated "FStar.Endianness.be_of_uint64")] let be_of_uint64 (x: UInt64.t): b:bytes{ S.length b = 8 } = n_to_be 8ul (UInt64.v x) [@(deprecated "FStar.Endianness.seq_uint32_of_le")] let rec seq_uint32_of_le (l: nat) (b: bytes{ S.length b = 4 * l }): s:S.seq UInt32.t { S.length s = l } = if S.length b = 0 then S.empty else let hd, tl = Seq.split b 4 in S.cons (uint32_of_le hd) (seq_uint32_of_le (l - 1) tl) [@(deprecated "FStar.Endianness.le_of_seq_uint32")] let rec le_of_seq_uint32 (s: S.seq UInt32.t): Tot (b:bytes { S.length b = 4 * S.length s }) (decreases (S.length s)) = if S.length s = 0 then S.empty else S.append (le_of_uint32 (S.head s)) (le_of_seq_uint32 (S.tail s)) [@(deprecated "FStar.Endianness.seq_uint32_of_be")] let rec seq_uint32_of_be (l: nat) (b: bytes{ S.length b = 4 * l }): s:S.seq UInt32.t { S.length s = l } = if S.length b = 0 then S.empty else let hd, tl = Seq.split b 4 in S.cons (uint32_of_be hd) (seq_uint32_of_be (l - 1) tl) [@(deprecated "FStar.Endianness.be_of_seq_uint32")] let rec be_of_seq_uint32 (s: S.seq UInt32.t): Tot (b:bytes { S.length b = 4 * S.length s }) (decreases (S.length s)) = if S.length s = 0 then S.empty else S.append (be_of_uint32 (S.head s)) (be_of_seq_uint32 (S.tail s)) [@(deprecated "FStar.Endianness.seq_uint64_of_le")] let rec seq_uint64_of_le (l: nat) (b: bytes{ S.length b = 8 * l }): s:S.seq UInt64.t { S.length s = l } = if S.length b = 0 then S.empty else let hd, tl = Seq.split b 8 in S.cons (uint64_of_le hd) (seq_uint64_of_le (l - 1) tl) [@(deprecated "FStar.Endianness.le_of_seq_uint64")] let rec le_of_seq_uint64 (s: S.seq UInt64.t): Tot (b:bytes { S.length b = 8 * S.length s }) (decreases (S.length s)) = if S.length s = 0 then S.empty else S.append (le_of_uint64 (S.head s)) (le_of_seq_uint64 (S.tail s)) [@(deprecated "FStar.Endianness.seq_uint64_of_be")] let rec seq_uint64_of_be (l: nat) (b: bytes{ S.length b = 8 * l }): s:S.seq UInt64.t { S.length s = l } = if S.length b = 0 then S.empty else let hd, tl = Seq.split b 8 in S.cons (uint64_of_be hd) (seq_uint64_of_be (l - 1) tl) [@(deprecated "FStar.Endianness.be_of_seq_uint64")] let rec be_of_seq_uint64 (s: S.seq UInt64.t): Tot (b:bytes { S.length b = 8 * S.length s }) (decreases (S.length s)) = if S.length s = 0 then S.empty else S.append (be_of_uint64 (S.head s)) (be_of_seq_uint64 (S.tail s)) #set-options "--max_fuel 1 --max_ifuel 0 --z3rlimit 50" [@(deprecated "FStar.Endianness.offset_uint32_be")] let rec offset_uint32_be (b: bytes) (n: nat) (i: nat): Lemma (requires ( S.length b = 4 * n /\ i < n)) (ensures ( S.index (seq_uint32_of_be n b) i == uint32_of_be (S.slice b (4 * i) (4 * i + 4)))) (decreases ( S.length b)) [ SMTPat (S.index (seq_uint32_of_be n b) i) ] = if S.length b = 0 then false_elim () else let hd, tl = Seq.split b 4 in if i = 0 then () else offset_uint32_be tl (n - 1) (i - 1) [@(deprecated "FStar.Endianness.offset_uint32_le")] let rec offset_uint32_le (b: bytes) (n: nat) (i: nat): Lemma (requires ( S.length b = 4 * n /\ i < n)) (ensures ( S.index (seq_uint32_of_le n b) i == uint32_of_le (S.slice b (4 * i) (4 * i + 4)))) (decreases ( S.length b)) [ SMTPat (S.index (seq_uint32_of_le n b) i) ] = if S.length b = 0 then false_elim () else let hd, tl = Seq.split b 4 in if i = 0 then () else offset_uint32_le tl (n - 1) (i - 1) [@(deprecated "FStar.Endianness.offset_uint64_be")] let rec offset_uint64_be (b: bytes) (n: nat) (i: nat): Lemma (requires ( S.length b = 8 * n /\ i < n)) (ensures ( S.index (seq_uint64_of_be n b) i == uint64_of_be (S.slice b (8 * i) (8 * i + 8)))) (decreases ( S.length b)) [ SMTPat (S.index (seq_uint64_of_be n b) i) ] = if S.length b = 0 then false_elim () else let hd, tl = Seq.split b 8 in if i = 0 then () else offset_uint64_be tl (n - 1) (i - 1) [@(deprecated "FStar.Endianness.offset_uint64_le")] let rec offset_uint64_le (b: bytes) (n: nat) (i: nat): Lemma (requires ( S.length b = 8 * n /\ i < n)) (ensures ( S.index (seq_uint64_of_le n b) i == uint64_of_le (S.slice b (8 * i) (8 * i + 8)))) (decreases ( S.length b)) [ SMTPat (S.index (seq_uint64_of_le n b) i) ] = if S.length b = 0 then false_elim () else let hd, tl = Seq.split b 8 in if i = 0 then () else offset_uint64_le tl (n - 1) (i - 1) (** Reasoning about endian-ness and words. *) #set-options "--max_fuel 1 --z3rlimit 20" (* TODO: move to FStar.Seq.Properties, with the pattern *) [@(deprecated "FStar.Endianness.tail_cons")] let tail_cons (#a: Type) (hd: a) (tl: S.seq a): Lemma (ensures (S.equal (S.tail (S.cons hd tl)) tl)) // [ SMTPat (S.tail (S.cons hd tl)) ] = () [@(deprecated "FStar.Endianness.be_of_seq_uint32_append")] let rec be_of_seq_uint32_append (s1 s2: S.seq U32.t): Lemma (ensures ( S.equal (be_of_seq_uint32 (S.append s1 s2)) (S.append (be_of_seq_uint32 s1) (be_of_seq_uint32 s2)))) (decreases ( S.length s1)) [ SMTPat (S.append (be_of_seq_uint32 s1) (be_of_seq_uint32 s2)) ] = Classical.forall_intro_2 (tail_cons #U32.t); // TODO: this is a local pattern, remove once tail_cons lands in FStar.Seq.Properties if S.length s1 = 0 then begin assert (S.equal (be_of_seq_uint32 s1) S.empty); assert (S.equal (S.append s1 s2) s2); () end else begin assert (S.equal (S.append s1 s2) (S.cons (S.head s1) (S.append (S.tail s1) s2))); assert (S.equal (be_of_seq_uint32 (S.append s1 s2)) (S.append (be_of_uint32 (S.head s1)) (be_of_seq_uint32 (S.append (S.tail s1) s2)))); be_of_seq_uint32_append (S.tail s1) s2 end [@(deprecated "FStar.Endianness.be_of_seq_uint32_base")] let be_of_seq_uint32_base (s1: S.seq U32.t) (s2: S.seq U8.t): Lemma (requires ( S.length s1 = 1 /\ S.length s2 = 4 /\ be_to_n s2 = U32.v (S.index s1 0))) (ensures (S.equal s2 (be_of_seq_uint32 s1))) [ SMTPat (be_to_n s2 = U32.v (S.index s1 0)) ] = () [@(deprecated "FStar.Endianness.le_of_seq_uint32_append")] let rec le_of_seq_uint32_append (s1 s2: S.seq U32.t): Lemma (ensures ( S.equal (le_of_seq_uint32 (S.append s1 s2)) (S.append (le_of_seq_uint32 s1) (le_of_seq_uint32 s2)))) (decreases ( S.length s1)) [ SMTPat (S.append (le_of_seq_uint32 s1) (le_of_seq_uint32 s2)) ] = Classical.forall_intro_2 (tail_cons #U32.t); // TODO: this is a local pattern, remove once tail_cons lands in FStar.Seq.Properties if S.length s1 = 0 then begin assert (S.equal (le_of_seq_uint32 s1) S.empty); assert (S.equal (S.append s1 s2) s2); () end else begin assert (S.equal (S.append s1 s2) (S.cons (S.head s1) (S.append (S.tail s1) s2))); assert (S.equal (le_of_seq_uint32 (S.append s1 s2)) (S.append (le_of_uint32 (S.head s1)) (le_of_seq_uint32 (S.append (S.tail s1) s2)))); le_of_seq_uint32_append (S.tail s1) s2 end [@(deprecated "FStar.Endianness.le_of_seq_uint32_base")] let le_of_seq_uint32_base (s1: S.seq U32.t) (s2: S.seq U8.t): Lemma (requires ( S.length s1 = 1 /\ S.length s2 = 4 /\ le_to_n s2 = U32.v (S.index s1 0))) (ensures (S.equal s2 (le_of_seq_uint32 s1))) [ SMTPat (le_to_n s2 = U32.v (S.index s1 0)) ] = () [@(deprecated "FStar.Endianness.be_of_seq_uint64_append")] let rec be_of_seq_uint64_append (s1 s2: S.seq U64.t): Lemma (ensures ( S.equal (be_of_seq_uint64 (S.append s1 s2)) (S.append (be_of_seq_uint64 s1) (be_of_seq_uint64 s2)))) (decreases ( S.length s1)) [ SMTPat (S.append (be_of_seq_uint64 s1) (be_of_seq_uint64 s2)) ] = Classical.forall_intro_2 (tail_cons #U64.t); // TODO: this is a local pattern, remove once tail_cons lands in FStar.Seq.Properties if S.length s1 = 0 then begin assert (S.equal (be_of_seq_uint64 s1) S.empty); assert (S.equal (S.append s1 s2) s2); () end else begin assert (S.equal (S.append s1 s2) (S.cons (S.head s1) (S.append (S.tail s1) s2))); assert (S.equal (be_of_seq_uint64 (S.append s1 s2)) (S.append (be_of_uint64 (S.head s1)) (be_of_seq_uint64 (S.append (S.tail s1) s2)))); be_of_seq_uint64_append (S.tail s1) s2 end [@(deprecated "FStar.Endianness.be_of_seq_uint64_base")] let be_of_seq_uint64_base (s1: S.seq U64.t) (s2: S.seq U8.t): Lemma (requires ( S.length s1 = 1 /\ S.length s2 = 8 /\ be_to_n s2 = U64.v (S.index s1 0))) (ensures (S.equal s2 (be_of_seq_uint64 s1))) [ SMTPat (be_to_n s2 = U64.v (S.index s1 0)) ] = ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.All.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "FStar.Krml.Endianness.fst" }
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Math.Lemmas", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Krml", "short_module": null }, { "abbrev": false, "full_module": "FStar.Krml", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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": 1, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
n: Prims.nat -> s: FStar.Seq.Base.seq FStar.UInt32.t -> FStar.Pervasives.Lemma (requires n == FStar.Seq.Base.length s) (ensures FStar.Seq.Base.equal (FStar.Krml.Endianness.seq_uint32_of_be n (FStar.Krml.Endianness.be_of_seq_uint32 s)) s) (decreases n) [SMTPat (FStar.Krml.Endianness.seq_uint32_of_be n (FStar.Krml.Endianness.be_of_seq_uint32 s))]
FStar.Pervasives.Lemma
[ "lemma", "" ]
[]
[ "Prims.nat", "FStar.Seq.Base.seq", "FStar.UInt32.t", "Prims.op_Equality", "Prims.int", "Prims.bool", "FStar.Seq.Properties.lemma_append_inj", "FStar.UInt8.t", "FStar.Seq.Base.slice", "FStar.Seq.Base.length", "FStar.Krml.Endianness.be_of_uint32", "FStar.Seq.Properties.head", "FStar.Krml.Endianness.be_of_seq_uint32", "FStar.Seq.Properties.tail", "Prims.unit", "FStar.Seq.Properties.lemma_split", "FStar.Krml.Endianness.bytes", "Prims.b2t", "Prims.op_Multiply", "FStar.Krml.Endianness.seq_uint32_of_be_be_of_seq_uint32", "Prims.op_Subtraction", "Prims._assert", "FStar.Seq.Base.equal", "FStar.Seq.Base.cons", "Prims.eq2", "Prims.squash", "FStar.Krml.Endianness.seq_uint32_of_be", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat", "Prims.Nil" ]
[ "recursion" ]
false
false
true
false
false
let rec seq_uint32_of_be_be_of_seq_uint32 (n: nat) (s: S.seq U32.t) : Lemma (requires (n == S.length s)) (ensures ((seq_uint32_of_be n (be_of_seq_uint32 s)) `S.equal` s)) (decreases n) [SMTPat (seq_uint32_of_be n (be_of_seq_uint32 s))] =
if n = 0 then () else (assert (s `S.equal` (S.cons (S.head s) (S.tail s))); seq_uint32_of_be_be_of_seq_uint32 (n - 1) (S.tail s); let s' = be_of_seq_uint32 s in S.lemma_split s' 4; S.lemma_append_inj (S.slice s' 0 4) (S.slice s' 4 (S.length s')) (be_of_uint32 (S.head s)) (be_of_seq_uint32 (S.tail s)))
false
FStar.Krml.Endianness.fst
FStar.Krml.Endianness.be_of_seq_uint32_slice
val be_of_seq_uint32_slice (s: S.seq U32.t) (lo hi: nat) : Lemma (requires (lo <= hi /\ hi <= S.length s)) (ensures ((be_of_seq_uint32 (S.slice s lo hi)) `S.equal` (S.slice (be_of_seq_uint32 s) (4 * lo) (4 * hi))))
val be_of_seq_uint32_slice (s: S.seq U32.t) (lo hi: nat) : Lemma (requires (lo <= hi /\ hi <= S.length s)) (ensures ((be_of_seq_uint32 (S.slice s lo hi)) `S.equal` (S.slice (be_of_seq_uint32 s) (4 * lo) (4 * hi))))
let be_of_seq_uint32_slice (s: S.seq U32.t) (lo: nat) (hi: nat) : Lemma (requires (lo <= hi /\ hi <= S.length s)) (ensures (be_of_seq_uint32 (S.slice s lo hi) `S.equal` S.slice (be_of_seq_uint32 s) (4 * lo) (4 * hi))) = slice_seq_uint32_of_be (S.length s) (be_of_seq_uint32 s) lo hi
{ "file_name": "krmllib/FStar.Krml.Endianness.fst", "git_rev": "da1e941b2fcb196aa5d1e34941aa00b4c67ac321", "git_url": "https://github.com/FStarLang/karamel.git", "project_name": "karamel" }
{ "end_col": 64, "end_line": 560, "start_col": 0, "start_line": 557 }
module FStar.Krml.Endianness open FStar.Mul open FStar.HyperStack.All module U8 = FStar.UInt8 module U32 = FStar.UInt32 module U64 = FStar.UInt64 module Math = FStar.Math.Lemmas module S = FStar.Seq (* Selectively imported from Hacl*'s FStar.Endianness.fst library, with several name changes *) inline_for_extraction noextract type bytes = S.seq U8.t /// lt_to_n interprets a byte sequence as a little-endian natural number [@(deprecated "FStar.Endianness.le_to_n")] val le_to_n : b:bytes -> Tot nat (decreases (S.length b)) let rec le_to_n b = if S.length b = 0 then 0 else U8.v (S.head b) + pow2 8 * le_to_n (S.tail b) /// be_to_n interprets a byte sequence as a big-endian natural number [@(deprecated "FStar.Endianness.be_to_n")] val be_to_n : b:bytes -> Tot nat (decreases (S.length b)) let rec be_to_n b = if S.length b = 0 then 0 else U8.v (S.last b) + pow2 8 * be_to_n (S.slice b 0 (S.length b - 1)) [@(deprecated "FStar.Endianness.lemma_euclidean_division")] private val lemma_euclidean_division: r:nat -> b:nat -> q:pos -> Lemma (requires (r < q)) (ensures (r + q * b < q * (b+1))) let lemma_euclidean_division r b q = () [@(deprecated "FStar.Endianness.lemma_factorise")] private val lemma_factorise: a:nat -> b:nat -> Lemma (a + a * b == a * (b + 1)) let lemma_factorise a b = () [@(deprecated "FStar.Endianness.lemma_le_to_n_is_bounded")] val lemma_le_to_n_is_bounded: b:bytes -> Lemma (requires True) (ensures (le_to_n b < pow2 (8 * Seq.length b))) (decreases (Seq.length b)) let rec lemma_le_to_n_is_bounded b = if Seq.length b = 0 then () else begin let s = Seq.slice b 1 (Seq.length b) in assert(Seq.length s = Seq.length b - 1); lemma_le_to_n_is_bounded s; assert(UInt8.v (Seq.index b 0) < pow2 8); assert(le_to_n s < pow2 (8 * Seq.length s)); assert(le_to_n b < pow2 8 + pow2 8 * pow2 (8 * (Seq.length b - 1))); lemma_euclidean_division (UInt8.v (Seq.index b 0)) (le_to_n s) (pow2 8); assert(le_to_n b <= pow2 8 * (le_to_n s + 1)); assert(le_to_n b <= pow2 8 * pow2 (8 * (Seq.length b - 1))); Math.Lemmas.pow2_plus 8 (8 * (Seq.length b - 1)); lemma_factorise 8 (Seq.length b - 1) end [@(deprecated "FStar.Endianness.lemma_be_to_n_is_bounded")] val lemma_be_to_n_is_bounded: b:bytes -> Lemma (requires True) (ensures (be_to_n b < pow2 (8 * Seq.length b))) (decreases (Seq.length b)) let rec lemma_be_to_n_is_bounded b = if Seq.length b = 0 then () else begin let s = Seq.slice b 0 (Seq.length b - 1) in assert(Seq.length s = Seq.length b - 1); lemma_be_to_n_is_bounded s; assert(UInt8.v (Seq.last b) < pow2 8); assert(be_to_n s < pow2 (8 * Seq.length s)); assert(be_to_n b < pow2 8 + pow2 8 * pow2 (8 * (Seq.length b - 1))); lemma_euclidean_division (UInt8.v (Seq.last b)) (be_to_n s) (pow2 8); assert(be_to_n b <= pow2 8 * (be_to_n s + 1)); assert(be_to_n b <= pow2 8 * pow2 (8 * (Seq.length b - 1))); Math.Lemmas.pow2_plus 8 (8 * (Seq.length b - 1)); lemma_factorise 8 (Seq.length b - 1) end /// n_to_le encodes a number as a little-endian byte sequence of a fixed, /// sufficiently large length [@(deprecated "FStar.Endianness.n_to_le")] val n_to_le : len:U32.t -> n:nat{n < pow2 (8 * U32.v len)} -> Tot (b:bytes{S.length b == U32.v len /\ n == le_to_n b}) (decreases (U32.v len)) let rec n_to_le len n = if len = 0ul then S.empty else let len = U32.(len -^ 1ul) in let byte = U8.uint_to_t (n % 256) in let n' = n / 256 in Math.pow2_plus 8 (8 * U32.v len); assert(n' < pow2 (8 * U32.v len )); let b' = n_to_le len n' in let b = S.cons byte b' in S.lemma_eq_intro b' (S.tail b); b /// n_to_be encodes a numbers as a big-endian byte sequence of a fixed, /// sufficiently large length [@(deprecated "FStar.Endianness.n_to_be")] val n_to_be: len:U32.t -> n:nat{n < pow2 (8 * U32.v len)} -> Tot (b:bytes{S.length b == U32.v len /\ n == be_to_n b}) (decreases (U32.v len)) let rec n_to_be len n = if len = 0ul then S.empty else let len = U32.(len -^ 1ul) in let byte = U8.uint_to_t (n % 256) in let n' = n / 256 in Math.pow2_plus 8 (8 * U32.v len); assert(n' < pow2 (8 * U32.v len )); let b' = n_to_be len n' in let b'' = S.create 1 byte in let b = S.append b' b'' in S.lemma_eq_intro b' (S.slice b 0 (U32.v len)); b [@(deprecated "FStar.Endianness.n_to_le_inj")] let n_to_le_inj (len:U32.t) (n1 n2: (n:nat{n < pow2 (8 * U32.v len)})) : Lemma (requires (n_to_le len n1 == n_to_le len n2)) (ensures (n1 == n2)) = // this lemma easily follows from le_to_n . (n_to_le len) == id, the inversion // proof in the spec for n_to_le () [@(deprecated "FStar.Endianness.n_to_be_inj")] let n_to_be_inj (len:U32.t) (n1 n2: (n:nat{n < pow2 (8 * U32.v len)})) : Lemma (requires (n_to_be len n1 == n_to_be len n2)) (ensures (n1 == n2)) = () [@(deprecated "FStar.Endianness.be_to_n_inj")] let rec be_to_n_inj (b1 b2: Seq.seq U8.t) : Lemma (requires (Seq.length b1 == Seq.length b2 /\ be_to_n b1 == be_to_n b2)) (ensures (Seq.equal b1 b2)) (decreases (Seq.length b1)) = if Seq.length b1 = 0 then () else begin be_to_n_inj (Seq.slice b1 0 (Seq.length b1 - 1)) (Seq.slice b2 0 (Seq.length b2 - 1)); Seq.lemma_split b1 (Seq.length b1 - 1); Seq.lemma_split b2 (Seq.length b2 - 1) end [@(deprecated "FStar.Endianness.le_to_n_inj")] let rec le_to_n_inj (b1 b2: Seq.seq U8.t) : Lemma (requires (Seq.length b1 == Seq.length b2 /\ le_to_n b1 == le_to_n b2)) (ensures (Seq.equal b1 b2)) (decreases (Seq.length b1)) = if Seq.length b1 = 0 then () else begin le_to_n_inj (Seq.slice b1 1 (Seq.length b1)) (Seq.slice b2 1 (Seq.length b2)); Seq.lemma_split b1 1; Seq.lemma_split b2 1 end [@(deprecated "FStar.Endianness.n_to_be_be_to_n")] let n_to_be_be_to_n (len: U32.t) (s: Seq.seq U8.t) : Lemma (requires (Seq.length s == U32.v len)) (ensures ( be_to_n s < pow2 (8 `Prims.op_Multiply` U32.v len) /\ n_to_be len (be_to_n s) == s )) [SMTPat (n_to_be len (be_to_n s))] = lemma_be_to_n_is_bounded s; be_to_n_inj s (n_to_be len (be_to_n s)) [@(deprecated "FStar.Endianness.n_to_le_le_to_n")] let n_to_le_le_to_n (len: U32.t) (s: Seq.seq U8.t) : Lemma (requires (Seq.length s == U32.v len)) (ensures ( le_to_n s < pow2 (8 `Prims.op_Multiply` U32.v len) /\ n_to_le len (le_to_n s) == s )) [SMTPat (n_to_le len (le_to_n s))] = lemma_le_to_n_is_bounded s; le_to_n_inj s (n_to_le len (le_to_n s)) (** A series of specializations to deal with machine integers *) [@(deprecated "FStar.Endianness.uint32_of_le")] let uint32_of_le (b: bytes { S.length b = 4 }) = let n = le_to_n b in lemma_le_to_n_is_bounded b; UInt32.uint_to_t n [@(deprecated "FStar.Endianness.le_of_uint32")] let le_of_uint32 (x: UInt32.t): b:bytes{ S.length b = 4 } = n_to_le 4ul (UInt32.v x) [@(deprecated "FStar.Endianness.uint32_of_be")] let uint32_of_be (b: bytes { S.length b = 4 }) = let n = be_to_n b in lemma_be_to_n_is_bounded b; UInt32.uint_to_t n [@(deprecated "FStar.Endianness.be_of_uint32")] let be_of_uint32 (x: UInt32.t): b:bytes{ S.length b = 4 } = n_to_be 4ul (UInt32.v x) [@(deprecated "FStar.Endianness.uint64_of_le")] let uint64_of_le (b: bytes { S.length b = 8 }) = let n = le_to_n b in lemma_le_to_n_is_bounded b; UInt64.uint_to_t n [@(deprecated "FStar.Endianness.le_of_uint64")] let le_of_uint64 (x: UInt64.t): b:bytes{ S.length b = 8 } = n_to_le 8ul (UInt64.v x) [@(deprecated "FStar.Endianness.uint64_of_be")] let uint64_of_be (b: bytes { S.length b = 8 }) = let n = be_to_n b in lemma_be_to_n_is_bounded b; UInt64.uint_to_t n [@(deprecated "FStar.Endianness.be_of_uint64")] let be_of_uint64 (x: UInt64.t): b:bytes{ S.length b = 8 } = n_to_be 8ul (UInt64.v x) [@(deprecated "FStar.Endianness.seq_uint32_of_le")] let rec seq_uint32_of_le (l: nat) (b: bytes{ S.length b = 4 * l }): s:S.seq UInt32.t { S.length s = l } = if S.length b = 0 then S.empty else let hd, tl = Seq.split b 4 in S.cons (uint32_of_le hd) (seq_uint32_of_le (l - 1) tl) [@(deprecated "FStar.Endianness.le_of_seq_uint32")] let rec le_of_seq_uint32 (s: S.seq UInt32.t): Tot (b:bytes { S.length b = 4 * S.length s }) (decreases (S.length s)) = if S.length s = 0 then S.empty else S.append (le_of_uint32 (S.head s)) (le_of_seq_uint32 (S.tail s)) [@(deprecated "FStar.Endianness.seq_uint32_of_be")] let rec seq_uint32_of_be (l: nat) (b: bytes{ S.length b = 4 * l }): s:S.seq UInt32.t { S.length s = l } = if S.length b = 0 then S.empty else let hd, tl = Seq.split b 4 in S.cons (uint32_of_be hd) (seq_uint32_of_be (l - 1) tl) [@(deprecated "FStar.Endianness.be_of_seq_uint32")] let rec be_of_seq_uint32 (s: S.seq UInt32.t): Tot (b:bytes { S.length b = 4 * S.length s }) (decreases (S.length s)) = if S.length s = 0 then S.empty else S.append (be_of_uint32 (S.head s)) (be_of_seq_uint32 (S.tail s)) [@(deprecated "FStar.Endianness.seq_uint64_of_le")] let rec seq_uint64_of_le (l: nat) (b: bytes{ S.length b = 8 * l }): s:S.seq UInt64.t { S.length s = l } = if S.length b = 0 then S.empty else let hd, tl = Seq.split b 8 in S.cons (uint64_of_le hd) (seq_uint64_of_le (l - 1) tl) [@(deprecated "FStar.Endianness.le_of_seq_uint64")] let rec le_of_seq_uint64 (s: S.seq UInt64.t): Tot (b:bytes { S.length b = 8 * S.length s }) (decreases (S.length s)) = if S.length s = 0 then S.empty else S.append (le_of_uint64 (S.head s)) (le_of_seq_uint64 (S.tail s)) [@(deprecated "FStar.Endianness.seq_uint64_of_be")] let rec seq_uint64_of_be (l: nat) (b: bytes{ S.length b = 8 * l }): s:S.seq UInt64.t { S.length s = l } = if S.length b = 0 then S.empty else let hd, tl = Seq.split b 8 in S.cons (uint64_of_be hd) (seq_uint64_of_be (l - 1) tl) [@(deprecated "FStar.Endianness.be_of_seq_uint64")] let rec be_of_seq_uint64 (s: S.seq UInt64.t): Tot (b:bytes { S.length b = 8 * S.length s }) (decreases (S.length s)) = if S.length s = 0 then S.empty else S.append (be_of_uint64 (S.head s)) (be_of_seq_uint64 (S.tail s)) #set-options "--max_fuel 1 --max_ifuel 0 --z3rlimit 50" [@(deprecated "FStar.Endianness.offset_uint32_be")] let rec offset_uint32_be (b: bytes) (n: nat) (i: nat): Lemma (requires ( S.length b = 4 * n /\ i < n)) (ensures ( S.index (seq_uint32_of_be n b) i == uint32_of_be (S.slice b (4 * i) (4 * i + 4)))) (decreases ( S.length b)) [ SMTPat (S.index (seq_uint32_of_be n b) i) ] = if S.length b = 0 then false_elim () else let hd, tl = Seq.split b 4 in if i = 0 then () else offset_uint32_be tl (n - 1) (i - 1) [@(deprecated "FStar.Endianness.offset_uint32_le")] let rec offset_uint32_le (b: bytes) (n: nat) (i: nat): Lemma (requires ( S.length b = 4 * n /\ i < n)) (ensures ( S.index (seq_uint32_of_le n b) i == uint32_of_le (S.slice b (4 * i) (4 * i + 4)))) (decreases ( S.length b)) [ SMTPat (S.index (seq_uint32_of_le n b) i) ] = if S.length b = 0 then false_elim () else let hd, tl = Seq.split b 4 in if i = 0 then () else offset_uint32_le tl (n - 1) (i - 1) [@(deprecated "FStar.Endianness.offset_uint64_be")] let rec offset_uint64_be (b: bytes) (n: nat) (i: nat): Lemma (requires ( S.length b = 8 * n /\ i < n)) (ensures ( S.index (seq_uint64_of_be n b) i == uint64_of_be (S.slice b (8 * i) (8 * i + 8)))) (decreases ( S.length b)) [ SMTPat (S.index (seq_uint64_of_be n b) i) ] = if S.length b = 0 then false_elim () else let hd, tl = Seq.split b 8 in if i = 0 then () else offset_uint64_be tl (n - 1) (i - 1) [@(deprecated "FStar.Endianness.offset_uint64_le")] let rec offset_uint64_le (b: bytes) (n: nat) (i: nat): Lemma (requires ( S.length b = 8 * n /\ i < n)) (ensures ( S.index (seq_uint64_of_le n b) i == uint64_of_le (S.slice b (8 * i) (8 * i + 8)))) (decreases ( S.length b)) [ SMTPat (S.index (seq_uint64_of_le n b) i) ] = if S.length b = 0 then false_elim () else let hd, tl = Seq.split b 8 in if i = 0 then () else offset_uint64_le tl (n - 1) (i - 1) (** Reasoning about endian-ness and words. *) #set-options "--max_fuel 1 --z3rlimit 20" (* TODO: move to FStar.Seq.Properties, with the pattern *) [@(deprecated "FStar.Endianness.tail_cons")] let tail_cons (#a: Type) (hd: a) (tl: S.seq a): Lemma (ensures (S.equal (S.tail (S.cons hd tl)) tl)) // [ SMTPat (S.tail (S.cons hd tl)) ] = () [@(deprecated "FStar.Endianness.be_of_seq_uint32_append")] let rec be_of_seq_uint32_append (s1 s2: S.seq U32.t): Lemma (ensures ( S.equal (be_of_seq_uint32 (S.append s1 s2)) (S.append (be_of_seq_uint32 s1) (be_of_seq_uint32 s2)))) (decreases ( S.length s1)) [ SMTPat (S.append (be_of_seq_uint32 s1) (be_of_seq_uint32 s2)) ] = Classical.forall_intro_2 (tail_cons #U32.t); // TODO: this is a local pattern, remove once tail_cons lands in FStar.Seq.Properties if S.length s1 = 0 then begin assert (S.equal (be_of_seq_uint32 s1) S.empty); assert (S.equal (S.append s1 s2) s2); () end else begin assert (S.equal (S.append s1 s2) (S.cons (S.head s1) (S.append (S.tail s1) s2))); assert (S.equal (be_of_seq_uint32 (S.append s1 s2)) (S.append (be_of_uint32 (S.head s1)) (be_of_seq_uint32 (S.append (S.tail s1) s2)))); be_of_seq_uint32_append (S.tail s1) s2 end [@(deprecated "FStar.Endianness.be_of_seq_uint32_base")] let be_of_seq_uint32_base (s1: S.seq U32.t) (s2: S.seq U8.t): Lemma (requires ( S.length s1 = 1 /\ S.length s2 = 4 /\ be_to_n s2 = U32.v (S.index s1 0))) (ensures (S.equal s2 (be_of_seq_uint32 s1))) [ SMTPat (be_to_n s2 = U32.v (S.index s1 0)) ] = () [@(deprecated "FStar.Endianness.le_of_seq_uint32_append")] let rec le_of_seq_uint32_append (s1 s2: S.seq U32.t): Lemma (ensures ( S.equal (le_of_seq_uint32 (S.append s1 s2)) (S.append (le_of_seq_uint32 s1) (le_of_seq_uint32 s2)))) (decreases ( S.length s1)) [ SMTPat (S.append (le_of_seq_uint32 s1) (le_of_seq_uint32 s2)) ] = Classical.forall_intro_2 (tail_cons #U32.t); // TODO: this is a local pattern, remove once tail_cons lands in FStar.Seq.Properties if S.length s1 = 0 then begin assert (S.equal (le_of_seq_uint32 s1) S.empty); assert (S.equal (S.append s1 s2) s2); () end else begin assert (S.equal (S.append s1 s2) (S.cons (S.head s1) (S.append (S.tail s1) s2))); assert (S.equal (le_of_seq_uint32 (S.append s1 s2)) (S.append (le_of_uint32 (S.head s1)) (le_of_seq_uint32 (S.append (S.tail s1) s2)))); le_of_seq_uint32_append (S.tail s1) s2 end [@(deprecated "FStar.Endianness.le_of_seq_uint32_base")] let le_of_seq_uint32_base (s1: S.seq U32.t) (s2: S.seq U8.t): Lemma (requires ( S.length s1 = 1 /\ S.length s2 = 4 /\ le_to_n s2 = U32.v (S.index s1 0))) (ensures (S.equal s2 (le_of_seq_uint32 s1))) [ SMTPat (le_to_n s2 = U32.v (S.index s1 0)) ] = () [@(deprecated "FStar.Endianness.be_of_seq_uint64_append")] let rec be_of_seq_uint64_append (s1 s2: S.seq U64.t): Lemma (ensures ( S.equal (be_of_seq_uint64 (S.append s1 s2)) (S.append (be_of_seq_uint64 s1) (be_of_seq_uint64 s2)))) (decreases ( S.length s1)) [ SMTPat (S.append (be_of_seq_uint64 s1) (be_of_seq_uint64 s2)) ] = Classical.forall_intro_2 (tail_cons #U64.t); // TODO: this is a local pattern, remove once tail_cons lands in FStar.Seq.Properties if S.length s1 = 0 then begin assert (S.equal (be_of_seq_uint64 s1) S.empty); assert (S.equal (S.append s1 s2) s2); () end else begin assert (S.equal (S.append s1 s2) (S.cons (S.head s1) (S.append (S.tail s1) s2))); assert (S.equal (be_of_seq_uint64 (S.append s1 s2)) (S.append (be_of_uint64 (S.head s1)) (be_of_seq_uint64 (S.append (S.tail s1) s2)))); be_of_seq_uint64_append (S.tail s1) s2 end [@(deprecated "FStar.Endianness.be_of_seq_uint64_base")] let be_of_seq_uint64_base (s1: S.seq U64.t) (s2: S.seq U8.t): Lemma (requires ( S.length s1 = 1 /\ S.length s2 = 8 /\ be_to_n s2 = U64.v (S.index s1 0))) (ensures (S.equal s2 (be_of_seq_uint64 s1))) [ SMTPat (be_to_n s2 = U64.v (S.index s1 0)) ] = () [@(deprecated "FStar.Endianness.seq_uint32_of_be_be_of_seq_uint32")] let rec seq_uint32_of_be_be_of_seq_uint32 (n: nat) (s: S.seq U32.t) : Lemma (requires (n == S.length s)) (ensures (seq_uint32_of_be n (be_of_seq_uint32 s) `S.equal` s)) (decreases n) [SMTPat (seq_uint32_of_be n (be_of_seq_uint32 s))] = if n = 0 then () else begin assert (s `S.equal` S.cons (S.head s) (S.tail s)); seq_uint32_of_be_be_of_seq_uint32 (n - 1) (S.tail s); let s' = be_of_seq_uint32 s in S.lemma_split s' 4; S.lemma_append_inj (S.slice s' 0 4) (S.slice s' 4 (S.length s')) (be_of_uint32 (S.head s)) (be_of_seq_uint32 (S.tail s)) end [@(deprecated "FStar.Endianness.be_of_seq_uint32_seq_uint32_of_be")] let rec be_of_seq_uint32_seq_uint32_of_be (n: nat) (s: S.seq U8.t) : Lemma (requires (4 * n == S.length s)) (ensures (be_of_seq_uint32 (seq_uint32_of_be n s) `S.equal` s)) (decreases n) [SMTPat (be_of_seq_uint32 (seq_uint32_of_be n s))] = if n = 0 then () else begin S.lemma_split s 4; be_of_seq_uint32_seq_uint32_of_be (n - 1) (S.slice s 4 (S.length s)); let s' = seq_uint32_of_be n s in let hd, tl = S.split s 4 in assert (S.head s' == uint32_of_be hd); tail_cons (uint32_of_be hd) (seq_uint32_of_be (n - 1) tl); assert (S.tail s' == seq_uint32_of_be (n - 1) tl); let s'' = be_of_seq_uint32 s' in S.lemma_split s'' 4; S.lemma_append_inj (S.slice s'' 0 4) (S.slice s'' 4 (S.length s'')) (be_of_uint32 (S.head s')) (be_of_seq_uint32 (S.tail s')); n_to_be_be_to_n 4ul hd end [@(deprecated "FStar.Endianness.slice_seq_uint32_of_be")] let slice_seq_uint32_of_be (n: nat) (s: S.seq U8.t) (lo: nat) (hi: nat) : Lemma (requires (4 * n == S.length s /\ lo <= hi /\ hi <= n)) (ensures (S.slice (seq_uint32_of_be n s) lo hi) `S.equal` seq_uint32_of_be (hi - lo) (S.slice s (4 * lo) (4 * hi))) = ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.All.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "FStar.Krml.Endianness.fst" }
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Math.Lemmas", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Krml", "short_module": null }, { "abbrev": false, "full_module": "FStar.Krml", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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": 1, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s: FStar.Seq.Base.seq FStar.UInt32.t -> lo: Prims.nat -> hi: Prims.nat -> FStar.Pervasives.Lemma (requires lo <= hi /\ hi <= FStar.Seq.Base.length s) (ensures FStar.Seq.Base.equal (FStar.Krml.Endianness.be_of_seq_uint32 (FStar.Seq.Base.slice s lo hi)) (FStar.Seq.Base.slice (FStar.Krml.Endianness.be_of_seq_uint32 s) (4 * lo) (4 * hi)))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "FStar.Seq.Base.seq", "FStar.UInt32.t", "Prims.nat", "FStar.Krml.Endianness.slice_seq_uint32_of_be", "FStar.Seq.Base.length", "FStar.Krml.Endianness.be_of_seq_uint32", "Prims.unit", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.squash", "FStar.Seq.Base.equal", "FStar.UInt8.t", "FStar.Seq.Base.slice", "FStar.Mul.op_Star", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
true
false
true
false
false
let be_of_seq_uint32_slice (s: S.seq U32.t) (lo hi: nat) : Lemma (requires (lo <= hi /\ hi <= S.length s)) (ensures ((be_of_seq_uint32 (S.slice s lo hi)) `S.equal` (S.slice (be_of_seq_uint32 s) (4 * lo) (4 * hi)))) =
slice_seq_uint32_of_be (S.length s) (be_of_seq_uint32 s) lo hi
false
FStar.Krml.Endianness.fst
FStar.Krml.Endianness.offset_uint64_le
val offset_uint64_le (b: bytes) (n i: nat) : Lemma (requires (S.length b = 8 * n /\ i < n)) (ensures (S.index (seq_uint64_of_le n b) i == uint64_of_le (S.slice b (8 * i) (8 * i + 8)))) (decreases (S.length b)) [SMTPat (S.index (seq_uint64_of_le n b) i)]
val offset_uint64_le (b: bytes) (n i: nat) : Lemma (requires (S.length b = 8 * n /\ i < n)) (ensures (S.index (seq_uint64_of_le n b) i == uint64_of_le (S.slice b (8 * i) (8 * i + 8)))) (decreases (S.length b)) [SMTPat (S.index (seq_uint64_of_le n b) i)]
let rec offset_uint64_le (b: bytes) (n: nat) (i: nat): Lemma (requires ( S.length b = 8 * n /\ i < n)) (ensures ( S.index (seq_uint64_of_le n b) i == uint64_of_le (S.slice b (8 * i) (8 * i + 8)))) (decreases ( S.length b)) [ SMTPat (S.index (seq_uint64_of_le n b) i) ] = if S.length b = 0 then false_elim () else let hd, tl = Seq.split b 8 in if i = 0 then () else offset_uint64_le tl (n - 1) (i - 1)
{ "file_name": "krmllib/FStar.Krml.Endianness.fst", "git_rev": "da1e941b2fcb196aa5d1e34941aa00b4c67ac321", "git_url": "https://github.com/FStarLang/karamel.git", "project_name": "karamel" }
{ "end_col": 41, "end_line": 401, "start_col": 0, "start_line": 383 }
module FStar.Krml.Endianness open FStar.Mul open FStar.HyperStack.All module U8 = FStar.UInt8 module U32 = FStar.UInt32 module U64 = FStar.UInt64 module Math = FStar.Math.Lemmas module S = FStar.Seq (* Selectively imported from Hacl*'s FStar.Endianness.fst library, with several name changes *) inline_for_extraction noextract type bytes = S.seq U8.t /// lt_to_n interprets a byte sequence as a little-endian natural number [@(deprecated "FStar.Endianness.le_to_n")] val le_to_n : b:bytes -> Tot nat (decreases (S.length b)) let rec le_to_n b = if S.length b = 0 then 0 else U8.v (S.head b) + pow2 8 * le_to_n (S.tail b) /// be_to_n interprets a byte sequence as a big-endian natural number [@(deprecated "FStar.Endianness.be_to_n")] val be_to_n : b:bytes -> Tot nat (decreases (S.length b)) let rec be_to_n b = if S.length b = 0 then 0 else U8.v (S.last b) + pow2 8 * be_to_n (S.slice b 0 (S.length b - 1)) [@(deprecated "FStar.Endianness.lemma_euclidean_division")] private val lemma_euclidean_division: r:nat -> b:nat -> q:pos -> Lemma (requires (r < q)) (ensures (r + q * b < q * (b+1))) let lemma_euclidean_division r b q = () [@(deprecated "FStar.Endianness.lemma_factorise")] private val lemma_factorise: a:nat -> b:nat -> Lemma (a + a * b == a * (b + 1)) let lemma_factorise a b = () [@(deprecated "FStar.Endianness.lemma_le_to_n_is_bounded")] val lemma_le_to_n_is_bounded: b:bytes -> Lemma (requires True) (ensures (le_to_n b < pow2 (8 * Seq.length b))) (decreases (Seq.length b)) let rec lemma_le_to_n_is_bounded b = if Seq.length b = 0 then () else begin let s = Seq.slice b 1 (Seq.length b) in assert(Seq.length s = Seq.length b - 1); lemma_le_to_n_is_bounded s; assert(UInt8.v (Seq.index b 0) < pow2 8); assert(le_to_n s < pow2 (8 * Seq.length s)); assert(le_to_n b < pow2 8 + pow2 8 * pow2 (8 * (Seq.length b - 1))); lemma_euclidean_division (UInt8.v (Seq.index b 0)) (le_to_n s) (pow2 8); assert(le_to_n b <= pow2 8 * (le_to_n s + 1)); assert(le_to_n b <= pow2 8 * pow2 (8 * (Seq.length b - 1))); Math.Lemmas.pow2_plus 8 (8 * (Seq.length b - 1)); lemma_factorise 8 (Seq.length b - 1) end [@(deprecated "FStar.Endianness.lemma_be_to_n_is_bounded")] val lemma_be_to_n_is_bounded: b:bytes -> Lemma (requires True) (ensures (be_to_n b < pow2 (8 * Seq.length b))) (decreases (Seq.length b)) let rec lemma_be_to_n_is_bounded b = if Seq.length b = 0 then () else begin let s = Seq.slice b 0 (Seq.length b - 1) in assert(Seq.length s = Seq.length b - 1); lemma_be_to_n_is_bounded s; assert(UInt8.v (Seq.last b) < pow2 8); assert(be_to_n s < pow2 (8 * Seq.length s)); assert(be_to_n b < pow2 8 + pow2 8 * pow2 (8 * (Seq.length b - 1))); lemma_euclidean_division (UInt8.v (Seq.last b)) (be_to_n s) (pow2 8); assert(be_to_n b <= pow2 8 * (be_to_n s + 1)); assert(be_to_n b <= pow2 8 * pow2 (8 * (Seq.length b - 1))); Math.Lemmas.pow2_plus 8 (8 * (Seq.length b - 1)); lemma_factorise 8 (Seq.length b - 1) end /// n_to_le encodes a number as a little-endian byte sequence of a fixed, /// sufficiently large length [@(deprecated "FStar.Endianness.n_to_le")] val n_to_le : len:U32.t -> n:nat{n < pow2 (8 * U32.v len)} -> Tot (b:bytes{S.length b == U32.v len /\ n == le_to_n b}) (decreases (U32.v len)) let rec n_to_le len n = if len = 0ul then S.empty else let len = U32.(len -^ 1ul) in let byte = U8.uint_to_t (n % 256) in let n' = n / 256 in Math.pow2_plus 8 (8 * U32.v len); assert(n' < pow2 (8 * U32.v len )); let b' = n_to_le len n' in let b = S.cons byte b' in S.lemma_eq_intro b' (S.tail b); b /// n_to_be encodes a numbers as a big-endian byte sequence of a fixed, /// sufficiently large length [@(deprecated "FStar.Endianness.n_to_be")] val n_to_be: len:U32.t -> n:nat{n < pow2 (8 * U32.v len)} -> Tot (b:bytes{S.length b == U32.v len /\ n == be_to_n b}) (decreases (U32.v len)) let rec n_to_be len n = if len = 0ul then S.empty else let len = U32.(len -^ 1ul) in let byte = U8.uint_to_t (n % 256) in let n' = n / 256 in Math.pow2_plus 8 (8 * U32.v len); assert(n' < pow2 (8 * U32.v len )); let b' = n_to_be len n' in let b'' = S.create 1 byte in let b = S.append b' b'' in S.lemma_eq_intro b' (S.slice b 0 (U32.v len)); b [@(deprecated "FStar.Endianness.n_to_le_inj")] let n_to_le_inj (len:U32.t) (n1 n2: (n:nat{n < pow2 (8 * U32.v len)})) : Lemma (requires (n_to_le len n1 == n_to_le len n2)) (ensures (n1 == n2)) = // this lemma easily follows from le_to_n . (n_to_le len) == id, the inversion // proof in the spec for n_to_le () [@(deprecated "FStar.Endianness.n_to_be_inj")] let n_to_be_inj (len:U32.t) (n1 n2: (n:nat{n < pow2 (8 * U32.v len)})) : Lemma (requires (n_to_be len n1 == n_to_be len n2)) (ensures (n1 == n2)) = () [@(deprecated "FStar.Endianness.be_to_n_inj")] let rec be_to_n_inj (b1 b2: Seq.seq U8.t) : Lemma (requires (Seq.length b1 == Seq.length b2 /\ be_to_n b1 == be_to_n b2)) (ensures (Seq.equal b1 b2)) (decreases (Seq.length b1)) = if Seq.length b1 = 0 then () else begin be_to_n_inj (Seq.slice b1 0 (Seq.length b1 - 1)) (Seq.slice b2 0 (Seq.length b2 - 1)); Seq.lemma_split b1 (Seq.length b1 - 1); Seq.lemma_split b2 (Seq.length b2 - 1) end [@(deprecated "FStar.Endianness.le_to_n_inj")] let rec le_to_n_inj (b1 b2: Seq.seq U8.t) : Lemma (requires (Seq.length b1 == Seq.length b2 /\ le_to_n b1 == le_to_n b2)) (ensures (Seq.equal b1 b2)) (decreases (Seq.length b1)) = if Seq.length b1 = 0 then () else begin le_to_n_inj (Seq.slice b1 1 (Seq.length b1)) (Seq.slice b2 1 (Seq.length b2)); Seq.lemma_split b1 1; Seq.lemma_split b2 1 end [@(deprecated "FStar.Endianness.n_to_be_be_to_n")] let n_to_be_be_to_n (len: U32.t) (s: Seq.seq U8.t) : Lemma (requires (Seq.length s == U32.v len)) (ensures ( be_to_n s < pow2 (8 `Prims.op_Multiply` U32.v len) /\ n_to_be len (be_to_n s) == s )) [SMTPat (n_to_be len (be_to_n s))] = lemma_be_to_n_is_bounded s; be_to_n_inj s (n_to_be len (be_to_n s)) [@(deprecated "FStar.Endianness.n_to_le_le_to_n")] let n_to_le_le_to_n (len: U32.t) (s: Seq.seq U8.t) : Lemma (requires (Seq.length s == U32.v len)) (ensures ( le_to_n s < pow2 (8 `Prims.op_Multiply` U32.v len) /\ n_to_le len (le_to_n s) == s )) [SMTPat (n_to_le len (le_to_n s))] = lemma_le_to_n_is_bounded s; le_to_n_inj s (n_to_le len (le_to_n s)) (** A series of specializations to deal with machine integers *) [@(deprecated "FStar.Endianness.uint32_of_le")] let uint32_of_le (b: bytes { S.length b = 4 }) = let n = le_to_n b in lemma_le_to_n_is_bounded b; UInt32.uint_to_t n [@(deprecated "FStar.Endianness.le_of_uint32")] let le_of_uint32 (x: UInt32.t): b:bytes{ S.length b = 4 } = n_to_le 4ul (UInt32.v x) [@(deprecated "FStar.Endianness.uint32_of_be")] let uint32_of_be (b: bytes { S.length b = 4 }) = let n = be_to_n b in lemma_be_to_n_is_bounded b; UInt32.uint_to_t n [@(deprecated "FStar.Endianness.be_of_uint32")] let be_of_uint32 (x: UInt32.t): b:bytes{ S.length b = 4 } = n_to_be 4ul (UInt32.v x) [@(deprecated "FStar.Endianness.uint64_of_le")] let uint64_of_le (b: bytes { S.length b = 8 }) = let n = le_to_n b in lemma_le_to_n_is_bounded b; UInt64.uint_to_t n [@(deprecated "FStar.Endianness.le_of_uint64")] let le_of_uint64 (x: UInt64.t): b:bytes{ S.length b = 8 } = n_to_le 8ul (UInt64.v x) [@(deprecated "FStar.Endianness.uint64_of_be")] let uint64_of_be (b: bytes { S.length b = 8 }) = let n = be_to_n b in lemma_be_to_n_is_bounded b; UInt64.uint_to_t n [@(deprecated "FStar.Endianness.be_of_uint64")] let be_of_uint64 (x: UInt64.t): b:bytes{ S.length b = 8 } = n_to_be 8ul (UInt64.v x) [@(deprecated "FStar.Endianness.seq_uint32_of_le")] let rec seq_uint32_of_le (l: nat) (b: bytes{ S.length b = 4 * l }): s:S.seq UInt32.t { S.length s = l } = if S.length b = 0 then S.empty else let hd, tl = Seq.split b 4 in S.cons (uint32_of_le hd) (seq_uint32_of_le (l - 1) tl) [@(deprecated "FStar.Endianness.le_of_seq_uint32")] let rec le_of_seq_uint32 (s: S.seq UInt32.t): Tot (b:bytes { S.length b = 4 * S.length s }) (decreases (S.length s)) = if S.length s = 0 then S.empty else S.append (le_of_uint32 (S.head s)) (le_of_seq_uint32 (S.tail s)) [@(deprecated "FStar.Endianness.seq_uint32_of_be")] let rec seq_uint32_of_be (l: nat) (b: bytes{ S.length b = 4 * l }): s:S.seq UInt32.t { S.length s = l } = if S.length b = 0 then S.empty else let hd, tl = Seq.split b 4 in S.cons (uint32_of_be hd) (seq_uint32_of_be (l - 1) tl) [@(deprecated "FStar.Endianness.be_of_seq_uint32")] let rec be_of_seq_uint32 (s: S.seq UInt32.t): Tot (b:bytes { S.length b = 4 * S.length s }) (decreases (S.length s)) = if S.length s = 0 then S.empty else S.append (be_of_uint32 (S.head s)) (be_of_seq_uint32 (S.tail s)) [@(deprecated "FStar.Endianness.seq_uint64_of_le")] let rec seq_uint64_of_le (l: nat) (b: bytes{ S.length b = 8 * l }): s:S.seq UInt64.t { S.length s = l } = if S.length b = 0 then S.empty else let hd, tl = Seq.split b 8 in S.cons (uint64_of_le hd) (seq_uint64_of_le (l - 1) tl) [@(deprecated "FStar.Endianness.le_of_seq_uint64")] let rec le_of_seq_uint64 (s: S.seq UInt64.t): Tot (b:bytes { S.length b = 8 * S.length s }) (decreases (S.length s)) = if S.length s = 0 then S.empty else S.append (le_of_uint64 (S.head s)) (le_of_seq_uint64 (S.tail s)) [@(deprecated "FStar.Endianness.seq_uint64_of_be")] let rec seq_uint64_of_be (l: nat) (b: bytes{ S.length b = 8 * l }): s:S.seq UInt64.t { S.length s = l } = if S.length b = 0 then S.empty else let hd, tl = Seq.split b 8 in S.cons (uint64_of_be hd) (seq_uint64_of_be (l - 1) tl) [@(deprecated "FStar.Endianness.be_of_seq_uint64")] let rec be_of_seq_uint64 (s: S.seq UInt64.t): Tot (b:bytes { S.length b = 8 * S.length s }) (decreases (S.length s)) = if S.length s = 0 then S.empty else S.append (be_of_uint64 (S.head s)) (be_of_seq_uint64 (S.tail s)) #set-options "--max_fuel 1 --max_ifuel 0 --z3rlimit 50" [@(deprecated "FStar.Endianness.offset_uint32_be")] let rec offset_uint32_be (b: bytes) (n: nat) (i: nat): Lemma (requires ( S.length b = 4 * n /\ i < n)) (ensures ( S.index (seq_uint32_of_be n b) i == uint32_of_be (S.slice b (4 * i) (4 * i + 4)))) (decreases ( S.length b)) [ SMTPat (S.index (seq_uint32_of_be n b) i) ] = if S.length b = 0 then false_elim () else let hd, tl = Seq.split b 4 in if i = 0 then () else offset_uint32_be tl (n - 1) (i - 1) [@(deprecated "FStar.Endianness.offset_uint32_le")] let rec offset_uint32_le (b: bytes) (n: nat) (i: nat): Lemma (requires ( S.length b = 4 * n /\ i < n)) (ensures ( S.index (seq_uint32_of_le n b) i == uint32_of_le (S.slice b (4 * i) (4 * i + 4)))) (decreases ( S.length b)) [ SMTPat (S.index (seq_uint32_of_le n b) i) ] = if S.length b = 0 then false_elim () else let hd, tl = Seq.split b 4 in if i = 0 then () else offset_uint32_le tl (n - 1) (i - 1) [@(deprecated "FStar.Endianness.offset_uint64_be")] let rec offset_uint64_be (b: bytes) (n: nat) (i: nat): Lemma (requires ( S.length b = 8 * n /\ i < n)) (ensures ( S.index (seq_uint64_of_be n b) i == uint64_of_be (S.slice b (8 * i) (8 * i + 8)))) (decreases ( S.length b)) [ SMTPat (S.index (seq_uint64_of_be n b) i) ] = if S.length b = 0 then false_elim () else let hd, tl = Seq.split b 8 in if i = 0 then () else offset_uint64_be tl (n - 1) (i - 1)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.All.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "FStar.Krml.Endianness.fst" }
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Math.Lemmas", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Krml", "short_module": null }, { "abbrev": false, "full_module": "FStar.Krml", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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": 1, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b: FStar.Krml.Endianness.bytes -> n: Prims.nat -> i: Prims.nat -> FStar.Pervasives.Lemma (requires FStar.Seq.Base.length b = 8 * n /\ i < n) (ensures FStar.Seq.Base.index (FStar.Krml.Endianness.seq_uint64_of_le n b) i == FStar.Krml.Endianness.uint64_of_le (FStar.Seq.Base.slice b (8 * i) (8 * i + 8))) (decreases FStar.Seq.Base.length b) [SMTPat (FStar.Seq.Base.index (FStar.Krml.Endianness.seq_uint64_of_le n b) i)]
FStar.Pervasives.Lemma
[ "lemma", "" ]
[]
[ "FStar.Krml.Endianness.bytes", "Prims.nat", "Prims.op_Equality", "Prims.int", "FStar.Seq.Base.length", "FStar.UInt8.t", "FStar.Pervasives.false_elim", "Prims.unit", "Prims.bool", "FStar.Seq.Base.seq", "FStar.Krml.Endianness.offset_uint64_le", "Prims.op_Subtraction", "FStar.Pervasives.Native.tuple2", "FStar.Seq.Properties.split", "Prims.l_and", "Prims.b2t", "FStar.Mul.op_Star", "Prims.op_LessThan", "Prims.squash", "Prims.eq2", "FStar.UInt64.t", "FStar.Seq.Base.index", "FStar.Krml.Endianness.seq_uint64_of_le", "FStar.Krml.Endianness.uint64_of_le", "FStar.Seq.Base.slice", "Prims.op_Addition", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat", "Prims.Nil" ]
[ "recursion" ]
false
false
true
false
false
let rec offset_uint64_le (b: bytes) (n i: nat) : Lemma (requires (S.length b = 8 * n /\ i < n)) (ensures (S.index (seq_uint64_of_le n b) i == uint64_of_le (S.slice b (8 * i) (8 * i + 8)))) (decreases (S.length b)) [SMTPat (S.index (seq_uint64_of_le n b) i)] =
if S.length b = 0 then false_elim () else let hd, tl = Seq.split b 8 in if i = 0 then () else offset_uint64_le tl (n - 1) (i - 1)
false
FStar.Krml.Endianness.fst
FStar.Krml.Endianness.offset_uint32_le
val offset_uint32_le (b: bytes) (n i: nat) : Lemma (requires (S.length b = 4 * n /\ i < n)) (ensures (S.index (seq_uint32_of_le n b) i == uint32_of_le (S.slice b (4 * i) (4 * i + 4)))) (decreases (S.length b)) [SMTPat (S.index (seq_uint32_of_le n b) i)]
val offset_uint32_le (b: bytes) (n i: nat) : Lemma (requires (S.length b = 4 * n /\ i < n)) (ensures (S.index (seq_uint32_of_le n b) i == uint32_of_le (S.slice b (4 * i) (4 * i + 4)))) (decreases (S.length b)) [SMTPat (S.index (seq_uint32_of_le n b) i)]
let rec offset_uint32_le (b: bytes) (n: nat) (i: nat): Lemma (requires ( S.length b = 4 * n /\ i < n)) (ensures ( S.index (seq_uint32_of_le n b) i == uint32_of_le (S.slice b (4 * i) (4 * i + 4)))) (decreases ( S.length b)) [ SMTPat (S.index (seq_uint32_of_le n b) i) ] = if S.length b = 0 then false_elim () else let hd, tl = Seq.split b 4 in if i = 0 then () else offset_uint32_le tl (n - 1) (i - 1)
{ "file_name": "krmllib/FStar.Krml.Endianness.fst", "git_rev": "da1e941b2fcb196aa5d1e34941aa00b4c67ac321", "git_url": "https://github.com/FStarLang/karamel.git", "project_name": "karamel" }
{ "end_col": 41, "end_line": 359, "start_col": 0, "start_line": 341 }
module FStar.Krml.Endianness open FStar.Mul open FStar.HyperStack.All module U8 = FStar.UInt8 module U32 = FStar.UInt32 module U64 = FStar.UInt64 module Math = FStar.Math.Lemmas module S = FStar.Seq (* Selectively imported from Hacl*'s FStar.Endianness.fst library, with several name changes *) inline_for_extraction noextract type bytes = S.seq U8.t /// lt_to_n interprets a byte sequence as a little-endian natural number [@(deprecated "FStar.Endianness.le_to_n")] val le_to_n : b:bytes -> Tot nat (decreases (S.length b)) let rec le_to_n b = if S.length b = 0 then 0 else U8.v (S.head b) + pow2 8 * le_to_n (S.tail b) /// be_to_n interprets a byte sequence as a big-endian natural number [@(deprecated "FStar.Endianness.be_to_n")] val be_to_n : b:bytes -> Tot nat (decreases (S.length b)) let rec be_to_n b = if S.length b = 0 then 0 else U8.v (S.last b) + pow2 8 * be_to_n (S.slice b 0 (S.length b - 1)) [@(deprecated "FStar.Endianness.lemma_euclidean_division")] private val lemma_euclidean_division: r:nat -> b:nat -> q:pos -> Lemma (requires (r < q)) (ensures (r + q * b < q * (b+1))) let lemma_euclidean_division r b q = () [@(deprecated "FStar.Endianness.lemma_factorise")] private val lemma_factorise: a:nat -> b:nat -> Lemma (a + a * b == a * (b + 1)) let lemma_factorise a b = () [@(deprecated "FStar.Endianness.lemma_le_to_n_is_bounded")] val lemma_le_to_n_is_bounded: b:bytes -> Lemma (requires True) (ensures (le_to_n b < pow2 (8 * Seq.length b))) (decreases (Seq.length b)) let rec lemma_le_to_n_is_bounded b = if Seq.length b = 0 then () else begin let s = Seq.slice b 1 (Seq.length b) in assert(Seq.length s = Seq.length b - 1); lemma_le_to_n_is_bounded s; assert(UInt8.v (Seq.index b 0) < pow2 8); assert(le_to_n s < pow2 (8 * Seq.length s)); assert(le_to_n b < pow2 8 + pow2 8 * pow2 (8 * (Seq.length b - 1))); lemma_euclidean_division (UInt8.v (Seq.index b 0)) (le_to_n s) (pow2 8); assert(le_to_n b <= pow2 8 * (le_to_n s + 1)); assert(le_to_n b <= pow2 8 * pow2 (8 * (Seq.length b - 1))); Math.Lemmas.pow2_plus 8 (8 * (Seq.length b - 1)); lemma_factorise 8 (Seq.length b - 1) end [@(deprecated "FStar.Endianness.lemma_be_to_n_is_bounded")] val lemma_be_to_n_is_bounded: b:bytes -> Lemma (requires True) (ensures (be_to_n b < pow2 (8 * Seq.length b))) (decreases (Seq.length b)) let rec lemma_be_to_n_is_bounded b = if Seq.length b = 0 then () else begin let s = Seq.slice b 0 (Seq.length b - 1) in assert(Seq.length s = Seq.length b - 1); lemma_be_to_n_is_bounded s; assert(UInt8.v (Seq.last b) < pow2 8); assert(be_to_n s < pow2 (8 * Seq.length s)); assert(be_to_n b < pow2 8 + pow2 8 * pow2 (8 * (Seq.length b - 1))); lemma_euclidean_division (UInt8.v (Seq.last b)) (be_to_n s) (pow2 8); assert(be_to_n b <= pow2 8 * (be_to_n s + 1)); assert(be_to_n b <= pow2 8 * pow2 (8 * (Seq.length b - 1))); Math.Lemmas.pow2_plus 8 (8 * (Seq.length b - 1)); lemma_factorise 8 (Seq.length b - 1) end /// n_to_le encodes a number as a little-endian byte sequence of a fixed, /// sufficiently large length [@(deprecated "FStar.Endianness.n_to_le")] val n_to_le : len:U32.t -> n:nat{n < pow2 (8 * U32.v len)} -> Tot (b:bytes{S.length b == U32.v len /\ n == le_to_n b}) (decreases (U32.v len)) let rec n_to_le len n = if len = 0ul then S.empty else let len = U32.(len -^ 1ul) in let byte = U8.uint_to_t (n % 256) in let n' = n / 256 in Math.pow2_plus 8 (8 * U32.v len); assert(n' < pow2 (8 * U32.v len )); let b' = n_to_le len n' in let b = S.cons byte b' in S.lemma_eq_intro b' (S.tail b); b /// n_to_be encodes a numbers as a big-endian byte sequence of a fixed, /// sufficiently large length [@(deprecated "FStar.Endianness.n_to_be")] val n_to_be: len:U32.t -> n:nat{n < pow2 (8 * U32.v len)} -> Tot (b:bytes{S.length b == U32.v len /\ n == be_to_n b}) (decreases (U32.v len)) let rec n_to_be len n = if len = 0ul then S.empty else let len = U32.(len -^ 1ul) in let byte = U8.uint_to_t (n % 256) in let n' = n / 256 in Math.pow2_plus 8 (8 * U32.v len); assert(n' < pow2 (8 * U32.v len )); let b' = n_to_be len n' in let b'' = S.create 1 byte in let b = S.append b' b'' in S.lemma_eq_intro b' (S.slice b 0 (U32.v len)); b [@(deprecated "FStar.Endianness.n_to_le_inj")] let n_to_le_inj (len:U32.t) (n1 n2: (n:nat{n < pow2 (8 * U32.v len)})) : Lemma (requires (n_to_le len n1 == n_to_le len n2)) (ensures (n1 == n2)) = // this lemma easily follows from le_to_n . (n_to_le len) == id, the inversion // proof in the spec for n_to_le () [@(deprecated "FStar.Endianness.n_to_be_inj")] let n_to_be_inj (len:U32.t) (n1 n2: (n:nat{n < pow2 (8 * U32.v len)})) : Lemma (requires (n_to_be len n1 == n_to_be len n2)) (ensures (n1 == n2)) = () [@(deprecated "FStar.Endianness.be_to_n_inj")] let rec be_to_n_inj (b1 b2: Seq.seq U8.t) : Lemma (requires (Seq.length b1 == Seq.length b2 /\ be_to_n b1 == be_to_n b2)) (ensures (Seq.equal b1 b2)) (decreases (Seq.length b1)) = if Seq.length b1 = 0 then () else begin be_to_n_inj (Seq.slice b1 0 (Seq.length b1 - 1)) (Seq.slice b2 0 (Seq.length b2 - 1)); Seq.lemma_split b1 (Seq.length b1 - 1); Seq.lemma_split b2 (Seq.length b2 - 1) end [@(deprecated "FStar.Endianness.le_to_n_inj")] let rec le_to_n_inj (b1 b2: Seq.seq U8.t) : Lemma (requires (Seq.length b1 == Seq.length b2 /\ le_to_n b1 == le_to_n b2)) (ensures (Seq.equal b1 b2)) (decreases (Seq.length b1)) = if Seq.length b1 = 0 then () else begin le_to_n_inj (Seq.slice b1 1 (Seq.length b1)) (Seq.slice b2 1 (Seq.length b2)); Seq.lemma_split b1 1; Seq.lemma_split b2 1 end [@(deprecated "FStar.Endianness.n_to_be_be_to_n")] let n_to_be_be_to_n (len: U32.t) (s: Seq.seq U8.t) : Lemma (requires (Seq.length s == U32.v len)) (ensures ( be_to_n s < pow2 (8 `Prims.op_Multiply` U32.v len) /\ n_to_be len (be_to_n s) == s )) [SMTPat (n_to_be len (be_to_n s))] = lemma_be_to_n_is_bounded s; be_to_n_inj s (n_to_be len (be_to_n s)) [@(deprecated "FStar.Endianness.n_to_le_le_to_n")] let n_to_le_le_to_n (len: U32.t) (s: Seq.seq U8.t) : Lemma (requires (Seq.length s == U32.v len)) (ensures ( le_to_n s < pow2 (8 `Prims.op_Multiply` U32.v len) /\ n_to_le len (le_to_n s) == s )) [SMTPat (n_to_le len (le_to_n s))] = lemma_le_to_n_is_bounded s; le_to_n_inj s (n_to_le len (le_to_n s)) (** A series of specializations to deal with machine integers *) [@(deprecated "FStar.Endianness.uint32_of_le")] let uint32_of_le (b: bytes { S.length b = 4 }) = let n = le_to_n b in lemma_le_to_n_is_bounded b; UInt32.uint_to_t n [@(deprecated "FStar.Endianness.le_of_uint32")] let le_of_uint32 (x: UInt32.t): b:bytes{ S.length b = 4 } = n_to_le 4ul (UInt32.v x) [@(deprecated "FStar.Endianness.uint32_of_be")] let uint32_of_be (b: bytes { S.length b = 4 }) = let n = be_to_n b in lemma_be_to_n_is_bounded b; UInt32.uint_to_t n [@(deprecated "FStar.Endianness.be_of_uint32")] let be_of_uint32 (x: UInt32.t): b:bytes{ S.length b = 4 } = n_to_be 4ul (UInt32.v x) [@(deprecated "FStar.Endianness.uint64_of_le")] let uint64_of_le (b: bytes { S.length b = 8 }) = let n = le_to_n b in lemma_le_to_n_is_bounded b; UInt64.uint_to_t n [@(deprecated "FStar.Endianness.le_of_uint64")] let le_of_uint64 (x: UInt64.t): b:bytes{ S.length b = 8 } = n_to_le 8ul (UInt64.v x) [@(deprecated "FStar.Endianness.uint64_of_be")] let uint64_of_be (b: bytes { S.length b = 8 }) = let n = be_to_n b in lemma_be_to_n_is_bounded b; UInt64.uint_to_t n [@(deprecated "FStar.Endianness.be_of_uint64")] let be_of_uint64 (x: UInt64.t): b:bytes{ S.length b = 8 } = n_to_be 8ul (UInt64.v x) [@(deprecated "FStar.Endianness.seq_uint32_of_le")] let rec seq_uint32_of_le (l: nat) (b: bytes{ S.length b = 4 * l }): s:S.seq UInt32.t { S.length s = l } = if S.length b = 0 then S.empty else let hd, tl = Seq.split b 4 in S.cons (uint32_of_le hd) (seq_uint32_of_le (l - 1) tl) [@(deprecated "FStar.Endianness.le_of_seq_uint32")] let rec le_of_seq_uint32 (s: S.seq UInt32.t): Tot (b:bytes { S.length b = 4 * S.length s }) (decreases (S.length s)) = if S.length s = 0 then S.empty else S.append (le_of_uint32 (S.head s)) (le_of_seq_uint32 (S.tail s)) [@(deprecated "FStar.Endianness.seq_uint32_of_be")] let rec seq_uint32_of_be (l: nat) (b: bytes{ S.length b = 4 * l }): s:S.seq UInt32.t { S.length s = l } = if S.length b = 0 then S.empty else let hd, tl = Seq.split b 4 in S.cons (uint32_of_be hd) (seq_uint32_of_be (l - 1) tl) [@(deprecated "FStar.Endianness.be_of_seq_uint32")] let rec be_of_seq_uint32 (s: S.seq UInt32.t): Tot (b:bytes { S.length b = 4 * S.length s }) (decreases (S.length s)) = if S.length s = 0 then S.empty else S.append (be_of_uint32 (S.head s)) (be_of_seq_uint32 (S.tail s)) [@(deprecated "FStar.Endianness.seq_uint64_of_le")] let rec seq_uint64_of_le (l: nat) (b: bytes{ S.length b = 8 * l }): s:S.seq UInt64.t { S.length s = l } = if S.length b = 0 then S.empty else let hd, tl = Seq.split b 8 in S.cons (uint64_of_le hd) (seq_uint64_of_le (l - 1) tl) [@(deprecated "FStar.Endianness.le_of_seq_uint64")] let rec le_of_seq_uint64 (s: S.seq UInt64.t): Tot (b:bytes { S.length b = 8 * S.length s }) (decreases (S.length s)) = if S.length s = 0 then S.empty else S.append (le_of_uint64 (S.head s)) (le_of_seq_uint64 (S.tail s)) [@(deprecated "FStar.Endianness.seq_uint64_of_be")] let rec seq_uint64_of_be (l: nat) (b: bytes{ S.length b = 8 * l }): s:S.seq UInt64.t { S.length s = l } = if S.length b = 0 then S.empty else let hd, tl = Seq.split b 8 in S.cons (uint64_of_be hd) (seq_uint64_of_be (l - 1) tl) [@(deprecated "FStar.Endianness.be_of_seq_uint64")] let rec be_of_seq_uint64 (s: S.seq UInt64.t): Tot (b:bytes { S.length b = 8 * S.length s }) (decreases (S.length s)) = if S.length s = 0 then S.empty else S.append (be_of_uint64 (S.head s)) (be_of_seq_uint64 (S.tail s)) #set-options "--max_fuel 1 --max_ifuel 0 --z3rlimit 50" [@(deprecated "FStar.Endianness.offset_uint32_be")] let rec offset_uint32_be (b: bytes) (n: nat) (i: nat): Lemma (requires ( S.length b = 4 * n /\ i < n)) (ensures ( S.index (seq_uint32_of_be n b) i == uint32_of_be (S.slice b (4 * i) (4 * i + 4)))) (decreases ( S.length b)) [ SMTPat (S.index (seq_uint32_of_be n b) i) ] = if S.length b = 0 then false_elim () else let hd, tl = Seq.split b 4 in if i = 0 then () else offset_uint32_be tl (n - 1) (i - 1)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.All.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "FStar.Krml.Endianness.fst" }
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Math.Lemmas", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Krml", "short_module": null }, { "abbrev": false, "full_module": "FStar.Krml", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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": 1, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b: FStar.Krml.Endianness.bytes -> n: Prims.nat -> i: Prims.nat -> FStar.Pervasives.Lemma (requires FStar.Seq.Base.length b = 4 * n /\ i < n) (ensures FStar.Seq.Base.index (FStar.Krml.Endianness.seq_uint32_of_le n b) i == FStar.Krml.Endianness.uint32_of_le (FStar.Seq.Base.slice b (4 * i) (4 * i + 4))) (decreases FStar.Seq.Base.length b) [SMTPat (FStar.Seq.Base.index (FStar.Krml.Endianness.seq_uint32_of_le n b) i)]
FStar.Pervasives.Lemma
[ "lemma", "" ]
[]
[ "FStar.Krml.Endianness.bytes", "Prims.nat", "Prims.op_Equality", "Prims.int", "FStar.Seq.Base.length", "FStar.UInt8.t", "FStar.Pervasives.false_elim", "Prims.unit", "Prims.bool", "FStar.Seq.Base.seq", "FStar.Krml.Endianness.offset_uint32_le", "Prims.op_Subtraction", "FStar.Pervasives.Native.tuple2", "FStar.Seq.Properties.split", "Prims.l_and", "Prims.b2t", "FStar.Mul.op_Star", "Prims.op_LessThan", "Prims.squash", "Prims.eq2", "FStar.UInt32.t", "FStar.Seq.Base.index", "FStar.Krml.Endianness.seq_uint32_of_le", "FStar.Krml.Endianness.uint32_of_le", "FStar.Seq.Base.slice", "Prims.op_Addition", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat", "Prims.Nil" ]
[ "recursion" ]
false
false
true
false
false
let rec offset_uint32_le (b: bytes) (n i: nat) : Lemma (requires (S.length b = 4 * n /\ i < n)) (ensures (S.index (seq_uint32_of_le n b) i == uint32_of_le (S.slice b (4 * i) (4 * i + 4)))) (decreases (S.length b)) [SMTPat (S.index (seq_uint32_of_le n b) i)] =
if S.length b = 0 then false_elim () else let hd, tl = Seq.split b 4 in if i = 0 then () else offset_uint32_le tl (n - 1) (i - 1)
false
FStar.Krml.Endianness.fst
FStar.Krml.Endianness.be_of_seq_uint32_seq_uint32_of_be
val be_of_seq_uint32_seq_uint32_of_be (n: nat) (s: S.seq U8.t) : Lemma (requires (4 * n == S.length s)) (ensures ((be_of_seq_uint32 (seq_uint32_of_be n s)) `S.equal` s)) (decreases n) [SMTPat (be_of_seq_uint32 (seq_uint32_of_be n s))]
val be_of_seq_uint32_seq_uint32_of_be (n: nat) (s: S.seq U8.t) : Lemma (requires (4 * n == S.length s)) (ensures ((be_of_seq_uint32 (seq_uint32_of_be n s)) `S.equal` s)) (decreases n) [SMTPat (be_of_seq_uint32 (seq_uint32_of_be n s))]
let rec be_of_seq_uint32_seq_uint32_of_be (n: nat) (s: S.seq U8.t) : Lemma (requires (4 * n == S.length s)) (ensures (be_of_seq_uint32 (seq_uint32_of_be n s) `S.equal` s)) (decreases n) [SMTPat (be_of_seq_uint32 (seq_uint32_of_be n s))] = if n = 0 then () else begin S.lemma_split s 4; be_of_seq_uint32_seq_uint32_of_be (n - 1) (S.slice s 4 (S.length s)); let s' = seq_uint32_of_be n s in let hd, tl = S.split s 4 in assert (S.head s' == uint32_of_be hd); tail_cons (uint32_of_be hd) (seq_uint32_of_be (n - 1) tl); assert (S.tail s' == seq_uint32_of_be (n - 1) tl); let s'' = be_of_seq_uint32 s' in S.lemma_split s'' 4; S.lemma_append_inj (S.slice s'' 0 4) (S.slice s'' 4 (S.length s'')) (be_of_uint32 (S.head s')) (be_of_seq_uint32 (S.tail s')); n_to_be_be_to_n 4ul hd end
{ "file_name": "krmllib/FStar.Krml.Endianness.fst", "git_rev": "da1e941b2fcb196aa5d1e34941aa00b4c67ac321", "git_url": "https://github.com/FStarLang/karamel.git", "project_name": "karamel" }
{ "end_col": 5, "end_line": 548, "start_col": 0, "start_line": 529 }
module FStar.Krml.Endianness open FStar.Mul open FStar.HyperStack.All module U8 = FStar.UInt8 module U32 = FStar.UInt32 module U64 = FStar.UInt64 module Math = FStar.Math.Lemmas module S = FStar.Seq (* Selectively imported from Hacl*'s FStar.Endianness.fst library, with several name changes *) inline_for_extraction noextract type bytes = S.seq U8.t /// lt_to_n interprets a byte sequence as a little-endian natural number [@(deprecated "FStar.Endianness.le_to_n")] val le_to_n : b:bytes -> Tot nat (decreases (S.length b)) let rec le_to_n b = if S.length b = 0 then 0 else U8.v (S.head b) + pow2 8 * le_to_n (S.tail b) /// be_to_n interprets a byte sequence as a big-endian natural number [@(deprecated "FStar.Endianness.be_to_n")] val be_to_n : b:bytes -> Tot nat (decreases (S.length b)) let rec be_to_n b = if S.length b = 0 then 0 else U8.v (S.last b) + pow2 8 * be_to_n (S.slice b 0 (S.length b - 1)) [@(deprecated "FStar.Endianness.lemma_euclidean_division")] private val lemma_euclidean_division: r:nat -> b:nat -> q:pos -> Lemma (requires (r < q)) (ensures (r + q * b < q * (b+1))) let lemma_euclidean_division r b q = () [@(deprecated "FStar.Endianness.lemma_factorise")] private val lemma_factorise: a:nat -> b:nat -> Lemma (a + a * b == a * (b + 1)) let lemma_factorise a b = () [@(deprecated "FStar.Endianness.lemma_le_to_n_is_bounded")] val lemma_le_to_n_is_bounded: b:bytes -> Lemma (requires True) (ensures (le_to_n b < pow2 (8 * Seq.length b))) (decreases (Seq.length b)) let rec lemma_le_to_n_is_bounded b = if Seq.length b = 0 then () else begin let s = Seq.slice b 1 (Seq.length b) in assert(Seq.length s = Seq.length b - 1); lemma_le_to_n_is_bounded s; assert(UInt8.v (Seq.index b 0) < pow2 8); assert(le_to_n s < pow2 (8 * Seq.length s)); assert(le_to_n b < pow2 8 + pow2 8 * pow2 (8 * (Seq.length b - 1))); lemma_euclidean_division (UInt8.v (Seq.index b 0)) (le_to_n s) (pow2 8); assert(le_to_n b <= pow2 8 * (le_to_n s + 1)); assert(le_to_n b <= pow2 8 * pow2 (8 * (Seq.length b - 1))); Math.Lemmas.pow2_plus 8 (8 * (Seq.length b - 1)); lemma_factorise 8 (Seq.length b - 1) end [@(deprecated "FStar.Endianness.lemma_be_to_n_is_bounded")] val lemma_be_to_n_is_bounded: b:bytes -> Lemma (requires True) (ensures (be_to_n b < pow2 (8 * Seq.length b))) (decreases (Seq.length b)) let rec lemma_be_to_n_is_bounded b = if Seq.length b = 0 then () else begin let s = Seq.slice b 0 (Seq.length b - 1) in assert(Seq.length s = Seq.length b - 1); lemma_be_to_n_is_bounded s; assert(UInt8.v (Seq.last b) < pow2 8); assert(be_to_n s < pow2 (8 * Seq.length s)); assert(be_to_n b < pow2 8 + pow2 8 * pow2 (8 * (Seq.length b - 1))); lemma_euclidean_division (UInt8.v (Seq.last b)) (be_to_n s) (pow2 8); assert(be_to_n b <= pow2 8 * (be_to_n s + 1)); assert(be_to_n b <= pow2 8 * pow2 (8 * (Seq.length b - 1))); Math.Lemmas.pow2_plus 8 (8 * (Seq.length b - 1)); lemma_factorise 8 (Seq.length b - 1) end /// n_to_le encodes a number as a little-endian byte sequence of a fixed, /// sufficiently large length [@(deprecated "FStar.Endianness.n_to_le")] val n_to_le : len:U32.t -> n:nat{n < pow2 (8 * U32.v len)} -> Tot (b:bytes{S.length b == U32.v len /\ n == le_to_n b}) (decreases (U32.v len)) let rec n_to_le len n = if len = 0ul then S.empty else let len = U32.(len -^ 1ul) in let byte = U8.uint_to_t (n % 256) in let n' = n / 256 in Math.pow2_plus 8 (8 * U32.v len); assert(n' < pow2 (8 * U32.v len )); let b' = n_to_le len n' in let b = S.cons byte b' in S.lemma_eq_intro b' (S.tail b); b /// n_to_be encodes a numbers as a big-endian byte sequence of a fixed, /// sufficiently large length [@(deprecated "FStar.Endianness.n_to_be")] val n_to_be: len:U32.t -> n:nat{n < pow2 (8 * U32.v len)} -> Tot (b:bytes{S.length b == U32.v len /\ n == be_to_n b}) (decreases (U32.v len)) let rec n_to_be len n = if len = 0ul then S.empty else let len = U32.(len -^ 1ul) in let byte = U8.uint_to_t (n % 256) in let n' = n / 256 in Math.pow2_plus 8 (8 * U32.v len); assert(n' < pow2 (8 * U32.v len )); let b' = n_to_be len n' in let b'' = S.create 1 byte in let b = S.append b' b'' in S.lemma_eq_intro b' (S.slice b 0 (U32.v len)); b [@(deprecated "FStar.Endianness.n_to_le_inj")] let n_to_le_inj (len:U32.t) (n1 n2: (n:nat{n < pow2 (8 * U32.v len)})) : Lemma (requires (n_to_le len n1 == n_to_le len n2)) (ensures (n1 == n2)) = // this lemma easily follows from le_to_n . (n_to_le len) == id, the inversion // proof in the spec for n_to_le () [@(deprecated "FStar.Endianness.n_to_be_inj")] let n_to_be_inj (len:U32.t) (n1 n2: (n:nat{n < pow2 (8 * U32.v len)})) : Lemma (requires (n_to_be len n1 == n_to_be len n2)) (ensures (n1 == n2)) = () [@(deprecated "FStar.Endianness.be_to_n_inj")] let rec be_to_n_inj (b1 b2: Seq.seq U8.t) : Lemma (requires (Seq.length b1 == Seq.length b2 /\ be_to_n b1 == be_to_n b2)) (ensures (Seq.equal b1 b2)) (decreases (Seq.length b1)) = if Seq.length b1 = 0 then () else begin be_to_n_inj (Seq.slice b1 0 (Seq.length b1 - 1)) (Seq.slice b2 0 (Seq.length b2 - 1)); Seq.lemma_split b1 (Seq.length b1 - 1); Seq.lemma_split b2 (Seq.length b2 - 1) end [@(deprecated "FStar.Endianness.le_to_n_inj")] let rec le_to_n_inj (b1 b2: Seq.seq U8.t) : Lemma (requires (Seq.length b1 == Seq.length b2 /\ le_to_n b1 == le_to_n b2)) (ensures (Seq.equal b1 b2)) (decreases (Seq.length b1)) = if Seq.length b1 = 0 then () else begin le_to_n_inj (Seq.slice b1 1 (Seq.length b1)) (Seq.slice b2 1 (Seq.length b2)); Seq.lemma_split b1 1; Seq.lemma_split b2 1 end [@(deprecated "FStar.Endianness.n_to_be_be_to_n")] let n_to_be_be_to_n (len: U32.t) (s: Seq.seq U8.t) : Lemma (requires (Seq.length s == U32.v len)) (ensures ( be_to_n s < pow2 (8 `Prims.op_Multiply` U32.v len) /\ n_to_be len (be_to_n s) == s )) [SMTPat (n_to_be len (be_to_n s))] = lemma_be_to_n_is_bounded s; be_to_n_inj s (n_to_be len (be_to_n s)) [@(deprecated "FStar.Endianness.n_to_le_le_to_n")] let n_to_le_le_to_n (len: U32.t) (s: Seq.seq U8.t) : Lemma (requires (Seq.length s == U32.v len)) (ensures ( le_to_n s < pow2 (8 `Prims.op_Multiply` U32.v len) /\ n_to_le len (le_to_n s) == s )) [SMTPat (n_to_le len (le_to_n s))] = lemma_le_to_n_is_bounded s; le_to_n_inj s (n_to_le len (le_to_n s)) (** A series of specializations to deal with machine integers *) [@(deprecated "FStar.Endianness.uint32_of_le")] let uint32_of_le (b: bytes { S.length b = 4 }) = let n = le_to_n b in lemma_le_to_n_is_bounded b; UInt32.uint_to_t n [@(deprecated "FStar.Endianness.le_of_uint32")] let le_of_uint32 (x: UInt32.t): b:bytes{ S.length b = 4 } = n_to_le 4ul (UInt32.v x) [@(deprecated "FStar.Endianness.uint32_of_be")] let uint32_of_be (b: bytes { S.length b = 4 }) = let n = be_to_n b in lemma_be_to_n_is_bounded b; UInt32.uint_to_t n [@(deprecated "FStar.Endianness.be_of_uint32")] let be_of_uint32 (x: UInt32.t): b:bytes{ S.length b = 4 } = n_to_be 4ul (UInt32.v x) [@(deprecated "FStar.Endianness.uint64_of_le")] let uint64_of_le (b: bytes { S.length b = 8 }) = let n = le_to_n b in lemma_le_to_n_is_bounded b; UInt64.uint_to_t n [@(deprecated "FStar.Endianness.le_of_uint64")] let le_of_uint64 (x: UInt64.t): b:bytes{ S.length b = 8 } = n_to_le 8ul (UInt64.v x) [@(deprecated "FStar.Endianness.uint64_of_be")] let uint64_of_be (b: bytes { S.length b = 8 }) = let n = be_to_n b in lemma_be_to_n_is_bounded b; UInt64.uint_to_t n [@(deprecated "FStar.Endianness.be_of_uint64")] let be_of_uint64 (x: UInt64.t): b:bytes{ S.length b = 8 } = n_to_be 8ul (UInt64.v x) [@(deprecated "FStar.Endianness.seq_uint32_of_le")] let rec seq_uint32_of_le (l: nat) (b: bytes{ S.length b = 4 * l }): s:S.seq UInt32.t { S.length s = l } = if S.length b = 0 then S.empty else let hd, tl = Seq.split b 4 in S.cons (uint32_of_le hd) (seq_uint32_of_le (l - 1) tl) [@(deprecated "FStar.Endianness.le_of_seq_uint32")] let rec le_of_seq_uint32 (s: S.seq UInt32.t): Tot (b:bytes { S.length b = 4 * S.length s }) (decreases (S.length s)) = if S.length s = 0 then S.empty else S.append (le_of_uint32 (S.head s)) (le_of_seq_uint32 (S.tail s)) [@(deprecated "FStar.Endianness.seq_uint32_of_be")] let rec seq_uint32_of_be (l: nat) (b: bytes{ S.length b = 4 * l }): s:S.seq UInt32.t { S.length s = l } = if S.length b = 0 then S.empty else let hd, tl = Seq.split b 4 in S.cons (uint32_of_be hd) (seq_uint32_of_be (l - 1) tl) [@(deprecated "FStar.Endianness.be_of_seq_uint32")] let rec be_of_seq_uint32 (s: S.seq UInt32.t): Tot (b:bytes { S.length b = 4 * S.length s }) (decreases (S.length s)) = if S.length s = 0 then S.empty else S.append (be_of_uint32 (S.head s)) (be_of_seq_uint32 (S.tail s)) [@(deprecated "FStar.Endianness.seq_uint64_of_le")] let rec seq_uint64_of_le (l: nat) (b: bytes{ S.length b = 8 * l }): s:S.seq UInt64.t { S.length s = l } = if S.length b = 0 then S.empty else let hd, tl = Seq.split b 8 in S.cons (uint64_of_le hd) (seq_uint64_of_le (l - 1) tl) [@(deprecated "FStar.Endianness.le_of_seq_uint64")] let rec le_of_seq_uint64 (s: S.seq UInt64.t): Tot (b:bytes { S.length b = 8 * S.length s }) (decreases (S.length s)) = if S.length s = 0 then S.empty else S.append (le_of_uint64 (S.head s)) (le_of_seq_uint64 (S.tail s)) [@(deprecated "FStar.Endianness.seq_uint64_of_be")] let rec seq_uint64_of_be (l: nat) (b: bytes{ S.length b = 8 * l }): s:S.seq UInt64.t { S.length s = l } = if S.length b = 0 then S.empty else let hd, tl = Seq.split b 8 in S.cons (uint64_of_be hd) (seq_uint64_of_be (l - 1) tl) [@(deprecated "FStar.Endianness.be_of_seq_uint64")] let rec be_of_seq_uint64 (s: S.seq UInt64.t): Tot (b:bytes { S.length b = 8 * S.length s }) (decreases (S.length s)) = if S.length s = 0 then S.empty else S.append (be_of_uint64 (S.head s)) (be_of_seq_uint64 (S.tail s)) #set-options "--max_fuel 1 --max_ifuel 0 --z3rlimit 50" [@(deprecated "FStar.Endianness.offset_uint32_be")] let rec offset_uint32_be (b: bytes) (n: nat) (i: nat): Lemma (requires ( S.length b = 4 * n /\ i < n)) (ensures ( S.index (seq_uint32_of_be n b) i == uint32_of_be (S.slice b (4 * i) (4 * i + 4)))) (decreases ( S.length b)) [ SMTPat (S.index (seq_uint32_of_be n b) i) ] = if S.length b = 0 then false_elim () else let hd, tl = Seq.split b 4 in if i = 0 then () else offset_uint32_be tl (n - 1) (i - 1) [@(deprecated "FStar.Endianness.offset_uint32_le")] let rec offset_uint32_le (b: bytes) (n: nat) (i: nat): Lemma (requires ( S.length b = 4 * n /\ i < n)) (ensures ( S.index (seq_uint32_of_le n b) i == uint32_of_le (S.slice b (4 * i) (4 * i + 4)))) (decreases ( S.length b)) [ SMTPat (S.index (seq_uint32_of_le n b) i) ] = if S.length b = 0 then false_elim () else let hd, tl = Seq.split b 4 in if i = 0 then () else offset_uint32_le tl (n - 1) (i - 1) [@(deprecated "FStar.Endianness.offset_uint64_be")] let rec offset_uint64_be (b: bytes) (n: nat) (i: nat): Lemma (requires ( S.length b = 8 * n /\ i < n)) (ensures ( S.index (seq_uint64_of_be n b) i == uint64_of_be (S.slice b (8 * i) (8 * i + 8)))) (decreases ( S.length b)) [ SMTPat (S.index (seq_uint64_of_be n b) i) ] = if S.length b = 0 then false_elim () else let hd, tl = Seq.split b 8 in if i = 0 then () else offset_uint64_be tl (n - 1) (i - 1) [@(deprecated "FStar.Endianness.offset_uint64_le")] let rec offset_uint64_le (b: bytes) (n: nat) (i: nat): Lemma (requires ( S.length b = 8 * n /\ i < n)) (ensures ( S.index (seq_uint64_of_le n b) i == uint64_of_le (S.slice b (8 * i) (8 * i + 8)))) (decreases ( S.length b)) [ SMTPat (S.index (seq_uint64_of_le n b) i) ] = if S.length b = 0 then false_elim () else let hd, tl = Seq.split b 8 in if i = 0 then () else offset_uint64_le tl (n - 1) (i - 1) (** Reasoning about endian-ness and words. *) #set-options "--max_fuel 1 --z3rlimit 20" (* TODO: move to FStar.Seq.Properties, with the pattern *) [@(deprecated "FStar.Endianness.tail_cons")] let tail_cons (#a: Type) (hd: a) (tl: S.seq a): Lemma (ensures (S.equal (S.tail (S.cons hd tl)) tl)) // [ SMTPat (S.tail (S.cons hd tl)) ] = () [@(deprecated "FStar.Endianness.be_of_seq_uint32_append")] let rec be_of_seq_uint32_append (s1 s2: S.seq U32.t): Lemma (ensures ( S.equal (be_of_seq_uint32 (S.append s1 s2)) (S.append (be_of_seq_uint32 s1) (be_of_seq_uint32 s2)))) (decreases ( S.length s1)) [ SMTPat (S.append (be_of_seq_uint32 s1) (be_of_seq_uint32 s2)) ] = Classical.forall_intro_2 (tail_cons #U32.t); // TODO: this is a local pattern, remove once tail_cons lands in FStar.Seq.Properties if S.length s1 = 0 then begin assert (S.equal (be_of_seq_uint32 s1) S.empty); assert (S.equal (S.append s1 s2) s2); () end else begin assert (S.equal (S.append s1 s2) (S.cons (S.head s1) (S.append (S.tail s1) s2))); assert (S.equal (be_of_seq_uint32 (S.append s1 s2)) (S.append (be_of_uint32 (S.head s1)) (be_of_seq_uint32 (S.append (S.tail s1) s2)))); be_of_seq_uint32_append (S.tail s1) s2 end [@(deprecated "FStar.Endianness.be_of_seq_uint32_base")] let be_of_seq_uint32_base (s1: S.seq U32.t) (s2: S.seq U8.t): Lemma (requires ( S.length s1 = 1 /\ S.length s2 = 4 /\ be_to_n s2 = U32.v (S.index s1 0))) (ensures (S.equal s2 (be_of_seq_uint32 s1))) [ SMTPat (be_to_n s2 = U32.v (S.index s1 0)) ] = () [@(deprecated "FStar.Endianness.le_of_seq_uint32_append")] let rec le_of_seq_uint32_append (s1 s2: S.seq U32.t): Lemma (ensures ( S.equal (le_of_seq_uint32 (S.append s1 s2)) (S.append (le_of_seq_uint32 s1) (le_of_seq_uint32 s2)))) (decreases ( S.length s1)) [ SMTPat (S.append (le_of_seq_uint32 s1) (le_of_seq_uint32 s2)) ] = Classical.forall_intro_2 (tail_cons #U32.t); // TODO: this is a local pattern, remove once tail_cons lands in FStar.Seq.Properties if S.length s1 = 0 then begin assert (S.equal (le_of_seq_uint32 s1) S.empty); assert (S.equal (S.append s1 s2) s2); () end else begin assert (S.equal (S.append s1 s2) (S.cons (S.head s1) (S.append (S.tail s1) s2))); assert (S.equal (le_of_seq_uint32 (S.append s1 s2)) (S.append (le_of_uint32 (S.head s1)) (le_of_seq_uint32 (S.append (S.tail s1) s2)))); le_of_seq_uint32_append (S.tail s1) s2 end [@(deprecated "FStar.Endianness.le_of_seq_uint32_base")] let le_of_seq_uint32_base (s1: S.seq U32.t) (s2: S.seq U8.t): Lemma (requires ( S.length s1 = 1 /\ S.length s2 = 4 /\ le_to_n s2 = U32.v (S.index s1 0))) (ensures (S.equal s2 (le_of_seq_uint32 s1))) [ SMTPat (le_to_n s2 = U32.v (S.index s1 0)) ] = () [@(deprecated "FStar.Endianness.be_of_seq_uint64_append")] let rec be_of_seq_uint64_append (s1 s2: S.seq U64.t): Lemma (ensures ( S.equal (be_of_seq_uint64 (S.append s1 s2)) (S.append (be_of_seq_uint64 s1) (be_of_seq_uint64 s2)))) (decreases ( S.length s1)) [ SMTPat (S.append (be_of_seq_uint64 s1) (be_of_seq_uint64 s2)) ] = Classical.forall_intro_2 (tail_cons #U64.t); // TODO: this is a local pattern, remove once tail_cons lands in FStar.Seq.Properties if S.length s1 = 0 then begin assert (S.equal (be_of_seq_uint64 s1) S.empty); assert (S.equal (S.append s1 s2) s2); () end else begin assert (S.equal (S.append s1 s2) (S.cons (S.head s1) (S.append (S.tail s1) s2))); assert (S.equal (be_of_seq_uint64 (S.append s1 s2)) (S.append (be_of_uint64 (S.head s1)) (be_of_seq_uint64 (S.append (S.tail s1) s2)))); be_of_seq_uint64_append (S.tail s1) s2 end [@(deprecated "FStar.Endianness.be_of_seq_uint64_base")] let be_of_seq_uint64_base (s1: S.seq U64.t) (s2: S.seq U8.t): Lemma (requires ( S.length s1 = 1 /\ S.length s2 = 8 /\ be_to_n s2 = U64.v (S.index s1 0))) (ensures (S.equal s2 (be_of_seq_uint64 s1))) [ SMTPat (be_to_n s2 = U64.v (S.index s1 0)) ] = () [@(deprecated "FStar.Endianness.seq_uint32_of_be_be_of_seq_uint32")] let rec seq_uint32_of_be_be_of_seq_uint32 (n: nat) (s: S.seq U32.t) : Lemma (requires (n == S.length s)) (ensures (seq_uint32_of_be n (be_of_seq_uint32 s) `S.equal` s)) (decreases n) [SMTPat (seq_uint32_of_be n (be_of_seq_uint32 s))] = if n = 0 then () else begin assert (s `S.equal` S.cons (S.head s) (S.tail s)); seq_uint32_of_be_be_of_seq_uint32 (n - 1) (S.tail s); let s' = be_of_seq_uint32 s in S.lemma_split s' 4; S.lemma_append_inj (S.slice s' 0 4) (S.slice s' 4 (S.length s')) (be_of_uint32 (S.head s)) (be_of_seq_uint32 (S.tail s)) end
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.All.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "FStar.Krml.Endianness.fst" }
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Math.Lemmas", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Krml", "short_module": null }, { "abbrev": false, "full_module": "FStar.Krml", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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": 1, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
n: Prims.nat -> s: FStar.Seq.Base.seq FStar.UInt8.t -> FStar.Pervasives.Lemma (requires 4 * n == FStar.Seq.Base.length s) (ensures FStar.Seq.Base.equal (FStar.Krml.Endianness.be_of_seq_uint32 (FStar.Krml.Endianness.seq_uint32_of_be n s)) s) (decreases n) [SMTPat (FStar.Krml.Endianness.be_of_seq_uint32 (FStar.Krml.Endianness.seq_uint32_of_be n s))]
FStar.Pervasives.Lemma
[ "lemma", "" ]
[]
[ "Prims.nat", "FStar.Seq.Base.seq", "FStar.UInt8.t", "Prims.op_Equality", "Prims.int", "Prims.bool", "FStar.Krml.Endianness.n_to_be_be_to_n", "FStar.UInt32.__uint_to_t", "Prims.unit", "FStar.Seq.Properties.lemma_append_inj", "FStar.Seq.Base.slice", "FStar.Seq.Base.length", "FStar.Krml.Endianness.be_of_uint32", "FStar.Seq.Properties.head", "FStar.UInt32.t", "FStar.Krml.Endianness.be_of_seq_uint32", "FStar.Seq.Properties.tail", "FStar.Seq.Properties.lemma_split", "FStar.Krml.Endianness.bytes", "Prims.b2t", "Prims.op_Multiply", "Prims._assert", "Prims.eq2", "FStar.Krml.Endianness.seq_uint32_of_be", "Prims.op_Subtraction", "FStar.Krml.Endianness.tail_cons", "FStar.Krml.Endianness.uint32_of_be", "FStar.Pervasives.Native.tuple2", "FStar.Seq.Properties.split", "FStar.Krml.Endianness.be_of_seq_uint32_seq_uint32_of_be", "FStar.Mul.op_Star", "Prims.squash", "FStar.Seq.Base.equal", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat", "Prims.Nil" ]
[ "recursion" ]
false
false
true
false
false
let rec be_of_seq_uint32_seq_uint32_of_be (n: nat) (s: S.seq U8.t) : Lemma (requires (4 * n == S.length s)) (ensures ((be_of_seq_uint32 (seq_uint32_of_be n s)) `S.equal` s)) (decreases n) [SMTPat (be_of_seq_uint32 (seq_uint32_of_be n s))] =
if n = 0 then () else (S.lemma_split s 4; be_of_seq_uint32_seq_uint32_of_be (n - 1) (S.slice s 4 (S.length s)); let s' = seq_uint32_of_be n s in let hd, tl = S.split s 4 in assert (S.head s' == uint32_of_be hd); tail_cons (uint32_of_be hd) (seq_uint32_of_be (n - 1) tl); assert (S.tail s' == seq_uint32_of_be (n - 1) tl); let s'' = be_of_seq_uint32 s' in S.lemma_split s'' 4; S.lemma_append_inj (S.slice s'' 0 4) (S.slice s'' 4 (S.length s'')) (be_of_uint32 (S.head s')) (be_of_seq_uint32 (S.tail s')); n_to_be_be_to_n 4ul hd)
false
FStar.Krml.Endianness.fst
FStar.Krml.Endianness.offset_uint64_be
val offset_uint64_be (b: bytes) (n i: nat) : Lemma (requires (S.length b = 8 * n /\ i < n)) (ensures (S.index (seq_uint64_of_be n b) i == uint64_of_be (S.slice b (8 * i) (8 * i + 8)))) (decreases (S.length b)) [SMTPat (S.index (seq_uint64_of_be n b) i)]
val offset_uint64_be (b: bytes) (n i: nat) : Lemma (requires (S.length b = 8 * n /\ i < n)) (ensures (S.index (seq_uint64_of_be n b) i == uint64_of_be (S.slice b (8 * i) (8 * i + 8)))) (decreases (S.length b)) [SMTPat (S.index (seq_uint64_of_be n b) i)]
let rec offset_uint64_be (b: bytes) (n: nat) (i: nat): Lemma (requires ( S.length b = 8 * n /\ i < n)) (ensures ( S.index (seq_uint64_of_be n b) i == uint64_of_be (S.slice b (8 * i) (8 * i + 8)))) (decreases ( S.length b)) [ SMTPat (S.index (seq_uint64_of_be n b) i) ] = if S.length b = 0 then false_elim () else let hd, tl = Seq.split b 8 in if i = 0 then () else offset_uint64_be tl (n - 1) (i - 1)
{ "file_name": "krmllib/FStar.Krml.Endianness.fst", "git_rev": "da1e941b2fcb196aa5d1e34941aa00b4c67ac321", "git_url": "https://github.com/FStarLang/karamel.git", "project_name": "karamel" }
{ "end_col": 41, "end_line": 380, "start_col": 0, "start_line": 362 }
module FStar.Krml.Endianness open FStar.Mul open FStar.HyperStack.All module U8 = FStar.UInt8 module U32 = FStar.UInt32 module U64 = FStar.UInt64 module Math = FStar.Math.Lemmas module S = FStar.Seq (* Selectively imported from Hacl*'s FStar.Endianness.fst library, with several name changes *) inline_for_extraction noextract type bytes = S.seq U8.t /// lt_to_n interprets a byte sequence as a little-endian natural number [@(deprecated "FStar.Endianness.le_to_n")] val le_to_n : b:bytes -> Tot nat (decreases (S.length b)) let rec le_to_n b = if S.length b = 0 then 0 else U8.v (S.head b) + pow2 8 * le_to_n (S.tail b) /// be_to_n interprets a byte sequence as a big-endian natural number [@(deprecated "FStar.Endianness.be_to_n")] val be_to_n : b:bytes -> Tot nat (decreases (S.length b)) let rec be_to_n b = if S.length b = 0 then 0 else U8.v (S.last b) + pow2 8 * be_to_n (S.slice b 0 (S.length b - 1)) [@(deprecated "FStar.Endianness.lemma_euclidean_division")] private val lemma_euclidean_division: r:nat -> b:nat -> q:pos -> Lemma (requires (r < q)) (ensures (r + q * b < q * (b+1))) let lemma_euclidean_division r b q = () [@(deprecated "FStar.Endianness.lemma_factorise")] private val lemma_factorise: a:nat -> b:nat -> Lemma (a + a * b == a * (b + 1)) let lemma_factorise a b = () [@(deprecated "FStar.Endianness.lemma_le_to_n_is_bounded")] val lemma_le_to_n_is_bounded: b:bytes -> Lemma (requires True) (ensures (le_to_n b < pow2 (8 * Seq.length b))) (decreases (Seq.length b)) let rec lemma_le_to_n_is_bounded b = if Seq.length b = 0 then () else begin let s = Seq.slice b 1 (Seq.length b) in assert(Seq.length s = Seq.length b - 1); lemma_le_to_n_is_bounded s; assert(UInt8.v (Seq.index b 0) < pow2 8); assert(le_to_n s < pow2 (8 * Seq.length s)); assert(le_to_n b < pow2 8 + pow2 8 * pow2 (8 * (Seq.length b - 1))); lemma_euclidean_division (UInt8.v (Seq.index b 0)) (le_to_n s) (pow2 8); assert(le_to_n b <= pow2 8 * (le_to_n s + 1)); assert(le_to_n b <= pow2 8 * pow2 (8 * (Seq.length b - 1))); Math.Lemmas.pow2_plus 8 (8 * (Seq.length b - 1)); lemma_factorise 8 (Seq.length b - 1) end [@(deprecated "FStar.Endianness.lemma_be_to_n_is_bounded")] val lemma_be_to_n_is_bounded: b:bytes -> Lemma (requires True) (ensures (be_to_n b < pow2 (8 * Seq.length b))) (decreases (Seq.length b)) let rec lemma_be_to_n_is_bounded b = if Seq.length b = 0 then () else begin let s = Seq.slice b 0 (Seq.length b - 1) in assert(Seq.length s = Seq.length b - 1); lemma_be_to_n_is_bounded s; assert(UInt8.v (Seq.last b) < pow2 8); assert(be_to_n s < pow2 (8 * Seq.length s)); assert(be_to_n b < pow2 8 + pow2 8 * pow2 (8 * (Seq.length b - 1))); lemma_euclidean_division (UInt8.v (Seq.last b)) (be_to_n s) (pow2 8); assert(be_to_n b <= pow2 8 * (be_to_n s + 1)); assert(be_to_n b <= pow2 8 * pow2 (8 * (Seq.length b - 1))); Math.Lemmas.pow2_plus 8 (8 * (Seq.length b - 1)); lemma_factorise 8 (Seq.length b - 1) end /// n_to_le encodes a number as a little-endian byte sequence of a fixed, /// sufficiently large length [@(deprecated "FStar.Endianness.n_to_le")] val n_to_le : len:U32.t -> n:nat{n < pow2 (8 * U32.v len)} -> Tot (b:bytes{S.length b == U32.v len /\ n == le_to_n b}) (decreases (U32.v len)) let rec n_to_le len n = if len = 0ul then S.empty else let len = U32.(len -^ 1ul) in let byte = U8.uint_to_t (n % 256) in let n' = n / 256 in Math.pow2_plus 8 (8 * U32.v len); assert(n' < pow2 (8 * U32.v len )); let b' = n_to_le len n' in let b = S.cons byte b' in S.lemma_eq_intro b' (S.tail b); b /// n_to_be encodes a numbers as a big-endian byte sequence of a fixed, /// sufficiently large length [@(deprecated "FStar.Endianness.n_to_be")] val n_to_be: len:U32.t -> n:nat{n < pow2 (8 * U32.v len)} -> Tot (b:bytes{S.length b == U32.v len /\ n == be_to_n b}) (decreases (U32.v len)) let rec n_to_be len n = if len = 0ul then S.empty else let len = U32.(len -^ 1ul) in let byte = U8.uint_to_t (n % 256) in let n' = n / 256 in Math.pow2_plus 8 (8 * U32.v len); assert(n' < pow2 (8 * U32.v len )); let b' = n_to_be len n' in let b'' = S.create 1 byte in let b = S.append b' b'' in S.lemma_eq_intro b' (S.slice b 0 (U32.v len)); b [@(deprecated "FStar.Endianness.n_to_le_inj")] let n_to_le_inj (len:U32.t) (n1 n2: (n:nat{n < pow2 (8 * U32.v len)})) : Lemma (requires (n_to_le len n1 == n_to_le len n2)) (ensures (n1 == n2)) = // this lemma easily follows from le_to_n . (n_to_le len) == id, the inversion // proof in the spec for n_to_le () [@(deprecated "FStar.Endianness.n_to_be_inj")] let n_to_be_inj (len:U32.t) (n1 n2: (n:nat{n < pow2 (8 * U32.v len)})) : Lemma (requires (n_to_be len n1 == n_to_be len n2)) (ensures (n1 == n2)) = () [@(deprecated "FStar.Endianness.be_to_n_inj")] let rec be_to_n_inj (b1 b2: Seq.seq U8.t) : Lemma (requires (Seq.length b1 == Seq.length b2 /\ be_to_n b1 == be_to_n b2)) (ensures (Seq.equal b1 b2)) (decreases (Seq.length b1)) = if Seq.length b1 = 0 then () else begin be_to_n_inj (Seq.slice b1 0 (Seq.length b1 - 1)) (Seq.slice b2 0 (Seq.length b2 - 1)); Seq.lemma_split b1 (Seq.length b1 - 1); Seq.lemma_split b2 (Seq.length b2 - 1) end [@(deprecated "FStar.Endianness.le_to_n_inj")] let rec le_to_n_inj (b1 b2: Seq.seq U8.t) : Lemma (requires (Seq.length b1 == Seq.length b2 /\ le_to_n b1 == le_to_n b2)) (ensures (Seq.equal b1 b2)) (decreases (Seq.length b1)) = if Seq.length b1 = 0 then () else begin le_to_n_inj (Seq.slice b1 1 (Seq.length b1)) (Seq.slice b2 1 (Seq.length b2)); Seq.lemma_split b1 1; Seq.lemma_split b2 1 end [@(deprecated "FStar.Endianness.n_to_be_be_to_n")] let n_to_be_be_to_n (len: U32.t) (s: Seq.seq U8.t) : Lemma (requires (Seq.length s == U32.v len)) (ensures ( be_to_n s < pow2 (8 `Prims.op_Multiply` U32.v len) /\ n_to_be len (be_to_n s) == s )) [SMTPat (n_to_be len (be_to_n s))] = lemma_be_to_n_is_bounded s; be_to_n_inj s (n_to_be len (be_to_n s)) [@(deprecated "FStar.Endianness.n_to_le_le_to_n")] let n_to_le_le_to_n (len: U32.t) (s: Seq.seq U8.t) : Lemma (requires (Seq.length s == U32.v len)) (ensures ( le_to_n s < pow2 (8 `Prims.op_Multiply` U32.v len) /\ n_to_le len (le_to_n s) == s )) [SMTPat (n_to_le len (le_to_n s))] = lemma_le_to_n_is_bounded s; le_to_n_inj s (n_to_le len (le_to_n s)) (** A series of specializations to deal with machine integers *) [@(deprecated "FStar.Endianness.uint32_of_le")] let uint32_of_le (b: bytes { S.length b = 4 }) = let n = le_to_n b in lemma_le_to_n_is_bounded b; UInt32.uint_to_t n [@(deprecated "FStar.Endianness.le_of_uint32")] let le_of_uint32 (x: UInt32.t): b:bytes{ S.length b = 4 } = n_to_le 4ul (UInt32.v x) [@(deprecated "FStar.Endianness.uint32_of_be")] let uint32_of_be (b: bytes { S.length b = 4 }) = let n = be_to_n b in lemma_be_to_n_is_bounded b; UInt32.uint_to_t n [@(deprecated "FStar.Endianness.be_of_uint32")] let be_of_uint32 (x: UInt32.t): b:bytes{ S.length b = 4 } = n_to_be 4ul (UInt32.v x) [@(deprecated "FStar.Endianness.uint64_of_le")] let uint64_of_le (b: bytes { S.length b = 8 }) = let n = le_to_n b in lemma_le_to_n_is_bounded b; UInt64.uint_to_t n [@(deprecated "FStar.Endianness.le_of_uint64")] let le_of_uint64 (x: UInt64.t): b:bytes{ S.length b = 8 } = n_to_le 8ul (UInt64.v x) [@(deprecated "FStar.Endianness.uint64_of_be")] let uint64_of_be (b: bytes { S.length b = 8 }) = let n = be_to_n b in lemma_be_to_n_is_bounded b; UInt64.uint_to_t n [@(deprecated "FStar.Endianness.be_of_uint64")] let be_of_uint64 (x: UInt64.t): b:bytes{ S.length b = 8 } = n_to_be 8ul (UInt64.v x) [@(deprecated "FStar.Endianness.seq_uint32_of_le")] let rec seq_uint32_of_le (l: nat) (b: bytes{ S.length b = 4 * l }): s:S.seq UInt32.t { S.length s = l } = if S.length b = 0 then S.empty else let hd, tl = Seq.split b 4 in S.cons (uint32_of_le hd) (seq_uint32_of_le (l - 1) tl) [@(deprecated "FStar.Endianness.le_of_seq_uint32")] let rec le_of_seq_uint32 (s: S.seq UInt32.t): Tot (b:bytes { S.length b = 4 * S.length s }) (decreases (S.length s)) = if S.length s = 0 then S.empty else S.append (le_of_uint32 (S.head s)) (le_of_seq_uint32 (S.tail s)) [@(deprecated "FStar.Endianness.seq_uint32_of_be")] let rec seq_uint32_of_be (l: nat) (b: bytes{ S.length b = 4 * l }): s:S.seq UInt32.t { S.length s = l } = if S.length b = 0 then S.empty else let hd, tl = Seq.split b 4 in S.cons (uint32_of_be hd) (seq_uint32_of_be (l - 1) tl) [@(deprecated "FStar.Endianness.be_of_seq_uint32")] let rec be_of_seq_uint32 (s: S.seq UInt32.t): Tot (b:bytes { S.length b = 4 * S.length s }) (decreases (S.length s)) = if S.length s = 0 then S.empty else S.append (be_of_uint32 (S.head s)) (be_of_seq_uint32 (S.tail s)) [@(deprecated "FStar.Endianness.seq_uint64_of_le")] let rec seq_uint64_of_le (l: nat) (b: bytes{ S.length b = 8 * l }): s:S.seq UInt64.t { S.length s = l } = if S.length b = 0 then S.empty else let hd, tl = Seq.split b 8 in S.cons (uint64_of_le hd) (seq_uint64_of_le (l - 1) tl) [@(deprecated "FStar.Endianness.le_of_seq_uint64")] let rec le_of_seq_uint64 (s: S.seq UInt64.t): Tot (b:bytes { S.length b = 8 * S.length s }) (decreases (S.length s)) = if S.length s = 0 then S.empty else S.append (le_of_uint64 (S.head s)) (le_of_seq_uint64 (S.tail s)) [@(deprecated "FStar.Endianness.seq_uint64_of_be")] let rec seq_uint64_of_be (l: nat) (b: bytes{ S.length b = 8 * l }): s:S.seq UInt64.t { S.length s = l } = if S.length b = 0 then S.empty else let hd, tl = Seq.split b 8 in S.cons (uint64_of_be hd) (seq_uint64_of_be (l - 1) tl) [@(deprecated "FStar.Endianness.be_of_seq_uint64")] let rec be_of_seq_uint64 (s: S.seq UInt64.t): Tot (b:bytes { S.length b = 8 * S.length s }) (decreases (S.length s)) = if S.length s = 0 then S.empty else S.append (be_of_uint64 (S.head s)) (be_of_seq_uint64 (S.tail s)) #set-options "--max_fuel 1 --max_ifuel 0 --z3rlimit 50" [@(deprecated "FStar.Endianness.offset_uint32_be")] let rec offset_uint32_be (b: bytes) (n: nat) (i: nat): Lemma (requires ( S.length b = 4 * n /\ i < n)) (ensures ( S.index (seq_uint32_of_be n b) i == uint32_of_be (S.slice b (4 * i) (4 * i + 4)))) (decreases ( S.length b)) [ SMTPat (S.index (seq_uint32_of_be n b) i) ] = if S.length b = 0 then false_elim () else let hd, tl = Seq.split b 4 in if i = 0 then () else offset_uint32_be tl (n - 1) (i - 1) [@(deprecated "FStar.Endianness.offset_uint32_le")] let rec offset_uint32_le (b: bytes) (n: nat) (i: nat): Lemma (requires ( S.length b = 4 * n /\ i < n)) (ensures ( S.index (seq_uint32_of_le n b) i == uint32_of_le (S.slice b (4 * i) (4 * i + 4)))) (decreases ( S.length b)) [ SMTPat (S.index (seq_uint32_of_le n b) i) ] = if S.length b = 0 then false_elim () else let hd, tl = Seq.split b 4 in if i = 0 then () else offset_uint32_le tl (n - 1) (i - 1)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.All.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "FStar.Krml.Endianness.fst" }
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Math.Lemmas", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Krml", "short_module": null }, { "abbrev": false, "full_module": "FStar.Krml", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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": 1, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b: FStar.Krml.Endianness.bytes -> n: Prims.nat -> i: Prims.nat -> FStar.Pervasives.Lemma (requires FStar.Seq.Base.length b = 8 * n /\ i < n) (ensures FStar.Seq.Base.index (FStar.Krml.Endianness.seq_uint64_of_be n b) i == FStar.Krml.Endianness.uint64_of_be (FStar.Seq.Base.slice b (8 * i) (8 * i + 8))) (decreases FStar.Seq.Base.length b) [SMTPat (FStar.Seq.Base.index (FStar.Krml.Endianness.seq_uint64_of_be n b) i)]
FStar.Pervasives.Lemma
[ "lemma", "" ]
[]
[ "FStar.Krml.Endianness.bytes", "Prims.nat", "Prims.op_Equality", "Prims.int", "FStar.Seq.Base.length", "FStar.UInt8.t", "FStar.Pervasives.false_elim", "Prims.unit", "Prims.bool", "FStar.Seq.Base.seq", "FStar.Krml.Endianness.offset_uint64_be", "Prims.op_Subtraction", "FStar.Pervasives.Native.tuple2", "FStar.Seq.Properties.split", "Prims.l_and", "Prims.b2t", "FStar.Mul.op_Star", "Prims.op_LessThan", "Prims.squash", "Prims.eq2", "FStar.UInt64.t", "FStar.Seq.Base.index", "FStar.Krml.Endianness.seq_uint64_of_be", "FStar.Krml.Endianness.uint64_of_be", "FStar.Seq.Base.slice", "Prims.op_Addition", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat", "Prims.Nil" ]
[ "recursion" ]
false
false
true
false
false
let rec offset_uint64_be (b: bytes) (n i: nat) : Lemma (requires (S.length b = 8 * n /\ i < n)) (ensures (S.index (seq_uint64_of_be n b) i == uint64_of_be (S.slice b (8 * i) (8 * i + 8)))) (decreases (S.length b)) [SMTPat (S.index (seq_uint64_of_be n b) i)] =
if S.length b = 0 then false_elim () else let hd, tl = Seq.split b 8 in if i = 0 then () else offset_uint64_be tl (n - 1) (i - 1)
false
FStar.Krml.Endianness.fst
FStar.Krml.Endianness.be_of_seq_uint32_append
val be_of_seq_uint32_append (s1 s2: S.seq U32.t) : Lemma (ensures (S.equal (be_of_seq_uint32 (S.append s1 s2)) (S.append (be_of_seq_uint32 s1) (be_of_seq_uint32 s2)))) (decreases (S.length s1)) [SMTPat (S.append (be_of_seq_uint32 s1) (be_of_seq_uint32 s2))]
val be_of_seq_uint32_append (s1 s2: S.seq U32.t) : Lemma (ensures (S.equal (be_of_seq_uint32 (S.append s1 s2)) (S.append (be_of_seq_uint32 s1) (be_of_seq_uint32 s2)))) (decreases (S.length s1)) [SMTPat (S.append (be_of_seq_uint32 s1) (be_of_seq_uint32 s2))]
let rec be_of_seq_uint32_append (s1 s2: S.seq U32.t): Lemma (ensures ( S.equal (be_of_seq_uint32 (S.append s1 s2)) (S.append (be_of_seq_uint32 s1) (be_of_seq_uint32 s2)))) (decreases ( S.length s1)) [ SMTPat (S.append (be_of_seq_uint32 s1) (be_of_seq_uint32 s2)) ] = Classical.forall_intro_2 (tail_cons #U32.t); // TODO: this is a local pattern, remove once tail_cons lands in FStar.Seq.Properties if S.length s1 = 0 then begin assert (S.equal (be_of_seq_uint32 s1) S.empty); assert (S.equal (S.append s1 s2) s2); () end else begin assert (S.equal (S.append s1 s2) (S.cons (S.head s1) (S.append (S.tail s1) s2))); assert (S.equal (be_of_seq_uint32 (S.append s1 s2)) (S.append (be_of_uint32 (S.head s1)) (be_of_seq_uint32 (S.append (S.tail s1) s2)))); be_of_seq_uint32_append (S.tail s1) s2 end
{ "file_name": "krmllib/FStar.Krml.Endianness.fst", "git_rev": "da1e941b2fcb196aa5d1e34941aa00b4c67ac321", "git_url": "https://github.com/FStarLang/karamel.git", "project_name": "karamel" }
{ "end_col": 5, "end_line": 435, "start_col": 0, "start_line": 417 }
module FStar.Krml.Endianness open FStar.Mul open FStar.HyperStack.All module U8 = FStar.UInt8 module U32 = FStar.UInt32 module U64 = FStar.UInt64 module Math = FStar.Math.Lemmas module S = FStar.Seq (* Selectively imported from Hacl*'s FStar.Endianness.fst library, with several name changes *) inline_for_extraction noextract type bytes = S.seq U8.t /// lt_to_n interprets a byte sequence as a little-endian natural number [@(deprecated "FStar.Endianness.le_to_n")] val le_to_n : b:bytes -> Tot nat (decreases (S.length b)) let rec le_to_n b = if S.length b = 0 then 0 else U8.v (S.head b) + pow2 8 * le_to_n (S.tail b) /// be_to_n interprets a byte sequence as a big-endian natural number [@(deprecated "FStar.Endianness.be_to_n")] val be_to_n : b:bytes -> Tot nat (decreases (S.length b)) let rec be_to_n b = if S.length b = 0 then 0 else U8.v (S.last b) + pow2 8 * be_to_n (S.slice b 0 (S.length b - 1)) [@(deprecated "FStar.Endianness.lemma_euclidean_division")] private val lemma_euclidean_division: r:nat -> b:nat -> q:pos -> Lemma (requires (r < q)) (ensures (r + q * b < q * (b+1))) let lemma_euclidean_division r b q = () [@(deprecated "FStar.Endianness.lemma_factorise")] private val lemma_factorise: a:nat -> b:nat -> Lemma (a + a * b == a * (b + 1)) let lemma_factorise a b = () [@(deprecated "FStar.Endianness.lemma_le_to_n_is_bounded")] val lemma_le_to_n_is_bounded: b:bytes -> Lemma (requires True) (ensures (le_to_n b < pow2 (8 * Seq.length b))) (decreases (Seq.length b)) let rec lemma_le_to_n_is_bounded b = if Seq.length b = 0 then () else begin let s = Seq.slice b 1 (Seq.length b) in assert(Seq.length s = Seq.length b - 1); lemma_le_to_n_is_bounded s; assert(UInt8.v (Seq.index b 0) < pow2 8); assert(le_to_n s < pow2 (8 * Seq.length s)); assert(le_to_n b < pow2 8 + pow2 8 * pow2 (8 * (Seq.length b - 1))); lemma_euclidean_division (UInt8.v (Seq.index b 0)) (le_to_n s) (pow2 8); assert(le_to_n b <= pow2 8 * (le_to_n s + 1)); assert(le_to_n b <= pow2 8 * pow2 (8 * (Seq.length b - 1))); Math.Lemmas.pow2_plus 8 (8 * (Seq.length b - 1)); lemma_factorise 8 (Seq.length b - 1) end [@(deprecated "FStar.Endianness.lemma_be_to_n_is_bounded")] val lemma_be_to_n_is_bounded: b:bytes -> Lemma (requires True) (ensures (be_to_n b < pow2 (8 * Seq.length b))) (decreases (Seq.length b)) let rec lemma_be_to_n_is_bounded b = if Seq.length b = 0 then () else begin let s = Seq.slice b 0 (Seq.length b - 1) in assert(Seq.length s = Seq.length b - 1); lemma_be_to_n_is_bounded s; assert(UInt8.v (Seq.last b) < pow2 8); assert(be_to_n s < pow2 (8 * Seq.length s)); assert(be_to_n b < pow2 8 + pow2 8 * pow2 (8 * (Seq.length b - 1))); lemma_euclidean_division (UInt8.v (Seq.last b)) (be_to_n s) (pow2 8); assert(be_to_n b <= pow2 8 * (be_to_n s + 1)); assert(be_to_n b <= pow2 8 * pow2 (8 * (Seq.length b - 1))); Math.Lemmas.pow2_plus 8 (8 * (Seq.length b - 1)); lemma_factorise 8 (Seq.length b - 1) end /// n_to_le encodes a number as a little-endian byte sequence of a fixed, /// sufficiently large length [@(deprecated "FStar.Endianness.n_to_le")] val n_to_le : len:U32.t -> n:nat{n < pow2 (8 * U32.v len)} -> Tot (b:bytes{S.length b == U32.v len /\ n == le_to_n b}) (decreases (U32.v len)) let rec n_to_le len n = if len = 0ul then S.empty else let len = U32.(len -^ 1ul) in let byte = U8.uint_to_t (n % 256) in let n' = n / 256 in Math.pow2_plus 8 (8 * U32.v len); assert(n' < pow2 (8 * U32.v len )); let b' = n_to_le len n' in let b = S.cons byte b' in S.lemma_eq_intro b' (S.tail b); b /// n_to_be encodes a numbers as a big-endian byte sequence of a fixed, /// sufficiently large length [@(deprecated "FStar.Endianness.n_to_be")] val n_to_be: len:U32.t -> n:nat{n < pow2 (8 * U32.v len)} -> Tot (b:bytes{S.length b == U32.v len /\ n == be_to_n b}) (decreases (U32.v len)) let rec n_to_be len n = if len = 0ul then S.empty else let len = U32.(len -^ 1ul) in let byte = U8.uint_to_t (n % 256) in let n' = n / 256 in Math.pow2_plus 8 (8 * U32.v len); assert(n' < pow2 (8 * U32.v len )); let b' = n_to_be len n' in let b'' = S.create 1 byte in let b = S.append b' b'' in S.lemma_eq_intro b' (S.slice b 0 (U32.v len)); b [@(deprecated "FStar.Endianness.n_to_le_inj")] let n_to_le_inj (len:U32.t) (n1 n2: (n:nat{n < pow2 (8 * U32.v len)})) : Lemma (requires (n_to_le len n1 == n_to_le len n2)) (ensures (n1 == n2)) = // this lemma easily follows from le_to_n . (n_to_le len) == id, the inversion // proof in the spec for n_to_le () [@(deprecated "FStar.Endianness.n_to_be_inj")] let n_to_be_inj (len:U32.t) (n1 n2: (n:nat{n < pow2 (8 * U32.v len)})) : Lemma (requires (n_to_be len n1 == n_to_be len n2)) (ensures (n1 == n2)) = () [@(deprecated "FStar.Endianness.be_to_n_inj")] let rec be_to_n_inj (b1 b2: Seq.seq U8.t) : Lemma (requires (Seq.length b1 == Seq.length b2 /\ be_to_n b1 == be_to_n b2)) (ensures (Seq.equal b1 b2)) (decreases (Seq.length b1)) = if Seq.length b1 = 0 then () else begin be_to_n_inj (Seq.slice b1 0 (Seq.length b1 - 1)) (Seq.slice b2 0 (Seq.length b2 - 1)); Seq.lemma_split b1 (Seq.length b1 - 1); Seq.lemma_split b2 (Seq.length b2 - 1) end [@(deprecated "FStar.Endianness.le_to_n_inj")] let rec le_to_n_inj (b1 b2: Seq.seq U8.t) : Lemma (requires (Seq.length b1 == Seq.length b2 /\ le_to_n b1 == le_to_n b2)) (ensures (Seq.equal b1 b2)) (decreases (Seq.length b1)) = if Seq.length b1 = 0 then () else begin le_to_n_inj (Seq.slice b1 1 (Seq.length b1)) (Seq.slice b2 1 (Seq.length b2)); Seq.lemma_split b1 1; Seq.lemma_split b2 1 end [@(deprecated "FStar.Endianness.n_to_be_be_to_n")] let n_to_be_be_to_n (len: U32.t) (s: Seq.seq U8.t) : Lemma (requires (Seq.length s == U32.v len)) (ensures ( be_to_n s < pow2 (8 `Prims.op_Multiply` U32.v len) /\ n_to_be len (be_to_n s) == s )) [SMTPat (n_to_be len (be_to_n s))] = lemma_be_to_n_is_bounded s; be_to_n_inj s (n_to_be len (be_to_n s)) [@(deprecated "FStar.Endianness.n_to_le_le_to_n")] let n_to_le_le_to_n (len: U32.t) (s: Seq.seq U8.t) : Lemma (requires (Seq.length s == U32.v len)) (ensures ( le_to_n s < pow2 (8 `Prims.op_Multiply` U32.v len) /\ n_to_le len (le_to_n s) == s )) [SMTPat (n_to_le len (le_to_n s))] = lemma_le_to_n_is_bounded s; le_to_n_inj s (n_to_le len (le_to_n s)) (** A series of specializations to deal with machine integers *) [@(deprecated "FStar.Endianness.uint32_of_le")] let uint32_of_le (b: bytes { S.length b = 4 }) = let n = le_to_n b in lemma_le_to_n_is_bounded b; UInt32.uint_to_t n [@(deprecated "FStar.Endianness.le_of_uint32")] let le_of_uint32 (x: UInt32.t): b:bytes{ S.length b = 4 } = n_to_le 4ul (UInt32.v x) [@(deprecated "FStar.Endianness.uint32_of_be")] let uint32_of_be (b: bytes { S.length b = 4 }) = let n = be_to_n b in lemma_be_to_n_is_bounded b; UInt32.uint_to_t n [@(deprecated "FStar.Endianness.be_of_uint32")] let be_of_uint32 (x: UInt32.t): b:bytes{ S.length b = 4 } = n_to_be 4ul (UInt32.v x) [@(deprecated "FStar.Endianness.uint64_of_le")] let uint64_of_le (b: bytes { S.length b = 8 }) = let n = le_to_n b in lemma_le_to_n_is_bounded b; UInt64.uint_to_t n [@(deprecated "FStar.Endianness.le_of_uint64")] let le_of_uint64 (x: UInt64.t): b:bytes{ S.length b = 8 } = n_to_le 8ul (UInt64.v x) [@(deprecated "FStar.Endianness.uint64_of_be")] let uint64_of_be (b: bytes { S.length b = 8 }) = let n = be_to_n b in lemma_be_to_n_is_bounded b; UInt64.uint_to_t n [@(deprecated "FStar.Endianness.be_of_uint64")] let be_of_uint64 (x: UInt64.t): b:bytes{ S.length b = 8 } = n_to_be 8ul (UInt64.v x) [@(deprecated "FStar.Endianness.seq_uint32_of_le")] let rec seq_uint32_of_le (l: nat) (b: bytes{ S.length b = 4 * l }): s:S.seq UInt32.t { S.length s = l } = if S.length b = 0 then S.empty else let hd, tl = Seq.split b 4 in S.cons (uint32_of_le hd) (seq_uint32_of_le (l - 1) tl) [@(deprecated "FStar.Endianness.le_of_seq_uint32")] let rec le_of_seq_uint32 (s: S.seq UInt32.t): Tot (b:bytes { S.length b = 4 * S.length s }) (decreases (S.length s)) = if S.length s = 0 then S.empty else S.append (le_of_uint32 (S.head s)) (le_of_seq_uint32 (S.tail s)) [@(deprecated "FStar.Endianness.seq_uint32_of_be")] let rec seq_uint32_of_be (l: nat) (b: bytes{ S.length b = 4 * l }): s:S.seq UInt32.t { S.length s = l } = if S.length b = 0 then S.empty else let hd, tl = Seq.split b 4 in S.cons (uint32_of_be hd) (seq_uint32_of_be (l - 1) tl) [@(deprecated "FStar.Endianness.be_of_seq_uint32")] let rec be_of_seq_uint32 (s: S.seq UInt32.t): Tot (b:bytes { S.length b = 4 * S.length s }) (decreases (S.length s)) = if S.length s = 0 then S.empty else S.append (be_of_uint32 (S.head s)) (be_of_seq_uint32 (S.tail s)) [@(deprecated "FStar.Endianness.seq_uint64_of_le")] let rec seq_uint64_of_le (l: nat) (b: bytes{ S.length b = 8 * l }): s:S.seq UInt64.t { S.length s = l } = if S.length b = 0 then S.empty else let hd, tl = Seq.split b 8 in S.cons (uint64_of_le hd) (seq_uint64_of_le (l - 1) tl) [@(deprecated "FStar.Endianness.le_of_seq_uint64")] let rec le_of_seq_uint64 (s: S.seq UInt64.t): Tot (b:bytes { S.length b = 8 * S.length s }) (decreases (S.length s)) = if S.length s = 0 then S.empty else S.append (le_of_uint64 (S.head s)) (le_of_seq_uint64 (S.tail s)) [@(deprecated "FStar.Endianness.seq_uint64_of_be")] let rec seq_uint64_of_be (l: nat) (b: bytes{ S.length b = 8 * l }): s:S.seq UInt64.t { S.length s = l } = if S.length b = 0 then S.empty else let hd, tl = Seq.split b 8 in S.cons (uint64_of_be hd) (seq_uint64_of_be (l - 1) tl) [@(deprecated "FStar.Endianness.be_of_seq_uint64")] let rec be_of_seq_uint64 (s: S.seq UInt64.t): Tot (b:bytes { S.length b = 8 * S.length s }) (decreases (S.length s)) = if S.length s = 0 then S.empty else S.append (be_of_uint64 (S.head s)) (be_of_seq_uint64 (S.tail s)) #set-options "--max_fuel 1 --max_ifuel 0 --z3rlimit 50" [@(deprecated "FStar.Endianness.offset_uint32_be")] let rec offset_uint32_be (b: bytes) (n: nat) (i: nat): Lemma (requires ( S.length b = 4 * n /\ i < n)) (ensures ( S.index (seq_uint32_of_be n b) i == uint32_of_be (S.slice b (4 * i) (4 * i + 4)))) (decreases ( S.length b)) [ SMTPat (S.index (seq_uint32_of_be n b) i) ] = if S.length b = 0 then false_elim () else let hd, tl = Seq.split b 4 in if i = 0 then () else offset_uint32_be tl (n - 1) (i - 1) [@(deprecated "FStar.Endianness.offset_uint32_le")] let rec offset_uint32_le (b: bytes) (n: nat) (i: nat): Lemma (requires ( S.length b = 4 * n /\ i < n)) (ensures ( S.index (seq_uint32_of_le n b) i == uint32_of_le (S.slice b (4 * i) (4 * i + 4)))) (decreases ( S.length b)) [ SMTPat (S.index (seq_uint32_of_le n b) i) ] = if S.length b = 0 then false_elim () else let hd, tl = Seq.split b 4 in if i = 0 then () else offset_uint32_le tl (n - 1) (i - 1) [@(deprecated "FStar.Endianness.offset_uint64_be")] let rec offset_uint64_be (b: bytes) (n: nat) (i: nat): Lemma (requires ( S.length b = 8 * n /\ i < n)) (ensures ( S.index (seq_uint64_of_be n b) i == uint64_of_be (S.slice b (8 * i) (8 * i + 8)))) (decreases ( S.length b)) [ SMTPat (S.index (seq_uint64_of_be n b) i) ] = if S.length b = 0 then false_elim () else let hd, tl = Seq.split b 8 in if i = 0 then () else offset_uint64_be tl (n - 1) (i - 1) [@(deprecated "FStar.Endianness.offset_uint64_le")] let rec offset_uint64_le (b: bytes) (n: nat) (i: nat): Lemma (requires ( S.length b = 8 * n /\ i < n)) (ensures ( S.index (seq_uint64_of_le n b) i == uint64_of_le (S.slice b (8 * i) (8 * i + 8)))) (decreases ( S.length b)) [ SMTPat (S.index (seq_uint64_of_le n b) i) ] = if S.length b = 0 then false_elim () else let hd, tl = Seq.split b 8 in if i = 0 then () else offset_uint64_le tl (n - 1) (i - 1) (** Reasoning about endian-ness and words. *) #set-options "--max_fuel 1 --z3rlimit 20" (* TODO: move to FStar.Seq.Properties, with the pattern *) [@(deprecated "FStar.Endianness.tail_cons")] let tail_cons (#a: Type) (hd: a) (tl: S.seq a): Lemma (ensures (S.equal (S.tail (S.cons hd tl)) tl)) // [ SMTPat (S.tail (S.cons hd tl)) ] = ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.All.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "FStar.Krml.Endianness.fst" }
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Math.Lemmas", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Krml", "short_module": null }, { "abbrev": false, "full_module": "FStar.Krml", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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": 1, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s1: FStar.Seq.Base.seq FStar.UInt32.t -> s2: FStar.Seq.Base.seq FStar.UInt32.t -> FStar.Pervasives.Lemma (ensures FStar.Seq.Base.equal (FStar.Krml.Endianness.be_of_seq_uint32 (FStar.Seq.Base.append s1 s2)) (FStar.Seq.Base.append (FStar.Krml.Endianness.be_of_seq_uint32 s1) (FStar.Krml.Endianness.be_of_seq_uint32 s2))) (decreases FStar.Seq.Base.length s1) [ SMTPat (FStar.Seq.Base.append (FStar.Krml.Endianness.be_of_seq_uint32 s1) (FStar.Krml.Endianness.be_of_seq_uint32 s2)) ]
FStar.Pervasives.Lemma
[ "lemma", "" ]
[]
[ "FStar.Seq.Base.seq", "FStar.UInt32.t", "Prims.op_Equality", "Prims.int", "FStar.Seq.Base.length", "Prims.unit", "Prims._assert", "FStar.Seq.Base.equal", "FStar.Seq.Base.append", "FStar.UInt8.t", "FStar.Krml.Endianness.be_of_seq_uint32", "FStar.Seq.Base.empty", "Prims.bool", "FStar.Krml.Endianness.be_of_seq_uint32_append", "FStar.Seq.Properties.tail", "FStar.Krml.Endianness.be_of_uint32", "FStar.Seq.Properties.head", "FStar.Seq.Base.cons", "FStar.Classical.forall_intro_2", "FStar.Krml.Endianness.tail_cons", "Prims.l_True", "Prims.squash", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat", "Prims.Nil" ]
[ "recursion" ]
false
false
true
false
false
let rec be_of_seq_uint32_append (s1 s2: S.seq U32.t) : Lemma (ensures (S.equal (be_of_seq_uint32 (S.append s1 s2)) (S.append (be_of_seq_uint32 s1) (be_of_seq_uint32 s2)))) (decreases (S.length s1)) [SMTPat (S.append (be_of_seq_uint32 s1) (be_of_seq_uint32 s2))] =
Classical.forall_intro_2 (tail_cons #U32.t); if S.length s1 = 0 then (assert (S.equal (be_of_seq_uint32 s1) S.empty); assert (S.equal (S.append s1 s2) s2); ()) else (assert (S.equal (S.append s1 s2) (S.cons (S.head s1) (S.append (S.tail s1) s2))); assert (S.equal (be_of_seq_uint32 (S.append s1 s2)) (S.append (be_of_uint32 (S.head s1)) (be_of_seq_uint32 (S.append (S.tail s1) s2)))); be_of_seq_uint32_append (S.tail s1) s2)
false
FStar.Krml.Endianness.fst
FStar.Krml.Endianness.le_of_seq_uint32_append
val le_of_seq_uint32_append (s1 s2: S.seq U32.t) : Lemma (ensures (S.equal (le_of_seq_uint32 (S.append s1 s2)) (S.append (le_of_seq_uint32 s1) (le_of_seq_uint32 s2)))) (decreases (S.length s1)) [SMTPat (S.append (le_of_seq_uint32 s1) (le_of_seq_uint32 s2))]
val le_of_seq_uint32_append (s1 s2: S.seq U32.t) : Lemma (ensures (S.equal (le_of_seq_uint32 (S.append s1 s2)) (S.append (le_of_seq_uint32 s1) (le_of_seq_uint32 s2)))) (decreases (S.length s1)) [SMTPat (S.append (le_of_seq_uint32 s1) (le_of_seq_uint32 s2))]
let rec le_of_seq_uint32_append (s1 s2: S.seq U32.t): Lemma (ensures ( S.equal (le_of_seq_uint32 (S.append s1 s2)) (S.append (le_of_seq_uint32 s1) (le_of_seq_uint32 s2)))) (decreases ( S.length s1)) [ SMTPat (S.append (le_of_seq_uint32 s1) (le_of_seq_uint32 s2)) ] = Classical.forall_intro_2 (tail_cons #U32.t); // TODO: this is a local pattern, remove once tail_cons lands in FStar.Seq.Properties if S.length s1 = 0 then begin assert (S.equal (le_of_seq_uint32 s1) S.empty); assert (S.equal (S.append s1 s2) s2); () end else begin assert (S.equal (S.append s1 s2) (S.cons (S.head s1) (S.append (S.tail s1) s2))); assert (S.equal (le_of_seq_uint32 (S.append s1 s2)) (S.append (le_of_uint32 (S.head s1)) (le_of_seq_uint32 (S.append (S.tail s1) s2)))); le_of_seq_uint32_append (S.tail s1) s2 end
{ "file_name": "krmllib/FStar.Krml.Endianness.fst", "git_rev": "da1e941b2fcb196aa5d1e34941aa00b4c67ac321", "git_url": "https://github.com/FStarLang/karamel.git", "project_name": "karamel" }
{ "end_col": 5, "end_line": 467, "start_col": 0, "start_line": 449 }
module FStar.Krml.Endianness open FStar.Mul open FStar.HyperStack.All module U8 = FStar.UInt8 module U32 = FStar.UInt32 module U64 = FStar.UInt64 module Math = FStar.Math.Lemmas module S = FStar.Seq (* Selectively imported from Hacl*'s FStar.Endianness.fst library, with several name changes *) inline_for_extraction noextract type bytes = S.seq U8.t /// lt_to_n interprets a byte sequence as a little-endian natural number [@(deprecated "FStar.Endianness.le_to_n")] val le_to_n : b:bytes -> Tot nat (decreases (S.length b)) let rec le_to_n b = if S.length b = 0 then 0 else U8.v (S.head b) + pow2 8 * le_to_n (S.tail b) /// be_to_n interprets a byte sequence as a big-endian natural number [@(deprecated "FStar.Endianness.be_to_n")] val be_to_n : b:bytes -> Tot nat (decreases (S.length b)) let rec be_to_n b = if S.length b = 0 then 0 else U8.v (S.last b) + pow2 8 * be_to_n (S.slice b 0 (S.length b - 1)) [@(deprecated "FStar.Endianness.lemma_euclidean_division")] private val lemma_euclidean_division: r:nat -> b:nat -> q:pos -> Lemma (requires (r < q)) (ensures (r + q * b < q * (b+1))) let lemma_euclidean_division r b q = () [@(deprecated "FStar.Endianness.lemma_factorise")] private val lemma_factorise: a:nat -> b:nat -> Lemma (a + a * b == a * (b + 1)) let lemma_factorise a b = () [@(deprecated "FStar.Endianness.lemma_le_to_n_is_bounded")] val lemma_le_to_n_is_bounded: b:bytes -> Lemma (requires True) (ensures (le_to_n b < pow2 (8 * Seq.length b))) (decreases (Seq.length b)) let rec lemma_le_to_n_is_bounded b = if Seq.length b = 0 then () else begin let s = Seq.slice b 1 (Seq.length b) in assert(Seq.length s = Seq.length b - 1); lemma_le_to_n_is_bounded s; assert(UInt8.v (Seq.index b 0) < pow2 8); assert(le_to_n s < pow2 (8 * Seq.length s)); assert(le_to_n b < pow2 8 + pow2 8 * pow2 (8 * (Seq.length b - 1))); lemma_euclidean_division (UInt8.v (Seq.index b 0)) (le_to_n s) (pow2 8); assert(le_to_n b <= pow2 8 * (le_to_n s + 1)); assert(le_to_n b <= pow2 8 * pow2 (8 * (Seq.length b - 1))); Math.Lemmas.pow2_plus 8 (8 * (Seq.length b - 1)); lemma_factorise 8 (Seq.length b - 1) end [@(deprecated "FStar.Endianness.lemma_be_to_n_is_bounded")] val lemma_be_to_n_is_bounded: b:bytes -> Lemma (requires True) (ensures (be_to_n b < pow2 (8 * Seq.length b))) (decreases (Seq.length b)) let rec lemma_be_to_n_is_bounded b = if Seq.length b = 0 then () else begin let s = Seq.slice b 0 (Seq.length b - 1) in assert(Seq.length s = Seq.length b - 1); lemma_be_to_n_is_bounded s; assert(UInt8.v (Seq.last b) < pow2 8); assert(be_to_n s < pow2 (8 * Seq.length s)); assert(be_to_n b < pow2 8 + pow2 8 * pow2 (8 * (Seq.length b - 1))); lemma_euclidean_division (UInt8.v (Seq.last b)) (be_to_n s) (pow2 8); assert(be_to_n b <= pow2 8 * (be_to_n s + 1)); assert(be_to_n b <= pow2 8 * pow2 (8 * (Seq.length b - 1))); Math.Lemmas.pow2_plus 8 (8 * (Seq.length b - 1)); lemma_factorise 8 (Seq.length b - 1) end /// n_to_le encodes a number as a little-endian byte sequence of a fixed, /// sufficiently large length [@(deprecated "FStar.Endianness.n_to_le")] val n_to_le : len:U32.t -> n:nat{n < pow2 (8 * U32.v len)} -> Tot (b:bytes{S.length b == U32.v len /\ n == le_to_n b}) (decreases (U32.v len)) let rec n_to_le len n = if len = 0ul then S.empty else let len = U32.(len -^ 1ul) in let byte = U8.uint_to_t (n % 256) in let n' = n / 256 in Math.pow2_plus 8 (8 * U32.v len); assert(n' < pow2 (8 * U32.v len )); let b' = n_to_le len n' in let b = S.cons byte b' in S.lemma_eq_intro b' (S.tail b); b /// n_to_be encodes a numbers as a big-endian byte sequence of a fixed, /// sufficiently large length [@(deprecated "FStar.Endianness.n_to_be")] val n_to_be: len:U32.t -> n:nat{n < pow2 (8 * U32.v len)} -> Tot (b:bytes{S.length b == U32.v len /\ n == be_to_n b}) (decreases (U32.v len)) let rec n_to_be len n = if len = 0ul then S.empty else let len = U32.(len -^ 1ul) in let byte = U8.uint_to_t (n % 256) in let n' = n / 256 in Math.pow2_plus 8 (8 * U32.v len); assert(n' < pow2 (8 * U32.v len )); let b' = n_to_be len n' in let b'' = S.create 1 byte in let b = S.append b' b'' in S.lemma_eq_intro b' (S.slice b 0 (U32.v len)); b [@(deprecated "FStar.Endianness.n_to_le_inj")] let n_to_le_inj (len:U32.t) (n1 n2: (n:nat{n < pow2 (8 * U32.v len)})) : Lemma (requires (n_to_le len n1 == n_to_le len n2)) (ensures (n1 == n2)) = // this lemma easily follows from le_to_n . (n_to_le len) == id, the inversion // proof in the spec for n_to_le () [@(deprecated "FStar.Endianness.n_to_be_inj")] let n_to_be_inj (len:U32.t) (n1 n2: (n:nat{n < pow2 (8 * U32.v len)})) : Lemma (requires (n_to_be len n1 == n_to_be len n2)) (ensures (n1 == n2)) = () [@(deprecated "FStar.Endianness.be_to_n_inj")] let rec be_to_n_inj (b1 b2: Seq.seq U8.t) : Lemma (requires (Seq.length b1 == Seq.length b2 /\ be_to_n b1 == be_to_n b2)) (ensures (Seq.equal b1 b2)) (decreases (Seq.length b1)) = if Seq.length b1 = 0 then () else begin be_to_n_inj (Seq.slice b1 0 (Seq.length b1 - 1)) (Seq.slice b2 0 (Seq.length b2 - 1)); Seq.lemma_split b1 (Seq.length b1 - 1); Seq.lemma_split b2 (Seq.length b2 - 1) end [@(deprecated "FStar.Endianness.le_to_n_inj")] let rec le_to_n_inj (b1 b2: Seq.seq U8.t) : Lemma (requires (Seq.length b1 == Seq.length b2 /\ le_to_n b1 == le_to_n b2)) (ensures (Seq.equal b1 b2)) (decreases (Seq.length b1)) = if Seq.length b1 = 0 then () else begin le_to_n_inj (Seq.slice b1 1 (Seq.length b1)) (Seq.slice b2 1 (Seq.length b2)); Seq.lemma_split b1 1; Seq.lemma_split b2 1 end [@(deprecated "FStar.Endianness.n_to_be_be_to_n")] let n_to_be_be_to_n (len: U32.t) (s: Seq.seq U8.t) : Lemma (requires (Seq.length s == U32.v len)) (ensures ( be_to_n s < pow2 (8 `Prims.op_Multiply` U32.v len) /\ n_to_be len (be_to_n s) == s )) [SMTPat (n_to_be len (be_to_n s))] = lemma_be_to_n_is_bounded s; be_to_n_inj s (n_to_be len (be_to_n s)) [@(deprecated "FStar.Endianness.n_to_le_le_to_n")] let n_to_le_le_to_n (len: U32.t) (s: Seq.seq U8.t) : Lemma (requires (Seq.length s == U32.v len)) (ensures ( le_to_n s < pow2 (8 `Prims.op_Multiply` U32.v len) /\ n_to_le len (le_to_n s) == s )) [SMTPat (n_to_le len (le_to_n s))] = lemma_le_to_n_is_bounded s; le_to_n_inj s (n_to_le len (le_to_n s)) (** A series of specializations to deal with machine integers *) [@(deprecated "FStar.Endianness.uint32_of_le")] let uint32_of_le (b: bytes { S.length b = 4 }) = let n = le_to_n b in lemma_le_to_n_is_bounded b; UInt32.uint_to_t n [@(deprecated "FStar.Endianness.le_of_uint32")] let le_of_uint32 (x: UInt32.t): b:bytes{ S.length b = 4 } = n_to_le 4ul (UInt32.v x) [@(deprecated "FStar.Endianness.uint32_of_be")] let uint32_of_be (b: bytes { S.length b = 4 }) = let n = be_to_n b in lemma_be_to_n_is_bounded b; UInt32.uint_to_t n [@(deprecated "FStar.Endianness.be_of_uint32")] let be_of_uint32 (x: UInt32.t): b:bytes{ S.length b = 4 } = n_to_be 4ul (UInt32.v x) [@(deprecated "FStar.Endianness.uint64_of_le")] let uint64_of_le (b: bytes { S.length b = 8 }) = let n = le_to_n b in lemma_le_to_n_is_bounded b; UInt64.uint_to_t n [@(deprecated "FStar.Endianness.le_of_uint64")] let le_of_uint64 (x: UInt64.t): b:bytes{ S.length b = 8 } = n_to_le 8ul (UInt64.v x) [@(deprecated "FStar.Endianness.uint64_of_be")] let uint64_of_be (b: bytes { S.length b = 8 }) = let n = be_to_n b in lemma_be_to_n_is_bounded b; UInt64.uint_to_t n [@(deprecated "FStar.Endianness.be_of_uint64")] let be_of_uint64 (x: UInt64.t): b:bytes{ S.length b = 8 } = n_to_be 8ul (UInt64.v x) [@(deprecated "FStar.Endianness.seq_uint32_of_le")] let rec seq_uint32_of_le (l: nat) (b: bytes{ S.length b = 4 * l }): s:S.seq UInt32.t { S.length s = l } = if S.length b = 0 then S.empty else let hd, tl = Seq.split b 4 in S.cons (uint32_of_le hd) (seq_uint32_of_le (l - 1) tl) [@(deprecated "FStar.Endianness.le_of_seq_uint32")] let rec le_of_seq_uint32 (s: S.seq UInt32.t): Tot (b:bytes { S.length b = 4 * S.length s }) (decreases (S.length s)) = if S.length s = 0 then S.empty else S.append (le_of_uint32 (S.head s)) (le_of_seq_uint32 (S.tail s)) [@(deprecated "FStar.Endianness.seq_uint32_of_be")] let rec seq_uint32_of_be (l: nat) (b: bytes{ S.length b = 4 * l }): s:S.seq UInt32.t { S.length s = l } = if S.length b = 0 then S.empty else let hd, tl = Seq.split b 4 in S.cons (uint32_of_be hd) (seq_uint32_of_be (l - 1) tl) [@(deprecated "FStar.Endianness.be_of_seq_uint32")] let rec be_of_seq_uint32 (s: S.seq UInt32.t): Tot (b:bytes { S.length b = 4 * S.length s }) (decreases (S.length s)) = if S.length s = 0 then S.empty else S.append (be_of_uint32 (S.head s)) (be_of_seq_uint32 (S.tail s)) [@(deprecated "FStar.Endianness.seq_uint64_of_le")] let rec seq_uint64_of_le (l: nat) (b: bytes{ S.length b = 8 * l }): s:S.seq UInt64.t { S.length s = l } = if S.length b = 0 then S.empty else let hd, tl = Seq.split b 8 in S.cons (uint64_of_le hd) (seq_uint64_of_le (l - 1) tl) [@(deprecated "FStar.Endianness.le_of_seq_uint64")] let rec le_of_seq_uint64 (s: S.seq UInt64.t): Tot (b:bytes { S.length b = 8 * S.length s }) (decreases (S.length s)) = if S.length s = 0 then S.empty else S.append (le_of_uint64 (S.head s)) (le_of_seq_uint64 (S.tail s)) [@(deprecated "FStar.Endianness.seq_uint64_of_be")] let rec seq_uint64_of_be (l: nat) (b: bytes{ S.length b = 8 * l }): s:S.seq UInt64.t { S.length s = l } = if S.length b = 0 then S.empty else let hd, tl = Seq.split b 8 in S.cons (uint64_of_be hd) (seq_uint64_of_be (l - 1) tl) [@(deprecated "FStar.Endianness.be_of_seq_uint64")] let rec be_of_seq_uint64 (s: S.seq UInt64.t): Tot (b:bytes { S.length b = 8 * S.length s }) (decreases (S.length s)) = if S.length s = 0 then S.empty else S.append (be_of_uint64 (S.head s)) (be_of_seq_uint64 (S.tail s)) #set-options "--max_fuel 1 --max_ifuel 0 --z3rlimit 50" [@(deprecated "FStar.Endianness.offset_uint32_be")] let rec offset_uint32_be (b: bytes) (n: nat) (i: nat): Lemma (requires ( S.length b = 4 * n /\ i < n)) (ensures ( S.index (seq_uint32_of_be n b) i == uint32_of_be (S.slice b (4 * i) (4 * i + 4)))) (decreases ( S.length b)) [ SMTPat (S.index (seq_uint32_of_be n b) i) ] = if S.length b = 0 then false_elim () else let hd, tl = Seq.split b 4 in if i = 0 then () else offset_uint32_be tl (n - 1) (i - 1) [@(deprecated "FStar.Endianness.offset_uint32_le")] let rec offset_uint32_le (b: bytes) (n: nat) (i: nat): Lemma (requires ( S.length b = 4 * n /\ i < n)) (ensures ( S.index (seq_uint32_of_le n b) i == uint32_of_le (S.slice b (4 * i) (4 * i + 4)))) (decreases ( S.length b)) [ SMTPat (S.index (seq_uint32_of_le n b) i) ] = if S.length b = 0 then false_elim () else let hd, tl = Seq.split b 4 in if i = 0 then () else offset_uint32_le tl (n - 1) (i - 1) [@(deprecated "FStar.Endianness.offset_uint64_be")] let rec offset_uint64_be (b: bytes) (n: nat) (i: nat): Lemma (requires ( S.length b = 8 * n /\ i < n)) (ensures ( S.index (seq_uint64_of_be n b) i == uint64_of_be (S.slice b (8 * i) (8 * i + 8)))) (decreases ( S.length b)) [ SMTPat (S.index (seq_uint64_of_be n b) i) ] = if S.length b = 0 then false_elim () else let hd, tl = Seq.split b 8 in if i = 0 then () else offset_uint64_be tl (n - 1) (i - 1) [@(deprecated "FStar.Endianness.offset_uint64_le")] let rec offset_uint64_le (b: bytes) (n: nat) (i: nat): Lemma (requires ( S.length b = 8 * n /\ i < n)) (ensures ( S.index (seq_uint64_of_le n b) i == uint64_of_le (S.slice b (8 * i) (8 * i + 8)))) (decreases ( S.length b)) [ SMTPat (S.index (seq_uint64_of_le n b) i) ] = if S.length b = 0 then false_elim () else let hd, tl = Seq.split b 8 in if i = 0 then () else offset_uint64_le tl (n - 1) (i - 1) (** Reasoning about endian-ness and words. *) #set-options "--max_fuel 1 --z3rlimit 20" (* TODO: move to FStar.Seq.Properties, with the pattern *) [@(deprecated "FStar.Endianness.tail_cons")] let tail_cons (#a: Type) (hd: a) (tl: S.seq a): Lemma (ensures (S.equal (S.tail (S.cons hd tl)) tl)) // [ SMTPat (S.tail (S.cons hd tl)) ] = () [@(deprecated "FStar.Endianness.be_of_seq_uint32_append")] let rec be_of_seq_uint32_append (s1 s2: S.seq U32.t): Lemma (ensures ( S.equal (be_of_seq_uint32 (S.append s1 s2)) (S.append (be_of_seq_uint32 s1) (be_of_seq_uint32 s2)))) (decreases ( S.length s1)) [ SMTPat (S.append (be_of_seq_uint32 s1) (be_of_seq_uint32 s2)) ] = Classical.forall_intro_2 (tail_cons #U32.t); // TODO: this is a local pattern, remove once tail_cons lands in FStar.Seq.Properties if S.length s1 = 0 then begin assert (S.equal (be_of_seq_uint32 s1) S.empty); assert (S.equal (S.append s1 s2) s2); () end else begin assert (S.equal (S.append s1 s2) (S.cons (S.head s1) (S.append (S.tail s1) s2))); assert (S.equal (be_of_seq_uint32 (S.append s1 s2)) (S.append (be_of_uint32 (S.head s1)) (be_of_seq_uint32 (S.append (S.tail s1) s2)))); be_of_seq_uint32_append (S.tail s1) s2 end [@(deprecated "FStar.Endianness.be_of_seq_uint32_base")] let be_of_seq_uint32_base (s1: S.seq U32.t) (s2: S.seq U8.t): Lemma (requires ( S.length s1 = 1 /\ S.length s2 = 4 /\ be_to_n s2 = U32.v (S.index s1 0))) (ensures (S.equal s2 (be_of_seq_uint32 s1))) [ SMTPat (be_to_n s2 = U32.v (S.index s1 0)) ] = ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.All.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "FStar.Krml.Endianness.fst" }
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Math.Lemmas", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Krml", "short_module": null }, { "abbrev": false, "full_module": "FStar.Krml", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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": 1, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s1: FStar.Seq.Base.seq FStar.UInt32.t -> s2: FStar.Seq.Base.seq FStar.UInt32.t -> FStar.Pervasives.Lemma (ensures FStar.Seq.Base.equal (FStar.Krml.Endianness.le_of_seq_uint32 (FStar.Seq.Base.append s1 s2)) (FStar.Seq.Base.append (FStar.Krml.Endianness.le_of_seq_uint32 s1) (FStar.Krml.Endianness.le_of_seq_uint32 s2))) (decreases FStar.Seq.Base.length s1) [ SMTPat (FStar.Seq.Base.append (FStar.Krml.Endianness.le_of_seq_uint32 s1) (FStar.Krml.Endianness.le_of_seq_uint32 s2)) ]
FStar.Pervasives.Lemma
[ "lemma", "" ]
[]
[ "FStar.Seq.Base.seq", "FStar.UInt32.t", "Prims.op_Equality", "Prims.int", "FStar.Seq.Base.length", "Prims.unit", "Prims._assert", "FStar.Seq.Base.equal", "FStar.Seq.Base.append", "FStar.UInt8.t", "FStar.Krml.Endianness.le_of_seq_uint32", "FStar.Seq.Base.empty", "Prims.bool", "FStar.Krml.Endianness.le_of_seq_uint32_append", "FStar.Seq.Properties.tail", "FStar.Krml.Endianness.le_of_uint32", "FStar.Seq.Properties.head", "FStar.Seq.Base.cons", "FStar.Classical.forall_intro_2", "FStar.Krml.Endianness.tail_cons", "Prims.l_True", "Prims.squash", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat", "Prims.Nil" ]
[ "recursion" ]
false
false
true
false
false
let rec le_of_seq_uint32_append (s1 s2: S.seq U32.t) : Lemma (ensures (S.equal (le_of_seq_uint32 (S.append s1 s2)) (S.append (le_of_seq_uint32 s1) (le_of_seq_uint32 s2)))) (decreases (S.length s1)) [SMTPat (S.append (le_of_seq_uint32 s1) (le_of_seq_uint32 s2))] =
Classical.forall_intro_2 (tail_cons #U32.t); if S.length s1 = 0 then (assert (S.equal (le_of_seq_uint32 s1) S.empty); assert (S.equal (S.append s1 s2) s2); ()) else (assert (S.equal (S.append s1 s2) (S.cons (S.head s1) (S.append (S.tail s1) s2))); assert (S.equal (le_of_seq_uint32 (S.append s1 s2)) (S.append (le_of_uint32 (S.head s1)) (le_of_seq_uint32 (S.append (S.tail s1) s2)))); le_of_seq_uint32_append (S.tail s1) s2)
false
FStar.Krml.Endianness.fst
FStar.Krml.Endianness.be_of_seq_uint64_append
val be_of_seq_uint64_append (s1 s2: S.seq U64.t) : Lemma (ensures (S.equal (be_of_seq_uint64 (S.append s1 s2)) (S.append (be_of_seq_uint64 s1) (be_of_seq_uint64 s2)))) (decreases (S.length s1)) [SMTPat (S.append (be_of_seq_uint64 s1) (be_of_seq_uint64 s2))]
val be_of_seq_uint64_append (s1 s2: S.seq U64.t) : Lemma (ensures (S.equal (be_of_seq_uint64 (S.append s1 s2)) (S.append (be_of_seq_uint64 s1) (be_of_seq_uint64 s2)))) (decreases (S.length s1)) [SMTPat (S.append (be_of_seq_uint64 s1) (be_of_seq_uint64 s2))]
let rec be_of_seq_uint64_append (s1 s2: S.seq U64.t): Lemma (ensures ( S.equal (be_of_seq_uint64 (S.append s1 s2)) (S.append (be_of_seq_uint64 s1) (be_of_seq_uint64 s2)))) (decreases ( S.length s1)) [ SMTPat (S.append (be_of_seq_uint64 s1) (be_of_seq_uint64 s2)) ] = Classical.forall_intro_2 (tail_cons #U64.t); // TODO: this is a local pattern, remove once tail_cons lands in FStar.Seq.Properties if S.length s1 = 0 then begin assert (S.equal (be_of_seq_uint64 s1) S.empty); assert (S.equal (S.append s1 s2) s2); () end else begin assert (S.equal (S.append s1 s2) (S.cons (S.head s1) (S.append (S.tail s1) s2))); assert (S.equal (be_of_seq_uint64 (S.append s1 s2)) (S.append (be_of_uint64 (S.head s1)) (be_of_seq_uint64 (S.append (S.tail s1) s2)))); be_of_seq_uint64_append (S.tail s1) s2 end
{ "file_name": "krmllib/FStar.Krml.Endianness.fst", "git_rev": "da1e941b2fcb196aa5d1e34941aa00b4c67ac321", "git_url": "https://github.com/FStarLang/karamel.git", "project_name": "karamel" }
{ "end_col": 5, "end_line": 499, "start_col": 0, "start_line": 481 }
module FStar.Krml.Endianness open FStar.Mul open FStar.HyperStack.All module U8 = FStar.UInt8 module U32 = FStar.UInt32 module U64 = FStar.UInt64 module Math = FStar.Math.Lemmas module S = FStar.Seq (* Selectively imported from Hacl*'s FStar.Endianness.fst library, with several name changes *) inline_for_extraction noextract type bytes = S.seq U8.t /// lt_to_n interprets a byte sequence as a little-endian natural number [@(deprecated "FStar.Endianness.le_to_n")] val le_to_n : b:bytes -> Tot nat (decreases (S.length b)) let rec le_to_n b = if S.length b = 0 then 0 else U8.v (S.head b) + pow2 8 * le_to_n (S.tail b) /// be_to_n interprets a byte sequence as a big-endian natural number [@(deprecated "FStar.Endianness.be_to_n")] val be_to_n : b:bytes -> Tot nat (decreases (S.length b)) let rec be_to_n b = if S.length b = 0 then 0 else U8.v (S.last b) + pow2 8 * be_to_n (S.slice b 0 (S.length b - 1)) [@(deprecated "FStar.Endianness.lemma_euclidean_division")] private val lemma_euclidean_division: r:nat -> b:nat -> q:pos -> Lemma (requires (r < q)) (ensures (r + q * b < q * (b+1))) let lemma_euclidean_division r b q = () [@(deprecated "FStar.Endianness.lemma_factorise")] private val lemma_factorise: a:nat -> b:nat -> Lemma (a + a * b == a * (b + 1)) let lemma_factorise a b = () [@(deprecated "FStar.Endianness.lemma_le_to_n_is_bounded")] val lemma_le_to_n_is_bounded: b:bytes -> Lemma (requires True) (ensures (le_to_n b < pow2 (8 * Seq.length b))) (decreases (Seq.length b)) let rec lemma_le_to_n_is_bounded b = if Seq.length b = 0 then () else begin let s = Seq.slice b 1 (Seq.length b) in assert(Seq.length s = Seq.length b - 1); lemma_le_to_n_is_bounded s; assert(UInt8.v (Seq.index b 0) < pow2 8); assert(le_to_n s < pow2 (8 * Seq.length s)); assert(le_to_n b < pow2 8 + pow2 8 * pow2 (8 * (Seq.length b - 1))); lemma_euclidean_division (UInt8.v (Seq.index b 0)) (le_to_n s) (pow2 8); assert(le_to_n b <= pow2 8 * (le_to_n s + 1)); assert(le_to_n b <= pow2 8 * pow2 (8 * (Seq.length b - 1))); Math.Lemmas.pow2_plus 8 (8 * (Seq.length b - 1)); lemma_factorise 8 (Seq.length b - 1) end [@(deprecated "FStar.Endianness.lemma_be_to_n_is_bounded")] val lemma_be_to_n_is_bounded: b:bytes -> Lemma (requires True) (ensures (be_to_n b < pow2 (8 * Seq.length b))) (decreases (Seq.length b)) let rec lemma_be_to_n_is_bounded b = if Seq.length b = 0 then () else begin let s = Seq.slice b 0 (Seq.length b - 1) in assert(Seq.length s = Seq.length b - 1); lemma_be_to_n_is_bounded s; assert(UInt8.v (Seq.last b) < pow2 8); assert(be_to_n s < pow2 (8 * Seq.length s)); assert(be_to_n b < pow2 8 + pow2 8 * pow2 (8 * (Seq.length b - 1))); lemma_euclidean_division (UInt8.v (Seq.last b)) (be_to_n s) (pow2 8); assert(be_to_n b <= pow2 8 * (be_to_n s + 1)); assert(be_to_n b <= pow2 8 * pow2 (8 * (Seq.length b - 1))); Math.Lemmas.pow2_plus 8 (8 * (Seq.length b - 1)); lemma_factorise 8 (Seq.length b - 1) end /// n_to_le encodes a number as a little-endian byte sequence of a fixed, /// sufficiently large length [@(deprecated "FStar.Endianness.n_to_le")] val n_to_le : len:U32.t -> n:nat{n < pow2 (8 * U32.v len)} -> Tot (b:bytes{S.length b == U32.v len /\ n == le_to_n b}) (decreases (U32.v len)) let rec n_to_le len n = if len = 0ul then S.empty else let len = U32.(len -^ 1ul) in let byte = U8.uint_to_t (n % 256) in let n' = n / 256 in Math.pow2_plus 8 (8 * U32.v len); assert(n' < pow2 (8 * U32.v len )); let b' = n_to_le len n' in let b = S.cons byte b' in S.lemma_eq_intro b' (S.tail b); b /// n_to_be encodes a numbers as a big-endian byte sequence of a fixed, /// sufficiently large length [@(deprecated "FStar.Endianness.n_to_be")] val n_to_be: len:U32.t -> n:nat{n < pow2 (8 * U32.v len)} -> Tot (b:bytes{S.length b == U32.v len /\ n == be_to_n b}) (decreases (U32.v len)) let rec n_to_be len n = if len = 0ul then S.empty else let len = U32.(len -^ 1ul) in let byte = U8.uint_to_t (n % 256) in let n' = n / 256 in Math.pow2_plus 8 (8 * U32.v len); assert(n' < pow2 (8 * U32.v len )); let b' = n_to_be len n' in let b'' = S.create 1 byte in let b = S.append b' b'' in S.lemma_eq_intro b' (S.slice b 0 (U32.v len)); b [@(deprecated "FStar.Endianness.n_to_le_inj")] let n_to_le_inj (len:U32.t) (n1 n2: (n:nat{n < pow2 (8 * U32.v len)})) : Lemma (requires (n_to_le len n1 == n_to_le len n2)) (ensures (n1 == n2)) = // this lemma easily follows from le_to_n . (n_to_le len) == id, the inversion // proof in the spec for n_to_le () [@(deprecated "FStar.Endianness.n_to_be_inj")] let n_to_be_inj (len:U32.t) (n1 n2: (n:nat{n < pow2 (8 * U32.v len)})) : Lemma (requires (n_to_be len n1 == n_to_be len n2)) (ensures (n1 == n2)) = () [@(deprecated "FStar.Endianness.be_to_n_inj")] let rec be_to_n_inj (b1 b2: Seq.seq U8.t) : Lemma (requires (Seq.length b1 == Seq.length b2 /\ be_to_n b1 == be_to_n b2)) (ensures (Seq.equal b1 b2)) (decreases (Seq.length b1)) = if Seq.length b1 = 0 then () else begin be_to_n_inj (Seq.slice b1 0 (Seq.length b1 - 1)) (Seq.slice b2 0 (Seq.length b2 - 1)); Seq.lemma_split b1 (Seq.length b1 - 1); Seq.lemma_split b2 (Seq.length b2 - 1) end [@(deprecated "FStar.Endianness.le_to_n_inj")] let rec le_to_n_inj (b1 b2: Seq.seq U8.t) : Lemma (requires (Seq.length b1 == Seq.length b2 /\ le_to_n b1 == le_to_n b2)) (ensures (Seq.equal b1 b2)) (decreases (Seq.length b1)) = if Seq.length b1 = 0 then () else begin le_to_n_inj (Seq.slice b1 1 (Seq.length b1)) (Seq.slice b2 1 (Seq.length b2)); Seq.lemma_split b1 1; Seq.lemma_split b2 1 end [@(deprecated "FStar.Endianness.n_to_be_be_to_n")] let n_to_be_be_to_n (len: U32.t) (s: Seq.seq U8.t) : Lemma (requires (Seq.length s == U32.v len)) (ensures ( be_to_n s < pow2 (8 `Prims.op_Multiply` U32.v len) /\ n_to_be len (be_to_n s) == s )) [SMTPat (n_to_be len (be_to_n s))] = lemma_be_to_n_is_bounded s; be_to_n_inj s (n_to_be len (be_to_n s)) [@(deprecated "FStar.Endianness.n_to_le_le_to_n")] let n_to_le_le_to_n (len: U32.t) (s: Seq.seq U8.t) : Lemma (requires (Seq.length s == U32.v len)) (ensures ( le_to_n s < pow2 (8 `Prims.op_Multiply` U32.v len) /\ n_to_le len (le_to_n s) == s )) [SMTPat (n_to_le len (le_to_n s))] = lemma_le_to_n_is_bounded s; le_to_n_inj s (n_to_le len (le_to_n s)) (** A series of specializations to deal with machine integers *) [@(deprecated "FStar.Endianness.uint32_of_le")] let uint32_of_le (b: bytes { S.length b = 4 }) = let n = le_to_n b in lemma_le_to_n_is_bounded b; UInt32.uint_to_t n [@(deprecated "FStar.Endianness.le_of_uint32")] let le_of_uint32 (x: UInt32.t): b:bytes{ S.length b = 4 } = n_to_le 4ul (UInt32.v x) [@(deprecated "FStar.Endianness.uint32_of_be")] let uint32_of_be (b: bytes { S.length b = 4 }) = let n = be_to_n b in lemma_be_to_n_is_bounded b; UInt32.uint_to_t n [@(deprecated "FStar.Endianness.be_of_uint32")] let be_of_uint32 (x: UInt32.t): b:bytes{ S.length b = 4 } = n_to_be 4ul (UInt32.v x) [@(deprecated "FStar.Endianness.uint64_of_le")] let uint64_of_le (b: bytes { S.length b = 8 }) = let n = le_to_n b in lemma_le_to_n_is_bounded b; UInt64.uint_to_t n [@(deprecated "FStar.Endianness.le_of_uint64")] let le_of_uint64 (x: UInt64.t): b:bytes{ S.length b = 8 } = n_to_le 8ul (UInt64.v x) [@(deprecated "FStar.Endianness.uint64_of_be")] let uint64_of_be (b: bytes { S.length b = 8 }) = let n = be_to_n b in lemma_be_to_n_is_bounded b; UInt64.uint_to_t n [@(deprecated "FStar.Endianness.be_of_uint64")] let be_of_uint64 (x: UInt64.t): b:bytes{ S.length b = 8 } = n_to_be 8ul (UInt64.v x) [@(deprecated "FStar.Endianness.seq_uint32_of_le")] let rec seq_uint32_of_le (l: nat) (b: bytes{ S.length b = 4 * l }): s:S.seq UInt32.t { S.length s = l } = if S.length b = 0 then S.empty else let hd, tl = Seq.split b 4 in S.cons (uint32_of_le hd) (seq_uint32_of_le (l - 1) tl) [@(deprecated "FStar.Endianness.le_of_seq_uint32")] let rec le_of_seq_uint32 (s: S.seq UInt32.t): Tot (b:bytes { S.length b = 4 * S.length s }) (decreases (S.length s)) = if S.length s = 0 then S.empty else S.append (le_of_uint32 (S.head s)) (le_of_seq_uint32 (S.tail s)) [@(deprecated "FStar.Endianness.seq_uint32_of_be")] let rec seq_uint32_of_be (l: nat) (b: bytes{ S.length b = 4 * l }): s:S.seq UInt32.t { S.length s = l } = if S.length b = 0 then S.empty else let hd, tl = Seq.split b 4 in S.cons (uint32_of_be hd) (seq_uint32_of_be (l - 1) tl) [@(deprecated "FStar.Endianness.be_of_seq_uint32")] let rec be_of_seq_uint32 (s: S.seq UInt32.t): Tot (b:bytes { S.length b = 4 * S.length s }) (decreases (S.length s)) = if S.length s = 0 then S.empty else S.append (be_of_uint32 (S.head s)) (be_of_seq_uint32 (S.tail s)) [@(deprecated "FStar.Endianness.seq_uint64_of_le")] let rec seq_uint64_of_le (l: nat) (b: bytes{ S.length b = 8 * l }): s:S.seq UInt64.t { S.length s = l } = if S.length b = 0 then S.empty else let hd, tl = Seq.split b 8 in S.cons (uint64_of_le hd) (seq_uint64_of_le (l - 1) tl) [@(deprecated "FStar.Endianness.le_of_seq_uint64")] let rec le_of_seq_uint64 (s: S.seq UInt64.t): Tot (b:bytes { S.length b = 8 * S.length s }) (decreases (S.length s)) = if S.length s = 0 then S.empty else S.append (le_of_uint64 (S.head s)) (le_of_seq_uint64 (S.tail s)) [@(deprecated "FStar.Endianness.seq_uint64_of_be")] let rec seq_uint64_of_be (l: nat) (b: bytes{ S.length b = 8 * l }): s:S.seq UInt64.t { S.length s = l } = if S.length b = 0 then S.empty else let hd, tl = Seq.split b 8 in S.cons (uint64_of_be hd) (seq_uint64_of_be (l - 1) tl) [@(deprecated "FStar.Endianness.be_of_seq_uint64")] let rec be_of_seq_uint64 (s: S.seq UInt64.t): Tot (b:bytes { S.length b = 8 * S.length s }) (decreases (S.length s)) = if S.length s = 0 then S.empty else S.append (be_of_uint64 (S.head s)) (be_of_seq_uint64 (S.tail s)) #set-options "--max_fuel 1 --max_ifuel 0 --z3rlimit 50" [@(deprecated "FStar.Endianness.offset_uint32_be")] let rec offset_uint32_be (b: bytes) (n: nat) (i: nat): Lemma (requires ( S.length b = 4 * n /\ i < n)) (ensures ( S.index (seq_uint32_of_be n b) i == uint32_of_be (S.slice b (4 * i) (4 * i + 4)))) (decreases ( S.length b)) [ SMTPat (S.index (seq_uint32_of_be n b) i) ] = if S.length b = 0 then false_elim () else let hd, tl = Seq.split b 4 in if i = 0 then () else offset_uint32_be tl (n - 1) (i - 1) [@(deprecated "FStar.Endianness.offset_uint32_le")] let rec offset_uint32_le (b: bytes) (n: nat) (i: nat): Lemma (requires ( S.length b = 4 * n /\ i < n)) (ensures ( S.index (seq_uint32_of_le n b) i == uint32_of_le (S.slice b (4 * i) (4 * i + 4)))) (decreases ( S.length b)) [ SMTPat (S.index (seq_uint32_of_le n b) i) ] = if S.length b = 0 then false_elim () else let hd, tl = Seq.split b 4 in if i = 0 then () else offset_uint32_le tl (n - 1) (i - 1) [@(deprecated "FStar.Endianness.offset_uint64_be")] let rec offset_uint64_be (b: bytes) (n: nat) (i: nat): Lemma (requires ( S.length b = 8 * n /\ i < n)) (ensures ( S.index (seq_uint64_of_be n b) i == uint64_of_be (S.slice b (8 * i) (8 * i + 8)))) (decreases ( S.length b)) [ SMTPat (S.index (seq_uint64_of_be n b) i) ] = if S.length b = 0 then false_elim () else let hd, tl = Seq.split b 8 in if i = 0 then () else offset_uint64_be tl (n - 1) (i - 1) [@(deprecated "FStar.Endianness.offset_uint64_le")] let rec offset_uint64_le (b: bytes) (n: nat) (i: nat): Lemma (requires ( S.length b = 8 * n /\ i < n)) (ensures ( S.index (seq_uint64_of_le n b) i == uint64_of_le (S.slice b (8 * i) (8 * i + 8)))) (decreases ( S.length b)) [ SMTPat (S.index (seq_uint64_of_le n b) i) ] = if S.length b = 0 then false_elim () else let hd, tl = Seq.split b 8 in if i = 0 then () else offset_uint64_le tl (n - 1) (i - 1) (** Reasoning about endian-ness and words. *) #set-options "--max_fuel 1 --z3rlimit 20" (* TODO: move to FStar.Seq.Properties, with the pattern *) [@(deprecated "FStar.Endianness.tail_cons")] let tail_cons (#a: Type) (hd: a) (tl: S.seq a): Lemma (ensures (S.equal (S.tail (S.cons hd tl)) tl)) // [ SMTPat (S.tail (S.cons hd tl)) ] = () [@(deprecated "FStar.Endianness.be_of_seq_uint32_append")] let rec be_of_seq_uint32_append (s1 s2: S.seq U32.t): Lemma (ensures ( S.equal (be_of_seq_uint32 (S.append s1 s2)) (S.append (be_of_seq_uint32 s1) (be_of_seq_uint32 s2)))) (decreases ( S.length s1)) [ SMTPat (S.append (be_of_seq_uint32 s1) (be_of_seq_uint32 s2)) ] = Classical.forall_intro_2 (tail_cons #U32.t); // TODO: this is a local pattern, remove once tail_cons lands in FStar.Seq.Properties if S.length s1 = 0 then begin assert (S.equal (be_of_seq_uint32 s1) S.empty); assert (S.equal (S.append s1 s2) s2); () end else begin assert (S.equal (S.append s1 s2) (S.cons (S.head s1) (S.append (S.tail s1) s2))); assert (S.equal (be_of_seq_uint32 (S.append s1 s2)) (S.append (be_of_uint32 (S.head s1)) (be_of_seq_uint32 (S.append (S.tail s1) s2)))); be_of_seq_uint32_append (S.tail s1) s2 end [@(deprecated "FStar.Endianness.be_of_seq_uint32_base")] let be_of_seq_uint32_base (s1: S.seq U32.t) (s2: S.seq U8.t): Lemma (requires ( S.length s1 = 1 /\ S.length s2 = 4 /\ be_to_n s2 = U32.v (S.index s1 0))) (ensures (S.equal s2 (be_of_seq_uint32 s1))) [ SMTPat (be_to_n s2 = U32.v (S.index s1 0)) ] = () [@(deprecated "FStar.Endianness.le_of_seq_uint32_append")] let rec le_of_seq_uint32_append (s1 s2: S.seq U32.t): Lemma (ensures ( S.equal (le_of_seq_uint32 (S.append s1 s2)) (S.append (le_of_seq_uint32 s1) (le_of_seq_uint32 s2)))) (decreases ( S.length s1)) [ SMTPat (S.append (le_of_seq_uint32 s1) (le_of_seq_uint32 s2)) ] = Classical.forall_intro_2 (tail_cons #U32.t); // TODO: this is a local pattern, remove once tail_cons lands in FStar.Seq.Properties if S.length s1 = 0 then begin assert (S.equal (le_of_seq_uint32 s1) S.empty); assert (S.equal (S.append s1 s2) s2); () end else begin assert (S.equal (S.append s1 s2) (S.cons (S.head s1) (S.append (S.tail s1) s2))); assert (S.equal (le_of_seq_uint32 (S.append s1 s2)) (S.append (le_of_uint32 (S.head s1)) (le_of_seq_uint32 (S.append (S.tail s1) s2)))); le_of_seq_uint32_append (S.tail s1) s2 end [@(deprecated "FStar.Endianness.le_of_seq_uint32_base")] let le_of_seq_uint32_base (s1: S.seq U32.t) (s2: S.seq U8.t): Lemma (requires ( S.length s1 = 1 /\ S.length s2 = 4 /\ le_to_n s2 = U32.v (S.index s1 0))) (ensures (S.equal s2 (le_of_seq_uint32 s1))) [ SMTPat (le_to_n s2 = U32.v (S.index s1 0)) ] = ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.All.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "FStar.Krml.Endianness.fst" }
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Math.Lemmas", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Krml", "short_module": null }, { "abbrev": false, "full_module": "FStar.Krml", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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": 1, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s1: FStar.Seq.Base.seq FStar.UInt64.t -> s2: FStar.Seq.Base.seq FStar.UInt64.t -> FStar.Pervasives.Lemma (ensures FStar.Seq.Base.equal (FStar.Krml.Endianness.be_of_seq_uint64 (FStar.Seq.Base.append s1 s2)) (FStar.Seq.Base.append (FStar.Krml.Endianness.be_of_seq_uint64 s1) (FStar.Krml.Endianness.be_of_seq_uint64 s2))) (decreases FStar.Seq.Base.length s1) [ SMTPat (FStar.Seq.Base.append (FStar.Krml.Endianness.be_of_seq_uint64 s1) (FStar.Krml.Endianness.be_of_seq_uint64 s2)) ]
FStar.Pervasives.Lemma
[ "lemma", "" ]
[]
[ "FStar.Seq.Base.seq", "FStar.UInt64.t", "Prims.op_Equality", "Prims.int", "FStar.Seq.Base.length", "Prims.unit", "Prims._assert", "FStar.Seq.Base.equal", "FStar.Seq.Base.append", "FStar.UInt8.t", "FStar.Krml.Endianness.be_of_seq_uint64", "FStar.Seq.Base.empty", "Prims.bool", "FStar.Krml.Endianness.be_of_seq_uint64_append", "FStar.Seq.Properties.tail", "FStar.Krml.Endianness.be_of_uint64", "FStar.Seq.Properties.head", "FStar.Seq.Base.cons", "FStar.Classical.forall_intro_2", "FStar.Krml.Endianness.tail_cons", "Prims.l_True", "Prims.squash", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat", "Prims.Nil" ]
[ "recursion" ]
false
false
true
false
false
let rec be_of_seq_uint64_append (s1 s2: S.seq U64.t) : Lemma (ensures (S.equal (be_of_seq_uint64 (S.append s1 s2)) (S.append (be_of_seq_uint64 s1) (be_of_seq_uint64 s2)))) (decreases (S.length s1)) [SMTPat (S.append (be_of_seq_uint64 s1) (be_of_seq_uint64 s2))] =
Classical.forall_intro_2 (tail_cons #U64.t); if S.length s1 = 0 then (assert (S.equal (be_of_seq_uint64 s1) S.empty); assert (S.equal (S.append s1 s2) s2); ()) else (assert (S.equal (S.append s1 s2) (S.cons (S.head s1) (S.append (S.tail s1) s2))); assert (S.equal (be_of_seq_uint64 (S.append s1 s2)) (S.append (be_of_uint64 (S.head s1)) (be_of_seq_uint64 (S.append (S.tail s1) s2)))); be_of_seq_uint64_append (S.tail s1) s2)
false
Hacl.Spec.Bignum.Multiplication.fst
Hacl.Spec.Bignum.Multiplication.bn_mul1_lshift_add_lemma
val bn_mul1_lshift_add_lemma: #t:limb_t -> #aLen:size_nat -> #resLen:size_nat -> a:lbignum t aLen -> b_j:limb t -> j:size_nat{j + aLen <= resLen} -> acc:lbignum t resLen -> Lemma (let (c, res) = bn_mul1_lshift_add a b_j j acc in v c * pow2 (bits t * (aLen + j)) + eval_ resLen res (aLen + j) == eval_ resLen acc (aLen + j) + bn_v a * v b_j * pow2 (bits t * j) /\ slice res (aLen + j) resLen == slice acc (aLen + j) resLen)
val bn_mul1_lshift_add_lemma: #t:limb_t -> #aLen:size_nat -> #resLen:size_nat -> a:lbignum t aLen -> b_j:limb t -> j:size_nat{j + aLen <= resLen} -> acc:lbignum t resLen -> Lemma (let (c, res) = bn_mul1_lshift_add a b_j j acc in v c * pow2 (bits t * (aLen + j)) + eval_ resLen res (aLen + j) == eval_ resLen acc (aLen + j) + bn_v a * v b_j * pow2 (bits t * j) /\ slice res (aLen + j) resLen == slice acc (aLen + j) resLen)
let bn_mul1_lshift_add_lemma #t #aLen #resLen a b_j j acc = let pbits = bits t in let res1 = sub acc j aLen in let c, res2 = bn_mul1_add_in_place a b_j res1 in bn_mul1_add_in_place_lemma a b_j res1; assert (v c * pow2 (pbits * aLen) + bn_v res2 == bn_v res1 + bn_v a * v b_j); let res = update_sub acc j aLen res2 in bn_eval_split_i (sub res 0 (j + aLen)) j; bn_eval_extensionality_j res (sub res 0 (j + aLen)) (j + aLen); assert (eval_ resLen res (j + aLen) == bn_v #t #j (sub res 0 j) + pow2 (pbits * j) * bn_v res2); eq_intro (sub res 0 j) (sub acc 0 j); assert (bn_v #t #j (sub res 0 j) == bn_v #t #j (sub acc 0 j)); bn_eval_split_i (sub acc 0 (j + aLen)) j; bn_eval_extensionality_j acc (sub acc 0 (j + aLen)) (j + aLen); assert (eval_ resLen acc (j + aLen) == bn_v #t #j (sub acc 0 j) + pow2 (pbits * j) * bn_v res1); calc (==) { v c * pow2 (pbits * (aLen + j)) + eval_ resLen res (aLen + j); (==) { Math.Lemmas.pow2_plus (pbits * aLen) (pbits * j) } v c * (pow2 (pbits * aLen) * pow2 (pbits * j)) + eval_ resLen res (aLen + j); (==) { Math.Lemmas.paren_mul_right (v c) (pow2 (pbits * aLen)) (pow2 (pbits * j)) } v c * pow2 (pbits * aLen) * pow2 (pbits * j) + eval_ resLen res (aLen + j); (==) { } (bn_v res1 + bn_v a * v b_j - bn_v res2) * pow2 (pbits * j) + eval_ resLen res (aLen + j); (==) { } (bn_v res1 + bn_v a * v b_j - bn_v res2) * pow2 (pbits * j) + eval_ resLen acc (j + aLen) - pow2 (pbits * j) * bn_v res1 + pow2 (pbits * j) * bn_v res2; (==) { Math.Lemmas.distributivity_add_right (pow2 (pbits * j)) (bn_v res1) (bn_v a * v b_j - bn_v res2) } pow2 (pbits * j) * (bn_v a * v b_j - bn_v res2) + eval_ resLen acc (j + aLen) + pow2 (pbits * j) * bn_v res2; (==) { Math.Lemmas.distributivity_sub_right (pow2 (pbits * j)) (bn_v a * v b_j) (bn_v res2) } pow2 (pbits * j) * (bn_v a * v b_j) + eval_ resLen acc (j + aLen); }; assert (v c * pow2 (pbits * (aLen + j)) + eval_ resLen res (aLen + j) == eval_ resLen acc (aLen + j) + bn_v a * v b_j * pow2 (pbits * j)); eq_intro (slice res (aLen + j) resLen) (slice acc (aLen + j) resLen)
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Multiplication.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 70, "end_line": 356, "start_col": 0, "start_line": 323 }
module Hacl.Spec.Bignum.Multiplication open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.LoopCombinators open Hacl.Spec.Bignum.Definitions open Hacl.Spec.Bignum.Base open Hacl.Spec.Lib #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" val bn_mul1_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> l:limb t -> i:size_nat{i < aLen} -> c:limb t -> limb t & limb t // carry & out let bn_mul1_f #t #aLen a l i c = mul_wide_add a.[i] l c val bn_mul1: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> l:limb t -> limb t & lbignum t aLen let bn_mul1 #t #aLen a l = generate_elems aLen aLen (bn_mul1_f a l) (uint #t 0) val bn_mul1_add_in_place_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> l:limb t -> acc:lbignum t aLen -> i:size_nat{i < aLen} -> c:limb t -> limb t & limb t // carry & out let bn_mul1_add_in_place_f #t #aLen a l acc i c = mul_wide_add2 a.[i] l c acc.[i] val bn_mul1_add_in_place: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> l:limb t -> acc:lbignum t aLen -> limb t & lbignum t aLen let bn_mul1_add_in_place #t #aLen a l acc = generate_elems aLen aLen (bn_mul1_add_in_place_f a l acc) (uint #t 0) val bn_mul1_lshift_add: #t:limb_t -> #aLen:size_nat -> #resLen:size_nat -> a:lbignum t aLen -> b_j:limb t -> j:size_nat{j + aLen <= resLen} -> res:lbignum t resLen -> limb t & lbignum t resLen let bn_mul1_lshift_add #t #aLen #resLen a b_j j res = let res' = sub res j aLen in let c, res' = bn_mul1_add_in_place a b_j res' in let res = update_sub res j aLen res' in c, res val bn_mul_: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat{aLen + bLen <= max_size_t} -> a:lbignum t aLen -> b:lbignum t bLen -> j:size_nat{j < bLen} -> res:lbignum t (aLen + bLen) -> lbignum t (aLen + bLen) let bn_mul_ #t #aLen #bLen a b j res = let c, res = bn_mul1_lshift_add a b.[j] j res in res.[aLen + j] <- c val bn_mul: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat{aLen + bLen <= max_size_t} -> a:lbignum t aLen -> b:lbignum t bLen -> lbignum t (aLen + bLen) let bn_mul #t #aLen #bLen a b = let res = create (aLen + bLen) (uint #t 0) in repeati bLen (bn_mul_ a b) res val bn_mul1_lemma_loop_step: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> l:limb t -> i:pos{i <= aLen} -> c1_res1:generate_elem_a (limb t) (limb t) aLen (i - 1) -> Lemma (requires (let (c1, res1) = c1_res1 in v c1 * pow2 (bits t * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen a (i - 1) * v l)) (ensures (let (c1, res1) = c1_res1 in let (c, res) = generate_elem_f aLen (bn_mul1_f a l) (i - 1) (c1, res1) in v c * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen a i * v l)) let bn_mul1_lemma_loop_step #t #aLen a l i (c1, res1) = let pbits = bits t in let b1 = pow2 (pbits * (i - 1)) in let b2 = pow2 (pbits * i) in let (c, res) = generate_elem_f aLen (bn_mul1_f a l) (i - 1) (c1, res1) in let c, e = mul_wide_add a.[i - 1] l c1 in assert (v e + v c * pow2 pbits == v a.[i - 1] * v l + v c1); calc (==) { v c * b2 + bn_v #t #i res; (==) { bn_eval_snoc #t #(i - 1) res1 e } v c * b2 + bn_v #t #(i - 1) res1 + v e * b1; (==) { } v c * b2 + eval_ aLen a (i - 1) * v l -(v e + v c * pow2 pbits - v a.[i - 1] * v l) * b1 + v e * b1; (==) { Math.Lemmas.distributivity_add_left (v e) (v c * pow2 pbits - v a.[i - 1] * v l) b1 } v c * b2 + eval_ aLen a (i - 1) * v l - (v c * pow2 pbits - v a.[i - 1] * v l) * b1; (==) { Math.Lemmas.distributivity_sub_left (v c * pow2 pbits) (v a.[i - 1] * v l) b1 } v c * b2 + eval_ aLen a (i - 1) * v l - v c * pow2 pbits * b1 + v a.[i - 1] * v l * b1; (==) { Math.Lemmas.paren_mul_right (v c) (pow2 pbits) b1; Math.Lemmas.pow2_plus pbits (pbits * (i - 1)) } eval_ aLen a (i - 1) * v l + v a.[i - 1] * v l * b1; (==) { Math.Lemmas.paren_mul_right (v a.[i - 1]) (v l) b1 } eval_ aLen a (i - 1) * v l + v a.[i - 1] * (b1 * v l); (==) { Math.Lemmas.paren_mul_right (v a.[i - 1]) b1 (v l) } eval_ aLen a (i - 1) * v l + v a.[i - 1] * b1 * v l; (==) { Math.Lemmas.distributivity_add_left (eval_ aLen a (i - 1)) (v a.[i - 1] * b1) (v l) } (eval_ aLen a (i - 1) + v a.[i - 1] * b1) * v l; (==) { bn_eval_unfold_i a i } eval_ aLen a i * v l; }; assert (v c * b2 + bn_v #t #i res == eval_ aLen a i * v l) val bn_mul1_lemma_loop: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> l:limb t -> i:nat{i <= aLen} -> Lemma (let (c, res) : generate_elem_a (limb t) (limb t) aLen i = generate_elems aLen i (bn_mul1_f a l) (uint #t 0) in v c * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen a i * v l) let rec bn_mul1_lemma_loop #t #aLen a l i = let pbits = bits t in let (c, res) : generate_elem_a (limb t) (limb t) aLen i = generate_elems aLen i (bn_mul1_f a l) (uint #t 0) in if i = 0 then begin eq_generate_elems0 aLen i (bn_mul1_f a l) (uint #t 0); assert (c == uint #t 0 /\ res == Seq.empty); bn_eval0 #t #0 res; assert_norm (pow2 0 = 1); bn_eval0 a; () end else begin let (c1, res1) : generate_elem_a (limb t) (limb t) aLen (i - 1) = generate_elems aLen (i - 1) (bn_mul1_f a l) (uint #t 0) in generate_elems_unfold aLen i (bn_mul1_f a l) (uint #t 0) (i - 1); assert (generate_elems aLen i (bn_mul1_f a l) (uint #t 0) == generate_elem_f aLen (bn_mul1_f a l) (i - 1) (generate_elems aLen (i - 1) (bn_mul1_f a l) (uint #t 0))); assert ((c, res) == generate_elem_f aLen (bn_mul1_f a l) (i - 1) (c1, res1)); bn_mul1_lemma_loop a l (i - 1); assert (v c1 * pow2 (pbits * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen a (i - 1) * v l); bn_mul1_lemma_loop_step a l i (c1, res1); assert (v c * pow2 (pbits * i) + bn_v #t #i res == eval_ aLen a i * v l); () end val bn_mul1_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> l:limb t -> Lemma (let (c, res) = bn_mul1 a l in v c * pow2 (bits t * aLen) + bn_v res == bn_v a * v l) let bn_mul1_lemma #t #aLen a l = let (c, res) = bn_mul1 a l in bn_mul1_lemma_loop a l aLen #push-options "--z3rlimit 150" val bn_mul1_add_in_place_lemma_loop_step: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> l:limb t -> acc:lbignum t aLen -> i:pos{i <= aLen} -> c1_res1:generate_elem_a (limb t) (limb t) aLen (i - 1) -> Lemma (requires (let (c1, res1) = c1_res1 in v c1 * pow2 (bits t * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen acc (i - 1) + eval_ aLen a (i - 1) * v l)) (ensures (let (c1, res1) = c1_res1 in let (c, res) = generate_elem_f aLen (bn_mul1_add_in_place_f a l acc) (i - 1) (c1, res1) in v c * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen acc i + eval_ aLen a i * v l)) let bn_mul1_add_in_place_lemma_loop_step #t #aLen a l acc i (c1, res1) = let pbits = bits t in let b1 = pow2 (pbits * (i - 1)) in let b2 = pow2 (pbits * i) in let (c, res) = generate_elem_f aLen (bn_mul1_add_in_place_f a l acc) (i - 1) (c1, res1) in let c, e = mul_wide_add2 a.[i - 1] l c1 acc.[i - 1] in assert (v e + v c * pow2 pbits == v a.[i - 1] * v l + v c1 + v acc.[i - 1]); calc (==) { v c * b2 + bn_v #t #i res; (==) { bn_eval_snoc #t #(i - 1) res1 e } v c * b2 + bn_v #t #(i - 1) res1 + v e * b1; (==) { } v c * b2 + eval_ aLen acc (i - 1) + eval_ aLen a (i - 1) * v l - (v e + v c * pow2 pbits - v a.[i - 1] * v l - v acc.[i - 1]) * b1 + v e * b1; (==) { Math.Lemmas.distributivity_add_left (v e) (v c * pow2 pbits - v a.[i - 1] * v l - v acc.[i - 1]) b1 } v c * b2 + eval_ aLen acc (i - 1) + eval_ aLen a (i - 1) * v l - (v c * pow2 pbits - v a.[i - 1] * v l - v acc.[i - 1]) * b1; (==) { Math.Lemmas.distributivity_sub_left (v c * pow2 pbits) (v a.[i - 1] * v l + v acc.[i - 1]) b1 } v c * b2 + eval_ aLen acc (i - 1) + eval_ aLen a (i - 1) * v l - (v c * pow2 pbits) * b1 + (v a.[i - 1] * v l + v acc.[i - 1]) * b1; (==) { Math.Lemmas.paren_mul_right (v c) (pow2 pbits) b1; Math.Lemmas.pow2_plus pbits (pbits * (i - 1)) } eval_ aLen acc (i - 1) + eval_ aLen a (i - 1) * v l + (v a.[i - 1] * v l + v acc.[i - 1]) * b1; (==) { Math.Lemmas.distributivity_add_left (v a.[i - 1] * v l) (v acc.[i - 1]) b1 } eval_ aLen acc (i - 1) + eval_ aLen a (i - 1) * v l + v a.[i - 1] * v l * b1 + v acc.[i - 1] * b1; (==) { bn_eval_unfold_i acc i } eval_ aLen acc i + eval_ aLen a (i - 1) * v l + v a.[i - 1] * v l * b1; (==) { Math.Lemmas.paren_mul_right (v a.[i - 1]) (v l) b1 } eval_ aLen acc i + eval_ aLen a (i - 1) * v l + v a.[i - 1] * (b1 * v l); (==) { Math.Lemmas.paren_mul_right (v a.[i - 1]) b1 (v l) } eval_ aLen acc i + eval_ aLen a (i - 1) * v l + v a.[i - 1] * b1 * v l; (==) { Math.Lemmas.distributivity_add_left (eval_ aLen a (i - 1)) (v a.[i - 1] * b1) (v l) } eval_ aLen acc i + (eval_ aLen a (i - 1) + v a.[i - 1] * b1) * v l; (==) { bn_eval_unfold_i a i } eval_ aLen acc i + eval_ aLen a i * v l; }; assert (v c * b2 + bn_v #t #i res == eval_ aLen acc i + eval_ aLen a i * v l) #pop-options val bn_mul1_add_in_place_lemma_loop: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> l:limb t -> acc:lbignum t aLen -> i:nat{i <= aLen} -> Lemma (let (c, res) : generate_elem_a (limb t) (limb t) aLen i = generate_elems aLen i (bn_mul1_add_in_place_f a l acc) (uint #t 0) in v c * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen acc i + eval_ aLen a i * v l) let rec bn_mul1_add_in_place_lemma_loop #t #aLen a l acc i = let pbits = bits t in let (c, res) : generate_elem_a (limb t) (limb t) aLen i = generate_elems aLen i (bn_mul1_add_in_place_f a l acc) (uint #t 0) in if i = 0 then begin eq_generate_elems0 aLen i (bn_mul1_add_in_place_f a l acc) (uint #t 0); assert (c == uint #t 0 /\ res == Seq.empty); bn_eval0 #t #0 res; assert_norm (pow2 0 = 1); bn_eval0 a; bn_eval0 acc; () end else begin let (c1, res1) : generate_elem_a (limb t) (limb t) aLen (i - 1) = generate_elems aLen (i - 1) (bn_mul1_add_in_place_f a l acc) (uint #t 0) in generate_elems_unfold aLen i (bn_mul1_add_in_place_f a l acc) (uint #t 0) (i - 1); assert (generate_elems aLen i (bn_mul1_add_in_place_f a l acc) (uint #t 0) == generate_elem_f aLen (bn_mul1_add_in_place_f a l acc) (i - 1) (generate_elems aLen (i - 1) (bn_mul1_add_in_place_f a l acc) (uint #t 0))); assert ((c, res) == generate_elem_f aLen (bn_mul1_add_in_place_f a l acc) (i - 1) (c1, res1)); bn_mul1_add_in_place_lemma_loop a l acc (i - 1); assert (v c1 * pow2 (pbits * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen acc (i - 1) + eval_ aLen a (i - 1) * v l); bn_mul1_add_in_place_lemma_loop_step a l acc i (c1, res1); assert (v c * pow2 (pbits * i) + bn_v #t #i res == eval_ aLen acc i + eval_ aLen a i * v l); () end val bn_mul1_add_in_place_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> l:limb t -> acc:lbignum t aLen -> Lemma (let (c, res) = bn_mul1_add_in_place a l acc in v c * pow2 (bits t * aLen) + bn_v res == bn_v acc + bn_v a * v l) let bn_mul1_add_in_place_lemma #t #aLen a l acc = let (c, res) = bn_mul1_add_in_place a l acc in bn_mul1_add_in_place_lemma_loop a l acc aLen val bn_mul1_lshift_add_lemma: #t:limb_t -> #aLen:size_nat -> #resLen:size_nat -> a:lbignum t aLen -> b_j:limb t -> j:size_nat{j + aLen <= resLen} -> acc:lbignum t resLen -> Lemma (let (c, res) = bn_mul1_lshift_add a b_j j acc in v c * pow2 (bits t * (aLen + j)) + eval_ resLen res (aLen + j) == eval_ resLen acc (aLen + j) + bn_v a * v b_j * pow2 (bits t * j) /\ slice res (aLen + j) resLen == slice acc (aLen + j) resLen)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Lib.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Bignum.Multiplication.fst" }
[ { "abbrev": false, "full_module": "Hacl.Spec.Lib", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Base", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> b_j: Hacl.Spec.Bignum.Definitions.limb t -> j: Lib.IntTypes.size_nat{j + aLen <= resLen} -> acc: Hacl.Spec.Bignum.Definitions.lbignum t resLen -> FStar.Pervasives.Lemma (ensures (let _ = Hacl.Spec.Bignum.Multiplication.bn_mul1_lshift_add a b_j j acc in (let FStar.Pervasives.Native.Mktuple2 #_ #_ c res = _ in Lib.IntTypes.v c * Prims.pow2 (Lib.IntTypes.bits t * (aLen + j)) + Hacl.Spec.Bignum.Definitions.eval_ resLen res (aLen + j) == Hacl.Spec.Bignum.Definitions.eval_ resLen acc (aLen + j) + (Hacl.Spec.Bignum.Definitions.bn_v a * Lib.IntTypes.v b_j) * Prims.pow2 (Lib.IntTypes.bits t * j) /\ Lib.Sequence.slice res (aLen + j) resLen == Lib.Sequence.slice acc (aLen + j) resLen) <: Type0))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Lib.IntTypes.size_nat", "Hacl.Spec.Bignum.Definitions.lbignum", "Hacl.Spec.Bignum.Definitions.limb", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "Lib.Sequence.eq_intro", "Prims.op_Subtraction", "Lib.Sequence.slice", "Prims.unit", "Prims._assert", "Prims.eq2", "Prims.int", "FStar.Mul.op_Star", "Lib.IntTypes.v", "Lib.IntTypes.SEC", "Prims.pow2", "Hacl.Spec.Bignum.Definitions.eval_", "Hacl.Spec.Bignum.Definitions.bn_v", "FStar.Calc.calc_finish", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "FStar.Calc.calc_step", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "FStar.Math.Lemmas.pow2_plus", "Prims.squash", "FStar.Math.Lemmas.paren_mul_right", "FStar.Math.Lemmas.distributivity_add_right", "FStar.Math.Lemmas.distributivity_sub_right", "Lib.Sequence.sub", "Hacl.Spec.Bignum.Definitions.bn_eval_extensionality_j", "Hacl.Spec.Bignum.Definitions.bn_eval_split_i", "Prims.nat", "Lib.Sequence.lseq", "Prims.l_and", "Prims.l_Forall", "Prims.l_or", "Prims.op_LessThan", "FStar.Seq.Base.index", "Lib.Sequence.to_seq", "Lib.Sequence.index", "Lib.Sequence.update_sub", "Hacl.Spec.Bignum.Multiplication.bn_mul1_add_in_place_lemma", "FStar.Pervasives.Native.tuple2", "Hacl.Spec.Bignum.Multiplication.bn_mul1_add_in_place", "FStar.Seq.Base.seq", "FStar.Seq.Base.slice", "Lib.IntTypes.bits" ]
[]
false
false
true
false
false
let bn_mul1_lshift_add_lemma #t #aLen #resLen a b_j j acc =
let pbits = bits t in let res1 = sub acc j aLen in let c, res2 = bn_mul1_add_in_place a b_j res1 in bn_mul1_add_in_place_lemma a b_j res1; assert (v c * pow2 (pbits * aLen) + bn_v res2 == bn_v res1 + bn_v a * v b_j); let res = update_sub acc j aLen res2 in bn_eval_split_i (sub res 0 (j + aLen)) j; bn_eval_extensionality_j res (sub res 0 (j + aLen)) (j + aLen); assert (eval_ resLen res (j + aLen) == bn_v #t #j (sub res 0 j) + pow2 (pbits * j) * bn_v res2); eq_intro (sub res 0 j) (sub acc 0 j); assert (bn_v #t #j (sub res 0 j) == bn_v #t #j (sub acc 0 j)); bn_eval_split_i (sub acc 0 (j + aLen)) j; bn_eval_extensionality_j acc (sub acc 0 (j + aLen)) (j + aLen); assert (eval_ resLen acc (j + aLen) == bn_v #t #j (sub acc 0 j) + pow2 (pbits * j) * bn_v res1); calc ( == ) { v c * pow2 (pbits * (aLen + j)) + eval_ resLen res (aLen + j); ( == ) { Math.Lemmas.pow2_plus (pbits * aLen) (pbits * j) } v c * (pow2 (pbits * aLen) * pow2 (pbits * j)) + eval_ resLen res (aLen + j); ( == ) { Math.Lemmas.paren_mul_right (v c) (pow2 (pbits * aLen)) (pow2 (pbits * j)) } (v c * pow2 (pbits * aLen)) * pow2 (pbits * j) + eval_ resLen res (aLen + j); ( == ) { () } (bn_v res1 + bn_v a * v b_j - bn_v res2) * pow2 (pbits * j) + eval_ resLen res (aLen + j); ( == ) { () } (bn_v res1 + bn_v a * v b_j - bn_v res2) * pow2 (pbits * j) + eval_ resLen acc (j + aLen) - pow2 (pbits * j) * bn_v res1 + pow2 (pbits * j) * bn_v res2; ( == ) { Math.Lemmas.distributivity_add_right (pow2 (pbits * j)) (bn_v res1) (bn_v a * v b_j - bn_v res2) } pow2 (pbits * j) * (bn_v a * v b_j - bn_v res2) + eval_ resLen acc (j + aLen) + pow2 (pbits * j) * bn_v res2; ( == ) { Math.Lemmas.distributivity_sub_right (pow2 (pbits * j)) (bn_v a * v b_j) (bn_v res2) } pow2 (pbits * j) * (bn_v a * v b_j) + eval_ resLen acc (j + aLen); }; assert (v c * pow2 (pbits * (aLen + j)) + eval_ resLen res (aLen + j) == eval_ resLen acc (aLen + j) + (bn_v a * v b_j) * pow2 (pbits * j)); eq_intro (slice res (aLen + j) resLen) (slice acc (aLen + j) resLen)
false
Hacl.Spec.Bignum.Multiplication.fst
Hacl.Spec.Bignum.Multiplication.bn_mul1_lemma_loop_step
val bn_mul1_lemma_loop_step: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> l:limb t -> i:pos{i <= aLen} -> c1_res1:generate_elem_a (limb t) (limb t) aLen (i - 1) -> Lemma (requires (let (c1, res1) = c1_res1 in v c1 * pow2 (bits t * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen a (i - 1) * v l)) (ensures (let (c1, res1) = c1_res1 in let (c, res) = generate_elem_f aLen (bn_mul1_f a l) (i - 1) (c1, res1) in v c * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen a i * v l))
val bn_mul1_lemma_loop_step: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> l:limb t -> i:pos{i <= aLen} -> c1_res1:generate_elem_a (limb t) (limb t) aLen (i - 1) -> Lemma (requires (let (c1, res1) = c1_res1 in v c1 * pow2 (bits t * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen a (i - 1) * v l)) (ensures (let (c1, res1) = c1_res1 in let (c, res) = generate_elem_f aLen (bn_mul1_f a l) (i - 1) (c1, res1) in v c * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen a i * v l))
let bn_mul1_lemma_loop_step #t #aLen a l i (c1, res1) = let pbits = bits t in let b1 = pow2 (pbits * (i - 1)) in let b2 = pow2 (pbits * i) in let (c, res) = generate_elem_f aLen (bn_mul1_f a l) (i - 1) (c1, res1) in let c, e = mul_wide_add a.[i - 1] l c1 in assert (v e + v c * pow2 pbits == v a.[i - 1] * v l + v c1); calc (==) { v c * b2 + bn_v #t #i res; (==) { bn_eval_snoc #t #(i - 1) res1 e } v c * b2 + bn_v #t #(i - 1) res1 + v e * b1; (==) { } v c * b2 + eval_ aLen a (i - 1) * v l -(v e + v c * pow2 pbits - v a.[i - 1] * v l) * b1 + v e * b1; (==) { Math.Lemmas.distributivity_add_left (v e) (v c * pow2 pbits - v a.[i - 1] * v l) b1 } v c * b2 + eval_ aLen a (i - 1) * v l - (v c * pow2 pbits - v a.[i - 1] * v l) * b1; (==) { Math.Lemmas.distributivity_sub_left (v c * pow2 pbits) (v a.[i - 1] * v l) b1 } v c * b2 + eval_ aLen a (i - 1) * v l - v c * pow2 pbits * b1 + v a.[i - 1] * v l * b1; (==) { Math.Lemmas.paren_mul_right (v c) (pow2 pbits) b1; Math.Lemmas.pow2_plus pbits (pbits * (i - 1)) } eval_ aLen a (i - 1) * v l + v a.[i - 1] * v l * b1; (==) { Math.Lemmas.paren_mul_right (v a.[i - 1]) (v l) b1 } eval_ aLen a (i - 1) * v l + v a.[i - 1] * (b1 * v l); (==) { Math.Lemmas.paren_mul_right (v a.[i - 1]) b1 (v l) } eval_ aLen a (i - 1) * v l + v a.[i - 1] * b1 * v l; (==) { Math.Lemmas.distributivity_add_left (eval_ aLen a (i - 1)) (v a.[i - 1] * b1) (v l) } (eval_ aLen a (i - 1) + v a.[i - 1] * b1) * v l; (==) { bn_eval_unfold_i a i } eval_ aLen a i * v l; }; assert (v c * b2 + bn_v #t #i res == eval_ aLen a i * v l)
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Multiplication.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 60, "end_line": 157, "start_col": 0, "start_line": 127 }
module Hacl.Spec.Bignum.Multiplication open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.LoopCombinators open Hacl.Spec.Bignum.Definitions open Hacl.Spec.Bignum.Base open Hacl.Spec.Lib #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" val bn_mul1_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> l:limb t -> i:size_nat{i < aLen} -> c:limb t -> limb t & limb t // carry & out let bn_mul1_f #t #aLen a l i c = mul_wide_add a.[i] l c val bn_mul1: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> l:limb t -> limb t & lbignum t aLen let bn_mul1 #t #aLen a l = generate_elems aLen aLen (bn_mul1_f a l) (uint #t 0) val bn_mul1_add_in_place_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> l:limb t -> acc:lbignum t aLen -> i:size_nat{i < aLen} -> c:limb t -> limb t & limb t // carry & out let bn_mul1_add_in_place_f #t #aLen a l acc i c = mul_wide_add2 a.[i] l c acc.[i] val bn_mul1_add_in_place: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> l:limb t -> acc:lbignum t aLen -> limb t & lbignum t aLen let bn_mul1_add_in_place #t #aLen a l acc = generate_elems aLen aLen (bn_mul1_add_in_place_f a l acc) (uint #t 0) val bn_mul1_lshift_add: #t:limb_t -> #aLen:size_nat -> #resLen:size_nat -> a:lbignum t aLen -> b_j:limb t -> j:size_nat{j + aLen <= resLen} -> res:lbignum t resLen -> limb t & lbignum t resLen let bn_mul1_lshift_add #t #aLen #resLen a b_j j res = let res' = sub res j aLen in let c, res' = bn_mul1_add_in_place a b_j res' in let res = update_sub res j aLen res' in c, res val bn_mul_: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat{aLen + bLen <= max_size_t} -> a:lbignum t aLen -> b:lbignum t bLen -> j:size_nat{j < bLen} -> res:lbignum t (aLen + bLen) -> lbignum t (aLen + bLen) let bn_mul_ #t #aLen #bLen a b j res = let c, res = bn_mul1_lshift_add a b.[j] j res in res.[aLen + j] <- c val bn_mul: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat{aLen + bLen <= max_size_t} -> a:lbignum t aLen -> b:lbignum t bLen -> lbignum t (aLen + bLen) let bn_mul #t #aLen #bLen a b = let res = create (aLen + bLen) (uint #t 0) in repeati bLen (bn_mul_ a b) res val bn_mul1_lemma_loop_step: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> l:limb t -> i:pos{i <= aLen} -> c1_res1:generate_elem_a (limb t) (limb t) aLen (i - 1) -> Lemma (requires (let (c1, res1) = c1_res1 in v c1 * pow2 (bits t * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen a (i - 1) * v l)) (ensures (let (c1, res1) = c1_res1 in let (c, res) = generate_elem_f aLen (bn_mul1_f a l) (i - 1) (c1, res1) in v c * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen a i * v l))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Lib.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Bignum.Multiplication.fst" }
[ { "abbrev": false, "full_module": "Hacl.Spec.Lib", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Base", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> l: Hacl.Spec.Bignum.Definitions.limb t -> i: Prims.pos{i <= aLen} -> c1_res1: Hacl.Spec.Lib.generate_elem_a (Hacl.Spec.Bignum.Definitions.limb t) (Hacl.Spec.Bignum.Definitions.limb t) aLen (i - 1) -> FStar.Pervasives.Lemma (requires (let _ = c1_res1 in (let FStar.Pervasives.Native.Mktuple2 #_ #_ c1 res1 = _ in Lib.IntTypes.v c1 * Prims.pow2 (Lib.IntTypes.bits t * (i - 1)) + Hacl.Spec.Bignum.Definitions.bn_v res1 == Hacl.Spec.Bignum.Definitions.eval_ aLen a (i - 1) * Lib.IntTypes.v l) <: Type0)) (ensures (let _ = c1_res1 in (let FStar.Pervasives.Native.Mktuple2 #_ #_ c1 res1 = _ in let _ = Hacl.Spec.Lib.generate_elem_f aLen (Hacl.Spec.Bignum.Multiplication.bn_mul1_f a l) (i - 1) (c1, res1) in (let FStar.Pervasives.Native.Mktuple2 #_ #_ c res = _ in Lib.IntTypes.v c * Prims.pow2 (Lib.IntTypes.bits t * i) + Hacl.Spec.Bignum.Definitions.bn_v res == Hacl.Spec.Bignum.Definitions.eval_ aLen a i * Lib.IntTypes.v l) <: Type0) <: Type0))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Lib.IntTypes.size_nat", "Hacl.Spec.Bignum.Definitions.lbignum", "Hacl.Spec.Bignum.Definitions.limb", "Prims.pos", "Prims.b2t", "Prims.op_LessThanOrEqual", "Hacl.Spec.Lib.generate_elem_a", "Prims.op_Subtraction", "Lib.Sequence.seq", "Prims.eq2", "Prims.nat", "Lib.Sequence.length", "Prims.op_Addition", "Prims._assert", "Prims.int", "FStar.Mul.op_Star", "Lib.IntTypes.v", "Lib.IntTypes.SEC", "Hacl.Spec.Bignum.Definitions.bn_v", "Hacl.Spec.Bignum.Definitions.eval_", "Prims.unit", "FStar.Calc.calc_finish", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "FStar.Calc.calc_step", "Lib.Sequence.op_String_Access", "Prims.pow2", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "Hacl.Spec.Bignum.Definitions.bn_eval_snoc", "Prims.squash", "FStar.Math.Lemmas.distributivity_add_left", "FStar.Math.Lemmas.distributivity_sub_left", "FStar.Math.Lemmas.pow2_plus", "FStar.Math.Lemmas.paren_mul_right", "Hacl.Spec.Bignum.Definitions.bn_eval_unfold_i", "FStar.Pervasives.Native.tuple2", "Hacl.Spec.Bignum.Base.mul_wide_add", "Hacl.Spec.Lib.generate_elem_f", "Hacl.Spec.Bignum.Multiplication.bn_mul1_f", "FStar.Pervasives.Native.Mktuple2", "Lib.IntTypes.bits" ]
[]
false
false
true
false
false
let bn_mul1_lemma_loop_step #t #aLen a l i (c1, res1) =
let pbits = bits t in let b1 = pow2 (pbits * (i - 1)) in let b2 = pow2 (pbits * i) in let c, res = generate_elem_f aLen (bn_mul1_f a l) (i - 1) (c1, res1) in let c, e = mul_wide_add a.[ i - 1 ] l c1 in assert (v e + v c * pow2 pbits == v a.[ i - 1 ] * v l + v c1); calc ( == ) { v c * b2 + bn_v #t #i res; ( == ) { bn_eval_snoc #t #(i - 1) res1 e } v c * b2 + bn_v #t #(i - 1) res1 + v e * b1; ( == ) { () } v c * b2 + eval_ aLen a (i - 1) * v l - (v e + v c * pow2 pbits - v a.[ i - 1 ] * v l) * b1 + v e * b1; ( == ) { Math.Lemmas.distributivity_add_left (v e) (v c * pow2 pbits - v a.[ i - 1 ] * v l) b1 } v c * b2 + eval_ aLen a (i - 1) * v l - (v c * pow2 pbits - v a.[ i - 1 ] * v l) * b1; ( == ) { Math.Lemmas.distributivity_sub_left (v c * pow2 pbits) (v a.[ i - 1 ] * v l) b1 } v c * b2 + eval_ aLen a (i - 1) * v l - (v c * pow2 pbits) * b1 + (v a.[ i - 1 ] * v l) * b1; ( == ) { (Math.Lemmas.paren_mul_right (v c) (pow2 pbits) b1; Math.Lemmas.pow2_plus pbits (pbits * (i - 1))) } eval_ aLen a (i - 1) * v l + (v a.[ i - 1 ] * v l) * b1; ( == ) { Math.Lemmas.paren_mul_right (v a.[ i - 1 ]) (v l) b1 } eval_ aLen a (i - 1) * v l + v a.[ i - 1 ] * (b1 * v l); ( == ) { Math.Lemmas.paren_mul_right (v a.[ i - 1 ]) b1 (v l) } eval_ aLen a (i - 1) * v l + (v a.[ i - 1 ] * b1) * v l; ( == ) { Math.Lemmas.distributivity_add_left (eval_ aLen a (i - 1)) (v a.[ i - 1 ] * b1) (v l) } (eval_ aLen a (i - 1) + v a.[ i - 1 ] * b1) * v l; ( == ) { bn_eval_unfold_i a i } eval_ aLen a i * v l; }; assert (v c * b2 + bn_v #t #i res == eval_ aLen a i * v l)
false
Steel.HigherReference.fst
Steel.HigherReference.ref
val ref ([@@@unused] a:Type u#1) : Type u#0
val ref ([@@@unused] a:Type u#1) : Type u#0
let ref a = Mem.ref (fractional a) pcm_frac
{ "file_name": "lib/steel/Steel.HigherReference.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 43, "end_line": 31, "start_col": 0, "start_line": 31 }
(* 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.HigherReference open FStar.Ghost open Steel.Memory open Steel.Effect.Atomic open Steel.Effect open FStar.PCM open Steel.PCMFrac open FStar.Real module RP = Steel.PCMReference #set-options "--ide_id_info_off" module Mem = Steel.Memory
{ "checked_file": "/", "dependencies": [ "Steel.PCMReference.fsti.checked", "Steel.PCMFrac.fst.checked", "Steel.Memory.fsti.checked", "Steel.Effect.Atomic.fsti.checked", "Steel.Effect.fsti.checked", "prims.fst.checked", "FStar.Real.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked", "FStar.NMSTTotal.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Steel.HigherReference.fst" }
[ { "abbrev": true, "full_module": "Steel.Memory", "short_module": "Mem" }, { "abbrev": true, "full_module": "Steel.PCMReference", "short_module": "RP" }, { "abbrev": false, "full_module": "FStar.Real", "short_module": null }, { "abbrev": false, "full_module": "Steel.PCMFrac", "short_module": null }, { "abbrev": false, "full_module": "FStar.PCM", "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": "FStar.Ghost", "short_module": null }, { "abbrev": true, "full_module": "Steel.Memory", "short_module": "Mem" }, { "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": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "Steel.FractionalPermission", "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
a: Type -> Type0
Prims.Tot
[ "total" ]
[]
[ "Steel.Memory.ref", "Steel.PCMFrac.fractional", "Steel.PCMFrac.pcm_frac" ]
[]
false
false
false
true
true
let ref a =
Mem.ref (fractional a) pcm_frac
false
Steel.HigherReference.fst
Steel.HigherReference.null
val null (#a:Type u#1) : ref a
val null (#a:Type u#1) : ref a
let null #a = Mem.null #(fractional a) #pcm_frac
{ "file_name": "lib/steel/Steel.HigherReference.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 48, "end_line": 32, "start_col": 0, "start_line": 32 }
(* 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.HigherReference open FStar.Ghost open Steel.Memory open Steel.Effect.Atomic open Steel.Effect open FStar.PCM open Steel.PCMFrac open FStar.Real module RP = Steel.PCMReference #set-options "--ide_id_info_off" module Mem = Steel.Memory
{ "checked_file": "/", "dependencies": [ "Steel.PCMReference.fsti.checked", "Steel.PCMFrac.fst.checked", "Steel.Memory.fsti.checked", "Steel.Effect.Atomic.fsti.checked", "Steel.Effect.fsti.checked", "prims.fst.checked", "FStar.Real.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked", "FStar.NMSTTotal.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Steel.HigherReference.fst" }
[ { "abbrev": true, "full_module": "Steel.Memory", "short_module": "Mem" }, { "abbrev": true, "full_module": "Steel.PCMReference", "short_module": "RP" }, { "abbrev": false, "full_module": "FStar.Real", "short_module": null }, { "abbrev": false, "full_module": "Steel.PCMFrac", "short_module": null }, { "abbrev": false, "full_module": "FStar.PCM", "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": "FStar.Ghost", "short_module": null }, { "abbrev": true, "full_module": "Steel.Memory", "short_module": "Mem" }, { "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": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "Steel.FractionalPermission", "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
Steel.HigherReference.ref a
Prims.Tot
[ "total" ]
[]
[ "Steel.Memory.null", "Steel.PCMFrac.fractional", "Steel.PCMFrac.pcm_frac", "Steel.HigherReference.ref" ]
[]
false
false
false
true
false
let null #a =
Mem.null #(fractional a) #pcm_frac
false
Steel.HigherReference.fst
Steel.HigherReference.pts_to_raw
val pts_to_raw (#a: Type) (r: ref a) (p: perm) (v: erased a) : vprop
val pts_to_raw (#a: Type) (r: ref a) (p: perm) (v: erased a) : vprop
let pts_to_raw (#a:Type) (r:ref a) (p:perm) (v:erased a) : vprop = to_vprop (Mem.pts_to r (Some (Ghost.reveal v, p)))
{ "file_name": "lib/steel/Steel.HigherReference.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 52, "end_line": 38, "start_col": 0, "start_line": 37 }
(* 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.HigherReference open FStar.Ghost open Steel.Memory open Steel.Effect.Atomic open Steel.Effect open FStar.PCM open Steel.PCMFrac open FStar.Real module RP = Steel.PCMReference #set-options "--ide_id_info_off" module Mem = Steel.Memory let ref a = Mem.ref (fractional a) pcm_frac let null #a = Mem.null #(fractional a) #pcm_frac let is_null #a r = Mem.is_null #(fractional a) #pcm_frac r let perm_ok p : prop = (p.v <=. one == true) /\ True let pts_to_raw_sl (#a:Type) (r:ref a) (p:perm) (v:erased a) : slprop =
{ "checked_file": "/", "dependencies": [ "Steel.PCMReference.fsti.checked", "Steel.PCMFrac.fst.checked", "Steel.Memory.fsti.checked", "Steel.Effect.Atomic.fsti.checked", "Steel.Effect.fsti.checked", "prims.fst.checked", "FStar.Real.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked", "FStar.NMSTTotal.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Steel.HigherReference.fst" }
[ { "abbrev": true, "full_module": "Steel.Memory", "short_module": "Mem" }, { "abbrev": true, "full_module": "Steel.PCMReference", "short_module": "RP" }, { "abbrev": false, "full_module": "FStar.Real", "short_module": null }, { "abbrev": false, "full_module": "Steel.PCMFrac", "short_module": null }, { "abbrev": false, "full_module": "FStar.PCM", "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": "FStar.Ghost", "short_module": null }, { "abbrev": true, "full_module": "Steel.Memory", "short_module": "Mem" }, { "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": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "Steel.FractionalPermission", "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
r: Steel.HigherReference.ref a -> p: Steel.FractionalPermission.perm -> v: FStar.Ghost.erased a -> Steel.Effect.Common.vprop
Prims.Tot
[ "total" ]
[]
[ "Steel.HigherReference.ref", "Steel.FractionalPermission.perm", "FStar.Ghost.erased", "Steel.Effect.Common.to_vprop", "Steel.Memory.pts_to", "Steel.PCMFrac.fractional", "Steel.PCMFrac.pcm_frac", "FStar.Pervasives.Native.Some", "FStar.Pervasives.Native.tuple2", "FStar.Pervasives.Native.Mktuple2", "FStar.Ghost.reveal", "Steel.Effect.Common.vprop" ]
[]
false
false
false
true
false
let pts_to_raw (#a: Type) (r: ref a) (p: perm) (v: erased a) : vprop =
to_vprop (Mem.pts_to r (Some (Ghost.reveal v, p)))
false
Steel.HigherReference.fst
Steel.HigherReference.pts_to'
val pts_to' (#a: Type u#1) (r: ref a) (p: perm) (v: erased a) : vprop
val pts_to' (#a: Type u#1) (r: ref a) (p: perm) (v: erased a) : vprop
let pts_to' (#a:Type u#1) (r:ref a) (p:perm) (v:erased a) : vprop = pts_to_raw r p v `star` pure (perm_ok p)
{ "file_name": "lib/steel/Steel.HigherReference.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 108, "end_line": 40, "start_col": 0, "start_line": 40 }
(* 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.HigherReference open FStar.Ghost open Steel.Memory open Steel.Effect.Atomic open Steel.Effect open FStar.PCM open Steel.PCMFrac open FStar.Real module RP = Steel.PCMReference #set-options "--ide_id_info_off" module Mem = Steel.Memory let ref a = Mem.ref (fractional a) pcm_frac let null #a = Mem.null #(fractional a) #pcm_frac let is_null #a r = Mem.is_null #(fractional a) #pcm_frac r let perm_ok p : prop = (p.v <=. one == true) /\ True let pts_to_raw_sl (#a:Type) (r:ref a) (p:perm) (v:erased a) : slprop = Mem.pts_to r (Some (Ghost.reveal v, p)) let pts_to_raw (#a:Type) (r:ref a) (p:perm) (v:erased a) : vprop = to_vprop (Mem.pts_to r (Some (Ghost.reveal v, p)))
{ "checked_file": "/", "dependencies": [ "Steel.PCMReference.fsti.checked", "Steel.PCMFrac.fst.checked", "Steel.Memory.fsti.checked", "Steel.Effect.Atomic.fsti.checked", "Steel.Effect.fsti.checked", "prims.fst.checked", "FStar.Real.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked", "FStar.NMSTTotal.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Steel.HigherReference.fst" }
[ { "abbrev": true, "full_module": "Steel.Memory", "short_module": "Mem" }, { "abbrev": true, "full_module": "Steel.PCMReference", "short_module": "RP" }, { "abbrev": false, "full_module": "FStar.Real", "short_module": null }, { "abbrev": false, "full_module": "Steel.PCMFrac", "short_module": null }, { "abbrev": false, "full_module": "FStar.PCM", "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": "FStar.Ghost", "short_module": null }, { "abbrev": true, "full_module": "Steel.Memory", "short_module": "Mem" }, { "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": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "Steel.FractionalPermission", "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
r: Steel.HigherReference.ref a -> p: Steel.FractionalPermission.perm -> v: FStar.Ghost.erased a -> Steel.Effect.Common.vprop
Prims.Tot
[ "total" ]
[]
[ "Steel.HigherReference.ref", "Steel.FractionalPermission.perm", "FStar.Ghost.erased", "Steel.Effect.Common.star", "Steel.HigherReference.pts_to_raw", "Steel.Effect.Common.pure", "Steel.HigherReference.perm_ok", "Steel.Effect.Common.vprop" ]
[]
false
false
false
true
false
let pts_to' (#a: Type u#1) (r: ref a) (p: perm) (v: erased a) : vprop =
(pts_to_raw r p v) `star` (pure (perm_ok p))
false
Steel.HigherReference.fst
Steel.HigherReference.pts_to_sl
val pts_to_sl (#a:Type u#1) (r:ref a) (p:perm) (v:a) : slprop u#1
val pts_to_sl (#a:Type u#1) (r:ref a) (p:perm) (v:a) : slprop u#1
let pts_to_sl #a r p v = hp_of (pts_to' r p v)
{ "file_name": "lib/steel/Steel.HigherReference.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 47, "end_line": 41, "start_col": 0, "start_line": 41 }
(* 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.HigherReference open FStar.Ghost open Steel.Memory open Steel.Effect.Atomic open Steel.Effect open FStar.PCM open Steel.PCMFrac open FStar.Real module RP = Steel.PCMReference #set-options "--ide_id_info_off" module Mem = Steel.Memory let ref a = Mem.ref (fractional a) pcm_frac let null #a = Mem.null #(fractional a) #pcm_frac let is_null #a r = Mem.is_null #(fractional a) #pcm_frac r let perm_ok p : prop = (p.v <=. one == true) /\ True let pts_to_raw_sl (#a:Type) (r:ref a) (p:perm) (v:erased a) : slprop = Mem.pts_to r (Some (Ghost.reveal v, p)) let pts_to_raw (#a:Type) (r:ref a) (p:perm) (v:erased a) : vprop = to_vprop (Mem.pts_to r (Some (Ghost.reveal v, p))) [@@__reduce__]
{ "checked_file": "/", "dependencies": [ "Steel.PCMReference.fsti.checked", "Steel.PCMFrac.fst.checked", "Steel.Memory.fsti.checked", "Steel.Effect.Atomic.fsti.checked", "Steel.Effect.fsti.checked", "prims.fst.checked", "FStar.Real.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked", "FStar.NMSTTotal.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Steel.HigherReference.fst" }
[ { "abbrev": true, "full_module": "Steel.Memory", "short_module": "Mem" }, { "abbrev": true, "full_module": "Steel.PCMReference", "short_module": "RP" }, { "abbrev": false, "full_module": "FStar.Real", "short_module": null }, { "abbrev": false, "full_module": "Steel.PCMFrac", "short_module": null }, { "abbrev": false, "full_module": "FStar.PCM", "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": "FStar.Ghost", "short_module": null }, { "abbrev": true, "full_module": "Steel.Memory", "short_module": "Mem" }, { "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": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "Steel.FractionalPermission", "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
r: Steel.HigherReference.ref a -> p: Steel.FractionalPermission.perm -> v: a -> Steel.Memory.slprop
Prims.Tot
[ "total" ]
[]
[ "Steel.HigherReference.ref", "Steel.FractionalPermission.perm", "Steel.Effect.Common.hp_of", "Steel.HigherReference.pts_to'", "FStar.Ghost.hide", "Steel.Memory.slprop" ]
[]
false
false
false
true
false
let pts_to_sl #a r p v =
hp_of (pts_to' r p v)
false
Hacl.Impl.Poly1305.Field32xN_128.fst
Hacl.Impl.Poly1305.Field32xN_128.fmul_r2_normalize
val fmul_r2_normalize: out:felem 2 -> p:precomp_r 2 -> Stack unit (requires fun h -> live h out /\ live h p /\ felem_fits h out (3, 3, 3, 3, 3) /\ load_precompute_r_post h p) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ felem_fits h1 out (2, 2, 2, 2, 2) /\ (let r = feval h0 (gsub p 0ul 5ul) in (feval h1 out).[0] == Vec.normalize_2 r.[0] (feval h0 out)))
val fmul_r2_normalize: out:felem 2 -> p:precomp_r 2 -> Stack unit (requires fun h -> live h out /\ live h p /\ felem_fits h out (3, 3, 3, 3, 3) /\ load_precompute_r_post h p) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ felem_fits h1 out (2, 2, 2, 2, 2) /\ (let r = feval h0 (gsub p 0ul 5ul) in (feval h1 out).[0] == Vec.normalize_2 r.[0] (feval h0 out)))
let fmul_r2_normalize out p = let r = sub p 0ul 5ul in let r2 = sub p 10ul 5ul in let a0 = out.(0ul) in let a1 = out.(1ul) in let a2 = out.(2ul) in let a3 = out.(3ul) in let a4 = out.(4ul) in let r10 = r.(0ul) in let r11 = r.(1ul) in let r12 = r.(2ul) in let r13 = r.(3ul) in let r14 = r.(4ul) in let r20 = r2.(0ul) in let r21 = r2.(1ul) in let r22 = r2.(2ul) in let r23 = r2.(3ul) in let r24 = r2.(4ul) in let (o0, o1, o2, o3, o4) = fmul_r2_normalize5 (a0, a1, a2, a3, a4) (r10, r11, r12, r13, r14) (r20, r21, r22, r23, r24) in out.(0ul) <- o0; out.(1ul) <- o1; out.(2ul) <- o2; out.(3ul) <- o3; out.(4ul) <- o4
{ "file_name": "code/poly1305/Hacl.Impl.Poly1305.Field32xN_128.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 17, "end_line": 101, "start_col": 0, "start_line": 73 }
module Hacl.Impl.Poly1305.Field32xN_128 open FStar.HyperStack open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer include Hacl.Spec.Poly1305.Field32xN open Hacl.Spec.Poly1305.Field32xN.Lemmas module Vec = Hacl.Spec.Poly1305.Vec module ST = FStar.HyperStack.ST open Hacl.Impl.Poly1305.Field32xN /// See comments in Hacl.Impl.Poly1305.Field32xN_256 #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 50 --using_facts_from '* -FStar.Seq'" val load_acc2: acc:felem 2 -> b:lbuffer uint8 32ul -> Stack unit (requires fun h -> live h acc /\ live h b /\ disjoint acc b /\ felem_fits h acc (2, 2, 2, 2, 2)) (ensures fun h0 _ h1 -> modifies (loc acc) h0 h1 /\ felem_fits h1 acc (3, 3, 3, 3, 3) /\ feval h1 acc == Vec.load_acc2 (as_seq h0 b) (feval h0 acc).[0]) let load_acc2 acc b = push_frame(); let e = create 5ul (zero 2) in load_blocks e b; let acc0 = acc.(0ul) in let acc1 = acc.(1ul) in let acc2 = acc.(2ul) in let acc3 = acc.(3ul) in let acc4 = acc.(4ul) in let e0 = e.(0ul) in let e1 = e.(1ul) in let e2 = e.(2ul) in let e3 = e.(3ul) in let e4 = e.(4ul) in let (acc0, acc1, acc2, acc3, acc4) = load_acc5_2 (acc0, acc1, acc2, acc3, acc4) (e0, e1, e2, e3, e4) in acc.(0ul) <- acc0; acc.(1ul) <- acc1; acc.(2ul) <- acc2; acc.(3ul) <- acc3; acc.(4ul) <- acc4; pop_frame() val fmul_r2_normalize: out:felem 2 -> p:precomp_r 2 -> Stack unit (requires fun h -> live h out /\ live h p /\ felem_fits h out (3, 3, 3, 3, 3) /\ load_precompute_r_post h p) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ felem_fits h1 out (2, 2, 2, 2, 2) /\ (let r = feval h0 (gsub p 0ul 5ul) in
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Poly1305.Vec.fst.checked", "Hacl.Spec.Poly1305.Field32xN.Lemmas.fst.checked", "Hacl.Spec.Poly1305.Field32xN.fst.checked", "Hacl.Impl.Poly1305.Field32xN.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Poly1305.Field32xN_128.fst" }
[ { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Hacl.Spec.Poly1305.Vec", "short_module": "Vec" }, { "abbrev": false, "full_module": "Hacl.Spec.Poly1305.Field32xN.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Poly1305.Field32xN", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
out: Hacl.Impl.Poly1305.Field32xN.felem 2 -> p: Hacl.Impl.Poly1305.Field32xN.precomp_r 2 -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Hacl.Impl.Poly1305.Field32xN.felem", "Hacl.Impl.Poly1305.Field32xN.precomp_r", "Hacl.Spec.Poly1305.Field32xN.uint64xN", "Lib.Buffer.op_Array_Assignment", "FStar.UInt32.__uint_to_t", "Prims.unit", "Hacl.Spec.Poly1305.Field32xN.felem5", "Hacl.Spec.Poly1305.Field32xN.fmul_r2_normalize5", "FStar.Pervasives.Native.Mktuple5", "Lib.Buffer.op_Array_Access", "Lib.Buffer.MUT", "Lib.Buffer.lbuffer_t", "FStar.UInt32.uint_to_t", "FStar.UInt32.t", "Lib.Buffer.sub" ]
[]
false
true
false
false
false
let fmul_r2_normalize out p =
let r = sub p 0ul 5ul in let r2 = sub p 10ul 5ul in let a0 = out.(0ul) in let a1 = out.(1ul) in let a2 = out.(2ul) in let a3 = out.(3ul) in let a4 = out.(4ul) in let r10 = r.(0ul) in let r11 = r.(1ul) in let r12 = r.(2ul) in let r13 = r.(3ul) in let r14 = r.(4ul) in let r20 = r2.(0ul) in let r21 = r2.(1ul) in let r22 = r2.(2ul) in let r23 = r2.(3ul) in let r24 = r2.(4ul) in let o0, o1, o2, o3, o4 = fmul_r2_normalize5 (a0, a1, a2, a3, a4) (r10, r11, r12, r13, r14) (r20, r21, r22, r23, r24) in out.(0ul) <- o0; out.(1ul) <- o1; out.(2ul) <- o2; out.(3ul) <- o3; out.(4ul) <- o4
false
Steel.HigherReference.fst
Steel.HigherReference.ghost_ref
val ghost_ref (a:Type u#1) : Type u#0
val ghost_ref (a:Type u#1) : Type u#0
let ghost_ref a = erased (ref a)
{ "file_name": "lib/steel/Steel.HigherReference.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 32, "end_line": 389, "start_col": 0, "start_line": 389 }
(* 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.HigherReference open FStar.Ghost open Steel.Memory open Steel.Effect.Atomic open Steel.Effect open FStar.PCM open Steel.PCMFrac open FStar.Real module RP = Steel.PCMReference #set-options "--ide_id_info_off" module Mem = Steel.Memory let ref a = Mem.ref (fractional a) pcm_frac let null #a = Mem.null #(fractional a) #pcm_frac let is_null #a r = Mem.is_null #(fractional a) #pcm_frac r let perm_ok p : prop = (p.v <=. one == true) /\ True let pts_to_raw_sl (#a:Type) (r:ref a) (p:perm) (v:erased a) : slprop = Mem.pts_to r (Some (Ghost.reveal v, p)) let pts_to_raw (#a:Type) (r:ref a) (p:perm) (v:erased a) : vprop = to_vprop (Mem.pts_to r (Some (Ghost.reveal v, p))) [@@__reduce__] let pts_to' (#a:Type u#1) (r:ref a) (p:perm) (v:erased a) : vprop = pts_to_raw r p v `star` pure (perm_ok p) let pts_to_sl #a r p v = hp_of (pts_to' r p v) let abcd_acbd (a b c d:slprop) : Lemma (Mem.(((a `star` b) `star` (c `star` d)) `equiv` ((a `star` c) `star` (b `star` d)))) = let open Steel.Memory in calc (equiv) { ((a `star` b) `star` (c `star` d)); (equiv) { star_associative a b (c `star` d) } ((a `star` (b `star` (c `star` d)))); (equiv) { star_associative b c d; star_congruence a (b `star` (c `star` d)) a ((b `star` c) `star` d) } (a `star` ((b `star` c) `star` d)); (equiv) { star_commutative b c; star_congruence (b `star` c) d (c `star` b) d; star_congruence a ((b `star` c) `star` d) a ((c `star` b) `star` d) } (a `star` ((c `star` b) `star` d)); (equiv) { star_associative c b d; star_congruence a ((c `star` b) `star` d) a (c `star` (b `star` d)) } (a `star` (c `star` (b `star` d))); (equiv) { star_associative a c (b `star` d) } ((a `star` c) `star` (b `star` d)); } let pts_to_ref_injective (#a: Type u#1) (r: ref a) (p0 p1:perm) (v0 v1:a) (m:mem) : Lemma (requires interp (pts_to_sl r p0 v0 `Mem.star` pts_to_sl r p1 v1) m) (ensures v0 == v1) = let open Steel.Memory in abcd_acbd (hp_of (pts_to_raw r p0 v0)) (pure (perm_ok p0)) (hp_of (pts_to_raw r p1 v1)) (pure (perm_ok p1)); Mem.affine_star (hp_of (pts_to_raw r p0 v0) `star` hp_of (pts_to_raw r p1 v1)) (pure (perm_ok p0) `star` pure (perm_ok p1)) m; Mem.pts_to_compatible r (Some (Ghost.reveal v0, p0)) (Some (Ghost.reveal v1, p1)) m let pts_to_not_null (#a:Type u#1) (r:ref a) (p:perm) (v:a) (m:mem) : Lemma (requires interp (pts_to_sl r p v) m) (ensures r =!= null) = Mem.affine_star (hp_of (pts_to_raw r p v)) (Mem.pure (perm_ok p)) m; Mem.pts_to_not_null r (Some (Ghost.reveal v, p)) m let pts_to_witinv (#a:Type) (r:ref a) (p:perm) : Lemma (is_witness_invariant (pts_to_sl r p)) = let aux (x y : erased a) (m:mem) : Lemma (requires (interp (pts_to_sl r p x) m /\ interp (pts_to_sl r p y) m)) (ensures (x == y)) = Mem.pts_to_join r (Some (Ghost.reveal x, p)) (Some (Ghost.reveal y, p)) m in Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y)) let higher_ref_pts_to_injective_eq #a #opened #p0 #p1 #v0 #v1 r = extract_info_raw (pts_to r p0 v0 `star` pts_to r p1 v1) (v0 == v1) (fun m -> pts_to_ref_injective r p0 p1 v0 v1 m); rewrite_slprop (pts_to r p1 v1) (pts_to r p1 v0) (fun _ -> ()) let pts_to_framon (#a:Type) (r:ref a) (p:perm) : Lemma (is_frame_monotonic (pts_to_sl r p)) = pts_to_witinv r p let intro_pts_to (p:perm) #a #uses (#v:erased a) (r:ref a) : SteelGhost unit uses (pts_to_raw r p v) (fun _ -> pts_to r p v) (requires fun _ -> perm_ok p) (ensures fun _ _ _ -> True) = intro_pure (perm_ok p); rewrite_slprop (pts_to' r p v) (pts_to r p v) (fun _ -> ()) let pts_to_perm #_ #_ #p #v r = rewrite_slprop (pts_to r p v) (pts_to' r p v) (fun _ -> ()); elim_pure (perm_ok p); intro_pure (perm_ok p); rewrite_slprop (pts_to' r p v) (pts_to r p v) (fun _ -> ()) let alloc #a x = let v = Some (x, full_perm) in assert (FStar.PCM.composable pcm_frac v None); assert (compatible pcm_frac v v); let r = RP.alloc v in rewrite_slprop (RP.pts_to r v) (pts_to r full_perm x) (fun m -> emp_unit (hp_of (pts_to_raw r full_perm x)); pure_star_interp (hp_of (pts_to_raw r full_perm x)) (perm_ok full_perm) m ); extract_info_raw (pts_to r full_perm x) (~ (is_null r)) (fun m -> pts_to_not_null r full_perm x m); return r let read (#a:Type) (#p:perm) (#v:erased a) (r:ref a) = let v1 : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, p)) in rewrite_slprop (pts_to r p v) (RP.pts_to r v1 `star` pure (perm_ok p)) (fun _ -> ()); elim_pure (perm_ok p); let v2 = RP.read r v1 in rewrite_slprop (RP.pts_to r v1) (pts_to r p v) (fun m -> emp_unit (hp_of (pts_to_raw r p v)); pure_star_interp (hp_of (pts_to_raw r p v)) (perm_ok p) m); assert (compatible pcm_frac v1 v2); let Some (x, _) = v2 in rewrite_slprop (pts_to r p v) (pts_to r p x) (fun _ -> ()); return x let atomic_read (#opened:_) (#a:Type) (#p:perm) (#v:erased a) (r:ref a) = let v1 : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, p)) in rewrite_slprop (pts_to r p v) (RP.pts_to r v1 `star` pure (perm_ok p)) (fun _ -> ()); elim_pure (perm_ok p); let v2 = RP.atomic_read r v1 in rewrite_slprop (RP.pts_to r v1) (pts_to r p v) (fun m -> emp_unit (hp_of (pts_to_raw r p v)); pure_star_interp (hp_of (pts_to_raw r p v)) (perm_ok p) m); assert (compatible pcm_frac v1 v2); let Some (x, _) = v2 in rewrite_slprop (pts_to r p v) (pts_to r p x) (fun _ -> ()); return x let read_refine (#a:Type) (#p:perm) (q:a -> vprop) (r:ref a) : SteelT a (h_exists (fun (v:a) -> pts_to r p v `star` q v)) (fun v -> pts_to r p v `star` q v) = let vs:erased a = witness_exists () in rewrite_slprop (pts_to r p (Ghost.hide (Ghost.reveal vs))) (pts_to r p vs) (fun _ -> ()); let v = read r in rewrite_slprop (q vs) (q v) (fun _ -> ()); return v let write (#a:Type) (#v:erased a) (r:ref a) (x:a) : SteelT unit (pts_to r full_perm v) (fun _ -> pts_to r full_perm x) = let v_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, full_perm)) in let v_new : fractional a = Some (x, full_perm) in rewrite_slprop (pts_to r full_perm v) (RP.pts_to r v_old `star` pure (perm_ok full_perm)) (fun _ -> ()); elim_pure (perm_ok full_perm); RP.write r v_old v_new; rewrite_slprop (RP.pts_to r v_new) (pts_to r full_perm x) (fun m -> emp_unit (hp_of (pts_to_raw r full_perm x)); pure_star_interp (hp_of (pts_to_raw r full_perm x)) (perm_ok full_perm) m) let atomic_write #opened #a #v r x = let v_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, full_perm)) in let v_new : fractional a = Some (x, full_perm) in rewrite_slprop (pts_to r full_perm v) (RP.pts_to r v_old `star` pure (perm_ok full_perm)) (fun _ -> ()); elim_pure (perm_ok full_perm); RP.atomic_write r v_old v_new; rewrite_slprop (RP.pts_to r v_new) (pts_to r full_perm x) (fun m -> emp_unit (hp_of (pts_to_raw r full_perm x)); pure_star_interp (hp_of (pts_to_raw r full_perm x)) (perm_ok full_perm) m) let free (#a:Type) (#v:erased a) (r:ref a) : SteelT unit (pts_to r full_perm v) (fun _ -> emp) = let v_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, full_perm)) in rewrite_slprop (pts_to r full_perm v) (RP.pts_to r v_old `star` pure (perm_ok full_perm)) (fun _ -> ()); elim_pure (perm_ok full_perm); RP.free r v_old; drop (RP.pts_to r (Mkpcm'?.one (Mkpcm?.p pcm_frac))) let share_atomic_raw_gen #a #uses (#p:perm) (r:ref a{perm_ok p}) (v0:erased a) (p1 p2: perm) : SteelGhost unit uses (pts_to_raw r p v0) (fun _ -> pts_to_raw r p1 v0 `star` pts_to_raw r p2 v0) (fun _ -> p == p1 `sum_perm` p2) (fun _ _ _ -> True) = rewrite_slprop (pts_to_raw r p v0) (RP.pts_to r _) (fun _ -> ()); RP.split r (Some (Ghost.reveal v0, p)) (Some (Ghost.reveal v0, p1)) (Some (Ghost.reveal v0, p2)); rewrite_slprop (RP.pts_to r _) (pts_to_raw r p1 v0) (fun _ -> ()); rewrite_slprop (RP.pts_to r _) (pts_to_raw r p2 v0) (fun _ -> ()) let share_atomic_raw #a #uses (#p:perm) (r:ref a{perm_ok p}) (v0:erased a) : SteelGhostT unit uses (pts_to_raw r p v0) (fun _ -> pts_to_raw r (half_perm p) v0 `star` pts_to_raw r (half_perm p) v0) = share_atomic_raw_gen r v0 (half_perm p) (half_perm p) let share_gen (#a:Type) (#uses:_) (#p:perm) (#v:erased a) (r:ref a) (p1 p2: perm) : SteelGhost unit uses (pts_to r p v) (fun _ -> pts_to r p1 v `star` pts_to r p2 v) (fun _ -> p == p1 `sum_perm` p2) (fun _ _ _ -> True) = let v_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, p)) in rewrite_slprop (pts_to r p v) (pts_to' r p v) (fun _ -> ()); elim_pure (perm_ok p); share_atomic_raw_gen r v p1 p2; intro_pts_to p1 r; intro_pts_to p2 r let share (#a:Type) #uses (#p:perm) (#v:erased a) (r:ref a) : SteelGhostT unit uses (pts_to r p v) (fun _ -> pts_to r (half_perm p) v `star` pts_to r (half_perm p) v) = share_gen r (half_perm p) (half_perm p) let gather_atomic_raw (#a:Type) (#uses:_) (#p0 #p1:perm) (r:ref a) (v0:erased a) (v1:erased a) : SteelGhostT (_:unit{v0==v1 /\ perm_ok (sum_perm p0 p1)}) uses (pts_to_raw r p0 v0 `star` pts_to_raw r p1 v1) (fun _ -> pts_to_raw r (sum_perm p0 p1) v0) = rewrite_slprop (pts_to_raw r p0 v0) (RP.pts_to r (Ghost.reveal (Some (Ghost.reveal v0, p0)))) (fun _ -> ()); rewrite_slprop (pts_to_raw r p1 v1) (RP.pts_to r (Ghost.reveal (Some (Ghost.reveal v1, p1)))) (fun _ -> ()); let _ = RP.gather r (Some (Ghost.reveal v0, p0)) (Some (Ghost.reveal v1, p1)) in rewrite_slprop (RP.pts_to r _) (pts_to_raw r (sum_perm p0 p1) v0) (fun _ -> ()) let gather (#a:Type) (#uses:_) (#p0:perm) (#p1:perm) (#v0 #v1:erased a) (r:ref a) = let v0_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v0, p0)) in let v1_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v1, p1)) in rewrite_slprop (pts_to r p0 v0) (pts_to_raw r p0 v0 `star` pure (perm_ok p0)) (fun _ -> ()); rewrite_slprop (pts_to r p1 v1) (pts_to_raw r p1 v1 `star` pure (perm_ok p1)) (fun _ -> ()); elim_pure (perm_ok p0); elim_pure (perm_ok p1); let _ = gather_atomic_raw r v0 v1 in intro_pts_to (sum_perm p0 p1) r let cas_provides #t (r:ref t) (v:Ghost.erased t) (v_new:t) (b:bool) = if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v let equiv_ext_right (p q r:slprop) : Lemma (requires q `Mem.equiv` r) (ensures Mem.((p `star` q) `equiv` (p `star` r))) = let open Steel.Memory in 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 cas_action_helper (p q r s:slprop) (m:mem) : Lemma (requires interp Mem.(p `star` q `star` r `star` s) m) (ensures interp Mem.(p `star` q `star` s) m) = let open Steel.Memory in calc (equiv) { r `star` s; (equiv) { star_commutative r s } s `star` r; }; calc (equiv) { p `star` q `star` r `star` s; (equiv) { Mem.star_associative (p `star` q) r s } (p `star` q) `star` (r `star` s); (equiv) { equiv_ext_right (p `star` q) (r `star` s) (s `star` r) } (p `star` q) `star` (s `star` r); (equiv) { star_associative (p `star` q) s r } (p `star` q `star` s) `star` r; }; assert (interp ((p `star` q `star` s) `star` r) m); affine_star (p `star` q `star` s) r m let cas_action (#t:Type) (eq: (x:t -> y:t -> b:bool{b <==> (x == y)})) (#uses:inames) (r:ref t) (v:Ghost.erased t) (v_old:t) (v_new:t) (fr:slprop) : MstTot (b:bool{b <==> (Ghost.reveal v == v_old)}) uses (pts_to_sl r full_perm v) (cas_provides r v v_new) fr (fun _ -> True) (fun _ _ _ -> True) = let m0 : full_mem = NMSTTotal.get () in let fv = Ghost.hide (Some (Ghost.reveal v, full_perm)) in let fv' = Some (v_new, full_perm) in assert (interp Mem.(pts_to_sl r full_perm v `star` fr `star` locks_invariant uses m0) m0); assert (interp Mem.(pts_to r fv `star` pure (perm_ok full_perm) `star` fr `star` locks_invariant uses m0) m0); cas_action_helper (Mem.pts_to r fv) (Mem.pure (perm_ok full_perm)) fr (locks_invariant uses m0) m0; assert (interp Mem.((pts_to r fv `star` pure (perm_ok full_perm)) `star` locks_invariant uses m0) m0); let fv_actual = Mem.frame (Mem.pure (perm_ok full_perm)) (sel_action uses r fv) fr in assert (compatible pcm_frac fv fv_actual); let Some (v', p) = fv_actual in assert (v == Ghost.hide v'); assert (p == full_perm); let b = if eq v' v_old then (Mem.frame (Mem.pure (perm_ok full_perm)) (upd_action uses r fv fv') fr; true) else false in b (*** GHOST REFERENCES ***)
{ "checked_file": "/", "dependencies": [ "Steel.PCMReference.fsti.checked", "Steel.PCMFrac.fst.checked", "Steel.Memory.fsti.checked", "Steel.Effect.Atomic.fsti.checked", "Steel.Effect.fsti.checked", "prims.fst.checked", "FStar.Real.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked", "FStar.NMSTTotal.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Steel.HigherReference.fst" }
[ { "abbrev": true, "full_module": "Steel.Memory", "short_module": "Mem" }, { "abbrev": true, "full_module": "Steel.PCMReference", "short_module": "RP" }, { "abbrev": false, "full_module": "FStar.Real", "short_module": null }, { "abbrev": false, "full_module": "Steel.PCMFrac", "short_module": null }, { "abbrev": false, "full_module": "FStar.PCM", "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": "FStar.Ghost", "short_module": null }, { "abbrev": true, "full_module": "Steel.Memory", "short_module": "Mem" }, { "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": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "Steel.FractionalPermission", "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
a: Type -> Type0
Prims.Tot
[ "total" ]
[]
[ "FStar.Ghost.erased", "Steel.HigherReference.ref" ]
[]
false
false
false
true
true
let ghost_ref a =
erased (ref a)
false
Steel.HigherReference.fst
Steel.HigherReference.ghost_pts_to_sl
val ghost_pts_to_sl (#a:_) (r:ghost_ref a) (p:perm) (x:a) : slprop u#1
val ghost_pts_to_sl (#a:_) (r:ghost_ref a) (p:perm) (x:a) : slprop u#1
let ghost_pts_to_sl #a (r:ghost_ref a) (p:perm) (x:a) = pts_to_sl (reveal r) p x
{ "file_name": "lib/steel/Steel.HigherReference.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 80, "end_line": 392, "start_col": 0, "start_line": 392 }
(* 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.HigherReference open FStar.Ghost open Steel.Memory open Steel.Effect.Atomic open Steel.Effect open FStar.PCM open Steel.PCMFrac open FStar.Real module RP = Steel.PCMReference #set-options "--ide_id_info_off" module Mem = Steel.Memory let ref a = Mem.ref (fractional a) pcm_frac let null #a = Mem.null #(fractional a) #pcm_frac let is_null #a r = Mem.is_null #(fractional a) #pcm_frac r let perm_ok p : prop = (p.v <=. one == true) /\ True let pts_to_raw_sl (#a:Type) (r:ref a) (p:perm) (v:erased a) : slprop = Mem.pts_to r (Some (Ghost.reveal v, p)) let pts_to_raw (#a:Type) (r:ref a) (p:perm) (v:erased a) : vprop = to_vprop (Mem.pts_to r (Some (Ghost.reveal v, p))) [@@__reduce__] let pts_to' (#a:Type u#1) (r:ref a) (p:perm) (v:erased a) : vprop = pts_to_raw r p v `star` pure (perm_ok p) let pts_to_sl #a r p v = hp_of (pts_to' r p v) let abcd_acbd (a b c d:slprop) : Lemma (Mem.(((a `star` b) `star` (c `star` d)) `equiv` ((a `star` c) `star` (b `star` d)))) = let open Steel.Memory in calc (equiv) { ((a `star` b) `star` (c `star` d)); (equiv) { star_associative a b (c `star` d) } ((a `star` (b `star` (c `star` d)))); (equiv) { star_associative b c d; star_congruence a (b `star` (c `star` d)) a ((b `star` c) `star` d) } (a `star` ((b `star` c) `star` d)); (equiv) { star_commutative b c; star_congruence (b `star` c) d (c `star` b) d; star_congruence a ((b `star` c) `star` d) a ((c `star` b) `star` d) } (a `star` ((c `star` b) `star` d)); (equiv) { star_associative c b d; star_congruence a ((c `star` b) `star` d) a (c `star` (b `star` d)) } (a `star` (c `star` (b `star` d))); (equiv) { star_associative a c (b `star` d) } ((a `star` c) `star` (b `star` d)); } let pts_to_ref_injective (#a: Type u#1) (r: ref a) (p0 p1:perm) (v0 v1:a) (m:mem) : Lemma (requires interp (pts_to_sl r p0 v0 `Mem.star` pts_to_sl r p1 v1) m) (ensures v0 == v1) = let open Steel.Memory in abcd_acbd (hp_of (pts_to_raw r p0 v0)) (pure (perm_ok p0)) (hp_of (pts_to_raw r p1 v1)) (pure (perm_ok p1)); Mem.affine_star (hp_of (pts_to_raw r p0 v0) `star` hp_of (pts_to_raw r p1 v1)) (pure (perm_ok p0) `star` pure (perm_ok p1)) m; Mem.pts_to_compatible r (Some (Ghost.reveal v0, p0)) (Some (Ghost.reveal v1, p1)) m let pts_to_not_null (#a:Type u#1) (r:ref a) (p:perm) (v:a) (m:mem) : Lemma (requires interp (pts_to_sl r p v) m) (ensures r =!= null) = Mem.affine_star (hp_of (pts_to_raw r p v)) (Mem.pure (perm_ok p)) m; Mem.pts_to_not_null r (Some (Ghost.reveal v, p)) m let pts_to_witinv (#a:Type) (r:ref a) (p:perm) : Lemma (is_witness_invariant (pts_to_sl r p)) = let aux (x y : erased a) (m:mem) : Lemma (requires (interp (pts_to_sl r p x) m /\ interp (pts_to_sl r p y) m)) (ensures (x == y)) = Mem.pts_to_join r (Some (Ghost.reveal x, p)) (Some (Ghost.reveal y, p)) m in Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y)) let higher_ref_pts_to_injective_eq #a #opened #p0 #p1 #v0 #v1 r = extract_info_raw (pts_to r p0 v0 `star` pts_to r p1 v1) (v0 == v1) (fun m -> pts_to_ref_injective r p0 p1 v0 v1 m); rewrite_slprop (pts_to r p1 v1) (pts_to r p1 v0) (fun _ -> ()) let pts_to_framon (#a:Type) (r:ref a) (p:perm) : Lemma (is_frame_monotonic (pts_to_sl r p)) = pts_to_witinv r p let intro_pts_to (p:perm) #a #uses (#v:erased a) (r:ref a) : SteelGhost unit uses (pts_to_raw r p v) (fun _ -> pts_to r p v) (requires fun _ -> perm_ok p) (ensures fun _ _ _ -> True) = intro_pure (perm_ok p); rewrite_slprop (pts_to' r p v) (pts_to r p v) (fun _ -> ()) let pts_to_perm #_ #_ #p #v r = rewrite_slprop (pts_to r p v) (pts_to' r p v) (fun _ -> ()); elim_pure (perm_ok p); intro_pure (perm_ok p); rewrite_slprop (pts_to' r p v) (pts_to r p v) (fun _ -> ()) let alloc #a x = let v = Some (x, full_perm) in assert (FStar.PCM.composable pcm_frac v None); assert (compatible pcm_frac v v); let r = RP.alloc v in rewrite_slprop (RP.pts_to r v) (pts_to r full_perm x) (fun m -> emp_unit (hp_of (pts_to_raw r full_perm x)); pure_star_interp (hp_of (pts_to_raw r full_perm x)) (perm_ok full_perm) m ); extract_info_raw (pts_to r full_perm x) (~ (is_null r)) (fun m -> pts_to_not_null r full_perm x m); return r let read (#a:Type) (#p:perm) (#v:erased a) (r:ref a) = let v1 : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, p)) in rewrite_slprop (pts_to r p v) (RP.pts_to r v1 `star` pure (perm_ok p)) (fun _ -> ()); elim_pure (perm_ok p); let v2 = RP.read r v1 in rewrite_slprop (RP.pts_to r v1) (pts_to r p v) (fun m -> emp_unit (hp_of (pts_to_raw r p v)); pure_star_interp (hp_of (pts_to_raw r p v)) (perm_ok p) m); assert (compatible pcm_frac v1 v2); let Some (x, _) = v2 in rewrite_slprop (pts_to r p v) (pts_to r p x) (fun _ -> ()); return x let atomic_read (#opened:_) (#a:Type) (#p:perm) (#v:erased a) (r:ref a) = let v1 : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, p)) in rewrite_slprop (pts_to r p v) (RP.pts_to r v1 `star` pure (perm_ok p)) (fun _ -> ()); elim_pure (perm_ok p); let v2 = RP.atomic_read r v1 in rewrite_slprop (RP.pts_to r v1) (pts_to r p v) (fun m -> emp_unit (hp_of (pts_to_raw r p v)); pure_star_interp (hp_of (pts_to_raw r p v)) (perm_ok p) m); assert (compatible pcm_frac v1 v2); let Some (x, _) = v2 in rewrite_slprop (pts_to r p v) (pts_to r p x) (fun _ -> ()); return x let read_refine (#a:Type) (#p:perm) (q:a -> vprop) (r:ref a) : SteelT a (h_exists (fun (v:a) -> pts_to r p v `star` q v)) (fun v -> pts_to r p v `star` q v) = let vs:erased a = witness_exists () in rewrite_slprop (pts_to r p (Ghost.hide (Ghost.reveal vs))) (pts_to r p vs) (fun _ -> ()); let v = read r in rewrite_slprop (q vs) (q v) (fun _ -> ()); return v let write (#a:Type) (#v:erased a) (r:ref a) (x:a) : SteelT unit (pts_to r full_perm v) (fun _ -> pts_to r full_perm x) = let v_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, full_perm)) in let v_new : fractional a = Some (x, full_perm) in rewrite_slprop (pts_to r full_perm v) (RP.pts_to r v_old `star` pure (perm_ok full_perm)) (fun _ -> ()); elim_pure (perm_ok full_perm); RP.write r v_old v_new; rewrite_slprop (RP.pts_to r v_new) (pts_to r full_perm x) (fun m -> emp_unit (hp_of (pts_to_raw r full_perm x)); pure_star_interp (hp_of (pts_to_raw r full_perm x)) (perm_ok full_perm) m) let atomic_write #opened #a #v r x = let v_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, full_perm)) in let v_new : fractional a = Some (x, full_perm) in rewrite_slprop (pts_to r full_perm v) (RP.pts_to r v_old `star` pure (perm_ok full_perm)) (fun _ -> ()); elim_pure (perm_ok full_perm); RP.atomic_write r v_old v_new; rewrite_slprop (RP.pts_to r v_new) (pts_to r full_perm x) (fun m -> emp_unit (hp_of (pts_to_raw r full_perm x)); pure_star_interp (hp_of (pts_to_raw r full_perm x)) (perm_ok full_perm) m) let free (#a:Type) (#v:erased a) (r:ref a) : SteelT unit (pts_to r full_perm v) (fun _ -> emp) = let v_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, full_perm)) in rewrite_slprop (pts_to r full_perm v) (RP.pts_to r v_old `star` pure (perm_ok full_perm)) (fun _ -> ()); elim_pure (perm_ok full_perm); RP.free r v_old; drop (RP.pts_to r (Mkpcm'?.one (Mkpcm?.p pcm_frac))) let share_atomic_raw_gen #a #uses (#p:perm) (r:ref a{perm_ok p}) (v0:erased a) (p1 p2: perm) : SteelGhost unit uses (pts_to_raw r p v0) (fun _ -> pts_to_raw r p1 v0 `star` pts_to_raw r p2 v0) (fun _ -> p == p1 `sum_perm` p2) (fun _ _ _ -> True) = rewrite_slprop (pts_to_raw r p v0) (RP.pts_to r _) (fun _ -> ()); RP.split r (Some (Ghost.reveal v0, p)) (Some (Ghost.reveal v0, p1)) (Some (Ghost.reveal v0, p2)); rewrite_slprop (RP.pts_to r _) (pts_to_raw r p1 v0) (fun _ -> ()); rewrite_slprop (RP.pts_to r _) (pts_to_raw r p2 v0) (fun _ -> ()) let share_atomic_raw #a #uses (#p:perm) (r:ref a{perm_ok p}) (v0:erased a) : SteelGhostT unit uses (pts_to_raw r p v0) (fun _ -> pts_to_raw r (half_perm p) v0 `star` pts_to_raw r (half_perm p) v0) = share_atomic_raw_gen r v0 (half_perm p) (half_perm p) let share_gen (#a:Type) (#uses:_) (#p:perm) (#v:erased a) (r:ref a) (p1 p2: perm) : SteelGhost unit uses (pts_to r p v) (fun _ -> pts_to r p1 v `star` pts_to r p2 v) (fun _ -> p == p1 `sum_perm` p2) (fun _ _ _ -> True) = let v_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, p)) in rewrite_slprop (pts_to r p v) (pts_to' r p v) (fun _ -> ()); elim_pure (perm_ok p); share_atomic_raw_gen r v p1 p2; intro_pts_to p1 r; intro_pts_to p2 r let share (#a:Type) #uses (#p:perm) (#v:erased a) (r:ref a) : SteelGhostT unit uses (pts_to r p v) (fun _ -> pts_to r (half_perm p) v `star` pts_to r (half_perm p) v) = share_gen r (half_perm p) (half_perm p) let gather_atomic_raw (#a:Type) (#uses:_) (#p0 #p1:perm) (r:ref a) (v0:erased a) (v1:erased a) : SteelGhostT (_:unit{v0==v1 /\ perm_ok (sum_perm p0 p1)}) uses (pts_to_raw r p0 v0 `star` pts_to_raw r p1 v1) (fun _ -> pts_to_raw r (sum_perm p0 p1) v0) = rewrite_slprop (pts_to_raw r p0 v0) (RP.pts_to r (Ghost.reveal (Some (Ghost.reveal v0, p0)))) (fun _ -> ()); rewrite_slprop (pts_to_raw r p1 v1) (RP.pts_to r (Ghost.reveal (Some (Ghost.reveal v1, p1)))) (fun _ -> ()); let _ = RP.gather r (Some (Ghost.reveal v0, p0)) (Some (Ghost.reveal v1, p1)) in rewrite_slprop (RP.pts_to r _) (pts_to_raw r (sum_perm p0 p1) v0) (fun _ -> ()) let gather (#a:Type) (#uses:_) (#p0:perm) (#p1:perm) (#v0 #v1:erased a) (r:ref a) = let v0_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v0, p0)) in let v1_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v1, p1)) in rewrite_slprop (pts_to r p0 v0) (pts_to_raw r p0 v0 `star` pure (perm_ok p0)) (fun _ -> ()); rewrite_slprop (pts_to r p1 v1) (pts_to_raw r p1 v1 `star` pure (perm_ok p1)) (fun _ -> ()); elim_pure (perm_ok p0); elim_pure (perm_ok p1); let _ = gather_atomic_raw r v0 v1 in intro_pts_to (sum_perm p0 p1) r let cas_provides #t (r:ref t) (v:Ghost.erased t) (v_new:t) (b:bool) = if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v let equiv_ext_right (p q r:slprop) : Lemma (requires q `Mem.equiv` r) (ensures Mem.((p `star` q) `equiv` (p `star` r))) = let open Steel.Memory in 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 cas_action_helper (p q r s:slprop) (m:mem) : Lemma (requires interp Mem.(p `star` q `star` r `star` s) m) (ensures interp Mem.(p `star` q `star` s) m) = let open Steel.Memory in calc (equiv) { r `star` s; (equiv) { star_commutative r s } s `star` r; }; calc (equiv) { p `star` q `star` r `star` s; (equiv) { Mem.star_associative (p `star` q) r s } (p `star` q) `star` (r `star` s); (equiv) { equiv_ext_right (p `star` q) (r `star` s) (s `star` r) } (p `star` q) `star` (s `star` r); (equiv) { star_associative (p `star` q) s r } (p `star` q `star` s) `star` r; }; assert (interp ((p `star` q `star` s) `star` r) m); affine_star (p `star` q `star` s) r m let cas_action (#t:Type) (eq: (x:t -> y:t -> b:bool{b <==> (x == y)})) (#uses:inames) (r:ref t) (v:Ghost.erased t) (v_old:t) (v_new:t) (fr:slprop) : MstTot (b:bool{b <==> (Ghost.reveal v == v_old)}) uses (pts_to_sl r full_perm v) (cas_provides r v v_new) fr (fun _ -> True) (fun _ _ _ -> True) = let m0 : full_mem = NMSTTotal.get () in let fv = Ghost.hide (Some (Ghost.reveal v, full_perm)) in let fv' = Some (v_new, full_perm) in assert (interp Mem.(pts_to_sl r full_perm v `star` fr `star` locks_invariant uses m0) m0); assert (interp Mem.(pts_to r fv `star` pure (perm_ok full_perm) `star` fr `star` locks_invariant uses m0) m0); cas_action_helper (Mem.pts_to r fv) (Mem.pure (perm_ok full_perm)) fr (locks_invariant uses m0) m0; assert (interp Mem.((pts_to r fv `star` pure (perm_ok full_perm)) `star` locks_invariant uses m0) m0); let fv_actual = Mem.frame (Mem.pure (perm_ok full_perm)) (sel_action uses r fv) fr in assert (compatible pcm_frac fv fv_actual); let Some (v', p) = fv_actual in assert (v == Ghost.hide v'); assert (p == full_perm); let b = if eq v' v_old then (Mem.frame (Mem.pure (perm_ok full_perm)) (upd_action uses r fv fv') fr; true) else false in b (*** GHOST REFERENCES ***) let ghost_ref a = erased (ref a)
{ "checked_file": "/", "dependencies": [ "Steel.PCMReference.fsti.checked", "Steel.PCMFrac.fst.checked", "Steel.Memory.fsti.checked", "Steel.Effect.Atomic.fsti.checked", "Steel.Effect.fsti.checked", "prims.fst.checked", "FStar.Real.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked", "FStar.NMSTTotal.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Steel.HigherReference.fst" }
[ { "abbrev": true, "full_module": "Steel.Memory", "short_module": "Mem" }, { "abbrev": true, "full_module": "Steel.PCMReference", "short_module": "RP" }, { "abbrev": false, "full_module": "FStar.Real", "short_module": null }, { "abbrev": false, "full_module": "Steel.PCMFrac", "short_module": null }, { "abbrev": false, "full_module": "FStar.PCM", "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": "FStar.Ghost", "short_module": null }, { "abbrev": true, "full_module": "Steel.Memory", "short_module": "Mem" }, { "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": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "Steel.FractionalPermission", "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
r: Steel.HigherReference.ghost_ref a -> p: Steel.FractionalPermission.perm -> x: a -> Steel.Memory.slprop
Prims.Tot
[ "total" ]
[]
[ "Steel.HigherReference.ghost_ref", "Steel.FractionalPermission.perm", "Steel.HigherReference.pts_to_sl", "FStar.Ghost.reveal", "Steel.HigherReference.ref", "Steel.Memory.slprop" ]
[]
false
false
false
true
false
let ghost_pts_to_sl #a (r: ghost_ref a) (p: perm) (x: a) =
pts_to_sl (reveal r) p x
false
Steel.HigherReference.fst
Steel.HigherReference.cas_provides
val cas_provides : r: Steel.HigherReference.ref t -> v: FStar.Ghost.erased t -> v_new: t -> b: Prims.bool -> Steel.Memory.slprop
let cas_provides #t (r:ref t) (v:Ghost.erased t) (v_new:t) (b:bool) = if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v
{ "file_name": "lib/steel/Steel.HigherReference.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 70, "end_line": 308, "start_col": 0, "start_line": 307 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.HigherReference open FStar.Ghost open Steel.Memory open Steel.Effect.Atomic open Steel.Effect open FStar.PCM open Steel.PCMFrac open FStar.Real module RP = Steel.PCMReference #set-options "--ide_id_info_off" module Mem = Steel.Memory let ref a = Mem.ref (fractional a) pcm_frac let null #a = Mem.null #(fractional a) #pcm_frac let is_null #a r = Mem.is_null #(fractional a) #pcm_frac r let perm_ok p : prop = (p.v <=. one == true) /\ True let pts_to_raw_sl (#a:Type) (r:ref a) (p:perm) (v:erased a) : slprop = Mem.pts_to r (Some (Ghost.reveal v, p)) let pts_to_raw (#a:Type) (r:ref a) (p:perm) (v:erased a) : vprop = to_vprop (Mem.pts_to r (Some (Ghost.reveal v, p))) [@@__reduce__] let pts_to' (#a:Type u#1) (r:ref a) (p:perm) (v:erased a) : vprop = pts_to_raw r p v `star` pure (perm_ok p) let pts_to_sl #a r p v = hp_of (pts_to' r p v) let abcd_acbd (a b c d:slprop) : Lemma (Mem.(((a `star` b) `star` (c `star` d)) `equiv` ((a `star` c) `star` (b `star` d)))) = let open Steel.Memory in calc (equiv) { ((a `star` b) `star` (c `star` d)); (equiv) { star_associative a b (c `star` d) } ((a `star` (b `star` (c `star` d)))); (equiv) { star_associative b c d; star_congruence a (b `star` (c `star` d)) a ((b `star` c) `star` d) } (a `star` ((b `star` c) `star` d)); (equiv) { star_commutative b c; star_congruence (b `star` c) d (c `star` b) d; star_congruence a ((b `star` c) `star` d) a ((c `star` b) `star` d) } (a `star` ((c `star` b) `star` d)); (equiv) { star_associative c b d; star_congruence a ((c `star` b) `star` d) a (c `star` (b `star` d)) } (a `star` (c `star` (b `star` d))); (equiv) { star_associative a c (b `star` d) } ((a `star` c) `star` (b `star` d)); } let pts_to_ref_injective (#a: Type u#1) (r: ref a) (p0 p1:perm) (v0 v1:a) (m:mem) : Lemma (requires interp (pts_to_sl r p0 v0 `Mem.star` pts_to_sl r p1 v1) m) (ensures v0 == v1) = let open Steel.Memory in abcd_acbd (hp_of (pts_to_raw r p0 v0)) (pure (perm_ok p0)) (hp_of (pts_to_raw r p1 v1)) (pure (perm_ok p1)); Mem.affine_star (hp_of (pts_to_raw r p0 v0) `star` hp_of (pts_to_raw r p1 v1)) (pure (perm_ok p0) `star` pure (perm_ok p1)) m; Mem.pts_to_compatible r (Some (Ghost.reveal v0, p0)) (Some (Ghost.reveal v1, p1)) m let pts_to_not_null (#a:Type u#1) (r:ref a) (p:perm) (v:a) (m:mem) : Lemma (requires interp (pts_to_sl r p v) m) (ensures r =!= null) = Mem.affine_star (hp_of (pts_to_raw r p v)) (Mem.pure (perm_ok p)) m; Mem.pts_to_not_null r (Some (Ghost.reveal v, p)) m let pts_to_witinv (#a:Type) (r:ref a) (p:perm) : Lemma (is_witness_invariant (pts_to_sl r p)) = let aux (x y : erased a) (m:mem) : Lemma (requires (interp (pts_to_sl r p x) m /\ interp (pts_to_sl r p y) m)) (ensures (x == y)) = Mem.pts_to_join r (Some (Ghost.reveal x, p)) (Some (Ghost.reveal y, p)) m in Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y)) let higher_ref_pts_to_injective_eq #a #opened #p0 #p1 #v0 #v1 r = extract_info_raw (pts_to r p0 v0 `star` pts_to r p1 v1) (v0 == v1) (fun m -> pts_to_ref_injective r p0 p1 v0 v1 m); rewrite_slprop (pts_to r p1 v1) (pts_to r p1 v0) (fun _ -> ()) let pts_to_framon (#a:Type) (r:ref a) (p:perm) : Lemma (is_frame_monotonic (pts_to_sl r p)) = pts_to_witinv r p let intro_pts_to (p:perm) #a #uses (#v:erased a) (r:ref a) : SteelGhost unit uses (pts_to_raw r p v) (fun _ -> pts_to r p v) (requires fun _ -> perm_ok p) (ensures fun _ _ _ -> True) = intro_pure (perm_ok p); rewrite_slprop (pts_to' r p v) (pts_to r p v) (fun _ -> ()) let pts_to_perm #_ #_ #p #v r = rewrite_slprop (pts_to r p v) (pts_to' r p v) (fun _ -> ()); elim_pure (perm_ok p); intro_pure (perm_ok p); rewrite_slprop (pts_to' r p v) (pts_to r p v) (fun _ -> ()) let alloc #a x = let v = Some (x, full_perm) in assert (FStar.PCM.composable pcm_frac v None); assert (compatible pcm_frac v v); let r = RP.alloc v in rewrite_slprop (RP.pts_to r v) (pts_to r full_perm x) (fun m -> emp_unit (hp_of (pts_to_raw r full_perm x)); pure_star_interp (hp_of (pts_to_raw r full_perm x)) (perm_ok full_perm) m ); extract_info_raw (pts_to r full_perm x) (~ (is_null r)) (fun m -> pts_to_not_null r full_perm x m); return r let read (#a:Type) (#p:perm) (#v:erased a) (r:ref a) = let v1 : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, p)) in rewrite_slprop (pts_to r p v) (RP.pts_to r v1 `star` pure (perm_ok p)) (fun _ -> ()); elim_pure (perm_ok p); let v2 = RP.read r v1 in rewrite_slprop (RP.pts_to r v1) (pts_to r p v) (fun m -> emp_unit (hp_of (pts_to_raw r p v)); pure_star_interp (hp_of (pts_to_raw r p v)) (perm_ok p) m); assert (compatible pcm_frac v1 v2); let Some (x, _) = v2 in rewrite_slprop (pts_to r p v) (pts_to r p x) (fun _ -> ()); return x let atomic_read (#opened:_) (#a:Type) (#p:perm) (#v:erased a) (r:ref a) = let v1 : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, p)) in rewrite_slprop (pts_to r p v) (RP.pts_to r v1 `star` pure (perm_ok p)) (fun _ -> ()); elim_pure (perm_ok p); let v2 = RP.atomic_read r v1 in rewrite_slprop (RP.pts_to r v1) (pts_to r p v) (fun m -> emp_unit (hp_of (pts_to_raw r p v)); pure_star_interp (hp_of (pts_to_raw r p v)) (perm_ok p) m); assert (compatible pcm_frac v1 v2); let Some (x, _) = v2 in rewrite_slprop (pts_to r p v) (pts_to r p x) (fun _ -> ()); return x let read_refine (#a:Type) (#p:perm) (q:a -> vprop) (r:ref a) : SteelT a (h_exists (fun (v:a) -> pts_to r p v `star` q v)) (fun v -> pts_to r p v `star` q v) = let vs:erased a = witness_exists () in rewrite_slprop (pts_to r p (Ghost.hide (Ghost.reveal vs))) (pts_to r p vs) (fun _ -> ()); let v = read r in rewrite_slprop (q vs) (q v) (fun _ -> ()); return v let write (#a:Type) (#v:erased a) (r:ref a) (x:a) : SteelT unit (pts_to r full_perm v) (fun _ -> pts_to r full_perm x) = let v_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, full_perm)) in let v_new : fractional a = Some (x, full_perm) in rewrite_slprop (pts_to r full_perm v) (RP.pts_to r v_old `star` pure (perm_ok full_perm)) (fun _ -> ()); elim_pure (perm_ok full_perm); RP.write r v_old v_new; rewrite_slprop (RP.pts_to r v_new) (pts_to r full_perm x) (fun m -> emp_unit (hp_of (pts_to_raw r full_perm x)); pure_star_interp (hp_of (pts_to_raw r full_perm x)) (perm_ok full_perm) m) let atomic_write #opened #a #v r x = let v_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, full_perm)) in let v_new : fractional a = Some (x, full_perm) in rewrite_slprop (pts_to r full_perm v) (RP.pts_to r v_old `star` pure (perm_ok full_perm)) (fun _ -> ()); elim_pure (perm_ok full_perm); RP.atomic_write r v_old v_new; rewrite_slprop (RP.pts_to r v_new) (pts_to r full_perm x) (fun m -> emp_unit (hp_of (pts_to_raw r full_perm x)); pure_star_interp (hp_of (pts_to_raw r full_perm x)) (perm_ok full_perm) m) let free (#a:Type) (#v:erased a) (r:ref a) : SteelT unit (pts_to r full_perm v) (fun _ -> emp) = let v_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, full_perm)) in rewrite_slprop (pts_to r full_perm v) (RP.pts_to r v_old `star` pure (perm_ok full_perm)) (fun _ -> ()); elim_pure (perm_ok full_perm); RP.free r v_old; drop (RP.pts_to r (Mkpcm'?.one (Mkpcm?.p pcm_frac))) let share_atomic_raw_gen #a #uses (#p:perm) (r:ref a{perm_ok p}) (v0:erased a) (p1 p2: perm) : SteelGhost unit uses (pts_to_raw r p v0) (fun _ -> pts_to_raw r p1 v0 `star` pts_to_raw r p2 v0) (fun _ -> p == p1 `sum_perm` p2) (fun _ _ _ -> True) = rewrite_slprop (pts_to_raw r p v0) (RP.pts_to r _) (fun _ -> ()); RP.split r (Some (Ghost.reveal v0, p)) (Some (Ghost.reveal v0, p1)) (Some (Ghost.reveal v0, p2)); rewrite_slprop (RP.pts_to r _) (pts_to_raw r p1 v0) (fun _ -> ()); rewrite_slprop (RP.pts_to r _) (pts_to_raw r p2 v0) (fun _ -> ()) let share_atomic_raw #a #uses (#p:perm) (r:ref a{perm_ok p}) (v0:erased a) : SteelGhostT unit uses (pts_to_raw r p v0) (fun _ -> pts_to_raw r (half_perm p) v0 `star` pts_to_raw r (half_perm p) v0) = share_atomic_raw_gen r v0 (half_perm p) (half_perm p) let share_gen (#a:Type) (#uses:_) (#p:perm) (#v:erased a) (r:ref a) (p1 p2: perm) : SteelGhost unit uses (pts_to r p v) (fun _ -> pts_to r p1 v `star` pts_to r p2 v) (fun _ -> p == p1 `sum_perm` p2) (fun _ _ _ -> True) = let v_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, p)) in rewrite_slprop (pts_to r p v) (pts_to' r p v) (fun _ -> ()); elim_pure (perm_ok p); share_atomic_raw_gen r v p1 p2; intro_pts_to p1 r; intro_pts_to p2 r let share (#a:Type) #uses (#p:perm) (#v:erased a) (r:ref a) : SteelGhostT unit uses (pts_to r p v) (fun _ -> pts_to r (half_perm p) v `star` pts_to r (half_perm p) v) = share_gen r (half_perm p) (half_perm p) let gather_atomic_raw (#a:Type) (#uses:_) (#p0 #p1:perm) (r:ref a) (v0:erased a) (v1:erased a) : SteelGhostT (_:unit{v0==v1 /\ perm_ok (sum_perm p0 p1)}) uses (pts_to_raw r p0 v0 `star` pts_to_raw r p1 v1) (fun _ -> pts_to_raw r (sum_perm p0 p1) v0) = rewrite_slprop (pts_to_raw r p0 v0) (RP.pts_to r (Ghost.reveal (Some (Ghost.reveal v0, p0)))) (fun _ -> ()); rewrite_slprop (pts_to_raw r p1 v1) (RP.pts_to r (Ghost.reveal (Some (Ghost.reveal v1, p1)))) (fun _ -> ()); let _ = RP.gather r (Some (Ghost.reveal v0, p0)) (Some (Ghost.reveal v1, p1)) in rewrite_slprop (RP.pts_to r _) (pts_to_raw r (sum_perm p0 p1) v0) (fun _ -> ()) let gather (#a:Type) (#uses:_) (#p0:perm) (#p1:perm) (#v0 #v1:erased a) (r:ref a) = let v0_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v0, p0)) in let v1_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v1, p1)) in rewrite_slprop (pts_to r p0 v0) (pts_to_raw r p0 v0 `star` pure (perm_ok p0)) (fun _ -> ()); rewrite_slprop (pts_to r p1 v1) (pts_to_raw r p1 v1 `star` pure (perm_ok p1)) (fun _ -> ()); elim_pure (perm_ok p0); elim_pure (perm_ok p1); let _ = gather_atomic_raw r v0 v1 in intro_pts_to (sum_perm p0 p1) r
{ "checked_file": "/", "dependencies": [ "Steel.PCMReference.fsti.checked", "Steel.PCMFrac.fst.checked", "Steel.Memory.fsti.checked", "Steel.Effect.Atomic.fsti.checked", "Steel.Effect.fsti.checked", "prims.fst.checked", "FStar.Real.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked", "FStar.NMSTTotal.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Steel.HigherReference.fst" }
[ { "abbrev": true, "full_module": "Steel.Memory", "short_module": "Mem" }, { "abbrev": true, "full_module": "Steel.PCMReference", "short_module": "RP" }, { "abbrev": false, "full_module": "FStar.Real", "short_module": null }, { "abbrev": false, "full_module": "Steel.PCMFrac", "short_module": null }, { "abbrev": false, "full_module": "FStar.PCM", "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": "FStar.Ghost", "short_module": null }, { "abbrev": true, "full_module": "Steel.Memory", "short_module": "Mem" }, { "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": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "Steel.FractionalPermission", "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
r: Steel.HigherReference.ref t -> v: FStar.Ghost.erased t -> v_new: t -> b: Prims.bool -> Steel.Memory.slprop
Prims.Tot
[ "total" ]
[]
[ "Steel.HigherReference.ref", "FStar.Ghost.erased", "Prims.bool", "Steel.HigherReference.pts_to_sl", "Steel.FractionalPermission.full_perm", "FStar.Ghost.reveal", "Steel.Memory.slprop" ]
[]
false
false
false
true
false
let cas_provides #t (r: ref t) (v: Ghost.erased t) (v_new: t) (b: bool) =
if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v
false
Steel.HigherReference.fst
Steel.HigherReference.pts_to_witinv
val pts_to_witinv (#a:Type) (r:ref a) (p:perm) : Lemma (is_witness_invariant (pts_to_sl r p))
val pts_to_witinv (#a:Type) (r:ref a) (p:perm) : Lemma (is_witness_invariant (pts_to_sl r p))
let pts_to_witinv (#a:Type) (r:ref a) (p:perm) : Lemma (is_witness_invariant (pts_to_sl r p)) = let aux (x y : erased a) (m:mem) : Lemma (requires (interp (pts_to_sl r p x) m /\ interp (pts_to_sl r p y) m)) (ensures (x == y)) = Mem.pts_to_join r (Some (Ghost.reveal x, p)) (Some (Ghost.reveal y, p)) m in Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y))
{ "file_name": "lib/steel/Steel.HigherReference.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 73, "end_line": 106, "start_col": 0, "start_line": 99 }
(* 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.HigherReference open FStar.Ghost open Steel.Memory open Steel.Effect.Atomic open Steel.Effect open FStar.PCM open Steel.PCMFrac open FStar.Real module RP = Steel.PCMReference #set-options "--ide_id_info_off" module Mem = Steel.Memory let ref a = Mem.ref (fractional a) pcm_frac let null #a = Mem.null #(fractional a) #pcm_frac let is_null #a r = Mem.is_null #(fractional a) #pcm_frac r let perm_ok p : prop = (p.v <=. one == true) /\ True let pts_to_raw_sl (#a:Type) (r:ref a) (p:perm) (v:erased a) : slprop = Mem.pts_to r (Some (Ghost.reveal v, p)) let pts_to_raw (#a:Type) (r:ref a) (p:perm) (v:erased a) : vprop = to_vprop (Mem.pts_to r (Some (Ghost.reveal v, p))) [@@__reduce__] let pts_to' (#a:Type u#1) (r:ref a) (p:perm) (v:erased a) : vprop = pts_to_raw r p v `star` pure (perm_ok p) let pts_to_sl #a r p v = hp_of (pts_to' r p v) let abcd_acbd (a b c d:slprop) : Lemma (Mem.(((a `star` b) `star` (c `star` d)) `equiv` ((a `star` c) `star` (b `star` d)))) = let open Steel.Memory in calc (equiv) { ((a `star` b) `star` (c `star` d)); (equiv) { star_associative a b (c `star` d) } ((a `star` (b `star` (c `star` d)))); (equiv) { star_associative b c d; star_congruence a (b `star` (c `star` d)) a ((b `star` c) `star` d) } (a `star` ((b `star` c) `star` d)); (equiv) { star_commutative b c; star_congruence (b `star` c) d (c `star` b) d; star_congruence a ((b `star` c) `star` d) a ((c `star` b) `star` d) } (a `star` ((c `star` b) `star` d)); (equiv) { star_associative c b d; star_congruence a ((c `star` b) `star` d) a (c `star` (b `star` d)) } (a `star` (c `star` (b `star` d))); (equiv) { star_associative a c (b `star` d) } ((a `star` c) `star` (b `star` d)); } let pts_to_ref_injective (#a: Type u#1) (r: ref a) (p0 p1:perm) (v0 v1:a) (m:mem) : Lemma (requires interp (pts_to_sl r p0 v0 `Mem.star` pts_to_sl r p1 v1) m) (ensures v0 == v1) = let open Steel.Memory in abcd_acbd (hp_of (pts_to_raw r p0 v0)) (pure (perm_ok p0)) (hp_of (pts_to_raw r p1 v1)) (pure (perm_ok p1)); Mem.affine_star (hp_of (pts_to_raw r p0 v0) `star` hp_of (pts_to_raw r p1 v1)) (pure (perm_ok p0) `star` pure (perm_ok p1)) m; Mem.pts_to_compatible r (Some (Ghost.reveal v0, p0)) (Some (Ghost.reveal v1, p1)) m let pts_to_not_null (#a:Type u#1) (r:ref a) (p:perm) (v:a) (m:mem) : Lemma (requires interp (pts_to_sl r p v) m) (ensures r =!= null) = Mem.affine_star (hp_of (pts_to_raw r p v)) (Mem.pure (perm_ok p)) m; Mem.pts_to_not_null r (Some (Ghost.reveal v, p)) m
{ "checked_file": "/", "dependencies": [ "Steel.PCMReference.fsti.checked", "Steel.PCMFrac.fst.checked", "Steel.Memory.fsti.checked", "Steel.Effect.Atomic.fsti.checked", "Steel.Effect.fsti.checked", "prims.fst.checked", "FStar.Real.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked", "FStar.NMSTTotal.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Steel.HigherReference.fst" }
[ { "abbrev": true, "full_module": "Steel.Memory", "short_module": "Mem" }, { "abbrev": true, "full_module": "Steel.PCMReference", "short_module": "RP" }, { "abbrev": false, "full_module": "FStar.Real", "short_module": null }, { "abbrev": false, "full_module": "Steel.PCMFrac", "short_module": null }, { "abbrev": false, "full_module": "FStar.PCM", "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": "FStar.Ghost", "short_module": null }, { "abbrev": true, "full_module": "Steel.Memory", "short_module": "Mem" }, { "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": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "Steel.FractionalPermission", "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
r: Steel.HigherReference.ref a -> p: Steel.FractionalPermission.perm -> FStar.Pervasives.Lemma (ensures Steel.Memory.is_witness_invariant (Steel.HigherReference.pts_to_sl r p))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Steel.HigherReference.ref", "Steel.FractionalPermission.perm", "FStar.Classical.forall_intro_3", "FStar.Ghost.erased", "Steel.Memory.mem", "Prims.l_imp", "Prims.l_and", "Steel.Memory.interp", "Steel.HigherReference.pts_to_sl", "FStar.Ghost.reveal", "Prims.eq2", "FStar.Classical.move_requires", "Prims.unit", "Prims.l_True", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern", "Steel.Memory.pts_to_join", "Steel.PCMFrac.fractional", "Steel.PCMFrac.pcm_frac", "FStar.Pervasives.Native.Some", "FStar.Pervasives.Native.tuple2", "FStar.Pervasives.Native.Mktuple2", "Steel.Memory.is_witness_invariant" ]
[]
false
false
true
false
false
let pts_to_witinv (#a: Type) (r: ref a) (p: perm) : Lemma (is_witness_invariant (pts_to_sl r p)) =
let aux (x y: erased a) (m: mem) : Lemma (requires (interp (pts_to_sl r p x) m /\ interp (pts_to_sl r p y) m)) (ensures (x == y)) = Mem.pts_to_join r (Some (Ghost.reveal x, p)) (Some (Ghost.reveal y, p)) m in Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y))
false
Steel.HigherReference.fst
Steel.HigherReference.is_null
val is_null (#a:Type u#1) (r:ref a) : (b:bool{b <==> r == null})
val is_null (#a:Type u#1) (r:ref a) : (b:bool{b <==> r == null})
let is_null #a r = Mem.is_null #(fractional a) #pcm_frac r
{ "file_name": "lib/steel/Steel.HigherReference.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 58, "end_line": 33, "start_col": 0, "start_line": 33 }
(* 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.HigherReference open FStar.Ghost open Steel.Memory open Steel.Effect.Atomic open Steel.Effect open FStar.PCM open Steel.PCMFrac open FStar.Real module RP = Steel.PCMReference #set-options "--ide_id_info_off" module Mem = Steel.Memory let ref a = Mem.ref (fractional a) pcm_frac
{ "checked_file": "/", "dependencies": [ "Steel.PCMReference.fsti.checked", "Steel.PCMFrac.fst.checked", "Steel.Memory.fsti.checked", "Steel.Effect.Atomic.fsti.checked", "Steel.Effect.fsti.checked", "prims.fst.checked", "FStar.Real.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked", "FStar.NMSTTotal.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Steel.HigherReference.fst" }
[ { "abbrev": true, "full_module": "Steel.Memory", "short_module": "Mem" }, { "abbrev": true, "full_module": "Steel.PCMReference", "short_module": "RP" }, { "abbrev": false, "full_module": "FStar.Real", "short_module": null }, { "abbrev": false, "full_module": "Steel.PCMFrac", "short_module": null }, { "abbrev": false, "full_module": "FStar.PCM", "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": "FStar.Ghost", "short_module": null }, { "abbrev": true, "full_module": "Steel.Memory", "short_module": "Mem" }, { "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": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "Steel.FractionalPermission", "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
r: Steel.HigherReference.ref a -> b: Prims.bool{b <==> r == Steel.HigherReference.null}
Prims.Tot
[ "total" ]
[]
[ "Steel.HigherReference.ref", "Steel.Memory.is_null", "Steel.PCMFrac.fractional", "Steel.PCMFrac.pcm_frac", "Prims.bool", "Prims.l_iff", "Prims.b2t", "Prims.eq2", "Steel.HigherReference.null" ]
[]
false
false
false
false
false
let is_null #a r =
Mem.is_null #(fractional a) #pcm_frac r
false
Steel.HigherReference.fst
Steel.HigherReference.abcd_acbd
val abcd_acbd (a b c d: slprop) : Lemma (let open Mem in ((a `star` b) `star` (c `star` d)) `equiv` ((a `star` c) `star` (b `star` d)))
val abcd_acbd (a b c d: slprop) : Lemma (let open Mem in ((a `star` b) `star` (c `star` d)) `equiv` ((a `star` c) `star` (b `star` d)))
let abcd_acbd (a b c d:slprop) : Lemma (Mem.(((a `star` b) `star` (c `star` d)) `equiv` ((a `star` c) `star` (b `star` d)))) = let open Steel.Memory in calc (equiv) { ((a `star` b) `star` (c `star` d)); (equiv) { star_associative a b (c `star` d) } ((a `star` (b `star` (c `star` d)))); (equiv) { star_associative b c d; star_congruence a (b `star` (c `star` d)) a ((b `star` c) `star` d) } (a `star` ((b `star` c) `star` d)); (equiv) { star_commutative b c; star_congruence (b `star` c) d (c `star` b) d; star_congruence a ((b `star` c) `star` d) a ((c `star` b) `star` d) } (a `star` ((c `star` b) `star` d)); (equiv) { star_associative c b d; star_congruence a ((c `star` b) `star` d) a (c `star` (b `star` d)) } (a `star` (c `star` (b `star` d))); (equiv) { star_associative a c (b `star` d) } ((a `star` c) `star` (b `star` d)); }
{ "file_name": "lib/steel/Steel.HigherReference.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 4, "end_line": 66, "start_col": 0, "start_line": 43 }
(* 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.HigherReference open FStar.Ghost open Steel.Memory open Steel.Effect.Atomic open Steel.Effect open FStar.PCM open Steel.PCMFrac open FStar.Real module RP = Steel.PCMReference #set-options "--ide_id_info_off" module Mem = Steel.Memory let ref a = Mem.ref (fractional a) pcm_frac let null #a = Mem.null #(fractional a) #pcm_frac let is_null #a r = Mem.is_null #(fractional a) #pcm_frac r let perm_ok p : prop = (p.v <=. one == true) /\ True let pts_to_raw_sl (#a:Type) (r:ref a) (p:perm) (v:erased a) : slprop = Mem.pts_to r (Some (Ghost.reveal v, p)) let pts_to_raw (#a:Type) (r:ref a) (p:perm) (v:erased a) : vprop = to_vprop (Mem.pts_to r (Some (Ghost.reveal v, p))) [@@__reduce__] let pts_to' (#a:Type u#1) (r:ref a) (p:perm) (v:erased a) : vprop = pts_to_raw r p v `star` pure (perm_ok p) let pts_to_sl #a r p v = hp_of (pts_to' r p v)
{ "checked_file": "/", "dependencies": [ "Steel.PCMReference.fsti.checked", "Steel.PCMFrac.fst.checked", "Steel.Memory.fsti.checked", "Steel.Effect.Atomic.fsti.checked", "Steel.Effect.fsti.checked", "prims.fst.checked", "FStar.Real.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked", "FStar.NMSTTotal.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Steel.HigherReference.fst" }
[ { "abbrev": true, "full_module": "Steel.Memory", "short_module": "Mem" }, { "abbrev": true, "full_module": "Steel.PCMReference", "short_module": "RP" }, { "abbrev": false, "full_module": "FStar.Real", "short_module": null }, { "abbrev": false, "full_module": "Steel.PCMFrac", "short_module": null }, { "abbrev": false, "full_module": "FStar.PCM", "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": "FStar.Ghost", "short_module": null }, { "abbrev": true, "full_module": "Steel.Memory", "short_module": "Mem" }, { "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": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "Steel.FractionalPermission", "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
a: Steel.Memory.slprop -> b: Steel.Memory.slprop -> c: Steel.Memory.slprop -> d: Steel.Memory.slprop -> FStar.Pervasives.Lemma (ensures Steel.Memory.equiv (Steel.Memory.star (Steel.Memory.star a b) (Steel.Memory.star c d)) (Steel.Memory.star (Steel.Memory.star a c) (Steel.Memory.star b d)))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Steel.Memory.slprop", "FStar.Calc.calc_finish", "Steel.Memory.equiv", "Steel.Memory.star", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "Prims.unit", "FStar.Calc.calc_step", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "Steel.Memory.star_associative", "Prims.squash", "Steel.Memory.star_congruence", "Steel.Memory.star_commutative", "Prims.l_True", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let abcd_acbd (a b c d: slprop) : Lemma (let open Mem in ((a `star` b) `star` (c `star` d)) `equiv` ((a `star` c) `star` (b `star` d))) =
let open Steel.Memory in calc (equiv) { ((a `star` b) `star` (c `star` d)); (equiv) { star_associative a b (c `star` d) } ((a `star` (b `star` (c `star` d)))); (equiv) { (star_associative b c d; star_congruence a (b `star` (c `star` d)) a ((b `star` c) `star` d)) } (a `star` ((b `star` c) `star` d)); (equiv) { (star_commutative b c; star_congruence (b `star` c) d (c `star` b) d; star_congruence a ((b `star` c) `star` d) a ((c `star` b) `star` d)) } (a `star` ((c `star` b) `star` d)); (equiv) { (star_associative c b d; star_congruence a ((c `star` b) `star` d) a (c `star` (b `star` d))) } (a `star` (c `star` (b `star` d))); (equiv) { star_associative a c (b `star` d) } ((a `star` c) `star` (b `star` d)); }
false
Steel.HigherReference.fst
Steel.HigherReference.pts_to_not_null
val pts_to_not_null (#a:Type u#1) (x:ref a) (p:perm) (v:a) (m:mem) : Lemma (requires interp (pts_to_sl x p v) m) (ensures x =!= null)
val pts_to_not_null (#a:Type u#1) (x:ref a) (p:perm) (v:a) (m:mem) : Lemma (requires interp (pts_to_sl x p v) m) (ensures x =!= null)
let pts_to_not_null (#a:Type u#1) (r:ref a) (p:perm) (v:a) (m:mem) : Lemma (requires interp (pts_to_sl r p v) m) (ensures r =!= null) = Mem.affine_star (hp_of (pts_to_raw r p v)) (Mem.pure (perm_ok p)) m; Mem.pts_to_not_null r (Some (Ghost.reveal v, p)) m
{ "file_name": "lib/steel/Steel.HigherReference.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 54, "end_line": 97, "start_col": 0, "start_line": 89 }
(* 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.HigherReference open FStar.Ghost open Steel.Memory open Steel.Effect.Atomic open Steel.Effect open FStar.PCM open Steel.PCMFrac open FStar.Real module RP = Steel.PCMReference #set-options "--ide_id_info_off" module Mem = Steel.Memory let ref a = Mem.ref (fractional a) pcm_frac let null #a = Mem.null #(fractional a) #pcm_frac let is_null #a r = Mem.is_null #(fractional a) #pcm_frac r let perm_ok p : prop = (p.v <=. one == true) /\ True let pts_to_raw_sl (#a:Type) (r:ref a) (p:perm) (v:erased a) : slprop = Mem.pts_to r (Some (Ghost.reveal v, p)) let pts_to_raw (#a:Type) (r:ref a) (p:perm) (v:erased a) : vprop = to_vprop (Mem.pts_to r (Some (Ghost.reveal v, p))) [@@__reduce__] let pts_to' (#a:Type u#1) (r:ref a) (p:perm) (v:erased a) : vprop = pts_to_raw r p v `star` pure (perm_ok p) let pts_to_sl #a r p v = hp_of (pts_to' r p v) let abcd_acbd (a b c d:slprop) : Lemma (Mem.(((a `star` b) `star` (c `star` d)) `equiv` ((a `star` c) `star` (b `star` d)))) = let open Steel.Memory in calc (equiv) { ((a `star` b) `star` (c `star` d)); (equiv) { star_associative a b (c `star` d) } ((a `star` (b `star` (c `star` d)))); (equiv) { star_associative b c d; star_congruence a (b `star` (c `star` d)) a ((b `star` c) `star` d) } (a `star` ((b `star` c) `star` d)); (equiv) { star_commutative b c; star_congruence (b `star` c) d (c `star` b) d; star_congruence a ((b `star` c) `star` d) a ((c `star` b) `star` d) } (a `star` ((c `star` b) `star` d)); (equiv) { star_associative c b d; star_congruence a ((c `star` b) `star` d) a (c `star` (b `star` d)) } (a `star` (c `star` (b `star` d))); (equiv) { star_associative a c (b `star` d) } ((a `star` c) `star` (b `star` d)); } let pts_to_ref_injective (#a: Type u#1) (r: ref a) (p0 p1:perm) (v0 v1:a) (m:mem) : Lemma (requires interp (pts_to_sl r p0 v0 `Mem.star` pts_to_sl r p1 v1) m) (ensures v0 == v1) = let open Steel.Memory in abcd_acbd (hp_of (pts_to_raw r p0 v0)) (pure (perm_ok p0)) (hp_of (pts_to_raw r p1 v1)) (pure (perm_ok p1)); Mem.affine_star (hp_of (pts_to_raw r p0 v0) `star` hp_of (pts_to_raw r p1 v1)) (pure (perm_ok p0) `star` pure (perm_ok p1)) m; Mem.pts_to_compatible r (Some (Ghost.reveal v0, p0)) (Some (Ghost.reveal v1, p1)) m
{ "checked_file": "/", "dependencies": [ "Steel.PCMReference.fsti.checked", "Steel.PCMFrac.fst.checked", "Steel.Memory.fsti.checked", "Steel.Effect.Atomic.fsti.checked", "Steel.Effect.fsti.checked", "prims.fst.checked", "FStar.Real.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked", "FStar.NMSTTotal.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Steel.HigherReference.fst" }
[ { "abbrev": true, "full_module": "Steel.Memory", "short_module": "Mem" }, { "abbrev": true, "full_module": "Steel.PCMReference", "short_module": "RP" }, { "abbrev": false, "full_module": "FStar.Real", "short_module": null }, { "abbrev": false, "full_module": "Steel.PCMFrac", "short_module": null }, { "abbrev": false, "full_module": "FStar.PCM", "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": "FStar.Ghost", "short_module": null }, { "abbrev": true, "full_module": "Steel.Memory", "short_module": "Mem" }, { "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": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "Steel.FractionalPermission", "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
x: Steel.HigherReference.ref a -> p: Steel.FractionalPermission.perm -> v: a -> m: Steel.Memory.mem -> FStar.Pervasives.Lemma (requires Steel.Memory.interp (Steel.HigherReference.pts_to_sl x p v) m) (ensures ~(x == Steel.HigherReference.null))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Steel.HigherReference.ref", "Steel.FractionalPermission.perm", "Steel.Memory.mem", "Steel.Memory.pts_to_not_null", "Steel.PCMFrac.fractional", "Steel.PCMFrac.pcm_frac", "FStar.Pervasives.Native.Some", "FStar.Pervasives.Native.tuple2", "FStar.Pervasives.Native.Mktuple2", "FStar.Ghost.reveal", "FStar.Ghost.hide", "Prims.unit", "Steel.Memory.affine_star", "Steel.Effect.Common.hp_of", "Steel.HigherReference.pts_to_raw", "Steel.Memory.pure", "Steel.HigherReference.perm_ok", "Steel.Memory.interp", "Steel.HigherReference.pts_to_sl", "Prims.squash", "Prims.l_not", "Prims.eq2", "Steel.HigherReference.null", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
true
false
true
false
false
let pts_to_not_null (#a: Type u#1) (r: ref a) (p: perm) (v: a) (m: mem) : Lemma (requires interp (pts_to_sl r p v) m) (ensures r =!= null) =
Mem.affine_star (hp_of (pts_to_raw r p v)) (Mem.pure (perm_ok p)) m; Mem.pts_to_not_null r (Some (Ghost.reveal v, p)) m
false
Steel.HigherReference.fst
Steel.HigherReference.pts_to_framon
val pts_to_framon (#a: Type) (r: ref a) (p: perm) : Lemma (is_frame_monotonic (pts_to_sl r p))
val pts_to_framon (#a: Type) (r: ref a) (p: perm) : Lemma (is_frame_monotonic (pts_to_sl r p))
let pts_to_framon (#a:Type) (r:ref a) (p:perm) : Lemma (is_frame_monotonic (pts_to_sl r p)) = pts_to_witinv r p
{ "file_name": "lib/steel/Steel.HigherReference.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 19, "end_line": 114, "start_col": 0, "start_line": 113 }
(* 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.HigherReference open FStar.Ghost open Steel.Memory open Steel.Effect.Atomic open Steel.Effect open FStar.PCM open Steel.PCMFrac open FStar.Real module RP = Steel.PCMReference #set-options "--ide_id_info_off" module Mem = Steel.Memory let ref a = Mem.ref (fractional a) pcm_frac let null #a = Mem.null #(fractional a) #pcm_frac let is_null #a r = Mem.is_null #(fractional a) #pcm_frac r let perm_ok p : prop = (p.v <=. one == true) /\ True let pts_to_raw_sl (#a:Type) (r:ref a) (p:perm) (v:erased a) : slprop = Mem.pts_to r (Some (Ghost.reveal v, p)) let pts_to_raw (#a:Type) (r:ref a) (p:perm) (v:erased a) : vprop = to_vprop (Mem.pts_to r (Some (Ghost.reveal v, p))) [@@__reduce__] let pts_to' (#a:Type u#1) (r:ref a) (p:perm) (v:erased a) : vprop = pts_to_raw r p v `star` pure (perm_ok p) let pts_to_sl #a r p v = hp_of (pts_to' r p v) let abcd_acbd (a b c d:slprop) : Lemma (Mem.(((a `star` b) `star` (c `star` d)) `equiv` ((a `star` c) `star` (b `star` d)))) = let open Steel.Memory in calc (equiv) { ((a `star` b) `star` (c `star` d)); (equiv) { star_associative a b (c `star` d) } ((a `star` (b `star` (c `star` d)))); (equiv) { star_associative b c d; star_congruence a (b `star` (c `star` d)) a ((b `star` c) `star` d) } (a `star` ((b `star` c) `star` d)); (equiv) { star_commutative b c; star_congruence (b `star` c) d (c `star` b) d; star_congruence a ((b `star` c) `star` d) a ((c `star` b) `star` d) } (a `star` ((c `star` b) `star` d)); (equiv) { star_associative c b d; star_congruence a ((c `star` b) `star` d) a (c `star` (b `star` d)) } (a `star` (c `star` (b `star` d))); (equiv) { star_associative a c (b `star` d) } ((a `star` c) `star` (b `star` d)); } let pts_to_ref_injective (#a: Type u#1) (r: ref a) (p0 p1:perm) (v0 v1:a) (m:mem) : Lemma (requires interp (pts_to_sl r p0 v0 `Mem.star` pts_to_sl r p1 v1) m) (ensures v0 == v1) = let open Steel.Memory in abcd_acbd (hp_of (pts_to_raw r p0 v0)) (pure (perm_ok p0)) (hp_of (pts_to_raw r p1 v1)) (pure (perm_ok p1)); Mem.affine_star (hp_of (pts_to_raw r p0 v0) `star` hp_of (pts_to_raw r p1 v1)) (pure (perm_ok p0) `star` pure (perm_ok p1)) m; Mem.pts_to_compatible r (Some (Ghost.reveal v0, p0)) (Some (Ghost.reveal v1, p1)) m let pts_to_not_null (#a:Type u#1) (r:ref a) (p:perm) (v:a) (m:mem) : Lemma (requires interp (pts_to_sl r p v) m) (ensures r =!= null) = Mem.affine_star (hp_of (pts_to_raw r p v)) (Mem.pure (perm_ok p)) m; Mem.pts_to_not_null r (Some (Ghost.reveal v, p)) m let pts_to_witinv (#a:Type) (r:ref a) (p:perm) : Lemma (is_witness_invariant (pts_to_sl r p)) = let aux (x y : erased a) (m:mem) : Lemma (requires (interp (pts_to_sl r p x) m /\ interp (pts_to_sl r p y) m)) (ensures (x == y)) = Mem.pts_to_join r (Some (Ghost.reveal x, p)) (Some (Ghost.reveal y, p)) m in Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y)) let higher_ref_pts_to_injective_eq #a #opened #p0 #p1 #v0 #v1 r = extract_info_raw (pts_to r p0 v0 `star` pts_to r p1 v1) (v0 == v1) (fun m -> pts_to_ref_injective r p0 p1 v0 v1 m); rewrite_slprop (pts_to r p1 v1) (pts_to r p1 v0) (fun _ -> ())
{ "checked_file": "/", "dependencies": [ "Steel.PCMReference.fsti.checked", "Steel.PCMFrac.fst.checked", "Steel.Memory.fsti.checked", "Steel.Effect.Atomic.fsti.checked", "Steel.Effect.fsti.checked", "prims.fst.checked", "FStar.Real.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked", "FStar.NMSTTotal.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Steel.HigherReference.fst" }
[ { "abbrev": true, "full_module": "Steel.Memory", "short_module": "Mem" }, { "abbrev": true, "full_module": "Steel.PCMReference", "short_module": "RP" }, { "abbrev": false, "full_module": "FStar.Real", "short_module": null }, { "abbrev": false, "full_module": "Steel.PCMFrac", "short_module": null }, { "abbrev": false, "full_module": "FStar.PCM", "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": "FStar.Ghost", "short_module": null }, { "abbrev": true, "full_module": "Steel.Memory", "short_module": "Mem" }, { "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": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "Steel.FractionalPermission", "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
r: Steel.HigherReference.ref a -> p: Steel.FractionalPermission.perm -> FStar.Pervasives.Lemma (ensures Steel.Memory.is_frame_monotonic (Steel.HigherReference.pts_to_sl r p))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Steel.HigherReference.ref", "Steel.FractionalPermission.perm", "Steel.HigherReference.pts_to_witinv", "Prims.unit", "Prims.l_True", "Prims.squash", "Steel.Memory.is_frame_monotonic", "Steel.HigherReference.pts_to_sl", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
true
false
true
false
false
let pts_to_framon (#a: Type) (r: ref a) (p: perm) : Lemma (is_frame_monotonic (pts_to_sl r p)) =
pts_to_witinv r p
false
Steel.HigherReference.fst
Steel.HigherReference.pts_to_ref_injective
val pts_to_ref_injective (#a: Type u#1) (r: ref a) (p0 p1:perm) (v0 v1:a) (m:mem) : Lemma (requires interp (pts_to_sl r p0 v0 `Mem.star` pts_to_sl r p1 v1) m) (ensures v0 == v1)
val pts_to_ref_injective (#a: Type u#1) (r: ref a) (p0 p1:perm) (v0 v1:a) (m:mem) : Lemma (requires interp (pts_to_sl r p0 v0 `Mem.star` pts_to_sl r p1 v1) m) (ensures v0 == v1)
let pts_to_ref_injective (#a: Type u#1) (r: ref a) (p0 p1:perm) (v0 v1:a) (m:mem) : Lemma (requires interp (pts_to_sl r p0 v0 `Mem.star` pts_to_sl r p1 v1) m) (ensures v0 == v1) = let open Steel.Memory in abcd_acbd (hp_of (pts_to_raw r p0 v0)) (pure (perm_ok p0)) (hp_of (pts_to_raw r p1 v1)) (pure (perm_ok p1)); Mem.affine_star (hp_of (pts_to_raw r p0 v0) `star` hp_of (pts_to_raw r p1 v1)) (pure (perm_ok p0) `star` pure (perm_ok p1)) m; Mem.pts_to_compatible r (Some (Ghost.reveal v0, p0)) (Some (Ghost.reveal v1, p1)) m
{ "file_name": "lib/steel/Steel.HigherReference.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 31, "end_line": 87, "start_col": 0, "start_line": 68 }
(* 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.HigherReference open FStar.Ghost open Steel.Memory open Steel.Effect.Atomic open Steel.Effect open FStar.PCM open Steel.PCMFrac open FStar.Real module RP = Steel.PCMReference #set-options "--ide_id_info_off" module Mem = Steel.Memory let ref a = Mem.ref (fractional a) pcm_frac let null #a = Mem.null #(fractional a) #pcm_frac let is_null #a r = Mem.is_null #(fractional a) #pcm_frac r let perm_ok p : prop = (p.v <=. one == true) /\ True let pts_to_raw_sl (#a:Type) (r:ref a) (p:perm) (v:erased a) : slprop = Mem.pts_to r (Some (Ghost.reveal v, p)) let pts_to_raw (#a:Type) (r:ref a) (p:perm) (v:erased a) : vprop = to_vprop (Mem.pts_to r (Some (Ghost.reveal v, p))) [@@__reduce__] let pts_to' (#a:Type u#1) (r:ref a) (p:perm) (v:erased a) : vprop = pts_to_raw r p v `star` pure (perm_ok p) let pts_to_sl #a r p v = hp_of (pts_to' r p v) let abcd_acbd (a b c d:slprop) : Lemma (Mem.(((a `star` b) `star` (c `star` d)) `equiv` ((a `star` c) `star` (b `star` d)))) = let open Steel.Memory in calc (equiv) { ((a `star` b) `star` (c `star` d)); (equiv) { star_associative a b (c `star` d) } ((a `star` (b `star` (c `star` d)))); (equiv) { star_associative b c d; star_congruence a (b `star` (c `star` d)) a ((b `star` c) `star` d) } (a `star` ((b `star` c) `star` d)); (equiv) { star_commutative b c; star_congruence (b `star` c) d (c `star` b) d; star_congruence a ((b `star` c) `star` d) a ((c `star` b) `star` d) } (a `star` ((c `star` b) `star` d)); (equiv) { star_associative c b d; star_congruence a ((c `star` b) `star` d) a (c `star` (b `star` d)) } (a `star` (c `star` (b `star` d))); (equiv) { star_associative a c (b `star` d) } ((a `star` c) `star` (b `star` d)); }
{ "checked_file": "/", "dependencies": [ "Steel.PCMReference.fsti.checked", "Steel.PCMFrac.fst.checked", "Steel.Memory.fsti.checked", "Steel.Effect.Atomic.fsti.checked", "Steel.Effect.fsti.checked", "prims.fst.checked", "FStar.Real.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked", "FStar.NMSTTotal.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Steel.HigherReference.fst" }
[ { "abbrev": true, "full_module": "Steel.Memory", "short_module": "Mem" }, { "abbrev": true, "full_module": "Steel.PCMReference", "short_module": "RP" }, { "abbrev": false, "full_module": "FStar.Real", "short_module": null }, { "abbrev": false, "full_module": "Steel.PCMFrac", "short_module": null }, { "abbrev": false, "full_module": "FStar.PCM", "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": "FStar.Ghost", "short_module": null }, { "abbrev": true, "full_module": "Steel.Memory", "short_module": "Mem" }, { "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": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "Steel.FractionalPermission", "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
r: Steel.HigherReference.ref a -> p0: Steel.FractionalPermission.perm -> p1: Steel.FractionalPermission.perm -> v0: a -> v1: a -> m: Steel.Memory.mem -> FStar.Pervasives.Lemma (requires Steel.Memory.interp (Steel.Memory.star (Steel.HigherReference.pts_to_sl r p0 v0) (Steel.HigherReference.pts_to_sl r p1 v1)) m) (ensures v0 == v1)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Steel.HigherReference.ref", "Steel.FractionalPermission.perm", "Steel.Memory.mem", "Steel.Memory.pts_to_compatible", "Steel.PCMFrac.fractional", "Steel.PCMFrac.pcm_frac", "FStar.Pervasives.Native.Some", "FStar.Pervasives.Native.tuple2", "FStar.Pervasives.Native.Mktuple2", "FStar.Ghost.reveal", "FStar.Ghost.hide", "Prims.unit", "Steel.Memory.affine_star", "Steel.Memory.star", "Steel.Effect.Common.hp_of", "Steel.HigherReference.pts_to_raw", "Steel.Memory.pure", "Steel.HigherReference.perm_ok", "Steel.HigherReference.abcd_acbd", "Steel.Memory.interp", "Steel.HigherReference.pts_to_sl", "Prims.squash", "Prims.eq2", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
true
false
true
false
false
let pts_to_ref_injective (#a: Type u#1) (r: ref a) (p0 p1: perm) (v0 v1: a) (m: mem) : Lemma (requires interp ((pts_to_sl r p0 v0) `Mem.star` (pts_to_sl r p1 v1)) m) (ensures v0 == v1) =
let open Steel.Memory in abcd_acbd (hp_of (pts_to_raw r p0 v0)) (pure (perm_ok p0)) (hp_of (pts_to_raw r p1 v1)) (pure (perm_ok p1)); Mem.affine_star ((hp_of (pts_to_raw r p0 v0)) `star` (hp_of (pts_to_raw r p1 v1))) ((pure (perm_ok p0)) `star` (pure (perm_ok p1))) m; Mem.pts_to_compatible r (Some (Ghost.reveal v0, p0)) (Some (Ghost.reveal v1, p1)) m
false
Hacl.Impl.Poly1305.Field32xN_128.fst
Hacl.Impl.Poly1305.Field32xN_128.load_acc2
val load_acc2: acc:felem 2 -> b:lbuffer uint8 32ul -> Stack unit (requires fun h -> live h acc /\ live h b /\ disjoint acc b /\ felem_fits h acc (2, 2, 2, 2, 2)) (ensures fun h0 _ h1 -> modifies (loc acc) h0 h1 /\ felem_fits h1 acc (3, 3, 3, 3, 3) /\ feval h1 acc == Vec.load_acc2 (as_seq h0 b) (feval h0 acc).[0])
val load_acc2: acc:felem 2 -> b:lbuffer uint8 32ul -> Stack unit (requires fun h -> live h acc /\ live h b /\ disjoint acc b /\ felem_fits h acc (2, 2, 2, 2, 2)) (ensures fun h0 _ h1 -> modifies (loc acc) h0 h1 /\ felem_fits h1 acc (3, 3, 3, 3, 3) /\ feval h1 acc == Vec.load_acc2 (as_seq h0 b) (feval h0 acc).[0])
let load_acc2 acc b = push_frame(); let e = create 5ul (zero 2) in load_blocks e b; let acc0 = acc.(0ul) in let acc1 = acc.(1ul) in let acc2 = acc.(2ul) in let acc3 = acc.(3ul) in let acc4 = acc.(4ul) in let e0 = e.(0ul) in let e1 = e.(1ul) in let e2 = e.(2ul) in let e3 = e.(3ul) in let e4 = e.(4ul) in let (acc0, acc1, acc2, acc3, acc4) = load_acc5_2 (acc0, acc1, acc2, acc3, acc4) (e0, e1, e2, e3, e4) in acc.(0ul) <- acc0; acc.(1ul) <- acc1; acc.(2ul) <- acc2; acc.(3ul) <- acc3; acc.(4ul) <- acc4; pop_frame()
{ "file_name": "code/poly1305/Hacl.Impl.Poly1305.Field32xN_128.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 13, "end_line": 57, "start_col": 0, "start_line": 34 }
module Hacl.Impl.Poly1305.Field32xN_128 open FStar.HyperStack open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer include Hacl.Spec.Poly1305.Field32xN open Hacl.Spec.Poly1305.Field32xN.Lemmas module Vec = Hacl.Spec.Poly1305.Vec module ST = FStar.HyperStack.ST open Hacl.Impl.Poly1305.Field32xN /// See comments in Hacl.Impl.Poly1305.Field32xN_256 #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 50 --using_facts_from '* -FStar.Seq'" val load_acc2: acc:felem 2 -> b:lbuffer uint8 32ul -> Stack unit (requires fun h -> live h acc /\ live h b /\ disjoint acc b /\ felem_fits h acc (2, 2, 2, 2, 2)) (ensures fun h0 _ h1 -> modifies (loc acc) h0 h1 /\ felem_fits h1 acc (3, 3, 3, 3, 3) /\
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Poly1305.Vec.fst.checked", "Hacl.Spec.Poly1305.Field32xN.Lemmas.fst.checked", "Hacl.Spec.Poly1305.Field32xN.fst.checked", "Hacl.Impl.Poly1305.Field32xN.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Poly1305.Field32xN_128.fst" }
[ { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Field32xN", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Hacl.Spec.Poly1305.Vec", "short_module": "Vec" }, { "abbrev": false, "full_module": "Hacl.Spec.Poly1305.Field32xN.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Poly1305.Field32xN", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
acc: Hacl.Impl.Poly1305.Field32xN.felem 2 -> b: Lib.Buffer.lbuffer Lib.IntTypes.uint8 32ul -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Hacl.Impl.Poly1305.Field32xN.felem", "Lib.Buffer.lbuffer", "Lib.IntTypes.uint8", "FStar.UInt32.__uint_to_t", "Hacl.Spec.Poly1305.Field32xN.uint64xN", "FStar.HyperStack.ST.pop_frame", "Prims.unit", "Lib.Buffer.op_Array_Assignment", "Hacl.Spec.Poly1305.Field32xN.felem5", "Hacl.Spec.Poly1305.Field32xN.load_acc5_2", "FStar.Pervasives.Native.Mktuple5", "Lib.Buffer.op_Array_Access", "Lib.Buffer.MUT", "Hacl.Impl.Poly1305.Field32xN.load_blocks", "Lib.Buffer.lbuffer_t", "FStar.UInt32.uint_to_t", "FStar.UInt32.t", "Lib.Buffer.create", "Hacl.Spec.Poly1305.Field32xN.zero", "FStar.HyperStack.ST.push_frame" ]
[]
false
true
false
false
false
let load_acc2 acc b =
push_frame (); let e = create 5ul (zero 2) in load_blocks e b; let acc0 = acc.(0ul) in let acc1 = acc.(1ul) in let acc2 = acc.(2ul) in let acc3 = acc.(3ul) in let acc4 = acc.(4ul) in let e0 = e.(0ul) in let e1 = e.(1ul) in let e2 = e.(2ul) in let e3 = e.(3ul) in let e4 = e.(4ul) in let acc0, acc1, acc2, acc3, acc4 = load_acc5_2 (acc0, acc1, acc2, acc3, acc4) (e0, e1, e2, e3, e4) in acc.(0ul) <- acc0; acc.(1ul) <- acc1; acc.(2ul) <- acc2; acc.(3ul) <- acc3; acc.(4ul) <- acc4; pop_frame ()
false
LatticeEff.fst
LatticeEff.wpof2
val wpof2 (#a: _) (l: list eff_label) : wp a
val wpof2 (#a: _) (l: list eff_label) : wp a
let wpof2 #a (l : list eff_label) : wp a = let i = interp l in let wp : wp a = fun p s0 -> (forall r s1. (i WR == false ==> s1 == s0) ==> (i EXN == false ==> V? r) ==> p r s1) in wp
{ "file_name": "examples/layeredeffects/LatticeEff.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 4, "end_line": 51, "start_col": 0, "start_line": 43 }
module LatticeEff open FStar.Tactics.V2 open FStar.List.Tot open FStar.All module H = FStar.Heap // GM: Force a type equality by SMT let coerce #a #b (x:a{a == b}) : b = x let unreachable #a () : Pure a (requires False) (ensures (fun _ -> False)) = coerce "whatever" type eff_label = // GM: Can we do this one? ALL's WPs are unary and this is a // relational property. // | RD | WR //| DIV | EXN type annot = eff_label -> bool let interp (l : list eff_label) : annot = fun lab -> mem lab l type state = H.heap type wp a = all_wp_h H.heap a // boring, exponential //let wpof1 #a (l : list eff_label) : all_wp_h H.heap a = // let i = interp l in // match i ST, i EXN with // | false, false -> // fun p s0 -> forall x. p (V x) s0 // | true , false -> // fun p s0 -> forall x s1. p (V x) s1 // | false, true -> // fun p s0 -> forall r. p r s0 // | true, true -> // fun p s0 -> forall r s1. p r s1
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Heap.fst.checked", "FStar.Classical.fsti.checked", "FStar.All.fst.checked" ], "interface_file": false, "source_file": "LatticeEff.fst" }
[ { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
l: Prims.list LatticeEff.eff_label -> LatticeEff.wp a
Prims.Tot
[ "total" ]
[]
[ "Prims.list", "LatticeEff.eff_label", "LatticeEff.wp", "FStar.Pervasives.all_post_h", "FStar.Monotonic.Heap.heap", "Prims.l_Forall", "FStar.Pervasives.result", "Prims.l_True", "Prims.l_imp", "Prims.eq2", "Prims.bool", "LatticeEff.WR", "LatticeEff.EXN", "Prims.b2t", "FStar.Pervasives.uu___is_V", "LatticeEff.annot", "LatticeEff.interp" ]
[]
false
false
false
true
false
let wpof2 #a (l: list eff_label) : wp a =
let i = interp l in let wp:wp a = fun p s0 -> (forall r s1. (i WR == false ==> s1 == s0) ==> (i EXN == false ==> V? r) ==> p r s1) in wp
false
Steel.HigherReference.fst
Steel.HigherReference.equiv_ext_right
val equiv_ext_right (p q r: slprop) : Lemma (requires q `Mem.equiv` r) (ensures Mem.((p `star` q) `equiv` (p `star` r)))
val equiv_ext_right (p q r: slprop) : Lemma (requires q `Mem.equiv` r) (ensures Mem.((p `star` q) `equiv` (p `star` r)))
let equiv_ext_right (p q r:slprop) : Lemma (requires q `Mem.equiv` r) (ensures Mem.((p `star` q) `equiv` (p `star` r))) = let open Steel.Memory in 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; }
{ "file_name": "lib/steel/Steel.HigherReference.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 5, "end_line": 323, "start_col": 0, "start_line": 310 }
(* 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.HigherReference open FStar.Ghost open Steel.Memory open Steel.Effect.Atomic open Steel.Effect open FStar.PCM open Steel.PCMFrac open FStar.Real module RP = Steel.PCMReference #set-options "--ide_id_info_off" module Mem = Steel.Memory let ref a = Mem.ref (fractional a) pcm_frac let null #a = Mem.null #(fractional a) #pcm_frac let is_null #a r = Mem.is_null #(fractional a) #pcm_frac r let perm_ok p : prop = (p.v <=. one == true) /\ True let pts_to_raw_sl (#a:Type) (r:ref a) (p:perm) (v:erased a) : slprop = Mem.pts_to r (Some (Ghost.reveal v, p)) let pts_to_raw (#a:Type) (r:ref a) (p:perm) (v:erased a) : vprop = to_vprop (Mem.pts_to r (Some (Ghost.reveal v, p))) [@@__reduce__] let pts_to' (#a:Type u#1) (r:ref a) (p:perm) (v:erased a) : vprop = pts_to_raw r p v `star` pure (perm_ok p) let pts_to_sl #a r p v = hp_of (pts_to' r p v) let abcd_acbd (a b c d:slprop) : Lemma (Mem.(((a `star` b) `star` (c `star` d)) `equiv` ((a `star` c) `star` (b `star` d)))) = let open Steel.Memory in calc (equiv) { ((a `star` b) `star` (c `star` d)); (equiv) { star_associative a b (c `star` d) } ((a `star` (b `star` (c `star` d)))); (equiv) { star_associative b c d; star_congruence a (b `star` (c `star` d)) a ((b `star` c) `star` d) } (a `star` ((b `star` c) `star` d)); (equiv) { star_commutative b c; star_congruence (b `star` c) d (c `star` b) d; star_congruence a ((b `star` c) `star` d) a ((c `star` b) `star` d) } (a `star` ((c `star` b) `star` d)); (equiv) { star_associative c b d; star_congruence a ((c `star` b) `star` d) a (c `star` (b `star` d)) } (a `star` (c `star` (b `star` d))); (equiv) { star_associative a c (b `star` d) } ((a `star` c) `star` (b `star` d)); } let pts_to_ref_injective (#a: Type u#1) (r: ref a) (p0 p1:perm) (v0 v1:a) (m:mem) : Lemma (requires interp (pts_to_sl r p0 v0 `Mem.star` pts_to_sl r p1 v1) m) (ensures v0 == v1) = let open Steel.Memory in abcd_acbd (hp_of (pts_to_raw r p0 v0)) (pure (perm_ok p0)) (hp_of (pts_to_raw r p1 v1)) (pure (perm_ok p1)); Mem.affine_star (hp_of (pts_to_raw r p0 v0) `star` hp_of (pts_to_raw r p1 v1)) (pure (perm_ok p0) `star` pure (perm_ok p1)) m; Mem.pts_to_compatible r (Some (Ghost.reveal v0, p0)) (Some (Ghost.reveal v1, p1)) m let pts_to_not_null (#a:Type u#1) (r:ref a) (p:perm) (v:a) (m:mem) : Lemma (requires interp (pts_to_sl r p v) m) (ensures r =!= null) = Mem.affine_star (hp_of (pts_to_raw r p v)) (Mem.pure (perm_ok p)) m; Mem.pts_to_not_null r (Some (Ghost.reveal v, p)) m let pts_to_witinv (#a:Type) (r:ref a) (p:perm) : Lemma (is_witness_invariant (pts_to_sl r p)) = let aux (x y : erased a) (m:mem) : Lemma (requires (interp (pts_to_sl r p x) m /\ interp (pts_to_sl r p y) m)) (ensures (x == y)) = Mem.pts_to_join r (Some (Ghost.reveal x, p)) (Some (Ghost.reveal y, p)) m in Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y)) let higher_ref_pts_to_injective_eq #a #opened #p0 #p1 #v0 #v1 r = extract_info_raw (pts_to r p0 v0 `star` pts_to r p1 v1) (v0 == v1) (fun m -> pts_to_ref_injective r p0 p1 v0 v1 m); rewrite_slprop (pts_to r p1 v1) (pts_to r p1 v0) (fun _ -> ()) let pts_to_framon (#a:Type) (r:ref a) (p:perm) : Lemma (is_frame_monotonic (pts_to_sl r p)) = pts_to_witinv r p let intro_pts_to (p:perm) #a #uses (#v:erased a) (r:ref a) : SteelGhost unit uses (pts_to_raw r p v) (fun _ -> pts_to r p v) (requires fun _ -> perm_ok p) (ensures fun _ _ _ -> True) = intro_pure (perm_ok p); rewrite_slprop (pts_to' r p v) (pts_to r p v) (fun _ -> ()) let pts_to_perm #_ #_ #p #v r = rewrite_slprop (pts_to r p v) (pts_to' r p v) (fun _ -> ()); elim_pure (perm_ok p); intro_pure (perm_ok p); rewrite_slprop (pts_to' r p v) (pts_to r p v) (fun _ -> ()) let alloc #a x = let v = Some (x, full_perm) in assert (FStar.PCM.composable pcm_frac v None); assert (compatible pcm_frac v v); let r = RP.alloc v in rewrite_slprop (RP.pts_to r v) (pts_to r full_perm x) (fun m -> emp_unit (hp_of (pts_to_raw r full_perm x)); pure_star_interp (hp_of (pts_to_raw r full_perm x)) (perm_ok full_perm) m ); extract_info_raw (pts_to r full_perm x) (~ (is_null r)) (fun m -> pts_to_not_null r full_perm x m); return r let read (#a:Type) (#p:perm) (#v:erased a) (r:ref a) = let v1 : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, p)) in rewrite_slprop (pts_to r p v) (RP.pts_to r v1 `star` pure (perm_ok p)) (fun _ -> ()); elim_pure (perm_ok p); let v2 = RP.read r v1 in rewrite_slprop (RP.pts_to r v1) (pts_to r p v) (fun m -> emp_unit (hp_of (pts_to_raw r p v)); pure_star_interp (hp_of (pts_to_raw r p v)) (perm_ok p) m); assert (compatible pcm_frac v1 v2); let Some (x, _) = v2 in rewrite_slprop (pts_to r p v) (pts_to r p x) (fun _ -> ()); return x let atomic_read (#opened:_) (#a:Type) (#p:perm) (#v:erased a) (r:ref a) = let v1 : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, p)) in rewrite_slprop (pts_to r p v) (RP.pts_to r v1 `star` pure (perm_ok p)) (fun _ -> ()); elim_pure (perm_ok p); let v2 = RP.atomic_read r v1 in rewrite_slprop (RP.pts_to r v1) (pts_to r p v) (fun m -> emp_unit (hp_of (pts_to_raw r p v)); pure_star_interp (hp_of (pts_to_raw r p v)) (perm_ok p) m); assert (compatible pcm_frac v1 v2); let Some (x, _) = v2 in rewrite_slprop (pts_to r p v) (pts_to r p x) (fun _ -> ()); return x let read_refine (#a:Type) (#p:perm) (q:a -> vprop) (r:ref a) : SteelT a (h_exists (fun (v:a) -> pts_to r p v `star` q v)) (fun v -> pts_to r p v `star` q v) = let vs:erased a = witness_exists () in rewrite_slprop (pts_to r p (Ghost.hide (Ghost.reveal vs))) (pts_to r p vs) (fun _ -> ()); let v = read r in rewrite_slprop (q vs) (q v) (fun _ -> ()); return v let write (#a:Type) (#v:erased a) (r:ref a) (x:a) : SteelT unit (pts_to r full_perm v) (fun _ -> pts_to r full_perm x) = let v_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, full_perm)) in let v_new : fractional a = Some (x, full_perm) in rewrite_slprop (pts_to r full_perm v) (RP.pts_to r v_old `star` pure (perm_ok full_perm)) (fun _ -> ()); elim_pure (perm_ok full_perm); RP.write r v_old v_new; rewrite_slprop (RP.pts_to r v_new) (pts_to r full_perm x) (fun m -> emp_unit (hp_of (pts_to_raw r full_perm x)); pure_star_interp (hp_of (pts_to_raw r full_perm x)) (perm_ok full_perm) m) let atomic_write #opened #a #v r x = let v_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, full_perm)) in let v_new : fractional a = Some (x, full_perm) in rewrite_slprop (pts_to r full_perm v) (RP.pts_to r v_old `star` pure (perm_ok full_perm)) (fun _ -> ()); elim_pure (perm_ok full_perm); RP.atomic_write r v_old v_new; rewrite_slprop (RP.pts_to r v_new) (pts_to r full_perm x) (fun m -> emp_unit (hp_of (pts_to_raw r full_perm x)); pure_star_interp (hp_of (pts_to_raw r full_perm x)) (perm_ok full_perm) m) let free (#a:Type) (#v:erased a) (r:ref a) : SteelT unit (pts_to r full_perm v) (fun _ -> emp) = let v_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, full_perm)) in rewrite_slprop (pts_to r full_perm v) (RP.pts_to r v_old `star` pure (perm_ok full_perm)) (fun _ -> ()); elim_pure (perm_ok full_perm); RP.free r v_old; drop (RP.pts_to r (Mkpcm'?.one (Mkpcm?.p pcm_frac))) let share_atomic_raw_gen #a #uses (#p:perm) (r:ref a{perm_ok p}) (v0:erased a) (p1 p2: perm) : SteelGhost unit uses (pts_to_raw r p v0) (fun _ -> pts_to_raw r p1 v0 `star` pts_to_raw r p2 v0) (fun _ -> p == p1 `sum_perm` p2) (fun _ _ _ -> True) = rewrite_slprop (pts_to_raw r p v0) (RP.pts_to r _) (fun _ -> ()); RP.split r (Some (Ghost.reveal v0, p)) (Some (Ghost.reveal v0, p1)) (Some (Ghost.reveal v0, p2)); rewrite_slprop (RP.pts_to r _) (pts_to_raw r p1 v0) (fun _ -> ()); rewrite_slprop (RP.pts_to r _) (pts_to_raw r p2 v0) (fun _ -> ()) let share_atomic_raw #a #uses (#p:perm) (r:ref a{perm_ok p}) (v0:erased a) : SteelGhostT unit uses (pts_to_raw r p v0) (fun _ -> pts_to_raw r (half_perm p) v0 `star` pts_to_raw r (half_perm p) v0) = share_atomic_raw_gen r v0 (half_perm p) (half_perm p) let share_gen (#a:Type) (#uses:_) (#p:perm) (#v:erased a) (r:ref a) (p1 p2: perm) : SteelGhost unit uses (pts_to r p v) (fun _ -> pts_to r p1 v `star` pts_to r p2 v) (fun _ -> p == p1 `sum_perm` p2) (fun _ _ _ -> True) = let v_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, p)) in rewrite_slprop (pts_to r p v) (pts_to' r p v) (fun _ -> ()); elim_pure (perm_ok p); share_atomic_raw_gen r v p1 p2; intro_pts_to p1 r; intro_pts_to p2 r let share (#a:Type) #uses (#p:perm) (#v:erased a) (r:ref a) : SteelGhostT unit uses (pts_to r p v) (fun _ -> pts_to r (half_perm p) v `star` pts_to r (half_perm p) v) = share_gen r (half_perm p) (half_perm p) let gather_atomic_raw (#a:Type) (#uses:_) (#p0 #p1:perm) (r:ref a) (v0:erased a) (v1:erased a) : SteelGhostT (_:unit{v0==v1 /\ perm_ok (sum_perm p0 p1)}) uses (pts_to_raw r p0 v0 `star` pts_to_raw r p1 v1) (fun _ -> pts_to_raw r (sum_perm p0 p1) v0) = rewrite_slprop (pts_to_raw r p0 v0) (RP.pts_to r (Ghost.reveal (Some (Ghost.reveal v0, p0)))) (fun _ -> ()); rewrite_slprop (pts_to_raw r p1 v1) (RP.pts_to r (Ghost.reveal (Some (Ghost.reveal v1, p1)))) (fun _ -> ()); let _ = RP.gather r (Some (Ghost.reveal v0, p0)) (Some (Ghost.reveal v1, p1)) in rewrite_slprop (RP.pts_to r _) (pts_to_raw r (sum_perm p0 p1) v0) (fun _ -> ()) let gather (#a:Type) (#uses:_) (#p0:perm) (#p1:perm) (#v0 #v1:erased a) (r:ref a) = let v0_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v0, p0)) in let v1_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v1, p1)) in rewrite_slprop (pts_to r p0 v0) (pts_to_raw r p0 v0 `star` pure (perm_ok p0)) (fun _ -> ()); rewrite_slprop (pts_to r p1 v1) (pts_to_raw r p1 v1 `star` pure (perm_ok p1)) (fun _ -> ()); elim_pure (perm_ok p0); elim_pure (perm_ok p1); let _ = gather_atomic_raw r v0 v1 in intro_pts_to (sum_perm p0 p1) r let cas_provides #t (r:ref t) (v:Ghost.erased t) (v_new:t) (b:bool) = if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v
{ "checked_file": "/", "dependencies": [ "Steel.PCMReference.fsti.checked", "Steel.PCMFrac.fst.checked", "Steel.Memory.fsti.checked", "Steel.Effect.Atomic.fsti.checked", "Steel.Effect.fsti.checked", "prims.fst.checked", "FStar.Real.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked", "FStar.NMSTTotal.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Steel.HigherReference.fst" }
[ { "abbrev": true, "full_module": "Steel.Memory", "short_module": "Mem" }, { "abbrev": true, "full_module": "Steel.PCMReference", "short_module": "RP" }, { "abbrev": false, "full_module": "FStar.Real", "short_module": null }, { "abbrev": false, "full_module": "Steel.PCMFrac", "short_module": null }, { "abbrev": false, "full_module": "FStar.PCM", "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": "FStar.Ghost", "short_module": null }, { "abbrev": true, "full_module": "Steel.Memory", "short_module": "Mem" }, { "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": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "Steel.FractionalPermission", "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
p: Steel.Memory.slprop -> q: Steel.Memory.slprop -> r: Steel.Memory.slprop -> FStar.Pervasives.Lemma (requires Steel.Memory.equiv q r) (ensures Steel.Memory.equiv (Steel.Memory.star p q) (Steel.Memory.star p r))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Steel.Memory.slprop", "FStar.Calc.calc_finish", "Steel.Memory.equiv", "Steel.Memory.star", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "Prims.unit", "FStar.Calc.calc_step", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "Steel.Memory.star_commutative", "Prims.squash", "Steel.Memory.equiv_extensional_on_star", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let equiv_ext_right (p q r: slprop) : Lemma (requires q `Mem.equiv` r) (ensures Mem.((p `star` q) `equiv` (p `star` r))) =
let open Steel.Memory in 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; }
false
LatticeEff.fst
LatticeEff.ann_le
val ann_le (ann1 ann2: annot) : prop
val ann_le (ann1 ann2: annot) : prop
let ann_le (ann1 ann2 : annot) : prop = forall x. ann1 x ==> ann2 x
{ "file_name": "examples/layeredeffects/LatticeEff.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 29, "end_line": 92, "start_col": 0, "start_line": 91 }
module LatticeEff open FStar.Tactics.V2 open FStar.List.Tot open FStar.All module H = FStar.Heap // GM: Force a type equality by SMT let coerce #a #b (x:a{a == b}) : b = x let unreachable #a () : Pure a (requires False) (ensures (fun _ -> False)) = coerce "whatever" type eff_label = // GM: Can we do this one? ALL's WPs are unary and this is a // relational property. // | RD | WR //| DIV | EXN type annot = eff_label -> bool let interp (l : list eff_label) : annot = fun lab -> mem lab l type state = H.heap type wp a = all_wp_h H.heap a // boring, exponential //let wpof1 #a (l : list eff_label) : all_wp_h H.heap a = // let i = interp l in // match i ST, i EXN with // | false, false -> // fun p s0 -> forall x. p (V x) s0 // | true , false -> // fun p s0 -> forall x s1. p (V x) s1 // | false, true -> // fun p s0 -> forall r. p r s0 // | true, true -> // fun p s0 -> forall r s1. p r s1 (* more generic *) let wpof2 #a (l : list eff_label) : wp a = let i = interp l in let wp : wp a = fun p s0 -> (forall r s1. (i WR == false ==> s1 == s0) ==> (i EXN == false ==> V? r) ==> p r s1) in wp type repr (a:Type u#aa) (labs : list u#0 eff_label) // #2074 : Type u#0 = unit -> ALL a (wpof2 labs) let rec interp_at (l1 l2 : list eff_label) (l : eff_label) : Lemma (interp (l1@l2) l == (interp l1 l || interp l2 l)) [SMTPat (interp (l1@l2) l)] = match l1 with | [] -> () | _::l1 -> interp_at l1 l2 l let sublist (l1 l2 : list eff_label) = forall x. mem x l1 ==> mem x l2 let sublist_refl (l : list eff_label) : Lemma (sublist l l) [SMTPat (sublist l l)] = () let rec interp_sublist (l1 l2 : list eff_label) (l : eff_label) : Lemma (requires (sublist l1 l2)) (ensures (interp l1 l ==> interp l2 l)) [SMTPat (interp l1 l); SMTPat (sublist l1 l2)] = match l1 with | [] -> () | _::l1 -> interp_sublist l1 l2 l let rec sublist_at (l1 l2 : list eff_label) : Lemma (sublist l1 (l1@l2) /\ sublist l2 (l1@l2)) [SMTPatOr [[SMTPat (sublist l1 (l1@l2))]; [SMTPat (sublist l2 (l1@l2))]]] = match l1 with | [] -> () | _::l1 -> sublist_at l1 l2
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Heap.fst.checked", "FStar.Classical.fsti.checked", "FStar.All.fst.checked" ], "interface_file": false, "source_file": "LatticeEff.fst" }
[ { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
ann1: LatticeEff.annot -> ann2: LatticeEff.annot -> Prims.prop
Prims.Tot
[ "total" ]
[]
[ "LatticeEff.annot", "Prims.l_Forall", "LatticeEff.eff_label", "Prims.l_imp", "Prims.b2t", "Prims.prop" ]
[]
false
false
false
true
true
let ann_le (ann1 ann2: annot) : prop =
forall x. ann1 x ==> ann2 x
false
SteelFramingTestSuite.fst
SteelFramingTestSuite.test_if7
val test_if7 (b: bool) (r1 r2: ref) : SteelT unit ((ptr r1) `star` (ptr r2)) (fun _ -> (ptr r1) `star` (ptr r2))
val test_if7 (b: bool) (r1 r2: ref) : SteelT unit ((ptr r1) `star` (ptr r2)) (fun _ -> (ptr r1) `star` (ptr r2))
let test_if7 (b:bool) (r1 r2: ref) : SteelT unit (ptr r1 `star` ptr r2) (fun _ -> ptr r1 `star` ptr r2) = if b then (write r1 0; write r2 0) else (write r2 0; write r1 0); write r2 0
{ "file_name": "share/steel/tests/SteelFramingTestSuite.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 14, "end_line": 138, "start_col": 0, "start_line": 134 }
(* 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 SteelFramingTestSuite open Steel.Memory open Steel.Effect /// A collection of small unit tests for the framing tactic assume val p : vprop assume val f (x:int) : SteelT unit p (fun _ -> p) let test () : SteelT unit (p `star` p `star` p) (fun _ -> p `star` p `star` p) = f 0; () assume val ref : Type0 assume val ptr (_:ref) : vprop assume val alloc (x:int) : SteelT ref emp (fun y -> ptr y) assume val free (r:ref) : SteelT unit (ptr r) (fun _ -> emp) assume val read (r:ref) : SteelT int (ptr r) (fun _ -> ptr r) assume val write (r:ref) (v: int) : SteelT unit (ptr r) (fun _ -> ptr r) let unused x = x // work around another gensym heisenbug let test0 (b1 b2 b3: ref) : SteelT int (ptr b1 `star` ptr b2 `star` ptr b3) (fun _ -> ptr b1 `star` ptr b2 `star` ptr b3) = let x = read b1 in x let test1 (b1 b2 b3: ref) : SteelT int (ptr b1 `star` ptr b2 `star` ptr b3) (fun _ -> ptr b1 `star` ptr b2 `star` ptr b3) = let x = (let y = read b1 in y) in x let test2 (b1 b2 b3: ref) : SteelT int (ptr b1 `star` ptr b2 `star` ptr b3) (fun _ -> ptr b3 `star` ptr b2 `star` ptr b1) = let x = read b1 in x let test3 (b1 b2 b3: ref) : SteelT int (ptr b1 `star` ptr b2 `star` ptr b3) (fun _ -> ptr b2 `star` ptr b1 `star` ptr b3) = let x = read b3 in x let test4 (b1 b2 b3: ref) : SteelT unit (ptr b1 `star` ptr b2 `star` ptr b3) (fun _ -> ptr b2 `star` ptr b1 `star` ptr b3) = let x = read b3 in write b2 x let test5 (b1 b2 b3: ref) : SteelT unit (ptr b1 `star` ptr b2 `star` ptr b3) (fun _ -> ptr b2 `star` ptr b1 `star` ptr b3) = let x = read b3 in write b2 (x + 1) let test6 (b1 b2 b3: ref) : SteelT unit (ptr b1 `star` ptr b2 `star` ptr b3) (fun _ -> ptr b2 `star` ptr b1 `star` ptr b3) = let x = read b3 in let b4 = alloc x in write b2 (x + 1); free b4 // With the formalism relying on can_be_split_post, this example fails if we normalize return_pre eqs goals before unification // When solving this equality, we have the goal // (*?u19*) _ _ == return_pre ((fun x -> (fun x -> (*?u758*) _ x x) x) r) // with x and r in the context of ?u19 // Not normalizing allows us to solve it as a function applied to x and r // Normalizing would lead to solve it to an slprop with x and r in the context, // but which would later fail when trying to prove the equivalence with (fun r -> ptr r) // in the postcondition let test7 (_:unit) : SteelT ref emp ptr = let r = alloc 0 in let x = read r in write r 0; r let test8 (b1 b2 b3:ref) : SteelT unit (ptr b1 `star` ptr b2 `star` ptr b3) (fun _ -> ptr b2 `star` ptr b1 `star` ptr b3) = write b2 0 open Steel.Effect.Atomic let test_if1 (b:bool) : SteelT unit emp (fun _ -> emp) = if b then noop () else noop () let test_if2 (b:bool) (r: ref) : SteelT unit (ptr r) (fun _ -> ptr r) = if b then write r 0 else write r 1 let test_if3 (b:bool) (r:ref) : SteelT unit (ptr r) (fun _ -> ptr r) = if b then noop () else noop () let test_if4 (b:bool) : SteelT unit emp (fun _ -> emp) = if b then (let r = alloc 0 in free r) else (noop ()) let test_if5 (b:bool) : SteelT ref emp (fun r -> ptr r) = if b then alloc 0 else alloc 1 let test_if6 (b:bool) : SteelT ref emp (fun r -> ptr r) = let r = if b then alloc 0 else alloc 1 in let x = read r in write r 0; r
{ "checked_file": "/", "dependencies": [ "Steel.Memory.fsti.checked", "Steel.Effect.Atomic.fsti.checked", "Steel.Effect.fsti.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "SteelFramingTestSuite.fst" }
[ { "abbrev": false, "full_module": "Steel.Effect.Atomic", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect", "short_module": null }, { "abbrev": false, "full_module": "Steel.Memory", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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: Prims.bool -> r1: SteelFramingTestSuite.ref -> r2: SteelFramingTestSuite.ref -> Steel.Effect.SteelT Prims.unit
Steel.Effect.SteelT
[]
[]
[ "Prims.bool", "SteelFramingTestSuite.ref", "SteelFramingTestSuite.write", "Prims.unit", "Steel.Effect.Common.star", "SteelFramingTestSuite.ptr", "Steel.Effect.Common.vprop" ]
[]
false
true
false
false
false
let test_if7 (b: bool) (r1 r2: ref) : SteelT unit ((ptr r1) `star` (ptr r2)) (fun _ -> (ptr r1) `star` (ptr r2)) =
if b then (write r1 0; write r2 0) else (write r2 0; write r1 0); write r2 0
false
Steel.HigherReference.fst
Steel.HigherReference.cas_action_helper
val cas_action_helper (p q r s: slprop) (m: mem) : Lemma (requires interp Mem.(((p `star` q) `star` r) `star` s) m) (ensures interp Mem.((p `star` q) `star` s) m)
val cas_action_helper (p q r s: slprop) (m: mem) : Lemma (requires interp Mem.(((p `star` q) `star` r) `star` s) m) (ensures interp Mem.((p `star` q) `star` s) m)
let cas_action_helper (p q r s:slprop) (m:mem) : Lemma (requires interp Mem.(p `star` q `star` r `star` s) m) (ensures interp Mem.(p `star` q `star` s) m) = let open Steel.Memory in calc (equiv) { r `star` s; (equiv) { star_commutative r s } s `star` r; }; calc (equiv) { p `star` q `star` r `star` s; (equiv) { Mem.star_associative (p `star` q) r s } (p `star` q) `star` (r `star` s); (equiv) { equiv_ext_right (p `star` q) (r `star` s) (s `star` r) } (p `star` q) `star` (s `star` r); (equiv) { star_associative (p `star` q) s r } (p `star` q `star` s) `star` r; }; assert (interp ((p `star` q `star` s) `star` r) m); affine_star (p `star` q `star` s) r m
{ "file_name": "lib/steel/Steel.HigherReference.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 41, "end_line": 347, "start_col": 0, "start_line": 325 }
(* 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.HigherReference open FStar.Ghost open Steel.Memory open Steel.Effect.Atomic open Steel.Effect open FStar.PCM open Steel.PCMFrac open FStar.Real module RP = Steel.PCMReference #set-options "--ide_id_info_off" module Mem = Steel.Memory let ref a = Mem.ref (fractional a) pcm_frac let null #a = Mem.null #(fractional a) #pcm_frac let is_null #a r = Mem.is_null #(fractional a) #pcm_frac r let perm_ok p : prop = (p.v <=. one == true) /\ True let pts_to_raw_sl (#a:Type) (r:ref a) (p:perm) (v:erased a) : slprop = Mem.pts_to r (Some (Ghost.reveal v, p)) let pts_to_raw (#a:Type) (r:ref a) (p:perm) (v:erased a) : vprop = to_vprop (Mem.pts_to r (Some (Ghost.reveal v, p))) [@@__reduce__] let pts_to' (#a:Type u#1) (r:ref a) (p:perm) (v:erased a) : vprop = pts_to_raw r p v `star` pure (perm_ok p) let pts_to_sl #a r p v = hp_of (pts_to' r p v) let abcd_acbd (a b c d:slprop) : Lemma (Mem.(((a `star` b) `star` (c `star` d)) `equiv` ((a `star` c) `star` (b `star` d)))) = let open Steel.Memory in calc (equiv) { ((a `star` b) `star` (c `star` d)); (equiv) { star_associative a b (c `star` d) } ((a `star` (b `star` (c `star` d)))); (equiv) { star_associative b c d; star_congruence a (b `star` (c `star` d)) a ((b `star` c) `star` d) } (a `star` ((b `star` c) `star` d)); (equiv) { star_commutative b c; star_congruence (b `star` c) d (c `star` b) d; star_congruence a ((b `star` c) `star` d) a ((c `star` b) `star` d) } (a `star` ((c `star` b) `star` d)); (equiv) { star_associative c b d; star_congruence a ((c `star` b) `star` d) a (c `star` (b `star` d)) } (a `star` (c `star` (b `star` d))); (equiv) { star_associative a c (b `star` d) } ((a `star` c) `star` (b `star` d)); } let pts_to_ref_injective (#a: Type u#1) (r: ref a) (p0 p1:perm) (v0 v1:a) (m:mem) : Lemma (requires interp (pts_to_sl r p0 v0 `Mem.star` pts_to_sl r p1 v1) m) (ensures v0 == v1) = let open Steel.Memory in abcd_acbd (hp_of (pts_to_raw r p0 v0)) (pure (perm_ok p0)) (hp_of (pts_to_raw r p1 v1)) (pure (perm_ok p1)); Mem.affine_star (hp_of (pts_to_raw r p0 v0) `star` hp_of (pts_to_raw r p1 v1)) (pure (perm_ok p0) `star` pure (perm_ok p1)) m; Mem.pts_to_compatible r (Some (Ghost.reveal v0, p0)) (Some (Ghost.reveal v1, p1)) m let pts_to_not_null (#a:Type u#1) (r:ref a) (p:perm) (v:a) (m:mem) : Lemma (requires interp (pts_to_sl r p v) m) (ensures r =!= null) = Mem.affine_star (hp_of (pts_to_raw r p v)) (Mem.pure (perm_ok p)) m; Mem.pts_to_not_null r (Some (Ghost.reveal v, p)) m let pts_to_witinv (#a:Type) (r:ref a) (p:perm) : Lemma (is_witness_invariant (pts_to_sl r p)) = let aux (x y : erased a) (m:mem) : Lemma (requires (interp (pts_to_sl r p x) m /\ interp (pts_to_sl r p y) m)) (ensures (x == y)) = Mem.pts_to_join r (Some (Ghost.reveal x, p)) (Some (Ghost.reveal y, p)) m in Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y)) let higher_ref_pts_to_injective_eq #a #opened #p0 #p1 #v0 #v1 r = extract_info_raw (pts_to r p0 v0 `star` pts_to r p1 v1) (v0 == v1) (fun m -> pts_to_ref_injective r p0 p1 v0 v1 m); rewrite_slprop (pts_to r p1 v1) (pts_to r p1 v0) (fun _ -> ()) let pts_to_framon (#a:Type) (r:ref a) (p:perm) : Lemma (is_frame_monotonic (pts_to_sl r p)) = pts_to_witinv r p let intro_pts_to (p:perm) #a #uses (#v:erased a) (r:ref a) : SteelGhost unit uses (pts_to_raw r p v) (fun _ -> pts_to r p v) (requires fun _ -> perm_ok p) (ensures fun _ _ _ -> True) = intro_pure (perm_ok p); rewrite_slprop (pts_to' r p v) (pts_to r p v) (fun _ -> ()) let pts_to_perm #_ #_ #p #v r = rewrite_slprop (pts_to r p v) (pts_to' r p v) (fun _ -> ()); elim_pure (perm_ok p); intro_pure (perm_ok p); rewrite_slprop (pts_to' r p v) (pts_to r p v) (fun _ -> ()) let alloc #a x = let v = Some (x, full_perm) in assert (FStar.PCM.composable pcm_frac v None); assert (compatible pcm_frac v v); let r = RP.alloc v in rewrite_slprop (RP.pts_to r v) (pts_to r full_perm x) (fun m -> emp_unit (hp_of (pts_to_raw r full_perm x)); pure_star_interp (hp_of (pts_to_raw r full_perm x)) (perm_ok full_perm) m ); extract_info_raw (pts_to r full_perm x) (~ (is_null r)) (fun m -> pts_to_not_null r full_perm x m); return r let read (#a:Type) (#p:perm) (#v:erased a) (r:ref a) = let v1 : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, p)) in rewrite_slprop (pts_to r p v) (RP.pts_to r v1 `star` pure (perm_ok p)) (fun _ -> ()); elim_pure (perm_ok p); let v2 = RP.read r v1 in rewrite_slprop (RP.pts_to r v1) (pts_to r p v) (fun m -> emp_unit (hp_of (pts_to_raw r p v)); pure_star_interp (hp_of (pts_to_raw r p v)) (perm_ok p) m); assert (compatible pcm_frac v1 v2); let Some (x, _) = v2 in rewrite_slprop (pts_to r p v) (pts_to r p x) (fun _ -> ()); return x let atomic_read (#opened:_) (#a:Type) (#p:perm) (#v:erased a) (r:ref a) = let v1 : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, p)) in rewrite_slprop (pts_to r p v) (RP.pts_to r v1 `star` pure (perm_ok p)) (fun _ -> ()); elim_pure (perm_ok p); let v2 = RP.atomic_read r v1 in rewrite_slprop (RP.pts_to r v1) (pts_to r p v) (fun m -> emp_unit (hp_of (pts_to_raw r p v)); pure_star_interp (hp_of (pts_to_raw r p v)) (perm_ok p) m); assert (compatible pcm_frac v1 v2); let Some (x, _) = v2 in rewrite_slprop (pts_to r p v) (pts_to r p x) (fun _ -> ()); return x let read_refine (#a:Type) (#p:perm) (q:a -> vprop) (r:ref a) : SteelT a (h_exists (fun (v:a) -> pts_to r p v `star` q v)) (fun v -> pts_to r p v `star` q v) = let vs:erased a = witness_exists () in rewrite_slprop (pts_to r p (Ghost.hide (Ghost.reveal vs))) (pts_to r p vs) (fun _ -> ()); let v = read r in rewrite_slprop (q vs) (q v) (fun _ -> ()); return v let write (#a:Type) (#v:erased a) (r:ref a) (x:a) : SteelT unit (pts_to r full_perm v) (fun _ -> pts_to r full_perm x) = let v_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, full_perm)) in let v_new : fractional a = Some (x, full_perm) in rewrite_slprop (pts_to r full_perm v) (RP.pts_to r v_old `star` pure (perm_ok full_perm)) (fun _ -> ()); elim_pure (perm_ok full_perm); RP.write r v_old v_new; rewrite_slprop (RP.pts_to r v_new) (pts_to r full_perm x) (fun m -> emp_unit (hp_of (pts_to_raw r full_perm x)); pure_star_interp (hp_of (pts_to_raw r full_perm x)) (perm_ok full_perm) m) let atomic_write #opened #a #v r x = let v_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, full_perm)) in let v_new : fractional a = Some (x, full_perm) in rewrite_slprop (pts_to r full_perm v) (RP.pts_to r v_old `star` pure (perm_ok full_perm)) (fun _ -> ()); elim_pure (perm_ok full_perm); RP.atomic_write r v_old v_new; rewrite_slprop (RP.pts_to r v_new) (pts_to r full_perm x) (fun m -> emp_unit (hp_of (pts_to_raw r full_perm x)); pure_star_interp (hp_of (pts_to_raw r full_perm x)) (perm_ok full_perm) m) let free (#a:Type) (#v:erased a) (r:ref a) : SteelT unit (pts_to r full_perm v) (fun _ -> emp) = let v_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, full_perm)) in rewrite_slprop (pts_to r full_perm v) (RP.pts_to r v_old `star` pure (perm_ok full_perm)) (fun _ -> ()); elim_pure (perm_ok full_perm); RP.free r v_old; drop (RP.pts_to r (Mkpcm'?.one (Mkpcm?.p pcm_frac))) let share_atomic_raw_gen #a #uses (#p:perm) (r:ref a{perm_ok p}) (v0:erased a) (p1 p2: perm) : SteelGhost unit uses (pts_to_raw r p v0) (fun _ -> pts_to_raw r p1 v0 `star` pts_to_raw r p2 v0) (fun _ -> p == p1 `sum_perm` p2) (fun _ _ _ -> True) = rewrite_slprop (pts_to_raw r p v0) (RP.pts_to r _) (fun _ -> ()); RP.split r (Some (Ghost.reveal v0, p)) (Some (Ghost.reveal v0, p1)) (Some (Ghost.reveal v0, p2)); rewrite_slprop (RP.pts_to r _) (pts_to_raw r p1 v0) (fun _ -> ()); rewrite_slprop (RP.pts_to r _) (pts_to_raw r p2 v0) (fun _ -> ()) let share_atomic_raw #a #uses (#p:perm) (r:ref a{perm_ok p}) (v0:erased a) : SteelGhostT unit uses (pts_to_raw r p v0) (fun _ -> pts_to_raw r (half_perm p) v0 `star` pts_to_raw r (half_perm p) v0) = share_atomic_raw_gen r v0 (half_perm p) (half_perm p) let share_gen (#a:Type) (#uses:_) (#p:perm) (#v:erased a) (r:ref a) (p1 p2: perm) : SteelGhost unit uses (pts_to r p v) (fun _ -> pts_to r p1 v `star` pts_to r p2 v) (fun _ -> p == p1 `sum_perm` p2) (fun _ _ _ -> True) = let v_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, p)) in rewrite_slprop (pts_to r p v) (pts_to' r p v) (fun _ -> ()); elim_pure (perm_ok p); share_atomic_raw_gen r v p1 p2; intro_pts_to p1 r; intro_pts_to p2 r let share (#a:Type) #uses (#p:perm) (#v:erased a) (r:ref a) : SteelGhostT unit uses (pts_to r p v) (fun _ -> pts_to r (half_perm p) v `star` pts_to r (half_perm p) v) = share_gen r (half_perm p) (half_perm p) let gather_atomic_raw (#a:Type) (#uses:_) (#p0 #p1:perm) (r:ref a) (v0:erased a) (v1:erased a) : SteelGhostT (_:unit{v0==v1 /\ perm_ok (sum_perm p0 p1)}) uses (pts_to_raw r p0 v0 `star` pts_to_raw r p1 v1) (fun _ -> pts_to_raw r (sum_perm p0 p1) v0) = rewrite_slprop (pts_to_raw r p0 v0) (RP.pts_to r (Ghost.reveal (Some (Ghost.reveal v0, p0)))) (fun _ -> ()); rewrite_slprop (pts_to_raw r p1 v1) (RP.pts_to r (Ghost.reveal (Some (Ghost.reveal v1, p1)))) (fun _ -> ()); let _ = RP.gather r (Some (Ghost.reveal v0, p0)) (Some (Ghost.reveal v1, p1)) in rewrite_slprop (RP.pts_to r _) (pts_to_raw r (sum_perm p0 p1) v0) (fun _ -> ()) let gather (#a:Type) (#uses:_) (#p0:perm) (#p1:perm) (#v0 #v1:erased a) (r:ref a) = let v0_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v0, p0)) in let v1_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v1, p1)) in rewrite_slprop (pts_to r p0 v0) (pts_to_raw r p0 v0 `star` pure (perm_ok p0)) (fun _ -> ()); rewrite_slprop (pts_to r p1 v1) (pts_to_raw r p1 v1 `star` pure (perm_ok p1)) (fun _ -> ()); elim_pure (perm_ok p0); elim_pure (perm_ok p1); let _ = gather_atomic_raw r v0 v1 in intro_pts_to (sum_perm p0 p1) r let cas_provides #t (r:ref t) (v:Ghost.erased t) (v_new:t) (b:bool) = if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v let equiv_ext_right (p q r:slprop) : Lemma (requires q `Mem.equiv` r) (ensures Mem.((p `star` q) `equiv` (p `star` r))) = let open Steel.Memory in 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; }
{ "checked_file": "/", "dependencies": [ "Steel.PCMReference.fsti.checked", "Steel.PCMFrac.fst.checked", "Steel.Memory.fsti.checked", "Steel.Effect.Atomic.fsti.checked", "Steel.Effect.fsti.checked", "prims.fst.checked", "FStar.Real.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked", "FStar.NMSTTotal.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Steel.HigherReference.fst" }
[ { "abbrev": true, "full_module": "Steel.Memory", "short_module": "Mem" }, { "abbrev": true, "full_module": "Steel.PCMReference", "short_module": "RP" }, { "abbrev": false, "full_module": "FStar.Real", "short_module": null }, { "abbrev": false, "full_module": "Steel.PCMFrac", "short_module": null }, { "abbrev": false, "full_module": "FStar.PCM", "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": "FStar.Ghost", "short_module": null }, { "abbrev": true, "full_module": "Steel.Memory", "short_module": "Mem" }, { "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": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "Steel.FractionalPermission", "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
p: Steel.Memory.slprop -> q: Steel.Memory.slprop -> r: Steel.Memory.slprop -> s: Steel.Memory.slprop -> m: Steel.Memory.mem -> FStar.Pervasives.Lemma (requires Steel.Memory.interp (Steel.Memory.star (Steel.Memory.star (Steel.Memory.star p q) r) s) m) (ensures Steel.Memory.interp (Steel.Memory.star (Steel.Memory.star p q) s) m)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Steel.Memory.slprop", "Steel.Memory.mem", "Steel.Memory.affine_star", "Steel.Memory.star", "Prims.unit", "Prims._assert", "Steel.Memory.interp", "FStar.Calc.calc_finish", "Steel.Memory.equiv", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "FStar.Calc.calc_step", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "Steel.Memory.star_associative", "Prims.squash", "Steel.HigherReference.equiv_ext_right", "Steel.Memory.star_commutative", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let cas_action_helper (p q r s: slprop) (m: mem) : Lemma (requires interp Mem.(((p `star` q) `star` r) `star` s) m) (ensures interp Mem.((p `star` q) `star` s) m) =
let open Steel.Memory in calc (equiv) { r `star` s; (equiv) { star_commutative r s } s `star` r; }; calc (equiv) { ((p `star` q) `star` r) `star` s; (equiv) { Mem.star_associative (p `star` q) r s } (p `star` q) `star` (r `star` s); (equiv) { equiv_ext_right (p `star` q) (r `star` s) (s `star` r) } (p `star` q) `star` (s `star` r); (equiv) { star_associative (p `star` q) s r } ((p `star` q) `star` s) `star` r; }; assert (interp (((p `star` q) `star` s) `star` r) m); affine_star ((p `star` q) `star` s) r m
false
LatticeEff.fst
LatticeEff.ite
val ite : p: Type0 -> q: Type0 -> r: Type0 -> Prims.logical
let ite (p q r : Type0) = (p ==> q) /\ (~p ==> r)
{ "file_name": "examples/layeredeffects/LatticeEff.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 49, "end_line": 114, "start_col": 0, "start_line": 114 }
module LatticeEff open FStar.Tactics.V2 open FStar.List.Tot open FStar.All module H = FStar.Heap // GM: Force a type equality by SMT let coerce #a #b (x:a{a == b}) : b = x let unreachable #a () : Pure a (requires False) (ensures (fun _ -> False)) = coerce "whatever" type eff_label = // GM: Can we do this one? ALL's WPs are unary and this is a // relational property. // | RD | WR //| DIV | EXN type annot = eff_label -> bool let interp (l : list eff_label) : annot = fun lab -> mem lab l type state = H.heap type wp a = all_wp_h H.heap a // boring, exponential //let wpof1 #a (l : list eff_label) : all_wp_h H.heap a = // let i = interp l in // match i ST, i EXN with // | false, false -> // fun p s0 -> forall x. p (V x) s0 // | true , false -> // fun p s0 -> forall x s1. p (V x) s1 // | false, true -> // fun p s0 -> forall r. p r s0 // | true, true -> // fun p s0 -> forall r s1. p r s1 (* more generic *) let wpof2 #a (l : list eff_label) : wp a = let i = interp l in let wp : wp a = fun p s0 -> (forall r s1. (i WR == false ==> s1 == s0) ==> (i EXN == false ==> V? r) ==> p r s1) in wp type repr (a:Type u#aa) (labs : list u#0 eff_label) // #2074 : Type u#0 = unit -> ALL a (wpof2 labs) let rec interp_at (l1 l2 : list eff_label) (l : eff_label) : Lemma (interp (l1@l2) l == (interp l1 l || interp l2 l)) [SMTPat (interp (l1@l2) l)] = match l1 with | [] -> () | _::l1 -> interp_at l1 l2 l let sublist (l1 l2 : list eff_label) = forall x. mem x l1 ==> mem x l2 let sublist_refl (l : list eff_label) : Lemma (sublist l l) [SMTPat (sublist l l)] = () let rec interp_sublist (l1 l2 : list eff_label) (l : eff_label) : Lemma (requires (sublist l1 l2)) (ensures (interp l1 l ==> interp l2 l)) [SMTPat (interp l1 l); SMTPat (sublist l1 l2)] = match l1 with | [] -> () | _::l1 -> interp_sublist l1 l2 l let rec sublist_at (l1 l2 : list eff_label) : Lemma (sublist l1 (l1@l2) /\ sublist l2 (l1@l2)) [SMTPatOr [[SMTPat (sublist l1 (l1@l2))]; [SMTPat (sublist l2 (l1@l2))]]] = match l1 with | [] -> () | _::l1 -> sublist_at l1 l2 let ann_le (ann1 ann2 : annot) : prop = forall x. ann1 x ==> ann2 x let return (a:Type) (x:a) : repr a [] = fun () -> x let bind (a b : Type) (labs1 labs2 : list eff_label) (c : repr a labs1) (f : (x:a -> repr b labs2)) : Tot (repr b (labs1@labs2)) = fun () -> f (c ()) () let subcomp (a:Type) (labs1 labs2 : list eff_label) (f : repr a labs1) : Pure (repr a labs2) (requires (sublist labs1 labs2)) (ensures (fun _ -> True)) = f
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Heap.fst.checked", "FStar.Classical.fsti.checked", "FStar.All.fst.checked" ], "interface_file": false, "source_file": "LatticeEff.fst" }
[ { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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: Type0 -> q: Type0 -> r: Type0 -> Prims.logical
Prims.Tot
[ "total" ]
[]
[ "Prims.l_and", "Prims.l_imp", "Prims.l_not", "Prims.logical" ]
[]
false
false
false
true
true
let ite (p q r: Type0) =
(p ==> q) /\ (~p ==> r)
false
Steel.HigherReference.fst
Steel.HigherReference.ghost_pts_to_witinv
val ghost_pts_to_witinv (#a:Type) (r:ghost_ref a) (p:perm) : Lemma (is_witness_invariant (ghost_pts_to_sl r p))
val ghost_pts_to_witinv (#a:Type) (r:ghost_ref a) (p:perm) : Lemma (is_witness_invariant (ghost_pts_to_sl r p))
let ghost_pts_to_witinv (#a:Type) (r:ghost_ref a) (p:perm) : Lemma (is_witness_invariant (ghost_pts_to_sl r p)) = let aux (x y : erased a) (m:mem) : Lemma (requires (interp (ghost_pts_to_sl r p x) m /\ interp (ghost_pts_to_sl r p y) m)) (ensures (x == y)) [SMTPat ()] = Mem.pts_to_join (Ghost.reveal r) (Some (Ghost.reveal x, p)) (Some (Ghost.reveal y, p)) m in assert (forall x y m. interp (ghost_pts_to_sl r p x) m /\ interp (ghost_pts_to_sl r p y) m ==> x == y); assert (is_witness_invariant (ghost_pts_to_sl r p))
{ "file_name": "lib/steel/Steel.HigherReference.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 53, "end_line": 408, "start_col": 0, "start_line": 399 }
(* 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.HigherReference open FStar.Ghost open Steel.Memory open Steel.Effect.Atomic open Steel.Effect open FStar.PCM open Steel.PCMFrac open FStar.Real module RP = Steel.PCMReference #set-options "--ide_id_info_off" module Mem = Steel.Memory let ref a = Mem.ref (fractional a) pcm_frac let null #a = Mem.null #(fractional a) #pcm_frac let is_null #a r = Mem.is_null #(fractional a) #pcm_frac r let perm_ok p : prop = (p.v <=. one == true) /\ True let pts_to_raw_sl (#a:Type) (r:ref a) (p:perm) (v:erased a) : slprop = Mem.pts_to r (Some (Ghost.reveal v, p)) let pts_to_raw (#a:Type) (r:ref a) (p:perm) (v:erased a) : vprop = to_vprop (Mem.pts_to r (Some (Ghost.reveal v, p))) [@@__reduce__] let pts_to' (#a:Type u#1) (r:ref a) (p:perm) (v:erased a) : vprop = pts_to_raw r p v `star` pure (perm_ok p) let pts_to_sl #a r p v = hp_of (pts_to' r p v) let abcd_acbd (a b c d:slprop) : Lemma (Mem.(((a `star` b) `star` (c `star` d)) `equiv` ((a `star` c) `star` (b `star` d)))) = let open Steel.Memory in calc (equiv) { ((a `star` b) `star` (c `star` d)); (equiv) { star_associative a b (c `star` d) } ((a `star` (b `star` (c `star` d)))); (equiv) { star_associative b c d; star_congruence a (b `star` (c `star` d)) a ((b `star` c) `star` d) } (a `star` ((b `star` c) `star` d)); (equiv) { star_commutative b c; star_congruence (b `star` c) d (c `star` b) d; star_congruence a ((b `star` c) `star` d) a ((c `star` b) `star` d) } (a `star` ((c `star` b) `star` d)); (equiv) { star_associative c b d; star_congruence a ((c `star` b) `star` d) a (c `star` (b `star` d)) } (a `star` (c `star` (b `star` d))); (equiv) { star_associative a c (b `star` d) } ((a `star` c) `star` (b `star` d)); } let pts_to_ref_injective (#a: Type u#1) (r: ref a) (p0 p1:perm) (v0 v1:a) (m:mem) : Lemma (requires interp (pts_to_sl r p0 v0 `Mem.star` pts_to_sl r p1 v1) m) (ensures v0 == v1) = let open Steel.Memory in abcd_acbd (hp_of (pts_to_raw r p0 v0)) (pure (perm_ok p0)) (hp_of (pts_to_raw r p1 v1)) (pure (perm_ok p1)); Mem.affine_star (hp_of (pts_to_raw r p0 v0) `star` hp_of (pts_to_raw r p1 v1)) (pure (perm_ok p0) `star` pure (perm_ok p1)) m; Mem.pts_to_compatible r (Some (Ghost.reveal v0, p0)) (Some (Ghost.reveal v1, p1)) m let pts_to_not_null (#a:Type u#1) (r:ref a) (p:perm) (v:a) (m:mem) : Lemma (requires interp (pts_to_sl r p v) m) (ensures r =!= null) = Mem.affine_star (hp_of (pts_to_raw r p v)) (Mem.pure (perm_ok p)) m; Mem.pts_to_not_null r (Some (Ghost.reveal v, p)) m let pts_to_witinv (#a:Type) (r:ref a) (p:perm) : Lemma (is_witness_invariant (pts_to_sl r p)) = let aux (x y : erased a) (m:mem) : Lemma (requires (interp (pts_to_sl r p x) m /\ interp (pts_to_sl r p y) m)) (ensures (x == y)) = Mem.pts_to_join r (Some (Ghost.reveal x, p)) (Some (Ghost.reveal y, p)) m in Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y)) let higher_ref_pts_to_injective_eq #a #opened #p0 #p1 #v0 #v1 r = extract_info_raw (pts_to r p0 v0 `star` pts_to r p1 v1) (v0 == v1) (fun m -> pts_to_ref_injective r p0 p1 v0 v1 m); rewrite_slprop (pts_to r p1 v1) (pts_to r p1 v0) (fun _ -> ()) let pts_to_framon (#a:Type) (r:ref a) (p:perm) : Lemma (is_frame_monotonic (pts_to_sl r p)) = pts_to_witinv r p let intro_pts_to (p:perm) #a #uses (#v:erased a) (r:ref a) : SteelGhost unit uses (pts_to_raw r p v) (fun _ -> pts_to r p v) (requires fun _ -> perm_ok p) (ensures fun _ _ _ -> True) = intro_pure (perm_ok p); rewrite_slprop (pts_to' r p v) (pts_to r p v) (fun _ -> ()) let pts_to_perm #_ #_ #p #v r = rewrite_slprop (pts_to r p v) (pts_to' r p v) (fun _ -> ()); elim_pure (perm_ok p); intro_pure (perm_ok p); rewrite_slprop (pts_to' r p v) (pts_to r p v) (fun _ -> ()) let alloc #a x = let v = Some (x, full_perm) in assert (FStar.PCM.composable pcm_frac v None); assert (compatible pcm_frac v v); let r = RP.alloc v in rewrite_slprop (RP.pts_to r v) (pts_to r full_perm x) (fun m -> emp_unit (hp_of (pts_to_raw r full_perm x)); pure_star_interp (hp_of (pts_to_raw r full_perm x)) (perm_ok full_perm) m ); extract_info_raw (pts_to r full_perm x) (~ (is_null r)) (fun m -> pts_to_not_null r full_perm x m); return r let read (#a:Type) (#p:perm) (#v:erased a) (r:ref a) = let v1 : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, p)) in rewrite_slprop (pts_to r p v) (RP.pts_to r v1 `star` pure (perm_ok p)) (fun _ -> ()); elim_pure (perm_ok p); let v2 = RP.read r v1 in rewrite_slprop (RP.pts_to r v1) (pts_to r p v) (fun m -> emp_unit (hp_of (pts_to_raw r p v)); pure_star_interp (hp_of (pts_to_raw r p v)) (perm_ok p) m); assert (compatible pcm_frac v1 v2); let Some (x, _) = v2 in rewrite_slprop (pts_to r p v) (pts_to r p x) (fun _ -> ()); return x let atomic_read (#opened:_) (#a:Type) (#p:perm) (#v:erased a) (r:ref a) = let v1 : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, p)) in rewrite_slprop (pts_to r p v) (RP.pts_to r v1 `star` pure (perm_ok p)) (fun _ -> ()); elim_pure (perm_ok p); let v2 = RP.atomic_read r v1 in rewrite_slprop (RP.pts_to r v1) (pts_to r p v) (fun m -> emp_unit (hp_of (pts_to_raw r p v)); pure_star_interp (hp_of (pts_to_raw r p v)) (perm_ok p) m); assert (compatible pcm_frac v1 v2); let Some (x, _) = v2 in rewrite_slprop (pts_to r p v) (pts_to r p x) (fun _ -> ()); return x let read_refine (#a:Type) (#p:perm) (q:a -> vprop) (r:ref a) : SteelT a (h_exists (fun (v:a) -> pts_to r p v `star` q v)) (fun v -> pts_to r p v `star` q v) = let vs:erased a = witness_exists () in rewrite_slprop (pts_to r p (Ghost.hide (Ghost.reveal vs))) (pts_to r p vs) (fun _ -> ()); let v = read r in rewrite_slprop (q vs) (q v) (fun _ -> ()); return v let write (#a:Type) (#v:erased a) (r:ref a) (x:a) : SteelT unit (pts_to r full_perm v) (fun _ -> pts_to r full_perm x) = let v_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, full_perm)) in let v_new : fractional a = Some (x, full_perm) in rewrite_slprop (pts_to r full_perm v) (RP.pts_to r v_old `star` pure (perm_ok full_perm)) (fun _ -> ()); elim_pure (perm_ok full_perm); RP.write r v_old v_new; rewrite_slprop (RP.pts_to r v_new) (pts_to r full_perm x) (fun m -> emp_unit (hp_of (pts_to_raw r full_perm x)); pure_star_interp (hp_of (pts_to_raw r full_perm x)) (perm_ok full_perm) m) let atomic_write #opened #a #v r x = let v_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, full_perm)) in let v_new : fractional a = Some (x, full_perm) in rewrite_slprop (pts_to r full_perm v) (RP.pts_to r v_old `star` pure (perm_ok full_perm)) (fun _ -> ()); elim_pure (perm_ok full_perm); RP.atomic_write r v_old v_new; rewrite_slprop (RP.pts_to r v_new) (pts_to r full_perm x) (fun m -> emp_unit (hp_of (pts_to_raw r full_perm x)); pure_star_interp (hp_of (pts_to_raw r full_perm x)) (perm_ok full_perm) m) let free (#a:Type) (#v:erased a) (r:ref a) : SteelT unit (pts_to r full_perm v) (fun _ -> emp) = let v_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, full_perm)) in rewrite_slprop (pts_to r full_perm v) (RP.pts_to r v_old `star` pure (perm_ok full_perm)) (fun _ -> ()); elim_pure (perm_ok full_perm); RP.free r v_old; drop (RP.pts_to r (Mkpcm'?.one (Mkpcm?.p pcm_frac))) let share_atomic_raw_gen #a #uses (#p:perm) (r:ref a{perm_ok p}) (v0:erased a) (p1 p2: perm) : SteelGhost unit uses (pts_to_raw r p v0) (fun _ -> pts_to_raw r p1 v0 `star` pts_to_raw r p2 v0) (fun _ -> p == p1 `sum_perm` p2) (fun _ _ _ -> True) = rewrite_slprop (pts_to_raw r p v0) (RP.pts_to r _) (fun _ -> ()); RP.split r (Some (Ghost.reveal v0, p)) (Some (Ghost.reveal v0, p1)) (Some (Ghost.reveal v0, p2)); rewrite_slprop (RP.pts_to r _) (pts_to_raw r p1 v0) (fun _ -> ()); rewrite_slprop (RP.pts_to r _) (pts_to_raw r p2 v0) (fun _ -> ()) let share_atomic_raw #a #uses (#p:perm) (r:ref a{perm_ok p}) (v0:erased a) : SteelGhostT unit uses (pts_to_raw r p v0) (fun _ -> pts_to_raw r (half_perm p) v0 `star` pts_to_raw r (half_perm p) v0) = share_atomic_raw_gen r v0 (half_perm p) (half_perm p) let share_gen (#a:Type) (#uses:_) (#p:perm) (#v:erased a) (r:ref a) (p1 p2: perm) : SteelGhost unit uses (pts_to r p v) (fun _ -> pts_to r p1 v `star` pts_to r p2 v) (fun _ -> p == p1 `sum_perm` p2) (fun _ _ _ -> True) = let v_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, p)) in rewrite_slprop (pts_to r p v) (pts_to' r p v) (fun _ -> ()); elim_pure (perm_ok p); share_atomic_raw_gen r v p1 p2; intro_pts_to p1 r; intro_pts_to p2 r let share (#a:Type) #uses (#p:perm) (#v:erased a) (r:ref a) : SteelGhostT unit uses (pts_to r p v) (fun _ -> pts_to r (half_perm p) v `star` pts_to r (half_perm p) v) = share_gen r (half_perm p) (half_perm p) let gather_atomic_raw (#a:Type) (#uses:_) (#p0 #p1:perm) (r:ref a) (v0:erased a) (v1:erased a) : SteelGhostT (_:unit{v0==v1 /\ perm_ok (sum_perm p0 p1)}) uses (pts_to_raw r p0 v0 `star` pts_to_raw r p1 v1) (fun _ -> pts_to_raw r (sum_perm p0 p1) v0) = rewrite_slprop (pts_to_raw r p0 v0) (RP.pts_to r (Ghost.reveal (Some (Ghost.reveal v0, p0)))) (fun _ -> ()); rewrite_slprop (pts_to_raw r p1 v1) (RP.pts_to r (Ghost.reveal (Some (Ghost.reveal v1, p1)))) (fun _ -> ()); let _ = RP.gather r (Some (Ghost.reveal v0, p0)) (Some (Ghost.reveal v1, p1)) in rewrite_slprop (RP.pts_to r _) (pts_to_raw r (sum_perm p0 p1) v0) (fun _ -> ()) let gather (#a:Type) (#uses:_) (#p0:perm) (#p1:perm) (#v0 #v1:erased a) (r:ref a) = let v0_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v0, p0)) in let v1_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v1, p1)) in rewrite_slprop (pts_to r p0 v0) (pts_to_raw r p0 v0 `star` pure (perm_ok p0)) (fun _ -> ()); rewrite_slprop (pts_to r p1 v1) (pts_to_raw r p1 v1 `star` pure (perm_ok p1)) (fun _ -> ()); elim_pure (perm_ok p0); elim_pure (perm_ok p1); let _ = gather_atomic_raw r v0 v1 in intro_pts_to (sum_perm p0 p1) r let cas_provides #t (r:ref t) (v:Ghost.erased t) (v_new:t) (b:bool) = if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v let equiv_ext_right (p q r:slprop) : Lemma (requires q `Mem.equiv` r) (ensures Mem.((p `star` q) `equiv` (p `star` r))) = let open Steel.Memory in 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 cas_action_helper (p q r s:slprop) (m:mem) : Lemma (requires interp Mem.(p `star` q `star` r `star` s) m) (ensures interp Mem.(p `star` q `star` s) m) = let open Steel.Memory in calc (equiv) { r `star` s; (equiv) { star_commutative r s } s `star` r; }; calc (equiv) { p `star` q `star` r `star` s; (equiv) { Mem.star_associative (p `star` q) r s } (p `star` q) `star` (r `star` s); (equiv) { equiv_ext_right (p `star` q) (r `star` s) (s `star` r) } (p `star` q) `star` (s `star` r); (equiv) { star_associative (p `star` q) s r } (p `star` q `star` s) `star` r; }; assert (interp ((p `star` q `star` s) `star` r) m); affine_star (p `star` q `star` s) r m let cas_action (#t:Type) (eq: (x:t -> y:t -> b:bool{b <==> (x == y)})) (#uses:inames) (r:ref t) (v:Ghost.erased t) (v_old:t) (v_new:t) (fr:slprop) : MstTot (b:bool{b <==> (Ghost.reveal v == v_old)}) uses (pts_to_sl r full_perm v) (cas_provides r v v_new) fr (fun _ -> True) (fun _ _ _ -> True) = let m0 : full_mem = NMSTTotal.get () in let fv = Ghost.hide (Some (Ghost.reveal v, full_perm)) in let fv' = Some (v_new, full_perm) in assert (interp Mem.(pts_to_sl r full_perm v `star` fr `star` locks_invariant uses m0) m0); assert (interp Mem.(pts_to r fv `star` pure (perm_ok full_perm) `star` fr `star` locks_invariant uses m0) m0); cas_action_helper (Mem.pts_to r fv) (Mem.pure (perm_ok full_perm)) fr (locks_invariant uses m0) m0; assert (interp Mem.((pts_to r fv `star` pure (perm_ok full_perm)) `star` locks_invariant uses m0) m0); let fv_actual = Mem.frame (Mem.pure (perm_ok full_perm)) (sel_action uses r fv) fr in assert (compatible pcm_frac fv fv_actual); let Some (v', p) = fv_actual in assert (v == Ghost.hide v'); assert (p == full_perm); let b = if eq v' v_old then (Mem.frame (Mem.pure (perm_ok full_perm)) (upd_action uses r fv fv') fr; true) else false in b (*** GHOST REFERENCES ***) let ghost_ref a = erased (ref a) [@@__reduce__] let ghost_pts_to_sl #a (r:ghost_ref a) (p:perm) (x:a) = pts_to_sl (reveal r) p x let reveal_ghost_ref _ = () let reveal_ghost_pts_to_sl _ _ _ = ()
{ "checked_file": "/", "dependencies": [ "Steel.PCMReference.fsti.checked", "Steel.PCMFrac.fst.checked", "Steel.Memory.fsti.checked", "Steel.Effect.Atomic.fsti.checked", "Steel.Effect.fsti.checked", "prims.fst.checked", "FStar.Real.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked", "FStar.NMSTTotal.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Steel.HigherReference.fst" }
[ { "abbrev": true, "full_module": "Steel.Memory", "short_module": "Mem" }, { "abbrev": true, "full_module": "Steel.PCMReference", "short_module": "RP" }, { "abbrev": false, "full_module": "FStar.Real", "short_module": null }, { "abbrev": false, "full_module": "Steel.PCMFrac", "short_module": null }, { "abbrev": false, "full_module": "FStar.PCM", "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": "FStar.Ghost", "short_module": null }, { "abbrev": true, "full_module": "Steel.Memory", "short_module": "Mem" }, { "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": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "Steel.FractionalPermission", "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": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
r: Steel.HigherReference.ghost_ref a -> p: Steel.FractionalPermission.perm -> FStar.Pervasives.Lemma (ensures Steel.Memory.is_witness_invariant (Steel.HigherReference.ghost_pts_to_sl r p))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Steel.HigherReference.ghost_ref", "Steel.FractionalPermission.perm", "Prims._assert", "Steel.Memory.is_witness_invariant", "Steel.HigherReference.ghost_pts_to_sl", "Prims.unit", "Prims.l_Forall", "Steel.Memory.mem", "Prims.l_imp", "Prims.l_and", "Steel.Memory.interp", "Prims.eq2", "FStar.Ghost.erased", "FStar.Ghost.reveal", "Prims.squash", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat", "Prims.Nil", "Steel.Memory.pts_to_join", "Steel.PCMFrac.fractional", "Steel.PCMFrac.pcm_frac", "Steel.HigherReference.ref", "FStar.Pervasives.Native.Some", "FStar.Pervasives.Native.tuple2", "FStar.Pervasives.Native.Mktuple2", "Prims.l_True" ]
[]
false
false
true
false
false
let ghost_pts_to_witinv (#a: Type) (r: ghost_ref a) (p: perm) : Lemma (is_witness_invariant (ghost_pts_to_sl r p)) =
let aux (x y: erased a) (m: mem) : Lemma (requires (interp (ghost_pts_to_sl r p x) m /\ interp (ghost_pts_to_sl r p y) m)) (ensures (x == y)) [SMTPat ()] = Mem.pts_to_join (Ghost.reveal r) (Some (Ghost.reveal x, p)) (Some (Ghost.reveal y, p)) m in assert (forall x y m. interp (ghost_pts_to_sl r p x) m /\ interp (ghost_pts_to_sl r p y) m ==> x == y); assert (is_witness_invariant (ghost_pts_to_sl r p))
false
LatticeEff.fst
LatticeEff.interp
val interp (l: list eff_label) : annot
val interp (l: list eff_label) : annot
let interp (l : list eff_label) : annot = fun lab -> mem lab l
{ "file_name": "examples/layeredeffects/LatticeEff.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 22, "end_line": 24, "start_col": 0, "start_line": 23 }
module LatticeEff open FStar.Tactics.V2 open FStar.List.Tot open FStar.All module H = FStar.Heap // GM: Force a type equality by SMT let coerce #a #b (x:a{a == b}) : b = x let unreachable #a () : Pure a (requires False) (ensures (fun _ -> False)) = coerce "whatever" type eff_label = // GM: Can we do this one? ALL's WPs are unary and this is a // relational property. // | RD | WR //| DIV | EXN type annot = eff_label -> bool
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Heap.fst.checked", "FStar.Classical.fsti.checked", "FStar.All.fst.checked" ], "interface_file": false, "source_file": "LatticeEff.fst" }
[ { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
l: Prims.list LatticeEff.eff_label -> LatticeEff.annot
Prims.Tot
[ "total" ]
[]
[ "Prims.list", "LatticeEff.eff_label", "FStar.List.Tot.Base.mem", "Prims.bool", "LatticeEff.annot" ]
[]
false
false
false
true
false
let interp (l: list eff_label) : annot =
fun lab -> mem lab l
false
LatticeEff.fst
LatticeEff.sublist
val sublist : l1: Prims.list LatticeEff.eff_label -> l2: Prims.list LatticeEff.eff_label -> Prims.logical
let sublist (l1 l2 : list eff_label) = forall x. mem x l1 ==> mem x l2
{ "file_name": "examples/layeredeffects/LatticeEff.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 33, "end_line": 66, "start_col": 0, "start_line": 65 }
module LatticeEff open FStar.Tactics.V2 open FStar.List.Tot open FStar.All module H = FStar.Heap // GM: Force a type equality by SMT let coerce #a #b (x:a{a == b}) : b = x let unreachable #a () : Pure a (requires False) (ensures (fun _ -> False)) = coerce "whatever" type eff_label = // GM: Can we do this one? ALL's WPs are unary and this is a // relational property. // | RD | WR //| DIV | EXN type annot = eff_label -> bool let interp (l : list eff_label) : annot = fun lab -> mem lab l type state = H.heap type wp a = all_wp_h H.heap a // boring, exponential //let wpof1 #a (l : list eff_label) : all_wp_h H.heap a = // let i = interp l in // match i ST, i EXN with // | false, false -> // fun p s0 -> forall x. p (V x) s0 // | true , false -> // fun p s0 -> forall x s1. p (V x) s1 // | false, true -> // fun p s0 -> forall r. p r s0 // | true, true -> // fun p s0 -> forall r s1. p r s1 (* more generic *) let wpof2 #a (l : list eff_label) : wp a = let i = interp l in let wp : wp a = fun p s0 -> (forall r s1. (i WR == false ==> s1 == s0) ==> (i EXN == false ==> V? r) ==> p r s1) in wp type repr (a:Type u#aa) (labs : list u#0 eff_label) // #2074 : Type u#0 = unit -> ALL a (wpof2 labs) let rec interp_at (l1 l2 : list eff_label) (l : eff_label) : Lemma (interp (l1@l2) l == (interp l1 l || interp l2 l)) [SMTPat (interp (l1@l2) l)] = match l1 with | [] -> () | _::l1 -> interp_at l1 l2 l
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Heap.fst.checked", "FStar.Classical.fsti.checked", "FStar.All.fst.checked" ], "interface_file": false, "source_file": "LatticeEff.fst" }
[ { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
l1: Prims.list LatticeEff.eff_label -> l2: Prims.list LatticeEff.eff_label -> Prims.logical
Prims.Tot
[ "total" ]
[]
[ "Prims.list", "LatticeEff.eff_label", "Prims.l_Forall", "Prims.l_imp", "Prims.b2t", "FStar.List.Tot.Base.mem", "Prims.logical" ]
[]
false
false
false
true
true
let sublist (l1 l2: list eff_label) =
forall x. mem x l1 ==> mem x l2
false
LatticeEff.fst
LatticeEff.interp_at
val interp_at (l1 l2: list eff_label) (l: eff_label) : Lemma (interp (l1 @ l2) l == (interp l1 l || interp l2 l)) [SMTPat (interp (l1 @ l2) l)]
val interp_at (l1 l2: list eff_label) (l: eff_label) : Lemma (interp (l1 @ l2) l == (interp l1 l || interp l2 l)) [SMTPat (interp (l1 @ l2) l)]
let rec interp_at (l1 l2 : list eff_label) (l : eff_label) : Lemma (interp (l1@l2) l == (interp l1 l || interp l2 l)) [SMTPat (interp (l1@l2) l)] = match l1 with | [] -> () | _::l1 -> interp_at l1 l2 l
{ "file_name": "examples/layeredeffects/LatticeEff.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 32, "end_line": 63, "start_col": 0, "start_line": 58 }
module LatticeEff open FStar.Tactics.V2 open FStar.List.Tot open FStar.All module H = FStar.Heap // GM: Force a type equality by SMT let coerce #a #b (x:a{a == b}) : b = x let unreachable #a () : Pure a (requires False) (ensures (fun _ -> False)) = coerce "whatever" type eff_label = // GM: Can we do this one? ALL's WPs are unary and this is a // relational property. // | RD | WR //| DIV | EXN type annot = eff_label -> bool let interp (l : list eff_label) : annot = fun lab -> mem lab l type state = H.heap type wp a = all_wp_h H.heap a // boring, exponential //let wpof1 #a (l : list eff_label) : all_wp_h H.heap a = // let i = interp l in // match i ST, i EXN with // | false, false -> // fun p s0 -> forall x. p (V x) s0 // | true , false -> // fun p s0 -> forall x s1. p (V x) s1 // | false, true -> // fun p s0 -> forall r. p r s0 // | true, true -> // fun p s0 -> forall r s1. p r s1 (* more generic *) let wpof2 #a (l : list eff_label) : wp a = let i = interp l in let wp : wp a = fun p s0 -> (forall r s1. (i WR == false ==> s1 == s0) ==> (i EXN == false ==> V? r) ==> p r s1) in wp type repr (a:Type u#aa) (labs : list u#0 eff_label) // #2074 : Type u#0 = unit -> ALL a (wpof2 labs)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Heap.fst.checked", "FStar.Classical.fsti.checked", "FStar.All.fst.checked" ], "interface_file": false, "source_file": "LatticeEff.fst" }
[ { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
l1: Prims.list LatticeEff.eff_label -> l2: Prims.list LatticeEff.eff_label -> l: LatticeEff.eff_label -> FStar.Pervasives.Lemma (ensures LatticeEff.interp (l1 @ l2) l == (LatticeEff.interp l1 l || LatticeEff.interp l2 l)) [SMTPat (LatticeEff.interp (l1 @ l2) l)]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.list", "LatticeEff.eff_label", "LatticeEff.interp_at", "Prims.unit", "Prims.l_True", "Prims.squash", "Prims.eq2", "Prims.bool", "LatticeEff.interp", "FStar.List.Tot.Base.op_At", "Prims.op_BarBar", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat", "Prims.Nil" ]
[ "recursion" ]
false
false
true
false
false
let rec interp_at (l1 l2: list eff_label) (l: eff_label) : Lemma (interp (l1 @ l2) l == (interp l1 l || interp l2 l)) [SMTPat (interp (l1 @ l2) l)] =
match l1 with | [] -> () | _ :: l1 -> interp_at l1 l2 l
false
LatticeEff.fst
LatticeEff.coerce
val coerce (#a #b: _) (x: a{a == b}) : b
val coerce (#a #b: _) (x: a{a == b}) : b
let coerce #a #b (x:a{a == b}) : b = x
{ "file_name": "examples/layeredeffects/LatticeEff.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 38, "end_line": 9, "start_col": 0, "start_line": 9 }
module LatticeEff open FStar.Tactics.V2 open FStar.List.Tot open FStar.All module H = FStar.Heap
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Heap.fst.checked", "FStar.Classical.fsti.checked", "FStar.All.fst.checked" ], "interface_file": false, "source_file": "LatticeEff.fst" }
[ { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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{a == b} -> b
Prims.Tot
[ "total" ]
[]
[ "Prims.eq2" ]
[]
false
false
false
false
false
let coerce #a #b (x: a{a == b}) : b =
x
false
LatticeEff.fst
LatticeEff.interp_sublist
val interp_sublist (l1 l2: list eff_label) (l: eff_label) : Lemma (requires (sublist l1 l2)) (ensures (interp l1 l ==> interp l2 l)) [SMTPat (interp l1 l); SMTPat (sublist l1 l2)]
val interp_sublist (l1 l2: list eff_label) (l: eff_label) : Lemma (requires (sublist l1 l2)) (ensures (interp l1 l ==> interp l2 l)) [SMTPat (interp l1 l); SMTPat (sublist l1 l2)]
let rec interp_sublist (l1 l2 : list eff_label) (l : eff_label) : Lemma (requires (sublist l1 l2)) (ensures (interp l1 l ==> interp l2 l)) [SMTPat (interp l1 l); SMTPat (sublist l1 l2)] = match l1 with | [] -> () | _::l1 -> interp_sublist l1 l2 l
{ "file_name": "examples/layeredeffects/LatticeEff.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 37, "end_line": 80, "start_col": 0, "start_line": 74 }
module LatticeEff open FStar.Tactics.V2 open FStar.List.Tot open FStar.All module H = FStar.Heap // GM: Force a type equality by SMT let coerce #a #b (x:a{a == b}) : b = x let unreachable #a () : Pure a (requires False) (ensures (fun _ -> False)) = coerce "whatever" type eff_label = // GM: Can we do this one? ALL's WPs are unary and this is a // relational property. // | RD | WR //| DIV | EXN type annot = eff_label -> bool let interp (l : list eff_label) : annot = fun lab -> mem lab l type state = H.heap type wp a = all_wp_h H.heap a // boring, exponential //let wpof1 #a (l : list eff_label) : all_wp_h H.heap a = // let i = interp l in // match i ST, i EXN with // | false, false -> // fun p s0 -> forall x. p (V x) s0 // | true , false -> // fun p s0 -> forall x s1. p (V x) s1 // | false, true -> // fun p s0 -> forall r. p r s0 // | true, true -> // fun p s0 -> forall r s1. p r s1 (* more generic *) let wpof2 #a (l : list eff_label) : wp a = let i = interp l in let wp : wp a = fun p s0 -> (forall r s1. (i WR == false ==> s1 == s0) ==> (i EXN == false ==> V? r) ==> p r s1) in wp type repr (a:Type u#aa) (labs : list u#0 eff_label) // #2074 : Type u#0 = unit -> ALL a (wpof2 labs) let rec interp_at (l1 l2 : list eff_label) (l : eff_label) : Lemma (interp (l1@l2) l == (interp l1 l || interp l2 l)) [SMTPat (interp (l1@l2) l)] = match l1 with | [] -> () | _::l1 -> interp_at l1 l2 l let sublist (l1 l2 : list eff_label) = forall x. mem x l1 ==> mem x l2 let sublist_refl (l : list eff_label) : Lemma (sublist l l) [SMTPat (sublist l l)] = ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Heap.fst.checked", "FStar.Classical.fsti.checked", "FStar.All.fst.checked" ], "interface_file": false, "source_file": "LatticeEff.fst" }
[ { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
l1: Prims.list LatticeEff.eff_label -> l2: Prims.list LatticeEff.eff_label -> l: LatticeEff.eff_label -> FStar.Pervasives.Lemma (requires LatticeEff.sublist l1 l2) (ensures LatticeEff.interp l1 l ==> LatticeEff.interp l2 l) [SMTPat (LatticeEff.interp l1 l); SMTPat (LatticeEff.sublist l1 l2)]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.list", "LatticeEff.eff_label", "LatticeEff.interp_sublist", "Prims.unit", "LatticeEff.sublist", "Prims.squash", "Prims.l_imp", "Prims.b2t", "LatticeEff.interp", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat", "Prims.bool", "Prims.logical", "Prims.Nil" ]
[ "recursion" ]
false
false
true
false
false
let rec interp_sublist (l1 l2: list eff_label) (l: eff_label) : Lemma (requires (sublist l1 l2)) (ensures (interp l1 l ==> interp l2 l)) [SMTPat (interp l1 l); SMTPat (sublist l1 l2)] =
match l1 with | [] -> () | _ :: l1 -> interp_sublist l1 l2 l
false
LatticeEff.fst
LatticeEff.return
val return (a: Type) (x: a) : repr a []
val return (a: Type) (x: a) : repr a []
let return (a:Type) (x:a) : repr a [] = fun () -> x
{ "file_name": "examples/layeredeffects/LatticeEff.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 13, "end_line": 97, "start_col": 0, "start_line": 94 }
module LatticeEff open FStar.Tactics.V2 open FStar.List.Tot open FStar.All module H = FStar.Heap // GM: Force a type equality by SMT let coerce #a #b (x:a{a == b}) : b = x let unreachable #a () : Pure a (requires False) (ensures (fun _ -> False)) = coerce "whatever" type eff_label = // GM: Can we do this one? ALL's WPs are unary and this is a // relational property. // | RD | WR //| DIV | EXN type annot = eff_label -> bool let interp (l : list eff_label) : annot = fun lab -> mem lab l type state = H.heap type wp a = all_wp_h H.heap a // boring, exponential //let wpof1 #a (l : list eff_label) : all_wp_h H.heap a = // let i = interp l in // match i ST, i EXN with // | false, false -> // fun p s0 -> forall x. p (V x) s0 // | true , false -> // fun p s0 -> forall x s1. p (V x) s1 // | false, true -> // fun p s0 -> forall r. p r s0 // | true, true -> // fun p s0 -> forall r s1. p r s1 (* more generic *) let wpof2 #a (l : list eff_label) : wp a = let i = interp l in let wp : wp a = fun p s0 -> (forall r s1. (i WR == false ==> s1 == s0) ==> (i EXN == false ==> V? r) ==> p r s1) in wp type repr (a:Type u#aa) (labs : list u#0 eff_label) // #2074 : Type u#0 = unit -> ALL a (wpof2 labs) let rec interp_at (l1 l2 : list eff_label) (l : eff_label) : Lemma (interp (l1@l2) l == (interp l1 l || interp l2 l)) [SMTPat (interp (l1@l2) l)] = match l1 with | [] -> () | _::l1 -> interp_at l1 l2 l let sublist (l1 l2 : list eff_label) = forall x. mem x l1 ==> mem x l2 let sublist_refl (l : list eff_label) : Lemma (sublist l l) [SMTPat (sublist l l)] = () let rec interp_sublist (l1 l2 : list eff_label) (l : eff_label) : Lemma (requires (sublist l1 l2)) (ensures (interp l1 l ==> interp l2 l)) [SMTPat (interp l1 l); SMTPat (sublist l1 l2)] = match l1 with | [] -> () | _::l1 -> interp_sublist l1 l2 l let rec sublist_at (l1 l2 : list eff_label) : Lemma (sublist l1 (l1@l2) /\ sublist l2 (l1@l2)) [SMTPatOr [[SMTPat (sublist l1 (l1@l2))]; [SMTPat (sublist l2 (l1@l2))]]] = match l1 with | [] -> () | _::l1 -> sublist_at l1 l2 let ann_le (ann1 ann2 : annot) : prop = forall x. ann1 x ==> ann2 x
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Heap.fst.checked", "FStar.Classical.fsti.checked", "FStar.All.fst.checked" ], "interface_file": false, "source_file": "LatticeEff.fst" }
[ { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Type -> x: a -> LatticeEff.repr a []
Prims.Tot
[ "total" ]
[]
[ "Prims.unit", "LatticeEff.repr", "Prims.Nil", "LatticeEff.eff_label" ]
[]
false
false
false
true
false
let return (a: Type) (x: a) : repr a [] =
fun () -> x
false
LatticeEff.fst
LatticeEff.sublist_at
val sublist_at (l1 l2: list eff_label) : Lemma (sublist l1 (l1 @ l2) /\ sublist l2 (l1 @ l2)) [SMTPatOr [[SMTPat (sublist l1 (l1 @ l2))]; [SMTPat (sublist l2 (l1 @ l2))]]]
val sublist_at (l1 l2: list eff_label) : Lemma (sublist l1 (l1 @ l2) /\ sublist l2 (l1 @ l2)) [SMTPatOr [[SMTPat (sublist l1 (l1 @ l2))]; [SMTPat (sublist l2 (l1 @ l2))]]]
let rec sublist_at (l1 l2 : list eff_label) : Lemma (sublist l1 (l1@l2) /\ sublist l2 (l1@l2)) [SMTPatOr [[SMTPat (sublist l1 (l1@l2))]; [SMTPat (sublist l2 (l1@l2))]]] = match l1 with | [] -> () | _::l1 -> sublist_at l1 l2
{ "file_name": "examples/layeredeffects/LatticeEff.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 31, "end_line": 89, "start_col": 0, "start_line": 82 }
module LatticeEff open FStar.Tactics.V2 open FStar.List.Tot open FStar.All module H = FStar.Heap // GM: Force a type equality by SMT let coerce #a #b (x:a{a == b}) : b = x let unreachable #a () : Pure a (requires False) (ensures (fun _ -> False)) = coerce "whatever" type eff_label = // GM: Can we do this one? ALL's WPs are unary and this is a // relational property. // | RD | WR //| DIV | EXN type annot = eff_label -> bool let interp (l : list eff_label) : annot = fun lab -> mem lab l type state = H.heap type wp a = all_wp_h H.heap a // boring, exponential //let wpof1 #a (l : list eff_label) : all_wp_h H.heap a = // let i = interp l in // match i ST, i EXN with // | false, false -> // fun p s0 -> forall x. p (V x) s0 // | true , false -> // fun p s0 -> forall x s1. p (V x) s1 // | false, true -> // fun p s0 -> forall r. p r s0 // | true, true -> // fun p s0 -> forall r s1. p r s1 (* more generic *) let wpof2 #a (l : list eff_label) : wp a = let i = interp l in let wp : wp a = fun p s0 -> (forall r s1. (i WR == false ==> s1 == s0) ==> (i EXN == false ==> V? r) ==> p r s1) in wp type repr (a:Type u#aa) (labs : list u#0 eff_label) // #2074 : Type u#0 = unit -> ALL a (wpof2 labs) let rec interp_at (l1 l2 : list eff_label) (l : eff_label) : Lemma (interp (l1@l2) l == (interp l1 l || interp l2 l)) [SMTPat (interp (l1@l2) l)] = match l1 with | [] -> () | _::l1 -> interp_at l1 l2 l let sublist (l1 l2 : list eff_label) = forall x. mem x l1 ==> mem x l2 let sublist_refl (l : list eff_label) : Lemma (sublist l l) [SMTPat (sublist l l)] = () let rec interp_sublist (l1 l2 : list eff_label) (l : eff_label) : Lemma (requires (sublist l1 l2)) (ensures (interp l1 l ==> interp l2 l)) [SMTPat (interp l1 l); SMTPat (sublist l1 l2)] = match l1 with | [] -> () | _::l1 -> interp_sublist l1 l2 l
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Heap.fst.checked", "FStar.Classical.fsti.checked", "FStar.All.fst.checked" ], "interface_file": false, "source_file": "LatticeEff.fst" }
[ { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
l1: Prims.list LatticeEff.eff_label -> l2: Prims.list LatticeEff.eff_label -> FStar.Pervasives.Lemma (ensures LatticeEff.sublist l1 (l1 @ l2) /\ LatticeEff.sublist l2 (l1 @ l2)) [ SMTPatOr [ [SMTPat (LatticeEff.sublist l1 (l1 @ l2))]; [SMTPat (LatticeEff.sublist l2 (l1 @ l2))] ] ]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.list", "LatticeEff.eff_label", "LatticeEff.sublist_at", "Prims.unit", "Prims.l_True", "Prims.squash", "Prims.l_and", "LatticeEff.sublist", "FStar.List.Tot.Base.op_At", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat_or", "FStar.Pervasives.smt_pat", "Prims.logical", "Prims.Nil" ]
[ "recursion" ]
false
false
true
false
false
let rec sublist_at (l1 l2: list eff_label) : Lemma (sublist l1 (l1 @ l2) /\ sublist l2 (l1 @ l2)) [SMTPatOr [[SMTPat (sublist l1 (l1 @ l2))]; [SMTPat (sublist l2 (l1 @ l2))]]] =
match l1 with | [] -> () | _ :: l1 -> sublist_at l1 l2
false
LatticeEff.fst
LatticeEff.bind
val bind (a b: Type) (labs1 labs2: list eff_label) (c: repr a labs1) (f: (x: a -> repr b labs2)) : Tot (repr b (labs1 @ labs2))
val bind (a b: Type) (labs1 labs2: list eff_label) (c: repr a labs1) (f: (x: a -> repr b labs2)) : Tot (repr b (labs1 @ labs2))
let bind (a b : Type) (labs1 labs2 : list eff_label) (c : repr a labs1) (f : (x:a -> repr b labs2)) : Tot (repr b (labs1@labs2)) = fun () -> f (c ()) ()
{ "file_name": "examples/layeredeffects/LatticeEff.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 25, "end_line": 104, "start_col": 0, "start_line": 99 }
module LatticeEff open FStar.Tactics.V2 open FStar.List.Tot open FStar.All module H = FStar.Heap // GM: Force a type equality by SMT let coerce #a #b (x:a{a == b}) : b = x let unreachable #a () : Pure a (requires False) (ensures (fun _ -> False)) = coerce "whatever" type eff_label = // GM: Can we do this one? ALL's WPs are unary and this is a // relational property. // | RD | WR //| DIV | EXN type annot = eff_label -> bool let interp (l : list eff_label) : annot = fun lab -> mem lab l type state = H.heap type wp a = all_wp_h H.heap a // boring, exponential //let wpof1 #a (l : list eff_label) : all_wp_h H.heap a = // let i = interp l in // match i ST, i EXN with // | false, false -> // fun p s0 -> forall x. p (V x) s0 // | true , false -> // fun p s0 -> forall x s1. p (V x) s1 // | false, true -> // fun p s0 -> forall r. p r s0 // | true, true -> // fun p s0 -> forall r s1. p r s1 (* more generic *) let wpof2 #a (l : list eff_label) : wp a = let i = interp l in let wp : wp a = fun p s0 -> (forall r s1. (i WR == false ==> s1 == s0) ==> (i EXN == false ==> V? r) ==> p r s1) in wp type repr (a:Type u#aa) (labs : list u#0 eff_label) // #2074 : Type u#0 = unit -> ALL a (wpof2 labs) let rec interp_at (l1 l2 : list eff_label) (l : eff_label) : Lemma (interp (l1@l2) l == (interp l1 l || interp l2 l)) [SMTPat (interp (l1@l2) l)] = match l1 with | [] -> () | _::l1 -> interp_at l1 l2 l let sublist (l1 l2 : list eff_label) = forall x. mem x l1 ==> mem x l2 let sublist_refl (l : list eff_label) : Lemma (sublist l l) [SMTPat (sublist l l)] = () let rec interp_sublist (l1 l2 : list eff_label) (l : eff_label) : Lemma (requires (sublist l1 l2)) (ensures (interp l1 l ==> interp l2 l)) [SMTPat (interp l1 l); SMTPat (sublist l1 l2)] = match l1 with | [] -> () | _::l1 -> interp_sublist l1 l2 l let rec sublist_at (l1 l2 : list eff_label) : Lemma (sublist l1 (l1@l2) /\ sublist l2 (l1@l2)) [SMTPatOr [[SMTPat (sublist l1 (l1@l2))]; [SMTPat (sublist l2 (l1@l2))]]] = match l1 with | [] -> () | _::l1 -> sublist_at l1 l2 let ann_le (ann1 ann2 : annot) : prop = forall x. ann1 x ==> ann2 x let return (a:Type) (x:a) : repr a [] = fun () -> x
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Heap.fst.checked", "FStar.Classical.fsti.checked", "FStar.All.fst.checked" ], "interface_file": false, "source_file": "LatticeEff.fst" }
[ { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Type -> b: Type -> labs1: Prims.list LatticeEff.eff_label -> labs2: Prims.list LatticeEff.eff_label -> c: LatticeEff.repr a labs1 -> f: (x: a -> LatticeEff.repr b labs2) -> LatticeEff.repr b (labs1 @ labs2)
Prims.Tot
[ "total" ]
[]
[ "Prims.list", "LatticeEff.eff_label", "LatticeEff.repr", "Prims.unit", "FStar.List.Tot.Base.op_At" ]
[]
false
false
false
false
false
let bind (a b: Type) (labs1 labs2: list eff_label) (c: repr a labs1) (f: (x: a -> repr b labs2)) : Tot (repr b (labs1 @ labs2)) =
fun () -> f (c ()) ()
false
LatticeEff.fst
LatticeEff.subcomp
val subcomp (a: Type) (labs1 labs2: list eff_label) (f: repr a labs1) : Pure (repr a labs2) (requires (sublist labs1 labs2)) (ensures (fun _ -> True))
val subcomp (a: Type) (labs1 labs2: list eff_label) (f: repr a labs1) : Pure (repr a labs2) (requires (sublist labs1 labs2)) (ensures (fun _ -> True))
let subcomp (a:Type) (labs1 labs2 : list eff_label) (f : repr a labs1) : Pure (repr a labs2) (requires (sublist labs1 labs2)) (ensures (fun _ -> True)) = f
{ "file_name": "examples/layeredeffects/LatticeEff.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 5, "end_line": 112, "start_col": 0, "start_line": 106 }
module LatticeEff open FStar.Tactics.V2 open FStar.List.Tot open FStar.All module H = FStar.Heap // GM: Force a type equality by SMT let coerce #a #b (x:a{a == b}) : b = x let unreachable #a () : Pure a (requires False) (ensures (fun _ -> False)) = coerce "whatever" type eff_label = // GM: Can we do this one? ALL's WPs are unary and this is a // relational property. // | RD | WR //| DIV | EXN type annot = eff_label -> bool let interp (l : list eff_label) : annot = fun lab -> mem lab l type state = H.heap type wp a = all_wp_h H.heap a // boring, exponential //let wpof1 #a (l : list eff_label) : all_wp_h H.heap a = // let i = interp l in // match i ST, i EXN with // | false, false -> // fun p s0 -> forall x. p (V x) s0 // | true , false -> // fun p s0 -> forall x s1. p (V x) s1 // | false, true -> // fun p s0 -> forall r. p r s0 // | true, true -> // fun p s0 -> forall r s1. p r s1 (* more generic *) let wpof2 #a (l : list eff_label) : wp a = let i = interp l in let wp : wp a = fun p s0 -> (forall r s1. (i WR == false ==> s1 == s0) ==> (i EXN == false ==> V? r) ==> p r s1) in wp type repr (a:Type u#aa) (labs : list u#0 eff_label) // #2074 : Type u#0 = unit -> ALL a (wpof2 labs) let rec interp_at (l1 l2 : list eff_label) (l : eff_label) : Lemma (interp (l1@l2) l == (interp l1 l || interp l2 l)) [SMTPat (interp (l1@l2) l)] = match l1 with | [] -> () | _::l1 -> interp_at l1 l2 l let sublist (l1 l2 : list eff_label) = forall x. mem x l1 ==> mem x l2 let sublist_refl (l : list eff_label) : Lemma (sublist l l) [SMTPat (sublist l l)] = () let rec interp_sublist (l1 l2 : list eff_label) (l : eff_label) : Lemma (requires (sublist l1 l2)) (ensures (interp l1 l ==> interp l2 l)) [SMTPat (interp l1 l); SMTPat (sublist l1 l2)] = match l1 with | [] -> () | _::l1 -> interp_sublist l1 l2 l let rec sublist_at (l1 l2 : list eff_label) : Lemma (sublist l1 (l1@l2) /\ sublist l2 (l1@l2)) [SMTPatOr [[SMTPat (sublist l1 (l1@l2))]; [SMTPat (sublist l2 (l1@l2))]]] = match l1 with | [] -> () | _::l1 -> sublist_at l1 l2 let ann_le (ann1 ann2 : annot) : prop = forall x. ann1 x ==> ann2 x let return (a:Type) (x:a) : repr a [] = fun () -> x let bind (a b : Type) (labs1 labs2 : list eff_label) (c : repr a labs1) (f : (x:a -> repr b labs2)) : Tot (repr b (labs1@labs2)) = fun () -> f (c ()) ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Heap.fst.checked", "FStar.Classical.fsti.checked", "FStar.All.fst.checked" ], "interface_file": false, "source_file": "LatticeEff.fst" }
[ { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Type -> labs1: Prims.list LatticeEff.eff_label -> labs2: Prims.list LatticeEff.eff_label -> f: LatticeEff.repr a labs1 -> Prims.Pure (LatticeEff.repr a labs2)
Prims.Pure
[]
[]
[ "Prims.list", "LatticeEff.eff_label", "LatticeEff.repr", "LatticeEff.sublist", "Prims.l_True" ]
[]
false
false
false
false
false
let subcomp (a: Type) (labs1 labs2: list eff_label) (f: repr a labs1) : Pure (repr a labs2) (requires (sublist labs1 labs2)) (ensures (fun _ -> True)) =
f
false
LatticeEff.fst
LatticeEff.put
val put (s: state{forall s1. heap_rel s1 s}) : EFF unit [WR]
val put (s: state{forall s1. heap_rel s1 s}) : EFF unit [WR]
let put (s:state{forall s1. heap_rel s1 s}) : EFF unit [WR] = EFF?.reflect (fun () -> gst_put s)
{ "file_name": "examples/layeredeffects/LatticeEff.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 36, "end_line": 157, "start_col": 0, "start_line": 156 }
module LatticeEff open FStar.Tactics.V2 open FStar.List.Tot open FStar.All module H = FStar.Heap // GM: Force a type equality by SMT let coerce #a #b (x:a{a == b}) : b = x let unreachable #a () : Pure a (requires False) (ensures (fun _ -> False)) = coerce "whatever" type eff_label = // GM: Can we do this one? ALL's WPs are unary and this is a // relational property. // | RD | WR //| DIV | EXN type annot = eff_label -> bool let interp (l : list eff_label) : annot = fun lab -> mem lab l type state = H.heap type wp a = all_wp_h H.heap a // boring, exponential //let wpof1 #a (l : list eff_label) : all_wp_h H.heap a = // let i = interp l in // match i ST, i EXN with // | false, false -> // fun p s0 -> forall x. p (V x) s0 // | true , false -> // fun p s0 -> forall x s1. p (V x) s1 // | false, true -> // fun p s0 -> forall r. p r s0 // | true, true -> // fun p s0 -> forall r s1. p r s1 (* more generic *) let wpof2 #a (l : list eff_label) : wp a = let i = interp l in let wp : wp a = fun p s0 -> (forall r s1. (i WR == false ==> s1 == s0) ==> (i EXN == false ==> V? r) ==> p r s1) in wp type repr (a:Type u#aa) (labs : list u#0 eff_label) // #2074 : Type u#0 = unit -> ALL a (wpof2 labs) let rec interp_at (l1 l2 : list eff_label) (l : eff_label) : Lemma (interp (l1@l2) l == (interp l1 l || interp l2 l)) [SMTPat (interp (l1@l2) l)] = match l1 with | [] -> () | _::l1 -> interp_at l1 l2 l let sublist (l1 l2 : list eff_label) = forall x. mem x l1 ==> mem x l2 let sublist_refl (l : list eff_label) : Lemma (sublist l l) [SMTPat (sublist l l)] = () let rec interp_sublist (l1 l2 : list eff_label) (l : eff_label) : Lemma (requires (sublist l1 l2)) (ensures (interp l1 l ==> interp l2 l)) [SMTPat (interp l1 l); SMTPat (sublist l1 l2)] = match l1 with | [] -> () | _::l1 -> interp_sublist l1 l2 l let rec sublist_at (l1 l2 : list eff_label) : Lemma (sublist l1 (l1@l2) /\ sublist l2 (l1@l2)) [SMTPatOr [[SMTPat (sublist l1 (l1@l2))]; [SMTPat (sublist l2 (l1@l2))]]] = match l1 with | [] -> () | _::l1 -> sublist_at l1 l2 let ann_le (ann1 ann2 : annot) : prop = forall x. ann1 x ==> ann2 x let return (a:Type) (x:a) : repr a [] = fun () -> x let bind (a b : Type) (labs1 labs2 : list eff_label) (c : repr a labs1) (f : (x:a -> repr b labs2)) : Tot (repr b (labs1@labs2)) = fun () -> f (c ()) () let subcomp (a:Type) (labs1 labs2 : list eff_label) (f : repr a labs1) : Pure (repr a labs2) (requires (sublist labs1 labs2)) (ensures (fun _ -> True)) = f let ite (p q r : Type0) = (p ==> q) /\ (~p ==> r) let if_then_else (a : Type) (labs1 labs2 : list eff_label) (f : repr a labs1) (g : repr a labs2) (p : bool) : Type = repr a (labs1@labs2) total reifiable reflectable effect { EFF (a:Type) (_:list eff_label) with {repr; return; bind; subcomp; if_then_else} } let lift_pure_eff (a:Type) (wp : pure_wp a) (f : unit -> PURE a wp) : Pure (repr a []) (requires (wp (fun _ -> True))) (ensures (fun _ -> True)) = FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp; fun () -> f () sub_effect PURE ~> EFF = lift_pure_eff let get () : EFF H.heap [] = EFF?.reflect (fun () -> get ()) let (!) #a (r:ref a) : EFF a [] = EFF?.reflect (fun () -> !r) let (:=) #a (r:ref a) (v:a) : EFF unit [WR] = EFF?.reflect (fun () -> r := v) (* GM: The refinement is clearly crap, just trying to get a typeable
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Heap.fst.checked", "FStar.Classical.fsti.checked", "FStar.All.fst.checked" ], "interface_file": false, "source_file": "LatticeEff.fst" }
[ { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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: LatticeEff.state{forall (s1: FStar.Monotonic.Heap.heap). FStar.ST.heap_rel s1 s} -> LatticeEff.EFF Prims.unit
LatticeEff.EFF
[]
[]
[ "LatticeEff.state", "Prims.l_Forall", "FStar.Monotonic.Heap.heap", "FStar.ST.heap_rel", "Prims.unit", "FStar.ST.gst_put", "Prims.Cons", "LatticeEff.eff_label", "LatticeEff.WR", "Prims.Nil" ]
[]
false
true
false
false
false
let put (s: state{forall s1. heap_rel s1 s}) : EFF unit [WR] =
EFF?.reflect (fun () -> gst_put s)
false
LatticeEff.fst
LatticeEff.lift_pure_eff
val lift_pure_eff (a: Type) (wp: pure_wp a) (f: (unit -> PURE a wp)) : Pure (repr a []) (requires (wp (fun _ -> True))) (ensures (fun _ -> True))
val lift_pure_eff (a: Type) (wp: pure_wp a) (f: (unit -> PURE a wp)) : Pure (repr a []) (requires (wp (fun _ -> True))) (ensures (fun _ -> True))
let lift_pure_eff (a:Type) (wp : pure_wp a) (f : unit -> PURE a wp) : Pure (repr a []) (requires (wp (fun _ -> True))) (ensures (fun _ -> True)) = FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp; fun () -> f ()
{ "file_name": "examples/layeredeffects/LatticeEff.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 17, "end_line": 141, "start_col": 0, "start_line": 133 }
module LatticeEff open FStar.Tactics.V2 open FStar.List.Tot open FStar.All module H = FStar.Heap // GM: Force a type equality by SMT let coerce #a #b (x:a{a == b}) : b = x let unreachable #a () : Pure a (requires False) (ensures (fun _ -> False)) = coerce "whatever" type eff_label = // GM: Can we do this one? ALL's WPs are unary and this is a // relational property. // | RD | WR //| DIV | EXN type annot = eff_label -> bool let interp (l : list eff_label) : annot = fun lab -> mem lab l type state = H.heap type wp a = all_wp_h H.heap a // boring, exponential //let wpof1 #a (l : list eff_label) : all_wp_h H.heap a = // let i = interp l in // match i ST, i EXN with // | false, false -> // fun p s0 -> forall x. p (V x) s0 // | true , false -> // fun p s0 -> forall x s1. p (V x) s1 // | false, true -> // fun p s0 -> forall r. p r s0 // | true, true -> // fun p s0 -> forall r s1. p r s1 (* more generic *) let wpof2 #a (l : list eff_label) : wp a = let i = interp l in let wp : wp a = fun p s0 -> (forall r s1. (i WR == false ==> s1 == s0) ==> (i EXN == false ==> V? r) ==> p r s1) in wp type repr (a:Type u#aa) (labs : list u#0 eff_label) // #2074 : Type u#0 = unit -> ALL a (wpof2 labs) let rec interp_at (l1 l2 : list eff_label) (l : eff_label) : Lemma (interp (l1@l2) l == (interp l1 l || interp l2 l)) [SMTPat (interp (l1@l2) l)] = match l1 with | [] -> () | _::l1 -> interp_at l1 l2 l let sublist (l1 l2 : list eff_label) = forall x. mem x l1 ==> mem x l2 let sublist_refl (l : list eff_label) : Lemma (sublist l l) [SMTPat (sublist l l)] = () let rec interp_sublist (l1 l2 : list eff_label) (l : eff_label) : Lemma (requires (sublist l1 l2)) (ensures (interp l1 l ==> interp l2 l)) [SMTPat (interp l1 l); SMTPat (sublist l1 l2)] = match l1 with | [] -> () | _::l1 -> interp_sublist l1 l2 l let rec sublist_at (l1 l2 : list eff_label) : Lemma (sublist l1 (l1@l2) /\ sublist l2 (l1@l2)) [SMTPatOr [[SMTPat (sublist l1 (l1@l2))]; [SMTPat (sublist l2 (l1@l2))]]] = match l1 with | [] -> () | _::l1 -> sublist_at l1 l2 let ann_le (ann1 ann2 : annot) : prop = forall x. ann1 x ==> ann2 x let return (a:Type) (x:a) : repr a [] = fun () -> x let bind (a b : Type) (labs1 labs2 : list eff_label) (c : repr a labs1) (f : (x:a -> repr b labs2)) : Tot (repr b (labs1@labs2)) = fun () -> f (c ()) () let subcomp (a:Type) (labs1 labs2 : list eff_label) (f : repr a labs1) : Pure (repr a labs2) (requires (sublist labs1 labs2)) (ensures (fun _ -> True)) = f let ite (p q r : Type0) = (p ==> q) /\ (~p ==> r) let if_then_else (a : Type) (labs1 labs2 : list eff_label) (f : repr a labs1) (g : repr a labs2) (p : bool) : Type = repr a (labs1@labs2) total reifiable reflectable effect { EFF (a:Type) (_:list eff_label) with {repr; return; bind; subcomp; if_then_else} }
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Heap.fst.checked", "FStar.Classical.fsti.checked", "FStar.All.fst.checked" ], "interface_file": false, "source_file": "LatticeEff.fst" }
[ { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Type -> wp: Prims.pure_wp a -> f: (_: Prims.unit -> Prims.PURE a) -> Prims.Pure (LatticeEff.repr a [])
Prims.Pure
[]
[]
[ "Prims.pure_wp", "Prims.unit", "FStar.Monotonic.Pure.elim_pure_wp_monotonicity", "LatticeEff.repr", "Prims.Nil", "LatticeEff.eff_label", "Prims.l_True" ]
[]
false
false
false
false
false
let lift_pure_eff (a: Type) (wp: pure_wp a) (f: (unit -> PURE a wp)) : Pure (repr a []) (requires (wp (fun _ -> True))) (ensures (fun _ -> True)) =
FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp; fun () -> f ()
false
LatticeEff.fst
LatticeEff.get
val get: Prims.unit -> EFF H.heap []
val get: Prims.unit -> EFF H.heap []
let get () : EFF H.heap [] = EFF?.reflect (fun () -> get ())
{ "file_name": "examples/layeredeffects/LatticeEff.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 33, "end_line": 146, "start_col": 0, "start_line": 145 }
module LatticeEff open FStar.Tactics.V2 open FStar.List.Tot open FStar.All module H = FStar.Heap // GM: Force a type equality by SMT let coerce #a #b (x:a{a == b}) : b = x let unreachable #a () : Pure a (requires False) (ensures (fun _ -> False)) = coerce "whatever" type eff_label = // GM: Can we do this one? ALL's WPs are unary and this is a // relational property. // | RD | WR //| DIV | EXN type annot = eff_label -> bool let interp (l : list eff_label) : annot = fun lab -> mem lab l type state = H.heap type wp a = all_wp_h H.heap a // boring, exponential //let wpof1 #a (l : list eff_label) : all_wp_h H.heap a = // let i = interp l in // match i ST, i EXN with // | false, false -> // fun p s0 -> forall x. p (V x) s0 // | true , false -> // fun p s0 -> forall x s1. p (V x) s1 // | false, true -> // fun p s0 -> forall r. p r s0 // | true, true -> // fun p s0 -> forall r s1. p r s1 (* more generic *) let wpof2 #a (l : list eff_label) : wp a = let i = interp l in let wp : wp a = fun p s0 -> (forall r s1. (i WR == false ==> s1 == s0) ==> (i EXN == false ==> V? r) ==> p r s1) in wp type repr (a:Type u#aa) (labs : list u#0 eff_label) // #2074 : Type u#0 = unit -> ALL a (wpof2 labs) let rec interp_at (l1 l2 : list eff_label) (l : eff_label) : Lemma (interp (l1@l2) l == (interp l1 l || interp l2 l)) [SMTPat (interp (l1@l2) l)] = match l1 with | [] -> () | _::l1 -> interp_at l1 l2 l let sublist (l1 l2 : list eff_label) = forall x. mem x l1 ==> mem x l2 let sublist_refl (l : list eff_label) : Lemma (sublist l l) [SMTPat (sublist l l)] = () let rec interp_sublist (l1 l2 : list eff_label) (l : eff_label) : Lemma (requires (sublist l1 l2)) (ensures (interp l1 l ==> interp l2 l)) [SMTPat (interp l1 l); SMTPat (sublist l1 l2)] = match l1 with | [] -> () | _::l1 -> interp_sublist l1 l2 l let rec sublist_at (l1 l2 : list eff_label) : Lemma (sublist l1 (l1@l2) /\ sublist l2 (l1@l2)) [SMTPatOr [[SMTPat (sublist l1 (l1@l2))]; [SMTPat (sublist l2 (l1@l2))]]] = match l1 with | [] -> () | _::l1 -> sublist_at l1 l2 let ann_le (ann1 ann2 : annot) : prop = forall x. ann1 x ==> ann2 x let return (a:Type) (x:a) : repr a [] = fun () -> x let bind (a b : Type) (labs1 labs2 : list eff_label) (c : repr a labs1) (f : (x:a -> repr b labs2)) : Tot (repr b (labs1@labs2)) = fun () -> f (c ()) () let subcomp (a:Type) (labs1 labs2 : list eff_label) (f : repr a labs1) : Pure (repr a labs2) (requires (sublist labs1 labs2)) (ensures (fun _ -> True)) = f let ite (p q r : Type0) = (p ==> q) /\ (~p ==> r) let if_then_else (a : Type) (labs1 labs2 : list eff_label) (f : repr a labs1) (g : repr a labs2) (p : bool) : Type = repr a (labs1@labs2) total reifiable reflectable effect { EFF (a:Type) (_:list eff_label) with {repr; return; bind; subcomp; if_then_else} } let lift_pure_eff (a:Type) (wp : pure_wp a) (f : unit -> PURE a wp) : Pure (repr a []) (requires (wp (fun _ -> True))) (ensures (fun _ -> True)) = FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp; fun () -> f () sub_effect PURE ~> EFF = lift_pure_eff
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Heap.fst.checked", "FStar.Classical.fsti.checked", "FStar.All.fst.checked" ], "interface_file": false, "source_file": "LatticeEff.fst" }
[ { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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 -> LatticeEff.EFF FStar.Monotonic.Heap.heap
LatticeEff.EFF
[]
[]
[ "Prims.unit", "FStar.ST.get", "FStar.Monotonic.Heap.heap", "Prims.Nil", "LatticeEff.eff_label" ]
[]
false
true
false
false
false
let get () : EFF H.heap [] =
EFF?.reflect (fun () -> get ())
false
LatticeEff.fst
LatticeEff.test1
val test1 (r: ref int) (x y: int) : EFF int [EXN; WR]
val test1 (r: ref int) (x y: int) : EFF int [EXN; WR]
let test1 (r:ref int) (x y : int) : EFF int [EXN; WR] = let z = !r in if x + z > 0 then raise (Failure "nope") else (r := 42; y - z)
{ "file_name": "examples/layeredeffects/LatticeEff.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 23, "end_line": 172, "start_col": 0, "start_line": 168 }
module LatticeEff open FStar.Tactics.V2 open FStar.List.Tot open FStar.All module H = FStar.Heap // GM: Force a type equality by SMT let coerce #a #b (x:a{a == b}) : b = x let unreachable #a () : Pure a (requires False) (ensures (fun _ -> False)) = coerce "whatever" type eff_label = // GM: Can we do this one? ALL's WPs are unary and this is a // relational property. // | RD | WR //| DIV | EXN type annot = eff_label -> bool let interp (l : list eff_label) : annot = fun lab -> mem lab l type state = H.heap type wp a = all_wp_h H.heap a // boring, exponential //let wpof1 #a (l : list eff_label) : all_wp_h H.heap a = // let i = interp l in // match i ST, i EXN with // | false, false -> // fun p s0 -> forall x. p (V x) s0 // | true , false -> // fun p s0 -> forall x s1. p (V x) s1 // | false, true -> // fun p s0 -> forall r. p r s0 // | true, true -> // fun p s0 -> forall r s1. p r s1 (* more generic *) let wpof2 #a (l : list eff_label) : wp a = let i = interp l in let wp : wp a = fun p s0 -> (forall r s1. (i WR == false ==> s1 == s0) ==> (i EXN == false ==> V? r) ==> p r s1) in wp type repr (a:Type u#aa) (labs : list u#0 eff_label) // #2074 : Type u#0 = unit -> ALL a (wpof2 labs) let rec interp_at (l1 l2 : list eff_label) (l : eff_label) : Lemma (interp (l1@l2) l == (interp l1 l || interp l2 l)) [SMTPat (interp (l1@l2) l)] = match l1 with | [] -> () | _::l1 -> interp_at l1 l2 l let sublist (l1 l2 : list eff_label) = forall x. mem x l1 ==> mem x l2 let sublist_refl (l : list eff_label) : Lemma (sublist l l) [SMTPat (sublist l l)] = () let rec interp_sublist (l1 l2 : list eff_label) (l : eff_label) : Lemma (requires (sublist l1 l2)) (ensures (interp l1 l ==> interp l2 l)) [SMTPat (interp l1 l); SMTPat (sublist l1 l2)] = match l1 with | [] -> () | _::l1 -> interp_sublist l1 l2 l let rec sublist_at (l1 l2 : list eff_label) : Lemma (sublist l1 (l1@l2) /\ sublist l2 (l1@l2)) [SMTPatOr [[SMTPat (sublist l1 (l1@l2))]; [SMTPat (sublist l2 (l1@l2))]]] = match l1 with | [] -> () | _::l1 -> sublist_at l1 l2 let ann_le (ann1 ann2 : annot) : prop = forall x. ann1 x ==> ann2 x let return (a:Type) (x:a) : repr a [] = fun () -> x let bind (a b : Type) (labs1 labs2 : list eff_label) (c : repr a labs1) (f : (x:a -> repr b labs2)) : Tot (repr b (labs1@labs2)) = fun () -> f (c ()) () let subcomp (a:Type) (labs1 labs2 : list eff_label) (f : repr a labs1) : Pure (repr a labs2) (requires (sublist labs1 labs2)) (ensures (fun _ -> True)) = f let ite (p q r : Type0) = (p ==> q) /\ (~p ==> r) let if_then_else (a : Type) (labs1 labs2 : list eff_label) (f : repr a labs1) (g : repr a labs2) (p : bool) : Type = repr a (labs1@labs2) total reifiable reflectable effect { EFF (a:Type) (_:list eff_label) with {repr; return; bind; subcomp; if_then_else} } let lift_pure_eff (a:Type) (wp : pure_wp a) (f : unit -> PURE a wp) : Pure (repr a []) (requires (wp (fun _ -> True))) (ensures (fun _ -> True)) = FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp; fun () -> f () sub_effect PURE ~> EFF = lift_pure_eff let get () : EFF H.heap [] = EFF?.reflect (fun () -> get ()) let (!) #a (r:ref a) : EFF a [] = EFF?.reflect (fun () -> !r) let (:=) #a (r:ref a) (v:a) : EFF unit [WR] = EFF?.reflect (fun () -> r := v) (* GM: The refinement is clearly crap, just trying to get a typeable put-like thing here. *) let put (s:state{forall s1. heap_rel s1 s}) : EFF unit [WR] = EFF?.reflect (fun () -> gst_put s) let raise #a (e:exn) : EFF a [EXN] = EFF?.reflect (fun () -> raise e) let test0 (r:ref int) (x y : int) : EFF int [EXN] = let z = !r in if x + z > 0 then raise (Failure "nope") else y - z
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Heap.fst.checked", "FStar.Classical.fsti.checked", "FStar.All.fst.checked" ], "interface_file": false, "source_file": "LatticeEff.fst" }
[ { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
r: FStar.ST.ref Prims.int -> x: Prims.int -> y: Prims.int -> LatticeEff.EFF Prims.int
LatticeEff.EFF
[]
[]
[ "FStar.ST.ref", "Prims.int", "Prims.op_GreaterThan", "Prims.op_Addition", "LatticeEff.raise", "FStar.All.Failure", "Prims.bool", "Prims.op_Subtraction", "Prims.unit", "LatticeEff.op_Colon_Equals", "LatticeEff.op_Bang", "Prims.Cons", "LatticeEff.eff_label", "LatticeEff.EXN", "LatticeEff.WR", "Prims.Nil" ]
[]
false
true
false
false
false
let test1 (r: ref int) (x y: int) : EFF int [EXN; WR] =
let z = !r in if x + z > 0 then raise (Failure "nope") else (r := 42; y - z)
false
LatticeEff.fst
LatticeEff.catch
val catch (#a #labs: _) (f: (unit -> EFF a (EXN :: labs))) (g: (unit -> EFF a labs)) : EFF a labs
val catch (#a #labs: _) (f: (unit -> EFF a (EXN :: labs))) (g: (unit -> EFF a labs)) : EFF a labs
let catch #a #labs (f : unit -> EFF a (EXN::labs)) (g : unit -> EFF a labs) : EFF a labs = EFF?.reflect begin fun () -> try_with (reify (f ())) (reify (g ())) end
{ "file_name": "examples/layeredeffects/LatticeEff.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 5, "end_line": 197, "start_col": 0, "start_line": 194 }
module LatticeEff open FStar.Tactics.V2 open FStar.List.Tot open FStar.All module H = FStar.Heap // GM: Force a type equality by SMT let coerce #a #b (x:a{a == b}) : b = x let unreachable #a () : Pure a (requires False) (ensures (fun _ -> False)) = coerce "whatever" type eff_label = // GM: Can we do this one? ALL's WPs are unary and this is a // relational property. // | RD | WR //| DIV | EXN type annot = eff_label -> bool let interp (l : list eff_label) : annot = fun lab -> mem lab l type state = H.heap type wp a = all_wp_h H.heap a // boring, exponential //let wpof1 #a (l : list eff_label) : all_wp_h H.heap a = // let i = interp l in // match i ST, i EXN with // | false, false -> // fun p s0 -> forall x. p (V x) s0 // | true , false -> // fun p s0 -> forall x s1. p (V x) s1 // | false, true -> // fun p s0 -> forall r. p r s0 // | true, true -> // fun p s0 -> forall r s1. p r s1 (* more generic *) let wpof2 #a (l : list eff_label) : wp a = let i = interp l in let wp : wp a = fun p s0 -> (forall r s1. (i WR == false ==> s1 == s0) ==> (i EXN == false ==> V? r) ==> p r s1) in wp type repr (a:Type u#aa) (labs : list u#0 eff_label) // #2074 : Type u#0 = unit -> ALL a (wpof2 labs) let rec interp_at (l1 l2 : list eff_label) (l : eff_label) : Lemma (interp (l1@l2) l == (interp l1 l || interp l2 l)) [SMTPat (interp (l1@l2) l)] = match l1 with | [] -> () | _::l1 -> interp_at l1 l2 l let sublist (l1 l2 : list eff_label) = forall x. mem x l1 ==> mem x l2 let sublist_refl (l : list eff_label) : Lemma (sublist l l) [SMTPat (sublist l l)] = () let rec interp_sublist (l1 l2 : list eff_label) (l : eff_label) : Lemma (requires (sublist l1 l2)) (ensures (interp l1 l ==> interp l2 l)) [SMTPat (interp l1 l); SMTPat (sublist l1 l2)] = match l1 with | [] -> () | _::l1 -> interp_sublist l1 l2 l let rec sublist_at (l1 l2 : list eff_label) : Lemma (sublist l1 (l1@l2) /\ sublist l2 (l1@l2)) [SMTPatOr [[SMTPat (sublist l1 (l1@l2))]; [SMTPat (sublist l2 (l1@l2))]]] = match l1 with | [] -> () | _::l1 -> sublist_at l1 l2 let ann_le (ann1 ann2 : annot) : prop = forall x. ann1 x ==> ann2 x let return (a:Type) (x:a) : repr a [] = fun () -> x let bind (a b : Type) (labs1 labs2 : list eff_label) (c : repr a labs1) (f : (x:a -> repr b labs2)) : Tot (repr b (labs1@labs2)) = fun () -> f (c ()) () let subcomp (a:Type) (labs1 labs2 : list eff_label) (f : repr a labs1) : Pure (repr a labs2) (requires (sublist labs1 labs2)) (ensures (fun _ -> True)) = f let ite (p q r : Type0) = (p ==> q) /\ (~p ==> r) let if_then_else (a : Type) (labs1 labs2 : list eff_label) (f : repr a labs1) (g : repr a labs2) (p : bool) : Type = repr a (labs1@labs2) total reifiable reflectable effect { EFF (a:Type) (_:list eff_label) with {repr; return; bind; subcomp; if_then_else} } let lift_pure_eff (a:Type) (wp : pure_wp a) (f : unit -> PURE a wp) : Pure (repr a []) (requires (wp (fun _ -> True))) (ensures (fun _ -> True)) = FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp; fun () -> f () sub_effect PURE ~> EFF = lift_pure_eff let get () : EFF H.heap [] = EFF?.reflect (fun () -> get ()) let (!) #a (r:ref a) : EFF a [] = EFF?.reflect (fun () -> !r) let (:=) #a (r:ref a) (v:a) : EFF unit [WR] = EFF?.reflect (fun () -> r := v) (* GM: The refinement is clearly crap, just trying to get a typeable put-like thing here. *) let put (s:state{forall s1. heap_rel s1 s}) : EFF unit [WR] = EFF?.reflect (fun () -> gst_put s) let raise #a (e:exn) : EFF a [EXN] = EFF?.reflect (fun () -> raise e) let test0 (r:ref int) (x y : int) : EFF int [EXN] = let z = !r in if x + z > 0 then raise (Failure "nope") else y - z let test1 (r:ref int) (x y : int) : EFF int [EXN; WR] = let z = !r in if x + z > 0 then raise (Failure "nope") else (r := 42; y - z) let sublist_at_self (l1 : list eff_label) : Lemma (sublist (l1@l1) l1) [SMTPat (l1@l1)] = Classical.forall_intro (List.Tot.Properties.append_mem l1 l1) let labpoly #labs (f g : unit -> EFF int labs) : EFF int labs = f () + g () assume val try_with (#a:_) (#wpf:_) (#wpg:_) ($f : unit -> ALL a wpf) ($g : unit -> ALL a wpg) : ALL a (fun p s0 -> wpf (fun r s1 -> match r with | V _ -> p r s1 | _ -> wpg p s1) s0) (* no rollback *) (* GM: NB: this looks incredibly simple, but took like an hour to get right
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Heap.fst.checked", "FStar.Classical.fsti.checked", "FStar.All.fst.checked" ], "interface_file": false, "source_file": "LatticeEff.fst" }
[ { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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: (_: Prims.unit -> LatticeEff.EFF a) -> g: (_: Prims.unit -> LatticeEff.EFF a) -> LatticeEff.EFF a
LatticeEff.EFF
[]
[]
[ "Prims.list", "LatticeEff.eff_label", "Prims.unit", "Prims.Cons", "LatticeEff.EXN", "LatticeEff.try_with", "LatticeEff.wpof2" ]
[]
false
true
false
false
false
let catch #a #labs (f: (unit -> EFF a (EXN :: labs))) (g: (unit -> EFF a labs)) : EFF a labs =
EFF?.reflect (fun () -> try_with (reify (f ())) (reify (g ())))
false
LatticeEff.fst
LatticeEff.raise
val raise (#a: _) (e: exn) : EFF a [EXN]
val raise (#a: _) (e: exn) : EFF a [EXN]
let raise #a (e:exn) : EFF a [EXN] = EFF?.reflect (fun () -> raise e)
{ "file_name": "examples/layeredeffects/LatticeEff.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 34, "end_line": 160, "start_col": 0, "start_line": 159 }
module LatticeEff open FStar.Tactics.V2 open FStar.List.Tot open FStar.All module H = FStar.Heap // GM: Force a type equality by SMT let coerce #a #b (x:a{a == b}) : b = x let unreachable #a () : Pure a (requires False) (ensures (fun _ -> False)) = coerce "whatever" type eff_label = // GM: Can we do this one? ALL's WPs are unary and this is a // relational property. // | RD | WR //| DIV | EXN type annot = eff_label -> bool let interp (l : list eff_label) : annot = fun lab -> mem lab l type state = H.heap type wp a = all_wp_h H.heap a // boring, exponential //let wpof1 #a (l : list eff_label) : all_wp_h H.heap a = // let i = interp l in // match i ST, i EXN with // | false, false -> // fun p s0 -> forall x. p (V x) s0 // | true , false -> // fun p s0 -> forall x s1. p (V x) s1 // | false, true -> // fun p s0 -> forall r. p r s0 // | true, true -> // fun p s0 -> forall r s1. p r s1 (* more generic *) let wpof2 #a (l : list eff_label) : wp a = let i = interp l in let wp : wp a = fun p s0 -> (forall r s1. (i WR == false ==> s1 == s0) ==> (i EXN == false ==> V? r) ==> p r s1) in wp type repr (a:Type u#aa) (labs : list u#0 eff_label) // #2074 : Type u#0 = unit -> ALL a (wpof2 labs) let rec interp_at (l1 l2 : list eff_label) (l : eff_label) : Lemma (interp (l1@l2) l == (interp l1 l || interp l2 l)) [SMTPat (interp (l1@l2) l)] = match l1 with | [] -> () | _::l1 -> interp_at l1 l2 l let sublist (l1 l2 : list eff_label) = forall x. mem x l1 ==> mem x l2 let sublist_refl (l : list eff_label) : Lemma (sublist l l) [SMTPat (sublist l l)] = () let rec interp_sublist (l1 l2 : list eff_label) (l : eff_label) : Lemma (requires (sublist l1 l2)) (ensures (interp l1 l ==> interp l2 l)) [SMTPat (interp l1 l); SMTPat (sublist l1 l2)] = match l1 with | [] -> () | _::l1 -> interp_sublist l1 l2 l let rec sublist_at (l1 l2 : list eff_label) : Lemma (sublist l1 (l1@l2) /\ sublist l2 (l1@l2)) [SMTPatOr [[SMTPat (sublist l1 (l1@l2))]; [SMTPat (sublist l2 (l1@l2))]]] = match l1 with | [] -> () | _::l1 -> sublist_at l1 l2 let ann_le (ann1 ann2 : annot) : prop = forall x. ann1 x ==> ann2 x let return (a:Type) (x:a) : repr a [] = fun () -> x let bind (a b : Type) (labs1 labs2 : list eff_label) (c : repr a labs1) (f : (x:a -> repr b labs2)) : Tot (repr b (labs1@labs2)) = fun () -> f (c ()) () let subcomp (a:Type) (labs1 labs2 : list eff_label) (f : repr a labs1) : Pure (repr a labs2) (requires (sublist labs1 labs2)) (ensures (fun _ -> True)) = f let ite (p q r : Type0) = (p ==> q) /\ (~p ==> r) let if_then_else (a : Type) (labs1 labs2 : list eff_label) (f : repr a labs1) (g : repr a labs2) (p : bool) : Type = repr a (labs1@labs2) total reifiable reflectable effect { EFF (a:Type) (_:list eff_label) with {repr; return; bind; subcomp; if_then_else} } let lift_pure_eff (a:Type) (wp : pure_wp a) (f : unit -> PURE a wp) : Pure (repr a []) (requires (wp (fun _ -> True))) (ensures (fun _ -> True)) = FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp; fun () -> f () sub_effect PURE ~> EFF = lift_pure_eff let get () : EFF H.heap [] = EFF?.reflect (fun () -> get ()) let (!) #a (r:ref a) : EFF a [] = EFF?.reflect (fun () -> !r) let (:=) #a (r:ref a) (v:a) : EFF unit [WR] = EFF?.reflect (fun () -> r := v) (* GM: The refinement is clearly crap, just trying to get a typeable put-like thing here. *) let put (s:state{forall s1. heap_rel s1 s}) : EFF unit [WR] = EFF?.reflect (fun () -> gst_put s)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Heap.fst.checked", "FStar.Classical.fsti.checked", "FStar.All.fst.checked" ], "interface_file": false, "source_file": "LatticeEff.fst" }
[ { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
e: Prims.exn -> LatticeEff.EFF a
LatticeEff.EFF
[]
[]
[ "Prims.exn", "Prims.unit", "FStar.Exn.raise", "Prims.Cons", "LatticeEff.eff_label", "LatticeEff.EXN", "Prims.Nil" ]
[]
false
true
false
false
false
let raise #a (e: exn) : EFF a [EXN] =
EFF?.reflect (fun () -> raise e)
false
Hacl.Spec.Bignum.Multiplication.fst
Hacl.Spec.Bignum.Multiplication.bn_mul1_add_in_place_lemma_loop_step
val bn_mul1_add_in_place_lemma_loop_step: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> l:limb t -> acc:lbignum t aLen -> i:pos{i <= aLen} -> c1_res1:generate_elem_a (limb t) (limb t) aLen (i - 1) -> Lemma (requires (let (c1, res1) = c1_res1 in v c1 * pow2 (bits t * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen acc (i - 1) + eval_ aLen a (i - 1) * v l)) (ensures (let (c1, res1) = c1_res1 in let (c, res) = generate_elem_f aLen (bn_mul1_add_in_place_f a l acc) (i - 1) (c1, res1) in v c * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen acc i + eval_ aLen a i * v l))
val bn_mul1_add_in_place_lemma_loop_step: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> l:limb t -> acc:lbignum t aLen -> i:pos{i <= aLen} -> c1_res1:generate_elem_a (limb t) (limb t) aLen (i - 1) -> Lemma (requires (let (c1, res1) = c1_res1 in v c1 * pow2 (bits t * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen acc (i - 1) + eval_ aLen a (i - 1) * v l)) (ensures (let (c1, res1) = c1_res1 in let (c, res) = generate_elem_f aLen (bn_mul1_add_in_place_f a l acc) (i - 1) (c1, res1) in v c * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen acc i + eval_ aLen a i * v l))
let bn_mul1_add_in_place_lemma_loop_step #t #aLen a l acc i (c1, res1) = let pbits = bits t in let b1 = pow2 (pbits * (i - 1)) in let b2 = pow2 (pbits * i) in let (c, res) = generate_elem_f aLen (bn_mul1_add_in_place_f a l acc) (i - 1) (c1, res1) in let c, e = mul_wide_add2 a.[i - 1] l c1 acc.[i - 1] in assert (v e + v c * pow2 pbits == v a.[i - 1] * v l + v c1 + v acc.[i - 1]); calc (==) { v c * b2 + bn_v #t #i res; (==) { bn_eval_snoc #t #(i - 1) res1 e } v c * b2 + bn_v #t #(i - 1) res1 + v e * b1; (==) { } v c * b2 + eval_ aLen acc (i - 1) + eval_ aLen a (i - 1) * v l - (v e + v c * pow2 pbits - v a.[i - 1] * v l - v acc.[i - 1]) * b1 + v e * b1; (==) { Math.Lemmas.distributivity_add_left (v e) (v c * pow2 pbits - v a.[i - 1] * v l - v acc.[i - 1]) b1 } v c * b2 + eval_ aLen acc (i - 1) + eval_ aLen a (i - 1) * v l - (v c * pow2 pbits - v a.[i - 1] * v l - v acc.[i - 1]) * b1; (==) { Math.Lemmas.distributivity_sub_left (v c * pow2 pbits) (v a.[i - 1] * v l + v acc.[i - 1]) b1 } v c * b2 + eval_ aLen acc (i - 1) + eval_ aLen a (i - 1) * v l - (v c * pow2 pbits) * b1 + (v a.[i - 1] * v l + v acc.[i - 1]) * b1; (==) { Math.Lemmas.paren_mul_right (v c) (pow2 pbits) b1; Math.Lemmas.pow2_plus pbits (pbits * (i - 1)) } eval_ aLen acc (i - 1) + eval_ aLen a (i - 1) * v l + (v a.[i - 1] * v l + v acc.[i - 1]) * b1; (==) { Math.Lemmas.distributivity_add_left (v a.[i - 1] * v l) (v acc.[i - 1]) b1 } eval_ aLen acc (i - 1) + eval_ aLen a (i - 1) * v l + v a.[i - 1] * v l * b1 + v acc.[i - 1] * b1; (==) { bn_eval_unfold_i acc i } eval_ aLen acc i + eval_ aLen a (i - 1) * v l + v a.[i - 1] * v l * b1; (==) { Math.Lemmas.paren_mul_right (v a.[i - 1]) (v l) b1 } eval_ aLen acc i + eval_ aLen a (i - 1) * v l + v a.[i - 1] * (b1 * v l); (==) { Math.Lemmas.paren_mul_right (v a.[i - 1]) b1 (v l) } eval_ aLen acc i + eval_ aLen a (i - 1) * v l + v a.[i - 1] * b1 * v l; (==) { Math.Lemmas.distributivity_add_left (eval_ aLen a (i - 1)) (v a.[i - 1] * b1) (v l) } eval_ aLen acc i + (eval_ aLen a (i - 1) + v a.[i - 1] * b1) * v l; (==) { bn_eval_unfold_i a i } eval_ aLen acc i + eval_ aLen a i * v l; }; assert (v c * b2 + bn_v #t #i res == eval_ aLen acc i + eval_ aLen a i * v l)
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Multiplication.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 79, "end_line": 258, "start_col": 0, "start_line": 222 }
module Hacl.Spec.Bignum.Multiplication open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.LoopCombinators open Hacl.Spec.Bignum.Definitions open Hacl.Spec.Bignum.Base open Hacl.Spec.Lib #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" val bn_mul1_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> l:limb t -> i:size_nat{i < aLen} -> c:limb t -> limb t & limb t // carry & out let bn_mul1_f #t #aLen a l i c = mul_wide_add a.[i] l c val bn_mul1: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> l:limb t -> limb t & lbignum t aLen let bn_mul1 #t #aLen a l = generate_elems aLen aLen (bn_mul1_f a l) (uint #t 0) val bn_mul1_add_in_place_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> l:limb t -> acc:lbignum t aLen -> i:size_nat{i < aLen} -> c:limb t -> limb t & limb t // carry & out let bn_mul1_add_in_place_f #t #aLen a l acc i c = mul_wide_add2 a.[i] l c acc.[i] val bn_mul1_add_in_place: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> l:limb t -> acc:lbignum t aLen -> limb t & lbignum t aLen let bn_mul1_add_in_place #t #aLen a l acc = generate_elems aLen aLen (bn_mul1_add_in_place_f a l acc) (uint #t 0) val bn_mul1_lshift_add: #t:limb_t -> #aLen:size_nat -> #resLen:size_nat -> a:lbignum t aLen -> b_j:limb t -> j:size_nat{j + aLen <= resLen} -> res:lbignum t resLen -> limb t & lbignum t resLen let bn_mul1_lshift_add #t #aLen #resLen a b_j j res = let res' = sub res j aLen in let c, res' = bn_mul1_add_in_place a b_j res' in let res = update_sub res j aLen res' in c, res val bn_mul_: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat{aLen + bLen <= max_size_t} -> a:lbignum t aLen -> b:lbignum t bLen -> j:size_nat{j < bLen} -> res:lbignum t (aLen + bLen) -> lbignum t (aLen + bLen) let bn_mul_ #t #aLen #bLen a b j res = let c, res = bn_mul1_lshift_add a b.[j] j res in res.[aLen + j] <- c val bn_mul: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat{aLen + bLen <= max_size_t} -> a:lbignum t aLen -> b:lbignum t bLen -> lbignum t (aLen + bLen) let bn_mul #t #aLen #bLen a b = let res = create (aLen + bLen) (uint #t 0) in repeati bLen (bn_mul_ a b) res val bn_mul1_lemma_loop_step: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> l:limb t -> i:pos{i <= aLen} -> c1_res1:generate_elem_a (limb t) (limb t) aLen (i - 1) -> Lemma (requires (let (c1, res1) = c1_res1 in v c1 * pow2 (bits t * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen a (i - 1) * v l)) (ensures (let (c1, res1) = c1_res1 in let (c, res) = generate_elem_f aLen (bn_mul1_f a l) (i - 1) (c1, res1) in v c * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen a i * v l)) let bn_mul1_lemma_loop_step #t #aLen a l i (c1, res1) = let pbits = bits t in let b1 = pow2 (pbits * (i - 1)) in let b2 = pow2 (pbits * i) in let (c, res) = generate_elem_f aLen (bn_mul1_f a l) (i - 1) (c1, res1) in let c, e = mul_wide_add a.[i - 1] l c1 in assert (v e + v c * pow2 pbits == v a.[i - 1] * v l + v c1); calc (==) { v c * b2 + bn_v #t #i res; (==) { bn_eval_snoc #t #(i - 1) res1 e } v c * b2 + bn_v #t #(i - 1) res1 + v e * b1; (==) { } v c * b2 + eval_ aLen a (i - 1) * v l -(v e + v c * pow2 pbits - v a.[i - 1] * v l) * b1 + v e * b1; (==) { Math.Lemmas.distributivity_add_left (v e) (v c * pow2 pbits - v a.[i - 1] * v l) b1 } v c * b2 + eval_ aLen a (i - 1) * v l - (v c * pow2 pbits - v a.[i - 1] * v l) * b1; (==) { Math.Lemmas.distributivity_sub_left (v c * pow2 pbits) (v a.[i - 1] * v l) b1 } v c * b2 + eval_ aLen a (i - 1) * v l - v c * pow2 pbits * b1 + v a.[i - 1] * v l * b1; (==) { Math.Lemmas.paren_mul_right (v c) (pow2 pbits) b1; Math.Lemmas.pow2_plus pbits (pbits * (i - 1)) } eval_ aLen a (i - 1) * v l + v a.[i - 1] * v l * b1; (==) { Math.Lemmas.paren_mul_right (v a.[i - 1]) (v l) b1 } eval_ aLen a (i - 1) * v l + v a.[i - 1] * (b1 * v l); (==) { Math.Lemmas.paren_mul_right (v a.[i - 1]) b1 (v l) } eval_ aLen a (i - 1) * v l + v a.[i - 1] * b1 * v l; (==) { Math.Lemmas.distributivity_add_left (eval_ aLen a (i - 1)) (v a.[i - 1] * b1) (v l) } (eval_ aLen a (i - 1) + v a.[i - 1] * b1) * v l; (==) { bn_eval_unfold_i a i } eval_ aLen a i * v l; }; assert (v c * b2 + bn_v #t #i res == eval_ aLen a i * v l) val bn_mul1_lemma_loop: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> l:limb t -> i:nat{i <= aLen} -> Lemma (let (c, res) : generate_elem_a (limb t) (limb t) aLen i = generate_elems aLen i (bn_mul1_f a l) (uint #t 0) in v c * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen a i * v l) let rec bn_mul1_lemma_loop #t #aLen a l i = let pbits = bits t in let (c, res) : generate_elem_a (limb t) (limb t) aLen i = generate_elems aLen i (bn_mul1_f a l) (uint #t 0) in if i = 0 then begin eq_generate_elems0 aLen i (bn_mul1_f a l) (uint #t 0); assert (c == uint #t 0 /\ res == Seq.empty); bn_eval0 #t #0 res; assert_norm (pow2 0 = 1); bn_eval0 a; () end else begin let (c1, res1) : generate_elem_a (limb t) (limb t) aLen (i - 1) = generate_elems aLen (i - 1) (bn_mul1_f a l) (uint #t 0) in generate_elems_unfold aLen i (bn_mul1_f a l) (uint #t 0) (i - 1); assert (generate_elems aLen i (bn_mul1_f a l) (uint #t 0) == generate_elem_f aLen (bn_mul1_f a l) (i - 1) (generate_elems aLen (i - 1) (bn_mul1_f a l) (uint #t 0))); assert ((c, res) == generate_elem_f aLen (bn_mul1_f a l) (i - 1) (c1, res1)); bn_mul1_lemma_loop a l (i - 1); assert (v c1 * pow2 (pbits * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen a (i - 1) * v l); bn_mul1_lemma_loop_step a l i (c1, res1); assert (v c * pow2 (pbits * i) + bn_v #t #i res == eval_ aLen a i * v l); () end val bn_mul1_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> l:limb t -> Lemma (let (c, res) = bn_mul1 a l in v c * pow2 (bits t * aLen) + bn_v res == bn_v a * v l) let bn_mul1_lemma #t #aLen a l = let (c, res) = bn_mul1 a l in bn_mul1_lemma_loop a l aLen #push-options "--z3rlimit 150" val bn_mul1_add_in_place_lemma_loop_step: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> l:limb t -> acc:lbignum t aLen -> i:pos{i <= aLen} -> c1_res1:generate_elem_a (limb t) (limb t) aLen (i - 1) -> Lemma (requires (let (c1, res1) = c1_res1 in v c1 * pow2 (bits t * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen acc (i - 1) + eval_ aLen a (i - 1) * v l)) (ensures (let (c1, res1) = c1_res1 in let (c, res) = generate_elem_f aLen (bn_mul1_add_in_place_f a l acc) (i - 1) (c1, res1) in v c * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen acc i + eval_ aLen a i * v l))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Lib.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Bignum.Multiplication.fst" }
[ { "abbrev": false, "full_module": "Hacl.Spec.Lib", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Base", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 150, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> l: Hacl.Spec.Bignum.Definitions.limb t -> acc: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> i: Prims.pos{i <= aLen} -> c1_res1: Hacl.Spec.Lib.generate_elem_a (Hacl.Spec.Bignum.Definitions.limb t) (Hacl.Spec.Bignum.Definitions.limb t) aLen (i - 1) -> FStar.Pervasives.Lemma (requires (let _ = c1_res1 in (let FStar.Pervasives.Native.Mktuple2 #_ #_ c1 res1 = _ in Lib.IntTypes.v c1 * Prims.pow2 (Lib.IntTypes.bits t * (i - 1)) + Hacl.Spec.Bignum.Definitions.bn_v res1 == Hacl.Spec.Bignum.Definitions.eval_ aLen acc (i - 1) + Hacl.Spec.Bignum.Definitions.eval_ aLen a (i - 1) * Lib.IntTypes.v l) <: Type0)) (ensures (let _ = c1_res1 in (let FStar.Pervasives.Native.Mktuple2 #_ #_ c1 res1 = _ in let _ = Hacl.Spec.Lib.generate_elem_f aLen (Hacl.Spec.Bignum.Multiplication.bn_mul1_add_in_place_f a l acc) (i - 1) (c1, res1) in (let FStar.Pervasives.Native.Mktuple2 #_ #_ c res = _ in Lib.IntTypes.v c * Prims.pow2 (Lib.IntTypes.bits t * i) + Hacl.Spec.Bignum.Definitions.bn_v res == Hacl.Spec.Bignum.Definitions.eval_ aLen acc i + Hacl.Spec.Bignum.Definitions.eval_ aLen a i * Lib.IntTypes.v l) <: Type0) <: Type0))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Lib.IntTypes.size_nat", "Hacl.Spec.Bignum.Definitions.lbignum", "Hacl.Spec.Bignum.Definitions.limb", "Prims.pos", "Prims.b2t", "Prims.op_LessThanOrEqual", "Hacl.Spec.Lib.generate_elem_a", "Prims.op_Subtraction", "Lib.Sequence.seq", "Prims.eq2", "Prims.nat", "Lib.Sequence.length", "Prims.op_Addition", "Prims._assert", "Prims.int", "FStar.Mul.op_Star", "Lib.IntTypes.v", "Lib.IntTypes.SEC", "Hacl.Spec.Bignum.Definitions.bn_v", "Hacl.Spec.Bignum.Definitions.eval_", "Prims.unit", "FStar.Calc.calc_finish", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "FStar.Calc.calc_step", "Lib.Sequence.op_String_Access", "Prims.pow2", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "Hacl.Spec.Bignum.Definitions.bn_eval_snoc", "Prims.squash", "FStar.Math.Lemmas.distributivity_add_left", "FStar.Math.Lemmas.distributivity_sub_left", "FStar.Math.Lemmas.pow2_plus", "FStar.Math.Lemmas.paren_mul_right", "Hacl.Spec.Bignum.Definitions.bn_eval_unfold_i", "FStar.Pervasives.Native.tuple2", "Hacl.Spec.Bignum.Base.mul_wide_add2", "Hacl.Spec.Lib.generate_elem_f", "Hacl.Spec.Bignum.Multiplication.bn_mul1_add_in_place_f", "FStar.Pervasives.Native.Mktuple2", "Lib.IntTypes.bits" ]
[]
false
false
true
false
false
let bn_mul1_add_in_place_lemma_loop_step #t #aLen a l acc i (c1, res1) =
let pbits = bits t in let b1 = pow2 (pbits * (i - 1)) in let b2 = pow2 (pbits * i) in let c, res = generate_elem_f aLen (bn_mul1_add_in_place_f a l acc) (i - 1) (c1, res1) in let c, e = mul_wide_add2 a.[ i - 1 ] l c1 acc.[ i - 1 ] in assert (v e + v c * pow2 pbits == v a.[ i - 1 ] * v l + v c1 + v acc.[ i - 1 ]); calc ( == ) { v c * b2 + bn_v #t #i res; ( == ) { bn_eval_snoc #t #(i - 1) res1 e } v c * b2 + bn_v #t #(i - 1) res1 + v e * b1; ( == ) { () } v c * b2 + eval_ aLen acc (i - 1) + eval_ aLen a (i - 1) * v l - (v e + v c * pow2 pbits - v a.[ i - 1 ] * v l - v acc.[ i - 1 ]) * b1 + v e * b1; ( == ) { Math.Lemmas.distributivity_add_left (v e) (v c * pow2 pbits - v a.[ i - 1 ] * v l - v acc.[ i - 1 ]) b1 } v c * b2 + eval_ aLen acc (i - 1) + eval_ aLen a (i - 1) * v l - (v c * pow2 pbits - v a.[ i - 1 ] * v l - v acc.[ i - 1 ]) * b1; ( == ) { Math.Lemmas.distributivity_sub_left (v c * pow2 pbits) (v a.[ i - 1 ] * v l + v acc.[ i - 1 ]) b1 } v c * b2 + eval_ aLen acc (i - 1) + eval_ aLen a (i - 1) * v l - (v c * pow2 pbits) * b1 + (v a.[ i - 1 ] * v l + v acc.[ i - 1 ]) * b1; ( == ) { (Math.Lemmas.paren_mul_right (v c) (pow2 pbits) b1; Math.Lemmas.pow2_plus pbits (pbits * (i - 1))) } eval_ aLen acc (i - 1) + eval_ aLen a (i - 1) * v l + (v a.[ i - 1 ] * v l + v acc.[ i - 1 ]) * b1; ( == ) { Math.Lemmas.distributivity_add_left (v a.[ i - 1 ] * v l) (v acc.[ i - 1 ]) b1 } eval_ aLen acc (i - 1) + eval_ aLen a (i - 1) * v l + (v a.[ i - 1 ] * v l) * b1 + v acc.[ i - 1 ] * b1; ( == ) { bn_eval_unfold_i acc i } eval_ aLen acc i + eval_ aLen a (i - 1) * v l + (v a.[ i - 1 ] * v l) * b1; ( == ) { Math.Lemmas.paren_mul_right (v a.[ i - 1 ]) (v l) b1 } eval_ aLen acc i + eval_ aLen a (i - 1) * v l + v a.[ i - 1 ] * (b1 * v l); ( == ) { Math.Lemmas.paren_mul_right (v a.[ i - 1 ]) b1 (v l) } eval_ aLen acc i + eval_ aLen a (i - 1) * v l + (v a.[ i - 1 ] * b1) * v l; ( == ) { Math.Lemmas.distributivity_add_left (eval_ aLen a (i - 1)) (v a.[ i - 1 ] * b1) (v l) } eval_ aLen acc i + (eval_ aLen a (i - 1) + v a.[ i - 1 ] * b1) * v l; ( == ) { bn_eval_unfold_i a i } eval_ aLen acc i + eval_ aLen a i * v l; }; assert (v c * b2 + bn_v #t #i res == eval_ aLen acc i + eval_ aLen a i * v l)
false
LatticeEff.fst
LatticeEff.test_catch
val test_catch (f: (unit -> EFF int [EXN; WR])) : EFF int [WR]
val test_catch (f: (unit -> EFF int [EXN; WR])) : EFF int [WR]
let test_catch (f : unit -> EFF int [EXN;WR]) : EFF int [WR] = catch f g
{ "file_name": "examples/layeredeffects/LatticeEff.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 11, "end_line": 202, "start_col": 0, "start_line": 201 }
module LatticeEff open FStar.Tactics.V2 open FStar.List.Tot open FStar.All module H = FStar.Heap // GM: Force a type equality by SMT let coerce #a #b (x:a{a == b}) : b = x let unreachable #a () : Pure a (requires False) (ensures (fun _ -> False)) = coerce "whatever" type eff_label = // GM: Can we do this one? ALL's WPs are unary and this is a // relational property. // | RD | WR //| DIV | EXN type annot = eff_label -> bool let interp (l : list eff_label) : annot = fun lab -> mem lab l type state = H.heap type wp a = all_wp_h H.heap a // boring, exponential //let wpof1 #a (l : list eff_label) : all_wp_h H.heap a = // let i = interp l in // match i ST, i EXN with // | false, false -> // fun p s0 -> forall x. p (V x) s0 // | true , false -> // fun p s0 -> forall x s1. p (V x) s1 // | false, true -> // fun p s0 -> forall r. p r s0 // | true, true -> // fun p s0 -> forall r s1. p r s1 (* more generic *) let wpof2 #a (l : list eff_label) : wp a = let i = interp l in let wp : wp a = fun p s0 -> (forall r s1. (i WR == false ==> s1 == s0) ==> (i EXN == false ==> V? r) ==> p r s1) in wp type repr (a:Type u#aa) (labs : list u#0 eff_label) // #2074 : Type u#0 = unit -> ALL a (wpof2 labs) let rec interp_at (l1 l2 : list eff_label) (l : eff_label) : Lemma (interp (l1@l2) l == (interp l1 l || interp l2 l)) [SMTPat (interp (l1@l2) l)] = match l1 with | [] -> () | _::l1 -> interp_at l1 l2 l let sublist (l1 l2 : list eff_label) = forall x. mem x l1 ==> mem x l2 let sublist_refl (l : list eff_label) : Lemma (sublist l l) [SMTPat (sublist l l)] = () let rec interp_sublist (l1 l2 : list eff_label) (l : eff_label) : Lemma (requires (sublist l1 l2)) (ensures (interp l1 l ==> interp l2 l)) [SMTPat (interp l1 l); SMTPat (sublist l1 l2)] = match l1 with | [] -> () | _::l1 -> interp_sublist l1 l2 l let rec sublist_at (l1 l2 : list eff_label) : Lemma (sublist l1 (l1@l2) /\ sublist l2 (l1@l2)) [SMTPatOr [[SMTPat (sublist l1 (l1@l2))]; [SMTPat (sublist l2 (l1@l2))]]] = match l1 with | [] -> () | _::l1 -> sublist_at l1 l2 let ann_le (ann1 ann2 : annot) : prop = forall x. ann1 x ==> ann2 x let return (a:Type) (x:a) : repr a [] = fun () -> x let bind (a b : Type) (labs1 labs2 : list eff_label) (c : repr a labs1) (f : (x:a -> repr b labs2)) : Tot (repr b (labs1@labs2)) = fun () -> f (c ()) () let subcomp (a:Type) (labs1 labs2 : list eff_label) (f : repr a labs1) : Pure (repr a labs2) (requires (sublist labs1 labs2)) (ensures (fun _ -> True)) = f let ite (p q r : Type0) = (p ==> q) /\ (~p ==> r) let if_then_else (a : Type) (labs1 labs2 : list eff_label) (f : repr a labs1) (g : repr a labs2) (p : bool) : Type = repr a (labs1@labs2) total reifiable reflectable effect { EFF (a:Type) (_:list eff_label) with {repr; return; bind; subcomp; if_then_else} } let lift_pure_eff (a:Type) (wp : pure_wp a) (f : unit -> PURE a wp) : Pure (repr a []) (requires (wp (fun _ -> True))) (ensures (fun _ -> True)) = FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp; fun () -> f () sub_effect PURE ~> EFF = lift_pure_eff let get () : EFF H.heap [] = EFF?.reflect (fun () -> get ()) let (!) #a (r:ref a) : EFF a [] = EFF?.reflect (fun () -> !r) let (:=) #a (r:ref a) (v:a) : EFF unit [WR] = EFF?.reflect (fun () -> r := v) (* GM: The refinement is clearly crap, just trying to get a typeable put-like thing here. *) let put (s:state{forall s1. heap_rel s1 s}) : EFF unit [WR] = EFF?.reflect (fun () -> gst_put s) let raise #a (e:exn) : EFF a [EXN] = EFF?.reflect (fun () -> raise e) let test0 (r:ref int) (x y : int) : EFF int [EXN] = let z = !r in if x + z > 0 then raise (Failure "nope") else y - z let test1 (r:ref int) (x y : int) : EFF int [EXN; WR] = let z = !r in if x + z > 0 then raise (Failure "nope") else (r := 42; y - z) let sublist_at_self (l1 : list eff_label) : Lemma (sublist (l1@l1) l1) [SMTPat (l1@l1)] = Classical.forall_intro (List.Tot.Properties.append_mem l1 l1) let labpoly #labs (f g : unit -> EFF int labs) : EFF int labs = f () + g () assume val try_with (#a:_) (#wpf:_) (#wpg:_) ($f : unit -> ALL a wpf) ($g : unit -> ALL a wpg) : ALL a (fun p s0 -> wpf (fun r s1 -> match r with | V _ -> p r s1 | _ -> wpg p s1) s0) (* no rollback *) (* GM: NB: this looks incredibly simple, but took like an hour to get right * when the WP of try_with wasn't exactly what was expected :-) *) let catch #a #labs (f : unit -> EFF a (EXN::labs)) (g : unit -> EFF a labs) : EFF a labs = EFF?.reflect begin fun () -> try_with (reify (f ())) (reify (g ())) end let g #labs () : EFF int labs = 42
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Heap.fst.checked", "FStar.Classical.fsti.checked", "FStar.All.fst.checked" ], "interface_file": false, "source_file": "LatticeEff.fst" }
[ { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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: (_: Prims.unit -> LatticeEff.EFF Prims.int) -> LatticeEff.EFF Prims.int
LatticeEff.EFF
[]
[]
[ "Prims.unit", "Prims.int", "Prims.Cons", "LatticeEff.eff_label", "LatticeEff.EXN", "LatticeEff.WR", "Prims.Nil", "LatticeEff.catch", "LatticeEff.g" ]
[]
false
true
false
false
false
let test_catch (f: (unit -> EFF int [EXN; WR])) : EFF int [WR] =
catch f g
false
LatticeEff.fst
LatticeEff.labpoly
val labpoly (#labs: _) (f g: (unit -> EFF int labs)) : EFF int labs
val labpoly (#labs: _) (f g: (unit -> EFF int labs)) : EFF int labs
let labpoly #labs (f g : unit -> EFF int labs) : EFF int labs = f () + g ()
{ "file_name": "examples/layeredeffects/LatticeEff.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 13, "end_line": 181, "start_col": 0, "start_line": 180 }
module LatticeEff open FStar.Tactics.V2 open FStar.List.Tot open FStar.All module H = FStar.Heap // GM: Force a type equality by SMT let coerce #a #b (x:a{a == b}) : b = x let unreachable #a () : Pure a (requires False) (ensures (fun _ -> False)) = coerce "whatever" type eff_label = // GM: Can we do this one? ALL's WPs are unary and this is a // relational property. // | RD | WR //| DIV | EXN type annot = eff_label -> bool let interp (l : list eff_label) : annot = fun lab -> mem lab l type state = H.heap type wp a = all_wp_h H.heap a // boring, exponential //let wpof1 #a (l : list eff_label) : all_wp_h H.heap a = // let i = interp l in // match i ST, i EXN with // | false, false -> // fun p s0 -> forall x. p (V x) s0 // | true , false -> // fun p s0 -> forall x s1. p (V x) s1 // | false, true -> // fun p s0 -> forall r. p r s0 // | true, true -> // fun p s0 -> forall r s1. p r s1 (* more generic *) let wpof2 #a (l : list eff_label) : wp a = let i = interp l in let wp : wp a = fun p s0 -> (forall r s1. (i WR == false ==> s1 == s0) ==> (i EXN == false ==> V? r) ==> p r s1) in wp type repr (a:Type u#aa) (labs : list u#0 eff_label) // #2074 : Type u#0 = unit -> ALL a (wpof2 labs) let rec interp_at (l1 l2 : list eff_label) (l : eff_label) : Lemma (interp (l1@l2) l == (interp l1 l || interp l2 l)) [SMTPat (interp (l1@l2) l)] = match l1 with | [] -> () | _::l1 -> interp_at l1 l2 l let sublist (l1 l2 : list eff_label) = forall x. mem x l1 ==> mem x l2 let sublist_refl (l : list eff_label) : Lemma (sublist l l) [SMTPat (sublist l l)] = () let rec interp_sublist (l1 l2 : list eff_label) (l : eff_label) : Lemma (requires (sublist l1 l2)) (ensures (interp l1 l ==> interp l2 l)) [SMTPat (interp l1 l); SMTPat (sublist l1 l2)] = match l1 with | [] -> () | _::l1 -> interp_sublist l1 l2 l let rec sublist_at (l1 l2 : list eff_label) : Lemma (sublist l1 (l1@l2) /\ sublist l2 (l1@l2)) [SMTPatOr [[SMTPat (sublist l1 (l1@l2))]; [SMTPat (sublist l2 (l1@l2))]]] = match l1 with | [] -> () | _::l1 -> sublist_at l1 l2 let ann_le (ann1 ann2 : annot) : prop = forall x. ann1 x ==> ann2 x let return (a:Type) (x:a) : repr a [] = fun () -> x let bind (a b : Type) (labs1 labs2 : list eff_label) (c : repr a labs1) (f : (x:a -> repr b labs2)) : Tot (repr b (labs1@labs2)) = fun () -> f (c ()) () let subcomp (a:Type) (labs1 labs2 : list eff_label) (f : repr a labs1) : Pure (repr a labs2) (requires (sublist labs1 labs2)) (ensures (fun _ -> True)) = f let ite (p q r : Type0) = (p ==> q) /\ (~p ==> r) let if_then_else (a : Type) (labs1 labs2 : list eff_label) (f : repr a labs1) (g : repr a labs2) (p : bool) : Type = repr a (labs1@labs2) total reifiable reflectable effect { EFF (a:Type) (_:list eff_label) with {repr; return; bind; subcomp; if_then_else} } let lift_pure_eff (a:Type) (wp : pure_wp a) (f : unit -> PURE a wp) : Pure (repr a []) (requires (wp (fun _ -> True))) (ensures (fun _ -> True)) = FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp; fun () -> f () sub_effect PURE ~> EFF = lift_pure_eff let get () : EFF H.heap [] = EFF?.reflect (fun () -> get ()) let (!) #a (r:ref a) : EFF a [] = EFF?.reflect (fun () -> !r) let (:=) #a (r:ref a) (v:a) : EFF unit [WR] = EFF?.reflect (fun () -> r := v) (* GM: The refinement is clearly crap, just trying to get a typeable put-like thing here. *) let put (s:state{forall s1. heap_rel s1 s}) : EFF unit [WR] = EFF?.reflect (fun () -> gst_put s) let raise #a (e:exn) : EFF a [EXN] = EFF?.reflect (fun () -> raise e) let test0 (r:ref int) (x y : int) : EFF int [EXN] = let z = !r in if x + z > 0 then raise (Failure "nope") else y - z let test1 (r:ref int) (x y : int) : EFF int [EXN; WR] = let z = !r in if x + z > 0 then raise (Failure "nope") else (r := 42; y - z) let sublist_at_self (l1 : list eff_label) : Lemma (sublist (l1@l1) l1) [SMTPat (l1@l1)] = Classical.forall_intro (List.Tot.Properties.append_mem l1 l1)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Heap.fst.checked", "FStar.Classical.fsti.checked", "FStar.All.fst.checked" ], "interface_file": false, "source_file": "LatticeEff.fst" }
[ { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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: (_: Prims.unit -> LatticeEff.EFF Prims.int) -> g: (_: Prims.unit -> LatticeEff.EFF Prims.int) -> LatticeEff.EFF Prims.int
LatticeEff.EFF
[]
[]
[ "Prims.list", "LatticeEff.eff_label", "Prims.unit", "Prims.int", "Prims.op_Addition" ]
[]
false
true
false
false
false
let labpoly #labs (f: (unit -> EFF int labs)) (g: (unit -> EFF int labs)) : EFF int labs =
f () + g ()
false
LatticeEff.fst
LatticeEff.sublist_at_self
val sublist_at_self (l1: list eff_label) : Lemma (sublist (l1 @ l1) l1) [SMTPat (l1 @ l1)]
val sublist_at_self (l1: list eff_label) : Lemma (sublist (l1 @ l1) l1) [SMTPat (l1 @ l1)]
let sublist_at_self (l1 : list eff_label) : Lemma (sublist (l1@l1) l1) [SMTPat (l1@l1)] = Classical.forall_intro (List.Tot.Properties.append_mem l1 l1)
{ "file_name": "examples/layeredeffects/LatticeEff.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 65, "end_line": 178, "start_col": 0, "start_line": 175 }
module LatticeEff open FStar.Tactics.V2 open FStar.List.Tot open FStar.All module H = FStar.Heap // GM: Force a type equality by SMT let coerce #a #b (x:a{a == b}) : b = x let unreachable #a () : Pure a (requires False) (ensures (fun _ -> False)) = coerce "whatever" type eff_label = // GM: Can we do this one? ALL's WPs are unary and this is a // relational property. // | RD | WR //| DIV | EXN type annot = eff_label -> bool let interp (l : list eff_label) : annot = fun lab -> mem lab l type state = H.heap type wp a = all_wp_h H.heap a // boring, exponential //let wpof1 #a (l : list eff_label) : all_wp_h H.heap a = // let i = interp l in // match i ST, i EXN with // | false, false -> // fun p s0 -> forall x. p (V x) s0 // | true , false -> // fun p s0 -> forall x s1. p (V x) s1 // | false, true -> // fun p s0 -> forall r. p r s0 // | true, true -> // fun p s0 -> forall r s1. p r s1 (* more generic *) let wpof2 #a (l : list eff_label) : wp a = let i = interp l in let wp : wp a = fun p s0 -> (forall r s1. (i WR == false ==> s1 == s0) ==> (i EXN == false ==> V? r) ==> p r s1) in wp type repr (a:Type u#aa) (labs : list u#0 eff_label) // #2074 : Type u#0 = unit -> ALL a (wpof2 labs) let rec interp_at (l1 l2 : list eff_label) (l : eff_label) : Lemma (interp (l1@l2) l == (interp l1 l || interp l2 l)) [SMTPat (interp (l1@l2) l)] = match l1 with | [] -> () | _::l1 -> interp_at l1 l2 l let sublist (l1 l2 : list eff_label) = forall x. mem x l1 ==> mem x l2 let sublist_refl (l : list eff_label) : Lemma (sublist l l) [SMTPat (sublist l l)] = () let rec interp_sublist (l1 l2 : list eff_label) (l : eff_label) : Lemma (requires (sublist l1 l2)) (ensures (interp l1 l ==> interp l2 l)) [SMTPat (interp l1 l); SMTPat (sublist l1 l2)] = match l1 with | [] -> () | _::l1 -> interp_sublist l1 l2 l let rec sublist_at (l1 l2 : list eff_label) : Lemma (sublist l1 (l1@l2) /\ sublist l2 (l1@l2)) [SMTPatOr [[SMTPat (sublist l1 (l1@l2))]; [SMTPat (sublist l2 (l1@l2))]]] = match l1 with | [] -> () | _::l1 -> sublist_at l1 l2 let ann_le (ann1 ann2 : annot) : prop = forall x. ann1 x ==> ann2 x let return (a:Type) (x:a) : repr a [] = fun () -> x let bind (a b : Type) (labs1 labs2 : list eff_label) (c : repr a labs1) (f : (x:a -> repr b labs2)) : Tot (repr b (labs1@labs2)) = fun () -> f (c ()) () let subcomp (a:Type) (labs1 labs2 : list eff_label) (f : repr a labs1) : Pure (repr a labs2) (requires (sublist labs1 labs2)) (ensures (fun _ -> True)) = f let ite (p q r : Type0) = (p ==> q) /\ (~p ==> r) let if_then_else (a : Type) (labs1 labs2 : list eff_label) (f : repr a labs1) (g : repr a labs2) (p : bool) : Type = repr a (labs1@labs2) total reifiable reflectable effect { EFF (a:Type) (_:list eff_label) with {repr; return; bind; subcomp; if_then_else} } let lift_pure_eff (a:Type) (wp : pure_wp a) (f : unit -> PURE a wp) : Pure (repr a []) (requires (wp (fun _ -> True))) (ensures (fun _ -> True)) = FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp; fun () -> f () sub_effect PURE ~> EFF = lift_pure_eff let get () : EFF H.heap [] = EFF?.reflect (fun () -> get ()) let (!) #a (r:ref a) : EFF a [] = EFF?.reflect (fun () -> !r) let (:=) #a (r:ref a) (v:a) : EFF unit [WR] = EFF?.reflect (fun () -> r := v) (* GM: The refinement is clearly crap, just trying to get a typeable put-like thing here. *) let put (s:state{forall s1. heap_rel s1 s}) : EFF unit [WR] = EFF?.reflect (fun () -> gst_put s) let raise #a (e:exn) : EFF a [EXN] = EFF?.reflect (fun () -> raise e) let test0 (r:ref int) (x y : int) : EFF int [EXN] = let z = !r in if x + z > 0 then raise (Failure "nope") else y - z let test1 (r:ref int) (x y : int) : EFF int [EXN; WR] = let z = !r in if x + z > 0 then raise (Failure "nope") else (r := 42; y - z)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Heap.fst.checked", "FStar.Classical.fsti.checked", "FStar.All.fst.checked" ], "interface_file": false, "source_file": "LatticeEff.fst" }
[ { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
l1: Prims.list LatticeEff.eff_label -> FStar.Pervasives.Lemma (ensures LatticeEff.sublist (l1 @ l1) l1) [SMTPat (l1 @ l1)]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.list", "LatticeEff.eff_label", "FStar.Classical.forall_intro", "Prims.b2t", "Prims.op_Equality", "Prims.bool", "FStar.List.Tot.Base.mem", "FStar.List.Tot.Base.op_At", "Prims.op_BarBar", "FStar.List.Tot.Properties.append_mem", "Prims.unit", "Prims.l_True", "Prims.squash", "LatticeEff.sublist", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat", "Prims.Nil" ]
[]
false
false
true
false
false
let sublist_at_self (l1: list eff_label) : Lemma (sublist (l1 @ l1) l1) [SMTPat (l1 @ l1)] =
Classical.forall_intro (List.Tot.Properties.append_mem l1 l1)
false
LatticeEff.fst
LatticeEff.g
val g: #labs: _ -> Prims.unit -> EFF int labs
val g: #labs: _ -> Prims.unit -> EFF int labs
let g #labs () : EFF int labs = 42
{ "file_name": "examples/layeredeffects/LatticeEff.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 34, "end_line": 199, "start_col": 0, "start_line": 199 }
module LatticeEff open FStar.Tactics.V2 open FStar.List.Tot open FStar.All module H = FStar.Heap // GM: Force a type equality by SMT let coerce #a #b (x:a{a == b}) : b = x let unreachable #a () : Pure a (requires False) (ensures (fun _ -> False)) = coerce "whatever" type eff_label = // GM: Can we do this one? ALL's WPs are unary and this is a // relational property. // | RD | WR //| DIV | EXN type annot = eff_label -> bool let interp (l : list eff_label) : annot = fun lab -> mem lab l type state = H.heap type wp a = all_wp_h H.heap a // boring, exponential //let wpof1 #a (l : list eff_label) : all_wp_h H.heap a = // let i = interp l in // match i ST, i EXN with // | false, false -> // fun p s0 -> forall x. p (V x) s0 // | true , false -> // fun p s0 -> forall x s1. p (V x) s1 // | false, true -> // fun p s0 -> forall r. p r s0 // | true, true -> // fun p s0 -> forall r s1. p r s1 (* more generic *) let wpof2 #a (l : list eff_label) : wp a = let i = interp l in let wp : wp a = fun p s0 -> (forall r s1. (i WR == false ==> s1 == s0) ==> (i EXN == false ==> V? r) ==> p r s1) in wp type repr (a:Type u#aa) (labs : list u#0 eff_label) // #2074 : Type u#0 = unit -> ALL a (wpof2 labs) let rec interp_at (l1 l2 : list eff_label) (l : eff_label) : Lemma (interp (l1@l2) l == (interp l1 l || interp l2 l)) [SMTPat (interp (l1@l2) l)] = match l1 with | [] -> () | _::l1 -> interp_at l1 l2 l let sublist (l1 l2 : list eff_label) = forall x. mem x l1 ==> mem x l2 let sublist_refl (l : list eff_label) : Lemma (sublist l l) [SMTPat (sublist l l)] = () let rec interp_sublist (l1 l2 : list eff_label) (l : eff_label) : Lemma (requires (sublist l1 l2)) (ensures (interp l1 l ==> interp l2 l)) [SMTPat (interp l1 l); SMTPat (sublist l1 l2)] = match l1 with | [] -> () | _::l1 -> interp_sublist l1 l2 l let rec sublist_at (l1 l2 : list eff_label) : Lemma (sublist l1 (l1@l2) /\ sublist l2 (l1@l2)) [SMTPatOr [[SMTPat (sublist l1 (l1@l2))]; [SMTPat (sublist l2 (l1@l2))]]] = match l1 with | [] -> () | _::l1 -> sublist_at l1 l2 let ann_le (ann1 ann2 : annot) : prop = forall x. ann1 x ==> ann2 x let return (a:Type) (x:a) : repr a [] = fun () -> x let bind (a b : Type) (labs1 labs2 : list eff_label) (c : repr a labs1) (f : (x:a -> repr b labs2)) : Tot (repr b (labs1@labs2)) = fun () -> f (c ()) () let subcomp (a:Type) (labs1 labs2 : list eff_label) (f : repr a labs1) : Pure (repr a labs2) (requires (sublist labs1 labs2)) (ensures (fun _ -> True)) = f let ite (p q r : Type0) = (p ==> q) /\ (~p ==> r) let if_then_else (a : Type) (labs1 labs2 : list eff_label) (f : repr a labs1) (g : repr a labs2) (p : bool) : Type = repr a (labs1@labs2) total reifiable reflectable effect { EFF (a:Type) (_:list eff_label) with {repr; return; bind; subcomp; if_then_else} } let lift_pure_eff (a:Type) (wp : pure_wp a) (f : unit -> PURE a wp) : Pure (repr a []) (requires (wp (fun _ -> True))) (ensures (fun _ -> True)) = FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp; fun () -> f () sub_effect PURE ~> EFF = lift_pure_eff let get () : EFF H.heap [] = EFF?.reflect (fun () -> get ()) let (!) #a (r:ref a) : EFF a [] = EFF?.reflect (fun () -> !r) let (:=) #a (r:ref a) (v:a) : EFF unit [WR] = EFF?.reflect (fun () -> r := v) (* GM: The refinement is clearly crap, just trying to get a typeable put-like thing here. *) let put (s:state{forall s1. heap_rel s1 s}) : EFF unit [WR] = EFF?.reflect (fun () -> gst_put s) let raise #a (e:exn) : EFF a [EXN] = EFF?.reflect (fun () -> raise e) let test0 (r:ref int) (x y : int) : EFF int [EXN] = let z = !r in if x + z > 0 then raise (Failure "nope") else y - z let test1 (r:ref int) (x y : int) : EFF int [EXN; WR] = let z = !r in if x + z > 0 then raise (Failure "nope") else (r := 42; y - z) let sublist_at_self (l1 : list eff_label) : Lemma (sublist (l1@l1) l1) [SMTPat (l1@l1)] = Classical.forall_intro (List.Tot.Properties.append_mem l1 l1) let labpoly #labs (f g : unit -> EFF int labs) : EFF int labs = f () + g () assume val try_with (#a:_) (#wpf:_) (#wpg:_) ($f : unit -> ALL a wpf) ($g : unit -> ALL a wpg) : ALL a (fun p s0 -> wpf (fun r s1 -> match r with | V _ -> p r s1 | _ -> wpg p s1) s0) (* no rollback *) (* GM: NB: this looks incredibly simple, but took like an hour to get right * when the WP of try_with wasn't exactly what was expected :-) *) let catch #a #labs (f : unit -> EFF a (EXN::labs)) (g : unit -> EFF a labs) : EFF a labs = EFF?.reflect begin fun () -> try_with (reify (f ())) (reify (g ())) end
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Heap.fst.checked", "FStar.Classical.fsti.checked", "FStar.All.fst.checked" ], "interface_file": false, "source_file": "LatticeEff.fst" }
[ { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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 -> LatticeEff.EFF Prims.int
LatticeEff.EFF
[]
[]
[ "Prims.list", "LatticeEff.eff_label", "Prims.unit", "Prims.int" ]
[]
false
true
false
false
false
let g #labs () : EFF int labs =
42
false
LatticeEff.fst
LatticeEff.test0
val test0 (r: ref int) (x y: int) : EFF int [EXN]
val test0 (r: ref int) (x y: int) : EFF int [EXN]
let test0 (r:ref int) (x y : int) : EFF int [EXN] = let z = !r in if x + z > 0 then raise (Failure "nope") else y - z
{ "file_name": "examples/layeredeffects/LatticeEff.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 12, "end_line": 166, "start_col": 0, "start_line": 162 }
module LatticeEff open FStar.Tactics.V2 open FStar.List.Tot open FStar.All module H = FStar.Heap // GM: Force a type equality by SMT let coerce #a #b (x:a{a == b}) : b = x let unreachable #a () : Pure a (requires False) (ensures (fun _ -> False)) = coerce "whatever" type eff_label = // GM: Can we do this one? ALL's WPs are unary and this is a // relational property. // | RD | WR //| DIV | EXN type annot = eff_label -> bool let interp (l : list eff_label) : annot = fun lab -> mem lab l type state = H.heap type wp a = all_wp_h H.heap a // boring, exponential //let wpof1 #a (l : list eff_label) : all_wp_h H.heap a = // let i = interp l in // match i ST, i EXN with // | false, false -> // fun p s0 -> forall x. p (V x) s0 // | true , false -> // fun p s0 -> forall x s1. p (V x) s1 // | false, true -> // fun p s0 -> forall r. p r s0 // | true, true -> // fun p s0 -> forall r s1. p r s1 (* more generic *) let wpof2 #a (l : list eff_label) : wp a = let i = interp l in let wp : wp a = fun p s0 -> (forall r s1. (i WR == false ==> s1 == s0) ==> (i EXN == false ==> V? r) ==> p r s1) in wp type repr (a:Type u#aa) (labs : list u#0 eff_label) // #2074 : Type u#0 = unit -> ALL a (wpof2 labs) let rec interp_at (l1 l2 : list eff_label) (l : eff_label) : Lemma (interp (l1@l2) l == (interp l1 l || interp l2 l)) [SMTPat (interp (l1@l2) l)] = match l1 with | [] -> () | _::l1 -> interp_at l1 l2 l let sublist (l1 l2 : list eff_label) = forall x. mem x l1 ==> mem x l2 let sublist_refl (l : list eff_label) : Lemma (sublist l l) [SMTPat (sublist l l)] = () let rec interp_sublist (l1 l2 : list eff_label) (l : eff_label) : Lemma (requires (sublist l1 l2)) (ensures (interp l1 l ==> interp l2 l)) [SMTPat (interp l1 l); SMTPat (sublist l1 l2)] = match l1 with | [] -> () | _::l1 -> interp_sublist l1 l2 l let rec sublist_at (l1 l2 : list eff_label) : Lemma (sublist l1 (l1@l2) /\ sublist l2 (l1@l2)) [SMTPatOr [[SMTPat (sublist l1 (l1@l2))]; [SMTPat (sublist l2 (l1@l2))]]] = match l1 with | [] -> () | _::l1 -> sublist_at l1 l2 let ann_le (ann1 ann2 : annot) : prop = forall x. ann1 x ==> ann2 x let return (a:Type) (x:a) : repr a [] = fun () -> x let bind (a b : Type) (labs1 labs2 : list eff_label) (c : repr a labs1) (f : (x:a -> repr b labs2)) : Tot (repr b (labs1@labs2)) = fun () -> f (c ()) () let subcomp (a:Type) (labs1 labs2 : list eff_label) (f : repr a labs1) : Pure (repr a labs2) (requires (sublist labs1 labs2)) (ensures (fun _ -> True)) = f let ite (p q r : Type0) = (p ==> q) /\ (~p ==> r) let if_then_else (a : Type) (labs1 labs2 : list eff_label) (f : repr a labs1) (g : repr a labs2) (p : bool) : Type = repr a (labs1@labs2) total reifiable reflectable effect { EFF (a:Type) (_:list eff_label) with {repr; return; bind; subcomp; if_then_else} } let lift_pure_eff (a:Type) (wp : pure_wp a) (f : unit -> PURE a wp) : Pure (repr a []) (requires (wp (fun _ -> True))) (ensures (fun _ -> True)) = FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp; fun () -> f () sub_effect PURE ~> EFF = lift_pure_eff let get () : EFF H.heap [] = EFF?.reflect (fun () -> get ()) let (!) #a (r:ref a) : EFF a [] = EFF?.reflect (fun () -> !r) let (:=) #a (r:ref a) (v:a) : EFF unit [WR] = EFF?.reflect (fun () -> r := v) (* GM: The refinement is clearly crap, just trying to get a typeable put-like thing here. *) let put (s:state{forall s1. heap_rel s1 s}) : EFF unit [WR] = EFF?.reflect (fun () -> gst_put s) let raise #a (e:exn) : EFF a [EXN] = EFF?.reflect (fun () -> raise e)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Heap.fst.checked", "FStar.Classical.fsti.checked", "FStar.All.fst.checked" ], "interface_file": false, "source_file": "LatticeEff.fst" }
[ { "abbrev": true, "full_module": "FStar.Heap", "short_module": "H" }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
r: FStar.ST.ref Prims.int -> x: Prims.int -> y: Prims.int -> LatticeEff.EFF Prims.int
LatticeEff.EFF
[]
[]
[ "FStar.ST.ref", "Prims.int", "Prims.op_GreaterThan", "Prims.op_Addition", "LatticeEff.raise", "FStar.All.Failure", "Prims.bool", "Prims.op_Subtraction", "LatticeEff.op_Bang", "Prims.Cons", "LatticeEff.eff_label", "LatticeEff.EXN", "Prims.Nil" ]
[]
false
true
false
false
false
let test0 (r: ref int) (x y: int) : EFF int [EXN] =
let z = !r in if x + z > 0 then raise (Failure "nope") else y - z
false
Steel.HigherReference.fst
Steel.HigherReference.ghost_share
val ghost_share (#a:Type) (#u:_) (#p:perm) (#x:erased a) (r:ghost_ref a) : SteelGhostT unit u (ghost_pts_to r p x) (fun _ -> ghost_pts_to r (half_perm p) x `star` ghost_pts_to r (half_perm p) x)
val ghost_share (#a:Type) (#u:_) (#p:perm) (#x:erased a) (r:ghost_ref a) : SteelGhostT unit u (ghost_pts_to r p x) (fun _ -> ghost_pts_to r (half_perm p) x `star` ghost_pts_to r (half_perm p) x)
let ghost_share r = share (reveal r)
{ "file_name": "lib/steel/Steel.HigherReference.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 36, "end_line": 440, "start_col": 0, "start_line": 440 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.HigherReference open FStar.Ghost open Steel.Memory open Steel.Effect.Atomic open Steel.Effect open FStar.PCM open Steel.PCMFrac open FStar.Real module RP = Steel.PCMReference #set-options "--ide_id_info_off" module Mem = Steel.Memory let ref a = Mem.ref (fractional a) pcm_frac let null #a = Mem.null #(fractional a) #pcm_frac let is_null #a r = Mem.is_null #(fractional a) #pcm_frac r let perm_ok p : prop = (p.v <=. one == true) /\ True let pts_to_raw_sl (#a:Type) (r:ref a) (p:perm) (v:erased a) : slprop = Mem.pts_to r (Some (Ghost.reveal v, p)) let pts_to_raw (#a:Type) (r:ref a) (p:perm) (v:erased a) : vprop = to_vprop (Mem.pts_to r (Some (Ghost.reveal v, p))) [@@__reduce__] let pts_to' (#a:Type u#1) (r:ref a) (p:perm) (v:erased a) : vprop = pts_to_raw r p v `star` pure (perm_ok p) let pts_to_sl #a r p v = hp_of (pts_to' r p v) let abcd_acbd (a b c d:slprop) : Lemma (Mem.(((a `star` b) `star` (c `star` d)) `equiv` ((a `star` c) `star` (b `star` d)))) = let open Steel.Memory in calc (equiv) { ((a `star` b) `star` (c `star` d)); (equiv) { star_associative a b (c `star` d) } ((a `star` (b `star` (c `star` d)))); (equiv) { star_associative b c d; star_congruence a (b `star` (c `star` d)) a ((b `star` c) `star` d) } (a `star` ((b `star` c) `star` d)); (equiv) { star_commutative b c; star_congruence (b `star` c) d (c `star` b) d; star_congruence a ((b `star` c) `star` d) a ((c `star` b) `star` d) } (a `star` ((c `star` b) `star` d)); (equiv) { star_associative c b d; star_congruence a ((c `star` b) `star` d) a (c `star` (b `star` d)) } (a `star` (c `star` (b `star` d))); (equiv) { star_associative a c (b `star` d) } ((a `star` c) `star` (b `star` d)); } let pts_to_ref_injective (#a: Type u#1) (r: ref a) (p0 p1:perm) (v0 v1:a) (m:mem) : Lemma (requires interp (pts_to_sl r p0 v0 `Mem.star` pts_to_sl r p1 v1) m) (ensures v0 == v1) = let open Steel.Memory in abcd_acbd (hp_of (pts_to_raw r p0 v0)) (pure (perm_ok p0)) (hp_of (pts_to_raw r p1 v1)) (pure (perm_ok p1)); Mem.affine_star (hp_of (pts_to_raw r p0 v0) `star` hp_of (pts_to_raw r p1 v1)) (pure (perm_ok p0) `star` pure (perm_ok p1)) m; Mem.pts_to_compatible r (Some (Ghost.reveal v0, p0)) (Some (Ghost.reveal v1, p1)) m let pts_to_not_null (#a:Type u#1) (r:ref a) (p:perm) (v:a) (m:mem) : Lemma (requires interp (pts_to_sl r p v) m) (ensures r =!= null) = Mem.affine_star (hp_of (pts_to_raw r p v)) (Mem.pure (perm_ok p)) m; Mem.pts_to_not_null r (Some (Ghost.reveal v, p)) m let pts_to_witinv (#a:Type) (r:ref a) (p:perm) : Lemma (is_witness_invariant (pts_to_sl r p)) = let aux (x y : erased a) (m:mem) : Lemma (requires (interp (pts_to_sl r p x) m /\ interp (pts_to_sl r p y) m)) (ensures (x == y)) = Mem.pts_to_join r (Some (Ghost.reveal x, p)) (Some (Ghost.reveal y, p)) m in Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y)) let higher_ref_pts_to_injective_eq #a #opened #p0 #p1 #v0 #v1 r = extract_info_raw (pts_to r p0 v0 `star` pts_to r p1 v1) (v0 == v1) (fun m -> pts_to_ref_injective r p0 p1 v0 v1 m); rewrite_slprop (pts_to r p1 v1) (pts_to r p1 v0) (fun _ -> ()) let pts_to_framon (#a:Type) (r:ref a) (p:perm) : Lemma (is_frame_monotonic (pts_to_sl r p)) = pts_to_witinv r p let intro_pts_to (p:perm) #a #uses (#v:erased a) (r:ref a) : SteelGhost unit uses (pts_to_raw r p v) (fun _ -> pts_to r p v) (requires fun _ -> perm_ok p) (ensures fun _ _ _ -> True) = intro_pure (perm_ok p); rewrite_slprop (pts_to' r p v) (pts_to r p v) (fun _ -> ()) let pts_to_perm #_ #_ #p #v r = rewrite_slprop (pts_to r p v) (pts_to' r p v) (fun _ -> ()); elim_pure (perm_ok p); intro_pure (perm_ok p); rewrite_slprop (pts_to' r p v) (pts_to r p v) (fun _ -> ()) let alloc #a x = let v = Some (x, full_perm) in assert (FStar.PCM.composable pcm_frac v None); assert (compatible pcm_frac v v); let r = RP.alloc v in rewrite_slprop (RP.pts_to r v) (pts_to r full_perm x) (fun m -> emp_unit (hp_of (pts_to_raw r full_perm x)); pure_star_interp (hp_of (pts_to_raw r full_perm x)) (perm_ok full_perm) m ); extract_info_raw (pts_to r full_perm x) (~ (is_null r)) (fun m -> pts_to_not_null r full_perm x m); return r let read (#a:Type) (#p:perm) (#v:erased a) (r:ref a) = let v1 : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, p)) in rewrite_slprop (pts_to r p v) (RP.pts_to r v1 `star` pure (perm_ok p)) (fun _ -> ()); elim_pure (perm_ok p); let v2 = RP.read r v1 in rewrite_slprop (RP.pts_to r v1) (pts_to r p v) (fun m -> emp_unit (hp_of (pts_to_raw r p v)); pure_star_interp (hp_of (pts_to_raw r p v)) (perm_ok p) m); assert (compatible pcm_frac v1 v2); let Some (x, _) = v2 in rewrite_slprop (pts_to r p v) (pts_to r p x) (fun _ -> ()); return x let atomic_read (#opened:_) (#a:Type) (#p:perm) (#v:erased a) (r:ref a) = let v1 : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, p)) in rewrite_slprop (pts_to r p v) (RP.pts_to r v1 `star` pure (perm_ok p)) (fun _ -> ()); elim_pure (perm_ok p); let v2 = RP.atomic_read r v1 in rewrite_slprop (RP.pts_to r v1) (pts_to r p v) (fun m -> emp_unit (hp_of (pts_to_raw r p v)); pure_star_interp (hp_of (pts_to_raw r p v)) (perm_ok p) m); assert (compatible pcm_frac v1 v2); let Some (x, _) = v2 in rewrite_slprop (pts_to r p v) (pts_to r p x) (fun _ -> ()); return x let read_refine (#a:Type) (#p:perm) (q:a -> vprop) (r:ref a) : SteelT a (h_exists (fun (v:a) -> pts_to r p v `star` q v)) (fun v -> pts_to r p v `star` q v) = let vs:erased a = witness_exists () in rewrite_slprop (pts_to r p (Ghost.hide (Ghost.reveal vs))) (pts_to r p vs) (fun _ -> ()); let v = read r in rewrite_slprop (q vs) (q v) (fun _ -> ()); return v let write (#a:Type) (#v:erased a) (r:ref a) (x:a) : SteelT unit (pts_to r full_perm v) (fun _ -> pts_to r full_perm x) = let v_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, full_perm)) in let v_new : fractional a = Some (x, full_perm) in rewrite_slprop (pts_to r full_perm v) (RP.pts_to r v_old `star` pure (perm_ok full_perm)) (fun _ -> ()); elim_pure (perm_ok full_perm); RP.write r v_old v_new; rewrite_slprop (RP.pts_to r v_new) (pts_to r full_perm x) (fun m -> emp_unit (hp_of (pts_to_raw r full_perm x)); pure_star_interp (hp_of (pts_to_raw r full_perm x)) (perm_ok full_perm) m) let atomic_write #opened #a #v r x = let v_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, full_perm)) in let v_new : fractional a = Some (x, full_perm) in rewrite_slprop (pts_to r full_perm v) (RP.pts_to r v_old `star` pure (perm_ok full_perm)) (fun _ -> ()); elim_pure (perm_ok full_perm); RP.atomic_write r v_old v_new; rewrite_slprop (RP.pts_to r v_new) (pts_to r full_perm x) (fun m -> emp_unit (hp_of (pts_to_raw r full_perm x)); pure_star_interp (hp_of (pts_to_raw r full_perm x)) (perm_ok full_perm) m) let free (#a:Type) (#v:erased a) (r:ref a) : SteelT unit (pts_to r full_perm v) (fun _ -> emp) = let v_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, full_perm)) in rewrite_slprop (pts_to r full_perm v) (RP.pts_to r v_old `star` pure (perm_ok full_perm)) (fun _ -> ()); elim_pure (perm_ok full_perm); RP.free r v_old; drop (RP.pts_to r (Mkpcm'?.one (Mkpcm?.p pcm_frac))) let share_atomic_raw_gen #a #uses (#p:perm) (r:ref a{perm_ok p}) (v0:erased a) (p1 p2: perm) : SteelGhost unit uses (pts_to_raw r p v0) (fun _ -> pts_to_raw r p1 v0 `star` pts_to_raw r p2 v0) (fun _ -> p == p1 `sum_perm` p2) (fun _ _ _ -> True) = rewrite_slprop (pts_to_raw r p v0) (RP.pts_to r _) (fun _ -> ()); RP.split r (Some (Ghost.reveal v0, p)) (Some (Ghost.reveal v0, p1)) (Some (Ghost.reveal v0, p2)); rewrite_slprop (RP.pts_to r _) (pts_to_raw r p1 v0) (fun _ -> ()); rewrite_slprop (RP.pts_to r _) (pts_to_raw r p2 v0) (fun _ -> ()) let share_atomic_raw #a #uses (#p:perm) (r:ref a{perm_ok p}) (v0:erased a) : SteelGhostT unit uses (pts_to_raw r p v0) (fun _ -> pts_to_raw r (half_perm p) v0 `star` pts_to_raw r (half_perm p) v0) = share_atomic_raw_gen r v0 (half_perm p) (half_perm p) let share_gen (#a:Type) (#uses:_) (#p:perm) (#v:erased a) (r:ref a) (p1 p2: perm) : SteelGhost unit uses (pts_to r p v) (fun _ -> pts_to r p1 v `star` pts_to r p2 v) (fun _ -> p == p1 `sum_perm` p2) (fun _ _ _ -> True) = let v_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, p)) in rewrite_slprop (pts_to r p v) (pts_to' r p v) (fun _ -> ()); elim_pure (perm_ok p); share_atomic_raw_gen r v p1 p2; intro_pts_to p1 r; intro_pts_to p2 r let share (#a:Type) #uses (#p:perm) (#v:erased a) (r:ref a) : SteelGhostT unit uses (pts_to r p v) (fun _ -> pts_to r (half_perm p) v `star` pts_to r (half_perm p) v) = share_gen r (half_perm p) (half_perm p) let gather_atomic_raw (#a:Type) (#uses:_) (#p0 #p1:perm) (r:ref a) (v0:erased a) (v1:erased a) : SteelGhostT (_:unit{v0==v1 /\ perm_ok (sum_perm p0 p1)}) uses (pts_to_raw r p0 v0 `star` pts_to_raw r p1 v1) (fun _ -> pts_to_raw r (sum_perm p0 p1) v0) = rewrite_slprop (pts_to_raw r p0 v0) (RP.pts_to r (Ghost.reveal (Some (Ghost.reveal v0, p0)))) (fun _ -> ()); rewrite_slprop (pts_to_raw r p1 v1) (RP.pts_to r (Ghost.reveal (Some (Ghost.reveal v1, p1)))) (fun _ -> ()); let _ = RP.gather r (Some (Ghost.reveal v0, p0)) (Some (Ghost.reveal v1, p1)) in rewrite_slprop (RP.pts_to r _) (pts_to_raw r (sum_perm p0 p1) v0) (fun _ -> ()) let gather (#a:Type) (#uses:_) (#p0:perm) (#p1:perm) (#v0 #v1:erased a) (r:ref a) = let v0_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v0, p0)) in let v1_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v1, p1)) in rewrite_slprop (pts_to r p0 v0) (pts_to_raw r p0 v0 `star` pure (perm_ok p0)) (fun _ -> ()); rewrite_slprop (pts_to r p1 v1) (pts_to_raw r p1 v1 `star` pure (perm_ok p1)) (fun _ -> ()); elim_pure (perm_ok p0); elim_pure (perm_ok p1); let _ = gather_atomic_raw r v0 v1 in intro_pts_to (sum_perm p0 p1) r let cas_provides #t (r:ref t) (v:Ghost.erased t) (v_new:t) (b:bool) = if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v let equiv_ext_right (p q r:slprop) : Lemma (requires q `Mem.equiv` r) (ensures Mem.((p `star` q) `equiv` (p `star` r))) = let open Steel.Memory in 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 cas_action_helper (p q r s:slprop) (m:mem) : Lemma (requires interp Mem.(p `star` q `star` r `star` s) m) (ensures interp Mem.(p `star` q `star` s) m) = let open Steel.Memory in calc (equiv) { r `star` s; (equiv) { star_commutative r s } s `star` r; }; calc (equiv) { p `star` q `star` r `star` s; (equiv) { Mem.star_associative (p `star` q) r s } (p `star` q) `star` (r `star` s); (equiv) { equiv_ext_right (p `star` q) (r `star` s) (s `star` r) } (p `star` q) `star` (s `star` r); (equiv) { star_associative (p `star` q) s r } (p `star` q `star` s) `star` r; }; assert (interp ((p `star` q `star` s) `star` r) m); affine_star (p `star` q `star` s) r m let cas_action (#t:Type) (eq: (x:t -> y:t -> b:bool{b <==> (x == y)})) (#uses:inames) (r:ref t) (v:Ghost.erased t) (v_old:t) (v_new:t) (fr:slprop) : MstTot (b:bool{b <==> (Ghost.reveal v == v_old)}) uses (pts_to_sl r full_perm v) (cas_provides r v v_new) fr (fun _ -> True) (fun _ _ _ -> True) = let m0 : full_mem = NMSTTotal.get () in let fv = Ghost.hide (Some (Ghost.reveal v, full_perm)) in let fv' = Some (v_new, full_perm) in assert (interp Mem.(pts_to_sl r full_perm v `star` fr `star` locks_invariant uses m0) m0); assert (interp Mem.(pts_to r fv `star` pure (perm_ok full_perm) `star` fr `star` locks_invariant uses m0) m0); cas_action_helper (Mem.pts_to r fv) (Mem.pure (perm_ok full_perm)) fr (locks_invariant uses m0) m0; assert (interp Mem.((pts_to r fv `star` pure (perm_ok full_perm)) `star` locks_invariant uses m0) m0); let fv_actual = Mem.frame (Mem.pure (perm_ok full_perm)) (sel_action uses r fv) fr in assert (compatible pcm_frac fv fv_actual); let Some (v', p) = fv_actual in assert (v == Ghost.hide v'); assert (p == full_perm); let b = if eq v' v_old then (Mem.frame (Mem.pure (perm_ok full_perm)) (upd_action uses r fv fv') fr; true) else false in b (*** GHOST REFERENCES ***) let ghost_ref a = erased (ref a) [@@__reduce__] let ghost_pts_to_sl #a (r:ghost_ref a) (p:perm) (x:a) = pts_to_sl (reveal r) p x let reveal_ghost_ref _ = () let reveal_ghost_pts_to_sl _ _ _ = () #push-options "--z3rlimit 20 --warn_error -271" let ghost_pts_to_witinv (#a:Type) (r:ghost_ref a) (p:perm) : Lemma (is_witness_invariant (ghost_pts_to_sl r p)) = let aux (x y : erased a) (m:mem) : Lemma (requires (interp (ghost_pts_to_sl r p x) m /\ interp (ghost_pts_to_sl r p y) m)) (ensures (x == y)) [SMTPat ()] = Mem.pts_to_join (Ghost.reveal r) (Some (Ghost.reveal x, p)) (Some (Ghost.reveal y, p)) m in assert (forall x y m. interp (ghost_pts_to_sl r p x) m /\ interp (ghost_pts_to_sl r p y) m ==> x == y); assert (is_witness_invariant (ghost_pts_to_sl r p)) #pop-options let ghost_alloc_aux (#a:Type) (#u:_) (x:a) : SteelGhostT (ref a) u emp (fun r -> pts_to r full_perm (Ghost.hide x)) = let v : fractional a = Some (x, full_perm) in assert (FStar.PCM.composable pcm_frac v None); assert (compatible pcm_frac v v); rewrite_slprop emp (to_vprop Mem.emp) (fun _ -> reveal_emp()); let r : ref a = as_atomic_action_ghost (Steel.Memory.alloc_action u v) in rewrite_slprop (RP.pts_to r v) (pts_to r full_perm x) (fun m -> emp_unit (hp_of (pts_to_raw r full_perm x)); pure_star_interp (hp_of (pts_to_raw r full_perm x)) (perm_ok full_perm) m); r let ghost_alloc x = let r = ghost_alloc_aux (reveal x) in hide r let ghost_free #a #u #v r = let v_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, full_perm)) in rewrite_slprop (pts_to r full_perm v) (RP.pts_to r v_old `star` pure (perm_ok full_perm)) (fun _ -> ()); elim_pure (perm_ok full_perm); as_atomic_action_ghost (free_action u r v_old); drop (RP.pts_to r (Mkpcm'?.one (Mkpcm?.p pcm_frac)))
{ "checked_file": "/", "dependencies": [ "Steel.PCMReference.fsti.checked", "Steel.PCMFrac.fst.checked", "Steel.Memory.fsti.checked", "Steel.Effect.Atomic.fsti.checked", "Steel.Effect.fsti.checked", "prims.fst.checked", "FStar.Real.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked", "FStar.NMSTTotal.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Steel.HigherReference.fst" }
[ { "abbrev": true, "full_module": "Steel.Memory", "short_module": "Mem" }, { "abbrev": true, "full_module": "Steel.PCMReference", "short_module": "RP" }, { "abbrev": false, "full_module": "FStar.Real", "short_module": null }, { "abbrev": false, "full_module": "Steel.PCMFrac", "short_module": null }, { "abbrev": false, "full_module": "FStar.PCM", "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": "FStar.Ghost", "short_module": null }, { "abbrev": true, "full_module": "Steel.Memory", "short_module": "Mem" }, { "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": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "Steel.FractionalPermission", "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
r: Steel.HigherReference.ghost_ref a -> Steel.Effect.Atomic.SteelGhostT Prims.unit
Steel.Effect.Atomic.SteelGhostT
[]
[]
[ "Steel.Memory.inames", "Steel.FractionalPermission.perm", "FStar.Ghost.erased", "Steel.HigherReference.ghost_ref", "Steel.HigherReference.share", "FStar.Ghost.reveal", "Steel.HigherReference.ref", "Prims.unit" ]
[]
false
true
false
false
false
let ghost_share r =
share (reveal r)
false
Steel.HigherReference.fst
Steel.HigherReference.ghost_share_gen
val ghost_share_gen (#a:Type) (#u:_) (#p:perm) (#x:erased a) (r:ghost_ref a) (p1 p2: perm) : SteelGhost unit u (ghost_pts_to r p x) (fun _ -> ghost_pts_to r p1 x `star` ghost_pts_to r p2 x) (fun _ -> p == p1 `sum_perm` p2) (fun _ _ _ -> True)
val ghost_share_gen (#a:Type) (#u:_) (#p:perm) (#x:erased a) (r:ghost_ref a) (p1 p2: perm) : SteelGhost unit u (ghost_pts_to r p x) (fun _ -> ghost_pts_to r p1 x `star` ghost_pts_to r p2 x) (fun _ -> p == p1 `sum_perm` p2) (fun _ _ _ -> True)
let ghost_share_gen r p1 p2 = share_gen (reveal r) p1 p2
{ "file_name": "lib/steel/Steel.HigherReference.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 56, "end_line": 439, "start_col": 0, "start_line": 439 }
(* 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.HigherReference open FStar.Ghost open Steel.Memory open Steel.Effect.Atomic open Steel.Effect open FStar.PCM open Steel.PCMFrac open FStar.Real module RP = Steel.PCMReference #set-options "--ide_id_info_off" module Mem = Steel.Memory let ref a = Mem.ref (fractional a) pcm_frac let null #a = Mem.null #(fractional a) #pcm_frac let is_null #a r = Mem.is_null #(fractional a) #pcm_frac r let perm_ok p : prop = (p.v <=. one == true) /\ True let pts_to_raw_sl (#a:Type) (r:ref a) (p:perm) (v:erased a) : slprop = Mem.pts_to r (Some (Ghost.reveal v, p)) let pts_to_raw (#a:Type) (r:ref a) (p:perm) (v:erased a) : vprop = to_vprop (Mem.pts_to r (Some (Ghost.reveal v, p))) [@@__reduce__] let pts_to' (#a:Type u#1) (r:ref a) (p:perm) (v:erased a) : vprop = pts_to_raw r p v `star` pure (perm_ok p) let pts_to_sl #a r p v = hp_of (pts_to' r p v) let abcd_acbd (a b c d:slprop) : Lemma (Mem.(((a `star` b) `star` (c `star` d)) `equiv` ((a `star` c) `star` (b `star` d)))) = let open Steel.Memory in calc (equiv) { ((a `star` b) `star` (c `star` d)); (equiv) { star_associative a b (c `star` d) } ((a `star` (b `star` (c `star` d)))); (equiv) { star_associative b c d; star_congruence a (b `star` (c `star` d)) a ((b `star` c) `star` d) } (a `star` ((b `star` c) `star` d)); (equiv) { star_commutative b c; star_congruence (b `star` c) d (c `star` b) d; star_congruence a ((b `star` c) `star` d) a ((c `star` b) `star` d) } (a `star` ((c `star` b) `star` d)); (equiv) { star_associative c b d; star_congruence a ((c `star` b) `star` d) a (c `star` (b `star` d)) } (a `star` (c `star` (b `star` d))); (equiv) { star_associative a c (b `star` d) } ((a `star` c) `star` (b `star` d)); } let pts_to_ref_injective (#a: Type u#1) (r: ref a) (p0 p1:perm) (v0 v1:a) (m:mem) : Lemma (requires interp (pts_to_sl r p0 v0 `Mem.star` pts_to_sl r p1 v1) m) (ensures v0 == v1) = let open Steel.Memory in abcd_acbd (hp_of (pts_to_raw r p0 v0)) (pure (perm_ok p0)) (hp_of (pts_to_raw r p1 v1)) (pure (perm_ok p1)); Mem.affine_star (hp_of (pts_to_raw r p0 v0) `star` hp_of (pts_to_raw r p1 v1)) (pure (perm_ok p0) `star` pure (perm_ok p1)) m; Mem.pts_to_compatible r (Some (Ghost.reveal v0, p0)) (Some (Ghost.reveal v1, p1)) m let pts_to_not_null (#a:Type u#1) (r:ref a) (p:perm) (v:a) (m:mem) : Lemma (requires interp (pts_to_sl r p v) m) (ensures r =!= null) = Mem.affine_star (hp_of (pts_to_raw r p v)) (Mem.pure (perm_ok p)) m; Mem.pts_to_not_null r (Some (Ghost.reveal v, p)) m let pts_to_witinv (#a:Type) (r:ref a) (p:perm) : Lemma (is_witness_invariant (pts_to_sl r p)) = let aux (x y : erased a) (m:mem) : Lemma (requires (interp (pts_to_sl r p x) m /\ interp (pts_to_sl r p y) m)) (ensures (x == y)) = Mem.pts_to_join r (Some (Ghost.reveal x, p)) (Some (Ghost.reveal y, p)) m in Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y)) let higher_ref_pts_to_injective_eq #a #opened #p0 #p1 #v0 #v1 r = extract_info_raw (pts_to r p0 v0 `star` pts_to r p1 v1) (v0 == v1) (fun m -> pts_to_ref_injective r p0 p1 v0 v1 m); rewrite_slprop (pts_to r p1 v1) (pts_to r p1 v0) (fun _ -> ()) let pts_to_framon (#a:Type) (r:ref a) (p:perm) : Lemma (is_frame_monotonic (pts_to_sl r p)) = pts_to_witinv r p let intro_pts_to (p:perm) #a #uses (#v:erased a) (r:ref a) : SteelGhost unit uses (pts_to_raw r p v) (fun _ -> pts_to r p v) (requires fun _ -> perm_ok p) (ensures fun _ _ _ -> True) = intro_pure (perm_ok p); rewrite_slprop (pts_to' r p v) (pts_to r p v) (fun _ -> ()) let pts_to_perm #_ #_ #p #v r = rewrite_slprop (pts_to r p v) (pts_to' r p v) (fun _ -> ()); elim_pure (perm_ok p); intro_pure (perm_ok p); rewrite_slprop (pts_to' r p v) (pts_to r p v) (fun _ -> ()) let alloc #a x = let v = Some (x, full_perm) in assert (FStar.PCM.composable pcm_frac v None); assert (compatible pcm_frac v v); let r = RP.alloc v in rewrite_slprop (RP.pts_to r v) (pts_to r full_perm x) (fun m -> emp_unit (hp_of (pts_to_raw r full_perm x)); pure_star_interp (hp_of (pts_to_raw r full_perm x)) (perm_ok full_perm) m ); extract_info_raw (pts_to r full_perm x) (~ (is_null r)) (fun m -> pts_to_not_null r full_perm x m); return r let read (#a:Type) (#p:perm) (#v:erased a) (r:ref a) = let v1 : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, p)) in rewrite_slprop (pts_to r p v) (RP.pts_to r v1 `star` pure (perm_ok p)) (fun _ -> ()); elim_pure (perm_ok p); let v2 = RP.read r v1 in rewrite_slprop (RP.pts_to r v1) (pts_to r p v) (fun m -> emp_unit (hp_of (pts_to_raw r p v)); pure_star_interp (hp_of (pts_to_raw r p v)) (perm_ok p) m); assert (compatible pcm_frac v1 v2); let Some (x, _) = v2 in rewrite_slprop (pts_to r p v) (pts_to r p x) (fun _ -> ()); return x let atomic_read (#opened:_) (#a:Type) (#p:perm) (#v:erased a) (r:ref a) = let v1 : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, p)) in rewrite_slprop (pts_to r p v) (RP.pts_to r v1 `star` pure (perm_ok p)) (fun _ -> ()); elim_pure (perm_ok p); let v2 = RP.atomic_read r v1 in rewrite_slprop (RP.pts_to r v1) (pts_to r p v) (fun m -> emp_unit (hp_of (pts_to_raw r p v)); pure_star_interp (hp_of (pts_to_raw r p v)) (perm_ok p) m); assert (compatible pcm_frac v1 v2); let Some (x, _) = v2 in rewrite_slprop (pts_to r p v) (pts_to r p x) (fun _ -> ()); return x let read_refine (#a:Type) (#p:perm) (q:a -> vprop) (r:ref a) : SteelT a (h_exists (fun (v:a) -> pts_to r p v `star` q v)) (fun v -> pts_to r p v `star` q v) = let vs:erased a = witness_exists () in rewrite_slprop (pts_to r p (Ghost.hide (Ghost.reveal vs))) (pts_to r p vs) (fun _ -> ()); let v = read r in rewrite_slprop (q vs) (q v) (fun _ -> ()); return v let write (#a:Type) (#v:erased a) (r:ref a) (x:a) : SteelT unit (pts_to r full_perm v) (fun _ -> pts_to r full_perm x) = let v_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, full_perm)) in let v_new : fractional a = Some (x, full_perm) in rewrite_slprop (pts_to r full_perm v) (RP.pts_to r v_old `star` pure (perm_ok full_perm)) (fun _ -> ()); elim_pure (perm_ok full_perm); RP.write r v_old v_new; rewrite_slprop (RP.pts_to r v_new) (pts_to r full_perm x) (fun m -> emp_unit (hp_of (pts_to_raw r full_perm x)); pure_star_interp (hp_of (pts_to_raw r full_perm x)) (perm_ok full_perm) m) let atomic_write #opened #a #v r x = let v_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, full_perm)) in let v_new : fractional a = Some (x, full_perm) in rewrite_slprop (pts_to r full_perm v) (RP.pts_to r v_old `star` pure (perm_ok full_perm)) (fun _ -> ()); elim_pure (perm_ok full_perm); RP.atomic_write r v_old v_new; rewrite_slprop (RP.pts_to r v_new) (pts_to r full_perm x) (fun m -> emp_unit (hp_of (pts_to_raw r full_perm x)); pure_star_interp (hp_of (pts_to_raw r full_perm x)) (perm_ok full_perm) m) let free (#a:Type) (#v:erased a) (r:ref a) : SteelT unit (pts_to r full_perm v) (fun _ -> emp) = let v_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, full_perm)) in rewrite_slprop (pts_to r full_perm v) (RP.pts_to r v_old `star` pure (perm_ok full_perm)) (fun _ -> ()); elim_pure (perm_ok full_perm); RP.free r v_old; drop (RP.pts_to r (Mkpcm'?.one (Mkpcm?.p pcm_frac))) let share_atomic_raw_gen #a #uses (#p:perm) (r:ref a{perm_ok p}) (v0:erased a) (p1 p2: perm) : SteelGhost unit uses (pts_to_raw r p v0) (fun _ -> pts_to_raw r p1 v0 `star` pts_to_raw r p2 v0) (fun _ -> p == p1 `sum_perm` p2) (fun _ _ _ -> True) = rewrite_slprop (pts_to_raw r p v0) (RP.pts_to r _) (fun _ -> ()); RP.split r (Some (Ghost.reveal v0, p)) (Some (Ghost.reveal v0, p1)) (Some (Ghost.reveal v0, p2)); rewrite_slprop (RP.pts_to r _) (pts_to_raw r p1 v0) (fun _ -> ()); rewrite_slprop (RP.pts_to r _) (pts_to_raw r p2 v0) (fun _ -> ()) let share_atomic_raw #a #uses (#p:perm) (r:ref a{perm_ok p}) (v0:erased a) : SteelGhostT unit uses (pts_to_raw r p v0) (fun _ -> pts_to_raw r (half_perm p) v0 `star` pts_to_raw r (half_perm p) v0) = share_atomic_raw_gen r v0 (half_perm p) (half_perm p) let share_gen (#a:Type) (#uses:_) (#p:perm) (#v:erased a) (r:ref a) (p1 p2: perm) : SteelGhost unit uses (pts_to r p v) (fun _ -> pts_to r p1 v `star` pts_to r p2 v) (fun _ -> p == p1 `sum_perm` p2) (fun _ _ _ -> True) = let v_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, p)) in rewrite_slprop (pts_to r p v) (pts_to' r p v) (fun _ -> ()); elim_pure (perm_ok p); share_atomic_raw_gen r v p1 p2; intro_pts_to p1 r; intro_pts_to p2 r let share (#a:Type) #uses (#p:perm) (#v:erased a) (r:ref a) : SteelGhostT unit uses (pts_to r p v) (fun _ -> pts_to r (half_perm p) v `star` pts_to r (half_perm p) v) = share_gen r (half_perm p) (half_perm p) let gather_atomic_raw (#a:Type) (#uses:_) (#p0 #p1:perm) (r:ref a) (v0:erased a) (v1:erased a) : SteelGhostT (_:unit{v0==v1 /\ perm_ok (sum_perm p0 p1)}) uses (pts_to_raw r p0 v0 `star` pts_to_raw r p1 v1) (fun _ -> pts_to_raw r (sum_perm p0 p1) v0) = rewrite_slprop (pts_to_raw r p0 v0) (RP.pts_to r (Ghost.reveal (Some (Ghost.reveal v0, p0)))) (fun _ -> ()); rewrite_slprop (pts_to_raw r p1 v1) (RP.pts_to r (Ghost.reveal (Some (Ghost.reveal v1, p1)))) (fun _ -> ()); let _ = RP.gather r (Some (Ghost.reveal v0, p0)) (Some (Ghost.reveal v1, p1)) in rewrite_slprop (RP.pts_to r _) (pts_to_raw r (sum_perm p0 p1) v0) (fun _ -> ()) let gather (#a:Type) (#uses:_) (#p0:perm) (#p1:perm) (#v0 #v1:erased a) (r:ref a) = let v0_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v0, p0)) in let v1_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v1, p1)) in rewrite_slprop (pts_to r p0 v0) (pts_to_raw r p0 v0 `star` pure (perm_ok p0)) (fun _ -> ()); rewrite_slprop (pts_to r p1 v1) (pts_to_raw r p1 v1 `star` pure (perm_ok p1)) (fun _ -> ()); elim_pure (perm_ok p0); elim_pure (perm_ok p1); let _ = gather_atomic_raw r v0 v1 in intro_pts_to (sum_perm p0 p1) r let cas_provides #t (r:ref t) (v:Ghost.erased t) (v_new:t) (b:bool) = if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v let equiv_ext_right (p q r:slprop) : Lemma (requires q `Mem.equiv` r) (ensures Mem.((p `star` q) `equiv` (p `star` r))) = let open Steel.Memory in 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 cas_action_helper (p q r s:slprop) (m:mem) : Lemma (requires interp Mem.(p `star` q `star` r `star` s) m) (ensures interp Mem.(p `star` q `star` s) m) = let open Steel.Memory in calc (equiv) { r `star` s; (equiv) { star_commutative r s } s `star` r; }; calc (equiv) { p `star` q `star` r `star` s; (equiv) { Mem.star_associative (p `star` q) r s } (p `star` q) `star` (r `star` s); (equiv) { equiv_ext_right (p `star` q) (r `star` s) (s `star` r) } (p `star` q) `star` (s `star` r); (equiv) { star_associative (p `star` q) s r } (p `star` q `star` s) `star` r; }; assert (interp ((p `star` q `star` s) `star` r) m); affine_star (p `star` q `star` s) r m let cas_action (#t:Type) (eq: (x:t -> y:t -> b:bool{b <==> (x == y)})) (#uses:inames) (r:ref t) (v:Ghost.erased t) (v_old:t) (v_new:t) (fr:slprop) : MstTot (b:bool{b <==> (Ghost.reveal v == v_old)}) uses (pts_to_sl r full_perm v) (cas_provides r v v_new) fr (fun _ -> True) (fun _ _ _ -> True) = let m0 : full_mem = NMSTTotal.get () in let fv = Ghost.hide (Some (Ghost.reveal v, full_perm)) in let fv' = Some (v_new, full_perm) in assert (interp Mem.(pts_to_sl r full_perm v `star` fr `star` locks_invariant uses m0) m0); assert (interp Mem.(pts_to r fv `star` pure (perm_ok full_perm) `star` fr `star` locks_invariant uses m0) m0); cas_action_helper (Mem.pts_to r fv) (Mem.pure (perm_ok full_perm)) fr (locks_invariant uses m0) m0; assert (interp Mem.((pts_to r fv `star` pure (perm_ok full_perm)) `star` locks_invariant uses m0) m0); let fv_actual = Mem.frame (Mem.pure (perm_ok full_perm)) (sel_action uses r fv) fr in assert (compatible pcm_frac fv fv_actual); let Some (v', p) = fv_actual in assert (v == Ghost.hide v'); assert (p == full_perm); let b = if eq v' v_old then (Mem.frame (Mem.pure (perm_ok full_perm)) (upd_action uses r fv fv') fr; true) else false in b (*** GHOST REFERENCES ***) let ghost_ref a = erased (ref a) [@@__reduce__] let ghost_pts_to_sl #a (r:ghost_ref a) (p:perm) (x:a) = pts_to_sl (reveal r) p x let reveal_ghost_ref _ = () let reveal_ghost_pts_to_sl _ _ _ = () #push-options "--z3rlimit 20 --warn_error -271" let ghost_pts_to_witinv (#a:Type) (r:ghost_ref a) (p:perm) : Lemma (is_witness_invariant (ghost_pts_to_sl r p)) = let aux (x y : erased a) (m:mem) : Lemma (requires (interp (ghost_pts_to_sl r p x) m /\ interp (ghost_pts_to_sl r p y) m)) (ensures (x == y)) [SMTPat ()] = Mem.pts_to_join (Ghost.reveal r) (Some (Ghost.reveal x, p)) (Some (Ghost.reveal y, p)) m in assert (forall x y m. interp (ghost_pts_to_sl r p x) m /\ interp (ghost_pts_to_sl r p y) m ==> x == y); assert (is_witness_invariant (ghost_pts_to_sl r p)) #pop-options let ghost_alloc_aux (#a:Type) (#u:_) (x:a) : SteelGhostT (ref a) u emp (fun r -> pts_to r full_perm (Ghost.hide x)) = let v : fractional a = Some (x, full_perm) in assert (FStar.PCM.composable pcm_frac v None); assert (compatible pcm_frac v v); rewrite_slprop emp (to_vprop Mem.emp) (fun _ -> reveal_emp()); let r : ref a = as_atomic_action_ghost (Steel.Memory.alloc_action u v) in rewrite_slprop (RP.pts_to r v) (pts_to r full_perm x) (fun m -> emp_unit (hp_of (pts_to_raw r full_perm x)); pure_star_interp (hp_of (pts_to_raw r full_perm x)) (perm_ok full_perm) m); r let ghost_alloc x = let r = ghost_alloc_aux (reveal x) in hide r let ghost_free #a #u #v r = let v_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, full_perm)) in rewrite_slprop (pts_to r full_perm v) (RP.pts_to r v_old `star` pure (perm_ok full_perm)) (fun _ -> ()); elim_pure (perm_ok full_perm); as_atomic_action_ghost (free_action u r v_old); drop (RP.pts_to r (Mkpcm'?.one (Mkpcm?.p pcm_frac)))
{ "checked_file": "/", "dependencies": [ "Steel.PCMReference.fsti.checked", "Steel.PCMFrac.fst.checked", "Steel.Memory.fsti.checked", "Steel.Effect.Atomic.fsti.checked", "Steel.Effect.fsti.checked", "prims.fst.checked", "FStar.Real.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked", "FStar.NMSTTotal.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Steel.HigherReference.fst" }
[ { "abbrev": true, "full_module": "Steel.Memory", "short_module": "Mem" }, { "abbrev": true, "full_module": "Steel.PCMReference", "short_module": "RP" }, { "abbrev": false, "full_module": "FStar.Real", "short_module": null }, { "abbrev": false, "full_module": "Steel.PCMFrac", "short_module": null }, { "abbrev": false, "full_module": "FStar.PCM", "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": "FStar.Ghost", "short_module": null }, { "abbrev": true, "full_module": "Steel.Memory", "short_module": "Mem" }, { "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": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "Steel.FractionalPermission", "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
r: Steel.HigherReference.ghost_ref a -> p1: Steel.FractionalPermission.perm -> p2: Steel.FractionalPermission.perm -> Steel.Effect.Atomic.SteelGhost Prims.unit
Steel.Effect.Atomic.SteelGhost
[]
[]
[ "Steel.Memory.inames", "Steel.FractionalPermission.perm", "FStar.Ghost.erased", "Steel.HigherReference.ghost_ref", "Steel.HigherReference.share_gen", "FStar.Ghost.reveal", "Steel.HigherReference.ref", "Prims.unit" ]
[]
false
true
false
false
false
let ghost_share_gen r p1 p2 =
share_gen (reveal r) p1 p2
false
Steel.HigherReference.fst
Steel.HigherReference.ghost_gather
val ghost_gather (#a:Type) (#u:_) (#p0 #p1:perm) (#x0 #x1:erased a) (r:ghost_ref a) : SteelGhost unit u (ghost_pts_to r p0 x0 `star` ghost_pts_to r p1 x1) (fun _ -> ghost_pts_to r (sum_perm p0 p1) x0) (requires fun _ -> True) (ensures fun _ _ _ -> x0 == x1)
val ghost_gather (#a:Type) (#u:_) (#p0 #p1:perm) (#x0 #x1:erased a) (r:ghost_ref a) : SteelGhost unit u (ghost_pts_to r p0 x0 `star` ghost_pts_to r p1 x1) (fun _ -> ghost_pts_to r (sum_perm p0 p1) x0) (requires fun _ -> True) (ensures fun _ _ _ -> x0 == x1)
let ghost_gather r = gather (reveal r)
{ "file_name": "lib/steel/Steel.HigherReference.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 38, "end_line": 441, "start_col": 0, "start_line": 441 }
(* 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.HigherReference open FStar.Ghost open Steel.Memory open Steel.Effect.Atomic open Steel.Effect open FStar.PCM open Steel.PCMFrac open FStar.Real module RP = Steel.PCMReference #set-options "--ide_id_info_off" module Mem = Steel.Memory let ref a = Mem.ref (fractional a) pcm_frac let null #a = Mem.null #(fractional a) #pcm_frac let is_null #a r = Mem.is_null #(fractional a) #pcm_frac r let perm_ok p : prop = (p.v <=. one == true) /\ True let pts_to_raw_sl (#a:Type) (r:ref a) (p:perm) (v:erased a) : slprop = Mem.pts_to r (Some (Ghost.reveal v, p)) let pts_to_raw (#a:Type) (r:ref a) (p:perm) (v:erased a) : vprop = to_vprop (Mem.pts_to r (Some (Ghost.reveal v, p))) [@@__reduce__] let pts_to' (#a:Type u#1) (r:ref a) (p:perm) (v:erased a) : vprop = pts_to_raw r p v `star` pure (perm_ok p) let pts_to_sl #a r p v = hp_of (pts_to' r p v) let abcd_acbd (a b c d:slprop) : Lemma (Mem.(((a `star` b) `star` (c `star` d)) `equiv` ((a `star` c) `star` (b `star` d)))) = let open Steel.Memory in calc (equiv) { ((a `star` b) `star` (c `star` d)); (equiv) { star_associative a b (c `star` d) } ((a `star` (b `star` (c `star` d)))); (equiv) { star_associative b c d; star_congruence a (b `star` (c `star` d)) a ((b `star` c) `star` d) } (a `star` ((b `star` c) `star` d)); (equiv) { star_commutative b c; star_congruence (b `star` c) d (c `star` b) d; star_congruence a ((b `star` c) `star` d) a ((c `star` b) `star` d) } (a `star` ((c `star` b) `star` d)); (equiv) { star_associative c b d; star_congruence a ((c `star` b) `star` d) a (c `star` (b `star` d)) } (a `star` (c `star` (b `star` d))); (equiv) { star_associative a c (b `star` d) } ((a `star` c) `star` (b `star` d)); } let pts_to_ref_injective (#a: Type u#1) (r: ref a) (p0 p1:perm) (v0 v1:a) (m:mem) : Lemma (requires interp (pts_to_sl r p0 v0 `Mem.star` pts_to_sl r p1 v1) m) (ensures v0 == v1) = let open Steel.Memory in abcd_acbd (hp_of (pts_to_raw r p0 v0)) (pure (perm_ok p0)) (hp_of (pts_to_raw r p1 v1)) (pure (perm_ok p1)); Mem.affine_star (hp_of (pts_to_raw r p0 v0) `star` hp_of (pts_to_raw r p1 v1)) (pure (perm_ok p0) `star` pure (perm_ok p1)) m; Mem.pts_to_compatible r (Some (Ghost.reveal v0, p0)) (Some (Ghost.reveal v1, p1)) m let pts_to_not_null (#a:Type u#1) (r:ref a) (p:perm) (v:a) (m:mem) : Lemma (requires interp (pts_to_sl r p v) m) (ensures r =!= null) = Mem.affine_star (hp_of (pts_to_raw r p v)) (Mem.pure (perm_ok p)) m; Mem.pts_to_not_null r (Some (Ghost.reveal v, p)) m let pts_to_witinv (#a:Type) (r:ref a) (p:perm) : Lemma (is_witness_invariant (pts_to_sl r p)) = let aux (x y : erased a) (m:mem) : Lemma (requires (interp (pts_to_sl r p x) m /\ interp (pts_to_sl r p y) m)) (ensures (x == y)) = Mem.pts_to_join r (Some (Ghost.reveal x, p)) (Some (Ghost.reveal y, p)) m in Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y)) let higher_ref_pts_to_injective_eq #a #opened #p0 #p1 #v0 #v1 r = extract_info_raw (pts_to r p0 v0 `star` pts_to r p1 v1) (v0 == v1) (fun m -> pts_to_ref_injective r p0 p1 v0 v1 m); rewrite_slprop (pts_to r p1 v1) (pts_to r p1 v0) (fun _ -> ()) let pts_to_framon (#a:Type) (r:ref a) (p:perm) : Lemma (is_frame_monotonic (pts_to_sl r p)) = pts_to_witinv r p let intro_pts_to (p:perm) #a #uses (#v:erased a) (r:ref a) : SteelGhost unit uses (pts_to_raw r p v) (fun _ -> pts_to r p v) (requires fun _ -> perm_ok p) (ensures fun _ _ _ -> True) = intro_pure (perm_ok p); rewrite_slprop (pts_to' r p v) (pts_to r p v) (fun _ -> ()) let pts_to_perm #_ #_ #p #v r = rewrite_slprop (pts_to r p v) (pts_to' r p v) (fun _ -> ()); elim_pure (perm_ok p); intro_pure (perm_ok p); rewrite_slprop (pts_to' r p v) (pts_to r p v) (fun _ -> ()) let alloc #a x = let v = Some (x, full_perm) in assert (FStar.PCM.composable pcm_frac v None); assert (compatible pcm_frac v v); let r = RP.alloc v in rewrite_slprop (RP.pts_to r v) (pts_to r full_perm x) (fun m -> emp_unit (hp_of (pts_to_raw r full_perm x)); pure_star_interp (hp_of (pts_to_raw r full_perm x)) (perm_ok full_perm) m ); extract_info_raw (pts_to r full_perm x) (~ (is_null r)) (fun m -> pts_to_not_null r full_perm x m); return r let read (#a:Type) (#p:perm) (#v:erased a) (r:ref a) = let v1 : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, p)) in rewrite_slprop (pts_to r p v) (RP.pts_to r v1 `star` pure (perm_ok p)) (fun _ -> ()); elim_pure (perm_ok p); let v2 = RP.read r v1 in rewrite_slprop (RP.pts_to r v1) (pts_to r p v) (fun m -> emp_unit (hp_of (pts_to_raw r p v)); pure_star_interp (hp_of (pts_to_raw r p v)) (perm_ok p) m); assert (compatible pcm_frac v1 v2); let Some (x, _) = v2 in rewrite_slprop (pts_to r p v) (pts_to r p x) (fun _ -> ()); return x let atomic_read (#opened:_) (#a:Type) (#p:perm) (#v:erased a) (r:ref a) = let v1 : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, p)) in rewrite_slprop (pts_to r p v) (RP.pts_to r v1 `star` pure (perm_ok p)) (fun _ -> ()); elim_pure (perm_ok p); let v2 = RP.atomic_read r v1 in rewrite_slprop (RP.pts_to r v1) (pts_to r p v) (fun m -> emp_unit (hp_of (pts_to_raw r p v)); pure_star_interp (hp_of (pts_to_raw r p v)) (perm_ok p) m); assert (compatible pcm_frac v1 v2); let Some (x, _) = v2 in rewrite_slprop (pts_to r p v) (pts_to r p x) (fun _ -> ()); return x let read_refine (#a:Type) (#p:perm) (q:a -> vprop) (r:ref a) : SteelT a (h_exists (fun (v:a) -> pts_to r p v `star` q v)) (fun v -> pts_to r p v `star` q v) = let vs:erased a = witness_exists () in rewrite_slprop (pts_to r p (Ghost.hide (Ghost.reveal vs))) (pts_to r p vs) (fun _ -> ()); let v = read r in rewrite_slprop (q vs) (q v) (fun _ -> ()); return v let write (#a:Type) (#v:erased a) (r:ref a) (x:a) : SteelT unit (pts_to r full_perm v) (fun _ -> pts_to r full_perm x) = let v_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, full_perm)) in let v_new : fractional a = Some (x, full_perm) in rewrite_slprop (pts_to r full_perm v) (RP.pts_to r v_old `star` pure (perm_ok full_perm)) (fun _ -> ()); elim_pure (perm_ok full_perm); RP.write r v_old v_new; rewrite_slprop (RP.pts_to r v_new) (pts_to r full_perm x) (fun m -> emp_unit (hp_of (pts_to_raw r full_perm x)); pure_star_interp (hp_of (pts_to_raw r full_perm x)) (perm_ok full_perm) m) let atomic_write #opened #a #v r x = let v_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, full_perm)) in let v_new : fractional a = Some (x, full_perm) in rewrite_slprop (pts_to r full_perm v) (RP.pts_to r v_old `star` pure (perm_ok full_perm)) (fun _ -> ()); elim_pure (perm_ok full_perm); RP.atomic_write r v_old v_new; rewrite_slprop (RP.pts_to r v_new) (pts_to r full_perm x) (fun m -> emp_unit (hp_of (pts_to_raw r full_perm x)); pure_star_interp (hp_of (pts_to_raw r full_perm x)) (perm_ok full_perm) m) let free (#a:Type) (#v:erased a) (r:ref a) : SteelT unit (pts_to r full_perm v) (fun _ -> emp) = let v_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, full_perm)) in rewrite_slprop (pts_to r full_perm v) (RP.pts_to r v_old `star` pure (perm_ok full_perm)) (fun _ -> ()); elim_pure (perm_ok full_perm); RP.free r v_old; drop (RP.pts_to r (Mkpcm'?.one (Mkpcm?.p pcm_frac))) let share_atomic_raw_gen #a #uses (#p:perm) (r:ref a{perm_ok p}) (v0:erased a) (p1 p2: perm) : SteelGhost unit uses (pts_to_raw r p v0) (fun _ -> pts_to_raw r p1 v0 `star` pts_to_raw r p2 v0) (fun _ -> p == p1 `sum_perm` p2) (fun _ _ _ -> True) = rewrite_slprop (pts_to_raw r p v0) (RP.pts_to r _) (fun _ -> ()); RP.split r (Some (Ghost.reveal v0, p)) (Some (Ghost.reveal v0, p1)) (Some (Ghost.reveal v0, p2)); rewrite_slprop (RP.pts_to r _) (pts_to_raw r p1 v0) (fun _ -> ()); rewrite_slprop (RP.pts_to r _) (pts_to_raw r p2 v0) (fun _ -> ()) let share_atomic_raw #a #uses (#p:perm) (r:ref a{perm_ok p}) (v0:erased a) : SteelGhostT unit uses (pts_to_raw r p v0) (fun _ -> pts_to_raw r (half_perm p) v0 `star` pts_to_raw r (half_perm p) v0) = share_atomic_raw_gen r v0 (half_perm p) (half_perm p) let share_gen (#a:Type) (#uses:_) (#p:perm) (#v:erased a) (r:ref a) (p1 p2: perm) : SteelGhost unit uses (pts_to r p v) (fun _ -> pts_to r p1 v `star` pts_to r p2 v) (fun _ -> p == p1 `sum_perm` p2) (fun _ _ _ -> True) = let v_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, p)) in rewrite_slprop (pts_to r p v) (pts_to' r p v) (fun _ -> ()); elim_pure (perm_ok p); share_atomic_raw_gen r v p1 p2; intro_pts_to p1 r; intro_pts_to p2 r let share (#a:Type) #uses (#p:perm) (#v:erased a) (r:ref a) : SteelGhostT unit uses (pts_to r p v) (fun _ -> pts_to r (half_perm p) v `star` pts_to r (half_perm p) v) = share_gen r (half_perm p) (half_perm p) let gather_atomic_raw (#a:Type) (#uses:_) (#p0 #p1:perm) (r:ref a) (v0:erased a) (v1:erased a) : SteelGhostT (_:unit{v0==v1 /\ perm_ok (sum_perm p0 p1)}) uses (pts_to_raw r p0 v0 `star` pts_to_raw r p1 v1) (fun _ -> pts_to_raw r (sum_perm p0 p1) v0) = rewrite_slprop (pts_to_raw r p0 v0) (RP.pts_to r (Ghost.reveal (Some (Ghost.reveal v0, p0)))) (fun _ -> ()); rewrite_slprop (pts_to_raw r p1 v1) (RP.pts_to r (Ghost.reveal (Some (Ghost.reveal v1, p1)))) (fun _ -> ()); let _ = RP.gather r (Some (Ghost.reveal v0, p0)) (Some (Ghost.reveal v1, p1)) in rewrite_slprop (RP.pts_to r _) (pts_to_raw r (sum_perm p0 p1) v0) (fun _ -> ()) let gather (#a:Type) (#uses:_) (#p0:perm) (#p1:perm) (#v0 #v1:erased a) (r:ref a) = let v0_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v0, p0)) in let v1_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v1, p1)) in rewrite_slprop (pts_to r p0 v0) (pts_to_raw r p0 v0 `star` pure (perm_ok p0)) (fun _ -> ()); rewrite_slprop (pts_to r p1 v1) (pts_to_raw r p1 v1 `star` pure (perm_ok p1)) (fun _ -> ()); elim_pure (perm_ok p0); elim_pure (perm_ok p1); let _ = gather_atomic_raw r v0 v1 in intro_pts_to (sum_perm p0 p1) r let cas_provides #t (r:ref t) (v:Ghost.erased t) (v_new:t) (b:bool) = if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v let equiv_ext_right (p q r:slprop) : Lemma (requires q `Mem.equiv` r) (ensures Mem.((p `star` q) `equiv` (p `star` r))) = let open Steel.Memory in 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 cas_action_helper (p q r s:slprop) (m:mem) : Lemma (requires interp Mem.(p `star` q `star` r `star` s) m) (ensures interp Mem.(p `star` q `star` s) m) = let open Steel.Memory in calc (equiv) { r `star` s; (equiv) { star_commutative r s } s `star` r; }; calc (equiv) { p `star` q `star` r `star` s; (equiv) { Mem.star_associative (p `star` q) r s } (p `star` q) `star` (r `star` s); (equiv) { equiv_ext_right (p `star` q) (r `star` s) (s `star` r) } (p `star` q) `star` (s `star` r); (equiv) { star_associative (p `star` q) s r } (p `star` q `star` s) `star` r; }; assert (interp ((p `star` q `star` s) `star` r) m); affine_star (p `star` q `star` s) r m let cas_action (#t:Type) (eq: (x:t -> y:t -> b:bool{b <==> (x == y)})) (#uses:inames) (r:ref t) (v:Ghost.erased t) (v_old:t) (v_new:t) (fr:slprop) : MstTot (b:bool{b <==> (Ghost.reveal v == v_old)}) uses (pts_to_sl r full_perm v) (cas_provides r v v_new) fr (fun _ -> True) (fun _ _ _ -> True) = let m0 : full_mem = NMSTTotal.get () in let fv = Ghost.hide (Some (Ghost.reveal v, full_perm)) in let fv' = Some (v_new, full_perm) in assert (interp Mem.(pts_to_sl r full_perm v `star` fr `star` locks_invariant uses m0) m0); assert (interp Mem.(pts_to r fv `star` pure (perm_ok full_perm) `star` fr `star` locks_invariant uses m0) m0); cas_action_helper (Mem.pts_to r fv) (Mem.pure (perm_ok full_perm)) fr (locks_invariant uses m0) m0; assert (interp Mem.((pts_to r fv `star` pure (perm_ok full_perm)) `star` locks_invariant uses m0) m0); let fv_actual = Mem.frame (Mem.pure (perm_ok full_perm)) (sel_action uses r fv) fr in assert (compatible pcm_frac fv fv_actual); let Some (v', p) = fv_actual in assert (v == Ghost.hide v'); assert (p == full_perm); let b = if eq v' v_old then (Mem.frame (Mem.pure (perm_ok full_perm)) (upd_action uses r fv fv') fr; true) else false in b (*** GHOST REFERENCES ***) let ghost_ref a = erased (ref a) [@@__reduce__] let ghost_pts_to_sl #a (r:ghost_ref a) (p:perm) (x:a) = pts_to_sl (reveal r) p x let reveal_ghost_ref _ = () let reveal_ghost_pts_to_sl _ _ _ = () #push-options "--z3rlimit 20 --warn_error -271" let ghost_pts_to_witinv (#a:Type) (r:ghost_ref a) (p:perm) : Lemma (is_witness_invariant (ghost_pts_to_sl r p)) = let aux (x y : erased a) (m:mem) : Lemma (requires (interp (ghost_pts_to_sl r p x) m /\ interp (ghost_pts_to_sl r p y) m)) (ensures (x == y)) [SMTPat ()] = Mem.pts_to_join (Ghost.reveal r) (Some (Ghost.reveal x, p)) (Some (Ghost.reveal y, p)) m in assert (forall x y m. interp (ghost_pts_to_sl r p x) m /\ interp (ghost_pts_to_sl r p y) m ==> x == y); assert (is_witness_invariant (ghost_pts_to_sl r p)) #pop-options let ghost_alloc_aux (#a:Type) (#u:_) (x:a) : SteelGhostT (ref a) u emp (fun r -> pts_to r full_perm (Ghost.hide x)) = let v : fractional a = Some (x, full_perm) in assert (FStar.PCM.composable pcm_frac v None); assert (compatible pcm_frac v v); rewrite_slprop emp (to_vprop Mem.emp) (fun _ -> reveal_emp()); let r : ref a = as_atomic_action_ghost (Steel.Memory.alloc_action u v) in rewrite_slprop (RP.pts_to r v) (pts_to r full_perm x) (fun m -> emp_unit (hp_of (pts_to_raw r full_perm x)); pure_star_interp (hp_of (pts_to_raw r full_perm x)) (perm_ok full_perm) m); r let ghost_alloc x = let r = ghost_alloc_aux (reveal x) in hide r let ghost_free #a #u #v r = let v_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, full_perm)) in rewrite_slprop (pts_to r full_perm v) (RP.pts_to r v_old `star` pure (perm_ok full_perm)) (fun _ -> ()); elim_pure (perm_ok full_perm); as_atomic_action_ghost (free_action u r v_old); drop (RP.pts_to r (Mkpcm'?.one (Mkpcm?.p pcm_frac))) let ghost_share_gen r p1 p2 = share_gen (reveal r) p1 p2
{ "checked_file": "/", "dependencies": [ "Steel.PCMReference.fsti.checked", "Steel.PCMFrac.fst.checked", "Steel.Memory.fsti.checked", "Steel.Effect.Atomic.fsti.checked", "Steel.Effect.fsti.checked", "prims.fst.checked", "FStar.Real.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked", "FStar.NMSTTotal.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Steel.HigherReference.fst" }
[ { "abbrev": true, "full_module": "Steel.Memory", "short_module": "Mem" }, { "abbrev": true, "full_module": "Steel.PCMReference", "short_module": "RP" }, { "abbrev": false, "full_module": "FStar.Real", "short_module": null }, { "abbrev": false, "full_module": "Steel.PCMFrac", "short_module": null }, { "abbrev": false, "full_module": "FStar.PCM", "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": "FStar.Ghost", "short_module": null }, { "abbrev": true, "full_module": "Steel.Memory", "short_module": "Mem" }, { "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": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "Steel.FractionalPermission", "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
r: Steel.HigherReference.ghost_ref a -> Steel.Effect.Atomic.SteelGhost Prims.unit
Steel.Effect.Atomic.SteelGhost
[]
[]
[ "Steel.Memory.inames", "Steel.FractionalPermission.perm", "FStar.Ghost.erased", "Steel.HigherReference.ghost_ref", "Steel.HigherReference.gather", "FStar.Ghost.reveal", "Steel.HigherReference.ref", "Prims.unit" ]
[]
false
true
false
false
false
let ghost_gather r =
gather (reveal r)
false
Steel.HigherReference.fst
Steel.HigherReference.ghost_pts_to_injective_eq
val ghost_pts_to_injective_eq (#a:_) (#u:_) (#p #q:_) (r:ghost_ref a) (v0 v1:Ghost.erased a) : SteelGhost unit u (ghost_pts_to r p v0 `star` ghost_pts_to r q v1) (fun _ -> ghost_pts_to r p v0 `star` ghost_pts_to r q v0) (requires fun _ -> True) (ensures fun _ _ _ -> v0 == v1)
val ghost_pts_to_injective_eq (#a:_) (#u:_) (#p #q:_) (r:ghost_ref a) (v0 v1:Ghost.erased a) : SteelGhost unit u (ghost_pts_to r p v0 `star` ghost_pts_to r q v1) (fun _ -> ghost_pts_to r p v0 `star` ghost_pts_to r q v0) (requires fun _ -> True) (ensures fun _ _ _ -> v0 == v1)
let ghost_pts_to_injective_eq #_ #_ #p0 #p1 r v0 v1 = higher_ref_pts_to_injective_eq #_ #_ #p0 #p1 #v0 #v1 (reveal r)
{ "file_name": "lib/steel/Steel.HigherReference.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 65, "end_line": 444, "start_col": 0, "start_line": 443 }
(* 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.HigherReference open FStar.Ghost open Steel.Memory open Steel.Effect.Atomic open Steel.Effect open FStar.PCM open Steel.PCMFrac open FStar.Real module RP = Steel.PCMReference #set-options "--ide_id_info_off" module Mem = Steel.Memory let ref a = Mem.ref (fractional a) pcm_frac let null #a = Mem.null #(fractional a) #pcm_frac let is_null #a r = Mem.is_null #(fractional a) #pcm_frac r let perm_ok p : prop = (p.v <=. one == true) /\ True let pts_to_raw_sl (#a:Type) (r:ref a) (p:perm) (v:erased a) : slprop = Mem.pts_to r (Some (Ghost.reveal v, p)) let pts_to_raw (#a:Type) (r:ref a) (p:perm) (v:erased a) : vprop = to_vprop (Mem.pts_to r (Some (Ghost.reveal v, p))) [@@__reduce__] let pts_to' (#a:Type u#1) (r:ref a) (p:perm) (v:erased a) : vprop = pts_to_raw r p v `star` pure (perm_ok p) let pts_to_sl #a r p v = hp_of (pts_to' r p v) let abcd_acbd (a b c d:slprop) : Lemma (Mem.(((a `star` b) `star` (c `star` d)) `equiv` ((a `star` c) `star` (b `star` d)))) = let open Steel.Memory in calc (equiv) { ((a `star` b) `star` (c `star` d)); (equiv) { star_associative a b (c `star` d) } ((a `star` (b `star` (c `star` d)))); (equiv) { star_associative b c d; star_congruence a (b `star` (c `star` d)) a ((b `star` c) `star` d) } (a `star` ((b `star` c) `star` d)); (equiv) { star_commutative b c; star_congruence (b `star` c) d (c `star` b) d; star_congruence a ((b `star` c) `star` d) a ((c `star` b) `star` d) } (a `star` ((c `star` b) `star` d)); (equiv) { star_associative c b d; star_congruence a ((c `star` b) `star` d) a (c `star` (b `star` d)) } (a `star` (c `star` (b `star` d))); (equiv) { star_associative a c (b `star` d) } ((a `star` c) `star` (b `star` d)); } let pts_to_ref_injective (#a: Type u#1) (r: ref a) (p0 p1:perm) (v0 v1:a) (m:mem) : Lemma (requires interp (pts_to_sl r p0 v0 `Mem.star` pts_to_sl r p1 v1) m) (ensures v0 == v1) = let open Steel.Memory in abcd_acbd (hp_of (pts_to_raw r p0 v0)) (pure (perm_ok p0)) (hp_of (pts_to_raw r p1 v1)) (pure (perm_ok p1)); Mem.affine_star (hp_of (pts_to_raw r p0 v0) `star` hp_of (pts_to_raw r p1 v1)) (pure (perm_ok p0) `star` pure (perm_ok p1)) m; Mem.pts_to_compatible r (Some (Ghost.reveal v0, p0)) (Some (Ghost.reveal v1, p1)) m let pts_to_not_null (#a:Type u#1) (r:ref a) (p:perm) (v:a) (m:mem) : Lemma (requires interp (pts_to_sl r p v) m) (ensures r =!= null) = Mem.affine_star (hp_of (pts_to_raw r p v)) (Mem.pure (perm_ok p)) m; Mem.pts_to_not_null r (Some (Ghost.reveal v, p)) m let pts_to_witinv (#a:Type) (r:ref a) (p:perm) : Lemma (is_witness_invariant (pts_to_sl r p)) = let aux (x y : erased a) (m:mem) : Lemma (requires (interp (pts_to_sl r p x) m /\ interp (pts_to_sl r p y) m)) (ensures (x == y)) = Mem.pts_to_join r (Some (Ghost.reveal x, p)) (Some (Ghost.reveal y, p)) m in Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y)) let higher_ref_pts_to_injective_eq #a #opened #p0 #p1 #v0 #v1 r = extract_info_raw (pts_to r p0 v0 `star` pts_to r p1 v1) (v0 == v1) (fun m -> pts_to_ref_injective r p0 p1 v0 v1 m); rewrite_slprop (pts_to r p1 v1) (pts_to r p1 v0) (fun _ -> ()) let pts_to_framon (#a:Type) (r:ref a) (p:perm) : Lemma (is_frame_monotonic (pts_to_sl r p)) = pts_to_witinv r p let intro_pts_to (p:perm) #a #uses (#v:erased a) (r:ref a) : SteelGhost unit uses (pts_to_raw r p v) (fun _ -> pts_to r p v) (requires fun _ -> perm_ok p) (ensures fun _ _ _ -> True) = intro_pure (perm_ok p); rewrite_slprop (pts_to' r p v) (pts_to r p v) (fun _ -> ()) let pts_to_perm #_ #_ #p #v r = rewrite_slprop (pts_to r p v) (pts_to' r p v) (fun _ -> ()); elim_pure (perm_ok p); intro_pure (perm_ok p); rewrite_slprop (pts_to' r p v) (pts_to r p v) (fun _ -> ()) let alloc #a x = let v = Some (x, full_perm) in assert (FStar.PCM.composable pcm_frac v None); assert (compatible pcm_frac v v); let r = RP.alloc v in rewrite_slprop (RP.pts_to r v) (pts_to r full_perm x) (fun m -> emp_unit (hp_of (pts_to_raw r full_perm x)); pure_star_interp (hp_of (pts_to_raw r full_perm x)) (perm_ok full_perm) m ); extract_info_raw (pts_to r full_perm x) (~ (is_null r)) (fun m -> pts_to_not_null r full_perm x m); return r let read (#a:Type) (#p:perm) (#v:erased a) (r:ref a) = let v1 : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, p)) in rewrite_slprop (pts_to r p v) (RP.pts_to r v1 `star` pure (perm_ok p)) (fun _ -> ()); elim_pure (perm_ok p); let v2 = RP.read r v1 in rewrite_slprop (RP.pts_to r v1) (pts_to r p v) (fun m -> emp_unit (hp_of (pts_to_raw r p v)); pure_star_interp (hp_of (pts_to_raw r p v)) (perm_ok p) m); assert (compatible pcm_frac v1 v2); let Some (x, _) = v2 in rewrite_slprop (pts_to r p v) (pts_to r p x) (fun _ -> ()); return x let atomic_read (#opened:_) (#a:Type) (#p:perm) (#v:erased a) (r:ref a) = let v1 : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, p)) in rewrite_slprop (pts_to r p v) (RP.pts_to r v1 `star` pure (perm_ok p)) (fun _ -> ()); elim_pure (perm_ok p); let v2 = RP.atomic_read r v1 in rewrite_slprop (RP.pts_to r v1) (pts_to r p v) (fun m -> emp_unit (hp_of (pts_to_raw r p v)); pure_star_interp (hp_of (pts_to_raw r p v)) (perm_ok p) m); assert (compatible pcm_frac v1 v2); let Some (x, _) = v2 in rewrite_slprop (pts_to r p v) (pts_to r p x) (fun _ -> ()); return x let read_refine (#a:Type) (#p:perm) (q:a -> vprop) (r:ref a) : SteelT a (h_exists (fun (v:a) -> pts_to r p v `star` q v)) (fun v -> pts_to r p v `star` q v) = let vs:erased a = witness_exists () in rewrite_slprop (pts_to r p (Ghost.hide (Ghost.reveal vs))) (pts_to r p vs) (fun _ -> ()); let v = read r in rewrite_slprop (q vs) (q v) (fun _ -> ()); return v let write (#a:Type) (#v:erased a) (r:ref a) (x:a) : SteelT unit (pts_to r full_perm v) (fun _ -> pts_to r full_perm x) = let v_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, full_perm)) in let v_new : fractional a = Some (x, full_perm) in rewrite_slprop (pts_to r full_perm v) (RP.pts_to r v_old `star` pure (perm_ok full_perm)) (fun _ -> ()); elim_pure (perm_ok full_perm); RP.write r v_old v_new; rewrite_slprop (RP.pts_to r v_new) (pts_to r full_perm x) (fun m -> emp_unit (hp_of (pts_to_raw r full_perm x)); pure_star_interp (hp_of (pts_to_raw r full_perm x)) (perm_ok full_perm) m) let atomic_write #opened #a #v r x = let v_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, full_perm)) in let v_new : fractional a = Some (x, full_perm) in rewrite_slprop (pts_to r full_perm v) (RP.pts_to r v_old `star` pure (perm_ok full_perm)) (fun _ -> ()); elim_pure (perm_ok full_perm); RP.atomic_write r v_old v_new; rewrite_slprop (RP.pts_to r v_new) (pts_to r full_perm x) (fun m -> emp_unit (hp_of (pts_to_raw r full_perm x)); pure_star_interp (hp_of (pts_to_raw r full_perm x)) (perm_ok full_perm) m) let free (#a:Type) (#v:erased a) (r:ref a) : SteelT unit (pts_to r full_perm v) (fun _ -> emp) = let v_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, full_perm)) in rewrite_slprop (pts_to r full_perm v) (RP.pts_to r v_old `star` pure (perm_ok full_perm)) (fun _ -> ()); elim_pure (perm_ok full_perm); RP.free r v_old; drop (RP.pts_to r (Mkpcm'?.one (Mkpcm?.p pcm_frac))) let share_atomic_raw_gen #a #uses (#p:perm) (r:ref a{perm_ok p}) (v0:erased a) (p1 p2: perm) : SteelGhost unit uses (pts_to_raw r p v0) (fun _ -> pts_to_raw r p1 v0 `star` pts_to_raw r p2 v0) (fun _ -> p == p1 `sum_perm` p2) (fun _ _ _ -> True) = rewrite_slprop (pts_to_raw r p v0) (RP.pts_to r _) (fun _ -> ()); RP.split r (Some (Ghost.reveal v0, p)) (Some (Ghost.reveal v0, p1)) (Some (Ghost.reveal v0, p2)); rewrite_slprop (RP.pts_to r _) (pts_to_raw r p1 v0) (fun _ -> ()); rewrite_slprop (RP.pts_to r _) (pts_to_raw r p2 v0) (fun _ -> ()) let share_atomic_raw #a #uses (#p:perm) (r:ref a{perm_ok p}) (v0:erased a) : SteelGhostT unit uses (pts_to_raw r p v0) (fun _ -> pts_to_raw r (half_perm p) v0 `star` pts_to_raw r (half_perm p) v0) = share_atomic_raw_gen r v0 (half_perm p) (half_perm p) let share_gen (#a:Type) (#uses:_) (#p:perm) (#v:erased a) (r:ref a) (p1 p2: perm) : SteelGhost unit uses (pts_to r p v) (fun _ -> pts_to r p1 v `star` pts_to r p2 v) (fun _ -> p == p1 `sum_perm` p2) (fun _ _ _ -> True) = let v_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, p)) in rewrite_slprop (pts_to r p v) (pts_to' r p v) (fun _ -> ()); elim_pure (perm_ok p); share_atomic_raw_gen r v p1 p2; intro_pts_to p1 r; intro_pts_to p2 r let share (#a:Type) #uses (#p:perm) (#v:erased a) (r:ref a) : SteelGhostT unit uses (pts_to r p v) (fun _ -> pts_to r (half_perm p) v `star` pts_to r (half_perm p) v) = share_gen r (half_perm p) (half_perm p) let gather_atomic_raw (#a:Type) (#uses:_) (#p0 #p1:perm) (r:ref a) (v0:erased a) (v1:erased a) : SteelGhostT (_:unit{v0==v1 /\ perm_ok (sum_perm p0 p1)}) uses (pts_to_raw r p0 v0 `star` pts_to_raw r p1 v1) (fun _ -> pts_to_raw r (sum_perm p0 p1) v0) = rewrite_slprop (pts_to_raw r p0 v0) (RP.pts_to r (Ghost.reveal (Some (Ghost.reveal v0, p0)))) (fun _ -> ()); rewrite_slprop (pts_to_raw r p1 v1) (RP.pts_to r (Ghost.reveal (Some (Ghost.reveal v1, p1)))) (fun _ -> ()); let _ = RP.gather r (Some (Ghost.reveal v0, p0)) (Some (Ghost.reveal v1, p1)) in rewrite_slprop (RP.pts_to r _) (pts_to_raw r (sum_perm p0 p1) v0) (fun _ -> ()) let gather (#a:Type) (#uses:_) (#p0:perm) (#p1:perm) (#v0 #v1:erased a) (r:ref a) = let v0_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v0, p0)) in let v1_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v1, p1)) in rewrite_slprop (pts_to r p0 v0) (pts_to_raw r p0 v0 `star` pure (perm_ok p0)) (fun _ -> ()); rewrite_slprop (pts_to r p1 v1) (pts_to_raw r p1 v1 `star` pure (perm_ok p1)) (fun _ -> ()); elim_pure (perm_ok p0); elim_pure (perm_ok p1); let _ = gather_atomic_raw r v0 v1 in intro_pts_to (sum_perm p0 p1) r let cas_provides #t (r:ref t) (v:Ghost.erased t) (v_new:t) (b:bool) = if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v let equiv_ext_right (p q r:slprop) : Lemma (requires q `Mem.equiv` r) (ensures Mem.((p `star` q) `equiv` (p `star` r))) = let open Steel.Memory in 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 cas_action_helper (p q r s:slprop) (m:mem) : Lemma (requires interp Mem.(p `star` q `star` r `star` s) m) (ensures interp Mem.(p `star` q `star` s) m) = let open Steel.Memory in calc (equiv) { r `star` s; (equiv) { star_commutative r s } s `star` r; }; calc (equiv) { p `star` q `star` r `star` s; (equiv) { Mem.star_associative (p `star` q) r s } (p `star` q) `star` (r `star` s); (equiv) { equiv_ext_right (p `star` q) (r `star` s) (s `star` r) } (p `star` q) `star` (s `star` r); (equiv) { star_associative (p `star` q) s r } (p `star` q `star` s) `star` r; }; assert (interp ((p `star` q `star` s) `star` r) m); affine_star (p `star` q `star` s) r m let cas_action (#t:Type) (eq: (x:t -> y:t -> b:bool{b <==> (x == y)})) (#uses:inames) (r:ref t) (v:Ghost.erased t) (v_old:t) (v_new:t) (fr:slprop) : MstTot (b:bool{b <==> (Ghost.reveal v == v_old)}) uses (pts_to_sl r full_perm v) (cas_provides r v v_new) fr (fun _ -> True) (fun _ _ _ -> True) = let m0 : full_mem = NMSTTotal.get () in let fv = Ghost.hide (Some (Ghost.reveal v, full_perm)) in let fv' = Some (v_new, full_perm) in assert (interp Mem.(pts_to_sl r full_perm v `star` fr `star` locks_invariant uses m0) m0); assert (interp Mem.(pts_to r fv `star` pure (perm_ok full_perm) `star` fr `star` locks_invariant uses m0) m0); cas_action_helper (Mem.pts_to r fv) (Mem.pure (perm_ok full_perm)) fr (locks_invariant uses m0) m0; assert (interp Mem.((pts_to r fv `star` pure (perm_ok full_perm)) `star` locks_invariant uses m0) m0); let fv_actual = Mem.frame (Mem.pure (perm_ok full_perm)) (sel_action uses r fv) fr in assert (compatible pcm_frac fv fv_actual); let Some (v', p) = fv_actual in assert (v == Ghost.hide v'); assert (p == full_perm); let b = if eq v' v_old then (Mem.frame (Mem.pure (perm_ok full_perm)) (upd_action uses r fv fv') fr; true) else false in b (*** GHOST REFERENCES ***) let ghost_ref a = erased (ref a) [@@__reduce__] let ghost_pts_to_sl #a (r:ghost_ref a) (p:perm) (x:a) = pts_to_sl (reveal r) p x let reveal_ghost_ref _ = () let reveal_ghost_pts_to_sl _ _ _ = () #push-options "--z3rlimit 20 --warn_error -271" let ghost_pts_to_witinv (#a:Type) (r:ghost_ref a) (p:perm) : Lemma (is_witness_invariant (ghost_pts_to_sl r p)) = let aux (x y : erased a) (m:mem) : Lemma (requires (interp (ghost_pts_to_sl r p x) m /\ interp (ghost_pts_to_sl r p y) m)) (ensures (x == y)) [SMTPat ()] = Mem.pts_to_join (Ghost.reveal r) (Some (Ghost.reveal x, p)) (Some (Ghost.reveal y, p)) m in assert (forall x y m. interp (ghost_pts_to_sl r p x) m /\ interp (ghost_pts_to_sl r p y) m ==> x == y); assert (is_witness_invariant (ghost_pts_to_sl r p)) #pop-options let ghost_alloc_aux (#a:Type) (#u:_) (x:a) : SteelGhostT (ref a) u emp (fun r -> pts_to r full_perm (Ghost.hide x)) = let v : fractional a = Some (x, full_perm) in assert (FStar.PCM.composable pcm_frac v None); assert (compatible pcm_frac v v); rewrite_slprop emp (to_vprop Mem.emp) (fun _ -> reveal_emp()); let r : ref a = as_atomic_action_ghost (Steel.Memory.alloc_action u v) in rewrite_slprop (RP.pts_to r v) (pts_to r full_perm x) (fun m -> emp_unit (hp_of (pts_to_raw r full_perm x)); pure_star_interp (hp_of (pts_to_raw r full_perm x)) (perm_ok full_perm) m); r let ghost_alloc x = let r = ghost_alloc_aux (reveal x) in hide r let ghost_free #a #u #v r = let v_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, full_perm)) in rewrite_slprop (pts_to r full_perm v) (RP.pts_to r v_old `star` pure (perm_ok full_perm)) (fun _ -> ()); elim_pure (perm_ok full_perm); as_atomic_action_ghost (free_action u r v_old); drop (RP.pts_to r (Mkpcm'?.one (Mkpcm?.p pcm_frac))) let ghost_share_gen r p1 p2 = share_gen (reveal r) p1 p2 let ghost_share r = share (reveal r) let ghost_gather r = gather (reveal r)
{ "checked_file": "/", "dependencies": [ "Steel.PCMReference.fsti.checked", "Steel.PCMFrac.fst.checked", "Steel.Memory.fsti.checked", "Steel.Effect.Atomic.fsti.checked", "Steel.Effect.fsti.checked", "prims.fst.checked", "FStar.Real.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked", "FStar.NMSTTotal.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Steel.HigherReference.fst" }
[ { "abbrev": true, "full_module": "Steel.Memory", "short_module": "Mem" }, { "abbrev": true, "full_module": "Steel.PCMReference", "short_module": "RP" }, { "abbrev": false, "full_module": "FStar.Real", "short_module": null }, { "abbrev": false, "full_module": "Steel.PCMFrac", "short_module": null }, { "abbrev": false, "full_module": "FStar.PCM", "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": "FStar.Ghost", "short_module": null }, { "abbrev": true, "full_module": "Steel.Memory", "short_module": "Mem" }, { "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": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "Steel.FractionalPermission", "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
r: Steel.HigherReference.ghost_ref a -> v0: FStar.Ghost.erased a -> v1: FStar.Ghost.erased a -> Steel.Effect.Atomic.SteelGhost Prims.unit
Steel.Effect.Atomic.SteelGhost
[]
[]
[ "Steel.Memory.inames", "Steel.FractionalPermission.perm", "Steel.HigherReference.ghost_ref", "FStar.Ghost.erased", "Steel.HigherReference.higher_ref_pts_to_injective_eq", "FStar.Ghost.reveal", "Steel.HigherReference.ref", "Prims.unit" ]
[]
false
true
false
false
false
let ghost_pts_to_injective_eq #_ #_ #p0 #p1 r v0 v1 =
higher_ref_pts_to_injective_eq #_ #_ #p0 #p1 #v0 #v1 (reveal r)
false
SteelFramingTestSuite.fst
SteelFramingTestSuite.test_if10
val test_if10 (b: bool) (r1 r2 r3: ref) : SteelT unit (((ptr r1) `star` (ptr r2)) `star` (ptr r3)) (fun _ -> ((ptr r1) `star` (ptr r2)) `star` (ptr r3))
val test_if10 (b: bool) (r1 r2 r3: ref) : SteelT unit (((ptr r1) `star` (ptr r2)) `star` (ptr r3)) (fun _ -> ((ptr r1) `star` (ptr r2)) `star` (ptr r3))
let test_if10 (b:bool) (r1 r2 r3: ref) : SteelT unit (ptr r1 `star` ptr r2 `star` ptr r3) (fun _ -> ptr r1 `star` ptr r2 `star` ptr r3) = if b then (write r1 0; write r2 0) else (write r2 0; write r1 0); write r2 0
{ "file_name": "share/steel/tests/SteelFramingTestSuite.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 14, "end_line": 161, "start_col": 0, "start_line": 157 }
(* 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 SteelFramingTestSuite open Steel.Memory open Steel.Effect /// A collection of small unit tests for the framing tactic assume val p : vprop assume val f (x:int) : SteelT unit p (fun _ -> p) let test () : SteelT unit (p `star` p `star` p) (fun _ -> p `star` p `star` p) = f 0; () assume val ref : Type0 assume val ptr (_:ref) : vprop assume val alloc (x:int) : SteelT ref emp (fun y -> ptr y) assume val free (r:ref) : SteelT unit (ptr r) (fun _ -> emp) assume val read (r:ref) : SteelT int (ptr r) (fun _ -> ptr r) assume val write (r:ref) (v: int) : SteelT unit (ptr r) (fun _ -> ptr r) let unused x = x // work around another gensym heisenbug let test0 (b1 b2 b3: ref) : SteelT int (ptr b1 `star` ptr b2 `star` ptr b3) (fun _ -> ptr b1 `star` ptr b2 `star` ptr b3) = let x = read b1 in x let test1 (b1 b2 b3: ref) : SteelT int (ptr b1 `star` ptr b2 `star` ptr b3) (fun _ -> ptr b1 `star` ptr b2 `star` ptr b3) = let x = (let y = read b1 in y) in x let test2 (b1 b2 b3: ref) : SteelT int (ptr b1 `star` ptr b2 `star` ptr b3) (fun _ -> ptr b3 `star` ptr b2 `star` ptr b1) = let x = read b1 in x let test3 (b1 b2 b3: ref) : SteelT int (ptr b1 `star` ptr b2 `star` ptr b3) (fun _ -> ptr b2 `star` ptr b1 `star` ptr b3) = let x = read b3 in x let test4 (b1 b2 b3: ref) : SteelT unit (ptr b1 `star` ptr b2 `star` ptr b3) (fun _ -> ptr b2 `star` ptr b1 `star` ptr b3) = let x = read b3 in write b2 x let test5 (b1 b2 b3: ref) : SteelT unit (ptr b1 `star` ptr b2 `star` ptr b3) (fun _ -> ptr b2 `star` ptr b1 `star` ptr b3) = let x = read b3 in write b2 (x + 1) let test6 (b1 b2 b3: ref) : SteelT unit (ptr b1 `star` ptr b2 `star` ptr b3) (fun _ -> ptr b2 `star` ptr b1 `star` ptr b3) = let x = read b3 in let b4 = alloc x in write b2 (x + 1); free b4 // With the formalism relying on can_be_split_post, this example fails if we normalize return_pre eqs goals before unification // When solving this equality, we have the goal // (*?u19*) _ _ == return_pre ((fun x -> (fun x -> (*?u758*) _ x x) x) r) // with x and r in the context of ?u19 // Not normalizing allows us to solve it as a function applied to x and r // Normalizing would lead to solve it to an slprop with x and r in the context, // but which would later fail when trying to prove the equivalence with (fun r -> ptr r) // in the postcondition let test7 (_:unit) : SteelT ref emp ptr = let r = alloc 0 in let x = read r in write r 0; r let test8 (b1 b2 b3:ref) : SteelT unit (ptr b1 `star` ptr b2 `star` ptr b3) (fun _ -> ptr b2 `star` ptr b1 `star` ptr b3) = write b2 0 open Steel.Effect.Atomic let test_if1 (b:bool) : SteelT unit emp (fun _ -> emp) = if b then noop () else noop () let test_if2 (b:bool) (r: ref) : SteelT unit (ptr r) (fun _ -> ptr r) = if b then write r 0 else write r 1 let test_if3 (b:bool) (r:ref) : SteelT unit (ptr r) (fun _ -> ptr r) = if b then noop () else noop () let test_if4 (b:bool) : SteelT unit emp (fun _ -> emp) = if b then (let r = alloc 0 in free r) else (noop ()) let test_if5 (b:bool) : SteelT ref emp (fun r -> ptr r) = if b then alloc 0 else alloc 1 let test_if6 (b:bool) : SteelT ref emp (fun r -> ptr r) = let r = if b then alloc 0 else alloc 1 in let x = read r in write r 0; r (* First test with different (but equivalent) slprops in both branches *) let test_if7 (b:bool) (r1 r2: ref) : SteelT unit (ptr r1 `star` ptr r2) (fun _ -> ptr r1 `star` ptr r2) = if b then (write r1 0; write r2 0) else (write r2 0; write r1 0); write r2 0 (* Test with different slprops in both branches. The second branch captures the outer frame in its context *) let test_if8 (b:bool) (r1 r2: ref) : SteelT unit (ptr r1 `star` ptr r2) (fun _ -> ptr r1 `star` ptr r2) = if b then (write r1 0; write r2 0) else (write r2 0); write r2 0 let test_if9 (b:bool) (r1 r2: ref) : SteelT unit (ptr r1 `star` ptr r2) (fun _ -> ptr r1 `star` ptr r2) = write r1 0; if b then (write r1 0) else (write r2 0); write r2 0; if b then (write r1 0) else (write r2 0); write r1 0
{ "checked_file": "/", "dependencies": [ "Steel.Memory.fsti.checked", "Steel.Effect.Atomic.fsti.checked", "Steel.Effect.fsti.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "SteelFramingTestSuite.fst" }
[ { "abbrev": false, "full_module": "Steel.Effect.Atomic", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect", "short_module": null }, { "abbrev": false, "full_module": "Steel.Memory", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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: Prims.bool -> r1: SteelFramingTestSuite.ref -> r2: SteelFramingTestSuite.ref -> r3: SteelFramingTestSuite.ref -> Steel.Effect.SteelT Prims.unit
Steel.Effect.SteelT
[]
[]
[ "Prims.bool", "SteelFramingTestSuite.ref", "SteelFramingTestSuite.write", "Prims.unit", "Steel.Effect.Common.star", "SteelFramingTestSuite.ptr", "Steel.Effect.Common.vprop" ]
[]
false
true
false
false
false
let test_if10 (b: bool) (r1 r2 r3: ref) : SteelT unit (((ptr r1) `star` (ptr r2)) `star` (ptr r3)) (fun _ -> ((ptr r1) `star` (ptr r2)) `star` (ptr r3)) =
if b then (write r1 0; write r2 0) else (write r2 0; write r1 0); write r2 0
false
Steel.HigherReference.fst
Steel.HigherReference.ghost_alloc
val ghost_alloc (#a:Type) (#u:_) (x:erased a) : SteelGhostT (ghost_ref a) u emp (fun r -> ghost_pts_to r full_perm x)
val ghost_alloc (#a:Type) (#u:_) (x:erased a) : SteelGhostT (ghost_ref a) u emp (fun r -> ghost_pts_to r full_perm x)
let ghost_alloc x = let r = ghost_alloc_aux (reveal x) in hide r
{ "file_name": "lib/steel/Steel.HigherReference.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 8, "end_line": 427, "start_col": 0, "start_line": 425 }
(* 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.HigherReference open FStar.Ghost open Steel.Memory open Steel.Effect.Atomic open Steel.Effect open FStar.PCM open Steel.PCMFrac open FStar.Real module RP = Steel.PCMReference #set-options "--ide_id_info_off" module Mem = Steel.Memory let ref a = Mem.ref (fractional a) pcm_frac let null #a = Mem.null #(fractional a) #pcm_frac let is_null #a r = Mem.is_null #(fractional a) #pcm_frac r let perm_ok p : prop = (p.v <=. one == true) /\ True let pts_to_raw_sl (#a:Type) (r:ref a) (p:perm) (v:erased a) : slprop = Mem.pts_to r (Some (Ghost.reveal v, p)) let pts_to_raw (#a:Type) (r:ref a) (p:perm) (v:erased a) : vprop = to_vprop (Mem.pts_to r (Some (Ghost.reveal v, p))) [@@__reduce__] let pts_to' (#a:Type u#1) (r:ref a) (p:perm) (v:erased a) : vprop = pts_to_raw r p v `star` pure (perm_ok p) let pts_to_sl #a r p v = hp_of (pts_to' r p v) let abcd_acbd (a b c d:slprop) : Lemma (Mem.(((a `star` b) `star` (c `star` d)) `equiv` ((a `star` c) `star` (b `star` d)))) = let open Steel.Memory in calc (equiv) { ((a `star` b) `star` (c `star` d)); (equiv) { star_associative a b (c `star` d) } ((a `star` (b `star` (c `star` d)))); (equiv) { star_associative b c d; star_congruence a (b `star` (c `star` d)) a ((b `star` c) `star` d) } (a `star` ((b `star` c) `star` d)); (equiv) { star_commutative b c; star_congruence (b `star` c) d (c `star` b) d; star_congruence a ((b `star` c) `star` d) a ((c `star` b) `star` d) } (a `star` ((c `star` b) `star` d)); (equiv) { star_associative c b d; star_congruence a ((c `star` b) `star` d) a (c `star` (b `star` d)) } (a `star` (c `star` (b `star` d))); (equiv) { star_associative a c (b `star` d) } ((a `star` c) `star` (b `star` d)); } let pts_to_ref_injective (#a: Type u#1) (r: ref a) (p0 p1:perm) (v0 v1:a) (m:mem) : Lemma (requires interp (pts_to_sl r p0 v0 `Mem.star` pts_to_sl r p1 v1) m) (ensures v0 == v1) = let open Steel.Memory in abcd_acbd (hp_of (pts_to_raw r p0 v0)) (pure (perm_ok p0)) (hp_of (pts_to_raw r p1 v1)) (pure (perm_ok p1)); Mem.affine_star (hp_of (pts_to_raw r p0 v0) `star` hp_of (pts_to_raw r p1 v1)) (pure (perm_ok p0) `star` pure (perm_ok p1)) m; Mem.pts_to_compatible r (Some (Ghost.reveal v0, p0)) (Some (Ghost.reveal v1, p1)) m let pts_to_not_null (#a:Type u#1) (r:ref a) (p:perm) (v:a) (m:mem) : Lemma (requires interp (pts_to_sl r p v) m) (ensures r =!= null) = Mem.affine_star (hp_of (pts_to_raw r p v)) (Mem.pure (perm_ok p)) m; Mem.pts_to_not_null r (Some (Ghost.reveal v, p)) m let pts_to_witinv (#a:Type) (r:ref a) (p:perm) : Lemma (is_witness_invariant (pts_to_sl r p)) = let aux (x y : erased a) (m:mem) : Lemma (requires (interp (pts_to_sl r p x) m /\ interp (pts_to_sl r p y) m)) (ensures (x == y)) = Mem.pts_to_join r (Some (Ghost.reveal x, p)) (Some (Ghost.reveal y, p)) m in Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y)) let higher_ref_pts_to_injective_eq #a #opened #p0 #p1 #v0 #v1 r = extract_info_raw (pts_to r p0 v0 `star` pts_to r p1 v1) (v0 == v1) (fun m -> pts_to_ref_injective r p0 p1 v0 v1 m); rewrite_slprop (pts_to r p1 v1) (pts_to r p1 v0) (fun _ -> ()) let pts_to_framon (#a:Type) (r:ref a) (p:perm) : Lemma (is_frame_monotonic (pts_to_sl r p)) = pts_to_witinv r p let intro_pts_to (p:perm) #a #uses (#v:erased a) (r:ref a) : SteelGhost unit uses (pts_to_raw r p v) (fun _ -> pts_to r p v) (requires fun _ -> perm_ok p) (ensures fun _ _ _ -> True) = intro_pure (perm_ok p); rewrite_slprop (pts_to' r p v) (pts_to r p v) (fun _ -> ()) let pts_to_perm #_ #_ #p #v r = rewrite_slprop (pts_to r p v) (pts_to' r p v) (fun _ -> ()); elim_pure (perm_ok p); intro_pure (perm_ok p); rewrite_slprop (pts_to' r p v) (pts_to r p v) (fun _ -> ()) let alloc #a x = let v = Some (x, full_perm) in assert (FStar.PCM.composable pcm_frac v None); assert (compatible pcm_frac v v); let r = RP.alloc v in rewrite_slprop (RP.pts_to r v) (pts_to r full_perm x) (fun m -> emp_unit (hp_of (pts_to_raw r full_perm x)); pure_star_interp (hp_of (pts_to_raw r full_perm x)) (perm_ok full_perm) m ); extract_info_raw (pts_to r full_perm x) (~ (is_null r)) (fun m -> pts_to_not_null r full_perm x m); return r let read (#a:Type) (#p:perm) (#v:erased a) (r:ref a) = let v1 : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, p)) in rewrite_slprop (pts_to r p v) (RP.pts_to r v1 `star` pure (perm_ok p)) (fun _ -> ()); elim_pure (perm_ok p); let v2 = RP.read r v1 in rewrite_slprop (RP.pts_to r v1) (pts_to r p v) (fun m -> emp_unit (hp_of (pts_to_raw r p v)); pure_star_interp (hp_of (pts_to_raw r p v)) (perm_ok p) m); assert (compatible pcm_frac v1 v2); let Some (x, _) = v2 in rewrite_slprop (pts_to r p v) (pts_to r p x) (fun _ -> ()); return x let atomic_read (#opened:_) (#a:Type) (#p:perm) (#v:erased a) (r:ref a) = let v1 : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, p)) in rewrite_slprop (pts_to r p v) (RP.pts_to r v1 `star` pure (perm_ok p)) (fun _ -> ()); elim_pure (perm_ok p); let v2 = RP.atomic_read r v1 in rewrite_slprop (RP.pts_to r v1) (pts_to r p v) (fun m -> emp_unit (hp_of (pts_to_raw r p v)); pure_star_interp (hp_of (pts_to_raw r p v)) (perm_ok p) m); assert (compatible pcm_frac v1 v2); let Some (x, _) = v2 in rewrite_slprop (pts_to r p v) (pts_to r p x) (fun _ -> ()); return x let read_refine (#a:Type) (#p:perm) (q:a -> vprop) (r:ref a) : SteelT a (h_exists (fun (v:a) -> pts_to r p v `star` q v)) (fun v -> pts_to r p v `star` q v) = let vs:erased a = witness_exists () in rewrite_slprop (pts_to r p (Ghost.hide (Ghost.reveal vs))) (pts_to r p vs) (fun _ -> ()); let v = read r in rewrite_slprop (q vs) (q v) (fun _ -> ()); return v let write (#a:Type) (#v:erased a) (r:ref a) (x:a) : SteelT unit (pts_to r full_perm v) (fun _ -> pts_to r full_perm x) = let v_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, full_perm)) in let v_new : fractional a = Some (x, full_perm) in rewrite_slprop (pts_to r full_perm v) (RP.pts_to r v_old `star` pure (perm_ok full_perm)) (fun _ -> ()); elim_pure (perm_ok full_perm); RP.write r v_old v_new; rewrite_slprop (RP.pts_to r v_new) (pts_to r full_perm x) (fun m -> emp_unit (hp_of (pts_to_raw r full_perm x)); pure_star_interp (hp_of (pts_to_raw r full_perm x)) (perm_ok full_perm) m) let atomic_write #opened #a #v r x = let v_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, full_perm)) in let v_new : fractional a = Some (x, full_perm) in rewrite_slprop (pts_to r full_perm v) (RP.pts_to r v_old `star` pure (perm_ok full_perm)) (fun _ -> ()); elim_pure (perm_ok full_perm); RP.atomic_write r v_old v_new; rewrite_slprop (RP.pts_to r v_new) (pts_to r full_perm x) (fun m -> emp_unit (hp_of (pts_to_raw r full_perm x)); pure_star_interp (hp_of (pts_to_raw r full_perm x)) (perm_ok full_perm) m) let free (#a:Type) (#v:erased a) (r:ref a) : SteelT unit (pts_to r full_perm v) (fun _ -> emp) = let v_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, full_perm)) in rewrite_slprop (pts_to r full_perm v) (RP.pts_to r v_old `star` pure (perm_ok full_perm)) (fun _ -> ()); elim_pure (perm_ok full_perm); RP.free r v_old; drop (RP.pts_to r (Mkpcm'?.one (Mkpcm?.p pcm_frac))) let share_atomic_raw_gen #a #uses (#p:perm) (r:ref a{perm_ok p}) (v0:erased a) (p1 p2: perm) : SteelGhost unit uses (pts_to_raw r p v0) (fun _ -> pts_to_raw r p1 v0 `star` pts_to_raw r p2 v0) (fun _ -> p == p1 `sum_perm` p2) (fun _ _ _ -> True) = rewrite_slprop (pts_to_raw r p v0) (RP.pts_to r _) (fun _ -> ()); RP.split r (Some (Ghost.reveal v0, p)) (Some (Ghost.reveal v0, p1)) (Some (Ghost.reveal v0, p2)); rewrite_slprop (RP.pts_to r _) (pts_to_raw r p1 v0) (fun _ -> ()); rewrite_slprop (RP.pts_to r _) (pts_to_raw r p2 v0) (fun _ -> ()) let share_atomic_raw #a #uses (#p:perm) (r:ref a{perm_ok p}) (v0:erased a) : SteelGhostT unit uses (pts_to_raw r p v0) (fun _ -> pts_to_raw r (half_perm p) v0 `star` pts_to_raw r (half_perm p) v0) = share_atomic_raw_gen r v0 (half_perm p) (half_perm p) let share_gen (#a:Type) (#uses:_) (#p:perm) (#v:erased a) (r:ref a) (p1 p2: perm) : SteelGhost unit uses (pts_to r p v) (fun _ -> pts_to r p1 v `star` pts_to r p2 v) (fun _ -> p == p1 `sum_perm` p2) (fun _ _ _ -> True) = let v_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v, p)) in rewrite_slprop (pts_to r p v) (pts_to' r p v) (fun _ -> ()); elim_pure (perm_ok p); share_atomic_raw_gen r v p1 p2; intro_pts_to p1 r; intro_pts_to p2 r let share (#a:Type) #uses (#p:perm) (#v:erased a) (r:ref a) : SteelGhostT unit uses (pts_to r p v) (fun _ -> pts_to r (half_perm p) v `star` pts_to r (half_perm p) v) = share_gen r (half_perm p) (half_perm p) let gather_atomic_raw (#a:Type) (#uses:_) (#p0 #p1:perm) (r:ref a) (v0:erased a) (v1:erased a) : SteelGhostT (_:unit{v0==v1 /\ perm_ok (sum_perm p0 p1)}) uses (pts_to_raw r p0 v0 `star` pts_to_raw r p1 v1) (fun _ -> pts_to_raw r (sum_perm p0 p1) v0) = rewrite_slprop (pts_to_raw r p0 v0) (RP.pts_to r (Ghost.reveal (Some (Ghost.reveal v0, p0)))) (fun _ -> ()); rewrite_slprop (pts_to_raw r p1 v1) (RP.pts_to r (Ghost.reveal (Some (Ghost.reveal v1, p1)))) (fun _ -> ()); let _ = RP.gather r (Some (Ghost.reveal v0, p0)) (Some (Ghost.reveal v1, p1)) in rewrite_slprop (RP.pts_to r _) (pts_to_raw r (sum_perm p0 p1) v0) (fun _ -> ()) let gather (#a:Type) (#uses:_) (#p0:perm) (#p1:perm) (#v0 #v1:erased a) (r:ref a) = let v0_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v0, p0)) in let v1_old : erased (fractional a) = Ghost.hide (Some (Ghost.reveal v1, p1)) in rewrite_slprop (pts_to r p0 v0) (pts_to_raw r p0 v0 `star` pure (perm_ok p0)) (fun _ -> ()); rewrite_slprop (pts_to r p1 v1) (pts_to_raw r p1 v1 `star` pure (perm_ok p1)) (fun _ -> ()); elim_pure (perm_ok p0); elim_pure (perm_ok p1); let _ = gather_atomic_raw r v0 v1 in intro_pts_to (sum_perm p0 p1) r let cas_provides #t (r:ref t) (v:Ghost.erased t) (v_new:t) (b:bool) = if b then pts_to_sl r full_perm v_new else pts_to_sl r full_perm v let equiv_ext_right (p q r:slprop) : Lemma (requires q `Mem.equiv` r) (ensures Mem.((p `star` q) `equiv` (p `star` r))) = let open Steel.Memory in 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 cas_action_helper (p q r s:slprop) (m:mem) : Lemma (requires interp Mem.(p `star` q `star` r `star` s) m) (ensures interp Mem.(p `star` q `star` s) m) = let open Steel.Memory in calc (equiv) { r `star` s; (equiv) { star_commutative r s } s `star` r; }; calc (equiv) { p `star` q `star` r `star` s; (equiv) { Mem.star_associative (p `star` q) r s } (p `star` q) `star` (r `star` s); (equiv) { equiv_ext_right (p `star` q) (r `star` s) (s `star` r) } (p `star` q) `star` (s `star` r); (equiv) { star_associative (p `star` q) s r } (p `star` q `star` s) `star` r; }; assert (interp ((p `star` q `star` s) `star` r) m); affine_star (p `star` q `star` s) r m let cas_action (#t:Type) (eq: (x:t -> y:t -> b:bool{b <==> (x == y)})) (#uses:inames) (r:ref t) (v:Ghost.erased t) (v_old:t) (v_new:t) (fr:slprop) : MstTot (b:bool{b <==> (Ghost.reveal v == v_old)}) uses (pts_to_sl r full_perm v) (cas_provides r v v_new) fr (fun _ -> True) (fun _ _ _ -> True) = let m0 : full_mem = NMSTTotal.get () in let fv = Ghost.hide (Some (Ghost.reveal v, full_perm)) in let fv' = Some (v_new, full_perm) in assert (interp Mem.(pts_to_sl r full_perm v `star` fr `star` locks_invariant uses m0) m0); assert (interp Mem.(pts_to r fv `star` pure (perm_ok full_perm) `star` fr `star` locks_invariant uses m0) m0); cas_action_helper (Mem.pts_to r fv) (Mem.pure (perm_ok full_perm)) fr (locks_invariant uses m0) m0; assert (interp Mem.((pts_to r fv `star` pure (perm_ok full_perm)) `star` locks_invariant uses m0) m0); let fv_actual = Mem.frame (Mem.pure (perm_ok full_perm)) (sel_action uses r fv) fr in assert (compatible pcm_frac fv fv_actual); let Some (v', p) = fv_actual in assert (v == Ghost.hide v'); assert (p == full_perm); let b = if eq v' v_old then (Mem.frame (Mem.pure (perm_ok full_perm)) (upd_action uses r fv fv') fr; true) else false in b (*** GHOST REFERENCES ***) let ghost_ref a = erased (ref a) [@@__reduce__] let ghost_pts_to_sl #a (r:ghost_ref a) (p:perm) (x:a) = pts_to_sl (reveal r) p x let reveal_ghost_ref _ = () let reveal_ghost_pts_to_sl _ _ _ = () #push-options "--z3rlimit 20 --warn_error -271" let ghost_pts_to_witinv (#a:Type) (r:ghost_ref a) (p:perm) : Lemma (is_witness_invariant (ghost_pts_to_sl r p)) = let aux (x y : erased a) (m:mem) : Lemma (requires (interp (ghost_pts_to_sl r p x) m /\ interp (ghost_pts_to_sl r p y) m)) (ensures (x == y)) [SMTPat ()] = Mem.pts_to_join (Ghost.reveal r) (Some (Ghost.reveal x, p)) (Some (Ghost.reveal y, p)) m in assert (forall x y m. interp (ghost_pts_to_sl r p x) m /\ interp (ghost_pts_to_sl r p y) m ==> x == y); assert (is_witness_invariant (ghost_pts_to_sl r p)) #pop-options let ghost_alloc_aux (#a:Type) (#u:_) (x:a) : SteelGhostT (ref a) u emp (fun r -> pts_to r full_perm (Ghost.hide x)) = let v : fractional a = Some (x, full_perm) in assert (FStar.PCM.composable pcm_frac v None); assert (compatible pcm_frac v v); rewrite_slprop emp (to_vprop Mem.emp) (fun _ -> reveal_emp()); let r : ref a = as_atomic_action_ghost (Steel.Memory.alloc_action u v) in rewrite_slprop (RP.pts_to r v) (pts_to r full_perm x) (fun m -> emp_unit (hp_of (pts_to_raw r full_perm x)); pure_star_interp (hp_of (pts_to_raw r full_perm x)) (perm_ok full_perm) m); r
{ "checked_file": "/", "dependencies": [ "Steel.PCMReference.fsti.checked", "Steel.PCMFrac.fst.checked", "Steel.Memory.fsti.checked", "Steel.Effect.Atomic.fsti.checked", "Steel.Effect.fsti.checked", "prims.fst.checked", "FStar.Real.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked", "FStar.NMSTTotal.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Steel.HigherReference.fst" }
[ { "abbrev": true, "full_module": "Steel.Memory", "short_module": "Mem" }, { "abbrev": true, "full_module": "Steel.PCMReference", "short_module": "RP" }, { "abbrev": false, "full_module": "FStar.Real", "short_module": null }, { "abbrev": false, "full_module": "Steel.PCMFrac", "short_module": null }, { "abbrev": false, "full_module": "FStar.PCM", "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": "FStar.Ghost", "short_module": null }, { "abbrev": true, "full_module": "Steel.Memory", "short_module": "Mem" }, { "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": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "Steel.FractionalPermission", "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
x: FStar.Ghost.erased a -> Steel.Effect.Atomic.SteelGhostT (Steel.HigherReference.ghost_ref a)
Steel.Effect.Atomic.SteelGhostT
[]
[]
[ "Steel.Memory.inames", "FStar.Ghost.erased", "FStar.Ghost.hide", "Steel.HigherReference.ref", "Steel.HigherReference.ghost_ref", "Steel.HigherReference.ghost_alloc_aux", "FStar.Ghost.reveal" ]
[]
false
true
false
false
false
let ghost_alloc x =
let r = ghost_alloc_aux (reveal x) in hide r
false
DoublyLinkedListIface.fst
DoublyLinkedListIface.node
val node (a:Type0) : Type0
val node (a:Type0) : Type0
let node a = B.pointer (DLL.node a)
{ "file_name": "examples/doublylinkedlist/DoublyLinkedListIface.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 35, "end_line": 48, "start_col": 0, "start_line": 48 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module DoublyLinkedListIface /// This module consists of proofs / code for the iface that is /// written in the actual fsti. Most of this code will never be user /// facing, and will soon be merged into the DoublyLinkedList module, /// as I work on moving stuff into DoublyLinkedList.fsti from the iface /// fsti. module DLL = DoublyLinkedList module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module G = FStar.Ghost module L = FStar.List.Pure module B = LowStar.Buffer open LowStar.BufferOps /// Convenience operators unfold let (@) (a:B.pointer 't) (h0:HS.mem) = B.get h0 a 0 unfold let (^@) (a:B.pointer_or_null 't{a =!= B.null}) (h0:HS.mem) = B.get h0 a 0 /// Abstract types defined by this library /// /// Note: Somehow confusingly, a node in the iface is a pointer to a /// real node, and a dll in the iface is a pointer to a real /// dll. Fortunately though, most users of the library will never even /// be looking inside the implementation, and thus hopefully it won't /// be confusing.
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "DoublyLinkedList.fst.checked" ], "interface_file": true, "source_file": "DoublyLinkedListIface.fst" }
[ { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": true, "full_module": "FStar.List.Pure", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "DoublyLinkedList", "short_module": "DLL" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Type0 -> Type0
Prims.Tot
[ "total" ]
[]
[ "LowStar.Buffer.pointer", "DoublyLinkedList.node" ]
[]
false
false
false
true
true
let node a =
B.pointer (DLL.node a)
false
DoublyLinkedListIface.fst
DoublyLinkedListIface.dll
val dll (a:Type0) : Type0
val dll (a:Type0) : Type0
let dll a = B.pointer (DLL.dll a)
{ "file_name": "examples/doublylinkedlist/DoublyLinkedListIface.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 33, "end_line": 49, "start_col": 0, "start_line": 49 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module DoublyLinkedListIface /// This module consists of proofs / code for the iface that is /// written in the actual fsti. Most of this code will never be user /// facing, and will soon be merged into the DoublyLinkedList module, /// as I work on moving stuff into DoublyLinkedList.fsti from the iface /// fsti. module DLL = DoublyLinkedList module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module G = FStar.Ghost module L = FStar.List.Pure module B = LowStar.Buffer open LowStar.BufferOps /// Convenience operators unfold let (@) (a:B.pointer 't) (h0:HS.mem) = B.get h0 a 0 unfold let (^@) (a:B.pointer_or_null 't{a =!= B.null}) (h0:HS.mem) = B.get h0 a 0 /// Abstract types defined by this library /// /// Note: Somehow confusingly, a node in the iface is a pointer to a /// real node, and a dll in the iface is a pointer to a real /// dll. Fortunately though, most users of the library will never even /// be looking inside the implementation, and thus hopefully it won't /// be confusing.
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "DoublyLinkedList.fst.checked" ], "interface_file": true, "source_file": "DoublyLinkedListIface.fst" }
[ { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": true, "full_module": "FStar.List.Pure", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "DoublyLinkedList", "short_module": "DLL" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Type0 -> Type0
Prims.Tot
[ "total" ]
[]
[ "LowStar.Buffer.pointer", "DoublyLinkedList.dll" ]
[]
false
false
false
true
true
let dll a =
B.pointer (DLL.dll a)
false
DoublyLinkedListIface.fst
DoublyLinkedListIface.dll_valid
val dll_valid (h:HS.mem) (d:dll 'a) : prop
val dll_valid (h:HS.mem) (d:dll 'a) : prop
let dll_valid h d = B.live h d /\ DLL.dll_valid h (d@h) /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 (d@h)
{ "file_name": "examples/doublylinkedlist/DoublyLinkedListIface.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 51, "end_line": 58, "start_col": 0, "start_line": 55 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module DoublyLinkedListIface /// This module consists of proofs / code for the iface that is /// written in the actual fsti. Most of this code will never be user /// facing, and will soon be merged into the DoublyLinkedList module, /// as I work on moving stuff into DoublyLinkedList.fsti from the iface /// fsti. module DLL = DoublyLinkedList module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module G = FStar.Ghost module L = FStar.List.Pure module B = LowStar.Buffer open LowStar.BufferOps /// Convenience operators unfold let (@) (a:B.pointer 't) (h0:HS.mem) = B.get h0 a 0 unfold let (^@) (a:B.pointer_or_null 't{a =!= B.null}) (h0:HS.mem) = B.get h0 a 0 /// Abstract types defined by this library /// /// Note: Somehow confusingly, a node in the iface is a pointer to a /// real node, and a dll in the iface is a pointer to a real /// dll. Fortunately though, most users of the library will never even /// be looking inside the implementation, and thus hopefully it won't /// be confusing. let node a = B.pointer (DLL.node a) let dll a = B.pointer (DLL.dll a) /// Abstract Validity Predicates let node_valid h n = True /\ B.live h n // XXX: why do I need the True here?
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "DoublyLinkedList.fst.checked" ], "interface_file": true, "source_file": "DoublyLinkedListIface.fst" }
[ { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": true, "full_module": "FStar.List.Pure", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "DoublyLinkedList", "short_module": "DLL" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
h: FStar.Monotonic.HyperStack.mem -> d: DoublyLinkedListIface.dll 'a -> Prims.prop
Prims.Tot
[ "total" ]
[]
[ "FStar.Monotonic.HyperStack.mem", "DoublyLinkedListIface.dll", "Prims.l_and", "LowStar.Monotonic.Buffer.live", "DoublyLinkedList.dll", "LowStar.Buffer.trivial_preorder", "DoublyLinkedList.dll_valid", "DoublyLinkedListIface.op_At", "LowStar.Monotonic.Buffer.loc_disjoint", "LowStar.Monotonic.Buffer.loc_buffer", "DoublyLinkedList.dll_fp0", "Prims.prop" ]
[]
false
false
false
true
true
let dll_valid h d =
B.live h d /\ DLL.dll_valid h (d @ h) /\ (B.loc_buffer d) `B.loc_disjoint` (DLL.dll_fp0 (d @ h))
false
DoublyLinkedListIface.fst
DoublyLinkedListIface.node_valid
val node_valid (h:HS.mem) (n:node 'a) : prop
val node_valid (h:HS.mem) (n:node 'a) : prop
let node_valid h n = True /\ B.live h n
{ "file_name": "examples/doublylinkedlist/DoublyLinkedListIface.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 39, "end_line": 53, "start_col": 0, "start_line": 53 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module DoublyLinkedListIface /// This module consists of proofs / code for the iface that is /// written in the actual fsti. Most of this code will never be user /// facing, and will soon be merged into the DoublyLinkedList module, /// as I work on moving stuff into DoublyLinkedList.fsti from the iface /// fsti. module DLL = DoublyLinkedList module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module G = FStar.Ghost module L = FStar.List.Pure module B = LowStar.Buffer open LowStar.BufferOps /// Convenience operators unfold let (@) (a:B.pointer 't) (h0:HS.mem) = B.get h0 a 0 unfold let (^@) (a:B.pointer_or_null 't{a =!= B.null}) (h0:HS.mem) = B.get h0 a 0 /// Abstract types defined by this library /// /// Note: Somehow confusingly, a node in the iface is a pointer to a /// real node, and a dll in the iface is a pointer to a real /// dll. Fortunately though, most users of the library will never even /// be looking inside the implementation, and thus hopefully it won't /// be confusing. let node a = B.pointer (DLL.node a) let dll a = B.pointer (DLL.dll a) /// Abstract Validity Predicates
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "DoublyLinkedList.fst.checked" ], "interface_file": true, "source_file": "DoublyLinkedListIface.fst" }
[ { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": true, "full_module": "FStar.List.Pure", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "DoublyLinkedList", "short_module": "DLL" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
h: FStar.Monotonic.HyperStack.mem -> n: DoublyLinkedListIface.node 'a -> Prims.prop
Prims.Tot
[ "total" ]
[]
[ "FStar.Monotonic.HyperStack.mem", "DoublyLinkedListIface.node", "Prims.l_and", "Prims.l_True", "LowStar.Monotonic.Buffer.live", "DoublyLinkedList.node", "LowStar.Buffer.trivial_preorder", "Prims.prop" ]
[]
false
false
false
true
true
let node_valid h n =
True /\ B.live h n
false
DoublyLinkedListIface.fst
DoublyLinkedListIface.fp_node
val fp_node (n:node 'a) : GTot B.loc
val fp_node (n:node 'a) : GTot B.loc
let fp_node n = B.loc_buffer n
{ "file_name": "examples/doublylinkedlist/DoublyLinkedListIface.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 30, "end_line": 62, "start_col": 0, "start_line": 62 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module DoublyLinkedListIface /// This module consists of proofs / code for the iface that is /// written in the actual fsti. Most of this code will never be user /// facing, and will soon be merged into the DoublyLinkedList module, /// as I work on moving stuff into DoublyLinkedList.fsti from the iface /// fsti. module DLL = DoublyLinkedList module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module G = FStar.Ghost module L = FStar.List.Pure module B = LowStar.Buffer open LowStar.BufferOps /// Convenience operators unfold let (@) (a:B.pointer 't) (h0:HS.mem) = B.get h0 a 0 unfold let (^@) (a:B.pointer_or_null 't{a =!= B.null}) (h0:HS.mem) = B.get h0 a 0 /// Abstract types defined by this library /// /// Note: Somehow confusingly, a node in the iface is a pointer to a /// real node, and a dll in the iface is a pointer to a real /// dll. Fortunately though, most users of the library will never even /// be looking inside the implementation, and thus hopefully it won't /// be confusing. let node a = B.pointer (DLL.node a) let dll a = B.pointer (DLL.dll a) /// Abstract Validity Predicates let node_valid h n = True /\ B.live h n // XXX: why do I need the True here? let dll_valid h d = B.live h d /\ DLL.dll_valid h (d@h) /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 (d@h) /// Abstract node and list footprints
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "DoublyLinkedList.fst.checked" ], "interface_file": true, "source_file": "DoublyLinkedListIface.fst" }
[ { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": true, "full_module": "FStar.List.Pure", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "DoublyLinkedList", "short_module": "DLL" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
n: DoublyLinkedListIface.node 'a -> Prims.GTot LowStar.Monotonic.Buffer.loc
Prims.GTot
[ "sometrivial" ]
[]
[ "DoublyLinkedListIface.node", "LowStar.Monotonic.Buffer.loc_buffer", "DoublyLinkedList.node", "LowStar.Buffer.trivial_preorder", "LowStar.Monotonic.Buffer.loc" ]
[]
false
false
false
false
false
let fp_node n =
B.loc_buffer n
false
DoublyLinkedListIface.fst
DoublyLinkedListIface.fp_dll
val fp_dll (h:HS.mem) (d:dll 'a) : GTot B.loc
val fp_dll (h:HS.mem) (d:dll 'a) : GTot B.loc
let fp_dll h d = B.loc_union (B.loc_buffer d) (DLL.dll_fp0 (d@h))
{ "file_name": "examples/doublylinkedlist/DoublyLinkedListIface.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 50, "end_line": 65, "start_col": 0, "start_line": 64 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module DoublyLinkedListIface /// This module consists of proofs / code for the iface that is /// written in the actual fsti. Most of this code will never be user /// facing, and will soon be merged into the DoublyLinkedList module, /// as I work on moving stuff into DoublyLinkedList.fsti from the iface /// fsti. module DLL = DoublyLinkedList module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module G = FStar.Ghost module L = FStar.List.Pure module B = LowStar.Buffer open LowStar.BufferOps /// Convenience operators unfold let (@) (a:B.pointer 't) (h0:HS.mem) = B.get h0 a 0 unfold let (^@) (a:B.pointer_or_null 't{a =!= B.null}) (h0:HS.mem) = B.get h0 a 0 /// Abstract types defined by this library /// /// Note: Somehow confusingly, a node in the iface is a pointer to a /// real node, and a dll in the iface is a pointer to a real /// dll. Fortunately though, most users of the library will never even /// be looking inside the implementation, and thus hopefully it won't /// be confusing. let node a = B.pointer (DLL.node a) let dll a = B.pointer (DLL.dll a) /// Abstract Validity Predicates let node_valid h n = True /\ B.live h n // XXX: why do I need the True here? let dll_valid h d = B.live h d /\ DLL.dll_valid h (d@h) /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 (d@h) /// Abstract node and list footprints let fp_node n = B.loc_buffer n
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "DoublyLinkedList.fst.checked" ], "interface_file": true, "source_file": "DoublyLinkedListIface.fst" }
[ { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": true, "full_module": "FStar.List.Pure", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "DoublyLinkedList", "short_module": "DLL" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
h: FStar.Monotonic.HyperStack.mem -> d: DoublyLinkedListIface.dll 'a -> Prims.GTot LowStar.Monotonic.Buffer.loc
Prims.GTot
[ "sometrivial" ]
[]
[ "FStar.Monotonic.HyperStack.mem", "DoublyLinkedListIface.dll", "LowStar.Monotonic.Buffer.loc_union", "LowStar.Monotonic.Buffer.loc_buffer", "DoublyLinkedList.dll", "LowStar.Buffer.trivial_preorder", "DoublyLinkedList.dll_fp0", "DoublyLinkedListIface.op_At", "LowStar.Monotonic.Buffer.loc" ]
[]
false
false
false
false
false
let fp_dll h d =
B.loc_union (B.loc_buffer d) (DLL.dll_fp0 (d @ h))
false
DoublyLinkedListIface.fst
DoublyLinkedListIface.g_node_val
val g_node_val (h:HS.mem) (n:node 'a) : GTot 'a
val g_node_val (h:HS.mem) (n:node 'a) : GTot 'a
let g_node_val h n = (n@h).DLL.p
{ "file_name": "examples/doublylinkedlist/DoublyLinkedListIface.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 13, "end_line": 70, "start_col": 0, "start_line": 69 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module DoublyLinkedListIface /// This module consists of proofs / code for the iface that is /// written in the actual fsti. Most of this code will never be user /// facing, and will soon be merged into the DoublyLinkedList module, /// as I work on moving stuff into DoublyLinkedList.fsti from the iface /// fsti. module DLL = DoublyLinkedList module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module G = FStar.Ghost module L = FStar.List.Pure module B = LowStar.Buffer open LowStar.BufferOps /// Convenience operators unfold let (@) (a:B.pointer 't) (h0:HS.mem) = B.get h0 a 0 unfold let (^@) (a:B.pointer_or_null 't{a =!= B.null}) (h0:HS.mem) = B.get h0 a 0 /// Abstract types defined by this library /// /// Note: Somehow confusingly, a node in the iface is a pointer to a /// real node, and a dll in the iface is a pointer to a real /// dll. Fortunately though, most users of the library will never even /// be looking inside the implementation, and thus hopefully it won't /// be confusing. let node a = B.pointer (DLL.node a) let dll a = B.pointer (DLL.dll a) /// Abstract Validity Predicates let node_valid h n = True /\ B.live h n // XXX: why do I need the True here? let dll_valid h d = B.live h d /\ DLL.dll_valid h (d@h) /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 (d@h) /// Abstract node and list footprints let fp_node n = B.loc_buffer n let fp_dll h d = B.loc_union (B.loc_buffer d) (DLL.dll_fp0 (d@h)) /// Getters and setters for [node]s
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "DoublyLinkedList.fst.checked" ], "interface_file": true, "source_file": "DoublyLinkedListIface.fst" }
[ { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": true, "full_module": "FStar.List.Pure", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "DoublyLinkedList", "short_module": "DLL" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
h: FStar.Monotonic.HyperStack.mem -> n: DoublyLinkedListIface.node 'a -> Prims.GTot 'a
Prims.GTot
[ "sometrivial" ]
[]
[ "FStar.Monotonic.HyperStack.mem", "DoublyLinkedListIface.node", "DoublyLinkedList.__proj__Mknode__item__p", "DoublyLinkedListIface.op_At", "DoublyLinkedList.node" ]
[]
false
false
false
false
false
let g_node_val h n =
(n @ h).DLL.p
false
DoublyLinkedListIface.fst
DoublyLinkedListIface.unchanged_node_connections
val unchanged_node_connections (h0 h1:HS.mem) (n:node 'a) : GTot prop
val unchanged_node_connections (h0 h1:HS.mem) (n:node 'a) : GTot prop
let unchanged_node_connections h0 h1 n = (n@h0).DLL.flink == (n@h1).DLL.flink /\ (n@h0).DLL.blink == (n@h1).DLL.blink
{ "file_name": "examples/doublylinkedlist/DoublyLinkedListIface.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 38, "end_line": 83, "start_col": 0, "start_line": 81 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module DoublyLinkedListIface /// This module consists of proofs / code for the iface that is /// written in the actual fsti. Most of this code will never be user /// facing, and will soon be merged into the DoublyLinkedList module, /// as I work on moving stuff into DoublyLinkedList.fsti from the iface /// fsti. module DLL = DoublyLinkedList module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module G = FStar.Ghost module L = FStar.List.Pure module B = LowStar.Buffer open LowStar.BufferOps /// Convenience operators unfold let (@) (a:B.pointer 't) (h0:HS.mem) = B.get h0 a 0 unfold let (^@) (a:B.pointer_or_null 't{a =!= B.null}) (h0:HS.mem) = B.get h0 a 0 /// Abstract types defined by this library /// /// Note: Somehow confusingly, a node in the iface is a pointer to a /// real node, and a dll in the iface is a pointer to a real /// dll. Fortunately though, most users of the library will never even /// be looking inside the implementation, and thus hopefully it won't /// be confusing. let node a = B.pointer (DLL.node a) let dll a = B.pointer (DLL.dll a) /// Abstract Validity Predicates let node_valid h n = True /\ B.live h n // XXX: why do I need the True here? let dll_valid h d = B.live h d /\ DLL.dll_valid h (d@h) /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 (d@h) /// Abstract node and list footprints let fp_node n = B.loc_buffer n let fp_dll h d = B.loc_union (B.loc_buffer d) (DLL.dll_fp0 (d@h)) /// Getters and setters for [node]s let g_node_val h n = (n@h).DLL.p let node_val n = (!*n).DLL.p let node_of v = B.alloca (DLL.empty_node v) 1ul /// Abstract Predicate to help "recall" that updating the payload /// leaves connections unchanged
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "DoublyLinkedList.fst.checked" ], "interface_file": true, "source_file": "DoublyLinkedListIface.fst" }
[ { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": true, "full_module": "FStar.List.Pure", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "DoublyLinkedList", "short_module": "DLL" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
h0: FStar.Monotonic.HyperStack.mem -> h1: FStar.Monotonic.HyperStack.mem -> n: DoublyLinkedListIface.node 'a -> Prims.GTot Prims.prop
Prims.GTot
[ "sometrivial" ]
[]
[ "FStar.Monotonic.HyperStack.mem", "DoublyLinkedListIface.node", "Prims.l_and", "Prims.eq2", "LowStar.Buffer.pointer_or_null", "DoublyLinkedList.node", "DoublyLinkedList.__proj__Mknode__item__flink", "DoublyLinkedListIface.op_At", "DoublyLinkedList.__proj__Mknode__item__blink", "Prims.prop" ]
[]
false
false
false
false
true
let unchanged_node_connections h0 h1 n =
(n @ h0).DLL.flink == (n @ h1).DLL.flink /\ (n @ h0).DLL.blink == (n @ h1).DLL.blink
false
DoublyLinkedListIface.fst
DoublyLinkedListIface.as_list
val as_list (h:HS.mem) (d:dll 'a) : GTot (list (node 'a))
val as_list (h:HS.mem) (d:dll 'a) : GTot (list (node 'a))
let as_list h d = (d@h).DLL.nodes
{ "file_name": "examples/doublylinkedlist/DoublyLinkedListIface.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 17, "end_line": 106, "start_col": 0, "start_line": 105 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module DoublyLinkedListIface /// This module consists of proofs / code for the iface that is /// written in the actual fsti. Most of this code will never be user /// facing, and will soon be merged into the DoublyLinkedList module, /// as I work on moving stuff into DoublyLinkedList.fsti from the iface /// fsti. module DLL = DoublyLinkedList module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module G = FStar.Ghost module L = FStar.List.Pure module B = LowStar.Buffer open LowStar.BufferOps /// Convenience operators unfold let (@) (a:B.pointer 't) (h0:HS.mem) = B.get h0 a 0 unfold let (^@) (a:B.pointer_or_null 't{a =!= B.null}) (h0:HS.mem) = B.get h0 a 0 /// Abstract types defined by this library /// /// Note: Somehow confusingly, a node in the iface is a pointer to a /// real node, and a dll in the iface is a pointer to a real /// dll. Fortunately though, most users of the library will never even /// be looking inside the implementation, and thus hopefully it won't /// be confusing. let node a = B.pointer (DLL.node a) let dll a = B.pointer (DLL.dll a) /// Abstract Validity Predicates let node_valid h n = True /\ B.live h n // XXX: why do I need the True here? let dll_valid h d = B.live h d /\ DLL.dll_valid h (d@h) /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 (d@h) /// Abstract node and list footprints let fp_node n = B.loc_buffer n let fp_dll h d = B.loc_union (B.loc_buffer d) (DLL.dll_fp0 (d@h)) /// Getters and setters for [node]s let g_node_val h n = (n@h).DLL.p let node_val n = (!*n).DLL.p let node_of v = B.alloca (DLL.empty_node v) 1ul /// Abstract Predicate to help "recall" that updating the payload /// leaves connections unchanged let unchanged_node_connections h0 h1 n = (n@h0).DLL.flink == (n@h1).DLL.flink /\ (n@h0).DLL.blink == (n@h1).DLL.blink /// Be able to modify the payload of a node easily, without affecting /// membership let node_update n v = n *= { !*n with DLL.p = v } /// Abstract Predicate to help "recall" that [g_node_val] remains /// unchanged for nodes, across multiple [mem]s let unchanged_node_val (h0 h1:HS.mem) (n:node 'a) : GTot prop = (B.live h0 n ==> (g_node_val h0 n == g_node_val h1 n /\ B.live h1 n)) let rec unchanged_node_vals (h0 h1:HS.mem) (ns:list (node 'a)) : GTot prop = match ns with | [] -> True | n :: ns' -> unchanged_node_val h0 h1 n /\ unchanged_node_vals h0 h1 ns' /// Viewing ghostly state of a list
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "DoublyLinkedList.fst.checked" ], "interface_file": true, "source_file": "DoublyLinkedListIface.fst" }
[ { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": true, "full_module": "FStar.List.Pure", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "DoublyLinkedList", "short_module": "DLL" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
h: FStar.Monotonic.HyperStack.mem -> d: DoublyLinkedListIface.dll 'a -> Prims.GTot (Prims.list (DoublyLinkedListIface.node 'a))
Prims.GTot
[ "sometrivial" ]
[]
[ "FStar.Monotonic.HyperStack.mem", "DoublyLinkedListIface.dll", "FStar.Ghost.reveal", "DoublyLinkedList.nodelist", "DoublyLinkedList.__proj__Mkdll__item__nodes", "DoublyLinkedListIface.op_At", "DoublyLinkedList.dll", "Prims.list", "DoublyLinkedListIface.node" ]
[]
false
false
false
false
false
let as_list h d =
(d @ h).DLL.nodes
false
DoublyLinkedListIface.fst
DoublyLinkedListIface.unchanged_node_val
val unchanged_node_val (h0 h1: HS.mem) (n: node 'a) : GTot prop
val unchanged_node_val (h0 h1: HS.mem) (n: node 'a) : GTot prop
let unchanged_node_val (h0 h1:HS.mem) (n:node 'a) : GTot prop = (B.live h0 n ==> (g_node_val h0 n == g_node_val h1 n /\ B.live h1 n))
{ "file_name": "examples/doublylinkedlist/DoublyLinkedListIface.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 55, "end_line": 96, "start_col": 0, "start_line": 94 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module DoublyLinkedListIface /// This module consists of proofs / code for the iface that is /// written in the actual fsti. Most of this code will never be user /// facing, and will soon be merged into the DoublyLinkedList module, /// as I work on moving stuff into DoublyLinkedList.fsti from the iface /// fsti. module DLL = DoublyLinkedList module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module G = FStar.Ghost module L = FStar.List.Pure module B = LowStar.Buffer open LowStar.BufferOps /// Convenience operators unfold let (@) (a:B.pointer 't) (h0:HS.mem) = B.get h0 a 0 unfold let (^@) (a:B.pointer_or_null 't{a =!= B.null}) (h0:HS.mem) = B.get h0 a 0 /// Abstract types defined by this library /// /// Note: Somehow confusingly, a node in the iface is a pointer to a /// real node, and a dll in the iface is a pointer to a real /// dll. Fortunately though, most users of the library will never even /// be looking inside the implementation, and thus hopefully it won't /// be confusing. let node a = B.pointer (DLL.node a) let dll a = B.pointer (DLL.dll a) /// Abstract Validity Predicates let node_valid h n = True /\ B.live h n // XXX: why do I need the True here? let dll_valid h d = B.live h d /\ DLL.dll_valid h (d@h) /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 (d@h) /// Abstract node and list footprints let fp_node n = B.loc_buffer n let fp_dll h d = B.loc_union (B.loc_buffer d) (DLL.dll_fp0 (d@h)) /// Getters and setters for [node]s let g_node_val h n = (n@h).DLL.p let node_val n = (!*n).DLL.p let node_of v = B.alloca (DLL.empty_node v) 1ul /// Abstract Predicate to help "recall" that updating the payload /// leaves connections unchanged let unchanged_node_connections h0 h1 n = (n@h0).DLL.flink == (n@h1).DLL.flink /\ (n@h0).DLL.blink == (n@h1).DLL.blink /// Be able to modify the payload of a node easily, without affecting /// membership let node_update n v = n *= { !*n with DLL.p = v } /// Abstract Predicate to help "recall" that [g_node_val] remains /// unchanged for nodes, across multiple [mem]s
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "DoublyLinkedList.fst.checked" ], "interface_file": true, "source_file": "DoublyLinkedListIface.fst" }
[ { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Pure", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "DoublyLinkedList", "short_module": "DLL" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
h0: FStar.Monotonic.HyperStack.mem -> h1: FStar.Monotonic.HyperStack.mem -> n: DoublyLinkedListIface.node 'a -> Prims.GTot Prims.prop
Prims.GTot
[ "sometrivial" ]
[]
[ "FStar.Monotonic.HyperStack.mem", "DoublyLinkedListIface.node", "Prims.l_imp", "LowStar.Monotonic.Buffer.live", "DoublyLinkedList.node", "LowStar.Buffer.trivial_preorder", "Prims.l_and", "Prims.eq2", "DoublyLinkedListIface.g_node_val", "Prims.prop" ]
[]
false
false
false
false
true
let unchanged_node_val (h0 h1: HS.mem) (n: node 'a) : GTot prop =
(B.live h0 n ==> (g_node_val h0 n == g_node_val h1 n /\ B.live h1 n))
false
DoublyLinkedListIface.fst
DoublyLinkedListIface.node_of
val node_of (v:'a) : HST.StackInline (node 'a) (requires (fun h0 -> True)) (ensures (fun h0 n h1 -> B.modifies B.loc_none h0 h1 /\ B.fresh_loc (fp_node n) h0 h1 /\ node_valid h1 n /\ v == g_node_val h1 n))
val node_of (v:'a) : HST.StackInline (node 'a) (requires (fun h0 -> True)) (ensures (fun h0 n h1 -> B.modifies B.loc_none h0 h1 /\ B.fresh_loc (fp_node n) h0 h1 /\ node_valid h1 n /\ v == g_node_val h1 n))
let node_of v = B.alloca (DLL.empty_node v) 1ul
{ "file_name": "examples/doublylinkedlist/DoublyLinkedListIface.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 33, "end_line": 76, "start_col": 0, "start_line": 75 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module DoublyLinkedListIface /// This module consists of proofs / code for the iface that is /// written in the actual fsti. Most of this code will never be user /// facing, and will soon be merged into the DoublyLinkedList module, /// as I work on moving stuff into DoublyLinkedList.fsti from the iface /// fsti. module DLL = DoublyLinkedList module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module G = FStar.Ghost module L = FStar.List.Pure module B = LowStar.Buffer open LowStar.BufferOps /// Convenience operators unfold let (@) (a:B.pointer 't) (h0:HS.mem) = B.get h0 a 0 unfold let (^@) (a:B.pointer_or_null 't{a =!= B.null}) (h0:HS.mem) = B.get h0 a 0 /// Abstract types defined by this library /// /// Note: Somehow confusingly, a node in the iface is a pointer to a /// real node, and a dll in the iface is a pointer to a real /// dll. Fortunately though, most users of the library will never even /// be looking inside the implementation, and thus hopefully it won't /// be confusing. let node a = B.pointer (DLL.node a) let dll a = B.pointer (DLL.dll a) /// Abstract Validity Predicates let node_valid h n = True /\ B.live h n // XXX: why do I need the True here? let dll_valid h d = B.live h d /\ DLL.dll_valid h (d@h) /\ B.loc_buffer d `B.loc_disjoint` DLL.dll_fp0 (d@h) /// Abstract node and list footprints let fp_node n = B.loc_buffer n let fp_dll h d = B.loc_union (B.loc_buffer d) (DLL.dll_fp0 (d@h)) /// Getters and setters for [node]s let g_node_val h n = (n@h).DLL.p let node_val n = (!*n).DLL.p
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Pure.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "DoublyLinkedList.fst.checked" ], "interface_file": true, "source_file": "DoublyLinkedListIface.fst" }
[ { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": true, "full_module": "FStar.List.Pure", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "DoublyLinkedList", "short_module": "DLL" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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: 'a -> FStar.HyperStack.ST.StackInline (DoublyLinkedListIface.node 'a)
FStar.HyperStack.ST.StackInline
[]
[]
[ "LowStar.Buffer.alloca", "DoublyLinkedList.node", "DoublyLinkedList.empty_node", "FStar.UInt32.__uint_to_t", "LowStar.Monotonic.Buffer.mbuffer", "LowStar.Buffer.trivial_preorder", "Prims.l_and", "Prims.eq2", "Prims.nat", "LowStar.Monotonic.Buffer.length", "FStar.UInt32.v", "Prims.b2t", "Prims.op_Negation", "LowStar.Monotonic.Buffer.g_is_null", "DoublyLinkedListIface.node" ]
[]
false
true
false
false
false
let node_of v =
B.alloca (DLL.empty_node v) 1ul
false