file_name
stringlengths
5
52
name
stringlengths
4
95
original_source_type
stringlengths
0
23k
source_type
stringlengths
9
23k
source_definition
stringlengths
9
57.9k
source
dict
source_range
dict
file_context
stringlengths
0
721k
dependencies
dict
opens_and_abbrevs
listlengths
2
94
vconfig
dict
interleaved
bool
1 class
verbose_type
stringlengths
1
7.42k
effect
stringclasses
118 values
effect_flags
sequencelengths
0
2
mutual_with
sequencelengths
0
11
ideal_premises
sequencelengths
0
236
proof_features
sequencelengths
0
1
is_simple_lemma
bool
2 classes
is_div
bool
2 classes
is_proof
bool
2 classes
is_simply_typed
bool
2 classes
is_type
bool
2 classes
partial_definition
stringlengths
5
3.99k
completed_definiton
stringlengths
1
1.63M
isa_cross_project_example
bool
1 class
Functor.fst
Functor.t1
val t1 : Prims.list Prims.int
let t1 = fmap #list (fun x -> x + 1) [1 ; 2 ; 3]
{ "file_name": "examples/typeclasses/Functor.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 48, "end_line": 33, "start_col": 0, "start_line": 33 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Functor open FStar.Tactics.Typeclasses class functor f = { fmap : (#a:Type) -> (#b:Type) -> (a -> b) -> f a -> f b ; } (* Two concrete instances *) instance functor_list : functor list = { fmap = List.Tot.map } instance functor_id : functor id = { fmap = fun #_ #_ f a -> f a } let compose t1 t2 = fun x -> t1 (t2 x) instance comp #ff #gg (_ : functor ff) (_ : functor gg) : functor (compose ff gg) = { fmap = (fun #a #b f x -> fmap #ff (fmap #gg f) x) }
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "Functor.fst" }
[ { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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.list Prims.int
Prims.Tot
[ "total" ]
[]
[ "Functor.fmap", "Prims.list", "Functor.functor_list", "Prims.int", "Prims.op_Addition", "Prims.Cons", "Prims.Nil" ]
[]
false
false
false
true
false
let t1 =
fmap #list (fun x -> x + 1) [1; 2; 3]
false
Steel.ST.GenArraySwap.Proof.fst
Steel.ST.GenArraySwap.Proof.mod_eq_elim
val mod_eq_elim (n: pos) (x1 x2: int) : Ghost int (requires (x1 % n == x2 % n)) (ensures (fun k -> x1 - x2 == k * n))
val mod_eq_elim (n: pos) (x1 x2: int) : Ghost int (requires (x1 % n == x2 % n)) (ensures (fun k -> x1 - x2 == k * n))
let mod_eq_elim (n: pos) (x1 x2: int) : Ghost int (requires (x1 % n == x2 % n)) (ensures (fun k -> x1 - x2 == k * n)) = euclidean_division_definition x1 n; euclidean_division_definition x2 n; let q1 = x1 / n in let q2 = x2 / n in let k = q1 + - q2 in let r = x1 % n in assert (q1 * n + r + - (q2 * n + r) == k * n) by (int_semiring ()); k
{ "file_name": "lib/steel/Steel.ST.GenArraySwap.Proof.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 3, "end_line": 403, "start_col": 0, "start_line": 390 }
module Steel.ST.GenArraySwap.Proof open FStar.Math.Lemmas open FStar.Mul let lemma_mod_lt (a:int) (b:pos) : Lemma (let r = a % b in 0 <= r /\ r < b) [SMTPat (a % b)] = () let lemma_mul_nat_nat_is_nat (a b: nat) : Lemma (a * b >= 0) [SMTPat (a * b)] = () let lemma_pos_mul_pos_args (a: nat) (b: nat) : Lemma (requires (a * b > 0)) (ensures (a > 0 /\ b > 0 /\ a <= a * b /\ b <= a * b /\ a * b == b * a)) = () let lemma_div_nat (a: nat) (b: pos) : Lemma (a / b >= 0) [SMTPat (a / b)] = () let lemma_mult_reg_l (k: int) (x1 x2: int) : Lemma (requires ( k * x1 == k * x2 /\ k <> 0 )) (ensures ( x1 == x2 )) = () let lemma_bezout_one_zero (x1: int) (x2: nat) (y1 y2: int) : Lemma (requires ( x1 * x2 + y1 * y2 == 1 /\ y1 == 0 )) (ensures ( x1 == 1 /\ x2 == 1 )) = () #set-options "--z3cliopt smt.arith.nl=false" let int_semiring () = FStar.Tactics.CanonCommSemiring.int_semiring (); FStar.Tactics.trefl (); FStar.Tactics.qed () [@@erasable] noeq type bezout_t = { d: pos; q_n: nat; q_l: nat; u_n: int; u_l: int; } let bezout_prop' (n: nat) (l: nat) (d: pos) (q_n: nat) (q_l: nat) (u_n: int) (u_l: int) : Tot prop = n == d * q_n /\ l == d * q_l /\ d == n * u_n + l * u_l let bezout_prop (n: nat) (l: nat) (b: bezout_t) : Tot prop = bezout_prop' n l b.d b.q_n b.q_l b.u_n b.u_l let bezout (n: nat) (l: nat) : Tot Type = (b: bezout_t { bezout_prop n l b }) #restart-solver let rec mk_bezout (n: pos) (l: nat) : Pure (bezout n l) (requires (l < n)) (ensures (fun _ -> True)) (decreases l) = if l = 0 then begin let d : pos = n in let q_n : nat = 1 in let q_l : nat = 0 in let u_n : int = 1 in let u_l : int = 0 in let res = { d = d; q_n = q_n; q_l = q_l; u_n = u_n; u_l = u_l; } in assert (eq2 #int n (d * q_n)) by (int_semiring ()); assert (eq2 #int 0 (d * q_l)) by (int_semiring ()); assert (eq2 #int d (n * 1 + 0 * res.u_l)) by (int_semiring ()); res end else begin let lpre = n % l in let ql = n / l in euclidean_division_definition n l; let bpre = mk_bezout l lpre in let d = bpre.d in let q_l = bpre.q_n in let qpre_lpre = bpre.q_l in let upre_l = bpre.u_n in let upre_lpre = bpre.u_l in let n_alt0 = l * ql + lpre in assert (n == n_alt0); let l_alt = d * q_l in let lpre_alt1 = d * qpre_lpre in let n_alt1 = l_alt * ql + lpre_alt1 in assert (n_alt1 == n); let q_n = q_l * ql + qpre_lpre in assert (eq2 #int n_alt1 (d * q_n)) by (int_semiring ()); let lpre_alt2 = n + - l * ql in assert (lpre_alt2 == lpre); let d_alt = l * upre_l + lpre_alt2 * upre_lpre in assert (d_alt == d); let u_l = upre_l + - ql * upre_lpre in assert (eq2 #int (n * upre_lpre + l * u_l) d_alt) by (int_semiring ()); let res = { d = d; q_n = q_n; q_l = q_l; u_n = upre_lpre; u_l = u_l; } in res end let bezout_q_eq (n: nat) (l: nat) (bz: bezout n l) : Lemma (bz.q_n == n / bz.d) [SMTPat (bezout_prop n l bz); SMTPat bz.q_n] = cancel_mul_div bz.q_n bz.d let rec iter_fun (#t: Type) (f: (t -> GTot t)) (n: nat) (x: t) : GTot t (decreases n) = if n = 0 then x else iter_fun f (n - 1) (f x) let nat_up_to (n: nat) : Tot Type = (i: nat { i < n }) let jump (n: pos) (l: nat) (x: nat_up_to n) : GTot (nat_up_to n) = (x + l) % n #restart-solver let jump_mod_d (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Lemma (jump n l x % b.d == x % b.d) = let x' = jump n l x in let x'q = (x + l) / n in euclidean_division_definition (x + l) n; let l_alt = b.d * b.q_l in assert (l_alt == l); let n_alt = b.d * b.q_n in assert (n_alt == n); let x'_alt = x + l_alt + - x'q * n_alt in assert (x'_alt == x'); let qx = b.q_l + - x'q * b.q_n in assert (eq2 #int x'_alt (x + qx * b.d)) by (int_semiring ()); lemma_mod_plus x qx b.d let rec jump_iter_mod_d (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) (k: nat) : Lemma (ensures (iter_fun #(nat_up_to n) (jump n l) k x % b.d == x % b.d)) (decreases k) = if k = 0 then () else begin jump_mod_d n l b x; jump_iter_mod_d n l b (jump n l x) (k - 1) end (* Coverage *) let rec jump_iter (n: pos) (l: nat) (x: nat_up_to n) (k: nat) : Lemma (ensures (iter_fun #(nat_up_to n) (jump n l) k x == (x + k * l) % n)) (decreases k) = if k = 0 then begin assert (eq2 #int (x + 0 * l) x) by (int_semiring ()); small_mod x n end else begin let k' = k - 1 in assert (eq2 #int (x + (k' + 1) * l) ((x + l) + k' * l)) by (int_semiring ()); jump_iter n l ((x + l) % n) k'; lemma_mod_add_distr (k' * l) (x + l) n end let bezout_pos_le (n: pos) (l: nat) (b: bezout n l) : Lemma (b.d <= n /\ b.q_n > 0) [SMTPat (bezout_prop n l b)] = lemma_pos_mul_pos_args b.q_n b.d #restart-solver [@@"opaque_to_smt"] irreducible let jump_coverage (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Ghost nat (requires True) (ensures (fun k -> x == iter_fun (jump n l) k (x % b.d) )) = let i = x % b.d in let qx = x / b.d in euclidean_division_definition x b.d; let k1 = qx * b.u_l in let m = qx * b.u_n in assert (eq2 #int (qx * (n * b.u_n + l * b.u_l) + i) (i + k1 * l + m * n)) by (int_semiring ()); assert (x == i + k1 * l + m * n); small_mod x n; lemma_mod_plus (i + k1 * l) m n; assert (x == (i + k1 * l) % n); let k = k1 % n in let qk = k1 / n in euclidean_division_definition k1 n; assert (i + (qk * n + k) * l == i + k * l + (qk * l) * n) by (int_semiring ()); lemma_mod_plus (i + k * l) (qk * l) n; assert (eq2 #int x ((i + k * l) % n)); jump_iter n l i k; k [@@"opaque_to_smt"] irreducible let rec minimal_exists' (p: (nat -> GTot bool)) (n: nat) (i: nat) : Ghost nat (requires ( p n == true /\ i <= n /\ (forall (j: nat) . j < i ==> p j == false) )) (ensures (fun k -> p k == true /\ (forall (j: nat) . j < k ==> p j == false) )) (decreases (n - i)) = if p i then i else minimal_exists' p n (i + 1) [@@"opaque_to_smt"] irreducible let minimal_exists (p: (nat -> GTot bool)) (n: nat) : Ghost nat (requires ( p n == true )) (ensures (fun k -> p k == true /\ (forall (j: nat) . j < k ==> p j == false) )) = minimal_exists' p n 0 [@@"opaque_to_smt"] irreducible let jump_coverage_strong (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Ghost nat (requires True) (ensures (fun k -> x == iter_fun (jump n l) k (x % b.d) /\ (forall (k': nat) . k' < k ==> (~ (x == iter_fun (jump n l) k' (x % b.d)))) )) = let k' = jump_coverage n l b x in minimal_exists (fun k -> x = iter_fun (jump n l) k (x % b.d)) k' #restart-solver let jump_iter_mod_q (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) (k: nat) : Lemma (ensures ( b.q_n > 0 /\ iter_fun (jump n l) (k % b.q_n) x == iter_fun (jump n l) k x )) = assert (b.q_n > 0); let k' = k % b.q_n in let qk = k / b.q_n in euclidean_division_definition k b.q_n; jump_iter n l x k'; jump_iter n l x k; assert (eq2 #int (x + (qk * b.q_n + k') * (b.d * b.q_l)) (x + k' * (b.d * b.q_l) + (qk * b.q_l) * (b.d * b.q_n))) by (int_semiring ()); assert (x + k * l == x + k' * l + (qk * b.q_l) * n); lemma_mod_plus (x + k' * l) (qk * b.q_l) n let jump_coverage_strong_bound (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Lemma (b.q_n > 0 /\ jump_coverage_strong n l b x < b.q_n ) [SMTPat (jump_coverage_strong n l b x)] = let k = jump_coverage_strong n l b x in jump_iter_mod_q n l b (x % b.d) k #restart-solver [@@"opaque_to_smt"]
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.CanonCommSemiring.fst.checked", "FStar.Tactics.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Steel.ST.GenArraySwap.Proof.fst" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.GenArraySwap", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.GenArraySwap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
n: Prims.pos -> x1: Prims.int -> x2: Prims.int -> Prims.Ghost Prims.int
Prims.Ghost
[]
[]
[ "Prims.pos", "Prims.int", "Prims.unit", "FStar.Tactics.Effect.assert_by_tactic", "Prims.eq2", "Prims.op_Addition", "FStar.Mul.op_Star", "Prims.op_Minus", "Steel.ST.GenArraySwap.Proof.int_semiring", "Prims.op_Modulus", "Prims.op_Division", "FStar.Math.Lemmas.euclidean_division_definition", "Prims.op_Subtraction" ]
[]
false
false
false
false
false
let mod_eq_elim (n: pos) (x1 x2: int) : Ghost int (requires (x1 % n == x2 % n)) (ensures (fun k -> x1 - x2 == k * n)) =
euclidean_division_definition x1 n; euclidean_division_definition x2 n; let q1 = x1 / n in let q2 = x2 / n in let k = q1 + - q2 in let r = x1 % n in FStar.Tactics.Effect.assert_by_tactic (q1 * n + r + - (q2 * n + r) == k * n) (fun _ -> (); (int_semiring ())); k
false
Functor.fst
Functor.fmap'
val fmap' (#f: (Type -> Type)) {| _: functor f |} (#a #b: Type) (g: (a -> b)) (x: f a) : f b
val fmap' (#f: (Type -> Type)) {| _: functor f |} (#a #b: Type) (g: (a -> b)) (x: f a) : f b
let fmap' (#f:Type -> Type) {| functor f |} (#a:Type) (#b:Type) (g:a -> b) (x: f a) : f b = fmap #f g x
{ "file_name": "examples/typeclasses/Functor.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 13, "end_line": 38, "start_col": 0, "start_line": 37 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Functor open FStar.Tactics.Typeclasses class functor f = { fmap : (#a:Type) -> (#b:Type) -> (a -> b) -> f a -> f b ; } (* Two concrete instances *) instance functor_list : functor list = { fmap = List.Tot.map } instance functor_id : functor id = { fmap = fun #_ #_ f a -> f a } let compose t1 t2 = fun x -> t1 (t2 x) instance comp #ff #gg (_ : functor ff) (_ : functor gg) : functor (compose ff gg) = { fmap = (fun #a #b f x -> fmap #ff (fmap #gg f) x) } let t1 = fmap #list (fun x -> x + 1) [1 ; 2 ; 3] let t2 = fmap #(compose list list) (fun x -> x + 1) [[1] ; [2 ; 3]]
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "Functor.fst" }
[ { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
{| _: Functor.functor f |} -> g: (_: a -> b) -> x: f a -> f b
Prims.Tot
[ "total" ]
[]
[ "Functor.functor", "Functor.fmap" ]
[]
false
false
false
false
false
let fmap' (#f: (Type -> Type)) {| _: functor f |} (#a #b: Type) (g: (a -> b)) (x: f a) : f b =
fmap #f g x
false
Steel.ST.GenArraySwap.Proof.fst
Steel.ST.GenArraySwap.Proof.jump_iter_inj
val jump_iter_inj (n l: nat) (b: bezout_t) (i1 i2 k1 k2: nat) : Lemma (requires (n > 0 /\ l > 0 /\ bezout_prop n l b /\ i1 < b.d /\ i2 < b.d /\ k1 < b.q_n /\ k2 < b.q_n /\ iter_fun (jump n l) k1 i1 == iter_fun (jump n l) k2 i2)) (ensures (i1 == i2 /\ k1 == k2)) [ SMTPat (iter_fun (jump n l) k1 i1); SMTPat (iter_fun (jump n l) k2 i2); SMTPat (bezout_prop n l b) ]
val jump_iter_inj (n l: nat) (b: bezout_t) (i1 i2 k1 k2: nat) : Lemma (requires (n > 0 /\ l > 0 /\ bezout_prop n l b /\ i1 < b.d /\ i2 < b.d /\ k1 < b.q_n /\ k2 < b.q_n /\ iter_fun (jump n l) k1 i1 == iter_fun (jump n l) k2 i2)) (ensures (i1 == i2 /\ k1 == k2)) [ SMTPat (iter_fun (jump n l) k1 i1); SMTPat (iter_fun (jump n l) k2 i2); SMTPat (bezout_prop n l b) ]
let jump_iter_inj (n: nat) (l: nat) (b: bezout_t) (i1 i2: nat) (k1 k2: nat) : Lemma (requires ( n > 0 /\ l > 0 /\ bezout_prop n l b /\ i1 < b.d /\ i2 < b.d /\ k1 < b.q_n /\ k2 < b.q_n /\ iter_fun (jump n l) k1 i1 == iter_fun (jump n l) k2 i2 )) (ensures ( i1 == i2 /\ k1 == k2 )) [SMTPat (iter_fun (jump n l) k1 i1); SMTPat (iter_fun (jump n l) k2 i2); SMTPat (bezout_prop n l b)] = jump_iter_mod_d n l b i1 k1; jump_iter_mod_d n l b i2 k2; small_mod i1 b.d; small_mod i2 b.d; jump_iter_mod_q_inj_weak n l b i1 k1 k2; small_mod k1 b.q_n; small_mod k2 b.q_n
{ "file_name": "lib/steel/Steel.ST.GenArraySwap.Proof.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 20, "end_line": 505, "start_col": 0, "start_line": 477 }
module Steel.ST.GenArraySwap.Proof open FStar.Math.Lemmas open FStar.Mul let lemma_mod_lt (a:int) (b:pos) : Lemma (let r = a % b in 0 <= r /\ r < b) [SMTPat (a % b)] = () let lemma_mul_nat_nat_is_nat (a b: nat) : Lemma (a * b >= 0) [SMTPat (a * b)] = () let lemma_pos_mul_pos_args (a: nat) (b: nat) : Lemma (requires (a * b > 0)) (ensures (a > 0 /\ b > 0 /\ a <= a * b /\ b <= a * b /\ a * b == b * a)) = () let lemma_div_nat (a: nat) (b: pos) : Lemma (a / b >= 0) [SMTPat (a / b)] = () let lemma_mult_reg_l (k: int) (x1 x2: int) : Lemma (requires ( k * x1 == k * x2 /\ k <> 0 )) (ensures ( x1 == x2 )) = () let lemma_bezout_one_zero (x1: int) (x2: nat) (y1 y2: int) : Lemma (requires ( x1 * x2 + y1 * y2 == 1 /\ y1 == 0 )) (ensures ( x1 == 1 /\ x2 == 1 )) = () #set-options "--z3cliopt smt.arith.nl=false" let int_semiring () = FStar.Tactics.CanonCommSemiring.int_semiring (); FStar.Tactics.trefl (); FStar.Tactics.qed () [@@erasable] noeq type bezout_t = { d: pos; q_n: nat; q_l: nat; u_n: int; u_l: int; } let bezout_prop' (n: nat) (l: nat) (d: pos) (q_n: nat) (q_l: nat) (u_n: int) (u_l: int) : Tot prop = n == d * q_n /\ l == d * q_l /\ d == n * u_n + l * u_l let bezout_prop (n: nat) (l: nat) (b: bezout_t) : Tot prop = bezout_prop' n l b.d b.q_n b.q_l b.u_n b.u_l let bezout (n: nat) (l: nat) : Tot Type = (b: bezout_t { bezout_prop n l b }) #restart-solver let rec mk_bezout (n: pos) (l: nat) : Pure (bezout n l) (requires (l < n)) (ensures (fun _ -> True)) (decreases l) = if l = 0 then begin let d : pos = n in let q_n : nat = 1 in let q_l : nat = 0 in let u_n : int = 1 in let u_l : int = 0 in let res = { d = d; q_n = q_n; q_l = q_l; u_n = u_n; u_l = u_l; } in assert (eq2 #int n (d * q_n)) by (int_semiring ()); assert (eq2 #int 0 (d * q_l)) by (int_semiring ()); assert (eq2 #int d (n * 1 + 0 * res.u_l)) by (int_semiring ()); res end else begin let lpre = n % l in let ql = n / l in euclidean_division_definition n l; let bpre = mk_bezout l lpre in let d = bpre.d in let q_l = bpre.q_n in let qpre_lpre = bpre.q_l in let upre_l = bpre.u_n in let upre_lpre = bpre.u_l in let n_alt0 = l * ql + lpre in assert (n == n_alt0); let l_alt = d * q_l in let lpre_alt1 = d * qpre_lpre in let n_alt1 = l_alt * ql + lpre_alt1 in assert (n_alt1 == n); let q_n = q_l * ql + qpre_lpre in assert (eq2 #int n_alt1 (d * q_n)) by (int_semiring ()); let lpre_alt2 = n + - l * ql in assert (lpre_alt2 == lpre); let d_alt = l * upre_l + lpre_alt2 * upre_lpre in assert (d_alt == d); let u_l = upre_l + - ql * upre_lpre in assert (eq2 #int (n * upre_lpre + l * u_l) d_alt) by (int_semiring ()); let res = { d = d; q_n = q_n; q_l = q_l; u_n = upre_lpre; u_l = u_l; } in res end let bezout_q_eq (n: nat) (l: nat) (bz: bezout n l) : Lemma (bz.q_n == n / bz.d) [SMTPat (bezout_prop n l bz); SMTPat bz.q_n] = cancel_mul_div bz.q_n bz.d let rec iter_fun (#t: Type) (f: (t -> GTot t)) (n: nat) (x: t) : GTot t (decreases n) = if n = 0 then x else iter_fun f (n - 1) (f x) let nat_up_to (n: nat) : Tot Type = (i: nat { i < n }) let jump (n: pos) (l: nat) (x: nat_up_to n) : GTot (nat_up_to n) = (x + l) % n #restart-solver let jump_mod_d (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Lemma (jump n l x % b.d == x % b.d) = let x' = jump n l x in let x'q = (x + l) / n in euclidean_division_definition (x + l) n; let l_alt = b.d * b.q_l in assert (l_alt == l); let n_alt = b.d * b.q_n in assert (n_alt == n); let x'_alt = x + l_alt + - x'q * n_alt in assert (x'_alt == x'); let qx = b.q_l + - x'q * b.q_n in assert (eq2 #int x'_alt (x + qx * b.d)) by (int_semiring ()); lemma_mod_plus x qx b.d let rec jump_iter_mod_d (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) (k: nat) : Lemma (ensures (iter_fun #(nat_up_to n) (jump n l) k x % b.d == x % b.d)) (decreases k) = if k = 0 then () else begin jump_mod_d n l b x; jump_iter_mod_d n l b (jump n l x) (k - 1) end (* Coverage *) let rec jump_iter (n: pos) (l: nat) (x: nat_up_to n) (k: nat) : Lemma (ensures (iter_fun #(nat_up_to n) (jump n l) k x == (x + k * l) % n)) (decreases k) = if k = 0 then begin assert (eq2 #int (x + 0 * l) x) by (int_semiring ()); small_mod x n end else begin let k' = k - 1 in assert (eq2 #int (x + (k' + 1) * l) ((x + l) + k' * l)) by (int_semiring ()); jump_iter n l ((x + l) % n) k'; lemma_mod_add_distr (k' * l) (x + l) n end let bezout_pos_le (n: pos) (l: nat) (b: bezout n l) : Lemma (b.d <= n /\ b.q_n > 0) [SMTPat (bezout_prop n l b)] = lemma_pos_mul_pos_args b.q_n b.d #restart-solver [@@"opaque_to_smt"] irreducible let jump_coverage (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Ghost nat (requires True) (ensures (fun k -> x == iter_fun (jump n l) k (x % b.d) )) = let i = x % b.d in let qx = x / b.d in euclidean_division_definition x b.d; let k1 = qx * b.u_l in let m = qx * b.u_n in assert (eq2 #int (qx * (n * b.u_n + l * b.u_l) + i) (i + k1 * l + m * n)) by (int_semiring ()); assert (x == i + k1 * l + m * n); small_mod x n; lemma_mod_plus (i + k1 * l) m n; assert (x == (i + k1 * l) % n); let k = k1 % n in let qk = k1 / n in euclidean_division_definition k1 n; assert (i + (qk * n + k) * l == i + k * l + (qk * l) * n) by (int_semiring ()); lemma_mod_plus (i + k * l) (qk * l) n; assert (eq2 #int x ((i + k * l) % n)); jump_iter n l i k; k [@@"opaque_to_smt"] irreducible let rec minimal_exists' (p: (nat -> GTot bool)) (n: nat) (i: nat) : Ghost nat (requires ( p n == true /\ i <= n /\ (forall (j: nat) . j < i ==> p j == false) )) (ensures (fun k -> p k == true /\ (forall (j: nat) . j < k ==> p j == false) )) (decreases (n - i)) = if p i then i else minimal_exists' p n (i + 1) [@@"opaque_to_smt"] irreducible let minimal_exists (p: (nat -> GTot bool)) (n: nat) : Ghost nat (requires ( p n == true )) (ensures (fun k -> p k == true /\ (forall (j: nat) . j < k ==> p j == false) )) = minimal_exists' p n 0 [@@"opaque_to_smt"] irreducible let jump_coverage_strong (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Ghost nat (requires True) (ensures (fun k -> x == iter_fun (jump n l) k (x % b.d) /\ (forall (k': nat) . k' < k ==> (~ (x == iter_fun (jump n l) k' (x % b.d)))) )) = let k' = jump_coverage n l b x in minimal_exists (fun k -> x = iter_fun (jump n l) k (x % b.d)) k' #restart-solver let jump_iter_mod_q (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) (k: nat) : Lemma (ensures ( b.q_n > 0 /\ iter_fun (jump n l) (k % b.q_n) x == iter_fun (jump n l) k x )) = assert (b.q_n > 0); let k' = k % b.q_n in let qk = k / b.q_n in euclidean_division_definition k b.q_n; jump_iter n l x k'; jump_iter n l x k; assert (eq2 #int (x + (qk * b.q_n + k') * (b.d * b.q_l)) (x + k' * (b.d * b.q_l) + (qk * b.q_l) * (b.d * b.q_n))) by (int_semiring ()); assert (x + k * l == x + k' * l + (qk * b.q_l) * n); lemma_mod_plus (x + k' * l) (qk * b.q_l) n let jump_coverage_strong_bound (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Lemma (b.q_n > 0 /\ jump_coverage_strong n l b x < b.q_n ) [SMTPat (jump_coverage_strong n l b x)] = let k = jump_coverage_strong n l b x in jump_iter_mod_q n l b (x % b.d) k #restart-solver [@@"opaque_to_smt"] irreducible let mod_eq_elim (n: pos) (x1 x2: int) : Ghost int (requires (x1 % n == x2 % n)) (ensures (fun k -> x1 - x2 == k * n)) = euclidean_division_definition x1 n; euclidean_division_definition x2 n; let q1 = x1 / n in let q2 = x2 / n in let k = q1 + - q2 in let r = x1 % n in assert (q1 * n + r + - (q2 * n + r) == k * n) by (int_semiring ()); k let mod_eq_intro (n: pos) (x1 x2: int) (k: int) : Lemma (requires (x1 - x2 == k * n)) (ensures (x1 % n == x2 % n)) = lemma_mod_plus x2 k n #restart-solver [@@"opaque_to_smt"] irreducible let gauss (n: pos) (l: pos) // necessary here (b: bezout n l) (kl kn: int) : Ghost int (requires ( kl * l == kn * n )) (ensures (fun k -> kl == k * b.q_n )) = assert ((b.d * b.q_n) * b.u_n + (b.d * b.q_l) * b.u_l == b.d * (b.u_n * b.q_n + b.u_l * b.q_l)) by (int_semiring ()); assert (b.d == b.d * 1) by (int_semiring ()); assert (b.d * (b.u_n * b.q_n + b.u_l * b.q_l) == b.d * 1); lemma_mult_reg_l b.d (b.u_n * b.q_n + b.u_l * b.q_l) 1; assert (b.u_n * b.q_n + b.u_l * b.q_l == 1); if b.u_l = 0 then begin lemma_bezout_one_zero b.u_n b.q_n b.u_l b.q_l; assert (b.q_n == 1); assert (kl * 1 == kl) by (int_semiring ()); kl end else begin assert (kl * (b.d * b.q_l) == kn * (b.d * b.q_n)); assert (kl * (b.d * b.q_l) == b.d * (kl * b.q_l)) by (int_semiring ()); assert (kn * (b.d * b.q_n) == b.d * (kn * b.q_n)) by (int_semiring ()); assert (b.d * (kl * b.q_l) == b.d * (kn * b.q_n)); lemma_mult_reg_l b.d (kl * b.q_l) (kn * b.q_n); assert (kl * b.q_l == kn * b.q_n); assert (b.u_l * (kl * b.q_l) == b.u_l * (kn * b.q_n)); assert (b.u_l * (kl * b.q_l) == kl * (b.u_l * b.q_l)) by (int_semiring ()); assert (b.u_l * (kn * b.q_n) == (kn * b.u_l) * b.q_n) by (int_semiring ()); assert (kl * (b.u_l * b.q_l) == (kn * b.u_l) * b.q_n); assert (kl * (1 + - (b.u_n * b.q_n)) == kl + - kl * b.u_n * b.q_n) by (int_semiring ()); assert (kl * b.u_n * b.q_n + (kn * b.u_l) * b.q_n == (kn * b.u_l + kl * b.u_n) * b.q_n) by (int_semiring ()); kn * b.u_l + kl * b.u_n end let jump_iter_mod_q_inj_weak (n: pos) (l: pos) (b: bezout n l) (x: nat_up_to n) (k1 k2: nat) : Lemma (requires ( iter_fun (jump n l) k1 x == iter_fun (jump n l) k2 x )) (ensures ( b.q_n > 0 /\ k1 % b.q_n == k2 % b.q_n )) = jump_iter n l x k1; jump_iter n l x k2; let kn = mod_eq_elim n (x + k1 * l) (x + k2 * l) in assert ((k1 + - k2) * l == (k1 * l + - (k2 * l))) by (int_semiring ()); let kq = gauss n l b (k1 + - k2) kn in mod_eq_intro b.q_n k1 k2 kq
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.CanonCommSemiring.fst.checked", "FStar.Tactics.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Steel.ST.GenArraySwap.Proof.fst" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.GenArraySwap", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.GenArraySwap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
n: Prims.nat -> l: Prims.nat -> b: Steel.ST.GenArraySwap.Proof.bezout_t -> i1: Prims.nat -> i2: Prims.nat -> k1: Prims.nat -> k2: Prims.nat -> FStar.Pervasives.Lemma (requires n > 0 /\ l > 0 /\ Steel.ST.GenArraySwap.Proof.bezout_prop n l b /\ i1 < Mkbezout_t?.d b /\ i2 < Mkbezout_t?.d b /\ k1 < Mkbezout_t?.q_n b /\ k2 < Mkbezout_t?.q_n b /\ Steel.ST.GenArraySwap.Proof.iter_fun (Steel.ST.GenArraySwap.Proof.jump n l) k1 i1 == Steel.ST.GenArraySwap.Proof.iter_fun (Steel.ST.GenArraySwap.Proof.jump n l) k2 i2) (ensures i1 == i2 /\ k1 == k2) [ SMTPat (Steel.ST.GenArraySwap.Proof.iter_fun (Steel.ST.GenArraySwap.Proof.jump n l) k1 i1); SMTPat (Steel.ST.GenArraySwap.Proof.iter_fun (Steel.ST.GenArraySwap.Proof.jump n l) k2 i2); SMTPat (Steel.ST.GenArraySwap.Proof.bezout_prop n l b) ]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.nat", "Steel.ST.GenArraySwap.Proof.bezout_t", "FStar.Math.Lemmas.small_mod", "Steel.ST.GenArraySwap.Proof.__proj__Mkbezout_t__item__q_n", "Prims.unit", "Steel.ST.GenArraySwap.Proof.jump_iter_mod_q_inj_weak", "Steel.ST.GenArraySwap.Proof.__proj__Mkbezout_t__item__d", "Steel.ST.GenArraySwap.Proof.jump_iter_mod_d", "Prims.l_and", "Prims.b2t", "Prims.op_GreaterThan", "Steel.ST.GenArraySwap.Proof.bezout_prop", "Prims.op_LessThan", "Prims.eq2", "Steel.ST.GenArraySwap.Proof.nat_up_to", "Steel.ST.GenArraySwap.Proof.iter_fun", "Steel.ST.GenArraySwap.Proof.jump", "Prims.squash", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat", "Prims.prop", "Prims.Nil" ]
[]
true
false
true
false
false
let jump_iter_inj (n l: nat) (b: bezout_t) (i1 i2 k1 k2: nat) : Lemma (requires (n > 0 /\ l > 0 /\ bezout_prop n l b /\ i1 < b.d /\ i2 < b.d /\ k1 < b.q_n /\ k2 < b.q_n /\ iter_fun (jump n l) k1 i1 == iter_fun (jump n l) k2 i2)) (ensures (i1 == i2 /\ k1 == k2)) [ SMTPat (iter_fun (jump n l) k1 i1); SMTPat (iter_fun (jump n l) k2 i2); SMTPat (bezout_prop n l b) ] =
jump_iter_mod_d n l b i1 k1; jump_iter_mod_d n l b i2 k2; small_mod i1 b.d; small_mod i2 b.d; jump_iter_mod_q_inj_weak n l b i1 k1 k2; small_mod k1 b.q_n; small_mod k2 b.q_n
false
Hacl.Curve25519_64.fsti
Hacl.Curve25519_64.p
val p : Prims.logical
let p = Vale.X64.CPU_Features_s.(adx_enabled /\ bmi2_enabled)
{ "file_name": "code/curve25519/Hacl.Curve25519_64.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 61, "end_line": 7, "start_col": 0, "start_line": 7 }
module Hacl.Curve25519_64 open Hacl.Impl.Curve25519.Generic open Hacl.Impl.Curve25519.Fields
{ "checked_file": "/", "dependencies": [ "Vale.X64.CPU_Features_s.fst.checked", "prims.fst.checked", "Hacl.Impl.Curve25519.Generic.fsti.checked", "Hacl.Impl.Curve25519.Fields.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Curve25519_64.fsti" }
[ { "abbrev": false, "full_module": "Hacl.Impl.Curve25519.Fields", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Curve25519.Generic", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Prims.logical
Prims.Tot
[ "total" ]
[]
[ "Prims.l_and", "Prims.b2t", "Vale.X64.CPU_Features_s.adx_enabled", "Vale.X64.CPU_Features_s.bmi2_enabled" ]
[]
false
false
false
true
true
let p =
let open Vale.X64.CPU_Features_s in adx_enabled /\ bmi2_enabled
false
Steel.ST.GenArraySwap.Proof.fst
Steel.ST.GenArraySwap.Proof.jump_iter_elim
val jump_iter_elim (n: pos) (p: (nat_up_to n -> prop)) (l: nat) (b: bezout n l) : Lemma (requires (forall (i: nat_up_to b.d) (k: nat_up_to b.q_n). p (iter_fun (jump n l) k i))) (ensures (forall (x: nat_up_to n). p x))
val jump_iter_elim (n: pos) (p: (nat_up_to n -> prop)) (l: nat) (b: bezout n l) : Lemma (requires (forall (i: nat_up_to b.d) (k: nat_up_to b.q_n). p (iter_fun (jump n l) k i))) (ensures (forall (x: nat_up_to n). p x))
let jump_iter_elim (n: pos) (p: nat_up_to n -> prop) (l: nat) (b: bezout n l) : Lemma (requires ( forall (i: nat_up_to b.d) (k: nat_up_to b.q_n) . p (iter_fun (jump n l) k i) )) (ensures ( forall (x: nat_up_to n) . p x )) = let prf (x: nat_up_to n) : Lemma (p x) = let i : nat_up_to b.d = x % b.d in let k' = jump_coverage_strong n l b x in jump_coverage_strong_bound n l b x; assert (p (iter_fun (jump n l) k' i)) in Classical.forall_intro prf
{ "file_name": "lib/steel/Steel.ST.GenArraySwap.Proof.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 28, "end_line": 530, "start_col": 0, "start_line": 508 }
module Steel.ST.GenArraySwap.Proof open FStar.Math.Lemmas open FStar.Mul let lemma_mod_lt (a:int) (b:pos) : Lemma (let r = a % b in 0 <= r /\ r < b) [SMTPat (a % b)] = () let lemma_mul_nat_nat_is_nat (a b: nat) : Lemma (a * b >= 0) [SMTPat (a * b)] = () let lemma_pos_mul_pos_args (a: nat) (b: nat) : Lemma (requires (a * b > 0)) (ensures (a > 0 /\ b > 0 /\ a <= a * b /\ b <= a * b /\ a * b == b * a)) = () let lemma_div_nat (a: nat) (b: pos) : Lemma (a / b >= 0) [SMTPat (a / b)] = () let lemma_mult_reg_l (k: int) (x1 x2: int) : Lemma (requires ( k * x1 == k * x2 /\ k <> 0 )) (ensures ( x1 == x2 )) = () let lemma_bezout_one_zero (x1: int) (x2: nat) (y1 y2: int) : Lemma (requires ( x1 * x2 + y1 * y2 == 1 /\ y1 == 0 )) (ensures ( x1 == 1 /\ x2 == 1 )) = () #set-options "--z3cliopt smt.arith.nl=false" let int_semiring () = FStar.Tactics.CanonCommSemiring.int_semiring (); FStar.Tactics.trefl (); FStar.Tactics.qed () [@@erasable] noeq type bezout_t = { d: pos; q_n: nat; q_l: nat; u_n: int; u_l: int; } let bezout_prop' (n: nat) (l: nat) (d: pos) (q_n: nat) (q_l: nat) (u_n: int) (u_l: int) : Tot prop = n == d * q_n /\ l == d * q_l /\ d == n * u_n + l * u_l let bezout_prop (n: nat) (l: nat) (b: bezout_t) : Tot prop = bezout_prop' n l b.d b.q_n b.q_l b.u_n b.u_l let bezout (n: nat) (l: nat) : Tot Type = (b: bezout_t { bezout_prop n l b }) #restart-solver let rec mk_bezout (n: pos) (l: nat) : Pure (bezout n l) (requires (l < n)) (ensures (fun _ -> True)) (decreases l) = if l = 0 then begin let d : pos = n in let q_n : nat = 1 in let q_l : nat = 0 in let u_n : int = 1 in let u_l : int = 0 in let res = { d = d; q_n = q_n; q_l = q_l; u_n = u_n; u_l = u_l; } in assert (eq2 #int n (d * q_n)) by (int_semiring ()); assert (eq2 #int 0 (d * q_l)) by (int_semiring ()); assert (eq2 #int d (n * 1 + 0 * res.u_l)) by (int_semiring ()); res end else begin let lpre = n % l in let ql = n / l in euclidean_division_definition n l; let bpre = mk_bezout l lpre in let d = bpre.d in let q_l = bpre.q_n in let qpre_lpre = bpre.q_l in let upre_l = bpre.u_n in let upre_lpre = bpre.u_l in let n_alt0 = l * ql + lpre in assert (n == n_alt0); let l_alt = d * q_l in let lpre_alt1 = d * qpre_lpre in let n_alt1 = l_alt * ql + lpre_alt1 in assert (n_alt1 == n); let q_n = q_l * ql + qpre_lpre in assert (eq2 #int n_alt1 (d * q_n)) by (int_semiring ()); let lpre_alt2 = n + - l * ql in assert (lpre_alt2 == lpre); let d_alt = l * upre_l + lpre_alt2 * upre_lpre in assert (d_alt == d); let u_l = upre_l + - ql * upre_lpre in assert (eq2 #int (n * upre_lpre + l * u_l) d_alt) by (int_semiring ()); let res = { d = d; q_n = q_n; q_l = q_l; u_n = upre_lpre; u_l = u_l; } in res end let bezout_q_eq (n: nat) (l: nat) (bz: bezout n l) : Lemma (bz.q_n == n / bz.d) [SMTPat (bezout_prop n l bz); SMTPat bz.q_n] = cancel_mul_div bz.q_n bz.d let rec iter_fun (#t: Type) (f: (t -> GTot t)) (n: nat) (x: t) : GTot t (decreases n) = if n = 0 then x else iter_fun f (n - 1) (f x) let nat_up_to (n: nat) : Tot Type = (i: nat { i < n }) let jump (n: pos) (l: nat) (x: nat_up_to n) : GTot (nat_up_to n) = (x + l) % n #restart-solver let jump_mod_d (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Lemma (jump n l x % b.d == x % b.d) = let x' = jump n l x in let x'q = (x + l) / n in euclidean_division_definition (x + l) n; let l_alt = b.d * b.q_l in assert (l_alt == l); let n_alt = b.d * b.q_n in assert (n_alt == n); let x'_alt = x + l_alt + - x'q * n_alt in assert (x'_alt == x'); let qx = b.q_l + - x'q * b.q_n in assert (eq2 #int x'_alt (x + qx * b.d)) by (int_semiring ()); lemma_mod_plus x qx b.d let rec jump_iter_mod_d (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) (k: nat) : Lemma (ensures (iter_fun #(nat_up_to n) (jump n l) k x % b.d == x % b.d)) (decreases k) = if k = 0 then () else begin jump_mod_d n l b x; jump_iter_mod_d n l b (jump n l x) (k - 1) end (* Coverage *) let rec jump_iter (n: pos) (l: nat) (x: nat_up_to n) (k: nat) : Lemma (ensures (iter_fun #(nat_up_to n) (jump n l) k x == (x + k * l) % n)) (decreases k) = if k = 0 then begin assert (eq2 #int (x + 0 * l) x) by (int_semiring ()); small_mod x n end else begin let k' = k - 1 in assert (eq2 #int (x + (k' + 1) * l) ((x + l) + k' * l)) by (int_semiring ()); jump_iter n l ((x + l) % n) k'; lemma_mod_add_distr (k' * l) (x + l) n end let bezout_pos_le (n: pos) (l: nat) (b: bezout n l) : Lemma (b.d <= n /\ b.q_n > 0) [SMTPat (bezout_prop n l b)] = lemma_pos_mul_pos_args b.q_n b.d #restart-solver [@@"opaque_to_smt"] irreducible let jump_coverage (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Ghost nat (requires True) (ensures (fun k -> x == iter_fun (jump n l) k (x % b.d) )) = let i = x % b.d in let qx = x / b.d in euclidean_division_definition x b.d; let k1 = qx * b.u_l in let m = qx * b.u_n in assert (eq2 #int (qx * (n * b.u_n + l * b.u_l) + i) (i + k1 * l + m * n)) by (int_semiring ()); assert (x == i + k1 * l + m * n); small_mod x n; lemma_mod_plus (i + k1 * l) m n; assert (x == (i + k1 * l) % n); let k = k1 % n in let qk = k1 / n in euclidean_division_definition k1 n; assert (i + (qk * n + k) * l == i + k * l + (qk * l) * n) by (int_semiring ()); lemma_mod_plus (i + k * l) (qk * l) n; assert (eq2 #int x ((i + k * l) % n)); jump_iter n l i k; k [@@"opaque_to_smt"] irreducible let rec minimal_exists' (p: (nat -> GTot bool)) (n: nat) (i: nat) : Ghost nat (requires ( p n == true /\ i <= n /\ (forall (j: nat) . j < i ==> p j == false) )) (ensures (fun k -> p k == true /\ (forall (j: nat) . j < k ==> p j == false) )) (decreases (n - i)) = if p i then i else minimal_exists' p n (i + 1) [@@"opaque_to_smt"] irreducible let minimal_exists (p: (nat -> GTot bool)) (n: nat) : Ghost nat (requires ( p n == true )) (ensures (fun k -> p k == true /\ (forall (j: nat) . j < k ==> p j == false) )) = minimal_exists' p n 0 [@@"opaque_to_smt"] irreducible let jump_coverage_strong (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Ghost nat (requires True) (ensures (fun k -> x == iter_fun (jump n l) k (x % b.d) /\ (forall (k': nat) . k' < k ==> (~ (x == iter_fun (jump n l) k' (x % b.d)))) )) = let k' = jump_coverage n l b x in minimal_exists (fun k -> x = iter_fun (jump n l) k (x % b.d)) k' #restart-solver let jump_iter_mod_q (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) (k: nat) : Lemma (ensures ( b.q_n > 0 /\ iter_fun (jump n l) (k % b.q_n) x == iter_fun (jump n l) k x )) = assert (b.q_n > 0); let k' = k % b.q_n in let qk = k / b.q_n in euclidean_division_definition k b.q_n; jump_iter n l x k'; jump_iter n l x k; assert (eq2 #int (x + (qk * b.q_n + k') * (b.d * b.q_l)) (x + k' * (b.d * b.q_l) + (qk * b.q_l) * (b.d * b.q_n))) by (int_semiring ()); assert (x + k * l == x + k' * l + (qk * b.q_l) * n); lemma_mod_plus (x + k' * l) (qk * b.q_l) n let jump_coverage_strong_bound (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Lemma (b.q_n > 0 /\ jump_coverage_strong n l b x < b.q_n ) [SMTPat (jump_coverage_strong n l b x)] = let k = jump_coverage_strong n l b x in jump_iter_mod_q n l b (x % b.d) k #restart-solver [@@"opaque_to_smt"] irreducible let mod_eq_elim (n: pos) (x1 x2: int) : Ghost int (requires (x1 % n == x2 % n)) (ensures (fun k -> x1 - x2 == k * n)) = euclidean_division_definition x1 n; euclidean_division_definition x2 n; let q1 = x1 / n in let q2 = x2 / n in let k = q1 + - q2 in let r = x1 % n in assert (q1 * n + r + - (q2 * n + r) == k * n) by (int_semiring ()); k let mod_eq_intro (n: pos) (x1 x2: int) (k: int) : Lemma (requires (x1 - x2 == k * n)) (ensures (x1 % n == x2 % n)) = lemma_mod_plus x2 k n #restart-solver [@@"opaque_to_smt"] irreducible let gauss (n: pos) (l: pos) // necessary here (b: bezout n l) (kl kn: int) : Ghost int (requires ( kl * l == kn * n )) (ensures (fun k -> kl == k * b.q_n )) = assert ((b.d * b.q_n) * b.u_n + (b.d * b.q_l) * b.u_l == b.d * (b.u_n * b.q_n + b.u_l * b.q_l)) by (int_semiring ()); assert (b.d == b.d * 1) by (int_semiring ()); assert (b.d * (b.u_n * b.q_n + b.u_l * b.q_l) == b.d * 1); lemma_mult_reg_l b.d (b.u_n * b.q_n + b.u_l * b.q_l) 1; assert (b.u_n * b.q_n + b.u_l * b.q_l == 1); if b.u_l = 0 then begin lemma_bezout_one_zero b.u_n b.q_n b.u_l b.q_l; assert (b.q_n == 1); assert (kl * 1 == kl) by (int_semiring ()); kl end else begin assert (kl * (b.d * b.q_l) == kn * (b.d * b.q_n)); assert (kl * (b.d * b.q_l) == b.d * (kl * b.q_l)) by (int_semiring ()); assert (kn * (b.d * b.q_n) == b.d * (kn * b.q_n)) by (int_semiring ()); assert (b.d * (kl * b.q_l) == b.d * (kn * b.q_n)); lemma_mult_reg_l b.d (kl * b.q_l) (kn * b.q_n); assert (kl * b.q_l == kn * b.q_n); assert (b.u_l * (kl * b.q_l) == b.u_l * (kn * b.q_n)); assert (b.u_l * (kl * b.q_l) == kl * (b.u_l * b.q_l)) by (int_semiring ()); assert (b.u_l * (kn * b.q_n) == (kn * b.u_l) * b.q_n) by (int_semiring ()); assert (kl * (b.u_l * b.q_l) == (kn * b.u_l) * b.q_n); assert (kl * (1 + - (b.u_n * b.q_n)) == kl + - kl * b.u_n * b.q_n) by (int_semiring ()); assert (kl * b.u_n * b.q_n + (kn * b.u_l) * b.q_n == (kn * b.u_l + kl * b.u_n) * b.q_n) by (int_semiring ()); kn * b.u_l + kl * b.u_n end let jump_iter_mod_q_inj_weak (n: pos) (l: pos) (b: bezout n l) (x: nat_up_to n) (k1 k2: nat) : Lemma (requires ( iter_fun (jump n l) k1 x == iter_fun (jump n l) k2 x )) (ensures ( b.q_n > 0 /\ k1 % b.q_n == k2 % b.q_n )) = jump_iter n l x k1; jump_iter n l x k2; let kn = mod_eq_elim n (x + k1 * l) (x + k2 * l) in assert ((k1 + - k2) * l == (k1 * l + - (k2 * l))) by (int_semiring ()); let kq = gauss n l b (k1 + - k2) kn in mod_eq_intro b.q_n k1 k2 kq let jump_iter_inj (n: nat) (l: nat) (b: bezout_t) (i1 i2: nat) (k1 k2: nat) : Lemma (requires ( n > 0 /\ l > 0 /\ bezout_prop n l b /\ i1 < b.d /\ i2 < b.d /\ k1 < b.q_n /\ k2 < b.q_n /\ iter_fun (jump n l) k1 i1 == iter_fun (jump n l) k2 i2 )) (ensures ( i1 == i2 /\ k1 == k2 )) [SMTPat (iter_fun (jump n l) k1 i1); SMTPat (iter_fun (jump n l) k2 i2); SMTPat (bezout_prop n l b)] = jump_iter_mod_d n l b i1 k1; jump_iter_mod_d n l b i2 k2; small_mod i1 b.d; small_mod i2 b.d; jump_iter_mod_q_inj_weak n l b i1 k1 k2; small_mod k1 b.q_n; small_mod k2 b.q_n
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.CanonCommSemiring.fst.checked", "FStar.Tactics.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Steel.ST.GenArraySwap.Proof.fst" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.GenArraySwap", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.GenArraySwap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
n: Prims.pos -> p: (_: Steel.ST.GenArraySwap.Proof.nat_up_to n -> Prims.prop) -> l: Prims.nat -> b: Steel.ST.GenArraySwap.Proof.bezout n l -> FStar.Pervasives.Lemma (requires forall (i: Steel.ST.GenArraySwap.Proof.nat_up_to (Mkbezout_t?.d b)) (k: Steel.ST.GenArraySwap.Proof.nat_up_to (Mkbezout_t?.q_n b)). p (Steel.ST.GenArraySwap.Proof.iter_fun (Steel.ST.GenArraySwap.Proof.jump n l) k i)) (ensures forall (x: Steel.ST.GenArraySwap.Proof.nat_up_to n). p x)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.pos", "Steel.ST.GenArraySwap.Proof.nat_up_to", "Prims.prop", "Prims.nat", "Steel.ST.GenArraySwap.Proof.bezout", "FStar.Classical.forall_intro", "Prims.unit", "Prims.l_True", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern", "Prims._assert", "Steel.ST.GenArraySwap.Proof.iter_fun", "Steel.ST.GenArraySwap.Proof.jump", "Steel.ST.GenArraySwap.Proof.jump_coverage_strong_bound", "Steel.ST.GenArraySwap.Proof.jump_coverage_strong", "Steel.ST.GenArraySwap.Proof.__proj__Mkbezout_t__item__d", "Prims.op_Modulus", "Prims.l_Forall", "Steel.ST.GenArraySwap.Proof.__proj__Mkbezout_t__item__q_n" ]
[]
false
false
true
false
false
let jump_iter_elim (n: pos) (p: (nat_up_to n -> prop)) (l: nat) (b: bezout n l) : Lemma (requires (forall (i: nat_up_to b.d) (k: nat_up_to b.q_n). p (iter_fun (jump n l) k i))) (ensures (forall (x: nat_up_to n). p x)) =
let prf (x: nat_up_to n) : Lemma (p x) = let i:nat_up_to b.d = x % b.d in let k' = jump_coverage_strong n l b x in jump_coverage_strong_bound n l b x; assert (p (iter_fun (jump n l) k' i)) in Classical.forall_intro prf
false
Steel.ST.GenArraySwap.Proof.fst
Steel.ST.GenArraySwap.Proof.jump_jump_iter_pred_q
val jump_jump_iter_pred_q (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) (j: nat_up_to b.q_n) : Lemma (requires (j == b.q_n - 1)) (ensures (jump n l (iter_fun (jump n l) j x) == x)) [SMTPat (jump n l (iter_fun (jump n l) j x)); SMTPat (bezout_prop n l b)]
val jump_jump_iter_pred_q (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) (j: nat_up_to b.q_n) : Lemma (requires (j == b.q_n - 1)) (ensures (jump n l (iter_fun (jump n l) j x) == x)) [SMTPat (jump n l (iter_fun (jump n l) j x)); SMTPat (bezout_prop n l b)]
let jump_jump_iter_pred_q (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) (j: nat_up_to b.q_n) : Lemma (requires ( j == b.q_n - 1 )) (ensures ( jump n l (iter_fun (jump n l) j x) == x )) [SMTPat (jump n l (iter_fun (jump n l) j x)); SMTPat (bezout_prop n l b)] = jump_iter_q n l b x
{ "file_name": "lib/steel/Steel.ST.GenArraySwap.Proof.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 21, "end_line": 592, "start_col": 0, "start_line": 578 }
module Steel.ST.GenArraySwap.Proof open FStar.Math.Lemmas open FStar.Mul let lemma_mod_lt (a:int) (b:pos) : Lemma (let r = a % b in 0 <= r /\ r < b) [SMTPat (a % b)] = () let lemma_mul_nat_nat_is_nat (a b: nat) : Lemma (a * b >= 0) [SMTPat (a * b)] = () let lemma_pos_mul_pos_args (a: nat) (b: nat) : Lemma (requires (a * b > 0)) (ensures (a > 0 /\ b > 0 /\ a <= a * b /\ b <= a * b /\ a * b == b * a)) = () let lemma_div_nat (a: nat) (b: pos) : Lemma (a / b >= 0) [SMTPat (a / b)] = () let lemma_mult_reg_l (k: int) (x1 x2: int) : Lemma (requires ( k * x1 == k * x2 /\ k <> 0 )) (ensures ( x1 == x2 )) = () let lemma_bezout_one_zero (x1: int) (x2: nat) (y1 y2: int) : Lemma (requires ( x1 * x2 + y1 * y2 == 1 /\ y1 == 0 )) (ensures ( x1 == 1 /\ x2 == 1 )) = () #set-options "--z3cliopt smt.arith.nl=false" let int_semiring () = FStar.Tactics.CanonCommSemiring.int_semiring (); FStar.Tactics.trefl (); FStar.Tactics.qed () [@@erasable] noeq type bezout_t = { d: pos; q_n: nat; q_l: nat; u_n: int; u_l: int; } let bezout_prop' (n: nat) (l: nat) (d: pos) (q_n: nat) (q_l: nat) (u_n: int) (u_l: int) : Tot prop = n == d * q_n /\ l == d * q_l /\ d == n * u_n + l * u_l let bezout_prop (n: nat) (l: nat) (b: bezout_t) : Tot prop = bezout_prop' n l b.d b.q_n b.q_l b.u_n b.u_l let bezout (n: nat) (l: nat) : Tot Type = (b: bezout_t { bezout_prop n l b }) #restart-solver let rec mk_bezout (n: pos) (l: nat) : Pure (bezout n l) (requires (l < n)) (ensures (fun _ -> True)) (decreases l) = if l = 0 then begin let d : pos = n in let q_n : nat = 1 in let q_l : nat = 0 in let u_n : int = 1 in let u_l : int = 0 in let res = { d = d; q_n = q_n; q_l = q_l; u_n = u_n; u_l = u_l; } in assert (eq2 #int n (d * q_n)) by (int_semiring ()); assert (eq2 #int 0 (d * q_l)) by (int_semiring ()); assert (eq2 #int d (n * 1 + 0 * res.u_l)) by (int_semiring ()); res end else begin let lpre = n % l in let ql = n / l in euclidean_division_definition n l; let bpre = mk_bezout l lpre in let d = bpre.d in let q_l = bpre.q_n in let qpre_lpre = bpre.q_l in let upre_l = bpre.u_n in let upre_lpre = bpre.u_l in let n_alt0 = l * ql + lpre in assert (n == n_alt0); let l_alt = d * q_l in let lpre_alt1 = d * qpre_lpre in let n_alt1 = l_alt * ql + lpre_alt1 in assert (n_alt1 == n); let q_n = q_l * ql + qpre_lpre in assert (eq2 #int n_alt1 (d * q_n)) by (int_semiring ()); let lpre_alt2 = n + - l * ql in assert (lpre_alt2 == lpre); let d_alt = l * upre_l + lpre_alt2 * upre_lpre in assert (d_alt == d); let u_l = upre_l + - ql * upre_lpre in assert (eq2 #int (n * upre_lpre + l * u_l) d_alt) by (int_semiring ()); let res = { d = d; q_n = q_n; q_l = q_l; u_n = upre_lpre; u_l = u_l; } in res end let bezout_q_eq (n: nat) (l: nat) (bz: bezout n l) : Lemma (bz.q_n == n / bz.d) [SMTPat (bezout_prop n l bz); SMTPat bz.q_n] = cancel_mul_div bz.q_n bz.d let rec iter_fun (#t: Type) (f: (t -> GTot t)) (n: nat) (x: t) : GTot t (decreases n) = if n = 0 then x else iter_fun f (n - 1) (f x) let nat_up_to (n: nat) : Tot Type = (i: nat { i < n }) let jump (n: pos) (l: nat) (x: nat_up_to n) : GTot (nat_up_to n) = (x + l) % n #restart-solver let jump_mod_d (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Lemma (jump n l x % b.d == x % b.d) = let x' = jump n l x in let x'q = (x + l) / n in euclidean_division_definition (x + l) n; let l_alt = b.d * b.q_l in assert (l_alt == l); let n_alt = b.d * b.q_n in assert (n_alt == n); let x'_alt = x + l_alt + - x'q * n_alt in assert (x'_alt == x'); let qx = b.q_l + - x'q * b.q_n in assert (eq2 #int x'_alt (x + qx * b.d)) by (int_semiring ()); lemma_mod_plus x qx b.d let rec jump_iter_mod_d (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) (k: nat) : Lemma (ensures (iter_fun #(nat_up_to n) (jump n l) k x % b.d == x % b.d)) (decreases k) = if k = 0 then () else begin jump_mod_d n l b x; jump_iter_mod_d n l b (jump n l x) (k - 1) end (* Coverage *) let rec jump_iter (n: pos) (l: nat) (x: nat_up_to n) (k: nat) : Lemma (ensures (iter_fun #(nat_up_to n) (jump n l) k x == (x + k * l) % n)) (decreases k) = if k = 0 then begin assert (eq2 #int (x + 0 * l) x) by (int_semiring ()); small_mod x n end else begin let k' = k - 1 in assert (eq2 #int (x + (k' + 1) * l) ((x + l) + k' * l)) by (int_semiring ()); jump_iter n l ((x + l) % n) k'; lemma_mod_add_distr (k' * l) (x + l) n end let bezout_pos_le (n: pos) (l: nat) (b: bezout n l) : Lemma (b.d <= n /\ b.q_n > 0) [SMTPat (bezout_prop n l b)] = lemma_pos_mul_pos_args b.q_n b.d #restart-solver [@@"opaque_to_smt"] irreducible let jump_coverage (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Ghost nat (requires True) (ensures (fun k -> x == iter_fun (jump n l) k (x % b.d) )) = let i = x % b.d in let qx = x / b.d in euclidean_division_definition x b.d; let k1 = qx * b.u_l in let m = qx * b.u_n in assert (eq2 #int (qx * (n * b.u_n + l * b.u_l) + i) (i + k1 * l + m * n)) by (int_semiring ()); assert (x == i + k1 * l + m * n); small_mod x n; lemma_mod_plus (i + k1 * l) m n; assert (x == (i + k1 * l) % n); let k = k1 % n in let qk = k1 / n in euclidean_division_definition k1 n; assert (i + (qk * n + k) * l == i + k * l + (qk * l) * n) by (int_semiring ()); lemma_mod_plus (i + k * l) (qk * l) n; assert (eq2 #int x ((i + k * l) % n)); jump_iter n l i k; k [@@"opaque_to_smt"] irreducible let rec minimal_exists' (p: (nat -> GTot bool)) (n: nat) (i: nat) : Ghost nat (requires ( p n == true /\ i <= n /\ (forall (j: nat) . j < i ==> p j == false) )) (ensures (fun k -> p k == true /\ (forall (j: nat) . j < k ==> p j == false) )) (decreases (n - i)) = if p i then i else minimal_exists' p n (i + 1) [@@"opaque_to_smt"] irreducible let minimal_exists (p: (nat -> GTot bool)) (n: nat) : Ghost nat (requires ( p n == true )) (ensures (fun k -> p k == true /\ (forall (j: nat) . j < k ==> p j == false) )) = minimal_exists' p n 0 [@@"opaque_to_smt"] irreducible let jump_coverage_strong (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Ghost nat (requires True) (ensures (fun k -> x == iter_fun (jump n l) k (x % b.d) /\ (forall (k': nat) . k' < k ==> (~ (x == iter_fun (jump n l) k' (x % b.d)))) )) = let k' = jump_coverage n l b x in minimal_exists (fun k -> x = iter_fun (jump n l) k (x % b.d)) k' #restart-solver let jump_iter_mod_q (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) (k: nat) : Lemma (ensures ( b.q_n > 0 /\ iter_fun (jump n l) (k % b.q_n) x == iter_fun (jump n l) k x )) = assert (b.q_n > 0); let k' = k % b.q_n in let qk = k / b.q_n in euclidean_division_definition k b.q_n; jump_iter n l x k'; jump_iter n l x k; assert (eq2 #int (x + (qk * b.q_n + k') * (b.d * b.q_l)) (x + k' * (b.d * b.q_l) + (qk * b.q_l) * (b.d * b.q_n))) by (int_semiring ()); assert (x + k * l == x + k' * l + (qk * b.q_l) * n); lemma_mod_plus (x + k' * l) (qk * b.q_l) n let jump_coverage_strong_bound (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Lemma (b.q_n > 0 /\ jump_coverage_strong n l b x < b.q_n ) [SMTPat (jump_coverage_strong n l b x)] = let k = jump_coverage_strong n l b x in jump_iter_mod_q n l b (x % b.d) k #restart-solver [@@"opaque_to_smt"] irreducible let mod_eq_elim (n: pos) (x1 x2: int) : Ghost int (requires (x1 % n == x2 % n)) (ensures (fun k -> x1 - x2 == k * n)) = euclidean_division_definition x1 n; euclidean_division_definition x2 n; let q1 = x1 / n in let q2 = x2 / n in let k = q1 + - q2 in let r = x1 % n in assert (q1 * n + r + - (q2 * n + r) == k * n) by (int_semiring ()); k let mod_eq_intro (n: pos) (x1 x2: int) (k: int) : Lemma (requires (x1 - x2 == k * n)) (ensures (x1 % n == x2 % n)) = lemma_mod_plus x2 k n #restart-solver [@@"opaque_to_smt"] irreducible let gauss (n: pos) (l: pos) // necessary here (b: bezout n l) (kl kn: int) : Ghost int (requires ( kl * l == kn * n )) (ensures (fun k -> kl == k * b.q_n )) = assert ((b.d * b.q_n) * b.u_n + (b.d * b.q_l) * b.u_l == b.d * (b.u_n * b.q_n + b.u_l * b.q_l)) by (int_semiring ()); assert (b.d == b.d * 1) by (int_semiring ()); assert (b.d * (b.u_n * b.q_n + b.u_l * b.q_l) == b.d * 1); lemma_mult_reg_l b.d (b.u_n * b.q_n + b.u_l * b.q_l) 1; assert (b.u_n * b.q_n + b.u_l * b.q_l == 1); if b.u_l = 0 then begin lemma_bezout_one_zero b.u_n b.q_n b.u_l b.q_l; assert (b.q_n == 1); assert (kl * 1 == kl) by (int_semiring ()); kl end else begin assert (kl * (b.d * b.q_l) == kn * (b.d * b.q_n)); assert (kl * (b.d * b.q_l) == b.d * (kl * b.q_l)) by (int_semiring ()); assert (kn * (b.d * b.q_n) == b.d * (kn * b.q_n)) by (int_semiring ()); assert (b.d * (kl * b.q_l) == b.d * (kn * b.q_n)); lemma_mult_reg_l b.d (kl * b.q_l) (kn * b.q_n); assert (kl * b.q_l == kn * b.q_n); assert (b.u_l * (kl * b.q_l) == b.u_l * (kn * b.q_n)); assert (b.u_l * (kl * b.q_l) == kl * (b.u_l * b.q_l)) by (int_semiring ()); assert (b.u_l * (kn * b.q_n) == (kn * b.u_l) * b.q_n) by (int_semiring ()); assert (kl * (b.u_l * b.q_l) == (kn * b.u_l) * b.q_n); assert (kl * (1 + - (b.u_n * b.q_n)) == kl + - kl * b.u_n * b.q_n) by (int_semiring ()); assert (kl * b.u_n * b.q_n + (kn * b.u_l) * b.q_n == (kn * b.u_l + kl * b.u_n) * b.q_n) by (int_semiring ()); kn * b.u_l + kl * b.u_n end let jump_iter_mod_q_inj_weak (n: pos) (l: pos) (b: bezout n l) (x: nat_up_to n) (k1 k2: nat) : Lemma (requires ( iter_fun (jump n l) k1 x == iter_fun (jump n l) k2 x )) (ensures ( b.q_n > 0 /\ k1 % b.q_n == k2 % b.q_n )) = jump_iter n l x k1; jump_iter n l x k2; let kn = mod_eq_elim n (x + k1 * l) (x + k2 * l) in assert ((k1 + - k2) * l == (k1 * l + - (k2 * l))) by (int_semiring ()); let kq = gauss n l b (k1 + - k2) kn in mod_eq_intro b.q_n k1 k2 kq let jump_iter_inj (n: nat) (l: nat) (b: bezout_t) (i1 i2: nat) (k1 k2: nat) : Lemma (requires ( n > 0 /\ l > 0 /\ bezout_prop n l b /\ i1 < b.d /\ i2 < b.d /\ k1 < b.q_n /\ k2 < b.q_n /\ iter_fun (jump n l) k1 i1 == iter_fun (jump n l) k2 i2 )) (ensures ( i1 == i2 /\ k1 == k2 )) [SMTPat (iter_fun (jump n l) k1 i1); SMTPat (iter_fun (jump n l) k2 i2); SMTPat (bezout_prop n l b)] = jump_iter_mod_d n l b i1 k1; jump_iter_mod_d n l b i2 k2; small_mod i1 b.d; small_mod i2 b.d; jump_iter_mod_q_inj_weak n l b i1 k1 k2; small_mod k1 b.q_n; small_mod k2 b.q_n #restart-solver let jump_iter_elim (n: pos) (p: nat_up_to n -> prop) (l: nat) (b: bezout n l) : Lemma (requires ( forall (i: nat_up_to b.d) (k: nat_up_to b.q_n) . p (iter_fun (jump n l) k i) )) (ensures ( forall (x: nat_up_to n) . p x )) = let prf (x: nat_up_to n) : Lemma (p x) = let i : nat_up_to b.d = x % b.d in let k' = jump_coverage_strong n l b x in jump_coverage_strong_bound n l b x; assert (p (iter_fun (jump n l) k' i)) in Classical.forall_intro prf let jump_if (n: pos) (l: nat) (sq: squash (l < n)) (idx: nat_up_to n) : Lemma (jump n l idx == (if idx + l >= n then idx - (n - l) else idx + l)) = let idx' = (if idx + l >= n then idx - (n - l) else idx + l) in small_mod idx n; small_mod idx' n; lemma_mod_plus (idx + l) (-1) n let jump_iter_q (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Lemma (ensures ( iter_fun (jump n l) b.q_n x == x )) = cancel_mul_mod 1 b.q_n; jump_iter_mod_q n l b x b.q_n let rec iter_fun_add (#t: Type) (f: (t -> GTot t)) (n1 n2: nat) (x: t) : Lemma (ensures (iter_fun f n1 (iter_fun f n2 x) == iter_fun f (n1 + n2) x)) (decreases n2) = if n2 = 0 then () else iter_fun_add f n1 (n2 - 1) (f x) let iter_succ_l (#t: Type) (f: (t -> GTot t)) (n: nat) (x: t) : Lemma (f (iter_fun f n x) == iter_fun f (n + 1) x) [SMTPat (f (iter_fun f n x))] = iter_fun_add f 1 n x
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.CanonCommSemiring.fst.checked", "FStar.Tactics.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Steel.ST.GenArraySwap.Proof.fst" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.GenArraySwap", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.GenArraySwap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
n: Prims.pos -> l: Prims.nat -> b: Steel.ST.GenArraySwap.Proof.bezout n l -> x: Steel.ST.GenArraySwap.Proof.nat_up_to n -> j: Steel.ST.GenArraySwap.Proof.nat_up_to (Mkbezout_t?.q_n b) -> FStar.Pervasives.Lemma (requires j == Mkbezout_t?.q_n b - 1) (ensures Steel.ST.GenArraySwap.Proof.jump n l (Steel.ST.GenArraySwap.Proof.iter_fun (Steel.ST.GenArraySwap.Proof.jump n l) j x) == x) [ SMTPat (Steel.ST.GenArraySwap.Proof.jump n l (Steel.ST.GenArraySwap.Proof.iter_fun (Steel.ST.GenArraySwap.Proof.jump n l) j x)); SMTPat (Steel.ST.GenArraySwap.Proof.bezout_prop n l b) ]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.pos", "Prims.nat", "Steel.ST.GenArraySwap.Proof.bezout", "Steel.ST.GenArraySwap.Proof.nat_up_to", "Steel.ST.GenArraySwap.Proof.__proj__Mkbezout_t__item__q_n", "Steel.ST.GenArraySwap.Proof.jump_iter_q", "Prims.unit", "Prims.eq2", "Prims.int", "Prims.op_Subtraction", "Prims.squash", "Steel.ST.GenArraySwap.Proof.jump", "Steel.ST.GenArraySwap.Proof.iter_fun", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat", "Prims.prop", "Steel.ST.GenArraySwap.Proof.bezout_prop", "Prims.Nil" ]
[]
true
false
true
false
false
let jump_jump_iter_pred_q (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) (j: nat_up_to b.q_n) : Lemma (requires (j == b.q_n - 1)) (ensures (jump n l (iter_fun (jump n l) j x) == x)) [SMTPat (jump n l (iter_fun (jump n l) j x)); SMTPat (bezout_prop n l b)] =
jump_iter_q n l b x
false
Steel.ST.GenArraySwap.Proof.fst
Steel.ST.GenArraySwap.Proof.sz_rem_spec
val sz_rem_spec (n l: SZ.t) : Lemma (requires (SZ.v l > 0)) (ensures (SZ.v (SZ.rem n l) == SZ.v n % SZ.v l)) [SMTPat (SZ.rem n l)]
val sz_rem_spec (n l: SZ.t) : Lemma (requires (SZ.v l > 0)) (ensures (SZ.v (SZ.rem n l) == SZ.v n % SZ.v l)) [SMTPat (SZ.rem n l)]
let sz_rem_spec (n: SZ.t) (l: SZ.t) : Lemma (requires (SZ.v l > 0)) (ensures (SZ.v (SZ.rem n l) == SZ.v n % SZ.v l)) [SMTPat (SZ.rem n l)] = euclidean_division_definition (SZ.v n) (SZ.v l)
{ "file_name": "lib/steel/Steel.ST.GenArraySwap.Proof.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 49, "end_line": 705, "start_col": 0, "start_line": 698 }
module Steel.ST.GenArraySwap.Proof open FStar.Math.Lemmas open FStar.Mul let lemma_mod_lt (a:int) (b:pos) : Lemma (let r = a % b in 0 <= r /\ r < b) [SMTPat (a % b)] = () let lemma_mul_nat_nat_is_nat (a b: nat) : Lemma (a * b >= 0) [SMTPat (a * b)] = () let lemma_pos_mul_pos_args (a: nat) (b: nat) : Lemma (requires (a * b > 0)) (ensures (a > 0 /\ b > 0 /\ a <= a * b /\ b <= a * b /\ a * b == b * a)) = () let lemma_div_nat (a: nat) (b: pos) : Lemma (a / b >= 0) [SMTPat (a / b)] = () let lemma_mult_reg_l (k: int) (x1 x2: int) : Lemma (requires ( k * x1 == k * x2 /\ k <> 0 )) (ensures ( x1 == x2 )) = () let lemma_bezout_one_zero (x1: int) (x2: nat) (y1 y2: int) : Lemma (requires ( x1 * x2 + y1 * y2 == 1 /\ y1 == 0 )) (ensures ( x1 == 1 /\ x2 == 1 )) = () #set-options "--z3cliopt smt.arith.nl=false" let int_semiring () = FStar.Tactics.CanonCommSemiring.int_semiring (); FStar.Tactics.trefl (); FStar.Tactics.qed () [@@erasable] noeq type bezout_t = { d: pos; q_n: nat; q_l: nat; u_n: int; u_l: int; } let bezout_prop' (n: nat) (l: nat) (d: pos) (q_n: nat) (q_l: nat) (u_n: int) (u_l: int) : Tot prop = n == d * q_n /\ l == d * q_l /\ d == n * u_n + l * u_l let bezout_prop (n: nat) (l: nat) (b: bezout_t) : Tot prop = bezout_prop' n l b.d b.q_n b.q_l b.u_n b.u_l let bezout (n: nat) (l: nat) : Tot Type = (b: bezout_t { bezout_prop n l b }) #restart-solver let rec mk_bezout (n: pos) (l: nat) : Pure (bezout n l) (requires (l < n)) (ensures (fun _ -> True)) (decreases l) = if l = 0 then begin let d : pos = n in let q_n : nat = 1 in let q_l : nat = 0 in let u_n : int = 1 in let u_l : int = 0 in let res = { d = d; q_n = q_n; q_l = q_l; u_n = u_n; u_l = u_l; } in assert (eq2 #int n (d * q_n)) by (int_semiring ()); assert (eq2 #int 0 (d * q_l)) by (int_semiring ()); assert (eq2 #int d (n * 1 + 0 * res.u_l)) by (int_semiring ()); res end else begin let lpre = n % l in let ql = n / l in euclidean_division_definition n l; let bpre = mk_bezout l lpre in let d = bpre.d in let q_l = bpre.q_n in let qpre_lpre = bpre.q_l in let upre_l = bpre.u_n in let upre_lpre = bpre.u_l in let n_alt0 = l * ql + lpre in assert (n == n_alt0); let l_alt = d * q_l in let lpre_alt1 = d * qpre_lpre in let n_alt1 = l_alt * ql + lpre_alt1 in assert (n_alt1 == n); let q_n = q_l * ql + qpre_lpre in assert (eq2 #int n_alt1 (d * q_n)) by (int_semiring ()); let lpre_alt2 = n + - l * ql in assert (lpre_alt2 == lpre); let d_alt = l * upre_l + lpre_alt2 * upre_lpre in assert (d_alt == d); let u_l = upre_l + - ql * upre_lpre in assert (eq2 #int (n * upre_lpre + l * u_l) d_alt) by (int_semiring ()); let res = { d = d; q_n = q_n; q_l = q_l; u_n = upre_lpre; u_l = u_l; } in res end let bezout_q_eq (n: nat) (l: nat) (bz: bezout n l) : Lemma (bz.q_n == n / bz.d) [SMTPat (bezout_prop n l bz); SMTPat bz.q_n] = cancel_mul_div bz.q_n bz.d let rec iter_fun (#t: Type) (f: (t -> GTot t)) (n: nat) (x: t) : GTot t (decreases n) = if n = 0 then x else iter_fun f (n - 1) (f x) let nat_up_to (n: nat) : Tot Type = (i: nat { i < n }) let jump (n: pos) (l: nat) (x: nat_up_to n) : GTot (nat_up_to n) = (x + l) % n #restart-solver let jump_mod_d (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Lemma (jump n l x % b.d == x % b.d) = let x' = jump n l x in let x'q = (x + l) / n in euclidean_division_definition (x + l) n; let l_alt = b.d * b.q_l in assert (l_alt == l); let n_alt = b.d * b.q_n in assert (n_alt == n); let x'_alt = x + l_alt + - x'q * n_alt in assert (x'_alt == x'); let qx = b.q_l + - x'q * b.q_n in assert (eq2 #int x'_alt (x + qx * b.d)) by (int_semiring ()); lemma_mod_plus x qx b.d let rec jump_iter_mod_d (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) (k: nat) : Lemma (ensures (iter_fun #(nat_up_to n) (jump n l) k x % b.d == x % b.d)) (decreases k) = if k = 0 then () else begin jump_mod_d n l b x; jump_iter_mod_d n l b (jump n l x) (k - 1) end (* Coverage *) let rec jump_iter (n: pos) (l: nat) (x: nat_up_to n) (k: nat) : Lemma (ensures (iter_fun #(nat_up_to n) (jump n l) k x == (x + k * l) % n)) (decreases k) = if k = 0 then begin assert (eq2 #int (x + 0 * l) x) by (int_semiring ()); small_mod x n end else begin let k' = k - 1 in assert (eq2 #int (x + (k' + 1) * l) ((x + l) + k' * l)) by (int_semiring ()); jump_iter n l ((x + l) % n) k'; lemma_mod_add_distr (k' * l) (x + l) n end let bezout_pos_le (n: pos) (l: nat) (b: bezout n l) : Lemma (b.d <= n /\ b.q_n > 0) [SMTPat (bezout_prop n l b)] = lemma_pos_mul_pos_args b.q_n b.d #restart-solver [@@"opaque_to_smt"] irreducible let jump_coverage (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Ghost nat (requires True) (ensures (fun k -> x == iter_fun (jump n l) k (x % b.d) )) = let i = x % b.d in let qx = x / b.d in euclidean_division_definition x b.d; let k1 = qx * b.u_l in let m = qx * b.u_n in assert (eq2 #int (qx * (n * b.u_n + l * b.u_l) + i) (i + k1 * l + m * n)) by (int_semiring ()); assert (x == i + k1 * l + m * n); small_mod x n; lemma_mod_plus (i + k1 * l) m n; assert (x == (i + k1 * l) % n); let k = k1 % n in let qk = k1 / n in euclidean_division_definition k1 n; assert (i + (qk * n + k) * l == i + k * l + (qk * l) * n) by (int_semiring ()); lemma_mod_plus (i + k * l) (qk * l) n; assert (eq2 #int x ((i + k * l) % n)); jump_iter n l i k; k [@@"opaque_to_smt"] irreducible let rec minimal_exists' (p: (nat -> GTot bool)) (n: nat) (i: nat) : Ghost nat (requires ( p n == true /\ i <= n /\ (forall (j: nat) . j < i ==> p j == false) )) (ensures (fun k -> p k == true /\ (forall (j: nat) . j < k ==> p j == false) )) (decreases (n - i)) = if p i then i else minimal_exists' p n (i + 1) [@@"opaque_to_smt"] irreducible let minimal_exists (p: (nat -> GTot bool)) (n: nat) : Ghost nat (requires ( p n == true )) (ensures (fun k -> p k == true /\ (forall (j: nat) . j < k ==> p j == false) )) = minimal_exists' p n 0 [@@"opaque_to_smt"] irreducible let jump_coverage_strong (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Ghost nat (requires True) (ensures (fun k -> x == iter_fun (jump n l) k (x % b.d) /\ (forall (k': nat) . k' < k ==> (~ (x == iter_fun (jump n l) k' (x % b.d)))) )) = let k' = jump_coverage n l b x in minimal_exists (fun k -> x = iter_fun (jump n l) k (x % b.d)) k' #restart-solver let jump_iter_mod_q (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) (k: nat) : Lemma (ensures ( b.q_n > 0 /\ iter_fun (jump n l) (k % b.q_n) x == iter_fun (jump n l) k x )) = assert (b.q_n > 0); let k' = k % b.q_n in let qk = k / b.q_n in euclidean_division_definition k b.q_n; jump_iter n l x k'; jump_iter n l x k; assert (eq2 #int (x + (qk * b.q_n + k') * (b.d * b.q_l)) (x + k' * (b.d * b.q_l) + (qk * b.q_l) * (b.d * b.q_n))) by (int_semiring ()); assert (x + k * l == x + k' * l + (qk * b.q_l) * n); lemma_mod_plus (x + k' * l) (qk * b.q_l) n let jump_coverage_strong_bound (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Lemma (b.q_n > 0 /\ jump_coverage_strong n l b x < b.q_n ) [SMTPat (jump_coverage_strong n l b x)] = let k = jump_coverage_strong n l b x in jump_iter_mod_q n l b (x % b.d) k #restart-solver [@@"opaque_to_smt"] irreducible let mod_eq_elim (n: pos) (x1 x2: int) : Ghost int (requires (x1 % n == x2 % n)) (ensures (fun k -> x1 - x2 == k * n)) = euclidean_division_definition x1 n; euclidean_division_definition x2 n; let q1 = x1 / n in let q2 = x2 / n in let k = q1 + - q2 in let r = x1 % n in assert (q1 * n + r + - (q2 * n + r) == k * n) by (int_semiring ()); k let mod_eq_intro (n: pos) (x1 x2: int) (k: int) : Lemma (requires (x1 - x2 == k * n)) (ensures (x1 % n == x2 % n)) = lemma_mod_plus x2 k n #restart-solver [@@"opaque_to_smt"] irreducible let gauss (n: pos) (l: pos) // necessary here (b: bezout n l) (kl kn: int) : Ghost int (requires ( kl * l == kn * n )) (ensures (fun k -> kl == k * b.q_n )) = assert ((b.d * b.q_n) * b.u_n + (b.d * b.q_l) * b.u_l == b.d * (b.u_n * b.q_n + b.u_l * b.q_l)) by (int_semiring ()); assert (b.d == b.d * 1) by (int_semiring ()); assert (b.d * (b.u_n * b.q_n + b.u_l * b.q_l) == b.d * 1); lemma_mult_reg_l b.d (b.u_n * b.q_n + b.u_l * b.q_l) 1; assert (b.u_n * b.q_n + b.u_l * b.q_l == 1); if b.u_l = 0 then begin lemma_bezout_one_zero b.u_n b.q_n b.u_l b.q_l; assert (b.q_n == 1); assert (kl * 1 == kl) by (int_semiring ()); kl end else begin assert (kl * (b.d * b.q_l) == kn * (b.d * b.q_n)); assert (kl * (b.d * b.q_l) == b.d * (kl * b.q_l)) by (int_semiring ()); assert (kn * (b.d * b.q_n) == b.d * (kn * b.q_n)) by (int_semiring ()); assert (b.d * (kl * b.q_l) == b.d * (kn * b.q_n)); lemma_mult_reg_l b.d (kl * b.q_l) (kn * b.q_n); assert (kl * b.q_l == kn * b.q_n); assert (b.u_l * (kl * b.q_l) == b.u_l * (kn * b.q_n)); assert (b.u_l * (kl * b.q_l) == kl * (b.u_l * b.q_l)) by (int_semiring ()); assert (b.u_l * (kn * b.q_n) == (kn * b.u_l) * b.q_n) by (int_semiring ()); assert (kl * (b.u_l * b.q_l) == (kn * b.u_l) * b.q_n); assert (kl * (1 + - (b.u_n * b.q_n)) == kl + - kl * b.u_n * b.q_n) by (int_semiring ()); assert (kl * b.u_n * b.q_n + (kn * b.u_l) * b.q_n == (kn * b.u_l + kl * b.u_n) * b.q_n) by (int_semiring ()); kn * b.u_l + kl * b.u_n end let jump_iter_mod_q_inj_weak (n: pos) (l: pos) (b: bezout n l) (x: nat_up_to n) (k1 k2: nat) : Lemma (requires ( iter_fun (jump n l) k1 x == iter_fun (jump n l) k2 x )) (ensures ( b.q_n > 0 /\ k1 % b.q_n == k2 % b.q_n )) = jump_iter n l x k1; jump_iter n l x k2; let kn = mod_eq_elim n (x + k1 * l) (x + k2 * l) in assert ((k1 + - k2) * l == (k1 * l + - (k2 * l))) by (int_semiring ()); let kq = gauss n l b (k1 + - k2) kn in mod_eq_intro b.q_n k1 k2 kq let jump_iter_inj (n: nat) (l: nat) (b: bezout_t) (i1 i2: nat) (k1 k2: nat) : Lemma (requires ( n > 0 /\ l > 0 /\ bezout_prop n l b /\ i1 < b.d /\ i2 < b.d /\ k1 < b.q_n /\ k2 < b.q_n /\ iter_fun (jump n l) k1 i1 == iter_fun (jump n l) k2 i2 )) (ensures ( i1 == i2 /\ k1 == k2 )) [SMTPat (iter_fun (jump n l) k1 i1); SMTPat (iter_fun (jump n l) k2 i2); SMTPat (bezout_prop n l b)] = jump_iter_mod_d n l b i1 k1; jump_iter_mod_d n l b i2 k2; small_mod i1 b.d; small_mod i2 b.d; jump_iter_mod_q_inj_weak n l b i1 k1 k2; small_mod k1 b.q_n; small_mod k2 b.q_n #restart-solver let jump_iter_elim (n: pos) (p: nat_up_to n -> prop) (l: nat) (b: bezout n l) : Lemma (requires ( forall (i: nat_up_to b.d) (k: nat_up_to b.q_n) . p (iter_fun (jump n l) k i) )) (ensures ( forall (x: nat_up_to n) . p x )) = let prf (x: nat_up_to n) : Lemma (p x) = let i : nat_up_to b.d = x % b.d in let k' = jump_coverage_strong n l b x in jump_coverage_strong_bound n l b x; assert (p (iter_fun (jump n l) k' i)) in Classical.forall_intro prf let jump_if (n: pos) (l: nat) (sq: squash (l < n)) (idx: nat_up_to n) : Lemma (jump n l idx == (if idx + l >= n then idx - (n - l) else idx + l)) = let idx' = (if idx + l >= n then idx - (n - l) else idx + l) in small_mod idx n; small_mod idx' n; lemma_mod_plus (idx + l) (-1) n let jump_iter_q (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Lemma (ensures ( iter_fun (jump n l) b.q_n x == x )) = cancel_mul_mod 1 b.q_n; jump_iter_mod_q n l b x b.q_n let rec iter_fun_add (#t: Type) (f: (t -> GTot t)) (n1 n2: nat) (x: t) : Lemma (ensures (iter_fun f n1 (iter_fun f n2 x) == iter_fun f (n1 + n2) x)) (decreases n2) = if n2 = 0 then () else iter_fun_add f n1 (n2 - 1) (f x) let iter_succ_l (#t: Type) (f: (t -> GTot t)) (n: nat) (x: t) : Lemma (f (iter_fun f n x) == iter_fun f (n + 1) x) [SMTPat (f (iter_fun f n x))] = iter_fun_add f 1 n x let jump_jump_iter_pred_q (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) (j: nat_up_to b.q_n) : Lemma (requires ( j == b.q_n - 1 )) (ensures ( jump n l (iter_fun (jump n l) j x) == x )) [SMTPat (jump n l (iter_fun (jump n l) j x)); SMTPat (bezout_prop n l b)] = jump_iter_q n l b x let array_swap_post (#t: Type) (s0: Seq.seq t) (n: nat) (l: nat) (s: Seq.seq t) : Tot prop = n == Seq.length s0 /\ 0 <= l /\ l <= n /\ s `Seq.equal` (Seq.slice s0 l n `Seq.append` Seq.slice s0 0 l) let array_as_ring_buffer_swap (#t: Type) (n: nat) (l: nat) (bz: bezout n l) (s0: Seq.seq t) (s: Seq.seq t) : Lemma (requires ( n == Seq.length s0 /\ n == Seq.length s /\ 0 < l /\ l < n /\ (forall (i': nat_up_to bz.d) . (forall (j: nat_up_to bz.q_n) . (i' < bz.d) ==> ( let idx = iter_fun #(nat_up_to n) (jump n l) j i' in Seq.index s idx == Seq.index s0 (jump n l idx) ))) )) (ensures ( array_swap_post s0 n l s )) [SMTPat (array_swap_post s0 n l s); SMTPat (bezout_prop n l bz)] = Classical.forall_intro (jump_if n l ()); let p (idx: nat_up_to n) : Tot prop = Seq.index s idx == Seq.index s0 (jump n l idx) in jump_iter_elim n p l bz let array_swap_outer_invariant // hoisting necessary because "Let binding is effectful" (#t: Type0) (s0: Seq.seq t) (n: nat) (l: nat) (bz: bezout (n) (l)) (s: Seq.seq t) (i: nat) : Tot prop = 0 < l /\ l < n /\ i <= bz.d /\ n == Seq.length s0 /\ n == Seq.length s /\ (forall (i': nat_up_to bz.d) . // this is always true, but I need it here for the pattern Seq.index s i' == Seq.index s (iter_fun #(nat_up_to (n)) (jump (n) (l)) 0 i') ) /\ (forall (i': nat_up_to bz.d) . (forall (j: nat_up_to bz.q_n) . let idx = iter_fun #(nat_up_to (n)) (jump (n) (l)) j i' in Seq.index s idx == Seq.index s0 (if i' < i then jump (n) (l) idx else idx) )) let array_swap_inner_invariant (#t: Type0) (s0: Seq.seq t) (n: nat) (l: nat) (bz: bezout (n) (l)) (s: Seq.seq t) (i: nat) (j: nat) (idx: nat) : Tot prop = 0 < l /\ l < n /\ n == Seq.length s0 /\ i < bz.d /\ j < bz.q_n /\ idx == iter_fun #(nat_up_to (n)) (jump (n) (l)) (j) (i) /\ n == Seq.length s /\ (forall (i': nat_up_to bz.d) . (forall (j': nat_up_to bz.q_n) . let idx = iter_fun #(nat_up_to (n)) (jump (n) (l)) j' i' in Seq.index s idx == Seq.index s0 (if i' < i || (i' = i && j' < j) then jump (n) (l) idx else idx) )) let array_swap_inner_invariant_end (#t: Type) (n: nat) (l: nat) (bz: bezout (n) (l)) (s0: Seq.seq t) (s: Seq.seq t) (i: nat) (j: nat) (idx: nat) : Lemma (requires ( array_swap_inner_invariant s0 n l bz s i j idx /\ (~ (j < bz.q_n - 1)) )) (ensures ( let s' = Seq.upd s idx (Seq.index s0 i) in array_swap_outer_invariant s0 n l bz s' (i + 1) )) // [SMTPat (array_swap_inner_invariant s0 n l bz s i j idx)] = () module SZ = FStar.SizeT
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.CanonCommSemiring.fst.checked", "FStar.Tactics.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Steel.ST.GenArraySwap.Proof.fst" }
[ { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "SZ" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.GenArraySwap", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.GenArraySwap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
n: FStar.SizeT.t -> l: FStar.SizeT.t -> FStar.Pervasives.Lemma (requires FStar.SizeT.v l > 0) (ensures FStar.SizeT.v (FStar.SizeT.rem n l) == FStar.SizeT.v n % FStar.SizeT.v l) [SMTPat (FStar.SizeT.rem n l)]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "FStar.SizeT.t", "FStar.Math.Lemmas.euclidean_division_definition", "FStar.SizeT.v", "Prims.unit", "Prims.b2t", "Prims.op_GreaterThan", "Prims.squash", "Prims.eq2", "Prims.int", "FStar.SizeT.rem", "Prims.op_Modulus", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat", "Prims.Nil" ]
[]
true
false
true
false
false
let sz_rem_spec (n l: SZ.t) : Lemma (requires (SZ.v l > 0)) (ensures (SZ.v (SZ.rem n l) == SZ.v n % SZ.v l)) [SMTPat (SZ.rem n l)] =
euclidean_division_definition (SZ.v n) (SZ.v l)
false
Steel.ST.GenArraySwap.Proof.fst
Steel.ST.GenArraySwap.Proof.array_as_ring_buffer_swap
val array_as_ring_buffer_swap (#t: Type) (n l: nat) (bz: bezout n l) (s0 s: Seq.seq t) : Lemma (requires (n == Seq.length s0 /\ n == Seq.length s /\ 0 < l /\ l < n /\ (forall (i': nat_up_to bz.d). (forall (j: nat_up_to bz.q_n). (i' < bz.d) ==> (let idx = iter_fun #(nat_up_to n) (jump n l) j i' in Seq.index s idx == Seq.index s0 (jump n l idx)))))) (ensures (array_swap_post s0 n l s)) [SMTPat (array_swap_post s0 n l s); SMTPat (bezout_prop n l bz)]
val array_as_ring_buffer_swap (#t: Type) (n l: nat) (bz: bezout n l) (s0 s: Seq.seq t) : Lemma (requires (n == Seq.length s0 /\ n == Seq.length s /\ 0 < l /\ l < n /\ (forall (i': nat_up_to bz.d). (forall (j: nat_up_to bz.q_n). (i' < bz.d) ==> (let idx = iter_fun #(nat_up_to n) (jump n l) j i' in Seq.index s idx == Seq.index s0 (jump n l idx)))))) (ensures (array_swap_post s0 n l s)) [SMTPat (array_swap_post s0 n l s); SMTPat (bezout_prop n l bz)]
let array_as_ring_buffer_swap (#t: Type) (n: nat) (l: nat) (bz: bezout n l) (s0: Seq.seq t) (s: Seq.seq t) : Lemma (requires ( n == Seq.length s0 /\ n == Seq.length s /\ 0 < l /\ l < n /\ (forall (i': nat_up_to bz.d) . (forall (j: nat_up_to bz.q_n) . (i' < bz.d) ==> ( let idx = iter_fun #(nat_up_to n) (jump n l) j i' in Seq.index s idx == Seq.index s0 (jump n l idx) ))) )) (ensures ( array_swap_post s0 n l s )) [SMTPat (array_swap_post s0 n l s); SMTPat (bezout_prop n l bz)] = Classical.forall_intro (jump_if n l ()); let p (idx: nat_up_to n) : Tot prop = Seq.index s idx == Seq.index s0 (jump n l idx) in jump_iter_elim n p l bz
{ "file_name": "lib/steel/Steel.ST.GenArraySwap.Proof.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 25, "end_line": 637, "start_col": 0, "start_line": 607 }
module Steel.ST.GenArraySwap.Proof open FStar.Math.Lemmas open FStar.Mul let lemma_mod_lt (a:int) (b:pos) : Lemma (let r = a % b in 0 <= r /\ r < b) [SMTPat (a % b)] = () let lemma_mul_nat_nat_is_nat (a b: nat) : Lemma (a * b >= 0) [SMTPat (a * b)] = () let lemma_pos_mul_pos_args (a: nat) (b: nat) : Lemma (requires (a * b > 0)) (ensures (a > 0 /\ b > 0 /\ a <= a * b /\ b <= a * b /\ a * b == b * a)) = () let lemma_div_nat (a: nat) (b: pos) : Lemma (a / b >= 0) [SMTPat (a / b)] = () let lemma_mult_reg_l (k: int) (x1 x2: int) : Lemma (requires ( k * x1 == k * x2 /\ k <> 0 )) (ensures ( x1 == x2 )) = () let lemma_bezout_one_zero (x1: int) (x2: nat) (y1 y2: int) : Lemma (requires ( x1 * x2 + y1 * y2 == 1 /\ y1 == 0 )) (ensures ( x1 == 1 /\ x2 == 1 )) = () #set-options "--z3cliopt smt.arith.nl=false" let int_semiring () = FStar.Tactics.CanonCommSemiring.int_semiring (); FStar.Tactics.trefl (); FStar.Tactics.qed () [@@erasable] noeq type bezout_t = { d: pos; q_n: nat; q_l: nat; u_n: int; u_l: int; } let bezout_prop' (n: nat) (l: nat) (d: pos) (q_n: nat) (q_l: nat) (u_n: int) (u_l: int) : Tot prop = n == d * q_n /\ l == d * q_l /\ d == n * u_n + l * u_l let bezout_prop (n: nat) (l: nat) (b: bezout_t) : Tot prop = bezout_prop' n l b.d b.q_n b.q_l b.u_n b.u_l let bezout (n: nat) (l: nat) : Tot Type = (b: bezout_t { bezout_prop n l b }) #restart-solver let rec mk_bezout (n: pos) (l: nat) : Pure (bezout n l) (requires (l < n)) (ensures (fun _ -> True)) (decreases l) = if l = 0 then begin let d : pos = n in let q_n : nat = 1 in let q_l : nat = 0 in let u_n : int = 1 in let u_l : int = 0 in let res = { d = d; q_n = q_n; q_l = q_l; u_n = u_n; u_l = u_l; } in assert (eq2 #int n (d * q_n)) by (int_semiring ()); assert (eq2 #int 0 (d * q_l)) by (int_semiring ()); assert (eq2 #int d (n * 1 + 0 * res.u_l)) by (int_semiring ()); res end else begin let lpre = n % l in let ql = n / l in euclidean_division_definition n l; let bpre = mk_bezout l lpre in let d = bpre.d in let q_l = bpre.q_n in let qpre_lpre = bpre.q_l in let upre_l = bpre.u_n in let upre_lpre = bpre.u_l in let n_alt0 = l * ql + lpre in assert (n == n_alt0); let l_alt = d * q_l in let lpre_alt1 = d * qpre_lpre in let n_alt1 = l_alt * ql + lpre_alt1 in assert (n_alt1 == n); let q_n = q_l * ql + qpre_lpre in assert (eq2 #int n_alt1 (d * q_n)) by (int_semiring ()); let lpre_alt2 = n + - l * ql in assert (lpre_alt2 == lpre); let d_alt = l * upre_l + lpre_alt2 * upre_lpre in assert (d_alt == d); let u_l = upre_l + - ql * upre_lpre in assert (eq2 #int (n * upre_lpre + l * u_l) d_alt) by (int_semiring ()); let res = { d = d; q_n = q_n; q_l = q_l; u_n = upre_lpre; u_l = u_l; } in res end let bezout_q_eq (n: nat) (l: nat) (bz: bezout n l) : Lemma (bz.q_n == n / bz.d) [SMTPat (bezout_prop n l bz); SMTPat bz.q_n] = cancel_mul_div bz.q_n bz.d let rec iter_fun (#t: Type) (f: (t -> GTot t)) (n: nat) (x: t) : GTot t (decreases n) = if n = 0 then x else iter_fun f (n - 1) (f x) let nat_up_to (n: nat) : Tot Type = (i: nat { i < n }) let jump (n: pos) (l: nat) (x: nat_up_to n) : GTot (nat_up_to n) = (x + l) % n #restart-solver let jump_mod_d (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Lemma (jump n l x % b.d == x % b.d) = let x' = jump n l x in let x'q = (x + l) / n in euclidean_division_definition (x + l) n; let l_alt = b.d * b.q_l in assert (l_alt == l); let n_alt = b.d * b.q_n in assert (n_alt == n); let x'_alt = x + l_alt + - x'q * n_alt in assert (x'_alt == x'); let qx = b.q_l + - x'q * b.q_n in assert (eq2 #int x'_alt (x + qx * b.d)) by (int_semiring ()); lemma_mod_plus x qx b.d let rec jump_iter_mod_d (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) (k: nat) : Lemma (ensures (iter_fun #(nat_up_to n) (jump n l) k x % b.d == x % b.d)) (decreases k) = if k = 0 then () else begin jump_mod_d n l b x; jump_iter_mod_d n l b (jump n l x) (k - 1) end (* Coverage *) let rec jump_iter (n: pos) (l: nat) (x: nat_up_to n) (k: nat) : Lemma (ensures (iter_fun #(nat_up_to n) (jump n l) k x == (x + k * l) % n)) (decreases k) = if k = 0 then begin assert (eq2 #int (x + 0 * l) x) by (int_semiring ()); small_mod x n end else begin let k' = k - 1 in assert (eq2 #int (x + (k' + 1) * l) ((x + l) + k' * l)) by (int_semiring ()); jump_iter n l ((x + l) % n) k'; lemma_mod_add_distr (k' * l) (x + l) n end let bezout_pos_le (n: pos) (l: nat) (b: bezout n l) : Lemma (b.d <= n /\ b.q_n > 0) [SMTPat (bezout_prop n l b)] = lemma_pos_mul_pos_args b.q_n b.d #restart-solver [@@"opaque_to_smt"] irreducible let jump_coverage (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Ghost nat (requires True) (ensures (fun k -> x == iter_fun (jump n l) k (x % b.d) )) = let i = x % b.d in let qx = x / b.d in euclidean_division_definition x b.d; let k1 = qx * b.u_l in let m = qx * b.u_n in assert (eq2 #int (qx * (n * b.u_n + l * b.u_l) + i) (i + k1 * l + m * n)) by (int_semiring ()); assert (x == i + k1 * l + m * n); small_mod x n; lemma_mod_plus (i + k1 * l) m n; assert (x == (i + k1 * l) % n); let k = k1 % n in let qk = k1 / n in euclidean_division_definition k1 n; assert (i + (qk * n + k) * l == i + k * l + (qk * l) * n) by (int_semiring ()); lemma_mod_plus (i + k * l) (qk * l) n; assert (eq2 #int x ((i + k * l) % n)); jump_iter n l i k; k [@@"opaque_to_smt"] irreducible let rec minimal_exists' (p: (nat -> GTot bool)) (n: nat) (i: nat) : Ghost nat (requires ( p n == true /\ i <= n /\ (forall (j: nat) . j < i ==> p j == false) )) (ensures (fun k -> p k == true /\ (forall (j: nat) . j < k ==> p j == false) )) (decreases (n - i)) = if p i then i else minimal_exists' p n (i + 1) [@@"opaque_to_smt"] irreducible let minimal_exists (p: (nat -> GTot bool)) (n: nat) : Ghost nat (requires ( p n == true )) (ensures (fun k -> p k == true /\ (forall (j: nat) . j < k ==> p j == false) )) = minimal_exists' p n 0 [@@"opaque_to_smt"] irreducible let jump_coverage_strong (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Ghost nat (requires True) (ensures (fun k -> x == iter_fun (jump n l) k (x % b.d) /\ (forall (k': nat) . k' < k ==> (~ (x == iter_fun (jump n l) k' (x % b.d)))) )) = let k' = jump_coverage n l b x in minimal_exists (fun k -> x = iter_fun (jump n l) k (x % b.d)) k' #restart-solver let jump_iter_mod_q (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) (k: nat) : Lemma (ensures ( b.q_n > 0 /\ iter_fun (jump n l) (k % b.q_n) x == iter_fun (jump n l) k x )) = assert (b.q_n > 0); let k' = k % b.q_n in let qk = k / b.q_n in euclidean_division_definition k b.q_n; jump_iter n l x k'; jump_iter n l x k; assert (eq2 #int (x + (qk * b.q_n + k') * (b.d * b.q_l)) (x + k' * (b.d * b.q_l) + (qk * b.q_l) * (b.d * b.q_n))) by (int_semiring ()); assert (x + k * l == x + k' * l + (qk * b.q_l) * n); lemma_mod_plus (x + k' * l) (qk * b.q_l) n let jump_coverage_strong_bound (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Lemma (b.q_n > 0 /\ jump_coverage_strong n l b x < b.q_n ) [SMTPat (jump_coverage_strong n l b x)] = let k = jump_coverage_strong n l b x in jump_iter_mod_q n l b (x % b.d) k #restart-solver [@@"opaque_to_smt"] irreducible let mod_eq_elim (n: pos) (x1 x2: int) : Ghost int (requires (x1 % n == x2 % n)) (ensures (fun k -> x1 - x2 == k * n)) = euclidean_division_definition x1 n; euclidean_division_definition x2 n; let q1 = x1 / n in let q2 = x2 / n in let k = q1 + - q2 in let r = x1 % n in assert (q1 * n + r + - (q2 * n + r) == k * n) by (int_semiring ()); k let mod_eq_intro (n: pos) (x1 x2: int) (k: int) : Lemma (requires (x1 - x2 == k * n)) (ensures (x1 % n == x2 % n)) = lemma_mod_plus x2 k n #restart-solver [@@"opaque_to_smt"] irreducible let gauss (n: pos) (l: pos) // necessary here (b: bezout n l) (kl kn: int) : Ghost int (requires ( kl * l == kn * n )) (ensures (fun k -> kl == k * b.q_n )) = assert ((b.d * b.q_n) * b.u_n + (b.d * b.q_l) * b.u_l == b.d * (b.u_n * b.q_n + b.u_l * b.q_l)) by (int_semiring ()); assert (b.d == b.d * 1) by (int_semiring ()); assert (b.d * (b.u_n * b.q_n + b.u_l * b.q_l) == b.d * 1); lemma_mult_reg_l b.d (b.u_n * b.q_n + b.u_l * b.q_l) 1; assert (b.u_n * b.q_n + b.u_l * b.q_l == 1); if b.u_l = 0 then begin lemma_bezout_one_zero b.u_n b.q_n b.u_l b.q_l; assert (b.q_n == 1); assert (kl * 1 == kl) by (int_semiring ()); kl end else begin assert (kl * (b.d * b.q_l) == kn * (b.d * b.q_n)); assert (kl * (b.d * b.q_l) == b.d * (kl * b.q_l)) by (int_semiring ()); assert (kn * (b.d * b.q_n) == b.d * (kn * b.q_n)) by (int_semiring ()); assert (b.d * (kl * b.q_l) == b.d * (kn * b.q_n)); lemma_mult_reg_l b.d (kl * b.q_l) (kn * b.q_n); assert (kl * b.q_l == kn * b.q_n); assert (b.u_l * (kl * b.q_l) == b.u_l * (kn * b.q_n)); assert (b.u_l * (kl * b.q_l) == kl * (b.u_l * b.q_l)) by (int_semiring ()); assert (b.u_l * (kn * b.q_n) == (kn * b.u_l) * b.q_n) by (int_semiring ()); assert (kl * (b.u_l * b.q_l) == (kn * b.u_l) * b.q_n); assert (kl * (1 + - (b.u_n * b.q_n)) == kl + - kl * b.u_n * b.q_n) by (int_semiring ()); assert (kl * b.u_n * b.q_n + (kn * b.u_l) * b.q_n == (kn * b.u_l + kl * b.u_n) * b.q_n) by (int_semiring ()); kn * b.u_l + kl * b.u_n end let jump_iter_mod_q_inj_weak (n: pos) (l: pos) (b: bezout n l) (x: nat_up_to n) (k1 k2: nat) : Lemma (requires ( iter_fun (jump n l) k1 x == iter_fun (jump n l) k2 x )) (ensures ( b.q_n > 0 /\ k1 % b.q_n == k2 % b.q_n )) = jump_iter n l x k1; jump_iter n l x k2; let kn = mod_eq_elim n (x + k1 * l) (x + k2 * l) in assert ((k1 + - k2) * l == (k1 * l + - (k2 * l))) by (int_semiring ()); let kq = gauss n l b (k1 + - k2) kn in mod_eq_intro b.q_n k1 k2 kq let jump_iter_inj (n: nat) (l: nat) (b: bezout_t) (i1 i2: nat) (k1 k2: nat) : Lemma (requires ( n > 0 /\ l > 0 /\ bezout_prop n l b /\ i1 < b.d /\ i2 < b.d /\ k1 < b.q_n /\ k2 < b.q_n /\ iter_fun (jump n l) k1 i1 == iter_fun (jump n l) k2 i2 )) (ensures ( i1 == i2 /\ k1 == k2 )) [SMTPat (iter_fun (jump n l) k1 i1); SMTPat (iter_fun (jump n l) k2 i2); SMTPat (bezout_prop n l b)] = jump_iter_mod_d n l b i1 k1; jump_iter_mod_d n l b i2 k2; small_mod i1 b.d; small_mod i2 b.d; jump_iter_mod_q_inj_weak n l b i1 k1 k2; small_mod k1 b.q_n; small_mod k2 b.q_n #restart-solver let jump_iter_elim (n: pos) (p: nat_up_to n -> prop) (l: nat) (b: bezout n l) : Lemma (requires ( forall (i: nat_up_to b.d) (k: nat_up_to b.q_n) . p (iter_fun (jump n l) k i) )) (ensures ( forall (x: nat_up_to n) . p x )) = let prf (x: nat_up_to n) : Lemma (p x) = let i : nat_up_to b.d = x % b.d in let k' = jump_coverage_strong n l b x in jump_coverage_strong_bound n l b x; assert (p (iter_fun (jump n l) k' i)) in Classical.forall_intro prf let jump_if (n: pos) (l: nat) (sq: squash (l < n)) (idx: nat_up_to n) : Lemma (jump n l idx == (if idx + l >= n then idx - (n - l) else idx + l)) = let idx' = (if idx + l >= n then idx - (n - l) else idx + l) in small_mod idx n; small_mod idx' n; lemma_mod_plus (idx + l) (-1) n let jump_iter_q (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Lemma (ensures ( iter_fun (jump n l) b.q_n x == x )) = cancel_mul_mod 1 b.q_n; jump_iter_mod_q n l b x b.q_n let rec iter_fun_add (#t: Type) (f: (t -> GTot t)) (n1 n2: nat) (x: t) : Lemma (ensures (iter_fun f n1 (iter_fun f n2 x) == iter_fun f (n1 + n2) x)) (decreases n2) = if n2 = 0 then () else iter_fun_add f n1 (n2 - 1) (f x) let iter_succ_l (#t: Type) (f: (t -> GTot t)) (n: nat) (x: t) : Lemma (f (iter_fun f n x) == iter_fun f (n + 1) x) [SMTPat (f (iter_fun f n x))] = iter_fun_add f 1 n x let jump_jump_iter_pred_q (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) (j: nat_up_to b.q_n) : Lemma (requires ( j == b.q_n - 1 )) (ensures ( jump n l (iter_fun (jump n l) j x) == x )) [SMTPat (jump n l (iter_fun (jump n l) j x)); SMTPat (bezout_prop n l b)] = jump_iter_q n l b x let array_swap_post (#t: Type) (s0: Seq.seq t) (n: nat) (l: nat) (s: Seq.seq t) : Tot prop = n == Seq.length s0 /\ 0 <= l /\ l <= n /\ s `Seq.equal` (Seq.slice s0 l n `Seq.append` Seq.slice s0 0 l)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.CanonCommSemiring.fst.checked", "FStar.Tactics.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Steel.ST.GenArraySwap.Proof.fst" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.GenArraySwap", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.GenArraySwap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
n: Prims.nat -> l: Prims.nat -> bz: Steel.ST.GenArraySwap.Proof.bezout n l -> s0: FStar.Seq.Base.seq t -> s: FStar.Seq.Base.seq t -> FStar.Pervasives.Lemma (requires n == FStar.Seq.Base.length s0 /\ n == FStar.Seq.Base.length s /\ 0 < l /\ l < n /\ (forall (i': Steel.ST.GenArraySwap.Proof.nat_up_to (Mkbezout_t?.d bz)) (j: Steel.ST.GenArraySwap.Proof.nat_up_to (Mkbezout_t?.q_n bz)). i' < Mkbezout_t?.d bz ==> (let idx = Steel.ST.GenArraySwap.Proof.iter_fun (Steel.ST.GenArraySwap.Proof.jump n l) j i' in FStar.Seq.Base.index s idx == FStar.Seq.Base.index s0 (Steel.ST.GenArraySwap.Proof.jump n l idx)))) (ensures Steel.ST.GenArraySwap.Proof.array_swap_post s0 n l s) [ SMTPat (Steel.ST.GenArraySwap.Proof.array_swap_post s0 n l s); SMTPat (Steel.ST.GenArraySwap.Proof.bezout_prop n l bz) ]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.nat", "Steel.ST.GenArraySwap.Proof.bezout", "FStar.Seq.Base.seq", "Steel.ST.GenArraySwap.Proof.jump_iter_elim", "Steel.ST.GenArraySwap.Proof.nat_up_to", "Prims.prop", "Prims.eq2", "FStar.Seq.Base.index", "Steel.ST.GenArraySwap.Proof.jump", "Prims.unit", "FStar.Classical.forall_intro", "Prims.int", "Prims.op_GreaterThanOrEqual", "Prims.op_Addition", "Prims.op_Subtraction", "Prims.bool", "Steel.ST.GenArraySwap.Proof.jump_if", "Prims.l_and", "FStar.Seq.Base.length", "Prims.b2t", "Prims.op_LessThan", "Prims.l_Forall", "Steel.ST.GenArraySwap.Proof.__proj__Mkbezout_t__item__d", "Steel.ST.GenArraySwap.Proof.__proj__Mkbezout_t__item__q_n", "Prims.l_imp", "Steel.ST.GenArraySwap.Proof.iter_fun", "Prims.squash", "Steel.ST.GenArraySwap.Proof.array_swap_post", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat", "Steel.ST.GenArraySwap.Proof.bezout_prop", "Prims.Nil" ]
[]
false
false
true
false
false
let array_as_ring_buffer_swap (#t: Type) (n l: nat) (bz: bezout n l) (s0 s: Seq.seq t) : Lemma (requires (n == Seq.length s0 /\ n == Seq.length s /\ 0 < l /\ l < n /\ (forall (i': nat_up_to bz.d). (forall (j: nat_up_to bz.q_n). (i' < bz.d) ==> (let idx = iter_fun #(nat_up_to n) (jump n l) j i' in Seq.index s idx == Seq.index s0 (jump n l idx)))))) (ensures (array_swap_post s0 n l s)) [SMTPat (array_swap_post s0 n l s); SMTPat (bezout_prop n l bz)] =
Classical.forall_intro (jump_if n l ()); let p (idx: nat_up_to n) : Tot prop = Seq.index s idx == Seq.index s0 (jump n l idx) in jump_iter_elim n p l bz
false
Hacl.Spec.P256.Qinv.fst
Hacl.Spec.P256.Qinv.nat_mod_comm_monoid
val nat_mod_comm_monoid : Lib.Exponentiation.Definition.comm_monoid (Lib.NatMod.nat_mod Spec.P256.PointOps.order)
let nat_mod_comm_monoid = M.mk_nat_mod_comm_monoid S.order
{ "file_name": "code/ecdsap256/Hacl.Spec.P256.Qinv.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 58, "end_line": 12, "start_col": 0, "start_line": 12 }
module Hacl.Spec.P256.Qinv open FStar.Mul module SE = Spec.Exponentiation module LE = Lib.Exponentiation module M = Lib.NatMod module S = Spec.P256 #set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
{ "checked_file": "/", "dependencies": [ "Spec.P256.fst.checked", "Spec.Exponentiation.fsti.checked", "prims.fst.checked", "Lib.NatMod.fsti.checked", "Lib.Exponentiation.fsti.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.P256.Qinv.fst" }
[ { "abbrev": true, "full_module": "Spec.P256", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.NatMod", "short_module": "M" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "LE" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.P256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.P256", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
Lib.Exponentiation.Definition.comm_monoid (Lib.NatMod.nat_mod Spec.P256.PointOps.order)
Prims.Tot
[ "total" ]
[]
[ "Lib.NatMod.mk_nat_mod_comm_monoid", "Spec.P256.PointOps.order" ]
[]
false
false
false
true
false
let nat_mod_comm_monoid =
M.mk_nat_mod_comm_monoid S.order
false
Hacl.Spec.P256.Qinv.fst
Hacl.Spec.P256.Qinv.qsquare_times
val qsquare_times (a: S.qelem) (b: nat) : S.qelem
val qsquare_times (a: S.qelem) (b: nat) : S.qelem
let qsquare_times (a:S.qelem) (b:nat) : S.qelem = SE.exp_pow2 mk_nat_mod_concrete_ops a b
{ "file_name": "code/ecdsap256/Hacl.Spec.P256.Qinv.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 41, "end_line": 37, "start_col": 0, "start_line": 36 }
module Hacl.Spec.P256.Qinv open FStar.Mul module SE = Spec.Exponentiation module LE = Lib.Exponentiation module M = Lib.NatMod module S = Spec.P256 #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" let nat_mod_comm_monoid = M.mk_nat_mod_comm_monoid S.order let mk_to_nat_mod_comm_monoid : SE.to_comm_monoid S.qelem = { SE.a_spec = S.qelem; SE.comm_monoid = nat_mod_comm_monoid; SE.refl = (fun (x:S.qelem) -> x); } val one_mod : SE.one_st S.qelem mk_to_nat_mod_comm_monoid let one_mod _ = 1 val mul_mod : SE.mul_st S.qelem mk_to_nat_mod_comm_monoid let mul_mod x y = S.qmul x y val sqr_mod : SE.sqr_st S.qelem mk_to_nat_mod_comm_monoid let sqr_mod x = S.qmul x x let mk_nat_mod_concrete_ops : SE.concrete_ops S.qelem = { SE.to = mk_to_nat_mod_comm_monoid; SE.one = one_mod; SE.mul = mul_mod; SE.sqr = sqr_mod; }
{ "checked_file": "/", "dependencies": [ "Spec.P256.fst.checked", "Spec.Exponentiation.fsti.checked", "prims.fst.checked", "Lib.NatMod.fsti.checked", "Lib.Exponentiation.fsti.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.P256.Qinv.fst" }
[ { "abbrev": true, "full_module": "Spec.P256", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.NatMod", "short_module": "M" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "LE" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.P256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.P256", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Spec.P256.PointOps.qelem -> b: Prims.nat -> Spec.P256.PointOps.qelem
Prims.Tot
[ "total" ]
[]
[ "Spec.P256.PointOps.qelem", "Prims.nat", "Spec.Exponentiation.exp_pow2", "Hacl.Spec.P256.Qinv.mk_nat_mod_concrete_ops" ]
[]
false
false
false
true
false
let qsquare_times (a: S.qelem) (b: nat) : S.qelem =
SE.exp_pow2 mk_nat_mod_concrete_ops a b
false
Hacl.Spec.P256.Qinv.fst
Hacl.Spec.P256.Qinv.qinv_x134_x153
val qinv_x134_x153 (x128 x_11 x_111 x_1111 x_10101 x_101111: S.qelem) : S.qelem
val qinv_x134_x153 (x128 x_11 x_111 x_1111 x_10101 x_101111: S.qelem) : S.qelem
let qinv_x134_x153 (x128 x_11 x_111 x_1111 x_10101 x_101111: S.qelem) : S.qelem = let x134 = S.qmul (qsquare_times x128 6) x_101111 in let x139 = S.qmul (qsquare_times x134 5) x_111 in let x143 = S.qmul (qsquare_times x139 4) x_11 in let x148 = S.qmul (qsquare_times x143 5) x_1111 in let x153 = S.qmul (qsquare_times x148 5) x_10101 in x153
{ "file_name": "code/ecdsap256/Hacl.Spec.P256.Qinv.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 6, "end_line": 63, "start_col": 0, "start_line": 57 }
module Hacl.Spec.P256.Qinv open FStar.Mul module SE = Spec.Exponentiation module LE = Lib.Exponentiation module M = Lib.NatMod module S = Spec.P256 #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" let nat_mod_comm_monoid = M.mk_nat_mod_comm_monoid S.order let mk_to_nat_mod_comm_monoid : SE.to_comm_monoid S.qelem = { SE.a_spec = S.qelem; SE.comm_monoid = nat_mod_comm_monoid; SE.refl = (fun (x:S.qelem) -> x); } val one_mod : SE.one_st S.qelem mk_to_nat_mod_comm_monoid let one_mod _ = 1 val mul_mod : SE.mul_st S.qelem mk_to_nat_mod_comm_monoid let mul_mod x y = S.qmul x y val sqr_mod : SE.sqr_st S.qelem mk_to_nat_mod_comm_monoid let sqr_mod x = S.qmul x x let mk_nat_mod_concrete_ops : SE.concrete_ops S.qelem = { SE.to = mk_to_nat_mod_comm_monoid; SE.one = one_mod; SE.mul = mul_mod; SE.sqr = sqr_mod; } let qsquare_times (a:S.qelem) (b:nat) : S.qelem = SE.exp_pow2 mk_nat_mod_concrete_ops a b val qsquare_times_lemma: a:S.qelem -> b:nat -> Lemma (qsquare_times a b == M.pow a (pow2 b) % S.order) let qsquare_times_lemma a b = SE.exp_pow2_lemma mk_nat_mod_concrete_ops a b; LE.exp_pow2_lemma nat_mod_comm_monoid a b; assert (qsquare_times a b == LE.pow nat_mod_comm_monoid a (pow2 b)); M.lemma_pow_nat_mod_is_pow #S.order a (pow2 b) let qinv_x8_x128 (x6 x_11: S.qelem) : S.qelem = let x8 = S.qmul (qsquare_times x6 2) x_11 in let x16 = S.qmul (qsquare_times x8 8) x8 in let x32 = S.qmul (qsquare_times x16 16) x16 in let x96 = S.qmul (qsquare_times x32 64) x32 in let x128 = S.qmul (qsquare_times x96 32) x32 in x128
{ "checked_file": "/", "dependencies": [ "Spec.P256.fst.checked", "Spec.Exponentiation.fsti.checked", "prims.fst.checked", "Lib.NatMod.fsti.checked", "Lib.Exponentiation.fsti.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.P256.Qinv.fst" }
[ { "abbrev": true, "full_module": "Spec.P256", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.NatMod", "short_module": "M" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "LE" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.P256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.P256", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
x128: Spec.P256.PointOps.qelem -> x_11: Spec.P256.PointOps.qelem -> x_111: Spec.P256.PointOps.qelem -> x_1111: Spec.P256.PointOps.qelem -> x_10101: Spec.P256.PointOps.qelem -> x_101111: Spec.P256.PointOps.qelem -> Spec.P256.PointOps.qelem
Prims.Tot
[ "total" ]
[]
[ "Spec.P256.PointOps.qelem", "Spec.P256.PointOps.qmul", "Hacl.Spec.P256.Qinv.qsquare_times" ]
[]
false
false
false
true
false
let qinv_x134_x153 (x128 x_11 x_111 x_1111 x_10101 x_101111: S.qelem) : S.qelem =
let x134 = S.qmul (qsquare_times x128 6) x_101111 in let x139 = S.qmul (qsquare_times x134 5) x_111 in let x143 = S.qmul (qsquare_times x139 4) x_11 in let x148 = S.qmul (qsquare_times x143 5) x_1111 in let x153 = S.qmul (qsquare_times x148 5) x_10101 in x153
false
Hacl.Spec.P256.Qinv.fst
Hacl.Spec.P256.Qinv.qinv_x153_x177
val qinv_x153_x177 (x153 x_101 x_111 x_101111: S.qelem) : S.qelem
val qinv_x153_x177 (x153 x_101 x_111 x_101111: S.qelem) : S.qelem
let qinv_x153_x177 (x153 x_101 x_111 x_101111: S.qelem) : S.qelem = let x157 = S.qmul (qsquare_times x153 4) x_101 in let x160 = S.qmul (qsquare_times x157 3) x_101 in let x163 = S.qmul (qsquare_times x160 3) x_101 in let x168 = S.qmul (qsquare_times x163 5) x_111 in let x177 = S.qmul (qsquare_times x168 9) x_101111 in x177
{ "file_name": "code/ecdsap256/Hacl.Spec.P256.Qinv.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 6, "end_line": 72, "start_col": 0, "start_line": 66 }
module Hacl.Spec.P256.Qinv open FStar.Mul module SE = Spec.Exponentiation module LE = Lib.Exponentiation module M = Lib.NatMod module S = Spec.P256 #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" let nat_mod_comm_monoid = M.mk_nat_mod_comm_monoid S.order let mk_to_nat_mod_comm_monoid : SE.to_comm_monoid S.qelem = { SE.a_spec = S.qelem; SE.comm_monoid = nat_mod_comm_monoid; SE.refl = (fun (x:S.qelem) -> x); } val one_mod : SE.one_st S.qelem mk_to_nat_mod_comm_monoid let one_mod _ = 1 val mul_mod : SE.mul_st S.qelem mk_to_nat_mod_comm_monoid let mul_mod x y = S.qmul x y val sqr_mod : SE.sqr_st S.qelem mk_to_nat_mod_comm_monoid let sqr_mod x = S.qmul x x let mk_nat_mod_concrete_ops : SE.concrete_ops S.qelem = { SE.to = mk_to_nat_mod_comm_monoid; SE.one = one_mod; SE.mul = mul_mod; SE.sqr = sqr_mod; } let qsquare_times (a:S.qelem) (b:nat) : S.qelem = SE.exp_pow2 mk_nat_mod_concrete_ops a b val qsquare_times_lemma: a:S.qelem -> b:nat -> Lemma (qsquare_times a b == M.pow a (pow2 b) % S.order) let qsquare_times_lemma a b = SE.exp_pow2_lemma mk_nat_mod_concrete_ops a b; LE.exp_pow2_lemma nat_mod_comm_monoid a b; assert (qsquare_times a b == LE.pow nat_mod_comm_monoid a (pow2 b)); M.lemma_pow_nat_mod_is_pow #S.order a (pow2 b) let qinv_x8_x128 (x6 x_11: S.qelem) : S.qelem = let x8 = S.qmul (qsquare_times x6 2) x_11 in let x16 = S.qmul (qsquare_times x8 8) x8 in let x32 = S.qmul (qsquare_times x16 16) x16 in let x96 = S.qmul (qsquare_times x32 64) x32 in let x128 = S.qmul (qsquare_times x96 32) x32 in x128 let qinv_x134_x153 (x128 x_11 x_111 x_1111 x_10101 x_101111: S.qelem) : S.qelem = let x134 = S.qmul (qsquare_times x128 6) x_101111 in let x139 = S.qmul (qsquare_times x134 5) x_111 in let x143 = S.qmul (qsquare_times x139 4) x_11 in let x148 = S.qmul (qsquare_times x143 5) x_1111 in let x153 = S.qmul (qsquare_times x148 5) x_10101 in x153
{ "checked_file": "/", "dependencies": [ "Spec.P256.fst.checked", "Spec.Exponentiation.fsti.checked", "prims.fst.checked", "Lib.NatMod.fsti.checked", "Lib.Exponentiation.fsti.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.P256.Qinv.fst" }
[ { "abbrev": true, "full_module": "Spec.P256", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.NatMod", "short_module": "M" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "LE" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.P256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.P256", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
x153: Spec.P256.PointOps.qelem -> x_101: Spec.P256.PointOps.qelem -> x_111: Spec.P256.PointOps.qelem -> x_101111: Spec.P256.PointOps.qelem -> Spec.P256.PointOps.qelem
Prims.Tot
[ "total" ]
[]
[ "Spec.P256.PointOps.qelem", "Spec.P256.PointOps.qmul", "Hacl.Spec.P256.Qinv.qsquare_times" ]
[]
false
false
false
true
false
let qinv_x153_x177 (x153 x_101 x_111 x_101111: S.qelem) : S.qelem =
let x157 = S.qmul (qsquare_times x153 4) x_101 in let x160 = S.qmul (qsquare_times x157 3) x_101 in let x163 = S.qmul (qsquare_times x160 3) x_101 in let x168 = S.qmul (qsquare_times x163 5) x_111 in let x177 = S.qmul (qsquare_times x168 9) x_101111 in x177
false
Hacl.Spec.P256.Qinv.fst
Hacl.Spec.P256.Qinv.qinv_x8_x128
val qinv_x8_x128 (x6 x_11: S.qelem) : S.qelem
val qinv_x8_x128 (x6 x_11: S.qelem) : S.qelem
let qinv_x8_x128 (x6 x_11: S.qelem) : S.qelem = let x8 = S.qmul (qsquare_times x6 2) x_11 in let x16 = S.qmul (qsquare_times x8 8) x8 in let x32 = S.qmul (qsquare_times x16 16) x16 in let x96 = S.qmul (qsquare_times x32 64) x32 in let x128 = S.qmul (qsquare_times x96 32) x32 in x128
{ "file_name": "code/ecdsap256/Hacl.Spec.P256.Qinv.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 6, "end_line": 54, "start_col": 0, "start_line": 48 }
module Hacl.Spec.P256.Qinv open FStar.Mul module SE = Spec.Exponentiation module LE = Lib.Exponentiation module M = Lib.NatMod module S = Spec.P256 #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" let nat_mod_comm_monoid = M.mk_nat_mod_comm_monoid S.order let mk_to_nat_mod_comm_monoid : SE.to_comm_monoid S.qelem = { SE.a_spec = S.qelem; SE.comm_monoid = nat_mod_comm_monoid; SE.refl = (fun (x:S.qelem) -> x); } val one_mod : SE.one_st S.qelem mk_to_nat_mod_comm_monoid let one_mod _ = 1 val mul_mod : SE.mul_st S.qelem mk_to_nat_mod_comm_monoid let mul_mod x y = S.qmul x y val sqr_mod : SE.sqr_st S.qelem mk_to_nat_mod_comm_monoid let sqr_mod x = S.qmul x x let mk_nat_mod_concrete_ops : SE.concrete_ops S.qelem = { SE.to = mk_to_nat_mod_comm_monoid; SE.one = one_mod; SE.mul = mul_mod; SE.sqr = sqr_mod; } let qsquare_times (a:S.qelem) (b:nat) : S.qelem = SE.exp_pow2 mk_nat_mod_concrete_ops a b val qsquare_times_lemma: a:S.qelem -> b:nat -> Lemma (qsquare_times a b == M.pow a (pow2 b) % S.order) let qsquare_times_lemma a b = SE.exp_pow2_lemma mk_nat_mod_concrete_ops a b; LE.exp_pow2_lemma nat_mod_comm_monoid a b; assert (qsquare_times a b == LE.pow nat_mod_comm_monoid a (pow2 b)); M.lemma_pow_nat_mod_is_pow #S.order a (pow2 b)
{ "checked_file": "/", "dependencies": [ "Spec.P256.fst.checked", "Spec.Exponentiation.fsti.checked", "prims.fst.checked", "Lib.NatMod.fsti.checked", "Lib.Exponentiation.fsti.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.P256.Qinv.fst" }
[ { "abbrev": true, "full_module": "Spec.P256", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.NatMod", "short_module": "M" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "LE" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.P256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.P256", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
x6: Spec.P256.PointOps.qelem -> x_11: Spec.P256.PointOps.qelem -> Spec.P256.PointOps.qelem
Prims.Tot
[ "total" ]
[]
[ "Spec.P256.PointOps.qelem", "Spec.P256.PointOps.qmul", "Hacl.Spec.P256.Qinv.qsquare_times" ]
[]
false
false
false
true
false
let qinv_x8_x128 (x6 x_11: S.qelem) : S.qelem =
let x8 = S.qmul (qsquare_times x6 2) x_11 in let x16 = S.qmul (qsquare_times x8 8) x8 in let x32 = S.qmul (qsquare_times x16 16) x16 in let x96 = S.qmul (qsquare_times x32 64) x32 in let x128 = S.qmul (qsquare_times x96 32) x32 in x128
false
Hacl.Spec.P256.Qinv.fst
Hacl.Spec.P256.Qinv.qinv_x210_x240
val qinv_x210_x240 (x210 x_11 x_101 x_101111: S.qelem) : S.qelem
val qinv_x210_x240 (x210 x_11 x_101 x_101111: S.qelem) : S.qelem
let qinv_x210_x240 (x210 x_11 x_101 x_101111: S.qelem) : S.qelem = let x215 = S.qmul (qsquare_times x210 5) x_101 in let x218 = S.qmul (qsquare_times x215 3) x_11 in let x228 = S.qmul (qsquare_times x218 10) x_101111 in let x230 = S.qmul (qsquare_times x228 2) x_11 in let x235 = S.qmul (qsquare_times x230 5) x_11 in let x240 = S.qmul (qsquare_times x235 5) x_11 in x240
{ "file_name": "code/ecdsap256/Hacl.Spec.P256.Qinv.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 6, "end_line": 93, "start_col": 0, "start_line": 86 }
module Hacl.Spec.P256.Qinv open FStar.Mul module SE = Spec.Exponentiation module LE = Lib.Exponentiation module M = Lib.NatMod module S = Spec.P256 #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" let nat_mod_comm_monoid = M.mk_nat_mod_comm_monoid S.order let mk_to_nat_mod_comm_monoid : SE.to_comm_monoid S.qelem = { SE.a_spec = S.qelem; SE.comm_monoid = nat_mod_comm_monoid; SE.refl = (fun (x:S.qelem) -> x); } val one_mod : SE.one_st S.qelem mk_to_nat_mod_comm_monoid let one_mod _ = 1 val mul_mod : SE.mul_st S.qelem mk_to_nat_mod_comm_monoid let mul_mod x y = S.qmul x y val sqr_mod : SE.sqr_st S.qelem mk_to_nat_mod_comm_monoid let sqr_mod x = S.qmul x x let mk_nat_mod_concrete_ops : SE.concrete_ops S.qelem = { SE.to = mk_to_nat_mod_comm_monoid; SE.one = one_mod; SE.mul = mul_mod; SE.sqr = sqr_mod; } let qsquare_times (a:S.qelem) (b:nat) : S.qelem = SE.exp_pow2 mk_nat_mod_concrete_ops a b val qsquare_times_lemma: a:S.qelem -> b:nat -> Lemma (qsquare_times a b == M.pow a (pow2 b) % S.order) let qsquare_times_lemma a b = SE.exp_pow2_lemma mk_nat_mod_concrete_ops a b; LE.exp_pow2_lemma nat_mod_comm_monoid a b; assert (qsquare_times a b == LE.pow nat_mod_comm_monoid a (pow2 b)); M.lemma_pow_nat_mod_is_pow #S.order a (pow2 b) let qinv_x8_x128 (x6 x_11: S.qelem) : S.qelem = let x8 = S.qmul (qsquare_times x6 2) x_11 in let x16 = S.qmul (qsquare_times x8 8) x8 in let x32 = S.qmul (qsquare_times x16 16) x16 in let x96 = S.qmul (qsquare_times x32 64) x32 in let x128 = S.qmul (qsquare_times x96 32) x32 in x128 let qinv_x134_x153 (x128 x_11 x_111 x_1111 x_10101 x_101111: S.qelem) : S.qelem = let x134 = S.qmul (qsquare_times x128 6) x_101111 in let x139 = S.qmul (qsquare_times x134 5) x_111 in let x143 = S.qmul (qsquare_times x139 4) x_11 in let x148 = S.qmul (qsquare_times x143 5) x_1111 in let x153 = S.qmul (qsquare_times x148 5) x_10101 in x153 let qinv_x153_x177 (x153 x_101 x_111 x_101111: S.qelem) : S.qelem = let x157 = S.qmul (qsquare_times x153 4) x_101 in let x160 = S.qmul (qsquare_times x157 3) x_101 in let x163 = S.qmul (qsquare_times x160 3) x_101 in let x168 = S.qmul (qsquare_times x163 5) x_111 in let x177 = S.qmul (qsquare_times x168 9) x_101111 in x177 let qinv_x177_x210 (f x177 x_111 x_1111: S.qelem) : S.qelem = let x183 = S.qmul (qsquare_times x177 6) x_1111 in let x185 = S.qmul (qsquare_times x183 2) f in let x190 = S.qmul (qsquare_times x185 5) f in let x196 = S.qmul (qsquare_times x190 6) x_1111 in let x201 = S.qmul (qsquare_times x196 5) x_111 in let x205 = S.qmul (qsquare_times x201 4) x_111 in let x210 = S.qmul (qsquare_times x205 5) x_111 in x210
{ "checked_file": "/", "dependencies": [ "Spec.P256.fst.checked", "Spec.Exponentiation.fsti.checked", "prims.fst.checked", "Lib.NatMod.fsti.checked", "Lib.Exponentiation.fsti.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.P256.Qinv.fst" }
[ { "abbrev": true, "full_module": "Spec.P256", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.NatMod", "short_module": "M" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "LE" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.P256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.P256", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
x210: Spec.P256.PointOps.qelem -> x_11: Spec.P256.PointOps.qelem -> x_101: Spec.P256.PointOps.qelem -> x_101111: Spec.P256.PointOps.qelem -> Spec.P256.PointOps.qelem
Prims.Tot
[ "total" ]
[]
[ "Spec.P256.PointOps.qelem", "Spec.P256.PointOps.qmul", "Hacl.Spec.P256.Qinv.qsquare_times" ]
[]
false
false
false
true
false
let qinv_x210_x240 (x210 x_11 x_101 x_101111: S.qelem) : S.qelem =
let x215 = S.qmul (qsquare_times x210 5) x_101 in let x218 = S.qmul (qsquare_times x215 3) x_11 in let x228 = S.qmul (qsquare_times x218 10) x_101111 in let x230 = S.qmul (qsquare_times x228 2) x_11 in let x235 = S.qmul (qsquare_times x230 5) x_11 in let x240 = S.qmul (qsquare_times x235 5) x_11 in x240
false
Hacl.Spec.P256.Qinv.fst
Hacl.Spec.P256.Qinv.qinv_x240_x256
val qinv_x240_x256 (f x240 x_1111 x_10101: S.qelem) : S.qelem
val qinv_x240_x256 (f x240 x_1111 x_10101: S.qelem) : S.qelem
let qinv_x240_x256 (f x240 x_1111 x_10101: S.qelem) : S.qelem = let x243 = S.qmul (qsquare_times x240 3) f in let x250 = S.qmul (qsquare_times x243 7) x_10101 in let x256 = S.qmul (qsquare_times x250 6) x_1111 in x256
{ "file_name": "code/ecdsap256/Hacl.Spec.P256.Qinv.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 6, "end_line": 100, "start_col": 0, "start_line": 96 }
module Hacl.Spec.P256.Qinv open FStar.Mul module SE = Spec.Exponentiation module LE = Lib.Exponentiation module M = Lib.NatMod module S = Spec.P256 #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" let nat_mod_comm_monoid = M.mk_nat_mod_comm_monoid S.order let mk_to_nat_mod_comm_monoid : SE.to_comm_monoid S.qelem = { SE.a_spec = S.qelem; SE.comm_monoid = nat_mod_comm_monoid; SE.refl = (fun (x:S.qelem) -> x); } val one_mod : SE.one_st S.qelem mk_to_nat_mod_comm_monoid let one_mod _ = 1 val mul_mod : SE.mul_st S.qelem mk_to_nat_mod_comm_monoid let mul_mod x y = S.qmul x y val sqr_mod : SE.sqr_st S.qelem mk_to_nat_mod_comm_monoid let sqr_mod x = S.qmul x x let mk_nat_mod_concrete_ops : SE.concrete_ops S.qelem = { SE.to = mk_to_nat_mod_comm_monoid; SE.one = one_mod; SE.mul = mul_mod; SE.sqr = sqr_mod; } let qsquare_times (a:S.qelem) (b:nat) : S.qelem = SE.exp_pow2 mk_nat_mod_concrete_ops a b val qsquare_times_lemma: a:S.qelem -> b:nat -> Lemma (qsquare_times a b == M.pow a (pow2 b) % S.order) let qsquare_times_lemma a b = SE.exp_pow2_lemma mk_nat_mod_concrete_ops a b; LE.exp_pow2_lemma nat_mod_comm_monoid a b; assert (qsquare_times a b == LE.pow nat_mod_comm_monoid a (pow2 b)); M.lemma_pow_nat_mod_is_pow #S.order a (pow2 b) let qinv_x8_x128 (x6 x_11: S.qelem) : S.qelem = let x8 = S.qmul (qsquare_times x6 2) x_11 in let x16 = S.qmul (qsquare_times x8 8) x8 in let x32 = S.qmul (qsquare_times x16 16) x16 in let x96 = S.qmul (qsquare_times x32 64) x32 in let x128 = S.qmul (qsquare_times x96 32) x32 in x128 let qinv_x134_x153 (x128 x_11 x_111 x_1111 x_10101 x_101111: S.qelem) : S.qelem = let x134 = S.qmul (qsquare_times x128 6) x_101111 in let x139 = S.qmul (qsquare_times x134 5) x_111 in let x143 = S.qmul (qsquare_times x139 4) x_11 in let x148 = S.qmul (qsquare_times x143 5) x_1111 in let x153 = S.qmul (qsquare_times x148 5) x_10101 in x153 let qinv_x153_x177 (x153 x_101 x_111 x_101111: S.qelem) : S.qelem = let x157 = S.qmul (qsquare_times x153 4) x_101 in let x160 = S.qmul (qsquare_times x157 3) x_101 in let x163 = S.qmul (qsquare_times x160 3) x_101 in let x168 = S.qmul (qsquare_times x163 5) x_111 in let x177 = S.qmul (qsquare_times x168 9) x_101111 in x177 let qinv_x177_x210 (f x177 x_111 x_1111: S.qelem) : S.qelem = let x183 = S.qmul (qsquare_times x177 6) x_1111 in let x185 = S.qmul (qsquare_times x183 2) f in let x190 = S.qmul (qsquare_times x185 5) f in let x196 = S.qmul (qsquare_times x190 6) x_1111 in let x201 = S.qmul (qsquare_times x196 5) x_111 in let x205 = S.qmul (qsquare_times x201 4) x_111 in let x210 = S.qmul (qsquare_times x205 5) x_111 in x210 let qinv_x210_x240 (x210 x_11 x_101 x_101111: S.qelem) : S.qelem = let x215 = S.qmul (qsquare_times x210 5) x_101 in let x218 = S.qmul (qsquare_times x215 3) x_11 in let x228 = S.qmul (qsquare_times x218 10) x_101111 in let x230 = S.qmul (qsquare_times x228 2) x_11 in let x235 = S.qmul (qsquare_times x230 5) x_11 in let x240 = S.qmul (qsquare_times x235 5) x_11 in x240
{ "checked_file": "/", "dependencies": [ "Spec.P256.fst.checked", "Spec.Exponentiation.fsti.checked", "prims.fst.checked", "Lib.NatMod.fsti.checked", "Lib.Exponentiation.fsti.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.P256.Qinv.fst" }
[ { "abbrev": true, "full_module": "Spec.P256", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.NatMod", "short_module": "M" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "LE" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.P256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.P256", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
f: Spec.P256.PointOps.qelem -> x240: Spec.P256.PointOps.qelem -> x_1111: Spec.P256.PointOps.qelem -> x_10101: Spec.P256.PointOps.qelem -> Spec.P256.PointOps.qelem
Prims.Tot
[ "total" ]
[]
[ "Spec.P256.PointOps.qelem", "Spec.P256.PointOps.qmul", "Hacl.Spec.P256.Qinv.qsquare_times" ]
[]
false
false
false
true
false
let qinv_x240_x256 (f x240 x_1111 x_10101: S.qelem) : S.qelem =
let x243 = S.qmul (qsquare_times x240 3) f in let x250 = S.qmul (qsquare_times x243 7) x_10101 in let x256 = S.qmul (qsquare_times x250 6) x_1111 in x256
false
Hacl.Spec.P256.Qinv.fst
Hacl.Spec.P256.Qinv.qinv_x177_x210
val qinv_x177_x210 (f x177 x_111 x_1111: S.qelem) : S.qelem
val qinv_x177_x210 (f x177 x_111 x_1111: S.qelem) : S.qelem
let qinv_x177_x210 (f x177 x_111 x_1111: S.qelem) : S.qelem = let x183 = S.qmul (qsquare_times x177 6) x_1111 in let x185 = S.qmul (qsquare_times x183 2) f in let x190 = S.qmul (qsquare_times x185 5) f in let x196 = S.qmul (qsquare_times x190 6) x_1111 in let x201 = S.qmul (qsquare_times x196 5) x_111 in let x205 = S.qmul (qsquare_times x201 4) x_111 in let x210 = S.qmul (qsquare_times x205 5) x_111 in x210
{ "file_name": "code/ecdsap256/Hacl.Spec.P256.Qinv.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 6, "end_line": 83, "start_col": 0, "start_line": 75 }
module Hacl.Spec.P256.Qinv open FStar.Mul module SE = Spec.Exponentiation module LE = Lib.Exponentiation module M = Lib.NatMod module S = Spec.P256 #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" let nat_mod_comm_monoid = M.mk_nat_mod_comm_monoid S.order let mk_to_nat_mod_comm_monoid : SE.to_comm_monoid S.qelem = { SE.a_spec = S.qelem; SE.comm_monoid = nat_mod_comm_monoid; SE.refl = (fun (x:S.qelem) -> x); } val one_mod : SE.one_st S.qelem mk_to_nat_mod_comm_monoid let one_mod _ = 1 val mul_mod : SE.mul_st S.qelem mk_to_nat_mod_comm_monoid let mul_mod x y = S.qmul x y val sqr_mod : SE.sqr_st S.qelem mk_to_nat_mod_comm_monoid let sqr_mod x = S.qmul x x let mk_nat_mod_concrete_ops : SE.concrete_ops S.qelem = { SE.to = mk_to_nat_mod_comm_monoid; SE.one = one_mod; SE.mul = mul_mod; SE.sqr = sqr_mod; } let qsquare_times (a:S.qelem) (b:nat) : S.qelem = SE.exp_pow2 mk_nat_mod_concrete_ops a b val qsquare_times_lemma: a:S.qelem -> b:nat -> Lemma (qsquare_times a b == M.pow a (pow2 b) % S.order) let qsquare_times_lemma a b = SE.exp_pow2_lemma mk_nat_mod_concrete_ops a b; LE.exp_pow2_lemma nat_mod_comm_monoid a b; assert (qsquare_times a b == LE.pow nat_mod_comm_monoid a (pow2 b)); M.lemma_pow_nat_mod_is_pow #S.order a (pow2 b) let qinv_x8_x128 (x6 x_11: S.qelem) : S.qelem = let x8 = S.qmul (qsquare_times x6 2) x_11 in let x16 = S.qmul (qsquare_times x8 8) x8 in let x32 = S.qmul (qsquare_times x16 16) x16 in let x96 = S.qmul (qsquare_times x32 64) x32 in let x128 = S.qmul (qsquare_times x96 32) x32 in x128 let qinv_x134_x153 (x128 x_11 x_111 x_1111 x_10101 x_101111: S.qelem) : S.qelem = let x134 = S.qmul (qsquare_times x128 6) x_101111 in let x139 = S.qmul (qsquare_times x134 5) x_111 in let x143 = S.qmul (qsquare_times x139 4) x_11 in let x148 = S.qmul (qsquare_times x143 5) x_1111 in let x153 = S.qmul (qsquare_times x148 5) x_10101 in x153 let qinv_x153_x177 (x153 x_101 x_111 x_101111: S.qelem) : S.qelem = let x157 = S.qmul (qsquare_times x153 4) x_101 in let x160 = S.qmul (qsquare_times x157 3) x_101 in let x163 = S.qmul (qsquare_times x160 3) x_101 in let x168 = S.qmul (qsquare_times x163 5) x_111 in let x177 = S.qmul (qsquare_times x168 9) x_101111 in x177
{ "checked_file": "/", "dependencies": [ "Spec.P256.fst.checked", "Spec.Exponentiation.fsti.checked", "prims.fst.checked", "Lib.NatMod.fsti.checked", "Lib.Exponentiation.fsti.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.P256.Qinv.fst" }
[ { "abbrev": true, "full_module": "Spec.P256", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.NatMod", "short_module": "M" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "LE" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.P256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.P256", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
f: Spec.P256.PointOps.qelem -> x177: Spec.P256.PointOps.qelem -> x_111: Spec.P256.PointOps.qelem -> x_1111: Spec.P256.PointOps.qelem -> Spec.P256.PointOps.qelem
Prims.Tot
[ "total" ]
[]
[ "Spec.P256.PointOps.qelem", "Spec.P256.PointOps.qmul", "Hacl.Spec.P256.Qinv.qsquare_times" ]
[]
false
false
false
true
false
let qinv_x177_x210 (f x177 x_111 x_1111: S.qelem) : S.qelem =
let x183 = S.qmul (qsquare_times x177 6) x_1111 in let x185 = S.qmul (qsquare_times x183 2) f in let x190 = S.qmul (qsquare_times x185 5) f in let x196 = S.qmul (qsquare_times x190 6) x_1111 in let x201 = S.qmul (qsquare_times x196 5) x_111 in let x205 = S.qmul (qsquare_times x201 4) x_111 in let x210 = S.qmul (qsquare_times x205 5) x_111 in x210
false
Steel.ST.GenArraySwap.Proof.fst
Steel.ST.GenArraySwap.Proof.jump_mod_d
val jump_mod_d (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Lemma (jump n l x % b.d == x % b.d)
val jump_mod_d (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Lemma (jump n l x % b.d == x % b.d)
let jump_mod_d (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Lemma (jump n l x % b.d == x % b.d) = let x' = jump n l x in let x'q = (x + l) / n in euclidean_division_definition (x + l) n; let l_alt = b.d * b.q_l in assert (l_alt == l); let n_alt = b.d * b.q_n in assert (n_alt == n); let x'_alt = x + l_alt + - x'q * n_alt in assert (x'_alt == x'); let qx = b.q_l + - x'q * b.q_n in assert (eq2 #int x'_alt (x + qx * b.d)) by (int_semiring ()); lemma_mod_plus x qx b.d
{ "file_name": "lib/steel/Steel.ST.GenArraySwap.Proof.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 25, "end_line": 218, "start_col": 0, "start_line": 199 }
module Steel.ST.GenArraySwap.Proof open FStar.Math.Lemmas open FStar.Mul let lemma_mod_lt (a:int) (b:pos) : Lemma (let r = a % b in 0 <= r /\ r < b) [SMTPat (a % b)] = () let lemma_mul_nat_nat_is_nat (a b: nat) : Lemma (a * b >= 0) [SMTPat (a * b)] = () let lemma_pos_mul_pos_args (a: nat) (b: nat) : Lemma (requires (a * b > 0)) (ensures (a > 0 /\ b > 0 /\ a <= a * b /\ b <= a * b /\ a * b == b * a)) = () let lemma_div_nat (a: nat) (b: pos) : Lemma (a / b >= 0) [SMTPat (a / b)] = () let lemma_mult_reg_l (k: int) (x1 x2: int) : Lemma (requires ( k * x1 == k * x2 /\ k <> 0 )) (ensures ( x1 == x2 )) = () let lemma_bezout_one_zero (x1: int) (x2: nat) (y1 y2: int) : Lemma (requires ( x1 * x2 + y1 * y2 == 1 /\ y1 == 0 )) (ensures ( x1 == 1 /\ x2 == 1 )) = () #set-options "--z3cliopt smt.arith.nl=false" let int_semiring () = FStar.Tactics.CanonCommSemiring.int_semiring (); FStar.Tactics.trefl (); FStar.Tactics.qed () [@@erasable] noeq type bezout_t = { d: pos; q_n: nat; q_l: nat; u_n: int; u_l: int; } let bezout_prop' (n: nat) (l: nat) (d: pos) (q_n: nat) (q_l: nat) (u_n: int) (u_l: int) : Tot prop = n == d * q_n /\ l == d * q_l /\ d == n * u_n + l * u_l let bezout_prop (n: nat) (l: nat) (b: bezout_t) : Tot prop = bezout_prop' n l b.d b.q_n b.q_l b.u_n b.u_l let bezout (n: nat) (l: nat) : Tot Type = (b: bezout_t { bezout_prop n l b }) #restart-solver let rec mk_bezout (n: pos) (l: nat) : Pure (bezout n l) (requires (l < n)) (ensures (fun _ -> True)) (decreases l) = if l = 0 then begin let d : pos = n in let q_n : nat = 1 in let q_l : nat = 0 in let u_n : int = 1 in let u_l : int = 0 in let res = { d = d; q_n = q_n; q_l = q_l; u_n = u_n; u_l = u_l; } in assert (eq2 #int n (d * q_n)) by (int_semiring ()); assert (eq2 #int 0 (d * q_l)) by (int_semiring ()); assert (eq2 #int d (n * 1 + 0 * res.u_l)) by (int_semiring ()); res end else begin let lpre = n % l in let ql = n / l in euclidean_division_definition n l; let bpre = mk_bezout l lpre in let d = bpre.d in let q_l = bpre.q_n in let qpre_lpre = bpre.q_l in let upre_l = bpre.u_n in let upre_lpre = bpre.u_l in let n_alt0 = l * ql + lpre in assert (n == n_alt0); let l_alt = d * q_l in let lpre_alt1 = d * qpre_lpre in let n_alt1 = l_alt * ql + lpre_alt1 in assert (n_alt1 == n); let q_n = q_l * ql + qpre_lpre in assert (eq2 #int n_alt1 (d * q_n)) by (int_semiring ()); let lpre_alt2 = n + - l * ql in assert (lpre_alt2 == lpre); let d_alt = l * upre_l + lpre_alt2 * upre_lpre in assert (d_alt == d); let u_l = upre_l + - ql * upre_lpre in assert (eq2 #int (n * upre_lpre + l * u_l) d_alt) by (int_semiring ()); let res = { d = d; q_n = q_n; q_l = q_l; u_n = upre_lpre; u_l = u_l; } in res end let bezout_q_eq (n: nat) (l: nat) (bz: bezout n l) : Lemma (bz.q_n == n / bz.d) [SMTPat (bezout_prop n l bz); SMTPat bz.q_n] = cancel_mul_div bz.q_n bz.d let rec iter_fun (#t: Type) (f: (t -> GTot t)) (n: nat) (x: t) : GTot t (decreases n) = if n = 0 then x else iter_fun f (n - 1) (f x) let nat_up_to (n: nat) : Tot Type = (i: nat { i < n }) let jump (n: pos) (l: nat) (x: nat_up_to n) : GTot (nat_up_to n) = (x + l) % n
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.CanonCommSemiring.fst.checked", "FStar.Tactics.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Steel.ST.GenArraySwap.Proof.fst" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.GenArraySwap", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.GenArraySwap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
n: Prims.pos -> l: Prims.nat -> b: Steel.ST.GenArraySwap.Proof.bezout n l -> x: Steel.ST.GenArraySwap.Proof.nat_up_to n -> FStar.Pervasives.Lemma (ensures Steel.ST.GenArraySwap.Proof.jump n l x % Mkbezout_t?.d b == x % Mkbezout_t?.d b)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.pos", "Prims.nat", "Steel.ST.GenArraySwap.Proof.bezout", "Steel.ST.GenArraySwap.Proof.nat_up_to", "FStar.Math.Lemmas.lemma_mod_plus", "Steel.ST.GenArraySwap.Proof.__proj__Mkbezout_t__item__d", "Prims.unit", "FStar.Tactics.Effect.assert_by_tactic", "Prims.eq2", "Prims.int", "Prims.op_Addition", "FStar.Mul.op_Star", "Steel.ST.GenArraySwap.Proof.int_semiring", "Steel.ST.GenArraySwap.Proof.__proj__Mkbezout_t__item__q_l", "Prims.op_Minus", "Steel.ST.GenArraySwap.Proof.__proj__Mkbezout_t__item__q_n", "Prims._assert", "FStar.Math.Lemmas.euclidean_division_definition", "Prims.op_Division", "Steel.ST.GenArraySwap.Proof.jump", "Prims.l_True", "Prims.squash", "Prims.op_Modulus", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let jump_mod_d (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Lemma (jump n l x % b.d == x % b.d) =
let x' = jump n l x in let x'q = (x + l) / n in euclidean_division_definition (x + l) n; let l_alt = b.d * b.q_l in assert (l_alt == l); let n_alt = b.d * b.q_n in assert (n_alt == n); let x'_alt = x + l_alt + - x'q * n_alt in assert (x'_alt == x'); let qx = b.q_l + - x'q * b.q_n in FStar.Tactics.Effect.assert_by_tactic (eq2 #int x'_alt (x + qx * b.d)) (fun _ -> (); (int_semiring ())); lemma_mod_plus x qx b.d
false
Hacl.Spec.P256.Qinv.fst
Hacl.Spec.P256.Qinv.qinv_x8_x256
val qinv_x8_x256 (f x6 x_11 x_101 x_111 x_1111 x_10101 x_101111: S.qelem) : S.qelem
val qinv_x8_x256 (f x6 x_11 x_101 x_111 x_1111 x_10101 x_101111: S.qelem) : S.qelem
let qinv_x8_x256 (f x6 x_11 x_101 x_111 x_1111 x_10101 x_101111 : S.qelem) : S.qelem = let x128 = qinv_x8_x128 x6 x_11 in let x153 = qinv_x134_x153 x128 x_11 x_111 x_1111 x_10101 x_101111 in let x177 = qinv_x153_x177 x153 x_101 x_111 x_101111 in let x210 = qinv_x177_x210 f x177 x_111 x_1111 in let x240 = qinv_x210_x240 x210 x_11 x_101 x_101111 in let x256 = qinv_x240_x256 f x240 x_1111 x_10101 in x256
{ "file_name": "code/ecdsap256/Hacl.Spec.P256.Qinv.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 6, "end_line": 110, "start_col": 0, "start_line": 103 }
module Hacl.Spec.P256.Qinv open FStar.Mul module SE = Spec.Exponentiation module LE = Lib.Exponentiation module M = Lib.NatMod module S = Spec.P256 #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" let nat_mod_comm_monoid = M.mk_nat_mod_comm_monoid S.order let mk_to_nat_mod_comm_monoid : SE.to_comm_monoid S.qelem = { SE.a_spec = S.qelem; SE.comm_monoid = nat_mod_comm_monoid; SE.refl = (fun (x:S.qelem) -> x); } val one_mod : SE.one_st S.qelem mk_to_nat_mod_comm_monoid let one_mod _ = 1 val mul_mod : SE.mul_st S.qelem mk_to_nat_mod_comm_monoid let mul_mod x y = S.qmul x y val sqr_mod : SE.sqr_st S.qelem mk_to_nat_mod_comm_monoid let sqr_mod x = S.qmul x x let mk_nat_mod_concrete_ops : SE.concrete_ops S.qelem = { SE.to = mk_to_nat_mod_comm_monoid; SE.one = one_mod; SE.mul = mul_mod; SE.sqr = sqr_mod; } let qsquare_times (a:S.qelem) (b:nat) : S.qelem = SE.exp_pow2 mk_nat_mod_concrete_ops a b val qsquare_times_lemma: a:S.qelem -> b:nat -> Lemma (qsquare_times a b == M.pow a (pow2 b) % S.order) let qsquare_times_lemma a b = SE.exp_pow2_lemma mk_nat_mod_concrete_ops a b; LE.exp_pow2_lemma nat_mod_comm_monoid a b; assert (qsquare_times a b == LE.pow nat_mod_comm_monoid a (pow2 b)); M.lemma_pow_nat_mod_is_pow #S.order a (pow2 b) let qinv_x8_x128 (x6 x_11: S.qelem) : S.qelem = let x8 = S.qmul (qsquare_times x6 2) x_11 in let x16 = S.qmul (qsquare_times x8 8) x8 in let x32 = S.qmul (qsquare_times x16 16) x16 in let x96 = S.qmul (qsquare_times x32 64) x32 in let x128 = S.qmul (qsquare_times x96 32) x32 in x128 let qinv_x134_x153 (x128 x_11 x_111 x_1111 x_10101 x_101111: S.qelem) : S.qelem = let x134 = S.qmul (qsquare_times x128 6) x_101111 in let x139 = S.qmul (qsquare_times x134 5) x_111 in let x143 = S.qmul (qsquare_times x139 4) x_11 in let x148 = S.qmul (qsquare_times x143 5) x_1111 in let x153 = S.qmul (qsquare_times x148 5) x_10101 in x153 let qinv_x153_x177 (x153 x_101 x_111 x_101111: S.qelem) : S.qelem = let x157 = S.qmul (qsquare_times x153 4) x_101 in let x160 = S.qmul (qsquare_times x157 3) x_101 in let x163 = S.qmul (qsquare_times x160 3) x_101 in let x168 = S.qmul (qsquare_times x163 5) x_111 in let x177 = S.qmul (qsquare_times x168 9) x_101111 in x177 let qinv_x177_x210 (f x177 x_111 x_1111: S.qelem) : S.qelem = let x183 = S.qmul (qsquare_times x177 6) x_1111 in let x185 = S.qmul (qsquare_times x183 2) f in let x190 = S.qmul (qsquare_times x185 5) f in let x196 = S.qmul (qsquare_times x190 6) x_1111 in let x201 = S.qmul (qsquare_times x196 5) x_111 in let x205 = S.qmul (qsquare_times x201 4) x_111 in let x210 = S.qmul (qsquare_times x205 5) x_111 in x210 let qinv_x210_x240 (x210 x_11 x_101 x_101111: S.qelem) : S.qelem = let x215 = S.qmul (qsquare_times x210 5) x_101 in let x218 = S.qmul (qsquare_times x215 3) x_11 in let x228 = S.qmul (qsquare_times x218 10) x_101111 in let x230 = S.qmul (qsquare_times x228 2) x_11 in let x235 = S.qmul (qsquare_times x230 5) x_11 in let x240 = S.qmul (qsquare_times x235 5) x_11 in x240 let qinv_x240_x256 (f x240 x_1111 x_10101: S.qelem) : S.qelem = let x243 = S.qmul (qsquare_times x240 3) f in let x250 = S.qmul (qsquare_times x243 7) x_10101 in let x256 = S.qmul (qsquare_times x250 6) x_1111 in x256
{ "checked_file": "/", "dependencies": [ "Spec.P256.fst.checked", "Spec.Exponentiation.fsti.checked", "prims.fst.checked", "Lib.NatMod.fsti.checked", "Lib.Exponentiation.fsti.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.P256.Qinv.fst" }
[ { "abbrev": true, "full_module": "Spec.P256", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.NatMod", "short_module": "M" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "LE" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.P256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.P256", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
f: Spec.P256.PointOps.qelem -> x6: Spec.P256.PointOps.qelem -> x_11: Spec.P256.PointOps.qelem -> x_101: Spec.P256.PointOps.qelem -> x_111: Spec.P256.PointOps.qelem -> x_1111: Spec.P256.PointOps.qelem -> x_10101: Spec.P256.PointOps.qelem -> x_101111: Spec.P256.PointOps.qelem -> Spec.P256.PointOps.qelem
Prims.Tot
[ "total" ]
[]
[ "Spec.P256.PointOps.qelem", "Hacl.Spec.P256.Qinv.qinv_x240_x256", "Hacl.Spec.P256.Qinv.qinv_x210_x240", "Hacl.Spec.P256.Qinv.qinv_x177_x210", "Hacl.Spec.P256.Qinv.qinv_x153_x177", "Hacl.Spec.P256.Qinv.qinv_x134_x153", "Hacl.Spec.P256.Qinv.qinv_x8_x128" ]
[]
false
false
false
true
false
let qinv_x8_x256 (f x6 x_11 x_101 x_111 x_1111 x_10101 x_101111: S.qelem) : S.qelem =
let x128 = qinv_x8_x128 x6 x_11 in let x153 = qinv_x134_x153 x128 x_11 x_111 x_1111 x_10101 x_101111 in let x177 = qinv_x153_x177 x153 x_101 x_111 x_101111 in let x210 = qinv_x177_x210 f x177 x_111 x_1111 in let x240 = qinv_x210_x240 x210 x_11 x_101 x_101111 in let x256 = qinv_x240_x256 f x240 x_1111 x_10101 in x256
false
Hacl.Spec.P256.Qinv.fst
Hacl.Spec.P256.Qinv.qinv
val qinv: f:S.qelem -> S.qelem
val qinv: f:S.qelem -> S.qelem
let qinv f = let x_10 = qsquare_times f 1 in // x_10 is used 3x let x_11 = S.qmul x_10 f in let x_101 = S.qmul x_10 x_11 in let x_111 = S.qmul x_10 x_101 in let x_1010 = qsquare_times x_101 1 in // x_1010 is used 2x let x_1111 = S.qmul x_101 x_1010 in let x_10101 = S.qmul (qsquare_times x_1010 1) f in let x_101010 = qsquare_times x_10101 1 in // x_101010 is used 2x let x_101111 = S.qmul x_101 x_101010 in let x6 = S.qmul x_10101 x_101010 in qinv_x8_x256 f x6 x_11 x_101 x_111 x_1111 x_10101 x_101111
{ "file_name": "code/ecdsap256/Hacl.Spec.P256.Qinv.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 60, "end_line": 131, "start_col": 0, "start_line": 118 }
module Hacl.Spec.P256.Qinv open FStar.Mul module SE = Spec.Exponentiation module LE = Lib.Exponentiation module M = Lib.NatMod module S = Spec.P256 #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" let nat_mod_comm_monoid = M.mk_nat_mod_comm_monoid S.order let mk_to_nat_mod_comm_monoid : SE.to_comm_monoid S.qelem = { SE.a_spec = S.qelem; SE.comm_monoid = nat_mod_comm_monoid; SE.refl = (fun (x:S.qelem) -> x); } val one_mod : SE.one_st S.qelem mk_to_nat_mod_comm_monoid let one_mod _ = 1 val mul_mod : SE.mul_st S.qelem mk_to_nat_mod_comm_monoid let mul_mod x y = S.qmul x y val sqr_mod : SE.sqr_st S.qelem mk_to_nat_mod_comm_monoid let sqr_mod x = S.qmul x x let mk_nat_mod_concrete_ops : SE.concrete_ops S.qelem = { SE.to = mk_to_nat_mod_comm_monoid; SE.one = one_mod; SE.mul = mul_mod; SE.sqr = sqr_mod; } let qsquare_times (a:S.qelem) (b:nat) : S.qelem = SE.exp_pow2 mk_nat_mod_concrete_ops a b val qsquare_times_lemma: a:S.qelem -> b:nat -> Lemma (qsquare_times a b == M.pow a (pow2 b) % S.order) let qsquare_times_lemma a b = SE.exp_pow2_lemma mk_nat_mod_concrete_ops a b; LE.exp_pow2_lemma nat_mod_comm_monoid a b; assert (qsquare_times a b == LE.pow nat_mod_comm_monoid a (pow2 b)); M.lemma_pow_nat_mod_is_pow #S.order a (pow2 b) let qinv_x8_x128 (x6 x_11: S.qelem) : S.qelem = let x8 = S.qmul (qsquare_times x6 2) x_11 in let x16 = S.qmul (qsquare_times x8 8) x8 in let x32 = S.qmul (qsquare_times x16 16) x16 in let x96 = S.qmul (qsquare_times x32 64) x32 in let x128 = S.qmul (qsquare_times x96 32) x32 in x128 let qinv_x134_x153 (x128 x_11 x_111 x_1111 x_10101 x_101111: S.qelem) : S.qelem = let x134 = S.qmul (qsquare_times x128 6) x_101111 in let x139 = S.qmul (qsquare_times x134 5) x_111 in let x143 = S.qmul (qsquare_times x139 4) x_11 in let x148 = S.qmul (qsquare_times x143 5) x_1111 in let x153 = S.qmul (qsquare_times x148 5) x_10101 in x153 let qinv_x153_x177 (x153 x_101 x_111 x_101111: S.qelem) : S.qelem = let x157 = S.qmul (qsquare_times x153 4) x_101 in let x160 = S.qmul (qsquare_times x157 3) x_101 in let x163 = S.qmul (qsquare_times x160 3) x_101 in let x168 = S.qmul (qsquare_times x163 5) x_111 in let x177 = S.qmul (qsquare_times x168 9) x_101111 in x177 let qinv_x177_x210 (f x177 x_111 x_1111: S.qelem) : S.qelem = let x183 = S.qmul (qsquare_times x177 6) x_1111 in let x185 = S.qmul (qsquare_times x183 2) f in let x190 = S.qmul (qsquare_times x185 5) f in let x196 = S.qmul (qsquare_times x190 6) x_1111 in let x201 = S.qmul (qsquare_times x196 5) x_111 in let x205 = S.qmul (qsquare_times x201 4) x_111 in let x210 = S.qmul (qsquare_times x205 5) x_111 in x210 let qinv_x210_x240 (x210 x_11 x_101 x_101111: S.qelem) : S.qelem = let x215 = S.qmul (qsquare_times x210 5) x_101 in let x218 = S.qmul (qsquare_times x215 3) x_11 in let x228 = S.qmul (qsquare_times x218 10) x_101111 in let x230 = S.qmul (qsquare_times x228 2) x_11 in let x235 = S.qmul (qsquare_times x230 5) x_11 in let x240 = S.qmul (qsquare_times x235 5) x_11 in x240 let qinv_x240_x256 (f x240 x_1111 x_10101: S.qelem) : S.qelem = let x243 = S.qmul (qsquare_times x240 3) f in let x250 = S.qmul (qsquare_times x243 7) x_10101 in let x256 = S.qmul (qsquare_times x250 6) x_1111 in x256 let qinv_x8_x256 (f x6 x_11 x_101 x_111 x_1111 x_10101 x_101111 : S.qelem) : S.qelem = let x128 = qinv_x8_x128 x6 x_11 in let x153 = qinv_x134_x153 x128 x_11 x_111 x_1111 x_10101 x_101111 in let x177 = qinv_x153_x177 x153 x_101 x_111 x_101111 in let x210 = qinv_x177_x210 f x177 x_111 x_1111 in let x240 = qinv_x210_x240 x210 x_11 x_101 x_101111 in let x256 = qinv_x240_x256 f x240 x_1111 x_10101 in x256 (** The algorithm is taken from https://briansmith.org/ecc-inversion-addition-chains-01 *)
{ "checked_file": "/", "dependencies": [ "Spec.P256.fst.checked", "Spec.Exponentiation.fsti.checked", "prims.fst.checked", "Lib.NatMod.fsti.checked", "Lib.Exponentiation.fsti.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.P256.Qinv.fst" }
[ { "abbrev": true, "full_module": "Spec.P256", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.NatMod", "short_module": "M" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "LE" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.P256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.P256", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
f: Spec.P256.PointOps.qelem -> Spec.P256.PointOps.qelem
Prims.Tot
[ "total" ]
[]
[ "Spec.P256.PointOps.qelem", "Hacl.Spec.P256.Qinv.qinv_x8_x256", "Spec.P256.PointOps.qmul", "Hacl.Spec.P256.Qinv.qsquare_times" ]
[]
false
false
false
true
false
let qinv f =
let x_10 = qsquare_times f 1 in let x_11 = S.qmul x_10 f in let x_101 = S.qmul x_10 x_11 in let x_111 = S.qmul x_10 x_101 in let x_1010 = qsquare_times x_101 1 in let x_1111 = S.qmul x_101 x_1010 in let x_10101 = S.qmul (qsquare_times x_1010 1) f in let x_101010 = qsquare_times x_10101 1 in let x_101111 = S.qmul x_101 x_101010 in let x6 = S.qmul x_10101 x_101010 in qinv_x8_x256 f x6 x_11 x_101 x_111 x_1111 x_10101 x_101111
false
Steel.ST.GenArraySwap.Proof.fst
Steel.ST.GenArraySwap.Proof.jump_iter_mod_q
val jump_iter_mod_q (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) (k: nat) : Lemma (ensures (b.q_n > 0 /\ iter_fun (jump n l) (k % b.q_n) x == iter_fun (jump n l) k x))
val jump_iter_mod_q (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) (k: nat) : Lemma (ensures (b.q_n > 0 /\ iter_fun (jump n l) (k % b.q_n) x == iter_fun (jump n l) k x))
let jump_iter_mod_q (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) (k: nat) : Lemma (ensures ( b.q_n > 0 /\ iter_fun (jump n l) (k % b.q_n) x == iter_fun (jump n l) k x )) = assert (b.q_n > 0); let k' = k % b.q_n in let qk = k / b.q_n in euclidean_division_definition k b.q_n; jump_iter n l x k'; jump_iter n l x k; assert (eq2 #int (x + (qk * b.q_n + k') * (b.d * b.q_l)) (x + k' * (b.d * b.q_l) + (qk * b.q_l) * (b.d * b.q_n))) by (int_semiring ()); assert (x + k * l == x + k' * l + (qk * b.q_l) * n); lemma_mod_plus (x + k' * l) (qk * b.q_l) n
{ "file_name": "lib/steel/Steel.ST.GenArraySwap.Proof.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 44, "end_line": 371, "start_col": 0, "start_line": 352 }
module Steel.ST.GenArraySwap.Proof open FStar.Math.Lemmas open FStar.Mul let lemma_mod_lt (a:int) (b:pos) : Lemma (let r = a % b in 0 <= r /\ r < b) [SMTPat (a % b)] = () let lemma_mul_nat_nat_is_nat (a b: nat) : Lemma (a * b >= 0) [SMTPat (a * b)] = () let lemma_pos_mul_pos_args (a: nat) (b: nat) : Lemma (requires (a * b > 0)) (ensures (a > 0 /\ b > 0 /\ a <= a * b /\ b <= a * b /\ a * b == b * a)) = () let lemma_div_nat (a: nat) (b: pos) : Lemma (a / b >= 0) [SMTPat (a / b)] = () let lemma_mult_reg_l (k: int) (x1 x2: int) : Lemma (requires ( k * x1 == k * x2 /\ k <> 0 )) (ensures ( x1 == x2 )) = () let lemma_bezout_one_zero (x1: int) (x2: nat) (y1 y2: int) : Lemma (requires ( x1 * x2 + y1 * y2 == 1 /\ y1 == 0 )) (ensures ( x1 == 1 /\ x2 == 1 )) = () #set-options "--z3cliopt smt.arith.nl=false" let int_semiring () = FStar.Tactics.CanonCommSemiring.int_semiring (); FStar.Tactics.trefl (); FStar.Tactics.qed () [@@erasable] noeq type bezout_t = { d: pos; q_n: nat; q_l: nat; u_n: int; u_l: int; } let bezout_prop' (n: nat) (l: nat) (d: pos) (q_n: nat) (q_l: nat) (u_n: int) (u_l: int) : Tot prop = n == d * q_n /\ l == d * q_l /\ d == n * u_n + l * u_l let bezout_prop (n: nat) (l: nat) (b: bezout_t) : Tot prop = bezout_prop' n l b.d b.q_n b.q_l b.u_n b.u_l let bezout (n: nat) (l: nat) : Tot Type = (b: bezout_t { bezout_prop n l b }) #restart-solver let rec mk_bezout (n: pos) (l: nat) : Pure (bezout n l) (requires (l < n)) (ensures (fun _ -> True)) (decreases l) = if l = 0 then begin let d : pos = n in let q_n : nat = 1 in let q_l : nat = 0 in let u_n : int = 1 in let u_l : int = 0 in let res = { d = d; q_n = q_n; q_l = q_l; u_n = u_n; u_l = u_l; } in assert (eq2 #int n (d * q_n)) by (int_semiring ()); assert (eq2 #int 0 (d * q_l)) by (int_semiring ()); assert (eq2 #int d (n * 1 + 0 * res.u_l)) by (int_semiring ()); res end else begin let lpre = n % l in let ql = n / l in euclidean_division_definition n l; let bpre = mk_bezout l lpre in let d = bpre.d in let q_l = bpre.q_n in let qpre_lpre = bpre.q_l in let upre_l = bpre.u_n in let upre_lpre = bpre.u_l in let n_alt0 = l * ql + lpre in assert (n == n_alt0); let l_alt = d * q_l in let lpre_alt1 = d * qpre_lpre in let n_alt1 = l_alt * ql + lpre_alt1 in assert (n_alt1 == n); let q_n = q_l * ql + qpre_lpre in assert (eq2 #int n_alt1 (d * q_n)) by (int_semiring ()); let lpre_alt2 = n + - l * ql in assert (lpre_alt2 == lpre); let d_alt = l * upre_l + lpre_alt2 * upre_lpre in assert (d_alt == d); let u_l = upre_l + - ql * upre_lpre in assert (eq2 #int (n * upre_lpre + l * u_l) d_alt) by (int_semiring ()); let res = { d = d; q_n = q_n; q_l = q_l; u_n = upre_lpre; u_l = u_l; } in res end let bezout_q_eq (n: nat) (l: nat) (bz: bezout n l) : Lemma (bz.q_n == n / bz.d) [SMTPat (bezout_prop n l bz); SMTPat bz.q_n] = cancel_mul_div bz.q_n bz.d let rec iter_fun (#t: Type) (f: (t -> GTot t)) (n: nat) (x: t) : GTot t (decreases n) = if n = 0 then x else iter_fun f (n - 1) (f x) let nat_up_to (n: nat) : Tot Type = (i: nat { i < n }) let jump (n: pos) (l: nat) (x: nat_up_to n) : GTot (nat_up_to n) = (x + l) % n #restart-solver let jump_mod_d (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Lemma (jump n l x % b.d == x % b.d) = let x' = jump n l x in let x'q = (x + l) / n in euclidean_division_definition (x + l) n; let l_alt = b.d * b.q_l in assert (l_alt == l); let n_alt = b.d * b.q_n in assert (n_alt == n); let x'_alt = x + l_alt + - x'q * n_alt in assert (x'_alt == x'); let qx = b.q_l + - x'q * b.q_n in assert (eq2 #int x'_alt (x + qx * b.d)) by (int_semiring ()); lemma_mod_plus x qx b.d let rec jump_iter_mod_d (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) (k: nat) : Lemma (ensures (iter_fun #(nat_up_to n) (jump n l) k x % b.d == x % b.d)) (decreases k) = if k = 0 then () else begin jump_mod_d n l b x; jump_iter_mod_d n l b (jump n l x) (k - 1) end (* Coverage *) let rec jump_iter (n: pos) (l: nat) (x: nat_up_to n) (k: nat) : Lemma (ensures (iter_fun #(nat_up_to n) (jump n l) k x == (x + k * l) % n)) (decreases k) = if k = 0 then begin assert (eq2 #int (x + 0 * l) x) by (int_semiring ()); small_mod x n end else begin let k' = k - 1 in assert (eq2 #int (x + (k' + 1) * l) ((x + l) + k' * l)) by (int_semiring ()); jump_iter n l ((x + l) % n) k'; lemma_mod_add_distr (k' * l) (x + l) n end let bezout_pos_le (n: pos) (l: nat) (b: bezout n l) : Lemma (b.d <= n /\ b.q_n > 0) [SMTPat (bezout_prop n l b)] = lemma_pos_mul_pos_args b.q_n b.d #restart-solver [@@"opaque_to_smt"] irreducible let jump_coverage (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Ghost nat (requires True) (ensures (fun k -> x == iter_fun (jump n l) k (x % b.d) )) = let i = x % b.d in let qx = x / b.d in euclidean_division_definition x b.d; let k1 = qx * b.u_l in let m = qx * b.u_n in assert (eq2 #int (qx * (n * b.u_n + l * b.u_l) + i) (i + k1 * l + m * n)) by (int_semiring ()); assert (x == i + k1 * l + m * n); small_mod x n; lemma_mod_plus (i + k1 * l) m n; assert (x == (i + k1 * l) % n); let k = k1 % n in let qk = k1 / n in euclidean_division_definition k1 n; assert (i + (qk * n + k) * l == i + k * l + (qk * l) * n) by (int_semiring ()); lemma_mod_plus (i + k * l) (qk * l) n; assert (eq2 #int x ((i + k * l) % n)); jump_iter n l i k; k [@@"opaque_to_smt"] irreducible let rec minimal_exists' (p: (nat -> GTot bool)) (n: nat) (i: nat) : Ghost nat (requires ( p n == true /\ i <= n /\ (forall (j: nat) . j < i ==> p j == false) )) (ensures (fun k -> p k == true /\ (forall (j: nat) . j < k ==> p j == false) )) (decreases (n - i)) = if p i then i else minimal_exists' p n (i + 1) [@@"opaque_to_smt"] irreducible let minimal_exists (p: (nat -> GTot bool)) (n: nat) : Ghost nat (requires ( p n == true )) (ensures (fun k -> p k == true /\ (forall (j: nat) . j < k ==> p j == false) )) = minimal_exists' p n 0 [@@"opaque_to_smt"] irreducible let jump_coverage_strong (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Ghost nat (requires True) (ensures (fun k -> x == iter_fun (jump n l) k (x % b.d) /\ (forall (k': nat) . k' < k ==> (~ (x == iter_fun (jump n l) k' (x % b.d)))) )) = let k' = jump_coverage n l b x in minimal_exists (fun k -> x = iter_fun (jump n l) k (x % b.d)) k'
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.CanonCommSemiring.fst.checked", "FStar.Tactics.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Steel.ST.GenArraySwap.Proof.fst" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.GenArraySwap", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.GenArraySwap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
n: Prims.pos -> l: Prims.nat -> b: Steel.ST.GenArraySwap.Proof.bezout n l -> x: Steel.ST.GenArraySwap.Proof.nat_up_to n -> k: Prims.nat -> FStar.Pervasives.Lemma (ensures Mkbezout_t?.q_n b > 0 /\ Steel.ST.GenArraySwap.Proof.iter_fun (Steel.ST.GenArraySwap.Proof.jump n l) (k % Mkbezout_t?.q_n b) x == Steel.ST.GenArraySwap.Proof.iter_fun (Steel.ST.GenArraySwap.Proof.jump n l) k x)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.pos", "Prims.nat", "Steel.ST.GenArraySwap.Proof.bezout", "Steel.ST.GenArraySwap.Proof.nat_up_to", "FStar.Math.Lemmas.lemma_mod_plus", "Prims.op_Addition", "FStar.Mul.op_Star", "Steel.ST.GenArraySwap.Proof.__proj__Mkbezout_t__item__q_l", "Prims.unit", "Prims._assert", "Prims.eq2", "Prims.int", "FStar.Tactics.Effect.assert_by_tactic", "Steel.ST.GenArraySwap.Proof.__proj__Mkbezout_t__item__q_n", "Steel.ST.GenArraySwap.Proof.__proj__Mkbezout_t__item__d", "Steel.ST.GenArraySwap.Proof.int_semiring", "Steel.ST.GenArraySwap.Proof.jump_iter", "FStar.Math.Lemmas.euclidean_division_definition", "Prims.op_Division", "Prims.op_Modulus", "Prims.b2t", "Prims.op_GreaterThan", "Prims.l_True", "Prims.squash", "Prims.l_and", "Steel.ST.GenArraySwap.Proof.iter_fun", "Steel.ST.GenArraySwap.Proof.jump", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let jump_iter_mod_q (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) (k: nat) : Lemma (ensures (b.q_n > 0 /\ iter_fun (jump n l) (k % b.q_n) x == iter_fun (jump n l) k x)) =
assert (b.q_n > 0); let k' = k % b.q_n in let qk = k / b.q_n in euclidean_division_definition k b.q_n; jump_iter n l x k'; jump_iter n l x k; FStar.Tactics.Effect.assert_by_tactic (eq2 #int (x + (qk * b.q_n + k') * (b.d * b.q_l)) (x + k' * (b.d * b.q_l) + (qk * b.q_l) * (b.d * b.q_n))) (fun _ -> (); (int_semiring ())); assert (x + k * l == x + k' * l + (qk * b.q_l) * n); lemma_mod_plus (x + k' * l) (qk * b.q_l) n
false
LatticeSpec.fst
LatticeSpec.abides
val abides (#a #pre #post: _) (f: repr0 a pre post) (ann: annot) : Type0
val abides (#a #pre #post: _) (f: repr0 a pre post) (ann: annot) : Type0
let abides #a #pre #post (f : repr0 a pre post) (ann:annot) : Type0 = (ann RD = false ==> (forall s0 s1. fst (f s0) == fst (f s1))) /\ (ann WR = false ==> (forall s0. snd (f s0) == s0)) /\ (ann EXN = false ==> (forall s0. Some? (fst (f s0))))
{ "file_name": "examples/layeredeffects/LatticeSpec.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 58, "end_line": 35, "start_col": 0, "start_line": 32 }
module LatticeSpec open FStar.Tactics.V2 open FStar.List.Tot // 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 = | RD | WR | EXN type annot = eff_label -> bool // warning: if this is not annotated, `eqtype` is inferred // as its type and the effect definition fails for some reason. type state : Type = int type pre_t = state -> Type0 type post_t a = state -> option a -> state -> Type0 // this repr doesn't seem to work too well type repr0 (a:Type u#aa) (pre : pre_t) (post : post_t u#aa a) // #2074 : Type u#aa = s0:state{pre s0} -> Tot (r:(option a & state){post s0 (fst r) (snd r)})
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LatticeSpec.fst" }
[ { "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: LatticeSpec.repr0 a pre post -> ann: LatticeSpec.annot -> Type0
Prims.Tot
[ "total" ]
[]
[ "LatticeSpec.pre_t", "LatticeSpec.post_t", "LatticeSpec.repr0", "LatticeSpec.annot", "Prims.l_and", "Prims.l_imp", "Prims.b2t", "Prims.op_Equality", "Prims.bool", "LatticeSpec.RD", "Prims.l_Forall", "LatticeSpec.state", "Prims.eq2", "FStar.Pervasives.Native.option", "FStar.Pervasives.Native.fst", "LatticeSpec.WR", "FStar.Pervasives.Native.snd", "LatticeSpec.EXN", "FStar.Pervasives.Native.uu___is_Some" ]
[]
false
false
false
false
true
let abides #a #pre #post (f: repr0 a pre post) (ann: annot) : Type0 =
(ann RD = false ==> (forall s0 s1. fst (f s0) == fst (f s1))) /\ (ann WR = false ==> (forall s0. snd (f s0) == s0)) /\ (ann EXN = false ==> (forall s0. Some? (fst (f s0))))
false
LowParse.Low.Writers.Instances.fst
LowParse.Low.Writers.Instances.max
val max (x1 x2: nat) : Tot nat
val max (x1 x2: nat) : Tot nat
let max (x1 x2: nat) : Tot nat = if x1 > x2 then x1 else x2
{ "file_name": "src/lowparse/LowParse.Low.Writers.Instances.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 59, "end_line": 72, "start_col": 0, "start_line": 72 }
module LowParse.Low.Writers.Instances include LowParse.Low.Writers include LowParse.Low.Combinators include LowParse.Low.Bytes include LowParse.Low.BitSum module HS = FStar.HyperStack module B = LowStar.Buffer module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST inline_for_extraction noextract let swrite_weaken (#h0: HS.mem) (#sout: slice (srel_of_buffer_srel (B.trivial_preorder _)) (srel_of_buffer_srel (B.trivial_preorder _))) (#pout_from0: U32.t) (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#s1: serializer p1 { k1.parser_kind_subkind == Some ParserStrong }) (#space_beyond: nat) (k2: parser_kind) (w1: swriter s1 h0 space_beyond sout pout_from0 { (k2 `is_weaker_than` k1) /\ k2.parser_kind_subkind == Some ParserStrong }) : Tot (w2: swriter (serialize_weaken k2 s1) h0 space_beyond sout pout_from0 { swvalue w2 == swvalue w1 }) = SWriter (Ghost.hide (swvalue w1)) (fun pout_from -> serialized_length_eq s1 (swvalue w1); serialized_length_eq (serialize_weaken k2 s1) (swvalue w1); let res = swrite w1 pout_from in let h = HST.get () in valid_weaken k2 p1 h sout pout_from; res ) inline_for_extraction noextract let swrite_nondep_then' (#h0: HS.mem) (#sout: slice (srel_of_buffer_srel (B.trivial_preorder _)) (srel_of_buffer_srel (B.trivial_preorder _))) (#pout_from0: U32.t) (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#s1: serializer p1 { k1.parser_kind_subkind == Some ParserStrong }) (#space_beyond: nat) (w1: swriter s1 h0 space_beyond sout pout_from0) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (#s2: serializer p2 { k2.parser_kind_subkind == Some ParserStrong }) (w2: swriter s2 h0 space_beyond sout pout_from0) : Tot (w: swriter (s1 `serialize_nondep_then` s2) h0 space_beyond sout pout_from0 { swvalue w == (swvalue w1, swvalue w2) }) = SWriter (Ghost.hide (swvalue w1, swvalue w2)) (fun pout_from -> serialized_length_eq (s1 `serialize_nondep_then` s2) (swvalue w1, swvalue w2); serialize_nondep_then_eq s1 s2 (swvalue w1, swvalue w2); serialized_length_eq s1 (swvalue w1); serialized_length_eq s2 (swvalue w2); let pos1 = swrite w1 pout_from in let pos2 = swrite w2 pos1 in let h' = HST.get () in valid_nondep_then h' p1 p2 sout pout_from; pos2 )
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Endianness.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Low.Writers.fst.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Low.Bytes.fst.checked", "LowParse.Low.BitSum.fst.checked", "LowParse.Endianness.BitFields.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Bytes.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Low.Writers.Instances.fst" }
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "LowParse.Low.BitSum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Bytes", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Writers", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Writers", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Writers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
x1: Prims.nat -> x2: Prims.nat -> Prims.nat
Prims.Tot
[ "total" ]
[]
[ "Prims.nat", "Prims.op_GreaterThan", "Prims.bool" ]
[]
false
false
false
true
false
let max (x1 x2: nat) : Tot nat =
if x1 > x2 then x1 else x2
false
Hacl.Spec.P256.Qinv.fst
Hacl.Spec.P256.Qinv.mul_mod
val mul_mod : SE.mul_st S.qelem mk_to_nat_mod_comm_monoid
val mul_mod : SE.mul_st S.qelem mk_to_nat_mod_comm_monoid
let mul_mod x y = S.qmul x y
{ "file_name": "code/ecdsap256/Hacl.Spec.P256.Qinv.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 28, "end_line": 24, "start_col": 0, "start_line": 24 }
module Hacl.Spec.P256.Qinv open FStar.Mul module SE = Spec.Exponentiation module LE = Lib.Exponentiation module M = Lib.NatMod module S = Spec.P256 #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" let nat_mod_comm_monoid = M.mk_nat_mod_comm_monoid S.order let mk_to_nat_mod_comm_monoid : SE.to_comm_monoid S.qelem = { SE.a_spec = S.qelem; SE.comm_monoid = nat_mod_comm_monoid; SE.refl = (fun (x:S.qelem) -> x); } val one_mod : SE.one_st S.qelem mk_to_nat_mod_comm_monoid let one_mod _ = 1
{ "checked_file": "/", "dependencies": [ "Spec.P256.fst.checked", "Spec.Exponentiation.fsti.checked", "prims.fst.checked", "Lib.NatMod.fsti.checked", "Lib.Exponentiation.fsti.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.P256.Qinv.fst" }
[ { "abbrev": true, "full_module": "Spec.P256", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.NatMod", "short_module": "M" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "LE" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.P256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.P256", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
Spec.Exponentiation.mul_st Spec.P256.PointOps.qelem Hacl.Spec.P256.Qinv.mk_to_nat_mod_comm_monoid
Prims.Tot
[ "total" ]
[]
[ "Spec.P256.PointOps.qelem", "Spec.P256.PointOps.qmul" ]
[]
false
false
false
true
false
let mul_mod x y =
S.qmul x y
false
Hacl.Spec.P256.Qinv.fst
Hacl.Spec.P256.Qinv.sqr_mod
val sqr_mod : SE.sqr_st S.qelem mk_to_nat_mod_comm_monoid
val sqr_mod : SE.sqr_st S.qelem mk_to_nat_mod_comm_monoid
let sqr_mod x = S.qmul x x
{ "file_name": "code/ecdsap256/Hacl.Spec.P256.Qinv.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 26, "end_line": 27, "start_col": 0, "start_line": 27 }
module Hacl.Spec.P256.Qinv open FStar.Mul module SE = Spec.Exponentiation module LE = Lib.Exponentiation module M = Lib.NatMod module S = Spec.P256 #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" let nat_mod_comm_monoid = M.mk_nat_mod_comm_monoid S.order let mk_to_nat_mod_comm_monoid : SE.to_comm_monoid S.qelem = { SE.a_spec = S.qelem; SE.comm_monoid = nat_mod_comm_monoid; SE.refl = (fun (x:S.qelem) -> x); } val one_mod : SE.one_st S.qelem mk_to_nat_mod_comm_monoid let one_mod _ = 1 val mul_mod : SE.mul_st S.qelem mk_to_nat_mod_comm_monoid let mul_mod x y = S.qmul x y
{ "checked_file": "/", "dependencies": [ "Spec.P256.fst.checked", "Spec.Exponentiation.fsti.checked", "prims.fst.checked", "Lib.NatMod.fsti.checked", "Lib.Exponentiation.fsti.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.P256.Qinv.fst" }
[ { "abbrev": true, "full_module": "Spec.P256", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.NatMod", "short_module": "M" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "LE" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.P256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.P256", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
Spec.Exponentiation.sqr_st Spec.P256.PointOps.qelem Hacl.Spec.P256.Qinv.mk_to_nat_mod_comm_monoid
Prims.Tot
[ "total" ]
[]
[ "Spec.P256.PointOps.qelem", "Spec.P256.PointOps.qmul" ]
[]
false
false
false
true
false
let sqr_mod x =
S.qmul x x
false
Hacl.Spec.P256.Qinv.fst
Hacl.Spec.P256.Qinv.lemma_pow_mod_1
val lemma_pow_mod_1: f:S.qelem -> Lemma (f == M.pow f 1 % S.order)
val lemma_pow_mod_1: f:S.qelem -> Lemma (f == M.pow f 1 % S.order)
let lemma_pow_mod_1 f = M.lemma_pow1 f; Math.Lemmas.small_mod f S.order; assert_norm (pow2 0 = 1); assert (f == M.pow f 1 % S.order)
{ "file_name": "code/ecdsap256/Hacl.Spec.P256.Qinv.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 35, "end_line": 140, "start_col": 0, "start_line": 136 }
module Hacl.Spec.P256.Qinv open FStar.Mul module SE = Spec.Exponentiation module LE = Lib.Exponentiation module M = Lib.NatMod module S = Spec.P256 #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" let nat_mod_comm_monoid = M.mk_nat_mod_comm_monoid S.order let mk_to_nat_mod_comm_monoid : SE.to_comm_monoid S.qelem = { SE.a_spec = S.qelem; SE.comm_monoid = nat_mod_comm_monoid; SE.refl = (fun (x:S.qelem) -> x); } val one_mod : SE.one_st S.qelem mk_to_nat_mod_comm_monoid let one_mod _ = 1 val mul_mod : SE.mul_st S.qelem mk_to_nat_mod_comm_monoid let mul_mod x y = S.qmul x y val sqr_mod : SE.sqr_st S.qelem mk_to_nat_mod_comm_monoid let sqr_mod x = S.qmul x x let mk_nat_mod_concrete_ops : SE.concrete_ops S.qelem = { SE.to = mk_to_nat_mod_comm_monoid; SE.one = one_mod; SE.mul = mul_mod; SE.sqr = sqr_mod; } let qsquare_times (a:S.qelem) (b:nat) : S.qelem = SE.exp_pow2 mk_nat_mod_concrete_ops a b val qsquare_times_lemma: a:S.qelem -> b:nat -> Lemma (qsquare_times a b == M.pow a (pow2 b) % S.order) let qsquare_times_lemma a b = SE.exp_pow2_lemma mk_nat_mod_concrete_ops a b; LE.exp_pow2_lemma nat_mod_comm_monoid a b; assert (qsquare_times a b == LE.pow nat_mod_comm_monoid a (pow2 b)); M.lemma_pow_nat_mod_is_pow #S.order a (pow2 b) let qinv_x8_x128 (x6 x_11: S.qelem) : S.qelem = let x8 = S.qmul (qsquare_times x6 2) x_11 in let x16 = S.qmul (qsquare_times x8 8) x8 in let x32 = S.qmul (qsquare_times x16 16) x16 in let x96 = S.qmul (qsquare_times x32 64) x32 in let x128 = S.qmul (qsquare_times x96 32) x32 in x128 let qinv_x134_x153 (x128 x_11 x_111 x_1111 x_10101 x_101111: S.qelem) : S.qelem = let x134 = S.qmul (qsquare_times x128 6) x_101111 in let x139 = S.qmul (qsquare_times x134 5) x_111 in let x143 = S.qmul (qsquare_times x139 4) x_11 in let x148 = S.qmul (qsquare_times x143 5) x_1111 in let x153 = S.qmul (qsquare_times x148 5) x_10101 in x153 let qinv_x153_x177 (x153 x_101 x_111 x_101111: S.qelem) : S.qelem = let x157 = S.qmul (qsquare_times x153 4) x_101 in let x160 = S.qmul (qsquare_times x157 3) x_101 in let x163 = S.qmul (qsquare_times x160 3) x_101 in let x168 = S.qmul (qsquare_times x163 5) x_111 in let x177 = S.qmul (qsquare_times x168 9) x_101111 in x177 let qinv_x177_x210 (f x177 x_111 x_1111: S.qelem) : S.qelem = let x183 = S.qmul (qsquare_times x177 6) x_1111 in let x185 = S.qmul (qsquare_times x183 2) f in let x190 = S.qmul (qsquare_times x185 5) f in let x196 = S.qmul (qsquare_times x190 6) x_1111 in let x201 = S.qmul (qsquare_times x196 5) x_111 in let x205 = S.qmul (qsquare_times x201 4) x_111 in let x210 = S.qmul (qsquare_times x205 5) x_111 in x210 let qinv_x210_x240 (x210 x_11 x_101 x_101111: S.qelem) : S.qelem = let x215 = S.qmul (qsquare_times x210 5) x_101 in let x218 = S.qmul (qsquare_times x215 3) x_11 in let x228 = S.qmul (qsquare_times x218 10) x_101111 in let x230 = S.qmul (qsquare_times x228 2) x_11 in let x235 = S.qmul (qsquare_times x230 5) x_11 in let x240 = S.qmul (qsquare_times x235 5) x_11 in x240 let qinv_x240_x256 (f x240 x_1111 x_10101: S.qelem) : S.qelem = let x243 = S.qmul (qsquare_times x240 3) f in let x250 = S.qmul (qsquare_times x243 7) x_10101 in let x256 = S.qmul (qsquare_times x250 6) x_1111 in x256 let qinv_x8_x256 (f x6 x_11 x_101 x_111 x_1111 x_10101 x_101111 : S.qelem) : S.qelem = let x128 = qinv_x8_x128 x6 x_11 in let x153 = qinv_x134_x153 x128 x_11 x_111 x_1111 x_10101 x_101111 in let x177 = qinv_x153_x177 x153 x_101 x_111 x_101111 in let x210 = qinv_x177_x210 f x177 x_111 x_1111 in let x240 = qinv_x210_x240 x210 x_11 x_101 x_101111 in let x256 = qinv_x240_x256 f x240 x_1111 x_10101 in x256 (** The algorithm is taken from https://briansmith.org/ecc-inversion-addition-chains-01 *) val qinv: f:S.qelem -> S.qelem let qinv f = let x_10 = qsquare_times f 1 in // x_10 is used 3x let x_11 = S.qmul x_10 f in let x_101 = S.qmul x_10 x_11 in let x_111 = S.qmul x_10 x_101 in let x_1010 = qsquare_times x_101 1 in // x_1010 is used 2x let x_1111 = S.qmul x_101 x_1010 in let x_10101 = S.qmul (qsquare_times x_1010 1) f in let x_101010 = qsquare_times x_10101 1 in // x_101010 is used 2x let x_101111 = S.qmul x_101 x_101010 in let x6 = S.qmul x_10101 x_101010 in qinv_x8_x256 f x6 x_11 x_101 x_111 x_1111 x_10101 x_101111 // TODO: mv to lib/
{ "checked_file": "/", "dependencies": [ "Spec.P256.fst.checked", "Spec.Exponentiation.fsti.checked", "prims.fst.checked", "Lib.NatMod.fsti.checked", "Lib.Exponentiation.fsti.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.P256.Qinv.fst" }
[ { "abbrev": true, "full_module": "Spec.P256", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.NatMod", "short_module": "M" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "LE" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.P256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.P256", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
f: Spec.P256.PointOps.qelem -> FStar.Pervasives.Lemma (ensures f == Lib.NatMod.pow f 1 % Spec.P256.PointOps.order)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Spec.P256.PointOps.qelem", "Prims._assert", "Prims.eq2", "Prims.int", "Prims.op_Modulus", "Lib.NatMod.pow", "Spec.P256.PointOps.order", "Prims.unit", "FStar.Pervasives.assert_norm", "Prims.b2t", "Prims.op_Equality", "Prims.pow2", "FStar.Math.Lemmas.small_mod", "Lib.NatMod.lemma_pow1" ]
[]
true
false
true
false
false
let lemma_pow_mod_1 f =
M.lemma_pow1 f; Math.Lemmas.small_mod f S.order; assert_norm (pow2 0 = 1); assert (f == M.pow f 1 % S.order)
false
Hacl.Spec.P256.Qinv.fst
Hacl.Spec.P256.Qinv.one_mod
val one_mod : SE.one_st S.qelem mk_to_nat_mod_comm_monoid
val one_mod : SE.one_st S.qelem mk_to_nat_mod_comm_monoid
let one_mod _ = 1
{ "file_name": "code/ecdsap256/Hacl.Spec.P256.Qinv.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 17, "end_line": 21, "start_col": 0, "start_line": 21 }
module Hacl.Spec.P256.Qinv open FStar.Mul module SE = Spec.Exponentiation module LE = Lib.Exponentiation module M = Lib.NatMod module S = Spec.P256 #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" let nat_mod_comm_monoid = M.mk_nat_mod_comm_monoid S.order let mk_to_nat_mod_comm_monoid : SE.to_comm_monoid S.qelem = { SE.a_spec = S.qelem; SE.comm_monoid = nat_mod_comm_monoid; SE.refl = (fun (x:S.qelem) -> x); }
{ "checked_file": "/", "dependencies": [ "Spec.P256.fst.checked", "Spec.Exponentiation.fsti.checked", "prims.fst.checked", "Lib.NatMod.fsti.checked", "Lib.Exponentiation.fsti.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.P256.Qinv.fst" }
[ { "abbrev": true, "full_module": "Spec.P256", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.NatMod", "short_module": "M" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "LE" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.P256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.P256", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
Spec.Exponentiation.one_st Spec.P256.PointOps.qelem Hacl.Spec.P256.Qinv.mk_to_nat_mod_comm_monoid
Prims.Tot
[ "total" ]
[]
[ "Prims.unit", "Spec.P256.PointOps.qelem" ]
[]
false
false
false
true
false
let one_mod _ =
1
false
Hacl.Spec.P256.Qinv.fst
Hacl.Spec.P256.Qinv.qinv_is_qinv_lemma
val qinv_is_qinv_lemma: f:S.qelem -> Lemma (qinv f == S.qinv f)
val qinv_is_qinv_lemma: f:S.qelem -> Lemma (qinv f == S.qinv f)
let qinv_is_qinv_lemma f = qinv_lemma f; assert (qinv f == M.pow f (S.order - 2) % S.order); M.lemma_pow_mod #S.order f (S.order - 2)
{ "file_name": "code/ecdsap256/Hacl.Spec.P256.Qinv.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 42, "end_line": 405, "start_col": 0, "start_line": 402 }
module Hacl.Spec.P256.Qinv open FStar.Mul module SE = Spec.Exponentiation module LE = Lib.Exponentiation module M = Lib.NatMod module S = Spec.P256 #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" let nat_mod_comm_monoid = M.mk_nat_mod_comm_monoid S.order let mk_to_nat_mod_comm_monoid : SE.to_comm_monoid S.qelem = { SE.a_spec = S.qelem; SE.comm_monoid = nat_mod_comm_monoid; SE.refl = (fun (x:S.qelem) -> x); } val one_mod : SE.one_st S.qelem mk_to_nat_mod_comm_monoid let one_mod _ = 1 val mul_mod : SE.mul_st S.qelem mk_to_nat_mod_comm_monoid let mul_mod x y = S.qmul x y val sqr_mod : SE.sqr_st S.qelem mk_to_nat_mod_comm_monoid let sqr_mod x = S.qmul x x let mk_nat_mod_concrete_ops : SE.concrete_ops S.qelem = { SE.to = mk_to_nat_mod_comm_monoid; SE.one = one_mod; SE.mul = mul_mod; SE.sqr = sqr_mod; } let qsquare_times (a:S.qelem) (b:nat) : S.qelem = SE.exp_pow2 mk_nat_mod_concrete_ops a b val qsquare_times_lemma: a:S.qelem -> b:nat -> Lemma (qsquare_times a b == M.pow a (pow2 b) % S.order) let qsquare_times_lemma a b = SE.exp_pow2_lemma mk_nat_mod_concrete_ops a b; LE.exp_pow2_lemma nat_mod_comm_monoid a b; assert (qsquare_times a b == LE.pow nat_mod_comm_monoid a (pow2 b)); M.lemma_pow_nat_mod_is_pow #S.order a (pow2 b) let qinv_x8_x128 (x6 x_11: S.qelem) : S.qelem = let x8 = S.qmul (qsquare_times x6 2) x_11 in let x16 = S.qmul (qsquare_times x8 8) x8 in let x32 = S.qmul (qsquare_times x16 16) x16 in let x96 = S.qmul (qsquare_times x32 64) x32 in let x128 = S.qmul (qsquare_times x96 32) x32 in x128 let qinv_x134_x153 (x128 x_11 x_111 x_1111 x_10101 x_101111: S.qelem) : S.qelem = let x134 = S.qmul (qsquare_times x128 6) x_101111 in let x139 = S.qmul (qsquare_times x134 5) x_111 in let x143 = S.qmul (qsquare_times x139 4) x_11 in let x148 = S.qmul (qsquare_times x143 5) x_1111 in let x153 = S.qmul (qsquare_times x148 5) x_10101 in x153 let qinv_x153_x177 (x153 x_101 x_111 x_101111: S.qelem) : S.qelem = let x157 = S.qmul (qsquare_times x153 4) x_101 in let x160 = S.qmul (qsquare_times x157 3) x_101 in let x163 = S.qmul (qsquare_times x160 3) x_101 in let x168 = S.qmul (qsquare_times x163 5) x_111 in let x177 = S.qmul (qsquare_times x168 9) x_101111 in x177 let qinv_x177_x210 (f x177 x_111 x_1111: S.qelem) : S.qelem = let x183 = S.qmul (qsquare_times x177 6) x_1111 in let x185 = S.qmul (qsquare_times x183 2) f in let x190 = S.qmul (qsquare_times x185 5) f in let x196 = S.qmul (qsquare_times x190 6) x_1111 in let x201 = S.qmul (qsquare_times x196 5) x_111 in let x205 = S.qmul (qsquare_times x201 4) x_111 in let x210 = S.qmul (qsquare_times x205 5) x_111 in x210 let qinv_x210_x240 (x210 x_11 x_101 x_101111: S.qelem) : S.qelem = let x215 = S.qmul (qsquare_times x210 5) x_101 in let x218 = S.qmul (qsquare_times x215 3) x_11 in let x228 = S.qmul (qsquare_times x218 10) x_101111 in let x230 = S.qmul (qsquare_times x228 2) x_11 in let x235 = S.qmul (qsquare_times x230 5) x_11 in let x240 = S.qmul (qsquare_times x235 5) x_11 in x240 let qinv_x240_x256 (f x240 x_1111 x_10101: S.qelem) : S.qelem = let x243 = S.qmul (qsquare_times x240 3) f in let x250 = S.qmul (qsquare_times x243 7) x_10101 in let x256 = S.qmul (qsquare_times x250 6) x_1111 in x256 let qinv_x8_x256 (f x6 x_11 x_101 x_111 x_1111 x_10101 x_101111 : S.qelem) : S.qelem = let x128 = qinv_x8_x128 x6 x_11 in let x153 = qinv_x134_x153 x128 x_11 x_111 x_1111 x_10101 x_101111 in let x177 = qinv_x153_x177 x153 x_101 x_111 x_101111 in let x210 = qinv_x177_x210 f x177 x_111 x_1111 in let x240 = qinv_x210_x240 x210 x_11 x_101 x_101111 in let x256 = qinv_x240_x256 f x240 x_1111 x_10101 in x256 (** The algorithm is taken from https://briansmith.org/ecc-inversion-addition-chains-01 *) val qinv: f:S.qelem -> S.qelem let qinv f = let x_10 = qsquare_times f 1 in // x_10 is used 3x let x_11 = S.qmul x_10 f in let x_101 = S.qmul x_10 x_11 in let x_111 = S.qmul x_10 x_101 in let x_1010 = qsquare_times x_101 1 in // x_1010 is used 2x let x_1111 = S.qmul x_101 x_1010 in let x_10101 = S.qmul (qsquare_times x_1010 1) f in let x_101010 = qsquare_times x_10101 1 in // x_101010 is used 2x let x_101111 = S.qmul x_101 x_101010 in let x6 = S.qmul x_10101 x_101010 in qinv_x8_x256 f x6 x_11 x_101 x_111 x_1111 x_10101 x_101111 // TODO: mv to lib/ val lemma_pow_mod_1: f:S.qelem -> Lemma (f == M.pow f 1 % S.order) let lemma_pow_mod_1 f = M.lemma_pow1 f; Math.Lemmas.small_mod f S.order; assert_norm (pow2 0 = 1); assert (f == M.pow f 1 % S.order) val lemma_pow_mod_mul: f:S.qelem -> a:nat -> b:nat -> Lemma (S.qmul (M.pow f a % S.order) (M.pow f b % S.order) == M.pow f (a + b) % S.order) let lemma_pow_mod_mul f a b = calc (==) { S.qmul (M.pow f a % S.order) (M.pow f b % S.order); (==) { Math.Lemmas.lemma_mod_mul_distr_l (M.pow f a) (M.pow f b % S.order) S.order; Math.Lemmas.lemma_mod_mul_distr_r (M.pow f a) (M.pow f b) S.order } M.pow f a * M.pow f b % S.order; (==) { M.lemma_pow_add f a b } M.pow f (a + b) % S.order; } val lemma_pow_pow_mod: f:S.qelem -> a:nat -> b:nat -> Lemma (M.pow (M.pow f a % S.order) b % S.order == M.pow f (a * b) % S.order) let lemma_pow_pow_mod f a b = calc (==) { M.pow (M.pow f a % S.order) b % S.order; (==) { M.lemma_pow_mod_base (M.pow f a) b S.order } M.pow (M.pow f a) b % S.order; (==) { M.lemma_pow_mul f a b } M.pow f (a * b) % S.order; } val lemma_pow_pow_mod_mul: f:S.qelem -> a:nat -> b:nat -> c:nat -> Lemma (S.qmul (M.pow (M.pow f a % S.order) b % S.order) (M.pow f c % S.order) == M.pow f (a * b + c) % S.order) let lemma_pow_pow_mod_mul f a b c = calc (==) { S.qmul (M.pow (M.pow f a % S.order) b % S.order) (M.pow f c % S.order); (==) { lemma_pow_pow_mod f a b } S.qmul (M.pow f (a * b) % S.order) (M.pow f c % S.order); (==) { lemma_pow_mod_mul f (a * b) c } M.pow f (a * b + c) % S.order; } ////////////////////////////// // S.order - 2 = 0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc63254f val qinv_lemma: f:S.qelem -> Lemma (qinv f == M.pow f (S.order - 2) % S.order) let qinv_lemma f = let x_10 = qsquare_times f 1 in qsquare_times_lemma f 1; assert_norm (pow2 1 = 0x2); assert (x_10 == M.pow f 0x2 % S.order); let x_11 = S.qmul x_10 f in lemma_pow_mod_1 f; lemma_pow_mod_mul f 0x2 0x1; assert (x_11 == M.pow f 0x3 % S.order); let x_101 = S.qmul x_10 x_11 in lemma_pow_mod_mul f 0x2 0x3; assert (x_101 == M.pow f 0x5 % S.order); let x_111 = S.qmul x_10 x_101 in lemma_pow_mod_mul f 0x2 0x5; assert (x_111 == M.pow f 0x7 % S.order); let x_1010 = qsquare_times x_101 1 in qsquare_times_lemma x_101 1; assert_norm (pow2 1 = 2); lemma_pow_pow_mod f 0x5 0x2; assert (x_1010 == M.pow f 0xa % S.order); let x_1111 = S.qmul x_101 x_1010 in lemma_pow_mod_mul f 0x5 0xa; assert (x_1111 == M.pow f 0xf % S.order); let x_10101 = S.qmul (qsquare_times x_1010 1) f in qsquare_times_lemma x_1010 1; lemma_pow_pow_mod_mul f 0xa 0x2 0x1; assert (x_10101 == M.pow f 0x15 % S.order); let x_101010 = qsquare_times x_10101 1 in qsquare_times_lemma x_10101 1; lemma_pow_pow_mod f 0x15 0x2; assert (x_101010 == M.pow f 0x2a % S.order); let x_101111 = S.qmul x_101 x_101010 in lemma_pow_mod_mul f 0x5 0x2a; assert (x_101111 == M.pow f 0x2f % S.order); let x6 = S.qmul x_10101 x_101010 in lemma_pow_mod_mul f 0x15 0x2a; assert (x6 == M.pow f 0x3f % S.order); let x8 = S.qmul (qsquare_times x6 2) x_11 in qsquare_times_lemma x6 2; assert_norm (pow2 2 = 0x4); lemma_pow_pow_mod_mul f 0x3f 0x4 0x3; assert (x8 == M.pow f 0xff % S.order); let x16 = S.qmul (qsquare_times x8 8) x8 in qsquare_times_lemma x8 8; assert_norm (pow2 8 = 0x100); lemma_pow_pow_mod_mul f 0xff 0x100 0xff; assert (x16 == M.pow f 0xffff % S.order); let x32 = S.qmul (qsquare_times x16 16) x16 in qsquare_times_lemma x16 16; assert_norm (pow2 16 = 0x10000); lemma_pow_pow_mod_mul f 0xffff 0x10000 0xffff; assert (x32 == M.pow f 0xffffffff % S.order); let x96 = S.qmul (qsquare_times x32 64) x32 in qsquare_times_lemma x32 64; assert_norm (pow2 64 = 0x10000000000000000); lemma_pow_pow_mod_mul f 0xffffffff 0x10000000000000000 0xffffffff; assert (x96 == M.pow f 0xffffffff00000000ffffffff % S.order); let x128 = S.qmul (qsquare_times x96 32) x32 in qsquare_times_lemma x96 32; assert_norm (pow2 32 = 0x100000000); lemma_pow_pow_mod_mul f 0xffffffff00000000ffffffff 0x100000000 0xffffffff; assert (x128 == M.pow f 0xffffffff00000000ffffffffffffffff % S.order); let x134 = S.qmul (qsquare_times x128 6) x_101111 in qsquare_times_lemma x128 6; assert_norm (pow2 6 = 0x40); lemma_pow_pow_mod_mul f 0xffffffff00000000ffffffffffffffff 0x40 0x2f; assert (x134 == M.pow f 0x3fffffffc00000003fffffffffffffffef % S.order); let x139 = S.qmul (qsquare_times x134 5) x_111 in qsquare_times_lemma x134 5; assert_norm (pow2 5 = 0x20); lemma_pow_pow_mod_mul f 0x3fffffffc00000003fffffffffffffffef 0x20 0x7; assert (x139 == M.pow f 0x7fffffff800000007fffffffffffffffde7 % S.order); let x143 = S.qmul (qsquare_times x139 4) x_11 in qsquare_times_lemma x139 4; assert_norm (pow2 4 = 0x10); lemma_pow_pow_mod_mul f 0x7fffffff800000007fffffffffffffffde7 0x10 0x3; assert (x143 == M.pow f 0x7fffffff800000007fffffffffffffffde73 % S.order); let x148 = S.qmul (qsquare_times x143 5) x_1111 in qsquare_times_lemma x143 5; lemma_pow_pow_mod_mul f 0x7fffffff800000007fffffffffffffffde73 0x20 0xf; assert (x148 == M.pow f 0xffffffff00000000ffffffffffffffffbce6f % S.order); let x153 = S.qmul (qsquare_times x148 5) x_10101 in qsquare_times_lemma x148 5; lemma_pow_pow_mod_mul f 0xffffffff00000000ffffffffffffffffbce6f 0x20 0x15; assert (x153 == M.pow f 0x1fffffffe00000001ffffffffffffffff79cdf5 % S.order); let x157 = S.qmul (qsquare_times x153 4) x_101 in qsquare_times_lemma x153 4; lemma_pow_pow_mod_mul f 0x1fffffffe00000001ffffffffffffffff79cdf5 0x10 0x5; assert (x157 == M.pow f 0x1fffffffe00000001ffffffffffffffff79cdf55 % S.order); let x160 = S.qmul (qsquare_times x157 3) x_101 in qsquare_times_lemma x157 3; assert_norm (pow2 3 = 0x8); lemma_pow_pow_mod_mul f 0x1fffffffe00000001ffffffffffffffff79cdf55 0x8 0x5; assert (x160 == M.pow f 0xffffffff00000000ffffffffffffffffbce6faad % S.order); let x163 = S.qmul (qsquare_times x160 3) x_101 in qsquare_times_lemma x160 3; lemma_pow_pow_mod_mul f 0xffffffff00000000ffffffffffffffffbce6faad 0x8 0x5; assert (x163 == M.pow f 0x7fffffff800000007fffffffffffffffde737d56d % S.order); let x168 = S.qmul (qsquare_times x163 5) x_111 in qsquare_times_lemma x163 5; lemma_pow_pow_mod_mul f 0x7fffffff800000007fffffffffffffffde737d56d 0x20 0x7; assert (x168 == M.pow f 0xffffffff00000000ffffffffffffffffbce6faada7 % S.order); let x177 = S.qmul (qsquare_times x168 9) x_101111 in qsquare_times_lemma x168 9; assert_norm (pow2 9 = 0x200); lemma_pow_pow_mod_mul f 0xffffffff00000000ffffffffffffffffbce6faada7 0x200 0x2f; assert (x177 == M.pow f 0x1fffffffe00000001ffffffffffffffff79cdf55b4e2f % S.order); let x183 = S.qmul (qsquare_times x177 6) x_1111 in qsquare_times_lemma x177 6; lemma_pow_pow_mod_mul f 0x1fffffffe00000001ffffffffffffffff79cdf55b4e2f 0x40 0xf; assert (x183 == M.pow f 0x7fffffff800000007fffffffffffffffde737d56d38bcf % S.order); let x185 = S.qmul (qsquare_times x183 2) f in qsquare_times_lemma x183 2; lemma_pow_pow_mod_mul f 0x7fffffff800000007fffffffffffffffde737d56d38bcf 0x4 0x1; assert (x185 == M.pow f 0x1fffffffe00000001ffffffffffffffff79cdf55b4e2f3d % S.order); let x190 = S.qmul (qsquare_times x185 5) f in qsquare_times_lemma x185 5; lemma_pow_pow_mod_mul f 0x1fffffffe00000001ffffffffffffffff79cdf55b4e2f3d 0x20 0x1; assert (x190 == M.pow f 0x3fffffffc00000003fffffffffffffffef39beab69c5e7a1 % S.order); let x196 = S.qmul (qsquare_times x190 6) x_1111 in qsquare_times_lemma x190 6; lemma_pow_pow_mod_mul f 0x3fffffffc00000003fffffffffffffffef39beab69c5e7a1 0x40 0xf; assert (x196 == M.pow f 0xffffffff00000000ffffffffffffffffbce6faada7179e84f % S.order); let x201 = S.qmul (qsquare_times x196 5) x_111 in qsquare_times_lemma x196 5; lemma_pow_pow_mod_mul f 0xffffffff00000000ffffffffffffffffbce6faada7179e84f 0x20 0x7; assert (x201 == M.pow f 0x1fffffffe00000001ffffffffffffffff79cdf55b4e2f3d09e7 % S.order); let x205 = S.qmul (qsquare_times x201 4) x_111 in qsquare_times_lemma x201 4; lemma_pow_pow_mod_mul f 0x1fffffffe00000001ffffffffffffffff79cdf55b4e2f3d09e7 0x10 0x7; assert (x205 == M.pow f 0x1fffffffe00000001ffffffffffffffff79cdf55b4e2f3d09e77 % S.order); let x210 = S.qmul (qsquare_times x205 5) x_111 in qsquare_times_lemma x205 5; lemma_pow_pow_mod_mul f 0x1fffffffe00000001ffffffffffffffff79cdf55b4e2f3d09e77 0x20 0x7; assert (x210 == M.pow f 0x3fffffffc00000003fffffffffffffffef39beab69c5e7a13cee7 % S.order); let x215 = S.qmul (qsquare_times x210 5) x_101 in qsquare_times_lemma x210 5; lemma_pow_pow_mod_mul f 0x3fffffffc00000003fffffffffffffffef39beab69c5e7a13cee7 0x20 0x5; assert (x215 == M.pow f 0x7fffffff800000007fffffffffffffffde737d56d38bcf4279dce5 % S.order); let x218 = S.qmul (qsquare_times x215 3) x_11 in qsquare_times_lemma x215 3; lemma_pow_pow_mod_mul f 0x7fffffff800000007fffffffffffffffde737d56d38bcf4279dce5 0x8 0x3; assert (x218 == M.pow f 0x3fffffffc00000003fffffffffffffffef39beab69c5e7a13cee72b % S.order); let x228 = S.qmul (qsquare_times x218 10) x_101111 in qsquare_times_lemma x218 10; assert_norm (pow2 10 = 0x400); lemma_pow_pow_mod_mul f 0x3fffffffc00000003fffffffffffffffef39beab69c5e7a13cee72b 0x400 0x2f; assert (x228 == M.pow f 0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2f % S.order); let x230 = S.qmul (qsquare_times x228 2) x_11 in qsquare_times_lemma x228 2; lemma_pow_pow_mod_mul f 0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2f 0x4 0x3; assert (x230 == M.pow f 0x3fffffffc00000003fffffffffffffffef39beab69c5e7a13cee72b0bf % S.order); let x235 = S.qmul (qsquare_times x230 5) x_11 in qsquare_times_lemma x230 5; lemma_pow_pow_mod_mul f 0x3fffffffc00000003fffffffffffffffef39beab69c5e7a13cee72b0bf 0x20 0x3; assert (x235 == M.pow f 0x7fffffff800000007fffffffffffffffde737d56d38bcf4279dce5617e3 % S.order); let x240 = S.qmul (qsquare_times x235 5) x_11 in qsquare_times_lemma x235 5; lemma_pow_pow_mod_mul f 0x7fffffff800000007fffffffffffffffde737d56d38bcf4279dce5617e3 0x20 0x3; assert (x240 == M.pow f 0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc63 % S.order); let x243 = S.qmul (qsquare_times x240 3) f in qsquare_times_lemma x240 3; lemma_pow_pow_mod_mul f 0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc63 0x8 0x1; assert (x243 == M.pow f 0x7fffffff800000007fffffffffffffffde737d56d38bcf4279dce5617e319 % S.order); let x250 = S.qmul (qsquare_times x243 7) x_10101 in qsquare_times_lemma x243 7; assert_norm (pow2 7 = 0x80); lemma_pow_pow_mod_mul f 0x7fffffff800000007fffffffffffffffde737d56d38bcf4279dce5617e319 0x80 0x15; assert (x250 == M.pow f 0x3fffffffc00000003fffffffffffffffef39beab69c5e7a13cee72b0bf18c95 % S.order); let x256 = S.qmul (qsquare_times x250 6) x_1111 in qsquare_times_lemma x250 6; lemma_pow_pow_mod_mul f 0x3fffffffc00000003fffffffffffffffef39beab69c5e7a13cee72b0bf18c95 0x40 0xf; assert (x256 == M.pow f 0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc63254f % S.order); assert_norm (S.order - 2 = 0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc63254f)
{ "checked_file": "/", "dependencies": [ "Spec.P256.fst.checked", "Spec.Exponentiation.fsti.checked", "prims.fst.checked", "Lib.NatMod.fsti.checked", "Lib.Exponentiation.fsti.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.P256.Qinv.fst" }
[ { "abbrev": true, "full_module": "Spec.P256", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.NatMod", "short_module": "M" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "LE" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.P256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.P256", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
f: Spec.P256.PointOps.qelem -> FStar.Pervasives.Lemma (ensures Hacl.Spec.P256.Qinv.qinv f == Spec.P256.PointOps.qinv f)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Spec.P256.PointOps.qelem", "Lib.NatMod.lemma_pow_mod", "Spec.P256.PointOps.order", "Prims.op_Subtraction", "Prims.unit", "Prims._assert", "Prims.eq2", "Prims.int", "Hacl.Spec.P256.Qinv.qinv", "Prims.op_Modulus", "Lib.NatMod.pow", "Hacl.Spec.P256.Qinv.qinv_lemma" ]
[]
true
false
true
false
false
let qinv_is_qinv_lemma f =
qinv_lemma f; assert (qinv f == M.pow f (S.order - 2) % S.order); M.lemma_pow_mod #S.order f (S.order - 2)
false
L0Types.fsti
L0Types.l0_record_perm
val l0_record_perm (record: l0_record_t) (p: perm) (repr: l0_record_repr_t) : vprop
val l0_record_perm (record: l0_record_t) (p: perm) (repr: l0_record_repr_t) : vprop
let l0_record_perm (record:l0_record_t) (p:perm) (repr:l0_record_repr_t) : vprop = V.pts_to record.fwid #p repr.fwid ** V.pts_to record.deviceID_label #p repr.deviceID_label ** V.pts_to record.aliasKey_label #p repr.aliasKey_label ** pure ( valid_hkdf_lbl_len record.deviceID_label_len /\ valid_hkdf_lbl_len record.aliasKey_label_len )
{ "file_name": "share/steel/examples/pulse/dice/l0/L0Types.fsti", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 3, "end_line": 93, "start_col": 0, "start_line": 86 }
(* Copyright 2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module L0Types open Pulse.Lib.Pervasives module R = Pulse.Lib.Reference module V = Pulse.Lib.Vec module US = FStar.SizeT module U8 = FStar.UInt8 module U32 = FStar.UInt32 open HACL val x509_version_t : Type0 val x509_serialNumber_t : Type0 val deviceIDCRI_t : Type0 val deviceIDCSR_t : Type0 val aliasKeyTBS_t : Type0 val aliasKeyCRT_t : Type0 noeq type deviceIDCSR_ingredients_t = { ku : U32.t; version : x509_version_t; s_common : string; s_org : string; s_country : string; } noeq type aliasKeyCRT_ingredients_t = { version : x509_version_t; serialNumber : x509_serialNumber_t; i_common : string; i_org : string; i_country : string; notBefore : US.t; (* UTC_TIME *) notAfter : US.t; (* Generalized_Time *) s_common : string; s_org : string; s_country : string; ku : U32.t; l0_version : U32.t; } (* Record *) noeq type l0_record_t = { fwid: V.lvec U8.t (US.v v32us); deviceID_label_len: hkdf_lbl_len; deviceID_label: V.lvec U8.t (US.v deviceID_label_len); (* public bytes *) aliasKey_label_len: hkdf_lbl_len; aliasKey_label: V.lvec U8.t (US.v aliasKey_label_len); (* public bytes *) deviceIDCSR_ingredients: deviceIDCSR_ingredients_t; aliasKeyCRT_ingredients: aliasKeyCRT_ingredients_t; } noeq type l0_record_repr_t = { fwid: Seq.seq U8.t; deviceID_label: Seq.seq U8.t; aliasKey_label: Seq.seq U8.t; } let mk_l0_repr fwid deviceID_label aliasKey_label = {fwid; deviceID_label; aliasKey_label}
{ "checked_file": "/", "dependencies": [ "Pulse.Lib.Vec.fsti.checked", "Pulse.Lib.Reference.fsti.checked", "Pulse.Lib.Pervasives.fst.checked", "prims.fst.checked", "HACL.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "L0Types.fsti" }
[ { "abbrev": false, "full_module": "Pulse.Lib.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "HACL", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "US" }, { "abbrev": true, "full_module": "Pulse.Lib.Vec", "short_module": "V" }, { "abbrev": true, "full_module": "Pulse.Lib.Reference", "short_module": "R" }, { "abbrev": false, "full_module": "Pulse.Lib.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
record: L0Types.l0_record_t -> p: PulseCore.FractionalPermission.perm -> repr: L0Types.l0_record_repr_t -> Pulse.Lib.Core.vprop
Prims.Tot
[ "total" ]
[]
[ "L0Types.l0_record_t", "PulseCore.FractionalPermission.perm", "L0Types.l0_record_repr_t", "Pulse.Lib.Core.op_Star_Star", "Pulse.Lib.Vec.pts_to", "FStar.UInt8.t", "L0Types.__proj__Mkl0_record_t__item__fwid", "L0Types.__proj__Mkl0_record_repr_t__item__fwid", "L0Types.__proj__Mkl0_record_t__item__deviceID_label", "L0Types.__proj__Mkl0_record_repr_t__item__deviceID_label", "L0Types.__proj__Mkl0_record_t__item__aliasKey_label", "L0Types.__proj__Mkl0_record_repr_t__item__aliasKey_label", "Pulse.Lib.Core.pure", "Prims.l_and", "HACL.valid_hkdf_lbl_len", "L0Types.__proj__Mkl0_record_t__item__deviceID_label_len", "L0Types.__proj__Mkl0_record_t__item__aliasKey_label_len", "Pulse.Lib.Core.vprop" ]
[]
false
false
false
true
false
let l0_record_perm (record: l0_record_t) (p: perm) (repr: l0_record_repr_t) : vprop =
((V.pts_to record.fwid #p repr.fwid ** V.pts_to record.deviceID_label #p repr.deviceID_label) ** V.pts_to record.aliasKey_label #p repr.aliasKey_label) ** pure (valid_hkdf_lbl_len record.deviceID_label_len /\ valid_hkdf_lbl_len record.aliasKey_label_len)
false
L0Types.fsti
L0Types.mk_l0_repr
val mk_l0_repr : fwid: FStar.Seq.Base.seq FStar.UInt8.t -> deviceID_label: FStar.Seq.Base.seq FStar.UInt8.t -> aliasKey_label: FStar.Seq.Base.seq FStar.UInt8.t -> L0Types.l0_record_repr_t
let mk_l0_repr fwid deviceID_label aliasKey_label = {fwid; deviceID_label; aliasKey_label}
{ "file_name": "share/steel/examples/pulse/dice/l0/L0Types.fsti", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 42, "end_line": 83, "start_col": 0, "start_line": 82 }
(* Copyright 2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module L0Types open Pulse.Lib.Pervasives module R = Pulse.Lib.Reference module V = Pulse.Lib.Vec module US = FStar.SizeT module U8 = FStar.UInt8 module U32 = FStar.UInt32 open HACL val x509_version_t : Type0 val x509_serialNumber_t : Type0 val deviceIDCRI_t : Type0 val deviceIDCSR_t : Type0 val aliasKeyTBS_t : Type0 val aliasKeyCRT_t : Type0 noeq type deviceIDCSR_ingredients_t = { ku : U32.t; version : x509_version_t; s_common : string; s_org : string; s_country : string; } noeq type aliasKeyCRT_ingredients_t = { version : x509_version_t; serialNumber : x509_serialNumber_t; i_common : string; i_org : string; i_country : string; notBefore : US.t; (* UTC_TIME *) notAfter : US.t; (* Generalized_Time *) s_common : string; s_org : string; s_country : string; ku : U32.t; l0_version : U32.t; } (* Record *) noeq type l0_record_t = { fwid: V.lvec U8.t (US.v v32us); deviceID_label_len: hkdf_lbl_len; deviceID_label: V.lvec U8.t (US.v deviceID_label_len); (* public bytes *) aliasKey_label_len: hkdf_lbl_len; aliasKey_label: V.lvec U8.t (US.v aliasKey_label_len); (* public bytes *) deviceIDCSR_ingredients: deviceIDCSR_ingredients_t; aliasKeyCRT_ingredients: aliasKeyCRT_ingredients_t; } noeq type l0_record_repr_t = { fwid: Seq.seq U8.t; deviceID_label: Seq.seq U8.t; aliasKey_label: Seq.seq U8.t; }
{ "checked_file": "/", "dependencies": [ "Pulse.Lib.Vec.fsti.checked", "Pulse.Lib.Reference.fsti.checked", "Pulse.Lib.Pervasives.fst.checked", "prims.fst.checked", "HACL.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "L0Types.fsti" }
[ { "abbrev": false, "full_module": "Pulse.Lib.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "HACL", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "US" }, { "abbrev": true, "full_module": "Pulse.Lib.Vec", "short_module": "V" }, { "abbrev": true, "full_module": "Pulse.Lib.Reference", "short_module": "R" }, { "abbrev": false, "full_module": "Pulse.Lib.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
fwid: FStar.Seq.Base.seq FStar.UInt8.t -> deviceID_label: FStar.Seq.Base.seq FStar.UInt8.t -> aliasKey_label: FStar.Seq.Base.seq FStar.UInt8.t -> L0Types.l0_record_repr_t
Prims.Tot
[ "total" ]
[]
[ "FStar.Seq.Base.seq", "FStar.UInt8.t", "L0Types.Mkl0_record_repr_t", "L0Types.l0_record_repr_t" ]
[]
false
false
false
true
false
let mk_l0_repr fwid deviceID_label aliasKey_label =
{ fwid = fwid; deviceID_label = deviceID_label; aliasKey_label = aliasKey_label }
false
Hacl.Spec.P256.Qinv.fst
Hacl.Spec.P256.Qinv.lemma_pow_mod_mul
val lemma_pow_mod_mul: f:S.qelem -> a:nat -> b:nat -> Lemma (S.qmul (M.pow f a % S.order) (M.pow f b % S.order) == M.pow f (a + b) % S.order)
val lemma_pow_mod_mul: f:S.qelem -> a:nat -> b:nat -> Lemma (S.qmul (M.pow f a % S.order) (M.pow f b % S.order) == M.pow f (a + b) % S.order)
let lemma_pow_mod_mul f a b = calc (==) { S.qmul (M.pow f a % S.order) (M.pow f b % S.order); (==) { Math.Lemmas.lemma_mod_mul_distr_l (M.pow f a) (M.pow f b % S.order) S.order; Math.Lemmas.lemma_mod_mul_distr_r (M.pow f a) (M.pow f b) S.order } M.pow f a * M.pow f b % S.order; (==) { M.lemma_pow_add f a b } M.pow f (a + b) % S.order; }
{ "file_name": "code/ecdsap256/Hacl.Spec.P256.Qinv.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 3, "end_line": 154, "start_col": 0, "start_line": 145 }
module Hacl.Spec.P256.Qinv open FStar.Mul module SE = Spec.Exponentiation module LE = Lib.Exponentiation module M = Lib.NatMod module S = Spec.P256 #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" let nat_mod_comm_monoid = M.mk_nat_mod_comm_monoid S.order let mk_to_nat_mod_comm_monoid : SE.to_comm_monoid S.qelem = { SE.a_spec = S.qelem; SE.comm_monoid = nat_mod_comm_monoid; SE.refl = (fun (x:S.qelem) -> x); } val one_mod : SE.one_st S.qelem mk_to_nat_mod_comm_monoid let one_mod _ = 1 val mul_mod : SE.mul_st S.qelem mk_to_nat_mod_comm_monoid let mul_mod x y = S.qmul x y val sqr_mod : SE.sqr_st S.qelem mk_to_nat_mod_comm_monoid let sqr_mod x = S.qmul x x let mk_nat_mod_concrete_ops : SE.concrete_ops S.qelem = { SE.to = mk_to_nat_mod_comm_monoid; SE.one = one_mod; SE.mul = mul_mod; SE.sqr = sqr_mod; } let qsquare_times (a:S.qelem) (b:nat) : S.qelem = SE.exp_pow2 mk_nat_mod_concrete_ops a b val qsquare_times_lemma: a:S.qelem -> b:nat -> Lemma (qsquare_times a b == M.pow a (pow2 b) % S.order) let qsquare_times_lemma a b = SE.exp_pow2_lemma mk_nat_mod_concrete_ops a b; LE.exp_pow2_lemma nat_mod_comm_monoid a b; assert (qsquare_times a b == LE.pow nat_mod_comm_monoid a (pow2 b)); M.lemma_pow_nat_mod_is_pow #S.order a (pow2 b) let qinv_x8_x128 (x6 x_11: S.qelem) : S.qelem = let x8 = S.qmul (qsquare_times x6 2) x_11 in let x16 = S.qmul (qsquare_times x8 8) x8 in let x32 = S.qmul (qsquare_times x16 16) x16 in let x96 = S.qmul (qsquare_times x32 64) x32 in let x128 = S.qmul (qsquare_times x96 32) x32 in x128 let qinv_x134_x153 (x128 x_11 x_111 x_1111 x_10101 x_101111: S.qelem) : S.qelem = let x134 = S.qmul (qsquare_times x128 6) x_101111 in let x139 = S.qmul (qsquare_times x134 5) x_111 in let x143 = S.qmul (qsquare_times x139 4) x_11 in let x148 = S.qmul (qsquare_times x143 5) x_1111 in let x153 = S.qmul (qsquare_times x148 5) x_10101 in x153 let qinv_x153_x177 (x153 x_101 x_111 x_101111: S.qelem) : S.qelem = let x157 = S.qmul (qsquare_times x153 4) x_101 in let x160 = S.qmul (qsquare_times x157 3) x_101 in let x163 = S.qmul (qsquare_times x160 3) x_101 in let x168 = S.qmul (qsquare_times x163 5) x_111 in let x177 = S.qmul (qsquare_times x168 9) x_101111 in x177 let qinv_x177_x210 (f x177 x_111 x_1111: S.qelem) : S.qelem = let x183 = S.qmul (qsquare_times x177 6) x_1111 in let x185 = S.qmul (qsquare_times x183 2) f in let x190 = S.qmul (qsquare_times x185 5) f in let x196 = S.qmul (qsquare_times x190 6) x_1111 in let x201 = S.qmul (qsquare_times x196 5) x_111 in let x205 = S.qmul (qsquare_times x201 4) x_111 in let x210 = S.qmul (qsquare_times x205 5) x_111 in x210 let qinv_x210_x240 (x210 x_11 x_101 x_101111: S.qelem) : S.qelem = let x215 = S.qmul (qsquare_times x210 5) x_101 in let x218 = S.qmul (qsquare_times x215 3) x_11 in let x228 = S.qmul (qsquare_times x218 10) x_101111 in let x230 = S.qmul (qsquare_times x228 2) x_11 in let x235 = S.qmul (qsquare_times x230 5) x_11 in let x240 = S.qmul (qsquare_times x235 5) x_11 in x240 let qinv_x240_x256 (f x240 x_1111 x_10101: S.qelem) : S.qelem = let x243 = S.qmul (qsquare_times x240 3) f in let x250 = S.qmul (qsquare_times x243 7) x_10101 in let x256 = S.qmul (qsquare_times x250 6) x_1111 in x256 let qinv_x8_x256 (f x6 x_11 x_101 x_111 x_1111 x_10101 x_101111 : S.qelem) : S.qelem = let x128 = qinv_x8_x128 x6 x_11 in let x153 = qinv_x134_x153 x128 x_11 x_111 x_1111 x_10101 x_101111 in let x177 = qinv_x153_x177 x153 x_101 x_111 x_101111 in let x210 = qinv_x177_x210 f x177 x_111 x_1111 in let x240 = qinv_x210_x240 x210 x_11 x_101 x_101111 in let x256 = qinv_x240_x256 f x240 x_1111 x_10101 in x256 (** The algorithm is taken from https://briansmith.org/ecc-inversion-addition-chains-01 *) val qinv: f:S.qelem -> S.qelem let qinv f = let x_10 = qsquare_times f 1 in // x_10 is used 3x let x_11 = S.qmul x_10 f in let x_101 = S.qmul x_10 x_11 in let x_111 = S.qmul x_10 x_101 in let x_1010 = qsquare_times x_101 1 in // x_1010 is used 2x let x_1111 = S.qmul x_101 x_1010 in let x_10101 = S.qmul (qsquare_times x_1010 1) f in let x_101010 = qsquare_times x_10101 1 in // x_101010 is used 2x let x_101111 = S.qmul x_101 x_101010 in let x6 = S.qmul x_10101 x_101010 in qinv_x8_x256 f x6 x_11 x_101 x_111 x_1111 x_10101 x_101111 // TODO: mv to lib/ val lemma_pow_mod_1: f:S.qelem -> Lemma (f == M.pow f 1 % S.order) let lemma_pow_mod_1 f = M.lemma_pow1 f; Math.Lemmas.small_mod f S.order; assert_norm (pow2 0 = 1); assert (f == M.pow f 1 % S.order) val lemma_pow_mod_mul: f:S.qelem -> a:nat -> b:nat ->
{ "checked_file": "/", "dependencies": [ "Spec.P256.fst.checked", "Spec.Exponentiation.fsti.checked", "prims.fst.checked", "Lib.NatMod.fsti.checked", "Lib.Exponentiation.fsti.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.P256.Qinv.fst" }
[ { "abbrev": true, "full_module": "Spec.P256", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.NatMod", "short_module": "M" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "LE" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.P256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.P256", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
f: Spec.P256.PointOps.qelem -> a: Prims.nat -> b: Prims.nat -> FStar.Pervasives.Lemma (ensures Spec.P256.PointOps.qmul (Lib.NatMod.pow f a % Spec.P256.PointOps.order) (Lib.NatMod.pow f b % Spec.P256.PointOps.order) == Lib.NatMod.pow f (a + b) % Spec.P256.PointOps.order)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Spec.P256.PointOps.qelem", "Prims.nat", "FStar.Calc.calc_finish", "Prims.eq2", "Spec.P256.PointOps.qmul", "Prims.op_Modulus", "Lib.NatMod.pow", "Spec.P256.PointOps.order", "Prims.op_Addition", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "Prims.unit", "FStar.Calc.calc_step", "FStar.Mul.op_Star", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "FStar.Math.Lemmas.lemma_mod_mul_distr_r", "FStar.Math.Lemmas.lemma_mod_mul_distr_l", "Prims.squash", "Lib.NatMod.lemma_pow_add" ]
[]
false
false
true
false
false
let lemma_pow_mod_mul f a b =
calc ( == ) { S.qmul (M.pow f a % S.order) (M.pow f b % S.order); ( == ) { (Math.Lemmas.lemma_mod_mul_distr_l (M.pow f a) (M.pow f b % S.order) S.order; Math.Lemmas.lemma_mod_mul_distr_r (M.pow f a) (M.pow f b) S.order) } M.pow f a * M.pow f b % S.order; ( == ) { M.lemma_pow_add f a b } M.pow f (a + b) % S.order; }
false
Hacl.Spec.P256.Qinv.fst
Hacl.Spec.P256.Qinv.qsquare_times_lemma
val qsquare_times_lemma: a:S.qelem -> b:nat -> Lemma (qsquare_times a b == M.pow a (pow2 b) % S.order)
val qsquare_times_lemma: a:S.qelem -> b:nat -> Lemma (qsquare_times a b == M.pow a (pow2 b) % S.order)
let qsquare_times_lemma a b = SE.exp_pow2_lemma mk_nat_mod_concrete_ops a b; LE.exp_pow2_lemma nat_mod_comm_monoid a b; assert (qsquare_times a b == LE.pow nat_mod_comm_monoid a (pow2 b)); M.lemma_pow_nat_mod_is_pow #S.order a (pow2 b)
{ "file_name": "code/ecdsap256/Hacl.Spec.P256.Qinv.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 48, "end_line": 45, "start_col": 0, "start_line": 41 }
module Hacl.Spec.P256.Qinv open FStar.Mul module SE = Spec.Exponentiation module LE = Lib.Exponentiation module M = Lib.NatMod module S = Spec.P256 #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" let nat_mod_comm_monoid = M.mk_nat_mod_comm_monoid S.order let mk_to_nat_mod_comm_monoid : SE.to_comm_monoid S.qelem = { SE.a_spec = S.qelem; SE.comm_monoid = nat_mod_comm_monoid; SE.refl = (fun (x:S.qelem) -> x); } val one_mod : SE.one_st S.qelem mk_to_nat_mod_comm_monoid let one_mod _ = 1 val mul_mod : SE.mul_st S.qelem mk_to_nat_mod_comm_monoid let mul_mod x y = S.qmul x y val sqr_mod : SE.sqr_st S.qelem mk_to_nat_mod_comm_monoid let sqr_mod x = S.qmul x x let mk_nat_mod_concrete_ops : SE.concrete_ops S.qelem = { SE.to = mk_to_nat_mod_comm_monoid; SE.one = one_mod; SE.mul = mul_mod; SE.sqr = sqr_mod; } let qsquare_times (a:S.qelem) (b:nat) : S.qelem = SE.exp_pow2 mk_nat_mod_concrete_ops a b val qsquare_times_lemma: a:S.qelem -> b:nat ->
{ "checked_file": "/", "dependencies": [ "Spec.P256.fst.checked", "Spec.Exponentiation.fsti.checked", "prims.fst.checked", "Lib.NatMod.fsti.checked", "Lib.Exponentiation.fsti.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.P256.Qinv.fst" }
[ { "abbrev": true, "full_module": "Spec.P256", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.NatMod", "short_module": "M" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "LE" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.P256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.P256", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Spec.P256.PointOps.qelem -> b: Prims.nat -> FStar.Pervasives.Lemma (ensures Hacl.Spec.P256.Qinv.qsquare_times a b == Lib.NatMod.pow a (Prims.pow2 b) % Spec.P256.PointOps.order)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Spec.P256.PointOps.qelem", "Prims.nat", "Lib.NatMod.lemma_pow_nat_mod_is_pow", "Spec.P256.PointOps.order", "Prims.pow2", "Prims.unit", "Prims._assert", "Prims.eq2", "Prims.l_or", "Prims.b2t", "Prims.op_LessThan", "Hacl.Spec.P256.Qinv.qsquare_times", "Lib.Exponentiation.Definition.pow", "Lib.NatMod.nat_mod", "Hacl.Spec.P256.Qinv.nat_mod_comm_monoid", "Lib.Exponentiation.exp_pow2_lemma", "Spec.Exponentiation.exp_pow2_lemma", "Hacl.Spec.P256.Qinv.mk_nat_mod_concrete_ops" ]
[]
true
false
true
false
false
let qsquare_times_lemma a b =
SE.exp_pow2_lemma mk_nat_mod_concrete_ops a b; LE.exp_pow2_lemma nat_mod_comm_monoid a b; assert (qsquare_times a b == LE.pow nat_mod_comm_monoid a (pow2 b)); M.lemma_pow_nat_mod_is_pow #S.order a (pow2 b)
false
LatticeSpec.fst
LatticeSpec.ann_le
val ann_le (ann1 ann2: annot) : Type0
val ann_le (ann1 ann2: annot) : Type0
let ann_le (ann1 ann2 : annot) : Type0 = forall x. ann1 x ==> ann2 x
{ "file_name": "examples/layeredeffects/LatticeSpec.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 29, "end_line": 82, "start_col": 0, "start_line": 81 }
module LatticeSpec open FStar.Tactics.V2 open FStar.List.Tot // 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 = | RD | WR | EXN type annot = eff_label -> bool // warning: if this is not annotated, `eqtype` is inferred // as its type and the effect definition fails for some reason. type state : Type = int type pre_t = state -> Type0 type post_t a = state -> option a -> state -> Type0 // this repr doesn't seem to work too well type repr0 (a:Type u#aa) (pre : pre_t) (post : post_t u#aa a) // #2074 : Type u#aa = s0:state{pre s0} -> Tot (r:(option a & state){post s0 (fst r) (snd r)}) let abides #a #pre #post (f : repr0 a pre post) (ann:annot) : Type0 = (ann RD = false ==> (forall s0 s1. fst (f s0) == fst (f s1))) /\ (ann WR = false ==> (forall s0. snd (f s0) == s0)) /\ (ann EXN = false ==> (forall s0. Some? (fst (f s0)))) let interp (l : list eff_label) : annot = fun lab -> mem lab 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 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 type repr (a:Type u#aa) (pre : pre_t) (post : post_t u#aa a) // #2074 (labs : list u#0 eff_label) // #2074 : Type u#aa = r:(repr0 a pre post){abides r (interp labs)}
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LatticeSpec.fst" }
[ { "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: LatticeSpec.annot -> ann2: LatticeSpec.annot -> Type0
Prims.Tot
[ "total" ]
[]
[ "LatticeSpec.annot", "Prims.l_Forall", "LatticeSpec.eff_label", "Prims.l_imp", "Prims.b2t" ]
[]
false
false
false
true
true
let ann_le (ann1 ann2: annot) : Type0 =
forall x. ann1 x ==> ann2 x
false
Steel.ST.GenArraySwap.Proof.fst
Steel.ST.GenArraySwap.Proof.jump_coverage
val jump_coverage (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Ghost nat (requires True) (ensures (fun k -> x == iter_fun (jump n l) k (x % b.d)))
val jump_coverage (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Ghost nat (requires True) (ensures (fun k -> x == iter_fun (jump n l) k (x % b.d)))
let jump_coverage (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Ghost nat (requires True) (ensures (fun k -> x == iter_fun (jump n l) k (x % b.d) )) = let i = x % b.d in let qx = x / b.d in euclidean_division_definition x b.d; let k1 = qx * b.u_l in let m = qx * b.u_n in assert (eq2 #int (qx * (n * b.u_n + l * b.u_l) + i) (i + k1 * l + m * n)) by (int_semiring ()); assert (x == i + k1 * l + m * n); small_mod x n; lemma_mod_plus (i + k1 * l) m n; assert (x == (i + k1 * l) % n); let k = k1 % n in let qk = k1 / n in euclidean_division_definition k1 n; assert (i + (qk * n + k) * l == i + k * l + (qk * l) * n) by (int_semiring ()); lemma_mod_plus (i + k * l) (qk * l) n; assert (eq2 #int x ((i + k * l) % n)); jump_iter n l i k; k
{ "file_name": "lib/steel/Steel.ST.GenArraySwap.Proof.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 3, "end_line": 297, "start_col": 0, "start_line": 269 }
module Steel.ST.GenArraySwap.Proof open FStar.Math.Lemmas open FStar.Mul let lemma_mod_lt (a:int) (b:pos) : Lemma (let r = a % b in 0 <= r /\ r < b) [SMTPat (a % b)] = () let lemma_mul_nat_nat_is_nat (a b: nat) : Lemma (a * b >= 0) [SMTPat (a * b)] = () let lemma_pos_mul_pos_args (a: nat) (b: nat) : Lemma (requires (a * b > 0)) (ensures (a > 0 /\ b > 0 /\ a <= a * b /\ b <= a * b /\ a * b == b * a)) = () let lemma_div_nat (a: nat) (b: pos) : Lemma (a / b >= 0) [SMTPat (a / b)] = () let lemma_mult_reg_l (k: int) (x1 x2: int) : Lemma (requires ( k * x1 == k * x2 /\ k <> 0 )) (ensures ( x1 == x2 )) = () let lemma_bezout_one_zero (x1: int) (x2: nat) (y1 y2: int) : Lemma (requires ( x1 * x2 + y1 * y2 == 1 /\ y1 == 0 )) (ensures ( x1 == 1 /\ x2 == 1 )) = () #set-options "--z3cliopt smt.arith.nl=false" let int_semiring () = FStar.Tactics.CanonCommSemiring.int_semiring (); FStar.Tactics.trefl (); FStar.Tactics.qed () [@@erasable] noeq type bezout_t = { d: pos; q_n: nat; q_l: nat; u_n: int; u_l: int; } let bezout_prop' (n: nat) (l: nat) (d: pos) (q_n: nat) (q_l: nat) (u_n: int) (u_l: int) : Tot prop = n == d * q_n /\ l == d * q_l /\ d == n * u_n + l * u_l let bezout_prop (n: nat) (l: nat) (b: bezout_t) : Tot prop = bezout_prop' n l b.d b.q_n b.q_l b.u_n b.u_l let bezout (n: nat) (l: nat) : Tot Type = (b: bezout_t { bezout_prop n l b }) #restart-solver let rec mk_bezout (n: pos) (l: nat) : Pure (bezout n l) (requires (l < n)) (ensures (fun _ -> True)) (decreases l) = if l = 0 then begin let d : pos = n in let q_n : nat = 1 in let q_l : nat = 0 in let u_n : int = 1 in let u_l : int = 0 in let res = { d = d; q_n = q_n; q_l = q_l; u_n = u_n; u_l = u_l; } in assert (eq2 #int n (d * q_n)) by (int_semiring ()); assert (eq2 #int 0 (d * q_l)) by (int_semiring ()); assert (eq2 #int d (n * 1 + 0 * res.u_l)) by (int_semiring ()); res end else begin let lpre = n % l in let ql = n / l in euclidean_division_definition n l; let bpre = mk_bezout l lpre in let d = bpre.d in let q_l = bpre.q_n in let qpre_lpre = bpre.q_l in let upre_l = bpre.u_n in let upre_lpre = bpre.u_l in let n_alt0 = l * ql + lpre in assert (n == n_alt0); let l_alt = d * q_l in let lpre_alt1 = d * qpre_lpre in let n_alt1 = l_alt * ql + lpre_alt1 in assert (n_alt1 == n); let q_n = q_l * ql + qpre_lpre in assert (eq2 #int n_alt1 (d * q_n)) by (int_semiring ()); let lpre_alt2 = n + - l * ql in assert (lpre_alt2 == lpre); let d_alt = l * upre_l + lpre_alt2 * upre_lpre in assert (d_alt == d); let u_l = upre_l + - ql * upre_lpre in assert (eq2 #int (n * upre_lpre + l * u_l) d_alt) by (int_semiring ()); let res = { d = d; q_n = q_n; q_l = q_l; u_n = upre_lpre; u_l = u_l; } in res end let bezout_q_eq (n: nat) (l: nat) (bz: bezout n l) : Lemma (bz.q_n == n / bz.d) [SMTPat (bezout_prop n l bz); SMTPat bz.q_n] = cancel_mul_div bz.q_n bz.d let rec iter_fun (#t: Type) (f: (t -> GTot t)) (n: nat) (x: t) : GTot t (decreases n) = if n = 0 then x else iter_fun f (n - 1) (f x) let nat_up_to (n: nat) : Tot Type = (i: nat { i < n }) let jump (n: pos) (l: nat) (x: nat_up_to n) : GTot (nat_up_to n) = (x + l) % n #restart-solver let jump_mod_d (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Lemma (jump n l x % b.d == x % b.d) = let x' = jump n l x in let x'q = (x + l) / n in euclidean_division_definition (x + l) n; let l_alt = b.d * b.q_l in assert (l_alt == l); let n_alt = b.d * b.q_n in assert (n_alt == n); let x'_alt = x + l_alt + - x'q * n_alt in assert (x'_alt == x'); let qx = b.q_l + - x'q * b.q_n in assert (eq2 #int x'_alt (x + qx * b.d)) by (int_semiring ()); lemma_mod_plus x qx b.d let rec jump_iter_mod_d (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) (k: nat) : Lemma (ensures (iter_fun #(nat_up_to n) (jump n l) k x % b.d == x % b.d)) (decreases k) = if k = 0 then () else begin jump_mod_d n l b x; jump_iter_mod_d n l b (jump n l x) (k - 1) end (* Coverage *) let rec jump_iter (n: pos) (l: nat) (x: nat_up_to n) (k: nat) : Lemma (ensures (iter_fun #(nat_up_to n) (jump n l) k x == (x + k * l) % n)) (decreases k) = if k = 0 then begin assert (eq2 #int (x + 0 * l) x) by (int_semiring ()); small_mod x n end else begin let k' = k - 1 in assert (eq2 #int (x + (k' + 1) * l) ((x + l) + k' * l)) by (int_semiring ()); jump_iter n l ((x + l) % n) k'; lemma_mod_add_distr (k' * l) (x + l) n end let bezout_pos_le (n: pos) (l: nat) (b: bezout n l) : Lemma (b.d <= n /\ b.q_n > 0) [SMTPat (bezout_prop n l b)] = lemma_pos_mul_pos_args b.q_n b.d #restart-solver [@@"opaque_to_smt"]
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.CanonCommSemiring.fst.checked", "FStar.Tactics.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Steel.ST.GenArraySwap.Proof.fst" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.GenArraySwap", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.GenArraySwap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
n: Prims.pos -> l: Prims.nat -> b: Steel.ST.GenArraySwap.Proof.bezout n l -> x: Steel.ST.GenArraySwap.Proof.nat_up_to n -> Prims.Ghost Prims.nat
Prims.Ghost
[]
[]
[ "Prims.pos", "Prims.nat", "Steel.ST.GenArraySwap.Proof.bezout", "Steel.ST.GenArraySwap.Proof.nat_up_to", "Prims.unit", "Steel.ST.GenArraySwap.Proof.jump_iter", "Prims._assert", "Prims.eq2", "Prims.int", "Prims.op_Modulus", "Prims.op_Addition", "FStar.Mul.op_Star", "FStar.Math.Lemmas.lemma_mod_plus", "FStar.Tactics.Effect.assert_by_tactic", "Steel.ST.GenArraySwap.Proof.int_semiring", "FStar.Math.Lemmas.euclidean_division_definition", "Prims.op_Division", "FStar.Math.Lemmas.small_mod", "Steel.ST.GenArraySwap.Proof.__proj__Mkbezout_t__item__u_n", "Steel.ST.GenArraySwap.Proof.__proj__Mkbezout_t__item__u_l", "Steel.ST.GenArraySwap.Proof.__proj__Mkbezout_t__item__d", "Prims.l_True", "Steel.ST.GenArraySwap.Proof.iter_fun", "Steel.ST.GenArraySwap.Proof.jump" ]
[]
false
false
false
false
false
let jump_coverage (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Ghost nat (requires True) (ensures (fun k -> x == iter_fun (jump n l) k (x % b.d))) =
let i = x % b.d in let qx = x / b.d in euclidean_division_definition x b.d; let k1 = qx * b.u_l in let m = qx * b.u_n in FStar.Tactics.Effect.assert_by_tactic (eq2 #int (qx * (n * b.u_n + l * b.u_l) + i) (i + k1 * l + m * n)) (fun _ -> (); (int_semiring ())); assert (x == i + k1 * l + m * n); small_mod x n; lemma_mod_plus (i + k1 * l) m n; assert (x == (i + k1 * l) % n); let k = k1 % n in let qk = k1 / n in euclidean_division_definition k1 n; FStar.Tactics.Effect.assert_by_tactic (i + (qk * n + k) * l == i + k * l + (qk * l) * n) (fun _ -> (); (int_semiring ())); lemma_mod_plus (i + k * l) (qk * l) n; assert (eq2 #int x ((i + k * l) % n)); jump_iter n l i k; k
false
LatticeSpec.fst
LatticeSpec.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/LatticeSpec.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 32, "end_line": 45, "start_col": 0, "start_line": 40 }
module LatticeSpec open FStar.Tactics.V2 open FStar.List.Tot // 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 = | RD | WR | EXN type annot = eff_label -> bool // warning: if this is not annotated, `eqtype` is inferred // as its type and the effect definition fails for some reason. type state : Type = int type pre_t = state -> Type0 type post_t a = state -> option a -> state -> Type0 // this repr doesn't seem to work too well type repr0 (a:Type u#aa) (pre : pre_t) (post : post_t u#aa a) // #2074 : Type u#aa = s0:state{pre s0} -> Tot (r:(option a & state){post s0 (fst r) (snd r)}) let abides #a #pre #post (f : repr0 a pre post) (ann:annot) : Type0 = (ann RD = false ==> (forall s0 s1. fst (f s0) == fst (f s1))) /\ (ann WR = false ==> (forall s0. snd (f s0) == s0)) /\ (ann EXN = false ==> (forall s0. Some? (fst (f s0)))) let interp (l : list eff_label) : annot = fun lab -> mem lab l
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LatticeSpec.fst" }
[ { "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 LatticeSpec.eff_label -> l2: Prims.list LatticeSpec.eff_label -> l: LatticeSpec.eff_label -> FStar.Pervasives.Lemma (ensures LatticeSpec.interp (l1 @ l2) l == (LatticeSpec.interp l1 l || LatticeSpec.interp l2 l)) [SMTPat (LatticeSpec.interp (l1 @ l2) l)]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.list", "LatticeSpec.eff_label", "LatticeSpec.interp_at", "Prims.unit", "Prims.l_True", "Prims.squash", "Prims.eq2", "Prims.bool", "LatticeSpec.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
Hacl.Spec.P256.Qinv.fst
Hacl.Spec.P256.Qinv.lemma_pow_pow_mod
val lemma_pow_pow_mod: f:S.qelem -> a:nat -> b:nat -> Lemma (M.pow (M.pow f a % S.order) b % S.order == M.pow f (a * b) % S.order)
val lemma_pow_pow_mod: f:S.qelem -> a:nat -> b:nat -> Lemma (M.pow (M.pow f a % S.order) b % S.order == M.pow f (a * b) % S.order)
let lemma_pow_pow_mod f a b = calc (==) { M.pow (M.pow f a % S.order) b % S.order; (==) { M.lemma_pow_mod_base (M.pow f a) b S.order } M.pow (M.pow f a) b % S.order; (==) { M.lemma_pow_mul f a b } M.pow f (a * b) % S.order; }
{ "file_name": "code/ecdsap256/Hacl.Spec.P256.Qinv.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 5, "end_line": 166, "start_col": 0, "start_line": 159 }
module Hacl.Spec.P256.Qinv open FStar.Mul module SE = Spec.Exponentiation module LE = Lib.Exponentiation module M = Lib.NatMod module S = Spec.P256 #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" let nat_mod_comm_monoid = M.mk_nat_mod_comm_monoid S.order let mk_to_nat_mod_comm_monoid : SE.to_comm_monoid S.qelem = { SE.a_spec = S.qelem; SE.comm_monoid = nat_mod_comm_monoid; SE.refl = (fun (x:S.qelem) -> x); } val one_mod : SE.one_st S.qelem mk_to_nat_mod_comm_monoid let one_mod _ = 1 val mul_mod : SE.mul_st S.qelem mk_to_nat_mod_comm_monoid let mul_mod x y = S.qmul x y val sqr_mod : SE.sqr_st S.qelem mk_to_nat_mod_comm_monoid let sqr_mod x = S.qmul x x let mk_nat_mod_concrete_ops : SE.concrete_ops S.qelem = { SE.to = mk_to_nat_mod_comm_monoid; SE.one = one_mod; SE.mul = mul_mod; SE.sqr = sqr_mod; } let qsquare_times (a:S.qelem) (b:nat) : S.qelem = SE.exp_pow2 mk_nat_mod_concrete_ops a b val qsquare_times_lemma: a:S.qelem -> b:nat -> Lemma (qsquare_times a b == M.pow a (pow2 b) % S.order) let qsquare_times_lemma a b = SE.exp_pow2_lemma mk_nat_mod_concrete_ops a b; LE.exp_pow2_lemma nat_mod_comm_monoid a b; assert (qsquare_times a b == LE.pow nat_mod_comm_monoid a (pow2 b)); M.lemma_pow_nat_mod_is_pow #S.order a (pow2 b) let qinv_x8_x128 (x6 x_11: S.qelem) : S.qelem = let x8 = S.qmul (qsquare_times x6 2) x_11 in let x16 = S.qmul (qsquare_times x8 8) x8 in let x32 = S.qmul (qsquare_times x16 16) x16 in let x96 = S.qmul (qsquare_times x32 64) x32 in let x128 = S.qmul (qsquare_times x96 32) x32 in x128 let qinv_x134_x153 (x128 x_11 x_111 x_1111 x_10101 x_101111: S.qelem) : S.qelem = let x134 = S.qmul (qsquare_times x128 6) x_101111 in let x139 = S.qmul (qsquare_times x134 5) x_111 in let x143 = S.qmul (qsquare_times x139 4) x_11 in let x148 = S.qmul (qsquare_times x143 5) x_1111 in let x153 = S.qmul (qsquare_times x148 5) x_10101 in x153 let qinv_x153_x177 (x153 x_101 x_111 x_101111: S.qelem) : S.qelem = let x157 = S.qmul (qsquare_times x153 4) x_101 in let x160 = S.qmul (qsquare_times x157 3) x_101 in let x163 = S.qmul (qsquare_times x160 3) x_101 in let x168 = S.qmul (qsquare_times x163 5) x_111 in let x177 = S.qmul (qsquare_times x168 9) x_101111 in x177 let qinv_x177_x210 (f x177 x_111 x_1111: S.qelem) : S.qelem = let x183 = S.qmul (qsquare_times x177 6) x_1111 in let x185 = S.qmul (qsquare_times x183 2) f in let x190 = S.qmul (qsquare_times x185 5) f in let x196 = S.qmul (qsquare_times x190 6) x_1111 in let x201 = S.qmul (qsquare_times x196 5) x_111 in let x205 = S.qmul (qsquare_times x201 4) x_111 in let x210 = S.qmul (qsquare_times x205 5) x_111 in x210 let qinv_x210_x240 (x210 x_11 x_101 x_101111: S.qelem) : S.qelem = let x215 = S.qmul (qsquare_times x210 5) x_101 in let x218 = S.qmul (qsquare_times x215 3) x_11 in let x228 = S.qmul (qsquare_times x218 10) x_101111 in let x230 = S.qmul (qsquare_times x228 2) x_11 in let x235 = S.qmul (qsquare_times x230 5) x_11 in let x240 = S.qmul (qsquare_times x235 5) x_11 in x240 let qinv_x240_x256 (f x240 x_1111 x_10101: S.qelem) : S.qelem = let x243 = S.qmul (qsquare_times x240 3) f in let x250 = S.qmul (qsquare_times x243 7) x_10101 in let x256 = S.qmul (qsquare_times x250 6) x_1111 in x256 let qinv_x8_x256 (f x6 x_11 x_101 x_111 x_1111 x_10101 x_101111 : S.qelem) : S.qelem = let x128 = qinv_x8_x128 x6 x_11 in let x153 = qinv_x134_x153 x128 x_11 x_111 x_1111 x_10101 x_101111 in let x177 = qinv_x153_x177 x153 x_101 x_111 x_101111 in let x210 = qinv_x177_x210 f x177 x_111 x_1111 in let x240 = qinv_x210_x240 x210 x_11 x_101 x_101111 in let x256 = qinv_x240_x256 f x240 x_1111 x_10101 in x256 (** The algorithm is taken from https://briansmith.org/ecc-inversion-addition-chains-01 *) val qinv: f:S.qelem -> S.qelem let qinv f = let x_10 = qsquare_times f 1 in // x_10 is used 3x let x_11 = S.qmul x_10 f in let x_101 = S.qmul x_10 x_11 in let x_111 = S.qmul x_10 x_101 in let x_1010 = qsquare_times x_101 1 in // x_1010 is used 2x let x_1111 = S.qmul x_101 x_1010 in let x_10101 = S.qmul (qsquare_times x_1010 1) f in let x_101010 = qsquare_times x_10101 1 in // x_101010 is used 2x let x_101111 = S.qmul x_101 x_101010 in let x6 = S.qmul x_10101 x_101010 in qinv_x8_x256 f x6 x_11 x_101 x_111 x_1111 x_10101 x_101111 // TODO: mv to lib/ val lemma_pow_mod_1: f:S.qelem -> Lemma (f == M.pow f 1 % S.order) let lemma_pow_mod_1 f = M.lemma_pow1 f; Math.Lemmas.small_mod f S.order; assert_norm (pow2 0 = 1); assert (f == M.pow f 1 % S.order) val lemma_pow_mod_mul: f:S.qelem -> a:nat -> b:nat -> Lemma (S.qmul (M.pow f a % S.order) (M.pow f b % S.order) == M.pow f (a + b) % S.order) let lemma_pow_mod_mul f a b = calc (==) { S.qmul (M.pow f a % S.order) (M.pow f b % S.order); (==) { Math.Lemmas.lemma_mod_mul_distr_l (M.pow f a) (M.pow f b % S.order) S.order; Math.Lemmas.lemma_mod_mul_distr_r (M.pow f a) (M.pow f b) S.order } M.pow f a * M.pow f b % S.order; (==) { M.lemma_pow_add f a b } M.pow f (a + b) % S.order; } val lemma_pow_pow_mod: f:S.qelem -> a:nat -> b:nat ->
{ "checked_file": "/", "dependencies": [ "Spec.P256.fst.checked", "Spec.Exponentiation.fsti.checked", "prims.fst.checked", "Lib.NatMod.fsti.checked", "Lib.Exponentiation.fsti.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.P256.Qinv.fst" }
[ { "abbrev": true, "full_module": "Spec.P256", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.NatMod", "short_module": "M" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "LE" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.P256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.P256", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
f: Spec.P256.PointOps.qelem -> a: Prims.nat -> b: Prims.nat -> FStar.Pervasives.Lemma (ensures Lib.NatMod.pow (Lib.NatMod.pow f a % Spec.P256.PointOps.order) b % Spec.P256.PointOps.order == Lib.NatMod.pow f (a * b) % Spec.P256.PointOps.order)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Spec.P256.PointOps.qelem", "Prims.nat", "FStar.Calc.calc_finish", "Prims.int", "Prims.eq2", "Prims.op_Modulus", "Lib.NatMod.pow", "Spec.P256.PointOps.order", "FStar.Mul.op_Star", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "Prims.unit", "FStar.Calc.calc_step", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "Lib.NatMod.lemma_pow_mod_base", "Prims.squash", "Lib.NatMod.lemma_pow_mul" ]
[]
false
false
true
false
false
let lemma_pow_pow_mod f a b =
calc ( == ) { M.pow (M.pow f a % S.order) b % S.order; ( == ) { M.lemma_pow_mod_base (M.pow f a) b S.order } M.pow (M.pow f a) b % S.order; ( == ) { M.lemma_pow_mul f a b } M.pow f (a * b) % S.order; }
false
LatticeSpec.fst
LatticeSpec.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/LatticeSpec.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 38, "end_line": 7, "start_col": 0, "start_line": 7 }
module LatticeSpec open FStar.Tactics.V2 open FStar.List.Tot
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LatticeSpec.fst" }
[ { "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
LatticeSpec.fst
LatticeSpec.bind_pre
val bind_pre (a: Type) (pre1: pre_t) (post1: post_t a) (b: Type) (pre2: (a -> pre_t)) (post2: (a -> post_t b)) : pre_t
val bind_pre (a: Type) (pre1: pre_t) (post1: post_t a) (b: Type) (pre2: (a -> pre_t)) (post2: (a -> post_t b)) : pre_t
let bind_pre (a:Type) (pre1:pre_t) (post1:post_t a) (b:Type) (pre2:a -> pre_t) (post2:a -> post_t b) : pre_t = fun s0 -> pre1 s0 /\ (forall y s1. post1 s0 (Some y) s1 ==> pre2 y s1)
{ "file_name": "examples/layeredeffects/LatticeSpec.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 73, "end_line": 96, "start_col": 0, "start_line": 92 }
module LatticeSpec open FStar.Tactics.V2 open FStar.List.Tot // 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 = | RD | WR | EXN type annot = eff_label -> bool // warning: if this is not annotated, `eqtype` is inferred // as its type and the effect definition fails for some reason. type state : Type = int type pre_t = state -> Type0 type post_t a = state -> option a -> state -> Type0 // this repr doesn't seem to work too well type repr0 (a:Type u#aa) (pre : pre_t) (post : post_t u#aa a) // #2074 : Type u#aa = s0:state{pre s0} -> Tot (r:(option a & state){post s0 (fst r) (snd r)}) let abides #a #pre #post (f : repr0 a pre post) (ann:annot) : Type0 = (ann RD = false ==> (forall s0 s1. fst (f s0) == fst (f s1))) /\ (ann WR = false ==> (forall s0. snd (f s0) == s0)) /\ (ann EXN = false ==> (forall s0. Some? (fst (f s0)))) let interp (l : list eff_label) : annot = fun lab -> mem lab 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 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 type repr (a:Type u#aa) (pre : pre_t) (post : post_t u#aa a) // #2074 (labs : list u#0 eff_label) // #2074 : Type u#aa = r:(repr0 a pre post){abides r (interp labs)} let ann_le (ann1 ann2 : annot) : Type0 = forall x. ann1 x ==> ann2 x let return (a:Type u#aa) (x:a) : Tot (repr a (fun _ -> True) (fun s0 y s1 -> s0 == s1 /\ y == Some x) []) = // GM: Need to write it like this.. why? let r (s0:state) : Tot (r:(option a & state){snd r == s0 /\ fst r == Some x}) = (Some x, s0) in r
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LatticeSpec.fst" }
[ { "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 -> pre1: LatticeSpec.pre_t -> post1: LatticeSpec.post_t a -> b: Type -> pre2: (_: a -> LatticeSpec.pre_t) -> post2: (_: a -> LatticeSpec.post_t b) -> LatticeSpec.pre_t
Prims.Tot
[ "total" ]
[]
[ "LatticeSpec.pre_t", "LatticeSpec.post_t", "LatticeSpec.state", "Prims.l_and", "Prims.l_Forall", "Prims.l_imp", "FStar.Pervasives.Native.Some" ]
[]
false
false
false
true
false
let bind_pre (a: Type) (pre1: pre_t) (post1: post_t a) (b: Type) (pre2: (a -> pre_t)) (post2: (a -> post_t b)) : pre_t =
fun s0 -> pre1 s0 /\ (forall y s1. post1 s0 (Some y) s1 ==> pre2 y s1)
false
LatticeSpec.fst
LatticeSpec.sublist
val sublist : l1: Prims.list LatticeSpec.eff_label -> l2: Prims.list LatticeSpec.eff_label -> Prims.logical
let sublist (l1 l2 : list eff_label) = forall x. mem x l1 ==> mem x l2
{ "file_name": "examples/layeredeffects/LatticeSpec.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 33, "end_line": 48, "start_col": 0, "start_line": 47 }
module LatticeSpec open FStar.Tactics.V2 open FStar.List.Tot // 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 = | RD | WR | EXN type annot = eff_label -> bool // warning: if this is not annotated, `eqtype` is inferred // as its type and the effect definition fails for some reason. type state : Type = int type pre_t = state -> Type0 type post_t a = state -> option a -> state -> Type0 // this repr doesn't seem to work too well type repr0 (a:Type u#aa) (pre : pre_t) (post : post_t u#aa a) // #2074 : Type u#aa = s0:state{pre s0} -> Tot (r:(option a & state){post s0 (fst r) (snd r)}) let abides #a #pre #post (f : repr0 a pre post) (ann:annot) : Type0 = (ann RD = false ==> (forall s0 s1. fst (f s0) == fst (f s1))) /\ (ann WR = false ==> (forall s0. snd (f s0) == s0)) /\ (ann EXN = false ==> (forall s0. Some? (fst (f s0)))) let interp (l : list eff_label) : annot = fun lab -> mem lab 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
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LatticeSpec.fst" }
[ { "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 LatticeSpec.eff_label -> l2: Prims.list LatticeSpec.eff_label -> Prims.logical
Prims.Tot
[ "total" ]
[]
[ "Prims.list", "LatticeSpec.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
LatticeSpec.fst
LatticeSpec.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/LatticeSpec.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 22, "end_line": 38, "start_col": 0, "start_line": 37 }
module LatticeSpec open FStar.Tactics.V2 open FStar.List.Tot // 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 = | RD | WR | EXN type annot = eff_label -> bool // warning: if this is not annotated, `eqtype` is inferred // as its type and the effect definition fails for some reason. type state : Type = int type pre_t = state -> Type0 type post_t a = state -> option a -> state -> Type0 // this repr doesn't seem to work too well type repr0 (a:Type u#aa) (pre : pre_t) (post : post_t u#aa a) // #2074 : Type u#aa = s0:state{pre s0} -> Tot (r:(option a & state){post s0 (fst r) (snd r)}) let abides #a #pre #post (f : repr0 a pre post) (ann:annot) : Type0 = (ann RD = false ==> (forall s0 s1. fst (f s0) == fst (f s1))) /\ (ann WR = false ==> (forall s0. snd (f s0) == s0)) /\ (ann EXN = false ==> (forall s0. Some? (fst (f s0))))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LatticeSpec.fst" }
[ { "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 LatticeSpec.eff_label -> LatticeSpec.annot
Prims.Tot
[ "total" ]
[]
[ "Prims.list", "LatticeSpec.eff_label", "FStar.List.Tot.Base.mem", "Prims.bool", "LatticeSpec.annot" ]
[]
false
false
false
true
false
let interp (l: list eff_label) : annot =
fun lab -> mem lab l
false
LatticeSpec.fst
LatticeSpec.bind_post
val bind_post (a: Type) (pre1: pre_t) (post1: post_t a) (b: Type) (pre2: (a -> pre_t)) (post2: (a -> post_t b)) : post_t b
val bind_post (a: Type) (pre1: pre_t) (post1: post_t a) (b: Type) (pre2: (a -> pre_t)) (post2: (a -> post_t b)) : post_t b
let bind_post (a:Type) (pre1:pre_t) (post1:post_t a) (b:Type) (pre2:a -> pre_t) (post2:a -> post_t b) : post_t b = fun s0 z s2 -> (exists s1 y. post1 s0 (Some y) s1 /\ post2 y s1 z s2) \/ (post1 s0 None s2)
{ "file_name": "examples/layeredeffects/LatticeSpec.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 41, "end_line": 104, "start_col": 0, "start_line": 99 }
module LatticeSpec open FStar.Tactics.V2 open FStar.List.Tot // 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 = | RD | WR | EXN type annot = eff_label -> bool // warning: if this is not annotated, `eqtype` is inferred // as its type and the effect definition fails for some reason. type state : Type = int type pre_t = state -> Type0 type post_t a = state -> option a -> state -> Type0 // this repr doesn't seem to work too well type repr0 (a:Type u#aa) (pre : pre_t) (post : post_t u#aa a) // #2074 : Type u#aa = s0:state{pre s0} -> Tot (r:(option a & state){post s0 (fst r) (snd r)}) let abides #a #pre #post (f : repr0 a pre post) (ann:annot) : Type0 = (ann RD = false ==> (forall s0 s1. fst (f s0) == fst (f s1))) /\ (ann WR = false ==> (forall s0. snd (f s0) == s0)) /\ (ann EXN = false ==> (forall s0. Some? (fst (f s0)))) let interp (l : list eff_label) : annot = fun lab -> mem lab 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 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 type repr (a:Type u#aa) (pre : pre_t) (post : post_t u#aa a) // #2074 (labs : list u#0 eff_label) // #2074 : Type u#aa = r:(repr0 a pre post){abides r (interp labs)} let ann_le (ann1 ann2 : annot) : Type0 = forall x. ann1 x ==> ann2 x let return (a:Type u#aa) (x:a) : Tot (repr a (fun _ -> True) (fun s0 y s1 -> s0 == s1 /\ y == Some x) []) = // GM: Need to write it like this.. why? let r (s0:state) : Tot (r:(option a & state){snd r == s0 /\ fst r == Some x}) = (Some x, s0) in r unfold let bind_pre (a:Type) (pre1:pre_t) (post1:post_t a) (b:Type) (pre2:a -> pre_t) (post2:a -> post_t b) : pre_t = fun s0 -> pre1 s0 /\ (forall y s1. post1 s0 (Some y) s1 ==> pre2 y s1)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LatticeSpec.fst" }
[ { "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 -> pre1: LatticeSpec.pre_t -> post1: LatticeSpec.post_t a -> b: Type -> pre2: (_: a -> LatticeSpec.pre_t) -> post2: (_: a -> LatticeSpec.post_t b) -> LatticeSpec.post_t b
Prims.Tot
[ "total" ]
[]
[ "LatticeSpec.pre_t", "LatticeSpec.post_t", "LatticeSpec.state", "FStar.Pervasives.Native.option", "Prims.l_or", "Prims.l_Exists", "Prims.l_and", "FStar.Pervasives.Native.Some", "FStar.Pervasives.Native.None" ]
[]
false
false
false
true
false
let bind_post (a: Type) (pre1: pre_t) (post1: post_t a) (b: Type) (pre2: (a -> pre_t)) (post2: (a -> post_t b)) : post_t b =
fun s0 z s2 -> (exists s1 y. post1 s0 (Some y) s1 /\ post2 y s1 z s2) \/ (post1 s0 None s2)
false
Steel.ST.GenArraySwap.Proof.fst
Steel.ST.GenArraySwap.Proof.mk_bezout
val mk_bezout (n: pos) (l: nat) : Pure (bezout n l) (requires (l < n)) (ensures (fun _ -> True)) (decreases l)
val mk_bezout (n: pos) (l: nat) : Pure (bezout n l) (requires (l < n)) (ensures (fun _ -> True)) (decreases l)
let rec mk_bezout (n: pos) (l: nat) : Pure (bezout n l) (requires (l < n)) (ensures (fun _ -> True)) (decreases l) = if l = 0 then begin let d : pos = n in let q_n : nat = 1 in let q_l : nat = 0 in let u_n : int = 1 in let u_l : int = 0 in let res = { d = d; q_n = q_n; q_l = q_l; u_n = u_n; u_l = u_l; } in assert (eq2 #int n (d * q_n)) by (int_semiring ()); assert (eq2 #int 0 (d * q_l)) by (int_semiring ()); assert (eq2 #int d (n * 1 + 0 * res.u_l)) by (int_semiring ()); res end else begin let lpre = n % l in let ql = n / l in euclidean_division_definition n l; let bpre = mk_bezout l lpre in let d = bpre.d in let q_l = bpre.q_n in let qpre_lpre = bpre.q_l in let upre_l = bpre.u_n in let upre_lpre = bpre.u_l in let n_alt0 = l * ql + lpre in assert (n == n_alt0); let l_alt = d * q_l in let lpre_alt1 = d * qpre_lpre in let n_alt1 = l_alt * ql + lpre_alt1 in assert (n_alt1 == n); let q_n = q_l * ql + qpre_lpre in assert (eq2 #int n_alt1 (d * q_n)) by (int_semiring ()); let lpre_alt2 = n + - l * ql in assert (lpre_alt2 == lpre); let d_alt = l * upre_l + lpre_alt2 * upre_lpre in assert (d_alt == d); let u_l = upre_l + - ql * upre_lpre in assert (eq2 #int (n * upre_lpre + l * u_l) d_alt) by (int_semiring ()); let res = { d = d; q_n = q_n; q_l = q_l; u_n = upre_lpre; u_l = u_l; } in res end
{ "file_name": "lib/steel/Steel.ST.GenArraySwap.Proof.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 5, "end_line": 167, "start_col": 0, "start_line": 107 }
module Steel.ST.GenArraySwap.Proof open FStar.Math.Lemmas open FStar.Mul let lemma_mod_lt (a:int) (b:pos) : Lemma (let r = a % b in 0 <= r /\ r < b) [SMTPat (a % b)] = () let lemma_mul_nat_nat_is_nat (a b: nat) : Lemma (a * b >= 0) [SMTPat (a * b)] = () let lemma_pos_mul_pos_args (a: nat) (b: nat) : Lemma (requires (a * b > 0)) (ensures (a > 0 /\ b > 0 /\ a <= a * b /\ b <= a * b /\ a * b == b * a)) = () let lemma_div_nat (a: nat) (b: pos) : Lemma (a / b >= 0) [SMTPat (a / b)] = () let lemma_mult_reg_l (k: int) (x1 x2: int) : Lemma (requires ( k * x1 == k * x2 /\ k <> 0 )) (ensures ( x1 == x2 )) = () let lemma_bezout_one_zero (x1: int) (x2: nat) (y1 y2: int) : Lemma (requires ( x1 * x2 + y1 * y2 == 1 /\ y1 == 0 )) (ensures ( x1 == 1 /\ x2 == 1 )) = () #set-options "--z3cliopt smt.arith.nl=false" let int_semiring () = FStar.Tactics.CanonCommSemiring.int_semiring (); FStar.Tactics.trefl (); FStar.Tactics.qed () [@@erasable] noeq type bezout_t = { d: pos; q_n: nat; q_l: nat; u_n: int; u_l: int; } let bezout_prop' (n: nat) (l: nat) (d: pos) (q_n: nat) (q_l: nat) (u_n: int) (u_l: int) : Tot prop = n == d * q_n /\ l == d * q_l /\ d == n * u_n + l * u_l let bezout_prop (n: nat) (l: nat) (b: bezout_t) : Tot prop = bezout_prop' n l b.d b.q_n b.q_l b.u_n b.u_l let bezout (n: nat) (l: nat) : Tot Type = (b: bezout_t { bezout_prop n l b })
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.CanonCommSemiring.fst.checked", "FStar.Tactics.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Steel.ST.GenArraySwap.Proof.fst" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.GenArraySwap", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.GenArraySwap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
n: Prims.pos -> l: Prims.nat -> Prims.Pure (Steel.ST.GenArraySwap.Proof.bezout n l)
Prims.Pure
[ "" ]
[]
[ "Prims.pos", "Prims.nat", "Prims.op_Equality", "Prims.int", "Prims.unit", "FStar.Tactics.Effect.assert_by_tactic", "Prims.eq2", "Prims.op_Addition", "FStar.Mul.op_Star", "Steel.ST.GenArraySwap.Proof.__proj__Mkbezout_t__item__u_l", "Steel.ST.GenArraySwap.Proof.int_semiring", "Steel.ST.GenArraySwap.Proof.bezout_t", "Steel.ST.GenArraySwap.Proof.Mkbezout_t", "Prims.bool", "Prims.op_Minus", "Prims._assert", "Steel.ST.GenArraySwap.Proof.__proj__Mkbezout_t__item__u_n", "Steel.ST.GenArraySwap.Proof.__proj__Mkbezout_t__item__q_l", "Steel.ST.GenArraySwap.Proof.__proj__Mkbezout_t__item__q_n", "Steel.ST.GenArraySwap.Proof.__proj__Mkbezout_t__item__d", "Steel.ST.GenArraySwap.Proof.bezout", "Steel.ST.GenArraySwap.Proof.mk_bezout", "FStar.Math.Lemmas.euclidean_division_definition", "Prims.op_Division", "Prims.op_Modulus", "Prims.b2t", "Prims.op_LessThan", "Prims.l_True" ]
[ "recursion" ]
false
false
false
false
false
let rec mk_bezout (n: pos) (l: nat) : Pure (bezout n l) (requires (l < n)) (ensures (fun _ -> True)) (decreases l) =
if l = 0 then let d:pos = n in let q_n:nat = 1 in let q_l:nat = 0 in let u_n:int = 1 in let u_l:int = 0 in let res = { d = d; q_n = q_n; q_l = q_l; u_n = u_n; u_l = u_l } in FStar.Tactics.Effect.assert_by_tactic (eq2 #int n (d * q_n)) (fun _ -> (); (int_semiring ())); FStar.Tactics.Effect.assert_by_tactic (eq2 #int 0 (d * q_l)) (fun _ -> (); (int_semiring ())); FStar.Tactics.Effect.assert_by_tactic (eq2 #int d (n * 1 + 0 * res.u_l)) (fun _ -> (); (int_semiring ())); res else let lpre = n % l in let ql = n / l in euclidean_division_definition n l; let bpre = mk_bezout l lpre in let d = bpre.d in let q_l = bpre.q_n in let qpre_lpre = bpre.q_l in let upre_l = bpre.u_n in let upre_lpre = bpre.u_l in let n_alt0 = l * ql + lpre in assert (n == n_alt0); let l_alt = d * q_l in let lpre_alt1 = d * qpre_lpre in let n_alt1 = l_alt * ql + lpre_alt1 in assert (n_alt1 == n); let q_n = q_l * ql + qpre_lpre in FStar.Tactics.Effect.assert_by_tactic (eq2 #int n_alt1 (d * q_n)) (fun _ -> (); (int_semiring ())); let lpre_alt2 = n + - l * ql in assert (lpre_alt2 == lpre); let d_alt = l * upre_l + lpre_alt2 * upre_lpre in assert (d_alt == d); let u_l = upre_l + - ql * upre_lpre in FStar.Tactics.Effect.assert_by_tactic (eq2 #int (n * upre_lpre + l * u_l) d_alt) (fun _ -> (); (int_semiring ())); let res = { d = d; q_n = q_n; q_l = q_l; u_n = upre_lpre; u_l = u_l } in res
false
Hacl.Spec.P256.Qinv.fst
Hacl.Spec.P256.Qinv.lemma_pow_pow_mod_mul
val lemma_pow_pow_mod_mul: f:S.qelem -> a:nat -> b:nat -> c:nat -> Lemma (S.qmul (M.pow (M.pow f a % S.order) b % S.order) (M.pow f c % S.order) == M.pow f (a * b + c) % S.order)
val lemma_pow_pow_mod_mul: f:S.qelem -> a:nat -> b:nat -> c:nat -> Lemma (S.qmul (M.pow (M.pow f a % S.order) b % S.order) (M.pow f c % S.order) == M.pow f (a * b + c) % S.order)
let lemma_pow_pow_mod_mul f a b c = calc (==) { S.qmul (M.pow (M.pow f a % S.order) b % S.order) (M.pow f c % S.order); (==) { lemma_pow_pow_mod f a b } S.qmul (M.pow f (a * b) % S.order) (M.pow f c % S.order); (==) { lemma_pow_mod_mul f (a * b) c } M.pow f (a * b + c) % S.order; }
{ "file_name": "code/ecdsap256/Hacl.Spec.P256.Qinv.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 3, "end_line": 178, "start_col": 0, "start_line": 171 }
module Hacl.Spec.P256.Qinv open FStar.Mul module SE = Spec.Exponentiation module LE = Lib.Exponentiation module M = Lib.NatMod module S = Spec.P256 #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" let nat_mod_comm_monoid = M.mk_nat_mod_comm_monoid S.order let mk_to_nat_mod_comm_monoid : SE.to_comm_monoid S.qelem = { SE.a_spec = S.qelem; SE.comm_monoid = nat_mod_comm_monoid; SE.refl = (fun (x:S.qelem) -> x); } val one_mod : SE.one_st S.qelem mk_to_nat_mod_comm_monoid let one_mod _ = 1 val mul_mod : SE.mul_st S.qelem mk_to_nat_mod_comm_monoid let mul_mod x y = S.qmul x y val sqr_mod : SE.sqr_st S.qelem mk_to_nat_mod_comm_monoid let sqr_mod x = S.qmul x x let mk_nat_mod_concrete_ops : SE.concrete_ops S.qelem = { SE.to = mk_to_nat_mod_comm_monoid; SE.one = one_mod; SE.mul = mul_mod; SE.sqr = sqr_mod; } let qsquare_times (a:S.qelem) (b:nat) : S.qelem = SE.exp_pow2 mk_nat_mod_concrete_ops a b val qsquare_times_lemma: a:S.qelem -> b:nat -> Lemma (qsquare_times a b == M.pow a (pow2 b) % S.order) let qsquare_times_lemma a b = SE.exp_pow2_lemma mk_nat_mod_concrete_ops a b; LE.exp_pow2_lemma nat_mod_comm_monoid a b; assert (qsquare_times a b == LE.pow nat_mod_comm_monoid a (pow2 b)); M.lemma_pow_nat_mod_is_pow #S.order a (pow2 b) let qinv_x8_x128 (x6 x_11: S.qelem) : S.qelem = let x8 = S.qmul (qsquare_times x6 2) x_11 in let x16 = S.qmul (qsquare_times x8 8) x8 in let x32 = S.qmul (qsquare_times x16 16) x16 in let x96 = S.qmul (qsquare_times x32 64) x32 in let x128 = S.qmul (qsquare_times x96 32) x32 in x128 let qinv_x134_x153 (x128 x_11 x_111 x_1111 x_10101 x_101111: S.qelem) : S.qelem = let x134 = S.qmul (qsquare_times x128 6) x_101111 in let x139 = S.qmul (qsquare_times x134 5) x_111 in let x143 = S.qmul (qsquare_times x139 4) x_11 in let x148 = S.qmul (qsquare_times x143 5) x_1111 in let x153 = S.qmul (qsquare_times x148 5) x_10101 in x153 let qinv_x153_x177 (x153 x_101 x_111 x_101111: S.qelem) : S.qelem = let x157 = S.qmul (qsquare_times x153 4) x_101 in let x160 = S.qmul (qsquare_times x157 3) x_101 in let x163 = S.qmul (qsquare_times x160 3) x_101 in let x168 = S.qmul (qsquare_times x163 5) x_111 in let x177 = S.qmul (qsquare_times x168 9) x_101111 in x177 let qinv_x177_x210 (f x177 x_111 x_1111: S.qelem) : S.qelem = let x183 = S.qmul (qsquare_times x177 6) x_1111 in let x185 = S.qmul (qsquare_times x183 2) f in let x190 = S.qmul (qsquare_times x185 5) f in let x196 = S.qmul (qsquare_times x190 6) x_1111 in let x201 = S.qmul (qsquare_times x196 5) x_111 in let x205 = S.qmul (qsquare_times x201 4) x_111 in let x210 = S.qmul (qsquare_times x205 5) x_111 in x210 let qinv_x210_x240 (x210 x_11 x_101 x_101111: S.qelem) : S.qelem = let x215 = S.qmul (qsquare_times x210 5) x_101 in let x218 = S.qmul (qsquare_times x215 3) x_11 in let x228 = S.qmul (qsquare_times x218 10) x_101111 in let x230 = S.qmul (qsquare_times x228 2) x_11 in let x235 = S.qmul (qsquare_times x230 5) x_11 in let x240 = S.qmul (qsquare_times x235 5) x_11 in x240 let qinv_x240_x256 (f x240 x_1111 x_10101: S.qelem) : S.qelem = let x243 = S.qmul (qsquare_times x240 3) f in let x250 = S.qmul (qsquare_times x243 7) x_10101 in let x256 = S.qmul (qsquare_times x250 6) x_1111 in x256 let qinv_x8_x256 (f x6 x_11 x_101 x_111 x_1111 x_10101 x_101111 : S.qelem) : S.qelem = let x128 = qinv_x8_x128 x6 x_11 in let x153 = qinv_x134_x153 x128 x_11 x_111 x_1111 x_10101 x_101111 in let x177 = qinv_x153_x177 x153 x_101 x_111 x_101111 in let x210 = qinv_x177_x210 f x177 x_111 x_1111 in let x240 = qinv_x210_x240 x210 x_11 x_101 x_101111 in let x256 = qinv_x240_x256 f x240 x_1111 x_10101 in x256 (** The algorithm is taken from https://briansmith.org/ecc-inversion-addition-chains-01 *) val qinv: f:S.qelem -> S.qelem let qinv f = let x_10 = qsquare_times f 1 in // x_10 is used 3x let x_11 = S.qmul x_10 f in let x_101 = S.qmul x_10 x_11 in let x_111 = S.qmul x_10 x_101 in let x_1010 = qsquare_times x_101 1 in // x_1010 is used 2x let x_1111 = S.qmul x_101 x_1010 in let x_10101 = S.qmul (qsquare_times x_1010 1) f in let x_101010 = qsquare_times x_10101 1 in // x_101010 is used 2x let x_101111 = S.qmul x_101 x_101010 in let x6 = S.qmul x_10101 x_101010 in qinv_x8_x256 f x6 x_11 x_101 x_111 x_1111 x_10101 x_101111 // TODO: mv to lib/ val lemma_pow_mod_1: f:S.qelem -> Lemma (f == M.pow f 1 % S.order) let lemma_pow_mod_1 f = M.lemma_pow1 f; Math.Lemmas.small_mod f S.order; assert_norm (pow2 0 = 1); assert (f == M.pow f 1 % S.order) val lemma_pow_mod_mul: f:S.qelem -> a:nat -> b:nat -> Lemma (S.qmul (M.pow f a % S.order) (M.pow f b % S.order) == M.pow f (a + b) % S.order) let lemma_pow_mod_mul f a b = calc (==) { S.qmul (M.pow f a % S.order) (M.pow f b % S.order); (==) { Math.Lemmas.lemma_mod_mul_distr_l (M.pow f a) (M.pow f b % S.order) S.order; Math.Lemmas.lemma_mod_mul_distr_r (M.pow f a) (M.pow f b) S.order } M.pow f a * M.pow f b % S.order; (==) { M.lemma_pow_add f a b } M.pow f (a + b) % S.order; } val lemma_pow_pow_mod: f:S.qelem -> a:nat -> b:nat -> Lemma (M.pow (M.pow f a % S.order) b % S.order == M.pow f (a * b) % S.order) let lemma_pow_pow_mod f a b = calc (==) { M.pow (M.pow f a % S.order) b % S.order; (==) { M.lemma_pow_mod_base (M.pow f a) b S.order } M.pow (M.pow f a) b % S.order; (==) { M.lemma_pow_mul f a b } M.pow f (a * b) % S.order; } val lemma_pow_pow_mod_mul: f:S.qelem -> a:nat -> b:nat -> c:nat ->
{ "checked_file": "/", "dependencies": [ "Spec.P256.fst.checked", "Spec.Exponentiation.fsti.checked", "prims.fst.checked", "Lib.NatMod.fsti.checked", "Lib.Exponentiation.fsti.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.P256.Qinv.fst" }
[ { "abbrev": true, "full_module": "Spec.P256", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.NatMod", "short_module": "M" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "LE" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.P256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.P256", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
f: Spec.P256.PointOps.qelem -> a: Prims.nat -> b: Prims.nat -> c: Prims.nat -> FStar.Pervasives.Lemma (ensures Spec.P256.PointOps.qmul (Lib.NatMod.pow (Lib.NatMod.pow f a % Spec.P256.PointOps.order) b % Spec.P256.PointOps.order) (Lib.NatMod.pow f c % Spec.P256.PointOps.order) == Lib.NatMod.pow f (a * b + c) % Spec.P256.PointOps.order)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Spec.P256.PointOps.qelem", "Prims.nat", "FStar.Calc.calc_finish", "Prims.eq2", "Spec.P256.PointOps.qmul", "Prims.op_Modulus", "Lib.NatMod.pow", "Spec.P256.PointOps.order", "Prims.op_Addition", "FStar.Mul.op_Star", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "Prims.unit", "FStar.Calc.calc_step", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "Hacl.Spec.P256.Qinv.lemma_pow_pow_mod", "Prims.squash", "Hacl.Spec.P256.Qinv.lemma_pow_mod_mul" ]
[]
false
false
true
false
false
let lemma_pow_pow_mod_mul f a b c =
calc ( == ) { S.qmul (M.pow (M.pow f a % S.order) b % S.order) (M.pow f c % S.order); ( == ) { lemma_pow_pow_mod f a b } S.qmul (M.pow f (a * b) % S.order) (M.pow f c % S.order); ( == ) { lemma_pow_mod_mul f (a * b) c } M.pow f (a * b + c) % S.order; }
false
LatticeSpec.fst
LatticeSpec.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/LatticeSpec.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 51, "end_line": 144, "start_col": 0, "start_line": 144 }
module LatticeSpec open FStar.Tactics.V2 open FStar.List.Tot // 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 = | RD | WR | EXN type annot = eff_label -> bool // warning: if this is not annotated, `eqtype` is inferred // as its type and the effect definition fails for some reason. type state : Type = int type pre_t = state -> Type0 type post_t a = state -> option a -> state -> Type0 // this repr doesn't seem to work too well type repr0 (a:Type u#aa) (pre : pre_t) (post : post_t u#aa a) // #2074 : Type u#aa = s0:state{pre s0} -> Tot (r:(option a & state){post s0 (fst r) (snd r)}) let abides #a #pre #post (f : repr0 a pre post) (ann:annot) : Type0 = (ann RD = false ==> (forall s0 s1. fst (f s0) == fst (f s1))) /\ (ann WR = false ==> (forall s0. snd (f s0) == s0)) /\ (ann EXN = false ==> (forall s0. Some? (fst (f s0)))) let interp (l : list eff_label) : annot = fun lab -> mem lab 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 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 type repr (a:Type u#aa) (pre : pre_t) (post : post_t u#aa a) // #2074 (labs : list u#0 eff_label) // #2074 : Type u#aa = r:(repr0 a pre post){abides r (interp labs)} let ann_le (ann1 ann2 : annot) : Type0 = forall x. ann1 x ==> ann2 x let return (a:Type u#aa) (x:a) : Tot (repr a (fun _ -> True) (fun s0 y s1 -> s0 == s1 /\ y == Some x) []) = // GM: Need to write it like this.. why? let r (s0:state) : Tot (r:(option a & state){snd r == s0 /\ fst r == Some x}) = (Some x, s0) in r unfold let bind_pre (a:Type) (pre1:pre_t) (post1:post_t a) (b:Type) (pre2:a -> pre_t) (post2:a -> post_t b) : pre_t = fun s0 -> pre1 s0 /\ (forall y s1. post1 s0 (Some y) s1 ==> pre2 y s1) unfold let bind_post (a:Type) (pre1:pre_t) (post1:post_t a) (b:Type) (pre2:a -> pre_t) (post2:a -> post_t b) : post_t b = fun s0 z s2 -> (exists s1 y. post1 s0 (Some y) s1 /\ post2 y s1 z s2) \/ (post1 s0 None s2) let bind (a b : Type) pre1 post1 (labs1 : list eff_label) pre2 post2 (labs2 : list eff_label) (c : repr a pre1 post1 labs1) (f : (x:a -> repr b (pre2 x) (post2 x) labs2)) : Tot (repr b (bind_pre a pre1 post1 b pre2 post2) (bind_post a pre1 post1 b pre2 post2) (labs1@labs2)) = let pre = bind_pre a pre1 post1 b pre2 post2 in let post = bind_post a pre1 post1 b pre2 post2 in let r (s0:state{pre s0}) : Tot (r:(option b & state){post s0 (fst r) (snd r)}) = match c s0 with | Some x, s1 -> assert (post1 s0 (Some x) s1); assert (pre2 x s1); f x s1 | None, s1 -> None, s1 in r let subcomp (a:Type) (pre1 : pre_t) (post1 : post_t a) (labs1 : list eff_label) (pre2 : pre_t) (post2 : post_t a) (labs2 : list eff_label) (f : repr a pre1 post1 labs1) : Pure (repr a pre2 post2 labs2) (requires ((forall s0. pre2 s0 ==> pre1 s0) /\ (forall s0 r s1. post1 s0 r s1 ==> post2 s0 r s1) /\ sublist labs1 labs2)) (ensures (fun _ -> True)) = f
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LatticeSpec.fst" }
[ { "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.ST.GenArraySwap.Proof.fst
Steel.ST.GenArraySwap.Proof.gauss
val gauss (n l: pos) (b: bezout n l) (kl kn: int) : Ghost int (requires (kl * l == kn * n)) (ensures (fun k -> kl == k * b.q_n))
val gauss (n l: pos) (b: bezout n l) (kl kn: int) : Ghost int (requires (kl * l == kn * n)) (ensures (fun k -> kl == k * b.q_n))
let gauss (n: pos) (l: pos) // necessary here (b: bezout n l) (kl kn: int) : Ghost int (requires ( kl * l == kn * n )) (ensures (fun k -> kl == k * b.q_n )) = assert ((b.d * b.q_n) * b.u_n + (b.d * b.q_l) * b.u_l == b.d * (b.u_n * b.q_n + b.u_l * b.q_l)) by (int_semiring ()); assert (b.d == b.d * 1) by (int_semiring ()); assert (b.d * (b.u_n * b.q_n + b.u_l * b.q_l) == b.d * 1); lemma_mult_reg_l b.d (b.u_n * b.q_n + b.u_l * b.q_l) 1; assert (b.u_n * b.q_n + b.u_l * b.q_l == 1); if b.u_l = 0 then begin lemma_bezout_one_zero b.u_n b.q_n b.u_l b.q_l; assert (b.q_n == 1); assert (kl * 1 == kl) by (int_semiring ()); kl end else begin assert (kl * (b.d * b.q_l) == kn * (b.d * b.q_n)); assert (kl * (b.d * b.q_l) == b.d * (kl * b.q_l)) by (int_semiring ()); assert (kn * (b.d * b.q_n) == b.d * (kn * b.q_n)) by (int_semiring ()); assert (b.d * (kl * b.q_l) == b.d * (kn * b.q_n)); lemma_mult_reg_l b.d (kl * b.q_l) (kn * b.q_n); assert (kl * b.q_l == kn * b.q_n); assert (b.u_l * (kl * b.q_l) == b.u_l * (kn * b.q_n)); assert (b.u_l * (kl * b.q_l) == kl * (b.u_l * b.q_l)) by (int_semiring ()); assert (b.u_l * (kn * b.q_n) == (kn * b.u_l) * b.q_n) by (int_semiring ()); assert (kl * (b.u_l * b.q_l) == (kn * b.u_l) * b.q_n); assert (kl * (1 + - (b.u_n * b.q_n)) == kl + - kl * b.u_n * b.q_n) by (int_semiring ()); assert (kl * b.u_n * b.q_n + (kn * b.u_l) * b.q_n == (kn * b.u_l + kl * b.u_n) * b.q_n) by (int_semiring ()); kn * b.u_l + kl * b.u_n end
{ "file_name": "lib/steel/Steel.ST.GenArraySwap.Proof.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 5, "end_line": 454, "start_col": 0, "start_line": 417 }
module Steel.ST.GenArraySwap.Proof open FStar.Math.Lemmas open FStar.Mul let lemma_mod_lt (a:int) (b:pos) : Lemma (let r = a % b in 0 <= r /\ r < b) [SMTPat (a % b)] = () let lemma_mul_nat_nat_is_nat (a b: nat) : Lemma (a * b >= 0) [SMTPat (a * b)] = () let lemma_pos_mul_pos_args (a: nat) (b: nat) : Lemma (requires (a * b > 0)) (ensures (a > 0 /\ b > 0 /\ a <= a * b /\ b <= a * b /\ a * b == b * a)) = () let lemma_div_nat (a: nat) (b: pos) : Lemma (a / b >= 0) [SMTPat (a / b)] = () let lemma_mult_reg_l (k: int) (x1 x2: int) : Lemma (requires ( k * x1 == k * x2 /\ k <> 0 )) (ensures ( x1 == x2 )) = () let lemma_bezout_one_zero (x1: int) (x2: nat) (y1 y2: int) : Lemma (requires ( x1 * x2 + y1 * y2 == 1 /\ y1 == 0 )) (ensures ( x1 == 1 /\ x2 == 1 )) = () #set-options "--z3cliopt smt.arith.nl=false" let int_semiring () = FStar.Tactics.CanonCommSemiring.int_semiring (); FStar.Tactics.trefl (); FStar.Tactics.qed () [@@erasable] noeq type bezout_t = { d: pos; q_n: nat; q_l: nat; u_n: int; u_l: int; } let bezout_prop' (n: nat) (l: nat) (d: pos) (q_n: nat) (q_l: nat) (u_n: int) (u_l: int) : Tot prop = n == d * q_n /\ l == d * q_l /\ d == n * u_n + l * u_l let bezout_prop (n: nat) (l: nat) (b: bezout_t) : Tot prop = bezout_prop' n l b.d b.q_n b.q_l b.u_n b.u_l let bezout (n: nat) (l: nat) : Tot Type = (b: bezout_t { bezout_prop n l b }) #restart-solver let rec mk_bezout (n: pos) (l: nat) : Pure (bezout n l) (requires (l < n)) (ensures (fun _ -> True)) (decreases l) = if l = 0 then begin let d : pos = n in let q_n : nat = 1 in let q_l : nat = 0 in let u_n : int = 1 in let u_l : int = 0 in let res = { d = d; q_n = q_n; q_l = q_l; u_n = u_n; u_l = u_l; } in assert (eq2 #int n (d * q_n)) by (int_semiring ()); assert (eq2 #int 0 (d * q_l)) by (int_semiring ()); assert (eq2 #int d (n * 1 + 0 * res.u_l)) by (int_semiring ()); res end else begin let lpre = n % l in let ql = n / l in euclidean_division_definition n l; let bpre = mk_bezout l lpre in let d = bpre.d in let q_l = bpre.q_n in let qpre_lpre = bpre.q_l in let upre_l = bpre.u_n in let upre_lpre = bpre.u_l in let n_alt0 = l * ql + lpre in assert (n == n_alt0); let l_alt = d * q_l in let lpre_alt1 = d * qpre_lpre in let n_alt1 = l_alt * ql + lpre_alt1 in assert (n_alt1 == n); let q_n = q_l * ql + qpre_lpre in assert (eq2 #int n_alt1 (d * q_n)) by (int_semiring ()); let lpre_alt2 = n + - l * ql in assert (lpre_alt2 == lpre); let d_alt = l * upre_l + lpre_alt2 * upre_lpre in assert (d_alt == d); let u_l = upre_l + - ql * upre_lpre in assert (eq2 #int (n * upre_lpre + l * u_l) d_alt) by (int_semiring ()); let res = { d = d; q_n = q_n; q_l = q_l; u_n = upre_lpre; u_l = u_l; } in res end let bezout_q_eq (n: nat) (l: nat) (bz: bezout n l) : Lemma (bz.q_n == n / bz.d) [SMTPat (bezout_prop n l bz); SMTPat bz.q_n] = cancel_mul_div bz.q_n bz.d let rec iter_fun (#t: Type) (f: (t -> GTot t)) (n: nat) (x: t) : GTot t (decreases n) = if n = 0 then x else iter_fun f (n - 1) (f x) let nat_up_to (n: nat) : Tot Type = (i: nat { i < n }) let jump (n: pos) (l: nat) (x: nat_up_to n) : GTot (nat_up_to n) = (x + l) % n #restart-solver let jump_mod_d (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Lemma (jump n l x % b.d == x % b.d) = let x' = jump n l x in let x'q = (x + l) / n in euclidean_division_definition (x + l) n; let l_alt = b.d * b.q_l in assert (l_alt == l); let n_alt = b.d * b.q_n in assert (n_alt == n); let x'_alt = x + l_alt + - x'q * n_alt in assert (x'_alt == x'); let qx = b.q_l + - x'q * b.q_n in assert (eq2 #int x'_alt (x + qx * b.d)) by (int_semiring ()); lemma_mod_plus x qx b.d let rec jump_iter_mod_d (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) (k: nat) : Lemma (ensures (iter_fun #(nat_up_to n) (jump n l) k x % b.d == x % b.d)) (decreases k) = if k = 0 then () else begin jump_mod_d n l b x; jump_iter_mod_d n l b (jump n l x) (k - 1) end (* Coverage *) let rec jump_iter (n: pos) (l: nat) (x: nat_up_to n) (k: nat) : Lemma (ensures (iter_fun #(nat_up_to n) (jump n l) k x == (x + k * l) % n)) (decreases k) = if k = 0 then begin assert (eq2 #int (x + 0 * l) x) by (int_semiring ()); small_mod x n end else begin let k' = k - 1 in assert (eq2 #int (x + (k' + 1) * l) ((x + l) + k' * l)) by (int_semiring ()); jump_iter n l ((x + l) % n) k'; lemma_mod_add_distr (k' * l) (x + l) n end let bezout_pos_le (n: pos) (l: nat) (b: bezout n l) : Lemma (b.d <= n /\ b.q_n > 0) [SMTPat (bezout_prop n l b)] = lemma_pos_mul_pos_args b.q_n b.d #restart-solver [@@"opaque_to_smt"] irreducible let jump_coverage (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Ghost nat (requires True) (ensures (fun k -> x == iter_fun (jump n l) k (x % b.d) )) = let i = x % b.d in let qx = x / b.d in euclidean_division_definition x b.d; let k1 = qx * b.u_l in let m = qx * b.u_n in assert (eq2 #int (qx * (n * b.u_n + l * b.u_l) + i) (i + k1 * l + m * n)) by (int_semiring ()); assert (x == i + k1 * l + m * n); small_mod x n; lemma_mod_plus (i + k1 * l) m n; assert (x == (i + k1 * l) % n); let k = k1 % n in let qk = k1 / n in euclidean_division_definition k1 n; assert (i + (qk * n + k) * l == i + k * l + (qk * l) * n) by (int_semiring ()); lemma_mod_plus (i + k * l) (qk * l) n; assert (eq2 #int x ((i + k * l) % n)); jump_iter n l i k; k [@@"opaque_to_smt"] irreducible let rec minimal_exists' (p: (nat -> GTot bool)) (n: nat) (i: nat) : Ghost nat (requires ( p n == true /\ i <= n /\ (forall (j: nat) . j < i ==> p j == false) )) (ensures (fun k -> p k == true /\ (forall (j: nat) . j < k ==> p j == false) )) (decreases (n - i)) = if p i then i else minimal_exists' p n (i + 1) [@@"opaque_to_smt"] irreducible let minimal_exists (p: (nat -> GTot bool)) (n: nat) : Ghost nat (requires ( p n == true )) (ensures (fun k -> p k == true /\ (forall (j: nat) . j < k ==> p j == false) )) = minimal_exists' p n 0 [@@"opaque_to_smt"] irreducible let jump_coverage_strong (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Ghost nat (requires True) (ensures (fun k -> x == iter_fun (jump n l) k (x % b.d) /\ (forall (k': nat) . k' < k ==> (~ (x == iter_fun (jump n l) k' (x % b.d)))) )) = let k' = jump_coverage n l b x in minimal_exists (fun k -> x = iter_fun (jump n l) k (x % b.d)) k' #restart-solver let jump_iter_mod_q (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) (k: nat) : Lemma (ensures ( b.q_n > 0 /\ iter_fun (jump n l) (k % b.q_n) x == iter_fun (jump n l) k x )) = assert (b.q_n > 0); let k' = k % b.q_n in let qk = k / b.q_n in euclidean_division_definition k b.q_n; jump_iter n l x k'; jump_iter n l x k; assert (eq2 #int (x + (qk * b.q_n + k') * (b.d * b.q_l)) (x + k' * (b.d * b.q_l) + (qk * b.q_l) * (b.d * b.q_n))) by (int_semiring ()); assert (x + k * l == x + k' * l + (qk * b.q_l) * n); lemma_mod_plus (x + k' * l) (qk * b.q_l) n let jump_coverage_strong_bound (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Lemma (b.q_n > 0 /\ jump_coverage_strong n l b x < b.q_n ) [SMTPat (jump_coverage_strong n l b x)] = let k = jump_coverage_strong n l b x in jump_iter_mod_q n l b (x % b.d) k #restart-solver [@@"opaque_to_smt"] irreducible let mod_eq_elim (n: pos) (x1 x2: int) : Ghost int (requires (x1 % n == x2 % n)) (ensures (fun k -> x1 - x2 == k * n)) = euclidean_division_definition x1 n; euclidean_division_definition x2 n; let q1 = x1 / n in let q2 = x2 / n in let k = q1 + - q2 in let r = x1 % n in assert (q1 * n + r + - (q2 * n + r) == k * n) by (int_semiring ()); k let mod_eq_intro (n: pos) (x1 x2: int) (k: int) : Lemma (requires (x1 - x2 == k * n)) (ensures (x1 % n == x2 % n)) = lemma_mod_plus x2 k n #restart-solver [@@"opaque_to_smt"]
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.CanonCommSemiring.fst.checked", "FStar.Tactics.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Steel.ST.GenArraySwap.Proof.fst" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.GenArraySwap", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.GenArraySwap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
n: Prims.pos -> l: Prims.pos -> b: Steel.ST.GenArraySwap.Proof.bezout n l -> kl: Prims.int -> kn: Prims.int -> Prims.Ghost Prims.int
Prims.Ghost
[]
[]
[ "Prims.pos", "Steel.ST.GenArraySwap.Proof.bezout", "Prims.int", "Prims.op_Equality", "Steel.ST.GenArraySwap.Proof.__proj__Mkbezout_t__item__u_l", "Prims.unit", "FStar.Tactics.Effect.assert_by_tactic", "Prims.eq2", "FStar.Mul.op_Star", "Steel.ST.GenArraySwap.Proof.int_semiring", "Prims._assert", "Steel.ST.GenArraySwap.Proof.__proj__Mkbezout_t__item__q_n", "Steel.ST.GenArraySwap.Proof.lemma_bezout_one_zero", "Steel.ST.GenArraySwap.Proof.__proj__Mkbezout_t__item__u_n", "Steel.ST.GenArraySwap.Proof.__proj__Mkbezout_t__item__q_l", "Prims.bool", "Prims.op_Addition", "Prims.op_Minus", "Steel.ST.GenArraySwap.Proof.lemma_mult_reg_l", "Steel.ST.GenArraySwap.Proof.__proj__Mkbezout_t__item__d" ]
[]
false
false
false
false
false
let gauss (n l: pos) (b: bezout n l) (kl kn: int) : Ghost int (requires (kl * l == kn * n)) (ensures (fun k -> kl == k * b.q_n)) =
FStar.Tactics.Effect.assert_by_tactic ((b.d * b.q_n) * b.u_n + (b.d * b.q_l) * b.u_l == b.d * (b.u_n * b.q_n + b.u_l * b.q_l)) (fun _ -> (); (int_semiring ())); FStar.Tactics.Effect.assert_by_tactic (b.d == b.d * 1) (fun _ -> (); (int_semiring ())); assert (b.d * (b.u_n * b.q_n + b.u_l * b.q_l) == b.d * 1); lemma_mult_reg_l b.d (b.u_n * b.q_n + b.u_l * b.q_l) 1; assert (b.u_n * b.q_n + b.u_l * b.q_l == 1); if b.u_l = 0 then (lemma_bezout_one_zero b.u_n b.q_n b.u_l b.q_l; assert (b.q_n == 1); FStar.Tactics.Effect.assert_by_tactic (kl * 1 == kl) (fun _ -> (); (int_semiring ())); kl) else (assert (kl * (b.d * b.q_l) == kn * (b.d * b.q_n)); FStar.Tactics.Effect.assert_by_tactic (kl * (b.d * b.q_l) == b.d * (kl * b.q_l)) (fun _ -> (); (int_semiring ())); FStar.Tactics.Effect.assert_by_tactic (kn * (b.d * b.q_n) == b.d * (kn * b.q_n)) (fun _ -> (); (int_semiring ())); assert (b.d * (kl * b.q_l) == b.d * (kn * b.q_n)); lemma_mult_reg_l b.d (kl * b.q_l) (kn * b.q_n); assert (kl * b.q_l == kn * b.q_n); assert (b.u_l * (kl * b.q_l) == b.u_l * (kn * b.q_n)); FStar.Tactics.Effect.assert_by_tactic (b.u_l * (kl * b.q_l) == kl * (b.u_l * b.q_l)) (fun _ -> (); (int_semiring ())); FStar.Tactics.Effect.assert_by_tactic (b.u_l * (kn * b.q_n) == (kn * b.u_l) * b.q_n) (fun _ -> (); (int_semiring ())); assert (kl * (b.u_l * b.q_l) == (kn * b.u_l) * b.q_n); FStar.Tactics.Effect.assert_by_tactic (kl * (1 + - (b.u_n * b.q_n)) == kl + - (kl * b.u_n) * b.q_n) (fun _ -> (); (int_semiring ())); FStar.Tactics.Effect.assert_by_tactic ((kl * b.u_n) * b.q_n + (kn * b.u_l) * b.q_n == (kn * b.u_l + kl * b.u_n) * b.q_n) (fun _ -> (); (int_semiring ())); kn * b.u_l + kl * b.u_n)
false
LatticeSpec.fst
LatticeSpec.sp
val sp (#a: _) (wp: pure_wp a) : pure_post a
val sp (#a: _) (wp: pure_wp a) : pure_post a
let sp #a (wp : pure_wp a) : pure_post a = fun x -> ~ (wp (fun y -> ~(x == y)))
{ "file_name": "examples/layeredeffects/LatticeSpec.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 38, "end_line": 172, "start_col": 0, "start_line": 171 }
module LatticeSpec open FStar.Tactics.V2 open FStar.List.Tot // 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 = | RD | WR | EXN type annot = eff_label -> bool // warning: if this is not annotated, `eqtype` is inferred // as its type and the effect definition fails for some reason. type state : Type = int type pre_t = state -> Type0 type post_t a = state -> option a -> state -> Type0 // this repr doesn't seem to work too well type repr0 (a:Type u#aa) (pre : pre_t) (post : post_t u#aa a) // #2074 : Type u#aa = s0:state{pre s0} -> Tot (r:(option a & state){post s0 (fst r) (snd r)}) let abides #a #pre #post (f : repr0 a pre post) (ann:annot) : Type0 = (ann RD = false ==> (forall s0 s1. fst (f s0) == fst (f s1))) /\ (ann WR = false ==> (forall s0. snd (f s0) == s0)) /\ (ann EXN = false ==> (forall s0. Some? (fst (f s0)))) let interp (l : list eff_label) : annot = fun lab -> mem lab 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 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 type repr (a:Type u#aa) (pre : pre_t) (post : post_t u#aa a) // #2074 (labs : list u#0 eff_label) // #2074 : Type u#aa = r:(repr0 a pre post){abides r (interp labs)} let ann_le (ann1 ann2 : annot) : Type0 = forall x. ann1 x ==> ann2 x let return (a:Type u#aa) (x:a) : Tot (repr a (fun _ -> True) (fun s0 y s1 -> s0 == s1 /\ y == Some x) []) = // GM: Need to write it like this.. why? let r (s0:state) : Tot (r:(option a & state){snd r == s0 /\ fst r == Some x}) = (Some x, s0) in r unfold let bind_pre (a:Type) (pre1:pre_t) (post1:post_t a) (b:Type) (pre2:a -> pre_t) (post2:a -> post_t b) : pre_t = fun s0 -> pre1 s0 /\ (forall y s1. post1 s0 (Some y) s1 ==> pre2 y s1) unfold let bind_post (a:Type) (pre1:pre_t) (post1:post_t a) (b:Type) (pre2:a -> pre_t) (post2:a -> post_t b) : post_t b = fun s0 z s2 -> (exists s1 y. post1 s0 (Some y) s1 /\ post2 y s1 z s2) \/ (post1 s0 None s2) let bind (a b : Type) pre1 post1 (labs1 : list eff_label) pre2 post2 (labs2 : list eff_label) (c : repr a pre1 post1 labs1) (f : (x:a -> repr b (pre2 x) (post2 x) labs2)) : Tot (repr b (bind_pre a pre1 post1 b pre2 post2) (bind_post a pre1 post1 b pre2 post2) (labs1@labs2)) = let pre = bind_pre a pre1 post1 b pre2 post2 in let post = bind_post a pre1 post1 b pre2 post2 in let r (s0:state{pre s0}) : Tot (r:(option b & state){post s0 (fst r) (snd r)}) = match c s0 with | Some x, s1 -> assert (post1 s0 (Some x) s1); assert (pre2 x s1); f x s1 | None, s1 -> None, s1 in r let subcomp (a:Type) (pre1 : pre_t) (post1 : post_t a) (labs1 : list eff_label) (pre2 : pre_t) (post2 : post_t a) (labs2 : list eff_label) (f : repr a pre1 post1 labs1) : Pure (repr a pre2 post2 labs2) (requires ((forall s0. pre2 s0 ==> pre1 s0) /\ (forall s0 r s1. post1 s0 r s1 ==> post2 s0 r s1) /\ sublist labs1 labs2)) (ensures (fun _ -> True)) = f unfold let ite (p q r : Type0) = (p ==> q) /\ ((~p) ==> r) let if_then_else (a : Type) (pre1 : pre_t) (post1 : post_t a) (labs1 : list eff_label) (pre2 : pre_t) (post2 : post_t a) (labs2 : list eff_label) (f : repr a pre1 post1 labs1) (g : repr a pre2 post2 labs2) (b : bool) : Type = repr a (fun s0 -> ite b (pre1 s0) (pre2 s0)) (fun s0 y s1 -> ite b (post1 s0 y s1) (post2 s0 y s1)) (labs1@labs2) total // need this for catch!! reifiable reflectable effect { EFF (a:Type) (_:pre_t) (_:post_t a) (_:list eff_label) with {repr; return; bind; subcomp; if_then_else} }
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LatticeSpec.fst" }
[ { "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
wp: Prims.pure_wp a -> Prims.pure_post a
Prims.Tot
[ "total" ]
[]
[ "Prims.pure_wp", "Prims.l_True", "Prims.l_not", "Prims.eq2", "Prims.pure_post" ]
[]
false
false
false
true
false
let sp #a (wp: pure_wp a) : pure_post a =
fun x -> ~(wp (fun y -> ~(x == y)))
false
LatticeSpec.fst
LatticeSpec.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/LatticeSpec.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 37, "end_line": 62, "start_col": 0, "start_line": 56 }
module LatticeSpec open FStar.Tactics.V2 open FStar.List.Tot // 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 = | RD | WR | EXN type annot = eff_label -> bool // warning: if this is not annotated, `eqtype` is inferred // as its type and the effect definition fails for some reason. type state : Type = int type pre_t = state -> Type0 type post_t a = state -> option a -> state -> Type0 // this repr doesn't seem to work too well type repr0 (a:Type u#aa) (pre : pre_t) (post : post_t u#aa a) // #2074 : Type u#aa = s0:state{pre s0} -> Tot (r:(option a & state){post s0 (fst r) (snd r)}) let abides #a #pre #post (f : repr0 a pre post) (ann:annot) : Type0 = (ann RD = false ==> (forall s0 s1. fst (f s0) == fst (f s1))) /\ (ann WR = false ==> (forall s0. snd (f s0) == s0)) /\ (ann EXN = false ==> (forall s0. Some? (fst (f s0)))) let interp (l : list eff_label) : annot = fun lab -> mem lab 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 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.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LatticeSpec.fst" }
[ { "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 LatticeSpec.eff_label -> l2: Prims.list LatticeSpec.eff_label -> l: LatticeSpec.eff_label -> FStar.Pervasives.Lemma (requires LatticeSpec.sublist l1 l2) (ensures LatticeSpec.interp l1 l ==> LatticeSpec.interp l2 l) [SMTPat (LatticeSpec.interp l1 l); SMTPat (LatticeSpec.sublist l1 l2)]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.list", "LatticeSpec.eff_label", "LatticeSpec.interp_sublist", "Prims.unit", "LatticeSpec.sublist", "Prims.squash", "Prims.l_imp", "Prims.b2t", "LatticeSpec.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
LatticeSpec.fst
LatticeSpec.return
val return (a: Type u#aa) (x: a) : Tot (repr a (fun _ -> True) (fun s0 y s1 -> s0 == s1 /\ y == Some x) [])
val return (a: Type u#aa) (x: a) : Tot (repr a (fun _ -> True) (fun s0 y s1 -> s0 == s1 /\ y == Some x) [])
let return (a:Type u#aa) (x:a) : Tot (repr a (fun _ -> True) (fun s0 y s1 -> s0 == s1 /\ y == Some x) []) = // GM: Need to write it like this.. why? let r (s0:state) : Tot (r:(option a & state){snd r == s0 /\ fst r == Some x}) = (Some x, s0) in r
{ "file_name": "examples/layeredeffects/LatticeSpec.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 3, "end_line": 89, "start_col": 0, "start_line": 84 }
module LatticeSpec open FStar.Tactics.V2 open FStar.List.Tot // 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 = | RD | WR | EXN type annot = eff_label -> bool // warning: if this is not annotated, `eqtype` is inferred // as its type and the effect definition fails for some reason. type state : Type = int type pre_t = state -> Type0 type post_t a = state -> option a -> state -> Type0 // this repr doesn't seem to work too well type repr0 (a:Type u#aa) (pre : pre_t) (post : post_t u#aa a) // #2074 : Type u#aa = s0:state{pre s0} -> Tot (r:(option a & state){post s0 (fst r) (snd r)}) let abides #a #pre #post (f : repr0 a pre post) (ann:annot) : Type0 = (ann RD = false ==> (forall s0 s1. fst (f s0) == fst (f s1))) /\ (ann WR = false ==> (forall s0. snd (f s0) == s0)) /\ (ann EXN = false ==> (forall s0. Some? (fst (f s0)))) let interp (l : list eff_label) : annot = fun lab -> mem lab 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 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 type repr (a:Type u#aa) (pre : pre_t) (post : post_t u#aa a) // #2074 (labs : list u#0 eff_label) // #2074 : Type u#aa = r:(repr0 a pre post){abides r (interp labs)} let ann_le (ann1 ann2 : annot) : Type0 = forall x. ann1 x ==> ann2 x
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LatticeSpec.fst" }
[ { "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 -> LatticeSpec.repr a (fun _ -> Prims.l_True) (fun s0 y s1 -> s0 == s1 /\ y == FStar.Pervasives.Native.Some x) []
Prims.Tot
[ "total" ]
[]
[ "LatticeSpec.state", "FStar.Pervasives.Native.tuple2", "FStar.Pervasives.Native.option", "Prims.l_and", "Prims.eq2", "FStar.Pervasives.Native.snd", "FStar.Pervasives.Native.fst", "FStar.Pervasives.Native.Some", "FStar.Pervasives.Native.Mktuple2", "LatticeSpec.repr", "Prims.l_True", "Prims.Nil", "LatticeSpec.eff_label" ]
[]
false
false
false
false
false
let return (a: Type u#aa) (x: a) : Tot (repr a (fun _ -> True) (fun s0 y s1 -> s0 == s1 /\ y == Some x) []) =
let r (s0: state) : Tot (r: (option a & state){snd r == s0 /\ fst r == Some x}) = (Some x, s0) in r
false
LatticeSpec.fst
LatticeSpec.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/LatticeSpec.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 31, "end_line": 71, "start_col": 0, "start_line": 64 }
module LatticeSpec open FStar.Tactics.V2 open FStar.List.Tot // 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 = | RD | WR | EXN type annot = eff_label -> bool // warning: if this is not annotated, `eqtype` is inferred // as its type and the effect definition fails for some reason. type state : Type = int type pre_t = state -> Type0 type post_t a = state -> option a -> state -> Type0 // this repr doesn't seem to work too well type repr0 (a:Type u#aa) (pre : pre_t) (post : post_t u#aa a) // #2074 : Type u#aa = s0:state{pre s0} -> Tot (r:(option a & state){post s0 (fst r) (snd r)}) let abides #a #pre #post (f : repr0 a pre post) (ann:annot) : Type0 = (ann RD = false ==> (forall s0 s1. fst (f s0) == fst (f s1))) /\ (ann WR = false ==> (forall s0. snd (f s0) == s0)) /\ (ann EXN = false ==> (forall s0. Some? (fst (f s0)))) let interp (l : list eff_label) : annot = fun lab -> mem lab 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 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.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LatticeSpec.fst" }
[ { "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 LatticeSpec.eff_label -> l2: Prims.list LatticeSpec.eff_label -> FStar.Pervasives.Lemma (ensures LatticeSpec.sublist l1 (l1 @ l2) /\ LatticeSpec.sublist l2 (l1 @ l2)) [ SMTPatOr [ [SMTPat (LatticeSpec.sublist l1 (l1 @ l2))]; [SMTPat (LatticeSpec.sublist l2 (l1 @ l2))] ] ]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.list", "LatticeSpec.eff_label", "LatticeSpec.sublist_at", "Prims.unit", "Prims.l_True", "Prims.squash", "Prims.l_and", "LatticeSpec.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
LatticeSpec.fst
LatticeSpec.post_of_wp
val post_of_wp (#a: _) (wp: pure_wp a) : post_t a
val post_of_wp (#a: _) (wp: pure_wp a) : post_t a
let post_of_wp #a (wp : pure_wp a) : post_t a = fun s0 r s1 -> s0 == s1 /\ Some? r /\ sp wp (Some?.v r)
{ "file_name": "examples/layeredeffects/LatticeSpec.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 57, "end_line": 176, "start_col": 0, "start_line": 175 }
module LatticeSpec open FStar.Tactics.V2 open FStar.List.Tot // 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 = | RD | WR | EXN type annot = eff_label -> bool // warning: if this is not annotated, `eqtype` is inferred // as its type and the effect definition fails for some reason. type state : Type = int type pre_t = state -> Type0 type post_t a = state -> option a -> state -> Type0 // this repr doesn't seem to work too well type repr0 (a:Type u#aa) (pre : pre_t) (post : post_t u#aa a) // #2074 : Type u#aa = s0:state{pre s0} -> Tot (r:(option a & state){post s0 (fst r) (snd r)}) let abides #a #pre #post (f : repr0 a pre post) (ann:annot) : Type0 = (ann RD = false ==> (forall s0 s1. fst (f s0) == fst (f s1))) /\ (ann WR = false ==> (forall s0. snd (f s0) == s0)) /\ (ann EXN = false ==> (forall s0. Some? (fst (f s0)))) let interp (l : list eff_label) : annot = fun lab -> mem lab 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 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 type repr (a:Type u#aa) (pre : pre_t) (post : post_t u#aa a) // #2074 (labs : list u#0 eff_label) // #2074 : Type u#aa = r:(repr0 a pre post){abides r (interp labs)} let ann_le (ann1 ann2 : annot) : Type0 = forall x. ann1 x ==> ann2 x let return (a:Type u#aa) (x:a) : Tot (repr a (fun _ -> True) (fun s0 y s1 -> s0 == s1 /\ y == Some x) []) = // GM: Need to write it like this.. why? let r (s0:state) : Tot (r:(option a & state){snd r == s0 /\ fst r == Some x}) = (Some x, s0) in r unfold let bind_pre (a:Type) (pre1:pre_t) (post1:post_t a) (b:Type) (pre2:a -> pre_t) (post2:a -> post_t b) : pre_t = fun s0 -> pre1 s0 /\ (forall y s1. post1 s0 (Some y) s1 ==> pre2 y s1) unfold let bind_post (a:Type) (pre1:pre_t) (post1:post_t a) (b:Type) (pre2:a -> pre_t) (post2:a -> post_t b) : post_t b = fun s0 z s2 -> (exists s1 y. post1 s0 (Some y) s1 /\ post2 y s1 z s2) \/ (post1 s0 None s2) let bind (a b : Type) pre1 post1 (labs1 : list eff_label) pre2 post2 (labs2 : list eff_label) (c : repr a pre1 post1 labs1) (f : (x:a -> repr b (pre2 x) (post2 x) labs2)) : Tot (repr b (bind_pre a pre1 post1 b pre2 post2) (bind_post a pre1 post1 b pre2 post2) (labs1@labs2)) = let pre = bind_pre a pre1 post1 b pre2 post2 in let post = bind_post a pre1 post1 b pre2 post2 in let r (s0:state{pre s0}) : Tot (r:(option b & state){post s0 (fst r) (snd r)}) = match c s0 with | Some x, s1 -> assert (post1 s0 (Some x) s1); assert (pre2 x s1); f x s1 | None, s1 -> None, s1 in r let subcomp (a:Type) (pre1 : pre_t) (post1 : post_t a) (labs1 : list eff_label) (pre2 : pre_t) (post2 : post_t a) (labs2 : list eff_label) (f : repr a pre1 post1 labs1) : Pure (repr a pre2 post2 labs2) (requires ((forall s0. pre2 s0 ==> pre1 s0) /\ (forall s0 r s1. post1 s0 r s1 ==> post2 s0 r s1) /\ sublist labs1 labs2)) (ensures (fun _ -> True)) = f unfold let ite (p q r : Type0) = (p ==> q) /\ ((~p) ==> r) let if_then_else (a : Type) (pre1 : pre_t) (post1 : post_t a) (labs1 : list eff_label) (pre2 : pre_t) (post2 : post_t a) (labs2 : list eff_label) (f : repr a pre1 post1 labs1) (g : repr a pre2 post2 labs2) (b : bool) : Type = repr a (fun s0 -> ite b (pre1 s0) (pre2 s0)) (fun s0 y s1 -> ite b (post1 s0 y s1) (post2 s0 y s1)) (labs1@labs2) total // need this for catch!! reifiable reflectable effect { EFF (a:Type) (_:pre_t) (_:post_t a) (_:list eff_label) with {repr; return; bind; subcomp; if_then_else} } unfold let sp #a (wp : pure_wp a) : pure_post a = fun x -> ~ (wp (fun y -> ~(x == y)))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LatticeSpec.fst" }
[ { "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
wp: Prims.pure_wp a -> LatticeSpec.post_t a
Prims.Tot
[ "total" ]
[]
[ "Prims.pure_wp", "LatticeSpec.state", "FStar.Pervasives.Native.option", "Prims.l_and", "Prims.eq2", "Prims.b2t", "FStar.Pervasives.Native.uu___is_Some", "LatticeSpec.sp", "FStar.Pervasives.Native.__proj__Some__item__v", "LatticeSpec.post_t" ]
[]
false
false
false
true
false
let post_of_wp #a (wp: pure_wp a) : post_t a =
fun s0 r s1 -> s0 == s1 /\ Some? r /\ sp wp (Some?.v r)
false
LatticeSpec.fst
LatticeSpec.subcomp
val subcomp (a: Type) (pre1: pre_t) (post1: post_t a) (labs1: list eff_label) (pre2: pre_t) (post2: post_t a) (labs2: list eff_label) (f: repr a pre1 post1 labs1) : Pure (repr a pre2 post2 labs2) (requires ((forall s0. pre2 s0 ==> pre1 s0) /\ (forall s0 r s1. post1 s0 r s1 ==> post2 s0 r s1) /\ sublist labs1 labs2)) (ensures (fun _ -> True))
val subcomp (a: Type) (pre1: pre_t) (post1: post_t a) (labs1: list eff_label) (pre2: pre_t) (post2: post_t a) (labs2: list eff_label) (f: repr a pre1 post1 labs1) : Pure (repr a pre2 post2 labs2) (requires ((forall s0. pre2 s0 ==> pre1 s0) /\ (forall s0 r s1. post1 s0 r s1 ==> post2 s0 r s1) /\ sublist labs1 labs2)) (ensures (fun _ -> True))
let subcomp (a:Type) (pre1 : pre_t) (post1 : post_t a) (labs1 : list eff_label) (pre2 : pre_t) (post2 : post_t a) (labs2 : list eff_label) (f : repr a pre1 post1 labs1) : Pure (repr a pre2 post2 labs2) (requires ((forall s0. pre2 s0 ==> pre1 s0) /\ (forall s0 r s1. post1 s0 r s1 ==> post2 s0 r s1) /\ sublist labs1 labs2)) (ensures (fun _ -> True)) = f
{ "file_name": "examples/layeredeffects/LatticeSpec.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 5, "end_line": 141, "start_col": 0, "start_line": 128 }
module LatticeSpec open FStar.Tactics.V2 open FStar.List.Tot // 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 = | RD | WR | EXN type annot = eff_label -> bool // warning: if this is not annotated, `eqtype` is inferred // as its type and the effect definition fails for some reason. type state : Type = int type pre_t = state -> Type0 type post_t a = state -> option a -> state -> Type0 // this repr doesn't seem to work too well type repr0 (a:Type u#aa) (pre : pre_t) (post : post_t u#aa a) // #2074 : Type u#aa = s0:state{pre s0} -> Tot (r:(option a & state){post s0 (fst r) (snd r)}) let abides #a #pre #post (f : repr0 a pre post) (ann:annot) : Type0 = (ann RD = false ==> (forall s0 s1. fst (f s0) == fst (f s1))) /\ (ann WR = false ==> (forall s0. snd (f s0) == s0)) /\ (ann EXN = false ==> (forall s0. Some? (fst (f s0)))) let interp (l : list eff_label) : annot = fun lab -> mem lab 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 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 type repr (a:Type u#aa) (pre : pre_t) (post : post_t u#aa a) // #2074 (labs : list u#0 eff_label) // #2074 : Type u#aa = r:(repr0 a pre post){abides r (interp labs)} let ann_le (ann1 ann2 : annot) : Type0 = forall x. ann1 x ==> ann2 x let return (a:Type u#aa) (x:a) : Tot (repr a (fun _ -> True) (fun s0 y s1 -> s0 == s1 /\ y == Some x) []) = // GM: Need to write it like this.. why? let r (s0:state) : Tot (r:(option a & state){snd r == s0 /\ fst r == Some x}) = (Some x, s0) in r unfold let bind_pre (a:Type) (pre1:pre_t) (post1:post_t a) (b:Type) (pre2:a -> pre_t) (post2:a -> post_t b) : pre_t = fun s0 -> pre1 s0 /\ (forall y s1. post1 s0 (Some y) s1 ==> pre2 y s1) unfold let bind_post (a:Type) (pre1:pre_t) (post1:post_t a) (b:Type) (pre2:a -> pre_t) (post2:a -> post_t b) : post_t b = fun s0 z s2 -> (exists s1 y. post1 s0 (Some y) s1 /\ post2 y s1 z s2) \/ (post1 s0 None s2) let bind (a b : Type) pre1 post1 (labs1 : list eff_label) pre2 post2 (labs2 : list eff_label) (c : repr a pre1 post1 labs1) (f : (x:a -> repr b (pre2 x) (post2 x) labs2)) : Tot (repr b (bind_pre a pre1 post1 b pre2 post2) (bind_post a pre1 post1 b pre2 post2) (labs1@labs2)) = let pre = bind_pre a pre1 post1 b pre2 post2 in let post = bind_post a pre1 post1 b pre2 post2 in let r (s0:state{pre s0}) : Tot (r:(option b & state){post s0 (fst r) (snd r)}) = match c s0 with | Some x, s1 -> assert (post1 s0 (Some x) s1); assert (pre2 x s1); f x s1 | None, s1 -> None, s1 in r
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LatticeSpec.fst" }
[ { "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 -> pre1: LatticeSpec.pre_t -> post1: LatticeSpec.post_t a -> labs1: Prims.list LatticeSpec.eff_label -> pre2: LatticeSpec.pre_t -> post2: LatticeSpec.post_t a -> labs2: Prims.list LatticeSpec.eff_label -> f: LatticeSpec.repr a pre1 post1 labs1 -> Prims.Pure (LatticeSpec.repr a pre2 post2 labs2)
Prims.Pure
[]
[]
[ "LatticeSpec.pre_t", "LatticeSpec.post_t", "Prims.list", "LatticeSpec.eff_label", "LatticeSpec.repr", "Prims.l_and", "Prims.l_Forall", "LatticeSpec.state", "Prims.l_imp", "FStar.Pervasives.Native.option", "LatticeSpec.sublist", "Prims.l_True" ]
[]
false
false
false
false
false
let subcomp (a: Type) (pre1: pre_t) (post1: post_t a) (labs1: list eff_label) (pre2: pre_t) (post2: post_t a) (labs2: list eff_label) (f: repr a pre1 post1 labs1) : Pure (repr a pre2 post2 labs2) (requires ((forall s0. pre2 s0 ==> pre1 s0) /\ (forall s0 r s1. post1 s0 r s1 ==> post2 s0 r s1) /\ sublist labs1 labs2)) (ensures (fun _ -> True)) =
f
false
LatticeSpec.fst
LatticeSpec.bind
val bind (a b: Type) (pre1 post1: _) (labs1: list eff_label) (pre2 post2: _) (labs2: list eff_label) (c: repr a pre1 post1 labs1) (f: (x: a -> repr b (pre2 x) (post2 x) labs2)) : Tot (repr b (bind_pre a pre1 post1 b pre2 post2) (bind_post a pre1 post1 b pre2 post2) (labs1 @ labs2))
val bind (a b: Type) (pre1 post1: _) (labs1: list eff_label) (pre2 post2: _) (labs2: list eff_label) (c: repr a pre1 post1 labs1) (f: (x: a -> repr b (pre2 x) (post2 x) labs2)) : Tot (repr b (bind_pre a pre1 post1 b pre2 post2) (bind_post a pre1 post1 b pre2 post2) (labs1 @ labs2))
let bind (a b : Type) pre1 post1 (labs1 : list eff_label) pre2 post2 (labs2 : list eff_label) (c : repr a pre1 post1 labs1) (f : (x:a -> repr b (pre2 x) (post2 x) labs2)) : Tot (repr b (bind_pre a pre1 post1 b pre2 post2) (bind_post a pre1 post1 b pre2 post2) (labs1@labs2)) = let pre = bind_pre a pre1 post1 b pre2 post2 in let post = bind_post a pre1 post1 b pre2 post2 in let r (s0:state{pre s0}) : Tot (r:(option b & state){post s0 (fst r) (snd r)}) = match c s0 with | Some x, s1 -> assert (post1 s0 (Some x) s1); assert (pre2 x s1); f x s1 | None, s1 -> None, s1 in r
{ "file_name": "examples/layeredeffects/LatticeSpec.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 5, "end_line": 126, "start_col": 0, "start_line": 106 }
module LatticeSpec open FStar.Tactics.V2 open FStar.List.Tot // 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 = | RD | WR | EXN type annot = eff_label -> bool // warning: if this is not annotated, `eqtype` is inferred // as its type and the effect definition fails for some reason. type state : Type = int type pre_t = state -> Type0 type post_t a = state -> option a -> state -> Type0 // this repr doesn't seem to work too well type repr0 (a:Type u#aa) (pre : pre_t) (post : post_t u#aa a) // #2074 : Type u#aa = s0:state{pre s0} -> Tot (r:(option a & state){post s0 (fst r) (snd r)}) let abides #a #pre #post (f : repr0 a pre post) (ann:annot) : Type0 = (ann RD = false ==> (forall s0 s1. fst (f s0) == fst (f s1))) /\ (ann WR = false ==> (forall s0. snd (f s0) == s0)) /\ (ann EXN = false ==> (forall s0. Some? (fst (f s0)))) let interp (l : list eff_label) : annot = fun lab -> mem lab 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 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 type repr (a:Type u#aa) (pre : pre_t) (post : post_t u#aa a) // #2074 (labs : list u#0 eff_label) // #2074 : Type u#aa = r:(repr0 a pre post){abides r (interp labs)} let ann_le (ann1 ann2 : annot) : Type0 = forall x. ann1 x ==> ann2 x let return (a:Type u#aa) (x:a) : Tot (repr a (fun _ -> True) (fun s0 y s1 -> s0 == s1 /\ y == Some x) []) = // GM: Need to write it like this.. why? let r (s0:state) : Tot (r:(option a & state){snd r == s0 /\ fst r == Some x}) = (Some x, s0) in r unfold let bind_pre (a:Type) (pre1:pre_t) (post1:post_t a) (b:Type) (pre2:a -> pre_t) (post2:a -> post_t b) : pre_t = fun s0 -> pre1 s0 /\ (forall y s1. post1 s0 (Some y) s1 ==> pre2 y s1) unfold let bind_post (a:Type) (pre1:pre_t) (post1:post_t a) (b:Type) (pre2:a -> pre_t) (post2:a -> post_t b) : post_t b = fun s0 z s2 -> (exists s1 y. post1 s0 (Some y) s1 /\ post2 y s1 z s2) \/ (post1 s0 None s2)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LatticeSpec.fst" }
[ { "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 -> pre1: LatticeSpec.pre_t -> post1: LatticeSpec.post_t a -> labs1: Prims.list LatticeSpec.eff_label -> pre2: (_: a -> LatticeSpec.pre_t) -> post2: (_: a -> LatticeSpec.post_t b) -> labs2: Prims.list LatticeSpec.eff_label -> c: LatticeSpec.repr a pre1 post1 labs1 -> f: (x: a -> LatticeSpec.repr b (pre2 x) (post2 x) labs2) -> LatticeSpec.repr b (LatticeSpec.bind_pre a pre1 post1 b pre2 post2) (LatticeSpec.bind_post a pre1 post1 b pre2 post2) (labs1 @ labs2)
Prims.Tot
[ "total" ]
[]
[ "LatticeSpec.pre_t", "LatticeSpec.post_t", "Prims.list", "LatticeSpec.eff_label", "LatticeSpec.repr", "LatticeSpec.state", "FStar.Pervasives.Native.tuple2", "FStar.Pervasives.Native.option", "FStar.Pervasives.Native.fst", "FStar.Pervasives.Native.snd", "Prims.unit", "Prims._assert", "FStar.Pervasives.Native.Some", "FStar.Pervasives.Native.Mktuple2", "FStar.Pervasives.Native.None", "LatticeSpec.bind_post", "LatticeSpec.bind_pre", "FStar.List.Tot.Base.op_At" ]
[]
false
false
false
false
false
let bind (a: Type) (b: Type) pre1 post1 (labs1: list eff_label) pre2 post2 (labs2: list eff_label) (c: repr a pre1 post1 labs1) (f: (x: a -> repr b (pre2 x) (post2 x) labs2)) : Tot (repr b (bind_pre a pre1 post1 b pre2 post2) (bind_post a pre1 post1 b pre2 post2) (labs1 @ labs2)) =
let pre = bind_pre a pre1 post1 b pre2 post2 in let post = bind_post a pre1 post1 b pre2 post2 in let r (s0: state{pre s0}) : Tot (r: (option b & state){post s0 (fst r) (snd r)}) = match c s0 with | Some x, s1 -> assert (post1 s0 (Some x) s1); assert (pre2 x s1); f x s1 | None, s1 -> None, s1 in r
false
LatticeSpec.fst
LatticeSpec.get
val get: Prims.unit -> EFF int (fun _ -> True) (fun s0 y s1 -> s1 == s0 /\ y == Some s0) [RD]
val get: Prims.unit -> EFF int (fun _ -> True) (fun s0 y s1 -> s1 == s0 /\ y == Some s0) [RD]
let get () : EFF int (fun _ -> True) (fun s0 y s1 -> s1 == s0 /\ y == Some s0) [RD] by (compute (); dump"") = EFF?.reflect _get
{ "file_name": "examples/layeredeffects/LatticeSpec.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 19, "end_line": 200, "start_col": 0, "start_line": 199 }
module LatticeSpec open FStar.Tactics.V2 open FStar.List.Tot // 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 = | RD | WR | EXN type annot = eff_label -> bool // warning: if this is not annotated, `eqtype` is inferred // as its type and the effect definition fails for some reason. type state : Type = int type pre_t = state -> Type0 type post_t a = state -> option a -> state -> Type0 // this repr doesn't seem to work too well type repr0 (a:Type u#aa) (pre : pre_t) (post : post_t u#aa a) // #2074 : Type u#aa = s0:state{pre s0} -> Tot (r:(option a & state){post s0 (fst r) (snd r)}) let abides #a #pre #post (f : repr0 a pre post) (ann:annot) : Type0 = (ann RD = false ==> (forall s0 s1. fst (f s0) == fst (f s1))) /\ (ann WR = false ==> (forall s0. snd (f s0) == s0)) /\ (ann EXN = false ==> (forall s0. Some? (fst (f s0)))) let interp (l : list eff_label) : annot = fun lab -> mem lab 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 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 type repr (a:Type u#aa) (pre : pre_t) (post : post_t u#aa a) // #2074 (labs : list u#0 eff_label) // #2074 : Type u#aa = r:(repr0 a pre post){abides r (interp labs)} let ann_le (ann1 ann2 : annot) : Type0 = forall x. ann1 x ==> ann2 x let return (a:Type u#aa) (x:a) : Tot (repr a (fun _ -> True) (fun s0 y s1 -> s0 == s1 /\ y == Some x) []) = // GM: Need to write it like this.. why? let r (s0:state) : Tot (r:(option a & state){snd r == s0 /\ fst r == Some x}) = (Some x, s0) in r unfold let bind_pre (a:Type) (pre1:pre_t) (post1:post_t a) (b:Type) (pre2:a -> pre_t) (post2:a -> post_t b) : pre_t = fun s0 -> pre1 s0 /\ (forall y s1. post1 s0 (Some y) s1 ==> pre2 y s1) unfold let bind_post (a:Type) (pre1:pre_t) (post1:post_t a) (b:Type) (pre2:a -> pre_t) (post2:a -> post_t b) : post_t b = fun s0 z s2 -> (exists s1 y. post1 s0 (Some y) s1 /\ post2 y s1 z s2) \/ (post1 s0 None s2) let bind (a b : Type) pre1 post1 (labs1 : list eff_label) pre2 post2 (labs2 : list eff_label) (c : repr a pre1 post1 labs1) (f : (x:a -> repr b (pre2 x) (post2 x) labs2)) : Tot (repr b (bind_pre a pre1 post1 b pre2 post2) (bind_post a pre1 post1 b pre2 post2) (labs1@labs2)) = let pre = bind_pre a pre1 post1 b pre2 post2 in let post = bind_post a pre1 post1 b pre2 post2 in let r (s0:state{pre s0}) : Tot (r:(option b & state){post s0 (fst r) (snd r)}) = match c s0 with | Some x, s1 -> assert (post1 s0 (Some x) s1); assert (pre2 x s1); f x s1 | None, s1 -> None, s1 in r let subcomp (a:Type) (pre1 : pre_t) (post1 : post_t a) (labs1 : list eff_label) (pre2 : pre_t) (post2 : post_t a) (labs2 : list eff_label) (f : repr a pre1 post1 labs1) : Pure (repr a pre2 post2 labs2) (requires ((forall s0. pre2 s0 ==> pre1 s0) /\ (forall s0 r s1. post1 s0 r s1 ==> post2 s0 r s1) /\ sublist labs1 labs2)) (ensures (fun _ -> True)) = f unfold let ite (p q r : Type0) = (p ==> q) /\ ((~p) ==> r) let if_then_else (a : Type) (pre1 : pre_t) (post1 : post_t a) (labs1 : list eff_label) (pre2 : pre_t) (post2 : post_t a) (labs2 : list eff_label) (f : repr a pre1 post1 labs1) (g : repr a pre2 post2 labs2) (b : bool) : Type = repr a (fun s0 -> ite b (pre1 s0) (pre2 s0)) (fun s0 y s1 -> ite b (post1 s0 y s1) (post2 s0 y s1)) (labs1@labs2) total // need this for catch!! reifiable reflectable effect { EFF (a:Type) (_:pre_t) (_:post_t a) (_:list eff_label) with {repr; return; bind; subcomp; if_then_else} } unfold let sp #a (wp : pure_wp a) : pure_post a = fun x -> ~ (wp (fun y -> ~(x == y))) unfold let post_of_wp #a (wp : pure_wp a) : post_t a = fun s0 r s1 -> s0 == s1 /\ Some? r /\ sp wp (Some?.v r) let lift_pure_eff (a:Type) (wp : pure_wp a) (f : unit -> PURE a wp) : repr a (fun _ -> wp (fun _ -> True)) (post_of_wp wp) [] = FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp; let r (s0:state{wp (fun _ -> True)}) : Tot (r:(option a & state){snd r == s0 /\ Some? (fst r) /\ sp wp (Some?.v (fst r))}) = (Some (f ()), s0) in r sub_effect PURE ~> EFF = lift_pure_eff let _get : repr state (fun _ -> True) (fun s0 y s1 -> s1 == s0 /\ y == Some s0) [RD] = let ff (s0:state) : Tot (r:(option state & state){fst r == Some s0 /\ snd r == s0}) = (Some s0, s0) in ff
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LatticeSpec.fst" }
[ { "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 -> LatticeSpec.EFF Prims.int
LatticeSpec.EFF
[]
[]
[ "Prims.unit", "LatticeSpec._get", "Prims.int", "LatticeSpec.state", "Prims.l_True", "FStar.Pervasives.Native.option", "Prims.l_and", "Prims.eq2", "FStar.Pervasives.Native.Some", "Prims.Cons", "LatticeSpec.eff_label", "LatticeSpec.RD", "Prims.Nil", "FStar.Stubs.Tactics.V2.Builtins.dump", "FStar.Tactics.V2.Derived.compute" ]
[]
false
true
false
false
false
let get () : EFF int (fun _ -> True) (fun s0 y s1 -> s1 == s0 /\ y == Some s0) [RD] by (compute (); dump "") =
EFF?.reflect _get
false
LatticeSpec.fst
LatticeSpec.put
val put (s: state) : EFF unit (fun _ -> True) (fun _ y s1 -> s1 == s) [WR]
val put (s: state) : EFF unit (fun _ -> True) (fun _ y s1 -> s1 == s) [WR]
let put (s:state) : EFF unit (fun _ -> True) (fun _ y s1 -> s1 == s) [WR] = EFF?.reflect (_put s)
{ "file_name": "examples/layeredeffects/LatticeSpec.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 23, "end_line": 210, "start_col": 0, "start_line": 209 }
module LatticeSpec open FStar.Tactics.V2 open FStar.List.Tot // 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 = | RD | WR | EXN type annot = eff_label -> bool // warning: if this is not annotated, `eqtype` is inferred // as its type and the effect definition fails for some reason. type state : Type = int type pre_t = state -> Type0 type post_t a = state -> option a -> state -> Type0 // this repr doesn't seem to work too well type repr0 (a:Type u#aa) (pre : pre_t) (post : post_t u#aa a) // #2074 : Type u#aa = s0:state{pre s0} -> Tot (r:(option a & state){post s0 (fst r) (snd r)}) let abides #a #pre #post (f : repr0 a pre post) (ann:annot) : Type0 = (ann RD = false ==> (forall s0 s1. fst (f s0) == fst (f s1))) /\ (ann WR = false ==> (forall s0. snd (f s0) == s0)) /\ (ann EXN = false ==> (forall s0. Some? (fst (f s0)))) let interp (l : list eff_label) : annot = fun lab -> mem lab 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 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 type repr (a:Type u#aa) (pre : pre_t) (post : post_t u#aa a) // #2074 (labs : list u#0 eff_label) // #2074 : Type u#aa = r:(repr0 a pre post){abides r (interp labs)} let ann_le (ann1 ann2 : annot) : Type0 = forall x. ann1 x ==> ann2 x let return (a:Type u#aa) (x:a) : Tot (repr a (fun _ -> True) (fun s0 y s1 -> s0 == s1 /\ y == Some x) []) = // GM: Need to write it like this.. why? let r (s0:state) : Tot (r:(option a & state){snd r == s0 /\ fst r == Some x}) = (Some x, s0) in r unfold let bind_pre (a:Type) (pre1:pre_t) (post1:post_t a) (b:Type) (pre2:a -> pre_t) (post2:a -> post_t b) : pre_t = fun s0 -> pre1 s0 /\ (forall y s1. post1 s0 (Some y) s1 ==> pre2 y s1) unfold let bind_post (a:Type) (pre1:pre_t) (post1:post_t a) (b:Type) (pre2:a -> pre_t) (post2:a -> post_t b) : post_t b = fun s0 z s2 -> (exists s1 y. post1 s0 (Some y) s1 /\ post2 y s1 z s2) \/ (post1 s0 None s2) let bind (a b : Type) pre1 post1 (labs1 : list eff_label) pre2 post2 (labs2 : list eff_label) (c : repr a pre1 post1 labs1) (f : (x:a -> repr b (pre2 x) (post2 x) labs2)) : Tot (repr b (bind_pre a pre1 post1 b pre2 post2) (bind_post a pre1 post1 b pre2 post2) (labs1@labs2)) = let pre = bind_pre a pre1 post1 b pre2 post2 in let post = bind_post a pre1 post1 b pre2 post2 in let r (s0:state{pre s0}) : Tot (r:(option b & state){post s0 (fst r) (snd r)}) = match c s0 with | Some x, s1 -> assert (post1 s0 (Some x) s1); assert (pre2 x s1); f x s1 | None, s1 -> None, s1 in r let subcomp (a:Type) (pre1 : pre_t) (post1 : post_t a) (labs1 : list eff_label) (pre2 : pre_t) (post2 : post_t a) (labs2 : list eff_label) (f : repr a pre1 post1 labs1) : Pure (repr a pre2 post2 labs2) (requires ((forall s0. pre2 s0 ==> pre1 s0) /\ (forall s0 r s1. post1 s0 r s1 ==> post2 s0 r s1) /\ sublist labs1 labs2)) (ensures (fun _ -> True)) = f unfold let ite (p q r : Type0) = (p ==> q) /\ ((~p) ==> r) let if_then_else (a : Type) (pre1 : pre_t) (post1 : post_t a) (labs1 : list eff_label) (pre2 : pre_t) (post2 : post_t a) (labs2 : list eff_label) (f : repr a pre1 post1 labs1) (g : repr a pre2 post2 labs2) (b : bool) : Type = repr a (fun s0 -> ite b (pre1 s0) (pre2 s0)) (fun s0 y s1 -> ite b (post1 s0 y s1) (post2 s0 y s1)) (labs1@labs2) total // need this for catch!! reifiable reflectable effect { EFF (a:Type) (_:pre_t) (_:post_t a) (_:list eff_label) with {repr; return; bind; subcomp; if_then_else} } unfold let sp #a (wp : pure_wp a) : pure_post a = fun x -> ~ (wp (fun y -> ~(x == y))) unfold let post_of_wp #a (wp : pure_wp a) : post_t a = fun s0 r s1 -> s0 == s1 /\ Some? r /\ sp wp (Some?.v r) let lift_pure_eff (a:Type) (wp : pure_wp a) (f : unit -> PURE a wp) : repr a (fun _ -> wp (fun _ -> True)) (post_of_wp wp) [] = FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp; let r (s0:state{wp (fun _ -> True)}) : Tot (r:(option a & state){snd r == s0 /\ Some? (fst r) /\ sp wp (Some?.v (fst r))}) = (Some (f ()), s0) in r sub_effect PURE ~> EFF = lift_pure_eff let _get : repr state (fun _ -> True) (fun s0 y s1 -> s1 == s0 /\ y == Some s0) [RD] = let ff (s0:state) : Tot (r:(option state & state){fst r == Some s0 /\ snd r == s0}) = (Some s0, s0) in ff let get () : EFF int (fun _ -> True) (fun s0 y s1 -> s1 == s0 /\ y == Some s0) [RD] by (compute (); dump"") = EFF?.reflect _get let _put (s:state) : repr unit (fun _ -> True) (fun _ y s1 -> s1 == s /\ y == Some ()) [WR] = // GM: pretty odd that I have to add `r == Some ()` here.... let ff (_:state) : Tot (r:(option unit & state){fst r == Some () /\ snd r == s}) = (Some (), s) in ff
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LatticeSpec.fst" }
[ { "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: LatticeSpec.state -> LatticeSpec.EFF Prims.unit
LatticeSpec.EFF
[]
[]
[ "LatticeSpec.state", "LatticeSpec._put", "Prims.unit", "Prims.l_True", "FStar.Pervasives.Native.option", "Prims.eq2", "Prims.Cons", "LatticeSpec.eff_label", "LatticeSpec.WR", "Prims.Nil" ]
[]
false
true
false
false
false
let put (s: state) : EFF unit (fun _ -> True) (fun _ y s1 -> s1 == s) [WR] =
EFF?.reflect (_put s)
false
Hacl.Ed25519.fst
Hacl.Ed25519.verify
val verify: public_key:lbuffer uint8 32ul -> msg_len:size_t -> msg:lbuffer uint8 msg_len -> signature:lbuffer uint8 64ul -> Stack bool (requires fun h -> live h public_key /\ live h msg /\ live h signature) (ensures fun h0 b h1 -> modifies0 h0 h1 /\ b == Spec.Ed25519.verify (as_seq h0 public_key) (as_seq h0 msg) (as_seq h0 signature))
val verify: public_key:lbuffer uint8 32ul -> msg_len:size_t -> msg:lbuffer uint8 msg_len -> signature:lbuffer uint8 64ul -> Stack bool (requires fun h -> live h public_key /\ live h msg /\ live h signature) (ensures fun h0 b h1 -> modifies0 h0 h1 /\ b == Spec.Ed25519.verify (as_seq h0 public_key) (as_seq h0 msg) (as_seq h0 signature))
let verify public_key msg_len msg signature = Hacl.Impl.Ed25519.Verify.verify public_key msg_len msg signature
{ "file_name": "code/ed25519/Hacl.Ed25519.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 66, "end_line": 62, "start_col": 0, "start_line": 61 }
module Hacl.Ed25519 module ST = FStar.HyperStack.ST open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer module S = Spec.Ed25519 #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" val secret_expand: expanded:lbuffer uint8 64ul -> secret:lbuffer uint8 32ul -> Stack unit (requires fun h -> live h expanded /\ live h secret /\ disjoint expanded secret) (ensures fun h0 _ h1 -> modifies (loc expanded) h0 h1 /\ (let a, prefix = S.secret_expand (as_seq h0 secret) in as_seq h1 (gsub expanded 0ul 32ul) == a /\ as_seq h1 (gsub expanded 32ul 32ul) == prefix)) [@CInline] let secret_expand expanded secret = assert_norm (pow2 32 <= pow2 125 - 1); Hacl.Streaming.SHA2.hash_512 expanded secret 32ul; let h_low = sub expanded 0ul 32ul in let h_low0 = h_low.( 0ul) in let h_low31 = h_low.(31ul) in h_low.( 0ul) <- h_low0 &. u8 0xf8; h_low.(31ul) <- (h_low31 &. u8 127) |. u8 64 let secret_to_public public_key private_key = push_frame (); let expanded_secret = create 64ul (u8 0) in secret_expand expanded_secret private_key; let a = sub expanded_secret 0ul 32ul in Hacl.Impl.Ed25519.Sign.point_mul_g_compress public_key a; pop_frame () let expand_keys expanded_keys private_key = let public_key = sub expanded_keys 0ul 32ul in let s_prefix = sub expanded_keys 32ul 64ul in let s = sub expanded_keys 32ul 32ul in secret_expand s_prefix private_key; Hacl.Impl.Ed25519.Sign.point_mul_g_compress public_key s let sign_expanded signature expanded_keys msg_len msg = Hacl.Impl.Ed25519.Sign.sign_expanded signature expanded_keys msg_len msg let sign signature private_key msg_len msg = push_frame (); let expanded_keys = create 96ul (u8 0) in expand_keys expanded_keys private_key; sign_expanded signature expanded_keys msg_len msg; pop_frame ()
{ "checked_file": "/", "dependencies": [ "Spec.Ed25519.fst.checked", "prims.fst.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.SHA2.fst.checked", "Hacl.Impl.Ed25519.Verify.fst.checked", "Hacl.Impl.Ed25519.Sign.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked" ], "interface_file": true, "source_file": "Hacl.Ed25519.fst" }
[ { "abbrev": true, "full_module": "Spec.Ed25519", "short_module": "S" }, { "abbrev": false, "full_module": "FStar.Mul", "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.HyperStack.All", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
public_key: Lib.Buffer.lbuffer Lib.IntTypes.uint8 32ul -> msg_len: Lib.IntTypes.size_t -> msg: Lib.Buffer.lbuffer Lib.IntTypes.uint8 msg_len -> signature: Lib.Buffer.lbuffer Lib.IntTypes.uint8 64ul -> FStar.HyperStack.ST.Stack Prims.bool
FStar.HyperStack.ST.Stack
[]
[]
[ "Lib.Buffer.lbuffer", "Lib.IntTypes.uint8", "FStar.UInt32.__uint_to_t", "Lib.IntTypes.size_t", "Hacl.Impl.Ed25519.Verify.verify", "Prims.bool" ]
[]
false
true
false
false
false
let verify public_key msg_len msg signature =
Hacl.Impl.Ed25519.Verify.verify public_key msg_len msg signature
false
LatticeSpec.fst
LatticeSpec.raise
val raise: #a: _ -> Prims.unit -> EFF a (fun _ -> True) (fun s0 _ s1 -> s1 == s0) [EXN]
val raise: #a: _ -> Prims.unit -> EFF a (fun _ -> True) (fun s0 _ s1 -> s1 == s0) [EXN]
let raise #a () : EFF a (fun _ -> True) (fun s0 _ s1 -> s1 == s0) [EXN] = EFF?.reflect _raise
{ "file_name": "examples/layeredeffects/LatticeSpec.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 21, "end_line": 219, "start_col": 0, "start_line": 218 }
module LatticeSpec open FStar.Tactics.V2 open FStar.List.Tot // 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 = | RD | WR | EXN type annot = eff_label -> bool // warning: if this is not annotated, `eqtype` is inferred // as its type and the effect definition fails for some reason. type state : Type = int type pre_t = state -> Type0 type post_t a = state -> option a -> state -> Type0 // this repr doesn't seem to work too well type repr0 (a:Type u#aa) (pre : pre_t) (post : post_t u#aa a) // #2074 : Type u#aa = s0:state{pre s0} -> Tot (r:(option a & state){post s0 (fst r) (snd r)}) let abides #a #pre #post (f : repr0 a pre post) (ann:annot) : Type0 = (ann RD = false ==> (forall s0 s1. fst (f s0) == fst (f s1))) /\ (ann WR = false ==> (forall s0. snd (f s0) == s0)) /\ (ann EXN = false ==> (forall s0. Some? (fst (f s0)))) let interp (l : list eff_label) : annot = fun lab -> mem lab 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 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 type repr (a:Type u#aa) (pre : pre_t) (post : post_t u#aa a) // #2074 (labs : list u#0 eff_label) // #2074 : Type u#aa = r:(repr0 a pre post){abides r (interp labs)} let ann_le (ann1 ann2 : annot) : Type0 = forall x. ann1 x ==> ann2 x let return (a:Type u#aa) (x:a) : Tot (repr a (fun _ -> True) (fun s0 y s1 -> s0 == s1 /\ y == Some x) []) = // GM: Need to write it like this.. why? let r (s0:state) : Tot (r:(option a & state){snd r == s0 /\ fst r == Some x}) = (Some x, s0) in r unfold let bind_pre (a:Type) (pre1:pre_t) (post1:post_t a) (b:Type) (pre2:a -> pre_t) (post2:a -> post_t b) : pre_t = fun s0 -> pre1 s0 /\ (forall y s1. post1 s0 (Some y) s1 ==> pre2 y s1) unfold let bind_post (a:Type) (pre1:pre_t) (post1:post_t a) (b:Type) (pre2:a -> pre_t) (post2:a -> post_t b) : post_t b = fun s0 z s2 -> (exists s1 y. post1 s0 (Some y) s1 /\ post2 y s1 z s2) \/ (post1 s0 None s2) let bind (a b : Type) pre1 post1 (labs1 : list eff_label) pre2 post2 (labs2 : list eff_label) (c : repr a pre1 post1 labs1) (f : (x:a -> repr b (pre2 x) (post2 x) labs2)) : Tot (repr b (bind_pre a pre1 post1 b pre2 post2) (bind_post a pre1 post1 b pre2 post2) (labs1@labs2)) = let pre = bind_pre a pre1 post1 b pre2 post2 in let post = bind_post a pre1 post1 b pre2 post2 in let r (s0:state{pre s0}) : Tot (r:(option b & state){post s0 (fst r) (snd r)}) = match c s0 with | Some x, s1 -> assert (post1 s0 (Some x) s1); assert (pre2 x s1); f x s1 | None, s1 -> None, s1 in r let subcomp (a:Type) (pre1 : pre_t) (post1 : post_t a) (labs1 : list eff_label) (pre2 : pre_t) (post2 : post_t a) (labs2 : list eff_label) (f : repr a pre1 post1 labs1) : Pure (repr a pre2 post2 labs2) (requires ((forall s0. pre2 s0 ==> pre1 s0) /\ (forall s0 r s1. post1 s0 r s1 ==> post2 s0 r s1) /\ sublist labs1 labs2)) (ensures (fun _ -> True)) = f unfold let ite (p q r : Type0) = (p ==> q) /\ ((~p) ==> r) let if_then_else (a : Type) (pre1 : pre_t) (post1 : post_t a) (labs1 : list eff_label) (pre2 : pre_t) (post2 : post_t a) (labs2 : list eff_label) (f : repr a pre1 post1 labs1) (g : repr a pre2 post2 labs2) (b : bool) : Type = repr a (fun s0 -> ite b (pre1 s0) (pre2 s0)) (fun s0 y s1 -> ite b (post1 s0 y s1) (post2 s0 y s1)) (labs1@labs2) total // need this for catch!! reifiable reflectable effect { EFF (a:Type) (_:pre_t) (_:post_t a) (_:list eff_label) with {repr; return; bind; subcomp; if_then_else} } unfold let sp #a (wp : pure_wp a) : pure_post a = fun x -> ~ (wp (fun y -> ~(x == y))) unfold let post_of_wp #a (wp : pure_wp a) : post_t a = fun s0 r s1 -> s0 == s1 /\ Some? r /\ sp wp (Some?.v r) let lift_pure_eff (a:Type) (wp : pure_wp a) (f : unit -> PURE a wp) : repr a (fun _ -> wp (fun _ -> True)) (post_of_wp wp) [] = FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp; let r (s0:state{wp (fun _ -> True)}) : Tot (r:(option a & state){snd r == s0 /\ Some? (fst r) /\ sp wp (Some?.v (fst r))}) = (Some (f ()), s0) in r sub_effect PURE ~> EFF = lift_pure_eff let _get : repr state (fun _ -> True) (fun s0 y s1 -> s1 == s0 /\ y == Some s0) [RD] = let ff (s0:state) : Tot (r:(option state & state){fst r == Some s0 /\ snd r == s0}) = (Some s0, s0) in ff let get () : EFF int (fun _ -> True) (fun s0 y s1 -> s1 == s0 /\ y == Some s0) [RD] by (compute (); dump"") = EFF?.reflect _get let _put (s:state) : repr unit (fun _ -> True) (fun _ y s1 -> s1 == s /\ y == Some ()) [WR] = // GM: pretty odd that I have to add `r == Some ()` here.... let ff (_:state) : Tot (r:(option unit & state){fst r == Some () /\ snd r == s}) = (Some (), s) in ff let put (s:state) : EFF unit (fun _ -> True) (fun _ y s1 -> s1 == s) [WR] = EFF?.reflect (_put s) let _raise #a : repr a (fun _ -> True) (fun s0 _ s1 -> s1 == s0) [EXN] = let ff (s0:state) : Tot (r:(option a & state){fst r == None /\ snd r == s0}) = (None, s0) in ff
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LatticeSpec.fst" }
[ { "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 -> LatticeSpec.EFF a
LatticeSpec.EFF
[]
[]
[ "Prims.unit", "LatticeSpec._raise", "LatticeSpec.state", "Prims.l_True", "FStar.Pervasives.Native.option", "Prims.eq2", "Prims.Cons", "LatticeSpec.eff_label", "LatticeSpec.EXN", "Prims.Nil" ]
[]
false
true
false
false
false
let raise #a () : EFF a (fun _ -> True) (fun s0 _ s1 -> s1 == s0) [EXN] =
EFF?.reflect _raise
false
LatticeSpec.fst
LatticeSpec.test0
val test0 (x y: int) : EFFT int [RD; EXN]
val test0 (x y: int) : EFFT int [RD; EXN]
let test0 (x y : int) : EFFT int [RD; EXN] = let z = get () in if x + z > 0 then raise () else y - z
{ "file_name": "examples/layeredeffects/LatticeSpec.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 12, "end_line": 227, "start_col": 0, "start_line": 223 }
module LatticeSpec open FStar.Tactics.V2 open FStar.List.Tot // 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 = | RD | WR | EXN type annot = eff_label -> bool // warning: if this is not annotated, `eqtype` is inferred // as its type and the effect definition fails for some reason. type state : Type = int type pre_t = state -> Type0 type post_t a = state -> option a -> state -> Type0 // this repr doesn't seem to work too well type repr0 (a:Type u#aa) (pre : pre_t) (post : post_t u#aa a) // #2074 : Type u#aa = s0:state{pre s0} -> Tot (r:(option a & state){post s0 (fst r) (snd r)}) let abides #a #pre #post (f : repr0 a pre post) (ann:annot) : Type0 = (ann RD = false ==> (forall s0 s1. fst (f s0) == fst (f s1))) /\ (ann WR = false ==> (forall s0. snd (f s0) == s0)) /\ (ann EXN = false ==> (forall s0. Some? (fst (f s0)))) let interp (l : list eff_label) : annot = fun lab -> mem lab 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 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 type repr (a:Type u#aa) (pre : pre_t) (post : post_t u#aa a) // #2074 (labs : list u#0 eff_label) // #2074 : Type u#aa = r:(repr0 a pre post){abides r (interp labs)} let ann_le (ann1 ann2 : annot) : Type0 = forall x. ann1 x ==> ann2 x let return (a:Type u#aa) (x:a) : Tot (repr a (fun _ -> True) (fun s0 y s1 -> s0 == s1 /\ y == Some x) []) = // GM: Need to write it like this.. why? let r (s0:state) : Tot (r:(option a & state){snd r == s0 /\ fst r == Some x}) = (Some x, s0) in r unfold let bind_pre (a:Type) (pre1:pre_t) (post1:post_t a) (b:Type) (pre2:a -> pre_t) (post2:a -> post_t b) : pre_t = fun s0 -> pre1 s0 /\ (forall y s1. post1 s0 (Some y) s1 ==> pre2 y s1) unfold let bind_post (a:Type) (pre1:pre_t) (post1:post_t a) (b:Type) (pre2:a -> pre_t) (post2:a -> post_t b) : post_t b = fun s0 z s2 -> (exists s1 y. post1 s0 (Some y) s1 /\ post2 y s1 z s2) \/ (post1 s0 None s2) let bind (a b : Type) pre1 post1 (labs1 : list eff_label) pre2 post2 (labs2 : list eff_label) (c : repr a pre1 post1 labs1) (f : (x:a -> repr b (pre2 x) (post2 x) labs2)) : Tot (repr b (bind_pre a pre1 post1 b pre2 post2) (bind_post a pre1 post1 b pre2 post2) (labs1@labs2)) = let pre = bind_pre a pre1 post1 b pre2 post2 in let post = bind_post a pre1 post1 b pre2 post2 in let r (s0:state{pre s0}) : Tot (r:(option b & state){post s0 (fst r) (snd r)}) = match c s0 with | Some x, s1 -> assert (post1 s0 (Some x) s1); assert (pre2 x s1); f x s1 | None, s1 -> None, s1 in r let subcomp (a:Type) (pre1 : pre_t) (post1 : post_t a) (labs1 : list eff_label) (pre2 : pre_t) (post2 : post_t a) (labs2 : list eff_label) (f : repr a pre1 post1 labs1) : Pure (repr a pre2 post2 labs2) (requires ((forall s0. pre2 s0 ==> pre1 s0) /\ (forall s0 r s1. post1 s0 r s1 ==> post2 s0 r s1) /\ sublist labs1 labs2)) (ensures (fun _ -> True)) = f unfold let ite (p q r : Type0) = (p ==> q) /\ ((~p) ==> r) let if_then_else (a : Type) (pre1 : pre_t) (post1 : post_t a) (labs1 : list eff_label) (pre2 : pre_t) (post2 : post_t a) (labs2 : list eff_label) (f : repr a pre1 post1 labs1) (g : repr a pre2 post2 labs2) (b : bool) : Type = repr a (fun s0 -> ite b (pre1 s0) (pre2 s0)) (fun s0 y s1 -> ite b (post1 s0 y s1) (post2 s0 y s1)) (labs1@labs2) total // need this for catch!! reifiable reflectable effect { EFF (a:Type) (_:pre_t) (_:post_t a) (_:list eff_label) with {repr; return; bind; subcomp; if_then_else} } unfold let sp #a (wp : pure_wp a) : pure_post a = fun x -> ~ (wp (fun y -> ~(x == y))) unfold let post_of_wp #a (wp : pure_wp a) : post_t a = fun s0 r s1 -> s0 == s1 /\ Some? r /\ sp wp (Some?.v r) let lift_pure_eff (a:Type) (wp : pure_wp a) (f : unit -> PURE a wp) : repr a (fun _ -> wp (fun _ -> True)) (post_of_wp wp) [] = FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp; let r (s0:state{wp (fun _ -> True)}) : Tot (r:(option a & state){snd r == s0 /\ Some? (fst r) /\ sp wp (Some?.v (fst r))}) = (Some (f ()), s0) in r sub_effect PURE ~> EFF = lift_pure_eff let _get : repr state (fun _ -> True) (fun s0 y s1 -> s1 == s0 /\ y == Some s0) [RD] = let ff (s0:state) : Tot (r:(option state & state){fst r == Some s0 /\ snd r == s0}) = (Some s0, s0) in ff let get () : EFF int (fun _ -> True) (fun s0 y s1 -> s1 == s0 /\ y == Some s0) [RD] by (compute (); dump"") = EFF?.reflect _get let _put (s:state) : repr unit (fun _ -> True) (fun _ y s1 -> s1 == s /\ y == Some ()) [WR] = // GM: pretty odd that I have to add `r == Some ()` here.... let ff (_:state) : Tot (r:(option unit & state){fst r == Some () /\ snd r == s}) = (Some (), s) in ff let put (s:state) : EFF unit (fun _ -> True) (fun _ y s1 -> s1 == s) [WR] = EFF?.reflect (_put s) let _raise #a : repr a (fun _ -> True) (fun s0 _ s1 -> s1 == s0) [EXN] = let ff (s0:state) : Tot (r:(option a & state){fst r == None /\ snd r == s0}) = (None, s0) in ff let raise #a () : EFF a (fun _ -> True) (fun s0 _ s1 -> s1 == s0) [EXN] = EFF?.reflect _raise effect EFFT (a:Type) (labs:list eff_label) = EFF a (fun _ -> True) (fun _ _ _ -> True) labs
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LatticeSpec.fst" }
[ { "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: Prims.int -> y: Prims.int -> LatticeSpec.EFFT Prims.int
LatticeSpec.EFFT
[]
[]
[ "Prims.int", "Prims.op_GreaterThan", "Prims.op_Addition", "LatticeSpec.raise", "Prims.bool", "Prims.op_Subtraction", "LatticeSpec.get", "Prims.Cons", "LatticeSpec.eff_label", "LatticeSpec.RD", "LatticeSpec.EXN", "Prims.Nil" ]
[]
false
true
false
false
false
let test0 (x y: int) : EFFT int [RD; EXN] =
let z = get () in if x + z > 0 then raise () else y - z
false
Pulse.Lib.InvList.fsti
Pulse.Lib.InvList.invlist_elem
val invlist_elem : Type
let invlist_elem = p:vprop & inv p
{ "file_name": "share/steel/examples/pulse/lib/pledge/Pulse.Lib.InvList.fsti", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 34, "end_line": 5, "start_col": 0, "start_line": 5 }
module Pulse.Lib.InvList open Pulse.Lib.Pervasives
{ "checked_file": "/", "dependencies": [ "Pulse.Lib.Priv.Trade0.fsti.checked", "Pulse.Lib.Pervasives.fst.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Lib.InvList.fsti" }
[ { "abbrev": false, "full_module": "Pulse.Lib.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
Type
Prims.Tot
[ "total" ]
[]
[ "Prims.dtuple2", "Pulse.Lib.Core.vprop", "Pulse.Lib.Core.inv" ]
[]
false
false
false
true
true
let invlist_elem =
p: vprop & inv p
false
LatticeSpec.fst
LatticeSpec._put
val _put (s: state) : repr unit (fun _ -> True) (fun _ y s1 -> s1 == s /\ y == Some ()) [WR]
val _put (s: state) : repr unit (fun _ -> True) (fun _ y s1 -> s1 == s /\ y == Some ()) [WR]
let _put (s:state) : repr unit (fun _ -> True) (fun _ y s1 -> s1 == s /\ y == Some ()) [WR] = // GM: pretty odd that I have to add `r == Some ()` here.... let ff (_:state) : Tot (r:(option unit & state){fst r == Some () /\ snd r == s}) = (Some (), s) in ff
{ "file_name": "examples/layeredeffects/LatticeSpec.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 4, "end_line": 207, "start_col": 0, "start_line": 202 }
module LatticeSpec open FStar.Tactics.V2 open FStar.List.Tot // 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 = | RD | WR | EXN type annot = eff_label -> bool // warning: if this is not annotated, `eqtype` is inferred // as its type and the effect definition fails for some reason. type state : Type = int type pre_t = state -> Type0 type post_t a = state -> option a -> state -> Type0 // this repr doesn't seem to work too well type repr0 (a:Type u#aa) (pre : pre_t) (post : post_t u#aa a) // #2074 : Type u#aa = s0:state{pre s0} -> Tot (r:(option a & state){post s0 (fst r) (snd r)}) let abides #a #pre #post (f : repr0 a pre post) (ann:annot) : Type0 = (ann RD = false ==> (forall s0 s1. fst (f s0) == fst (f s1))) /\ (ann WR = false ==> (forall s0. snd (f s0) == s0)) /\ (ann EXN = false ==> (forall s0. Some? (fst (f s0)))) let interp (l : list eff_label) : annot = fun lab -> mem lab 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 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 type repr (a:Type u#aa) (pre : pre_t) (post : post_t u#aa a) // #2074 (labs : list u#0 eff_label) // #2074 : Type u#aa = r:(repr0 a pre post){abides r (interp labs)} let ann_le (ann1 ann2 : annot) : Type0 = forall x. ann1 x ==> ann2 x let return (a:Type u#aa) (x:a) : Tot (repr a (fun _ -> True) (fun s0 y s1 -> s0 == s1 /\ y == Some x) []) = // GM: Need to write it like this.. why? let r (s0:state) : Tot (r:(option a & state){snd r == s0 /\ fst r == Some x}) = (Some x, s0) in r unfold let bind_pre (a:Type) (pre1:pre_t) (post1:post_t a) (b:Type) (pre2:a -> pre_t) (post2:a -> post_t b) : pre_t = fun s0 -> pre1 s0 /\ (forall y s1. post1 s0 (Some y) s1 ==> pre2 y s1) unfold let bind_post (a:Type) (pre1:pre_t) (post1:post_t a) (b:Type) (pre2:a -> pre_t) (post2:a -> post_t b) : post_t b = fun s0 z s2 -> (exists s1 y. post1 s0 (Some y) s1 /\ post2 y s1 z s2) \/ (post1 s0 None s2) let bind (a b : Type) pre1 post1 (labs1 : list eff_label) pre2 post2 (labs2 : list eff_label) (c : repr a pre1 post1 labs1) (f : (x:a -> repr b (pre2 x) (post2 x) labs2)) : Tot (repr b (bind_pre a pre1 post1 b pre2 post2) (bind_post a pre1 post1 b pre2 post2) (labs1@labs2)) = let pre = bind_pre a pre1 post1 b pre2 post2 in let post = bind_post a pre1 post1 b pre2 post2 in let r (s0:state{pre s0}) : Tot (r:(option b & state){post s0 (fst r) (snd r)}) = match c s0 with | Some x, s1 -> assert (post1 s0 (Some x) s1); assert (pre2 x s1); f x s1 | None, s1 -> None, s1 in r let subcomp (a:Type) (pre1 : pre_t) (post1 : post_t a) (labs1 : list eff_label) (pre2 : pre_t) (post2 : post_t a) (labs2 : list eff_label) (f : repr a pre1 post1 labs1) : Pure (repr a pre2 post2 labs2) (requires ((forall s0. pre2 s0 ==> pre1 s0) /\ (forall s0 r s1. post1 s0 r s1 ==> post2 s0 r s1) /\ sublist labs1 labs2)) (ensures (fun _ -> True)) = f unfold let ite (p q r : Type0) = (p ==> q) /\ ((~p) ==> r) let if_then_else (a : Type) (pre1 : pre_t) (post1 : post_t a) (labs1 : list eff_label) (pre2 : pre_t) (post2 : post_t a) (labs2 : list eff_label) (f : repr a pre1 post1 labs1) (g : repr a pre2 post2 labs2) (b : bool) : Type = repr a (fun s0 -> ite b (pre1 s0) (pre2 s0)) (fun s0 y s1 -> ite b (post1 s0 y s1) (post2 s0 y s1)) (labs1@labs2) total // need this for catch!! reifiable reflectable effect { EFF (a:Type) (_:pre_t) (_:post_t a) (_:list eff_label) with {repr; return; bind; subcomp; if_then_else} } unfold let sp #a (wp : pure_wp a) : pure_post a = fun x -> ~ (wp (fun y -> ~(x == y))) unfold let post_of_wp #a (wp : pure_wp a) : post_t a = fun s0 r s1 -> s0 == s1 /\ Some? r /\ sp wp (Some?.v r) let lift_pure_eff (a:Type) (wp : pure_wp a) (f : unit -> PURE a wp) : repr a (fun _ -> wp (fun _ -> True)) (post_of_wp wp) [] = FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp; let r (s0:state{wp (fun _ -> True)}) : Tot (r:(option a & state){snd r == s0 /\ Some? (fst r) /\ sp wp (Some?.v (fst r))}) = (Some (f ()), s0) in r sub_effect PURE ~> EFF = lift_pure_eff let _get : repr state (fun _ -> True) (fun s0 y s1 -> s1 == s0 /\ y == Some s0) [RD] = let ff (s0:state) : Tot (r:(option state & state){fst r == Some s0 /\ snd r == s0}) = (Some s0, s0) in ff let get () : EFF int (fun _ -> True) (fun s0 y s1 -> s1 == s0 /\ y == Some s0) [RD] by (compute (); dump"") = EFF?.reflect _get
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LatticeSpec.fst" }
[ { "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: LatticeSpec.state -> LatticeSpec.repr Prims.unit (fun _ -> Prims.l_True) (fun _ y s1 -> s1 == s /\ y == FStar.Pervasives.Native.Some ()) [LatticeSpec.WR]
Prims.Tot
[ "total" ]
[]
[ "LatticeSpec.state", "FStar.Pervasives.Native.tuple2", "FStar.Pervasives.Native.option", "Prims.unit", "Prims.l_and", "Prims.eq2", "FStar.Pervasives.Native.fst", "FStar.Pervasives.Native.Some", "FStar.Pervasives.Native.snd", "FStar.Pervasives.Native.Mktuple2", "LatticeSpec.repr", "Prims.l_True", "Prims.Cons", "LatticeSpec.eff_label", "LatticeSpec.WR", "Prims.Nil" ]
[]
false
false
false
false
false
let _put (s: state) : repr unit (fun _ -> True) (fun _ y s1 -> s1 == s /\ y == Some ()) [WR] =
let ff (_: state) : Tot (r: (option unit & state){fst r == Some () /\ snd r == s}) = (Some (), s) in ff
false
LatticeSpec.fst
LatticeSpec.lift_pure_eff
val lift_pure_eff (a: Type) (wp: pure_wp a) (f: (unit -> PURE a wp)) : repr a (fun _ -> wp (fun _ -> True)) (post_of_wp wp) []
val lift_pure_eff (a: Type) (wp: pure_wp a) (f: (unit -> PURE a wp)) : repr a (fun _ -> wp (fun _ -> True)) (post_of_wp wp) []
let lift_pure_eff (a:Type) (wp : pure_wp a) (f : unit -> PURE a wp) : repr a (fun _ -> wp (fun _ -> True)) (post_of_wp wp) [] = FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp; let r (s0:state{wp (fun _ -> True)}) : Tot (r:(option a & state){snd r == s0 /\ Some? (fst r) /\ sp wp (Some?.v (fst r))}) = (Some (f ()), s0) in r
{ "file_name": "examples/layeredeffects/LatticeSpec.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 4, "end_line": 189, "start_col": 0, "start_line": 178 }
module LatticeSpec open FStar.Tactics.V2 open FStar.List.Tot // 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 = | RD | WR | EXN type annot = eff_label -> bool // warning: if this is not annotated, `eqtype` is inferred // as its type and the effect definition fails for some reason. type state : Type = int type pre_t = state -> Type0 type post_t a = state -> option a -> state -> Type0 // this repr doesn't seem to work too well type repr0 (a:Type u#aa) (pre : pre_t) (post : post_t u#aa a) // #2074 : Type u#aa = s0:state{pre s0} -> Tot (r:(option a & state){post s0 (fst r) (snd r)}) let abides #a #pre #post (f : repr0 a pre post) (ann:annot) : Type0 = (ann RD = false ==> (forall s0 s1. fst (f s0) == fst (f s1))) /\ (ann WR = false ==> (forall s0. snd (f s0) == s0)) /\ (ann EXN = false ==> (forall s0. Some? (fst (f s0)))) let interp (l : list eff_label) : annot = fun lab -> mem lab 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 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 type repr (a:Type u#aa) (pre : pre_t) (post : post_t u#aa a) // #2074 (labs : list u#0 eff_label) // #2074 : Type u#aa = r:(repr0 a pre post){abides r (interp labs)} let ann_le (ann1 ann2 : annot) : Type0 = forall x. ann1 x ==> ann2 x let return (a:Type u#aa) (x:a) : Tot (repr a (fun _ -> True) (fun s0 y s1 -> s0 == s1 /\ y == Some x) []) = // GM: Need to write it like this.. why? let r (s0:state) : Tot (r:(option a & state){snd r == s0 /\ fst r == Some x}) = (Some x, s0) in r unfold let bind_pre (a:Type) (pre1:pre_t) (post1:post_t a) (b:Type) (pre2:a -> pre_t) (post2:a -> post_t b) : pre_t = fun s0 -> pre1 s0 /\ (forall y s1. post1 s0 (Some y) s1 ==> pre2 y s1) unfold let bind_post (a:Type) (pre1:pre_t) (post1:post_t a) (b:Type) (pre2:a -> pre_t) (post2:a -> post_t b) : post_t b = fun s0 z s2 -> (exists s1 y. post1 s0 (Some y) s1 /\ post2 y s1 z s2) \/ (post1 s0 None s2) let bind (a b : Type) pre1 post1 (labs1 : list eff_label) pre2 post2 (labs2 : list eff_label) (c : repr a pre1 post1 labs1) (f : (x:a -> repr b (pre2 x) (post2 x) labs2)) : Tot (repr b (bind_pre a pre1 post1 b pre2 post2) (bind_post a pre1 post1 b pre2 post2) (labs1@labs2)) = let pre = bind_pre a pre1 post1 b pre2 post2 in let post = bind_post a pre1 post1 b pre2 post2 in let r (s0:state{pre s0}) : Tot (r:(option b & state){post s0 (fst r) (snd r)}) = match c s0 with | Some x, s1 -> assert (post1 s0 (Some x) s1); assert (pre2 x s1); f x s1 | None, s1 -> None, s1 in r let subcomp (a:Type) (pre1 : pre_t) (post1 : post_t a) (labs1 : list eff_label) (pre2 : pre_t) (post2 : post_t a) (labs2 : list eff_label) (f : repr a pre1 post1 labs1) : Pure (repr a pre2 post2 labs2) (requires ((forall s0. pre2 s0 ==> pre1 s0) /\ (forall s0 r s1. post1 s0 r s1 ==> post2 s0 r s1) /\ sublist labs1 labs2)) (ensures (fun _ -> True)) = f unfold let ite (p q r : Type0) = (p ==> q) /\ ((~p) ==> r) let if_then_else (a : Type) (pre1 : pre_t) (post1 : post_t a) (labs1 : list eff_label) (pre2 : pre_t) (post2 : post_t a) (labs2 : list eff_label) (f : repr a pre1 post1 labs1) (g : repr a pre2 post2 labs2) (b : bool) : Type = repr a (fun s0 -> ite b (pre1 s0) (pre2 s0)) (fun s0 y s1 -> ite b (post1 s0 y s1) (post2 s0 y s1)) (labs1@labs2) total // need this for catch!! reifiable reflectable effect { EFF (a:Type) (_:pre_t) (_:post_t a) (_:list eff_label) with {repr; return; bind; subcomp; if_then_else} } unfold let sp #a (wp : pure_wp a) : pure_post a = fun x -> ~ (wp (fun y -> ~(x == y))) unfold let post_of_wp #a (wp : pure_wp a) : post_t a = fun s0 r s1 -> s0 == s1 /\ Some? r /\ sp wp (Some?.v r)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LatticeSpec.fst" }
[ { "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) -> LatticeSpec.repr a (fun _ -> wp (fun _ -> Prims.l_True)) (LatticeSpec.post_of_wp wp) []
Prims.Tot
[ "total" ]
[]
[ "Prims.pure_wp", "Prims.unit", "LatticeSpec.state", "Prims.l_True", "FStar.Pervasives.Native.tuple2", "FStar.Pervasives.Native.option", "Prims.l_and", "Prims.eq2", "FStar.Pervasives.Native.snd", "Prims.b2t", "FStar.Pervasives.Native.uu___is_Some", "FStar.Pervasives.Native.fst", "Prims.l_not", "FStar.Pervasives.Native.__proj__Some__item__v", "FStar.Pervasives.Native.Mktuple2", "FStar.Pervasives.Native.Some", "LatticeSpec.sp", "FStar.Monotonic.Pure.elim_pure_wp_monotonicity", "LatticeSpec.repr", "LatticeSpec.post_of_wp", "Prims.Nil", "LatticeSpec.eff_label" ]
[]
false
false
false
false
false
let lift_pure_eff (a: Type) (wp: pure_wp a) (f: (unit -> PURE a wp)) : repr a (fun _ -> wp (fun _ -> True)) (post_of_wp wp) [] =
FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp; let r (s0: state{wp (fun _ -> True)}) : Tot (r: (option a & state){snd r == s0 /\ Some? (fst r) /\ sp wp (Some?.v (fst r))}) = (Some (f ()), s0) in r
false
LatticeSpec.fst
LatticeSpec._raise
val _raise (#a: _) : repr a (fun _ -> True) (fun s0 _ s1 -> s1 == s0) [EXN]
val _raise (#a: _) : repr a (fun _ -> True) (fun s0 _ s1 -> s1 == s0) [EXN]
let _raise #a : repr a (fun _ -> True) (fun s0 _ s1 -> s1 == s0) [EXN] = let ff (s0:state) : Tot (r:(option a & state){fst r == None /\ snd r == s0}) = (None, s0) in ff
{ "file_name": "examples/layeredeffects/LatticeSpec.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 4, "end_line": 216, "start_col": 0, "start_line": 212 }
module LatticeSpec open FStar.Tactics.V2 open FStar.List.Tot // 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 = | RD | WR | EXN type annot = eff_label -> bool // warning: if this is not annotated, `eqtype` is inferred // as its type and the effect definition fails for some reason. type state : Type = int type pre_t = state -> Type0 type post_t a = state -> option a -> state -> Type0 // this repr doesn't seem to work too well type repr0 (a:Type u#aa) (pre : pre_t) (post : post_t u#aa a) // #2074 : Type u#aa = s0:state{pre s0} -> Tot (r:(option a & state){post s0 (fst r) (snd r)}) let abides #a #pre #post (f : repr0 a pre post) (ann:annot) : Type0 = (ann RD = false ==> (forall s0 s1. fst (f s0) == fst (f s1))) /\ (ann WR = false ==> (forall s0. snd (f s0) == s0)) /\ (ann EXN = false ==> (forall s0. Some? (fst (f s0)))) let interp (l : list eff_label) : annot = fun lab -> mem lab 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 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 type repr (a:Type u#aa) (pre : pre_t) (post : post_t u#aa a) // #2074 (labs : list u#0 eff_label) // #2074 : Type u#aa = r:(repr0 a pre post){abides r (interp labs)} let ann_le (ann1 ann2 : annot) : Type0 = forall x. ann1 x ==> ann2 x let return (a:Type u#aa) (x:a) : Tot (repr a (fun _ -> True) (fun s0 y s1 -> s0 == s1 /\ y == Some x) []) = // GM: Need to write it like this.. why? let r (s0:state) : Tot (r:(option a & state){snd r == s0 /\ fst r == Some x}) = (Some x, s0) in r unfold let bind_pre (a:Type) (pre1:pre_t) (post1:post_t a) (b:Type) (pre2:a -> pre_t) (post2:a -> post_t b) : pre_t = fun s0 -> pre1 s0 /\ (forall y s1. post1 s0 (Some y) s1 ==> pre2 y s1) unfold let bind_post (a:Type) (pre1:pre_t) (post1:post_t a) (b:Type) (pre2:a -> pre_t) (post2:a -> post_t b) : post_t b = fun s0 z s2 -> (exists s1 y. post1 s0 (Some y) s1 /\ post2 y s1 z s2) \/ (post1 s0 None s2) let bind (a b : Type) pre1 post1 (labs1 : list eff_label) pre2 post2 (labs2 : list eff_label) (c : repr a pre1 post1 labs1) (f : (x:a -> repr b (pre2 x) (post2 x) labs2)) : Tot (repr b (bind_pre a pre1 post1 b pre2 post2) (bind_post a pre1 post1 b pre2 post2) (labs1@labs2)) = let pre = bind_pre a pre1 post1 b pre2 post2 in let post = bind_post a pre1 post1 b pre2 post2 in let r (s0:state{pre s0}) : Tot (r:(option b & state){post s0 (fst r) (snd r)}) = match c s0 with | Some x, s1 -> assert (post1 s0 (Some x) s1); assert (pre2 x s1); f x s1 | None, s1 -> None, s1 in r let subcomp (a:Type) (pre1 : pre_t) (post1 : post_t a) (labs1 : list eff_label) (pre2 : pre_t) (post2 : post_t a) (labs2 : list eff_label) (f : repr a pre1 post1 labs1) : Pure (repr a pre2 post2 labs2) (requires ((forall s0. pre2 s0 ==> pre1 s0) /\ (forall s0 r s1. post1 s0 r s1 ==> post2 s0 r s1) /\ sublist labs1 labs2)) (ensures (fun _ -> True)) = f unfold let ite (p q r : Type0) = (p ==> q) /\ ((~p) ==> r) let if_then_else (a : Type) (pre1 : pre_t) (post1 : post_t a) (labs1 : list eff_label) (pre2 : pre_t) (post2 : post_t a) (labs2 : list eff_label) (f : repr a pre1 post1 labs1) (g : repr a pre2 post2 labs2) (b : bool) : Type = repr a (fun s0 -> ite b (pre1 s0) (pre2 s0)) (fun s0 y s1 -> ite b (post1 s0 y s1) (post2 s0 y s1)) (labs1@labs2) total // need this for catch!! reifiable reflectable effect { EFF (a:Type) (_:pre_t) (_:post_t a) (_:list eff_label) with {repr; return; bind; subcomp; if_then_else} } unfold let sp #a (wp : pure_wp a) : pure_post a = fun x -> ~ (wp (fun y -> ~(x == y))) unfold let post_of_wp #a (wp : pure_wp a) : post_t a = fun s0 r s1 -> s0 == s1 /\ Some? r /\ sp wp (Some?.v r) let lift_pure_eff (a:Type) (wp : pure_wp a) (f : unit -> PURE a wp) : repr a (fun _ -> wp (fun _ -> True)) (post_of_wp wp) [] = FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp; let r (s0:state{wp (fun _ -> True)}) : Tot (r:(option a & state){snd r == s0 /\ Some? (fst r) /\ sp wp (Some?.v (fst r))}) = (Some (f ()), s0) in r sub_effect PURE ~> EFF = lift_pure_eff let _get : repr state (fun _ -> True) (fun s0 y s1 -> s1 == s0 /\ y == Some s0) [RD] = let ff (s0:state) : Tot (r:(option state & state){fst r == Some s0 /\ snd r == s0}) = (Some s0, s0) in ff let get () : EFF int (fun _ -> True) (fun s0 y s1 -> s1 == s0 /\ y == Some s0) [RD] by (compute (); dump"") = EFF?.reflect _get let _put (s:state) : repr unit (fun _ -> True) (fun _ y s1 -> s1 == s /\ y == Some ()) [WR] = // GM: pretty odd that I have to add `r == Some ()` here.... let ff (_:state) : Tot (r:(option unit & state){fst r == Some () /\ snd r == s}) = (Some (), s) in ff let put (s:state) : EFF unit (fun _ -> True) (fun _ y s1 -> s1 == s) [WR] = EFF?.reflect (_put s)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LatticeSpec.fst" }
[ { "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
LatticeSpec.repr a (fun _ -> Prims.l_True) (fun s0 _ s1 -> s1 == s0) [LatticeSpec.EXN]
Prims.Tot
[ "total" ]
[]
[ "LatticeSpec.state", "FStar.Pervasives.Native.tuple2", "FStar.Pervasives.Native.option", "Prims.l_and", "Prims.eq2", "FStar.Pervasives.Native.fst", "FStar.Pervasives.Native.None", "FStar.Pervasives.Native.snd", "FStar.Pervasives.Native.Mktuple2", "LatticeSpec.repr", "Prims.l_True", "Prims.Cons", "LatticeSpec.eff_label", "LatticeSpec.EXN", "Prims.Nil" ]
[]
false
false
false
false
false
let _raise #a : repr a (fun _ -> True) (fun s0 _ s1 -> s1 == s0) [EXN] =
let ff (s0: state) : Tot (r: (option a & state){fst r == None /\ snd r == s0}) = (None, s0) in ff
false
Pulse.Lib.InvList.fsti
Pulse.Lib.InvList.invlist0
val invlist0 : Type
let invlist0 = list invlist_elem
{ "file_name": "share/steel/examples/pulse/lib/pledge/Pulse.Lib.InvList.fsti", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 32, "end_line": 6, "start_col": 0, "start_line": 6 }
module Pulse.Lib.InvList open Pulse.Lib.Pervasives
{ "checked_file": "/", "dependencies": [ "Pulse.Lib.Priv.Trade0.fsti.checked", "Pulse.Lib.Pervasives.fst.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Lib.InvList.fsti" }
[ { "abbrev": false, "full_module": "Pulse.Lib.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
Type
Prims.Tot
[ "total" ]
[]
[ "Prims.list", "Pulse.Lib.InvList.invlist_elem" ]
[]
false
false
false
true
true
let invlist0 =
list invlist_elem
false
LowParse.Low.Writers.Instances.fst
LowParse.Low.Writers.Instances.swrite_weaken
val swrite_weaken (#h0: HS.mem) (#sout: slice (srel_of_buffer_srel (B.trivial_preorder _)) (srel_of_buffer_srel (B.trivial_preorder _))) (#pout_from0: U32.t) (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#s1: serializer p1 {k1.parser_kind_subkind == Some ParserStrong}) (#space_beyond: nat) (k2: parser_kind) (w1: swriter s1 h0 space_beyond sout pout_from0 {(k2 `is_weaker_than` k1) /\ k2.parser_kind_subkind == Some ParserStrong}) : Tot (w2: swriter (serialize_weaken k2 s1) h0 space_beyond sout pout_from0 {swvalue w2 == swvalue w1} )
val swrite_weaken (#h0: HS.mem) (#sout: slice (srel_of_buffer_srel (B.trivial_preorder _)) (srel_of_buffer_srel (B.trivial_preorder _))) (#pout_from0: U32.t) (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#s1: serializer p1 {k1.parser_kind_subkind == Some ParserStrong}) (#space_beyond: nat) (k2: parser_kind) (w1: swriter s1 h0 space_beyond sout pout_from0 {(k2 `is_weaker_than` k1) /\ k2.parser_kind_subkind == Some ParserStrong}) : Tot (w2: swriter (serialize_weaken k2 s1) h0 space_beyond sout pout_from0 {swvalue w2 == swvalue w1} )
let swrite_weaken (#h0: HS.mem) (#sout: slice (srel_of_buffer_srel (B.trivial_preorder _)) (srel_of_buffer_srel (B.trivial_preorder _))) (#pout_from0: U32.t) (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#s1: serializer p1 { k1.parser_kind_subkind == Some ParserStrong }) (#space_beyond: nat) (k2: parser_kind) (w1: swriter s1 h0 space_beyond sout pout_from0 { (k2 `is_weaker_than` k1) /\ k2.parser_kind_subkind == Some ParserStrong }) : Tot (w2: swriter (serialize_weaken k2 s1) h0 space_beyond sout pout_from0 { swvalue w2 == swvalue w1 }) = SWriter (Ghost.hide (swvalue w1)) (fun pout_from -> serialized_length_eq s1 (swvalue w1); serialized_length_eq (serialize_weaken k2 s1) (swvalue w1); let res = swrite w1 pout_from in let h = HST.get () in valid_weaken k2 p1 h sout pout_from; res )
{ "file_name": "src/lowparse/LowParse.Low.Writers.Instances.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 3, "end_line": 38, "start_col": 0, "start_line": 14 }
module LowParse.Low.Writers.Instances include LowParse.Low.Writers include LowParse.Low.Combinators include LowParse.Low.Bytes include LowParse.Low.BitSum module HS = FStar.HyperStack module B = LowStar.Buffer module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST inline_for_extraction
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Endianness.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Low.Writers.fst.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Low.Bytes.fst.checked", "LowParse.Low.BitSum.fst.checked", "LowParse.Endianness.BitFields.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Bytes.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Low.Writers.Instances.fst" }
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "LowParse.Low.BitSum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Bytes", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Writers", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Writers", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Writers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
k2: LowParse.Spec.Base.parser_kind -> w1: LowParse.Low.Writers.swriter s1 h0 space_beyond sout pout_from0 { LowParse.Spec.Base.is_weaker_than k2 k1 /\ Mkparser_kind'?.parser_kind_subkind k2 == FStar.Pervasives.Native.Some LowParse.Spec.Base.ParserStrong } -> w2: LowParse.Low.Writers.swriter (LowParse.Spec.Combinators.serialize_weaken k2 s1) h0 space_beyond sout pout_from0 {LowParse.Low.Writers.swvalue w2 == LowParse.Low.Writers.swvalue w1}
Prims.Tot
[ "total" ]
[]
[ "FStar.Monotonic.HyperStack.mem", "LowParse.Slice.slice", "LowParse.Slice.srel_of_buffer_srel", "LowParse.Bytes.byte", "LowStar.Buffer.trivial_preorder", "FStar.UInt32.t", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Spec.Base.serializer", "Prims.eq2", "FStar.Pervasives.Native.option", "LowParse.Spec.Base.parser_subkind", "LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_subkind", "FStar.Pervasives.Native.Some", "LowParse.Spec.Base.ParserStrong", "Prims.nat", "LowParse.Low.Writers.swriter", "Prims.l_and", "LowParse.Spec.Base.is_weaker_than", "LowParse.Low.Writers.SWriter", "LowParse.Spec.Base.weaken", "LowParse.Spec.Combinators.serialize_weaken", "FStar.Ghost.hide", "LowParse.Low.Writers.swvalue", "Prims.unit", "LowParse.Low.Base.valid_weaken", "FStar.HyperStack.ST.get", "LowParse.Low.Writers.swrite", "LowParse.Low.Base.Spec.serialized_length_eq" ]
[]
false
false
false
false
false
let swrite_weaken (#h0: HS.mem) (#sout: slice (srel_of_buffer_srel (B.trivial_preorder _)) (srel_of_buffer_srel (B.trivial_preorder _))) (#pout_from0: U32.t) (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#s1: serializer p1 {k1.parser_kind_subkind == Some ParserStrong}) (#space_beyond: nat) (k2: parser_kind) (w1: swriter s1 h0 space_beyond sout pout_from0 {(k2 `is_weaker_than` k1) /\ k2.parser_kind_subkind == Some ParserStrong}) : Tot (w2: swriter (serialize_weaken k2 s1) h0 space_beyond sout pout_from0 {swvalue w2 == swvalue w1} ) =
SWriter (Ghost.hide (swvalue w1)) (fun pout_from -> serialized_length_eq s1 (swvalue w1); serialized_length_eq (serialize_weaken k2 s1) (swvalue w1); let res = swrite w1 pout_from in let h = HST.get () in valid_weaken k2 p1 h sout pout_from; res)
false
LatticeSpec.fst
LatticeSpec.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/LatticeSpec.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 65, "end_line": 239, "start_col": 0, "start_line": 236 }
module LatticeSpec open FStar.Tactics.V2 open FStar.List.Tot // 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 = | RD | WR | EXN type annot = eff_label -> bool // warning: if this is not annotated, `eqtype` is inferred // as its type and the effect definition fails for some reason. type state : Type = int type pre_t = state -> Type0 type post_t a = state -> option a -> state -> Type0 // this repr doesn't seem to work too well type repr0 (a:Type u#aa) (pre : pre_t) (post : post_t u#aa a) // #2074 : Type u#aa = s0:state{pre s0} -> Tot (r:(option a & state){post s0 (fst r) (snd r)}) let abides #a #pre #post (f : repr0 a pre post) (ann:annot) : Type0 = (ann RD = false ==> (forall s0 s1. fst (f s0) == fst (f s1))) /\ (ann WR = false ==> (forall s0. snd (f s0) == s0)) /\ (ann EXN = false ==> (forall s0. Some? (fst (f s0)))) let interp (l : list eff_label) : annot = fun lab -> mem lab 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 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 type repr (a:Type u#aa) (pre : pre_t) (post : post_t u#aa a) // #2074 (labs : list u#0 eff_label) // #2074 : Type u#aa = r:(repr0 a pre post){abides r (interp labs)} let ann_le (ann1 ann2 : annot) : Type0 = forall x. ann1 x ==> ann2 x let return (a:Type u#aa) (x:a) : Tot (repr a (fun _ -> True) (fun s0 y s1 -> s0 == s1 /\ y == Some x) []) = // GM: Need to write it like this.. why? let r (s0:state) : Tot (r:(option a & state){snd r == s0 /\ fst r == Some x}) = (Some x, s0) in r unfold let bind_pre (a:Type) (pre1:pre_t) (post1:post_t a) (b:Type) (pre2:a -> pre_t) (post2:a -> post_t b) : pre_t = fun s0 -> pre1 s0 /\ (forall y s1. post1 s0 (Some y) s1 ==> pre2 y s1) unfold let bind_post (a:Type) (pre1:pre_t) (post1:post_t a) (b:Type) (pre2:a -> pre_t) (post2:a -> post_t b) : post_t b = fun s0 z s2 -> (exists s1 y. post1 s0 (Some y) s1 /\ post2 y s1 z s2) \/ (post1 s0 None s2) let bind (a b : Type) pre1 post1 (labs1 : list eff_label) pre2 post2 (labs2 : list eff_label) (c : repr a pre1 post1 labs1) (f : (x:a -> repr b (pre2 x) (post2 x) labs2)) : Tot (repr b (bind_pre a pre1 post1 b pre2 post2) (bind_post a pre1 post1 b pre2 post2) (labs1@labs2)) = let pre = bind_pre a pre1 post1 b pre2 post2 in let post = bind_post a pre1 post1 b pre2 post2 in let r (s0:state{pre s0}) : Tot (r:(option b & state){post s0 (fst r) (snd r)}) = match c s0 with | Some x, s1 -> assert (post1 s0 (Some x) s1); assert (pre2 x s1); f x s1 | None, s1 -> None, s1 in r let subcomp (a:Type) (pre1 : pre_t) (post1 : post_t a) (labs1 : list eff_label) (pre2 : pre_t) (post2 : post_t a) (labs2 : list eff_label) (f : repr a pre1 post1 labs1) : Pure (repr a pre2 post2 labs2) (requires ((forall s0. pre2 s0 ==> pre1 s0) /\ (forall s0 r s1. post1 s0 r s1 ==> post2 s0 r s1) /\ sublist labs1 labs2)) (ensures (fun _ -> True)) = f unfold let ite (p q r : Type0) = (p ==> q) /\ ((~p) ==> r) let if_then_else (a : Type) (pre1 : pre_t) (post1 : post_t a) (labs1 : list eff_label) (pre2 : pre_t) (post2 : post_t a) (labs2 : list eff_label) (f : repr a pre1 post1 labs1) (g : repr a pre2 post2 labs2) (b : bool) : Type = repr a (fun s0 -> ite b (pre1 s0) (pre2 s0)) (fun s0 y s1 -> ite b (post1 s0 y s1) (post2 s0 y s1)) (labs1@labs2) total // need this for catch!! reifiable reflectable effect { EFF (a:Type) (_:pre_t) (_:post_t a) (_:list eff_label) with {repr; return; bind; subcomp; if_then_else} } unfold let sp #a (wp : pure_wp a) : pure_post a = fun x -> ~ (wp (fun y -> ~(x == y))) unfold let post_of_wp #a (wp : pure_wp a) : post_t a = fun s0 r s1 -> s0 == s1 /\ Some? r /\ sp wp (Some?.v r) let lift_pure_eff (a:Type) (wp : pure_wp a) (f : unit -> PURE a wp) : repr a (fun _ -> wp (fun _ -> True)) (post_of_wp wp) [] = FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp; let r (s0:state{wp (fun _ -> True)}) : Tot (r:(option a & state){snd r == s0 /\ Some? (fst r) /\ sp wp (Some?.v (fst r))}) = (Some (f ()), s0) in r sub_effect PURE ~> EFF = lift_pure_eff let _get : repr state (fun _ -> True) (fun s0 y s1 -> s1 == s0 /\ y == Some s0) [RD] = let ff (s0:state) : Tot (r:(option state & state){fst r == Some s0 /\ snd r == s0}) = (Some s0, s0) in ff let get () : EFF int (fun _ -> True) (fun s0 y s1 -> s1 == s0 /\ y == Some s0) [RD] by (compute (); dump"") = EFF?.reflect _get let _put (s:state) : repr unit (fun _ -> True) (fun _ y s1 -> s1 == s /\ y == Some ()) [WR] = // GM: pretty odd that I have to add `r == Some ()` here.... let ff (_:state) : Tot (r:(option unit & state){fst r == Some () /\ snd r == s}) = (Some (), s) in ff let put (s:state) : EFF unit (fun _ -> True) (fun _ y s1 -> s1 == s) [WR] = EFF?.reflect (_put s) let _raise #a : repr a (fun _ -> True) (fun s0 _ s1 -> s1 == s0) [EXN] = let ff (s0:state) : Tot (r:(option a & state){fst r == None /\ snd r == s0}) = (None, s0) in ff let raise #a () : EFF a (fun _ -> True) (fun s0 _ s1 -> s1 == s0) [EXN] = EFF?.reflect _raise effect EFFT (a:Type) (labs:list eff_label) = EFF a (fun _ -> True) (fun _ _ _ -> True) labs let test0 (x y : int) : EFFT int [RD; EXN] = let z = get () in if x + z > 0 then raise () else y - z // need compute let test1 (x y : int) : EFFT int [EXN; RD; WR] by (compute ())= let z = get () in if x + z > 0 then raise () else (put 42; y - z)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LatticeSpec.fst" }
[ { "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 LatticeSpec.eff_label -> FStar.Pervasives.Lemma (ensures LatticeSpec.sublist (l1 @ l1) l1) [SMTPat (l1 @ l1)]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.list", "LatticeSpec.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", "LatticeSpec.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
PulseCore.Preorder.fst
PulseCore.Preorder.hist
val hist : q: FStar.Preorder.preorder a -> Type
let hist (#a: Type u#a) (q:preorder a) = l:list a{qhistory q l}
{ "file_name": "lib/pulse_core/PulseCore.Preorder.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 63, "end_line": 94, "start_col": 0, "start_line": 94 }
(* 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 PulseCore.Preorder open FStar.PCM open FStar.Preorder open PulseCore.FractionalPermission open FStar.Real /// This module explores the connection between PCM and preorders. More specifically, we show here /// that any PCM induces a preorder relation, characterized by frame-preservation for any updates. /// /// Furthermore, we also consider the reverse relationship where we derive a PCM for any preorder, /// by taking as elements of the PCM the trace of all the states of the element. (**** PCM to preoder *) (** PCM [p] induces the preorder [q] if for any frame preserving update of [x] to [y], the argument and result of the frame preserving update are related by q *) let induces_preorder (#a:Type u#a) (p:pcm a) (q:preorder a) = forall (x y:a) (f:frame_preserving_upd p x y) (v:a). p.refine v ==> compatible p x v ==> q v (f v) (** We can define a canonical preorder from any PCM by taking the quantified conjunction over all the preorders [q] induced by this PCM. *) let preorder_of_pcm (#a:Type u#a) (p:pcm a) : preorder a = fun x y -> forall (q:preorder a). induces_preorder p q ==> q x y let frame_preserving_upd_is_preorder_preserving (#a:Type u#a) (p:pcm a) (x y:a) (f:frame_preserving_upd p x y) (v_old:a{p.refine v_old /\ compatible p x v_old}) : Lemma ((preorder_of_pcm p) v_old (f v_old)) = () (** This canonical preorder enjoys the nice property that it preserves fact stability of any induced preorder *) let stability (#a: Type u#a) (fact:a -> prop) (q:preorder a) (p:pcm a) : Lemma (requires stable fact q /\ induces_preorder p q) (ensures stable fact (preorder_of_pcm p)) = () let stable_compatiblity (#a:Type u#a) (fact: a -> prop) (p:pcm a) (v v0 v1:a) : Lemma (requires stable fact (preorder_of_pcm p) /\ p.refine v0 /\ fact v0 /\ p.refine v1 /\ frame_preserving p v v1 /\ compatible p v v0) (ensures fact v1) = let f : frame_preserving_upd p v v1 = frame_preserving_val_to_fp_upd p v v1 in frame_preserving_upd_is_preorder_preserving p v v1 f v0 (**** Preorder to PCM *) (***** Building the preorder *) (** This predicate tells that the list [l] can represent a trace of elements whose evolution is compatible with the preorder [q] *) let rec qhistory #a (q:preorder a) (l:list a) = match l with | [] | [_] -> True | x::y::tl -> y `q` x /\ qhistory q (y::tl)
{ "checked_file": "/", "dependencies": [ "PulseCore.FractionalPermission.fst.checked", "prims.fst.checked", "FStar.Real.fsti.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked", "FStar.List.Tot.fst.checked", "FStar.IndefiniteDescription.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "PulseCore.Preorder.fst" }
[ { "abbrev": false, "full_module": "FStar.Real", "short_module": null }, { "abbrev": false, "full_module": "PulseCore.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "FStar.Preorder", "short_module": null }, { "abbrev": false, "full_module": "FStar.PCM", "short_module": null }, { "abbrev": false, "full_module": "PulseCore", "short_module": null }, { "abbrev": false, "full_module": "PulseCore", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
q: FStar.Preorder.preorder a -> Type
Prims.Tot
[ "total" ]
[]
[ "FStar.Preorder.preorder", "Prims.list", "PulseCore.Preorder.qhistory" ]
[]
false
false
false
true
true
let hist (#a: Type u#a) (q: preorder a) =
l: list a {qhistory q l}
false
LatticeSpec.fst
LatticeSpec._get
val _get:repr state (fun _ -> True) (fun s0 y s1 -> s1 == s0 /\ y == Some s0) [RD]
val _get:repr state (fun _ -> True) (fun s0 y s1 -> s1 == s0 /\ y == Some s0) [RD]
let _get : repr state (fun _ -> True) (fun s0 y s1 -> s1 == s0 /\ y == Some s0) [RD] = let ff (s0:state) : Tot (r:(option state & state){fst r == Some s0 /\ snd r == s0}) = (Some s0, s0) in ff
{ "file_name": "examples/layeredeffects/LatticeSpec.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 4, "end_line": 197, "start_col": 0, "start_line": 193 }
module LatticeSpec open FStar.Tactics.V2 open FStar.List.Tot // 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 = | RD | WR | EXN type annot = eff_label -> bool // warning: if this is not annotated, `eqtype` is inferred // as its type and the effect definition fails for some reason. type state : Type = int type pre_t = state -> Type0 type post_t a = state -> option a -> state -> Type0 // this repr doesn't seem to work too well type repr0 (a:Type u#aa) (pre : pre_t) (post : post_t u#aa a) // #2074 : Type u#aa = s0:state{pre s0} -> Tot (r:(option a & state){post s0 (fst r) (snd r)}) let abides #a #pre #post (f : repr0 a pre post) (ann:annot) : Type0 = (ann RD = false ==> (forall s0 s1. fst (f s0) == fst (f s1))) /\ (ann WR = false ==> (forall s0. snd (f s0) == s0)) /\ (ann EXN = false ==> (forall s0. Some? (fst (f s0)))) let interp (l : list eff_label) : annot = fun lab -> mem lab 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 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 type repr (a:Type u#aa) (pre : pre_t) (post : post_t u#aa a) // #2074 (labs : list u#0 eff_label) // #2074 : Type u#aa = r:(repr0 a pre post){abides r (interp labs)} let ann_le (ann1 ann2 : annot) : Type0 = forall x. ann1 x ==> ann2 x let return (a:Type u#aa) (x:a) : Tot (repr a (fun _ -> True) (fun s0 y s1 -> s0 == s1 /\ y == Some x) []) = // GM: Need to write it like this.. why? let r (s0:state) : Tot (r:(option a & state){snd r == s0 /\ fst r == Some x}) = (Some x, s0) in r unfold let bind_pre (a:Type) (pre1:pre_t) (post1:post_t a) (b:Type) (pre2:a -> pre_t) (post2:a -> post_t b) : pre_t = fun s0 -> pre1 s0 /\ (forall y s1. post1 s0 (Some y) s1 ==> pre2 y s1) unfold let bind_post (a:Type) (pre1:pre_t) (post1:post_t a) (b:Type) (pre2:a -> pre_t) (post2:a -> post_t b) : post_t b = fun s0 z s2 -> (exists s1 y. post1 s0 (Some y) s1 /\ post2 y s1 z s2) \/ (post1 s0 None s2) let bind (a b : Type) pre1 post1 (labs1 : list eff_label) pre2 post2 (labs2 : list eff_label) (c : repr a pre1 post1 labs1) (f : (x:a -> repr b (pre2 x) (post2 x) labs2)) : Tot (repr b (bind_pre a pre1 post1 b pre2 post2) (bind_post a pre1 post1 b pre2 post2) (labs1@labs2)) = let pre = bind_pre a pre1 post1 b pre2 post2 in let post = bind_post a pre1 post1 b pre2 post2 in let r (s0:state{pre s0}) : Tot (r:(option b & state){post s0 (fst r) (snd r)}) = match c s0 with | Some x, s1 -> assert (post1 s0 (Some x) s1); assert (pre2 x s1); f x s1 | None, s1 -> None, s1 in r let subcomp (a:Type) (pre1 : pre_t) (post1 : post_t a) (labs1 : list eff_label) (pre2 : pre_t) (post2 : post_t a) (labs2 : list eff_label) (f : repr a pre1 post1 labs1) : Pure (repr a pre2 post2 labs2) (requires ((forall s0. pre2 s0 ==> pre1 s0) /\ (forall s0 r s1. post1 s0 r s1 ==> post2 s0 r s1) /\ sublist labs1 labs2)) (ensures (fun _ -> True)) = f unfold let ite (p q r : Type0) = (p ==> q) /\ ((~p) ==> r) let if_then_else (a : Type) (pre1 : pre_t) (post1 : post_t a) (labs1 : list eff_label) (pre2 : pre_t) (post2 : post_t a) (labs2 : list eff_label) (f : repr a pre1 post1 labs1) (g : repr a pre2 post2 labs2) (b : bool) : Type = repr a (fun s0 -> ite b (pre1 s0) (pre2 s0)) (fun s0 y s1 -> ite b (post1 s0 y s1) (post2 s0 y s1)) (labs1@labs2) total // need this for catch!! reifiable reflectable effect { EFF (a:Type) (_:pre_t) (_:post_t a) (_:list eff_label) with {repr; return; bind; subcomp; if_then_else} } unfold let sp #a (wp : pure_wp a) : pure_post a = fun x -> ~ (wp (fun y -> ~(x == y))) unfold let post_of_wp #a (wp : pure_wp a) : post_t a = fun s0 r s1 -> s0 == s1 /\ Some? r /\ sp wp (Some?.v r) let lift_pure_eff (a:Type) (wp : pure_wp a) (f : unit -> PURE a wp) : repr a (fun _ -> wp (fun _ -> True)) (post_of_wp wp) [] = FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp; let r (s0:state{wp (fun _ -> True)}) : Tot (r:(option a & state){snd r == s0 /\ Some? (fst r) /\ sp wp (Some?.v (fst r))}) = (Some (f ()), s0) in r sub_effect PURE ~> EFF = lift_pure_eff
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LatticeSpec.fst" }
[ { "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
LatticeSpec.repr LatticeSpec.state (fun _ -> Prims.l_True) (fun s0 y s1 -> s1 == s0 /\ y == FStar.Pervasives.Native.Some s0) [LatticeSpec.RD]
Prims.Tot
[ "total" ]
[]
[ "LatticeSpec.state", "FStar.Pervasives.Native.tuple2", "FStar.Pervasives.Native.option", "Prims.l_and", "Prims.eq2", "FStar.Pervasives.Native.fst", "FStar.Pervasives.Native.Some", "FStar.Pervasives.Native.snd", "FStar.Pervasives.Native.Mktuple2" ]
[]
false
false
false
false
false
let _get:repr state (fun _ -> True) (fun s0 y s1 -> s1 == s0 /\ y == Some s0) [RD] =
let ff (s0: state) : Tot (r: (option state & state){fst r == Some s0 /\ snd r == s0}) = (Some s0, s0) in ff
false
PulseCore.Preorder.fst
PulseCore.Preorder.preorder_of_pcm
val preorder_of_pcm (#a: Type u#a) (p: pcm a) : preorder a
val preorder_of_pcm (#a: Type u#a) (p: pcm a) : preorder a
let preorder_of_pcm (#a:Type u#a) (p:pcm a) : preorder a = fun x y -> forall (q:preorder a). induces_preorder p q ==> q x y
{ "file_name": "lib/pulse_core/PulseCore.Preorder.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 66, "end_line": 45, "start_col": 0, "start_line": 44 }
(* 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 PulseCore.Preorder open FStar.PCM open FStar.Preorder open PulseCore.FractionalPermission open FStar.Real /// This module explores the connection between PCM and preorders. More specifically, we show here /// that any PCM induces a preorder relation, characterized by frame-preservation for any updates. /// /// Furthermore, we also consider the reverse relationship where we derive a PCM for any preorder, /// by taking as elements of the PCM the trace of all the states of the element. (**** PCM to preoder *) (** PCM [p] induces the preorder [q] if for any frame preserving update of [x] to [y], the argument and result of the frame preserving update are related by q *) let induces_preorder (#a:Type u#a) (p:pcm a) (q:preorder a) = forall (x y:a) (f:frame_preserving_upd p x y) (v:a). p.refine v ==> compatible p x v ==> q v (f v) (** We can define a canonical preorder from any PCM by taking the quantified conjunction over all the preorders [q] induced by this PCM.
{ "checked_file": "/", "dependencies": [ "PulseCore.FractionalPermission.fst.checked", "prims.fst.checked", "FStar.Real.fsti.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked", "FStar.List.Tot.fst.checked", "FStar.IndefiniteDescription.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "PulseCore.Preorder.fst" }
[ { "abbrev": false, "full_module": "FStar.Real", "short_module": null }, { "abbrev": false, "full_module": "PulseCore.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "FStar.Preorder", "short_module": null }, { "abbrev": false, "full_module": "FStar.PCM", "short_module": null }, { "abbrev": false, "full_module": "PulseCore", "short_module": null }, { "abbrev": false, "full_module": "PulseCore", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
p: FStar.PCM.pcm a -> FStar.Preorder.preorder a
Prims.Tot
[ "total" ]
[]
[ "FStar.PCM.pcm", "Prims.l_Forall", "FStar.Preorder.preorder", "Prims.l_imp", "PulseCore.Preorder.induces_preorder", "Prims.logical" ]
[]
false
false
false
true
false
let preorder_of_pcm (#a: Type u#a) (p: pcm a) : preorder a =
fun x y -> forall (q: preorder a). induces_preorder p q ==> q x y
false
Pulse.Lib.InvList.fsti
Pulse.Lib.InvList.invlist
val invlist : Type
let invlist = i:invlist0{invlist_nodups i}
{ "file_name": "share/steel/examples/pulse/lib/pledge/Pulse.Lib.InvList.fsti", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 30, "end_line": 19, "start_col": 0, "start_line": 18 }
module Pulse.Lib.InvList open Pulse.Lib.Pervasives let invlist_elem = p:vprop & inv p let invlist0 = list invlist_elem let rec invlist_names (is : invlist0) : inames = match is with | [] -> emp_inames | i :: is -> add_iname (invlist_names is) (name_of_inv <| dsnd i) let rec invlist_nodups (is : invlist0) : prop = match is with | [] -> True | i :: is -> not (mem_inv (invlist_names is) (dsnd i)) /\ invlist_nodups is
{ "checked_file": "/", "dependencies": [ "Pulse.Lib.Priv.Trade0.fsti.checked", "Pulse.Lib.Pervasives.fst.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Lib.InvList.fsti" }
[ { "abbrev": false, "full_module": "Pulse.Lib.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
Type
Prims.Tot
[ "total" ]
[]
[ "Pulse.Lib.InvList.invlist0", "Pulse.Lib.InvList.invlist_nodups" ]
[]
false
false
false
true
true
let invlist =
i: invlist0{invlist_nodups i}
false
LatticeSpec.fst
LatticeSpec.test_catch2
val test_catch2 (f: (unit -> EFFT int [EXN; EXN; WR])) : EFFT int [EXN; WR]
val test_catch2 (f: (unit -> EFFT int [EXN; EXN; WR])) : EFFT int [EXN; WR]
let test_catch2 (f : unit -> EFFT int [EXN;EXN;WR]) : EFFT int [EXN;WR] = catch f g
{ "file_name": "examples/layeredeffects/LatticeSpec.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 11, "end_line": 271, "start_col": 0, "start_line": 270 }
module LatticeSpec open FStar.Tactics.V2 open FStar.List.Tot // 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 = | RD | WR | EXN type annot = eff_label -> bool // warning: if this is not annotated, `eqtype` is inferred // as its type and the effect definition fails for some reason. type state : Type = int type pre_t = state -> Type0 type post_t a = state -> option a -> state -> Type0 // this repr doesn't seem to work too well type repr0 (a:Type u#aa) (pre : pre_t) (post : post_t u#aa a) // #2074 : Type u#aa = s0:state{pre s0} -> Tot (r:(option a & state){post s0 (fst r) (snd r)}) let abides #a #pre #post (f : repr0 a pre post) (ann:annot) : Type0 = (ann RD = false ==> (forall s0 s1. fst (f s0) == fst (f s1))) /\ (ann WR = false ==> (forall s0. snd (f s0) == s0)) /\ (ann EXN = false ==> (forall s0. Some? (fst (f s0)))) let interp (l : list eff_label) : annot = fun lab -> mem lab 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 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 type repr (a:Type u#aa) (pre : pre_t) (post : post_t u#aa a) // #2074 (labs : list u#0 eff_label) // #2074 : Type u#aa = r:(repr0 a pre post){abides r (interp labs)} let ann_le (ann1 ann2 : annot) : Type0 = forall x. ann1 x ==> ann2 x let return (a:Type u#aa) (x:a) : Tot (repr a (fun _ -> True) (fun s0 y s1 -> s0 == s1 /\ y == Some x) []) = // GM: Need to write it like this.. why? let r (s0:state) : Tot (r:(option a & state){snd r == s0 /\ fst r == Some x}) = (Some x, s0) in r unfold let bind_pre (a:Type) (pre1:pre_t) (post1:post_t a) (b:Type) (pre2:a -> pre_t) (post2:a -> post_t b) : pre_t = fun s0 -> pre1 s0 /\ (forall y s1. post1 s0 (Some y) s1 ==> pre2 y s1) unfold let bind_post (a:Type) (pre1:pre_t) (post1:post_t a) (b:Type) (pre2:a -> pre_t) (post2:a -> post_t b) : post_t b = fun s0 z s2 -> (exists s1 y. post1 s0 (Some y) s1 /\ post2 y s1 z s2) \/ (post1 s0 None s2) let bind (a b : Type) pre1 post1 (labs1 : list eff_label) pre2 post2 (labs2 : list eff_label) (c : repr a pre1 post1 labs1) (f : (x:a -> repr b (pre2 x) (post2 x) labs2)) : Tot (repr b (bind_pre a pre1 post1 b pre2 post2) (bind_post a pre1 post1 b pre2 post2) (labs1@labs2)) = let pre = bind_pre a pre1 post1 b pre2 post2 in let post = bind_post a pre1 post1 b pre2 post2 in let r (s0:state{pre s0}) : Tot (r:(option b & state){post s0 (fst r) (snd r)}) = match c s0 with | Some x, s1 -> assert (post1 s0 (Some x) s1); assert (pre2 x s1); f x s1 | None, s1 -> None, s1 in r let subcomp (a:Type) (pre1 : pre_t) (post1 : post_t a) (labs1 : list eff_label) (pre2 : pre_t) (post2 : post_t a) (labs2 : list eff_label) (f : repr a pre1 post1 labs1) : Pure (repr a pre2 post2 labs2) (requires ((forall s0. pre2 s0 ==> pre1 s0) /\ (forall s0 r s1. post1 s0 r s1 ==> post2 s0 r s1) /\ sublist labs1 labs2)) (ensures (fun _ -> True)) = f unfold let ite (p q r : Type0) = (p ==> q) /\ ((~p) ==> r) let if_then_else (a : Type) (pre1 : pre_t) (post1 : post_t a) (labs1 : list eff_label) (pre2 : pre_t) (post2 : post_t a) (labs2 : list eff_label) (f : repr a pre1 post1 labs1) (g : repr a pre2 post2 labs2) (b : bool) : Type = repr a (fun s0 -> ite b (pre1 s0) (pre2 s0)) (fun s0 y s1 -> ite b (post1 s0 y s1) (post2 s0 y s1)) (labs1@labs2) total // need this for catch!! reifiable reflectable effect { EFF (a:Type) (_:pre_t) (_:post_t a) (_:list eff_label) with {repr; return; bind; subcomp; if_then_else} } unfold let sp #a (wp : pure_wp a) : pure_post a = fun x -> ~ (wp (fun y -> ~(x == y))) unfold let post_of_wp #a (wp : pure_wp a) : post_t a = fun s0 r s1 -> s0 == s1 /\ Some? r /\ sp wp (Some?.v r) let lift_pure_eff (a:Type) (wp : pure_wp a) (f : unit -> PURE a wp) : repr a (fun _ -> wp (fun _ -> True)) (post_of_wp wp) [] = FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp; let r (s0:state{wp (fun _ -> True)}) : Tot (r:(option a & state){snd r == s0 /\ Some? (fst r) /\ sp wp (Some?.v (fst r))}) = (Some (f ()), s0) in r sub_effect PURE ~> EFF = lift_pure_eff let _get : repr state (fun _ -> True) (fun s0 y s1 -> s1 == s0 /\ y == Some s0) [RD] = let ff (s0:state) : Tot (r:(option state & state){fst r == Some s0 /\ snd r == s0}) = (Some s0, s0) in ff let get () : EFF int (fun _ -> True) (fun s0 y s1 -> s1 == s0 /\ y == Some s0) [RD] by (compute (); dump"") = EFF?.reflect _get let _put (s:state) : repr unit (fun _ -> True) (fun _ y s1 -> s1 == s /\ y == Some ()) [WR] = // GM: pretty odd that I have to add `r == Some ()` here.... let ff (_:state) : Tot (r:(option unit & state){fst r == Some () /\ snd r == s}) = (Some (), s) in ff let put (s:state) : EFF unit (fun _ -> True) (fun _ y s1 -> s1 == s) [WR] = EFF?.reflect (_put s) let _raise #a : repr a (fun _ -> True) (fun s0 _ s1 -> s1 == s0) [EXN] = let ff (s0:state) : Tot (r:(option a & state){fst r == None /\ snd r == s0}) = (None, s0) in ff let raise #a () : EFF a (fun _ -> True) (fun s0 _ s1 -> s1 == s0) [EXN] = EFF?.reflect _raise effect EFFT (a:Type) (labs:list eff_label) = EFF a (fun _ -> True) (fun _ _ _ -> True) labs let test0 (x y : int) : EFFT int [RD; EXN] = let z = get () in if x + z > 0 then raise () else y - z // need compute let test1 (x y : int) : EFFT int [EXN; RD; WR] by (compute ())= let z = get () in if x + z > 0 then raise () else (put 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 -> EFFT int labs) : EFFT int labs = f () + g () let catch0 #a #labs (f:repr a (fun _ -> True) (fun _ _ _ -> True) (EXN::labs)) (g:repr a (fun _ -> True) (fun _ _ _ -> True) labs) : repr a (fun _ -> True) (fun _ _ _ -> True) labs = fun s0 -> let r0 : option a & state = f s0 in let r1 : option a & state = match r0 with | (Some v, s1) -> (Some v, s1) | (None, s1) -> g s1 | _ -> unreachable () in r1 (* no rollback *) let catch #a #labs (f : unit -> EFFT a (EXN::labs)) (g : unit -> EFFT a labs) : EFFT a labs = EFF?.reflect (catch0 (reify (f ())) (reify (g ()))) let g #labs () : EFFT int labs = 42 let test_catch #labs (f : unit -> EFFT int [EXN;WR]) : EFFT int [WR] = catch f g
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LatticeSpec.fst" }
[ { "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 -> LatticeSpec.EFFT Prims.int) -> LatticeSpec.EFFT Prims.int
LatticeSpec.EFFT
[]
[]
[ "Prims.unit", "Prims.int", "Prims.Cons", "LatticeSpec.eff_label", "LatticeSpec.EXN", "LatticeSpec.WR", "Prims.Nil", "LatticeSpec.catch", "LatticeSpec.g" ]
[]
false
true
false
false
false
let test_catch2 (f: (unit -> EFFT int [EXN; EXN; WR])) : EFFT int [EXN; WR] =
catch f g
false
LatticeSpec.fst
LatticeSpec.labpoly
val labpoly (#labs: _) (f g: (unit -> EFFT int labs)) : EFFT int labs
val labpoly (#labs: _) (f g: (unit -> EFFT int labs)) : EFFT int labs
let labpoly #labs (f g : unit -> EFFT int labs) : EFFT int labs = f () + g ()
{ "file_name": "examples/layeredeffects/LatticeSpec.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 13, "end_line": 242, "start_col": 0, "start_line": 241 }
module LatticeSpec open FStar.Tactics.V2 open FStar.List.Tot // 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 = | RD | WR | EXN type annot = eff_label -> bool // warning: if this is not annotated, `eqtype` is inferred // as its type and the effect definition fails for some reason. type state : Type = int type pre_t = state -> Type0 type post_t a = state -> option a -> state -> Type0 // this repr doesn't seem to work too well type repr0 (a:Type u#aa) (pre : pre_t) (post : post_t u#aa a) // #2074 : Type u#aa = s0:state{pre s0} -> Tot (r:(option a & state){post s0 (fst r) (snd r)}) let abides #a #pre #post (f : repr0 a pre post) (ann:annot) : Type0 = (ann RD = false ==> (forall s0 s1. fst (f s0) == fst (f s1))) /\ (ann WR = false ==> (forall s0. snd (f s0) == s0)) /\ (ann EXN = false ==> (forall s0. Some? (fst (f s0)))) let interp (l : list eff_label) : annot = fun lab -> mem lab 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 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 type repr (a:Type u#aa) (pre : pre_t) (post : post_t u#aa a) // #2074 (labs : list u#0 eff_label) // #2074 : Type u#aa = r:(repr0 a pre post){abides r (interp labs)} let ann_le (ann1 ann2 : annot) : Type0 = forall x. ann1 x ==> ann2 x let return (a:Type u#aa) (x:a) : Tot (repr a (fun _ -> True) (fun s0 y s1 -> s0 == s1 /\ y == Some x) []) = // GM: Need to write it like this.. why? let r (s0:state) : Tot (r:(option a & state){snd r == s0 /\ fst r == Some x}) = (Some x, s0) in r unfold let bind_pre (a:Type) (pre1:pre_t) (post1:post_t a) (b:Type) (pre2:a -> pre_t) (post2:a -> post_t b) : pre_t = fun s0 -> pre1 s0 /\ (forall y s1. post1 s0 (Some y) s1 ==> pre2 y s1) unfold let bind_post (a:Type) (pre1:pre_t) (post1:post_t a) (b:Type) (pre2:a -> pre_t) (post2:a -> post_t b) : post_t b = fun s0 z s2 -> (exists s1 y. post1 s0 (Some y) s1 /\ post2 y s1 z s2) \/ (post1 s0 None s2) let bind (a b : Type) pre1 post1 (labs1 : list eff_label) pre2 post2 (labs2 : list eff_label) (c : repr a pre1 post1 labs1) (f : (x:a -> repr b (pre2 x) (post2 x) labs2)) : Tot (repr b (bind_pre a pre1 post1 b pre2 post2) (bind_post a pre1 post1 b pre2 post2) (labs1@labs2)) = let pre = bind_pre a pre1 post1 b pre2 post2 in let post = bind_post a pre1 post1 b pre2 post2 in let r (s0:state{pre s0}) : Tot (r:(option b & state){post s0 (fst r) (snd r)}) = match c s0 with | Some x, s1 -> assert (post1 s0 (Some x) s1); assert (pre2 x s1); f x s1 | None, s1 -> None, s1 in r let subcomp (a:Type) (pre1 : pre_t) (post1 : post_t a) (labs1 : list eff_label) (pre2 : pre_t) (post2 : post_t a) (labs2 : list eff_label) (f : repr a pre1 post1 labs1) : Pure (repr a pre2 post2 labs2) (requires ((forall s0. pre2 s0 ==> pre1 s0) /\ (forall s0 r s1. post1 s0 r s1 ==> post2 s0 r s1) /\ sublist labs1 labs2)) (ensures (fun _ -> True)) = f unfold let ite (p q r : Type0) = (p ==> q) /\ ((~p) ==> r) let if_then_else (a : Type) (pre1 : pre_t) (post1 : post_t a) (labs1 : list eff_label) (pre2 : pre_t) (post2 : post_t a) (labs2 : list eff_label) (f : repr a pre1 post1 labs1) (g : repr a pre2 post2 labs2) (b : bool) : Type = repr a (fun s0 -> ite b (pre1 s0) (pre2 s0)) (fun s0 y s1 -> ite b (post1 s0 y s1) (post2 s0 y s1)) (labs1@labs2) total // need this for catch!! reifiable reflectable effect { EFF (a:Type) (_:pre_t) (_:post_t a) (_:list eff_label) with {repr; return; bind; subcomp; if_then_else} } unfold let sp #a (wp : pure_wp a) : pure_post a = fun x -> ~ (wp (fun y -> ~(x == y))) unfold let post_of_wp #a (wp : pure_wp a) : post_t a = fun s0 r s1 -> s0 == s1 /\ Some? r /\ sp wp (Some?.v r) let lift_pure_eff (a:Type) (wp : pure_wp a) (f : unit -> PURE a wp) : repr a (fun _ -> wp (fun _ -> True)) (post_of_wp wp) [] = FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp; let r (s0:state{wp (fun _ -> True)}) : Tot (r:(option a & state){snd r == s0 /\ Some? (fst r) /\ sp wp (Some?.v (fst r))}) = (Some (f ()), s0) in r sub_effect PURE ~> EFF = lift_pure_eff let _get : repr state (fun _ -> True) (fun s0 y s1 -> s1 == s0 /\ y == Some s0) [RD] = let ff (s0:state) : Tot (r:(option state & state){fst r == Some s0 /\ snd r == s0}) = (Some s0, s0) in ff let get () : EFF int (fun _ -> True) (fun s0 y s1 -> s1 == s0 /\ y == Some s0) [RD] by (compute (); dump"") = EFF?.reflect _get let _put (s:state) : repr unit (fun _ -> True) (fun _ y s1 -> s1 == s /\ y == Some ()) [WR] = // GM: pretty odd that I have to add `r == Some ()` here.... let ff (_:state) : Tot (r:(option unit & state){fst r == Some () /\ snd r == s}) = (Some (), s) in ff let put (s:state) : EFF unit (fun _ -> True) (fun _ y s1 -> s1 == s) [WR] = EFF?.reflect (_put s) let _raise #a : repr a (fun _ -> True) (fun s0 _ s1 -> s1 == s0) [EXN] = let ff (s0:state) : Tot (r:(option a & state){fst r == None /\ snd r == s0}) = (None, s0) in ff let raise #a () : EFF a (fun _ -> True) (fun s0 _ s1 -> s1 == s0) [EXN] = EFF?.reflect _raise effect EFFT (a:Type) (labs:list eff_label) = EFF a (fun _ -> True) (fun _ _ _ -> True) labs let test0 (x y : int) : EFFT int [RD; EXN] = let z = get () in if x + z > 0 then raise () else y - z // need compute let test1 (x y : int) : EFFT int [EXN; RD; WR] by (compute ())= let z = get () in if x + z > 0 then raise () else (put 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.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LatticeSpec.fst" }
[ { "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 -> LatticeSpec.EFFT Prims.int) -> g: (_: Prims.unit -> LatticeSpec.EFFT Prims.int) -> LatticeSpec.EFFT Prims.int
LatticeSpec.EFFT
[]
[]
[ "Prims.list", "LatticeSpec.eff_label", "Prims.unit", "Prims.int", "Prims.op_Addition" ]
[]
false
true
false
false
false
let labpoly #labs (f: (unit -> EFFT int labs)) (g: (unit -> EFFT int labs)) : EFFT int labs =
f () + g ()
false
PulseCore.Preorder.fst
PulseCore.Preorder.induces_preorder
val induces_preorder : p: FStar.PCM.pcm a -> q: FStar.Preorder.preorder a -> Prims.logical
let induces_preorder (#a:Type u#a) (p:pcm a) (q:preorder a) = forall (x y:a) (f:frame_preserving_upd p x y) (v:a). p.refine v ==> compatible p x v ==> q v (f v)
{ "file_name": "lib/pulse_core/PulseCore.Preorder.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 49, "end_line": 37, "start_col": 0, "start_line": 35 }
(* 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 PulseCore.Preorder open FStar.PCM open FStar.Preorder open PulseCore.FractionalPermission open FStar.Real /// This module explores the connection between PCM and preorders. More specifically, we show here /// that any PCM induces a preorder relation, characterized by frame-preservation for any updates. /// /// Furthermore, we also consider the reverse relationship where we derive a PCM for any preorder, /// by taking as elements of the PCM the trace of all the states of the element. (**** PCM to preoder *) (** PCM [p] induces the preorder [q] if for any frame preserving update of [x] to [y], the argument and result of the frame preserving update are related by q
{ "checked_file": "/", "dependencies": [ "PulseCore.FractionalPermission.fst.checked", "prims.fst.checked", "FStar.Real.fsti.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked", "FStar.List.Tot.fst.checked", "FStar.IndefiniteDescription.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "PulseCore.Preorder.fst" }
[ { "abbrev": false, "full_module": "FStar.Real", "short_module": null }, { "abbrev": false, "full_module": "PulseCore.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "FStar.Preorder", "short_module": null }, { "abbrev": false, "full_module": "FStar.PCM", "short_module": null }, { "abbrev": false, "full_module": "PulseCore", "short_module": null }, { "abbrev": false, "full_module": "PulseCore", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
p: FStar.PCM.pcm a -> q: FStar.Preorder.preorder a -> Prims.logical
Prims.Tot
[ "total" ]
[]
[ "FStar.PCM.pcm", "FStar.Preorder.preorder", "Prims.l_Forall", "FStar.PCM.frame_preserving_upd", "Prims.l_imp", "FStar.PCM.__proj__Mkpcm__item__refine", "FStar.PCM.compatible", "Prims.logical" ]
[]
false
false
false
true
true
let induces_preorder (#a: Type u#a) (p: pcm a) (q: preorder a) =
forall (x: a) (y: a) (f: frame_preserving_upd p x y) (v: a). p.refine v ==> compatible p x v ==> q v (f v)
false
LowParse.Low.Writers.Instances.fst
LowParse.Low.Writers.Instances.swrite_synth
val swrite_synth (#h0: HS.mem) (#sout: slice (srel_of_buffer_srel (B.trivial_preorder _)) (srel_of_buffer_srel (B.trivial_preorder _))) (#pout_from0: U32.t) (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#s1: serializer p1 {k1.parser_kind_subkind == Some ParserStrong}) (#space_beyond: nat) (w1: swriter s1 h0 space_beyond sout pout_from0) (#t2: Type) (f12: (t1 -> GTot t2)) (f21: (t2 -> GTot t1)) (prf: squash (synth_injective f12 /\ synth_inverse f12 f21)) : Tot (w2: swriter (serialize_synth p1 f12 s1 f21 ()) h0 space_beyond sout pout_from0 {swvalue w2 == f12 (swvalue w1) /\ swvalue w1 == f21 (swvalue w2)})
val swrite_synth (#h0: HS.mem) (#sout: slice (srel_of_buffer_srel (B.trivial_preorder _)) (srel_of_buffer_srel (B.trivial_preorder _))) (#pout_from0: U32.t) (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#s1: serializer p1 {k1.parser_kind_subkind == Some ParserStrong}) (#space_beyond: nat) (w1: swriter s1 h0 space_beyond sout pout_from0) (#t2: Type) (f12: (t1 -> GTot t2)) (f21: (t2 -> GTot t1)) (prf: squash (synth_injective f12 /\ synth_inverse f12 f21)) : Tot (w2: swriter (serialize_synth p1 f12 s1 f21 ()) h0 space_beyond sout pout_from0 {swvalue w2 == f12 (swvalue w1) /\ swvalue w1 == f21 (swvalue w2)})
let swrite_synth (#h0: HS.mem) (#sout: slice (srel_of_buffer_srel (B.trivial_preorder _)) (srel_of_buffer_srel (B.trivial_preorder _))) (#pout_from0: U32.t) (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#s1: serializer p1 { k1.parser_kind_subkind == Some ParserStrong }) (#space_beyond: nat) (w1: swriter s1 h0 space_beyond sout pout_from0) (#t2: Type) (f12: (t1 -> GTot t2)) (f21: (t2 -> GTot t1)) (prf: squash ( synth_injective f12 /\ synth_inverse f12 f21 )) : Tot (w2: swriter (serialize_synth p1 f12 s1 f21 ()) h0 space_beyond sout pout_from0 { swvalue w2 == f12 (swvalue w1) /\ swvalue w1 == f21 (swvalue w2) }) = [@inline_let] let _ = serialize_synth_eq p1 f12 s1 f21 () (f12 (swvalue w1)); synth_injective_synth_inverse_synth_inverse_recip f12 f21 () in SWriter (Ghost.hide (f12 (swvalue w1))) (fun pout_from -> serialized_length_eq (serialize_synth p1 f12 s1 f21 ()) (f12 (swvalue w1)); serialized_length_eq s1 (swvalue w1); let res = swrite w1 pout_from in let h = HST.get () in valid_synth h p1 f12 sout pout_from; res )
{ "file_name": "src/lowparse/LowParse.Low.Writers.Instances.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 3, "end_line": 158, "start_col": 0, "start_line": 126 }
module LowParse.Low.Writers.Instances include LowParse.Low.Writers include LowParse.Low.Combinators include LowParse.Low.Bytes include LowParse.Low.BitSum module HS = FStar.HyperStack module B = LowStar.Buffer module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST inline_for_extraction noextract let swrite_weaken (#h0: HS.mem) (#sout: slice (srel_of_buffer_srel (B.trivial_preorder _)) (srel_of_buffer_srel (B.trivial_preorder _))) (#pout_from0: U32.t) (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#s1: serializer p1 { k1.parser_kind_subkind == Some ParserStrong }) (#space_beyond: nat) (k2: parser_kind) (w1: swriter s1 h0 space_beyond sout pout_from0 { (k2 `is_weaker_than` k1) /\ k2.parser_kind_subkind == Some ParserStrong }) : Tot (w2: swriter (serialize_weaken k2 s1) h0 space_beyond sout pout_from0 { swvalue w2 == swvalue w1 }) = SWriter (Ghost.hide (swvalue w1)) (fun pout_from -> serialized_length_eq s1 (swvalue w1); serialized_length_eq (serialize_weaken k2 s1) (swvalue w1); let res = swrite w1 pout_from in let h = HST.get () in valid_weaken k2 p1 h sout pout_from; res ) inline_for_extraction noextract let swrite_nondep_then' (#h0: HS.mem) (#sout: slice (srel_of_buffer_srel (B.trivial_preorder _)) (srel_of_buffer_srel (B.trivial_preorder _))) (#pout_from0: U32.t) (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#s1: serializer p1 { k1.parser_kind_subkind == Some ParserStrong }) (#space_beyond: nat) (w1: swriter s1 h0 space_beyond sout pout_from0) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (#s2: serializer p2 { k2.parser_kind_subkind == Some ParserStrong }) (w2: swriter s2 h0 space_beyond sout pout_from0) : Tot (w: swriter (s1 `serialize_nondep_then` s2) h0 space_beyond sout pout_from0 { swvalue w == (swvalue w1, swvalue w2) }) = SWriter (Ghost.hide (swvalue w1, swvalue w2)) (fun pout_from -> serialized_length_eq (s1 `serialize_nondep_then` s2) (swvalue w1, swvalue w2); serialize_nondep_then_eq s1 s2 (swvalue w1, swvalue w2); serialized_length_eq s1 (swvalue w1); serialized_length_eq s2 (swvalue w2); let pos1 = swrite w1 pout_from in let pos2 = swrite w2 pos1 in let h' = HST.get () in valid_nondep_then h' p1 p2 sout pout_from; pos2 ) let max (x1 x2: nat) : Tot nat = if x1 > x2 then x1 else x2 inline_for_extraction noextract let swrite_nondep_then (#h0: HS.mem) (#sout: slice (srel_of_buffer_srel (B.trivial_preorder _)) (srel_of_buffer_srel (B.trivial_preorder _))) (#pout_from0: U32.t) (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#s1: serializer p1 { k1.parser_kind_subkind == Some ParserStrong }) (#space_beyond1: nat) (w1: swriter s1 h0 space_beyond1 sout pout_from0) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (#s2: serializer p2 { k2.parser_kind_subkind == Some ParserStrong }) (#space_beyond2: nat) (w2: swriter s2 h0 space_beyond2 sout pout_from0) : Tot (w: swriter (s1 `serialize_nondep_then` s2) h0 (space_beyond1 `max` space_beyond2) sout pout_from0 { swvalue w == (swvalue w1, swvalue w2) }) = [@inline_let] let sbmax = space_beyond1 `max` space_beyond2 in weaken_swriter w1 h0 sbmax pout_from0 `swrite_nondep_then'` weaken_swriter w2 h0 sbmax pout_from0 inline_for_extraction noextract let swrite_filter (#h0: HS.mem) (#sout: slice (srel_of_buffer_srel (B.trivial_preorder _)) (srel_of_buffer_srel (B.trivial_preorder _))) (#pout_from0: U32.t) (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#s1: serializer p1 { k1.parser_kind_subkind == Some ParserStrong }) (#space_beyond: nat) (cond: (t1 -> GTot bool)) (w1: swriter s1 h0 space_beyond sout pout_from0 { cond (swvalue w1) } ) : Tot (w2: swriter (serialize_filter s1 cond) h0 space_beyond sout pout_from0 { swvalue w2 == swvalue w1 }) = SWriter (Ghost.hide (swvalue w1)) (fun pout_from -> serialized_length_eq (serialize_filter s1 cond) (swvalue w1); serialized_length_eq s1 (swvalue w1); let res = swrite w1 pout_from in let h = HST.get () in valid_filter h p1 cond sout pout_from; res ) inline_for_extraction
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Endianness.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Low.Writers.fst.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Low.Bytes.fst.checked", "LowParse.Low.BitSum.fst.checked", "LowParse.Endianness.BitFields.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Bytes.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Low.Writers.Instances.fst" }
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "LowParse.Low.BitSum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Bytes", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Writers", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Writers", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Writers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
w1: LowParse.Low.Writers.swriter s1 h0 space_beyond sout pout_from0 -> f12: (_: t1 -> Prims.GTot t2) -> f21: (_: t2 -> Prims.GTot t1) -> prf: Prims.squash (LowParse.Spec.Combinators.synth_injective f12 /\ LowParse.Spec.Combinators.synth_inverse f12 f21) -> w2: LowParse.Low.Writers.swriter (LowParse.Spec.Combinators.serialize_synth p1 f12 s1 f21 ()) h0 space_beyond sout pout_from0 { LowParse.Low.Writers.swvalue w2 == f12 (LowParse.Low.Writers.swvalue w1) /\ LowParse.Low.Writers.swvalue w1 == f21 (LowParse.Low.Writers.swvalue w2) }
Prims.Tot
[ "total" ]
[]
[ "FStar.Monotonic.HyperStack.mem", "LowParse.Slice.slice", "LowParse.Slice.srel_of_buffer_srel", "LowParse.Bytes.byte", "LowStar.Buffer.trivial_preorder", "FStar.UInt32.t", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Spec.Base.serializer", "Prims.eq2", "FStar.Pervasives.Native.option", "LowParse.Spec.Base.parser_subkind", "LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_subkind", "FStar.Pervasives.Native.Some", "LowParse.Spec.Base.ParserStrong", "Prims.nat", "LowParse.Low.Writers.swriter", "Prims.squash", "Prims.l_and", "LowParse.Spec.Combinators.synth_injective", "LowParse.Spec.Combinators.synth_inverse", "LowParse.Low.Writers.SWriter", "LowParse.Spec.Combinators.parse_synth", "LowParse.Spec.Combinators.serialize_synth", "FStar.Ghost.hide", "LowParse.Low.Writers.swvalue", "Prims.unit", "LowParse.Low.Combinators.valid_synth", "FStar.HyperStack.ST.get", "LowParse.Low.Writers.swrite", "LowParse.Low.Base.Spec.serialized_length_eq", "LowParse.Spec.Combinators.synth_injective_synth_inverse_synth_inverse_recip", "LowParse.Spec.Combinators.serialize_synth_eq" ]
[]
false
false
false
false
false
let swrite_synth (#h0: HS.mem) (#sout: slice (srel_of_buffer_srel (B.trivial_preorder _)) (srel_of_buffer_srel (B.trivial_preorder _))) (#pout_from0: U32.t) (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#s1: serializer p1 {k1.parser_kind_subkind == Some ParserStrong}) (#space_beyond: nat) (w1: swriter s1 h0 space_beyond sout pout_from0) (#t2: Type) (f12: (t1 -> GTot t2)) (f21: (t2 -> GTot t1)) (prf: squash (synth_injective f12 /\ synth_inverse f12 f21)) : Tot (w2: swriter (serialize_synth p1 f12 s1 f21 ()) h0 space_beyond sout pout_from0 {swvalue w2 == f12 (swvalue w1) /\ swvalue w1 == f21 (swvalue w2)}) =
[@@ inline_let ]let _ = serialize_synth_eq p1 f12 s1 f21 () (f12 (swvalue w1)); synth_injective_synth_inverse_synth_inverse_recip f12 f21 () in SWriter (Ghost.hide (f12 (swvalue w1))) (fun pout_from -> serialized_length_eq (serialize_synth p1 f12 s1 f21 ()) (f12 (swvalue w1)); serialized_length_eq s1 (swvalue w1); let res = swrite w1 pout_from in let h = HST.get () in valid_synth h p1 f12 sout pout_from; res)
false
LatticeSpec.fst
LatticeSpec.g
val g: #labs: _ -> Prims.unit -> EFFT int labs
val g: #labs: _ -> Prims.unit -> EFFT int labs
let g #labs () : EFFT int labs = 42
{ "file_name": "examples/layeredeffects/LatticeSpec.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 35, "end_line": 265, "start_col": 0, "start_line": 265 }
module LatticeSpec open FStar.Tactics.V2 open FStar.List.Tot // 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 = | RD | WR | EXN type annot = eff_label -> bool // warning: if this is not annotated, `eqtype` is inferred // as its type and the effect definition fails for some reason. type state : Type = int type pre_t = state -> Type0 type post_t a = state -> option a -> state -> Type0 // this repr doesn't seem to work too well type repr0 (a:Type u#aa) (pre : pre_t) (post : post_t u#aa a) // #2074 : Type u#aa = s0:state{pre s0} -> Tot (r:(option a & state){post s0 (fst r) (snd r)}) let abides #a #pre #post (f : repr0 a pre post) (ann:annot) : Type0 = (ann RD = false ==> (forall s0 s1. fst (f s0) == fst (f s1))) /\ (ann WR = false ==> (forall s0. snd (f s0) == s0)) /\ (ann EXN = false ==> (forall s0. Some? (fst (f s0)))) let interp (l : list eff_label) : annot = fun lab -> mem lab 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 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 type repr (a:Type u#aa) (pre : pre_t) (post : post_t u#aa a) // #2074 (labs : list u#0 eff_label) // #2074 : Type u#aa = r:(repr0 a pre post){abides r (interp labs)} let ann_le (ann1 ann2 : annot) : Type0 = forall x. ann1 x ==> ann2 x let return (a:Type u#aa) (x:a) : Tot (repr a (fun _ -> True) (fun s0 y s1 -> s0 == s1 /\ y == Some x) []) = // GM: Need to write it like this.. why? let r (s0:state) : Tot (r:(option a & state){snd r == s0 /\ fst r == Some x}) = (Some x, s0) in r unfold let bind_pre (a:Type) (pre1:pre_t) (post1:post_t a) (b:Type) (pre2:a -> pre_t) (post2:a -> post_t b) : pre_t = fun s0 -> pre1 s0 /\ (forall y s1. post1 s0 (Some y) s1 ==> pre2 y s1) unfold let bind_post (a:Type) (pre1:pre_t) (post1:post_t a) (b:Type) (pre2:a -> pre_t) (post2:a -> post_t b) : post_t b = fun s0 z s2 -> (exists s1 y. post1 s0 (Some y) s1 /\ post2 y s1 z s2) \/ (post1 s0 None s2) let bind (a b : Type) pre1 post1 (labs1 : list eff_label) pre2 post2 (labs2 : list eff_label) (c : repr a pre1 post1 labs1) (f : (x:a -> repr b (pre2 x) (post2 x) labs2)) : Tot (repr b (bind_pre a pre1 post1 b pre2 post2) (bind_post a pre1 post1 b pre2 post2) (labs1@labs2)) = let pre = bind_pre a pre1 post1 b pre2 post2 in let post = bind_post a pre1 post1 b pre2 post2 in let r (s0:state{pre s0}) : Tot (r:(option b & state){post s0 (fst r) (snd r)}) = match c s0 with | Some x, s1 -> assert (post1 s0 (Some x) s1); assert (pre2 x s1); f x s1 | None, s1 -> None, s1 in r let subcomp (a:Type) (pre1 : pre_t) (post1 : post_t a) (labs1 : list eff_label) (pre2 : pre_t) (post2 : post_t a) (labs2 : list eff_label) (f : repr a pre1 post1 labs1) : Pure (repr a pre2 post2 labs2) (requires ((forall s0. pre2 s0 ==> pre1 s0) /\ (forall s0 r s1. post1 s0 r s1 ==> post2 s0 r s1) /\ sublist labs1 labs2)) (ensures (fun _ -> True)) = f unfold let ite (p q r : Type0) = (p ==> q) /\ ((~p) ==> r) let if_then_else (a : Type) (pre1 : pre_t) (post1 : post_t a) (labs1 : list eff_label) (pre2 : pre_t) (post2 : post_t a) (labs2 : list eff_label) (f : repr a pre1 post1 labs1) (g : repr a pre2 post2 labs2) (b : bool) : Type = repr a (fun s0 -> ite b (pre1 s0) (pre2 s0)) (fun s0 y s1 -> ite b (post1 s0 y s1) (post2 s0 y s1)) (labs1@labs2) total // need this for catch!! reifiable reflectable effect { EFF (a:Type) (_:pre_t) (_:post_t a) (_:list eff_label) with {repr; return; bind; subcomp; if_then_else} } unfold let sp #a (wp : pure_wp a) : pure_post a = fun x -> ~ (wp (fun y -> ~(x == y))) unfold let post_of_wp #a (wp : pure_wp a) : post_t a = fun s0 r s1 -> s0 == s1 /\ Some? r /\ sp wp (Some?.v r) let lift_pure_eff (a:Type) (wp : pure_wp a) (f : unit -> PURE a wp) : repr a (fun _ -> wp (fun _ -> True)) (post_of_wp wp) [] = FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp; let r (s0:state{wp (fun _ -> True)}) : Tot (r:(option a & state){snd r == s0 /\ Some? (fst r) /\ sp wp (Some?.v (fst r))}) = (Some (f ()), s0) in r sub_effect PURE ~> EFF = lift_pure_eff let _get : repr state (fun _ -> True) (fun s0 y s1 -> s1 == s0 /\ y == Some s0) [RD] = let ff (s0:state) : Tot (r:(option state & state){fst r == Some s0 /\ snd r == s0}) = (Some s0, s0) in ff let get () : EFF int (fun _ -> True) (fun s0 y s1 -> s1 == s0 /\ y == Some s0) [RD] by (compute (); dump"") = EFF?.reflect _get let _put (s:state) : repr unit (fun _ -> True) (fun _ y s1 -> s1 == s /\ y == Some ()) [WR] = // GM: pretty odd that I have to add `r == Some ()` here.... let ff (_:state) : Tot (r:(option unit & state){fst r == Some () /\ snd r == s}) = (Some (), s) in ff let put (s:state) : EFF unit (fun _ -> True) (fun _ y s1 -> s1 == s) [WR] = EFF?.reflect (_put s) let _raise #a : repr a (fun _ -> True) (fun s0 _ s1 -> s1 == s0) [EXN] = let ff (s0:state) : Tot (r:(option a & state){fst r == None /\ snd r == s0}) = (None, s0) in ff let raise #a () : EFF a (fun _ -> True) (fun s0 _ s1 -> s1 == s0) [EXN] = EFF?.reflect _raise effect EFFT (a:Type) (labs:list eff_label) = EFF a (fun _ -> True) (fun _ _ _ -> True) labs let test0 (x y : int) : EFFT int [RD; EXN] = let z = get () in if x + z > 0 then raise () else y - z // need compute let test1 (x y : int) : EFFT int [EXN; RD; WR] by (compute ())= let z = get () in if x + z > 0 then raise () else (put 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 -> EFFT int labs) : EFFT int labs = f () + g () let catch0 #a #labs (f:repr a (fun _ -> True) (fun _ _ _ -> True) (EXN::labs)) (g:repr a (fun _ -> True) (fun _ _ _ -> True) labs) : repr a (fun _ -> True) (fun _ _ _ -> True) labs = fun s0 -> let r0 : option a & state = f s0 in let r1 : option a & state = match r0 with | (Some v, s1) -> (Some v, s1) | (None, s1) -> g s1 | _ -> unreachable () in r1 (* no rollback *) let catch #a #labs (f : unit -> EFFT a (EXN::labs)) (g : unit -> EFFT a labs) : EFFT a labs = EFF?.reflect (catch0 (reify (f ())) (reify (g ())))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LatticeSpec.fst" }
[ { "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 -> LatticeSpec.EFFT Prims.int
LatticeSpec.EFFT
[]
[]
[ "Prims.list", "LatticeSpec.eff_label", "Prims.unit", "Prims.int" ]
[]
false
true
false
false
false
let g #labs () : EFFT int labs =
42
false
LowParse.Low.Writers.Instances.fst
LowParse.Low.Writers.Instances.swrite_nondep_then
val swrite_nondep_then (#h0: HS.mem) (#sout: slice (srel_of_buffer_srel (B.trivial_preorder _)) (srel_of_buffer_srel (B.trivial_preorder _))) (#pout_from0: U32.t) (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#s1: serializer p1 {k1.parser_kind_subkind == Some ParserStrong}) (#space_beyond1: nat) (w1: swriter s1 h0 space_beyond1 sout pout_from0) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (#s2: serializer p2 {k2.parser_kind_subkind == Some ParserStrong}) (#space_beyond2: nat) (w2: swriter s2 h0 space_beyond2 sout pout_from0) : Tot (w: swriter (s1 `serialize_nondep_then` s2) h0 (space_beyond1 `max` space_beyond2) sout pout_from0 {swvalue w == (swvalue w1, swvalue w2)})
val swrite_nondep_then (#h0: HS.mem) (#sout: slice (srel_of_buffer_srel (B.trivial_preorder _)) (srel_of_buffer_srel (B.trivial_preorder _))) (#pout_from0: U32.t) (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#s1: serializer p1 {k1.parser_kind_subkind == Some ParserStrong}) (#space_beyond1: nat) (w1: swriter s1 h0 space_beyond1 sout pout_from0) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (#s2: serializer p2 {k2.parser_kind_subkind == Some ParserStrong}) (#space_beyond2: nat) (w2: swriter s2 h0 space_beyond2 sout pout_from0) : Tot (w: swriter (s1 `serialize_nondep_then` s2) h0 (space_beyond1 `max` space_beyond2) sout pout_from0 {swvalue w == (swvalue w1, swvalue w2)})
let swrite_nondep_then (#h0: HS.mem) (#sout: slice (srel_of_buffer_srel (B.trivial_preorder _)) (srel_of_buffer_srel (B.trivial_preorder _))) (#pout_from0: U32.t) (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#s1: serializer p1 { k1.parser_kind_subkind == Some ParserStrong }) (#space_beyond1: nat) (w1: swriter s1 h0 space_beyond1 sout pout_from0) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (#s2: serializer p2 { k2.parser_kind_subkind == Some ParserStrong }) (#space_beyond2: nat) (w2: swriter s2 h0 space_beyond2 sout pout_from0) : Tot (w: swriter (s1 `serialize_nondep_then` s2) h0 (space_beyond1 `max` space_beyond2) sout pout_from0 { swvalue w == (swvalue w1, swvalue w2) }) = [@inline_let] let sbmax = space_beyond1 `max` space_beyond2 in weaken_swriter w1 h0 sbmax pout_from0 `swrite_nondep_then'` weaken_swriter w2 h0 sbmax pout_from0
{ "file_name": "src/lowparse/LowParse.Low.Writers.Instances.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 99, "end_line": 97, "start_col": 0, "start_line": 76 }
module LowParse.Low.Writers.Instances include LowParse.Low.Writers include LowParse.Low.Combinators include LowParse.Low.Bytes include LowParse.Low.BitSum module HS = FStar.HyperStack module B = LowStar.Buffer module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST inline_for_extraction noextract let swrite_weaken (#h0: HS.mem) (#sout: slice (srel_of_buffer_srel (B.trivial_preorder _)) (srel_of_buffer_srel (B.trivial_preorder _))) (#pout_from0: U32.t) (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#s1: serializer p1 { k1.parser_kind_subkind == Some ParserStrong }) (#space_beyond: nat) (k2: parser_kind) (w1: swriter s1 h0 space_beyond sout pout_from0 { (k2 `is_weaker_than` k1) /\ k2.parser_kind_subkind == Some ParserStrong }) : Tot (w2: swriter (serialize_weaken k2 s1) h0 space_beyond sout pout_from0 { swvalue w2 == swvalue w1 }) = SWriter (Ghost.hide (swvalue w1)) (fun pout_from -> serialized_length_eq s1 (swvalue w1); serialized_length_eq (serialize_weaken k2 s1) (swvalue w1); let res = swrite w1 pout_from in let h = HST.get () in valid_weaken k2 p1 h sout pout_from; res ) inline_for_extraction noextract let swrite_nondep_then' (#h0: HS.mem) (#sout: slice (srel_of_buffer_srel (B.trivial_preorder _)) (srel_of_buffer_srel (B.trivial_preorder _))) (#pout_from0: U32.t) (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#s1: serializer p1 { k1.parser_kind_subkind == Some ParserStrong }) (#space_beyond: nat) (w1: swriter s1 h0 space_beyond sout pout_from0) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (#s2: serializer p2 { k2.parser_kind_subkind == Some ParserStrong }) (w2: swriter s2 h0 space_beyond sout pout_from0) : Tot (w: swriter (s1 `serialize_nondep_then` s2) h0 space_beyond sout pout_from0 { swvalue w == (swvalue w1, swvalue w2) }) = SWriter (Ghost.hide (swvalue w1, swvalue w2)) (fun pout_from -> serialized_length_eq (s1 `serialize_nondep_then` s2) (swvalue w1, swvalue w2); serialize_nondep_then_eq s1 s2 (swvalue w1, swvalue w2); serialized_length_eq s1 (swvalue w1); serialized_length_eq s2 (swvalue w2); let pos1 = swrite w1 pout_from in let pos2 = swrite w2 pos1 in let h' = HST.get () in valid_nondep_then h' p1 p2 sout pout_from; pos2 ) let max (x1 x2: nat) : Tot nat = if x1 > x2 then x1 else x2 inline_for_extraction
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Endianness.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Low.Writers.fst.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Low.Bytes.fst.checked", "LowParse.Low.BitSum.fst.checked", "LowParse.Endianness.BitFields.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Bytes.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Low.Writers.Instances.fst" }
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "LowParse.Low.BitSum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Bytes", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Writers", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Writers", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Writers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
w1: LowParse.Low.Writers.swriter s1 h0 space_beyond1 sout pout_from0 -> w2: LowParse.Low.Writers.swriter s2 h0 space_beyond2 sout pout_from0 -> w: LowParse.Low.Writers.swriter (LowParse.Spec.Combinators.serialize_nondep_then s1 s2) h0 (LowParse.Low.Writers.Instances.max space_beyond1 space_beyond2) sout pout_from0 { LowParse.Low.Writers.swvalue w == (LowParse.Low.Writers.swvalue w1, LowParse.Low.Writers.swvalue w2) }
Prims.Tot
[ "total" ]
[]
[ "FStar.Monotonic.HyperStack.mem", "LowParse.Slice.slice", "LowParse.Slice.srel_of_buffer_srel", "LowParse.Bytes.byte", "LowStar.Buffer.trivial_preorder", "FStar.UInt32.t", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Spec.Base.serializer", "Prims.eq2", "FStar.Pervasives.Native.option", "LowParse.Spec.Base.parser_subkind", "LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_subkind", "FStar.Pervasives.Native.Some", "LowParse.Spec.Base.ParserStrong", "Prims.nat", "LowParse.Low.Writers.swriter", "LowParse.Low.Writers.Instances.swrite_nondep_then'", "LowParse.Low.Writers.weaken_swriter", "LowParse.Low.Writers.Instances.max", "LowParse.Spec.Combinators.and_then_kind", "FStar.Pervasives.Native.tuple2", "LowParse.Spec.Combinators.nondep_then", "LowParse.Spec.Combinators.serialize_nondep_then", "LowParse.Low.Writers.swvalue", "FStar.Pervasives.Native.Mktuple2" ]
[]
false
false
false
false
false
let swrite_nondep_then (#h0: HS.mem) (#sout: slice (srel_of_buffer_srel (B.trivial_preorder _)) (srel_of_buffer_srel (B.trivial_preorder _))) (#pout_from0: U32.t) (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#s1: serializer p1 {k1.parser_kind_subkind == Some ParserStrong}) (#space_beyond1: nat) (w1: swriter s1 h0 space_beyond1 sout pout_from0) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (#s2: serializer p2 {k2.parser_kind_subkind == Some ParserStrong}) (#space_beyond2: nat) (w2: swriter s2 h0 space_beyond2 sout pout_from0) : Tot (w: swriter (s1 `serialize_nondep_then` s2) h0 (space_beyond1 `max` space_beyond2) sout pout_from0 {swvalue w == (swvalue w1, swvalue w2)}) =
[@@ inline_let ]let sbmax = space_beyond1 `max` space_beyond2 in (weaken_swriter w1 h0 sbmax pout_from0) `swrite_nondep_then'` (weaken_swriter w2 h0 sbmax pout_from0)
false
LatticeSpec.fst
LatticeSpec.test1
val test1 (x y: int) : EFFT int [EXN; RD; WR]
val test1 (x y: int) : EFFT int [EXN; RD; WR]
let test1 (x y : int) : EFFT int [EXN; RD; WR] by (compute ())= let z = get () in if x + z > 0 then raise () else (put 42; y - z)
{ "file_name": "examples/layeredeffects/LatticeSpec.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 22, "end_line": 234, "start_col": 0, "start_line": 230 }
module LatticeSpec open FStar.Tactics.V2 open FStar.List.Tot // 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 = | RD | WR | EXN type annot = eff_label -> bool // warning: if this is not annotated, `eqtype` is inferred // as its type and the effect definition fails for some reason. type state : Type = int type pre_t = state -> Type0 type post_t a = state -> option a -> state -> Type0 // this repr doesn't seem to work too well type repr0 (a:Type u#aa) (pre : pre_t) (post : post_t u#aa a) // #2074 : Type u#aa = s0:state{pre s0} -> Tot (r:(option a & state){post s0 (fst r) (snd r)}) let abides #a #pre #post (f : repr0 a pre post) (ann:annot) : Type0 = (ann RD = false ==> (forall s0 s1. fst (f s0) == fst (f s1))) /\ (ann WR = false ==> (forall s0. snd (f s0) == s0)) /\ (ann EXN = false ==> (forall s0. Some? (fst (f s0)))) let interp (l : list eff_label) : annot = fun lab -> mem lab 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 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 type repr (a:Type u#aa) (pre : pre_t) (post : post_t u#aa a) // #2074 (labs : list u#0 eff_label) // #2074 : Type u#aa = r:(repr0 a pre post){abides r (interp labs)} let ann_le (ann1 ann2 : annot) : Type0 = forall x. ann1 x ==> ann2 x let return (a:Type u#aa) (x:a) : Tot (repr a (fun _ -> True) (fun s0 y s1 -> s0 == s1 /\ y == Some x) []) = // GM: Need to write it like this.. why? let r (s0:state) : Tot (r:(option a & state){snd r == s0 /\ fst r == Some x}) = (Some x, s0) in r unfold let bind_pre (a:Type) (pre1:pre_t) (post1:post_t a) (b:Type) (pre2:a -> pre_t) (post2:a -> post_t b) : pre_t = fun s0 -> pre1 s0 /\ (forall y s1. post1 s0 (Some y) s1 ==> pre2 y s1) unfold let bind_post (a:Type) (pre1:pre_t) (post1:post_t a) (b:Type) (pre2:a -> pre_t) (post2:a -> post_t b) : post_t b = fun s0 z s2 -> (exists s1 y. post1 s0 (Some y) s1 /\ post2 y s1 z s2) \/ (post1 s0 None s2) let bind (a b : Type) pre1 post1 (labs1 : list eff_label) pre2 post2 (labs2 : list eff_label) (c : repr a pre1 post1 labs1) (f : (x:a -> repr b (pre2 x) (post2 x) labs2)) : Tot (repr b (bind_pre a pre1 post1 b pre2 post2) (bind_post a pre1 post1 b pre2 post2) (labs1@labs2)) = let pre = bind_pre a pre1 post1 b pre2 post2 in let post = bind_post a pre1 post1 b pre2 post2 in let r (s0:state{pre s0}) : Tot (r:(option b & state){post s0 (fst r) (snd r)}) = match c s0 with | Some x, s1 -> assert (post1 s0 (Some x) s1); assert (pre2 x s1); f x s1 | None, s1 -> None, s1 in r let subcomp (a:Type) (pre1 : pre_t) (post1 : post_t a) (labs1 : list eff_label) (pre2 : pre_t) (post2 : post_t a) (labs2 : list eff_label) (f : repr a pre1 post1 labs1) : Pure (repr a pre2 post2 labs2) (requires ((forall s0. pre2 s0 ==> pre1 s0) /\ (forall s0 r s1. post1 s0 r s1 ==> post2 s0 r s1) /\ sublist labs1 labs2)) (ensures (fun _ -> True)) = f unfold let ite (p q r : Type0) = (p ==> q) /\ ((~p) ==> r) let if_then_else (a : Type) (pre1 : pre_t) (post1 : post_t a) (labs1 : list eff_label) (pre2 : pre_t) (post2 : post_t a) (labs2 : list eff_label) (f : repr a pre1 post1 labs1) (g : repr a pre2 post2 labs2) (b : bool) : Type = repr a (fun s0 -> ite b (pre1 s0) (pre2 s0)) (fun s0 y s1 -> ite b (post1 s0 y s1) (post2 s0 y s1)) (labs1@labs2) total // need this for catch!! reifiable reflectable effect { EFF (a:Type) (_:pre_t) (_:post_t a) (_:list eff_label) with {repr; return; bind; subcomp; if_then_else} } unfold let sp #a (wp : pure_wp a) : pure_post a = fun x -> ~ (wp (fun y -> ~(x == y))) unfold let post_of_wp #a (wp : pure_wp a) : post_t a = fun s0 r s1 -> s0 == s1 /\ Some? r /\ sp wp (Some?.v r) let lift_pure_eff (a:Type) (wp : pure_wp a) (f : unit -> PURE a wp) : repr a (fun _ -> wp (fun _ -> True)) (post_of_wp wp) [] = FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp; let r (s0:state{wp (fun _ -> True)}) : Tot (r:(option a & state){snd r == s0 /\ Some? (fst r) /\ sp wp (Some?.v (fst r))}) = (Some (f ()), s0) in r sub_effect PURE ~> EFF = lift_pure_eff let _get : repr state (fun _ -> True) (fun s0 y s1 -> s1 == s0 /\ y == Some s0) [RD] = let ff (s0:state) : Tot (r:(option state & state){fst r == Some s0 /\ snd r == s0}) = (Some s0, s0) in ff let get () : EFF int (fun _ -> True) (fun s0 y s1 -> s1 == s0 /\ y == Some s0) [RD] by (compute (); dump"") = EFF?.reflect _get let _put (s:state) : repr unit (fun _ -> True) (fun _ y s1 -> s1 == s /\ y == Some ()) [WR] = // GM: pretty odd that I have to add `r == Some ()` here.... let ff (_:state) : Tot (r:(option unit & state){fst r == Some () /\ snd r == s}) = (Some (), s) in ff let put (s:state) : EFF unit (fun _ -> True) (fun _ y s1 -> s1 == s) [WR] = EFF?.reflect (_put s) let _raise #a : repr a (fun _ -> True) (fun s0 _ s1 -> s1 == s0) [EXN] = let ff (s0:state) : Tot (r:(option a & state){fst r == None /\ snd r == s0}) = (None, s0) in ff let raise #a () : EFF a (fun _ -> True) (fun s0 _ s1 -> s1 == s0) [EXN] = EFF?.reflect _raise effect EFFT (a:Type) (labs:list eff_label) = EFF a (fun _ -> True) (fun _ _ _ -> True) labs let test0 (x y : int) : EFFT int [RD; EXN] = let z = get () in if x + z > 0 then raise () else y - z
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LatticeSpec.fst" }
[ { "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: Prims.int -> y: Prims.int -> LatticeSpec.EFFT Prims.int
LatticeSpec.EFFT
[]
[]
[ "Prims.int", "Prims.op_GreaterThan", "Prims.op_Addition", "LatticeSpec.raise", "Prims.bool", "Prims.op_Subtraction", "Prims.unit", "LatticeSpec.put", "LatticeSpec.get", "Prims.Cons", "LatticeSpec.eff_label", "LatticeSpec.EXN", "LatticeSpec.RD", "LatticeSpec.WR", "Prims.Nil", "FStar.Tactics.V2.Derived.compute" ]
[]
false
true
false
false
false
let test1 (x y: int) : EFFT int [EXN; RD; WR] by (compute ()) =
let z = get () in if x + z > 0 then raise () else (put 42; y - z)
false
PulseCore.Preorder.fst
PulseCore.Preorder.stable_compatiblity
val stable_compatiblity (#a: Type u#a) (fact: (a -> prop)) (p: pcm a) (v v0 v1: a) : Lemma (requires stable fact (preorder_of_pcm p) /\ p.refine v0 /\ fact v0 /\ p.refine v1 /\ frame_preserving p v v1 /\ compatible p v v0) (ensures fact v1)
val stable_compatiblity (#a: Type u#a) (fact: (a -> prop)) (p: pcm a) (v v0 v1: a) : Lemma (requires stable fact (preorder_of_pcm p) /\ p.refine v0 /\ fact v0 /\ p.refine v1 /\ frame_preserving p v v1 /\ compatible p v v0) (ensures fact v1)
let stable_compatiblity (#a:Type u#a) (fact: a -> prop) (p:pcm a) (v v0 v1:a) : Lemma (requires stable fact (preorder_of_pcm p) /\ p.refine v0 /\ fact v0 /\ p.refine v1 /\ frame_preserving p v v1 /\ compatible p v v0) (ensures fact v1) = let f : frame_preserving_upd p v v1 = frame_preserving_val_to_fp_upd p v v1 in frame_preserving_upd_is_preorder_preserving p v v1 f v0
{ "file_name": "lib/pulse_core/PulseCore.Preorder.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 59, "end_line": 76, "start_col": 0, "start_line": 64 }
(* 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 PulseCore.Preorder open FStar.PCM open FStar.Preorder open PulseCore.FractionalPermission open FStar.Real /// This module explores the connection between PCM and preorders. More specifically, we show here /// that any PCM induces a preorder relation, characterized by frame-preservation for any updates. /// /// Furthermore, we also consider the reverse relationship where we derive a PCM for any preorder, /// by taking as elements of the PCM the trace of all the states of the element. (**** PCM to preoder *) (** PCM [p] induces the preorder [q] if for any frame preserving update of [x] to [y], the argument and result of the frame preserving update are related by q *) let induces_preorder (#a:Type u#a) (p:pcm a) (q:preorder a) = forall (x y:a) (f:frame_preserving_upd p x y) (v:a). p.refine v ==> compatible p x v ==> q v (f v) (** We can define a canonical preorder from any PCM by taking the quantified conjunction over all the preorders [q] induced by this PCM. *) let preorder_of_pcm (#a:Type u#a) (p:pcm a) : preorder a = fun x y -> forall (q:preorder a). induces_preorder p q ==> q x y let frame_preserving_upd_is_preorder_preserving (#a:Type u#a) (p:pcm a) (x y:a) (f:frame_preserving_upd p x y) (v_old:a{p.refine v_old /\ compatible p x v_old}) : Lemma ((preorder_of_pcm p) v_old (f v_old)) = () (** This canonical preorder enjoys the nice property that it preserves fact stability of any induced preorder *) let stability (#a: Type u#a) (fact:a -> prop) (q:preorder a) (p:pcm a) : Lemma (requires stable fact q /\ induces_preorder p q) (ensures stable fact (preorder_of_pcm p)) = ()
{ "checked_file": "/", "dependencies": [ "PulseCore.FractionalPermission.fst.checked", "prims.fst.checked", "FStar.Real.fsti.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked", "FStar.List.Tot.fst.checked", "FStar.IndefiniteDescription.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "PulseCore.Preorder.fst" }
[ { "abbrev": false, "full_module": "FStar.Real", "short_module": null }, { "abbrev": false, "full_module": "PulseCore.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "FStar.Preorder", "short_module": null }, { "abbrev": false, "full_module": "FStar.PCM", "short_module": null }, { "abbrev": false, "full_module": "PulseCore", "short_module": null }, { "abbrev": false, "full_module": "PulseCore", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
fact: (_: a -> Prims.prop) -> p: FStar.PCM.pcm a -> v: a -> v0: a -> v1: a -> FStar.Pervasives.Lemma (requires FStar.Preorder.stable fact (PulseCore.Preorder.preorder_of_pcm p) /\ Mkpcm?.refine p v0 /\ fact v0 /\ Mkpcm?.refine p v1 /\ FStar.PCM.frame_preserving p v v1 /\ FStar.PCM.compatible p v v0) (ensures fact v1)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.prop", "FStar.PCM.pcm", "PulseCore.Preorder.frame_preserving_upd_is_preorder_preserving", "FStar.PCM.frame_preserving_upd", "FStar.PCM.frame_preserving_val_to_fp_upd", "FStar.Ghost.hide", "Prims.unit", "Prims.l_and", "FStar.Preorder.stable", "PulseCore.Preorder.preorder_of_pcm", "FStar.PCM.__proj__Mkpcm__item__refine", "FStar.PCM.frame_preserving", "FStar.PCM.compatible", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
true
false
true
false
false
let stable_compatiblity (#a: Type u#a) (fact: (a -> prop)) (p: pcm a) (v v0 v1: a) : Lemma (requires stable fact (preorder_of_pcm p) /\ p.refine v0 /\ fact v0 /\ p.refine v1 /\ frame_preserving p v v1 /\ compatible p v v0) (ensures fact v1) =
let f:frame_preserving_upd p v v1 = frame_preserving_val_to_fp_upd p v v1 in frame_preserving_upd_is_preorder_preserving p v v1 f v0
false
PulseCore.Preorder.fst
PulseCore.Preorder.extends'
val extends' : h0: PulseCore.Preorder.hist q -> h1: PulseCore.Preorder.hist q -> Prims.logical
let rec extends' (#a: Type u#a) (#q:preorder a) (h0 h1:hist q) = h0 == h1 \/ (Cons? h0 /\ extends' (Cons?.tl h0) h1)
{ "file_name": "lib/pulse_core/PulseCore.Preorder.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 53, "end_line": 98, "start_col": 0, "start_line": 97 }
(* 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 PulseCore.Preorder open FStar.PCM open FStar.Preorder open PulseCore.FractionalPermission open FStar.Real /// This module explores the connection between PCM and preorders. More specifically, we show here /// that any PCM induces a preorder relation, characterized by frame-preservation for any updates. /// /// Furthermore, we also consider the reverse relationship where we derive a PCM for any preorder, /// by taking as elements of the PCM the trace of all the states of the element. (**** PCM to preoder *) (** PCM [p] induces the preorder [q] if for any frame preserving update of [x] to [y], the argument and result of the frame preserving update are related by q *) let induces_preorder (#a:Type u#a) (p:pcm a) (q:preorder a) = forall (x y:a) (f:frame_preserving_upd p x y) (v:a). p.refine v ==> compatible p x v ==> q v (f v) (** We can define a canonical preorder from any PCM by taking the quantified conjunction over all the preorders [q] induced by this PCM. *) let preorder_of_pcm (#a:Type u#a) (p:pcm a) : preorder a = fun x y -> forall (q:preorder a). induces_preorder p q ==> q x y let frame_preserving_upd_is_preorder_preserving (#a:Type u#a) (p:pcm a) (x y:a) (f:frame_preserving_upd p x y) (v_old:a{p.refine v_old /\ compatible p x v_old}) : Lemma ((preorder_of_pcm p) v_old (f v_old)) = () (** This canonical preorder enjoys the nice property that it preserves fact stability of any induced preorder *) let stability (#a: Type u#a) (fact:a -> prop) (q:preorder a) (p:pcm a) : Lemma (requires stable fact q /\ induces_preorder p q) (ensures stable fact (preorder_of_pcm p)) = () let stable_compatiblity (#a:Type u#a) (fact: a -> prop) (p:pcm a) (v v0 v1:a) : Lemma (requires stable fact (preorder_of_pcm p) /\ p.refine v0 /\ fact v0 /\ p.refine v1 /\ frame_preserving p v v1 /\ compatible p v v0) (ensures fact v1) = let f : frame_preserving_upd p v v1 = frame_preserving_val_to_fp_upd p v v1 in frame_preserving_upd_is_preorder_preserving p v v1 f v0 (**** Preorder to PCM *) (***** Building the preorder *) (** This predicate tells that the list [l] can represent a trace of elements whose evolution is compatible with the preorder [q] *) let rec qhistory #a (q:preorder a) (l:list a) = match l with | [] | [_] -> True | x::y::tl -> y `q` x /\ qhistory q (y::tl) (** The history of a preorder is the type of all the traces compatible with that preorder *) let hist (#a: Type u#a) (q:preorder a) = l:list a{qhistory q l}
{ "checked_file": "/", "dependencies": [ "PulseCore.FractionalPermission.fst.checked", "prims.fst.checked", "FStar.Real.fsti.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked", "FStar.List.Tot.fst.checked", "FStar.IndefiniteDescription.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "PulseCore.Preorder.fst" }
[ { "abbrev": false, "full_module": "FStar.Real", "short_module": null }, { "abbrev": false, "full_module": "PulseCore.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "FStar.Preorder", "short_module": null }, { "abbrev": false, "full_module": "FStar.PCM", "short_module": null }, { "abbrev": false, "full_module": "PulseCore", "short_module": null }, { "abbrev": false, "full_module": "PulseCore", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
h0: PulseCore.Preorder.hist q -> h1: PulseCore.Preorder.hist q -> Prims.logical
Prims.Tot
[ "total" ]
[]
[ "FStar.Preorder.preorder", "PulseCore.Preorder.hist", "Prims.l_or", "Prims.eq2", "Prims.l_and", "Prims.b2t", "Prims.uu___is_Cons", "PulseCore.Preorder.extends'", "Prims.__proj__Cons__item__tl", "Prims.logical" ]
[ "recursion" ]
false
false
false
false
true
let rec extends' (#a: Type u#a) (#q: preorder a) (h0 h1: hist q) =
h0 == h1 \/ (Cons? h0 /\ extends' (Cons?.tl h0) h1)
false
PulseCore.Preorder.fst
PulseCore.Preorder.vhist
val vhist : q: FStar.Preorder.preorder a -> Type
let vhist (#a: Type u#a) (q:preorder a) = h:hist q{Cons? h}
{ "file_name": "lib/pulse_core/PulseCore.Preorder.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 59, "end_line": 217, "start_col": 0, "start_line": 217 }
(* 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 PulseCore.Preorder open FStar.PCM open FStar.Preorder open PulseCore.FractionalPermission open FStar.Real /// This module explores the connection between PCM and preorders. More specifically, we show here /// that any PCM induces a preorder relation, characterized by frame-preservation for any updates. /// /// Furthermore, we also consider the reverse relationship where we derive a PCM for any preorder, /// by taking as elements of the PCM the trace of all the states of the element. (**** PCM to preoder *) (** PCM [p] induces the preorder [q] if for any frame preserving update of [x] to [y], the argument and result of the frame preserving update are related by q *) let induces_preorder (#a:Type u#a) (p:pcm a) (q:preorder a) = forall (x y:a) (f:frame_preserving_upd p x y) (v:a). p.refine v ==> compatible p x v ==> q v (f v) (** We can define a canonical preorder from any PCM by taking the quantified conjunction over all the preorders [q] induced by this PCM. *) let preorder_of_pcm (#a:Type u#a) (p:pcm a) : preorder a = fun x y -> forall (q:preorder a). induces_preorder p q ==> q x y let frame_preserving_upd_is_preorder_preserving (#a:Type u#a) (p:pcm a) (x y:a) (f:frame_preserving_upd p x y) (v_old:a{p.refine v_old /\ compatible p x v_old}) : Lemma ((preorder_of_pcm p) v_old (f v_old)) = () (** This canonical preorder enjoys the nice property that it preserves fact stability of any induced preorder *) let stability (#a: Type u#a) (fact:a -> prop) (q:preorder a) (p:pcm a) : Lemma (requires stable fact q /\ induces_preorder p q) (ensures stable fact (preorder_of_pcm p)) = () let stable_compatiblity (#a:Type u#a) (fact: a -> prop) (p:pcm a) (v v0 v1:a) : Lemma (requires stable fact (preorder_of_pcm p) /\ p.refine v0 /\ fact v0 /\ p.refine v1 /\ frame_preserving p v v1 /\ compatible p v v0) (ensures fact v1) = let f : frame_preserving_upd p v v1 = frame_preserving_val_to_fp_upd p v v1 in frame_preserving_upd_is_preorder_preserving p v v1 f v0 (**** Preorder to PCM *) (***** Building the preorder *) (** This predicate tells that the list [l] can represent a trace of elements whose evolution is compatible with the preorder [q] *) let rec qhistory #a (q:preorder a) (l:list a) = match l with | [] | [_] -> True | x::y::tl -> y `q` x /\ qhistory q (y::tl) (** The history of a preorder is the type of all the traces compatible with that preorder *) let hist (#a: Type u#a) (q:preorder a) = l:list a{qhistory q l} (** Two compatible traces can extend each other *) let rec extends' (#a: Type u#a) (#q:preorder a) (h0 h1:hist q) = h0 == h1 \/ (Cons? h0 /\ extends' (Cons?.tl h0) h1) (** This extension relation is transitive *) let rec extends_trans #a (#q:preorder a) (x y z:hist q) : Lemma (x `extends'` y /\ y `extends'` z ==> x `extends'` z) [SMTPat (x `extends'` y); SMTPat (y `extends'` z)] = match x with | [] -> () | _::tl -> extends_trans tl y z (** And it is also reflexive, so extensibility on traces is a preorder on traces *) let extends (#a: Type u#a) (#q:preorder a) : preorder (hist q) = extends' module L = FStar.List.Tot (** If [h0] extends by [h1], then the length of [h0] is superior *) let rec extends_length_eq (#a: Type u#a) (#q:preorder a) (h0 h1:hist q) : Lemma (ensures (extends h0 h1 ==> h0 == h1 \/ L.length h0 > L.length h1)) [SMTPat (extends h0 h1)] = match h0 with | [] -> () | hd::tl -> extends_length_eq tl h1 (** We build our relation of composability for traces by reflexing the extension to ensure symmetry *) let p_composable (#a: Type u#a) (q:preorder a) : symrel (hist q) = fun x y -> extends x y \/ extends y x (** The operation for the PCM is to return the full trace of two extensible traces *) let p_op (#a: Type u#a) (q:preorder a) (x:hist q) (y:hist q{p_composable q x y}) : hist q = if L.length x >= L.length y then x else if L.length x = L.length y then (assert (x == y); x) else y (** The operation actually implements extension *) let p_op_extends (#a: Type u#a) (q:preorder a) (x:hist q) (y:hist q{p_composable q x y}) : Lemma (ensures (p_op q x y `extends` x /\ p_op q x y `extends` y /\ (p_op q x y == x \/ p_op q x y == y))) [SMTPat (p_op q x y)] = extends_length_eq x y; extends_length_eq y x (** And the empty trace is the unit element *) let rec p_op_nil (#a: Type u#a) (q:preorder a) (x:hist q) : Lemma (ensures (p_composable q x [] /\ p_op q x [] == x)) [SMTPat (p_composable q x [])] = match x with | [] -> () | _::tl -> p_op_nil q tl (** We can finally define our PCM with these operations *) let p (#a: Type u#a) (q:preorder a) : pcm' (hist q) = { composable = p_composable q; op = p_op q; one = [] } (** Composability is commutative *) let comm (#a: Type u#a) (q:preorder a) (x y:hist q) : Lemma (requires p_composable q x y) (ensures p_composable q y x) = () (** As well as the compose operation *) let comm_op (#a: Type u#a) (q:preorder a) (x:hist q) (y:hist q{p_composable q x y}) : Lemma (p_op q x y == p_op q y x) = extends_length_eq x y; extends_length_eq y x (** If [z] extends [x] and [y], then [x] and [y] are extending one or another *) let rec extends_disjunction (#a: Type u#a) (#q:preorder a) (x y z:hist q) : Lemma (z `extends` x /\ z `extends` y ==> x `extends` y \/ y `extends` x) [SMTPat (z `extends` x); SMTPat (z `extends` y)] = match z with | [] -> () | _::tl -> extends_disjunction x y tl (** If [x] extends [y], then the two heads of the traces are still related by the preorder *) let rec extends_related_head (#a: Type u#a) (#q:preorder a) (x y:hist q) : Lemma (ensures x `extends` y /\ Cons? x /\ Cons? y ==> Cons?.hd y `q` Cons?.hd x) [SMTPat (x `extends` y)] = match x with | [] -> () | _::tl -> extends_related_head tl y (** Finally, we can have our fully-fledged PCM from the preorder *) let pcm_of_preorder (#a: Type u#a) (q:preorder a) : pcm (hist q) = { p = p q; comm = comm_op q; assoc = (fun _ _ _ -> ()); assoc_r = (fun _ _ _ -> ()); is_unit = (fun _ -> ()); refine = (fun _ -> True) } (***** Using the preorder *) (** We check that the preorder derived from the PCM derived from the preorder satisfies the same properties as the original preorder. Here, we get back history extension from frame-preserving updates. *) let frame_preserving_q_aux (#a : Type u#a) (q:preorder a) (x y:hist q) (z:hist q) : Lemma (requires (frame_preserving (pcm_of_preorder q) x y /\ compatible (pcm_of_preorder q) x z)) (ensures (y `extends` z)) = ()
{ "checked_file": "/", "dependencies": [ "PulseCore.FractionalPermission.fst.checked", "prims.fst.checked", "FStar.Real.fsti.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked", "FStar.List.Tot.fst.checked", "FStar.IndefiniteDescription.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "PulseCore.Preorder.fst" }
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Real", "short_module": null }, { "abbrev": false, "full_module": "PulseCore.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "FStar.Preorder", "short_module": null }, { "abbrev": false, "full_module": "FStar.PCM", "short_module": null }, { "abbrev": false, "full_module": "PulseCore", "short_module": null }, { "abbrev": false, "full_module": "PulseCore", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
q: FStar.Preorder.preorder a -> Type
Prims.Tot
[ "total" ]
[]
[ "FStar.Preorder.preorder", "PulseCore.Preorder.hist", "Prims.b2t", "Prims.uu___is_Cons" ]
[]
false
false
false
true
true
let vhist (#a: Type u#a) (q: preorder a) =
h: hist q {Cons? h}
false
PulseCore.Preorder.fst
PulseCore.Preorder.extends
val extends (#a: Type u#a) (#q: preorder a) : preorder (hist q)
val extends (#a: Type u#a) (#q: preorder a) : preorder (hist q)
let extends (#a: Type u#a) (#q:preorder a) : preorder (hist q) = extends'
{ "file_name": "lib/pulse_core/PulseCore.Preorder.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 73, "end_line": 110, "start_col": 0, "start_line": 110 }
(* 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 PulseCore.Preorder open FStar.PCM open FStar.Preorder open PulseCore.FractionalPermission open FStar.Real /// This module explores the connection between PCM and preorders. More specifically, we show here /// that any PCM induces a preorder relation, characterized by frame-preservation for any updates. /// /// Furthermore, we also consider the reverse relationship where we derive a PCM for any preorder, /// by taking as elements of the PCM the trace of all the states of the element. (**** PCM to preoder *) (** PCM [p] induces the preorder [q] if for any frame preserving update of [x] to [y], the argument and result of the frame preserving update are related by q *) let induces_preorder (#a:Type u#a) (p:pcm a) (q:preorder a) = forall (x y:a) (f:frame_preserving_upd p x y) (v:a). p.refine v ==> compatible p x v ==> q v (f v) (** We can define a canonical preorder from any PCM by taking the quantified conjunction over all the preorders [q] induced by this PCM. *) let preorder_of_pcm (#a:Type u#a) (p:pcm a) : preorder a = fun x y -> forall (q:preorder a). induces_preorder p q ==> q x y let frame_preserving_upd_is_preorder_preserving (#a:Type u#a) (p:pcm a) (x y:a) (f:frame_preserving_upd p x y) (v_old:a{p.refine v_old /\ compatible p x v_old}) : Lemma ((preorder_of_pcm p) v_old (f v_old)) = () (** This canonical preorder enjoys the nice property that it preserves fact stability of any induced preorder *) let stability (#a: Type u#a) (fact:a -> prop) (q:preorder a) (p:pcm a) : Lemma (requires stable fact q /\ induces_preorder p q) (ensures stable fact (preorder_of_pcm p)) = () let stable_compatiblity (#a:Type u#a) (fact: a -> prop) (p:pcm a) (v v0 v1:a) : Lemma (requires stable fact (preorder_of_pcm p) /\ p.refine v0 /\ fact v0 /\ p.refine v1 /\ frame_preserving p v v1 /\ compatible p v v0) (ensures fact v1) = let f : frame_preserving_upd p v v1 = frame_preserving_val_to_fp_upd p v v1 in frame_preserving_upd_is_preorder_preserving p v v1 f v0 (**** Preorder to PCM *) (***** Building the preorder *) (** This predicate tells that the list [l] can represent a trace of elements whose evolution is compatible with the preorder [q] *) let rec qhistory #a (q:preorder a) (l:list a) = match l with | [] | [_] -> True | x::y::tl -> y `q` x /\ qhistory q (y::tl) (** The history of a preorder is the type of all the traces compatible with that preorder *) let hist (#a: Type u#a) (q:preorder a) = l:list a{qhistory q l} (** Two compatible traces can extend each other *) let rec extends' (#a: Type u#a) (#q:preorder a) (h0 h1:hist q) = h0 == h1 \/ (Cons? h0 /\ extends' (Cons?.tl h0) h1) (** This extension relation is transitive *) let rec extends_trans #a (#q:preorder a) (x y z:hist q) : Lemma (x `extends'` y /\ y `extends'` z ==> x `extends'` z) [SMTPat (x `extends'` y); SMTPat (y `extends'` z)] = match x with | [] -> () | _::tl -> extends_trans tl y z
{ "checked_file": "/", "dependencies": [ "PulseCore.FractionalPermission.fst.checked", "prims.fst.checked", "FStar.Real.fsti.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked", "FStar.List.Tot.fst.checked", "FStar.IndefiniteDescription.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "PulseCore.Preorder.fst" }
[ { "abbrev": false, "full_module": "FStar.Real", "short_module": null }, { "abbrev": false, "full_module": "PulseCore.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "FStar.Preorder", "short_module": null }, { "abbrev": false, "full_module": "FStar.PCM", "short_module": null }, { "abbrev": false, "full_module": "PulseCore", "short_module": null }, { "abbrev": false, "full_module": "PulseCore", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
FStar.Preorder.preorder (PulseCore.Preorder.hist q)
Prims.Tot
[ "total" ]
[]
[ "FStar.Preorder.preorder", "PulseCore.Preorder.extends'", "PulseCore.Preorder.hist" ]
[]
false
false
false
false
false
let extends (#a: Type u#a) (#q: preorder a) : preorder (hist q) =
extends'
false
PulseCore.Preorder.fst
PulseCore.Preorder.p_composable
val p_composable (#a: Type u#a) (q: preorder a) : symrel (hist q)
val p_composable (#a: Type u#a) (q: preorder a) : symrel (hist q)
let p_composable (#a: Type u#a) (q:preorder a) : symrel (hist q) = fun x y -> extends x y \/ extends y x
{ "file_name": "lib/pulse_core/PulseCore.Preorder.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 41, "end_line": 127, "start_col": 0, "start_line": 126 }
(* 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 PulseCore.Preorder open FStar.PCM open FStar.Preorder open PulseCore.FractionalPermission open FStar.Real /// This module explores the connection between PCM and preorders. More specifically, we show here /// that any PCM induces a preorder relation, characterized by frame-preservation for any updates. /// /// Furthermore, we also consider the reverse relationship where we derive a PCM for any preorder, /// by taking as elements of the PCM the trace of all the states of the element. (**** PCM to preoder *) (** PCM [p] induces the preorder [q] if for any frame preserving update of [x] to [y], the argument and result of the frame preserving update are related by q *) let induces_preorder (#a:Type u#a) (p:pcm a) (q:preorder a) = forall (x y:a) (f:frame_preserving_upd p x y) (v:a). p.refine v ==> compatible p x v ==> q v (f v) (** We can define a canonical preorder from any PCM by taking the quantified conjunction over all the preorders [q] induced by this PCM. *) let preorder_of_pcm (#a:Type u#a) (p:pcm a) : preorder a = fun x y -> forall (q:preorder a). induces_preorder p q ==> q x y let frame_preserving_upd_is_preorder_preserving (#a:Type u#a) (p:pcm a) (x y:a) (f:frame_preserving_upd p x y) (v_old:a{p.refine v_old /\ compatible p x v_old}) : Lemma ((preorder_of_pcm p) v_old (f v_old)) = () (** This canonical preorder enjoys the nice property that it preserves fact stability of any induced preorder *) let stability (#a: Type u#a) (fact:a -> prop) (q:preorder a) (p:pcm a) : Lemma (requires stable fact q /\ induces_preorder p q) (ensures stable fact (preorder_of_pcm p)) = () let stable_compatiblity (#a:Type u#a) (fact: a -> prop) (p:pcm a) (v v0 v1:a) : Lemma (requires stable fact (preorder_of_pcm p) /\ p.refine v0 /\ fact v0 /\ p.refine v1 /\ frame_preserving p v v1 /\ compatible p v v0) (ensures fact v1) = let f : frame_preserving_upd p v v1 = frame_preserving_val_to_fp_upd p v v1 in frame_preserving_upd_is_preorder_preserving p v v1 f v0 (**** Preorder to PCM *) (***** Building the preorder *) (** This predicate tells that the list [l] can represent a trace of elements whose evolution is compatible with the preorder [q] *) let rec qhistory #a (q:preorder a) (l:list a) = match l with | [] | [_] -> True | x::y::tl -> y `q` x /\ qhistory q (y::tl) (** The history of a preorder is the type of all the traces compatible with that preorder *) let hist (#a: Type u#a) (q:preorder a) = l:list a{qhistory q l} (** Two compatible traces can extend each other *) let rec extends' (#a: Type u#a) (#q:preorder a) (h0 h1:hist q) = h0 == h1 \/ (Cons? h0 /\ extends' (Cons?.tl h0) h1) (** This extension relation is transitive *) let rec extends_trans #a (#q:preorder a) (x y z:hist q) : Lemma (x `extends'` y /\ y `extends'` z ==> x `extends'` z) [SMTPat (x `extends'` y); SMTPat (y `extends'` z)] = match x with | [] -> () | _::tl -> extends_trans tl y z (** And it is also reflexive, so extensibility on traces is a preorder on traces *) let extends (#a: Type u#a) (#q:preorder a) : preorder (hist q) = extends' module L = FStar.List.Tot (** If [h0] extends by [h1], then the length of [h0] is superior *) let rec extends_length_eq (#a: Type u#a) (#q:preorder a) (h0 h1:hist q) : Lemma (ensures (extends h0 h1 ==> h0 == h1 \/ L.length h0 > L.length h1)) [SMTPat (extends h0 h1)] = match h0 with | [] -> () | hd::tl -> extends_length_eq tl h1 (** We build our relation of composability for traces by reflexing the extension to ensure symmetry
{ "checked_file": "/", "dependencies": [ "PulseCore.FractionalPermission.fst.checked", "prims.fst.checked", "FStar.Real.fsti.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked", "FStar.List.Tot.fst.checked", "FStar.IndefiniteDescription.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "PulseCore.Preorder.fst" }
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Real", "short_module": null }, { "abbrev": false, "full_module": "PulseCore.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "FStar.Preorder", "short_module": null }, { "abbrev": false, "full_module": "FStar.PCM", "short_module": null }, { "abbrev": false, "full_module": "PulseCore", "short_module": null }, { "abbrev": false, "full_module": "PulseCore", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
q: FStar.Preorder.preorder a -> FStar.PCM.symrel (PulseCore.Preorder.hist q)
Prims.Tot
[ "total" ]
[]
[ "FStar.Preorder.preorder", "PulseCore.Preorder.hist", "Prims.l_or", "PulseCore.Preorder.extends", "Prims.prop", "FStar.PCM.symrel" ]
[]
false
false
false
false
false
let p_composable (#a: Type u#a) (q: preorder a) : symrel (hist q) =
fun x y -> extends x y \/ extends y x
false
PulseCore.Preorder.fst
PulseCore.Preorder.extends_trans
val extends_trans (#a: _) (#q: preorder a) (x y z: hist q) : Lemma (x `extends'` y /\ y `extends'` z ==> x `extends'` z) [SMTPat (x `extends'` y); SMTPat (y `extends'` z)]
val extends_trans (#a: _) (#q: preorder a) (x y z: hist q) : Lemma (x `extends'` y /\ y `extends'` z ==> x `extends'` z) [SMTPat (x `extends'` y); SMTPat (y `extends'` z)]
let rec extends_trans #a (#q:preorder a) (x y z:hist q) : Lemma (x `extends'` y /\ y `extends'` z ==> x `extends'` z) [SMTPat (x `extends'` y); SMTPat (y `extends'` z)] = match x with | [] -> () | _::tl -> extends_trans tl y z
{ "file_name": "lib/pulse_core/PulseCore.Preorder.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 35, "end_line": 107, "start_col": 0, "start_line": 101 }
(* 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 PulseCore.Preorder open FStar.PCM open FStar.Preorder open PulseCore.FractionalPermission open FStar.Real /// This module explores the connection between PCM and preorders. More specifically, we show here /// that any PCM induces a preorder relation, characterized by frame-preservation for any updates. /// /// Furthermore, we also consider the reverse relationship where we derive a PCM for any preorder, /// by taking as elements of the PCM the trace of all the states of the element. (**** PCM to preoder *) (** PCM [p] induces the preorder [q] if for any frame preserving update of [x] to [y], the argument and result of the frame preserving update are related by q *) let induces_preorder (#a:Type u#a) (p:pcm a) (q:preorder a) = forall (x y:a) (f:frame_preserving_upd p x y) (v:a). p.refine v ==> compatible p x v ==> q v (f v) (** We can define a canonical preorder from any PCM by taking the quantified conjunction over all the preorders [q] induced by this PCM. *) let preorder_of_pcm (#a:Type u#a) (p:pcm a) : preorder a = fun x y -> forall (q:preorder a). induces_preorder p q ==> q x y let frame_preserving_upd_is_preorder_preserving (#a:Type u#a) (p:pcm a) (x y:a) (f:frame_preserving_upd p x y) (v_old:a{p.refine v_old /\ compatible p x v_old}) : Lemma ((preorder_of_pcm p) v_old (f v_old)) = () (** This canonical preorder enjoys the nice property that it preserves fact stability of any induced preorder *) let stability (#a: Type u#a) (fact:a -> prop) (q:preorder a) (p:pcm a) : Lemma (requires stable fact q /\ induces_preorder p q) (ensures stable fact (preorder_of_pcm p)) = () let stable_compatiblity (#a:Type u#a) (fact: a -> prop) (p:pcm a) (v v0 v1:a) : Lemma (requires stable fact (preorder_of_pcm p) /\ p.refine v0 /\ fact v0 /\ p.refine v1 /\ frame_preserving p v v1 /\ compatible p v v0) (ensures fact v1) = let f : frame_preserving_upd p v v1 = frame_preserving_val_to_fp_upd p v v1 in frame_preserving_upd_is_preorder_preserving p v v1 f v0 (**** Preorder to PCM *) (***** Building the preorder *) (** This predicate tells that the list [l] can represent a trace of elements whose evolution is compatible with the preorder [q] *) let rec qhistory #a (q:preorder a) (l:list a) = match l with | [] | [_] -> True | x::y::tl -> y `q` x /\ qhistory q (y::tl) (** The history of a preorder is the type of all the traces compatible with that preorder *) let hist (#a: Type u#a) (q:preorder a) = l:list a{qhistory q l} (** Two compatible traces can extend each other *) let rec extends' (#a: Type u#a) (#q:preorder a) (h0 h1:hist q) = h0 == h1 \/ (Cons? h0 /\ extends' (Cons?.tl h0) h1)
{ "checked_file": "/", "dependencies": [ "PulseCore.FractionalPermission.fst.checked", "prims.fst.checked", "FStar.Real.fsti.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked", "FStar.List.Tot.fst.checked", "FStar.IndefiniteDescription.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "PulseCore.Preorder.fst" }
[ { "abbrev": false, "full_module": "FStar.Real", "short_module": null }, { "abbrev": false, "full_module": "PulseCore.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "FStar.Preorder", "short_module": null }, { "abbrev": false, "full_module": "FStar.PCM", "short_module": null }, { "abbrev": false, "full_module": "PulseCore", "short_module": null }, { "abbrev": false, "full_module": "PulseCore", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: PulseCore.Preorder.hist q -> y: PulseCore.Preorder.hist q -> z: PulseCore.Preorder.hist q -> FStar.Pervasives.Lemma (ensures PulseCore.Preorder.extends' x y /\ PulseCore.Preorder.extends' y z ==> PulseCore.Preorder.extends' x z) [SMTPat (PulseCore.Preorder.extends' x y); SMTPat (PulseCore.Preorder.extends' y z)]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "FStar.Preorder.preorder", "PulseCore.Preorder.hist", "Prims.list", "PulseCore.Preorder.extends_trans", "Prims.unit", "Prims.l_True", "Prims.squash", "Prims.l_imp", "Prims.l_and", "PulseCore.Preorder.extends'", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat", "Prims.logical", "Prims.Nil" ]
[ "recursion" ]
false
false
true
false
false
let rec extends_trans #a (#q: preorder a) (x: hist q) (y: hist q) (z: hist q) : Lemma (x `extends'` y /\ y `extends'` z ==> x `extends'` z) [SMTPat (x `extends'` y); SMTPat (y `extends'` z)] =
match x with | [] -> () | _ :: tl -> extends_trans tl y z
false
PulseCore.Preorder.fst
PulseCore.Preorder.qhistory
val qhistory : q: FStar.Preorder.preorder a -> l: Prims.list a -> Prims.logical
let rec qhistory #a (q:preorder a) (l:list a) = match l with | [] | [_] -> True | x::y::tl -> y `q` x /\ qhistory q (y::tl)
{ "file_name": "lib/pulse_core/PulseCore.Preorder.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 45, "end_line": 91, "start_col": 0, "start_line": 87 }
(* 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 PulseCore.Preorder open FStar.PCM open FStar.Preorder open PulseCore.FractionalPermission open FStar.Real /// This module explores the connection between PCM and preorders. More specifically, we show here /// that any PCM induces a preorder relation, characterized by frame-preservation for any updates. /// /// Furthermore, we also consider the reverse relationship where we derive a PCM for any preorder, /// by taking as elements of the PCM the trace of all the states of the element. (**** PCM to preoder *) (** PCM [p] induces the preorder [q] if for any frame preserving update of [x] to [y], the argument and result of the frame preserving update are related by q *) let induces_preorder (#a:Type u#a) (p:pcm a) (q:preorder a) = forall (x y:a) (f:frame_preserving_upd p x y) (v:a). p.refine v ==> compatible p x v ==> q v (f v) (** We can define a canonical preorder from any PCM by taking the quantified conjunction over all the preorders [q] induced by this PCM. *) let preorder_of_pcm (#a:Type u#a) (p:pcm a) : preorder a = fun x y -> forall (q:preorder a). induces_preorder p q ==> q x y let frame_preserving_upd_is_preorder_preserving (#a:Type u#a) (p:pcm a) (x y:a) (f:frame_preserving_upd p x y) (v_old:a{p.refine v_old /\ compatible p x v_old}) : Lemma ((preorder_of_pcm p) v_old (f v_old)) = () (** This canonical preorder enjoys the nice property that it preserves fact stability of any induced preorder *) let stability (#a: Type u#a) (fact:a -> prop) (q:preorder a) (p:pcm a) : Lemma (requires stable fact q /\ induces_preorder p q) (ensures stable fact (preorder_of_pcm p)) = () let stable_compatiblity (#a:Type u#a) (fact: a -> prop) (p:pcm a) (v v0 v1:a) : Lemma (requires stable fact (preorder_of_pcm p) /\ p.refine v0 /\ fact v0 /\ p.refine v1 /\ frame_preserving p v v1 /\ compatible p v v0) (ensures fact v1) = let f : frame_preserving_upd p v v1 = frame_preserving_val_to_fp_upd p v v1 in frame_preserving_upd_is_preorder_preserving p v v1 f v0 (**** Preorder to PCM *) (***** Building the preorder *) (** This predicate tells that the list [l] can represent a trace of elements whose evolution is compatible with the preorder [q]
{ "checked_file": "/", "dependencies": [ "PulseCore.FractionalPermission.fst.checked", "prims.fst.checked", "FStar.Real.fsti.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked", "FStar.List.Tot.fst.checked", "FStar.IndefiniteDescription.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "PulseCore.Preorder.fst" }
[ { "abbrev": false, "full_module": "FStar.Real", "short_module": null }, { "abbrev": false, "full_module": "PulseCore.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "FStar.Preorder", "short_module": null }, { "abbrev": false, "full_module": "FStar.PCM", "short_module": null }, { "abbrev": false, "full_module": "PulseCore", "short_module": null }, { "abbrev": false, "full_module": "PulseCore", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
q: FStar.Preorder.preorder a -> l: Prims.list a -> Prims.logical
Prims.Tot
[ "total" ]
[]
[ "FStar.Preorder.preorder", "Prims.list", "Prims.l_True", "Prims.l_and", "PulseCore.Preorder.qhistory", "Prims.Cons", "Prims.logical" ]
[ "recursion" ]
false
false
false
true
true
let rec qhistory #a (q: preorder a) (l: list a) =
match l with | [] | [_] -> True | x :: y :: tl -> y `q` x /\ qhistory q (y :: tl)
false
PulseCore.Preorder.fst
PulseCore.Preorder.extends_length_eq
val extends_length_eq (#a: Type u#a) (#q: preorder a) (h0 h1: hist q) : Lemma (ensures (extends h0 h1 ==> h0 == h1 \/ L.length h0 > L.length h1)) [SMTPat (extends h0 h1)]
val extends_length_eq (#a: Type u#a) (#q: preorder a) (h0 h1: hist q) : Lemma (ensures (extends h0 h1 ==> h0 == h1 \/ L.length h0 > L.length h1)) [SMTPat (extends h0 h1)]
let rec extends_length_eq (#a: Type u#a) (#q:preorder a) (h0 h1:hist q) : Lemma (ensures (extends h0 h1 ==> h0 == h1 \/ L.length h0 > L.length h1)) [SMTPat (extends h0 h1)] = match h0 with | [] -> () | hd::tl -> extends_length_eq tl h1
{ "file_name": "lib/pulse_core/PulseCore.Preorder.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 39, "end_line": 120, "start_col": 0, "start_line": 115 }
(* 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 PulseCore.Preorder open FStar.PCM open FStar.Preorder open PulseCore.FractionalPermission open FStar.Real /// This module explores the connection between PCM and preorders. More specifically, we show here /// that any PCM induces a preorder relation, characterized by frame-preservation for any updates. /// /// Furthermore, we also consider the reverse relationship where we derive a PCM for any preorder, /// by taking as elements of the PCM the trace of all the states of the element. (**** PCM to preoder *) (** PCM [p] induces the preorder [q] if for any frame preserving update of [x] to [y], the argument and result of the frame preserving update are related by q *) let induces_preorder (#a:Type u#a) (p:pcm a) (q:preorder a) = forall (x y:a) (f:frame_preserving_upd p x y) (v:a). p.refine v ==> compatible p x v ==> q v (f v) (** We can define a canonical preorder from any PCM by taking the quantified conjunction over all the preorders [q] induced by this PCM. *) let preorder_of_pcm (#a:Type u#a) (p:pcm a) : preorder a = fun x y -> forall (q:preorder a). induces_preorder p q ==> q x y let frame_preserving_upd_is_preorder_preserving (#a:Type u#a) (p:pcm a) (x y:a) (f:frame_preserving_upd p x y) (v_old:a{p.refine v_old /\ compatible p x v_old}) : Lemma ((preorder_of_pcm p) v_old (f v_old)) = () (** This canonical preorder enjoys the nice property that it preserves fact stability of any induced preorder *) let stability (#a: Type u#a) (fact:a -> prop) (q:preorder a) (p:pcm a) : Lemma (requires stable fact q /\ induces_preorder p q) (ensures stable fact (preorder_of_pcm p)) = () let stable_compatiblity (#a:Type u#a) (fact: a -> prop) (p:pcm a) (v v0 v1:a) : Lemma (requires stable fact (preorder_of_pcm p) /\ p.refine v0 /\ fact v0 /\ p.refine v1 /\ frame_preserving p v v1 /\ compatible p v v0) (ensures fact v1) = let f : frame_preserving_upd p v v1 = frame_preserving_val_to_fp_upd p v v1 in frame_preserving_upd_is_preorder_preserving p v v1 f v0 (**** Preorder to PCM *) (***** Building the preorder *) (** This predicate tells that the list [l] can represent a trace of elements whose evolution is compatible with the preorder [q] *) let rec qhistory #a (q:preorder a) (l:list a) = match l with | [] | [_] -> True | x::y::tl -> y `q` x /\ qhistory q (y::tl) (** The history of a preorder is the type of all the traces compatible with that preorder *) let hist (#a: Type u#a) (q:preorder a) = l:list a{qhistory q l} (** Two compatible traces can extend each other *) let rec extends' (#a: Type u#a) (#q:preorder a) (h0 h1:hist q) = h0 == h1 \/ (Cons? h0 /\ extends' (Cons?.tl h0) h1) (** This extension relation is transitive *) let rec extends_trans #a (#q:preorder a) (x y z:hist q) : Lemma (x `extends'` y /\ y `extends'` z ==> x `extends'` z) [SMTPat (x `extends'` y); SMTPat (y `extends'` z)] = match x with | [] -> () | _::tl -> extends_trans tl y z (** And it is also reflexive, so extensibility on traces is a preorder on traces *) let extends (#a: Type u#a) (#q:preorder a) : preorder (hist q) = extends' module L = FStar.List.Tot
{ "checked_file": "/", "dependencies": [ "PulseCore.FractionalPermission.fst.checked", "prims.fst.checked", "FStar.Real.fsti.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked", "FStar.List.Tot.fst.checked", "FStar.IndefiniteDescription.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "PulseCore.Preorder.fst" }
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Real", "short_module": null }, { "abbrev": false, "full_module": "PulseCore.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "FStar.Preorder", "short_module": null }, { "abbrev": false, "full_module": "FStar.PCM", "short_module": null }, { "abbrev": false, "full_module": "PulseCore", "short_module": null }, { "abbrev": false, "full_module": "PulseCore", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
h0: PulseCore.Preorder.hist q -> h1: PulseCore.Preorder.hist q -> FStar.Pervasives.Lemma (ensures PulseCore.Preorder.extends h0 h1 ==> h0 == h1 \/ FStar.List.Tot.Base.length h0 > FStar.List.Tot.Base.length h1) [SMTPat (PulseCore.Preorder.extends h0 h1)]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "FStar.Preorder.preorder", "PulseCore.Preorder.hist", "Prims.list", "PulseCore.Preorder.extends_length_eq", "Prims.unit", "Prims.l_True", "Prims.squash", "Prims.l_imp", "PulseCore.Preorder.extends", "Prims.l_or", "Prims.eq2", "Prims.b2t", "Prims.op_GreaterThan", "FStar.List.Tot.Base.length", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat", "Prims.Nil" ]
[ "recursion" ]
false
false
true
false
false
let rec extends_length_eq (#a: Type u#a) (#q: preorder a) (h0 h1: hist q) : Lemma (ensures (extends h0 h1 ==> h0 == h1 \/ L.length h0 > L.length h1)) [SMTPat (extends h0 h1)] =
match h0 with | [] -> () | hd :: tl -> extends_length_eq tl h1
false
PulseCore.Preorder.fst
PulseCore.Preorder.p
val p (#a: Type u#a) (q: preorder a) : pcm' (hist q)
val p (#a: Type u#a) (q: preorder a) : pcm' (hist q)
let p (#a: Type u#a) (q:preorder a) : pcm' (hist q) = { composable = p_composable q; op = p_op q; one = [] }
{ "file_name": "lib/pulse_core/PulseCore.Preorder.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 1, "end_line": 159, "start_col": 0, "start_line": 155 }
(* 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 PulseCore.Preorder open FStar.PCM open FStar.Preorder open PulseCore.FractionalPermission open FStar.Real /// This module explores the connection between PCM and preorders. More specifically, we show here /// that any PCM induces a preorder relation, characterized by frame-preservation for any updates. /// /// Furthermore, we also consider the reverse relationship where we derive a PCM for any preorder, /// by taking as elements of the PCM the trace of all the states of the element. (**** PCM to preoder *) (** PCM [p] induces the preorder [q] if for any frame preserving update of [x] to [y], the argument and result of the frame preserving update are related by q *) let induces_preorder (#a:Type u#a) (p:pcm a) (q:preorder a) = forall (x y:a) (f:frame_preserving_upd p x y) (v:a). p.refine v ==> compatible p x v ==> q v (f v) (** We can define a canonical preorder from any PCM by taking the quantified conjunction over all the preorders [q] induced by this PCM. *) let preorder_of_pcm (#a:Type u#a) (p:pcm a) : preorder a = fun x y -> forall (q:preorder a). induces_preorder p q ==> q x y let frame_preserving_upd_is_preorder_preserving (#a:Type u#a) (p:pcm a) (x y:a) (f:frame_preserving_upd p x y) (v_old:a{p.refine v_old /\ compatible p x v_old}) : Lemma ((preorder_of_pcm p) v_old (f v_old)) = () (** This canonical preorder enjoys the nice property that it preserves fact stability of any induced preorder *) let stability (#a: Type u#a) (fact:a -> prop) (q:preorder a) (p:pcm a) : Lemma (requires stable fact q /\ induces_preorder p q) (ensures stable fact (preorder_of_pcm p)) = () let stable_compatiblity (#a:Type u#a) (fact: a -> prop) (p:pcm a) (v v0 v1:a) : Lemma (requires stable fact (preorder_of_pcm p) /\ p.refine v0 /\ fact v0 /\ p.refine v1 /\ frame_preserving p v v1 /\ compatible p v v0) (ensures fact v1) = let f : frame_preserving_upd p v v1 = frame_preserving_val_to_fp_upd p v v1 in frame_preserving_upd_is_preorder_preserving p v v1 f v0 (**** Preorder to PCM *) (***** Building the preorder *) (** This predicate tells that the list [l] can represent a trace of elements whose evolution is compatible with the preorder [q] *) let rec qhistory #a (q:preorder a) (l:list a) = match l with | [] | [_] -> True | x::y::tl -> y `q` x /\ qhistory q (y::tl) (** The history of a preorder is the type of all the traces compatible with that preorder *) let hist (#a: Type u#a) (q:preorder a) = l:list a{qhistory q l} (** Two compatible traces can extend each other *) let rec extends' (#a: Type u#a) (#q:preorder a) (h0 h1:hist q) = h0 == h1 \/ (Cons? h0 /\ extends' (Cons?.tl h0) h1) (** This extension relation is transitive *) let rec extends_trans #a (#q:preorder a) (x y z:hist q) : Lemma (x `extends'` y /\ y `extends'` z ==> x `extends'` z) [SMTPat (x `extends'` y); SMTPat (y `extends'` z)] = match x with | [] -> () | _::tl -> extends_trans tl y z (** And it is also reflexive, so extensibility on traces is a preorder on traces *) let extends (#a: Type u#a) (#q:preorder a) : preorder (hist q) = extends' module L = FStar.List.Tot (** If [h0] extends by [h1], then the length of [h0] is superior *) let rec extends_length_eq (#a: Type u#a) (#q:preorder a) (h0 h1:hist q) : Lemma (ensures (extends h0 h1 ==> h0 == h1 \/ L.length h0 > L.length h1)) [SMTPat (extends h0 h1)] = match h0 with | [] -> () | hd::tl -> extends_length_eq tl h1 (** We build our relation of composability for traces by reflexing the extension to ensure symmetry *) let p_composable (#a: Type u#a) (q:preorder a) : symrel (hist q) = fun x y -> extends x y \/ extends y x (** The operation for the PCM is to return the full trace of two extensible traces *) let p_op (#a: Type u#a) (q:preorder a) (x:hist q) (y:hist q{p_composable q x y}) : hist q = if L.length x >= L.length y then x else if L.length x = L.length y then (assert (x == y); x) else y (** The operation actually implements extension *) let p_op_extends (#a: Type u#a) (q:preorder a) (x:hist q) (y:hist q{p_composable q x y}) : Lemma (ensures (p_op q x y `extends` x /\ p_op q x y `extends` y /\ (p_op q x y == x \/ p_op q x y == y))) [SMTPat (p_op q x y)] = extends_length_eq x y; extends_length_eq y x (** And the empty trace is the unit element *) let rec p_op_nil (#a: Type u#a) (q:preorder a) (x:hist q) : Lemma (ensures (p_composable q x [] /\ p_op q x [] == x)) [SMTPat (p_composable q x [])] = match x with | [] -> () | _::tl -> p_op_nil q tl
{ "checked_file": "/", "dependencies": [ "PulseCore.FractionalPermission.fst.checked", "prims.fst.checked", "FStar.Real.fsti.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked", "FStar.List.Tot.fst.checked", "FStar.IndefiniteDescription.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "PulseCore.Preorder.fst" }
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Real", "short_module": null }, { "abbrev": false, "full_module": "PulseCore.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "FStar.Preorder", "short_module": null }, { "abbrev": false, "full_module": "FStar.PCM", "short_module": null }, { "abbrev": false, "full_module": "PulseCore", "short_module": null }, { "abbrev": false, "full_module": "PulseCore", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
q: FStar.Preorder.preorder a -> FStar.PCM.pcm' (PulseCore.Preorder.hist q)
Prims.Tot
[ "total" ]
[]
[ "FStar.Preorder.preorder", "FStar.PCM.Mkpcm'", "PulseCore.Preorder.hist", "PulseCore.Preorder.p_composable", "PulseCore.Preorder.p_op", "Prims.Nil", "FStar.PCM.pcm'" ]
[]
false
false
false
false
false
let p (#a: Type u#a) (q: preorder a) : pcm' (hist q) =
{ composable = p_composable q; op = p_op q; one = [] }
false
PulseCore.Preorder.fst
PulseCore.Preorder.p_op
val p_op (#a: Type u#a) (q: preorder a) (x: hist q) (y: hist q {p_composable q x y}) : hist q
val p_op (#a: Type u#a) (q: preorder a) (x: hist q) (y: hist q {p_composable q x y}) : hist q
let p_op (#a: Type u#a) (q:preorder a) (x:hist q) (y:hist q{p_composable q x y}) : hist q = if L.length x >= L.length y then x else if L.length x = L.length y then (assert (x == y); x) else y
{ "file_name": "lib/pulse_core/PulseCore.Preorder.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 8, "end_line": 135, "start_col": 0, "start_line": 130 }
(* 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 PulseCore.Preorder open FStar.PCM open FStar.Preorder open PulseCore.FractionalPermission open FStar.Real /// This module explores the connection between PCM and preorders. More specifically, we show here /// that any PCM induces a preorder relation, characterized by frame-preservation for any updates. /// /// Furthermore, we also consider the reverse relationship where we derive a PCM for any preorder, /// by taking as elements of the PCM the trace of all the states of the element. (**** PCM to preoder *) (** PCM [p] induces the preorder [q] if for any frame preserving update of [x] to [y], the argument and result of the frame preserving update are related by q *) let induces_preorder (#a:Type u#a) (p:pcm a) (q:preorder a) = forall (x y:a) (f:frame_preserving_upd p x y) (v:a). p.refine v ==> compatible p x v ==> q v (f v) (** We can define a canonical preorder from any PCM by taking the quantified conjunction over all the preorders [q] induced by this PCM. *) let preorder_of_pcm (#a:Type u#a) (p:pcm a) : preorder a = fun x y -> forall (q:preorder a). induces_preorder p q ==> q x y let frame_preserving_upd_is_preorder_preserving (#a:Type u#a) (p:pcm a) (x y:a) (f:frame_preserving_upd p x y) (v_old:a{p.refine v_old /\ compatible p x v_old}) : Lemma ((preorder_of_pcm p) v_old (f v_old)) = () (** This canonical preorder enjoys the nice property that it preserves fact stability of any induced preorder *) let stability (#a: Type u#a) (fact:a -> prop) (q:preorder a) (p:pcm a) : Lemma (requires stable fact q /\ induces_preorder p q) (ensures stable fact (preorder_of_pcm p)) = () let stable_compatiblity (#a:Type u#a) (fact: a -> prop) (p:pcm a) (v v0 v1:a) : Lemma (requires stable fact (preorder_of_pcm p) /\ p.refine v0 /\ fact v0 /\ p.refine v1 /\ frame_preserving p v v1 /\ compatible p v v0) (ensures fact v1) = let f : frame_preserving_upd p v v1 = frame_preserving_val_to_fp_upd p v v1 in frame_preserving_upd_is_preorder_preserving p v v1 f v0 (**** Preorder to PCM *) (***** Building the preorder *) (** This predicate tells that the list [l] can represent a trace of elements whose evolution is compatible with the preorder [q] *) let rec qhistory #a (q:preorder a) (l:list a) = match l with | [] | [_] -> True | x::y::tl -> y `q` x /\ qhistory q (y::tl) (** The history of a preorder is the type of all the traces compatible with that preorder *) let hist (#a: Type u#a) (q:preorder a) = l:list a{qhistory q l} (** Two compatible traces can extend each other *) let rec extends' (#a: Type u#a) (#q:preorder a) (h0 h1:hist q) = h0 == h1 \/ (Cons? h0 /\ extends' (Cons?.tl h0) h1) (** This extension relation is transitive *) let rec extends_trans #a (#q:preorder a) (x y z:hist q) : Lemma (x `extends'` y /\ y `extends'` z ==> x `extends'` z) [SMTPat (x `extends'` y); SMTPat (y `extends'` z)] = match x with | [] -> () | _::tl -> extends_trans tl y z (** And it is also reflexive, so extensibility on traces is a preorder on traces *) let extends (#a: Type u#a) (#q:preorder a) : preorder (hist q) = extends' module L = FStar.List.Tot (** If [h0] extends by [h1], then the length of [h0] is superior *) let rec extends_length_eq (#a: Type u#a) (#q:preorder a) (h0 h1:hist q) : Lemma (ensures (extends h0 h1 ==> h0 == h1 \/ L.length h0 > L.length h1)) [SMTPat (extends h0 h1)] = match h0 with | [] -> () | hd::tl -> extends_length_eq tl h1 (** We build our relation of composability for traces by reflexing the extension to ensure symmetry *) let p_composable (#a: Type u#a) (q:preorder a) : symrel (hist q) = fun x y -> extends x y \/ extends y x
{ "checked_file": "/", "dependencies": [ "PulseCore.FractionalPermission.fst.checked", "prims.fst.checked", "FStar.Real.fsti.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked", "FStar.List.Tot.fst.checked", "FStar.IndefiniteDescription.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "PulseCore.Preorder.fst" }
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Real", "short_module": null }, { "abbrev": false, "full_module": "PulseCore.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "FStar.Preorder", "short_module": null }, { "abbrev": false, "full_module": "FStar.PCM", "short_module": null }, { "abbrev": false, "full_module": "PulseCore", "short_module": null }, { "abbrev": false, "full_module": "PulseCore", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
q: FStar.Preorder.preorder a -> x: PulseCore.Preorder.hist q -> y: PulseCore.Preorder.hist q {PulseCore.Preorder.p_composable q x y} -> PulseCore.Preorder.hist q
Prims.Tot
[ "total" ]
[]
[ "FStar.Preorder.preorder", "PulseCore.Preorder.hist", "PulseCore.Preorder.p_composable", "Prims.op_GreaterThanOrEqual", "FStar.List.Tot.Base.length", "Prims.bool", "Prims.op_Equality", "Prims.nat", "Prims.unit", "Prims._assert", "Prims.eq2" ]
[]
false
false
false
false
false
let p_op (#a: Type u#a) (q: preorder a) (x: hist q) (y: hist q {p_composable q x y}) : hist q =
if L.length x >= L.length y then x else if L.length x = L.length y then (assert (x == y); x) else y
false
PulseCore.Preorder.fst
PulseCore.Preorder.p_op_nil
val p_op_nil (#a: Type u#a) (q: preorder a) (x: hist q) : Lemma (ensures (p_composable q x [] /\ p_op q x [] == x)) [SMTPat (p_composable q x [])]
val p_op_nil (#a: Type u#a) (q: preorder a) (x: hist q) : Lemma (ensures (p_composable q x [] /\ p_op q x [] == x)) [SMTPat (p_composable q x [])]
let rec p_op_nil (#a: Type u#a) (q:preorder a) (x:hist q) : Lemma (ensures (p_composable q x [] /\ p_op q x [] == x)) [SMTPat (p_composable q x [])] = match x with | [] -> () | _::tl -> p_op_nil q tl
{ "file_name": "lib/pulse_core/PulseCore.Preorder.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 28, "end_line": 152, "start_col": 0, "start_line": 147 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module PulseCore.Preorder open FStar.PCM open FStar.Preorder open PulseCore.FractionalPermission open FStar.Real /// This module explores the connection between PCM and preorders. More specifically, we show here /// that any PCM induces a preorder relation, characterized by frame-preservation for any updates. /// /// Furthermore, we also consider the reverse relationship where we derive a PCM for any preorder, /// by taking as elements of the PCM the trace of all the states of the element. (**** PCM to preoder *) (** PCM [p] induces the preorder [q] if for any frame preserving update of [x] to [y], the argument and result of the frame preserving update are related by q *) let induces_preorder (#a:Type u#a) (p:pcm a) (q:preorder a) = forall (x y:a) (f:frame_preserving_upd p x y) (v:a). p.refine v ==> compatible p x v ==> q v (f v) (** We can define a canonical preorder from any PCM by taking the quantified conjunction over all the preorders [q] induced by this PCM. *) let preorder_of_pcm (#a:Type u#a) (p:pcm a) : preorder a = fun x y -> forall (q:preorder a). induces_preorder p q ==> q x y let frame_preserving_upd_is_preorder_preserving (#a:Type u#a) (p:pcm a) (x y:a) (f:frame_preserving_upd p x y) (v_old:a{p.refine v_old /\ compatible p x v_old}) : Lemma ((preorder_of_pcm p) v_old (f v_old)) = () (** This canonical preorder enjoys the nice property that it preserves fact stability of any induced preorder *) let stability (#a: Type u#a) (fact:a -> prop) (q:preorder a) (p:pcm a) : Lemma (requires stable fact q /\ induces_preorder p q) (ensures stable fact (preorder_of_pcm p)) = () let stable_compatiblity (#a:Type u#a) (fact: a -> prop) (p:pcm a) (v v0 v1:a) : Lemma (requires stable fact (preorder_of_pcm p) /\ p.refine v0 /\ fact v0 /\ p.refine v1 /\ frame_preserving p v v1 /\ compatible p v v0) (ensures fact v1) = let f : frame_preserving_upd p v v1 = frame_preserving_val_to_fp_upd p v v1 in frame_preserving_upd_is_preorder_preserving p v v1 f v0 (**** Preorder to PCM *) (***** Building the preorder *) (** This predicate tells that the list [l] can represent a trace of elements whose evolution is compatible with the preorder [q] *) let rec qhistory #a (q:preorder a) (l:list a) = match l with | [] | [_] -> True | x::y::tl -> y `q` x /\ qhistory q (y::tl) (** The history of a preorder is the type of all the traces compatible with that preorder *) let hist (#a: Type u#a) (q:preorder a) = l:list a{qhistory q l} (** Two compatible traces can extend each other *) let rec extends' (#a: Type u#a) (#q:preorder a) (h0 h1:hist q) = h0 == h1 \/ (Cons? h0 /\ extends' (Cons?.tl h0) h1) (** This extension relation is transitive *) let rec extends_trans #a (#q:preorder a) (x y z:hist q) : Lemma (x `extends'` y /\ y `extends'` z ==> x `extends'` z) [SMTPat (x `extends'` y); SMTPat (y `extends'` z)] = match x with | [] -> () | _::tl -> extends_trans tl y z (** And it is also reflexive, so extensibility on traces is a preorder on traces *) let extends (#a: Type u#a) (#q:preorder a) : preorder (hist q) = extends' module L = FStar.List.Tot (** If [h0] extends by [h1], then the length of [h0] is superior *) let rec extends_length_eq (#a: Type u#a) (#q:preorder a) (h0 h1:hist q) : Lemma (ensures (extends h0 h1 ==> h0 == h1 \/ L.length h0 > L.length h1)) [SMTPat (extends h0 h1)] = match h0 with | [] -> () | hd::tl -> extends_length_eq tl h1 (** We build our relation of composability for traces by reflexing the extension to ensure symmetry *) let p_composable (#a: Type u#a) (q:preorder a) : symrel (hist q) = fun x y -> extends x y \/ extends y x (** The operation for the PCM is to return the full trace of two extensible traces *) let p_op (#a: Type u#a) (q:preorder a) (x:hist q) (y:hist q{p_composable q x y}) : hist q = if L.length x >= L.length y then x else if L.length x = L.length y then (assert (x == y); x) else y (** The operation actually implements extension *) let p_op_extends (#a: Type u#a) (q:preorder a) (x:hist q) (y:hist q{p_composable q x y}) : Lemma (ensures (p_op q x y `extends` x /\ p_op q x y `extends` y /\ (p_op q x y == x \/ p_op q x y == y))) [SMTPat (p_op q x y)] = extends_length_eq x y; extends_length_eq y x
{ "checked_file": "/", "dependencies": [ "PulseCore.FractionalPermission.fst.checked", "prims.fst.checked", "FStar.Real.fsti.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked", "FStar.List.Tot.fst.checked", "FStar.IndefiniteDescription.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "PulseCore.Preorder.fst" }
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Real", "short_module": null }, { "abbrev": false, "full_module": "PulseCore.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "FStar.Preorder", "short_module": null }, { "abbrev": false, "full_module": "FStar.PCM", "short_module": null }, { "abbrev": false, "full_module": "PulseCore", "short_module": null }, { "abbrev": false, "full_module": "PulseCore", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
q: FStar.Preorder.preorder a -> x: PulseCore.Preorder.hist q -> FStar.Pervasives.Lemma (ensures PulseCore.Preorder.p_composable q x [] /\ PulseCore.Preorder.p_op q x [] == x) [SMTPat (PulseCore.Preorder.p_composable q x [])]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "FStar.Preorder.preorder", "PulseCore.Preorder.hist", "Prims.list", "PulseCore.Preorder.p_op_nil", "Prims.unit", "Prims.l_True", "Prims.squash", "Prims.l_and", "PulseCore.Preorder.p_composable", "Prims.Nil", "Prims.eq2", "PulseCore.Preorder.p_op", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat", "Prims.prop" ]
[ "recursion" ]
false
false
true
false
false
let rec p_op_nil (#a: Type u#a) (q: preorder a) (x: hist q) : Lemma (ensures (p_composable q x [] /\ p_op q x [] == x)) [SMTPat (p_composable q x [])] =
match x with | [] -> () | _ :: tl -> p_op_nil q tl
false
PulseCore.Preorder.fst
PulseCore.Preorder.stable_property
val stable_property : pcm: FStar.PCM.pcm a -> Type
let stable_property (#a:Type) (pcm:pcm a) = fact:property a { FStar.Preorder.stable fact (preorder_of_pcm pcm) }
{ "file_name": "lib/pulse_core/PulseCore.Preorder.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 5, "end_line": 272, "start_col": 0, "start_line": 269 }
(* 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 PulseCore.Preorder open FStar.PCM open FStar.Preorder open PulseCore.FractionalPermission open FStar.Real /// This module explores the connection between PCM and preorders. More specifically, we show here /// that any PCM induces a preorder relation, characterized by frame-preservation for any updates. /// /// Furthermore, we also consider the reverse relationship where we derive a PCM for any preorder, /// by taking as elements of the PCM the trace of all the states of the element. (**** PCM to preoder *) (** PCM [p] induces the preorder [q] if for any frame preserving update of [x] to [y], the argument and result of the frame preserving update are related by q *) let induces_preorder (#a:Type u#a) (p:pcm a) (q:preorder a) = forall (x y:a) (f:frame_preserving_upd p x y) (v:a). p.refine v ==> compatible p x v ==> q v (f v) (** We can define a canonical preorder from any PCM by taking the quantified conjunction over all the preorders [q] induced by this PCM. *) let preorder_of_pcm (#a:Type u#a) (p:pcm a) : preorder a = fun x y -> forall (q:preorder a). induces_preorder p q ==> q x y let frame_preserving_upd_is_preorder_preserving (#a:Type u#a) (p:pcm a) (x y:a) (f:frame_preserving_upd p x y) (v_old:a{p.refine v_old /\ compatible p x v_old}) : Lemma ((preorder_of_pcm p) v_old (f v_old)) = () (** This canonical preorder enjoys the nice property that it preserves fact stability of any induced preorder *) let stability (#a: Type u#a) (fact:a -> prop) (q:preorder a) (p:pcm a) : Lemma (requires stable fact q /\ induces_preorder p q) (ensures stable fact (preorder_of_pcm p)) = () let stable_compatiblity (#a:Type u#a) (fact: a -> prop) (p:pcm a) (v v0 v1:a) : Lemma (requires stable fact (preorder_of_pcm p) /\ p.refine v0 /\ fact v0 /\ p.refine v1 /\ frame_preserving p v v1 /\ compatible p v v0) (ensures fact v1) = let f : frame_preserving_upd p v v1 = frame_preserving_val_to_fp_upd p v v1 in frame_preserving_upd_is_preorder_preserving p v v1 f v0 (**** Preorder to PCM *) (***** Building the preorder *) (** This predicate tells that the list [l] can represent a trace of elements whose evolution is compatible with the preorder [q] *) let rec qhistory #a (q:preorder a) (l:list a) = match l with | [] | [_] -> True | x::y::tl -> y `q` x /\ qhistory q (y::tl) (** The history of a preorder is the type of all the traces compatible with that preorder *) let hist (#a: Type u#a) (q:preorder a) = l:list a{qhistory q l} (** Two compatible traces can extend each other *) let rec extends' (#a: Type u#a) (#q:preorder a) (h0 h1:hist q) = h0 == h1 \/ (Cons? h0 /\ extends' (Cons?.tl h0) h1) (** This extension relation is transitive *) let rec extends_trans #a (#q:preorder a) (x y z:hist q) : Lemma (x `extends'` y /\ y `extends'` z ==> x `extends'` z) [SMTPat (x `extends'` y); SMTPat (y `extends'` z)] = match x with | [] -> () | _::tl -> extends_trans tl y z (** And it is also reflexive, so extensibility on traces is a preorder on traces *) let extends (#a: Type u#a) (#q:preorder a) : preorder (hist q) = extends' module L = FStar.List.Tot (** If [h0] extends by [h1], then the length of [h0] is superior *) let rec extends_length_eq (#a: Type u#a) (#q:preorder a) (h0 h1:hist q) : Lemma (ensures (extends h0 h1 ==> h0 == h1 \/ L.length h0 > L.length h1)) [SMTPat (extends h0 h1)] = match h0 with | [] -> () | hd::tl -> extends_length_eq tl h1 (** We build our relation of composability for traces by reflexing the extension to ensure symmetry *) let p_composable (#a: Type u#a) (q:preorder a) : symrel (hist q) = fun x y -> extends x y \/ extends y x (** The operation for the PCM is to return the full trace of two extensible traces *) let p_op (#a: Type u#a) (q:preorder a) (x:hist q) (y:hist q{p_composable q x y}) : hist q = if L.length x >= L.length y then x else if L.length x = L.length y then (assert (x == y); x) else y (** The operation actually implements extension *) let p_op_extends (#a: Type u#a) (q:preorder a) (x:hist q) (y:hist q{p_composable q x y}) : Lemma (ensures (p_op q x y `extends` x /\ p_op q x y `extends` y /\ (p_op q x y == x \/ p_op q x y == y))) [SMTPat (p_op q x y)] = extends_length_eq x y; extends_length_eq y x (** And the empty trace is the unit element *) let rec p_op_nil (#a: Type u#a) (q:preorder a) (x:hist q) : Lemma (ensures (p_composable q x [] /\ p_op q x [] == x)) [SMTPat (p_composable q x [])] = match x with | [] -> () | _::tl -> p_op_nil q tl (** We can finally define our PCM with these operations *) let p (#a: Type u#a) (q:preorder a) : pcm' (hist q) = { composable = p_composable q; op = p_op q; one = [] } (** Composability is commutative *) let comm (#a: Type u#a) (q:preorder a) (x y:hist q) : Lemma (requires p_composable q x y) (ensures p_composable q y x) = () (** As well as the compose operation *) let comm_op (#a: Type u#a) (q:preorder a) (x:hist q) (y:hist q{p_composable q x y}) : Lemma (p_op q x y == p_op q y x) = extends_length_eq x y; extends_length_eq y x (** If [z] extends [x] and [y], then [x] and [y] are extending one or another *) let rec extends_disjunction (#a: Type u#a) (#q:preorder a) (x y z:hist q) : Lemma (z `extends` x /\ z `extends` y ==> x `extends` y \/ y `extends` x) [SMTPat (z `extends` x); SMTPat (z `extends` y)] = match z with | [] -> () | _::tl -> extends_disjunction x y tl (** If [x] extends [y], then the two heads of the traces are still related by the preorder *) let rec extends_related_head (#a: Type u#a) (#q:preorder a) (x y:hist q) : Lemma (ensures x `extends` y /\ Cons? x /\ Cons? y ==> Cons?.hd y `q` Cons?.hd x) [SMTPat (x `extends` y)] = match x with | [] -> () | _::tl -> extends_related_head tl y (** Finally, we can have our fully-fledged PCM from the preorder *) let pcm_of_preorder (#a: Type u#a) (q:preorder a) : pcm (hist q) = { p = p q; comm = comm_op q; assoc = (fun _ _ _ -> ()); assoc_r = (fun _ _ _ -> ()); is_unit = (fun _ -> ()); refine = (fun _ -> True) } (***** Using the preorder *) (** We check that the preorder derived from the PCM derived from the preorder satisfies the same properties as the original preorder. Here, we get back history extension from frame-preserving updates. *) let frame_preserving_q_aux (#a : Type u#a) (q:preorder a) (x y:hist q) (z:hist q) : Lemma (requires (frame_preserving (pcm_of_preorder q) x y /\ compatible (pcm_of_preorder q) x z)) (ensures (y `extends` z)) = () (** A non-empty history *) let vhist (#a: Type u#a) (q:preorder a) = h:hist q{Cons? h} (** Get the current value from an history *) let curval (#a: Type u#a) (#q:preorder a) (v:vhist q) = Cons?.hd v (** Given a frame-preserving update from [x] to [y] for any value of resource [z] (compatible with [x]) the new value [y] advances the history [z] in a preorder respecting manner *) let frame_preserving_q (#a: Type u#a) (q:preorder a) (x y:vhist q) : Lemma (requires frame_preserving (pcm_of_preorder q) x y) (ensures (forall (z:hist q). compatible (pcm_of_preorder q) x z ==> curval z `q` curval y)) = () (** Still given a frame-preserving update from [x] to [y], this update extends the history *) let frame_preserving_extends (#a: Type u#a) (q:preorder a) (x y:vhist q) : Lemma (requires frame_preserving (pcm_of_preorder q) x y) (ensures (forall (z:hist q). compatible (pcm_of_preorder q) x z ==> y `extends` z)) = () (** Helper function that flips a preoder *) let flip (#a: Type u#a) (p:preorder a) : preorder a = fun x y -> p y x (** What is the preorder induced from the PCM induced by preorder [q]? It turns out that it is the flipped of [q], reversed extension. *) let frame_preserving_extends2 (#a: Type u#a) (q:preorder a) (x y:hist q) : Lemma (requires frame_preserving (pcm_of_preorder q) x y) (ensures (forall (z:hist q). compatible (pcm_of_preorder q) x z ==> z `flip extends` y)) [SMTPat (frame_preserving (pcm_of_preorder q) x y)] = () #push-options "--warn_error -271" let pcm_of_preorder_induces_extends (#a: Type u#a) (q:preorder a) : Lemma (induces_preorder (pcm_of_preorder q) (flip extends)) = let fp_full (x y:hist q) (f:frame_preserving_upd (pcm_of_preorder q) x y) (v:hist q) : Lemma (requires compatible (pcm_of_preorder q) x v) (ensures extends (f v) v) [SMTPat ()] = assert (composable (pcm_of_preorder q) x v) in () #pop-options let extend_history (#a:Type u#a) (#q:preorder a) (h0:vhist q) (v:a{q (curval h0) v}) : h1:vhist q{h1 `extends` h0} = v :: h0 let property (a:Type) = a -> prop
{ "checked_file": "/", "dependencies": [ "PulseCore.FractionalPermission.fst.checked", "prims.fst.checked", "FStar.Real.fsti.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked", "FStar.List.Tot.fst.checked", "FStar.IndefiniteDescription.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "PulseCore.Preorder.fst" }
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Real", "short_module": null }, { "abbrev": false, "full_module": "PulseCore.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "FStar.Preorder", "short_module": null }, { "abbrev": false, "full_module": "FStar.PCM", "short_module": null }, { "abbrev": false, "full_module": "PulseCore", "short_module": null }, { "abbrev": false, "full_module": "PulseCore", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
pcm: FStar.PCM.pcm a -> Type
Prims.Tot
[ "total" ]
[]
[ "FStar.PCM.pcm", "PulseCore.Preorder.property", "FStar.Preorder.stable", "PulseCore.Preorder.preorder_of_pcm" ]
[]
false
false
false
true
true
let stable_property (#a: Type) (pcm: pcm a) =
fact: property a {FStar.Preorder.stable fact (preorder_of_pcm pcm)}
false
PulseCore.Preorder.fst
PulseCore.Preorder.extends_related_head
val extends_related_head (#a: Type u#a) (#q: preorder a) (x y: hist q) : Lemma (ensures x `extends` y /\ Cons? x /\ Cons? y ==> (Cons?.hd y) `q` (Cons?.hd x)) [SMTPat (x `extends` y)]
val extends_related_head (#a: Type u#a) (#q: preorder a) (x y: hist q) : Lemma (ensures x `extends` y /\ Cons? x /\ Cons? y ==> (Cons?.hd y) `q` (Cons?.hd x)) [SMTPat (x `extends` y)]
let rec extends_related_head (#a: Type u#a) (#q:preorder a) (x y:hist q) : Lemma (ensures x `extends` y /\ Cons? x /\ Cons? y ==> Cons?.hd y `q` Cons?.hd x) [SMTPat (x `extends` y)] = match x with | [] -> () | _::tl -> extends_related_head tl y
{ "file_name": "lib/pulse_core/PulseCore.Preorder.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 40, "end_line": 192, "start_col": 0, "start_line": 183 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module PulseCore.Preorder open FStar.PCM open FStar.Preorder open PulseCore.FractionalPermission open FStar.Real /// This module explores the connection between PCM and preorders. More specifically, we show here /// that any PCM induces a preorder relation, characterized by frame-preservation for any updates. /// /// Furthermore, we also consider the reverse relationship where we derive a PCM for any preorder, /// by taking as elements of the PCM the trace of all the states of the element. (**** PCM to preoder *) (** PCM [p] induces the preorder [q] if for any frame preserving update of [x] to [y], the argument and result of the frame preserving update are related by q *) let induces_preorder (#a:Type u#a) (p:pcm a) (q:preorder a) = forall (x y:a) (f:frame_preserving_upd p x y) (v:a). p.refine v ==> compatible p x v ==> q v (f v) (** We can define a canonical preorder from any PCM by taking the quantified conjunction over all the preorders [q] induced by this PCM. *) let preorder_of_pcm (#a:Type u#a) (p:pcm a) : preorder a = fun x y -> forall (q:preorder a). induces_preorder p q ==> q x y let frame_preserving_upd_is_preorder_preserving (#a:Type u#a) (p:pcm a) (x y:a) (f:frame_preserving_upd p x y) (v_old:a{p.refine v_old /\ compatible p x v_old}) : Lemma ((preorder_of_pcm p) v_old (f v_old)) = () (** This canonical preorder enjoys the nice property that it preserves fact stability of any induced preorder *) let stability (#a: Type u#a) (fact:a -> prop) (q:preorder a) (p:pcm a) : Lemma (requires stable fact q /\ induces_preorder p q) (ensures stable fact (preorder_of_pcm p)) = () let stable_compatiblity (#a:Type u#a) (fact: a -> prop) (p:pcm a) (v v0 v1:a) : Lemma (requires stable fact (preorder_of_pcm p) /\ p.refine v0 /\ fact v0 /\ p.refine v1 /\ frame_preserving p v v1 /\ compatible p v v0) (ensures fact v1) = let f : frame_preserving_upd p v v1 = frame_preserving_val_to_fp_upd p v v1 in frame_preserving_upd_is_preorder_preserving p v v1 f v0 (**** Preorder to PCM *) (***** Building the preorder *) (** This predicate tells that the list [l] can represent a trace of elements whose evolution is compatible with the preorder [q] *) let rec qhistory #a (q:preorder a) (l:list a) = match l with | [] | [_] -> True | x::y::tl -> y `q` x /\ qhistory q (y::tl) (** The history of a preorder is the type of all the traces compatible with that preorder *) let hist (#a: Type u#a) (q:preorder a) = l:list a{qhistory q l} (** Two compatible traces can extend each other *) let rec extends' (#a: Type u#a) (#q:preorder a) (h0 h1:hist q) = h0 == h1 \/ (Cons? h0 /\ extends' (Cons?.tl h0) h1) (** This extension relation is transitive *) let rec extends_trans #a (#q:preorder a) (x y z:hist q) : Lemma (x `extends'` y /\ y `extends'` z ==> x `extends'` z) [SMTPat (x `extends'` y); SMTPat (y `extends'` z)] = match x with | [] -> () | _::tl -> extends_trans tl y z (** And it is also reflexive, so extensibility on traces is a preorder on traces *) let extends (#a: Type u#a) (#q:preorder a) : preorder (hist q) = extends' module L = FStar.List.Tot (** If [h0] extends by [h1], then the length of [h0] is superior *) let rec extends_length_eq (#a: Type u#a) (#q:preorder a) (h0 h1:hist q) : Lemma (ensures (extends h0 h1 ==> h0 == h1 \/ L.length h0 > L.length h1)) [SMTPat (extends h0 h1)] = match h0 with | [] -> () | hd::tl -> extends_length_eq tl h1 (** We build our relation of composability for traces by reflexing the extension to ensure symmetry *) let p_composable (#a: Type u#a) (q:preorder a) : symrel (hist q) = fun x y -> extends x y \/ extends y x (** The operation for the PCM is to return the full trace of two extensible traces *) let p_op (#a: Type u#a) (q:preorder a) (x:hist q) (y:hist q{p_composable q x y}) : hist q = if L.length x >= L.length y then x else if L.length x = L.length y then (assert (x == y); x) else y (** The operation actually implements extension *) let p_op_extends (#a: Type u#a) (q:preorder a) (x:hist q) (y:hist q{p_composable q x y}) : Lemma (ensures (p_op q x y `extends` x /\ p_op q x y `extends` y /\ (p_op q x y == x \/ p_op q x y == y))) [SMTPat (p_op q x y)] = extends_length_eq x y; extends_length_eq y x (** And the empty trace is the unit element *) let rec p_op_nil (#a: Type u#a) (q:preorder a) (x:hist q) : Lemma (ensures (p_composable q x [] /\ p_op q x [] == x)) [SMTPat (p_composable q x [])] = match x with | [] -> () | _::tl -> p_op_nil q tl (** We can finally define our PCM with these operations *) let p (#a: Type u#a) (q:preorder a) : pcm' (hist q) = { composable = p_composable q; op = p_op q; one = [] } (** Composability is commutative *) let comm (#a: Type u#a) (q:preorder a) (x y:hist q) : Lemma (requires p_composable q x y) (ensures p_composable q y x) = () (** As well as the compose operation *) let comm_op (#a: Type u#a) (q:preorder a) (x:hist q) (y:hist q{p_composable q x y}) : Lemma (p_op q x y == p_op q y x) = extends_length_eq x y; extends_length_eq y x (** If [z] extends [x] and [y], then [x] and [y] are extending one or another *) let rec extends_disjunction (#a: Type u#a) (#q:preorder a) (x y z:hist q) : Lemma (z `extends` x /\ z `extends` y ==> x `extends` y \/ y `extends` x) [SMTPat (z `extends` x); SMTPat (z `extends` y)] = match z with | [] -> () | _::tl -> extends_disjunction x y tl
{ "checked_file": "/", "dependencies": [ "PulseCore.FractionalPermission.fst.checked", "prims.fst.checked", "FStar.Real.fsti.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked", "FStar.List.Tot.fst.checked", "FStar.IndefiniteDescription.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "PulseCore.Preorder.fst" }
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Real", "short_module": null }, { "abbrev": false, "full_module": "PulseCore.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "FStar.Preorder", "short_module": null }, { "abbrev": false, "full_module": "FStar.PCM", "short_module": null }, { "abbrev": false, "full_module": "PulseCore", "short_module": null }, { "abbrev": false, "full_module": "PulseCore", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: PulseCore.Preorder.hist q -> y: PulseCore.Preorder.hist q -> FStar.Pervasives.Lemma (ensures PulseCore.Preorder.extends x y /\ Cons? x /\ Cons? y ==> q (Cons?.hd y) (Cons?.hd x)) [SMTPat (PulseCore.Preorder.extends x y)]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "FStar.Preorder.preorder", "PulseCore.Preorder.hist", "Prims.list", "PulseCore.Preorder.extends_related_head", "Prims.unit", "Prims.l_True", "Prims.squash", "Prims.l_imp", "Prims.l_and", "PulseCore.Preorder.extends", "Prims.b2t", "Prims.uu___is_Cons", "Prims.__proj__Cons__item__hd", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat", "Prims.Nil" ]
[ "recursion" ]
false
false
true
false
false
let rec extends_related_head (#a: Type u#a) (#q: preorder a) (x y: hist q) : Lemma (ensures x `extends` y /\ Cons? x /\ Cons? y ==> (Cons?.hd y) `q` (Cons?.hd x)) [SMTPat (x `extends` y)] =
match x with | [] -> () | _ :: tl -> extends_related_head tl y
false
PulseCore.Preorder.fst
PulseCore.Preorder.property
val property : a: Type -> Type
let property (a:Type) = a -> prop
{ "file_name": "lib/pulse_core/PulseCore.Preorder.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 13, "end_line": 267, "start_col": 0, "start_line": 266 }
(* 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 PulseCore.Preorder open FStar.PCM open FStar.Preorder open PulseCore.FractionalPermission open FStar.Real /// This module explores the connection between PCM and preorders. More specifically, we show here /// that any PCM induces a preorder relation, characterized by frame-preservation for any updates. /// /// Furthermore, we also consider the reverse relationship where we derive a PCM for any preorder, /// by taking as elements of the PCM the trace of all the states of the element. (**** PCM to preoder *) (** PCM [p] induces the preorder [q] if for any frame preserving update of [x] to [y], the argument and result of the frame preserving update are related by q *) let induces_preorder (#a:Type u#a) (p:pcm a) (q:preorder a) = forall (x y:a) (f:frame_preserving_upd p x y) (v:a). p.refine v ==> compatible p x v ==> q v (f v) (** We can define a canonical preorder from any PCM by taking the quantified conjunction over all the preorders [q] induced by this PCM. *) let preorder_of_pcm (#a:Type u#a) (p:pcm a) : preorder a = fun x y -> forall (q:preorder a). induces_preorder p q ==> q x y let frame_preserving_upd_is_preorder_preserving (#a:Type u#a) (p:pcm a) (x y:a) (f:frame_preserving_upd p x y) (v_old:a{p.refine v_old /\ compatible p x v_old}) : Lemma ((preorder_of_pcm p) v_old (f v_old)) = () (** This canonical preorder enjoys the nice property that it preserves fact stability of any induced preorder *) let stability (#a: Type u#a) (fact:a -> prop) (q:preorder a) (p:pcm a) : Lemma (requires stable fact q /\ induces_preorder p q) (ensures stable fact (preorder_of_pcm p)) = () let stable_compatiblity (#a:Type u#a) (fact: a -> prop) (p:pcm a) (v v0 v1:a) : Lemma (requires stable fact (preorder_of_pcm p) /\ p.refine v0 /\ fact v0 /\ p.refine v1 /\ frame_preserving p v v1 /\ compatible p v v0) (ensures fact v1) = let f : frame_preserving_upd p v v1 = frame_preserving_val_to_fp_upd p v v1 in frame_preserving_upd_is_preorder_preserving p v v1 f v0 (**** Preorder to PCM *) (***** Building the preorder *) (** This predicate tells that the list [l] can represent a trace of elements whose evolution is compatible with the preorder [q] *) let rec qhistory #a (q:preorder a) (l:list a) = match l with | [] | [_] -> True | x::y::tl -> y `q` x /\ qhistory q (y::tl) (** The history of a preorder is the type of all the traces compatible with that preorder *) let hist (#a: Type u#a) (q:preorder a) = l:list a{qhistory q l} (** Two compatible traces can extend each other *) let rec extends' (#a: Type u#a) (#q:preorder a) (h0 h1:hist q) = h0 == h1 \/ (Cons? h0 /\ extends' (Cons?.tl h0) h1) (** This extension relation is transitive *) let rec extends_trans #a (#q:preorder a) (x y z:hist q) : Lemma (x `extends'` y /\ y `extends'` z ==> x `extends'` z) [SMTPat (x `extends'` y); SMTPat (y `extends'` z)] = match x with | [] -> () | _::tl -> extends_trans tl y z (** And it is also reflexive, so extensibility on traces is a preorder on traces *) let extends (#a: Type u#a) (#q:preorder a) : preorder (hist q) = extends' module L = FStar.List.Tot (** If [h0] extends by [h1], then the length of [h0] is superior *) let rec extends_length_eq (#a: Type u#a) (#q:preorder a) (h0 h1:hist q) : Lemma (ensures (extends h0 h1 ==> h0 == h1 \/ L.length h0 > L.length h1)) [SMTPat (extends h0 h1)] = match h0 with | [] -> () | hd::tl -> extends_length_eq tl h1 (** We build our relation of composability for traces by reflexing the extension to ensure symmetry *) let p_composable (#a: Type u#a) (q:preorder a) : symrel (hist q) = fun x y -> extends x y \/ extends y x (** The operation for the PCM is to return the full trace of two extensible traces *) let p_op (#a: Type u#a) (q:preorder a) (x:hist q) (y:hist q{p_composable q x y}) : hist q = if L.length x >= L.length y then x else if L.length x = L.length y then (assert (x == y); x) else y (** The operation actually implements extension *) let p_op_extends (#a: Type u#a) (q:preorder a) (x:hist q) (y:hist q{p_composable q x y}) : Lemma (ensures (p_op q x y `extends` x /\ p_op q x y `extends` y /\ (p_op q x y == x \/ p_op q x y == y))) [SMTPat (p_op q x y)] = extends_length_eq x y; extends_length_eq y x (** And the empty trace is the unit element *) let rec p_op_nil (#a: Type u#a) (q:preorder a) (x:hist q) : Lemma (ensures (p_composable q x [] /\ p_op q x [] == x)) [SMTPat (p_composable q x [])] = match x with | [] -> () | _::tl -> p_op_nil q tl (** We can finally define our PCM with these operations *) let p (#a: Type u#a) (q:preorder a) : pcm' (hist q) = { composable = p_composable q; op = p_op q; one = [] } (** Composability is commutative *) let comm (#a: Type u#a) (q:preorder a) (x y:hist q) : Lemma (requires p_composable q x y) (ensures p_composable q y x) = () (** As well as the compose operation *) let comm_op (#a: Type u#a) (q:preorder a) (x:hist q) (y:hist q{p_composable q x y}) : Lemma (p_op q x y == p_op q y x) = extends_length_eq x y; extends_length_eq y x (** If [z] extends [x] and [y], then [x] and [y] are extending one or another *) let rec extends_disjunction (#a: Type u#a) (#q:preorder a) (x y z:hist q) : Lemma (z `extends` x /\ z `extends` y ==> x `extends` y \/ y `extends` x) [SMTPat (z `extends` x); SMTPat (z `extends` y)] = match z with | [] -> () | _::tl -> extends_disjunction x y tl (** If [x] extends [y], then the two heads of the traces are still related by the preorder *) let rec extends_related_head (#a: Type u#a) (#q:preorder a) (x y:hist q) : Lemma (ensures x `extends` y /\ Cons? x /\ Cons? y ==> Cons?.hd y `q` Cons?.hd x) [SMTPat (x `extends` y)] = match x with | [] -> () | _::tl -> extends_related_head tl y (** Finally, we can have our fully-fledged PCM from the preorder *) let pcm_of_preorder (#a: Type u#a) (q:preorder a) : pcm (hist q) = { p = p q; comm = comm_op q; assoc = (fun _ _ _ -> ()); assoc_r = (fun _ _ _ -> ()); is_unit = (fun _ -> ()); refine = (fun _ -> True) } (***** Using the preorder *) (** We check that the preorder derived from the PCM derived from the preorder satisfies the same properties as the original preorder. Here, we get back history extension from frame-preserving updates. *) let frame_preserving_q_aux (#a : Type u#a) (q:preorder a) (x y:hist q) (z:hist q) : Lemma (requires (frame_preserving (pcm_of_preorder q) x y /\ compatible (pcm_of_preorder q) x z)) (ensures (y `extends` z)) = () (** A non-empty history *) let vhist (#a: Type u#a) (q:preorder a) = h:hist q{Cons? h} (** Get the current value from an history *) let curval (#a: Type u#a) (#q:preorder a) (v:vhist q) = Cons?.hd v (** Given a frame-preserving update from [x] to [y] for any value of resource [z] (compatible with [x]) the new value [y] advances the history [z] in a preorder respecting manner *) let frame_preserving_q (#a: Type u#a) (q:preorder a) (x y:vhist q) : Lemma (requires frame_preserving (pcm_of_preorder q) x y) (ensures (forall (z:hist q). compatible (pcm_of_preorder q) x z ==> curval z `q` curval y)) = () (** Still given a frame-preserving update from [x] to [y], this update extends the history *) let frame_preserving_extends (#a: Type u#a) (q:preorder a) (x y:vhist q) : Lemma (requires frame_preserving (pcm_of_preorder q) x y) (ensures (forall (z:hist q). compatible (pcm_of_preorder q) x z ==> y `extends` z)) = () (** Helper function that flips a preoder *) let flip (#a: Type u#a) (p:preorder a) : preorder a = fun x y -> p y x (** What is the preorder induced from the PCM induced by preorder [q]? It turns out that it is the flipped of [q], reversed extension. *) let frame_preserving_extends2 (#a: Type u#a) (q:preorder a) (x y:hist q) : Lemma (requires frame_preserving (pcm_of_preorder q) x y) (ensures (forall (z:hist q). compatible (pcm_of_preorder q) x z ==> z `flip extends` y)) [SMTPat (frame_preserving (pcm_of_preorder q) x y)] = () #push-options "--warn_error -271" let pcm_of_preorder_induces_extends (#a: Type u#a) (q:preorder a) : Lemma (induces_preorder (pcm_of_preorder q) (flip extends)) = let fp_full (x y:hist q) (f:frame_preserving_upd (pcm_of_preorder q) x y) (v:hist q) : Lemma (requires compatible (pcm_of_preorder q) x v) (ensures extends (f v) v) [SMTPat ()] = assert (composable (pcm_of_preorder q) x v) in () #pop-options let extend_history (#a:Type u#a) (#q:preorder a) (h0:vhist q) (v:a{q (curval h0) v}) : h1:vhist q{h1 `extends` h0} = v :: h0
{ "checked_file": "/", "dependencies": [ "PulseCore.FractionalPermission.fst.checked", "prims.fst.checked", "FStar.Real.fsti.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked", "FStar.List.Tot.fst.checked", "FStar.IndefiniteDescription.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "PulseCore.Preorder.fst" }
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Real", "short_module": null }, { "abbrev": false, "full_module": "PulseCore.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "FStar.Preorder", "short_module": null }, { "abbrev": false, "full_module": "FStar.PCM", "short_module": null }, { "abbrev": false, "full_module": "PulseCore", "short_module": null }, { "abbrev": false, "full_module": "PulseCore", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Type -> Type
Prims.Tot
[ "total" ]
[]
[ "Prims.prop" ]
[]
false
false
false
true
true
let property (a: Type) =
a -> prop
false
PulseCore.Preorder.fst
PulseCore.Preorder.fact_valid_compat
val fact_valid_compat : fact: PulseCore.Preorder.stable_property pcm -> v: a -> Prims.logical
let fact_valid_compat (#a:Type) (#pcm:pcm a) (fact:stable_property pcm) (v:a) = forall z. compatible pcm v z ==> fact z
{ "file_name": "lib/pulse_core/PulseCore.Preorder.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 43, "end_line": 277, "start_col": 0, "start_line": 274 }
(* 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 PulseCore.Preorder open FStar.PCM open FStar.Preorder open PulseCore.FractionalPermission open FStar.Real /// This module explores the connection between PCM and preorders. More specifically, we show here /// that any PCM induces a preorder relation, characterized by frame-preservation for any updates. /// /// Furthermore, we also consider the reverse relationship where we derive a PCM for any preorder, /// by taking as elements of the PCM the trace of all the states of the element. (**** PCM to preoder *) (** PCM [p] induces the preorder [q] if for any frame preserving update of [x] to [y], the argument and result of the frame preserving update are related by q *) let induces_preorder (#a:Type u#a) (p:pcm a) (q:preorder a) = forall (x y:a) (f:frame_preserving_upd p x y) (v:a). p.refine v ==> compatible p x v ==> q v (f v) (** We can define a canonical preorder from any PCM by taking the quantified conjunction over all the preorders [q] induced by this PCM. *) let preorder_of_pcm (#a:Type u#a) (p:pcm a) : preorder a = fun x y -> forall (q:preorder a). induces_preorder p q ==> q x y let frame_preserving_upd_is_preorder_preserving (#a:Type u#a) (p:pcm a) (x y:a) (f:frame_preserving_upd p x y) (v_old:a{p.refine v_old /\ compatible p x v_old}) : Lemma ((preorder_of_pcm p) v_old (f v_old)) = () (** This canonical preorder enjoys the nice property that it preserves fact stability of any induced preorder *) let stability (#a: Type u#a) (fact:a -> prop) (q:preorder a) (p:pcm a) : Lemma (requires stable fact q /\ induces_preorder p q) (ensures stable fact (preorder_of_pcm p)) = () let stable_compatiblity (#a:Type u#a) (fact: a -> prop) (p:pcm a) (v v0 v1:a) : Lemma (requires stable fact (preorder_of_pcm p) /\ p.refine v0 /\ fact v0 /\ p.refine v1 /\ frame_preserving p v v1 /\ compatible p v v0) (ensures fact v1) = let f : frame_preserving_upd p v v1 = frame_preserving_val_to_fp_upd p v v1 in frame_preserving_upd_is_preorder_preserving p v v1 f v0 (**** Preorder to PCM *) (***** Building the preorder *) (** This predicate tells that the list [l] can represent a trace of elements whose evolution is compatible with the preorder [q] *) let rec qhistory #a (q:preorder a) (l:list a) = match l with | [] | [_] -> True | x::y::tl -> y `q` x /\ qhistory q (y::tl) (** The history of a preorder is the type of all the traces compatible with that preorder *) let hist (#a: Type u#a) (q:preorder a) = l:list a{qhistory q l} (** Two compatible traces can extend each other *) let rec extends' (#a: Type u#a) (#q:preorder a) (h0 h1:hist q) = h0 == h1 \/ (Cons? h0 /\ extends' (Cons?.tl h0) h1) (** This extension relation is transitive *) let rec extends_trans #a (#q:preorder a) (x y z:hist q) : Lemma (x `extends'` y /\ y `extends'` z ==> x `extends'` z) [SMTPat (x `extends'` y); SMTPat (y `extends'` z)] = match x with | [] -> () | _::tl -> extends_trans tl y z (** And it is also reflexive, so extensibility on traces is a preorder on traces *) let extends (#a: Type u#a) (#q:preorder a) : preorder (hist q) = extends' module L = FStar.List.Tot (** If [h0] extends by [h1], then the length of [h0] is superior *) let rec extends_length_eq (#a: Type u#a) (#q:preorder a) (h0 h1:hist q) : Lemma (ensures (extends h0 h1 ==> h0 == h1 \/ L.length h0 > L.length h1)) [SMTPat (extends h0 h1)] = match h0 with | [] -> () | hd::tl -> extends_length_eq tl h1 (** We build our relation of composability for traces by reflexing the extension to ensure symmetry *) let p_composable (#a: Type u#a) (q:preorder a) : symrel (hist q) = fun x y -> extends x y \/ extends y x (** The operation for the PCM is to return the full trace of two extensible traces *) let p_op (#a: Type u#a) (q:preorder a) (x:hist q) (y:hist q{p_composable q x y}) : hist q = if L.length x >= L.length y then x else if L.length x = L.length y then (assert (x == y); x) else y (** The operation actually implements extension *) let p_op_extends (#a: Type u#a) (q:preorder a) (x:hist q) (y:hist q{p_composable q x y}) : Lemma (ensures (p_op q x y `extends` x /\ p_op q x y `extends` y /\ (p_op q x y == x \/ p_op q x y == y))) [SMTPat (p_op q x y)] = extends_length_eq x y; extends_length_eq y x (** And the empty trace is the unit element *) let rec p_op_nil (#a: Type u#a) (q:preorder a) (x:hist q) : Lemma (ensures (p_composable q x [] /\ p_op q x [] == x)) [SMTPat (p_composable q x [])] = match x with | [] -> () | _::tl -> p_op_nil q tl (** We can finally define our PCM with these operations *) let p (#a: Type u#a) (q:preorder a) : pcm' (hist q) = { composable = p_composable q; op = p_op q; one = [] } (** Composability is commutative *) let comm (#a: Type u#a) (q:preorder a) (x y:hist q) : Lemma (requires p_composable q x y) (ensures p_composable q y x) = () (** As well as the compose operation *) let comm_op (#a: Type u#a) (q:preorder a) (x:hist q) (y:hist q{p_composable q x y}) : Lemma (p_op q x y == p_op q y x) = extends_length_eq x y; extends_length_eq y x (** If [z] extends [x] and [y], then [x] and [y] are extending one or another *) let rec extends_disjunction (#a: Type u#a) (#q:preorder a) (x y z:hist q) : Lemma (z `extends` x /\ z `extends` y ==> x `extends` y \/ y `extends` x) [SMTPat (z `extends` x); SMTPat (z `extends` y)] = match z with | [] -> () | _::tl -> extends_disjunction x y tl (** If [x] extends [y], then the two heads of the traces are still related by the preorder *) let rec extends_related_head (#a: Type u#a) (#q:preorder a) (x y:hist q) : Lemma (ensures x `extends` y /\ Cons? x /\ Cons? y ==> Cons?.hd y `q` Cons?.hd x) [SMTPat (x `extends` y)] = match x with | [] -> () | _::tl -> extends_related_head tl y (** Finally, we can have our fully-fledged PCM from the preorder *) let pcm_of_preorder (#a: Type u#a) (q:preorder a) : pcm (hist q) = { p = p q; comm = comm_op q; assoc = (fun _ _ _ -> ()); assoc_r = (fun _ _ _ -> ()); is_unit = (fun _ -> ()); refine = (fun _ -> True) } (***** Using the preorder *) (** We check that the preorder derived from the PCM derived from the preorder satisfies the same properties as the original preorder. Here, we get back history extension from frame-preserving updates. *) let frame_preserving_q_aux (#a : Type u#a) (q:preorder a) (x y:hist q) (z:hist q) : Lemma (requires (frame_preserving (pcm_of_preorder q) x y /\ compatible (pcm_of_preorder q) x z)) (ensures (y `extends` z)) = () (** A non-empty history *) let vhist (#a: Type u#a) (q:preorder a) = h:hist q{Cons? h} (** Get the current value from an history *) let curval (#a: Type u#a) (#q:preorder a) (v:vhist q) = Cons?.hd v (** Given a frame-preserving update from [x] to [y] for any value of resource [z] (compatible with [x]) the new value [y] advances the history [z] in a preorder respecting manner *) let frame_preserving_q (#a: Type u#a) (q:preorder a) (x y:vhist q) : Lemma (requires frame_preserving (pcm_of_preorder q) x y) (ensures (forall (z:hist q). compatible (pcm_of_preorder q) x z ==> curval z `q` curval y)) = () (** Still given a frame-preserving update from [x] to [y], this update extends the history *) let frame_preserving_extends (#a: Type u#a) (q:preorder a) (x y:vhist q) : Lemma (requires frame_preserving (pcm_of_preorder q) x y) (ensures (forall (z:hist q). compatible (pcm_of_preorder q) x z ==> y `extends` z)) = () (** Helper function that flips a preoder *) let flip (#a: Type u#a) (p:preorder a) : preorder a = fun x y -> p y x (** What is the preorder induced from the PCM induced by preorder [q]? It turns out that it is the flipped of [q], reversed extension. *) let frame_preserving_extends2 (#a: Type u#a) (q:preorder a) (x y:hist q) : Lemma (requires frame_preserving (pcm_of_preorder q) x y) (ensures (forall (z:hist q). compatible (pcm_of_preorder q) x z ==> z `flip extends` y)) [SMTPat (frame_preserving (pcm_of_preorder q) x y)] = () #push-options "--warn_error -271" let pcm_of_preorder_induces_extends (#a: Type u#a) (q:preorder a) : Lemma (induces_preorder (pcm_of_preorder q) (flip extends)) = let fp_full (x y:hist q) (f:frame_preserving_upd (pcm_of_preorder q) x y) (v:hist q) : Lemma (requires compatible (pcm_of_preorder q) x v) (ensures extends (f v) v) [SMTPat ()] = assert (composable (pcm_of_preorder q) x v) in () #pop-options let extend_history (#a:Type u#a) (#q:preorder a) (h0:vhist q) (v:a{q (curval h0) v}) : h1:vhist q{h1 `extends` h0} = v :: h0 let property (a:Type) = a -> prop let stable_property (#a:Type) (pcm:pcm a) = fact:property a { FStar.Preorder.stable fact (preorder_of_pcm pcm) }
{ "checked_file": "/", "dependencies": [ "PulseCore.FractionalPermission.fst.checked", "prims.fst.checked", "FStar.Real.fsti.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked", "FStar.List.Tot.fst.checked", "FStar.IndefiniteDescription.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "PulseCore.Preorder.fst" }
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Real", "short_module": null }, { "abbrev": false, "full_module": "PulseCore.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "FStar.Preorder", "short_module": null }, { "abbrev": false, "full_module": "FStar.PCM", "short_module": null }, { "abbrev": false, "full_module": "PulseCore", "short_module": null }, { "abbrev": false, "full_module": "PulseCore", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
fact: PulseCore.Preorder.stable_property pcm -> v: a -> Prims.logical
Prims.Tot
[ "total" ]
[]
[ "FStar.PCM.pcm", "PulseCore.Preorder.stable_property", "Prims.l_Forall", "Prims.l_imp", "FStar.PCM.compatible", "Prims.logical" ]
[]
false
false
false
false
true
let fact_valid_compat (#a: Type) (#pcm: pcm a) (fact: stable_property pcm) (v: a) =
forall z. compatible pcm v z ==> fact z
false
Hacl.HPKE.Interface.AEAD.fst
Hacl.HPKE.Interface.AEAD.aead_decrypt_cp128
val aead_decrypt_cp128 : aead_decrypt_st (S.Seal AEAD.CHACHA20_POLY1305)
val aead_decrypt_cp128 : aead_decrypt_st (S.Seal AEAD.CHACHA20_POLY1305)
let aead_decrypt_cp128 = fun _ key nonce alen aad len input output -> let cipher = sub output 0ul len in let tag = sub output len 16ul in Hacl.Chacha20Poly1305_128.decrypt input cipher len aad alen key nonce tag
{ "file_name": "code/hpke/Hacl.HPKE.Interface.AEAD.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 77, "end_line": 46, "start_col": 0, "start_line": 42 }
module Hacl.HPKE.Interface.AEAD open FStar.HyperStack open FStar.HyperStack.All open Lib.Buffer friend Spec.Agile.AEAD /// These two functions will never be extracted, they are only an interface /// boundary for the tactic performing instantiations. /// In other files, it is exposed as an assume val, but for AEAD, we need an fsti /// since we need to friend Spec.Agile.AEAD to perform the instantiations below, /// and assume val are forbidden in interface files let aead_encrypt #cs = admit() let aead_decrypt #cs = admit() #set-options "--z3rlimit 60 --fuel 0 --ifuel 0" inline_for_extraction noextract let aead_encrypt_cp32 = fun _ key nonce alen aad len input output -> let cipher = sub output 0ul len in let tag = sub output len 16ul in Hacl.Chacha20Poly1305_32.encrypt cipher tag input len aad alen key nonce inline_for_extraction noextract let aead_decrypt_cp32 = fun _ key nonce alen aad len input output -> let cipher = sub output 0ul len in let tag = sub output len 16ul in Hacl.Chacha20Poly1305_32.decrypt input cipher len aad alen key nonce tag inline_for_extraction noextract let aead_encrypt_cp128 = fun _ key nonce alen aad len input output -> let cipher = sub output 0ul len in let tag = sub output len 16ul in Hacl.Chacha20Poly1305_128.encrypt cipher tag input len aad alen key nonce
{ "checked_file": "/", "dependencies": [ "Spec.Agile.AEAD.fst.checked", "prims.fst.checked", "Lib.Buffer.fsti.checked", "Hacl.Chacha20Poly1305_32.fst.checked", "Hacl.Chacha20Poly1305_256.fst.checked", "Hacl.Chacha20Poly1305_128.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": true, "source_file": "Hacl.HPKE.Interface.AEAD.fst" }
[ { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": true, "full_module": "Spec.Agile.AEAD", "short_module": "AEAD" }, { "abbrev": true, "full_module": "Spec.Agile.HPKE", "short_module": "S" }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "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.HPKE.Interface", "short_module": null }, { "abbrev": false, "full_module": "Hacl.HPKE.Interface", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 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": 60, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Hacl.HPKE.Interface.AEAD.aead_decrypt_st (Spec.Agile.HPKE.Seal Spec.Agile.AEAD.CHACHA20_POLY1305)
Prims.Tot
[ "total" ]
[]
[ "Prims.squash", "Prims.l_and", "Prims.b2t", "Spec.Agile.HPKE.uu___is_Seal", "Spec.Agile.HPKE.Seal", "Spec.Agile.AEAD.CHACHA20_POLY1305", "Spec.Agile.HPKE.is_valid_aead", "Hacl.HPKE.Interface.AEAD.kv", "Spec.Agile.HPKE.__proj__Seal__item__alg", "Hacl.HPKE.Interface.AEAD.iv", "Lib.IntTypes.size_t", "Prims.op_LessThanOrEqual", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Spec.Agile.AEAD.max_length", "Lib.Buffer.lbuffer", "Lib.IntTypes.uint8", "Prims.op_Addition", "Lib.IntTypes.max_size_t", "Lib.IntTypes.size", "Hacl.Chacha20Poly1305_128.decrypt", "FStar.UInt32.t", "Lib.Buffer.lbuffer_t", "Lib.Buffer.MUT", "Lib.IntTypes.int_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "FStar.UInt32.uint_to_t", "Lib.Buffer.sub", "FStar.UInt32.__uint_to_t" ]
[]
false
false
false
true
false
let aead_decrypt_cp128 =
fun _ key nonce alen aad len input output -> let cipher = sub output 0ul len in let tag = sub output len 16ul in Hacl.Chacha20Poly1305_128.decrypt input cipher len aad alen key nonce tag
false
LowParse.Low.Writers.Instances.fst
LowParse.Low.Writers.Instances.swrite_filter
val swrite_filter (#h0: HS.mem) (#sout: slice (srel_of_buffer_srel (B.trivial_preorder _)) (srel_of_buffer_srel (B.trivial_preorder _))) (#pout_from0: U32.t) (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#s1: serializer p1 {k1.parser_kind_subkind == Some ParserStrong}) (#space_beyond: nat) (cond: (t1 -> GTot bool)) (w1: swriter s1 h0 space_beyond sout pout_from0 {cond (swvalue w1)}) : Tot (w2: swriter (serialize_filter s1 cond) h0 space_beyond sout pout_from0 {swvalue w2 == swvalue w1})
val swrite_filter (#h0: HS.mem) (#sout: slice (srel_of_buffer_srel (B.trivial_preorder _)) (srel_of_buffer_srel (B.trivial_preorder _))) (#pout_from0: U32.t) (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#s1: serializer p1 {k1.parser_kind_subkind == Some ParserStrong}) (#space_beyond: nat) (cond: (t1 -> GTot bool)) (w1: swriter s1 h0 space_beyond sout pout_from0 {cond (swvalue w1)}) : Tot (w2: swriter (serialize_filter s1 cond) h0 space_beyond sout pout_from0 {swvalue w2 == swvalue w1})
let swrite_filter (#h0: HS.mem) (#sout: slice (srel_of_buffer_srel (B.trivial_preorder _)) (srel_of_buffer_srel (B.trivial_preorder _))) (#pout_from0: U32.t) (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#s1: serializer p1 { k1.parser_kind_subkind == Some ParserStrong }) (#space_beyond: nat) (cond: (t1 -> GTot bool)) (w1: swriter s1 h0 space_beyond sout pout_from0 { cond (swvalue w1) } ) : Tot (w2: swriter (serialize_filter s1 cond) h0 space_beyond sout pout_from0 { swvalue w2 == swvalue w1 }) = SWriter (Ghost.hide (swvalue w1)) (fun pout_from -> serialized_length_eq (serialize_filter s1 cond) (swvalue w1); serialized_length_eq s1 (swvalue w1); let res = swrite w1 pout_from in let h = HST.get () in valid_filter h p1 cond sout pout_from; res )
{ "file_name": "src/lowparse/LowParse.Low.Writers.Instances.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 3, "end_line": 122, "start_col": 0, "start_line": 101 }
module LowParse.Low.Writers.Instances include LowParse.Low.Writers include LowParse.Low.Combinators include LowParse.Low.Bytes include LowParse.Low.BitSum module HS = FStar.HyperStack module B = LowStar.Buffer module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST inline_for_extraction noextract let swrite_weaken (#h0: HS.mem) (#sout: slice (srel_of_buffer_srel (B.trivial_preorder _)) (srel_of_buffer_srel (B.trivial_preorder _))) (#pout_from0: U32.t) (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#s1: serializer p1 { k1.parser_kind_subkind == Some ParserStrong }) (#space_beyond: nat) (k2: parser_kind) (w1: swriter s1 h0 space_beyond sout pout_from0 { (k2 `is_weaker_than` k1) /\ k2.parser_kind_subkind == Some ParserStrong }) : Tot (w2: swriter (serialize_weaken k2 s1) h0 space_beyond sout pout_from0 { swvalue w2 == swvalue w1 }) = SWriter (Ghost.hide (swvalue w1)) (fun pout_from -> serialized_length_eq s1 (swvalue w1); serialized_length_eq (serialize_weaken k2 s1) (swvalue w1); let res = swrite w1 pout_from in let h = HST.get () in valid_weaken k2 p1 h sout pout_from; res ) inline_for_extraction noextract let swrite_nondep_then' (#h0: HS.mem) (#sout: slice (srel_of_buffer_srel (B.trivial_preorder _)) (srel_of_buffer_srel (B.trivial_preorder _))) (#pout_from0: U32.t) (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#s1: serializer p1 { k1.parser_kind_subkind == Some ParserStrong }) (#space_beyond: nat) (w1: swriter s1 h0 space_beyond sout pout_from0) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (#s2: serializer p2 { k2.parser_kind_subkind == Some ParserStrong }) (w2: swriter s2 h0 space_beyond sout pout_from0) : Tot (w: swriter (s1 `serialize_nondep_then` s2) h0 space_beyond sout pout_from0 { swvalue w == (swvalue w1, swvalue w2) }) = SWriter (Ghost.hide (swvalue w1, swvalue w2)) (fun pout_from -> serialized_length_eq (s1 `serialize_nondep_then` s2) (swvalue w1, swvalue w2); serialize_nondep_then_eq s1 s2 (swvalue w1, swvalue w2); serialized_length_eq s1 (swvalue w1); serialized_length_eq s2 (swvalue w2); let pos1 = swrite w1 pout_from in let pos2 = swrite w2 pos1 in let h' = HST.get () in valid_nondep_then h' p1 p2 sout pout_from; pos2 ) let max (x1 x2: nat) : Tot nat = if x1 > x2 then x1 else x2 inline_for_extraction noextract let swrite_nondep_then (#h0: HS.mem) (#sout: slice (srel_of_buffer_srel (B.trivial_preorder _)) (srel_of_buffer_srel (B.trivial_preorder _))) (#pout_from0: U32.t) (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#s1: serializer p1 { k1.parser_kind_subkind == Some ParserStrong }) (#space_beyond1: nat) (w1: swriter s1 h0 space_beyond1 sout pout_from0) (#k2: parser_kind) (#t2: Type) (#p2: parser k2 t2) (#s2: serializer p2 { k2.parser_kind_subkind == Some ParserStrong }) (#space_beyond2: nat) (w2: swriter s2 h0 space_beyond2 sout pout_from0) : Tot (w: swriter (s1 `serialize_nondep_then` s2) h0 (space_beyond1 `max` space_beyond2) sout pout_from0 { swvalue w == (swvalue w1, swvalue w2) }) = [@inline_let] let sbmax = space_beyond1 `max` space_beyond2 in weaken_swriter w1 h0 sbmax pout_from0 `swrite_nondep_then'` weaken_swriter w2 h0 sbmax pout_from0 inline_for_extraction
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Endianness.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Low.Writers.fst.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Low.Bytes.fst.checked", "LowParse.Low.BitSum.fst.checked", "LowParse.Endianness.BitFields.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Bytes.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Low.Writers.Instances.fst" }
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "LowParse.Low.BitSum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Bytes", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Writers", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Writers", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Writers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
cond: (_: t1 -> Prims.GTot Prims.bool) -> w1: LowParse.Low.Writers.swriter s1 h0 space_beyond sout pout_from0 {cond (LowParse.Low.Writers.swvalue w1)} -> w2: LowParse.Low.Writers.swriter (LowParse.Spec.Combinators.serialize_filter s1 cond) h0 space_beyond sout pout_from0 {LowParse.Low.Writers.swvalue w2 == LowParse.Low.Writers.swvalue w1}
Prims.Tot
[ "total" ]
[]
[ "FStar.Monotonic.HyperStack.mem", "LowParse.Slice.slice", "LowParse.Slice.srel_of_buffer_srel", "LowParse.Bytes.byte", "LowStar.Buffer.trivial_preorder", "FStar.UInt32.t", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Spec.Base.serializer", "Prims.eq2", "FStar.Pervasives.Native.option", "LowParse.Spec.Base.parser_subkind", "LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_subkind", "FStar.Pervasives.Native.Some", "LowParse.Spec.Base.ParserStrong", "Prims.nat", "Prims.bool", "LowParse.Low.Writers.swriter", "Prims.b2t", "LowParse.Low.Writers.swvalue", "LowParse.Low.Writers.SWriter", "LowParse.Spec.Combinators.parse_filter_kind", "LowParse.Spec.Combinators.parse_filter_refine", "LowParse.Spec.Combinators.parse_filter", "LowParse.Spec.Combinators.serialize_filter", "FStar.Ghost.hide", "Prims.unit", "LowParse.Low.Combinators.valid_filter", "FStar.HyperStack.ST.get", "LowParse.Low.Writers.swrite", "LowParse.Low.Base.Spec.serialized_length_eq" ]
[]
false
false
false
false
false
let swrite_filter (#h0: HS.mem) (#sout: slice (srel_of_buffer_srel (B.trivial_preorder _)) (srel_of_buffer_srel (B.trivial_preorder _))) (#pout_from0: U32.t) (#k1: parser_kind) (#t1: Type) (#p1: parser k1 t1) (#s1: serializer p1 {k1.parser_kind_subkind == Some ParserStrong}) (#space_beyond: nat) (cond: (t1 -> GTot bool)) (w1: swriter s1 h0 space_beyond sout pout_from0 {cond (swvalue w1)}) : Tot (w2: swriter (serialize_filter s1 cond) h0 space_beyond sout pout_from0 {swvalue w2 == swvalue w1}) =
SWriter (Ghost.hide (swvalue w1)) (fun pout_from -> serialized_length_eq (serialize_filter s1 cond) (swvalue w1); serialized_length_eq s1 (swvalue w1); let res = swrite w1 pout_from in let h = HST.get () in valid_filter h p1 cond sout pout_from; res)
false
PulseCore.Preorder.fst
PulseCore.Preorder.extends_disjunction
val extends_disjunction (#a: Type u#a) (#q: preorder a) (x y z: hist q) : Lemma (z `extends` x /\ z `extends` y ==> x `extends` y \/ y `extends` x) [SMTPat (z `extends` x); SMTPat (z `extends` y)]
val extends_disjunction (#a: Type u#a) (#q: preorder a) (x y z: hist q) : Lemma (z `extends` x /\ z `extends` y ==> x `extends` y \/ y `extends` x) [SMTPat (z `extends` x); SMTPat (z `extends` y)]
let rec extends_disjunction (#a: Type u#a) (#q:preorder a) (x y z:hist q) : Lemma (z `extends` x /\ z `extends` y ==> x `extends` y \/ y `extends` x) [SMTPat (z `extends` x); SMTPat (z `extends` y)] = match z with | [] -> () | _::tl -> extends_disjunction x y tl
{ "file_name": "lib/pulse_core/PulseCore.Preorder.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 41, "end_line": 180, "start_col": 0, "start_line": 174 }
(* 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 PulseCore.Preorder open FStar.PCM open FStar.Preorder open PulseCore.FractionalPermission open FStar.Real /// This module explores the connection between PCM and preorders. More specifically, we show here /// that any PCM induces a preorder relation, characterized by frame-preservation for any updates. /// /// Furthermore, we also consider the reverse relationship where we derive a PCM for any preorder, /// by taking as elements of the PCM the trace of all the states of the element. (**** PCM to preoder *) (** PCM [p] induces the preorder [q] if for any frame preserving update of [x] to [y], the argument and result of the frame preserving update are related by q *) let induces_preorder (#a:Type u#a) (p:pcm a) (q:preorder a) = forall (x y:a) (f:frame_preserving_upd p x y) (v:a). p.refine v ==> compatible p x v ==> q v (f v) (** We can define a canonical preorder from any PCM by taking the quantified conjunction over all the preorders [q] induced by this PCM. *) let preorder_of_pcm (#a:Type u#a) (p:pcm a) : preorder a = fun x y -> forall (q:preorder a). induces_preorder p q ==> q x y let frame_preserving_upd_is_preorder_preserving (#a:Type u#a) (p:pcm a) (x y:a) (f:frame_preserving_upd p x y) (v_old:a{p.refine v_old /\ compatible p x v_old}) : Lemma ((preorder_of_pcm p) v_old (f v_old)) = () (** This canonical preorder enjoys the nice property that it preserves fact stability of any induced preorder *) let stability (#a: Type u#a) (fact:a -> prop) (q:preorder a) (p:pcm a) : Lemma (requires stable fact q /\ induces_preorder p q) (ensures stable fact (preorder_of_pcm p)) = () let stable_compatiblity (#a:Type u#a) (fact: a -> prop) (p:pcm a) (v v0 v1:a) : Lemma (requires stable fact (preorder_of_pcm p) /\ p.refine v0 /\ fact v0 /\ p.refine v1 /\ frame_preserving p v v1 /\ compatible p v v0) (ensures fact v1) = let f : frame_preserving_upd p v v1 = frame_preserving_val_to_fp_upd p v v1 in frame_preserving_upd_is_preorder_preserving p v v1 f v0 (**** Preorder to PCM *) (***** Building the preorder *) (** This predicate tells that the list [l] can represent a trace of elements whose evolution is compatible with the preorder [q] *) let rec qhistory #a (q:preorder a) (l:list a) = match l with | [] | [_] -> True | x::y::tl -> y `q` x /\ qhistory q (y::tl) (** The history of a preorder is the type of all the traces compatible with that preorder *) let hist (#a: Type u#a) (q:preorder a) = l:list a{qhistory q l} (** Two compatible traces can extend each other *) let rec extends' (#a: Type u#a) (#q:preorder a) (h0 h1:hist q) = h0 == h1 \/ (Cons? h0 /\ extends' (Cons?.tl h0) h1) (** This extension relation is transitive *) let rec extends_trans #a (#q:preorder a) (x y z:hist q) : Lemma (x `extends'` y /\ y `extends'` z ==> x `extends'` z) [SMTPat (x `extends'` y); SMTPat (y `extends'` z)] = match x with | [] -> () | _::tl -> extends_trans tl y z (** And it is also reflexive, so extensibility on traces is a preorder on traces *) let extends (#a: Type u#a) (#q:preorder a) : preorder (hist q) = extends' module L = FStar.List.Tot (** If [h0] extends by [h1], then the length of [h0] is superior *) let rec extends_length_eq (#a: Type u#a) (#q:preorder a) (h0 h1:hist q) : Lemma (ensures (extends h0 h1 ==> h0 == h1 \/ L.length h0 > L.length h1)) [SMTPat (extends h0 h1)] = match h0 with | [] -> () | hd::tl -> extends_length_eq tl h1 (** We build our relation of composability for traces by reflexing the extension to ensure symmetry *) let p_composable (#a: Type u#a) (q:preorder a) : symrel (hist q) = fun x y -> extends x y \/ extends y x (** The operation for the PCM is to return the full trace of two extensible traces *) let p_op (#a: Type u#a) (q:preorder a) (x:hist q) (y:hist q{p_composable q x y}) : hist q = if L.length x >= L.length y then x else if L.length x = L.length y then (assert (x == y); x) else y (** The operation actually implements extension *) let p_op_extends (#a: Type u#a) (q:preorder a) (x:hist q) (y:hist q{p_composable q x y}) : Lemma (ensures (p_op q x y `extends` x /\ p_op q x y `extends` y /\ (p_op q x y == x \/ p_op q x y == y))) [SMTPat (p_op q x y)] = extends_length_eq x y; extends_length_eq y x (** And the empty trace is the unit element *) let rec p_op_nil (#a: Type u#a) (q:preorder a) (x:hist q) : Lemma (ensures (p_composable q x [] /\ p_op q x [] == x)) [SMTPat (p_composable q x [])] = match x with | [] -> () | _::tl -> p_op_nil q tl (** We can finally define our PCM with these operations *) let p (#a: Type u#a) (q:preorder a) : pcm' (hist q) = { composable = p_composable q; op = p_op q; one = [] } (** Composability is commutative *) let comm (#a: Type u#a) (q:preorder a) (x y:hist q) : Lemma (requires p_composable q x y) (ensures p_composable q y x) = () (** As well as the compose operation *) let comm_op (#a: Type u#a) (q:preorder a) (x:hist q) (y:hist q{p_composable q x y}) : Lemma (p_op q x y == p_op q y x) = extends_length_eq x y; extends_length_eq y x
{ "checked_file": "/", "dependencies": [ "PulseCore.FractionalPermission.fst.checked", "prims.fst.checked", "FStar.Real.fsti.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked", "FStar.List.Tot.fst.checked", "FStar.IndefiniteDescription.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "PulseCore.Preorder.fst" }
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Real", "short_module": null }, { "abbrev": false, "full_module": "PulseCore.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "FStar.Preorder", "short_module": null }, { "abbrev": false, "full_module": "FStar.PCM", "short_module": null }, { "abbrev": false, "full_module": "PulseCore", "short_module": null }, { "abbrev": false, "full_module": "PulseCore", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: PulseCore.Preorder.hist q -> y: PulseCore.Preorder.hist q -> z: PulseCore.Preorder.hist q -> FStar.Pervasives.Lemma (ensures PulseCore.Preorder.extends z x /\ PulseCore.Preorder.extends z y ==> PulseCore.Preorder.extends x y \/ PulseCore.Preorder.extends y x) [SMTPat (PulseCore.Preorder.extends z x); SMTPat (PulseCore.Preorder.extends z y)]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "FStar.Preorder.preorder", "PulseCore.Preorder.hist", "Prims.list", "PulseCore.Preorder.extends_disjunction", "Prims.unit", "Prims.l_True", "Prims.squash", "Prims.l_imp", "Prims.l_and", "PulseCore.Preorder.extends", "Prims.l_or", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat", "Prims.Nil" ]
[ "recursion" ]
false
false
true
false
false
let rec extends_disjunction (#a: Type u#a) (#q: preorder a) (x y z: hist q) : Lemma (z `extends` x /\ z `extends` y ==> x `extends` y \/ y `extends` x) [SMTPat (z `extends` x); SMTPat (z `extends` y)] =
match z with | [] -> () | _ :: tl -> extends_disjunction x y tl
false
PulseCore.Preorder.fst
PulseCore.Preorder.hval
val hval (#a #p: _) (h: history a p {Current? h}) : Ghost.erased a
val hval (#a #p: _) (h: history a p {Current? h}) : Ghost.erased a
let hval #a #p (h:history a p{Current? h}) : Ghost.erased a = hval_tot h
{ "file_name": "lib/pulse_core/PulseCore.Preorder.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 12, "end_line": 290, "start_col": 0, "start_line": 289 }
(* 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 PulseCore.Preorder open FStar.PCM open FStar.Preorder open PulseCore.FractionalPermission open FStar.Real /// This module explores the connection between PCM and preorders. More specifically, we show here /// that any PCM induces a preorder relation, characterized by frame-preservation for any updates. /// /// Furthermore, we also consider the reverse relationship where we derive a PCM for any preorder, /// by taking as elements of the PCM the trace of all the states of the element. (**** PCM to preoder *) (** PCM [p] induces the preorder [q] if for any frame preserving update of [x] to [y], the argument and result of the frame preserving update are related by q *) let induces_preorder (#a:Type u#a) (p:pcm a) (q:preorder a) = forall (x y:a) (f:frame_preserving_upd p x y) (v:a). p.refine v ==> compatible p x v ==> q v (f v) (** We can define a canonical preorder from any PCM by taking the quantified conjunction over all the preorders [q] induced by this PCM. *) let preorder_of_pcm (#a:Type u#a) (p:pcm a) : preorder a = fun x y -> forall (q:preorder a). induces_preorder p q ==> q x y let frame_preserving_upd_is_preorder_preserving (#a:Type u#a) (p:pcm a) (x y:a) (f:frame_preserving_upd p x y) (v_old:a{p.refine v_old /\ compatible p x v_old}) : Lemma ((preorder_of_pcm p) v_old (f v_old)) = () (** This canonical preorder enjoys the nice property that it preserves fact stability of any induced preorder *) let stability (#a: Type u#a) (fact:a -> prop) (q:preorder a) (p:pcm a) : Lemma (requires stable fact q /\ induces_preorder p q) (ensures stable fact (preorder_of_pcm p)) = () let stable_compatiblity (#a:Type u#a) (fact: a -> prop) (p:pcm a) (v v0 v1:a) : Lemma (requires stable fact (preorder_of_pcm p) /\ p.refine v0 /\ fact v0 /\ p.refine v1 /\ frame_preserving p v v1 /\ compatible p v v0) (ensures fact v1) = let f : frame_preserving_upd p v v1 = frame_preserving_val_to_fp_upd p v v1 in frame_preserving_upd_is_preorder_preserving p v v1 f v0 (**** Preorder to PCM *) (***** Building the preorder *) (** This predicate tells that the list [l] can represent a trace of elements whose evolution is compatible with the preorder [q] *) let rec qhistory #a (q:preorder a) (l:list a) = match l with | [] | [_] -> True | x::y::tl -> y `q` x /\ qhistory q (y::tl) (** The history of a preorder is the type of all the traces compatible with that preorder *) let hist (#a: Type u#a) (q:preorder a) = l:list a{qhistory q l} (** Two compatible traces can extend each other *) let rec extends' (#a: Type u#a) (#q:preorder a) (h0 h1:hist q) = h0 == h1 \/ (Cons? h0 /\ extends' (Cons?.tl h0) h1) (** This extension relation is transitive *) let rec extends_trans #a (#q:preorder a) (x y z:hist q) : Lemma (x `extends'` y /\ y `extends'` z ==> x `extends'` z) [SMTPat (x `extends'` y); SMTPat (y `extends'` z)] = match x with | [] -> () | _::tl -> extends_trans tl y z (** And it is also reflexive, so extensibility on traces is a preorder on traces *) let extends (#a: Type u#a) (#q:preorder a) : preorder (hist q) = extends' module L = FStar.List.Tot (** If [h0] extends by [h1], then the length of [h0] is superior *) let rec extends_length_eq (#a: Type u#a) (#q:preorder a) (h0 h1:hist q) : Lemma (ensures (extends h0 h1 ==> h0 == h1 \/ L.length h0 > L.length h1)) [SMTPat (extends h0 h1)] = match h0 with | [] -> () | hd::tl -> extends_length_eq tl h1 (** We build our relation of composability for traces by reflexing the extension to ensure symmetry *) let p_composable (#a: Type u#a) (q:preorder a) : symrel (hist q) = fun x y -> extends x y \/ extends y x (** The operation for the PCM is to return the full trace of two extensible traces *) let p_op (#a: Type u#a) (q:preorder a) (x:hist q) (y:hist q{p_composable q x y}) : hist q = if L.length x >= L.length y then x else if L.length x = L.length y then (assert (x == y); x) else y (** The operation actually implements extension *) let p_op_extends (#a: Type u#a) (q:preorder a) (x:hist q) (y:hist q{p_composable q x y}) : Lemma (ensures (p_op q x y `extends` x /\ p_op q x y `extends` y /\ (p_op q x y == x \/ p_op q x y == y))) [SMTPat (p_op q x y)] = extends_length_eq x y; extends_length_eq y x (** And the empty trace is the unit element *) let rec p_op_nil (#a: Type u#a) (q:preorder a) (x:hist q) : Lemma (ensures (p_composable q x [] /\ p_op q x [] == x)) [SMTPat (p_composable q x [])] = match x with | [] -> () | _::tl -> p_op_nil q tl (** We can finally define our PCM with these operations *) let p (#a: Type u#a) (q:preorder a) : pcm' (hist q) = { composable = p_composable q; op = p_op q; one = [] } (** Composability is commutative *) let comm (#a: Type u#a) (q:preorder a) (x y:hist q) : Lemma (requires p_composable q x y) (ensures p_composable q y x) = () (** As well as the compose operation *) let comm_op (#a: Type u#a) (q:preorder a) (x:hist q) (y:hist q{p_composable q x y}) : Lemma (p_op q x y == p_op q y x) = extends_length_eq x y; extends_length_eq y x (** If [z] extends [x] and [y], then [x] and [y] are extending one or another *) let rec extends_disjunction (#a: Type u#a) (#q:preorder a) (x y z:hist q) : Lemma (z `extends` x /\ z `extends` y ==> x `extends` y \/ y `extends` x) [SMTPat (z `extends` x); SMTPat (z `extends` y)] = match z with | [] -> () | _::tl -> extends_disjunction x y tl (** If [x] extends [y], then the two heads of the traces are still related by the preorder *) let rec extends_related_head (#a: Type u#a) (#q:preorder a) (x y:hist q) : Lemma (ensures x `extends` y /\ Cons? x /\ Cons? y ==> Cons?.hd y `q` Cons?.hd x) [SMTPat (x `extends` y)] = match x with | [] -> () | _::tl -> extends_related_head tl y (** Finally, we can have our fully-fledged PCM from the preorder *) let pcm_of_preorder (#a: Type u#a) (q:preorder a) : pcm (hist q) = { p = p q; comm = comm_op q; assoc = (fun _ _ _ -> ()); assoc_r = (fun _ _ _ -> ()); is_unit = (fun _ -> ()); refine = (fun _ -> True) } (***** Using the preorder *) (** We check that the preorder derived from the PCM derived from the preorder satisfies the same properties as the original preorder. Here, we get back history extension from frame-preserving updates. *) let frame_preserving_q_aux (#a : Type u#a) (q:preorder a) (x y:hist q) (z:hist q) : Lemma (requires (frame_preserving (pcm_of_preorder q) x y /\ compatible (pcm_of_preorder q) x z)) (ensures (y `extends` z)) = () (** A non-empty history *) let vhist (#a: Type u#a) (q:preorder a) = h:hist q{Cons? h} (** Get the current value from an history *) let curval (#a: Type u#a) (#q:preorder a) (v:vhist q) = Cons?.hd v (** Given a frame-preserving update from [x] to [y] for any value of resource [z] (compatible with [x]) the new value [y] advances the history [z] in a preorder respecting manner *) let frame_preserving_q (#a: Type u#a) (q:preorder a) (x y:vhist q) : Lemma (requires frame_preserving (pcm_of_preorder q) x y) (ensures (forall (z:hist q). compatible (pcm_of_preorder q) x z ==> curval z `q` curval y)) = () (** Still given a frame-preserving update from [x] to [y], this update extends the history *) let frame_preserving_extends (#a: Type u#a) (q:preorder a) (x y:vhist q) : Lemma (requires frame_preserving (pcm_of_preorder q) x y) (ensures (forall (z:hist q). compatible (pcm_of_preorder q) x z ==> y `extends` z)) = () (** Helper function that flips a preoder *) let flip (#a: Type u#a) (p:preorder a) : preorder a = fun x y -> p y x (** What is the preorder induced from the PCM induced by preorder [q]? It turns out that it is the flipped of [q], reversed extension. *) let frame_preserving_extends2 (#a: Type u#a) (q:preorder a) (x y:hist q) : Lemma (requires frame_preserving (pcm_of_preorder q) x y) (ensures (forall (z:hist q). compatible (pcm_of_preorder q) x z ==> z `flip extends` y)) [SMTPat (frame_preserving (pcm_of_preorder q) x y)] = () #push-options "--warn_error -271" let pcm_of_preorder_induces_extends (#a: Type u#a) (q:preorder a) : Lemma (induces_preorder (pcm_of_preorder q) (flip extends)) = let fp_full (x y:hist q) (f:frame_preserving_upd (pcm_of_preorder q) x y) (v:hist q) : Lemma (requires compatible (pcm_of_preorder q) x v) (ensures extends (f v) v) [SMTPat ()] = assert (composable (pcm_of_preorder q) x v) in () #pop-options let extend_history (#a:Type u#a) (#q:preorder a) (h0:vhist q) (v:a{q (curval h0) v}) : h1:vhist q{h1 `extends` h0} = v :: h0 let property (a:Type) = a -> prop let stable_property (#a:Type) (pcm:pcm a) = fact:property a { FStar.Preorder.stable fact (preorder_of_pcm pcm) } let fact_valid_compat (#a:Type) (#pcm:pcm a) (fact:stable_property pcm) (v:a) = forall z. compatible pcm v z ==> fact z noeq type history (a:Type) (p:preorder a) = | Witnessed : hist p -> history a p | Current : h:vhist p -> f:perm -> history a p let hval_tot #a #p (h:history a p{Current? h}) : a = match h with | Current h _ -> curval h
{ "checked_file": "/", "dependencies": [ "PulseCore.FractionalPermission.fst.checked", "prims.fst.checked", "FStar.Real.fsti.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked", "FStar.List.Tot.fst.checked", "FStar.IndefiniteDescription.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "PulseCore.Preorder.fst" }
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Real", "short_module": null }, { "abbrev": false, "full_module": "PulseCore.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "FStar.Preorder", "short_module": null }, { "abbrev": false, "full_module": "FStar.PCM", "short_module": null }, { "abbrev": false, "full_module": "PulseCore", "short_module": null }, { "abbrev": false, "full_module": "PulseCore", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
h: PulseCore.Preorder.history a p {Current? h} -> FStar.Ghost.erased a
Prims.Tot
[ "total" ]
[]
[ "FStar.Preorder.preorder", "PulseCore.Preorder.history", "Prims.b2t", "PulseCore.Preorder.uu___is_Current", "FStar.Ghost.hide", "PulseCore.Preorder.hval_tot", "FStar.Ghost.erased" ]
[]
false
false
false
false
false
let hval #a #p (h: history a p {Current? h}) : Ghost.erased a =
hval_tot h
false
PulseCore.Preorder.fst
PulseCore.Preorder.p_op_extends
val p_op_extends (#a: Type u#a) (q: preorder a) (x: hist q) (y: hist q {p_composable q x y}) : Lemma (ensures ((p_op q x y) `extends` x /\ (p_op q x y) `extends` y /\ (p_op q x y == x \/ p_op q x y == y))) [SMTPat (p_op q x y)]
val p_op_extends (#a: Type u#a) (q: preorder a) (x: hist q) (y: hist q {p_composable q x y}) : Lemma (ensures ((p_op q x y) `extends` x /\ (p_op q x y) `extends` y /\ (p_op q x y == x \/ p_op q x y == y))) [SMTPat (p_op q x y)]
let p_op_extends (#a: Type u#a) (q:preorder a) (x:hist q) (y:hist q{p_composable q x y}) : Lemma (ensures (p_op q x y `extends` x /\ p_op q x y `extends` y /\ (p_op q x y == x \/ p_op q x y == y))) [SMTPat (p_op q x y)] = extends_length_eq x y; extends_length_eq y x
{ "file_name": "lib/pulse_core/PulseCore.Preorder.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 25, "end_line": 144, "start_col": 0, "start_line": 138 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module PulseCore.Preorder open FStar.PCM open FStar.Preorder open PulseCore.FractionalPermission open FStar.Real /// This module explores the connection between PCM and preorders. More specifically, we show here /// that any PCM induces a preorder relation, characterized by frame-preservation for any updates. /// /// Furthermore, we also consider the reverse relationship where we derive a PCM for any preorder, /// by taking as elements of the PCM the trace of all the states of the element. (**** PCM to preoder *) (** PCM [p] induces the preorder [q] if for any frame preserving update of [x] to [y], the argument and result of the frame preserving update are related by q *) let induces_preorder (#a:Type u#a) (p:pcm a) (q:preorder a) = forall (x y:a) (f:frame_preserving_upd p x y) (v:a). p.refine v ==> compatible p x v ==> q v (f v) (** We can define a canonical preorder from any PCM by taking the quantified conjunction over all the preorders [q] induced by this PCM. *) let preorder_of_pcm (#a:Type u#a) (p:pcm a) : preorder a = fun x y -> forall (q:preorder a). induces_preorder p q ==> q x y let frame_preserving_upd_is_preorder_preserving (#a:Type u#a) (p:pcm a) (x y:a) (f:frame_preserving_upd p x y) (v_old:a{p.refine v_old /\ compatible p x v_old}) : Lemma ((preorder_of_pcm p) v_old (f v_old)) = () (** This canonical preorder enjoys the nice property that it preserves fact stability of any induced preorder *) let stability (#a: Type u#a) (fact:a -> prop) (q:preorder a) (p:pcm a) : Lemma (requires stable fact q /\ induces_preorder p q) (ensures stable fact (preorder_of_pcm p)) = () let stable_compatiblity (#a:Type u#a) (fact: a -> prop) (p:pcm a) (v v0 v1:a) : Lemma (requires stable fact (preorder_of_pcm p) /\ p.refine v0 /\ fact v0 /\ p.refine v1 /\ frame_preserving p v v1 /\ compatible p v v0) (ensures fact v1) = let f : frame_preserving_upd p v v1 = frame_preserving_val_to_fp_upd p v v1 in frame_preserving_upd_is_preorder_preserving p v v1 f v0 (**** Preorder to PCM *) (***** Building the preorder *) (** This predicate tells that the list [l] can represent a trace of elements whose evolution is compatible with the preorder [q] *) let rec qhistory #a (q:preorder a) (l:list a) = match l with | [] | [_] -> True | x::y::tl -> y `q` x /\ qhistory q (y::tl) (** The history of a preorder is the type of all the traces compatible with that preorder *) let hist (#a: Type u#a) (q:preorder a) = l:list a{qhistory q l} (** Two compatible traces can extend each other *) let rec extends' (#a: Type u#a) (#q:preorder a) (h0 h1:hist q) = h0 == h1 \/ (Cons? h0 /\ extends' (Cons?.tl h0) h1) (** This extension relation is transitive *) let rec extends_trans #a (#q:preorder a) (x y z:hist q) : Lemma (x `extends'` y /\ y `extends'` z ==> x `extends'` z) [SMTPat (x `extends'` y); SMTPat (y `extends'` z)] = match x with | [] -> () | _::tl -> extends_trans tl y z (** And it is also reflexive, so extensibility on traces is a preorder on traces *) let extends (#a: Type u#a) (#q:preorder a) : preorder (hist q) = extends' module L = FStar.List.Tot (** If [h0] extends by [h1], then the length of [h0] is superior *) let rec extends_length_eq (#a: Type u#a) (#q:preorder a) (h0 h1:hist q) : Lemma (ensures (extends h0 h1 ==> h0 == h1 \/ L.length h0 > L.length h1)) [SMTPat (extends h0 h1)] = match h0 with | [] -> () | hd::tl -> extends_length_eq tl h1 (** We build our relation of composability for traces by reflexing the extension to ensure symmetry *) let p_composable (#a: Type u#a) (q:preorder a) : symrel (hist q) = fun x y -> extends x y \/ extends y x (** The operation for the PCM is to return the full trace of two extensible traces *) let p_op (#a: Type u#a) (q:preorder a) (x:hist q) (y:hist q{p_composable q x y}) : hist q = if L.length x >= L.length y then x else if L.length x = L.length y then (assert (x == y); x) else y
{ "checked_file": "/", "dependencies": [ "PulseCore.FractionalPermission.fst.checked", "prims.fst.checked", "FStar.Real.fsti.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked", "FStar.List.Tot.fst.checked", "FStar.IndefiniteDescription.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "PulseCore.Preorder.fst" }
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Real", "short_module": null }, { "abbrev": false, "full_module": "PulseCore.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "FStar.Preorder", "short_module": null }, { "abbrev": false, "full_module": "FStar.PCM", "short_module": null }, { "abbrev": false, "full_module": "PulseCore", "short_module": null }, { "abbrev": false, "full_module": "PulseCore", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
q: FStar.Preorder.preorder a -> x: PulseCore.Preorder.hist q -> y: PulseCore.Preorder.hist q {PulseCore.Preorder.p_composable q x y} -> FStar.Pervasives.Lemma (ensures PulseCore.Preorder.extends (PulseCore.Preorder.p_op q x y) x /\ PulseCore.Preorder.extends (PulseCore.Preorder.p_op q x y) y /\ (PulseCore.Preorder.p_op q x y == x \/ PulseCore.Preorder.p_op q x y == y)) [SMTPat (PulseCore.Preorder.p_op q x y)]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "FStar.Preorder.preorder", "PulseCore.Preorder.hist", "PulseCore.Preorder.p_composable", "PulseCore.Preorder.extends_length_eq", "Prims.unit", "Prims.l_True", "Prims.squash", "Prims.l_and", "PulseCore.Preorder.extends", "PulseCore.Preorder.p_op", "Prims.l_or", "Prims.eq2", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat", "Prims.Nil" ]
[]
true
false
true
false
false
let p_op_extends (#a: Type u#a) (q: preorder a) (x: hist q) (y: hist q {p_composable q x y}) : Lemma (ensures ((p_op q x y) `extends` x /\ (p_op q x y) `extends` y /\ (p_op q x y == x \/ p_op q x y == y))) [SMTPat (p_op q x y)] =
extends_length_eq x y; extends_length_eq y x
false
Hacl.HPKE.Interface.AEAD.fst
Hacl.HPKE.Interface.AEAD.aead_decrypt_cp32
val aead_decrypt_cp32 : aead_decrypt_st (S.Seal AEAD.CHACHA20_POLY1305)
val aead_decrypt_cp32 : aead_decrypt_st (S.Seal AEAD.CHACHA20_POLY1305)
let aead_decrypt_cp32 = fun _ key nonce alen aad len input output -> let cipher = sub output 0ul len in let tag = sub output len 16ul in Hacl.Chacha20Poly1305_32.decrypt input cipher len aad alen key nonce tag
{ "file_name": "code/hpke/Hacl.HPKE.Interface.AEAD.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 76, "end_line": 32, "start_col": 0, "start_line": 28 }
module Hacl.HPKE.Interface.AEAD open FStar.HyperStack open FStar.HyperStack.All open Lib.Buffer friend Spec.Agile.AEAD /// These two functions will never be extracted, they are only an interface /// boundary for the tactic performing instantiations. /// In other files, it is exposed as an assume val, but for AEAD, we need an fsti /// since we need to friend Spec.Agile.AEAD to perform the instantiations below, /// and assume val are forbidden in interface files let aead_encrypt #cs = admit() let aead_decrypt #cs = admit() #set-options "--z3rlimit 60 --fuel 0 --ifuel 0" inline_for_extraction noextract let aead_encrypt_cp32 = fun _ key nonce alen aad len input output -> let cipher = sub output 0ul len in let tag = sub output len 16ul in Hacl.Chacha20Poly1305_32.encrypt cipher tag input len aad alen key nonce
{ "checked_file": "/", "dependencies": [ "Spec.Agile.AEAD.fst.checked", "prims.fst.checked", "Lib.Buffer.fsti.checked", "Hacl.Chacha20Poly1305_32.fst.checked", "Hacl.Chacha20Poly1305_256.fst.checked", "Hacl.Chacha20Poly1305_128.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": true, "source_file": "Hacl.HPKE.Interface.AEAD.fst" }
[ { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": true, "full_module": "Spec.Agile.AEAD", "short_module": "AEAD" }, { "abbrev": true, "full_module": "Spec.Agile.HPKE", "short_module": "S" }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "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.HPKE.Interface", "short_module": null }, { "abbrev": false, "full_module": "Hacl.HPKE.Interface", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 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": 60, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Hacl.HPKE.Interface.AEAD.aead_decrypt_st (Spec.Agile.HPKE.Seal Spec.Agile.AEAD.CHACHA20_POLY1305)
Prims.Tot
[ "total" ]
[]
[ "Prims.squash", "Prims.l_and", "Prims.b2t", "Spec.Agile.HPKE.uu___is_Seal", "Spec.Agile.HPKE.Seal", "Spec.Agile.AEAD.CHACHA20_POLY1305", "Spec.Agile.HPKE.is_valid_aead", "Hacl.HPKE.Interface.AEAD.kv", "Spec.Agile.HPKE.__proj__Seal__item__alg", "Hacl.HPKE.Interface.AEAD.iv", "Lib.IntTypes.size_t", "Prims.op_LessThanOrEqual", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Spec.Agile.AEAD.max_length", "Lib.Buffer.lbuffer", "Lib.IntTypes.uint8", "Prims.op_Addition", "Lib.IntTypes.max_size_t", "Lib.IntTypes.size", "Hacl.Chacha20Poly1305_32.decrypt", "FStar.UInt32.t", "Lib.Buffer.lbuffer_t", "Lib.Buffer.MUT", "Lib.IntTypes.int_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "FStar.UInt32.uint_to_t", "Lib.Buffer.sub", "FStar.UInt32.__uint_to_t" ]
[]
false
false
false
true
false
let aead_decrypt_cp32 =
fun _ key nonce alen aad len input output -> let cipher = sub output 0ul len in let tag = sub output len 16ul in Hacl.Chacha20Poly1305_32.decrypt input cipher len aad alen key nonce tag
false
PulseCore.Preorder.fst
PulseCore.Preorder.comm_op
val comm_op (#a: Type u#a) (q: preorder a) (x: hist q) (y: hist q {p_composable q x y}) : Lemma (p_op q x y == p_op q y x)
val comm_op (#a: Type u#a) (q: preorder a) (x: hist q) (y: hist q {p_composable q x y}) : Lemma (p_op q x y == p_op q y x)
let comm_op (#a: Type u#a) (q:preorder a) (x:hist q) (y:hist q{p_composable q x y}) : Lemma (p_op q x y == p_op q y x) = extends_length_eq x y; extends_length_eq y x
{ "file_name": "lib/pulse_core/PulseCore.Preorder.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 25, "end_line": 171, "start_col": 0, "start_line": 168 }
(* 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 PulseCore.Preorder open FStar.PCM open FStar.Preorder open PulseCore.FractionalPermission open FStar.Real /// This module explores the connection between PCM and preorders. More specifically, we show here /// that any PCM induces a preorder relation, characterized by frame-preservation for any updates. /// /// Furthermore, we also consider the reverse relationship where we derive a PCM for any preorder, /// by taking as elements of the PCM the trace of all the states of the element. (**** PCM to preoder *) (** PCM [p] induces the preorder [q] if for any frame preserving update of [x] to [y], the argument and result of the frame preserving update are related by q *) let induces_preorder (#a:Type u#a) (p:pcm a) (q:preorder a) = forall (x y:a) (f:frame_preserving_upd p x y) (v:a). p.refine v ==> compatible p x v ==> q v (f v) (** We can define a canonical preorder from any PCM by taking the quantified conjunction over all the preorders [q] induced by this PCM. *) let preorder_of_pcm (#a:Type u#a) (p:pcm a) : preorder a = fun x y -> forall (q:preorder a). induces_preorder p q ==> q x y let frame_preserving_upd_is_preorder_preserving (#a:Type u#a) (p:pcm a) (x y:a) (f:frame_preserving_upd p x y) (v_old:a{p.refine v_old /\ compatible p x v_old}) : Lemma ((preorder_of_pcm p) v_old (f v_old)) = () (** This canonical preorder enjoys the nice property that it preserves fact stability of any induced preorder *) let stability (#a: Type u#a) (fact:a -> prop) (q:preorder a) (p:pcm a) : Lemma (requires stable fact q /\ induces_preorder p q) (ensures stable fact (preorder_of_pcm p)) = () let stable_compatiblity (#a:Type u#a) (fact: a -> prop) (p:pcm a) (v v0 v1:a) : Lemma (requires stable fact (preorder_of_pcm p) /\ p.refine v0 /\ fact v0 /\ p.refine v1 /\ frame_preserving p v v1 /\ compatible p v v0) (ensures fact v1) = let f : frame_preserving_upd p v v1 = frame_preserving_val_to_fp_upd p v v1 in frame_preserving_upd_is_preorder_preserving p v v1 f v0 (**** Preorder to PCM *) (***** Building the preorder *) (** This predicate tells that the list [l] can represent a trace of elements whose evolution is compatible with the preorder [q] *) let rec qhistory #a (q:preorder a) (l:list a) = match l with | [] | [_] -> True | x::y::tl -> y `q` x /\ qhistory q (y::tl) (** The history of a preorder is the type of all the traces compatible with that preorder *) let hist (#a: Type u#a) (q:preorder a) = l:list a{qhistory q l} (** Two compatible traces can extend each other *) let rec extends' (#a: Type u#a) (#q:preorder a) (h0 h1:hist q) = h0 == h1 \/ (Cons? h0 /\ extends' (Cons?.tl h0) h1) (** This extension relation is transitive *) let rec extends_trans #a (#q:preorder a) (x y z:hist q) : Lemma (x `extends'` y /\ y `extends'` z ==> x `extends'` z) [SMTPat (x `extends'` y); SMTPat (y `extends'` z)] = match x with | [] -> () | _::tl -> extends_trans tl y z (** And it is also reflexive, so extensibility on traces is a preorder on traces *) let extends (#a: Type u#a) (#q:preorder a) : preorder (hist q) = extends' module L = FStar.List.Tot (** If [h0] extends by [h1], then the length of [h0] is superior *) let rec extends_length_eq (#a: Type u#a) (#q:preorder a) (h0 h1:hist q) : Lemma (ensures (extends h0 h1 ==> h0 == h1 \/ L.length h0 > L.length h1)) [SMTPat (extends h0 h1)] = match h0 with | [] -> () | hd::tl -> extends_length_eq tl h1 (** We build our relation of composability for traces by reflexing the extension to ensure symmetry *) let p_composable (#a: Type u#a) (q:preorder a) : symrel (hist q) = fun x y -> extends x y \/ extends y x (** The operation for the PCM is to return the full trace of two extensible traces *) let p_op (#a: Type u#a) (q:preorder a) (x:hist q) (y:hist q{p_composable q x y}) : hist q = if L.length x >= L.length y then x else if L.length x = L.length y then (assert (x == y); x) else y (** The operation actually implements extension *) let p_op_extends (#a: Type u#a) (q:preorder a) (x:hist q) (y:hist q{p_composable q x y}) : Lemma (ensures (p_op q x y `extends` x /\ p_op q x y `extends` y /\ (p_op q x y == x \/ p_op q x y == y))) [SMTPat (p_op q x y)] = extends_length_eq x y; extends_length_eq y x (** And the empty trace is the unit element *) let rec p_op_nil (#a: Type u#a) (q:preorder a) (x:hist q) : Lemma (ensures (p_composable q x [] /\ p_op q x [] == x)) [SMTPat (p_composable q x [])] = match x with | [] -> () | _::tl -> p_op_nil q tl (** We can finally define our PCM with these operations *) let p (#a: Type u#a) (q:preorder a) : pcm' (hist q) = { composable = p_composable q; op = p_op q; one = [] } (** Composability is commutative *) let comm (#a: Type u#a) (q:preorder a) (x y:hist q) : Lemma (requires p_composable q x y) (ensures p_composable q y x) = ()
{ "checked_file": "/", "dependencies": [ "PulseCore.FractionalPermission.fst.checked", "prims.fst.checked", "FStar.Real.fsti.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked", "FStar.List.Tot.fst.checked", "FStar.IndefiniteDescription.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "PulseCore.Preorder.fst" }
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Real", "short_module": null }, { "abbrev": false, "full_module": "PulseCore.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "FStar.Preorder", "short_module": null }, { "abbrev": false, "full_module": "FStar.PCM", "short_module": null }, { "abbrev": false, "full_module": "PulseCore", "short_module": null }, { "abbrev": false, "full_module": "PulseCore", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
q: FStar.Preorder.preorder a -> x: PulseCore.Preorder.hist q -> y: PulseCore.Preorder.hist q {PulseCore.Preorder.p_composable q x y} -> FStar.Pervasives.Lemma (ensures PulseCore.Preorder.p_op q x y == PulseCore.Preorder.p_op q y x)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "FStar.Preorder.preorder", "PulseCore.Preorder.hist", "PulseCore.Preorder.p_composable", "PulseCore.Preorder.extends_length_eq", "Prims.unit", "Prims.l_True", "Prims.squash", "Prims.eq2", "PulseCore.Preorder.p_op", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
true
false
true
false
false
let comm_op (#a: Type u#a) (q: preorder a) (x: hist q) (y: hist q {p_composable q x y}) : Lemma (p_op q x y == p_op q y x) =
extends_length_eq x y; extends_length_eq y x
false
Hacl.HPKE.Interface.AEAD.fst
Hacl.HPKE.Interface.AEAD.aead_decrypt_cp256
val aead_decrypt_cp256 : aead_decrypt_st (S.Seal AEAD.CHACHA20_POLY1305)
val aead_decrypt_cp256 : aead_decrypt_st (S.Seal AEAD.CHACHA20_POLY1305)
let aead_decrypt_cp256 = fun _ key nonce alen aad len input output -> let cipher = sub output 0ul len in let tag = sub output len 16ul in Hacl.Chacha20Poly1305_256.decrypt input cipher len aad alen key nonce tag
{ "file_name": "code/hpke/Hacl.HPKE.Interface.AEAD.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 77, "end_line": 60, "start_col": 0, "start_line": 56 }
module Hacl.HPKE.Interface.AEAD open FStar.HyperStack open FStar.HyperStack.All open Lib.Buffer friend Spec.Agile.AEAD /// These two functions will never be extracted, they are only an interface /// boundary for the tactic performing instantiations. /// In other files, it is exposed as an assume val, but for AEAD, we need an fsti /// since we need to friend Spec.Agile.AEAD to perform the instantiations below, /// and assume val are forbidden in interface files let aead_encrypt #cs = admit() let aead_decrypt #cs = admit() #set-options "--z3rlimit 60 --fuel 0 --ifuel 0" inline_for_extraction noextract let aead_encrypt_cp32 = fun _ key nonce alen aad len input output -> let cipher = sub output 0ul len in let tag = sub output len 16ul in Hacl.Chacha20Poly1305_32.encrypt cipher tag input len aad alen key nonce inline_for_extraction noextract let aead_decrypt_cp32 = fun _ key nonce alen aad len input output -> let cipher = sub output 0ul len in let tag = sub output len 16ul in Hacl.Chacha20Poly1305_32.decrypt input cipher len aad alen key nonce tag inline_for_extraction noextract let aead_encrypt_cp128 = fun _ key nonce alen aad len input output -> let cipher = sub output 0ul len in let tag = sub output len 16ul in Hacl.Chacha20Poly1305_128.encrypt cipher tag input len aad alen key nonce inline_for_extraction noextract let aead_decrypt_cp128 = fun _ key nonce alen aad len input output -> let cipher = sub output 0ul len in let tag = sub output len 16ul in Hacl.Chacha20Poly1305_128.decrypt input cipher len aad alen key nonce tag inline_for_extraction noextract let aead_encrypt_cp256 = fun _ key nonce alen aad len input output -> let cipher = sub output 0ul len in let tag = sub output len 16ul in Hacl.Chacha20Poly1305_256.encrypt cipher tag input len aad alen key nonce
{ "checked_file": "/", "dependencies": [ "Spec.Agile.AEAD.fst.checked", "prims.fst.checked", "Lib.Buffer.fsti.checked", "Hacl.Chacha20Poly1305_32.fst.checked", "Hacl.Chacha20Poly1305_256.fst.checked", "Hacl.Chacha20Poly1305_128.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": true, "source_file": "Hacl.HPKE.Interface.AEAD.fst" }
[ { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": true, "full_module": "Spec.Agile.AEAD", "short_module": "AEAD" }, { "abbrev": true, "full_module": "Spec.Agile.HPKE", "short_module": "S" }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "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.HPKE.Interface", "short_module": null }, { "abbrev": false, "full_module": "Hacl.HPKE.Interface", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 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": 60, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Hacl.HPKE.Interface.AEAD.aead_decrypt_st (Spec.Agile.HPKE.Seal Spec.Agile.AEAD.CHACHA20_POLY1305)
Prims.Tot
[ "total" ]
[]
[ "Prims.squash", "Prims.l_and", "Prims.b2t", "Spec.Agile.HPKE.uu___is_Seal", "Spec.Agile.HPKE.Seal", "Spec.Agile.AEAD.CHACHA20_POLY1305", "Spec.Agile.HPKE.is_valid_aead", "Hacl.HPKE.Interface.AEAD.kv", "Spec.Agile.HPKE.__proj__Seal__item__alg", "Hacl.HPKE.Interface.AEAD.iv", "Lib.IntTypes.size_t", "Prims.op_LessThanOrEqual", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Spec.Agile.AEAD.max_length", "Lib.Buffer.lbuffer", "Lib.IntTypes.uint8", "Prims.op_Addition", "Lib.IntTypes.max_size_t", "Lib.IntTypes.size", "Hacl.Chacha20Poly1305_256.decrypt", "FStar.UInt32.t", "Lib.Buffer.lbuffer_t", "Lib.Buffer.MUT", "Lib.IntTypes.int_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "FStar.UInt32.uint_to_t", "Lib.Buffer.sub", "FStar.UInt32.__uint_to_t" ]
[]
false
false
false
true
false
let aead_decrypt_cp256 =
fun _ key nonce alen aad len input output -> let cipher = sub output 0ul len in let tag = sub output len 16ul in Hacl.Chacha20Poly1305_256.decrypt input cipher len aad alen key nonce tag
false
PulseCore.Preorder.fst
PulseCore.Preorder.curval
val curval : v: PulseCore.Preorder.vhist q -> a
let curval (#a: Type u#a) (#q:preorder a) (v:vhist q) = Cons?.hd v
{ "file_name": "lib/pulse_core/PulseCore.Preorder.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 66, "end_line": 220, "start_col": 0, "start_line": 220 }
(* 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 PulseCore.Preorder open FStar.PCM open FStar.Preorder open PulseCore.FractionalPermission open FStar.Real /// This module explores the connection between PCM and preorders. More specifically, we show here /// that any PCM induces a preorder relation, characterized by frame-preservation for any updates. /// /// Furthermore, we also consider the reverse relationship where we derive a PCM for any preorder, /// by taking as elements of the PCM the trace of all the states of the element. (**** PCM to preoder *) (** PCM [p] induces the preorder [q] if for any frame preserving update of [x] to [y], the argument and result of the frame preserving update are related by q *) let induces_preorder (#a:Type u#a) (p:pcm a) (q:preorder a) = forall (x y:a) (f:frame_preserving_upd p x y) (v:a). p.refine v ==> compatible p x v ==> q v (f v) (** We can define a canonical preorder from any PCM by taking the quantified conjunction over all the preorders [q] induced by this PCM. *) let preorder_of_pcm (#a:Type u#a) (p:pcm a) : preorder a = fun x y -> forall (q:preorder a). induces_preorder p q ==> q x y let frame_preserving_upd_is_preorder_preserving (#a:Type u#a) (p:pcm a) (x y:a) (f:frame_preserving_upd p x y) (v_old:a{p.refine v_old /\ compatible p x v_old}) : Lemma ((preorder_of_pcm p) v_old (f v_old)) = () (** This canonical preorder enjoys the nice property that it preserves fact stability of any induced preorder *) let stability (#a: Type u#a) (fact:a -> prop) (q:preorder a) (p:pcm a) : Lemma (requires stable fact q /\ induces_preorder p q) (ensures stable fact (preorder_of_pcm p)) = () let stable_compatiblity (#a:Type u#a) (fact: a -> prop) (p:pcm a) (v v0 v1:a) : Lemma (requires stable fact (preorder_of_pcm p) /\ p.refine v0 /\ fact v0 /\ p.refine v1 /\ frame_preserving p v v1 /\ compatible p v v0) (ensures fact v1) = let f : frame_preserving_upd p v v1 = frame_preserving_val_to_fp_upd p v v1 in frame_preserving_upd_is_preorder_preserving p v v1 f v0 (**** Preorder to PCM *) (***** Building the preorder *) (** This predicate tells that the list [l] can represent a trace of elements whose evolution is compatible with the preorder [q] *) let rec qhistory #a (q:preorder a) (l:list a) = match l with | [] | [_] -> True | x::y::tl -> y `q` x /\ qhistory q (y::tl) (** The history of a preorder is the type of all the traces compatible with that preorder *) let hist (#a: Type u#a) (q:preorder a) = l:list a{qhistory q l} (** Two compatible traces can extend each other *) let rec extends' (#a: Type u#a) (#q:preorder a) (h0 h1:hist q) = h0 == h1 \/ (Cons? h0 /\ extends' (Cons?.tl h0) h1) (** This extension relation is transitive *) let rec extends_trans #a (#q:preorder a) (x y z:hist q) : Lemma (x `extends'` y /\ y `extends'` z ==> x `extends'` z) [SMTPat (x `extends'` y); SMTPat (y `extends'` z)] = match x with | [] -> () | _::tl -> extends_trans tl y z (** And it is also reflexive, so extensibility on traces is a preorder on traces *) let extends (#a: Type u#a) (#q:preorder a) : preorder (hist q) = extends' module L = FStar.List.Tot (** If [h0] extends by [h1], then the length of [h0] is superior *) let rec extends_length_eq (#a: Type u#a) (#q:preorder a) (h0 h1:hist q) : Lemma (ensures (extends h0 h1 ==> h0 == h1 \/ L.length h0 > L.length h1)) [SMTPat (extends h0 h1)] = match h0 with | [] -> () | hd::tl -> extends_length_eq tl h1 (** We build our relation of composability for traces by reflexing the extension to ensure symmetry *) let p_composable (#a: Type u#a) (q:preorder a) : symrel (hist q) = fun x y -> extends x y \/ extends y x (** The operation for the PCM is to return the full trace of two extensible traces *) let p_op (#a: Type u#a) (q:preorder a) (x:hist q) (y:hist q{p_composable q x y}) : hist q = if L.length x >= L.length y then x else if L.length x = L.length y then (assert (x == y); x) else y (** The operation actually implements extension *) let p_op_extends (#a: Type u#a) (q:preorder a) (x:hist q) (y:hist q{p_composable q x y}) : Lemma (ensures (p_op q x y `extends` x /\ p_op q x y `extends` y /\ (p_op q x y == x \/ p_op q x y == y))) [SMTPat (p_op q x y)] = extends_length_eq x y; extends_length_eq y x (** And the empty trace is the unit element *) let rec p_op_nil (#a: Type u#a) (q:preorder a) (x:hist q) : Lemma (ensures (p_composable q x [] /\ p_op q x [] == x)) [SMTPat (p_composable q x [])] = match x with | [] -> () | _::tl -> p_op_nil q tl (** We can finally define our PCM with these operations *) let p (#a: Type u#a) (q:preorder a) : pcm' (hist q) = { composable = p_composable q; op = p_op q; one = [] } (** Composability is commutative *) let comm (#a: Type u#a) (q:preorder a) (x y:hist q) : Lemma (requires p_composable q x y) (ensures p_composable q y x) = () (** As well as the compose operation *) let comm_op (#a: Type u#a) (q:preorder a) (x:hist q) (y:hist q{p_composable q x y}) : Lemma (p_op q x y == p_op q y x) = extends_length_eq x y; extends_length_eq y x (** If [z] extends [x] and [y], then [x] and [y] are extending one or another *) let rec extends_disjunction (#a: Type u#a) (#q:preorder a) (x y z:hist q) : Lemma (z `extends` x /\ z `extends` y ==> x `extends` y \/ y `extends` x) [SMTPat (z `extends` x); SMTPat (z `extends` y)] = match z with | [] -> () | _::tl -> extends_disjunction x y tl (** If [x] extends [y], then the two heads of the traces are still related by the preorder *) let rec extends_related_head (#a: Type u#a) (#q:preorder a) (x y:hist q) : Lemma (ensures x `extends` y /\ Cons? x /\ Cons? y ==> Cons?.hd y `q` Cons?.hd x) [SMTPat (x `extends` y)] = match x with | [] -> () | _::tl -> extends_related_head tl y (** Finally, we can have our fully-fledged PCM from the preorder *) let pcm_of_preorder (#a: Type u#a) (q:preorder a) : pcm (hist q) = { p = p q; comm = comm_op q; assoc = (fun _ _ _ -> ()); assoc_r = (fun _ _ _ -> ()); is_unit = (fun _ -> ()); refine = (fun _ -> True) } (***** Using the preorder *) (** We check that the preorder derived from the PCM derived from the preorder satisfies the same properties as the original preorder. Here, we get back history extension from frame-preserving updates. *) let frame_preserving_q_aux (#a : Type u#a) (q:preorder a) (x y:hist q) (z:hist q) : Lemma (requires (frame_preserving (pcm_of_preorder q) x y /\ compatible (pcm_of_preorder q) x z)) (ensures (y `extends` z)) = () (** A non-empty history *) let vhist (#a: Type u#a) (q:preorder a) = h:hist q{Cons? h}
{ "checked_file": "/", "dependencies": [ "PulseCore.FractionalPermission.fst.checked", "prims.fst.checked", "FStar.Real.fsti.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked", "FStar.List.Tot.fst.checked", "FStar.IndefiniteDescription.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "PulseCore.Preorder.fst" }
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Real", "short_module": null }, { "abbrev": false, "full_module": "PulseCore.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "FStar.Preorder", "short_module": null }, { "abbrev": false, "full_module": "FStar.PCM", "short_module": null }, { "abbrev": false, "full_module": "PulseCore", "short_module": null }, { "abbrev": false, "full_module": "PulseCore", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
v: PulseCore.Preorder.vhist q -> a
Prims.Tot
[ "total" ]
[]
[ "FStar.Preorder.preorder", "PulseCore.Preorder.vhist", "Prims.__proj__Cons__item__hd" ]
[]
false
false
false
false
false
let curval (#a: Type u#a) (#q: preorder a) (v: vhist q) =
Cons?.hd v
false
Hacl.Ed25519.fst
Hacl.Ed25519.sign_expanded
val sign_expanded: signature:lbuffer uint8 64ul -> expanded_keys:lbuffer uint8 96ul -> msg_len:size_t -> msg:lbuffer uint8 msg_len -> Stack unit (requires fun h -> live h signature /\ live h msg /\ live h expanded_keys /\ disjoint signature msg /\ disjoint signature expanded_keys) (ensures fun h0 _ h1 -> modifies (loc signature) h0 h1 /\ as_seq h1 signature == Spec.Ed25519.sign_expanded (as_seq h0 (gsub expanded_keys 0ul 32ul)) (as_seq h0 (gsub expanded_keys 32ul 32ul)) (as_seq h0 (gsub expanded_keys 64ul 32ul)) (as_seq h0 msg))
val sign_expanded: signature:lbuffer uint8 64ul -> expanded_keys:lbuffer uint8 96ul -> msg_len:size_t -> msg:lbuffer uint8 msg_len -> Stack unit (requires fun h -> live h signature /\ live h msg /\ live h expanded_keys /\ disjoint signature msg /\ disjoint signature expanded_keys) (ensures fun h0 _ h1 -> modifies (loc signature) h0 h1 /\ as_seq h1 signature == Spec.Ed25519.sign_expanded (as_seq h0 (gsub expanded_keys 0ul 32ul)) (as_seq h0 (gsub expanded_keys 32ul 32ul)) (as_seq h0 (gsub expanded_keys 64ul 32ul)) (as_seq h0 msg))
let sign_expanded signature expanded_keys msg_len msg = Hacl.Impl.Ed25519.Sign.sign_expanded signature expanded_keys msg_len msg
{ "file_name": "code/ed25519/Hacl.Ed25519.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 74, "end_line": 50, "start_col": 0, "start_line": 49 }
module Hacl.Ed25519 module ST = FStar.HyperStack.ST open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer module S = Spec.Ed25519 #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" val secret_expand: expanded:lbuffer uint8 64ul -> secret:lbuffer uint8 32ul -> Stack unit (requires fun h -> live h expanded /\ live h secret /\ disjoint expanded secret) (ensures fun h0 _ h1 -> modifies (loc expanded) h0 h1 /\ (let a, prefix = S.secret_expand (as_seq h0 secret) in as_seq h1 (gsub expanded 0ul 32ul) == a /\ as_seq h1 (gsub expanded 32ul 32ul) == prefix)) [@CInline] let secret_expand expanded secret = assert_norm (pow2 32 <= pow2 125 - 1); Hacl.Streaming.SHA2.hash_512 expanded secret 32ul; let h_low = sub expanded 0ul 32ul in let h_low0 = h_low.( 0ul) in let h_low31 = h_low.(31ul) in h_low.( 0ul) <- h_low0 &. u8 0xf8; h_low.(31ul) <- (h_low31 &. u8 127) |. u8 64 let secret_to_public public_key private_key = push_frame (); let expanded_secret = create 64ul (u8 0) in secret_expand expanded_secret private_key; let a = sub expanded_secret 0ul 32ul in Hacl.Impl.Ed25519.Sign.point_mul_g_compress public_key a; pop_frame () let expand_keys expanded_keys private_key = let public_key = sub expanded_keys 0ul 32ul in let s_prefix = sub expanded_keys 32ul 64ul in let s = sub expanded_keys 32ul 32ul in secret_expand s_prefix private_key; Hacl.Impl.Ed25519.Sign.point_mul_g_compress public_key s
{ "checked_file": "/", "dependencies": [ "Spec.Ed25519.fst.checked", "prims.fst.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.SHA2.fst.checked", "Hacl.Impl.Ed25519.Verify.fst.checked", "Hacl.Impl.Ed25519.Sign.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked" ], "interface_file": true, "source_file": "Hacl.Ed25519.fst" }
[ { "abbrev": true, "full_module": "Spec.Ed25519", "short_module": "S" }, { "abbrev": false, "full_module": "FStar.Mul", "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.HyperStack.All", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
signature: Lib.Buffer.lbuffer Lib.IntTypes.uint8 64ul -> expanded_keys: Lib.Buffer.lbuffer Lib.IntTypes.uint8 96ul -> msg_len: Lib.IntTypes.size_t -> msg: Lib.Buffer.lbuffer Lib.IntTypes.uint8 msg_len -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Lib.Buffer.lbuffer", "Lib.IntTypes.uint8", "FStar.UInt32.__uint_to_t", "Lib.IntTypes.size_t", "Hacl.Impl.Ed25519.Sign.sign_expanded", "Prims.unit" ]
[]
false
true
false
false
false
let sign_expanded signature expanded_keys msg_len msg =
Hacl.Impl.Ed25519.Sign.sign_expanded signature expanded_keys msg_len msg
false