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 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
BinomialQueue.fst | BinomialQueue.tree_root_is_max_aux | val tree_root_is_max_aux (d: nat) (upper_bound: key_t) (t: tree)
: Lemma (requires pow2heap_pred d upper_bound t)
(ensures max upper_bound (keys_of_tree t).ms_elems)
(decreases t) | val tree_root_is_max_aux (d: nat) (upper_bound: key_t) (t: tree)
: Lemma (requires pow2heap_pred d upper_bound t)
(ensures max upper_bound (keys_of_tree t).ms_elems)
(decreases t) | let rec tree_root_is_max_aux (d:nat) (upper_bound:key_t) (t:tree)
: Lemma
(requires pow2heap_pred d upper_bound t)
(ensures max upper_bound (keys_of_tree t).ms_elems)
(decreases t) =
match t with
| Leaf -> ()
| Internal left k right ->
tree_root_is_max_aux (d - 1) k left;
tree_root_is_max_aux (d - 1) upper_bound right | {
"file_name": "examples/data_structures/BinomialQueue.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 50,
"end_line": 546,
"start_col": 0,
"start_line": 536
} | (*
Copyright 2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Authors: Aseem Rastogi
*)
module BinomialQueue
module L = FStar.List.Tot
/// Some auxiliary lemmas
let rec last_cons (#a:Type) (x:a) (l:list a)
: Lemma
(requires Cons? l)
(ensures L.last (x::l) == L.last l)
[SMTPat (L.last (x::l))] =
match l with
| [_] -> ()
| _::tl -> last_cons x tl
/// We will maintain the priority queue as a forest
type tree =
| Leaf : tree
| Internal : tree -> key_t -> tree -> tree
/// Tree t is a complete binary tree of depth d
///
/// All its keys are <= upper_bound
///
/// If the left subtree is non-empty,
/// its root is maximum in its subtree
let rec pow2heap_pred (d:nat) (upper_bound:key_t) (t:tree) : prop =
match t with
| Leaf -> d == 0
| Internal left k right ->
0 < d /\
k <= upper_bound /\
pow2heap_pred (d - 1) k left /\
pow2heap_pred (d - 1) upper_bound right
/// A power-2-heap of depth d is an Internal tree whose right child is a Leaf,
/// and left child is a complete binary tree satisfying pow2heap_pred
/// with upper bound as the key k
let is_pow2heap (d:pos) (t:tree) : prop =
match t with
| Internal left k Leaf -> pow2heap_pred (d - 1) k left
| _ -> False
/// A list of trees is a binomial queue starting with depth d if:
type forest = list tree
let rec is_binomial_queue (d:pos) (l:forest)
: Tot prop (decreases l) =
match l with
| [] -> True
| hd::tl ->
(Leaf? hd \/ is_pow2heap d hd) /\ is_binomial_queue (d + 1) tl
/// We will also keep the binomial queue in a compact form,
/// truncating unnecessary empty trees from the forest
let is_compact (l:forest) = l == [] \/ Internal? (L.last l)
let is_priq (l:forest) = is_binomial_queue 1 l /\ is_compact l
/// The main priq type
let priq = l:forest{is_priq l}
let empty = []
/// We define a function to compact a forest
let rec all_leaf (l:forest{Cons? l}) : bool =
match l with
| [Leaf] -> true
| Leaf::tl -> all_leaf tl
| _ -> false
let rec mk_compact (l:forest) : forest =
match l with
| [] -> []
| _ ->
if all_leaf l then []
else let hd::tl = l in
hd::(mk_compact tl)
/// Correctness of mk_compact
let rec mk_compact_correctness (l:forest)
: Lemma (is_compact (mk_compact l))
[SMTPat (is_compact (mk_compact l))] =
match l with
| [] -> ()
| _ ->
if all_leaf l then ()
else mk_compact_correctness (L.tl l)
let rec mk_compact_preserves_binomial_queue (d:pos) (l:forest)
: Lemma
(requires is_binomial_queue d l)
(ensures is_binomial_queue d (mk_compact l))
(decreases l)
[SMTPat (is_binomial_queue d (mk_compact l))] =
match l with
| [] -> ()
| _ ->
if all_leaf l then ()
else mk_compact_preserves_binomial_queue (d + 1) (L.tl l)
/// smash is a key function combining two power of 2 heaps of depth d
/// into a power of 2 heap of depth (d + 1)
let smash (d:pos) (t1:tree) (t2:tree)
: Pure tree
(requires is_pow2heap d t1 /\ is_pow2heap d t2)
(ensures fun t -> is_pow2heap (d + 1) t) =
match t1, t2 with
| Internal left1 k1 Leaf, Internal left2 k2 Leaf ->
if k1 <= k2
then Internal (Internal left1 k1 left2) k2 Leaf
else Internal (Internal left2 k2 left1) k1 Leaf
/// carry adds t to q, preserving the binomial queue relation
///
/// It has a nice symmetery to carry in binary arithmetic
let rec carry (d:pos) (q:forest) (t:tree)
: Pure forest
(requires is_binomial_queue d q /\ is_pow2heap d t)
(ensures fun q -> is_binomial_queue d q)
(decreases q) =
match q with
| [] -> [t]
| Leaf::tl -> t::tl
| hd::tl ->
let q = carry (d + 1) tl (smash d hd t) in
Leaf::q
/// join combines two trees p and q, with the carry c,
/// preserving the binomial queue relation
///
/// It has a nice symmetry to binary addition
let rec join (d:pos) (p q:forest) (c:tree)
: Pure forest
(requires
is_binomial_queue d p /\
is_binomial_queue d q /\
(Leaf? c \/ is_pow2heap d c))
(ensures fun q -> is_binomial_queue d q)
(decreases L.length p) =
match p, q, c with
| [], _, Leaf -> q
| _, [], Leaf -> p
| [], _, _ -> carry d q c
| _, [], _ -> carry d p c
| Leaf::tl_p, Leaf::tl_q, _ ->
c::(join (d + 1) tl_p tl_q Leaf)
| hd_p::tl_p, Leaf::tl_q, Leaf ->
hd_p::(join (d + 1) tl_p tl_q Leaf)
| Leaf::tl_p, hd_q::tl_q, Leaf ->
hd_q::(join (d + 1) tl_p tl_q Leaf)
| Leaf::tl_p, hd_q::tl_q, _ ->
Leaf::(join (d + 1) tl_p tl_q (smash d hd_q c))
| hd_p::tl_p, Leaf::tl_q, _ ->
Leaf::(join (d + 1) tl_p tl_q (smash d hd_p c))
| hd_p::tl_p, hd_q::tl_q, c ->
c::(join (d + 1) tl_p tl_q (smash d hd_p hd_q))
/// insert is just carry of (Internal Leaf x Leaf) to q
let insert x q =
let l = carry 1 q (Internal Leaf x Leaf) in
mk_compact l
/// Towards delete max
/// find_max with the current max as max
let rec find_max (max:option key_t) (q:forest)
: Tot (option key_t) (decreases q) =
match q with
| [] -> max
| Leaf::q -> find_max max q
| (Internal _ k _)::q ->
match max with
| None -> find_max (Some k) q
| Some max -> find_max (if max < k then Some k else Some max) q
/// If q is a binomial queue starting at depth d,
/// and t is a power of 2 heap of depth (d + length q)
///
/// Then appending t to q is also a binomial queue
let rec binomial_queue_append (d:pos) (q:forest) (t:tree)
: Lemma
(requires
is_binomial_queue d q /\ is_pow2heap (L.length q + d) t)
(ensures is_binomial_queue d (L.append q [t]))
(decreases q) =
match q with
| [] -> ()
| _::q -> binomial_queue_append (d + 1) q t
/// unzip splits the tree t along its right spine
///
/// See https://www.cs.princeton.edu/~appel/BQ.pdf
///
/// The upper bound is only needed to show we return a priq,
/// may be it's not important?
let rec unzip (d:nat) (upper_bound:key_t) (t:tree)
: Pure priq
(requires pow2heap_pred d upper_bound t)
(ensures fun q -> L.length q == d) =
match t with
| Leaf -> []
| Internal left k right ->
let q = unzip (d - 1) upper_bound right in
binomial_queue_append 1 q (Internal left k Leaf);
L.append_length q [Internal left k Leaf];
L.lemma_append_last q [Internal left k Leaf];
L.append q [Internal left k Leaf]
/// Delete root of t, and unzip it
let heap_delete_max (d:pos) (t:tree)
: Pure priq
(requires is_pow2heap d t)
(ensures fun q -> L.length q == d - 1) =
match t with
| Internal left k Leaf -> unzip (d - 1) k left
/// Take the first tree in q whose root is >= m,
/// delete its root and unzip it,
/// return (the deleted root, q with that tree replaces with Leaf, unzipped forest)
///
let rec delete_max_aux (m:key_t) (d:pos) (q:forest)
: Pure (key_t & forest & priq)
(requires is_binomial_queue d q)
(ensures fun (x, q, _) -> m <= x /\ is_binomial_queue d q)
(decreases q) =
match q with
| [] -> m + 1, [], [] // this case won't arise
// we could strengthen preconditions
| Leaf::q ->
let x, q, new_q = delete_max_aux m (d + 1) q in
x, Leaf::q, new_q
| (Internal left x right)::q ->
if x < m
then let y, q, new_q = delete_max_aux m (d + 1) q in
y, (Internal left x right)::q, new_q
else x, Leaf::q, heap_delete_max d (Internal left x right)
/// delete_max finds the maximum key in the forest,
/// deletes it from its tree, and joins the remaining forests
let delete_max q =
match find_max None q with
| None -> None
| Some m ->
let x, q, new_q = delete_max_aux m 1 q in
let r = join 1 q new_q Leaf in
mk_compact_correctness r;
Some (x, mk_compact r)
/// merge is just join with Leaf as the carry
let merge p q =
let l = join 1 p q Leaf in
mk_compact l
/// Towards defining repr
let rec keys_of_tree (t:tree) : ms =
match t with
| Leaf -> ms_empty
| Internal left k right ->
ms_append (keys_of_tree left)
(ms_cons k (keys_of_tree right))
let rec keys (q:forest) : ms =
match q with
| [] -> ms_empty
| hd::tl -> ms_append (keys_of_tree hd) (keys tl)
let repr_t (t:tree) (l:ms) : prop =
permutation (keys_of_tree t) l
let repr_l (q:forest) (s:ms) : prop =
permutation (keys q) s
/// The main repr predicate saying s is a permutation of (keys q)
let repr q s = repr_l q s
let empty_repr _ = ()
/// Correctness of carry and join
let smash_repr (d:pos) (t1 t2:tree) (l1 l2:ms)
: Lemma
(requires
is_pow2heap d t1 /\
is_pow2heap d t2 /\
t1 `repr_t` l1 /\
t2 `repr_t` l2)
(ensures smash d t1 t2 `repr_t` (ms_append l1 l2)) = ()
let rec carry_repr (d:pos) (q:forest) (t:tree) (lq lt:ms)
: Lemma
(requires
is_binomial_queue d q /\
is_pow2heap d t /\
q `repr_l` lq /\
t `repr_t` lt)
(ensures carry d q t `repr_l` ms_append lq lt)
(decreases q) =
match q with
| [] -> ()
| Leaf::_ -> ()
| hd::tl ->
smash_repr d hd t (keys_of_tree hd) (keys_of_tree t);
carry_repr (d + 1) tl (smash d hd t)
(keys tl)
(ms_append (keys_of_tree hd) (keys_of_tree t))
#push-options "--z3rlimit 50 --fuel 1 --ifuel 1"
let rec join_repr (d:pos) (p q:forest) (c:tree)
(lp lq lc:ms)
: Lemma
(requires
is_binomial_queue d p /\
is_binomial_queue d q /\
(Leaf? c \/ is_pow2heap d c) /\
p `repr_l` lp /\
q `repr_l` lq /\
c `repr_t` lc)
(ensures join d p q c `repr_l` ms_append lp (ms_append lq lc))
(decreases p) =
match p, q, c with
| [], _, Leaf
| _, [], Leaf -> ()
| [], _, _ -> carry_repr d q c lq lc
| _, [], _ -> carry_repr d p c lp lc
| Leaf::tl_p, Leaf::tl_q, _ ->
join_repr (d + 1) tl_p tl_q Leaf
(keys tl_p) (keys tl_q) ms_empty
| hd_p::tl_p, Leaf::tl_q, Leaf ->
join_repr (d + 1) tl_p tl_q Leaf
(keys tl_p) (keys tl_q) ms_empty
| Leaf::tl_p, hd_q::tl_q, Leaf ->
join_repr (d + 1) tl_p tl_q Leaf
(keys tl_p) (keys tl_q) ms_empty
| Leaf::tl_p, hd_q::tl_q, _ ->
smash_repr d hd_q c (keys_of_tree hd_q) (keys_of_tree c);
join_repr (d + 1) tl_p tl_q (smash d hd_q c)
(keys tl_p) (keys tl_q)
(ms_append (keys_of_tree hd_q) (keys_of_tree c))
| hd_p::tl_p, Leaf::tl_q, _ ->
smash_repr d hd_p c (keys_of_tree hd_p) (keys_of_tree c);
join_repr (d + 1) tl_p tl_q (smash d hd_p c)
(keys tl_p) (keys tl_q)
(ms_append (keys_of_tree hd_p) (keys_of_tree c))
| hd_p::tl_p, hd_q::tl_q, c ->
smash_repr d hd_p hd_q (keys_of_tree hd_p) (keys_of_tree hd_q);
join_repr (d + 1) tl_p tl_q (smash d hd_p hd_q)
(keys tl_p) (keys tl_q)
(ms_append (keys_of_tree hd_p) (keys_of_tree hd_q))
#pop-options
/// mk_compact preserves keys
let rec all_leaf_keys (l:forest{Cons? l})
: Lemma
(requires Cons? l /\ all_leaf l)
(ensures permutation (keys l) ms_empty) =
match l with
| [Leaf] -> ()
| Leaf::tl -> all_leaf_keys tl
let rec compact_preserves_keys (q:forest)
: Lemma (permutation (keys q) (keys (mk_compact q)))
[SMTPat (keys (mk_compact q))] =
match q with
| [] -> ()
| _ ->
if all_leaf q
then all_leaf_keys q
else compact_preserves_keys (L.tl q)
/// insert and merge correctness follows from carry and joinx
let insert_repr x q s =
carry_repr 1 q (Internal Leaf x Leaf) s (ms_singleton x)
let merge_repr p q sp sq =
join_repr 1 p q Leaf sp sq ms_empty
/// Towards proof of delete correctness
let rec last_key_in_keys (l:forest)
: Lemma
(requires
Cons? l /\
Internal? (L.last l))
(ensures (let Internal _ k _ = L.last l in
S.subset (S.singleton k) (keys l).ms_elems)) =
match l with
| [Internal _ _ _] -> ()
| _::tl -> last_key_in_keys tl
let rec find_max_some_is_some (k:key_t) (l:forest)
: Lemma (ensures Some? (find_max (Some k) l) /\
k <= Some?.v (find_max (Some k) l))
(decreases l) =
match l with
| [] -> ()
| Leaf::tl -> find_max_some_is_some k tl
| (Internal _ k' _)::tl ->
let k = if k < k' then k' else k in
find_max_some_is_some k tl
let find_max_emp_repr_l (l:priq)
: Lemma
(requires l `repr_l` ms_empty)
(ensures find_max None l == None) =
match l with
| [] -> ()
| _ -> last_key_in_keys l
let rec find_max_emp_repr_r (l:forest)
: Lemma
(requires find_max None l == None)
(ensures permutation (keys l) ms_empty) =
match l with
| [] -> ()
| Leaf::tl -> find_max_emp_repr_r tl
| (Internal _ k _)::tl -> find_max_some_is_some k tl
#push-options "--warn_error -271"
let delete_max_none_repr p =
let delete_max_none_repr_l (l:priq)
: Lemma
(requires l `repr` ms_empty)
(ensures delete_max l == None)
[SMTPat ()] = find_max_emp_repr_l l in
let delete_max_none_repr_r (l:priq)
: Lemma
(requires delete_max l == None)
(ensures l `repr` ms_empty)
[SMTPat ()] = find_max_emp_repr_r l in
()
#pop-options
let rec keys_append (l1 l2:forest) (ms1 ms2:ms)
: Lemma (requires l1 `repr_l` ms1 /\ l2 `repr_l` ms2)
(ensures (L.append l1 l2) `repr_l` (ms_append ms1 ms2)) =
match l1 with
| [] -> ()
| _::tl -> keys_append tl l2 (keys tl) ms2
let rec unzip_repr (d:nat) (upper_bound:key_t) (t:tree) (lt:ms)
: Lemma
(requires
pow2heap_pred d upper_bound t /\
permutation (keys_of_tree t) lt)
(ensures permutation lt (keys (unzip d upper_bound t)))
(decreases t) =
match t with
| Leaf -> ()
| Internal left k right ->
let q = unzip (d - 1) upper_bound right in
unzip_repr (d - 1) upper_bound right (keys_of_tree right);
keys_append q [Internal left k Leaf]
(keys_of_tree right) (ms_append (keys_of_tree left)
(ms_append (ms_singleton k)
ms_empty))
let heap_delete_max_repr (d:pos) (t:tree) (lt:ms)
: Lemma
(requires is_pow2heap d t /\ t `repr_t` lt)
(ensures (
let Internal left k Leaf = t in
permutation lt (ms_append (ms_singleton k)
(keys (heap_delete_max d t))))) =
let Internal left k Leaf = t in
unzip_repr (d - 1) k left (keys_of_tree left)
let max (k:key_t) (s:S.set key_t) =
forall (x:key_t). Set.mem x s ==> x <= k | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "BinomialQueue.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Set",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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 | d: Prims.nat -> upper_bound: BinomialQueue.key_t -> t: BinomialQueue.tree
-> FStar.Pervasives.Lemma (requires BinomialQueue.pow2heap_pred d upper_bound t)
(ensures BinomialQueue.max upper_bound (Mkms?.ms_elems (BinomialQueue.keys_of_tree t)))
(decreases t) | FStar.Pervasives.Lemma | [
"lemma",
""
] | [] | [
"Prims.nat",
"BinomialQueue.key_t",
"BinomialQueue.tree",
"BinomialQueue.tree_root_is_max_aux",
"Prims.op_Subtraction",
"Prims.unit",
"BinomialQueue.pow2heap_pred",
"Prims.squash",
"BinomialQueue.max",
"BinomialQueue.__proj__Mkms__item__ms_elems",
"BinomialQueue.keys_of_tree",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [
"recursion"
] | false | false | true | false | false | let rec tree_root_is_max_aux (d: nat) (upper_bound: key_t) (t: tree)
: Lemma (requires pow2heap_pred d upper_bound t)
(ensures max upper_bound (keys_of_tree t).ms_elems)
(decreases t) =
| match t with
| Leaf -> ()
| Internal left k right ->
tree_root_is_max_aux (d - 1) k left;
tree_root_is_max_aux (d - 1) upper_bound right | false |
BinomialQueue.fst | BinomialQueue.last_key_in_keys | val last_key_in_keys (l: forest)
: Lemma (requires Cons? l /\ Internal? (L.last l))
(ensures
(let Internal _ k _ = L.last l in
S.subset (S.singleton k) (keys l).ms_elems)) | val last_key_in_keys (l: forest)
: Lemma (requires Cons? l /\ Internal? (L.last l))
(ensures
(let Internal _ k _ = L.last l in
S.subset (S.singleton k) (keys l).ms_elems)) | let rec last_key_in_keys (l:forest)
: Lemma
(requires
Cons? l /\
Internal? (L.last l))
(ensures (let Internal _ k _ = L.last l in
S.subset (S.singleton k) (keys l).ms_elems)) =
match l with
| [Internal _ _ _] -> ()
| _::tl -> last_key_in_keys tl | {
"file_name": "examples/data_structures/BinomialQueue.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 32,
"end_line": 450,
"start_col": 0,
"start_line": 441
} | (*
Copyright 2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Authors: Aseem Rastogi
*)
module BinomialQueue
module L = FStar.List.Tot
/// Some auxiliary lemmas
let rec last_cons (#a:Type) (x:a) (l:list a)
: Lemma
(requires Cons? l)
(ensures L.last (x::l) == L.last l)
[SMTPat (L.last (x::l))] =
match l with
| [_] -> ()
| _::tl -> last_cons x tl
/// We will maintain the priority queue as a forest
type tree =
| Leaf : tree
| Internal : tree -> key_t -> tree -> tree
/// Tree t is a complete binary tree of depth d
///
/// All its keys are <= upper_bound
///
/// If the left subtree is non-empty,
/// its root is maximum in its subtree
let rec pow2heap_pred (d:nat) (upper_bound:key_t) (t:tree) : prop =
match t with
| Leaf -> d == 0
| Internal left k right ->
0 < d /\
k <= upper_bound /\
pow2heap_pred (d - 1) k left /\
pow2heap_pred (d - 1) upper_bound right
/// A power-2-heap of depth d is an Internal tree whose right child is a Leaf,
/// and left child is a complete binary tree satisfying pow2heap_pred
/// with upper bound as the key k
let is_pow2heap (d:pos) (t:tree) : prop =
match t with
| Internal left k Leaf -> pow2heap_pred (d - 1) k left
| _ -> False
/// A list of trees is a binomial queue starting with depth d if:
type forest = list tree
let rec is_binomial_queue (d:pos) (l:forest)
: Tot prop (decreases l) =
match l with
| [] -> True
| hd::tl ->
(Leaf? hd \/ is_pow2heap d hd) /\ is_binomial_queue (d + 1) tl
/// We will also keep the binomial queue in a compact form,
/// truncating unnecessary empty trees from the forest
let is_compact (l:forest) = l == [] \/ Internal? (L.last l)
let is_priq (l:forest) = is_binomial_queue 1 l /\ is_compact l
/// The main priq type
let priq = l:forest{is_priq l}
let empty = []
/// We define a function to compact a forest
let rec all_leaf (l:forest{Cons? l}) : bool =
match l with
| [Leaf] -> true
| Leaf::tl -> all_leaf tl
| _ -> false
let rec mk_compact (l:forest) : forest =
match l with
| [] -> []
| _ ->
if all_leaf l then []
else let hd::tl = l in
hd::(mk_compact tl)
/// Correctness of mk_compact
let rec mk_compact_correctness (l:forest)
: Lemma (is_compact (mk_compact l))
[SMTPat (is_compact (mk_compact l))] =
match l with
| [] -> ()
| _ ->
if all_leaf l then ()
else mk_compact_correctness (L.tl l)
let rec mk_compact_preserves_binomial_queue (d:pos) (l:forest)
: Lemma
(requires is_binomial_queue d l)
(ensures is_binomial_queue d (mk_compact l))
(decreases l)
[SMTPat (is_binomial_queue d (mk_compact l))] =
match l with
| [] -> ()
| _ ->
if all_leaf l then ()
else mk_compact_preserves_binomial_queue (d + 1) (L.tl l)
/// smash is a key function combining two power of 2 heaps of depth d
/// into a power of 2 heap of depth (d + 1)
let smash (d:pos) (t1:tree) (t2:tree)
: Pure tree
(requires is_pow2heap d t1 /\ is_pow2heap d t2)
(ensures fun t -> is_pow2heap (d + 1) t) =
match t1, t2 with
| Internal left1 k1 Leaf, Internal left2 k2 Leaf ->
if k1 <= k2
then Internal (Internal left1 k1 left2) k2 Leaf
else Internal (Internal left2 k2 left1) k1 Leaf
/// carry adds t to q, preserving the binomial queue relation
///
/// It has a nice symmetery to carry in binary arithmetic
let rec carry (d:pos) (q:forest) (t:tree)
: Pure forest
(requires is_binomial_queue d q /\ is_pow2heap d t)
(ensures fun q -> is_binomial_queue d q)
(decreases q) =
match q with
| [] -> [t]
| Leaf::tl -> t::tl
| hd::tl ->
let q = carry (d + 1) tl (smash d hd t) in
Leaf::q
/// join combines two trees p and q, with the carry c,
/// preserving the binomial queue relation
///
/// It has a nice symmetry to binary addition
let rec join (d:pos) (p q:forest) (c:tree)
: Pure forest
(requires
is_binomial_queue d p /\
is_binomial_queue d q /\
(Leaf? c \/ is_pow2heap d c))
(ensures fun q -> is_binomial_queue d q)
(decreases L.length p) =
match p, q, c with
| [], _, Leaf -> q
| _, [], Leaf -> p
| [], _, _ -> carry d q c
| _, [], _ -> carry d p c
| Leaf::tl_p, Leaf::tl_q, _ ->
c::(join (d + 1) tl_p tl_q Leaf)
| hd_p::tl_p, Leaf::tl_q, Leaf ->
hd_p::(join (d + 1) tl_p tl_q Leaf)
| Leaf::tl_p, hd_q::tl_q, Leaf ->
hd_q::(join (d + 1) tl_p tl_q Leaf)
| Leaf::tl_p, hd_q::tl_q, _ ->
Leaf::(join (d + 1) tl_p tl_q (smash d hd_q c))
| hd_p::tl_p, Leaf::tl_q, _ ->
Leaf::(join (d + 1) tl_p tl_q (smash d hd_p c))
| hd_p::tl_p, hd_q::tl_q, c ->
c::(join (d + 1) tl_p tl_q (smash d hd_p hd_q))
/// insert is just carry of (Internal Leaf x Leaf) to q
let insert x q =
let l = carry 1 q (Internal Leaf x Leaf) in
mk_compact l
/// Towards delete max
/// find_max with the current max as max
let rec find_max (max:option key_t) (q:forest)
: Tot (option key_t) (decreases q) =
match q with
| [] -> max
| Leaf::q -> find_max max q
| (Internal _ k _)::q ->
match max with
| None -> find_max (Some k) q
| Some max -> find_max (if max < k then Some k else Some max) q
/// If q is a binomial queue starting at depth d,
/// and t is a power of 2 heap of depth (d + length q)
///
/// Then appending t to q is also a binomial queue
let rec binomial_queue_append (d:pos) (q:forest) (t:tree)
: Lemma
(requires
is_binomial_queue d q /\ is_pow2heap (L.length q + d) t)
(ensures is_binomial_queue d (L.append q [t]))
(decreases q) =
match q with
| [] -> ()
| _::q -> binomial_queue_append (d + 1) q t
/// unzip splits the tree t along its right spine
///
/// See https://www.cs.princeton.edu/~appel/BQ.pdf
///
/// The upper bound is only needed to show we return a priq,
/// may be it's not important?
let rec unzip (d:nat) (upper_bound:key_t) (t:tree)
: Pure priq
(requires pow2heap_pred d upper_bound t)
(ensures fun q -> L.length q == d) =
match t with
| Leaf -> []
| Internal left k right ->
let q = unzip (d - 1) upper_bound right in
binomial_queue_append 1 q (Internal left k Leaf);
L.append_length q [Internal left k Leaf];
L.lemma_append_last q [Internal left k Leaf];
L.append q [Internal left k Leaf]
/// Delete root of t, and unzip it
let heap_delete_max (d:pos) (t:tree)
: Pure priq
(requires is_pow2heap d t)
(ensures fun q -> L.length q == d - 1) =
match t with
| Internal left k Leaf -> unzip (d - 1) k left
/// Take the first tree in q whose root is >= m,
/// delete its root and unzip it,
/// return (the deleted root, q with that tree replaces with Leaf, unzipped forest)
///
let rec delete_max_aux (m:key_t) (d:pos) (q:forest)
: Pure (key_t & forest & priq)
(requires is_binomial_queue d q)
(ensures fun (x, q, _) -> m <= x /\ is_binomial_queue d q)
(decreases q) =
match q with
| [] -> m + 1, [], [] // this case won't arise
// we could strengthen preconditions
| Leaf::q ->
let x, q, new_q = delete_max_aux m (d + 1) q in
x, Leaf::q, new_q
| (Internal left x right)::q ->
if x < m
then let y, q, new_q = delete_max_aux m (d + 1) q in
y, (Internal left x right)::q, new_q
else x, Leaf::q, heap_delete_max d (Internal left x right)
/// delete_max finds the maximum key in the forest,
/// deletes it from its tree, and joins the remaining forests
let delete_max q =
match find_max None q with
| None -> None
| Some m ->
let x, q, new_q = delete_max_aux m 1 q in
let r = join 1 q new_q Leaf in
mk_compact_correctness r;
Some (x, mk_compact r)
/// merge is just join with Leaf as the carry
let merge p q =
let l = join 1 p q Leaf in
mk_compact l
/// Towards defining repr
let rec keys_of_tree (t:tree) : ms =
match t with
| Leaf -> ms_empty
| Internal left k right ->
ms_append (keys_of_tree left)
(ms_cons k (keys_of_tree right))
let rec keys (q:forest) : ms =
match q with
| [] -> ms_empty
| hd::tl -> ms_append (keys_of_tree hd) (keys tl)
let repr_t (t:tree) (l:ms) : prop =
permutation (keys_of_tree t) l
let repr_l (q:forest) (s:ms) : prop =
permutation (keys q) s
/// The main repr predicate saying s is a permutation of (keys q)
let repr q s = repr_l q s
let empty_repr _ = ()
/// Correctness of carry and join
let smash_repr (d:pos) (t1 t2:tree) (l1 l2:ms)
: Lemma
(requires
is_pow2heap d t1 /\
is_pow2heap d t2 /\
t1 `repr_t` l1 /\
t2 `repr_t` l2)
(ensures smash d t1 t2 `repr_t` (ms_append l1 l2)) = ()
let rec carry_repr (d:pos) (q:forest) (t:tree) (lq lt:ms)
: Lemma
(requires
is_binomial_queue d q /\
is_pow2heap d t /\
q `repr_l` lq /\
t `repr_t` lt)
(ensures carry d q t `repr_l` ms_append lq lt)
(decreases q) =
match q with
| [] -> ()
| Leaf::_ -> ()
| hd::tl ->
smash_repr d hd t (keys_of_tree hd) (keys_of_tree t);
carry_repr (d + 1) tl (smash d hd t)
(keys tl)
(ms_append (keys_of_tree hd) (keys_of_tree t))
#push-options "--z3rlimit 50 --fuel 1 --ifuel 1"
let rec join_repr (d:pos) (p q:forest) (c:tree)
(lp lq lc:ms)
: Lemma
(requires
is_binomial_queue d p /\
is_binomial_queue d q /\
(Leaf? c \/ is_pow2heap d c) /\
p `repr_l` lp /\
q `repr_l` lq /\
c `repr_t` lc)
(ensures join d p q c `repr_l` ms_append lp (ms_append lq lc))
(decreases p) =
match p, q, c with
| [], _, Leaf
| _, [], Leaf -> ()
| [], _, _ -> carry_repr d q c lq lc
| _, [], _ -> carry_repr d p c lp lc
| Leaf::tl_p, Leaf::tl_q, _ ->
join_repr (d + 1) tl_p tl_q Leaf
(keys tl_p) (keys tl_q) ms_empty
| hd_p::tl_p, Leaf::tl_q, Leaf ->
join_repr (d + 1) tl_p tl_q Leaf
(keys tl_p) (keys tl_q) ms_empty
| Leaf::tl_p, hd_q::tl_q, Leaf ->
join_repr (d + 1) tl_p tl_q Leaf
(keys tl_p) (keys tl_q) ms_empty
| Leaf::tl_p, hd_q::tl_q, _ ->
smash_repr d hd_q c (keys_of_tree hd_q) (keys_of_tree c);
join_repr (d + 1) tl_p tl_q (smash d hd_q c)
(keys tl_p) (keys tl_q)
(ms_append (keys_of_tree hd_q) (keys_of_tree c))
| hd_p::tl_p, Leaf::tl_q, _ ->
smash_repr d hd_p c (keys_of_tree hd_p) (keys_of_tree c);
join_repr (d + 1) tl_p tl_q (smash d hd_p c)
(keys tl_p) (keys tl_q)
(ms_append (keys_of_tree hd_p) (keys_of_tree c))
| hd_p::tl_p, hd_q::tl_q, c ->
smash_repr d hd_p hd_q (keys_of_tree hd_p) (keys_of_tree hd_q);
join_repr (d + 1) tl_p tl_q (smash d hd_p hd_q)
(keys tl_p) (keys tl_q)
(ms_append (keys_of_tree hd_p) (keys_of_tree hd_q))
#pop-options
/// mk_compact preserves keys
let rec all_leaf_keys (l:forest{Cons? l})
: Lemma
(requires Cons? l /\ all_leaf l)
(ensures permutation (keys l) ms_empty) =
match l with
| [Leaf] -> ()
| Leaf::tl -> all_leaf_keys tl
let rec compact_preserves_keys (q:forest)
: Lemma (permutation (keys q) (keys (mk_compact q)))
[SMTPat (keys (mk_compact q))] =
match q with
| [] -> ()
| _ ->
if all_leaf q
then all_leaf_keys q
else compact_preserves_keys (L.tl q)
/// insert and merge correctness follows from carry and joinx
let insert_repr x q s =
carry_repr 1 q (Internal Leaf x Leaf) s (ms_singleton x)
let merge_repr p q sp sq =
join_repr 1 p q Leaf sp sq ms_empty
/// Towards proof of delete correctness | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "BinomialQueue.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Set",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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: BinomialQueue.forest
-> FStar.Pervasives.Lemma (requires Cons? l /\ Internal? (FStar.List.Tot.Base.last l))
(ensures
(let _ = FStar.List.Tot.Base.last l in
(let BinomialQueue.Internal _ k _ = _ in
FStar.Set.subset (FStar.Set.singleton k) (Mkms?.ms_elems (BinomialQueue.keys l)))
<:
Type0)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"BinomialQueue.forest",
"BinomialQueue.tree",
"BinomialQueue.key_t",
"Prims.list",
"BinomialQueue.last_key_in_keys",
"Prims.unit",
"Prims.l_and",
"Prims.b2t",
"Prims.uu___is_Cons",
"BinomialQueue.uu___is_Internal",
"FStar.List.Tot.Base.last",
"Prims.squash",
"FStar.Set.subset",
"FStar.Set.singleton",
"BinomialQueue.__proj__Mkms__item__ms_elems",
"BinomialQueue.keys",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [
"recursion"
] | false | false | true | false | false | let rec last_key_in_keys (l: forest)
: Lemma (requires Cons? l /\ Internal? (L.last l))
(ensures
(let Internal _ k _ = L.last l in
S.subset (S.singleton k) (keys l).ms_elems)) =
| match l with
| [Internal _ _ _] -> ()
| _ :: tl -> last_key_in_keys tl | false |
BinomialQueue.fst | BinomialQueue.delete_max_none_repr | val delete_max_none_repr (p:priq)
: Lemma (delete_max p == None <==> p `repr` ms_empty) | val delete_max_none_repr (p:priq)
: Lemma (delete_max p == None <==> p `repr` ms_empty) | let delete_max_none_repr p =
let delete_max_none_repr_l (l:priq)
: Lemma
(requires l `repr` ms_empty)
(ensures delete_max l == None)
[SMTPat ()] = find_max_emp_repr_l l in
let delete_max_none_repr_r (l:priq)
: Lemma
(requires delete_max l == None)
(ensures l `repr` ms_empty)
[SMTPat ()] = find_max_emp_repr_r l in
() | {
"file_name": "examples/data_structures/BinomialQueue.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 4,
"end_line": 494,
"start_col": 0,
"start_line": 482
} | (*
Copyright 2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Authors: Aseem Rastogi
*)
module BinomialQueue
module L = FStar.List.Tot
/// Some auxiliary lemmas
let rec last_cons (#a:Type) (x:a) (l:list a)
: Lemma
(requires Cons? l)
(ensures L.last (x::l) == L.last l)
[SMTPat (L.last (x::l))] =
match l with
| [_] -> ()
| _::tl -> last_cons x tl
/// We will maintain the priority queue as a forest
type tree =
| Leaf : tree
| Internal : tree -> key_t -> tree -> tree
/// Tree t is a complete binary tree of depth d
///
/// All its keys are <= upper_bound
///
/// If the left subtree is non-empty,
/// its root is maximum in its subtree
let rec pow2heap_pred (d:nat) (upper_bound:key_t) (t:tree) : prop =
match t with
| Leaf -> d == 0
| Internal left k right ->
0 < d /\
k <= upper_bound /\
pow2heap_pred (d - 1) k left /\
pow2heap_pred (d - 1) upper_bound right
/// A power-2-heap of depth d is an Internal tree whose right child is a Leaf,
/// and left child is a complete binary tree satisfying pow2heap_pred
/// with upper bound as the key k
let is_pow2heap (d:pos) (t:tree) : prop =
match t with
| Internal left k Leaf -> pow2heap_pred (d - 1) k left
| _ -> False
/// A list of trees is a binomial queue starting with depth d if:
type forest = list tree
let rec is_binomial_queue (d:pos) (l:forest)
: Tot prop (decreases l) =
match l with
| [] -> True
| hd::tl ->
(Leaf? hd \/ is_pow2heap d hd) /\ is_binomial_queue (d + 1) tl
/// We will also keep the binomial queue in a compact form,
/// truncating unnecessary empty trees from the forest
let is_compact (l:forest) = l == [] \/ Internal? (L.last l)
let is_priq (l:forest) = is_binomial_queue 1 l /\ is_compact l
/// The main priq type
let priq = l:forest{is_priq l}
let empty = []
/// We define a function to compact a forest
let rec all_leaf (l:forest{Cons? l}) : bool =
match l with
| [Leaf] -> true
| Leaf::tl -> all_leaf tl
| _ -> false
let rec mk_compact (l:forest) : forest =
match l with
| [] -> []
| _ ->
if all_leaf l then []
else let hd::tl = l in
hd::(mk_compact tl)
/// Correctness of mk_compact
let rec mk_compact_correctness (l:forest)
: Lemma (is_compact (mk_compact l))
[SMTPat (is_compact (mk_compact l))] =
match l with
| [] -> ()
| _ ->
if all_leaf l then ()
else mk_compact_correctness (L.tl l)
let rec mk_compact_preserves_binomial_queue (d:pos) (l:forest)
: Lemma
(requires is_binomial_queue d l)
(ensures is_binomial_queue d (mk_compact l))
(decreases l)
[SMTPat (is_binomial_queue d (mk_compact l))] =
match l with
| [] -> ()
| _ ->
if all_leaf l then ()
else mk_compact_preserves_binomial_queue (d + 1) (L.tl l)
/// smash is a key function combining two power of 2 heaps of depth d
/// into a power of 2 heap of depth (d + 1)
let smash (d:pos) (t1:tree) (t2:tree)
: Pure tree
(requires is_pow2heap d t1 /\ is_pow2heap d t2)
(ensures fun t -> is_pow2heap (d + 1) t) =
match t1, t2 with
| Internal left1 k1 Leaf, Internal left2 k2 Leaf ->
if k1 <= k2
then Internal (Internal left1 k1 left2) k2 Leaf
else Internal (Internal left2 k2 left1) k1 Leaf
/// carry adds t to q, preserving the binomial queue relation
///
/// It has a nice symmetery to carry in binary arithmetic
let rec carry (d:pos) (q:forest) (t:tree)
: Pure forest
(requires is_binomial_queue d q /\ is_pow2heap d t)
(ensures fun q -> is_binomial_queue d q)
(decreases q) =
match q with
| [] -> [t]
| Leaf::tl -> t::tl
| hd::tl ->
let q = carry (d + 1) tl (smash d hd t) in
Leaf::q
/// join combines two trees p and q, with the carry c,
/// preserving the binomial queue relation
///
/// It has a nice symmetry to binary addition
let rec join (d:pos) (p q:forest) (c:tree)
: Pure forest
(requires
is_binomial_queue d p /\
is_binomial_queue d q /\
(Leaf? c \/ is_pow2heap d c))
(ensures fun q -> is_binomial_queue d q)
(decreases L.length p) =
match p, q, c with
| [], _, Leaf -> q
| _, [], Leaf -> p
| [], _, _ -> carry d q c
| _, [], _ -> carry d p c
| Leaf::tl_p, Leaf::tl_q, _ ->
c::(join (d + 1) tl_p tl_q Leaf)
| hd_p::tl_p, Leaf::tl_q, Leaf ->
hd_p::(join (d + 1) tl_p tl_q Leaf)
| Leaf::tl_p, hd_q::tl_q, Leaf ->
hd_q::(join (d + 1) tl_p tl_q Leaf)
| Leaf::tl_p, hd_q::tl_q, _ ->
Leaf::(join (d + 1) tl_p tl_q (smash d hd_q c))
| hd_p::tl_p, Leaf::tl_q, _ ->
Leaf::(join (d + 1) tl_p tl_q (smash d hd_p c))
| hd_p::tl_p, hd_q::tl_q, c ->
c::(join (d + 1) tl_p tl_q (smash d hd_p hd_q))
/// insert is just carry of (Internal Leaf x Leaf) to q
let insert x q =
let l = carry 1 q (Internal Leaf x Leaf) in
mk_compact l
/// Towards delete max
/// find_max with the current max as max
let rec find_max (max:option key_t) (q:forest)
: Tot (option key_t) (decreases q) =
match q with
| [] -> max
| Leaf::q -> find_max max q
| (Internal _ k _)::q ->
match max with
| None -> find_max (Some k) q
| Some max -> find_max (if max < k then Some k else Some max) q
/// If q is a binomial queue starting at depth d,
/// and t is a power of 2 heap of depth (d + length q)
///
/// Then appending t to q is also a binomial queue
let rec binomial_queue_append (d:pos) (q:forest) (t:tree)
: Lemma
(requires
is_binomial_queue d q /\ is_pow2heap (L.length q + d) t)
(ensures is_binomial_queue d (L.append q [t]))
(decreases q) =
match q with
| [] -> ()
| _::q -> binomial_queue_append (d + 1) q t
/// unzip splits the tree t along its right spine
///
/// See https://www.cs.princeton.edu/~appel/BQ.pdf
///
/// The upper bound is only needed to show we return a priq,
/// may be it's not important?
let rec unzip (d:nat) (upper_bound:key_t) (t:tree)
: Pure priq
(requires pow2heap_pred d upper_bound t)
(ensures fun q -> L.length q == d) =
match t with
| Leaf -> []
| Internal left k right ->
let q = unzip (d - 1) upper_bound right in
binomial_queue_append 1 q (Internal left k Leaf);
L.append_length q [Internal left k Leaf];
L.lemma_append_last q [Internal left k Leaf];
L.append q [Internal left k Leaf]
/// Delete root of t, and unzip it
let heap_delete_max (d:pos) (t:tree)
: Pure priq
(requires is_pow2heap d t)
(ensures fun q -> L.length q == d - 1) =
match t with
| Internal left k Leaf -> unzip (d - 1) k left
/// Take the first tree in q whose root is >= m,
/// delete its root and unzip it,
/// return (the deleted root, q with that tree replaces with Leaf, unzipped forest)
///
let rec delete_max_aux (m:key_t) (d:pos) (q:forest)
: Pure (key_t & forest & priq)
(requires is_binomial_queue d q)
(ensures fun (x, q, _) -> m <= x /\ is_binomial_queue d q)
(decreases q) =
match q with
| [] -> m + 1, [], [] // this case won't arise
// we could strengthen preconditions
| Leaf::q ->
let x, q, new_q = delete_max_aux m (d + 1) q in
x, Leaf::q, new_q
| (Internal left x right)::q ->
if x < m
then let y, q, new_q = delete_max_aux m (d + 1) q in
y, (Internal left x right)::q, new_q
else x, Leaf::q, heap_delete_max d (Internal left x right)
/// delete_max finds the maximum key in the forest,
/// deletes it from its tree, and joins the remaining forests
let delete_max q =
match find_max None q with
| None -> None
| Some m ->
let x, q, new_q = delete_max_aux m 1 q in
let r = join 1 q new_q Leaf in
mk_compact_correctness r;
Some (x, mk_compact r)
/// merge is just join with Leaf as the carry
let merge p q =
let l = join 1 p q Leaf in
mk_compact l
/// Towards defining repr
let rec keys_of_tree (t:tree) : ms =
match t with
| Leaf -> ms_empty
| Internal left k right ->
ms_append (keys_of_tree left)
(ms_cons k (keys_of_tree right))
let rec keys (q:forest) : ms =
match q with
| [] -> ms_empty
| hd::tl -> ms_append (keys_of_tree hd) (keys tl)
let repr_t (t:tree) (l:ms) : prop =
permutation (keys_of_tree t) l
let repr_l (q:forest) (s:ms) : prop =
permutation (keys q) s
/// The main repr predicate saying s is a permutation of (keys q)
let repr q s = repr_l q s
let empty_repr _ = ()
/// Correctness of carry and join
let smash_repr (d:pos) (t1 t2:tree) (l1 l2:ms)
: Lemma
(requires
is_pow2heap d t1 /\
is_pow2heap d t2 /\
t1 `repr_t` l1 /\
t2 `repr_t` l2)
(ensures smash d t1 t2 `repr_t` (ms_append l1 l2)) = ()
let rec carry_repr (d:pos) (q:forest) (t:tree) (lq lt:ms)
: Lemma
(requires
is_binomial_queue d q /\
is_pow2heap d t /\
q `repr_l` lq /\
t `repr_t` lt)
(ensures carry d q t `repr_l` ms_append lq lt)
(decreases q) =
match q with
| [] -> ()
| Leaf::_ -> ()
| hd::tl ->
smash_repr d hd t (keys_of_tree hd) (keys_of_tree t);
carry_repr (d + 1) tl (smash d hd t)
(keys tl)
(ms_append (keys_of_tree hd) (keys_of_tree t))
#push-options "--z3rlimit 50 --fuel 1 --ifuel 1"
let rec join_repr (d:pos) (p q:forest) (c:tree)
(lp lq lc:ms)
: Lemma
(requires
is_binomial_queue d p /\
is_binomial_queue d q /\
(Leaf? c \/ is_pow2heap d c) /\
p `repr_l` lp /\
q `repr_l` lq /\
c `repr_t` lc)
(ensures join d p q c `repr_l` ms_append lp (ms_append lq lc))
(decreases p) =
match p, q, c with
| [], _, Leaf
| _, [], Leaf -> ()
| [], _, _ -> carry_repr d q c lq lc
| _, [], _ -> carry_repr d p c lp lc
| Leaf::tl_p, Leaf::tl_q, _ ->
join_repr (d + 1) tl_p tl_q Leaf
(keys tl_p) (keys tl_q) ms_empty
| hd_p::tl_p, Leaf::tl_q, Leaf ->
join_repr (d + 1) tl_p tl_q Leaf
(keys tl_p) (keys tl_q) ms_empty
| Leaf::tl_p, hd_q::tl_q, Leaf ->
join_repr (d + 1) tl_p tl_q Leaf
(keys tl_p) (keys tl_q) ms_empty
| Leaf::tl_p, hd_q::tl_q, _ ->
smash_repr d hd_q c (keys_of_tree hd_q) (keys_of_tree c);
join_repr (d + 1) tl_p tl_q (smash d hd_q c)
(keys tl_p) (keys tl_q)
(ms_append (keys_of_tree hd_q) (keys_of_tree c))
| hd_p::tl_p, Leaf::tl_q, _ ->
smash_repr d hd_p c (keys_of_tree hd_p) (keys_of_tree c);
join_repr (d + 1) tl_p tl_q (smash d hd_p c)
(keys tl_p) (keys tl_q)
(ms_append (keys_of_tree hd_p) (keys_of_tree c))
| hd_p::tl_p, hd_q::tl_q, c ->
smash_repr d hd_p hd_q (keys_of_tree hd_p) (keys_of_tree hd_q);
join_repr (d + 1) tl_p tl_q (smash d hd_p hd_q)
(keys tl_p) (keys tl_q)
(ms_append (keys_of_tree hd_p) (keys_of_tree hd_q))
#pop-options
/// mk_compact preserves keys
let rec all_leaf_keys (l:forest{Cons? l})
: Lemma
(requires Cons? l /\ all_leaf l)
(ensures permutation (keys l) ms_empty) =
match l with
| [Leaf] -> ()
| Leaf::tl -> all_leaf_keys tl
let rec compact_preserves_keys (q:forest)
: Lemma (permutation (keys q) (keys (mk_compact q)))
[SMTPat (keys (mk_compact q))] =
match q with
| [] -> ()
| _ ->
if all_leaf q
then all_leaf_keys q
else compact_preserves_keys (L.tl q)
/// insert and merge correctness follows from carry and joinx
let insert_repr x q s =
carry_repr 1 q (Internal Leaf x Leaf) s (ms_singleton x)
let merge_repr p q sp sq =
join_repr 1 p q Leaf sp sq ms_empty
/// Towards proof of delete correctness
let rec last_key_in_keys (l:forest)
: Lemma
(requires
Cons? l /\
Internal? (L.last l))
(ensures (let Internal _ k _ = L.last l in
S.subset (S.singleton k) (keys l).ms_elems)) =
match l with
| [Internal _ _ _] -> ()
| _::tl -> last_key_in_keys tl
let rec find_max_some_is_some (k:key_t) (l:forest)
: Lemma (ensures Some? (find_max (Some k) l) /\
k <= Some?.v (find_max (Some k) l))
(decreases l) =
match l with
| [] -> ()
| Leaf::tl -> find_max_some_is_some k tl
| (Internal _ k' _)::tl ->
let k = if k < k' then k' else k in
find_max_some_is_some k tl
let find_max_emp_repr_l (l:priq)
: Lemma
(requires l `repr_l` ms_empty)
(ensures find_max None l == None) =
match l with
| [] -> ()
| _ -> last_key_in_keys l
let rec find_max_emp_repr_r (l:forest)
: Lemma
(requires find_max None l == None)
(ensures permutation (keys l) ms_empty) =
match l with
| [] -> ()
| Leaf::tl -> find_max_emp_repr_r tl
| (Internal _ k _)::tl -> find_max_some_is_some k tl | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "BinomialQueue.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Set",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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: BinomialQueue.priq
-> FStar.Pervasives.Lemma
(ensures
BinomialQueue.delete_max p == FStar.Pervasives.Native.None <==>
BinomialQueue.repr p BinomialQueue.ms_empty) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"BinomialQueue.priq",
"Prims.unit",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"FStar.Pervasives.Native.tuple2",
"BinomialQueue.key_t",
"BinomialQueue.delete_max",
"FStar.Pervasives.Native.None",
"Prims.squash",
"BinomialQueue.repr",
"BinomialQueue.ms_empty",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"Prims.Nil",
"BinomialQueue.find_max_emp_repr_r",
"BinomialQueue.find_max_emp_repr_l"
] | [] | false | false | true | false | false | let delete_max_none_repr p =
| let delete_max_none_repr_l (l: priq)
: Lemma (requires l `repr` ms_empty) (ensures delete_max l == None) [SMTPat ()] =
find_max_emp_repr_l l
in
let delete_max_none_repr_r (l: priq)
: Lemma (requires delete_max l == None) (ensures l `repr` ms_empty) [SMTPat ()] =
find_max_emp_repr_r l
in
() | false |
BinomialQueue.fst | BinomialQueue.unzip_repr | val unzip_repr (d: nat) (upper_bound: key_t) (t: tree) (lt: ms)
: Lemma (requires pow2heap_pred d upper_bound t /\ permutation (keys_of_tree t) lt)
(ensures permutation lt (keys (unzip d upper_bound t)))
(decreases t) | val unzip_repr (d: nat) (upper_bound: key_t) (t: tree) (lt: ms)
: Lemma (requires pow2heap_pred d upper_bound t /\ permutation (keys_of_tree t) lt)
(ensures permutation lt (keys (unzip d upper_bound t)))
(decreases t) | let rec unzip_repr (d:nat) (upper_bound:key_t) (t:tree) (lt:ms)
: Lemma
(requires
pow2heap_pred d upper_bound t /\
permutation (keys_of_tree t) lt)
(ensures permutation lt (keys (unzip d upper_bound t)))
(decreases t) =
match t with
| Leaf -> ()
| Internal left k right ->
let q = unzip (d - 1) upper_bound right in
unzip_repr (d - 1) upper_bound right (keys_of_tree right);
keys_append q [Internal left k Leaf]
(keys_of_tree right) (ms_append (keys_of_tree left)
(ms_append (ms_singleton k)
ms_empty)) | {
"file_name": "examples/data_structures/BinomialQueue.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 59,
"end_line": 520,
"start_col": 0,
"start_line": 505
} | (*
Copyright 2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Authors: Aseem Rastogi
*)
module BinomialQueue
module L = FStar.List.Tot
/// Some auxiliary lemmas
let rec last_cons (#a:Type) (x:a) (l:list a)
: Lemma
(requires Cons? l)
(ensures L.last (x::l) == L.last l)
[SMTPat (L.last (x::l))] =
match l with
| [_] -> ()
| _::tl -> last_cons x tl
/// We will maintain the priority queue as a forest
type tree =
| Leaf : tree
| Internal : tree -> key_t -> tree -> tree
/// Tree t is a complete binary tree of depth d
///
/// All its keys are <= upper_bound
///
/// If the left subtree is non-empty,
/// its root is maximum in its subtree
let rec pow2heap_pred (d:nat) (upper_bound:key_t) (t:tree) : prop =
match t with
| Leaf -> d == 0
| Internal left k right ->
0 < d /\
k <= upper_bound /\
pow2heap_pred (d - 1) k left /\
pow2heap_pred (d - 1) upper_bound right
/// A power-2-heap of depth d is an Internal tree whose right child is a Leaf,
/// and left child is a complete binary tree satisfying pow2heap_pred
/// with upper bound as the key k
let is_pow2heap (d:pos) (t:tree) : prop =
match t with
| Internal left k Leaf -> pow2heap_pred (d - 1) k left
| _ -> False
/// A list of trees is a binomial queue starting with depth d if:
type forest = list tree
let rec is_binomial_queue (d:pos) (l:forest)
: Tot prop (decreases l) =
match l with
| [] -> True
| hd::tl ->
(Leaf? hd \/ is_pow2heap d hd) /\ is_binomial_queue (d + 1) tl
/// We will also keep the binomial queue in a compact form,
/// truncating unnecessary empty trees from the forest
let is_compact (l:forest) = l == [] \/ Internal? (L.last l)
let is_priq (l:forest) = is_binomial_queue 1 l /\ is_compact l
/// The main priq type
let priq = l:forest{is_priq l}
let empty = []
/// We define a function to compact a forest
let rec all_leaf (l:forest{Cons? l}) : bool =
match l with
| [Leaf] -> true
| Leaf::tl -> all_leaf tl
| _ -> false
let rec mk_compact (l:forest) : forest =
match l with
| [] -> []
| _ ->
if all_leaf l then []
else let hd::tl = l in
hd::(mk_compact tl)
/// Correctness of mk_compact
let rec mk_compact_correctness (l:forest)
: Lemma (is_compact (mk_compact l))
[SMTPat (is_compact (mk_compact l))] =
match l with
| [] -> ()
| _ ->
if all_leaf l then ()
else mk_compact_correctness (L.tl l)
let rec mk_compact_preserves_binomial_queue (d:pos) (l:forest)
: Lemma
(requires is_binomial_queue d l)
(ensures is_binomial_queue d (mk_compact l))
(decreases l)
[SMTPat (is_binomial_queue d (mk_compact l))] =
match l with
| [] -> ()
| _ ->
if all_leaf l then ()
else mk_compact_preserves_binomial_queue (d + 1) (L.tl l)
/// smash is a key function combining two power of 2 heaps of depth d
/// into a power of 2 heap of depth (d + 1)
let smash (d:pos) (t1:tree) (t2:tree)
: Pure tree
(requires is_pow2heap d t1 /\ is_pow2heap d t2)
(ensures fun t -> is_pow2heap (d + 1) t) =
match t1, t2 with
| Internal left1 k1 Leaf, Internal left2 k2 Leaf ->
if k1 <= k2
then Internal (Internal left1 k1 left2) k2 Leaf
else Internal (Internal left2 k2 left1) k1 Leaf
/// carry adds t to q, preserving the binomial queue relation
///
/// It has a nice symmetery to carry in binary arithmetic
let rec carry (d:pos) (q:forest) (t:tree)
: Pure forest
(requires is_binomial_queue d q /\ is_pow2heap d t)
(ensures fun q -> is_binomial_queue d q)
(decreases q) =
match q with
| [] -> [t]
| Leaf::tl -> t::tl
| hd::tl ->
let q = carry (d + 1) tl (smash d hd t) in
Leaf::q
/// join combines two trees p and q, with the carry c,
/// preserving the binomial queue relation
///
/// It has a nice symmetry to binary addition
let rec join (d:pos) (p q:forest) (c:tree)
: Pure forest
(requires
is_binomial_queue d p /\
is_binomial_queue d q /\
(Leaf? c \/ is_pow2heap d c))
(ensures fun q -> is_binomial_queue d q)
(decreases L.length p) =
match p, q, c with
| [], _, Leaf -> q
| _, [], Leaf -> p
| [], _, _ -> carry d q c
| _, [], _ -> carry d p c
| Leaf::tl_p, Leaf::tl_q, _ ->
c::(join (d + 1) tl_p tl_q Leaf)
| hd_p::tl_p, Leaf::tl_q, Leaf ->
hd_p::(join (d + 1) tl_p tl_q Leaf)
| Leaf::tl_p, hd_q::tl_q, Leaf ->
hd_q::(join (d + 1) tl_p tl_q Leaf)
| Leaf::tl_p, hd_q::tl_q, _ ->
Leaf::(join (d + 1) tl_p tl_q (smash d hd_q c))
| hd_p::tl_p, Leaf::tl_q, _ ->
Leaf::(join (d + 1) tl_p tl_q (smash d hd_p c))
| hd_p::tl_p, hd_q::tl_q, c ->
c::(join (d + 1) tl_p tl_q (smash d hd_p hd_q))
/// insert is just carry of (Internal Leaf x Leaf) to q
let insert x q =
let l = carry 1 q (Internal Leaf x Leaf) in
mk_compact l
/// Towards delete max
/// find_max with the current max as max
let rec find_max (max:option key_t) (q:forest)
: Tot (option key_t) (decreases q) =
match q with
| [] -> max
| Leaf::q -> find_max max q
| (Internal _ k _)::q ->
match max with
| None -> find_max (Some k) q
| Some max -> find_max (if max < k then Some k else Some max) q
/// If q is a binomial queue starting at depth d,
/// and t is a power of 2 heap of depth (d + length q)
///
/// Then appending t to q is also a binomial queue
let rec binomial_queue_append (d:pos) (q:forest) (t:tree)
: Lemma
(requires
is_binomial_queue d q /\ is_pow2heap (L.length q + d) t)
(ensures is_binomial_queue d (L.append q [t]))
(decreases q) =
match q with
| [] -> ()
| _::q -> binomial_queue_append (d + 1) q t
/// unzip splits the tree t along its right spine
///
/// See https://www.cs.princeton.edu/~appel/BQ.pdf
///
/// The upper bound is only needed to show we return a priq,
/// may be it's not important?
let rec unzip (d:nat) (upper_bound:key_t) (t:tree)
: Pure priq
(requires pow2heap_pred d upper_bound t)
(ensures fun q -> L.length q == d) =
match t with
| Leaf -> []
| Internal left k right ->
let q = unzip (d - 1) upper_bound right in
binomial_queue_append 1 q (Internal left k Leaf);
L.append_length q [Internal left k Leaf];
L.lemma_append_last q [Internal left k Leaf];
L.append q [Internal left k Leaf]
/// Delete root of t, and unzip it
let heap_delete_max (d:pos) (t:tree)
: Pure priq
(requires is_pow2heap d t)
(ensures fun q -> L.length q == d - 1) =
match t with
| Internal left k Leaf -> unzip (d - 1) k left
/// Take the first tree in q whose root is >= m,
/// delete its root and unzip it,
/// return (the deleted root, q with that tree replaces with Leaf, unzipped forest)
///
let rec delete_max_aux (m:key_t) (d:pos) (q:forest)
: Pure (key_t & forest & priq)
(requires is_binomial_queue d q)
(ensures fun (x, q, _) -> m <= x /\ is_binomial_queue d q)
(decreases q) =
match q with
| [] -> m + 1, [], [] // this case won't arise
// we could strengthen preconditions
| Leaf::q ->
let x, q, new_q = delete_max_aux m (d + 1) q in
x, Leaf::q, new_q
| (Internal left x right)::q ->
if x < m
then let y, q, new_q = delete_max_aux m (d + 1) q in
y, (Internal left x right)::q, new_q
else x, Leaf::q, heap_delete_max d (Internal left x right)
/// delete_max finds the maximum key in the forest,
/// deletes it from its tree, and joins the remaining forests
let delete_max q =
match find_max None q with
| None -> None
| Some m ->
let x, q, new_q = delete_max_aux m 1 q in
let r = join 1 q new_q Leaf in
mk_compact_correctness r;
Some (x, mk_compact r)
/// merge is just join with Leaf as the carry
let merge p q =
let l = join 1 p q Leaf in
mk_compact l
/// Towards defining repr
let rec keys_of_tree (t:tree) : ms =
match t with
| Leaf -> ms_empty
| Internal left k right ->
ms_append (keys_of_tree left)
(ms_cons k (keys_of_tree right))
let rec keys (q:forest) : ms =
match q with
| [] -> ms_empty
| hd::tl -> ms_append (keys_of_tree hd) (keys tl)
let repr_t (t:tree) (l:ms) : prop =
permutation (keys_of_tree t) l
let repr_l (q:forest) (s:ms) : prop =
permutation (keys q) s
/// The main repr predicate saying s is a permutation of (keys q)
let repr q s = repr_l q s
let empty_repr _ = ()
/// Correctness of carry and join
let smash_repr (d:pos) (t1 t2:tree) (l1 l2:ms)
: Lemma
(requires
is_pow2heap d t1 /\
is_pow2heap d t2 /\
t1 `repr_t` l1 /\
t2 `repr_t` l2)
(ensures smash d t1 t2 `repr_t` (ms_append l1 l2)) = ()
let rec carry_repr (d:pos) (q:forest) (t:tree) (lq lt:ms)
: Lemma
(requires
is_binomial_queue d q /\
is_pow2heap d t /\
q `repr_l` lq /\
t `repr_t` lt)
(ensures carry d q t `repr_l` ms_append lq lt)
(decreases q) =
match q with
| [] -> ()
| Leaf::_ -> ()
| hd::tl ->
smash_repr d hd t (keys_of_tree hd) (keys_of_tree t);
carry_repr (d + 1) tl (smash d hd t)
(keys tl)
(ms_append (keys_of_tree hd) (keys_of_tree t))
#push-options "--z3rlimit 50 --fuel 1 --ifuel 1"
let rec join_repr (d:pos) (p q:forest) (c:tree)
(lp lq lc:ms)
: Lemma
(requires
is_binomial_queue d p /\
is_binomial_queue d q /\
(Leaf? c \/ is_pow2heap d c) /\
p `repr_l` lp /\
q `repr_l` lq /\
c `repr_t` lc)
(ensures join d p q c `repr_l` ms_append lp (ms_append lq lc))
(decreases p) =
match p, q, c with
| [], _, Leaf
| _, [], Leaf -> ()
| [], _, _ -> carry_repr d q c lq lc
| _, [], _ -> carry_repr d p c lp lc
| Leaf::tl_p, Leaf::tl_q, _ ->
join_repr (d + 1) tl_p tl_q Leaf
(keys tl_p) (keys tl_q) ms_empty
| hd_p::tl_p, Leaf::tl_q, Leaf ->
join_repr (d + 1) tl_p tl_q Leaf
(keys tl_p) (keys tl_q) ms_empty
| Leaf::tl_p, hd_q::tl_q, Leaf ->
join_repr (d + 1) tl_p tl_q Leaf
(keys tl_p) (keys tl_q) ms_empty
| Leaf::tl_p, hd_q::tl_q, _ ->
smash_repr d hd_q c (keys_of_tree hd_q) (keys_of_tree c);
join_repr (d + 1) tl_p tl_q (smash d hd_q c)
(keys tl_p) (keys tl_q)
(ms_append (keys_of_tree hd_q) (keys_of_tree c))
| hd_p::tl_p, Leaf::tl_q, _ ->
smash_repr d hd_p c (keys_of_tree hd_p) (keys_of_tree c);
join_repr (d + 1) tl_p tl_q (smash d hd_p c)
(keys tl_p) (keys tl_q)
(ms_append (keys_of_tree hd_p) (keys_of_tree c))
| hd_p::tl_p, hd_q::tl_q, c ->
smash_repr d hd_p hd_q (keys_of_tree hd_p) (keys_of_tree hd_q);
join_repr (d + 1) tl_p tl_q (smash d hd_p hd_q)
(keys tl_p) (keys tl_q)
(ms_append (keys_of_tree hd_p) (keys_of_tree hd_q))
#pop-options
/// mk_compact preserves keys
let rec all_leaf_keys (l:forest{Cons? l})
: Lemma
(requires Cons? l /\ all_leaf l)
(ensures permutation (keys l) ms_empty) =
match l with
| [Leaf] -> ()
| Leaf::tl -> all_leaf_keys tl
let rec compact_preserves_keys (q:forest)
: Lemma (permutation (keys q) (keys (mk_compact q)))
[SMTPat (keys (mk_compact q))] =
match q with
| [] -> ()
| _ ->
if all_leaf q
then all_leaf_keys q
else compact_preserves_keys (L.tl q)
/// insert and merge correctness follows from carry and joinx
let insert_repr x q s =
carry_repr 1 q (Internal Leaf x Leaf) s (ms_singleton x)
let merge_repr p q sp sq =
join_repr 1 p q Leaf sp sq ms_empty
/// Towards proof of delete correctness
let rec last_key_in_keys (l:forest)
: Lemma
(requires
Cons? l /\
Internal? (L.last l))
(ensures (let Internal _ k _ = L.last l in
S.subset (S.singleton k) (keys l).ms_elems)) =
match l with
| [Internal _ _ _] -> ()
| _::tl -> last_key_in_keys tl
let rec find_max_some_is_some (k:key_t) (l:forest)
: Lemma (ensures Some? (find_max (Some k) l) /\
k <= Some?.v (find_max (Some k) l))
(decreases l) =
match l with
| [] -> ()
| Leaf::tl -> find_max_some_is_some k tl
| (Internal _ k' _)::tl ->
let k = if k < k' then k' else k in
find_max_some_is_some k tl
let find_max_emp_repr_l (l:priq)
: Lemma
(requires l `repr_l` ms_empty)
(ensures find_max None l == None) =
match l with
| [] -> ()
| _ -> last_key_in_keys l
let rec find_max_emp_repr_r (l:forest)
: Lemma
(requires find_max None l == None)
(ensures permutation (keys l) ms_empty) =
match l with
| [] -> ()
| Leaf::tl -> find_max_emp_repr_r tl
| (Internal _ k _)::tl -> find_max_some_is_some k tl
#push-options "--warn_error -271"
let delete_max_none_repr p =
let delete_max_none_repr_l (l:priq)
: Lemma
(requires l `repr` ms_empty)
(ensures delete_max l == None)
[SMTPat ()] = find_max_emp_repr_l l in
let delete_max_none_repr_r (l:priq)
: Lemma
(requires delete_max l == None)
(ensures l `repr` ms_empty)
[SMTPat ()] = find_max_emp_repr_r l in
()
#pop-options
let rec keys_append (l1 l2:forest) (ms1 ms2:ms)
: Lemma (requires l1 `repr_l` ms1 /\ l2 `repr_l` ms2)
(ensures (L.append l1 l2) `repr_l` (ms_append ms1 ms2)) =
match l1 with
| [] -> ()
| _::tl -> keys_append tl l2 (keys tl) ms2 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "BinomialQueue.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Set",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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 | d: Prims.nat -> upper_bound: BinomialQueue.key_t -> t: BinomialQueue.tree -> lt: BinomialQueue.ms
-> FStar.Pervasives.Lemma
(requires
BinomialQueue.pow2heap_pred d upper_bound t /\
BinomialQueue.permutation (BinomialQueue.keys_of_tree t) lt)
(ensures
BinomialQueue.permutation lt (BinomialQueue.keys (BinomialQueue.unzip d upper_bound t)))
(decreases t) | FStar.Pervasives.Lemma | [
"lemma",
""
] | [] | [
"Prims.nat",
"BinomialQueue.key_t",
"BinomialQueue.tree",
"BinomialQueue.ms",
"BinomialQueue.keys_append",
"Prims.Cons",
"BinomialQueue.Internal",
"BinomialQueue.Leaf",
"Prims.Nil",
"BinomialQueue.keys_of_tree",
"BinomialQueue.ms_append",
"BinomialQueue.ms_singleton",
"BinomialQueue.ms_empty",
"Prims.unit",
"BinomialQueue.unzip_repr",
"Prims.op_Subtraction",
"BinomialQueue.priq",
"BinomialQueue.unzip",
"Prims.l_and",
"BinomialQueue.pow2heap_pred",
"BinomialQueue.permutation",
"Prims.squash",
"BinomialQueue.keys",
"FStar.Pervasives.pattern"
] | [
"recursion"
] | false | false | true | false | false | let rec unzip_repr (d: nat) (upper_bound: key_t) (t: tree) (lt: ms)
: Lemma (requires pow2heap_pred d upper_bound t /\ permutation (keys_of_tree t) lt)
(ensures permutation lt (keys (unzip d upper_bound t)))
(decreases t) =
| match t with
| Leaf -> ()
| Internal left k right ->
let q = unzip (d - 1) upper_bound right in
unzip_repr (d - 1) upper_bound right (keys_of_tree right);
keys_append q
[Internal left k Leaf]
(keys_of_tree right)
(ms_append (keys_of_tree left) (ms_append (ms_singleton k) ms_empty)) | false |
BinomialQueue.fst | BinomialQueue.heap_delete_max_repr | val heap_delete_max_repr (d: pos) (t: tree) (lt: ms)
: Lemma (requires is_pow2heap d t /\ t `repr_t` lt)
(ensures
(let Internal left k Leaf = t in
permutation lt (ms_append (ms_singleton k) (keys (heap_delete_max d t))))) | val heap_delete_max_repr (d: pos) (t: tree) (lt: ms)
: Lemma (requires is_pow2heap d t /\ t `repr_t` lt)
(ensures
(let Internal left k Leaf = t in
permutation lt (ms_append (ms_singleton k) (keys (heap_delete_max d t))))) | let heap_delete_max_repr (d:pos) (t:tree) (lt:ms)
: Lemma
(requires is_pow2heap d t /\ t `repr_t` lt)
(ensures (
let Internal left k Leaf = t in
permutation lt (ms_append (ms_singleton k)
(keys (heap_delete_max d t))))) =
let Internal left k Leaf = t in
unzip_repr (d - 1) k left (keys_of_tree left) | {
"file_name": "examples/data_structures/BinomialQueue.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 47,
"end_line": 531,
"start_col": 0,
"start_line": 522
} | (*
Copyright 2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Authors: Aseem Rastogi
*)
module BinomialQueue
module L = FStar.List.Tot
/// Some auxiliary lemmas
let rec last_cons (#a:Type) (x:a) (l:list a)
: Lemma
(requires Cons? l)
(ensures L.last (x::l) == L.last l)
[SMTPat (L.last (x::l))] =
match l with
| [_] -> ()
| _::tl -> last_cons x tl
/// We will maintain the priority queue as a forest
type tree =
| Leaf : tree
| Internal : tree -> key_t -> tree -> tree
/// Tree t is a complete binary tree of depth d
///
/// All its keys are <= upper_bound
///
/// If the left subtree is non-empty,
/// its root is maximum in its subtree
let rec pow2heap_pred (d:nat) (upper_bound:key_t) (t:tree) : prop =
match t with
| Leaf -> d == 0
| Internal left k right ->
0 < d /\
k <= upper_bound /\
pow2heap_pred (d - 1) k left /\
pow2heap_pred (d - 1) upper_bound right
/// A power-2-heap of depth d is an Internal tree whose right child is a Leaf,
/// and left child is a complete binary tree satisfying pow2heap_pred
/// with upper bound as the key k
let is_pow2heap (d:pos) (t:tree) : prop =
match t with
| Internal left k Leaf -> pow2heap_pred (d - 1) k left
| _ -> False
/// A list of trees is a binomial queue starting with depth d if:
type forest = list tree
let rec is_binomial_queue (d:pos) (l:forest)
: Tot prop (decreases l) =
match l with
| [] -> True
| hd::tl ->
(Leaf? hd \/ is_pow2heap d hd) /\ is_binomial_queue (d + 1) tl
/// We will also keep the binomial queue in a compact form,
/// truncating unnecessary empty trees from the forest
let is_compact (l:forest) = l == [] \/ Internal? (L.last l)
let is_priq (l:forest) = is_binomial_queue 1 l /\ is_compact l
/// The main priq type
let priq = l:forest{is_priq l}
let empty = []
/// We define a function to compact a forest
let rec all_leaf (l:forest{Cons? l}) : bool =
match l with
| [Leaf] -> true
| Leaf::tl -> all_leaf tl
| _ -> false
let rec mk_compact (l:forest) : forest =
match l with
| [] -> []
| _ ->
if all_leaf l then []
else let hd::tl = l in
hd::(mk_compact tl)
/// Correctness of mk_compact
let rec mk_compact_correctness (l:forest)
: Lemma (is_compact (mk_compact l))
[SMTPat (is_compact (mk_compact l))] =
match l with
| [] -> ()
| _ ->
if all_leaf l then ()
else mk_compact_correctness (L.tl l)
let rec mk_compact_preserves_binomial_queue (d:pos) (l:forest)
: Lemma
(requires is_binomial_queue d l)
(ensures is_binomial_queue d (mk_compact l))
(decreases l)
[SMTPat (is_binomial_queue d (mk_compact l))] =
match l with
| [] -> ()
| _ ->
if all_leaf l then ()
else mk_compact_preserves_binomial_queue (d + 1) (L.tl l)
/// smash is a key function combining two power of 2 heaps of depth d
/// into a power of 2 heap of depth (d + 1)
let smash (d:pos) (t1:tree) (t2:tree)
: Pure tree
(requires is_pow2heap d t1 /\ is_pow2heap d t2)
(ensures fun t -> is_pow2heap (d + 1) t) =
match t1, t2 with
| Internal left1 k1 Leaf, Internal left2 k2 Leaf ->
if k1 <= k2
then Internal (Internal left1 k1 left2) k2 Leaf
else Internal (Internal left2 k2 left1) k1 Leaf
/// carry adds t to q, preserving the binomial queue relation
///
/// It has a nice symmetery to carry in binary arithmetic
let rec carry (d:pos) (q:forest) (t:tree)
: Pure forest
(requires is_binomial_queue d q /\ is_pow2heap d t)
(ensures fun q -> is_binomial_queue d q)
(decreases q) =
match q with
| [] -> [t]
| Leaf::tl -> t::tl
| hd::tl ->
let q = carry (d + 1) tl (smash d hd t) in
Leaf::q
/// join combines two trees p and q, with the carry c,
/// preserving the binomial queue relation
///
/// It has a nice symmetry to binary addition
let rec join (d:pos) (p q:forest) (c:tree)
: Pure forest
(requires
is_binomial_queue d p /\
is_binomial_queue d q /\
(Leaf? c \/ is_pow2heap d c))
(ensures fun q -> is_binomial_queue d q)
(decreases L.length p) =
match p, q, c with
| [], _, Leaf -> q
| _, [], Leaf -> p
| [], _, _ -> carry d q c
| _, [], _ -> carry d p c
| Leaf::tl_p, Leaf::tl_q, _ ->
c::(join (d + 1) tl_p tl_q Leaf)
| hd_p::tl_p, Leaf::tl_q, Leaf ->
hd_p::(join (d + 1) tl_p tl_q Leaf)
| Leaf::tl_p, hd_q::tl_q, Leaf ->
hd_q::(join (d + 1) tl_p tl_q Leaf)
| Leaf::tl_p, hd_q::tl_q, _ ->
Leaf::(join (d + 1) tl_p tl_q (smash d hd_q c))
| hd_p::tl_p, Leaf::tl_q, _ ->
Leaf::(join (d + 1) tl_p tl_q (smash d hd_p c))
| hd_p::tl_p, hd_q::tl_q, c ->
c::(join (d + 1) tl_p tl_q (smash d hd_p hd_q))
/// insert is just carry of (Internal Leaf x Leaf) to q
let insert x q =
let l = carry 1 q (Internal Leaf x Leaf) in
mk_compact l
/// Towards delete max
/// find_max with the current max as max
let rec find_max (max:option key_t) (q:forest)
: Tot (option key_t) (decreases q) =
match q with
| [] -> max
| Leaf::q -> find_max max q
| (Internal _ k _)::q ->
match max with
| None -> find_max (Some k) q
| Some max -> find_max (if max < k then Some k else Some max) q
/// If q is a binomial queue starting at depth d,
/// and t is a power of 2 heap of depth (d + length q)
///
/// Then appending t to q is also a binomial queue
let rec binomial_queue_append (d:pos) (q:forest) (t:tree)
: Lemma
(requires
is_binomial_queue d q /\ is_pow2heap (L.length q + d) t)
(ensures is_binomial_queue d (L.append q [t]))
(decreases q) =
match q with
| [] -> ()
| _::q -> binomial_queue_append (d + 1) q t
/// unzip splits the tree t along its right spine
///
/// See https://www.cs.princeton.edu/~appel/BQ.pdf
///
/// The upper bound is only needed to show we return a priq,
/// may be it's not important?
let rec unzip (d:nat) (upper_bound:key_t) (t:tree)
: Pure priq
(requires pow2heap_pred d upper_bound t)
(ensures fun q -> L.length q == d) =
match t with
| Leaf -> []
| Internal left k right ->
let q = unzip (d - 1) upper_bound right in
binomial_queue_append 1 q (Internal left k Leaf);
L.append_length q [Internal left k Leaf];
L.lemma_append_last q [Internal left k Leaf];
L.append q [Internal left k Leaf]
/// Delete root of t, and unzip it
let heap_delete_max (d:pos) (t:tree)
: Pure priq
(requires is_pow2heap d t)
(ensures fun q -> L.length q == d - 1) =
match t with
| Internal left k Leaf -> unzip (d - 1) k left
/// Take the first tree in q whose root is >= m,
/// delete its root and unzip it,
/// return (the deleted root, q with that tree replaces with Leaf, unzipped forest)
///
let rec delete_max_aux (m:key_t) (d:pos) (q:forest)
: Pure (key_t & forest & priq)
(requires is_binomial_queue d q)
(ensures fun (x, q, _) -> m <= x /\ is_binomial_queue d q)
(decreases q) =
match q with
| [] -> m + 1, [], [] // this case won't arise
// we could strengthen preconditions
| Leaf::q ->
let x, q, new_q = delete_max_aux m (d + 1) q in
x, Leaf::q, new_q
| (Internal left x right)::q ->
if x < m
then let y, q, new_q = delete_max_aux m (d + 1) q in
y, (Internal left x right)::q, new_q
else x, Leaf::q, heap_delete_max d (Internal left x right)
/// delete_max finds the maximum key in the forest,
/// deletes it from its tree, and joins the remaining forests
let delete_max q =
match find_max None q with
| None -> None
| Some m ->
let x, q, new_q = delete_max_aux m 1 q in
let r = join 1 q new_q Leaf in
mk_compact_correctness r;
Some (x, mk_compact r)
/// merge is just join with Leaf as the carry
let merge p q =
let l = join 1 p q Leaf in
mk_compact l
/// Towards defining repr
let rec keys_of_tree (t:tree) : ms =
match t with
| Leaf -> ms_empty
| Internal left k right ->
ms_append (keys_of_tree left)
(ms_cons k (keys_of_tree right))
let rec keys (q:forest) : ms =
match q with
| [] -> ms_empty
| hd::tl -> ms_append (keys_of_tree hd) (keys tl)
let repr_t (t:tree) (l:ms) : prop =
permutation (keys_of_tree t) l
let repr_l (q:forest) (s:ms) : prop =
permutation (keys q) s
/// The main repr predicate saying s is a permutation of (keys q)
let repr q s = repr_l q s
let empty_repr _ = ()
/// Correctness of carry and join
let smash_repr (d:pos) (t1 t2:tree) (l1 l2:ms)
: Lemma
(requires
is_pow2heap d t1 /\
is_pow2heap d t2 /\
t1 `repr_t` l1 /\
t2 `repr_t` l2)
(ensures smash d t1 t2 `repr_t` (ms_append l1 l2)) = ()
let rec carry_repr (d:pos) (q:forest) (t:tree) (lq lt:ms)
: Lemma
(requires
is_binomial_queue d q /\
is_pow2heap d t /\
q `repr_l` lq /\
t `repr_t` lt)
(ensures carry d q t `repr_l` ms_append lq lt)
(decreases q) =
match q with
| [] -> ()
| Leaf::_ -> ()
| hd::tl ->
smash_repr d hd t (keys_of_tree hd) (keys_of_tree t);
carry_repr (d + 1) tl (smash d hd t)
(keys tl)
(ms_append (keys_of_tree hd) (keys_of_tree t))
#push-options "--z3rlimit 50 --fuel 1 --ifuel 1"
let rec join_repr (d:pos) (p q:forest) (c:tree)
(lp lq lc:ms)
: Lemma
(requires
is_binomial_queue d p /\
is_binomial_queue d q /\
(Leaf? c \/ is_pow2heap d c) /\
p `repr_l` lp /\
q `repr_l` lq /\
c `repr_t` lc)
(ensures join d p q c `repr_l` ms_append lp (ms_append lq lc))
(decreases p) =
match p, q, c with
| [], _, Leaf
| _, [], Leaf -> ()
| [], _, _ -> carry_repr d q c lq lc
| _, [], _ -> carry_repr d p c lp lc
| Leaf::tl_p, Leaf::tl_q, _ ->
join_repr (d + 1) tl_p tl_q Leaf
(keys tl_p) (keys tl_q) ms_empty
| hd_p::tl_p, Leaf::tl_q, Leaf ->
join_repr (d + 1) tl_p tl_q Leaf
(keys tl_p) (keys tl_q) ms_empty
| Leaf::tl_p, hd_q::tl_q, Leaf ->
join_repr (d + 1) tl_p tl_q Leaf
(keys tl_p) (keys tl_q) ms_empty
| Leaf::tl_p, hd_q::tl_q, _ ->
smash_repr d hd_q c (keys_of_tree hd_q) (keys_of_tree c);
join_repr (d + 1) tl_p tl_q (smash d hd_q c)
(keys tl_p) (keys tl_q)
(ms_append (keys_of_tree hd_q) (keys_of_tree c))
| hd_p::tl_p, Leaf::tl_q, _ ->
smash_repr d hd_p c (keys_of_tree hd_p) (keys_of_tree c);
join_repr (d + 1) tl_p tl_q (smash d hd_p c)
(keys tl_p) (keys tl_q)
(ms_append (keys_of_tree hd_p) (keys_of_tree c))
| hd_p::tl_p, hd_q::tl_q, c ->
smash_repr d hd_p hd_q (keys_of_tree hd_p) (keys_of_tree hd_q);
join_repr (d + 1) tl_p tl_q (smash d hd_p hd_q)
(keys tl_p) (keys tl_q)
(ms_append (keys_of_tree hd_p) (keys_of_tree hd_q))
#pop-options
/// mk_compact preserves keys
let rec all_leaf_keys (l:forest{Cons? l})
: Lemma
(requires Cons? l /\ all_leaf l)
(ensures permutation (keys l) ms_empty) =
match l with
| [Leaf] -> ()
| Leaf::tl -> all_leaf_keys tl
let rec compact_preserves_keys (q:forest)
: Lemma (permutation (keys q) (keys (mk_compact q)))
[SMTPat (keys (mk_compact q))] =
match q with
| [] -> ()
| _ ->
if all_leaf q
then all_leaf_keys q
else compact_preserves_keys (L.tl q)
/// insert and merge correctness follows from carry and joinx
let insert_repr x q s =
carry_repr 1 q (Internal Leaf x Leaf) s (ms_singleton x)
let merge_repr p q sp sq =
join_repr 1 p q Leaf sp sq ms_empty
/// Towards proof of delete correctness
let rec last_key_in_keys (l:forest)
: Lemma
(requires
Cons? l /\
Internal? (L.last l))
(ensures (let Internal _ k _ = L.last l in
S.subset (S.singleton k) (keys l).ms_elems)) =
match l with
| [Internal _ _ _] -> ()
| _::tl -> last_key_in_keys tl
let rec find_max_some_is_some (k:key_t) (l:forest)
: Lemma (ensures Some? (find_max (Some k) l) /\
k <= Some?.v (find_max (Some k) l))
(decreases l) =
match l with
| [] -> ()
| Leaf::tl -> find_max_some_is_some k tl
| (Internal _ k' _)::tl ->
let k = if k < k' then k' else k in
find_max_some_is_some k tl
let find_max_emp_repr_l (l:priq)
: Lemma
(requires l `repr_l` ms_empty)
(ensures find_max None l == None) =
match l with
| [] -> ()
| _ -> last_key_in_keys l
let rec find_max_emp_repr_r (l:forest)
: Lemma
(requires find_max None l == None)
(ensures permutation (keys l) ms_empty) =
match l with
| [] -> ()
| Leaf::tl -> find_max_emp_repr_r tl
| (Internal _ k _)::tl -> find_max_some_is_some k tl
#push-options "--warn_error -271"
let delete_max_none_repr p =
let delete_max_none_repr_l (l:priq)
: Lemma
(requires l `repr` ms_empty)
(ensures delete_max l == None)
[SMTPat ()] = find_max_emp_repr_l l in
let delete_max_none_repr_r (l:priq)
: Lemma
(requires delete_max l == None)
(ensures l `repr` ms_empty)
[SMTPat ()] = find_max_emp_repr_r l in
()
#pop-options
let rec keys_append (l1 l2:forest) (ms1 ms2:ms)
: Lemma (requires l1 `repr_l` ms1 /\ l2 `repr_l` ms2)
(ensures (L.append l1 l2) `repr_l` (ms_append ms1 ms2)) =
match l1 with
| [] -> ()
| _::tl -> keys_append tl l2 (keys tl) ms2
let rec unzip_repr (d:nat) (upper_bound:key_t) (t:tree) (lt:ms)
: Lemma
(requires
pow2heap_pred d upper_bound t /\
permutation (keys_of_tree t) lt)
(ensures permutation lt (keys (unzip d upper_bound t)))
(decreases t) =
match t with
| Leaf -> ()
| Internal left k right ->
let q = unzip (d - 1) upper_bound right in
unzip_repr (d - 1) upper_bound right (keys_of_tree right);
keys_append q [Internal left k Leaf]
(keys_of_tree right) (ms_append (keys_of_tree left)
(ms_append (ms_singleton k)
ms_empty)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "BinomialQueue.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Set",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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 | d: Prims.pos -> t: BinomialQueue.tree -> lt: BinomialQueue.ms
-> FStar.Pervasives.Lemma (requires BinomialQueue.is_pow2heap d t /\ BinomialQueue.repr_t t lt)
(ensures
(let _ = t in
(let BinomialQueue.Internal _ k BinomialQueue.Leaf = _ in
BinomialQueue.permutation lt
(BinomialQueue.ms_append (BinomialQueue.ms_singleton k)
(BinomialQueue.keys (BinomialQueue.heap_delete_max d t))))
<:
Type0)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"BinomialQueue.tree",
"BinomialQueue.ms",
"BinomialQueue.key_t",
"BinomialQueue.unzip_repr",
"Prims.op_Subtraction",
"BinomialQueue.keys_of_tree",
"Prims.unit",
"Prims.l_and",
"BinomialQueue.is_pow2heap",
"BinomialQueue.repr_t",
"Prims.squash",
"BinomialQueue.permutation",
"BinomialQueue.ms_append",
"BinomialQueue.ms_singleton",
"BinomialQueue.keys",
"BinomialQueue.heap_delete_max",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let heap_delete_max_repr (d: pos) (t: tree) (lt: ms)
: Lemma (requires is_pow2heap d t /\ t `repr_t` lt)
(ensures
(let Internal left k Leaf = t in
permutation lt (ms_append (ms_singleton k) (keys (heap_delete_max d t))))) =
| let Internal left k Leaf = t in
unzip_repr (d - 1) k left (keys_of_tree left) | false |
BinomialQueue.fst | BinomialQueue.keys_append | val keys_append (l1 l2: forest) (ms1 ms2: ms)
: Lemma (requires l1 `repr_l` ms1 /\ l2 `repr_l` ms2)
(ensures (L.append l1 l2) `repr_l` (ms_append ms1 ms2)) | val keys_append (l1 l2: forest) (ms1 ms2: ms)
: Lemma (requires l1 `repr_l` ms1 /\ l2 `repr_l` ms2)
(ensures (L.append l1 l2) `repr_l` (ms_append ms1 ms2)) | let rec keys_append (l1 l2:forest) (ms1 ms2:ms)
: Lemma (requires l1 `repr_l` ms1 /\ l2 `repr_l` ms2)
(ensures (L.append l1 l2) `repr_l` (ms_append ms1 ms2)) =
match l1 with
| [] -> ()
| _::tl -> keys_append tl l2 (keys tl) ms2 | {
"file_name": "examples/data_structures/BinomialQueue.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 44,
"end_line": 503,
"start_col": 0,
"start_line": 497
} | (*
Copyright 2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Authors: Aseem Rastogi
*)
module BinomialQueue
module L = FStar.List.Tot
/// Some auxiliary lemmas
let rec last_cons (#a:Type) (x:a) (l:list a)
: Lemma
(requires Cons? l)
(ensures L.last (x::l) == L.last l)
[SMTPat (L.last (x::l))] =
match l with
| [_] -> ()
| _::tl -> last_cons x tl
/// We will maintain the priority queue as a forest
type tree =
| Leaf : tree
| Internal : tree -> key_t -> tree -> tree
/// Tree t is a complete binary tree of depth d
///
/// All its keys are <= upper_bound
///
/// If the left subtree is non-empty,
/// its root is maximum in its subtree
let rec pow2heap_pred (d:nat) (upper_bound:key_t) (t:tree) : prop =
match t with
| Leaf -> d == 0
| Internal left k right ->
0 < d /\
k <= upper_bound /\
pow2heap_pred (d - 1) k left /\
pow2heap_pred (d - 1) upper_bound right
/// A power-2-heap of depth d is an Internal tree whose right child is a Leaf,
/// and left child is a complete binary tree satisfying pow2heap_pred
/// with upper bound as the key k
let is_pow2heap (d:pos) (t:tree) : prop =
match t with
| Internal left k Leaf -> pow2heap_pred (d - 1) k left
| _ -> False
/// A list of trees is a binomial queue starting with depth d if:
type forest = list tree
let rec is_binomial_queue (d:pos) (l:forest)
: Tot prop (decreases l) =
match l with
| [] -> True
| hd::tl ->
(Leaf? hd \/ is_pow2heap d hd) /\ is_binomial_queue (d + 1) tl
/// We will also keep the binomial queue in a compact form,
/// truncating unnecessary empty trees from the forest
let is_compact (l:forest) = l == [] \/ Internal? (L.last l)
let is_priq (l:forest) = is_binomial_queue 1 l /\ is_compact l
/// The main priq type
let priq = l:forest{is_priq l}
let empty = []
/// We define a function to compact a forest
let rec all_leaf (l:forest{Cons? l}) : bool =
match l with
| [Leaf] -> true
| Leaf::tl -> all_leaf tl
| _ -> false
let rec mk_compact (l:forest) : forest =
match l with
| [] -> []
| _ ->
if all_leaf l then []
else let hd::tl = l in
hd::(mk_compact tl)
/// Correctness of mk_compact
let rec mk_compact_correctness (l:forest)
: Lemma (is_compact (mk_compact l))
[SMTPat (is_compact (mk_compact l))] =
match l with
| [] -> ()
| _ ->
if all_leaf l then ()
else mk_compact_correctness (L.tl l)
let rec mk_compact_preserves_binomial_queue (d:pos) (l:forest)
: Lemma
(requires is_binomial_queue d l)
(ensures is_binomial_queue d (mk_compact l))
(decreases l)
[SMTPat (is_binomial_queue d (mk_compact l))] =
match l with
| [] -> ()
| _ ->
if all_leaf l then ()
else mk_compact_preserves_binomial_queue (d + 1) (L.tl l)
/// smash is a key function combining two power of 2 heaps of depth d
/// into a power of 2 heap of depth (d + 1)
let smash (d:pos) (t1:tree) (t2:tree)
: Pure tree
(requires is_pow2heap d t1 /\ is_pow2heap d t2)
(ensures fun t -> is_pow2heap (d + 1) t) =
match t1, t2 with
| Internal left1 k1 Leaf, Internal left2 k2 Leaf ->
if k1 <= k2
then Internal (Internal left1 k1 left2) k2 Leaf
else Internal (Internal left2 k2 left1) k1 Leaf
/// carry adds t to q, preserving the binomial queue relation
///
/// It has a nice symmetery to carry in binary arithmetic
let rec carry (d:pos) (q:forest) (t:tree)
: Pure forest
(requires is_binomial_queue d q /\ is_pow2heap d t)
(ensures fun q -> is_binomial_queue d q)
(decreases q) =
match q with
| [] -> [t]
| Leaf::tl -> t::tl
| hd::tl ->
let q = carry (d + 1) tl (smash d hd t) in
Leaf::q
/// join combines two trees p and q, with the carry c,
/// preserving the binomial queue relation
///
/// It has a nice symmetry to binary addition
let rec join (d:pos) (p q:forest) (c:tree)
: Pure forest
(requires
is_binomial_queue d p /\
is_binomial_queue d q /\
(Leaf? c \/ is_pow2heap d c))
(ensures fun q -> is_binomial_queue d q)
(decreases L.length p) =
match p, q, c with
| [], _, Leaf -> q
| _, [], Leaf -> p
| [], _, _ -> carry d q c
| _, [], _ -> carry d p c
| Leaf::tl_p, Leaf::tl_q, _ ->
c::(join (d + 1) tl_p tl_q Leaf)
| hd_p::tl_p, Leaf::tl_q, Leaf ->
hd_p::(join (d + 1) tl_p tl_q Leaf)
| Leaf::tl_p, hd_q::tl_q, Leaf ->
hd_q::(join (d + 1) tl_p tl_q Leaf)
| Leaf::tl_p, hd_q::tl_q, _ ->
Leaf::(join (d + 1) tl_p tl_q (smash d hd_q c))
| hd_p::tl_p, Leaf::tl_q, _ ->
Leaf::(join (d + 1) tl_p tl_q (smash d hd_p c))
| hd_p::tl_p, hd_q::tl_q, c ->
c::(join (d + 1) tl_p tl_q (smash d hd_p hd_q))
/// insert is just carry of (Internal Leaf x Leaf) to q
let insert x q =
let l = carry 1 q (Internal Leaf x Leaf) in
mk_compact l
/// Towards delete max
/// find_max with the current max as max
let rec find_max (max:option key_t) (q:forest)
: Tot (option key_t) (decreases q) =
match q with
| [] -> max
| Leaf::q -> find_max max q
| (Internal _ k _)::q ->
match max with
| None -> find_max (Some k) q
| Some max -> find_max (if max < k then Some k else Some max) q
/// If q is a binomial queue starting at depth d,
/// and t is a power of 2 heap of depth (d + length q)
///
/// Then appending t to q is also a binomial queue
let rec binomial_queue_append (d:pos) (q:forest) (t:tree)
: Lemma
(requires
is_binomial_queue d q /\ is_pow2heap (L.length q + d) t)
(ensures is_binomial_queue d (L.append q [t]))
(decreases q) =
match q with
| [] -> ()
| _::q -> binomial_queue_append (d + 1) q t
/// unzip splits the tree t along its right spine
///
/// See https://www.cs.princeton.edu/~appel/BQ.pdf
///
/// The upper bound is only needed to show we return a priq,
/// may be it's not important?
let rec unzip (d:nat) (upper_bound:key_t) (t:tree)
: Pure priq
(requires pow2heap_pred d upper_bound t)
(ensures fun q -> L.length q == d) =
match t with
| Leaf -> []
| Internal left k right ->
let q = unzip (d - 1) upper_bound right in
binomial_queue_append 1 q (Internal left k Leaf);
L.append_length q [Internal left k Leaf];
L.lemma_append_last q [Internal left k Leaf];
L.append q [Internal left k Leaf]
/// Delete root of t, and unzip it
let heap_delete_max (d:pos) (t:tree)
: Pure priq
(requires is_pow2heap d t)
(ensures fun q -> L.length q == d - 1) =
match t with
| Internal left k Leaf -> unzip (d - 1) k left
/// Take the first tree in q whose root is >= m,
/// delete its root and unzip it,
/// return (the deleted root, q with that tree replaces with Leaf, unzipped forest)
///
let rec delete_max_aux (m:key_t) (d:pos) (q:forest)
: Pure (key_t & forest & priq)
(requires is_binomial_queue d q)
(ensures fun (x, q, _) -> m <= x /\ is_binomial_queue d q)
(decreases q) =
match q with
| [] -> m + 1, [], [] // this case won't arise
// we could strengthen preconditions
| Leaf::q ->
let x, q, new_q = delete_max_aux m (d + 1) q in
x, Leaf::q, new_q
| (Internal left x right)::q ->
if x < m
then let y, q, new_q = delete_max_aux m (d + 1) q in
y, (Internal left x right)::q, new_q
else x, Leaf::q, heap_delete_max d (Internal left x right)
/// delete_max finds the maximum key in the forest,
/// deletes it from its tree, and joins the remaining forests
let delete_max q =
match find_max None q with
| None -> None
| Some m ->
let x, q, new_q = delete_max_aux m 1 q in
let r = join 1 q new_q Leaf in
mk_compact_correctness r;
Some (x, mk_compact r)
/// merge is just join with Leaf as the carry
let merge p q =
let l = join 1 p q Leaf in
mk_compact l
/// Towards defining repr
let rec keys_of_tree (t:tree) : ms =
match t with
| Leaf -> ms_empty
| Internal left k right ->
ms_append (keys_of_tree left)
(ms_cons k (keys_of_tree right))
let rec keys (q:forest) : ms =
match q with
| [] -> ms_empty
| hd::tl -> ms_append (keys_of_tree hd) (keys tl)
let repr_t (t:tree) (l:ms) : prop =
permutation (keys_of_tree t) l
let repr_l (q:forest) (s:ms) : prop =
permutation (keys q) s
/// The main repr predicate saying s is a permutation of (keys q)
let repr q s = repr_l q s
let empty_repr _ = ()
/// Correctness of carry and join
let smash_repr (d:pos) (t1 t2:tree) (l1 l2:ms)
: Lemma
(requires
is_pow2heap d t1 /\
is_pow2heap d t2 /\
t1 `repr_t` l1 /\
t2 `repr_t` l2)
(ensures smash d t1 t2 `repr_t` (ms_append l1 l2)) = ()
let rec carry_repr (d:pos) (q:forest) (t:tree) (lq lt:ms)
: Lemma
(requires
is_binomial_queue d q /\
is_pow2heap d t /\
q `repr_l` lq /\
t `repr_t` lt)
(ensures carry d q t `repr_l` ms_append lq lt)
(decreases q) =
match q with
| [] -> ()
| Leaf::_ -> ()
| hd::tl ->
smash_repr d hd t (keys_of_tree hd) (keys_of_tree t);
carry_repr (d + 1) tl (smash d hd t)
(keys tl)
(ms_append (keys_of_tree hd) (keys_of_tree t))
#push-options "--z3rlimit 50 --fuel 1 --ifuel 1"
let rec join_repr (d:pos) (p q:forest) (c:tree)
(lp lq lc:ms)
: Lemma
(requires
is_binomial_queue d p /\
is_binomial_queue d q /\
(Leaf? c \/ is_pow2heap d c) /\
p `repr_l` lp /\
q `repr_l` lq /\
c `repr_t` lc)
(ensures join d p q c `repr_l` ms_append lp (ms_append lq lc))
(decreases p) =
match p, q, c with
| [], _, Leaf
| _, [], Leaf -> ()
| [], _, _ -> carry_repr d q c lq lc
| _, [], _ -> carry_repr d p c lp lc
| Leaf::tl_p, Leaf::tl_q, _ ->
join_repr (d + 1) tl_p tl_q Leaf
(keys tl_p) (keys tl_q) ms_empty
| hd_p::tl_p, Leaf::tl_q, Leaf ->
join_repr (d + 1) tl_p tl_q Leaf
(keys tl_p) (keys tl_q) ms_empty
| Leaf::tl_p, hd_q::tl_q, Leaf ->
join_repr (d + 1) tl_p tl_q Leaf
(keys tl_p) (keys tl_q) ms_empty
| Leaf::tl_p, hd_q::tl_q, _ ->
smash_repr d hd_q c (keys_of_tree hd_q) (keys_of_tree c);
join_repr (d + 1) tl_p tl_q (smash d hd_q c)
(keys tl_p) (keys tl_q)
(ms_append (keys_of_tree hd_q) (keys_of_tree c))
| hd_p::tl_p, Leaf::tl_q, _ ->
smash_repr d hd_p c (keys_of_tree hd_p) (keys_of_tree c);
join_repr (d + 1) tl_p tl_q (smash d hd_p c)
(keys tl_p) (keys tl_q)
(ms_append (keys_of_tree hd_p) (keys_of_tree c))
| hd_p::tl_p, hd_q::tl_q, c ->
smash_repr d hd_p hd_q (keys_of_tree hd_p) (keys_of_tree hd_q);
join_repr (d + 1) tl_p tl_q (smash d hd_p hd_q)
(keys tl_p) (keys tl_q)
(ms_append (keys_of_tree hd_p) (keys_of_tree hd_q))
#pop-options
/// mk_compact preserves keys
let rec all_leaf_keys (l:forest{Cons? l})
: Lemma
(requires Cons? l /\ all_leaf l)
(ensures permutation (keys l) ms_empty) =
match l with
| [Leaf] -> ()
| Leaf::tl -> all_leaf_keys tl
let rec compact_preserves_keys (q:forest)
: Lemma (permutation (keys q) (keys (mk_compact q)))
[SMTPat (keys (mk_compact q))] =
match q with
| [] -> ()
| _ ->
if all_leaf q
then all_leaf_keys q
else compact_preserves_keys (L.tl q)
/// insert and merge correctness follows from carry and joinx
let insert_repr x q s =
carry_repr 1 q (Internal Leaf x Leaf) s (ms_singleton x)
let merge_repr p q sp sq =
join_repr 1 p q Leaf sp sq ms_empty
/// Towards proof of delete correctness
let rec last_key_in_keys (l:forest)
: Lemma
(requires
Cons? l /\
Internal? (L.last l))
(ensures (let Internal _ k _ = L.last l in
S.subset (S.singleton k) (keys l).ms_elems)) =
match l with
| [Internal _ _ _] -> ()
| _::tl -> last_key_in_keys tl
let rec find_max_some_is_some (k:key_t) (l:forest)
: Lemma (ensures Some? (find_max (Some k) l) /\
k <= Some?.v (find_max (Some k) l))
(decreases l) =
match l with
| [] -> ()
| Leaf::tl -> find_max_some_is_some k tl
| (Internal _ k' _)::tl ->
let k = if k < k' then k' else k in
find_max_some_is_some k tl
let find_max_emp_repr_l (l:priq)
: Lemma
(requires l `repr_l` ms_empty)
(ensures find_max None l == None) =
match l with
| [] -> ()
| _ -> last_key_in_keys l
let rec find_max_emp_repr_r (l:forest)
: Lemma
(requires find_max None l == None)
(ensures permutation (keys l) ms_empty) =
match l with
| [] -> ()
| Leaf::tl -> find_max_emp_repr_r tl
| (Internal _ k _)::tl -> find_max_some_is_some k tl
#push-options "--warn_error -271"
let delete_max_none_repr p =
let delete_max_none_repr_l (l:priq)
: Lemma
(requires l `repr` ms_empty)
(ensures delete_max l == None)
[SMTPat ()] = find_max_emp_repr_l l in
let delete_max_none_repr_r (l:priq)
: Lemma
(requires delete_max l == None)
(ensures l `repr` ms_empty)
[SMTPat ()] = find_max_emp_repr_r l in
()
#pop-options | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "BinomialQueue.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Set",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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: BinomialQueue.forest ->
l2: BinomialQueue.forest ->
ms1: BinomialQueue.ms ->
ms2: BinomialQueue.ms
-> FStar.Pervasives.Lemma (requires BinomialQueue.repr_l l1 ms1 /\ BinomialQueue.repr_l l2 ms2)
(ensures BinomialQueue.repr_l (l1 @ l2) (BinomialQueue.ms_append ms1 ms2)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"BinomialQueue.forest",
"BinomialQueue.ms",
"BinomialQueue.tree",
"Prims.list",
"BinomialQueue.keys_append",
"BinomialQueue.keys",
"Prims.unit",
"Prims.l_and",
"BinomialQueue.repr_l",
"Prims.squash",
"FStar.List.Tot.Base.append",
"BinomialQueue.ms_append",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [
"recursion"
] | false | false | true | false | false | let rec keys_append (l1 l2: forest) (ms1 ms2: ms)
: Lemma (requires l1 `repr_l` ms1 /\ l2 `repr_l` ms2)
(ensures (L.append l1 l2) `repr_l` (ms_append ms1 ms2)) =
| match l1 with
| [] -> ()
| _ :: tl -> keys_append tl l2 (keys tl) ms2 | false |
BinomialQueue.fst | BinomialQueue.find_max_is_max | val find_max_is_max (d: pos) (kopt: option key_t) (q: forest)
: Lemma (requires is_binomial_queue d q /\ Some? (find_max kopt q))
(ensures
(let Some k = find_max kopt q in
max k (keys q).ms_elems))
(decreases q) | val find_max_is_max (d: pos) (kopt: option key_t) (q: forest)
: Lemma (requires is_binomial_queue d q /\ Some? (find_max kopt q))
(ensures
(let Some k = find_max kopt q in
max k (keys q).ms_elems))
(decreases q) | let rec find_max_is_max (d:pos) (kopt:option key_t) (q:forest)
: Lemma
(requires
is_binomial_queue d q /\
Some? (find_max kopt q))
(ensures
(let Some k = find_max kopt q in
max k (keys q).ms_elems))
(decreases q) =
match q with
| [] -> ()
| Leaf::q ->
find_max_is_max (d + 1) kopt q
| (Internal left k Leaf)::tl ->
tree_root_is_max d (Internal left k Leaf);
match kopt with
| None ->
find_max_is_max (d + 1) (Some k) tl;
find_max_some_is_some k tl
| Some k' ->
let k = if k' < k then k else k' in
find_max_is_max (d + 1) (Some k) tl;
find_max_some_is_some k tl | {
"file_name": "examples/data_structures/BinomialQueue.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 32,
"end_line": 629,
"start_col": 0,
"start_line": 607
} | (*
Copyright 2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Authors: Aseem Rastogi
*)
module BinomialQueue
module L = FStar.List.Tot
/// Some auxiliary lemmas
let rec last_cons (#a:Type) (x:a) (l:list a)
: Lemma
(requires Cons? l)
(ensures L.last (x::l) == L.last l)
[SMTPat (L.last (x::l))] =
match l with
| [_] -> ()
| _::tl -> last_cons x tl
/// We will maintain the priority queue as a forest
type tree =
| Leaf : tree
| Internal : tree -> key_t -> tree -> tree
/// Tree t is a complete binary tree of depth d
///
/// All its keys are <= upper_bound
///
/// If the left subtree is non-empty,
/// its root is maximum in its subtree
let rec pow2heap_pred (d:nat) (upper_bound:key_t) (t:tree) : prop =
match t with
| Leaf -> d == 0
| Internal left k right ->
0 < d /\
k <= upper_bound /\
pow2heap_pred (d - 1) k left /\
pow2heap_pred (d - 1) upper_bound right
/// A power-2-heap of depth d is an Internal tree whose right child is a Leaf,
/// and left child is a complete binary tree satisfying pow2heap_pred
/// with upper bound as the key k
let is_pow2heap (d:pos) (t:tree) : prop =
match t with
| Internal left k Leaf -> pow2heap_pred (d - 1) k left
| _ -> False
/// A list of trees is a binomial queue starting with depth d if:
type forest = list tree
let rec is_binomial_queue (d:pos) (l:forest)
: Tot prop (decreases l) =
match l with
| [] -> True
| hd::tl ->
(Leaf? hd \/ is_pow2heap d hd) /\ is_binomial_queue (d + 1) tl
/// We will also keep the binomial queue in a compact form,
/// truncating unnecessary empty trees from the forest
let is_compact (l:forest) = l == [] \/ Internal? (L.last l)
let is_priq (l:forest) = is_binomial_queue 1 l /\ is_compact l
/// The main priq type
let priq = l:forest{is_priq l}
let empty = []
/// We define a function to compact a forest
let rec all_leaf (l:forest{Cons? l}) : bool =
match l with
| [Leaf] -> true
| Leaf::tl -> all_leaf tl
| _ -> false
let rec mk_compact (l:forest) : forest =
match l with
| [] -> []
| _ ->
if all_leaf l then []
else let hd::tl = l in
hd::(mk_compact tl)
/// Correctness of mk_compact
let rec mk_compact_correctness (l:forest)
: Lemma (is_compact (mk_compact l))
[SMTPat (is_compact (mk_compact l))] =
match l with
| [] -> ()
| _ ->
if all_leaf l then ()
else mk_compact_correctness (L.tl l)
let rec mk_compact_preserves_binomial_queue (d:pos) (l:forest)
: Lemma
(requires is_binomial_queue d l)
(ensures is_binomial_queue d (mk_compact l))
(decreases l)
[SMTPat (is_binomial_queue d (mk_compact l))] =
match l with
| [] -> ()
| _ ->
if all_leaf l then ()
else mk_compact_preserves_binomial_queue (d + 1) (L.tl l)
/// smash is a key function combining two power of 2 heaps of depth d
/// into a power of 2 heap of depth (d + 1)
let smash (d:pos) (t1:tree) (t2:tree)
: Pure tree
(requires is_pow2heap d t1 /\ is_pow2heap d t2)
(ensures fun t -> is_pow2heap (d + 1) t) =
match t1, t2 with
| Internal left1 k1 Leaf, Internal left2 k2 Leaf ->
if k1 <= k2
then Internal (Internal left1 k1 left2) k2 Leaf
else Internal (Internal left2 k2 left1) k1 Leaf
/// carry adds t to q, preserving the binomial queue relation
///
/// It has a nice symmetery to carry in binary arithmetic
let rec carry (d:pos) (q:forest) (t:tree)
: Pure forest
(requires is_binomial_queue d q /\ is_pow2heap d t)
(ensures fun q -> is_binomial_queue d q)
(decreases q) =
match q with
| [] -> [t]
| Leaf::tl -> t::tl
| hd::tl ->
let q = carry (d + 1) tl (smash d hd t) in
Leaf::q
/// join combines two trees p and q, with the carry c,
/// preserving the binomial queue relation
///
/// It has a nice symmetry to binary addition
let rec join (d:pos) (p q:forest) (c:tree)
: Pure forest
(requires
is_binomial_queue d p /\
is_binomial_queue d q /\
(Leaf? c \/ is_pow2heap d c))
(ensures fun q -> is_binomial_queue d q)
(decreases L.length p) =
match p, q, c with
| [], _, Leaf -> q
| _, [], Leaf -> p
| [], _, _ -> carry d q c
| _, [], _ -> carry d p c
| Leaf::tl_p, Leaf::tl_q, _ ->
c::(join (d + 1) tl_p tl_q Leaf)
| hd_p::tl_p, Leaf::tl_q, Leaf ->
hd_p::(join (d + 1) tl_p tl_q Leaf)
| Leaf::tl_p, hd_q::tl_q, Leaf ->
hd_q::(join (d + 1) tl_p tl_q Leaf)
| Leaf::tl_p, hd_q::tl_q, _ ->
Leaf::(join (d + 1) tl_p tl_q (smash d hd_q c))
| hd_p::tl_p, Leaf::tl_q, _ ->
Leaf::(join (d + 1) tl_p tl_q (smash d hd_p c))
| hd_p::tl_p, hd_q::tl_q, c ->
c::(join (d + 1) tl_p tl_q (smash d hd_p hd_q))
/// insert is just carry of (Internal Leaf x Leaf) to q
let insert x q =
let l = carry 1 q (Internal Leaf x Leaf) in
mk_compact l
/// Towards delete max
/// find_max with the current max as max
let rec find_max (max:option key_t) (q:forest)
: Tot (option key_t) (decreases q) =
match q with
| [] -> max
| Leaf::q -> find_max max q
| (Internal _ k _)::q ->
match max with
| None -> find_max (Some k) q
| Some max -> find_max (if max < k then Some k else Some max) q
/// If q is a binomial queue starting at depth d,
/// and t is a power of 2 heap of depth (d + length q)
///
/// Then appending t to q is also a binomial queue
let rec binomial_queue_append (d:pos) (q:forest) (t:tree)
: Lemma
(requires
is_binomial_queue d q /\ is_pow2heap (L.length q + d) t)
(ensures is_binomial_queue d (L.append q [t]))
(decreases q) =
match q with
| [] -> ()
| _::q -> binomial_queue_append (d + 1) q t
/// unzip splits the tree t along its right spine
///
/// See https://www.cs.princeton.edu/~appel/BQ.pdf
///
/// The upper bound is only needed to show we return a priq,
/// may be it's not important?
let rec unzip (d:nat) (upper_bound:key_t) (t:tree)
: Pure priq
(requires pow2heap_pred d upper_bound t)
(ensures fun q -> L.length q == d) =
match t with
| Leaf -> []
| Internal left k right ->
let q = unzip (d - 1) upper_bound right in
binomial_queue_append 1 q (Internal left k Leaf);
L.append_length q [Internal left k Leaf];
L.lemma_append_last q [Internal left k Leaf];
L.append q [Internal left k Leaf]
/// Delete root of t, and unzip it
let heap_delete_max (d:pos) (t:tree)
: Pure priq
(requires is_pow2heap d t)
(ensures fun q -> L.length q == d - 1) =
match t with
| Internal left k Leaf -> unzip (d - 1) k left
/// Take the first tree in q whose root is >= m,
/// delete its root and unzip it,
/// return (the deleted root, q with that tree replaces with Leaf, unzipped forest)
///
let rec delete_max_aux (m:key_t) (d:pos) (q:forest)
: Pure (key_t & forest & priq)
(requires is_binomial_queue d q)
(ensures fun (x, q, _) -> m <= x /\ is_binomial_queue d q)
(decreases q) =
match q with
| [] -> m + 1, [], [] // this case won't arise
// we could strengthen preconditions
| Leaf::q ->
let x, q, new_q = delete_max_aux m (d + 1) q in
x, Leaf::q, new_q
| (Internal left x right)::q ->
if x < m
then let y, q, new_q = delete_max_aux m (d + 1) q in
y, (Internal left x right)::q, new_q
else x, Leaf::q, heap_delete_max d (Internal left x right)
/// delete_max finds the maximum key in the forest,
/// deletes it from its tree, and joins the remaining forests
let delete_max q =
match find_max None q with
| None -> None
| Some m ->
let x, q, new_q = delete_max_aux m 1 q in
let r = join 1 q new_q Leaf in
mk_compact_correctness r;
Some (x, mk_compact r)
/// merge is just join with Leaf as the carry
let merge p q =
let l = join 1 p q Leaf in
mk_compact l
/// Towards defining repr
let rec keys_of_tree (t:tree) : ms =
match t with
| Leaf -> ms_empty
| Internal left k right ->
ms_append (keys_of_tree left)
(ms_cons k (keys_of_tree right))
let rec keys (q:forest) : ms =
match q with
| [] -> ms_empty
| hd::tl -> ms_append (keys_of_tree hd) (keys tl)
let repr_t (t:tree) (l:ms) : prop =
permutation (keys_of_tree t) l
let repr_l (q:forest) (s:ms) : prop =
permutation (keys q) s
/// The main repr predicate saying s is a permutation of (keys q)
let repr q s = repr_l q s
let empty_repr _ = ()
/// Correctness of carry and join
let smash_repr (d:pos) (t1 t2:tree) (l1 l2:ms)
: Lemma
(requires
is_pow2heap d t1 /\
is_pow2heap d t2 /\
t1 `repr_t` l1 /\
t2 `repr_t` l2)
(ensures smash d t1 t2 `repr_t` (ms_append l1 l2)) = ()
let rec carry_repr (d:pos) (q:forest) (t:tree) (lq lt:ms)
: Lemma
(requires
is_binomial_queue d q /\
is_pow2heap d t /\
q `repr_l` lq /\
t `repr_t` lt)
(ensures carry d q t `repr_l` ms_append lq lt)
(decreases q) =
match q with
| [] -> ()
| Leaf::_ -> ()
| hd::tl ->
smash_repr d hd t (keys_of_tree hd) (keys_of_tree t);
carry_repr (d + 1) tl (smash d hd t)
(keys tl)
(ms_append (keys_of_tree hd) (keys_of_tree t))
#push-options "--z3rlimit 50 --fuel 1 --ifuel 1"
let rec join_repr (d:pos) (p q:forest) (c:tree)
(lp lq lc:ms)
: Lemma
(requires
is_binomial_queue d p /\
is_binomial_queue d q /\
(Leaf? c \/ is_pow2heap d c) /\
p `repr_l` lp /\
q `repr_l` lq /\
c `repr_t` lc)
(ensures join d p q c `repr_l` ms_append lp (ms_append lq lc))
(decreases p) =
match p, q, c with
| [], _, Leaf
| _, [], Leaf -> ()
| [], _, _ -> carry_repr d q c lq lc
| _, [], _ -> carry_repr d p c lp lc
| Leaf::tl_p, Leaf::tl_q, _ ->
join_repr (d + 1) tl_p tl_q Leaf
(keys tl_p) (keys tl_q) ms_empty
| hd_p::tl_p, Leaf::tl_q, Leaf ->
join_repr (d + 1) tl_p tl_q Leaf
(keys tl_p) (keys tl_q) ms_empty
| Leaf::tl_p, hd_q::tl_q, Leaf ->
join_repr (d + 1) tl_p tl_q Leaf
(keys tl_p) (keys tl_q) ms_empty
| Leaf::tl_p, hd_q::tl_q, _ ->
smash_repr d hd_q c (keys_of_tree hd_q) (keys_of_tree c);
join_repr (d + 1) tl_p tl_q (smash d hd_q c)
(keys tl_p) (keys tl_q)
(ms_append (keys_of_tree hd_q) (keys_of_tree c))
| hd_p::tl_p, Leaf::tl_q, _ ->
smash_repr d hd_p c (keys_of_tree hd_p) (keys_of_tree c);
join_repr (d + 1) tl_p tl_q (smash d hd_p c)
(keys tl_p) (keys tl_q)
(ms_append (keys_of_tree hd_p) (keys_of_tree c))
| hd_p::tl_p, hd_q::tl_q, c ->
smash_repr d hd_p hd_q (keys_of_tree hd_p) (keys_of_tree hd_q);
join_repr (d + 1) tl_p tl_q (smash d hd_p hd_q)
(keys tl_p) (keys tl_q)
(ms_append (keys_of_tree hd_p) (keys_of_tree hd_q))
#pop-options
/// mk_compact preserves keys
let rec all_leaf_keys (l:forest{Cons? l})
: Lemma
(requires Cons? l /\ all_leaf l)
(ensures permutation (keys l) ms_empty) =
match l with
| [Leaf] -> ()
| Leaf::tl -> all_leaf_keys tl
let rec compact_preserves_keys (q:forest)
: Lemma (permutation (keys q) (keys (mk_compact q)))
[SMTPat (keys (mk_compact q))] =
match q with
| [] -> ()
| _ ->
if all_leaf q
then all_leaf_keys q
else compact_preserves_keys (L.tl q)
/// insert and merge correctness follows from carry and joinx
let insert_repr x q s =
carry_repr 1 q (Internal Leaf x Leaf) s (ms_singleton x)
let merge_repr p q sp sq =
join_repr 1 p q Leaf sp sq ms_empty
/// Towards proof of delete correctness
let rec last_key_in_keys (l:forest)
: Lemma
(requires
Cons? l /\
Internal? (L.last l))
(ensures (let Internal _ k _ = L.last l in
S.subset (S.singleton k) (keys l).ms_elems)) =
match l with
| [Internal _ _ _] -> ()
| _::tl -> last_key_in_keys tl
let rec find_max_some_is_some (k:key_t) (l:forest)
: Lemma (ensures Some? (find_max (Some k) l) /\
k <= Some?.v (find_max (Some k) l))
(decreases l) =
match l with
| [] -> ()
| Leaf::tl -> find_max_some_is_some k tl
| (Internal _ k' _)::tl ->
let k = if k < k' then k' else k in
find_max_some_is_some k tl
let find_max_emp_repr_l (l:priq)
: Lemma
(requires l `repr_l` ms_empty)
(ensures find_max None l == None) =
match l with
| [] -> ()
| _ -> last_key_in_keys l
let rec find_max_emp_repr_r (l:forest)
: Lemma
(requires find_max None l == None)
(ensures permutation (keys l) ms_empty) =
match l with
| [] -> ()
| Leaf::tl -> find_max_emp_repr_r tl
| (Internal _ k _)::tl -> find_max_some_is_some k tl
#push-options "--warn_error -271"
let delete_max_none_repr p =
let delete_max_none_repr_l (l:priq)
: Lemma
(requires l `repr` ms_empty)
(ensures delete_max l == None)
[SMTPat ()] = find_max_emp_repr_l l in
let delete_max_none_repr_r (l:priq)
: Lemma
(requires delete_max l == None)
(ensures l `repr` ms_empty)
[SMTPat ()] = find_max_emp_repr_r l in
()
#pop-options
let rec keys_append (l1 l2:forest) (ms1 ms2:ms)
: Lemma (requires l1 `repr_l` ms1 /\ l2 `repr_l` ms2)
(ensures (L.append l1 l2) `repr_l` (ms_append ms1 ms2)) =
match l1 with
| [] -> ()
| _::tl -> keys_append tl l2 (keys tl) ms2
let rec unzip_repr (d:nat) (upper_bound:key_t) (t:tree) (lt:ms)
: Lemma
(requires
pow2heap_pred d upper_bound t /\
permutation (keys_of_tree t) lt)
(ensures permutation lt (keys (unzip d upper_bound t)))
(decreases t) =
match t with
| Leaf -> ()
| Internal left k right ->
let q = unzip (d - 1) upper_bound right in
unzip_repr (d - 1) upper_bound right (keys_of_tree right);
keys_append q [Internal left k Leaf]
(keys_of_tree right) (ms_append (keys_of_tree left)
(ms_append (ms_singleton k)
ms_empty))
let heap_delete_max_repr (d:pos) (t:tree) (lt:ms)
: Lemma
(requires is_pow2heap d t /\ t `repr_t` lt)
(ensures (
let Internal left k Leaf = t in
permutation lt (ms_append (ms_singleton k)
(keys (heap_delete_max d t))))) =
let Internal left k Leaf = t in
unzip_repr (d - 1) k left (keys_of_tree left)
let max (k:key_t) (s:S.set key_t) =
forall (x:key_t). Set.mem x s ==> x <= k
let rec tree_root_is_max_aux (d:nat) (upper_bound:key_t) (t:tree)
: Lemma
(requires pow2heap_pred d upper_bound t)
(ensures max upper_bound (keys_of_tree t).ms_elems)
(decreases t) =
match t with
| Leaf -> ()
| Internal left k right ->
tree_root_is_max_aux (d - 1) k left;
tree_root_is_max_aux (d - 1) upper_bound right
let tree_root_is_max (d:pos) (t:tree)
: Lemma
(requires is_pow2heap d t)
(ensures
(let Internal left k Leaf = t in
max k (keys_of_tree left).ms_elems)) =
let Internal left k Leaf = t in
tree_root_is_max_aux (d - 1) k left
#push-options "--z3rlimit 40"
let rec delete_max_aux_repr (m:key_t) (d:pos) (q:forest)
(x:key_t) (r:forest) (p:priq)
(lq lr lp:ms)
: Lemma
(requires
S.mem m (keys q).ms_elems /\
is_binomial_queue d q /\
q `repr_l` lq /\
delete_max_aux m d q == (x, r, p) /\
r `repr_l` lr /\
p `repr_l` lp)
(ensures
permutation lq (ms_append (ms_singleton x)
(ms_append lr lp)))
(decreases q) =
match q with
| [] -> ()
| Leaf::q ->
delete_max_aux_repr m (d + 1) q x (L.tl r) p lq lr lp
| (Internal left x Leaf)::q ->
if x < m
then begin
tree_root_is_max d (Internal left x Leaf);
assert (~ (S.mem m (keys_of_tree left).ms_elems));
let y, _, _ = delete_max_aux m (d + 1) q in
delete_max_aux_repr m (d + 1) q y (L.tl r) p (keys q) (keys (L.tl r)) lp
end
else heap_delete_max_repr d (Internal left x Leaf) (keys_of_tree (Internal left x Leaf))
#pop-options
let rec find_max_mem_keys (kopt:option key_t) (q:forest)
: Lemma
(ensures
find_max kopt q == kopt \/
(let kopt = find_max kopt q in
Some? kopt /\ S.mem (Some?.v kopt) (keys q).ms_elems))
(decreases q) =
match q with
| [] -> ()
| Leaf::q -> find_max_mem_keys kopt q
| (Internal _ k _)::q ->
match kopt with
| None ->
find_max_mem_keys (Some k) q
| Some k' ->
let k = if k' < k then k else k' in
find_max_mem_keys (Some k) q | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "BinomialQueue.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Set",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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 | d: Prims.pos -> kopt: FStar.Pervasives.Native.option BinomialQueue.key_t -> q: BinomialQueue.forest
-> FStar.Pervasives.Lemma
(requires BinomialQueue.is_binomial_queue d q /\ Some? (BinomialQueue.find_max kopt q))
(ensures
(let _ = BinomialQueue.find_max kopt q in
(let FStar.Pervasives.Native.Some #_ k = _ in
BinomialQueue.max k (Mkms?.ms_elems (BinomialQueue.keys q)))
<:
Type0))
(decreases q) | FStar.Pervasives.Lemma | [
"lemma",
""
] | [] | [
"Prims.pos",
"FStar.Pervasives.Native.option",
"BinomialQueue.key_t",
"BinomialQueue.forest",
"Prims.list",
"BinomialQueue.tree",
"BinomialQueue.find_max_is_max",
"Prims.op_Addition",
"BinomialQueue.find_max_some_is_some",
"Prims.unit",
"FStar.Pervasives.Native.Some",
"Prims.op_LessThan",
"Prims.bool",
"BinomialQueue.tree_root_is_max",
"BinomialQueue.Internal",
"BinomialQueue.Leaf",
"Prims.l_and",
"BinomialQueue.is_binomial_queue",
"Prims.b2t",
"FStar.Pervasives.Native.uu___is_Some",
"BinomialQueue.find_max",
"Prims.squash",
"BinomialQueue.max",
"BinomialQueue.__proj__Mkms__item__ms_elems",
"BinomialQueue.keys",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [
"recursion"
] | false | false | true | false | false | let rec find_max_is_max (d: pos) (kopt: option key_t) (q: forest)
: Lemma (requires is_binomial_queue d q /\ Some? (find_max kopt q))
(ensures
(let Some k = find_max kopt q in
max k (keys q).ms_elems))
(decreases q) =
| match q with
| [] -> ()
| Leaf :: q -> find_max_is_max (d + 1) kopt q
| Internal left k Leaf :: tl ->
tree_root_is_max d (Internal left k Leaf);
match kopt with
| None ->
find_max_is_max (d + 1) (Some k) tl;
find_max_some_is_some k tl
| Some k' ->
let k = if k' < k then k else k' in
find_max_is_max (d + 1) (Some k) tl;
find_max_some_is_some k tl | false |
BinomialQueue.fst | BinomialQueue.merge_repr | val merge_repr (p q:priq) (sp sq:ms)
: Lemma (requires p `repr` sp /\ q `repr` sq)
(ensures merge p q `repr` ms_append sp sq) | val merge_repr (p q:priq) (sp sq:ms)
: Lemma (requires p `repr` sp /\ q `repr` sq)
(ensures merge p q `repr` ms_append sp sq) | let merge_repr p q sp sq =
join_repr 1 p q Leaf sp sq ms_empty | {
"file_name": "examples/data_structures/BinomialQueue.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 37,
"end_line": 437,
"start_col": 0,
"start_line": 436
} | (*
Copyright 2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Authors: Aseem Rastogi
*)
module BinomialQueue
module L = FStar.List.Tot
/// Some auxiliary lemmas
let rec last_cons (#a:Type) (x:a) (l:list a)
: Lemma
(requires Cons? l)
(ensures L.last (x::l) == L.last l)
[SMTPat (L.last (x::l))] =
match l with
| [_] -> ()
| _::tl -> last_cons x tl
/// We will maintain the priority queue as a forest
type tree =
| Leaf : tree
| Internal : tree -> key_t -> tree -> tree
/// Tree t is a complete binary tree of depth d
///
/// All its keys are <= upper_bound
///
/// If the left subtree is non-empty,
/// its root is maximum in its subtree
let rec pow2heap_pred (d:nat) (upper_bound:key_t) (t:tree) : prop =
match t with
| Leaf -> d == 0
| Internal left k right ->
0 < d /\
k <= upper_bound /\
pow2heap_pred (d - 1) k left /\
pow2heap_pred (d - 1) upper_bound right
/// A power-2-heap of depth d is an Internal tree whose right child is a Leaf,
/// and left child is a complete binary tree satisfying pow2heap_pred
/// with upper bound as the key k
let is_pow2heap (d:pos) (t:tree) : prop =
match t with
| Internal left k Leaf -> pow2heap_pred (d - 1) k left
| _ -> False
/// A list of trees is a binomial queue starting with depth d if:
type forest = list tree
let rec is_binomial_queue (d:pos) (l:forest)
: Tot prop (decreases l) =
match l with
| [] -> True
| hd::tl ->
(Leaf? hd \/ is_pow2heap d hd) /\ is_binomial_queue (d + 1) tl
/// We will also keep the binomial queue in a compact form,
/// truncating unnecessary empty trees from the forest
let is_compact (l:forest) = l == [] \/ Internal? (L.last l)
let is_priq (l:forest) = is_binomial_queue 1 l /\ is_compact l
/// The main priq type
let priq = l:forest{is_priq l}
let empty = []
/// We define a function to compact a forest
let rec all_leaf (l:forest{Cons? l}) : bool =
match l with
| [Leaf] -> true
| Leaf::tl -> all_leaf tl
| _ -> false
let rec mk_compact (l:forest) : forest =
match l with
| [] -> []
| _ ->
if all_leaf l then []
else let hd::tl = l in
hd::(mk_compact tl)
/// Correctness of mk_compact
let rec mk_compact_correctness (l:forest)
: Lemma (is_compact (mk_compact l))
[SMTPat (is_compact (mk_compact l))] =
match l with
| [] -> ()
| _ ->
if all_leaf l then ()
else mk_compact_correctness (L.tl l)
let rec mk_compact_preserves_binomial_queue (d:pos) (l:forest)
: Lemma
(requires is_binomial_queue d l)
(ensures is_binomial_queue d (mk_compact l))
(decreases l)
[SMTPat (is_binomial_queue d (mk_compact l))] =
match l with
| [] -> ()
| _ ->
if all_leaf l then ()
else mk_compact_preserves_binomial_queue (d + 1) (L.tl l)
/// smash is a key function combining two power of 2 heaps of depth d
/// into a power of 2 heap of depth (d + 1)
let smash (d:pos) (t1:tree) (t2:tree)
: Pure tree
(requires is_pow2heap d t1 /\ is_pow2heap d t2)
(ensures fun t -> is_pow2heap (d + 1) t) =
match t1, t2 with
| Internal left1 k1 Leaf, Internal left2 k2 Leaf ->
if k1 <= k2
then Internal (Internal left1 k1 left2) k2 Leaf
else Internal (Internal left2 k2 left1) k1 Leaf
/// carry adds t to q, preserving the binomial queue relation
///
/// It has a nice symmetery to carry in binary arithmetic
let rec carry (d:pos) (q:forest) (t:tree)
: Pure forest
(requires is_binomial_queue d q /\ is_pow2heap d t)
(ensures fun q -> is_binomial_queue d q)
(decreases q) =
match q with
| [] -> [t]
| Leaf::tl -> t::tl
| hd::tl ->
let q = carry (d + 1) tl (smash d hd t) in
Leaf::q
/// join combines two trees p and q, with the carry c,
/// preserving the binomial queue relation
///
/// It has a nice symmetry to binary addition
let rec join (d:pos) (p q:forest) (c:tree)
: Pure forest
(requires
is_binomial_queue d p /\
is_binomial_queue d q /\
(Leaf? c \/ is_pow2heap d c))
(ensures fun q -> is_binomial_queue d q)
(decreases L.length p) =
match p, q, c with
| [], _, Leaf -> q
| _, [], Leaf -> p
| [], _, _ -> carry d q c
| _, [], _ -> carry d p c
| Leaf::tl_p, Leaf::tl_q, _ ->
c::(join (d + 1) tl_p tl_q Leaf)
| hd_p::tl_p, Leaf::tl_q, Leaf ->
hd_p::(join (d + 1) tl_p tl_q Leaf)
| Leaf::tl_p, hd_q::tl_q, Leaf ->
hd_q::(join (d + 1) tl_p tl_q Leaf)
| Leaf::tl_p, hd_q::tl_q, _ ->
Leaf::(join (d + 1) tl_p tl_q (smash d hd_q c))
| hd_p::tl_p, Leaf::tl_q, _ ->
Leaf::(join (d + 1) tl_p tl_q (smash d hd_p c))
| hd_p::tl_p, hd_q::tl_q, c ->
c::(join (d + 1) tl_p tl_q (smash d hd_p hd_q))
/// insert is just carry of (Internal Leaf x Leaf) to q
let insert x q =
let l = carry 1 q (Internal Leaf x Leaf) in
mk_compact l
/// Towards delete max
/// find_max with the current max as max
let rec find_max (max:option key_t) (q:forest)
: Tot (option key_t) (decreases q) =
match q with
| [] -> max
| Leaf::q -> find_max max q
| (Internal _ k _)::q ->
match max with
| None -> find_max (Some k) q
| Some max -> find_max (if max < k then Some k else Some max) q
/// If q is a binomial queue starting at depth d,
/// and t is a power of 2 heap of depth (d + length q)
///
/// Then appending t to q is also a binomial queue
let rec binomial_queue_append (d:pos) (q:forest) (t:tree)
: Lemma
(requires
is_binomial_queue d q /\ is_pow2heap (L.length q + d) t)
(ensures is_binomial_queue d (L.append q [t]))
(decreases q) =
match q with
| [] -> ()
| _::q -> binomial_queue_append (d + 1) q t
/// unzip splits the tree t along its right spine
///
/// See https://www.cs.princeton.edu/~appel/BQ.pdf
///
/// The upper bound is only needed to show we return a priq,
/// may be it's not important?
let rec unzip (d:nat) (upper_bound:key_t) (t:tree)
: Pure priq
(requires pow2heap_pred d upper_bound t)
(ensures fun q -> L.length q == d) =
match t with
| Leaf -> []
| Internal left k right ->
let q = unzip (d - 1) upper_bound right in
binomial_queue_append 1 q (Internal left k Leaf);
L.append_length q [Internal left k Leaf];
L.lemma_append_last q [Internal left k Leaf];
L.append q [Internal left k Leaf]
/// Delete root of t, and unzip it
let heap_delete_max (d:pos) (t:tree)
: Pure priq
(requires is_pow2heap d t)
(ensures fun q -> L.length q == d - 1) =
match t with
| Internal left k Leaf -> unzip (d - 1) k left
/// Take the first tree in q whose root is >= m,
/// delete its root and unzip it,
/// return (the deleted root, q with that tree replaces with Leaf, unzipped forest)
///
let rec delete_max_aux (m:key_t) (d:pos) (q:forest)
: Pure (key_t & forest & priq)
(requires is_binomial_queue d q)
(ensures fun (x, q, _) -> m <= x /\ is_binomial_queue d q)
(decreases q) =
match q with
| [] -> m + 1, [], [] // this case won't arise
// we could strengthen preconditions
| Leaf::q ->
let x, q, new_q = delete_max_aux m (d + 1) q in
x, Leaf::q, new_q
| (Internal left x right)::q ->
if x < m
then let y, q, new_q = delete_max_aux m (d + 1) q in
y, (Internal left x right)::q, new_q
else x, Leaf::q, heap_delete_max d (Internal left x right)
/// delete_max finds the maximum key in the forest,
/// deletes it from its tree, and joins the remaining forests
let delete_max q =
match find_max None q with
| None -> None
| Some m ->
let x, q, new_q = delete_max_aux m 1 q in
let r = join 1 q new_q Leaf in
mk_compact_correctness r;
Some (x, mk_compact r)
/// merge is just join with Leaf as the carry
let merge p q =
let l = join 1 p q Leaf in
mk_compact l
/// Towards defining repr
let rec keys_of_tree (t:tree) : ms =
match t with
| Leaf -> ms_empty
| Internal left k right ->
ms_append (keys_of_tree left)
(ms_cons k (keys_of_tree right))
let rec keys (q:forest) : ms =
match q with
| [] -> ms_empty
| hd::tl -> ms_append (keys_of_tree hd) (keys tl)
let repr_t (t:tree) (l:ms) : prop =
permutation (keys_of_tree t) l
let repr_l (q:forest) (s:ms) : prop =
permutation (keys q) s
/// The main repr predicate saying s is a permutation of (keys q)
let repr q s = repr_l q s
let empty_repr _ = ()
/// Correctness of carry and join
let smash_repr (d:pos) (t1 t2:tree) (l1 l2:ms)
: Lemma
(requires
is_pow2heap d t1 /\
is_pow2heap d t2 /\
t1 `repr_t` l1 /\
t2 `repr_t` l2)
(ensures smash d t1 t2 `repr_t` (ms_append l1 l2)) = ()
let rec carry_repr (d:pos) (q:forest) (t:tree) (lq lt:ms)
: Lemma
(requires
is_binomial_queue d q /\
is_pow2heap d t /\
q `repr_l` lq /\
t `repr_t` lt)
(ensures carry d q t `repr_l` ms_append lq lt)
(decreases q) =
match q with
| [] -> ()
| Leaf::_ -> ()
| hd::tl ->
smash_repr d hd t (keys_of_tree hd) (keys_of_tree t);
carry_repr (d + 1) tl (smash d hd t)
(keys tl)
(ms_append (keys_of_tree hd) (keys_of_tree t))
#push-options "--z3rlimit 50 --fuel 1 --ifuel 1"
let rec join_repr (d:pos) (p q:forest) (c:tree)
(lp lq lc:ms)
: Lemma
(requires
is_binomial_queue d p /\
is_binomial_queue d q /\
(Leaf? c \/ is_pow2heap d c) /\
p `repr_l` lp /\
q `repr_l` lq /\
c `repr_t` lc)
(ensures join d p q c `repr_l` ms_append lp (ms_append lq lc))
(decreases p) =
match p, q, c with
| [], _, Leaf
| _, [], Leaf -> ()
| [], _, _ -> carry_repr d q c lq lc
| _, [], _ -> carry_repr d p c lp lc
| Leaf::tl_p, Leaf::tl_q, _ ->
join_repr (d + 1) tl_p tl_q Leaf
(keys tl_p) (keys tl_q) ms_empty
| hd_p::tl_p, Leaf::tl_q, Leaf ->
join_repr (d + 1) tl_p tl_q Leaf
(keys tl_p) (keys tl_q) ms_empty
| Leaf::tl_p, hd_q::tl_q, Leaf ->
join_repr (d + 1) tl_p tl_q Leaf
(keys tl_p) (keys tl_q) ms_empty
| Leaf::tl_p, hd_q::tl_q, _ ->
smash_repr d hd_q c (keys_of_tree hd_q) (keys_of_tree c);
join_repr (d + 1) tl_p tl_q (smash d hd_q c)
(keys tl_p) (keys tl_q)
(ms_append (keys_of_tree hd_q) (keys_of_tree c))
| hd_p::tl_p, Leaf::tl_q, _ ->
smash_repr d hd_p c (keys_of_tree hd_p) (keys_of_tree c);
join_repr (d + 1) tl_p tl_q (smash d hd_p c)
(keys tl_p) (keys tl_q)
(ms_append (keys_of_tree hd_p) (keys_of_tree c))
| hd_p::tl_p, hd_q::tl_q, c ->
smash_repr d hd_p hd_q (keys_of_tree hd_p) (keys_of_tree hd_q);
join_repr (d + 1) tl_p tl_q (smash d hd_p hd_q)
(keys tl_p) (keys tl_q)
(ms_append (keys_of_tree hd_p) (keys_of_tree hd_q))
#pop-options
/// mk_compact preserves keys
let rec all_leaf_keys (l:forest{Cons? l})
: Lemma
(requires Cons? l /\ all_leaf l)
(ensures permutation (keys l) ms_empty) =
match l with
| [Leaf] -> ()
| Leaf::tl -> all_leaf_keys tl
let rec compact_preserves_keys (q:forest)
: Lemma (permutation (keys q) (keys (mk_compact q)))
[SMTPat (keys (mk_compact q))] =
match q with
| [] -> ()
| _ ->
if all_leaf q
then all_leaf_keys q
else compact_preserves_keys (L.tl q)
/// insert and merge correctness follows from carry and joinx
let insert_repr x q s =
carry_repr 1 q (Internal Leaf x Leaf) s (ms_singleton x) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "BinomialQueue.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Set",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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: BinomialQueue.priq -> q: BinomialQueue.priq -> sp: BinomialQueue.ms -> sq: BinomialQueue.ms
-> FStar.Pervasives.Lemma (requires BinomialQueue.repr p sp /\ BinomialQueue.repr q sq)
(ensures BinomialQueue.repr (BinomialQueue.merge p q) (BinomialQueue.ms_append sp sq)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"BinomialQueue.priq",
"BinomialQueue.ms",
"BinomialQueue.join_repr",
"BinomialQueue.Leaf",
"BinomialQueue.ms_empty",
"Prims.unit"
] | [] | true | false | true | false | false | let merge_repr p q sp sq =
| join_repr 1 p q Leaf sp sq ms_empty | false |
BinomialQueue.fst | BinomialQueue.carry_repr | val carry_repr (d: pos) (q: forest) (t: tree) (lq lt: ms)
: Lemma (requires is_binomial_queue d q /\ is_pow2heap d t /\ q `repr_l` lq /\ t `repr_t` lt)
(ensures (carry d q t) `repr_l` (ms_append lq lt))
(decreases q) | val carry_repr (d: pos) (q: forest) (t: tree) (lq lt: ms)
: Lemma (requires is_binomial_queue d q /\ is_pow2heap d t /\ q `repr_l` lq /\ t `repr_t` lt)
(ensures (carry d q t) `repr_l` (ms_append lq lt))
(decreases q) | let rec carry_repr (d:pos) (q:forest) (t:tree) (lq lt:ms)
: Lemma
(requires
is_binomial_queue d q /\
is_pow2heap d t /\
q `repr_l` lq /\
t `repr_t` lt)
(ensures carry d q t `repr_l` ms_append lq lt)
(decreases q) =
match q with
| [] -> ()
| Leaf::_ -> ()
| hd::tl ->
smash_repr d hd t (keys_of_tree hd) (keys_of_tree t);
carry_repr (d + 1) tl (smash d hd t)
(keys tl)
(ms_append (keys_of_tree hd) (keys_of_tree t)) | {
"file_name": "examples/data_structures/BinomialQueue.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 52,
"end_line": 359,
"start_col": 0,
"start_line": 342
} | (*
Copyright 2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Authors: Aseem Rastogi
*)
module BinomialQueue
module L = FStar.List.Tot
/// Some auxiliary lemmas
let rec last_cons (#a:Type) (x:a) (l:list a)
: Lemma
(requires Cons? l)
(ensures L.last (x::l) == L.last l)
[SMTPat (L.last (x::l))] =
match l with
| [_] -> ()
| _::tl -> last_cons x tl
/// We will maintain the priority queue as a forest
type tree =
| Leaf : tree
| Internal : tree -> key_t -> tree -> tree
/// Tree t is a complete binary tree of depth d
///
/// All its keys are <= upper_bound
///
/// If the left subtree is non-empty,
/// its root is maximum in its subtree
let rec pow2heap_pred (d:nat) (upper_bound:key_t) (t:tree) : prop =
match t with
| Leaf -> d == 0
| Internal left k right ->
0 < d /\
k <= upper_bound /\
pow2heap_pred (d - 1) k left /\
pow2heap_pred (d - 1) upper_bound right
/// A power-2-heap of depth d is an Internal tree whose right child is a Leaf,
/// and left child is a complete binary tree satisfying pow2heap_pred
/// with upper bound as the key k
let is_pow2heap (d:pos) (t:tree) : prop =
match t with
| Internal left k Leaf -> pow2heap_pred (d - 1) k left
| _ -> False
/// A list of trees is a binomial queue starting with depth d if:
type forest = list tree
let rec is_binomial_queue (d:pos) (l:forest)
: Tot prop (decreases l) =
match l with
| [] -> True
| hd::tl ->
(Leaf? hd \/ is_pow2heap d hd) /\ is_binomial_queue (d + 1) tl
/// We will also keep the binomial queue in a compact form,
/// truncating unnecessary empty trees from the forest
let is_compact (l:forest) = l == [] \/ Internal? (L.last l)
let is_priq (l:forest) = is_binomial_queue 1 l /\ is_compact l
/// The main priq type
let priq = l:forest{is_priq l}
let empty = []
/// We define a function to compact a forest
let rec all_leaf (l:forest{Cons? l}) : bool =
match l with
| [Leaf] -> true
| Leaf::tl -> all_leaf tl
| _ -> false
let rec mk_compact (l:forest) : forest =
match l with
| [] -> []
| _ ->
if all_leaf l then []
else let hd::tl = l in
hd::(mk_compact tl)
/// Correctness of mk_compact
let rec mk_compact_correctness (l:forest)
: Lemma (is_compact (mk_compact l))
[SMTPat (is_compact (mk_compact l))] =
match l with
| [] -> ()
| _ ->
if all_leaf l then ()
else mk_compact_correctness (L.tl l)
let rec mk_compact_preserves_binomial_queue (d:pos) (l:forest)
: Lemma
(requires is_binomial_queue d l)
(ensures is_binomial_queue d (mk_compact l))
(decreases l)
[SMTPat (is_binomial_queue d (mk_compact l))] =
match l with
| [] -> ()
| _ ->
if all_leaf l then ()
else mk_compact_preserves_binomial_queue (d + 1) (L.tl l)
/// smash is a key function combining two power of 2 heaps of depth d
/// into a power of 2 heap of depth (d + 1)
let smash (d:pos) (t1:tree) (t2:tree)
: Pure tree
(requires is_pow2heap d t1 /\ is_pow2heap d t2)
(ensures fun t -> is_pow2heap (d + 1) t) =
match t1, t2 with
| Internal left1 k1 Leaf, Internal left2 k2 Leaf ->
if k1 <= k2
then Internal (Internal left1 k1 left2) k2 Leaf
else Internal (Internal left2 k2 left1) k1 Leaf
/// carry adds t to q, preserving the binomial queue relation
///
/// It has a nice symmetery to carry in binary arithmetic
let rec carry (d:pos) (q:forest) (t:tree)
: Pure forest
(requires is_binomial_queue d q /\ is_pow2heap d t)
(ensures fun q -> is_binomial_queue d q)
(decreases q) =
match q with
| [] -> [t]
| Leaf::tl -> t::tl
| hd::tl ->
let q = carry (d + 1) tl (smash d hd t) in
Leaf::q
/// join combines two trees p and q, with the carry c,
/// preserving the binomial queue relation
///
/// It has a nice symmetry to binary addition
let rec join (d:pos) (p q:forest) (c:tree)
: Pure forest
(requires
is_binomial_queue d p /\
is_binomial_queue d q /\
(Leaf? c \/ is_pow2heap d c))
(ensures fun q -> is_binomial_queue d q)
(decreases L.length p) =
match p, q, c with
| [], _, Leaf -> q
| _, [], Leaf -> p
| [], _, _ -> carry d q c
| _, [], _ -> carry d p c
| Leaf::tl_p, Leaf::tl_q, _ ->
c::(join (d + 1) tl_p tl_q Leaf)
| hd_p::tl_p, Leaf::tl_q, Leaf ->
hd_p::(join (d + 1) tl_p tl_q Leaf)
| Leaf::tl_p, hd_q::tl_q, Leaf ->
hd_q::(join (d + 1) tl_p tl_q Leaf)
| Leaf::tl_p, hd_q::tl_q, _ ->
Leaf::(join (d + 1) tl_p tl_q (smash d hd_q c))
| hd_p::tl_p, Leaf::tl_q, _ ->
Leaf::(join (d + 1) tl_p tl_q (smash d hd_p c))
| hd_p::tl_p, hd_q::tl_q, c ->
c::(join (d + 1) tl_p tl_q (smash d hd_p hd_q))
/// insert is just carry of (Internal Leaf x Leaf) to q
let insert x q =
let l = carry 1 q (Internal Leaf x Leaf) in
mk_compact l
/// Towards delete max
/// find_max with the current max as max
let rec find_max (max:option key_t) (q:forest)
: Tot (option key_t) (decreases q) =
match q with
| [] -> max
| Leaf::q -> find_max max q
| (Internal _ k _)::q ->
match max with
| None -> find_max (Some k) q
| Some max -> find_max (if max < k then Some k else Some max) q
/// If q is a binomial queue starting at depth d,
/// and t is a power of 2 heap of depth (d + length q)
///
/// Then appending t to q is also a binomial queue
let rec binomial_queue_append (d:pos) (q:forest) (t:tree)
: Lemma
(requires
is_binomial_queue d q /\ is_pow2heap (L.length q + d) t)
(ensures is_binomial_queue d (L.append q [t]))
(decreases q) =
match q with
| [] -> ()
| _::q -> binomial_queue_append (d + 1) q t
/// unzip splits the tree t along its right spine
///
/// See https://www.cs.princeton.edu/~appel/BQ.pdf
///
/// The upper bound is only needed to show we return a priq,
/// may be it's not important?
let rec unzip (d:nat) (upper_bound:key_t) (t:tree)
: Pure priq
(requires pow2heap_pred d upper_bound t)
(ensures fun q -> L.length q == d) =
match t with
| Leaf -> []
| Internal left k right ->
let q = unzip (d - 1) upper_bound right in
binomial_queue_append 1 q (Internal left k Leaf);
L.append_length q [Internal left k Leaf];
L.lemma_append_last q [Internal left k Leaf];
L.append q [Internal left k Leaf]
/// Delete root of t, and unzip it
let heap_delete_max (d:pos) (t:tree)
: Pure priq
(requires is_pow2heap d t)
(ensures fun q -> L.length q == d - 1) =
match t with
| Internal left k Leaf -> unzip (d - 1) k left
/// Take the first tree in q whose root is >= m,
/// delete its root and unzip it,
/// return (the deleted root, q with that tree replaces with Leaf, unzipped forest)
///
let rec delete_max_aux (m:key_t) (d:pos) (q:forest)
: Pure (key_t & forest & priq)
(requires is_binomial_queue d q)
(ensures fun (x, q, _) -> m <= x /\ is_binomial_queue d q)
(decreases q) =
match q with
| [] -> m + 1, [], [] // this case won't arise
// we could strengthen preconditions
| Leaf::q ->
let x, q, new_q = delete_max_aux m (d + 1) q in
x, Leaf::q, new_q
| (Internal left x right)::q ->
if x < m
then let y, q, new_q = delete_max_aux m (d + 1) q in
y, (Internal left x right)::q, new_q
else x, Leaf::q, heap_delete_max d (Internal left x right)
/// delete_max finds the maximum key in the forest,
/// deletes it from its tree, and joins the remaining forests
let delete_max q =
match find_max None q with
| None -> None
| Some m ->
let x, q, new_q = delete_max_aux m 1 q in
let r = join 1 q new_q Leaf in
mk_compact_correctness r;
Some (x, mk_compact r)
/// merge is just join with Leaf as the carry
let merge p q =
let l = join 1 p q Leaf in
mk_compact l
/// Towards defining repr
let rec keys_of_tree (t:tree) : ms =
match t with
| Leaf -> ms_empty
| Internal left k right ->
ms_append (keys_of_tree left)
(ms_cons k (keys_of_tree right))
let rec keys (q:forest) : ms =
match q with
| [] -> ms_empty
| hd::tl -> ms_append (keys_of_tree hd) (keys tl)
let repr_t (t:tree) (l:ms) : prop =
permutation (keys_of_tree t) l
let repr_l (q:forest) (s:ms) : prop =
permutation (keys q) s
/// The main repr predicate saying s is a permutation of (keys q)
let repr q s = repr_l q s
let empty_repr _ = ()
/// Correctness of carry and join
let smash_repr (d:pos) (t1 t2:tree) (l1 l2:ms)
: Lemma
(requires
is_pow2heap d t1 /\
is_pow2heap d t2 /\
t1 `repr_t` l1 /\
t2 `repr_t` l2)
(ensures smash d t1 t2 `repr_t` (ms_append l1 l2)) = () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "BinomialQueue.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Set",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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 |
d: Prims.pos ->
q: BinomialQueue.forest ->
t: BinomialQueue.tree ->
lq: BinomialQueue.ms ->
lt: BinomialQueue.ms
-> FStar.Pervasives.Lemma
(requires
BinomialQueue.is_binomial_queue d q /\ BinomialQueue.is_pow2heap d t /\
BinomialQueue.repr_l q lq /\ BinomialQueue.repr_t t lt)
(ensures BinomialQueue.repr_l (BinomialQueue.carry d q t) (BinomialQueue.ms_append lq lt))
(decreases q) | FStar.Pervasives.Lemma | [
"lemma",
""
] | [] | [
"Prims.pos",
"BinomialQueue.forest",
"BinomialQueue.tree",
"BinomialQueue.ms",
"Prims.list",
"BinomialQueue.carry_repr",
"Prims.op_Addition",
"BinomialQueue.smash",
"BinomialQueue.keys",
"BinomialQueue.ms_append",
"BinomialQueue.keys_of_tree",
"Prims.unit",
"BinomialQueue.smash_repr",
"Prims.l_and",
"BinomialQueue.is_binomial_queue",
"BinomialQueue.is_pow2heap",
"BinomialQueue.repr_l",
"BinomialQueue.repr_t",
"Prims.squash",
"BinomialQueue.carry",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [
"recursion"
] | false | false | true | false | false | let rec carry_repr (d: pos) (q: forest) (t: tree) (lq lt: ms)
: Lemma (requires is_binomial_queue d q /\ is_pow2heap d t /\ q `repr_l` lq /\ t `repr_t` lt)
(ensures (carry d q t) `repr_l` (ms_append lq lt))
(decreases q) =
| match q with
| [] -> ()
| Leaf :: _ -> ()
| hd :: tl ->
smash_repr d hd t (keys_of_tree hd) (keys_of_tree t);
carry_repr (d + 1) tl (smash d hd t) (keys tl) (ms_append (keys_of_tree hd) (keys_of_tree t)) | false |
BinomialQueue.fst | BinomialQueue.delete_max_aux_repr | val delete_max_aux_repr
(m: key_t)
(d: pos)
(q: forest)
(x: key_t)
(r: forest)
(p: priq)
(lq lr lp: ms)
: Lemma
(requires
S.mem m (keys q).ms_elems /\ is_binomial_queue d q /\ q `repr_l` lq /\
delete_max_aux m d q == (x, r, p) /\ r `repr_l` lr /\ p `repr_l` lp)
(ensures permutation lq (ms_append (ms_singleton x) (ms_append lr lp)))
(decreases q) | val delete_max_aux_repr
(m: key_t)
(d: pos)
(q: forest)
(x: key_t)
(r: forest)
(p: priq)
(lq lr lp: ms)
: Lemma
(requires
S.mem m (keys q).ms_elems /\ is_binomial_queue d q /\ q `repr_l` lq /\
delete_max_aux m d q == (x, r, p) /\ r `repr_l` lr /\ p `repr_l` lp)
(ensures permutation lq (ms_append (ms_singleton x) (ms_append lr lp)))
(decreases q) | let rec delete_max_aux_repr (m:key_t) (d:pos) (q:forest)
(x:key_t) (r:forest) (p:priq)
(lq lr lp:ms)
: Lemma
(requires
S.mem m (keys q).ms_elems /\
is_binomial_queue d q /\
q `repr_l` lq /\
delete_max_aux m d q == (x, r, p) /\
r `repr_l` lr /\
p `repr_l` lp)
(ensures
permutation lq (ms_append (ms_singleton x)
(ms_append lr lp)))
(decreases q) =
match q with
| [] -> ()
| Leaf::q ->
delete_max_aux_repr m (d + 1) q x (L.tl r) p lq lr lp
| (Internal left x Leaf)::q ->
if x < m
then begin
tree_root_is_max d (Internal left x Leaf);
assert (~ (S.mem m (keys_of_tree left).ms_elems));
let y, _, _ = delete_max_aux m (d + 1) q in
delete_max_aux_repr m (d + 1) q y (L.tl r) p (keys q) (keys (L.tl r)) lp
end
else heap_delete_max_repr d (Internal left x Leaf) (keys_of_tree (Internal left x Leaf)) | {
"file_name": "examples/data_structures/BinomialQueue.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 92,
"end_line": 586,
"start_col": 0,
"start_line": 558
} | (*
Copyright 2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Authors: Aseem Rastogi
*)
module BinomialQueue
module L = FStar.List.Tot
/// Some auxiliary lemmas
let rec last_cons (#a:Type) (x:a) (l:list a)
: Lemma
(requires Cons? l)
(ensures L.last (x::l) == L.last l)
[SMTPat (L.last (x::l))] =
match l with
| [_] -> ()
| _::tl -> last_cons x tl
/// We will maintain the priority queue as a forest
type tree =
| Leaf : tree
| Internal : tree -> key_t -> tree -> tree
/// Tree t is a complete binary tree of depth d
///
/// All its keys are <= upper_bound
///
/// If the left subtree is non-empty,
/// its root is maximum in its subtree
let rec pow2heap_pred (d:nat) (upper_bound:key_t) (t:tree) : prop =
match t with
| Leaf -> d == 0
| Internal left k right ->
0 < d /\
k <= upper_bound /\
pow2heap_pred (d - 1) k left /\
pow2heap_pred (d - 1) upper_bound right
/// A power-2-heap of depth d is an Internal tree whose right child is a Leaf,
/// and left child is a complete binary tree satisfying pow2heap_pred
/// with upper bound as the key k
let is_pow2heap (d:pos) (t:tree) : prop =
match t with
| Internal left k Leaf -> pow2heap_pred (d - 1) k left
| _ -> False
/// A list of trees is a binomial queue starting with depth d if:
type forest = list tree
let rec is_binomial_queue (d:pos) (l:forest)
: Tot prop (decreases l) =
match l with
| [] -> True
| hd::tl ->
(Leaf? hd \/ is_pow2heap d hd) /\ is_binomial_queue (d + 1) tl
/// We will also keep the binomial queue in a compact form,
/// truncating unnecessary empty trees from the forest
let is_compact (l:forest) = l == [] \/ Internal? (L.last l)
let is_priq (l:forest) = is_binomial_queue 1 l /\ is_compact l
/// The main priq type
let priq = l:forest{is_priq l}
let empty = []
/// We define a function to compact a forest
let rec all_leaf (l:forest{Cons? l}) : bool =
match l with
| [Leaf] -> true
| Leaf::tl -> all_leaf tl
| _ -> false
let rec mk_compact (l:forest) : forest =
match l with
| [] -> []
| _ ->
if all_leaf l then []
else let hd::tl = l in
hd::(mk_compact tl)
/// Correctness of mk_compact
let rec mk_compact_correctness (l:forest)
: Lemma (is_compact (mk_compact l))
[SMTPat (is_compact (mk_compact l))] =
match l with
| [] -> ()
| _ ->
if all_leaf l then ()
else mk_compact_correctness (L.tl l)
let rec mk_compact_preserves_binomial_queue (d:pos) (l:forest)
: Lemma
(requires is_binomial_queue d l)
(ensures is_binomial_queue d (mk_compact l))
(decreases l)
[SMTPat (is_binomial_queue d (mk_compact l))] =
match l with
| [] -> ()
| _ ->
if all_leaf l then ()
else mk_compact_preserves_binomial_queue (d + 1) (L.tl l)
/// smash is a key function combining two power of 2 heaps of depth d
/// into a power of 2 heap of depth (d + 1)
let smash (d:pos) (t1:tree) (t2:tree)
: Pure tree
(requires is_pow2heap d t1 /\ is_pow2heap d t2)
(ensures fun t -> is_pow2heap (d + 1) t) =
match t1, t2 with
| Internal left1 k1 Leaf, Internal left2 k2 Leaf ->
if k1 <= k2
then Internal (Internal left1 k1 left2) k2 Leaf
else Internal (Internal left2 k2 left1) k1 Leaf
/// carry adds t to q, preserving the binomial queue relation
///
/// It has a nice symmetery to carry in binary arithmetic
let rec carry (d:pos) (q:forest) (t:tree)
: Pure forest
(requires is_binomial_queue d q /\ is_pow2heap d t)
(ensures fun q -> is_binomial_queue d q)
(decreases q) =
match q with
| [] -> [t]
| Leaf::tl -> t::tl
| hd::tl ->
let q = carry (d + 1) tl (smash d hd t) in
Leaf::q
/// join combines two trees p and q, with the carry c,
/// preserving the binomial queue relation
///
/// It has a nice symmetry to binary addition
let rec join (d:pos) (p q:forest) (c:tree)
: Pure forest
(requires
is_binomial_queue d p /\
is_binomial_queue d q /\
(Leaf? c \/ is_pow2heap d c))
(ensures fun q -> is_binomial_queue d q)
(decreases L.length p) =
match p, q, c with
| [], _, Leaf -> q
| _, [], Leaf -> p
| [], _, _ -> carry d q c
| _, [], _ -> carry d p c
| Leaf::tl_p, Leaf::tl_q, _ ->
c::(join (d + 1) tl_p tl_q Leaf)
| hd_p::tl_p, Leaf::tl_q, Leaf ->
hd_p::(join (d + 1) tl_p tl_q Leaf)
| Leaf::tl_p, hd_q::tl_q, Leaf ->
hd_q::(join (d + 1) tl_p tl_q Leaf)
| Leaf::tl_p, hd_q::tl_q, _ ->
Leaf::(join (d + 1) tl_p tl_q (smash d hd_q c))
| hd_p::tl_p, Leaf::tl_q, _ ->
Leaf::(join (d + 1) tl_p tl_q (smash d hd_p c))
| hd_p::tl_p, hd_q::tl_q, c ->
c::(join (d + 1) tl_p tl_q (smash d hd_p hd_q))
/// insert is just carry of (Internal Leaf x Leaf) to q
let insert x q =
let l = carry 1 q (Internal Leaf x Leaf) in
mk_compact l
/// Towards delete max
/// find_max with the current max as max
let rec find_max (max:option key_t) (q:forest)
: Tot (option key_t) (decreases q) =
match q with
| [] -> max
| Leaf::q -> find_max max q
| (Internal _ k _)::q ->
match max with
| None -> find_max (Some k) q
| Some max -> find_max (if max < k then Some k else Some max) q
/// If q is a binomial queue starting at depth d,
/// and t is a power of 2 heap of depth (d + length q)
///
/// Then appending t to q is also a binomial queue
let rec binomial_queue_append (d:pos) (q:forest) (t:tree)
: Lemma
(requires
is_binomial_queue d q /\ is_pow2heap (L.length q + d) t)
(ensures is_binomial_queue d (L.append q [t]))
(decreases q) =
match q with
| [] -> ()
| _::q -> binomial_queue_append (d + 1) q t
/// unzip splits the tree t along its right spine
///
/// See https://www.cs.princeton.edu/~appel/BQ.pdf
///
/// The upper bound is only needed to show we return a priq,
/// may be it's not important?
let rec unzip (d:nat) (upper_bound:key_t) (t:tree)
: Pure priq
(requires pow2heap_pred d upper_bound t)
(ensures fun q -> L.length q == d) =
match t with
| Leaf -> []
| Internal left k right ->
let q = unzip (d - 1) upper_bound right in
binomial_queue_append 1 q (Internal left k Leaf);
L.append_length q [Internal left k Leaf];
L.lemma_append_last q [Internal left k Leaf];
L.append q [Internal left k Leaf]
/// Delete root of t, and unzip it
let heap_delete_max (d:pos) (t:tree)
: Pure priq
(requires is_pow2heap d t)
(ensures fun q -> L.length q == d - 1) =
match t with
| Internal left k Leaf -> unzip (d - 1) k left
/// Take the first tree in q whose root is >= m,
/// delete its root and unzip it,
/// return (the deleted root, q with that tree replaces with Leaf, unzipped forest)
///
let rec delete_max_aux (m:key_t) (d:pos) (q:forest)
: Pure (key_t & forest & priq)
(requires is_binomial_queue d q)
(ensures fun (x, q, _) -> m <= x /\ is_binomial_queue d q)
(decreases q) =
match q with
| [] -> m + 1, [], [] // this case won't arise
// we could strengthen preconditions
| Leaf::q ->
let x, q, new_q = delete_max_aux m (d + 1) q in
x, Leaf::q, new_q
| (Internal left x right)::q ->
if x < m
then let y, q, new_q = delete_max_aux m (d + 1) q in
y, (Internal left x right)::q, new_q
else x, Leaf::q, heap_delete_max d (Internal left x right)
/// delete_max finds the maximum key in the forest,
/// deletes it from its tree, and joins the remaining forests
let delete_max q =
match find_max None q with
| None -> None
| Some m ->
let x, q, new_q = delete_max_aux m 1 q in
let r = join 1 q new_q Leaf in
mk_compact_correctness r;
Some (x, mk_compact r)
/// merge is just join with Leaf as the carry
let merge p q =
let l = join 1 p q Leaf in
mk_compact l
/// Towards defining repr
let rec keys_of_tree (t:tree) : ms =
match t with
| Leaf -> ms_empty
| Internal left k right ->
ms_append (keys_of_tree left)
(ms_cons k (keys_of_tree right))
let rec keys (q:forest) : ms =
match q with
| [] -> ms_empty
| hd::tl -> ms_append (keys_of_tree hd) (keys tl)
let repr_t (t:tree) (l:ms) : prop =
permutation (keys_of_tree t) l
let repr_l (q:forest) (s:ms) : prop =
permutation (keys q) s
/// The main repr predicate saying s is a permutation of (keys q)
let repr q s = repr_l q s
let empty_repr _ = ()
/// Correctness of carry and join
let smash_repr (d:pos) (t1 t2:tree) (l1 l2:ms)
: Lemma
(requires
is_pow2heap d t1 /\
is_pow2heap d t2 /\
t1 `repr_t` l1 /\
t2 `repr_t` l2)
(ensures smash d t1 t2 `repr_t` (ms_append l1 l2)) = ()
let rec carry_repr (d:pos) (q:forest) (t:tree) (lq lt:ms)
: Lemma
(requires
is_binomial_queue d q /\
is_pow2heap d t /\
q `repr_l` lq /\
t `repr_t` lt)
(ensures carry d q t `repr_l` ms_append lq lt)
(decreases q) =
match q with
| [] -> ()
| Leaf::_ -> ()
| hd::tl ->
smash_repr d hd t (keys_of_tree hd) (keys_of_tree t);
carry_repr (d + 1) tl (smash d hd t)
(keys tl)
(ms_append (keys_of_tree hd) (keys_of_tree t))
#push-options "--z3rlimit 50 --fuel 1 --ifuel 1"
let rec join_repr (d:pos) (p q:forest) (c:tree)
(lp lq lc:ms)
: Lemma
(requires
is_binomial_queue d p /\
is_binomial_queue d q /\
(Leaf? c \/ is_pow2heap d c) /\
p `repr_l` lp /\
q `repr_l` lq /\
c `repr_t` lc)
(ensures join d p q c `repr_l` ms_append lp (ms_append lq lc))
(decreases p) =
match p, q, c with
| [], _, Leaf
| _, [], Leaf -> ()
| [], _, _ -> carry_repr d q c lq lc
| _, [], _ -> carry_repr d p c lp lc
| Leaf::tl_p, Leaf::tl_q, _ ->
join_repr (d + 1) tl_p tl_q Leaf
(keys tl_p) (keys tl_q) ms_empty
| hd_p::tl_p, Leaf::tl_q, Leaf ->
join_repr (d + 1) tl_p tl_q Leaf
(keys tl_p) (keys tl_q) ms_empty
| Leaf::tl_p, hd_q::tl_q, Leaf ->
join_repr (d + 1) tl_p tl_q Leaf
(keys tl_p) (keys tl_q) ms_empty
| Leaf::tl_p, hd_q::tl_q, _ ->
smash_repr d hd_q c (keys_of_tree hd_q) (keys_of_tree c);
join_repr (d + 1) tl_p tl_q (smash d hd_q c)
(keys tl_p) (keys tl_q)
(ms_append (keys_of_tree hd_q) (keys_of_tree c))
| hd_p::tl_p, Leaf::tl_q, _ ->
smash_repr d hd_p c (keys_of_tree hd_p) (keys_of_tree c);
join_repr (d + 1) tl_p tl_q (smash d hd_p c)
(keys tl_p) (keys tl_q)
(ms_append (keys_of_tree hd_p) (keys_of_tree c))
| hd_p::tl_p, hd_q::tl_q, c ->
smash_repr d hd_p hd_q (keys_of_tree hd_p) (keys_of_tree hd_q);
join_repr (d + 1) tl_p tl_q (smash d hd_p hd_q)
(keys tl_p) (keys tl_q)
(ms_append (keys_of_tree hd_p) (keys_of_tree hd_q))
#pop-options
/// mk_compact preserves keys
let rec all_leaf_keys (l:forest{Cons? l})
: Lemma
(requires Cons? l /\ all_leaf l)
(ensures permutation (keys l) ms_empty) =
match l with
| [Leaf] -> ()
| Leaf::tl -> all_leaf_keys tl
let rec compact_preserves_keys (q:forest)
: Lemma (permutation (keys q) (keys (mk_compact q)))
[SMTPat (keys (mk_compact q))] =
match q with
| [] -> ()
| _ ->
if all_leaf q
then all_leaf_keys q
else compact_preserves_keys (L.tl q)
/// insert and merge correctness follows from carry and joinx
let insert_repr x q s =
carry_repr 1 q (Internal Leaf x Leaf) s (ms_singleton x)
let merge_repr p q sp sq =
join_repr 1 p q Leaf sp sq ms_empty
/// Towards proof of delete correctness
let rec last_key_in_keys (l:forest)
: Lemma
(requires
Cons? l /\
Internal? (L.last l))
(ensures (let Internal _ k _ = L.last l in
S.subset (S.singleton k) (keys l).ms_elems)) =
match l with
| [Internal _ _ _] -> ()
| _::tl -> last_key_in_keys tl
let rec find_max_some_is_some (k:key_t) (l:forest)
: Lemma (ensures Some? (find_max (Some k) l) /\
k <= Some?.v (find_max (Some k) l))
(decreases l) =
match l with
| [] -> ()
| Leaf::tl -> find_max_some_is_some k tl
| (Internal _ k' _)::tl ->
let k = if k < k' then k' else k in
find_max_some_is_some k tl
let find_max_emp_repr_l (l:priq)
: Lemma
(requires l `repr_l` ms_empty)
(ensures find_max None l == None) =
match l with
| [] -> ()
| _ -> last_key_in_keys l
let rec find_max_emp_repr_r (l:forest)
: Lemma
(requires find_max None l == None)
(ensures permutation (keys l) ms_empty) =
match l with
| [] -> ()
| Leaf::tl -> find_max_emp_repr_r tl
| (Internal _ k _)::tl -> find_max_some_is_some k tl
#push-options "--warn_error -271"
let delete_max_none_repr p =
let delete_max_none_repr_l (l:priq)
: Lemma
(requires l `repr` ms_empty)
(ensures delete_max l == None)
[SMTPat ()] = find_max_emp_repr_l l in
let delete_max_none_repr_r (l:priq)
: Lemma
(requires delete_max l == None)
(ensures l `repr` ms_empty)
[SMTPat ()] = find_max_emp_repr_r l in
()
#pop-options
let rec keys_append (l1 l2:forest) (ms1 ms2:ms)
: Lemma (requires l1 `repr_l` ms1 /\ l2 `repr_l` ms2)
(ensures (L.append l1 l2) `repr_l` (ms_append ms1 ms2)) =
match l1 with
| [] -> ()
| _::tl -> keys_append tl l2 (keys tl) ms2
let rec unzip_repr (d:nat) (upper_bound:key_t) (t:tree) (lt:ms)
: Lemma
(requires
pow2heap_pred d upper_bound t /\
permutation (keys_of_tree t) lt)
(ensures permutation lt (keys (unzip d upper_bound t)))
(decreases t) =
match t with
| Leaf -> ()
| Internal left k right ->
let q = unzip (d - 1) upper_bound right in
unzip_repr (d - 1) upper_bound right (keys_of_tree right);
keys_append q [Internal left k Leaf]
(keys_of_tree right) (ms_append (keys_of_tree left)
(ms_append (ms_singleton k)
ms_empty))
let heap_delete_max_repr (d:pos) (t:tree) (lt:ms)
: Lemma
(requires is_pow2heap d t /\ t `repr_t` lt)
(ensures (
let Internal left k Leaf = t in
permutation lt (ms_append (ms_singleton k)
(keys (heap_delete_max d t))))) =
let Internal left k Leaf = t in
unzip_repr (d - 1) k left (keys_of_tree left)
let max (k:key_t) (s:S.set key_t) =
forall (x:key_t). Set.mem x s ==> x <= k
let rec tree_root_is_max_aux (d:nat) (upper_bound:key_t) (t:tree)
: Lemma
(requires pow2heap_pred d upper_bound t)
(ensures max upper_bound (keys_of_tree t).ms_elems)
(decreases t) =
match t with
| Leaf -> ()
| Internal left k right ->
tree_root_is_max_aux (d - 1) k left;
tree_root_is_max_aux (d - 1) upper_bound right
let tree_root_is_max (d:pos) (t:tree)
: Lemma
(requires is_pow2heap d t)
(ensures
(let Internal left k Leaf = t in
max k (keys_of_tree left).ms_elems)) =
let Internal left k Leaf = t in
tree_root_is_max_aux (d - 1) k left | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "BinomialQueue.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Set",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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": 40,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
m: BinomialQueue.key_t ->
d: Prims.pos ->
q: BinomialQueue.forest ->
x: BinomialQueue.key_t ->
r: BinomialQueue.forest ->
p: BinomialQueue.priq ->
lq: BinomialQueue.ms ->
lr: BinomialQueue.ms ->
lp: BinomialQueue.ms
-> FStar.Pervasives.Lemma
(requires
FStar.Set.mem m (Mkms?.ms_elems (BinomialQueue.keys q)) /\
BinomialQueue.is_binomial_queue d q /\ BinomialQueue.repr_l q lq /\
BinomialQueue.delete_max_aux m d q == (x, r, p) /\ BinomialQueue.repr_l r lr /\
BinomialQueue.repr_l p lp)
(ensures
BinomialQueue.permutation lq
(BinomialQueue.ms_append (BinomialQueue.ms_singleton x) (BinomialQueue.ms_append lr lp)))
(decreases q) | FStar.Pervasives.Lemma | [
"lemma",
""
] | [] | [
"BinomialQueue.key_t",
"Prims.pos",
"BinomialQueue.forest",
"BinomialQueue.priq",
"BinomialQueue.ms",
"Prims.list",
"BinomialQueue.tree",
"BinomialQueue.delete_max_aux_repr",
"Prims.op_Addition",
"FStar.List.Tot.Base.tl",
"Prims.op_LessThan",
"BinomialQueue.keys",
"Prims.unit",
"FStar.Pervasives.Native.tuple3",
"BinomialQueue.delete_max_aux",
"Prims._assert",
"Prims.l_not",
"Prims.b2t",
"FStar.Set.mem",
"BinomialQueue.__proj__Mkms__item__ms_elems",
"BinomialQueue.keys_of_tree",
"BinomialQueue.tree_root_is_max",
"BinomialQueue.Internal",
"BinomialQueue.Leaf",
"Prims.bool",
"BinomialQueue.heap_delete_max_repr",
"Prims.l_and",
"BinomialQueue.is_binomial_queue",
"BinomialQueue.repr_l",
"Prims.eq2",
"FStar.Pervasives.Native.Mktuple3",
"Prims.squash",
"BinomialQueue.permutation",
"BinomialQueue.ms_append",
"BinomialQueue.ms_singleton",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [
"recursion"
] | false | false | true | false | false | let rec delete_max_aux_repr
(m: key_t)
(d: pos)
(q: forest)
(x: key_t)
(r: forest)
(p: priq)
(lq lr lp: ms)
: Lemma
(requires
S.mem m (keys q).ms_elems /\ is_binomial_queue d q /\ q `repr_l` lq /\
delete_max_aux m d q == (x, r, p) /\ r `repr_l` lr /\ p `repr_l` lp)
(ensures permutation lq (ms_append (ms_singleton x) (ms_append lr lp)))
(decreases q) =
| match q with
| [] -> ()
| Leaf :: q -> delete_max_aux_repr m (d + 1) q x (L.tl r) p lq lr lp
| Internal left x Leaf :: q ->
if x < m
then
(tree_root_is_max d (Internal left x Leaf);
assert (~(S.mem m (keys_of_tree left).ms_elems));
let y, _, _ = delete_max_aux m (d + 1) q in
delete_max_aux_repr m (d + 1) q y (L.tl r) p (keys q) (keys (L.tl r)) lp)
else heap_delete_max_repr d (Internal left x Leaf) (keys_of_tree (Internal left x Leaf)) | false |
Steel.ST.C.Types.Base.fsti | Steel.ST.C.Types.Base.mk_fraction_split | val mk_fraction_split
(#opened: _)
(#t: Type)
(#td: typedef t)
(r: ref td)
(v: Ghost.erased t {fractionable td v})
(p1 p2: P.perm)
: STGhost unit
opened
(pts_to r v)
(fun _ -> (pts_to r (mk_fraction td v p1)) `star` (pts_to r (mk_fraction td v p2)))
(P.full_perm == p1 `P.sum_perm` p2)
(fun _ -> True) | val mk_fraction_split
(#opened: _)
(#t: Type)
(#td: typedef t)
(r: ref td)
(v: Ghost.erased t {fractionable td v})
(p1 p2: P.perm)
: STGhost unit
opened
(pts_to r v)
(fun _ -> (pts_to r (mk_fraction td v p1)) `star` (pts_to r (mk_fraction td v p2)))
(P.full_perm == p1 `P.sum_perm` p2)
(fun _ -> True) | let mk_fraction_split
(#opened: _)
(#t: Type) (#td: typedef t) (r: ref td) (v: Ghost.erased t { fractionable td v }) (p1 p2: P.perm) : STGhost unit opened
(pts_to r v)
(fun _ -> pts_to r (mk_fraction td v p1) `star` pts_to r (mk_fraction td v p2))
(P.full_perm == p1 `P.sum_perm` p2)
(fun _ -> True)
= mk_fraction_full td v;
rewrite (pts_to _ _) (pts_to _ _);
mk_fraction_split_gen r v P.full_perm p1 p2 | {
"file_name": "lib/steel/c/Steel.ST.C.Types.Base.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 45,
"end_line": 288,
"start_col": 0,
"start_line": 279
} | module Steel.ST.C.Types.Base
open Steel.ST.Util
module P = Steel.FractionalPermission
/// Helper to compose two permissions into one
val prod_perm (p1 p2: P.perm) : Pure P.perm
(requires True)
(ensures (fun p ->
((p1 `P.lesser_equal_perm` P.full_perm /\ p2 `P.lesser_equal_perm` P.full_perm) ==>
p `P.lesser_equal_perm` P.full_perm) /\
p.v == (let open FStar.Real in p1.v *. p2.v)
))
[@@noextract_to "krml"] // proof-only
val typedef (t: Type0) : Type0
inline_for_extraction [@@noextract_to "krml"]
let typeof (#t: Type0) (td: typedef t) : Tot Type0 = t
val fractionable (#t: Type0) (td: typedef t) (x: t) : GTot prop
val mk_fraction (#t: Type0) (td: typedef t) (x: t) (p: P.perm) : Ghost t
(requires (fractionable td x))
(ensures (fun y -> p `P.lesser_equal_perm` P.full_perm ==> fractionable td y))
val mk_fraction_full (#t: Type0) (td: typedef t) (x: t) : Lemma
(requires (fractionable td x))
(ensures (mk_fraction td x P.full_perm == x))
[SMTPat (mk_fraction td x P.full_perm)]
val mk_fraction_compose (#t: Type0) (td: typedef t) (x: t) (p1 p2: P.perm) : Lemma
(requires (fractionable td x /\ p1 `P.lesser_equal_perm` P.full_perm /\ p2 `P.lesser_equal_perm` P.full_perm))
(ensures (mk_fraction td (mk_fraction td x p1) p2 == mk_fraction td x (p1 `prod_perm` p2)))
val full (#t: Type0) (td: typedef t) (v: t) : GTot prop
val uninitialized (#t: Type0) (td: typedef t) : Ghost t
(requires True)
(ensures (fun y -> full td y /\ fractionable td y))
val unknown (#t: Type0) (td: typedef t) : Ghost t
(requires True)
(ensures (fun y -> fractionable td y))
val full_not_unknown
(#t: Type)
(td: typedef t)
(v: t)
: Lemma
(requires (full td v))
(ensures (~ (v == unknown td)))
[SMTPat (full td v)]
val mk_fraction_unknown (#t: Type0) (td: typedef t) (p: P.perm) : Lemma
(ensures (mk_fraction td (unknown td) p == unknown td))
val mk_fraction_eq_unknown (#t: Type0) (td: typedef t) (v: t) (p: P.perm) : Lemma
(requires (fractionable td v /\ mk_fraction td v p == unknown td))
(ensures (v == unknown td))
// To be extracted as: void*
[@@noextract_to "krml"] // primitive
val void_ptr : Type0
// To be extracted as: NULL
[@@noextract_to "krml"] // primitive
val void_null: void_ptr
// To be extracted as: *t
[@@noextract_to "krml"] // primitive
val ptr_gen ([@@@unused] t: Type) : Type0
[@@noextract_to "krml"] // primitive
val null_gen (t: Type) : Tot (ptr_gen t)
val ghost_void_ptr_of_ptr_gen (#[@@@unused] t: Type) (x: ptr_gen t) : GTot void_ptr
val ghost_ptr_gen_of_void_ptr (x: void_ptr) ([@@@unused] t: Type) : GTot (ptr_gen t)
val ghost_void_ptr_of_ptr_gen_of_void_ptr
(x: void_ptr)
(t: Type)
: Lemma
(ghost_void_ptr_of_ptr_gen (ghost_ptr_gen_of_void_ptr x t) == x)
[SMTPat (ghost_void_ptr_of_ptr_gen (ghost_ptr_gen_of_void_ptr x t))]
val ghost_ptr_gen_of_void_ptr_of_ptr_gen
(#t: Type)
(x: ptr_gen t)
: Lemma
(ghost_ptr_gen_of_void_ptr (ghost_void_ptr_of_ptr_gen x) t == x)
[SMTPat (ghost_ptr_gen_of_void_ptr (ghost_void_ptr_of_ptr_gen x) t)]
inline_for_extraction [@@noextract_to "krml"] // primitive
let ptr (#t: Type) (td: typedef t) : Tot Type0 = ptr_gen t
inline_for_extraction [@@noextract_to "krml"] // primitive
let null (#t: Type) (td: typedef t) : Tot (ptr td) = null_gen t
inline_for_extraction [@@noextract_to "krml"]
let ref (#t: Type) (td: typedef t) : Tot Type0 = (p: ptr td { ~ (p == null td) })
val pts_to (#t: Type) (#td: typedef t) (r: ref td) ([@@@smt_fallback] v: Ghost.erased t) : vprop
let pts_to_or_null
(#t: Type) (#td: typedef t) (p: ptr td) (v: Ghost.erased t) : vprop
= if FStar.StrongExcludedMiddle.strong_excluded_middle (p == null _)
then emp
else pts_to p v
[@@noextract_to "krml"] // primitive
val is_null
(#t: Type)
(#opened: _)
(#td: typedef t)
(#v: Ghost.erased t)
(p: ptr td)
: STAtomicBase bool false opened Unobservable
(pts_to_or_null p v)
(fun _ -> pts_to_or_null p v)
(True)
(fun res -> res == true <==> p == null _)
let assert_null
(#t: Type)
(#opened: _)
(#td: typedef t)
(#v: Ghost.erased t)
(p: ptr td)
: STGhost unit opened
(pts_to_or_null p v)
(fun _ -> emp)
(p == null _)
(fun _ -> True)
= rewrite (pts_to_or_null p v) emp
let assert_not_null
(#t: Type)
(#opened: _)
(#td: typedef t)
(#v: Ghost.erased t)
(p: ptr td)
: STGhost (squash (~ (p == null _))) opened
(pts_to_or_null p v)
(fun _ -> pts_to p v)
(~ (p == null _))
(fun _ -> True)
= rewrite (pts_to_or_null p v) (pts_to p v)
[@@noextract_to "krml"] // primitive
val void_ptr_of_ptr (#t: Type) (#opened: _) (#td: typedef t) (#v: Ghost.erased t) (x: ptr td) : STAtomicBase void_ptr false opened Unobservable
(pts_to_or_null x v)
(fun _ -> pts_to_or_null x v)
True
(fun y -> y == ghost_void_ptr_of_ptr_gen x)
[@@noextract_to "krml"] inline_for_extraction
let void_ptr_of_ref (#t: Type) (#opened: _) (#td: typedef t) (#v: Ghost.erased t) (x: ref td) : STAtomicBase void_ptr false opened Unobservable
(pts_to x v)
(fun _ -> pts_to x v)
True
(fun y -> y == ghost_void_ptr_of_ptr_gen x)
= rewrite (pts_to x v) (pts_to_or_null x v);
let res = void_ptr_of_ptr x in
rewrite (pts_to_or_null x v) (pts_to x v);
return res
[@@noextract_to "krml"] // primitive
val ptr_of_void_ptr (#t: Type) (#opened: _) (#td: typedef t) (#v: Ghost.erased t) (x: void_ptr) : STAtomicBase (ptr td) false opened Unobservable
(pts_to_or_null (ghost_ptr_gen_of_void_ptr x t <: ptr td) v)
(fun y -> pts_to_or_null y v)
True
(fun y -> y == ghost_ptr_gen_of_void_ptr x t)
[@@noextract_to "krml"] inline_for_extraction
let ref_of_void_ptr (#t: Type) (#opened: _) (#td: typedef t) (#v: Ghost.erased t) (x: void_ptr) (y': Ghost.erased (ref td)) : STAtomicBase (ref td) false opened Unobservable
(pts_to y' v)
(fun y -> pts_to y v)
(Ghost.reveal y' == ghost_ptr_gen_of_void_ptr x t)
(fun y -> y == Ghost.reveal y')
= rewrite (pts_to y' v) (pts_to_or_null (ghost_ptr_gen_of_void_ptr x t <: ptr td) v);
let y = ptr_of_void_ptr x in
rewrite (pts_to_or_null y v) (pts_to y v);
return y
val ref_equiv
(#t: Type)
(#td: typedef t)
(r1 r2: ref td)
: Tot vprop
val pts_to_equiv
(#opened: _)
(#t: Type)
(#td: typedef t)
(r1 r2: ref td)
(v: Ghost.erased t)
: STGhostT unit opened
(ref_equiv r1 r2 `star` pts_to r1 v)
(fun _ -> ref_equiv r1 r2 `star` pts_to r2 v)
val freeable
(#t: Type)
(#td: typedef t)
(r: ref td)
: Tot vprop
val freeable_dup
(#opened: _)
(#t: Type)
(#td: typedef t)
(r: ref td)
: STGhostT unit opened
(freeable r)
(fun _ -> freeable r `star` freeable r)
val freeable_equiv
(#opened: _)
(#t: Type)
(#td: typedef t)
(r1 r2: ref td)
: STGhostT unit opened
(ref_equiv r1 r2 `star` freeable r1)
(fun _ -> ref_equiv r1 r2 `star` freeable r2)
let freeable_or_null
(#t: Type)
(#td: typedef t)
(r: ptr td)
: Tot vprop
= if FStar.StrongExcludedMiddle.strong_excluded_middle (r == null _)
then emp
else freeable r
(*
let freeable_or_null_dup
(#opened: _)
(#t: Type)
(#td: typedef t)
(r: ptr td)
: SteelGhostT vprop opened
(freeable_or_null r)
(fun _ -> freeable_or_null r `star` freeable_or_null r)
= if FStar.StrongExcludedMiddle.strong_excluded_middle (r == null _)
then ()
else freeable r
*)
[@@noextract_to "krml"] // primitive
val alloc
(#t: Type)
(td: typedef t)
: STT (ptr td)
emp
(fun p -> pts_to_or_null p (uninitialized td) `star` freeable_or_null p)
[@@noextract_to "krml"] // primitive
val free
(#t: Type)
(#td: typedef t)
(#v: Ghost.erased t)
(r: ref td)
: ST unit
(pts_to r v `star` freeable r)
(fun _ -> emp)
(
full td v
)
(fun _ -> True)
val mk_fraction_split_gen
(#opened: _)
(#t: Type) (#td: typedef t) (r: ref td) (v: t { fractionable td v }) (p p1 p2: P.perm) : STGhost unit opened
(pts_to r (mk_fraction td v p))
(fun _ -> pts_to r (mk_fraction td v p1) `star` pts_to r (mk_fraction td v p2))
(p == p1 `P.sum_perm` p2 /\ p `P.lesser_equal_perm` P.full_perm)
(fun _ -> True) | {
"checked_file": "/",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"Steel.FractionalPermission.fst.checked",
"prims.fst.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Real.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.ST.C.Types.Base.fsti"
} | [
{
"abbrev": true,
"full_module": "Steel.FractionalPermission",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.C.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.C.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
r: Steel.ST.C.Types.Base.ref td ->
v: FStar.Ghost.erased t {Steel.ST.C.Types.Base.fractionable td (FStar.Ghost.reveal v)} ->
p1: Steel.FractionalPermission.perm ->
p2: Steel.FractionalPermission.perm
-> Steel.ST.Effect.Ghost.STGhost Prims.unit | Steel.ST.Effect.Ghost.STGhost | [] | [] | [
"Steel.Memory.inames",
"Steel.ST.C.Types.Base.typedef",
"Steel.ST.C.Types.Base.ref",
"FStar.Ghost.erased",
"Steel.ST.C.Types.Base.fractionable",
"FStar.Ghost.reveal",
"Steel.FractionalPermission.perm",
"Steel.ST.C.Types.Base.mk_fraction_split_gen",
"Steel.FractionalPermission.full_perm",
"Prims.unit",
"Steel.ST.Util.rewrite",
"Steel.ST.C.Types.Base.pts_to",
"FStar.Ghost.hide",
"Steel.ST.C.Types.Base.mk_fraction",
"Steel.ST.C.Types.Base.mk_fraction_full",
"Steel.Effect.Common.star",
"Steel.Effect.Common.vprop",
"Prims.eq2",
"Steel.FractionalPermission.sum_perm",
"Prims.l_True"
] | [] | false | true | false | false | false | let mk_fraction_split
(#opened: _)
(#t: Type)
(#td: typedef t)
(r: ref td)
(v: Ghost.erased t {fractionable td v})
(p1 p2: P.perm)
: STGhost unit
opened
(pts_to r v)
(fun _ -> (pts_to r (mk_fraction td v p1)) `star` (pts_to r (mk_fraction td v p2)))
(P.full_perm == p1 `P.sum_perm` p2)
(fun _ -> True) =
| mk_fraction_full td v;
rewrite (pts_to _ _) (pts_to _ _);
mk_fraction_split_gen r v P.full_perm p1 p2 | false |
BinomialQueue.fst | BinomialQueue.delete_max_some_repr | val delete_max_some_repr (p:priq) (sp:ms)
(k:key_t) (q:priq) (sq:ms)
: Lemma (requires
p `repr` sp /\
delete_max p == Some (k, q) /\
q `repr` sq)
(ensures
permutation sp (ms_cons k sq) /\
(forall (x:key_t). S.mem x sp.ms_elems ==> x <= k)) | val delete_max_some_repr (p:priq) (sp:ms)
(k:key_t) (q:priq) (sq:ms)
: Lemma (requires
p `repr` sp /\
delete_max p == Some (k, q) /\
q `repr` sq)
(ensures
permutation sp (ms_cons k sq) /\
(forall (x:key_t). S.mem x sp.ms_elems ==> x <= k)) | let delete_max_some_repr p pl k q ql =
match find_max None p with
| None -> ()
| Some m ->
find_max_mem_keys None p;
assert (S.mem m (keys p).ms_elems);
let x, q, new_q = delete_max_aux m 1 p in
delete_max_aux_repr m 1 p x q new_q
pl (keys q) (keys new_q);
let r = join 1 q new_q Leaf in
join_repr 1 q new_q Leaf (keys q) (keys new_q) ms_empty;
compact_preserves_keys r;
assert (permutation pl (ms_append (ms_singleton k) ql));
find_max_is_max 1 None p | {
"file_name": "examples/data_structures/BinomialQueue.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 28,
"end_line": 644,
"start_col": 0,
"start_line": 631
} | (*
Copyright 2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Authors: Aseem Rastogi
*)
module BinomialQueue
module L = FStar.List.Tot
/// Some auxiliary lemmas
let rec last_cons (#a:Type) (x:a) (l:list a)
: Lemma
(requires Cons? l)
(ensures L.last (x::l) == L.last l)
[SMTPat (L.last (x::l))] =
match l with
| [_] -> ()
| _::tl -> last_cons x tl
/// We will maintain the priority queue as a forest
type tree =
| Leaf : tree
| Internal : tree -> key_t -> tree -> tree
/// Tree t is a complete binary tree of depth d
///
/// All its keys are <= upper_bound
///
/// If the left subtree is non-empty,
/// its root is maximum in its subtree
let rec pow2heap_pred (d:nat) (upper_bound:key_t) (t:tree) : prop =
match t with
| Leaf -> d == 0
| Internal left k right ->
0 < d /\
k <= upper_bound /\
pow2heap_pred (d - 1) k left /\
pow2heap_pred (d - 1) upper_bound right
/// A power-2-heap of depth d is an Internal tree whose right child is a Leaf,
/// and left child is a complete binary tree satisfying pow2heap_pred
/// with upper bound as the key k
let is_pow2heap (d:pos) (t:tree) : prop =
match t with
| Internal left k Leaf -> pow2heap_pred (d - 1) k left
| _ -> False
/// A list of trees is a binomial queue starting with depth d if:
type forest = list tree
let rec is_binomial_queue (d:pos) (l:forest)
: Tot prop (decreases l) =
match l with
| [] -> True
| hd::tl ->
(Leaf? hd \/ is_pow2heap d hd) /\ is_binomial_queue (d + 1) tl
/// We will also keep the binomial queue in a compact form,
/// truncating unnecessary empty trees from the forest
let is_compact (l:forest) = l == [] \/ Internal? (L.last l)
let is_priq (l:forest) = is_binomial_queue 1 l /\ is_compact l
/// The main priq type
let priq = l:forest{is_priq l}
let empty = []
/// We define a function to compact a forest
let rec all_leaf (l:forest{Cons? l}) : bool =
match l with
| [Leaf] -> true
| Leaf::tl -> all_leaf tl
| _ -> false
let rec mk_compact (l:forest) : forest =
match l with
| [] -> []
| _ ->
if all_leaf l then []
else let hd::tl = l in
hd::(mk_compact tl)
/// Correctness of mk_compact
let rec mk_compact_correctness (l:forest)
: Lemma (is_compact (mk_compact l))
[SMTPat (is_compact (mk_compact l))] =
match l with
| [] -> ()
| _ ->
if all_leaf l then ()
else mk_compact_correctness (L.tl l)
let rec mk_compact_preserves_binomial_queue (d:pos) (l:forest)
: Lemma
(requires is_binomial_queue d l)
(ensures is_binomial_queue d (mk_compact l))
(decreases l)
[SMTPat (is_binomial_queue d (mk_compact l))] =
match l with
| [] -> ()
| _ ->
if all_leaf l then ()
else mk_compact_preserves_binomial_queue (d + 1) (L.tl l)
/// smash is a key function combining two power of 2 heaps of depth d
/// into a power of 2 heap of depth (d + 1)
let smash (d:pos) (t1:tree) (t2:tree)
: Pure tree
(requires is_pow2heap d t1 /\ is_pow2heap d t2)
(ensures fun t -> is_pow2heap (d + 1) t) =
match t1, t2 with
| Internal left1 k1 Leaf, Internal left2 k2 Leaf ->
if k1 <= k2
then Internal (Internal left1 k1 left2) k2 Leaf
else Internal (Internal left2 k2 left1) k1 Leaf
/// carry adds t to q, preserving the binomial queue relation
///
/// It has a nice symmetery to carry in binary arithmetic
let rec carry (d:pos) (q:forest) (t:tree)
: Pure forest
(requires is_binomial_queue d q /\ is_pow2heap d t)
(ensures fun q -> is_binomial_queue d q)
(decreases q) =
match q with
| [] -> [t]
| Leaf::tl -> t::tl
| hd::tl ->
let q = carry (d + 1) tl (smash d hd t) in
Leaf::q
/// join combines two trees p and q, with the carry c,
/// preserving the binomial queue relation
///
/// It has a nice symmetry to binary addition
let rec join (d:pos) (p q:forest) (c:tree)
: Pure forest
(requires
is_binomial_queue d p /\
is_binomial_queue d q /\
(Leaf? c \/ is_pow2heap d c))
(ensures fun q -> is_binomial_queue d q)
(decreases L.length p) =
match p, q, c with
| [], _, Leaf -> q
| _, [], Leaf -> p
| [], _, _ -> carry d q c
| _, [], _ -> carry d p c
| Leaf::tl_p, Leaf::tl_q, _ ->
c::(join (d + 1) tl_p tl_q Leaf)
| hd_p::tl_p, Leaf::tl_q, Leaf ->
hd_p::(join (d + 1) tl_p tl_q Leaf)
| Leaf::tl_p, hd_q::tl_q, Leaf ->
hd_q::(join (d + 1) tl_p tl_q Leaf)
| Leaf::tl_p, hd_q::tl_q, _ ->
Leaf::(join (d + 1) tl_p tl_q (smash d hd_q c))
| hd_p::tl_p, Leaf::tl_q, _ ->
Leaf::(join (d + 1) tl_p tl_q (smash d hd_p c))
| hd_p::tl_p, hd_q::tl_q, c ->
c::(join (d + 1) tl_p tl_q (smash d hd_p hd_q))
/// insert is just carry of (Internal Leaf x Leaf) to q
let insert x q =
let l = carry 1 q (Internal Leaf x Leaf) in
mk_compact l
/// Towards delete max
/// find_max with the current max as max
let rec find_max (max:option key_t) (q:forest)
: Tot (option key_t) (decreases q) =
match q with
| [] -> max
| Leaf::q -> find_max max q
| (Internal _ k _)::q ->
match max with
| None -> find_max (Some k) q
| Some max -> find_max (if max < k then Some k else Some max) q
/// If q is a binomial queue starting at depth d,
/// and t is a power of 2 heap of depth (d + length q)
///
/// Then appending t to q is also a binomial queue
let rec binomial_queue_append (d:pos) (q:forest) (t:tree)
: Lemma
(requires
is_binomial_queue d q /\ is_pow2heap (L.length q + d) t)
(ensures is_binomial_queue d (L.append q [t]))
(decreases q) =
match q with
| [] -> ()
| _::q -> binomial_queue_append (d + 1) q t
/// unzip splits the tree t along its right spine
///
/// See https://www.cs.princeton.edu/~appel/BQ.pdf
///
/// The upper bound is only needed to show we return a priq,
/// may be it's not important?
let rec unzip (d:nat) (upper_bound:key_t) (t:tree)
: Pure priq
(requires pow2heap_pred d upper_bound t)
(ensures fun q -> L.length q == d) =
match t with
| Leaf -> []
| Internal left k right ->
let q = unzip (d - 1) upper_bound right in
binomial_queue_append 1 q (Internal left k Leaf);
L.append_length q [Internal left k Leaf];
L.lemma_append_last q [Internal left k Leaf];
L.append q [Internal left k Leaf]
/// Delete root of t, and unzip it
let heap_delete_max (d:pos) (t:tree)
: Pure priq
(requires is_pow2heap d t)
(ensures fun q -> L.length q == d - 1) =
match t with
| Internal left k Leaf -> unzip (d - 1) k left
/// Take the first tree in q whose root is >= m,
/// delete its root and unzip it,
/// return (the deleted root, q with that tree replaces with Leaf, unzipped forest)
///
let rec delete_max_aux (m:key_t) (d:pos) (q:forest)
: Pure (key_t & forest & priq)
(requires is_binomial_queue d q)
(ensures fun (x, q, _) -> m <= x /\ is_binomial_queue d q)
(decreases q) =
match q with
| [] -> m + 1, [], [] // this case won't arise
// we could strengthen preconditions
| Leaf::q ->
let x, q, new_q = delete_max_aux m (d + 1) q in
x, Leaf::q, new_q
| (Internal left x right)::q ->
if x < m
then let y, q, new_q = delete_max_aux m (d + 1) q in
y, (Internal left x right)::q, new_q
else x, Leaf::q, heap_delete_max d (Internal left x right)
/// delete_max finds the maximum key in the forest,
/// deletes it from its tree, and joins the remaining forests
let delete_max q =
match find_max None q with
| None -> None
| Some m ->
let x, q, new_q = delete_max_aux m 1 q in
let r = join 1 q new_q Leaf in
mk_compact_correctness r;
Some (x, mk_compact r)
/// merge is just join with Leaf as the carry
let merge p q =
let l = join 1 p q Leaf in
mk_compact l
/// Towards defining repr
let rec keys_of_tree (t:tree) : ms =
match t with
| Leaf -> ms_empty
| Internal left k right ->
ms_append (keys_of_tree left)
(ms_cons k (keys_of_tree right))
let rec keys (q:forest) : ms =
match q with
| [] -> ms_empty
| hd::tl -> ms_append (keys_of_tree hd) (keys tl)
let repr_t (t:tree) (l:ms) : prop =
permutation (keys_of_tree t) l
let repr_l (q:forest) (s:ms) : prop =
permutation (keys q) s
/// The main repr predicate saying s is a permutation of (keys q)
let repr q s = repr_l q s
let empty_repr _ = ()
/// Correctness of carry and join
let smash_repr (d:pos) (t1 t2:tree) (l1 l2:ms)
: Lemma
(requires
is_pow2heap d t1 /\
is_pow2heap d t2 /\
t1 `repr_t` l1 /\
t2 `repr_t` l2)
(ensures smash d t1 t2 `repr_t` (ms_append l1 l2)) = ()
let rec carry_repr (d:pos) (q:forest) (t:tree) (lq lt:ms)
: Lemma
(requires
is_binomial_queue d q /\
is_pow2heap d t /\
q `repr_l` lq /\
t `repr_t` lt)
(ensures carry d q t `repr_l` ms_append lq lt)
(decreases q) =
match q with
| [] -> ()
| Leaf::_ -> ()
| hd::tl ->
smash_repr d hd t (keys_of_tree hd) (keys_of_tree t);
carry_repr (d + 1) tl (smash d hd t)
(keys tl)
(ms_append (keys_of_tree hd) (keys_of_tree t))
#push-options "--z3rlimit 50 --fuel 1 --ifuel 1"
let rec join_repr (d:pos) (p q:forest) (c:tree)
(lp lq lc:ms)
: Lemma
(requires
is_binomial_queue d p /\
is_binomial_queue d q /\
(Leaf? c \/ is_pow2heap d c) /\
p `repr_l` lp /\
q `repr_l` lq /\
c `repr_t` lc)
(ensures join d p q c `repr_l` ms_append lp (ms_append lq lc))
(decreases p) =
match p, q, c with
| [], _, Leaf
| _, [], Leaf -> ()
| [], _, _ -> carry_repr d q c lq lc
| _, [], _ -> carry_repr d p c lp lc
| Leaf::tl_p, Leaf::tl_q, _ ->
join_repr (d + 1) tl_p tl_q Leaf
(keys tl_p) (keys tl_q) ms_empty
| hd_p::tl_p, Leaf::tl_q, Leaf ->
join_repr (d + 1) tl_p tl_q Leaf
(keys tl_p) (keys tl_q) ms_empty
| Leaf::tl_p, hd_q::tl_q, Leaf ->
join_repr (d + 1) tl_p tl_q Leaf
(keys tl_p) (keys tl_q) ms_empty
| Leaf::tl_p, hd_q::tl_q, _ ->
smash_repr d hd_q c (keys_of_tree hd_q) (keys_of_tree c);
join_repr (d + 1) tl_p tl_q (smash d hd_q c)
(keys tl_p) (keys tl_q)
(ms_append (keys_of_tree hd_q) (keys_of_tree c))
| hd_p::tl_p, Leaf::tl_q, _ ->
smash_repr d hd_p c (keys_of_tree hd_p) (keys_of_tree c);
join_repr (d + 1) tl_p tl_q (smash d hd_p c)
(keys tl_p) (keys tl_q)
(ms_append (keys_of_tree hd_p) (keys_of_tree c))
| hd_p::tl_p, hd_q::tl_q, c ->
smash_repr d hd_p hd_q (keys_of_tree hd_p) (keys_of_tree hd_q);
join_repr (d + 1) tl_p tl_q (smash d hd_p hd_q)
(keys tl_p) (keys tl_q)
(ms_append (keys_of_tree hd_p) (keys_of_tree hd_q))
#pop-options
/// mk_compact preserves keys
let rec all_leaf_keys (l:forest{Cons? l})
: Lemma
(requires Cons? l /\ all_leaf l)
(ensures permutation (keys l) ms_empty) =
match l with
| [Leaf] -> ()
| Leaf::tl -> all_leaf_keys tl
let rec compact_preserves_keys (q:forest)
: Lemma (permutation (keys q) (keys (mk_compact q)))
[SMTPat (keys (mk_compact q))] =
match q with
| [] -> ()
| _ ->
if all_leaf q
then all_leaf_keys q
else compact_preserves_keys (L.tl q)
/// insert and merge correctness follows from carry and joinx
let insert_repr x q s =
carry_repr 1 q (Internal Leaf x Leaf) s (ms_singleton x)
let merge_repr p q sp sq =
join_repr 1 p q Leaf sp sq ms_empty
/// Towards proof of delete correctness
let rec last_key_in_keys (l:forest)
: Lemma
(requires
Cons? l /\
Internal? (L.last l))
(ensures (let Internal _ k _ = L.last l in
S.subset (S.singleton k) (keys l).ms_elems)) =
match l with
| [Internal _ _ _] -> ()
| _::tl -> last_key_in_keys tl
let rec find_max_some_is_some (k:key_t) (l:forest)
: Lemma (ensures Some? (find_max (Some k) l) /\
k <= Some?.v (find_max (Some k) l))
(decreases l) =
match l with
| [] -> ()
| Leaf::tl -> find_max_some_is_some k tl
| (Internal _ k' _)::tl ->
let k = if k < k' then k' else k in
find_max_some_is_some k tl
let find_max_emp_repr_l (l:priq)
: Lemma
(requires l `repr_l` ms_empty)
(ensures find_max None l == None) =
match l with
| [] -> ()
| _ -> last_key_in_keys l
let rec find_max_emp_repr_r (l:forest)
: Lemma
(requires find_max None l == None)
(ensures permutation (keys l) ms_empty) =
match l with
| [] -> ()
| Leaf::tl -> find_max_emp_repr_r tl
| (Internal _ k _)::tl -> find_max_some_is_some k tl
#push-options "--warn_error -271"
let delete_max_none_repr p =
let delete_max_none_repr_l (l:priq)
: Lemma
(requires l `repr` ms_empty)
(ensures delete_max l == None)
[SMTPat ()] = find_max_emp_repr_l l in
let delete_max_none_repr_r (l:priq)
: Lemma
(requires delete_max l == None)
(ensures l `repr` ms_empty)
[SMTPat ()] = find_max_emp_repr_r l in
()
#pop-options
let rec keys_append (l1 l2:forest) (ms1 ms2:ms)
: Lemma (requires l1 `repr_l` ms1 /\ l2 `repr_l` ms2)
(ensures (L.append l1 l2) `repr_l` (ms_append ms1 ms2)) =
match l1 with
| [] -> ()
| _::tl -> keys_append tl l2 (keys tl) ms2
let rec unzip_repr (d:nat) (upper_bound:key_t) (t:tree) (lt:ms)
: Lemma
(requires
pow2heap_pred d upper_bound t /\
permutation (keys_of_tree t) lt)
(ensures permutation lt (keys (unzip d upper_bound t)))
(decreases t) =
match t with
| Leaf -> ()
| Internal left k right ->
let q = unzip (d - 1) upper_bound right in
unzip_repr (d - 1) upper_bound right (keys_of_tree right);
keys_append q [Internal left k Leaf]
(keys_of_tree right) (ms_append (keys_of_tree left)
(ms_append (ms_singleton k)
ms_empty))
let heap_delete_max_repr (d:pos) (t:tree) (lt:ms)
: Lemma
(requires is_pow2heap d t /\ t `repr_t` lt)
(ensures (
let Internal left k Leaf = t in
permutation lt (ms_append (ms_singleton k)
(keys (heap_delete_max d t))))) =
let Internal left k Leaf = t in
unzip_repr (d - 1) k left (keys_of_tree left)
let max (k:key_t) (s:S.set key_t) =
forall (x:key_t). Set.mem x s ==> x <= k
let rec tree_root_is_max_aux (d:nat) (upper_bound:key_t) (t:tree)
: Lemma
(requires pow2heap_pred d upper_bound t)
(ensures max upper_bound (keys_of_tree t).ms_elems)
(decreases t) =
match t with
| Leaf -> ()
| Internal left k right ->
tree_root_is_max_aux (d - 1) k left;
tree_root_is_max_aux (d - 1) upper_bound right
let tree_root_is_max (d:pos) (t:tree)
: Lemma
(requires is_pow2heap d t)
(ensures
(let Internal left k Leaf = t in
max k (keys_of_tree left).ms_elems)) =
let Internal left k Leaf = t in
tree_root_is_max_aux (d - 1) k left
#push-options "--z3rlimit 40"
let rec delete_max_aux_repr (m:key_t) (d:pos) (q:forest)
(x:key_t) (r:forest) (p:priq)
(lq lr lp:ms)
: Lemma
(requires
S.mem m (keys q).ms_elems /\
is_binomial_queue d q /\
q `repr_l` lq /\
delete_max_aux m d q == (x, r, p) /\
r `repr_l` lr /\
p `repr_l` lp)
(ensures
permutation lq (ms_append (ms_singleton x)
(ms_append lr lp)))
(decreases q) =
match q with
| [] -> ()
| Leaf::q ->
delete_max_aux_repr m (d + 1) q x (L.tl r) p lq lr lp
| (Internal left x Leaf)::q ->
if x < m
then begin
tree_root_is_max d (Internal left x Leaf);
assert (~ (S.mem m (keys_of_tree left).ms_elems));
let y, _, _ = delete_max_aux m (d + 1) q in
delete_max_aux_repr m (d + 1) q y (L.tl r) p (keys q) (keys (L.tl r)) lp
end
else heap_delete_max_repr d (Internal left x Leaf) (keys_of_tree (Internal left x Leaf))
#pop-options
let rec find_max_mem_keys (kopt:option key_t) (q:forest)
: Lemma
(ensures
find_max kopt q == kopt \/
(let kopt = find_max kopt q in
Some? kopt /\ S.mem (Some?.v kopt) (keys q).ms_elems))
(decreases q) =
match q with
| [] -> ()
| Leaf::q -> find_max_mem_keys kopt q
| (Internal _ k _)::q ->
match kopt with
| None ->
find_max_mem_keys (Some k) q
| Some k' ->
let k = if k' < k then k else k' in
find_max_mem_keys (Some k) q
let rec find_max_is_max (d:pos) (kopt:option key_t) (q:forest)
: Lemma
(requires
is_binomial_queue d q /\
Some? (find_max kopt q))
(ensures
(let Some k = find_max kopt q in
max k (keys q).ms_elems))
(decreases q) =
match q with
| [] -> ()
| Leaf::q ->
find_max_is_max (d + 1) kopt q
| (Internal left k Leaf)::tl ->
tree_root_is_max d (Internal left k Leaf);
match kopt with
| None ->
find_max_is_max (d + 1) (Some k) tl;
find_max_some_is_some k tl
| Some k' ->
let k = if k' < k then k else k' in
find_max_is_max (d + 1) (Some k) tl;
find_max_some_is_some k tl | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "BinomialQueue.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Set",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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: BinomialQueue.priq ->
sp: BinomialQueue.ms ->
k: BinomialQueue.key_t ->
q: BinomialQueue.priq ->
sq: BinomialQueue.ms
-> FStar.Pervasives.Lemma
(requires
BinomialQueue.repr p sp /\ BinomialQueue.delete_max p == FStar.Pervasives.Native.Some (k, q) /\
BinomialQueue.repr q sq)
(ensures
BinomialQueue.permutation sp (BinomialQueue.ms_cons k sq) /\
(forall (x: BinomialQueue.key_t). FStar.Set.mem x (Mkms?.ms_elems sp) ==> x <= k)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"BinomialQueue.priq",
"BinomialQueue.ms",
"BinomialQueue.key_t",
"BinomialQueue.find_max",
"FStar.Pervasives.Native.None",
"BinomialQueue.forest",
"BinomialQueue.find_max_is_max",
"Prims.unit",
"Prims._assert",
"BinomialQueue.permutation",
"BinomialQueue.ms_append",
"BinomialQueue.ms_singleton",
"BinomialQueue.compact_preserves_keys",
"BinomialQueue.join_repr",
"BinomialQueue.Leaf",
"BinomialQueue.keys",
"BinomialQueue.ms_empty",
"BinomialQueue.join",
"BinomialQueue.delete_max_aux_repr",
"FStar.Pervasives.Native.tuple3",
"BinomialQueue.delete_max_aux",
"Prims.b2t",
"FStar.Set.mem",
"BinomialQueue.__proj__Mkms__item__ms_elems",
"BinomialQueue.find_max_mem_keys"
] | [] | false | false | true | false | false | let delete_max_some_repr p pl k q ql =
| match find_max None p with
| None -> ()
| Some m ->
find_max_mem_keys None p;
assert (S.mem m (keys p).ms_elems);
let x, q, new_q = delete_max_aux m 1 p in
delete_max_aux_repr m 1 p x q new_q pl (keys q) (keys new_q);
let r = join 1 q new_q Leaf in
join_repr 1 q new_q Leaf (keys q) (keys new_q) ms_empty;
compact_preserves_keys r;
assert (permutation pl (ms_append (ms_singleton k) ql));
find_max_is_max 1 None p | false |
BinomialQueue.fst | BinomialQueue.join_repr | val join_repr (d: pos) (p q: forest) (c: tree) (lp lq lc: ms)
: Lemma
(requires
is_binomial_queue d p /\ is_binomial_queue d q /\ (Leaf? c \/ is_pow2heap d c) /\
p `repr_l` lp /\ q `repr_l` lq /\ c `repr_t` lc)
(ensures (join d p q c) `repr_l` (ms_append lp (ms_append lq lc)))
(decreases p) | val join_repr (d: pos) (p q: forest) (c: tree) (lp lq lc: ms)
: Lemma
(requires
is_binomial_queue d p /\ is_binomial_queue d q /\ (Leaf? c \/ is_pow2heap d c) /\
p `repr_l` lp /\ q `repr_l` lq /\ c `repr_t` lc)
(ensures (join d p q c) `repr_l` (ms_append lp (ms_append lq lc)))
(decreases p) | let rec join_repr (d:pos) (p q:forest) (c:tree)
(lp lq lc:ms)
: Lemma
(requires
is_binomial_queue d p /\
is_binomial_queue d q /\
(Leaf? c \/ is_pow2heap d c) /\
p `repr_l` lp /\
q `repr_l` lq /\
c `repr_t` lc)
(ensures join d p q c `repr_l` ms_append lp (ms_append lq lc))
(decreases p) =
match p, q, c with
| [], _, Leaf
| _, [], Leaf -> ()
| [], _, _ -> carry_repr d q c lq lc
| _, [], _ -> carry_repr d p c lp lc
| Leaf::tl_p, Leaf::tl_q, _ ->
join_repr (d + 1) tl_p tl_q Leaf
(keys tl_p) (keys tl_q) ms_empty
| hd_p::tl_p, Leaf::tl_q, Leaf ->
join_repr (d + 1) tl_p tl_q Leaf
(keys tl_p) (keys tl_q) ms_empty
| Leaf::tl_p, hd_q::tl_q, Leaf ->
join_repr (d + 1) tl_p tl_q Leaf
(keys tl_p) (keys tl_q) ms_empty
| Leaf::tl_p, hd_q::tl_q, _ ->
smash_repr d hd_q c (keys_of_tree hd_q) (keys_of_tree c);
join_repr (d + 1) tl_p tl_q (smash d hd_q c)
(keys tl_p) (keys tl_q)
(ms_append (keys_of_tree hd_q) (keys_of_tree c))
| hd_p::tl_p, Leaf::tl_q, _ ->
smash_repr d hd_p c (keys_of_tree hd_p) (keys_of_tree c);
join_repr (d + 1) tl_p tl_q (smash d hd_p c)
(keys tl_p) (keys tl_q)
(ms_append (keys_of_tree hd_p) (keys_of_tree c))
| hd_p::tl_p, hd_q::tl_q, c ->
smash_repr d hd_p hd_q (keys_of_tree hd_p) (keys_of_tree hd_q);
join_repr (d + 1) tl_p tl_q (smash d hd_p hd_q)
(keys tl_p) (keys tl_q)
(ms_append (keys_of_tree hd_p) (keys_of_tree hd_q)) | {
"file_name": "examples/data_structures/BinomialQueue.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 57,
"end_line": 407,
"start_col": 0,
"start_line": 362
} | (*
Copyright 2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Authors: Aseem Rastogi
*)
module BinomialQueue
module L = FStar.List.Tot
/// Some auxiliary lemmas
let rec last_cons (#a:Type) (x:a) (l:list a)
: Lemma
(requires Cons? l)
(ensures L.last (x::l) == L.last l)
[SMTPat (L.last (x::l))] =
match l with
| [_] -> ()
| _::tl -> last_cons x tl
/// We will maintain the priority queue as a forest
type tree =
| Leaf : tree
| Internal : tree -> key_t -> tree -> tree
/// Tree t is a complete binary tree of depth d
///
/// All its keys are <= upper_bound
///
/// If the left subtree is non-empty,
/// its root is maximum in its subtree
let rec pow2heap_pred (d:nat) (upper_bound:key_t) (t:tree) : prop =
match t with
| Leaf -> d == 0
| Internal left k right ->
0 < d /\
k <= upper_bound /\
pow2heap_pred (d - 1) k left /\
pow2heap_pred (d - 1) upper_bound right
/// A power-2-heap of depth d is an Internal tree whose right child is a Leaf,
/// and left child is a complete binary tree satisfying pow2heap_pred
/// with upper bound as the key k
let is_pow2heap (d:pos) (t:tree) : prop =
match t with
| Internal left k Leaf -> pow2heap_pred (d - 1) k left
| _ -> False
/// A list of trees is a binomial queue starting with depth d if:
type forest = list tree
let rec is_binomial_queue (d:pos) (l:forest)
: Tot prop (decreases l) =
match l with
| [] -> True
| hd::tl ->
(Leaf? hd \/ is_pow2heap d hd) /\ is_binomial_queue (d + 1) tl
/// We will also keep the binomial queue in a compact form,
/// truncating unnecessary empty trees from the forest
let is_compact (l:forest) = l == [] \/ Internal? (L.last l)
let is_priq (l:forest) = is_binomial_queue 1 l /\ is_compact l
/// The main priq type
let priq = l:forest{is_priq l}
let empty = []
/// We define a function to compact a forest
let rec all_leaf (l:forest{Cons? l}) : bool =
match l with
| [Leaf] -> true
| Leaf::tl -> all_leaf tl
| _ -> false
let rec mk_compact (l:forest) : forest =
match l with
| [] -> []
| _ ->
if all_leaf l then []
else let hd::tl = l in
hd::(mk_compact tl)
/// Correctness of mk_compact
let rec mk_compact_correctness (l:forest)
: Lemma (is_compact (mk_compact l))
[SMTPat (is_compact (mk_compact l))] =
match l with
| [] -> ()
| _ ->
if all_leaf l then ()
else mk_compact_correctness (L.tl l)
let rec mk_compact_preserves_binomial_queue (d:pos) (l:forest)
: Lemma
(requires is_binomial_queue d l)
(ensures is_binomial_queue d (mk_compact l))
(decreases l)
[SMTPat (is_binomial_queue d (mk_compact l))] =
match l with
| [] -> ()
| _ ->
if all_leaf l then ()
else mk_compact_preserves_binomial_queue (d + 1) (L.tl l)
/// smash is a key function combining two power of 2 heaps of depth d
/// into a power of 2 heap of depth (d + 1)
let smash (d:pos) (t1:tree) (t2:tree)
: Pure tree
(requires is_pow2heap d t1 /\ is_pow2heap d t2)
(ensures fun t -> is_pow2heap (d + 1) t) =
match t1, t2 with
| Internal left1 k1 Leaf, Internal left2 k2 Leaf ->
if k1 <= k2
then Internal (Internal left1 k1 left2) k2 Leaf
else Internal (Internal left2 k2 left1) k1 Leaf
/// carry adds t to q, preserving the binomial queue relation
///
/// It has a nice symmetery to carry in binary arithmetic
let rec carry (d:pos) (q:forest) (t:tree)
: Pure forest
(requires is_binomial_queue d q /\ is_pow2heap d t)
(ensures fun q -> is_binomial_queue d q)
(decreases q) =
match q with
| [] -> [t]
| Leaf::tl -> t::tl
| hd::tl ->
let q = carry (d + 1) tl (smash d hd t) in
Leaf::q
/// join combines two trees p and q, with the carry c,
/// preserving the binomial queue relation
///
/// It has a nice symmetry to binary addition
let rec join (d:pos) (p q:forest) (c:tree)
: Pure forest
(requires
is_binomial_queue d p /\
is_binomial_queue d q /\
(Leaf? c \/ is_pow2heap d c))
(ensures fun q -> is_binomial_queue d q)
(decreases L.length p) =
match p, q, c with
| [], _, Leaf -> q
| _, [], Leaf -> p
| [], _, _ -> carry d q c
| _, [], _ -> carry d p c
| Leaf::tl_p, Leaf::tl_q, _ ->
c::(join (d + 1) tl_p tl_q Leaf)
| hd_p::tl_p, Leaf::tl_q, Leaf ->
hd_p::(join (d + 1) tl_p tl_q Leaf)
| Leaf::tl_p, hd_q::tl_q, Leaf ->
hd_q::(join (d + 1) tl_p tl_q Leaf)
| Leaf::tl_p, hd_q::tl_q, _ ->
Leaf::(join (d + 1) tl_p tl_q (smash d hd_q c))
| hd_p::tl_p, Leaf::tl_q, _ ->
Leaf::(join (d + 1) tl_p tl_q (smash d hd_p c))
| hd_p::tl_p, hd_q::tl_q, c ->
c::(join (d + 1) tl_p tl_q (smash d hd_p hd_q))
/// insert is just carry of (Internal Leaf x Leaf) to q
let insert x q =
let l = carry 1 q (Internal Leaf x Leaf) in
mk_compact l
/// Towards delete max
/// find_max with the current max as max
let rec find_max (max:option key_t) (q:forest)
: Tot (option key_t) (decreases q) =
match q with
| [] -> max
| Leaf::q -> find_max max q
| (Internal _ k _)::q ->
match max with
| None -> find_max (Some k) q
| Some max -> find_max (if max < k then Some k else Some max) q
/// If q is a binomial queue starting at depth d,
/// and t is a power of 2 heap of depth (d + length q)
///
/// Then appending t to q is also a binomial queue
let rec binomial_queue_append (d:pos) (q:forest) (t:tree)
: Lemma
(requires
is_binomial_queue d q /\ is_pow2heap (L.length q + d) t)
(ensures is_binomial_queue d (L.append q [t]))
(decreases q) =
match q with
| [] -> ()
| _::q -> binomial_queue_append (d + 1) q t
/// unzip splits the tree t along its right spine
///
/// See https://www.cs.princeton.edu/~appel/BQ.pdf
///
/// The upper bound is only needed to show we return a priq,
/// may be it's not important?
let rec unzip (d:nat) (upper_bound:key_t) (t:tree)
: Pure priq
(requires pow2heap_pred d upper_bound t)
(ensures fun q -> L.length q == d) =
match t with
| Leaf -> []
| Internal left k right ->
let q = unzip (d - 1) upper_bound right in
binomial_queue_append 1 q (Internal left k Leaf);
L.append_length q [Internal left k Leaf];
L.lemma_append_last q [Internal left k Leaf];
L.append q [Internal left k Leaf]
/// Delete root of t, and unzip it
let heap_delete_max (d:pos) (t:tree)
: Pure priq
(requires is_pow2heap d t)
(ensures fun q -> L.length q == d - 1) =
match t with
| Internal left k Leaf -> unzip (d - 1) k left
/// Take the first tree in q whose root is >= m,
/// delete its root and unzip it,
/// return (the deleted root, q with that tree replaces with Leaf, unzipped forest)
///
let rec delete_max_aux (m:key_t) (d:pos) (q:forest)
: Pure (key_t & forest & priq)
(requires is_binomial_queue d q)
(ensures fun (x, q, _) -> m <= x /\ is_binomial_queue d q)
(decreases q) =
match q with
| [] -> m + 1, [], [] // this case won't arise
// we could strengthen preconditions
| Leaf::q ->
let x, q, new_q = delete_max_aux m (d + 1) q in
x, Leaf::q, new_q
| (Internal left x right)::q ->
if x < m
then let y, q, new_q = delete_max_aux m (d + 1) q in
y, (Internal left x right)::q, new_q
else x, Leaf::q, heap_delete_max d (Internal left x right)
/// delete_max finds the maximum key in the forest,
/// deletes it from its tree, and joins the remaining forests
let delete_max q =
match find_max None q with
| None -> None
| Some m ->
let x, q, new_q = delete_max_aux m 1 q in
let r = join 1 q new_q Leaf in
mk_compact_correctness r;
Some (x, mk_compact r)
/// merge is just join with Leaf as the carry
let merge p q =
let l = join 1 p q Leaf in
mk_compact l
/// Towards defining repr
let rec keys_of_tree (t:tree) : ms =
match t with
| Leaf -> ms_empty
| Internal left k right ->
ms_append (keys_of_tree left)
(ms_cons k (keys_of_tree right))
let rec keys (q:forest) : ms =
match q with
| [] -> ms_empty
| hd::tl -> ms_append (keys_of_tree hd) (keys tl)
let repr_t (t:tree) (l:ms) : prop =
permutation (keys_of_tree t) l
let repr_l (q:forest) (s:ms) : prop =
permutation (keys q) s
/// The main repr predicate saying s is a permutation of (keys q)
let repr q s = repr_l q s
let empty_repr _ = ()
/// Correctness of carry and join
let smash_repr (d:pos) (t1 t2:tree) (l1 l2:ms)
: Lemma
(requires
is_pow2heap d t1 /\
is_pow2heap d t2 /\
t1 `repr_t` l1 /\
t2 `repr_t` l2)
(ensures smash d t1 t2 `repr_t` (ms_append l1 l2)) = ()
let rec carry_repr (d:pos) (q:forest) (t:tree) (lq lt:ms)
: Lemma
(requires
is_binomial_queue d q /\
is_pow2heap d t /\
q `repr_l` lq /\
t `repr_t` lt)
(ensures carry d q t `repr_l` ms_append lq lt)
(decreases q) =
match q with
| [] -> ()
| Leaf::_ -> ()
| hd::tl ->
smash_repr d hd t (keys_of_tree hd) (keys_of_tree t);
carry_repr (d + 1) tl (smash d hd t)
(keys tl)
(ms_append (keys_of_tree hd) (keys_of_tree t)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "BinomialQueue.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Set",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 1,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
d: Prims.pos ->
p: BinomialQueue.forest ->
q: BinomialQueue.forest ->
c: BinomialQueue.tree ->
lp: BinomialQueue.ms ->
lq: BinomialQueue.ms ->
lc: BinomialQueue.ms
-> FStar.Pervasives.Lemma
(requires
BinomialQueue.is_binomial_queue d p /\ BinomialQueue.is_binomial_queue d q /\
(Leaf? c \/ BinomialQueue.is_pow2heap d c) /\ BinomialQueue.repr_l p lp /\
BinomialQueue.repr_l q lq /\ BinomialQueue.repr_t c lc)
(ensures
BinomialQueue.repr_l (BinomialQueue.join d p q c)
(BinomialQueue.ms_append lp (BinomialQueue.ms_append lq lc)))
(decreases p) | FStar.Pervasives.Lemma | [
"lemma",
""
] | [] | [
"Prims.pos",
"BinomialQueue.forest",
"BinomialQueue.tree",
"BinomialQueue.ms",
"FStar.Pervasives.Native.Mktuple3",
"Prims.list",
"BinomialQueue.carry_repr",
"BinomialQueue.join_repr",
"Prims.op_Addition",
"BinomialQueue.Leaf",
"BinomialQueue.keys",
"BinomialQueue.ms_empty",
"BinomialQueue.smash",
"BinomialQueue.ms_append",
"BinomialQueue.keys_of_tree",
"Prims.unit",
"BinomialQueue.smash_repr",
"Prims.l_and",
"BinomialQueue.is_binomial_queue",
"Prims.l_or",
"Prims.b2t",
"BinomialQueue.uu___is_Leaf",
"BinomialQueue.is_pow2heap",
"BinomialQueue.repr_l",
"BinomialQueue.repr_t",
"Prims.squash",
"BinomialQueue.join",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [
"recursion"
] | false | false | true | false | false | let rec join_repr (d: pos) (p q: forest) (c: tree) (lp lq lc: ms)
: Lemma
(requires
is_binomial_queue d p /\ is_binomial_queue d q /\ (Leaf? c \/ is_pow2heap d c) /\
p `repr_l` lp /\ q `repr_l` lq /\ c `repr_t` lc)
(ensures (join d p q c) `repr_l` (ms_append lp (ms_append lq lc)))
(decreases p) =
| match p, q, c with
| [], _, Leaf | _, [], Leaf -> ()
| [], _, _ -> carry_repr d q c lq lc
| _, [], _ -> carry_repr d p c lp lc
| Leaf :: tl_p, Leaf :: tl_q, _ -> join_repr (d + 1) tl_p tl_q Leaf (keys tl_p) (keys tl_q) ms_empty
| hd_p :: tl_p, Leaf :: tl_q, Leaf ->
join_repr (d + 1) tl_p tl_q Leaf (keys tl_p) (keys tl_q) ms_empty
| Leaf :: tl_p, hd_q :: tl_q, Leaf ->
join_repr (d + 1) tl_p tl_q Leaf (keys tl_p) (keys tl_q) ms_empty
| Leaf :: tl_p, hd_q :: tl_q, _ ->
smash_repr d hd_q c (keys_of_tree hd_q) (keys_of_tree c);
join_repr (d + 1)
tl_p
tl_q
(smash d hd_q c)
(keys tl_p)
(keys tl_q)
(ms_append (keys_of_tree hd_q) (keys_of_tree c))
| hd_p :: tl_p, Leaf :: tl_q, _ ->
smash_repr d hd_p c (keys_of_tree hd_p) (keys_of_tree c);
join_repr (d + 1)
tl_p
tl_q
(smash d hd_p c)
(keys tl_p)
(keys tl_q)
(ms_append (keys_of_tree hd_p) (keys_of_tree c))
| hd_p :: tl_p, hd_q :: tl_q, c ->
smash_repr d hd_p hd_q (keys_of_tree hd_p) (keys_of_tree hd_q);
join_repr (d + 1)
tl_p
tl_q
(smash d hd_p hd_q)
(keys tl_p)
(keys tl_q)
(ms_append (keys_of_tree hd_p) (keys_of_tree hd_q)) | false |
Vale.Bignum.X64.fsti | Vale.Bignum.X64.flags_t | val flags_t : Type0 | let flags_t = Vale.X64.Flags.t | {
"file_name": "obj/Vale.Bignum.X64.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 30,
"end_line": 17,
"start_col": 0,
"start_line": 17
} | module Vale.Bignum.X64
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Arch.Types
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.X64.Stack_i
open Vale.X64.State
open Vale.X64.Decls
open Vale.X64.InsBasic
open Vale.X64.InsMem
open Vale.X64.InsStack
open Vale.X64.QuickCode
open Vale.X64.QuickCodes
open Vale.X64.CPU_Features_s | {
"checked_file": "/",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.Stack_i.fsti.checked",
"Vale.X64.QuickCodes.fsti.checked",
"Vale.X64.QuickCode.fst.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.InsStack.fsti.checked",
"Vale.X64.InsMem.fsti.checked",
"Vale.X64.InsBasic.fsti.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.X64.Decls.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Bignum.Defs.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.Bignum.X64.fsti"
} | [
{
"abbrev": false,
"full_module": "Vale.Bignum.Defs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCodes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsMem",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsBasic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Stack_i",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Type0 | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Flags.t"
] | [] | false | false | false | true | true | let flags_t =
| Vale.X64.Flags.t | false |
|
Vale.Bignum.X64.fsti | Vale.Bignum.X64.update_cf | val update_cf : f': Vale.Bignum.X64.flags_t -> c: Vale.Def.Words_s.nat1 -> Prims.logical | let update_cf (f':flags_t) (c:nat1) = flag_cf f' == c /\ valid_cf f' | {
"file_name": "obj/Vale.Bignum.X64.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 68,
"end_line": 20,
"start_col": 0,
"start_line": 20
} | module Vale.Bignum.X64
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Arch.Types
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.X64.Stack_i
open Vale.X64.State
open Vale.X64.Decls
open Vale.X64.InsBasic
open Vale.X64.InsMem
open Vale.X64.InsStack
open Vale.X64.QuickCode
open Vale.X64.QuickCodes
open Vale.X64.CPU_Features_s
open Vale.Bignum.Defs
let flags_t = Vale.X64.Flags.t
val flag_cf (f:flags_t) : nat1 | {
"checked_file": "/",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.Stack_i.fsti.checked",
"Vale.X64.QuickCodes.fsti.checked",
"Vale.X64.QuickCode.fst.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.InsStack.fsti.checked",
"Vale.X64.InsMem.fsti.checked",
"Vale.X64.InsBasic.fsti.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.X64.Decls.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Bignum.Defs.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.Bignum.X64.fsti"
} | [
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Bignum.Defs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCodes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsMem",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsBasic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Stack_i",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Bignum.Defs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCodes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsMem",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsBasic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Stack_i",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | f': Vale.Bignum.X64.flags_t -> c: Vale.Def.Words_s.nat1 -> Prims.logical | Prims.Tot | [
"total"
] | [] | [
"Vale.Bignum.X64.flags_t",
"Vale.Def.Words_s.nat1",
"Prims.l_and",
"Prims.eq2",
"Vale.Bignum.X64.flag_cf",
"Prims.b2t",
"Vale.X64.Decls.valid_cf",
"Prims.logical"
] | [] | false | false | false | true | true | let update_cf (f': flags_t) (c: nat1) =
| flag_cf f' == c /\ valid_cf f' | false |
|
LListReverse.fst | LListReverse.pop | val pop (#l: Ghost.erased (list U64.t)) (p: ref llist_cell {Cons? l})
: STT (ref llist_cell)
(llist l p)
(fun p' ->
exists_ (fun x ->
((pts_to p full_perm x) `star` (llist (List.Tot.tl l) p'))
`star`
(pure (x.value == List.Tot.hd l)))) | val pop (#l: Ghost.erased (list U64.t)) (p: ref llist_cell {Cons? l})
: STT (ref llist_cell)
(llist l p)
(fun p' ->
exists_ (fun x ->
((pts_to p full_perm x) `star` (llist (List.Tot.tl l) p'))
`star`
(pure (x.value == List.Tot.hd l)))) | let pop
(#l: Ghost.erased (list U64.t))
(p: ref llist_cell { Cons? l })
: STT (ref llist_cell)
(llist l p)
(fun p' -> exists_ (fun x -> pts_to p full_perm x `star` llist (List.Tot.tl l) p' `star` pure (x.value == List.Tot.hd l)))
= rewrite (llist l p) (llist_cons (List.Tot.hd l) (llist (List.Tot.tl l)) p);
let _ = gen_elim () in
// let p' = (read p).next in // FIXME: "Effects STBase and Tot cannot be composed"
let x = read p in
let p' = x.next in
vpattern_rewrite (llist _) p';
return p' | {
"file_name": "share/steel/tests/krml/LListReverse.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 11,
"end_line": 76,
"start_col": 0,
"start_line": 64
} | module LListReverse
open Steel.ST.GenElim
open Steel.ST.Reference
open Steel.ST.Loops
module U64 = FStar.UInt64
let main () = C.EXIT_SUCCESS // dummy for compilation
noeq
type llist_cell = {
value: U64.t;
next: ref llist_cell;
}
[@@__reduce__]
let llist_nil
(p: ref llist_cell)
: Tot vprop
= pure (p == null)
[@@__reduce__]
let llist_cons
(a: U64.t)
(llist: (ref llist_cell -> Tot vprop))
(p: ref llist_cell)
: Tot vprop
= exists_ (fun c ->
pts_to p full_perm c `star`
pure (c.value == a) `star`
llist c.next
)
let rec llist
(l: Ghost.erased (list U64.t))
: Tot (ref llist_cell -> vprop)
(decreases Ghost.reveal l)
= match Ghost.reveal l with
| [] -> llist_nil
| a :: q -> llist_cons a (llist q)
let llist_nil_is_null
(#opened: _)
(l: Ghost.erased (list U64.t))
(p: ref llist_cell)
: STGhost unit opened
(llist l p)
(fun _ -> llist l p)
True
(fun _ -> (p == null <==> Nil? l))
= if Nil? l
then begin
rewrite (llist l p) (llist_nil p);
let _ = gen_elim () in
rewrite (llist_nil p) (llist l p)
end else begin
let a :: q = Ghost.reveal l in
rewrite (llist l p) (llist_cons a (llist q) p);
let _ = gen_elim () in
pts_to_not_null p;
rewrite (llist_cons a (llist q) p) (llist l p)
end | {
"checked_file": "/",
"dependencies": [
"Steel.ST.Reference.fsti.checked",
"Steel.ST.Loops.fsti.checked",
"Steel.ST.GenElim.fsti.checked",
"prims.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked",
"C.fst.checked"
],
"interface_file": false,
"source_file": "LListReverse.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": false,
"full_module": "Steel.ST.Loops",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.Reference",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.GenElim",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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 | p: Steel.ST.Reference.ref LListReverse.llist_cell {Cons? (FStar.Ghost.reveal l)}
-> Steel.ST.Effect.STT (Steel.ST.Reference.ref LListReverse.llist_cell) | Steel.ST.Effect.STT | [] | [] | [
"FStar.Ghost.erased",
"Prims.list",
"FStar.UInt64.t",
"Steel.ST.Reference.ref",
"LListReverse.llist_cell",
"Prims.b2t",
"Prims.uu___is_Cons",
"FStar.Ghost.reveal",
"Steel.ST.Util.return",
"FStar.Ghost.hide",
"FStar.Set.set",
"Steel.Memory.iname",
"FStar.Set.empty",
"Steel.ST.Util.exists_",
"Steel.Effect.Common.VStar",
"Steel.ST.Reference.pts_to",
"Steel.FractionalPermission.full_perm",
"LListReverse.llist",
"FStar.List.Tot.Base.tl",
"Steel.ST.Util.pure",
"Prims.eq2",
"LListReverse.__proj__Mkllist_cell__item__value",
"FStar.List.Tot.Base.hd",
"Steel.Effect.Common.vprop",
"Prims.unit",
"Steel.ST.Util.vpattern_rewrite",
"LListReverse.__proj__Mkllist_cell__item__next",
"Steel.ST.Reference.read",
"Steel.ST.GenElim.gen_elim",
"Steel.Effect.Common.star",
"Steel.Effect.Common.emp",
"Prims.l_and",
"Prims.l_True",
"Prims.prop",
"Steel.ST.Util.rewrite",
"LListReverse.llist_cons"
] | [] | false | true | false | false | false | let pop (#l: Ghost.erased (list U64.t)) (p: ref llist_cell {Cons? l})
: STT (ref llist_cell)
(llist l p)
(fun p' ->
exists_ (fun x ->
((pts_to p full_perm x) `star` (llist (List.Tot.tl l) p'))
`star`
(pure (x.value == List.Tot.hd l)))) =
| rewrite (llist l p) (llist_cons (List.Tot.hd l) (llist (List.Tot.tl l)) p);
let _ = gen_elim () in
let x = read p in
let p' = x.next in
vpattern_rewrite (llist _) p';
return p' | false |
Vale.Bignum.X64.fsti | Vale.Bignum.X64.update_of | val update_of : f': Vale.Bignum.X64.flags_t -> o: Vale.Def.Words_s.nat1 -> Prims.logical | let update_of (f':flags_t) (o:nat1) = flag_of f' == o /\ valid_of f' | {
"file_name": "obj/Vale.Bignum.X64.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 68,
"end_line": 21,
"start_col": 0,
"start_line": 21
} | module Vale.Bignum.X64
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Arch.Types
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.X64.Stack_i
open Vale.X64.State
open Vale.X64.Decls
open Vale.X64.InsBasic
open Vale.X64.InsMem
open Vale.X64.InsStack
open Vale.X64.QuickCode
open Vale.X64.QuickCodes
open Vale.X64.CPU_Features_s
open Vale.Bignum.Defs
let flags_t = Vale.X64.Flags.t
val flag_cf (f:flags_t) : nat1
val flag_of (f:flags_t) : nat1 | {
"checked_file": "/",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.Stack_i.fsti.checked",
"Vale.X64.QuickCodes.fsti.checked",
"Vale.X64.QuickCode.fst.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.InsStack.fsti.checked",
"Vale.X64.InsMem.fsti.checked",
"Vale.X64.InsBasic.fsti.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.X64.Decls.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Bignum.Defs.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.Bignum.X64.fsti"
} | [
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Bignum.Defs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCodes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsMem",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsBasic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Stack_i",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Bignum.Defs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCodes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsMem",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsBasic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Stack_i",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | f': Vale.Bignum.X64.flags_t -> o: Vale.Def.Words_s.nat1 -> Prims.logical | Prims.Tot | [
"total"
] | [] | [
"Vale.Bignum.X64.flags_t",
"Vale.Def.Words_s.nat1",
"Prims.l_and",
"Prims.eq2",
"Vale.Bignum.X64.flag_of",
"Prims.b2t",
"Vale.X64.Decls.valid_of",
"Prims.logical"
] | [] | false | false | false | true | true | let update_of (f': flags_t) (o: nat1) =
| flag_of f' == o /\ valid_of f' | false |
|
Vale.Bignum.X64.fsti | Vale.Bignum.X64.maintain_of | val maintain_of : f': Vale.Bignum.X64.flags_t -> f: Vale.Bignum.X64.flags_t -> Prims.logical | let maintain_of (f':flags_t) (f:flags_t) = flag_of f' == flag_of f /\ valid_of f' == valid_of f | {
"file_name": "obj/Vale.Bignum.X64.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 95,
"end_line": 23,
"start_col": 0,
"start_line": 23
} | module Vale.Bignum.X64
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Arch.Types
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.X64.Stack_i
open Vale.X64.State
open Vale.X64.Decls
open Vale.X64.InsBasic
open Vale.X64.InsMem
open Vale.X64.InsStack
open Vale.X64.QuickCode
open Vale.X64.QuickCodes
open Vale.X64.CPU_Features_s
open Vale.Bignum.Defs
let flags_t = Vale.X64.Flags.t
val flag_cf (f:flags_t) : nat1
val flag_of (f:flags_t) : nat1
let update_cf (f':flags_t) (c:nat1) = flag_cf f' == c /\ valid_cf f'
let update_of (f':flags_t) (o:nat1) = flag_of f' == o /\ valid_of f' | {
"checked_file": "/",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.Stack_i.fsti.checked",
"Vale.X64.QuickCodes.fsti.checked",
"Vale.X64.QuickCode.fst.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.InsStack.fsti.checked",
"Vale.X64.InsMem.fsti.checked",
"Vale.X64.InsBasic.fsti.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.X64.Decls.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Bignum.Defs.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.Bignum.X64.fsti"
} | [
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Bignum.Defs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCodes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsMem",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsBasic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Stack_i",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Bignum.Defs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCodes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsMem",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsBasic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Stack_i",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | f': Vale.Bignum.X64.flags_t -> f: Vale.Bignum.X64.flags_t -> Prims.logical | Prims.Tot | [
"total"
] | [] | [
"Vale.Bignum.X64.flags_t",
"Prims.l_and",
"Prims.eq2",
"Vale.Def.Words_s.nat1",
"Vale.Bignum.X64.flag_of",
"Prims.bool",
"Vale.X64.Decls.valid_of",
"Prims.logical"
] | [] | false | false | false | true | true | let maintain_of (f' f: flags_t) =
| flag_of f' == flag_of f /\ valid_of f' == valid_of f | false |
|
Vale.Bignum.X64.fsti | Vale.Bignum.X64.maintain_cf | val maintain_cf : f': Vale.Bignum.X64.flags_t -> f: Vale.Bignum.X64.flags_t -> Prims.logical | let maintain_cf (f':flags_t) (f:flags_t) = flag_cf f' == flag_cf f /\ valid_cf f' == valid_cf f | {
"file_name": "obj/Vale.Bignum.X64.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 95,
"end_line": 22,
"start_col": 0,
"start_line": 22
} | module Vale.Bignum.X64
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Arch.Types
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.X64.Stack_i
open Vale.X64.State
open Vale.X64.Decls
open Vale.X64.InsBasic
open Vale.X64.InsMem
open Vale.X64.InsStack
open Vale.X64.QuickCode
open Vale.X64.QuickCodes
open Vale.X64.CPU_Features_s
open Vale.Bignum.Defs
let flags_t = Vale.X64.Flags.t
val flag_cf (f:flags_t) : nat1
val flag_of (f:flags_t) : nat1
let update_cf (f':flags_t) (c:nat1) = flag_cf f' == c /\ valid_cf f' | {
"checked_file": "/",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.Stack_i.fsti.checked",
"Vale.X64.QuickCodes.fsti.checked",
"Vale.X64.QuickCode.fst.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.InsStack.fsti.checked",
"Vale.X64.InsMem.fsti.checked",
"Vale.X64.InsBasic.fsti.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.X64.Decls.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Bignum.Defs.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.Bignum.X64.fsti"
} | [
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Bignum.Defs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCodes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsMem",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsBasic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Stack_i",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Bignum.Defs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCodes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsMem",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsBasic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Stack_i",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | f': Vale.Bignum.X64.flags_t -> f: Vale.Bignum.X64.flags_t -> Prims.logical | Prims.Tot | [
"total"
] | [] | [
"Vale.Bignum.X64.flags_t",
"Prims.l_and",
"Prims.eq2",
"Vale.Def.Words_s.nat1",
"Vale.Bignum.X64.flag_cf",
"Prims.bool",
"Vale.X64.Decls.valid_cf",
"Prims.logical"
] | [] | false | false | false | true | true | let maintain_cf (f' f: flags_t) =
| flag_cf f' == flag_cf f /\ valid_cf f' == valid_cf f | false |
|
Vale.Bignum.X64.fsti | Vale.Bignum.X64.va_wp_Adcx_64 | val va_wp_Adcx_64
(dst: va_operand_dst_opr64)
(src: va_operand_opr64)
(va_s0: va_state)
(va_k: (va_state -> unit -> Type0))
: Type0 | val va_wp_Adcx_64
(dst: va_operand_dst_opr64)
(src: va_operand_opr64)
(va_s0: va_state)
(va_k: (va_state -> unit -> Type0))
: Type0 | let va_wp_Adcx_64 (dst:va_operand_dst_opr64) (src:va_operand_opr64) (va_s0:va_state)
(va_k:(va_state -> unit -> Type0)) : Type0 =
(va_is_dst_dst_opr64 dst va_s0 /\ va_is_src_opr64 src va_s0 /\ va_get_ok va_s0 /\ adx_enabled /\
Vale.X64.Decls.valid_cf (va_get_flags va_s0) /\ (forall (va_x_dst:va_value_dst_opr64)
(va_x_efl:Vale.X64.Flags.t) . let va_sM = va_upd_flags va_x_efl (va_upd_operand_dst_opr64 dst
va_x_dst va_s0) in va_get_ok va_sM /\ va_eval_dst_opr64 va_sM dst == Vale.Bignum.Defs.add_lo
(va_eval_dst_opr64 va_s0 dst) (va_eval_opr64 va_s0 src) (flag_cf (va_get_flags va_s0)) /\
update_cf (va_get_flags va_sM) (Vale.Bignum.Defs.add_hi (va_eval_dst_opr64 va_s0 dst)
(va_eval_opr64 va_s0 src) (flag_cf (va_get_flags va_s0))) /\ maintain_of (va_get_flags va_sM)
(va_get_flags va_s0) ==> va_k va_sM (()))) | {
"file_name": "obj/Vale.Bignum.X64.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 46,
"end_line": 69,
"start_col": 0,
"start_line": 60
} | module Vale.Bignum.X64
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Arch.Types
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.X64.Stack_i
open Vale.X64.State
open Vale.X64.Decls
open Vale.X64.InsBasic
open Vale.X64.InsMem
open Vale.X64.InsStack
open Vale.X64.QuickCode
open Vale.X64.QuickCodes
open Vale.X64.CPU_Features_s
open Vale.Bignum.Defs
let flags_t = Vale.X64.Flags.t
val flag_cf (f:flags_t) : nat1
val flag_of (f:flags_t) : nat1
let update_cf (f':flags_t) (c:nat1) = flag_cf f' == c /\ valid_cf f'
let update_of (f':flags_t) (o:nat1) = flag_of f' == o /\ valid_of f'
let maintain_cf (f':flags_t) (f:flags_t) = flag_cf f' == flag_cf f /\ valid_cf f' == valid_cf f
let maintain_of (f':flags_t) (f:flags_t) = flag_of f' == flag_of f /\ valid_of f' == valid_of f
//-- reveal_flags
val reveal_flags : f:flags_t
-> Lemma
(requires true)
(ensures (flag_cf f = 1 == Vale.X64.Decls.cf f /\ flag_of f = 1 == Vale.X64.Decls.overflow f))
//--
//-- lemma_add_hi_lo64
val lemma_add_hi_lo64 : dummy:int
-> Lemma
(requires true)
(ensures (forall (a:nat64) (b:nat64) (c:nat1) . {:pattern(add_lo a b c); (add_hi a b
c)}Vale.Bignum.Defs.add_lo a b c + va_mul_nat pow2_64 (Vale.Bignum.Defs.add_hi a b c) == a + b
+ c))
//--
//-- Adcx_64
val va_code_Adcx_64 : dst:va_operand_dst_opr64 -> src:va_operand_opr64 -> Tot va_code
val va_codegen_success_Adcx_64 : dst:va_operand_dst_opr64 -> src:va_operand_opr64 -> Tot va_pbool
val va_lemma_Adcx_64 : va_b0:va_code -> va_s0:va_state -> dst:va_operand_dst_opr64 ->
src:va_operand_opr64
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_Adcx_64 dst src) va_s0 /\ va_is_dst_dst_opr64 dst
va_s0 /\ va_is_src_opr64 src va_s0 /\ va_get_ok va_s0 /\ adx_enabled /\ Vale.X64.Decls.valid_cf
(va_get_flags va_s0)))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
va_eval_dst_opr64 va_sM dst == Vale.Bignum.Defs.add_lo (va_eval_dst_opr64 va_s0 dst)
(va_eval_opr64 va_s0 src) (flag_cf (va_get_flags va_s0)) /\ update_cf (va_get_flags va_sM)
(Vale.Bignum.Defs.add_hi (va_eval_dst_opr64 va_s0 dst) (va_eval_opr64 va_s0 src) (flag_cf
(va_get_flags va_s0))) /\ maintain_of (va_get_flags va_sM) (va_get_flags va_s0) /\ va_state_eq
va_sM (va_update_flags va_sM (va_update_ok va_sM (va_update_operand_dst_opr64 dst va_sM
va_s0))))) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.Stack_i.fsti.checked",
"Vale.X64.QuickCodes.fsti.checked",
"Vale.X64.QuickCode.fst.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.InsStack.fsti.checked",
"Vale.X64.InsMem.fsti.checked",
"Vale.X64.InsBasic.fsti.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.X64.Decls.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Bignum.Defs.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.Bignum.X64.fsti"
} | [
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Bignum.Defs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCodes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsMem",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsBasic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Stack_i",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Bignum.Defs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCodes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsMem",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsBasic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Stack_i",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
dst: Vale.X64.Decls.va_operand_dst_opr64 ->
src: Vale.X64.Decls.va_operand_opr64 ->
va_s0: Vale.X64.Decls.va_state ->
va_k: (_: Vale.X64.Decls.va_state -> _: Prims.unit -> Type0)
-> Type0 | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Decls.va_operand_dst_opr64",
"Vale.X64.Decls.va_operand_opr64",
"Vale.X64.Decls.va_state",
"Prims.unit",
"Prims.l_and",
"Prims.b2t",
"Vale.X64.Decls.va_is_dst_dst_opr64",
"Vale.X64.Decls.va_is_src_opr64",
"Vale.X64.Decls.va_get_ok",
"Vale.X64.CPU_Features_s.adx_enabled",
"Vale.X64.Decls.valid_cf",
"Vale.X64.Decls.va_get_flags",
"Prims.l_Forall",
"Vale.X64.Decls.va_value_dst_opr64",
"Vale.X64.Flags.t",
"Prims.l_imp",
"Prims.eq2",
"Vale.Def.Words_s.natN",
"Vale.Def.Words_s.pow2_64",
"Vale.X64.Decls.va_eval_dst_opr64",
"Vale.Bignum.Defs.add_lo",
"Vale.X64.Decls.va_eval_opr64",
"Vale.Bignum.X64.flag_cf",
"Vale.Bignum.X64.update_cf",
"Vale.Bignum.Defs.add_hi",
"Vale.Bignum.X64.maintain_of",
"Vale.X64.State.vale_state",
"Vale.X64.Decls.va_upd_flags",
"Vale.X64.Decls.va_upd_operand_dst_opr64"
] | [] | false | false | false | true | true | let va_wp_Adcx_64
(dst: va_operand_dst_opr64)
(src: va_operand_opr64)
(va_s0: va_state)
(va_k: (va_state -> unit -> Type0))
: Type0 =
| (va_is_dst_dst_opr64 dst va_s0 /\ va_is_src_opr64 src va_s0 /\ va_get_ok va_s0 /\ adx_enabled /\
Vale.X64.Decls.valid_cf (va_get_flags va_s0) /\
(forall (va_x_dst: va_value_dst_opr64) (va_x_efl: Vale.X64.Flags.t).
let va_sM = va_upd_flags va_x_efl (va_upd_operand_dst_opr64 dst va_x_dst va_s0) in
va_get_ok va_sM /\
va_eval_dst_opr64 va_sM dst ==
Vale.Bignum.Defs.add_lo (va_eval_dst_opr64 va_s0 dst)
(va_eval_opr64 va_s0 src)
(flag_cf (va_get_flags va_s0)) /\
update_cf (va_get_flags va_sM)
(Vale.Bignum.Defs.add_hi (va_eval_dst_opr64 va_s0 dst)
(va_eval_opr64 va_s0 src)
(flag_cf (va_get_flags va_s0))) /\ maintain_of (va_get_flags va_sM) (va_get_flags va_s0) ==>
va_k va_sM (()))) | false |
Vale.Bignum.X64.fsti | Vale.Bignum.X64.va_wp_Adox_64 | val va_wp_Adox_64
(dst: va_operand_dst_opr64)
(src: va_operand_opr64)
(va_s0: va_state)
(va_k: (va_state -> unit -> Type0))
: Type0 | val va_wp_Adox_64
(dst: va_operand_dst_opr64)
(src: va_operand_opr64)
(va_s0: va_state)
(va_k: (va_state -> unit -> Type0))
: Type0 | let va_wp_Adox_64 (dst:va_operand_dst_opr64) (src:va_operand_opr64) (va_s0:va_state)
(va_k:(va_state -> unit -> Type0)) : Type0 =
(va_is_dst_dst_opr64 dst va_s0 /\ va_is_src_opr64 src va_s0 /\ va_get_ok va_s0 /\ adx_enabled /\
Vale.X64.Decls.valid_of (va_get_flags va_s0) /\ (forall (va_x_dst:va_value_dst_opr64)
(va_x_efl:Vale.X64.Flags.t) . let va_sM = va_upd_flags va_x_efl (va_upd_operand_dst_opr64 dst
va_x_dst va_s0) in va_get_ok va_sM /\ va_eval_dst_opr64 va_sM dst == Vale.Bignum.Defs.add_lo
(va_eval_dst_opr64 va_s0 dst) (va_eval_opr64 va_s0 src) (flag_of (va_get_flags va_s0)) /\
update_of (va_get_flags va_sM) (Vale.Bignum.Defs.add_hi (va_eval_dst_opr64 va_s0 dst)
(va_eval_opr64 va_s0 src) (flag_of (va_get_flags va_s0))) /\ maintain_cf (va_get_flags va_sM)
(va_get_flags va_s0) ==> va_k va_sM (()))) | {
"file_name": "obj/Vale.Bignum.X64.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 46,
"end_line": 112,
"start_col": 0,
"start_line": 103
} | module Vale.Bignum.X64
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Arch.Types
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.X64.Stack_i
open Vale.X64.State
open Vale.X64.Decls
open Vale.X64.InsBasic
open Vale.X64.InsMem
open Vale.X64.InsStack
open Vale.X64.QuickCode
open Vale.X64.QuickCodes
open Vale.X64.CPU_Features_s
open Vale.Bignum.Defs
let flags_t = Vale.X64.Flags.t
val flag_cf (f:flags_t) : nat1
val flag_of (f:flags_t) : nat1
let update_cf (f':flags_t) (c:nat1) = flag_cf f' == c /\ valid_cf f'
let update_of (f':flags_t) (o:nat1) = flag_of f' == o /\ valid_of f'
let maintain_cf (f':flags_t) (f:flags_t) = flag_cf f' == flag_cf f /\ valid_cf f' == valid_cf f
let maintain_of (f':flags_t) (f:flags_t) = flag_of f' == flag_of f /\ valid_of f' == valid_of f
//-- reveal_flags
val reveal_flags : f:flags_t
-> Lemma
(requires true)
(ensures (flag_cf f = 1 == Vale.X64.Decls.cf f /\ flag_of f = 1 == Vale.X64.Decls.overflow f))
//--
//-- lemma_add_hi_lo64
val lemma_add_hi_lo64 : dummy:int
-> Lemma
(requires true)
(ensures (forall (a:nat64) (b:nat64) (c:nat1) . {:pattern(add_lo a b c); (add_hi a b
c)}Vale.Bignum.Defs.add_lo a b c + va_mul_nat pow2_64 (Vale.Bignum.Defs.add_hi a b c) == a + b
+ c))
//--
//-- Adcx_64
val va_code_Adcx_64 : dst:va_operand_dst_opr64 -> src:va_operand_opr64 -> Tot va_code
val va_codegen_success_Adcx_64 : dst:va_operand_dst_opr64 -> src:va_operand_opr64 -> Tot va_pbool
val va_lemma_Adcx_64 : va_b0:va_code -> va_s0:va_state -> dst:va_operand_dst_opr64 ->
src:va_operand_opr64
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_Adcx_64 dst src) va_s0 /\ va_is_dst_dst_opr64 dst
va_s0 /\ va_is_src_opr64 src va_s0 /\ va_get_ok va_s0 /\ adx_enabled /\ Vale.X64.Decls.valid_cf
(va_get_flags va_s0)))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
va_eval_dst_opr64 va_sM dst == Vale.Bignum.Defs.add_lo (va_eval_dst_opr64 va_s0 dst)
(va_eval_opr64 va_s0 src) (flag_cf (va_get_flags va_s0)) /\ update_cf (va_get_flags va_sM)
(Vale.Bignum.Defs.add_hi (va_eval_dst_opr64 va_s0 dst) (va_eval_opr64 va_s0 src) (flag_cf
(va_get_flags va_s0))) /\ maintain_of (va_get_flags va_sM) (va_get_flags va_s0) /\ va_state_eq
va_sM (va_update_flags va_sM (va_update_ok va_sM (va_update_operand_dst_opr64 dst va_sM
va_s0)))))
[@ va_qattr]
let va_wp_Adcx_64 (dst:va_operand_dst_opr64) (src:va_operand_opr64) (va_s0:va_state)
(va_k:(va_state -> unit -> Type0)) : Type0 =
(va_is_dst_dst_opr64 dst va_s0 /\ va_is_src_opr64 src va_s0 /\ va_get_ok va_s0 /\ adx_enabled /\
Vale.X64.Decls.valid_cf (va_get_flags va_s0) /\ (forall (va_x_dst:va_value_dst_opr64)
(va_x_efl:Vale.X64.Flags.t) . let va_sM = va_upd_flags va_x_efl (va_upd_operand_dst_opr64 dst
va_x_dst va_s0) in va_get_ok va_sM /\ va_eval_dst_opr64 va_sM dst == Vale.Bignum.Defs.add_lo
(va_eval_dst_opr64 va_s0 dst) (va_eval_opr64 va_s0 src) (flag_cf (va_get_flags va_s0)) /\
update_cf (va_get_flags va_sM) (Vale.Bignum.Defs.add_hi (va_eval_dst_opr64 va_s0 dst)
(va_eval_opr64 va_s0 src) (flag_cf (va_get_flags va_s0))) /\ maintain_of (va_get_flags va_sM)
(va_get_flags va_s0) ==> va_k va_sM (())))
val va_wpProof_Adcx_64 : dst:va_operand_dst_opr64 -> src:va_operand_opr64 -> va_s0:va_state ->
va_k:(va_state -> unit -> Type0)
-> Ghost (va_state & va_fuel & unit)
(requires (va_t_require va_s0 /\ va_wp_Adcx_64 dst src va_s0 va_k))
(ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_Adcx_64 dst src) ([va_Mod_flags;
va_mod_dst_opr64 dst]) va_s0 va_k ((va_sM, va_f0, va_g))))
[@ "opaque_to_smt" va_qattr]
let va_quick_Adcx_64 (dst:va_operand_dst_opr64) (src:va_operand_opr64) : (va_quickCode unit
(va_code_Adcx_64 dst src)) =
(va_QProc (va_code_Adcx_64 dst src) ([va_Mod_flags; va_mod_dst_opr64 dst]) (va_wp_Adcx_64 dst
src) (va_wpProof_Adcx_64 dst src))
//--
//-- Adox_64
val va_code_Adox_64 : dst:va_operand_dst_opr64 -> src:va_operand_opr64 -> Tot va_code
val va_codegen_success_Adox_64 : dst:va_operand_dst_opr64 -> src:va_operand_opr64 -> Tot va_pbool
val va_lemma_Adox_64 : va_b0:va_code -> va_s0:va_state -> dst:va_operand_dst_opr64 ->
src:va_operand_opr64
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_Adox_64 dst src) va_s0 /\ va_is_dst_dst_opr64 dst
va_s0 /\ va_is_src_opr64 src va_s0 /\ va_get_ok va_s0 /\ adx_enabled /\ Vale.X64.Decls.valid_of
(va_get_flags va_s0)))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
va_eval_dst_opr64 va_sM dst == Vale.Bignum.Defs.add_lo (va_eval_dst_opr64 va_s0 dst)
(va_eval_opr64 va_s0 src) (flag_of (va_get_flags va_s0)) /\ update_of (va_get_flags va_sM)
(Vale.Bignum.Defs.add_hi (va_eval_dst_opr64 va_s0 dst) (va_eval_opr64 va_s0 src) (flag_of
(va_get_flags va_s0))) /\ maintain_cf (va_get_flags va_sM) (va_get_flags va_s0) /\ va_state_eq
va_sM (va_update_flags va_sM (va_update_ok va_sM (va_update_operand_dst_opr64 dst va_sM
va_s0))))) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.Stack_i.fsti.checked",
"Vale.X64.QuickCodes.fsti.checked",
"Vale.X64.QuickCode.fst.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.InsStack.fsti.checked",
"Vale.X64.InsMem.fsti.checked",
"Vale.X64.InsBasic.fsti.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.X64.Decls.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Bignum.Defs.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.Bignum.X64.fsti"
} | [
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Bignum.Defs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCodes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsMem",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsBasic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Stack_i",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Bignum.Defs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCodes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsMem",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsBasic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Stack_i",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
dst: Vale.X64.Decls.va_operand_dst_opr64 ->
src: Vale.X64.Decls.va_operand_opr64 ->
va_s0: Vale.X64.Decls.va_state ->
va_k: (_: Vale.X64.Decls.va_state -> _: Prims.unit -> Type0)
-> Type0 | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Decls.va_operand_dst_opr64",
"Vale.X64.Decls.va_operand_opr64",
"Vale.X64.Decls.va_state",
"Prims.unit",
"Prims.l_and",
"Prims.b2t",
"Vale.X64.Decls.va_is_dst_dst_opr64",
"Vale.X64.Decls.va_is_src_opr64",
"Vale.X64.Decls.va_get_ok",
"Vale.X64.CPU_Features_s.adx_enabled",
"Vale.X64.Decls.valid_of",
"Vale.X64.Decls.va_get_flags",
"Prims.l_Forall",
"Vale.X64.Decls.va_value_dst_opr64",
"Vale.X64.Flags.t",
"Prims.l_imp",
"Prims.eq2",
"Vale.Def.Words_s.natN",
"Vale.Def.Words_s.pow2_64",
"Vale.X64.Decls.va_eval_dst_opr64",
"Vale.Bignum.Defs.add_lo",
"Vale.X64.Decls.va_eval_opr64",
"Vale.Bignum.X64.flag_of",
"Vale.Bignum.X64.update_of",
"Vale.Bignum.Defs.add_hi",
"Vale.Bignum.X64.maintain_cf",
"Vale.X64.State.vale_state",
"Vale.X64.Decls.va_upd_flags",
"Vale.X64.Decls.va_upd_operand_dst_opr64"
] | [] | false | false | false | true | true | let va_wp_Adox_64
(dst: va_operand_dst_opr64)
(src: va_operand_opr64)
(va_s0: va_state)
(va_k: (va_state -> unit -> Type0))
: Type0 =
| (va_is_dst_dst_opr64 dst va_s0 /\ va_is_src_opr64 src va_s0 /\ va_get_ok va_s0 /\ adx_enabled /\
Vale.X64.Decls.valid_of (va_get_flags va_s0) /\
(forall (va_x_dst: va_value_dst_opr64) (va_x_efl: Vale.X64.Flags.t).
let va_sM = va_upd_flags va_x_efl (va_upd_operand_dst_opr64 dst va_x_dst va_s0) in
va_get_ok va_sM /\
va_eval_dst_opr64 va_sM dst ==
Vale.Bignum.Defs.add_lo (va_eval_dst_opr64 va_s0 dst)
(va_eval_opr64 va_s0 src)
(flag_of (va_get_flags va_s0)) /\
update_of (va_get_flags va_sM)
(Vale.Bignum.Defs.add_hi (va_eval_dst_opr64 va_s0 dst)
(va_eval_opr64 va_s0 src)
(flag_of (va_get_flags va_s0))) /\ maintain_cf (va_get_flags va_sM) (va_get_flags va_s0) ==>
va_k va_sM (()))) | false |
Vale.Bignum.X64.fsti | Vale.Bignum.X64.va_quick_Adox_64 | val va_quick_Adox_64 (dst: va_operand_dst_opr64) (src: va_operand_opr64)
: (va_quickCode unit (va_code_Adox_64 dst src)) | val va_quick_Adox_64 (dst: va_operand_dst_opr64) (src: va_operand_opr64)
: (va_quickCode unit (va_code_Adox_64 dst src)) | let va_quick_Adox_64 (dst:va_operand_dst_opr64) (src:va_operand_opr64) : (va_quickCode unit
(va_code_Adox_64 dst src)) =
(va_QProc (va_code_Adox_64 dst src) ([va_Mod_flags; va_mod_dst_opr64 dst]) (va_wp_Adox_64 dst
src) (va_wpProof_Adox_64 dst src)) | {
"file_name": "obj/Vale.Bignum.X64.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 38,
"end_line": 124,
"start_col": 0,
"start_line": 121
} | module Vale.Bignum.X64
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Arch.Types
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.X64.Stack_i
open Vale.X64.State
open Vale.X64.Decls
open Vale.X64.InsBasic
open Vale.X64.InsMem
open Vale.X64.InsStack
open Vale.X64.QuickCode
open Vale.X64.QuickCodes
open Vale.X64.CPU_Features_s
open Vale.Bignum.Defs
let flags_t = Vale.X64.Flags.t
val flag_cf (f:flags_t) : nat1
val flag_of (f:flags_t) : nat1
let update_cf (f':flags_t) (c:nat1) = flag_cf f' == c /\ valid_cf f'
let update_of (f':flags_t) (o:nat1) = flag_of f' == o /\ valid_of f'
let maintain_cf (f':flags_t) (f:flags_t) = flag_cf f' == flag_cf f /\ valid_cf f' == valid_cf f
let maintain_of (f':flags_t) (f:flags_t) = flag_of f' == flag_of f /\ valid_of f' == valid_of f
//-- reveal_flags
val reveal_flags : f:flags_t
-> Lemma
(requires true)
(ensures (flag_cf f = 1 == Vale.X64.Decls.cf f /\ flag_of f = 1 == Vale.X64.Decls.overflow f))
//--
//-- lemma_add_hi_lo64
val lemma_add_hi_lo64 : dummy:int
-> Lemma
(requires true)
(ensures (forall (a:nat64) (b:nat64) (c:nat1) . {:pattern(add_lo a b c); (add_hi a b
c)}Vale.Bignum.Defs.add_lo a b c + va_mul_nat pow2_64 (Vale.Bignum.Defs.add_hi a b c) == a + b
+ c))
//--
//-- Adcx_64
val va_code_Adcx_64 : dst:va_operand_dst_opr64 -> src:va_operand_opr64 -> Tot va_code
val va_codegen_success_Adcx_64 : dst:va_operand_dst_opr64 -> src:va_operand_opr64 -> Tot va_pbool
val va_lemma_Adcx_64 : va_b0:va_code -> va_s0:va_state -> dst:va_operand_dst_opr64 ->
src:va_operand_opr64
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_Adcx_64 dst src) va_s0 /\ va_is_dst_dst_opr64 dst
va_s0 /\ va_is_src_opr64 src va_s0 /\ va_get_ok va_s0 /\ adx_enabled /\ Vale.X64.Decls.valid_cf
(va_get_flags va_s0)))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
va_eval_dst_opr64 va_sM dst == Vale.Bignum.Defs.add_lo (va_eval_dst_opr64 va_s0 dst)
(va_eval_opr64 va_s0 src) (flag_cf (va_get_flags va_s0)) /\ update_cf (va_get_flags va_sM)
(Vale.Bignum.Defs.add_hi (va_eval_dst_opr64 va_s0 dst) (va_eval_opr64 va_s0 src) (flag_cf
(va_get_flags va_s0))) /\ maintain_of (va_get_flags va_sM) (va_get_flags va_s0) /\ va_state_eq
va_sM (va_update_flags va_sM (va_update_ok va_sM (va_update_operand_dst_opr64 dst va_sM
va_s0)))))
[@ va_qattr]
let va_wp_Adcx_64 (dst:va_operand_dst_opr64) (src:va_operand_opr64) (va_s0:va_state)
(va_k:(va_state -> unit -> Type0)) : Type0 =
(va_is_dst_dst_opr64 dst va_s0 /\ va_is_src_opr64 src va_s0 /\ va_get_ok va_s0 /\ adx_enabled /\
Vale.X64.Decls.valid_cf (va_get_flags va_s0) /\ (forall (va_x_dst:va_value_dst_opr64)
(va_x_efl:Vale.X64.Flags.t) . let va_sM = va_upd_flags va_x_efl (va_upd_operand_dst_opr64 dst
va_x_dst va_s0) in va_get_ok va_sM /\ va_eval_dst_opr64 va_sM dst == Vale.Bignum.Defs.add_lo
(va_eval_dst_opr64 va_s0 dst) (va_eval_opr64 va_s0 src) (flag_cf (va_get_flags va_s0)) /\
update_cf (va_get_flags va_sM) (Vale.Bignum.Defs.add_hi (va_eval_dst_opr64 va_s0 dst)
(va_eval_opr64 va_s0 src) (flag_cf (va_get_flags va_s0))) /\ maintain_of (va_get_flags va_sM)
(va_get_flags va_s0) ==> va_k va_sM (())))
val va_wpProof_Adcx_64 : dst:va_operand_dst_opr64 -> src:va_operand_opr64 -> va_s0:va_state ->
va_k:(va_state -> unit -> Type0)
-> Ghost (va_state & va_fuel & unit)
(requires (va_t_require va_s0 /\ va_wp_Adcx_64 dst src va_s0 va_k))
(ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_Adcx_64 dst src) ([va_Mod_flags;
va_mod_dst_opr64 dst]) va_s0 va_k ((va_sM, va_f0, va_g))))
[@ "opaque_to_smt" va_qattr]
let va_quick_Adcx_64 (dst:va_operand_dst_opr64) (src:va_operand_opr64) : (va_quickCode unit
(va_code_Adcx_64 dst src)) =
(va_QProc (va_code_Adcx_64 dst src) ([va_Mod_flags; va_mod_dst_opr64 dst]) (va_wp_Adcx_64 dst
src) (va_wpProof_Adcx_64 dst src))
//--
//-- Adox_64
val va_code_Adox_64 : dst:va_operand_dst_opr64 -> src:va_operand_opr64 -> Tot va_code
val va_codegen_success_Adox_64 : dst:va_operand_dst_opr64 -> src:va_operand_opr64 -> Tot va_pbool
val va_lemma_Adox_64 : va_b0:va_code -> va_s0:va_state -> dst:va_operand_dst_opr64 ->
src:va_operand_opr64
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_Adox_64 dst src) va_s0 /\ va_is_dst_dst_opr64 dst
va_s0 /\ va_is_src_opr64 src va_s0 /\ va_get_ok va_s0 /\ adx_enabled /\ Vale.X64.Decls.valid_of
(va_get_flags va_s0)))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
va_eval_dst_opr64 va_sM dst == Vale.Bignum.Defs.add_lo (va_eval_dst_opr64 va_s0 dst)
(va_eval_opr64 va_s0 src) (flag_of (va_get_flags va_s0)) /\ update_of (va_get_flags va_sM)
(Vale.Bignum.Defs.add_hi (va_eval_dst_opr64 va_s0 dst) (va_eval_opr64 va_s0 src) (flag_of
(va_get_flags va_s0))) /\ maintain_cf (va_get_flags va_sM) (va_get_flags va_s0) /\ va_state_eq
va_sM (va_update_flags va_sM (va_update_ok va_sM (va_update_operand_dst_opr64 dst va_sM
va_s0)))))
[@ va_qattr]
let va_wp_Adox_64 (dst:va_operand_dst_opr64) (src:va_operand_opr64) (va_s0:va_state)
(va_k:(va_state -> unit -> Type0)) : Type0 =
(va_is_dst_dst_opr64 dst va_s0 /\ va_is_src_opr64 src va_s0 /\ va_get_ok va_s0 /\ adx_enabled /\
Vale.X64.Decls.valid_of (va_get_flags va_s0) /\ (forall (va_x_dst:va_value_dst_opr64)
(va_x_efl:Vale.X64.Flags.t) . let va_sM = va_upd_flags va_x_efl (va_upd_operand_dst_opr64 dst
va_x_dst va_s0) in va_get_ok va_sM /\ va_eval_dst_opr64 va_sM dst == Vale.Bignum.Defs.add_lo
(va_eval_dst_opr64 va_s0 dst) (va_eval_opr64 va_s0 src) (flag_of (va_get_flags va_s0)) /\
update_of (va_get_flags va_sM) (Vale.Bignum.Defs.add_hi (va_eval_dst_opr64 va_s0 dst)
(va_eval_opr64 va_s0 src) (flag_of (va_get_flags va_s0))) /\ maintain_cf (va_get_flags va_sM)
(va_get_flags va_s0) ==> va_k va_sM (())))
val va_wpProof_Adox_64 : dst:va_operand_dst_opr64 -> src:va_operand_opr64 -> va_s0:va_state ->
va_k:(va_state -> unit -> Type0)
-> Ghost (va_state & va_fuel & unit)
(requires (va_t_require va_s0 /\ va_wp_Adox_64 dst src va_s0 va_k))
(ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_Adox_64 dst src) ([va_Mod_flags;
va_mod_dst_opr64 dst]) va_s0 va_k ((va_sM, va_f0, va_g)))) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.Stack_i.fsti.checked",
"Vale.X64.QuickCodes.fsti.checked",
"Vale.X64.QuickCode.fst.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.InsStack.fsti.checked",
"Vale.X64.InsMem.fsti.checked",
"Vale.X64.InsBasic.fsti.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.X64.Decls.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Bignum.Defs.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.Bignum.X64.fsti"
} | [
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Bignum.Defs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCodes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsMem",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsBasic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Stack_i",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Bignum.Defs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCodes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsMem",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsBasic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Stack_i",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | dst: Vale.X64.Decls.va_operand_dst_opr64 -> src: Vale.X64.Decls.va_operand_opr64
-> Vale.X64.QuickCode.va_quickCode Prims.unit (Vale.Bignum.X64.va_code_Adox_64 dst src) | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Decls.va_operand_dst_opr64",
"Vale.X64.Decls.va_operand_opr64",
"Vale.X64.QuickCode.va_QProc",
"Prims.unit",
"Vale.Bignum.X64.va_code_Adox_64",
"Prims.Cons",
"Vale.X64.QuickCode.mod_t",
"Vale.X64.QuickCode.va_Mod_flags",
"Vale.X64.QuickCode.va_mod_dst_opr64",
"Prims.Nil",
"Vale.Bignum.X64.va_wp_Adox_64",
"Vale.Bignum.X64.va_wpProof_Adox_64",
"Vale.X64.QuickCode.va_quickCode"
] | [] | false | false | false | false | false | let va_quick_Adox_64 (dst: va_operand_dst_opr64) (src: va_operand_opr64)
: (va_quickCode unit (va_code_Adox_64 dst src)) =
| (va_QProc (va_code_Adox_64 dst src)
([va_Mod_flags; va_mod_dst_opr64 dst])
(va_wp_Adox_64 dst src)
(va_wpProof_Adox_64 dst src)) | false |
Vale.Bignum.X64.fsti | Vale.Bignum.X64.va_quick_Adcx_64 | val va_quick_Adcx_64 (dst: va_operand_dst_opr64) (src: va_operand_opr64)
: (va_quickCode unit (va_code_Adcx_64 dst src)) | val va_quick_Adcx_64 (dst: va_operand_dst_opr64) (src: va_operand_opr64)
: (va_quickCode unit (va_code_Adcx_64 dst src)) | let va_quick_Adcx_64 (dst:va_operand_dst_opr64) (src:va_operand_opr64) : (va_quickCode unit
(va_code_Adcx_64 dst src)) =
(va_QProc (va_code_Adcx_64 dst src) ([va_Mod_flags; va_mod_dst_opr64 dst]) (va_wp_Adcx_64 dst
src) (va_wpProof_Adcx_64 dst src)) | {
"file_name": "obj/Vale.Bignum.X64.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 38,
"end_line": 81,
"start_col": 0,
"start_line": 78
} | module Vale.Bignum.X64
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.Arch.Types
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.X64.Stack_i
open Vale.X64.State
open Vale.X64.Decls
open Vale.X64.InsBasic
open Vale.X64.InsMem
open Vale.X64.InsStack
open Vale.X64.QuickCode
open Vale.X64.QuickCodes
open Vale.X64.CPU_Features_s
open Vale.Bignum.Defs
let flags_t = Vale.X64.Flags.t
val flag_cf (f:flags_t) : nat1
val flag_of (f:flags_t) : nat1
let update_cf (f':flags_t) (c:nat1) = flag_cf f' == c /\ valid_cf f'
let update_of (f':flags_t) (o:nat1) = flag_of f' == o /\ valid_of f'
let maintain_cf (f':flags_t) (f:flags_t) = flag_cf f' == flag_cf f /\ valid_cf f' == valid_cf f
let maintain_of (f':flags_t) (f:flags_t) = flag_of f' == flag_of f /\ valid_of f' == valid_of f
//-- reveal_flags
val reveal_flags : f:flags_t
-> Lemma
(requires true)
(ensures (flag_cf f = 1 == Vale.X64.Decls.cf f /\ flag_of f = 1 == Vale.X64.Decls.overflow f))
//--
//-- lemma_add_hi_lo64
val lemma_add_hi_lo64 : dummy:int
-> Lemma
(requires true)
(ensures (forall (a:nat64) (b:nat64) (c:nat1) . {:pattern(add_lo a b c); (add_hi a b
c)}Vale.Bignum.Defs.add_lo a b c + va_mul_nat pow2_64 (Vale.Bignum.Defs.add_hi a b c) == a + b
+ c))
//--
//-- Adcx_64
val va_code_Adcx_64 : dst:va_operand_dst_opr64 -> src:va_operand_opr64 -> Tot va_code
val va_codegen_success_Adcx_64 : dst:va_operand_dst_opr64 -> src:va_operand_opr64 -> Tot va_pbool
val va_lemma_Adcx_64 : va_b0:va_code -> va_s0:va_state -> dst:va_operand_dst_opr64 ->
src:va_operand_opr64
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_Adcx_64 dst src) va_s0 /\ va_is_dst_dst_opr64 dst
va_s0 /\ va_is_src_opr64 src va_s0 /\ va_get_ok va_s0 /\ adx_enabled /\ Vale.X64.Decls.valid_cf
(va_get_flags va_s0)))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
va_eval_dst_opr64 va_sM dst == Vale.Bignum.Defs.add_lo (va_eval_dst_opr64 va_s0 dst)
(va_eval_opr64 va_s0 src) (flag_cf (va_get_flags va_s0)) /\ update_cf (va_get_flags va_sM)
(Vale.Bignum.Defs.add_hi (va_eval_dst_opr64 va_s0 dst) (va_eval_opr64 va_s0 src) (flag_cf
(va_get_flags va_s0))) /\ maintain_of (va_get_flags va_sM) (va_get_flags va_s0) /\ va_state_eq
va_sM (va_update_flags va_sM (va_update_ok va_sM (va_update_operand_dst_opr64 dst va_sM
va_s0)))))
[@ va_qattr]
let va_wp_Adcx_64 (dst:va_operand_dst_opr64) (src:va_operand_opr64) (va_s0:va_state)
(va_k:(va_state -> unit -> Type0)) : Type0 =
(va_is_dst_dst_opr64 dst va_s0 /\ va_is_src_opr64 src va_s0 /\ va_get_ok va_s0 /\ adx_enabled /\
Vale.X64.Decls.valid_cf (va_get_flags va_s0) /\ (forall (va_x_dst:va_value_dst_opr64)
(va_x_efl:Vale.X64.Flags.t) . let va_sM = va_upd_flags va_x_efl (va_upd_operand_dst_opr64 dst
va_x_dst va_s0) in va_get_ok va_sM /\ va_eval_dst_opr64 va_sM dst == Vale.Bignum.Defs.add_lo
(va_eval_dst_opr64 va_s0 dst) (va_eval_opr64 va_s0 src) (flag_cf (va_get_flags va_s0)) /\
update_cf (va_get_flags va_sM) (Vale.Bignum.Defs.add_hi (va_eval_dst_opr64 va_s0 dst)
(va_eval_opr64 va_s0 src) (flag_cf (va_get_flags va_s0))) /\ maintain_of (va_get_flags va_sM)
(va_get_flags va_s0) ==> va_k va_sM (())))
val va_wpProof_Adcx_64 : dst:va_operand_dst_opr64 -> src:va_operand_opr64 -> va_s0:va_state ->
va_k:(va_state -> unit -> Type0)
-> Ghost (va_state & va_fuel & unit)
(requires (va_t_require va_s0 /\ va_wp_Adcx_64 dst src va_s0 va_k))
(ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_Adcx_64 dst src) ([va_Mod_flags;
va_mod_dst_opr64 dst]) va_s0 va_k ((va_sM, va_f0, va_g)))) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.Stack_i.fsti.checked",
"Vale.X64.QuickCodes.fsti.checked",
"Vale.X64.QuickCode.fst.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.InsStack.fsti.checked",
"Vale.X64.InsMem.fsti.checked",
"Vale.X64.InsBasic.fsti.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.X64.Decls.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Bignum.Defs.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.Bignum.X64.fsti"
} | [
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Bignum.Defs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCodes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsMem",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsBasic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Stack_i",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Bignum.Defs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCodes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsMem",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsBasic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Stack_i",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | dst: Vale.X64.Decls.va_operand_dst_opr64 -> src: Vale.X64.Decls.va_operand_opr64
-> Vale.X64.QuickCode.va_quickCode Prims.unit (Vale.Bignum.X64.va_code_Adcx_64 dst src) | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Decls.va_operand_dst_opr64",
"Vale.X64.Decls.va_operand_opr64",
"Vale.X64.QuickCode.va_QProc",
"Prims.unit",
"Vale.Bignum.X64.va_code_Adcx_64",
"Prims.Cons",
"Vale.X64.QuickCode.mod_t",
"Vale.X64.QuickCode.va_Mod_flags",
"Vale.X64.QuickCode.va_mod_dst_opr64",
"Prims.Nil",
"Vale.Bignum.X64.va_wp_Adcx_64",
"Vale.Bignum.X64.va_wpProof_Adcx_64",
"Vale.X64.QuickCode.va_quickCode"
] | [] | false | false | false | false | false | let va_quick_Adcx_64 (dst: va_operand_dst_opr64) (src: va_operand_opr64)
: (va_quickCode unit (va_code_Adcx_64 dst src)) =
| (va_QProc (va_code_Adcx_64 dst src)
([va_Mod_flags; va_mod_dst_opr64 dst])
(va_wp_Adcx_64 dst src)
(va_wpProof_Adcx_64 dst src)) | false |
Hacl.Spec.BignumQ.Lemmas.fst | Hacl.Spec.BignumQ.Lemmas.lemma_as_nat5 | val lemma_as_nat5: f:qelem5 ->
Lemma
(requires qelem_fits5 f (1, 1, 1, 1, 1))
(ensures as_nat5 f < pow2 280) | val lemma_as_nat5: f:qelem5 ->
Lemma
(requires qelem_fits5 f (1, 1, 1, 1, 1))
(ensures as_nat5 f < pow2 280) | let lemma_as_nat5 f =
//let (f0, f1, f2, f3, f4) = f in
//assert (as_nat5 f == v f0 + v f1 * pow56 + v f2 * pow112 + v f3 * pow168 + v f4 * pow224);
assert_norm (pow2 56 * pow2 56 = pow2 112);
assert_norm (pow2 56 * pow2 112 = pow2 168);
assert_norm (pow2 56 * pow2 168 = pow2 224);
assert_norm (pow2 56 * pow2 224 = pow2 280) | {
"file_name": "code/ed25519/Hacl.Spec.BignumQ.Lemmas.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 45,
"end_line": 36,
"start_col": 0,
"start_line": 30
} | module Hacl.Spec.BignumQ.Lemmas
open FStar.Tactics.CanonCommSemiring
open FStar.Mul
open Lib.IntTypes
module S = Spec.Ed25519
include Hacl.Spec.BignumQ.Definitions
let feq (#a #b:Type) (f:(a -> b)) (x y:a) :
Lemma (requires x == y) (ensures f x == f y) = ()
let eq_eq2 (#a:eqtype) (x y:a) :
Lemma (requires x = y) (ensures x == y) = ()
val lemma_mul_lt:a:nat -> b:nat -> c:nat -> d:nat ->
Lemma
(requires a < b /\ c < d)
(ensures a * c < b * d)
let lemma_mul_lt a b c d = ()
val lemma_as_nat5: f:qelem5 ->
Lemma
(requires qelem_fits5 f (1, 1, 1, 1, 1))
(ensures as_nat5 f < pow2 280) | {
"checked_file": "/",
"dependencies": [
"Spec.Ed25519.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.BignumQ.Definitions.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Tactics.CanonCommSemiring.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.BignumQ.Lemmas.fst"
} | [
{
"abbrev": false,
"full_module": "Hacl.Spec.BignumQ.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.Ed25519",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.CanonCommSemiring",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.BignumQ",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.BignumQ",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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 | f: Hacl.Spec.BignumQ.Definitions.qelem5
-> FStar.Pervasives.Lemma (requires Hacl.Spec.BignumQ.Definitions.qelem_fits5 f (1, 1, 1, 1, 1))
(ensures Hacl.Spec.BignumQ.Definitions.as_nat5 f < Prims.pow2 280) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Hacl.Spec.BignumQ.Definitions.qelem5",
"FStar.Pervasives.assert_norm",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"FStar.Mul.op_Star",
"Prims.pow2",
"Prims.unit"
] | [] | true | false | true | false | false | let lemma_as_nat5 f =
| assert_norm (pow2 56 * pow2 56 = pow2 112);
assert_norm (pow2 56 * pow2 112 = pow2 168);
assert_norm (pow2 56 * pow2 168 = pow2 224);
assert_norm (pow2 56 * pow2 224 = pow2 280) | false |
Hacl.Spec.BignumQ.Lemmas.fst | Hacl.Spec.BignumQ.Lemmas.lemma_choose_step | val lemma_choose_step:
bit:uint64{v bit <= 1}
-> x:uint64
-> y:uint64
-> Lemma
(let mask = bit -. u64 1 in
let z = x ^. (mask &. (x ^. y)) in
if v bit = 1 then z == x else z == y) | val lemma_choose_step:
bit:uint64{v bit <= 1}
-> x:uint64
-> y:uint64
-> Lemma
(let mask = bit -. u64 1 in
let z = x ^. (mask &. (x ^. y)) in
if v bit = 1 then z == x else z == y) | let lemma_choose_step bit p1 p2 =
let mask = bit -. u64 1 in
assert (v bit == 0 ==> v mask == pow2 64 - 1);
assert (v bit == 1 ==> v mask == 0);
let dummy = mask &. (p1 ^. p2) in
logand_lemma mask (p1 ^. p2);
assert (v bit == 1 ==> v dummy == 0);
assert (v bit == 0 ==> v dummy == v (p1 ^. p2));
let p1' = p1 ^. dummy in
assert (v dummy == v (if v bit = 1 then u64 0 else (p1 ^. p2)));
logxor_lemma p1 p2 | {
"file_name": "code/ed25519/Hacl.Spec.BignumQ.Lemmas.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 20,
"end_line": 58,
"start_col": 0,
"start_line": 48
} | module Hacl.Spec.BignumQ.Lemmas
open FStar.Tactics.CanonCommSemiring
open FStar.Mul
open Lib.IntTypes
module S = Spec.Ed25519
include Hacl.Spec.BignumQ.Definitions
let feq (#a #b:Type) (f:(a -> b)) (x y:a) :
Lemma (requires x == y) (ensures f x == f y) = ()
let eq_eq2 (#a:eqtype) (x y:a) :
Lemma (requires x = y) (ensures x == y) = ()
val lemma_mul_lt:a:nat -> b:nat -> c:nat -> d:nat ->
Lemma
(requires a < b /\ c < d)
(ensures a * c < b * d)
let lemma_mul_lt a b c d = ()
val lemma_as_nat5: f:qelem5 ->
Lemma
(requires qelem_fits5 f (1, 1, 1, 1, 1))
(ensures as_nat5 f < pow2 280)
let lemma_as_nat5 f =
//let (f0, f1, f2, f3, f4) = f in
//assert (as_nat5 f == v f0 + v f1 * pow56 + v f2 * pow112 + v f3 * pow168 + v f4 * pow224);
assert_norm (pow2 56 * pow2 56 = pow2 112);
assert_norm (pow2 56 * pow2 112 = pow2 168);
assert_norm (pow2 56 * pow2 168 = pow2 224);
assert_norm (pow2 56 * pow2 224 = pow2 280)
val lemma_choose_step:
bit:uint64{v bit <= 1}
-> x:uint64
-> y:uint64
-> Lemma
(let mask = bit -. u64 1 in
let z = x ^. (mask &. (x ^. y)) in
if v bit = 1 then z == x else z == y) | {
"checked_file": "/",
"dependencies": [
"Spec.Ed25519.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.BignumQ.Definitions.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Tactics.CanonCommSemiring.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.BignumQ.Lemmas.fst"
} | [
{
"abbrev": false,
"full_module": "Hacl.Spec.BignumQ.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.Ed25519",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.CanonCommSemiring",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.BignumQ",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.BignumQ",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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 |
bit: Lib.IntTypes.uint64{Lib.IntTypes.v bit <= 1} ->
x: Lib.IntTypes.uint64 ->
y: Lib.IntTypes.uint64
-> FStar.Pervasives.Lemma
(ensures
(let mask = bit -. Lib.IntTypes.u64 1 in
let z = x ^. (mask &. x ^. y) in
(match Lib.IntTypes.v bit = 1 with
| true -> z == x
| _ -> z == y)
<:
Type0)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Lib.IntTypes.uint64",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Lib.IntTypes.v",
"Lib.IntTypes.U64",
"Lib.IntTypes.SEC",
"Lib.IntTypes.logxor_lemma",
"Prims.unit",
"Prims._assert",
"Prims.eq2",
"Lib.IntTypes.range_t",
"Prims.op_Equality",
"Prims.int",
"Lib.IntTypes.u64",
"Prims.bool",
"Lib.IntTypes.op_Hat_Dot",
"Lib.IntTypes.int_t",
"Prims.l_imp",
"Lib.IntTypes.logand_lemma",
"Lib.IntTypes.op_Amp_Dot",
"Prims.op_Subtraction",
"Prims.pow2",
"Lib.IntTypes.op_Subtraction_Dot"
] | [] | false | false | true | false | false | let lemma_choose_step bit p1 p2 =
| let mask = bit -. u64 1 in
assert (v bit == 0 ==> v mask == pow2 64 - 1);
assert (v bit == 1 ==> v mask == 0);
let dummy = mask &. (p1 ^. p2) in
logand_lemma mask (p1 ^. p2);
assert (v bit == 1 ==> v dummy == 0);
assert (v bit == 0 ==> v dummy == v (p1 ^. p2));
let p1' = p1 ^. dummy in
assert (v dummy == v (if v bit = 1 then u64 0 else (p1 ^. p2)));
logxor_lemma p1 p2 | false |
Hacl.Spec.BignumQ.Lemmas.fst | Hacl.Spec.BignumQ.Lemmas.lemma_div248_x5 | val lemma_div248_x5: x5:uint64 ->
Lemma ( pow2 32 * (v x5 % pow2 24) + v x5 / pow2 24 * pow2 56 == v x5 * pow2 32) | val lemma_div248_x5: x5:uint64 ->
Lemma ( pow2 32 * (v x5 % pow2 24) + v x5 / pow2 24 * pow2 56 == v x5 * pow2 32) | let lemma_div248_x5 x5 =
assert_norm (pow2 32 * pow2 24 = pow2 56) | {
"file_name": "code/ed25519/Hacl.Spec.BignumQ.Lemmas.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 43,
"end_line": 165,
"start_col": 0,
"start_line": 164
} | module Hacl.Spec.BignumQ.Lemmas
open FStar.Tactics.CanonCommSemiring
open FStar.Mul
open Lib.IntTypes
module S = Spec.Ed25519
include Hacl.Spec.BignumQ.Definitions
let feq (#a #b:Type) (f:(a -> b)) (x y:a) :
Lemma (requires x == y) (ensures f x == f y) = ()
let eq_eq2 (#a:eqtype) (x y:a) :
Lemma (requires x = y) (ensures x == y) = ()
val lemma_mul_lt:a:nat -> b:nat -> c:nat -> d:nat ->
Lemma
(requires a < b /\ c < d)
(ensures a * c < b * d)
let lemma_mul_lt a b c d = ()
val lemma_as_nat5: f:qelem5 ->
Lemma
(requires qelem_fits5 f (1, 1, 1, 1, 1))
(ensures as_nat5 f < pow2 280)
let lemma_as_nat5 f =
//let (f0, f1, f2, f3, f4) = f in
//assert (as_nat5 f == v f0 + v f1 * pow56 + v f2 * pow112 + v f3 * pow168 + v f4 * pow224);
assert_norm (pow2 56 * pow2 56 = pow2 112);
assert_norm (pow2 56 * pow2 112 = pow2 168);
assert_norm (pow2 56 * pow2 168 = pow2 224);
assert_norm (pow2 56 * pow2 224 = pow2 280)
val lemma_choose_step:
bit:uint64{v bit <= 1}
-> x:uint64
-> y:uint64
-> Lemma
(let mask = bit -. u64 1 in
let z = x ^. (mask &. (x ^. y)) in
if v bit = 1 then z == x else z == y)
let lemma_choose_step bit p1 p2 =
let mask = bit -. u64 1 in
assert (v bit == 0 ==> v mask == pow2 64 - 1);
assert (v bit == 1 ==> v mask == 0);
let dummy = mask &. (p1 ^. p2) in
logand_lemma mask (p1 ^. p2);
assert (v bit == 1 ==> v dummy == 0);
assert (v bit == 0 ==> v dummy == v (p1 ^. p2));
let p1' = p1 ^. dummy in
assert (v dummy == v (if v bit = 1 then u64 0 else (p1 ^. p2)));
logxor_lemma p1 p2
val lemma_subm_conditional:
x0:nat -> x1:nat -> x2:nat -> x3:nat -> x4:nat
-> y0:nat -> y1:nat -> y2:nat -> y3:nat -> y4:nat
-> b0:nat -> b1:nat -> b2:nat -> b3:nat -> b4:nat ->
Lemma (
x0 - y0 + b0 * pow2 56 +
(x1 - y1 - b0 + b1 * pow2 56) * pow2 56 +
(x2 - y2 - b1 + b2 * pow2 56) * pow2 112 +
(x3 - y3 - b2 + b3 * pow2 56) * pow2 168 +
(x4 - y4 - b3 + b4 * pow2 56) * pow2 224 ==
(x0 + x1 * pow2 56 + x2 * pow2 112 + x3 * pow2 168 + x4 * pow2 224) -
(y0 + y1 * pow2 56 + y2 * pow2 112 + y3 * pow2 168 + y4 * pow2 224) + b4 * pow2 280)
let lemma_subm_conditional x0 x1 x2 x3 x4 y0 y1 y2 y3 y4 b0 b1 b2 b3 b4 =
assert_norm (pow2 56 * pow2 56 = pow2 112);
assert_norm (pow2 56 * pow2 112 = pow2 168);
assert_norm (pow2 56 * pow2 168 = pow2 224);
assert_norm (pow2 56 * pow2 224 = pow2 280);
assert (
x0 - y0 + b0 * pow2 56 +
(x1 - y1 - b0 + b1 * pow2 56) * pow2 56 +
(x2 - y2 - b1 + b2 * pow2 56) * pow2 112 +
(x3 - y3 - b2 + b3 * pow2 56) * pow2 168 +
(x4 - y4 - b3 + b4 * pow2 56) * pow2 224 ==
(x0 + x1 * pow2 56 + x2 * pow2 112 + x3 * pow2 168 + x4 * pow2 224) -
(y0 + y1 * pow2 56 + y2 * pow2 112 + y3 * pow2 168 + y4 * pow2 224) + b4 * pow2 280)
by (int_semiring ());
()
val lemma_div224: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1))
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
wide_as_nat5 x / pow2 224 ==
v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280))
#push-options "--z3rlimit 50"
let lemma_div224 x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert
(wide_as_nat5 x ==
v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168 + v x4 * pow2 224 +
v x5 * pow2 280 + v x6 * pow2 336 + v x7 * pow2 392 + v x8 * pow2 448 + v x9 * pow2 504);
assert_norm (pow2 56 * pow2 224 == pow2 280);
assert_norm (pow2 112 * pow2 224 == pow2 336);
assert_norm (pow2 168 * pow2 224 == pow2 392);
assert_norm (pow2 224 * pow2 224 == pow2 448);
assert_norm (pow2 280 * pow2 224 == pow2 504);
calc (==) {
wide_as_nat5 x / pow2 224;
(==) { }
(v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168 +
(v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280) * pow2 224) / pow2 224;
(==) {
FStar.Math.Lemmas.lemma_div_plus
(v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168)
(v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280) (pow2 224) }
(v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168) / pow2 224 +
v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280;
(==) { FStar.Math.Lemmas.small_division_lemma_1 (v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168) (pow2 224) }
v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280;
}
#pop-options
val lemma_div248_aux: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 512)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
wide_as_nat5 x / pow2 248 ==
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256))
open FStar.Tactics.CanonCommSemiring
#push-options "--z3cliopt smt.arith.nl=false"
let lemma_div248_aux x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert_norm (pow2 248 == pow2 224 * pow2 24);
assert_norm (pow2 56 == pow2 32 * pow2 24);
assert_norm (pow2 112 == pow2 88 * pow2 24);
assert_norm (pow2 168 == pow2 144 * pow2 24);
assert_norm (pow2 224 == pow2 200 * pow2 24);
assert_norm (pow2 280 == pow2 256 * pow2 24);
assert_norm (0 < pow2 24);
calc (==) {
wide_as_nat5 x / pow2 248;
(==) { FStar.Math.Lemmas.division_multiplication_lemma (wide_as_nat5 x) (pow2 224) (pow2 24) }
(wide_as_nat5 x / pow2 224) / pow2 24;
(==) { lemma_div224 x }
(v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280) / pow2 24;
(==) { _ by (Tactics.mapply (`feq #int #int (fun x -> x / pow2 24)); int_semiring ()) } (v x4 + (v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256) * pow2 24) / pow2 24;
(==) { FStar.Math.Lemmas.lemma_div_plus (v x4) (v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256) (pow2 24) }
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256;
}
#pop-options
val lemma_div248_x5: x5:uint64 -> | {
"checked_file": "/",
"dependencies": [
"Spec.Ed25519.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.BignumQ.Definitions.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Tactics.CanonCommSemiring.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.BignumQ.Lemmas.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.CanonCommSemiring",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.BignumQ.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.Ed25519",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.CanonCommSemiring",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.BignumQ",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.BignumQ",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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 | x5: Lib.IntTypes.uint64
-> FStar.Pervasives.Lemma
(ensures
Prims.pow2 32 * (Lib.IntTypes.v x5 % Prims.pow2 24) +
(Lib.IntTypes.v x5 / Prims.pow2 24) * Prims.pow2 56 ==
Lib.IntTypes.v x5 * Prims.pow2 32) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Lib.IntTypes.uint64",
"FStar.Pervasives.assert_norm",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"FStar.Mul.op_Star",
"Prims.pow2",
"Prims.unit"
] | [] | true | false | true | false | false | let lemma_div248_x5 x5 =
| assert_norm (pow2 32 * pow2 24 = pow2 56) | false |
Steel.ST.SeqMatch.fst | Steel.ST.SeqMatch.seq_seq_match_upd | val seq_seq_match_upd
(#opened: _)
(#t1 #t2: Type)
(p: (t1 -> t2 -> vprop))
(s1: Seq.seq t1)
(s2: Seq.seq t2)
(i j: nat)
(k: nat{i <= j /\ j < k})
(x1: t1)
(x2: t2)
: STGhostT (squash (j < Seq.length s1 /\ j < Seq.length s2))
opened
((seq_seq_match p s1 s2 i k) `star` (p x1 x2))
(fun _ -> seq_seq_match p (Seq.upd s1 j x1) (Seq.upd s2 j x2) i k) | val seq_seq_match_upd
(#opened: _)
(#t1 #t2: Type)
(p: (t1 -> t2 -> vprop))
(s1: Seq.seq t1)
(s2: Seq.seq t2)
(i j: nat)
(k: nat{i <= j /\ j < k})
(x1: t1)
(x2: t2)
: STGhostT (squash (j < Seq.length s1 /\ j < Seq.length s2))
opened
((seq_seq_match p s1 s2 i k) `star` (p x1 x2))
(fun _ -> seq_seq_match p (Seq.upd s1 j x1) (Seq.upd s2 j x2) i k) | let seq_seq_match_upd
(#opened: _)
(#t1 #t2: Type)
(p: t1 -> t2 -> vprop)
(s1: Seq.seq t1)
(s2: Seq.seq t2)
(i j: nat)
(k: nat {
i <= j /\ j < k
})
(x1: t1)
(x2: t2)
: STGhostT (squash (j < Seq.length s1 /\ j < Seq.length s2)) opened
(seq_seq_match p s1 s2 i k `star` p x1 x2)
(fun _ ->
seq_seq_match p (Seq.upd s1 j x1) (Seq.upd s2 j x2) i k
)
= seq_seq_match_length p s1 s2 i k;
on_range_get
(seq_seq_match_item p s1 s2)
i j (j + 1) k;
let res : squash (j < Seq.length s1 /\ j < Seq.length s2) = () in
drop (seq_seq_match_item p s1 s2 j);
rewrite
(p x1 x2)
(seq_seq_match_item p (Seq.upd s1 j x1) (Seq.upd s2 j x2) j);
seq_seq_match_weaken
p p (fun _ _ -> noop ())
s1 (Seq.upd s1 j x1)
s2 (Seq.upd s2 j x2)
i j;
seq_seq_match_weaken
p p (fun _ _ -> noop ())
s1 (Seq.upd s1 j x1)
s2 (Seq.upd s2 j x2)
(j + 1) k;
on_range_put
(seq_seq_match_item p (Seq.upd s1 j x1) (Seq.upd s2 j x2))
i j j (j + 1) k;
res | {
"file_name": "lib/steel/Steel.ST.SeqMatch.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 5,
"end_line": 727,
"start_col": 0,
"start_line": 688
} | module Steel.ST.SeqMatch
include Steel.ST.OnRange
open Steel.ST.GenElim
module Seq = FStar.Seq
module SZ = FStar.SizeT
(* `seq_list_match` describes how to match a sequence of low-level
values (the low-level contents of an array) with a list of high-level
values. `seq_list_match` is carefully designed to be usable within
(mutually) recursive definitions of matching functions on the type of
high-level values. *)
[@@__reduce__]
let seq_list_match_nil0
(#t: Type)
(c: Seq.seq t)
: Tot vprop
= pure (c `Seq.equal` Seq.empty)
[@@__reduce__]
let seq_list_match_cons0
(#t #t': Type)
(c: Seq.seq t)
(l: list t' { Cons? l })
(item_match: (t -> (v': t' { v' << l }) -> vprop))
(seq_list_match: (Seq.seq t -> (v': list t') -> (raw_data_item_match: (t -> (v'': t' { v'' << v' }) -> vprop) { v' << l }) ->
vprop))
: Tot vprop
= exists_ (fun (c1: t) -> exists_ (fun (c2: Seq.seq t) ->
item_match c1 (List.Tot.hd l) `star`
seq_list_match c2 (List.Tot.tl l) item_match `star`
pure (c `Seq.equal` Seq.cons c1 c2)
))
let rec seq_list_match
(#t #t': Type)
(c: Seq.seq t)
(v: list t')
(item_match: (t -> (v': t' { v' << v }) -> vprop))
: Tot vprop
(decreases v)
= if Nil? v
then seq_list_match_nil0 c
else seq_list_match_cons0 c v item_match seq_list_match
let seq_list_match_cons_eq
(#t #t': Type)
(c: Seq.seq t)
(v: list t')
(item_match: (t -> (v': t' { v' << v }) -> vprop))
: Lemma
(requires (Cons? v))
(ensures (
seq_list_match c v item_match ==
seq_list_match_cons0 c v item_match seq_list_match
))
= let a :: q = v in
assert_norm (seq_list_match c (a :: q) item_match ==
seq_list_match_cons0 c (a :: q) item_match seq_list_match
)
let seq_list_match_nil
(#opened: _)
(#t #t': Type)
(c: Seq.seq t)
(v: list t')
(item_match: (t -> (v': t' { v' << v }) -> vprop))
: STGhost unit opened
emp
(fun _ -> seq_list_match c v item_match)
(c `Seq.equal` Seq.empty /\
Nil? v)
(fun _ -> True)
= noop ();
rewrite
(seq_list_match_nil0 c)
(seq_list_match c v item_match)
let list_cons_precedes
(#t: Type)
(a: t)
(q: list t)
: Lemma
((a << a :: q) /\ (q << a :: q))
[SMTPat (a :: q)]
= assert (List.Tot.hd (a :: q) << (a :: q));
assert (List.Tot.tl (a :: q) << (a :: q))
let seq_list_match_cons_intro
(#opened: _)
(#t #t': Type)
(a: t)
(a' : t')
(c: Seq.seq t)
(v: list t')
(item_match: (t -> (v': t' { v' << a' :: v }) -> vprop))
: STGhostT unit opened
(item_match a a' `star` seq_list_match c v item_match)
(fun _ -> seq_list_match (Seq.cons a c) (a' :: v) item_match)
= seq_list_match_cons_eq (Seq.cons a c) (a' :: v) item_match;
noop ();
rewrite
(seq_list_match_cons0 (Seq.cons a c) (a' :: v) item_match seq_list_match)
(seq_list_match (Seq.cons a c) (a' :: v) item_match)
let seq_list_match_cons_elim
(#opened: _)
(#t #t': Type)
(c: Seq.seq t)
(v: list t' { Cons? v \/ Seq.length c > 0 })
(item_match: (t -> (v': t' { v' << v }) -> vprop))
: STGhostT (squash (Cons? v /\ Seq.length c > 0)) opened
(seq_list_match c v item_match)
(fun _ -> item_match (Seq.head c) (List.Tot.hd v) `star`
seq_list_match (Seq.tail c) (List.Tot.tl v) item_match)
= if Nil? v
then begin
rewrite
(seq_list_match c v item_match)
(seq_list_match_nil0 c);
let _ = gen_elim () in
assert False;
rewrite // by contradiction
emp
(item_match (Seq.head c) (List.Tot.hd v) `star`
seq_list_match (Seq.tail c) (List.Tot.tl v) item_match)
end else begin
seq_list_match_cons_eq c v item_match;
noop ();
rewrite
(seq_list_match c v item_match)
(seq_list_match_cons0 c v item_match seq_list_match);
let _ = gen_elim () in
let prf : squash (Cons? v /\ Seq.length c > 0) = () in
let c1 = vpattern (fun c1 -> item_match c1 (List.Tot.hd v)) in
let c2 = vpattern (fun c2 -> seq_list_match c2 (List.Tot.tl v) item_match) in
Seq.lemma_cons_inj c1 (Seq.head c) c2 (Seq.tail c);
vpattern_rewrite (fun c1 -> item_match c1 (List.Tot.hd v)) (Seq.head c);
vpattern_rewrite (fun c2 -> seq_list_match c2 (List.Tot.tl v) item_match) (Seq.tail c);
prf
end
// this one cannot be proven with seq_seq_match because of the << refinement in the type of item_match
let rec seq_list_match_weaken
(#opened: _)
(#t #t': Type)
(c: Seq.seq t)
(v: list t')
(item_match1 item_match2: (t -> (v': t' { v' << v }) -> vprop))
(prf: (
(#opened: _) ->
(c': t) ->
(v': t' { v' << v }) ->
STGhostT unit opened
(item_match1 c' v')
(fun _ -> item_match2 c' v')
))
: STGhostT unit opened
(seq_list_match c v item_match1)
(fun _ -> seq_list_match c v item_match2)
(decreases v)
= if Nil? v
then
rewrite (seq_list_match c v item_match1) (seq_list_match c v item_match2)
else begin
let _ : squash (Cons? v) = () in
seq_list_match_cons_eq c v item_match1;
seq_list_match_cons_eq c v item_match2;
rewrite
(seq_list_match c v item_match1)
(seq_list_match_cons0 c v item_match1 seq_list_match);
let _ = gen_elim () in
prf _ _;
seq_list_match_weaken _ (List.Tot.tl v) item_match1 item_match2 prf;
rewrite
(seq_list_match_cons0 c v item_match2 seq_list_match)
(seq_list_match c v item_match2)
end
(* `seq_seq_match` describes how to match a sequence of low-level
values (the low-level contents of an array) with a sequence of high-level
values. Contrary to `seq_list_match`, `seq_seq_match` is not meant to be usable within
(mutually) recursive definitions of matching functions on the type of
high-level values, because no lemma ensures that `Seq.index s i << s` *)
let seq_seq_match_item
(#t1 #t2: Type)
(p: t1 -> t2 -> vprop)
(c: Seq.seq t1)
(l: Seq.seq t2)
(i: nat)
: Tot vprop
= if i < Seq.length c && i < Seq.length l
then
p (Seq.index c i) (Seq.index l i)
else
pure (squash False)
let seq_seq_match_item_tail
(#t1 #t2: Type)
(p: t1 -> t2 -> vprop)
(c: Seq.seq t1)
(l: Seq.seq t2)
(delta: nat)
(i: nat)
: Lemma
(requires (
i + delta <= Seq.length c /\
i + delta <= Seq.length l
))
(ensures (
seq_seq_match_item p (Seq.slice c delta (Seq.length c)) (Seq.slice l delta (Seq.length l)) i ==
seq_seq_match_item p c l (i + delta)
))
= ()
[@@__reduce__]
let seq_seq_match
(#t1 #t2: Type)
(p: t1 -> t2 -> vprop)
(c: Seq.seq t1)
(l: Seq.seq t2)
(i j: nat)
: Tot vprop
= on_range (seq_seq_match_item p c l) i j
let seq_seq_match_length
(#opened: _)
(#t1 #t2: Type)
(p: t1 -> t2 -> vprop)
(s1: Seq.seq t1)
(s2: Seq.seq t2)
(i j: nat)
: STGhost unit opened
(seq_seq_match p s1 s2 i j)
(fun _ -> seq_seq_match p s1 s2 i j)
True
(fun _ -> i <= j /\ (i == j \/ (j <= Seq.length s1 /\ j <= Seq.length s2)))
= on_range_le (seq_seq_match_item p s1 s2) i j;
if i = j
then noop ()
else begin
let j' = j - 1 in
if j' < Seq.length s1 && j' < Seq.length s2
then noop ()
else begin
on_range_unsnoc
(seq_seq_match_item p s1 s2)
i j' j;
rewrite
(seq_seq_match_item p _ _ _)
(pure (squash False));
let _ = gen_elim () in
rewrite
(seq_seq_match p s1 s2 i j')
(seq_seq_match p s1 s2 i j) // by contradiction
end
end
let seq_seq_match_weaken
(#opened: _)
(#t1 #t2: Type)
(p p': t1 -> t2 -> vprop)
(w: ((x1: t1) -> (x2: t2) -> STGhostT unit opened
(p x1 x2) (fun _ -> p' x1 x2)
))
(c1 c1': Seq.seq t1)
(c2 c2': Seq.seq t2)
(i j: nat)
: STGhost unit opened
(seq_seq_match p c1 c2 i j)
(fun _ -> seq_seq_match p' c1' c2' i j)
(i <= j /\ (i == j \/ (
j <= Seq.length c1 /\ j <= Seq.length c2 /\
j <= Seq.length c1' /\ j <= Seq.length c2' /\
Seq.slice c1 i j `Seq.equal` Seq.slice c1' i j /\
Seq.slice c2 i j `Seq.equal` Seq.slice c2' i j
)))
(fun _ -> True)
=
on_range_weaken
(seq_seq_match_item p c1 c2)
(seq_seq_match_item p' c1' c2')
i j
(fun k ->
rewrite (seq_seq_match_item p c1 c2 k) (p (Seq.index (Seq.slice c1 i j) (k - i)) (Seq.index (Seq.slice c2 i j) (k - i)));
w _ _;
rewrite (p' _ _) (seq_seq_match_item p' c1' c2' k)
)
let seq_seq_match_weaken_with_implies
(#opened: _)
(#t1 #t2: Type)
(p: t1 -> t2 -> vprop)
(c1 c1': Seq.seq t1)
(c2 c2': Seq.seq t2)
(i j: nat)
: STGhost unit opened
(seq_seq_match p c1 c2 i j)
(fun _ -> seq_seq_match p c1' c2' i j `star`
(seq_seq_match p c1' c2' i j `implies_` seq_seq_match p c1 c2 i j)
)
(i <= j /\ (i == j \/ (
j <= Seq.length c1 /\ j <= Seq.length c2 /\
j <= Seq.length c1' /\ j <= Seq.length c2' /\
Seq.slice c1 i j `Seq.equal` Seq.slice c1' i j /\
Seq.slice c2 i j `Seq.equal` Seq.slice c2' i j
)))
(fun _ -> True)
= seq_seq_match_weaken
p p (fun _ _ -> noop ())
c1 c1'
c2 c2'
i j;
intro_implies
(seq_seq_match p c1' c2' i j)
(seq_seq_match p c1 c2 i j)
emp
(fun _ ->
seq_seq_match_weaken
p p (fun _ _ -> noop ())
c1' c1
c2' c2
i j
)
(* Going between `seq_list_match` and `seq_seq_match` *)
let seq_seq_match_tail_elim
(#t1 #t2: Type)
(#opened: _)
(p: t1 -> t2 -> vprop)
(c: Seq.seq t1)
(l: Seq.seq (t2))
(delta: nat {
delta <= Seq.length c /\
delta <= Seq.length l
})
(i j: nat)
: STGhostT unit opened
(seq_seq_match p (Seq.slice c delta (Seq.length c)) (Seq.slice l delta (Seq.length l)) i j)
(fun _ -> seq_seq_match p c l (i + delta) (j + delta))
= on_range_le (seq_seq_match_item p _ _) _ _;
on_range_weaken_and_shift
(seq_seq_match_item p (Seq.slice c delta (Seq.length c)) (Seq.slice l delta (Seq.length l)))
(seq_seq_match_item p c l)
delta
i j
(fun k ->
if k < Seq.length c - delta && k < Seq.length l - delta
then begin
seq_seq_match_item_tail p c l delta k;
rewrite
(seq_seq_match_item p (Seq.slice c delta (Seq.length c)) (Seq.slice l delta (Seq.length l)) k)
(seq_seq_match_item p c l (k + delta))
end else begin
rewrite
(seq_seq_match_item p (Seq.slice c delta (Seq.length c)) (Seq.slice l delta (Seq.length l)) k)
(pure (squash False));
let _ = gen_elim () in
rewrite
emp
(seq_seq_match_item p c l (k + delta)) // by contradiction
end
)
(i + delta) (j + delta)
let seq_seq_match_tail_intro
(#t1 #t2: Type)
(#opened: _)
(p: t1 -> t2 -> vprop)
(c: Seq.seq t1)
(l: Seq.seq t2)
(delta: nat {
delta <= Seq.length c /\
delta <= Seq.length l
})
(i: nat {
delta <= i
})
(j: nat)
: STGhostT (squash (i <= j)) opened
(seq_seq_match p c l i j)
(fun _ -> seq_seq_match p (Seq.slice c delta (Seq.length c)) (Seq.slice l delta (Seq.length l)) (i - delta) (j - delta))
= on_range_le (seq_seq_match_item p _ _) _ _;
on_range_weaken_and_shift
(seq_seq_match_item p c l)
(seq_seq_match_item p (Seq.slice c delta (Seq.length c)) (Seq.slice l delta (Seq.length l)))
(0 - delta)
i j
(fun k ->
if k < Seq.length c && k < Seq.length l
then begin
seq_seq_match_item_tail p c l delta (k - delta);
rewrite
(seq_seq_match_item p c l k)
(seq_seq_match_item p (Seq.slice c delta (Seq.length c)) (Seq.slice l delta (Seq.length l)) (k + (0 - delta)))
end else begin
rewrite
(seq_seq_match_item p c l k)
(pure (squash False));
let _ = gen_elim () in
rewrite
emp
(seq_seq_match_item p (Seq.slice c delta (Seq.length c)) (Seq.slice l delta (Seq.length l)) (k + (0 - delta))) // by contradiction
end
)
(i - delta) (j - delta)
let rec seq_seq_match_seq_list_match
(#opened: _)
(#t1 #t2: Type)
(p: t1 -> t2 -> vprop)
(c: Seq.seq t1)
(l: list t2)
: STGhost unit opened
(seq_seq_match p c (Seq.seq_of_list l) 0 (List.Tot.length l))
(fun _ -> seq_list_match c l p)
(Seq.length c == List.Tot.length l)
(fun _ -> True)
(decreases l)
= match l with
| [] ->
drop (seq_seq_match p _ _ _ _);
rewrite
(seq_list_match_nil0 c)
(seq_list_match c l p)
| a :: q ->
Seq.lemma_seq_of_list_induction (a :: q);
seq_list_match_cons_eq c l p;
on_range_uncons
(seq_seq_match_item p _ _)
_ 1 _;
rewrite
(seq_seq_match_item p _ _ _)
(p (Seq.head c) (List.Tot.hd l));
let _ = seq_seq_match_tail_intro
p _ _ 1 _ _
in
rewrite
(seq_seq_match p _ _ _ _)
(seq_seq_match p (Seq.tail c) (Seq.seq_of_list (List.Tot.tl l)) 0 (List.Tot.length (List.Tot.tl l)));
seq_seq_match_seq_list_match p _ (List.Tot.tl l);
rewrite
(seq_list_match_cons0 c l p seq_list_match)
(seq_list_match c l p)
let rec seq_list_match_seq_seq_match
(#opened: _)
(#t1 #t2: Type)
(p: t1 -> t2 -> vprop)
(c: Seq.seq t1)
(l: list t2)
: STGhost unit opened
(seq_list_match c l p)
(fun _ -> seq_seq_match p c (Seq.seq_of_list l) 0 (List.Tot.length l))
True
(fun _ -> Seq.length c == List.Tot.length l)
(decreases l)
= match l with
| [] ->
rewrite
(seq_list_match c l p)
(seq_list_match_nil0 c);
let _ = gen_elim () in
on_range_empty
(seq_seq_match_item p c (Seq.seq_of_list l))
0
(List.Tot.length l)
| a :: q ->
let _l_nonempty : squash (Cons? l) = () in
Seq.lemma_seq_of_list_induction (a :: q);
seq_list_match_cons_eq c l p;
noop ();
rewrite
(seq_list_match c l p)
(seq_list_match_cons0 c l p seq_list_match);
let _ = gen_elim () in
let a' = vpattern (fun a' -> p a' _) in
let c' = vpattern (fun c' -> seq_list_match c' _ _) in
Seq.lemma_cons_inj (Seq.head c) a' (Seq.tail c) c';
assert (a' == Seq.head c);
assert (c' == Seq.tail c);
noop ();
seq_list_match_seq_seq_match p _ _;
rewrite
(seq_seq_match p _ _ _ _)
(seq_seq_match p (Seq.slice c 1 (Seq.length c)) (Seq.slice (Seq.seq_of_list l) 1 (Seq.length (Seq.seq_of_list l))) 0 (List.Tot.length (List.Tot.tl l)));
let _ = seq_seq_match_tail_elim
p c (Seq.seq_of_list l) 1 0 (List.Tot.length (List.Tot.tl l))
in
rewrite
(seq_seq_match p _ _ _ _)
(seq_seq_match p c (Seq.seq_of_list l) 1 (List.Tot.length l));
rewrite
(p _ _)
(seq_seq_match_item p c (Seq.seq_of_list l) 0);
on_range_cons
(seq_seq_match_item p _ _)
0 1 (List.Tot.length l)
let seq_seq_match_seq_list_match_with_implies
(#opened: _)
(#t1 #t2: Type)
(p: t1 -> t2 -> vprop)
(c: Seq.seq t1)
(l: list t2)
: STGhost unit opened
(seq_seq_match p c (Seq.seq_of_list l) 0 (List.Tot.length l))
(fun _ -> seq_list_match c l p `star` (seq_list_match c l p `implies_` seq_seq_match p c (Seq.seq_of_list l) 0 (List.Tot.length l)))
(Seq.length c == List.Tot.length l)
(fun _ -> True)
= seq_seq_match_seq_list_match p c l;
intro_implies
(seq_list_match c l p)
(seq_seq_match p c (Seq.seq_of_list l) 0 (List.Tot.length l))
emp
(fun _ -> seq_list_match_seq_seq_match p c l)
let seq_list_match_seq_seq_match_with_implies
(#opened: _)
(#t1 #t2: Type)
(p: t1 -> t2 -> vprop)
(c: Seq.seq t1)
(l: list t2)
: STGhost unit opened
(seq_list_match c l p)
(fun _ -> seq_seq_match p c (Seq.seq_of_list l) 0 (List.Tot.length l) `star` (seq_seq_match p c (Seq.seq_of_list l) 0 (List.Tot.length l) `implies_` seq_list_match c l p))
True
(fun _ -> Seq.length c == List.Tot.length l)
= seq_list_match_seq_seq_match p c l;
intro_implies
(seq_seq_match p c (Seq.seq_of_list l) 0 (List.Tot.length l))
(seq_list_match c l p)
emp
(fun _ -> seq_seq_match_seq_list_match p c l)
let seq_list_match_length
(#opened: _)
(#t1 #t2: Type)
(p: t1 -> t2 -> vprop)
(c: Seq.seq t1)
(l: list t2)
: STGhost unit opened
(seq_list_match c l p)
(fun _ -> seq_list_match c l p)
True
(fun _ -> Seq.length c == List.Tot.length l)
= seq_list_match_seq_seq_match_with_implies p c l;
seq_seq_match_length p _ _ _ _;
elim_implies
(seq_seq_match p _ _ _ _)
(seq_list_match c l p)
let seq_list_match_index
(#opened: _)
(#t1 #t2: Type)
(p: t1 -> t2 -> vprop)
(s1: Seq.seq t1)
(s2: list t2)
(i: nat)
: STGhost (squash (i < Seq.length s1 /\ List.Tot.length s2 == Seq.length s1)) opened
(seq_list_match s1 s2 p)
(fun _ ->
p (Seq.index s1 i) (List.Tot.index s2 i) `star`
(p (Seq.index s1 i) (List.Tot.index s2 i) `implies_`
seq_list_match s1 s2 p)
)
(i < Seq.length s1 \/ i < List.Tot.length s2)
(fun _ -> True)
= seq_list_match_seq_seq_match_with_implies p s1 s2;
let res : squash (i < Seq.length s1 /\ List.Tot.length s2 == Seq.length s1) = () in
on_range_focus (seq_seq_match_item p s1 (Seq.seq_of_list s2)) 0 i (List.Tot.length s2);
rewrite_with_implies
(seq_seq_match_item p _ _ _)
(p (Seq.index s1 i) (List.Tot.index s2 i));
implies_trans
(p (Seq.index s1 i) (List.Tot.index s2 i))
(seq_seq_match_item p _ _ _)
(seq_seq_match p s1 (Seq.seq_of_list s2) 0 (List.Tot.length s2));
implies_trans
(p (Seq.index s1 i) (List.Tot.index s2 i))
(seq_seq_match p s1 (Seq.seq_of_list s2) 0 (List.Tot.length s2))
(seq_list_match s1 s2 p);
res
(* Random array access
Since `seq_list_match` is defined recursively on the list of
high-level values, it is used naturally left-to-right. By contrast,
in practice, an application may populate an array in a different
order, or even out-of-order. `seq_seq_match` supports that scenario
better, as we show below.
*)
let seq_map (#t1 #t2: Type) (f: t1 -> t2) (s: Seq.seq t1) : Tot (Seq.seq t2) =
Seq.init (Seq.length s) (fun i -> f (Seq.index s i))
let item_match_option
(#t1 #t2: Type)
(p: t1 -> t2 -> vprop)
(x1: t1)
(x2: option t2)
: Tot vprop
= match x2 with
| None -> emp
| Some x2' -> p x1 x2'
let seq_seq_match_item_match_option_elim
(#opened: _)
(#t1 #t2: Type)
(p: t1 -> t2 -> vprop)
(s1: Seq.seq t1)
(s2: Seq.seq t2)
(i j: nat)
: STGhostT unit opened
(seq_seq_match (item_match_option p) s1 (seq_map Some s2) i j)
(fun _ -> seq_seq_match p s1 s2 i j)
= on_range_weaken
(seq_seq_match_item (item_match_option p) s1 (seq_map Some s2))
(seq_seq_match_item p s1 s2)
i j
(fun k ->
rewrite
(seq_seq_match_item (item_match_option p) s1 (seq_map Some s2) k)
(seq_seq_match_item p s1 s2 k)
)
let seq_seq_match_item_match_option_intro
(#opened: _)
(#t1 #t2: Type)
(p: t1 -> t2 -> vprop)
(s1: Seq.seq t1)
(s2: Seq.seq t2)
(i j: nat)
: STGhostT unit opened
(seq_seq_match p s1 s2 i j)
(fun _ -> seq_seq_match (item_match_option p) s1 (seq_map Some s2) i j)
= on_range_weaken
(seq_seq_match_item p s1 s2)
(seq_seq_match_item (item_match_option p) s1 (seq_map Some s2))
i j
(fun k ->
rewrite
(seq_seq_match_item p s1 s2 k)
(seq_seq_match_item (item_match_option p) s1 (seq_map Some s2) k)
)
let rec seq_seq_match_item_match_option_init
(#opened: _)
(#t1 #t2: Type)
(p: t1 -> t2 -> vprop)
(s: Seq.seq t1)
: STGhostT unit opened
emp
(fun _ -> seq_seq_match (item_match_option p) s (Seq.create (Seq.length s) None) 0 (Seq.length s))
(decreases (Seq.length s))
= if Seq.length s = 0
then
on_range_empty (seq_seq_match_item (item_match_option p) s (Seq.create (Seq.length s) None)) 0 (Seq.length s)
else begin
seq_seq_match_item_match_option_init p (Seq.tail s);
on_range_weaken_and_shift
(seq_seq_match_item (item_match_option p) (Seq.tail s) (Seq.create (Seq.length (Seq.tail s)) None))
(seq_seq_match_item (item_match_option p) s (Seq.create (Seq.length s) None))
1
0
(Seq.length (Seq.tail s))
(fun k ->
rewrite
(seq_seq_match_item (item_match_option p) (Seq.tail s) (Seq.create (Seq.length (Seq.tail s)) None) k)
(seq_seq_match_item (item_match_option p) s (Seq.create (Seq.length s) None) (k + 1))
)
1
(Seq.length s);
rewrite
emp
(seq_seq_match_item (item_match_option p) s (Seq.create (Seq.length s) None) 0);
on_range_cons
(seq_seq_match_item (item_match_option p) s (Seq.create (Seq.length s) None))
0
1
(Seq.length s)
end | {
"checked_file": "/",
"dependencies": [
"Steel.ST.OnRange.fsti.checked",
"Steel.ST.GenElim.fsti.checked",
"prims.fst.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "Steel.ST.SeqMatch.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "SZ"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "Steel.ST.GenElim",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.OnRange",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
p: (_: t1 -> _: t2 -> Steel.Effect.Common.vprop) ->
s1: FStar.Seq.Base.seq t1 ->
s2: FStar.Seq.Base.seq t2 ->
i: Prims.nat ->
j: Prims.nat ->
k: Prims.nat{i <= j /\ j < k} ->
x1: t1 ->
x2: t2
-> Steel.ST.Effect.Ghost.STGhostT
(Prims.squash (j < FStar.Seq.Base.length s1 /\ j < FStar.Seq.Base.length s2)) | Steel.ST.Effect.Ghost.STGhostT | [] | [] | [
"Steel.Memory.inames",
"Steel.Effect.Common.vprop",
"FStar.Seq.Base.seq",
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"Prims.squash",
"FStar.Seq.Base.length",
"Prims.unit",
"Steel.ST.OnRange.on_range_put",
"Steel.ST.SeqMatch.seq_seq_match_item",
"FStar.Seq.Base.upd",
"Prims.op_Addition",
"Steel.ST.SeqMatch.seq_seq_match_weaken",
"Steel.ST.Util.noop",
"Steel.ST.Util.rewrite",
"Steel.ST.Util.drop",
"Steel.ST.OnRange.on_range_get",
"Steel.ST.SeqMatch.seq_seq_match_length",
"Steel.Effect.Common.star",
"Steel.ST.SeqMatch.seq_seq_match"
] | [] | false | true | true | false | false | let seq_seq_match_upd
(#opened: _)
(#t1 #t2: Type)
(p: (t1 -> t2 -> vprop))
(s1: Seq.seq t1)
(s2: Seq.seq t2)
(i j: nat)
(k: nat{i <= j /\ j < k})
(x1: t1)
(x2: t2)
: STGhostT (squash (j < Seq.length s1 /\ j < Seq.length s2))
opened
((seq_seq_match p s1 s2 i k) `star` (p x1 x2))
(fun _ -> seq_seq_match p (Seq.upd s1 j x1) (Seq.upd s2 j x2) i k) =
| seq_seq_match_length p s1 s2 i k;
on_range_get (seq_seq_match_item p s1 s2) i j (j + 1) k;
let res:squash (j < Seq.length s1 /\ j < Seq.length s2) = () in
drop (seq_seq_match_item p s1 s2 j);
rewrite (p x1 x2) (seq_seq_match_item p (Seq.upd s1 j x1) (Seq.upd s2 j x2) j);
seq_seq_match_weaken p p (fun _ _ -> noop ()) s1 (Seq.upd s1 j x1) s2 (Seq.upd s2 j x2) i j;
seq_seq_match_weaken p p (fun _ _ -> noop ()) s1 (Seq.upd s1 j x1) s2 (Seq.upd s2 j x2) (j + 1) k;
on_range_put (seq_seq_match_item p (Seq.upd s1 j x1) (Seq.upd s2 j x2)) i j j (j + 1) k;
res | false |
Steel.ST.C.Types.Base.fsti | Steel.ST.C.Types.Base.void_ptr_of_ref | val void_ptr_of_ref (#t: Type) (#opened: _) (#td: typedef t) (#v: Ghost.erased t) (x: ref td)
: STAtomicBase void_ptr
false
opened
Unobservable
(pts_to x v)
(fun _ -> pts_to x v)
True
(fun y -> y == ghost_void_ptr_of_ptr_gen x) | val void_ptr_of_ref (#t: Type) (#opened: _) (#td: typedef t) (#v: Ghost.erased t) (x: ref td)
: STAtomicBase void_ptr
false
opened
Unobservable
(pts_to x v)
(fun _ -> pts_to x v)
True
(fun y -> y == ghost_void_ptr_of_ptr_gen x) | let void_ptr_of_ref (#t: Type) (#opened: _) (#td: typedef t) (#v: Ghost.erased t) (x: ref td) : STAtomicBase void_ptr false opened Unobservable
(pts_to x v)
(fun _ -> pts_to x v)
True
(fun y -> y == ghost_void_ptr_of_ptr_gen x)
= rewrite (pts_to x v) (pts_to_or_null x v);
let res = void_ptr_of_ptr x in
rewrite (pts_to_or_null x v) (pts_to x v);
return res | {
"file_name": "lib/steel/c/Steel.ST.C.Types.Base.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 12,
"end_line": 166,
"start_col": 0,
"start_line": 158
} | module Steel.ST.C.Types.Base
open Steel.ST.Util
module P = Steel.FractionalPermission
/// Helper to compose two permissions into one
val prod_perm (p1 p2: P.perm) : Pure P.perm
(requires True)
(ensures (fun p ->
((p1 `P.lesser_equal_perm` P.full_perm /\ p2 `P.lesser_equal_perm` P.full_perm) ==>
p `P.lesser_equal_perm` P.full_perm) /\
p.v == (let open FStar.Real in p1.v *. p2.v)
))
[@@noextract_to "krml"] // proof-only
val typedef (t: Type0) : Type0
inline_for_extraction [@@noextract_to "krml"]
let typeof (#t: Type0) (td: typedef t) : Tot Type0 = t
val fractionable (#t: Type0) (td: typedef t) (x: t) : GTot prop
val mk_fraction (#t: Type0) (td: typedef t) (x: t) (p: P.perm) : Ghost t
(requires (fractionable td x))
(ensures (fun y -> p `P.lesser_equal_perm` P.full_perm ==> fractionable td y))
val mk_fraction_full (#t: Type0) (td: typedef t) (x: t) : Lemma
(requires (fractionable td x))
(ensures (mk_fraction td x P.full_perm == x))
[SMTPat (mk_fraction td x P.full_perm)]
val mk_fraction_compose (#t: Type0) (td: typedef t) (x: t) (p1 p2: P.perm) : Lemma
(requires (fractionable td x /\ p1 `P.lesser_equal_perm` P.full_perm /\ p2 `P.lesser_equal_perm` P.full_perm))
(ensures (mk_fraction td (mk_fraction td x p1) p2 == mk_fraction td x (p1 `prod_perm` p2)))
val full (#t: Type0) (td: typedef t) (v: t) : GTot prop
val uninitialized (#t: Type0) (td: typedef t) : Ghost t
(requires True)
(ensures (fun y -> full td y /\ fractionable td y))
val unknown (#t: Type0) (td: typedef t) : Ghost t
(requires True)
(ensures (fun y -> fractionable td y))
val full_not_unknown
(#t: Type)
(td: typedef t)
(v: t)
: Lemma
(requires (full td v))
(ensures (~ (v == unknown td)))
[SMTPat (full td v)]
val mk_fraction_unknown (#t: Type0) (td: typedef t) (p: P.perm) : Lemma
(ensures (mk_fraction td (unknown td) p == unknown td))
val mk_fraction_eq_unknown (#t: Type0) (td: typedef t) (v: t) (p: P.perm) : Lemma
(requires (fractionable td v /\ mk_fraction td v p == unknown td))
(ensures (v == unknown td))
// To be extracted as: void*
[@@noextract_to "krml"] // primitive
val void_ptr : Type0
// To be extracted as: NULL
[@@noextract_to "krml"] // primitive
val void_null: void_ptr
// To be extracted as: *t
[@@noextract_to "krml"] // primitive
val ptr_gen ([@@@unused] t: Type) : Type0
[@@noextract_to "krml"] // primitive
val null_gen (t: Type) : Tot (ptr_gen t)
val ghost_void_ptr_of_ptr_gen (#[@@@unused] t: Type) (x: ptr_gen t) : GTot void_ptr
val ghost_ptr_gen_of_void_ptr (x: void_ptr) ([@@@unused] t: Type) : GTot (ptr_gen t)
val ghost_void_ptr_of_ptr_gen_of_void_ptr
(x: void_ptr)
(t: Type)
: Lemma
(ghost_void_ptr_of_ptr_gen (ghost_ptr_gen_of_void_ptr x t) == x)
[SMTPat (ghost_void_ptr_of_ptr_gen (ghost_ptr_gen_of_void_ptr x t))]
val ghost_ptr_gen_of_void_ptr_of_ptr_gen
(#t: Type)
(x: ptr_gen t)
: Lemma
(ghost_ptr_gen_of_void_ptr (ghost_void_ptr_of_ptr_gen x) t == x)
[SMTPat (ghost_ptr_gen_of_void_ptr (ghost_void_ptr_of_ptr_gen x) t)]
inline_for_extraction [@@noextract_to "krml"] // primitive
let ptr (#t: Type) (td: typedef t) : Tot Type0 = ptr_gen t
inline_for_extraction [@@noextract_to "krml"] // primitive
let null (#t: Type) (td: typedef t) : Tot (ptr td) = null_gen t
inline_for_extraction [@@noextract_to "krml"]
let ref (#t: Type) (td: typedef t) : Tot Type0 = (p: ptr td { ~ (p == null td) })
val pts_to (#t: Type) (#td: typedef t) (r: ref td) ([@@@smt_fallback] v: Ghost.erased t) : vprop
let pts_to_or_null
(#t: Type) (#td: typedef t) (p: ptr td) (v: Ghost.erased t) : vprop
= if FStar.StrongExcludedMiddle.strong_excluded_middle (p == null _)
then emp
else pts_to p v
[@@noextract_to "krml"] // primitive
val is_null
(#t: Type)
(#opened: _)
(#td: typedef t)
(#v: Ghost.erased t)
(p: ptr td)
: STAtomicBase bool false opened Unobservable
(pts_to_or_null p v)
(fun _ -> pts_to_or_null p v)
(True)
(fun res -> res == true <==> p == null _)
let assert_null
(#t: Type)
(#opened: _)
(#td: typedef t)
(#v: Ghost.erased t)
(p: ptr td)
: STGhost unit opened
(pts_to_or_null p v)
(fun _ -> emp)
(p == null _)
(fun _ -> True)
= rewrite (pts_to_or_null p v) emp
let assert_not_null
(#t: Type)
(#opened: _)
(#td: typedef t)
(#v: Ghost.erased t)
(p: ptr td)
: STGhost (squash (~ (p == null _))) opened
(pts_to_or_null p v)
(fun _ -> pts_to p v)
(~ (p == null _))
(fun _ -> True)
= rewrite (pts_to_or_null p v) (pts_to p v)
[@@noextract_to "krml"] // primitive
val void_ptr_of_ptr (#t: Type) (#opened: _) (#td: typedef t) (#v: Ghost.erased t) (x: ptr td) : STAtomicBase void_ptr false opened Unobservable
(pts_to_or_null x v)
(fun _ -> pts_to_or_null x v)
True
(fun y -> y == ghost_void_ptr_of_ptr_gen x) | {
"checked_file": "/",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"Steel.FractionalPermission.fst.checked",
"prims.fst.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Real.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.ST.C.Types.Base.fsti"
} | [
{
"abbrev": true,
"full_module": "Steel.FractionalPermission",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.C.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.C.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: Steel.ST.C.Types.Base.ref td
-> Steel.ST.Effect.Atomic.STAtomicBase Steel.ST.C.Types.Base.void_ptr | Steel.ST.Effect.Atomic.STAtomicBase | [] | [] | [
"Steel.Memory.inames",
"Steel.ST.C.Types.Base.typedef",
"FStar.Ghost.erased",
"Steel.ST.C.Types.Base.ref",
"Steel.ST.Util.return",
"Steel.ST.C.Types.Base.void_ptr",
"Steel.ST.C.Types.Base.pts_to",
"Steel.Effect.Common.vprop",
"Prims.unit",
"Steel.ST.Util.rewrite",
"Steel.ST.C.Types.Base.pts_to_or_null",
"Steel.ST.C.Types.Base.void_ptr_of_ptr",
"Steel.Effect.Common.Unobservable",
"Prims.l_True",
"Prims.eq2",
"Steel.ST.C.Types.Base.ghost_void_ptr_of_ptr_gen"
] | [] | false | true | false | false | false | let void_ptr_of_ref (#t: Type) (#opened: _) (#td: typedef t) (#v: Ghost.erased t) (x: ref td)
: STAtomicBase void_ptr
false
opened
Unobservable
(pts_to x v)
(fun _ -> pts_to x v)
True
(fun y -> y == ghost_void_ptr_of_ptr_gen x) =
| rewrite (pts_to x v) (pts_to_or_null x v);
let res = void_ptr_of_ptr x in
rewrite (pts_to_or_null x v) (pts_to x v);
return res | false |
Hacl.Spec.BignumQ.Lemmas.fst | Hacl.Spec.BignumQ.Lemmas.lemma_add_modq5 | val lemma_add_modq5:
x:qelem5
-> y:qelem5
-> t:qelem5 ->
Lemma
(requires
qelem_fits5 x (1, 1, 1, 1, 1) /\
qelem_fits5 y (1, 1, 1, 1, 1) /\
qelem_fits5 t (1, 1, 1, 1, 1) /\
as_nat5 x < S.q /\ as_nat5 y < S.q /\
as_nat5 t == as_nat5 x + as_nat5 y)
(ensures
(let res = if as_nat5 t >= S.q then as_nat5 t - S.q else as_nat5 t in
res < S.q /\ res == (as_nat5 x + as_nat5 y) % S.q)) | val lemma_add_modq5:
x:qelem5
-> y:qelem5
-> t:qelem5 ->
Lemma
(requires
qelem_fits5 x (1, 1, 1, 1, 1) /\
qelem_fits5 y (1, 1, 1, 1, 1) /\
qelem_fits5 t (1, 1, 1, 1, 1) /\
as_nat5 x < S.q /\ as_nat5 y < S.q /\
as_nat5 t == as_nat5 x + as_nat5 y)
(ensures
(let res = if as_nat5 t >= S.q then as_nat5 t - S.q else as_nat5 t in
res < S.q /\ res == (as_nat5 x + as_nat5 y) % S.q)) | let lemma_add_modq5 x y t =
assert (as_nat5 t == as_nat5 x + as_nat5 y);
let res = if as_nat5 t >= S.q then as_nat5 t - S.q else as_nat5 t in
assert (res < S.q);
if as_nat5 t >= S.q then (
FStar.Math.Lemmas.sub_div_mod_1 (as_nat5 t) S.q;
assert (res % S.q == as_nat5 t % S.q))
else
assert (res % S.q == as_nat5 t % S.q);
FStar.Math.Lemmas.small_mod res S.q | {
"file_name": "code/ed25519/Hacl.Spec.BignumQ.Lemmas.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 37,
"end_line": 306,
"start_col": 0,
"start_line": 296
} | module Hacl.Spec.BignumQ.Lemmas
open FStar.Tactics.CanonCommSemiring
open FStar.Mul
open Lib.IntTypes
module S = Spec.Ed25519
include Hacl.Spec.BignumQ.Definitions
let feq (#a #b:Type) (f:(a -> b)) (x y:a) :
Lemma (requires x == y) (ensures f x == f y) = ()
let eq_eq2 (#a:eqtype) (x y:a) :
Lemma (requires x = y) (ensures x == y) = ()
val lemma_mul_lt:a:nat -> b:nat -> c:nat -> d:nat ->
Lemma
(requires a < b /\ c < d)
(ensures a * c < b * d)
let lemma_mul_lt a b c d = ()
val lemma_as_nat5: f:qelem5 ->
Lemma
(requires qelem_fits5 f (1, 1, 1, 1, 1))
(ensures as_nat5 f < pow2 280)
let lemma_as_nat5 f =
//let (f0, f1, f2, f3, f4) = f in
//assert (as_nat5 f == v f0 + v f1 * pow56 + v f2 * pow112 + v f3 * pow168 + v f4 * pow224);
assert_norm (pow2 56 * pow2 56 = pow2 112);
assert_norm (pow2 56 * pow2 112 = pow2 168);
assert_norm (pow2 56 * pow2 168 = pow2 224);
assert_norm (pow2 56 * pow2 224 = pow2 280)
val lemma_choose_step:
bit:uint64{v bit <= 1}
-> x:uint64
-> y:uint64
-> Lemma
(let mask = bit -. u64 1 in
let z = x ^. (mask &. (x ^. y)) in
if v bit = 1 then z == x else z == y)
let lemma_choose_step bit p1 p2 =
let mask = bit -. u64 1 in
assert (v bit == 0 ==> v mask == pow2 64 - 1);
assert (v bit == 1 ==> v mask == 0);
let dummy = mask &. (p1 ^. p2) in
logand_lemma mask (p1 ^. p2);
assert (v bit == 1 ==> v dummy == 0);
assert (v bit == 0 ==> v dummy == v (p1 ^. p2));
let p1' = p1 ^. dummy in
assert (v dummy == v (if v bit = 1 then u64 0 else (p1 ^. p2)));
logxor_lemma p1 p2
val lemma_subm_conditional:
x0:nat -> x1:nat -> x2:nat -> x3:nat -> x4:nat
-> y0:nat -> y1:nat -> y2:nat -> y3:nat -> y4:nat
-> b0:nat -> b1:nat -> b2:nat -> b3:nat -> b4:nat ->
Lemma (
x0 - y0 + b0 * pow2 56 +
(x1 - y1 - b0 + b1 * pow2 56) * pow2 56 +
(x2 - y2 - b1 + b2 * pow2 56) * pow2 112 +
(x3 - y3 - b2 + b3 * pow2 56) * pow2 168 +
(x4 - y4 - b3 + b4 * pow2 56) * pow2 224 ==
(x0 + x1 * pow2 56 + x2 * pow2 112 + x3 * pow2 168 + x4 * pow2 224) -
(y0 + y1 * pow2 56 + y2 * pow2 112 + y3 * pow2 168 + y4 * pow2 224) + b4 * pow2 280)
let lemma_subm_conditional x0 x1 x2 x3 x4 y0 y1 y2 y3 y4 b0 b1 b2 b3 b4 =
assert_norm (pow2 56 * pow2 56 = pow2 112);
assert_norm (pow2 56 * pow2 112 = pow2 168);
assert_norm (pow2 56 * pow2 168 = pow2 224);
assert_norm (pow2 56 * pow2 224 = pow2 280);
assert (
x0 - y0 + b0 * pow2 56 +
(x1 - y1 - b0 + b1 * pow2 56) * pow2 56 +
(x2 - y2 - b1 + b2 * pow2 56) * pow2 112 +
(x3 - y3 - b2 + b3 * pow2 56) * pow2 168 +
(x4 - y4 - b3 + b4 * pow2 56) * pow2 224 ==
(x0 + x1 * pow2 56 + x2 * pow2 112 + x3 * pow2 168 + x4 * pow2 224) -
(y0 + y1 * pow2 56 + y2 * pow2 112 + y3 * pow2 168 + y4 * pow2 224) + b4 * pow2 280)
by (int_semiring ());
()
val lemma_div224: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1))
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
wide_as_nat5 x / pow2 224 ==
v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280))
#push-options "--z3rlimit 50"
let lemma_div224 x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert
(wide_as_nat5 x ==
v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168 + v x4 * pow2 224 +
v x5 * pow2 280 + v x6 * pow2 336 + v x7 * pow2 392 + v x8 * pow2 448 + v x9 * pow2 504);
assert_norm (pow2 56 * pow2 224 == pow2 280);
assert_norm (pow2 112 * pow2 224 == pow2 336);
assert_norm (pow2 168 * pow2 224 == pow2 392);
assert_norm (pow2 224 * pow2 224 == pow2 448);
assert_norm (pow2 280 * pow2 224 == pow2 504);
calc (==) {
wide_as_nat5 x / pow2 224;
(==) { }
(v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168 +
(v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280) * pow2 224) / pow2 224;
(==) {
FStar.Math.Lemmas.lemma_div_plus
(v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168)
(v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280) (pow2 224) }
(v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168) / pow2 224 +
v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280;
(==) { FStar.Math.Lemmas.small_division_lemma_1 (v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168) (pow2 224) }
v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280;
}
#pop-options
val lemma_div248_aux: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 512)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
wide_as_nat5 x / pow2 248 ==
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256))
open FStar.Tactics.CanonCommSemiring
#push-options "--z3cliopt smt.arith.nl=false"
let lemma_div248_aux x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert_norm (pow2 248 == pow2 224 * pow2 24);
assert_norm (pow2 56 == pow2 32 * pow2 24);
assert_norm (pow2 112 == pow2 88 * pow2 24);
assert_norm (pow2 168 == pow2 144 * pow2 24);
assert_norm (pow2 224 == pow2 200 * pow2 24);
assert_norm (pow2 280 == pow2 256 * pow2 24);
assert_norm (0 < pow2 24);
calc (==) {
wide_as_nat5 x / pow2 248;
(==) { FStar.Math.Lemmas.division_multiplication_lemma (wide_as_nat5 x) (pow2 224) (pow2 24) }
(wide_as_nat5 x / pow2 224) / pow2 24;
(==) { lemma_div224 x }
(v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280) / pow2 24;
(==) { _ by (Tactics.mapply (`feq #int #int (fun x -> x / pow2 24)); int_semiring ()) } (v x4 + (v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256) * pow2 24) / pow2 24;
(==) { FStar.Math.Lemmas.lemma_div_plus (v x4) (v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256) (pow2 24) }
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256;
}
#pop-options
val lemma_div248_x5: x5:uint64 ->
Lemma ( pow2 32 * (v x5 % pow2 24) + v x5 / pow2 24 * pow2 56 == v x5 * pow2 32)
let lemma_div248_x5 x5 =
assert_norm (pow2 32 * pow2 24 = pow2 56)
val lemma_div248_x6: x6:uint64 ->
Lemma (pow2 32 * (v x6 % pow2 24) * pow2 56 + v x6 / pow2 24 * pow2 112 == v x6 * pow2 88)
let lemma_div248_x6 x6 =
calc (==) {
pow2 32 * (v x6 % pow2 24) * pow2 56 + v x6 / pow2 24 * pow2 112;
(==) { _ by (Tactics.norm [delta_only [`%pow2]; primops]; int_semiring ()) }
((v x6 / pow2 24) * pow2 24 + v x6 % pow2 24) * pow2 88;
(==) { FStar.Math.Lemmas.euclidean_division_definition (v x6) (pow2 24) }
v x6 * pow2 88;
}
val lemma_div248_x7: x7:uint64 ->
Lemma (pow2 32 * (v x7 % pow2 24) * pow2 112 + v x7 / pow2 24 * pow2 168 == v x7 * pow2 144)
let lemma_div248_x7 x7 =
calc (==) {
pow2 32 * (v x7 % pow2 24) * pow2 112 + v x7 / pow2 24 * pow2 168;
(==) { _ by (Tactics.norm [delta_only [`%pow2]; primops]; int_semiring ()) }
((v x7 / pow2 24) * pow2 24 + v x7 % pow2 24) * pow2 144;
(==) { FStar.Math.Lemmas.euclidean_division_definition (v x7) (pow2 24) }
v x7 * pow2 144;
}
val lemma_div248_x8: x8:uint64 ->
Lemma (pow2 32 * (v x8 % pow2 24) * pow2 168 + v x8 / pow2 24 * pow2 224 == v x8 * pow2 200)
let lemma_div248_x8 x8 =
calc (==) {
pow2 32 * (v x8 % pow2 24) * pow2 168 + v x8 / pow2 24 * pow2 224;
(==) { _ by (Tactics.norm [delta_only [`%pow2]; primops]; int_semiring ()) }
((v x8 / pow2 24) * pow2 24 + v x8 % pow2 24) * pow2 200;
(==) { FStar.Math.Lemmas.euclidean_division_definition (v x8) (pow2 24) }
v x8 * pow2 200;
}
val lemma_div248_x9: x9:uint64{v x9 < pow2 24} ->
Lemma (pow2 32 * (v x9 % pow2 24) * pow2 224 == v x9 * pow2 256)
let lemma_div248_x9 x9 =
calc (==) {
pow2 32 * (v x9 % pow2 24) * pow2 224;
(==) { Math.Lemmas.small_mod (v x9) (pow2 24) }
pow2 32 * v x9 * pow2 224;
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
v x9 * pow2 256;
}
val lemma_wide_as_nat_pow512: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 512)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
v x9 < pow2 24))
let lemma_wide_as_nat_pow512 x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert_norm (pow2 504 * pow2 8 = pow2 512);
FStar.Math.Lemmas.pow2_minus 512 504;
assert (v x9 < pow2 8);
assert_norm (pow2 8 < pow2 24)
val lemma_div248: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 512)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
let z0 = v x4 / pow2 24 + pow2 32 * (v x5 % pow2 24) in
let z1 = v x5 / pow2 24 + pow2 32 * (v x6 % pow2 24) in
let z2 = v x6 / pow2 24 + pow2 32 * (v x7 % pow2 24) in
let z3 = v x7 / pow2 24 + pow2 32 * (v x8 % pow2 24) in
let z4 = v x8 / pow2 24 + pow2 32 * (v x9 % pow2 24) in
wide_as_nat5 x / pow2 248 == z0 + z1 * pow2 56 + z2 * pow2 112 + z3 * pow2 168 + z4 * pow2 224))
#push-options "--z3rlimit 50"
let lemma_div248 x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
lemma_wide_as_nat_pow512 x;
assert (v x9 < pow2 24);
calc (==) {
(let z0 = v x4 / pow2 24 + pow2 32 * (v x5 % pow2 24) in
let z1 = v x5 / pow2 24 + pow2 32 * (v x6 % pow2 24) in
let z2 = v x6 / pow2 24 + pow2 32 * (v x7 % pow2 24) in
let z3 = v x7 / pow2 24 + pow2 32 * (v x8 % pow2 24) in
let z4 = v x8 / pow2 24 + pow2 32 * (v x9 % pow2 24) in
z0 + z1 * pow2 56 + z2 * pow2 112 + z3 * pow2 168 + z4 * pow2 224);
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
v x4 / pow2 24 + pow2 32 * (v x5 % pow2 24) +
v x5 / pow2 24 * pow2 56 + pow2 32 * (v x6 % pow2 24) * pow2 56 +
v x6 / pow2 24 * pow2 112 + pow2 32 * (v x7 % pow2 24) * pow2 112 +
v x7 / pow2 24 * pow2 168 + pow2 32 * (v x8 % pow2 24) * pow2 168 +
v x8 / pow2 24 * pow2 224 + pow2 32 * (v x9 % pow2 24) * pow2 224;
(==) { lemma_div248_x5 x5; lemma_div248_x6 x6 }
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 +
pow2 32 * (v x7 % pow2 24) * pow2 112 +
v x7 / pow2 24 * pow2 168 + pow2 32 * (v x8 % pow2 24) * pow2 168 +
v x8 / pow2 24 * pow2 224 + pow2 32 * (v x9 % pow2 24) * pow2 224;
(==) { lemma_div248_x7 x7; lemma_div248_x8 x8 }
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 +
pow2 32 * (v x9 % pow2 24) * pow2 224;
(==) { lemma_div248_x9 x9 }
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256;
(==) { lemma_div248_aux x }
wide_as_nat5 x / pow2 248;
}
#pop-options
val lemma_add_modq5:
x:qelem5
-> y:qelem5
-> t:qelem5 ->
Lemma
(requires
qelem_fits5 x (1, 1, 1, 1, 1) /\
qelem_fits5 y (1, 1, 1, 1, 1) /\
qelem_fits5 t (1, 1, 1, 1, 1) /\
as_nat5 x < S.q /\ as_nat5 y < S.q /\
as_nat5 t == as_nat5 x + as_nat5 y)
(ensures
(let res = if as_nat5 t >= S.q then as_nat5 t - S.q else as_nat5 t in
res < S.q /\ res == (as_nat5 x + as_nat5 y) % S.q)) | {
"checked_file": "/",
"dependencies": [
"Spec.Ed25519.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.BignumQ.Definitions.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Tactics.CanonCommSemiring.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.BignumQ.Lemmas.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.CanonCommSemiring",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.BignumQ.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.Ed25519",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.CanonCommSemiring",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.BignumQ",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.BignumQ",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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 |
x: Hacl.Spec.BignumQ.Definitions.qelem5 ->
y: Hacl.Spec.BignumQ.Definitions.qelem5 ->
t: Hacl.Spec.BignumQ.Definitions.qelem5
-> FStar.Pervasives.Lemma
(requires
Hacl.Spec.BignumQ.Definitions.qelem_fits5 x (1, 1, 1, 1, 1) /\
Hacl.Spec.BignumQ.Definitions.qelem_fits5 y (1, 1, 1, 1, 1) /\
Hacl.Spec.BignumQ.Definitions.qelem_fits5 t (1, 1, 1, 1, 1) /\
Hacl.Spec.BignumQ.Definitions.as_nat5 x < Spec.Ed25519.q /\
Hacl.Spec.BignumQ.Definitions.as_nat5 y < Spec.Ed25519.q /\
Hacl.Spec.BignumQ.Definitions.as_nat5 t ==
Hacl.Spec.BignumQ.Definitions.as_nat5 x + Hacl.Spec.BignumQ.Definitions.as_nat5 y)
(ensures
(let res =
(match Hacl.Spec.BignumQ.Definitions.as_nat5 t >= Spec.Ed25519.q with
| true -> Hacl.Spec.BignumQ.Definitions.as_nat5 t - Spec.Ed25519.q
| _ -> Hacl.Spec.BignumQ.Definitions.as_nat5 t)
<:
Prims.int
in
res < Spec.Ed25519.q /\
res ==
(Hacl.Spec.BignumQ.Definitions.as_nat5 x + Hacl.Spec.BignumQ.Definitions.as_nat5 y) %
Spec.Ed25519.q)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Hacl.Spec.BignumQ.Definitions.qelem5",
"FStar.Math.Lemmas.small_mod",
"Spec.Ed25519.q",
"Prims.unit",
"Prims.op_GreaterThanOrEqual",
"Hacl.Spec.BignumQ.Definitions.as_nat5",
"Prims._assert",
"Prims.eq2",
"Prims.int",
"Prims.op_Modulus",
"FStar.Math.Lemmas.sub_div_mod_1",
"Prims.bool",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.op_Subtraction",
"Prims.op_Addition"
] | [] | false | false | true | false | false | let lemma_add_modq5 x y t =
| assert (as_nat5 t == as_nat5 x + as_nat5 y);
let res = if as_nat5 t >= S.q then as_nat5 t - S.q else as_nat5 t in
assert (res < S.q);
if as_nat5 t >= S.q
then
(FStar.Math.Lemmas.sub_div_mod_1 (as_nat5 t) S.q;
assert (res % S.q == as_nat5 t % S.q))
else assert (res % S.q == as_nat5 t % S.q);
FStar.Math.Lemmas.small_mod res S.q | false |
Hacl.Spec.BignumQ.Lemmas.fst | Hacl.Spec.BignumQ.Lemmas.lemma_div248_x6 | val lemma_div248_x6: x6:uint64 ->
Lemma (pow2 32 * (v x6 % pow2 24) * pow2 56 + v x6 / pow2 24 * pow2 112 == v x6 * pow2 88) | val lemma_div248_x6: x6:uint64 ->
Lemma (pow2 32 * (v x6 % pow2 24) * pow2 56 + v x6 / pow2 24 * pow2 112 == v x6 * pow2 88) | let lemma_div248_x6 x6 =
calc (==) {
pow2 32 * (v x6 % pow2 24) * pow2 56 + v x6 / pow2 24 * pow2 112;
(==) { _ by (Tactics.norm [delta_only [`%pow2]; primops]; int_semiring ()) }
((v x6 / pow2 24) * pow2 24 + v x6 % pow2 24) * pow2 88;
(==) { FStar.Math.Lemmas.euclidean_division_definition (v x6) (pow2 24) }
v x6 * pow2 88;
} | {
"file_name": "code/ed25519/Hacl.Spec.BignumQ.Lemmas.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 3,
"end_line": 176,
"start_col": 0,
"start_line": 169
} | module Hacl.Spec.BignumQ.Lemmas
open FStar.Tactics.CanonCommSemiring
open FStar.Mul
open Lib.IntTypes
module S = Spec.Ed25519
include Hacl.Spec.BignumQ.Definitions
let feq (#a #b:Type) (f:(a -> b)) (x y:a) :
Lemma (requires x == y) (ensures f x == f y) = ()
let eq_eq2 (#a:eqtype) (x y:a) :
Lemma (requires x = y) (ensures x == y) = ()
val lemma_mul_lt:a:nat -> b:nat -> c:nat -> d:nat ->
Lemma
(requires a < b /\ c < d)
(ensures a * c < b * d)
let lemma_mul_lt a b c d = ()
val lemma_as_nat5: f:qelem5 ->
Lemma
(requires qelem_fits5 f (1, 1, 1, 1, 1))
(ensures as_nat5 f < pow2 280)
let lemma_as_nat5 f =
//let (f0, f1, f2, f3, f4) = f in
//assert (as_nat5 f == v f0 + v f1 * pow56 + v f2 * pow112 + v f3 * pow168 + v f4 * pow224);
assert_norm (pow2 56 * pow2 56 = pow2 112);
assert_norm (pow2 56 * pow2 112 = pow2 168);
assert_norm (pow2 56 * pow2 168 = pow2 224);
assert_norm (pow2 56 * pow2 224 = pow2 280)
val lemma_choose_step:
bit:uint64{v bit <= 1}
-> x:uint64
-> y:uint64
-> Lemma
(let mask = bit -. u64 1 in
let z = x ^. (mask &. (x ^. y)) in
if v bit = 1 then z == x else z == y)
let lemma_choose_step bit p1 p2 =
let mask = bit -. u64 1 in
assert (v bit == 0 ==> v mask == pow2 64 - 1);
assert (v bit == 1 ==> v mask == 0);
let dummy = mask &. (p1 ^. p2) in
logand_lemma mask (p1 ^. p2);
assert (v bit == 1 ==> v dummy == 0);
assert (v bit == 0 ==> v dummy == v (p1 ^. p2));
let p1' = p1 ^. dummy in
assert (v dummy == v (if v bit = 1 then u64 0 else (p1 ^. p2)));
logxor_lemma p1 p2
val lemma_subm_conditional:
x0:nat -> x1:nat -> x2:nat -> x3:nat -> x4:nat
-> y0:nat -> y1:nat -> y2:nat -> y3:nat -> y4:nat
-> b0:nat -> b1:nat -> b2:nat -> b3:nat -> b4:nat ->
Lemma (
x0 - y0 + b0 * pow2 56 +
(x1 - y1 - b0 + b1 * pow2 56) * pow2 56 +
(x2 - y2 - b1 + b2 * pow2 56) * pow2 112 +
(x3 - y3 - b2 + b3 * pow2 56) * pow2 168 +
(x4 - y4 - b3 + b4 * pow2 56) * pow2 224 ==
(x0 + x1 * pow2 56 + x2 * pow2 112 + x3 * pow2 168 + x4 * pow2 224) -
(y0 + y1 * pow2 56 + y2 * pow2 112 + y3 * pow2 168 + y4 * pow2 224) + b4 * pow2 280)
let lemma_subm_conditional x0 x1 x2 x3 x4 y0 y1 y2 y3 y4 b0 b1 b2 b3 b4 =
assert_norm (pow2 56 * pow2 56 = pow2 112);
assert_norm (pow2 56 * pow2 112 = pow2 168);
assert_norm (pow2 56 * pow2 168 = pow2 224);
assert_norm (pow2 56 * pow2 224 = pow2 280);
assert (
x0 - y0 + b0 * pow2 56 +
(x1 - y1 - b0 + b1 * pow2 56) * pow2 56 +
(x2 - y2 - b1 + b2 * pow2 56) * pow2 112 +
(x3 - y3 - b2 + b3 * pow2 56) * pow2 168 +
(x4 - y4 - b3 + b4 * pow2 56) * pow2 224 ==
(x0 + x1 * pow2 56 + x2 * pow2 112 + x3 * pow2 168 + x4 * pow2 224) -
(y0 + y1 * pow2 56 + y2 * pow2 112 + y3 * pow2 168 + y4 * pow2 224) + b4 * pow2 280)
by (int_semiring ());
()
val lemma_div224: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1))
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
wide_as_nat5 x / pow2 224 ==
v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280))
#push-options "--z3rlimit 50"
let lemma_div224 x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert
(wide_as_nat5 x ==
v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168 + v x4 * pow2 224 +
v x5 * pow2 280 + v x6 * pow2 336 + v x7 * pow2 392 + v x8 * pow2 448 + v x9 * pow2 504);
assert_norm (pow2 56 * pow2 224 == pow2 280);
assert_norm (pow2 112 * pow2 224 == pow2 336);
assert_norm (pow2 168 * pow2 224 == pow2 392);
assert_norm (pow2 224 * pow2 224 == pow2 448);
assert_norm (pow2 280 * pow2 224 == pow2 504);
calc (==) {
wide_as_nat5 x / pow2 224;
(==) { }
(v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168 +
(v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280) * pow2 224) / pow2 224;
(==) {
FStar.Math.Lemmas.lemma_div_plus
(v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168)
(v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280) (pow2 224) }
(v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168) / pow2 224 +
v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280;
(==) { FStar.Math.Lemmas.small_division_lemma_1 (v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168) (pow2 224) }
v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280;
}
#pop-options
val lemma_div248_aux: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 512)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
wide_as_nat5 x / pow2 248 ==
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256))
open FStar.Tactics.CanonCommSemiring
#push-options "--z3cliopt smt.arith.nl=false"
let lemma_div248_aux x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert_norm (pow2 248 == pow2 224 * pow2 24);
assert_norm (pow2 56 == pow2 32 * pow2 24);
assert_norm (pow2 112 == pow2 88 * pow2 24);
assert_norm (pow2 168 == pow2 144 * pow2 24);
assert_norm (pow2 224 == pow2 200 * pow2 24);
assert_norm (pow2 280 == pow2 256 * pow2 24);
assert_norm (0 < pow2 24);
calc (==) {
wide_as_nat5 x / pow2 248;
(==) { FStar.Math.Lemmas.division_multiplication_lemma (wide_as_nat5 x) (pow2 224) (pow2 24) }
(wide_as_nat5 x / pow2 224) / pow2 24;
(==) { lemma_div224 x }
(v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280) / pow2 24;
(==) { _ by (Tactics.mapply (`feq #int #int (fun x -> x / pow2 24)); int_semiring ()) } (v x4 + (v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256) * pow2 24) / pow2 24;
(==) { FStar.Math.Lemmas.lemma_div_plus (v x4) (v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256) (pow2 24) }
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256;
}
#pop-options
val lemma_div248_x5: x5:uint64 ->
Lemma ( pow2 32 * (v x5 % pow2 24) + v x5 / pow2 24 * pow2 56 == v x5 * pow2 32)
let lemma_div248_x5 x5 =
assert_norm (pow2 32 * pow2 24 = pow2 56)
val lemma_div248_x6: x6:uint64 -> | {
"checked_file": "/",
"dependencies": [
"Spec.Ed25519.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.BignumQ.Definitions.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Tactics.CanonCommSemiring.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.BignumQ.Lemmas.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.CanonCommSemiring",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.BignumQ.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.Ed25519",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.CanonCommSemiring",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.BignumQ",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.BignumQ",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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 | x6: Lib.IntTypes.uint64
-> FStar.Pervasives.Lemma
(ensures
(Prims.pow2 32 * (Lib.IntTypes.v x6 % Prims.pow2 24)) * Prims.pow2 56 +
(Lib.IntTypes.v x6 / Prims.pow2 24) * Prims.pow2 112 ==
Lib.IntTypes.v x6 * Prims.pow2 88) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Lib.IntTypes.uint64",
"FStar.Calc.calc_finish",
"Prims.int",
"Prims.eq2",
"Prims.op_Addition",
"FStar.Mul.op_Star",
"Prims.pow2",
"Prims.op_Modulus",
"Lib.IntTypes.v",
"Lib.IntTypes.U64",
"Lib.IntTypes.SEC",
"Prims.op_Division",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"Prims.unit",
"FStar.Calc.calc_step",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"FStar.Tactics.CanonCommSemiring.semiring_reflect",
"FStar.Tactics.CanonCommSemiring.int_cr",
"FStar.Pervasives.Native.Mktuple2",
"Prims.list",
"FStar.Pervasives.Native.tuple2",
"Prims.nat",
"FStar.Pervasives.Native.snd",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"Lib.IntTypes.sec_int_v",
"FStar.Stubs.Reflection.V2.Data.var",
"FStar.Tactics.CanonCommSemiring.Pplus",
"FStar.Tactics.CanonCommSemiring.Pmult",
"FStar.Tactics.CanonCommSemiring.Pvar",
"Prims.squash",
"FStar.Math.Lemmas.euclidean_division_definition"
] | [] | false | false | true | false | false | let lemma_div248_x6 x6 =
| calc ( == ) {
(pow2 32 * (v x6 % pow2 24)) * pow2 56 + (v x6 / pow2 24) * pow2 112;
( == ) { FStar.Tactics.Effect.synth_by_tactic (fun _ ->
(Tactics.norm [delta_only [`%pow2]; primops];
int_semiring ())) }
((v x6 / pow2 24) * pow2 24 + v x6 % pow2 24) * pow2 88;
( == ) { FStar.Math.Lemmas.euclidean_division_definition (v x6) (pow2 24) }
v x6 * pow2 88;
} | false |
Hacl.Spec.BignumQ.Lemmas.fst | Hacl.Spec.BignumQ.Lemmas.lemma_wide_as_nat_pow528 | val lemma_wide_as_nat_pow528: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 528)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
v x9 < pow2 40)) | val lemma_wide_as_nat_pow528: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 528)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
v x9 < pow2 40)) | let lemma_wide_as_nat_pow528 x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert_norm (pow2 504 * pow2 24 = pow2 528);
FStar.Math.Lemmas.pow2_minus 528 504;
assert (v x9 < pow2 24);
assert_norm (pow2 24 < pow2 40) | {
"file_name": "code/ed25519/Hacl.Spec.BignumQ.Lemmas.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 33,
"end_line": 323,
"start_col": 0,
"start_line": 318
} | module Hacl.Spec.BignumQ.Lemmas
open FStar.Tactics.CanonCommSemiring
open FStar.Mul
open Lib.IntTypes
module S = Spec.Ed25519
include Hacl.Spec.BignumQ.Definitions
let feq (#a #b:Type) (f:(a -> b)) (x y:a) :
Lemma (requires x == y) (ensures f x == f y) = ()
let eq_eq2 (#a:eqtype) (x y:a) :
Lemma (requires x = y) (ensures x == y) = ()
val lemma_mul_lt:a:nat -> b:nat -> c:nat -> d:nat ->
Lemma
(requires a < b /\ c < d)
(ensures a * c < b * d)
let lemma_mul_lt a b c d = ()
val lemma_as_nat5: f:qelem5 ->
Lemma
(requires qelem_fits5 f (1, 1, 1, 1, 1))
(ensures as_nat5 f < pow2 280)
let lemma_as_nat5 f =
//let (f0, f1, f2, f3, f4) = f in
//assert (as_nat5 f == v f0 + v f1 * pow56 + v f2 * pow112 + v f3 * pow168 + v f4 * pow224);
assert_norm (pow2 56 * pow2 56 = pow2 112);
assert_norm (pow2 56 * pow2 112 = pow2 168);
assert_norm (pow2 56 * pow2 168 = pow2 224);
assert_norm (pow2 56 * pow2 224 = pow2 280)
val lemma_choose_step:
bit:uint64{v bit <= 1}
-> x:uint64
-> y:uint64
-> Lemma
(let mask = bit -. u64 1 in
let z = x ^. (mask &. (x ^. y)) in
if v bit = 1 then z == x else z == y)
let lemma_choose_step bit p1 p2 =
let mask = bit -. u64 1 in
assert (v bit == 0 ==> v mask == pow2 64 - 1);
assert (v bit == 1 ==> v mask == 0);
let dummy = mask &. (p1 ^. p2) in
logand_lemma mask (p1 ^. p2);
assert (v bit == 1 ==> v dummy == 0);
assert (v bit == 0 ==> v dummy == v (p1 ^. p2));
let p1' = p1 ^. dummy in
assert (v dummy == v (if v bit = 1 then u64 0 else (p1 ^. p2)));
logxor_lemma p1 p2
val lemma_subm_conditional:
x0:nat -> x1:nat -> x2:nat -> x3:nat -> x4:nat
-> y0:nat -> y1:nat -> y2:nat -> y3:nat -> y4:nat
-> b0:nat -> b1:nat -> b2:nat -> b3:nat -> b4:nat ->
Lemma (
x0 - y0 + b0 * pow2 56 +
(x1 - y1 - b0 + b1 * pow2 56) * pow2 56 +
(x2 - y2 - b1 + b2 * pow2 56) * pow2 112 +
(x3 - y3 - b2 + b3 * pow2 56) * pow2 168 +
(x4 - y4 - b3 + b4 * pow2 56) * pow2 224 ==
(x0 + x1 * pow2 56 + x2 * pow2 112 + x3 * pow2 168 + x4 * pow2 224) -
(y0 + y1 * pow2 56 + y2 * pow2 112 + y3 * pow2 168 + y4 * pow2 224) + b4 * pow2 280)
let lemma_subm_conditional x0 x1 x2 x3 x4 y0 y1 y2 y3 y4 b0 b1 b2 b3 b4 =
assert_norm (pow2 56 * pow2 56 = pow2 112);
assert_norm (pow2 56 * pow2 112 = pow2 168);
assert_norm (pow2 56 * pow2 168 = pow2 224);
assert_norm (pow2 56 * pow2 224 = pow2 280);
assert (
x0 - y0 + b0 * pow2 56 +
(x1 - y1 - b0 + b1 * pow2 56) * pow2 56 +
(x2 - y2 - b1 + b2 * pow2 56) * pow2 112 +
(x3 - y3 - b2 + b3 * pow2 56) * pow2 168 +
(x4 - y4 - b3 + b4 * pow2 56) * pow2 224 ==
(x0 + x1 * pow2 56 + x2 * pow2 112 + x3 * pow2 168 + x4 * pow2 224) -
(y0 + y1 * pow2 56 + y2 * pow2 112 + y3 * pow2 168 + y4 * pow2 224) + b4 * pow2 280)
by (int_semiring ());
()
val lemma_div224: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1))
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
wide_as_nat5 x / pow2 224 ==
v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280))
#push-options "--z3rlimit 50"
let lemma_div224 x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert
(wide_as_nat5 x ==
v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168 + v x4 * pow2 224 +
v x5 * pow2 280 + v x6 * pow2 336 + v x7 * pow2 392 + v x8 * pow2 448 + v x9 * pow2 504);
assert_norm (pow2 56 * pow2 224 == pow2 280);
assert_norm (pow2 112 * pow2 224 == pow2 336);
assert_norm (pow2 168 * pow2 224 == pow2 392);
assert_norm (pow2 224 * pow2 224 == pow2 448);
assert_norm (pow2 280 * pow2 224 == pow2 504);
calc (==) {
wide_as_nat5 x / pow2 224;
(==) { }
(v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168 +
(v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280) * pow2 224) / pow2 224;
(==) {
FStar.Math.Lemmas.lemma_div_plus
(v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168)
(v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280) (pow2 224) }
(v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168) / pow2 224 +
v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280;
(==) { FStar.Math.Lemmas.small_division_lemma_1 (v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168) (pow2 224) }
v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280;
}
#pop-options
val lemma_div248_aux: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 512)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
wide_as_nat5 x / pow2 248 ==
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256))
open FStar.Tactics.CanonCommSemiring
#push-options "--z3cliopt smt.arith.nl=false"
let lemma_div248_aux x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert_norm (pow2 248 == pow2 224 * pow2 24);
assert_norm (pow2 56 == pow2 32 * pow2 24);
assert_norm (pow2 112 == pow2 88 * pow2 24);
assert_norm (pow2 168 == pow2 144 * pow2 24);
assert_norm (pow2 224 == pow2 200 * pow2 24);
assert_norm (pow2 280 == pow2 256 * pow2 24);
assert_norm (0 < pow2 24);
calc (==) {
wide_as_nat5 x / pow2 248;
(==) { FStar.Math.Lemmas.division_multiplication_lemma (wide_as_nat5 x) (pow2 224) (pow2 24) }
(wide_as_nat5 x / pow2 224) / pow2 24;
(==) { lemma_div224 x }
(v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280) / pow2 24;
(==) { _ by (Tactics.mapply (`feq #int #int (fun x -> x / pow2 24)); int_semiring ()) } (v x4 + (v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256) * pow2 24) / pow2 24;
(==) { FStar.Math.Lemmas.lemma_div_plus (v x4) (v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256) (pow2 24) }
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256;
}
#pop-options
val lemma_div248_x5: x5:uint64 ->
Lemma ( pow2 32 * (v x5 % pow2 24) + v x5 / pow2 24 * pow2 56 == v x5 * pow2 32)
let lemma_div248_x5 x5 =
assert_norm (pow2 32 * pow2 24 = pow2 56)
val lemma_div248_x6: x6:uint64 ->
Lemma (pow2 32 * (v x6 % pow2 24) * pow2 56 + v x6 / pow2 24 * pow2 112 == v x6 * pow2 88)
let lemma_div248_x6 x6 =
calc (==) {
pow2 32 * (v x6 % pow2 24) * pow2 56 + v x6 / pow2 24 * pow2 112;
(==) { _ by (Tactics.norm [delta_only [`%pow2]; primops]; int_semiring ()) }
((v x6 / pow2 24) * pow2 24 + v x6 % pow2 24) * pow2 88;
(==) { FStar.Math.Lemmas.euclidean_division_definition (v x6) (pow2 24) }
v x6 * pow2 88;
}
val lemma_div248_x7: x7:uint64 ->
Lemma (pow2 32 * (v x7 % pow2 24) * pow2 112 + v x7 / pow2 24 * pow2 168 == v x7 * pow2 144)
let lemma_div248_x7 x7 =
calc (==) {
pow2 32 * (v x7 % pow2 24) * pow2 112 + v x7 / pow2 24 * pow2 168;
(==) { _ by (Tactics.norm [delta_only [`%pow2]; primops]; int_semiring ()) }
((v x7 / pow2 24) * pow2 24 + v x7 % pow2 24) * pow2 144;
(==) { FStar.Math.Lemmas.euclidean_division_definition (v x7) (pow2 24) }
v x7 * pow2 144;
}
val lemma_div248_x8: x8:uint64 ->
Lemma (pow2 32 * (v x8 % pow2 24) * pow2 168 + v x8 / pow2 24 * pow2 224 == v x8 * pow2 200)
let lemma_div248_x8 x8 =
calc (==) {
pow2 32 * (v x8 % pow2 24) * pow2 168 + v x8 / pow2 24 * pow2 224;
(==) { _ by (Tactics.norm [delta_only [`%pow2]; primops]; int_semiring ()) }
((v x8 / pow2 24) * pow2 24 + v x8 % pow2 24) * pow2 200;
(==) { FStar.Math.Lemmas.euclidean_division_definition (v x8) (pow2 24) }
v x8 * pow2 200;
}
val lemma_div248_x9: x9:uint64{v x9 < pow2 24} ->
Lemma (pow2 32 * (v x9 % pow2 24) * pow2 224 == v x9 * pow2 256)
let lemma_div248_x9 x9 =
calc (==) {
pow2 32 * (v x9 % pow2 24) * pow2 224;
(==) { Math.Lemmas.small_mod (v x9) (pow2 24) }
pow2 32 * v x9 * pow2 224;
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
v x9 * pow2 256;
}
val lemma_wide_as_nat_pow512: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 512)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
v x9 < pow2 24))
let lemma_wide_as_nat_pow512 x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert_norm (pow2 504 * pow2 8 = pow2 512);
FStar.Math.Lemmas.pow2_minus 512 504;
assert (v x9 < pow2 8);
assert_norm (pow2 8 < pow2 24)
val lemma_div248: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 512)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
let z0 = v x4 / pow2 24 + pow2 32 * (v x5 % pow2 24) in
let z1 = v x5 / pow2 24 + pow2 32 * (v x6 % pow2 24) in
let z2 = v x6 / pow2 24 + pow2 32 * (v x7 % pow2 24) in
let z3 = v x7 / pow2 24 + pow2 32 * (v x8 % pow2 24) in
let z4 = v x8 / pow2 24 + pow2 32 * (v x9 % pow2 24) in
wide_as_nat5 x / pow2 248 == z0 + z1 * pow2 56 + z2 * pow2 112 + z3 * pow2 168 + z4 * pow2 224))
#push-options "--z3rlimit 50"
let lemma_div248 x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
lemma_wide_as_nat_pow512 x;
assert (v x9 < pow2 24);
calc (==) {
(let z0 = v x4 / pow2 24 + pow2 32 * (v x5 % pow2 24) in
let z1 = v x5 / pow2 24 + pow2 32 * (v x6 % pow2 24) in
let z2 = v x6 / pow2 24 + pow2 32 * (v x7 % pow2 24) in
let z3 = v x7 / pow2 24 + pow2 32 * (v x8 % pow2 24) in
let z4 = v x8 / pow2 24 + pow2 32 * (v x9 % pow2 24) in
z0 + z1 * pow2 56 + z2 * pow2 112 + z3 * pow2 168 + z4 * pow2 224);
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
v x4 / pow2 24 + pow2 32 * (v x5 % pow2 24) +
v x5 / pow2 24 * pow2 56 + pow2 32 * (v x6 % pow2 24) * pow2 56 +
v x6 / pow2 24 * pow2 112 + pow2 32 * (v x7 % pow2 24) * pow2 112 +
v x7 / pow2 24 * pow2 168 + pow2 32 * (v x8 % pow2 24) * pow2 168 +
v x8 / pow2 24 * pow2 224 + pow2 32 * (v x9 % pow2 24) * pow2 224;
(==) { lemma_div248_x5 x5; lemma_div248_x6 x6 }
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 +
pow2 32 * (v x7 % pow2 24) * pow2 112 +
v x7 / pow2 24 * pow2 168 + pow2 32 * (v x8 % pow2 24) * pow2 168 +
v x8 / pow2 24 * pow2 224 + pow2 32 * (v x9 % pow2 24) * pow2 224;
(==) { lemma_div248_x7 x7; lemma_div248_x8 x8 }
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 +
pow2 32 * (v x9 % pow2 24) * pow2 224;
(==) { lemma_div248_x9 x9 }
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256;
(==) { lemma_div248_aux x }
wide_as_nat5 x / pow2 248;
}
#pop-options
val lemma_add_modq5:
x:qelem5
-> y:qelem5
-> t:qelem5 ->
Lemma
(requires
qelem_fits5 x (1, 1, 1, 1, 1) /\
qelem_fits5 y (1, 1, 1, 1, 1) /\
qelem_fits5 t (1, 1, 1, 1, 1) /\
as_nat5 x < S.q /\ as_nat5 y < S.q /\
as_nat5 t == as_nat5 x + as_nat5 y)
(ensures
(let res = if as_nat5 t >= S.q then as_nat5 t - S.q else as_nat5 t in
res < S.q /\ res == (as_nat5 x + as_nat5 y) % S.q))
let lemma_add_modq5 x y t =
assert (as_nat5 t == as_nat5 x + as_nat5 y);
let res = if as_nat5 t >= S.q then as_nat5 t - S.q else as_nat5 t in
assert (res < S.q);
if as_nat5 t >= S.q then (
FStar.Math.Lemmas.sub_div_mod_1 (as_nat5 t) S.q;
assert (res % S.q == as_nat5 t % S.q))
else
assert (res % S.q == as_nat5 t % S.q);
FStar.Math.Lemmas.small_mod res S.q
val lemma_wide_as_nat_pow528: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 528)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
v x9 < pow2 40)) | {
"checked_file": "/",
"dependencies": [
"Spec.Ed25519.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.BignumQ.Definitions.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Tactics.CanonCommSemiring.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.BignumQ.Lemmas.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.CanonCommSemiring",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.BignumQ.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.Ed25519",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.CanonCommSemiring",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.BignumQ",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.BignumQ",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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 | x: Hacl.Spec.BignumQ.Definitions.qelem_wide5
-> FStar.Pervasives.Lemma
(requires
Hacl.Spec.BignumQ.Definitions.qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
Hacl.Spec.BignumQ.Definitions.wide_as_nat5 x < Prims.pow2 528)
(ensures
(let _ = x in
(let FStar.Pervasives.Native.Mktuple10 #_ #_ #_ #_ #_ #_ #_ #_ #_ #_ _ _ _ _ _ _ _ _ _ x9
=
_
in
Lib.IntTypes.v x9 < Prims.pow2 40)
<:
Type0)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Hacl.Spec.BignumQ.Definitions.qelem_wide5",
"Lib.IntTypes.uint64",
"FStar.Pervasives.assert_norm",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.pow2",
"Prims.unit",
"Prims._assert",
"Lib.IntTypes.v",
"Lib.IntTypes.U64",
"Lib.IntTypes.SEC",
"FStar.Math.Lemmas.pow2_minus",
"Prims.op_Equality",
"Prims.int",
"FStar.Mul.op_Star"
] | [] | false | false | true | false | false | let lemma_wide_as_nat_pow528 x =
| let x0, x1, x2, x3, x4, x5, x6, x7, x8, x9 = x in
assert_norm (pow2 504 * pow2 24 = pow2 528);
FStar.Math.Lemmas.pow2_minus 528 504;
assert (v x9 < pow2 24);
assert_norm (pow2 24 < pow2 40) | false |
Hacl.Spec.BignumQ.Lemmas.fst | Hacl.Spec.BignumQ.Lemmas.lemma_as_nat_pow264 | val lemma_as_nat_pow264: x:qelem5 ->
Lemma
(requires
(let (x0, x1, x2, x3, x4) = x in
qelem_fits5 x (1, 1, 1, 1, 1) /\
v x4 < pow2 40))
(ensures as_nat5 x < pow2 264) | val lemma_as_nat_pow264: x:qelem5 ->
Lemma
(requires
(let (x0, x1, x2, x3, x4) = x in
qelem_fits5 x (1, 1, 1, 1, 1) /\
v x4 < pow2 40))
(ensures as_nat5 x < pow2 264) | let lemma_as_nat_pow264 x =
let (x0, x1, x2, x3, x4) = x in
assert_norm (pow2 40 * pow2 224 = pow2 264) | {
"file_name": "code/ed25519/Hacl.Spec.BignumQ.Lemmas.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 45,
"end_line": 513,
"start_col": 0,
"start_line": 511
} | module Hacl.Spec.BignumQ.Lemmas
open FStar.Tactics.CanonCommSemiring
open FStar.Mul
open Lib.IntTypes
module S = Spec.Ed25519
include Hacl.Spec.BignumQ.Definitions
let feq (#a #b:Type) (f:(a -> b)) (x y:a) :
Lemma (requires x == y) (ensures f x == f y) = ()
let eq_eq2 (#a:eqtype) (x y:a) :
Lemma (requires x = y) (ensures x == y) = ()
val lemma_mul_lt:a:nat -> b:nat -> c:nat -> d:nat ->
Lemma
(requires a < b /\ c < d)
(ensures a * c < b * d)
let lemma_mul_lt a b c d = ()
val lemma_as_nat5: f:qelem5 ->
Lemma
(requires qelem_fits5 f (1, 1, 1, 1, 1))
(ensures as_nat5 f < pow2 280)
let lemma_as_nat5 f =
//let (f0, f1, f2, f3, f4) = f in
//assert (as_nat5 f == v f0 + v f1 * pow56 + v f2 * pow112 + v f3 * pow168 + v f4 * pow224);
assert_norm (pow2 56 * pow2 56 = pow2 112);
assert_norm (pow2 56 * pow2 112 = pow2 168);
assert_norm (pow2 56 * pow2 168 = pow2 224);
assert_norm (pow2 56 * pow2 224 = pow2 280)
val lemma_choose_step:
bit:uint64{v bit <= 1}
-> x:uint64
-> y:uint64
-> Lemma
(let mask = bit -. u64 1 in
let z = x ^. (mask &. (x ^. y)) in
if v bit = 1 then z == x else z == y)
let lemma_choose_step bit p1 p2 =
let mask = bit -. u64 1 in
assert (v bit == 0 ==> v mask == pow2 64 - 1);
assert (v bit == 1 ==> v mask == 0);
let dummy = mask &. (p1 ^. p2) in
logand_lemma mask (p1 ^. p2);
assert (v bit == 1 ==> v dummy == 0);
assert (v bit == 0 ==> v dummy == v (p1 ^. p2));
let p1' = p1 ^. dummy in
assert (v dummy == v (if v bit = 1 then u64 0 else (p1 ^. p2)));
logxor_lemma p1 p2
val lemma_subm_conditional:
x0:nat -> x1:nat -> x2:nat -> x3:nat -> x4:nat
-> y0:nat -> y1:nat -> y2:nat -> y3:nat -> y4:nat
-> b0:nat -> b1:nat -> b2:nat -> b3:nat -> b4:nat ->
Lemma (
x0 - y0 + b0 * pow2 56 +
(x1 - y1 - b0 + b1 * pow2 56) * pow2 56 +
(x2 - y2 - b1 + b2 * pow2 56) * pow2 112 +
(x3 - y3 - b2 + b3 * pow2 56) * pow2 168 +
(x4 - y4 - b3 + b4 * pow2 56) * pow2 224 ==
(x0 + x1 * pow2 56 + x2 * pow2 112 + x3 * pow2 168 + x4 * pow2 224) -
(y0 + y1 * pow2 56 + y2 * pow2 112 + y3 * pow2 168 + y4 * pow2 224) + b4 * pow2 280)
let lemma_subm_conditional x0 x1 x2 x3 x4 y0 y1 y2 y3 y4 b0 b1 b2 b3 b4 =
assert_norm (pow2 56 * pow2 56 = pow2 112);
assert_norm (pow2 56 * pow2 112 = pow2 168);
assert_norm (pow2 56 * pow2 168 = pow2 224);
assert_norm (pow2 56 * pow2 224 = pow2 280);
assert (
x0 - y0 + b0 * pow2 56 +
(x1 - y1 - b0 + b1 * pow2 56) * pow2 56 +
(x2 - y2 - b1 + b2 * pow2 56) * pow2 112 +
(x3 - y3 - b2 + b3 * pow2 56) * pow2 168 +
(x4 - y4 - b3 + b4 * pow2 56) * pow2 224 ==
(x0 + x1 * pow2 56 + x2 * pow2 112 + x3 * pow2 168 + x4 * pow2 224) -
(y0 + y1 * pow2 56 + y2 * pow2 112 + y3 * pow2 168 + y4 * pow2 224) + b4 * pow2 280)
by (int_semiring ());
()
val lemma_div224: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1))
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
wide_as_nat5 x / pow2 224 ==
v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280))
#push-options "--z3rlimit 50"
let lemma_div224 x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert
(wide_as_nat5 x ==
v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168 + v x4 * pow2 224 +
v x5 * pow2 280 + v x6 * pow2 336 + v x7 * pow2 392 + v x8 * pow2 448 + v x9 * pow2 504);
assert_norm (pow2 56 * pow2 224 == pow2 280);
assert_norm (pow2 112 * pow2 224 == pow2 336);
assert_norm (pow2 168 * pow2 224 == pow2 392);
assert_norm (pow2 224 * pow2 224 == pow2 448);
assert_norm (pow2 280 * pow2 224 == pow2 504);
calc (==) {
wide_as_nat5 x / pow2 224;
(==) { }
(v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168 +
(v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280) * pow2 224) / pow2 224;
(==) {
FStar.Math.Lemmas.lemma_div_plus
(v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168)
(v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280) (pow2 224) }
(v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168) / pow2 224 +
v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280;
(==) { FStar.Math.Lemmas.small_division_lemma_1 (v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168) (pow2 224) }
v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280;
}
#pop-options
val lemma_div248_aux: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 512)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
wide_as_nat5 x / pow2 248 ==
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256))
open FStar.Tactics.CanonCommSemiring
#push-options "--z3cliopt smt.arith.nl=false"
let lemma_div248_aux x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert_norm (pow2 248 == pow2 224 * pow2 24);
assert_norm (pow2 56 == pow2 32 * pow2 24);
assert_norm (pow2 112 == pow2 88 * pow2 24);
assert_norm (pow2 168 == pow2 144 * pow2 24);
assert_norm (pow2 224 == pow2 200 * pow2 24);
assert_norm (pow2 280 == pow2 256 * pow2 24);
assert_norm (0 < pow2 24);
calc (==) {
wide_as_nat5 x / pow2 248;
(==) { FStar.Math.Lemmas.division_multiplication_lemma (wide_as_nat5 x) (pow2 224) (pow2 24) }
(wide_as_nat5 x / pow2 224) / pow2 24;
(==) { lemma_div224 x }
(v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280) / pow2 24;
(==) { _ by (Tactics.mapply (`feq #int #int (fun x -> x / pow2 24)); int_semiring ()) } (v x4 + (v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256) * pow2 24) / pow2 24;
(==) { FStar.Math.Lemmas.lemma_div_plus (v x4) (v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256) (pow2 24) }
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256;
}
#pop-options
val lemma_div248_x5: x5:uint64 ->
Lemma ( pow2 32 * (v x5 % pow2 24) + v x5 / pow2 24 * pow2 56 == v x5 * pow2 32)
let lemma_div248_x5 x5 =
assert_norm (pow2 32 * pow2 24 = pow2 56)
val lemma_div248_x6: x6:uint64 ->
Lemma (pow2 32 * (v x6 % pow2 24) * pow2 56 + v x6 / pow2 24 * pow2 112 == v x6 * pow2 88)
let lemma_div248_x6 x6 =
calc (==) {
pow2 32 * (v x6 % pow2 24) * pow2 56 + v x6 / pow2 24 * pow2 112;
(==) { _ by (Tactics.norm [delta_only [`%pow2]; primops]; int_semiring ()) }
((v x6 / pow2 24) * pow2 24 + v x6 % pow2 24) * pow2 88;
(==) { FStar.Math.Lemmas.euclidean_division_definition (v x6) (pow2 24) }
v x6 * pow2 88;
}
val lemma_div248_x7: x7:uint64 ->
Lemma (pow2 32 * (v x7 % pow2 24) * pow2 112 + v x7 / pow2 24 * pow2 168 == v x7 * pow2 144)
let lemma_div248_x7 x7 =
calc (==) {
pow2 32 * (v x7 % pow2 24) * pow2 112 + v x7 / pow2 24 * pow2 168;
(==) { _ by (Tactics.norm [delta_only [`%pow2]; primops]; int_semiring ()) }
((v x7 / pow2 24) * pow2 24 + v x7 % pow2 24) * pow2 144;
(==) { FStar.Math.Lemmas.euclidean_division_definition (v x7) (pow2 24) }
v x7 * pow2 144;
}
val lemma_div248_x8: x8:uint64 ->
Lemma (pow2 32 * (v x8 % pow2 24) * pow2 168 + v x8 / pow2 24 * pow2 224 == v x8 * pow2 200)
let lemma_div248_x8 x8 =
calc (==) {
pow2 32 * (v x8 % pow2 24) * pow2 168 + v x8 / pow2 24 * pow2 224;
(==) { _ by (Tactics.norm [delta_only [`%pow2]; primops]; int_semiring ()) }
((v x8 / pow2 24) * pow2 24 + v x8 % pow2 24) * pow2 200;
(==) { FStar.Math.Lemmas.euclidean_division_definition (v x8) (pow2 24) }
v x8 * pow2 200;
}
val lemma_div248_x9: x9:uint64{v x9 < pow2 24} ->
Lemma (pow2 32 * (v x9 % pow2 24) * pow2 224 == v x9 * pow2 256)
let lemma_div248_x9 x9 =
calc (==) {
pow2 32 * (v x9 % pow2 24) * pow2 224;
(==) { Math.Lemmas.small_mod (v x9) (pow2 24) }
pow2 32 * v x9 * pow2 224;
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
v x9 * pow2 256;
}
val lemma_wide_as_nat_pow512: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 512)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
v x9 < pow2 24))
let lemma_wide_as_nat_pow512 x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert_norm (pow2 504 * pow2 8 = pow2 512);
FStar.Math.Lemmas.pow2_minus 512 504;
assert (v x9 < pow2 8);
assert_norm (pow2 8 < pow2 24)
val lemma_div248: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 512)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
let z0 = v x4 / pow2 24 + pow2 32 * (v x5 % pow2 24) in
let z1 = v x5 / pow2 24 + pow2 32 * (v x6 % pow2 24) in
let z2 = v x6 / pow2 24 + pow2 32 * (v x7 % pow2 24) in
let z3 = v x7 / pow2 24 + pow2 32 * (v x8 % pow2 24) in
let z4 = v x8 / pow2 24 + pow2 32 * (v x9 % pow2 24) in
wide_as_nat5 x / pow2 248 == z0 + z1 * pow2 56 + z2 * pow2 112 + z3 * pow2 168 + z4 * pow2 224))
#push-options "--z3rlimit 50"
let lemma_div248 x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
lemma_wide_as_nat_pow512 x;
assert (v x9 < pow2 24);
calc (==) {
(let z0 = v x4 / pow2 24 + pow2 32 * (v x5 % pow2 24) in
let z1 = v x5 / pow2 24 + pow2 32 * (v x6 % pow2 24) in
let z2 = v x6 / pow2 24 + pow2 32 * (v x7 % pow2 24) in
let z3 = v x7 / pow2 24 + pow2 32 * (v x8 % pow2 24) in
let z4 = v x8 / pow2 24 + pow2 32 * (v x9 % pow2 24) in
z0 + z1 * pow2 56 + z2 * pow2 112 + z3 * pow2 168 + z4 * pow2 224);
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
v x4 / pow2 24 + pow2 32 * (v x5 % pow2 24) +
v x5 / pow2 24 * pow2 56 + pow2 32 * (v x6 % pow2 24) * pow2 56 +
v x6 / pow2 24 * pow2 112 + pow2 32 * (v x7 % pow2 24) * pow2 112 +
v x7 / pow2 24 * pow2 168 + pow2 32 * (v x8 % pow2 24) * pow2 168 +
v x8 / pow2 24 * pow2 224 + pow2 32 * (v x9 % pow2 24) * pow2 224;
(==) { lemma_div248_x5 x5; lemma_div248_x6 x6 }
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 +
pow2 32 * (v x7 % pow2 24) * pow2 112 +
v x7 / pow2 24 * pow2 168 + pow2 32 * (v x8 % pow2 24) * pow2 168 +
v x8 / pow2 24 * pow2 224 + pow2 32 * (v x9 % pow2 24) * pow2 224;
(==) { lemma_div248_x7 x7; lemma_div248_x8 x8 }
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 +
pow2 32 * (v x9 % pow2 24) * pow2 224;
(==) { lemma_div248_x9 x9 }
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256;
(==) { lemma_div248_aux x }
wide_as_nat5 x / pow2 248;
}
#pop-options
val lemma_add_modq5:
x:qelem5
-> y:qelem5
-> t:qelem5 ->
Lemma
(requires
qelem_fits5 x (1, 1, 1, 1, 1) /\
qelem_fits5 y (1, 1, 1, 1, 1) /\
qelem_fits5 t (1, 1, 1, 1, 1) /\
as_nat5 x < S.q /\ as_nat5 y < S.q /\
as_nat5 t == as_nat5 x + as_nat5 y)
(ensures
(let res = if as_nat5 t >= S.q then as_nat5 t - S.q else as_nat5 t in
res < S.q /\ res == (as_nat5 x + as_nat5 y) % S.q))
let lemma_add_modq5 x y t =
assert (as_nat5 t == as_nat5 x + as_nat5 y);
let res = if as_nat5 t >= S.q then as_nat5 t - S.q else as_nat5 t in
assert (res < S.q);
if as_nat5 t >= S.q then (
FStar.Math.Lemmas.sub_div_mod_1 (as_nat5 t) S.q;
assert (res % S.q == as_nat5 t % S.q))
else
assert (res % S.q == as_nat5 t % S.q);
FStar.Math.Lemmas.small_mod res S.q
val lemma_wide_as_nat_pow528: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 528)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
v x9 < pow2 40))
let lemma_wide_as_nat_pow528 x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert_norm (pow2 504 * pow2 24 = pow2 528);
FStar.Math.Lemmas.pow2_minus 528 504;
assert (v x9 < pow2 24);
assert_norm (pow2 24 < pow2 40)
#push-options "--z3cliopt smt.arith.nl=false"
val lemma_div264_aux: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 528)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
wide_as_nat5 x / pow2 264 ==
v x4 / pow2 40 + v x5 * pow2 16 + v x6 * pow2 72 + v x7 * pow2 128 + v x8 * pow2 184 + v x9 * pow2 240))
let lemma_div264_aux x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert_norm (pow2 264 == pow2 224 * pow2 40);
assert_norm (pow2 56 == pow2 16 * pow2 40);
assert_norm (pow2 112 == pow2 72 * pow2 40);
assert_norm (pow2 168 == pow2 128 * pow2 40);
assert_norm (pow2 224 == pow2 184 * pow2 40);
assert_norm (pow2 280 == pow2 240 * pow2 40);
assert_norm (0 < pow2 40);
calc (==) {
wide_as_nat5 x / pow2 264;
(==) { FStar.Math.Lemmas.division_multiplication_lemma (wide_as_nat5 x) (pow2 224) (pow2 40) }
(wide_as_nat5 x / pow2 224) / pow2 40;
(==) { lemma_div224 x }
(v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280) / pow2 40;
(==) { _ by (Tactics.mapply (`feq #int #int (fun x -> x / pow2 40)); int_semiring ()) }
(v x4 + (v x5 * pow2 16 + v x6 * pow2 72 + v x7 * pow2 128 + v x8 * pow2 184 + v x9 * pow2 240) * pow2 40) / pow2 40;
(==) { FStar.Math.Lemmas.lemma_div_plus (v x4) (v x5 * pow2 16 + v x6 * pow2 72 + v x7 * pow2 128 + v x8 * pow2 184 + v x9 * pow2 240) (pow2 40) }
v x4 / pow2 40 + v x5 * pow2 16 + v x6 * pow2 72 + v x7 * pow2 128 + v x8 * pow2 184 + v x9 * pow2 240;
}
val lemma_div264_x5: x5:uint64 ->
Lemma (pow2 16 * (v x5 % pow2 40) + v x5 / pow2 40 * pow2 56 == v x5 * pow2 16)
let lemma_div264_x5 x5 =
assert_norm (0 < pow2 24);
calc (==) {
pow2 16 * (v x5 % pow2 40) + v x5 / pow2 40 * pow2 56;
(==) { _ by (Tactics.norm [delta_only [`%pow2]; primops]; int_semiring ()) }
((v x5 / pow2 40) * pow2 40 + v x5 % pow2 40) * pow2 16;
(==) { FStar.Math.Lemmas.euclidean_division_definition (v x5) (pow2 40) }
v x5 * pow2 16;
}
val lemma_div264_x6: x6:uint64 ->
Lemma (pow2 16 * (v x6 % pow2 40) * pow2 56 + v x6 / pow2 40 * pow2 112 == v x6 * pow2 72)
let lemma_div264_x6 x6 =
calc (==) {
pow2 16 * (v x6 % pow2 40) * pow2 56 + v x6 / pow2 40 * pow2 112;
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
((v x6 / pow2 40) * pow2 40 + v x6 % pow2 40) * pow2 72;
(==) { Math.Lemmas.euclidean_division_definition (v x6) (pow2 40) }
v x6 * pow2 72;
}
val lemma_div264_x7: x7:uint64 ->
Lemma (pow2 16 * (v x7 % pow2 40) * pow2 112 + v x7 / pow2 40 * pow2 168 == v x7 * pow2 128)
let lemma_div264_x7 x7 =
calc (==) {
pow2 16 * (v x7 % pow2 40) * pow2 112 + v x7 / pow2 40 * pow2 168;
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
((v x7 / pow2 40) * pow2 40 + v x7 % pow2 40) * pow2 128;
(==) { Math.Lemmas.euclidean_division_definition (v x7) (pow2 40) }
v x7 * pow2 128;
}
val lemma_div264_x8: x8:uint64 ->
Lemma (pow2 16 * (v x8 % pow2 40) * pow2 168 + v x8 / pow2 40 * pow2 224 == v x8 * pow2 184)
let lemma_div264_x8 x8 =
calc (==) {
pow2 16 * (v x8 % pow2 40) * pow2 168 + v x8 / pow2 40 * pow2 224;
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
((v x8 / pow2 40) * pow2 40 + v x8 % pow2 40) * pow2 184;
(==) { Math.Lemmas.euclidean_division_definition (v x8) (pow2 40) }
v x8 * pow2 184;
}
val lemma_div264_x9: x9:uint64{v x9 < pow2 40} ->
Lemma (pow2 16 * (v x9 % pow2 40) * pow2 224 == v x9 * pow2 240)
let lemma_div264_x9 x9 =
calc (==) {
pow2 16 * (v x9 % pow2 40) * pow2 224;
(==) { Math.Lemmas.small_mod (v x9) (pow2 40) }
pow2 16 * v x9 * pow2 224;
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
v x9 * pow2 240;
}
val lemma_div264: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 528)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
let z0 = v x4 / pow2 40 + pow2 16 * (v x5 % pow2 40) in
let z1 = v x5 / pow2 40 + pow2 16 * (v x6 % pow2 40) in
let z2 = v x6 / pow2 40 + pow2 16 * (v x7 % pow2 40) in
let z3 = v x7 / pow2 40 + pow2 16 * (v x8 % pow2 40) in
let z4 = v x8 / pow2 40 + pow2 16 * (v x9 % pow2 40) in
wide_as_nat5 x / pow2 264 == z0 + z1 * pow2 56 + z2 * pow2 112 + z3 * pow2 168 + z4 * pow2 224))
#push-options "--z3rlimit 50"
let lemma_div264 x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
lemma_wide_as_nat_pow528 x;
assert (v x9 < pow2 40);
calc (==) {
(let z0 = v x4 / pow2 40 + pow2 16 * (v x5 % pow2 40) in
let z1 = v x5 / pow2 40 + pow2 16 * (v x6 % pow2 40) in
let z2 = v x6 / pow2 40 + pow2 16 * (v x7 % pow2 40) in
let z3 = v x7 / pow2 40 + pow2 16 * (v x8 % pow2 40) in
let z4 = v x8 / pow2 40 + pow2 16 * (v x9 % pow2 40) in
z0 + z1 * pow2 56 + z2 * pow2 112 + z3 * pow2 168 + z4 * pow2 224);
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
v x4 / pow2 40 + pow2 16 * (v x5 % pow2 40) +
v x5 / pow2 40 * pow2 56 + pow2 16 * (v x6 % pow2 40) * pow2 56 +
v x6 / pow2 40 * pow2 112 + pow2 16 * (v x7 % pow2 40) * pow2 112 +
v x7 / pow2 40 * pow2 168 + pow2 16 * (v x8 % pow2 40) * pow2 168 +
v x8 / pow2 40 * pow2 224 + pow2 16 * (v x9 % pow2 40) * pow2 224;
(==) { lemma_div264_x5 x5; lemma_div264_x6 x6 }
v x4 / pow2 40 + v x5 * pow2 16 + v x6 * pow2 72 +
pow2 16 * (v x7 % pow2 40) * pow2 112 +
v x7 / pow2 40 * pow2 168 + pow2 16 * (v x8 % pow2 40) * pow2 168 +
v x8 / pow2 40 * pow2 224 + pow2 16 * (v x9 % pow2 40) * pow2 224;
(==) { lemma_div264_x7 x7; lemma_div264_x8 x8 }
v x4 / pow2 40 + v x5 * pow2 16 + v x6 * pow2 72 + v x7 * pow2 128 + v x8 * pow2 184 +
pow2 16 * (v x9 % pow2 40) * pow2 224;
(==) { lemma_div264_x9 x9 }
v x4 / pow2 40 + v x5 * pow2 16 + v x6 * pow2 72 + v x7 * pow2 128 + v x8 * pow2 184 + v x9 * pow2 240;
(==) { lemma_div264_aux x }
wide_as_nat5 x / pow2 264;
}
#pop-options
#pop-options // "--z3cliopt smt.arith.nl=false"
val lemma_mod_264_aux: t:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 t (1, 1, 1, 1, 1, 1, 1, 1, 1, 1))
(ensures
(let (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) = t in
(wide_as_nat5 t) % pow2 264 ==
(v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + v t4 * pow2 224) % pow2 264))
#push-options "--z3rlimit 150"
let lemma_mod_264_aux t =
let (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) = t in
let res = (t0, t1, t2, t3, t4 &. u64 0xffffffffff) in
assert_norm (pow2 16 * pow2 264 == pow2 280);
assert_norm (pow2 72 * pow2 264 == pow2 336);
assert_norm (pow2 128 * pow2 264 == pow2 392);
assert_norm (pow2 184 * pow2 264 == pow2 448);
assert_norm (pow2 240 * pow2 264 == pow2 504);
calc (==) {
(wide_as_nat5 t) % pow2 264;
(==) { }
(v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + v t4 * pow2 224 +
(v t5 * pow2 16 + v t6 * pow2 72 + v t7 * pow2 128 + v t8 * pow2 184 + v t9 * pow2 240) * pow2 264) % pow2 264;
(==) { FStar.Math.Lemmas.lemma_mod_add_distr (v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + v t4 * pow2 224)
((v t5 * pow2 16 + v t6 * pow2 72 + v t7 * pow2 128 + v t8 * pow2 184 + v t9 * pow2 240) * pow2 264) (pow2 264)}
((v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + v t4 * pow2 224) +
((v t5 * pow2 16 + v t6 * pow2 72 + v t7 * pow2 128 + v t8 * pow2 184 + v t9 * pow2 240) * pow2 264) % pow2 264) % pow2 264;
(==) { FStar.Math.Lemmas.cancel_mul_mod (v t5 * pow2 16 + v t6 * pow2 72 + v t7 * pow2 128 + v t8 * pow2 184 + v t9 * pow2 240) (pow2 264) }
(v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + v t4 * pow2 224) % pow2 264;
}
#pop-options
val lemma_as_nat_pow264: x:qelem5 ->
Lemma
(requires
(let (x0, x1, x2, x3, x4) = x in
qelem_fits5 x (1, 1, 1, 1, 1) /\
v x4 < pow2 40))
(ensures as_nat5 x < pow2 264) | {
"checked_file": "/",
"dependencies": [
"Spec.Ed25519.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.BignumQ.Definitions.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Tactics.CanonCommSemiring.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.BignumQ.Lemmas.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.CanonCommSemiring",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.BignumQ.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.Ed25519",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.CanonCommSemiring",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.BignumQ",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.BignumQ",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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 | x: Hacl.Spec.BignumQ.Definitions.qelem5
-> FStar.Pervasives.Lemma
(requires
(let _ = x in
(let FStar.Pervasives.Native.Mktuple5 #_ #_ #_ #_ #_ _ _ _ _ x4 = _ in
Hacl.Spec.BignumQ.Definitions.qelem_fits5 x (1, 1, 1, 1, 1) /\
Lib.IntTypes.v x4 < Prims.pow2 40)
<:
Type0)) (ensures Hacl.Spec.BignumQ.Definitions.as_nat5 x < Prims.pow2 264) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Hacl.Spec.BignumQ.Definitions.qelem5",
"Lib.IntTypes.uint64",
"FStar.Pervasives.assert_norm",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"FStar.Mul.op_Star",
"Prims.pow2",
"Prims.unit"
] | [] | false | false | true | false | false | let lemma_as_nat_pow264 x =
| let x0, x1, x2, x3, x4 = x in
assert_norm (pow2 40 * pow2 224 = pow2 264) | false |
SfBasic.fst | SfBasic.next_weekday | val next_weekday : day -> Tot day | val next_weekday : day -> Tot day | let next_weekday d =
match d with
| Monday -> Tuesday
| Tuesday -> Wednesday
| Wednesday -> Thursday
| Thursday -> Friday
| Friday -> Monday
| Saturday -> Monday
| Sunday -> Monday | {
"file_name": "examples/software_foundations/SfBasic.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 23,
"end_line": 41,
"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.
*)
(*
A translation to F* of Basics.v from Software Foundations
Original name: "Basics: Functional Programming in Coq"
*)
module SfBasic
type day =
| Monday
| Tuesday
| Wednesday
| Thursday
| Friday
| Saturday
| Sunday | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "SfBasic.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | d: SfBasic.day -> SfBasic.day | Prims.Tot | [
"total"
] | [] | [
"SfBasic.day",
"SfBasic.Tuesday",
"SfBasic.Wednesday",
"SfBasic.Thursday",
"SfBasic.Friday",
"SfBasic.Monday"
] | [] | false | false | false | true | false | let next_weekday d =
| match d with
| Monday -> Tuesday
| Tuesday -> Wednesday
| Wednesday -> Thursday
| Thursday -> Friday
| Friday -> Monday
| Saturday -> Monday
| Sunday -> Monday | false |
Hacl.Spec.BignumQ.Lemmas.fst | Hacl.Spec.BignumQ.Lemmas.lemma_wide_as_nat_pow512 | val lemma_wide_as_nat_pow512: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 512)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
v x9 < pow2 24)) | val lemma_wide_as_nat_pow512: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 512)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
v x9 < pow2 24)) | let lemma_wide_as_nat_pow512 x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert_norm (pow2 504 * pow2 8 = pow2 512);
FStar.Math.Lemmas.pow2_minus 512 504;
assert (v x9 < pow2 8);
assert_norm (pow2 8 < pow2 24) | {
"file_name": "code/ed25519/Hacl.Spec.BignumQ.Lemmas.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 32,
"end_line": 229,
"start_col": 0,
"start_line": 224
} | module Hacl.Spec.BignumQ.Lemmas
open FStar.Tactics.CanonCommSemiring
open FStar.Mul
open Lib.IntTypes
module S = Spec.Ed25519
include Hacl.Spec.BignumQ.Definitions
let feq (#a #b:Type) (f:(a -> b)) (x y:a) :
Lemma (requires x == y) (ensures f x == f y) = ()
let eq_eq2 (#a:eqtype) (x y:a) :
Lemma (requires x = y) (ensures x == y) = ()
val lemma_mul_lt:a:nat -> b:nat -> c:nat -> d:nat ->
Lemma
(requires a < b /\ c < d)
(ensures a * c < b * d)
let lemma_mul_lt a b c d = ()
val lemma_as_nat5: f:qelem5 ->
Lemma
(requires qelem_fits5 f (1, 1, 1, 1, 1))
(ensures as_nat5 f < pow2 280)
let lemma_as_nat5 f =
//let (f0, f1, f2, f3, f4) = f in
//assert (as_nat5 f == v f0 + v f1 * pow56 + v f2 * pow112 + v f3 * pow168 + v f4 * pow224);
assert_norm (pow2 56 * pow2 56 = pow2 112);
assert_norm (pow2 56 * pow2 112 = pow2 168);
assert_norm (pow2 56 * pow2 168 = pow2 224);
assert_norm (pow2 56 * pow2 224 = pow2 280)
val lemma_choose_step:
bit:uint64{v bit <= 1}
-> x:uint64
-> y:uint64
-> Lemma
(let mask = bit -. u64 1 in
let z = x ^. (mask &. (x ^. y)) in
if v bit = 1 then z == x else z == y)
let lemma_choose_step bit p1 p2 =
let mask = bit -. u64 1 in
assert (v bit == 0 ==> v mask == pow2 64 - 1);
assert (v bit == 1 ==> v mask == 0);
let dummy = mask &. (p1 ^. p2) in
logand_lemma mask (p1 ^. p2);
assert (v bit == 1 ==> v dummy == 0);
assert (v bit == 0 ==> v dummy == v (p1 ^. p2));
let p1' = p1 ^. dummy in
assert (v dummy == v (if v bit = 1 then u64 0 else (p1 ^. p2)));
logxor_lemma p1 p2
val lemma_subm_conditional:
x0:nat -> x1:nat -> x2:nat -> x3:nat -> x4:nat
-> y0:nat -> y1:nat -> y2:nat -> y3:nat -> y4:nat
-> b0:nat -> b1:nat -> b2:nat -> b3:nat -> b4:nat ->
Lemma (
x0 - y0 + b0 * pow2 56 +
(x1 - y1 - b0 + b1 * pow2 56) * pow2 56 +
(x2 - y2 - b1 + b2 * pow2 56) * pow2 112 +
(x3 - y3 - b2 + b3 * pow2 56) * pow2 168 +
(x4 - y4 - b3 + b4 * pow2 56) * pow2 224 ==
(x0 + x1 * pow2 56 + x2 * pow2 112 + x3 * pow2 168 + x4 * pow2 224) -
(y0 + y1 * pow2 56 + y2 * pow2 112 + y3 * pow2 168 + y4 * pow2 224) + b4 * pow2 280)
let lemma_subm_conditional x0 x1 x2 x3 x4 y0 y1 y2 y3 y4 b0 b1 b2 b3 b4 =
assert_norm (pow2 56 * pow2 56 = pow2 112);
assert_norm (pow2 56 * pow2 112 = pow2 168);
assert_norm (pow2 56 * pow2 168 = pow2 224);
assert_norm (pow2 56 * pow2 224 = pow2 280);
assert (
x0 - y0 + b0 * pow2 56 +
(x1 - y1 - b0 + b1 * pow2 56) * pow2 56 +
(x2 - y2 - b1 + b2 * pow2 56) * pow2 112 +
(x3 - y3 - b2 + b3 * pow2 56) * pow2 168 +
(x4 - y4 - b3 + b4 * pow2 56) * pow2 224 ==
(x0 + x1 * pow2 56 + x2 * pow2 112 + x3 * pow2 168 + x4 * pow2 224) -
(y0 + y1 * pow2 56 + y2 * pow2 112 + y3 * pow2 168 + y4 * pow2 224) + b4 * pow2 280)
by (int_semiring ());
()
val lemma_div224: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1))
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
wide_as_nat5 x / pow2 224 ==
v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280))
#push-options "--z3rlimit 50"
let lemma_div224 x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert
(wide_as_nat5 x ==
v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168 + v x4 * pow2 224 +
v x5 * pow2 280 + v x6 * pow2 336 + v x7 * pow2 392 + v x8 * pow2 448 + v x9 * pow2 504);
assert_norm (pow2 56 * pow2 224 == pow2 280);
assert_norm (pow2 112 * pow2 224 == pow2 336);
assert_norm (pow2 168 * pow2 224 == pow2 392);
assert_norm (pow2 224 * pow2 224 == pow2 448);
assert_norm (pow2 280 * pow2 224 == pow2 504);
calc (==) {
wide_as_nat5 x / pow2 224;
(==) { }
(v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168 +
(v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280) * pow2 224) / pow2 224;
(==) {
FStar.Math.Lemmas.lemma_div_plus
(v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168)
(v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280) (pow2 224) }
(v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168) / pow2 224 +
v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280;
(==) { FStar.Math.Lemmas.small_division_lemma_1 (v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168) (pow2 224) }
v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280;
}
#pop-options
val lemma_div248_aux: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 512)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
wide_as_nat5 x / pow2 248 ==
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256))
open FStar.Tactics.CanonCommSemiring
#push-options "--z3cliopt smt.arith.nl=false"
let lemma_div248_aux x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert_norm (pow2 248 == pow2 224 * pow2 24);
assert_norm (pow2 56 == pow2 32 * pow2 24);
assert_norm (pow2 112 == pow2 88 * pow2 24);
assert_norm (pow2 168 == pow2 144 * pow2 24);
assert_norm (pow2 224 == pow2 200 * pow2 24);
assert_norm (pow2 280 == pow2 256 * pow2 24);
assert_norm (0 < pow2 24);
calc (==) {
wide_as_nat5 x / pow2 248;
(==) { FStar.Math.Lemmas.division_multiplication_lemma (wide_as_nat5 x) (pow2 224) (pow2 24) }
(wide_as_nat5 x / pow2 224) / pow2 24;
(==) { lemma_div224 x }
(v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280) / pow2 24;
(==) { _ by (Tactics.mapply (`feq #int #int (fun x -> x / pow2 24)); int_semiring ()) } (v x4 + (v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256) * pow2 24) / pow2 24;
(==) { FStar.Math.Lemmas.lemma_div_plus (v x4) (v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256) (pow2 24) }
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256;
}
#pop-options
val lemma_div248_x5: x5:uint64 ->
Lemma ( pow2 32 * (v x5 % pow2 24) + v x5 / pow2 24 * pow2 56 == v x5 * pow2 32)
let lemma_div248_x5 x5 =
assert_norm (pow2 32 * pow2 24 = pow2 56)
val lemma_div248_x6: x6:uint64 ->
Lemma (pow2 32 * (v x6 % pow2 24) * pow2 56 + v x6 / pow2 24 * pow2 112 == v x6 * pow2 88)
let lemma_div248_x6 x6 =
calc (==) {
pow2 32 * (v x6 % pow2 24) * pow2 56 + v x6 / pow2 24 * pow2 112;
(==) { _ by (Tactics.norm [delta_only [`%pow2]; primops]; int_semiring ()) }
((v x6 / pow2 24) * pow2 24 + v x6 % pow2 24) * pow2 88;
(==) { FStar.Math.Lemmas.euclidean_division_definition (v x6) (pow2 24) }
v x6 * pow2 88;
}
val lemma_div248_x7: x7:uint64 ->
Lemma (pow2 32 * (v x7 % pow2 24) * pow2 112 + v x7 / pow2 24 * pow2 168 == v x7 * pow2 144)
let lemma_div248_x7 x7 =
calc (==) {
pow2 32 * (v x7 % pow2 24) * pow2 112 + v x7 / pow2 24 * pow2 168;
(==) { _ by (Tactics.norm [delta_only [`%pow2]; primops]; int_semiring ()) }
((v x7 / pow2 24) * pow2 24 + v x7 % pow2 24) * pow2 144;
(==) { FStar.Math.Lemmas.euclidean_division_definition (v x7) (pow2 24) }
v x7 * pow2 144;
}
val lemma_div248_x8: x8:uint64 ->
Lemma (pow2 32 * (v x8 % pow2 24) * pow2 168 + v x8 / pow2 24 * pow2 224 == v x8 * pow2 200)
let lemma_div248_x8 x8 =
calc (==) {
pow2 32 * (v x8 % pow2 24) * pow2 168 + v x8 / pow2 24 * pow2 224;
(==) { _ by (Tactics.norm [delta_only [`%pow2]; primops]; int_semiring ()) }
((v x8 / pow2 24) * pow2 24 + v x8 % pow2 24) * pow2 200;
(==) { FStar.Math.Lemmas.euclidean_division_definition (v x8) (pow2 24) }
v x8 * pow2 200;
}
val lemma_div248_x9: x9:uint64{v x9 < pow2 24} ->
Lemma (pow2 32 * (v x9 % pow2 24) * pow2 224 == v x9 * pow2 256)
let lemma_div248_x9 x9 =
calc (==) {
pow2 32 * (v x9 % pow2 24) * pow2 224;
(==) { Math.Lemmas.small_mod (v x9) (pow2 24) }
pow2 32 * v x9 * pow2 224;
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
v x9 * pow2 256;
}
val lemma_wide_as_nat_pow512: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 512)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
v x9 < pow2 24)) | {
"checked_file": "/",
"dependencies": [
"Spec.Ed25519.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.BignumQ.Definitions.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Tactics.CanonCommSemiring.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.BignumQ.Lemmas.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.CanonCommSemiring",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.BignumQ.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.Ed25519",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.CanonCommSemiring",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.BignumQ",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.BignumQ",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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 | x: Hacl.Spec.BignumQ.Definitions.qelem_wide5
-> FStar.Pervasives.Lemma
(requires
Hacl.Spec.BignumQ.Definitions.qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
Hacl.Spec.BignumQ.Definitions.wide_as_nat5 x < Prims.pow2 512)
(ensures
(let _ = x in
(let FStar.Pervasives.Native.Mktuple10 #_ #_ #_ #_ #_ #_ #_ #_ #_ #_ _ _ _ _ _ _ _ _ _ x9
=
_
in
Lib.IntTypes.v x9 < Prims.pow2 24)
<:
Type0)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Hacl.Spec.BignumQ.Definitions.qelem_wide5",
"Lib.IntTypes.uint64",
"FStar.Pervasives.assert_norm",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.pow2",
"Prims.unit",
"Prims._assert",
"Lib.IntTypes.v",
"Lib.IntTypes.U64",
"Lib.IntTypes.SEC",
"FStar.Math.Lemmas.pow2_minus",
"Prims.op_Equality",
"Prims.int",
"FStar.Mul.op_Star"
] | [] | false | false | true | false | false | let lemma_wide_as_nat_pow512 x =
| let x0, x1, x2, x3, x4, x5, x6, x7, x8, x9 = x in
assert_norm (pow2 504 * pow2 8 = pow2 512);
FStar.Math.Lemmas.pow2_minus 512 504;
assert (v x9 < pow2 8);
assert_norm (pow2 8 < pow2 24) | false |
SfBasic.fst | SfBasic.orb | val orb : mbool -> mbool -> Tot mbool | val orb : mbool -> mbool -> Tot mbool | let orb b1 b2 =
match b1 with
| MTrue -> MTrue
| MFalse -> b2 | {
"file_name": "examples/software_foundations/SfBasic.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 16,
"end_line": 73,
"start_col": 0,
"start_line": 70
} | (*
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.
*)
(*
A translation to F* of Basics.v from Software Foundations
Original name: "Basics: Functional Programming in Coq"
*)
module SfBasic
type day =
| Monday
| Tuesday
| Wednesday
| Thursday
| Friday
| Saturday
| Sunday
val next_weekday : day -> Tot day
let next_weekday d =
match d with
| Monday -> Tuesday
| Tuesday -> Wednesday
| Wednesday -> Thursday
| Thursday -> Friday
| Friday -> Monday
| Saturday -> Monday
| Sunday -> Monday
val test_next_weekday : unit -> Lemma
(ensures ((next_weekday (next_weekday Saturday)) = Tuesday))
let test_next_weekday () = ()
(* Booleans *)
(* The original example calls these bool, True, and False,
and that doesn't seem to cause problems;
I've just renamed them to be 100% sure that's not the cause
of the troubles in this file *)
type mbool =
| MTrue
| MFalse
val negb : mbool -> Tot mbool
let negb b =
match b with
| MTrue -> MFalse
| MFalse -> MTrue
val andb : mbool -> mbool -> Tot mbool
let andb b1 b2 =
match b1 with
| MTrue -> b2
| MFalse -> MFalse | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "SfBasic.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | b1: SfBasic.mbool -> b2: SfBasic.mbool -> SfBasic.mbool | Prims.Tot | [
"total"
] | [] | [
"SfBasic.mbool",
"SfBasic.MTrue"
] | [] | false | false | false | true | false | let orb b1 b2 =
| match b1 with
| MTrue -> MTrue
| MFalse -> b2 | false |
SfBasic.fst | SfBasic.negb | val negb : mbool -> Tot mbool | val negb : mbool -> Tot mbool | let negb b =
match b with
| MTrue -> MFalse
| MFalse -> MTrue | {
"file_name": "examples/software_foundations/SfBasic.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 19,
"end_line": 61,
"start_col": 0,
"start_line": 58
} | (*
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.
*)
(*
A translation to F* of Basics.v from Software Foundations
Original name: "Basics: Functional Programming in Coq"
*)
module SfBasic
type day =
| Monday
| Tuesday
| Wednesday
| Thursday
| Friday
| Saturday
| Sunday
val next_weekday : day -> Tot day
let next_weekday d =
match d with
| Monday -> Tuesday
| Tuesday -> Wednesday
| Wednesday -> Thursday
| Thursday -> Friday
| Friday -> Monday
| Saturday -> Monday
| Sunday -> Monday
val test_next_weekday : unit -> Lemma
(ensures ((next_weekday (next_weekday Saturday)) = Tuesday))
let test_next_weekday () = ()
(* Booleans *)
(* The original example calls these bool, True, and False,
and that doesn't seem to cause problems;
I've just renamed them to be 100% sure that's not the cause
of the troubles in this file *)
type mbool =
| MTrue
| MFalse | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "SfBasic.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | b: SfBasic.mbool -> SfBasic.mbool | Prims.Tot | [
"total"
] | [] | [
"SfBasic.mbool",
"SfBasic.MFalse",
"SfBasic.MTrue"
] | [] | false | false | false | true | false | let negb b =
| match b with
| MTrue -> MFalse
| MFalse -> MTrue | false |
Hacl.Spec.BignumQ.Lemmas.fst | Hacl.Spec.BignumQ.Lemmas.lemma_sub_mod_264_aux | val lemma_sub_mod_264_aux:
x0:nat -> x1:nat -> x2:nat -> x3:nat -> x4:nat
-> y0:nat -> y1:nat -> y2:nat -> y3:nat -> y4:nat
-> c1:nat -> c2:nat -> c3:nat -> c4:nat -> c5:nat ->
Lemma (
x0 - y0 + c1 * pow56 +
(x1 - y1 - c1 + c2 * pow56) * pow56 +
(x2 - y2 - c2 + c3 * pow56) * pow112 +
(x3 - y3 - c3 + c4 * pow56) * pow168 +
(x4 - y4 - c4 + pow2 40 * c5) * pow224 ==
(x0 + x1 * pow2 56 + x2 * pow2 112 + x3 * pow2 168 + x4 * pow2 224) -
(y0 + y1 * pow2 56 + y2 * pow2 112 + y3 * pow2 168 + y4 * pow2 224) + c5 * pow2 264) | val lemma_sub_mod_264_aux:
x0:nat -> x1:nat -> x2:nat -> x3:nat -> x4:nat
-> y0:nat -> y1:nat -> y2:nat -> y3:nat -> y4:nat
-> c1:nat -> c2:nat -> c3:nat -> c4:nat -> c5:nat ->
Lemma (
x0 - y0 + c1 * pow56 +
(x1 - y1 - c1 + c2 * pow56) * pow56 +
(x2 - y2 - c2 + c3 * pow56) * pow112 +
(x3 - y3 - c3 + c4 * pow56) * pow168 +
(x4 - y4 - c4 + pow2 40 * c5) * pow224 ==
(x0 + x1 * pow2 56 + x2 * pow2 112 + x3 * pow2 168 + x4 * pow2 224) -
(y0 + y1 * pow2 56 + y2 * pow2 112 + y3 * pow2 168 + y4 * pow2 224) + c5 * pow2 264) | let lemma_sub_mod_264_aux x0 x1 x2 x3 x4 y0 y1 y2 y3 y4 b0 b1 b2 b3 b4 =
assert_norm (pow2 56 * pow2 56 = pow2 112);
assert_norm (pow2 56 * pow2 112 = pow2 168);
assert_norm (pow2 56 * pow2 168 = pow2 224);
assert_norm (pow2 40 * pow2 224 = pow2 264) | {
"file_name": "code/ed25519/Hacl.Spec.BignumQ.Lemmas.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 45,
"end_line": 581,
"start_col": 0,
"start_line": 577
} | module Hacl.Spec.BignumQ.Lemmas
open FStar.Tactics.CanonCommSemiring
open FStar.Mul
open Lib.IntTypes
module S = Spec.Ed25519
include Hacl.Spec.BignumQ.Definitions
let feq (#a #b:Type) (f:(a -> b)) (x y:a) :
Lemma (requires x == y) (ensures f x == f y) = ()
let eq_eq2 (#a:eqtype) (x y:a) :
Lemma (requires x = y) (ensures x == y) = ()
val lemma_mul_lt:a:nat -> b:nat -> c:nat -> d:nat ->
Lemma
(requires a < b /\ c < d)
(ensures a * c < b * d)
let lemma_mul_lt a b c d = ()
val lemma_as_nat5: f:qelem5 ->
Lemma
(requires qelem_fits5 f (1, 1, 1, 1, 1))
(ensures as_nat5 f < pow2 280)
let lemma_as_nat5 f =
//let (f0, f1, f2, f3, f4) = f in
//assert (as_nat5 f == v f0 + v f1 * pow56 + v f2 * pow112 + v f3 * pow168 + v f4 * pow224);
assert_norm (pow2 56 * pow2 56 = pow2 112);
assert_norm (pow2 56 * pow2 112 = pow2 168);
assert_norm (pow2 56 * pow2 168 = pow2 224);
assert_norm (pow2 56 * pow2 224 = pow2 280)
val lemma_choose_step:
bit:uint64{v bit <= 1}
-> x:uint64
-> y:uint64
-> Lemma
(let mask = bit -. u64 1 in
let z = x ^. (mask &. (x ^. y)) in
if v bit = 1 then z == x else z == y)
let lemma_choose_step bit p1 p2 =
let mask = bit -. u64 1 in
assert (v bit == 0 ==> v mask == pow2 64 - 1);
assert (v bit == 1 ==> v mask == 0);
let dummy = mask &. (p1 ^. p2) in
logand_lemma mask (p1 ^. p2);
assert (v bit == 1 ==> v dummy == 0);
assert (v bit == 0 ==> v dummy == v (p1 ^. p2));
let p1' = p1 ^. dummy in
assert (v dummy == v (if v bit = 1 then u64 0 else (p1 ^. p2)));
logxor_lemma p1 p2
val lemma_subm_conditional:
x0:nat -> x1:nat -> x2:nat -> x3:nat -> x4:nat
-> y0:nat -> y1:nat -> y2:nat -> y3:nat -> y4:nat
-> b0:nat -> b1:nat -> b2:nat -> b3:nat -> b4:nat ->
Lemma (
x0 - y0 + b0 * pow2 56 +
(x1 - y1 - b0 + b1 * pow2 56) * pow2 56 +
(x2 - y2 - b1 + b2 * pow2 56) * pow2 112 +
(x3 - y3 - b2 + b3 * pow2 56) * pow2 168 +
(x4 - y4 - b3 + b4 * pow2 56) * pow2 224 ==
(x0 + x1 * pow2 56 + x2 * pow2 112 + x3 * pow2 168 + x4 * pow2 224) -
(y0 + y1 * pow2 56 + y2 * pow2 112 + y3 * pow2 168 + y4 * pow2 224) + b4 * pow2 280)
let lemma_subm_conditional x0 x1 x2 x3 x4 y0 y1 y2 y3 y4 b0 b1 b2 b3 b4 =
assert_norm (pow2 56 * pow2 56 = pow2 112);
assert_norm (pow2 56 * pow2 112 = pow2 168);
assert_norm (pow2 56 * pow2 168 = pow2 224);
assert_norm (pow2 56 * pow2 224 = pow2 280);
assert (
x0 - y0 + b0 * pow2 56 +
(x1 - y1 - b0 + b1 * pow2 56) * pow2 56 +
(x2 - y2 - b1 + b2 * pow2 56) * pow2 112 +
(x3 - y3 - b2 + b3 * pow2 56) * pow2 168 +
(x4 - y4 - b3 + b4 * pow2 56) * pow2 224 ==
(x0 + x1 * pow2 56 + x2 * pow2 112 + x3 * pow2 168 + x4 * pow2 224) -
(y0 + y1 * pow2 56 + y2 * pow2 112 + y3 * pow2 168 + y4 * pow2 224) + b4 * pow2 280)
by (int_semiring ());
()
val lemma_div224: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1))
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
wide_as_nat5 x / pow2 224 ==
v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280))
#push-options "--z3rlimit 50"
let lemma_div224 x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert
(wide_as_nat5 x ==
v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168 + v x4 * pow2 224 +
v x5 * pow2 280 + v x6 * pow2 336 + v x7 * pow2 392 + v x8 * pow2 448 + v x9 * pow2 504);
assert_norm (pow2 56 * pow2 224 == pow2 280);
assert_norm (pow2 112 * pow2 224 == pow2 336);
assert_norm (pow2 168 * pow2 224 == pow2 392);
assert_norm (pow2 224 * pow2 224 == pow2 448);
assert_norm (pow2 280 * pow2 224 == pow2 504);
calc (==) {
wide_as_nat5 x / pow2 224;
(==) { }
(v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168 +
(v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280) * pow2 224) / pow2 224;
(==) {
FStar.Math.Lemmas.lemma_div_plus
(v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168)
(v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280) (pow2 224) }
(v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168) / pow2 224 +
v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280;
(==) { FStar.Math.Lemmas.small_division_lemma_1 (v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168) (pow2 224) }
v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280;
}
#pop-options
val lemma_div248_aux: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 512)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
wide_as_nat5 x / pow2 248 ==
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256))
open FStar.Tactics.CanonCommSemiring
#push-options "--z3cliopt smt.arith.nl=false"
let lemma_div248_aux x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert_norm (pow2 248 == pow2 224 * pow2 24);
assert_norm (pow2 56 == pow2 32 * pow2 24);
assert_norm (pow2 112 == pow2 88 * pow2 24);
assert_norm (pow2 168 == pow2 144 * pow2 24);
assert_norm (pow2 224 == pow2 200 * pow2 24);
assert_norm (pow2 280 == pow2 256 * pow2 24);
assert_norm (0 < pow2 24);
calc (==) {
wide_as_nat5 x / pow2 248;
(==) { FStar.Math.Lemmas.division_multiplication_lemma (wide_as_nat5 x) (pow2 224) (pow2 24) }
(wide_as_nat5 x / pow2 224) / pow2 24;
(==) { lemma_div224 x }
(v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280) / pow2 24;
(==) { _ by (Tactics.mapply (`feq #int #int (fun x -> x / pow2 24)); int_semiring ()) } (v x4 + (v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256) * pow2 24) / pow2 24;
(==) { FStar.Math.Lemmas.lemma_div_plus (v x4) (v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256) (pow2 24) }
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256;
}
#pop-options
val lemma_div248_x5: x5:uint64 ->
Lemma ( pow2 32 * (v x5 % pow2 24) + v x5 / pow2 24 * pow2 56 == v x5 * pow2 32)
let lemma_div248_x5 x5 =
assert_norm (pow2 32 * pow2 24 = pow2 56)
val lemma_div248_x6: x6:uint64 ->
Lemma (pow2 32 * (v x6 % pow2 24) * pow2 56 + v x6 / pow2 24 * pow2 112 == v x6 * pow2 88)
let lemma_div248_x6 x6 =
calc (==) {
pow2 32 * (v x6 % pow2 24) * pow2 56 + v x6 / pow2 24 * pow2 112;
(==) { _ by (Tactics.norm [delta_only [`%pow2]; primops]; int_semiring ()) }
((v x6 / pow2 24) * pow2 24 + v x6 % pow2 24) * pow2 88;
(==) { FStar.Math.Lemmas.euclidean_division_definition (v x6) (pow2 24) }
v x6 * pow2 88;
}
val lemma_div248_x7: x7:uint64 ->
Lemma (pow2 32 * (v x7 % pow2 24) * pow2 112 + v x7 / pow2 24 * pow2 168 == v x7 * pow2 144)
let lemma_div248_x7 x7 =
calc (==) {
pow2 32 * (v x7 % pow2 24) * pow2 112 + v x7 / pow2 24 * pow2 168;
(==) { _ by (Tactics.norm [delta_only [`%pow2]; primops]; int_semiring ()) }
((v x7 / pow2 24) * pow2 24 + v x7 % pow2 24) * pow2 144;
(==) { FStar.Math.Lemmas.euclidean_division_definition (v x7) (pow2 24) }
v x7 * pow2 144;
}
val lemma_div248_x8: x8:uint64 ->
Lemma (pow2 32 * (v x8 % pow2 24) * pow2 168 + v x8 / pow2 24 * pow2 224 == v x8 * pow2 200)
let lemma_div248_x8 x8 =
calc (==) {
pow2 32 * (v x8 % pow2 24) * pow2 168 + v x8 / pow2 24 * pow2 224;
(==) { _ by (Tactics.norm [delta_only [`%pow2]; primops]; int_semiring ()) }
((v x8 / pow2 24) * pow2 24 + v x8 % pow2 24) * pow2 200;
(==) { FStar.Math.Lemmas.euclidean_division_definition (v x8) (pow2 24) }
v x8 * pow2 200;
}
val lemma_div248_x9: x9:uint64{v x9 < pow2 24} ->
Lemma (pow2 32 * (v x9 % pow2 24) * pow2 224 == v x9 * pow2 256)
let lemma_div248_x9 x9 =
calc (==) {
pow2 32 * (v x9 % pow2 24) * pow2 224;
(==) { Math.Lemmas.small_mod (v x9) (pow2 24) }
pow2 32 * v x9 * pow2 224;
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
v x9 * pow2 256;
}
val lemma_wide_as_nat_pow512: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 512)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
v x9 < pow2 24))
let lemma_wide_as_nat_pow512 x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert_norm (pow2 504 * pow2 8 = pow2 512);
FStar.Math.Lemmas.pow2_minus 512 504;
assert (v x9 < pow2 8);
assert_norm (pow2 8 < pow2 24)
val lemma_div248: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 512)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
let z0 = v x4 / pow2 24 + pow2 32 * (v x5 % pow2 24) in
let z1 = v x5 / pow2 24 + pow2 32 * (v x6 % pow2 24) in
let z2 = v x6 / pow2 24 + pow2 32 * (v x7 % pow2 24) in
let z3 = v x7 / pow2 24 + pow2 32 * (v x8 % pow2 24) in
let z4 = v x8 / pow2 24 + pow2 32 * (v x9 % pow2 24) in
wide_as_nat5 x / pow2 248 == z0 + z1 * pow2 56 + z2 * pow2 112 + z3 * pow2 168 + z4 * pow2 224))
#push-options "--z3rlimit 50"
let lemma_div248 x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
lemma_wide_as_nat_pow512 x;
assert (v x9 < pow2 24);
calc (==) {
(let z0 = v x4 / pow2 24 + pow2 32 * (v x5 % pow2 24) in
let z1 = v x5 / pow2 24 + pow2 32 * (v x6 % pow2 24) in
let z2 = v x6 / pow2 24 + pow2 32 * (v x7 % pow2 24) in
let z3 = v x7 / pow2 24 + pow2 32 * (v x8 % pow2 24) in
let z4 = v x8 / pow2 24 + pow2 32 * (v x9 % pow2 24) in
z0 + z1 * pow2 56 + z2 * pow2 112 + z3 * pow2 168 + z4 * pow2 224);
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
v x4 / pow2 24 + pow2 32 * (v x5 % pow2 24) +
v x5 / pow2 24 * pow2 56 + pow2 32 * (v x6 % pow2 24) * pow2 56 +
v x6 / pow2 24 * pow2 112 + pow2 32 * (v x7 % pow2 24) * pow2 112 +
v x7 / pow2 24 * pow2 168 + pow2 32 * (v x8 % pow2 24) * pow2 168 +
v x8 / pow2 24 * pow2 224 + pow2 32 * (v x9 % pow2 24) * pow2 224;
(==) { lemma_div248_x5 x5; lemma_div248_x6 x6 }
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 +
pow2 32 * (v x7 % pow2 24) * pow2 112 +
v x7 / pow2 24 * pow2 168 + pow2 32 * (v x8 % pow2 24) * pow2 168 +
v x8 / pow2 24 * pow2 224 + pow2 32 * (v x9 % pow2 24) * pow2 224;
(==) { lemma_div248_x7 x7; lemma_div248_x8 x8 }
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 +
pow2 32 * (v x9 % pow2 24) * pow2 224;
(==) { lemma_div248_x9 x9 }
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256;
(==) { lemma_div248_aux x }
wide_as_nat5 x / pow2 248;
}
#pop-options
val lemma_add_modq5:
x:qelem5
-> y:qelem5
-> t:qelem5 ->
Lemma
(requires
qelem_fits5 x (1, 1, 1, 1, 1) /\
qelem_fits5 y (1, 1, 1, 1, 1) /\
qelem_fits5 t (1, 1, 1, 1, 1) /\
as_nat5 x < S.q /\ as_nat5 y < S.q /\
as_nat5 t == as_nat5 x + as_nat5 y)
(ensures
(let res = if as_nat5 t >= S.q then as_nat5 t - S.q else as_nat5 t in
res < S.q /\ res == (as_nat5 x + as_nat5 y) % S.q))
let lemma_add_modq5 x y t =
assert (as_nat5 t == as_nat5 x + as_nat5 y);
let res = if as_nat5 t >= S.q then as_nat5 t - S.q else as_nat5 t in
assert (res < S.q);
if as_nat5 t >= S.q then (
FStar.Math.Lemmas.sub_div_mod_1 (as_nat5 t) S.q;
assert (res % S.q == as_nat5 t % S.q))
else
assert (res % S.q == as_nat5 t % S.q);
FStar.Math.Lemmas.small_mod res S.q
val lemma_wide_as_nat_pow528: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 528)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
v x9 < pow2 40))
let lemma_wide_as_nat_pow528 x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert_norm (pow2 504 * pow2 24 = pow2 528);
FStar.Math.Lemmas.pow2_minus 528 504;
assert (v x9 < pow2 24);
assert_norm (pow2 24 < pow2 40)
#push-options "--z3cliopt smt.arith.nl=false"
val lemma_div264_aux: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 528)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
wide_as_nat5 x / pow2 264 ==
v x4 / pow2 40 + v x5 * pow2 16 + v x6 * pow2 72 + v x7 * pow2 128 + v x8 * pow2 184 + v x9 * pow2 240))
let lemma_div264_aux x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert_norm (pow2 264 == pow2 224 * pow2 40);
assert_norm (pow2 56 == pow2 16 * pow2 40);
assert_norm (pow2 112 == pow2 72 * pow2 40);
assert_norm (pow2 168 == pow2 128 * pow2 40);
assert_norm (pow2 224 == pow2 184 * pow2 40);
assert_norm (pow2 280 == pow2 240 * pow2 40);
assert_norm (0 < pow2 40);
calc (==) {
wide_as_nat5 x / pow2 264;
(==) { FStar.Math.Lemmas.division_multiplication_lemma (wide_as_nat5 x) (pow2 224) (pow2 40) }
(wide_as_nat5 x / pow2 224) / pow2 40;
(==) { lemma_div224 x }
(v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280) / pow2 40;
(==) { _ by (Tactics.mapply (`feq #int #int (fun x -> x / pow2 40)); int_semiring ()) }
(v x4 + (v x5 * pow2 16 + v x6 * pow2 72 + v x7 * pow2 128 + v x8 * pow2 184 + v x9 * pow2 240) * pow2 40) / pow2 40;
(==) { FStar.Math.Lemmas.lemma_div_plus (v x4) (v x5 * pow2 16 + v x6 * pow2 72 + v x7 * pow2 128 + v x8 * pow2 184 + v x9 * pow2 240) (pow2 40) }
v x4 / pow2 40 + v x5 * pow2 16 + v x6 * pow2 72 + v x7 * pow2 128 + v x8 * pow2 184 + v x9 * pow2 240;
}
val lemma_div264_x5: x5:uint64 ->
Lemma (pow2 16 * (v x5 % pow2 40) + v x5 / pow2 40 * pow2 56 == v x5 * pow2 16)
let lemma_div264_x5 x5 =
assert_norm (0 < pow2 24);
calc (==) {
pow2 16 * (v x5 % pow2 40) + v x5 / pow2 40 * pow2 56;
(==) { _ by (Tactics.norm [delta_only [`%pow2]; primops]; int_semiring ()) }
((v x5 / pow2 40) * pow2 40 + v x5 % pow2 40) * pow2 16;
(==) { FStar.Math.Lemmas.euclidean_division_definition (v x5) (pow2 40) }
v x5 * pow2 16;
}
val lemma_div264_x6: x6:uint64 ->
Lemma (pow2 16 * (v x6 % pow2 40) * pow2 56 + v x6 / pow2 40 * pow2 112 == v x6 * pow2 72)
let lemma_div264_x6 x6 =
calc (==) {
pow2 16 * (v x6 % pow2 40) * pow2 56 + v x6 / pow2 40 * pow2 112;
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
((v x6 / pow2 40) * pow2 40 + v x6 % pow2 40) * pow2 72;
(==) { Math.Lemmas.euclidean_division_definition (v x6) (pow2 40) }
v x6 * pow2 72;
}
val lemma_div264_x7: x7:uint64 ->
Lemma (pow2 16 * (v x7 % pow2 40) * pow2 112 + v x7 / pow2 40 * pow2 168 == v x7 * pow2 128)
let lemma_div264_x7 x7 =
calc (==) {
pow2 16 * (v x7 % pow2 40) * pow2 112 + v x7 / pow2 40 * pow2 168;
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
((v x7 / pow2 40) * pow2 40 + v x7 % pow2 40) * pow2 128;
(==) { Math.Lemmas.euclidean_division_definition (v x7) (pow2 40) }
v x7 * pow2 128;
}
val lemma_div264_x8: x8:uint64 ->
Lemma (pow2 16 * (v x8 % pow2 40) * pow2 168 + v x8 / pow2 40 * pow2 224 == v x8 * pow2 184)
let lemma_div264_x8 x8 =
calc (==) {
pow2 16 * (v x8 % pow2 40) * pow2 168 + v x8 / pow2 40 * pow2 224;
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
((v x8 / pow2 40) * pow2 40 + v x8 % pow2 40) * pow2 184;
(==) { Math.Lemmas.euclidean_division_definition (v x8) (pow2 40) }
v x8 * pow2 184;
}
val lemma_div264_x9: x9:uint64{v x9 < pow2 40} ->
Lemma (pow2 16 * (v x9 % pow2 40) * pow2 224 == v x9 * pow2 240)
let lemma_div264_x9 x9 =
calc (==) {
pow2 16 * (v x9 % pow2 40) * pow2 224;
(==) { Math.Lemmas.small_mod (v x9) (pow2 40) }
pow2 16 * v x9 * pow2 224;
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
v x9 * pow2 240;
}
val lemma_div264: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 528)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
let z0 = v x4 / pow2 40 + pow2 16 * (v x5 % pow2 40) in
let z1 = v x5 / pow2 40 + pow2 16 * (v x6 % pow2 40) in
let z2 = v x6 / pow2 40 + pow2 16 * (v x7 % pow2 40) in
let z3 = v x7 / pow2 40 + pow2 16 * (v x8 % pow2 40) in
let z4 = v x8 / pow2 40 + pow2 16 * (v x9 % pow2 40) in
wide_as_nat5 x / pow2 264 == z0 + z1 * pow2 56 + z2 * pow2 112 + z3 * pow2 168 + z4 * pow2 224))
#push-options "--z3rlimit 50"
let lemma_div264 x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
lemma_wide_as_nat_pow528 x;
assert (v x9 < pow2 40);
calc (==) {
(let z0 = v x4 / pow2 40 + pow2 16 * (v x5 % pow2 40) in
let z1 = v x5 / pow2 40 + pow2 16 * (v x6 % pow2 40) in
let z2 = v x6 / pow2 40 + pow2 16 * (v x7 % pow2 40) in
let z3 = v x7 / pow2 40 + pow2 16 * (v x8 % pow2 40) in
let z4 = v x8 / pow2 40 + pow2 16 * (v x9 % pow2 40) in
z0 + z1 * pow2 56 + z2 * pow2 112 + z3 * pow2 168 + z4 * pow2 224);
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
v x4 / pow2 40 + pow2 16 * (v x5 % pow2 40) +
v x5 / pow2 40 * pow2 56 + pow2 16 * (v x6 % pow2 40) * pow2 56 +
v x6 / pow2 40 * pow2 112 + pow2 16 * (v x7 % pow2 40) * pow2 112 +
v x7 / pow2 40 * pow2 168 + pow2 16 * (v x8 % pow2 40) * pow2 168 +
v x8 / pow2 40 * pow2 224 + pow2 16 * (v x9 % pow2 40) * pow2 224;
(==) { lemma_div264_x5 x5; lemma_div264_x6 x6 }
v x4 / pow2 40 + v x5 * pow2 16 + v x6 * pow2 72 +
pow2 16 * (v x7 % pow2 40) * pow2 112 +
v x7 / pow2 40 * pow2 168 + pow2 16 * (v x8 % pow2 40) * pow2 168 +
v x8 / pow2 40 * pow2 224 + pow2 16 * (v x9 % pow2 40) * pow2 224;
(==) { lemma_div264_x7 x7; lemma_div264_x8 x8 }
v x4 / pow2 40 + v x5 * pow2 16 + v x6 * pow2 72 + v x7 * pow2 128 + v x8 * pow2 184 +
pow2 16 * (v x9 % pow2 40) * pow2 224;
(==) { lemma_div264_x9 x9 }
v x4 / pow2 40 + v x5 * pow2 16 + v x6 * pow2 72 + v x7 * pow2 128 + v x8 * pow2 184 + v x9 * pow2 240;
(==) { lemma_div264_aux x }
wide_as_nat5 x / pow2 264;
}
#pop-options
#pop-options // "--z3cliopt smt.arith.nl=false"
val lemma_mod_264_aux: t:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 t (1, 1, 1, 1, 1, 1, 1, 1, 1, 1))
(ensures
(let (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) = t in
(wide_as_nat5 t) % pow2 264 ==
(v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + v t4 * pow2 224) % pow2 264))
#push-options "--z3rlimit 150"
let lemma_mod_264_aux t =
let (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) = t in
let res = (t0, t1, t2, t3, t4 &. u64 0xffffffffff) in
assert_norm (pow2 16 * pow2 264 == pow2 280);
assert_norm (pow2 72 * pow2 264 == pow2 336);
assert_norm (pow2 128 * pow2 264 == pow2 392);
assert_norm (pow2 184 * pow2 264 == pow2 448);
assert_norm (pow2 240 * pow2 264 == pow2 504);
calc (==) {
(wide_as_nat5 t) % pow2 264;
(==) { }
(v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + v t4 * pow2 224 +
(v t5 * pow2 16 + v t6 * pow2 72 + v t7 * pow2 128 + v t8 * pow2 184 + v t9 * pow2 240) * pow2 264) % pow2 264;
(==) { FStar.Math.Lemmas.lemma_mod_add_distr (v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + v t4 * pow2 224)
((v t5 * pow2 16 + v t6 * pow2 72 + v t7 * pow2 128 + v t8 * pow2 184 + v t9 * pow2 240) * pow2 264) (pow2 264)}
((v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + v t4 * pow2 224) +
((v t5 * pow2 16 + v t6 * pow2 72 + v t7 * pow2 128 + v t8 * pow2 184 + v t9 * pow2 240) * pow2 264) % pow2 264) % pow2 264;
(==) { FStar.Math.Lemmas.cancel_mul_mod (v t5 * pow2 16 + v t6 * pow2 72 + v t7 * pow2 128 + v t8 * pow2 184 + v t9 * pow2 240) (pow2 264) }
(v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + v t4 * pow2 224) % pow2 264;
}
#pop-options
val lemma_as_nat_pow264: x:qelem5 ->
Lemma
(requires
(let (x0, x1, x2, x3, x4) = x in
qelem_fits5 x (1, 1, 1, 1, 1) /\
v x4 < pow2 40))
(ensures as_nat5 x < pow2 264)
let lemma_as_nat_pow264 x =
let (x0, x1, x2, x3, x4) = x in
assert_norm (pow2 40 * pow2 224 = pow2 264)
val lemma_mod_264: t:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 t (1, 1, 1, 1, 1, 1, 1, 1, 1, 1))
(ensures
(let (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) = t in
let res = (t0, t1, t2, t3, t4 &. u64 0xffffffffff) in
qelem_fits5 res (1, 1, 1, 1, 1) /\
as_nat5 res == (wide_as_nat5 t) % pow2 264))
let lemma_mod_264 t =
let (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) = t in
let t4' = t4 &. u64 0xffffffffff in
let res = (t0, t1, t2, t3, t4') in
assert_norm (pow2 40 < pow2 64);
assert_norm (pow2 40 - 1 == 0xffffffffff);
mod_mask_lemma t4 40ul;
assert (v (mod_mask #U64 #SEC 40ul) == 0xffffffffff);
assert (v (t4 &. u64 0xffffffffff) == v t4 % pow2 40);
calc (==) {
(wide_as_nat5 t) % pow2 264;
(==) { lemma_mod_264_aux t }
(v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + v t4 * pow2 224) % pow2 264;
(==) { FStar.Math.Lemmas.lemma_mod_add_distr (v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168) (v t4 * pow2 224) (pow2 264) }
(v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + (v t4 * pow2 224) % pow2 264) % pow2 264;
(==) { FStar.Math.Lemmas.pow2_multiplication_modulo_lemma_2 (v t4) 264 224 }
(v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + (v t4 % pow2 40) * pow2 224) % pow2 264;
(==) { lemma_as_nat_pow264 res; FStar.Math.Lemmas.modulo_lemma (as_nat5 res) (pow2 264) }
v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + (v t4 % pow2 40) * pow2 224;
}
val lemma_as_nat_pow264_x4: x:qelem5 ->
Lemma
(requires
qelem_fits5 x (1, 1, 1, 1, 1) /\
as_nat5 x < pow2 264)
(ensures
(let (x0, x1, x2, x3, x4) = x in
v x4 < pow2 40))
let lemma_as_nat_pow264_x4 x =
let (x0, x1, x2, x3, x4) = x in
assert_norm (pow2 40 * pow2 224 = pow2 264)
val lemma_sub_mod_264_aux:
x0:nat -> x1:nat -> x2:nat -> x3:nat -> x4:nat
-> y0:nat -> y1:nat -> y2:nat -> y3:nat -> y4:nat
-> c1:nat -> c2:nat -> c3:nat -> c4:nat -> c5:nat ->
Lemma (
x0 - y0 + c1 * pow56 +
(x1 - y1 - c1 + c2 * pow56) * pow56 +
(x2 - y2 - c2 + c3 * pow56) * pow112 +
(x3 - y3 - c3 + c4 * pow56) * pow168 +
(x4 - y4 - c4 + pow2 40 * c5) * pow224 ==
(x0 + x1 * pow2 56 + x2 * pow2 112 + x3 * pow2 168 + x4 * pow2 224) -
(y0 + y1 * pow2 56 + y2 * pow2 112 + y3 * pow2 168 + y4 * pow2 224) + c5 * pow2 264) | {
"checked_file": "/",
"dependencies": [
"Spec.Ed25519.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.BignumQ.Definitions.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Tactics.CanonCommSemiring.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.BignumQ.Lemmas.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.CanonCommSemiring",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.BignumQ.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.Ed25519",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.CanonCommSemiring",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.BignumQ",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.BignumQ",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
x0: Prims.nat ->
x1: Prims.nat ->
x2: Prims.nat ->
x3: Prims.nat ->
x4: Prims.nat ->
y0: Prims.nat ->
y1: Prims.nat ->
y2: Prims.nat ->
y3: Prims.nat ->
y4: Prims.nat ->
c1: Prims.nat ->
c2: Prims.nat ->
c3: Prims.nat ->
c4: Prims.nat ->
c5: Prims.nat
-> FStar.Pervasives.Lemma
(ensures
x0 - y0 + c1 * Hacl.Spec.BignumQ.Definitions.pow56 +
(x1 - y1 - c1 + c2 * Hacl.Spec.BignumQ.Definitions.pow56) *
Hacl.Spec.BignumQ.Definitions.pow56 +
(x2 - y2 - c2 + c3 * Hacl.Spec.BignumQ.Definitions.pow56) *
Hacl.Spec.BignumQ.Definitions.pow112 +
(x3 - y3 - c3 + c4 * Hacl.Spec.BignumQ.Definitions.pow56) *
Hacl.Spec.BignumQ.Definitions.pow168 +
(x4 - y4 - c4 + Prims.pow2 40 * c5) * Hacl.Spec.BignumQ.Definitions.pow224 ==
x0 + x1 * Prims.pow2 56 + x2 * Prims.pow2 112 + x3 * Prims.pow2 168 + x4 * Prims.pow2 224 -
(y0 + y1 * Prims.pow2 56 + y2 * Prims.pow2 112 + y3 * Prims.pow2 168 + y4 * Prims.pow2 224) +
c5 * Prims.pow2 264) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.nat",
"FStar.Pervasives.assert_norm",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"FStar.Mul.op_Star",
"Prims.pow2",
"Prims.unit"
] | [] | true | false | true | false | false | let lemma_sub_mod_264_aux x0 x1 x2 x3 x4 y0 y1 y2 y3 y4 b0 b1 b2 b3 b4 =
| assert_norm (pow2 56 * pow2 56 = pow2 112);
assert_norm (pow2 56 * pow2 112 = pow2 168);
assert_norm (pow2 56 * pow2 168 = pow2 224);
assert_norm (pow2 40 * pow2 224 = pow2 264) | false |
SfBasic.fst | SfBasic.andb | val andb : mbool -> mbool -> Tot mbool | val andb : mbool -> mbool -> Tot mbool | let andb b1 b2 =
match b1 with
| MTrue -> b2
| MFalse -> MFalse | {
"file_name": "examples/software_foundations/SfBasic.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 20,
"end_line": 67,
"start_col": 0,
"start_line": 64
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
(*
A translation to F* of Basics.v from Software Foundations
Original name: "Basics: Functional Programming in Coq"
*)
module SfBasic
type day =
| Monday
| Tuesday
| Wednesday
| Thursday
| Friday
| Saturday
| Sunday
val next_weekday : day -> Tot day
let next_weekday d =
match d with
| Monday -> Tuesday
| Tuesday -> Wednesday
| Wednesday -> Thursday
| Thursday -> Friday
| Friday -> Monday
| Saturday -> Monday
| Sunday -> Monday
val test_next_weekday : unit -> Lemma
(ensures ((next_weekday (next_weekday Saturday)) = Tuesday))
let test_next_weekday () = ()
(* Booleans *)
(* The original example calls these bool, True, and False,
and that doesn't seem to cause problems;
I've just renamed them to be 100% sure that's not the cause
of the troubles in this file *)
type mbool =
| MTrue
| MFalse
val negb : mbool -> Tot mbool
let negb b =
match b with
| MTrue -> MFalse
| MFalse -> MTrue | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "SfBasic.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | b1: SfBasic.mbool -> b2: SfBasic.mbool -> SfBasic.mbool | Prims.Tot | [
"total"
] | [] | [
"SfBasic.mbool",
"SfBasic.MFalse"
] | [] | false | false | false | true | false | let andb b1 b2 =
| match b1 with
| MTrue -> b2
| MFalse -> MFalse | false |
SfBasic.fst | SfBasic.oddb | val oddb : nat -> Tot mbool | val oddb : nat -> Tot mbool | let oddb n = negb (evenb n) | {
"file_name": "examples/software_foundations/SfBasic.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 27,
"end_line": 118,
"start_col": 0,
"start_line": 118
} | (*
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.
*)
(*
A translation to F* of Basics.v from Software Foundations
Original name: "Basics: Functional Programming in Coq"
*)
module SfBasic
type day =
| Monday
| Tuesday
| Wednesday
| Thursday
| Friday
| Saturday
| Sunday
val next_weekday : day -> Tot day
let next_weekday d =
match d with
| Monday -> Tuesday
| Tuesday -> Wednesday
| Wednesday -> Thursday
| Thursday -> Friday
| Friday -> Monday
| Saturday -> Monday
| Sunday -> Monday
val test_next_weekday : unit -> Lemma
(ensures ((next_weekday (next_weekday Saturday)) = Tuesday))
let test_next_weekday () = ()
(* Booleans *)
(* The original example calls these bool, True, and False,
and that doesn't seem to cause problems;
I've just renamed them to be 100% sure that's not the cause
of the troubles in this file *)
type mbool =
| MTrue
| MFalse
val negb : mbool -> Tot mbool
let negb b =
match b with
| MTrue -> MFalse
| MFalse -> MTrue
val andb : mbool -> mbool -> Tot mbool
let andb b1 b2 =
match b1 with
| MTrue -> b2
| MFalse -> MFalse
val orb : mbool -> mbool -> Tot mbool
let orb b1 b2 =
match b1 with
| MTrue -> MTrue
| MFalse -> b2
val test_orb1 : unit -> Lemma
(ensures ((orb MTrue MFalse) = MTrue))
let test_orb1 () = ()
val test_orb2 : unit -> Lemma
(ensures ((orb MFalse MFalse) = MFalse))
let test_orb2 () = ()
val test_orb3 : unit -> Lemma
(ensures ((orb MFalse MTrue) = MTrue))
let test_orb3 () = ()
val test_orb4 : unit -> Lemma
(ensures ((orb MTrue MTrue) = MTrue))
let test_orb4 () = ()
(* Numbers *)
type nat =
| O : nat
| S : nat -> nat
val pred : nat -> Tot nat
let pred n =
match n with
| O -> O
| S n' -> n'
val minustwo : nat -> Tot nat
let minustwo n =
match n with
| O -> O
| S O -> O
| S (S n') -> n'
val evenb : nat -> Tot mbool
let rec evenb n =
match n with
| O -> MTrue
| S O -> MFalse
| S (S n') -> evenb n' | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "SfBasic.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | n: SfBasic.nat -> SfBasic.mbool | Prims.Tot | [
"total"
] | [] | [
"SfBasic.nat",
"SfBasic.negb",
"SfBasic.evenb",
"SfBasic.mbool"
] | [] | false | false | false | true | false | let oddb n =
| negb (evenb n) | false |
Hacl.Spec.BignumQ.Lemmas.fst | Hacl.Spec.BignumQ.Lemmas.lemma_div264_x5 | val lemma_div264_x5: x5:uint64 ->
Lemma (pow2 16 * (v x5 % pow2 40) + v x5 / pow2 40 * pow2 56 == v x5 * pow2 16) | val lemma_div264_x5: x5:uint64 ->
Lemma (pow2 16 * (v x5 % pow2 40) + v x5 / pow2 40 * pow2 56 == v x5 * pow2 16) | let lemma_div264_x5 x5 =
assert_norm (0 < pow2 24);
calc (==) {
pow2 16 * (v x5 % pow2 40) + v x5 / pow2 40 * pow2 56;
(==) { _ by (Tactics.norm [delta_only [`%pow2]; primops]; int_semiring ()) }
((v x5 / pow2 40) * pow2 40 + v x5 % pow2 40) * pow2 16;
(==) { FStar.Math.Lemmas.euclidean_division_definition (v x5) (pow2 40) }
v x5 * pow2 16;
} | {
"file_name": "code/ed25519/Hacl.Spec.BignumQ.Lemmas.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 3,
"end_line": 369,
"start_col": 0,
"start_line": 361
} | module Hacl.Spec.BignumQ.Lemmas
open FStar.Tactics.CanonCommSemiring
open FStar.Mul
open Lib.IntTypes
module S = Spec.Ed25519
include Hacl.Spec.BignumQ.Definitions
let feq (#a #b:Type) (f:(a -> b)) (x y:a) :
Lemma (requires x == y) (ensures f x == f y) = ()
let eq_eq2 (#a:eqtype) (x y:a) :
Lemma (requires x = y) (ensures x == y) = ()
val lemma_mul_lt:a:nat -> b:nat -> c:nat -> d:nat ->
Lemma
(requires a < b /\ c < d)
(ensures a * c < b * d)
let lemma_mul_lt a b c d = ()
val lemma_as_nat5: f:qelem5 ->
Lemma
(requires qelem_fits5 f (1, 1, 1, 1, 1))
(ensures as_nat5 f < pow2 280)
let lemma_as_nat5 f =
//let (f0, f1, f2, f3, f4) = f in
//assert (as_nat5 f == v f0 + v f1 * pow56 + v f2 * pow112 + v f3 * pow168 + v f4 * pow224);
assert_norm (pow2 56 * pow2 56 = pow2 112);
assert_norm (pow2 56 * pow2 112 = pow2 168);
assert_norm (pow2 56 * pow2 168 = pow2 224);
assert_norm (pow2 56 * pow2 224 = pow2 280)
val lemma_choose_step:
bit:uint64{v bit <= 1}
-> x:uint64
-> y:uint64
-> Lemma
(let mask = bit -. u64 1 in
let z = x ^. (mask &. (x ^. y)) in
if v bit = 1 then z == x else z == y)
let lemma_choose_step bit p1 p2 =
let mask = bit -. u64 1 in
assert (v bit == 0 ==> v mask == pow2 64 - 1);
assert (v bit == 1 ==> v mask == 0);
let dummy = mask &. (p1 ^. p2) in
logand_lemma mask (p1 ^. p2);
assert (v bit == 1 ==> v dummy == 0);
assert (v bit == 0 ==> v dummy == v (p1 ^. p2));
let p1' = p1 ^. dummy in
assert (v dummy == v (if v bit = 1 then u64 0 else (p1 ^. p2)));
logxor_lemma p1 p2
val lemma_subm_conditional:
x0:nat -> x1:nat -> x2:nat -> x3:nat -> x4:nat
-> y0:nat -> y1:nat -> y2:nat -> y3:nat -> y4:nat
-> b0:nat -> b1:nat -> b2:nat -> b3:nat -> b4:nat ->
Lemma (
x0 - y0 + b0 * pow2 56 +
(x1 - y1 - b0 + b1 * pow2 56) * pow2 56 +
(x2 - y2 - b1 + b2 * pow2 56) * pow2 112 +
(x3 - y3 - b2 + b3 * pow2 56) * pow2 168 +
(x4 - y4 - b3 + b4 * pow2 56) * pow2 224 ==
(x0 + x1 * pow2 56 + x2 * pow2 112 + x3 * pow2 168 + x4 * pow2 224) -
(y0 + y1 * pow2 56 + y2 * pow2 112 + y3 * pow2 168 + y4 * pow2 224) + b4 * pow2 280)
let lemma_subm_conditional x0 x1 x2 x3 x4 y0 y1 y2 y3 y4 b0 b1 b2 b3 b4 =
assert_norm (pow2 56 * pow2 56 = pow2 112);
assert_norm (pow2 56 * pow2 112 = pow2 168);
assert_norm (pow2 56 * pow2 168 = pow2 224);
assert_norm (pow2 56 * pow2 224 = pow2 280);
assert (
x0 - y0 + b0 * pow2 56 +
(x1 - y1 - b0 + b1 * pow2 56) * pow2 56 +
(x2 - y2 - b1 + b2 * pow2 56) * pow2 112 +
(x3 - y3 - b2 + b3 * pow2 56) * pow2 168 +
(x4 - y4 - b3 + b4 * pow2 56) * pow2 224 ==
(x0 + x1 * pow2 56 + x2 * pow2 112 + x3 * pow2 168 + x4 * pow2 224) -
(y0 + y1 * pow2 56 + y2 * pow2 112 + y3 * pow2 168 + y4 * pow2 224) + b4 * pow2 280)
by (int_semiring ());
()
val lemma_div224: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1))
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
wide_as_nat5 x / pow2 224 ==
v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280))
#push-options "--z3rlimit 50"
let lemma_div224 x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert
(wide_as_nat5 x ==
v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168 + v x4 * pow2 224 +
v x5 * pow2 280 + v x6 * pow2 336 + v x7 * pow2 392 + v x8 * pow2 448 + v x9 * pow2 504);
assert_norm (pow2 56 * pow2 224 == pow2 280);
assert_norm (pow2 112 * pow2 224 == pow2 336);
assert_norm (pow2 168 * pow2 224 == pow2 392);
assert_norm (pow2 224 * pow2 224 == pow2 448);
assert_norm (pow2 280 * pow2 224 == pow2 504);
calc (==) {
wide_as_nat5 x / pow2 224;
(==) { }
(v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168 +
(v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280) * pow2 224) / pow2 224;
(==) {
FStar.Math.Lemmas.lemma_div_plus
(v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168)
(v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280) (pow2 224) }
(v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168) / pow2 224 +
v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280;
(==) { FStar.Math.Lemmas.small_division_lemma_1 (v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168) (pow2 224) }
v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280;
}
#pop-options
val lemma_div248_aux: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 512)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
wide_as_nat5 x / pow2 248 ==
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256))
open FStar.Tactics.CanonCommSemiring
#push-options "--z3cliopt smt.arith.nl=false"
let lemma_div248_aux x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert_norm (pow2 248 == pow2 224 * pow2 24);
assert_norm (pow2 56 == pow2 32 * pow2 24);
assert_norm (pow2 112 == pow2 88 * pow2 24);
assert_norm (pow2 168 == pow2 144 * pow2 24);
assert_norm (pow2 224 == pow2 200 * pow2 24);
assert_norm (pow2 280 == pow2 256 * pow2 24);
assert_norm (0 < pow2 24);
calc (==) {
wide_as_nat5 x / pow2 248;
(==) { FStar.Math.Lemmas.division_multiplication_lemma (wide_as_nat5 x) (pow2 224) (pow2 24) }
(wide_as_nat5 x / pow2 224) / pow2 24;
(==) { lemma_div224 x }
(v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280) / pow2 24;
(==) { _ by (Tactics.mapply (`feq #int #int (fun x -> x / pow2 24)); int_semiring ()) } (v x4 + (v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256) * pow2 24) / pow2 24;
(==) { FStar.Math.Lemmas.lemma_div_plus (v x4) (v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256) (pow2 24) }
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256;
}
#pop-options
val lemma_div248_x5: x5:uint64 ->
Lemma ( pow2 32 * (v x5 % pow2 24) + v x5 / pow2 24 * pow2 56 == v x5 * pow2 32)
let lemma_div248_x5 x5 =
assert_norm (pow2 32 * pow2 24 = pow2 56)
val lemma_div248_x6: x6:uint64 ->
Lemma (pow2 32 * (v x6 % pow2 24) * pow2 56 + v x6 / pow2 24 * pow2 112 == v x6 * pow2 88)
let lemma_div248_x6 x6 =
calc (==) {
pow2 32 * (v x6 % pow2 24) * pow2 56 + v x6 / pow2 24 * pow2 112;
(==) { _ by (Tactics.norm [delta_only [`%pow2]; primops]; int_semiring ()) }
((v x6 / pow2 24) * pow2 24 + v x6 % pow2 24) * pow2 88;
(==) { FStar.Math.Lemmas.euclidean_division_definition (v x6) (pow2 24) }
v x6 * pow2 88;
}
val lemma_div248_x7: x7:uint64 ->
Lemma (pow2 32 * (v x7 % pow2 24) * pow2 112 + v x7 / pow2 24 * pow2 168 == v x7 * pow2 144)
let lemma_div248_x7 x7 =
calc (==) {
pow2 32 * (v x7 % pow2 24) * pow2 112 + v x7 / pow2 24 * pow2 168;
(==) { _ by (Tactics.norm [delta_only [`%pow2]; primops]; int_semiring ()) }
((v x7 / pow2 24) * pow2 24 + v x7 % pow2 24) * pow2 144;
(==) { FStar.Math.Lemmas.euclidean_division_definition (v x7) (pow2 24) }
v x7 * pow2 144;
}
val lemma_div248_x8: x8:uint64 ->
Lemma (pow2 32 * (v x8 % pow2 24) * pow2 168 + v x8 / pow2 24 * pow2 224 == v x8 * pow2 200)
let lemma_div248_x8 x8 =
calc (==) {
pow2 32 * (v x8 % pow2 24) * pow2 168 + v x8 / pow2 24 * pow2 224;
(==) { _ by (Tactics.norm [delta_only [`%pow2]; primops]; int_semiring ()) }
((v x8 / pow2 24) * pow2 24 + v x8 % pow2 24) * pow2 200;
(==) { FStar.Math.Lemmas.euclidean_division_definition (v x8) (pow2 24) }
v x8 * pow2 200;
}
val lemma_div248_x9: x9:uint64{v x9 < pow2 24} ->
Lemma (pow2 32 * (v x9 % pow2 24) * pow2 224 == v x9 * pow2 256)
let lemma_div248_x9 x9 =
calc (==) {
pow2 32 * (v x9 % pow2 24) * pow2 224;
(==) { Math.Lemmas.small_mod (v x9) (pow2 24) }
pow2 32 * v x9 * pow2 224;
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
v x9 * pow2 256;
}
val lemma_wide_as_nat_pow512: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 512)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
v x9 < pow2 24))
let lemma_wide_as_nat_pow512 x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert_norm (pow2 504 * pow2 8 = pow2 512);
FStar.Math.Lemmas.pow2_minus 512 504;
assert (v x9 < pow2 8);
assert_norm (pow2 8 < pow2 24)
val lemma_div248: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 512)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
let z0 = v x4 / pow2 24 + pow2 32 * (v x5 % pow2 24) in
let z1 = v x5 / pow2 24 + pow2 32 * (v x6 % pow2 24) in
let z2 = v x6 / pow2 24 + pow2 32 * (v x7 % pow2 24) in
let z3 = v x7 / pow2 24 + pow2 32 * (v x8 % pow2 24) in
let z4 = v x8 / pow2 24 + pow2 32 * (v x9 % pow2 24) in
wide_as_nat5 x / pow2 248 == z0 + z1 * pow2 56 + z2 * pow2 112 + z3 * pow2 168 + z4 * pow2 224))
#push-options "--z3rlimit 50"
let lemma_div248 x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
lemma_wide_as_nat_pow512 x;
assert (v x9 < pow2 24);
calc (==) {
(let z0 = v x4 / pow2 24 + pow2 32 * (v x5 % pow2 24) in
let z1 = v x5 / pow2 24 + pow2 32 * (v x6 % pow2 24) in
let z2 = v x6 / pow2 24 + pow2 32 * (v x7 % pow2 24) in
let z3 = v x7 / pow2 24 + pow2 32 * (v x8 % pow2 24) in
let z4 = v x8 / pow2 24 + pow2 32 * (v x9 % pow2 24) in
z0 + z1 * pow2 56 + z2 * pow2 112 + z3 * pow2 168 + z4 * pow2 224);
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
v x4 / pow2 24 + pow2 32 * (v x5 % pow2 24) +
v x5 / pow2 24 * pow2 56 + pow2 32 * (v x6 % pow2 24) * pow2 56 +
v x6 / pow2 24 * pow2 112 + pow2 32 * (v x7 % pow2 24) * pow2 112 +
v x7 / pow2 24 * pow2 168 + pow2 32 * (v x8 % pow2 24) * pow2 168 +
v x8 / pow2 24 * pow2 224 + pow2 32 * (v x9 % pow2 24) * pow2 224;
(==) { lemma_div248_x5 x5; lemma_div248_x6 x6 }
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 +
pow2 32 * (v x7 % pow2 24) * pow2 112 +
v x7 / pow2 24 * pow2 168 + pow2 32 * (v x8 % pow2 24) * pow2 168 +
v x8 / pow2 24 * pow2 224 + pow2 32 * (v x9 % pow2 24) * pow2 224;
(==) { lemma_div248_x7 x7; lemma_div248_x8 x8 }
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 +
pow2 32 * (v x9 % pow2 24) * pow2 224;
(==) { lemma_div248_x9 x9 }
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256;
(==) { lemma_div248_aux x }
wide_as_nat5 x / pow2 248;
}
#pop-options
val lemma_add_modq5:
x:qelem5
-> y:qelem5
-> t:qelem5 ->
Lemma
(requires
qelem_fits5 x (1, 1, 1, 1, 1) /\
qelem_fits5 y (1, 1, 1, 1, 1) /\
qelem_fits5 t (1, 1, 1, 1, 1) /\
as_nat5 x < S.q /\ as_nat5 y < S.q /\
as_nat5 t == as_nat5 x + as_nat5 y)
(ensures
(let res = if as_nat5 t >= S.q then as_nat5 t - S.q else as_nat5 t in
res < S.q /\ res == (as_nat5 x + as_nat5 y) % S.q))
let lemma_add_modq5 x y t =
assert (as_nat5 t == as_nat5 x + as_nat5 y);
let res = if as_nat5 t >= S.q then as_nat5 t - S.q else as_nat5 t in
assert (res < S.q);
if as_nat5 t >= S.q then (
FStar.Math.Lemmas.sub_div_mod_1 (as_nat5 t) S.q;
assert (res % S.q == as_nat5 t % S.q))
else
assert (res % S.q == as_nat5 t % S.q);
FStar.Math.Lemmas.small_mod res S.q
val lemma_wide_as_nat_pow528: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 528)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
v x9 < pow2 40))
let lemma_wide_as_nat_pow528 x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert_norm (pow2 504 * pow2 24 = pow2 528);
FStar.Math.Lemmas.pow2_minus 528 504;
assert (v x9 < pow2 24);
assert_norm (pow2 24 < pow2 40)
#push-options "--z3cliopt smt.arith.nl=false"
val lemma_div264_aux: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 528)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
wide_as_nat5 x / pow2 264 ==
v x4 / pow2 40 + v x5 * pow2 16 + v x6 * pow2 72 + v x7 * pow2 128 + v x8 * pow2 184 + v x9 * pow2 240))
let lemma_div264_aux x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert_norm (pow2 264 == pow2 224 * pow2 40);
assert_norm (pow2 56 == pow2 16 * pow2 40);
assert_norm (pow2 112 == pow2 72 * pow2 40);
assert_norm (pow2 168 == pow2 128 * pow2 40);
assert_norm (pow2 224 == pow2 184 * pow2 40);
assert_norm (pow2 280 == pow2 240 * pow2 40);
assert_norm (0 < pow2 40);
calc (==) {
wide_as_nat5 x / pow2 264;
(==) { FStar.Math.Lemmas.division_multiplication_lemma (wide_as_nat5 x) (pow2 224) (pow2 40) }
(wide_as_nat5 x / pow2 224) / pow2 40;
(==) { lemma_div224 x }
(v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280) / pow2 40;
(==) { _ by (Tactics.mapply (`feq #int #int (fun x -> x / pow2 40)); int_semiring ()) }
(v x4 + (v x5 * pow2 16 + v x6 * pow2 72 + v x7 * pow2 128 + v x8 * pow2 184 + v x9 * pow2 240) * pow2 40) / pow2 40;
(==) { FStar.Math.Lemmas.lemma_div_plus (v x4) (v x5 * pow2 16 + v x6 * pow2 72 + v x7 * pow2 128 + v x8 * pow2 184 + v x9 * pow2 240) (pow2 40) }
v x4 / pow2 40 + v x5 * pow2 16 + v x6 * pow2 72 + v x7 * pow2 128 + v x8 * pow2 184 + v x9 * pow2 240;
}
val lemma_div264_x5: x5:uint64 -> | {
"checked_file": "/",
"dependencies": [
"Spec.Ed25519.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.BignumQ.Definitions.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Tactics.CanonCommSemiring.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.BignumQ.Lemmas.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.CanonCommSemiring",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.BignumQ.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.Ed25519",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.CanonCommSemiring",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.BignumQ",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.BignumQ",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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": [
"smt.arith.nl=false"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x5: Lib.IntTypes.uint64
-> FStar.Pervasives.Lemma
(ensures
Prims.pow2 16 * (Lib.IntTypes.v x5 % Prims.pow2 40) +
(Lib.IntTypes.v x5 / Prims.pow2 40) * Prims.pow2 56 ==
Lib.IntTypes.v x5 * Prims.pow2 16) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Lib.IntTypes.uint64",
"FStar.Calc.calc_finish",
"Prims.int",
"Prims.eq2",
"Prims.op_Addition",
"FStar.Mul.op_Star",
"Prims.pow2",
"Prims.op_Modulus",
"Lib.IntTypes.v",
"Lib.IntTypes.U64",
"Lib.IntTypes.SEC",
"Prims.op_Division",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"Prims.unit",
"FStar.Calc.calc_step",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"FStar.Tactics.CanonCommSemiring.semiring_reflect",
"FStar.Tactics.CanonCommSemiring.int_cr",
"FStar.Pervasives.Native.Mktuple2",
"Prims.list",
"FStar.Pervasives.Native.tuple2",
"Prims.nat",
"FStar.Pervasives.Native.snd",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"Lib.IntTypes.sec_int_v",
"FStar.Stubs.Reflection.V2.Data.var",
"FStar.Tactics.CanonCommSemiring.Pplus",
"FStar.Tactics.CanonCommSemiring.Pmult",
"FStar.Tactics.CanonCommSemiring.Pvar",
"Prims.squash",
"FStar.Math.Lemmas.euclidean_division_definition",
"FStar.Pervasives.assert_norm",
"Prims.op_LessThan"
] | [] | false | false | true | false | false | let lemma_div264_x5 x5 =
| assert_norm (0 < pow2 24);
calc ( == ) {
pow2 16 * (v x5 % pow2 40) + (v x5 / pow2 40) * pow2 56;
( == ) { FStar.Tactics.Effect.synth_by_tactic (fun _ ->
(Tactics.norm [delta_only [`%pow2]; primops];
int_semiring ())) }
((v x5 / pow2 40) * pow2 40 + v x5 % pow2 40) * pow2 16;
( == ) { FStar.Math.Lemmas.euclidean_division_definition (v x5) (pow2 40) }
v x5 * pow2 16;
} | false |
Hacl.Spec.BignumQ.Lemmas.fst | Hacl.Spec.BignumQ.Lemmas.lemma_as_nat_pow264_x4 | val lemma_as_nat_pow264_x4: x:qelem5 ->
Lemma
(requires
qelem_fits5 x (1, 1, 1, 1, 1) /\
as_nat5 x < pow2 264)
(ensures
(let (x0, x1, x2, x3, x4) = x in
v x4 < pow2 40)) | val lemma_as_nat_pow264_x4: x:qelem5 ->
Lemma
(requires
qelem_fits5 x (1, 1, 1, 1, 1) /\
as_nat5 x < pow2 264)
(ensures
(let (x0, x1, x2, x3, x4) = x in
v x4 < pow2 40)) | let lemma_as_nat_pow264_x4 x =
let (x0, x1, x2, x3, x4) = x in
assert_norm (pow2 40 * pow2 224 = pow2 264) | {
"file_name": "code/ed25519/Hacl.Spec.BignumQ.Lemmas.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 45,
"end_line": 560,
"start_col": 0,
"start_line": 558
} | module Hacl.Spec.BignumQ.Lemmas
open FStar.Tactics.CanonCommSemiring
open FStar.Mul
open Lib.IntTypes
module S = Spec.Ed25519
include Hacl.Spec.BignumQ.Definitions
let feq (#a #b:Type) (f:(a -> b)) (x y:a) :
Lemma (requires x == y) (ensures f x == f y) = ()
let eq_eq2 (#a:eqtype) (x y:a) :
Lemma (requires x = y) (ensures x == y) = ()
val lemma_mul_lt:a:nat -> b:nat -> c:nat -> d:nat ->
Lemma
(requires a < b /\ c < d)
(ensures a * c < b * d)
let lemma_mul_lt a b c d = ()
val lemma_as_nat5: f:qelem5 ->
Lemma
(requires qelem_fits5 f (1, 1, 1, 1, 1))
(ensures as_nat5 f < pow2 280)
let lemma_as_nat5 f =
//let (f0, f1, f2, f3, f4) = f in
//assert (as_nat5 f == v f0 + v f1 * pow56 + v f2 * pow112 + v f3 * pow168 + v f4 * pow224);
assert_norm (pow2 56 * pow2 56 = pow2 112);
assert_norm (pow2 56 * pow2 112 = pow2 168);
assert_norm (pow2 56 * pow2 168 = pow2 224);
assert_norm (pow2 56 * pow2 224 = pow2 280)
val lemma_choose_step:
bit:uint64{v bit <= 1}
-> x:uint64
-> y:uint64
-> Lemma
(let mask = bit -. u64 1 in
let z = x ^. (mask &. (x ^. y)) in
if v bit = 1 then z == x else z == y)
let lemma_choose_step bit p1 p2 =
let mask = bit -. u64 1 in
assert (v bit == 0 ==> v mask == pow2 64 - 1);
assert (v bit == 1 ==> v mask == 0);
let dummy = mask &. (p1 ^. p2) in
logand_lemma mask (p1 ^. p2);
assert (v bit == 1 ==> v dummy == 0);
assert (v bit == 0 ==> v dummy == v (p1 ^. p2));
let p1' = p1 ^. dummy in
assert (v dummy == v (if v bit = 1 then u64 0 else (p1 ^. p2)));
logxor_lemma p1 p2
val lemma_subm_conditional:
x0:nat -> x1:nat -> x2:nat -> x3:nat -> x4:nat
-> y0:nat -> y1:nat -> y2:nat -> y3:nat -> y4:nat
-> b0:nat -> b1:nat -> b2:nat -> b3:nat -> b4:nat ->
Lemma (
x0 - y0 + b0 * pow2 56 +
(x1 - y1 - b0 + b1 * pow2 56) * pow2 56 +
(x2 - y2 - b1 + b2 * pow2 56) * pow2 112 +
(x3 - y3 - b2 + b3 * pow2 56) * pow2 168 +
(x4 - y4 - b3 + b4 * pow2 56) * pow2 224 ==
(x0 + x1 * pow2 56 + x2 * pow2 112 + x3 * pow2 168 + x4 * pow2 224) -
(y0 + y1 * pow2 56 + y2 * pow2 112 + y3 * pow2 168 + y4 * pow2 224) + b4 * pow2 280)
let lemma_subm_conditional x0 x1 x2 x3 x4 y0 y1 y2 y3 y4 b0 b1 b2 b3 b4 =
assert_norm (pow2 56 * pow2 56 = pow2 112);
assert_norm (pow2 56 * pow2 112 = pow2 168);
assert_norm (pow2 56 * pow2 168 = pow2 224);
assert_norm (pow2 56 * pow2 224 = pow2 280);
assert (
x0 - y0 + b0 * pow2 56 +
(x1 - y1 - b0 + b1 * pow2 56) * pow2 56 +
(x2 - y2 - b1 + b2 * pow2 56) * pow2 112 +
(x3 - y3 - b2 + b3 * pow2 56) * pow2 168 +
(x4 - y4 - b3 + b4 * pow2 56) * pow2 224 ==
(x0 + x1 * pow2 56 + x2 * pow2 112 + x3 * pow2 168 + x4 * pow2 224) -
(y0 + y1 * pow2 56 + y2 * pow2 112 + y3 * pow2 168 + y4 * pow2 224) + b4 * pow2 280)
by (int_semiring ());
()
val lemma_div224: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1))
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
wide_as_nat5 x / pow2 224 ==
v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280))
#push-options "--z3rlimit 50"
let lemma_div224 x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert
(wide_as_nat5 x ==
v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168 + v x4 * pow2 224 +
v x5 * pow2 280 + v x6 * pow2 336 + v x7 * pow2 392 + v x8 * pow2 448 + v x9 * pow2 504);
assert_norm (pow2 56 * pow2 224 == pow2 280);
assert_norm (pow2 112 * pow2 224 == pow2 336);
assert_norm (pow2 168 * pow2 224 == pow2 392);
assert_norm (pow2 224 * pow2 224 == pow2 448);
assert_norm (pow2 280 * pow2 224 == pow2 504);
calc (==) {
wide_as_nat5 x / pow2 224;
(==) { }
(v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168 +
(v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280) * pow2 224) / pow2 224;
(==) {
FStar.Math.Lemmas.lemma_div_plus
(v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168)
(v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280) (pow2 224) }
(v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168) / pow2 224 +
v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280;
(==) { FStar.Math.Lemmas.small_division_lemma_1 (v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168) (pow2 224) }
v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280;
}
#pop-options
val lemma_div248_aux: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 512)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
wide_as_nat5 x / pow2 248 ==
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256))
open FStar.Tactics.CanonCommSemiring
#push-options "--z3cliopt smt.arith.nl=false"
let lemma_div248_aux x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert_norm (pow2 248 == pow2 224 * pow2 24);
assert_norm (pow2 56 == pow2 32 * pow2 24);
assert_norm (pow2 112 == pow2 88 * pow2 24);
assert_norm (pow2 168 == pow2 144 * pow2 24);
assert_norm (pow2 224 == pow2 200 * pow2 24);
assert_norm (pow2 280 == pow2 256 * pow2 24);
assert_norm (0 < pow2 24);
calc (==) {
wide_as_nat5 x / pow2 248;
(==) { FStar.Math.Lemmas.division_multiplication_lemma (wide_as_nat5 x) (pow2 224) (pow2 24) }
(wide_as_nat5 x / pow2 224) / pow2 24;
(==) { lemma_div224 x }
(v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280) / pow2 24;
(==) { _ by (Tactics.mapply (`feq #int #int (fun x -> x / pow2 24)); int_semiring ()) } (v x4 + (v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256) * pow2 24) / pow2 24;
(==) { FStar.Math.Lemmas.lemma_div_plus (v x4) (v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256) (pow2 24) }
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256;
}
#pop-options
val lemma_div248_x5: x5:uint64 ->
Lemma ( pow2 32 * (v x5 % pow2 24) + v x5 / pow2 24 * pow2 56 == v x5 * pow2 32)
let lemma_div248_x5 x5 =
assert_norm (pow2 32 * pow2 24 = pow2 56)
val lemma_div248_x6: x6:uint64 ->
Lemma (pow2 32 * (v x6 % pow2 24) * pow2 56 + v x6 / pow2 24 * pow2 112 == v x6 * pow2 88)
let lemma_div248_x6 x6 =
calc (==) {
pow2 32 * (v x6 % pow2 24) * pow2 56 + v x6 / pow2 24 * pow2 112;
(==) { _ by (Tactics.norm [delta_only [`%pow2]; primops]; int_semiring ()) }
((v x6 / pow2 24) * pow2 24 + v x6 % pow2 24) * pow2 88;
(==) { FStar.Math.Lemmas.euclidean_division_definition (v x6) (pow2 24) }
v x6 * pow2 88;
}
val lemma_div248_x7: x7:uint64 ->
Lemma (pow2 32 * (v x7 % pow2 24) * pow2 112 + v x7 / pow2 24 * pow2 168 == v x7 * pow2 144)
let lemma_div248_x7 x7 =
calc (==) {
pow2 32 * (v x7 % pow2 24) * pow2 112 + v x7 / pow2 24 * pow2 168;
(==) { _ by (Tactics.norm [delta_only [`%pow2]; primops]; int_semiring ()) }
((v x7 / pow2 24) * pow2 24 + v x7 % pow2 24) * pow2 144;
(==) { FStar.Math.Lemmas.euclidean_division_definition (v x7) (pow2 24) }
v x7 * pow2 144;
}
val lemma_div248_x8: x8:uint64 ->
Lemma (pow2 32 * (v x8 % pow2 24) * pow2 168 + v x8 / pow2 24 * pow2 224 == v x8 * pow2 200)
let lemma_div248_x8 x8 =
calc (==) {
pow2 32 * (v x8 % pow2 24) * pow2 168 + v x8 / pow2 24 * pow2 224;
(==) { _ by (Tactics.norm [delta_only [`%pow2]; primops]; int_semiring ()) }
((v x8 / pow2 24) * pow2 24 + v x8 % pow2 24) * pow2 200;
(==) { FStar.Math.Lemmas.euclidean_division_definition (v x8) (pow2 24) }
v x8 * pow2 200;
}
val lemma_div248_x9: x9:uint64{v x9 < pow2 24} ->
Lemma (pow2 32 * (v x9 % pow2 24) * pow2 224 == v x9 * pow2 256)
let lemma_div248_x9 x9 =
calc (==) {
pow2 32 * (v x9 % pow2 24) * pow2 224;
(==) { Math.Lemmas.small_mod (v x9) (pow2 24) }
pow2 32 * v x9 * pow2 224;
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
v x9 * pow2 256;
}
val lemma_wide_as_nat_pow512: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 512)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
v x9 < pow2 24))
let lemma_wide_as_nat_pow512 x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert_norm (pow2 504 * pow2 8 = pow2 512);
FStar.Math.Lemmas.pow2_minus 512 504;
assert (v x9 < pow2 8);
assert_norm (pow2 8 < pow2 24)
val lemma_div248: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 512)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
let z0 = v x4 / pow2 24 + pow2 32 * (v x5 % pow2 24) in
let z1 = v x5 / pow2 24 + pow2 32 * (v x6 % pow2 24) in
let z2 = v x6 / pow2 24 + pow2 32 * (v x7 % pow2 24) in
let z3 = v x7 / pow2 24 + pow2 32 * (v x8 % pow2 24) in
let z4 = v x8 / pow2 24 + pow2 32 * (v x9 % pow2 24) in
wide_as_nat5 x / pow2 248 == z0 + z1 * pow2 56 + z2 * pow2 112 + z3 * pow2 168 + z4 * pow2 224))
#push-options "--z3rlimit 50"
let lemma_div248 x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
lemma_wide_as_nat_pow512 x;
assert (v x9 < pow2 24);
calc (==) {
(let z0 = v x4 / pow2 24 + pow2 32 * (v x5 % pow2 24) in
let z1 = v x5 / pow2 24 + pow2 32 * (v x6 % pow2 24) in
let z2 = v x6 / pow2 24 + pow2 32 * (v x7 % pow2 24) in
let z3 = v x7 / pow2 24 + pow2 32 * (v x8 % pow2 24) in
let z4 = v x8 / pow2 24 + pow2 32 * (v x9 % pow2 24) in
z0 + z1 * pow2 56 + z2 * pow2 112 + z3 * pow2 168 + z4 * pow2 224);
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
v x4 / pow2 24 + pow2 32 * (v x5 % pow2 24) +
v x5 / pow2 24 * pow2 56 + pow2 32 * (v x6 % pow2 24) * pow2 56 +
v x6 / pow2 24 * pow2 112 + pow2 32 * (v x7 % pow2 24) * pow2 112 +
v x7 / pow2 24 * pow2 168 + pow2 32 * (v x8 % pow2 24) * pow2 168 +
v x8 / pow2 24 * pow2 224 + pow2 32 * (v x9 % pow2 24) * pow2 224;
(==) { lemma_div248_x5 x5; lemma_div248_x6 x6 }
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 +
pow2 32 * (v x7 % pow2 24) * pow2 112 +
v x7 / pow2 24 * pow2 168 + pow2 32 * (v x8 % pow2 24) * pow2 168 +
v x8 / pow2 24 * pow2 224 + pow2 32 * (v x9 % pow2 24) * pow2 224;
(==) { lemma_div248_x7 x7; lemma_div248_x8 x8 }
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 +
pow2 32 * (v x9 % pow2 24) * pow2 224;
(==) { lemma_div248_x9 x9 }
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256;
(==) { lemma_div248_aux x }
wide_as_nat5 x / pow2 248;
}
#pop-options
val lemma_add_modq5:
x:qelem5
-> y:qelem5
-> t:qelem5 ->
Lemma
(requires
qelem_fits5 x (1, 1, 1, 1, 1) /\
qelem_fits5 y (1, 1, 1, 1, 1) /\
qelem_fits5 t (1, 1, 1, 1, 1) /\
as_nat5 x < S.q /\ as_nat5 y < S.q /\
as_nat5 t == as_nat5 x + as_nat5 y)
(ensures
(let res = if as_nat5 t >= S.q then as_nat5 t - S.q else as_nat5 t in
res < S.q /\ res == (as_nat5 x + as_nat5 y) % S.q))
let lemma_add_modq5 x y t =
assert (as_nat5 t == as_nat5 x + as_nat5 y);
let res = if as_nat5 t >= S.q then as_nat5 t - S.q else as_nat5 t in
assert (res < S.q);
if as_nat5 t >= S.q then (
FStar.Math.Lemmas.sub_div_mod_1 (as_nat5 t) S.q;
assert (res % S.q == as_nat5 t % S.q))
else
assert (res % S.q == as_nat5 t % S.q);
FStar.Math.Lemmas.small_mod res S.q
val lemma_wide_as_nat_pow528: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 528)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
v x9 < pow2 40))
let lemma_wide_as_nat_pow528 x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert_norm (pow2 504 * pow2 24 = pow2 528);
FStar.Math.Lemmas.pow2_minus 528 504;
assert (v x9 < pow2 24);
assert_norm (pow2 24 < pow2 40)
#push-options "--z3cliopt smt.arith.nl=false"
val lemma_div264_aux: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 528)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
wide_as_nat5 x / pow2 264 ==
v x4 / pow2 40 + v x5 * pow2 16 + v x6 * pow2 72 + v x7 * pow2 128 + v x8 * pow2 184 + v x9 * pow2 240))
let lemma_div264_aux x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert_norm (pow2 264 == pow2 224 * pow2 40);
assert_norm (pow2 56 == pow2 16 * pow2 40);
assert_norm (pow2 112 == pow2 72 * pow2 40);
assert_norm (pow2 168 == pow2 128 * pow2 40);
assert_norm (pow2 224 == pow2 184 * pow2 40);
assert_norm (pow2 280 == pow2 240 * pow2 40);
assert_norm (0 < pow2 40);
calc (==) {
wide_as_nat5 x / pow2 264;
(==) { FStar.Math.Lemmas.division_multiplication_lemma (wide_as_nat5 x) (pow2 224) (pow2 40) }
(wide_as_nat5 x / pow2 224) / pow2 40;
(==) { lemma_div224 x }
(v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280) / pow2 40;
(==) { _ by (Tactics.mapply (`feq #int #int (fun x -> x / pow2 40)); int_semiring ()) }
(v x4 + (v x5 * pow2 16 + v x6 * pow2 72 + v x7 * pow2 128 + v x8 * pow2 184 + v x9 * pow2 240) * pow2 40) / pow2 40;
(==) { FStar.Math.Lemmas.lemma_div_plus (v x4) (v x5 * pow2 16 + v x6 * pow2 72 + v x7 * pow2 128 + v x8 * pow2 184 + v x9 * pow2 240) (pow2 40) }
v x4 / pow2 40 + v x5 * pow2 16 + v x6 * pow2 72 + v x7 * pow2 128 + v x8 * pow2 184 + v x9 * pow2 240;
}
val lemma_div264_x5: x5:uint64 ->
Lemma (pow2 16 * (v x5 % pow2 40) + v x5 / pow2 40 * pow2 56 == v x5 * pow2 16)
let lemma_div264_x5 x5 =
assert_norm (0 < pow2 24);
calc (==) {
pow2 16 * (v x5 % pow2 40) + v x5 / pow2 40 * pow2 56;
(==) { _ by (Tactics.norm [delta_only [`%pow2]; primops]; int_semiring ()) }
((v x5 / pow2 40) * pow2 40 + v x5 % pow2 40) * pow2 16;
(==) { FStar.Math.Lemmas.euclidean_division_definition (v x5) (pow2 40) }
v x5 * pow2 16;
}
val lemma_div264_x6: x6:uint64 ->
Lemma (pow2 16 * (v x6 % pow2 40) * pow2 56 + v x6 / pow2 40 * pow2 112 == v x6 * pow2 72)
let lemma_div264_x6 x6 =
calc (==) {
pow2 16 * (v x6 % pow2 40) * pow2 56 + v x6 / pow2 40 * pow2 112;
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
((v x6 / pow2 40) * pow2 40 + v x6 % pow2 40) * pow2 72;
(==) { Math.Lemmas.euclidean_division_definition (v x6) (pow2 40) }
v x6 * pow2 72;
}
val lemma_div264_x7: x7:uint64 ->
Lemma (pow2 16 * (v x7 % pow2 40) * pow2 112 + v x7 / pow2 40 * pow2 168 == v x7 * pow2 128)
let lemma_div264_x7 x7 =
calc (==) {
pow2 16 * (v x7 % pow2 40) * pow2 112 + v x7 / pow2 40 * pow2 168;
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
((v x7 / pow2 40) * pow2 40 + v x7 % pow2 40) * pow2 128;
(==) { Math.Lemmas.euclidean_division_definition (v x7) (pow2 40) }
v x7 * pow2 128;
}
val lemma_div264_x8: x8:uint64 ->
Lemma (pow2 16 * (v x8 % pow2 40) * pow2 168 + v x8 / pow2 40 * pow2 224 == v x8 * pow2 184)
let lemma_div264_x8 x8 =
calc (==) {
pow2 16 * (v x8 % pow2 40) * pow2 168 + v x8 / pow2 40 * pow2 224;
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
((v x8 / pow2 40) * pow2 40 + v x8 % pow2 40) * pow2 184;
(==) { Math.Lemmas.euclidean_division_definition (v x8) (pow2 40) }
v x8 * pow2 184;
}
val lemma_div264_x9: x9:uint64{v x9 < pow2 40} ->
Lemma (pow2 16 * (v x9 % pow2 40) * pow2 224 == v x9 * pow2 240)
let lemma_div264_x9 x9 =
calc (==) {
pow2 16 * (v x9 % pow2 40) * pow2 224;
(==) { Math.Lemmas.small_mod (v x9) (pow2 40) }
pow2 16 * v x9 * pow2 224;
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
v x9 * pow2 240;
}
val lemma_div264: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 528)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
let z0 = v x4 / pow2 40 + pow2 16 * (v x5 % pow2 40) in
let z1 = v x5 / pow2 40 + pow2 16 * (v x6 % pow2 40) in
let z2 = v x6 / pow2 40 + pow2 16 * (v x7 % pow2 40) in
let z3 = v x7 / pow2 40 + pow2 16 * (v x8 % pow2 40) in
let z4 = v x8 / pow2 40 + pow2 16 * (v x9 % pow2 40) in
wide_as_nat5 x / pow2 264 == z0 + z1 * pow2 56 + z2 * pow2 112 + z3 * pow2 168 + z4 * pow2 224))
#push-options "--z3rlimit 50"
let lemma_div264 x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
lemma_wide_as_nat_pow528 x;
assert (v x9 < pow2 40);
calc (==) {
(let z0 = v x4 / pow2 40 + pow2 16 * (v x5 % pow2 40) in
let z1 = v x5 / pow2 40 + pow2 16 * (v x6 % pow2 40) in
let z2 = v x6 / pow2 40 + pow2 16 * (v x7 % pow2 40) in
let z3 = v x7 / pow2 40 + pow2 16 * (v x8 % pow2 40) in
let z4 = v x8 / pow2 40 + pow2 16 * (v x9 % pow2 40) in
z0 + z1 * pow2 56 + z2 * pow2 112 + z3 * pow2 168 + z4 * pow2 224);
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
v x4 / pow2 40 + pow2 16 * (v x5 % pow2 40) +
v x5 / pow2 40 * pow2 56 + pow2 16 * (v x6 % pow2 40) * pow2 56 +
v x6 / pow2 40 * pow2 112 + pow2 16 * (v x7 % pow2 40) * pow2 112 +
v x7 / pow2 40 * pow2 168 + pow2 16 * (v x8 % pow2 40) * pow2 168 +
v x8 / pow2 40 * pow2 224 + pow2 16 * (v x9 % pow2 40) * pow2 224;
(==) { lemma_div264_x5 x5; lemma_div264_x6 x6 }
v x4 / pow2 40 + v x5 * pow2 16 + v x6 * pow2 72 +
pow2 16 * (v x7 % pow2 40) * pow2 112 +
v x7 / pow2 40 * pow2 168 + pow2 16 * (v x8 % pow2 40) * pow2 168 +
v x8 / pow2 40 * pow2 224 + pow2 16 * (v x9 % pow2 40) * pow2 224;
(==) { lemma_div264_x7 x7; lemma_div264_x8 x8 }
v x4 / pow2 40 + v x5 * pow2 16 + v x6 * pow2 72 + v x7 * pow2 128 + v x8 * pow2 184 +
pow2 16 * (v x9 % pow2 40) * pow2 224;
(==) { lemma_div264_x9 x9 }
v x4 / pow2 40 + v x5 * pow2 16 + v x6 * pow2 72 + v x7 * pow2 128 + v x8 * pow2 184 + v x9 * pow2 240;
(==) { lemma_div264_aux x }
wide_as_nat5 x / pow2 264;
}
#pop-options
#pop-options // "--z3cliopt smt.arith.nl=false"
val lemma_mod_264_aux: t:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 t (1, 1, 1, 1, 1, 1, 1, 1, 1, 1))
(ensures
(let (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) = t in
(wide_as_nat5 t) % pow2 264 ==
(v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + v t4 * pow2 224) % pow2 264))
#push-options "--z3rlimit 150"
let lemma_mod_264_aux t =
let (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) = t in
let res = (t0, t1, t2, t3, t4 &. u64 0xffffffffff) in
assert_norm (pow2 16 * pow2 264 == pow2 280);
assert_norm (pow2 72 * pow2 264 == pow2 336);
assert_norm (pow2 128 * pow2 264 == pow2 392);
assert_norm (pow2 184 * pow2 264 == pow2 448);
assert_norm (pow2 240 * pow2 264 == pow2 504);
calc (==) {
(wide_as_nat5 t) % pow2 264;
(==) { }
(v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + v t4 * pow2 224 +
(v t5 * pow2 16 + v t6 * pow2 72 + v t7 * pow2 128 + v t8 * pow2 184 + v t9 * pow2 240) * pow2 264) % pow2 264;
(==) { FStar.Math.Lemmas.lemma_mod_add_distr (v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + v t4 * pow2 224)
((v t5 * pow2 16 + v t6 * pow2 72 + v t7 * pow2 128 + v t8 * pow2 184 + v t9 * pow2 240) * pow2 264) (pow2 264)}
((v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + v t4 * pow2 224) +
((v t5 * pow2 16 + v t6 * pow2 72 + v t7 * pow2 128 + v t8 * pow2 184 + v t9 * pow2 240) * pow2 264) % pow2 264) % pow2 264;
(==) { FStar.Math.Lemmas.cancel_mul_mod (v t5 * pow2 16 + v t6 * pow2 72 + v t7 * pow2 128 + v t8 * pow2 184 + v t9 * pow2 240) (pow2 264) }
(v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + v t4 * pow2 224) % pow2 264;
}
#pop-options
val lemma_as_nat_pow264: x:qelem5 ->
Lemma
(requires
(let (x0, x1, x2, x3, x4) = x in
qelem_fits5 x (1, 1, 1, 1, 1) /\
v x4 < pow2 40))
(ensures as_nat5 x < pow2 264)
let lemma_as_nat_pow264 x =
let (x0, x1, x2, x3, x4) = x in
assert_norm (pow2 40 * pow2 224 = pow2 264)
val lemma_mod_264: t:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 t (1, 1, 1, 1, 1, 1, 1, 1, 1, 1))
(ensures
(let (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) = t in
let res = (t0, t1, t2, t3, t4 &. u64 0xffffffffff) in
qelem_fits5 res (1, 1, 1, 1, 1) /\
as_nat5 res == (wide_as_nat5 t) % pow2 264))
let lemma_mod_264 t =
let (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) = t in
let t4' = t4 &. u64 0xffffffffff in
let res = (t0, t1, t2, t3, t4') in
assert_norm (pow2 40 < pow2 64);
assert_norm (pow2 40 - 1 == 0xffffffffff);
mod_mask_lemma t4 40ul;
assert (v (mod_mask #U64 #SEC 40ul) == 0xffffffffff);
assert (v (t4 &. u64 0xffffffffff) == v t4 % pow2 40);
calc (==) {
(wide_as_nat5 t) % pow2 264;
(==) { lemma_mod_264_aux t }
(v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + v t4 * pow2 224) % pow2 264;
(==) { FStar.Math.Lemmas.lemma_mod_add_distr (v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168) (v t4 * pow2 224) (pow2 264) }
(v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + (v t4 * pow2 224) % pow2 264) % pow2 264;
(==) { FStar.Math.Lemmas.pow2_multiplication_modulo_lemma_2 (v t4) 264 224 }
(v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + (v t4 % pow2 40) * pow2 224) % pow2 264;
(==) { lemma_as_nat_pow264 res; FStar.Math.Lemmas.modulo_lemma (as_nat5 res) (pow2 264) }
v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + (v t4 % pow2 40) * pow2 224;
}
val lemma_as_nat_pow264_x4: x:qelem5 ->
Lemma
(requires
qelem_fits5 x (1, 1, 1, 1, 1) /\
as_nat5 x < pow2 264)
(ensures
(let (x0, x1, x2, x3, x4) = x in
v x4 < pow2 40)) | {
"checked_file": "/",
"dependencies": [
"Spec.Ed25519.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.BignumQ.Definitions.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Tactics.CanonCommSemiring.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.BignumQ.Lemmas.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.CanonCommSemiring",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.BignumQ.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.Ed25519",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.CanonCommSemiring",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.BignumQ",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.BignumQ",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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 | x: Hacl.Spec.BignumQ.Definitions.qelem5
-> FStar.Pervasives.Lemma
(requires
Hacl.Spec.BignumQ.Definitions.qelem_fits5 x (1, 1, 1, 1, 1) /\
Hacl.Spec.BignumQ.Definitions.as_nat5 x < Prims.pow2 264)
(ensures
(let _ = x in
(let FStar.Pervasives.Native.Mktuple5 #_ #_ #_ #_ #_ _ _ _ _ x4 = _ in
Lib.IntTypes.v x4 < Prims.pow2 40)
<:
Type0)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Hacl.Spec.BignumQ.Definitions.qelem5",
"Lib.IntTypes.uint64",
"FStar.Pervasives.assert_norm",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"FStar.Mul.op_Star",
"Prims.pow2",
"Prims.unit"
] | [] | false | false | true | false | false | let lemma_as_nat_pow264_x4 x =
| let x0, x1, x2, x3, x4 = x in
assert_norm (pow2 40 * pow2 224 = pow2 264) | false |
SfBasic.fst | SfBasic.pred | val pred : nat -> Tot nat | val pred : nat -> Tot nat | let pred n =
match n with
| O -> O
| S n' -> n' | {
"file_name": "examples/software_foundations/SfBasic.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 16,
"end_line": 101,
"start_col": 0,
"start_line": 98
} | (*
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.
*)
(*
A translation to F* of Basics.v from Software Foundations
Original name: "Basics: Functional Programming in Coq"
*)
module SfBasic
type day =
| Monday
| Tuesday
| Wednesday
| Thursday
| Friday
| Saturday
| Sunday
val next_weekday : day -> Tot day
let next_weekday d =
match d with
| Monday -> Tuesday
| Tuesday -> Wednesday
| Wednesday -> Thursday
| Thursday -> Friday
| Friday -> Monday
| Saturday -> Monday
| Sunday -> Monday
val test_next_weekday : unit -> Lemma
(ensures ((next_weekday (next_weekday Saturday)) = Tuesday))
let test_next_weekday () = ()
(* Booleans *)
(* The original example calls these bool, True, and False,
and that doesn't seem to cause problems;
I've just renamed them to be 100% sure that's not the cause
of the troubles in this file *)
type mbool =
| MTrue
| MFalse
val negb : mbool -> Tot mbool
let negb b =
match b with
| MTrue -> MFalse
| MFalse -> MTrue
val andb : mbool -> mbool -> Tot mbool
let andb b1 b2 =
match b1 with
| MTrue -> b2
| MFalse -> MFalse
val orb : mbool -> mbool -> Tot mbool
let orb b1 b2 =
match b1 with
| MTrue -> MTrue
| MFalse -> b2
val test_orb1 : unit -> Lemma
(ensures ((orb MTrue MFalse) = MTrue))
let test_orb1 () = ()
val test_orb2 : unit -> Lemma
(ensures ((orb MFalse MFalse) = MFalse))
let test_orb2 () = ()
val test_orb3 : unit -> Lemma
(ensures ((orb MFalse MTrue) = MTrue))
let test_orb3 () = ()
val test_orb4 : unit -> Lemma
(ensures ((orb MTrue MTrue) = MTrue))
let test_orb4 () = ()
(* Numbers *)
type nat =
| O : nat
| S : nat -> nat | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "SfBasic.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | n: SfBasic.nat -> SfBasic.nat | Prims.Tot | [
"total"
] | [] | [
"SfBasic.nat",
"SfBasic.O"
] | [] | false | false | false | true | false | let pred n =
| match n with
| O -> O
| S n' -> n' | false |
SfBasic.fst | SfBasic.minustwo | val minustwo : nat -> Tot nat | val minustwo : nat -> Tot nat | let minustwo n =
match n with
| O -> O
| S O -> O
| S (S n') -> n' | {
"file_name": "examples/software_foundations/SfBasic.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 20,
"end_line": 108,
"start_col": 0,
"start_line": 104
} | (*
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.
*)
(*
A translation to F* of Basics.v from Software Foundations
Original name: "Basics: Functional Programming in Coq"
*)
module SfBasic
type day =
| Monday
| Tuesday
| Wednesday
| Thursday
| Friday
| Saturday
| Sunday
val next_weekday : day -> Tot day
let next_weekday d =
match d with
| Monday -> Tuesday
| Tuesday -> Wednesday
| Wednesday -> Thursday
| Thursday -> Friday
| Friday -> Monday
| Saturday -> Monday
| Sunday -> Monday
val test_next_weekday : unit -> Lemma
(ensures ((next_weekday (next_weekday Saturday)) = Tuesday))
let test_next_weekday () = ()
(* Booleans *)
(* The original example calls these bool, True, and False,
and that doesn't seem to cause problems;
I've just renamed them to be 100% sure that's not the cause
of the troubles in this file *)
type mbool =
| MTrue
| MFalse
val negb : mbool -> Tot mbool
let negb b =
match b with
| MTrue -> MFalse
| MFalse -> MTrue
val andb : mbool -> mbool -> Tot mbool
let andb b1 b2 =
match b1 with
| MTrue -> b2
| MFalse -> MFalse
val orb : mbool -> mbool -> Tot mbool
let orb b1 b2 =
match b1 with
| MTrue -> MTrue
| MFalse -> b2
val test_orb1 : unit -> Lemma
(ensures ((orb MTrue MFalse) = MTrue))
let test_orb1 () = ()
val test_orb2 : unit -> Lemma
(ensures ((orb MFalse MFalse) = MFalse))
let test_orb2 () = ()
val test_orb3 : unit -> Lemma
(ensures ((orb MFalse MTrue) = MTrue))
let test_orb3 () = ()
val test_orb4 : unit -> Lemma
(ensures ((orb MTrue MTrue) = MTrue))
let test_orb4 () = ()
(* Numbers *)
type nat =
| O : nat
| S : nat -> nat
val pred : nat -> Tot nat
let pred n =
match n with
| O -> O
| S n' -> n' | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "SfBasic.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | n: SfBasic.nat -> SfBasic.nat | Prims.Tot | [
"total"
] | [] | [
"SfBasic.nat",
"SfBasic.O"
] | [] | false | false | false | true | false | let minustwo n =
| match n with
| O -> O
| S O -> O
| S (S n') -> n' | false |
SfBasic.fst | SfBasic.evenb | val evenb : nat -> Tot mbool | val evenb : nat -> Tot mbool | let rec evenb n =
match n with
| O -> MTrue
| S O -> MFalse
| S (S n') -> evenb n' | {
"file_name": "examples/software_foundations/SfBasic.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 24,
"end_line": 115,
"start_col": 0,
"start_line": 111
} | (*
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.
*)
(*
A translation to F* of Basics.v from Software Foundations
Original name: "Basics: Functional Programming in Coq"
*)
module SfBasic
type day =
| Monday
| Tuesday
| Wednesday
| Thursday
| Friday
| Saturday
| Sunday
val next_weekday : day -> Tot day
let next_weekday d =
match d with
| Monday -> Tuesday
| Tuesday -> Wednesday
| Wednesday -> Thursday
| Thursday -> Friday
| Friday -> Monday
| Saturday -> Monday
| Sunday -> Monday
val test_next_weekday : unit -> Lemma
(ensures ((next_weekday (next_weekday Saturday)) = Tuesday))
let test_next_weekday () = ()
(* Booleans *)
(* The original example calls these bool, True, and False,
and that doesn't seem to cause problems;
I've just renamed them to be 100% sure that's not the cause
of the troubles in this file *)
type mbool =
| MTrue
| MFalse
val negb : mbool -> Tot mbool
let negb b =
match b with
| MTrue -> MFalse
| MFalse -> MTrue
val andb : mbool -> mbool -> Tot mbool
let andb b1 b2 =
match b1 with
| MTrue -> b2
| MFalse -> MFalse
val orb : mbool -> mbool -> Tot mbool
let orb b1 b2 =
match b1 with
| MTrue -> MTrue
| MFalse -> b2
val test_orb1 : unit -> Lemma
(ensures ((orb MTrue MFalse) = MTrue))
let test_orb1 () = ()
val test_orb2 : unit -> Lemma
(ensures ((orb MFalse MFalse) = MFalse))
let test_orb2 () = ()
val test_orb3 : unit -> Lemma
(ensures ((orb MFalse MTrue) = MTrue))
let test_orb3 () = ()
val test_orb4 : unit -> Lemma
(ensures ((orb MTrue MTrue) = MTrue))
let test_orb4 () = ()
(* Numbers *)
type nat =
| O : nat
| S : nat -> nat
val pred : nat -> Tot nat
let pred n =
match n with
| O -> O
| S n' -> n'
val minustwo : nat -> Tot nat
let minustwo n =
match n with
| O -> O
| S O -> O
| S (S n') -> n' | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "SfBasic.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | n: SfBasic.nat -> SfBasic.mbool | Prims.Tot | [
"total"
] | [] | [
"SfBasic.nat",
"SfBasic.MTrue",
"SfBasic.MFalse",
"SfBasic.evenb",
"SfBasic.mbool"
] | [
"recursion"
] | false | false | false | true | false | let rec evenb n =
| match n with
| O -> MTrue
| S O -> MFalse
| S (S n') -> evenb n' | false |
SfBasic.fst | SfBasic.plus | val plus : nat -> nat -> Tot nat | val plus : nat -> nat -> Tot nat | let rec plus n m =
match n with
| O -> m
| S n' -> S (plus n' m) | {
"file_name": "examples/software_foundations/SfBasic.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 27,
"end_line": 132,
"start_col": 0,
"start_line": 129
} | (*
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.
*)
(*
A translation to F* of Basics.v from Software Foundations
Original name: "Basics: Functional Programming in Coq"
*)
module SfBasic
type day =
| Monday
| Tuesday
| Wednesday
| Thursday
| Friday
| Saturday
| Sunday
val next_weekday : day -> Tot day
let next_weekday d =
match d with
| Monday -> Tuesday
| Tuesday -> Wednesday
| Wednesday -> Thursday
| Thursday -> Friday
| Friday -> Monday
| Saturday -> Monday
| Sunday -> Monday
val test_next_weekday : unit -> Lemma
(ensures ((next_weekday (next_weekday Saturday)) = Tuesday))
let test_next_weekday () = ()
(* Booleans *)
(* The original example calls these bool, True, and False,
and that doesn't seem to cause problems;
I've just renamed them to be 100% sure that's not the cause
of the troubles in this file *)
type mbool =
| MTrue
| MFalse
val negb : mbool -> Tot mbool
let negb b =
match b with
| MTrue -> MFalse
| MFalse -> MTrue
val andb : mbool -> mbool -> Tot mbool
let andb b1 b2 =
match b1 with
| MTrue -> b2
| MFalse -> MFalse
val orb : mbool -> mbool -> Tot mbool
let orb b1 b2 =
match b1 with
| MTrue -> MTrue
| MFalse -> b2
val test_orb1 : unit -> Lemma
(ensures ((orb MTrue MFalse) = MTrue))
let test_orb1 () = ()
val test_orb2 : unit -> Lemma
(ensures ((orb MFalse MFalse) = MFalse))
let test_orb2 () = ()
val test_orb3 : unit -> Lemma
(ensures ((orb MFalse MTrue) = MTrue))
let test_orb3 () = ()
val test_orb4 : unit -> Lemma
(ensures ((orb MTrue MTrue) = MTrue))
let test_orb4 () = ()
(* Numbers *)
type nat =
| O : nat
| S : nat -> nat
val pred : nat -> Tot nat
let pred n =
match n with
| O -> O
| S n' -> n'
val minustwo : nat -> Tot nat
let minustwo n =
match n with
| O -> O
| S O -> O
| S (S n') -> n'
val evenb : nat -> Tot mbool
let rec evenb n =
match n with
| O -> MTrue
| S O -> MFalse
| S (S n') -> evenb n'
val oddb : nat -> Tot mbool
let oddb n = negb (evenb n)
val test_oddb1 : unit -> Lemma
(ensures ((oddb (S O)) = MTrue))
let test_oddb1 () = ()
val test_oddb2 : unit -> Lemma
(ensures (oddb (S (S (S (S O)))) = MFalse))
let test_oddb2 () = () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "SfBasic.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | n: SfBasic.nat -> m: SfBasic.nat -> SfBasic.nat | Prims.Tot | [
"total"
] | [] | [
"SfBasic.nat",
"SfBasic.S",
"SfBasic.plus"
] | [
"recursion"
] | false | false | false | true | false | let rec plus n m =
| match n with
| O -> m
| S n' -> S (plus n' m) | false |
SfBasic.fst | SfBasic.beq_nat | val beq_nat : nat -> nat -> Tot mbool | val beq_nat : nat -> nat -> Tot mbool | let rec beq_nat n m =
match n, m with
| O , O -> MTrue
| S n', S m' -> beq_nat n' m'
| _ , _ -> MFalse | {
"file_name": "examples/software_foundations/SfBasic.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 24,
"end_line": 157,
"start_col": 0,
"start_line": 153
} | (*
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.
*)
(*
A translation to F* of Basics.v from Software Foundations
Original name: "Basics: Functional Programming in Coq"
*)
module SfBasic
type day =
| Monday
| Tuesday
| Wednesday
| Thursday
| Friday
| Saturday
| Sunday
val next_weekday : day -> Tot day
let next_weekday d =
match d with
| Monday -> Tuesday
| Tuesday -> Wednesday
| Wednesday -> Thursday
| Thursday -> Friday
| Friday -> Monday
| Saturday -> Monday
| Sunday -> Monday
val test_next_weekday : unit -> Lemma
(ensures ((next_weekday (next_weekday Saturday)) = Tuesday))
let test_next_weekday () = ()
(* Booleans *)
(* The original example calls these bool, True, and False,
and that doesn't seem to cause problems;
I've just renamed them to be 100% sure that's not the cause
of the troubles in this file *)
type mbool =
| MTrue
| MFalse
val negb : mbool -> Tot mbool
let negb b =
match b with
| MTrue -> MFalse
| MFalse -> MTrue
val andb : mbool -> mbool -> Tot mbool
let andb b1 b2 =
match b1 with
| MTrue -> b2
| MFalse -> MFalse
val orb : mbool -> mbool -> Tot mbool
let orb b1 b2 =
match b1 with
| MTrue -> MTrue
| MFalse -> b2
val test_orb1 : unit -> Lemma
(ensures ((orb MTrue MFalse) = MTrue))
let test_orb1 () = ()
val test_orb2 : unit -> Lemma
(ensures ((orb MFalse MFalse) = MFalse))
let test_orb2 () = ()
val test_orb3 : unit -> Lemma
(ensures ((orb MFalse MTrue) = MTrue))
let test_orb3 () = ()
val test_orb4 : unit -> Lemma
(ensures ((orb MTrue MTrue) = MTrue))
let test_orb4 () = ()
(* Numbers *)
type nat =
| O : nat
| S : nat -> nat
val pred : nat -> Tot nat
let pred n =
match n with
| O -> O
| S n' -> n'
val minustwo : nat -> Tot nat
let minustwo n =
match n with
| O -> O
| S O -> O
| S (S n') -> n'
val evenb : nat -> Tot mbool
let rec evenb n =
match n with
| O -> MTrue
| S O -> MFalse
| S (S n') -> evenb n'
val oddb : nat -> Tot mbool
let oddb n = negb (evenb n)
val test_oddb1 : unit -> Lemma
(ensures ((oddb (S O)) = MTrue))
let test_oddb1 () = ()
val test_oddb2 : unit -> Lemma
(ensures (oddb (S (S (S (S O)))) = MFalse))
let test_oddb2 () = ()
val plus : nat -> nat -> Tot nat
let rec plus n m =
match n with
| O -> m
| S n' -> S (plus n' m)
val mult : nat -> nat -> Tot nat
let rec mult n m =
match n with
| O -> O
| S n' -> plus m (mult n' m)
val test_mult1 : unit -> Lemma
(ensures (mult (S (S (S O))) (S (S (S O))))
= (S (S (S (S (S (S (S (S (S O))))))))))
let test_mult1 () = ()
val minus : nat -> nat -> Tot nat
let rec minus (n : nat) (m : nat) : nat =
match n, m with
| O , _ -> O
| S _ , O -> n
| S n', S m' -> minus n' m' | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "SfBasic.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | n: SfBasic.nat -> m: SfBasic.nat -> SfBasic.mbool | Prims.Tot | [
"total"
] | [] | [
"SfBasic.nat",
"FStar.Pervasives.Native.Mktuple2",
"SfBasic.MTrue",
"SfBasic.beq_nat",
"SfBasic.MFalse",
"SfBasic.mbool"
] | [
"recursion"
] | false | false | false | true | false | let rec beq_nat n m =
| match n, m with
| O, O -> MTrue
| S n', S m' -> beq_nat n' m'
| _, _ -> MFalse | false |
SfBasic.fst | SfBasic.minus | val minus : nat -> nat -> Tot nat | val minus : nat -> nat -> Tot nat | let rec minus (n : nat) (m : nat) : nat =
match n, m with
| O , _ -> O
| S _ , O -> n
| S n', S m' -> minus n' m' | {
"file_name": "examples/software_foundations/SfBasic.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 29,
"end_line": 150,
"start_col": 0,
"start_line": 146
} | (*
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.
*)
(*
A translation to F* of Basics.v from Software Foundations
Original name: "Basics: Functional Programming in Coq"
*)
module SfBasic
type day =
| Monday
| Tuesday
| Wednesday
| Thursday
| Friday
| Saturday
| Sunday
val next_weekday : day -> Tot day
let next_weekday d =
match d with
| Monday -> Tuesday
| Tuesday -> Wednesday
| Wednesday -> Thursday
| Thursday -> Friday
| Friday -> Monday
| Saturday -> Monday
| Sunday -> Monday
val test_next_weekday : unit -> Lemma
(ensures ((next_weekday (next_weekday Saturday)) = Tuesday))
let test_next_weekday () = ()
(* Booleans *)
(* The original example calls these bool, True, and False,
and that doesn't seem to cause problems;
I've just renamed them to be 100% sure that's not the cause
of the troubles in this file *)
type mbool =
| MTrue
| MFalse
val negb : mbool -> Tot mbool
let negb b =
match b with
| MTrue -> MFalse
| MFalse -> MTrue
val andb : mbool -> mbool -> Tot mbool
let andb b1 b2 =
match b1 with
| MTrue -> b2
| MFalse -> MFalse
val orb : mbool -> mbool -> Tot mbool
let orb b1 b2 =
match b1 with
| MTrue -> MTrue
| MFalse -> b2
val test_orb1 : unit -> Lemma
(ensures ((orb MTrue MFalse) = MTrue))
let test_orb1 () = ()
val test_orb2 : unit -> Lemma
(ensures ((orb MFalse MFalse) = MFalse))
let test_orb2 () = ()
val test_orb3 : unit -> Lemma
(ensures ((orb MFalse MTrue) = MTrue))
let test_orb3 () = ()
val test_orb4 : unit -> Lemma
(ensures ((orb MTrue MTrue) = MTrue))
let test_orb4 () = ()
(* Numbers *)
type nat =
| O : nat
| S : nat -> nat
val pred : nat -> Tot nat
let pred n =
match n with
| O -> O
| S n' -> n'
val minustwo : nat -> Tot nat
let minustwo n =
match n with
| O -> O
| S O -> O
| S (S n') -> n'
val evenb : nat -> Tot mbool
let rec evenb n =
match n with
| O -> MTrue
| S O -> MFalse
| S (S n') -> evenb n'
val oddb : nat -> Tot mbool
let oddb n = negb (evenb n)
val test_oddb1 : unit -> Lemma
(ensures ((oddb (S O)) = MTrue))
let test_oddb1 () = ()
val test_oddb2 : unit -> Lemma
(ensures (oddb (S (S (S (S O)))) = MFalse))
let test_oddb2 () = ()
val plus : nat -> nat -> Tot nat
let rec plus n m =
match n with
| O -> m
| S n' -> S (plus n' m)
val mult : nat -> nat -> Tot nat
let rec mult n m =
match n with
| O -> O
| S n' -> plus m (mult n' m)
val test_mult1 : unit -> Lemma
(ensures (mult (S (S (S O))) (S (S (S O))))
= (S (S (S (S (S (S (S (S (S O))))))))))
let test_mult1 () = () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "SfBasic.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | n: SfBasic.nat -> m: SfBasic.nat -> SfBasic.nat | Prims.Tot | [
"total"
] | [] | [
"SfBasic.nat",
"FStar.Pervasives.Native.Mktuple2",
"SfBasic.O",
"SfBasic.minus"
] | [
"recursion"
] | false | false | false | true | false | let rec minus (n m: nat) : nat =
| match n, m with
| O, _ -> O
| S _, O -> n
| S n', S m' -> minus n' m' | false |
SfBasic.fst | SfBasic.mult | val mult : nat -> nat -> Tot nat | val mult : nat -> nat -> Tot nat | let rec mult n m =
match n with
| O -> O
| S n' -> plus m (mult n' m) | {
"file_name": "examples/software_foundations/SfBasic.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 32,
"end_line": 138,
"start_col": 0,
"start_line": 135
} | (*
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.
*)
(*
A translation to F* of Basics.v from Software Foundations
Original name: "Basics: Functional Programming in Coq"
*)
module SfBasic
type day =
| Monday
| Tuesday
| Wednesday
| Thursday
| Friday
| Saturday
| Sunday
val next_weekday : day -> Tot day
let next_weekday d =
match d with
| Monday -> Tuesday
| Tuesday -> Wednesday
| Wednesday -> Thursday
| Thursday -> Friday
| Friday -> Monday
| Saturday -> Monday
| Sunday -> Monday
val test_next_weekday : unit -> Lemma
(ensures ((next_weekday (next_weekday Saturday)) = Tuesday))
let test_next_weekday () = ()
(* Booleans *)
(* The original example calls these bool, True, and False,
and that doesn't seem to cause problems;
I've just renamed them to be 100% sure that's not the cause
of the troubles in this file *)
type mbool =
| MTrue
| MFalse
val negb : mbool -> Tot mbool
let negb b =
match b with
| MTrue -> MFalse
| MFalse -> MTrue
val andb : mbool -> mbool -> Tot mbool
let andb b1 b2 =
match b1 with
| MTrue -> b2
| MFalse -> MFalse
val orb : mbool -> mbool -> Tot mbool
let orb b1 b2 =
match b1 with
| MTrue -> MTrue
| MFalse -> b2
val test_orb1 : unit -> Lemma
(ensures ((orb MTrue MFalse) = MTrue))
let test_orb1 () = ()
val test_orb2 : unit -> Lemma
(ensures ((orb MFalse MFalse) = MFalse))
let test_orb2 () = ()
val test_orb3 : unit -> Lemma
(ensures ((orb MFalse MTrue) = MTrue))
let test_orb3 () = ()
val test_orb4 : unit -> Lemma
(ensures ((orb MTrue MTrue) = MTrue))
let test_orb4 () = ()
(* Numbers *)
type nat =
| O : nat
| S : nat -> nat
val pred : nat -> Tot nat
let pred n =
match n with
| O -> O
| S n' -> n'
val minustwo : nat -> Tot nat
let minustwo n =
match n with
| O -> O
| S O -> O
| S (S n') -> n'
val evenb : nat -> Tot mbool
let rec evenb n =
match n with
| O -> MTrue
| S O -> MFalse
| S (S n') -> evenb n'
val oddb : nat -> Tot mbool
let oddb n = negb (evenb n)
val test_oddb1 : unit -> Lemma
(ensures ((oddb (S O)) = MTrue))
let test_oddb1 () = ()
val test_oddb2 : unit -> Lemma
(ensures (oddb (S (S (S (S O)))) = MFalse))
let test_oddb2 () = ()
val plus : nat -> nat -> Tot nat
let rec plus n m =
match n with
| O -> m
| S n' -> S (plus n' m) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "SfBasic.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | n: SfBasic.nat -> m: SfBasic.nat -> SfBasic.nat | Prims.Tot | [
"total"
] | [] | [
"SfBasic.nat",
"SfBasic.O",
"SfBasic.plus",
"SfBasic.mult"
] | [
"recursion"
] | false | false | false | true | false | let rec mult n m =
| match n with
| O -> O
| S n' -> plus m (mult n' m) | false |
Hacl.Spec.BignumQ.Lemmas.fst | Hacl.Spec.BignumQ.Lemmas.lemma_sub_mod_264 | val lemma_sub_mod_264:
x:qelem5
-> y:qelem5
-> t:qelem5
-> c5:uint64 ->
Lemma
(requires
qelem_fits5 x (1, 1, 1, 1, 1) /\
qelem_fits5 y (1, 1, 1, 1, 1) /\
qelem_fits5 t (1, 1, 1, 1, 1) /\
as_nat5 x < pow2 264 /\
as_nat5 y < pow2 264 /\
as_nat5 t == as_nat5 x - as_nat5 y + v c5 * pow2 264 /\ v c5 <= 1 /\
(if v c5 = 0 then as_nat5 x >= as_nat5 y else as_nat5 x < as_nat5 y))
(ensures
(if as_nat5 x >= as_nat5 y then
as_nat5 t == as_nat5 x - as_nat5 y
else as_nat5 t == as_nat5 x - as_nat5 y + pow2 264)) | val lemma_sub_mod_264:
x:qelem5
-> y:qelem5
-> t:qelem5
-> c5:uint64 ->
Lemma
(requires
qelem_fits5 x (1, 1, 1, 1, 1) /\
qelem_fits5 y (1, 1, 1, 1, 1) /\
qelem_fits5 t (1, 1, 1, 1, 1) /\
as_nat5 x < pow2 264 /\
as_nat5 y < pow2 264 /\
as_nat5 t == as_nat5 x - as_nat5 y + v c5 * pow2 264 /\ v c5 <= 1 /\
(if v c5 = 0 then as_nat5 x >= as_nat5 y else as_nat5 x < as_nat5 y))
(ensures
(if as_nat5 x >= as_nat5 y then
as_nat5 t == as_nat5 x - as_nat5 y
else as_nat5 t == as_nat5 x - as_nat5 y + pow2 264)) | let lemma_sub_mod_264 x y t c5 =
assert (if v c5 = 0 then as_nat5 x >= as_nat5 y else as_nat5 x < as_nat5 y);
assert (as_nat5 t == as_nat5 x - as_nat5 y + v c5 * pow2 264);
if as_nat5 x >= as_nat5 y then
assert (v c5 == 0 /\ as_nat5 t == as_nat5 x - as_nat5 y)
else
assert (v c5 == 1 /\ as_nat5 t == as_nat5 x - as_nat5 y + pow2 264) | {
"file_name": "code/ed25519/Hacl.Spec.BignumQ.Lemmas.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 71,
"end_line": 610,
"start_col": 0,
"start_line": 604
} | module Hacl.Spec.BignumQ.Lemmas
open FStar.Tactics.CanonCommSemiring
open FStar.Mul
open Lib.IntTypes
module S = Spec.Ed25519
include Hacl.Spec.BignumQ.Definitions
let feq (#a #b:Type) (f:(a -> b)) (x y:a) :
Lemma (requires x == y) (ensures f x == f y) = ()
let eq_eq2 (#a:eqtype) (x y:a) :
Lemma (requires x = y) (ensures x == y) = ()
val lemma_mul_lt:a:nat -> b:nat -> c:nat -> d:nat ->
Lemma
(requires a < b /\ c < d)
(ensures a * c < b * d)
let lemma_mul_lt a b c d = ()
val lemma_as_nat5: f:qelem5 ->
Lemma
(requires qelem_fits5 f (1, 1, 1, 1, 1))
(ensures as_nat5 f < pow2 280)
let lemma_as_nat5 f =
//let (f0, f1, f2, f3, f4) = f in
//assert (as_nat5 f == v f0 + v f1 * pow56 + v f2 * pow112 + v f3 * pow168 + v f4 * pow224);
assert_norm (pow2 56 * pow2 56 = pow2 112);
assert_norm (pow2 56 * pow2 112 = pow2 168);
assert_norm (pow2 56 * pow2 168 = pow2 224);
assert_norm (pow2 56 * pow2 224 = pow2 280)
val lemma_choose_step:
bit:uint64{v bit <= 1}
-> x:uint64
-> y:uint64
-> Lemma
(let mask = bit -. u64 1 in
let z = x ^. (mask &. (x ^. y)) in
if v bit = 1 then z == x else z == y)
let lemma_choose_step bit p1 p2 =
let mask = bit -. u64 1 in
assert (v bit == 0 ==> v mask == pow2 64 - 1);
assert (v bit == 1 ==> v mask == 0);
let dummy = mask &. (p1 ^. p2) in
logand_lemma mask (p1 ^. p2);
assert (v bit == 1 ==> v dummy == 0);
assert (v bit == 0 ==> v dummy == v (p1 ^. p2));
let p1' = p1 ^. dummy in
assert (v dummy == v (if v bit = 1 then u64 0 else (p1 ^. p2)));
logxor_lemma p1 p2
val lemma_subm_conditional:
x0:nat -> x1:nat -> x2:nat -> x3:nat -> x4:nat
-> y0:nat -> y1:nat -> y2:nat -> y3:nat -> y4:nat
-> b0:nat -> b1:nat -> b2:nat -> b3:nat -> b4:nat ->
Lemma (
x0 - y0 + b0 * pow2 56 +
(x1 - y1 - b0 + b1 * pow2 56) * pow2 56 +
(x2 - y2 - b1 + b2 * pow2 56) * pow2 112 +
(x3 - y3 - b2 + b3 * pow2 56) * pow2 168 +
(x4 - y4 - b3 + b4 * pow2 56) * pow2 224 ==
(x0 + x1 * pow2 56 + x2 * pow2 112 + x3 * pow2 168 + x4 * pow2 224) -
(y0 + y1 * pow2 56 + y2 * pow2 112 + y3 * pow2 168 + y4 * pow2 224) + b4 * pow2 280)
let lemma_subm_conditional x0 x1 x2 x3 x4 y0 y1 y2 y3 y4 b0 b1 b2 b3 b4 =
assert_norm (pow2 56 * pow2 56 = pow2 112);
assert_norm (pow2 56 * pow2 112 = pow2 168);
assert_norm (pow2 56 * pow2 168 = pow2 224);
assert_norm (pow2 56 * pow2 224 = pow2 280);
assert (
x0 - y0 + b0 * pow2 56 +
(x1 - y1 - b0 + b1 * pow2 56) * pow2 56 +
(x2 - y2 - b1 + b2 * pow2 56) * pow2 112 +
(x3 - y3 - b2 + b3 * pow2 56) * pow2 168 +
(x4 - y4 - b3 + b4 * pow2 56) * pow2 224 ==
(x0 + x1 * pow2 56 + x2 * pow2 112 + x3 * pow2 168 + x4 * pow2 224) -
(y0 + y1 * pow2 56 + y2 * pow2 112 + y3 * pow2 168 + y4 * pow2 224) + b4 * pow2 280)
by (int_semiring ());
()
val lemma_div224: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1))
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
wide_as_nat5 x / pow2 224 ==
v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280))
#push-options "--z3rlimit 50"
let lemma_div224 x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert
(wide_as_nat5 x ==
v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168 + v x4 * pow2 224 +
v x5 * pow2 280 + v x6 * pow2 336 + v x7 * pow2 392 + v x8 * pow2 448 + v x9 * pow2 504);
assert_norm (pow2 56 * pow2 224 == pow2 280);
assert_norm (pow2 112 * pow2 224 == pow2 336);
assert_norm (pow2 168 * pow2 224 == pow2 392);
assert_norm (pow2 224 * pow2 224 == pow2 448);
assert_norm (pow2 280 * pow2 224 == pow2 504);
calc (==) {
wide_as_nat5 x / pow2 224;
(==) { }
(v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168 +
(v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280) * pow2 224) / pow2 224;
(==) {
FStar.Math.Lemmas.lemma_div_plus
(v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168)
(v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280) (pow2 224) }
(v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168) / pow2 224 +
v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280;
(==) { FStar.Math.Lemmas.small_division_lemma_1 (v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168) (pow2 224) }
v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280;
}
#pop-options
val lemma_div248_aux: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 512)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
wide_as_nat5 x / pow2 248 ==
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256))
open FStar.Tactics.CanonCommSemiring
#push-options "--z3cliopt smt.arith.nl=false"
let lemma_div248_aux x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert_norm (pow2 248 == pow2 224 * pow2 24);
assert_norm (pow2 56 == pow2 32 * pow2 24);
assert_norm (pow2 112 == pow2 88 * pow2 24);
assert_norm (pow2 168 == pow2 144 * pow2 24);
assert_norm (pow2 224 == pow2 200 * pow2 24);
assert_norm (pow2 280 == pow2 256 * pow2 24);
assert_norm (0 < pow2 24);
calc (==) {
wide_as_nat5 x / pow2 248;
(==) { FStar.Math.Lemmas.division_multiplication_lemma (wide_as_nat5 x) (pow2 224) (pow2 24) }
(wide_as_nat5 x / pow2 224) / pow2 24;
(==) { lemma_div224 x }
(v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280) / pow2 24;
(==) { _ by (Tactics.mapply (`feq #int #int (fun x -> x / pow2 24)); int_semiring ()) } (v x4 + (v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256) * pow2 24) / pow2 24;
(==) { FStar.Math.Lemmas.lemma_div_plus (v x4) (v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256) (pow2 24) }
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256;
}
#pop-options
val lemma_div248_x5: x5:uint64 ->
Lemma ( pow2 32 * (v x5 % pow2 24) + v x5 / pow2 24 * pow2 56 == v x5 * pow2 32)
let lemma_div248_x5 x5 =
assert_norm (pow2 32 * pow2 24 = pow2 56)
val lemma_div248_x6: x6:uint64 ->
Lemma (pow2 32 * (v x6 % pow2 24) * pow2 56 + v x6 / pow2 24 * pow2 112 == v x6 * pow2 88)
let lemma_div248_x6 x6 =
calc (==) {
pow2 32 * (v x6 % pow2 24) * pow2 56 + v x6 / pow2 24 * pow2 112;
(==) { _ by (Tactics.norm [delta_only [`%pow2]; primops]; int_semiring ()) }
((v x6 / pow2 24) * pow2 24 + v x6 % pow2 24) * pow2 88;
(==) { FStar.Math.Lemmas.euclidean_division_definition (v x6) (pow2 24) }
v x6 * pow2 88;
}
val lemma_div248_x7: x7:uint64 ->
Lemma (pow2 32 * (v x7 % pow2 24) * pow2 112 + v x7 / pow2 24 * pow2 168 == v x7 * pow2 144)
let lemma_div248_x7 x7 =
calc (==) {
pow2 32 * (v x7 % pow2 24) * pow2 112 + v x7 / pow2 24 * pow2 168;
(==) { _ by (Tactics.norm [delta_only [`%pow2]; primops]; int_semiring ()) }
((v x7 / pow2 24) * pow2 24 + v x7 % pow2 24) * pow2 144;
(==) { FStar.Math.Lemmas.euclidean_division_definition (v x7) (pow2 24) }
v x7 * pow2 144;
}
val lemma_div248_x8: x8:uint64 ->
Lemma (pow2 32 * (v x8 % pow2 24) * pow2 168 + v x8 / pow2 24 * pow2 224 == v x8 * pow2 200)
let lemma_div248_x8 x8 =
calc (==) {
pow2 32 * (v x8 % pow2 24) * pow2 168 + v x8 / pow2 24 * pow2 224;
(==) { _ by (Tactics.norm [delta_only [`%pow2]; primops]; int_semiring ()) }
((v x8 / pow2 24) * pow2 24 + v x8 % pow2 24) * pow2 200;
(==) { FStar.Math.Lemmas.euclidean_division_definition (v x8) (pow2 24) }
v x8 * pow2 200;
}
val lemma_div248_x9: x9:uint64{v x9 < pow2 24} ->
Lemma (pow2 32 * (v x9 % pow2 24) * pow2 224 == v x9 * pow2 256)
let lemma_div248_x9 x9 =
calc (==) {
pow2 32 * (v x9 % pow2 24) * pow2 224;
(==) { Math.Lemmas.small_mod (v x9) (pow2 24) }
pow2 32 * v x9 * pow2 224;
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
v x9 * pow2 256;
}
val lemma_wide_as_nat_pow512: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 512)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
v x9 < pow2 24))
let lemma_wide_as_nat_pow512 x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert_norm (pow2 504 * pow2 8 = pow2 512);
FStar.Math.Lemmas.pow2_minus 512 504;
assert (v x9 < pow2 8);
assert_norm (pow2 8 < pow2 24)
val lemma_div248: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 512)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
let z0 = v x4 / pow2 24 + pow2 32 * (v x5 % pow2 24) in
let z1 = v x5 / pow2 24 + pow2 32 * (v x6 % pow2 24) in
let z2 = v x6 / pow2 24 + pow2 32 * (v x7 % pow2 24) in
let z3 = v x7 / pow2 24 + pow2 32 * (v x8 % pow2 24) in
let z4 = v x8 / pow2 24 + pow2 32 * (v x9 % pow2 24) in
wide_as_nat5 x / pow2 248 == z0 + z1 * pow2 56 + z2 * pow2 112 + z3 * pow2 168 + z4 * pow2 224))
#push-options "--z3rlimit 50"
let lemma_div248 x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
lemma_wide_as_nat_pow512 x;
assert (v x9 < pow2 24);
calc (==) {
(let z0 = v x4 / pow2 24 + pow2 32 * (v x5 % pow2 24) in
let z1 = v x5 / pow2 24 + pow2 32 * (v x6 % pow2 24) in
let z2 = v x6 / pow2 24 + pow2 32 * (v x7 % pow2 24) in
let z3 = v x7 / pow2 24 + pow2 32 * (v x8 % pow2 24) in
let z4 = v x8 / pow2 24 + pow2 32 * (v x9 % pow2 24) in
z0 + z1 * pow2 56 + z2 * pow2 112 + z3 * pow2 168 + z4 * pow2 224);
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
v x4 / pow2 24 + pow2 32 * (v x5 % pow2 24) +
v x5 / pow2 24 * pow2 56 + pow2 32 * (v x6 % pow2 24) * pow2 56 +
v x6 / pow2 24 * pow2 112 + pow2 32 * (v x7 % pow2 24) * pow2 112 +
v x7 / pow2 24 * pow2 168 + pow2 32 * (v x8 % pow2 24) * pow2 168 +
v x8 / pow2 24 * pow2 224 + pow2 32 * (v x9 % pow2 24) * pow2 224;
(==) { lemma_div248_x5 x5; lemma_div248_x6 x6 }
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 +
pow2 32 * (v x7 % pow2 24) * pow2 112 +
v x7 / pow2 24 * pow2 168 + pow2 32 * (v x8 % pow2 24) * pow2 168 +
v x8 / pow2 24 * pow2 224 + pow2 32 * (v x9 % pow2 24) * pow2 224;
(==) { lemma_div248_x7 x7; lemma_div248_x8 x8 }
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 +
pow2 32 * (v x9 % pow2 24) * pow2 224;
(==) { lemma_div248_x9 x9 }
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256;
(==) { lemma_div248_aux x }
wide_as_nat5 x / pow2 248;
}
#pop-options
val lemma_add_modq5:
x:qelem5
-> y:qelem5
-> t:qelem5 ->
Lemma
(requires
qelem_fits5 x (1, 1, 1, 1, 1) /\
qelem_fits5 y (1, 1, 1, 1, 1) /\
qelem_fits5 t (1, 1, 1, 1, 1) /\
as_nat5 x < S.q /\ as_nat5 y < S.q /\
as_nat5 t == as_nat5 x + as_nat5 y)
(ensures
(let res = if as_nat5 t >= S.q then as_nat5 t - S.q else as_nat5 t in
res < S.q /\ res == (as_nat5 x + as_nat5 y) % S.q))
let lemma_add_modq5 x y t =
assert (as_nat5 t == as_nat5 x + as_nat5 y);
let res = if as_nat5 t >= S.q then as_nat5 t - S.q else as_nat5 t in
assert (res < S.q);
if as_nat5 t >= S.q then (
FStar.Math.Lemmas.sub_div_mod_1 (as_nat5 t) S.q;
assert (res % S.q == as_nat5 t % S.q))
else
assert (res % S.q == as_nat5 t % S.q);
FStar.Math.Lemmas.small_mod res S.q
val lemma_wide_as_nat_pow528: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 528)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
v x9 < pow2 40))
let lemma_wide_as_nat_pow528 x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert_norm (pow2 504 * pow2 24 = pow2 528);
FStar.Math.Lemmas.pow2_minus 528 504;
assert (v x9 < pow2 24);
assert_norm (pow2 24 < pow2 40)
#push-options "--z3cliopt smt.arith.nl=false"
val lemma_div264_aux: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 528)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
wide_as_nat5 x / pow2 264 ==
v x4 / pow2 40 + v x5 * pow2 16 + v x6 * pow2 72 + v x7 * pow2 128 + v x8 * pow2 184 + v x9 * pow2 240))
let lemma_div264_aux x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert_norm (pow2 264 == pow2 224 * pow2 40);
assert_norm (pow2 56 == pow2 16 * pow2 40);
assert_norm (pow2 112 == pow2 72 * pow2 40);
assert_norm (pow2 168 == pow2 128 * pow2 40);
assert_norm (pow2 224 == pow2 184 * pow2 40);
assert_norm (pow2 280 == pow2 240 * pow2 40);
assert_norm (0 < pow2 40);
calc (==) {
wide_as_nat5 x / pow2 264;
(==) { FStar.Math.Lemmas.division_multiplication_lemma (wide_as_nat5 x) (pow2 224) (pow2 40) }
(wide_as_nat5 x / pow2 224) / pow2 40;
(==) { lemma_div224 x }
(v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280) / pow2 40;
(==) { _ by (Tactics.mapply (`feq #int #int (fun x -> x / pow2 40)); int_semiring ()) }
(v x4 + (v x5 * pow2 16 + v x6 * pow2 72 + v x7 * pow2 128 + v x8 * pow2 184 + v x9 * pow2 240) * pow2 40) / pow2 40;
(==) { FStar.Math.Lemmas.lemma_div_plus (v x4) (v x5 * pow2 16 + v x6 * pow2 72 + v x7 * pow2 128 + v x8 * pow2 184 + v x9 * pow2 240) (pow2 40) }
v x4 / pow2 40 + v x5 * pow2 16 + v x6 * pow2 72 + v x7 * pow2 128 + v x8 * pow2 184 + v x9 * pow2 240;
}
val lemma_div264_x5: x5:uint64 ->
Lemma (pow2 16 * (v x5 % pow2 40) + v x5 / pow2 40 * pow2 56 == v x5 * pow2 16)
let lemma_div264_x5 x5 =
assert_norm (0 < pow2 24);
calc (==) {
pow2 16 * (v x5 % pow2 40) + v x5 / pow2 40 * pow2 56;
(==) { _ by (Tactics.norm [delta_only [`%pow2]; primops]; int_semiring ()) }
((v x5 / pow2 40) * pow2 40 + v x5 % pow2 40) * pow2 16;
(==) { FStar.Math.Lemmas.euclidean_division_definition (v x5) (pow2 40) }
v x5 * pow2 16;
}
val lemma_div264_x6: x6:uint64 ->
Lemma (pow2 16 * (v x6 % pow2 40) * pow2 56 + v x6 / pow2 40 * pow2 112 == v x6 * pow2 72)
let lemma_div264_x6 x6 =
calc (==) {
pow2 16 * (v x6 % pow2 40) * pow2 56 + v x6 / pow2 40 * pow2 112;
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
((v x6 / pow2 40) * pow2 40 + v x6 % pow2 40) * pow2 72;
(==) { Math.Lemmas.euclidean_division_definition (v x6) (pow2 40) }
v x6 * pow2 72;
}
val lemma_div264_x7: x7:uint64 ->
Lemma (pow2 16 * (v x7 % pow2 40) * pow2 112 + v x7 / pow2 40 * pow2 168 == v x7 * pow2 128)
let lemma_div264_x7 x7 =
calc (==) {
pow2 16 * (v x7 % pow2 40) * pow2 112 + v x7 / pow2 40 * pow2 168;
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
((v x7 / pow2 40) * pow2 40 + v x7 % pow2 40) * pow2 128;
(==) { Math.Lemmas.euclidean_division_definition (v x7) (pow2 40) }
v x7 * pow2 128;
}
val lemma_div264_x8: x8:uint64 ->
Lemma (pow2 16 * (v x8 % pow2 40) * pow2 168 + v x8 / pow2 40 * pow2 224 == v x8 * pow2 184)
let lemma_div264_x8 x8 =
calc (==) {
pow2 16 * (v x8 % pow2 40) * pow2 168 + v x8 / pow2 40 * pow2 224;
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
((v x8 / pow2 40) * pow2 40 + v x8 % pow2 40) * pow2 184;
(==) { Math.Lemmas.euclidean_division_definition (v x8) (pow2 40) }
v x8 * pow2 184;
}
val lemma_div264_x9: x9:uint64{v x9 < pow2 40} ->
Lemma (pow2 16 * (v x9 % pow2 40) * pow2 224 == v x9 * pow2 240)
let lemma_div264_x9 x9 =
calc (==) {
pow2 16 * (v x9 % pow2 40) * pow2 224;
(==) { Math.Lemmas.small_mod (v x9) (pow2 40) }
pow2 16 * v x9 * pow2 224;
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
v x9 * pow2 240;
}
val lemma_div264: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 528)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
let z0 = v x4 / pow2 40 + pow2 16 * (v x5 % pow2 40) in
let z1 = v x5 / pow2 40 + pow2 16 * (v x6 % pow2 40) in
let z2 = v x6 / pow2 40 + pow2 16 * (v x7 % pow2 40) in
let z3 = v x7 / pow2 40 + pow2 16 * (v x8 % pow2 40) in
let z4 = v x8 / pow2 40 + pow2 16 * (v x9 % pow2 40) in
wide_as_nat5 x / pow2 264 == z0 + z1 * pow2 56 + z2 * pow2 112 + z3 * pow2 168 + z4 * pow2 224))
#push-options "--z3rlimit 50"
let lemma_div264 x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
lemma_wide_as_nat_pow528 x;
assert (v x9 < pow2 40);
calc (==) {
(let z0 = v x4 / pow2 40 + pow2 16 * (v x5 % pow2 40) in
let z1 = v x5 / pow2 40 + pow2 16 * (v x6 % pow2 40) in
let z2 = v x6 / pow2 40 + pow2 16 * (v x7 % pow2 40) in
let z3 = v x7 / pow2 40 + pow2 16 * (v x8 % pow2 40) in
let z4 = v x8 / pow2 40 + pow2 16 * (v x9 % pow2 40) in
z0 + z1 * pow2 56 + z2 * pow2 112 + z3 * pow2 168 + z4 * pow2 224);
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
v x4 / pow2 40 + pow2 16 * (v x5 % pow2 40) +
v x5 / pow2 40 * pow2 56 + pow2 16 * (v x6 % pow2 40) * pow2 56 +
v x6 / pow2 40 * pow2 112 + pow2 16 * (v x7 % pow2 40) * pow2 112 +
v x7 / pow2 40 * pow2 168 + pow2 16 * (v x8 % pow2 40) * pow2 168 +
v x8 / pow2 40 * pow2 224 + pow2 16 * (v x9 % pow2 40) * pow2 224;
(==) { lemma_div264_x5 x5; lemma_div264_x6 x6 }
v x4 / pow2 40 + v x5 * pow2 16 + v x6 * pow2 72 +
pow2 16 * (v x7 % pow2 40) * pow2 112 +
v x7 / pow2 40 * pow2 168 + pow2 16 * (v x8 % pow2 40) * pow2 168 +
v x8 / pow2 40 * pow2 224 + pow2 16 * (v x9 % pow2 40) * pow2 224;
(==) { lemma_div264_x7 x7; lemma_div264_x8 x8 }
v x4 / pow2 40 + v x5 * pow2 16 + v x6 * pow2 72 + v x7 * pow2 128 + v x8 * pow2 184 +
pow2 16 * (v x9 % pow2 40) * pow2 224;
(==) { lemma_div264_x9 x9 }
v x4 / pow2 40 + v x5 * pow2 16 + v x6 * pow2 72 + v x7 * pow2 128 + v x8 * pow2 184 + v x9 * pow2 240;
(==) { lemma_div264_aux x }
wide_as_nat5 x / pow2 264;
}
#pop-options
#pop-options // "--z3cliopt smt.arith.nl=false"
val lemma_mod_264_aux: t:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 t (1, 1, 1, 1, 1, 1, 1, 1, 1, 1))
(ensures
(let (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) = t in
(wide_as_nat5 t) % pow2 264 ==
(v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + v t4 * pow2 224) % pow2 264))
#push-options "--z3rlimit 150"
let lemma_mod_264_aux t =
let (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) = t in
let res = (t0, t1, t2, t3, t4 &. u64 0xffffffffff) in
assert_norm (pow2 16 * pow2 264 == pow2 280);
assert_norm (pow2 72 * pow2 264 == pow2 336);
assert_norm (pow2 128 * pow2 264 == pow2 392);
assert_norm (pow2 184 * pow2 264 == pow2 448);
assert_norm (pow2 240 * pow2 264 == pow2 504);
calc (==) {
(wide_as_nat5 t) % pow2 264;
(==) { }
(v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + v t4 * pow2 224 +
(v t5 * pow2 16 + v t6 * pow2 72 + v t7 * pow2 128 + v t8 * pow2 184 + v t9 * pow2 240) * pow2 264) % pow2 264;
(==) { FStar.Math.Lemmas.lemma_mod_add_distr (v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + v t4 * pow2 224)
((v t5 * pow2 16 + v t6 * pow2 72 + v t7 * pow2 128 + v t8 * pow2 184 + v t9 * pow2 240) * pow2 264) (pow2 264)}
((v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + v t4 * pow2 224) +
((v t5 * pow2 16 + v t6 * pow2 72 + v t7 * pow2 128 + v t8 * pow2 184 + v t9 * pow2 240) * pow2 264) % pow2 264) % pow2 264;
(==) { FStar.Math.Lemmas.cancel_mul_mod (v t5 * pow2 16 + v t6 * pow2 72 + v t7 * pow2 128 + v t8 * pow2 184 + v t9 * pow2 240) (pow2 264) }
(v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + v t4 * pow2 224) % pow2 264;
}
#pop-options
val lemma_as_nat_pow264: x:qelem5 ->
Lemma
(requires
(let (x0, x1, x2, x3, x4) = x in
qelem_fits5 x (1, 1, 1, 1, 1) /\
v x4 < pow2 40))
(ensures as_nat5 x < pow2 264)
let lemma_as_nat_pow264 x =
let (x0, x1, x2, x3, x4) = x in
assert_norm (pow2 40 * pow2 224 = pow2 264)
val lemma_mod_264: t:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 t (1, 1, 1, 1, 1, 1, 1, 1, 1, 1))
(ensures
(let (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) = t in
let res = (t0, t1, t2, t3, t4 &. u64 0xffffffffff) in
qelem_fits5 res (1, 1, 1, 1, 1) /\
as_nat5 res == (wide_as_nat5 t) % pow2 264))
let lemma_mod_264 t =
let (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) = t in
let t4' = t4 &. u64 0xffffffffff in
let res = (t0, t1, t2, t3, t4') in
assert_norm (pow2 40 < pow2 64);
assert_norm (pow2 40 - 1 == 0xffffffffff);
mod_mask_lemma t4 40ul;
assert (v (mod_mask #U64 #SEC 40ul) == 0xffffffffff);
assert (v (t4 &. u64 0xffffffffff) == v t4 % pow2 40);
calc (==) {
(wide_as_nat5 t) % pow2 264;
(==) { lemma_mod_264_aux t }
(v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + v t4 * pow2 224) % pow2 264;
(==) { FStar.Math.Lemmas.lemma_mod_add_distr (v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168) (v t4 * pow2 224) (pow2 264) }
(v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + (v t4 * pow2 224) % pow2 264) % pow2 264;
(==) { FStar.Math.Lemmas.pow2_multiplication_modulo_lemma_2 (v t4) 264 224 }
(v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + (v t4 % pow2 40) * pow2 224) % pow2 264;
(==) { lemma_as_nat_pow264 res; FStar.Math.Lemmas.modulo_lemma (as_nat5 res) (pow2 264) }
v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + (v t4 % pow2 40) * pow2 224;
}
val lemma_as_nat_pow264_x4: x:qelem5 ->
Lemma
(requires
qelem_fits5 x (1, 1, 1, 1, 1) /\
as_nat5 x < pow2 264)
(ensures
(let (x0, x1, x2, x3, x4) = x in
v x4 < pow2 40))
let lemma_as_nat_pow264_x4 x =
let (x0, x1, x2, x3, x4) = x in
assert_norm (pow2 40 * pow2 224 = pow2 264)
val lemma_sub_mod_264_aux:
x0:nat -> x1:nat -> x2:nat -> x3:nat -> x4:nat
-> y0:nat -> y1:nat -> y2:nat -> y3:nat -> y4:nat
-> c1:nat -> c2:nat -> c3:nat -> c4:nat -> c5:nat ->
Lemma (
x0 - y0 + c1 * pow56 +
(x1 - y1 - c1 + c2 * pow56) * pow56 +
(x2 - y2 - c2 + c3 * pow56) * pow112 +
(x3 - y3 - c3 + c4 * pow56) * pow168 +
(x4 - y4 - c4 + pow2 40 * c5) * pow224 ==
(x0 + x1 * pow2 56 + x2 * pow2 112 + x3 * pow2 168 + x4 * pow2 224) -
(y0 + y1 * pow2 56 + y2 * pow2 112 + y3 * pow2 168 + y4 * pow2 224) + c5 * pow2 264)
#push-options "--z3rlimit 50"
let lemma_sub_mod_264_aux x0 x1 x2 x3 x4 y0 y1 y2 y3 y4 b0 b1 b2 b3 b4 =
assert_norm (pow2 56 * pow2 56 = pow2 112);
assert_norm (pow2 56 * pow2 112 = pow2 168);
assert_norm (pow2 56 * pow2 168 = pow2 224);
assert_norm (pow2 40 * pow2 224 = pow2 264)
#pop-options
val lemma_sub_mod_264:
x:qelem5
-> y:qelem5
-> t:qelem5
-> c5:uint64 ->
Lemma
(requires
qelem_fits5 x (1, 1, 1, 1, 1) /\
qelem_fits5 y (1, 1, 1, 1, 1) /\
qelem_fits5 t (1, 1, 1, 1, 1) /\
as_nat5 x < pow2 264 /\
as_nat5 y < pow2 264 /\
as_nat5 t == as_nat5 x - as_nat5 y + v c5 * pow2 264 /\ v c5 <= 1 /\
(if v c5 = 0 then as_nat5 x >= as_nat5 y else as_nat5 x < as_nat5 y))
(ensures
(if as_nat5 x >= as_nat5 y then
as_nat5 t == as_nat5 x - as_nat5 y
else as_nat5 t == as_nat5 x - as_nat5 y + pow2 264)) | {
"checked_file": "/",
"dependencies": [
"Spec.Ed25519.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.BignumQ.Definitions.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Tactics.CanonCommSemiring.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.BignumQ.Lemmas.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.CanonCommSemiring",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.BignumQ.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.Ed25519",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.CanonCommSemiring",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.BignumQ",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.BignumQ",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
x: Hacl.Spec.BignumQ.Definitions.qelem5 ->
y: Hacl.Spec.BignumQ.Definitions.qelem5 ->
t: Hacl.Spec.BignumQ.Definitions.qelem5 ->
c5: Lib.IntTypes.uint64
-> FStar.Pervasives.Lemma
(requires
Hacl.Spec.BignumQ.Definitions.qelem_fits5 x (1, 1, 1, 1, 1) /\
Hacl.Spec.BignumQ.Definitions.qelem_fits5 y (1, 1, 1, 1, 1) /\
Hacl.Spec.BignumQ.Definitions.qelem_fits5 t (1, 1, 1, 1, 1) /\
Hacl.Spec.BignumQ.Definitions.as_nat5 x < Prims.pow2 264 /\
Hacl.Spec.BignumQ.Definitions.as_nat5 y < Prims.pow2 264 /\
Hacl.Spec.BignumQ.Definitions.as_nat5 t ==
Hacl.Spec.BignumQ.Definitions.as_nat5 x - Hacl.Spec.BignumQ.Definitions.as_nat5 y +
Lib.IntTypes.v c5 * Prims.pow2 264 /\ Lib.IntTypes.v c5 <= 1 /\
(match Lib.IntTypes.v c5 = 0 with
| true ->
Hacl.Spec.BignumQ.Definitions.as_nat5 x >= Hacl.Spec.BignumQ.Definitions.as_nat5 y
| _ -> Hacl.Spec.BignumQ.Definitions.as_nat5 x < Hacl.Spec.BignumQ.Definitions.as_nat5 y))
(ensures
((match
Hacl.Spec.BignumQ.Definitions.as_nat5 x >= Hacl.Spec.BignumQ.Definitions.as_nat5 y
with
| true ->
Hacl.Spec.BignumQ.Definitions.as_nat5 t ==
Hacl.Spec.BignumQ.Definitions.as_nat5 x - Hacl.Spec.BignumQ.Definitions.as_nat5 y
| _ ->
Hacl.Spec.BignumQ.Definitions.as_nat5 t ==
Hacl.Spec.BignumQ.Definitions.as_nat5 x - Hacl.Spec.BignumQ.Definitions.as_nat5 y +
Prims.pow2 264)
<:
Type0)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Hacl.Spec.BignumQ.Definitions.qelem5",
"Lib.IntTypes.uint64",
"Prims.op_GreaterThanOrEqual",
"Hacl.Spec.BignumQ.Definitions.as_nat5",
"Prims._assert",
"Prims.l_and",
"Prims.eq2",
"Prims.int",
"Lib.IntTypes.v",
"Lib.IntTypes.U64",
"Lib.IntTypes.SEC",
"Prims.op_Subtraction",
"Prims.bool",
"Prims.op_Addition",
"Prims.pow2",
"Prims.unit",
"FStar.Mul.op_Star",
"Prims.op_Equality",
"Prims.b2t",
"Prims.op_LessThan"
] | [] | false | false | true | false | false | let lemma_sub_mod_264 x y t c5 =
| assert (if v c5 = 0 then as_nat5 x >= as_nat5 y else as_nat5 x < as_nat5 y);
assert (as_nat5 t == as_nat5 x - as_nat5 y + v c5 * pow2 264);
if as_nat5 x >= as_nat5 y
then assert (v c5 == 0 /\ as_nat5 t == as_nat5 x - as_nat5 y)
else assert (v c5 == 1 /\ as_nat5 t == as_nat5 x - as_nat5 y + pow2 264) | false |
SfBasic.fst | SfBasic.ble_nat | val ble_nat : nat -> nat -> Tot mbool | val ble_nat : nat -> nat -> Tot mbool | let rec ble_nat n m =
match n, m with
| O , _ -> MTrue
| S n', O -> MFalse
| S n', S m' -> ble_nat n' m' | {
"file_name": "examples/software_foundations/SfBasic.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 31,
"end_line": 164,
"start_col": 0,
"start_line": 160
} | (*
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.
*)
(*
A translation to F* of Basics.v from Software Foundations
Original name: "Basics: Functional Programming in Coq"
*)
module SfBasic
type day =
| Monday
| Tuesday
| Wednesday
| Thursday
| Friday
| Saturday
| Sunday
val next_weekday : day -> Tot day
let next_weekday d =
match d with
| Monday -> Tuesday
| Tuesday -> Wednesday
| Wednesday -> Thursday
| Thursday -> Friday
| Friday -> Monday
| Saturday -> Monday
| Sunday -> Monday
val test_next_weekday : unit -> Lemma
(ensures ((next_weekday (next_weekday Saturday)) = Tuesday))
let test_next_weekday () = ()
(* Booleans *)
(* The original example calls these bool, True, and False,
and that doesn't seem to cause problems;
I've just renamed them to be 100% sure that's not the cause
of the troubles in this file *)
type mbool =
| MTrue
| MFalse
val negb : mbool -> Tot mbool
let negb b =
match b with
| MTrue -> MFalse
| MFalse -> MTrue
val andb : mbool -> mbool -> Tot mbool
let andb b1 b2 =
match b1 with
| MTrue -> b2
| MFalse -> MFalse
val orb : mbool -> mbool -> Tot mbool
let orb b1 b2 =
match b1 with
| MTrue -> MTrue
| MFalse -> b2
val test_orb1 : unit -> Lemma
(ensures ((orb MTrue MFalse) = MTrue))
let test_orb1 () = ()
val test_orb2 : unit -> Lemma
(ensures ((orb MFalse MFalse) = MFalse))
let test_orb2 () = ()
val test_orb3 : unit -> Lemma
(ensures ((orb MFalse MTrue) = MTrue))
let test_orb3 () = ()
val test_orb4 : unit -> Lemma
(ensures ((orb MTrue MTrue) = MTrue))
let test_orb4 () = ()
(* Numbers *)
type nat =
| O : nat
| S : nat -> nat
val pred : nat -> Tot nat
let pred n =
match n with
| O -> O
| S n' -> n'
val minustwo : nat -> Tot nat
let minustwo n =
match n with
| O -> O
| S O -> O
| S (S n') -> n'
val evenb : nat -> Tot mbool
let rec evenb n =
match n with
| O -> MTrue
| S O -> MFalse
| S (S n') -> evenb n'
val oddb : nat -> Tot mbool
let oddb n = negb (evenb n)
val test_oddb1 : unit -> Lemma
(ensures ((oddb (S O)) = MTrue))
let test_oddb1 () = ()
val test_oddb2 : unit -> Lemma
(ensures (oddb (S (S (S (S O)))) = MFalse))
let test_oddb2 () = ()
val plus : nat -> nat -> Tot nat
let rec plus n m =
match n with
| O -> m
| S n' -> S (plus n' m)
val mult : nat -> nat -> Tot nat
let rec mult n m =
match n with
| O -> O
| S n' -> plus m (mult n' m)
val test_mult1 : unit -> Lemma
(ensures (mult (S (S (S O))) (S (S (S O))))
= (S (S (S (S (S (S (S (S (S O))))))))))
let test_mult1 () = ()
val minus : nat -> nat -> Tot nat
let rec minus (n : nat) (m : nat) : nat =
match n, m with
| O , _ -> O
| S _ , O -> n
| S n', S m' -> minus n' m'
val beq_nat : nat -> nat -> Tot mbool
let rec beq_nat n m =
match n, m with
| O , O -> MTrue
| S n', S m' -> beq_nat n' m'
| _ , _ -> MFalse | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "SfBasic.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | n: SfBasic.nat -> m: SfBasic.nat -> SfBasic.mbool | Prims.Tot | [
"total"
] | [] | [
"SfBasic.nat",
"FStar.Pervasives.Native.Mktuple2",
"SfBasic.MTrue",
"SfBasic.MFalse",
"SfBasic.ble_nat",
"SfBasic.mbool"
] | [
"recursion"
] | false | false | false | true | false | let rec ble_nat n m =
| match n, m with
| O, _ -> MTrue
| S n', O -> MFalse
| S n', S m' -> ble_nat n' m' | false |
SfBasic.fst | SfBasic.plus_0_r | val plus_0_r : n : nat -> Lemma
(ensures (plus n O = n)) | val plus_0_r : n : nat -> Lemma
(ensures (plus n O = n)) | let rec plus_0_r n =
match n with
| O -> ()
| S n' -> plus_0_r n' | {
"file_name": "examples/software_foundations/SfBasic.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": 207
} | (*
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.
*)
(*
A translation to F* of Basics.v from Software Foundations
Original name: "Basics: Functional Programming in Coq"
*)
module SfBasic
type day =
| Monday
| Tuesday
| Wednesday
| Thursday
| Friday
| Saturday
| Sunday
val next_weekday : day -> Tot day
let next_weekday d =
match d with
| Monday -> Tuesday
| Tuesday -> Wednesday
| Wednesday -> Thursday
| Thursday -> Friday
| Friday -> Monday
| Saturday -> Monday
| Sunday -> Monday
val test_next_weekday : unit -> Lemma
(ensures ((next_weekday (next_weekday Saturday)) = Tuesday))
let test_next_weekday () = ()
(* Booleans *)
(* The original example calls these bool, True, and False,
and that doesn't seem to cause problems;
I've just renamed them to be 100% sure that's not the cause
of the troubles in this file *)
type mbool =
| MTrue
| MFalse
val negb : mbool -> Tot mbool
let negb b =
match b with
| MTrue -> MFalse
| MFalse -> MTrue
val andb : mbool -> mbool -> Tot mbool
let andb b1 b2 =
match b1 with
| MTrue -> b2
| MFalse -> MFalse
val orb : mbool -> mbool -> Tot mbool
let orb b1 b2 =
match b1 with
| MTrue -> MTrue
| MFalse -> b2
val test_orb1 : unit -> Lemma
(ensures ((orb MTrue MFalse) = MTrue))
let test_orb1 () = ()
val test_orb2 : unit -> Lemma
(ensures ((orb MFalse MFalse) = MFalse))
let test_orb2 () = ()
val test_orb3 : unit -> Lemma
(ensures ((orb MFalse MTrue) = MTrue))
let test_orb3 () = ()
val test_orb4 : unit -> Lemma
(ensures ((orb MTrue MTrue) = MTrue))
let test_orb4 () = ()
(* Numbers *)
type nat =
| O : nat
| S : nat -> nat
val pred : nat -> Tot nat
let pred n =
match n with
| O -> O
| S n' -> n'
val minustwo : nat -> Tot nat
let minustwo n =
match n with
| O -> O
| S O -> O
| S (S n') -> n'
val evenb : nat -> Tot mbool
let rec evenb n =
match n with
| O -> MTrue
| S O -> MFalse
| S (S n') -> evenb n'
val oddb : nat -> Tot mbool
let oddb n = negb (evenb n)
val test_oddb1 : unit -> Lemma
(ensures ((oddb (S O)) = MTrue))
let test_oddb1 () = ()
val test_oddb2 : unit -> Lemma
(ensures (oddb (S (S (S (S O)))) = MFalse))
let test_oddb2 () = ()
val plus : nat -> nat -> Tot nat
let rec plus n m =
match n with
| O -> m
| S n' -> S (plus n' m)
val mult : nat -> nat -> Tot nat
let rec mult n m =
match n with
| O -> O
| S n' -> plus m (mult n' m)
val test_mult1 : unit -> Lemma
(ensures (mult (S (S (S O))) (S (S (S O))))
= (S (S (S (S (S (S (S (S (S O))))))))))
let test_mult1 () = ()
val minus : nat -> nat -> Tot nat
let rec minus (n : nat) (m : nat) : nat =
match n, m with
| O , _ -> O
| S _ , O -> n
| S n', S m' -> minus n' m'
val beq_nat : nat -> nat -> Tot mbool
let rec beq_nat n m =
match n, m with
| O , O -> MTrue
| S n', S m' -> beq_nat n' m'
| _ , _ -> MFalse
val ble_nat : nat -> nat -> Tot mbool
let rec ble_nat n m =
match n, m with
| O , _ -> MTrue
| S n', O -> MFalse
| S n', S m' -> ble_nat n' m'
val test_ble_nat1 : unit -> Lemma
(ensures (ble_nat (S (S O)) (S (S O)) = MTrue))
let test_ble_nat1 () = ()
val test_ble_nat2 : unit -> Lemma
(ensures (ble_nat (S (S O)) (S (S (S (S O)))) = MTrue))
let test_ble_nat2 () = ()
val test_ble_nat3 : unit -> Lemma
(ensures (ble_nat (S (S (S (S O)))) (S (S O)) = MFalse))
let test_ble_nat3 () = ()
(* Proof by Simplification *)
val plus_O_n : n : nat -> Lemma
(ensures (plus O n = n))
let plus_O_n n = ()
(* Proof by Rewriting *)
val plus_id_example : n : nat -> m : nat -> Pure unit
(requires (n == m))
(ensures (fun r -> (plus n n = plus m m)))
let plus_id_example n m = ()
val mult_0_plus : n : nat -> m : nat -> Lemma
(ensures ((mult (plus O n) m) = mult n m))
let mult_0_plus n m = ()
(* Proof by Case Analysis *)
val plus_1_neq_0 : n : nat -> Lemma
(ensures (beq_nat (plus n (S O)) O = MFalse))
let plus_1_neq_0 n = ()
val negb_involutive : b : mbool -> Lemma
(ensures (negb (negb b) = b))
let negb_involutive b = ()
(* Proof by Induction (Induction.v) *)
val plus_0_r : n : nat -> Lemma | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "SfBasic.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | n: SfBasic.nat -> FStar.Pervasives.Lemma (ensures SfBasic.plus n SfBasic.O = n) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"SfBasic.nat",
"SfBasic.plus_0_r",
"Prims.unit"
] | [
"recursion"
] | false | false | true | false | false | let rec plus_0_r n =
| match n with
| O -> ()
| S n' -> plus_0_r n' | false |
Hacl.Spec.BignumQ.Lemmas.fst | Hacl.Spec.BignumQ.Lemmas.lemma_subm_conditional | val lemma_subm_conditional:
x0:nat -> x1:nat -> x2:nat -> x3:nat -> x4:nat
-> y0:nat -> y1:nat -> y2:nat -> y3:nat -> y4:nat
-> b0:nat -> b1:nat -> b2:nat -> b3:nat -> b4:nat ->
Lemma (
x0 - y0 + b0 * pow2 56 +
(x1 - y1 - b0 + b1 * pow2 56) * pow2 56 +
(x2 - y2 - b1 + b2 * pow2 56) * pow2 112 +
(x3 - y3 - b2 + b3 * pow2 56) * pow2 168 +
(x4 - y4 - b3 + b4 * pow2 56) * pow2 224 ==
(x0 + x1 * pow2 56 + x2 * pow2 112 + x3 * pow2 168 + x4 * pow2 224) -
(y0 + y1 * pow2 56 + y2 * pow2 112 + y3 * pow2 168 + y4 * pow2 224) + b4 * pow2 280) | val lemma_subm_conditional:
x0:nat -> x1:nat -> x2:nat -> x3:nat -> x4:nat
-> y0:nat -> y1:nat -> y2:nat -> y3:nat -> y4:nat
-> b0:nat -> b1:nat -> b2:nat -> b3:nat -> b4:nat ->
Lemma (
x0 - y0 + b0 * pow2 56 +
(x1 - y1 - b0 + b1 * pow2 56) * pow2 56 +
(x2 - y2 - b1 + b2 * pow2 56) * pow2 112 +
(x3 - y3 - b2 + b3 * pow2 56) * pow2 168 +
(x4 - y4 - b3 + b4 * pow2 56) * pow2 224 ==
(x0 + x1 * pow2 56 + x2 * pow2 112 + x3 * pow2 168 + x4 * pow2 224) -
(y0 + y1 * pow2 56 + y2 * pow2 112 + y3 * pow2 168 + y4 * pow2 224) + b4 * pow2 280) | let lemma_subm_conditional x0 x1 x2 x3 x4 y0 y1 y2 y3 y4 b0 b1 b2 b3 b4 =
assert_norm (pow2 56 * pow2 56 = pow2 112);
assert_norm (pow2 56 * pow2 112 = pow2 168);
assert_norm (pow2 56 * pow2 168 = pow2 224);
assert_norm (pow2 56 * pow2 224 = pow2 280);
assert (
x0 - y0 + b0 * pow2 56 +
(x1 - y1 - b0 + b1 * pow2 56) * pow2 56 +
(x2 - y2 - b1 + b2 * pow2 56) * pow2 112 +
(x3 - y3 - b2 + b3 * pow2 56) * pow2 168 +
(x4 - y4 - b3 + b4 * pow2 56) * pow2 224 ==
(x0 + x1 * pow2 56 + x2 * pow2 112 + x3 * pow2 168 + x4 * pow2 224) -
(y0 + y1 * pow2 56 + y2 * pow2 112 + y3 * pow2 168 + y4 * pow2 224) + b4 * pow2 280)
by (int_semiring ());
() | {
"file_name": "code/ed25519/Hacl.Spec.BignumQ.Lemmas.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 4,
"end_line": 88,
"start_col": 0,
"start_line": 74
} | module Hacl.Spec.BignumQ.Lemmas
open FStar.Tactics.CanonCommSemiring
open FStar.Mul
open Lib.IntTypes
module S = Spec.Ed25519
include Hacl.Spec.BignumQ.Definitions
let feq (#a #b:Type) (f:(a -> b)) (x y:a) :
Lemma (requires x == y) (ensures f x == f y) = ()
let eq_eq2 (#a:eqtype) (x y:a) :
Lemma (requires x = y) (ensures x == y) = ()
val lemma_mul_lt:a:nat -> b:nat -> c:nat -> d:nat ->
Lemma
(requires a < b /\ c < d)
(ensures a * c < b * d)
let lemma_mul_lt a b c d = ()
val lemma_as_nat5: f:qelem5 ->
Lemma
(requires qelem_fits5 f (1, 1, 1, 1, 1))
(ensures as_nat5 f < pow2 280)
let lemma_as_nat5 f =
//let (f0, f1, f2, f3, f4) = f in
//assert (as_nat5 f == v f0 + v f1 * pow56 + v f2 * pow112 + v f3 * pow168 + v f4 * pow224);
assert_norm (pow2 56 * pow2 56 = pow2 112);
assert_norm (pow2 56 * pow2 112 = pow2 168);
assert_norm (pow2 56 * pow2 168 = pow2 224);
assert_norm (pow2 56 * pow2 224 = pow2 280)
val lemma_choose_step:
bit:uint64{v bit <= 1}
-> x:uint64
-> y:uint64
-> Lemma
(let mask = bit -. u64 1 in
let z = x ^. (mask &. (x ^. y)) in
if v bit = 1 then z == x else z == y)
let lemma_choose_step bit p1 p2 =
let mask = bit -. u64 1 in
assert (v bit == 0 ==> v mask == pow2 64 - 1);
assert (v bit == 1 ==> v mask == 0);
let dummy = mask &. (p1 ^. p2) in
logand_lemma mask (p1 ^. p2);
assert (v bit == 1 ==> v dummy == 0);
assert (v bit == 0 ==> v dummy == v (p1 ^. p2));
let p1' = p1 ^. dummy in
assert (v dummy == v (if v bit = 1 then u64 0 else (p1 ^. p2)));
logxor_lemma p1 p2
val lemma_subm_conditional:
x0:nat -> x1:nat -> x2:nat -> x3:nat -> x4:nat
-> y0:nat -> y1:nat -> y2:nat -> y3:nat -> y4:nat
-> b0:nat -> b1:nat -> b2:nat -> b3:nat -> b4:nat ->
Lemma (
x0 - y0 + b0 * pow2 56 +
(x1 - y1 - b0 + b1 * pow2 56) * pow2 56 +
(x2 - y2 - b1 + b2 * pow2 56) * pow2 112 +
(x3 - y3 - b2 + b3 * pow2 56) * pow2 168 +
(x4 - y4 - b3 + b4 * pow2 56) * pow2 224 ==
(x0 + x1 * pow2 56 + x2 * pow2 112 + x3 * pow2 168 + x4 * pow2 224) -
(y0 + y1 * pow2 56 + y2 * pow2 112 + y3 * pow2 168 + y4 * pow2 224) + b4 * pow2 280) | {
"checked_file": "/",
"dependencies": [
"Spec.Ed25519.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.BignumQ.Definitions.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Tactics.CanonCommSemiring.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.BignumQ.Lemmas.fst"
} | [
{
"abbrev": false,
"full_module": "Hacl.Spec.BignumQ.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.Ed25519",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.CanonCommSemiring",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.BignumQ",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.BignumQ",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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 |
x0: Prims.nat ->
x1: Prims.nat ->
x2: Prims.nat ->
x3: Prims.nat ->
x4: Prims.nat ->
y0: Prims.nat ->
y1: Prims.nat ->
y2: Prims.nat ->
y3: Prims.nat ->
y4: Prims.nat ->
b0: Prims.nat ->
b1: Prims.nat ->
b2: Prims.nat ->
b3: Prims.nat ->
b4: Prims.nat
-> FStar.Pervasives.Lemma
(ensures
x0 - y0 + b0 * Prims.pow2 56 + (x1 - y1 - b0 + b1 * Prims.pow2 56) * Prims.pow2 56 +
(x2 - y2 - b1 + b2 * Prims.pow2 56) * Prims.pow2 112 +
(x3 - y3 - b2 + b3 * Prims.pow2 56) * Prims.pow2 168 +
(x4 - y4 - b3 + b4 * Prims.pow2 56) * Prims.pow2 224 ==
x0 + x1 * Prims.pow2 56 + x2 * Prims.pow2 112 + x3 * Prims.pow2 168 + x4 * Prims.pow2 224 -
(y0 + y1 * Prims.pow2 56 + y2 * Prims.pow2 112 + y3 * Prims.pow2 168 + y4 * Prims.pow2 224) +
b4 * Prims.pow2 280) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.nat",
"Prims.unit",
"FStar.Tactics.Effect.assert_by_tactic",
"Prims.eq2",
"Prims.int",
"Prims.op_Addition",
"Prims.op_Subtraction",
"FStar.Mul.op_Star",
"Prims.pow2",
"FStar.Tactics.CanonCommSemiring.int_semiring",
"FStar.Pervasives.assert_norm",
"Prims.b2t",
"Prims.op_Equality"
] | [] | false | false | true | false | false | let lemma_subm_conditional x0 x1 x2 x3 x4 y0 y1 y2 y3 y4 b0 b1 b2 b3 b4 =
| assert_norm (pow2 56 * pow2 56 = pow2 112);
assert_norm (pow2 56 * pow2 112 = pow2 168);
assert_norm (pow2 56 * pow2 168 = pow2 224);
assert_norm (pow2 56 * pow2 224 = pow2 280);
FStar.Tactics.Effect.assert_by_tactic (x0 - y0 + b0 * pow2 56 +
(x1 - y1 - b0 + b1 * pow2 56) * pow2 56 +
(x2 - y2 - b1 + b2 * pow2 56) * pow2 112 +
(x3 - y3 - b2 + b3 * pow2 56) * pow2 168 +
(x4 - y4 - b3 + b4 * pow2 56) * pow2 224 ==
(x0 + x1 * pow2 56 + x2 * pow2 112 + x3 * pow2 168 + x4 * pow2 224) -
(y0 + y1 * pow2 56 + y2 * pow2 112 + y3 * pow2 168 + y4 * pow2 224) +
b4 * pow2 280)
(fun _ ->
();
(int_semiring ()));
() | false |
SfBasic.fst | SfBasic.plus_rearrange | val plus_rearrange : n : nat -> m : nat -> p : nat -> q : nat -> Lemma
(ensures (plus (plus n m) (plus p q) = plus (plus m n) (plus p q))) | val plus_rearrange : n : nat -> m : nat -> p : nat -> q : nat -> Lemma
(ensures (plus (plus n m) (plus p q) = plus (plus m n) (plus p q))) | let plus_rearrange n m p q = plus_comm n m | {
"file_name": "examples/software_foundations/SfBasic.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 42,
"end_line": 230,
"start_col": 0,
"start_line": 230
} | (*
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.
*)
(*
A translation to F* of Basics.v from Software Foundations
Original name: "Basics: Functional Programming in Coq"
*)
module SfBasic
type day =
| Monday
| Tuesday
| Wednesday
| Thursday
| Friday
| Saturday
| Sunday
val next_weekday : day -> Tot day
let next_weekday d =
match d with
| Monday -> Tuesday
| Tuesday -> Wednesday
| Wednesday -> Thursday
| Thursday -> Friday
| Friday -> Monday
| Saturday -> Monday
| Sunday -> Monday
val test_next_weekday : unit -> Lemma
(ensures ((next_weekday (next_weekday Saturday)) = Tuesday))
let test_next_weekday () = ()
(* Booleans *)
(* The original example calls these bool, True, and False,
and that doesn't seem to cause problems;
I've just renamed them to be 100% sure that's not the cause
of the troubles in this file *)
type mbool =
| MTrue
| MFalse
val negb : mbool -> Tot mbool
let negb b =
match b with
| MTrue -> MFalse
| MFalse -> MTrue
val andb : mbool -> mbool -> Tot mbool
let andb b1 b2 =
match b1 with
| MTrue -> b2
| MFalse -> MFalse
val orb : mbool -> mbool -> Tot mbool
let orb b1 b2 =
match b1 with
| MTrue -> MTrue
| MFalse -> b2
val test_orb1 : unit -> Lemma
(ensures ((orb MTrue MFalse) = MTrue))
let test_orb1 () = ()
val test_orb2 : unit -> Lemma
(ensures ((orb MFalse MFalse) = MFalse))
let test_orb2 () = ()
val test_orb3 : unit -> Lemma
(ensures ((orb MFalse MTrue) = MTrue))
let test_orb3 () = ()
val test_orb4 : unit -> Lemma
(ensures ((orb MTrue MTrue) = MTrue))
let test_orb4 () = ()
(* Numbers *)
type nat =
| O : nat
| S : nat -> nat
val pred : nat -> Tot nat
let pred n =
match n with
| O -> O
| S n' -> n'
val minustwo : nat -> Tot nat
let minustwo n =
match n with
| O -> O
| S O -> O
| S (S n') -> n'
val evenb : nat -> Tot mbool
let rec evenb n =
match n with
| O -> MTrue
| S O -> MFalse
| S (S n') -> evenb n'
val oddb : nat -> Tot mbool
let oddb n = negb (evenb n)
val test_oddb1 : unit -> Lemma
(ensures ((oddb (S O)) = MTrue))
let test_oddb1 () = ()
val test_oddb2 : unit -> Lemma
(ensures (oddb (S (S (S (S O)))) = MFalse))
let test_oddb2 () = ()
val plus : nat -> nat -> Tot nat
let rec plus n m =
match n with
| O -> m
| S n' -> S (plus n' m)
val mult : nat -> nat -> Tot nat
let rec mult n m =
match n with
| O -> O
| S n' -> plus m (mult n' m)
val test_mult1 : unit -> Lemma
(ensures (mult (S (S (S O))) (S (S (S O))))
= (S (S (S (S (S (S (S (S (S O))))))))))
let test_mult1 () = ()
val minus : nat -> nat -> Tot nat
let rec minus (n : nat) (m : nat) : nat =
match n, m with
| O , _ -> O
| S _ , O -> n
| S n', S m' -> minus n' m'
val beq_nat : nat -> nat -> Tot mbool
let rec beq_nat n m =
match n, m with
| O , O -> MTrue
| S n', S m' -> beq_nat n' m'
| _ , _ -> MFalse
val ble_nat : nat -> nat -> Tot mbool
let rec ble_nat n m =
match n, m with
| O , _ -> MTrue
| S n', O -> MFalse
| S n', S m' -> ble_nat n' m'
val test_ble_nat1 : unit -> Lemma
(ensures (ble_nat (S (S O)) (S (S O)) = MTrue))
let test_ble_nat1 () = ()
val test_ble_nat2 : unit -> Lemma
(ensures (ble_nat (S (S O)) (S (S (S (S O)))) = MTrue))
let test_ble_nat2 () = ()
val test_ble_nat3 : unit -> Lemma
(ensures (ble_nat (S (S (S (S O)))) (S (S O)) = MFalse))
let test_ble_nat3 () = ()
(* Proof by Simplification *)
val plus_O_n : n : nat -> Lemma
(ensures (plus O n = n))
let plus_O_n n = ()
(* Proof by Rewriting *)
val plus_id_example : n : nat -> m : nat -> Pure unit
(requires (n == m))
(ensures (fun r -> (plus n n = plus m m)))
let plus_id_example n m = ()
val mult_0_plus : n : nat -> m : nat -> Lemma
(ensures ((mult (plus O n) m) = mult n m))
let mult_0_plus n m = ()
(* Proof by Case Analysis *)
val plus_1_neq_0 : n : nat -> Lemma
(ensures (beq_nat (plus n (S O)) O = MFalse))
let plus_1_neq_0 n = ()
val negb_involutive : b : mbool -> Lemma
(ensures (negb (negb b) = b))
let negb_involutive b = ()
(* Proof by Induction (Induction.v) *)
val plus_0_r : n : nat -> Lemma
(ensures (plus n O = n))
let rec plus_0_r n =
match n with
| O -> ()
| S n' -> plus_0_r n'
val plus_n_Sm : n : nat -> m : nat -> Lemma
(ensures (S (plus n m) = plus n (S m)))
let rec plus_n_Sm n m =
match n with
| O -> ()
| S n' -> plus_n_Sm n' m
(* this one uses previous lemma -- needs to be explicit it seems *)
val plus_comm : n : nat -> m : nat -> Lemma
(ensures (plus n m = plus m n))
let rec plus_comm n m =
match n with
| O -> plus_0_r m
| S n' -> plus_comm n' m; plus_n_Sm m n'
(* this one uses previous lemma -- needs to be explicit it seems *)
val plus_rearrange : n : nat -> m : nat -> p : nat -> q : nat -> Lemma | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "SfBasic.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | n: SfBasic.nat -> m: SfBasic.nat -> p: SfBasic.nat -> q: SfBasic.nat
-> FStar.Pervasives.Lemma
(ensures
SfBasic.plus (SfBasic.plus n m) (SfBasic.plus p q) =
SfBasic.plus (SfBasic.plus m n) (SfBasic.plus p q)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"SfBasic.nat",
"SfBasic.plus_comm",
"Prims.unit"
] | [] | true | false | true | false | false | let plus_rearrange n m p q =
| plus_comm n m | false |
Hacl.Spec.BignumQ.Lemmas.fst | Hacl.Spec.BignumQ.Lemmas.lemma_div248_x7 | val lemma_div248_x7: x7:uint64 ->
Lemma (pow2 32 * (v x7 % pow2 24) * pow2 112 + v x7 / pow2 24 * pow2 168 == v x7 * pow2 144) | val lemma_div248_x7: x7:uint64 ->
Lemma (pow2 32 * (v x7 % pow2 24) * pow2 112 + v x7 / pow2 24 * pow2 168 == v x7 * pow2 144) | let lemma_div248_x7 x7 =
calc (==) {
pow2 32 * (v x7 % pow2 24) * pow2 112 + v x7 / pow2 24 * pow2 168;
(==) { _ by (Tactics.norm [delta_only [`%pow2]; primops]; int_semiring ()) }
((v x7 / pow2 24) * pow2 24 + v x7 % pow2 24) * pow2 144;
(==) { FStar.Math.Lemmas.euclidean_division_definition (v x7) (pow2 24) }
v x7 * pow2 144;
} | {
"file_name": "code/ed25519/Hacl.Spec.BignumQ.Lemmas.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 3,
"end_line": 188,
"start_col": 0,
"start_line": 181
} | module Hacl.Spec.BignumQ.Lemmas
open FStar.Tactics.CanonCommSemiring
open FStar.Mul
open Lib.IntTypes
module S = Spec.Ed25519
include Hacl.Spec.BignumQ.Definitions
let feq (#a #b:Type) (f:(a -> b)) (x y:a) :
Lemma (requires x == y) (ensures f x == f y) = ()
let eq_eq2 (#a:eqtype) (x y:a) :
Lemma (requires x = y) (ensures x == y) = ()
val lemma_mul_lt:a:nat -> b:nat -> c:nat -> d:nat ->
Lemma
(requires a < b /\ c < d)
(ensures a * c < b * d)
let lemma_mul_lt a b c d = ()
val lemma_as_nat5: f:qelem5 ->
Lemma
(requires qelem_fits5 f (1, 1, 1, 1, 1))
(ensures as_nat5 f < pow2 280)
let lemma_as_nat5 f =
//let (f0, f1, f2, f3, f4) = f in
//assert (as_nat5 f == v f0 + v f1 * pow56 + v f2 * pow112 + v f3 * pow168 + v f4 * pow224);
assert_norm (pow2 56 * pow2 56 = pow2 112);
assert_norm (pow2 56 * pow2 112 = pow2 168);
assert_norm (pow2 56 * pow2 168 = pow2 224);
assert_norm (pow2 56 * pow2 224 = pow2 280)
val lemma_choose_step:
bit:uint64{v bit <= 1}
-> x:uint64
-> y:uint64
-> Lemma
(let mask = bit -. u64 1 in
let z = x ^. (mask &. (x ^. y)) in
if v bit = 1 then z == x else z == y)
let lemma_choose_step bit p1 p2 =
let mask = bit -. u64 1 in
assert (v bit == 0 ==> v mask == pow2 64 - 1);
assert (v bit == 1 ==> v mask == 0);
let dummy = mask &. (p1 ^. p2) in
logand_lemma mask (p1 ^. p2);
assert (v bit == 1 ==> v dummy == 0);
assert (v bit == 0 ==> v dummy == v (p1 ^. p2));
let p1' = p1 ^. dummy in
assert (v dummy == v (if v bit = 1 then u64 0 else (p1 ^. p2)));
logxor_lemma p1 p2
val lemma_subm_conditional:
x0:nat -> x1:nat -> x2:nat -> x3:nat -> x4:nat
-> y0:nat -> y1:nat -> y2:nat -> y3:nat -> y4:nat
-> b0:nat -> b1:nat -> b2:nat -> b3:nat -> b4:nat ->
Lemma (
x0 - y0 + b0 * pow2 56 +
(x1 - y1 - b0 + b1 * pow2 56) * pow2 56 +
(x2 - y2 - b1 + b2 * pow2 56) * pow2 112 +
(x3 - y3 - b2 + b3 * pow2 56) * pow2 168 +
(x4 - y4 - b3 + b4 * pow2 56) * pow2 224 ==
(x0 + x1 * pow2 56 + x2 * pow2 112 + x3 * pow2 168 + x4 * pow2 224) -
(y0 + y1 * pow2 56 + y2 * pow2 112 + y3 * pow2 168 + y4 * pow2 224) + b4 * pow2 280)
let lemma_subm_conditional x0 x1 x2 x3 x4 y0 y1 y2 y3 y4 b0 b1 b2 b3 b4 =
assert_norm (pow2 56 * pow2 56 = pow2 112);
assert_norm (pow2 56 * pow2 112 = pow2 168);
assert_norm (pow2 56 * pow2 168 = pow2 224);
assert_norm (pow2 56 * pow2 224 = pow2 280);
assert (
x0 - y0 + b0 * pow2 56 +
(x1 - y1 - b0 + b1 * pow2 56) * pow2 56 +
(x2 - y2 - b1 + b2 * pow2 56) * pow2 112 +
(x3 - y3 - b2 + b3 * pow2 56) * pow2 168 +
(x4 - y4 - b3 + b4 * pow2 56) * pow2 224 ==
(x0 + x1 * pow2 56 + x2 * pow2 112 + x3 * pow2 168 + x4 * pow2 224) -
(y0 + y1 * pow2 56 + y2 * pow2 112 + y3 * pow2 168 + y4 * pow2 224) + b4 * pow2 280)
by (int_semiring ());
()
val lemma_div224: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1))
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
wide_as_nat5 x / pow2 224 ==
v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280))
#push-options "--z3rlimit 50"
let lemma_div224 x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert
(wide_as_nat5 x ==
v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168 + v x4 * pow2 224 +
v x5 * pow2 280 + v x6 * pow2 336 + v x7 * pow2 392 + v x8 * pow2 448 + v x9 * pow2 504);
assert_norm (pow2 56 * pow2 224 == pow2 280);
assert_norm (pow2 112 * pow2 224 == pow2 336);
assert_norm (pow2 168 * pow2 224 == pow2 392);
assert_norm (pow2 224 * pow2 224 == pow2 448);
assert_norm (pow2 280 * pow2 224 == pow2 504);
calc (==) {
wide_as_nat5 x / pow2 224;
(==) { }
(v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168 +
(v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280) * pow2 224) / pow2 224;
(==) {
FStar.Math.Lemmas.lemma_div_plus
(v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168)
(v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280) (pow2 224) }
(v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168) / pow2 224 +
v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280;
(==) { FStar.Math.Lemmas.small_division_lemma_1 (v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168) (pow2 224) }
v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280;
}
#pop-options
val lemma_div248_aux: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 512)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
wide_as_nat5 x / pow2 248 ==
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256))
open FStar.Tactics.CanonCommSemiring
#push-options "--z3cliopt smt.arith.nl=false"
let lemma_div248_aux x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert_norm (pow2 248 == pow2 224 * pow2 24);
assert_norm (pow2 56 == pow2 32 * pow2 24);
assert_norm (pow2 112 == pow2 88 * pow2 24);
assert_norm (pow2 168 == pow2 144 * pow2 24);
assert_norm (pow2 224 == pow2 200 * pow2 24);
assert_norm (pow2 280 == pow2 256 * pow2 24);
assert_norm (0 < pow2 24);
calc (==) {
wide_as_nat5 x / pow2 248;
(==) { FStar.Math.Lemmas.division_multiplication_lemma (wide_as_nat5 x) (pow2 224) (pow2 24) }
(wide_as_nat5 x / pow2 224) / pow2 24;
(==) { lemma_div224 x }
(v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280) / pow2 24;
(==) { _ by (Tactics.mapply (`feq #int #int (fun x -> x / pow2 24)); int_semiring ()) } (v x4 + (v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256) * pow2 24) / pow2 24;
(==) { FStar.Math.Lemmas.lemma_div_plus (v x4) (v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256) (pow2 24) }
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256;
}
#pop-options
val lemma_div248_x5: x5:uint64 ->
Lemma ( pow2 32 * (v x5 % pow2 24) + v x5 / pow2 24 * pow2 56 == v x5 * pow2 32)
let lemma_div248_x5 x5 =
assert_norm (pow2 32 * pow2 24 = pow2 56)
val lemma_div248_x6: x6:uint64 ->
Lemma (pow2 32 * (v x6 % pow2 24) * pow2 56 + v x6 / pow2 24 * pow2 112 == v x6 * pow2 88)
let lemma_div248_x6 x6 =
calc (==) {
pow2 32 * (v x6 % pow2 24) * pow2 56 + v x6 / pow2 24 * pow2 112;
(==) { _ by (Tactics.norm [delta_only [`%pow2]; primops]; int_semiring ()) }
((v x6 / pow2 24) * pow2 24 + v x6 % pow2 24) * pow2 88;
(==) { FStar.Math.Lemmas.euclidean_division_definition (v x6) (pow2 24) }
v x6 * pow2 88;
}
val lemma_div248_x7: x7:uint64 -> | {
"checked_file": "/",
"dependencies": [
"Spec.Ed25519.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.BignumQ.Definitions.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Tactics.CanonCommSemiring.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.BignumQ.Lemmas.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.CanonCommSemiring",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.BignumQ.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.Ed25519",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.CanonCommSemiring",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.BignumQ",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.BignumQ",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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 | x7: Lib.IntTypes.uint64
-> FStar.Pervasives.Lemma
(ensures
(Prims.pow2 32 * (Lib.IntTypes.v x7 % Prims.pow2 24)) * Prims.pow2 112 +
(Lib.IntTypes.v x7 / Prims.pow2 24) * Prims.pow2 168 ==
Lib.IntTypes.v x7 * Prims.pow2 144) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Lib.IntTypes.uint64",
"FStar.Calc.calc_finish",
"Prims.int",
"Prims.eq2",
"Prims.op_Addition",
"FStar.Mul.op_Star",
"Prims.pow2",
"Prims.op_Modulus",
"Lib.IntTypes.v",
"Lib.IntTypes.U64",
"Lib.IntTypes.SEC",
"Prims.op_Division",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"Prims.unit",
"FStar.Calc.calc_step",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"FStar.Tactics.CanonCommSemiring.semiring_reflect",
"FStar.Tactics.CanonCommSemiring.int_cr",
"FStar.Pervasives.Native.Mktuple2",
"Prims.list",
"FStar.Pervasives.Native.tuple2",
"Prims.nat",
"FStar.Pervasives.Native.snd",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"Lib.IntTypes.sec_int_v",
"FStar.Stubs.Reflection.V2.Data.var",
"FStar.Tactics.CanonCommSemiring.Pplus",
"FStar.Tactics.CanonCommSemiring.Pmult",
"FStar.Tactics.CanonCommSemiring.Pvar",
"Prims.squash",
"FStar.Math.Lemmas.euclidean_division_definition"
] | [] | false | false | true | false | false | let lemma_div248_x7 x7 =
| calc ( == ) {
(pow2 32 * (v x7 % pow2 24)) * pow2 112 + (v x7 / pow2 24) * pow2 168;
( == ) { FStar.Tactics.Effect.synth_by_tactic (fun _ ->
(Tactics.norm [delta_only [`%pow2]; primops];
int_semiring ())) }
((v x7 / pow2 24) * pow2 24 + v x7 % pow2 24) * pow2 144;
( == ) { FStar.Math.Lemmas.euclidean_division_definition (v x7) (pow2 24) }
v x7 * pow2 144;
} | false |
SfBasic.fst | SfBasic.plus_comm | val plus_comm : n : nat -> m : nat -> Lemma
(ensures (plus n m = plus m n)) | val plus_comm : n : nat -> m : nat -> Lemma
(ensures (plus n m = plus m n)) | let rec plus_comm n m =
match n with
| O -> plus_0_r m
| S n' -> plus_comm n' m; plus_n_Sm m n' | {
"file_name": "examples/software_foundations/SfBasic.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 42,
"end_line": 225,
"start_col": 0,
"start_line": 222
} | (*
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.
*)
(*
A translation to F* of Basics.v from Software Foundations
Original name: "Basics: Functional Programming in Coq"
*)
module SfBasic
type day =
| Monday
| Tuesday
| Wednesday
| Thursday
| Friday
| Saturday
| Sunday
val next_weekday : day -> Tot day
let next_weekday d =
match d with
| Monday -> Tuesday
| Tuesday -> Wednesday
| Wednesday -> Thursday
| Thursday -> Friday
| Friday -> Monday
| Saturday -> Monday
| Sunday -> Monday
val test_next_weekday : unit -> Lemma
(ensures ((next_weekday (next_weekday Saturday)) = Tuesday))
let test_next_weekday () = ()
(* Booleans *)
(* The original example calls these bool, True, and False,
and that doesn't seem to cause problems;
I've just renamed them to be 100% sure that's not the cause
of the troubles in this file *)
type mbool =
| MTrue
| MFalse
val negb : mbool -> Tot mbool
let negb b =
match b with
| MTrue -> MFalse
| MFalse -> MTrue
val andb : mbool -> mbool -> Tot mbool
let andb b1 b2 =
match b1 with
| MTrue -> b2
| MFalse -> MFalse
val orb : mbool -> mbool -> Tot mbool
let orb b1 b2 =
match b1 with
| MTrue -> MTrue
| MFalse -> b2
val test_orb1 : unit -> Lemma
(ensures ((orb MTrue MFalse) = MTrue))
let test_orb1 () = ()
val test_orb2 : unit -> Lemma
(ensures ((orb MFalse MFalse) = MFalse))
let test_orb2 () = ()
val test_orb3 : unit -> Lemma
(ensures ((orb MFalse MTrue) = MTrue))
let test_orb3 () = ()
val test_orb4 : unit -> Lemma
(ensures ((orb MTrue MTrue) = MTrue))
let test_orb4 () = ()
(* Numbers *)
type nat =
| O : nat
| S : nat -> nat
val pred : nat -> Tot nat
let pred n =
match n with
| O -> O
| S n' -> n'
val minustwo : nat -> Tot nat
let minustwo n =
match n with
| O -> O
| S O -> O
| S (S n') -> n'
val evenb : nat -> Tot mbool
let rec evenb n =
match n with
| O -> MTrue
| S O -> MFalse
| S (S n') -> evenb n'
val oddb : nat -> Tot mbool
let oddb n = negb (evenb n)
val test_oddb1 : unit -> Lemma
(ensures ((oddb (S O)) = MTrue))
let test_oddb1 () = ()
val test_oddb2 : unit -> Lemma
(ensures (oddb (S (S (S (S O)))) = MFalse))
let test_oddb2 () = ()
val plus : nat -> nat -> Tot nat
let rec plus n m =
match n with
| O -> m
| S n' -> S (plus n' m)
val mult : nat -> nat -> Tot nat
let rec mult n m =
match n with
| O -> O
| S n' -> plus m (mult n' m)
val test_mult1 : unit -> Lemma
(ensures (mult (S (S (S O))) (S (S (S O))))
= (S (S (S (S (S (S (S (S (S O))))))))))
let test_mult1 () = ()
val minus : nat -> nat -> Tot nat
let rec minus (n : nat) (m : nat) : nat =
match n, m with
| O , _ -> O
| S _ , O -> n
| S n', S m' -> minus n' m'
val beq_nat : nat -> nat -> Tot mbool
let rec beq_nat n m =
match n, m with
| O , O -> MTrue
| S n', S m' -> beq_nat n' m'
| _ , _ -> MFalse
val ble_nat : nat -> nat -> Tot mbool
let rec ble_nat n m =
match n, m with
| O , _ -> MTrue
| S n', O -> MFalse
| S n', S m' -> ble_nat n' m'
val test_ble_nat1 : unit -> Lemma
(ensures (ble_nat (S (S O)) (S (S O)) = MTrue))
let test_ble_nat1 () = ()
val test_ble_nat2 : unit -> Lemma
(ensures (ble_nat (S (S O)) (S (S (S (S O)))) = MTrue))
let test_ble_nat2 () = ()
val test_ble_nat3 : unit -> Lemma
(ensures (ble_nat (S (S (S (S O)))) (S (S O)) = MFalse))
let test_ble_nat3 () = ()
(* Proof by Simplification *)
val plus_O_n : n : nat -> Lemma
(ensures (plus O n = n))
let plus_O_n n = ()
(* Proof by Rewriting *)
val plus_id_example : n : nat -> m : nat -> Pure unit
(requires (n == m))
(ensures (fun r -> (plus n n = plus m m)))
let plus_id_example n m = ()
val mult_0_plus : n : nat -> m : nat -> Lemma
(ensures ((mult (plus O n) m) = mult n m))
let mult_0_plus n m = ()
(* Proof by Case Analysis *)
val plus_1_neq_0 : n : nat -> Lemma
(ensures (beq_nat (plus n (S O)) O = MFalse))
let plus_1_neq_0 n = ()
val negb_involutive : b : mbool -> Lemma
(ensures (negb (negb b) = b))
let negb_involutive b = ()
(* Proof by Induction (Induction.v) *)
val plus_0_r : n : nat -> Lemma
(ensures (plus n O = n))
let rec plus_0_r n =
match n with
| O -> ()
| S n' -> plus_0_r n'
val plus_n_Sm : n : nat -> m : nat -> Lemma
(ensures (S (plus n m) = plus n (S m)))
let rec plus_n_Sm n m =
match n with
| O -> ()
| S n' -> plus_n_Sm n' m
(* this one uses previous lemma -- needs to be explicit it seems *)
val plus_comm : n : nat -> m : nat -> Lemma | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "SfBasic.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | n: SfBasic.nat -> m: SfBasic.nat
-> FStar.Pervasives.Lemma (ensures SfBasic.plus n m = SfBasic.plus m n) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"SfBasic.nat",
"SfBasic.plus_0_r",
"SfBasic.plus_n_Sm",
"Prims.unit",
"SfBasic.plus_comm"
] | [
"recursion"
] | false | false | true | false | false | let rec plus_comm n m =
| match n with
| O -> plus_0_r m
| S n' ->
plus_comm n' m;
plus_n_Sm m n' | false |
Hacl.Spec.BignumQ.Lemmas.fst | Hacl.Spec.BignumQ.Lemmas.lemma_mod_264'' | val lemma_mod_264'':
a0:nat -> a1:nat-> a2:nat -> a3:nat -> a4:nat ->
Lemma
(requires a0 < pow56 /\ a1 < pow56 /\ a2 < pow56 /\ a3 < pow56)
(ensures a0 + pow2 56 * a1 + pow2 112 * a2 + pow2 168 * a3 + pow2 224 * (a4 % pow2 40) < pow2 264) | val lemma_mod_264'':
a0:nat -> a1:nat-> a2:nat -> a3:nat -> a4:nat ->
Lemma
(requires a0 < pow56 /\ a1 < pow56 /\ a2 < pow56 /\ a3 < pow56)
(ensures a0 + pow2 56 * a1 + pow2 112 * a2 + pow2 168 * a3 + pow2 224 * (a4 % pow2 40) < pow2 264) | let lemma_mod_264'' a0 a1 a2 a3 a4 =
assert_norm(pow2 40 = 0x10000000000);
assert_norm(pow2 56 = 0x100000000000000);
assert_norm(pow2 112 = 0x10000000000000000000000000000);
assert_norm(pow2 168 = 0x1000000000000000000000000000000000000000000);
assert_norm(pow2 224 = 0x100000000000000000000000000000000000000000000000000000000);
assert_norm(pow2 264 = 0x1000000000000000000000000000000000000000000000000000000000000000000) | {
"file_name": "code/ed25519/Hacl.Spec.BignumQ.Lemmas.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 95,
"end_line": 712,
"start_col": 0,
"start_line": 706
} | module Hacl.Spec.BignumQ.Lemmas
open FStar.Tactics.CanonCommSemiring
open FStar.Mul
open Lib.IntTypes
module S = Spec.Ed25519
include Hacl.Spec.BignumQ.Definitions
let feq (#a #b:Type) (f:(a -> b)) (x y:a) :
Lemma (requires x == y) (ensures f x == f y) = ()
let eq_eq2 (#a:eqtype) (x y:a) :
Lemma (requires x = y) (ensures x == y) = ()
val lemma_mul_lt:a:nat -> b:nat -> c:nat -> d:nat ->
Lemma
(requires a < b /\ c < d)
(ensures a * c < b * d)
let lemma_mul_lt a b c d = ()
val lemma_as_nat5: f:qelem5 ->
Lemma
(requires qelem_fits5 f (1, 1, 1, 1, 1))
(ensures as_nat5 f < pow2 280)
let lemma_as_nat5 f =
//let (f0, f1, f2, f3, f4) = f in
//assert (as_nat5 f == v f0 + v f1 * pow56 + v f2 * pow112 + v f3 * pow168 + v f4 * pow224);
assert_norm (pow2 56 * pow2 56 = pow2 112);
assert_norm (pow2 56 * pow2 112 = pow2 168);
assert_norm (pow2 56 * pow2 168 = pow2 224);
assert_norm (pow2 56 * pow2 224 = pow2 280)
val lemma_choose_step:
bit:uint64{v bit <= 1}
-> x:uint64
-> y:uint64
-> Lemma
(let mask = bit -. u64 1 in
let z = x ^. (mask &. (x ^. y)) in
if v bit = 1 then z == x else z == y)
let lemma_choose_step bit p1 p2 =
let mask = bit -. u64 1 in
assert (v bit == 0 ==> v mask == pow2 64 - 1);
assert (v bit == 1 ==> v mask == 0);
let dummy = mask &. (p1 ^. p2) in
logand_lemma mask (p1 ^. p2);
assert (v bit == 1 ==> v dummy == 0);
assert (v bit == 0 ==> v dummy == v (p1 ^. p2));
let p1' = p1 ^. dummy in
assert (v dummy == v (if v bit = 1 then u64 0 else (p1 ^. p2)));
logxor_lemma p1 p2
val lemma_subm_conditional:
x0:nat -> x1:nat -> x2:nat -> x3:nat -> x4:nat
-> y0:nat -> y1:nat -> y2:nat -> y3:nat -> y4:nat
-> b0:nat -> b1:nat -> b2:nat -> b3:nat -> b4:nat ->
Lemma (
x0 - y0 + b0 * pow2 56 +
(x1 - y1 - b0 + b1 * pow2 56) * pow2 56 +
(x2 - y2 - b1 + b2 * pow2 56) * pow2 112 +
(x3 - y3 - b2 + b3 * pow2 56) * pow2 168 +
(x4 - y4 - b3 + b4 * pow2 56) * pow2 224 ==
(x0 + x1 * pow2 56 + x2 * pow2 112 + x3 * pow2 168 + x4 * pow2 224) -
(y0 + y1 * pow2 56 + y2 * pow2 112 + y3 * pow2 168 + y4 * pow2 224) + b4 * pow2 280)
let lemma_subm_conditional x0 x1 x2 x3 x4 y0 y1 y2 y3 y4 b0 b1 b2 b3 b4 =
assert_norm (pow2 56 * pow2 56 = pow2 112);
assert_norm (pow2 56 * pow2 112 = pow2 168);
assert_norm (pow2 56 * pow2 168 = pow2 224);
assert_norm (pow2 56 * pow2 224 = pow2 280);
assert (
x0 - y0 + b0 * pow2 56 +
(x1 - y1 - b0 + b1 * pow2 56) * pow2 56 +
(x2 - y2 - b1 + b2 * pow2 56) * pow2 112 +
(x3 - y3 - b2 + b3 * pow2 56) * pow2 168 +
(x4 - y4 - b3 + b4 * pow2 56) * pow2 224 ==
(x0 + x1 * pow2 56 + x2 * pow2 112 + x3 * pow2 168 + x4 * pow2 224) -
(y0 + y1 * pow2 56 + y2 * pow2 112 + y3 * pow2 168 + y4 * pow2 224) + b4 * pow2 280)
by (int_semiring ());
()
val lemma_div224: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1))
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
wide_as_nat5 x / pow2 224 ==
v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280))
#push-options "--z3rlimit 50"
let lemma_div224 x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert
(wide_as_nat5 x ==
v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168 + v x4 * pow2 224 +
v x5 * pow2 280 + v x6 * pow2 336 + v x7 * pow2 392 + v x8 * pow2 448 + v x9 * pow2 504);
assert_norm (pow2 56 * pow2 224 == pow2 280);
assert_norm (pow2 112 * pow2 224 == pow2 336);
assert_norm (pow2 168 * pow2 224 == pow2 392);
assert_norm (pow2 224 * pow2 224 == pow2 448);
assert_norm (pow2 280 * pow2 224 == pow2 504);
calc (==) {
wide_as_nat5 x / pow2 224;
(==) { }
(v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168 +
(v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280) * pow2 224) / pow2 224;
(==) {
FStar.Math.Lemmas.lemma_div_plus
(v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168)
(v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280) (pow2 224) }
(v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168) / pow2 224 +
v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280;
(==) { FStar.Math.Lemmas.small_division_lemma_1 (v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168) (pow2 224) }
v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280;
}
#pop-options
val lemma_div248_aux: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 512)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
wide_as_nat5 x / pow2 248 ==
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256))
open FStar.Tactics.CanonCommSemiring
#push-options "--z3cliopt smt.arith.nl=false"
let lemma_div248_aux x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert_norm (pow2 248 == pow2 224 * pow2 24);
assert_norm (pow2 56 == pow2 32 * pow2 24);
assert_norm (pow2 112 == pow2 88 * pow2 24);
assert_norm (pow2 168 == pow2 144 * pow2 24);
assert_norm (pow2 224 == pow2 200 * pow2 24);
assert_norm (pow2 280 == pow2 256 * pow2 24);
assert_norm (0 < pow2 24);
calc (==) {
wide_as_nat5 x / pow2 248;
(==) { FStar.Math.Lemmas.division_multiplication_lemma (wide_as_nat5 x) (pow2 224) (pow2 24) }
(wide_as_nat5 x / pow2 224) / pow2 24;
(==) { lemma_div224 x }
(v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280) / pow2 24;
(==) { _ by (Tactics.mapply (`feq #int #int (fun x -> x / pow2 24)); int_semiring ()) } (v x4 + (v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256) * pow2 24) / pow2 24;
(==) { FStar.Math.Lemmas.lemma_div_plus (v x4) (v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256) (pow2 24) }
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256;
}
#pop-options
val lemma_div248_x5: x5:uint64 ->
Lemma ( pow2 32 * (v x5 % pow2 24) + v x5 / pow2 24 * pow2 56 == v x5 * pow2 32)
let lemma_div248_x5 x5 =
assert_norm (pow2 32 * pow2 24 = pow2 56)
val lemma_div248_x6: x6:uint64 ->
Lemma (pow2 32 * (v x6 % pow2 24) * pow2 56 + v x6 / pow2 24 * pow2 112 == v x6 * pow2 88)
let lemma_div248_x6 x6 =
calc (==) {
pow2 32 * (v x6 % pow2 24) * pow2 56 + v x6 / pow2 24 * pow2 112;
(==) { _ by (Tactics.norm [delta_only [`%pow2]; primops]; int_semiring ()) }
((v x6 / pow2 24) * pow2 24 + v x6 % pow2 24) * pow2 88;
(==) { FStar.Math.Lemmas.euclidean_division_definition (v x6) (pow2 24) }
v x6 * pow2 88;
}
val lemma_div248_x7: x7:uint64 ->
Lemma (pow2 32 * (v x7 % pow2 24) * pow2 112 + v x7 / pow2 24 * pow2 168 == v x7 * pow2 144)
let lemma_div248_x7 x7 =
calc (==) {
pow2 32 * (v x7 % pow2 24) * pow2 112 + v x7 / pow2 24 * pow2 168;
(==) { _ by (Tactics.norm [delta_only [`%pow2]; primops]; int_semiring ()) }
((v x7 / pow2 24) * pow2 24 + v x7 % pow2 24) * pow2 144;
(==) { FStar.Math.Lemmas.euclidean_division_definition (v x7) (pow2 24) }
v x7 * pow2 144;
}
val lemma_div248_x8: x8:uint64 ->
Lemma (pow2 32 * (v x8 % pow2 24) * pow2 168 + v x8 / pow2 24 * pow2 224 == v x8 * pow2 200)
let lemma_div248_x8 x8 =
calc (==) {
pow2 32 * (v x8 % pow2 24) * pow2 168 + v x8 / pow2 24 * pow2 224;
(==) { _ by (Tactics.norm [delta_only [`%pow2]; primops]; int_semiring ()) }
((v x8 / pow2 24) * pow2 24 + v x8 % pow2 24) * pow2 200;
(==) { FStar.Math.Lemmas.euclidean_division_definition (v x8) (pow2 24) }
v x8 * pow2 200;
}
val lemma_div248_x9: x9:uint64{v x9 < pow2 24} ->
Lemma (pow2 32 * (v x9 % pow2 24) * pow2 224 == v x9 * pow2 256)
let lemma_div248_x9 x9 =
calc (==) {
pow2 32 * (v x9 % pow2 24) * pow2 224;
(==) { Math.Lemmas.small_mod (v x9) (pow2 24) }
pow2 32 * v x9 * pow2 224;
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
v x9 * pow2 256;
}
val lemma_wide_as_nat_pow512: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 512)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
v x9 < pow2 24))
let lemma_wide_as_nat_pow512 x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert_norm (pow2 504 * pow2 8 = pow2 512);
FStar.Math.Lemmas.pow2_minus 512 504;
assert (v x9 < pow2 8);
assert_norm (pow2 8 < pow2 24)
val lemma_div248: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 512)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
let z0 = v x4 / pow2 24 + pow2 32 * (v x5 % pow2 24) in
let z1 = v x5 / pow2 24 + pow2 32 * (v x6 % pow2 24) in
let z2 = v x6 / pow2 24 + pow2 32 * (v x7 % pow2 24) in
let z3 = v x7 / pow2 24 + pow2 32 * (v x8 % pow2 24) in
let z4 = v x8 / pow2 24 + pow2 32 * (v x9 % pow2 24) in
wide_as_nat5 x / pow2 248 == z0 + z1 * pow2 56 + z2 * pow2 112 + z3 * pow2 168 + z4 * pow2 224))
#push-options "--z3rlimit 50"
let lemma_div248 x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
lemma_wide_as_nat_pow512 x;
assert (v x9 < pow2 24);
calc (==) {
(let z0 = v x4 / pow2 24 + pow2 32 * (v x5 % pow2 24) in
let z1 = v x5 / pow2 24 + pow2 32 * (v x6 % pow2 24) in
let z2 = v x6 / pow2 24 + pow2 32 * (v x7 % pow2 24) in
let z3 = v x7 / pow2 24 + pow2 32 * (v x8 % pow2 24) in
let z4 = v x8 / pow2 24 + pow2 32 * (v x9 % pow2 24) in
z0 + z1 * pow2 56 + z2 * pow2 112 + z3 * pow2 168 + z4 * pow2 224);
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
v x4 / pow2 24 + pow2 32 * (v x5 % pow2 24) +
v x5 / pow2 24 * pow2 56 + pow2 32 * (v x6 % pow2 24) * pow2 56 +
v x6 / pow2 24 * pow2 112 + pow2 32 * (v x7 % pow2 24) * pow2 112 +
v x7 / pow2 24 * pow2 168 + pow2 32 * (v x8 % pow2 24) * pow2 168 +
v x8 / pow2 24 * pow2 224 + pow2 32 * (v x9 % pow2 24) * pow2 224;
(==) { lemma_div248_x5 x5; lemma_div248_x6 x6 }
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 +
pow2 32 * (v x7 % pow2 24) * pow2 112 +
v x7 / pow2 24 * pow2 168 + pow2 32 * (v x8 % pow2 24) * pow2 168 +
v x8 / pow2 24 * pow2 224 + pow2 32 * (v x9 % pow2 24) * pow2 224;
(==) { lemma_div248_x7 x7; lemma_div248_x8 x8 }
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 +
pow2 32 * (v x9 % pow2 24) * pow2 224;
(==) { lemma_div248_x9 x9 }
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256;
(==) { lemma_div248_aux x }
wide_as_nat5 x / pow2 248;
}
#pop-options
val lemma_add_modq5:
x:qelem5
-> y:qelem5
-> t:qelem5 ->
Lemma
(requires
qelem_fits5 x (1, 1, 1, 1, 1) /\
qelem_fits5 y (1, 1, 1, 1, 1) /\
qelem_fits5 t (1, 1, 1, 1, 1) /\
as_nat5 x < S.q /\ as_nat5 y < S.q /\
as_nat5 t == as_nat5 x + as_nat5 y)
(ensures
(let res = if as_nat5 t >= S.q then as_nat5 t - S.q else as_nat5 t in
res < S.q /\ res == (as_nat5 x + as_nat5 y) % S.q))
let lemma_add_modq5 x y t =
assert (as_nat5 t == as_nat5 x + as_nat5 y);
let res = if as_nat5 t >= S.q then as_nat5 t - S.q else as_nat5 t in
assert (res < S.q);
if as_nat5 t >= S.q then (
FStar.Math.Lemmas.sub_div_mod_1 (as_nat5 t) S.q;
assert (res % S.q == as_nat5 t % S.q))
else
assert (res % S.q == as_nat5 t % S.q);
FStar.Math.Lemmas.small_mod res S.q
val lemma_wide_as_nat_pow528: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 528)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
v x9 < pow2 40))
let lemma_wide_as_nat_pow528 x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert_norm (pow2 504 * pow2 24 = pow2 528);
FStar.Math.Lemmas.pow2_minus 528 504;
assert (v x9 < pow2 24);
assert_norm (pow2 24 < pow2 40)
#push-options "--z3cliopt smt.arith.nl=false"
val lemma_div264_aux: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 528)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
wide_as_nat5 x / pow2 264 ==
v x4 / pow2 40 + v x5 * pow2 16 + v x6 * pow2 72 + v x7 * pow2 128 + v x8 * pow2 184 + v x9 * pow2 240))
let lemma_div264_aux x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert_norm (pow2 264 == pow2 224 * pow2 40);
assert_norm (pow2 56 == pow2 16 * pow2 40);
assert_norm (pow2 112 == pow2 72 * pow2 40);
assert_norm (pow2 168 == pow2 128 * pow2 40);
assert_norm (pow2 224 == pow2 184 * pow2 40);
assert_norm (pow2 280 == pow2 240 * pow2 40);
assert_norm (0 < pow2 40);
calc (==) {
wide_as_nat5 x / pow2 264;
(==) { FStar.Math.Lemmas.division_multiplication_lemma (wide_as_nat5 x) (pow2 224) (pow2 40) }
(wide_as_nat5 x / pow2 224) / pow2 40;
(==) { lemma_div224 x }
(v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280) / pow2 40;
(==) { _ by (Tactics.mapply (`feq #int #int (fun x -> x / pow2 40)); int_semiring ()) }
(v x4 + (v x5 * pow2 16 + v x6 * pow2 72 + v x7 * pow2 128 + v x8 * pow2 184 + v x9 * pow2 240) * pow2 40) / pow2 40;
(==) { FStar.Math.Lemmas.lemma_div_plus (v x4) (v x5 * pow2 16 + v x6 * pow2 72 + v x7 * pow2 128 + v x8 * pow2 184 + v x9 * pow2 240) (pow2 40) }
v x4 / pow2 40 + v x5 * pow2 16 + v x6 * pow2 72 + v x7 * pow2 128 + v x8 * pow2 184 + v x9 * pow2 240;
}
val lemma_div264_x5: x5:uint64 ->
Lemma (pow2 16 * (v x5 % pow2 40) + v x5 / pow2 40 * pow2 56 == v x5 * pow2 16)
let lemma_div264_x5 x5 =
assert_norm (0 < pow2 24);
calc (==) {
pow2 16 * (v x5 % pow2 40) + v x5 / pow2 40 * pow2 56;
(==) { _ by (Tactics.norm [delta_only [`%pow2]; primops]; int_semiring ()) }
((v x5 / pow2 40) * pow2 40 + v x5 % pow2 40) * pow2 16;
(==) { FStar.Math.Lemmas.euclidean_division_definition (v x5) (pow2 40) }
v x5 * pow2 16;
}
val lemma_div264_x6: x6:uint64 ->
Lemma (pow2 16 * (v x6 % pow2 40) * pow2 56 + v x6 / pow2 40 * pow2 112 == v x6 * pow2 72)
let lemma_div264_x6 x6 =
calc (==) {
pow2 16 * (v x6 % pow2 40) * pow2 56 + v x6 / pow2 40 * pow2 112;
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
((v x6 / pow2 40) * pow2 40 + v x6 % pow2 40) * pow2 72;
(==) { Math.Lemmas.euclidean_division_definition (v x6) (pow2 40) }
v x6 * pow2 72;
}
val lemma_div264_x7: x7:uint64 ->
Lemma (pow2 16 * (v x7 % pow2 40) * pow2 112 + v x7 / pow2 40 * pow2 168 == v x7 * pow2 128)
let lemma_div264_x7 x7 =
calc (==) {
pow2 16 * (v x7 % pow2 40) * pow2 112 + v x7 / pow2 40 * pow2 168;
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
((v x7 / pow2 40) * pow2 40 + v x7 % pow2 40) * pow2 128;
(==) { Math.Lemmas.euclidean_division_definition (v x7) (pow2 40) }
v x7 * pow2 128;
}
val lemma_div264_x8: x8:uint64 ->
Lemma (pow2 16 * (v x8 % pow2 40) * pow2 168 + v x8 / pow2 40 * pow2 224 == v x8 * pow2 184)
let lemma_div264_x8 x8 =
calc (==) {
pow2 16 * (v x8 % pow2 40) * pow2 168 + v x8 / pow2 40 * pow2 224;
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
((v x8 / pow2 40) * pow2 40 + v x8 % pow2 40) * pow2 184;
(==) { Math.Lemmas.euclidean_division_definition (v x8) (pow2 40) }
v x8 * pow2 184;
}
val lemma_div264_x9: x9:uint64{v x9 < pow2 40} ->
Lemma (pow2 16 * (v x9 % pow2 40) * pow2 224 == v x9 * pow2 240)
let lemma_div264_x9 x9 =
calc (==) {
pow2 16 * (v x9 % pow2 40) * pow2 224;
(==) { Math.Lemmas.small_mod (v x9) (pow2 40) }
pow2 16 * v x9 * pow2 224;
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
v x9 * pow2 240;
}
val lemma_div264: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 528)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
let z0 = v x4 / pow2 40 + pow2 16 * (v x5 % pow2 40) in
let z1 = v x5 / pow2 40 + pow2 16 * (v x6 % pow2 40) in
let z2 = v x6 / pow2 40 + pow2 16 * (v x7 % pow2 40) in
let z3 = v x7 / pow2 40 + pow2 16 * (v x8 % pow2 40) in
let z4 = v x8 / pow2 40 + pow2 16 * (v x9 % pow2 40) in
wide_as_nat5 x / pow2 264 == z0 + z1 * pow2 56 + z2 * pow2 112 + z3 * pow2 168 + z4 * pow2 224))
#push-options "--z3rlimit 50"
let lemma_div264 x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
lemma_wide_as_nat_pow528 x;
assert (v x9 < pow2 40);
calc (==) {
(let z0 = v x4 / pow2 40 + pow2 16 * (v x5 % pow2 40) in
let z1 = v x5 / pow2 40 + pow2 16 * (v x6 % pow2 40) in
let z2 = v x6 / pow2 40 + pow2 16 * (v x7 % pow2 40) in
let z3 = v x7 / pow2 40 + pow2 16 * (v x8 % pow2 40) in
let z4 = v x8 / pow2 40 + pow2 16 * (v x9 % pow2 40) in
z0 + z1 * pow2 56 + z2 * pow2 112 + z3 * pow2 168 + z4 * pow2 224);
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
v x4 / pow2 40 + pow2 16 * (v x5 % pow2 40) +
v x5 / pow2 40 * pow2 56 + pow2 16 * (v x6 % pow2 40) * pow2 56 +
v x6 / pow2 40 * pow2 112 + pow2 16 * (v x7 % pow2 40) * pow2 112 +
v x7 / pow2 40 * pow2 168 + pow2 16 * (v x8 % pow2 40) * pow2 168 +
v x8 / pow2 40 * pow2 224 + pow2 16 * (v x9 % pow2 40) * pow2 224;
(==) { lemma_div264_x5 x5; lemma_div264_x6 x6 }
v x4 / pow2 40 + v x5 * pow2 16 + v x6 * pow2 72 +
pow2 16 * (v x7 % pow2 40) * pow2 112 +
v x7 / pow2 40 * pow2 168 + pow2 16 * (v x8 % pow2 40) * pow2 168 +
v x8 / pow2 40 * pow2 224 + pow2 16 * (v x9 % pow2 40) * pow2 224;
(==) { lemma_div264_x7 x7; lemma_div264_x8 x8 }
v x4 / pow2 40 + v x5 * pow2 16 + v x6 * pow2 72 + v x7 * pow2 128 + v x8 * pow2 184 +
pow2 16 * (v x9 % pow2 40) * pow2 224;
(==) { lemma_div264_x9 x9 }
v x4 / pow2 40 + v x5 * pow2 16 + v x6 * pow2 72 + v x7 * pow2 128 + v x8 * pow2 184 + v x9 * pow2 240;
(==) { lemma_div264_aux x }
wide_as_nat5 x / pow2 264;
}
#pop-options
#pop-options // "--z3cliopt smt.arith.nl=false"
val lemma_mod_264_aux: t:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 t (1, 1, 1, 1, 1, 1, 1, 1, 1, 1))
(ensures
(let (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) = t in
(wide_as_nat5 t) % pow2 264 ==
(v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + v t4 * pow2 224) % pow2 264))
#push-options "--z3rlimit 150"
let lemma_mod_264_aux t =
let (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) = t in
let res = (t0, t1, t2, t3, t4 &. u64 0xffffffffff) in
assert_norm (pow2 16 * pow2 264 == pow2 280);
assert_norm (pow2 72 * pow2 264 == pow2 336);
assert_norm (pow2 128 * pow2 264 == pow2 392);
assert_norm (pow2 184 * pow2 264 == pow2 448);
assert_norm (pow2 240 * pow2 264 == pow2 504);
calc (==) {
(wide_as_nat5 t) % pow2 264;
(==) { }
(v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + v t4 * pow2 224 +
(v t5 * pow2 16 + v t6 * pow2 72 + v t7 * pow2 128 + v t8 * pow2 184 + v t9 * pow2 240) * pow2 264) % pow2 264;
(==) { FStar.Math.Lemmas.lemma_mod_add_distr (v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + v t4 * pow2 224)
((v t5 * pow2 16 + v t6 * pow2 72 + v t7 * pow2 128 + v t8 * pow2 184 + v t9 * pow2 240) * pow2 264) (pow2 264)}
((v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + v t4 * pow2 224) +
((v t5 * pow2 16 + v t6 * pow2 72 + v t7 * pow2 128 + v t8 * pow2 184 + v t9 * pow2 240) * pow2 264) % pow2 264) % pow2 264;
(==) { FStar.Math.Lemmas.cancel_mul_mod (v t5 * pow2 16 + v t6 * pow2 72 + v t7 * pow2 128 + v t8 * pow2 184 + v t9 * pow2 240) (pow2 264) }
(v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + v t4 * pow2 224) % pow2 264;
}
#pop-options
val lemma_as_nat_pow264: x:qelem5 ->
Lemma
(requires
(let (x0, x1, x2, x3, x4) = x in
qelem_fits5 x (1, 1, 1, 1, 1) /\
v x4 < pow2 40))
(ensures as_nat5 x < pow2 264)
let lemma_as_nat_pow264 x =
let (x0, x1, x2, x3, x4) = x in
assert_norm (pow2 40 * pow2 224 = pow2 264)
val lemma_mod_264: t:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 t (1, 1, 1, 1, 1, 1, 1, 1, 1, 1))
(ensures
(let (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) = t in
let res = (t0, t1, t2, t3, t4 &. u64 0xffffffffff) in
qelem_fits5 res (1, 1, 1, 1, 1) /\
as_nat5 res == (wide_as_nat5 t) % pow2 264))
let lemma_mod_264 t =
let (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) = t in
let t4' = t4 &. u64 0xffffffffff in
let res = (t0, t1, t2, t3, t4') in
assert_norm (pow2 40 < pow2 64);
assert_norm (pow2 40 - 1 == 0xffffffffff);
mod_mask_lemma t4 40ul;
assert (v (mod_mask #U64 #SEC 40ul) == 0xffffffffff);
assert (v (t4 &. u64 0xffffffffff) == v t4 % pow2 40);
calc (==) {
(wide_as_nat5 t) % pow2 264;
(==) { lemma_mod_264_aux t }
(v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + v t4 * pow2 224) % pow2 264;
(==) { FStar.Math.Lemmas.lemma_mod_add_distr (v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168) (v t4 * pow2 224) (pow2 264) }
(v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + (v t4 * pow2 224) % pow2 264) % pow2 264;
(==) { FStar.Math.Lemmas.pow2_multiplication_modulo_lemma_2 (v t4) 264 224 }
(v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + (v t4 % pow2 40) * pow2 224) % pow2 264;
(==) { lemma_as_nat_pow264 res; FStar.Math.Lemmas.modulo_lemma (as_nat5 res) (pow2 264) }
v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + (v t4 % pow2 40) * pow2 224;
}
val lemma_as_nat_pow264_x4: x:qelem5 ->
Lemma
(requires
qelem_fits5 x (1, 1, 1, 1, 1) /\
as_nat5 x < pow2 264)
(ensures
(let (x0, x1, x2, x3, x4) = x in
v x4 < pow2 40))
let lemma_as_nat_pow264_x4 x =
let (x0, x1, x2, x3, x4) = x in
assert_norm (pow2 40 * pow2 224 = pow2 264)
val lemma_sub_mod_264_aux:
x0:nat -> x1:nat -> x2:nat -> x3:nat -> x4:nat
-> y0:nat -> y1:nat -> y2:nat -> y3:nat -> y4:nat
-> c1:nat -> c2:nat -> c3:nat -> c4:nat -> c5:nat ->
Lemma (
x0 - y0 + c1 * pow56 +
(x1 - y1 - c1 + c2 * pow56) * pow56 +
(x2 - y2 - c2 + c3 * pow56) * pow112 +
(x3 - y3 - c3 + c4 * pow56) * pow168 +
(x4 - y4 - c4 + pow2 40 * c5) * pow224 ==
(x0 + x1 * pow2 56 + x2 * pow2 112 + x3 * pow2 168 + x4 * pow2 224) -
(y0 + y1 * pow2 56 + y2 * pow2 112 + y3 * pow2 168 + y4 * pow2 224) + c5 * pow2 264)
#push-options "--z3rlimit 50"
let lemma_sub_mod_264_aux x0 x1 x2 x3 x4 y0 y1 y2 y3 y4 b0 b1 b2 b3 b4 =
assert_norm (pow2 56 * pow2 56 = pow2 112);
assert_norm (pow2 56 * pow2 112 = pow2 168);
assert_norm (pow2 56 * pow2 168 = pow2 224);
assert_norm (pow2 40 * pow2 224 = pow2 264)
#pop-options
val lemma_sub_mod_264:
x:qelem5
-> y:qelem5
-> t:qelem5
-> c5:uint64 ->
Lemma
(requires
qelem_fits5 x (1, 1, 1, 1, 1) /\
qelem_fits5 y (1, 1, 1, 1, 1) /\
qelem_fits5 t (1, 1, 1, 1, 1) /\
as_nat5 x < pow2 264 /\
as_nat5 y < pow2 264 /\
as_nat5 t == as_nat5 x - as_nat5 y + v c5 * pow2 264 /\ v c5 <= 1 /\
(if v c5 = 0 then as_nat5 x >= as_nat5 y else as_nat5 x < as_nat5 y))
(ensures
(if as_nat5 x >= as_nat5 y then
as_nat5 t == as_nat5 x - as_nat5 y
else as_nat5 t == as_nat5 x - as_nat5 y + pow2 264))
#push-options "--z3rlimit 50"
let lemma_sub_mod_264 x y t c5 =
assert (if v c5 = 0 then as_nat5 x >= as_nat5 y else as_nat5 x < as_nat5 y);
assert (as_nat5 t == as_nat5 x - as_nat5 y + v c5 * pow2 264);
if as_nat5 x >= as_nat5 y then
assert (v c5 == 0 /\ as_nat5 t == as_nat5 x - as_nat5 y)
else
assert (v c5 == 1 /\ as_nat5 t == as_nat5 x - as_nat5 y + pow2 264)
#pop-options
let lemma_mul_qelem5 (x0 x1 x2 x3 x4 y0 y1 y2 y3 y4:nat) : Lemma
((x0 + x1 * pow2 56 + x2 * pow2 112 + x3 * pow2 168 + x4 * pow2 224) *
(y0 + y1 * pow2 56 + y2 * pow2 112 + y3 * pow2 168 + y4 * pow2 224) ==
x0 * y0 +
(x0 * y1 + x1 * y0) * pow56 +
(x0 * y2 + x1 * y1 + x2 * y0) * pow112 +
(x0 * y3 + x1 * y2 + x2 * y1 + x3 * y0) * pow168 +
(x0 * y4 + x1 * y3 + x2 * y2 + x3 * y1 + x4 * y0) * pow224 +
(x1 * y4 + x2 * y3 + x3 * y2 + x4 * y1) * pow280 +
(x2 * y4 + x3 * y3 + x4 * y2) * pow336 +
(x3 * y4 + x4 * y3) * pow392 +
(x4 * y4) * pow448)
=
assert ((x0 + x1 * pow2 56 + x2 * pow2 112 + x3 * pow2 168 + x4 * pow2 224) *
(y0 + y1 * pow2 56 + y2 * pow2 112 + y3 * pow2 168 + y4 * pow2 224) ==
x0 * y0 +
(x0 * y1 + x1 * y0) * pow56 +
(x0 * y2 + x1 * y1 + x2 * y0) * pow112 +
(x0 * y3 + x1 * y2 + x2 * y1 + x3 * y0) * pow168 +
(x0 * y4 + x1 * y3 + x2 * y2 + x3 * y1 + x4 * y0) * pow224 +
(x1 * y4 + x2 * y3 + x3 * y2 + x4 * y1) * pow280 +
(x2 * y4 + x3 * y3 + x4 * y2) * pow336 +
(x3 * y4 + x4 * y3) * pow392 +
(x4 * y4) * pow448)
by (Tactics.norm [zeta; iota; delta; primops]; int_semiring ())
val lemma_mul_5_low_264:
x1:nat -> x2:nat -> x3:nat -> x4:nat -> x5:nat ->
y1:nat -> y2:nat -> y3:nat -> y4:nat -> y5:nat ->
Lemma (
(x1 * y1) >= 0
/\ (x2 * y1 + x1 * y2 + ((x1 * y1) / pow2 56)) >= 0
/\ (x3 * y1 + x2 * y2 + x1 * y3 + ((x2 * y1 + x1 * y2 + ((x1 * y1) / pow2 56)) / pow2 56)) >= 0
/\ (x4 * y1 + x3 * y2 + x2 * y3 + x1 * y4 + ((x3 * y1 + x2 * y2 + x1 * y3 + ((x2 * y1 + x1 * y2 + ((x1 * y1) / pow2 56)) / pow2 56)) / pow2 56)) >= 0
/\ (
let a0 = (x1 * y1) % pow2 56 in
let a1 = ((x2 * y1 + x1 * y2 + ((x1 * y1) / pow2 56)) % pow2 56) in
let a2 = ((x3 * y1 + x2 * y2 + x1 * y3 + ((x2 * y1 + x1 * y2 + ((x1 * y1) / pow2 56)) / pow2 56)) % pow2 56) in
let a3 = ((x4 * y1 + x3 * y2 + x2 * y3 + x1 * y4 + ((x3 * y1 + x2 * y2 + x1 * y3 + ((x2 * y1 + x1 * y2 + ((x1 * y1) / pow2 56)) / pow2 56)) / pow2 56)) % pow2 56) in
let a4 = (x5 * y1 + x4 * y2 + x3 * y3 + x2 * y4 + x1 * y5 + ((x4 * y1 + x3 * y2 + x2 * y3 + x1 * y4 + ((x3 * y1 + x2 * y2 + x1 * y3 + ((x2 * y1 + x1 * y2 + ((x1 * y1) / pow2 56)) / pow2 56)) / pow2 56)) / pow2 56)) in
((x1 + pow2 56 * x2 + pow2 112 * x3 + pow2 168 * x4 + pow2 224 * x5)
* (y1 + pow2 56 * y2 + pow2 112 * y3 + pow2 168 * y4 + pow2 224 * y5)) % pow2 264
== a0 + pow2 56 * a1 + pow2 112 * a2 + pow2 168 * a3 + pow2 224 * (a4 % pow2 40)))
private let lemma_mul_nat_is_nat (a:nat) (b:nat) : Lemma (a*b >= 0) = ()
private let lemma_div_nat_is_nat (a:nat) (b:pos) : Lemma (a/b >= 0) = ()
private
val lemma_mul_5''':
x1:nat -> x2:nat -> x3:nat -> x4:nat -> x5:nat ->
y1:nat -> y2:nat -> y3:nat -> y4:nat -> y5:nat ->
Lemma (((x1 + pow2 56 * x2 + pow2 112 * x3 + pow2 168 * x4 + pow2 224 * x5)
* (y1 + pow2 56 * y2 + pow2 112 * y3 + pow2 168 * y4 + pow2 224 * y5)) % pow2 264
==
(x1 * y1
+ pow2 56 * (x2 * y1 + x1 * y2)
+ pow2 112 * (x3 * y1 + x2 * y2 + x1 * y3)
+ pow2 168 * (x4 * y1 + x3 * y2 + x2 * y3 + x1 * y4)
+ pow2 224 * (x5 * y1 + x4 * y2 + x3 * y3 + x2 * y4 + x1 * y5)) % pow2 264)
let lemma_mul_5''' x1 x2 x3 x4 x5 y1 y2 y3 y4 y5 =
calc (==) {
((x1 + pow2 56 * x2 + pow2 112 * x3 + pow2 168 * x4 + pow2 224 * x5)
* (y1 + pow2 56 * y2 + pow2 112 * y3 + pow2 168 * y4 + pow2 224 * y5)) % pow2 264;
(==) { _ by (Tactics.mapply (`feq #int #int (fun x -> x % pow2 264));
Tactics.norm [zeta; iota; delta; primops];
int_semiring ()) }
(x1 * y1
+ pow2 56 * (x2 * y1 + x1 * y2)
+ pow2 112 * (x3 * y1 + x2 * y2 + x1 * y3)
+ pow2 168 * (x4 * y1 + x3 * y2 + x2 * y3 + x1 * y4)
+ pow2 224 * (x5 * y1 + x4 * y2 + x3 * y3 + x2 * y4 + x1 * y5)
+ (pow2 16 * x2 * y5 +
pow2 16 * x3 * y4 + pow2 72 * x3 * y5 +
pow2 16 * x4 * y3 + pow2 72 * x4 * y4 + pow2 128 * x4 * y5 +
pow2 16 * x5 * y2 + pow2 72 * x5 * y3 + pow2 128 * x5 * y4 + pow2 184 * x5 * y5) * pow2 264) % pow2 264;
(==) { _ by (Tactics.mapply (`eq_eq2); Tactics.mapply (`Math.Lemmas.lemma_mod_plus)) }
(x1 * y1
+ pow2 56 * (x2 * y1 + x1 * y2)
+ pow2 112 * (x3 * y1 + x2 * y2 + x1 * y3)
+ pow2 168 * (x4 * y1 + x3 * y2 + x2 * y3 + x1 * y4)
+ pow2 224 * (x5 * y1 + x4 * y2 + x3 * y3 + x2 * y4 + x1 * y5)) % pow2 264;
}
private val lemma_mod_264'':
a0:nat -> a1:nat-> a2:nat -> a3:nat -> a4:nat ->
Lemma
(requires a0 < pow56 /\ a1 < pow56 /\ a2 < pow56 /\ a3 < pow56) | {
"checked_file": "/",
"dependencies": [
"Spec.Ed25519.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.BignumQ.Definitions.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Tactics.CanonCommSemiring.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.BignumQ.Lemmas.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.CanonCommSemiring",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.BignumQ.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.Ed25519",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.CanonCommSemiring",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.BignumQ",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.BignumQ",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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 | a0: Prims.nat -> a1: Prims.nat -> a2: Prims.nat -> a3: Prims.nat -> a4: Prims.nat
-> FStar.Pervasives.Lemma
(requires
a0 < Hacl.Spec.BignumQ.Definitions.pow56 /\ a1 < Hacl.Spec.BignumQ.Definitions.pow56 /\
a2 < Hacl.Spec.BignumQ.Definitions.pow56 /\ a3 < Hacl.Spec.BignumQ.Definitions.pow56)
(ensures
a0 + Prims.pow2 56 * a1 + Prims.pow2 112 * a2 + Prims.pow2 168 * a3 +
Prims.pow2 224 * (a4 % Prims.pow2 40) <
Prims.pow2 264) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.nat",
"FStar.Pervasives.assert_norm",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"Prims.pow2",
"Prims.unit"
] | [] | true | false | true | false | false | let lemma_mod_264'' a0 a1 a2 a3 a4 =
| assert_norm (pow2 40 = 0x10000000000);
assert_norm (pow2 56 = 0x100000000000000);
assert_norm (pow2 112 = 0x10000000000000000000000000000);
assert_norm (pow2 168 = 0x1000000000000000000000000000000000000000000);
assert_norm (pow2 224 = 0x100000000000000000000000000000000000000000000000000000000);
assert_norm (pow2 264 = 0x1000000000000000000000000000000000000000000000000000000000000000000) | false |
SfBasic.fst | SfBasic.plus_n_Sm | val plus_n_Sm : n : nat -> m : nat -> Lemma
(ensures (S (plus n m) = plus n (S m))) | val plus_n_Sm : n : nat -> m : nat -> Lemma
(ensures (S (plus n m) = plus n (S m))) | let rec plus_n_Sm n m =
match n with
| O -> ()
| S n' -> plus_n_Sm n' m | {
"file_name": "examples/software_foundations/SfBasic.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 26,
"end_line": 217,
"start_col": 0,
"start_line": 214
} | (*
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.
*)
(*
A translation to F* of Basics.v from Software Foundations
Original name: "Basics: Functional Programming in Coq"
*)
module SfBasic
type day =
| Monday
| Tuesday
| Wednesday
| Thursday
| Friday
| Saturday
| Sunday
val next_weekday : day -> Tot day
let next_weekday d =
match d with
| Monday -> Tuesday
| Tuesday -> Wednesday
| Wednesday -> Thursday
| Thursday -> Friday
| Friday -> Monday
| Saturday -> Monday
| Sunday -> Monday
val test_next_weekday : unit -> Lemma
(ensures ((next_weekday (next_weekday Saturday)) = Tuesday))
let test_next_weekday () = ()
(* Booleans *)
(* The original example calls these bool, True, and False,
and that doesn't seem to cause problems;
I've just renamed them to be 100% sure that's not the cause
of the troubles in this file *)
type mbool =
| MTrue
| MFalse
val negb : mbool -> Tot mbool
let negb b =
match b with
| MTrue -> MFalse
| MFalse -> MTrue
val andb : mbool -> mbool -> Tot mbool
let andb b1 b2 =
match b1 with
| MTrue -> b2
| MFalse -> MFalse
val orb : mbool -> mbool -> Tot mbool
let orb b1 b2 =
match b1 with
| MTrue -> MTrue
| MFalse -> b2
val test_orb1 : unit -> Lemma
(ensures ((orb MTrue MFalse) = MTrue))
let test_orb1 () = ()
val test_orb2 : unit -> Lemma
(ensures ((orb MFalse MFalse) = MFalse))
let test_orb2 () = ()
val test_orb3 : unit -> Lemma
(ensures ((orb MFalse MTrue) = MTrue))
let test_orb3 () = ()
val test_orb4 : unit -> Lemma
(ensures ((orb MTrue MTrue) = MTrue))
let test_orb4 () = ()
(* Numbers *)
type nat =
| O : nat
| S : nat -> nat
val pred : nat -> Tot nat
let pred n =
match n with
| O -> O
| S n' -> n'
val minustwo : nat -> Tot nat
let minustwo n =
match n with
| O -> O
| S O -> O
| S (S n') -> n'
val evenb : nat -> Tot mbool
let rec evenb n =
match n with
| O -> MTrue
| S O -> MFalse
| S (S n') -> evenb n'
val oddb : nat -> Tot mbool
let oddb n = negb (evenb n)
val test_oddb1 : unit -> Lemma
(ensures ((oddb (S O)) = MTrue))
let test_oddb1 () = ()
val test_oddb2 : unit -> Lemma
(ensures (oddb (S (S (S (S O)))) = MFalse))
let test_oddb2 () = ()
val plus : nat -> nat -> Tot nat
let rec plus n m =
match n with
| O -> m
| S n' -> S (plus n' m)
val mult : nat -> nat -> Tot nat
let rec mult n m =
match n with
| O -> O
| S n' -> plus m (mult n' m)
val test_mult1 : unit -> Lemma
(ensures (mult (S (S (S O))) (S (S (S O))))
= (S (S (S (S (S (S (S (S (S O))))))))))
let test_mult1 () = ()
val minus : nat -> nat -> Tot nat
let rec minus (n : nat) (m : nat) : nat =
match n, m with
| O , _ -> O
| S _ , O -> n
| S n', S m' -> minus n' m'
val beq_nat : nat -> nat -> Tot mbool
let rec beq_nat n m =
match n, m with
| O , O -> MTrue
| S n', S m' -> beq_nat n' m'
| _ , _ -> MFalse
val ble_nat : nat -> nat -> Tot mbool
let rec ble_nat n m =
match n, m with
| O , _ -> MTrue
| S n', O -> MFalse
| S n', S m' -> ble_nat n' m'
val test_ble_nat1 : unit -> Lemma
(ensures (ble_nat (S (S O)) (S (S O)) = MTrue))
let test_ble_nat1 () = ()
val test_ble_nat2 : unit -> Lemma
(ensures (ble_nat (S (S O)) (S (S (S (S O)))) = MTrue))
let test_ble_nat2 () = ()
val test_ble_nat3 : unit -> Lemma
(ensures (ble_nat (S (S (S (S O)))) (S (S O)) = MFalse))
let test_ble_nat3 () = ()
(* Proof by Simplification *)
val plus_O_n : n : nat -> Lemma
(ensures (plus O n = n))
let plus_O_n n = ()
(* Proof by Rewriting *)
val plus_id_example : n : nat -> m : nat -> Pure unit
(requires (n == m))
(ensures (fun r -> (plus n n = plus m m)))
let plus_id_example n m = ()
val mult_0_plus : n : nat -> m : nat -> Lemma
(ensures ((mult (plus O n) m) = mult n m))
let mult_0_plus n m = ()
(* Proof by Case Analysis *)
val plus_1_neq_0 : n : nat -> Lemma
(ensures (beq_nat (plus n (S O)) O = MFalse))
let plus_1_neq_0 n = ()
val negb_involutive : b : mbool -> Lemma
(ensures (negb (negb b) = b))
let negb_involutive b = ()
(* Proof by Induction (Induction.v) *)
val plus_0_r : n : nat -> Lemma
(ensures (plus n O = n))
let rec plus_0_r n =
match n with
| O -> ()
| S n' -> plus_0_r n'
val plus_n_Sm : n : nat -> m : nat -> Lemma | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "SfBasic.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | n: SfBasic.nat -> m: SfBasic.nat
-> FStar.Pervasives.Lemma (ensures SfBasic.S (SfBasic.plus n m) = SfBasic.plus n (SfBasic.S m)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"SfBasic.nat",
"SfBasic.plus_n_Sm",
"Prims.unit"
] | [
"recursion"
] | false | false | true | false | false | let rec plus_n_Sm n m =
| match n with
| O -> ()
| S n' -> plus_n_Sm n' m | false |
Hacl.Spec.BignumQ.Lemmas.fst | Hacl.Spec.BignumQ.Lemmas.lemma_div264_x6 | val lemma_div264_x6: x6:uint64 ->
Lemma (pow2 16 * (v x6 % pow2 40) * pow2 56 + v x6 / pow2 40 * pow2 112 == v x6 * pow2 72) | val lemma_div264_x6: x6:uint64 ->
Lemma (pow2 16 * (v x6 % pow2 40) * pow2 56 + v x6 / pow2 40 * pow2 112 == v x6 * pow2 72) | let lemma_div264_x6 x6 =
calc (==) {
pow2 16 * (v x6 % pow2 40) * pow2 56 + v x6 / pow2 40 * pow2 112;
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
((v x6 / pow2 40) * pow2 40 + v x6 % pow2 40) * pow2 72;
(==) { Math.Lemmas.euclidean_division_definition (v x6) (pow2 40) }
v x6 * pow2 72;
} | {
"file_name": "code/ed25519/Hacl.Spec.BignumQ.Lemmas.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 3,
"end_line": 381,
"start_col": 0,
"start_line": 374
} | module Hacl.Spec.BignumQ.Lemmas
open FStar.Tactics.CanonCommSemiring
open FStar.Mul
open Lib.IntTypes
module S = Spec.Ed25519
include Hacl.Spec.BignumQ.Definitions
let feq (#a #b:Type) (f:(a -> b)) (x y:a) :
Lemma (requires x == y) (ensures f x == f y) = ()
let eq_eq2 (#a:eqtype) (x y:a) :
Lemma (requires x = y) (ensures x == y) = ()
val lemma_mul_lt:a:nat -> b:nat -> c:nat -> d:nat ->
Lemma
(requires a < b /\ c < d)
(ensures a * c < b * d)
let lemma_mul_lt a b c d = ()
val lemma_as_nat5: f:qelem5 ->
Lemma
(requires qelem_fits5 f (1, 1, 1, 1, 1))
(ensures as_nat5 f < pow2 280)
let lemma_as_nat5 f =
//let (f0, f1, f2, f3, f4) = f in
//assert (as_nat5 f == v f0 + v f1 * pow56 + v f2 * pow112 + v f3 * pow168 + v f4 * pow224);
assert_norm (pow2 56 * pow2 56 = pow2 112);
assert_norm (pow2 56 * pow2 112 = pow2 168);
assert_norm (pow2 56 * pow2 168 = pow2 224);
assert_norm (pow2 56 * pow2 224 = pow2 280)
val lemma_choose_step:
bit:uint64{v bit <= 1}
-> x:uint64
-> y:uint64
-> Lemma
(let mask = bit -. u64 1 in
let z = x ^. (mask &. (x ^. y)) in
if v bit = 1 then z == x else z == y)
let lemma_choose_step bit p1 p2 =
let mask = bit -. u64 1 in
assert (v bit == 0 ==> v mask == pow2 64 - 1);
assert (v bit == 1 ==> v mask == 0);
let dummy = mask &. (p1 ^. p2) in
logand_lemma mask (p1 ^. p2);
assert (v bit == 1 ==> v dummy == 0);
assert (v bit == 0 ==> v dummy == v (p1 ^. p2));
let p1' = p1 ^. dummy in
assert (v dummy == v (if v bit = 1 then u64 0 else (p1 ^. p2)));
logxor_lemma p1 p2
val lemma_subm_conditional:
x0:nat -> x1:nat -> x2:nat -> x3:nat -> x4:nat
-> y0:nat -> y1:nat -> y2:nat -> y3:nat -> y4:nat
-> b0:nat -> b1:nat -> b2:nat -> b3:nat -> b4:nat ->
Lemma (
x0 - y0 + b0 * pow2 56 +
(x1 - y1 - b0 + b1 * pow2 56) * pow2 56 +
(x2 - y2 - b1 + b2 * pow2 56) * pow2 112 +
(x3 - y3 - b2 + b3 * pow2 56) * pow2 168 +
(x4 - y4 - b3 + b4 * pow2 56) * pow2 224 ==
(x0 + x1 * pow2 56 + x2 * pow2 112 + x3 * pow2 168 + x4 * pow2 224) -
(y0 + y1 * pow2 56 + y2 * pow2 112 + y3 * pow2 168 + y4 * pow2 224) + b4 * pow2 280)
let lemma_subm_conditional x0 x1 x2 x3 x4 y0 y1 y2 y3 y4 b0 b1 b2 b3 b4 =
assert_norm (pow2 56 * pow2 56 = pow2 112);
assert_norm (pow2 56 * pow2 112 = pow2 168);
assert_norm (pow2 56 * pow2 168 = pow2 224);
assert_norm (pow2 56 * pow2 224 = pow2 280);
assert (
x0 - y0 + b0 * pow2 56 +
(x1 - y1 - b0 + b1 * pow2 56) * pow2 56 +
(x2 - y2 - b1 + b2 * pow2 56) * pow2 112 +
(x3 - y3 - b2 + b3 * pow2 56) * pow2 168 +
(x4 - y4 - b3 + b4 * pow2 56) * pow2 224 ==
(x0 + x1 * pow2 56 + x2 * pow2 112 + x3 * pow2 168 + x4 * pow2 224) -
(y0 + y1 * pow2 56 + y2 * pow2 112 + y3 * pow2 168 + y4 * pow2 224) + b4 * pow2 280)
by (int_semiring ());
()
val lemma_div224: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1))
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
wide_as_nat5 x / pow2 224 ==
v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280))
#push-options "--z3rlimit 50"
let lemma_div224 x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert
(wide_as_nat5 x ==
v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168 + v x4 * pow2 224 +
v x5 * pow2 280 + v x6 * pow2 336 + v x7 * pow2 392 + v x8 * pow2 448 + v x9 * pow2 504);
assert_norm (pow2 56 * pow2 224 == pow2 280);
assert_norm (pow2 112 * pow2 224 == pow2 336);
assert_norm (pow2 168 * pow2 224 == pow2 392);
assert_norm (pow2 224 * pow2 224 == pow2 448);
assert_norm (pow2 280 * pow2 224 == pow2 504);
calc (==) {
wide_as_nat5 x / pow2 224;
(==) { }
(v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168 +
(v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280) * pow2 224) / pow2 224;
(==) {
FStar.Math.Lemmas.lemma_div_plus
(v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168)
(v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280) (pow2 224) }
(v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168) / pow2 224 +
v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280;
(==) { FStar.Math.Lemmas.small_division_lemma_1 (v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168) (pow2 224) }
v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280;
}
#pop-options
val lemma_div248_aux: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 512)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
wide_as_nat5 x / pow2 248 ==
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256))
open FStar.Tactics.CanonCommSemiring
#push-options "--z3cliopt smt.arith.nl=false"
let lemma_div248_aux x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert_norm (pow2 248 == pow2 224 * pow2 24);
assert_norm (pow2 56 == pow2 32 * pow2 24);
assert_norm (pow2 112 == pow2 88 * pow2 24);
assert_norm (pow2 168 == pow2 144 * pow2 24);
assert_norm (pow2 224 == pow2 200 * pow2 24);
assert_norm (pow2 280 == pow2 256 * pow2 24);
assert_norm (0 < pow2 24);
calc (==) {
wide_as_nat5 x / pow2 248;
(==) { FStar.Math.Lemmas.division_multiplication_lemma (wide_as_nat5 x) (pow2 224) (pow2 24) }
(wide_as_nat5 x / pow2 224) / pow2 24;
(==) { lemma_div224 x }
(v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280) / pow2 24;
(==) { _ by (Tactics.mapply (`feq #int #int (fun x -> x / pow2 24)); int_semiring ()) } (v x4 + (v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256) * pow2 24) / pow2 24;
(==) { FStar.Math.Lemmas.lemma_div_plus (v x4) (v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256) (pow2 24) }
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256;
}
#pop-options
val lemma_div248_x5: x5:uint64 ->
Lemma ( pow2 32 * (v x5 % pow2 24) + v x5 / pow2 24 * pow2 56 == v x5 * pow2 32)
let lemma_div248_x5 x5 =
assert_norm (pow2 32 * pow2 24 = pow2 56)
val lemma_div248_x6: x6:uint64 ->
Lemma (pow2 32 * (v x6 % pow2 24) * pow2 56 + v x6 / pow2 24 * pow2 112 == v x6 * pow2 88)
let lemma_div248_x6 x6 =
calc (==) {
pow2 32 * (v x6 % pow2 24) * pow2 56 + v x6 / pow2 24 * pow2 112;
(==) { _ by (Tactics.norm [delta_only [`%pow2]; primops]; int_semiring ()) }
((v x6 / pow2 24) * pow2 24 + v x6 % pow2 24) * pow2 88;
(==) { FStar.Math.Lemmas.euclidean_division_definition (v x6) (pow2 24) }
v x6 * pow2 88;
}
val lemma_div248_x7: x7:uint64 ->
Lemma (pow2 32 * (v x7 % pow2 24) * pow2 112 + v x7 / pow2 24 * pow2 168 == v x7 * pow2 144)
let lemma_div248_x7 x7 =
calc (==) {
pow2 32 * (v x7 % pow2 24) * pow2 112 + v x7 / pow2 24 * pow2 168;
(==) { _ by (Tactics.norm [delta_only [`%pow2]; primops]; int_semiring ()) }
((v x7 / pow2 24) * pow2 24 + v x7 % pow2 24) * pow2 144;
(==) { FStar.Math.Lemmas.euclidean_division_definition (v x7) (pow2 24) }
v x7 * pow2 144;
}
val lemma_div248_x8: x8:uint64 ->
Lemma (pow2 32 * (v x8 % pow2 24) * pow2 168 + v x8 / pow2 24 * pow2 224 == v x8 * pow2 200)
let lemma_div248_x8 x8 =
calc (==) {
pow2 32 * (v x8 % pow2 24) * pow2 168 + v x8 / pow2 24 * pow2 224;
(==) { _ by (Tactics.norm [delta_only [`%pow2]; primops]; int_semiring ()) }
((v x8 / pow2 24) * pow2 24 + v x8 % pow2 24) * pow2 200;
(==) { FStar.Math.Lemmas.euclidean_division_definition (v x8) (pow2 24) }
v x8 * pow2 200;
}
val lemma_div248_x9: x9:uint64{v x9 < pow2 24} ->
Lemma (pow2 32 * (v x9 % pow2 24) * pow2 224 == v x9 * pow2 256)
let lemma_div248_x9 x9 =
calc (==) {
pow2 32 * (v x9 % pow2 24) * pow2 224;
(==) { Math.Lemmas.small_mod (v x9) (pow2 24) }
pow2 32 * v x9 * pow2 224;
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
v x9 * pow2 256;
}
val lemma_wide_as_nat_pow512: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 512)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
v x9 < pow2 24))
let lemma_wide_as_nat_pow512 x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert_norm (pow2 504 * pow2 8 = pow2 512);
FStar.Math.Lemmas.pow2_minus 512 504;
assert (v x9 < pow2 8);
assert_norm (pow2 8 < pow2 24)
val lemma_div248: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 512)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
let z0 = v x4 / pow2 24 + pow2 32 * (v x5 % pow2 24) in
let z1 = v x5 / pow2 24 + pow2 32 * (v x6 % pow2 24) in
let z2 = v x6 / pow2 24 + pow2 32 * (v x7 % pow2 24) in
let z3 = v x7 / pow2 24 + pow2 32 * (v x8 % pow2 24) in
let z4 = v x8 / pow2 24 + pow2 32 * (v x9 % pow2 24) in
wide_as_nat5 x / pow2 248 == z0 + z1 * pow2 56 + z2 * pow2 112 + z3 * pow2 168 + z4 * pow2 224))
#push-options "--z3rlimit 50"
let lemma_div248 x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
lemma_wide_as_nat_pow512 x;
assert (v x9 < pow2 24);
calc (==) {
(let z0 = v x4 / pow2 24 + pow2 32 * (v x5 % pow2 24) in
let z1 = v x5 / pow2 24 + pow2 32 * (v x6 % pow2 24) in
let z2 = v x6 / pow2 24 + pow2 32 * (v x7 % pow2 24) in
let z3 = v x7 / pow2 24 + pow2 32 * (v x8 % pow2 24) in
let z4 = v x8 / pow2 24 + pow2 32 * (v x9 % pow2 24) in
z0 + z1 * pow2 56 + z2 * pow2 112 + z3 * pow2 168 + z4 * pow2 224);
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
v x4 / pow2 24 + pow2 32 * (v x5 % pow2 24) +
v x5 / pow2 24 * pow2 56 + pow2 32 * (v x6 % pow2 24) * pow2 56 +
v x6 / pow2 24 * pow2 112 + pow2 32 * (v x7 % pow2 24) * pow2 112 +
v x7 / pow2 24 * pow2 168 + pow2 32 * (v x8 % pow2 24) * pow2 168 +
v x8 / pow2 24 * pow2 224 + pow2 32 * (v x9 % pow2 24) * pow2 224;
(==) { lemma_div248_x5 x5; lemma_div248_x6 x6 }
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 +
pow2 32 * (v x7 % pow2 24) * pow2 112 +
v x7 / pow2 24 * pow2 168 + pow2 32 * (v x8 % pow2 24) * pow2 168 +
v x8 / pow2 24 * pow2 224 + pow2 32 * (v x9 % pow2 24) * pow2 224;
(==) { lemma_div248_x7 x7; lemma_div248_x8 x8 }
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 +
pow2 32 * (v x9 % pow2 24) * pow2 224;
(==) { lemma_div248_x9 x9 }
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256;
(==) { lemma_div248_aux x }
wide_as_nat5 x / pow2 248;
}
#pop-options
val lemma_add_modq5:
x:qelem5
-> y:qelem5
-> t:qelem5 ->
Lemma
(requires
qelem_fits5 x (1, 1, 1, 1, 1) /\
qelem_fits5 y (1, 1, 1, 1, 1) /\
qelem_fits5 t (1, 1, 1, 1, 1) /\
as_nat5 x < S.q /\ as_nat5 y < S.q /\
as_nat5 t == as_nat5 x + as_nat5 y)
(ensures
(let res = if as_nat5 t >= S.q then as_nat5 t - S.q else as_nat5 t in
res < S.q /\ res == (as_nat5 x + as_nat5 y) % S.q))
let lemma_add_modq5 x y t =
assert (as_nat5 t == as_nat5 x + as_nat5 y);
let res = if as_nat5 t >= S.q then as_nat5 t - S.q else as_nat5 t in
assert (res < S.q);
if as_nat5 t >= S.q then (
FStar.Math.Lemmas.sub_div_mod_1 (as_nat5 t) S.q;
assert (res % S.q == as_nat5 t % S.q))
else
assert (res % S.q == as_nat5 t % S.q);
FStar.Math.Lemmas.small_mod res S.q
val lemma_wide_as_nat_pow528: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 528)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
v x9 < pow2 40))
let lemma_wide_as_nat_pow528 x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert_norm (pow2 504 * pow2 24 = pow2 528);
FStar.Math.Lemmas.pow2_minus 528 504;
assert (v x9 < pow2 24);
assert_norm (pow2 24 < pow2 40)
#push-options "--z3cliopt smt.arith.nl=false"
val lemma_div264_aux: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 528)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
wide_as_nat5 x / pow2 264 ==
v x4 / pow2 40 + v x5 * pow2 16 + v x6 * pow2 72 + v x7 * pow2 128 + v x8 * pow2 184 + v x9 * pow2 240))
let lemma_div264_aux x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert_norm (pow2 264 == pow2 224 * pow2 40);
assert_norm (pow2 56 == pow2 16 * pow2 40);
assert_norm (pow2 112 == pow2 72 * pow2 40);
assert_norm (pow2 168 == pow2 128 * pow2 40);
assert_norm (pow2 224 == pow2 184 * pow2 40);
assert_norm (pow2 280 == pow2 240 * pow2 40);
assert_norm (0 < pow2 40);
calc (==) {
wide_as_nat5 x / pow2 264;
(==) { FStar.Math.Lemmas.division_multiplication_lemma (wide_as_nat5 x) (pow2 224) (pow2 40) }
(wide_as_nat5 x / pow2 224) / pow2 40;
(==) { lemma_div224 x }
(v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280) / pow2 40;
(==) { _ by (Tactics.mapply (`feq #int #int (fun x -> x / pow2 40)); int_semiring ()) }
(v x4 + (v x5 * pow2 16 + v x6 * pow2 72 + v x7 * pow2 128 + v x8 * pow2 184 + v x9 * pow2 240) * pow2 40) / pow2 40;
(==) { FStar.Math.Lemmas.lemma_div_plus (v x4) (v x5 * pow2 16 + v x6 * pow2 72 + v x7 * pow2 128 + v x8 * pow2 184 + v x9 * pow2 240) (pow2 40) }
v x4 / pow2 40 + v x5 * pow2 16 + v x6 * pow2 72 + v x7 * pow2 128 + v x8 * pow2 184 + v x9 * pow2 240;
}
val lemma_div264_x5: x5:uint64 ->
Lemma (pow2 16 * (v x5 % pow2 40) + v x5 / pow2 40 * pow2 56 == v x5 * pow2 16)
let lemma_div264_x5 x5 =
assert_norm (0 < pow2 24);
calc (==) {
pow2 16 * (v x5 % pow2 40) + v x5 / pow2 40 * pow2 56;
(==) { _ by (Tactics.norm [delta_only [`%pow2]; primops]; int_semiring ()) }
((v x5 / pow2 40) * pow2 40 + v x5 % pow2 40) * pow2 16;
(==) { FStar.Math.Lemmas.euclidean_division_definition (v x5) (pow2 40) }
v x5 * pow2 16;
}
val lemma_div264_x6: x6:uint64 -> | {
"checked_file": "/",
"dependencies": [
"Spec.Ed25519.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.BignumQ.Definitions.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Tactics.CanonCommSemiring.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.BignumQ.Lemmas.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.CanonCommSemiring",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.BignumQ.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.Ed25519",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.CanonCommSemiring",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.BignumQ",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.BignumQ",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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": [
"smt.arith.nl=false"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x6: Lib.IntTypes.uint64
-> FStar.Pervasives.Lemma
(ensures
(Prims.pow2 16 * (Lib.IntTypes.v x6 % Prims.pow2 40)) * Prims.pow2 56 +
(Lib.IntTypes.v x6 / Prims.pow2 40) * Prims.pow2 112 ==
Lib.IntTypes.v x6 * Prims.pow2 72) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Lib.IntTypes.uint64",
"FStar.Calc.calc_finish",
"Prims.int",
"Prims.eq2",
"Prims.op_Addition",
"FStar.Mul.op_Star",
"Prims.pow2",
"Prims.op_Modulus",
"Lib.IntTypes.v",
"Lib.IntTypes.U64",
"Lib.IntTypes.SEC",
"Prims.op_Division",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"Prims.unit",
"FStar.Calc.calc_step",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"FStar.Tactics.CanonCommSemiring.semiring_reflect",
"FStar.Tactics.CanonCommSemiring.int_cr",
"FStar.Pervasives.Native.Mktuple2",
"Prims.list",
"FStar.Pervasives.Native.tuple2",
"Prims.nat",
"FStar.Pervasives.Native.snd",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"Lib.IntTypes.sec_int_v",
"FStar.Stubs.Reflection.V2.Data.var",
"FStar.Tactics.CanonCommSemiring.Pplus",
"FStar.Tactics.CanonCommSemiring.Pmult",
"FStar.Tactics.CanonCommSemiring.Pvar",
"Prims.op_Multiply",
"Prims.l_and",
"Prims.bool",
"Prims.op_LessThanOrEqual",
"Prims.op_Subtraction",
"Lib.IntTypes.bits",
"Prims.squash",
"FStar.Math.Lemmas.euclidean_division_definition"
] | [] | false | false | true | false | false | let lemma_div264_x6 x6 =
| calc ( == ) {
(pow2 16 * (v x6 % pow2 40)) * pow2 56 + (v x6 / pow2 40) * pow2 112;
( == ) { FStar.Tactics.Effect.synth_by_tactic (fun _ ->
(Tactics.norm [delta; primops];
int_semiring ())) }
((v x6 / pow2 40) * pow2 40 + v x6 % pow2 40) * pow2 72;
( == ) { Math.Lemmas.euclidean_division_definition (v x6) (pow2 40) }
v x6 * pow2 72;
} | false |
Hacl.Spec.BignumQ.Lemmas.fst | Hacl.Spec.BignumQ.Lemmas.lemma_div264_x7 | val lemma_div264_x7: x7:uint64 ->
Lemma (pow2 16 * (v x7 % pow2 40) * pow2 112 + v x7 / pow2 40 * pow2 168 == v x7 * pow2 128) | val lemma_div264_x7: x7:uint64 ->
Lemma (pow2 16 * (v x7 % pow2 40) * pow2 112 + v x7 / pow2 40 * pow2 168 == v x7 * pow2 128) | let lemma_div264_x7 x7 =
calc (==) {
pow2 16 * (v x7 % pow2 40) * pow2 112 + v x7 / pow2 40 * pow2 168;
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
((v x7 / pow2 40) * pow2 40 + v x7 % pow2 40) * pow2 128;
(==) { Math.Lemmas.euclidean_division_definition (v x7) (pow2 40) }
v x7 * pow2 128;
} | {
"file_name": "code/ed25519/Hacl.Spec.BignumQ.Lemmas.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 3,
"end_line": 393,
"start_col": 0,
"start_line": 386
} | module Hacl.Spec.BignumQ.Lemmas
open FStar.Tactics.CanonCommSemiring
open FStar.Mul
open Lib.IntTypes
module S = Spec.Ed25519
include Hacl.Spec.BignumQ.Definitions
let feq (#a #b:Type) (f:(a -> b)) (x y:a) :
Lemma (requires x == y) (ensures f x == f y) = ()
let eq_eq2 (#a:eqtype) (x y:a) :
Lemma (requires x = y) (ensures x == y) = ()
val lemma_mul_lt:a:nat -> b:nat -> c:nat -> d:nat ->
Lemma
(requires a < b /\ c < d)
(ensures a * c < b * d)
let lemma_mul_lt a b c d = ()
val lemma_as_nat5: f:qelem5 ->
Lemma
(requires qelem_fits5 f (1, 1, 1, 1, 1))
(ensures as_nat5 f < pow2 280)
let lemma_as_nat5 f =
//let (f0, f1, f2, f3, f4) = f in
//assert (as_nat5 f == v f0 + v f1 * pow56 + v f2 * pow112 + v f3 * pow168 + v f4 * pow224);
assert_norm (pow2 56 * pow2 56 = pow2 112);
assert_norm (pow2 56 * pow2 112 = pow2 168);
assert_norm (pow2 56 * pow2 168 = pow2 224);
assert_norm (pow2 56 * pow2 224 = pow2 280)
val lemma_choose_step:
bit:uint64{v bit <= 1}
-> x:uint64
-> y:uint64
-> Lemma
(let mask = bit -. u64 1 in
let z = x ^. (mask &. (x ^. y)) in
if v bit = 1 then z == x else z == y)
let lemma_choose_step bit p1 p2 =
let mask = bit -. u64 1 in
assert (v bit == 0 ==> v mask == pow2 64 - 1);
assert (v bit == 1 ==> v mask == 0);
let dummy = mask &. (p1 ^. p2) in
logand_lemma mask (p1 ^. p2);
assert (v bit == 1 ==> v dummy == 0);
assert (v bit == 0 ==> v dummy == v (p1 ^. p2));
let p1' = p1 ^. dummy in
assert (v dummy == v (if v bit = 1 then u64 0 else (p1 ^. p2)));
logxor_lemma p1 p2
val lemma_subm_conditional:
x0:nat -> x1:nat -> x2:nat -> x3:nat -> x4:nat
-> y0:nat -> y1:nat -> y2:nat -> y3:nat -> y4:nat
-> b0:nat -> b1:nat -> b2:nat -> b3:nat -> b4:nat ->
Lemma (
x0 - y0 + b0 * pow2 56 +
(x1 - y1 - b0 + b1 * pow2 56) * pow2 56 +
(x2 - y2 - b1 + b2 * pow2 56) * pow2 112 +
(x3 - y3 - b2 + b3 * pow2 56) * pow2 168 +
(x4 - y4 - b3 + b4 * pow2 56) * pow2 224 ==
(x0 + x1 * pow2 56 + x2 * pow2 112 + x3 * pow2 168 + x4 * pow2 224) -
(y0 + y1 * pow2 56 + y2 * pow2 112 + y3 * pow2 168 + y4 * pow2 224) + b4 * pow2 280)
let lemma_subm_conditional x0 x1 x2 x3 x4 y0 y1 y2 y3 y4 b0 b1 b2 b3 b4 =
assert_norm (pow2 56 * pow2 56 = pow2 112);
assert_norm (pow2 56 * pow2 112 = pow2 168);
assert_norm (pow2 56 * pow2 168 = pow2 224);
assert_norm (pow2 56 * pow2 224 = pow2 280);
assert (
x0 - y0 + b0 * pow2 56 +
(x1 - y1 - b0 + b1 * pow2 56) * pow2 56 +
(x2 - y2 - b1 + b2 * pow2 56) * pow2 112 +
(x3 - y3 - b2 + b3 * pow2 56) * pow2 168 +
(x4 - y4 - b3 + b4 * pow2 56) * pow2 224 ==
(x0 + x1 * pow2 56 + x2 * pow2 112 + x3 * pow2 168 + x4 * pow2 224) -
(y0 + y1 * pow2 56 + y2 * pow2 112 + y3 * pow2 168 + y4 * pow2 224) + b4 * pow2 280)
by (int_semiring ());
()
val lemma_div224: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1))
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
wide_as_nat5 x / pow2 224 ==
v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280))
#push-options "--z3rlimit 50"
let lemma_div224 x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert
(wide_as_nat5 x ==
v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168 + v x4 * pow2 224 +
v x5 * pow2 280 + v x6 * pow2 336 + v x7 * pow2 392 + v x8 * pow2 448 + v x9 * pow2 504);
assert_norm (pow2 56 * pow2 224 == pow2 280);
assert_norm (pow2 112 * pow2 224 == pow2 336);
assert_norm (pow2 168 * pow2 224 == pow2 392);
assert_norm (pow2 224 * pow2 224 == pow2 448);
assert_norm (pow2 280 * pow2 224 == pow2 504);
calc (==) {
wide_as_nat5 x / pow2 224;
(==) { }
(v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168 +
(v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280) * pow2 224) / pow2 224;
(==) {
FStar.Math.Lemmas.lemma_div_plus
(v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168)
(v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280) (pow2 224) }
(v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168) / pow2 224 +
v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280;
(==) { FStar.Math.Lemmas.small_division_lemma_1 (v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168) (pow2 224) }
v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280;
}
#pop-options
val lemma_div248_aux: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 512)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
wide_as_nat5 x / pow2 248 ==
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256))
open FStar.Tactics.CanonCommSemiring
#push-options "--z3cliopt smt.arith.nl=false"
let lemma_div248_aux x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert_norm (pow2 248 == pow2 224 * pow2 24);
assert_norm (pow2 56 == pow2 32 * pow2 24);
assert_norm (pow2 112 == pow2 88 * pow2 24);
assert_norm (pow2 168 == pow2 144 * pow2 24);
assert_norm (pow2 224 == pow2 200 * pow2 24);
assert_norm (pow2 280 == pow2 256 * pow2 24);
assert_norm (0 < pow2 24);
calc (==) {
wide_as_nat5 x / pow2 248;
(==) { FStar.Math.Lemmas.division_multiplication_lemma (wide_as_nat5 x) (pow2 224) (pow2 24) }
(wide_as_nat5 x / pow2 224) / pow2 24;
(==) { lemma_div224 x }
(v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280) / pow2 24;
(==) { _ by (Tactics.mapply (`feq #int #int (fun x -> x / pow2 24)); int_semiring ()) } (v x4 + (v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256) * pow2 24) / pow2 24;
(==) { FStar.Math.Lemmas.lemma_div_plus (v x4) (v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256) (pow2 24) }
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256;
}
#pop-options
val lemma_div248_x5: x5:uint64 ->
Lemma ( pow2 32 * (v x5 % pow2 24) + v x5 / pow2 24 * pow2 56 == v x5 * pow2 32)
let lemma_div248_x5 x5 =
assert_norm (pow2 32 * pow2 24 = pow2 56)
val lemma_div248_x6: x6:uint64 ->
Lemma (pow2 32 * (v x6 % pow2 24) * pow2 56 + v x6 / pow2 24 * pow2 112 == v x6 * pow2 88)
let lemma_div248_x6 x6 =
calc (==) {
pow2 32 * (v x6 % pow2 24) * pow2 56 + v x6 / pow2 24 * pow2 112;
(==) { _ by (Tactics.norm [delta_only [`%pow2]; primops]; int_semiring ()) }
((v x6 / pow2 24) * pow2 24 + v x6 % pow2 24) * pow2 88;
(==) { FStar.Math.Lemmas.euclidean_division_definition (v x6) (pow2 24) }
v x6 * pow2 88;
}
val lemma_div248_x7: x7:uint64 ->
Lemma (pow2 32 * (v x7 % pow2 24) * pow2 112 + v x7 / pow2 24 * pow2 168 == v x7 * pow2 144)
let lemma_div248_x7 x7 =
calc (==) {
pow2 32 * (v x7 % pow2 24) * pow2 112 + v x7 / pow2 24 * pow2 168;
(==) { _ by (Tactics.norm [delta_only [`%pow2]; primops]; int_semiring ()) }
((v x7 / pow2 24) * pow2 24 + v x7 % pow2 24) * pow2 144;
(==) { FStar.Math.Lemmas.euclidean_division_definition (v x7) (pow2 24) }
v x7 * pow2 144;
}
val lemma_div248_x8: x8:uint64 ->
Lemma (pow2 32 * (v x8 % pow2 24) * pow2 168 + v x8 / pow2 24 * pow2 224 == v x8 * pow2 200)
let lemma_div248_x8 x8 =
calc (==) {
pow2 32 * (v x8 % pow2 24) * pow2 168 + v x8 / pow2 24 * pow2 224;
(==) { _ by (Tactics.norm [delta_only [`%pow2]; primops]; int_semiring ()) }
((v x8 / pow2 24) * pow2 24 + v x8 % pow2 24) * pow2 200;
(==) { FStar.Math.Lemmas.euclidean_division_definition (v x8) (pow2 24) }
v x8 * pow2 200;
}
val lemma_div248_x9: x9:uint64{v x9 < pow2 24} ->
Lemma (pow2 32 * (v x9 % pow2 24) * pow2 224 == v x9 * pow2 256)
let lemma_div248_x9 x9 =
calc (==) {
pow2 32 * (v x9 % pow2 24) * pow2 224;
(==) { Math.Lemmas.small_mod (v x9) (pow2 24) }
pow2 32 * v x9 * pow2 224;
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
v x9 * pow2 256;
}
val lemma_wide_as_nat_pow512: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 512)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
v x9 < pow2 24))
let lemma_wide_as_nat_pow512 x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert_norm (pow2 504 * pow2 8 = pow2 512);
FStar.Math.Lemmas.pow2_minus 512 504;
assert (v x9 < pow2 8);
assert_norm (pow2 8 < pow2 24)
val lemma_div248: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 512)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
let z0 = v x4 / pow2 24 + pow2 32 * (v x5 % pow2 24) in
let z1 = v x5 / pow2 24 + pow2 32 * (v x6 % pow2 24) in
let z2 = v x6 / pow2 24 + pow2 32 * (v x7 % pow2 24) in
let z3 = v x7 / pow2 24 + pow2 32 * (v x8 % pow2 24) in
let z4 = v x8 / pow2 24 + pow2 32 * (v x9 % pow2 24) in
wide_as_nat5 x / pow2 248 == z0 + z1 * pow2 56 + z2 * pow2 112 + z3 * pow2 168 + z4 * pow2 224))
#push-options "--z3rlimit 50"
let lemma_div248 x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
lemma_wide_as_nat_pow512 x;
assert (v x9 < pow2 24);
calc (==) {
(let z0 = v x4 / pow2 24 + pow2 32 * (v x5 % pow2 24) in
let z1 = v x5 / pow2 24 + pow2 32 * (v x6 % pow2 24) in
let z2 = v x6 / pow2 24 + pow2 32 * (v x7 % pow2 24) in
let z3 = v x7 / pow2 24 + pow2 32 * (v x8 % pow2 24) in
let z4 = v x8 / pow2 24 + pow2 32 * (v x9 % pow2 24) in
z0 + z1 * pow2 56 + z2 * pow2 112 + z3 * pow2 168 + z4 * pow2 224);
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
v x4 / pow2 24 + pow2 32 * (v x5 % pow2 24) +
v x5 / pow2 24 * pow2 56 + pow2 32 * (v x6 % pow2 24) * pow2 56 +
v x6 / pow2 24 * pow2 112 + pow2 32 * (v x7 % pow2 24) * pow2 112 +
v x7 / pow2 24 * pow2 168 + pow2 32 * (v x8 % pow2 24) * pow2 168 +
v x8 / pow2 24 * pow2 224 + pow2 32 * (v x9 % pow2 24) * pow2 224;
(==) { lemma_div248_x5 x5; lemma_div248_x6 x6 }
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 +
pow2 32 * (v x7 % pow2 24) * pow2 112 +
v x7 / pow2 24 * pow2 168 + pow2 32 * (v x8 % pow2 24) * pow2 168 +
v x8 / pow2 24 * pow2 224 + pow2 32 * (v x9 % pow2 24) * pow2 224;
(==) { lemma_div248_x7 x7; lemma_div248_x8 x8 }
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 +
pow2 32 * (v x9 % pow2 24) * pow2 224;
(==) { lemma_div248_x9 x9 }
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256;
(==) { lemma_div248_aux x }
wide_as_nat5 x / pow2 248;
}
#pop-options
val lemma_add_modq5:
x:qelem5
-> y:qelem5
-> t:qelem5 ->
Lemma
(requires
qelem_fits5 x (1, 1, 1, 1, 1) /\
qelem_fits5 y (1, 1, 1, 1, 1) /\
qelem_fits5 t (1, 1, 1, 1, 1) /\
as_nat5 x < S.q /\ as_nat5 y < S.q /\
as_nat5 t == as_nat5 x + as_nat5 y)
(ensures
(let res = if as_nat5 t >= S.q then as_nat5 t - S.q else as_nat5 t in
res < S.q /\ res == (as_nat5 x + as_nat5 y) % S.q))
let lemma_add_modq5 x y t =
assert (as_nat5 t == as_nat5 x + as_nat5 y);
let res = if as_nat5 t >= S.q then as_nat5 t - S.q else as_nat5 t in
assert (res < S.q);
if as_nat5 t >= S.q then (
FStar.Math.Lemmas.sub_div_mod_1 (as_nat5 t) S.q;
assert (res % S.q == as_nat5 t % S.q))
else
assert (res % S.q == as_nat5 t % S.q);
FStar.Math.Lemmas.small_mod res S.q
val lemma_wide_as_nat_pow528: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 528)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
v x9 < pow2 40))
let lemma_wide_as_nat_pow528 x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert_norm (pow2 504 * pow2 24 = pow2 528);
FStar.Math.Lemmas.pow2_minus 528 504;
assert (v x9 < pow2 24);
assert_norm (pow2 24 < pow2 40)
#push-options "--z3cliopt smt.arith.nl=false"
val lemma_div264_aux: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 528)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
wide_as_nat5 x / pow2 264 ==
v x4 / pow2 40 + v x5 * pow2 16 + v x6 * pow2 72 + v x7 * pow2 128 + v x8 * pow2 184 + v x9 * pow2 240))
let lemma_div264_aux x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert_norm (pow2 264 == pow2 224 * pow2 40);
assert_norm (pow2 56 == pow2 16 * pow2 40);
assert_norm (pow2 112 == pow2 72 * pow2 40);
assert_norm (pow2 168 == pow2 128 * pow2 40);
assert_norm (pow2 224 == pow2 184 * pow2 40);
assert_norm (pow2 280 == pow2 240 * pow2 40);
assert_norm (0 < pow2 40);
calc (==) {
wide_as_nat5 x / pow2 264;
(==) { FStar.Math.Lemmas.division_multiplication_lemma (wide_as_nat5 x) (pow2 224) (pow2 40) }
(wide_as_nat5 x / pow2 224) / pow2 40;
(==) { lemma_div224 x }
(v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280) / pow2 40;
(==) { _ by (Tactics.mapply (`feq #int #int (fun x -> x / pow2 40)); int_semiring ()) }
(v x4 + (v x5 * pow2 16 + v x6 * pow2 72 + v x7 * pow2 128 + v x8 * pow2 184 + v x9 * pow2 240) * pow2 40) / pow2 40;
(==) { FStar.Math.Lemmas.lemma_div_plus (v x4) (v x5 * pow2 16 + v x6 * pow2 72 + v x7 * pow2 128 + v x8 * pow2 184 + v x9 * pow2 240) (pow2 40) }
v x4 / pow2 40 + v x5 * pow2 16 + v x6 * pow2 72 + v x7 * pow2 128 + v x8 * pow2 184 + v x9 * pow2 240;
}
val lemma_div264_x5: x5:uint64 ->
Lemma (pow2 16 * (v x5 % pow2 40) + v x5 / pow2 40 * pow2 56 == v x5 * pow2 16)
let lemma_div264_x5 x5 =
assert_norm (0 < pow2 24);
calc (==) {
pow2 16 * (v x5 % pow2 40) + v x5 / pow2 40 * pow2 56;
(==) { _ by (Tactics.norm [delta_only [`%pow2]; primops]; int_semiring ()) }
((v x5 / pow2 40) * pow2 40 + v x5 % pow2 40) * pow2 16;
(==) { FStar.Math.Lemmas.euclidean_division_definition (v x5) (pow2 40) }
v x5 * pow2 16;
}
val lemma_div264_x6: x6:uint64 ->
Lemma (pow2 16 * (v x6 % pow2 40) * pow2 56 + v x6 / pow2 40 * pow2 112 == v x6 * pow2 72)
let lemma_div264_x6 x6 =
calc (==) {
pow2 16 * (v x6 % pow2 40) * pow2 56 + v x6 / pow2 40 * pow2 112;
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
((v x6 / pow2 40) * pow2 40 + v x6 % pow2 40) * pow2 72;
(==) { Math.Lemmas.euclidean_division_definition (v x6) (pow2 40) }
v x6 * pow2 72;
}
val lemma_div264_x7: x7:uint64 -> | {
"checked_file": "/",
"dependencies": [
"Spec.Ed25519.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.BignumQ.Definitions.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Tactics.CanonCommSemiring.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.BignumQ.Lemmas.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.CanonCommSemiring",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.BignumQ.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.Ed25519",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.CanonCommSemiring",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.BignumQ",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.BignumQ",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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": [
"smt.arith.nl=false"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x7: Lib.IntTypes.uint64
-> FStar.Pervasives.Lemma
(ensures
(Prims.pow2 16 * (Lib.IntTypes.v x7 % Prims.pow2 40)) * Prims.pow2 112 +
(Lib.IntTypes.v x7 / Prims.pow2 40) * Prims.pow2 168 ==
Lib.IntTypes.v x7 * Prims.pow2 128) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Lib.IntTypes.uint64",
"FStar.Calc.calc_finish",
"Prims.int",
"Prims.eq2",
"Prims.op_Addition",
"FStar.Mul.op_Star",
"Prims.pow2",
"Prims.op_Modulus",
"Lib.IntTypes.v",
"Lib.IntTypes.U64",
"Lib.IntTypes.SEC",
"Prims.op_Division",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"Prims.unit",
"FStar.Calc.calc_step",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"FStar.Tactics.CanonCommSemiring.semiring_reflect",
"FStar.Tactics.CanonCommSemiring.int_cr",
"FStar.Pervasives.Native.Mktuple2",
"Prims.list",
"FStar.Pervasives.Native.tuple2",
"Prims.nat",
"FStar.Pervasives.Native.snd",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"Lib.IntTypes.sec_int_v",
"FStar.Stubs.Reflection.V2.Data.var",
"FStar.Tactics.CanonCommSemiring.Pplus",
"FStar.Tactics.CanonCommSemiring.Pmult",
"FStar.Tactics.CanonCommSemiring.Pvar",
"Prims.op_Multiply",
"Prims.l_and",
"Prims.bool",
"Prims.op_LessThanOrEqual",
"Prims.op_Subtraction",
"Lib.IntTypes.bits",
"Prims.squash",
"FStar.Math.Lemmas.euclidean_division_definition"
] | [] | false | false | true | false | false | let lemma_div264_x7 x7 =
| calc ( == ) {
(pow2 16 * (v x7 % pow2 40)) * pow2 112 + (v x7 / pow2 40) * pow2 168;
( == ) { FStar.Tactics.Effect.synth_by_tactic (fun _ ->
(Tactics.norm [delta; primops];
int_semiring ())) }
((v x7 / pow2 40) * pow2 40 + v x7 % pow2 40) * pow2 128;
( == ) { Math.Lemmas.euclidean_division_definition (v x7) (pow2 40) }
v x7 * pow2 128;
} | false |
Hacl.Spec.BignumQ.Lemmas.fst | Hacl.Spec.BignumQ.Lemmas.lemma_div264_x9 | val lemma_div264_x9: x9:uint64{v x9 < pow2 40} ->
Lemma (pow2 16 * (v x9 % pow2 40) * pow2 224 == v x9 * pow2 240) | val lemma_div264_x9: x9:uint64{v x9 < pow2 40} ->
Lemma (pow2 16 * (v x9 % pow2 40) * pow2 224 == v x9 * pow2 240) | let lemma_div264_x9 x9 =
calc (==) {
pow2 16 * (v x9 % pow2 40) * pow2 224;
(==) { Math.Lemmas.small_mod (v x9) (pow2 40) }
pow2 16 * v x9 * pow2 224;
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
v x9 * pow2 240;
} | {
"file_name": "code/ed25519/Hacl.Spec.BignumQ.Lemmas.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 3,
"end_line": 416,
"start_col": 0,
"start_line": 409
} | module Hacl.Spec.BignumQ.Lemmas
open FStar.Tactics.CanonCommSemiring
open FStar.Mul
open Lib.IntTypes
module S = Spec.Ed25519
include Hacl.Spec.BignumQ.Definitions
let feq (#a #b:Type) (f:(a -> b)) (x y:a) :
Lemma (requires x == y) (ensures f x == f y) = ()
let eq_eq2 (#a:eqtype) (x y:a) :
Lemma (requires x = y) (ensures x == y) = ()
val lemma_mul_lt:a:nat -> b:nat -> c:nat -> d:nat ->
Lemma
(requires a < b /\ c < d)
(ensures a * c < b * d)
let lemma_mul_lt a b c d = ()
val lemma_as_nat5: f:qelem5 ->
Lemma
(requires qelem_fits5 f (1, 1, 1, 1, 1))
(ensures as_nat5 f < pow2 280)
let lemma_as_nat5 f =
//let (f0, f1, f2, f3, f4) = f in
//assert (as_nat5 f == v f0 + v f1 * pow56 + v f2 * pow112 + v f3 * pow168 + v f4 * pow224);
assert_norm (pow2 56 * pow2 56 = pow2 112);
assert_norm (pow2 56 * pow2 112 = pow2 168);
assert_norm (pow2 56 * pow2 168 = pow2 224);
assert_norm (pow2 56 * pow2 224 = pow2 280)
val lemma_choose_step:
bit:uint64{v bit <= 1}
-> x:uint64
-> y:uint64
-> Lemma
(let mask = bit -. u64 1 in
let z = x ^. (mask &. (x ^. y)) in
if v bit = 1 then z == x else z == y)
let lemma_choose_step bit p1 p2 =
let mask = bit -. u64 1 in
assert (v bit == 0 ==> v mask == pow2 64 - 1);
assert (v bit == 1 ==> v mask == 0);
let dummy = mask &. (p1 ^. p2) in
logand_lemma mask (p1 ^. p2);
assert (v bit == 1 ==> v dummy == 0);
assert (v bit == 0 ==> v dummy == v (p1 ^. p2));
let p1' = p1 ^. dummy in
assert (v dummy == v (if v bit = 1 then u64 0 else (p1 ^. p2)));
logxor_lemma p1 p2
val lemma_subm_conditional:
x0:nat -> x1:nat -> x2:nat -> x3:nat -> x4:nat
-> y0:nat -> y1:nat -> y2:nat -> y3:nat -> y4:nat
-> b0:nat -> b1:nat -> b2:nat -> b3:nat -> b4:nat ->
Lemma (
x0 - y0 + b0 * pow2 56 +
(x1 - y1 - b0 + b1 * pow2 56) * pow2 56 +
(x2 - y2 - b1 + b2 * pow2 56) * pow2 112 +
(x3 - y3 - b2 + b3 * pow2 56) * pow2 168 +
(x4 - y4 - b3 + b4 * pow2 56) * pow2 224 ==
(x0 + x1 * pow2 56 + x2 * pow2 112 + x3 * pow2 168 + x4 * pow2 224) -
(y0 + y1 * pow2 56 + y2 * pow2 112 + y3 * pow2 168 + y4 * pow2 224) + b4 * pow2 280)
let lemma_subm_conditional x0 x1 x2 x3 x4 y0 y1 y2 y3 y4 b0 b1 b2 b3 b4 =
assert_norm (pow2 56 * pow2 56 = pow2 112);
assert_norm (pow2 56 * pow2 112 = pow2 168);
assert_norm (pow2 56 * pow2 168 = pow2 224);
assert_norm (pow2 56 * pow2 224 = pow2 280);
assert (
x0 - y0 + b0 * pow2 56 +
(x1 - y1 - b0 + b1 * pow2 56) * pow2 56 +
(x2 - y2 - b1 + b2 * pow2 56) * pow2 112 +
(x3 - y3 - b2 + b3 * pow2 56) * pow2 168 +
(x4 - y4 - b3 + b4 * pow2 56) * pow2 224 ==
(x0 + x1 * pow2 56 + x2 * pow2 112 + x3 * pow2 168 + x4 * pow2 224) -
(y0 + y1 * pow2 56 + y2 * pow2 112 + y3 * pow2 168 + y4 * pow2 224) + b4 * pow2 280)
by (int_semiring ());
()
val lemma_div224: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1))
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
wide_as_nat5 x / pow2 224 ==
v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280))
#push-options "--z3rlimit 50"
let lemma_div224 x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert
(wide_as_nat5 x ==
v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168 + v x4 * pow2 224 +
v x5 * pow2 280 + v x6 * pow2 336 + v x7 * pow2 392 + v x8 * pow2 448 + v x9 * pow2 504);
assert_norm (pow2 56 * pow2 224 == pow2 280);
assert_norm (pow2 112 * pow2 224 == pow2 336);
assert_norm (pow2 168 * pow2 224 == pow2 392);
assert_norm (pow2 224 * pow2 224 == pow2 448);
assert_norm (pow2 280 * pow2 224 == pow2 504);
calc (==) {
wide_as_nat5 x / pow2 224;
(==) { }
(v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168 +
(v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280) * pow2 224) / pow2 224;
(==) {
FStar.Math.Lemmas.lemma_div_plus
(v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168)
(v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280) (pow2 224) }
(v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168) / pow2 224 +
v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280;
(==) { FStar.Math.Lemmas.small_division_lemma_1 (v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168) (pow2 224) }
v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280;
}
#pop-options
val lemma_div248_aux: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 512)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
wide_as_nat5 x / pow2 248 ==
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256))
open FStar.Tactics.CanonCommSemiring
#push-options "--z3cliopt smt.arith.nl=false"
let lemma_div248_aux x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert_norm (pow2 248 == pow2 224 * pow2 24);
assert_norm (pow2 56 == pow2 32 * pow2 24);
assert_norm (pow2 112 == pow2 88 * pow2 24);
assert_norm (pow2 168 == pow2 144 * pow2 24);
assert_norm (pow2 224 == pow2 200 * pow2 24);
assert_norm (pow2 280 == pow2 256 * pow2 24);
assert_norm (0 < pow2 24);
calc (==) {
wide_as_nat5 x / pow2 248;
(==) { FStar.Math.Lemmas.division_multiplication_lemma (wide_as_nat5 x) (pow2 224) (pow2 24) }
(wide_as_nat5 x / pow2 224) / pow2 24;
(==) { lemma_div224 x }
(v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280) / pow2 24;
(==) { _ by (Tactics.mapply (`feq #int #int (fun x -> x / pow2 24)); int_semiring ()) } (v x4 + (v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256) * pow2 24) / pow2 24;
(==) { FStar.Math.Lemmas.lemma_div_plus (v x4) (v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256) (pow2 24) }
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256;
}
#pop-options
val lemma_div248_x5: x5:uint64 ->
Lemma ( pow2 32 * (v x5 % pow2 24) + v x5 / pow2 24 * pow2 56 == v x5 * pow2 32)
let lemma_div248_x5 x5 =
assert_norm (pow2 32 * pow2 24 = pow2 56)
val lemma_div248_x6: x6:uint64 ->
Lemma (pow2 32 * (v x6 % pow2 24) * pow2 56 + v x6 / pow2 24 * pow2 112 == v x6 * pow2 88)
let lemma_div248_x6 x6 =
calc (==) {
pow2 32 * (v x6 % pow2 24) * pow2 56 + v x6 / pow2 24 * pow2 112;
(==) { _ by (Tactics.norm [delta_only [`%pow2]; primops]; int_semiring ()) }
((v x6 / pow2 24) * pow2 24 + v x6 % pow2 24) * pow2 88;
(==) { FStar.Math.Lemmas.euclidean_division_definition (v x6) (pow2 24) }
v x6 * pow2 88;
}
val lemma_div248_x7: x7:uint64 ->
Lemma (pow2 32 * (v x7 % pow2 24) * pow2 112 + v x7 / pow2 24 * pow2 168 == v x7 * pow2 144)
let lemma_div248_x7 x7 =
calc (==) {
pow2 32 * (v x7 % pow2 24) * pow2 112 + v x7 / pow2 24 * pow2 168;
(==) { _ by (Tactics.norm [delta_only [`%pow2]; primops]; int_semiring ()) }
((v x7 / pow2 24) * pow2 24 + v x7 % pow2 24) * pow2 144;
(==) { FStar.Math.Lemmas.euclidean_division_definition (v x7) (pow2 24) }
v x7 * pow2 144;
}
val lemma_div248_x8: x8:uint64 ->
Lemma (pow2 32 * (v x8 % pow2 24) * pow2 168 + v x8 / pow2 24 * pow2 224 == v x8 * pow2 200)
let lemma_div248_x8 x8 =
calc (==) {
pow2 32 * (v x8 % pow2 24) * pow2 168 + v x8 / pow2 24 * pow2 224;
(==) { _ by (Tactics.norm [delta_only [`%pow2]; primops]; int_semiring ()) }
((v x8 / pow2 24) * pow2 24 + v x8 % pow2 24) * pow2 200;
(==) { FStar.Math.Lemmas.euclidean_division_definition (v x8) (pow2 24) }
v x8 * pow2 200;
}
val lemma_div248_x9: x9:uint64{v x9 < pow2 24} ->
Lemma (pow2 32 * (v x9 % pow2 24) * pow2 224 == v x9 * pow2 256)
let lemma_div248_x9 x9 =
calc (==) {
pow2 32 * (v x9 % pow2 24) * pow2 224;
(==) { Math.Lemmas.small_mod (v x9) (pow2 24) }
pow2 32 * v x9 * pow2 224;
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
v x9 * pow2 256;
}
val lemma_wide_as_nat_pow512: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 512)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
v x9 < pow2 24))
let lemma_wide_as_nat_pow512 x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert_norm (pow2 504 * pow2 8 = pow2 512);
FStar.Math.Lemmas.pow2_minus 512 504;
assert (v x9 < pow2 8);
assert_norm (pow2 8 < pow2 24)
val lemma_div248: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 512)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
let z0 = v x4 / pow2 24 + pow2 32 * (v x5 % pow2 24) in
let z1 = v x5 / pow2 24 + pow2 32 * (v x6 % pow2 24) in
let z2 = v x6 / pow2 24 + pow2 32 * (v x7 % pow2 24) in
let z3 = v x7 / pow2 24 + pow2 32 * (v x8 % pow2 24) in
let z4 = v x8 / pow2 24 + pow2 32 * (v x9 % pow2 24) in
wide_as_nat5 x / pow2 248 == z0 + z1 * pow2 56 + z2 * pow2 112 + z3 * pow2 168 + z4 * pow2 224))
#push-options "--z3rlimit 50"
let lemma_div248 x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
lemma_wide_as_nat_pow512 x;
assert (v x9 < pow2 24);
calc (==) {
(let z0 = v x4 / pow2 24 + pow2 32 * (v x5 % pow2 24) in
let z1 = v x5 / pow2 24 + pow2 32 * (v x6 % pow2 24) in
let z2 = v x6 / pow2 24 + pow2 32 * (v x7 % pow2 24) in
let z3 = v x7 / pow2 24 + pow2 32 * (v x8 % pow2 24) in
let z4 = v x8 / pow2 24 + pow2 32 * (v x9 % pow2 24) in
z0 + z1 * pow2 56 + z2 * pow2 112 + z3 * pow2 168 + z4 * pow2 224);
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
v x4 / pow2 24 + pow2 32 * (v x5 % pow2 24) +
v x5 / pow2 24 * pow2 56 + pow2 32 * (v x6 % pow2 24) * pow2 56 +
v x6 / pow2 24 * pow2 112 + pow2 32 * (v x7 % pow2 24) * pow2 112 +
v x7 / pow2 24 * pow2 168 + pow2 32 * (v x8 % pow2 24) * pow2 168 +
v x8 / pow2 24 * pow2 224 + pow2 32 * (v x9 % pow2 24) * pow2 224;
(==) { lemma_div248_x5 x5; lemma_div248_x6 x6 }
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 +
pow2 32 * (v x7 % pow2 24) * pow2 112 +
v x7 / pow2 24 * pow2 168 + pow2 32 * (v x8 % pow2 24) * pow2 168 +
v x8 / pow2 24 * pow2 224 + pow2 32 * (v x9 % pow2 24) * pow2 224;
(==) { lemma_div248_x7 x7; lemma_div248_x8 x8 }
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 +
pow2 32 * (v x9 % pow2 24) * pow2 224;
(==) { lemma_div248_x9 x9 }
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256;
(==) { lemma_div248_aux x }
wide_as_nat5 x / pow2 248;
}
#pop-options
val lemma_add_modq5:
x:qelem5
-> y:qelem5
-> t:qelem5 ->
Lemma
(requires
qelem_fits5 x (1, 1, 1, 1, 1) /\
qelem_fits5 y (1, 1, 1, 1, 1) /\
qelem_fits5 t (1, 1, 1, 1, 1) /\
as_nat5 x < S.q /\ as_nat5 y < S.q /\
as_nat5 t == as_nat5 x + as_nat5 y)
(ensures
(let res = if as_nat5 t >= S.q then as_nat5 t - S.q else as_nat5 t in
res < S.q /\ res == (as_nat5 x + as_nat5 y) % S.q))
let lemma_add_modq5 x y t =
assert (as_nat5 t == as_nat5 x + as_nat5 y);
let res = if as_nat5 t >= S.q then as_nat5 t - S.q else as_nat5 t in
assert (res < S.q);
if as_nat5 t >= S.q then (
FStar.Math.Lemmas.sub_div_mod_1 (as_nat5 t) S.q;
assert (res % S.q == as_nat5 t % S.q))
else
assert (res % S.q == as_nat5 t % S.q);
FStar.Math.Lemmas.small_mod res S.q
val lemma_wide_as_nat_pow528: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 528)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
v x9 < pow2 40))
let lemma_wide_as_nat_pow528 x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert_norm (pow2 504 * pow2 24 = pow2 528);
FStar.Math.Lemmas.pow2_minus 528 504;
assert (v x9 < pow2 24);
assert_norm (pow2 24 < pow2 40)
#push-options "--z3cliopt smt.arith.nl=false"
val lemma_div264_aux: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 528)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
wide_as_nat5 x / pow2 264 ==
v x4 / pow2 40 + v x5 * pow2 16 + v x6 * pow2 72 + v x7 * pow2 128 + v x8 * pow2 184 + v x9 * pow2 240))
let lemma_div264_aux x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert_norm (pow2 264 == pow2 224 * pow2 40);
assert_norm (pow2 56 == pow2 16 * pow2 40);
assert_norm (pow2 112 == pow2 72 * pow2 40);
assert_norm (pow2 168 == pow2 128 * pow2 40);
assert_norm (pow2 224 == pow2 184 * pow2 40);
assert_norm (pow2 280 == pow2 240 * pow2 40);
assert_norm (0 < pow2 40);
calc (==) {
wide_as_nat5 x / pow2 264;
(==) { FStar.Math.Lemmas.division_multiplication_lemma (wide_as_nat5 x) (pow2 224) (pow2 40) }
(wide_as_nat5 x / pow2 224) / pow2 40;
(==) { lemma_div224 x }
(v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280) / pow2 40;
(==) { _ by (Tactics.mapply (`feq #int #int (fun x -> x / pow2 40)); int_semiring ()) }
(v x4 + (v x5 * pow2 16 + v x6 * pow2 72 + v x7 * pow2 128 + v x8 * pow2 184 + v x9 * pow2 240) * pow2 40) / pow2 40;
(==) { FStar.Math.Lemmas.lemma_div_plus (v x4) (v x5 * pow2 16 + v x6 * pow2 72 + v x7 * pow2 128 + v x8 * pow2 184 + v x9 * pow2 240) (pow2 40) }
v x4 / pow2 40 + v x5 * pow2 16 + v x6 * pow2 72 + v x7 * pow2 128 + v x8 * pow2 184 + v x9 * pow2 240;
}
val lemma_div264_x5: x5:uint64 ->
Lemma (pow2 16 * (v x5 % pow2 40) + v x5 / pow2 40 * pow2 56 == v x5 * pow2 16)
let lemma_div264_x5 x5 =
assert_norm (0 < pow2 24);
calc (==) {
pow2 16 * (v x5 % pow2 40) + v x5 / pow2 40 * pow2 56;
(==) { _ by (Tactics.norm [delta_only [`%pow2]; primops]; int_semiring ()) }
((v x5 / pow2 40) * pow2 40 + v x5 % pow2 40) * pow2 16;
(==) { FStar.Math.Lemmas.euclidean_division_definition (v x5) (pow2 40) }
v x5 * pow2 16;
}
val lemma_div264_x6: x6:uint64 ->
Lemma (pow2 16 * (v x6 % pow2 40) * pow2 56 + v x6 / pow2 40 * pow2 112 == v x6 * pow2 72)
let lemma_div264_x6 x6 =
calc (==) {
pow2 16 * (v x6 % pow2 40) * pow2 56 + v x6 / pow2 40 * pow2 112;
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
((v x6 / pow2 40) * pow2 40 + v x6 % pow2 40) * pow2 72;
(==) { Math.Lemmas.euclidean_division_definition (v x6) (pow2 40) }
v x6 * pow2 72;
}
val lemma_div264_x7: x7:uint64 ->
Lemma (pow2 16 * (v x7 % pow2 40) * pow2 112 + v x7 / pow2 40 * pow2 168 == v x7 * pow2 128)
let lemma_div264_x7 x7 =
calc (==) {
pow2 16 * (v x7 % pow2 40) * pow2 112 + v x7 / pow2 40 * pow2 168;
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
((v x7 / pow2 40) * pow2 40 + v x7 % pow2 40) * pow2 128;
(==) { Math.Lemmas.euclidean_division_definition (v x7) (pow2 40) }
v x7 * pow2 128;
}
val lemma_div264_x8: x8:uint64 ->
Lemma (pow2 16 * (v x8 % pow2 40) * pow2 168 + v x8 / pow2 40 * pow2 224 == v x8 * pow2 184)
let lemma_div264_x8 x8 =
calc (==) {
pow2 16 * (v x8 % pow2 40) * pow2 168 + v x8 / pow2 40 * pow2 224;
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
((v x8 / pow2 40) * pow2 40 + v x8 % pow2 40) * pow2 184;
(==) { Math.Lemmas.euclidean_division_definition (v x8) (pow2 40) }
v x8 * pow2 184;
}
val lemma_div264_x9: x9:uint64{v x9 < pow2 40} -> | {
"checked_file": "/",
"dependencies": [
"Spec.Ed25519.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.BignumQ.Definitions.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Tactics.CanonCommSemiring.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.BignumQ.Lemmas.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.CanonCommSemiring",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.BignumQ.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.Ed25519",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.CanonCommSemiring",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.BignumQ",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.BignumQ",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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": [
"smt.arith.nl=false"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x9: Lib.IntTypes.uint64{Lib.IntTypes.v x9 < Prims.pow2 40}
-> FStar.Pervasives.Lemma
(ensures
(Prims.pow2 16 * (Lib.IntTypes.v x9 % Prims.pow2 40)) * Prims.pow2 224 ==
Lib.IntTypes.v x9 * Prims.pow2 240) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Lib.IntTypes.uint64",
"Prims.b2t",
"Prims.op_LessThan",
"Lib.IntTypes.v",
"Lib.IntTypes.U64",
"Lib.IntTypes.SEC",
"Prims.pow2",
"FStar.Calc.calc_finish",
"Prims.int",
"Prims.eq2",
"FStar.Mul.op_Star",
"Prims.op_Modulus",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"Prims.unit",
"FStar.Calc.calc_step",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"FStar.Math.Lemmas.small_mod",
"Prims.squash",
"FStar.Tactics.CanonCommSemiring.semiring_reflect",
"FStar.Tactics.CanonCommSemiring.int_cr",
"FStar.Pervasives.Native.Mktuple2",
"Prims.list",
"FStar.Pervasives.Native.tuple2",
"Prims.nat",
"FStar.Pervasives.Native.snd",
"Prims.op_GreaterThanOrEqual",
"Lib.IntTypes.sec_int_v",
"FStar.Stubs.Reflection.V2.Data.var",
"FStar.Tactics.CanonCommSemiring.Pmult",
"FStar.Tactics.CanonCommSemiring.Pvar",
"Prims.op_Multiply",
"Prims.l_and",
"Prims.bool",
"Prims.op_LessThanOrEqual",
"Prims.op_Subtraction",
"Lib.IntTypes.bits"
] | [] | false | false | true | false | false | let lemma_div264_x9 x9 =
| calc ( == ) {
(pow2 16 * (v x9 % pow2 40)) * pow2 224;
( == ) { Math.Lemmas.small_mod (v x9) (pow2 40) }
(pow2 16 * v x9) * pow2 224;
( == ) { FStar.Tactics.Effect.synth_by_tactic (fun _ ->
(Tactics.norm [delta; primops];
int_semiring ())) }
v x9 * pow2 240;
} | false |
Hacl.Spec.BignumQ.Lemmas.fst | Hacl.Spec.BignumQ.Lemmas.lemma_div248_x9 | val lemma_div248_x9: x9:uint64{v x9 < pow2 24} ->
Lemma (pow2 32 * (v x9 % pow2 24) * pow2 224 == v x9 * pow2 256) | val lemma_div248_x9: x9:uint64{v x9 < pow2 24} ->
Lemma (pow2 32 * (v x9 % pow2 24) * pow2 224 == v x9 * pow2 256) | let lemma_div248_x9 x9 =
calc (==) {
pow2 32 * (v x9 % pow2 24) * pow2 224;
(==) { Math.Lemmas.small_mod (v x9) (pow2 24) }
pow2 32 * v x9 * pow2 224;
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
v x9 * pow2 256;
} | {
"file_name": "code/ed25519/Hacl.Spec.BignumQ.Lemmas.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 3,
"end_line": 212,
"start_col": 0,
"start_line": 205
} | module Hacl.Spec.BignumQ.Lemmas
open FStar.Tactics.CanonCommSemiring
open FStar.Mul
open Lib.IntTypes
module S = Spec.Ed25519
include Hacl.Spec.BignumQ.Definitions
let feq (#a #b:Type) (f:(a -> b)) (x y:a) :
Lemma (requires x == y) (ensures f x == f y) = ()
let eq_eq2 (#a:eqtype) (x y:a) :
Lemma (requires x = y) (ensures x == y) = ()
val lemma_mul_lt:a:nat -> b:nat -> c:nat -> d:nat ->
Lemma
(requires a < b /\ c < d)
(ensures a * c < b * d)
let lemma_mul_lt a b c d = ()
val lemma_as_nat5: f:qelem5 ->
Lemma
(requires qelem_fits5 f (1, 1, 1, 1, 1))
(ensures as_nat5 f < pow2 280)
let lemma_as_nat5 f =
//let (f0, f1, f2, f3, f4) = f in
//assert (as_nat5 f == v f0 + v f1 * pow56 + v f2 * pow112 + v f3 * pow168 + v f4 * pow224);
assert_norm (pow2 56 * pow2 56 = pow2 112);
assert_norm (pow2 56 * pow2 112 = pow2 168);
assert_norm (pow2 56 * pow2 168 = pow2 224);
assert_norm (pow2 56 * pow2 224 = pow2 280)
val lemma_choose_step:
bit:uint64{v bit <= 1}
-> x:uint64
-> y:uint64
-> Lemma
(let mask = bit -. u64 1 in
let z = x ^. (mask &. (x ^. y)) in
if v bit = 1 then z == x else z == y)
let lemma_choose_step bit p1 p2 =
let mask = bit -. u64 1 in
assert (v bit == 0 ==> v mask == pow2 64 - 1);
assert (v bit == 1 ==> v mask == 0);
let dummy = mask &. (p1 ^. p2) in
logand_lemma mask (p1 ^. p2);
assert (v bit == 1 ==> v dummy == 0);
assert (v bit == 0 ==> v dummy == v (p1 ^. p2));
let p1' = p1 ^. dummy in
assert (v dummy == v (if v bit = 1 then u64 0 else (p1 ^. p2)));
logxor_lemma p1 p2
val lemma_subm_conditional:
x0:nat -> x1:nat -> x2:nat -> x3:nat -> x4:nat
-> y0:nat -> y1:nat -> y2:nat -> y3:nat -> y4:nat
-> b0:nat -> b1:nat -> b2:nat -> b3:nat -> b4:nat ->
Lemma (
x0 - y0 + b0 * pow2 56 +
(x1 - y1 - b0 + b1 * pow2 56) * pow2 56 +
(x2 - y2 - b1 + b2 * pow2 56) * pow2 112 +
(x3 - y3 - b2 + b3 * pow2 56) * pow2 168 +
(x4 - y4 - b3 + b4 * pow2 56) * pow2 224 ==
(x0 + x1 * pow2 56 + x2 * pow2 112 + x3 * pow2 168 + x4 * pow2 224) -
(y0 + y1 * pow2 56 + y2 * pow2 112 + y3 * pow2 168 + y4 * pow2 224) + b4 * pow2 280)
let lemma_subm_conditional x0 x1 x2 x3 x4 y0 y1 y2 y3 y4 b0 b1 b2 b3 b4 =
assert_norm (pow2 56 * pow2 56 = pow2 112);
assert_norm (pow2 56 * pow2 112 = pow2 168);
assert_norm (pow2 56 * pow2 168 = pow2 224);
assert_norm (pow2 56 * pow2 224 = pow2 280);
assert (
x0 - y0 + b0 * pow2 56 +
(x1 - y1 - b0 + b1 * pow2 56) * pow2 56 +
(x2 - y2 - b1 + b2 * pow2 56) * pow2 112 +
(x3 - y3 - b2 + b3 * pow2 56) * pow2 168 +
(x4 - y4 - b3 + b4 * pow2 56) * pow2 224 ==
(x0 + x1 * pow2 56 + x2 * pow2 112 + x3 * pow2 168 + x4 * pow2 224) -
(y0 + y1 * pow2 56 + y2 * pow2 112 + y3 * pow2 168 + y4 * pow2 224) + b4 * pow2 280)
by (int_semiring ());
()
val lemma_div224: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1))
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
wide_as_nat5 x / pow2 224 ==
v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280))
#push-options "--z3rlimit 50"
let lemma_div224 x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert
(wide_as_nat5 x ==
v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168 + v x4 * pow2 224 +
v x5 * pow2 280 + v x6 * pow2 336 + v x7 * pow2 392 + v x8 * pow2 448 + v x9 * pow2 504);
assert_norm (pow2 56 * pow2 224 == pow2 280);
assert_norm (pow2 112 * pow2 224 == pow2 336);
assert_norm (pow2 168 * pow2 224 == pow2 392);
assert_norm (pow2 224 * pow2 224 == pow2 448);
assert_norm (pow2 280 * pow2 224 == pow2 504);
calc (==) {
wide_as_nat5 x / pow2 224;
(==) { }
(v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168 +
(v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280) * pow2 224) / pow2 224;
(==) {
FStar.Math.Lemmas.lemma_div_plus
(v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168)
(v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280) (pow2 224) }
(v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168) / pow2 224 +
v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280;
(==) { FStar.Math.Lemmas.small_division_lemma_1 (v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168) (pow2 224) }
v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280;
}
#pop-options
val lemma_div248_aux: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 512)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
wide_as_nat5 x / pow2 248 ==
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256))
open FStar.Tactics.CanonCommSemiring
#push-options "--z3cliopt smt.arith.nl=false"
let lemma_div248_aux x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert_norm (pow2 248 == pow2 224 * pow2 24);
assert_norm (pow2 56 == pow2 32 * pow2 24);
assert_norm (pow2 112 == pow2 88 * pow2 24);
assert_norm (pow2 168 == pow2 144 * pow2 24);
assert_norm (pow2 224 == pow2 200 * pow2 24);
assert_norm (pow2 280 == pow2 256 * pow2 24);
assert_norm (0 < pow2 24);
calc (==) {
wide_as_nat5 x / pow2 248;
(==) { FStar.Math.Lemmas.division_multiplication_lemma (wide_as_nat5 x) (pow2 224) (pow2 24) }
(wide_as_nat5 x / pow2 224) / pow2 24;
(==) { lemma_div224 x }
(v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280) / pow2 24;
(==) { _ by (Tactics.mapply (`feq #int #int (fun x -> x / pow2 24)); int_semiring ()) } (v x4 + (v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256) * pow2 24) / pow2 24;
(==) { FStar.Math.Lemmas.lemma_div_plus (v x4) (v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256) (pow2 24) }
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256;
}
#pop-options
val lemma_div248_x5: x5:uint64 ->
Lemma ( pow2 32 * (v x5 % pow2 24) + v x5 / pow2 24 * pow2 56 == v x5 * pow2 32)
let lemma_div248_x5 x5 =
assert_norm (pow2 32 * pow2 24 = pow2 56)
val lemma_div248_x6: x6:uint64 ->
Lemma (pow2 32 * (v x6 % pow2 24) * pow2 56 + v x6 / pow2 24 * pow2 112 == v x6 * pow2 88)
let lemma_div248_x6 x6 =
calc (==) {
pow2 32 * (v x6 % pow2 24) * pow2 56 + v x6 / pow2 24 * pow2 112;
(==) { _ by (Tactics.norm [delta_only [`%pow2]; primops]; int_semiring ()) }
((v x6 / pow2 24) * pow2 24 + v x6 % pow2 24) * pow2 88;
(==) { FStar.Math.Lemmas.euclidean_division_definition (v x6) (pow2 24) }
v x6 * pow2 88;
}
val lemma_div248_x7: x7:uint64 ->
Lemma (pow2 32 * (v x7 % pow2 24) * pow2 112 + v x7 / pow2 24 * pow2 168 == v x7 * pow2 144)
let lemma_div248_x7 x7 =
calc (==) {
pow2 32 * (v x7 % pow2 24) * pow2 112 + v x7 / pow2 24 * pow2 168;
(==) { _ by (Tactics.norm [delta_only [`%pow2]; primops]; int_semiring ()) }
((v x7 / pow2 24) * pow2 24 + v x7 % pow2 24) * pow2 144;
(==) { FStar.Math.Lemmas.euclidean_division_definition (v x7) (pow2 24) }
v x7 * pow2 144;
}
val lemma_div248_x8: x8:uint64 ->
Lemma (pow2 32 * (v x8 % pow2 24) * pow2 168 + v x8 / pow2 24 * pow2 224 == v x8 * pow2 200)
let lemma_div248_x8 x8 =
calc (==) {
pow2 32 * (v x8 % pow2 24) * pow2 168 + v x8 / pow2 24 * pow2 224;
(==) { _ by (Tactics.norm [delta_only [`%pow2]; primops]; int_semiring ()) }
((v x8 / pow2 24) * pow2 24 + v x8 % pow2 24) * pow2 200;
(==) { FStar.Math.Lemmas.euclidean_division_definition (v x8) (pow2 24) }
v x8 * pow2 200;
}
val lemma_div248_x9: x9:uint64{v x9 < pow2 24} -> | {
"checked_file": "/",
"dependencies": [
"Spec.Ed25519.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.BignumQ.Definitions.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Tactics.CanonCommSemiring.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.BignumQ.Lemmas.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.CanonCommSemiring",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.BignumQ.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.Ed25519",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.CanonCommSemiring",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.BignumQ",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.BignumQ",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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 | x9: Lib.IntTypes.uint64{Lib.IntTypes.v x9 < Prims.pow2 24}
-> FStar.Pervasives.Lemma
(ensures
(Prims.pow2 32 * (Lib.IntTypes.v x9 % Prims.pow2 24)) * Prims.pow2 224 ==
Lib.IntTypes.v x9 * Prims.pow2 256) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Lib.IntTypes.uint64",
"Prims.b2t",
"Prims.op_LessThan",
"Lib.IntTypes.v",
"Lib.IntTypes.U64",
"Lib.IntTypes.SEC",
"Prims.pow2",
"FStar.Calc.calc_finish",
"Prims.int",
"Prims.eq2",
"FStar.Mul.op_Star",
"Prims.op_Modulus",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"Prims.unit",
"FStar.Calc.calc_step",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"FStar.Math.Lemmas.small_mod",
"Prims.squash",
"FStar.Tactics.CanonCommSemiring.semiring_reflect",
"FStar.Tactics.CanonCommSemiring.int_cr",
"FStar.Pervasives.Native.Mktuple2",
"Prims.list",
"FStar.Pervasives.Native.tuple2",
"Prims.nat",
"FStar.Pervasives.Native.snd",
"Prims.op_GreaterThanOrEqual",
"Lib.IntTypes.sec_int_v",
"FStar.Stubs.Reflection.V2.Data.var",
"FStar.Tactics.CanonCommSemiring.Pmult",
"FStar.Tactics.CanonCommSemiring.Pvar",
"Prims.op_Multiply",
"Prims.l_and",
"Prims.bool",
"Prims.op_LessThanOrEqual",
"Prims.op_Subtraction",
"Lib.IntTypes.bits"
] | [] | false | false | true | false | false | let lemma_div248_x9 x9 =
| calc ( == ) {
(pow2 32 * (v x9 % pow2 24)) * pow2 224;
( == ) { Math.Lemmas.small_mod (v x9) (pow2 24) }
(pow2 32 * v x9) * pow2 224;
( == ) { FStar.Tactics.Effect.synth_by_tactic (fun _ ->
(Tactics.norm [delta; primops];
int_semiring ())) }
v x9 * pow2 256;
} | false |
Hacl.Spec.BignumQ.Lemmas.fst | Hacl.Spec.BignumQ.Lemmas.lemma_div248_x8 | val lemma_div248_x8: x8:uint64 ->
Lemma (pow2 32 * (v x8 % pow2 24) * pow2 168 + v x8 / pow2 24 * pow2 224 == v x8 * pow2 200) | val lemma_div248_x8: x8:uint64 ->
Lemma (pow2 32 * (v x8 % pow2 24) * pow2 168 + v x8 / pow2 24 * pow2 224 == v x8 * pow2 200) | let lemma_div248_x8 x8 =
calc (==) {
pow2 32 * (v x8 % pow2 24) * pow2 168 + v x8 / pow2 24 * pow2 224;
(==) { _ by (Tactics.norm [delta_only [`%pow2]; primops]; int_semiring ()) }
((v x8 / pow2 24) * pow2 24 + v x8 % pow2 24) * pow2 200;
(==) { FStar.Math.Lemmas.euclidean_division_definition (v x8) (pow2 24) }
v x8 * pow2 200;
} | {
"file_name": "code/ed25519/Hacl.Spec.BignumQ.Lemmas.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 3,
"end_line": 200,
"start_col": 0,
"start_line": 193
} | module Hacl.Spec.BignumQ.Lemmas
open FStar.Tactics.CanonCommSemiring
open FStar.Mul
open Lib.IntTypes
module S = Spec.Ed25519
include Hacl.Spec.BignumQ.Definitions
let feq (#a #b:Type) (f:(a -> b)) (x y:a) :
Lemma (requires x == y) (ensures f x == f y) = ()
let eq_eq2 (#a:eqtype) (x y:a) :
Lemma (requires x = y) (ensures x == y) = ()
val lemma_mul_lt:a:nat -> b:nat -> c:nat -> d:nat ->
Lemma
(requires a < b /\ c < d)
(ensures a * c < b * d)
let lemma_mul_lt a b c d = ()
val lemma_as_nat5: f:qelem5 ->
Lemma
(requires qelem_fits5 f (1, 1, 1, 1, 1))
(ensures as_nat5 f < pow2 280)
let lemma_as_nat5 f =
//let (f0, f1, f2, f3, f4) = f in
//assert (as_nat5 f == v f0 + v f1 * pow56 + v f2 * pow112 + v f3 * pow168 + v f4 * pow224);
assert_norm (pow2 56 * pow2 56 = pow2 112);
assert_norm (pow2 56 * pow2 112 = pow2 168);
assert_norm (pow2 56 * pow2 168 = pow2 224);
assert_norm (pow2 56 * pow2 224 = pow2 280)
val lemma_choose_step:
bit:uint64{v bit <= 1}
-> x:uint64
-> y:uint64
-> Lemma
(let mask = bit -. u64 1 in
let z = x ^. (mask &. (x ^. y)) in
if v bit = 1 then z == x else z == y)
let lemma_choose_step bit p1 p2 =
let mask = bit -. u64 1 in
assert (v bit == 0 ==> v mask == pow2 64 - 1);
assert (v bit == 1 ==> v mask == 0);
let dummy = mask &. (p1 ^. p2) in
logand_lemma mask (p1 ^. p2);
assert (v bit == 1 ==> v dummy == 0);
assert (v bit == 0 ==> v dummy == v (p1 ^. p2));
let p1' = p1 ^. dummy in
assert (v dummy == v (if v bit = 1 then u64 0 else (p1 ^. p2)));
logxor_lemma p1 p2
val lemma_subm_conditional:
x0:nat -> x1:nat -> x2:nat -> x3:nat -> x4:nat
-> y0:nat -> y1:nat -> y2:nat -> y3:nat -> y4:nat
-> b0:nat -> b1:nat -> b2:nat -> b3:nat -> b4:nat ->
Lemma (
x0 - y0 + b0 * pow2 56 +
(x1 - y1 - b0 + b1 * pow2 56) * pow2 56 +
(x2 - y2 - b1 + b2 * pow2 56) * pow2 112 +
(x3 - y3 - b2 + b3 * pow2 56) * pow2 168 +
(x4 - y4 - b3 + b4 * pow2 56) * pow2 224 ==
(x0 + x1 * pow2 56 + x2 * pow2 112 + x3 * pow2 168 + x4 * pow2 224) -
(y0 + y1 * pow2 56 + y2 * pow2 112 + y3 * pow2 168 + y4 * pow2 224) + b4 * pow2 280)
let lemma_subm_conditional x0 x1 x2 x3 x4 y0 y1 y2 y3 y4 b0 b1 b2 b3 b4 =
assert_norm (pow2 56 * pow2 56 = pow2 112);
assert_norm (pow2 56 * pow2 112 = pow2 168);
assert_norm (pow2 56 * pow2 168 = pow2 224);
assert_norm (pow2 56 * pow2 224 = pow2 280);
assert (
x0 - y0 + b0 * pow2 56 +
(x1 - y1 - b0 + b1 * pow2 56) * pow2 56 +
(x2 - y2 - b1 + b2 * pow2 56) * pow2 112 +
(x3 - y3 - b2 + b3 * pow2 56) * pow2 168 +
(x4 - y4 - b3 + b4 * pow2 56) * pow2 224 ==
(x0 + x1 * pow2 56 + x2 * pow2 112 + x3 * pow2 168 + x4 * pow2 224) -
(y0 + y1 * pow2 56 + y2 * pow2 112 + y3 * pow2 168 + y4 * pow2 224) + b4 * pow2 280)
by (int_semiring ());
()
val lemma_div224: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1))
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
wide_as_nat5 x / pow2 224 ==
v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280))
#push-options "--z3rlimit 50"
let lemma_div224 x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert
(wide_as_nat5 x ==
v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168 + v x4 * pow2 224 +
v x5 * pow2 280 + v x6 * pow2 336 + v x7 * pow2 392 + v x8 * pow2 448 + v x9 * pow2 504);
assert_norm (pow2 56 * pow2 224 == pow2 280);
assert_norm (pow2 112 * pow2 224 == pow2 336);
assert_norm (pow2 168 * pow2 224 == pow2 392);
assert_norm (pow2 224 * pow2 224 == pow2 448);
assert_norm (pow2 280 * pow2 224 == pow2 504);
calc (==) {
wide_as_nat5 x / pow2 224;
(==) { }
(v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168 +
(v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280) * pow2 224) / pow2 224;
(==) {
FStar.Math.Lemmas.lemma_div_plus
(v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168)
(v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280) (pow2 224) }
(v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168) / pow2 224 +
v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280;
(==) { FStar.Math.Lemmas.small_division_lemma_1 (v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168) (pow2 224) }
v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280;
}
#pop-options
val lemma_div248_aux: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 512)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
wide_as_nat5 x / pow2 248 ==
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256))
open FStar.Tactics.CanonCommSemiring
#push-options "--z3cliopt smt.arith.nl=false"
let lemma_div248_aux x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert_norm (pow2 248 == pow2 224 * pow2 24);
assert_norm (pow2 56 == pow2 32 * pow2 24);
assert_norm (pow2 112 == pow2 88 * pow2 24);
assert_norm (pow2 168 == pow2 144 * pow2 24);
assert_norm (pow2 224 == pow2 200 * pow2 24);
assert_norm (pow2 280 == pow2 256 * pow2 24);
assert_norm (0 < pow2 24);
calc (==) {
wide_as_nat5 x / pow2 248;
(==) { FStar.Math.Lemmas.division_multiplication_lemma (wide_as_nat5 x) (pow2 224) (pow2 24) }
(wide_as_nat5 x / pow2 224) / pow2 24;
(==) { lemma_div224 x }
(v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280) / pow2 24;
(==) { _ by (Tactics.mapply (`feq #int #int (fun x -> x / pow2 24)); int_semiring ()) } (v x4 + (v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256) * pow2 24) / pow2 24;
(==) { FStar.Math.Lemmas.lemma_div_plus (v x4) (v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256) (pow2 24) }
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256;
}
#pop-options
val lemma_div248_x5: x5:uint64 ->
Lemma ( pow2 32 * (v x5 % pow2 24) + v x5 / pow2 24 * pow2 56 == v x5 * pow2 32)
let lemma_div248_x5 x5 =
assert_norm (pow2 32 * pow2 24 = pow2 56)
val lemma_div248_x6: x6:uint64 ->
Lemma (pow2 32 * (v x6 % pow2 24) * pow2 56 + v x6 / pow2 24 * pow2 112 == v x6 * pow2 88)
let lemma_div248_x6 x6 =
calc (==) {
pow2 32 * (v x6 % pow2 24) * pow2 56 + v x6 / pow2 24 * pow2 112;
(==) { _ by (Tactics.norm [delta_only [`%pow2]; primops]; int_semiring ()) }
((v x6 / pow2 24) * pow2 24 + v x6 % pow2 24) * pow2 88;
(==) { FStar.Math.Lemmas.euclidean_division_definition (v x6) (pow2 24) }
v x6 * pow2 88;
}
val lemma_div248_x7: x7:uint64 ->
Lemma (pow2 32 * (v x7 % pow2 24) * pow2 112 + v x7 / pow2 24 * pow2 168 == v x7 * pow2 144)
let lemma_div248_x7 x7 =
calc (==) {
pow2 32 * (v x7 % pow2 24) * pow2 112 + v x7 / pow2 24 * pow2 168;
(==) { _ by (Tactics.norm [delta_only [`%pow2]; primops]; int_semiring ()) }
((v x7 / pow2 24) * pow2 24 + v x7 % pow2 24) * pow2 144;
(==) { FStar.Math.Lemmas.euclidean_division_definition (v x7) (pow2 24) }
v x7 * pow2 144;
}
val lemma_div248_x8: x8:uint64 -> | {
"checked_file": "/",
"dependencies": [
"Spec.Ed25519.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.BignumQ.Definitions.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Tactics.CanonCommSemiring.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.BignumQ.Lemmas.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.CanonCommSemiring",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.BignumQ.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.Ed25519",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.CanonCommSemiring",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.BignumQ",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.BignumQ",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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 | x8: Lib.IntTypes.uint64
-> FStar.Pervasives.Lemma
(ensures
(Prims.pow2 32 * (Lib.IntTypes.v x8 % Prims.pow2 24)) * Prims.pow2 168 +
(Lib.IntTypes.v x8 / Prims.pow2 24) * Prims.pow2 224 ==
Lib.IntTypes.v x8 * Prims.pow2 200) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Lib.IntTypes.uint64",
"FStar.Calc.calc_finish",
"Prims.int",
"Prims.eq2",
"Prims.op_Addition",
"FStar.Mul.op_Star",
"Prims.pow2",
"Prims.op_Modulus",
"Lib.IntTypes.v",
"Lib.IntTypes.U64",
"Lib.IntTypes.SEC",
"Prims.op_Division",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"Prims.unit",
"FStar.Calc.calc_step",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"FStar.Tactics.CanonCommSemiring.semiring_reflect",
"FStar.Tactics.CanonCommSemiring.int_cr",
"FStar.Pervasives.Native.Mktuple2",
"Prims.list",
"FStar.Pervasives.Native.tuple2",
"Prims.nat",
"FStar.Pervasives.Native.snd",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"Lib.IntTypes.sec_int_v",
"FStar.Stubs.Reflection.V2.Data.var",
"FStar.Tactics.CanonCommSemiring.Pplus",
"FStar.Tactics.CanonCommSemiring.Pmult",
"FStar.Tactics.CanonCommSemiring.Pvar",
"Prims.squash",
"FStar.Math.Lemmas.euclidean_division_definition"
] | [] | false | false | true | false | false | let lemma_div248_x8 x8 =
| calc ( == ) {
(pow2 32 * (v x8 % pow2 24)) * pow2 168 + (v x8 / pow2 24) * pow2 224;
( == ) { FStar.Tactics.Effect.synth_by_tactic (fun _ ->
(Tactics.norm [delta_only [`%pow2]; primops];
int_semiring ())) }
((v x8 / pow2 24) * pow2 24 + v x8 % pow2 24) * pow2 200;
( == ) { FStar.Math.Lemmas.euclidean_division_definition (v x8) (pow2 24) }
v x8 * pow2 200;
} | false |
Hacl.Spec.BignumQ.Lemmas.fst | Hacl.Spec.BignumQ.Lemmas.lemma_mod_264' | val lemma_mod_264':
a0:nat -> a1:nat-> a2:nat -> a3:nat -> a4:nat ->
Lemma
(requires a0 < pow56 /\ a1 < pow56 /\ a2 < pow56 /\ a3 < pow56)
(ensures (a0
+ pow2 56 * a1
+ pow2 112 * a2
+ pow2 168 * a3
+ pow2 224 * a4) % pow2 264 =
a0
+ pow2 56 * a1
+ pow2 112 * a2
+ pow2 168 * a3
+ pow2 224 * (a4 % pow2 40) ) | val lemma_mod_264':
a0:nat -> a1:nat-> a2:nat -> a3:nat -> a4:nat ->
Lemma
(requires a0 < pow56 /\ a1 < pow56 /\ a2 < pow56 /\ a3 < pow56)
(ensures (a0
+ pow2 56 * a1
+ pow2 112 * a2
+ pow2 168 * a3
+ pow2 224 * a4) % pow2 264 =
a0
+ pow2 56 * a1
+ pow2 112 * a2
+ pow2 168 * a3
+ pow2 224 * (a4 % pow2 40) ) | let lemma_mod_264' a0 a1 a2 a3 a4 =
assert_norm(pow2 56 = 0x100000000000000);
assert_norm(pow2 112 = 0x10000000000000000000000000000);
assert_norm(pow2 168 = 0x1000000000000000000000000000000000000000000);
assert_norm(pow2 224 = 0x100000000000000000000000000000000000000000000000000000000);
Math.Lemmas.lemma_mod_plus_distr_l (pow2 224 * a4) (a0 + pow2 56 * a1 + pow2 112 * a2 + pow2 168 * a3) (pow2 264);
Math.Lemmas.pow2_multiplication_modulo_lemma_2 a4 264 224;
lemma_mod_264'' a0 a1 a2 a3 a4;
Math.Lemmas.modulo_lemma (a0 + pow2 56 * a1 + pow2 112 * a2 + pow2 168 * a3 + pow2 224 * (a4 % pow2 40)) (pow2 264) | {
"file_name": "code/ed25519/Hacl.Spec.BignumQ.Lemmas.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 117,
"end_line": 737,
"start_col": 0,
"start_line": 729
} | module Hacl.Spec.BignumQ.Lemmas
open FStar.Tactics.CanonCommSemiring
open FStar.Mul
open Lib.IntTypes
module S = Spec.Ed25519
include Hacl.Spec.BignumQ.Definitions
let feq (#a #b:Type) (f:(a -> b)) (x y:a) :
Lemma (requires x == y) (ensures f x == f y) = ()
let eq_eq2 (#a:eqtype) (x y:a) :
Lemma (requires x = y) (ensures x == y) = ()
val lemma_mul_lt:a:nat -> b:nat -> c:nat -> d:nat ->
Lemma
(requires a < b /\ c < d)
(ensures a * c < b * d)
let lemma_mul_lt a b c d = ()
val lemma_as_nat5: f:qelem5 ->
Lemma
(requires qelem_fits5 f (1, 1, 1, 1, 1))
(ensures as_nat5 f < pow2 280)
let lemma_as_nat5 f =
//let (f0, f1, f2, f3, f4) = f in
//assert (as_nat5 f == v f0 + v f1 * pow56 + v f2 * pow112 + v f3 * pow168 + v f4 * pow224);
assert_norm (pow2 56 * pow2 56 = pow2 112);
assert_norm (pow2 56 * pow2 112 = pow2 168);
assert_norm (pow2 56 * pow2 168 = pow2 224);
assert_norm (pow2 56 * pow2 224 = pow2 280)
val lemma_choose_step:
bit:uint64{v bit <= 1}
-> x:uint64
-> y:uint64
-> Lemma
(let mask = bit -. u64 1 in
let z = x ^. (mask &. (x ^. y)) in
if v bit = 1 then z == x else z == y)
let lemma_choose_step bit p1 p2 =
let mask = bit -. u64 1 in
assert (v bit == 0 ==> v mask == pow2 64 - 1);
assert (v bit == 1 ==> v mask == 0);
let dummy = mask &. (p1 ^. p2) in
logand_lemma mask (p1 ^. p2);
assert (v bit == 1 ==> v dummy == 0);
assert (v bit == 0 ==> v dummy == v (p1 ^. p2));
let p1' = p1 ^. dummy in
assert (v dummy == v (if v bit = 1 then u64 0 else (p1 ^. p2)));
logxor_lemma p1 p2
val lemma_subm_conditional:
x0:nat -> x1:nat -> x2:nat -> x3:nat -> x4:nat
-> y0:nat -> y1:nat -> y2:nat -> y3:nat -> y4:nat
-> b0:nat -> b1:nat -> b2:nat -> b3:nat -> b4:nat ->
Lemma (
x0 - y0 + b0 * pow2 56 +
(x1 - y1 - b0 + b1 * pow2 56) * pow2 56 +
(x2 - y2 - b1 + b2 * pow2 56) * pow2 112 +
(x3 - y3 - b2 + b3 * pow2 56) * pow2 168 +
(x4 - y4 - b3 + b4 * pow2 56) * pow2 224 ==
(x0 + x1 * pow2 56 + x2 * pow2 112 + x3 * pow2 168 + x4 * pow2 224) -
(y0 + y1 * pow2 56 + y2 * pow2 112 + y3 * pow2 168 + y4 * pow2 224) + b4 * pow2 280)
let lemma_subm_conditional x0 x1 x2 x3 x4 y0 y1 y2 y3 y4 b0 b1 b2 b3 b4 =
assert_norm (pow2 56 * pow2 56 = pow2 112);
assert_norm (pow2 56 * pow2 112 = pow2 168);
assert_norm (pow2 56 * pow2 168 = pow2 224);
assert_norm (pow2 56 * pow2 224 = pow2 280);
assert (
x0 - y0 + b0 * pow2 56 +
(x1 - y1 - b0 + b1 * pow2 56) * pow2 56 +
(x2 - y2 - b1 + b2 * pow2 56) * pow2 112 +
(x3 - y3 - b2 + b3 * pow2 56) * pow2 168 +
(x4 - y4 - b3 + b4 * pow2 56) * pow2 224 ==
(x0 + x1 * pow2 56 + x2 * pow2 112 + x3 * pow2 168 + x4 * pow2 224) -
(y0 + y1 * pow2 56 + y2 * pow2 112 + y3 * pow2 168 + y4 * pow2 224) + b4 * pow2 280)
by (int_semiring ());
()
val lemma_div224: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1))
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
wide_as_nat5 x / pow2 224 ==
v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280))
#push-options "--z3rlimit 50"
let lemma_div224 x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert
(wide_as_nat5 x ==
v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168 + v x4 * pow2 224 +
v x5 * pow2 280 + v x6 * pow2 336 + v x7 * pow2 392 + v x8 * pow2 448 + v x9 * pow2 504);
assert_norm (pow2 56 * pow2 224 == pow2 280);
assert_norm (pow2 112 * pow2 224 == pow2 336);
assert_norm (pow2 168 * pow2 224 == pow2 392);
assert_norm (pow2 224 * pow2 224 == pow2 448);
assert_norm (pow2 280 * pow2 224 == pow2 504);
calc (==) {
wide_as_nat5 x / pow2 224;
(==) { }
(v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168 +
(v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280) * pow2 224) / pow2 224;
(==) {
FStar.Math.Lemmas.lemma_div_plus
(v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168)
(v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280) (pow2 224) }
(v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168) / pow2 224 +
v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280;
(==) { FStar.Math.Lemmas.small_division_lemma_1 (v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168) (pow2 224) }
v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280;
}
#pop-options
val lemma_div248_aux: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 512)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
wide_as_nat5 x / pow2 248 ==
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256))
open FStar.Tactics.CanonCommSemiring
#push-options "--z3cliopt smt.arith.nl=false"
let lemma_div248_aux x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert_norm (pow2 248 == pow2 224 * pow2 24);
assert_norm (pow2 56 == pow2 32 * pow2 24);
assert_norm (pow2 112 == pow2 88 * pow2 24);
assert_norm (pow2 168 == pow2 144 * pow2 24);
assert_norm (pow2 224 == pow2 200 * pow2 24);
assert_norm (pow2 280 == pow2 256 * pow2 24);
assert_norm (0 < pow2 24);
calc (==) {
wide_as_nat5 x / pow2 248;
(==) { FStar.Math.Lemmas.division_multiplication_lemma (wide_as_nat5 x) (pow2 224) (pow2 24) }
(wide_as_nat5 x / pow2 224) / pow2 24;
(==) { lemma_div224 x }
(v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280) / pow2 24;
(==) { _ by (Tactics.mapply (`feq #int #int (fun x -> x / pow2 24)); int_semiring ()) } (v x4 + (v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256) * pow2 24) / pow2 24;
(==) { FStar.Math.Lemmas.lemma_div_plus (v x4) (v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256) (pow2 24) }
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256;
}
#pop-options
val lemma_div248_x5: x5:uint64 ->
Lemma ( pow2 32 * (v x5 % pow2 24) + v x5 / pow2 24 * pow2 56 == v x5 * pow2 32)
let lemma_div248_x5 x5 =
assert_norm (pow2 32 * pow2 24 = pow2 56)
val lemma_div248_x6: x6:uint64 ->
Lemma (pow2 32 * (v x6 % pow2 24) * pow2 56 + v x6 / pow2 24 * pow2 112 == v x6 * pow2 88)
let lemma_div248_x6 x6 =
calc (==) {
pow2 32 * (v x6 % pow2 24) * pow2 56 + v x6 / pow2 24 * pow2 112;
(==) { _ by (Tactics.norm [delta_only [`%pow2]; primops]; int_semiring ()) }
((v x6 / pow2 24) * pow2 24 + v x6 % pow2 24) * pow2 88;
(==) { FStar.Math.Lemmas.euclidean_division_definition (v x6) (pow2 24) }
v x6 * pow2 88;
}
val lemma_div248_x7: x7:uint64 ->
Lemma (pow2 32 * (v x7 % pow2 24) * pow2 112 + v x7 / pow2 24 * pow2 168 == v x7 * pow2 144)
let lemma_div248_x7 x7 =
calc (==) {
pow2 32 * (v x7 % pow2 24) * pow2 112 + v x7 / pow2 24 * pow2 168;
(==) { _ by (Tactics.norm [delta_only [`%pow2]; primops]; int_semiring ()) }
((v x7 / pow2 24) * pow2 24 + v x7 % pow2 24) * pow2 144;
(==) { FStar.Math.Lemmas.euclidean_division_definition (v x7) (pow2 24) }
v x7 * pow2 144;
}
val lemma_div248_x8: x8:uint64 ->
Lemma (pow2 32 * (v x8 % pow2 24) * pow2 168 + v x8 / pow2 24 * pow2 224 == v x8 * pow2 200)
let lemma_div248_x8 x8 =
calc (==) {
pow2 32 * (v x8 % pow2 24) * pow2 168 + v x8 / pow2 24 * pow2 224;
(==) { _ by (Tactics.norm [delta_only [`%pow2]; primops]; int_semiring ()) }
((v x8 / pow2 24) * pow2 24 + v x8 % pow2 24) * pow2 200;
(==) { FStar.Math.Lemmas.euclidean_division_definition (v x8) (pow2 24) }
v x8 * pow2 200;
}
val lemma_div248_x9: x9:uint64{v x9 < pow2 24} ->
Lemma (pow2 32 * (v x9 % pow2 24) * pow2 224 == v x9 * pow2 256)
let lemma_div248_x9 x9 =
calc (==) {
pow2 32 * (v x9 % pow2 24) * pow2 224;
(==) { Math.Lemmas.small_mod (v x9) (pow2 24) }
pow2 32 * v x9 * pow2 224;
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
v x9 * pow2 256;
}
val lemma_wide_as_nat_pow512: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 512)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
v x9 < pow2 24))
let lemma_wide_as_nat_pow512 x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert_norm (pow2 504 * pow2 8 = pow2 512);
FStar.Math.Lemmas.pow2_minus 512 504;
assert (v x9 < pow2 8);
assert_norm (pow2 8 < pow2 24)
val lemma_div248: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 512)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
let z0 = v x4 / pow2 24 + pow2 32 * (v x5 % pow2 24) in
let z1 = v x5 / pow2 24 + pow2 32 * (v x6 % pow2 24) in
let z2 = v x6 / pow2 24 + pow2 32 * (v x7 % pow2 24) in
let z3 = v x7 / pow2 24 + pow2 32 * (v x8 % pow2 24) in
let z4 = v x8 / pow2 24 + pow2 32 * (v x9 % pow2 24) in
wide_as_nat5 x / pow2 248 == z0 + z1 * pow2 56 + z2 * pow2 112 + z3 * pow2 168 + z4 * pow2 224))
#push-options "--z3rlimit 50"
let lemma_div248 x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
lemma_wide_as_nat_pow512 x;
assert (v x9 < pow2 24);
calc (==) {
(let z0 = v x4 / pow2 24 + pow2 32 * (v x5 % pow2 24) in
let z1 = v x5 / pow2 24 + pow2 32 * (v x6 % pow2 24) in
let z2 = v x6 / pow2 24 + pow2 32 * (v x7 % pow2 24) in
let z3 = v x7 / pow2 24 + pow2 32 * (v x8 % pow2 24) in
let z4 = v x8 / pow2 24 + pow2 32 * (v x9 % pow2 24) in
z0 + z1 * pow2 56 + z2 * pow2 112 + z3 * pow2 168 + z4 * pow2 224);
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
v x4 / pow2 24 + pow2 32 * (v x5 % pow2 24) +
v x5 / pow2 24 * pow2 56 + pow2 32 * (v x6 % pow2 24) * pow2 56 +
v x6 / pow2 24 * pow2 112 + pow2 32 * (v x7 % pow2 24) * pow2 112 +
v x7 / pow2 24 * pow2 168 + pow2 32 * (v x8 % pow2 24) * pow2 168 +
v x8 / pow2 24 * pow2 224 + pow2 32 * (v x9 % pow2 24) * pow2 224;
(==) { lemma_div248_x5 x5; lemma_div248_x6 x6 }
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 +
pow2 32 * (v x7 % pow2 24) * pow2 112 +
v x7 / pow2 24 * pow2 168 + pow2 32 * (v x8 % pow2 24) * pow2 168 +
v x8 / pow2 24 * pow2 224 + pow2 32 * (v x9 % pow2 24) * pow2 224;
(==) { lemma_div248_x7 x7; lemma_div248_x8 x8 }
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 +
pow2 32 * (v x9 % pow2 24) * pow2 224;
(==) { lemma_div248_x9 x9 }
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256;
(==) { lemma_div248_aux x }
wide_as_nat5 x / pow2 248;
}
#pop-options
val lemma_add_modq5:
x:qelem5
-> y:qelem5
-> t:qelem5 ->
Lemma
(requires
qelem_fits5 x (1, 1, 1, 1, 1) /\
qelem_fits5 y (1, 1, 1, 1, 1) /\
qelem_fits5 t (1, 1, 1, 1, 1) /\
as_nat5 x < S.q /\ as_nat5 y < S.q /\
as_nat5 t == as_nat5 x + as_nat5 y)
(ensures
(let res = if as_nat5 t >= S.q then as_nat5 t - S.q else as_nat5 t in
res < S.q /\ res == (as_nat5 x + as_nat5 y) % S.q))
let lemma_add_modq5 x y t =
assert (as_nat5 t == as_nat5 x + as_nat5 y);
let res = if as_nat5 t >= S.q then as_nat5 t - S.q else as_nat5 t in
assert (res < S.q);
if as_nat5 t >= S.q then (
FStar.Math.Lemmas.sub_div_mod_1 (as_nat5 t) S.q;
assert (res % S.q == as_nat5 t % S.q))
else
assert (res % S.q == as_nat5 t % S.q);
FStar.Math.Lemmas.small_mod res S.q
val lemma_wide_as_nat_pow528: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 528)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
v x9 < pow2 40))
let lemma_wide_as_nat_pow528 x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert_norm (pow2 504 * pow2 24 = pow2 528);
FStar.Math.Lemmas.pow2_minus 528 504;
assert (v x9 < pow2 24);
assert_norm (pow2 24 < pow2 40)
#push-options "--z3cliopt smt.arith.nl=false"
val lemma_div264_aux: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 528)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
wide_as_nat5 x / pow2 264 ==
v x4 / pow2 40 + v x5 * pow2 16 + v x6 * pow2 72 + v x7 * pow2 128 + v x8 * pow2 184 + v x9 * pow2 240))
let lemma_div264_aux x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert_norm (pow2 264 == pow2 224 * pow2 40);
assert_norm (pow2 56 == pow2 16 * pow2 40);
assert_norm (pow2 112 == pow2 72 * pow2 40);
assert_norm (pow2 168 == pow2 128 * pow2 40);
assert_norm (pow2 224 == pow2 184 * pow2 40);
assert_norm (pow2 280 == pow2 240 * pow2 40);
assert_norm (0 < pow2 40);
calc (==) {
wide_as_nat5 x / pow2 264;
(==) { FStar.Math.Lemmas.division_multiplication_lemma (wide_as_nat5 x) (pow2 224) (pow2 40) }
(wide_as_nat5 x / pow2 224) / pow2 40;
(==) { lemma_div224 x }
(v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280) / pow2 40;
(==) { _ by (Tactics.mapply (`feq #int #int (fun x -> x / pow2 40)); int_semiring ()) }
(v x4 + (v x5 * pow2 16 + v x6 * pow2 72 + v x7 * pow2 128 + v x8 * pow2 184 + v x9 * pow2 240) * pow2 40) / pow2 40;
(==) { FStar.Math.Lemmas.lemma_div_plus (v x4) (v x5 * pow2 16 + v x6 * pow2 72 + v x7 * pow2 128 + v x8 * pow2 184 + v x9 * pow2 240) (pow2 40) }
v x4 / pow2 40 + v x5 * pow2 16 + v x6 * pow2 72 + v x7 * pow2 128 + v x8 * pow2 184 + v x9 * pow2 240;
}
val lemma_div264_x5: x5:uint64 ->
Lemma (pow2 16 * (v x5 % pow2 40) + v x5 / pow2 40 * pow2 56 == v x5 * pow2 16)
let lemma_div264_x5 x5 =
assert_norm (0 < pow2 24);
calc (==) {
pow2 16 * (v x5 % pow2 40) + v x5 / pow2 40 * pow2 56;
(==) { _ by (Tactics.norm [delta_only [`%pow2]; primops]; int_semiring ()) }
((v x5 / pow2 40) * pow2 40 + v x5 % pow2 40) * pow2 16;
(==) { FStar.Math.Lemmas.euclidean_division_definition (v x5) (pow2 40) }
v x5 * pow2 16;
}
val lemma_div264_x6: x6:uint64 ->
Lemma (pow2 16 * (v x6 % pow2 40) * pow2 56 + v x6 / pow2 40 * pow2 112 == v x6 * pow2 72)
let lemma_div264_x6 x6 =
calc (==) {
pow2 16 * (v x6 % pow2 40) * pow2 56 + v x6 / pow2 40 * pow2 112;
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
((v x6 / pow2 40) * pow2 40 + v x6 % pow2 40) * pow2 72;
(==) { Math.Lemmas.euclidean_division_definition (v x6) (pow2 40) }
v x6 * pow2 72;
}
val lemma_div264_x7: x7:uint64 ->
Lemma (pow2 16 * (v x7 % pow2 40) * pow2 112 + v x7 / pow2 40 * pow2 168 == v x7 * pow2 128)
let lemma_div264_x7 x7 =
calc (==) {
pow2 16 * (v x7 % pow2 40) * pow2 112 + v x7 / pow2 40 * pow2 168;
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
((v x7 / pow2 40) * pow2 40 + v x7 % pow2 40) * pow2 128;
(==) { Math.Lemmas.euclidean_division_definition (v x7) (pow2 40) }
v x7 * pow2 128;
}
val lemma_div264_x8: x8:uint64 ->
Lemma (pow2 16 * (v x8 % pow2 40) * pow2 168 + v x8 / pow2 40 * pow2 224 == v x8 * pow2 184)
let lemma_div264_x8 x8 =
calc (==) {
pow2 16 * (v x8 % pow2 40) * pow2 168 + v x8 / pow2 40 * pow2 224;
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
((v x8 / pow2 40) * pow2 40 + v x8 % pow2 40) * pow2 184;
(==) { Math.Lemmas.euclidean_division_definition (v x8) (pow2 40) }
v x8 * pow2 184;
}
val lemma_div264_x9: x9:uint64{v x9 < pow2 40} ->
Lemma (pow2 16 * (v x9 % pow2 40) * pow2 224 == v x9 * pow2 240)
let lemma_div264_x9 x9 =
calc (==) {
pow2 16 * (v x9 % pow2 40) * pow2 224;
(==) { Math.Lemmas.small_mod (v x9) (pow2 40) }
pow2 16 * v x9 * pow2 224;
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
v x9 * pow2 240;
}
val lemma_div264: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 528)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
let z0 = v x4 / pow2 40 + pow2 16 * (v x5 % pow2 40) in
let z1 = v x5 / pow2 40 + pow2 16 * (v x6 % pow2 40) in
let z2 = v x6 / pow2 40 + pow2 16 * (v x7 % pow2 40) in
let z3 = v x7 / pow2 40 + pow2 16 * (v x8 % pow2 40) in
let z4 = v x8 / pow2 40 + pow2 16 * (v x9 % pow2 40) in
wide_as_nat5 x / pow2 264 == z0 + z1 * pow2 56 + z2 * pow2 112 + z3 * pow2 168 + z4 * pow2 224))
#push-options "--z3rlimit 50"
let lemma_div264 x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
lemma_wide_as_nat_pow528 x;
assert (v x9 < pow2 40);
calc (==) {
(let z0 = v x4 / pow2 40 + pow2 16 * (v x5 % pow2 40) in
let z1 = v x5 / pow2 40 + pow2 16 * (v x6 % pow2 40) in
let z2 = v x6 / pow2 40 + pow2 16 * (v x7 % pow2 40) in
let z3 = v x7 / pow2 40 + pow2 16 * (v x8 % pow2 40) in
let z4 = v x8 / pow2 40 + pow2 16 * (v x9 % pow2 40) in
z0 + z1 * pow2 56 + z2 * pow2 112 + z3 * pow2 168 + z4 * pow2 224);
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
v x4 / pow2 40 + pow2 16 * (v x5 % pow2 40) +
v x5 / pow2 40 * pow2 56 + pow2 16 * (v x6 % pow2 40) * pow2 56 +
v x6 / pow2 40 * pow2 112 + pow2 16 * (v x7 % pow2 40) * pow2 112 +
v x7 / pow2 40 * pow2 168 + pow2 16 * (v x8 % pow2 40) * pow2 168 +
v x8 / pow2 40 * pow2 224 + pow2 16 * (v x9 % pow2 40) * pow2 224;
(==) { lemma_div264_x5 x5; lemma_div264_x6 x6 }
v x4 / pow2 40 + v x5 * pow2 16 + v x6 * pow2 72 +
pow2 16 * (v x7 % pow2 40) * pow2 112 +
v x7 / pow2 40 * pow2 168 + pow2 16 * (v x8 % pow2 40) * pow2 168 +
v x8 / pow2 40 * pow2 224 + pow2 16 * (v x9 % pow2 40) * pow2 224;
(==) { lemma_div264_x7 x7; lemma_div264_x8 x8 }
v x4 / pow2 40 + v x5 * pow2 16 + v x6 * pow2 72 + v x7 * pow2 128 + v x8 * pow2 184 +
pow2 16 * (v x9 % pow2 40) * pow2 224;
(==) { lemma_div264_x9 x9 }
v x4 / pow2 40 + v x5 * pow2 16 + v x6 * pow2 72 + v x7 * pow2 128 + v x8 * pow2 184 + v x9 * pow2 240;
(==) { lemma_div264_aux x }
wide_as_nat5 x / pow2 264;
}
#pop-options
#pop-options // "--z3cliopt smt.arith.nl=false"
val lemma_mod_264_aux: t:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 t (1, 1, 1, 1, 1, 1, 1, 1, 1, 1))
(ensures
(let (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) = t in
(wide_as_nat5 t) % pow2 264 ==
(v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + v t4 * pow2 224) % pow2 264))
#push-options "--z3rlimit 150"
let lemma_mod_264_aux t =
let (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) = t in
let res = (t0, t1, t2, t3, t4 &. u64 0xffffffffff) in
assert_norm (pow2 16 * pow2 264 == pow2 280);
assert_norm (pow2 72 * pow2 264 == pow2 336);
assert_norm (pow2 128 * pow2 264 == pow2 392);
assert_norm (pow2 184 * pow2 264 == pow2 448);
assert_norm (pow2 240 * pow2 264 == pow2 504);
calc (==) {
(wide_as_nat5 t) % pow2 264;
(==) { }
(v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + v t4 * pow2 224 +
(v t5 * pow2 16 + v t6 * pow2 72 + v t7 * pow2 128 + v t8 * pow2 184 + v t9 * pow2 240) * pow2 264) % pow2 264;
(==) { FStar.Math.Lemmas.lemma_mod_add_distr (v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + v t4 * pow2 224)
((v t5 * pow2 16 + v t6 * pow2 72 + v t7 * pow2 128 + v t8 * pow2 184 + v t9 * pow2 240) * pow2 264) (pow2 264)}
((v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + v t4 * pow2 224) +
((v t5 * pow2 16 + v t6 * pow2 72 + v t7 * pow2 128 + v t8 * pow2 184 + v t9 * pow2 240) * pow2 264) % pow2 264) % pow2 264;
(==) { FStar.Math.Lemmas.cancel_mul_mod (v t5 * pow2 16 + v t6 * pow2 72 + v t7 * pow2 128 + v t8 * pow2 184 + v t9 * pow2 240) (pow2 264) }
(v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + v t4 * pow2 224) % pow2 264;
}
#pop-options
val lemma_as_nat_pow264: x:qelem5 ->
Lemma
(requires
(let (x0, x1, x2, x3, x4) = x in
qelem_fits5 x (1, 1, 1, 1, 1) /\
v x4 < pow2 40))
(ensures as_nat5 x < pow2 264)
let lemma_as_nat_pow264 x =
let (x0, x1, x2, x3, x4) = x in
assert_norm (pow2 40 * pow2 224 = pow2 264)
val lemma_mod_264: t:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 t (1, 1, 1, 1, 1, 1, 1, 1, 1, 1))
(ensures
(let (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) = t in
let res = (t0, t1, t2, t3, t4 &. u64 0xffffffffff) in
qelem_fits5 res (1, 1, 1, 1, 1) /\
as_nat5 res == (wide_as_nat5 t) % pow2 264))
let lemma_mod_264 t =
let (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) = t in
let t4' = t4 &. u64 0xffffffffff in
let res = (t0, t1, t2, t3, t4') in
assert_norm (pow2 40 < pow2 64);
assert_norm (pow2 40 - 1 == 0xffffffffff);
mod_mask_lemma t4 40ul;
assert (v (mod_mask #U64 #SEC 40ul) == 0xffffffffff);
assert (v (t4 &. u64 0xffffffffff) == v t4 % pow2 40);
calc (==) {
(wide_as_nat5 t) % pow2 264;
(==) { lemma_mod_264_aux t }
(v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + v t4 * pow2 224) % pow2 264;
(==) { FStar.Math.Lemmas.lemma_mod_add_distr (v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168) (v t4 * pow2 224) (pow2 264) }
(v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + (v t4 * pow2 224) % pow2 264) % pow2 264;
(==) { FStar.Math.Lemmas.pow2_multiplication_modulo_lemma_2 (v t4) 264 224 }
(v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + (v t4 % pow2 40) * pow2 224) % pow2 264;
(==) { lemma_as_nat_pow264 res; FStar.Math.Lemmas.modulo_lemma (as_nat5 res) (pow2 264) }
v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + (v t4 % pow2 40) * pow2 224;
}
val lemma_as_nat_pow264_x4: x:qelem5 ->
Lemma
(requires
qelem_fits5 x (1, 1, 1, 1, 1) /\
as_nat5 x < pow2 264)
(ensures
(let (x0, x1, x2, x3, x4) = x in
v x4 < pow2 40))
let lemma_as_nat_pow264_x4 x =
let (x0, x1, x2, x3, x4) = x in
assert_norm (pow2 40 * pow2 224 = pow2 264)
val lemma_sub_mod_264_aux:
x0:nat -> x1:nat -> x2:nat -> x3:nat -> x4:nat
-> y0:nat -> y1:nat -> y2:nat -> y3:nat -> y4:nat
-> c1:nat -> c2:nat -> c3:nat -> c4:nat -> c5:nat ->
Lemma (
x0 - y0 + c1 * pow56 +
(x1 - y1 - c1 + c2 * pow56) * pow56 +
(x2 - y2 - c2 + c3 * pow56) * pow112 +
(x3 - y3 - c3 + c4 * pow56) * pow168 +
(x4 - y4 - c4 + pow2 40 * c5) * pow224 ==
(x0 + x1 * pow2 56 + x2 * pow2 112 + x3 * pow2 168 + x4 * pow2 224) -
(y0 + y1 * pow2 56 + y2 * pow2 112 + y3 * pow2 168 + y4 * pow2 224) + c5 * pow2 264)
#push-options "--z3rlimit 50"
let lemma_sub_mod_264_aux x0 x1 x2 x3 x4 y0 y1 y2 y3 y4 b0 b1 b2 b3 b4 =
assert_norm (pow2 56 * pow2 56 = pow2 112);
assert_norm (pow2 56 * pow2 112 = pow2 168);
assert_norm (pow2 56 * pow2 168 = pow2 224);
assert_norm (pow2 40 * pow2 224 = pow2 264)
#pop-options
val lemma_sub_mod_264:
x:qelem5
-> y:qelem5
-> t:qelem5
-> c5:uint64 ->
Lemma
(requires
qelem_fits5 x (1, 1, 1, 1, 1) /\
qelem_fits5 y (1, 1, 1, 1, 1) /\
qelem_fits5 t (1, 1, 1, 1, 1) /\
as_nat5 x < pow2 264 /\
as_nat5 y < pow2 264 /\
as_nat5 t == as_nat5 x - as_nat5 y + v c5 * pow2 264 /\ v c5 <= 1 /\
(if v c5 = 0 then as_nat5 x >= as_nat5 y else as_nat5 x < as_nat5 y))
(ensures
(if as_nat5 x >= as_nat5 y then
as_nat5 t == as_nat5 x - as_nat5 y
else as_nat5 t == as_nat5 x - as_nat5 y + pow2 264))
#push-options "--z3rlimit 50"
let lemma_sub_mod_264 x y t c5 =
assert (if v c5 = 0 then as_nat5 x >= as_nat5 y else as_nat5 x < as_nat5 y);
assert (as_nat5 t == as_nat5 x - as_nat5 y + v c5 * pow2 264);
if as_nat5 x >= as_nat5 y then
assert (v c5 == 0 /\ as_nat5 t == as_nat5 x - as_nat5 y)
else
assert (v c5 == 1 /\ as_nat5 t == as_nat5 x - as_nat5 y + pow2 264)
#pop-options
let lemma_mul_qelem5 (x0 x1 x2 x3 x4 y0 y1 y2 y3 y4:nat) : Lemma
((x0 + x1 * pow2 56 + x2 * pow2 112 + x3 * pow2 168 + x4 * pow2 224) *
(y0 + y1 * pow2 56 + y2 * pow2 112 + y3 * pow2 168 + y4 * pow2 224) ==
x0 * y0 +
(x0 * y1 + x1 * y0) * pow56 +
(x0 * y2 + x1 * y1 + x2 * y0) * pow112 +
(x0 * y3 + x1 * y2 + x2 * y1 + x3 * y0) * pow168 +
(x0 * y4 + x1 * y3 + x2 * y2 + x3 * y1 + x4 * y0) * pow224 +
(x1 * y4 + x2 * y3 + x3 * y2 + x4 * y1) * pow280 +
(x2 * y4 + x3 * y3 + x4 * y2) * pow336 +
(x3 * y4 + x4 * y3) * pow392 +
(x4 * y4) * pow448)
=
assert ((x0 + x1 * pow2 56 + x2 * pow2 112 + x3 * pow2 168 + x4 * pow2 224) *
(y0 + y1 * pow2 56 + y2 * pow2 112 + y3 * pow2 168 + y4 * pow2 224) ==
x0 * y0 +
(x0 * y1 + x1 * y0) * pow56 +
(x0 * y2 + x1 * y1 + x2 * y0) * pow112 +
(x0 * y3 + x1 * y2 + x2 * y1 + x3 * y0) * pow168 +
(x0 * y4 + x1 * y3 + x2 * y2 + x3 * y1 + x4 * y0) * pow224 +
(x1 * y4 + x2 * y3 + x3 * y2 + x4 * y1) * pow280 +
(x2 * y4 + x3 * y3 + x4 * y2) * pow336 +
(x3 * y4 + x4 * y3) * pow392 +
(x4 * y4) * pow448)
by (Tactics.norm [zeta; iota; delta; primops]; int_semiring ())
val lemma_mul_5_low_264:
x1:nat -> x2:nat -> x3:nat -> x4:nat -> x5:nat ->
y1:nat -> y2:nat -> y3:nat -> y4:nat -> y5:nat ->
Lemma (
(x1 * y1) >= 0
/\ (x2 * y1 + x1 * y2 + ((x1 * y1) / pow2 56)) >= 0
/\ (x3 * y1 + x2 * y2 + x1 * y3 + ((x2 * y1 + x1 * y2 + ((x1 * y1) / pow2 56)) / pow2 56)) >= 0
/\ (x4 * y1 + x3 * y2 + x2 * y3 + x1 * y4 + ((x3 * y1 + x2 * y2 + x1 * y3 + ((x2 * y1 + x1 * y2 + ((x1 * y1) / pow2 56)) / pow2 56)) / pow2 56)) >= 0
/\ (
let a0 = (x1 * y1) % pow2 56 in
let a1 = ((x2 * y1 + x1 * y2 + ((x1 * y1) / pow2 56)) % pow2 56) in
let a2 = ((x3 * y1 + x2 * y2 + x1 * y3 + ((x2 * y1 + x1 * y2 + ((x1 * y1) / pow2 56)) / pow2 56)) % pow2 56) in
let a3 = ((x4 * y1 + x3 * y2 + x2 * y3 + x1 * y4 + ((x3 * y1 + x2 * y2 + x1 * y3 + ((x2 * y1 + x1 * y2 + ((x1 * y1) / pow2 56)) / pow2 56)) / pow2 56)) % pow2 56) in
let a4 = (x5 * y1 + x4 * y2 + x3 * y3 + x2 * y4 + x1 * y5 + ((x4 * y1 + x3 * y2 + x2 * y3 + x1 * y4 + ((x3 * y1 + x2 * y2 + x1 * y3 + ((x2 * y1 + x1 * y2 + ((x1 * y1) / pow2 56)) / pow2 56)) / pow2 56)) / pow2 56)) in
((x1 + pow2 56 * x2 + pow2 112 * x3 + pow2 168 * x4 + pow2 224 * x5)
* (y1 + pow2 56 * y2 + pow2 112 * y3 + pow2 168 * y4 + pow2 224 * y5)) % pow2 264
== a0 + pow2 56 * a1 + pow2 112 * a2 + pow2 168 * a3 + pow2 224 * (a4 % pow2 40)))
private let lemma_mul_nat_is_nat (a:nat) (b:nat) : Lemma (a*b >= 0) = ()
private let lemma_div_nat_is_nat (a:nat) (b:pos) : Lemma (a/b >= 0) = ()
private
val lemma_mul_5''':
x1:nat -> x2:nat -> x3:nat -> x4:nat -> x5:nat ->
y1:nat -> y2:nat -> y3:nat -> y4:nat -> y5:nat ->
Lemma (((x1 + pow2 56 * x2 + pow2 112 * x3 + pow2 168 * x4 + pow2 224 * x5)
* (y1 + pow2 56 * y2 + pow2 112 * y3 + pow2 168 * y4 + pow2 224 * y5)) % pow2 264
==
(x1 * y1
+ pow2 56 * (x2 * y1 + x1 * y2)
+ pow2 112 * (x3 * y1 + x2 * y2 + x1 * y3)
+ pow2 168 * (x4 * y1 + x3 * y2 + x2 * y3 + x1 * y4)
+ pow2 224 * (x5 * y1 + x4 * y2 + x3 * y3 + x2 * y4 + x1 * y5)) % pow2 264)
let lemma_mul_5''' x1 x2 x3 x4 x5 y1 y2 y3 y4 y5 =
calc (==) {
((x1 + pow2 56 * x2 + pow2 112 * x3 + pow2 168 * x4 + pow2 224 * x5)
* (y1 + pow2 56 * y2 + pow2 112 * y3 + pow2 168 * y4 + pow2 224 * y5)) % pow2 264;
(==) { _ by (Tactics.mapply (`feq #int #int (fun x -> x % pow2 264));
Tactics.norm [zeta; iota; delta; primops];
int_semiring ()) }
(x1 * y1
+ pow2 56 * (x2 * y1 + x1 * y2)
+ pow2 112 * (x3 * y1 + x2 * y2 + x1 * y3)
+ pow2 168 * (x4 * y1 + x3 * y2 + x2 * y3 + x1 * y4)
+ pow2 224 * (x5 * y1 + x4 * y2 + x3 * y3 + x2 * y4 + x1 * y5)
+ (pow2 16 * x2 * y5 +
pow2 16 * x3 * y4 + pow2 72 * x3 * y5 +
pow2 16 * x4 * y3 + pow2 72 * x4 * y4 + pow2 128 * x4 * y5 +
pow2 16 * x5 * y2 + pow2 72 * x5 * y3 + pow2 128 * x5 * y4 + pow2 184 * x5 * y5) * pow2 264) % pow2 264;
(==) { _ by (Tactics.mapply (`eq_eq2); Tactics.mapply (`Math.Lemmas.lemma_mod_plus)) }
(x1 * y1
+ pow2 56 * (x2 * y1 + x1 * y2)
+ pow2 112 * (x3 * y1 + x2 * y2 + x1 * y3)
+ pow2 168 * (x4 * y1 + x3 * y2 + x2 * y3 + x1 * y4)
+ pow2 224 * (x5 * y1 + x4 * y2 + x3 * y3 + x2 * y4 + x1 * y5)) % pow2 264;
}
private val lemma_mod_264'':
a0:nat -> a1:nat-> a2:nat -> a3:nat -> a4:nat ->
Lemma
(requires a0 < pow56 /\ a1 < pow56 /\ a2 < pow56 /\ a3 < pow56)
(ensures a0 + pow2 56 * a1 + pow2 112 * a2 + pow2 168 * a3 + pow2 224 * (a4 % pow2 40) < pow2 264)
let lemma_mod_264'' a0 a1 a2 a3 a4 =
assert_norm(pow2 40 = 0x10000000000);
assert_norm(pow2 56 = 0x100000000000000);
assert_norm(pow2 112 = 0x10000000000000000000000000000);
assert_norm(pow2 168 = 0x1000000000000000000000000000000000000000000);
assert_norm(pow2 224 = 0x100000000000000000000000000000000000000000000000000000000);
assert_norm(pow2 264 = 0x1000000000000000000000000000000000000000000000000000000000000000000)
private val lemma_mod_264':
a0:nat -> a1:nat-> a2:nat -> a3:nat -> a4:nat ->
Lemma
(requires a0 < pow56 /\ a1 < pow56 /\ a2 < pow56 /\ a3 < pow56)
(ensures (a0
+ pow2 56 * a1
+ pow2 112 * a2
+ pow2 168 * a3
+ pow2 224 * a4) % pow2 264 =
a0
+ pow2 56 * a1
+ pow2 112 * a2
+ pow2 168 * a3 | {
"checked_file": "/",
"dependencies": [
"Spec.Ed25519.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.BignumQ.Definitions.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Tactics.CanonCommSemiring.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.BignumQ.Lemmas.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.CanonCommSemiring",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.BignumQ.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.Ed25519",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.CanonCommSemiring",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.BignumQ",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.BignumQ",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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 | a0: Prims.nat -> a1: Prims.nat -> a2: Prims.nat -> a3: Prims.nat -> a4: Prims.nat
-> FStar.Pervasives.Lemma
(requires
a0 < Hacl.Spec.BignumQ.Definitions.pow56 /\ a1 < Hacl.Spec.BignumQ.Definitions.pow56 /\
a2 < Hacl.Spec.BignumQ.Definitions.pow56 /\ a3 < Hacl.Spec.BignumQ.Definitions.pow56)
(ensures
(a0 + Prims.pow2 56 * a1 + Prims.pow2 112 * a2 + Prims.pow2 168 * a3 + Prims.pow2 224 * a4) %
Prims.pow2 264 =
a0 + Prims.pow2 56 * a1 + Prims.pow2 112 * a2 + Prims.pow2 168 * a3 +
Prims.pow2 224 * (a4 % Prims.pow2 40)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.nat",
"FStar.Math.Lemmas.modulo_lemma",
"Prims.op_Addition",
"FStar.Mul.op_Star",
"Prims.pow2",
"Prims.op_Modulus",
"Prims.unit",
"Hacl.Spec.BignumQ.Lemmas.lemma_mod_264''",
"FStar.Math.Lemmas.pow2_multiplication_modulo_lemma_2",
"FStar.Math.Lemmas.lemma_mod_plus_distr_l",
"FStar.Pervasives.assert_norm",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int"
] | [] | true | false | true | false | false | let lemma_mod_264' a0 a1 a2 a3 a4 =
| assert_norm (pow2 56 = 0x100000000000000);
assert_norm (pow2 112 = 0x10000000000000000000000000000);
assert_norm (pow2 168 = 0x1000000000000000000000000000000000000000000);
assert_norm (pow2 224 = 0x100000000000000000000000000000000000000000000000000000000);
Math.Lemmas.lemma_mod_plus_distr_l (pow2 224 * a4)
(a0 + pow2 56 * a1 + pow2 112 * a2 + pow2 168 * a3)
(pow2 264);
Math.Lemmas.pow2_multiplication_modulo_lemma_2 a4 264 224;
lemma_mod_264'' a0 a1 a2 a3 a4;
Math.Lemmas.modulo_lemma (a0 + pow2 56 * a1 + pow2 112 * a2 + pow2 168 * a3 +
pow2 224 * (a4 % pow2 40))
(pow2 264) | false |
Steel.ST.SeqMatch.fst | Steel.ST.SeqMatch.seq_seq_match_item_match_option_index | val seq_seq_match_item_match_option_index
(#opened: _)
(#t1 #t2: Type)
(p: (t1 -> t2 -> vprop))
(s1: Seq.seq t1)
(s2: Seq.seq (option t2))
(i j: nat)
(k: nat{i <= j /\ j < k /\ (j < Seq.length s2 ==> Some? (Seq.index s2 j))})
: STGhostT (squash (j < Seq.length s1 /\ j < Seq.length s2 /\ Some? (Seq.index s2 j)))
opened
(seq_seq_match (item_match_option p) s1 s2 i k)
(fun _ ->
(seq_seq_match (item_match_option p) s1 (Seq.upd s2 j None) i k)
`star`
(p (Seq.index s1 j) (Some?.v (Seq.index s2 j)))) | val seq_seq_match_item_match_option_index
(#opened: _)
(#t1 #t2: Type)
(p: (t1 -> t2 -> vprop))
(s1: Seq.seq t1)
(s2: Seq.seq (option t2))
(i j: nat)
(k: nat{i <= j /\ j < k /\ (j < Seq.length s2 ==> Some? (Seq.index s2 j))})
: STGhostT (squash (j < Seq.length s1 /\ j < Seq.length s2 /\ Some? (Seq.index s2 j)))
opened
(seq_seq_match (item_match_option p) s1 s2 i k)
(fun _ ->
(seq_seq_match (item_match_option p) s1 (Seq.upd s2 j None) i k)
`star`
(p (Seq.index s1 j) (Some?.v (Seq.index s2 j)))) | let seq_seq_match_item_match_option_index
(#opened: _)
(#t1 #t2: Type)
(p: t1 -> t2 -> vprop)
(s1: Seq.seq t1)
(s2: Seq.seq (option t2))
(i j: nat)
(k: nat {
i <= j /\ j < k /\
(j < Seq.length s2 ==> Some? (Seq.index s2 j))
})
: STGhostT (squash (j < Seq.length s1 /\ j < Seq.length s2 /\ Some? (Seq.index s2 j))) opened
(seq_seq_match (item_match_option p) s1 s2 i k)
(fun _ ->
seq_seq_match (item_match_option p) s1 (Seq.upd s2 j None) i k `star`
p (Seq.index s1 j) (Some?.v (Seq.index s2 j))
)
= seq_seq_match_length (item_match_option p) s1 s2 i k;
on_range_get
(seq_seq_match_item (item_match_option p) s1 s2)
i j (j + 1) k;
let res : squash (j < Seq.length s1 /\ j < Seq.length s2 /\ Some? (Seq.index s2 j)) = () in
rewrite
(seq_seq_match_item (item_match_option p) s1 s2 j)
(p (Seq.index s1 j) (Some?.v (Seq.index s2 j)));
rewrite
emp
(seq_seq_match_item (item_match_option p) s1 (Seq.upd s2 j None) j);
seq_seq_match_weaken
(item_match_option p) (item_match_option p) (fun _ _ -> noop ())
s1 s1
s2 (Seq.upd s2 j None)
i j;
seq_seq_match_weaken
(item_match_option p) (item_match_option p) (fun _ _ -> noop ())
s1 s1
s2 (Seq.upd s2 j None)
(j + 1) k;
on_range_put
(seq_seq_match_item (item_match_option p) s1 (Seq.upd s2 j None))
i j j (j + 1) k;
res | {
"file_name": "lib/steel/Steel.ST.SeqMatch.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 5,
"end_line": 792,
"start_col": 0,
"start_line": 751
} | module Steel.ST.SeqMatch
include Steel.ST.OnRange
open Steel.ST.GenElim
module Seq = FStar.Seq
module SZ = FStar.SizeT
(* `seq_list_match` describes how to match a sequence of low-level
values (the low-level contents of an array) with a list of high-level
values. `seq_list_match` is carefully designed to be usable within
(mutually) recursive definitions of matching functions on the type of
high-level values. *)
[@@__reduce__]
let seq_list_match_nil0
(#t: Type)
(c: Seq.seq t)
: Tot vprop
= pure (c `Seq.equal` Seq.empty)
[@@__reduce__]
let seq_list_match_cons0
(#t #t': Type)
(c: Seq.seq t)
(l: list t' { Cons? l })
(item_match: (t -> (v': t' { v' << l }) -> vprop))
(seq_list_match: (Seq.seq t -> (v': list t') -> (raw_data_item_match: (t -> (v'': t' { v'' << v' }) -> vprop) { v' << l }) ->
vprop))
: Tot vprop
= exists_ (fun (c1: t) -> exists_ (fun (c2: Seq.seq t) ->
item_match c1 (List.Tot.hd l) `star`
seq_list_match c2 (List.Tot.tl l) item_match `star`
pure (c `Seq.equal` Seq.cons c1 c2)
))
let rec seq_list_match
(#t #t': Type)
(c: Seq.seq t)
(v: list t')
(item_match: (t -> (v': t' { v' << v }) -> vprop))
: Tot vprop
(decreases v)
= if Nil? v
then seq_list_match_nil0 c
else seq_list_match_cons0 c v item_match seq_list_match
let seq_list_match_cons_eq
(#t #t': Type)
(c: Seq.seq t)
(v: list t')
(item_match: (t -> (v': t' { v' << v }) -> vprop))
: Lemma
(requires (Cons? v))
(ensures (
seq_list_match c v item_match ==
seq_list_match_cons0 c v item_match seq_list_match
))
= let a :: q = v in
assert_norm (seq_list_match c (a :: q) item_match ==
seq_list_match_cons0 c (a :: q) item_match seq_list_match
)
let seq_list_match_nil
(#opened: _)
(#t #t': Type)
(c: Seq.seq t)
(v: list t')
(item_match: (t -> (v': t' { v' << v }) -> vprop))
: STGhost unit opened
emp
(fun _ -> seq_list_match c v item_match)
(c `Seq.equal` Seq.empty /\
Nil? v)
(fun _ -> True)
= noop ();
rewrite
(seq_list_match_nil0 c)
(seq_list_match c v item_match)
let list_cons_precedes
(#t: Type)
(a: t)
(q: list t)
: Lemma
((a << a :: q) /\ (q << a :: q))
[SMTPat (a :: q)]
= assert (List.Tot.hd (a :: q) << (a :: q));
assert (List.Tot.tl (a :: q) << (a :: q))
let seq_list_match_cons_intro
(#opened: _)
(#t #t': Type)
(a: t)
(a' : t')
(c: Seq.seq t)
(v: list t')
(item_match: (t -> (v': t' { v' << a' :: v }) -> vprop))
: STGhostT unit opened
(item_match a a' `star` seq_list_match c v item_match)
(fun _ -> seq_list_match (Seq.cons a c) (a' :: v) item_match)
= seq_list_match_cons_eq (Seq.cons a c) (a' :: v) item_match;
noop ();
rewrite
(seq_list_match_cons0 (Seq.cons a c) (a' :: v) item_match seq_list_match)
(seq_list_match (Seq.cons a c) (a' :: v) item_match)
let seq_list_match_cons_elim
(#opened: _)
(#t #t': Type)
(c: Seq.seq t)
(v: list t' { Cons? v \/ Seq.length c > 0 })
(item_match: (t -> (v': t' { v' << v }) -> vprop))
: STGhostT (squash (Cons? v /\ Seq.length c > 0)) opened
(seq_list_match c v item_match)
(fun _ -> item_match (Seq.head c) (List.Tot.hd v) `star`
seq_list_match (Seq.tail c) (List.Tot.tl v) item_match)
= if Nil? v
then begin
rewrite
(seq_list_match c v item_match)
(seq_list_match_nil0 c);
let _ = gen_elim () in
assert False;
rewrite // by contradiction
emp
(item_match (Seq.head c) (List.Tot.hd v) `star`
seq_list_match (Seq.tail c) (List.Tot.tl v) item_match)
end else begin
seq_list_match_cons_eq c v item_match;
noop ();
rewrite
(seq_list_match c v item_match)
(seq_list_match_cons0 c v item_match seq_list_match);
let _ = gen_elim () in
let prf : squash (Cons? v /\ Seq.length c > 0) = () in
let c1 = vpattern (fun c1 -> item_match c1 (List.Tot.hd v)) in
let c2 = vpattern (fun c2 -> seq_list_match c2 (List.Tot.tl v) item_match) in
Seq.lemma_cons_inj c1 (Seq.head c) c2 (Seq.tail c);
vpattern_rewrite (fun c1 -> item_match c1 (List.Tot.hd v)) (Seq.head c);
vpattern_rewrite (fun c2 -> seq_list_match c2 (List.Tot.tl v) item_match) (Seq.tail c);
prf
end
// this one cannot be proven with seq_seq_match because of the << refinement in the type of item_match
let rec seq_list_match_weaken
(#opened: _)
(#t #t': Type)
(c: Seq.seq t)
(v: list t')
(item_match1 item_match2: (t -> (v': t' { v' << v }) -> vprop))
(prf: (
(#opened: _) ->
(c': t) ->
(v': t' { v' << v }) ->
STGhostT unit opened
(item_match1 c' v')
(fun _ -> item_match2 c' v')
))
: STGhostT unit opened
(seq_list_match c v item_match1)
(fun _ -> seq_list_match c v item_match2)
(decreases v)
= if Nil? v
then
rewrite (seq_list_match c v item_match1) (seq_list_match c v item_match2)
else begin
let _ : squash (Cons? v) = () in
seq_list_match_cons_eq c v item_match1;
seq_list_match_cons_eq c v item_match2;
rewrite
(seq_list_match c v item_match1)
(seq_list_match_cons0 c v item_match1 seq_list_match);
let _ = gen_elim () in
prf _ _;
seq_list_match_weaken _ (List.Tot.tl v) item_match1 item_match2 prf;
rewrite
(seq_list_match_cons0 c v item_match2 seq_list_match)
(seq_list_match c v item_match2)
end
(* `seq_seq_match` describes how to match a sequence of low-level
values (the low-level contents of an array) with a sequence of high-level
values. Contrary to `seq_list_match`, `seq_seq_match` is not meant to be usable within
(mutually) recursive definitions of matching functions on the type of
high-level values, because no lemma ensures that `Seq.index s i << s` *)
let seq_seq_match_item
(#t1 #t2: Type)
(p: t1 -> t2 -> vprop)
(c: Seq.seq t1)
(l: Seq.seq t2)
(i: nat)
: Tot vprop
= if i < Seq.length c && i < Seq.length l
then
p (Seq.index c i) (Seq.index l i)
else
pure (squash False)
let seq_seq_match_item_tail
(#t1 #t2: Type)
(p: t1 -> t2 -> vprop)
(c: Seq.seq t1)
(l: Seq.seq t2)
(delta: nat)
(i: nat)
: Lemma
(requires (
i + delta <= Seq.length c /\
i + delta <= Seq.length l
))
(ensures (
seq_seq_match_item p (Seq.slice c delta (Seq.length c)) (Seq.slice l delta (Seq.length l)) i ==
seq_seq_match_item p c l (i + delta)
))
= ()
[@@__reduce__]
let seq_seq_match
(#t1 #t2: Type)
(p: t1 -> t2 -> vprop)
(c: Seq.seq t1)
(l: Seq.seq t2)
(i j: nat)
: Tot vprop
= on_range (seq_seq_match_item p c l) i j
let seq_seq_match_length
(#opened: _)
(#t1 #t2: Type)
(p: t1 -> t2 -> vprop)
(s1: Seq.seq t1)
(s2: Seq.seq t2)
(i j: nat)
: STGhost unit opened
(seq_seq_match p s1 s2 i j)
(fun _ -> seq_seq_match p s1 s2 i j)
True
(fun _ -> i <= j /\ (i == j \/ (j <= Seq.length s1 /\ j <= Seq.length s2)))
= on_range_le (seq_seq_match_item p s1 s2) i j;
if i = j
then noop ()
else begin
let j' = j - 1 in
if j' < Seq.length s1 && j' < Seq.length s2
then noop ()
else begin
on_range_unsnoc
(seq_seq_match_item p s1 s2)
i j' j;
rewrite
(seq_seq_match_item p _ _ _)
(pure (squash False));
let _ = gen_elim () in
rewrite
(seq_seq_match p s1 s2 i j')
(seq_seq_match p s1 s2 i j) // by contradiction
end
end
let seq_seq_match_weaken
(#opened: _)
(#t1 #t2: Type)
(p p': t1 -> t2 -> vprop)
(w: ((x1: t1) -> (x2: t2) -> STGhostT unit opened
(p x1 x2) (fun _ -> p' x1 x2)
))
(c1 c1': Seq.seq t1)
(c2 c2': Seq.seq t2)
(i j: nat)
: STGhost unit opened
(seq_seq_match p c1 c2 i j)
(fun _ -> seq_seq_match p' c1' c2' i j)
(i <= j /\ (i == j \/ (
j <= Seq.length c1 /\ j <= Seq.length c2 /\
j <= Seq.length c1' /\ j <= Seq.length c2' /\
Seq.slice c1 i j `Seq.equal` Seq.slice c1' i j /\
Seq.slice c2 i j `Seq.equal` Seq.slice c2' i j
)))
(fun _ -> True)
=
on_range_weaken
(seq_seq_match_item p c1 c2)
(seq_seq_match_item p' c1' c2')
i j
(fun k ->
rewrite (seq_seq_match_item p c1 c2 k) (p (Seq.index (Seq.slice c1 i j) (k - i)) (Seq.index (Seq.slice c2 i j) (k - i)));
w _ _;
rewrite (p' _ _) (seq_seq_match_item p' c1' c2' k)
)
let seq_seq_match_weaken_with_implies
(#opened: _)
(#t1 #t2: Type)
(p: t1 -> t2 -> vprop)
(c1 c1': Seq.seq t1)
(c2 c2': Seq.seq t2)
(i j: nat)
: STGhost unit opened
(seq_seq_match p c1 c2 i j)
(fun _ -> seq_seq_match p c1' c2' i j `star`
(seq_seq_match p c1' c2' i j `implies_` seq_seq_match p c1 c2 i j)
)
(i <= j /\ (i == j \/ (
j <= Seq.length c1 /\ j <= Seq.length c2 /\
j <= Seq.length c1' /\ j <= Seq.length c2' /\
Seq.slice c1 i j `Seq.equal` Seq.slice c1' i j /\
Seq.slice c2 i j `Seq.equal` Seq.slice c2' i j
)))
(fun _ -> True)
= seq_seq_match_weaken
p p (fun _ _ -> noop ())
c1 c1'
c2 c2'
i j;
intro_implies
(seq_seq_match p c1' c2' i j)
(seq_seq_match p c1 c2 i j)
emp
(fun _ ->
seq_seq_match_weaken
p p (fun _ _ -> noop ())
c1' c1
c2' c2
i j
)
(* Going between `seq_list_match` and `seq_seq_match` *)
let seq_seq_match_tail_elim
(#t1 #t2: Type)
(#opened: _)
(p: t1 -> t2 -> vprop)
(c: Seq.seq t1)
(l: Seq.seq (t2))
(delta: nat {
delta <= Seq.length c /\
delta <= Seq.length l
})
(i j: nat)
: STGhostT unit opened
(seq_seq_match p (Seq.slice c delta (Seq.length c)) (Seq.slice l delta (Seq.length l)) i j)
(fun _ -> seq_seq_match p c l (i + delta) (j + delta))
= on_range_le (seq_seq_match_item p _ _) _ _;
on_range_weaken_and_shift
(seq_seq_match_item p (Seq.slice c delta (Seq.length c)) (Seq.slice l delta (Seq.length l)))
(seq_seq_match_item p c l)
delta
i j
(fun k ->
if k < Seq.length c - delta && k < Seq.length l - delta
then begin
seq_seq_match_item_tail p c l delta k;
rewrite
(seq_seq_match_item p (Seq.slice c delta (Seq.length c)) (Seq.slice l delta (Seq.length l)) k)
(seq_seq_match_item p c l (k + delta))
end else begin
rewrite
(seq_seq_match_item p (Seq.slice c delta (Seq.length c)) (Seq.slice l delta (Seq.length l)) k)
(pure (squash False));
let _ = gen_elim () in
rewrite
emp
(seq_seq_match_item p c l (k + delta)) // by contradiction
end
)
(i + delta) (j + delta)
let seq_seq_match_tail_intro
(#t1 #t2: Type)
(#opened: _)
(p: t1 -> t2 -> vprop)
(c: Seq.seq t1)
(l: Seq.seq t2)
(delta: nat {
delta <= Seq.length c /\
delta <= Seq.length l
})
(i: nat {
delta <= i
})
(j: nat)
: STGhostT (squash (i <= j)) opened
(seq_seq_match p c l i j)
(fun _ -> seq_seq_match p (Seq.slice c delta (Seq.length c)) (Seq.slice l delta (Seq.length l)) (i - delta) (j - delta))
= on_range_le (seq_seq_match_item p _ _) _ _;
on_range_weaken_and_shift
(seq_seq_match_item p c l)
(seq_seq_match_item p (Seq.slice c delta (Seq.length c)) (Seq.slice l delta (Seq.length l)))
(0 - delta)
i j
(fun k ->
if k < Seq.length c && k < Seq.length l
then begin
seq_seq_match_item_tail p c l delta (k - delta);
rewrite
(seq_seq_match_item p c l k)
(seq_seq_match_item p (Seq.slice c delta (Seq.length c)) (Seq.slice l delta (Seq.length l)) (k + (0 - delta)))
end else begin
rewrite
(seq_seq_match_item p c l k)
(pure (squash False));
let _ = gen_elim () in
rewrite
emp
(seq_seq_match_item p (Seq.slice c delta (Seq.length c)) (Seq.slice l delta (Seq.length l)) (k + (0 - delta))) // by contradiction
end
)
(i - delta) (j - delta)
let rec seq_seq_match_seq_list_match
(#opened: _)
(#t1 #t2: Type)
(p: t1 -> t2 -> vprop)
(c: Seq.seq t1)
(l: list t2)
: STGhost unit opened
(seq_seq_match p c (Seq.seq_of_list l) 0 (List.Tot.length l))
(fun _ -> seq_list_match c l p)
(Seq.length c == List.Tot.length l)
(fun _ -> True)
(decreases l)
= match l with
| [] ->
drop (seq_seq_match p _ _ _ _);
rewrite
(seq_list_match_nil0 c)
(seq_list_match c l p)
| a :: q ->
Seq.lemma_seq_of_list_induction (a :: q);
seq_list_match_cons_eq c l p;
on_range_uncons
(seq_seq_match_item p _ _)
_ 1 _;
rewrite
(seq_seq_match_item p _ _ _)
(p (Seq.head c) (List.Tot.hd l));
let _ = seq_seq_match_tail_intro
p _ _ 1 _ _
in
rewrite
(seq_seq_match p _ _ _ _)
(seq_seq_match p (Seq.tail c) (Seq.seq_of_list (List.Tot.tl l)) 0 (List.Tot.length (List.Tot.tl l)));
seq_seq_match_seq_list_match p _ (List.Tot.tl l);
rewrite
(seq_list_match_cons0 c l p seq_list_match)
(seq_list_match c l p)
let rec seq_list_match_seq_seq_match
(#opened: _)
(#t1 #t2: Type)
(p: t1 -> t2 -> vprop)
(c: Seq.seq t1)
(l: list t2)
: STGhost unit opened
(seq_list_match c l p)
(fun _ -> seq_seq_match p c (Seq.seq_of_list l) 0 (List.Tot.length l))
True
(fun _ -> Seq.length c == List.Tot.length l)
(decreases l)
= match l with
| [] ->
rewrite
(seq_list_match c l p)
(seq_list_match_nil0 c);
let _ = gen_elim () in
on_range_empty
(seq_seq_match_item p c (Seq.seq_of_list l))
0
(List.Tot.length l)
| a :: q ->
let _l_nonempty : squash (Cons? l) = () in
Seq.lemma_seq_of_list_induction (a :: q);
seq_list_match_cons_eq c l p;
noop ();
rewrite
(seq_list_match c l p)
(seq_list_match_cons0 c l p seq_list_match);
let _ = gen_elim () in
let a' = vpattern (fun a' -> p a' _) in
let c' = vpattern (fun c' -> seq_list_match c' _ _) in
Seq.lemma_cons_inj (Seq.head c) a' (Seq.tail c) c';
assert (a' == Seq.head c);
assert (c' == Seq.tail c);
noop ();
seq_list_match_seq_seq_match p _ _;
rewrite
(seq_seq_match p _ _ _ _)
(seq_seq_match p (Seq.slice c 1 (Seq.length c)) (Seq.slice (Seq.seq_of_list l) 1 (Seq.length (Seq.seq_of_list l))) 0 (List.Tot.length (List.Tot.tl l)));
let _ = seq_seq_match_tail_elim
p c (Seq.seq_of_list l) 1 0 (List.Tot.length (List.Tot.tl l))
in
rewrite
(seq_seq_match p _ _ _ _)
(seq_seq_match p c (Seq.seq_of_list l) 1 (List.Tot.length l));
rewrite
(p _ _)
(seq_seq_match_item p c (Seq.seq_of_list l) 0);
on_range_cons
(seq_seq_match_item p _ _)
0 1 (List.Tot.length l)
let seq_seq_match_seq_list_match_with_implies
(#opened: _)
(#t1 #t2: Type)
(p: t1 -> t2 -> vprop)
(c: Seq.seq t1)
(l: list t2)
: STGhost unit opened
(seq_seq_match p c (Seq.seq_of_list l) 0 (List.Tot.length l))
(fun _ -> seq_list_match c l p `star` (seq_list_match c l p `implies_` seq_seq_match p c (Seq.seq_of_list l) 0 (List.Tot.length l)))
(Seq.length c == List.Tot.length l)
(fun _ -> True)
= seq_seq_match_seq_list_match p c l;
intro_implies
(seq_list_match c l p)
(seq_seq_match p c (Seq.seq_of_list l) 0 (List.Tot.length l))
emp
(fun _ -> seq_list_match_seq_seq_match p c l)
let seq_list_match_seq_seq_match_with_implies
(#opened: _)
(#t1 #t2: Type)
(p: t1 -> t2 -> vprop)
(c: Seq.seq t1)
(l: list t2)
: STGhost unit opened
(seq_list_match c l p)
(fun _ -> seq_seq_match p c (Seq.seq_of_list l) 0 (List.Tot.length l) `star` (seq_seq_match p c (Seq.seq_of_list l) 0 (List.Tot.length l) `implies_` seq_list_match c l p))
True
(fun _ -> Seq.length c == List.Tot.length l)
= seq_list_match_seq_seq_match p c l;
intro_implies
(seq_seq_match p c (Seq.seq_of_list l) 0 (List.Tot.length l))
(seq_list_match c l p)
emp
(fun _ -> seq_seq_match_seq_list_match p c l)
let seq_list_match_length
(#opened: _)
(#t1 #t2: Type)
(p: t1 -> t2 -> vprop)
(c: Seq.seq t1)
(l: list t2)
: STGhost unit opened
(seq_list_match c l p)
(fun _ -> seq_list_match c l p)
True
(fun _ -> Seq.length c == List.Tot.length l)
= seq_list_match_seq_seq_match_with_implies p c l;
seq_seq_match_length p _ _ _ _;
elim_implies
(seq_seq_match p _ _ _ _)
(seq_list_match c l p)
let seq_list_match_index
(#opened: _)
(#t1 #t2: Type)
(p: t1 -> t2 -> vprop)
(s1: Seq.seq t1)
(s2: list t2)
(i: nat)
: STGhost (squash (i < Seq.length s1 /\ List.Tot.length s2 == Seq.length s1)) opened
(seq_list_match s1 s2 p)
(fun _ ->
p (Seq.index s1 i) (List.Tot.index s2 i) `star`
(p (Seq.index s1 i) (List.Tot.index s2 i) `implies_`
seq_list_match s1 s2 p)
)
(i < Seq.length s1 \/ i < List.Tot.length s2)
(fun _ -> True)
= seq_list_match_seq_seq_match_with_implies p s1 s2;
let res : squash (i < Seq.length s1 /\ List.Tot.length s2 == Seq.length s1) = () in
on_range_focus (seq_seq_match_item p s1 (Seq.seq_of_list s2)) 0 i (List.Tot.length s2);
rewrite_with_implies
(seq_seq_match_item p _ _ _)
(p (Seq.index s1 i) (List.Tot.index s2 i));
implies_trans
(p (Seq.index s1 i) (List.Tot.index s2 i))
(seq_seq_match_item p _ _ _)
(seq_seq_match p s1 (Seq.seq_of_list s2) 0 (List.Tot.length s2));
implies_trans
(p (Seq.index s1 i) (List.Tot.index s2 i))
(seq_seq_match p s1 (Seq.seq_of_list s2) 0 (List.Tot.length s2))
(seq_list_match s1 s2 p);
res
(* Random array access
Since `seq_list_match` is defined recursively on the list of
high-level values, it is used naturally left-to-right. By contrast,
in practice, an application may populate an array in a different
order, or even out-of-order. `seq_seq_match` supports that scenario
better, as we show below.
*)
let seq_map (#t1 #t2: Type) (f: t1 -> t2) (s: Seq.seq t1) : Tot (Seq.seq t2) =
Seq.init (Seq.length s) (fun i -> f (Seq.index s i))
let item_match_option
(#t1 #t2: Type)
(p: t1 -> t2 -> vprop)
(x1: t1)
(x2: option t2)
: Tot vprop
= match x2 with
| None -> emp
| Some x2' -> p x1 x2'
let seq_seq_match_item_match_option_elim
(#opened: _)
(#t1 #t2: Type)
(p: t1 -> t2 -> vprop)
(s1: Seq.seq t1)
(s2: Seq.seq t2)
(i j: nat)
: STGhostT unit opened
(seq_seq_match (item_match_option p) s1 (seq_map Some s2) i j)
(fun _ -> seq_seq_match p s1 s2 i j)
= on_range_weaken
(seq_seq_match_item (item_match_option p) s1 (seq_map Some s2))
(seq_seq_match_item p s1 s2)
i j
(fun k ->
rewrite
(seq_seq_match_item (item_match_option p) s1 (seq_map Some s2) k)
(seq_seq_match_item p s1 s2 k)
)
let seq_seq_match_item_match_option_intro
(#opened: _)
(#t1 #t2: Type)
(p: t1 -> t2 -> vprop)
(s1: Seq.seq t1)
(s2: Seq.seq t2)
(i j: nat)
: STGhostT unit opened
(seq_seq_match p s1 s2 i j)
(fun _ -> seq_seq_match (item_match_option p) s1 (seq_map Some s2) i j)
= on_range_weaken
(seq_seq_match_item p s1 s2)
(seq_seq_match_item (item_match_option p) s1 (seq_map Some s2))
i j
(fun k ->
rewrite
(seq_seq_match_item p s1 s2 k)
(seq_seq_match_item (item_match_option p) s1 (seq_map Some s2) k)
)
let rec seq_seq_match_item_match_option_init
(#opened: _)
(#t1 #t2: Type)
(p: t1 -> t2 -> vprop)
(s: Seq.seq t1)
: STGhostT unit opened
emp
(fun _ -> seq_seq_match (item_match_option p) s (Seq.create (Seq.length s) None) 0 (Seq.length s))
(decreases (Seq.length s))
= if Seq.length s = 0
then
on_range_empty (seq_seq_match_item (item_match_option p) s (Seq.create (Seq.length s) None)) 0 (Seq.length s)
else begin
seq_seq_match_item_match_option_init p (Seq.tail s);
on_range_weaken_and_shift
(seq_seq_match_item (item_match_option p) (Seq.tail s) (Seq.create (Seq.length (Seq.tail s)) None))
(seq_seq_match_item (item_match_option p) s (Seq.create (Seq.length s) None))
1
0
(Seq.length (Seq.tail s))
(fun k ->
rewrite
(seq_seq_match_item (item_match_option p) (Seq.tail s) (Seq.create (Seq.length (Seq.tail s)) None) k)
(seq_seq_match_item (item_match_option p) s (Seq.create (Seq.length s) None) (k + 1))
)
1
(Seq.length s);
rewrite
emp
(seq_seq_match_item (item_match_option p) s (Seq.create (Seq.length s) None) 0);
on_range_cons
(seq_seq_match_item (item_match_option p) s (Seq.create (Seq.length s) None))
0
1
(Seq.length s)
end
let seq_seq_match_upd
(#opened: _)
(#t1 #t2: Type)
(p: t1 -> t2 -> vprop)
(s1: Seq.seq t1)
(s2: Seq.seq t2)
(i j: nat)
(k: nat {
i <= j /\ j < k
})
(x1: t1)
(x2: t2)
: STGhostT (squash (j < Seq.length s1 /\ j < Seq.length s2)) opened
(seq_seq_match p s1 s2 i k `star` p x1 x2)
(fun _ ->
seq_seq_match p (Seq.upd s1 j x1) (Seq.upd s2 j x2) i k
)
= seq_seq_match_length p s1 s2 i k;
on_range_get
(seq_seq_match_item p s1 s2)
i j (j + 1) k;
let res : squash (j < Seq.length s1 /\ j < Seq.length s2) = () in
drop (seq_seq_match_item p s1 s2 j);
rewrite
(p x1 x2)
(seq_seq_match_item p (Seq.upd s1 j x1) (Seq.upd s2 j x2) j);
seq_seq_match_weaken
p p (fun _ _ -> noop ())
s1 (Seq.upd s1 j x1)
s2 (Seq.upd s2 j x2)
i j;
seq_seq_match_weaken
p p (fun _ _ -> noop ())
s1 (Seq.upd s1 j x1)
s2 (Seq.upd s2 j x2)
(j + 1) k;
on_range_put
(seq_seq_match_item p (Seq.upd s1 j x1) (Seq.upd s2 j x2))
i j j (j + 1) k;
res
let seq_seq_match_item_match_option_upd
(#opened: _)
(#t1 #t2: Type)
(p: t1 -> t2 -> vprop)
(s1: Seq.seq t1)
(s2: Seq.seq (option t2))
(i j: nat)
(k: nat {
i <= j /\ j < k
})
(x1: t1)
(x2: t2)
: STGhostT (squash (j < Seq.length s1 /\ j < Seq.length s2)) opened
(seq_seq_match (item_match_option p) s1 s2 i k `star` p x1 x2)
(fun _ ->
seq_seq_match (item_match_option p) (Seq.upd s1 j x1) (Seq.upd s2 j (Some x2)) i k
)
= rewrite
(p x1 x2)
(item_match_option p x1 (Some x2));
seq_seq_match_upd (item_match_option p) s1 s2 i j k x1 (Some x2) | {
"checked_file": "/",
"dependencies": [
"Steel.ST.OnRange.fsti.checked",
"Steel.ST.GenElim.fsti.checked",
"prims.fst.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "Steel.ST.SeqMatch.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "SZ"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "Steel.ST.GenElim",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.OnRange",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
p: (_: t1 -> _: t2 -> Steel.Effect.Common.vprop) ->
s1: FStar.Seq.Base.seq t1 ->
s2: FStar.Seq.Base.seq (FStar.Pervasives.Native.option t2) ->
i: Prims.nat ->
j: Prims.nat ->
k:
Prims.nat
{i <= j /\ j < k /\ (j < FStar.Seq.Base.length s2 ==> Some? (FStar.Seq.Base.index s2 j))}
-> Steel.ST.Effect.Ghost.STGhostT
(Prims.squash (j < FStar.Seq.Base.length s1 /\ j < FStar.Seq.Base.length s2 /\
Some? (FStar.Seq.Base.index s2 j))) | Steel.ST.Effect.Ghost.STGhostT | [] | [] | [
"Steel.Memory.inames",
"Steel.Effect.Common.vprop",
"FStar.Seq.Base.seq",
"FStar.Pervasives.Native.option",
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"Prims.l_imp",
"FStar.Seq.Base.length",
"FStar.Pervasives.Native.uu___is_Some",
"FStar.Seq.Base.index",
"Prims.squash",
"Prims.unit",
"Steel.ST.OnRange.on_range_put",
"Steel.ST.SeqMatch.seq_seq_match_item",
"Steel.ST.SeqMatch.item_match_option",
"FStar.Seq.Base.upd",
"FStar.Pervasives.Native.None",
"Prims.op_Addition",
"Steel.ST.SeqMatch.seq_seq_match_weaken",
"Steel.ST.Util.noop",
"Steel.ST.Util.rewrite",
"Steel.Effect.Common.emp",
"FStar.Pervasives.Native.__proj__Some__item__v",
"Steel.ST.OnRange.on_range_get",
"Steel.ST.SeqMatch.seq_seq_match_length",
"Steel.ST.SeqMatch.seq_seq_match",
"Steel.Effect.Common.star"
] | [] | false | true | true | false | false | let seq_seq_match_item_match_option_index
(#opened: _)
(#t1 #t2: Type)
(p: (t1 -> t2 -> vprop))
(s1: Seq.seq t1)
(s2: Seq.seq (option t2))
(i j: nat)
(k: nat{i <= j /\ j < k /\ (j < Seq.length s2 ==> Some? (Seq.index s2 j))})
: STGhostT (squash (j < Seq.length s1 /\ j < Seq.length s2 /\ Some? (Seq.index s2 j)))
opened
(seq_seq_match (item_match_option p) s1 s2 i k)
(fun _ ->
(seq_seq_match (item_match_option p) s1 (Seq.upd s2 j None) i k)
`star`
(p (Seq.index s1 j) (Some?.v (Seq.index s2 j)))) =
| seq_seq_match_length (item_match_option p) s1 s2 i k;
on_range_get (seq_seq_match_item (item_match_option p) s1 s2) i j (j + 1) k;
let res:squash (j < Seq.length s1 /\ j < Seq.length s2 /\ Some? (Seq.index s2 j)) = () in
rewrite (seq_seq_match_item (item_match_option p) s1 s2 j)
(p (Seq.index s1 j) (Some?.v (Seq.index s2 j)));
rewrite emp (seq_seq_match_item (item_match_option p) s1 (Seq.upd s2 j None) j);
seq_seq_match_weaken (item_match_option p)
(item_match_option p)
(fun _ _ -> noop ())
s1
s1
s2
(Seq.upd s2 j None)
i
j;
seq_seq_match_weaken (item_match_option p)
(item_match_option p)
(fun _ _ -> noop ())
s1
s1
s2
(Seq.upd s2 j None)
(j + 1)
k;
on_range_put (seq_seq_match_item (item_match_option p) s1 (Seq.upd s2 j None)) i j j (j + 1) k;
res | false |
Hacl.Spec.BignumQ.Lemmas.fst | Hacl.Spec.BignumQ.Lemmas.lemma_aux_0 | val lemma_aux_0 (a b n: nat)
: Lemma
(pow2 n * a + pow2 (n + 56) * b = pow2 n * (a % pow2 56) + pow2 (n + 56) * (b + a / pow2 56)) | val lemma_aux_0 (a b n: nat)
: Lemma
(pow2 n * a + pow2 (n + 56) * b = pow2 n * (a % pow2 56) + pow2 (n + 56) * (b + a / pow2 56)) | let lemma_aux_0 (a:nat) (b:nat) (n:nat) : Lemma
(pow2 n * a + pow2 (n+56) * b = pow2 n * (a % pow2 56) + pow2 (n+56) * (b + a / pow2 56))
= Math.Lemmas.lemma_div_mod a (pow2 56);
Math.Lemmas.pow2_plus n 56;
assert(a = pow2 56 * (a / pow2 56) + (a % pow2 56));
Math.Lemmas.distributivity_add_right (pow2 n) (pow2 56 * (a / pow2 56)) (a % pow2 56);
Math.Lemmas.paren_mul_right (pow2 n) (pow2 56) (a / pow2 56);
Math.Lemmas.distributivity_add_right (pow2 (n+56)) b (a / pow2 56) | {
"file_name": "code/ed25519/Hacl.Spec.BignumQ.Lemmas.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 70,
"end_line": 746,
"start_col": 8,
"start_line": 739
} | module Hacl.Spec.BignumQ.Lemmas
open FStar.Tactics.CanonCommSemiring
open FStar.Mul
open Lib.IntTypes
module S = Spec.Ed25519
include Hacl.Spec.BignumQ.Definitions
let feq (#a #b:Type) (f:(a -> b)) (x y:a) :
Lemma (requires x == y) (ensures f x == f y) = ()
let eq_eq2 (#a:eqtype) (x y:a) :
Lemma (requires x = y) (ensures x == y) = ()
val lemma_mul_lt:a:nat -> b:nat -> c:nat -> d:nat ->
Lemma
(requires a < b /\ c < d)
(ensures a * c < b * d)
let lemma_mul_lt a b c d = ()
val lemma_as_nat5: f:qelem5 ->
Lemma
(requires qelem_fits5 f (1, 1, 1, 1, 1))
(ensures as_nat5 f < pow2 280)
let lemma_as_nat5 f =
//let (f0, f1, f2, f3, f4) = f in
//assert (as_nat5 f == v f0 + v f1 * pow56 + v f2 * pow112 + v f3 * pow168 + v f4 * pow224);
assert_norm (pow2 56 * pow2 56 = pow2 112);
assert_norm (pow2 56 * pow2 112 = pow2 168);
assert_norm (pow2 56 * pow2 168 = pow2 224);
assert_norm (pow2 56 * pow2 224 = pow2 280)
val lemma_choose_step:
bit:uint64{v bit <= 1}
-> x:uint64
-> y:uint64
-> Lemma
(let mask = bit -. u64 1 in
let z = x ^. (mask &. (x ^. y)) in
if v bit = 1 then z == x else z == y)
let lemma_choose_step bit p1 p2 =
let mask = bit -. u64 1 in
assert (v bit == 0 ==> v mask == pow2 64 - 1);
assert (v bit == 1 ==> v mask == 0);
let dummy = mask &. (p1 ^. p2) in
logand_lemma mask (p1 ^. p2);
assert (v bit == 1 ==> v dummy == 0);
assert (v bit == 0 ==> v dummy == v (p1 ^. p2));
let p1' = p1 ^. dummy in
assert (v dummy == v (if v bit = 1 then u64 0 else (p1 ^. p2)));
logxor_lemma p1 p2
val lemma_subm_conditional:
x0:nat -> x1:nat -> x2:nat -> x3:nat -> x4:nat
-> y0:nat -> y1:nat -> y2:nat -> y3:nat -> y4:nat
-> b0:nat -> b1:nat -> b2:nat -> b3:nat -> b4:nat ->
Lemma (
x0 - y0 + b0 * pow2 56 +
(x1 - y1 - b0 + b1 * pow2 56) * pow2 56 +
(x2 - y2 - b1 + b2 * pow2 56) * pow2 112 +
(x3 - y3 - b2 + b3 * pow2 56) * pow2 168 +
(x4 - y4 - b3 + b4 * pow2 56) * pow2 224 ==
(x0 + x1 * pow2 56 + x2 * pow2 112 + x3 * pow2 168 + x4 * pow2 224) -
(y0 + y1 * pow2 56 + y2 * pow2 112 + y3 * pow2 168 + y4 * pow2 224) + b4 * pow2 280)
let lemma_subm_conditional x0 x1 x2 x3 x4 y0 y1 y2 y3 y4 b0 b1 b2 b3 b4 =
assert_norm (pow2 56 * pow2 56 = pow2 112);
assert_norm (pow2 56 * pow2 112 = pow2 168);
assert_norm (pow2 56 * pow2 168 = pow2 224);
assert_norm (pow2 56 * pow2 224 = pow2 280);
assert (
x0 - y0 + b0 * pow2 56 +
(x1 - y1 - b0 + b1 * pow2 56) * pow2 56 +
(x2 - y2 - b1 + b2 * pow2 56) * pow2 112 +
(x3 - y3 - b2 + b3 * pow2 56) * pow2 168 +
(x4 - y4 - b3 + b4 * pow2 56) * pow2 224 ==
(x0 + x1 * pow2 56 + x2 * pow2 112 + x3 * pow2 168 + x4 * pow2 224) -
(y0 + y1 * pow2 56 + y2 * pow2 112 + y3 * pow2 168 + y4 * pow2 224) + b4 * pow2 280)
by (int_semiring ());
()
val lemma_div224: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1))
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
wide_as_nat5 x / pow2 224 ==
v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280))
#push-options "--z3rlimit 50"
let lemma_div224 x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert
(wide_as_nat5 x ==
v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168 + v x4 * pow2 224 +
v x5 * pow2 280 + v x6 * pow2 336 + v x7 * pow2 392 + v x8 * pow2 448 + v x9 * pow2 504);
assert_norm (pow2 56 * pow2 224 == pow2 280);
assert_norm (pow2 112 * pow2 224 == pow2 336);
assert_norm (pow2 168 * pow2 224 == pow2 392);
assert_norm (pow2 224 * pow2 224 == pow2 448);
assert_norm (pow2 280 * pow2 224 == pow2 504);
calc (==) {
wide_as_nat5 x / pow2 224;
(==) { }
(v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168 +
(v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280) * pow2 224) / pow2 224;
(==) {
FStar.Math.Lemmas.lemma_div_plus
(v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168)
(v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280) (pow2 224) }
(v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168) / pow2 224 +
v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280;
(==) { FStar.Math.Lemmas.small_division_lemma_1 (v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168) (pow2 224) }
v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280;
}
#pop-options
val lemma_div248_aux: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 512)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
wide_as_nat5 x / pow2 248 ==
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256))
open FStar.Tactics.CanonCommSemiring
#push-options "--z3cliopt smt.arith.nl=false"
let lemma_div248_aux x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert_norm (pow2 248 == pow2 224 * pow2 24);
assert_norm (pow2 56 == pow2 32 * pow2 24);
assert_norm (pow2 112 == pow2 88 * pow2 24);
assert_norm (pow2 168 == pow2 144 * pow2 24);
assert_norm (pow2 224 == pow2 200 * pow2 24);
assert_norm (pow2 280 == pow2 256 * pow2 24);
assert_norm (0 < pow2 24);
calc (==) {
wide_as_nat5 x / pow2 248;
(==) { FStar.Math.Lemmas.division_multiplication_lemma (wide_as_nat5 x) (pow2 224) (pow2 24) }
(wide_as_nat5 x / pow2 224) / pow2 24;
(==) { lemma_div224 x }
(v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280) / pow2 24;
(==) { _ by (Tactics.mapply (`feq #int #int (fun x -> x / pow2 24)); int_semiring ()) } (v x4 + (v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256) * pow2 24) / pow2 24;
(==) { FStar.Math.Lemmas.lemma_div_plus (v x4) (v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256) (pow2 24) }
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256;
}
#pop-options
val lemma_div248_x5: x5:uint64 ->
Lemma ( pow2 32 * (v x5 % pow2 24) + v x5 / pow2 24 * pow2 56 == v x5 * pow2 32)
let lemma_div248_x5 x5 =
assert_norm (pow2 32 * pow2 24 = pow2 56)
val lemma_div248_x6: x6:uint64 ->
Lemma (pow2 32 * (v x6 % pow2 24) * pow2 56 + v x6 / pow2 24 * pow2 112 == v x6 * pow2 88)
let lemma_div248_x6 x6 =
calc (==) {
pow2 32 * (v x6 % pow2 24) * pow2 56 + v x6 / pow2 24 * pow2 112;
(==) { _ by (Tactics.norm [delta_only [`%pow2]; primops]; int_semiring ()) }
((v x6 / pow2 24) * pow2 24 + v x6 % pow2 24) * pow2 88;
(==) { FStar.Math.Lemmas.euclidean_division_definition (v x6) (pow2 24) }
v x6 * pow2 88;
}
val lemma_div248_x7: x7:uint64 ->
Lemma (pow2 32 * (v x7 % pow2 24) * pow2 112 + v x7 / pow2 24 * pow2 168 == v x7 * pow2 144)
let lemma_div248_x7 x7 =
calc (==) {
pow2 32 * (v x7 % pow2 24) * pow2 112 + v x7 / pow2 24 * pow2 168;
(==) { _ by (Tactics.norm [delta_only [`%pow2]; primops]; int_semiring ()) }
((v x7 / pow2 24) * pow2 24 + v x7 % pow2 24) * pow2 144;
(==) { FStar.Math.Lemmas.euclidean_division_definition (v x7) (pow2 24) }
v x7 * pow2 144;
}
val lemma_div248_x8: x8:uint64 ->
Lemma (pow2 32 * (v x8 % pow2 24) * pow2 168 + v x8 / pow2 24 * pow2 224 == v x8 * pow2 200)
let lemma_div248_x8 x8 =
calc (==) {
pow2 32 * (v x8 % pow2 24) * pow2 168 + v x8 / pow2 24 * pow2 224;
(==) { _ by (Tactics.norm [delta_only [`%pow2]; primops]; int_semiring ()) }
((v x8 / pow2 24) * pow2 24 + v x8 % pow2 24) * pow2 200;
(==) { FStar.Math.Lemmas.euclidean_division_definition (v x8) (pow2 24) }
v x8 * pow2 200;
}
val lemma_div248_x9: x9:uint64{v x9 < pow2 24} ->
Lemma (pow2 32 * (v x9 % pow2 24) * pow2 224 == v x9 * pow2 256)
let lemma_div248_x9 x9 =
calc (==) {
pow2 32 * (v x9 % pow2 24) * pow2 224;
(==) { Math.Lemmas.small_mod (v x9) (pow2 24) }
pow2 32 * v x9 * pow2 224;
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
v x9 * pow2 256;
}
val lemma_wide_as_nat_pow512: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 512)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
v x9 < pow2 24))
let lemma_wide_as_nat_pow512 x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert_norm (pow2 504 * pow2 8 = pow2 512);
FStar.Math.Lemmas.pow2_minus 512 504;
assert (v x9 < pow2 8);
assert_norm (pow2 8 < pow2 24)
val lemma_div248: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 512)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
let z0 = v x4 / pow2 24 + pow2 32 * (v x5 % pow2 24) in
let z1 = v x5 / pow2 24 + pow2 32 * (v x6 % pow2 24) in
let z2 = v x6 / pow2 24 + pow2 32 * (v x7 % pow2 24) in
let z3 = v x7 / pow2 24 + pow2 32 * (v x8 % pow2 24) in
let z4 = v x8 / pow2 24 + pow2 32 * (v x9 % pow2 24) in
wide_as_nat5 x / pow2 248 == z0 + z1 * pow2 56 + z2 * pow2 112 + z3 * pow2 168 + z4 * pow2 224))
#push-options "--z3rlimit 50"
let lemma_div248 x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
lemma_wide_as_nat_pow512 x;
assert (v x9 < pow2 24);
calc (==) {
(let z0 = v x4 / pow2 24 + pow2 32 * (v x5 % pow2 24) in
let z1 = v x5 / pow2 24 + pow2 32 * (v x6 % pow2 24) in
let z2 = v x6 / pow2 24 + pow2 32 * (v x7 % pow2 24) in
let z3 = v x7 / pow2 24 + pow2 32 * (v x8 % pow2 24) in
let z4 = v x8 / pow2 24 + pow2 32 * (v x9 % pow2 24) in
z0 + z1 * pow2 56 + z2 * pow2 112 + z3 * pow2 168 + z4 * pow2 224);
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
v x4 / pow2 24 + pow2 32 * (v x5 % pow2 24) +
v x5 / pow2 24 * pow2 56 + pow2 32 * (v x6 % pow2 24) * pow2 56 +
v x6 / pow2 24 * pow2 112 + pow2 32 * (v x7 % pow2 24) * pow2 112 +
v x7 / pow2 24 * pow2 168 + pow2 32 * (v x8 % pow2 24) * pow2 168 +
v x8 / pow2 24 * pow2 224 + pow2 32 * (v x9 % pow2 24) * pow2 224;
(==) { lemma_div248_x5 x5; lemma_div248_x6 x6 }
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 +
pow2 32 * (v x7 % pow2 24) * pow2 112 +
v x7 / pow2 24 * pow2 168 + pow2 32 * (v x8 % pow2 24) * pow2 168 +
v x8 / pow2 24 * pow2 224 + pow2 32 * (v x9 % pow2 24) * pow2 224;
(==) { lemma_div248_x7 x7; lemma_div248_x8 x8 }
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 +
pow2 32 * (v x9 % pow2 24) * pow2 224;
(==) { lemma_div248_x9 x9 }
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256;
(==) { lemma_div248_aux x }
wide_as_nat5 x / pow2 248;
}
#pop-options
val lemma_add_modq5:
x:qelem5
-> y:qelem5
-> t:qelem5 ->
Lemma
(requires
qelem_fits5 x (1, 1, 1, 1, 1) /\
qelem_fits5 y (1, 1, 1, 1, 1) /\
qelem_fits5 t (1, 1, 1, 1, 1) /\
as_nat5 x < S.q /\ as_nat5 y < S.q /\
as_nat5 t == as_nat5 x + as_nat5 y)
(ensures
(let res = if as_nat5 t >= S.q then as_nat5 t - S.q else as_nat5 t in
res < S.q /\ res == (as_nat5 x + as_nat5 y) % S.q))
let lemma_add_modq5 x y t =
assert (as_nat5 t == as_nat5 x + as_nat5 y);
let res = if as_nat5 t >= S.q then as_nat5 t - S.q else as_nat5 t in
assert (res < S.q);
if as_nat5 t >= S.q then (
FStar.Math.Lemmas.sub_div_mod_1 (as_nat5 t) S.q;
assert (res % S.q == as_nat5 t % S.q))
else
assert (res % S.q == as_nat5 t % S.q);
FStar.Math.Lemmas.small_mod res S.q
val lemma_wide_as_nat_pow528: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 528)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
v x9 < pow2 40))
let lemma_wide_as_nat_pow528 x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert_norm (pow2 504 * pow2 24 = pow2 528);
FStar.Math.Lemmas.pow2_minus 528 504;
assert (v x9 < pow2 24);
assert_norm (pow2 24 < pow2 40)
#push-options "--z3cliopt smt.arith.nl=false"
val lemma_div264_aux: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 528)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
wide_as_nat5 x / pow2 264 ==
v x4 / pow2 40 + v x5 * pow2 16 + v x6 * pow2 72 + v x7 * pow2 128 + v x8 * pow2 184 + v x9 * pow2 240))
let lemma_div264_aux x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert_norm (pow2 264 == pow2 224 * pow2 40);
assert_norm (pow2 56 == pow2 16 * pow2 40);
assert_norm (pow2 112 == pow2 72 * pow2 40);
assert_norm (pow2 168 == pow2 128 * pow2 40);
assert_norm (pow2 224 == pow2 184 * pow2 40);
assert_norm (pow2 280 == pow2 240 * pow2 40);
assert_norm (0 < pow2 40);
calc (==) {
wide_as_nat5 x / pow2 264;
(==) { FStar.Math.Lemmas.division_multiplication_lemma (wide_as_nat5 x) (pow2 224) (pow2 40) }
(wide_as_nat5 x / pow2 224) / pow2 40;
(==) { lemma_div224 x }
(v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280) / pow2 40;
(==) { _ by (Tactics.mapply (`feq #int #int (fun x -> x / pow2 40)); int_semiring ()) }
(v x4 + (v x5 * pow2 16 + v x6 * pow2 72 + v x7 * pow2 128 + v x8 * pow2 184 + v x9 * pow2 240) * pow2 40) / pow2 40;
(==) { FStar.Math.Lemmas.lemma_div_plus (v x4) (v x5 * pow2 16 + v x6 * pow2 72 + v x7 * pow2 128 + v x8 * pow2 184 + v x9 * pow2 240) (pow2 40) }
v x4 / pow2 40 + v x5 * pow2 16 + v x6 * pow2 72 + v x7 * pow2 128 + v x8 * pow2 184 + v x9 * pow2 240;
}
val lemma_div264_x5: x5:uint64 ->
Lemma (pow2 16 * (v x5 % pow2 40) + v x5 / pow2 40 * pow2 56 == v x5 * pow2 16)
let lemma_div264_x5 x5 =
assert_norm (0 < pow2 24);
calc (==) {
pow2 16 * (v x5 % pow2 40) + v x5 / pow2 40 * pow2 56;
(==) { _ by (Tactics.norm [delta_only [`%pow2]; primops]; int_semiring ()) }
((v x5 / pow2 40) * pow2 40 + v x5 % pow2 40) * pow2 16;
(==) { FStar.Math.Lemmas.euclidean_division_definition (v x5) (pow2 40) }
v x5 * pow2 16;
}
val lemma_div264_x6: x6:uint64 ->
Lemma (pow2 16 * (v x6 % pow2 40) * pow2 56 + v x6 / pow2 40 * pow2 112 == v x6 * pow2 72)
let lemma_div264_x6 x6 =
calc (==) {
pow2 16 * (v x6 % pow2 40) * pow2 56 + v x6 / pow2 40 * pow2 112;
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
((v x6 / pow2 40) * pow2 40 + v x6 % pow2 40) * pow2 72;
(==) { Math.Lemmas.euclidean_division_definition (v x6) (pow2 40) }
v x6 * pow2 72;
}
val lemma_div264_x7: x7:uint64 ->
Lemma (pow2 16 * (v x7 % pow2 40) * pow2 112 + v x7 / pow2 40 * pow2 168 == v x7 * pow2 128)
let lemma_div264_x7 x7 =
calc (==) {
pow2 16 * (v x7 % pow2 40) * pow2 112 + v x7 / pow2 40 * pow2 168;
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
((v x7 / pow2 40) * pow2 40 + v x7 % pow2 40) * pow2 128;
(==) { Math.Lemmas.euclidean_division_definition (v x7) (pow2 40) }
v x7 * pow2 128;
}
val lemma_div264_x8: x8:uint64 ->
Lemma (pow2 16 * (v x8 % pow2 40) * pow2 168 + v x8 / pow2 40 * pow2 224 == v x8 * pow2 184)
let lemma_div264_x8 x8 =
calc (==) {
pow2 16 * (v x8 % pow2 40) * pow2 168 + v x8 / pow2 40 * pow2 224;
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
((v x8 / pow2 40) * pow2 40 + v x8 % pow2 40) * pow2 184;
(==) { Math.Lemmas.euclidean_division_definition (v x8) (pow2 40) }
v x8 * pow2 184;
}
val lemma_div264_x9: x9:uint64{v x9 < pow2 40} ->
Lemma (pow2 16 * (v x9 % pow2 40) * pow2 224 == v x9 * pow2 240)
let lemma_div264_x9 x9 =
calc (==) {
pow2 16 * (v x9 % pow2 40) * pow2 224;
(==) { Math.Lemmas.small_mod (v x9) (pow2 40) }
pow2 16 * v x9 * pow2 224;
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
v x9 * pow2 240;
}
val lemma_div264: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 528)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
let z0 = v x4 / pow2 40 + pow2 16 * (v x5 % pow2 40) in
let z1 = v x5 / pow2 40 + pow2 16 * (v x6 % pow2 40) in
let z2 = v x6 / pow2 40 + pow2 16 * (v x7 % pow2 40) in
let z3 = v x7 / pow2 40 + pow2 16 * (v x8 % pow2 40) in
let z4 = v x8 / pow2 40 + pow2 16 * (v x9 % pow2 40) in
wide_as_nat5 x / pow2 264 == z0 + z1 * pow2 56 + z2 * pow2 112 + z3 * pow2 168 + z4 * pow2 224))
#push-options "--z3rlimit 50"
let lemma_div264 x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
lemma_wide_as_nat_pow528 x;
assert (v x9 < pow2 40);
calc (==) {
(let z0 = v x4 / pow2 40 + pow2 16 * (v x5 % pow2 40) in
let z1 = v x5 / pow2 40 + pow2 16 * (v x6 % pow2 40) in
let z2 = v x6 / pow2 40 + pow2 16 * (v x7 % pow2 40) in
let z3 = v x7 / pow2 40 + pow2 16 * (v x8 % pow2 40) in
let z4 = v x8 / pow2 40 + pow2 16 * (v x9 % pow2 40) in
z0 + z1 * pow2 56 + z2 * pow2 112 + z3 * pow2 168 + z4 * pow2 224);
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
v x4 / pow2 40 + pow2 16 * (v x5 % pow2 40) +
v x5 / pow2 40 * pow2 56 + pow2 16 * (v x6 % pow2 40) * pow2 56 +
v x6 / pow2 40 * pow2 112 + pow2 16 * (v x7 % pow2 40) * pow2 112 +
v x7 / pow2 40 * pow2 168 + pow2 16 * (v x8 % pow2 40) * pow2 168 +
v x8 / pow2 40 * pow2 224 + pow2 16 * (v x9 % pow2 40) * pow2 224;
(==) { lemma_div264_x5 x5; lemma_div264_x6 x6 }
v x4 / pow2 40 + v x5 * pow2 16 + v x6 * pow2 72 +
pow2 16 * (v x7 % pow2 40) * pow2 112 +
v x7 / pow2 40 * pow2 168 + pow2 16 * (v x8 % pow2 40) * pow2 168 +
v x8 / pow2 40 * pow2 224 + pow2 16 * (v x9 % pow2 40) * pow2 224;
(==) { lemma_div264_x7 x7; lemma_div264_x8 x8 }
v x4 / pow2 40 + v x5 * pow2 16 + v x6 * pow2 72 + v x7 * pow2 128 + v x8 * pow2 184 +
pow2 16 * (v x9 % pow2 40) * pow2 224;
(==) { lemma_div264_x9 x9 }
v x4 / pow2 40 + v x5 * pow2 16 + v x6 * pow2 72 + v x7 * pow2 128 + v x8 * pow2 184 + v x9 * pow2 240;
(==) { lemma_div264_aux x }
wide_as_nat5 x / pow2 264;
}
#pop-options
#pop-options // "--z3cliopt smt.arith.nl=false"
val lemma_mod_264_aux: t:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 t (1, 1, 1, 1, 1, 1, 1, 1, 1, 1))
(ensures
(let (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) = t in
(wide_as_nat5 t) % pow2 264 ==
(v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + v t4 * pow2 224) % pow2 264))
#push-options "--z3rlimit 150"
let lemma_mod_264_aux t =
let (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) = t in
let res = (t0, t1, t2, t3, t4 &. u64 0xffffffffff) in
assert_norm (pow2 16 * pow2 264 == pow2 280);
assert_norm (pow2 72 * pow2 264 == pow2 336);
assert_norm (pow2 128 * pow2 264 == pow2 392);
assert_norm (pow2 184 * pow2 264 == pow2 448);
assert_norm (pow2 240 * pow2 264 == pow2 504);
calc (==) {
(wide_as_nat5 t) % pow2 264;
(==) { }
(v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + v t4 * pow2 224 +
(v t5 * pow2 16 + v t6 * pow2 72 + v t7 * pow2 128 + v t8 * pow2 184 + v t9 * pow2 240) * pow2 264) % pow2 264;
(==) { FStar.Math.Lemmas.lemma_mod_add_distr (v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + v t4 * pow2 224)
((v t5 * pow2 16 + v t6 * pow2 72 + v t7 * pow2 128 + v t8 * pow2 184 + v t9 * pow2 240) * pow2 264) (pow2 264)}
((v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + v t4 * pow2 224) +
((v t5 * pow2 16 + v t6 * pow2 72 + v t7 * pow2 128 + v t8 * pow2 184 + v t9 * pow2 240) * pow2 264) % pow2 264) % pow2 264;
(==) { FStar.Math.Lemmas.cancel_mul_mod (v t5 * pow2 16 + v t6 * pow2 72 + v t7 * pow2 128 + v t8 * pow2 184 + v t9 * pow2 240) (pow2 264) }
(v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + v t4 * pow2 224) % pow2 264;
}
#pop-options
val lemma_as_nat_pow264: x:qelem5 ->
Lemma
(requires
(let (x0, x1, x2, x3, x4) = x in
qelem_fits5 x (1, 1, 1, 1, 1) /\
v x4 < pow2 40))
(ensures as_nat5 x < pow2 264)
let lemma_as_nat_pow264 x =
let (x0, x1, x2, x3, x4) = x in
assert_norm (pow2 40 * pow2 224 = pow2 264)
val lemma_mod_264: t:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 t (1, 1, 1, 1, 1, 1, 1, 1, 1, 1))
(ensures
(let (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) = t in
let res = (t0, t1, t2, t3, t4 &. u64 0xffffffffff) in
qelem_fits5 res (1, 1, 1, 1, 1) /\
as_nat5 res == (wide_as_nat5 t) % pow2 264))
let lemma_mod_264 t =
let (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) = t in
let t4' = t4 &. u64 0xffffffffff in
let res = (t0, t1, t2, t3, t4') in
assert_norm (pow2 40 < pow2 64);
assert_norm (pow2 40 - 1 == 0xffffffffff);
mod_mask_lemma t4 40ul;
assert (v (mod_mask #U64 #SEC 40ul) == 0xffffffffff);
assert (v (t4 &. u64 0xffffffffff) == v t4 % pow2 40);
calc (==) {
(wide_as_nat5 t) % pow2 264;
(==) { lemma_mod_264_aux t }
(v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + v t4 * pow2 224) % pow2 264;
(==) { FStar.Math.Lemmas.lemma_mod_add_distr (v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168) (v t4 * pow2 224) (pow2 264) }
(v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + (v t4 * pow2 224) % pow2 264) % pow2 264;
(==) { FStar.Math.Lemmas.pow2_multiplication_modulo_lemma_2 (v t4) 264 224 }
(v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + (v t4 % pow2 40) * pow2 224) % pow2 264;
(==) { lemma_as_nat_pow264 res; FStar.Math.Lemmas.modulo_lemma (as_nat5 res) (pow2 264) }
v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + (v t4 % pow2 40) * pow2 224;
}
val lemma_as_nat_pow264_x4: x:qelem5 ->
Lemma
(requires
qelem_fits5 x (1, 1, 1, 1, 1) /\
as_nat5 x < pow2 264)
(ensures
(let (x0, x1, x2, x3, x4) = x in
v x4 < pow2 40))
let lemma_as_nat_pow264_x4 x =
let (x0, x1, x2, x3, x4) = x in
assert_norm (pow2 40 * pow2 224 = pow2 264)
val lemma_sub_mod_264_aux:
x0:nat -> x1:nat -> x2:nat -> x3:nat -> x4:nat
-> y0:nat -> y1:nat -> y2:nat -> y3:nat -> y4:nat
-> c1:nat -> c2:nat -> c3:nat -> c4:nat -> c5:nat ->
Lemma (
x0 - y0 + c1 * pow56 +
(x1 - y1 - c1 + c2 * pow56) * pow56 +
(x2 - y2 - c2 + c3 * pow56) * pow112 +
(x3 - y3 - c3 + c4 * pow56) * pow168 +
(x4 - y4 - c4 + pow2 40 * c5) * pow224 ==
(x0 + x1 * pow2 56 + x2 * pow2 112 + x3 * pow2 168 + x4 * pow2 224) -
(y0 + y1 * pow2 56 + y2 * pow2 112 + y3 * pow2 168 + y4 * pow2 224) + c5 * pow2 264)
#push-options "--z3rlimit 50"
let lemma_sub_mod_264_aux x0 x1 x2 x3 x4 y0 y1 y2 y3 y4 b0 b1 b2 b3 b4 =
assert_norm (pow2 56 * pow2 56 = pow2 112);
assert_norm (pow2 56 * pow2 112 = pow2 168);
assert_norm (pow2 56 * pow2 168 = pow2 224);
assert_norm (pow2 40 * pow2 224 = pow2 264)
#pop-options
val lemma_sub_mod_264:
x:qelem5
-> y:qelem5
-> t:qelem5
-> c5:uint64 ->
Lemma
(requires
qelem_fits5 x (1, 1, 1, 1, 1) /\
qelem_fits5 y (1, 1, 1, 1, 1) /\
qelem_fits5 t (1, 1, 1, 1, 1) /\
as_nat5 x < pow2 264 /\
as_nat5 y < pow2 264 /\
as_nat5 t == as_nat5 x - as_nat5 y + v c5 * pow2 264 /\ v c5 <= 1 /\
(if v c5 = 0 then as_nat5 x >= as_nat5 y else as_nat5 x < as_nat5 y))
(ensures
(if as_nat5 x >= as_nat5 y then
as_nat5 t == as_nat5 x - as_nat5 y
else as_nat5 t == as_nat5 x - as_nat5 y + pow2 264))
#push-options "--z3rlimit 50"
let lemma_sub_mod_264 x y t c5 =
assert (if v c5 = 0 then as_nat5 x >= as_nat5 y else as_nat5 x < as_nat5 y);
assert (as_nat5 t == as_nat5 x - as_nat5 y + v c5 * pow2 264);
if as_nat5 x >= as_nat5 y then
assert (v c5 == 0 /\ as_nat5 t == as_nat5 x - as_nat5 y)
else
assert (v c5 == 1 /\ as_nat5 t == as_nat5 x - as_nat5 y + pow2 264)
#pop-options
let lemma_mul_qelem5 (x0 x1 x2 x3 x4 y0 y1 y2 y3 y4:nat) : Lemma
((x0 + x1 * pow2 56 + x2 * pow2 112 + x3 * pow2 168 + x4 * pow2 224) *
(y0 + y1 * pow2 56 + y2 * pow2 112 + y3 * pow2 168 + y4 * pow2 224) ==
x0 * y0 +
(x0 * y1 + x1 * y0) * pow56 +
(x0 * y2 + x1 * y1 + x2 * y0) * pow112 +
(x0 * y3 + x1 * y2 + x2 * y1 + x3 * y0) * pow168 +
(x0 * y4 + x1 * y3 + x2 * y2 + x3 * y1 + x4 * y0) * pow224 +
(x1 * y4 + x2 * y3 + x3 * y2 + x4 * y1) * pow280 +
(x2 * y4 + x3 * y3 + x4 * y2) * pow336 +
(x3 * y4 + x4 * y3) * pow392 +
(x4 * y4) * pow448)
=
assert ((x0 + x1 * pow2 56 + x2 * pow2 112 + x3 * pow2 168 + x4 * pow2 224) *
(y0 + y1 * pow2 56 + y2 * pow2 112 + y3 * pow2 168 + y4 * pow2 224) ==
x0 * y0 +
(x0 * y1 + x1 * y0) * pow56 +
(x0 * y2 + x1 * y1 + x2 * y0) * pow112 +
(x0 * y3 + x1 * y2 + x2 * y1 + x3 * y0) * pow168 +
(x0 * y4 + x1 * y3 + x2 * y2 + x3 * y1 + x4 * y0) * pow224 +
(x1 * y4 + x2 * y3 + x3 * y2 + x4 * y1) * pow280 +
(x2 * y4 + x3 * y3 + x4 * y2) * pow336 +
(x3 * y4 + x4 * y3) * pow392 +
(x4 * y4) * pow448)
by (Tactics.norm [zeta; iota; delta; primops]; int_semiring ())
val lemma_mul_5_low_264:
x1:nat -> x2:nat -> x3:nat -> x4:nat -> x5:nat ->
y1:nat -> y2:nat -> y3:nat -> y4:nat -> y5:nat ->
Lemma (
(x1 * y1) >= 0
/\ (x2 * y1 + x1 * y2 + ((x1 * y1) / pow2 56)) >= 0
/\ (x3 * y1 + x2 * y2 + x1 * y3 + ((x2 * y1 + x1 * y2 + ((x1 * y1) / pow2 56)) / pow2 56)) >= 0
/\ (x4 * y1 + x3 * y2 + x2 * y3 + x1 * y4 + ((x3 * y1 + x2 * y2 + x1 * y3 + ((x2 * y1 + x1 * y2 + ((x1 * y1) / pow2 56)) / pow2 56)) / pow2 56)) >= 0
/\ (
let a0 = (x1 * y1) % pow2 56 in
let a1 = ((x2 * y1 + x1 * y2 + ((x1 * y1) / pow2 56)) % pow2 56) in
let a2 = ((x3 * y1 + x2 * y2 + x1 * y3 + ((x2 * y1 + x1 * y2 + ((x1 * y1) / pow2 56)) / pow2 56)) % pow2 56) in
let a3 = ((x4 * y1 + x3 * y2 + x2 * y3 + x1 * y4 + ((x3 * y1 + x2 * y2 + x1 * y3 + ((x2 * y1 + x1 * y2 + ((x1 * y1) / pow2 56)) / pow2 56)) / pow2 56)) % pow2 56) in
let a4 = (x5 * y1 + x4 * y2 + x3 * y3 + x2 * y4 + x1 * y5 + ((x4 * y1 + x3 * y2 + x2 * y3 + x1 * y4 + ((x3 * y1 + x2 * y2 + x1 * y3 + ((x2 * y1 + x1 * y2 + ((x1 * y1) / pow2 56)) / pow2 56)) / pow2 56)) / pow2 56)) in
((x1 + pow2 56 * x2 + pow2 112 * x3 + pow2 168 * x4 + pow2 224 * x5)
* (y1 + pow2 56 * y2 + pow2 112 * y3 + pow2 168 * y4 + pow2 224 * y5)) % pow2 264
== a0 + pow2 56 * a1 + pow2 112 * a2 + pow2 168 * a3 + pow2 224 * (a4 % pow2 40)))
private let lemma_mul_nat_is_nat (a:nat) (b:nat) : Lemma (a*b >= 0) = ()
private let lemma_div_nat_is_nat (a:nat) (b:pos) : Lemma (a/b >= 0) = ()
private
val lemma_mul_5''':
x1:nat -> x2:nat -> x3:nat -> x4:nat -> x5:nat ->
y1:nat -> y2:nat -> y3:nat -> y4:nat -> y5:nat ->
Lemma (((x1 + pow2 56 * x2 + pow2 112 * x3 + pow2 168 * x4 + pow2 224 * x5)
* (y1 + pow2 56 * y2 + pow2 112 * y3 + pow2 168 * y4 + pow2 224 * y5)) % pow2 264
==
(x1 * y1
+ pow2 56 * (x2 * y1 + x1 * y2)
+ pow2 112 * (x3 * y1 + x2 * y2 + x1 * y3)
+ pow2 168 * (x4 * y1 + x3 * y2 + x2 * y3 + x1 * y4)
+ pow2 224 * (x5 * y1 + x4 * y2 + x3 * y3 + x2 * y4 + x1 * y5)) % pow2 264)
let lemma_mul_5''' x1 x2 x3 x4 x5 y1 y2 y3 y4 y5 =
calc (==) {
((x1 + pow2 56 * x2 + pow2 112 * x3 + pow2 168 * x4 + pow2 224 * x5)
* (y1 + pow2 56 * y2 + pow2 112 * y3 + pow2 168 * y4 + pow2 224 * y5)) % pow2 264;
(==) { _ by (Tactics.mapply (`feq #int #int (fun x -> x % pow2 264));
Tactics.norm [zeta; iota; delta; primops];
int_semiring ()) }
(x1 * y1
+ pow2 56 * (x2 * y1 + x1 * y2)
+ pow2 112 * (x3 * y1 + x2 * y2 + x1 * y3)
+ pow2 168 * (x4 * y1 + x3 * y2 + x2 * y3 + x1 * y4)
+ pow2 224 * (x5 * y1 + x4 * y2 + x3 * y3 + x2 * y4 + x1 * y5)
+ (pow2 16 * x2 * y5 +
pow2 16 * x3 * y4 + pow2 72 * x3 * y5 +
pow2 16 * x4 * y3 + pow2 72 * x4 * y4 + pow2 128 * x4 * y5 +
pow2 16 * x5 * y2 + pow2 72 * x5 * y3 + pow2 128 * x5 * y4 + pow2 184 * x5 * y5) * pow2 264) % pow2 264;
(==) { _ by (Tactics.mapply (`eq_eq2); Tactics.mapply (`Math.Lemmas.lemma_mod_plus)) }
(x1 * y1
+ pow2 56 * (x2 * y1 + x1 * y2)
+ pow2 112 * (x3 * y1 + x2 * y2 + x1 * y3)
+ pow2 168 * (x4 * y1 + x3 * y2 + x2 * y3 + x1 * y4)
+ pow2 224 * (x5 * y1 + x4 * y2 + x3 * y3 + x2 * y4 + x1 * y5)) % pow2 264;
}
private val lemma_mod_264'':
a0:nat -> a1:nat-> a2:nat -> a3:nat -> a4:nat ->
Lemma
(requires a0 < pow56 /\ a1 < pow56 /\ a2 < pow56 /\ a3 < pow56)
(ensures a0 + pow2 56 * a1 + pow2 112 * a2 + pow2 168 * a3 + pow2 224 * (a4 % pow2 40) < pow2 264)
let lemma_mod_264'' a0 a1 a2 a3 a4 =
assert_norm(pow2 40 = 0x10000000000);
assert_norm(pow2 56 = 0x100000000000000);
assert_norm(pow2 112 = 0x10000000000000000000000000000);
assert_norm(pow2 168 = 0x1000000000000000000000000000000000000000000);
assert_norm(pow2 224 = 0x100000000000000000000000000000000000000000000000000000000);
assert_norm(pow2 264 = 0x1000000000000000000000000000000000000000000000000000000000000000000)
private val lemma_mod_264':
a0:nat -> a1:nat-> a2:nat -> a3:nat -> a4:nat ->
Lemma
(requires a0 < pow56 /\ a1 < pow56 /\ a2 < pow56 /\ a3 < pow56)
(ensures (a0
+ pow2 56 * a1
+ pow2 112 * a2
+ pow2 168 * a3
+ pow2 224 * a4) % pow2 264 =
a0
+ pow2 56 * a1
+ pow2 112 * a2
+ pow2 168 * a3
+ pow2 224 * (a4 % pow2 40) )
let lemma_mod_264' a0 a1 a2 a3 a4 =
assert_norm(pow2 56 = 0x100000000000000);
assert_norm(pow2 112 = 0x10000000000000000000000000000);
assert_norm(pow2 168 = 0x1000000000000000000000000000000000000000000);
assert_norm(pow2 224 = 0x100000000000000000000000000000000000000000000000000000000);
Math.Lemmas.lemma_mod_plus_distr_l (pow2 224 * a4) (a0 + pow2 56 * a1 + pow2 112 * a2 + pow2 168 * a3) (pow2 264);
Math.Lemmas.pow2_multiplication_modulo_lemma_2 a4 264 224;
lemma_mod_264'' a0 a1 a2 a3 a4;
Math.Lemmas.modulo_lemma (a0 + pow2 56 * a1 + pow2 112 * a2 + pow2 168 * a3 + pow2 224 * (a4 % pow2 40)) (pow2 264) | {
"checked_file": "/",
"dependencies": [
"Spec.Ed25519.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.BignumQ.Definitions.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Tactics.CanonCommSemiring.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.BignumQ.Lemmas.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.CanonCommSemiring",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.BignumQ.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.Ed25519",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.CanonCommSemiring",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.BignumQ",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.BignumQ",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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 | a: Prims.nat -> b: Prims.nat -> n: Prims.nat
-> FStar.Pervasives.Lemma
(ensures
Prims.pow2 n * a + Prims.pow2 (n + 56) * b =
Prims.pow2 n * (a % Prims.pow2 56) + Prims.pow2 (n + 56) * (b + a / Prims.pow2 56)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.nat",
"FStar.Math.Lemmas.distributivity_add_right",
"Prims.pow2",
"Prims.op_Addition",
"Prims.op_Division",
"Prims.unit",
"FStar.Math.Lemmas.paren_mul_right",
"FStar.Mul.op_Star",
"Prims.op_Modulus",
"Prims._assert",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"FStar.Math.Lemmas.pow2_plus",
"FStar.Math.Lemmas.lemma_div_mod",
"Prims.l_True",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let lemma_aux_0 (a b n: nat)
: Lemma
(pow2 n * a + pow2 (n + 56) * b = pow2 n * (a % pow2 56) + pow2 (n + 56) * (b + a / pow2 56)) =
| Math.Lemmas.lemma_div_mod a (pow2 56);
Math.Lemmas.pow2_plus n 56;
assert (a = pow2 56 * (a / pow2 56) + (a % pow2 56));
Math.Lemmas.distributivity_add_right (pow2 n) (pow2 56 * (a / pow2 56)) (a % pow2 56);
Math.Lemmas.paren_mul_right (pow2 n) (pow2 56) (a / pow2 56);
Math.Lemmas.distributivity_add_right (pow2 (n + 56)) b (a / pow2 56) | false |
Hacl.Spec.BignumQ.Lemmas.fst | Hacl.Spec.BignumQ.Lemmas.lemma_1 | val lemma_1 (x y: nat) (c: pos)
: Lemma (requires (x - y < c /\ x >= y))
(ensures
(x - y = (if (x % c) - (y % c) < 0 then c + (x % c) - (y % c) else (x % c) - (y % c)))) | val lemma_1 (x y: nat) (c: pos)
: Lemma (requires (x - y < c /\ x >= y))
(ensures
(x - y = (if (x % c) - (y % c) < 0 then c + (x % c) - (y % c) else (x % c) - (y % c)))) | let lemma_1 (x:nat) (y:nat) (c:pos) : Lemma
(requires (x - y < c /\ x >= y))
(ensures (x - y = (if (x % c) - (y % c) < 0 then c + (x % c) - (y % c)
else (x % c) - (y % c))))
= Math.Lemmas.lemma_div_mod x c;
Math.Lemmas.lemma_div_mod y c;
Math.Lemmas.distributivity_sub_right c (y/c) (x/c);
assert( (x%c) - (y%c) = x - y - c*((x/c) - (y/c)));
lemma_0 x y c | {
"file_name": "code/ed25519/Hacl.Spec.BignumQ.Lemmas.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 17,
"end_line": 864,
"start_col": 0,
"start_line": 856
} | module Hacl.Spec.BignumQ.Lemmas
open FStar.Tactics.CanonCommSemiring
open FStar.Mul
open Lib.IntTypes
module S = Spec.Ed25519
include Hacl.Spec.BignumQ.Definitions
let feq (#a #b:Type) (f:(a -> b)) (x y:a) :
Lemma (requires x == y) (ensures f x == f y) = ()
let eq_eq2 (#a:eqtype) (x y:a) :
Lemma (requires x = y) (ensures x == y) = ()
val lemma_mul_lt:a:nat -> b:nat -> c:nat -> d:nat ->
Lemma
(requires a < b /\ c < d)
(ensures a * c < b * d)
let lemma_mul_lt a b c d = ()
val lemma_as_nat5: f:qelem5 ->
Lemma
(requires qelem_fits5 f (1, 1, 1, 1, 1))
(ensures as_nat5 f < pow2 280)
let lemma_as_nat5 f =
//let (f0, f1, f2, f3, f4) = f in
//assert (as_nat5 f == v f0 + v f1 * pow56 + v f2 * pow112 + v f3 * pow168 + v f4 * pow224);
assert_norm (pow2 56 * pow2 56 = pow2 112);
assert_norm (pow2 56 * pow2 112 = pow2 168);
assert_norm (pow2 56 * pow2 168 = pow2 224);
assert_norm (pow2 56 * pow2 224 = pow2 280)
val lemma_choose_step:
bit:uint64{v bit <= 1}
-> x:uint64
-> y:uint64
-> Lemma
(let mask = bit -. u64 1 in
let z = x ^. (mask &. (x ^. y)) in
if v bit = 1 then z == x else z == y)
let lemma_choose_step bit p1 p2 =
let mask = bit -. u64 1 in
assert (v bit == 0 ==> v mask == pow2 64 - 1);
assert (v bit == 1 ==> v mask == 0);
let dummy = mask &. (p1 ^. p2) in
logand_lemma mask (p1 ^. p2);
assert (v bit == 1 ==> v dummy == 0);
assert (v bit == 0 ==> v dummy == v (p1 ^. p2));
let p1' = p1 ^. dummy in
assert (v dummy == v (if v bit = 1 then u64 0 else (p1 ^. p2)));
logxor_lemma p1 p2
val lemma_subm_conditional:
x0:nat -> x1:nat -> x2:nat -> x3:nat -> x4:nat
-> y0:nat -> y1:nat -> y2:nat -> y3:nat -> y4:nat
-> b0:nat -> b1:nat -> b2:nat -> b3:nat -> b4:nat ->
Lemma (
x0 - y0 + b0 * pow2 56 +
(x1 - y1 - b0 + b1 * pow2 56) * pow2 56 +
(x2 - y2 - b1 + b2 * pow2 56) * pow2 112 +
(x3 - y3 - b2 + b3 * pow2 56) * pow2 168 +
(x4 - y4 - b3 + b4 * pow2 56) * pow2 224 ==
(x0 + x1 * pow2 56 + x2 * pow2 112 + x3 * pow2 168 + x4 * pow2 224) -
(y0 + y1 * pow2 56 + y2 * pow2 112 + y3 * pow2 168 + y4 * pow2 224) + b4 * pow2 280)
let lemma_subm_conditional x0 x1 x2 x3 x4 y0 y1 y2 y3 y4 b0 b1 b2 b3 b4 =
assert_norm (pow2 56 * pow2 56 = pow2 112);
assert_norm (pow2 56 * pow2 112 = pow2 168);
assert_norm (pow2 56 * pow2 168 = pow2 224);
assert_norm (pow2 56 * pow2 224 = pow2 280);
assert (
x0 - y0 + b0 * pow2 56 +
(x1 - y1 - b0 + b1 * pow2 56) * pow2 56 +
(x2 - y2 - b1 + b2 * pow2 56) * pow2 112 +
(x3 - y3 - b2 + b3 * pow2 56) * pow2 168 +
(x4 - y4 - b3 + b4 * pow2 56) * pow2 224 ==
(x0 + x1 * pow2 56 + x2 * pow2 112 + x3 * pow2 168 + x4 * pow2 224) -
(y0 + y1 * pow2 56 + y2 * pow2 112 + y3 * pow2 168 + y4 * pow2 224) + b4 * pow2 280)
by (int_semiring ());
()
val lemma_div224: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1))
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
wide_as_nat5 x / pow2 224 ==
v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280))
#push-options "--z3rlimit 50"
let lemma_div224 x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert
(wide_as_nat5 x ==
v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168 + v x4 * pow2 224 +
v x5 * pow2 280 + v x6 * pow2 336 + v x7 * pow2 392 + v x8 * pow2 448 + v x9 * pow2 504);
assert_norm (pow2 56 * pow2 224 == pow2 280);
assert_norm (pow2 112 * pow2 224 == pow2 336);
assert_norm (pow2 168 * pow2 224 == pow2 392);
assert_norm (pow2 224 * pow2 224 == pow2 448);
assert_norm (pow2 280 * pow2 224 == pow2 504);
calc (==) {
wide_as_nat5 x / pow2 224;
(==) { }
(v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168 +
(v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280) * pow2 224) / pow2 224;
(==) {
FStar.Math.Lemmas.lemma_div_plus
(v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168)
(v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280) (pow2 224) }
(v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168) / pow2 224 +
v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280;
(==) { FStar.Math.Lemmas.small_division_lemma_1 (v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168) (pow2 224) }
v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280;
}
#pop-options
val lemma_div248_aux: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 512)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
wide_as_nat5 x / pow2 248 ==
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256))
open FStar.Tactics.CanonCommSemiring
#push-options "--z3cliopt smt.arith.nl=false"
let lemma_div248_aux x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert_norm (pow2 248 == pow2 224 * pow2 24);
assert_norm (pow2 56 == pow2 32 * pow2 24);
assert_norm (pow2 112 == pow2 88 * pow2 24);
assert_norm (pow2 168 == pow2 144 * pow2 24);
assert_norm (pow2 224 == pow2 200 * pow2 24);
assert_norm (pow2 280 == pow2 256 * pow2 24);
assert_norm (0 < pow2 24);
calc (==) {
wide_as_nat5 x / pow2 248;
(==) { FStar.Math.Lemmas.division_multiplication_lemma (wide_as_nat5 x) (pow2 224) (pow2 24) }
(wide_as_nat5 x / pow2 224) / pow2 24;
(==) { lemma_div224 x }
(v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280) / pow2 24;
(==) { _ by (Tactics.mapply (`feq #int #int (fun x -> x / pow2 24)); int_semiring ()) } (v x4 + (v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256) * pow2 24) / pow2 24;
(==) { FStar.Math.Lemmas.lemma_div_plus (v x4) (v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256) (pow2 24) }
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256;
}
#pop-options
val lemma_div248_x5: x5:uint64 ->
Lemma ( pow2 32 * (v x5 % pow2 24) + v x5 / pow2 24 * pow2 56 == v x5 * pow2 32)
let lemma_div248_x5 x5 =
assert_norm (pow2 32 * pow2 24 = pow2 56)
val lemma_div248_x6: x6:uint64 ->
Lemma (pow2 32 * (v x6 % pow2 24) * pow2 56 + v x6 / pow2 24 * pow2 112 == v x6 * pow2 88)
let lemma_div248_x6 x6 =
calc (==) {
pow2 32 * (v x6 % pow2 24) * pow2 56 + v x6 / pow2 24 * pow2 112;
(==) { _ by (Tactics.norm [delta_only [`%pow2]; primops]; int_semiring ()) }
((v x6 / pow2 24) * pow2 24 + v x6 % pow2 24) * pow2 88;
(==) { FStar.Math.Lemmas.euclidean_division_definition (v x6) (pow2 24) }
v x6 * pow2 88;
}
val lemma_div248_x7: x7:uint64 ->
Lemma (pow2 32 * (v x7 % pow2 24) * pow2 112 + v x7 / pow2 24 * pow2 168 == v x7 * pow2 144)
let lemma_div248_x7 x7 =
calc (==) {
pow2 32 * (v x7 % pow2 24) * pow2 112 + v x7 / pow2 24 * pow2 168;
(==) { _ by (Tactics.norm [delta_only [`%pow2]; primops]; int_semiring ()) }
((v x7 / pow2 24) * pow2 24 + v x7 % pow2 24) * pow2 144;
(==) { FStar.Math.Lemmas.euclidean_division_definition (v x7) (pow2 24) }
v x7 * pow2 144;
}
val lemma_div248_x8: x8:uint64 ->
Lemma (pow2 32 * (v x8 % pow2 24) * pow2 168 + v x8 / pow2 24 * pow2 224 == v x8 * pow2 200)
let lemma_div248_x8 x8 =
calc (==) {
pow2 32 * (v x8 % pow2 24) * pow2 168 + v x8 / pow2 24 * pow2 224;
(==) { _ by (Tactics.norm [delta_only [`%pow2]; primops]; int_semiring ()) }
((v x8 / pow2 24) * pow2 24 + v x8 % pow2 24) * pow2 200;
(==) { FStar.Math.Lemmas.euclidean_division_definition (v x8) (pow2 24) }
v x8 * pow2 200;
}
val lemma_div248_x9: x9:uint64{v x9 < pow2 24} ->
Lemma (pow2 32 * (v x9 % pow2 24) * pow2 224 == v x9 * pow2 256)
let lemma_div248_x9 x9 =
calc (==) {
pow2 32 * (v x9 % pow2 24) * pow2 224;
(==) { Math.Lemmas.small_mod (v x9) (pow2 24) }
pow2 32 * v x9 * pow2 224;
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
v x9 * pow2 256;
}
val lemma_wide_as_nat_pow512: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 512)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
v x9 < pow2 24))
let lemma_wide_as_nat_pow512 x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert_norm (pow2 504 * pow2 8 = pow2 512);
FStar.Math.Lemmas.pow2_minus 512 504;
assert (v x9 < pow2 8);
assert_norm (pow2 8 < pow2 24)
val lemma_div248: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 512)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
let z0 = v x4 / pow2 24 + pow2 32 * (v x5 % pow2 24) in
let z1 = v x5 / pow2 24 + pow2 32 * (v x6 % pow2 24) in
let z2 = v x6 / pow2 24 + pow2 32 * (v x7 % pow2 24) in
let z3 = v x7 / pow2 24 + pow2 32 * (v x8 % pow2 24) in
let z4 = v x8 / pow2 24 + pow2 32 * (v x9 % pow2 24) in
wide_as_nat5 x / pow2 248 == z0 + z1 * pow2 56 + z2 * pow2 112 + z3 * pow2 168 + z4 * pow2 224))
#push-options "--z3rlimit 50"
let lemma_div248 x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
lemma_wide_as_nat_pow512 x;
assert (v x9 < pow2 24);
calc (==) {
(let z0 = v x4 / pow2 24 + pow2 32 * (v x5 % pow2 24) in
let z1 = v x5 / pow2 24 + pow2 32 * (v x6 % pow2 24) in
let z2 = v x6 / pow2 24 + pow2 32 * (v x7 % pow2 24) in
let z3 = v x7 / pow2 24 + pow2 32 * (v x8 % pow2 24) in
let z4 = v x8 / pow2 24 + pow2 32 * (v x9 % pow2 24) in
z0 + z1 * pow2 56 + z2 * pow2 112 + z3 * pow2 168 + z4 * pow2 224);
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
v x4 / pow2 24 + pow2 32 * (v x5 % pow2 24) +
v x5 / pow2 24 * pow2 56 + pow2 32 * (v x6 % pow2 24) * pow2 56 +
v x6 / pow2 24 * pow2 112 + pow2 32 * (v x7 % pow2 24) * pow2 112 +
v x7 / pow2 24 * pow2 168 + pow2 32 * (v x8 % pow2 24) * pow2 168 +
v x8 / pow2 24 * pow2 224 + pow2 32 * (v x9 % pow2 24) * pow2 224;
(==) { lemma_div248_x5 x5; lemma_div248_x6 x6 }
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 +
pow2 32 * (v x7 % pow2 24) * pow2 112 +
v x7 / pow2 24 * pow2 168 + pow2 32 * (v x8 % pow2 24) * pow2 168 +
v x8 / pow2 24 * pow2 224 + pow2 32 * (v x9 % pow2 24) * pow2 224;
(==) { lemma_div248_x7 x7; lemma_div248_x8 x8 }
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 +
pow2 32 * (v x9 % pow2 24) * pow2 224;
(==) { lemma_div248_x9 x9 }
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256;
(==) { lemma_div248_aux x }
wide_as_nat5 x / pow2 248;
}
#pop-options
val lemma_add_modq5:
x:qelem5
-> y:qelem5
-> t:qelem5 ->
Lemma
(requires
qelem_fits5 x (1, 1, 1, 1, 1) /\
qelem_fits5 y (1, 1, 1, 1, 1) /\
qelem_fits5 t (1, 1, 1, 1, 1) /\
as_nat5 x < S.q /\ as_nat5 y < S.q /\
as_nat5 t == as_nat5 x + as_nat5 y)
(ensures
(let res = if as_nat5 t >= S.q then as_nat5 t - S.q else as_nat5 t in
res < S.q /\ res == (as_nat5 x + as_nat5 y) % S.q))
let lemma_add_modq5 x y t =
assert (as_nat5 t == as_nat5 x + as_nat5 y);
let res = if as_nat5 t >= S.q then as_nat5 t - S.q else as_nat5 t in
assert (res < S.q);
if as_nat5 t >= S.q then (
FStar.Math.Lemmas.sub_div_mod_1 (as_nat5 t) S.q;
assert (res % S.q == as_nat5 t % S.q))
else
assert (res % S.q == as_nat5 t % S.q);
FStar.Math.Lemmas.small_mod res S.q
val lemma_wide_as_nat_pow528: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 528)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
v x9 < pow2 40))
let lemma_wide_as_nat_pow528 x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert_norm (pow2 504 * pow2 24 = pow2 528);
FStar.Math.Lemmas.pow2_minus 528 504;
assert (v x9 < pow2 24);
assert_norm (pow2 24 < pow2 40)
#push-options "--z3cliopt smt.arith.nl=false"
val lemma_div264_aux: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 528)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
wide_as_nat5 x / pow2 264 ==
v x4 / pow2 40 + v x5 * pow2 16 + v x6 * pow2 72 + v x7 * pow2 128 + v x8 * pow2 184 + v x9 * pow2 240))
let lemma_div264_aux x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert_norm (pow2 264 == pow2 224 * pow2 40);
assert_norm (pow2 56 == pow2 16 * pow2 40);
assert_norm (pow2 112 == pow2 72 * pow2 40);
assert_norm (pow2 168 == pow2 128 * pow2 40);
assert_norm (pow2 224 == pow2 184 * pow2 40);
assert_norm (pow2 280 == pow2 240 * pow2 40);
assert_norm (0 < pow2 40);
calc (==) {
wide_as_nat5 x / pow2 264;
(==) { FStar.Math.Lemmas.division_multiplication_lemma (wide_as_nat5 x) (pow2 224) (pow2 40) }
(wide_as_nat5 x / pow2 224) / pow2 40;
(==) { lemma_div224 x }
(v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280) / pow2 40;
(==) { _ by (Tactics.mapply (`feq #int #int (fun x -> x / pow2 40)); int_semiring ()) }
(v x4 + (v x5 * pow2 16 + v x6 * pow2 72 + v x7 * pow2 128 + v x8 * pow2 184 + v x9 * pow2 240) * pow2 40) / pow2 40;
(==) { FStar.Math.Lemmas.lemma_div_plus (v x4) (v x5 * pow2 16 + v x6 * pow2 72 + v x7 * pow2 128 + v x8 * pow2 184 + v x9 * pow2 240) (pow2 40) }
v x4 / pow2 40 + v x5 * pow2 16 + v x6 * pow2 72 + v x7 * pow2 128 + v x8 * pow2 184 + v x9 * pow2 240;
}
val lemma_div264_x5: x5:uint64 ->
Lemma (pow2 16 * (v x5 % pow2 40) + v x5 / pow2 40 * pow2 56 == v x5 * pow2 16)
let lemma_div264_x5 x5 =
assert_norm (0 < pow2 24);
calc (==) {
pow2 16 * (v x5 % pow2 40) + v x5 / pow2 40 * pow2 56;
(==) { _ by (Tactics.norm [delta_only [`%pow2]; primops]; int_semiring ()) }
((v x5 / pow2 40) * pow2 40 + v x5 % pow2 40) * pow2 16;
(==) { FStar.Math.Lemmas.euclidean_division_definition (v x5) (pow2 40) }
v x5 * pow2 16;
}
val lemma_div264_x6: x6:uint64 ->
Lemma (pow2 16 * (v x6 % pow2 40) * pow2 56 + v x6 / pow2 40 * pow2 112 == v x6 * pow2 72)
let lemma_div264_x6 x6 =
calc (==) {
pow2 16 * (v x6 % pow2 40) * pow2 56 + v x6 / pow2 40 * pow2 112;
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
((v x6 / pow2 40) * pow2 40 + v x6 % pow2 40) * pow2 72;
(==) { Math.Lemmas.euclidean_division_definition (v x6) (pow2 40) }
v x6 * pow2 72;
}
val lemma_div264_x7: x7:uint64 ->
Lemma (pow2 16 * (v x7 % pow2 40) * pow2 112 + v x7 / pow2 40 * pow2 168 == v x7 * pow2 128)
let lemma_div264_x7 x7 =
calc (==) {
pow2 16 * (v x7 % pow2 40) * pow2 112 + v x7 / pow2 40 * pow2 168;
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
((v x7 / pow2 40) * pow2 40 + v x7 % pow2 40) * pow2 128;
(==) { Math.Lemmas.euclidean_division_definition (v x7) (pow2 40) }
v x7 * pow2 128;
}
val lemma_div264_x8: x8:uint64 ->
Lemma (pow2 16 * (v x8 % pow2 40) * pow2 168 + v x8 / pow2 40 * pow2 224 == v x8 * pow2 184)
let lemma_div264_x8 x8 =
calc (==) {
pow2 16 * (v x8 % pow2 40) * pow2 168 + v x8 / pow2 40 * pow2 224;
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
((v x8 / pow2 40) * pow2 40 + v x8 % pow2 40) * pow2 184;
(==) { Math.Lemmas.euclidean_division_definition (v x8) (pow2 40) }
v x8 * pow2 184;
}
val lemma_div264_x9: x9:uint64{v x9 < pow2 40} ->
Lemma (pow2 16 * (v x9 % pow2 40) * pow2 224 == v x9 * pow2 240)
let lemma_div264_x9 x9 =
calc (==) {
pow2 16 * (v x9 % pow2 40) * pow2 224;
(==) { Math.Lemmas.small_mod (v x9) (pow2 40) }
pow2 16 * v x9 * pow2 224;
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
v x9 * pow2 240;
}
val lemma_div264: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 528)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
let z0 = v x4 / pow2 40 + pow2 16 * (v x5 % pow2 40) in
let z1 = v x5 / pow2 40 + pow2 16 * (v x6 % pow2 40) in
let z2 = v x6 / pow2 40 + pow2 16 * (v x7 % pow2 40) in
let z3 = v x7 / pow2 40 + pow2 16 * (v x8 % pow2 40) in
let z4 = v x8 / pow2 40 + pow2 16 * (v x9 % pow2 40) in
wide_as_nat5 x / pow2 264 == z0 + z1 * pow2 56 + z2 * pow2 112 + z3 * pow2 168 + z4 * pow2 224))
#push-options "--z3rlimit 50"
let lemma_div264 x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
lemma_wide_as_nat_pow528 x;
assert (v x9 < pow2 40);
calc (==) {
(let z0 = v x4 / pow2 40 + pow2 16 * (v x5 % pow2 40) in
let z1 = v x5 / pow2 40 + pow2 16 * (v x6 % pow2 40) in
let z2 = v x6 / pow2 40 + pow2 16 * (v x7 % pow2 40) in
let z3 = v x7 / pow2 40 + pow2 16 * (v x8 % pow2 40) in
let z4 = v x8 / pow2 40 + pow2 16 * (v x9 % pow2 40) in
z0 + z1 * pow2 56 + z2 * pow2 112 + z3 * pow2 168 + z4 * pow2 224);
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
v x4 / pow2 40 + pow2 16 * (v x5 % pow2 40) +
v x5 / pow2 40 * pow2 56 + pow2 16 * (v x6 % pow2 40) * pow2 56 +
v x6 / pow2 40 * pow2 112 + pow2 16 * (v x7 % pow2 40) * pow2 112 +
v x7 / pow2 40 * pow2 168 + pow2 16 * (v x8 % pow2 40) * pow2 168 +
v x8 / pow2 40 * pow2 224 + pow2 16 * (v x9 % pow2 40) * pow2 224;
(==) { lemma_div264_x5 x5; lemma_div264_x6 x6 }
v x4 / pow2 40 + v x5 * pow2 16 + v x6 * pow2 72 +
pow2 16 * (v x7 % pow2 40) * pow2 112 +
v x7 / pow2 40 * pow2 168 + pow2 16 * (v x8 % pow2 40) * pow2 168 +
v x8 / pow2 40 * pow2 224 + pow2 16 * (v x9 % pow2 40) * pow2 224;
(==) { lemma_div264_x7 x7; lemma_div264_x8 x8 }
v x4 / pow2 40 + v x5 * pow2 16 + v x6 * pow2 72 + v x7 * pow2 128 + v x8 * pow2 184 +
pow2 16 * (v x9 % pow2 40) * pow2 224;
(==) { lemma_div264_x9 x9 }
v x4 / pow2 40 + v x5 * pow2 16 + v x6 * pow2 72 + v x7 * pow2 128 + v x8 * pow2 184 + v x9 * pow2 240;
(==) { lemma_div264_aux x }
wide_as_nat5 x / pow2 264;
}
#pop-options
#pop-options // "--z3cliopt smt.arith.nl=false"
val lemma_mod_264_aux: t:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 t (1, 1, 1, 1, 1, 1, 1, 1, 1, 1))
(ensures
(let (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) = t in
(wide_as_nat5 t) % pow2 264 ==
(v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + v t4 * pow2 224) % pow2 264))
#push-options "--z3rlimit 150"
let lemma_mod_264_aux t =
let (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) = t in
let res = (t0, t1, t2, t3, t4 &. u64 0xffffffffff) in
assert_norm (pow2 16 * pow2 264 == pow2 280);
assert_norm (pow2 72 * pow2 264 == pow2 336);
assert_norm (pow2 128 * pow2 264 == pow2 392);
assert_norm (pow2 184 * pow2 264 == pow2 448);
assert_norm (pow2 240 * pow2 264 == pow2 504);
calc (==) {
(wide_as_nat5 t) % pow2 264;
(==) { }
(v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + v t4 * pow2 224 +
(v t5 * pow2 16 + v t6 * pow2 72 + v t7 * pow2 128 + v t8 * pow2 184 + v t9 * pow2 240) * pow2 264) % pow2 264;
(==) { FStar.Math.Lemmas.lemma_mod_add_distr (v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + v t4 * pow2 224)
((v t5 * pow2 16 + v t6 * pow2 72 + v t7 * pow2 128 + v t8 * pow2 184 + v t9 * pow2 240) * pow2 264) (pow2 264)}
((v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + v t4 * pow2 224) +
((v t5 * pow2 16 + v t6 * pow2 72 + v t7 * pow2 128 + v t8 * pow2 184 + v t9 * pow2 240) * pow2 264) % pow2 264) % pow2 264;
(==) { FStar.Math.Lemmas.cancel_mul_mod (v t5 * pow2 16 + v t6 * pow2 72 + v t7 * pow2 128 + v t8 * pow2 184 + v t9 * pow2 240) (pow2 264) }
(v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + v t4 * pow2 224) % pow2 264;
}
#pop-options
val lemma_as_nat_pow264: x:qelem5 ->
Lemma
(requires
(let (x0, x1, x2, x3, x4) = x in
qelem_fits5 x (1, 1, 1, 1, 1) /\
v x4 < pow2 40))
(ensures as_nat5 x < pow2 264)
let lemma_as_nat_pow264 x =
let (x0, x1, x2, x3, x4) = x in
assert_norm (pow2 40 * pow2 224 = pow2 264)
val lemma_mod_264: t:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 t (1, 1, 1, 1, 1, 1, 1, 1, 1, 1))
(ensures
(let (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) = t in
let res = (t0, t1, t2, t3, t4 &. u64 0xffffffffff) in
qelem_fits5 res (1, 1, 1, 1, 1) /\
as_nat5 res == (wide_as_nat5 t) % pow2 264))
let lemma_mod_264 t =
let (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) = t in
let t4' = t4 &. u64 0xffffffffff in
let res = (t0, t1, t2, t3, t4') in
assert_norm (pow2 40 < pow2 64);
assert_norm (pow2 40 - 1 == 0xffffffffff);
mod_mask_lemma t4 40ul;
assert (v (mod_mask #U64 #SEC 40ul) == 0xffffffffff);
assert (v (t4 &. u64 0xffffffffff) == v t4 % pow2 40);
calc (==) {
(wide_as_nat5 t) % pow2 264;
(==) { lemma_mod_264_aux t }
(v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + v t4 * pow2 224) % pow2 264;
(==) { FStar.Math.Lemmas.lemma_mod_add_distr (v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168) (v t4 * pow2 224) (pow2 264) }
(v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + (v t4 * pow2 224) % pow2 264) % pow2 264;
(==) { FStar.Math.Lemmas.pow2_multiplication_modulo_lemma_2 (v t4) 264 224 }
(v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + (v t4 % pow2 40) * pow2 224) % pow2 264;
(==) { lemma_as_nat_pow264 res; FStar.Math.Lemmas.modulo_lemma (as_nat5 res) (pow2 264) }
v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + (v t4 % pow2 40) * pow2 224;
}
val lemma_as_nat_pow264_x4: x:qelem5 ->
Lemma
(requires
qelem_fits5 x (1, 1, 1, 1, 1) /\
as_nat5 x < pow2 264)
(ensures
(let (x0, x1, x2, x3, x4) = x in
v x4 < pow2 40))
let lemma_as_nat_pow264_x4 x =
let (x0, x1, x2, x3, x4) = x in
assert_norm (pow2 40 * pow2 224 = pow2 264)
val lemma_sub_mod_264_aux:
x0:nat -> x1:nat -> x2:nat -> x3:nat -> x4:nat
-> y0:nat -> y1:nat -> y2:nat -> y3:nat -> y4:nat
-> c1:nat -> c2:nat -> c3:nat -> c4:nat -> c5:nat ->
Lemma (
x0 - y0 + c1 * pow56 +
(x1 - y1 - c1 + c2 * pow56) * pow56 +
(x2 - y2 - c2 + c3 * pow56) * pow112 +
(x3 - y3 - c3 + c4 * pow56) * pow168 +
(x4 - y4 - c4 + pow2 40 * c5) * pow224 ==
(x0 + x1 * pow2 56 + x2 * pow2 112 + x3 * pow2 168 + x4 * pow2 224) -
(y0 + y1 * pow2 56 + y2 * pow2 112 + y3 * pow2 168 + y4 * pow2 224) + c5 * pow2 264)
#push-options "--z3rlimit 50"
let lemma_sub_mod_264_aux x0 x1 x2 x3 x4 y0 y1 y2 y3 y4 b0 b1 b2 b3 b4 =
assert_norm (pow2 56 * pow2 56 = pow2 112);
assert_norm (pow2 56 * pow2 112 = pow2 168);
assert_norm (pow2 56 * pow2 168 = pow2 224);
assert_norm (pow2 40 * pow2 224 = pow2 264)
#pop-options
val lemma_sub_mod_264:
x:qelem5
-> y:qelem5
-> t:qelem5
-> c5:uint64 ->
Lemma
(requires
qelem_fits5 x (1, 1, 1, 1, 1) /\
qelem_fits5 y (1, 1, 1, 1, 1) /\
qelem_fits5 t (1, 1, 1, 1, 1) /\
as_nat5 x < pow2 264 /\
as_nat5 y < pow2 264 /\
as_nat5 t == as_nat5 x - as_nat5 y + v c5 * pow2 264 /\ v c5 <= 1 /\
(if v c5 = 0 then as_nat5 x >= as_nat5 y else as_nat5 x < as_nat5 y))
(ensures
(if as_nat5 x >= as_nat5 y then
as_nat5 t == as_nat5 x - as_nat5 y
else as_nat5 t == as_nat5 x - as_nat5 y + pow2 264))
#push-options "--z3rlimit 50"
let lemma_sub_mod_264 x y t c5 =
assert (if v c5 = 0 then as_nat5 x >= as_nat5 y else as_nat5 x < as_nat5 y);
assert (as_nat5 t == as_nat5 x - as_nat5 y + v c5 * pow2 264);
if as_nat5 x >= as_nat5 y then
assert (v c5 == 0 /\ as_nat5 t == as_nat5 x - as_nat5 y)
else
assert (v c5 == 1 /\ as_nat5 t == as_nat5 x - as_nat5 y + pow2 264)
#pop-options
let lemma_mul_qelem5 (x0 x1 x2 x3 x4 y0 y1 y2 y3 y4:nat) : Lemma
((x0 + x1 * pow2 56 + x2 * pow2 112 + x3 * pow2 168 + x4 * pow2 224) *
(y0 + y1 * pow2 56 + y2 * pow2 112 + y3 * pow2 168 + y4 * pow2 224) ==
x0 * y0 +
(x0 * y1 + x1 * y0) * pow56 +
(x0 * y2 + x1 * y1 + x2 * y0) * pow112 +
(x0 * y3 + x1 * y2 + x2 * y1 + x3 * y0) * pow168 +
(x0 * y4 + x1 * y3 + x2 * y2 + x3 * y1 + x4 * y0) * pow224 +
(x1 * y4 + x2 * y3 + x3 * y2 + x4 * y1) * pow280 +
(x2 * y4 + x3 * y3 + x4 * y2) * pow336 +
(x3 * y4 + x4 * y3) * pow392 +
(x4 * y4) * pow448)
=
assert ((x0 + x1 * pow2 56 + x2 * pow2 112 + x3 * pow2 168 + x4 * pow2 224) *
(y0 + y1 * pow2 56 + y2 * pow2 112 + y3 * pow2 168 + y4 * pow2 224) ==
x0 * y0 +
(x0 * y1 + x1 * y0) * pow56 +
(x0 * y2 + x1 * y1 + x2 * y0) * pow112 +
(x0 * y3 + x1 * y2 + x2 * y1 + x3 * y0) * pow168 +
(x0 * y4 + x1 * y3 + x2 * y2 + x3 * y1 + x4 * y0) * pow224 +
(x1 * y4 + x2 * y3 + x3 * y2 + x4 * y1) * pow280 +
(x2 * y4 + x3 * y3 + x4 * y2) * pow336 +
(x3 * y4 + x4 * y3) * pow392 +
(x4 * y4) * pow448)
by (Tactics.norm [zeta; iota; delta; primops]; int_semiring ())
val lemma_mul_5_low_264:
x1:nat -> x2:nat -> x3:nat -> x4:nat -> x5:nat ->
y1:nat -> y2:nat -> y3:nat -> y4:nat -> y5:nat ->
Lemma (
(x1 * y1) >= 0
/\ (x2 * y1 + x1 * y2 + ((x1 * y1) / pow2 56)) >= 0
/\ (x3 * y1 + x2 * y2 + x1 * y3 + ((x2 * y1 + x1 * y2 + ((x1 * y1) / pow2 56)) / pow2 56)) >= 0
/\ (x4 * y1 + x3 * y2 + x2 * y3 + x1 * y4 + ((x3 * y1 + x2 * y2 + x1 * y3 + ((x2 * y1 + x1 * y2 + ((x1 * y1) / pow2 56)) / pow2 56)) / pow2 56)) >= 0
/\ (
let a0 = (x1 * y1) % pow2 56 in
let a1 = ((x2 * y1 + x1 * y2 + ((x1 * y1) / pow2 56)) % pow2 56) in
let a2 = ((x3 * y1 + x2 * y2 + x1 * y3 + ((x2 * y1 + x1 * y2 + ((x1 * y1) / pow2 56)) / pow2 56)) % pow2 56) in
let a3 = ((x4 * y1 + x3 * y2 + x2 * y3 + x1 * y4 + ((x3 * y1 + x2 * y2 + x1 * y3 + ((x2 * y1 + x1 * y2 + ((x1 * y1) / pow2 56)) / pow2 56)) / pow2 56)) % pow2 56) in
let a4 = (x5 * y1 + x4 * y2 + x3 * y3 + x2 * y4 + x1 * y5 + ((x4 * y1 + x3 * y2 + x2 * y3 + x1 * y4 + ((x3 * y1 + x2 * y2 + x1 * y3 + ((x2 * y1 + x1 * y2 + ((x1 * y1) / pow2 56)) / pow2 56)) / pow2 56)) / pow2 56)) in
((x1 + pow2 56 * x2 + pow2 112 * x3 + pow2 168 * x4 + pow2 224 * x5)
* (y1 + pow2 56 * y2 + pow2 112 * y3 + pow2 168 * y4 + pow2 224 * y5)) % pow2 264
== a0 + pow2 56 * a1 + pow2 112 * a2 + pow2 168 * a3 + pow2 224 * (a4 % pow2 40)))
private let lemma_mul_nat_is_nat (a:nat) (b:nat) : Lemma (a*b >= 0) = ()
private let lemma_div_nat_is_nat (a:nat) (b:pos) : Lemma (a/b >= 0) = ()
private
val lemma_mul_5''':
x1:nat -> x2:nat -> x3:nat -> x4:nat -> x5:nat ->
y1:nat -> y2:nat -> y3:nat -> y4:nat -> y5:nat ->
Lemma (((x1 + pow2 56 * x2 + pow2 112 * x3 + pow2 168 * x4 + pow2 224 * x5)
* (y1 + pow2 56 * y2 + pow2 112 * y3 + pow2 168 * y4 + pow2 224 * y5)) % pow2 264
==
(x1 * y1
+ pow2 56 * (x2 * y1 + x1 * y2)
+ pow2 112 * (x3 * y1 + x2 * y2 + x1 * y3)
+ pow2 168 * (x4 * y1 + x3 * y2 + x2 * y3 + x1 * y4)
+ pow2 224 * (x5 * y1 + x4 * y2 + x3 * y3 + x2 * y4 + x1 * y5)) % pow2 264)
let lemma_mul_5''' x1 x2 x3 x4 x5 y1 y2 y3 y4 y5 =
calc (==) {
((x1 + pow2 56 * x2 + pow2 112 * x3 + pow2 168 * x4 + pow2 224 * x5)
* (y1 + pow2 56 * y2 + pow2 112 * y3 + pow2 168 * y4 + pow2 224 * y5)) % pow2 264;
(==) { _ by (Tactics.mapply (`feq #int #int (fun x -> x % pow2 264));
Tactics.norm [zeta; iota; delta; primops];
int_semiring ()) }
(x1 * y1
+ pow2 56 * (x2 * y1 + x1 * y2)
+ pow2 112 * (x3 * y1 + x2 * y2 + x1 * y3)
+ pow2 168 * (x4 * y1 + x3 * y2 + x2 * y3 + x1 * y4)
+ pow2 224 * (x5 * y1 + x4 * y2 + x3 * y3 + x2 * y4 + x1 * y5)
+ (pow2 16 * x2 * y5 +
pow2 16 * x3 * y4 + pow2 72 * x3 * y5 +
pow2 16 * x4 * y3 + pow2 72 * x4 * y4 + pow2 128 * x4 * y5 +
pow2 16 * x5 * y2 + pow2 72 * x5 * y3 + pow2 128 * x5 * y4 + pow2 184 * x5 * y5) * pow2 264) % pow2 264;
(==) { _ by (Tactics.mapply (`eq_eq2); Tactics.mapply (`Math.Lemmas.lemma_mod_plus)) }
(x1 * y1
+ pow2 56 * (x2 * y1 + x1 * y2)
+ pow2 112 * (x3 * y1 + x2 * y2 + x1 * y3)
+ pow2 168 * (x4 * y1 + x3 * y2 + x2 * y3 + x1 * y4)
+ pow2 224 * (x5 * y1 + x4 * y2 + x3 * y3 + x2 * y4 + x1 * y5)) % pow2 264;
}
private val lemma_mod_264'':
a0:nat -> a1:nat-> a2:nat -> a3:nat -> a4:nat ->
Lemma
(requires a0 < pow56 /\ a1 < pow56 /\ a2 < pow56 /\ a3 < pow56)
(ensures a0 + pow2 56 * a1 + pow2 112 * a2 + pow2 168 * a3 + pow2 224 * (a4 % pow2 40) < pow2 264)
let lemma_mod_264'' a0 a1 a2 a3 a4 =
assert_norm(pow2 40 = 0x10000000000);
assert_norm(pow2 56 = 0x100000000000000);
assert_norm(pow2 112 = 0x10000000000000000000000000000);
assert_norm(pow2 168 = 0x1000000000000000000000000000000000000000000);
assert_norm(pow2 224 = 0x100000000000000000000000000000000000000000000000000000000);
assert_norm(pow2 264 = 0x1000000000000000000000000000000000000000000000000000000000000000000)
private val lemma_mod_264':
a0:nat -> a1:nat-> a2:nat -> a3:nat -> a4:nat ->
Lemma
(requires a0 < pow56 /\ a1 < pow56 /\ a2 < pow56 /\ a3 < pow56)
(ensures (a0
+ pow2 56 * a1
+ pow2 112 * a2
+ pow2 168 * a3
+ pow2 224 * a4) % pow2 264 =
a0
+ pow2 56 * a1
+ pow2 112 * a2
+ pow2 168 * a3
+ pow2 224 * (a4 % pow2 40) )
let lemma_mod_264' a0 a1 a2 a3 a4 =
assert_norm(pow2 56 = 0x100000000000000);
assert_norm(pow2 112 = 0x10000000000000000000000000000);
assert_norm(pow2 168 = 0x1000000000000000000000000000000000000000000);
assert_norm(pow2 224 = 0x100000000000000000000000000000000000000000000000000000000);
Math.Lemmas.lemma_mod_plus_distr_l (pow2 224 * a4) (a0 + pow2 56 * a1 + pow2 112 * a2 + pow2 168 * a3) (pow2 264);
Math.Lemmas.pow2_multiplication_modulo_lemma_2 a4 264 224;
lemma_mod_264'' a0 a1 a2 a3 a4;
Math.Lemmas.modulo_lemma (a0 + pow2 56 * a1 + pow2 112 * a2 + pow2 168 * a3 + pow2 224 * (a4 % pow2 40)) (pow2 264)
private let lemma_aux_0 (a:nat) (b:nat) (n:nat) : Lemma
(pow2 n * a + pow2 (n+56) * b = pow2 n * (a % pow2 56) + pow2 (n+56) * (b + a / pow2 56))
= Math.Lemmas.lemma_div_mod a (pow2 56);
Math.Lemmas.pow2_plus n 56;
assert(a = pow2 56 * (a / pow2 56) + (a % pow2 56));
Math.Lemmas.distributivity_add_right (pow2 n) (pow2 56 * (a / pow2 56)) (a % pow2 56);
Math.Lemmas.paren_mul_right (pow2 n) (pow2 56) (a / pow2 56);
Math.Lemmas.distributivity_add_right (pow2 (n+56)) b (a / pow2 56)
private
val lemma_mod_264_small:
a0:nat -> a1:nat -> a2:nat -> a3:nat -> a4:nat ->
Lemma ( (a0 + pow2 56 * a1 + pow2 112 * a2 + pow2 168 * a3 + pow2 224 * a4)
= (a0 % pow2 56)
+ pow2 56 * ((a1 + (a0 / pow2 56)) % pow2 56)
+ pow2 112 * ((a2 + ((a1 + (a0 / pow2 56)) / pow2 56)) % pow2 56)
+ pow2 168 * ((a3 + ((a2 + ((a1 + (a0 / pow2 56)) / pow2 56)) / pow2 56)) % pow2 56)
+ pow2 224 * (a4 + ((a3 + ((a2 + ((a1 + (a0 / pow2 56)) / pow2 56)) / pow2 56)) / pow2 56)))
(* These silly lemmas needed to guide the proof below... *)
private let aux_nat_over_pos (p : nat) (q : pos) : Lemma (p / q >= 0) = ()
private let aux_nat_plus_nat (p : nat) (q : nat) : Lemma (p + q >= 0) = ()
let lemma_mod_264_small a0 a1 a2 a3 a4 =
Math.Lemmas.lemma_div_mod a0 (pow2 56);
Math.Lemmas.distributivity_add_right (pow2 56) a1 (a0 / pow2 56);
(**) aux_nat_over_pos a0 (pow2 56);
(**) aux_nat_plus_nat a1 (a0 / pow2 56);
let a1':nat = (a1 + (a0 / pow2 56)) in
(**) aux_nat_over_pos a1' (pow2 56);
(**) aux_nat_plus_nat a2 (a1' / pow2 56);
let a2':nat = (a2 + (a1' / pow2 56)) in
(**) aux_nat_over_pos a2' (pow2 56);
(**) aux_nat_plus_nat a3 (a2' / pow2 56);
let a3':nat = (a3 + (a2' / pow2 56)) in
lemma_aux_0 a1' a2 56;
lemma_aux_0 a2' a3 112;
lemma_aux_0 a3' a4 168
private
val lemma_mod_264_:
a0:nat -> a1:nat -> a2:nat -> a3:nat -> a4:nat ->
Lemma ((a0 + pow2 56 * a1 + pow2 112 * a2 + pow2 168 * a3 + pow2 224 * a4) % pow2 264 =
(a0 % pow2 56)
+ pow2 56 * ((a1 + (a0 / pow2 56)) % pow2 56)
+ pow2 112 * ((a2 + ((a1 + (a0 / pow2 56)) / pow2 56)) % pow2 56)
+ pow2 168 * ((a3 + ((a2 + ((a1 + (a0 / pow2 56)) / pow2 56)) / pow2 56)) % pow2 56)
+ pow2 224 * ((a4 + ((a3 + ((a2 + ((a1 + (a0 / pow2 56)) / pow2 56)) / pow2 56)) / pow2 56)) % pow2 40))
let lemma_mod_264_ a0 a1 a2 a3 a4 =
lemma_mod_264_small a0 a1 a2 a3 a4;
let x0 = a0 % pow2 56 in
assert (x0 < pow56);
let x1 = ((a1 + (a0 / pow2 56)) % pow2 56) in
assert (x1 < pow56);
let x2 = ((a2 + ((a1 + (a0 / pow2 56)) / pow2 56)) % pow2 56) in
assert (x2 < pow56);
let x3 = ((a3 + ((a2 + ((a1 + (a0 / pow2 56)) / pow2 56)) / pow2 56)) % pow2 56) in
assert (x3 < pow56);
lemma_mod_264' x0 x1 x2 x3 (a4 + ((a3 + ((a2 + ((a1 + (a0 / pow2 56)) / pow2 56)) / pow2 56)) / pow2 56))
#push-options "--z3rlimit 50"
let lemma_mul_5_low_264 x1 x2 x3 x4 x5 y1 y2 y3 y4 y5 =
lemma_div_nat_is_nat (x1 * y1) (pow2 56);
lemma_div_nat_is_nat (x2 * y1 + x1 * y2 + ((x1 * y1) / pow2 56)) (pow2 56);
lemma_div_nat_is_nat (x3 * y1 + x2 * y2 + x1 * y3 + ((x2 * y1 + x1 * y2 + ((x1 * y1) / pow2 56)) / pow2 56)) (pow2 56);
lemma_div_nat_is_nat (x4 * y1 + x3 * y2 + x2 * y3 + x1 * y4 + ((x3 * y1 + x2 * y2 + x1 * y3 + ((x2 * y1 + x1 * y2 + ((x1 * y1) / pow2 56)) / pow2 56)) / pow2 56)) (pow2 56);
lemma_mul_5''' x1 x2 x3 x4 x5 y1 y2 y3 y4 y5;
lemma_mod_264_ (x1 * y1) (x2 * y1 + x1 * y2) (x3 * y1 + x2 * y2 + x1 * y3) (x4 * y1 + x3 * y2 + x2 * y3 + x1 * y4) (x5 * y1 + x4 * y2 + x3 * y3 + x2 * y4 + x1 * y5)
#pop-options
private
val lemma_optimized_barrett_reduce:
a:nat{a < pow2 512} ->
Lemma (a - (((a / pow2 248) * (pow2 512 / S.q)) / pow2 264) * S.q < 2 * S.q
/\ a - (((a / pow2 248) * (pow2 512 / S.q)) / pow2 264) * S.q >= 0)
#push-options "--z3rlimit 50"
let lemma_optimized_barrett_reduce a =
assert_norm (pow2 248 = 0x100000000000000000000000000000000000000000000000000000000000000);
assert_norm (pow2 264 = 0x1000000000000000000000000000000000000000000000000000000000000000000);
assert_norm (S.q == 0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed);
assert_norm (0x100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 == pow2 512)
#pop-options
private
val lemma_optimized_barrett_reduce2:
a:nat{a < pow2 512} ->
Lemma (a - ((a * (pow2 512 / S.q)) / pow2 512) * S.q < pow2 264 /\
a - ((a * (pow2 512 / S.q)) / pow2 512) * S.q >= 0)
#push-options "--z3rlimit 50"
let lemma_optimized_barrett_reduce2 a =
assert_norm (pow2 248 = 0x100000000000000000000000000000000000000000000000000000000000000);
assert_norm (pow2 264 = 0x1000000000000000000000000000000000000000000000000000000000000000000);
assert_norm (S.q == 0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed);
assert_norm (0x100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 == pow2 512)
#pop-options
#push-options "--fuel 0 --z3cliopt smt.arith.nl=true --smtencoding.elim_box true --smtencoding.l_arith_repr native --smtencoding.nl_arith_repr native --z3rlimit 30"
private
let lemma_0 (x:nat) (y:nat) (c:pos) : Lemma
(requires (x >= y /\ x - y < c))
(ensures (x / c - y / c <= 1))
= if x / c - y / c > 1 then (
Math.Lemmas.lemma_div_mod x c;
Math.Lemmas.lemma_div_mod y c;
Math.Lemmas.distributivity_sub_right c (x / c) (y / c);
Math.Lemmas.lemma_div_mod (x-y) c;
Math.Lemmas.small_div (x-y) c;
Math.Lemmas.swap_mul c (x/c - y/c);
Math.Lemmas.cancel_mul_div (x/c - y/c) c
)
#pop-options
#push-options "--z3rlimit 30" | {
"checked_file": "/",
"dependencies": [
"Spec.Ed25519.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.BignumQ.Definitions.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Tactics.CanonCommSemiring.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.BignumQ.Lemmas.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.CanonCommSemiring",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.BignumQ.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.Ed25519",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.CanonCommSemiring",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.BignumQ",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.BignumQ",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: Prims.nat -> y: Prims.nat -> c: Prims.pos
-> FStar.Pervasives.Lemma (requires x - y < c /\ x >= y)
(ensures
x - y =
(match x % c - y % c < 0 with
| true -> c + x % c - y % c
| _ -> x % c - y % c)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.nat",
"Prims.pos",
"Hacl.Spec.BignumQ.Lemmas.lemma_0",
"Prims.unit",
"Prims._assert",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"Prims.op_Subtraction",
"Prims.op_Modulus",
"FStar.Mul.op_Star",
"Prims.op_Division",
"FStar.Math.Lemmas.distributivity_sub_right",
"FStar.Math.Lemmas.lemma_div_mod",
"Prims.l_and",
"Prims.op_LessThan",
"Prims.op_GreaterThanOrEqual",
"Prims.squash",
"Prims.op_Addition",
"Prims.bool",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let lemma_1 (x y: nat) (c: pos)
: Lemma (requires (x - y < c /\ x >= y))
(ensures
(x - y = (if (x % c) - (y % c) < 0 then c + (x % c) - (y % c) else (x % c) - (y % c)))) =
| Math.Lemmas.lemma_div_mod x c;
Math.Lemmas.lemma_div_mod y c;
Math.Lemmas.distributivity_sub_right c (y / c) (x / c);
assert ((x % c) - (y % c) = x - y - c * ((x / c) - (y / c)));
lemma_0 x y c | false |
Hacl.Spec.BignumQ.Lemmas.fst | Hacl.Spec.BignumQ.Lemmas.lemma_mul_qelem5 | val lemma_mul_qelem5 (x0 x1 x2 x3 x4 y0 y1 y2 y3 y4: nat)
: Lemma
((x0 + x1 * pow2 56 + x2 * pow2 112 + x3 * pow2 168 + x4 * pow2 224) *
(y0 + y1 * pow2 56 + y2 * pow2 112 + y3 * pow2 168 + y4 * pow2 224) ==
x0 * y0 + (x0 * y1 + x1 * y0) * pow56 + (x0 * y2 + x1 * y1 + x2 * y0) * pow112 +
(x0 * y3 + x1 * y2 + x2 * y1 + x3 * y0) * pow168 +
(x0 * y4 + x1 * y3 + x2 * y2 + x3 * y1 + x4 * y0) * pow224 +
(x1 * y4 + x2 * y3 + x3 * y2 + x4 * y1) * pow280 +
(x2 * y4 + x3 * y3 + x4 * y2) * pow336 +
(x3 * y4 + x4 * y3) * pow392 +
(x4 * y4) * pow448) | val lemma_mul_qelem5 (x0 x1 x2 x3 x4 y0 y1 y2 y3 y4: nat)
: Lemma
((x0 + x1 * pow2 56 + x2 * pow2 112 + x3 * pow2 168 + x4 * pow2 224) *
(y0 + y1 * pow2 56 + y2 * pow2 112 + y3 * pow2 168 + y4 * pow2 224) ==
x0 * y0 + (x0 * y1 + x1 * y0) * pow56 + (x0 * y2 + x1 * y1 + x2 * y0) * pow112 +
(x0 * y3 + x1 * y2 + x2 * y1 + x3 * y0) * pow168 +
(x0 * y4 + x1 * y3 + x2 * y2 + x3 * y1 + x4 * y0) * pow224 +
(x1 * y4 + x2 * y3 + x3 * y2 + x4 * y1) * pow280 +
(x2 * y4 + x3 * y3 + x4 * y2) * pow336 +
(x3 * y4 + x4 * y3) * pow392 +
(x4 * y4) * pow448) | let lemma_mul_qelem5 (x0 x1 x2 x3 x4 y0 y1 y2 y3 y4:nat) : Lemma
((x0 + x1 * pow2 56 + x2 * pow2 112 + x3 * pow2 168 + x4 * pow2 224) *
(y0 + y1 * pow2 56 + y2 * pow2 112 + y3 * pow2 168 + y4 * pow2 224) ==
x0 * y0 +
(x0 * y1 + x1 * y0) * pow56 +
(x0 * y2 + x1 * y1 + x2 * y0) * pow112 +
(x0 * y3 + x1 * y2 + x2 * y1 + x3 * y0) * pow168 +
(x0 * y4 + x1 * y3 + x2 * y2 + x3 * y1 + x4 * y0) * pow224 +
(x1 * y4 + x2 * y3 + x3 * y2 + x4 * y1) * pow280 +
(x2 * y4 + x3 * y3 + x4 * y2) * pow336 +
(x3 * y4 + x4 * y3) * pow392 +
(x4 * y4) * pow448)
=
assert ((x0 + x1 * pow2 56 + x2 * pow2 112 + x3 * pow2 168 + x4 * pow2 224) *
(y0 + y1 * pow2 56 + y2 * pow2 112 + y3 * pow2 168 + y4 * pow2 224) ==
x0 * y0 +
(x0 * y1 + x1 * y0) * pow56 +
(x0 * y2 + x1 * y1 + x2 * y0) * pow112 +
(x0 * y3 + x1 * y2 + x2 * y1 + x3 * y0) * pow168 +
(x0 * y4 + x1 * y3 + x2 * y2 + x3 * y1 + x4 * y0) * pow224 +
(x1 * y4 + x2 * y3 + x3 * y2 + x4 * y1) * pow280 +
(x2 * y4 + x3 * y3 + x4 * y2) * pow336 +
(x3 * y4 + x4 * y3) * pow392 +
(x4 * y4) * pow448)
by (Tactics.norm [zeta; iota; delta; primops]; int_semiring ()) | {
"file_name": "code/ed25519/Hacl.Spec.BignumQ.Lemmas.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 65,
"end_line": 637,
"start_col": 0,
"start_line": 613
} | module Hacl.Spec.BignumQ.Lemmas
open FStar.Tactics.CanonCommSemiring
open FStar.Mul
open Lib.IntTypes
module S = Spec.Ed25519
include Hacl.Spec.BignumQ.Definitions
let feq (#a #b:Type) (f:(a -> b)) (x y:a) :
Lemma (requires x == y) (ensures f x == f y) = ()
let eq_eq2 (#a:eqtype) (x y:a) :
Lemma (requires x = y) (ensures x == y) = ()
val lemma_mul_lt:a:nat -> b:nat -> c:nat -> d:nat ->
Lemma
(requires a < b /\ c < d)
(ensures a * c < b * d)
let lemma_mul_lt a b c d = ()
val lemma_as_nat5: f:qelem5 ->
Lemma
(requires qelem_fits5 f (1, 1, 1, 1, 1))
(ensures as_nat5 f < pow2 280)
let lemma_as_nat5 f =
//let (f0, f1, f2, f3, f4) = f in
//assert (as_nat5 f == v f0 + v f1 * pow56 + v f2 * pow112 + v f3 * pow168 + v f4 * pow224);
assert_norm (pow2 56 * pow2 56 = pow2 112);
assert_norm (pow2 56 * pow2 112 = pow2 168);
assert_norm (pow2 56 * pow2 168 = pow2 224);
assert_norm (pow2 56 * pow2 224 = pow2 280)
val lemma_choose_step:
bit:uint64{v bit <= 1}
-> x:uint64
-> y:uint64
-> Lemma
(let mask = bit -. u64 1 in
let z = x ^. (mask &. (x ^. y)) in
if v bit = 1 then z == x else z == y)
let lemma_choose_step bit p1 p2 =
let mask = bit -. u64 1 in
assert (v bit == 0 ==> v mask == pow2 64 - 1);
assert (v bit == 1 ==> v mask == 0);
let dummy = mask &. (p1 ^. p2) in
logand_lemma mask (p1 ^. p2);
assert (v bit == 1 ==> v dummy == 0);
assert (v bit == 0 ==> v dummy == v (p1 ^. p2));
let p1' = p1 ^. dummy in
assert (v dummy == v (if v bit = 1 then u64 0 else (p1 ^. p2)));
logxor_lemma p1 p2
val lemma_subm_conditional:
x0:nat -> x1:nat -> x2:nat -> x3:nat -> x4:nat
-> y0:nat -> y1:nat -> y2:nat -> y3:nat -> y4:nat
-> b0:nat -> b1:nat -> b2:nat -> b3:nat -> b4:nat ->
Lemma (
x0 - y0 + b0 * pow2 56 +
(x1 - y1 - b0 + b1 * pow2 56) * pow2 56 +
(x2 - y2 - b1 + b2 * pow2 56) * pow2 112 +
(x3 - y3 - b2 + b3 * pow2 56) * pow2 168 +
(x4 - y4 - b3 + b4 * pow2 56) * pow2 224 ==
(x0 + x1 * pow2 56 + x2 * pow2 112 + x3 * pow2 168 + x4 * pow2 224) -
(y0 + y1 * pow2 56 + y2 * pow2 112 + y3 * pow2 168 + y4 * pow2 224) + b4 * pow2 280)
let lemma_subm_conditional x0 x1 x2 x3 x4 y0 y1 y2 y3 y4 b0 b1 b2 b3 b4 =
assert_norm (pow2 56 * pow2 56 = pow2 112);
assert_norm (pow2 56 * pow2 112 = pow2 168);
assert_norm (pow2 56 * pow2 168 = pow2 224);
assert_norm (pow2 56 * pow2 224 = pow2 280);
assert (
x0 - y0 + b0 * pow2 56 +
(x1 - y1 - b0 + b1 * pow2 56) * pow2 56 +
(x2 - y2 - b1 + b2 * pow2 56) * pow2 112 +
(x3 - y3 - b2 + b3 * pow2 56) * pow2 168 +
(x4 - y4 - b3 + b4 * pow2 56) * pow2 224 ==
(x0 + x1 * pow2 56 + x2 * pow2 112 + x3 * pow2 168 + x4 * pow2 224) -
(y0 + y1 * pow2 56 + y2 * pow2 112 + y3 * pow2 168 + y4 * pow2 224) + b4 * pow2 280)
by (int_semiring ());
()
val lemma_div224: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1))
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
wide_as_nat5 x / pow2 224 ==
v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280))
#push-options "--z3rlimit 50"
let lemma_div224 x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert
(wide_as_nat5 x ==
v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168 + v x4 * pow2 224 +
v x5 * pow2 280 + v x6 * pow2 336 + v x7 * pow2 392 + v x8 * pow2 448 + v x9 * pow2 504);
assert_norm (pow2 56 * pow2 224 == pow2 280);
assert_norm (pow2 112 * pow2 224 == pow2 336);
assert_norm (pow2 168 * pow2 224 == pow2 392);
assert_norm (pow2 224 * pow2 224 == pow2 448);
assert_norm (pow2 280 * pow2 224 == pow2 504);
calc (==) {
wide_as_nat5 x / pow2 224;
(==) { }
(v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168 +
(v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280) * pow2 224) / pow2 224;
(==) {
FStar.Math.Lemmas.lemma_div_plus
(v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168)
(v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280) (pow2 224) }
(v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168) / pow2 224 +
v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280;
(==) { FStar.Math.Lemmas.small_division_lemma_1 (v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168) (pow2 224) }
v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280;
}
#pop-options
val lemma_div248_aux: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 512)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
wide_as_nat5 x / pow2 248 ==
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256))
open FStar.Tactics.CanonCommSemiring
#push-options "--z3cliopt smt.arith.nl=false"
let lemma_div248_aux x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert_norm (pow2 248 == pow2 224 * pow2 24);
assert_norm (pow2 56 == pow2 32 * pow2 24);
assert_norm (pow2 112 == pow2 88 * pow2 24);
assert_norm (pow2 168 == pow2 144 * pow2 24);
assert_norm (pow2 224 == pow2 200 * pow2 24);
assert_norm (pow2 280 == pow2 256 * pow2 24);
assert_norm (0 < pow2 24);
calc (==) {
wide_as_nat5 x / pow2 248;
(==) { FStar.Math.Lemmas.division_multiplication_lemma (wide_as_nat5 x) (pow2 224) (pow2 24) }
(wide_as_nat5 x / pow2 224) / pow2 24;
(==) { lemma_div224 x }
(v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280) / pow2 24;
(==) { _ by (Tactics.mapply (`feq #int #int (fun x -> x / pow2 24)); int_semiring ()) } (v x4 + (v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256) * pow2 24) / pow2 24;
(==) { FStar.Math.Lemmas.lemma_div_plus (v x4) (v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256) (pow2 24) }
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256;
}
#pop-options
val lemma_div248_x5: x5:uint64 ->
Lemma ( pow2 32 * (v x5 % pow2 24) + v x5 / pow2 24 * pow2 56 == v x5 * pow2 32)
let lemma_div248_x5 x5 =
assert_norm (pow2 32 * pow2 24 = pow2 56)
val lemma_div248_x6: x6:uint64 ->
Lemma (pow2 32 * (v x6 % pow2 24) * pow2 56 + v x6 / pow2 24 * pow2 112 == v x6 * pow2 88)
let lemma_div248_x6 x6 =
calc (==) {
pow2 32 * (v x6 % pow2 24) * pow2 56 + v x6 / pow2 24 * pow2 112;
(==) { _ by (Tactics.norm [delta_only [`%pow2]; primops]; int_semiring ()) }
((v x6 / pow2 24) * pow2 24 + v x6 % pow2 24) * pow2 88;
(==) { FStar.Math.Lemmas.euclidean_division_definition (v x6) (pow2 24) }
v x6 * pow2 88;
}
val lemma_div248_x7: x7:uint64 ->
Lemma (pow2 32 * (v x7 % pow2 24) * pow2 112 + v x7 / pow2 24 * pow2 168 == v x7 * pow2 144)
let lemma_div248_x7 x7 =
calc (==) {
pow2 32 * (v x7 % pow2 24) * pow2 112 + v x7 / pow2 24 * pow2 168;
(==) { _ by (Tactics.norm [delta_only [`%pow2]; primops]; int_semiring ()) }
((v x7 / pow2 24) * pow2 24 + v x7 % pow2 24) * pow2 144;
(==) { FStar.Math.Lemmas.euclidean_division_definition (v x7) (pow2 24) }
v x7 * pow2 144;
}
val lemma_div248_x8: x8:uint64 ->
Lemma (pow2 32 * (v x8 % pow2 24) * pow2 168 + v x8 / pow2 24 * pow2 224 == v x8 * pow2 200)
let lemma_div248_x8 x8 =
calc (==) {
pow2 32 * (v x8 % pow2 24) * pow2 168 + v x8 / pow2 24 * pow2 224;
(==) { _ by (Tactics.norm [delta_only [`%pow2]; primops]; int_semiring ()) }
((v x8 / pow2 24) * pow2 24 + v x8 % pow2 24) * pow2 200;
(==) { FStar.Math.Lemmas.euclidean_division_definition (v x8) (pow2 24) }
v x8 * pow2 200;
}
val lemma_div248_x9: x9:uint64{v x9 < pow2 24} ->
Lemma (pow2 32 * (v x9 % pow2 24) * pow2 224 == v x9 * pow2 256)
let lemma_div248_x9 x9 =
calc (==) {
pow2 32 * (v x9 % pow2 24) * pow2 224;
(==) { Math.Lemmas.small_mod (v x9) (pow2 24) }
pow2 32 * v x9 * pow2 224;
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
v x9 * pow2 256;
}
val lemma_wide_as_nat_pow512: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 512)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
v x9 < pow2 24))
let lemma_wide_as_nat_pow512 x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert_norm (pow2 504 * pow2 8 = pow2 512);
FStar.Math.Lemmas.pow2_minus 512 504;
assert (v x9 < pow2 8);
assert_norm (pow2 8 < pow2 24)
val lemma_div248: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 512)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
let z0 = v x4 / pow2 24 + pow2 32 * (v x5 % pow2 24) in
let z1 = v x5 / pow2 24 + pow2 32 * (v x6 % pow2 24) in
let z2 = v x6 / pow2 24 + pow2 32 * (v x7 % pow2 24) in
let z3 = v x7 / pow2 24 + pow2 32 * (v x8 % pow2 24) in
let z4 = v x8 / pow2 24 + pow2 32 * (v x9 % pow2 24) in
wide_as_nat5 x / pow2 248 == z0 + z1 * pow2 56 + z2 * pow2 112 + z3 * pow2 168 + z4 * pow2 224))
#push-options "--z3rlimit 50"
let lemma_div248 x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
lemma_wide_as_nat_pow512 x;
assert (v x9 < pow2 24);
calc (==) {
(let z0 = v x4 / pow2 24 + pow2 32 * (v x5 % pow2 24) in
let z1 = v x5 / pow2 24 + pow2 32 * (v x6 % pow2 24) in
let z2 = v x6 / pow2 24 + pow2 32 * (v x7 % pow2 24) in
let z3 = v x7 / pow2 24 + pow2 32 * (v x8 % pow2 24) in
let z4 = v x8 / pow2 24 + pow2 32 * (v x9 % pow2 24) in
z0 + z1 * pow2 56 + z2 * pow2 112 + z3 * pow2 168 + z4 * pow2 224);
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
v x4 / pow2 24 + pow2 32 * (v x5 % pow2 24) +
v x5 / pow2 24 * pow2 56 + pow2 32 * (v x6 % pow2 24) * pow2 56 +
v x6 / pow2 24 * pow2 112 + pow2 32 * (v x7 % pow2 24) * pow2 112 +
v x7 / pow2 24 * pow2 168 + pow2 32 * (v x8 % pow2 24) * pow2 168 +
v x8 / pow2 24 * pow2 224 + pow2 32 * (v x9 % pow2 24) * pow2 224;
(==) { lemma_div248_x5 x5; lemma_div248_x6 x6 }
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 +
pow2 32 * (v x7 % pow2 24) * pow2 112 +
v x7 / pow2 24 * pow2 168 + pow2 32 * (v x8 % pow2 24) * pow2 168 +
v x8 / pow2 24 * pow2 224 + pow2 32 * (v x9 % pow2 24) * pow2 224;
(==) { lemma_div248_x7 x7; lemma_div248_x8 x8 }
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 +
pow2 32 * (v x9 % pow2 24) * pow2 224;
(==) { lemma_div248_x9 x9 }
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256;
(==) { lemma_div248_aux x }
wide_as_nat5 x / pow2 248;
}
#pop-options
val lemma_add_modq5:
x:qelem5
-> y:qelem5
-> t:qelem5 ->
Lemma
(requires
qelem_fits5 x (1, 1, 1, 1, 1) /\
qelem_fits5 y (1, 1, 1, 1, 1) /\
qelem_fits5 t (1, 1, 1, 1, 1) /\
as_nat5 x < S.q /\ as_nat5 y < S.q /\
as_nat5 t == as_nat5 x + as_nat5 y)
(ensures
(let res = if as_nat5 t >= S.q then as_nat5 t - S.q else as_nat5 t in
res < S.q /\ res == (as_nat5 x + as_nat5 y) % S.q))
let lemma_add_modq5 x y t =
assert (as_nat5 t == as_nat5 x + as_nat5 y);
let res = if as_nat5 t >= S.q then as_nat5 t - S.q else as_nat5 t in
assert (res < S.q);
if as_nat5 t >= S.q then (
FStar.Math.Lemmas.sub_div_mod_1 (as_nat5 t) S.q;
assert (res % S.q == as_nat5 t % S.q))
else
assert (res % S.q == as_nat5 t % S.q);
FStar.Math.Lemmas.small_mod res S.q
val lemma_wide_as_nat_pow528: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 528)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
v x9 < pow2 40))
let lemma_wide_as_nat_pow528 x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert_norm (pow2 504 * pow2 24 = pow2 528);
FStar.Math.Lemmas.pow2_minus 528 504;
assert (v x9 < pow2 24);
assert_norm (pow2 24 < pow2 40)
#push-options "--z3cliopt smt.arith.nl=false"
val lemma_div264_aux: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 528)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
wide_as_nat5 x / pow2 264 ==
v x4 / pow2 40 + v x5 * pow2 16 + v x6 * pow2 72 + v x7 * pow2 128 + v x8 * pow2 184 + v x9 * pow2 240))
let lemma_div264_aux x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert_norm (pow2 264 == pow2 224 * pow2 40);
assert_norm (pow2 56 == pow2 16 * pow2 40);
assert_norm (pow2 112 == pow2 72 * pow2 40);
assert_norm (pow2 168 == pow2 128 * pow2 40);
assert_norm (pow2 224 == pow2 184 * pow2 40);
assert_norm (pow2 280 == pow2 240 * pow2 40);
assert_norm (0 < pow2 40);
calc (==) {
wide_as_nat5 x / pow2 264;
(==) { FStar.Math.Lemmas.division_multiplication_lemma (wide_as_nat5 x) (pow2 224) (pow2 40) }
(wide_as_nat5 x / pow2 224) / pow2 40;
(==) { lemma_div224 x }
(v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280) / pow2 40;
(==) { _ by (Tactics.mapply (`feq #int #int (fun x -> x / pow2 40)); int_semiring ()) }
(v x4 + (v x5 * pow2 16 + v x6 * pow2 72 + v x7 * pow2 128 + v x8 * pow2 184 + v x9 * pow2 240) * pow2 40) / pow2 40;
(==) { FStar.Math.Lemmas.lemma_div_plus (v x4) (v x5 * pow2 16 + v x6 * pow2 72 + v x7 * pow2 128 + v x8 * pow2 184 + v x9 * pow2 240) (pow2 40) }
v x4 / pow2 40 + v x5 * pow2 16 + v x6 * pow2 72 + v x7 * pow2 128 + v x8 * pow2 184 + v x9 * pow2 240;
}
val lemma_div264_x5: x5:uint64 ->
Lemma (pow2 16 * (v x5 % pow2 40) + v x5 / pow2 40 * pow2 56 == v x5 * pow2 16)
let lemma_div264_x5 x5 =
assert_norm (0 < pow2 24);
calc (==) {
pow2 16 * (v x5 % pow2 40) + v x5 / pow2 40 * pow2 56;
(==) { _ by (Tactics.norm [delta_only [`%pow2]; primops]; int_semiring ()) }
((v x5 / pow2 40) * pow2 40 + v x5 % pow2 40) * pow2 16;
(==) { FStar.Math.Lemmas.euclidean_division_definition (v x5) (pow2 40) }
v x5 * pow2 16;
}
val lemma_div264_x6: x6:uint64 ->
Lemma (pow2 16 * (v x6 % pow2 40) * pow2 56 + v x6 / pow2 40 * pow2 112 == v x6 * pow2 72)
let lemma_div264_x6 x6 =
calc (==) {
pow2 16 * (v x6 % pow2 40) * pow2 56 + v x6 / pow2 40 * pow2 112;
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
((v x6 / pow2 40) * pow2 40 + v x6 % pow2 40) * pow2 72;
(==) { Math.Lemmas.euclidean_division_definition (v x6) (pow2 40) }
v x6 * pow2 72;
}
val lemma_div264_x7: x7:uint64 ->
Lemma (pow2 16 * (v x7 % pow2 40) * pow2 112 + v x7 / pow2 40 * pow2 168 == v x7 * pow2 128)
let lemma_div264_x7 x7 =
calc (==) {
pow2 16 * (v x7 % pow2 40) * pow2 112 + v x7 / pow2 40 * pow2 168;
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
((v x7 / pow2 40) * pow2 40 + v x7 % pow2 40) * pow2 128;
(==) { Math.Lemmas.euclidean_division_definition (v x7) (pow2 40) }
v x7 * pow2 128;
}
val lemma_div264_x8: x8:uint64 ->
Lemma (pow2 16 * (v x8 % pow2 40) * pow2 168 + v x8 / pow2 40 * pow2 224 == v x8 * pow2 184)
let lemma_div264_x8 x8 =
calc (==) {
pow2 16 * (v x8 % pow2 40) * pow2 168 + v x8 / pow2 40 * pow2 224;
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
((v x8 / pow2 40) * pow2 40 + v x8 % pow2 40) * pow2 184;
(==) { Math.Lemmas.euclidean_division_definition (v x8) (pow2 40) }
v x8 * pow2 184;
}
val lemma_div264_x9: x9:uint64{v x9 < pow2 40} ->
Lemma (pow2 16 * (v x9 % pow2 40) * pow2 224 == v x9 * pow2 240)
let lemma_div264_x9 x9 =
calc (==) {
pow2 16 * (v x9 % pow2 40) * pow2 224;
(==) { Math.Lemmas.small_mod (v x9) (pow2 40) }
pow2 16 * v x9 * pow2 224;
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
v x9 * pow2 240;
}
val lemma_div264: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 528)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
let z0 = v x4 / pow2 40 + pow2 16 * (v x5 % pow2 40) in
let z1 = v x5 / pow2 40 + pow2 16 * (v x6 % pow2 40) in
let z2 = v x6 / pow2 40 + pow2 16 * (v x7 % pow2 40) in
let z3 = v x7 / pow2 40 + pow2 16 * (v x8 % pow2 40) in
let z4 = v x8 / pow2 40 + pow2 16 * (v x9 % pow2 40) in
wide_as_nat5 x / pow2 264 == z0 + z1 * pow2 56 + z2 * pow2 112 + z3 * pow2 168 + z4 * pow2 224))
#push-options "--z3rlimit 50"
let lemma_div264 x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
lemma_wide_as_nat_pow528 x;
assert (v x9 < pow2 40);
calc (==) {
(let z0 = v x4 / pow2 40 + pow2 16 * (v x5 % pow2 40) in
let z1 = v x5 / pow2 40 + pow2 16 * (v x6 % pow2 40) in
let z2 = v x6 / pow2 40 + pow2 16 * (v x7 % pow2 40) in
let z3 = v x7 / pow2 40 + pow2 16 * (v x8 % pow2 40) in
let z4 = v x8 / pow2 40 + pow2 16 * (v x9 % pow2 40) in
z0 + z1 * pow2 56 + z2 * pow2 112 + z3 * pow2 168 + z4 * pow2 224);
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
v x4 / pow2 40 + pow2 16 * (v x5 % pow2 40) +
v x5 / pow2 40 * pow2 56 + pow2 16 * (v x6 % pow2 40) * pow2 56 +
v x6 / pow2 40 * pow2 112 + pow2 16 * (v x7 % pow2 40) * pow2 112 +
v x7 / pow2 40 * pow2 168 + pow2 16 * (v x8 % pow2 40) * pow2 168 +
v x8 / pow2 40 * pow2 224 + pow2 16 * (v x9 % pow2 40) * pow2 224;
(==) { lemma_div264_x5 x5; lemma_div264_x6 x6 }
v x4 / pow2 40 + v x5 * pow2 16 + v x6 * pow2 72 +
pow2 16 * (v x7 % pow2 40) * pow2 112 +
v x7 / pow2 40 * pow2 168 + pow2 16 * (v x8 % pow2 40) * pow2 168 +
v x8 / pow2 40 * pow2 224 + pow2 16 * (v x9 % pow2 40) * pow2 224;
(==) { lemma_div264_x7 x7; lemma_div264_x8 x8 }
v x4 / pow2 40 + v x5 * pow2 16 + v x6 * pow2 72 + v x7 * pow2 128 + v x8 * pow2 184 +
pow2 16 * (v x9 % pow2 40) * pow2 224;
(==) { lemma_div264_x9 x9 }
v x4 / pow2 40 + v x5 * pow2 16 + v x6 * pow2 72 + v x7 * pow2 128 + v x8 * pow2 184 + v x9 * pow2 240;
(==) { lemma_div264_aux x }
wide_as_nat5 x / pow2 264;
}
#pop-options
#pop-options // "--z3cliopt smt.arith.nl=false"
val lemma_mod_264_aux: t:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 t (1, 1, 1, 1, 1, 1, 1, 1, 1, 1))
(ensures
(let (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) = t in
(wide_as_nat5 t) % pow2 264 ==
(v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + v t4 * pow2 224) % pow2 264))
#push-options "--z3rlimit 150"
let lemma_mod_264_aux t =
let (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) = t in
let res = (t0, t1, t2, t3, t4 &. u64 0xffffffffff) in
assert_norm (pow2 16 * pow2 264 == pow2 280);
assert_norm (pow2 72 * pow2 264 == pow2 336);
assert_norm (pow2 128 * pow2 264 == pow2 392);
assert_norm (pow2 184 * pow2 264 == pow2 448);
assert_norm (pow2 240 * pow2 264 == pow2 504);
calc (==) {
(wide_as_nat5 t) % pow2 264;
(==) { }
(v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + v t4 * pow2 224 +
(v t5 * pow2 16 + v t6 * pow2 72 + v t7 * pow2 128 + v t8 * pow2 184 + v t9 * pow2 240) * pow2 264) % pow2 264;
(==) { FStar.Math.Lemmas.lemma_mod_add_distr (v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + v t4 * pow2 224)
((v t5 * pow2 16 + v t6 * pow2 72 + v t7 * pow2 128 + v t8 * pow2 184 + v t9 * pow2 240) * pow2 264) (pow2 264)}
((v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + v t4 * pow2 224) +
((v t5 * pow2 16 + v t6 * pow2 72 + v t7 * pow2 128 + v t8 * pow2 184 + v t9 * pow2 240) * pow2 264) % pow2 264) % pow2 264;
(==) { FStar.Math.Lemmas.cancel_mul_mod (v t5 * pow2 16 + v t6 * pow2 72 + v t7 * pow2 128 + v t8 * pow2 184 + v t9 * pow2 240) (pow2 264) }
(v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + v t4 * pow2 224) % pow2 264;
}
#pop-options
val lemma_as_nat_pow264: x:qelem5 ->
Lemma
(requires
(let (x0, x1, x2, x3, x4) = x in
qelem_fits5 x (1, 1, 1, 1, 1) /\
v x4 < pow2 40))
(ensures as_nat5 x < pow2 264)
let lemma_as_nat_pow264 x =
let (x0, x1, x2, x3, x4) = x in
assert_norm (pow2 40 * pow2 224 = pow2 264)
val lemma_mod_264: t:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 t (1, 1, 1, 1, 1, 1, 1, 1, 1, 1))
(ensures
(let (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) = t in
let res = (t0, t1, t2, t3, t4 &. u64 0xffffffffff) in
qelem_fits5 res (1, 1, 1, 1, 1) /\
as_nat5 res == (wide_as_nat5 t) % pow2 264))
let lemma_mod_264 t =
let (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) = t in
let t4' = t4 &. u64 0xffffffffff in
let res = (t0, t1, t2, t3, t4') in
assert_norm (pow2 40 < pow2 64);
assert_norm (pow2 40 - 1 == 0xffffffffff);
mod_mask_lemma t4 40ul;
assert (v (mod_mask #U64 #SEC 40ul) == 0xffffffffff);
assert (v (t4 &. u64 0xffffffffff) == v t4 % pow2 40);
calc (==) {
(wide_as_nat5 t) % pow2 264;
(==) { lemma_mod_264_aux t }
(v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + v t4 * pow2 224) % pow2 264;
(==) { FStar.Math.Lemmas.lemma_mod_add_distr (v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168) (v t4 * pow2 224) (pow2 264) }
(v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + (v t4 * pow2 224) % pow2 264) % pow2 264;
(==) { FStar.Math.Lemmas.pow2_multiplication_modulo_lemma_2 (v t4) 264 224 }
(v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + (v t4 % pow2 40) * pow2 224) % pow2 264;
(==) { lemma_as_nat_pow264 res; FStar.Math.Lemmas.modulo_lemma (as_nat5 res) (pow2 264) }
v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + (v t4 % pow2 40) * pow2 224;
}
val lemma_as_nat_pow264_x4: x:qelem5 ->
Lemma
(requires
qelem_fits5 x (1, 1, 1, 1, 1) /\
as_nat5 x < pow2 264)
(ensures
(let (x0, x1, x2, x3, x4) = x in
v x4 < pow2 40))
let lemma_as_nat_pow264_x4 x =
let (x0, x1, x2, x3, x4) = x in
assert_norm (pow2 40 * pow2 224 = pow2 264)
val lemma_sub_mod_264_aux:
x0:nat -> x1:nat -> x2:nat -> x3:nat -> x4:nat
-> y0:nat -> y1:nat -> y2:nat -> y3:nat -> y4:nat
-> c1:nat -> c2:nat -> c3:nat -> c4:nat -> c5:nat ->
Lemma (
x0 - y0 + c1 * pow56 +
(x1 - y1 - c1 + c2 * pow56) * pow56 +
(x2 - y2 - c2 + c3 * pow56) * pow112 +
(x3 - y3 - c3 + c4 * pow56) * pow168 +
(x4 - y4 - c4 + pow2 40 * c5) * pow224 ==
(x0 + x1 * pow2 56 + x2 * pow2 112 + x3 * pow2 168 + x4 * pow2 224) -
(y0 + y1 * pow2 56 + y2 * pow2 112 + y3 * pow2 168 + y4 * pow2 224) + c5 * pow2 264)
#push-options "--z3rlimit 50"
let lemma_sub_mod_264_aux x0 x1 x2 x3 x4 y0 y1 y2 y3 y4 b0 b1 b2 b3 b4 =
assert_norm (pow2 56 * pow2 56 = pow2 112);
assert_norm (pow2 56 * pow2 112 = pow2 168);
assert_norm (pow2 56 * pow2 168 = pow2 224);
assert_norm (pow2 40 * pow2 224 = pow2 264)
#pop-options
val lemma_sub_mod_264:
x:qelem5
-> y:qelem5
-> t:qelem5
-> c5:uint64 ->
Lemma
(requires
qelem_fits5 x (1, 1, 1, 1, 1) /\
qelem_fits5 y (1, 1, 1, 1, 1) /\
qelem_fits5 t (1, 1, 1, 1, 1) /\
as_nat5 x < pow2 264 /\
as_nat5 y < pow2 264 /\
as_nat5 t == as_nat5 x - as_nat5 y + v c5 * pow2 264 /\ v c5 <= 1 /\
(if v c5 = 0 then as_nat5 x >= as_nat5 y else as_nat5 x < as_nat5 y))
(ensures
(if as_nat5 x >= as_nat5 y then
as_nat5 t == as_nat5 x - as_nat5 y
else as_nat5 t == as_nat5 x - as_nat5 y + pow2 264))
#push-options "--z3rlimit 50"
let lemma_sub_mod_264 x y t c5 =
assert (if v c5 = 0 then as_nat5 x >= as_nat5 y else as_nat5 x < as_nat5 y);
assert (as_nat5 t == as_nat5 x - as_nat5 y + v c5 * pow2 264);
if as_nat5 x >= as_nat5 y then
assert (v c5 == 0 /\ as_nat5 t == as_nat5 x - as_nat5 y)
else
assert (v c5 == 1 /\ as_nat5 t == as_nat5 x - as_nat5 y + pow2 264)
#pop-options | {
"checked_file": "/",
"dependencies": [
"Spec.Ed25519.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.BignumQ.Definitions.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Tactics.CanonCommSemiring.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.BignumQ.Lemmas.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.CanonCommSemiring",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.BignumQ.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.Ed25519",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.CanonCommSemiring",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.BignumQ",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.BignumQ",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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 |
x0: Prims.nat ->
x1: Prims.nat ->
x2: Prims.nat ->
x3: Prims.nat ->
x4: Prims.nat ->
y0: Prims.nat ->
y1: Prims.nat ->
y2: Prims.nat ->
y3: Prims.nat ->
y4: Prims.nat
-> FStar.Pervasives.Lemma
(ensures
(x0 + x1 * Prims.pow2 56 + x2 * Prims.pow2 112 + x3 * Prims.pow2 168 + x4 * Prims.pow2 224) *
(y0 + y1 * Prims.pow2 56 + y2 * Prims.pow2 112 + y3 * Prims.pow2 168 + y4 * Prims.pow2 224) ==
x0 * y0 + (x0 * y1 + x1 * y0) * Hacl.Spec.BignumQ.Definitions.pow56 +
(x0 * y2 + x1 * y1 + x2 * y0) * Hacl.Spec.BignumQ.Definitions.pow112 +
(x0 * y3 + x1 * y2 + x2 * y1 + x3 * y0) * Hacl.Spec.BignumQ.Definitions.pow168 +
(x0 * y4 + x1 * y3 + x2 * y2 + x3 * y1 + x4 * y0) * Hacl.Spec.BignumQ.Definitions.pow224 +
(x1 * y4 + x2 * y3 + x3 * y2 + x4 * y1) * Hacl.Spec.BignumQ.Definitions.pow280 +
(x2 * y4 + x3 * y3 + x4 * y2) * Hacl.Spec.BignumQ.Definitions.pow336 +
(x3 * y4 + x4 * y3) * Hacl.Spec.BignumQ.Definitions.pow392 +
(x4 * y4) * Hacl.Spec.BignumQ.Definitions.pow448) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.nat",
"FStar.Tactics.Effect.assert_by_tactic",
"Prims.eq2",
"Prims.int",
"FStar.Mul.op_Star",
"Prims.op_Addition",
"Prims.pow2",
"Hacl.Spec.BignumQ.Definitions.pow56",
"Hacl.Spec.BignumQ.Definitions.pow112",
"Hacl.Spec.BignumQ.Definitions.pow168",
"Hacl.Spec.BignumQ.Definitions.pow224",
"Hacl.Spec.BignumQ.Definitions.pow280",
"Hacl.Spec.BignumQ.Definitions.pow336",
"Hacl.Spec.BignumQ.Definitions.pow392",
"Hacl.Spec.BignumQ.Definitions.pow448",
"Prims.unit",
"FStar.Tactics.CanonCommSemiring.int_semiring",
"FStar.Stubs.Tactics.V1.Builtins.norm",
"Prims.Cons",
"FStar.Pervasives.norm_step",
"FStar.Pervasives.zeta",
"FStar.Pervasives.iota",
"FStar.Pervasives.delta",
"FStar.Pervasives.primops",
"Prims.Nil",
"Prims.l_True",
"Prims.squash",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let lemma_mul_qelem5 (x0 x1 x2 x3 x4 y0 y1 y2 y3 y4: nat)
: Lemma
((x0 + x1 * pow2 56 + x2 * pow2 112 + x3 * pow2 168 + x4 * pow2 224) *
(y0 + y1 * pow2 56 + y2 * pow2 112 + y3 * pow2 168 + y4 * pow2 224) ==
x0 * y0 + (x0 * y1 + x1 * y0) * pow56 + (x0 * y2 + x1 * y1 + x2 * y0) * pow112 +
(x0 * y3 + x1 * y2 + x2 * y1 + x3 * y0) * pow168 +
(x0 * y4 + x1 * y3 + x2 * y2 + x3 * y1 + x4 * y0) * pow224 +
(x1 * y4 + x2 * y3 + x3 * y2 + x4 * y1) * pow280 +
(x2 * y4 + x3 * y3 + x4 * y2) * pow336 +
(x3 * y4 + x4 * y3) * pow392 +
(x4 * y4) * pow448) =
| FStar.Tactics.Effect.assert_by_tactic ((x0 + x1 * pow2 56 + x2 * pow2 112 + x3 * pow2 168 +
x4 * pow2 224) *
(y0 + y1 * pow2 56 + y2 * pow2 112 + y3 * pow2 168 + y4 * pow2 224) ==
x0 * y0 + (x0 * y1 + x1 * y0) * pow56 + (x0 * y2 + x1 * y1 + x2 * y0) * pow112 +
(x0 * y3 + x1 * y2 + x2 * y1 + x3 * y0) * pow168 +
(x0 * y4 + x1 * y3 + x2 * y2 + x3 * y1 + x4 * y0) * pow224 +
(x1 * y4 + x2 * y3 + x3 * y2 + x4 * y1) * pow280 +
(x2 * y4 + x3 * y3 + x4 * y2) * pow336 +
(x3 * y4 + x4 * y3) * pow392 +
(x4 * y4) * pow448)
(fun _ ->
();
(Tactics.norm [zeta; iota; delta; primops];
int_semiring ())) | false |
Hacl.Spec.BignumQ.Lemmas.fst | Hacl.Spec.BignumQ.Lemmas.lemma_mod_264_ | val lemma_mod_264_:
a0:nat -> a1:nat -> a2:nat -> a3:nat -> a4:nat ->
Lemma ((a0 + pow2 56 * a1 + pow2 112 * a2 + pow2 168 * a3 + pow2 224 * a4) % pow2 264 =
(a0 % pow2 56)
+ pow2 56 * ((a1 + (a0 / pow2 56)) % pow2 56)
+ pow2 112 * ((a2 + ((a1 + (a0 / pow2 56)) / pow2 56)) % pow2 56)
+ pow2 168 * ((a3 + ((a2 + ((a1 + (a0 / pow2 56)) / pow2 56)) / pow2 56)) % pow2 56)
+ pow2 224 * ((a4 + ((a3 + ((a2 + ((a1 + (a0 / pow2 56)) / pow2 56)) / pow2 56)) / pow2 56)) % pow2 40)) | val lemma_mod_264_:
a0:nat -> a1:nat -> a2:nat -> a3:nat -> a4:nat ->
Lemma ((a0 + pow2 56 * a1 + pow2 112 * a2 + pow2 168 * a3 + pow2 224 * a4) % pow2 264 =
(a0 % pow2 56)
+ pow2 56 * ((a1 + (a0 / pow2 56)) % pow2 56)
+ pow2 112 * ((a2 + ((a1 + (a0 / pow2 56)) / pow2 56)) % pow2 56)
+ pow2 168 * ((a3 + ((a2 + ((a1 + (a0 / pow2 56)) / pow2 56)) / pow2 56)) % pow2 56)
+ pow2 224 * ((a4 + ((a3 + ((a2 + ((a1 + (a0 / pow2 56)) / pow2 56)) / pow2 56)) / pow2 56)) % pow2 40)) | let lemma_mod_264_ a0 a1 a2 a3 a4 =
lemma_mod_264_small a0 a1 a2 a3 a4;
let x0 = a0 % pow2 56 in
assert (x0 < pow56);
let x1 = ((a1 + (a0 / pow2 56)) % pow2 56) in
assert (x1 < pow56);
let x2 = ((a2 + ((a1 + (a0 / pow2 56)) / pow2 56)) % pow2 56) in
assert (x2 < pow56);
let x3 = ((a3 + ((a2 + ((a1 + (a0 / pow2 56)) / pow2 56)) / pow2 56)) % pow2 56) in
assert (x3 < pow56);
lemma_mod_264' x0 x1 x2 x3 (a4 + ((a3 + ((a2 + ((a1 + (a0 / pow2 56)) / pow2 56)) / pow2 56)) / pow2 56)) | {
"file_name": "code/ed25519/Hacl.Spec.BignumQ.Lemmas.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 107,
"end_line": 798,
"start_col": 0,
"start_line": 788
} | module Hacl.Spec.BignumQ.Lemmas
open FStar.Tactics.CanonCommSemiring
open FStar.Mul
open Lib.IntTypes
module S = Spec.Ed25519
include Hacl.Spec.BignumQ.Definitions
let feq (#a #b:Type) (f:(a -> b)) (x y:a) :
Lemma (requires x == y) (ensures f x == f y) = ()
let eq_eq2 (#a:eqtype) (x y:a) :
Lemma (requires x = y) (ensures x == y) = ()
val lemma_mul_lt:a:nat -> b:nat -> c:nat -> d:nat ->
Lemma
(requires a < b /\ c < d)
(ensures a * c < b * d)
let lemma_mul_lt a b c d = ()
val lemma_as_nat5: f:qelem5 ->
Lemma
(requires qelem_fits5 f (1, 1, 1, 1, 1))
(ensures as_nat5 f < pow2 280)
let lemma_as_nat5 f =
//let (f0, f1, f2, f3, f4) = f in
//assert (as_nat5 f == v f0 + v f1 * pow56 + v f2 * pow112 + v f3 * pow168 + v f4 * pow224);
assert_norm (pow2 56 * pow2 56 = pow2 112);
assert_norm (pow2 56 * pow2 112 = pow2 168);
assert_norm (pow2 56 * pow2 168 = pow2 224);
assert_norm (pow2 56 * pow2 224 = pow2 280)
val lemma_choose_step:
bit:uint64{v bit <= 1}
-> x:uint64
-> y:uint64
-> Lemma
(let mask = bit -. u64 1 in
let z = x ^. (mask &. (x ^. y)) in
if v bit = 1 then z == x else z == y)
let lemma_choose_step bit p1 p2 =
let mask = bit -. u64 1 in
assert (v bit == 0 ==> v mask == pow2 64 - 1);
assert (v bit == 1 ==> v mask == 0);
let dummy = mask &. (p1 ^. p2) in
logand_lemma mask (p1 ^. p2);
assert (v bit == 1 ==> v dummy == 0);
assert (v bit == 0 ==> v dummy == v (p1 ^. p2));
let p1' = p1 ^. dummy in
assert (v dummy == v (if v bit = 1 then u64 0 else (p1 ^. p2)));
logxor_lemma p1 p2
val lemma_subm_conditional:
x0:nat -> x1:nat -> x2:nat -> x3:nat -> x4:nat
-> y0:nat -> y1:nat -> y2:nat -> y3:nat -> y4:nat
-> b0:nat -> b1:nat -> b2:nat -> b3:nat -> b4:nat ->
Lemma (
x0 - y0 + b0 * pow2 56 +
(x1 - y1 - b0 + b1 * pow2 56) * pow2 56 +
(x2 - y2 - b1 + b2 * pow2 56) * pow2 112 +
(x3 - y3 - b2 + b3 * pow2 56) * pow2 168 +
(x4 - y4 - b3 + b4 * pow2 56) * pow2 224 ==
(x0 + x1 * pow2 56 + x2 * pow2 112 + x3 * pow2 168 + x4 * pow2 224) -
(y0 + y1 * pow2 56 + y2 * pow2 112 + y3 * pow2 168 + y4 * pow2 224) + b4 * pow2 280)
let lemma_subm_conditional x0 x1 x2 x3 x4 y0 y1 y2 y3 y4 b0 b1 b2 b3 b4 =
assert_norm (pow2 56 * pow2 56 = pow2 112);
assert_norm (pow2 56 * pow2 112 = pow2 168);
assert_norm (pow2 56 * pow2 168 = pow2 224);
assert_norm (pow2 56 * pow2 224 = pow2 280);
assert (
x0 - y0 + b0 * pow2 56 +
(x1 - y1 - b0 + b1 * pow2 56) * pow2 56 +
(x2 - y2 - b1 + b2 * pow2 56) * pow2 112 +
(x3 - y3 - b2 + b3 * pow2 56) * pow2 168 +
(x4 - y4 - b3 + b4 * pow2 56) * pow2 224 ==
(x0 + x1 * pow2 56 + x2 * pow2 112 + x3 * pow2 168 + x4 * pow2 224) -
(y0 + y1 * pow2 56 + y2 * pow2 112 + y3 * pow2 168 + y4 * pow2 224) + b4 * pow2 280)
by (int_semiring ());
()
val lemma_div224: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1))
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
wide_as_nat5 x / pow2 224 ==
v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280))
#push-options "--z3rlimit 50"
let lemma_div224 x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert
(wide_as_nat5 x ==
v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168 + v x4 * pow2 224 +
v x5 * pow2 280 + v x6 * pow2 336 + v x7 * pow2 392 + v x8 * pow2 448 + v x9 * pow2 504);
assert_norm (pow2 56 * pow2 224 == pow2 280);
assert_norm (pow2 112 * pow2 224 == pow2 336);
assert_norm (pow2 168 * pow2 224 == pow2 392);
assert_norm (pow2 224 * pow2 224 == pow2 448);
assert_norm (pow2 280 * pow2 224 == pow2 504);
calc (==) {
wide_as_nat5 x / pow2 224;
(==) { }
(v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168 +
(v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280) * pow2 224) / pow2 224;
(==) {
FStar.Math.Lemmas.lemma_div_plus
(v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168)
(v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280) (pow2 224) }
(v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168) / pow2 224 +
v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280;
(==) { FStar.Math.Lemmas.small_division_lemma_1 (v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168) (pow2 224) }
v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280;
}
#pop-options
val lemma_div248_aux: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 512)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
wide_as_nat5 x / pow2 248 ==
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256))
open FStar.Tactics.CanonCommSemiring
#push-options "--z3cliopt smt.arith.nl=false"
let lemma_div248_aux x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert_norm (pow2 248 == pow2 224 * pow2 24);
assert_norm (pow2 56 == pow2 32 * pow2 24);
assert_norm (pow2 112 == pow2 88 * pow2 24);
assert_norm (pow2 168 == pow2 144 * pow2 24);
assert_norm (pow2 224 == pow2 200 * pow2 24);
assert_norm (pow2 280 == pow2 256 * pow2 24);
assert_norm (0 < pow2 24);
calc (==) {
wide_as_nat5 x / pow2 248;
(==) { FStar.Math.Lemmas.division_multiplication_lemma (wide_as_nat5 x) (pow2 224) (pow2 24) }
(wide_as_nat5 x / pow2 224) / pow2 24;
(==) { lemma_div224 x }
(v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280) / pow2 24;
(==) { _ by (Tactics.mapply (`feq #int #int (fun x -> x / pow2 24)); int_semiring ()) } (v x4 + (v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256) * pow2 24) / pow2 24;
(==) { FStar.Math.Lemmas.lemma_div_plus (v x4) (v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256) (pow2 24) }
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256;
}
#pop-options
val lemma_div248_x5: x5:uint64 ->
Lemma ( pow2 32 * (v x5 % pow2 24) + v x5 / pow2 24 * pow2 56 == v x5 * pow2 32)
let lemma_div248_x5 x5 =
assert_norm (pow2 32 * pow2 24 = pow2 56)
val lemma_div248_x6: x6:uint64 ->
Lemma (pow2 32 * (v x6 % pow2 24) * pow2 56 + v x6 / pow2 24 * pow2 112 == v x6 * pow2 88)
let lemma_div248_x6 x6 =
calc (==) {
pow2 32 * (v x6 % pow2 24) * pow2 56 + v x6 / pow2 24 * pow2 112;
(==) { _ by (Tactics.norm [delta_only [`%pow2]; primops]; int_semiring ()) }
((v x6 / pow2 24) * pow2 24 + v x6 % pow2 24) * pow2 88;
(==) { FStar.Math.Lemmas.euclidean_division_definition (v x6) (pow2 24) }
v x6 * pow2 88;
}
val lemma_div248_x7: x7:uint64 ->
Lemma (pow2 32 * (v x7 % pow2 24) * pow2 112 + v x7 / pow2 24 * pow2 168 == v x7 * pow2 144)
let lemma_div248_x7 x7 =
calc (==) {
pow2 32 * (v x7 % pow2 24) * pow2 112 + v x7 / pow2 24 * pow2 168;
(==) { _ by (Tactics.norm [delta_only [`%pow2]; primops]; int_semiring ()) }
((v x7 / pow2 24) * pow2 24 + v x7 % pow2 24) * pow2 144;
(==) { FStar.Math.Lemmas.euclidean_division_definition (v x7) (pow2 24) }
v x7 * pow2 144;
}
val lemma_div248_x8: x8:uint64 ->
Lemma (pow2 32 * (v x8 % pow2 24) * pow2 168 + v x8 / pow2 24 * pow2 224 == v x8 * pow2 200)
let lemma_div248_x8 x8 =
calc (==) {
pow2 32 * (v x8 % pow2 24) * pow2 168 + v x8 / pow2 24 * pow2 224;
(==) { _ by (Tactics.norm [delta_only [`%pow2]; primops]; int_semiring ()) }
((v x8 / pow2 24) * pow2 24 + v x8 % pow2 24) * pow2 200;
(==) { FStar.Math.Lemmas.euclidean_division_definition (v x8) (pow2 24) }
v x8 * pow2 200;
}
val lemma_div248_x9: x9:uint64{v x9 < pow2 24} ->
Lemma (pow2 32 * (v x9 % pow2 24) * pow2 224 == v x9 * pow2 256)
let lemma_div248_x9 x9 =
calc (==) {
pow2 32 * (v x9 % pow2 24) * pow2 224;
(==) { Math.Lemmas.small_mod (v x9) (pow2 24) }
pow2 32 * v x9 * pow2 224;
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
v x9 * pow2 256;
}
val lemma_wide_as_nat_pow512: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 512)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
v x9 < pow2 24))
let lemma_wide_as_nat_pow512 x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert_norm (pow2 504 * pow2 8 = pow2 512);
FStar.Math.Lemmas.pow2_minus 512 504;
assert (v x9 < pow2 8);
assert_norm (pow2 8 < pow2 24)
val lemma_div248: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 512)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
let z0 = v x4 / pow2 24 + pow2 32 * (v x5 % pow2 24) in
let z1 = v x5 / pow2 24 + pow2 32 * (v x6 % pow2 24) in
let z2 = v x6 / pow2 24 + pow2 32 * (v x7 % pow2 24) in
let z3 = v x7 / pow2 24 + pow2 32 * (v x8 % pow2 24) in
let z4 = v x8 / pow2 24 + pow2 32 * (v x9 % pow2 24) in
wide_as_nat5 x / pow2 248 == z0 + z1 * pow2 56 + z2 * pow2 112 + z3 * pow2 168 + z4 * pow2 224))
#push-options "--z3rlimit 50"
let lemma_div248 x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
lemma_wide_as_nat_pow512 x;
assert (v x9 < pow2 24);
calc (==) {
(let z0 = v x4 / pow2 24 + pow2 32 * (v x5 % pow2 24) in
let z1 = v x5 / pow2 24 + pow2 32 * (v x6 % pow2 24) in
let z2 = v x6 / pow2 24 + pow2 32 * (v x7 % pow2 24) in
let z3 = v x7 / pow2 24 + pow2 32 * (v x8 % pow2 24) in
let z4 = v x8 / pow2 24 + pow2 32 * (v x9 % pow2 24) in
z0 + z1 * pow2 56 + z2 * pow2 112 + z3 * pow2 168 + z4 * pow2 224);
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
v x4 / pow2 24 + pow2 32 * (v x5 % pow2 24) +
v x5 / pow2 24 * pow2 56 + pow2 32 * (v x6 % pow2 24) * pow2 56 +
v x6 / pow2 24 * pow2 112 + pow2 32 * (v x7 % pow2 24) * pow2 112 +
v x7 / pow2 24 * pow2 168 + pow2 32 * (v x8 % pow2 24) * pow2 168 +
v x8 / pow2 24 * pow2 224 + pow2 32 * (v x9 % pow2 24) * pow2 224;
(==) { lemma_div248_x5 x5; lemma_div248_x6 x6 }
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 +
pow2 32 * (v x7 % pow2 24) * pow2 112 +
v x7 / pow2 24 * pow2 168 + pow2 32 * (v x8 % pow2 24) * pow2 168 +
v x8 / pow2 24 * pow2 224 + pow2 32 * (v x9 % pow2 24) * pow2 224;
(==) { lemma_div248_x7 x7; lemma_div248_x8 x8 }
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 +
pow2 32 * (v x9 % pow2 24) * pow2 224;
(==) { lemma_div248_x9 x9 }
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256;
(==) { lemma_div248_aux x }
wide_as_nat5 x / pow2 248;
}
#pop-options
val lemma_add_modq5:
x:qelem5
-> y:qelem5
-> t:qelem5 ->
Lemma
(requires
qelem_fits5 x (1, 1, 1, 1, 1) /\
qelem_fits5 y (1, 1, 1, 1, 1) /\
qelem_fits5 t (1, 1, 1, 1, 1) /\
as_nat5 x < S.q /\ as_nat5 y < S.q /\
as_nat5 t == as_nat5 x + as_nat5 y)
(ensures
(let res = if as_nat5 t >= S.q then as_nat5 t - S.q else as_nat5 t in
res < S.q /\ res == (as_nat5 x + as_nat5 y) % S.q))
let lemma_add_modq5 x y t =
assert (as_nat5 t == as_nat5 x + as_nat5 y);
let res = if as_nat5 t >= S.q then as_nat5 t - S.q else as_nat5 t in
assert (res < S.q);
if as_nat5 t >= S.q then (
FStar.Math.Lemmas.sub_div_mod_1 (as_nat5 t) S.q;
assert (res % S.q == as_nat5 t % S.q))
else
assert (res % S.q == as_nat5 t % S.q);
FStar.Math.Lemmas.small_mod res S.q
val lemma_wide_as_nat_pow528: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 528)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
v x9 < pow2 40))
let lemma_wide_as_nat_pow528 x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert_norm (pow2 504 * pow2 24 = pow2 528);
FStar.Math.Lemmas.pow2_minus 528 504;
assert (v x9 < pow2 24);
assert_norm (pow2 24 < pow2 40)
#push-options "--z3cliopt smt.arith.nl=false"
val lemma_div264_aux: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 528)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
wide_as_nat5 x / pow2 264 ==
v x4 / pow2 40 + v x5 * pow2 16 + v x6 * pow2 72 + v x7 * pow2 128 + v x8 * pow2 184 + v x9 * pow2 240))
let lemma_div264_aux x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert_norm (pow2 264 == pow2 224 * pow2 40);
assert_norm (pow2 56 == pow2 16 * pow2 40);
assert_norm (pow2 112 == pow2 72 * pow2 40);
assert_norm (pow2 168 == pow2 128 * pow2 40);
assert_norm (pow2 224 == pow2 184 * pow2 40);
assert_norm (pow2 280 == pow2 240 * pow2 40);
assert_norm (0 < pow2 40);
calc (==) {
wide_as_nat5 x / pow2 264;
(==) { FStar.Math.Lemmas.division_multiplication_lemma (wide_as_nat5 x) (pow2 224) (pow2 40) }
(wide_as_nat5 x / pow2 224) / pow2 40;
(==) { lemma_div224 x }
(v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280) / pow2 40;
(==) { _ by (Tactics.mapply (`feq #int #int (fun x -> x / pow2 40)); int_semiring ()) }
(v x4 + (v x5 * pow2 16 + v x6 * pow2 72 + v x7 * pow2 128 + v x8 * pow2 184 + v x9 * pow2 240) * pow2 40) / pow2 40;
(==) { FStar.Math.Lemmas.lemma_div_plus (v x4) (v x5 * pow2 16 + v x6 * pow2 72 + v x7 * pow2 128 + v x8 * pow2 184 + v x9 * pow2 240) (pow2 40) }
v x4 / pow2 40 + v x5 * pow2 16 + v x6 * pow2 72 + v x7 * pow2 128 + v x8 * pow2 184 + v x9 * pow2 240;
}
val lemma_div264_x5: x5:uint64 ->
Lemma (pow2 16 * (v x5 % pow2 40) + v x5 / pow2 40 * pow2 56 == v x5 * pow2 16)
let lemma_div264_x5 x5 =
assert_norm (0 < pow2 24);
calc (==) {
pow2 16 * (v x5 % pow2 40) + v x5 / pow2 40 * pow2 56;
(==) { _ by (Tactics.norm [delta_only [`%pow2]; primops]; int_semiring ()) }
((v x5 / pow2 40) * pow2 40 + v x5 % pow2 40) * pow2 16;
(==) { FStar.Math.Lemmas.euclidean_division_definition (v x5) (pow2 40) }
v x5 * pow2 16;
}
val lemma_div264_x6: x6:uint64 ->
Lemma (pow2 16 * (v x6 % pow2 40) * pow2 56 + v x6 / pow2 40 * pow2 112 == v x6 * pow2 72)
let lemma_div264_x6 x6 =
calc (==) {
pow2 16 * (v x6 % pow2 40) * pow2 56 + v x6 / pow2 40 * pow2 112;
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
((v x6 / pow2 40) * pow2 40 + v x6 % pow2 40) * pow2 72;
(==) { Math.Lemmas.euclidean_division_definition (v x6) (pow2 40) }
v x6 * pow2 72;
}
val lemma_div264_x7: x7:uint64 ->
Lemma (pow2 16 * (v x7 % pow2 40) * pow2 112 + v x7 / pow2 40 * pow2 168 == v x7 * pow2 128)
let lemma_div264_x7 x7 =
calc (==) {
pow2 16 * (v x7 % pow2 40) * pow2 112 + v x7 / pow2 40 * pow2 168;
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
((v x7 / pow2 40) * pow2 40 + v x7 % pow2 40) * pow2 128;
(==) { Math.Lemmas.euclidean_division_definition (v x7) (pow2 40) }
v x7 * pow2 128;
}
val lemma_div264_x8: x8:uint64 ->
Lemma (pow2 16 * (v x8 % pow2 40) * pow2 168 + v x8 / pow2 40 * pow2 224 == v x8 * pow2 184)
let lemma_div264_x8 x8 =
calc (==) {
pow2 16 * (v x8 % pow2 40) * pow2 168 + v x8 / pow2 40 * pow2 224;
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
((v x8 / pow2 40) * pow2 40 + v x8 % pow2 40) * pow2 184;
(==) { Math.Lemmas.euclidean_division_definition (v x8) (pow2 40) }
v x8 * pow2 184;
}
val lemma_div264_x9: x9:uint64{v x9 < pow2 40} ->
Lemma (pow2 16 * (v x9 % pow2 40) * pow2 224 == v x9 * pow2 240)
let lemma_div264_x9 x9 =
calc (==) {
pow2 16 * (v x9 % pow2 40) * pow2 224;
(==) { Math.Lemmas.small_mod (v x9) (pow2 40) }
pow2 16 * v x9 * pow2 224;
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
v x9 * pow2 240;
}
val lemma_div264: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 528)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
let z0 = v x4 / pow2 40 + pow2 16 * (v x5 % pow2 40) in
let z1 = v x5 / pow2 40 + pow2 16 * (v x6 % pow2 40) in
let z2 = v x6 / pow2 40 + pow2 16 * (v x7 % pow2 40) in
let z3 = v x7 / pow2 40 + pow2 16 * (v x8 % pow2 40) in
let z4 = v x8 / pow2 40 + pow2 16 * (v x9 % pow2 40) in
wide_as_nat5 x / pow2 264 == z0 + z1 * pow2 56 + z2 * pow2 112 + z3 * pow2 168 + z4 * pow2 224))
#push-options "--z3rlimit 50"
let lemma_div264 x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
lemma_wide_as_nat_pow528 x;
assert (v x9 < pow2 40);
calc (==) {
(let z0 = v x4 / pow2 40 + pow2 16 * (v x5 % pow2 40) in
let z1 = v x5 / pow2 40 + pow2 16 * (v x6 % pow2 40) in
let z2 = v x6 / pow2 40 + pow2 16 * (v x7 % pow2 40) in
let z3 = v x7 / pow2 40 + pow2 16 * (v x8 % pow2 40) in
let z4 = v x8 / pow2 40 + pow2 16 * (v x9 % pow2 40) in
z0 + z1 * pow2 56 + z2 * pow2 112 + z3 * pow2 168 + z4 * pow2 224);
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
v x4 / pow2 40 + pow2 16 * (v x5 % pow2 40) +
v x5 / pow2 40 * pow2 56 + pow2 16 * (v x6 % pow2 40) * pow2 56 +
v x6 / pow2 40 * pow2 112 + pow2 16 * (v x7 % pow2 40) * pow2 112 +
v x7 / pow2 40 * pow2 168 + pow2 16 * (v x8 % pow2 40) * pow2 168 +
v x8 / pow2 40 * pow2 224 + pow2 16 * (v x9 % pow2 40) * pow2 224;
(==) { lemma_div264_x5 x5; lemma_div264_x6 x6 }
v x4 / pow2 40 + v x5 * pow2 16 + v x6 * pow2 72 +
pow2 16 * (v x7 % pow2 40) * pow2 112 +
v x7 / pow2 40 * pow2 168 + pow2 16 * (v x8 % pow2 40) * pow2 168 +
v x8 / pow2 40 * pow2 224 + pow2 16 * (v x9 % pow2 40) * pow2 224;
(==) { lemma_div264_x7 x7; lemma_div264_x8 x8 }
v x4 / pow2 40 + v x5 * pow2 16 + v x6 * pow2 72 + v x7 * pow2 128 + v x8 * pow2 184 +
pow2 16 * (v x9 % pow2 40) * pow2 224;
(==) { lemma_div264_x9 x9 }
v x4 / pow2 40 + v x5 * pow2 16 + v x6 * pow2 72 + v x7 * pow2 128 + v x8 * pow2 184 + v x9 * pow2 240;
(==) { lemma_div264_aux x }
wide_as_nat5 x / pow2 264;
}
#pop-options
#pop-options // "--z3cliopt smt.arith.nl=false"
val lemma_mod_264_aux: t:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 t (1, 1, 1, 1, 1, 1, 1, 1, 1, 1))
(ensures
(let (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) = t in
(wide_as_nat5 t) % pow2 264 ==
(v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + v t4 * pow2 224) % pow2 264))
#push-options "--z3rlimit 150"
let lemma_mod_264_aux t =
let (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) = t in
let res = (t0, t1, t2, t3, t4 &. u64 0xffffffffff) in
assert_norm (pow2 16 * pow2 264 == pow2 280);
assert_norm (pow2 72 * pow2 264 == pow2 336);
assert_norm (pow2 128 * pow2 264 == pow2 392);
assert_norm (pow2 184 * pow2 264 == pow2 448);
assert_norm (pow2 240 * pow2 264 == pow2 504);
calc (==) {
(wide_as_nat5 t) % pow2 264;
(==) { }
(v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + v t4 * pow2 224 +
(v t5 * pow2 16 + v t6 * pow2 72 + v t7 * pow2 128 + v t8 * pow2 184 + v t9 * pow2 240) * pow2 264) % pow2 264;
(==) { FStar.Math.Lemmas.lemma_mod_add_distr (v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + v t4 * pow2 224)
((v t5 * pow2 16 + v t6 * pow2 72 + v t7 * pow2 128 + v t8 * pow2 184 + v t9 * pow2 240) * pow2 264) (pow2 264)}
((v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + v t4 * pow2 224) +
((v t5 * pow2 16 + v t6 * pow2 72 + v t7 * pow2 128 + v t8 * pow2 184 + v t9 * pow2 240) * pow2 264) % pow2 264) % pow2 264;
(==) { FStar.Math.Lemmas.cancel_mul_mod (v t5 * pow2 16 + v t6 * pow2 72 + v t7 * pow2 128 + v t8 * pow2 184 + v t9 * pow2 240) (pow2 264) }
(v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + v t4 * pow2 224) % pow2 264;
}
#pop-options
val lemma_as_nat_pow264: x:qelem5 ->
Lemma
(requires
(let (x0, x1, x2, x3, x4) = x in
qelem_fits5 x (1, 1, 1, 1, 1) /\
v x4 < pow2 40))
(ensures as_nat5 x < pow2 264)
let lemma_as_nat_pow264 x =
let (x0, x1, x2, x3, x4) = x in
assert_norm (pow2 40 * pow2 224 = pow2 264)
val lemma_mod_264: t:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 t (1, 1, 1, 1, 1, 1, 1, 1, 1, 1))
(ensures
(let (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) = t in
let res = (t0, t1, t2, t3, t4 &. u64 0xffffffffff) in
qelem_fits5 res (1, 1, 1, 1, 1) /\
as_nat5 res == (wide_as_nat5 t) % pow2 264))
let lemma_mod_264 t =
let (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) = t in
let t4' = t4 &. u64 0xffffffffff in
let res = (t0, t1, t2, t3, t4') in
assert_norm (pow2 40 < pow2 64);
assert_norm (pow2 40 - 1 == 0xffffffffff);
mod_mask_lemma t4 40ul;
assert (v (mod_mask #U64 #SEC 40ul) == 0xffffffffff);
assert (v (t4 &. u64 0xffffffffff) == v t4 % pow2 40);
calc (==) {
(wide_as_nat5 t) % pow2 264;
(==) { lemma_mod_264_aux t }
(v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + v t4 * pow2 224) % pow2 264;
(==) { FStar.Math.Lemmas.lemma_mod_add_distr (v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168) (v t4 * pow2 224) (pow2 264) }
(v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + (v t4 * pow2 224) % pow2 264) % pow2 264;
(==) { FStar.Math.Lemmas.pow2_multiplication_modulo_lemma_2 (v t4) 264 224 }
(v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + (v t4 % pow2 40) * pow2 224) % pow2 264;
(==) { lemma_as_nat_pow264 res; FStar.Math.Lemmas.modulo_lemma (as_nat5 res) (pow2 264) }
v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + (v t4 % pow2 40) * pow2 224;
}
val lemma_as_nat_pow264_x4: x:qelem5 ->
Lemma
(requires
qelem_fits5 x (1, 1, 1, 1, 1) /\
as_nat5 x < pow2 264)
(ensures
(let (x0, x1, x2, x3, x4) = x in
v x4 < pow2 40))
let lemma_as_nat_pow264_x4 x =
let (x0, x1, x2, x3, x4) = x in
assert_norm (pow2 40 * pow2 224 = pow2 264)
val lemma_sub_mod_264_aux:
x0:nat -> x1:nat -> x2:nat -> x3:nat -> x4:nat
-> y0:nat -> y1:nat -> y2:nat -> y3:nat -> y4:nat
-> c1:nat -> c2:nat -> c3:nat -> c4:nat -> c5:nat ->
Lemma (
x0 - y0 + c1 * pow56 +
(x1 - y1 - c1 + c2 * pow56) * pow56 +
(x2 - y2 - c2 + c3 * pow56) * pow112 +
(x3 - y3 - c3 + c4 * pow56) * pow168 +
(x4 - y4 - c4 + pow2 40 * c5) * pow224 ==
(x0 + x1 * pow2 56 + x2 * pow2 112 + x3 * pow2 168 + x4 * pow2 224) -
(y0 + y1 * pow2 56 + y2 * pow2 112 + y3 * pow2 168 + y4 * pow2 224) + c5 * pow2 264)
#push-options "--z3rlimit 50"
let lemma_sub_mod_264_aux x0 x1 x2 x3 x4 y0 y1 y2 y3 y4 b0 b1 b2 b3 b4 =
assert_norm (pow2 56 * pow2 56 = pow2 112);
assert_norm (pow2 56 * pow2 112 = pow2 168);
assert_norm (pow2 56 * pow2 168 = pow2 224);
assert_norm (pow2 40 * pow2 224 = pow2 264)
#pop-options
val lemma_sub_mod_264:
x:qelem5
-> y:qelem5
-> t:qelem5
-> c5:uint64 ->
Lemma
(requires
qelem_fits5 x (1, 1, 1, 1, 1) /\
qelem_fits5 y (1, 1, 1, 1, 1) /\
qelem_fits5 t (1, 1, 1, 1, 1) /\
as_nat5 x < pow2 264 /\
as_nat5 y < pow2 264 /\
as_nat5 t == as_nat5 x - as_nat5 y + v c5 * pow2 264 /\ v c5 <= 1 /\
(if v c5 = 0 then as_nat5 x >= as_nat5 y else as_nat5 x < as_nat5 y))
(ensures
(if as_nat5 x >= as_nat5 y then
as_nat5 t == as_nat5 x - as_nat5 y
else as_nat5 t == as_nat5 x - as_nat5 y + pow2 264))
#push-options "--z3rlimit 50"
let lemma_sub_mod_264 x y t c5 =
assert (if v c5 = 0 then as_nat5 x >= as_nat5 y else as_nat5 x < as_nat5 y);
assert (as_nat5 t == as_nat5 x - as_nat5 y + v c5 * pow2 264);
if as_nat5 x >= as_nat5 y then
assert (v c5 == 0 /\ as_nat5 t == as_nat5 x - as_nat5 y)
else
assert (v c5 == 1 /\ as_nat5 t == as_nat5 x - as_nat5 y + pow2 264)
#pop-options
let lemma_mul_qelem5 (x0 x1 x2 x3 x4 y0 y1 y2 y3 y4:nat) : Lemma
((x0 + x1 * pow2 56 + x2 * pow2 112 + x3 * pow2 168 + x4 * pow2 224) *
(y0 + y1 * pow2 56 + y2 * pow2 112 + y3 * pow2 168 + y4 * pow2 224) ==
x0 * y0 +
(x0 * y1 + x1 * y0) * pow56 +
(x0 * y2 + x1 * y1 + x2 * y0) * pow112 +
(x0 * y3 + x1 * y2 + x2 * y1 + x3 * y0) * pow168 +
(x0 * y4 + x1 * y3 + x2 * y2 + x3 * y1 + x4 * y0) * pow224 +
(x1 * y4 + x2 * y3 + x3 * y2 + x4 * y1) * pow280 +
(x2 * y4 + x3 * y3 + x4 * y2) * pow336 +
(x3 * y4 + x4 * y3) * pow392 +
(x4 * y4) * pow448)
=
assert ((x0 + x1 * pow2 56 + x2 * pow2 112 + x3 * pow2 168 + x4 * pow2 224) *
(y0 + y1 * pow2 56 + y2 * pow2 112 + y3 * pow2 168 + y4 * pow2 224) ==
x0 * y0 +
(x0 * y1 + x1 * y0) * pow56 +
(x0 * y2 + x1 * y1 + x2 * y0) * pow112 +
(x0 * y3 + x1 * y2 + x2 * y1 + x3 * y0) * pow168 +
(x0 * y4 + x1 * y3 + x2 * y2 + x3 * y1 + x4 * y0) * pow224 +
(x1 * y4 + x2 * y3 + x3 * y2 + x4 * y1) * pow280 +
(x2 * y4 + x3 * y3 + x4 * y2) * pow336 +
(x3 * y4 + x4 * y3) * pow392 +
(x4 * y4) * pow448)
by (Tactics.norm [zeta; iota; delta; primops]; int_semiring ())
val lemma_mul_5_low_264:
x1:nat -> x2:nat -> x3:nat -> x4:nat -> x5:nat ->
y1:nat -> y2:nat -> y3:nat -> y4:nat -> y5:nat ->
Lemma (
(x1 * y1) >= 0
/\ (x2 * y1 + x1 * y2 + ((x1 * y1) / pow2 56)) >= 0
/\ (x3 * y1 + x2 * y2 + x1 * y3 + ((x2 * y1 + x1 * y2 + ((x1 * y1) / pow2 56)) / pow2 56)) >= 0
/\ (x4 * y1 + x3 * y2 + x2 * y3 + x1 * y4 + ((x3 * y1 + x2 * y2 + x1 * y3 + ((x2 * y1 + x1 * y2 + ((x1 * y1) / pow2 56)) / pow2 56)) / pow2 56)) >= 0
/\ (
let a0 = (x1 * y1) % pow2 56 in
let a1 = ((x2 * y1 + x1 * y2 + ((x1 * y1) / pow2 56)) % pow2 56) in
let a2 = ((x3 * y1 + x2 * y2 + x1 * y3 + ((x2 * y1 + x1 * y2 + ((x1 * y1) / pow2 56)) / pow2 56)) % pow2 56) in
let a3 = ((x4 * y1 + x3 * y2 + x2 * y3 + x1 * y4 + ((x3 * y1 + x2 * y2 + x1 * y3 + ((x2 * y1 + x1 * y2 + ((x1 * y1) / pow2 56)) / pow2 56)) / pow2 56)) % pow2 56) in
let a4 = (x5 * y1 + x4 * y2 + x3 * y3 + x2 * y4 + x1 * y5 + ((x4 * y1 + x3 * y2 + x2 * y3 + x1 * y4 + ((x3 * y1 + x2 * y2 + x1 * y3 + ((x2 * y1 + x1 * y2 + ((x1 * y1) / pow2 56)) / pow2 56)) / pow2 56)) / pow2 56)) in
((x1 + pow2 56 * x2 + pow2 112 * x3 + pow2 168 * x4 + pow2 224 * x5)
* (y1 + pow2 56 * y2 + pow2 112 * y3 + pow2 168 * y4 + pow2 224 * y5)) % pow2 264
== a0 + pow2 56 * a1 + pow2 112 * a2 + pow2 168 * a3 + pow2 224 * (a4 % pow2 40)))
private let lemma_mul_nat_is_nat (a:nat) (b:nat) : Lemma (a*b >= 0) = ()
private let lemma_div_nat_is_nat (a:nat) (b:pos) : Lemma (a/b >= 0) = ()
private
val lemma_mul_5''':
x1:nat -> x2:nat -> x3:nat -> x4:nat -> x5:nat ->
y1:nat -> y2:nat -> y3:nat -> y4:nat -> y5:nat ->
Lemma (((x1 + pow2 56 * x2 + pow2 112 * x3 + pow2 168 * x4 + pow2 224 * x5)
* (y1 + pow2 56 * y2 + pow2 112 * y3 + pow2 168 * y4 + pow2 224 * y5)) % pow2 264
==
(x1 * y1
+ pow2 56 * (x2 * y1 + x1 * y2)
+ pow2 112 * (x3 * y1 + x2 * y2 + x1 * y3)
+ pow2 168 * (x4 * y1 + x3 * y2 + x2 * y3 + x1 * y4)
+ pow2 224 * (x5 * y1 + x4 * y2 + x3 * y3 + x2 * y4 + x1 * y5)) % pow2 264)
let lemma_mul_5''' x1 x2 x3 x4 x5 y1 y2 y3 y4 y5 =
calc (==) {
((x1 + pow2 56 * x2 + pow2 112 * x3 + pow2 168 * x4 + pow2 224 * x5)
* (y1 + pow2 56 * y2 + pow2 112 * y3 + pow2 168 * y4 + pow2 224 * y5)) % pow2 264;
(==) { _ by (Tactics.mapply (`feq #int #int (fun x -> x % pow2 264));
Tactics.norm [zeta; iota; delta; primops];
int_semiring ()) }
(x1 * y1
+ pow2 56 * (x2 * y1 + x1 * y2)
+ pow2 112 * (x3 * y1 + x2 * y2 + x1 * y3)
+ pow2 168 * (x4 * y1 + x3 * y2 + x2 * y3 + x1 * y4)
+ pow2 224 * (x5 * y1 + x4 * y2 + x3 * y3 + x2 * y4 + x1 * y5)
+ (pow2 16 * x2 * y5 +
pow2 16 * x3 * y4 + pow2 72 * x3 * y5 +
pow2 16 * x4 * y3 + pow2 72 * x4 * y4 + pow2 128 * x4 * y5 +
pow2 16 * x5 * y2 + pow2 72 * x5 * y3 + pow2 128 * x5 * y4 + pow2 184 * x5 * y5) * pow2 264) % pow2 264;
(==) { _ by (Tactics.mapply (`eq_eq2); Tactics.mapply (`Math.Lemmas.lemma_mod_plus)) }
(x1 * y1
+ pow2 56 * (x2 * y1 + x1 * y2)
+ pow2 112 * (x3 * y1 + x2 * y2 + x1 * y3)
+ pow2 168 * (x4 * y1 + x3 * y2 + x2 * y3 + x1 * y4)
+ pow2 224 * (x5 * y1 + x4 * y2 + x3 * y3 + x2 * y4 + x1 * y5)) % pow2 264;
}
private val lemma_mod_264'':
a0:nat -> a1:nat-> a2:nat -> a3:nat -> a4:nat ->
Lemma
(requires a0 < pow56 /\ a1 < pow56 /\ a2 < pow56 /\ a3 < pow56)
(ensures a0 + pow2 56 * a1 + pow2 112 * a2 + pow2 168 * a3 + pow2 224 * (a4 % pow2 40) < pow2 264)
let lemma_mod_264'' a0 a1 a2 a3 a4 =
assert_norm(pow2 40 = 0x10000000000);
assert_norm(pow2 56 = 0x100000000000000);
assert_norm(pow2 112 = 0x10000000000000000000000000000);
assert_norm(pow2 168 = 0x1000000000000000000000000000000000000000000);
assert_norm(pow2 224 = 0x100000000000000000000000000000000000000000000000000000000);
assert_norm(pow2 264 = 0x1000000000000000000000000000000000000000000000000000000000000000000)
private val lemma_mod_264':
a0:nat -> a1:nat-> a2:nat -> a3:nat -> a4:nat ->
Lemma
(requires a0 < pow56 /\ a1 < pow56 /\ a2 < pow56 /\ a3 < pow56)
(ensures (a0
+ pow2 56 * a1
+ pow2 112 * a2
+ pow2 168 * a3
+ pow2 224 * a4) % pow2 264 =
a0
+ pow2 56 * a1
+ pow2 112 * a2
+ pow2 168 * a3
+ pow2 224 * (a4 % pow2 40) )
let lemma_mod_264' a0 a1 a2 a3 a4 =
assert_norm(pow2 56 = 0x100000000000000);
assert_norm(pow2 112 = 0x10000000000000000000000000000);
assert_norm(pow2 168 = 0x1000000000000000000000000000000000000000000);
assert_norm(pow2 224 = 0x100000000000000000000000000000000000000000000000000000000);
Math.Lemmas.lemma_mod_plus_distr_l (pow2 224 * a4) (a0 + pow2 56 * a1 + pow2 112 * a2 + pow2 168 * a3) (pow2 264);
Math.Lemmas.pow2_multiplication_modulo_lemma_2 a4 264 224;
lemma_mod_264'' a0 a1 a2 a3 a4;
Math.Lemmas.modulo_lemma (a0 + pow2 56 * a1 + pow2 112 * a2 + pow2 168 * a3 + pow2 224 * (a4 % pow2 40)) (pow2 264)
private let lemma_aux_0 (a:nat) (b:nat) (n:nat) : Lemma
(pow2 n * a + pow2 (n+56) * b = pow2 n * (a % pow2 56) + pow2 (n+56) * (b + a / pow2 56))
= Math.Lemmas.lemma_div_mod a (pow2 56);
Math.Lemmas.pow2_plus n 56;
assert(a = pow2 56 * (a / pow2 56) + (a % pow2 56));
Math.Lemmas.distributivity_add_right (pow2 n) (pow2 56 * (a / pow2 56)) (a % pow2 56);
Math.Lemmas.paren_mul_right (pow2 n) (pow2 56) (a / pow2 56);
Math.Lemmas.distributivity_add_right (pow2 (n+56)) b (a / pow2 56)
private
val lemma_mod_264_small:
a0:nat -> a1:nat -> a2:nat -> a3:nat -> a4:nat ->
Lemma ( (a0 + pow2 56 * a1 + pow2 112 * a2 + pow2 168 * a3 + pow2 224 * a4)
= (a0 % pow2 56)
+ pow2 56 * ((a1 + (a0 / pow2 56)) % pow2 56)
+ pow2 112 * ((a2 + ((a1 + (a0 / pow2 56)) / pow2 56)) % pow2 56)
+ pow2 168 * ((a3 + ((a2 + ((a1 + (a0 / pow2 56)) / pow2 56)) / pow2 56)) % pow2 56)
+ pow2 224 * (a4 + ((a3 + ((a2 + ((a1 + (a0 / pow2 56)) / pow2 56)) / pow2 56)) / pow2 56)))
(* These silly lemmas needed to guide the proof below... *)
private let aux_nat_over_pos (p : nat) (q : pos) : Lemma (p / q >= 0) = ()
private let aux_nat_plus_nat (p : nat) (q : nat) : Lemma (p + q >= 0) = ()
let lemma_mod_264_small a0 a1 a2 a3 a4 =
Math.Lemmas.lemma_div_mod a0 (pow2 56);
Math.Lemmas.distributivity_add_right (pow2 56) a1 (a0 / pow2 56);
(**) aux_nat_over_pos a0 (pow2 56);
(**) aux_nat_plus_nat a1 (a0 / pow2 56);
let a1':nat = (a1 + (a0 / pow2 56)) in
(**) aux_nat_over_pos a1' (pow2 56);
(**) aux_nat_plus_nat a2 (a1' / pow2 56);
let a2':nat = (a2 + (a1' / pow2 56)) in
(**) aux_nat_over_pos a2' (pow2 56);
(**) aux_nat_plus_nat a3 (a2' / pow2 56);
let a3':nat = (a3 + (a2' / pow2 56)) in
lemma_aux_0 a1' a2 56;
lemma_aux_0 a2' a3 112;
lemma_aux_0 a3' a4 168
private
val lemma_mod_264_:
a0:nat -> a1:nat -> a2:nat -> a3:nat -> a4:nat ->
Lemma ((a0 + pow2 56 * a1 + pow2 112 * a2 + pow2 168 * a3 + pow2 224 * a4) % pow2 264 =
(a0 % pow2 56)
+ pow2 56 * ((a1 + (a0 / pow2 56)) % pow2 56)
+ pow2 112 * ((a2 + ((a1 + (a0 / pow2 56)) / pow2 56)) % pow2 56)
+ pow2 168 * ((a3 + ((a2 + ((a1 + (a0 / pow2 56)) / pow2 56)) / pow2 56)) % pow2 56)
+ pow2 224 * ((a4 + ((a3 + ((a2 + ((a1 + (a0 / pow2 56)) / pow2 56)) / pow2 56)) / pow2 56)) % pow2 40)) | {
"checked_file": "/",
"dependencies": [
"Spec.Ed25519.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.BignumQ.Definitions.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Tactics.CanonCommSemiring.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.BignumQ.Lemmas.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.CanonCommSemiring",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.BignumQ.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.Ed25519",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.CanonCommSemiring",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.BignumQ",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.BignumQ",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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 | a0: Prims.nat -> a1: Prims.nat -> a2: Prims.nat -> a3: Prims.nat -> a4: Prims.nat
-> FStar.Pervasives.Lemma
(ensures
(a0 + Prims.pow2 56 * a1 + Prims.pow2 112 * a2 + Prims.pow2 168 * a3 + Prims.pow2 224 * a4) %
Prims.pow2 264 =
a0 % Prims.pow2 56 + Prims.pow2 56 * ((a1 + a0 / Prims.pow2 56) % Prims.pow2 56) +
Prims.pow2 112 * ((a2 + (a1 + a0 / Prims.pow2 56) / Prims.pow2 56) % Prims.pow2 56) +
Prims.pow2 168 *
((a3 + (a2 + (a1 + a0 / Prims.pow2 56) / Prims.pow2 56) / Prims.pow2 56) % Prims.pow2 56) +
Prims.pow2 224 *
((a4 + (a3 + (a2 + (a1 + a0 / Prims.pow2 56) / Prims.pow2 56) / Prims.pow2 56) / Prims.pow2 56
) %
Prims.pow2 40)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.nat",
"Hacl.Spec.BignumQ.Lemmas.lemma_mod_264'",
"Prims.op_Addition",
"Prims.op_Division",
"Prims.pow2",
"Prims.unit",
"Prims._assert",
"Prims.b2t",
"Prims.op_LessThan",
"Hacl.Spec.BignumQ.Definitions.pow56",
"Prims.int",
"Prims.op_Modulus",
"Hacl.Spec.BignumQ.Lemmas.lemma_mod_264_small"
] | [] | true | false | true | false | false | let lemma_mod_264_ a0 a1 a2 a3 a4 =
| lemma_mod_264_small a0 a1 a2 a3 a4;
let x0 = a0 % pow2 56 in
assert (x0 < pow56);
let x1 = ((a1 + (a0 / pow2 56)) % pow2 56) in
assert (x1 < pow56);
let x2 = ((a2 + ((a1 + (a0 / pow2 56)) / pow2 56)) % pow2 56) in
assert (x2 < pow56);
let x3 = ((a3 + ((a2 + ((a1 + (a0 / pow2 56)) / pow2 56)) / pow2 56)) % pow2 56) in
assert (x3 < pow56);
lemma_mod_264' x0
x1
x2
x3
(a4 + ((a3 + ((a2 + ((a1 + (a0 / pow2 56)) / pow2 56)) / pow2 56)) / pow2 56)) | false |
Monad.fst | Monad.f | val f (#a #b #m: _) {| _: monad m |} (x: m (a -> b)) (y: m a) : m b | val f (#a #b #m: _) {| _: monad m |} (x: m (a -> b)) (y: m a) : m b | let f #a #b #m {| monad m |} (x : m (a -> b)) (y : m a) : m b =
bind #m x (fun x ->
bind #m y (fun y ->
return #m (x y))) | {
"file_name": "examples/typeclasses/Monad.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 19,
"end_line": 49,
"start_col": 0,
"start_line": 46
} | (*
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 Monad
open FStar.Tactics.Typeclasses
(* Fails... due to unification? check it out *)
// class monad (m:Type0 -> Type0) : Type = {
// return : #a:_ -> a -> m a;
// bind : #a:_ -> #b:_ -> m a -> (a -> m b) -> m b;
// idL : #a:_ -> #b:_ -> x:a -> f:(a -> m b) -> Lemma (bind (return x) f == f x);
// idR : #a:_ -> x:m a -> Lemma (bind x return == x);
// assoc : #a:_ -> #b:_ -> #c:_ -> x:m a -> f:(a -> m b) -> g:(b -> m c) ->
// Lemma (bind (bind x f) g ==
// bind x (fun y -> bind (f y) g));
// }
noeq
type monad_laws (m:Type0 -> Type0) (return : (#a:_ -> a -> m a)) (bind : (#a:_ -> #b:_ -> m a -> (a -> m b) -> m b)) = {
idL : #a:_ -> #b:_ -> x:a -> f:(a -> m b) -> Lemma (bind (return x) f == f x);
idR : #a:_ -> x:m a -> Lemma (bind x return == x);
assoc : #a:_ -> #b:_ -> #c:_ -> x:m a -> f:(a -> m b) -> g:(b -> m c) ->
Lemma (bind (bind x f) g ==
bind x (fun y -> bind (f y) g));
}
class monad (m : Type0 -> Type0) = {
return : #a:_ -> a -> m a;
bind : #a:_ -> #b:_ -> m a -> (a -> m b) -> m b;
laws : monad_laws m return bind;
} | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Functor.fst.checked",
"FStar.Tactics.Typeclasses.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Monad.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 | {| _: Monad.monad m |} -> x: m (_: a -> b) -> y: m a -> m b | Prims.Tot | [
"total"
] | [] | [
"Monad.monad",
"Monad.bind",
"Monad.return"
] | [] | false | false | false | false | false | let f #a #b #m {| _: monad m |} (x: m (a -> b)) (y: m a) : m b =
| bind #m x (fun x -> bind #m y (fun y -> return #m (x y))) | false |
Monad.fst | Monad.monad_functor | [@@ FStar.Tactics.Typeclasses.tcinstance]
val monad_functor (#m: _) (d: monad m) : functor m | [@@ FStar.Tactics.Typeclasses.tcinstance]
val monad_functor (#m: _) (d: monad m) : functor m | instance monad_functor #m (d : monad m) : functor m =
{ fmap = (fun #_ #_ f x -> bind #m x (fun xx -> return #m (f xx))); } | {
"file_name": "examples/typeclasses/Monad.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 71,
"end_line": 65,
"start_col": 0,
"start_line": 64
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Monad
open FStar.Tactics.Typeclasses
(* Fails... due to unification? check it out *)
// class monad (m:Type0 -> Type0) : Type = {
// return : #a:_ -> a -> m a;
// bind : #a:_ -> #b:_ -> m a -> (a -> m b) -> m b;
// idL : #a:_ -> #b:_ -> x:a -> f:(a -> m b) -> Lemma (bind (return x) f == f x);
// idR : #a:_ -> x:m a -> Lemma (bind x return == x);
// assoc : #a:_ -> #b:_ -> #c:_ -> x:m a -> f:(a -> m b) -> g:(b -> m c) ->
// Lemma (bind (bind x f) g ==
// bind x (fun y -> bind (f y) g));
// }
noeq
type monad_laws (m:Type0 -> Type0) (return : (#a:_ -> a -> m a)) (bind : (#a:_ -> #b:_ -> m a -> (a -> m b) -> m b)) = {
idL : #a:_ -> #b:_ -> x:a -> f:(a -> m b) -> Lemma (bind (return x) f == f x);
idR : #a:_ -> x:m a -> Lemma (bind x return == x);
assoc : #a:_ -> #b:_ -> #c:_ -> x:m a -> f:(a -> m b) -> g:(b -> m c) ->
Lemma (bind (bind x f) g ==
bind x (fun y -> bind (f y) g));
}
class monad (m : Type0 -> Type0) = {
return : #a:_ -> a -> m a;
bind : #a:_ -> #b:_ -> m a -> (a -> m b) -> m b;
laws : monad_laws m return bind;
}
let f #a #b #m {| monad m |} (x : m (a -> b)) (y : m a) : m b =
bind #m x (fun x ->
bind #m y (fun y ->
return #m (x y)))
let g #a #b #m {| d : monad m |} (x : m a) =
d.laws.idL () (fun () -> x);
d.laws.idR x;
assert (bind #m x (return #m) == bind #m (return #m ()) (fun () -> x))
(* Same bug as EnumEq, I think, requiring the #d in for laws *)
let g' #a #b #m {| monad m |} (x : m a) =
(laws #m).idL () (fun () -> x);
(laws #m).idR x;
assert (bind #m x (return #m) == bind #m (return #m ()) (fun () -> x))
open Functor | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Functor.fst.checked",
"FStar.Tactics.Typeclasses.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Monad.fst"
} | [
{
"abbrev": false,
"full_module": "Functor",
"short_module": null
},
{
"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 | d: Monad.monad m -> Functor.functor m | Prims.Tot | [
"total"
] | [] | [
"Monad.monad",
"Functor.Mkfunctor",
"Monad.bind",
"Monad.return",
"Functor.functor"
] | [] | false | false | false | false | false | [@@ FStar.Tactics.Typeclasses.tcinstance]
let monad_functor #m (d: monad m) : functor m =
| { fmap = (fun #_ #_ f x -> bind #m x (fun xx -> return #m (f xx))) } | false |
Hacl.Spec.BignumQ.Lemmas.fst | Hacl.Spec.BignumQ.Lemmas.lemma_0 | val lemma_0 (x y: nat) (c: pos)
: Lemma (requires (x >= y /\ x - y < c)) (ensures (x / c - y / c <= 1)) | val lemma_0 (x y: nat) (c: pos)
: Lemma (requires (x >= y /\ x - y < c)) (ensures (x / c - y / c <= 1)) | let lemma_0 (x:nat) (y:nat) (c:pos) : Lemma
(requires (x >= y /\ x - y < c))
(ensures (x / c - y / c <= 1))
= if x / c - y / c > 1 then (
Math.Lemmas.lemma_div_mod x c;
Math.Lemmas.lemma_div_mod y c;
Math.Lemmas.distributivity_sub_right c (x / c) (y / c);
Math.Lemmas.lemma_div_mod (x-y) c;
Math.Lemmas.small_div (x-y) c;
Math.Lemmas.swap_mul c (x/c - y/c);
Math.Lemmas.cancel_mul_div (x/c - y/c) c
) | {
"file_name": "code/ed25519/Hacl.Spec.BignumQ.Lemmas.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 7,
"end_line": 851,
"start_col": 0,
"start_line": 840
} | module Hacl.Spec.BignumQ.Lemmas
open FStar.Tactics.CanonCommSemiring
open FStar.Mul
open Lib.IntTypes
module S = Spec.Ed25519
include Hacl.Spec.BignumQ.Definitions
let feq (#a #b:Type) (f:(a -> b)) (x y:a) :
Lemma (requires x == y) (ensures f x == f y) = ()
let eq_eq2 (#a:eqtype) (x y:a) :
Lemma (requires x = y) (ensures x == y) = ()
val lemma_mul_lt:a:nat -> b:nat -> c:nat -> d:nat ->
Lemma
(requires a < b /\ c < d)
(ensures a * c < b * d)
let lemma_mul_lt a b c d = ()
val lemma_as_nat5: f:qelem5 ->
Lemma
(requires qelem_fits5 f (1, 1, 1, 1, 1))
(ensures as_nat5 f < pow2 280)
let lemma_as_nat5 f =
//let (f0, f1, f2, f3, f4) = f in
//assert (as_nat5 f == v f0 + v f1 * pow56 + v f2 * pow112 + v f3 * pow168 + v f4 * pow224);
assert_norm (pow2 56 * pow2 56 = pow2 112);
assert_norm (pow2 56 * pow2 112 = pow2 168);
assert_norm (pow2 56 * pow2 168 = pow2 224);
assert_norm (pow2 56 * pow2 224 = pow2 280)
val lemma_choose_step:
bit:uint64{v bit <= 1}
-> x:uint64
-> y:uint64
-> Lemma
(let mask = bit -. u64 1 in
let z = x ^. (mask &. (x ^. y)) in
if v bit = 1 then z == x else z == y)
let lemma_choose_step bit p1 p2 =
let mask = bit -. u64 1 in
assert (v bit == 0 ==> v mask == pow2 64 - 1);
assert (v bit == 1 ==> v mask == 0);
let dummy = mask &. (p1 ^. p2) in
logand_lemma mask (p1 ^. p2);
assert (v bit == 1 ==> v dummy == 0);
assert (v bit == 0 ==> v dummy == v (p1 ^. p2));
let p1' = p1 ^. dummy in
assert (v dummy == v (if v bit = 1 then u64 0 else (p1 ^. p2)));
logxor_lemma p1 p2
val lemma_subm_conditional:
x0:nat -> x1:nat -> x2:nat -> x3:nat -> x4:nat
-> y0:nat -> y1:nat -> y2:nat -> y3:nat -> y4:nat
-> b0:nat -> b1:nat -> b2:nat -> b3:nat -> b4:nat ->
Lemma (
x0 - y0 + b0 * pow2 56 +
(x1 - y1 - b0 + b1 * pow2 56) * pow2 56 +
(x2 - y2 - b1 + b2 * pow2 56) * pow2 112 +
(x3 - y3 - b2 + b3 * pow2 56) * pow2 168 +
(x4 - y4 - b3 + b4 * pow2 56) * pow2 224 ==
(x0 + x1 * pow2 56 + x2 * pow2 112 + x3 * pow2 168 + x4 * pow2 224) -
(y0 + y1 * pow2 56 + y2 * pow2 112 + y3 * pow2 168 + y4 * pow2 224) + b4 * pow2 280)
let lemma_subm_conditional x0 x1 x2 x3 x4 y0 y1 y2 y3 y4 b0 b1 b2 b3 b4 =
assert_norm (pow2 56 * pow2 56 = pow2 112);
assert_norm (pow2 56 * pow2 112 = pow2 168);
assert_norm (pow2 56 * pow2 168 = pow2 224);
assert_norm (pow2 56 * pow2 224 = pow2 280);
assert (
x0 - y0 + b0 * pow2 56 +
(x1 - y1 - b0 + b1 * pow2 56) * pow2 56 +
(x2 - y2 - b1 + b2 * pow2 56) * pow2 112 +
(x3 - y3 - b2 + b3 * pow2 56) * pow2 168 +
(x4 - y4 - b3 + b4 * pow2 56) * pow2 224 ==
(x0 + x1 * pow2 56 + x2 * pow2 112 + x3 * pow2 168 + x4 * pow2 224) -
(y0 + y1 * pow2 56 + y2 * pow2 112 + y3 * pow2 168 + y4 * pow2 224) + b4 * pow2 280)
by (int_semiring ());
()
val lemma_div224: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1))
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
wide_as_nat5 x / pow2 224 ==
v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280))
#push-options "--z3rlimit 50"
let lemma_div224 x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert
(wide_as_nat5 x ==
v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168 + v x4 * pow2 224 +
v x5 * pow2 280 + v x6 * pow2 336 + v x7 * pow2 392 + v x8 * pow2 448 + v x9 * pow2 504);
assert_norm (pow2 56 * pow2 224 == pow2 280);
assert_norm (pow2 112 * pow2 224 == pow2 336);
assert_norm (pow2 168 * pow2 224 == pow2 392);
assert_norm (pow2 224 * pow2 224 == pow2 448);
assert_norm (pow2 280 * pow2 224 == pow2 504);
calc (==) {
wide_as_nat5 x / pow2 224;
(==) { }
(v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168 +
(v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280) * pow2 224) / pow2 224;
(==) {
FStar.Math.Lemmas.lemma_div_plus
(v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168)
(v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280) (pow2 224) }
(v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168) / pow2 224 +
v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280;
(==) { FStar.Math.Lemmas.small_division_lemma_1 (v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168) (pow2 224) }
v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280;
}
#pop-options
val lemma_div248_aux: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 512)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
wide_as_nat5 x / pow2 248 ==
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256))
open FStar.Tactics.CanonCommSemiring
#push-options "--z3cliopt smt.arith.nl=false"
let lemma_div248_aux x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert_norm (pow2 248 == pow2 224 * pow2 24);
assert_norm (pow2 56 == pow2 32 * pow2 24);
assert_norm (pow2 112 == pow2 88 * pow2 24);
assert_norm (pow2 168 == pow2 144 * pow2 24);
assert_norm (pow2 224 == pow2 200 * pow2 24);
assert_norm (pow2 280 == pow2 256 * pow2 24);
assert_norm (0 < pow2 24);
calc (==) {
wide_as_nat5 x / pow2 248;
(==) { FStar.Math.Lemmas.division_multiplication_lemma (wide_as_nat5 x) (pow2 224) (pow2 24) }
(wide_as_nat5 x / pow2 224) / pow2 24;
(==) { lemma_div224 x }
(v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280) / pow2 24;
(==) { _ by (Tactics.mapply (`feq #int #int (fun x -> x / pow2 24)); int_semiring ()) } (v x4 + (v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256) * pow2 24) / pow2 24;
(==) { FStar.Math.Lemmas.lemma_div_plus (v x4) (v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256) (pow2 24) }
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256;
}
#pop-options
val lemma_div248_x5: x5:uint64 ->
Lemma ( pow2 32 * (v x5 % pow2 24) + v x5 / pow2 24 * pow2 56 == v x5 * pow2 32)
let lemma_div248_x5 x5 =
assert_norm (pow2 32 * pow2 24 = pow2 56)
val lemma_div248_x6: x6:uint64 ->
Lemma (pow2 32 * (v x6 % pow2 24) * pow2 56 + v x6 / pow2 24 * pow2 112 == v x6 * pow2 88)
let lemma_div248_x6 x6 =
calc (==) {
pow2 32 * (v x6 % pow2 24) * pow2 56 + v x6 / pow2 24 * pow2 112;
(==) { _ by (Tactics.norm [delta_only [`%pow2]; primops]; int_semiring ()) }
((v x6 / pow2 24) * pow2 24 + v x6 % pow2 24) * pow2 88;
(==) { FStar.Math.Lemmas.euclidean_division_definition (v x6) (pow2 24) }
v x6 * pow2 88;
}
val lemma_div248_x7: x7:uint64 ->
Lemma (pow2 32 * (v x7 % pow2 24) * pow2 112 + v x7 / pow2 24 * pow2 168 == v x7 * pow2 144)
let lemma_div248_x7 x7 =
calc (==) {
pow2 32 * (v x7 % pow2 24) * pow2 112 + v x7 / pow2 24 * pow2 168;
(==) { _ by (Tactics.norm [delta_only [`%pow2]; primops]; int_semiring ()) }
((v x7 / pow2 24) * pow2 24 + v x7 % pow2 24) * pow2 144;
(==) { FStar.Math.Lemmas.euclidean_division_definition (v x7) (pow2 24) }
v x7 * pow2 144;
}
val lemma_div248_x8: x8:uint64 ->
Lemma (pow2 32 * (v x8 % pow2 24) * pow2 168 + v x8 / pow2 24 * pow2 224 == v x8 * pow2 200)
let lemma_div248_x8 x8 =
calc (==) {
pow2 32 * (v x8 % pow2 24) * pow2 168 + v x8 / pow2 24 * pow2 224;
(==) { _ by (Tactics.norm [delta_only [`%pow2]; primops]; int_semiring ()) }
((v x8 / pow2 24) * pow2 24 + v x8 % pow2 24) * pow2 200;
(==) { FStar.Math.Lemmas.euclidean_division_definition (v x8) (pow2 24) }
v x8 * pow2 200;
}
val lemma_div248_x9: x9:uint64{v x9 < pow2 24} ->
Lemma (pow2 32 * (v x9 % pow2 24) * pow2 224 == v x9 * pow2 256)
let lemma_div248_x9 x9 =
calc (==) {
pow2 32 * (v x9 % pow2 24) * pow2 224;
(==) { Math.Lemmas.small_mod (v x9) (pow2 24) }
pow2 32 * v x9 * pow2 224;
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
v x9 * pow2 256;
}
val lemma_wide_as_nat_pow512: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 512)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
v x9 < pow2 24))
let lemma_wide_as_nat_pow512 x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert_norm (pow2 504 * pow2 8 = pow2 512);
FStar.Math.Lemmas.pow2_minus 512 504;
assert (v x9 < pow2 8);
assert_norm (pow2 8 < pow2 24)
val lemma_div248: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 512)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
let z0 = v x4 / pow2 24 + pow2 32 * (v x5 % pow2 24) in
let z1 = v x5 / pow2 24 + pow2 32 * (v x6 % pow2 24) in
let z2 = v x6 / pow2 24 + pow2 32 * (v x7 % pow2 24) in
let z3 = v x7 / pow2 24 + pow2 32 * (v x8 % pow2 24) in
let z4 = v x8 / pow2 24 + pow2 32 * (v x9 % pow2 24) in
wide_as_nat5 x / pow2 248 == z0 + z1 * pow2 56 + z2 * pow2 112 + z3 * pow2 168 + z4 * pow2 224))
#push-options "--z3rlimit 50"
let lemma_div248 x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
lemma_wide_as_nat_pow512 x;
assert (v x9 < pow2 24);
calc (==) {
(let z0 = v x4 / pow2 24 + pow2 32 * (v x5 % pow2 24) in
let z1 = v x5 / pow2 24 + pow2 32 * (v x6 % pow2 24) in
let z2 = v x6 / pow2 24 + pow2 32 * (v x7 % pow2 24) in
let z3 = v x7 / pow2 24 + pow2 32 * (v x8 % pow2 24) in
let z4 = v x8 / pow2 24 + pow2 32 * (v x9 % pow2 24) in
z0 + z1 * pow2 56 + z2 * pow2 112 + z3 * pow2 168 + z4 * pow2 224);
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
v x4 / pow2 24 + pow2 32 * (v x5 % pow2 24) +
v x5 / pow2 24 * pow2 56 + pow2 32 * (v x6 % pow2 24) * pow2 56 +
v x6 / pow2 24 * pow2 112 + pow2 32 * (v x7 % pow2 24) * pow2 112 +
v x7 / pow2 24 * pow2 168 + pow2 32 * (v x8 % pow2 24) * pow2 168 +
v x8 / pow2 24 * pow2 224 + pow2 32 * (v x9 % pow2 24) * pow2 224;
(==) { lemma_div248_x5 x5; lemma_div248_x6 x6 }
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 +
pow2 32 * (v x7 % pow2 24) * pow2 112 +
v x7 / pow2 24 * pow2 168 + pow2 32 * (v x8 % pow2 24) * pow2 168 +
v x8 / pow2 24 * pow2 224 + pow2 32 * (v x9 % pow2 24) * pow2 224;
(==) { lemma_div248_x7 x7; lemma_div248_x8 x8 }
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 +
pow2 32 * (v x9 % pow2 24) * pow2 224;
(==) { lemma_div248_x9 x9 }
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256;
(==) { lemma_div248_aux x }
wide_as_nat5 x / pow2 248;
}
#pop-options
val lemma_add_modq5:
x:qelem5
-> y:qelem5
-> t:qelem5 ->
Lemma
(requires
qelem_fits5 x (1, 1, 1, 1, 1) /\
qelem_fits5 y (1, 1, 1, 1, 1) /\
qelem_fits5 t (1, 1, 1, 1, 1) /\
as_nat5 x < S.q /\ as_nat5 y < S.q /\
as_nat5 t == as_nat5 x + as_nat5 y)
(ensures
(let res = if as_nat5 t >= S.q then as_nat5 t - S.q else as_nat5 t in
res < S.q /\ res == (as_nat5 x + as_nat5 y) % S.q))
let lemma_add_modq5 x y t =
assert (as_nat5 t == as_nat5 x + as_nat5 y);
let res = if as_nat5 t >= S.q then as_nat5 t - S.q else as_nat5 t in
assert (res < S.q);
if as_nat5 t >= S.q then (
FStar.Math.Lemmas.sub_div_mod_1 (as_nat5 t) S.q;
assert (res % S.q == as_nat5 t % S.q))
else
assert (res % S.q == as_nat5 t % S.q);
FStar.Math.Lemmas.small_mod res S.q
val lemma_wide_as_nat_pow528: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 528)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
v x9 < pow2 40))
let lemma_wide_as_nat_pow528 x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert_norm (pow2 504 * pow2 24 = pow2 528);
FStar.Math.Lemmas.pow2_minus 528 504;
assert (v x9 < pow2 24);
assert_norm (pow2 24 < pow2 40)
#push-options "--z3cliopt smt.arith.nl=false"
val lemma_div264_aux: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 528)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
wide_as_nat5 x / pow2 264 ==
v x4 / pow2 40 + v x5 * pow2 16 + v x6 * pow2 72 + v x7 * pow2 128 + v x8 * pow2 184 + v x9 * pow2 240))
let lemma_div264_aux x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert_norm (pow2 264 == pow2 224 * pow2 40);
assert_norm (pow2 56 == pow2 16 * pow2 40);
assert_norm (pow2 112 == pow2 72 * pow2 40);
assert_norm (pow2 168 == pow2 128 * pow2 40);
assert_norm (pow2 224 == pow2 184 * pow2 40);
assert_norm (pow2 280 == pow2 240 * pow2 40);
assert_norm (0 < pow2 40);
calc (==) {
wide_as_nat5 x / pow2 264;
(==) { FStar.Math.Lemmas.division_multiplication_lemma (wide_as_nat5 x) (pow2 224) (pow2 40) }
(wide_as_nat5 x / pow2 224) / pow2 40;
(==) { lemma_div224 x }
(v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280) / pow2 40;
(==) { _ by (Tactics.mapply (`feq #int #int (fun x -> x / pow2 40)); int_semiring ()) }
(v x4 + (v x5 * pow2 16 + v x6 * pow2 72 + v x7 * pow2 128 + v x8 * pow2 184 + v x9 * pow2 240) * pow2 40) / pow2 40;
(==) { FStar.Math.Lemmas.lemma_div_plus (v x4) (v x5 * pow2 16 + v x6 * pow2 72 + v x7 * pow2 128 + v x8 * pow2 184 + v x9 * pow2 240) (pow2 40) }
v x4 / pow2 40 + v x5 * pow2 16 + v x6 * pow2 72 + v x7 * pow2 128 + v x8 * pow2 184 + v x9 * pow2 240;
}
val lemma_div264_x5: x5:uint64 ->
Lemma (pow2 16 * (v x5 % pow2 40) + v x5 / pow2 40 * pow2 56 == v x5 * pow2 16)
let lemma_div264_x5 x5 =
assert_norm (0 < pow2 24);
calc (==) {
pow2 16 * (v x5 % pow2 40) + v x5 / pow2 40 * pow2 56;
(==) { _ by (Tactics.norm [delta_only [`%pow2]; primops]; int_semiring ()) }
((v x5 / pow2 40) * pow2 40 + v x5 % pow2 40) * pow2 16;
(==) { FStar.Math.Lemmas.euclidean_division_definition (v x5) (pow2 40) }
v x5 * pow2 16;
}
val lemma_div264_x6: x6:uint64 ->
Lemma (pow2 16 * (v x6 % pow2 40) * pow2 56 + v x6 / pow2 40 * pow2 112 == v x6 * pow2 72)
let lemma_div264_x6 x6 =
calc (==) {
pow2 16 * (v x6 % pow2 40) * pow2 56 + v x6 / pow2 40 * pow2 112;
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
((v x6 / pow2 40) * pow2 40 + v x6 % pow2 40) * pow2 72;
(==) { Math.Lemmas.euclidean_division_definition (v x6) (pow2 40) }
v x6 * pow2 72;
}
val lemma_div264_x7: x7:uint64 ->
Lemma (pow2 16 * (v x7 % pow2 40) * pow2 112 + v x7 / pow2 40 * pow2 168 == v x7 * pow2 128)
let lemma_div264_x7 x7 =
calc (==) {
pow2 16 * (v x7 % pow2 40) * pow2 112 + v x7 / pow2 40 * pow2 168;
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
((v x7 / pow2 40) * pow2 40 + v x7 % pow2 40) * pow2 128;
(==) { Math.Lemmas.euclidean_division_definition (v x7) (pow2 40) }
v x7 * pow2 128;
}
val lemma_div264_x8: x8:uint64 ->
Lemma (pow2 16 * (v x8 % pow2 40) * pow2 168 + v x8 / pow2 40 * pow2 224 == v x8 * pow2 184)
let lemma_div264_x8 x8 =
calc (==) {
pow2 16 * (v x8 % pow2 40) * pow2 168 + v x8 / pow2 40 * pow2 224;
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
((v x8 / pow2 40) * pow2 40 + v x8 % pow2 40) * pow2 184;
(==) { Math.Lemmas.euclidean_division_definition (v x8) (pow2 40) }
v x8 * pow2 184;
}
val lemma_div264_x9: x9:uint64{v x9 < pow2 40} ->
Lemma (pow2 16 * (v x9 % pow2 40) * pow2 224 == v x9 * pow2 240)
let lemma_div264_x9 x9 =
calc (==) {
pow2 16 * (v x9 % pow2 40) * pow2 224;
(==) { Math.Lemmas.small_mod (v x9) (pow2 40) }
pow2 16 * v x9 * pow2 224;
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
v x9 * pow2 240;
}
val lemma_div264: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 528)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
let z0 = v x4 / pow2 40 + pow2 16 * (v x5 % pow2 40) in
let z1 = v x5 / pow2 40 + pow2 16 * (v x6 % pow2 40) in
let z2 = v x6 / pow2 40 + pow2 16 * (v x7 % pow2 40) in
let z3 = v x7 / pow2 40 + pow2 16 * (v x8 % pow2 40) in
let z4 = v x8 / pow2 40 + pow2 16 * (v x9 % pow2 40) in
wide_as_nat5 x / pow2 264 == z0 + z1 * pow2 56 + z2 * pow2 112 + z3 * pow2 168 + z4 * pow2 224))
#push-options "--z3rlimit 50"
let lemma_div264 x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
lemma_wide_as_nat_pow528 x;
assert (v x9 < pow2 40);
calc (==) {
(let z0 = v x4 / pow2 40 + pow2 16 * (v x5 % pow2 40) in
let z1 = v x5 / pow2 40 + pow2 16 * (v x6 % pow2 40) in
let z2 = v x6 / pow2 40 + pow2 16 * (v x7 % pow2 40) in
let z3 = v x7 / pow2 40 + pow2 16 * (v x8 % pow2 40) in
let z4 = v x8 / pow2 40 + pow2 16 * (v x9 % pow2 40) in
z0 + z1 * pow2 56 + z2 * pow2 112 + z3 * pow2 168 + z4 * pow2 224);
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
v x4 / pow2 40 + pow2 16 * (v x5 % pow2 40) +
v x5 / pow2 40 * pow2 56 + pow2 16 * (v x6 % pow2 40) * pow2 56 +
v x6 / pow2 40 * pow2 112 + pow2 16 * (v x7 % pow2 40) * pow2 112 +
v x7 / pow2 40 * pow2 168 + pow2 16 * (v x8 % pow2 40) * pow2 168 +
v x8 / pow2 40 * pow2 224 + pow2 16 * (v x9 % pow2 40) * pow2 224;
(==) { lemma_div264_x5 x5; lemma_div264_x6 x6 }
v x4 / pow2 40 + v x5 * pow2 16 + v x6 * pow2 72 +
pow2 16 * (v x7 % pow2 40) * pow2 112 +
v x7 / pow2 40 * pow2 168 + pow2 16 * (v x8 % pow2 40) * pow2 168 +
v x8 / pow2 40 * pow2 224 + pow2 16 * (v x9 % pow2 40) * pow2 224;
(==) { lemma_div264_x7 x7; lemma_div264_x8 x8 }
v x4 / pow2 40 + v x5 * pow2 16 + v x6 * pow2 72 + v x7 * pow2 128 + v x8 * pow2 184 +
pow2 16 * (v x9 % pow2 40) * pow2 224;
(==) { lemma_div264_x9 x9 }
v x4 / pow2 40 + v x5 * pow2 16 + v x6 * pow2 72 + v x7 * pow2 128 + v x8 * pow2 184 + v x9 * pow2 240;
(==) { lemma_div264_aux x }
wide_as_nat5 x / pow2 264;
}
#pop-options
#pop-options // "--z3cliopt smt.arith.nl=false"
val lemma_mod_264_aux: t:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 t (1, 1, 1, 1, 1, 1, 1, 1, 1, 1))
(ensures
(let (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) = t in
(wide_as_nat5 t) % pow2 264 ==
(v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + v t4 * pow2 224) % pow2 264))
#push-options "--z3rlimit 150"
let lemma_mod_264_aux t =
let (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) = t in
let res = (t0, t1, t2, t3, t4 &. u64 0xffffffffff) in
assert_norm (pow2 16 * pow2 264 == pow2 280);
assert_norm (pow2 72 * pow2 264 == pow2 336);
assert_norm (pow2 128 * pow2 264 == pow2 392);
assert_norm (pow2 184 * pow2 264 == pow2 448);
assert_norm (pow2 240 * pow2 264 == pow2 504);
calc (==) {
(wide_as_nat5 t) % pow2 264;
(==) { }
(v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + v t4 * pow2 224 +
(v t5 * pow2 16 + v t6 * pow2 72 + v t7 * pow2 128 + v t8 * pow2 184 + v t9 * pow2 240) * pow2 264) % pow2 264;
(==) { FStar.Math.Lemmas.lemma_mod_add_distr (v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + v t4 * pow2 224)
((v t5 * pow2 16 + v t6 * pow2 72 + v t7 * pow2 128 + v t8 * pow2 184 + v t9 * pow2 240) * pow2 264) (pow2 264)}
((v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + v t4 * pow2 224) +
((v t5 * pow2 16 + v t6 * pow2 72 + v t7 * pow2 128 + v t8 * pow2 184 + v t9 * pow2 240) * pow2 264) % pow2 264) % pow2 264;
(==) { FStar.Math.Lemmas.cancel_mul_mod (v t5 * pow2 16 + v t6 * pow2 72 + v t7 * pow2 128 + v t8 * pow2 184 + v t9 * pow2 240) (pow2 264) }
(v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + v t4 * pow2 224) % pow2 264;
}
#pop-options
val lemma_as_nat_pow264: x:qelem5 ->
Lemma
(requires
(let (x0, x1, x2, x3, x4) = x in
qelem_fits5 x (1, 1, 1, 1, 1) /\
v x4 < pow2 40))
(ensures as_nat5 x < pow2 264)
let lemma_as_nat_pow264 x =
let (x0, x1, x2, x3, x4) = x in
assert_norm (pow2 40 * pow2 224 = pow2 264)
val lemma_mod_264: t:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 t (1, 1, 1, 1, 1, 1, 1, 1, 1, 1))
(ensures
(let (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) = t in
let res = (t0, t1, t2, t3, t4 &. u64 0xffffffffff) in
qelem_fits5 res (1, 1, 1, 1, 1) /\
as_nat5 res == (wide_as_nat5 t) % pow2 264))
let lemma_mod_264 t =
let (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) = t in
let t4' = t4 &. u64 0xffffffffff in
let res = (t0, t1, t2, t3, t4') in
assert_norm (pow2 40 < pow2 64);
assert_norm (pow2 40 - 1 == 0xffffffffff);
mod_mask_lemma t4 40ul;
assert (v (mod_mask #U64 #SEC 40ul) == 0xffffffffff);
assert (v (t4 &. u64 0xffffffffff) == v t4 % pow2 40);
calc (==) {
(wide_as_nat5 t) % pow2 264;
(==) { lemma_mod_264_aux t }
(v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + v t4 * pow2 224) % pow2 264;
(==) { FStar.Math.Lemmas.lemma_mod_add_distr (v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168) (v t4 * pow2 224) (pow2 264) }
(v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + (v t4 * pow2 224) % pow2 264) % pow2 264;
(==) { FStar.Math.Lemmas.pow2_multiplication_modulo_lemma_2 (v t4) 264 224 }
(v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + (v t4 % pow2 40) * pow2 224) % pow2 264;
(==) { lemma_as_nat_pow264 res; FStar.Math.Lemmas.modulo_lemma (as_nat5 res) (pow2 264) }
v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + (v t4 % pow2 40) * pow2 224;
}
val lemma_as_nat_pow264_x4: x:qelem5 ->
Lemma
(requires
qelem_fits5 x (1, 1, 1, 1, 1) /\
as_nat5 x < pow2 264)
(ensures
(let (x0, x1, x2, x3, x4) = x in
v x4 < pow2 40))
let lemma_as_nat_pow264_x4 x =
let (x0, x1, x2, x3, x4) = x in
assert_norm (pow2 40 * pow2 224 = pow2 264)
val lemma_sub_mod_264_aux:
x0:nat -> x1:nat -> x2:nat -> x3:nat -> x4:nat
-> y0:nat -> y1:nat -> y2:nat -> y3:nat -> y4:nat
-> c1:nat -> c2:nat -> c3:nat -> c4:nat -> c5:nat ->
Lemma (
x0 - y0 + c1 * pow56 +
(x1 - y1 - c1 + c2 * pow56) * pow56 +
(x2 - y2 - c2 + c3 * pow56) * pow112 +
(x3 - y3 - c3 + c4 * pow56) * pow168 +
(x4 - y4 - c4 + pow2 40 * c5) * pow224 ==
(x0 + x1 * pow2 56 + x2 * pow2 112 + x3 * pow2 168 + x4 * pow2 224) -
(y0 + y1 * pow2 56 + y2 * pow2 112 + y3 * pow2 168 + y4 * pow2 224) + c5 * pow2 264)
#push-options "--z3rlimit 50"
let lemma_sub_mod_264_aux x0 x1 x2 x3 x4 y0 y1 y2 y3 y4 b0 b1 b2 b3 b4 =
assert_norm (pow2 56 * pow2 56 = pow2 112);
assert_norm (pow2 56 * pow2 112 = pow2 168);
assert_norm (pow2 56 * pow2 168 = pow2 224);
assert_norm (pow2 40 * pow2 224 = pow2 264)
#pop-options
val lemma_sub_mod_264:
x:qelem5
-> y:qelem5
-> t:qelem5
-> c5:uint64 ->
Lemma
(requires
qelem_fits5 x (1, 1, 1, 1, 1) /\
qelem_fits5 y (1, 1, 1, 1, 1) /\
qelem_fits5 t (1, 1, 1, 1, 1) /\
as_nat5 x < pow2 264 /\
as_nat5 y < pow2 264 /\
as_nat5 t == as_nat5 x - as_nat5 y + v c5 * pow2 264 /\ v c5 <= 1 /\
(if v c5 = 0 then as_nat5 x >= as_nat5 y else as_nat5 x < as_nat5 y))
(ensures
(if as_nat5 x >= as_nat5 y then
as_nat5 t == as_nat5 x - as_nat5 y
else as_nat5 t == as_nat5 x - as_nat5 y + pow2 264))
#push-options "--z3rlimit 50"
let lemma_sub_mod_264 x y t c5 =
assert (if v c5 = 0 then as_nat5 x >= as_nat5 y else as_nat5 x < as_nat5 y);
assert (as_nat5 t == as_nat5 x - as_nat5 y + v c5 * pow2 264);
if as_nat5 x >= as_nat5 y then
assert (v c5 == 0 /\ as_nat5 t == as_nat5 x - as_nat5 y)
else
assert (v c5 == 1 /\ as_nat5 t == as_nat5 x - as_nat5 y + pow2 264)
#pop-options
let lemma_mul_qelem5 (x0 x1 x2 x3 x4 y0 y1 y2 y3 y4:nat) : Lemma
((x0 + x1 * pow2 56 + x2 * pow2 112 + x3 * pow2 168 + x4 * pow2 224) *
(y0 + y1 * pow2 56 + y2 * pow2 112 + y3 * pow2 168 + y4 * pow2 224) ==
x0 * y0 +
(x0 * y1 + x1 * y0) * pow56 +
(x0 * y2 + x1 * y1 + x2 * y0) * pow112 +
(x0 * y3 + x1 * y2 + x2 * y1 + x3 * y0) * pow168 +
(x0 * y4 + x1 * y3 + x2 * y2 + x3 * y1 + x4 * y0) * pow224 +
(x1 * y4 + x2 * y3 + x3 * y2 + x4 * y1) * pow280 +
(x2 * y4 + x3 * y3 + x4 * y2) * pow336 +
(x3 * y4 + x4 * y3) * pow392 +
(x4 * y4) * pow448)
=
assert ((x0 + x1 * pow2 56 + x2 * pow2 112 + x3 * pow2 168 + x4 * pow2 224) *
(y0 + y1 * pow2 56 + y2 * pow2 112 + y3 * pow2 168 + y4 * pow2 224) ==
x0 * y0 +
(x0 * y1 + x1 * y0) * pow56 +
(x0 * y2 + x1 * y1 + x2 * y0) * pow112 +
(x0 * y3 + x1 * y2 + x2 * y1 + x3 * y0) * pow168 +
(x0 * y4 + x1 * y3 + x2 * y2 + x3 * y1 + x4 * y0) * pow224 +
(x1 * y4 + x2 * y3 + x3 * y2 + x4 * y1) * pow280 +
(x2 * y4 + x3 * y3 + x4 * y2) * pow336 +
(x3 * y4 + x4 * y3) * pow392 +
(x4 * y4) * pow448)
by (Tactics.norm [zeta; iota; delta; primops]; int_semiring ())
val lemma_mul_5_low_264:
x1:nat -> x2:nat -> x3:nat -> x4:nat -> x5:nat ->
y1:nat -> y2:nat -> y3:nat -> y4:nat -> y5:nat ->
Lemma (
(x1 * y1) >= 0
/\ (x2 * y1 + x1 * y2 + ((x1 * y1) / pow2 56)) >= 0
/\ (x3 * y1 + x2 * y2 + x1 * y3 + ((x2 * y1 + x1 * y2 + ((x1 * y1) / pow2 56)) / pow2 56)) >= 0
/\ (x4 * y1 + x3 * y2 + x2 * y3 + x1 * y4 + ((x3 * y1 + x2 * y2 + x1 * y3 + ((x2 * y1 + x1 * y2 + ((x1 * y1) / pow2 56)) / pow2 56)) / pow2 56)) >= 0
/\ (
let a0 = (x1 * y1) % pow2 56 in
let a1 = ((x2 * y1 + x1 * y2 + ((x1 * y1) / pow2 56)) % pow2 56) in
let a2 = ((x3 * y1 + x2 * y2 + x1 * y3 + ((x2 * y1 + x1 * y2 + ((x1 * y1) / pow2 56)) / pow2 56)) % pow2 56) in
let a3 = ((x4 * y1 + x3 * y2 + x2 * y3 + x1 * y4 + ((x3 * y1 + x2 * y2 + x1 * y3 + ((x2 * y1 + x1 * y2 + ((x1 * y1) / pow2 56)) / pow2 56)) / pow2 56)) % pow2 56) in
let a4 = (x5 * y1 + x4 * y2 + x3 * y3 + x2 * y4 + x1 * y5 + ((x4 * y1 + x3 * y2 + x2 * y3 + x1 * y4 + ((x3 * y1 + x2 * y2 + x1 * y3 + ((x2 * y1 + x1 * y2 + ((x1 * y1) / pow2 56)) / pow2 56)) / pow2 56)) / pow2 56)) in
((x1 + pow2 56 * x2 + pow2 112 * x3 + pow2 168 * x4 + pow2 224 * x5)
* (y1 + pow2 56 * y2 + pow2 112 * y3 + pow2 168 * y4 + pow2 224 * y5)) % pow2 264
== a0 + pow2 56 * a1 + pow2 112 * a2 + pow2 168 * a3 + pow2 224 * (a4 % pow2 40)))
private let lemma_mul_nat_is_nat (a:nat) (b:nat) : Lemma (a*b >= 0) = ()
private let lemma_div_nat_is_nat (a:nat) (b:pos) : Lemma (a/b >= 0) = ()
private
val lemma_mul_5''':
x1:nat -> x2:nat -> x3:nat -> x4:nat -> x5:nat ->
y1:nat -> y2:nat -> y3:nat -> y4:nat -> y5:nat ->
Lemma (((x1 + pow2 56 * x2 + pow2 112 * x3 + pow2 168 * x4 + pow2 224 * x5)
* (y1 + pow2 56 * y2 + pow2 112 * y3 + pow2 168 * y4 + pow2 224 * y5)) % pow2 264
==
(x1 * y1
+ pow2 56 * (x2 * y1 + x1 * y2)
+ pow2 112 * (x3 * y1 + x2 * y2 + x1 * y3)
+ pow2 168 * (x4 * y1 + x3 * y2 + x2 * y3 + x1 * y4)
+ pow2 224 * (x5 * y1 + x4 * y2 + x3 * y3 + x2 * y4 + x1 * y5)) % pow2 264)
let lemma_mul_5''' x1 x2 x3 x4 x5 y1 y2 y3 y4 y5 =
calc (==) {
((x1 + pow2 56 * x2 + pow2 112 * x3 + pow2 168 * x4 + pow2 224 * x5)
* (y1 + pow2 56 * y2 + pow2 112 * y3 + pow2 168 * y4 + pow2 224 * y5)) % pow2 264;
(==) { _ by (Tactics.mapply (`feq #int #int (fun x -> x % pow2 264));
Tactics.norm [zeta; iota; delta; primops];
int_semiring ()) }
(x1 * y1
+ pow2 56 * (x2 * y1 + x1 * y2)
+ pow2 112 * (x3 * y1 + x2 * y2 + x1 * y3)
+ pow2 168 * (x4 * y1 + x3 * y2 + x2 * y3 + x1 * y4)
+ pow2 224 * (x5 * y1 + x4 * y2 + x3 * y3 + x2 * y4 + x1 * y5)
+ (pow2 16 * x2 * y5 +
pow2 16 * x3 * y4 + pow2 72 * x3 * y5 +
pow2 16 * x4 * y3 + pow2 72 * x4 * y4 + pow2 128 * x4 * y5 +
pow2 16 * x5 * y2 + pow2 72 * x5 * y3 + pow2 128 * x5 * y4 + pow2 184 * x5 * y5) * pow2 264) % pow2 264;
(==) { _ by (Tactics.mapply (`eq_eq2); Tactics.mapply (`Math.Lemmas.lemma_mod_plus)) }
(x1 * y1
+ pow2 56 * (x2 * y1 + x1 * y2)
+ pow2 112 * (x3 * y1 + x2 * y2 + x1 * y3)
+ pow2 168 * (x4 * y1 + x3 * y2 + x2 * y3 + x1 * y4)
+ pow2 224 * (x5 * y1 + x4 * y2 + x3 * y3 + x2 * y4 + x1 * y5)) % pow2 264;
}
private val lemma_mod_264'':
a0:nat -> a1:nat-> a2:nat -> a3:nat -> a4:nat ->
Lemma
(requires a0 < pow56 /\ a1 < pow56 /\ a2 < pow56 /\ a3 < pow56)
(ensures a0 + pow2 56 * a1 + pow2 112 * a2 + pow2 168 * a3 + pow2 224 * (a4 % pow2 40) < pow2 264)
let lemma_mod_264'' a0 a1 a2 a3 a4 =
assert_norm(pow2 40 = 0x10000000000);
assert_norm(pow2 56 = 0x100000000000000);
assert_norm(pow2 112 = 0x10000000000000000000000000000);
assert_norm(pow2 168 = 0x1000000000000000000000000000000000000000000);
assert_norm(pow2 224 = 0x100000000000000000000000000000000000000000000000000000000);
assert_norm(pow2 264 = 0x1000000000000000000000000000000000000000000000000000000000000000000)
private val lemma_mod_264':
a0:nat -> a1:nat-> a2:nat -> a3:nat -> a4:nat ->
Lemma
(requires a0 < pow56 /\ a1 < pow56 /\ a2 < pow56 /\ a3 < pow56)
(ensures (a0
+ pow2 56 * a1
+ pow2 112 * a2
+ pow2 168 * a3
+ pow2 224 * a4) % pow2 264 =
a0
+ pow2 56 * a1
+ pow2 112 * a2
+ pow2 168 * a3
+ pow2 224 * (a4 % pow2 40) )
let lemma_mod_264' a0 a1 a2 a3 a4 =
assert_norm(pow2 56 = 0x100000000000000);
assert_norm(pow2 112 = 0x10000000000000000000000000000);
assert_norm(pow2 168 = 0x1000000000000000000000000000000000000000000);
assert_norm(pow2 224 = 0x100000000000000000000000000000000000000000000000000000000);
Math.Lemmas.lemma_mod_plus_distr_l (pow2 224 * a4) (a0 + pow2 56 * a1 + pow2 112 * a2 + pow2 168 * a3) (pow2 264);
Math.Lemmas.pow2_multiplication_modulo_lemma_2 a4 264 224;
lemma_mod_264'' a0 a1 a2 a3 a4;
Math.Lemmas.modulo_lemma (a0 + pow2 56 * a1 + pow2 112 * a2 + pow2 168 * a3 + pow2 224 * (a4 % pow2 40)) (pow2 264)
private let lemma_aux_0 (a:nat) (b:nat) (n:nat) : Lemma
(pow2 n * a + pow2 (n+56) * b = pow2 n * (a % pow2 56) + pow2 (n+56) * (b + a / pow2 56))
= Math.Lemmas.lemma_div_mod a (pow2 56);
Math.Lemmas.pow2_plus n 56;
assert(a = pow2 56 * (a / pow2 56) + (a % pow2 56));
Math.Lemmas.distributivity_add_right (pow2 n) (pow2 56 * (a / pow2 56)) (a % pow2 56);
Math.Lemmas.paren_mul_right (pow2 n) (pow2 56) (a / pow2 56);
Math.Lemmas.distributivity_add_right (pow2 (n+56)) b (a / pow2 56)
private
val lemma_mod_264_small:
a0:nat -> a1:nat -> a2:nat -> a3:nat -> a4:nat ->
Lemma ( (a0 + pow2 56 * a1 + pow2 112 * a2 + pow2 168 * a3 + pow2 224 * a4)
= (a0 % pow2 56)
+ pow2 56 * ((a1 + (a0 / pow2 56)) % pow2 56)
+ pow2 112 * ((a2 + ((a1 + (a0 / pow2 56)) / pow2 56)) % pow2 56)
+ pow2 168 * ((a3 + ((a2 + ((a1 + (a0 / pow2 56)) / pow2 56)) / pow2 56)) % pow2 56)
+ pow2 224 * (a4 + ((a3 + ((a2 + ((a1 + (a0 / pow2 56)) / pow2 56)) / pow2 56)) / pow2 56)))
(* These silly lemmas needed to guide the proof below... *)
private let aux_nat_over_pos (p : nat) (q : pos) : Lemma (p / q >= 0) = ()
private let aux_nat_plus_nat (p : nat) (q : nat) : Lemma (p + q >= 0) = ()
let lemma_mod_264_small a0 a1 a2 a3 a4 =
Math.Lemmas.lemma_div_mod a0 (pow2 56);
Math.Lemmas.distributivity_add_right (pow2 56) a1 (a0 / pow2 56);
(**) aux_nat_over_pos a0 (pow2 56);
(**) aux_nat_plus_nat a1 (a0 / pow2 56);
let a1':nat = (a1 + (a0 / pow2 56)) in
(**) aux_nat_over_pos a1' (pow2 56);
(**) aux_nat_plus_nat a2 (a1' / pow2 56);
let a2':nat = (a2 + (a1' / pow2 56)) in
(**) aux_nat_over_pos a2' (pow2 56);
(**) aux_nat_plus_nat a3 (a2' / pow2 56);
let a3':nat = (a3 + (a2' / pow2 56)) in
lemma_aux_0 a1' a2 56;
lemma_aux_0 a2' a3 112;
lemma_aux_0 a3' a4 168
private
val lemma_mod_264_:
a0:nat -> a1:nat -> a2:nat -> a3:nat -> a4:nat ->
Lemma ((a0 + pow2 56 * a1 + pow2 112 * a2 + pow2 168 * a3 + pow2 224 * a4) % pow2 264 =
(a0 % pow2 56)
+ pow2 56 * ((a1 + (a0 / pow2 56)) % pow2 56)
+ pow2 112 * ((a2 + ((a1 + (a0 / pow2 56)) / pow2 56)) % pow2 56)
+ pow2 168 * ((a3 + ((a2 + ((a1 + (a0 / pow2 56)) / pow2 56)) / pow2 56)) % pow2 56)
+ pow2 224 * ((a4 + ((a3 + ((a2 + ((a1 + (a0 / pow2 56)) / pow2 56)) / pow2 56)) / pow2 56)) % pow2 40))
let lemma_mod_264_ a0 a1 a2 a3 a4 =
lemma_mod_264_small a0 a1 a2 a3 a4;
let x0 = a0 % pow2 56 in
assert (x0 < pow56);
let x1 = ((a1 + (a0 / pow2 56)) % pow2 56) in
assert (x1 < pow56);
let x2 = ((a2 + ((a1 + (a0 / pow2 56)) / pow2 56)) % pow2 56) in
assert (x2 < pow56);
let x3 = ((a3 + ((a2 + ((a1 + (a0 / pow2 56)) / pow2 56)) / pow2 56)) % pow2 56) in
assert (x3 < pow56);
lemma_mod_264' x0 x1 x2 x3 (a4 + ((a3 + ((a2 + ((a1 + (a0 / pow2 56)) / pow2 56)) / pow2 56)) / pow2 56))
#push-options "--z3rlimit 50"
let lemma_mul_5_low_264 x1 x2 x3 x4 x5 y1 y2 y3 y4 y5 =
lemma_div_nat_is_nat (x1 * y1) (pow2 56);
lemma_div_nat_is_nat (x2 * y1 + x1 * y2 + ((x1 * y1) / pow2 56)) (pow2 56);
lemma_div_nat_is_nat (x3 * y1 + x2 * y2 + x1 * y3 + ((x2 * y1 + x1 * y2 + ((x1 * y1) / pow2 56)) / pow2 56)) (pow2 56);
lemma_div_nat_is_nat (x4 * y1 + x3 * y2 + x2 * y3 + x1 * y4 + ((x3 * y1 + x2 * y2 + x1 * y3 + ((x2 * y1 + x1 * y2 + ((x1 * y1) / pow2 56)) / pow2 56)) / pow2 56)) (pow2 56);
lemma_mul_5''' x1 x2 x3 x4 x5 y1 y2 y3 y4 y5;
lemma_mod_264_ (x1 * y1) (x2 * y1 + x1 * y2) (x3 * y1 + x2 * y2 + x1 * y3) (x4 * y1 + x3 * y2 + x2 * y3 + x1 * y4) (x5 * y1 + x4 * y2 + x3 * y3 + x2 * y4 + x1 * y5)
#pop-options
private
val lemma_optimized_barrett_reduce:
a:nat{a < pow2 512} ->
Lemma (a - (((a / pow2 248) * (pow2 512 / S.q)) / pow2 264) * S.q < 2 * S.q
/\ a - (((a / pow2 248) * (pow2 512 / S.q)) / pow2 264) * S.q >= 0)
#push-options "--z3rlimit 50"
let lemma_optimized_barrett_reduce a =
assert_norm (pow2 248 = 0x100000000000000000000000000000000000000000000000000000000000000);
assert_norm (pow2 264 = 0x1000000000000000000000000000000000000000000000000000000000000000000);
assert_norm (S.q == 0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed);
assert_norm (0x100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 == pow2 512)
#pop-options
private
val lemma_optimized_barrett_reduce2:
a:nat{a < pow2 512} ->
Lemma (a - ((a * (pow2 512 / S.q)) / pow2 512) * S.q < pow2 264 /\
a - ((a * (pow2 512 / S.q)) / pow2 512) * S.q >= 0)
#push-options "--z3rlimit 50"
let lemma_optimized_barrett_reduce2 a =
assert_norm (pow2 248 = 0x100000000000000000000000000000000000000000000000000000000000000);
assert_norm (pow2 264 = 0x1000000000000000000000000000000000000000000000000000000000000000000);
assert_norm (S.q == 0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed);
assert_norm (0x100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 == pow2 512)
#pop-options
#push-options "--fuel 0 --z3cliopt smt.arith.nl=true --smtencoding.elim_box true --smtencoding.l_arith_repr native --smtencoding.nl_arith_repr native --z3rlimit 30" | {
"checked_file": "/",
"dependencies": [
"Spec.Ed25519.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.BignumQ.Definitions.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Tactics.CanonCommSemiring.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.BignumQ.Lemmas.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.CanonCommSemiring",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.BignumQ.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.Ed25519",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.CanonCommSemiring",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.BignumQ",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.BignumQ",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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": 1,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "native",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=true"
],
"z3refresh": false,
"z3rlimit": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: Prims.nat -> y: Prims.nat -> c: Prims.pos
-> FStar.Pervasives.Lemma (requires x >= y /\ x - y < c) (ensures x / c - y / c <= 1) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.nat",
"Prims.pos",
"Prims.op_GreaterThan",
"Prims.op_Subtraction",
"Prims.op_Division",
"FStar.Math.Lemmas.cancel_mul_div",
"Prims.unit",
"FStar.Math.Lemmas.swap_mul",
"FStar.Math.Lemmas.small_div",
"FStar.Math.Lemmas.lemma_div_mod",
"FStar.Math.Lemmas.distributivity_sub_right",
"Prims.bool",
"Prims.l_and",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"Prims.op_LessThan",
"Prims.squash",
"Prims.op_LessThanOrEqual",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let lemma_0 (x y: nat) (c: pos)
: Lemma (requires (x >= y /\ x - y < c)) (ensures (x / c - y / c <= 1)) =
| if x / c - y / c > 1
then
(Math.Lemmas.lemma_div_mod x c;
Math.Lemmas.lemma_div_mod y c;
Math.Lemmas.distributivity_sub_right c (x / c) (y / c);
Math.Lemmas.lemma_div_mod (x - y) c;
Math.Lemmas.small_div (x - y) c;
Math.Lemmas.swap_mul c (x / c - y / c);
Math.Lemmas.cancel_mul_div (x / c - y / c) c) | false |
LowParse.Low.ConstInt32.fst | LowParse.Low.ConstInt32.decompose_int32le_1 | val decompose_int32le_1 (v: nat{0 <= v /\ v < 4294967296}) : Tot (b1: nat{0 <= b1 /\ b1 < 256}) | val decompose_int32le_1 (v: nat{0 <= v /\ v < 4294967296}) : Tot (b1: nat{0 <= b1 /\ b1 < 256}) | let decompose_int32le_1
(v: nat { 0 <= v /\ v < 4294967296 } )
: Tot (b1: nat { 0 <= b1 /\ b1 < 256 } )
= v / 256 % 256 | {
"file_name": "src/lowparse/LowParse.Low.ConstInt32.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 15,
"end_line": 71,
"start_col": 0,
"start_line": 68
} | module LowParse.Low.ConstInt32
(* LowParse implementation module for 32 bits contants *)
include FStar.Endianness
include LowParse.Spec.ConstInt32
include LowParse.Spec.Int32le
include LowParse.Low.Combinators
include LowParse.Low.Int32le
module U32 = FStar.UInt32
module U8 = FStar.UInt8
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module B = LowStar.Buffer
module Cast = FStar.Int.Cast
module U64 = FStar.UInt64
let valid_constint32le
(v: nat { 0 <= v /\ v < 4294967296 } )
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma (valid (parse_constint32le v) h input pos
<==>
(valid parse_int32le h input pos /\
U32.v (contents parse_int32le h input pos) == v))
= valid_facts (parse_constint32le v) h input pos;
valid_facts parse_int32le h input pos;
parse_constint32le_unfold v (bytes_of_slice_from h input pos)
inline_for_extraction
let validate_constint32le_slow
(v: U32.t { 0 <= U32.v v /\ U32.v v < 4294967296 } )
: Tot (validator (parse_constint32le (U32.v v)))
= fun #rrel #rel (input: slice rrel rel) pos ->
let h = HST.get() in
let _ =
valid_constint32le (U32.v v) h input (uint64_to_uint32 pos);
valid_equiv parse_int32le h input (uint64_to_uint32 pos)
in
if U64.lt (Cast.uint32_to_uint64 input.len `U64.sub` pos) 4uL
then
validator_error_not_enough_data
else
let v' = read_int32le input (uint64_to_uint32 pos) in
if U32.eq v v' then
pos `U64.add` 4uL
else
validator_error_generic
inline_for_extraction
let read_constint32le
(v: U32.t { 0 <= U32.v v /\ U32.v v < 4294967296 } )
: Tot (leaf_reader (parse_constint32le (U32.v v)))
= fun #rrel #rel input pos ->
v
inline_for_extraction
let decompose_int32le_0
(v: nat { 0 <= v /\ v < 4294967296 } )
: Tot (b0: nat { 0 <= b0 /\ b0 < 256 } )
= v % 256 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Int32le.fst.checked",
"LowParse.Spec.ConstInt32.fst.checked",
"LowParse.Low.Int32le.fst.checked",
"LowParse.Low.Combinators.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Endianness.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.ConstInt32.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "LowParse.Low.Int32le",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Int32le",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.ConstInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Endianness",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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: Prims.nat{0 <= v /\ v < 4294967296} -> b1: Prims.nat{0 <= b1 /\ b1 < 256} | Prims.Tot | [
"total"
] | [] | [
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"Prims.op_Modulus",
"Prims.op_Division"
] | [] | false | false | false | false | false | let decompose_int32le_1 (v: nat{0 <= v /\ v < 4294967296}) : Tot (b1: nat{0 <= b1 /\ b1 < 256}) =
| v / 256 % 256 | false |
LowParse.Low.ConstInt32.fst | LowParse.Low.ConstInt32.decompose_int32le_0 | val decompose_int32le_0 (v: nat{0 <= v /\ v < 4294967296}) : Tot (b0: nat{0 <= b0 /\ b0 < 256}) | val decompose_int32le_0 (v: nat{0 <= v /\ v < 4294967296}) : Tot (b0: nat{0 <= b0 /\ b0 < 256}) | let decompose_int32le_0
(v: nat { 0 <= v /\ v < 4294967296 } )
: Tot (b0: nat { 0 <= b0 /\ b0 < 256 } )
= v % 256 | {
"file_name": "src/lowparse/LowParse.Low.ConstInt32.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 9,
"end_line": 65,
"start_col": 0,
"start_line": 62
} | module LowParse.Low.ConstInt32
(* LowParse implementation module for 32 bits contants *)
include FStar.Endianness
include LowParse.Spec.ConstInt32
include LowParse.Spec.Int32le
include LowParse.Low.Combinators
include LowParse.Low.Int32le
module U32 = FStar.UInt32
module U8 = FStar.UInt8
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module B = LowStar.Buffer
module Cast = FStar.Int.Cast
module U64 = FStar.UInt64
let valid_constint32le
(v: nat { 0 <= v /\ v < 4294967296 } )
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma (valid (parse_constint32le v) h input pos
<==>
(valid parse_int32le h input pos /\
U32.v (contents parse_int32le h input pos) == v))
= valid_facts (parse_constint32le v) h input pos;
valid_facts parse_int32le h input pos;
parse_constint32le_unfold v (bytes_of_slice_from h input pos)
inline_for_extraction
let validate_constint32le_slow
(v: U32.t { 0 <= U32.v v /\ U32.v v < 4294967296 } )
: Tot (validator (parse_constint32le (U32.v v)))
= fun #rrel #rel (input: slice rrel rel) pos ->
let h = HST.get() in
let _ =
valid_constint32le (U32.v v) h input (uint64_to_uint32 pos);
valid_equiv parse_int32le h input (uint64_to_uint32 pos)
in
if U64.lt (Cast.uint32_to_uint64 input.len `U64.sub` pos) 4uL
then
validator_error_not_enough_data
else
let v' = read_int32le input (uint64_to_uint32 pos) in
if U32.eq v v' then
pos `U64.add` 4uL
else
validator_error_generic
inline_for_extraction
let read_constint32le
(v: U32.t { 0 <= U32.v v /\ U32.v v < 4294967296 } )
: Tot (leaf_reader (parse_constint32le (U32.v v)))
= fun #rrel #rel input pos ->
v | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Int32le.fst.checked",
"LowParse.Spec.ConstInt32.fst.checked",
"LowParse.Low.Int32le.fst.checked",
"LowParse.Low.Combinators.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Endianness.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.ConstInt32.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "LowParse.Low.Int32le",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Int32le",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.ConstInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Endianness",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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: Prims.nat{0 <= v /\ v < 4294967296} -> b0: Prims.nat{0 <= b0 /\ b0 < 256} | Prims.Tot | [
"total"
] | [] | [
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"Prims.op_Modulus"
] | [] | false | false | false | false | false | let decompose_int32le_0 (v: nat{0 <= v /\ v < 4294967296}) : Tot (b0: nat{0 <= b0 /\ b0 < 256}) =
| v % 256 | false |
Monad.fst | Monad.g' | val g' : {| _: Monad.monad m |} -> x: m a -> Prims.unit | let g' #a #b #m {| monad m |} (x : m a) =
(laws #m).idL () (fun () -> x);
(laws #m).idR x;
assert (bind #m x (return #m) == bind #m (return #m ()) (fun () -> x)) | {
"file_name": "examples/typeclasses/Monad.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 72,
"end_line": 60,
"start_col": 0,
"start_line": 57
} | (*
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 Monad
open FStar.Tactics.Typeclasses
(* Fails... due to unification? check it out *)
// class monad (m:Type0 -> Type0) : Type = {
// return : #a:_ -> a -> m a;
// bind : #a:_ -> #b:_ -> m a -> (a -> m b) -> m b;
// idL : #a:_ -> #b:_ -> x:a -> f:(a -> m b) -> Lemma (bind (return x) f == f x);
// idR : #a:_ -> x:m a -> Lemma (bind x return == x);
// assoc : #a:_ -> #b:_ -> #c:_ -> x:m a -> f:(a -> m b) -> g:(b -> m c) ->
// Lemma (bind (bind x f) g ==
// bind x (fun y -> bind (f y) g));
// }
noeq
type monad_laws (m:Type0 -> Type0) (return : (#a:_ -> a -> m a)) (bind : (#a:_ -> #b:_ -> m a -> (a -> m b) -> m b)) = {
idL : #a:_ -> #b:_ -> x:a -> f:(a -> m b) -> Lemma (bind (return x) f == f x);
idR : #a:_ -> x:m a -> Lemma (bind x return == x);
assoc : #a:_ -> #b:_ -> #c:_ -> x:m a -> f:(a -> m b) -> g:(b -> m c) ->
Lemma (bind (bind x f) g ==
bind x (fun y -> bind (f y) g));
}
class monad (m : Type0 -> Type0) = {
return : #a:_ -> a -> m a;
bind : #a:_ -> #b:_ -> m a -> (a -> m b) -> m b;
laws : monad_laws m return bind;
}
let f #a #b #m {| monad m |} (x : m (a -> b)) (y : m a) : m b =
bind #m x (fun x ->
bind #m y (fun y ->
return #m (x y)))
let g #a #b #m {| d : monad m |} (x : m a) =
d.laws.idL () (fun () -> x);
d.laws.idR x;
assert (bind #m x (return #m) == bind #m (return #m ()) (fun () -> x)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Functor.fst.checked",
"FStar.Tactics.Typeclasses.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Monad.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 | {| _: Monad.monad m |} -> x: m a -> Prims.unit | Prims.Tot | [
"total"
] | [] | [
"Monad.monad",
"Prims._assert",
"Prims.eq2",
"Monad.bind",
"Monad.return",
"Prims.unit",
"Monad.__proj__Mkmonad_laws__item__idR",
"Monad.__proj__Mkmonad__item__return",
"Monad.__proj__Mkmonad__item__bind",
"Monad.laws",
"Monad.__proj__Mkmonad_laws__item__idL"
] | [] | false | false | false | false | false | let g' #a #b #m {| _: monad m |} (x: m a) =
| (laws #m).idL () (fun () -> x);
(laws #m).idR x;
assert (bind #m x (return #m) == bind #m (return #m ()) (fun () -> x)) | false |
|
Monad.fst | Monad.g | val g : {| d: Monad.monad m |} -> x: m a -> Prims.unit | let g #a #b #m {| d : monad m |} (x : m a) =
d.laws.idL () (fun () -> x);
d.laws.idR x;
assert (bind #m x (return #m) == bind #m (return #m ()) (fun () -> x)) | {
"file_name": "examples/typeclasses/Monad.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 72,
"end_line": 54,
"start_col": 0,
"start_line": 51
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Monad
open FStar.Tactics.Typeclasses
(* Fails... due to unification? check it out *)
// class monad (m:Type0 -> Type0) : Type = {
// return : #a:_ -> a -> m a;
// bind : #a:_ -> #b:_ -> m a -> (a -> m b) -> m b;
// idL : #a:_ -> #b:_ -> x:a -> f:(a -> m b) -> Lemma (bind (return x) f == f x);
// idR : #a:_ -> x:m a -> Lemma (bind x return == x);
// assoc : #a:_ -> #b:_ -> #c:_ -> x:m a -> f:(a -> m b) -> g:(b -> m c) ->
// Lemma (bind (bind x f) g ==
// bind x (fun y -> bind (f y) g));
// }
noeq
type monad_laws (m:Type0 -> Type0) (return : (#a:_ -> a -> m a)) (bind : (#a:_ -> #b:_ -> m a -> (a -> m b) -> m b)) = {
idL : #a:_ -> #b:_ -> x:a -> f:(a -> m b) -> Lemma (bind (return x) f == f x);
idR : #a:_ -> x:m a -> Lemma (bind x return == x);
assoc : #a:_ -> #b:_ -> #c:_ -> x:m a -> f:(a -> m b) -> g:(b -> m c) ->
Lemma (bind (bind x f) g ==
bind x (fun y -> bind (f y) g));
}
class monad (m : Type0 -> Type0) = {
return : #a:_ -> a -> m a;
bind : #a:_ -> #b:_ -> m a -> (a -> m b) -> m b;
laws : monad_laws m return bind;
}
let f #a #b #m {| monad m |} (x : m (a -> b)) (y : m a) : m b =
bind #m x (fun x ->
bind #m y (fun y ->
return #m (x y))) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Functor.fst.checked",
"FStar.Tactics.Typeclasses.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Monad.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 | {| d: Monad.monad m |} -> x: m a -> Prims.unit | Prims.Tot | [
"total"
] | [] | [
"Monad.monad",
"Prims._assert",
"Prims.eq2",
"Monad.bind",
"Monad.return",
"Prims.unit",
"Monad.__proj__Mkmonad_laws__item__idR",
"Monad.__proj__Mkmonad__item__return",
"Monad.__proj__Mkmonad__item__bind",
"Monad.__proj__Mkmonad__item__laws",
"Monad.__proj__Mkmonad_laws__item__idL"
] | [] | false | false | false | false | false | let g #a #b #m {| d: monad m |} (x: m a) =
| d.laws.idL () (fun () -> x);
d.laws.idR x;
assert (bind #m x (return #m) == bind #m (return #m ()) (fun () -> x)) | false |
|
Hacl.Spec.BignumQ.Lemmas.fst | Hacl.Spec.BignumQ.Lemmas.lemma_optimized_barrett_reduce2 | val lemma_optimized_barrett_reduce2:
a:nat{a < pow2 512} ->
Lemma (a - ((a * (pow2 512 / S.q)) / pow2 512) * S.q < pow2 264 /\
a - ((a * (pow2 512 / S.q)) / pow2 512) * S.q >= 0) | val lemma_optimized_barrett_reduce2:
a:nat{a < pow2 512} ->
Lemma (a - ((a * (pow2 512 / S.q)) / pow2 512) * S.q < pow2 264 /\
a - ((a * (pow2 512 / S.q)) / pow2 512) * S.q >= 0) | let lemma_optimized_barrett_reduce2 a =
assert_norm (pow2 248 = 0x100000000000000000000000000000000000000000000000000000000000000);
assert_norm (pow2 264 = 0x1000000000000000000000000000000000000000000000000000000000000000000);
assert_norm (S.q == 0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed);
assert_norm (0x100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 == pow2 512) | {
"file_name": "code/ed25519/Hacl.Spec.BignumQ.Lemmas.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 159,
"end_line": 835,
"start_col": 0,
"start_line": 831
} | module Hacl.Spec.BignumQ.Lemmas
open FStar.Tactics.CanonCommSemiring
open FStar.Mul
open Lib.IntTypes
module S = Spec.Ed25519
include Hacl.Spec.BignumQ.Definitions
let feq (#a #b:Type) (f:(a -> b)) (x y:a) :
Lemma (requires x == y) (ensures f x == f y) = ()
let eq_eq2 (#a:eqtype) (x y:a) :
Lemma (requires x = y) (ensures x == y) = ()
val lemma_mul_lt:a:nat -> b:nat -> c:nat -> d:nat ->
Lemma
(requires a < b /\ c < d)
(ensures a * c < b * d)
let lemma_mul_lt a b c d = ()
val lemma_as_nat5: f:qelem5 ->
Lemma
(requires qelem_fits5 f (1, 1, 1, 1, 1))
(ensures as_nat5 f < pow2 280)
let lemma_as_nat5 f =
//let (f0, f1, f2, f3, f4) = f in
//assert (as_nat5 f == v f0 + v f1 * pow56 + v f2 * pow112 + v f3 * pow168 + v f4 * pow224);
assert_norm (pow2 56 * pow2 56 = pow2 112);
assert_norm (pow2 56 * pow2 112 = pow2 168);
assert_norm (pow2 56 * pow2 168 = pow2 224);
assert_norm (pow2 56 * pow2 224 = pow2 280)
val lemma_choose_step:
bit:uint64{v bit <= 1}
-> x:uint64
-> y:uint64
-> Lemma
(let mask = bit -. u64 1 in
let z = x ^. (mask &. (x ^. y)) in
if v bit = 1 then z == x else z == y)
let lemma_choose_step bit p1 p2 =
let mask = bit -. u64 1 in
assert (v bit == 0 ==> v mask == pow2 64 - 1);
assert (v bit == 1 ==> v mask == 0);
let dummy = mask &. (p1 ^. p2) in
logand_lemma mask (p1 ^. p2);
assert (v bit == 1 ==> v dummy == 0);
assert (v bit == 0 ==> v dummy == v (p1 ^. p2));
let p1' = p1 ^. dummy in
assert (v dummy == v (if v bit = 1 then u64 0 else (p1 ^. p2)));
logxor_lemma p1 p2
val lemma_subm_conditional:
x0:nat -> x1:nat -> x2:nat -> x3:nat -> x4:nat
-> y0:nat -> y1:nat -> y2:nat -> y3:nat -> y4:nat
-> b0:nat -> b1:nat -> b2:nat -> b3:nat -> b4:nat ->
Lemma (
x0 - y0 + b0 * pow2 56 +
(x1 - y1 - b0 + b1 * pow2 56) * pow2 56 +
(x2 - y2 - b1 + b2 * pow2 56) * pow2 112 +
(x3 - y3 - b2 + b3 * pow2 56) * pow2 168 +
(x4 - y4 - b3 + b4 * pow2 56) * pow2 224 ==
(x0 + x1 * pow2 56 + x2 * pow2 112 + x3 * pow2 168 + x4 * pow2 224) -
(y0 + y1 * pow2 56 + y2 * pow2 112 + y3 * pow2 168 + y4 * pow2 224) + b4 * pow2 280)
let lemma_subm_conditional x0 x1 x2 x3 x4 y0 y1 y2 y3 y4 b0 b1 b2 b3 b4 =
assert_norm (pow2 56 * pow2 56 = pow2 112);
assert_norm (pow2 56 * pow2 112 = pow2 168);
assert_norm (pow2 56 * pow2 168 = pow2 224);
assert_norm (pow2 56 * pow2 224 = pow2 280);
assert (
x0 - y0 + b0 * pow2 56 +
(x1 - y1 - b0 + b1 * pow2 56) * pow2 56 +
(x2 - y2 - b1 + b2 * pow2 56) * pow2 112 +
(x3 - y3 - b2 + b3 * pow2 56) * pow2 168 +
(x4 - y4 - b3 + b4 * pow2 56) * pow2 224 ==
(x0 + x1 * pow2 56 + x2 * pow2 112 + x3 * pow2 168 + x4 * pow2 224) -
(y0 + y1 * pow2 56 + y2 * pow2 112 + y3 * pow2 168 + y4 * pow2 224) + b4 * pow2 280)
by (int_semiring ());
()
val lemma_div224: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1))
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
wide_as_nat5 x / pow2 224 ==
v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280))
#push-options "--z3rlimit 50"
let lemma_div224 x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert
(wide_as_nat5 x ==
v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168 + v x4 * pow2 224 +
v x5 * pow2 280 + v x6 * pow2 336 + v x7 * pow2 392 + v x8 * pow2 448 + v x9 * pow2 504);
assert_norm (pow2 56 * pow2 224 == pow2 280);
assert_norm (pow2 112 * pow2 224 == pow2 336);
assert_norm (pow2 168 * pow2 224 == pow2 392);
assert_norm (pow2 224 * pow2 224 == pow2 448);
assert_norm (pow2 280 * pow2 224 == pow2 504);
calc (==) {
wide_as_nat5 x / pow2 224;
(==) { }
(v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168 +
(v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280) * pow2 224) / pow2 224;
(==) {
FStar.Math.Lemmas.lemma_div_plus
(v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168)
(v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280) (pow2 224) }
(v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168) / pow2 224 +
v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280;
(==) { FStar.Math.Lemmas.small_division_lemma_1 (v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168) (pow2 224) }
v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280;
}
#pop-options
val lemma_div248_aux: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 512)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
wide_as_nat5 x / pow2 248 ==
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256))
open FStar.Tactics.CanonCommSemiring
#push-options "--z3cliopt smt.arith.nl=false"
let lemma_div248_aux x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert_norm (pow2 248 == pow2 224 * pow2 24);
assert_norm (pow2 56 == pow2 32 * pow2 24);
assert_norm (pow2 112 == pow2 88 * pow2 24);
assert_norm (pow2 168 == pow2 144 * pow2 24);
assert_norm (pow2 224 == pow2 200 * pow2 24);
assert_norm (pow2 280 == pow2 256 * pow2 24);
assert_norm (0 < pow2 24);
calc (==) {
wide_as_nat5 x / pow2 248;
(==) { FStar.Math.Lemmas.division_multiplication_lemma (wide_as_nat5 x) (pow2 224) (pow2 24) }
(wide_as_nat5 x / pow2 224) / pow2 24;
(==) { lemma_div224 x }
(v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280) / pow2 24;
(==) { _ by (Tactics.mapply (`feq #int #int (fun x -> x / pow2 24)); int_semiring ()) } (v x4 + (v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256) * pow2 24) / pow2 24;
(==) { FStar.Math.Lemmas.lemma_div_plus (v x4) (v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256) (pow2 24) }
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256;
}
#pop-options
val lemma_div248_x5: x5:uint64 ->
Lemma ( pow2 32 * (v x5 % pow2 24) + v x5 / pow2 24 * pow2 56 == v x5 * pow2 32)
let lemma_div248_x5 x5 =
assert_norm (pow2 32 * pow2 24 = pow2 56)
val lemma_div248_x6: x6:uint64 ->
Lemma (pow2 32 * (v x6 % pow2 24) * pow2 56 + v x6 / pow2 24 * pow2 112 == v x6 * pow2 88)
let lemma_div248_x6 x6 =
calc (==) {
pow2 32 * (v x6 % pow2 24) * pow2 56 + v x6 / pow2 24 * pow2 112;
(==) { _ by (Tactics.norm [delta_only [`%pow2]; primops]; int_semiring ()) }
((v x6 / pow2 24) * pow2 24 + v x6 % pow2 24) * pow2 88;
(==) { FStar.Math.Lemmas.euclidean_division_definition (v x6) (pow2 24) }
v x6 * pow2 88;
}
val lemma_div248_x7: x7:uint64 ->
Lemma (pow2 32 * (v x7 % pow2 24) * pow2 112 + v x7 / pow2 24 * pow2 168 == v x7 * pow2 144)
let lemma_div248_x7 x7 =
calc (==) {
pow2 32 * (v x7 % pow2 24) * pow2 112 + v x7 / pow2 24 * pow2 168;
(==) { _ by (Tactics.norm [delta_only [`%pow2]; primops]; int_semiring ()) }
((v x7 / pow2 24) * pow2 24 + v x7 % pow2 24) * pow2 144;
(==) { FStar.Math.Lemmas.euclidean_division_definition (v x7) (pow2 24) }
v x7 * pow2 144;
}
val lemma_div248_x8: x8:uint64 ->
Lemma (pow2 32 * (v x8 % pow2 24) * pow2 168 + v x8 / pow2 24 * pow2 224 == v x8 * pow2 200)
let lemma_div248_x8 x8 =
calc (==) {
pow2 32 * (v x8 % pow2 24) * pow2 168 + v x8 / pow2 24 * pow2 224;
(==) { _ by (Tactics.norm [delta_only [`%pow2]; primops]; int_semiring ()) }
((v x8 / pow2 24) * pow2 24 + v x8 % pow2 24) * pow2 200;
(==) { FStar.Math.Lemmas.euclidean_division_definition (v x8) (pow2 24) }
v x8 * pow2 200;
}
val lemma_div248_x9: x9:uint64{v x9 < pow2 24} ->
Lemma (pow2 32 * (v x9 % pow2 24) * pow2 224 == v x9 * pow2 256)
let lemma_div248_x9 x9 =
calc (==) {
pow2 32 * (v x9 % pow2 24) * pow2 224;
(==) { Math.Lemmas.small_mod (v x9) (pow2 24) }
pow2 32 * v x9 * pow2 224;
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
v x9 * pow2 256;
}
val lemma_wide_as_nat_pow512: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 512)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
v x9 < pow2 24))
let lemma_wide_as_nat_pow512 x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert_norm (pow2 504 * pow2 8 = pow2 512);
FStar.Math.Lemmas.pow2_minus 512 504;
assert (v x9 < pow2 8);
assert_norm (pow2 8 < pow2 24)
val lemma_div248: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 512)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
let z0 = v x4 / pow2 24 + pow2 32 * (v x5 % pow2 24) in
let z1 = v x5 / pow2 24 + pow2 32 * (v x6 % pow2 24) in
let z2 = v x6 / pow2 24 + pow2 32 * (v x7 % pow2 24) in
let z3 = v x7 / pow2 24 + pow2 32 * (v x8 % pow2 24) in
let z4 = v x8 / pow2 24 + pow2 32 * (v x9 % pow2 24) in
wide_as_nat5 x / pow2 248 == z0 + z1 * pow2 56 + z2 * pow2 112 + z3 * pow2 168 + z4 * pow2 224))
#push-options "--z3rlimit 50"
let lemma_div248 x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
lemma_wide_as_nat_pow512 x;
assert (v x9 < pow2 24);
calc (==) {
(let z0 = v x4 / pow2 24 + pow2 32 * (v x5 % pow2 24) in
let z1 = v x5 / pow2 24 + pow2 32 * (v x6 % pow2 24) in
let z2 = v x6 / pow2 24 + pow2 32 * (v x7 % pow2 24) in
let z3 = v x7 / pow2 24 + pow2 32 * (v x8 % pow2 24) in
let z4 = v x8 / pow2 24 + pow2 32 * (v x9 % pow2 24) in
z0 + z1 * pow2 56 + z2 * pow2 112 + z3 * pow2 168 + z4 * pow2 224);
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
v x4 / pow2 24 + pow2 32 * (v x5 % pow2 24) +
v x5 / pow2 24 * pow2 56 + pow2 32 * (v x6 % pow2 24) * pow2 56 +
v x6 / pow2 24 * pow2 112 + pow2 32 * (v x7 % pow2 24) * pow2 112 +
v x7 / pow2 24 * pow2 168 + pow2 32 * (v x8 % pow2 24) * pow2 168 +
v x8 / pow2 24 * pow2 224 + pow2 32 * (v x9 % pow2 24) * pow2 224;
(==) { lemma_div248_x5 x5; lemma_div248_x6 x6 }
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 +
pow2 32 * (v x7 % pow2 24) * pow2 112 +
v x7 / pow2 24 * pow2 168 + pow2 32 * (v x8 % pow2 24) * pow2 168 +
v x8 / pow2 24 * pow2 224 + pow2 32 * (v x9 % pow2 24) * pow2 224;
(==) { lemma_div248_x7 x7; lemma_div248_x8 x8 }
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 +
pow2 32 * (v x9 % pow2 24) * pow2 224;
(==) { lemma_div248_x9 x9 }
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256;
(==) { lemma_div248_aux x }
wide_as_nat5 x / pow2 248;
}
#pop-options
val lemma_add_modq5:
x:qelem5
-> y:qelem5
-> t:qelem5 ->
Lemma
(requires
qelem_fits5 x (1, 1, 1, 1, 1) /\
qelem_fits5 y (1, 1, 1, 1, 1) /\
qelem_fits5 t (1, 1, 1, 1, 1) /\
as_nat5 x < S.q /\ as_nat5 y < S.q /\
as_nat5 t == as_nat5 x + as_nat5 y)
(ensures
(let res = if as_nat5 t >= S.q then as_nat5 t - S.q else as_nat5 t in
res < S.q /\ res == (as_nat5 x + as_nat5 y) % S.q))
let lemma_add_modq5 x y t =
assert (as_nat5 t == as_nat5 x + as_nat5 y);
let res = if as_nat5 t >= S.q then as_nat5 t - S.q else as_nat5 t in
assert (res < S.q);
if as_nat5 t >= S.q then (
FStar.Math.Lemmas.sub_div_mod_1 (as_nat5 t) S.q;
assert (res % S.q == as_nat5 t % S.q))
else
assert (res % S.q == as_nat5 t % S.q);
FStar.Math.Lemmas.small_mod res S.q
val lemma_wide_as_nat_pow528: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 528)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
v x9 < pow2 40))
let lemma_wide_as_nat_pow528 x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert_norm (pow2 504 * pow2 24 = pow2 528);
FStar.Math.Lemmas.pow2_minus 528 504;
assert (v x9 < pow2 24);
assert_norm (pow2 24 < pow2 40)
#push-options "--z3cliopt smt.arith.nl=false"
val lemma_div264_aux: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 528)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
wide_as_nat5 x / pow2 264 ==
v x4 / pow2 40 + v x5 * pow2 16 + v x6 * pow2 72 + v x7 * pow2 128 + v x8 * pow2 184 + v x9 * pow2 240))
let lemma_div264_aux x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert_norm (pow2 264 == pow2 224 * pow2 40);
assert_norm (pow2 56 == pow2 16 * pow2 40);
assert_norm (pow2 112 == pow2 72 * pow2 40);
assert_norm (pow2 168 == pow2 128 * pow2 40);
assert_norm (pow2 224 == pow2 184 * pow2 40);
assert_norm (pow2 280 == pow2 240 * pow2 40);
assert_norm (0 < pow2 40);
calc (==) {
wide_as_nat5 x / pow2 264;
(==) { FStar.Math.Lemmas.division_multiplication_lemma (wide_as_nat5 x) (pow2 224) (pow2 40) }
(wide_as_nat5 x / pow2 224) / pow2 40;
(==) { lemma_div224 x }
(v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280) / pow2 40;
(==) { _ by (Tactics.mapply (`feq #int #int (fun x -> x / pow2 40)); int_semiring ()) }
(v x4 + (v x5 * pow2 16 + v x6 * pow2 72 + v x7 * pow2 128 + v x8 * pow2 184 + v x9 * pow2 240) * pow2 40) / pow2 40;
(==) { FStar.Math.Lemmas.lemma_div_plus (v x4) (v x5 * pow2 16 + v x6 * pow2 72 + v x7 * pow2 128 + v x8 * pow2 184 + v x9 * pow2 240) (pow2 40) }
v x4 / pow2 40 + v x5 * pow2 16 + v x6 * pow2 72 + v x7 * pow2 128 + v x8 * pow2 184 + v x9 * pow2 240;
}
val lemma_div264_x5: x5:uint64 ->
Lemma (pow2 16 * (v x5 % pow2 40) + v x5 / pow2 40 * pow2 56 == v x5 * pow2 16)
let lemma_div264_x5 x5 =
assert_norm (0 < pow2 24);
calc (==) {
pow2 16 * (v x5 % pow2 40) + v x5 / pow2 40 * pow2 56;
(==) { _ by (Tactics.norm [delta_only [`%pow2]; primops]; int_semiring ()) }
((v x5 / pow2 40) * pow2 40 + v x5 % pow2 40) * pow2 16;
(==) { FStar.Math.Lemmas.euclidean_division_definition (v x5) (pow2 40) }
v x5 * pow2 16;
}
val lemma_div264_x6: x6:uint64 ->
Lemma (pow2 16 * (v x6 % pow2 40) * pow2 56 + v x6 / pow2 40 * pow2 112 == v x6 * pow2 72)
let lemma_div264_x6 x6 =
calc (==) {
pow2 16 * (v x6 % pow2 40) * pow2 56 + v x6 / pow2 40 * pow2 112;
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
((v x6 / pow2 40) * pow2 40 + v x6 % pow2 40) * pow2 72;
(==) { Math.Lemmas.euclidean_division_definition (v x6) (pow2 40) }
v x6 * pow2 72;
}
val lemma_div264_x7: x7:uint64 ->
Lemma (pow2 16 * (v x7 % pow2 40) * pow2 112 + v x7 / pow2 40 * pow2 168 == v x7 * pow2 128)
let lemma_div264_x7 x7 =
calc (==) {
pow2 16 * (v x7 % pow2 40) * pow2 112 + v x7 / pow2 40 * pow2 168;
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
((v x7 / pow2 40) * pow2 40 + v x7 % pow2 40) * pow2 128;
(==) { Math.Lemmas.euclidean_division_definition (v x7) (pow2 40) }
v x7 * pow2 128;
}
val lemma_div264_x8: x8:uint64 ->
Lemma (pow2 16 * (v x8 % pow2 40) * pow2 168 + v x8 / pow2 40 * pow2 224 == v x8 * pow2 184)
let lemma_div264_x8 x8 =
calc (==) {
pow2 16 * (v x8 % pow2 40) * pow2 168 + v x8 / pow2 40 * pow2 224;
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
((v x8 / pow2 40) * pow2 40 + v x8 % pow2 40) * pow2 184;
(==) { Math.Lemmas.euclidean_division_definition (v x8) (pow2 40) }
v x8 * pow2 184;
}
val lemma_div264_x9: x9:uint64{v x9 < pow2 40} ->
Lemma (pow2 16 * (v x9 % pow2 40) * pow2 224 == v x9 * pow2 240)
let lemma_div264_x9 x9 =
calc (==) {
pow2 16 * (v x9 % pow2 40) * pow2 224;
(==) { Math.Lemmas.small_mod (v x9) (pow2 40) }
pow2 16 * v x9 * pow2 224;
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
v x9 * pow2 240;
}
val lemma_div264: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 528)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
let z0 = v x4 / pow2 40 + pow2 16 * (v x5 % pow2 40) in
let z1 = v x5 / pow2 40 + pow2 16 * (v x6 % pow2 40) in
let z2 = v x6 / pow2 40 + pow2 16 * (v x7 % pow2 40) in
let z3 = v x7 / pow2 40 + pow2 16 * (v x8 % pow2 40) in
let z4 = v x8 / pow2 40 + pow2 16 * (v x9 % pow2 40) in
wide_as_nat5 x / pow2 264 == z0 + z1 * pow2 56 + z2 * pow2 112 + z3 * pow2 168 + z4 * pow2 224))
#push-options "--z3rlimit 50"
let lemma_div264 x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
lemma_wide_as_nat_pow528 x;
assert (v x9 < pow2 40);
calc (==) {
(let z0 = v x4 / pow2 40 + pow2 16 * (v x5 % pow2 40) in
let z1 = v x5 / pow2 40 + pow2 16 * (v x6 % pow2 40) in
let z2 = v x6 / pow2 40 + pow2 16 * (v x7 % pow2 40) in
let z3 = v x7 / pow2 40 + pow2 16 * (v x8 % pow2 40) in
let z4 = v x8 / pow2 40 + pow2 16 * (v x9 % pow2 40) in
z0 + z1 * pow2 56 + z2 * pow2 112 + z3 * pow2 168 + z4 * pow2 224);
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
v x4 / pow2 40 + pow2 16 * (v x5 % pow2 40) +
v x5 / pow2 40 * pow2 56 + pow2 16 * (v x6 % pow2 40) * pow2 56 +
v x6 / pow2 40 * pow2 112 + pow2 16 * (v x7 % pow2 40) * pow2 112 +
v x7 / pow2 40 * pow2 168 + pow2 16 * (v x8 % pow2 40) * pow2 168 +
v x8 / pow2 40 * pow2 224 + pow2 16 * (v x9 % pow2 40) * pow2 224;
(==) { lemma_div264_x5 x5; lemma_div264_x6 x6 }
v x4 / pow2 40 + v x5 * pow2 16 + v x6 * pow2 72 +
pow2 16 * (v x7 % pow2 40) * pow2 112 +
v x7 / pow2 40 * pow2 168 + pow2 16 * (v x8 % pow2 40) * pow2 168 +
v x8 / pow2 40 * pow2 224 + pow2 16 * (v x9 % pow2 40) * pow2 224;
(==) { lemma_div264_x7 x7; lemma_div264_x8 x8 }
v x4 / pow2 40 + v x5 * pow2 16 + v x6 * pow2 72 + v x7 * pow2 128 + v x8 * pow2 184 +
pow2 16 * (v x9 % pow2 40) * pow2 224;
(==) { lemma_div264_x9 x9 }
v x4 / pow2 40 + v x5 * pow2 16 + v x6 * pow2 72 + v x7 * pow2 128 + v x8 * pow2 184 + v x9 * pow2 240;
(==) { lemma_div264_aux x }
wide_as_nat5 x / pow2 264;
}
#pop-options
#pop-options // "--z3cliopt smt.arith.nl=false"
val lemma_mod_264_aux: t:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 t (1, 1, 1, 1, 1, 1, 1, 1, 1, 1))
(ensures
(let (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) = t in
(wide_as_nat5 t) % pow2 264 ==
(v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + v t4 * pow2 224) % pow2 264))
#push-options "--z3rlimit 150"
let lemma_mod_264_aux t =
let (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) = t in
let res = (t0, t1, t2, t3, t4 &. u64 0xffffffffff) in
assert_norm (pow2 16 * pow2 264 == pow2 280);
assert_norm (pow2 72 * pow2 264 == pow2 336);
assert_norm (pow2 128 * pow2 264 == pow2 392);
assert_norm (pow2 184 * pow2 264 == pow2 448);
assert_norm (pow2 240 * pow2 264 == pow2 504);
calc (==) {
(wide_as_nat5 t) % pow2 264;
(==) { }
(v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + v t4 * pow2 224 +
(v t5 * pow2 16 + v t6 * pow2 72 + v t7 * pow2 128 + v t8 * pow2 184 + v t9 * pow2 240) * pow2 264) % pow2 264;
(==) { FStar.Math.Lemmas.lemma_mod_add_distr (v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + v t4 * pow2 224)
((v t5 * pow2 16 + v t6 * pow2 72 + v t7 * pow2 128 + v t8 * pow2 184 + v t9 * pow2 240) * pow2 264) (pow2 264)}
((v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + v t4 * pow2 224) +
((v t5 * pow2 16 + v t6 * pow2 72 + v t7 * pow2 128 + v t8 * pow2 184 + v t9 * pow2 240) * pow2 264) % pow2 264) % pow2 264;
(==) { FStar.Math.Lemmas.cancel_mul_mod (v t5 * pow2 16 + v t6 * pow2 72 + v t7 * pow2 128 + v t8 * pow2 184 + v t9 * pow2 240) (pow2 264) }
(v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + v t4 * pow2 224) % pow2 264;
}
#pop-options
val lemma_as_nat_pow264: x:qelem5 ->
Lemma
(requires
(let (x0, x1, x2, x3, x4) = x in
qelem_fits5 x (1, 1, 1, 1, 1) /\
v x4 < pow2 40))
(ensures as_nat5 x < pow2 264)
let lemma_as_nat_pow264 x =
let (x0, x1, x2, x3, x4) = x in
assert_norm (pow2 40 * pow2 224 = pow2 264)
val lemma_mod_264: t:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 t (1, 1, 1, 1, 1, 1, 1, 1, 1, 1))
(ensures
(let (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) = t in
let res = (t0, t1, t2, t3, t4 &. u64 0xffffffffff) in
qelem_fits5 res (1, 1, 1, 1, 1) /\
as_nat5 res == (wide_as_nat5 t) % pow2 264))
let lemma_mod_264 t =
let (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) = t in
let t4' = t4 &. u64 0xffffffffff in
let res = (t0, t1, t2, t3, t4') in
assert_norm (pow2 40 < pow2 64);
assert_norm (pow2 40 - 1 == 0xffffffffff);
mod_mask_lemma t4 40ul;
assert (v (mod_mask #U64 #SEC 40ul) == 0xffffffffff);
assert (v (t4 &. u64 0xffffffffff) == v t4 % pow2 40);
calc (==) {
(wide_as_nat5 t) % pow2 264;
(==) { lemma_mod_264_aux t }
(v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + v t4 * pow2 224) % pow2 264;
(==) { FStar.Math.Lemmas.lemma_mod_add_distr (v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168) (v t4 * pow2 224) (pow2 264) }
(v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + (v t4 * pow2 224) % pow2 264) % pow2 264;
(==) { FStar.Math.Lemmas.pow2_multiplication_modulo_lemma_2 (v t4) 264 224 }
(v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + (v t4 % pow2 40) * pow2 224) % pow2 264;
(==) { lemma_as_nat_pow264 res; FStar.Math.Lemmas.modulo_lemma (as_nat5 res) (pow2 264) }
v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + (v t4 % pow2 40) * pow2 224;
}
val lemma_as_nat_pow264_x4: x:qelem5 ->
Lemma
(requires
qelem_fits5 x (1, 1, 1, 1, 1) /\
as_nat5 x < pow2 264)
(ensures
(let (x0, x1, x2, x3, x4) = x in
v x4 < pow2 40))
let lemma_as_nat_pow264_x4 x =
let (x0, x1, x2, x3, x4) = x in
assert_norm (pow2 40 * pow2 224 = pow2 264)
val lemma_sub_mod_264_aux:
x0:nat -> x1:nat -> x2:nat -> x3:nat -> x4:nat
-> y0:nat -> y1:nat -> y2:nat -> y3:nat -> y4:nat
-> c1:nat -> c2:nat -> c3:nat -> c4:nat -> c5:nat ->
Lemma (
x0 - y0 + c1 * pow56 +
(x1 - y1 - c1 + c2 * pow56) * pow56 +
(x2 - y2 - c2 + c3 * pow56) * pow112 +
(x3 - y3 - c3 + c4 * pow56) * pow168 +
(x4 - y4 - c4 + pow2 40 * c5) * pow224 ==
(x0 + x1 * pow2 56 + x2 * pow2 112 + x3 * pow2 168 + x4 * pow2 224) -
(y0 + y1 * pow2 56 + y2 * pow2 112 + y3 * pow2 168 + y4 * pow2 224) + c5 * pow2 264)
#push-options "--z3rlimit 50"
let lemma_sub_mod_264_aux x0 x1 x2 x3 x4 y0 y1 y2 y3 y4 b0 b1 b2 b3 b4 =
assert_norm (pow2 56 * pow2 56 = pow2 112);
assert_norm (pow2 56 * pow2 112 = pow2 168);
assert_norm (pow2 56 * pow2 168 = pow2 224);
assert_norm (pow2 40 * pow2 224 = pow2 264)
#pop-options
val lemma_sub_mod_264:
x:qelem5
-> y:qelem5
-> t:qelem5
-> c5:uint64 ->
Lemma
(requires
qelem_fits5 x (1, 1, 1, 1, 1) /\
qelem_fits5 y (1, 1, 1, 1, 1) /\
qelem_fits5 t (1, 1, 1, 1, 1) /\
as_nat5 x < pow2 264 /\
as_nat5 y < pow2 264 /\
as_nat5 t == as_nat5 x - as_nat5 y + v c5 * pow2 264 /\ v c5 <= 1 /\
(if v c5 = 0 then as_nat5 x >= as_nat5 y else as_nat5 x < as_nat5 y))
(ensures
(if as_nat5 x >= as_nat5 y then
as_nat5 t == as_nat5 x - as_nat5 y
else as_nat5 t == as_nat5 x - as_nat5 y + pow2 264))
#push-options "--z3rlimit 50"
let lemma_sub_mod_264 x y t c5 =
assert (if v c5 = 0 then as_nat5 x >= as_nat5 y else as_nat5 x < as_nat5 y);
assert (as_nat5 t == as_nat5 x - as_nat5 y + v c5 * pow2 264);
if as_nat5 x >= as_nat5 y then
assert (v c5 == 0 /\ as_nat5 t == as_nat5 x - as_nat5 y)
else
assert (v c5 == 1 /\ as_nat5 t == as_nat5 x - as_nat5 y + pow2 264)
#pop-options
let lemma_mul_qelem5 (x0 x1 x2 x3 x4 y0 y1 y2 y3 y4:nat) : Lemma
((x0 + x1 * pow2 56 + x2 * pow2 112 + x3 * pow2 168 + x4 * pow2 224) *
(y0 + y1 * pow2 56 + y2 * pow2 112 + y3 * pow2 168 + y4 * pow2 224) ==
x0 * y0 +
(x0 * y1 + x1 * y0) * pow56 +
(x0 * y2 + x1 * y1 + x2 * y0) * pow112 +
(x0 * y3 + x1 * y2 + x2 * y1 + x3 * y0) * pow168 +
(x0 * y4 + x1 * y3 + x2 * y2 + x3 * y1 + x4 * y0) * pow224 +
(x1 * y4 + x2 * y3 + x3 * y2 + x4 * y1) * pow280 +
(x2 * y4 + x3 * y3 + x4 * y2) * pow336 +
(x3 * y4 + x4 * y3) * pow392 +
(x4 * y4) * pow448)
=
assert ((x0 + x1 * pow2 56 + x2 * pow2 112 + x3 * pow2 168 + x4 * pow2 224) *
(y0 + y1 * pow2 56 + y2 * pow2 112 + y3 * pow2 168 + y4 * pow2 224) ==
x0 * y0 +
(x0 * y1 + x1 * y0) * pow56 +
(x0 * y2 + x1 * y1 + x2 * y0) * pow112 +
(x0 * y3 + x1 * y2 + x2 * y1 + x3 * y0) * pow168 +
(x0 * y4 + x1 * y3 + x2 * y2 + x3 * y1 + x4 * y0) * pow224 +
(x1 * y4 + x2 * y3 + x3 * y2 + x4 * y1) * pow280 +
(x2 * y4 + x3 * y3 + x4 * y2) * pow336 +
(x3 * y4 + x4 * y3) * pow392 +
(x4 * y4) * pow448)
by (Tactics.norm [zeta; iota; delta; primops]; int_semiring ())
val lemma_mul_5_low_264:
x1:nat -> x2:nat -> x3:nat -> x4:nat -> x5:nat ->
y1:nat -> y2:nat -> y3:nat -> y4:nat -> y5:nat ->
Lemma (
(x1 * y1) >= 0
/\ (x2 * y1 + x1 * y2 + ((x1 * y1) / pow2 56)) >= 0
/\ (x3 * y1 + x2 * y2 + x1 * y3 + ((x2 * y1 + x1 * y2 + ((x1 * y1) / pow2 56)) / pow2 56)) >= 0
/\ (x4 * y1 + x3 * y2 + x2 * y3 + x1 * y4 + ((x3 * y1 + x2 * y2 + x1 * y3 + ((x2 * y1 + x1 * y2 + ((x1 * y1) / pow2 56)) / pow2 56)) / pow2 56)) >= 0
/\ (
let a0 = (x1 * y1) % pow2 56 in
let a1 = ((x2 * y1 + x1 * y2 + ((x1 * y1) / pow2 56)) % pow2 56) in
let a2 = ((x3 * y1 + x2 * y2 + x1 * y3 + ((x2 * y1 + x1 * y2 + ((x1 * y1) / pow2 56)) / pow2 56)) % pow2 56) in
let a3 = ((x4 * y1 + x3 * y2 + x2 * y3 + x1 * y4 + ((x3 * y1 + x2 * y2 + x1 * y3 + ((x2 * y1 + x1 * y2 + ((x1 * y1) / pow2 56)) / pow2 56)) / pow2 56)) % pow2 56) in
let a4 = (x5 * y1 + x4 * y2 + x3 * y3 + x2 * y4 + x1 * y5 + ((x4 * y1 + x3 * y2 + x2 * y3 + x1 * y4 + ((x3 * y1 + x2 * y2 + x1 * y3 + ((x2 * y1 + x1 * y2 + ((x1 * y1) / pow2 56)) / pow2 56)) / pow2 56)) / pow2 56)) in
((x1 + pow2 56 * x2 + pow2 112 * x3 + pow2 168 * x4 + pow2 224 * x5)
* (y1 + pow2 56 * y2 + pow2 112 * y3 + pow2 168 * y4 + pow2 224 * y5)) % pow2 264
== a0 + pow2 56 * a1 + pow2 112 * a2 + pow2 168 * a3 + pow2 224 * (a4 % pow2 40)))
private let lemma_mul_nat_is_nat (a:nat) (b:nat) : Lemma (a*b >= 0) = ()
private let lemma_div_nat_is_nat (a:nat) (b:pos) : Lemma (a/b >= 0) = ()
private
val lemma_mul_5''':
x1:nat -> x2:nat -> x3:nat -> x4:nat -> x5:nat ->
y1:nat -> y2:nat -> y3:nat -> y4:nat -> y5:nat ->
Lemma (((x1 + pow2 56 * x2 + pow2 112 * x3 + pow2 168 * x4 + pow2 224 * x5)
* (y1 + pow2 56 * y2 + pow2 112 * y3 + pow2 168 * y4 + pow2 224 * y5)) % pow2 264
==
(x1 * y1
+ pow2 56 * (x2 * y1 + x1 * y2)
+ pow2 112 * (x3 * y1 + x2 * y2 + x1 * y3)
+ pow2 168 * (x4 * y1 + x3 * y2 + x2 * y3 + x1 * y4)
+ pow2 224 * (x5 * y1 + x4 * y2 + x3 * y3 + x2 * y4 + x1 * y5)) % pow2 264)
let lemma_mul_5''' x1 x2 x3 x4 x5 y1 y2 y3 y4 y5 =
calc (==) {
((x1 + pow2 56 * x2 + pow2 112 * x3 + pow2 168 * x4 + pow2 224 * x5)
* (y1 + pow2 56 * y2 + pow2 112 * y3 + pow2 168 * y4 + pow2 224 * y5)) % pow2 264;
(==) { _ by (Tactics.mapply (`feq #int #int (fun x -> x % pow2 264));
Tactics.norm [zeta; iota; delta; primops];
int_semiring ()) }
(x1 * y1
+ pow2 56 * (x2 * y1 + x1 * y2)
+ pow2 112 * (x3 * y1 + x2 * y2 + x1 * y3)
+ pow2 168 * (x4 * y1 + x3 * y2 + x2 * y3 + x1 * y4)
+ pow2 224 * (x5 * y1 + x4 * y2 + x3 * y3 + x2 * y4 + x1 * y5)
+ (pow2 16 * x2 * y5 +
pow2 16 * x3 * y4 + pow2 72 * x3 * y5 +
pow2 16 * x4 * y3 + pow2 72 * x4 * y4 + pow2 128 * x4 * y5 +
pow2 16 * x5 * y2 + pow2 72 * x5 * y3 + pow2 128 * x5 * y4 + pow2 184 * x5 * y5) * pow2 264) % pow2 264;
(==) { _ by (Tactics.mapply (`eq_eq2); Tactics.mapply (`Math.Lemmas.lemma_mod_plus)) }
(x1 * y1
+ pow2 56 * (x2 * y1 + x1 * y2)
+ pow2 112 * (x3 * y1 + x2 * y2 + x1 * y3)
+ pow2 168 * (x4 * y1 + x3 * y2 + x2 * y3 + x1 * y4)
+ pow2 224 * (x5 * y1 + x4 * y2 + x3 * y3 + x2 * y4 + x1 * y5)) % pow2 264;
}
private val lemma_mod_264'':
a0:nat -> a1:nat-> a2:nat -> a3:nat -> a4:nat ->
Lemma
(requires a0 < pow56 /\ a1 < pow56 /\ a2 < pow56 /\ a3 < pow56)
(ensures a0 + pow2 56 * a1 + pow2 112 * a2 + pow2 168 * a3 + pow2 224 * (a4 % pow2 40) < pow2 264)
let lemma_mod_264'' a0 a1 a2 a3 a4 =
assert_norm(pow2 40 = 0x10000000000);
assert_norm(pow2 56 = 0x100000000000000);
assert_norm(pow2 112 = 0x10000000000000000000000000000);
assert_norm(pow2 168 = 0x1000000000000000000000000000000000000000000);
assert_norm(pow2 224 = 0x100000000000000000000000000000000000000000000000000000000);
assert_norm(pow2 264 = 0x1000000000000000000000000000000000000000000000000000000000000000000)
private val lemma_mod_264':
a0:nat -> a1:nat-> a2:nat -> a3:nat -> a4:nat ->
Lemma
(requires a0 < pow56 /\ a1 < pow56 /\ a2 < pow56 /\ a3 < pow56)
(ensures (a0
+ pow2 56 * a1
+ pow2 112 * a2
+ pow2 168 * a3
+ pow2 224 * a4) % pow2 264 =
a0
+ pow2 56 * a1
+ pow2 112 * a2
+ pow2 168 * a3
+ pow2 224 * (a4 % pow2 40) )
let lemma_mod_264' a0 a1 a2 a3 a4 =
assert_norm(pow2 56 = 0x100000000000000);
assert_norm(pow2 112 = 0x10000000000000000000000000000);
assert_norm(pow2 168 = 0x1000000000000000000000000000000000000000000);
assert_norm(pow2 224 = 0x100000000000000000000000000000000000000000000000000000000);
Math.Lemmas.lemma_mod_plus_distr_l (pow2 224 * a4) (a0 + pow2 56 * a1 + pow2 112 * a2 + pow2 168 * a3) (pow2 264);
Math.Lemmas.pow2_multiplication_modulo_lemma_2 a4 264 224;
lemma_mod_264'' a0 a1 a2 a3 a4;
Math.Lemmas.modulo_lemma (a0 + pow2 56 * a1 + pow2 112 * a2 + pow2 168 * a3 + pow2 224 * (a4 % pow2 40)) (pow2 264)
private let lemma_aux_0 (a:nat) (b:nat) (n:nat) : Lemma
(pow2 n * a + pow2 (n+56) * b = pow2 n * (a % pow2 56) + pow2 (n+56) * (b + a / pow2 56))
= Math.Lemmas.lemma_div_mod a (pow2 56);
Math.Lemmas.pow2_plus n 56;
assert(a = pow2 56 * (a / pow2 56) + (a % pow2 56));
Math.Lemmas.distributivity_add_right (pow2 n) (pow2 56 * (a / pow2 56)) (a % pow2 56);
Math.Lemmas.paren_mul_right (pow2 n) (pow2 56) (a / pow2 56);
Math.Lemmas.distributivity_add_right (pow2 (n+56)) b (a / pow2 56)
private
val lemma_mod_264_small:
a0:nat -> a1:nat -> a2:nat -> a3:nat -> a4:nat ->
Lemma ( (a0 + pow2 56 * a1 + pow2 112 * a2 + pow2 168 * a3 + pow2 224 * a4)
= (a0 % pow2 56)
+ pow2 56 * ((a1 + (a0 / pow2 56)) % pow2 56)
+ pow2 112 * ((a2 + ((a1 + (a0 / pow2 56)) / pow2 56)) % pow2 56)
+ pow2 168 * ((a3 + ((a2 + ((a1 + (a0 / pow2 56)) / pow2 56)) / pow2 56)) % pow2 56)
+ pow2 224 * (a4 + ((a3 + ((a2 + ((a1 + (a0 / pow2 56)) / pow2 56)) / pow2 56)) / pow2 56)))
(* These silly lemmas needed to guide the proof below... *)
private let aux_nat_over_pos (p : nat) (q : pos) : Lemma (p / q >= 0) = ()
private let aux_nat_plus_nat (p : nat) (q : nat) : Lemma (p + q >= 0) = ()
let lemma_mod_264_small a0 a1 a2 a3 a4 =
Math.Lemmas.lemma_div_mod a0 (pow2 56);
Math.Lemmas.distributivity_add_right (pow2 56) a1 (a0 / pow2 56);
(**) aux_nat_over_pos a0 (pow2 56);
(**) aux_nat_plus_nat a1 (a0 / pow2 56);
let a1':nat = (a1 + (a0 / pow2 56)) in
(**) aux_nat_over_pos a1' (pow2 56);
(**) aux_nat_plus_nat a2 (a1' / pow2 56);
let a2':nat = (a2 + (a1' / pow2 56)) in
(**) aux_nat_over_pos a2' (pow2 56);
(**) aux_nat_plus_nat a3 (a2' / pow2 56);
let a3':nat = (a3 + (a2' / pow2 56)) in
lemma_aux_0 a1' a2 56;
lemma_aux_0 a2' a3 112;
lemma_aux_0 a3' a4 168
private
val lemma_mod_264_:
a0:nat -> a1:nat -> a2:nat -> a3:nat -> a4:nat ->
Lemma ((a0 + pow2 56 * a1 + pow2 112 * a2 + pow2 168 * a3 + pow2 224 * a4) % pow2 264 =
(a0 % pow2 56)
+ pow2 56 * ((a1 + (a0 / pow2 56)) % pow2 56)
+ pow2 112 * ((a2 + ((a1 + (a0 / pow2 56)) / pow2 56)) % pow2 56)
+ pow2 168 * ((a3 + ((a2 + ((a1 + (a0 / pow2 56)) / pow2 56)) / pow2 56)) % pow2 56)
+ pow2 224 * ((a4 + ((a3 + ((a2 + ((a1 + (a0 / pow2 56)) / pow2 56)) / pow2 56)) / pow2 56)) % pow2 40))
let lemma_mod_264_ a0 a1 a2 a3 a4 =
lemma_mod_264_small a0 a1 a2 a3 a4;
let x0 = a0 % pow2 56 in
assert (x0 < pow56);
let x1 = ((a1 + (a0 / pow2 56)) % pow2 56) in
assert (x1 < pow56);
let x2 = ((a2 + ((a1 + (a0 / pow2 56)) / pow2 56)) % pow2 56) in
assert (x2 < pow56);
let x3 = ((a3 + ((a2 + ((a1 + (a0 / pow2 56)) / pow2 56)) / pow2 56)) % pow2 56) in
assert (x3 < pow56);
lemma_mod_264' x0 x1 x2 x3 (a4 + ((a3 + ((a2 + ((a1 + (a0 / pow2 56)) / pow2 56)) / pow2 56)) / pow2 56))
#push-options "--z3rlimit 50"
let lemma_mul_5_low_264 x1 x2 x3 x4 x5 y1 y2 y3 y4 y5 =
lemma_div_nat_is_nat (x1 * y1) (pow2 56);
lemma_div_nat_is_nat (x2 * y1 + x1 * y2 + ((x1 * y1) / pow2 56)) (pow2 56);
lemma_div_nat_is_nat (x3 * y1 + x2 * y2 + x1 * y3 + ((x2 * y1 + x1 * y2 + ((x1 * y1) / pow2 56)) / pow2 56)) (pow2 56);
lemma_div_nat_is_nat (x4 * y1 + x3 * y2 + x2 * y3 + x1 * y4 + ((x3 * y1 + x2 * y2 + x1 * y3 + ((x2 * y1 + x1 * y2 + ((x1 * y1) / pow2 56)) / pow2 56)) / pow2 56)) (pow2 56);
lemma_mul_5''' x1 x2 x3 x4 x5 y1 y2 y3 y4 y5;
lemma_mod_264_ (x1 * y1) (x2 * y1 + x1 * y2) (x3 * y1 + x2 * y2 + x1 * y3) (x4 * y1 + x3 * y2 + x2 * y3 + x1 * y4) (x5 * y1 + x4 * y2 + x3 * y3 + x2 * y4 + x1 * y5)
#pop-options
private
val lemma_optimized_barrett_reduce:
a:nat{a < pow2 512} ->
Lemma (a - (((a / pow2 248) * (pow2 512 / S.q)) / pow2 264) * S.q < 2 * S.q
/\ a - (((a / pow2 248) * (pow2 512 / S.q)) / pow2 264) * S.q >= 0)
#push-options "--z3rlimit 50"
let lemma_optimized_barrett_reduce a =
assert_norm (pow2 248 = 0x100000000000000000000000000000000000000000000000000000000000000);
assert_norm (pow2 264 = 0x1000000000000000000000000000000000000000000000000000000000000000000);
assert_norm (S.q == 0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed);
assert_norm (0x100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 == pow2 512)
#pop-options
private
val lemma_optimized_barrett_reduce2:
a:nat{a < pow2 512} ->
Lemma (a - ((a * (pow2 512 / S.q)) / pow2 512) * S.q < pow2 264 /\
a - ((a * (pow2 512 / S.q)) / pow2 512) * S.q >= 0) | {
"checked_file": "/",
"dependencies": [
"Spec.Ed25519.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.BignumQ.Definitions.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Tactics.CanonCommSemiring.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.BignumQ.Lemmas.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.CanonCommSemiring",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.BignumQ.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.Ed25519",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.CanonCommSemiring",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.BignumQ",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.BignumQ",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Prims.nat{a < Prims.pow2 512}
-> FStar.Pervasives.Lemma
(ensures
a - (a * (Prims.pow2 512 / Spec.Ed25519.q) / Prims.pow2 512) * Spec.Ed25519.q < Prims.pow2 264 /\
a - (a * (Prims.pow2 512 / Spec.Ed25519.q) / Prims.pow2 512) * Spec.Ed25519.q >= 0) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.pow2",
"FStar.Pervasives.assert_norm",
"Prims.eq2",
"Prims.int",
"Prims.unit",
"Spec.Ed25519.q",
"Prims.op_Equality"
] | [] | true | false | true | false | false | let lemma_optimized_barrett_reduce2 a =
| assert_norm (pow2 248 = 0x100000000000000000000000000000000000000000000000000000000000000);
assert_norm (pow2 264 = 0x1000000000000000000000000000000000000000000000000000000000000000000);
assert_norm (S.q == 0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed);
assert_norm (0x100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 ==
pow2 512) | false |
LowParse.Low.DER.fst | LowParse.Low.DER.jump_der_length_payload32 | val jump_der_length_payload32 (x: U8.t{der_length_payload_size_of_tag x <= 4})
: Tot (jumper (parse_der_length_payload32 x)) | val jump_der_length_payload32 (x: U8.t{der_length_payload_size_of_tag x <= 4})
: Tot (jumper (parse_der_length_payload32 x)) | let jump_der_length_payload32
(x: U8.t { der_length_payload_size_of_tag x <= 4 } )
: Tot (jumper (parse_der_length_payload32 x))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_facts (parse_der_length_payload32 x) h input pos;
parse_der_length_payload32_unfold x (bytes_of_slice_from h input pos);
assert_norm (pow2 (8 * 1) == 256);
assert_norm (pow2 (8 * 2) == 65536);
assert_norm (pow2 (8 * 3) == 16777216);
assert_norm (pow2 (8 * 4) == 4294967296)
in
if x `U8.lt` 128uy
then pos
else
[@inline_let]
let len = x `U8.sub` 128uy in
[@inline_let] let _ =
valid_facts parse_u8 h input pos;
parser_kind_prop_equiv parse_u8_kind parse_u8;
valid_facts (parse_bounded_integer (U8.v len)) h input pos;
parser_kind_prop_equiv (parse_bounded_integer_kind (U8.v len)) (parse_bounded_integer (U8.v len))
in
pos `U32.add` Cast.uint8_to_uint32 len | {
"file_name": "src/lowparse/LowParse.Low.DER.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 44,
"end_line": 106,
"start_col": 0,
"start_line": 82
} | module LowParse.Low.DER
include LowParse.Spec.DER
include LowParse.Low.Int // for parse_u8
include LowParse.Low.BoundedInt // for bounded_integer
open FStar.Mul
module U8 = FStar.UInt8
module U32 = FStar.UInt32
module HST = FStar.HyperStack.ST
module B = LowStar.Buffer
module Cast = FStar.Int.Cast
module U64 = FStar.UInt64
#reset-options "--z3cliopt smt.arith.nl=false --max_fuel 0 --max_ifuel 0"
#push-options "--z3rlimit 32"
inline_for_extraction
let validate_der_length_payload32
(x: U8.t { der_length_payload_size_of_tag x <= 4 } )
: Tot (validator (parse_der_length_payload32 x))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_facts (parse_der_length_payload32 x) h input (uint64_to_uint32 pos);
assert (U64.v pos <= U32.v input.len);
parse_der_length_payload32_unfold x (bytes_of_slice_from h input (uint64_to_uint32 pos));
assert_norm (pow2 (8 * 1) == 256);
assert_norm (pow2 (8 * 2) == 65536);
assert_norm (pow2 (8 * 3) == 16777216);
assert_norm (pow2 (8 * 4) == 4294967296)
in
if x `U8.lt` 128uy
then pos
else if x = 128uy || x = 255uy
then validator_error_generic
else if x = 129uy
then
[@inline_let] let _ = valid_facts parse_u8 h input (uint64_to_uint32 pos) in
let v = validate_u8 () input pos in
if is_error v
then v
else
let z = read_u8 input (uint64_to_uint32 pos) in
if z `U8.lt` 128uy
then validator_error_generic
else v
else
let len = x `U8.sub` 128uy in
[@inline_let] let _ = valid_facts (parse_bounded_integer (U8.v len)) h input (uint64_to_uint32 pos) in
if len = 2uy
then
let v = validate_bounded_integer 2 input pos in
if is_error v
then v
else
let y = read_bounded_integer_2 () input (uint64_to_uint32 pos) in
if y `U32.lt `256ul
then validator_error_generic
else v
else if len = 3uy
then
let v = validate_bounded_integer 3 input pos in
if is_error v
then v
else
let y = read_bounded_integer_3 () input (uint64_to_uint32 pos) in
if y `U32.lt `65536ul
then validator_error_generic
else v
else
let v = validate_bounded_integer 4 input pos in
if is_error v
then v
else
let y = read_bounded_integer_4 () input (uint64_to_uint32 pos) in
if y `U32.lt` 16777216ul
then validator_error_generic
else v | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.DER.fsti.checked",
"LowParse.Low.Int.fsti.checked",
"LowParse.Low.BoundedInt.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.DER.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.BoundedInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Int",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.DER",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.arith.nl=false"
],
"z3refresh": false,
"z3rlimit": 32,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: FStar.UInt8.t{LowParse.Spec.DER.der_length_payload_size_of_tag x <= 4}
-> LowParse.Low.Base.jumper (LowParse.Spec.DER.parse_der_length_payload32 x) | Prims.Tot | [
"total"
] | [] | [
"FStar.UInt8.t",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"LowParse.Spec.DER.der_length_payload_size_of_tag",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"FStar.UInt8.lt",
"FStar.UInt8.__uint_to_t",
"Prims.bool",
"FStar.UInt32.add",
"FStar.Int.Cast.uint8_to_uint32",
"Prims.unit",
"LowParse.Spec.Base.parser_kind_prop_equiv",
"LowParse.Spec.BoundedInt.bounded_integer",
"FStar.UInt8.v",
"LowParse.Spec.BoundedInt.parse_bounded_integer_kind",
"LowParse.Spec.BoundedInt.parse_bounded_integer",
"LowParse.Low.Base.Spec.valid_facts",
"LowParse.Spec.Int.parse_u8_kind",
"LowParse.Spec.Int.parse_u8",
"FStar.UInt8.sub",
"FStar.Pervasives.assert_norm",
"Prims.eq2",
"Prims.int",
"Prims.pow2",
"FStar.Mul.op_Star",
"LowParse.Spec.DER.parse_der_length_payload32_unfold",
"LowParse.Slice.bytes_of_slice_from",
"LowParse.Spec.DER.parse_der_length_payload_kind",
"LowParse.Spec.Base.refine_with_tag",
"LowParse.Spec.DER.tag_of_der_length32",
"LowParse.Spec.DER.parse_der_length_payload32",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"LowParse.Low.Base.jumper"
] | [] | false | false | false | false | false | let jump_der_length_payload32 (x: U8.t{der_length_payload_size_of_tag x <= 4})
: Tot (jumper (parse_der_length_payload32 x)) =
| fun #rrel #rel input pos ->
let h = HST.get () in
[@@ inline_let ]let _ =
valid_facts (parse_der_length_payload32 x) h input pos;
parse_der_length_payload32_unfold x (bytes_of_slice_from h input pos);
assert_norm (pow2 (8 * 1) == 256);
assert_norm (pow2 (8 * 2) == 65536);
assert_norm (pow2 (8 * 3) == 16777216);
assert_norm (pow2 (8 * 4) == 4294967296)
in
if x `U8.lt` 128uy
then pos
else
[@@ inline_let ]let len = x `U8.sub` 128uy in
[@@ inline_let ]let _ =
valid_facts parse_u8 h input pos;
parser_kind_prop_equiv parse_u8_kind parse_u8;
valid_facts (parse_bounded_integer (U8.v len)) h input pos;
parser_kind_prop_equiv (parse_bounded_integer_kind (U8.v len))
(parse_bounded_integer (U8.v len))
in
pos `U32.add` (Cast.uint8_to_uint32 len) | false |
Hacl.Spec.BignumQ.Lemmas.fst | Hacl.Spec.BignumQ.Lemmas.lemma_div264_x8 | val lemma_div264_x8: x8:uint64 ->
Lemma (pow2 16 * (v x8 % pow2 40) * pow2 168 + v x8 / pow2 40 * pow2 224 == v x8 * pow2 184) | val lemma_div264_x8: x8:uint64 ->
Lemma (pow2 16 * (v x8 % pow2 40) * pow2 168 + v x8 / pow2 40 * pow2 224 == v x8 * pow2 184) | let lemma_div264_x8 x8 =
calc (==) {
pow2 16 * (v x8 % pow2 40) * pow2 168 + v x8 / pow2 40 * pow2 224;
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
((v x8 / pow2 40) * pow2 40 + v x8 % pow2 40) * pow2 184;
(==) { Math.Lemmas.euclidean_division_definition (v x8) (pow2 40) }
v x8 * pow2 184;
} | {
"file_name": "code/ed25519/Hacl.Spec.BignumQ.Lemmas.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 3,
"end_line": 405,
"start_col": 0,
"start_line": 398
} | module Hacl.Spec.BignumQ.Lemmas
open FStar.Tactics.CanonCommSemiring
open FStar.Mul
open Lib.IntTypes
module S = Spec.Ed25519
include Hacl.Spec.BignumQ.Definitions
let feq (#a #b:Type) (f:(a -> b)) (x y:a) :
Lemma (requires x == y) (ensures f x == f y) = ()
let eq_eq2 (#a:eqtype) (x y:a) :
Lemma (requires x = y) (ensures x == y) = ()
val lemma_mul_lt:a:nat -> b:nat -> c:nat -> d:nat ->
Lemma
(requires a < b /\ c < d)
(ensures a * c < b * d)
let lemma_mul_lt a b c d = ()
val lemma_as_nat5: f:qelem5 ->
Lemma
(requires qelem_fits5 f (1, 1, 1, 1, 1))
(ensures as_nat5 f < pow2 280)
let lemma_as_nat5 f =
//let (f0, f1, f2, f3, f4) = f in
//assert (as_nat5 f == v f0 + v f1 * pow56 + v f2 * pow112 + v f3 * pow168 + v f4 * pow224);
assert_norm (pow2 56 * pow2 56 = pow2 112);
assert_norm (pow2 56 * pow2 112 = pow2 168);
assert_norm (pow2 56 * pow2 168 = pow2 224);
assert_norm (pow2 56 * pow2 224 = pow2 280)
val lemma_choose_step:
bit:uint64{v bit <= 1}
-> x:uint64
-> y:uint64
-> Lemma
(let mask = bit -. u64 1 in
let z = x ^. (mask &. (x ^. y)) in
if v bit = 1 then z == x else z == y)
let lemma_choose_step bit p1 p2 =
let mask = bit -. u64 1 in
assert (v bit == 0 ==> v mask == pow2 64 - 1);
assert (v bit == 1 ==> v mask == 0);
let dummy = mask &. (p1 ^. p2) in
logand_lemma mask (p1 ^. p2);
assert (v bit == 1 ==> v dummy == 0);
assert (v bit == 0 ==> v dummy == v (p1 ^. p2));
let p1' = p1 ^. dummy in
assert (v dummy == v (if v bit = 1 then u64 0 else (p1 ^. p2)));
logxor_lemma p1 p2
val lemma_subm_conditional:
x0:nat -> x1:nat -> x2:nat -> x3:nat -> x4:nat
-> y0:nat -> y1:nat -> y2:nat -> y3:nat -> y4:nat
-> b0:nat -> b1:nat -> b2:nat -> b3:nat -> b4:nat ->
Lemma (
x0 - y0 + b0 * pow2 56 +
(x1 - y1 - b0 + b1 * pow2 56) * pow2 56 +
(x2 - y2 - b1 + b2 * pow2 56) * pow2 112 +
(x3 - y3 - b2 + b3 * pow2 56) * pow2 168 +
(x4 - y4 - b3 + b4 * pow2 56) * pow2 224 ==
(x0 + x1 * pow2 56 + x2 * pow2 112 + x3 * pow2 168 + x4 * pow2 224) -
(y0 + y1 * pow2 56 + y2 * pow2 112 + y3 * pow2 168 + y4 * pow2 224) + b4 * pow2 280)
let lemma_subm_conditional x0 x1 x2 x3 x4 y0 y1 y2 y3 y4 b0 b1 b2 b3 b4 =
assert_norm (pow2 56 * pow2 56 = pow2 112);
assert_norm (pow2 56 * pow2 112 = pow2 168);
assert_norm (pow2 56 * pow2 168 = pow2 224);
assert_norm (pow2 56 * pow2 224 = pow2 280);
assert (
x0 - y0 + b0 * pow2 56 +
(x1 - y1 - b0 + b1 * pow2 56) * pow2 56 +
(x2 - y2 - b1 + b2 * pow2 56) * pow2 112 +
(x3 - y3 - b2 + b3 * pow2 56) * pow2 168 +
(x4 - y4 - b3 + b4 * pow2 56) * pow2 224 ==
(x0 + x1 * pow2 56 + x2 * pow2 112 + x3 * pow2 168 + x4 * pow2 224) -
(y0 + y1 * pow2 56 + y2 * pow2 112 + y3 * pow2 168 + y4 * pow2 224) + b4 * pow2 280)
by (int_semiring ());
()
val lemma_div224: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1))
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
wide_as_nat5 x / pow2 224 ==
v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280))
#push-options "--z3rlimit 50"
let lemma_div224 x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert
(wide_as_nat5 x ==
v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168 + v x4 * pow2 224 +
v x5 * pow2 280 + v x6 * pow2 336 + v x7 * pow2 392 + v x8 * pow2 448 + v x9 * pow2 504);
assert_norm (pow2 56 * pow2 224 == pow2 280);
assert_norm (pow2 112 * pow2 224 == pow2 336);
assert_norm (pow2 168 * pow2 224 == pow2 392);
assert_norm (pow2 224 * pow2 224 == pow2 448);
assert_norm (pow2 280 * pow2 224 == pow2 504);
calc (==) {
wide_as_nat5 x / pow2 224;
(==) { }
(v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168 +
(v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280) * pow2 224) / pow2 224;
(==) {
FStar.Math.Lemmas.lemma_div_plus
(v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168)
(v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280) (pow2 224) }
(v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168) / pow2 224 +
v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280;
(==) { FStar.Math.Lemmas.small_division_lemma_1 (v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168) (pow2 224) }
v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280;
}
#pop-options
val lemma_div248_aux: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 512)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
wide_as_nat5 x / pow2 248 ==
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256))
open FStar.Tactics.CanonCommSemiring
#push-options "--z3cliopt smt.arith.nl=false"
let lemma_div248_aux x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert_norm (pow2 248 == pow2 224 * pow2 24);
assert_norm (pow2 56 == pow2 32 * pow2 24);
assert_norm (pow2 112 == pow2 88 * pow2 24);
assert_norm (pow2 168 == pow2 144 * pow2 24);
assert_norm (pow2 224 == pow2 200 * pow2 24);
assert_norm (pow2 280 == pow2 256 * pow2 24);
assert_norm (0 < pow2 24);
calc (==) {
wide_as_nat5 x / pow2 248;
(==) { FStar.Math.Lemmas.division_multiplication_lemma (wide_as_nat5 x) (pow2 224) (pow2 24) }
(wide_as_nat5 x / pow2 224) / pow2 24;
(==) { lemma_div224 x }
(v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280) / pow2 24;
(==) { _ by (Tactics.mapply (`feq #int #int (fun x -> x / pow2 24)); int_semiring ()) } (v x4 + (v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256) * pow2 24) / pow2 24;
(==) { FStar.Math.Lemmas.lemma_div_plus (v x4) (v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256) (pow2 24) }
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256;
}
#pop-options
val lemma_div248_x5: x5:uint64 ->
Lemma ( pow2 32 * (v x5 % pow2 24) + v x5 / pow2 24 * pow2 56 == v x5 * pow2 32)
let lemma_div248_x5 x5 =
assert_norm (pow2 32 * pow2 24 = pow2 56)
val lemma_div248_x6: x6:uint64 ->
Lemma (pow2 32 * (v x6 % pow2 24) * pow2 56 + v x6 / pow2 24 * pow2 112 == v x6 * pow2 88)
let lemma_div248_x6 x6 =
calc (==) {
pow2 32 * (v x6 % pow2 24) * pow2 56 + v x6 / pow2 24 * pow2 112;
(==) { _ by (Tactics.norm [delta_only [`%pow2]; primops]; int_semiring ()) }
((v x6 / pow2 24) * pow2 24 + v x6 % pow2 24) * pow2 88;
(==) { FStar.Math.Lemmas.euclidean_division_definition (v x6) (pow2 24) }
v x6 * pow2 88;
}
val lemma_div248_x7: x7:uint64 ->
Lemma (pow2 32 * (v x7 % pow2 24) * pow2 112 + v x7 / pow2 24 * pow2 168 == v x7 * pow2 144)
let lemma_div248_x7 x7 =
calc (==) {
pow2 32 * (v x7 % pow2 24) * pow2 112 + v x7 / pow2 24 * pow2 168;
(==) { _ by (Tactics.norm [delta_only [`%pow2]; primops]; int_semiring ()) }
((v x7 / pow2 24) * pow2 24 + v x7 % pow2 24) * pow2 144;
(==) { FStar.Math.Lemmas.euclidean_division_definition (v x7) (pow2 24) }
v x7 * pow2 144;
}
val lemma_div248_x8: x8:uint64 ->
Lemma (pow2 32 * (v x8 % pow2 24) * pow2 168 + v x8 / pow2 24 * pow2 224 == v x8 * pow2 200)
let lemma_div248_x8 x8 =
calc (==) {
pow2 32 * (v x8 % pow2 24) * pow2 168 + v x8 / pow2 24 * pow2 224;
(==) { _ by (Tactics.norm [delta_only [`%pow2]; primops]; int_semiring ()) }
((v x8 / pow2 24) * pow2 24 + v x8 % pow2 24) * pow2 200;
(==) { FStar.Math.Lemmas.euclidean_division_definition (v x8) (pow2 24) }
v x8 * pow2 200;
}
val lemma_div248_x9: x9:uint64{v x9 < pow2 24} ->
Lemma (pow2 32 * (v x9 % pow2 24) * pow2 224 == v x9 * pow2 256)
let lemma_div248_x9 x9 =
calc (==) {
pow2 32 * (v x9 % pow2 24) * pow2 224;
(==) { Math.Lemmas.small_mod (v x9) (pow2 24) }
pow2 32 * v x9 * pow2 224;
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
v x9 * pow2 256;
}
val lemma_wide_as_nat_pow512: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 512)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
v x9 < pow2 24))
let lemma_wide_as_nat_pow512 x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert_norm (pow2 504 * pow2 8 = pow2 512);
FStar.Math.Lemmas.pow2_minus 512 504;
assert (v x9 < pow2 8);
assert_norm (pow2 8 < pow2 24)
val lemma_div248: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 512)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
let z0 = v x4 / pow2 24 + pow2 32 * (v x5 % pow2 24) in
let z1 = v x5 / pow2 24 + pow2 32 * (v x6 % pow2 24) in
let z2 = v x6 / pow2 24 + pow2 32 * (v x7 % pow2 24) in
let z3 = v x7 / pow2 24 + pow2 32 * (v x8 % pow2 24) in
let z4 = v x8 / pow2 24 + pow2 32 * (v x9 % pow2 24) in
wide_as_nat5 x / pow2 248 == z0 + z1 * pow2 56 + z2 * pow2 112 + z3 * pow2 168 + z4 * pow2 224))
#push-options "--z3rlimit 50"
let lemma_div248 x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
lemma_wide_as_nat_pow512 x;
assert (v x9 < pow2 24);
calc (==) {
(let z0 = v x4 / pow2 24 + pow2 32 * (v x5 % pow2 24) in
let z1 = v x5 / pow2 24 + pow2 32 * (v x6 % pow2 24) in
let z2 = v x6 / pow2 24 + pow2 32 * (v x7 % pow2 24) in
let z3 = v x7 / pow2 24 + pow2 32 * (v x8 % pow2 24) in
let z4 = v x8 / pow2 24 + pow2 32 * (v x9 % pow2 24) in
z0 + z1 * pow2 56 + z2 * pow2 112 + z3 * pow2 168 + z4 * pow2 224);
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
v x4 / pow2 24 + pow2 32 * (v x5 % pow2 24) +
v x5 / pow2 24 * pow2 56 + pow2 32 * (v x6 % pow2 24) * pow2 56 +
v x6 / pow2 24 * pow2 112 + pow2 32 * (v x7 % pow2 24) * pow2 112 +
v x7 / pow2 24 * pow2 168 + pow2 32 * (v x8 % pow2 24) * pow2 168 +
v x8 / pow2 24 * pow2 224 + pow2 32 * (v x9 % pow2 24) * pow2 224;
(==) { lemma_div248_x5 x5; lemma_div248_x6 x6 }
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 +
pow2 32 * (v x7 % pow2 24) * pow2 112 +
v x7 / pow2 24 * pow2 168 + pow2 32 * (v x8 % pow2 24) * pow2 168 +
v x8 / pow2 24 * pow2 224 + pow2 32 * (v x9 % pow2 24) * pow2 224;
(==) { lemma_div248_x7 x7; lemma_div248_x8 x8 }
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 +
pow2 32 * (v x9 % pow2 24) * pow2 224;
(==) { lemma_div248_x9 x9 }
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256;
(==) { lemma_div248_aux x }
wide_as_nat5 x / pow2 248;
}
#pop-options
val lemma_add_modq5:
x:qelem5
-> y:qelem5
-> t:qelem5 ->
Lemma
(requires
qelem_fits5 x (1, 1, 1, 1, 1) /\
qelem_fits5 y (1, 1, 1, 1, 1) /\
qelem_fits5 t (1, 1, 1, 1, 1) /\
as_nat5 x < S.q /\ as_nat5 y < S.q /\
as_nat5 t == as_nat5 x + as_nat5 y)
(ensures
(let res = if as_nat5 t >= S.q then as_nat5 t - S.q else as_nat5 t in
res < S.q /\ res == (as_nat5 x + as_nat5 y) % S.q))
let lemma_add_modq5 x y t =
assert (as_nat5 t == as_nat5 x + as_nat5 y);
let res = if as_nat5 t >= S.q then as_nat5 t - S.q else as_nat5 t in
assert (res < S.q);
if as_nat5 t >= S.q then (
FStar.Math.Lemmas.sub_div_mod_1 (as_nat5 t) S.q;
assert (res % S.q == as_nat5 t % S.q))
else
assert (res % S.q == as_nat5 t % S.q);
FStar.Math.Lemmas.small_mod res S.q
val lemma_wide_as_nat_pow528: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 528)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
v x9 < pow2 40))
let lemma_wide_as_nat_pow528 x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert_norm (pow2 504 * pow2 24 = pow2 528);
FStar.Math.Lemmas.pow2_minus 528 504;
assert (v x9 < pow2 24);
assert_norm (pow2 24 < pow2 40)
#push-options "--z3cliopt smt.arith.nl=false"
val lemma_div264_aux: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 528)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
wide_as_nat5 x / pow2 264 ==
v x4 / pow2 40 + v x5 * pow2 16 + v x6 * pow2 72 + v x7 * pow2 128 + v x8 * pow2 184 + v x9 * pow2 240))
let lemma_div264_aux x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert_norm (pow2 264 == pow2 224 * pow2 40);
assert_norm (pow2 56 == pow2 16 * pow2 40);
assert_norm (pow2 112 == pow2 72 * pow2 40);
assert_norm (pow2 168 == pow2 128 * pow2 40);
assert_norm (pow2 224 == pow2 184 * pow2 40);
assert_norm (pow2 280 == pow2 240 * pow2 40);
assert_norm (0 < pow2 40);
calc (==) {
wide_as_nat5 x / pow2 264;
(==) { FStar.Math.Lemmas.division_multiplication_lemma (wide_as_nat5 x) (pow2 224) (pow2 40) }
(wide_as_nat5 x / pow2 224) / pow2 40;
(==) { lemma_div224 x }
(v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280) / pow2 40;
(==) { _ by (Tactics.mapply (`feq #int #int (fun x -> x / pow2 40)); int_semiring ()) }
(v x4 + (v x5 * pow2 16 + v x6 * pow2 72 + v x7 * pow2 128 + v x8 * pow2 184 + v x9 * pow2 240) * pow2 40) / pow2 40;
(==) { FStar.Math.Lemmas.lemma_div_plus (v x4) (v x5 * pow2 16 + v x6 * pow2 72 + v x7 * pow2 128 + v x8 * pow2 184 + v x9 * pow2 240) (pow2 40) }
v x4 / pow2 40 + v x5 * pow2 16 + v x6 * pow2 72 + v x7 * pow2 128 + v x8 * pow2 184 + v x9 * pow2 240;
}
val lemma_div264_x5: x5:uint64 ->
Lemma (pow2 16 * (v x5 % pow2 40) + v x5 / pow2 40 * pow2 56 == v x5 * pow2 16)
let lemma_div264_x5 x5 =
assert_norm (0 < pow2 24);
calc (==) {
pow2 16 * (v x5 % pow2 40) + v x5 / pow2 40 * pow2 56;
(==) { _ by (Tactics.norm [delta_only [`%pow2]; primops]; int_semiring ()) }
((v x5 / pow2 40) * pow2 40 + v x5 % pow2 40) * pow2 16;
(==) { FStar.Math.Lemmas.euclidean_division_definition (v x5) (pow2 40) }
v x5 * pow2 16;
}
val lemma_div264_x6: x6:uint64 ->
Lemma (pow2 16 * (v x6 % pow2 40) * pow2 56 + v x6 / pow2 40 * pow2 112 == v x6 * pow2 72)
let lemma_div264_x6 x6 =
calc (==) {
pow2 16 * (v x6 % pow2 40) * pow2 56 + v x6 / pow2 40 * pow2 112;
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
((v x6 / pow2 40) * pow2 40 + v x6 % pow2 40) * pow2 72;
(==) { Math.Lemmas.euclidean_division_definition (v x6) (pow2 40) }
v x6 * pow2 72;
}
val lemma_div264_x7: x7:uint64 ->
Lemma (pow2 16 * (v x7 % pow2 40) * pow2 112 + v x7 / pow2 40 * pow2 168 == v x7 * pow2 128)
let lemma_div264_x7 x7 =
calc (==) {
pow2 16 * (v x7 % pow2 40) * pow2 112 + v x7 / pow2 40 * pow2 168;
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
((v x7 / pow2 40) * pow2 40 + v x7 % pow2 40) * pow2 128;
(==) { Math.Lemmas.euclidean_division_definition (v x7) (pow2 40) }
v x7 * pow2 128;
}
val lemma_div264_x8: x8:uint64 -> | {
"checked_file": "/",
"dependencies": [
"Spec.Ed25519.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.BignumQ.Definitions.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Tactics.CanonCommSemiring.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.BignumQ.Lemmas.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.CanonCommSemiring",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.BignumQ.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.Ed25519",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.CanonCommSemiring",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.BignumQ",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.BignumQ",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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": [
"smt.arith.nl=false"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x8: Lib.IntTypes.uint64
-> FStar.Pervasives.Lemma
(ensures
(Prims.pow2 16 * (Lib.IntTypes.v x8 % Prims.pow2 40)) * Prims.pow2 168 +
(Lib.IntTypes.v x8 / Prims.pow2 40) * Prims.pow2 224 ==
Lib.IntTypes.v x8 * Prims.pow2 184) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Lib.IntTypes.uint64",
"FStar.Calc.calc_finish",
"Prims.int",
"Prims.eq2",
"Prims.op_Addition",
"FStar.Mul.op_Star",
"Prims.pow2",
"Prims.op_Modulus",
"Lib.IntTypes.v",
"Lib.IntTypes.U64",
"Lib.IntTypes.SEC",
"Prims.op_Division",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"Prims.unit",
"FStar.Calc.calc_step",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"FStar.Tactics.CanonCommSemiring.semiring_reflect",
"FStar.Tactics.CanonCommSemiring.int_cr",
"FStar.Pervasives.Native.Mktuple2",
"Prims.list",
"FStar.Pervasives.Native.tuple2",
"Prims.nat",
"FStar.Pervasives.Native.snd",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"Lib.IntTypes.sec_int_v",
"FStar.Stubs.Reflection.V2.Data.var",
"FStar.Tactics.CanonCommSemiring.Pplus",
"FStar.Tactics.CanonCommSemiring.Pmult",
"FStar.Tactics.CanonCommSemiring.Pvar",
"Prims.op_Multiply",
"Prims.l_and",
"Prims.bool",
"Prims.op_LessThanOrEqual",
"Prims.op_Subtraction",
"Lib.IntTypes.bits",
"Prims.squash",
"FStar.Math.Lemmas.euclidean_division_definition"
] | [] | false | false | true | false | false | let lemma_div264_x8 x8 =
| calc ( == ) {
(pow2 16 * (v x8 % pow2 40)) * pow2 168 + (v x8 / pow2 40) * pow2 224;
( == ) { FStar.Tactics.Effect.synth_by_tactic (fun _ ->
(Tactics.norm [delta; primops];
int_semiring ())) }
((v x8 / pow2 40) * pow2 40 + v x8 % pow2 40) * pow2 184;
( == ) { Math.Lemmas.euclidean_division_definition (v x8) (pow2 40) }
v x8 * pow2 184;
} | false |
LowParse.Low.ConstInt32.fst | LowParse.Low.ConstInt32.compare_by_bytes | val compare_by_bytes : a0: FStar.UInt8.t{0 <= FStar.UInt8.v a0 /\ FStar.UInt8.v a0 < 256} ->
a1: FStar.UInt8.t{0 <= FStar.UInt8.v a1 /\ FStar.UInt8.v a1 < 256} ->
a2: FStar.UInt8.t{0 <= FStar.UInt8.v a2 /\ FStar.UInt8.v a2 < 256} ->
a3: FStar.UInt8.t{0 <= FStar.UInt8.v a3 /\ FStar.UInt8.v a3 < 256} ->
b0: FStar.UInt8.t{0 <= FStar.UInt8.v b0 /\ FStar.UInt8.v b0 < 256} ->
b1: FStar.UInt8.t{0 <= FStar.UInt8.v b1 /\ FStar.UInt8.v b1 < 256} ->
b2: FStar.UInt8.t{0 <= FStar.UInt8.v b2 /\ FStar.UInt8.v b2 < 256} ->
b3: FStar.UInt8.t{0 <= FStar.UInt8.v b3 /\ FStar.UInt8.v b3 < 256}
-> Prims.bool | let compare_by_bytes
(a0: U8.t { 0 <= U8.v a0 /\ U8.v a0 < 256 } )
(a1: U8.t { 0 <= U8.v a1 /\ U8.v a1 < 256 } )
(a2: U8.t { 0 <= U8.v a2 /\ U8.v a2 < 256 } )
(a3: U8.t { 0 <= U8.v a3 /\ U8.v a3 < 256 } )
(b0: U8.t { 0 <= U8.v b0 /\ U8.v b0 < 256 } )
(b1: U8.t { 0 <= U8.v b1 /\ U8.v b1 < 256 } )
(b2: U8.t { 0 <= U8.v b2 /\ U8.v b2 < 256 } )
(b3: U8.t { 0 <= U8.v b3 /\ U8.v b3 < 256 } )
= a0 = b0 && a1 = b1 && a2 = b2 && a3 = b3 | {
"file_name": "src/lowparse/LowParse.Low.ConstInt32.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 42,
"end_line": 115,
"start_col": 0,
"start_line": 106
} | module LowParse.Low.ConstInt32
(* LowParse implementation module for 32 bits contants *)
include FStar.Endianness
include LowParse.Spec.ConstInt32
include LowParse.Spec.Int32le
include LowParse.Low.Combinators
include LowParse.Low.Int32le
module U32 = FStar.UInt32
module U8 = FStar.UInt8
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module B = LowStar.Buffer
module Cast = FStar.Int.Cast
module U64 = FStar.UInt64
let valid_constint32le
(v: nat { 0 <= v /\ v < 4294967296 } )
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma (valid (parse_constint32le v) h input pos
<==>
(valid parse_int32le h input pos /\
U32.v (contents parse_int32le h input pos) == v))
= valid_facts (parse_constint32le v) h input pos;
valid_facts parse_int32le h input pos;
parse_constint32le_unfold v (bytes_of_slice_from h input pos)
inline_for_extraction
let validate_constint32le_slow
(v: U32.t { 0 <= U32.v v /\ U32.v v < 4294967296 } )
: Tot (validator (parse_constint32le (U32.v v)))
= fun #rrel #rel (input: slice rrel rel) pos ->
let h = HST.get() in
let _ =
valid_constint32le (U32.v v) h input (uint64_to_uint32 pos);
valid_equiv parse_int32le h input (uint64_to_uint32 pos)
in
if U64.lt (Cast.uint32_to_uint64 input.len `U64.sub` pos) 4uL
then
validator_error_not_enough_data
else
let v' = read_int32le input (uint64_to_uint32 pos) in
if U32.eq v v' then
pos `U64.add` 4uL
else
validator_error_generic
inline_for_extraction
let read_constint32le
(v: U32.t { 0 <= U32.v v /\ U32.v v < 4294967296 } )
: Tot (leaf_reader (parse_constint32le (U32.v v)))
= fun #rrel #rel input pos ->
v
inline_for_extraction
let decompose_int32le_0
(v: nat { 0 <= v /\ v < 4294967296 } )
: Tot (b0: nat { 0 <= b0 /\ b0 < 256 } )
= v % 256
inline_for_extraction
let decompose_int32le_1
(v: nat { 0 <= v /\ v < 4294967296 } )
: Tot (b1: nat { 0 <= b1 /\ b1 < 256 } )
= v / 256 % 256
inline_for_extraction
let decompose_int32le_2
(v: nat { 0 <= v /\ v < 4294967296 } )
: Tot (b2: nat { 0 <= b2 /\ b2 < 256 } )
= v / 65536 % 256
inline_for_extraction
let decompose_int32le_3
(v: nat { 0 <= v /\ v < 4294967296 } )
: Tot (b3: nat { 0 <= b3 /\ b3 < 256 } )
= v / 16777216
let compose_int32le
(b0: nat { 0 <= b0 /\ b0 < 256 } )
(b1: nat { 0 <= b1 /\ b1 < 256 } )
(b2: nat { 0 <= b2 /\ b2 < 256 } )
(b3: nat { 0 <= b3 /\ b3 < 256 } )
: Tot (v: nat { 0 <= v /\ v < 4294967296 } )
= b0
+ 256 `FStar.Mul.op_Star` (b1
+ 256 `FStar.Mul.op_Star` (b2
+ 256 `FStar.Mul.op_Star` b3))
#push-options "--z3rlimit 16"
let decompose_compose_equiv
(v: nat { 0 <= v /\ v < 4294967296 } )
: Lemma (compose_int32le (decompose_int32le_0 v) (decompose_int32le_1 v) (decompose_int32le_2 v) (decompose_int32le_3 v) == v)
= ()
#pop-options | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Int32le.fst.checked",
"LowParse.Spec.ConstInt32.fst.checked",
"LowParse.Low.Int32le.fst.checked",
"LowParse.Low.Combinators.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Endianness.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.ConstInt32.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "LowParse.Low.Int32le",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Int32le",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.ConstInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Endianness",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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 |
a0: FStar.UInt8.t{0 <= FStar.UInt8.v a0 /\ FStar.UInt8.v a0 < 256} ->
a1: FStar.UInt8.t{0 <= FStar.UInt8.v a1 /\ FStar.UInt8.v a1 < 256} ->
a2: FStar.UInt8.t{0 <= FStar.UInt8.v a2 /\ FStar.UInt8.v a2 < 256} ->
a3: FStar.UInt8.t{0 <= FStar.UInt8.v a3 /\ FStar.UInt8.v a3 < 256} ->
b0: FStar.UInt8.t{0 <= FStar.UInt8.v b0 /\ FStar.UInt8.v b0 < 256} ->
b1: FStar.UInt8.t{0 <= FStar.UInt8.v b1 /\ FStar.UInt8.v b1 < 256} ->
b2: FStar.UInt8.t{0 <= FStar.UInt8.v b2 /\ FStar.UInt8.v b2 < 256} ->
b3: FStar.UInt8.t{0 <= FStar.UInt8.v b3 /\ FStar.UInt8.v b3 < 256}
-> Prims.bool | Prims.Tot | [
"total"
] | [] | [
"FStar.UInt8.t",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.UInt8.v",
"Prims.op_LessThan",
"Prims.op_AmpAmp",
"Prims.op_Equality",
"Prims.l_or",
"Prims.bool"
] | [] | false | false | false | false | false | let compare_by_bytes
(a0: U8.t{0 <= U8.v a0 /\ U8.v a0 < 256})
(a1: U8.t{0 <= U8.v a1 /\ U8.v a1 < 256})
(a2: U8.t{0 <= U8.v a2 /\ U8.v a2 < 256})
(a3: U8.t{0 <= U8.v a3 /\ U8.v a3 < 256})
(b0: U8.t{0 <= U8.v b0 /\ U8.v b0 < 256})
(b1: U8.t{0 <= U8.v b1 /\ U8.v b1 < 256})
(b2: U8.t{0 <= U8.v b2 /\ U8.v b2 < 256})
(b3: U8.t{0 <= U8.v b3 /\ U8.v b3 < 256})
=
| a0 = b0 && a1 = b1 && a2 = b2 && a3 = b3 | false |
|
LowParse.Low.ConstInt32.fst | LowParse.Low.ConstInt32.compose_int32le | val compose_int32le
(b0: nat{0 <= b0 /\ b0 < 256})
(b1: nat{0 <= b1 /\ b1 < 256})
(b2: nat{0 <= b2 /\ b2 < 256})
(b3: nat{0 <= b3 /\ b3 < 256})
: Tot (v: nat{0 <= v /\ v < 4294967296}) | val compose_int32le
(b0: nat{0 <= b0 /\ b0 < 256})
(b1: nat{0 <= b1 /\ b1 < 256})
(b2: nat{0 <= b2 /\ b2 < 256})
(b3: nat{0 <= b3 /\ b3 < 256})
: Tot (v: nat{0 <= v /\ v < 4294967296}) | let compose_int32le
(b0: nat { 0 <= b0 /\ b0 < 256 } )
(b1: nat { 0 <= b1 /\ b1 < 256 } )
(b2: nat { 0 <= b2 /\ b2 < 256 } )
(b3: nat { 0 <= b3 /\ b3 < 256 } )
: Tot (v: nat { 0 <= v /\ v < 4294967296 } )
= b0
+ 256 `FStar.Mul.op_Star` (b1
+ 256 `FStar.Mul.op_Star` (b2
+ 256 `FStar.Mul.op_Star` b3)) | {
"file_name": "src/lowparse/LowParse.Low.ConstInt32.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 32,
"end_line": 94,
"start_col": 0,
"start_line": 85
} | module LowParse.Low.ConstInt32
(* LowParse implementation module for 32 bits contants *)
include FStar.Endianness
include LowParse.Spec.ConstInt32
include LowParse.Spec.Int32le
include LowParse.Low.Combinators
include LowParse.Low.Int32le
module U32 = FStar.UInt32
module U8 = FStar.UInt8
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module B = LowStar.Buffer
module Cast = FStar.Int.Cast
module U64 = FStar.UInt64
let valid_constint32le
(v: nat { 0 <= v /\ v < 4294967296 } )
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma (valid (parse_constint32le v) h input pos
<==>
(valid parse_int32le h input pos /\
U32.v (contents parse_int32le h input pos) == v))
= valid_facts (parse_constint32le v) h input pos;
valid_facts parse_int32le h input pos;
parse_constint32le_unfold v (bytes_of_slice_from h input pos)
inline_for_extraction
let validate_constint32le_slow
(v: U32.t { 0 <= U32.v v /\ U32.v v < 4294967296 } )
: Tot (validator (parse_constint32le (U32.v v)))
= fun #rrel #rel (input: slice rrel rel) pos ->
let h = HST.get() in
let _ =
valid_constint32le (U32.v v) h input (uint64_to_uint32 pos);
valid_equiv parse_int32le h input (uint64_to_uint32 pos)
in
if U64.lt (Cast.uint32_to_uint64 input.len `U64.sub` pos) 4uL
then
validator_error_not_enough_data
else
let v' = read_int32le input (uint64_to_uint32 pos) in
if U32.eq v v' then
pos `U64.add` 4uL
else
validator_error_generic
inline_for_extraction
let read_constint32le
(v: U32.t { 0 <= U32.v v /\ U32.v v < 4294967296 } )
: Tot (leaf_reader (parse_constint32le (U32.v v)))
= fun #rrel #rel input pos ->
v
inline_for_extraction
let decompose_int32le_0
(v: nat { 0 <= v /\ v < 4294967296 } )
: Tot (b0: nat { 0 <= b0 /\ b0 < 256 } )
= v % 256
inline_for_extraction
let decompose_int32le_1
(v: nat { 0 <= v /\ v < 4294967296 } )
: Tot (b1: nat { 0 <= b1 /\ b1 < 256 } )
= v / 256 % 256
inline_for_extraction
let decompose_int32le_2
(v: nat { 0 <= v /\ v < 4294967296 } )
: Tot (b2: nat { 0 <= b2 /\ b2 < 256 } )
= v / 65536 % 256
inline_for_extraction
let decompose_int32le_3
(v: nat { 0 <= v /\ v < 4294967296 } )
: Tot (b3: nat { 0 <= b3 /\ b3 < 256 } )
= v / 16777216 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Int32le.fst.checked",
"LowParse.Spec.ConstInt32.fst.checked",
"LowParse.Low.Int32le.fst.checked",
"LowParse.Low.Combinators.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Endianness.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.ConstInt32.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "LowParse.Low.Int32le",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Int32le",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.ConstInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Endianness",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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 |
b0: Prims.nat{0 <= b0 /\ b0 < 256} ->
b1: Prims.nat{0 <= b1 /\ b1 < 256} ->
b2: Prims.nat{0 <= b2 /\ b2 < 256} ->
b3: Prims.nat{0 <= b3 /\ b3 < 256}
-> v: Prims.nat{0 <= v /\ v < 4294967296} | Prims.Tot | [
"total"
] | [] | [
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"Prims.op_Addition",
"FStar.Mul.op_Star"
] | [] | false | false | false | false | false | let compose_int32le
(b0: nat{0 <= b0 /\ b0 < 256})
(b1: nat{0 <= b1 /\ b1 < 256})
(b2: nat{0 <= b2 /\ b2 < 256})
(b3: nat{0 <= b3 /\ b3 < 256})
: Tot (v: nat{0 <= v /\ v < 4294967296}) =
| b0 + 256 `FStar.Mul.op_Star` (b1 + 256 `FStar.Mul.op_Star` (b2 + 256 `FStar.Mul.op_Star` b3)) | false |
LowParse.Low.ConstInt32.fst | LowParse.Low.ConstInt32.valid_constint32le | val valid_constint32le
(v: nat{0 <= v /\ v < 4294967296})
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(valid (parse_constint32le v) h input pos <==>
(valid parse_int32le h input pos /\ U32.v (contents parse_int32le h input pos) == v)) | val valid_constint32le
(v: nat{0 <= v /\ v < 4294967296})
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(valid (parse_constint32le v) h input pos <==>
(valid parse_int32le h input pos /\ U32.v (contents parse_int32le h input pos) == v)) | let valid_constint32le
(v: nat { 0 <= v /\ v < 4294967296 } )
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma (valid (parse_constint32le v) h input pos
<==>
(valid parse_int32le h input pos /\
U32.v (contents parse_int32le h input pos) == v))
= valid_facts (parse_constint32le v) h input pos;
valid_facts parse_int32le h input pos;
parse_constint32le_unfold v (bytes_of_slice_from h input pos) | {
"file_name": "src/lowparse/LowParse.Low.ConstInt32.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 63,
"end_line": 32,
"start_col": 0,
"start_line": 20
} | module LowParse.Low.ConstInt32
(* LowParse implementation module for 32 bits contants *)
include FStar.Endianness
include LowParse.Spec.ConstInt32
include LowParse.Spec.Int32le
include LowParse.Low.Combinators
include LowParse.Low.Int32le
module U32 = FStar.UInt32
module U8 = FStar.UInt8
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module B = LowStar.Buffer
module Cast = FStar.Int.Cast
module U64 = FStar.UInt64 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Int32le.fst.checked",
"LowParse.Spec.ConstInt32.fst.checked",
"LowParse.Low.Int32le.fst.checked",
"LowParse.Low.Combinators.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Endianness.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.ConstInt32.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "LowParse.Low.Int32le",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Int32le",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.ConstInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Endianness",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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: Prims.nat{0 <= v /\ v < 4294967296} ->
h: FStar.Monotonic.HyperStack.mem ->
input: LowParse.Slice.slice rrel rel ->
pos: FStar.UInt32.t
-> FStar.Pervasives.Lemma
(ensures
LowParse.Low.Base.Spec.valid (LowParse.Spec.ConstInt32.parse_constint32le v) h input pos <==>
LowParse.Low.Base.Spec.valid LowParse.Spec.Int32le.parse_int32le h input pos /\
FStar.UInt32.v (LowParse.Low.Base.Spec.contents LowParse.Spec.Int32le.parse_int32le
h
input
pos) ==
v) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"FStar.Monotonic.HyperStack.mem",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"LowParse.Spec.ConstInt32.parse_constint32le_unfold",
"LowParse.Slice.bytes_of_slice_from",
"Prims.unit",
"LowParse.Low.Base.Spec.valid_facts",
"LowParse.Spec.Base.total_constant_size_parser_kind",
"LowParse.Spec.Int32le.parse_int32le",
"LowParse.Spec.ConstInt32.parse_constint32le_kind",
"LowParse.Spec.ConstInt32.constint32",
"LowParse.Spec.ConstInt32.parse_constint32le",
"Prims.l_True",
"Prims.squash",
"Prims.l_iff",
"LowParse.Low.Base.Spec.valid",
"Prims.eq2",
"Prims.int",
"Prims.l_or",
"FStar.UInt.size",
"FStar.UInt32.n",
"Prims.op_GreaterThanOrEqual",
"FStar.UInt32.v",
"LowParse.Low.Base.Spec.contents",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let valid_constint32le
(v: nat{0 <= v /\ v < 4294967296})
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(valid (parse_constint32le v) h input pos <==>
(valid parse_int32le h input pos /\ U32.v (contents parse_int32le h input pos) == v)) =
| valid_facts (parse_constint32le v) h input pos;
valid_facts parse_int32le h input pos;
parse_constint32le_unfold v (bytes_of_slice_from h input pos) | false |
LowParse.Low.ConstInt32.fst | LowParse.Low.ConstInt32.decompose_int32le_2 | val decompose_int32le_2 (v: nat{0 <= v /\ v < 4294967296}) : Tot (b2: nat{0 <= b2 /\ b2 < 256}) | val decompose_int32le_2 (v: nat{0 <= v /\ v < 4294967296}) : Tot (b2: nat{0 <= b2 /\ b2 < 256}) | let decompose_int32le_2
(v: nat { 0 <= v /\ v < 4294967296 } )
: Tot (b2: nat { 0 <= b2 /\ b2 < 256 } )
= v / 65536 % 256 | {
"file_name": "src/lowparse/LowParse.Low.ConstInt32.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 17,
"end_line": 77,
"start_col": 0,
"start_line": 74
} | module LowParse.Low.ConstInt32
(* LowParse implementation module for 32 bits contants *)
include FStar.Endianness
include LowParse.Spec.ConstInt32
include LowParse.Spec.Int32le
include LowParse.Low.Combinators
include LowParse.Low.Int32le
module U32 = FStar.UInt32
module U8 = FStar.UInt8
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module B = LowStar.Buffer
module Cast = FStar.Int.Cast
module U64 = FStar.UInt64
let valid_constint32le
(v: nat { 0 <= v /\ v < 4294967296 } )
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma (valid (parse_constint32le v) h input pos
<==>
(valid parse_int32le h input pos /\
U32.v (contents parse_int32le h input pos) == v))
= valid_facts (parse_constint32le v) h input pos;
valid_facts parse_int32le h input pos;
parse_constint32le_unfold v (bytes_of_slice_from h input pos)
inline_for_extraction
let validate_constint32le_slow
(v: U32.t { 0 <= U32.v v /\ U32.v v < 4294967296 } )
: Tot (validator (parse_constint32le (U32.v v)))
= fun #rrel #rel (input: slice rrel rel) pos ->
let h = HST.get() in
let _ =
valid_constint32le (U32.v v) h input (uint64_to_uint32 pos);
valid_equiv parse_int32le h input (uint64_to_uint32 pos)
in
if U64.lt (Cast.uint32_to_uint64 input.len `U64.sub` pos) 4uL
then
validator_error_not_enough_data
else
let v' = read_int32le input (uint64_to_uint32 pos) in
if U32.eq v v' then
pos `U64.add` 4uL
else
validator_error_generic
inline_for_extraction
let read_constint32le
(v: U32.t { 0 <= U32.v v /\ U32.v v < 4294967296 } )
: Tot (leaf_reader (parse_constint32le (U32.v v)))
= fun #rrel #rel input pos ->
v
inline_for_extraction
let decompose_int32le_0
(v: nat { 0 <= v /\ v < 4294967296 } )
: Tot (b0: nat { 0 <= b0 /\ b0 < 256 } )
= v % 256
inline_for_extraction
let decompose_int32le_1
(v: nat { 0 <= v /\ v < 4294967296 } )
: Tot (b1: nat { 0 <= b1 /\ b1 < 256 } )
= v / 256 % 256 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Int32le.fst.checked",
"LowParse.Spec.ConstInt32.fst.checked",
"LowParse.Low.Int32le.fst.checked",
"LowParse.Low.Combinators.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Endianness.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.ConstInt32.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "LowParse.Low.Int32le",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Int32le",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.ConstInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Endianness",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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: Prims.nat{0 <= v /\ v < 4294967296} -> b2: Prims.nat{0 <= b2 /\ b2 < 256} | Prims.Tot | [
"total"
] | [] | [
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"Prims.op_Modulus",
"Prims.op_Division"
] | [] | false | false | false | false | false | let decompose_int32le_2 (v: nat{0 <= v /\ v < 4294967296}) : Tot (b2: nat{0 <= b2 /\ b2 < 256}) =
| v / 65536 % 256 | false |
LowParse.Low.ConstInt32.fst | LowParse.Low.ConstInt32.decompose_int32le_3 | val decompose_int32le_3 (v: nat{0 <= v /\ v < 4294967296}) : Tot (b3: nat{0 <= b3 /\ b3 < 256}) | val decompose_int32le_3 (v: nat{0 <= v /\ v < 4294967296}) : Tot (b3: nat{0 <= b3 /\ b3 < 256}) | let decompose_int32le_3
(v: nat { 0 <= v /\ v < 4294967296 } )
: Tot (b3: nat { 0 <= b3 /\ b3 < 256 } )
= v / 16777216 | {
"file_name": "src/lowparse/LowParse.Low.ConstInt32.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 14,
"end_line": 83,
"start_col": 0,
"start_line": 80
} | module LowParse.Low.ConstInt32
(* LowParse implementation module for 32 bits contants *)
include FStar.Endianness
include LowParse.Spec.ConstInt32
include LowParse.Spec.Int32le
include LowParse.Low.Combinators
include LowParse.Low.Int32le
module U32 = FStar.UInt32
module U8 = FStar.UInt8
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module B = LowStar.Buffer
module Cast = FStar.Int.Cast
module U64 = FStar.UInt64
let valid_constint32le
(v: nat { 0 <= v /\ v < 4294967296 } )
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma (valid (parse_constint32le v) h input pos
<==>
(valid parse_int32le h input pos /\
U32.v (contents parse_int32le h input pos) == v))
= valid_facts (parse_constint32le v) h input pos;
valid_facts parse_int32le h input pos;
parse_constint32le_unfold v (bytes_of_slice_from h input pos)
inline_for_extraction
let validate_constint32le_slow
(v: U32.t { 0 <= U32.v v /\ U32.v v < 4294967296 } )
: Tot (validator (parse_constint32le (U32.v v)))
= fun #rrel #rel (input: slice rrel rel) pos ->
let h = HST.get() in
let _ =
valid_constint32le (U32.v v) h input (uint64_to_uint32 pos);
valid_equiv parse_int32le h input (uint64_to_uint32 pos)
in
if U64.lt (Cast.uint32_to_uint64 input.len `U64.sub` pos) 4uL
then
validator_error_not_enough_data
else
let v' = read_int32le input (uint64_to_uint32 pos) in
if U32.eq v v' then
pos `U64.add` 4uL
else
validator_error_generic
inline_for_extraction
let read_constint32le
(v: U32.t { 0 <= U32.v v /\ U32.v v < 4294967296 } )
: Tot (leaf_reader (parse_constint32le (U32.v v)))
= fun #rrel #rel input pos ->
v
inline_for_extraction
let decompose_int32le_0
(v: nat { 0 <= v /\ v < 4294967296 } )
: Tot (b0: nat { 0 <= b0 /\ b0 < 256 } )
= v % 256
inline_for_extraction
let decompose_int32le_1
(v: nat { 0 <= v /\ v < 4294967296 } )
: Tot (b1: nat { 0 <= b1 /\ b1 < 256 } )
= v / 256 % 256
inline_for_extraction
let decompose_int32le_2
(v: nat { 0 <= v /\ v < 4294967296 } )
: Tot (b2: nat { 0 <= b2 /\ b2 < 256 } )
= v / 65536 % 256 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Int32le.fst.checked",
"LowParse.Spec.ConstInt32.fst.checked",
"LowParse.Low.Int32le.fst.checked",
"LowParse.Low.Combinators.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Endianness.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.ConstInt32.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "LowParse.Low.Int32le",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Int32le",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.ConstInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Endianness",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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: Prims.nat{0 <= v /\ v < 4294967296} -> b3: Prims.nat{0 <= b3 /\ b3 < 256} | Prims.Tot | [
"total"
] | [] | [
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"Prims.op_Division"
] | [] | false | false | false | false | false | let decompose_int32le_3 (v: nat{0 <= v /\ v < 4294967296}) : Tot (b3: nat{0 <= b3 /\ b3 < 256}) =
| v / 16777216 | false |
LowParse.Low.ConstInt32.fst | LowParse.Low.ConstInt32.compare_by_bytes' | val compare_by_bytes' : a0: FStar.UInt8.t{0 <= FStar.UInt8.v a0 /\ FStar.UInt8.v a0 < 256} ->
a1: FStar.UInt8.t{0 <= FStar.UInt8.v a1 /\ FStar.UInt8.v a1 < 256} ->
a2: FStar.UInt8.t{0 <= FStar.UInt8.v a2 /\ FStar.UInt8.v a2 < 256} ->
a3: FStar.UInt8.t{0 <= FStar.UInt8.v a3 /\ FStar.UInt8.v a3 < 256} ->
b0: FStar.UInt8.t{0 <= FStar.UInt8.v b0 /\ FStar.UInt8.v b0 < 256} ->
b1: FStar.UInt8.t{0 <= FStar.UInt8.v b1 /\ FStar.UInt8.v b1 < 256} ->
b2: FStar.UInt8.t{0 <= FStar.UInt8.v b2 /\ FStar.UInt8.v b2 < 256} ->
b3: FStar.UInt8.t{0 <= FStar.UInt8.v b3 /\ FStar.UInt8.v b3 < 256}
-> Prims.bool | let compare_by_bytes'
(a0: U8.t { 0 <= U8.v a0 /\ U8.v a0 < 256 } )
(a1: U8.t { 0 <= U8.v a1 /\ U8.v a1 < 256 } )
(a2: U8.t { 0 <= U8.v a2 /\ U8.v a2 < 256 } )
(a3: U8.t { 0 <= U8.v a3 /\ U8.v a3 < 256 } )
(b0: U8.t { 0 <= U8.v b0 /\ U8.v b0 < 256 } )
(b1: U8.t { 0 <= U8.v b1 /\ U8.v b1 < 256 } )
(b2: U8.t { 0 <= U8.v b2 /\ U8.v b2 < 256 } )
(b3: U8.t { 0 <= U8.v b3 /\ U8.v b3 < 256 } )
= (compose_int32le (U8.v a0) (U8.v a1) (U8.v a2) (U8.v a3)) =
(compose_int32le (U8.v b0) (U8.v b1) (U8.v b2) (U8.v b3)) | {
"file_name": "src/lowparse/LowParse.Low.ConstInt32.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 59,
"end_line": 127,
"start_col": 0,
"start_line": 117
} | module LowParse.Low.ConstInt32
(* LowParse implementation module for 32 bits contants *)
include FStar.Endianness
include LowParse.Spec.ConstInt32
include LowParse.Spec.Int32le
include LowParse.Low.Combinators
include LowParse.Low.Int32le
module U32 = FStar.UInt32
module U8 = FStar.UInt8
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module B = LowStar.Buffer
module Cast = FStar.Int.Cast
module U64 = FStar.UInt64
let valid_constint32le
(v: nat { 0 <= v /\ v < 4294967296 } )
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma (valid (parse_constint32le v) h input pos
<==>
(valid parse_int32le h input pos /\
U32.v (contents parse_int32le h input pos) == v))
= valid_facts (parse_constint32le v) h input pos;
valid_facts parse_int32le h input pos;
parse_constint32le_unfold v (bytes_of_slice_from h input pos)
inline_for_extraction
let validate_constint32le_slow
(v: U32.t { 0 <= U32.v v /\ U32.v v < 4294967296 } )
: Tot (validator (parse_constint32le (U32.v v)))
= fun #rrel #rel (input: slice rrel rel) pos ->
let h = HST.get() in
let _ =
valid_constint32le (U32.v v) h input (uint64_to_uint32 pos);
valid_equiv parse_int32le h input (uint64_to_uint32 pos)
in
if U64.lt (Cast.uint32_to_uint64 input.len `U64.sub` pos) 4uL
then
validator_error_not_enough_data
else
let v' = read_int32le input (uint64_to_uint32 pos) in
if U32.eq v v' then
pos `U64.add` 4uL
else
validator_error_generic
inline_for_extraction
let read_constint32le
(v: U32.t { 0 <= U32.v v /\ U32.v v < 4294967296 } )
: Tot (leaf_reader (parse_constint32le (U32.v v)))
= fun #rrel #rel input pos ->
v
inline_for_extraction
let decompose_int32le_0
(v: nat { 0 <= v /\ v < 4294967296 } )
: Tot (b0: nat { 0 <= b0 /\ b0 < 256 } )
= v % 256
inline_for_extraction
let decompose_int32le_1
(v: nat { 0 <= v /\ v < 4294967296 } )
: Tot (b1: nat { 0 <= b1 /\ b1 < 256 } )
= v / 256 % 256
inline_for_extraction
let decompose_int32le_2
(v: nat { 0 <= v /\ v < 4294967296 } )
: Tot (b2: nat { 0 <= b2 /\ b2 < 256 } )
= v / 65536 % 256
inline_for_extraction
let decompose_int32le_3
(v: nat { 0 <= v /\ v < 4294967296 } )
: Tot (b3: nat { 0 <= b3 /\ b3 < 256 } )
= v / 16777216
let compose_int32le
(b0: nat { 0 <= b0 /\ b0 < 256 } )
(b1: nat { 0 <= b1 /\ b1 < 256 } )
(b2: nat { 0 <= b2 /\ b2 < 256 } )
(b3: nat { 0 <= b3 /\ b3 < 256 } )
: Tot (v: nat { 0 <= v /\ v < 4294967296 } )
= b0
+ 256 `FStar.Mul.op_Star` (b1
+ 256 `FStar.Mul.op_Star` (b2
+ 256 `FStar.Mul.op_Star` b3))
#push-options "--z3rlimit 16"
let decompose_compose_equiv
(v: nat { 0 <= v /\ v < 4294967296 } )
: Lemma (compose_int32le (decompose_int32le_0 v) (decompose_int32le_1 v) (decompose_int32le_2 v) (decompose_int32le_3 v) == v)
= ()
#pop-options
inline_for_extraction
let compare_by_bytes
(a0: U8.t { 0 <= U8.v a0 /\ U8.v a0 < 256 } )
(a1: U8.t { 0 <= U8.v a1 /\ U8.v a1 < 256 } )
(a2: U8.t { 0 <= U8.v a2 /\ U8.v a2 < 256 } )
(a3: U8.t { 0 <= U8.v a3 /\ U8.v a3 < 256 } )
(b0: U8.t { 0 <= U8.v b0 /\ U8.v b0 < 256 } )
(b1: U8.t { 0 <= U8.v b1 /\ U8.v b1 < 256 } )
(b2: U8.t { 0 <= U8.v b2 /\ U8.v b2 < 256 } )
(b3: U8.t { 0 <= U8.v b3 /\ U8.v b3 < 256 } )
= a0 = b0 && a1 = b1 && a2 = b2 && a3 = b3 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Int32le.fst.checked",
"LowParse.Spec.ConstInt32.fst.checked",
"LowParse.Low.Int32le.fst.checked",
"LowParse.Low.Combinators.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Endianness.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.ConstInt32.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "LowParse.Low.Int32le",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Int32le",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.ConstInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Endianness",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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 |
a0: FStar.UInt8.t{0 <= FStar.UInt8.v a0 /\ FStar.UInt8.v a0 < 256} ->
a1: FStar.UInt8.t{0 <= FStar.UInt8.v a1 /\ FStar.UInt8.v a1 < 256} ->
a2: FStar.UInt8.t{0 <= FStar.UInt8.v a2 /\ FStar.UInt8.v a2 < 256} ->
a3: FStar.UInt8.t{0 <= FStar.UInt8.v a3 /\ FStar.UInt8.v a3 < 256} ->
b0: FStar.UInt8.t{0 <= FStar.UInt8.v b0 /\ FStar.UInt8.v b0 < 256} ->
b1: FStar.UInt8.t{0 <= FStar.UInt8.v b1 /\ FStar.UInt8.v b1 < 256} ->
b2: FStar.UInt8.t{0 <= FStar.UInt8.v b2 /\ FStar.UInt8.v b2 < 256} ->
b3: FStar.UInt8.t{0 <= FStar.UInt8.v b3 /\ FStar.UInt8.v b3 < 256}
-> Prims.bool | Prims.Tot | [
"total"
] | [] | [
"FStar.UInt8.t",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.UInt8.v",
"Prims.op_LessThan",
"Prims.op_Equality",
"Prims.nat",
"Prims.l_or",
"LowParse.Low.ConstInt32.compose_int32le",
"Prims.bool"
] | [] | false | false | false | false | false | let compare_by_bytes'
(a0: U8.t{0 <= U8.v a0 /\ U8.v a0 < 256})
(a1: U8.t{0 <= U8.v a1 /\ U8.v a1 < 256})
(a2: U8.t{0 <= U8.v a2 /\ U8.v a2 < 256})
(a3: U8.t{0 <= U8.v a3 /\ U8.v a3 < 256})
(b0: U8.t{0 <= U8.v b0 /\ U8.v b0 < 256})
(b1: U8.t{0 <= U8.v b1 /\ U8.v b1 < 256})
(b2: U8.t{0 <= U8.v b2 /\ U8.v b2 < 256})
(b3: U8.t{0 <= U8.v b3 /\ U8.v b3 < 256})
=
| (compose_int32le (U8.v a0) (U8.v a1) (U8.v a2) (U8.v a3)) =
(compose_int32le (U8.v b0) (U8.v b1) (U8.v b2) (U8.v b3)) | false |
|
LowParse.Low.ConstInt32.fst | LowParse.Low.ConstInt32.read_constint32le | val read_constint32le (v: U32.t{0 <= U32.v v /\ U32.v v < 4294967296})
: Tot (leaf_reader (parse_constint32le (U32.v v))) | val read_constint32le (v: U32.t{0 <= U32.v v /\ U32.v v < 4294967296})
: Tot (leaf_reader (parse_constint32le (U32.v v))) | let read_constint32le
(v: U32.t { 0 <= U32.v v /\ U32.v v < 4294967296 } )
: Tot (leaf_reader (parse_constint32le (U32.v v)))
= fun #rrel #rel input pos ->
v | {
"file_name": "src/lowparse/LowParse.Low.ConstInt32.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 5,
"end_line": 59,
"start_col": 0,
"start_line": 55
} | module LowParse.Low.ConstInt32
(* LowParse implementation module for 32 bits contants *)
include FStar.Endianness
include LowParse.Spec.ConstInt32
include LowParse.Spec.Int32le
include LowParse.Low.Combinators
include LowParse.Low.Int32le
module U32 = FStar.UInt32
module U8 = FStar.UInt8
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module B = LowStar.Buffer
module Cast = FStar.Int.Cast
module U64 = FStar.UInt64
let valid_constint32le
(v: nat { 0 <= v /\ v < 4294967296 } )
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma (valid (parse_constint32le v) h input pos
<==>
(valid parse_int32le h input pos /\
U32.v (contents parse_int32le h input pos) == v))
= valid_facts (parse_constint32le v) h input pos;
valid_facts parse_int32le h input pos;
parse_constint32le_unfold v (bytes_of_slice_from h input pos)
inline_for_extraction
let validate_constint32le_slow
(v: U32.t { 0 <= U32.v v /\ U32.v v < 4294967296 } )
: Tot (validator (parse_constint32le (U32.v v)))
= fun #rrel #rel (input: slice rrel rel) pos ->
let h = HST.get() in
let _ =
valid_constint32le (U32.v v) h input (uint64_to_uint32 pos);
valid_equiv parse_int32le h input (uint64_to_uint32 pos)
in
if U64.lt (Cast.uint32_to_uint64 input.len `U64.sub` pos) 4uL
then
validator_error_not_enough_data
else
let v' = read_int32le input (uint64_to_uint32 pos) in
if U32.eq v v' then
pos `U64.add` 4uL
else
validator_error_generic | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Int32le.fst.checked",
"LowParse.Spec.ConstInt32.fst.checked",
"LowParse.Low.Int32le.fst.checked",
"LowParse.Low.Combinators.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Endianness.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.ConstInt32.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "LowParse.Low.Int32le",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Int32le",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.ConstInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Endianness",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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: FStar.UInt32.t{0 <= FStar.UInt32.v v /\ FStar.UInt32.v v < 4294967296}
-> LowParse.Low.Base.leaf_reader (LowParse.Spec.ConstInt32.parse_constint32le (FStar.UInt32.v v)) | Prims.Tot | [
"total"
] | [] | [
"FStar.UInt32.t",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.UInt32.v",
"Prims.op_LessThan",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"LowParse.Spec.ConstInt32.constint32",
"LowParse.Low.Base.leaf_reader",
"LowParse.Spec.ConstInt32.parse_constint32le_kind",
"LowParse.Spec.ConstInt32.parse_constint32le"
] | [] | false | false | false | false | false | let read_constint32le (v: U32.t{0 <= U32.v v /\ U32.v v < 4294967296})
: Tot (leaf_reader (parse_constint32le (U32.v v))) =
| fun #rrel #rel input pos -> v | false |
LowParse.Low.DER.fst | LowParse.Low.DER.serialize32_bounded_der_length32 | val serialize32_bounded_der_length32
(vmin: der_length_t)
(vmax: der_length_t{vmin <= vmax /\ vmax < 4294967296})
: Tot (serializer32 (serialize_bounded_der_length32 (vmin) (vmax))) | val serialize32_bounded_der_length32
(vmin: der_length_t)
(vmax: der_length_t{vmin <= vmax /\ vmax < 4294967296})
: Tot (serializer32 (serialize_bounded_der_length32 (vmin) (vmax))) | let serialize32_bounded_der_length32
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
: Tot (serializer32 (serialize_bounded_der_length32 (vmin) (vmax)))
= fun (y' : bounded_int32 (vmin) (vmax)) #rrel #rel b pos ->
serialize32_bounded_der_length32' vmin vmax y' b pos | {
"file_name": "src/lowparse/LowParse.Low.DER.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 54,
"end_line": 319,
"start_col": 0,
"start_line": 314
} | module LowParse.Low.DER
include LowParse.Spec.DER
include LowParse.Low.Int // for parse_u8
include LowParse.Low.BoundedInt // for bounded_integer
open FStar.Mul
module U8 = FStar.UInt8
module U32 = FStar.UInt32
module HST = FStar.HyperStack.ST
module B = LowStar.Buffer
module Cast = FStar.Int.Cast
module U64 = FStar.UInt64
#reset-options "--z3cliopt smt.arith.nl=false --max_fuel 0 --max_ifuel 0"
#push-options "--z3rlimit 32"
inline_for_extraction
let validate_der_length_payload32
(x: U8.t { der_length_payload_size_of_tag x <= 4 } )
: Tot (validator (parse_der_length_payload32 x))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_facts (parse_der_length_payload32 x) h input (uint64_to_uint32 pos);
assert (U64.v pos <= U32.v input.len);
parse_der_length_payload32_unfold x (bytes_of_slice_from h input (uint64_to_uint32 pos));
assert_norm (pow2 (8 * 1) == 256);
assert_norm (pow2 (8 * 2) == 65536);
assert_norm (pow2 (8 * 3) == 16777216);
assert_norm (pow2 (8 * 4) == 4294967296)
in
if x `U8.lt` 128uy
then pos
else if x = 128uy || x = 255uy
then validator_error_generic
else if x = 129uy
then
[@inline_let] let _ = valid_facts parse_u8 h input (uint64_to_uint32 pos) in
let v = validate_u8 () input pos in
if is_error v
then v
else
let z = read_u8 input (uint64_to_uint32 pos) in
if z `U8.lt` 128uy
then validator_error_generic
else v
else
let len = x `U8.sub` 128uy in
[@inline_let] let _ = valid_facts (parse_bounded_integer (U8.v len)) h input (uint64_to_uint32 pos) in
if len = 2uy
then
let v = validate_bounded_integer 2 input pos in
if is_error v
then v
else
let y = read_bounded_integer_2 () input (uint64_to_uint32 pos) in
if y `U32.lt `256ul
then validator_error_generic
else v
else if len = 3uy
then
let v = validate_bounded_integer 3 input pos in
if is_error v
then v
else
let y = read_bounded_integer_3 () input (uint64_to_uint32 pos) in
if y `U32.lt `65536ul
then validator_error_generic
else v
else
let v = validate_bounded_integer 4 input pos in
if is_error v
then v
else
let y = read_bounded_integer_4 () input (uint64_to_uint32 pos) in
if y `U32.lt` 16777216ul
then validator_error_generic
else v
inline_for_extraction
let jump_der_length_payload32
(x: U8.t { der_length_payload_size_of_tag x <= 4 } )
: Tot (jumper (parse_der_length_payload32 x))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_facts (parse_der_length_payload32 x) h input pos;
parse_der_length_payload32_unfold x (bytes_of_slice_from h input pos);
assert_norm (pow2 (8 * 1) == 256);
assert_norm (pow2 (8 * 2) == 65536);
assert_norm (pow2 (8 * 3) == 16777216);
assert_norm (pow2 (8 * 4) == 4294967296)
in
if x `U8.lt` 128uy
then pos
else
[@inline_let]
let len = x `U8.sub` 128uy in
[@inline_let] let _ =
valid_facts parse_u8 h input pos;
parser_kind_prop_equiv parse_u8_kind parse_u8;
valid_facts (parse_bounded_integer (U8.v len)) h input pos;
parser_kind_prop_equiv (parse_bounded_integer_kind (U8.v len)) (parse_bounded_integer (U8.v len))
in
pos `U32.add` Cast.uint8_to_uint32 len
inline_for_extraction
let read_der_length_payload32
(x: U8.t { der_length_payload_size_of_tag x <= 4 } )
: Tot (leaf_reader (parse_der_length_payload32 x))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_facts (parse_der_length_payload32 x) h input pos;
parse_der_length_payload32_unfold x (bytes_of_slice_from h input pos);
assert_norm (pow2 (8 * 1) == 256);
assert_norm (pow2 (8 * 2) == 65536);
assert_norm (pow2 (8 * 3) == 16777216);
assert_norm (pow2 (8 * 4) == 4294967296)
in
if x `U8.lt` 128uy
then
[@inline_let]
let res = Cast.uint8_to_uint32 x in
[@inline_let] let _ = assert (tag_of_der_length32 res == x) in
(res <: refine_with_tag tag_of_der_length32 x)
else if x = 129uy
then
[@inline_let] let _ = valid_facts parse_u8 h input pos in
let z = read_u8 input pos in
[@inline_let] let res = Cast.uint8_to_uint32 z in
[@inline_let] let _ = assert (tag_of_der_length32 res == x) in
(res <: refine_with_tag tag_of_der_length32 x)
else
let len = x `U8.sub` 128uy in
[@inline_let] let _ = valid_facts (parse_bounded_integer (U8.v len)) h input pos in
if len = 2uy
then
let res = read_bounded_integer_2 () input pos in
[@inline_let] let _ = assert (tag_of_der_length32 res == x) in
(res <: refine_with_tag tag_of_der_length32 x)
else if len = 3uy
then
let res = read_bounded_integer_3 () input pos in
[@inline_let] let _ = assert (tag_of_der_length32 res == x) in
(res <: refine_with_tag tag_of_der_length32 x)
else
let res = read_bounded_integer_4 () input pos in
[@inline_let] let _ = assert (tag_of_der_length32 res == x) in
(res <: refine_with_tag tag_of_der_length32 x)
inline_for_extraction
let validate_bounded_der_length32
(vmin: der_length_t)
(min: U32.t { U32.v min == vmin } )
(vmax: der_length_t)
(max: U32.t { U32.v max == vmax /\ U32.v min <= U32.v max } )
: Tot (
validator (parse_bounded_der_length32 (vmin) (vmax)))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ =
valid_facts (parse_bounded_der_length32 (U32.v min) (U32.v max)) h input (uint64_to_uint32 pos);
parse_bounded_der_length32_unfold (U32.v min) (U32.v max) (bytes_of_slice_from h input (uint64_to_uint32 pos));
valid_facts parse_u8 h input (uint64_to_uint32 pos)
in
let v = validate_u8 () input pos in
if is_error v
then v
else
let x = read_u8 input (uint64_to_uint32 pos) in
let len = der_length_payload_size_of_tag8 x in
let tg1 = tag_of_der_length32_impl min in
let l1 = der_length_payload_size_of_tag8 tg1 in
let tg2 = tag_of_der_length32_impl max in
let l2 = der_length_payload_size_of_tag8 tg2 in
if (len `U8.lt` l1) || ( l2 `U8.lt` len)
then validator_error_generic
else
[@inline_let] let _ = valid_facts (parse_der_length_payload32 x) h input (uint64_to_uint32 v) in
let v2 = validate_der_length_payload32 x input v in
if is_error v2
then v2
else
let y = read_der_length_payload32 x input (uint64_to_uint32 v) in
if y `U32.lt` min || max `U32.lt` y
then validator_error_generic
else v2
inline_for_extraction
let jump_bounded_der_length32
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
: Tot (
jumper (parse_bounded_der_length32 (vmin) (vmax)))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ =
valid_facts (parse_bounded_der_length32 (vmin) (vmax)) h input pos;
parse_bounded_der_length32_unfold (vmin) (vmax) (bytes_of_slice_from h input pos);
valid_facts parse_u8 h input pos
in
let v = jump_u8 input pos in
let x = read_u8 input pos in
let len = der_length_payload_size_of_tag8 x in
[@inline_let] let _ = valid_facts (parse_der_length_payload32 x) h input v in
jump_der_length_payload32 x input v
inline_for_extraction
let read_bounded_der_length32
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
: Tot (
leaf_reader (parse_bounded_der_length32 (vmin) (vmax)))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ =
valid_facts (parse_bounded_der_length32 (vmin) (vmax)) h input pos;
parse_bounded_der_length32_unfold (vmin) (vmax) (bytes_of_slice_from h input pos);
valid_facts parse_u8 h input pos
in
let v = jump_u8 input pos in
let x = read_u8 input pos in
let len = der_length_payload_size_of_tag8 x in
[@inline_let] let _ = valid_facts (parse_der_length_payload32 x) h input v in
let y = read_der_length_payload32 x input v in
(y <: bounded_int32 (vmin) (vmax))
#pop-options
#push-options "--z3rlimit 64"
inline_for_extraction
let serialize32_bounded_der_length32'
(min: der_length_t)
(max: der_length_t { min <= max /\ max < 4294967296 } )
(y' : bounded_int32 (min) (max))
(#rrel #rel: _)
(b: B.mbuffer U8.t rrel rel)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
let len = Seq.length (serialize (serialize_bounded_der_length32 ( min) (max)) y') in
B.live h b /\
U32.v pos + len <= B.length b /\
writable b (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h len h' ->
let sx = serialize (serialize_bounded_der_length32 (min) (max)) y' in
Seq.length sx == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` sx
)))
= [@inline_let]
let gpos = Ghost.hide (U32.v pos) in
[@inline_let]
let gpos' = Ghost.hide (U32.v pos + Seq.length (serialize (serialize_bounded_der_length32 min max) y')) in
[@inline_let]
let _ =
serialize_bounded_der_length32_unfold (min) (max) y'
in
let x = tag_of_der_length32_impl y' in
if x `U8.lt` 128uy
then begin
mbuffer_upd b gpos gpos' pos x;
1ul
end else
if x = 129uy
then begin
mbuffer_upd b gpos gpos' pos x;
mbuffer_upd b gpos gpos' (pos `U32.add` 1ul) (Cast.uint32_to_uint8 y');
2ul
end else
if x = 130uy
then begin
mbuffer_upd b gpos gpos' pos x;
let h = HST.get () in
writable_weaken b (Ghost.reveal gpos) (Ghost.reveal gpos') h (U32.v pos + 1) (U32.v pos + 3);
let z = serialize32_bounded_integer_2 () y' b (pos `U32.add` 1ul) in
let h' = HST.get () in
Seq.lemma_split (Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + 3)) 1;
B.modifies_buffer_from_to_elim b pos (pos `U32.add` 1ul) (B.loc_buffer_from_to b (pos `U32.add` 1ul) (pos `U32.add` 3ul)) h h' ;
3ul // 1ul `U32.add` z
end else
if x = 131uy
then begin
mbuffer_upd b gpos gpos' pos x;
let h = HST.get () in
writable_weaken b (Ghost.reveal gpos) (Ghost.reveal gpos') h (U32.v pos + 1) (U32.v pos + 4);
let z = serialize32_bounded_integer_3 () y' b (pos `U32.add` 1ul) in
let h' = HST.get () in
Seq.lemma_split (Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + 4)) 1;
B.modifies_buffer_from_to_elim b pos (pos `U32.add` 1ul) (B.loc_buffer_from_to b (pos `U32.add` 1ul) (pos `U32.add` 4ul)) h h' ;
4ul // 1ul `U32.add` z
end else begin
mbuffer_upd b gpos gpos' pos x;
let h = HST.get () in
writable_weaken b (Ghost.reveal gpos) (Ghost.reveal gpos') h (U32.v pos + 1) (U32.v pos + 5);
let z = serialize32_bounded_integer_4 () y' b (pos `U32.add` 1ul) in
let h' = HST.get () in
Seq.lemma_split (Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + 5)) 1;
B.modifies_buffer_from_to_elim b pos (pos `U32.add` 1ul) (B.loc_buffer_from_to b (pos `U32.add` 1ul) (pos `U32.add` 5ul)) h h' ;
5ul // 1ul `U32.add` z
end
#pop-options | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.DER.fsti.checked",
"LowParse.Low.Int.fsti.checked",
"LowParse.Low.BoundedInt.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.DER.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.BoundedInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Int",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.DER",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.arith.nl=false"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
vmin: LowParse.Spec.DER.der_length_t ->
vmax: LowParse.Spec.DER.der_length_t{vmin <= vmax /\ vmax < 4294967296}
-> LowParse.Low.Base.serializer32 (LowParse.Spec.DER.serialize_bounded_der_length32 vmin vmax) | Prims.Tot | [
"total"
] | [] | [
"LowParse.Spec.DER.der_length_t",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"LowParse.Spec.BoundedInt.bounded_int32",
"LowStar.Monotonic.Buffer.srel",
"LowParse.Bytes.byte",
"LowStar.Monotonic.Buffer.mbuffer",
"FStar.UInt32.t",
"LowParse.Low.DER.serialize32_bounded_der_length32'",
"LowParse.Low.Base.serializer32",
"LowParse.Spec.DER.parse_bounded_der_length32_kind",
"LowParse.Spec.DER.parse_bounded_der_length32",
"LowParse.Spec.DER.serialize_bounded_der_length32"
] | [] | false | false | false | false | false | let serialize32_bounded_der_length32
(vmin: der_length_t)
(vmax: der_length_t{vmin <= vmax /\ vmax < 4294967296})
: Tot (serializer32 (serialize_bounded_der_length32 (vmin) (vmax))) =
| fun (y': bounded_int32 (vmin) (vmax)) #rrel #rel b pos ->
serialize32_bounded_der_length32' vmin vmax y' b pos | false |
LowParse.Low.DER.fst | LowParse.Low.DER.read_der_length_payload32 | val read_der_length_payload32 (x: U8.t{der_length_payload_size_of_tag x <= 4})
: Tot (leaf_reader (parse_der_length_payload32 x)) | val read_der_length_payload32 (x: U8.t{der_length_payload_size_of_tag x <= 4})
: Tot (leaf_reader (parse_der_length_payload32 x)) | let read_der_length_payload32
(x: U8.t { der_length_payload_size_of_tag x <= 4 } )
: Tot (leaf_reader (parse_der_length_payload32 x))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_facts (parse_der_length_payload32 x) h input pos;
parse_der_length_payload32_unfold x (bytes_of_slice_from h input pos);
assert_norm (pow2 (8 * 1) == 256);
assert_norm (pow2 (8 * 2) == 65536);
assert_norm (pow2 (8 * 3) == 16777216);
assert_norm (pow2 (8 * 4) == 4294967296)
in
if x `U8.lt` 128uy
then
[@inline_let]
let res = Cast.uint8_to_uint32 x in
[@inline_let] let _ = assert (tag_of_der_length32 res == x) in
(res <: refine_with_tag tag_of_der_length32 x)
else if x = 129uy
then
[@inline_let] let _ = valid_facts parse_u8 h input pos in
let z = read_u8 input pos in
[@inline_let] let res = Cast.uint8_to_uint32 z in
[@inline_let] let _ = assert (tag_of_der_length32 res == x) in
(res <: refine_with_tag tag_of_der_length32 x)
else
let len = x `U8.sub` 128uy in
[@inline_let] let _ = valid_facts (parse_bounded_integer (U8.v len)) h input pos in
if len = 2uy
then
let res = read_bounded_integer_2 () input pos in
[@inline_let] let _ = assert (tag_of_der_length32 res == x) in
(res <: refine_with_tag tag_of_der_length32 x)
else if len = 3uy
then
let res = read_bounded_integer_3 () input pos in
[@inline_let] let _ = assert (tag_of_der_length32 res == x) in
(res <: refine_with_tag tag_of_der_length32 x)
else
let res = read_bounded_integer_4 () input pos in
[@inline_let] let _ = assert (tag_of_der_length32 res == x) in
(res <: refine_with_tag tag_of_der_length32 x) | {
"file_name": "src/lowparse/LowParse.Low.DER.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 54,
"end_line": 151,
"start_col": 0,
"start_line": 109
} | module LowParse.Low.DER
include LowParse.Spec.DER
include LowParse.Low.Int // for parse_u8
include LowParse.Low.BoundedInt // for bounded_integer
open FStar.Mul
module U8 = FStar.UInt8
module U32 = FStar.UInt32
module HST = FStar.HyperStack.ST
module B = LowStar.Buffer
module Cast = FStar.Int.Cast
module U64 = FStar.UInt64
#reset-options "--z3cliopt smt.arith.nl=false --max_fuel 0 --max_ifuel 0"
#push-options "--z3rlimit 32"
inline_for_extraction
let validate_der_length_payload32
(x: U8.t { der_length_payload_size_of_tag x <= 4 } )
: Tot (validator (parse_der_length_payload32 x))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_facts (parse_der_length_payload32 x) h input (uint64_to_uint32 pos);
assert (U64.v pos <= U32.v input.len);
parse_der_length_payload32_unfold x (bytes_of_slice_from h input (uint64_to_uint32 pos));
assert_norm (pow2 (8 * 1) == 256);
assert_norm (pow2 (8 * 2) == 65536);
assert_norm (pow2 (8 * 3) == 16777216);
assert_norm (pow2 (8 * 4) == 4294967296)
in
if x `U8.lt` 128uy
then pos
else if x = 128uy || x = 255uy
then validator_error_generic
else if x = 129uy
then
[@inline_let] let _ = valid_facts parse_u8 h input (uint64_to_uint32 pos) in
let v = validate_u8 () input pos in
if is_error v
then v
else
let z = read_u8 input (uint64_to_uint32 pos) in
if z `U8.lt` 128uy
then validator_error_generic
else v
else
let len = x `U8.sub` 128uy in
[@inline_let] let _ = valid_facts (parse_bounded_integer (U8.v len)) h input (uint64_to_uint32 pos) in
if len = 2uy
then
let v = validate_bounded_integer 2 input pos in
if is_error v
then v
else
let y = read_bounded_integer_2 () input (uint64_to_uint32 pos) in
if y `U32.lt `256ul
then validator_error_generic
else v
else if len = 3uy
then
let v = validate_bounded_integer 3 input pos in
if is_error v
then v
else
let y = read_bounded_integer_3 () input (uint64_to_uint32 pos) in
if y `U32.lt `65536ul
then validator_error_generic
else v
else
let v = validate_bounded_integer 4 input pos in
if is_error v
then v
else
let y = read_bounded_integer_4 () input (uint64_to_uint32 pos) in
if y `U32.lt` 16777216ul
then validator_error_generic
else v
inline_for_extraction
let jump_der_length_payload32
(x: U8.t { der_length_payload_size_of_tag x <= 4 } )
: Tot (jumper (parse_der_length_payload32 x))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_facts (parse_der_length_payload32 x) h input pos;
parse_der_length_payload32_unfold x (bytes_of_slice_from h input pos);
assert_norm (pow2 (8 * 1) == 256);
assert_norm (pow2 (8 * 2) == 65536);
assert_norm (pow2 (8 * 3) == 16777216);
assert_norm (pow2 (8 * 4) == 4294967296)
in
if x `U8.lt` 128uy
then pos
else
[@inline_let]
let len = x `U8.sub` 128uy in
[@inline_let] let _ =
valid_facts parse_u8 h input pos;
parser_kind_prop_equiv parse_u8_kind parse_u8;
valid_facts (parse_bounded_integer (U8.v len)) h input pos;
parser_kind_prop_equiv (parse_bounded_integer_kind (U8.v len)) (parse_bounded_integer (U8.v len))
in
pos `U32.add` Cast.uint8_to_uint32 len | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.DER.fsti.checked",
"LowParse.Low.Int.fsti.checked",
"LowParse.Low.BoundedInt.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.DER.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.BoundedInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Int",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.DER",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.arith.nl=false"
],
"z3refresh": false,
"z3rlimit": 32,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: FStar.UInt8.t{LowParse.Spec.DER.der_length_payload_size_of_tag x <= 4}
-> LowParse.Low.Base.leaf_reader (LowParse.Spec.DER.parse_der_length_payload32 x) | Prims.Tot | [
"total"
] | [] | [
"FStar.UInt8.t",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"LowParse.Spec.DER.der_length_payload_size_of_tag",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"FStar.UInt8.lt",
"FStar.UInt8.__uint_to_t",
"LowParse.Spec.Base.refine_with_tag",
"LowParse.Spec.DER.tag_of_der_length32",
"Prims.unit",
"Prims._assert",
"Prims.eq2",
"Prims.op_Equality",
"Prims.int",
"Prims.l_or",
"FStar.UInt.size",
"FStar.UInt32.v",
"FStar.UInt8.v",
"FStar.Int.Cast.uint8_to_uint32",
"Prims.bool",
"LowParse.Low.Int.read_u8",
"LowParse.Low.Base.Spec.valid_facts",
"LowParse.Spec.Int.parse_u8_kind",
"LowParse.Spec.Int.parse_u8",
"LowParse.Spec.BoundedInt.bounded_integer",
"LowParse.Low.BoundedInt.read_bounded_integer_2",
"LowParse.Low.BoundedInt.read_bounded_integer_3",
"LowParse.Low.BoundedInt.read_bounded_integer_4",
"LowParse.Spec.BoundedInt.parse_bounded_integer_kind",
"LowParse.Spec.BoundedInt.parse_bounded_integer",
"FStar.UInt8.sub",
"FStar.Pervasives.assert_norm",
"Prims.pow2",
"FStar.Mul.op_Star",
"LowParse.Spec.DER.parse_der_length_payload32_unfold",
"LowParse.Slice.bytes_of_slice_from",
"LowParse.Spec.DER.parse_der_length_payload_kind",
"LowParse.Spec.DER.parse_der_length_payload32",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"LowParse.Low.Base.leaf_reader"
] | [] | false | false | false | false | false | let read_der_length_payload32 (x: U8.t{der_length_payload_size_of_tag x <= 4})
: Tot (leaf_reader (parse_der_length_payload32 x)) =
| fun #rrel #rel input pos ->
let h = HST.get () in
[@@ inline_let ]let _ =
valid_facts (parse_der_length_payload32 x) h input pos;
parse_der_length_payload32_unfold x (bytes_of_slice_from h input pos);
assert_norm (pow2 (8 * 1) == 256);
assert_norm (pow2 (8 * 2) == 65536);
assert_norm (pow2 (8 * 3) == 16777216);
assert_norm (pow2 (8 * 4) == 4294967296)
in
if x `U8.lt` 128uy
then
[@@ inline_let ]let res = Cast.uint8_to_uint32 x in
[@@ inline_let ]let _ = assert (tag_of_der_length32 res == x) in
(res <: refine_with_tag tag_of_der_length32 x)
else
if x = 129uy
then
[@@ inline_let ]let _ = valid_facts parse_u8 h input pos in
let z = read_u8 input pos in
[@@ inline_let ]let res = Cast.uint8_to_uint32 z in
[@@ inline_let ]let _ = assert (tag_of_der_length32 res == x) in
(res <: refine_with_tag tag_of_der_length32 x)
else
let len = x `U8.sub` 128uy in
[@@ inline_let ]let _ = valid_facts (parse_bounded_integer (U8.v len)) h input pos in
if len = 2uy
then
let res = read_bounded_integer_2 () input pos in
[@@ inline_let ]let _ = assert (tag_of_der_length32 res == x) in
(res <: refine_with_tag tag_of_der_length32 x)
else
if len = 3uy
then
let res = read_bounded_integer_3 () input pos in
[@@ inline_let ]let _ = assert (tag_of_der_length32 res == x) in
(res <: refine_with_tag tag_of_der_length32 x)
else
let res = read_bounded_integer_4 () input pos in
[@@ inline_let ]let _ = assert (tag_of_der_length32 res == x) in
(res <: refine_with_tag tag_of_der_length32 x) | false |
LowParse.Low.DER.fst | LowParse.Low.DER.write_bounded_der_length32 | val write_bounded_der_length32
(vmin: der_length_t)
(vmax: der_length_t{vmin <= vmax /\ vmax < 4294967296})
: Tot (leaf_writer_strong (serialize_bounded_der_length32 (vmin) (vmax))) | val write_bounded_der_length32
(vmin: der_length_t)
(vmax: der_length_t{vmin <= vmax /\ vmax < 4294967296})
: Tot (leaf_writer_strong (serialize_bounded_der_length32 (vmin) (vmax))) | let write_bounded_der_length32
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
: Tot (leaf_writer_strong (serialize_bounded_der_length32 (vmin) (vmax)))
= leaf_writer_strong_of_serializer32 (serialize32_bounded_der_length32 vmin vmax) () | {
"file_name": "src/lowparse/LowParse.Low.DER.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 84,
"end_line": 326,
"start_col": 0,
"start_line": 322
} | module LowParse.Low.DER
include LowParse.Spec.DER
include LowParse.Low.Int // for parse_u8
include LowParse.Low.BoundedInt // for bounded_integer
open FStar.Mul
module U8 = FStar.UInt8
module U32 = FStar.UInt32
module HST = FStar.HyperStack.ST
module B = LowStar.Buffer
module Cast = FStar.Int.Cast
module U64 = FStar.UInt64
#reset-options "--z3cliopt smt.arith.nl=false --max_fuel 0 --max_ifuel 0"
#push-options "--z3rlimit 32"
inline_for_extraction
let validate_der_length_payload32
(x: U8.t { der_length_payload_size_of_tag x <= 4 } )
: Tot (validator (parse_der_length_payload32 x))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_facts (parse_der_length_payload32 x) h input (uint64_to_uint32 pos);
assert (U64.v pos <= U32.v input.len);
parse_der_length_payload32_unfold x (bytes_of_slice_from h input (uint64_to_uint32 pos));
assert_norm (pow2 (8 * 1) == 256);
assert_norm (pow2 (8 * 2) == 65536);
assert_norm (pow2 (8 * 3) == 16777216);
assert_norm (pow2 (8 * 4) == 4294967296)
in
if x `U8.lt` 128uy
then pos
else if x = 128uy || x = 255uy
then validator_error_generic
else if x = 129uy
then
[@inline_let] let _ = valid_facts parse_u8 h input (uint64_to_uint32 pos) in
let v = validate_u8 () input pos in
if is_error v
then v
else
let z = read_u8 input (uint64_to_uint32 pos) in
if z `U8.lt` 128uy
then validator_error_generic
else v
else
let len = x `U8.sub` 128uy in
[@inline_let] let _ = valid_facts (parse_bounded_integer (U8.v len)) h input (uint64_to_uint32 pos) in
if len = 2uy
then
let v = validate_bounded_integer 2 input pos in
if is_error v
then v
else
let y = read_bounded_integer_2 () input (uint64_to_uint32 pos) in
if y `U32.lt `256ul
then validator_error_generic
else v
else if len = 3uy
then
let v = validate_bounded_integer 3 input pos in
if is_error v
then v
else
let y = read_bounded_integer_3 () input (uint64_to_uint32 pos) in
if y `U32.lt `65536ul
then validator_error_generic
else v
else
let v = validate_bounded_integer 4 input pos in
if is_error v
then v
else
let y = read_bounded_integer_4 () input (uint64_to_uint32 pos) in
if y `U32.lt` 16777216ul
then validator_error_generic
else v
inline_for_extraction
let jump_der_length_payload32
(x: U8.t { der_length_payload_size_of_tag x <= 4 } )
: Tot (jumper (parse_der_length_payload32 x))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_facts (parse_der_length_payload32 x) h input pos;
parse_der_length_payload32_unfold x (bytes_of_slice_from h input pos);
assert_norm (pow2 (8 * 1) == 256);
assert_norm (pow2 (8 * 2) == 65536);
assert_norm (pow2 (8 * 3) == 16777216);
assert_norm (pow2 (8 * 4) == 4294967296)
in
if x `U8.lt` 128uy
then pos
else
[@inline_let]
let len = x `U8.sub` 128uy in
[@inline_let] let _ =
valid_facts parse_u8 h input pos;
parser_kind_prop_equiv parse_u8_kind parse_u8;
valid_facts (parse_bounded_integer (U8.v len)) h input pos;
parser_kind_prop_equiv (parse_bounded_integer_kind (U8.v len)) (parse_bounded_integer (U8.v len))
in
pos `U32.add` Cast.uint8_to_uint32 len
inline_for_extraction
let read_der_length_payload32
(x: U8.t { der_length_payload_size_of_tag x <= 4 } )
: Tot (leaf_reader (parse_der_length_payload32 x))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_facts (parse_der_length_payload32 x) h input pos;
parse_der_length_payload32_unfold x (bytes_of_slice_from h input pos);
assert_norm (pow2 (8 * 1) == 256);
assert_norm (pow2 (8 * 2) == 65536);
assert_norm (pow2 (8 * 3) == 16777216);
assert_norm (pow2 (8 * 4) == 4294967296)
in
if x `U8.lt` 128uy
then
[@inline_let]
let res = Cast.uint8_to_uint32 x in
[@inline_let] let _ = assert (tag_of_der_length32 res == x) in
(res <: refine_with_tag tag_of_der_length32 x)
else if x = 129uy
then
[@inline_let] let _ = valid_facts parse_u8 h input pos in
let z = read_u8 input pos in
[@inline_let] let res = Cast.uint8_to_uint32 z in
[@inline_let] let _ = assert (tag_of_der_length32 res == x) in
(res <: refine_with_tag tag_of_der_length32 x)
else
let len = x `U8.sub` 128uy in
[@inline_let] let _ = valid_facts (parse_bounded_integer (U8.v len)) h input pos in
if len = 2uy
then
let res = read_bounded_integer_2 () input pos in
[@inline_let] let _ = assert (tag_of_der_length32 res == x) in
(res <: refine_with_tag tag_of_der_length32 x)
else if len = 3uy
then
let res = read_bounded_integer_3 () input pos in
[@inline_let] let _ = assert (tag_of_der_length32 res == x) in
(res <: refine_with_tag tag_of_der_length32 x)
else
let res = read_bounded_integer_4 () input pos in
[@inline_let] let _ = assert (tag_of_der_length32 res == x) in
(res <: refine_with_tag tag_of_der_length32 x)
inline_for_extraction
let validate_bounded_der_length32
(vmin: der_length_t)
(min: U32.t { U32.v min == vmin } )
(vmax: der_length_t)
(max: U32.t { U32.v max == vmax /\ U32.v min <= U32.v max } )
: Tot (
validator (parse_bounded_der_length32 (vmin) (vmax)))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ =
valid_facts (parse_bounded_der_length32 (U32.v min) (U32.v max)) h input (uint64_to_uint32 pos);
parse_bounded_der_length32_unfold (U32.v min) (U32.v max) (bytes_of_slice_from h input (uint64_to_uint32 pos));
valid_facts parse_u8 h input (uint64_to_uint32 pos)
in
let v = validate_u8 () input pos in
if is_error v
then v
else
let x = read_u8 input (uint64_to_uint32 pos) in
let len = der_length_payload_size_of_tag8 x in
let tg1 = tag_of_der_length32_impl min in
let l1 = der_length_payload_size_of_tag8 tg1 in
let tg2 = tag_of_der_length32_impl max in
let l2 = der_length_payload_size_of_tag8 tg2 in
if (len `U8.lt` l1) || ( l2 `U8.lt` len)
then validator_error_generic
else
[@inline_let] let _ = valid_facts (parse_der_length_payload32 x) h input (uint64_to_uint32 v) in
let v2 = validate_der_length_payload32 x input v in
if is_error v2
then v2
else
let y = read_der_length_payload32 x input (uint64_to_uint32 v) in
if y `U32.lt` min || max `U32.lt` y
then validator_error_generic
else v2
inline_for_extraction
let jump_bounded_der_length32
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
: Tot (
jumper (parse_bounded_der_length32 (vmin) (vmax)))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ =
valid_facts (parse_bounded_der_length32 (vmin) (vmax)) h input pos;
parse_bounded_der_length32_unfold (vmin) (vmax) (bytes_of_slice_from h input pos);
valid_facts parse_u8 h input pos
in
let v = jump_u8 input pos in
let x = read_u8 input pos in
let len = der_length_payload_size_of_tag8 x in
[@inline_let] let _ = valid_facts (parse_der_length_payload32 x) h input v in
jump_der_length_payload32 x input v
inline_for_extraction
let read_bounded_der_length32
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
: Tot (
leaf_reader (parse_bounded_der_length32 (vmin) (vmax)))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ =
valid_facts (parse_bounded_der_length32 (vmin) (vmax)) h input pos;
parse_bounded_der_length32_unfold (vmin) (vmax) (bytes_of_slice_from h input pos);
valid_facts parse_u8 h input pos
in
let v = jump_u8 input pos in
let x = read_u8 input pos in
let len = der_length_payload_size_of_tag8 x in
[@inline_let] let _ = valid_facts (parse_der_length_payload32 x) h input v in
let y = read_der_length_payload32 x input v in
(y <: bounded_int32 (vmin) (vmax))
#pop-options
#push-options "--z3rlimit 64"
inline_for_extraction
let serialize32_bounded_der_length32'
(min: der_length_t)
(max: der_length_t { min <= max /\ max < 4294967296 } )
(y' : bounded_int32 (min) (max))
(#rrel #rel: _)
(b: B.mbuffer U8.t rrel rel)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
let len = Seq.length (serialize (serialize_bounded_der_length32 ( min) (max)) y') in
B.live h b /\
U32.v pos + len <= B.length b /\
writable b (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h len h' ->
let sx = serialize (serialize_bounded_der_length32 (min) (max)) y' in
Seq.length sx == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` sx
)))
= [@inline_let]
let gpos = Ghost.hide (U32.v pos) in
[@inline_let]
let gpos' = Ghost.hide (U32.v pos + Seq.length (serialize (serialize_bounded_der_length32 min max) y')) in
[@inline_let]
let _ =
serialize_bounded_der_length32_unfold (min) (max) y'
in
let x = tag_of_der_length32_impl y' in
if x `U8.lt` 128uy
then begin
mbuffer_upd b gpos gpos' pos x;
1ul
end else
if x = 129uy
then begin
mbuffer_upd b gpos gpos' pos x;
mbuffer_upd b gpos gpos' (pos `U32.add` 1ul) (Cast.uint32_to_uint8 y');
2ul
end else
if x = 130uy
then begin
mbuffer_upd b gpos gpos' pos x;
let h = HST.get () in
writable_weaken b (Ghost.reveal gpos) (Ghost.reveal gpos') h (U32.v pos + 1) (U32.v pos + 3);
let z = serialize32_bounded_integer_2 () y' b (pos `U32.add` 1ul) in
let h' = HST.get () in
Seq.lemma_split (Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + 3)) 1;
B.modifies_buffer_from_to_elim b pos (pos `U32.add` 1ul) (B.loc_buffer_from_to b (pos `U32.add` 1ul) (pos `U32.add` 3ul)) h h' ;
3ul // 1ul `U32.add` z
end else
if x = 131uy
then begin
mbuffer_upd b gpos gpos' pos x;
let h = HST.get () in
writable_weaken b (Ghost.reveal gpos) (Ghost.reveal gpos') h (U32.v pos + 1) (U32.v pos + 4);
let z = serialize32_bounded_integer_3 () y' b (pos `U32.add` 1ul) in
let h' = HST.get () in
Seq.lemma_split (Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + 4)) 1;
B.modifies_buffer_from_to_elim b pos (pos `U32.add` 1ul) (B.loc_buffer_from_to b (pos `U32.add` 1ul) (pos `U32.add` 4ul)) h h' ;
4ul // 1ul `U32.add` z
end else begin
mbuffer_upd b gpos gpos' pos x;
let h = HST.get () in
writable_weaken b (Ghost.reveal gpos) (Ghost.reveal gpos') h (U32.v pos + 1) (U32.v pos + 5);
let z = serialize32_bounded_integer_4 () y' b (pos `U32.add` 1ul) in
let h' = HST.get () in
Seq.lemma_split (Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + 5)) 1;
B.modifies_buffer_from_to_elim b pos (pos `U32.add` 1ul) (B.loc_buffer_from_to b (pos `U32.add` 1ul) (pos `U32.add` 5ul)) h h' ;
5ul // 1ul `U32.add` z
end
#pop-options
inline_for_extraction
let serialize32_bounded_der_length32
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
: Tot (serializer32 (serialize_bounded_der_length32 (vmin) (vmax)))
= fun (y' : bounded_int32 (vmin) (vmax)) #rrel #rel b pos ->
serialize32_bounded_der_length32' vmin vmax y' b pos | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.DER.fsti.checked",
"LowParse.Low.Int.fsti.checked",
"LowParse.Low.BoundedInt.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.DER.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.BoundedInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Int",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.DER",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.arith.nl=false"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
vmin: LowParse.Spec.DER.der_length_t ->
vmax: LowParse.Spec.DER.der_length_t{vmin <= vmax /\ vmax < 4294967296}
-> LowParse.Low.Base.leaf_writer_strong (LowParse.Spec.DER.serialize_bounded_der_length32 vmin
vmax) | Prims.Tot | [
"total"
] | [] | [
"LowParse.Spec.DER.der_length_t",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"LowParse.Low.Base.leaf_writer_strong_of_serializer32",
"LowParse.Spec.DER.parse_bounded_der_length32_kind",
"LowParse.Spec.BoundedInt.bounded_int32",
"LowParse.Spec.DER.parse_bounded_der_length32",
"LowParse.Spec.DER.serialize_bounded_der_length32",
"LowParse.Low.DER.serialize32_bounded_der_length32",
"LowParse.Low.Base.leaf_writer_strong"
] | [] | false | false | false | false | false | let write_bounded_der_length32
(vmin: der_length_t)
(vmax: der_length_t{vmin <= vmax /\ vmax < 4294967296})
: Tot (leaf_writer_strong (serialize_bounded_der_length32 (vmin) (vmax))) =
| leaf_writer_strong_of_serializer32 (serialize32_bounded_der_length32 vmin vmax) () | false |
Hacl.Spec.BignumQ.Lemmas.fst | Hacl.Spec.BignumQ.Lemmas.lemma_optimized_barrett_reduce | val lemma_optimized_barrett_reduce:
a:nat{a < pow2 512} ->
Lemma (a - (((a / pow2 248) * (pow2 512 / S.q)) / pow2 264) * S.q < 2 * S.q
/\ a - (((a / pow2 248) * (pow2 512 / S.q)) / pow2 264) * S.q >= 0) | val lemma_optimized_barrett_reduce:
a:nat{a < pow2 512} ->
Lemma (a - (((a / pow2 248) * (pow2 512 / S.q)) / pow2 264) * S.q < 2 * S.q
/\ a - (((a / pow2 248) * (pow2 512 / S.q)) / pow2 264) * S.q >= 0) | let lemma_optimized_barrett_reduce a =
assert_norm (pow2 248 = 0x100000000000000000000000000000000000000000000000000000000000000);
assert_norm (pow2 264 = 0x1000000000000000000000000000000000000000000000000000000000000000000);
assert_norm (S.q == 0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed);
assert_norm (0x100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 == pow2 512) | {
"file_name": "code/ed25519/Hacl.Spec.BignumQ.Lemmas.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 159,
"end_line": 821,
"start_col": 0,
"start_line": 817
} | module Hacl.Spec.BignumQ.Lemmas
open FStar.Tactics.CanonCommSemiring
open FStar.Mul
open Lib.IntTypes
module S = Spec.Ed25519
include Hacl.Spec.BignumQ.Definitions
let feq (#a #b:Type) (f:(a -> b)) (x y:a) :
Lemma (requires x == y) (ensures f x == f y) = ()
let eq_eq2 (#a:eqtype) (x y:a) :
Lemma (requires x = y) (ensures x == y) = ()
val lemma_mul_lt:a:nat -> b:nat -> c:nat -> d:nat ->
Lemma
(requires a < b /\ c < d)
(ensures a * c < b * d)
let lemma_mul_lt a b c d = ()
val lemma_as_nat5: f:qelem5 ->
Lemma
(requires qelem_fits5 f (1, 1, 1, 1, 1))
(ensures as_nat5 f < pow2 280)
let lemma_as_nat5 f =
//let (f0, f1, f2, f3, f4) = f in
//assert (as_nat5 f == v f0 + v f1 * pow56 + v f2 * pow112 + v f3 * pow168 + v f4 * pow224);
assert_norm (pow2 56 * pow2 56 = pow2 112);
assert_norm (pow2 56 * pow2 112 = pow2 168);
assert_norm (pow2 56 * pow2 168 = pow2 224);
assert_norm (pow2 56 * pow2 224 = pow2 280)
val lemma_choose_step:
bit:uint64{v bit <= 1}
-> x:uint64
-> y:uint64
-> Lemma
(let mask = bit -. u64 1 in
let z = x ^. (mask &. (x ^. y)) in
if v bit = 1 then z == x else z == y)
let lemma_choose_step bit p1 p2 =
let mask = bit -. u64 1 in
assert (v bit == 0 ==> v mask == pow2 64 - 1);
assert (v bit == 1 ==> v mask == 0);
let dummy = mask &. (p1 ^. p2) in
logand_lemma mask (p1 ^. p2);
assert (v bit == 1 ==> v dummy == 0);
assert (v bit == 0 ==> v dummy == v (p1 ^. p2));
let p1' = p1 ^. dummy in
assert (v dummy == v (if v bit = 1 then u64 0 else (p1 ^. p2)));
logxor_lemma p1 p2
val lemma_subm_conditional:
x0:nat -> x1:nat -> x2:nat -> x3:nat -> x4:nat
-> y0:nat -> y1:nat -> y2:nat -> y3:nat -> y4:nat
-> b0:nat -> b1:nat -> b2:nat -> b3:nat -> b4:nat ->
Lemma (
x0 - y0 + b0 * pow2 56 +
(x1 - y1 - b0 + b1 * pow2 56) * pow2 56 +
(x2 - y2 - b1 + b2 * pow2 56) * pow2 112 +
(x3 - y3 - b2 + b3 * pow2 56) * pow2 168 +
(x4 - y4 - b3 + b4 * pow2 56) * pow2 224 ==
(x0 + x1 * pow2 56 + x2 * pow2 112 + x3 * pow2 168 + x4 * pow2 224) -
(y0 + y1 * pow2 56 + y2 * pow2 112 + y3 * pow2 168 + y4 * pow2 224) + b4 * pow2 280)
let lemma_subm_conditional x0 x1 x2 x3 x4 y0 y1 y2 y3 y4 b0 b1 b2 b3 b4 =
assert_norm (pow2 56 * pow2 56 = pow2 112);
assert_norm (pow2 56 * pow2 112 = pow2 168);
assert_norm (pow2 56 * pow2 168 = pow2 224);
assert_norm (pow2 56 * pow2 224 = pow2 280);
assert (
x0 - y0 + b0 * pow2 56 +
(x1 - y1 - b0 + b1 * pow2 56) * pow2 56 +
(x2 - y2 - b1 + b2 * pow2 56) * pow2 112 +
(x3 - y3 - b2 + b3 * pow2 56) * pow2 168 +
(x4 - y4 - b3 + b4 * pow2 56) * pow2 224 ==
(x0 + x1 * pow2 56 + x2 * pow2 112 + x3 * pow2 168 + x4 * pow2 224) -
(y0 + y1 * pow2 56 + y2 * pow2 112 + y3 * pow2 168 + y4 * pow2 224) + b4 * pow2 280)
by (int_semiring ());
()
val lemma_div224: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1))
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
wide_as_nat5 x / pow2 224 ==
v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280))
#push-options "--z3rlimit 50"
let lemma_div224 x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert
(wide_as_nat5 x ==
v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168 + v x4 * pow2 224 +
v x5 * pow2 280 + v x6 * pow2 336 + v x7 * pow2 392 + v x8 * pow2 448 + v x9 * pow2 504);
assert_norm (pow2 56 * pow2 224 == pow2 280);
assert_norm (pow2 112 * pow2 224 == pow2 336);
assert_norm (pow2 168 * pow2 224 == pow2 392);
assert_norm (pow2 224 * pow2 224 == pow2 448);
assert_norm (pow2 280 * pow2 224 == pow2 504);
calc (==) {
wide_as_nat5 x / pow2 224;
(==) { }
(v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168 +
(v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280) * pow2 224) / pow2 224;
(==) {
FStar.Math.Lemmas.lemma_div_plus
(v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168)
(v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280) (pow2 224) }
(v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168) / pow2 224 +
v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280;
(==) { FStar.Math.Lemmas.small_division_lemma_1 (v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168) (pow2 224) }
v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280;
}
#pop-options
val lemma_div248_aux: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 512)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
wide_as_nat5 x / pow2 248 ==
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256))
open FStar.Tactics.CanonCommSemiring
#push-options "--z3cliopt smt.arith.nl=false"
let lemma_div248_aux x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert_norm (pow2 248 == pow2 224 * pow2 24);
assert_norm (pow2 56 == pow2 32 * pow2 24);
assert_norm (pow2 112 == pow2 88 * pow2 24);
assert_norm (pow2 168 == pow2 144 * pow2 24);
assert_norm (pow2 224 == pow2 200 * pow2 24);
assert_norm (pow2 280 == pow2 256 * pow2 24);
assert_norm (0 < pow2 24);
calc (==) {
wide_as_nat5 x / pow2 248;
(==) { FStar.Math.Lemmas.division_multiplication_lemma (wide_as_nat5 x) (pow2 224) (pow2 24) }
(wide_as_nat5 x / pow2 224) / pow2 24;
(==) { lemma_div224 x }
(v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280) / pow2 24;
(==) { _ by (Tactics.mapply (`feq #int #int (fun x -> x / pow2 24)); int_semiring ()) } (v x4 + (v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256) * pow2 24) / pow2 24;
(==) { FStar.Math.Lemmas.lemma_div_plus (v x4) (v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256) (pow2 24) }
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256;
}
#pop-options
val lemma_div248_x5: x5:uint64 ->
Lemma ( pow2 32 * (v x5 % pow2 24) + v x5 / pow2 24 * pow2 56 == v x5 * pow2 32)
let lemma_div248_x5 x5 =
assert_norm (pow2 32 * pow2 24 = pow2 56)
val lemma_div248_x6: x6:uint64 ->
Lemma (pow2 32 * (v x6 % pow2 24) * pow2 56 + v x6 / pow2 24 * pow2 112 == v x6 * pow2 88)
let lemma_div248_x6 x6 =
calc (==) {
pow2 32 * (v x6 % pow2 24) * pow2 56 + v x6 / pow2 24 * pow2 112;
(==) { _ by (Tactics.norm [delta_only [`%pow2]; primops]; int_semiring ()) }
((v x6 / pow2 24) * pow2 24 + v x6 % pow2 24) * pow2 88;
(==) { FStar.Math.Lemmas.euclidean_division_definition (v x6) (pow2 24) }
v x6 * pow2 88;
}
val lemma_div248_x7: x7:uint64 ->
Lemma (pow2 32 * (v x7 % pow2 24) * pow2 112 + v x7 / pow2 24 * pow2 168 == v x7 * pow2 144)
let lemma_div248_x7 x7 =
calc (==) {
pow2 32 * (v x7 % pow2 24) * pow2 112 + v x7 / pow2 24 * pow2 168;
(==) { _ by (Tactics.norm [delta_only [`%pow2]; primops]; int_semiring ()) }
((v x7 / pow2 24) * pow2 24 + v x7 % pow2 24) * pow2 144;
(==) { FStar.Math.Lemmas.euclidean_division_definition (v x7) (pow2 24) }
v x7 * pow2 144;
}
val lemma_div248_x8: x8:uint64 ->
Lemma (pow2 32 * (v x8 % pow2 24) * pow2 168 + v x8 / pow2 24 * pow2 224 == v x8 * pow2 200)
let lemma_div248_x8 x8 =
calc (==) {
pow2 32 * (v x8 % pow2 24) * pow2 168 + v x8 / pow2 24 * pow2 224;
(==) { _ by (Tactics.norm [delta_only [`%pow2]; primops]; int_semiring ()) }
((v x8 / pow2 24) * pow2 24 + v x8 % pow2 24) * pow2 200;
(==) { FStar.Math.Lemmas.euclidean_division_definition (v x8) (pow2 24) }
v x8 * pow2 200;
}
val lemma_div248_x9: x9:uint64{v x9 < pow2 24} ->
Lemma (pow2 32 * (v x9 % pow2 24) * pow2 224 == v x9 * pow2 256)
let lemma_div248_x9 x9 =
calc (==) {
pow2 32 * (v x9 % pow2 24) * pow2 224;
(==) { Math.Lemmas.small_mod (v x9) (pow2 24) }
pow2 32 * v x9 * pow2 224;
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
v x9 * pow2 256;
}
val lemma_wide_as_nat_pow512: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 512)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
v x9 < pow2 24))
let lemma_wide_as_nat_pow512 x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert_norm (pow2 504 * pow2 8 = pow2 512);
FStar.Math.Lemmas.pow2_minus 512 504;
assert (v x9 < pow2 8);
assert_norm (pow2 8 < pow2 24)
val lemma_div248: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 512)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
let z0 = v x4 / pow2 24 + pow2 32 * (v x5 % pow2 24) in
let z1 = v x5 / pow2 24 + pow2 32 * (v x6 % pow2 24) in
let z2 = v x6 / pow2 24 + pow2 32 * (v x7 % pow2 24) in
let z3 = v x7 / pow2 24 + pow2 32 * (v x8 % pow2 24) in
let z4 = v x8 / pow2 24 + pow2 32 * (v x9 % pow2 24) in
wide_as_nat5 x / pow2 248 == z0 + z1 * pow2 56 + z2 * pow2 112 + z3 * pow2 168 + z4 * pow2 224))
#push-options "--z3rlimit 50"
let lemma_div248 x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
lemma_wide_as_nat_pow512 x;
assert (v x9 < pow2 24);
calc (==) {
(let z0 = v x4 / pow2 24 + pow2 32 * (v x5 % pow2 24) in
let z1 = v x5 / pow2 24 + pow2 32 * (v x6 % pow2 24) in
let z2 = v x6 / pow2 24 + pow2 32 * (v x7 % pow2 24) in
let z3 = v x7 / pow2 24 + pow2 32 * (v x8 % pow2 24) in
let z4 = v x8 / pow2 24 + pow2 32 * (v x9 % pow2 24) in
z0 + z1 * pow2 56 + z2 * pow2 112 + z3 * pow2 168 + z4 * pow2 224);
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
v x4 / pow2 24 + pow2 32 * (v x5 % pow2 24) +
v x5 / pow2 24 * pow2 56 + pow2 32 * (v x6 % pow2 24) * pow2 56 +
v x6 / pow2 24 * pow2 112 + pow2 32 * (v x7 % pow2 24) * pow2 112 +
v x7 / pow2 24 * pow2 168 + pow2 32 * (v x8 % pow2 24) * pow2 168 +
v x8 / pow2 24 * pow2 224 + pow2 32 * (v x9 % pow2 24) * pow2 224;
(==) { lemma_div248_x5 x5; lemma_div248_x6 x6 }
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 +
pow2 32 * (v x7 % pow2 24) * pow2 112 +
v x7 / pow2 24 * pow2 168 + pow2 32 * (v x8 % pow2 24) * pow2 168 +
v x8 / pow2 24 * pow2 224 + pow2 32 * (v x9 % pow2 24) * pow2 224;
(==) { lemma_div248_x7 x7; lemma_div248_x8 x8 }
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 +
pow2 32 * (v x9 % pow2 24) * pow2 224;
(==) { lemma_div248_x9 x9 }
v x4 / pow2 24 + v x5 * pow2 32 + v x6 * pow2 88 + v x7 * pow2 144 + v x8 * pow2 200 + v x9 * pow2 256;
(==) { lemma_div248_aux x }
wide_as_nat5 x / pow2 248;
}
#pop-options
val lemma_add_modq5:
x:qelem5
-> y:qelem5
-> t:qelem5 ->
Lemma
(requires
qelem_fits5 x (1, 1, 1, 1, 1) /\
qelem_fits5 y (1, 1, 1, 1, 1) /\
qelem_fits5 t (1, 1, 1, 1, 1) /\
as_nat5 x < S.q /\ as_nat5 y < S.q /\
as_nat5 t == as_nat5 x + as_nat5 y)
(ensures
(let res = if as_nat5 t >= S.q then as_nat5 t - S.q else as_nat5 t in
res < S.q /\ res == (as_nat5 x + as_nat5 y) % S.q))
let lemma_add_modq5 x y t =
assert (as_nat5 t == as_nat5 x + as_nat5 y);
let res = if as_nat5 t >= S.q then as_nat5 t - S.q else as_nat5 t in
assert (res < S.q);
if as_nat5 t >= S.q then (
FStar.Math.Lemmas.sub_div_mod_1 (as_nat5 t) S.q;
assert (res % S.q == as_nat5 t % S.q))
else
assert (res % S.q == as_nat5 t % S.q);
FStar.Math.Lemmas.small_mod res S.q
val lemma_wide_as_nat_pow528: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 528)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
v x9 < pow2 40))
let lemma_wide_as_nat_pow528 x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert_norm (pow2 504 * pow2 24 = pow2 528);
FStar.Math.Lemmas.pow2_minus 528 504;
assert (v x9 < pow2 24);
assert_norm (pow2 24 < pow2 40)
#push-options "--z3cliopt smt.arith.nl=false"
val lemma_div264_aux: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 528)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
wide_as_nat5 x / pow2 264 ==
v x4 / pow2 40 + v x5 * pow2 16 + v x6 * pow2 72 + v x7 * pow2 128 + v x8 * pow2 184 + v x9 * pow2 240))
let lemma_div264_aux x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
assert_norm (pow2 264 == pow2 224 * pow2 40);
assert_norm (pow2 56 == pow2 16 * pow2 40);
assert_norm (pow2 112 == pow2 72 * pow2 40);
assert_norm (pow2 168 == pow2 128 * pow2 40);
assert_norm (pow2 224 == pow2 184 * pow2 40);
assert_norm (pow2 280 == pow2 240 * pow2 40);
assert_norm (0 < pow2 40);
calc (==) {
wide_as_nat5 x / pow2 264;
(==) { FStar.Math.Lemmas.division_multiplication_lemma (wide_as_nat5 x) (pow2 224) (pow2 40) }
(wide_as_nat5 x / pow2 224) / pow2 40;
(==) { lemma_div224 x }
(v x4 + v x5 * pow2 56 + v x6 * pow2 112 + v x7 * pow2 168 + v x8 * pow2 224 + v x9 * pow2 280) / pow2 40;
(==) { _ by (Tactics.mapply (`feq #int #int (fun x -> x / pow2 40)); int_semiring ()) }
(v x4 + (v x5 * pow2 16 + v x6 * pow2 72 + v x7 * pow2 128 + v x8 * pow2 184 + v x9 * pow2 240) * pow2 40) / pow2 40;
(==) { FStar.Math.Lemmas.lemma_div_plus (v x4) (v x5 * pow2 16 + v x6 * pow2 72 + v x7 * pow2 128 + v x8 * pow2 184 + v x9 * pow2 240) (pow2 40) }
v x4 / pow2 40 + v x5 * pow2 16 + v x6 * pow2 72 + v x7 * pow2 128 + v x8 * pow2 184 + v x9 * pow2 240;
}
val lemma_div264_x5: x5:uint64 ->
Lemma (pow2 16 * (v x5 % pow2 40) + v x5 / pow2 40 * pow2 56 == v x5 * pow2 16)
let lemma_div264_x5 x5 =
assert_norm (0 < pow2 24);
calc (==) {
pow2 16 * (v x5 % pow2 40) + v x5 / pow2 40 * pow2 56;
(==) { _ by (Tactics.norm [delta_only [`%pow2]; primops]; int_semiring ()) }
((v x5 / pow2 40) * pow2 40 + v x5 % pow2 40) * pow2 16;
(==) { FStar.Math.Lemmas.euclidean_division_definition (v x5) (pow2 40) }
v x5 * pow2 16;
}
val lemma_div264_x6: x6:uint64 ->
Lemma (pow2 16 * (v x6 % pow2 40) * pow2 56 + v x6 / pow2 40 * pow2 112 == v x6 * pow2 72)
let lemma_div264_x6 x6 =
calc (==) {
pow2 16 * (v x6 % pow2 40) * pow2 56 + v x6 / pow2 40 * pow2 112;
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
((v x6 / pow2 40) * pow2 40 + v x6 % pow2 40) * pow2 72;
(==) { Math.Lemmas.euclidean_division_definition (v x6) (pow2 40) }
v x6 * pow2 72;
}
val lemma_div264_x7: x7:uint64 ->
Lemma (pow2 16 * (v x7 % pow2 40) * pow2 112 + v x7 / pow2 40 * pow2 168 == v x7 * pow2 128)
let lemma_div264_x7 x7 =
calc (==) {
pow2 16 * (v x7 % pow2 40) * pow2 112 + v x7 / pow2 40 * pow2 168;
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
((v x7 / pow2 40) * pow2 40 + v x7 % pow2 40) * pow2 128;
(==) { Math.Lemmas.euclidean_division_definition (v x7) (pow2 40) }
v x7 * pow2 128;
}
val lemma_div264_x8: x8:uint64 ->
Lemma (pow2 16 * (v x8 % pow2 40) * pow2 168 + v x8 / pow2 40 * pow2 224 == v x8 * pow2 184)
let lemma_div264_x8 x8 =
calc (==) {
pow2 16 * (v x8 % pow2 40) * pow2 168 + v x8 / pow2 40 * pow2 224;
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
((v x8 / pow2 40) * pow2 40 + v x8 % pow2 40) * pow2 184;
(==) { Math.Lemmas.euclidean_division_definition (v x8) (pow2 40) }
v x8 * pow2 184;
}
val lemma_div264_x9: x9:uint64{v x9 < pow2 40} ->
Lemma (pow2 16 * (v x9 % pow2 40) * pow2 224 == v x9 * pow2 240)
let lemma_div264_x9 x9 =
calc (==) {
pow2 16 * (v x9 % pow2 40) * pow2 224;
(==) { Math.Lemmas.small_mod (v x9) (pow2 40) }
pow2 16 * v x9 * pow2 224;
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
v x9 * pow2 240;
}
val lemma_div264: x:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\
wide_as_nat5 x < pow2 528)
(ensures
(let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
let z0 = v x4 / pow2 40 + pow2 16 * (v x5 % pow2 40) in
let z1 = v x5 / pow2 40 + pow2 16 * (v x6 % pow2 40) in
let z2 = v x6 / pow2 40 + pow2 16 * (v x7 % pow2 40) in
let z3 = v x7 / pow2 40 + pow2 16 * (v x8 % pow2 40) in
let z4 = v x8 / pow2 40 + pow2 16 * (v x9 % pow2 40) in
wide_as_nat5 x / pow2 264 == z0 + z1 * pow2 56 + z2 * pow2 112 + z3 * pow2 168 + z4 * pow2 224))
#push-options "--z3rlimit 50"
let lemma_div264 x =
let (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = x in
lemma_wide_as_nat_pow528 x;
assert (v x9 < pow2 40);
calc (==) {
(let z0 = v x4 / pow2 40 + pow2 16 * (v x5 % pow2 40) in
let z1 = v x5 / pow2 40 + pow2 16 * (v x6 % pow2 40) in
let z2 = v x6 / pow2 40 + pow2 16 * (v x7 % pow2 40) in
let z3 = v x7 / pow2 40 + pow2 16 * (v x8 % pow2 40) in
let z4 = v x8 / pow2 40 + pow2 16 * (v x9 % pow2 40) in
z0 + z1 * pow2 56 + z2 * pow2 112 + z3 * pow2 168 + z4 * pow2 224);
(==) { _ by (Tactics.norm [delta; primops]; int_semiring ()) }
v x4 / pow2 40 + pow2 16 * (v x5 % pow2 40) +
v x5 / pow2 40 * pow2 56 + pow2 16 * (v x6 % pow2 40) * pow2 56 +
v x6 / pow2 40 * pow2 112 + pow2 16 * (v x7 % pow2 40) * pow2 112 +
v x7 / pow2 40 * pow2 168 + pow2 16 * (v x8 % pow2 40) * pow2 168 +
v x8 / pow2 40 * pow2 224 + pow2 16 * (v x9 % pow2 40) * pow2 224;
(==) { lemma_div264_x5 x5; lemma_div264_x6 x6 }
v x4 / pow2 40 + v x5 * pow2 16 + v x6 * pow2 72 +
pow2 16 * (v x7 % pow2 40) * pow2 112 +
v x7 / pow2 40 * pow2 168 + pow2 16 * (v x8 % pow2 40) * pow2 168 +
v x8 / pow2 40 * pow2 224 + pow2 16 * (v x9 % pow2 40) * pow2 224;
(==) { lemma_div264_x7 x7; lemma_div264_x8 x8 }
v x4 / pow2 40 + v x5 * pow2 16 + v x6 * pow2 72 + v x7 * pow2 128 + v x8 * pow2 184 +
pow2 16 * (v x9 % pow2 40) * pow2 224;
(==) { lemma_div264_x9 x9 }
v x4 / pow2 40 + v x5 * pow2 16 + v x6 * pow2 72 + v x7 * pow2 128 + v x8 * pow2 184 + v x9 * pow2 240;
(==) { lemma_div264_aux x }
wide_as_nat5 x / pow2 264;
}
#pop-options
#pop-options // "--z3cliopt smt.arith.nl=false"
val lemma_mod_264_aux: t:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 t (1, 1, 1, 1, 1, 1, 1, 1, 1, 1))
(ensures
(let (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) = t in
(wide_as_nat5 t) % pow2 264 ==
(v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + v t4 * pow2 224) % pow2 264))
#push-options "--z3rlimit 150"
let lemma_mod_264_aux t =
let (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) = t in
let res = (t0, t1, t2, t3, t4 &. u64 0xffffffffff) in
assert_norm (pow2 16 * pow2 264 == pow2 280);
assert_norm (pow2 72 * pow2 264 == pow2 336);
assert_norm (pow2 128 * pow2 264 == pow2 392);
assert_norm (pow2 184 * pow2 264 == pow2 448);
assert_norm (pow2 240 * pow2 264 == pow2 504);
calc (==) {
(wide_as_nat5 t) % pow2 264;
(==) { }
(v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + v t4 * pow2 224 +
(v t5 * pow2 16 + v t6 * pow2 72 + v t7 * pow2 128 + v t8 * pow2 184 + v t9 * pow2 240) * pow2 264) % pow2 264;
(==) { FStar.Math.Lemmas.lemma_mod_add_distr (v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + v t4 * pow2 224)
((v t5 * pow2 16 + v t6 * pow2 72 + v t7 * pow2 128 + v t8 * pow2 184 + v t9 * pow2 240) * pow2 264) (pow2 264)}
((v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + v t4 * pow2 224) +
((v t5 * pow2 16 + v t6 * pow2 72 + v t7 * pow2 128 + v t8 * pow2 184 + v t9 * pow2 240) * pow2 264) % pow2 264) % pow2 264;
(==) { FStar.Math.Lemmas.cancel_mul_mod (v t5 * pow2 16 + v t6 * pow2 72 + v t7 * pow2 128 + v t8 * pow2 184 + v t9 * pow2 240) (pow2 264) }
(v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + v t4 * pow2 224) % pow2 264;
}
#pop-options
val lemma_as_nat_pow264: x:qelem5 ->
Lemma
(requires
(let (x0, x1, x2, x3, x4) = x in
qelem_fits5 x (1, 1, 1, 1, 1) /\
v x4 < pow2 40))
(ensures as_nat5 x < pow2 264)
let lemma_as_nat_pow264 x =
let (x0, x1, x2, x3, x4) = x in
assert_norm (pow2 40 * pow2 224 = pow2 264)
val lemma_mod_264: t:qelem_wide5 ->
Lemma
(requires
qelem_wide_fits5 t (1, 1, 1, 1, 1, 1, 1, 1, 1, 1))
(ensures
(let (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) = t in
let res = (t0, t1, t2, t3, t4 &. u64 0xffffffffff) in
qelem_fits5 res (1, 1, 1, 1, 1) /\
as_nat5 res == (wide_as_nat5 t) % pow2 264))
let lemma_mod_264 t =
let (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) = t in
let t4' = t4 &. u64 0xffffffffff in
let res = (t0, t1, t2, t3, t4') in
assert_norm (pow2 40 < pow2 64);
assert_norm (pow2 40 - 1 == 0xffffffffff);
mod_mask_lemma t4 40ul;
assert (v (mod_mask #U64 #SEC 40ul) == 0xffffffffff);
assert (v (t4 &. u64 0xffffffffff) == v t4 % pow2 40);
calc (==) {
(wide_as_nat5 t) % pow2 264;
(==) { lemma_mod_264_aux t }
(v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + v t4 * pow2 224) % pow2 264;
(==) { FStar.Math.Lemmas.lemma_mod_add_distr (v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168) (v t4 * pow2 224) (pow2 264) }
(v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + (v t4 * pow2 224) % pow2 264) % pow2 264;
(==) { FStar.Math.Lemmas.pow2_multiplication_modulo_lemma_2 (v t4) 264 224 }
(v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + (v t4 % pow2 40) * pow2 224) % pow2 264;
(==) { lemma_as_nat_pow264 res; FStar.Math.Lemmas.modulo_lemma (as_nat5 res) (pow2 264) }
v t0 + v t1 * pow2 56 + v t2 * pow2 112 + v t3 * pow2 168 + (v t4 % pow2 40) * pow2 224;
}
val lemma_as_nat_pow264_x4: x:qelem5 ->
Lemma
(requires
qelem_fits5 x (1, 1, 1, 1, 1) /\
as_nat5 x < pow2 264)
(ensures
(let (x0, x1, x2, x3, x4) = x in
v x4 < pow2 40))
let lemma_as_nat_pow264_x4 x =
let (x0, x1, x2, x3, x4) = x in
assert_norm (pow2 40 * pow2 224 = pow2 264)
val lemma_sub_mod_264_aux:
x0:nat -> x1:nat -> x2:nat -> x3:nat -> x4:nat
-> y0:nat -> y1:nat -> y2:nat -> y3:nat -> y4:nat
-> c1:nat -> c2:nat -> c3:nat -> c4:nat -> c5:nat ->
Lemma (
x0 - y0 + c1 * pow56 +
(x1 - y1 - c1 + c2 * pow56) * pow56 +
(x2 - y2 - c2 + c3 * pow56) * pow112 +
(x3 - y3 - c3 + c4 * pow56) * pow168 +
(x4 - y4 - c4 + pow2 40 * c5) * pow224 ==
(x0 + x1 * pow2 56 + x2 * pow2 112 + x3 * pow2 168 + x4 * pow2 224) -
(y0 + y1 * pow2 56 + y2 * pow2 112 + y3 * pow2 168 + y4 * pow2 224) + c5 * pow2 264)
#push-options "--z3rlimit 50"
let lemma_sub_mod_264_aux x0 x1 x2 x3 x4 y0 y1 y2 y3 y4 b0 b1 b2 b3 b4 =
assert_norm (pow2 56 * pow2 56 = pow2 112);
assert_norm (pow2 56 * pow2 112 = pow2 168);
assert_norm (pow2 56 * pow2 168 = pow2 224);
assert_norm (pow2 40 * pow2 224 = pow2 264)
#pop-options
val lemma_sub_mod_264:
x:qelem5
-> y:qelem5
-> t:qelem5
-> c5:uint64 ->
Lemma
(requires
qelem_fits5 x (1, 1, 1, 1, 1) /\
qelem_fits5 y (1, 1, 1, 1, 1) /\
qelem_fits5 t (1, 1, 1, 1, 1) /\
as_nat5 x < pow2 264 /\
as_nat5 y < pow2 264 /\
as_nat5 t == as_nat5 x - as_nat5 y + v c5 * pow2 264 /\ v c5 <= 1 /\
(if v c5 = 0 then as_nat5 x >= as_nat5 y else as_nat5 x < as_nat5 y))
(ensures
(if as_nat5 x >= as_nat5 y then
as_nat5 t == as_nat5 x - as_nat5 y
else as_nat5 t == as_nat5 x - as_nat5 y + pow2 264))
#push-options "--z3rlimit 50"
let lemma_sub_mod_264 x y t c5 =
assert (if v c5 = 0 then as_nat5 x >= as_nat5 y else as_nat5 x < as_nat5 y);
assert (as_nat5 t == as_nat5 x - as_nat5 y + v c5 * pow2 264);
if as_nat5 x >= as_nat5 y then
assert (v c5 == 0 /\ as_nat5 t == as_nat5 x - as_nat5 y)
else
assert (v c5 == 1 /\ as_nat5 t == as_nat5 x - as_nat5 y + pow2 264)
#pop-options
let lemma_mul_qelem5 (x0 x1 x2 x3 x4 y0 y1 y2 y3 y4:nat) : Lemma
((x0 + x1 * pow2 56 + x2 * pow2 112 + x3 * pow2 168 + x4 * pow2 224) *
(y0 + y1 * pow2 56 + y2 * pow2 112 + y3 * pow2 168 + y4 * pow2 224) ==
x0 * y0 +
(x0 * y1 + x1 * y0) * pow56 +
(x0 * y2 + x1 * y1 + x2 * y0) * pow112 +
(x0 * y3 + x1 * y2 + x2 * y1 + x3 * y0) * pow168 +
(x0 * y4 + x1 * y3 + x2 * y2 + x3 * y1 + x4 * y0) * pow224 +
(x1 * y4 + x2 * y3 + x3 * y2 + x4 * y1) * pow280 +
(x2 * y4 + x3 * y3 + x4 * y2) * pow336 +
(x3 * y4 + x4 * y3) * pow392 +
(x4 * y4) * pow448)
=
assert ((x0 + x1 * pow2 56 + x2 * pow2 112 + x3 * pow2 168 + x4 * pow2 224) *
(y0 + y1 * pow2 56 + y2 * pow2 112 + y3 * pow2 168 + y4 * pow2 224) ==
x0 * y0 +
(x0 * y1 + x1 * y0) * pow56 +
(x0 * y2 + x1 * y1 + x2 * y0) * pow112 +
(x0 * y3 + x1 * y2 + x2 * y1 + x3 * y0) * pow168 +
(x0 * y4 + x1 * y3 + x2 * y2 + x3 * y1 + x4 * y0) * pow224 +
(x1 * y4 + x2 * y3 + x3 * y2 + x4 * y1) * pow280 +
(x2 * y4 + x3 * y3 + x4 * y2) * pow336 +
(x3 * y4 + x4 * y3) * pow392 +
(x4 * y4) * pow448)
by (Tactics.norm [zeta; iota; delta; primops]; int_semiring ())
val lemma_mul_5_low_264:
x1:nat -> x2:nat -> x3:nat -> x4:nat -> x5:nat ->
y1:nat -> y2:nat -> y3:nat -> y4:nat -> y5:nat ->
Lemma (
(x1 * y1) >= 0
/\ (x2 * y1 + x1 * y2 + ((x1 * y1) / pow2 56)) >= 0
/\ (x3 * y1 + x2 * y2 + x1 * y3 + ((x2 * y1 + x1 * y2 + ((x1 * y1) / pow2 56)) / pow2 56)) >= 0
/\ (x4 * y1 + x3 * y2 + x2 * y3 + x1 * y4 + ((x3 * y1 + x2 * y2 + x1 * y3 + ((x2 * y1 + x1 * y2 + ((x1 * y1) / pow2 56)) / pow2 56)) / pow2 56)) >= 0
/\ (
let a0 = (x1 * y1) % pow2 56 in
let a1 = ((x2 * y1 + x1 * y2 + ((x1 * y1) / pow2 56)) % pow2 56) in
let a2 = ((x3 * y1 + x2 * y2 + x1 * y3 + ((x2 * y1 + x1 * y2 + ((x1 * y1) / pow2 56)) / pow2 56)) % pow2 56) in
let a3 = ((x4 * y1 + x3 * y2 + x2 * y3 + x1 * y4 + ((x3 * y1 + x2 * y2 + x1 * y3 + ((x2 * y1 + x1 * y2 + ((x1 * y1) / pow2 56)) / pow2 56)) / pow2 56)) % pow2 56) in
let a4 = (x5 * y1 + x4 * y2 + x3 * y3 + x2 * y4 + x1 * y5 + ((x4 * y1 + x3 * y2 + x2 * y3 + x1 * y4 + ((x3 * y1 + x2 * y2 + x1 * y3 + ((x2 * y1 + x1 * y2 + ((x1 * y1) / pow2 56)) / pow2 56)) / pow2 56)) / pow2 56)) in
((x1 + pow2 56 * x2 + pow2 112 * x3 + pow2 168 * x4 + pow2 224 * x5)
* (y1 + pow2 56 * y2 + pow2 112 * y3 + pow2 168 * y4 + pow2 224 * y5)) % pow2 264
== a0 + pow2 56 * a1 + pow2 112 * a2 + pow2 168 * a3 + pow2 224 * (a4 % pow2 40)))
private let lemma_mul_nat_is_nat (a:nat) (b:nat) : Lemma (a*b >= 0) = ()
private let lemma_div_nat_is_nat (a:nat) (b:pos) : Lemma (a/b >= 0) = ()
private
val lemma_mul_5''':
x1:nat -> x2:nat -> x3:nat -> x4:nat -> x5:nat ->
y1:nat -> y2:nat -> y3:nat -> y4:nat -> y5:nat ->
Lemma (((x1 + pow2 56 * x2 + pow2 112 * x3 + pow2 168 * x4 + pow2 224 * x5)
* (y1 + pow2 56 * y2 + pow2 112 * y3 + pow2 168 * y4 + pow2 224 * y5)) % pow2 264
==
(x1 * y1
+ pow2 56 * (x2 * y1 + x1 * y2)
+ pow2 112 * (x3 * y1 + x2 * y2 + x1 * y3)
+ pow2 168 * (x4 * y1 + x3 * y2 + x2 * y3 + x1 * y4)
+ pow2 224 * (x5 * y1 + x4 * y2 + x3 * y3 + x2 * y4 + x1 * y5)) % pow2 264)
let lemma_mul_5''' x1 x2 x3 x4 x5 y1 y2 y3 y4 y5 =
calc (==) {
((x1 + pow2 56 * x2 + pow2 112 * x3 + pow2 168 * x4 + pow2 224 * x5)
* (y1 + pow2 56 * y2 + pow2 112 * y3 + pow2 168 * y4 + pow2 224 * y5)) % pow2 264;
(==) { _ by (Tactics.mapply (`feq #int #int (fun x -> x % pow2 264));
Tactics.norm [zeta; iota; delta; primops];
int_semiring ()) }
(x1 * y1
+ pow2 56 * (x2 * y1 + x1 * y2)
+ pow2 112 * (x3 * y1 + x2 * y2 + x1 * y3)
+ pow2 168 * (x4 * y1 + x3 * y2 + x2 * y3 + x1 * y4)
+ pow2 224 * (x5 * y1 + x4 * y2 + x3 * y3 + x2 * y4 + x1 * y5)
+ (pow2 16 * x2 * y5 +
pow2 16 * x3 * y4 + pow2 72 * x3 * y5 +
pow2 16 * x4 * y3 + pow2 72 * x4 * y4 + pow2 128 * x4 * y5 +
pow2 16 * x5 * y2 + pow2 72 * x5 * y3 + pow2 128 * x5 * y4 + pow2 184 * x5 * y5) * pow2 264) % pow2 264;
(==) { _ by (Tactics.mapply (`eq_eq2); Tactics.mapply (`Math.Lemmas.lemma_mod_plus)) }
(x1 * y1
+ pow2 56 * (x2 * y1 + x1 * y2)
+ pow2 112 * (x3 * y1 + x2 * y2 + x1 * y3)
+ pow2 168 * (x4 * y1 + x3 * y2 + x2 * y3 + x1 * y4)
+ pow2 224 * (x5 * y1 + x4 * y2 + x3 * y3 + x2 * y4 + x1 * y5)) % pow2 264;
}
private val lemma_mod_264'':
a0:nat -> a1:nat-> a2:nat -> a3:nat -> a4:nat ->
Lemma
(requires a0 < pow56 /\ a1 < pow56 /\ a2 < pow56 /\ a3 < pow56)
(ensures a0 + pow2 56 * a1 + pow2 112 * a2 + pow2 168 * a3 + pow2 224 * (a4 % pow2 40) < pow2 264)
let lemma_mod_264'' a0 a1 a2 a3 a4 =
assert_norm(pow2 40 = 0x10000000000);
assert_norm(pow2 56 = 0x100000000000000);
assert_norm(pow2 112 = 0x10000000000000000000000000000);
assert_norm(pow2 168 = 0x1000000000000000000000000000000000000000000);
assert_norm(pow2 224 = 0x100000000000000000000000000000000000000000000000000000000);
assert_norm(pow2 264 = 0x1000000000000000000000000000000000000000000000000000000000000000000)
private val lemma_mod_264':
a0:nat -> a1:nat-> a2:nat -> a3:nat -> a4:nat ->
Lemma
(requires a0 < pow56 /\ a1 < pow56 /\ a2 < pow56 /\ a3 < pow56)
(ensures (a0
+ pow2 56 * a1
+ pow2 112 * a2
+ pow2 168 * a3
+ pow2 224 * a4) % pow2 264 =
a0
+ pow2 56 * a1
+ pow2 112 * a2
+ pow2 168 * a3
+ pow2 224 * (a4 % pow2 40) )
let lemma_mod_264' a0 a1 a2 a3 a4 =
assert_norm(pow2 56 = 0x100000000000000);
assert_norm(pow2 112 = 0x10000000000000000000000000000);
assert_norm(pow2 168 = 0x1000000000000000000000000000000000000000000);
assert_norm(pow2 224 = 0x100000000000000000000000000000000000000000000000000000000);
Math.Lemmas.lemma_mod_plus_distr_l (pow2 224 * a4) (a0 + pow2 56 * a1 + pow2 112 * a2 + pow2 168 * a3) (pow2 264);
Math.Lemmas.pow2_multiplication_modulo_lemma_2 a4 264 224;
lemma_mod_264'' a0 a1 a2 a3 a4;
Math.Lemmas.modulo_lemma (a0 + pow2 56 * a1 + pow2 112 * a2 + pow2 168 * a3 + pow2 224 * (a4 % pow2 40)) (pow2 264)
private let lemma_aux_0 (a:nat) (b:nat) (n:nat) : Lemma
(pow2 n * a + pow2 (n+56) * b = pow2 n * (a % pow2 56) + pow2 (n+56) * (b + a / pow2 56))
= Math.Lemmas.lemma_div_mod a (pow2 56);
Math.Lemmas.pow2_plus n 56;
assert(a = pow2 56 * (a / pow2 56) + (a % pow2 56));
Math.Lemmas.distributivity_add_right (pow2 n) (pow2 56 * (a / pow2 56)) (a % pow2 56);
Math.Lemmas.paren_mul_right (pow2 n) (pow2 56) (a / pow2 56);
Math.Lemmas.distributivity_add_right (pow2 (n+56)) b (a / pow2 56)
private
val lemma_mod_264_small:
a0:nat -> a1:nat -> a2:nat -> a3:nat -> a4:nat ->
Lemma ( (a0 + pow2 56 * a1 + pow2 112 * a2 + pow2 168 * a3 + pow2 224 * a4)
= (a0 % pow2 56)
+ pow2 56 * ((a1 + (a0 / pow2 56)) % pow2 56)
+ pow2 112 * ((a2 + ((a1 + (a0 / pow2 56)) / pow2 56)) % pow2 56)
+ pow2 168 * ((a3 + ((a2 + ((a1 + (a0 / pow2 56)) / pow2 56)) / pow2 56)) % pow2 56)
+ pow2 224 * (a4 + ((a3 + ((a2 + ((a1 + (a0 / pow2 56)) / pow2 56)) / pow2 56)) / pow2 56)))
(* These silly lemmas needed to guide the proof below... *)
private let aux_nat_over_pos (p : nat) (q : pos) : Lemma (p / q >= 0) = ()
private let aux_nat_plus_nat (p : nat) (q : nat) : Lemma (p + q >= 0) = ()
let lemma_mod_264_small a0 a1 a2 a3 a4 =
Math.Lemmas.lemma_div_mod a0 (pow2 56);
Math.Lemmas.distributivity_add_right (pow2 56) a1 (a0 / pow2 56);
(**) aux_nat_over_pos a0 (pow2 56);
(**) aux_nat_plus_nat a1 (a0 / pow2 56);
let a1':nat = (a1 + (a0 / pow2 56)) in
(**) aux_nat_over_pos a1' (pow2 56);
(**) aux_nat_plus_nat a2 (a1' / pow2 56);
let a2':nat = (a2 + (a1' / pow2 56)) in
(**) aux_nat_over_pos a2' (pow2 56);
(**) aux_nat_plus_nat a3 (a2' / pow2 56);
let a3':nat = (a3 + (a2' / pow2 56)) in
lemma_aux_0 a1' a2 56;
lemma_aux_0 a2' a3 112;
lemma_aux_0 a3' a4 168
private
val lemma_mod_264_:
a0:nat -> a1:nat -> a2:nat -> a3:nat -> a4:nat ->
Lemma ((a0 + pow2 56 * a1 + pow2 112 * a2 + pow2 168 * a3 + pow2 224 * a4) % pow2 264 =
(a0 % pow2 56)
+ pow2 56 * ((a1 + (a0 / pow2 56)) % pow2 56)
+ pow2 112 * ((a2 + ((a1 + (a0 / pow2 56)) / pow2 56)) % pow2 56)
+ pow2 168 * ((a3 + ((a2 + ((a1 + (a0 / pow2 56)) / pow2 56)) / pow2 56)) % pow2 56)
+ pow2 224 * ((a4 + ((a3 + ((a2 + ((a1 + (a0 / pow2 56)) / pow2 56)) / pow2 56)) / pow2 56)) % pow2 40))
let lemma_mod_264_ a0 a1 a2 a3 a4 =
lemma_mod_264_small a0 a1 a2 a3 a4;
let x0 = a0 % pow2 56 in
assert (x0 < pow56);
let x1 = ((a1 + (a0 / pow2 56)) % pow2 56) in
assert (x1 < pow56);
let x2 = ((a2 + ((a1 + (a0 / pow2 56)) / pow2 56)) % pow2 56) in
assert (x2 < pow56);
let x3 = ((a3 + ((a2 + ((a1 + (a0 / pow2 56)) / pow2 56)) / pow2 56)) % pow2 56) in
assert (x3 < pow56);
lemma_mod_264' x0 x1 x2 x3 (a4 + ((a3 + ((a2 + ((a1 + (a0 / pow2 56)) / pow2 56)) / pow2 56)) / pow2 56))
#push-options "--z3rlimit 50"
let lemma_mul_5_low_264 x1 x2 x3 x4 x5 y1 y2 y3 y4 y5 =
lemma_div_nat_is_nat (x1 * y1) (pow2 56);
lemma_div_nat_is_nat (x2 * y1 + x1 * y2 + ((x1 * y1) / pow2 56)) (pow2 56);
lemma_div_nat_is_nat (x3 * y1 + x2 * y2 + x1 * y3 + ((x2 * y1 + x1 * y2 + ((x1 * y1) / pow2 56)) / pow2 56)) (pow2 56);
lemma_div_nat_is_nat (x4 * y1 + x3 * y2 + x2 * y3 + x1 * y4 + ((x3 * y1 + x2 * y2 + x1 * y3 + ((x2 * y1 + x1 * y2 + ((x1 * y1) / pow2 56)) / pow2 56)) / pow2 56)) (pow2 56);
lemma_mul_5''' x1 x2 x3 x4 x5 y1 y2 y3 y4 y5;
lemma_mod_264_ (x1 * y1) (x2 * y1 + x1 * y2) (x3 * y1 + x2 * y2 + x1 * y3) (x4 * y1 + x3 * y2 + x2 * y3 + x1 * y4) (x5 * y1 + x4 * y2 + x3 * y3 + x2 * y4 + x1 * y5)
#pop-options
private
val lemma_optimized_barrett_reduce:
a:nat{a < pow2 512} ->
Lemma (a - (((a / pow2 248) * (pow2 512 / S.q)) / pow2 264) * S.q < 2 * S.q
/\ a - (((a / pow2 248) * (pow2 512 / S.q)) / pow2 264) * S.q >= 0) | {
"checked_file": "/",
"dependencies": [
"Spec.Ed25519.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.BignumQ.Definitions.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Tactics.CanonCommSemiring.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.BignumQ.Lemmas.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.CanonCommSemiring",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.BignumQ.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.Ed25519",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.CanonCommSemiring",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.BignumQ",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.BignumQ",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Prims.nat{a < Prims.pow2 512}
-> FStar.Pervasives.Lemma
(ensures
a -
((a / Prims.pow2 248) * (Prims.pow2 512 / Spec.Ed25519.q) / Prims.pow2 264) * Spec.Ed25519.q <
2 * Spec.Ed25519.q /\
a -
((a / Prims.pow2 248) * (Prims.pow2 512 / Spec.Ed25519.q) / Prims.pow2 264) * Spec.Ed25519.q >=
0) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.pow2",
"FStar.Pervasives.assert_norm",
"Prims.eq2",
"Prims.int",
"Prims.unit",
"Spec.Ed25519.q",
"Prims.op_Equality"
] | [] | true | false | true | false | false | let lemma_optimized_barrett_reduce a =
| assert_norm (pow2 248 = 0x100000000000000000000000000000000000000000000000000000000000000);
assert_norm (pow2 264 = 0x1000000000000000000000000000000000000000000000000000000000000000000);
assert_norm (S.q == 0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed);
assert_norm (0x100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 ==
pow2 512) | false |
LowParse.Low.DER.fst | LowParse.Low.DER.validate_der_length_payload32 | val validate_der_length_payload32 (x: U8.t{der_length_payload_size_of_tag x <= 4})
: Tot (validator (parse_der_length_payload32 x)) | val validate_der_length_payload32 (x: U8.t{der_length_payload_size_of_tag x <= 4})
: Tot (validator (parse_der_length_payload32 x)) | let validate_der_length_payload32
(x: U8.t { der_length_payload_size_of_tag x <= 4 } )
: Tot (validator (parse_der_length_payload32 x))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_facts (parse_der_length_payload32 x) h input (uint64_to_uint32 pos);
assert (U64.v pos <= U32.v input.len);
parse_der_length_payload32_unfold x (bytes_of_slice_from h input (uint64_to_uint32 pos));
assert_norm (pow2 (8 * 1) == 256);
assert_norm (pow2 (8 * 2) == 65536);
assert_norm (pow2 (8 * 3) == 16777216);
assert_norm (pow2 (8 * 4) == 4294967296)
in
if x `U8.lt` 128uy
then pos
else if x = 128uy || x = 255uy
then validator_error_generic
else if x = 129uy
then
[@inline_let] let _ = valid_facts parse_u8 h input (uint64_to_uint32 pos) in
let v = validate_u8 () input pos in
if is_error v
then v
else
let z = read_u8 input (uint64_to_uint32 pos) in
if z `U8.lt` 128uy
then validator_error_generic
else v
else
let len = x `U8.sub` 128uy in
[@inline_let] let _ = valid_facts (parse_bounded_integer (U8.v len)) h input (uint64_to_uint32 pos) in
if len = 2uy
then
let v = validate_bounded_integer 2 input pos in
if is_error v
then v
else
let y = read_bounded_integer_2 () input (uint64_to_uint32 pos) in
if y `U32.lt `256ul
then validator_error_generic
else v
else if len = 3uy
then
let v = validate_bounded_integer 3 input pos in
if is_error v
then v
else
let y = read_bounded_integer_3 () input (uint64_to_uint32 pos) in
if y `U32.lt `65536ul
then validator_error_generic
else v
else
let v = validate_bounded_integer 4 input pos in
if is_error v
then v
else
let y = read_bounded_integer_4 () input (uint64_to_uint32 pos) in
if y `U32.lt` 16777216ul
then validator_error_generic
else v | {
"file_name": "src/lowparse/LowParse.Low.DER.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 16,
"end_line": 79,
"start_col": 0,
"start_line": 19
} | module LowParse.Low.DER
include LowParse.Spec.DER
include LowParse.Low.Int // for parse_u8
include LowParse.Low.BoundedInt // for bounded_integer
open FStar.Mul
module U8 = FStar.UInt8
module U32 = FStar.UInt32
module HST = FStar.HyperStack.ST
module B = LowStar.Buffer
module Cast = FStar.Int.Cast
module U64 = FStar.UInt64
#reset-options "--z3cliopt smt.arith.nl=false --max_fuel 0 --max_ifuel 0"
#push-options "--z3rlimit 32" | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.DER.fsti.checked",
"LowParse.Low.Int.fsti.checked",
"LowParse.Low.BoundedInt.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.DER.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.BoundedInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Int",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.DER",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.arith.nl=false"
],
"z3refresh": false,
"z3rlimit": 32,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: FStar.UInt8.t{LowParse.Spec.DER.der_length_payload_size_of_tag x <= 4}
-> LowParse.Low.Base.validator (LowParse.Spec.DER.parse_der_length_payload32 x) | Prims.Tot | [
"total"
] | [] | [
"FStar.UInt8.t",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"LowParse.Spec.DER.der_length_payload_size_of_tag",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"FStar.UInt64.t",
"FStar.UInt8.lt",
"FStar.UInt8.__uint_to_t",
"Prims.bool",
"Prims.op_BarBar",
"Prims.op_Equality",
"LowParse.Low.ErrorCode.validator_error_generic",
"LowParse.Low.ErrorCode.is_error",
"LowParse.Low.Int.read_u8",
"LowParse.Low.ErrorCode.uint64_to_uint32",
"LowParse.Low.Int.validate_u8",
"Prims.unit",
"LowParse.Low.Base.Spec.valid_facts",
"LowParse.Spec.Int.parse_u8_kind",
"LowParse.Spec.Int.parse_u8",
"FStar.UInt32.lt",
"FStar.UInt32.__uint_to_t",
"LowParse.Spec.BoundedInt.bounded_integer",
"LowParse.Low.BoundedInt.read_bounded_integer_2",
"LowParse.Low.BoundedInt.validate_bounded_integer",
"LowParse.Low.BoundedInt.read_bounded_integer_3",
"LowParse.Low.BoundedInt.read_bounded_integer_4",
"LowParse.Spec.BoundedInt.parse_bounded_integer_kind",
"FStar.UInt8.v",
"LowParse.Spec.BoundedInt.parse_bounded_integer",
"FStar.UInt8.sub",
"FStar.Pervasives.assert_norm",
"Prims.eq2",
"Prims.int",
"Prims.pow2",
"FStar.Mul.op_Star",
"LowParse.Spec.DER.parse_der_length_payload32_unfold",
"LowParse.Slice.bytes_of_slice_from",
"Prims._assert",
"FStar.UInt64.v",
"FStar.UInt32.v",
"LowParse.Slice.__proj__Mkslice__item__len",
"LowParse.Spec.DER.parse_der_length_payload_kind",
"LowParse.Spec.Base.refine_with_tag",
"FStar.UInt32.t",
"LowParse.Spec.DER.tag_of_der_length32",
"LowParse.Spec.DER.parse_der_length_payload32",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"LowParse.Low.Base.validator"
] | [] | false | false | false | false | false | let validate_der_length_payload32 (x: U8.t{der_length_payload_size_of_tag x <= 4})
: Tot (validator (parse_der_length_payload32 x)) =
| fun #rrel #rel input pos ->
let h = HST.get () in
[@@ inline_let ]let _ =
valid_facts (parse_der_length_payload32 x) h input (uint64_to_uint32 pos);
assert (U64.v pos <= U32.v input.len);
parse_der_length_payload32_unfold x (bytes_of_slice_from h input (uint64_to_uint32 pos));
assert_norm (pow2 (8 * 1) == 256);
assert_norm (pow2 (8 * 2) == 65536);
assert_norm (pow2 (8 * 3) == 16777216);
assert_norm (pow2 (8 * 4) == 4294967296)
in
if x `U8.lt` 128uy
then pos
else
if x = 128uy || x = 255uy
then validator_error_generic
else
if x = 129uy
then
[@@ inline_let ]let _ = valid_facts parse_u8 h input (uint64_to_uint32 pos) in
let v = validate_u8 () input pos in
if is_error v
then v
else
let z = read_u8 input (uint64_to_uint32 pos) in
if z `U8.lt` 128uy then validator_error_generic else v
else
let len = x `U8.sub` 128uy in
[@@ inline_let ]let _ =
valid_facts (parse_bounded_integer (U8.v len)) h input (uint64_to_uint32 pos)
in
if len = 2uy
then
let v = validate_bounded_integer 2 input pos in
if is_error v
then v
else
let y = read_bounded_integer_2 () input (uint64_to_uint32 pos) in
if y `U32.lt` 256ul then validator_error_generic else v
else
if len = 3uy
then
let v = validate_bounded_integer 3 input pos in
if is_error v
then v
else
let y = read_bounded_integer_3 () input (uint64_to_uint32 pos) in
if y `U32.lt` 65536ul then validator_error_generic else v
else
let v = validate_bounded_integer 4 input pos in
if is_error v
then v
else
let y = read_bounded_integer_4 () input (uint64_to_uint32 pos) in
if y `U32.lt` 16777216ul then validator_error_generic else v | false |
LowParse.Low.DER.fst | LowParse.Low.DER.read_bounded_der_length32 | val read_bounded_der_length32
(vmin: der_length_t)
(vmax: der_length_t{vmin <= vmax /\ vmax < 4294967296})
: Tot (leaf_reader (parse_bounded_der_length32 (vmin) (vmax))) | val read_bounded_der_length32
(vmin: der_length_t)
(vmax: der_length_t{vmin <= vmax /\ vmax < 4294967296})
: Tot (leaf_reader (parse_bounded_der_length32 (vmin) (vmax))) | let read_bounded_der_length32
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
: Tot (
leaf_reader (parse_bounded_der_length32 (vmin) (vmax)))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ =
valid_facts (parse_bounded_der_length32 (vmin) (vmax)) h input pos;
parse_bounded_der_length32_unfold (vmin) (vmax) (bytes_of_slice_from h input pos);
valid_facts parse_u8 h input pos
in
let v = jump_u8 input pos in
let x = read_u8 input pos in
let len = der_length_payload_size_of_tag8 x in
[@inline_let] let _ = valid_facts (parse_der_length_payload32 x) h input v in
let y = read_der_length_payload32 x input v in
(y <: bounded_int32 (vmin) (vmax)) | {
"file_name": "src/lowparse/LowParse.Low.DER.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 38,
"end_line": 231,
"start_col": 0,
"start_line": 213
} | module LowParse.Low.DER
include LowParse.Spec.DER
include LowParse.Low.Int // for parse_u8
include LowParse.Low.BoundedInt // for bounded_integer
open FStar.Mul
module U8 = FStar.UInt8
module U32 = FStar.UInt32
module HST = FStar.HyperStack.ST
module B = LowStar.Buffer
module Cast = FStar.Int.Cast
module U64 = FStar.UInt64
#reset-options "--z3cliopt smt.arith.nl=false --max_fuel 0 --max_ifuel 0"
#push-options "--z3rlimit 32"
inline_for_extraction
let validate_der_length_payload32
(x: U8.t { der_length_payload_size_of_tag x <= 4 } )
: Tot (validator (parse_der_length_payload32 x))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_facts (parse_der_length_payload32 x) h input (uint64_to_uint32 pos);
assert (U64.v pos <= U32.v input.len);
parse_der_length_payload32_unfold x (bytes_of_slice_from h input (uint64_to_uint32 pos));
assert_norm (pow2 (8 * 1) == 256);
assert_norm (pow2 (8 * 2) == 65536);
assert_norm (pow2 (8 * 3) == 16777216);
assert_norm (pow2 (8 * 4) == 4294967296)
in
if x `U8.lt` 128uy
then pos
else if x = 128uy || x = 255uy
then validator_error_generic
else if x = 129uy
then
[@inline_let] let _ = valid_facts parse_u8 h input (uint64_to_uint32 pos) in
let v = validate_u8 () input pos in
if is_error v
then v
else
let z = read_u8 input (uint64_to_uint32 pos) in
if z `U8.lt` 128uy
then validator_error_generic
else v
else
let len = x `U8.sub` 128uy in
[@inline_let] let _ = valid_facts (parse_bounded_integer (U8.v len)) h input (uint64_to_uint32 pos) in
if len = 2uy
then
let v = validate_bounded_integer 2 input pos in
if is_error v
then v
else
let y = read_bounded_integer_2 () input (uint64_to_uint32 pos) in
if y `U32.lt `256ul
then validator_error_generic
else v
else if len = 3uy
then
let v = validate_bounded_integer 3 input pos in
if is_error v
then v
else
let y = read_bounded_integer_3 () input (uint64_to_uint32 pos) in
if y `U32.lt `65536ul
then validator_error_generic
else v
else
let v = validate_bounded_integer 4 input pos in
if is_error v
then v
else
let y = read_bounded_integer_4 () input (uint64_to_uint32 pos) in
if y `U32.lt` 16777216ul
then validator_error_generic
else v
inline_for_extraction
let jump_der_length_payload32
(x: U8.t { der_length_payload_size_of_tag x <= 4 } )
: Tot (jumper (parse_der_length_payload32 x))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_facts (parse_der_length_payload32 x) h input pos;
parse_der_length_payload32_unfold x (bytes_of_slice_from h input pos);
assert_norm (pow2 (8 * 1) == 256);
assert_norm (pow2 (8 * 2) == 65536);
assert_norm (pow2 (8 * 3) == 16777216);
assert_norm (pow2 (8 * 4) == 4294967296)
in
if x `U8.lt` 128uy
then pos
else
[@inline_let]
let len = x `U8.sub` 128uy in
[@inline_let] let _ =
valid_facts parse_u8 h input pos;
parser_kind_prop_equiv parse_u8_kind parse_u8;
valid_facts (parse_bounded_integer (U8.v len)) h input pos;
parser_kind_prop_equiv (parse_bounded_integer_kind (U8.v len)) (parse_bounded_integer (U8.v len))
in
pos `U32.add` Cast.uint8_to_uint32 len
inline_for_extraction
let read_der_length_payload32
(x: U8.t { der_length_payload_size_of_tag x <= 4 } )
: Tot (leaf_reader (parse_der_length_payload32 x))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_facts (parse_der_length_payload32 x) h input pos;
parse_der_length_payload32_unfold x (bytes_of_slice_from h input pos);
assert_norm (pow2 (8 * 1) == 256);
assert_norm (pow2 (8 * 2) == 65536);
assert_norm (pow2 (8 * 3) == 16777216);
assert_norm (pow2 (8 * 4) == 4294967296)
in
if x `U8.lt` 128uy
then
[@inline_let]
let res = Cast.uint8_to_uint32 x in
[@inline_let] let _ = assert (tag_of_der_length32 res == x) in
(res <: refine_with_tag tag_of_der_length32 x)
else if x = 129uy
then
[@inline_let] let _ = valid_facts parse_u8 h input pos in
let z = read_u8 input pos in
[@inline_let] let res = Cast.uint8_to_uint32 z in
[@inline_let] let _ = assert (tag_of_der_length32 res == x) in
(res <: refine_with_tag tag_of_der_length32 x)
else
let len = x `U8.sub` 128uy in
[@inline_let] let _ = valid_facts (parse_bounded_integer (U8.v len)) h input pos in
if len = 2uy
then
let res = read_bounded_integer_2 () input pos in
[@inline_let] let _ = assert (tag_of_der_length32 res == x) in
(res <: refine_with_tag tag_of_der_length32 x)
else if len = 3uy
then
let res = read_bounded_integer_3 () input pos in
[@inline_let] let _ = assert (tag_of_der_length32 res == x) in
(res <: refine_with_tag tag_of_der_length32 x)
else
let res = read_bounded_integer_4 () input pos in
[@inline_let] let _ = assert (tag_of_der_length32 res == x) in
(res <: refine_with_tag tag_of_der_length32 x)
inline_for_extraction
let validate_bounded_der_length32
(vmin: der_length_t)
(min: U32.t { U32.v min == vmin } )
(vmax: der_length_t)
(max: U32.t { U32.v max == vmax /\ U32.v min <= U32.v max } )
: Tot (
validator (parse_bounded_der_length32 (vmin) (vmax)))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ =
valid_facts (parse_bounded_der_length32 (U32.v min) (U32.v max)) h input (uint64_to_uint32 pos);
parse_bounded_der_length32_unfold (U32.v min) (U32.v max) (bytes_of_slice_from h input (uint64_to_uint32 pos));
valid_facts parse_u8 h input (uint64_to_uint32 pos)
in
let v = validate_u8 () input pos in
if is_error v
then v
else
let x = read_u8 input (uint64_to_uint32 pos) in
let len = der_length_payload_size_of_tag8 x in
let tg1 = tag_of_der_length32_impl min in
let l1 = der_length_payload_size_of_tag8 tg1 in
let tg2 = tag_of_der_length32_impl max in
let l2 = der_length_payload_size_of_tag8 tg2 in
if (len `U8.lt` l1) || ( l2 `U8.lt` len)
then validator_error_generic
else
[@inline_let] let _ = valid_facts (parse_der_length_payload32 x) h input (uint64_to_uint32 v) in
let v2 = validate_der_length_payload32 x input v in
if is_error v2
then v2
else
let y = read_der_length_payload32 x input (uint64_to_uint32 v) in
if y `U32.lt` min || max `U32.lt` y
then validator_error_generic
else v2
inline_for_extraction
let jump_bounded_der_length32
(vmin: der_length_t)
(vmax: der_length_t { vmin <= vmax /\ vmax < 4294967296 } )
: Tot (
jumper (parse_bounded_der_length32 (vmin) (vmax)))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ =
valid_facts (parse_bounded_der_length32 (vmin) (vmax)) h input pos;
parse_bounded_der_length32_unfold (vmin) (vmax) (bytes_of_slice_from h input pos);
valid_facts parse_u8 h input pos
in
let v = jump_u8 input pos in
let x = read_u8 input pos in
let len = der_length_payload_size_of_tag8 x in
[@inline_let] let _ = valid_facts (parse_der_length_payload32 x) h input v in
jump_der_length_payload32 x input v | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.DER.fsti.checked",
"LowParse.Low.Int.fsti.checked",
"LowParse.Low.BoundedInt.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.DER.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.BoundedInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Int",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.DER",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.arith.nl=false"
],
"z3refresh": false,
"z3rlimit": 32,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
vmin: LowParse.Spec.DER.der_length_t ->
vmax: LowParse.Spec.DER.der_length_t{vmin <= vmax /\ vmax < 4294967296}
-> LowParse.Low.Base.leaf_reader (LowParse.Spec.DER.parse_bounded_der_length32 vmin vmax) | Prims.Tot | [
"total"
] | [] | [
"LowParse.Spec.DER.der_length_t",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"LowParse.Spec.BoundedInt.bounded_int32",
"LowParse.Spec.Base.refine_with_tag",
"FStar.UInt8.t",
"LowParse.Spec.DER.tag_of_der_length32",
"LowParse.Low.DER.read_der_length_payload32",
"Prims.unit",
"LowParse.Low.Base.Spec.valid_facts",
"LowParse.Spec.DER.parse_der_length_payload_kind",
"LowParse.Spec.DER.parse_der_length_payload32",
"Prims.eq2",
"Prims.int",
"Prims.l_or",
"FStar.UInt.size",
"Prims.op_GreaterThanOrEqual",
"FStar.UInt8.v",
"LowParse.Spec.DER.der_length_payload_size_of_tag",
"LowParse.Spec.DER.der_length_payload_size_of_tag8",
"LowParse.Low.Int.read_u8",
"LowParse.Low.Int.jump_u8",
"LowParse.Spec.Int.parse_u8_kind",
"LowParse.Spec.Int.parse_u8",
"LowParse.Spec.DER.parse_bounded_der_length32_unfold",
"LowParse.Slice.bytes_of_slice_from",
"LowParse.Spec.DER.parse_bounded_der_length32_kind",
"LowParse.Spec.DER.parse_bounded_der_length32",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"LowParse.Low.Base.leaf_reader"
] | [] | false | false | false | false | false | let read_bounded_der_length32
(vmin: der_length_t)
(vmax: der_length_t{vmin <= vmax /\ vmax < 4294967296})
: Tot (leaf_reader (parse_bounded_der_length32 (vmin) (vmax))) =
| fun #rrel #rel input pos ->
let h = HST.get () in
[@@ inline_let ]let _ =
valid_facts (parse_bounded_der_length32 (vmin) (vmax)) h input pos;
parse_bounded_der_length32_unfold (vmin) (vmax) (bytes_of_slice_from h input pos);
valid_facts parse_u8 h input pos
in
let v = jump_u8 input pos in
let x = read_u8 input pos in
let len = der_length_payload_size_of_tag8 x in
[@@ inline_let ]let _ = valid_facts (parse_der_length_payload32 x) h input v in
let y = read_der_length_payload32 x input v in
(y <: bounded_int32 (vmin) (vmax)) | false |
LowParse.Low.ConstInt32.fst | LowParse.Low.ConstInt32.decompose_compare | val decompose_compare (v1: nat{0 <= v1 /\ v1 < 4294967296}) (v2: nat{0 <= v2 /\ v2 < 4294967296})
: Lemma
((v1 = v2) ==
(compare_by_bytes (U8.uint_to_t (decompose_int32le_0 v1))
(U8.uint_to_t (decompose_int32le_1 v1))
(U8.uint_to_t (decompose_int32le_2 v1))
(U8.uint_to_t (decompose_int32le_3 v1))
(U8.uint_to_t (decompose_int32le_0 v2))
(U8.uint_to_t (decompose_int32le_1 v2))
(U8.uint_to_t (decompose_int32le_2 v2))
(U8.uint_to_t (decompose_int32le_3 v2)))) | val decompose_compare (v1: nat{0 <= v1 /\ v1 < 4294967296}) (v2: nat{0 <= v2 /\ v2 < 4294967296})
: Lemma
((v1 = v2) ==
(compare_by_bytes (U8.uint_to_t (decompose_int32le_0 v1))
(U8.uint_to_t (decompose_int32le_1 v1))
(U8.uint_to_t (decompose_int32le_2 v1))
(U8.uint_to_t (decompose_int32le_3 v1))
(U8.uint_to_t (decompose_int32le_0 v2))
(U8.uint_to_t (decompose_int32le_1 v2))
(U8.uint_to_t (decompose_int32le_2 v2))
(U8.uint_to_t (decompose_int32le_3 v2)))) | let decompose_compare
(v1 : nat { 0 <= v1 /\ v1 < 4294967296 } )
(v2 : nat { 0 <= v2 /\ v2 < 4294967296 } )
: Lemma ( (v1 = v2)
== (compare_by_bytes
(U8.uint_to_t (decompose_int32le_0 v1))
(U8.uint_to_t (decompose_int32le_1 v1))
(U8.uint_to_t (decompose_int32le_2 v1))
(U8.uint_to_t (decompose_int32le_3 v1))
(U8.uint_to_t (decompose_int32le_0 v2))
(U8.uint_to_t (decompose_int32le_1 v2))
(U8.uint_to_t (decompose_int32le_2 v2))
(U8.uint_to_t (decompose_int32le_3 v2))))
= let a0 = U8.uint_to_t (decompose_int32le_0 v1) in
let a1 = U8.uint_to_t (decompose_int32le_1 v1) in
let a2 = U8.uint_to_t (decompose_int32le_2 v1) in
let a3 = U8.uint_to_t (decompose_int32le_3 v1) in
let b0 = U8.uint_to_t (decompose_int32le_0 v2) in
let b1 = U8.uint_to_t (decompose_int32le_1 v2) in
let b2 = U8.uint_to_t (decompose_int32le_2 v2) in
let b3 = U8.uint_to_t (decompose_int32le_3 v2) in
compare_by_bytes_equiv a0 a1 a2 a3 b0 b1 b2 b3;
decompose_compose_equiv v1;
decompose_compose_equiv v2 | {
"file_name": "src/lowparse/LowParse.Low.ConstInt32.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 28,
"end_line": 173,
"start_col": 0,
"start_line": 150
} | module LowParse.Low.ConstInt32
(* LowParse implementation module for 32 bits contants *)
include FStar.Endianness
include LowParse.Spec.ConstInt32
include LowParse.Spec.Int32le
include LowParse.Low.Combinators
include LowParse.Low.Int32le
module U32 = FStar.UInt32
module U8 = FStar.UInt8
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module B = LowStar.Buffer
module Cast = FStar.Int.Cast
module U64 = FStar.UInt64
let valid_constint32le
(v: nat { 0 <= v /\ v < 4294967296 } )
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma (valid (parse_constint32le v) h input pos
<==>
(valid parse_int32le h input pos /\
U32.v (contents parse_int32le h input pos) == v))
= valid_facts (parse_constint32le v) h input pos;
valid_facts parse_int32le h input pos;
parse_constint32le_unfold v (bytes_of_slice_from h input pos)
inline_for_extraction
let validate_constint32le_slow
(v: U32.t { 0 <= U32.v v /\ U32.v v < 4294967296 } )
: Tot (validator (parse_constint32le (U32.v v)))
= fun #rrel #rel (input: slice rrel rel) pos ->
let h = HST.get() in
let _ =
valid_constint32le (U32.v v) h input (uint64_to_uint32 pos);
valid_equiv parse_int32le h input (uint64_to_uint32 pos)
in
if U64.lt (Cast.uint32_to_uint64 input.len `U64.sub` pos) 4uL
then
validator_error_not_enough_data
else
let v' = read_int32le input (uint64_to_uint32 pos) in
if U32.eq v v' then
pos `U64.add` 4uL
else
validator_error_generic
inline_for_extraction
let read_constint32le
(v: U32.t { 0 <= U32.v v /\ U32.v v < 4294967296 } )
: Tot (leaf_reader (parse_constint32le (U32.v v)))
= fun #rrel #rel input pos ->
v
inline_for_extraction
let decompose_int32le_0
(v: nat { 0 <= v /\ v < 4294967296 } )
: Tot (b0: nat { 0 <= b0 /\ b0 < 256 } )
= v % 256
inline_for_extraction
let decompose_int32le_1
(v: nat { 0 <= v /\ v < 4294967296 } )
: Tot (b1: nat { 0 <= b1 /\ b1 < 256 } )
= v / 256 % 256
inline_for_extraction
let decompose_int32le_2
(v: nat { 0 <= v /\ v < 4294967296 } )
: Tot (b2: nat { 0 <= b2 /\ b2 < 256 } )
= v / 65536 % 256
inline_for_extraction
let decompose_int32le_3
(v: nat { 0 <= v /\ v < 4294967296 } )
: Tot (b3: nat { 0 <= b3 /\ b3 < 256 } )
= v / 16777216
let compose_int32le
(b0: nat { 0 <= b0 /\ b0 < 256 } )
(b1: nat { 0 <= b1 /\ b1 < 256 } )
(b2: nat { 0 <= b2 /\ b2 < 256 } )
(b3: nat { 0 <= b3 /\ b3 < 256 } )
: Tot (v: nat { 0 <= v /\ v < 4294967296 } )
= b0
+ 256 `FStar.Mul.op_Star` (b1
+ 256 `FStar.Mul.op_Star` (b2
+ 256 `FStar.Mul.op_Star` b3))
#push-options "--z3rlimit 16"
let decompose_compose_equiv
(v: nat { 0 <= v /\ v < 4294967296 } )
: Lemma (compose_int32le (decompose_int32le_0 v) (decompose_int32le_1 v) (decompose_int32le_2 v) (decompose_int32le_3 v) == v)
= ()
#pop-options
inline_for_extraction
let compare_by_bytes
(a0: U8.t { 0 <= U8.v a0 /\ U8.v a0 < 256 } )
(a1: U8.t { 0 <= U8.v a1 /\ U8.v a1 < 256 } )
(a2: U8.t { 0 <= U8.v a2 /\ U8.v a2 < 256 } )
(a3: U8.t { 0 <= U8.v a3 /\ U8.v a3 < 256 } )
(b0: U8.t { 0 <= U8.v b0 /\ U8.v b0 < 256 } )
(b1: U8.t { 0 <= U8.v b1 /\ U8.v b1 < 256 } )
(b2: U8.t { 0 <= U8.v b2 /\ U8.v b2 < 256 } )
(b3: U8.t { 0 <= U8.v b3 /\ U8.v b3 < 256 } )
= a0 = b0 && a1 = b1 && a2 = b2 && a3 = b3
let compare_by_bytes'
(a0: U8.t { 0 <= U8.v a0 /\ U8.v a0 < 256 } )
(a1: U8.t { 0 <= U8.v a1 /\ U8.v a1 < 256 } )
(a2: U8.t { 0 <= U8.v a2 /\ U8.v a2 < 256 } )
(a3: U8.t { 0 <= U8.v a3 /\ U8.v a3 < 256 } )
(b0: U8.t { 0 <= U8.v b0 /\ U8.v b0 < 256 } )
(b1: U8.t { 0 <= U8.v b1 /\ U8.v b1 < 256 } )
(b2: U8.t { 0 <= U8.v b2 /\ U8.v b2 < 256 } )
(b3: U8.t { 0 <= U8.v b3 /\ U8.v b3 < 256 } )
= (compose_int32le (U8.v a0) (U8.v a1) (U8.v a2) (U8.v a3)) =
(compose_int32le (U8.v b0) (U8.v b1) (U8.v b2) (U8.v b3))
#push-options "--max_fuel 5 --z3rlimit 64"
let compare_by_bytes_equiv
(a0: U8.t { 0 <= U8.v a0 /\ U8.v a0 < 256 } )
(a1: U8.t { 0 <= U8.v a1 /\ U8.v a1 < 256 } )
(a2: U8.t { 0 <= U8.v a2 /\ U8.v a2 < 256 } )
(a3: U8.t { 0 <= U8.v a3 /\ U8.v a3 < 256 } )
(b0: U8.t { 0 <= U8.v b0 /\ U8.v b0 < 256 } )
(b1: U8.t { 0 <= U8.v b1 /\ U8.v b1 < 256 } )
(b2: U8.t { 0 <= U8.v b2 /\ U8.v b2 < 256 } )
(b3: U8.t { 0 <= U8.v b3 /\ U8.v b3 < 256 } )
: Lemma
((compare_by_bytes a0 a1 a2 a3 b0 b1 b2 b3) ==
compare_by_bytes' a0 a1 a2 a3 b0 b1 b2 b3)
= let a = compose_int32le (U8.v a0) (U8.v a1) (U8.v a2) (U8.v a3) in
let b = compose_int32le (U8.v b0) (U8.v b1) (U8.v b2) (U8.v b3) in
decompose_compose_equiv a;
decompose_compose_equiv b
#pop-options | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Int32le.fst.checked",
"LowParse.Spec.ConstInt32.fst.checked",
"LowParse.Low.Int32le.fst.checked",
"LowParse.Low.Combinators.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Endianness.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.ConstInt32.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "LowParse.Low.Int32le",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Int32le",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.ConstInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Endianness",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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 | v1: Prims.nat{0 <= v1 /\ v1 < 4294967296} -> v2: Prims.nat{0 <= v2 /\ v2 < 4294967296}
-> FStar.Pervasives.Lemma
(ensures
v1 = v2 ==
LowParse.Low.ConstInt32.compare_by_bytes (FStar.UInt8.uint_to_t (LowParse.Low.ConstInt32.decompose_int32le_0
v1))
(FStar.UInt8.uint_to_t (LowParse.Low.ConstInt32.decompose_int32le_1 v1))
(FStar.UInt8.uint_to_t (LowParse.Low.ConstInt32.decompose_int32le_2 v1))
(FStar.UInt8.uint_to_t (LowParse.Low.ConstInt32.decompose_int32le_3 v1))
(FStar.UInt8.uint_to_t (LowParse.Low.ConstInt32.decompose_int32le_0 v2))
(FStar.UInt8.uint_to_t (LowParse.Low.ConstInt32.decompose_int32le_1 v2))
(FStar.UInt8.uint_to_t (LowParse.Low.ConstInt32.decompose_int32le_2 v2))
(FStar.UInt8.uint_to_t (LowParse.Low.ConstInt32.decompose_int32le_3 v2))) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"LowParse.Low.ConstInt32.decompose_compose_equiv",
"Prims.unit",
"LowParse.Low.ConstInt32.compare_by_bytes_equiv",
"FStar.UInt8.t",
"FStar.UInt8.uint_to_t",
"LowParse.Low.ConstInt32.decompose_int32le_3",
"LowParse.Low.ConstInt32.decompose_int32le_2",
"LowParse.Low.ConstInt32.decompose_int32le_1",
"LowParse.Low.ConstInt32.decompose_int32le_0",
"Prims.l_True",
"Prims.squash",
"Prims.eq2",
"Prims.bool",
"Prims.op_Equality",
"Prims.l_or",
"LowParse.Low.ConstInt32.compare_by_bytes",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let decompose_compare (v1: nat{0 <= v1 /\ v1 < 4294967296}) (v2: nat{0 <= v2 /\ v2 < 4294967296})
: Lemma
((v1 = v2) ==
(compare_by_bytes (U8.uint_to_t (decompose_int32le_0 v1))
(U8.uint_to_t (decompose_int32le_1 v1))
(U8.uint_to_t (decompose_int32le_2 v1))
(U8.uint_to_t (decompose_int32le_3 v1))
(U8.uint_to_t (decompose_int32le_0 v2))
(U8.uint_to_t (decompose_int32le_1 v2))
(U8.uint_to_t (decompose_int32le_2 v2))
(U8.uint_to_t (decompose_int32le_3 v2)))) =
| let a0 = U8.uint_to_t (decompose_int32le_0 v1) in
let a1 = U8.uint_to_t (decompose_int32le_1 v1) in
let a2 = U8.uint_to_t (decompose_int32le_2 v1) in
let a3 = U8.uint_to_t (decompose_int32le_3 v1) in
let b0 = U8.uint_to_t (decompose_int32le_0 v2) in
let b1 = U8.uint_to_t (decompose_int32le_1 v2) in
let b2 = U8.uint_to_t (decompose_int32le_2 v2) in
let b3 = U8.uint_to_t (decompose_int32le_3 v2) in
compare_by_bytes_equiv a0 a1 a2 a3 b0 b1 b2 b3;
decompose_compose_equiv v1;
decompose_compose_equiv v2 | false |
Steel.ST.C.Types.Base.fsti | Steel.ST.C.Types.Base.ref_of_void_ptr | val ref_of_void_ptr
(#t: Type)
(#opened: _)
(#td: typedef t)
(#v: Ghost.erased t)
(x: void_ptr)
(y': Ghost.erased (ref td))
: STAtomicBase (ref td)
false
opened
Unobservable
(pts_to y' v)
(fun y -> pts_to y v)
(Ghost.reveal y' == ghost_ptr_gen_of_void_ptr x t)
(fun y -> y == Ghost.reveal y') | val ref_of_void_ptr
(#t: Type)
(#opened: _)
(#td: typedef t)
(#v: Ghost.erased t)
(x: void_ptr)
(y': Ghost.erased (ref td))
: STAtomicBase (ref td)
false
opened
Unobservable
(pts_to y' v)
(fun y -> pts_to y v)
(Ghost.reveal y' == ghost_ptr_gen_of_void_ptr x t)
(fun y -> y == Ghost.reveal y') | let ref_of_void_ptr (#t: Type) (#opened: _) (#td: typedef t) (#v: Ghost.erased t) (x: void_ptr) (y': Ghost.erased (ref td)) : STAtomicBase (ref td) false opened Unobservable
(pts_to y' v)
(fun y -> pts_to y v)
(Ghost.reveal y' == ghost_ptr_gen_of_void_ptr x t)
(fun y -> y == Ghost.reveal y')
= rewrite (pts_to y' v) (pts_to_or_null (ghost_ptr_gen_of_void_ptr x t <: ptr td) v);
let y = ptr_of_void_ptr x in
rewrite (pts_to_or_null y v) (pts_to y v);
return y | {
"file_name": "lib/steel/c/Steel.ST.C.Types.Base.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 10,
"end_line": 184,
"start_col": 0,
"start_line": 176
} | module Steel.ST.C.Types.Base
open Steel.ST.Util
module P = Steel.FractionalPermission
/// Helper to compose two permissions into one
val prod_perm (p1 p2: P.perm) : Pure P.perm
(requires True)
(ensures (fun p ->
((p1 `P.lesser_equal_perm` P.full_perm /\ p2 `P.lesser_equal_perm` P.full_perm) ==>
p `P.lesser_equal_perm` P.full_perm) /\
p.v == (let open FStar.Real in p1.v *. p2.v)
))
[@@noextract_to "krml"] // proof-only
val typedef (t: Type0) : Type0
inline_for_extraction [@@noextract_to "krml"]
let typeof (#t: Type0) (td: typedef t) : Tot Type0 = t
val fractionable (#t: Type0) (td: typedef t) (x: t) : GTot prop
val mk_fraction (#t: Type0) (td: typedef t) (x: t) (p: P.perm) : Ghost t
(requires (fractionable td x))
(ensures (fun y -> p `P.lesser_equal_perm` P.full_perm ==> fractionable td y))
val mk_fraction_full (#t: Type0) (td: typedef t) (x: t) : Lemma
(requires (fractionable td x))
(ensures (mk_fraction td x P.full_perm == x))
[SMTPat (mk_fraction td x P.full_perm)]
val mk_fraction_compose (#t: Type0) (td: typedef t) (x: t) (p1 p2: P.perm) : Lemma
(requires (fractionable td x /\ p1 `P.lesser_equal_perm` P.full_perm /\ p2 `P.lesser_equal_perm` P.full_perm))
(ensures (mk_fraction td (mk_fraction td x p1) p2 == mk_fraction td x (p1 `prod_perm` p2)))
val full (#t: Type0) (td: typedef t) (v: t) : GTot prop
val uninitialized (#t: Type0) (td: typedef t) : Ghost t
(requires True)
(ensures (fun y -> full td y /\ fractionable td y))
val unknown (#t: Type0) (td: typedef t) : Ghost t
(requires True)
(ensures (fun y -> fractionable td y))
val full_not_unknown
(#t: Type)
(td: typedef t)
(v: t)
: Lemma
(requires (full td v))
(ensures (~ (v == unknown td)))
[SMTPat (full td v)]
val mk_fraction_unknown (#t: Type0) (td: typedef t) (p: P.perm) : Lemma
(ensures (mk_fraction td (unknown td) p == unknown td))
val mk_fraction_eq_unknown (#t: Type0) (td: typedef t) (v: t) (p: P.perm) : Lemma
(requires (fractionable td v /\ mk_fraction td v p == unknown td))
(ensures (v == unknown td))
// To be extracted as: void*
[@@noextract_to "krml"] // primitive
val void_ptr : Type0
// To be extracted as: NULL
[@@noextract_to "krml"] // primitive
val void_null: void_ptr
// To be extracted as: *t
[@@noextract_to "krml"] // primitive
val ptr_gen ([@@@unused] t: Type) : Type0
[@@noextract_to "krml"] // primitive
val null_gen (t: Type) : Tot (ptr_gen t)
val ghost_void_ptr_of_ptr_gen (#[@@@unused] t: Type) (x: ptr_gen t) : GTot void_ptr
val ghost_ptr_gen_of_void_ptr (x: void_ptr) ([@@@unused] t: Type) : GTot (ptr_gen t)
val ghost_void_ptr_of_ptr_gen_of_void_ptr
(x: void_ptr)
(t: Type)
: Lemma
(ghost_void_ptr_of_ptr_gen (ghost_ptr_gen_of_void_ptr x t) == x)
[SMTPat (ghost_void_ptr_of_ptr_gen (ghost_ptr_gen_of_void_ptr x t))]
val ghost_ptr_gen_of_void_ptr_of_ptr_gen
(#t: Type)
(x: ptr_gen t)
: Lemma
(ghost_ptr_gen_of_void_ptr (ghost_void_ptr_of_ptr_gen x) t == x)
[SMTPat (ghost_ptr_gen_of_void_ptr (ghost_void_ptr_of_ptr_gen x) t)]
inline_for_extraction [@@noextract_to "krml"] // primitive
let ptr (#t: Type) (td: typedef t) : Tot Type0 = ptr_gen t
inline_for_extraction [@@noextract_to "krml"] // primitive
let null (#t: Type) (td: typedef t) : Tot (ptr td) = null_gen t
inline_for_extraction [@@noextract_to "krml"]
let ref (#t: Type) (td: typedef t) : Tot Type0 = (p: ptr td { ~ (p == null td) })
val pts_to (#t: Type) (#td: typedef t) (r: ref td) ([@@@smt_fallback] v: Ghost.erased t) : vprop
let pts_to_or_null
(#t: Type) (#td: typedef t) (p: ptr td) (v: Ghost.erased t) : vprop
= if FStar.StrongExcludedMiddle.strong_excluded_middle (p == null _)
then emp
else pts_to p v
[@@noextract_to "krml"] // primitive
val is_null
(#t: Type)
(#opened: _)
(#td: typedef t)
(#v: Ghost.erased t)
(p: ptr td)
: STAtomicBase bool false opened Unobservable
(pts_to_or_null p v)
(fun _ -> pts_to_or_null p v)
(True)
(fun res -> res == true <==> p == null _)
let assert_null
(#t: Type)
(#opened: _)
(#td: typedef t)
(#v: Ghost.erased t)
(p: ptr td)
: STGhost unit opened
(pts_to_or_null p v)
(fun _ -> emp)
(p == null _)
(fun _ -> True)
= rewrite (pts_to_or_null p v) emp
let assert_not_null
(#t: Type)
(#opened: _)
(#td: typedef t)
(#v: Ghost.erased t)
(p: ptr td)
: STGhost (squash (~ (p == null _))) opened
(pts_to_or_null p v)
(fun _ -> pts_to p v)
(~ (p == null _))
(fun _ -> True)
= rewrite (pts_to_or_null p v) (pts_to p v)
[@@noextract_to "krml"] // primitive
val void_ptr_of_ptr (#t: Type) (#opened: _) (#td: typedef t) (#v: Ghost.erased t) (x: ptr td) : STAtomicBase void_ptr false opened Unobservable
(pts_to_or_null x v)
(fun _ -> pts_to_or_null x v)
True
(fun y -> y == ghost_void_ptr_of_ptr_gen x)
[@@noextract_to "krml"] inline_for_extraction
let void_ptr_of_ref (#t: Type) (#opened: _) (#td: typedef t) (#v: Ghost.erased t) (x: ref td) : STAtomicBase void_ptr false opened Unobservable
(pts_to x v)
(fun _ -> pts_to x v)
True
(fun y -> y == ghost_void_ptr_of_ptr_gen x)
= rewrite (pts_to x v) (pts_to_or_null x v);
let res = void_ptr_of_ptr x in
rewrite (pts_to_or_null x v) (pts_to x v);
return res
[@@noextract_to "krml"] // primitive
val ptr_of_void_ptr (#t: Type) (#opened: _) (#td: typedef t) (#v: Ghost.erased t) (x: void_ptr) : STAtomicBase (ptr td) false opened Unobservable
(pts_to_or_null (ghost_ptr_gen_of_void_ptr x t <: ptr td) v)
(fun y -> pts_to_or_null y v)
True
(fun y -> y == ghost_ptr_gen_of_void_ptr x t) | {
"checked_file": "/",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"Steel.FractionalPermission.fst.checked",
"prims.fst.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Real.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.ST.C.Types.Base.fsti"
} | [
{
"abbrev": true,
"full_module": "Steel.FractionalPermission",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.C.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.C.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: Steel.ST.C.Types.Base.void_ptr -> y': FStar.Ghost.erased (Steel.ST.C.Types.Base.ref td)
-> Steel.ST.Effect.Atomic.STAtomicBase (Steel.ST.C.Types.Base.ref td) | Steel.ST.Effect.Atomic.STAtomicBase | [] | [] | [
"Steel.Memory.inames",
"Steel.ST.C.Types.Base.typedef",
"FStar.Ghost.erased",
"Steel.ST.C.Types.Base.void_ptr",
"Steel.ST.C.Types.Base.ref",
"Steel.ST.Util.return",
"Steel.ST.C.Types.Base.pts_to",
"Steel.Effect.Common.vprop",
"Prims.unit",
"Steel.ST.Util.rewrite",
"Steel.ST.C.Types.Base.pts_to_or_null",
"Steel.ST.C.Types.Base.ptr",
"Steel.ST.C.Types.Base.ptr_of_void_ptr",
"FStar.Ghost.reveal",
"Steel.ST.C.Types.Base.ghost_ptr_gen_of_void_ptr",
"Steel.Effect.Common.Unobservable",
"Prims.eq2",
"Steel.ST.C.Types.Base.ptr_gen",
"Prims.l_True"
] | [] | false | true | false | false | false | let ref_of_void_ptr
(#t: Type)
(#opened: _)
(#td: typedef t)
(#v: Ghost.erased t)
(x: void_ptr)
(y': Ghost.erased (ref td))
: STAtomicBase (ref td)
false
opened
Unobservable
(pts_to y' v)
(fun y -> pts_to y v)
(Ghost.reveal y' == ghost_ptr_gen_of_void_ptr x t)
(fun y -> y == Ghost.reveal y') =
| rewrite (pts_to y' v) (pts_to_or_null (ghost_ptr_gen_of_void_ptr x t <: ptr td) v);
let y = ptr_of_void_ptr x in
rewrite (pts_to_or_null y v) (pts_to y v);
return y | false |
Spec.FFDHE.fst | Spec.FFDHE.list_ffdhe_g2 | val list_ffdhe_g2:List.Tot.llist pub_uint8 1 | val list_ffdhe_g2:List.Tot.llist pub_uint8 1 | let list_ffdhe_g2: List.Tot.llist pub_uint8 1 =
[@inline_let]
let l = [ 0x02uy ] in
assert_norm (List.Tot.length l == 1);
l | {
"file_name": "specs/Spec.FFDHE.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 3,
"end_line": 28,
"start_col": 0,
"start_line": 24
} | module Spec.FFDHE
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
(** https://tools.ietf.org/html/rfc7919#appendix-A *)
noeq type ffdhe_params_t =
| Mk_ffdhe_params:
ffdhe_p_len:size_nat
-> ffdhe_p:lseq pub_uint8 ffdhe_p_len
-> ffdhe_g_len:size_nat
-> ffdhe_g:lseq pub_uint8 ffdhe_g_len
-> ffdhe_params_t
[@"opaque_to_smt"] | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NatMod.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "Spec.FFDHE.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 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 | FStar.List.Tot.Properties.llist (Lib.IntTypes.int_t Lib.IntTypes.U8 Lib.IntTypes.PUB) 1 | Prims.Tot | [
"total"
] | [] | [
"Prims.unit",
"FStar.Pervasives.assert_norm",
"Prims.eq2",
"Prims.int",
"FStar.List.Tot.Base.length",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.PUB",
"Prims.list",
"Prims.Cons",
"FStar.UInt8.__uint_to_t",
"Prims.Nil"
] | [] | false | false | false | false | false | let list_ffdhe_g2:List.Tot.llist pub_uint8 1 =
| [@@ inline_let ]let l = [0x02uy] in
assert_norm (List.Tot.length l == 1);
l | false |
Spec.FFDHE.fst | Spec.FFDHE.ffdhe_params_4096 | val ffdhe_params_4096:ffdhe_params_t | val ffdhe_params_4096:ffdhe_params_t | let ffdhe_params_4096 : ffdhe_params_t =
Mk_ffdhe_params 512 ffdhe_p4096 1 ffdhe_g2 | {
"file_name": "specs/Spec.FFDHE.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 44,
"end_line": 222,
"start_col": 0,
"start_line": 221
} | module Spec.FFDHE
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
(** https://tools.ietf.org/html/rfc7919#appendix-A *)
noeq type ffdhe_params_t =
| Mk_ffdhe_params:
ffdhe_p_len:size_nat
-> ffdhe_p:lseq pub_uint8 ffdhe_p_len
-> ffdhe_g_len:size_nat
-> ffdhe_g:lseq pub_uint8 ffdhe_g_len
-> ffdhe_params_t
[@"opaque_to_smt"]
inline_for_extraction
let list_ffdhe_g2: List.Tot.llist pub_uint8 1 =
[@inline_let]
let l = [ 0x02uy ] in
assert_norm (List.Tot.length l == 1);
l
let ffdhe_g2: lseq pub_uint8 1 = of_list list_ffdhe_g2
[@"opaque_to_smt"]
inline_for_extraction
let list_ffdhe_p2048: List.Tot.llist pub_uint8 256 =
[@inline_let]
let l = [
0xFFuy; 0xFFuy; 0xFFuy; 0xFFuy; 0xFFuy; 0xFFuy; 0xFFuy; 0xFFuy;
0xADuy; 0xF8uy; 0x54uy; 0x58uy; 0xA2uy; 0xBBuy; 0x4Auy; 0x9Auy;
0xAFuy; 0xDCuy; 0x56uy; 0x20uy; 0x27uy; 0x3Duy; 0x3Cuy; 0xF1uy;
0xD8uy; 0xB9uy; 0xC5uy; 0x83uy; 0xCEuy; 0x2Duy; 0x36uy; 0x95uy;
0xA9uy; 0xE1uy; 0x36uy; 0x41uy; 0x14uy; 0x64uy; 0x33uy; 0xFBuy;
0xCCuy; 0x93uy; 0x9Duy; 0xCEuy; 0x24uy; 0x9Buy; 0x3Euy; 0xF9uy;
0x7Duy; 0x2Fuy; 0xE3uy; 0x63uy; 0x63uy; 0x0Cuy; 0x75uy; 0xD8uy;
0xF6uy; 0x81uy; 0xB2uy; 0x02uy; 0xAEuy; 0xC4uy; 0x61uy; 0x7Auy;
0xD3uy; 0xDFuy; 0x1Euy; 0xD5uy; 0xD5uy; 0xFDuy; 0x65uy; 0x61uy;
0x24uy; 0x33uy; 0xF5uy; 0x1Fuy; 0x5Fuy; 0x06uy; 0x6Euy; 0xD0uy;
0x85uy; 0x63uy; 0x65uy; 0x55uy; 0x3Duy; 0xEDuy; 0x1Auy; 0xF3uy;
0xB5uy; 0x57uy; 0x13uy; 0x5Euy; 0x7Fuy; 0x57uy; 0xC9uy; 0x35uy;
0x98uy; 0x4Fuy; 0x0Cuy; 0x70uy; 0xE0uy; 0xE6uy; 0x8Buy; 0x77uy;
0xE2uy; 0xA6uy; 0x89uy; 0xDAuy; 0xF3uy; 0xEFuy; 0xE8uy; 0x72uy;
0x1Duy; 0xF1uy; 0x58uy; 0xA1uy; 0x36uy; 0xADuy; 0xE7uy; 0x35uy;
0x30uy; 0xACuy; 0xCAuy; 0x4Fuy; 0x48uy; 0x3Auy; 0x79uy; 0x7Auy;
0xBCuy; 0x0Auy; 0xB1uy; 0x82uy; 0xB3uy; 0x24uy; 0xFBuy; 0x61uy;
0xD1uy; 0x08uy; 0xA9uy; 0x4Buy; 0xB2uy; 0xC8uy; 0xE3uy; 0xFBuy;
0xB9uy; 0x6Auy; 0xDAuy; 0xB7uy; 0x60uy; 0xD7uy; 0xF4uy; 0x68uy;
0x1Duy; 0x4Fuy; 0x42uy; 0xA3uy; 0xDEuy; 0x39uy; 0x4Duy; 0xF4uy;
0xAEuy; 0x56uy; 0xEDuy; 0xE7uy; 0x63uy; 0x72uy; 0xBBuy; 0x19uy;
0x0Buy; 0x07uy; 0xA7uy; 0xC8uy; 0xEEuy; 0x0Auy; 0x6Duy; 0x70uy;
0x9Euy; 0x02uy; 0xFCuy; 0xE1uy; 0xCDuy; 0xF7uy; 0xE2uy; 0xECuy;
0xC0uy; 0x34uy; 0x04uy; 0xCDuy; 0x28uy; 0x34uy; 0x2Fuy; 0x61uy;
0x91uy; 0x72uy; 0xFEuy; 0x9Cuy; 0xE9uy; 0x85uy; 0x83uy; 0xFFuy;
0x8Euy; 0x4Fuy; 0x12uy; 0x32uy; 0xEEuy; 0xF2uy; 0x81uy; 0x83uy;
0xC3uy; 0xFEuy; 0x3Buy; 0x1Buy; 0x4Cuy; 0x6Fuy; 0xADuy; 0x73uy;
0x3Buy; 0xB5uy; 0xFCuy; 0xBCuy; 0x2Euy; 0xC2uy; 0x20uy; 0x05uy;
0xC5uy; 0x8Euy; 0xF1uy; 0x83uy; 0x7Duy; 0x16uy; 0x83uy; 0xB2uy;
0xC6uy; 0xF3uy; 0x4Auy; 0x26uy; 0xC1uy; 0xB2uy; 0xEFuy; 0xFAuy;
0x88uy; 0x6Buy; 0x42uy; 0x38uy; 0x61uy; 0x28uy; 0x5Cuy; 0x97uy;
0xFFuy; 0xFFuy; 0xFFuy; 0xFFuy; 0xFFuy; 0xFFuy; 0xFFuy; 0xFFuy
] in
assert_norm (List.Tot.length l == 256);
l
let ffdhe_p2048: lseq pub_uint8 256 = of_list list_ffdhe_p2048
// The estimated symmetric-equivalent strength of this group is 103 bits.
let ffdhe_params_2048 : ffdhe_params_t =
Mk_ffdhe_params 256 ffdhe_p2048 1 ffdhe_g2
[@"opaque_to_smt"]
inline_for_extraction
let list_ffdhe_p3072: List.Tot.llist pub_uint8 384 =
[@inline_let]
let l = [
0xFFuy; 0xFFuy; 0xFFuy; 0xFFuy; 0xFFuy; 0xFFuy; 0xFFuy; 0xFFuy;
0xADuy; 0xF8uy; 0x54uy; 0x58uy; 0xA2uy; 0xBBuy; 0x4Auy; 0x9Auy;
0xAFuy; 0xDCuy; 0x56uy; 0x20uy; 0x27uy; 0x3Duy; 0x3Cuy; 0xF1uy;
0xD8uy; 0xB9uy; 0xC5uy; 0x83uy; 0xCEuy; 0x2Duy; 0x36uy; 0x95uy;
0xA9uy; 0xE1uy; 0x36uy; 0x41uy; 0x14uy; 0x64uy; 0x33uy; 0xFBuy;
0xCCuy; 0x93uy; 0x9Duy; 0xCEuy; 0x24uy; 0x9Buy; 0x3Euy; 0xF9uy;
0x7Duy; 0x2Fuy; 0xE3uy; 0x63uy; 0x63uy; 0x0Cuy; 0x75uy; 0xD8uy;
0xF6uy; 0x81uy; 0xB2uy; 0x02uy; 0xAEuy; 0xC4uy; 0x61uy; 0x7Auy;
0xD3uy; 0xDFuy; 0x1Euy; 0xD5uy; 0xD5uy; 0xFDuy; 0x65uy; 0x61uy;
0x24uy; 0x33uy; 0xF5uy; 0x1Fuy; 0x5Fuy; 0x06uy; 0x6Euy; 0xD0uy;
0x85uy; 0x63uy; 0x65uy; 0x55uy; 0x3Duy; 0xEDuy; 0x1Auy; 0xF3uy;
0xB5uy; 0x57uy; 0x13uy; 0x5Euy; 0x7Fuy; 0x57uy; 0xC9uy; 0x35uy;
0x98uy; 0x4Fuy; 0x0Cuy; 0x70uy; 0xE0uy; 0xE6uy; 0x8Buy; 0x77uy;
0xE2uy; 0xA6uy; 0x89uy; 0xDAuy; 0xF3uy; 0xEFuy; 0xE8uy; 0x72uy;
0x1Duy; 0xF1uy; 0x58uy; 0xA1uy; 0x36uy; 0xADuy; 0xE7uy; 0x35uy;
0x30uy; 0xACuy; 0xCAuy; 0x4Fuy; 0x48uy; 0x3Auy; 0x79uy; 0x7Auy;
0xBCuy; 0x0Auy; 0xB1uy; 0x82uy; 0xB3uy; 0x24uy; 0xFBuy; 0x61uy;
0xD1uy; 0x08uy; 0xA9uy; 0x4Buy; 0xB2uy; 0xC8uy; 0xE3uy; 0xFBuy;
0xB9uy; 0x6Auy; 0xDAuy; 0xB7uy; 0x60uy; 0xD7uy; 0xF4uy; 0x68uy;
0x1Duy; 0x4Fuy; 0x42uy; 0xA3uy; 0xDEuy; 0x39uy; 0x4Duy; 0xF4uy;
0xAEuy; 0x56uy; 0xEDuy; 0xE7uy; 0x63uy; 0x72uy; 0xBBuy; 0x19uy;
0x0Buy; 0x07uy; 0xA7uy; 0xC8uy; 0xEEuy; 0x0Auy; 0x6Duy; 0x70uy;
0x9Euy; 0x02uy; 0xFCuy; 0xE1uy; 0xCDuy; 0xF7uy; 0xE2uy; 0xECuy;
0xC0uy; 0x34uy; 0x04uy; 0xCDuy; 0x28uy; 0x34uy; 0x2Fuy; 0x61uy;
0x91uy; 0x72uy; 0xFEuy; 0x9Cuy; 0xE9uy; 0x85uy; 0x83uy; 0xFFuy;
0x8Euy; 0x4Fuy; 0x12uy; 0x32uy; 0xEEuy; 0xF2uy; 0x81uy; 0x83uy;
0xC3uy; 0xFEuy; 0x3Buy; 0x1Buy; 0x4Cuy; 0x6Fuy; 0xADuy; 0x73uy;
0x3Buy; 0xB5uy; 0xFCuy; 0xBCuy; 0x2Euy; 0xC2uy; 0x20uy; 0x05uy;
0xC5uy; 0x8Euy; 0xF1uy; 0x83uy; 0x7Duy; 0x16uy; 0x83uy; 0xB2uy;
0xC6uy; 0xF3uy; 0x4Auy; 0x26uy; 0xC1uy; 0xB2uy; 0xEFuy; 0xFAuy;
0x88uy; 0x6Buy; 0x42uy; 0x38uy; 0x61uy; 0x1Fuy; 0xCFuy; 0xDCuy;
0xDEuy; 0x35uy; 0x5Buy; 0x3Buy; 0x65uy; 0x19uy; 0x03uy; 0x5Buy;
0xBCuy; 0x34uy; 0xF4uy; 0xDEuy; 0xF9uy; 0x9Cuy; 0x02uy; 0x38uy;
0x61uy; 0xB4uy; 0x6Fuy; 0xC9uy; 0xD6uy; 0xE6uy; 0xC9uy; 0x07uy;
0x7Auy; 0xD9uy; 0x1Duy; 0x26uy; 0x91uy; 0xF7uy; 0xF7uy; 0xEEuy;
0x59uy; 0x8Cuy; 0xB0uy; 0xFAuy; 0xC1uy; 0x86uy; 0xD9uy; 0x1Cuy;
0xAEuy; 0xFEuy; 0x13uy; 0x09uy; 0x85uy; 0x13uy; 0x92uy; 0x70uy;
0xB4uy; 0x13uy; 0x0Cuy; 0x93uy; 0xBCuy; 0x43uy; 0x79uy; 0x44uy;
0xF4uy; 0xFDuy; 0x44uy; 0x52uy; 0xE2uy; 0xD7uy; 0x4Duy; 0xD3uy;
0x64uy; 0xF2uy; 0xE2uy; 0x1Euy; 0x71uy; 0xF5uy; 0x4Buy; 0xFFuy;
0x5Cuy; 0xAEuy; 0x82uy; 0xABuy; 0x9Cuy; 0x9Duy; 0xF6uy; 0x9Euy;
0xE8uy; 0x6Duy; 0x2Buy; 0xC5uy; 0x22uy; 0x36uy; 0x3Auy; 0x0Duy;
0xABuy; 0xC5uy; 0x21uy; 0x97uy; 0x9Buy; 0x0Duy; 0xEAuy; 0xDAuy;
0x1Duy; 0xBFuy; 0x9Auy; 0x42uy; 0xD5uy; 0xC4uy; 0x48uy; 0x4Euy;
0x0Auy; 0xBCuy; 0xD0uy; 0x6Buy; 0xFAuy; 0x53uy; 0xDDuy; 0xEFuy;
0x3Cuy; 0x1Buy; 0x20uy; 0xEEuy; 0x3Fuy; 0xD5uy; 0x9Duy; 0x7Cuy;
0x25uy; 0xE4uy; 0x1Duy; 0x2Buy; 0x66uy; 0xC6uy; 0x2Euy; 0x37uy;
0xFFuy; 0xFFuy; 0xFFuy; 0xFFuy; 0xFFuy; 0xFFuy; 0xFFuy; 0xFFuy
] in
assert_norm (List.Tot.length l == 384);
l
let ffdhe_p3072: lseq pub_uint8 384 = of_list list_ffdhe_p3072
// The estimated symmetric-equivalent strength of this group is 125 bits.
let ffdhe_params_3072 : ffdhe_params_t =
Mk_ffdhe_params 384 ffdhe_p3072 1 ffdhe_g2
[@"opaque_to_smt"]
inline_for_extraction
let list_ffdhe_p4096: List.Tot.llist pub_uint8 512 =
[@inline_let]
let l = [
0xFFuy; 0xFFuy; 0xFFuy; 0xFFuy; 0xFFuy; 0xFFuy; 0xFFuy; 0xFFuy;
0xADuy; 0xF8uy; 0x54uy; 0x58uy; 0xA2uy; 0xBBuy; 0x4Auy; 0x9Auy;
0xAFuy; 0xDCuy; 0x56uy; 0x20uy; 0x27uy; 0x3Duy; 0x3Cuy; 0xF1uy;
0xD8uy; 0xB9uy; 0xC5uy; 0x83uy; 0xCEuy; 0x2Duy; 0x36uy; 0x95uy;
0xA9uy; 0xE1uy; 0x36uy; 0x41uy; 0x14uy; 0x64uy; 0x33uy; 0xFBuy;
0xCCuy; 0x93uy; 0x9Duy; 0xCEuy; 0x24uy; 0x9Buy; 0x3Euy; 0xF9uy;
0x7Duy; 0x2Fuy; 0xE3uy; 0x63uy; 0x63uy; 0x0Cuy; 0x75uy; 0xD8uy;
0xF6uy; 0x81uy; 0xB2uy; 0x02uy; 0xAEuy; 0xC4uy; 0x61uy; 0x7Auy;
0xD3uy; 0xDFuy; 0x1Euy; 0xD5uy; 0xD5uy; 0xFDuy; 0x65uy; 0x61uy;
0x24uy; 0x33uy; 0xF5uy; 0x1Fuy; 0x5Fuy; 0x06uy; 0x6Euy; 0xD0uy;
0x85uy; 0x63uy; 0x65uy; 0x55uy; 0x3Duy; 0xEDuy; 0x1Auy; 0xF3uy;
0xB5uy; 0x57uy; 0x13uy; 0x5Euy; 0x7Fuy; 0x57uy; 0xC9uy; 0x35uy;
0x98uy; 0x4Fuy; 0x0Cuy; 0x70uy; 0xE0uy; 0xE6uy; 0x8Buy; 0x77uy;
0xE2uy; 0xA6uy; 0x89uy; 0xDAuy; 0xF3uy; 0xEFuy; 0xE8uy; 0x72uy;
0x1Duy; 0xF1uy; 0x58uy; 0xA1uy; 0x36uy; 0xADuy; 0xE7uy; 0x35uy;
0x30uy; 0xACuy; 0xCAuy; 0x4Fuy; 0x48uy; 0x3Auy; 0x79uy; 0x7Auy;
0xBCuy; 0x0Auy; 0xB1uy; 0x82uy; 0xB3uy; 0x24uy; 0xFBuy; 0x61uy;
0xD1uy; 0x08uy; 0xA9uy; 0x4Buy; 0xB2uy; 0xC8uy; 0xE3uy; 0xFBuy;
0xB9uy; 0x6Auy; 0xDAuy; 0xB7uy; 0x60uy; 0xD7uy; 0xF4uy; 0x68uy;
0x1Duy; 0x4Fuy; 0x42uy; 0xA3uy; 0xDEuy; 0x39uy; 0x4Duy; 0xF4uy;
0xAEuy; 0x56uy; 0xEDuy; 0xE7uy; 0x63uy; 0x72uy; 0xBBuy; 0x19uy;
0x0Buy; 0x07uy; 0xA7uy; 0xC8uy; 0xEEuy; 0x0Auy; 0x6Duy; 0x70uy;
0x9Euy; 0x02uy; 0xFCuy; 0xE1uy; 0xCDuy; 0xF7uy; 0xE2uy; 0xECuy;
0xC0uy; 0x34uy; 0x04uy; 0xCDuy; 0x28uy; 0x34uy; 0x2Fuy; 0x61uy;
0x91uy; 0x72uy; 0xFEuy; 0x9Cuy; 0xE9uy; 0x85uy; 0x83uy; 0xFFuy;
0x8Euy; 0x4Fuy; 0x12uy; 0x32uy; 0xEEuy; 0xF2uy; 0x81uy; 0x83uy;
0xC3uy; 0xFEuy; 0x3Buy; 0x1Buy; 0x4Cuy; 0x6Fuy; 0xADuy; 0x73uy;
0x3Buy; 0xB5uy; 0xFCuy; 0xBCuy; 0x2Euy; 0xC2uy; 0x20uy; 0x05uy;
0xC5uy; 0x8Euy; 0xF1uy; 0x83uy; 0x7Duy; 0x16uy; 0x83uy; 0xB2uy;
0xC6uy; 0xF3uy; 0x4Auy; 0x26uy; 0xC1uy; 0xB2uy; 0xEFuy; 0xFAuy;
0x88uy; 0x6Buy; 0x42uy; 0x38uy; 0x61uy; 0x1Fuy; 0xCFuy; 0xDCuy;
0xDEuy; 0x35uy; 0x5Buy; 0x3Buy; 0x65uy; 0x19uy; 0x03uy; 0x5Buy;
0xBCuy; 0x34uy; 0xF4uy; 0xDEuy; 0xF9uy; 0x9Cuy; 0x02uy; 0x38uy;
0x61uy; 0xB4uy; 0x6Fuy; 0xC9uy; 0xD6uy; 0xE6uy; 0xC9uy; 0x07uy;
0x7Auy; 0xD9uy; 0x1Duy; 0x26uy; 0x91uy; 0xF7uy; 0xF7uy; 0xEEuy;
0x59uy; 0x8Cuy; 0xB0uy; 0xFAuy; 0xC1uy; 0x86uy; 0xD9uy; 0x1Cuy;
0xAEuy; 0xFEuy; 0x13uy; 0x09uy; 0x85uy; 0x13uy; 0x92uy; 0x70uy;
0xB4uy; 0x13uy; 0x0Cuy; 0x93uy; 0xBCuy; 0x43uy; 0x79uy; 0x44uy;
0xF4uy; 0xFDuy; 0x44uy; 0x52uy; 0xE2uy; 0xD7uy; 0x4Duy; 0xD3uy;
0x64uy; 0xF2uy; 0xE2uy; 0x1Euy; 0x71uy; 0xF5uy; 0x4Buy; 0xFFuy;
0x5Cuy; 0xAEuy; 0x82uy; 0xABuy; 0x9Cuy; 0x9Duy; 0xF6uy; 0x9Euy;
0xE8uy; 0x6Duy; 0x2Buy; 0xC5uy; 0x22uy; 0x36uy; 0x3Auy; 0x0Duy;
0xABuy; 0xC5uy; 0x21uy; 0x97uy; 0x9Buy; 0x0Duy; 0xEAuy; 0xDAuy;
0x1Duy; 0xBFuy; 0x9Auy; 0x42uy; 0xD5uy; 0xC4uy; 0x48uy; 0x4Euy;
0x0Auy; 0xBCuy; 0xD0uy; 0x6Buy; 0xFAuy; 0x53uy; 0xDDuy; 0xEFuy;
0x3Cuy; 0x1Buy; 0x20uy; 0xEEuy; 0x3Fuy; 0xD5uy; 0x9Duy; 0x7Cuy;
0x25uy; 0xE4uy; 0x1Duy; 0x2Buy; 0x66uy; 0x9Euy; 0x1Euy; 0xF1uy;
0x6Euy; 0x6Fuy; 0x52uy; 0xC3uy; 0x16uy; 0x4Duy; 0xF4uy; 0xFBuy;
0x79uy; 0x30uy; 0xE9uy; 0xE4uy; 0xE5uy; 0x88uy; 0x57uy; 0xB6uy;
0xACuy; 0x7Duy; 0x5Fuy; 0x42uy; 0xD6uy; 0x9Fuy; 0x6Duy; 0x18uy;
0x77uy; 0x63uy; 0xCFuy; 0x1Duy; 0x55uy; 0x03uy; 0x40uy; 0x04uy;
0x87uy; 0xF5uy; 0x5Buy; 0xA5uy; 0x7Euy; 0x31uy; 0xCCuy; 0x7Auy;
0x71uy; 0x35uy; 0xC8uy; 0x86uy; 0xEFuy; 0xB4uy; 0x31uy; 0x8Auy;
0xEDuy; 0x6Auy; 0x1Euy; 0x01uy; 0x2Duy; 0x9Euy; 0x68uy; 0x32uy;
0xA9uy; 0x07uy; 0x60uy; 0x0Auy; 0x91uy; 0x81uy; 0x30uy; 0xC4uy;
0x6Duy; 0xC7uy; 0x78uy; 0xF9uy; 0x71uy; 0xADuy; 0x00uy; 0x38uy;
0x09uy; 0x29uy; 0x99uy; 0xA3uy; 0x33uy; 0xCBuy; 0x8Buy; 0x7Auy;
0x1Auy; 0x1Duy; 0xB9uy; 0x3Duy; 0x71uy; 0x40uy; 0x00uy; 0x3Cuy;
0x2Auy; 0x4Euy; 0xCEuy; 0xA9uy; 0xF9uy; 0x8Duy; 0x0Auy; 0xCCuy;
0x0Auy; 0x82uy; 0x91uy; 0xCDuy; 0xCEuy; 0xC9uy; 0x7Duy; 0xCFuy;
0x8Euy; 0xC9uy; 0xB5uy; 0x5Auy; 0x7Fuy; 0x88uy; 0xA4uy; 0x6Buy;
0x4Duy; 0xB5uy; 0xA8uy; 0x51uy; 0xF4uy; 0x41uy; 0x82uy; 0xE1uy;
0xC6uy; 0x8Auy; 0x00uy; 0x7Euy; 0x5Euy; 0x65uy; 0x5Fuy; 0x6Auy;
0xFFuy; 0xFFuy; 0xFFuy; 0xFFuy; 0xFFuy; 0xFFuy; 0xFFuy; 0xFFuy
] in
assert_norm (List.Tot.length l == 512);
l
let ffdhe_p4096: lseq pub_uint8 512 = of_list list_ffdhe_p4096 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NatMod.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "Spec.FFDHE.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 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.FFDHE.ffdhe_params_t | Prims.Tot | [
"total"
] | [] | [
"Spec.FFDHE.Mk_ffdhe_params",
"Spec.FFDHE.ffdhe_p4096",
"Spec.FFDHE.ffdhe_g2"
] | [] | false | false | false | true | false | let ffdhe_params_4096:ffdhe_params_t =
| Mk_ffdhe_params 512 ffdhe_p4096 1 ffdhe_g2 | false |
LowParse.Low.ConstInt32.fst | LowParse.Low.ConstInt32.validate_constint32le_slow | val validate_constint32le_slow (v: U32.t{0 <= U32.v v /\ U32.v v < 4294967296})
: Tot (validator (parse_constint32le (U32.v v))) | val validate_constint32le_slow (v: U32.t{0 <= U32.v v /\ U32.v v < 4294967296})
: Tot (validator (parse_constint32le (U32.v v))) | let validate_constint32le_slow
(v: U32.t { 0 <= U32.v v /\ U32.v v < 4294967296 } )
: Tot (validator (parse_constint32le (U32.v v)))
= fun #rrel #rel (input: slice rrel rel) pos ->
let h = HST.get() in
let _ =
valid_constint32le (U32.v v) h input (uint64_to_uint32 pos);
valid_equiv parse_int32le h input (uint64_to_uint32 pos)
in
if U64.lt (Cast.uint32_to_uint64 input.len `U64.sub` pos) 4uL
then
validator_error_not_enough_data
else
let v' = read_int32le input (uint64_to_uint32 pos) in
if U32.eq v v' then
pos `U64.add` 4uL
else
validator_error_generic | {
"file_name": "src/lowparse/LowParse.Low.ConstInt32.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 29,
"end_line": 52,
"start_col": 0,
"start_line": 35
} | module LowParse.Low.ConstInt32
(* LowParse implementation module for 32 bits contants *)
include FStar.Endianness
include LowParse.Spec.ConstInt32
include LowParse.Spec.Int32le
include LowParse.Low.Combinators
include LowParse.Low.Int32le
module U32 = FStar.UInt32
module U8 = FStar.UInt8
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module B = LowStar.Buffer
module Cast = FStar.Int.Cast
module U64 = FStar.UInt64
let valid_constint32le
(v: nat { 0 <= v /\ v < 4294967296 } )
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma (valid (parse_constint32le v) h input pos
<==>
(valid parse_int32le h input pos /\
U32.v (contents parse_int32le h input pos) == v))
= valid_facts (parse_constint32le v) h input pos;
valid_facts parse_int32le h input pos;
parse_constint32le_unfold v (bytes_of_slice_from h input pos) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Int32le.fst.checked",
"LowParse.Spec.ConstInt32.fst.checked",
"LowParse.Low.Int32le.fst.checked",
"LowParse.Low.Combinators.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Endianness.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.ConstInt32.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "LowParse.Low.Int32le",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Int32le",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.ConstInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Endianness",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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: FStar.UInt32.t{0 <= FStar.UInt32.v v /\ FStar.UInt32.v v < 4294967296}
-> LowParse.Low.Base.validator (LowParse.Spec.ConstInt32.parse_constint32le (FStar.UInt32.v v)) | Prims.Tot | [
"total"
] | [] | [
"FStar.UInt32.t",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.UInt32.v",
"Prims.op_LessThan",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"FStar.UInt64.t",
"FStar.UInt64.lt",
"FStar.UInt64.sub",
"FStar.Int.Cast.uint32_to_uint64",
"LowParse.Slice.__proj__Mkslice__item__len",
"FStar.UInt64.__uint_to_t",
"LowParse.Low.ErrorCode.validator_error_not_enough_data",
"Prims.bool",
"FStar.UInt32.eq",
"FStar.UInt64.add",
"LowParse.Low.ErrorCode.validator_error_generic",
"LowParse.Low.Int32le.read_int32le",
"LowParse.Low.ErrorCode.uint64_to_uint32",
"Prims.unit",
"LowParse.Low.Base.Spec.valid_equiv",
"LowParse.Spec.Base.total_constant_size_parser_kind",
"LowParse.Spec.Int32le.parse_int32le",
"LowParse.Low.ConstInt32.valid_constint32le",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"LowParse.Low.Base.validator",
"LowParse.Spec.ConstInt32.parse_constint32le_kind",
"LowParse.Spec.ConstInt32.constint32",
"LowParse.Spec.ConstInt32.parse_constint32le"
] | [] | false | false | false | false | false | let validate_constint32le_slow (v: U32.t{0 <= U32.v v /\ U32.v v < 4294967296})
: Tot (validator (parse_constint32le (U32.v v))) =
| fun #rrel #rel (input: slice rrel rel) pos ->
let h = HST.get () in
let _ =
valid_constint32le (U32.v v) h input (uint64_to_uint32 pos);
valid_equiv parse_int32le h input (uint64_to_uint32 pos)
in
if U64.lt ((Cast.uint32_to_uint64 input.len) `U64.sub` pos) 4uL
then validator_error_not_enough_data
else
let v' = read_int32le input (uint64_to_uint32 pos) in
if U32.eq v v' then pos `U64.add` 4uL else validator_error_generic | false |
Spec.FFDHE.fst | Spec.FFDHE.ffdhe_params_2048 | val ffdhe_params_2048:ffdhe_params_t | val ffdhe_params_2048:ffdhe_params_t | let ffdhe_params_2048 : ffdhe_params_t =
Mk_ffdhe_params 256 ffdhe_p2048 1 ffdhe_g2 | {
"file_name": "specs/Spec.FFDHE.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 44,
"end_line": 78,
"start_col": 0,
"start_line": 77
} | module Spec.FFDHE
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
(** https://tools.ietf.org/html/rfc7919#appendix-A *)
noeq type ffdhe_params_t =
| Mk_ffdhe_params:
ffdhe_p_len:size_nat
-> ffdhe_p:lseq pub_uint8 ffdhe_p_len
-> ffdhe_g_len:size_nat
-> ffdhe_g:lseq pub_uint8 ffdhe_g_len
-> ffdhe_params_t
[@"opaque_to_smt"]
inline_for_extraction
let list_ffdhe_g2: List.Tot.llist pub_uint8 1 =
[@inline_let]
let l = [ 0x02uy ] in
assert_norm (List.Tot.length l == 1);
l
let ffdhe_g2: lseq pub_uint8 1 = of_list list_ffdhe_g2
[@"opaque_to_smt"]
inline_for_extraction
let list_ffdhe_p2048: List.Tot.llist pub_uint8 256 =
[@inline_let]
let l = [
0xFFuy; 0xFFuy; 0xFFuy; 0xFFuy; 0xFFuy; 0xFFuy; 0xFFuy; 0xFFuy;
0xADuy; 0xF8uy; 0x54uy; 0x58uy; 0xA2uy; 0xBBuy; 0x4Auy; 0x9Auy;
0xAFuy; 0xDCuy; 0x56uy; 0x20uy; 0x27uy; 0x3Duy; 0x3Cuy; 0xF1uy;
0xD8uy; 0xB9uy; 0xC5uy; 0x83uy; 0xCEuy; 0x2Duy; 0x36uy; 0x95uy;
0xA9uy; 0xE1uy; 0x36uy; 0x41uy; 0x14uy; 0x64uy; 0x33uy; 0xFBuy;
0xCCuy; 0x93uy; 0x9Duy; 0xCEuy; 0x24uy; 0x9Buy; 0x3Euy; 0xF9uy;
0x7Duy; 0x2Fuy; 0xE3uy; 0x63uy; 0x63uy; 0x0Cuy; 0x75uy; 0xD8uy;
0xF6uy; 0x81uy; 0xB2uy; 0x02uy; 0xAEuy; 0xC4uy; 0x61uy; 0x7Auy;
0xD3uy; 0xDFuy; 0x1Euy; 0xD5uy; 0xD5uy; 0xFDuy; 0x65uy; 0x61uy;
0x24uy; 0x33uy; 0xF5uy; 0x1Fuy; 0x5Fuy; 0x06uy; 0x6Euy; 0xD0uy;
0x85uy; 0x63uy; 0x65uy; 0x55uy; 0x3Duy; 0xEDuy; 0x1Auy; 0xF3uy;
0xB5uy; 0x57uy; 0x13uy; 0x5Euy; 0x7Fuy; 0x57uy; 0xC9uy; 0x35uy;
0x98uy; 0x4Fuy; 0x0Cuy; 0x70uy; 0xE0uy; 0xE6uy; 0x8Buy; 0x77uy;
0xE2uy; 0xA6uy; 0x89uy; 0xDAuy; 0xF3uy; 0xEFuy; 0xE8uy; 0x72uy;
0x1Duy; 0xF1uy; 0x58uy; 0xA1uy; 0x36uy; 0xADuy; 0xE7uy; 0x35uy;
0x30uy; 0xACuy; 0xCAuy; 0x4Fuy; 0x48uy; 0x3Auy; 0x79uy; 0x7Auy;
0xBCuy; 0x0Auy; 0xB1uy; 0x82uy; 0xB3uy; 0x24uy; 0xFBuy; 0x61uy;
0xD1uy; 0x08uy; 0xA9uy; 0x4Buy; 0xB2uy; 0xC8uy; 0xE3uy; 0xFBuy;
0xB9uy; 0x6Auy; 0xDAuy; 0xB7uy; 0x60uy; 0xD7uy; 0xF4uy; 0x68uy;
0x1Duy; 0x4Fuy; 0x42uy; 0xA3uy; 0xDEuy; 0x39uy; 0x4Duy; 0xF4uy;
0xAEuy; 0x56uy; 0xEDuy; 0xE7uy; 0x63uy; 0x72uy; 0xBBuy; 0x19uy;
0x0Buy; 0x07uy; 0xA7uy; 0xC8uy; 0xEEuy; 0x0Auy; 0x6Duy; 0x70uy;
0x9Euy; 0x02uy; 0xFCuy; 0xE1uy; 0xCDuy; 0xF7uy; 0xE2uy; 0xECuy;
0xC0uy; 0x34uy; 0x04uy; 0xCDuy; 0x28uy; 0x34uy; 0x2Fuy; 0x61uy;
0x91uy; 0x72uy; 0xFEuy; 0x9Cuy; 0xE9uy; 0x85uy; 0x83uy; 0xFFuy;
0x8Euy; 0x4Fuy; 0x12uy; 0x32uy; 0xEEuy; 0xF2uy; 0x81uy; 0x83uy;
0xC3uy; 0xFEuy; 0x3Buy; 0x1Buy; 0x4Cuy; 0x6Fuy; 0xADuy; 0x73uy;
0x3Buy; 0xB5uy; 0xFCuy; 0xBCuy; 0x2Euy; 0xC2uy; 0x20uy; 0x05uy;
0xC5uy; 0x8Euy; 0xF1uy; 0x83uy; 0x7Duy; 0x16uy; 0x83uy; 0xB2uy;
0xC6uy; 0xF3uy; 0x4Auy; 0x26uy; 0xC1uy; 0xB2uy; 0xEFuy; 0xFAuy;
0x88uy; 0x6Buy; 0x42uy; 0x38uy; 0x61uy; 0x28uy; 0x5Cuy; 0x97uy;
0xFFuy; 0xFFuy; 0xFFuy; 0xFFuy; 0xFFuy; 0xFFuy; 0xFFuy; 0xFFuy
] in
assert_norm (List.Tot.length l == 256);
l
let ffdhe_p2048: lseq pub_uint8 256 = of_list list_ffdhe_p2048 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NatMod.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "Spec.FFDHE.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 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.FFDHE.ffdhe_params_t | Prims.Tot | [
"total"
] | [] | [
"Spec.FFDHE.Mk_ffdhe_params",
"Spec.FFDHE.ffdhe_p2048",
"Spec.FFDHE.ffdhe_g2"
] | [] | false | false | false | true | false | let ffdhe_params_2048:ffdhe_params_t =
| Mk_ffdhe_params 256 ffdhe_p2048 1 ffdhe_g2 | false |
Spec.FFDHE.fst | Spec.FFDHE.ffdhe_params_6144 | val ffdhe_params_6144:ffdhe_params_t | val ffdhe_params_6144:ffdhe_params_t | let ffdhe_params_6144 : ffdhe_params_t =
Mk_ffdhe_params 768 ffdhe_p6144 1 ffdhe_g2 | {
"file_name": "specs/Spec.FFDHE.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 44,
"end_line": 334,
"start_col": 0,
"start_line": 333
} | module Spec.FFDHE
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
(** https://tools.ietf.org/html/rfc7919#appendix-A *)
noeq type ffdhe_params_t =
| Mk_ffdhe_params:
ffdhe_p_len:size_nat
-> ffdhe_p:lseq pub_uint8 ffdhe_p_len
-> ffdhe_g_len:size_nat
-> ffdhe_g:lseq pub_uint8 ffdhe_g_len
-> ffdhe_params_t
[@"opaque_to_smt"]
inline_for_extraction
let list_ffdhe_g2: List.Tot.llist pub_uint8 1 =
[@inline_let]
let l = [ 0x02uy ] in
assert_norm (List.Tot.length l == 1);
l
let ffdhe_g2: lseq pub_uint8 1 = of_list list_ffdhe_g2
[@"opaque_to_smt"]
inline_for_extraction
let list_ffdhe_p2048: List.Tot.llist pub_uint8 256 =
[@inline_let]
let l = [
0xFFuy; 0xFFuy; 0xFFuy; 0xFFuy; 0xFFuy; 0xFFuy; 0xFFuy; 0xFFuy;
0xADuy; 0xF8uy; 0x54uy; 0x58uy; 0xA2uy; 0xBBuy; 0x4Auy; 0x9Auy;
0xAFuy; 0xDCuy; 0x56uy; 0x20uy; 0x27uy; 0x3Duy; 0x3Cuy; 0xF1uy;
0xD8uy; 0xB9uy; 0xC5uy; 0x83uy; 0xCEuy; 0x2Duy; 0x36uy; 0x95uy;
0xA9uy; 0xE1uy; 0x36uy; 0x41uy; 0x14uy; 0x64uy; 0x33uy; 0xFBuy;
0xCCuy; 0x93uy; 0x9Duy; 0xCEuy; 0x24uy; 0x9Buy; 0x3Euy; 0xF9uy;
0x7Duy; 0x2Fuy; 0xE3uy; 0x63uy; 0x63uy; 0x0Cuy; 0x75uy; 0xD8uy;
0xF6uy; 0x81uy; 0xB2uy; 0x02uy; 0xAEuy; 0xC4uy; 0x61uy; 0x7Auy;
0xD3uy; 0xDFuy; 0x1Euy; 0xD5uy; 0xD5uy; 0xFDuy; 0x65uy; 0x61uy;
0x24uy; 0x33uy; 0xF5uy; 0x1Fuy; 0x5Fuy; 0x06uy; 0x6Euy; 0xD0uy;
0x85uy; 0x63uy; 0x65uy; 0x55uy; 0x3Duy; 0xEDuy; 0x1Auy; 0xF3uy;
0xB5uy; 0x57uy; 0x13uy; 0x5Euy; 0x7Fuy; 0x57uy; 0xC9uy; 0x35uy;
0x98uy; 0x4Fuy; 0x0Cuy; 0x70uy; 0xE0uy; 0xE6uy; 0x8Buy; 0x77uy;
0xE2uy; 0xA6uy; 0x89uy; 0xDAuy; 0xF3uy; 0xEFuy; 0xE8uy; 0x72uy;
0x1Duy; 0xF1uy; 0x58uy; 0xA1uy; 0x36uy; 0xADuy; 0xE7uy; 0x35uy;
0x30uy; 0xACuy; 0xCAuy; 0x4Fuy; 0x48uy; 0x3Auy; 0x79uy; 0x7Auy;
0xBCuy; 0x0Auy; 0xB1uy; 0x82uy; 0xB3uy; 0x24uy; 0xFBuy; 0x61uy;
0xD1uy; 0x08uy; 0xA9uy; 0x4Buy; 0xB2uy; 0xC8uy; 0xE3uy; 0xFBuy;
0xB9uy; 0x6Auy; 0xDAuy; 0xB7uy; 0x60uy; 0xD7uy; 0xF4uy; 0x68uy;
0x1Duy; 0x4Fuy; 0x42uy; 0xA3uy; 0xDEuy; 0x39uy; 0x4Duy; 0xF4uy;
0xAEuy; 0x56uy; 0xEDuy; 0xE7uy; 0x63uy; 0x72uy; 0xBBuy; 0x19uy;
0x0Buy; 0x07uy; 0xA7uy; 0xC8uy; 0xEEuy; 0x0Auy; 0x6Duy; 0x70uy;
0x9Euy; 0x02uy; 0xFCuy; 0xE1uy; 0xCDuy; 0xF7uy; 0xE2uy; 0xECuy;
0xC0uy; 0x34uy; 0x04uy; 0xCDuy; 0x28uy; 0x34uy; 0x2Fuy; 0x61uy;
0x91uy; 0x72uy; 0xFEuy; 0x9Cuy; 0xE9uy; 0x85uy; 0x83uy; 0xFFuy;
0x8Euy; 0x4Fuy; 0x12uy; 0x32uy; 0xEEuy; 0xF2uy; 0x81uy; 0x83uy;
0xC3uy; 0xFEuy; 0x3Buy; 0x1Buy; 0x4Cuy; 0x6Fuy; 0xADuy; 0x73uy;
0x3Buy; 0xB5uy; 0xFCuy; 0xBCuy; 0x2Euy; 0xC2uy; 0x20uy; 0x05uy;
0xC5uy; 0x8Euy; 0xF1uy; 0x83uy; 0x7Duy; 0x16uy; 0x83uy; 0xB2uy;
0xC6uy; 0xF3uy; 0x4Auy; 0x26uy; 0xC1uy; 0xB2uy; 0xEFuy; 0xFAuy;
0x88uy; 0x6Buy; 0x42uy; 0x38uy; 0x61uy; 0x28uy; 0x5Cuy; 0x97uy;
0xFFuy; 0xFFuy; 0xFFuy; 0xFFuy; 0xFFuy; 0xFFuy; 0xFFuy; 0xFFuy
] in
assert_norm (List.Tot.length l == 256);
l
let ffdhe_p2048: lseq pub_uint8 256 = of_list list_ffdhe_p2048
// The estimated symmetric-equivalent strength of this group is 103 bits.
let ffdhe_params_2048 : ffdhe_params_t =
Mk_ffdhe_params 256 ffdhe_p2048 1 ffdhe_g2
[@"opaque_to_smt"]
inline_for_extraction
let list_ffdhe_p3072: List.Tot.llist pub_uint8 384 =
[@inline_let]
let l = [
0xFFuy; 0xFFuy; 0xFFuy; 0xFFuy; 0xFFuy; 0xFFuy; 0xFFuy; 0xFFuy;
0xADuy; 0xF8uy; 0x54uy; 0x58uy; 0xA2uy; 0xBBuy; 0x4Auy; 0x9Auy;
0xAFuy; 0xDCuy; 0x56uy; 0x20uy; 0x27uy; 0x3Duy; 0x3Cuy; 0xF1uy;
0xD8uy; 0xB9uy; 0xC5uy; 0x83uy; 0xCEuy; 0x2Duy; 0x36uy; 0x95uy;
0xA9uy; 0xE1uy; 0x36uy; 0x41uy; 0x14uy; 0x64uy; 0x33uy; 0xFBuy;
0xCCuy; 0x93uy; 0x9Duy; 0xCEuy; 0x24uy; 0x9Buy; 0x3Euy; 0xF9uy;
0x7Duy; 0x2Fuy; 0xE3uy; 0x63uy; 0x63uy; 0x0Cuy; 0x75uy; 0xD8uy;
0xF6uy; 0x81uy; 0xB2uy; 0x02uy; 0xAEuy; 0xC4uy; 0x61uy; 0x7Auy;
0xD3uy; 0xDFuy; 0x1Euy; 0xD5uy; 0xD5uy; 0xFDuy; 0x65uy; 0x61uy;
0x24uy; 0x33uy; 0xF5uy; 0x1Fuy; 0x5Fuy; 0x06uy; 0x6Euy; 0xD0uy;
0x85uy; 0x63uy; 0x65uy; 0x55uy; 0x3Duy; 0xEDuy; 0x1Auy; 0xF3uy;
0xB5uy; 0x57uy; 0x13uy; 0x5Euy; 0x7Fuy; 0x57uy; 0xC9uy; 0x35uy;
0x98uy; 0x4Fuy; 0x0Cuy; 0x70uy; 0xE0uy; 0xE6uy; 0x8Buy; 0x77uy;
0xE2uy; 0xA6uy; 0x89uy; 0xDAuy; 0xF3uy; 0xEFuy; 0xE8uy; 0x72uy;
0x1Duy; 0xF1uy; 0x58uy; 0xA1uy; 0x36uy; 0xADuy; 0xE7uy; 0x35uy;
0x30uy; 0xACuy; 0xCAuy; 0x4Fuy; 0x48uy; 0x3Auy; 0x79uy; 0x7Auy;
0xBCuy; 0x0Auy; 0xB1uy; 0x82uy; 0xB3uy; 0x24uy; 0xFBuy; 0x61uy;
0xD1uy; 0x08uy; 0xA9uy; 0x4Buy; 0xB2uy; 0xC8uy; 0xE3uy; 0xFBuy;
0xB9uy; 0x6Auy; 0xDAuy; 0xB7uy; 0x60uy; 0xD7uy; 0xF4uy; 0x68uy;
0x1Duy; 0x4Fuy; 0x42uy; 0xA3uy; 0xDEuy; 0x39uy; 0x4Duy; 0xF4uy;
0xAEuy; 0x56uy; 0xEDuy; 0xE7uy; 0x63uy; 0x72uy; 0xBBuy; 0x19uy;
0x0Buy; 0x07uy; 0xA7uy; 0xC8uy; 0xEEuy; 0x0Auy; 0x6Duy; 0x70uy;
0x9Euy; 0x02uy; 0xFCuy; 0xE1uy; 0xCDuy; 0xF7uy; 0xE2uy; 0xECuy;
0xC0uy; 0x34uy; 0x04uy; 0xCDuy; 0x28uy; 0x34uy; 0x2Fuy; 0x61uy;
0x91uy; 0x72uy; 0xFEuy; 0x9Cuy; 0xE9uy; 0x85uy; 0x83uy; 0xFFuy;
0x8Euy; 0x4Fuy; 0x12uy; 0x32uy; 0xEEuy; 0xF2uy; 0x81uy; 0x83uy;
0xC3uy; 0xFEuy; 0x3Buy; 0x1Buy; 0x4Cuy; 0x6Fuy; 0xADuy; 0x73uy;
0x3Buy; 0xB5uy; 0xFCuy; 0xBCuy; 0x2Euy; 0xC2uy; 0x20uy; 0x05uy;
0xC5uy; 0x8Euy; 0xF1uy; 0x83uy; 0x7Duy; 0x16uy; 0x83uy; 0xB2uy;
0xC6uy; 0xF3uy; 0x4Auy; 0x26uy; 0xC1uy; 0xB2uy; 0xEFuy; 0xFAuy;
0x88uy; 0x6Buy; 0x42uy; 0x38uy; 0x61uy; 0x1Fuy; 0xCFuy; 0xDCuy;
0xDEuy; 0x35uy; 0x5Buy; 0x3Buy; 0x65uy; 0x19uy; 0x03uy; 0x5Buy;
0xBCuy; 0x34uy; 0xF4uy; 0xDEuy; 0xF9uy; 0x9Cuy; 0x02uy; 0x38uy;
0x61uy; 0xB4uy; 0x6Fuy; 0xC9uy; 0xD6uy; 0xE6uy; 0xC9uy; 0x07uy;
0x7Auy; 0xD9uy; 0x1Duy; 0x26uy; 0x91uy; 0xF7uy; 0xF7uy; 0xEEuy;
0x59uy; 0x8Cuy; 0xB0uy; 0xFAuy; 0xC1uy; 0x86uy; 0xD9uy; 0x1Cuy;
0xAEuy; 0xFEuy; 0x13uy; 0x09uy; 0x85uy; 0x13uy; 0x92uy; 0x70uy;
0xB4uy; 0x13uy; 0x0Cuy; 0x93uy; 0xBCuy; 0x43uy; 0x79uy; 0x44uy;
0xF4uy; 0xFDuy; 0x44uy; 0x52uy; 0xE2uy; 0xD7uy; 0x4Duy; 0xD3uy;
0x64uy; 0xF2uy; 0xE2uy; 0x1Euy; 0x71uy; 0xF5uy; 0x4Buy; 0xFFuy;
0x5Cuy; 0xAEuy; 0x82uy; 0xABuy; 0x9Cuy; 0x9Duy; 0xF6uy; 0x9Euy;
0xE8uy; 0x6Duy; 0x2Buy; 0xC5uy; 0x22uy; 0x36uy; 0x3Auy; 0x0Duy;
0xABuy; 0xC5uy; 0x21uy; 0x97uy; 0x9Buy; 0x0Duy; 0xEAuy; 0xDAuy;
0x1Duy; 0xBFuy; 0x9Auy; 0x42uy; 0xD5uy; 0xC4uy; 0x48uy; 0x4Euy;
0x0Auy; 0xBCuy; 0xD0uy; 0x6Buy; 0xFAuy; 0x53uy; 0xDDuy; 0xEFuy;
0x3Cuy; 0x1Buy; 0x20uy; 0xEEuy; 0x3Fuy; 0xD5uy; 0x9Duy; 0x7Cuy;
0x25uy; 0xE4uy; 0x1Duy; 0x2Buy; 0x66uy; 0xC6uy; 0x2Euy; 0x37uy;
0xFFuy; 0xFFuy; 0xFFuy; 0xFFuy; 0xFFuy; 0xFFuy; 0xFFuy; 0xFFuy
] in
assert_norm (List.Tot.length l == 384);
l
let ffdhe_p3072: lseq pub_uint8 384 = of_list list_ffdhe_p3072
// The estimated symmetric-equivalent strength of this group is 125 bits.
let ffdhe_params_3072 : ffdhe_params_t =
Mk_ffdhe_params 384 ffdhe_p3072 1 ffdhe_g2
[@"opaque_to_smt"]
inline_for_extraction
let list_ffdhe_p4096: List.Tot.llist pub_uint8 512 =
[@inline_let]
let l = [
0xFFuy; 0xFFuy; 0xFFuy; 0xFFuy; 0xFFuy; 0xFFuy; 0xFFuy; 0xFFuy;
0xADuy; 0xF8uy; 0x54uy; 0x58uy; 0xA2uy; 0xBBuy; 0x4Auy; 0x9Auy;
0xAFuy; 0xDCuy; 0x56uy; 0x20uy; 0x27uy; 0x3Duy; 0x3Cuy; 0xF1uy;
0xD8uy; 0xB9uy; 0xC5uy; 0x83uy; 0xCEuy; 0x2Duy; 0x36uy; 0x95uy;
0xA9uy; 0xE1uy; 0x36uy; 0x41uy; 0x14uy; 0x64uy; 0x33uy; 0xFBuy;
0xCCuy; 0x93uy; 0x9Duy; 0xCEuy; 0x24uy; 0x9Buy; 0x3Euy; 0xF9uy;
0x7Duy; 0x2Fuy; 0xE3uy; 0x63uy; 0x63uy; 0x0Cuy; 0x75uy; 0xD8uy;
0xF6uy; 0x81uy; 0xB2uy; 0x02uy; 0xAEuy; 0xC4uy; 0x61uy; 0x7Auy;
0xD3uy; 0xDFuy; 0x1Euy; 0xD5uy; 0xD5uy; 0xFDuy; 0x65uy; 0x61uy;
0x24uy; 0x33uy; 0xF5uy; 0x1Fuy; 0x5Fuy; 0x06uy; 0x6Euy; 0xD0uy;
0x85uy; 0x63uy; 0x65uy; 0x55uy; 0x3Duy; 0xEDuy; 0x1Auy; 0xF3uy;
0xB5uy; 0x57uy; 0x13uy; 0x5Euy; 0x7Fuy; 0x57uy; 0xC9uy; 0x35uy;
0x98uy; 0x4Fuy; 0x0Cuy; 0x70uy; 0xE0uy; 0xE6uy; 0x8Buy; 0x77uy;
0xE2uy; 0xA6uy; 0x89uy; 0xDAuy; 0xF3uy; 0xEFuy; 0xE8uy; 0x72uy;
0x1Duy; 0xF1uy; 0x58uy; 0xA1uy; 0x36uy; 0xADuy; 0xE7uy; 0x35uy;
0x30uy; 0xACuy; 0xCAuy; 0x4Fuy; 0x48uy; 0x3Auy; 0x79uy; 0x7Auy;
0xBCuy; 0x0Auy; 0xB1uy; 0x82uy; 0xB3uy; 0x24uy; 0xFBuy; 0x61uy;
0xD1uy; 0x08uy; 0xA9uy; 0x4Buy; 0xB2uy; 0xC8uy; 0xE3uy; 0xFBuy;
0xB9uy; 0x6Auy; 0xDAuy; 0xB7uy; 0x60uy; 0xD7uy; 0xF4uy; 0x68uy;
0x1Duy; 0x4Fuy; 0x42uy; 0xA3uy; 0xDEuy; 0x39uy; 0x4Duy; 0xF4uy;
0xAEuy; 0x56uy; 0xEDuy; 0xE7uy; 0x63uy; 0x72uy; 0xBBuy; 0x19uy;
0x0Buy; 0x07uy; 0xA7uy; 0xC8uy; 0xEEuy; 0x0Auy; 0x6Duy; 0x70uy;
0x9Euy; 0x02uy; 0xFCuy; 0xE1uy; 0xCDuy; 0xF7uy; 0xE2uy; 0xECuy;
0xC0uy; 0x34uy; 0x04uy; 0xCDuy; 0x28uy; 0x34uy; 0x2Fuy; 0x61uy;
0x91uy; 0x72uy; 0xFEuy; 0x9Cuy; 0xE9uy; 0x85uy; 0x83uy; 0xFFuy;
0x8Euy; 0x4Fuy; 0x12uy; 0x32uy; 0xEEuy; 0xF2uy; 0x81uy; 0x83uy;
0xC3uy; 0xFEuy; 0x3Buy; 0x1Buy; 0x4Cuy; 0x6Fuy; 0xADuy; 0x73uy;
0x3Buy; 0xB5uy; 0xFCuy; 0xBCuy; 0x2Euy; 0xC2uy; 0x20uy; 0x05uy;
0xC5uy; 0x8Euy; 0xF1uy; 0x83uy; 0x7Duy; 0x16uy; 0x83uy; 0xB2uy;
0xC6uy; 0xF3uy; 0x4Auy; 0x26uy; 0xC1uy; 0xB2uy; 0xEFuy; 0xFAuy;
0x88uy; 0x6Buy; 0x42uy; 0x38uy; 0x61uy; 0x1Fuy; 0xCFuy; 0xDCuy;
0xDEuy; 0x35uy; 0x5Buy; 0x3Buy; 0x65uy; 0x19uy; 0x03uy; 0x5Buy;
0xBCuy; 0x34uy; 0xF4uy; 0xDEuy; 0xF9uy; 0x9Cuy; 0x02uy; 0x38uy;
0x61uy; 0xB4uy; 0x6Fuy; 0xC9uy; 0xD6uy; 0xE6uy; 0xC9uy; 0x07uy;
0x7Auy; 0xD9uy; 0x1Duy; 0x26uy; 0x91uy; 0xF7uy; 0xF7uy; 0xEEuy;
0x59uy; 0x8Cuy; 0xB0uy; 0xFAuy; 0xC1uy; 0x86uy; 0xD9uy; 0x1Cuy;
0xAEuy; 0xFEuy; 0x13uy; 0x09uy; 0x85uy; 0x13uy; 0x92uy; 0x70uy;
0xB4uy; 0x13uy; 0x0Cuy; 0x93uy; 0xBCuy; 0x43uy; 0x79uy; 0x44uy;
0xF4uy; 0xFDuy; 0x44uy; 0x52uy; 0xE2uy; 0xD7uy; 0x4Duy; 0xD3uy;
0x64uy; 0xF2uy; 0xE2uy; 0x1Euy; 0x71uy; 0xF5uy; 0x4Buy; 0xFFuy;
0x5Cuy; 0xAEuy; 0x82uy; 0xABuy; 0x9Cuy; 0x9Duy; 0xF6uy; 0x9Euy;
0xE8uy; 0x6Duy; 0x2Buy; 0xC5uy; 0x22uy; 0x36uy; 0x3Auy; 0x0Duy;
0xABuy; 0xC5uy; 0x21uy; 0x97uy; 0x9Buy; 0x0Duy; 0xEAuy; 0xDAuy;
0x1Duy; 0xBFuy; 0x9Auy; 0x42uy; 0xD5uy; 0xC4uy; 0x48uy; 0x4Euy;
0x0Auy; 0xBCuy; 0xD0uy; 0x6Buy; 0xFAuy; 0x53uy; 0xDDuy; 0xEFuy;
0x3Cuy; 0x1Buy; 0x20uy; 0xEEuy; 0x3Fuy; 0xD5uy; 0x9Duy; 0x7Cuy;
0x25uy; 0xE4uy; 0x1Duy; 0x2Buy; 0x66uy; 0x9Euy; 0x1Euy; 0xF1uy;
0x6Euy; 0x6Fuy; 0x52uy; 0xC3uy; 0x16uy; 0x4Duy; 0xF4uy; 0xFBuy;
0x79uy; 0x30uy; 0xE9uy; 0xE4uy; 0xE5uy; 0x88uy; 0x57uy; 0xB6uy;
0xACuy; 0x7Duy; 0x5Fuy; 0x42uy; 0xD6uy; 0x9Fuy; 0x6Duy; 0x18uy;
0x77uy; 0x63uy; 0xCFuy; 0x1Duy; 0x55uy; 0x03uy; 0x40uy; 0x04uy;
0x87uy; 0xF5uy; 0x5Buy; 0xA5uy; 0x7Euy; 0x31uy; 0xCCuy; 0x7Auy;
0x71uy; 0x35uy; 0xC8uy; 0x86uy; 0xEFuy; 0xB4uy; 0x31uy; 0x8Auy;
0xEDuy; 0x6Auy; 0x1Euy; 0x01uy; 0x2Duy; 0x9Euy; 0x68uy; 0x32uy;
0xA9uy; 0x07uy; 0x60uy; 0x0Auy; 0x91uy; 0x81uy; 0x30uy; 0xC4uy;
0x6Duy; 0xC7uy; 0x78uy; 0xF9uy; 0x71uy; 0xADuy; 0x00uy; 0x38uy;
0x09uy; 0x29uy; 0x99uy; 0xA3uy; 0x33uy; 0xCBuy; 0x8Buy; 0x7Auy;
0x1Auy; 0x1Duy; 0xB9uy; 0x3Duy; 0x71uy; 0x40uy; 0x00uy; 0x3Cuy;
0x2Auy; 0x4Euy; 0xCEuy; 0xA9uy; 0xF9uy; 0x8Duy; 0x0Auy; 0xCCuy;
0x0Auy; 0x82uy; 0x91uy; 0xCDuy; 0xCEuy; 0xC9uy; 0x7Duy; 0xCFuy;
0x8Euy; 0xC9uy; 0xB5uy; 0x5Auy; 0x7Fuy; 0x88uy; 0xA4uy; 0x6Buy;
0x4Duy; 0xB5uy; 0xA8uy; 0x51uy; 0xF4uy; 0x41uy; 0x82uy; 0xE1uy;
0xC6uy; 0x8Auy; 0x00uy; 0x7Euy; 0x5Euy; 0x65uy; 0x5Fuy; 0x6Auy;
0xFFuy; 0xFFuy; 0xFFuy; 0xFFuy; 0xFFuy; 0xFFuy; 0xFFuy; 0xFFuy
] in
assert_norm (List.Tot.length l == 512);
l
let ffdhe_p4096: lseq pub_uint8 512 = of_list list_ffdhe_p4096
// The estimated symmetric-equivalent strength of this group is 150 bits.
let ffdhe_params_4096 : ffdhe_params_t =
Mk_ffdhe_params 512 ffdhe_p4096 1 ffdhe_g2
[@"opaque_to_smt"]
inline_for_extraction
let list_ffdhe_p6144: List.Tot.llist pub_uint8 768 =
[@inline_let]
let l = [
0xFFuy; 0xFFuy; 0xFFuy; 0xFFuy; 0xFFuy; 0xFFuy; 0xFFuy; 0xFFuy;
0xADuy; 0xF8uy; 0x54uy; 0x58uy; 0xA2uy; 0xBBuy; 0x4Auy; 0x9Auy;
0xAFuy; 0xDCuy; 0x56uy; 0x20uy; 0x27uy; 0x3Duy; 0x3Cuy; 0xF1uy;
0xD8uy; 0xB9uy; 0xC5uy; 0x83uy; 0xCEuy; 0x2Duy; 0x36uy; 0x95uy;
0xA9uy; 0xE1uy; 0x36uy; 0x41uy; 0x14uy; 0x64uy; 0x33uy; 0xFBuy;
0xCCuy; 0x93uy; 0x9Duy; 0xCEuy; 0x24uy; 0x9Buy; 0x3Euy; 0xF9uy;
0x7Duy; 0x2Fuy; 0xE3uy; 0x63uy; 0x63uy; 0x0Cuy; 0x75uy; 0xD8uy;
0xF6uy; 0x81uy; 0xB2uy; 0x02uy; 0xAEuy; 0xC4uy; 0x61uy; 0x7Auy;
0xD3uy; 0xDFuy; 0x1Euy; 0xD5uy; 0xD5uy; 0xFDuy; 0x65uy; 0x61uy;
0x24uy; 0x33uy; 0xF5uy; 0x1Fuy; 0x5Fuy; 0x06uy; 0x6Euy; 0xD0uy;
0x85uy; 0x63uy; 0x65uy; 0x55uy; 0x3Duy; 0xEDuy; 0x1Auy; 0xF3uy;
0xB5uy; 0x57uy; 0x13uy; 0x5Euy; 0x7Fuy; 0x57uy; 0xC9uy; 0x35uy;
0x98uy; 0x4Fuy; 0x0Cuy; 0x70uy; 0xE0uy; 0xE6uy; 0x8Buy; 0x77uy;
0xE2uy; 0xA6uy; 0x89uy; 0xDAuy; 0xF3uy; 0xEFuy; 0xE8uy; 0x72uy;
0x1Duy; 0xF1uy; 0x58uy; 0xA1uy; 0x36uy; 0xADuy; 0xE7uy; 0x35uy;
0x30uy; 0xACuy; 0xCAuy; 0x4Fuy; 0x48uy; 0x3Auy; 0x79uy; 0x7Auy;
0xBCuy; 0x0Auy; 0xB1uy; 0x82uy; 0xB3uy; 0x24uy; 0xFBuy; 0x61uy;
0xD1uy; 0x08uy; 0xA9uy; 0x4Buy; 0xB2uy; 0xC8uy; 0xE3uy; 0xFBuy;
0xB9uy; 0x6Auy; 0xDAuy; 0xB7uy; 0x60uy; 0xD7uy; 0xF4uy; 0x68uy;
0x1Duy; 0x4Fuy; 0x42uy; 0xA3uy; 0xDEuy; 0x39uy; 0x4Duy; 0xF4uy;
0xAEuy; 0x56uy; 0xEDuy; 0xE7uy; 0x63uy; 0x72uy; 0xBBuy; 0x19uy;
0x0Buy; 0x07uy; 0xA7uy; 0xC8uy; 0xEEuy; 0x0Auy; 0x6Duy; 0x70uy;
0x9Euy; 0x02uy; 0xFCuy; 0xE1uy; 0xCDuy; 0xF7uy; 0xE2uy; 0xECuy;
0xC0uy; 0x34uy; 0x04uy; 0xCDuy; 0x28uy; 0x34uy; 0x2Fuy; 0x61uy;
0x91uy; 0x72uy; 0xFEuy; 0x9Cuy; 0xE9uy; 0x85uy; 0x83uy; 0xFFuy;
0x8Euy; 0x4Fuy; 0x12uy; 0x32uy; 0xEEuy; 0xF2uy; 0x81uy; 0x83uy;
0xC3uy; 0xFEuy; 0x3Buy; 0x1Buy; 0x4Cuy; 0x6Fuy; 0xADuy; 0x73uy;
0x3Buy; 0xB5uy; 0xFCuy; 0xBCuy; 0x2Euy; 0xC2uy; 0x20uy; 0x05uy;
0xC5uy; 0x8Euy; 0xF1uy; 0x83uy; 0x7Duy; 0x16uy; 0x83uy; 0xB2uy;
0xC6uy; 0xF3uy; 0x4Auy; 0x26uy; 0xC1uy; 0xB2uy; 0xEFuy; 0xFAuy;
0x88uy; 0x6Buy; 0x42uy; 0x38uy; 0x61uy; 0x1Fuy; 0xCFuy; 0xDCuy;
0xDEuy; 0x35uy; 0x5Buy; 0x3Buy; 0x65uy; 0x19uy; 0x03uy; 0x5Buy;
0xBCuy; 0x34uy; 0xF4uy; 0xDEuy; 0xF9uy; 0x9Cuy; 0x02uy; 0x38uy;
0x61uy; 0xB4uy; 0x6Fuy; 0xC9uy; 0xD6uy; 0xE6uy; 0xC9uy; 0x07uy;
0x7Auy; 0xD9uy; 0x1Duy; 0x26uy; 0x91uy; 0xF7uy; 0xF7uy; 0xEEuy;
0x59uy; 0x8Cuy; 0xB0uy; 0xFAuy; 0xC1uy; 0x86uy; 0xD9uy; 0x1Cuy;
0xAEuy; 0xFEuy; 0x13uy; 0x09uy; 0x85uy; 0x13uy; 0x92uy; 0x70uy;
0xB4uy; 0x13uy; 0x0Cuy; 0x93uy; 0xBCuy; 0x43uy; 0x79uy; 0x44uy;
0xF4uy; 0xFDuy; 0x44uy; 0x52uy; 0xE2uy; 0xD7uy; 0x4Duy; 0xD3uy;
0x64uy; 0xF2uy; 0xE2uy; 0x1Euy; 0x71uy; 0xF5uy; 0x4Buy; 0xFFuy;
0x5Cuy; 0xAEuy; 0x82uy; 0xABuy; 0x9Cuy; 0x9Duy; 0xF6uy; 0x9Euy;
0xE8uy; 0x6Duy; 0x2Buy; 0xC5uy; 0x22uy; 0x36uy; 0x3Auy; 0x0Duy;
0xABuy; 0xC5uy; 0x21uy; 0x97uy; 0x9Buy; 0x0Duy; 0xEAuy; 0xDAuy;
0x1Duy; 0xBFuy; 0x9Auy; 0x42uy; 0xD5uy; 0xC4uy; 0x48uy; 0x4Euy;
0x0Auy; 0xBCuy; 0xD0uy; 0x6Buy; 0xFAuy; 0x53uy; 0xDDuy; 0xEFuy;
0x3Cuy; 0x1Buy; 0x20uy; 0xEEuy; 0x3Fuy; 0xD5uy; 0x9Duy; 0x7Cuy;
0x25uy; 0xE4uy; 0x1Duy; 0x2Buy; 0x66uy; 0x9Euy; 0x1Euy; 0xF1uy;
0x6Euy; 0x6Fuy; 0x52uy; 0xC3uy; 0x16uy; 0x4Duy; 0xF4uy; 0xFBuy;
0x79uy; 0x30uy; 0xE9uy; 0xE4uy; 0xE5uy; 0x88uy; 0x57uy; 0xB6uy;
0xACuy; 0x7Duy; 0x5Fuy; 0x42uy; 0xD6uy; 0x9Fuy; 0x6Duy; 0x18uy;
0x77uy; 0x63uy; 0xCFuy; 0x1Duy; 0x55uy; 0x03uy; 0x40uy; 0x04uy;
0x87uy; 0xF5uy; 0x5Buy; 0xA5uy; 0x7Euy; 0x31uy; 0xCCuy; 0x7Auy;
0x71uy; 0x35uy; 0xC8uy; 0x86uy; 0xEFuy; 0xB4uy; 0x31uy; 0x8Auy;
0xEDuy; 0x6Auy; 0x1Euy; 0x01uy; 0x2Duy; 0x9Euy; 0x68uy; 0x32uy;
0xA9uy; 0x07uy; 0x60uy; 0x0Auy; 0x91uy; 0x81uy; 0x30uy; 0xC4uy;
0x6Duy; 0xC7uy; 0x78uy; 0xF9uy; 0x71uy; 0xADuy; 0x00uy; 0x38uy;
0x09uy; 0x29uy; 0x99uy; 0xA3uy; 0x33uy; 0xCBuy; 0x8Buy; 0x7Auy;
0x1Auy; 0x1Duy; 0xB9uy; 0x3Duy; 0x71uy; 0x40uy; 0x00uy; 0x3Cuy;
0x2Auy; 0x4Euy; 0xCEuy; 0xA9uy; 0xF9uy; 0x8Duy; 0x0Auy; 0xCCuy;
0x0Auy; 0x82uy; 0x91uy; 0xCDuy; 0xCEuy; 0xC9uy; 0x7Duy; 0xCFuy;
0x8Euy; 0xC9uy; 0xB5uy; 0x5Auy; 0x7Fuy; 0x88uy; 0xA4uy; 0x6Buy;
0x4Duy; 0xB5uy; 0xA8uy; 0x51uy; 0xF4uy; 0x41uy; 0x82uy; 0xE1uy;
0xC6uy; 0x8Auy; 0x00uy; 0x7Euy; 0x5Euy; 0x0Duy; 0xD9uy; 0x02uy;
0x0Buy; 0xFDuy; 0x64uy; 0xB6uy; 0x45uy; 0x03uy; 0x6Cuy; 0x7Auy;
0x4Euy; 0x67uy; 0x7Duy; 0x2Cuy; 0x38uy; 0x53uy; 0x2Auy; 0x3Auy;
0x23uy; 0xBAuy; 0x44uy; 0x42uy; 0xCAuy; 0xF5uy; 0x3Euy; 0xA6uy;
0x3Buy; 0xB4uy; 0x54uy; 0x32uy; 0x9Buy; 0x76uy; 0x24uy; 0xC8uy;
0x91uy; 0x7Buy; 0xDDuy; 0x64uy; 0xB1uy; 0xC0uy; 0xFDuy; 0x4Cuy;
0xB3uy; 0x8Euy; 0x8Cuy; 0x33uy; 0x4Cuy; 0x70uy; 0x1Cuy; 0x3Auy;
0xCDuy; 0xADuy; 0x06uy; 0x57uy; 0xFCuy; 0xCFuy; 0xECuy; 0x71uy;
0x9Buy; 0x1Fuy; 0x5Cuy; 0x3Euy; 0x4Euy; 0x46uy; 0x04uy; 0x1Fuy;
0x38uy; 0x81uy; 0x47uy; 0xFBuy; 0x4Cuy; 0xFDuy; 0xB4uy; 0x77uy;
0xA5uy; 0x24uy; 0x71uy; 0xF7uy; 0xA9uy; 0xA9uy; 0x69uy; 0x10uy;
0xB8uy; 0x55uy; 0x32uy; 0x2Euy; 0xDBuy; 0x63uy; 0x40uy; 0xD8uy;
0xA0uy; 0x0Euy; 0xF0uy; 0x92uy; 0x35uy; 0x05uy; 0x11uy; 0xE3uy;
0x0Auy; 0xBEuy; 0xC1uy; 0xFFuy; 0xF9uy; 0xE3uy; 0xA2uy; 0x6Euy;
0x7Fuy; 0xB2uy; 0x9Fuy; 0x8Cuy; 0x18uy; 0x30uy; 0x23uy; 0xC3uy;
0x58uy; 0x7Euy; 0x38uy; 0xDAuy; 0x00uy; 0x77uy; 0xD9uy; 0xB4uy;
0x76uy; 0x3Euy; 0x4Euy; 0x4Buy; 0x94uy; 0xB2uy; 0xBBuy; 0xC1uy;
0x94uy; 0xC6uy; 0x65uy; 0x1Euy; 0x77uy; 0xCAuy; 0xF9uy; 0x92uy;
0xEEuy; 0xAAuy; 0xC0uy; 0x23uy; 0x2Auy; 0x28uy; 0x1Buy; 0xF6uy;
0xB3uy; 0xA7uy; 0x39uy; 0xC1uy; 0x22uy; 0x61uy; 0x16uy; 0x82uy;
0x0Auy; 0xE8uy; 0xDBuy; 0x58uy; 0x47uy; 0xA6uy; 0x7Cuy; 0xBEuy;
0xF9uy; 0xC9uy; 0x09uy; 0x1Buy; 0x46uy; 0x2Duy; 0x53uy; 0x8Cuy;
0xD7uy; 0x2Buy; 0x03uy; 0x74uy; 0x6Auy; 0xE7uy; 0x7Fuy; 0x5Euy;
0x62uy; 0x29uy; 0x2Cuy; 0x31uy; 0x15uy; 0x62uy; 0xA8uy; 0x46uy;
0x50uy; 0x5Duy; 0xC8uy; 0x2Duy; 0xB8uy; 0x54uy; 0x33uy; 0x8Auy;
0xE4uy; 0x9Fuy; 0x52uy; 0x35uy; 0xC9uy; 0x5Buy; 0x91uy; 0x17uy;
0x8Cuy; 0xCFuy; 0x2Duy; 0xD5uy; 0xCAuy; 0xCEuy; 0xF4uy; 0x03uy;
0xECuy; 0x9Duy; 0x18uy; 0x10uy; 0xC6uy; 0x27uy; 0x2Buy; 0x04uy;
0x5Buy; 0x3Buy; 0x71uy; 0xF9uy; 0xDCuy; 0x6Buy; 0x80uy; 0xD6uy;
0x3Fuy; 0xDDuy; 0x4Auy; 0x8Euy; 0x9Auy; 0xDBuy; 0x1Euy; 0x69uy;
0x62uy; 0xA6uy; 0x95uy; 0x26uy; 0xD4uy; 0x31uy; 0x61uy; 0xC1uy;
0xA4uy; 0x1Duy; 0x57uy; 0x0Duy; 0x79uy; 0x38uy; 0xDAuy; 0xD4uy;
0xA4uy; 0x0Euy; 0x32uy; 0x9Cuy; 0xD0uy; 0xE4uy; 0x0Euy; 0x65uy;
0xFFuy; 0xFFuy; 0xFFuy; 0xFFuy; 0xFFuy; 0xFFuy; 0xFFuy; 0xFFuy
] in
assert_norm (List.Tot.length l == 768);
l
let ffdhe_p6144: lseq pub_uint8 768 = of_list list_ffdhe_p6144 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NatMod.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "Spec.FFDHE.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 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.FFDHE.ffdhe_params_t | Prims.Tot | [
"total"
] | [] | [
"Spec.FFDHE.Mk_ffdhe_params",
"Spec.FFDHE.ffdhe_p6144",
"Spec.FFDHE.ffdhe_g2"
] | [] | false | false | false | true | false | let ffdhe_params_6144:ffdhe_params_t =
| Mk_ffdhe_params 768 ffdhe_p6144 1 ffdhe_g2 | false |
Spec.FFDHE.fst | Spec.FFDHE.ffdhe_g2 | val ffdhe_g2:lseq pub_uint8 1 | val ffdhe_g2:lseq pub_uint8 1 | let ffdhe_g2: lseq pub_uint8 1 = of_list list_ffdhe_g2 | {
"file_name": "specs/Spec.FFDHE.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 54,
"end_line": 30,
"start_col": 0,
"start_line": 30
} | module Spec.FFDHE
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
(** https://tools.ietf.org/html/rfc7919#appendix-A *)
noeq type ffdhe_params_t =
| Mk_ffdhe_params:
ffdhe_p_len:size_nat
-> ffdhe_p:lseq pub_uint8 ffdhe_p_len
-> ffdhe_g_len:size_nat
-> ffdhe_g:lseq pub_uint8 ffdhe_g_len
-> ffdhe_params_t
[@"opaque_to_smt"]
inline_for_extraction
let list_ffdhe_g2: List.Tot.llist pub_uint8 1 =
[@inline_let]
let l = [ 0x02uy ] in
assert_norm (List.Tot.length l == 1);
l | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NatMod.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "Spec.FFDHE.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 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.Sequence.lseq (Lib.IntTypes.int_t Lib.IntTypes.U8 Lib.IntTypes.PUB) 1 | Prims.Tot | [
"total"
] | [] | [
"Lib.Sequence.of_list",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.PUB",
"Spec.FFDHE.list_ffdhe_g2"
] | [] | false | false | false | false | false | let ffdhe_g2:lseq pub_uint8 1 =
| of_list list_ffdhe_g2 | false |
LowParse.Low.ConstInt32.fst | LowParse.Low.ConstInt32.compare_by_bytes_equiv | val compare_by_bytes_equiv
(a0: U8.t{0 <= U8.v a0 /\ U8.v a0 < 256})
(a1: U8.t{0 <= U8.v a1 /\ U8.v a1 < 256})
(a2: U8.t{0 <= U8.v a2 /\ U8.v a2 < 256})
(a3: U8.t{0 <= U8.v a3 /\ U8.v a3 < 256})
(b0: U8.t{0 <= U8.v b0 /\ U8.v b0 < 256})
(b1: U8.t{0 <= U8.v b1 /\ U8.v b1 < 256})
(b2: U8.t{0 <= U8.v b2 /\ U8.v b2 < 256})
(b3: U8.t{0 <= U8.v b3 /\ U8.v b3 < 256})
: Lemma
((compare_by_bytes a0 a1 a2 a3 b0 b1 b2 b3) == compare_by_bytes' a0 a1 a2 a3 b0 b1 b2 b3) | val compare_by_bytes_equiv
(a0: U8.t{0 <= U8.v a0 /\ U8.v a0 < 256})
(a1: U8.t{0 <= U8.v a1 /\ U8.v a1 < 256})
(a2: U8.t{0 <= U8.v a2 /\ U8.v a2 < 256})
(a3: U8.t{0 <= U8.v a3 /\ U8.v a3 < 256})
(b0: U8.t{0 <= U8.v b0 /\ U8.v b0 < 256})
(b1: U8.t{0 <= U8.v b1 /\ U8.v b1 < 256})
(b2: U8.t{0 <= U8.v b2 /\ U8.v b2 < 256})
(b3: U8.t{0 <= U8.v b3 /\ U8.v b3 < 256})
: Lemma
((compare_by_bytes a0 a1 a2 a3 b0 b1 b2 b3) == compare_by_bytes' a0 a1 a2 a3 b0 b1 b2 b3) | let compare_by_bytes_equiv
(a0: U8.t { 0 <= U8.v a0 /\ U8.v a0 < 256 } )
(a1: U8.t { 0 <= U8.v a1 /\ U8.v a1 < 256 } )
(a2: U8.t { 0 <= U8.v a2 /\ U8.v a2 < 256 } )
(a3: U8.t { 0 <= U8.v a3 /\ U8.v a3 < 256 } )
(b0: U8.t { 0 <= U8.v b0 /\ U8.v b0 < 256 } )
(b1: U8.t { 0 <= U8.v b1 /\ U8.v b1 < 256 } )
(b2: U8.t { 0 <= U8.v b2 /\ U8.v b2 < 256 } )
(b3: U8.t { 0 <= U8.v b3 /\ U8.v b3 < 256 } )
: Lemma
((compare_by_bytes a0 a1 a2 a3 b0 b1 b2 b3) ==
compare_by_bytes' a0 a1 a2 a3 b0 b1 b2 b3)
= let a = compose_int32le (U8.v a0) (U8.v a1) (U8.v a2) (U8.v a3) in
let b = compose_int32le (U8.v b0) (U8.v b1) (U8.v b2) (U8.v b3) in
decompose_compose_equiv a;
decompose_compose_equiv b | {
"file_name": "src/lowparse/LowParse.Low.ConstInt32.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 27,
"end_line": 146,
"start_col": 0,
"start_line": 131
} | module LowParse.Low.ConstInt32
(* LowParse implementation module for 32 bits contants *)
include FStar.Endianness
include LowParse.Spec.ConstInt32
include LowParse.Spec.Int32le
include LowParse.Low.Combinators
include LowParse.Low.Int32le
module U32 = FStar.UInt32
module U8 = FStar.UInt8
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module B = LowStar.Buffer
module Cast = FStar.Int.Cast
module U64 = FStar.UInt64
let valid_constint32le
(v: nat { 0 <= v /\ v < 4294967296 } )
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma (valid (parse_constint32le v) h input pos
<==>
(valid parse_int32le h input pos /\
U32.v (contents parse_int32le h input pos) == v))
= valid_facts (parse_constint32le v) h input pos;
valid_facts parse_int32le h input pos;
parse_constint32le_unfold v (bytes_of_slice_from h input pos)
inline_for_extraction
let validate_constint32le_slow
(v: U32.t { 0 <= U32.v v /\ U32.v v < 4294967296 } )
: Tot (validator (parse_constint32le (U32.v v)))
= fun #rrel #rel (input: slice rrel rel) pos ->
let h = HST.get() in
let _ =
valid_constint32le (U32.v v) h input (uint64_to_uint32 pos);
valid_equiv parse_int32le h input (uint64_to_uint32 pos)
in
if U64.lt (Cast.uint32_to_uint64 input.len `U64.sub` pos) 4uL
then
validator_error_not_enough_data
else
let v' = read_int32le input (uint64_to_uint32 pos) in
if U32.eq v v' then
pos `U64.add` 4uL
else
validator_error_generic
inline_for_extraction
let read_constint32le
(v: U32.t { 0 <= U32.v v /\ U32.v v < 4294967296 } )
: Tot (leaf_reader (parse_constint32le (U32.v v)))
= fun #rrel #rel input pos ->
v
inline_for_extraction
let decompose_int32le_0
(v: nat { 0 <= v /\ v < 4294967296 } )
: Tot (b0: nat { 0 <= b0 /\ b0 < 256 } )
= v % 256
inline_for_extraction
let decompose_int32le_1
(v: nat { 0 <= v /\ v < 4294967296 } )
: Tot (b1: nat { 0 <= b1 /\ b1 < 256 } )
= v / 256 % 256
inline_for_extraction
let decompose_int32le_2
(v: nat { 0 <= v /\ v < 4294967296 } )
: Tot (b2: nat { 0 <= b2 /\ b2 < 256 } )
= v / 65536 % 256
inline_for_extraction
let decompose_int32le_3
(v: nat { 0 <= v /\ v < 4294967296 } )
: Tot (b3: nat { 0 <= b3 /\ b3 < 256 } )
= v / 16777216
let compose_int32le
(b0: nat { 0 <= b0 /\ b0 < 256 } )
(b1: nat { 0 <= b1 /\ b1 < 256 } )
(b2: nat { 0 <= b2 /\ b2 < 256 } )
(b3: nat { 0 <= b3 /\ b3 < 256 } )
: Tot (v: nat { 0 <= v /\ v < 4294967296 } )
= b0
+ 256 `FStar.Mul.op_Star` (b1
+ 256 `FStar.Mul.op_Star` (b2
+ 256 `FStar.Mul.op_Star` b3))
#push-options "--z3rlimit 16"
let decompose_compose_equiv
(v: nat { 0 <= v /\ v < 4294967296 } )
: Lemma (compose_int32le (decompose_int32le_0 v) (decompose_int32le_1 v) (decompose_int32le_2 v) (decompose_int32le_3 v) == v)
= ()
#pop-options
inline_for_extraction
let compare_by_bytes
(a0: U8.t { 0 <= U8.v a0 /\ U8.v a0 < 256 } )
(a1: U8.t { 0 <= U8.v a1 /\ U8.v a1 < 256 } )
(a2: U8.t { 0 <= U8.v a2 /\ U8.v a2 < 256 } )
(a3: U8.t { 0 <= U8.v a3 /\ U8.v a3 < 256 } )
(b0: U8.t { 0 <= U8.v b0 /\ U8.v b0 < 256 } )
(b1: U8.t { 0 <= U8.v b1 /\ U8.v b1 < 256 } )
(b2: U8.t { 0 <= U8.v b2 /\ U8.v b2 < 256 } )
(b3: U8.t { 0 <= U8.v b3 /\ U8.v b3 < 256 } )
= a0 = b0 && a1 = b1 && a2 = b2 && a3 = b3
let compare_by_bytes'
(a0: U8.t { 0 <= U8.v a0 /\ U8.v a0 < 256 } )
(a1: U8.t { 0 <= U8.v a1 /\ U8.v a1 < 256 } )
(a2: U8.t { 0 <= U8.v a2 /\ U8.v a2 < 256 } )
(a3: U8.t { 0 <= U8.v a3 /\ U8.v a3 < 256 } )
(b0: U8.t { 0 <= U8.v b0 /\ U8.v b0 < 256 } )
(b1: U8.t { 0 <= U8.v b1 /\ U8.v b1 < 256 } )
(b2: U8.t { 0 <= U8.v b2 /\ U8.v b2 < 256 } )
(b3: U8.t { 0 <= U8.v b3 /\ U8.v b3 < 256 } )
= (compose_int32le (U8.v a0) (U8.v a1) (U8.v a2) (U8.v a3)) =
(compose_int32le (U8.v b0) (U8.v b1) (U8.v b2) (U8.v b3))
#push-options "--max_fuel 5 --z3rlimit 64" | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Int32le.fst.checked",
"LowParse.Spec.ConstInt32.fst.checked",
"LowParse.Low.Int32le.fst.checked",
"LowParse.Low.Combinators.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Endianness.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.ConstInt32.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "LowParse.Low.Int32le",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Int32le",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.ConstInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Endianness",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 5,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 64,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
a0: FStar.UInt8.t{0 <= FStar.UInt8.v a0 /\ FStar.UInt8.v a0 < 256} ->
a1: FStar.UInt8.t{0 <= FStar.UInt8.v a1 /\ FStar.UInt8.v a1 < 256} ->
a2: FStar.UInt8.t{0 <= FStar.UInt8.v a2 /\ FStar.UInt8.v a2 < 256} ->
a3: FStar.UInt8.t{0 <= FStar.UInt8.v a3 /\ FStar.UInt8.v a3 < 256} ->
b0: FStar.UInt8.t{0 <= FStar.UInt8.v b0 /\ FStar.UInt8.v b0 < 256} ->
b1: FStar.UInt8.t{0 <= FStar.UInt8.v b1 /\ FStar.UInt8.v b1 < 256} ->
b2: FStar.UInt8.t{0 <= FStar.UInt8.v b2 /\ FStar.UInt8.v b2 < 256} ->
b3: FStar.UInt8.t{0 <= FStar.UInt8.v b3 /\ FStar.UInt8.v b3 < 256}
-> FStar.Pervasives.Lemma
(ensures
LowParse.Low.ConstInt32.compare_by_bytes a0 a1 a2 a3 b0 b1 b2 b3 ==
LowParse.Low.ConstInt32.compare_by_bytes' a0 a1 a2 a3 b0 b1 b2 b3) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.UInt8.t",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.UInt8.v",
"Prims.op_LessThan",
"LowParse.Low.ConstInt32.decompose_compose_equiv",
"Prims.unit",
"Prims.nat",
"LowParse.Low.ConstInt32.compose_int32le",
"Prims.l_True",
"Prims.squash",
"Prims.eq2",
"Prims.bool",
"LowParse.Low.ConstInt32.compare_by_bytes",
"LowParse.Low.ConstInt32.compare_by_bytes'",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let compare_by_bytes_equiv
(a0: U8.t{0 <= U8.v a0 /\ U8.v a0 < 256})
(a1: U8.t{0 <= U8.v a1 /\ U8.v a1 < 256})
(a2: U8.t{0 <= U8.v a2 /\ U8.v a2 < 256})
(a3: U8.t{0 <= U8.v a3 /\ U8.v a3 < 256})
(b0: U8.t{0 <= U8.v b0 /\ U8.v b0 < 256})
(b1: U8.t{0 <= U8.v b1 /\ U8.v b1 < 256})
(b2: U8.t{0 <= U8.v b2 /\ U8.v b2 < 256})
(b3: U8.t{0 <= U8.v b3 /\ U8.v b3 < 256})
: Lemma
((compare_by_bytes a0 a1 a2 a3 b0 b1 b2 b3) == compare_by_bytes' a0 a1 a2 a3 b0 b1 b2 b3) =
| let a = compose_int32le (U8.v a0) (U8.v a1) (U8.v a2) (U8.v a3) in
let b = compose_int32le (U8.v b0) (U8.v b1) (U8.v b2) (U8.v b3) in
decompose_compose_equiv a;
decompose_compose_equiv b | false |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.