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
Steel.FractionalAnchoredPreorder.fst
Steel.FractionalAnchoredPreorder.avalue_val
val avalue_val : m: Steel.FractionalAnchoredPreorder.avalue s -> Steel.Preorder.vhist p
let avalue_val (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue #v #p s) = snd m
{ "file_name": "lib/steel/Steel.FractionalAnchoredPreorder.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 11, "end_line": 418, "start_col": 0, "start_line": 414 }
(* Copyright 2021 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. Author: N. Swamy *) module Steel.FractionalAnchoredPreorder (** This module provides a partial commutative monoid (PCM) for use in the ghost state of a concurrent Steel program. Its goal is to facilitate a form of information-sharing between multiple threads including the following features: Fractions, Preorders, Snapshots, and Anchors --- Anchors are the most unusual. 1. Fractions: Ownership of the state is controlled by a fractional permission, so multiple threads may share read-only privileges on the state, but only one can have write permission. 2. Preorders: The ghost state is governed by a preorder p and all updates to the state must respect the preorder (a reflexive, transitive relation on the state) 3. Snapshots: Since the state always evolves by a preorder, it is possible to take a snapshot of the state. A snapshot does not confer any particular ownership on the state, except knowledge of a snapshot ensures that the current state is related to the snapshot by the preorder. 4. Anchors are a kind of refinement of the preorder. If a thread owns an anchored value [v], then no other thread, even a thread owning a full fractional permission, can advance the state "too far" from the anchor. In particular, the PCM is parameterized by a binary relation on values, [anchors:anchor_relation]. If a thread owns the anchor [v], then the current value `cur` of the state must be in relation [v `anchors` cur]. This can be used to ensure that the knowledge of one thread is never becomes too stale. For example, this allows one to model a shared monotonically increasing counter, where if one thread anchors knowledge of the counter at the value 5, no other thread can increase the value of the counter beyond, say, 10, (when the anchor relation is y - x <= 5), until the anchoring thread releases the anchor. Further, at any point, a thread can take a snapshot of the counter and rely on the fact that the value of the counter in the future will be >= the snapshot. *) open FStar.PCM open FStar.Preorder open Steel.Preorder open Steel.FractionalPermission #push-options "--fuel 0 --ifuel 2" /// A permission: is a pair of /// /// * an optional fractional permission; with `Some p` indicating /// some ownership, while `None` is an additional "0" permission /// value, to encode snapshots. /// /// * and an optional anchor, where `Some a` indicates the current /// value can't be too far from `a`. let permission (v:Type) = option perm & option v /// Non-zero permission is either a read or write permission let has_nonzero #v (p:permission v) = Some? (fst p) /// Has an anchor set let has_anchor #v (p:permission v) = Some? (snd p) /// Either an anchor or non-zero let has_some_ownership #v (p:permission v) = has_nonzero p || has_anchor p /// The anchoring value let anchor_of #v (p:permission v { has_anchor p }) : v = Some?.v (snd p) /// The anchoring relation: /// -- A binary relation on values /// -- refining the preorder /// -- and if x `anchors` z then it also anchors any `y` between `x` and `z` /// /// Explaining the third clause a bit: /// Think intuitively of anchoring relations as a kind of distance measure /// /// if `z` is close enough to `x` then if `z` is further than `y` /// (since it is ahead of `y` in the preorder) then `y` is also /// close enough to `x` let anchor_rel (#v:Type) (p:preorder v) = anchors:(v -> v -> prop) { (forall v0 v1. anchors v0 v1 ==> p v0 v1) /\ (forall x z. x `anchors` z ==> (forall y. p x y /\ p y z ==> x `anchors` y)) // } /// An implementation remark: We use Steel.Preorder here to /// generically transform any preorder into a PCM. That works by /// taking the value of the PCM to be a history of values related by /// the preorder. So, throughout, we'll be using the the [vhist p] /// from Steel.Preorder, the type of a non-empty history compatible /// with [p]. The details of the histories don't matter much for our /// purposes---we only care about the most recent value, for which /// we'll use [curval v]. /// If the anchor is set, then the current value is anchored by it let anchored (#v:Type) (#p:preorder v) (anchors:anchor_rel p) (pv:(permission v & vhist p)) = has_anchor (fst pv) ==> anchor_of (fst pv) `anchors` curval (snd pv) /// A value in our fractional anchored PCM is a pair of a permission /// and a p-compatible history, refined to ensure that if the anchor /// is set, then the current value is anchored by it. let avalue (#v:Type) (#p:preorder v) (anchors:anchor_rel p) = pv:(permission v & vhist p) { anchored anchors pv } /// initial_value: A utility to construct a value in the PCM #push-options "--fuel 1" let initial_value (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (value:v { anchors value value }) : avalue anchors = (Some full_perm, Some value), [value] #pop-options /// We add a unit element to [avalue], as needed for a PCM [@@erasable] noeq type knowledge (#v:Type) (#p:preorder v) (anchors:anchor_rel p) = | Owns : avalue anchors -> knowledge anchors | Nothing : knowledge anchors let b2p (b:bool) : prop = b == true /// Fractional permissions are composable when their sum <= 1.0 let perm_opt_composable (p0 p1:option perm) : prop = match p0, p1 with | None, None -> True | Some p, None | None, Some p -> b2p (p `lesser_equal_perm` full_perm) | Some p0, Some p1 -> b2p (sum_perm p0 p1 `lesser_equal_perm` full_perm) /// Composing them sums the permissions let compose_perm_opt (p0 p1:option perm) = match p0, p1 with | None, p | p, None -> p | Some p0, Some p1 -> Some (sum_perm p0 p1) /// Anchored permissions are composable when at most one of them has the anchor set let permission_composable #v (p0 p1 : permission v) : prop = let q0, s0 = p0 in let q1, s1 = p1 in perm_opt_composable q0 q1 /\ // some of fracs can't exceed 1 not (Some? s0 && Some? s1) // at most one can have an anchor /// Compose permissions component wise, keeping the anchor if set let compose_permissions (#v:_) (p0:permission v) (p1:permission v{permission_composable p0 p1}) : permission v = compose_perm_opt (fst p0) (fst p1), (match snd p0, snd p1 with | None, a | a, None -> a) /// This is the central definition of the PCM --- defining when two /// values are composable, or equivalently, when one thread's /// knowledge of [av0] is compatible with another thread's knowledge /// of [av1] /// /// This definition shows the interplay between fractions and anchors. /// It wasn't obvious to me how to factor this further, e.g., adding /// anchors to preorders and then separately adding fractions to it. let avalue_composable (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (av0 av1: avalue anchors) : prop = let (p0, v0) = av0 in let (p1, v1) = av1 in permission_composable p0 p1 /\ (if not (has_some_ownership p0) && not (has_some_ownership p1) then p_composable _ v0 v1 //neither has ownership, one history is older than the other else if not (has_some_ownership p0) && has_some_ownership p1 then ( if has_nonzero p1 then v1 `extends` v0 //the one with ownership is more recent else ( //this part is the most subtle assert (has_anchor p1); p_composable _ v0 v1 /\ (v0 `extends` v1 ==> //if v0 is a more recent snapshot than v1 //then v0 must still be anchored by v1's anchor anchor_of p1 `anchors` curval v0) ) ) else if has_some_ownership p0 && not (has_some_ownership p1) then ( //symmetric if has_nonzero p0 then v0 `extends` v1 else ( assert (has_anchor p0); p_composable _ v0 v1 /\ (v1 `extends` v0 ==> anchor_of p0 `anchors` curval v1) ) ) else ( assert (has_some_ownership p0 && has_some_ownership p1); if has_nonzero p0 && has_nonzero p1 then v0 == v1 //if both have non-zero perm, then they must both only have read permission and must agree on the value else if has_nonzero p0 && has_anchor p1 then ( assert (not (has_nonzero p1)); //The key part of the anchor semantics: v0 `extends` v1 /\ //v0 has advanceable ownership, so extends anchor_of p1 `anchors` curval v0 //but not beyond what is allowed by s ) else if has_anchor p0 && has_nonzero p1 //symmetric then ( assert (not (has_nonzero p0)); v1 `extends` v0 /\ anchor_of p0 `anchors` curval v1 //v1 extends, but not beyond what is allowed by s ) else (assert false; False) ) ) //exhaustive /// Lifting avalue comosability to knowledge, including the unit let composable #v (#p:preorder v) (#a:anchor_rel p) : symrel (knowledge a) = fun (k0 k1:knowledge a) -> match k0, k1 with | Nothing, _ | _, Nothing -> True | Owns m, Owns m' -> avalue_composable m m' /// Compose avalues by composing permissions and composing the values /// using the underlying preorder PCM let compose_avalue (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (m0:avalue anchors) (m1:avalue anchors { avalue_composable m0 m1 } ) : avalue anchors = let p0, v0 = m0 in let p1, v1 = m1 in let p12 = compose_permissions p0 p1 in let v12 = p_op _ v0 v1 in p12, v12 //////////////////////////////////////////////////////////////////////////////// (** avalue composition is associative and commutative **) let compose_avalue_comm (#v:Type) (#p:preorder v) (#anc:anchor_rel p) (m0: avalue anc) (m1: avalue anc{ avalue_composable m0 m1 }) : Lemma (compose_avalue m0 m1 == compose_avalue m1 m0) = () let avalue_composable_assoc_l (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (m0: avalue anchors) (m1: avalue anchors) (m2: avalue anchors { avalue_composable m1 m2 /\ avalue_composable m0 (compose_avalue m1 m2) }) : Lemma (avalue_composable m0 m1 /\ avalue_composable (compose_avalue m0 m1) m2) = () let compose_avalue_assoc_l (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m0: avalue s) (m1: avalue s) (m2: avalue s { avalue_composable m1 m2 /\ avalue_composable m0 (compose_avalue m1 m2) }) : Lemma (avalue_composable m0 m1 /\ avalue_composable (compose_avalue m0 m1) m2 /\ compose_avalue m0 (compose_avalue m1 m2) == compose_avalue (compose_avalue m0 m1) m2) = avalue_composable_assoc_l m0 m1 m2 let avalue_composable_assoc_r (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (m0: avalue anchors) (m1: avalue anchors) (m2: avalue anchors { avalue_composable m0 m1 /\ avalue_composable (compose_avalue m0 m1) m2 }) : Lemma (avalue_composable m1 m2 /\ avalue_composable m0 (compose_avalue m1 m2)) = () let compose_avalue_assoc_r (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m0: avalue s) (m1: avalue s) (m2: avalue s{ avalue_composable m0 m1 /\ avalue_composable (compose_avalue m0 m1) m2 }) : Lemma (avalue_composable m1 m2 /\ avalue_composable m0 (compose_avalue m1 m2) /\ compose_avalue m0 (compose_avalue m1 m2) == compose_avalue (compose_avalue m0 m1) m2) = avalue_composable_assoc_r m0 m1 m2 //////////////////////////////////////////////////////////////////////////////// /// lifting avalue composition to knowledge, including unit let compose (#v:Type) (#p:preorder v) (#s:anchor_rel p) (k0:knowledge s) (k1:knowledge s{ composable k0 k1 }) : knowledge s = match k0, k1 with | Nothing, k | k, Nothing -> k | Owns m, Owns m' -> Owns (compose_avalue m m') let composable_assoc_r #v (#p:preorder v) (#s:anchor_rel p) (k0 k1 k2: knowledge s) : Lemma (requires composable k0 k1 /\ composable (compose k0 k1) k2) (ensures composable k1 k2 /\ composable k0 (compose k1 k2) /\ compose k0 (compose k1 k2) == compose (compose k0 k1) k2 ) = match k0, k1, k2 with | Nothing, _, _ | _, Nothing, _ | _, _, Nothing -> () | Owns m0, Owns m1, Owns m2 -> compose_avalue_assoc_r m0 m1 m2 let composable_assoc_l #v (#p:preorder v) (#s:anchor_rel p) (k0 k1 k2: knowledge s) : Lemma (requires composable k1 k2 /\ composable k0 (compose k1 k2)) (ensures composable k0 k1 /\ composable (compose k0 k1) k2 /\ compose k0 (compose k1 k2) == compose (compose k0 k1) k2) = match k0, k1, k2 with | Nothing, _, _ | _, Nothing, _ | _, _, Nothing -> () | Owns m0, Owns m1, Owns m2 -> compose_avalue_assoc_l m0 m1 m2 /// Now, we can define our PCM /// The core of the PCM let p0 #v #p #s : pcm' (knowledge #v #p s) = { composable; op=compose; one=Nothing } let avalue_perm (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) = fst m /// A avalue represents full ownership when the fraction is full AND /// the anchor is set. This means that no knowledge held by any other /// thread can constrain this value meaningfully. let avalue_owns (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) : prop = fst (avalue_perm m) == Some full_perm /\ Some? (snd (avalue_perm m)) let full_knowledge #v #p #s (kn:knowledge #v #p s) : prop = match kn with | Nothing -> False | Owns km -> avalue_owns km /// The PCM itself, together with proofs of its properties let pcm #v #p #s : pcm (knowledge #v #p s) = { p = p0; comm = (fun k0 k1 -> match k0, k1 with | Nothing, _ | _, Nothing -> () | Owns m0, Owns m1 -> compose_avalue_comm m0 m1); assoc = (fun k0 k1 k2 -> composable_assoc_l k0 k1 k2); assoc_r = (fun k0 k1 k2 -> composable_assoc_r k0 k1 k2); is_unit = (fun _ -> ()); refine = full_knowledge; }
{ "checked_file": "/", "dependencies": [ "Steel.Preorder.fst.checked", "Steel.FractionalPermission.fst.checked", "prims.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked" ], "interface_file": false, "source_file": "Steel.FractionalAnchoredPreorder.fst" }
[ { "abbrev": false, "full_module": "Steel.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Steel.Preorder", "short_module": null }, { "abbrev": false, "full_module": "FStar.Preorder", "short_module": null }, { "abbrev": false, "full_module": "FStar.PCM", "short_module": null }, { "abbrev": false, "full_module": "Steel", "short_module": null }, { "abbrev": false, "full_module": "Steel", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
m: Steel.FractionalAnchoredPreorder.avalue s -> Steel.Preorder.vhist p
Prims.Tot
[ "total" ]
[]
[ "FStar.Preorder.preorder", "Steel.FractionalAnchoredPreorder.anchor_rel", "Steel.FractionalAnchoredPreorder.avalue", "FStar.Pervasives.Native.snd", "Steel.FractionalAnchoredPreorder.permission", "Steel.Preorder.vhist" ]
[]
false
false
false
false
false
let avalue_val (#v: Type) (#p: preorder v) (#s: anchor_rel p) (m: avalue #v #p s) =
snd m
false
Steel.FractionalAnchoredPreorder.fst
Steel.FractionalAnchoredPreorder.compat_with_any_anchor_of
val compat_with_any_anchor_of : v1: v -> v0: Steel.FractionalAnchoredPreorder.avalue anchors -> Prims.logical
let compat_with_any_anchor_of (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (v1:v) (v0:avalue anchors) = forall (anchor:v). anchor `anchors` curval (avalue_val v0) ==> anchor `anchors` v1
{ "file_name": "lib/steel/Steel.FractionalAnchoredPreorder.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 37, "end_line": 504, "start_col": 0, "start_line": 498 }
(* Copyright 2021 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. Author: N. Swamy *) module Steel.FractionalAnchoredPreorder (** This module provides a partial commutative monoid (PCM) for use in the ghost state of a concurrent Steel program. Its goal is to facilitate a form of information-sharing between multiple threads including the following features: Fractions, Preorders, Snapshots, and Anchors --- Anchors are the most unusual. 1. Fractions: Ownership of the state is controlled by a fractional permission, so multiple threads may share read-only privileges on the state, but only one can have write permission. 2. Preorders: The ghost state is governed by a preorder p and all updates to the state must respect the preorder (a reflexive, transitive relation on the state) 3. Snapshots: Since the state always evolves by a preorder, it is possible to take a snapshot of the state. A snapshot does not confer any particular ownership on the state, except knowledge of a snapshot ensures that the current state is related to the snapshot by the preorder. 4. Anchors are a kind of refinement of the preorder. If a thread owns an anchored value [v], then no other thread, even a thread owning a full fractional permission, can advance the state "too far" from the anchor. In particular, the PCM is parameterized by a binary relation on values, [anchors:anchor_relation]. If a thread owns the anchor [v], then the current value `cur` of the state must be in relation [v `anchors` cur]. This can be used to ensure that the knowledge of one thread is never becomes too stale. For example, this allows one to model a shared monotonically increasing counter, where if one thread anchors knowledge of the counter at the value 5, no other thread can increase the value of the counter beyond, say, 10, (when the anchor relation is y - x <= 5), until the anchoring thread releases the anchor. Further, at any point, a thread can take a snapshot of the counter and rely on the fact that the value of the counter in the future will be >= the snapshot. *) open FStar.PCM open FStar.Preorder open Steel.Preorder open Steel.FractionalPermission #push-options "--fuel 0 --ifuel 2" /// A permission: is a pair of /// /// * an optional fractional permission; with `Some p` indicating /// some ownership, while `None` is an additional "0" permission /// value, to encode snapshots. /// /// * and an optional anchor, where `Some a` indicates the current /// value can't be too far from `a`. let permission (v:Type) = option perm & option v /// Non-zero permission is either a read or write permission let has_nonzero #v (p:permission v) = Some? (fst p) /// Has an anchor set let has_anchor #v (p:permission v) = Some? (snd p) /// Either an anchor or non-zero let has_some_ownership #v (p:permission v) = has_nonzero p || has_anchor p /// The anchoring value let anchor_of #v (p:permission v { has_anchor p }) : v = Some?.v (snd p) /// The anchoring relation: /// -- A binary relation on values /// -- refining the preorder /// -- and if x `anchors` z then it also anchors any `y` between `x` and `z` /// /// Explaining the third clause a bit: /// Think intuitively of anchoring relations as a kind of distance measure /// /// if `z` is close enough to `x` then if `z` is further than `y` /// (since it is ahead of `y` in the preorder) then `y` is also /// close enough to `x` let anchor_rel (#v:Type) (p:preorder v) = anchors:(v -> v -> prop) { (forall v0 v1. anchors v0 v1 ==> p v0 v1) /\ (forall x z. x `anchors` z ==> (forall y. p x y /\ p y z ==> x `anchors` y)) // } /// An implementation remark: We use Steel.Preorder here to /// generically transform any preorder into a PCM. That works by /// taking the value of the PCM to be a history of values related by /// the preorder. So, throughout, we'll be using the the [vhist p] /// from Steel.Preorder, the type of a non-empty history compatible /// with [p]. The details of the histories don't matter much for our /// purposes---we only care about the most recent value, for which /// we'll use [curval v]. /// If the anchor is set, then the current value is anchored by it let anchored (#v:Type) (#p:preorder v) (anchors:anchor_rel p) (pv:(permission v & vhist p)) = has_anchor (fst pv) ==> anchor_of (fst pv) `anchors` curval (snd pv) /// A value in our fractional anchored PCM is a pair of a permission /// and a p-compatible history, refined to ensure that if the anchor /// is set, then the current value is anchored by it. let avalue (#v:Type) (#p:preorder v) (anchors:anchor_rel p) = pv:(permission v & vhist p) { anchored anchors pv } /// initial_value: A utility to construct a value in the PCM #push-options "--fuel 1" let initial_value (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (value:v { anchors value value }) : avalue anchors = (Some full_perm, Some value), [value] #pop-options /// We add a unit element to [avalue], as needed for a PCM [@@erasable] noeq type knowledge (#v:Type) (#p:preorder v) (anchors:anchor_rel p) = | Owns : avalue anchors -> knowledge anchors | Nothing : knowledge anchors let b2p (b:bool) : prop = b == true /// Fractional permissions are composable when their sum <= 1.0 let perm_opt_composable (p0 p1:option perm) : prop = match p0, p1 with | None, None -> True | Some p, None | None, Some p -> b2p (p `lesser_equal_perm` full_perm) | Some p0, Some p1 -> b2p (sum_perm p0 p1 `lesser_equal_perm` full_perm) /// Composing them sums the permissions let compose_perm_opt (p0 p1:option perm) = match p0, p1 with | None, p | p, None -> p | Some p0, Some p1 -> Some (sum_perm p0 p1) /// Anchored permissions are composable when at most one of them has the anchor set let permission_composable #v (p0 p1 : permission v) : prop = let q0, s0 = p0 in let q1, s1 = p1 in perm_opt_composable q0 q1 /\ // some of fracs can't exceed 1 not (Some? s0 && Some? s1) // at most one can have an anchor /// Compose permissions component wise, keeping the anchor if set let compose_permissions (#v:_) (p0:permission v) (p1:permission v{permission_composable p0 p1}) : permission v = compose_perm_opt (fst p0) (fst p1), (match snd p0, snd p1 with | None, a | a, None -> a) /// This is the central definition of the PCM --- defining when two /// values are composable, or equivalently, when one thread's /// knowledge of [av0] is compatible with another thread's knowledge /// of [av1] /// /// This definition shows the interplay between fractions and anchors. /// It wasn't obvious to me how to factor this further, e.g., adding /// anchors to preorders and then separately adding fractions to it. let avalue_composable (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (av0 av1: avalue anchors) : prop = let (p0, v0) = av0 in let (p1, v1) = av1 in permission_composable p0 p1 /\ (if not (has_some_ownership p0) && not (has_some_ownership p1) then p_composable _ v0 v1 //neither has ownership, one history is older than the other else if not (has_some_ownership p0) && has_some_ownership p1 then ( if has_nonzero p1 then v1 `extends` v0 //the one with ownership is more recent else ( //this part is the most subtle assert (has_anchor p1); p_composable _ v0 v1 /\ (v0 `extends` v1 ==> //if v0 is a more recent snapshot than v1 //then v0 must still be anchored by v1's anchor anchor_of p1 `anchors` curval v0) ) ) else if has_some_ownership p0 && not (has_some_ownership p1) then ( //symmetric if has_nonzero p0 then v0 `extends` v1 else ( assert (has_anchor p0); p_composable _ v0 v1 /\ (v1 `extends` v0 ==> anchor_of p0 `anchors` curval v1) ) ) else ( assert (has_some_ownership p0 && has_some_ownership p1); if has_nonzero p0 && has_nonzero p1 then v0 == v1 //if both have non-zero perm, then they must both only have read permission and must agree on the value else if has_nonzero p0 && has_anchor p1 then ( assert (not (has_nonzero p1)); //The key part of the anchor semantics: v0 `extends` v1 /\ //v0 has advanceable ownership, so extends anchor_of p1 `anchors` curval v0 //but not beyond what is allowed by s ) else if has_anchor p0 && has_nonzero p1 //symmetric then ( assert (not (has_nonzero p0)); v1 `extends` v0 /\ anchor_of p0 `anchors` curval v1 //v1 extends, but not beyond what is allowed by s ) else (assert false; False) ) ) //exhaustive /// Lifting avalue comosability to knowledge, including the unit let composable #v (#p:preorder v) (#a:anchor_rel p) : symrel (knowledge a) = fun (k0 k1:knowledge a) -> match k0, k1 with | Nothing, _ | _, Nothing -> True | Owns m, Owns m' -> avalue_composable m m' /// Compose avalues by composing permissions and composing the values /// using the underlying preorder PCM let compose_avalue (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (m0:avalue anchors) (m1:avalue anchors { avalue_composable m0 m1 } ) : avalue anchors = let p0, v0 = m0 in let p1, v1 = m1 in let p12 = compose_permissions p0 p1 in let v12 = p_op _ v0 v1 in p12, v12 //////////////////////////////////////////////////////////////////////////////// (** avalue composition is associative and commutative **) let compose_avalue_comm (#v:Type) (#p:preorder v) (#anc:anchor_rel p) (m0: avalue anc) (m1: avalue anc{ avalue_composable m0 m1 }) : Lemma (compose_avalue m0 m1 == compose_avalue m1 m0) = () let avalue_composable_assoc_l (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (m0: avalue anchors) (m1: avalue anchors) (m2: avalue anchors { avalue_composable m1 m2 /\ avalue_composable m0 (compose_avalue m1 m2) }) : Lemma (avalue_composable m0 m1 /\ avalue_composable (compose_avalue m0 m1) m2) = () let compose_avalue_assoc_l (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m0: avalue s) (m1: avalue s) (m2: avalue s { avalue_composable m1 m2 /\ avalue_composable m0 (compose_avalue m1 m2) }) : Lemma (avalue_composable m0 m1 /\ avalue_composable (compose_avalue m0 m1) m2 /\ compose_avalue m0 (compose_avalue m1 m2) == compose_avalue (compose_avalue m0 m1) m2) = avalue_composable_assoc_l m0 m1 m2 let avalue_composable_assoc_r (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (m0: avalue anchors) (m1: avalue anchors) (m2: avalue anchors { avalue_composable m0 m1 /\ avalue_composable (compose_avalue m0 m1) m2 }) : Lemma (avalue_composable m1 m2 /\ avalue_composable m0 (compose_avalue m1 m2)) = () let compose_avalue_assoc_r (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m0: avalue s) (m1: avalue s) (m2: avalue s{ avalue_composable m0 m1 /\ avalue_composable (compose_avalue m0 m1) m2 }) : Lemma (avalue_composable m1 m2 /\ avalue_composable m0 (compose_avalue m1 m2) /\ compose_avalue m0 (compose_avalue m1 m2) == compose_avalue (compose_avalue m0 m1) m2) = avalue_composable_assoc_r m0 m1 m2 //////////////////////////////////////////////////////////////////////////////// /// lifting avalue composition to knowledge, including unit let compose (#v:Type) (#p:preorder v) (#s:anchor_rel p) (k0:knowledge s) (k1:knowledge s{ composable k0 k1 }) : knowledge s = match k0, k1 with | Nothing, k | k, Nothing -> k | Owns m, Owns m' -> Owns (compose_avalue m m') let composable_assoc_r #v (#p:preorder v) (#s:anchor_rel p) (k0 k1 k2: knowledge s) : Lemma (requires composable k0 k1 /\ composable (compose k0 k1) k2) (ensures composable k1 k2 /\ composable k0 (compose k1 k2) /\ compose k0 (compose k1 k2) == compose (compose k0 k1) k2 ) = match k0, k1, k2 with | Nothing, _, _ | _, Nothing, _ | _, _, Nothing -> () | Owns m0, Owns m1, Owns m2 -> compose_avalue_assoc_r m0 m1 m2 let composable_assoc_l #v (#p:preorder v) (#s:anchor_rel p) (k0 k1 k2: knowledge s) : Lemma (requires composable k1 k2 /\ composable k0 (compose k1 k2)) (ensures composable k0 k1 /\ composable (compose k0 k1) k2 /\ compose k0 (compose k1 k2) == compose (compose k0 k1) k2) = match k0, k1, k2 with | Nothing, _, _ | _, Nothing, _ | _, _, Nothing -> () | Owns m0, Owns m1, Owns m2 -> compose_avalue_assoc_l m0 m1 m2 /// Now, we can define our PCM /// The core of the PCM let p0 #v #p #s : pcm' (knowledge #v #p s) = { composable; op=compose; one=Nothing } let avalue_perm (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) = fst m /// A avalue represents full ownership when the fraction is full AND /// the anchor is set. This means that no knowledge held by any other /// thread can constrain this value meaningfully. let avalue_owns (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) : prop = fst (avalue_perm m) == Some full_perm /\ Some? (snd (avalue_perm m)) let full_knowledge #v #p #s (kn:knowledge #v #p s) : prop = match kn with | Nothing -> False | Owns km -> avalue_owns km /// The PCM itself, together with proofs of its properties let pcm #v #p #s : pcm (knowledge #v #p s) = { p = p0; comm = (fun k0 k1 -> match k0, k1 with | Nothing, _ | _, Nothing -> () | Owns m0, Owns m1 -> compose_avalue_comm m0 m1); assoc = (fun k0 k1 k2 -> composable_assoc_l k0 k1 k2); assoc_r = (fun k0 k1 k2 -> composable_assoc_r k0 k1 k2); is_unit = (fun _ -> ()); refine = full_knowledge; } /// Some utilities: The value of an avalue let avalue_val (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue #v #p s) = snd m /// Updating the value, in a full-ownership situation, also involves /// updating the anchor let avalue_update (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) (value:vhist p { s (curval value) (curval value) }) : avalue s = let p, _ = avalue_perm m in let p' = p, Some (curval value) in (p', value) /// Our core frame-preserving update: /// /// If you fully own a value, you can update it so long as you /// respect the preorder, and prove that the new value is related /// to itself by the anchor (since we'll be setting the anchor to /// the new value) /// /// This is a building block: we'll define a derived version that /// on values rather than histories #push-options "--z3rlimit_factor 2" let update_hist (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) (v1:vhist p { avalue_owns m /\ v1 `extends` avalue_val m /\ s (curval v1) (curval v1) }) : frame_preserving_upd pcm (Owns m) (Owns (avalue_update m v1)) = fun full_v -> let Owns full_m = full_v in let m_res = avalue_update full_m v1 in Owns m_res #pop-options /// Updating with value, rather than a history let avalue_update_value (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) (value:v { curval (avalue_val m) `p` value /\ s value value }) : m':avalue s { curval (avalue_val m') == value /\ avalue_val m' `extends` avalue_val m } = let v = avalue_val m in avalue_update m (extend_history v value) /// A derived frame-preserving update for which one presents only a value let update_value (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) (v1:v { avalue_owns m /\ //if you have full ownership of key curval (avalue_val m) `p` v1 /\ //you can update it wrt the preorder only s v1 v1 //and it is related to itself by the anchor }) : frame_preserving_upd pcm (Owns m) (Owns (avalue_update_value m v1)) = coerce_eq () (update_hist m (extend_history (avalue_val m) v1)) //F* goes nuts and starts swallowing gobs of memory without the coerce_eq: TODO, debug /// Now for anchored updates /// Ownership of the whole fraction, but not the anchor let avalue_owns_anchored (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) = fst (avalue_perm m) == Some full_perm /\ None? (snd (avalue_perm m))
{ "checked_file": "/", "dependencies": [ "Steel.Preorder.fst.checked", "Steel.FractionalPermission.fst.checked", "prims.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked" ], "interface_file": false, "source_file": "Steel.FractionalAnchoredPreorder.fst" }
[ { "abbrev": false, "full_module": "Steel.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Steel.Preorder", "short_module": null }, { "abbrev": false, "full_module": "FStar.Preorder", "short_module": null }, { "abbrev": false, "full_module": "FStar.PCM", "short_module": null }, { "abbrev": false, "full_module": "Steel", "short_module": null }, { "abbrev": false, "full_module": "Steel", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
v1: v -> v0: Steel.FractionalAnchoredPreorder.avalue anchors -> Prims.logical
Prims.Tot
[ "total" ]
[]
[ "FStar.Preorder.preorder", "Steel.FractionalAnchoredPreorder.anchor_rel", "Steel.FractionalAnchoredPreorder.avalue", "Prims.l_Forall", "Prims.l_imp", "Steel.Preorder.curval", "Steel.FractionalAnchoredPreorder.avalue_val", "Prims.logical" ]
[]
false
false
false
false
true
let compat_with_any_anchor_of (#v: Type) (#p: preorder v) (#anchors: anchor_rel p) (v1: v) (v0: avalue anchors) =
forall (anchor: v). anchor `anchors` (curval (avalue_val v0)) ==> anchor `anchors` v1
false
Steel.FractionalAnchoredPreorder.fst
Steel.FractionalAnchoredPreorder.full_knowledge
val full_knowledge (#v #p #s: _) (kn: knowledge #v #p s) : prop
val full_knowledge (#v #p #s: _) (kn: knowledge #v #p s) : prop
let full_knowledge #v #p #s (kn:knowledge #v #p s) : prop = match kn with | Nothing -> False | Owns km -> avalue_owns km
{ "file_name": "lib/steel/Steel.FractionalAnchoredPreorder.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 31, "end_line": 396, "start_col": 0, "start_line": 392 }
(* Copyright 2021 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. Author: N. Swamy *) module Steel.FractionalAnchoredPreorder (** This module provides a partial commutative monoid (PCM) for use in the ghost state of a concurrent Steel program. Its goal is to facilitate a form of information-sharing between multiple threads including the following features: Fractions, Preorders, Snapshots, and Anchors --- Anchors are the most unusual. 1. Fractions: Ownership of the state is controlled by a fractional permission, so multiple threads may share read-only privileges on the state, but only one can have write permission. 2. Preorders: The ghost state is governed by a preorder p and all updates to the state must respect the preorder (a reflexive, transitive relation on the state) 3. Snapshots: Since the state always evolves by a preorder, it is possible to take a snapshot of the state. A snapshot does not confer any particular ownership on the state, except knowledge of a snapshot ensures that the current state is related to the snapshot by the preorder. 4. Anchors are a kind of refinement of the preorder. If a thread owns an anchored value [v], then no other thread, even a thread owning a full fractional permission, can advance the state "too far" from the anchor. In particular, the PCM is parameterized by a binary relation on values, [anchors:anchor_relation]. If a thread owns the anchor [v], then the current value `cur` of the state must be in relation [v `anchors` cur]. This can be used to ensure that the knowledge of one thread is never becomes too stale. For example, this allows one to model a shared monotonically increasing counter, where if one thread anchors knowledge of the counter at the value 5, no other thread can increase the value of the counter beyond, say, 10, (when the anchor relation is y - x <= 5), until the anchoring thread releases the anchor. Further, at any point, a thread can take a snapshot of the counter and rely on the fact that the value of the counter in the future will be >= the snapshot. *) open FStar.PCM open FStar.Preorder open Steel.Preorder open Steel.FractionalPermission #push-options "--fuel 0 --ifuel 2" /// A permission: is a pair of /// /// * an optional fractional permission; with `Some p` indicating /// some ownership, while `None` is an additional "0" permission /// value, to encode snapshots. /// /// * and an optional anchor, where `Some a` indicates the current /// value can't be too far from `a`. let permission (v:Type) = option perm & option v /// Non-zero permission is either a read or write permission let has_nonzero #v (p:permission v) = Some? (fst p) /// Has an anchor set let has_anchor #v (p:permission v) = Some? (snd p) /// Either an anchor or non-zero let has_some_ownership #v (p:permission v) = has_nonzero p || has_anchor p /// The anchoring value let anchor_of #v (p:permission v { has_anchor p }) : v = Some?.v (snd p) /// The anchoring relation: /// -- A binary relation on values /// -- refining the preorder /// -- and if x `anchors` z then it also anchors any `y` between `x` and `z` /// /// Explaining the third clause a bit: /// Think intuitively of anchoring relations as a kind of distance measure /// /// if `z` is close enough to `x` then if `z` is further than `y` /// (since it is ahead of `y` in the preorder) then `y` is also /// close enough to `x` let anchor_rel (#v:Type) (p:preorder v) = anchors:(v -> v -> prop) { (forall v0 v1. anchors v0 v1 ==> p v0 v1) /\ (forall x z. x `anchors` z ==> (forall y. p x y /\ p y z ==> x `anchors` y)) // } /// An implementation remark: We use Steel.Preorder here to /// generically transform any preorder into a PCM. That works by /// taking the value of the PCM to be a history of values related by /// the preorder. So, throughout, we'll be using the the [vhist p] /// from Steel.Preorder, the type of a non-empty history compatible /// with [p]. The details of the histories don't matter much for our /// purposes---we only care about the most recent value, for which /// we'll use [curval v]. /// If the anchor is set, then the current value is anchored by it let anchored (#v:Type) (#p:preorder v) (anchors:anchor_rel p) (pv:(permission v & vhist p)) = has_anchor (fst pv) ==> anchor_of (fst pv) `anchors` curval (snd pv) /// A value in our fractional anchored PCM is a pair of a permission /// and a p-compatible history, refined to ensure that if the anchor /// is set, then the current value is anchored by it. let avalue (#v:Type) (#p:preorder v) (anchors:anchor_rel p) = pv:(permission v & vhist p) { anchored anchors pv } /// initial_value: A utility to construct a value in the PCM #push-options "--fuel 1" let initial_value (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (value:v { anchors value value }) : avalue anchors = (Some full_perm, Some value), [value] #pop-options /// We add a unit element to [avalue], as needed for a PCM [@@erasable] noeq type knowledge (#v:Type) (#p:preorder v) (anchors:anchor_rel p) = | Owns : avalue anchors -> knowledge anchors | Nothing : knowledge anchors let b2p (b:bool) : prop = b == true /// Fractional permissions are composable when their sum <= 1.0 let perm_opt_composable (p0 p1:option perm) : prop = match p0, p1 with | None, None -> True | Some p, None | None, Some p -> b2p (p `lesser_equal_perm` full_perm) | Some p0, Some p1 -> b2p (sum_perm p0 p1 `lesser_equal_perm` full_perm) /// Composing them sums the permissions let compose_perm_opt (p0 p1:option perm) = match p0, p1 with | None, p | p, None -> p | Some p0, Some p1 -> Some (sum_perm p0 p1) /// Anchored permissions are composable when at most one of them has the anchor set let permission_composable #v (p0 p1 : permission v) : prop = let q0, s0 = p0 in let q1, s1 = p1 in perm_opt_composable q0 q1 /\ // some of fracs can't exceed 1 not (Some? s0 && Some? s1) // at most one can have an anchor /// Compose permissions component wise, keeping the anchor if set let compose_permissions (#v:_) (p0:permission v) (p1:permission v{permission_composable p0 p1}) : permission v = compose_perm_opt (fst p0) (fst p1), (match snd p0, snd p1 with | None, a | a, None -> a) /// This is the central definition of the PCM --- defining when two /// values are composable, or equivalently, when one thread's /// knowledge of [av0] is compatible with another thread's knowledge /// of [av1] /// /// This definition shows the interplay between fractions and anchors. /// It wasn't obvious to me how to factor this further, e.g., adding /// anchors to preorders and then separately adding fractions to it. let avalue_composable (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (av0 av1: avalue anchors) : prop = let (p0, v0) = av0 in let (p1, v1) = av1 in permission_composable p0 p1 /\ (if not (has_some_ownership p0) && not (has_some_ownership p1) then p_composable _ v0 v1 //neither has ownership, one history is older than the other else if not (has_some_ownership p0) && has_some_ownership p1 then ( if has_nonzero p1 then v1 `extends` v0 //the one with ownership is more recent else ( //this part is the most subtle assert (has_anchor p1); p_composable _ v0 v1 /\ (v0 `extends` v1 ==> //if v0 is a more recent snapshot than v1 //then v0 must still be anchored by v1's anchor anchor_of p1 `anchors` curval v0) ) ) else if has_some_ownership p0 && not (has_some_ownership p1) then ( //symmetric if has_nonzero p0 then v0 `extends` v1 else ( assert (has_anchor p0); p_composable _ v0 v1 /\ (v1 `extends` v0 ==> anchor_of p0 `anchors` curval v1) ) ) else ( assert (has_some_ownership p0 && has_some_ownership p1); if has_nonzero p0 && has_nonzero p1 then v0 == v1 //if both have non-zero perm, then they must both only have read permission and must agree on the value else if has_nonzero p0 && has_anchor p1 then ( assert (not (has_nonzero p1)); //The key part of the anchor semantics: v0 `extends` v1 /\ //v0 has advanceable ownership, so extends anchor_of p1 `anchors` curval v0 //but not beyond what is allowed by s ) else if has_anchor p0 && has_nonzero p1 //symmetric then ( assert (not (has_nonzero p0)); v1 `extends` v0 /\ anchor_of p0 `anchors` curval v1 //v1 extends, but not beyond what is allowed by s ) else (assert false; False) ) ) //exhaustive /// Lifting avalue comosability to knowledge, including the unit let composable #v (#p:preorder v) (#a:anchor_rel p) : symrel (knowledge a) = fun (k0 k1:knowledge a) -> match k0, k1 with | Nothing, _ | _, Nothing -> True | Owns m, Owns m' -> avalue_composable m m' /// Compose avalues by composing permissions and composing the values /// using the underlying preorder PCM let compose_avalue (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (m0:avalue anchors) (m1:avalue anchors { avalue_composable m0 m1 } ) : avalue anchors = let p0, v0 = m0 in let p1, v1 = m1 in let p12 = compose_permissions p0 p1 in let v12 = p_op _ v0 v1 in p12, v12 //////////////////////////////////////////////////////////////////////////////// (** avalue composition is associative and commutative **) let compose_avalue_comm (#v:Type) (#p:preorder v) (#anc:anchor_rel p) (m0: avalue anc) (m1: avalue anc{ avalue_composable m0 m1 }) : Lemma (compose_avalue m0 m1 == compose_avalue m1 m0) = () let avalue_composable_assoc_l (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (m0: avalue anchors) (m1: avalue anchors) (m2: avalue anchors { avalue_composable m1 m2 /\ avalue_composable m0 (compose_avalue m1 m2) }) : Lemma (avalue_composable m0 m1 /\ avalue_composable (compose_avalue m0 m1) m2) = () let compose_avalue_assoc_l (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m0: avalue s) (m1: avalue s) (m2: avalue s { avalue_composable m1 m2 /\ avalue_composable m0 (compose_avalue m1 m2) }) : Lemma (avalue_composable m0 m1 /\ avalue_composable (compose_avalue m0 m1) m2 /\ compose_avalue m0 (compose_avalue m1 m2) == compose_avalue (compose_avalue m0 m1) m2) = avalue_composable_assoc_l m0 m1 m2 let avalue_composable_assoc_r (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (m0: avalue anchors) (m1: avalue anchors) (m2: avalue anchors { avalue_composable m0 m1 /\ avalue_composable (compose_avalue m0 m1) m2 }) : Lemma (avalue_composable m1 m2 /\ avalue_composable m0 (compose_avalue m1 m2)) = () let compose_avalue_assoc_r (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m0: avalue s) (m1: avalue s) (m2: avalue s{ avalue_composable m0 m1 /\ avalue_composable (compose_avalue m0 m1) m2 }) : Lemma (avalue_composable m1 m2 /\ avalue_composable m0 (compose_avalue m1 m2) /\ compose_avalue m0 (compose_avalue m1 m2) == compose_avalue (compose_avalue m0 m1) m2) = avalue_composable_assoc_r m0 m1 m2 //////////////////////////////////////////////////////////////////////////////// /// lifting avalue composition to knowledge, including unit let compose (#v:Type) (#p:preorder v) (#s:anchor_rel p) (k0:knowledge s) (k1:knowledge s{ composable k0 k1 }) : knowledge s = match k0, k1 with | Nothing, k | k, Nothing -> k | Owns m, Owns m' -> Owns (compose_avalue m m') let composable_assoc_r #v (#p:preorder v) (#s:anchor_rel p) (k0 k1 k2: knowledge s) : Lemma (requires composable k0 k1 /\ composable (compose k0 k1) k2) (ensures composable k1 k2 /\ composable k0 (compose k1 k2) /\ compose k0 (compose k1 k2) == compose (compose k0 k1) k2 ) = match k0, k1, k2 with | Nothing, _, _ | _, Nothing, _ | _, _, Nothing -> () | Owns m0, Owns m1, Owns m2 -> compose_avalue_assoc_r m0 m1 m2 let composable_assoc_l #v (#p:preorder v) (#s:anchor_rel p) (k0 k1 k2: knowledge s) : Lemma (requires composable k1 k2 /\ composable k0 (compose k1 k2)) (ensures composable k0 k1 /\ composable (compose k0 k1) k2 /\ compose k0 (compose k1 k2) == compose (compose k0 k1) k2) = match k0, k1, k2 with | Nothing, _, _ | _, Nothing, _ | _, _, Nothing -> () | Owns m0, Owns m1, Owns m2 -> compose_avalue_assoc_l m0 m1 m2 /// Now, we can define our PCM /// The core of the PCM let p0 #v #p #s : pcm' (knowledge #v #p s) = { composable; op=compose; one=Nothing } let avalue_perm (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) = fst m /// A avalue represents full ownership when the fraction is full AND /// the anchor is set. This means that no knowledge held by any other /// thread can constrain this value meaningfully. let avalue_owns (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) : prop = fst (avalue_perm m) == Some full_perm /\ Some? (snd (avalue_perm m))
{ "checked_file": "/", "dependencies": [ "Steel.Preorder.fst.checked", "Steel.FractionalPermission.fst.checked", "prims.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked" ], "interface_file": false, "source_file": "Steel.FractionalAnchoredPreorder.fst" }
[ { "abbrev": false, "full_module": "Steel.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Steel.Preorder", "short_module": null }, { "abbrev": false, "full_module": "FStar.Preorder", "short_module": null }, { "abbrev": false, "full_module": "FStar.PCM", "short_module": null }, { "abbrev": false, "full_module": "Steel", "short_module": null }, { "abbrev": false, "full_module": "Steel", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
kn: Steel.FractionalAnchoredPreorder.knowledge s -> Prims.prop
Prims.Tot
[ "total" ]
[]
[ "FStar.Preorder.preorder", "Steel.FractionalAnchoredPreorder.anchor_rel", "Steel.FractionalAnchoredPreorder.knowledge", "Prims.l_False", "Steel.FractionalAnchoredPreorder.avalue", "Steel.FractionalAnchoredPreorder.avalue_owns", "Prims.prop" ]
[]
false
false
false
false
true
let full_knowledge #v #p #s (kn: knowledge #v #p s) : prop =
match kn with | Nothing -> False | Owns km -> avalue_owns km
false
Steel.FractionalAnchoredPreorder.fst
Steel.FractionalAnchoredPreorder.avalue_composable
val avalue_composable (#v: Type) (#p: preorder v) (#anchors: anchor_rel p) (av0 av1: avalue anchors) : prop
val avalue_composable (#v: Type) (#p: preorder v) (#anchors: anchor_rel p) (av0 av1: avalue anchors) : prop
let avalue_composable (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (av0 av1: avalue anchors) : prop = let (p0, v0) = av0 in let (p1, v1) = av1 in permission_composable p0 p1 /\ (if not (has_some_ownership p0) && not (has_some_ownership p1) then p_composable _ v0 v1 //neither has ownership, one history is older than the other else if not (has_some_ownership p0) && has_some_ownership p1 then ( if has_nonzero p1 then v1 `extends` v0 //the one with ownership is more recent else ( //this part is the most subtle assert (has_anchor p1); p_composable _ v0 v1 /\ (v0 `extends` v1 ==> //if v0 is a more recent snapshot than v1 //then v0 must still be anchored by v1's anchor anchor_of p1 `anchors` curval v0) ) ) else if has_some_ownership p0 && not (has_some_ownership p1) then ( //symmetric if has_nonzero p0 then v0 `extends` v1 else ( assert (has_anchor p0); p_composable _ v0 v1 /\ (v1 `extends` v0 ==> anchor_of p0 `anchors` curval v1) ) ) else ( assert (has_some_ownership p0 && has_some_ownership p1); if has_nonzero p0 && has_nonzero p1 then v0 == v1 //if both have non-zero perm, then they must both only have read permission and must agree on the value else if has_nonzero p0 && has_anchor p1 then ( assert (not (has_nonzero p1)); //The key part of the anchor semantics: v0 `extends` v1 /\ //v0 has advanceable ownership, so extends anchor_of p1 `anchors` curval v0 //but not beyond what is allowed by s ) else if has_anchor p0 && has_nonzero p1 //symmetric then ( assert (not (has_nonzero p0)); v1 `extends` v0 /\ anchor_of p0 `anchors` curval v1 //v1 extends, but not beyond what is allowed by s ) else (assert false; False) ) )
{ "file_name": "lib/steel/Steel.FractionalAnchoredPreorder.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 5, "end_line": 232, "start_col": 0, "start_line": 182 }
(* Copyright 2021 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. Author: N. Swamy *) module Steel.FractionalAnchoredPreorder (** This module provides a partial commutative monoid (PCM) for use in the ghost state of a concurrent Steel program. Its goal is to facilitate a form of information-sharing between multiple threads including the following features: Fractions, Preorders, Snapshots, and Anchors --- Anchors are the most unusual. 1. Fractions: Ownership of the state is controlled by a fractional permission, so multiple threads may share read-only privileges on the state, but only one can have write permission. 2. Preorders: The ghost state is governed by a preorder p and all updates to the state must respect the preorder (a reflexive, transitive relation on the state) 3. Snapshots: Since the state always evolves by a preorder, it is possible to take a snapshot of the state. A snapshot does not confer any particular ownership on the state, except knowledge of a snapshot ensures that the current state is related to the snapshot by the preorder. 4. Anchors are a kind of refinement of the preorder. If a thread owns an anchored value [v], then no other thread, even a thread owning a full fractional permission, can advance the state "too far" from the anchor. In particular, the PCM is parameterized by a binary relation on values, [anchors:anchor_relation]. If a thread owns the anchor [v], then the current value `cur` of the state must be in relation [v `anchors` cur]. This can be used to ensure that the knowledge of one thread is never becomes too stale. For example, this allows one to model a shared monotonically increasing counter, where if one thread anchors knowledge of the counter at the value 5, no other thread can increase the value of the counter beyond, say, 10, (when the anchor relation is y - x <= 5), until the anchoring thread releases the anchor. Further, at any point, a thread can take a snapshot of the counter and rely on the fact that the value of the counter in the future will be >= the snapshot. *) open FStar.PCM open FStar.Preorder open Steel.Preorder open Steel.FractionalPermission #push-options "--fuel 0 --ifuel 2" /// A permission: is a pair of /// /// * an optional fractional permission; with `Some p` indicating /// some ownership, while `None` is an additional "0" permission /// value, to encode snapshots. /// /// * and an optional anchor, where `Some a` indicates the current /// value can't be too far from `a`. let permission (v:Type) = option perm & option v /// Non-zero permission is either a read or write permission let has_nonzero #v (p:permission v) = Some? (fst p) /// Has an anchor set let has_anchor #v (p:permission v) = Some? (snd p) /// Either an anchor or non-zero let has_some_ownership #v (p:permission v) = has_nonzero p || has_anchor p /// The anchoring value let anchor_of #v (p:permission v { has_anchor p }) : v = Some?.v (snd p) /// The anchoring relation: /// -- A binary relation on values /// -- refining the preorder /// -- and if x `anchors` z then it also anchors any `y` between `x` and `z` /// /// Explaining the third clause a bit: /// Think intuitively of anchoring relations as a kind of distance measure /// /// if `z` is close enough to `x` then if `z` is further than `y` /// (since it is ahead of `y` in the preorder) then `y` is also /// close enough to `x` let anchor_rel (#v:Type) (p:preorder v) = anchors:(v -> v -> prop) { (forall v0 v1. anchors v0 v1 ==> p v0 v1) /\ (forall x z. x `anchors` z ==> (forall y. p x y /\ p y z ==> x `anchors` y)) // } /// An implementation remark: We use Steel.Preorder here to /// generically transform any preorder into a PCM. That works by /// taking the value of the PCM to be a history of values related by /// the preorder. So, throughout, we'll be using the the [vhist p] /// from Steel.Preorder, the type of a non-empty history compatible /// with [p]. The details of the histories don't matter much for our /// purposes---we only care about the most recent value, for which /// we'll use [curval v]. /// If the anchor is set, then the current value is anchored by it let anchored (#v:Type) (#p:preorder v) (anchors:anchor_rel p) (pv:(permission v & vhist p)) = has_anchor (fst pv) ==> anchor_of (fst pv) `anchors` curval (snd pv) /// A value in our fractional anchored PCM is a pair of a permission /// and a p-compatible history, refined to ensure that if the anchor /// is set, then the current value is anchored by it. let avalue (#v:Type) (#p:preorder v) (anchors:anchor_rel p) = pv:(permission v & vhist p) { anchored anchors pv } /// initial_value: A utility to construct a value in the PCM #push-options "--fuel 1" let initial_value (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (value:v { anchors value value }) : avalue anchors = (Some full_perm, Some value), [value] #pop-options /// We add a unit element to [avalue], as needed for a PCM [@@erasable] noeq type knowledge (#v:Type) (#p:preorder v) (anchors:anchor_rel p) = | Owns : avalue anchors -> knowledge anchors | Nothing : knowledge anchors let b2p (b:bool) : prop = b == true /// Fractional permissions are composable when their sum <= 1.0 let perm_opt_composable (p0 p1:option perm) : prop = match p0, p1 with | None, None -> True | Some p, None | None, Some p -> b2p (p `lesser_equal_perm` full_perm) | Some p0, Some p1 -> b2p (sum_perm p0 p1 `lesser_equal_perm` full_perm) /// Composing them sums the permissions let compose_perm_opt (p0 p1:option perm) = match p0, p1 with | None, p | p, None -> p | Some p0, Some p1 -> Some (sum_perm p0 p1) /// Anchored permissions are composable when at most one of them has the anchor set let permission_composable #v (p0 p1 : permission v) : prop = let q0, s0 = p0 in let q1, s1 = p1 in perm_opt_composable q0 q1 /\ // some of fracs can't exceed 1 not (Some? s0 && Some? s1) // at most one can have an anchor /// Compose permissions component wise, keeping the anchor if set let compose_permissions (#v:_) (p0:permission v) (p1:permission v{permission_composable p0 p1}) : permission v = compose_perm_opt (fst p0) (fst p1), (match snd p0, snd p1 with | None, a | a, None -> a) /// This is the central definition of the PCM --- defining when two /// values are composable, or equivalently, when one thread's /// knowledge of [av0] is compatible with another thread's knowledge /// of [av1] /// /// This definition shows the interplay between fractions and anchors. /// It wasn't obvious to me how to factor this further, e.g., adding
{ "checked_file": "/", "dependencies": [ "Steel.Preorder.fst.checked", "Steel.FractionalPermission.fst.checked", "prims.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked" ], "interface_file": false, "source_file": "Steel.FractionalAnchoredPreorder.fst" }
[ { "abbrev": false, "full_module": "Steel.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Steel.Preorder", "short_module": null }, { "abbrev": false, "full_module": "FStar.Preorder", "short_module": null }, { "abbrev": false, "full_module": "FStar.PCM", "short_module": null }, { "abbrev": false, "full_module": "Steel", "short_module": null }, { "abbrev": false, "full_module": "Steel", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
av0: Steel.FractionalAnchoredPreorder.avalue anchors -> av1: Steel.FractionalAnchoredPreorder.avalue anchors -> Prims.prop
Prims.Tot
[ "total" ]
[]
[ "FStar.Preorder.preorder", "Steel.FractionalAnchoredPreorder.anchor_rel", "Steel.FractionalAnchoredPreorder.avalue", "Steel.FractionalAnchoredPreorder.permission", "Steel.Preorder.vhist", "Prims.l_and", "Steel.FractionalAnchoredPreorder.permission_composable", "Prims.op_AmpAmp", "Prims.op_Negation", "Steel.FractionalAnchoredPreorder.has_some_ownership", "Steel.Preorder.p_composable", "Prims.bool", "Steel.FractionalAnchoredPreorder.has_nonzero", "Steel.Preorder.extends", "Prims.l_imp", "Steel.FractionalAnchoredPreorder.anchor_of", "Steel.Preorder.curval", "Prims.unit", "Prims._assert", "Prims.b2t", "Steel.FractionalAnchoredPreorder.has_anchor", "Prims.logical", "Prims.eq2", "Prims.l_False", "Prims.prop" ]
[]
false
false
false
false
true
let avalue_composable (#v: Type) (#p: preorder v) (#anchors: anchor_rel p) (av0 av1: avalue anchors) : prop =
let p0, v0 = av0 in let p1, v1 = av1 in permission_composable p0 p1 /\ (if not (has_some_ownership p0) && not (has_some_ownership p1) then p_composable _ v0 v1 else if not (has_some_ownership p0) && has_some_ownership p1 then (if has_nonzero p1 then v1 `extends` v0 else (assert (has_anchor p1); p_composable _ v0 v1 /\ (v0 `extends` v1 ==> (anchor_of p1) `anchors` (curval v0)))) else if has_some_ownership p0 && not (has_some_ownership p1) then (if has_nonzero p0 then v0 `extends` v1 else (assert (has_anchor p0); p_composable _ v0 v1 /\ (v1 `extends` v0 ==> (anchor_of p0) `anchors` (curval v1)))) else (assert (has_some_ownership p0 && has_some_ownership p1); if has_nonzero p0 && has_nonzero p1 then v0 == v1 else if has_nonzero p0 && has_anchor p1 then (assert (not (has_nonzero p1)); v0 `extends` v1 /\ (anchor_of p1) `anchors` (curval v0)) else if has_anchor p0 && has_nonzero p1 then (assert (not (has_nonzero p0)); v1 `extends` v0 /\ (anchor_of p0) `anchors` (curval v1)) else (assert false; False)))
false
Steel.FractionalAnchoredPreorder.fst
Steel.FractionalAnchoredPreorder.composable_assoc_r
val composable_assoc_r (#v: _) (#p: preorder v) (#s: anchor_rel p) (k0 k1 k2: knowledge s) : Lemma (requires composable k0 k1 /\ composable (compose k0 k1) k2) (ensures composable k1 k2 /\ composable k0 (compose k1 k2) /\ compose k0 (compose k1 k2) == compose (compose k0 k1) k2)
val composable_assoc_r (#v: _) (#p: preorder v) (#s: anchor_rel p) (k0 k1 k2: knowledge s) : Lemma (requires composable k0 k1 /\ composable (compose k0 k1) k2) (ensures composable k1 k2 /\ composable k0 (compose k1 k2) /\ compose k0 (compose k1 k2) == compose (compose k0 k1) k2)
let composable_assoc_r #v (#p:preorder v) (#s:anchor_rel p) (k0 k1 k2: knowledge s) : Lemma (requires composable k0 k1 /\ composable (compose k0 k1) k2) (ensures composable k1 k2 /\ composable k0 (compose k1 k2) /\ compose k0 (compose k1 k2) == compose (compose k0 k1) k2 ) = match k0, k1, k2 with | Nothing, _, _ | _, Nothing, _ | _, _, Nothing -> () | Owns m0, Owns m1, Owns m2 -> compose_avalue_assoc_r m0 m1 m2
{ "file_name": "lib/steel/Steel.FractionalAnchoredPreorder.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 37, "end_line": 346, "start_col": 0, "start_line": 330 }
(* Copyright 2021 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. Author: N. Swamy *) module Steel.FractionalAnchoredPreorder (** This module provides a partial commutative monoid (PCM) for use in the ghost state of a concurrent Steel program. Its goal is to facilitate a form of information-sharing between multiple threads including the following features: Fractions, Preorders, Snapshots, and Anchors --- Anchors are the most unusual. 1. Fractions: Ownership of the state is controlled by a fractional permission, so multiple threads may share read-only privileges on the state, but only one can have write permission. 2. Preorders: The ghost state is governed by a preorder p and all updates to the state must respect the preorder (a reflexive, transitive relation on the state) 3. Snapshots: Since the state always evolves by a preorder, it is possible to take a snapshot of the state. A snapshot does not confer any particular ownership on the state, except knowledge of a snapshot ensures that the current state is related to the snapshot by the preorder. 4. Anchors are a kind of refinement of the preorder. If a thread owns an anchored value [v], then no other thread, even a thread owning a full fractional permission, can advance the state "too far" from the anchor. In particular, the PCM is parameterized by a binary relation on values, [anchors:anchor_relation]. If a thread owns the anchor [v], then the current value `cur` of the state must be in relation [v `anchors` cur]. This can be used to ensure that the knowledge of one thread is never becomes too stale. For example, this allows one to model a shared monotonically increasing counter, where if one thread anchors knowledge of the counter at the value 5, no other thread can increase the value of the counter beyond, say, 10, (when the anchor relation is y - x <= 5), until the anchoring thread releases the anchor. Further, at any point, a thread can take a snapshot of the counter and rely on the fact that the value of the counter in the future will be >= the snapshot. *) open FStar.PCM open FStar.Preorder open Steel.Preorder open Steel.FractionalPermission #push-options "--fuel 0 --ifuel 2" /// A permission: is a pair of /// /// * an optional fractional permission; with `Some p` indicating /// some ownership, while `None` is an additional "0" permission /// value, to encode snapshots. /// /// * and an optional anchor, where `Some a` indicates the current /// value can't be too far from `a`. let permission (v:Type) = option perm & option v /// Non-zero permission is either a read or write permission let has_nonzero #v (p:permission v) = Some? (fst p) /// Has an anchor set let has_anchor #v (p:permission v) = Some? (snd p) /// Either an anchor or non-zero let has_some_ownership #v (p:permission v) = has_nonzero p || has_anchor p /// The anchoring value let anchor_of #v (p:permission v { has_anchor p }) : v = Some?.v (snd p) /// The anchoring relation: /// -- A binary relation on values /// -- refining the preorder /// -- and if x `anchors` z then it also anchors any `y` between `x` and `z` /// /// Explaining the third clause a bit: /// Think intuitively of anchoring relations as a kind of distance measure /// /// if `z` is close enough to `x` then if `z` is further than `y` /// (since it is ahead of `y` in the preorder) then `y` is also /// close enough to `x` let anchor_rel (#v:Type) (p:preorder v) = anchors:(v -> v -> prop) { (forall v0 v1. anchors v0 v1 ==> p v0 v1) /\ (forall x z. x `anchors` z ==> (forall y. p x y /\ p y z ==> x `anchors` y)) // } /// An implementation remark: We use Steel.Preorder here to /// generically transform any preorder into a PCM. That works by /// taking the value of the PCM to be a history of values related by /// the preorder. So, throughout, we'll be using the the [vhist p] /// from Steel.Preorder, the type of a non-empty history compatible /// with [p]. The details of the histories don't matter much for our /// purposes---we only care about the most recent value, for which /// we'll use [curval v]. /// If the anchor is set, then the current value is anchored by it let anchored (#v:Type) (#p:preorder v) (anchors:anchor_rel p) (pv:(permission v & vhist p)) = has_anchor (fst pv) ==> anchor_of (fst pv) `anchors` curval (snd pv) /// A value in our fractional anchored PCM is a pair of a permission /// and a p-compatible history, refined to ensure that if the anchor /// is set, then the current value is anchored by it. let avalue (#v:Type) (#p:preorder v) (anchors:anchor_rel p) = pv:(permission v & vhist p) { anchored anchors pv } /// initial_value: A utility to construct a value in the PCM #push-options "--fuel 1" let initial_value (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (value:v { anchors value value }) : avalue anchors = (Some full_perm, Some value), [value] #pop-options /// We add a unit element to [avalue], as needed for a PCM [@@erasable] noeq type knowledge (#v:Type) (#p:preorder v) (anchors:anchor_rel p) = | Owns : avalue anchors -> knowledge anchors | Nothing : knowledge anchors let b2p (b:bool) : prop = b == true /// Fractional permissions are composable when their sum <= 1.0 let perm_opt_composable (p0 p1:option perm) : prop = match p0, p1 with | None, None -> True | Some p, None | None, Some p -> b2p (p `lesser_equal_perm` full_perm) | Some p0, Some p1 -> b2p (sum_perm p0 p1 `lesser_equal_perm` full_perm) /// Composing them sums the permissions let compose_perm_opt (p0 p1:option perm) = match p0, p1 with | None, p | p, None -> p | Some p0, Some p1 -> Some (sum_perm p0 p1) /// Anchored permissions are composable when at most one of them has the anchor set let permission_composable #v (p0 p1 : permission v) : prop = let q0, s0 = p0 in let q1, s1 = p1 in perm_opt_composable q0 q1 /\ // some of fracs can't exceed 1 not (Some? s0 && Some? s1) // at most one can have an anchor /// Compose permissions component wise, keeping the anchor if set let compose_permissions (#v:_) (p0:permission v) (p1:permission v{permission_composable p0 p1}) : permission v = compose_perm_opt (fst p0) (fst p1), (match snd p0, snd p1 with | None, a | a, None -> a) /// This is the central definition of the PCM --- defining when two /// values are composable, or equivalently, when one thread's /// knowledge of [av0] is compatible with another thread's knowledge /// of [av1] /// /// This definition shows the interplay between fractions and anchors. /// It wasn't obvious to me how to factor this further, e.g., adding /// anchors to preorders and then separately adding fractions to it. let avalue_composable (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (av0 av1: avalue anchors) : prop = let (p0, v0) = av0 in let (p1, v1) = av1 in permission_composable p0 p1 /\ (if not (has_some_ownership p0) && not (has_some_ownership p1) then p_composable _ v0 v1 //neither has ownership, one history is older than the other else if not (has_some_ownership p0) && has_some_ownership p1 then ( if has_nonzero p1 then v1 `extends` v0 //the one with ownership is more recent else ( //this part is the most subtle assert (has_anchor p1); p_composable _ v0 v1 /\ (v0 `extends` v1 ==> //if v0 is a more recent snapshot than v1 //then v0 must still be anchored by v1's anchor anchor_of p1 `anchors` curval v0) ) ) else if has_some_ownership p0 && not (has_some_ownership p1) then ( //symmetric if has_nonzero p0 then v0 `extends` v1 else ( assert (has_anchor p0); p_composable _ v0 v1 /\ (v1 `extends` v0 ==> anchor_of p0 `anchors` curval v1) ) ) else ( assert (has_some_ownership p0 && has_some_ownership p1); if has_nonzero p0 && has_nonzero p1 then v0 == v1 //if both have non-zero perm, then they must both only have read permission and must agree on the value else if has_nonzero p0 && has_anchor p1 then ( assert (not (has_nonzero p1)); //The key part of the anchor semantics: v0 `extends` v1 /\ //v0 has advanceable ownership, so extends anchor_of p1 `anchors` curval v0 //but not beyond what is allowed by s ) else if has_anchor p0 && has_nonzero p1 //symmetric then ( assert (not (has_nonzero p0)); v1 `extends` v0 /\ anchor_of p0 `anchors` curval v1 //v1 extends, but not beyond what is allowed by s ) else (assert false; False) ) ) //exhaustive /// Lifting avalue comosability to knowledge, including the unit let composable #v (#p:preorder v) (#a:anchor_rel p) : symrel (knowledge a) = fun (k0 k1:knowledge a) -> match k0, k1 with | Nothing, _ | _, Nothing -> True | Owns m, Owns m' -> avalue_composable m m' /// Compose avalues by composing permissions and composing the values /// using the underlying preorder PCM let compose_avalue (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (m0:avalue anchors) (m1:avalue anchors { avalue_composable m0 m1 } ) : avalue anchors = let p0, v0 = m0 in let p1, v1 = m1 in let p12 = compose_permissions p0 p1 in let v12 = p_op _ v0 v1 in p12, v12 //////////////////////////////////////////////////////////////////////////////// (** avalue composition is associative and commutative **) let compose_avalue_comm (#v:Type) (#p:preorder v) (#anc:anchor_rel p) (m0: avalue anc) (m1: avalue anc{ avalue_composable m0 m1 }) : Lemma (compose_avalue m0 m1 == compose_avalue m1 m0) = () let avalue_composable_assoc_l (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (m0: avalue anchors) (m1: avalue anchors) (m2: avalue anchors { avalue_composable m1 m2 /\ avalue_composable m0 (compose_avalue m1 m2) }) : Lemma (avalue_composable m0 m1 /\ avalue_composable (compose_avalue m0 m1) m2) = () let compose_avalue_assoc_l (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m0: avalue s) (m1: avalue s) (m2: avalue s { avalue_composable m1 m2 /\ avalue_composable m0 (compose_avalue m1 m2) }) : Lemma (avalue_composable m0 m1 /\ avalue_composable (compose_avalue m0 m1) m2 /\ compose_avalue m0 (compose_avalue m1 m2) == compose_avalue (compose_avalue m0 m1) m2) = avalue_composable_assoc_l m0 m1 m2 let avalue_composable_assoc_r (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (m0: avalue anchors) (m1: avalue anchors) (m2: avalue anchors { avalue_composable m0 m1 /\ avalue_composable (compose_avalue m0 m1) m2 }) : Lemma (avalue_composable m1 m2 /\ avalue_composable m0 (compose_avalue m1 m2)) = () let compose_avalue_assoc_r (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m0: avalue s) (m1: avalue s) (m2: avalue s{ avalue_composable m0 m1 /\ avalue_composable (compose_avalue m0 m1) m2 }) : Lemma (avalue_composable m1 m2 /\ avalue_composable m0 (compose_avalue m1 m2) /\ compose_avalue m0 (compose_avalue m1 m2) == compose_avalue (compose_avalue m0 m1) m2) = avalue_composable_assoc_r m0 m1 m2 //////////////////////////////////////////////////////////////////////////////// /// lifting avalue composition to knowledge, including unit let compose (#v:Type) (#p:preorder v) (#s:anchor_rel p) (k0:knowledge s) (k1:knowledge s{ composable k0 k1 }) : knowledge s = match k0, k1 with | Nothing, k | k, Nothing -> k | Owns m, Owns m' -> Owns (compose_avalue m m')
{ "checked_file": "/", "dependencies": [ "Steel.Preorder.fst.checked", "Steel.FractionalPermission.fst.checked", "prims.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked" ], "interface_file": false, "source_file": "Steel.FractionalAnchoredPreorder.fst" }
[ { "abbrev": false, "full_module": "Steel.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Steel.Preorder", "short_module": null }, { "abbrev": false, "full_module": "FStar.Preorder", "short_module": null }, { "abbrev": false, "full_module": "FStar.PCM", "short_module": null }, { "abbrev": false, "full_module": "Steel", "short_module": null }, { "abbrev": false, "full_module": "Steel", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
k0: Steel.FractionalAnchoredPreorder.knowledge s -> k1: Steel.FractionalAnchoredPreorder.knowledge s -> k2: Steel.FractionalAnchoredPreorder.knowledge s -> FStar.Pervasives.Lemma (requires Steel.FractionalAnchoredPreorder.composable k0 k1 /\ Steel.FractionalAnchoredPreorder.composable (Steel.FractionalAnchoredPreorder.compose k0 k1) k2) (ensures Steel.FractionalAnchoredPreorder.composable k1 k2 /\ Steel.FractionalAnchoredPreorder.composable k0 (Steel.FractionalAnchoredPreorder.compose k1 k2) /\ Steel.FractionalAnchoredPreorder.compose k0 (Steel.FractionalAnchoredPreorder.compose k1 k2) == Steel.FractionalAnchoredPreorder.compose (Steel.FractionalAnchoredPreorder.compose k0 k1) k2 )
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "FStar.Preorder.preorder", "Steel.FractionalAnchoredPreorder.anchor_rel", "Steel.FractionalAnchoredPreorder.knowledge", "FStar.Pervasives.Native.Mktuple3", "Steel.FractionalAnchoredPreorder.avalue", "Steel.FractionalAnchoredPreorder.compose_avalue_assoc_r", "Prims.unit", "Prims.l_and", "Steel.FractionalAnchoredPreorder.composable", "Steel.FractionalAnchoredPreorder.compose", "Prims.squash", "Prims.eq2", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let composable_assoc_r #v (#p: preorder v) (#s: anchor_rel p) (k0: knowledge s) (k1: knowledge s) (k2: knowledge s) : Lemma (requires composable k0 k1 /\ composable (compose k0 k1) k2) (ensures composable k1 k2 /\ composable k0 (compose k1 k2) /\ compose k0 (compose k1 k2) == compose (compose k0 k1) k2) =
match k0, k1, k2 with | Nothing, _, _ | _, Nothing, _ | _, _, Nothing -> () | Owns m0, Owns m1, Owns m2 -> compose_avalue_assoc_r m0 m1 m2
false
Steel.FractionalAnchoredPreorder.fst
Steel.FractionalAnchoredPreorder.compose
val compose (#v: Type) (#p: preorder v) (#s: anchor_rel p) (k0: knowledge s) (k1: knowledge s {composable k0 k1}) : knowledge s
val compose (#v: Type) (#p: preorder v) (#s: anchor_rel p) (k0: knowledge s) (k1: knowledge s {composable k0 k1}) : knowledge s
let compose (#v:Type) (#p:preorder v) (#s:anchor_rel p) (k0:knowledge s) (k1:knowledge s{ composable k0 k1 }) : knowledge s = match k0, k1 with | Nothing, k | k, Nothing -> k | Owns m, Owns m' -> Owns (compose_avalue m m')
{ "file_name": "lib/steel/Steel.FractionalAnchoredPreorder.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 32, "end_line": 328, "start_col": 0, "start_line": 319 }
(* Copyright 2021 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. Author: N. Swamy *) module Steel.FractionalAnchoredPreorder (** This module provides a partial commutative monoid (PCM) for use in the ghost state of a concurrent Steel program. Its goal is to facilitate a form of information-sharing between multiple threads including the following features: Fractions, Preorders, Snapshots, and Anchors --- Anchors are the most unusual. 1. Fractions: Ownership of the state is controlled by a fractional permission, so multiple threads may share read-only privileges on the state, but only one can have write permission. 2. Preorders: The ghost state is governed by a preorder p and all updates to the state must respect the preorder (a reflexive, transitive relation on the state) 3. Snapshots: Since the state always evolves by a preorder, it is possible to take a snapshot of the state. A snapshot does not confer any particular ownership on the state, except knowledge of a snapshot ensures that the current state is related to the snapshot by the preorder. 4. Anchors are a kind of refinement of the preorder. If a thread owns an anchored value [v], then no other thread, even a thread owning a full fractional permission, can advance the state "too far" from the anchor. In particular, the PCM is parameterized by a binary relation on values, [anchors:anchor_relation]. If a thread owns the anchor [v], then the current value `cur` of the state must be in relation [v `anchors` cur]. This can be used to ensure that the knowledge of one thread is never becomes too stale. For example, this allows one to model a shared monotonically increasing counter, where if one thread anchors knowledge of the counter at the value 5, no other thread can increase the value of the counter beyond, say, 10, (when the anchor relation is y - x <= 5), until the anchoring thread releases the anchor. Further, at any point, a thread can take a snapshot of the counter and rely on the fact that the value of the counter in the future will be >= the snapshot. *) open FStar.PCM open FStar.Preorder open Steel.Preorder open Steel.FractionalPermission #push-options "--fuel 0 --ifuel 2" /// A permission: is a pair of /// /// * an optional fractional permission; with `Some p` indicating /// some ownership, while `None` is an additional "0" permission /// value, to encode snapshots. /// /// * and an optional anchor, where `Some a` indicates the current /// value can't be too far from `a`. let permission (v:Type) = option perm & option v /// Non-zero permission is either a read or write permission let has_nonzero #v (p:permission v) = Some? (fst p) /// Has an anchor set let has_anchor #v (p:permission v) = Some? (snd p) /// Either an anchor or non-zero let has_some_ownership #v (p:permission v) = has_nonzero p || has_anchor p /// The anchoring value let anchor_of #v (p:permission v { has_anchor p }) : v = Some?.v (snd p) /// The anchoring relation: /// -- A binary relation on values /// -- refining the preorder /// -- and if x `anchors` z then it also anchors any `y` between `x` and `z` /// /// Explaining the third clause a bit: /// Think intuitively of anchoring relations as a kind of distance measure /// /// if `z` is close enough to `x` then if `z` is further than `y` /// (since it is ahead of `y` in the preorder) then `y` is also /// close enough to `x` let anchor_rel (#v:Type) (p:preorder v) = anchors:(v -> v -> prop) { (forall v0 v1. anchors v0 v1 ==> p v0 v1) /\ (forall x z. x `anchors` z ==> (forall y. p x y /\ p y z ==> x `anchors` y)) // } /// An implementation remark: We use Steel.Preorder here to /// generically transform any preorder into a PCM. That works by /// taking the value of the PCM to be a history of values related by /// the preorder. So, throughout, we'll be using the the [vhist p] /// from Steel.Preorder, the type of a non-empty history compatible /// with [p]. The details of the histories don't matter much for our /// purposes---we only care about the most recent value, for which /// we'll use [curval v]. /// If the anchor is set, then the current value is anchored by it let anchored (#v:Type) (#p:preorder v) (anchors:anchor_rel p) (pv:(permission v & vhist p)) = has_anchor (fst pv) ==> anchor_of (fst pv) `anchors` curval (snd pv) /// A value in our fractional anchored PCM is a pair of a permission /// and a p-compatible history, refined to ensure that if the anchor /// is set, then the current value is anchored by it. let avalue (#v:Type) (#p:preorder v) (anchors:anchor_rel p) = pv:(permission v & vhist p) { anchored anchors pv } /// initial_value: A utility to construct a value in the PCM #push-options "--fuel 1" let initial_value (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (value:v { anchors value value }) : avalue anchors = (Some full_perm, Some value), [value] #pop-options /// We add a unit element to [avalue], as needed for a PCM [@@erasable] noeq type knowledge (#v:Type) (#p:preorder v) (anchors:anchor_rel p) = | Owns : avalue anchors -> knowledge anchors | Nothing : knowledge anchors let b2p (b:bool) : prop = b == true /// Fractional permissions are composable when their sum <= 1.0 let perm_opt_composable (p0 p1:option perm) : prop = match p0, p1 with | None, None -> True | Some p, None | None, Some p -> b2p (p `lesser_equal_perm` full_perm) | Some p0, Some p1 -> b2p (sum_perm p0 p1 `lesser_equal_perm` full_perm) /// Composing them sums the permissions let compose_perm_opt (p0 p1:option perm) = match p0, p1 with | None, p | p, None -> p | Some p0, Some p1 -> Some (sum_perm p0 p1) /// Anchored permissions are composable when at most one of them has the anchor set let permission_composable #v (p0 p1 : permission v) : prop = let q0, s0 = p0 in let q1, s1 = p1 in perm_opt_composable q0 q1 /\ // some of fracs can't exceed 1 not (Some? s0 && Some? s1) // at most one can have an anchor /// Compose permissions component wise, keeping the anchor if set let compose_permissions (#v:_) (p0:permission v) (p1:permission v{permission_composable p0 p1}) : permission v = compose_perm_opt (fst p0) (fst p1), (match snd p0, snd p1 with | None, a | a, None -> a) /// This is the central definition of the PCM --- defining when two /// values are composable, or equivalently, when one thread's /// knowledge of [av0] is compatible with another thread's knowledge /// of [av1] /// /// This definition shows the interplay between fractions and anchors. /// It wasn't obvious to me how to factor this further, e.g., adding /// anchors to preorders and then separately adding fractions to it. let avalue_composable (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (av0 av1: avalue anchors) : prop = let (p0, v0) = av0 in let (p1, v1) = av1 in permission_composable p0 p1 /\ (if not (has_some_ownership p0) && not (has_some_ownership p1) then p_composable _ v0 v1 //neither has ownership, one history is older than the other else if not (has_some_ownership p0) && has_some_ownership p1 then ( if has_nonzero p1 then v1 `extends` v0 //the one with ownership is more recent else ( //this part is the most subtle assert (has_anchor p1); p_composable _ v0 v1 /\ (v0 `extends` v1 ==> //if v0 is a more recent snapshot than v1 //then v0 must still be anchored by v1's anchor anchor_of p1 `anchors` curval v0) ) ) else if has_some_ownership p0 && not (has_some_ownership p1) then ( //symmetric if has_nonzero p0 then v0 `extends` v1 else ( assert (has_anchor p0); p_composable _ v0 v1 /\ (v1 `extends` v0 ==> anchor_of p0 `anchors` curval v1) ) ) else ( assert (has_some_ownership p0 && has_some_ownership p1); if has_nonzero p0 && has_nonzero p1 then v0 == v1 //if both have non-zero perm, then they must both only have read permission and must agree on the value else if has_nonzero p0 && has_anchor p1 then ( assert (not (has_nonzero p1)); //The key part of the anchor semantics: v0 `extends` v1 /\ //v0 has advanceable ownership, so extends anchor_of p1 `anchors` curval v0 //but not beyond what is allowed by s ) else if has_anchor p0 && has_nonzero p1 //symmetric then ( assert (not (has_nonzero p0)); v1 `extends` v0 /\ anchor_of p0 `anchors` curval v1 //v1 extends, but not beyond what is allowed by s ) else (assert false; False) ) ) //exhaustive /// Lifting avalue comosability to knowledge, including the unit let composable #v (#p:preorder v) (#a:anchor_rel p) : symrel (knowledge a) = fun (k0 k1:knowledge a) -> match k0, k1 with | Nothing, _ | _, Nothing -> True | Owns m, Owns m' -> avalue_composable m m' /// Compose avalues by composing permissions and composing the values /// using the underlying preorder PCM let compose_avalue (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (m0:avalue anchors) (m1:avalue anchors { avalue_composable m0 m1 } ) : avalue anchors = let p0, v0 = m0 in let p1, v1 = m1 in let p12 = compose_permissions p0 p1 in let v12 = p_op _ v0 v1 in p12, v12 //////////////////////////////////////////////////////////////////////////////// (** avalue composition is associative and commutative **) let compose_avalue_comm (#v:Type) (#p:preorder v) (#anc:anchor_rel p) (m0: avalue anc) (m1: avalue anc{ avalue_composable m0 m1 }) : Lemma (compose_avalue m0 m1 == compose_avalue m1 m0) = () let avalue_composable_assoc_l (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (m0: avalue anchors) (m1: avalue anchors) (m2: avalue anchors { avalue_composable m1 m2 /\ avalue_composable m0 (compose_avalue m1 m2) }) : Lemma (avalue_composable m0 m1 /\ avalue_composable (compose_avalue m0 m1) m2) = () let compose_avalue_assoc_l (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m0: avalue s) (m1: avalue s) (m2: avalue s { avalue_composable m1 m2 /\ avalue_composable m0 (compose_avalue m1 m2) }) : Lemma (avalue_composable m0 m1 /\ avalue_composable (compose_avalue m0 m1) m2 /\ compose_avalue m0 (compose_avalue m1 m2) == compose_avalue (compose_avalue m0 m1) m2) = avalue_composable_assoc_l m0 m1 m2 let avalue_composable_assoc_r (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (m0: avalue anchors) (m1: avalue anchors) (m2: avalue anchors { avalue_composable m0 m1 /\ avalue_composable (compose_avalue m0 m1) m2 }) : Lemma (avalue_composable m1 m2 /\ avalue_composable m0 (compose_avalue m1 m2)) = () let compose_avalue_assoc_r (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m0: avalue s) (m1: avalue s) (m2: avalue s{ avalue_composable m0 m1 /\ avalue_composable (compose_avalue m0 m1) m2 }) : Lemma (avalue_composable m1 m2 /\ avalue_composable m0 (compose_avalue m1 m2) /\ compose_avalue m0 (compose_avalue m1 m2) == compose_avalue (compose_avalue m0 m1) m2) = avalue_composable_assoc_r m0 m1 m2 ////////////////////////////////////////////////////////////////////////////////
{ "checked_file": "/", "dependencies": [ "Steel.Preorder.fst.checked", "Steel.FractionalPermission.fst.checked", "prims.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked" ], "interface_file": false, "source_file": "Steel.FractionalAnchoredPreorder.fst" }
[ { "abbrev": false, "full_module": "Steel.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Steel.Preorder", "short_module": null }, { "abbrev": false, "full_module": "FStar.Preorder", "short_module": null }, { "abbrev": false, "full_module": "FStar.PCM", "short_module": null }, { "abbrev": false, "full_module": "Steel", "short_module": null }, { "abbrev": false, "full_module": "Steel", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
k0: Steel.FractionalAnchoredPreorder.knowledge s -> k1: Steel.FractionalAnchoredPreorder.knowledge s {Steel.FractionalAnchoredPreorder.composable k0 k1} -> Steel.FractionalAnchoredPreorder.knowledge s
Prims.Tot
[ "total" ]
[]
[ "FStar.Preorder.preorder", "Steel.FractionalAnchoredPreorder.anchor_rel", "Steel.FractionalAnchoredPreorder.knowledge", "Steel.FractionalAnchoredPreorder.composable", "FStar.Pervasives.Native.Mktuple2", "Steel.FractionalAnchoredPreorder.avalue", "Steel.FractionalAnchoredPreorder.Owns", "Steel.FractionalAnchoredPreorder.compose_avalue" ]
[]
false
false
false
false
false
let compose (#v: Type) (#p: preorder v) (#s: anchor_rel p) (k0: knowledge s) (k1: knowledge s {composable k0 k1}) : knowledge s =
match k0, k1 with | Nothing, k | k, Nothing -> k | Owns m, Owns m' -> Owns (compose_avalue m m')
false
Spec.Agile.HPKE.fst
Spec.Agile.HPKE.sealAuthPSK
val sealAuthPSK: cs:ciphersuite_not_export_only -> skE:key_dh_secret_s cs -> pkR:DH.serialized_point (kem_dh_of_cs cs) -> info:info_s cs -> aad:AEAD.ad (aead_alg_of cs) -> pt:AEAD.plain (aead_alg_of cs) -> psk:psk_s cs -> psk_id:psk_id_s cs -> skS:key_dh_secret_s cs -> Tot (option (key_dh_public_s cs & AEAD.encrypted #(aead_alg_of cs) pt))
val sealAuthPSK: cs:ciphersuite_not_export_only -> skE:key_dh_secret_s cs -> pkR:DH.serialized_point (kem_dh_of_cs cs) -> info:info_s cs -> aad:AEAD.ad (aead_alg_of cs) -> pt:AEAD.plain (aead_alg_of cs) -> psk:psk_s cs -> psk_id:psk_id_s cs -> skS:key_dh_secret_s cs -> Tot (option (key_dh_public_s cs & AEAD.encrypted #(aead_alg_of cs) pt))
let sealAuthPSK cs skE pkR info aad pt psk psk_id skS = match setupAuthPSKS cs skE pkR info psk psk_id skS with | None -> None | Some (enc, ctx) -> match context_seal cs ctx aad pt with | None -> None | Some (_, ct) -> Some (enc, ct)
{ "file_name": "specs/Spec.Agile.HPKE.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 36, "end_line": 611, "start_col": 0, "start_line": 605 }
module Spec.Agile.HPKE open FStar.Mul open Lib.IntTypes open Lib.RawIntTypes open Lib.Sequence open Lib.ByteSequence module DH = Spec.Agile.DH module AEAD = Spec.Agile.AEAD module Hash = Spec.Agile.Hash module HKDF = Spec.Agile.HKDF let pow2_61 : _:unit{pow2 61 == 2305843009213693952} = assert_norm(pow2 61 == 2305843009213693952) let pow2_35_less_than_pow2_61 : _:unit{pow2 32 * pow2 3 <= pow2 61 - 1} = assert_norm(pow2 32 * pow2 3 <= pow2 61 - 1) let pow2_35_less_than_pow2_125 : _:unit{pow2 32 * pow2 3 <= pow2 125 - 1} = assert_norm(pow2 32 * pow2 3 <= pow2 125 - 1) #set-options "--z3rlimit 20 --fuel 0 --ifuel 1" /// Types val id_kem: cs:ciphersuite -> Tot (lbytes 2) let id_kem cs = let kem_dh, kem_hash, _, _ = cs in match kem_dh, kem_hash with | DH.DH_P256, Hash.SHA2_256 -> create 1 (u8 0) @| create 1 (u8 16) | DH.DH_Curve25519, Hash.SHA2_256 -> create 1 (u8 0) @| create 1 (u8 32) val id_kdf: cs:ciphersuite -> Tot (lbytes 2) let id_kdf cs = let _, _, _, h = cs in match h with | Hash.SHA2_256 -> create 1 (u8 0) @| create 1 (u8 1) | Hash.SHA2_384 -> create 1 (u8 0) @| create 1 (u8 2) | Hash.SHA2_512 -> create 1 (u8 0) @| create 1 (u8 3) val id_aead: cs:ciphersuite -> Tot (lbytes 2) let id_aead cs = let _, _, a, _ = cs in match a with | Seal AEAD.AES128_GCM -> create 1 (u8 0) @| create 1 (u8 1) | Seal AEAD.AES256_GCM -> create 1 (u8 0) @| create 1 (u8 2) | Seal AEAD.CHACHA20_POLY1305 -> create 1 (u8 0) @| create 1 (u8 3) | ExportOnly -> create 1 (u8 255) @| create 1 (u8 255) val suite_id_kem: cs:ciphersuite -> Tot (lbytes size_suite_id_kem) let suite_id_kem cs = Seq.append label_KEM (id_kem cs) val suite_id_hpke: cs:ciphersuite -> Tot (lbytes size_suite_id_hpke) let suite_id_hpke cs = Seq.append label_HPKE (id_kem cs @| id_kdf cs @| id_aead cs) val id_of_mode: m:mode -> Tot (lbytes size_mode_identifier) let id_of_mode m = match m with | Base -> create 1 (u8 0) | PSK -> create 1 (u8 1) | Auth -> create 1 (u8 2) | AuthPSK -> create 1 (u8 3) val labeled_extract: a:hash_algorithm -> suite_id:bytes -> salt:bytes -> label:bytes -> ikm:bytes -> Pure (lbytes (Spec.Hash.Definitions.hash_length a)) (requires Spec.Agile.HMAC.keysized a (Seq.length salt) /\ labeled_extract_ikm_length_pred a (Seq.length suite_id + Seq.length label + Seq.length ikm)) (ensures fun _ -> True) let labeled_extract a suite_id salt label ikm = let labeled_ikm1 = Seq.append label_version suite_id in let labeled_ikm2 = Seq.append labeled_ikm1 label in let labeled_ikm3 = Seq.append labeled_ikm2 ikm in HKDF.extract a salt labeled_ikm3 val labeled_expand: a:hash_algorithm -> suite_id:bytes -> prk:bytes -> label:bytes -> info:bytes -> l:size_nat -> Pure (lbytes l) (requires Spec.Hash.Definitions.hash_length a <= Seq.length prk /\ Spec.Agile.HMAC.keysized a (Seq.length prk) /\ labeled_expand_info_length_pred a (Seq.length suite_id + Seq.length label + Seq.length info) /\ HKDF.expand_output_length_pred a l) (ensures fun _ -> True) let labeled_expand a suite_id prk label info l = let labeled_info1 = nat_to_bytes_be 2 l in let labeled_info2 = Seq.append labeled_info1 label_version in let labeled_info3 = Seq.append labeled_info2 suite_id in let labeled_info4 = Seq.append labeled_info3 label in let labeled_info5 = Seq.append labeled_info4 info in HKDF.expand a prk labeled_info5 l let extract_and_expand_dh_pred (cs:ciphersuite) (dh_length:nat) = labeled_extract_ikm_length_pred (kem_hash_of_cs cs) (size_suite_id_kem + size_label_eae_prk + dh_length) let extract_and_expand_ctx_pred (cs:ciphersuite) (ctx_length:nat) = labeled_expand_info_length_pred (kem_hash_of_cs cs) (size_suite_id_kem + size_label_shared_secret + ctx_length) val extract_and_expand: cs:ciphersuite -> dh:bytes -> kem_context:bytes -> Pure (key_kem_s cs) (requires extract_and_expand_dh_pred cs (Seq.length dh) /\ extract_and_expand_ctx_pred cs (Seq.length kem_context)) (ensures fun _ -> True) let extract_and_expand cs dh kem_context = let eae_prk = labeled_extract (kem_hash_of_cs cs) (suite_id_kem cs) lbytes_empty label_eae_prk dh in labeled_expand (kem_hash_of_cs cs) (suite_id_kem cs) eae_prk label_shared_secret kem_context (size_kem_key cs) let deserialize_public_key cs pk = match kem_dh_of_cs cs with | DH.DH_Curve25519 -> pk // Extract the point coordinates by removing the first representation byte | DH.DH_P256 -> sub pk 1 64 let serialize_public_key cs pk = match kem_dh_of_cs cs with | DH.DH_Curve25519 -> pk // Add the first representation byte to the point coordinates | DH.DH_P256 -> create 1 (u8 4) @| pk val dkp_nist_p: cs:ciphersuite -> lbytes (size_kem_kdf cs) -> counter:uint8 -> Tot (option (key_dh_secret_s cs & key_dh_public_s cs)) (decreases 255 - v counter) let rec dkp_nist_p cs dkp_prk counter = let counterbyte = nat_to_intseq_be #U8 #SEC 1 (v counter) in let bytes = labeled_expand (kem_hash_of_cs cs) (suite_id_kem cs) dkp_prk label_candidate counterbyte (size_dh_key cs) in let bytes = Lib.Sequence.map2 (logand #U8 #SEC) bytes (Seq.create (size_dh_key cs) (u8 255)) in let sk = nat_from_intseq_be #U8 #SEC bytes in if sk = 0 || sk >= Spec.P256.prime then if (v counter) = 255 then None else dkp_nist_p cs dkp_prk (counter +! (u8 1)) else match DH.secret_to_public (kem_dh_of_cs cs) bytes with | Some pk -> Some (bytes, serialize_public_key cs pk) | None -> if (v counter) = 255 then None else dkp_nist_p cs dkp_prk (counter +! (u8 1)) let derive_key_pair cs ikm = match kem_dh_of_cs cs with | DH.DH_Curve25519 -> begin let dkp_prk = labeled_extract (kem_hash_of_cs cs) (suite_id_kem cs) lbytes_empty label_dkp_prk ikm in let sk = labeled_expand (kem_hash_of_cs cs) (suite_id_kem cs) dkp_prk label_sk lbytes_empty (size_dh_key cs) in match DH.secret_to_public (kem_dh_of_cs cs) sk with | Some pk -> Some (sk, serialize_public_key cs pk) end | DH.DH_P256 -> let dkp_prk = labeled_extract (kem_hash_of_cs cs) (suite_id_kem cs) lbytes_empty label_dkp_prk ikm in dkp_nist_p cs dkp_prk (u8 0) val prepare_dh: cs:ciphersuite -> DH.serialized_point (kem_dh_of_cs cs) -> Tot (lbytes 32) let prepare_dh cs dh = match (kem_dh_of_cs cs) with | DH.DH_Curve25519 -> serialize_public_key cs dh | DH.DH_P256 -> sub dh 0 32 val encap: cs:ciphersuite -> skE:key_dh_secret_s cs -> pkR:DH.serialized_point (kem_dh_of_cs cs) -> Tot (option (key_kem_s cs & key_dh_public_s cs)) #restart-solver #set-options "--z3rlimit 100 --fuel 0 --ifuel 0" let encap cs skE pkR = let _ = allow_inversion Spec.Agile.DH.algorithm in match DH.secret_to_public (kem_dh_of_cs cs) skE with | None -> None | Some pkE -> let enc = serialize_public_key cs pkE in match DH.dh (kem_dh_of_cs cs) skE pkR with | None -> None | Some dh -> let pkRm = serialize_public_key cs pkR in let kem_context = concat enc pkRm in let dhm = prepare_dh cs dh in assert (Seq.length kem_context = 2*size_dh_public cs); assert (extract_and_expand_ctx_pred cs (Seq.length kem_context)); let shared_secret:key_kem_s cs = extract_and_expand cs dhm kem_context in Some (shared_secret, enc) val decap: cs: ciphersuite -> enc: key_dh_public_s cs -> skR: key_dh_secret_s cs -> Tot (option (key_kem_s cs)) #set-options "--z3rlimit 100 --fuel 0 --ifuel 0" let decap cs enc skR = let _ = allow_inversion Spec.Agile.DH.algorithm in let _ = allow_inversion Spec.Agile.Hash.hash_alg in let pkE = deserialize_public_key cs enc in match DH.dh (kem_dh_of_cs cs) skR pkE with | None -> None | Some dh -> match DH.secret_to_public (kem_dh_of_cs cs) skR with | None -> None | Some pkR -> let pkRm = serialize_public_key cs pkR in let kem_context = concat enc pkRm in let dhm = prepare_dh cs dh in assert (Seq.length kem_context = 2*size_dh_public cs); assert (extract_and_expand_ctx_pred cs (Seq.length kem_context)); let shared_secret = extract_and_expand cs dhm kem_context in Some (shared_secret) val auth_encap: cs:ciphersuite -> skE:key_dh_secret_s cs -> pkR:DH.serialized_point (kem_dh_of_cs cs) -> skS:key_dh_secret_s cs -> Tot (option (key_kem_s cs & key_dh_public_s cs)) #set-options "--z3rlimit 100 --fuel 0 --ifuel 0" let auth_encap cs skE pkR skS = let _ = allow_inversion Spec.Agile.DH.algorithm in match DH.secret_to_public (kem_dh_of_cs cs) skE with | None -> None | Some pkE -> match DH.dh (kem_dh_of_cs cs) skE pkR with | None -> None | Some es -> match DH.dh (kem_dh_of_cs cs) skS pkR with | None -> None | Some ss -> let esm = prepare_dh cs es in let ssm = prepare_dh cs ss in // TODO Do not put 32 literally let dh = concat #uint8 #32 #32 esm ssm in let enc = serialize_public_key cs pkE in match DH.secret_to_public (kem_dh_of_cs cs) skS with | None -> None | Some pkS -> let pkSm = serialize_public_key cs pkS in let pkRm = serialize_public_key cs pkR in let kem_context = concat enc (concat pkRm pkSm) in assert (Seq.length kem_context = 3*size_dh_public cs); assert (labeled_expand_info_length_pred (kem_hash_of_cs cs) (size_suite_id_kem + size_label_shared_secret + Seq.length kem_context)); assert (extract_and_expand_ctx_pred cs (Seq.length kem_context)); // TODO Do not put 64 literally assert (Seq.length dh = 64); assert (labeled_extract_ikm_length_pred (kem_hash_of_cs cs) (size_suite_id_kem + size_label_eae_prk + Seq.length dh)); assert (extract_and_expand_dh_pred cs (Seq.length dh)); let shared_secret = extract_and_expand cs dh kem_context in Some (shared_secret, enc) #reset-options val auth_decap: cs: ciphersuite -> enc: key_dh_public_s cs -> skR: key_dh_secret_s cs -> pkS: DH.serialized_point (kem_dh_of_cs cs) -> Tot (option (key_kem_s cs)) #restart-solver #set-options "--z3rlimit 100 --fuel 0 --ifuel 0" let auth_decap cs enc skR pkS = let _ = allow_inversion Spec.Agile.DH.algorithm in let pkE = deserialize_public_key cs enc in match DH.dh (kem_dh_of_cs cs) skR pkE with | None -> None | Some es -> match DH.dh (kem_dh_of_cs cs) skR pkS with | None -> None | Some ss -> let esm = prepare_dh cs es in let ssm = prepare_dh cs ss in let dh = concat #uint8 #32 #32 esm ssm in match DH.secret_to_public (kem_dh_of_cs cs) skR with | None -> None | Some pkR -> let pkRm = serialize_public_key cs pkR in let pkSm = serialize_public_key cs pkS in let kem_context = concat enc (concat pkRm pkSm) in assert (Seq.length kem_context = 3*size_dh_public cs); assert (labeled_expand_info_length_pred (kem_hash_of_cs cs) (size_suite_id_kem + size_label_shared_secret + Seq.length kem_context)); assert (extract_and_expand_ctx_pred cs (Seq.length kem_context)); assert (Seq.length dh = 64); assert (labeled_extract_ikm_length_pred (kem_hash_of_cs cs) (size_suite_id_kem + size_label_eae_prk + Seq.length dh)); assert (extract_and_expand_dh_pred cs (Seq.length dh)); let shared_secret = extract_and_expand cs dh kem_context in Some (shared_secret) #reset-options let default_psk = lbytes_empty let default_psk_id = lbytes_empty val build_context: cs:ciphersuite -> m:mode -> psk_id_hash:lbytes (size_kdf cs) -> info_hash:lbytes (size_kdf cs) -> Tot (lbytes (size_ks_ctx cs)) let build_context cs m psk_id_hash info_hash = let context = id_of_mode m in let context = Seq.append context psk_id_hash in let context = Seq.append context info_hash in context let verify_psk_inputs (cs:ciphersuite) (m:mode) (opsk:option(psk_s cs & psk_id_s cs)) : bool = match (m, opsk) with | Base, None -> true | PSK, Some _ -> true | Auth, None -> true | AuthPSK, Some _ -> true | _, _ -> false // key and nonce are zero-length if AEAD is Export-Only let encryption_context (cs:ciphersuite) = key_aead_s cs & nonce_aead_s cs & seq_aead_s cs & exporter_secret_s cs val key_schedule: cs:ciphersuite -> m:mode -> shared_secret:key_kem_s cs -> info:info_s cs -> opsk:option (psk_s cs & psk_id_s cs) -> Pure (encryption_context cs) (requires verify_psk_inputs cs m opsk) (ensures fun _ -> True) #set-options "--z3rlimit 500 --fuel 0 --ifuel 2" let key_schedule_core (cs:ciphersuite) (m:mode) (shared_secret:key_kem_s cs) (info:info_s cs) (opsk:option (psk_s cs & psk_id_s cs)) : (lbytes (size_ks_ctx cs) & exporter_secret_s cs & (lbytes (Spec.Hash.Definitions.hash_length (hash_of_cs cs)))) = let (psk, psk_id) = match opsk with | None -> (default_psk, default_psk_id) | Some (psk, psk_id) -> (psk, psk_id) in let psk_id_hash = labeled_extract (hash_of_cs cs) (suite_id_hpke cs) lbytes_empty label_psk_id_hash psk_id in let info_hash = labeled_extract (hash_of_cs cs) (suite_id_hpke cs) lbytes_empty label_info_hash info in let context = build_context cs m psk_id_hash info_hash in let secret = labeled_extract (hash_of_cs cs) (suite_id_hpke cs) shared_secret label_secret psk in let exporter_secret = labeled_expand (hash_of_cs cs) (suite_id_hpke cs) secret label_exp context (size_kdf cs) in context, exporter_secret, secret let key_schedule_end (cs:ciphersuite) (m:mode) (context:lbytes (size_ks_ctx cs)) (exporter_secret:exporter_secret_s cs) (secret:(lbytes (Spec.Hash.Definitions.hash_length (hash_of_cs cs)))) : encryption_context cs = if is_valid_not_export_only_ciphersuite cs then ( let key = labeled_expand (hash_of_cs cs) (suite_id_hpke cs) secret label_key context (size_aead_key cs) in let base_nonce = labeled_expand (hash_of_cs cs) (suite_id_hpke cs) secret label_base_nonce context (size_aead_nonce cs) in (key, base_nonce, 0, exporter_secret) ) else ( (* if AEAD is Export-Only, then skip computation of key and base_nonce *) assert (size_aead_key cs = 0); assert (size_aead_nonce cs = 0); (lbytes_empty, lbytes_empty, 0, exporter_secret)) let key_schedule cs m shared_secret info opsk = let context, exporter_secret, secret = key_schedule_core cs m shared_secret info opsk in key_schedule_end cs m context exporter_secret secret let key_of_ctx (cs:ciphersuite) (ctx:encryption_context cs) = let key, _, _, _ = ctx in key let base_nonce_of_ctx (cs:ciphersuite) (ctx:encryption_context cs) = let _, base_nonce, _, _ = ctx in base_nonce let seq_of_ctx (cs:ciphersuite) (ctx:encryption_context cs) = let _, _, seq, _ = ctx in seq let exp_sec_of_ctx (cs:ciphersuite) (ctx:encryption_context cs) = let _, _, _, exp_sec = ctx in exp_sec let set_seq (cs:ciphersuite) (ctx:encryption_context cs) (seq:seq_aead_s cs) = let key, base_nonce, _, exp_sec = ctx in (key, base_nonce, seq, exp_sec) /// /// Encryption Context /// let context_export cs ctx exp_ctx l = let exp_sec = exp_sec_of_ctx cs ctx in labeled_expand (hash_of_cs cs) (suite_id_hpke cs) exp_sec label_sec exp_ctx l let context_compute_nonce cs ctx seq = let base_nonce = base_nonce_of_ctx cs ctx in let enc_seq = nat_to_bytes_be (size_aead_nonce cs) seq in Spec.Loops.seq_map2 logxor enc_seq base_nonce let context_increment_seq cs ctx = let seq = seq_of_ctx cs ctx in if seq = max_seq cs then None else Some (set_seq cs ctx (seq + 1)) let context_seal cs ctx aad pt = let key = key_of_ctx cs ctx in let seq = seq_of_ctx cs ctx in let nonce = context_compute_nonce cs ctx seq in let ct = AEAD.encrypt key nonce aad pt in match context_increment_seq cs ctx with | None -> None | Some new_ctx -> Some (new_ctx, ct) let context_open cs ctx aad ct = let key = key_of_ctx cs ctx in let seq = seq_of_ctx cs ctx in let nonce = context_compute_nonce cs ctx seq in match AEAD.decrypt key nonce aad ct with | None -> None | Some pt -> match context_increment_seq cs ctx with | None -> None | Some new_ctx -> Some (new_ctx, pt) /// /// Base Mode /// let setupBaseS cs skE pkR info = match encap cs skE pkR with | None -> None | Some (shared_secret, enc) -> let enc_ctx = key_schedule cs Base shared_secret info None in Some (enc, enc_ctx) let setupBaseR cs enc skR info = let pkR = DH.secret_to_public (kem_dh_of_cs cs) skR in let shared_secret = decap cs enc skR in match pkR, shared_secret with | Some pkR, Some shared_secret -> Some (key_schedule cs Base shared_secret info None) | _ -> None let sealBase cs skE pkR info aad pt = match setupBaseS cs skE pkR info with | None -> None | Some (enc, ctx) -> match context_seal cs ctx aad pt with | None -> None | Some (_, ct) -> Some (enc, ct) let openBase cs enc skR info aad ct = match setupBaseR cs enc skR info with | None -> None | Some ctx -> match context_open cs ctx aad ct with | None -> None | Some (_, pt) -> Some pt let sendExportBase cs skE pkR info exp_ctx l = match setupBaseS cs skE pkR info with | None -> None | Some (enc, ctx) -> Some (enc, context_export cs ctx exp_ctx l) let receiveExportBase cs enc skR info exp_ctx l = match setupBaseR cs enc skR info with | None -> None | Some ctx -> Some (context_export cs ctx exp_ctx l) /// /// PSK mode /// let setupPSKS cs skE pkR info psk psk_id = match encap cs skE pkR with | None -> None | Some (shared_secret, enc) -> assert (verify_psk_inputs cs PSK (Some (psk, psk_id))); let enc_ctx = key_schedule cs PSK shared_secret info (Some (psk, psk_id)) in Some (enc, enc_ctx) let setupPSKR cs enc skR info psk psk_id = let pkR = DH.secret_to_public (kem_dh_of_cs cs) skR in let shared_secret = decap cs enc skR in match pkR, shared_secret with | Some pkR, Some shared_secret -> Some (key_schedule cs PSK shared_secret info (Some (psk, psk_id))) | _ -> None let sealPSK cs skE pkR info aad pt psk psk_id = match setupPSKS cs skE pkR info psk psk_id with | None -> None | Some (enc, ctx) -> match context_seal cs ctx aad pt with | None -> None | Some (_, ct) -> Some (enc, ct) #restart-solver let openPSK cs enc skR info aad ct psk psk_id = match setupPSKR cs enc skR info psk psk_id with | None -> None | Some ctx -> match context_open cs ctx aad ct with | None -> None | Some (_, pt) -> Some pt let sendExportPSK cs skE pkR info exp_ctx l psk psk_id = match setupPSKS cs skE pkR info psk psk_id with | None -> None | Some (enc, ctx) -> Some (enc, context_export cs ctx exp_ctx l) let receiveExportPSK cs enc skR info exp_ctx l psk psk_id = match setupPSKR cs enc skR info psk psk_id with | None -> None | Some ctx -> Some (context_export cs ctx exp_ctx l) /// /// Auth mode /// let setupAuthS cs skE pkR info skS = match auth_encap cs skE pkR skS with | None -> None | Some (shared_secret, enc) -> let enc_ctx = key_schedule cs Auth shared_secret info None in Some (enc, enc_ctx) let setupAuthR cs enc skR info pkS = let pkR = DH.secret_to_public (kem_dh_of_cs cs) skR in let shared_secret = auth_decap cs enc skR pkS in match pkR, shared_secret with | Some pkR, Some shared_secret -> Some (key_schedule cs Auth shared_secret info None) | _ -> None let sealAuth cs skE pkR info aad pt skS = match setupAuthS cs skE pkR info skS with | None -> None | Some (enc, ctx) -> match context_seal cs ctx aad pt with | None -> None | Some (_, ct) -> Some (enc, ct) let openAuth cs enc skR info aad ct pkS = match setupAuthR cs enc skR info pkS with | None -> None | Some ctx -> match context_open cs ctx aad ct with | None -> None | Some (_, pt) -> Some pt let sendExportAuth cs skE pkR info exp_ctx l skS = match setupAuthS cs skE pkR info skS with | None -> None | Some (enc, ctx) -> Some (enc, context_export cs ctx exp_ctx l) let receiveExportAuth cs enc skR info exp_ctx l pkS = match setupAuthR cs enc skR info pkS with | None -> None | Some ctx -> Some (context_export cs ctx exp_ctx l) /// /// AuthPSK mode /// let setupAuthPSKS cs skE pkR info psk psk_id skS = match auth_encap cs skE pkR skS with | None -> None | Some (shared_secret, enc) -> let enc_ctx = key_schedule cs AuthPSK shared_secret info (Some (psk, psk_id)) in Some (enc, enc_ctx) let setupAuthPSKR cs enc skR info psk psk_id pkS = let pkR = DH.secret_to_public (kem_dh_of_cs cs) skR in let shared_secret = auth_decap cs enc skR pkS in match pkR, shared_secret with | Some pkR, Some shared_secret -> Some (key_schedule cs AuthPSK shared_secret info (Some (psk, psk_id))) | _ -> None
{ "checked_file": "/", "dependencies": [ "Spec.P256.fst.checked", "Spec.Loops.fst.checked", "Spec.Hash.Definitions.fst.checked", "Spec.Agile.HMAC.fsti.checked", "Spec.Agile.HKDF.fsti.checked", "Spec.Agile.Hash.fsti.checked", "Spec.Agile.DH.fst.checked", "Spec.Agile.AEAD.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.RawIntTypes.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Spec.Agile.HPKE.fst" }
[ { "abbrev": true, "full_module": "Spec.Agile.HKDF", "short_module": "HKDF" }, { "abbrev": true, "full_module": "Spec.Agile.Hash", "short_module": "Hash" }, { "abbrev": true, "full_module": "Spec.Agile.AEAD", "short_module": "AEAD" }, { "abbrev": true, "full_module": "Spec.Agile.DH", "short_module": "DH" }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.RawIntTypes", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Spec.Agile.HKDF", "short_module": "HKDF" }, { "abbrev": true, "full_module": "Spec.Agile.Hash", "short_module": "Hash" }, { "abbrev": true, "full_module": "Spec.Agile.AEAD", "short_module": "AEAD" }, { "abbrev": true, "full_module": "Spec.Agile.DH", "short_module": "DH" }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.RawIntTypes", "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.Agile", "short_module": null }, { "abbrev": false, "full_module": "Spec.Agile", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 500, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
cs: Spec.Agile.HPKE.ciphersuite_not_export_only -> skE: Spec.Agile.HPKE.key_dh_secret_s cs -> pkR: Spec.Agile.DH.serialized_point (Spec.Agile.HPKE.kem_dh_of_cs cs) -> info: Spec.Agile.HPKE.info_s cs -> aad: Spec.Agile.AEAD.ad (Spec.Agile.HPKE.aead_alg_of cs) -> pt: Spec.Agile.AEAD.plain (Spec.Agile.HPKE.aead_alg_of cs) -> psk: Spec.Agile.HPKE.psk_s cs -> psk_id: Spec.Agile.HPKE.psk_id_s cs -> skS: Spec.Agile.HPKE.key_dh_secret_s cs -> FStar.Pervasives.Native.option (Spec.Agile.HPKE.key_dh_public_s cs * Spec.Agile.AEAD.encrypted pt)
Prims.Tot
[ "total" ]
[]
[ "Spec.Agile.HPKE.ciphersuite_not_export_only", "Spec.Agile.HPKE.key_dh_secret_s", "Spec.Agile.DH.serialized_point", "Spec.Agile.HPKE.kem_dh_of_cs", "Spec.Agile.HPKE.info_s", "Spec.Agile.AEAD.ad", "Spec.Agile.HPKE.aead_alg_of", "Spec.Agile.AEAD.plain", "Spec.Agile.HPKE.psk_s", "Spec.Agile.HPKE.psk_id_s", "Spec.Agile.HPKE.setupAuthPSKS", "FStar.Pervasives.Native.None", "FStar.Pervasives.Native.tuple2", "Spec.Agile.HPKE.key_dh_public_s", "Spec.Agile.AEAD.encrypted", "Spec.Agile.HPKE.encryption_context", "Spec.Agile.HPKE.context_seal", "Spec.Agile.AEAD.cipher", "FStar.Pervasives.Native.Some", "FStar.Pervasives.Native.Mktuple2", "FStar.Pervasives.Native.option" ]
[]
false
false
false
false
false
let sealAuthPSK cs skE pkR info aad pt psk psk_id skS =
match setupAuthPSKS cs skE pkR info psk psk_id skS with | None -> None | Some (enc, ctx) -> match context_seal cs ctx aad pt with | None -> None | Some (_, ct) -> Some (enc, ct)
false
Steel.FractionalAnchoredPreorder.fst
Steel.FractionalAnchoredPreorder.compose_avalue
val compose_avalue (#v: Type) (#p: preorder v) (#anchors: anchor_rel p) (m0: avalue anchors) (m1: avalue anchors {avalue_composable m0 m1}) : avalue anchors
val compose_avalue (#v: Type) (#p: preorder v) (#anchors: anchor_rel p) (m0: avalue anchors) (m1: avalue anchors {avalue_composable m0 m1}) : avalue anchors
let compose_avalue (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (m0:avalue anchors) (m1:avalue anchors { avalue_composable m0 m1 } ) : avalue anchors = let p0, v0 = m0 in let p1, v1 = m1 in let p12 = compose_permissions p0 p1 in let v12 = p_op _ v0 v1 in p12, v12
{ "file_name": "lib/steel/Steel.FractionalAnchoredPreorder.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 13, "end_line": 255, "start_col": 0, "start_line": 247 }
(* Copyright 2021 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. Author: N. Swamy *) module Steel.FractionalAnchoredPreorder (** This module provides a partial commutative monoid (PCM) for use in the ghost state of a concurrent Steel program. Its goal is to facilitate a form of information-sharing between multiple threads including the following features: Fractions, Preorders, Snapshots, and Anchors --- Anchors are the most unusual. 1. Fractions: Ownership of the state is controlled by a fractional permission, so multiple threads may share read-only privileges on the state, but only one can have write permission. 2. Preorders: The ghost state is governed by a preorder p and all updates to the state must respect the preorder (a reflexive, transitive relation on the state) 3. Snapshots: Since the state always evolves by a preorder, it is possible to take a snapshot of the state. A snapshot does not confer any particular ownership on the state, except knowledge of a snapshot ensures that the current state is related to the snapshot by the preorder. 4. Anchors are a kind of refinement of the preorder. If a thread owns an anchored value [v], then no other thread, even a thread owning a full fractional permission, can advance the state "too far" from the anchor. In particular, the PCM is parameterized by a binary relation on values, [anchors:anchor_relation]. If a thread owns the anchor [v], then the current value `cur` of the state must be in relation [v `anchors` cur]. This can be used to ensure that the knowledge of one thread is never becomes too stale. For example, this allows one to model a shared monotonically increasing counter, where if one thread anchors knowledge of the counter at the value 5, no other thread can increase the value of the counter beyond, say, 10, (when the anchor relation is y - x <= 5), until the anchoring thread releases the anchor. Further, at any point, a thread can take a snapshot of the counter and rely on the fact that the value of the counter in the future will be >= the snapshot. *) open FStar.PCM open FStar.Preorder open Steel.Preorder open Steel.FractionalPermission #push-options "--fuel 0 --ifuel 2" /// A permission: is a pair of /// /// * an optional fractional permission; with `Some p` indicating /// some ownership, while `None` is an additional "0" permission /// value, to encode snapshots. /// /// * and an optional anchor, where `Some a` indicates the current /// value can't be too far from `a`. let permission (v:Type) = option perm & option v /// Non-zero permission is either a read or write permission let has_nonzero #v (p:permission v) = Some? (fst p) /// Has an anchor set let has_anchor #v (p:permission v) = Some? (snd p) /// Either an anchor or non-zero let has_some_ownership #v (p:permission v) = has_nonzero p || has_anchor p /// The anchoring value let anchor_of #v (p:permission v { has_anchor p }) : v = Some?.v (snd p) /// The anchoring relation: /// -- A binary relation on values /// -- refining the preorder /// -- and if x `anchors` z then it also anchors any `y` between `x` and `z` /// /// Explaining the third clause a bit: /// Think intuitively of anchoring relations as a kind of distance measure /// /// if `z` is close enough to `x` then if `z` is further than `y` /// (since it is ahead of `y` in the preorder) then `y` is also /// close enough to `x` let anchor_rel (#v:Type) (p:preorder v) = anchors:(v -> v -> prop) { (forall v0 v1. anchors v0 v1 ==> p v0 v1) /\ (forall x z. x `anchors` z ==> (forall y. p x y /\ p y z ==> x `anchors` y)) // } /// An implementation remark: We use Steel.Preorder here to /// generically transform any preorder into a PCM. That works by /// taking the value of the PCM to be a history of values related by /// the preorder. So, throughout, we'll be using the the [vhist p] /// from Steel.Preorder, the type of a non-empty history compatible /// with [p]. The details of the histories don't matter much for our /// purposes---we only care about the most recent value, for which /// we'll use [curval v]. /// If the anchor is set, then the current value is anchored by it let anchored (#v:Type) (#p:preorder v) (anchors:anchor_rel p) (pv:(permission v & vhist p)) = has_anchor (fst pv) ==> anchor_of (fst pv) `anchors` curval (snd pv) /// A value in our fractional anchored PCM is a pair of a permission /// and a p-compatible history, refined to ensure that if the anchor /// is set, then the current value is anchored by it. let avalue (#v:Type) (#p:preorder v) (anchors:anchor_rel p) = pv:(permission v & vhist p) { anchored anchors pv } /// initial_value: A utility to construct a value in the PCM #push-options "--fuel 1" let initial_value (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (value:v { anchors value value }) : avalue anchors = (Some full_perm, Some value), [value] #pop-options /// We add a unit element to [avalue], as needed for a PCM [@@erasable] noeq type knowledge (#v:Type) (#p:preorder v) (anchors:anchor_rel p) = | Owns : avalue anchors -> knowledge anchors | Nothing : knowledge anchors let b2p (b:bool) : prop = b == true /// Fractional permissions are composable when their sum <= 1.0 let perm_opt_composable (p0 p1:option perm) : prop = match p0, p1 with | None, None -> True | Some p, None | None, Some p -> b2p (p `lesser_equal_perm` full_perm) | Some p0, Some p1 -> b2p (sum_perm p0 p1 `lesser_equal_perm` full_perm) /// Composing them sums the permissions let compose_perm_opt (p0 p1:option perm) = match p0, p1 with | None, p | p, None -> p | Some p0, Some p1 -> Some (sum_perm p0 p1) /// Anchored permissions are composable when at most one of them has the anchor set let permission_composable #v (p0 p1 : permission v) : prop = let q0, s0 = p0 in let q1, s1 = p1 in perm_opt_composable q0 q1 /\ // some of fracs can't exceed 1 not (Some? s0 && Some? s1) // at most one can have an anchor /// Compose permissions component wise, keeping the anchor if set let compose_permissions (#v:_) (p0:permission v) (p1:permission v{permission_composable p0 p1}) : permission v = compose_perm_opt (fst p0) (fst p1), (match snd p0, snd p1 with | None, a | a, None -> a) /// This is the central definition of the PCM --- defining when two /// values are composable, or equivalently, when one thread's /// knowledge of [av0] is compatible with another thread's knowledge /// of [av1] /// /// This definition shows the interplay between fractions and anchors. /// It wasn't obvious to me how to factor this further, e.g., adding /// anchors to preorders and then separately adding fractions to it. let avalue_composable (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (av0 av1: avalue anchors) : prop = let (p0, v0) = av0 in let (p1, v1) = av1 in permission_composable p0 p1 /\ (if not (has_some_ownership p0) && not (has_some_ownership p1) then p_composable _ v0 v1 //neither has ownership, one history is older than the other else if not (has_some_ownership p0) && has_some_ownership p1 then ( if has_nonzero p1 then v1 `extends` v0 //the one with ownership is more recent else ( //this part is the most subtle assert (has_anchor p1); p_composable _ v0 v1 /\ (v0 `extends` v1 ==> //if v0 is a more recent snapshot than v1 //then v0 must still be anchored by v1's anchor anchor_of p1 `anchors` curval v0) ) ) else if has_some_ownership p0 && not (has_some_ownership p1) then ( //symmetric if has_nonzero p0 then v0 `extends` v1 else ( assert (has_anchor p0); p_composable _ v0 v1 /\ (v1 `extends` v0 ==> anchor_of p0 `anchors` curval v1) ) ) else ( assert (has_some_ownership p0 && has_some_ownership p1); if has_nonzero p0 && has_nonzero p1 then v0 == v1 //if both have non-zero perm, then they must both only have read permission and must agree on the value else if has_nonzero p0 && has_anchor p1 then ( assert (not (has_nonzero p1)); //The key part of the anchor semantics: v0 `extends` v1 /\ //v0 has advanceable ownership, so extends anchor_of p1 `anchors` curval v0 //but not beyond what is allowed by s ) else if has_anchor p0 && has_nonzero p1 //symmetric then ( assert (not (has_nonzero p0)); v1 `extends` v0 /\ anchor_of p0 `anchors` curval v1 //v1 extends, but not beyond what is allowed by s ) else (assert false; False) ) ) //exhaustive /// Lifting avalue comosability to knowledge, including the unit let composable #v (#p:preorder v) (#a:anchor_rel p) : symrel (knowledge a) = fun (k0 k1:knowledge a) -> match k0, k1 with | Nothing, _ | _, Nothing -> True | Owns m, Owns m' -> avalue_composable m m' /// Compose avalues by composing permissions and composing the values
{ "checked_file": "/", "dependencies": [ "Steel.Preorder.fst.checked", "Steel.FractionalPermission.fst.checked", "prims.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked" ], "interface_file": false, "source_file": "Steel.FractionalAnchoredPreorder.fst" }
[ { "abbrev": false, "full_module": "Steel.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Steel.Preorder", "short_module": null }, { "abbrev": false, "full_module": "FStar.Preorder", "short_module": null }, { "abbrev": false, "full_module": "FStar.PCM", "short_module": null }, { "abbrev": false, "full_module": "Steel", "short_module": null }, { "abbrev": false, "full_module": "Steel", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
m0: Steel.FractionalAnchoredPreorder.avalue anchors -> m1: Steel.FractionalAnchoredPreorder.avalue anchors {Steel.FractionalAnchoredPreorder.avalue_composable m0 m1} -> Steel.FractionalAnchoredPreorder.avalue anchors
Prims.Tot
[ "total" ]
[]
[ "FStar.Preorder.preorder", "Steel.FractionalAnchoredPreorder.anchor_rel", "Steel.FractionalAnchoredPreorder.avalue", "Steel.FractionalAnchoredPreorder.avalue_composable", "Steel.FractionalAnchoredPreorder.permission", "Steel.Preorder.vhist", "FStar.Pervasives.Native.Mktuple2", "Steel.Preorder.hist", "Steel.Preorder.p_op", "Steel.FractionalAnchoredPreorder.compose_permissions" ]
[]
false
false
false
false
false
let compose_avalue (#v: Type) (#p: preorder v) (#anchors: anchor_rel p) (m0: avalue anchors) (m1: avalue anchors {avalue_composable m0 m1}) : avalue anchors =
let p0, v0 = m0 in let p1, v1 = m1 in let p12 = compose_permissions p0 p1 in let v12 = p_op _ v0 v1 in p12, v12
false
Steel.FractionalAnchoredPreorder.fst
Steel.FractionalAnchoredPreorder.composable
val composable (#v: _) (#p: preorder v) (#a: anchor_rel p) : symrel (knowledge a)
val composable (#v: _) (#p: preorder v) (#a: anchor_rel p) : symrel (knowledge a)
let composable #v (#p:preorder v) (#a:anchor_rel p) : symrel (knowledge a) = fun (k0 k1:knowledge a) -> match k0, k1 with | Nothing, _ | _, Nothing -> True | Owns m, Owns m' -> avalue_composable m m'
{ "file_name": "lib/steel/Steel.FractionalAnchoredPreorder.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 28, "end_line": 243, "start_col": 0, "start_line": 235 }
(* Copyright 2021 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. Author: N. Swamy *) module Steel.FractionalAnchoredPreorder (** This module provides a partial commutative monoid (PCM) for use in the ghost state of a concurrent Steel program. Its goal is to facilitate a form of information-sharing between multiple threads including the following features: Fractions, Preorders, Snapshots, and Anchors --- Anchors are the most unusual. 1. Fractions: Ownership of the state is controlled by a fractional permission, so multiple threads may share read-only privileges on the state, but only one can have write permission. 2. Preorders: The ghost state is governed by a preorder p and all updates to the state must respect the preorder (a reflexive, transitive relation on the state) 3. Snapshots: Since the state always evolves by a preorder, it is possible to take a snapshot of the state. A snapshot does not confer any particular ownership on the state, except knowledge of a snapshot ensures that the current state is related to the snapshot by the preorder. 4. Anchors are a kind of refinement of the preorder. If a thread owns an anchored value [v], then no other thread, even a thread owning a full fractional permission, can advance the state "too far" from the anchor. In particular, the PCM is parameterized by a binary relation on values, [anchors:anchor_relation]. If a thread owns the anchor [v], then the current value `cur` of the state must be in relation [v `anchors` cur]. This can be used to ensure that the knowledge of one thread is never becomes too stale. For example, this allows one to model a shared monotonically increasing counter, where if one thread anchors knowledge of the counter at the value 5, no other thread can increase the value of the counter beyond, say, 10, (when the anchor relation is y - x <= 5), until the anchoring thread releases the anchor. Further, at any point, a thread can take a snapshot of the counter and rely on the fact that the value of the counter in the future will be >= the snapshot. *) open FStar.PCM open FStar.Preorder open Steel.Preorder open Steel.FractionalPermission #push-options "--fuel 0 --ifuel 2" /// A permission: is a pair of /// /// * an optional fractional permission; with `Some p` indicating /// some ownership, while `None` is an additional "0" permission /// value, to encode snapshots. /// /// * and an optional anchor, where `Some a` indicates the current /// value can't be too far from `a`. let permission (v:Type) = option perm & option v /// Non-zero permission is either a read or write permission let has_nonzero #v (p:permission v) = Some? (fst p) /// Has an anchor set let has_anchor #v (p:permission v) = Some? (snd p) /// Either an anchor or non-zero let has_some_ownership #v (p:permission v) = has_nonzero p || has_anchor p /// The anchoring value let anchor_of #v (p:permission v { has_anchor p }) : v = Some?.v (snd p) /// The anchoring relation: /// -- A binary relation on values /// -- refining the preorder /// -- and if x `anchors` z then it also anchors any `y` between `x` and `z` /// /// Explaining the third clause a bit: /// Think intuitively of anchoring relations as a kind of distance measure /// /// if `z` is close enough to `x` then if `z` is further than `y` /// (since it is ahead of `y` in the preorder) then `y` is also /// close enough to `x` let anchor_rel (#v:Type) (p:preorder v) = anchors:(v -> v -> prop) { (forall v0 v1. anchors v0 v1 ==> p v0 v1) /\ (forall x z. x `anchors` z ==> (forall y. p x y /\ p y z ==> x `anchors` y)) // } /// An implementation remark: We use Steel.Preorder here to /// generically transform any preorder into a PCM. That works by /// taking the value of the PCM to be a history of values related by /// the preorder. So, throughout, we'll be using the the [vhist p] /// from Steel.Preorder, the type of a non-empty history compatible /// with [p]. The details of the histories don't matter much for our /// purposes---we only care about the most recent value, for which /// we'll use [curval v]. /// If the anchor is set, then the current value is anchored by it let anchored (#v:Type) (#p:preorder v) (anchors:anchor_rel p) (pv:(permission v & vhist p)) = has_anchor (fst pv) ==> anchor_of (fst pv) `anchors` curval (snd pv) /// A value in our fractional anchored PCM is a pair of a permission /// and a p-compatible history, refined to ensure that if the anchor /// is set, then the current value is anchored by it. let avalue (#v:Type) (#p:preorder v) (anchors:anchor_rel p) = pv:(permission v & vhist p) { anchored anchors pv } /// initial_value: A utility to construct a value in the PCM #push-options "--fuel 1" let initial_value (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (value:v { anchors value value }) : avalue anchors = (Some full_perm, Some value), [value] #pop-options /// We add a unit element to [avalue], as needed for a PCM [@@erasable] noeq type knowledge (#v:Type) (#p:preorder v) (anchors:anchor_rel p) = | Owns : avalue anchors -> knowledge anchors | Nothing : knowledge anchors let b2p (b:bool) : prop = b == true /// Fractional permissions are composable when their sum <= 1.0 let perm_opt_composable (p0 p1:option perm) : prop = match p0, p1 with | None, None -> True | Some p, None | None, Some p -> b2p (p `lesser_equal_perm` full_perm) | Some p0, Some p1 -> b2p (sum_perm p0 p1 `lesser_equal_perm` full_perm) /// Composing them sums the permissions let compose_perm_opt (p0 p1:option perm) = match p0, p1 with | None, p | p, None -> p | Some p0, Some p1 -> Some (sum_perm p0 p1) /// Anchored permissions are composable when at most one of them has the anchor set let permission_composable #v (p0 p1 : permission v) : prop = let q0, s0 = p0 in let q1, s1 = p1 in perm_opt_composable q0 q1 /\ // some of fracs can't exceed 1 not (Some? s0 && Some? s1) // at most one can have an anchor /// Compose permissions component wise, keeping the anchor if set let compose_permissions (#v:_) (p0:permission v) (p1:permission v{permission_composable p0 p1}) : permission v = compose_perm_opt (fst p0) (fst p1), (match snd p0, snd p1 with | None, a | a, None -> a) /// This is the central definition of the PCM --- defining when two /// values are composable, or equivalently, when one thread's /// knowledge of [av0] is compatible with another thread's knowledge /// of [av1] /// /// This definition shows the interplay between fractions and anchors. /// It wasn't obvious to me how to factor this further, e.g., adding /// anchors to preorders and then separately adding fractions to it. let avalue_composable (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (av0 av1: avalue anchors) : prop = let (p0, v0) = av0 in let (p1, v1) = av1 in permission_composable p0 p1 /\ (if not (has_some_ownership p0) && not (has_some_ownership p1) then p_composable _ v0 v1 //neither has ownership, one history is older than the other else if not (has_some_ownership p0) && has_some_ownership p1 then ( if has_nonzero p1 then v1 `extends` v0 //the one with ownership is more recent else ( //this part is the most subtle assert (has_anchor p1); p_composable _ v0 v1 /\ (v0 `extends` v1 ==> //if v0 is a more recent snapshot than v1 //then v0 must still be anchored by v1's anchor anchor_of p1 `anchors` curval v0) ) ) else if has_some_ownership p0 && not (has_some_ownership p1) then ( //symmetric if has_nonzero p0 then v0 `extends` v1 else ( assert (has_anchor p0); p_composable _ v0 v1 /\ (v1 `extends` v0 ==> anchor_of p0 `anchors` curval v1) ) ) else ( assert (has_some_ownership p0 && has_some_ownership p1); if has_nonzero p0 && has_nonzero p1 then v0 == v1 //if both have non-zero perm, then they must both only have read permission and must agree on the value else if has_nonzero p0 && has_anchor p1 then ( assert (not (has_nonzero p1)); //The key part of the anchor semantics: v0 `extends` v1 /\ //v0 has advanceable ownership, so extends anchor_of p1 `anchors` curval v0 //but not beyond what is allowed by s ) else if has_anchor p0 && has_nonzero p1 //symmetric then ( assert (not (has_nonzero p0)); v1 `extends` v0 /\ anchor_of p0 `anchors` curval v1 //v1 extends, but not beyond what is allowed by s ) else (assert false; False) ) ) //exhaustive
{ "checked_file": "/", "dependencies": [ "Steel.Preorder.fst.checked", "Steel.FractionalPermission.fst.checked", "prims.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked" ], "interface_file": false, "source_file": "Steel.FractionalAnchoredPreorder.fst" }
[ { "abbrev": false, "full_module": "Steel.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Steel.Preorder", "short_module": null }, { "abbrev": false, "full_module": "FStar.Preorder", "short_module": null }, { "abbrev": false, "full_module": "FStar.PCM", "short_module": null }, { "abbrev": false, "full_module": "Steel", "short_module": null }, { "abbrev": false, "full_module": "Steel", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
FStar.PCM.symrel (Steel.FractionalAnchoredPreorder.knowledge a)
Prims.Tot
[ "total" ]
[]
[ "FStar.Preorder.preorder", "Steel.FractionalAnchoredPreorder.anchor_rel", "Steel.FractionalAnchoredPreorder.knowledge", "FStar.Pervasives.Native.Mktuple2", "Prims.l_True", "Steel.FractionalAnchoredPreorder.avalue", "Steel.FractionalAnchoredPreorder.avalue_composable", "Prims.prop", "FStar.PCM.symrel" ]
[]
false
false
false
false
false
let composable #v (#p: preorder v) (#a: anchor_rel p) : symrel (knowledge a) =
fun (k0: knowledge a) (k1: knowledge a) -> match k0, k1 with | Nothing, _ | _, Nothing -> True | Owns m, Owns m' -> avalue_composable m m'
false
Spec.Agile.HPKE.fst
Spec.Agile.HPKE.auth_encap
val auth_encap: cs:ciphersuite -> skE:key_dh_secret_s cs -> pkR:DH.serialized_point (kem_dh_of_cs cs) -> skS:key_dh_secret_s cs -> Tot (option (key_kem_s cs & key_dh_public_s cs))
val auth_encap: cs:ciphersuite -> skE:key_dh_secret_s cs -> pkR:DH.serialized_point (kem_dh_of_cs cs) -> skS:key_dh_secret_s cs -> Tot (option (key_kem_s cs & key_dh_public_s cs))
let auth_encap cs skE pkR skS = let _ = allow_inversion Spec.Agile.DH.algorithm in match DH.secret_to_public (kem_dh_of_cs cs) skE with | None -> None | Some pkE -> match DH.dh (kem_dh_of_cs cs) skE pkR with | None -> None | Some es -> match DH.dh (kem_dh_of_cs cs) skS pkR with | None -> None | Some ss -> let esm = prepare_dh cs es in let ssm = prepare_dh cs ss in // TODO Do not put 32 literally let dh = concat #uint8 #32 #32 esm ssm in let enc = serialize_public_key cs pkE in match DH.secret_to_public (kem_dh_of_cs cs) skS with | None -> None | Some pkS -> let pkSm = serialize_public_key cs pkS in let pkRm = serialize_public_key cs pkR in let kem_context = concat enc (concat pkRm pkSm) in assert (Seq.length kem_context = 3*size_dh_public cs); assert (labeled_expand_info_length_pred (kem_hash_of_cs cs) (size_suite_id_kem + size_label_shared_secret + Seq.length kem_context)); assert (extract_and_expand_ctx_pred cs (Seq.length kem_context)); // TODO Do not put 64 literally assert (Seq.length dh = 64); assert (labeled_extract_ikm_length_pred (kem_hash_of_cs cs) (size_suite_id_kem + size_label_eae_prk + Seq.length dh)); assert (extract_and_expand_dh_pred cs (Seq.length dh)); let shared_secret = extract_and_expand cs dh kem_context in Some (shared_secret, enc)
{ "file_name": "specs/Spec.Agile.HPKE.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 35, "end_line": 265, "start_col": 0, "start_line": 235 }
module Spec.Agile.HPKE open FStar.Mul open Lib.IntTypes open Lib.RawIntTypes open Lib.Sequence open Lib.ByteSequence module DH = Spec.Agile.DH module AEAD = Spec.Agile.AEAD module Hash = Spec.Agile.Hash module HKDF = Spec.Agile.HKDF let pow2_61 : _:unit{pow2 61 == 2305843009213693952} = assert_norm(pow2 61 == 2305843009213693952) let pow2_35_less_than_pow2_61 : _:unit{pow2 32 * pow2 3 <= pow2 61 - 1} = assert_norm(pow2 32 * pow2 3 <= pow2 61 - 1) let pow2_35_less_than_pow2_125 : _:unit{pow2 32 * pow2 3 <= pow2 125 - 1} = assert_norm(pow2 32 * pow2 3 <= pow2 125 - 1) #set-options "--z3rlimit 20 --fuel 0 --ifuel 1" /// Types val id_kem: cs:ciphersuite -> Tot (lbytes 2) let id_kem cs = let kem_dh, kem_hash, _, _ = cs in match kem_dh, kem_hash with | DH.DH_P256, Hash.SHA2_256 -> create 1 (u8 0) @| create 1 (u8 16) | DH.DH_Curve25519, Hash.SHA2_256 -> create 1 (u8 0) @| create 1 (u8 32) val id_kdf: cs:ciphersuite -> Tot (lbytes 2) let id_kdf cs = let _, _, _, h = cs in match h with | Hash.SHA2_256 -> create 1 (u8 0) @| create 1 (u8 1) | Hash.SHA2_384 -> create 1 (u8 0) @| create 1 (u8 2) | Hash.SHA2_512 -> create 1 (u8 0) @| create 1 (u8 3) val id_aead: cs:ciphersuite -> Tot (lbytes 2) let id_aead cs = let _, _, a, _ = cs in match a with | Seal AEAD.AES128_GCM -> create 1 (u8 0) @| create 1 (u8 1) | Seal AEAD.AES256_GCM -> create 1 (u8 0) @| create 1 (u8 2) | Seal AEAD.CHACHA20_POLY1305 -> create 1 (u8 0) @| create 1 (u8 3) | ExportOnly -> create 1 (u8 255) @| create 1 (u8 255) val suite_id_kem: cs:ciphersuite -> Tot (lbytes size_suite_id_kem) let suite_id_kem cs = Seq.append label_KEM (id_kem cs) val suite_id_hpke: cs:ciphersuite -> Tot (lbytes size_suite_id_hpke) let suite_id_hpke cs = Seq.append label_HPKE (id_kem cs @| id_kdf cs @| id_aead cs) val id_of_mode: m:mode -> Tot (lbytes size_mode_identifier) let id_of_mode m = match m with | Base -> create 1 (u8 0) | PSK -> create 1 (u8 1) | Auth -> create 1 (u8 2) | AuthPSK -> create 1 (u8 3) val labeled_extract: a:hash_algorithm -> suite_id:bytes -> salt:bytes -> label:bytes -> ikm:bytes -> Pure (lbytes (Spec.Hash.Definitions.hash_length a)) (requires Spec.Agile.HMAC.keysized a (Seq.length salt) /\ labeled_extract_ikm_length_pred a (Seq.length suite_id + Seq.length label + Seq.length ikm)) (ensures fun _ -> True) let labeled_extract a suite_id salt label ikm = let labeled_ikm1 = Seq.append label_version suite_id in let labeled_ikm2 = Seq.append labeled_ikm1 label in let labeled_ikm3 = Seq.append labeled_ikm2 ikm in HKDF.extract a salt labeled_ikm3 val labeled_expand: a:hash_algorithm -> suite_id:bytes -> prk:bytes -> label:bytes -> info:bytes -> l:size_nat -> Pure (lbytes l) (requires Spec.Hash.Definitions.hash_length a <= Seq.length prk /\ Spec.Agile.HMAC.keysized a (Seq.length prk) /\ labeled_expand_info_length_pred a (Seq.length suite_id + Seq.length label + Seq.length info) /\ HKDF.expand_output_length_pred a l) (ensures fun _ -> True) let labeled_expand a suite_id prk label info l = let labeled_info1 = nat_to_bytes_be 2 l in let labeled_info2 = Seq.append labeled_info1 label_version in let labeled_info3 = Seq.append labeled_info2 suite_id in let labeled_info4 = Seq.append labeled_info3 label in let labeled_info5 = Seq.append labeled_info4 info in HKDF.expand a prk labeled_info5 l let extract_and_expand_dh_pred (cs:ciphersuite) (dh_length:nat) = labeled_extract_ikm_length_pred (kem_hash_of_cs cs) (size_suite_id_kem + size_label_eae_prk + dh_length) let extract_and_expand_ctx_pred (cs:ciphersuite) (ctx_length:nat) = labeled_expand_info_length_pred (kem_hash_of_cs cs) (size_suite_id_kem + size_label_shared_secret + ctx_length) val extract_and_expand: cs:ciphersuite -> dh:bytes -> kem_context:bytes -> Pure (key_kem_s cs) (requires extract_and_expand_dh_pred cs (Seq.length dh) /\ extract_and_expand_ctx_pred cs (Seq.length kem_context)) (ensures fun _ -> True) let extract_and_expand cs dh kem_context = let eae_prk = labeled_extract (kem_hash_of_cs cs) (suite_id_kem cs) lbytes_empty label_eae_prk dh in labeled_expand (kem_hash_of_cs cs) (suite_id_kem cs) eae_prk label_shared_secret kem_context (size_kem_key cs) let deserialize_public_key cs pk = match kem_dh_of_cs cs with | DH.DH_Curve25519 -> pk // Extract the point coordinates by removing the first representation byte | DH.DH_P256 -> sub pk 1 64 let serialize_public_key cs pk = match kem_dh_of_cs cs with | DH.DH_Curve25519 -> pk // Add the first representation byte to the point coordinates | DH.DH_P256 -> create 1 (u8 4) @| pk val dkp_nist_p: cs:ciphersuite -> lbytes (size_kem_kdf cs) -> counter:uint8 -> Tot (option (key_dh_secret_s cs & key_dh_public_s cs)) (decreases 255 - v counter) let rec dkp_nist_p cs dkp_prk counter = let counterbyte = nat_to_intseq_be #U8 #SEC 1 (v counter) in let bytes = labeled_expand (kem_hash_of_cs cs) (suite_id_kem cs) dkp_prk label_candidate counterbyte (size_dh_key cs) in let bytes = Lib.Sequence.map2 (logand #U8 #SEC) bytes (Seq.create (size_dh_key cs) (u8 255)) in let sk = nat_from_intseq_be #U8 #SEC bytes in if sk = 0 || sk >= Spec.P256.prime then if (v counter) = 255 then None else dkp_nist_p cs dkp_prk (counter +! (u8 1)) else match DH.secret_to_public (kem_dh_of_cs cs) bytes with | Some pk -> Some (bytes, serialize_public_key cs pk) | None -> if (v counter) = 255 then None else dkp_nist_p cs dkp_prk (counter +! (u8 1)) let derive_key_pair cs ikm = match kem_dh_of_cs cs with | DH.DH_Curve25519 -> begin let dkp_prk = labeled_extract (kem_hash_of_cs cs) (suite_id_kem cs) lbytes_empty label_dkp_prk ikm in let sk = labeled_expand (kem_hash_of_cs cs) (suite_id_kem cs) dkp_prk label_sk lbytes_empty (size_dh_key cs) in match DH.secret_to_public (kem_dh_of_cs cs) sk with | Some pk -> Some (sk, serialize_public_key cs pk) end | DH.DH_P256 -> let dkp_prk = labeled_extract (kem_hash_of_cs cs) (suite_id_kem cs) lbytes_empty label_dkp_prk ikm in dkp_nist_p cs dkp_prk (u8 0) val prepare_dh: cs:ciphersuite -> DH.serialized_point (kem_dh_of_cs cs) -> Tot (lbytes 32) let prepare_dh cs dh = match (kem_dh_of_cs cs) with | DH.DH_Curve25519 -> serialize_public_key cs dh | DH.DH_P256 -> sub dh 0 32 val encap: cs:ciphersuite -> skE:key_dh_secret_s cs -> pkR:DH.serialized_point (kem_dh_of_cs cs) -> Tot (option (key_kem_s cs & key_dh_public_s cs)) #restart-solver #set-options "--z3rlimit 100 --fuel 0 --ifuel 0" let encap cs skE pkR = let _ = allow_inversion Spec.Agile.DH.algorithm in match DH.secret_to_public (kem_dh_of_cs cs) skE with | None -> None | Some pkE -> let enc = serialize_public_key cs pkE in match DH.dh (kem_dh_of_cs cs) skE pkR with | None -> None | Some dh -> let pkRm = serialize_public_key cs pkR in let kem_context = concat enc pkRm in let dhm = prepare_dh cs dh in assert (Seq.length kem_context = 2*size_dh_public cs); assert (extract_and_expand_ctx_pred cs (Seq.length kem_context)); let shared_secret:key_kem_s cs = extract_and_expand cs dhm kem_context in Some (shared_secret, enc) val decap: cs: ciphersuite -> enc: key_dh_public_s cs -> skR: key_dh_secret_s cs -> Tot (option (key_kem_s cs)) #set-options "--z3rlimit 100 --fuel 0 --ifuel 0" let decap cs enc skR = let _ = allow_inversion Spec.Agile.DH.algorithm in let _ = allow_inversion Spec.Agile.Hash.hash_alg in let pkE = deserialize_public_key cs enc in match DH.dh (kem_dh_of_cs cs) skR pkE with | None -> None | Some dh -> match DH.secret_to_public (kem_dh_of_cs cs) skR with | None -> None | Some pkR -> let pkRm = serialize_public_key cs pkR in let kem_context = concat enc pkRm in let dhm = prepare_dh cs dh in assert (Seq.length kem_context = 2*size_dh_public cs); assert (extract_and_expand_ctx_pred cs (Seq.length kem_context)); let shared_secret = extract_and_expand cs dhm kem_context in Some (shared_secret) val auth_encap: cs:ciphersuite -> skE:key_dh_secret_s cs -> pkR:DH.serialized_point (kem_dh_of_cs cs) -> skS:key_dh_secret_s cs -> Tot (option (key_kem_s cs & key_dh_public_s cs))
{ "checked_file": "/", "dependencies": [ "Spec.P256.fst.checked", "Spec.Loops.fst.checked", "Spec.Hash.Definitions.fst.checked", "Spec.Agile.HMAC.fsti.checked", "Spec.Agile.HKDF.fsti.checked", "Spec.Agile.Hash.fsti.checked", "Spec.Agile.DH.fst.checked", "Spec.Agile.AEAD.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.RawIntTypes.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Spec.Agile.HPKE.fst" }
[ { "abbrev": true, "full_module": "Spec.Agile.HKDF", "short_module": "HKDF" }, { "abbrev": true, "full_module": "Spec.Agile.Hash", "short_module": "Hash" }, { "abbrev": true, "full_module": "Spec.Agile.AEAD", "short_module": "AEAD" }, { "abbrev": true, "full_module": "Spec.Agile.DH", "short_module": "DH" }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.RawIntTypes", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Spec.Agile.HKDF", "short_module": "HKDF" }, { "abbrev": true, "full_module": "Spec.Agile.Hash", "short_module": "Hash" }, { "abbrev": true, "full_module": "Spec.Agile.AEAD", "short_module": "AEAD" }, { "abbrev": true, "full_module": "Spec.Agile.DH", "short_module": "DH" }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.RawIntTypes", "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.Agile", "short_module": null }, { "abbrev": false, "full_module": "Spec.Agile", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
cs: Spec.Agile.HPKE.ciphersuite -> skE: Spec.Agile.HPKE.key_dh_secret_s cs -> pkR: Spec.Agile.DH.serialized_point (Spec.Agile.HPKE.kem_dh_of_cs cs) -> skS: Spec.Agile.HPKE.key_dh_secret_s cs -> FStar.Pervasives.Native.option (Spec.Agile.HPKE.key_kem_s cs * Spec.Agile.HPKE.key_dh_public_s cs)
Prims.Tot
[ "total" ]
[]
[ "Spec.Agile.HPKE.ciphersuite", "Spec.Agile.HPKE.key_dh_secret_s", "Spec.Agile.DH.serialized_point", "Spec.Agile.HPKE.kem_dh_of_cs", "Spec.Agile.DH.secret_to_public", "FStar.Pervasives.Native.None", "FStar.Pervasives.Native.tuple2", "Spec.Agile.HPKE.key_kem_s", "Spec.Agile.HPKE.key_dh_public_s", "Spec.Agile.DH.dh", "FStar.Pervasives.Native.Some", "FStar.Pervasives.Native.Mktuple2", "Spec.Agile.HPKE.extract_and_expand", "Prims.unit", "Prims._assert", "Prims.b2t", "Spec.Agile.HPKE.extract_and_expand_dh_pred", "FStar.Seq.Base.length", "Lib.IntTypes.uint8", "Spec.Agile.HPKE.labeled_extract_ikm_length_pred", "Spec.Agile.HPKE.kem_hash_of_cs", "Prims.op_Addition", "Spec.Agile.HPKE.size_suite_id_kem", "Spec.Agile.HPKE.size_label_eae_prk", "Prims.op_Equality", "Prims.int", "Spec.Agile.HPKE.extract_and_expand_ctx_pred", "Lib.IntTypes.uint_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "Spec.Agile.HPKE.labeled_expand_info_length_pred", "Spec.Agile.HPKE.size_label_shared_secret", "FStar.Mul.op_Star", "Spec.Agile.HPKE.size_dh_public", "Lib.Sequence.lseq", "Lib.IntTypes.int_t", "Prims.eq2", "FStar.Seq.Base.seq", "Lib.Sequence.to_seq", "FStar.Seq.Base.append", "Lib.Sequence.concat", "Spec.Agile.HPKE.serialize_public_key", "FStar.Pervasives.Native.option", "Spec.Agile.HPKE.prepare_dh", "FStar.Pervasives.allow_inversion", "Spec.Agile.DH.algorithm" ]
[]
false
false
false
false
false
let auth_encap cs skE pkR skS =
let _ = allow_inversion Spec.Agile.DH.algorithm in match DH.secret_to_public (kem_dh_of_cs cs) skE with | None -> None | Some pkE -> match DH.dh (kem_dh_of_cs cs) skE pkR with | None -> None | Some es -> match DH.dh (kem_dh_of_cs cs) skS pkR with | None -> None | Some ss -> let esm = prepare_dh cs es in let ssm = prepare_dh cs ss in let dh = concat #uint8 #32 #32 esm ssm in let enc = serialize_public_key cs pkE in match DH.secret_to_public (kem_dh_of_cs cs) skS with | None -> None | Some pkS -> let pkSm = serialize_public_key cs pkS in let pkRm = serialize_public_key cs pkR in let kem_context = concat enc (concat pkRm pkSm) in assert (Seq.length kem_context = 3 * size_dh_public cs); assert (labeled_expand_info_length_pred (kem_hash_of_cs cs) (size_suite_id_kem + size_label_shared_secret + Seq.length kem_context)); assert (extract_and_expand_ctx_pred cs (Seq.length kem_context)); assert (Seq.length dh = 64); assert (labeled_extract_ikm_length_pred (kem_hash_of_cs cs) (size_suite_id_kem + size_label_eae_prk + Seq.length dh)); assert (extract_and_expand_dh_pred cs (Seq.length dh)); let shared_secret = extract_and_expand cs dh kem_context in Some (shared_secret, enc)
false
Steel.FractionalAnchoredPreorder.fst
Steel.FractionalAnchoredPreorder.avalue_update_value
val avalue_update_value (#v: Type) (#p: preorder v) (#s: anchor_rel p) (m: avalue s) (value: v{(curval (avalue_val m)) `p` value /\ s value value}) : m': avalue s {curval (avalue_val m') == value /\ (avalue_val m') `extends` (avalue_val m)}
val avalue_update_value (#v: Type) (#p: preorder v) (#s: anchor_rel p) (m: avalue s) (value: v{(curval (avalue_val m)) `p` value /\ s value value}) : m': avalue s {curval (avalue_val m') == value /\ (avalue_val m') `extends` (avalue_val m)}
let avalue_update_value (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) (value:v { curval (avalue_val m) `p` value /\ s value value }) : m':avalue s { curval (avalue_val m') == value /\ avalue_val m' `extends` avalue_val m } = let v = avalue_val m in avalue_update m (extend_history v value)
{ "file_name": "lib/steel/Steel.FractionalAnchoredPreorder.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 44, "end_line": 472, "start_col": 0, "start_line": 459 }
(* Copyright 2021 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. Author: N. Swamy *) module Steel.FractionalAnchoredPreorder (** This module provides a partial commutative monoid (PCM) for use in the ghost state of a concurrent Steel program. Its goal is to facilitate a form of information-sharing between multiple threads including the following features: Fractions, Preorders, Snapshots, and Anchors --- Anchors are the most unusual. 1. Fractions: Ownership of the state is controlled by a fractional permission, so multiple threads may share read-only privileges on the state, but only one can have write permission. 2. Preorders: The ghost state is governed by a preorder p and all updates to the state must respect the preorder (a reflexive, transitive relation on the state) 3. Snapshots: Since the state always evolves by a preorder, it is possible to take a snapshot of the state. A snapshot does not confer any particular ownership on the state, except knowledge of a snapshot ensures that the current state is related to the snapshot by the preorder. 4. Anchors are a kind of refinement of the preorder. If a thread owns an anchored value [v], then no other thread, even a thread owning a full fractional permission, can advance the state "too far" from the anchor. In particular, the PCM is parameterized by a binary relation on values, [anchors:anchor_relation]. If a thread owns the anchor [v], then the current value `cur` of the state must be in relation [v `anchors` cur]. This can be used to ensure that the knowledge of one thread is never becomes too stale. For example, this allows one to model a shared monotonically increasing counter, where if one thread anchors knowledge of the counter at the value 5, no other thread can increase the value of the counter beyond, say, 10, (when the anchor relation is y - x <= 5), until the anchoring thread releases the anchor. Further, at any point, a thread can take a snapshot of the counter and rely on the fact that the value of the counter in the future will be >= the snapshot. *) open FStar.PCM open FStar.Preorder open Steel.Preorder open Steel.FractionalPermission #push-options "--fuel 0 --ifuel 2" /// A permission: is a pair of /// /// * an optional fractional permission; with `Some p` indicating /// some ownership, while `None` is an additional "0" permission /// value, to encode snapshots. /// /// * and an optional anchor, where `Some a` indicates the current /// value can't be too far from `a`. let permission (v:Type) = option perm & option v /// Non-zero permission is either a read or write permission let has_nonzero #v (p:permission v) = Some? (fst p) /// Has an anchor set let has_anchor #v (p:permission v) = Some? (snd p) /// Either an anchor or non-zero let has_some_ownership #v (p:permission v) = has_nonzero p || has_anchor p /// The anchoring value let anchor_of #v (p:permission v { has_anchor p }) : v = Some?.v (snd p) /// The anchoring relation: /// -- A binary relation on values /// -- refining the preorder /// -- and if x `anchors` z then it also anchors any `y` between `x` and `z` /// /// Explaining the third clause a bit: /// Think intuitively of anchoring relations as a kind of distance measure /// /// if `z` is close enough to `x` then if `z` is further than `y` /// (since it is ahead of `y` in the preorder) then `y` is also /// close enough to `x` let anchor_rel (#v:Type) (p:preorder v) = anchors:(v -> v -> prop) { (forall v0 v1. anchors v0 v1 ==> p v0 v1) /\ (forall x z. x `anchors` z ==> (forall y. p x y /\ p y z ==> x `anchors` y)) // } /// An implementation remark: We use Steel.Preorder here to /// generically transform any preorder into a PCM. That works by /// taking the value of the PCM to be a history of values related by /// the preorder. So, throughout, we'll be using the the [vhist p] /// from Steel.Preorder, the type of a non-empty history compatible /// with [p]. The details of the histories don't matter much for our /// purposes---we only care about the most recent value, for which /// we'll use [curval v]. /// If the anchor is set, then the current value is anchored by it let anchored (#v:Type) (#p:preorder v) (anchors:anchor_rel p) (pv:(permission v & vhist p)) = has_anchor (fst pv) ==> anchor_of (fst pv) `anchors` curval (snd pv) /// A value in our fractional anchored PCM is a pair of a permission /// and a p-compatible history, refined to ensure that if the anchor /// is set, then the current value is anchored by it. let avalue (#v:Type) (#p:preorder v) (anchors:anchor_rel p) = pv:(permission v & vhist p) { anchored anchors pv } /// initial_value: A utility to construct a value in the PCM #push-options "--fuel 1" let initial_value (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (value:v { anchors value value }) : avalue anchors = (Some full_perm, Some value), [value] #pop-options /// We add a unit element to [avalue], as needed for a PCM [@@erasable] noeq type knowledge (#v:Type) (#p:preorder v) (anchors:anchor_rel p) = | Owns : avalue anchors -> knowledge anchors | Nothing : knowledge anchors let b2p (b:bool) : prop = b == true /// Fractional permissions are composable when their sum <= 1.0 let perm_opt_composable (p0 p1:option perm) : prop = match p0, p1 with | None, None -> True | Some p, None | None, Some p -> b2p (p `lesser_equal_perm` full_perm) | Some p0, Some p1 -> b2p (sum_perm p0 p1 `lesser_equal_perm` full_perm) /// Composing them sums the permissions let compose_perm_opt (p0 p1:option perm) = match p0, p1 with | None, p | p, None -> p | Some p0, Some p1 -> Some (sum_perm p0 p1) /// Anchored permissions are composable when at most one of them has the anchor set let permission_composable #v (p0 p1 : permission v) : prop = let q0, s0 = p0 in let q1, s1 = p1 in perm_opt_composable q0 q1 /\ // some of fracs can't exceed 1 not (Some? s0 && Some? s1) // at most one can have an anchor /// Compose permissions component wise, keeping the anchor if set let compose_permissions (#v:_) (p0:permission v) (p1:permission v{permission_composable p0 p1}) : permission v = compose_perm_opt (fst p0) (fst p1), (match snd p0, snd p1 with | None, a | a, None -> a) /// This is the central definition of the PCM --- defining when two /// values are composable, or equivalently, when one thread's /// knowledge of [av0] is compatible with another thread's knowledge /// of [av1] /// /// This definition shows the interplay between fractions and anchors. /// It wasn't obvious to me how to factor this further, e.g., adding /// anchors to preorders and then separately adding fractions to it. let avalue_composable (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (av0 av1: avalue anchors) : prop = let (p0, v0) = av0 in let (p1, v1) = av1 in permission_composable p0 p1 /\ (if not (has_some_ownership p0) && not (has_some_ownership p1) then p_composable _ v0 v1 //neither has ownership, one history is older than the other else if not (has_some_ownership p0) && has_some_ownership p1 then ( if has_nonzero p1 then v1 `extends` v0 //the one with ownership is more recent else ( //this part is the most subtle assert (has_anchor p1); p_composable _ v0 v1 /\ (v0 `extends` v1 ==> //if v0 is a more recent snapshot than v1 //then v0 must still be anchored by v1's anchor anchor_of p1 `anchors` curval v0) ) ) else if has_some_ownership p0 && not (has_some_ownership p1) then ( //symmetric if has_nonzero p0 then v0 `extends` v1 else ( assert (has_anchor p0); p_composable _ v0 v1 /\ (v1 `extends` v0 ==> anchor_of p0 `anchors` curval v1) ) ) else ( assert (has_some_ownership p0 && has_some_ownership p1); if has_nonzero p0 && has_nonzero p1 then v0 == v1 //if both have non-zero perm, then they must both only have read permission and must agree on the value else if has_nonzero p0 && has_anchor p1 then ( assert (not (has_nonzero p1)); //The key part of the anchor semantics: v0 `extends` v1 /\ //v0 has advanceable ownership, so extends anchor_of p1 `anchors` curval v0 //but not beyond what is allowed by s ) else if has_anchor p0 && has_nonzero p1 //symmetric then ( assert (not (has_nonzero p0)); v1 `extends` v0 /\ anchor_of p0 `anchors` curval v1 //v1 extends, but not beyond what is allowed by s ) else (assert false; False) ) ) //exhaustive /// Lifting avalue comosability to knowledge, including the unit let composable #v (#p:preorder v) (#a:anchor_rel p) : symrel (knowledge a) = fun (k0 k1:knowledge a) -> match k0, k1 with | Nothing, _ | _, Nothing -> True | Owns m, Owns m' -> avalue_composable m m' /// Compose avalues by composing permissions and composing the values /// using the underlying preorder PCM let compose_avalue (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (m0:avalue anchors) (m1:avalue anchors { avalue_composable m0 m1 } ) : avalue anchors = let p0, v0 = m0 in let p1, v1 = m1 in let p12 = compose_permissions p0 p1 in let v12 = p_op _ v0 v1 in p12, v12 //////////////////////////////////////////////////////////////////////////////// (** avalue composition is associative and commutative **) let compose_avalue_comm (#v:Type) (#p:preorder v) (#anc:anchor_rel p) (m0: avalue anc) (m1: avalue anc{ avalue_composable m0 m1 }) : Lemma (compose_avalue m0 m1 == compose_avalue m1 m0) = () let avalue_composable_assoc_l (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (m0: avalue anchors) (m1: avalue anchors) (m2: avalue anchors { avalue_composable m1 m2 /\ avalue_composable m0 (compose_avalue m1 m2) }) : Lemma (avalue_composable m0 m1 /\ avalue_composable (compose_avalue m0 m1) m2) = () let compose_avalue_assoc_l (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m0: avalue s) (m1: avalue s) (m2: avalue s { avalue_composable m1 m2 /\ avalue_composable m0 (compose_avalue m1 m2) }) : Lemma (avalue_composable m0 m1 /\ avalue_composable (compose_avalue m0 m1) m2 /\ compose_avalue m0 (compose_avalue m1 m2) == compose_avalue (compose_avalue m0 m1) m2) = avalue_composable_assoc_l m0 m1 m2 let avalue_composable_assoc_r (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (m0: avalue anchors) (m1: avalue anchors) (m2: avalue anchors { avalue_composable m0 m1 /\ avalue_composable (compose_avalue m0 m1) m2 }) : Lemma (avalue_composable m1 m2 /\ avalue_composable m0 (compose_avalue m1 m2)) = () let compose_avalue_assoc_r (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m0: avalue s) (m1: avalue s) (m2: avalue s{ avalue_composable m0 m1 /\ avalue_composable (compose_avalue m0 m1) m2 }) : Lemma (avalue_composable m1 m2 /\ avalue_composable m0 (compose_avalue m1 m2) /\ compose_avalue m0 (compose_avalue m1 m2) == compose_avalue (compose_avalue m0 m1) m2) = avalue_composable_assoc_r m0 m1 m2 //////////////////////////////////////////////////////////////////////////////// /// lifting avalue composition to knowledge, including unit let compose (#v:Type) (#p:preorder v) (#s:anchor_rel p) (k0:knowledge s) (k1:knowledge s{ composable k0 k1 }) : knowledge s = match k0, k1 with | Nothing, k | k, Nothing -> k | Owns m, Owns m' -> Owns (compose_avalue m m') let composable_assoc_r #v (#p:preorder v) (#s:anchor_rel p) (k0 k1 k2: knowledge s) : Lemma (requires composable k0 k1 /\ composable (compose k0 k1) k2) (ensures composable k1 k2 /\ composable k0 (compose k1 k2) /\ compose k0 (compose k1 k2) == compose (compose k0 k1) k2 ) = match k0, k1, k2 with | Nothing, _, _ | _, Nothing, _ | _, _, Nothing -> () | Owns m0, Owns m1, Owns m2 -> compose_avalue_assoc_r m0 m1 m2 let composable_assoc_l #v (#p:preorder v) (#s:anchor_rel p) (k0 k1 k2: knowledge s) : Lemma (requires composable k1 k2 /\ composable k0 (compose k1 k2)) (ensures composable k0 k1 /\ composable (compose k0 k1) k2 /\ compose k0 (compose k1 k2) == compose (compose k0 k1) k2) = match k0, k1, k2 with | Nothing, _, _ | _, Nothing, _ | _, _, Nothing -> () | Owns m0, Owns m1, Owns m2 -> compose_avalue_assoc_l m0 m1 m2 /// Now, we can define our PCM /// The core of the PCM let p0 #v #p #s : pcm' (knowledge #v #p s) = { composable; op=compose; one=Nothing } let avalue_perm (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) = fst m /// A avalue represents full ownership when the fraction is full AND /// the anchor is set. This means that no knowledge held by any other /// thread can constrain this value meaningfully. let avalue_owns (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) : prop = fst (avalue_perm m) == Some full_perm /\ Some? (snd (avalue_perm m)) let full_knowledge #v #p #s (kn:knowledge #v #p s) : prop = match kn with | Nothing -> False | Owns km -> avalue_owns km /// The PCM itself, together with proofs of its properties let pcm #v #p #s : pcm (knowledge #v #p s) = { p = p0; comm = (fun k0 k1 -> match k0, k1 with | Nothing, _ | _, Nothing -> () | Owns m0, Owns m1 -> compose_avalue_comm m0 m1); assoc = (fun k0 k1 k2 -> composable_assoc_l k0 k1 k2); assoc_r = (fun k0 k1 k2 -> composable_assoc_r k0 k1 k2); is_unit = (fun _ -> ()); refine = full_knowledge; } /// Some utilities: The value of an avalue let avalue_val (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue #v #p s) = snd m /// Updating the value, in a full-ownership situation, also involves /// updating the anchor let avalue_update (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) (value:vhist p { s (curval value) (curval value) }) : avalue s = let p, _ = avalue_perm m in let p' = p, Some (curval value) in (p', value) /// Our core frame-preserving update: /// /// If you fully own a value, you can update it so long as you /// respect the preorder, and prove that the new value is related /// to itself by the anchor (since we'll be setting the anchor to /// the new value) /// /// This is a building block: we'll define a derived version that /// on values rather than histories #push-options "--z3rlimit_factor 2" let update_hist (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) (v1:vhist p { avalue_owns m /\ v1 `extends` avalue_val m /\ s (curval v1) (curval v1) }) : frame_preserving_upd pcm (Owns m) (Owns (avalue_update m v1)) = fun full_v -> let Owns full_m = full_v in let m_res = avalue_update full_m v1 in Owns m_res #pop-options
{ "checked_file": "/", "dependencies": [ "Steel.Preorder.fst.checked", "Steel.FractionalPermission.fst.checked", "prims.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked" ], "interface_file": false, "source_file": "Steel.FractionalAnchoredPreorder.fst" }
[ { "abbrev": false, "full_module": "Steel.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Steel.Preorder", "short_module": null }, { "abbrev": false, "full_module": "FStar.Preorder", "short_module": null }, { "abbrev": false, "full_module": "FStar.PCM", "short_module": null }, { "abbrev": false, "full_module": "Steel", "short_module": null }, { "abbrev": false, "full_module": "Steel", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
m: Steel.FractionalAnchoredPreorder.avalue s -> value: v { p (Steel.Preorder.curval (Steel.FractionalAnchoredPreorder.avalue_val m)) value /\ s value value } -> m': Steel.FractionalAnchoredPreorder.avalue s { Steel.Preorder.curval (Steel.FractionalAnchoredPreorder.avalue_val m') == value /\ Steel.Preorder.extends (Steel.FractionalAnchoredPreorder.avalue_val m') (Steel.FractionalAnchoredPreorder.avalue_val m) }
Prims.Tot
[ "total" ]
[]
[ "FStar.Preorder.preorder", "Steel.FractionalAnchoredPreorder.anchor_rel", "Steel.FractionalAnchoredPreorder.avalue", "Prims.l_and", "Steel.Preorder.curval", "Steel.FractionalAnchoredPreorder.avalue_val", "Steel.FractionalAnchoredPreorder.avalue_update", "Steel.Preorder.extend_history", "Steel.Preorder.vhist", "Prims.eq2", "Steel.Preorder.extends" ]
[]
false
false
false
false
false
let avalue_update_value (#v: Type) (#p: preorder v) (#s: anchor_rel p) (m: avalue s) (value: v{(curval (avalue_val m)) `p` value /\ s value value}) : m': avalue s {curval (avalue_val m') == value /\ (avalue_val m') `extends` (avalue_val m)} =
let v = avalue_val m in avalue_update m (extend_history v value)
false
Steel.FractionalAnchoredPreorder.fst
Steel.FractionalAnchoredPreorder.perm_ok
val perm_ok : a: Steel.FractionalAnchoredPreorder.avalue s -> Prims.prop
let perm_ok #v #p #s (a:avalue #v #p s) = perm_opt_composable (fst (avalue_perm a)) None
{ "file_name": "lib/steel/Steel.FractionalAnchoredPreorder.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 50, "end_line": 575, "start_col": 0, "start_line": 574 }
(* Copyright 2021 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. Author: N. Swamy *) module Steel.FractionalAnchoredPreorder (** This module provides a partial commutative monoid (PCM) for use in the ghost state of a concurrent Steel program. Its goal is to facilitate a form of information-sharing between multiple threads including the following features: Fractions, Preorders, Snapshots, and Anchors --- Anchors are the most unusual. 1. Fractions: Ownership of the state is controlled by a fractional permission, so multiple threads may share read-only privileges on the state, but only one can have write permission. 2. Preorders: The ghost state is governed by a preorder p and all updates to the state must respect the preorder (a reflexive, transitive relation on the state) 3. Snapshots: Since the state always evolves by a preorder, it is possible to take a snapshot of the state. A snapshot does not confer any particular ownership on the state, except knowledge of a snapshot ensures that the current state is related to the snapshot by the preorder. 4. Anchors are a kind of refinement of the preorder. If a thread owns an anchored value [v], then no other thread, even a thread owning a full fractional permission, can advance the state "too far" from the anchor. In particular, the PCM is parameterized by a binary relation on values, [anchors:anchor_relation]. If a thread owns the anchor [v], then the current value `cur` of the state must be in relation [v `anchors` cur]. This can be used to ensure that the knowledge of one thread is never becomes too stale. For example, this allows one to model a shared monotonically increasing counter, where if one thread anchors knowledge of the counter at the value 5, no other thread can increase the value of the counter beyond, say, 10, (when the anchor relation is y - x <= 5), until the anchoring thread releases the anchor. Further, at any point, a thread can take a snapshot of the counter and rely on the fact that the value of the counter in the future will be >= the snapshot. *) open FStar.PCM open FStar.Preorder open Steel.Preorder open Steel.FractionalPermission #push-options "--fuel 0 --ifuel 2" /// A permission: is a pair of /// /// * an optional fractional permission; with `Some p` indicating /// some ownership, while `None` is an additional "0" permission /// value, to encode snapshots. /// /// * and an optional anchor, where `Some a` indicates the current /// value can't be too far from `a`. let permission (v:Type) = option perm & option v /// Non-zero permission is either a read or write permission let has_nonzero #v (p:permission v) = Some? (fst p) /// Has an anchor set let has_anchor #v (p:permission v) = Some? (snd p) /// Either an anchor or non-zero let has_some_ownership #v (p:permission v) = has_nonzero p || has_anchor p /// The anchoring value let anchor_of #v (p:permission v { has_anchor p }) : v = Some?.v (snd p) /// The anchoring relation: /// -- A binary relation on values /// -- refining the preorder /// -- and if x `anchors` z then it also anchors any `y` between `x` and `z` /// /// Explaining the third clause a bit: /// Think intuitively of anchoring relations as a kind of distance measure /// /// if `z` is close enough to `x` then if `z` is further than `y` /// (since it is ahead of `y` in the preorder) then `y` is also /// close enough to `x` let anchor_rel (#v:Type) (p:preorder v) = anchors:(v -> v -> prop) { (forall v0 v1. anchors v0 v1 ==> p v0 v1) /\ (forall x z. x `anchors` z ==> (forall y. p x y /\ p y z ==> x `anchors` y)) // } /// An implementation remark: We use Steel.Preorder here to /// generically transform any preorder into a PCM. That works by /// taking the value of the PCM to be a history of values related by /// the preorder. So, throughout, we'll be using the the [vhist p] /// from Steel.Preorder, the type of a non-empty history compatible /// with [p]. The details of the histories don't matter much for our /// purposes---we only care about the most recent value, for which /// we'll use [curval v]. /// If the anchor is set, then the current value is anchored by it let anchored (#v:Type) (#p:preorder v) (anchors:anchor_rel p) (pv:(permission v & vhist p)) = has_anchor (fst pv) ==> anchor_of (fst pv) `anchors` curval (snd pv) /// A value in our fractional anchored PCM is a pair of a permission /// and a p-compatible history, refined to ensure that if the anchor /// is set, then the current value is anchored by it. let avalue (#v:Type) (#p:preorder v) (anchors:anchor_rel p) = pv:(permission v & vhist p) { anchored anchors pv } /// initial_value: A utility to construct a value in the PCM #push-options "--fuel 1" let initial_value (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (value:v { anchors value value }) : avalue anchors = (Some full_perm, Some value), [value] #pop-options /// We add a unit element to [avalue], as needed for a PCM [@@erasable] noeq type knowledge (#v:Type) (#p:preorder v) (anchors:anchor_rel p) = | Owns : avalue anchors -> knowledge anchors | Nothing : knowledge anchors let b2p (b:bool) : prop = b == true /// Fractional permissions are composable when their sum <= 1.0 let perm_opt_composable (p0 p1:option perm) : prop = match p0, p1 with | None, None -> True | Some p, None | None, Some p -> b2p (p `lesser_equal_perm` full_perm) | Some p0, Some p1 -> b2p (sum_perm p0 p1 `lesser_equal_perm` full_perm) /// Composing them sums the permissions let compose_perm_opt (p0 p1:option perm) = match p0, p1 with | None, p | p, None -> p | Some p0, Some p1 -> Some (sum_perm p0 p1) /// Anchored permissions are composable when at most one of them has the anchor set let permission_composable #v (p0 p1 : permission v) : prop = let q0, s0 = p0 in let q1, s1 = p1 in perm_opt_composable q0 q1 /\ // some of fracs can't exceed 1 not (Some? s0 && Some? s1) // at most one can have an anchor /// Compose permissions component wise, keeping the anchor if set let compose_permissions (#v:_) (p0:permission v) (p1:permission v{permission_composable p0 p1}) : permission v = compose_perm_opt (fst p0) (fst p1), (match snd p0, snd p1 with | None, a | a, None -> a) /// This is the central definition of the PCM --- defining when two /// values are composable, or equivalently, when one thread's /// knowledge of [av0] is compatible with another thread's knowledge /// of [av1] /// /// This definition shows the interplay between fractions and anchors. /// It wasn't obvious to me how to factor this further, e.g., adding /// anchors to preorders and then separately adding fractions to it. let avalue_composable (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (av0 av1: avalue anchors) : prop = let (p0, v0) = av0 in let (p1, v1) = av1 in permission_composable p0 p1 /\ (if not (has_some_ownership p0) && not (has_some_ownership p1) then p_composable _ v0 v1 //neither has ownership, one history is older than the other else if not (has_some_ownership p0) && has_some_ownership p1 then ( if has_nonzero p1 then v1 `extends` v0 //the one with ownership is more recent else ( //this part is the most subtle assert (has_anchor p1); p_composable _ v0 v1 /\ (v0 `extends` v1 ==> //if v0 is a more recent snapshot than v1 //then v0 must still be anchored by v1's anchor anchor_of p1 `anchors` curval v0) ) ) else if has_some_ownership p0 && not (has_some_ownership p1) then ( //symmetric if has_nonzero p0 then v0 `extends` v1 else ( assert (has_anchor p0); p_composable _ v0 v1 /\ (v1 `extends` v0 ==> anchor_of p0 `anchors` curval v1) ) ) else ( assert (has_some_ownership p0 && has_some_ownership p1); if has_nonzero p0 && has_nonzero p1 then v0 == v1 //if both have non-zero perm, then they must both only have read permission and must agree on the value else if has_nonzero p0 && has_anchor p1 then ( assert (not (has_nonzero p1)); //The key part of the anchor semantics: v0 `extends` v1 /\ //v0 has advanceable ownership, so extends anchor_of p1 `anchors` curval v0 //but not beyond what is allowed by s ) else if has_anchor p0 && has_nonzero p1 //symmetric then ( assert (not (has_nonzero p0)); v1 `extends` v0 /\ anchor_of p0 `anchors` curval v1 //v1 extends, but not beyond what is allowed by s ) else (assert false; False) ) ) //exhaustive /// Lifting avalue comosability to knowledge, including the unit let composable #v (#p:preorder v) (#a:anchor_rel p) : symrel (knowledge a) = fun (k0 k1:knowledge a) -> match k0, k1 with | Nothing, _ | _, Nothing -> True | Owns m, Owns m' -> avalue_composable m m' /// Compose avalues by composing permissions and composing the values /// using the underlying preorder PCM let compose_avalue (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (m0:avalue anchors) (m1:avalue anchors { avalue_composable m0 m1 } ) : avalue anchors = let p0, v0 = m0 in let p1, v1 = m1 in let p12 = compose_permissions p0 p1 in let v12 = p_op _ v0 v1 in p12, v12 //////////////////////////////////////////////////////////////////////////////// (** avalue composition is associative and commutative **) let compose_avalue_comm (#v:Type) (#p:preorder v) (#anc:anchor_rel p) (m0: avalue anc) (m1: avalue anc{ avalue_composable m0 m1 }) : Lemma (compose_avalue m0 m1 == compose_avalue m1 m0) = () let avalue_composable_assoc_l (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (m0: avalue anchors) (m1: avalue anchors) (m2: avalue anchors { avalue_composable m1 m2 /\ avalue_composable m0 (compose_avalue m1 m2) }) : Lemma (avalue_composable m0 m1 /\ avalue_composable (compose_avalue m0 m1) m2) = () let compose_avalue_assoc_l (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m0: avalue s) (m1: avalue s) (m2: avalue s { avalue_composable m1 m2 /\ avalue_composable m0 (compose_avalue m1 m2) }) : Lemma (avalue_composable m0 m1 /\ avalue_composable (compose_avalue m0 m1) m2 /\ compose_avalue m0 (compose_avalue m1 m2) == compose_avalue (compose_avalue m0 m1) m2) = avalue_composable_assoc_l m0 m1 m2 let avalue_composable_assoc_r (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (m0: avalue anchors) (m1: avalue anchors) (m2: avalue anchors { avalue_composable m0 m1 /\ avalue_composable (compose_avalue m0 m1) m2 }) : Lemma (avalue_composable m1 m2 /\ avalue_composable m0 (compose_avalue m1 m2)) = () let compose_avalue_assoc_r (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m0: avalue s) (m1: avalue s) (m2: avalue s{ avalue_composable m0 m1 /\ avalue_composable (compose_avalue m0 m1) m2 }) : Lemma (avalue_composable m1 m2 /\ avalue_composable m0 (compose_avalue m1 m2) /\ compose_avalue m0 (compose_avalue m1 m2) == compose_avalue (compose_avalue m0 m1) m2) = avalue_composable_assoc_r m0 m1 m2 //////////////////////////////////////////////////////////////////////////////// /// lifting avalue composition to knowledge, including unit let compose (#v:Type) (#p:preorder v) (#s:anchor_rel p) (k0:knowledge s) (k1:knowledge s{ composable k0 k1 }) : knowledge s = match k0, k1 with | Nothing, k | k, Nothing -> k | Owns m, Owns m' -> Owns (compose_avalue m m') let composable_assoc_r #v (#p:preorder v) (#s:anchor_rel p) (k0 k1 k2: knowledge s) : Lemma (requires composable k0 k1 /\ composable (compose k0 k1) k2) (ensures composable k1 k2 /\ composable k0 (compose k1 k2) /\ compose k0 (compose k1 k2) == compose (compose k0 k1) k2 ) = match k0, k1, k2 with | Nothing, _, _ | _, Nothing, _ | _, _, Nothing -> () | Owns m0, Owns m1, Owns m2 -> compose_avalue_assoc_r m0 m1 m2 let composable_assoc_l #v (#p:preorder v) (#s:anchor_rel p) (k0 k1 k2: knowledge s) : Lemma (requires composable k1 k2 /\ composable k0 (compose k1 k2)) (ensures composable k0 k1 /\ composable (compose k0 k1) k2 /\ compose k0 (compose k1 k2) == compose (compose k0 k1) k2) = match k0, k1, k2 with | Nothing, _, _ | _, Nothing, _ | _, _, Nothing -> () | Owns m0, Owns m1, Owns m2 -> compose_avalue_assoc_l m0 m1 m2 /// Now, we can define our PCM /// The core of the PCM let p0 #v #p #s : pcm' (knowledge #v #p s) = { composable; op=compose; one=Nothing } let avalue_perm (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) = fst m /// A avalue represents full ownership when the fraction is full AND /// the anchor is set. This means that no knowledge held by any other /// thread can constrain this value meaningfully. let avalue_owns (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) : prop = fst (avalue_perm m) == Some full_perm /\ Some? (snd (avalue_perm m)) let full_knowledge #v #p #s (kn:knowledge #v #p s) : prop = match kn with | Nothing -> False | Owns km -> avalue_owns km /// The PCM itself, together with proofs of its properties let pcm #v #p #s : pcm (knowledge #v #p s) = { p = p0; comm = (fun k0 k1 -> match k0, k1 with | Nothing, _ | _, Nothing -> () | Owns m0, Owns m1 -> compose_avalue_comm m0 m1); assoc = (fun k0 k1 k2 -> composable_assoc_l k0 k1 k2); assoc_r = (fun k0 k1 k2 -> composable_assoc_r k0 k1 k2); is_unit = (fun _ -> ()); refine = full_knowledge; } /// Some utilities: The value of an avalue let avalue_val (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue #v #p s) = snd m /// Updating the value, in a full-ownership situation, also involves /// updating the anchor let avalue_update (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) (value:vhist p { s (curval value) (curval value) }) : avalue s = let p, _ = avalue_perm m in let p' = p, Some (curval value) in (p', value) /// Our core frame-preserving update: /// /// If you fully own a value, you can update it so long as you /// respect the preorder, and prove that the new value is related /// to itself by the anchor (since we'll be setting the anchor to /// the new value) /// /// This is a building block: we'll define a derived version that /// on values rather than histories #push-options "--z3rlimit_factor 2" let update_hist (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) (v1:vhist p { avalue_owns m /\ v1 `extends` avalue_val m /\ s (curval v1) (curval v1) }) : frame_preserving_upd pcm (Owns m) (Owns (avalue_update m v1)) = fun full_v -> let Owns full_m = full_v in let m_res = avalue_update full_m v1 in Owns m_res #pop-options /// Updating with value, rather than a history let avalue_update_value (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) (value:v { curval (avalue_val m) `p` value /\ s value value }) : m':avalue s { curval (avalue_val m') == value /\ avalue_val m' `extends` avalue_val m } = let v = avalue_val m in avalue_update m (extend_history v value) /// A derived frame-preserving update for which one presents only a value let update_value (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) (v1:v { avalue_owns m /\ //if you have full ownership of key curval (avalue_val m) `p` v1 /\ //you can update it wrt the preorder only s v1 v1 //and it is related to itself by the anchor }) : frame_preserving_upd pcm (Owns m) (Owns (avalue_update_value m v1)) = coerce_eq () (update_hist m (extend_history (avalue_val m) v1)) //F* goes nuts and starts swallowing gobs of memory without the coerce_eq: TODO, debug /// Now for anchored updates /// Ownership of the whole fraction, but not the anchor let avalue_owns_anchored (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) = fst (avalue_perm m) == Some full_perm /\ None? (snd (avalue_perm m)) /// [v1] is compatible with (i.e., not too far from) any anchor of [v0] let compat_with_any_anchor_of (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (v1:v) (v0:avalue anchors) = forall (anchor:v). anchor `anchors` curval (avalue_val v0) ==> anchor `anchors` v1 /// An anchored update: Update the value, but leave the permission /// unchanged Only possible if the new value is compatible with any /// anchor of the old value let avalue_anchored_update (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) (value:vhist p { curval value `compat_with_any_anchor_of` m }) : avalue s = avalue_perm m, value /// A frame-preserving update for anchored values. /// Notice the additional precondition, refining the preorder let update_anchored_hist (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) (v1:vhist p { avalue_owns_anchored m /\ v1 `extends` avalue_val m /\ curval v1 `compat_with_any_anchor_of` m }) : frame_preserving_upd pcm (Owns m) (Owns (avalue_anchored_update m v1)) = fun full_v -> let Owns full_m = full_v in let m_res = avalue_anchored_update full_m v1 in Owns m_res /// A derived form without a history on the new value let avalue_update_anchored_value (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) (value:v { curval (avalue_val m) `p` value /\ value `compat_with_any_anchor_of` m }) : m':avalue s { curval (avalue_val m') == value /\ avalue_val m' `extends` avalue_val m } = let v = avalue_val m in avalue_anchored_update m (extend_history v value) /// Derived frame-preserving update let update_anchored_value (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) (v1:v { avalue_owns_anchored m /\ //if you own an anchored key, you can update if you respect curval (avalue_val m) `p` v1 /\ //the preorder v1 `compat_with_any_anchor_of` m //and respect any anchor of the current value }) : frame_preserving_upd pcm (Owns m) (Owns (avalue_update_anchored_value m v1)) = coerce_eq () (update_anchored_hist m (extend_history (avalue_val m) v1)) //////////////////////////////////////////////////////////////////////////////// /// Now for some lemmas about which kinds of knowledge are compatible /// with others and about snapshots /// A [snapshot] keeps the value, dropping all permissions let snapshot (#v:Type0) (#p:preorder v) (#s:anchor_rel p) (a: avalue s) : avalue s = (None, None), avalue_val a
{ "checked_file": "/", "dependencies": [ "Steel.Preorder.fst.checked", "Steel.FractionalPermission.fst.checked", "prims.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked" ], "interface_file": false, "source_file": "Steel.FractionalAnchoredPreorder.fst" }
[ { "abbrev": false, "full_module": "Steel.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Steel.Preorder", "short_module": null }, { "abbrev": false, "full_module": "FStar.Preorder", "short_module": null }, { "abbrev": false, "full_module": "FStar.PCM", "short_module": null }, { "abbrev": false, "full_module": "Steel", "short_module": null }, { "abbrev": false, "full_module": "Steel", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Steel.FractionalAnchoredPreorder.avalue s -> Prims.prop
Prims.Tot
[ "total" ]
[]
[ "FStar.Preorder.preorder", "Steel.FractionalAnchoredPreorder.anchor_rel", "Steel.FractionalAnchoredPreorder.avalue", "Steel.FractionalAnchoredPreorder.perm_opt_composable", "FStar.Pervasives.Native.fst", "FStar.Pervasives.Native.option", "Steel.FractionalPermission.perm", "Steel.FractionalAnchoredPreorder.avalue_perm", "FStar.Pervasives.Native.None", "Prims.prop" ]
[]
false
false
false
false
true
let perm_ok #v #p #s (a: avalue #v #p s) =
perm_opt_composable (fst (avalue_perm a)) None
false
Steel.FractionalAnchoredPreorder.fst
Steel.FractionalAnchoredPreorder.pcm
val pcm (#v #p #s: _) : pcm (knowledge #v #p s)
val pcm (#v #p #s: _) : pcm (knowledge #v #p s)
let pcm #v #p #s : pcm (knowledge #v #p s) = { p = p0; comm = (fun k0 k1 -> match k0, k1 with | Nothing, _ | _, Nothing -> () | Owns m0, Owns m1 -> compose_avalue_comm m0 m1); assoc = (fun k0 k1 k2 -> composable_assoc_l k0 k1 k2); assoc_r = (fun k0 k1 k2 -> composable_assoc_r k0 k1 k2); is_unit = (fun _ -> ()); refine = full_knowledge; }
{ "file_name": "lib/steel/Steel.FractionalAnchoredPreorder.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 1, "end_line": 411, "start_col": 0, "start_line": 399 }
(* Copyright 2021 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. Author: N. Swamy *) module Steel.FractionalAnchoredPreorder (** This module provides a partial commutative monoid (PCM) for use in the ghost state of a concurrent Steel program. Its goal is to facilitate a form of information-sharing between multiple threads including the following features: Fractions, Preorders, Snapshots, and Anchors --- Anchors are the most unusual. 1. Fractions: Ownership of the state is controlled by a fractional permission, so multiple threads may share read-only privileges on the state, but only one can have write permission. 2. Preorders: The ghost state is governed by a preorder p and all updates to the state must respect the preorder (a reflexive, transitive relation on the state) 3. Snapshots: Since the state always evolves by a preorder, it is possible to take a snapshot of the state. A snapshot does not confer any particular ownership on the state, except knowledge of a snapshot ensures that the current state is related to the snapshot by the preorder. 4. Anchors are a kind of refinement of the preorder. If a thread owns an anchored value [v], then no other thread, even a thread owning a full fractional permission, can advance the state "too far" from the anchor. In particular, the PCM is parameterized by a binary relation on values, [anchors:anchor_relation]. If a thread owns the anchor [v], then the current value `cur` of the state must be in relation [v `anchors` cur]. This can be used to ensure that the knowledge of one thread is never becomes too stale. For example, this allows one to model a shared monotonically increasing counter, where if one thread anchors knowledge of the counter at the value 5, no other thread can increase the value of the counter beyond, say, 10, (when the anchor relation is y - x <= 5), until the anchoring thread releases the anchor. Further, at any point, a thread can take a snapshot of the counter and rely on the fact that the value of the counter in the future will be >= the snapshot. *) open FStar.PCM open FStar.Preorder open Steel.Preorder open Steel.FractionalPermission #push-options "--fuel 0 --ifuel 2" /// A permission: is a pair of /// /// * an optional fractional permission; with `Some p` indicating /// some ownership, while `None` is an additional "0" permission /// value, to encode snapshots. /// /// * and an optional anchor, where `Some a` indicates the current /// value can't be too far from `a`. let permission (v:Type) = option perm & option v /// Non-zero permission is either a read or write permission let has_nonzero #v (p:permission v) = Some? (fst p) /// Has an anchor set let has_anchor #v (p:permission v) = Some? (snd p) /// Either an anchor or non-zero let has_some_ownership #v (p:permission v) = has_nonzero p || has_anchor p /// The anchoring value let anchor_of #v (p:permission v { has_anchor p }) : v = Some?.v (snd p) /// The anchoring relation: /// -- A binary relation on values /// -- refining the preorder /// -- and if x `anchors` z then it also anchors any `y` between `x` and `z` /// /// Explaining the third clause a bit: /// Think intuitively of anchoring relations as a kind of distance measure /// /// if `z` is close enough to `x` then if `z` is further than `y` /// (since it is ahead of `y` in the preorder) then `y` is also /// close enough to `x` let anchor_rel (#v:Type) (p:preorder v) = anchors:(v -> v -> prop) { (forall v0 v1. anchors v0 v1 ==> p v0 v1) /\ (forall x z. x `anchors` z ==> (forall y. p x y /\ p y z ==> x `anchors` y)) // } /// An implementation remark: We use Steel.Preorder here to /// generically transform any preorder into a PCM. That works by /// taking the value of the PCM to be a history of values related by /// the preorder. So, throughout, we'll be using the the [vhist p] /// from Steel.Preorder, the type of a non-empty history compatible /// with [p]. The details of the histories don't matter much for our /// purposes---we only care about the most recent value, for which /// we'll use [curval v]. /// If the anchor is set, then the current value is anchored by it let anchored (#v:Type) (#p:preorder v) (anchors:anchor_rel p) (pv:(permission v & vhist p)) = has_anchor (fst pv) ==> anchor_of (fst pv) `anchors` curval (snd pv) /// A value in our fractional anchored PCM is a pair of a permission /// and a p-compatible history, refined to ensure that if the anchor /// is set, then the current value is anchored by it. let avalue (#v:Type) (#p:preorder v) (anchors:anchor_rel p) = pv:(permission v & vhist p) { anchored anchors pv } /// initial_value: A utility to construct a value in the PCM #push-options "--fuel 1" let initial_value (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (value:v { anchors value value }) : avalue anchors = (Some full_perm, Some value), [value] #pop-options /// We add a unit element to [avalue], as needed for a PCM [@@erasable] noeq type knowledge (#v:Type) (#p:preorder v) (anchors:anchor_rel p) = | Owns : avalue anchors -> knowledge anchors | Nothing : knowledge anchors let b2p (b:bool) : prop = b == true /// Fractional permissions are composable when their sum <= 1.0 let perm_opt_composable (p0 p1:option perm) : prop = match p0, p1 with | None, None -> True | Some p, None | None, Some p -> b2p (p `lesser_equal_perm` full_perm) | Some p0, Some p1 -> b2p (sum_perm p0 p1 `lesser_equal_perm` full_perm) /// Composing them sums the permissions let compose_perm_opt (p0 p1:option perm) = match p0, p1 with | None, p | p, None -> p | Some p0, Some p1 -> Some (sum_perm p0 p1) /// Anchored permissions are composable when at most one of them has the anchor set let permission_composable #v (p0 p1 : permission v) : prop = let q0, s0 = p0 in let q1, s1 = p1 in perm_opt_composable q0 q1 /\ // some of fracs can't exceed 1 not (Some? s0 && Some? s1) // at most one can have an anchor /// Compose permissions component wise, keeping the anchor if set let compose_permissions (#v:_) (p0:permission v) (p1:permission v{permission_composable p0 p1}) : permission v = compose_perm_opt (fst p0) (fst p1), (match snd p0, snd p1 with | None, a | a, None -> a) /// This is the central definition of the PCM --- defining when two /// values are composable, or equivalently, when one thread's /// knowledge of [av0] is compatible with another thread's knowledge /// of [av1] /// /// This definition shows the interplay between fractions and anchors. /// It wasn't obvious to me how to factor this further, e.g., adding /// anchors to preorders and then separately adding fractions to it. let avalue_composable (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (av0 av1: avalue anchors) : prop = let (p0, v0) = av0 in let (p1, v1) = av1 in permission_composable p0 p1 /\ (if not (has_some_ownership p0) && not (has_some_ownership p1) then p_composable _ v0 v1 //neither has ownership, one history is older than the other else if not (has_some_ownership p0) && has_some_ownership p1 then ( if has_nonzero p1 then v1 `extends` v0 //the one with ownership is more recent else ( //this part is the most subtle assert (has_anchor p1); p_composable _ v0 v1 /\ (v0 `extends` v1 ==> //if v0 is a more recent snapshot than v1 //then v0 must still be anchored by v1's anchor anchor_of p1 `anchors` curval v0) ) ) else if has_some_ownership p0 && not (has_some_ownership p1) then ( //symmetric if has_nonzero p0 then v0 `extends` v1 else ( assert (has_anchor p0); p_composable _ v0 v1 /\ (v1 `extends` v0 ==> anchor_of p0 `anchors` curval v1) ) ) else ( assert (has_some_ownership p0 && has_some_ownership p1); if has_nonzero p0 && has_nonzero p1 then v0 == v1 //if both have non-zero perm, then they must both only have read permission and must agree on the value else if has_nonzero p0 && has_anchor p1 then ( assert (not (has_nonzero p1)); //The key part of the anchor semantics: v0 `extends` v1 /\ //v0 has advanceable ownership, so extends anchor_of p1 `anchors` curval v0 //but not beyond what is allowed by s ) else if has_anchor p0 && has_nonzero p1 //symmetric then ( assert (not (has_nonzero p0)); v1 `extends` v0 /\ anchor_of p0 `anchors` curval v1 //v1 extends, but not beyond what is allowed by s ) else (assert false; False) ) ) //exhaustive /// Lifting avalue comosability to knowledge, including the unit let composable #v (#p:preorder v) (#a:anchor_rel p) : symrel (knowledge a) = fun (k0 k1:knowledge a) -> match k0, k1 with | Nothing, _ | _, Nothing -> True | Owns m, Owns m' -> avalue_composable m m' /// Compose avalues by composing permissions and composing the values /// using the underlying preorder PCM let compose_avalue (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (m0:avalue anchors) (m1:avalue anchors { avalue_composable m0 m1 } ) : avalue anchors = let p0, v0 = m0 in let p1, v1 = m1 in let p12 = compose_permissions p0 p1 in let v12 = p_op _ v0 v1 in p12, v12 //////////////////////////////////////////////////////////////////////////////// (** avalue composition is associative and commutative **) let compose_avalue_comm (#v:Type) (#p:preorder v) (#anc:anchor_rel p) (m0: avalue anc) (m1: avalue anc{ avalue_composable m0 m1 }) : Lemma (compose_avalue m0 m1 == compose_avalue m1 m0) = () let avalue_composable_assoc_l (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (m0: avalue anchors) (m1: avalue anchors) (m2: avalue anchors { avalue_composable m1 m2 /\ avalue_composable m0 (compose_avalue m1 m2) }) : Lemma (avalue_composable m0 m1 /\ avalue_composable (compose_avalue m0 m1) m2) = () let compose_avalue_assoc_l (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m0: avalue s) (m1: avalue s) (m2: avalue s { avalue_composable m1 m2 /\ avalue_composable m0 (compose_avalue m1 m2) }) : Lemma (avalue_composable m0 m1 /\ avalue_composable (compose_avalue m0 m1) m2 /\ compose_avalue m0 (compose_avalue m1 m2) == compose_avalue (compose_avalue m0 m1) m2) = avalue_composable_assoc_l m0 m1 m2 let avalue_composable_assoc_r (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (m0: avalue anchors) (m1: avalue anchors) (m2: avalue anchors { avalue_composable m0 m1 /\ avalue_composable (compose_avalue m0 m1) m2 }) : Lemma (avalue_composable m1 m2 /\ avalue_composable m0 (compose_avalue m1 m2)) = () let compose_avalue_assoc_r (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m0: avalue s) (m1: avalue s) (m2: avalue s{ avalue_composable m0 m1 /\ avalue_composable (compose_avalue m0 m1) m2 }) : Lemma (avalue_composable m1 m2 /\ avalue_composable m0 (compose_avalue m1 m2) /\ compose_avalue m0 (compose_avalue m1 m2) == compose_avalue (compose_avalue m0 m1) m2) = avalue_composable_assoc_r m0 m1 m2 //////////////////////////////////////////////////////////////////////////////// /// lifting avalue composition to knowledge, including unit let compose (#v:Type) (#p:preorder v) (#s:anchor_rel p) (k0:knowledge s) (k1:knowledge s{ composable k0 k1 }) : knowledge s = match k0, k1 with | Nothing, k | k, Nothing -> k | Owns m, Owns m' -> Owns (compose_avalue m m') let composable_assoc_r #v (#p:preorder v) (#s:anchor_rel p) (k0 k1 k2: knowledge s) : Lemma (requires composable k0 k1 /\ composable (compose k0 k1) k2) (ensures composable k1 k2 /\ composable k0 (compose k1 k2) /\ compose k0 (compose k1 k2) == compose (compose k0 k1) k2 ) = match k0, k1, k2 with | Nothing, _, _ | _, Nothing, _ | _, _, Nothing -> () | Owns m0, Owns m1, Owns m2 -> compose_avalue_assoc_r m0 m1 m2 let composable_assoc_l #v (#p:preorder v) (#s:anchor_rel p) (k0 k1 k2: knowledge s) : Lemma (requires composable k1 k2 /\ composable k0 (compose k1 k2)) (ensures composable k0 k1 /\ composable (compose k0 k1) k2 /\ compose k0 (compose k1 k2) == compose (compose k0 k1) k2) = match k0, k1, k2 with | Nothing, _, _ | _, Nothing, _ | _, _, Nothing -> () | Owns m0, Owns m1, Owns m2 -> compose_avalue_assoc_l m0 m1 m2 /// Now, we can define our PCM /// The core of the PCM let p0 #v #p #s : pcm' (knowledge #v #p s) = { composable; op=compose; one=Nothing } let avalue_perm (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) = fst m /// A avalue represents full ownership when the fraction is full AND /// the anchor is set. This means that no knowledge held by any other /// thread can constrain this value meaningfully. let avalue_owns (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) : prop = fst (avalue_perm m) == Some full_perm /\ Some? (snd (avalue_perm m)) let full_knowledge #v #p #s (kn:knowledge #v #p s) : prop = match kn with | Nothing -> False | Owns km -> avalue_owns km
{ "checked_file": "/", "dependencies": [ "Steel.Preorder.fst.checked", "Steel.FractionalPermission.fst.checked", "prims.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked" ], "interface_file": false, "source_file": "Steel.FractionalAnchoredPreorder.fst" }
[ { "abbrev": false, "full_module": "Steel.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Steel.Preorder", "short_module": null }, { "abbrev": false, "full_module": "FStar.Preorder", "short_module": null }, { "abbrev": false, "full_module": "FStar.PCM", "short_module": null }, { "abbrev": false, "full_module": "Steel", "short_module": null }, { "abbrev": false, "full_module": "Steel", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
FStar.PCM.pcm (Steel.FractionalAnchoredPreorder.knowledge s)
Prims.Tot
[ "total" ]
[]
[ "FStar.Preorder.preorder", "Steel.FractionalAnchoredPreorder.anchor_rel", "FStar.PCM.Mkpcm", "Steel.FractionalAnchoredPreorder.knowledge", "Steel.FractionalAnchoredPreorder.p0", "FStar.PCM.__proj__Mkpcm'__item__composable", "FStar.Pervasives.Native.Mktuple2", "Steel.FractionalAnchoredPreorder.avalue", "Steel.FractionalAnchoredPreorder.compose_avalue_comm", "Prims.unit", "Prims.l_and", "FStar.PCM.__proj__Mkpcm'__item__op", "Steel.FractionalAnchoredPreorder.composable_assoc_l", "Steel.FractionalAnchoredPreorder.composable_assoc_r", "Steel.FractionalAnchoredPreorder.full_knowledge", "FStar.PCM.pcm" ]
[]
false
false
false
false
false
let pcm #v #p #s : pcm (knowledge #v #p s) =
{ p = p0; comm = (fun k0 k1 -> match k0, k1 with | Nothing, _ | _, Nothing -> () | Owns m0, Owns m1 -> compose_avalue_comm m0 m1); assoc = (fun k0 k1 k2 -> composable_assoc_l k0 k1 k2); assoc_r = (fun k0 k1 k2 -> composable_assoc_r k0 k1 k2); is_unit = (fun _ -> ()); refine = full_knowledge }
false
Steel.FractionalAnchoredPreorder.fst
Steel.FractionalAnchoredPreorder.update_value
val update_value (#v: Type) (#p: preorder v) (#s: anchor_rel p) (m: avalue s) (v1: v{avalue_owns m /\ (curval (avalue_val m)) `p` v1 /\ s v1 v1}) : frame_preserving_upd pcm (Owns m) (Owns (avalue_update_value m v1))
val update_value (#v: Type) (#p: preorder v) (#s: anchor_rel p) (m: avalue s) (v1: v{avalue_owns m /\ (curval (avalue_val m)) `p` v1 /\ s v1 v1}) : frame_preserving_upd pcm (Owns m) (Owns (avalue_update_value m v1))
let update_value (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) (v1:v { avalue_owns m /\ //if you have full ownership of key curval (avalue_val m) `p` v1 /\ //you can update it wrt the preorder only s v1 v1 //and it is related to itself by the anchor }) : frame_preserving_upd pcm (Owns m) (Owns (avalue_update_value m v1)) = coerce_eq () (update_hist m (extend_history (avalue_val m) v1))
{ "file_name": "lib/steel/Steel.FractionalAnchoredPreorder.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 67, "end_line": 485, "start_col": 0, "start_line": 475 }
(* Copyright 2021 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. Author: N. Swamy *) module Steel.FractionalAnchoredPreorder (** This module provides a partial commutative monoid (PCM) for use in the ghost state of a concurrent Steel program. Its goal is to facilitate a form of information-sharing between multiple threads including the following features: Fractions, Preorders, Snapshots, and Anchors --- Anchors are the most unusual. 1. Fractions: Ownership of the state is controlled by a fractional permission, so multiple threads may share read-only privileges on the state, but only one can have write permission. 2. Preorders: The ghost state is governed by a preorder p and all updates to the state must respect the preorder (a reflexive, transitive relation on the state) 3. Snapshots: Since the state always evolves by a preorder, it is possible to take a snapshot of the state. A snapshot does not confer any particular ownership on the state, except knowledge of a snapshot ensures that the current state is related to the snapshot by the preorder. 4. Anchors are a kind of refinement of the preorder. If a thread owns an anchored value [v], then no other thread, even a thread owning a full fractional permission, can advance the state "too far" from the anchor. In particular, the PCM is parameterized by a binary relation on values, [anchors:anchor_relation]. If a thread owns the anchor [v], then the current value `cur` of the state must be in relation [v `anchors` cur]. This can be used to ensure that the knowledge of one thread is never becomes too stale. For example, this allows one to model a shared monotonically increasing counter, where if one thread anchors knowledge of the counter at the value 5, no other thread can increase the value of the counter beyond, say, 10, (when the anchor relation is y - x <= 5), until the anchoring thread releases the anchor. Further, at any point, a thread can take a snapshot of the counter and rely on the fact that the value of the counter in the future will be >= the snapshot. *) open FStar.PCM open FStar.Preorder open Steel.Preorder open Steel.FractionalPermission #push-options "--fuel 0 --ifuel 2" /// A permission: is a pair of /// /// * an optional fractional permission; with `Some p` indicating /// some ownership, while `None` is an additional "0" permission /// value, to encode snapshots. /// /// * and an optional anchor, where `Some a` indicates the current /// value can't be too far from `a`. let permission (v:Type) = option perm & option v /// Non-zero permission is either a read or write permission let has_nonzero #v (p:permission v) = Some? (fst p) /// Has an anchor set let has_anchor #v (p:permission v) = Some? (snd p) /// Either an anchor or non-zero let has_some_ownership #v (p:permission v) = has_nonzero p || has_anchor p /// The anchoring value let anchor_of #v (p:permission v { has_anchor p }) : v = Some?.v (snd p) /// The anchoring relation: /// -- A binary relation on values /// -- refining the preorder /// -- and if x `anchors` z then it also anchors any `y` between `x` and `z` /// /// Explaining the third clause a bit: /// Think intuitively of anchoring relations as a kind of distance measure /// /// if `z` is close enough to `x` then if `z` is further than `y` /// (since it is ahead of `y` in the preorder) then `y` is also /// close enough to `x` let anchor_rel (#v:Type) (p:preorder v) = anchors:(v -> v -> prop) { (forall v0 v1. anchors v0 v1 ==> p v0 v1) /\ (forall x z. x `anchors` z ==> (forall y. p x y /\ p y z ==> x `anchors` y)) // } /// An implementation remark: We use Steel.Preorder here to /// generically transform any preorder into a PCM. That works by /// taking the value of the PCM to be a history of values related by /// the preorder. So, throughout, we'll be using the the [vhist p] /// from Steel.Preorder, the type of a non-empty history compatible /// with [p]. The details of the histories don't matter much for our /// purposes---we only care about the most recent value, for which /// we'll use [curval v]. /// If the anchor is set, then the current value is anchored by it let anchored (#v:Type) (#p:preorder v) (anchors:anchor_rel p) (pv:(permission v & vhist p)) = has_anchor (fst pv) ==> anchor_of (fst pv) `anchors` curval (snd pv) /// A value in our fractional anchored PCM is a pair of a permission /// and a p-compatible history, refined to ensure that if the anchor /// is set, then the current value is anchored by it. let avalue (#v:Type) (#p:preorder v) (anchors:anchor_rel p) = pv:(permission v & vhist p) { anchored anchors pv } /// initial_value: A utility to construct a value in the PCM #push-options "--fuel 1" let initial_value (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (value:v { anchors value value }) : avalue anchors = (Some full_perm, Some value), [value] #pop-options /// We add a unit element to [avalue], as needed for a PCM [@@erasable] noeq type knowledge (#v:Type) (#p:preorder v) (anchors:anchor_rel p) = | Owns : avalue anchors -> knowledge anchors | Nothing : knowledge anchors let b2p (b:bool) : prop = b == true /// Fractional permissions are composable when their sum <= 1.0 let perm_opt_composable (p0 p1:option perm) : prop = match p0, p1 with | None, None -> True | Some p, None | None, Some p -> b2p (p `lesser_equal_perm` full_perm) | Some p0, Some p1 -> b2p (sum_perm p0 p1 `lesser_equal_perm` full_perm) /// Composing them sums the permissions let compose_perm_opt (p0 p1:option perm) = match p0, p1 with | None, p | p, None -> p | Some p0, Some p1 -> Some (sum_perm p0 p1) /// Anchored permissions are composable when at most one of them has the anchor set let permission_composable #v (p0 p1 : permission v) : prop = let q0, s0 = p0 in let q1, s1 = p1 in perm_opt_composable q0 q1 /\ // some of fracs can't exceed 1 not (Some? s0 && Some? s1) // at most one can have an anchor /// Compose permissions component wise, keeping the anchor if set let compose_permissions (#v:_) (p0:permission v) (p1:permission v{permission_composable p0 p1}) : permission v = compose_perm_opt (fst p0) (fst p1), (match snd p0, snd p1 with | None, a | a, None -> a) /// This is the central definition of the PCM --- defining when two /// values are composable, or equivalently, when one thread's /// knowledge of [av0] is compatible with another thread's knowledge /// of [av1] /// /// This definition shows the interplay between fractions and anchors. /// It wasn't obvious to me how to factor this further, e.g., adding /// anchors to preorders and then separately adding fractions to it. let avalue_composable (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (av0 av1: avalue anchors) : prop = let (p0, v0) = av0 in let (p1, v1) = av1 in permission_composable p0 p1 /\ (if not (has_some_ownership p0) && not (has_some_ownership p1) then p_composable _ v0 v1 //neither has ownership, one history is older than the other else if not (has_some_ownership p0) && has_some_ownership p1 then ( if has_nonzero p1 then v1 `extends` v0 //the one with ownership is more recent else ( //this part is the most subtle assert (has_anchor p1); p_composable _ v0 v1 /\ (v0 `extends` v1 ==> //if v0 is a more recent snapshot than v1 //then v0 must still be anchored by v1's anchor anchor_of p1 `anchors` curval v0) ) ) else if has_some_ownership p0 && not (has_some_ownership p1) then ( //symmetric if has_nonzero p0 then v0 `extends` v1 else ( assert (has_anchor p0); p_composable _ v0 v1 /\ (v1 `extends` v0 ==> anchor_of p0 `anchors` curval v1) ) ) else ( assert (has_some_ownership p0 && has_some_ownership p1); if has_nonzero p0 && has_nonzero p1 then v0 == v1 //if both have non-zero perm, then they must both only have read permission and must agree on the value else if has_nonzero p0 && has_anchor p1 then ( assert (not (has_nonzero p1)); //The key part of the anchor semantics: v0 `extends` v1 /\ //v0 has advanceable ownership, so extends anchor_of p1 `anchors` curval v0 //but not beyond what is allowed by s ) else if has_anchor p0 && has_nonzero p1 //symmetric then ( assert (not (has_nonzero p0)); v1 `extends` v0 /\ anchor_of p0 `anchors` curval v1 //v1 extends, but not beyond what is allowed by s ) else (assert false; False) ) ) //exhaustive /// Lifting avalue comosability to knowledge, including the unit let composable #v (#p:preorder v) (#a:anchor_rel p) : symrel (knowledge a) = fun (k0 k1:knowledge a) -> match k0, k1 with | Nothing, _ | _, Nothing -> True | Owns m, Owns m' -> avalue_composable m m' /// Compose avalues by composing permissions and composing the values /// using the underlying preorder PCM let compose_avalue (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (m0:avalue anchors) (m1:avalue anchors { avalue_composable m0 m1 } ) : avalue anchors = let p0, v0 = m0 in let p1, v1 = m1 in let p12 = compose_permissions p0 p1 in let v12 = p_op _ v0 v1 in p12, v12 //////////////////////////////////////////////////////////////////////////////// (** avalue composition is associative and commutative **) let compose_avalue_comm (#v:Type) (#p:preorder v) (#anc:anchor_rel p) (m0: avalue anc) (m1: avalue anc{ avalue_composable m0 m1 }) : Lemma (compose_avalue m0 m1 == compose_avalue m1 m0) = () let avalue_composable_assoc_l (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (m0: avalue anchors) (m1: avalue anchors) (m2: avalue anchors { avalue_composable m1 m2 /\ avalue_composable m0 (compose_avalue m1 m2) }) : Lemma (avalue_composable m0 m1 /\ avalue_composable (compose_avalue m0 m1) m2) = () let compose_avalue_assoc_l (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m0: avalue s) (m1: avalue s) (m2: avalue s { avalue_composable m1 m2 /\ avalue_composable m0 (compose_avalue m1 m2) }) : Lemma (avalue_composable m0 m1 /\ avalue_composable (compose_avalue m0 m1) m2 /\ compose_avalue m0 (compose_avalue m1 m2) == compose_avalue (compose_avalue m0 m1) m2) = avalue_composable_assoc_l m0 m1 m2 let avalue_composable_assoc_r (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (m0: avalue anchors) (m1: avalue anchors) (m2: avalue anchors { avalue_composable m0 m1 /\ avalue_composable (compose_avalue m0 m1) m2 }) : Lemma (avalue_composable m1 m2 /\ avalue_composable m0 (compose_avalue m1 m2)) = () let compose_avalue_assoc_r (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m0: avalue s) (m1: avalue s) (m2: avalue s{ avalue_composable m0 m1 /\ avalue_composable (compose_avalue m0 m1) m2 }) : Lemma (avalue_composable m1 m2 /\ avalue_composable m0 (compose_avalue m1 m2) /\ compose_avalue m0 (compose_avalue m1 m2) == compose_avalue (compose_avalue m0 m1) m2) = avalue_composable_assoc_r m0 m1 m2 //////////////////////////////////////////////////////////////////////////////// /// lifting avalue composition to knowledge, including unit let compose (#v:Type) (#p:preorder v) (#s:anchor_rel p) (k0:knowledge s) (k1:knowledge s{ composable k0 k1 }) : knowledge s = match k0, k1 with | Nothing, k | k, Nothing -> k | Owns m, Owns m' -> Owns (compose_avalue m m') let composable_assoc_r #v (#p:preorder v) (#s:anchor_rel p) (k0 k1 k2: knowledge s) : Lemma (requires composable k0 k1 /\ composable (compose k0 k1) k2) (ensures composable k1 k2 /\ composable k0 (compose k1 k2) /\ compose k0 (compose k1 k2) == compose (compose k0 k1) k2 ) = match k0, k1, k2 with | Nothing, _, _ | _, Nothing, _ | _, _, Nothing -> () | Owns m0, Owns m1, Owns m2 -> compose_avalue_assoc_r m0 m1 m2 let composable_assoc_l #v (#p:preorder v) (#s:anchor_rel p) (k0 k1 k2: knowledge s) : Lemma (requires composable k1 k2 /\ composable k0 (compose k1 k2)) (ensures composable k0 k1 /\ composable (compose k0 k1) k2 /\ compose k0 (compose k1 k2) == compose (compose k0 k1) k2) = match k0, k1, k2 with | Nothing, _, _ | _, Nothing, _ | _, _, Nothing -> () | Owns m0, Owns m1, Owns m2 -> compose_avalue_assoc_l m0 m1 m2 /// Now, we can define our PCM /// The core of the PCM let p0 #v #p #s : pcm' (knowledge #v #p s) = { composable; op=compose; one=Nothing } let avalue_perm (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) = fst m /// A avalue represents full ownership when the fraction is full AND /// the anchor is set. This means that no knowledge held by any other /// thread can constrain this value meaningfully. let avalue_owns (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) : prop = fst (avalue_perm m) == Some full_perm /\ Some? (snd (avalue_perm m)) let full_knowledge #v #p #s (kn:knowledge #v #p s) : prop = match kn with | Nothing -> False | Owns km -> avalue_owns km /// The PCM itself, together with proofs of its properties let pcm #v #p #s : pcm (knowledge #v #p s) = { p = p0; comm = (fun k0 k1 -> match k0, k1 with | Nothing, _ | _, Nothing -> () | Owns m0, Owns m1 -> compose_avalue_comm m0 m1); assoc = (fun k0 k1 k2 -> composable_assoc_l k0 k1 k2); assoc_r = (fun k0 k1 k2 -> composable_assoc_r k0 k1 k2); is_unit = (fun _ -> ()); refine = full_knowledge; } /// Some utilities: The value of an avalue let avalue_val (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue #v #p s) = snd m /// Updating the value, in a full-ownership situation, also involves /// updating the anchor let avalue_update (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) (value:vhist p { s (curval value) (curval value) }) : avalue s = let p, _ = avalue_perm m in let p' = p, Some (curval value) in (p', value) /// Our core frame-preserving update: /// /// If you fully own a value, you can update it so long as you /// respect the preorder, and prove that the new value is related /// to itself by the anchor (since we'll be setting the anchor to /// the new value) /// /// This is a building block: we'll define a derived version that /// on values rather than histories #push-options "--z3rlimit_factor 2" let update_hist (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) (v1:vhist p { avalue_owns m /\ v1 `extends` avalue_val m /\ s (curval v1) (curval v1) }) : frame_preserving_upd pcm (Owns m) (Owns (avalue_update m v1)) = fun full_v -> let Owns full_m = full_v in let m_res = avalue_update full_m v1 in Owns m_res #pop-options /// Updating with value, rather than a history let avalue_update_value (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) (value:v { curval (avalue_val m) `p` value /\ s value value }) : m':avalue s { curval (avalue_val m') == value /\ avalue_val m' `extends` avalue_val m } = let v = avalue_val m in avalue_update m (extend_history v value)
{ "checked_file": "/", "dependencies": [ "Steel.Preorder.fst.checked", "Steel.FractionalPermission.fst.checked", "prims.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked" ], "interface_file": false, "source_file": "Steel.FractionalAnchoredPreorder.fst" }
[ { "abbrev": false, "full_module": "Steel.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Steel.Preorder", "short_module": null }, { "abbrev": false, "full_module": "FStar.Preorder", "short_module": null }, { "abbrev": false, "full_module": "FStar.PCM", "short_module": null }, { "abbrev": false, "full_module": "Steel", "short_module": null }, { "abbrev": false, "full_module": "Steel", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
m: Steel.FractionalAnchoredPreorder.avalue s -> v1: v { Steel.FractionalAnchoredPreorder.avalue_owns m /\ p (Steel.Preorder.curval (Steel.FractionalAnchoredPreorder.avalue_val m)) v1 /\ s v1 v1 } -> FStar.PCM.frame_preserving_upd Steel.FractionalAnchoredPreorder.pcm (Steel.FractionalAnchoredPreorder.Owns m) (Steel.FractionalAnchoredPreorder.Owns (Steel.FractionalAnchoredPreorder.avalue_update_value m v1))
Prims.Tot
[ "total" ]
[]
[ "FStar.Preorder.preorder", "Steel.FractionalAnchoredPreorder.anchor_rel", "Steel.FractionalAnchoredPreorder.avalue", "Prims.l_and", "Steel.FractionalAnchoredPreorder.avalue_owns", "Steel.Preorder.curval", "Steel.FractionalAnchoredPreorder.avalue_val", "FStar.Pervasives.coerce_eq", "FStar.PCM.frame_preserving_upd", "Steel.FractionalAnchoredPreorder.knowledge", "Steel.FractionalAnchoredPreorder.pcm", "Steel.FractionalAnchoredPreorder.Owns", "Steel.FractionalAnchoredPreorder.avalue_update", "Steel.Preorder.extend_history", "Steel.FractionalAnchoredPreorder.avalue_update_value", "Steel.FractionalAnchoredPreorder.update_hist" ]
[]
false
false
false
false
false
let update_value (#v: Type) (#p: preorder v) (#s: anchor_rel p) (m: avalue s) (v1: v{avalue_owns m /\ (curval (avalue_val m)) `p` v1 /\ s v1 v1}) : frame_preserving_upd pcm (Owns m) (Owns (avalue_update_value m v1)) =
coerce_eq () (update_hist m (extend_history (avalue_val m) v1))
false
Hacl.Poly1305.Field32xN.Lemmas0.fst
Hacl.Poly1305.Field32xN.Lemmas0.smul_add_felem5_eval_lemma
val smul_add_felem5_eval_lemma: #w:lanes -> #m1:scale32 -> #m2:scale32_5 -> #m3:scale64_5{m3 +* m1 *^ m2 <=* s64x5 4096} -> u1:uint64xN w{felem_fits1 u1 m1} -> f2:felem5 w{felem_fits5 f2 m2} -> acc1:felem_wide5 w{felem_wide_fits5 acc1 m3} -> Lemma (fas_nat5 (smul_add_felem5 #w u1 f2 acc1) == map2 #nat #nat #nat (fun a b -> a + b) (fas_nat5 acc1) (map2 #nat #nat #nat (fun a b -> a * b) (uint64xN_v u1) (fas_nat5 f2)))
val smul_add_felem5_eval_lemma: #w:lanes -> #m1:scale32 -> #m2:scale32_5 -> #m3:scale64_5{m3 +* m1 *^ m2 <=* s64x5 4096} -> u1:uint64xN w{felem_fits1 u1 m1} -> f2:felem5 w{felem_fits5 f2 m2} -> acc1:felem_wide5 w{felem_wide_fits5 acc1 m3} -> Lemma (fas_nat5 (smul_add_felem5 #w u1 f2 acc1) == map2 #nat #nat #nat (fun a b -> a + b) (fas_nat5 acc1) (map2 #nat #nat #nat (fun a b -> a * b) (uint64xN_v u1) (fas_nat5 f2)))
let smul_add_felem5_eval_lemma #w #m1 #m2 #m3 u1 f2 acc1 = let tmp = map2 #nat #nat #nat (fun a b -> a + b) (fas_nat5 acc1) (map2 #nat #nat #nat (fun a b -> a * b) (uint64xN_v u1) (fas_nat5 f2)) in FStar.Classical.forall_intro (smul_add_felem5_eval_lemma_i #w #m1 #m2 #m3 u1 f2 acc1); eq_intro (fas_nat5 (smul_add_felem5 #w u1 f2 acc1)) tmp
{ "file_name": "code/poly1305/Hacl.Poly1305.Field32xN.Lemmas0.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 57, "end_line": 359, "start_col": 0, "start_line": 354 }
module Hacl.Poly1305.Field32xN.Lemmas0 open Lib.IntTypes open Lib.IntVector open Lib.Sequence open FStar.Mul open FStar.Calc open Hacl.Spec.Poly1305.Vec include Hacl.Spec.Poly1305.Field32xN #reset-options "--z3rlimit 50 --using_facts_from '* -FStar.Seq' --max_fuel 0 --max_ifuel 0" val lemma_prime: unit -> Lemma (pow2 130 % prime = 5) let lemma_prime () = assert_norm (pow2 130 % prime = 5 % prime); assert_norm (5 < prime); FStar.Math.Lemmas.modulo_lemma 5 prime val lemma_mult_le: a:nat -> b:nat -> c:nat -> d:nat -> Lemma (requires a <= b /\ c <= d) (ensures a * c <= b * d) let lemma_mult_le a b c d = () val lemma_mul5_distr_l: a:nat -> b:nat -> c:nat -> d:nat -> e:nat -> f:nat -> Lemma (a * (b + c + d + e + f) == a * b + a * c + a * d + a * e + a * f) let lemma_mul5_distr_l a b c d e f = () val lemma_mul5_distr_r: a:nat -> b:nat -> c:nat -> d:nat -> e:nat -> f:nat -> Lemma ((a + b + c + d + e) * f == a * f + b * f + c * f + d * f + e * f) let lemma_mul5_distr_r a b c d e f = () val smul_mod_lemma: #m1:scale32 -> #m2:scale32 -> a:nat{a <= m1 * max26} -> b:nat{b <= m2 * max26} -> Lemma (a * b % pow2 64 == a * b) let smul_mod_lemma #m1 #m2 a b = lemma_mult_le a (m1 * max26) b (m2 * max26); assert (a * b <= m1 * m2 * max26 * max26); FStar.Math.Lemmas.modulo_lemma (a * b) (pow2 64) val smul_add_mod_lemma: #m1:scale32 -> #m2:scale32 -> #m3:scale64{m3 + m1 * m2 <= 4096} -> a:nat{a <= m1 * max26} -> b:nat{b <= m2 * max26} -> c:nat{c <= m3 * max26 * max26} -> Lemma ((c + a * b % pow2 64) % pow2 64 == c + a * b) let smul_add_mod_lemma #m1 #m2 #m3 a b c = assert_norm ((m3 + m1 * m2) * max26 * max26 < pow2 64); lemma_mult_le a (m1 * max26) b (m2 * max26); assert (c + a * b <= m3 * max26 * max26 + m1 * m2 * max26 * max26); FStar.Math.Lemmas.modulo_lemma (c + a * b) (pow2 64) val add5_lemma1: ma:scale64 -> mb:scale64 -> a:uint64 -> b:uint64 -> Lemma (requires v a <= ma * max26 /\ v b <= mb * max26 /\ ma + mb <= 64) (ensures v (a +. b) == v a + v b /\ v (a +. b) <= (ma + mb) * max26) let add5_lemma1 ma mb a b = assert (v a + v b <= (ma + mb) * max26); Math.Lemmas.lemma_mult_le_right max26 (ma + mb) 64; assert (v a + v b <= 64 * max26); assert_norm (64 * max26 < pow2 32); Math.Lemmas.small_mod (v a + v b) (pow2 32) #set-options "--ifuel 1" val fadd5_eval_lemma_i: #w:lanes -> f1:felem5 w{felem_fits5 f1 (2,2,2,2,2)} -> f2:felem5 w{felem_fits5 f2 (1,1,1,1,1)} -> i:nat{i < w} -> Lemma ((feval5 (fadd5 f1 f2)).[i] == pfadd (feval5 f1).[i] (feval5 f2).[i]) let fadd5_eval_lemma_i #w f1 f2 i = let o = fadd5 f1 f2 in let (f10, f11, f12, f13, f14) = as_tup64_i f1 i in let (f20, f21, f22, f23, f24) = as_tup64_i f2 i in let (o0, o1, o2, o3, o4) = as_tup64_i o i in add5_lemma1 2 1 f10 f20; add5_lemma1 2 1 f11 f21; add5_lemma1 2 1 f12 f22; add5_lemma1 2 1 f13 f23; add5_lemma1 2 1 f14 f24; assert (as_nat5 (o0, o1, o2, o3, o4) == as_nat5 (f10, f11, f12, f13, f14) + as_nat5 (f20, f21, f22, f23, f24)); FStar.Math.Lemmas.lemma_mod_plus_distr_l (as_nat5 (f10, f11, f12, f13, f14)) (as_nat5 (f20, f21, f22, f23, f24)) prime; FStar.Math.Lemmas.lemma_mod_plus_distr_r (as_nat5 (f10, f11, f12, f13, f14) % prime) (as_nat5 (f20, f21, f22, f23, f24)) prime val smul_felem5_fits_lemma_i: #w:lanes -> #m1:scale32 -> #m2:scale32 -> u1:uint64xN w{felem_fits1 u1 m1} -> f2:uint64xN w{felem_fits1 f2 m2} -> i:nat{i < w} -> Lemma ((uint64xN_v (vec_mul_mod f2 u1)).[i] <= m1 * m2 * max26 * max26) let smul_felem5_fits_lemma_i #w #m1 #m2 u1 f2 i = let o = vec_mul_mod f2 u1 in smul_mod_lemma #m1 #m2 (uint64xN_v u1).[i] (uint64xN_v f2).[i]; assert ((uint64xN_v o).[i] == (uint64xN_v u1).[i] * (uint64xN_v f2).[i]); lemma_mult_le (uint64xN_v u1).[i] (m1 * max26) (uint64xN_v f2).[i] (m2 * max26) val smul_felem5_eval_lemma_i: #w:lanes -> #m1:scale32 -> #m2:scale32_5 -> u1:uint64xN w{felem_fits1 u1 m1} -> f2:felem5 w{felem_fits5 f2 m2} -> i:nat{i < w} -> Lemma ((fas_nat5 (smul_felem5 #w u1 f2)).[i] == (uint64xN_v u1).[i] * (fas_nat5 f2).[i]) let smul_felem5_eval_lemma_i #w #m1 #m2 u1 f2 i = let o = smul_felem5 #w u1 f2 in let (m20, m21, m22, m23, m24) = m2 in let vu1 = (uint64xN_v u1).[i] in let (tf20, tf21, tf22, tf23, tf24) = as_tup64_i f2 i in let (to0, to1, to2, to3, to4) = as_tup64_i o i in smul_mod_lemma #m1 #m20 vu1 (v tf20); smul_mod_lemma #m1 #m21 vu1 (v tf21); smul_mod_lemma #m1 #m22 vu1 (v tf22); smul_mod_lemma #m1 #m23 vu1 (v tf23); smul_mod_lemma #m1 #m24 vu1 (v tf24); assert ((fas_nat5 o).[i] == vu1 * v tf20 + vu1 * v tf21 * pow26 + vu1 * v tf22 * pow52 + vu1 * v tf23 * pow78 + vu1 * v tf24 * pow104); calc (==) { vu1 * (fas_nat5 f2).[i]; (==) { } vu1 * (v tf20 + v tf21 * pow26 + v tf22 * pow52 + v tf23 * pow78 + v tf24 * pow104); (==) { lemma_mul5_distr_l vu1 (v tf20) (v tf21 * pow26) (v tf22 * pow52) (v tf23 * pow78) (v tf24 * pow104)} vu1 * v tf20 + vu1 * (v tf21 * pow26) + vu1 * (v tf22 * pow52) + vu1 * (v tf23 * pow78) + vu1 * (v tf24 * pow104); (==) { FStar.Math.Lemmas.paren_mul_right vu1 (v tf21) pow26; FStar.Math.Lemmas.paren_mul_right vu1 (v tf22) pow52; FStar.Math.Lemmas.paren_mul_right vu1 (v tf23) pow78; FStar.Math.Lemmas.paren_mul_right vu1 (v tf24) pow104} vu1 * v tf20 + vu1 * v tf21 * pow26 + vu1 * v tf22 * pow52 + vu1 * v tf23 * pow78 + vu1 * v tf24 * pow104; }; assert (vu1 * (fas_nat5 f2).[i] == (fas_nat5 o).[i]) val smul_felem5_fits_lemma1: #w:lanes -> #m1:scale32 -> #m2:scale32 -> u1:uint64xN w{felem_fits1 u1 m1} -> f2:uint64xN w{felem_fits1 f2 m2} -> Lemma (felem_wide_fits1 (vec_mul_mod f2 u1) (m1 * m2)) let smul_felem5_fits_lemma1 #w #m1 #m2 u1 f2 = match w with | 1 -> smul_felem5_fits_lemma_i #w #m1 #m2 u1 f2 0 | 2 -> smul_felem5_fits_lemma_i #w #m1 #m2 u1 f2 0; smul_felem5_fits_lemma_i #w #m1 #m2 u1 f2 1 | 4 -> smul_felem5_fits_lemma_i #w #m1 #m2 u1 f2 0; smul_felem5_fits_lemma_i #w #m1 #m2 u1 f2 1; smul_felem5_fits_lemma_i #w #m1 #m2 u1 f2 2; smul_felem5_fits_lemma_i #w #m1 #m2 u1 f2 3 val smul_felem5_fits_lemma: #w:lanes -> #m1:scale32 -> #m2:scale32_5 -> u1:uint64xN w{felem_fits1 u1 m1} -> f2:felem5 w{felem_fits5 f2 m2} -> Lemma (felem_wide_fits5 (smul_felem5 #w u1 f2) (m1 *^ m2)) let smul_felem5_fits_lemma #w #m1 #m2 u1 f2 = let (f20, f21, f22, f23, f24) = f2 in let (m20, m21, m22, m23, m24) = m2 in smul_felem5_fits_lemma1 #w #m1 #m20 u1 f20; smul_felem5_fits_lemma1 #w #m1 #m21 u1 f21; smul_felem5_fits_lemma1 #w #m1 #m22 u1 f22; smul_felem5_fits_lemma1 #w #m1 #m23 u1 f23; smul_felem5_fits_lemma1 #w #m1 #m24 u1 f24 val smul_felem5_eval_lemma: #w:lanes -> #m1:scale32 -> #m2:scale32_5 -> u1:uint64xN w{felem_fits1 u1 m1} -> f2:felem5 w{felem_fits5 f2 m2} -> Lemma (fas_nat5 (smul_felem5 #w u1 f2) == map2 #nat #nat #nat (fun a b -> a * b) (uint64xN_v u1) (fas_nat5 f2)) let smul_felem5_eval_lemma #w #m1 #m2 u1 f2 = FStar.Classical.forall_intro (smul_felem5_eval_lemma_i #w #m1 #m2 u1 f2); eq_intro (fas_nat5 (smul_felem5 #w u1 f2)) (map2 #nat #nat #nat (fun a b -> a * b) (uint64xN_v u1) (fas_nat5 f2)) val smul_add_felem5_fits_lemma_i: #w:lanes -> #m1:scale32 -> #m2:scale32 -> #m3:scale64{m3 + m1 * m2 <= 4096} -> u1:uint64xN w{felem_fits1 u1 m1} -> f2:uint64xN w{felem_fits1 f2 m2} -> acc1:uint64xN w{felem_wide_fits1 acc1 m3} -> i:nat{i < w} -> Lemma ((uint64xN_v (vec_add_mod acc1 (vec_mul_mod f2 u1))).[i] <= (m3 + m1 * m2) * max26 * max26) #push-options "--z3rlimit 200" let smul_add_felem5_fits_lemma_i #w #m1 #m2 #m3 u1 f2 acc1 i = let o = vec_add_mod acc1 (vec_mul_mod f2 u1) in smul_add_mod_lemma #m1 #m2 #m3 (uint64xN_v u1).[i] (uint64xN_v f2).[i] (uint64xN_v acc1).[i]; assert ((uint64xN_v o).[i] == (uint64xN_v acc1).[i] + (uint64xN_v u1).[i] * (uint64xN_v f2).[i]); lemma_mult_le (uint64xN_v u1).[i] (m1 * max26) (uint64xN_v f2).[i] (m2 * max26); assert ((uint64xN_v o).[i] <= m3 * max26 * max26 + m1 * m2 * max26 * max26) #pop-options val smul_add_felem5_eval_lemma_i: #w:lanes -> #m1:scale32 -> #m2:scale32_5 -> #m3:scale64_5{m3 +* m1 *^ m2 <=* s64x5 4096} -> u1:uint64xN w{felem_fits1 u1 m1} -> f2:felem5 w{felem_fits5 f2 m2} -> acc1:felem_wide5 w{felem_wide_fits5 acc1 m3} -> i:nat{i < w} -> Lemma ((fas_nat5 (smul_add_felem5 #w u1 f2 acc1)).[i] == (fas_nat5 acc1).[i] + (uint64xN_v u1).[i] * (fas_nat5 f2).[i]) let smul_add_felem5_eval_lemma_i #w #m1 #m2 #m3 u1 f2 acc1 i = let o = smul_add_felem5 #w u1 f2 acc1 in let (m20, m21, m22, m23, m24) = m2 in let (m30, m31, m32, m33, m34) = m3 in let vu1 = (uint64xN_v u1).[i] in let (tf20, tf21, tf22, tf23, tf24) = as_tup64_i f2 i in let (ta0, ta1, ta2, ta3, ta4) = as_tup64_i acc1 i in let (to0, to1, to2, to3, to4) = as_tup64_i o i in smul_add_mod_lemma #m1 #m20 #m30 vu1 (v tf20) (v ta0); smul_add_mod_lemma #m1 #m21 #m31 vu1 (v tf21) (v ta1); smul_add_mod_lemma #m1 #m22 #m32 vu1 (v tf22) (v ta2); smul_add_mod_lemma #m1 #m23 #m33 vu1 (v tf23) (v ta3); smul_add_mod_lemma #m1 #m24 #m34 vu1 (v tf24) (v ta4); calc (==) { (fas_nat5 o).[i]; (==) { } v ta0 + vu1 * v tf20 + (v ta1 + vu1 * v tf21) * pow26 + (v ta2 + vu1 * v tf22) * pow52 + (v ta3 + vu1 * v tf23) * pow78 + (v ta4 + vu1 * v tf24) * pow104; (==) { FStar.Math.Lemmas.distributivity_add_left (v ta1) (vu1 * v tf21) pow26; FStar.Math.Lemmas.distributivity_add_left (v ta2) (vu1 * v tf22) pow52; FStar.Math.Lemmas.distributivity_add_left (v ta3) (vu1 * v tf23) pow78; FStar.Math.Lemmas.distributivity_add_left (v ta1) (vu1 * v tf24) pow104 } v ta0 + v ta1 * pow26 + v ta2 * pow52 + v ta3 * pow78 + v ta4 * pow104 + vu1 * v tf20 + vu1 * v tf21 * pow26 + vu1 * v tf22 * pow52 + vu1 * v tf23 * pow78 + vu1 * v tf24 * pow104; (==) { } (fas_nat5 acc1).[i] + vu1 * v tf20 + vu1 * v tf21 * pow26 + vu1 * v tf22 * pow52 + vu1 * v tf23 * pow78 + vu1 * v tf24 * pow104; }; assert ((fas_nat5 o).[i] == (fas_nat5 acc1).[i] + vu1 * v tf20 + vu1 * v tf21 * pow26 + vu1 * v tf22 * pow52 + vu1 * v tf23 * pow78 + vu1 * v tf24 * pow104); calc (==) { vu1 * (fas_nat5 f2).[i]; (==) { } vu1 * (v tf20 + v tf21 * pow26 + v tf22 * pow52 + v tf23 * pow78 + v tf24 * pow104); (==) { lemma_mul5_distr_l vu1 (v tf20) (v tf21 * pow26) (v tf22 * pow52) (v tf23 * pow78) (v tf24 * pow104)} vu1 * v tf20 + vu1 * (v tf21 * pow26) + vu1 * (v tf22 * pow52) + vu1 * (v tf23 * pow78) + vu1 * (v tf24 * pow104); (==) { FStar.Math.Lemmas.paren_mul_right vu1 (v tf21) pow26; FStar.Math.Lemmas.paren_mul_right vu1 (v tf22) pow52; FStar.Math.Lemmas.paren_mul_right vu1 (v tf23) pow78; FStar.Math.Lemmas.paren_mul_right vu1 (v tf24) pow104} vu1 * v tf20 + vu1 * v tf21 * pow26 + vu1 * v tf22 * pow52 + vu1 * v tf23 * pow78 + vu1 * v tf24 * pow104; }; assert ((fas_nat5 o).[i] == (fas_nat5 acc1).[i] + vu1 * (fas_nat5 f2).[i]) val smul_add_felem5_fits_lemma1: #w:lanes -> #m1:scale32 -> #m2:scale32 -> #m3:scale64{m3 + m1 * m2 <= 4096} -> u1:uint64xN w{felem_fits1 u1 m1} -> f2:uint64xN w{felem_fits1 f2 m2} -> acc1:uint64xN w{felem_wide_fits1 acc1 m3} -> Lemma (felem_wide_fits1 (vec_add_mod acc1 (vec_mul_mod f2 u1)) (m3 + m1 * m2)) let smul_add_felem5_fits_lemma1 #w #m1 #m2 #m3 u1 f2 acc1 = match w with | 1 -> smul_add_felem5_fits_lemma_i #w #m1 #m2 #m3 u1 f2 acc1 0 | 2 -> smul_add_felem5_fits_lemma_i #w #m1 #m2 #m3 u1 f2 acc1 0; smul_add_felem5_fits_lemma_i #w #m1 #m2 #m3 u1 f2 acc1 1 | 4 -> smul_add_felem5_fits_lemma_i #w #m1 #m2 #m3 u1 f2 acc1 0; smul_add_felem5_fits_lemma_i #w #m1 #m2 #m3 u1 f2 acc1 1; smul_add_felem5_fits_lemma_i #w #m1 #m2 #m3 u1 f2 acc1 2; smul_add_felem5_fits_lemma_i #w #m1 #m2 #m3 u1 f2 acc1 3 val smul_add_felem5_fits_lemma: #w:lanes -> #m1:scale32 -> #m2:scale32_5 -> #m3:scale64_5{m3 +* m1 *^ m2 <=* s64x5 4096} -> u1:uint64xN w{felem_fits1 u1 m1} -> f2:felem5 w{felem_fits5 f2 m2} -> acc1:felem_wide5 w{felem_wide_fits5 acc1 m3} -> Lemma (felem_wide_fits5 (smul_add_felem5 #w u1 f2 acc1) (m3 +* m1 *^ m2)) let smul_add_felem5_fits_lemma #w #m1 #m2 #m3 u1 f2 acc1 = let (f20, f21, f22, f23, f24) = f2 in let (m20, m21, m22, m23, m24) = m2 in let (a0, a1, a2, a3, a4) = acc1 in let (m30, m31, m32, m33, m34) = m3 in smul_add_felem5_fits_lemma1 #w #m1 #m20 #m30 u1 f20 a0; smul_add_felem5_fits_lemma1 #w #m1 #m21 #m31 u1 f21 a1; smul_add_felem5_fits_lemma1 #w #m1 #m22 #m32 u1 f22 a2; smul_add_felem5_fits_lemma1 #w #m1 #m23 #m33 u1 f23 a3; smul_add_felem5_fits_lemma1 #w #m1 #m24 #m34 u1 f24 a4 val smul_add_felem5_eval_lemma: #w:lanes -> #m1:scale32 -> #m2:scale32_5 -> #m3:scale64_5{m3 +* m1 *^ m2 <=* s64x5 4096} -> u1:uint64xN w{felem_fits1 u1 m1} -> f2:felem5 w{felem_fits5 f2 m2} -> acc1:felem_wide5 w{felem_wide_fits5 acc1 m3} -> Lemma (fas_nat5 (smul_add_felem5 #w u1 f2 acc1) == map2 #nat #nat #nat (fun a b -> a + b) (fas_nat5 acc1) (map2 #nat #nat #nat (fun a b -> a * b) (uint64xN_v u1) (fas_nat5 f2)))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntVector.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Poly1305.Vec.fst.checked", "Hacl.Spec.Poly1305.Field32xN.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Poly1305.Field32xN.Lemmas0.fst" }
[ { "abbrev": false, "full_module": "Hacl.Spec.Poly1305.Field32xN", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Poly1305.Vec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntVector", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Poly1305.Field32xN", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Poly1305.Field32xN", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
u1: Hacl.Spec.Poly1305.Field32xN.uint64xN w {Hacl.Spec.Poly1305.Field32xN.felem_fits1 u1 m1} -> f2: Hacl.Spec.Poly1305.Field32xN.felem5 w {Hacl.Spec.Poly1305.Field32xN.felem_fits5 f2 m2} -> acc1: Hacl.Spec.Poly1305.Field32xN.felem_wide5 w {Hacl.Spec.Poly1305.Field32xN.felem_wide_fits5 acc1 m3} -> FStar.Pervasives.Lemma (ensures Hacl.Spec.Poly1305.Field32xN.fas_nat5 (Hacl.Spec.Poly1305.Field32xN.smul_add_felem5 u1 f2 acc1 ) == Lib.Sequence.map2 (fun a b -> a + b) (Hacl.Spec.Poly1305.Field32xN.fas_nat5 acc1) (Lib.Sequence.map2 (fun a b -> a * b) (Hacl.Spec.Poly1305.Field32xN.uint64xN_v u1) (Hacl.Spec.Poly1305.Field32xN.fas_nat5 f2)))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Hacl.Spec.Poly1305.Field32xN.lanes", "Hacl.Spec.Poly1305.Field32xN.scale32", "Hacl.Spec.Poly1305.Field32xN.scale32_5", "Hacl.Spec.Poly1305.Field32xN.scale64_5", "Hacl.Spec.Poly1305.Field32xN.op_Less_Equals_Star", "Hacl.Spec.Poly1305.Field32xN.op_Plus_Star", "Hacl.Spec.Poly1305.Field32xN.op_Star_Hat", "Hacl.Spec.Poly1305.Field32xN.s64x5", "Hacl.Spec.Poly1305.Field32xN.uint64xN", "Hacl.Spec.Poly1305.Field32xN.felem_fits1", "Hacl.Spec.Poly1305.Field32xN.felem5", "Hacl.Spec.Poly1305.Field32xN.felem_fits5", "Hacl.Spec.Poly1305.Field32xN.felem_wide5", "Hacl.Spec.Poly1305.Field32xN.felem_wide_fits5", "Lib.Sequence.eq_intro", "Prims.nat", "Hacl.Spec.Poly1305.Field32xN.fas_nat5", "Hacl.Spec.Poly1305.Field32xN.smul_add_felem5", "Prims.unit", "FStar.Classical.forall_intro", "Prims.b2t", "Prims.op_LessThan", "Prims.eq2", "Prims.int", "Lib.Sequence.op_String_Access", "Prims.op_Addition", "FStar.Mul.op_Star", "Hacl.Spec.Poly1305.Field32xN.uint64xN_v", "Hacl.Poly1305.Field32xN.Lemmas0.smul_add_felem5_eval_lemma_i", "Lib.Sequence.lseq", "Prims.l_Forall", "Prims.l_imp", "Lib.Sequence.index", "Lib.Sequence.map2", "Prims.op_Multiply" ]
[]
false
false
true
false
false
let smul_add_felem5_eval_lemma #w #m1 #m2 #m3 u1 f2 acc1 =
let tmp = map2 #nat #nat #nat (fun a b -> a + b) (fas_nat5 acc1) (map2 #nat #nat #nat (fun a b -> a * b) (uint64xN_v u1) (fas_nat5 f2)) in FStar.Classical.forall_intro (smul_add_felem5_eval_lemma_i #w #m1 #m2 #m3 u1 f2 acc1); eq_intro (fas_nat5 (smul_add_felem5 #w u1 f2 acc1)) tmp
false
Steel.FractionalAnchoredPreorder.fst
Steel.FractionalAnchoredPreorder.avalue_anchored_update
val avalue_anchored_update (#v: Type) (#p: preorder v) (#s: anchor_rel p) (m: avalue s) (value: vhist p {(curval value) `compat_with_any_anchor_of` m}) : avalue s
val avalue_anchored_update (#v: Type) (#p: preorder v) (#s: anchor_rel p) (m: avalue s) (value: vhist p {(curval value) `compat_with_any_anchor_of` m}) : avalue s
let avalue_anchored_update (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) (value:vhist p { curval value `compat_with_any_anchor_of` m }) : avalue s = avalue_perm m, value
{ "file_name": "lib/steel/Steel.FractionalAnchoredPreorder.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 24, "end_line": 517, "start_col": 0, "start_line": 509 }
(* Copyright 2021 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. Author: N. Swamy *) module Steel.FractionalAnchoredPreorder (** This module provides a partial commutative monoid (PCM) for use in the ghost state of a concurrent Steel program. Its goal is to facilitate a form of information-sharing between multiple threads including the following features: Fractions, Preorders, Snapshots, and Anchors --- Anchors are the most unusual. 1. Fractions: Ownership of the state is controlled by a fractional permission, so multiple threads may share read-only privileges on the state, but only one can have write permission. 2. Preorders: The ghost state is governed by a preorder p and all updates to the state must respect the preorder (a reflexive, transitive relation on the state) 3. Snapshots: Since the state always evolves by a preorder, it is possible to take a snapshot of the state. A snapshot does not confer any particular ownership on the state, except knowledge of a snapshot ensures that the current state is related to the snapshot by the preorder. 4. Anchors are a kind of refinement of the preorder. If a thread owns an anchored value [v], then no other thread, even a thread owning a full fractional permission, can advance the state "too far" from the anchor. In particular, the PCM is parameterized by a binary relation on values, [anchors:anchor_relation]. If a thread owns the anchor [v], then the current value `cur` of the state must be in relation [v `anchors` cur]. This can be used to ensure that the knowledge of one thread is never becomes too stale. For example, this allows one to model a shared monotonically increasing counter, where if one thread anchors knowledge of the counter at the value 5, no other thread can increase the value of the counter beyond, say, 10, (when the anchor relation is y - x <= 5), until the anchoring thread releases the anchor. Further, at any point, a thread can take a snapshot of the counter and rely on the fact that the value of the counter in the future will be >= the snapshot. *) open FStar.PCM open FStar.Preorder open Steel.Preorder open Steel.FractionalPermission #push-options "--fuel 0 --ifuel 2" /// A permission: is a pair of /// /// * an optional fractional permission; with `Some p` indicating /// some ownership, while `None` is an additional "0" permission /// value, to encode snapshots. /// /// * and an optional anchor, where `Some a` indicates the current /// value can't be too far from `a`. let permission (v:Type) = option perm & option v /// Non-zero permission is either a read or write permission let has_nonzero #v (p:permission v) = Some? (fst p) /// Has an anchor set let has_anchor #v (p:permission v) = Some? (snd p) /// Either an anchor or non-zero let has_some_ownership #v (p:permission v) = has_nonzero p || has_anchor p /// The anchoring value let anchor_of #v (p:permission v { has_anchor p }) : v = Some?.v (snd p) /// The anchoring relation: /// -- A binary relation on values /// -- refining the preorder /// -- and if x `anchors` z then it also anchors any `y` between `x` and `z` /// /// Explaining the third clause a bit: /// Think intuitively of anchoring relations as a kind of distance measure /// /// if `z` is close enough to `x` then if `z` is further than `y` /// (since it is ahead of `y` in the preorder) then `y` is also /// close enough to `x` let anchor_rel (#v:Type) (p:preorder v) = anchors:(v -> v -> prop) { (forall v0 v1. anchors v0 v1 ==> p v0 v1) /\ (forall x z. x `anchors` z ==> (forall y. p x y /\ p y z ==> x `anchors` y)) // } /// An implementation remark: We use Steel.Preorder here to /// generically transform any preorder into a PCM. That works by /// taking the value of the PCM to be a history of values related by /// the preorder. So, throughout, we'll be using the the [vhist p] /// from Steel.Preorder, the type of a non-empty history compatible /// with [p]. The details of the histories don't matter much for our /// purposes---we only care about the most recent value, for which /// we'll use [curval v]. /// If the anchor is set, then the current value is anchored by it let anchored (#v:Type) (#p:preorder v) (anchors:anchor_rel p) (pv:(permission v & vhist p)) = has_anchor (fst pv) ==> anchor_of (fst pv) `anchors` curval (snd pv) /// A value in our fractional anchored PCM is a pair of a permission /// and a p-compatible history, refined to ensure that if the anchor /// is set, then the current value is anchored by it. let avalue (#v:Type) (#p:preorder v) (anchors:anchor_rel p) = pv:(permission v & vhist p) { anchored anchors pv } /// initial_value: A utility to construct a value in the PCM #push-options "--fuel 1" let initial_value (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (value:v { anchors value value }) : avalue anchors = (Some full_perm, Some value), [value] #pop-options /// We add a unit element to [avalue], as needed for a PCM [@@erasable] noeq type knowledge (#v:Type) (#p:preorder v) (anchors:anchor_rel p) = | Owns : avalue anchors -> knowledge anchors | Nothing : knowledge anchors let b2p (b:bool) : prop = b == true /// Fractional permissions are composable when their sum <= 1.0 let perm_opt_composable (p0 p1:option perm) : prop = match p0, p1 with | None, None -> True | Some p, None | None, Some p -> b2p (p `lesser_equal_perm` full_perm) | Some p0, Some p1 -> b2p (sum_perm p0 p1 `lesser_equal_perm` full_perm) /// Composing them sums the permissions let compose_perm_opt (p0 p1:option perm) = match p0, p1 with | None, p | p, None -> p | Some p0, Some p1 -> Some (sum_perm p0 p1) /// Anchored permissions are composable when at most one of them has the anchor set let permission_composable #v (p0 p1 : permission v) : prop = let q0, s0 = p0 in let q1, s1 = p1 in perm_opt_composable q0 q1 /\ // some of fracs can't exceed 1 not (Some? s0 && Some? s1) // at most one can have an anchor /// Compose permissions component wise, keeping the anchor if set let compose_permissions (#v:_) (p0:permission v) (p1:permission v{permission_composable p0 p1}) : permission v = compose_perm_opt (fst p0) (fst p1), (match snd p0, snd p1 with | None, a | a, None -> a) /// This is the central definition of the PCM --- defining when two /// values are composable, or equivalently, when one thread's /// knowledge of [av0] is compatible with another thread's knowledge /// of [av1] /// /// This definition shows the interplay between fractions and anchors. /// It wasn't obvious to me how to factor this further, e.g., adding /// anchors to preorders and then separately adding fractions to it. let avalue_composable (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (av0 av1: avalue anchors) : prop = let (p0, v0) = av0 in let (p1, v1) = av1 in permission_composable p0 p1 /\ (if not (has_some_ownership p0) && not (has_some_ownership p1) then p_composable _ v0 v1 //neither has ownership, one history is older than the other else if not (has_some_ownership p0) && has_some_ownership p1 then ( if has_nonzero p1 then v1 `extends` v0 //the one with ownership is more recent else ( //this part is the most subtle assert (has_anchor p1); p_composable _ v0 v1 /\ (v0 `extends` v1 ==> //if v0 is a more recent snapshot than v1 //then v0 must still be anchored by v1's anchor anchor_of p1 `anchors` curval v0) ) ) else if has_some_ownership p0 && not (has_some_ownership p1) then ( //symmetric if has_nonzero p0 then v0 `extends` v1 else ( assert (has_anchor p0); p_composable _ v0 v1 /\ (v1 `extends` v0 ==> anchor_of p0 `anchors` curval v1) ) ) else ( assert (has_some_ownership p0 && has_some_ownership p1); if has_nonzero p0 && has_nonzero p1 then v0 == v1 //if both have non-zero perm, then they must both only have read permission and must agree on the value else if has_nonzero p0 && has_anchor p1 then ( assert (not (has_nonzero p1)); //The key part of the anchor semantics: v0 `extends` v1 /\ //v0 has advanceable ownership, so extends anchor_of p1 `anchors` curval v0 //but not beyond what is allowed by s ) else if has_anchor p0 && has_nonzero p1 //symmetric then ( assert (not (has_nonzero p0)); v1 `extends` v0 /\ anchor_of p0 `anchors` curval v1 //v1 extends, but not beyond what is allowed by s ) else (assert false; False) ) ) //exhaustive /// Lifting avalue comosability to knowledge, including the unit let composable #v (#p:preorder v) (#a:anchor_rel p) : symrel (knowledge a) = fun (k0 k1:knowledge a) -> match k0, k1 with | Nothing, _ | _, Nothing -> True | Owns m, Owns m' -> avalue_composable m m' /// Compose avalues by composing permissions and composing the values /// using the underlying preorder PCM let compose_avalue (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (m0:avalue anchors) (m1:avalue anchors { avalue_composable m0 m1 } ) : avalue anchors = let p0, v0 = m0 in let p1, v1 = m1 in let p12 = compose_permissions p0 p1 in let v12 = p_op _ v0 v1 in p12, v12 //////////////////////////////////////////////////////////////////////////////// (** avalue composition is associative and commutative **) let compose_avalue_comm (#v:Type) (#p:preorder v) (#anc:anchor_rel p) (m0: avalue anc) (m1: avalue anc{ avalue_composable m0 m1 }) : Lemma (compose_avalue m0 m1 == compose_avalue m1 m0) = () let avalue_composable_assoc_l (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (m0: avalue anchors) (m1: avalue anchors) (m2: avalue anchors { avalue_composable m1 m2 /\ avalue_composable m0 (compose_avalue m1 m2) }) : Lemma (avalue_composable m0 m1 /\ avalue_composable (compose_avalue m0 m1) m2) = () let compose_avalue_assoc_l (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m0: avalue s) (m1: avalue s) (m2: avalue s { avalue_composable m1 m2 /\ avalue_composable m0 (compose_avalue m1 m2) }) : Lemma (avalue_composable m0 m1 /\ avalue_composable (compose_avalue m0 m1) m2 /\ compose_avalue m0 (compose_avalue m1 m2) == compose_avalue (compose_avalue m0 m1) m2) = avalue_composable_assoc_l m0 m1 m2 let avalue_composable_assoc_r (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (m0: avalue anchors) (m1: avalue anchors) (m2: avalue anchors { avalue_composable m0 m1 /\ avalue_composable (compose_avalue m0 m1) m2 }) : Lemma (avalue_composable m1 m2 /\ avalue_composable m0 (compose_avalue m1 m2)) = () let compose_avalue_assoc_r (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m0: avalue s) (m1: avalue s) (m2: avalue s{ avalue_composable m0 m1 /\ avalue_composable (compose_avalue m0 m1) m2 }) : Lemma (avalue_composable m1 m2 /\ avalue_composable m0 (compose_avalue m1 m2) /\ compose_avalue m0 (compose_avalue m1 m2) == compose_avalue (compose_avalue m0 m1) m2) = avalue_composable_assoc_r m0 m1 m2 //////////////////////////////////////////////////////////////////////////////// /// lifting avalue composition to knowledge, including unit let compose (#v:Type) (#p:preorder v) (#s:anchor_rel p) (k0:knowledge s) (k1:knowledge s{ composable k0 k1 }) : knowledge s = match k0, k1 with | Nothing, k | k, Nothing -> k | Owns m, Owns m' -> Owns (compose_avalue m m') let composable_assoc_r #v (#p:preorder v) (#s:anchor_rel p) (k0 k1 k2: knowledge s) : Lemma (requires composable k0 k1 /\ composable (compose k0 k1) k2) (ensures composable k1 k2 /\ composable k0 (compose k1 k2) /\ compose k0 (compose k1 k2) == compose (compose k0 k1) k2 ) = match k0, k1, k2 with | Nothing, _, _ | _, Nothing, _ | _, _, Nothing -> () | Owns m0, Owns m1, Owns m2 -> compose_avalue_assoc_r m0 m1 m2 let composable_assoc_l #v (#p:preorder v) (#s:anchor_rel p) (k0 k1 k2: knowledge s) : Lemma (requires composable k1 k2 /\ composable k0 (compose k1 k2)) (ensures composable k0 k1 /\ composable (compose k0 k1) k2 /\ compose k0 (compose k1 k2) == compose (compose k0 k1) k2) = match k0, k1, k2 with | Nothing, _, _ | _, Nothing, _ | _, _, Nothing -> () | Owns m0, Owns m1, Owns m2 -> compose_avalue_assoc_l m0 m1 m2 /// Now, we can define our PCM /// The core of the PCM let p0 #v #p #s : pcm' (knowledge #v #p s) = { composable; op=compose; one=Nothing } let avalue_perm (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) = fst m /// A avalue represents full ownership when the fraction is full AND /// the anchor is set. This means that no knowledge held by any other /// thread can constrain this value meaningfully. let avalue_owns (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) : prop = fst (avalue_perm m) == Some full_perm /\ Some? (snd (avalue_perm m)) let full_knowledge #v #p #s (kn:knowledge #v #p s) : prop = match kn with | Nothing -> False | Owns km -> avalue_owns km /// The PCM itself, together with proofs of its properties let pcm #v #p #s : pcm (knowledge #v #p s) = { p = p0; comm = (fun k0 k1 -> match k0, k1 with | Nothing, _ | _, Nothing -> () | Owns m0, Owns m1 -> compose_avalue_comm m0 m1); assoc = (fun k0 k1 k2 -> composable_assoc_l k0 k1 k2); assoc_r = (fun k0 k1 k2 -> composable_assoc_r k0 k1 k2); is_unit = (fun _ -> ()); refine = full_knowledge; } /// Some utilities: The value of an avalue let avalue_val (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue #v #p s) = snd m /// Updating the value, in a full-ownership situation, also involves /// updating the anchor let avalue_update (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) (value:vhist p { s (curval value) (curval value) }) : avalue s = let p, _ = avalue_perm m in let p' = p, Some (curval value) in (p', value) /// Our core frame-preserving update: /// /// If you fully own a value, you can update it so long as you /// respect the preorder, and prove that the new value is related /// to itself by the anchor (since we'll be setting the anchor to /// the new value) /// /// This is a building block: we'll define a derived version that /// on values rather than histories #push-options "--z3rlimit_factor 2" let update_hist (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) (v1:vhist p { avalue_owns m /\ v1 `extends` avalue_val m /\ s (curval v1) (curval v1) }) : frame_preserving_upd pcm (Owns m) (Owns (avalue_update m v1)) = fun full_v -> let Owns full_m = full_v in let m_res = avalue_update full_m v1 in Owns m_res #pop-options /// Updating with value, rather than a history let avalue_update_value (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) (value:v { curval (avalue_val m) `p` value /\ s value value }) : m':avalue s { curval (avalue_val m') == value /\ avalue_val m' `extends` avalue_val m } = let v = avalue_val m in avalue_update m (extend_history v value) /// A derived frame-preserving update for which one presents only a value let update_value (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) (v1:v { avalue_owns m /\ //if you have full ownership of key curval (avalue_val m) `p` v1 /\ //you can update it wrt the preorder only s v1 v1 //and it is related to itself by the anchor }) : frame_preserving_upd pcm (Owns m) (Owns (avalue_update_value m v1)) = coerce_eq () (update_hist m (extend_history (avalue_val m) v1)) //F* goes nuts and starts swallowing gobs of memory without the coerce_eq: TODO, debug /// Now for anchored updates /// Ownership of the whole fraction, but not the anchor let avalue_owns_anchored (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) = fst (avalue_perm m) == Some full_perm /\ None? (snd (avalue_perm m)) /// [v1] is compatible with (i.e., not too far from) any anchor of [v0] let compat_with_any_anchor_of (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (v1:v) (v0:avalue anchors) = forall (anchor:v). anchor `anchors` curval (avalue_val v0) ==> anchor `anchors` v1 /// An anchored update: Update the value, but leave the permission /// unchanged Only possible if the new value is compatible with any
{ "checked_file": "/", "dependencies": [ "Steel.Preorder.fst.checked", "Steel.FractionalPermission.fst.checked", "prims.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked" ], "interface_file": false, "source_file": "Steel.FractionalAnchoredPreorder.fst" }
[ { "abbrev": false, "full_module": "Steel.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Steel.Preorder", "short_module": null }, { "abbrev": false, "full_module": "FStar.Preorder", "short_module": null }, { "abbrev": false, "full_module": "FStar.PCM", "short_module": null }, { "abbrev": false, "full_module": "Steel", "short_module": null }, { "abbrev": false, "full_module": "Steel", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
m: Steel.FractionalAnchoredPreorder.avalue s -> value: Steel.Preorder.vhist p {Steel.FractionalAnchoredPreorder.compat_with_any_anchor_of (Steel.Preorder.curval value) m} -> Steel.FractionalAnchoredPreorder.avalue s
Prims.Tot
[ "total" ]
[]
[ "FStar.Preorder.preorder", "Steel.FractionalAnchoredPreorder.anchor_rel", "Steel.FractionalAnchoredPreorder.avalue", "Steel.Preorder.vhist", "Steel.FractionalAnchoredPreorder.compat_with_any_anchor_of", "Steel.Preorder.curval", "FStar.Pervasives.Native.Mktuple2", "Steel.FractionalAnchoredPreorder.permission", "Steel.FractionalAnchoredPreorder.avalue_perm" ]
[]
false
false
false
false
false
let avalue_anchored_update (#v: Type) (#p: preorder v) (#s: anchor_rel p) (m: avalue s) (value: vhist p {(curval value) `compat_with_any_anchor_of` m}) : avalue s =
avalue_perm m, value
false
Vale.Arch.Types.fsti
Vale.Arch.Types.sub_wrap64
val sub_wrap64 (x y: nat64) : nat64
val sub_wrap64 (x y: nat64) : nat64
let sub_wrap64 (x:nat64) (y:nat64) : nat64 = sub_wrap x y
{ "file_name": "vale/code/arch/Vale.Arch.Types.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 64, "end_line": 21, "start_col": 7, "start_line": 21 }
module Vale.Arch.Types open FStar.Mul open Vale.Def.Opaque_s open Vale.Def.Types_s open Vale.Lib.Seqs_s open Vale.Lib.Seqs open Vale.Def.Words_s open Vale.Def.Words.Four_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Seq open FStar.Seq open Vale.Def.Words.Two_s unfold let ( *^ ) = nat32_xor unfold let ( *^^ ) = quad32_xor unfold let add_wrap32 (x:nat32) (y:nat32) : nat32 = add_wrap x y unfold let add_wrap64 (x:nat64) (y:nat64) : nat64 = add_wrap x y
{ "checked_file": "/", "dependencies": [ "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Two_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Seq.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.Arch.Types.fsti" }
[ { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
x: Vale.Def.Words_s.nat64 -> y: Vale.Def.Words_s.nat64 -> Vale.Def.Words_s.nat64
Prims.Tot
[ "total" ]
[]
[ "Vale.Def.Words_s.nat64", "Vale.Def.Types_s.sub_wrap", "Vale.Def.Words_s.pow2_64" ]
[]
false
false
false
true
false
let sub_wrap64 (x y: nat64) : nat64 =
sub_wrap x y
false
Steel.FractionalAnchoredPreorder.fst
Steel.FractionalAnchoredPreorder.compose_avalue_assoc_l
val compose_avalue_assoc_l (#v: Type) (#p: preorder v) (#s: anchor_rel p) (m0 m1: avalue s) (m2: avalue s {avalue_composable m1 m2 /\ avalue_composable m0 (compose_avalue m1 m2)}) : Lemma (avalue_composable m0 m1 /\ avalue_composable (compose_avalue m0 m1) m2 /\ compose_avalue m0 (compose_avalue m1 m2) == compose_avalue (compose_avalue m0 m1) m2)
val compose_avalue_assoc_l (#v: Type) (#p: preorder v) (#s: anchor_rel p) (m0 m1: avalue s) (m2: avalue s {avalue_composable m1 m2 /\ avalue_composable m0 (compose_avalue m1 m2)}) : Lemma (avalue_composable m0 m1 /\ avalue_composable (compose_avalue m0 m1) m2 /\ compose_avalue m0 (compose_avalue m1 m2) == compose_avalue (compose_avalue m0 m1) m2)
let compose_avalue_assoc_l (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m0: avalue s) (m1: avalue s) (m2: avalue s { avalue_composable m1 m2 /\ avalue_composable m0 (compose_avalue m1 m2) }) : Lemma (avalue_composable m0 m1 /\ avalue_composable (compose_avalue m0 m1) m2 /\ compose_avalue m0 (compose_avalue m1 m2) == compose_avalue (compose_avalue m0 m1) m2) = avalue_composable_assoc_l m0 m1 m2
{ "file_name": "lib/steel/Steel.FractionalAnchoredPreorder.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 37, "end_line": 289, "start_col": 0, "start_line": 278 }
(* Copyright 2021 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. Author: N. Swamy *) module Steel.FractionalAnchoredPreorder (** This module provides a partial commutative monoid (PCM) for use in the ghost state of a concurrent Steel program. Its goal is to facilitate a form of information-sharing between multiple threads including the following features: Fractions, Preorders, Snapshots, and Anchors --- Anchors are the most unusual. 1. Fractions: Ownership of the state is controlled by a fractional permission, so multiple threads may share read-only privileges on the state, but only one can have write permission. 2. Preorders: The ghost state is governed by a preorder p and all updates to the state must respect the preorder (a reflexive, transitive relation on the state) 3. Snapshots: Since the state always evolves by a preorder, it is possible to take a snapshot of the state. A snapshot does not confer any particular ownership on the state, except knowledge of a snapshot ensures that the current state is related to the snapshot by the preorder. 4. Anchors are a kind of refinement of the preorder. If a thread owns an anchored value [v], then no other thread, even a thread owning a full fractional permission, can advance the state "too far" from the anchor. In particular, the PCM is parameterized by a binary relation on values, [anchors:anchor_relation]. If a thread owns the anchor [v], then the current value `cur` of the state must be in relation [v `anchors` cur]. This can be used to ensure that the knowledge of one thread is never becomes too stale. For example, this allows one to model a shared monotonically increasing counter, where if one thread anchors knowledge of the counter at the value 5, no other thread can increase the value of the counter beyond, say, 10, (when the anchor relation is y - x <= 5), until the anchoring thread releases the anchor. Further, at any point, a thread can take a snapshot of the counter and rely on the fact that the value of the counter in the future will be >= the snapshot. *) open FStar.PCM open FStar.Preorder open Steel.Preorder open Steel.FractionalPermission #push-options "--fuel 0 --ifuel 2" /// A permission: is a pair of /// /// * an optional fractional permission; with `Some p` indicating /// some ownership, while `None` is an additional "0" permission /// value, to encode snapshots. /// /// * and an optional anchor, where `Some a` indicates the current /// value can't be too far from `a`. let permission (v:Type) = option perm & option v /// Non-zero permission is either a read or write permission let has_nonzero #v (p:permission v) = Some? (fst p) /// Has an anchor set let has_anchor #v (p:permission v) = Some? (snd p) /// Either an anchor or non-zero let has_some_ownership #v (p:permission v) = has_nonzero p || has_anchor p /// The anchoring value let anchor_of #v (p:permission v { has_anchor p }) : v = Some?.v (snd p) /// The anchoring relation: /// -- A binary relation on values /// -- refining the preorder /// -- and if x `anchors` z then it also anchors any `y` between `x` and `z` /// /// Explaining the third clause a bit: /// Think intuitively of anchoring relations as a kind of distance measure /// /// if `z` is close enough to `x` then if `z` is further than `y` /// (since it is ahead of `y` in the preorder) then `y` is also /// close enough to `x` let anchor_rel (#v:Type) (p:preorder v) = anchors:(v -> v -> prop) { (forall v0 v1. anchors v0 v1 ==> p v0 v1) /\ (forall x z. x `anchors` z ==> (forall y. p x y /\ p y z ==> x `anchors` y)) // } /// An implementation remark: We use Steel.Preorder here to /// generically transform any preorder into a PCM. That works by /// taking the value of the PCM to be a history of values related by /// the preorder. So, throughout, we'll be using the the [vhist p] /// from Steel.Preorder, the type of a non-empty history compatible /// with [p]. The details of the histories don't matter much for our /// purposes---we only care about the most recent value, for which /// we'll use [curval v]. /// If the anchor is set, then the current value is anchored by it let anchored (#v:Type) (#p:preorder v) (anchors:anchor_rel p) (pv:(permission v & vhist p)) = has_anchor (fst pv) ==> anchor_of (fst pv) `anchors` curval (snd pv) /// A value in our fractional anchored PCM is a pair of a permission /// and a p-compatible history, refined to ensure that if the anchor /// is set, then the current value is anchored by it. let avalue (#v:Type) (#p:preorder v) (anchors:anchor_rel p) = pv:(permission v & vhist p) { anchored anchors pv } /// initial_value: A utility to construct a value in the PCM #push-options "--fuel 1" let initial_value (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (value:v { anchors value value }) : avalue anchors = (Some full_perm, Some value), [value] #pop-options /// We add a unit element to [avalue], as needed for a PCM [@@erasable] noeq type knowledge (#v:Type) (#p:preorder v) (anchors:anchor_rel p) = | Owns : avalue anchors -> knowledge anchors | Nothing : knowledge anchors let b2p (b:bool) : prop = b == true /// Fractional permissions are composable when their sum <= 1.0 let perm_opt_composable (p0 p1:option perm) : prop = match p0, p1 with | None, None -> True | Some p, None | None, Some p -> b2p (p `lesser_equal_perm` full_perm) | Some p0, Some p1 -> b2p (sum_perm p0 p1 `lesser_equal_perm` full_perm) /// Composing them sums the permissions let compose_perm_opt (p0 p1:option perm) = match p0, p1 with | None, p | p, None -> p | Some p0, Some p1 -> Some (sum_perm p0 p1) /// Anchored permissions are composable when at most one of them has the anchor set let permission_composable #v (p0 p1 : permission v) : prop = let q0, s0 = p0 in let q1, s1 = p1 in perm_opt_composable q0 q1 /\ // some of fracs can't exceed 1 not (Some? s0 && Some? s1) // at most one can have an anchor /// Compose permissions component wise, keeping the anchor if set let compose_permissions (#v:_) (p0:permission v) (p1:permission v{permission_composable p0 p1}) : permission v = compose_perm_opt (fst p0) (fst p1), (match snd p0, snd p1 with | None, a | a, None -> a) /// This is the central definition of the PCM --- defining when two /// values are composable, or equivalently, when one thread's /// knowledge of [av0] is compatible with another thread's knowledge /// of [av1] /// /// This definition shows the interplay between fractions and anchors. /// It wasn't obvious to me how to factor this further, e.g., adding /// anchors to preorders and then separately adding fractions to it. let avalue_composable (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (av0 av1: avalue anchors) : prop = let (p0, v0) = av0 in let (p1, v1) = av1 in permission_composable p0 p1 /\ (if not (has_some_ownership p0) && not (has_some_ownership p1) then p_composable _ v0 v1 //neither has ownership, one history is older than the other else if not (has_some_ownership p0) && has_some_ownership p1 then ( if has_nonzero p1 then v1 `extends` v0 //the one with ownership is more recent else ( //this part is the most subtle assert (has_anchor p1); p_composable _ v0 v1 /\ (v0 `extends` v1 ==> //if v0 is a more recent snapshot than v1 //then v0 must still be anchored by v1's anchor anchor_of p1 `anchors` curval v0) ) ) else if has_some_ownership p0 && not (has_some_ownership p1) then ( //symmetric if has_nonzero p0 then v0 `extends` v1 else ( assert (has_anchor p0); p_composable _ v0 v1 /\ (v1 `extends` v0 ==> anchor_of p0 `anchors` curval v1) ) ) else ( assert (has_some_ownership p0 && has_some_ownership p1); if has_nonzero p0 && has_nonzero p1 then v0 == v1 //if both have non-zero perm, then they must both only have read permission and must agree on the value else if has_nonzero p0 && has_anchor p1 then ( assert (not (has_nonzero p1)); //The key part of the anchor semantics: v0 `extends` v1 /\ //v0 has advanceable ownership, so extends anchor_of p1 `anchors` curval v0 //but not beyond what is allowed by s ) else if has_anchor p0 && has_nonzero p1 //symmetric then ( assert (not (has_nonzero p0)); v1 `extends` v0 /\ anchor_of p0 `anchors` curval v1 //v1 extends, but not beyond what is allowed by s ) else (assert false; False) ) ) //exhaustive /// Lifting avalue comosability to knowledge, including the unit let composable #v (#p:preorder v) (#a:anchor_rel p) : symrel (knowledge a) = fun (k0 k1:knowledge a) -> match k0, k1 with | Nothing, _ | _, Nothing -> True | Owns m, Owns m' -> avalue_composable m m' /// Compose avalues by composing permissions and composing the values /// using the underlying preorder PCM let compose_avalue (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (m0:avalue anchors) (m1:avalue anchors { avalue_composable m0 m1 } ) : avalue anchors = let p0, v0 = m0 in let p1, v1 = m1 in let p12 = compose_permissions p0 p1 in let v12 = p_op _ v0 v1 in p12, v12 //////////////////////////////////////////////////////////////////////////////// (** avalue composition is associative and commutative **) let compose_avalue_comm (#v:Type) (#p:preorder v) (#anc:anchor_rel p) (m0: avalue anc) (m1: avalue anc{ avalue_composable m0 m1 }) : Lemma (compose_avalue m0 m1 == compose_avalue m1 m0) = () let avalue_composable_assoc_l (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (m0: avalue anchors) (m1: avalue anchors) (m2: avalue anchors { avalue_composable m1 m2 /\ avalue_composable m0 (compose_avalue m1 m2) }) : Lemma (avalue_composable m0 m1 /\ avalue_composable (compose_avalue m0 m1) m2) = ()
{ "checked_file": "/", "dependencies": [ "Steel.Preorder.fst.checked", "Steel.FractionalPermission.fst.checked", "prims.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked" ], "interface_file": false, "source_file": "Steel.FractionalAnchoredPreorder.fst" }
[ { "abbrev": false, "full_module": "Steel.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Steel.Preorder", "short_module": null }, { "abbrev": false, "full_module": "FStar.Preorder", "short_module": null }, { "abbrev": false, "full_module": "FStar.PCM", "short_module": null }, { "abbrev": false, "full_module": "Steel", "short_module": null }, { "abbrev": false, "full_module": "Steel", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
m0: Steel.FractionalAnchoredPreorder.avalue s -> m1: Steel.FractionalAnchoredPreorder.avalue s -> m2: Steel.FractionalAnchoredPreorder.avalue s { Steel.FractionalAnchoredPreorder.avalue_composable m1 m2 /\ Steel.FractionalAnchoredPreorder.avalue_composable m0 (Steel.FractionalAnchoredPreorder.compose_avalue m1 m2) } -> FStar.Pervasives.Lemma (ensures Steel.FractionalAnchoredPreorder.avalue_composable m0 m1 /\ Steel.FractionalAnchoredPreorder.avalue_composable (Steel.FractionalAnchoredPreorder.compose_avalue m0 m1) m2 /\ Steel.FractionalAnchoredPreorder.compose_avalue m0 (Steel.FractionalAnchoredPreorder.compose_avalue m1 m2) == Steel.FractionalAnchoredPreorder.compose_avalue (Steel.FractionalAnchoredPreorder.compose_avalue m0 m1) m2)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "FStar.Preorder.preorder", "Steel.FractionalAnchoredPreorder.anchor_rel", "Steel.FractionalAnchoredPreorder.avalue", "Prims.l_and", "Steel.FractionalAnchoredPreorder.avalue_composable", "Steel.FractionalAnchoredPreorder.compose_avalue", "Steel.FractionalAnchoredPreorder.avalue_composable_assoc_l", "Prims.unit", "Prims.l_True", "Prims.squash", "Prims.eq2", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
true
false
true
false
false
let compose_avalue_assoc_l (#v: Type) (#p: preorder v) (#s: anchor_rel p) (m0 m1: avalue s) (m2: avalue s {avalue_composable m1 m2 /\ avalue_composable m0 (compose_avalue m1 m2)}) : Lemma (avalue_composable m0 m1 /\ avalue_composable (compose_avalue m0 m1) m2 /\ compose_avalue m0 (compose_avalue m1 m2) == compose_avalue (compose_avalue m0 m1) m2) =
avalue_composable_assoc_l m0 m1 m2
false
Vale.Arch.Types.fsti
Vale.Arch.Types.iand32
val iand32 (a b: nat32) : nat32
val iand32 (a b: nat32) : nat32
let iand32 (a:nat32) (b:nat32) : nat32 = iand a b
{ "file_name": "vale/code/arch/Vale.Arch.Types.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 56, "end_line": 23, "start_col": 7, "start_line": 23 }
module Vale.Arch.Types open FStar.Mul open Vale.Def.Opaque_s open Vale.Def.Types_s open Vale.Lib.Seqs_s open Vale.Lib.Seqs open Vale.Def.Words_s open Vale.Def.Words.Four_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Seq open FStar.Seq open Vale.Def.Words.Two_s unfold let ( *^ ) = nat32_xor unfold let ( *^^ ) = quad32_xor unfold let add_wrap32 (x:nat32) (y:nat32) : nat32 = add_wrap x y unfold let add_wrap64 (x:nat64) (y:nat64) : nat64 = add_wrap x y unfold let sub_wrap32 (x:nat32) (y:nat32) : nat32 = sub_wrap x y unfold let sub_wrap64 (x:nat64) (y:nat64) : nat64 = sub_wrap x y
{ "checked_file": "/", "dependencies": [ "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Two_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Seq.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.Arch.Types.fsti" }
[ { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Vale.Def.Words_s.nat32 -> b: Vale.Def.Words_s.nat32 -> Vale.Def.Words_s.nat32
Prims.Tot
[ "total" ]
[]
[ "Vale.Def.Words_s.nat32", "Vale.Def.Types_s.iand", "Vale.Def.Words_s.pow2_32" ]
[]
false
false
false
true
false
let iand32 (a b: nat32) : nat32 =
iand a b
false
Vale.Arch.Types.fsti
Vale.Arch.Types.sub_wrap32
val sub_wrap32 (x y: nat32) : nat32
val sub_wrap32 (x y: nat32) : nat32
let sub_wrap32 (x:nat32) (y:nat32) : nat32 = sub_wrap x y
{ "file_name": "vale/code/arch/Vale.Arch.Types.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 64, "end_line": 20, "start_col": 7, "start_line": 20 }
module Vale.Arch.Types open FStar.Mul open Vale.Def.Opaque_s open Vale.Def.Types_s open Vale.Lib.Seqs_s open Vale.Lib.Seqs open Vale.Def.Words_s open Vale.Def.Words.Four_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Seq open FStar.Seq open Vale.Def.Words.Two_s unfold let ( *^ ) = nat32_xor unfold let ( *^^ ) = quad32_xor unfold let add_wrap32 (x:nat32) (y:nat32) : nat32 = add_wrap x y
{ "checked_file": "/", "dependencies": [ "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Two_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Seq.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.Arch.Types.fsti" }
[ { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
x: Vale.Def.Words_s.nat32 -> y: Vale.Def.Words_s.nat32 -> Vale.Def.Words_s.nat32
Prims.Tot
[ "total" ]
[]
[ "Vale.Def.Words_s.nat32", "Vale.Def.Types_s.sub_wrap", "Vale.Def.Words_s.pow2_32" ]
[]
false
false
false
true
false
let sub_wrap32 (x y: nat32) : nat32 =
sub_wrap x y
false
Hacl.Poly1305.Field32xN.Lemmas0.fst
Hacl.Poly1305.Field32xN.Lemmas0.mul_felem5_lemma
val mul_felem5_lemma: f1:tup64_5{tup64_fits5 f1 (3, 3, 3, 3, 3)} -> r:tup64_5{tup64_fits5 r (2, 2, 2, 2, 2)} -> Lemma (let (f10, f11, f12, f13, f14) = f1 in let (r0, r1, r2, r3, r4) = r in (as_pfelem5 f1) `pfmul` (as_pfelem5 r) == (v f10 * as_nat5 (r0, r1, r2, r3, r4) + v f11 * as_nat5 (r4 *! u64 5, r0, r1, r2, r3) + v f12 * as_nat5 (r3 *! u64 5, r4 *! u64 5, r0, r1, r2) + v f13 * as_nat5 (r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0, r1) + v f14 * as_nat5 (r1 *! u64 5, r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0)) % prime)
val mul_felem5_lemma: f1:tup64_5{tup64_fits5 f1 (3, 3, 3, 3, 3)} -> r:tup64_5{tup64_fits5 r (2, 2, 2, 2, 2)} -> Lemma (let (f10, f11, f12, f13, f14) = f1 in let (r0, r1, r2, r3, r4) = r in (as_pfelem5 f1) `pfmul` (as_pfelem5 r) == (v f10 * as_nat5 (r0, r1, r2, r3, r4) + v f11 * as_nat5 (r4 *! u64 5, r0, r1, r2, r3) + v f12 * as_nat5 (r3 *! u64 5, r4 *! u64 5, r0, r1, r2) + v f13 * as_nat5 (r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0, r1) + v f14 * as_nat5 (r1 *! u64 5, r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0)) % prime)
let mul_felem5_lemma f1 r = let (f10, f11, f12, f13, f14) = f1 in let (r0, r1, r2, r3, r4) = r in mul_felem5_lemma_4 f1 r; FStar.Math.Lemmas.lemma_mod_mul_distr_l (as_nat5 f1) (as_nat5 r) prime; FStar.Math.Lemmas.lemma_mod_mul_distr_r (as_nat5 f1 % prime) (as_nat5 r) prime
{ "file_name": "code/poly1305/Hacl.Poly1305.Field32xN.Lemmas0.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 80, "end_line": 653, "start_col": 0, "start_line": 648 }
module Hacl.Poly1305.Field32xN.Lemmas0 open Lib.IntTypes open Lib.IntVector open Lib.Sequence open FStar.Mul open FStar.Calc open Hacl.Spec.Poly1305.Vec include Hacl.Spec.Poly1305.Field32xN #reset-options "--z3rlimit 50 --using_facts_from '* -FStar.Seq' --max_fuel 0 --max_ifuel 0" val lemma_prime: unit -> Lemma (pow2 130 % prime = 5) let lemma_prime () = assert_norm (pow2 130 % prime = 5 % prime); assert_norm (5 < prime); FStar.Math.Lemmas.modulo_lemma 5 prime val lemma_mult_le: a:nat -> b:nat -> c:nat -> d:nat -> Lemma (requires a <= b /\ c <= d) (ensures a * c <= b * d) let lemma_mult_le a b c d = () val lemma_mul5_distr_l: a:nat -> b:nat -> c:nat -> d:nat -> e:nat -> f:nat -> Lemma (a * (b + c + d + e + f) == a * b + a * c + a * d + a * e + a * f) let lemma_mul5_distr_l a b c d e f = () val lemma_mul5_distr_r: a:nat -> b:nat -> c:nat -> d:nat -> e:nat -> f:nat -> Lemma ((a + b + c + d + e) * f == a * f + b * f + c * f + d * f + e * f) let lemma_mul5_distr_r a b c d e f = () val smul_mod_lemma: #m1:scale32 -> #m2:scale32 -> a:nat{a <= m1 * max26} -> b:nat{b <= m2 * max26} -> Lemma (a * b % pow2 64 == a * b) let smul_mod_lemma #m1 #m2 a b = lemma_mult_le a (m1 * max26) b (m2 * max26); assert (a * b <= m1 * m2 * max26 * max26); FStar.Math.Lemmas.modulo_lemma (a * b) (pow2 64) val smul_add_mod_lemma: #m1:scale32 -> #m2:scale32 -> #m3:scale64{m3 + m1 * m2 <= 4096} -> a:nat{a <= m1 * max26} -> b:nat{b <= m2 * max26} -> c:nat{c <= m3 * max26 * max26} -> Lemma ((c + a * b % pow2 64) % pow2 64 == c + a * b) let smul_add_mod_lemma #m1 #m2 #m3 a b c = assert_norm ((m3 + m1 * m2) * max26 * max26 < pow2 64); lemma_mult_le a (m1 * max26) b (m2 * max26); assert (c + a * b <= m3 * max26 * max26 + m1 * m2 * max26 * max26); FStar.Math.Lemmas.modulo_lemma (c + a * b) (pow2 64) val add5_lemma1: ma:scale64 -> mb:scale64 -> a:uint64 -> b:uint64 -> Lemma (requires v a <= ma * max26 /\ v b <= mb * max26 /\ ma + mb <= 64) (ensures v (a +. b) == v a + v b /\ v (a +. b) <= (ma + mb) * max26) let add5_lemma1 ma mb a b = assert (v a + v b <= (ma + mb) * max26); Math.Lemmas.lemma_mult_le_right max26 (ma + mb) 64; assert (v a + v b <= 64 * max26); assert_norm (64 * max26 < pow2 32); Math.Lemmas.small_mod (v a + v b) (pow2 32) #set-options "--ifuel 1" val fadd5_eval_lemma_i: #w:lanes -> f1:felem5 w{felem_fits5 f1 (2,2,2,2,2)} -> f2:felem5 w{felem_fits5 f2 (1,1,1,1,1)} -> i:nat{i < w} -> Lemma ((feval5 (fadd5 f1 f2)).[i] == pfadd (feval5 f1).[i] (feval5 f2).[i]) let fadd5_eval_lemma_i #w f1 f2 i = let o = fadd5 f1 f2 in let (f10, f11, f12, f13, f14) = as_tup64_i f1 i in let (f20, f21, f22, f23, f24) = as_tup64_i f2 i in let (o0, o1, o2, o3, o4) = as_tup64_i o i in add5_lemma1 2 1 f10 f20; add5_lemma1 2 1 f11 f21; add5_lemma1 2 1 f12 f22; add5_lemma1 2 1 f13 f23; add5_lemma1 2 1 f14 f24; assert (as_nat5 (o0, o1, o2, o3, o4) == as_nat5 (f10, f11, f12, f13, f14) + as_nat5 (f20, f21, f22, f23, f24)); FStar.Math.Lemmas.lemma_mod_plus_distr_l (as_nat5 (f10, f11, f12, f13, f14)) (as_nat5 (f20, f21, f22, f23, f24)) prime; FStar.Math.Lemmas.lemma_mod_plus_distr_r (as_nat5 (f10, f11, f12, f13, f14) % prime) (as_nat5 (f20, f21, f22, f23, f24)) prime val smul_felem5_fits_lemma_i: #w:lanes -> #m1:scale32 -> #m2:scale32 -> u1:uint64xN w{felem_fits1 u1 m1} -> f2:uint64xN w{felem_fits1 f2 m2} -> i:nat{i < w} -> Lemma ((uint64xN_v (vec_mul_mod f2 u1)).[i] <= m1 * m2 * max26 * max26) let smul_felem5_fits_lemma_i #w #m1 #m2 u1 f2 i = let o = vec_mul_mod f2 u1 in smul_mod_lemma #m1 #m2 (uint64xN_v u1).[i] (uint64xN_v f2).[i]; assert ((uint64xN_v o).[i] == (uint64xN_v u1).[i] * (uint64xN_v f2).[i]); lemma_mult_le (uint64xN_v u1).[i] (m1 * max26) (uint64xN_v f2).[i] (m2 * max26) val smul_felem5_eval_lemma_i: #w:lanes -> #m1:scale32 -> #m2:scale32_5 -> u1:uint64xN w{felem_fits1 u1 m1} -> f2:felem5 w{felem_fits5 f2 m2} -> i:nat{i < w} -> Lemma ((fas_nat5 (smul_felem5 #w u1 f2)).[i] == (uint64xN_v u1).[i] * (fas_nat5 f2).[i]) let smul_felem5_eval_lemma_i #w #m1 #m2 u1 f2 i = let o = smul_felem5 #w u1 f2 in let (m20, m21, m22, m23, m24) = m2 in let vu1 = (uint64xN_v u1).[i] in let (tf20, tf21, tf22, tf23, tf24) = as_tup64_i f2 i in let (to0, to1, to2, to3, to4) = as_tup64_i o i in smul_mod_lemma #m1 #m20 vu1 (v tf20); smul_mod_lemma #m1 #m21 vu1 (v tf21); smul_mod_lemma #m1 #m22 vu1 (v tf22); smul_mod_lemma #m1 #m23 vu1 (v tf23); smul_mod_lemma #m1 #m24 vu1 (v tf24); assert ((fas_nat5 o).[i] == vu1 * v tf20 + vu1 * v tf21 * pow26 + vu1 * v tf22 * pow52 + vu1 * v tf23 * pow78 + vu1 * v tf24 * pow104); calc (==) { vu1 * (fas_nat5 f2).[i]; (==) { } vu1 * (v tf20 + v tf21 * pow26 + v tf22 * pow52 + v tf23 * pow78 + v tf24 * pow104); (==) { lemma_mul5_distr_l vu1 (v tf20) (v tf21 * pow26) (v tf22 * pow52) (v tf23 * pow78) (v tf24 * pow104)} vu1 * v tf20 + vu1 * (v tf21 * pow26) + vu1 * (v tf22 * pow52) + vu1 * (v tf23 * pow78) + vu1 * (v tf24 * pow104); (==) { FStar.Math.Lemmas.paren_mul_right vu1 (v tf21) pow26; FStar.Math.Lemmas.paren_mul_right vu1 (v tf22) pow52; FStar.Math.Lemmas.paren_mul_right vu1 (v tf23) pow78; FStar.Math.Lemmas.paren_mul_right vu1 (v tf24) pow104} vu1 * v tf20 + vu1 * v tf21 * pow26 + vu1 * v tf22 * pow52 + vu1 * v tf23 * pow78 + vu1 * v tf24 * pow104; }; assert (vu1 * (fas_nat5 f2).[i] == (fas_nat5 o).[i]) val smul_felem5_fits_lemma1: #w:lanes -> #m1:scale32 -> #m2:scale32 -> u1:uint64xN w{felem_fits1 u1 m1} -> f2:uint64xN w{felem_fits1 f2 m2} -> Lemma (felem_wide_fits1 (vec_mul_mod f2 u1) (m1 * m2)) let smul_felem5_fits_lemma1 #w #m1 #m2 u1 f2 = match w with | 1 -> smul_felem5_fits_lemma_i #w #m1 #m2 u1 f2 0 | 2 -> smul_felem5_fits_lemma_i #w #m1 #m2 u1 f2 0; smul_felem5_fits_lemma_i #w #m1 #m2 u1 f2 1 | 4 -> smul_felem5_fits_lemma_i #w #m1 #m2 u1 f2 0; smul_felem5_fits_lemma_i #w #m1 #m2 u1 f2 1; smul_felem5_fits_lemma_i #w #m1 #m2 u1 f2 2; smul_felem5_fits_lemma_i #w #m1 #m2 u1 f2 3 val smul_felem5_fits_lemma: #w:lanes -> #m1:scale32 -> #m2:scale32_5 -> u1:uint64xN w{felem_fits1 u1 m1} -> f2:felem5 w{felem_fits5 f2 m2} -> Lemma (felem_wide_fits5 (smul_felem5 #w u1 f2) (m1 *^ m2)) let smul_felem5_fits_lemma #w #m1 #m2 u1 f2 = let (f20, f21, f22, f23, f24) = f2 in let (m20, m21, m22, m23, m24) = m2 in smul_felem5_fits_lemma1 #w #m1 #m20 u1 f20; smul_felem5_fits_lemma1 #w #m1 #m21 u1 f21; smul_felem5_fits_lemma1 #w #m1 #m22 u1 f22; smul_felem5_fits_lemma1 #w #m1 #m23 u1 f23; smul_felem5_fits_lemma1 #w #m1 #m24 u1 f24 val smul_felem5_eval_lemma: #w:lanes -> #m1:scale32 -> #m2:scale32_5 -> u1:uint64xN w{felem_fits1 u1 m1} -> f2:felem5 w{felem_fits5 f2 m2} -> Lemma (fas_nat5 (smul_felem5 #w u1 f2) == map2 #nat #nat #nat (fun a b -> a * b) (uint64xN_v u1) (fas_nat5 f2)) let smul_felem5_eval_lemma #w #m1 #m2 u1 f2 = FStar.Classical.forall_intro (smul_felem5_eval_lemma_i #w #m1 #m2 u1 f2); eq_intro (fas_nat5 (smul_felem5 #w u1 f2)) (map2 #nat #nat #nat (fun a b -> a * b) (uint64xN_v u1) (fas_nat5 f2)) val smul_add_felem5_fits_lemma_i: #w:lanes -> #m1:scale32 -> #m2:scale32 -> #m3:scale64{m3 + m1 * m2 <= 4096} -> u1:uint64xN w{felem_fits1 u1 m1} -> f2:uint64xN w{felem_fits1 f2 m2} -> acc1:uint64xN w{felem_wide_fits1 acc1 m3} -> i:nat{i < w} -> Lemma ((uint64xN_v (vec_add_mod acc1 (vec_mul_mod f2 u1))).[i] <= (m3 + m1 * m2) * max26 * max26) #push-options "--z3rlimit 200" let smul_add_felem5_fits_lemma_i #w #m1 #m2 #m3 u1 f2 acc1 i = let o = vec_add_mod acc1 (vec_mul_mod f2 u1) in smul_add_mod_lemma #m1 #m2 #m3 (uint64xN_v u1).[i] (uint64xN_v f2).[i] (uint64xN_v acc1).[i]; assert ((uint64xN_v o).[i] == (uint64xN_v acc1).[i] + (uint64xN_v u1).[i] * (uint64xN_v f2).[i]); lemma_mult_le (uint64xN_v u1).[i] (m1 * max26) (uint64xN_v f2).[i] (m2 * max26); assert ((uint64xN_v o).[i] <= m3 * max26 * max26 + m1 * m2 * max26 * max26) #pop-options val smul_add_felem5_eval_lemma_i: #w:lanes -> #m1:scale32 -> #m2:scale32_5 -> #m3:scale64_5{m3 +* m1 *^ m2 <=* s64x5 4096} -> u1:uint64xN w{felem_fits1 u1 m1} -> f2:felem5 w{felem_fits5 f2 m2} -> acc1:felem_wide5 w{felem_wide_fits5 acc1 m3} -> i:nat{i < w} -> Lemma ((fas_nat5 (smul_add_felem5 #w u1 f2 acc1)).[i] == (fas_nat5 acc1).[i] + (uint64xN_v u1).[i] * (fas_nat5 f2).[i]) let smul_add_felem5_eval_lemma_i #w #m1 #m2 #m3 u1 f2 acc1 i = let o = smul_add_felem5 #w u1 f2 acc1 in let (m20, m21, m22, m23, m24) = m2 in let (m30, m31, m32, m33, m34) = m3 in let vu1 = (uint64xN_v u1).[i] in let (tf20, tf21, tf22, tf23, tf24) = as_tup64_i f2 i in let (ta0, ta1, ta2, ta3, ta4) = as_tup64_i acc1 i in let (to0, to1, to2, to3, to4) = as_tup64_i o i in smul_add_mod_lemma #m1 #m20 #m30 vu1 (v tf20) (v ta0); smul_add_mod_lemma #m1 #m21 #m31 vu1 (v tf21) (v ta1); smul_add_mod_lemma #m1 #m22 #m32 vu1 (v tf22) (v ta2); smul_add_mod_lemma #m1 #m23 #m33 vu1 (v tf23) (v ta3); smul_add_mod_lemma #m1 #m24 #m34 vu1 (v tf24) (v ta4); calc (==) { (fas_nat5 o).[i]; (==) { } v ta0 + vu1 * v tf20 + (v ta1 + vu1 * v tf21) * pow26 + (v ta2 + vu1 * v tf22) * pow52 + (v ta3 + vu1 * v tf23) * pow78 + (v ta4 + vu1 * v tf24) * pow104; (==) { FStar.Math.Lemmas.distributivity_add_left (v ta1) (vu1 * v tf21) pow26; FStar.Math.Lemmas.distributivity_add_left (v ta2) (vu1 * v tf22) pow52; FStar.Math.Lemmas.distributivity_add_left (v ta3) (vu1 * v tf23) pow78; FStar.Math.Lemmas.distributivity_add_left (v ta1) (vu1 * v tf24) pow104 } v ta0 + v ta1 * pow26 + v ta2 * pow52 + v ta3 * pow78 + v ta4 * pow104 + vu1 * v tf20 + vu1 * v tf21 * pow26 + vu1 * v tf22 * pow52 + vu1 * v tf23 * pow78 + vu1 * v tf24 * pow104; (==) { } (fas_nat5 acc1).[i] + vu1 * v tf20 + vu1 * v tf21 * pow26 + vu1 * v tf22 * pow52 + vu1 * v tf23 * pow78 + vu1 * v tf24 * pow104; }; assert ((fas_nat5 o).[i] == (fas_nat5 acc1).[i] + vu1 * v tf20 + vu1 * v tf21 * pow26 + vu1 * v tf22 * pow52 + vu1 * v tf23 * pow78 + vu1 * v tf24 * pow104); calc (==) { vu1 * (fas_nat5 f2).[i]; (==) { } vu1 * (v tf20 + v tf21 * pow26 + v tf22 * pow52 + v tf23 * pow78 + v tf24 * pow104); (==) { lemma_mul5_distr_l vu1 (v tf20) (v tf21 * pow26) (v tf22 * pow52) (v tf23 * pow78) (v tf24 * pow104)} vu1 * v tf20 + vu1 * (v tf21 * pow26) + vu1 * (v tf22 * pow52) + vu1 * (v tf23 * pow78) + vu1 * (v tf24 * pow104); (==) { FStar.Math.Lemmas.paren_mul_right vu1 (v tf21) pow26; FStar.Math.Lemmas.paren_mul_right vu1 (v tf22) pow52; FStar.Math.Lemmas.paren_mul_right vu1 (v tf23) pow78; FStar.Math.Lemmas.paren_mul_right vu1 (v tf24) pow104} vu1 * v tf20 + vu1 * v tf21 * pow26 + vu1 * v tf22 * pow52 + vu1 * v tf23 * pow78 + vu1 * v tf24 * pow104; }; assert ((fas_nat5 o).[i] == (fas_nat5 acc1).[i] + vu1 * (fas_nat5 f2).[i]) val smul_add_felem5_fits_lemma1: #w:lanes -> #m1:scale32 -> #m2:scale32 -> #m3:scale64{m3 + m1 * m2 <= 4096} -> u1:uint64xN w{felem_fits1 u1 m1} -> f2:uint64xN w{felem_fits1 f2 m2} -> acc1:uint64xN w{felem_wide_fits1 acc1 m3} -> Lemma (felem_wide_fits1 (vec_add_mod acc1 (vec_mul_mod f2 u1)) (m3 + m1 * m2)) let smul_add_felem5_fits_lemma1 #w #m1 #m2 #m3 u1 f2 acc1 = match w with | 1 -> smul_add_felem5_fits_lemma_i #w #m1 #m2 #m3 u1 f2 acc1 0 | 2 -> smul_add_felem5_fits_lemma_i #w #m1 #m2 #m3 u1 f2 acc1 0; smul_add_felem5_fits_lemma_i #w #m1 #m2 #m3 u1 f2 acc1 1 | 4 -> smul_add_felem5_fits_lemma_i #w #m1 #m2 #m3 u1 f2 acc1 0; smul_add_felem5_fits_lemma_i #w #m1 #m2 #m3 u1 f2 acc1 1; smul_add_felem5_fits_lemma_i #w #m1 #m2 #m3 u1 f2 acc1 2; smul_add_felem5_fits_lemma_i #w #m1 #m2 #m3 u1 f2 acc1 3 val smul_add_felem5_fits_lemma: #w:lanes -> #m1:scale32 -> #m2:scale32_5 -> #m3:scale64_5{m3 +* m1 *^ m2 <=* s64x5 4096} -> u1:uint64xN w{felem_fits1 u1 m1} -> f2:felem5 w{felem_fits5 f2 m2} -> acc1:felem_wide5 w{felem_wide_fits5 acc1 m3} -> Lemma (felem_wide_fits5 (smul_add_felem5 #w u1 f2 acc1) (m3 +* m1 *^ m2)) let smul_add_felem5_fits_lemma #w #m1 #m2 #m3 u1 f2 acc1 = let (f20, f21, f22, f23, f24) = f2 in let (m20, m21, m22, m23, m24) = m2 in let (a0, a1, a2, a3, a4) = acc1 in let (m30, m31, m32, m33, m34) = m3 in smul_add_felem5_fits_lemma1 #w #m1 #m20 #m30 u1 f20 a0; smul_add_felem5_fits_lemma1 #w #m1 #m21 #m31 u1 f21 a1; smul_add_felem5_fits_lemma1 #w #m1 #m22 #m32 u1 f22 a2; smul_add_felem5_fits_lemma1 #w #m1 #m23 #m33 u1 f23 a3; smul_add_felem5_fits_lemma1 #w #m1 #m24 #m34 u1 f24 a4 val smul_add_felem5_eval_lemma: #w:lanes -> #m1:scale32 -> #m2:scale32_5 -> #m3:scale64_5{m3 +* m1 *^ m2 <=* s64x5 4096} -> u1:uint64xN w{felem_fits1 u1 m1} -> f2:felem5 w{felem_fits5 f2 m2} -> acc1:felem_wide5 w{felem_wide_fits5 acc1 m3} -> Lemma (fas_nat5 (smul_add_felem5 #w u1 f2 acc1) == map2 #nat #nat #nat (fun a b -> a + b) (fas_nat5 acc1) (map2 #nat #nat #nat (fun a b -> a * b) (uint64xN_v u1) (fas_nat5 f2))) let smul_add_felem5_eval_lemma #w #m1 #m2 #m3 u1 f2 acc1 = let tmp = map2 #nat #nat #nat (fun a b -> a + b) (fas_nat5 acc1) (map2 #nat #nat #nat (fun a b -> a * b) (uint64xN_v u1) (fas_nat5 f2)) in FStar.Classical.forall_intro (smul_add_felem5_eval_lemma_i #w #m1 #m2 #m3 u1 f2 acc1); eq_intro (fas_nat5 (smul_add_felem5 #w u1 f2 acc1)) tmp val lemma_fmul5_pow26: r:tup64_5 -> Lemma (requires (let (r0, r1, r2, r3, r4) = r in v r4 * 5 <= 10 * pow26)) (ensures (let (r0, r1, r2, r3, r4) = r in (pow26 * as_nat5 r) % prime == as_nat5 (r4 *! u64 5, r0, r1, r2, r3) % prime)) let lemma_fmul5_pow26 r = let (r0, r1, r2, r3, r4) = r in calc (==) { (pow26 * as_nat5 r) % prime; (==) { } (pow26 * (v r0 + v r1 * pow26 + v r2 * pow52 + v r3 * pow78 + v r4 * pow104)) % prime; (==) { lemma_mul5_distr_l pow26 (v r0) (v r1 * pow26) (v r2 * pow52) (v r3 * pow78) (v r4 * pow104) } (v r0 * pow26 + pow26 * v r1 * pow26 + pow26 * v r2 * pow52 + pow26 * v r3 * pow78 + pow26 * v r4 * pow104) % prime; (==) { } (v r0 * pow26 + v r1 * pow26 * pow26 + v r2 * pow26 * pow52 + v r3 * pow26 * pow78 + v r4 * pow26 * pow104) % prime; (==) { assert_norm (pow26 * pow26 = pow52); assert_norm (pow26 * pow52 = pow78); assert_norm (pow26 * pow78 = pow104); assert_norm (pow26 * pow104 = pow2 130) } (v r0 * pow26 + v r1 * pow52 + v r2 * pow78 + v r3 * pow104 + v r4 * pow2 130) % prime; (==) { FStar.Math.Lemmas.lemma_mod_plus_distr_r (v r0 * pow26 + v r1 * pow52 + v r2 * pow78 + v r3 * pow104) (v r4 * pow2 130) prime } (v r0 * pow26 + v r1 * pow52 + v r2 * pow78 + v r3 * pow104 + (v r4 * pow2 130) % prime) % prime; (==) { FStar.Math.Lemmas.lemma_mod_mul_distr_r (v r4) (pow2 130) prime } (v r0 * pow26 + v r1 * pow52 + v r2 * pow78 + v r3 * pow104 + (v r4 * (pow2 130 % prime)) % prime) % prime; (==) { lemma_prime () } (v r0 * pow26 + v r1 * pow52 + v r2 * pow78 + v r3 * pow104 + (v r4 * 5) % prime) % prime; (==) { FStar.Math.Lemmas.lemma_mod_plus_distr_r (v r0 * pow26 + v r1 * pow52 + v r2 * pow78 + v r3 * pow104) (v r4 * 5) prime } (v r0 * pow26 + v r1 * pow52 + v r2 * pow78 + v r3 * pow104 + v r4 * 5) % prime; }; assert ((pow26 * as_nat5 r) % prime == (v r0 * pow26 + v r1 * pow52 + v r2 * pow78 + v r3 * pow104 + v r4 * 5) % prime) val lemma_fmul5_pow52: r:tup64_5 -> Lemma (requires (let (r0, r1, r2, r3, r4) = r in v r4 * 5 <= 10 * pow26 /\ v r3 * 5 <= 10 * pow26)) (ensures (let (r0, r1, r2, r3, r4) = r in (pow52 * as_nat5 r) % prime == as_nat5 (r3 *! u64 5, r4 *! u64 5, r0, r1, r2) % prime)) let lemma_fmul5_pow52 r = let (r0, r1, r2, r3, r4) = r in calc (==) { (pow52 * as_nat5 r) % prime; (==) { assert_norm (pow52 == pow26 * pow26) } (pow26 * pow26 * as_nat5 r) % prime; (==) { FStar.Math.Lemmas.paren_mul_right pow26 pow26 (as_nat5 r); FStar.Math.Lemmas.lemma_mod_mul_distr_r pow26 (pow26 * as_nat5 r) prime } (pow26 * (pow26 * as_nat5 r % prime)) % prime; (==) { lemma_fmul5_pow26 r } (pow26 * (as_nat5 (r4 *! u64 5, r0, r1, r2, r3) % prime)) % prime; (==) { FStar.Math.Lemmas.lemma_mod_mul_distr_r pow26 (as_nat5 (r4 *! u64 5, r0, r1, r2, r3)) prime } (pow26 * as_nat5 (r4 *! u64 5, r0, r1, r2, r3)) % prime; (==) { lemma_fmul5_pow26 (r4 *! u64 5, r0, r1, r2, r3) } as_nat5 (r3 *! u64 5, r4 *! u64 5, r0, r1, r2) % prime; }; assert ((pow52 * as_nat5 r) % prime == as_nat5 (r3 *! u64 5, r4 *! u64 5, r0, r1, r2) % prime) val lemma_fmul5_pow78: r:tup64_5 -> Lemma (requires (let (r0, r1, r2, r3, r4) = r in v r4 * 5 <= 10 * pow26 /\ v r3 * 5 <= 10 * pow26 /\ v r2 * 5 <= 10 * pow26)) (ensures (let (r0, r1, r2, r3, r4) = r in (pow78 * as_nat5 r) % prime == as_nat5 (r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0, r1) % prime)) let lemma_fmul5_pow78 r = let (r0, r1, r2, r3, r4) = r in calc (==) { (pow78 * as_nat5 r) % prime; (==) { assert_norm (pow78 == pow26 * pow52) } (pow26 * pow52 * as_nat5 r) % prime; (==) { FStar.Math.Lemmas.paren_mul_right pow26 pow52 (as_nat5 r); FStar.Math.Lemmas.lemma_mod_mul_distr_r pow26 (pow52 * as_nat5 r) prime } (pow26 * (pow52 * as_nat5 r % prime)) % prime; (==) { lemma_fmul5_pow52 r } (pow26 * (as_nat5 (r3 *! u64 5, r4 *! u64 5, r0, r1, r2) % prime)) % prime; (==) { FStar.Math.Lemmas.lemma_mod_mul_distr_r pow26 (as_nat5 (r3 *! u64 5, r4 *! u64 5, r0, r1, r2)) prime } (pow26 * as_nat5 (r3 *! u64 5, r4 *! u64 5, r0, r1, r2)) % prime; (==) { lemma_fmul5_pow26 (r3 *! u64 5, r4 *! u64 5, r0, r1, r2) } as_nat5 (r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0, r1) % prime; }; assert ((pow78 * as_nat5 r) % prime == as_nat5 (r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0, r1) % prime) val lemma_fmul5_pow104: r:tup64_5 -> Lemma (requires (let (r0, r1, r2, r3, r4) = r in v r4 * 5 <= 10 * pow26 /\ v r3 * 5 <= 10 * pow26 /\ v r2 * 5 <= 10 * pow26 /\ v r1 * 5 <= 10 * pow26)) (ensures (let (r0, r1, r2, r3, r4) = r in (pow104 * as_nat5 r) % prime == as_nat5 (r1 *! u64 5, r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0) % prime)) let lemma_fmul5_pow104 r = let (r0, r1, r2, r3, r4) = r in calc (==) { (pow104 * as_nat5 r) % prime; (==) { assert_norm (pow104 == pow26 * pow78) } (pow26 * pow78 * as_nat5 r) % prime; (==) { FStar.Math.Lemmas.paren_mul_right pow26 pow78 (as_nat5 r); FStar.Math.Lemmas.lemma_mod_mul_distr_r pow26 (pow78 * as_nat5 r) prime } (pow26 * (pow78 * as_nat5 r % prime)) % prime; (==) { lemma_fmul5_pow78 r } (pow26 * (as_nat5 (r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0, r1) % prime)) % prime; (==) { FStar.Math.Lemmas.lemma_mod_mul_distr_r pow26 (as_nat5 (r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0, r1)) prime } (pow26 * as_nat5 (r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0, r1)) % prime; (==) { lemma_fmul5_pow26 (r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0, r1) } as_nat5 (r1 *! u64 5, r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0) % prime; }; assert ((pow104 * as_nat5 r) % prime == as_nat5 (r1 *! u64 5, r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0) % prime) val mul_felem5_lemma_1: f1:tup64_5{tup64_fits5 f1 (3, 3, 3, 3, 3)} -> r:tup64_5{tup64_fits5 r (2, 2, 2, 2, 2)} -> Lemma (let (f10, f11, f12, f13, f14) = f1 in let (r0, r1, r2, r3, r4) = r in (as_nat5 f1 * as_nat5 r) % prime == (v f10 * as_nat5 r + v f11 * as_nat5 (r4 *! u64 5, r0, r1, r2, r3) + v f12 * pow52 * as_nat5 r + v f13 * pow78 * as_nat5 r + v f14 * pow104 * as_nat5 r) % prime) let mul_felem5_lemma_1 f1 r = let (f10, f11, f12, f13, f14) = f1 in let (r0, r1, r2, r3, r4) = r in let tmp = v f10 * as_nat5 r + v f12 * pow52 * as_nat5 r + v f13 * pow78 * as_nat5 r + v f14 * pow104 * as_nat5 r in calc (==) { (as_nat5 f1 * as_nat5 r) % prime; (==) { } (v f10 + v f11 * pow26 + v f12 * pow52 + v f13 * pow78 + v f14 * pow104) * as_nat5 r % prime; (==) { lemma_mul5_distr_r (v f10) (v f11 * pow26) (v f12 * pow52) (v f13 * pow78) (v f14 * pow104) (as_nat5 r) } (v f10 * as_nat5 r + v f11 * pow26 * as_nat5 r + v f12 * pow52 * as_nat5 r + v f13 * pow78 * as_nat5 r + v f14 * pow104 * as_nat5 r) % prime; (==) { FStar.Math.Lemmas.lemma_mod_plus_distr_r tmp (v f11 * pow26 * as_nat5 r) prime } (tmp + (v f11 * pow26 * as_nat5 r) % prime) % prime; (==) { FStar.Math.Lemmas.paren_mul_right (v f11) pow26 (as_nat5 r); FStar.Math.Lemmas.lemma_mod_mul_distr_r (v f11) (pow26 * as_nat5 r) prime } (tmp + v f11 * (pow26 * as_nat5 r % prime) % prime) % prime; (==) { lemma_fmul5_pow26 r } (tmp + v f11 * (as_nat5 (r4 *! u64 5, r0, r1, r2, r3) % prime) % prime) % prime; (==) { FStar.Math.Lemmas.lemma_mod_mul_distr_r (v f11) (as_nat5 (r4 *! u64 5, r0, r1, r2, r3)) prime } (tmp + v f11 * as_nat5 (r4 *! u64 5, r0, r1, r2, r3) % prime) % prime; (==) { FStar.Math.Lemmas.lemma_mod_plus_distr_r tmp (v f11 * as_nat5 (r4 *! u64 5, r0, r1, r2, r3)) prime } (tmp + v f11 * as_nat5 (r4 *! u64 5, r0, r1, r2, r3)) % prime; }; assert ((as_nat5 f1 * as_nat5 r) % prime == (tmp + v f11 * as_nat5 (r4 *! u64 5, r0, r1, r2, r3)) % prime) val mul_felem5_lemma_2: f1:tup64_5{tup64_fits5 f1 (3, 3, 3, 3, 3)} -> r:tup64_5{tup64_fits5 r (2, 2, 2, 2, 2)} -> Lemma (let (f10, f11, f12, f13, f14) = f1 in let (r0, r1, r2, r3, r4) = r in (as_nat5 f1 * as_nat5 r) % prime == (v f10 * as_nat5 r + v f11 * as_nat5 (r4 *! u64 5, r0, r1, r2, r3) + v f12 * as_nat5 (r3 *! u64 5, r4 *! u64 5, r0, r1, r2) + v f13 * pow78 * as_nat5 r + v f14 * pow104 * as_nat5 r) % prime) let mul_felem5_lemma_2 f1 r = let (f10, f11, f12, f13, f14) = f1 in let (r0, r1, r2, r3, r4) = r in let tmp = v f10 * as_nat5 r + v f11 * as_nat5 (r4 *! u64 5, r0, r1, r2, r3) + v f13 * pow78 * as_nat5 r + v f14 * pow104 * as_nat5 r in calc (==) { (as_nat5 f1 * as_nat5 r) % prime; (==) { mul_felem5_lemma_1 f1 r } (tmp + v f12 * pow52 * as_nat5 r) % prime; (==) { FStar.Math.Lemmas.lemma_mod_plus_distr_r tmp (v f12 * pow52 * as_nat5 r) prime } (tmp + (v f12 * pow52 * as_nat5 r) % prime) % prime; (==) { FStar.Math.Lemmas.paren_mul_right (v f12) pow52 (as_nat5 r); FStar.Math.Lemmas.lemma_mod_mul_distr_r (v f12) (pow52 * as_nat5 r) prime } (tmp + v f12 * (pow52 * as_nat5 r % prime) % prime) % prime; (==) { lemma_fmul5_pow52 r } (tmp + v f12 * (as_nat5 (r3 *! u64 5, r4 *! u64 5, r0, r1, r2) % prime) % prime) % prime; (==) { FStar.Math.Lemmas.lemma_mod_mul_distr_r (v f12) (as_nat5 (r3 *! u64 5, r4 *! u64 5, r0, r1, r2)) prime } (tmp + v f12 * as_nat5 (r3 *! u64 5, r4 *! u64 5, r0, r1, r2) % prime) % prime; (==) { FStar.Math.Lemmas.lemma_mod_plus_distr_r tmp (v f12 * as_nat5 (r3 *! u64 5, r4 *! u64 5, r0, r1, r2)) prime } (tmp + v f12 * as_nat5 (r3 *! u64 5, r4 *! u64 5, r0, r1, r2)) % prime; }; assert ((as_nat5 f1 * as_nat5 r) % prime == (tmp + v f12 * as_nat5 (r3 *! u64 5, r4 *! u64 5, r0, r1, r2)) % prime) val mul_felem5_lemma_3: f1:tup64_5{tup64_fits5 f1 (3, 3, 3, 3, 3)} -> r:tup64_5{tup64_fits5 r (2, 2, 2, 2, 2)} -> Lemma (let (f10, f11, f12, f13, f14) = f1 in let (r0, r1, r2, r3, r4) = r in (as_nat5 f1 * as_nat5 r) % prime == (v f10 * as_nat5 r + v f11 * as_nat5 (r4 *! u64 5, r0, r1, r2, r3) + v f12 * as_nat5 (r3 *! u64 5, r4 *! u64 5, r0, r1, r2) + v f13 * as_nat5 (r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0, r1) + v f14 * pow104 * as_nat5 r) % prime) let mul_felem5_lemma_3 f1 r = let (f10, f11, f12, f13, f14) = f1 in let (r0, r1, r2, r3, r4) = r in let tmp = v f10 * as_nat5 r + v f11 * as_nat5 (r4 *! u64 5, r0, r1, r2, r3) + v f12 * as_nat5 (r3 *! u64 5, r4 *! u64 5, r0, r1, r2) + v f14 * pow104 * as_nat5 r in calc (==) { (as_nat5 f1 * as_nat5 r) % prime; (==) { mul_felem5_lemma_2 f1 r } (tmp + v f13 * pow78 * as_nat5 r) % prime; (==) { FStar.Math.Lemmas.lemma_mod_plus_distr_r tmp (v f13 * pow78 * as_nat5 r) prime } (tmp + (v f13 * pow78 * as_nat5 r) % prime) % prime; (==) { FStar.Math.Lemmas.paren_mul_right (v f13) pow78 (as_nat5 r); FStar.Math.Lemmas.lemma_mod_mul_distr_r (v f13) (pow78 * as_nat5 r) prime } (tmp + v f13 * (pow78 * as_nat5 r % prime) % prime) % prime; (==) { lemma_fmul5_pow78 r } (tmp + v f13 * (as_nat5 (r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0, r1) % prime) % prime) % prime; (==) { FStar.Math.Lemmas.lemma_mod_mul_distr_r (v f13) (as_nat5 (r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0, r1)) prime } (tmp + v f13 * as_nat5 (r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0, r1) % prime) % prime; (==) { FStar.Math.Lemmas.lemma_mod_plus_distr_r tmp (v f13 * as_nat5 (r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0, r1)) prime } (tmp + v f13 * as_nat5 (r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0, r1)) % prime; }; assert ((as_nat5 f1 * as_nat5 r) % prime == (tmp + v f13 * as_nat5 (r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0, r1)) % prime) val mul_felem5_lemma_4: f1:tup64_5{tup64_fits5 f1 (3, 3, 3, 3, 3)} -> r:tup64_5{tup64_fits5 r (2, 2, 2, 2, 2)} -> Lemma (let (f10, f11, f12, f13, f14) = f1 in let (r0, r1, r2, r3, r4) = r in (as_nat5 f1 * as_nat5 r) % prime == (v f10 * as_nat5 r + v f11 * as_nat5 (r4 *! u64 5, r0, r1, r2, r3) + v f12 * as_nat5 (r3 *! u64 5, r4 *! u64 5, r0, r1, r2) + v f13 * as_nat5 (r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0, r1) + v f14 * as_nat5 (r1 *! u64 5, r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0)) % prime) let mul_felem5_lemma_4 f1 r = let (f10, f11, f12, f13, f14) = f1 in let (r0, r1, r2, r3, r4) = r in let tmp = v f10 * as_nat5 r + v f11 * as_nat5 (r4 *! u64 5, r0, r1, r2, r3) + v f12 * as_nat5 (r3 *! u64 5, r4 *! u64 5, r0, r1, r2) + v f13 * as_nat5 (r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0, r1) in calc (==) { (as_nat5 f1 * as_nat5 r) % prime; (==) { mul_felem5_lemma_3 f1 r } (tmp + v f14 * pow104 * as_nat5 r) % prime; (==) { FStar.Math.Lemmas.lemma_mod_plus_distr_r tmp (v f14 * pow104 * as_nat5 r) prime } (tmp + (v f14 * pow104 * as_nat5 r) % prime) % prime; (==) { FStar.Math.Lemmas.paren_mul_right (v f14) pow104 (as_nat5 r); FStar.Math.Lemmas.lemma_mod_mul_distr_r (v f14) (pow104 * as_nat5 r) prime } (tmp + v f14 * (pow104 * as_nat5 r % prime) % prime) % prime; (==) { lemma_fmul5_pow104 r } (tmp + v f14 * (as_nat5 (r1 *! u64 5, r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0) % prime) % prime) % prime; (==) { FStar.Math.Lemmas.lemma_mod_mul_distr_r (v f14) (as_nat5 (r1 *! u64 5, r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0)) prime } (tmp + v f14 * as_nat5 (r1 *! u64 5, r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0) % prime) % prime; (==) { FStar.Math.Lemmas.lemma_mod_plus_distr_r tmp (v f14 * as_nat5 (r1 *! u64 5, r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0)) prime } (tmp + v f14 * as_nat5 (r1 *! u64 5, r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0)) % prime; }; assert ((as_nat5 f1 * as_nat5 r) % prime == (tmp + v f14 * as_nat5 (r1 *! u64 5, r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0)) % prime) val mul_felem5_lemma: f1:tup64_5{tup64_fits5 f1 (3, 3, 3, 3, 3)} -> r:tup64_5{tup64_fits5 r (2, 2, 2, 2, 2)} -> Lemma (let (f10, f11, f12, f13, f14) = f1 in let (r0, r1, r2, r3, r4) = r in (as_pfelem5 f1) `pfmul` (as_pfelem5 r) == (v f10 * as_nat5 (r0, r1, r2, r3, r4) + v f11 * as_nat5 (r4 *! u64 5, r0, r1, r2, r3) + v f12 * as_nat5 (r3 *! u64 5, r4 *! u64 5, r0, r1, r2) + v f13 * as_nat5 (r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0, r1) + v f14 * as_nat5 (r1 *! u64 5, r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0)) % prime)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntVector.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Poly1305.Vec.fst.checked", "Hacl.Spec.Poly1305.Field32xN.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Poly1305.Field32xN.Lemmas0.fst" }
[ { "abbrev": false, "full_module": "Hacl.Spec.Poly1305.Field32xN", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Poly1305.Vec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntVector", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Poly1305.Field32xN", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Poly1305.Field32xN", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
f1: Hacl.Spec.Poly1305.Field32xN.tup64_5 {Hacl.Spec.Poly1305.Field32xN.tup64_fits5 f1 (3, 3, 3, 3, 3)} -> r: Hacl.Spec.Poly1305.Field32xN.tup64_5 {Hacl.Spec.Poly1305.Field32xN.tup64_fits5 r (2, 2, 2, 2, 2)} -> FStar.Pervasives.Lemma (ensures (let _ = f1 in (let FStar.Pervasives.Native.Mktuple5 #_ #_ #_ #_ #_ f10 f11 f12 f13 f14 = _ in let _ = r in (let FStar.Pervasives.Native.Mktuple5 #_ #_ #_ #_ #_ r0 r1 r2 r3 r4 = _ in Hacl.Spec.Poly1305.Vec.pfmul (Hacl.Spec.Poly1305.Field32xN.as_pfelem5 f1) (Hacl.Spec.Poly1305.Field32xN.as_pfelem5 r) == (Lib.IntTypes.v f10 * Hacl.Spec.Poly1305.Field32xN.as_nat5 (r0, r1, r2, r3, r4) + Lib.IntTypes.v f11 * Hacl.Spec.Poly1305.Field32xN.as_nat5 (r4 *! Lib.IntTypes.u64 5, r0, r1, r2, r3) + Lib.IntTypes.v f12 * Hacl.Spec.Poly1305.Field32xN.as_nat5 (r3 *! Lib.IntTypes.u64 5, r4 *! Lib.IntTypes.u64 5, r0, r1, r2) + Lib.IntTypes.v f13 * Hacl.Spec.Poly1305.Field32xN.as_nat5 (r2 *! Lib.IntTypes.u64 5, r3 *! Lib.IntTypes.u64 5, r4 *! Lib.IntTypes.u64 5, r0, r1) + Lib.IntTypes.v f14 * Hacl.Spec.Poly1305.Field32xN.as_nat5 (r1 *! Lib.IntTypes.u64 5, r2 *! Lib.IntTypes.u64 5, r3 *! Lib.IntTypes.u64 5, r4 *! Lib.IntTypes.u64 5, r0)) % Hacl.Spec.Poly1305.Vec.prime) <: Type0) <: Type0))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Hacl.Spec.Poly1305.Field32xN.tup64_5", "Hacl.Spec.Poly1305.Field32xN.tup64_fits5", "FStar.Pervasives.Native.Mktuple5", "Prims.nat", "Lib.IntTypes.uint64", "FStar.Math.Lemmas.lemma_mod_mul_distr_r", "Prims.op_Modulus", "Hacl.Spec.Poly1305.Field32xN.as_nat5", "Hacl.Spec.Poly1305.Vec.prime", "Prims.unit", "FStar.Math.Lemmas.lemma_mod_mul_distr_l", "Hacl.Poly1305.Field32xN.Lemmas0.mul_felem5_lemma_4" ]
[]
false
false
true
false
false
let mul_felem5_lemma f1 r =
let f10, f11, f12, f13, f14 = f1 in let r0, r1, r2, r3, r4 = r in mul_felem5_lemma_4 f1 r; FStar.Math.Lemmas.lemma_mod_mul_distr_l (as_nat5 f1) (as_nat5 r) prime; FStar.Math.Lemmas.lemma_mod_mul_distr_r (as_nat5 f1 % prime) (as_nat5 r) prime
false
Vale.Arch.Types.fsti
Vale.Arch.Types.add_wrap32
val add_wrap32 (x y: nat32) : nat32
val add_wrap32 (x y: nat32) : nat32
let add_wrap32 (x:nat32) (y:nat32) : nat32 = add_wrap x y
{ "file_name": "vale/code/arch/Vale.Arch.Types.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 64, "end_line": 18, "start_col": 7, "start_line": 18 }
module Vale.Arch.Types open FStar.Mul open Vale.Def.Opaque_s open Vale.Def.Types_s open Vale.Lib.Seqs_s open Vale.Lib.Seqs open Vale.Def.Words_s open Vale.Def.Words.Four_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Seq open FStar.Seq open Vale.Def.Words.Two_s unfold let ( *^ ) = nat32_xor unfold let ( *^^ ) = quad32_xor
{ "checked_file": "/", "dependencies": [ "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Two_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Seq.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.Arch.Types.fsti" }
[ { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
x: Vale.Def.Words_s.nat32 -> y: Vale.Def.Words_s.nat32 -> Vale.Def.Words_s.nat32
Prims.Tot
[ "total" ]
[]
[ "Vale.Def.Words_s.nat32", "Vale.Def.Types_s.add_wrap", "Vale.Def.Words_s.pow2_32" ]
[]
false
false
false
true
false
let add_wrap32 (x y: nat32) : nat32 =
add_wrap x y
false
Steel.FractionalAnchoredPreorder.fst
Steel.FractionalAnchoredPreorder.compose_avalue_assoc_r
val compose_avalue_assoc_r (#v: Type) (#p: preorder v) (#s: anchor_rel p) (m0 m1: avalue s) (m2: avalue s {avalue_composable m0 m1 /\ avalue_composable (compose_avalue m0 m1) m2}) : Lemma (avalue_composable m1 m2 /\ avalue_composable m0 (compose_avalue m1 m2) /\ compose_avalue m0 (compose_avalue m1 m2) == compose_avalue (compose_avalue m0 m1) m2)
val compose_avalue_assoc_r (#v: Type) (#p: preorder v) (#s: anchor_rel p) (m0 m1: avalue s) (m2: avalue s {avalue_composable m0 m1 /\ avalue_composable (compose_avalue m0 m1) m2}) : Lemma (avalue_composable m1 m2 /\ avalue_composable m0 (compose_avalue m1 m2) /\ compose_avalue m0 (compose_avalue m1 m2) == compose_avalue (compose_avalue m0 m1) m2)
let compose_avalue_assoc_r (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m0: avalue s) (m1: avalue s) (m2: avalue s{ avalue_composable m0 m1 /\ avalue_composable (compose_avalue m0 m1) m2 }) : Lemma (avalue_composable m1 m2 /\ avalue_composable m0 (compose_avalue m1 m2) /\ compose_avalue m0 (compose_avalue m1 m2) == compose_avalue (compose_avalue m0 m1) m2) = avalue_composable_assoc_r m0 m1 m2
{ "file_name": "lib/steel/Steel.FractionalAnchoredPreorder.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 37, "end_line": 314, "start_col": 0, "start_line": 303 }
(* Copyright 2021 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. Author: N. Swamy *) module Steel.FractionalAnchoredPreorder (** This module provides a partial commutative monoid (PCM) for use in the ghost state of a concurrent Steel program. Its goal is to facilitate a form of information-sharing between multiple threads including the following features: Fractions, Preorders, Snapshots, and Anchors --- Anchors are the most unusual. 1. Fractions: Ownership of the state is controlled by a fractional permission, so multiple threads may share read-only privileges on the state, but only one can have write permission. 2. Preorders: The ghost state is governed by a preorder p and all updates to the state must respect the preorder (a reflexive, transitive relation on the state) 3. Snapshots: Since the state always evolves by a preorder, it is possible to take a snapshot of the state. A snapshot does not confer any particular ownership on the state, except knowledge of a snapshot ensures that the current state is related to the snapshot by the preorder. 4. Anchors are a kind of refinement of the preorder. If a thread owns an anchored value [v], then no other thread, even a thread owning a full fractional permission, can advance the state "too far" from the anchor. In particular, the PCM is parameterized by a binary relation on values, [anchors:anchor_relation]. If a thread owns the anchor [v], then the current value `cur` of the state must be in relation [v `anchors` cur]. This can be used to ensure that the knowledge of one thread is never becomes too stale. For example, this allows one to model a shared monotonically increasing counter, where if one thread anchors knowledge of the counter at the value 5, no other thread can increase the value of the counter beyond, say, 10, (when the anchor relation is y - x <= 5), until the anchoring thread releases the anchor. Further, at any point, a thread can take a snapshot of the counter and rely on the fact that the value of the counter in the future will be >= the snapshot. *) open FStar.PCM open FStar.Preorder open Steel.Preorder open Steel.FractionalPermission #push-options "--fuel 0 --ifuel 2" /// A permission: is a pair of /// /// * an optional fractional permission; with `Some p` indicating /// some ownership, while `None` is an additional "0" permission /// value, to encode snapshots. /// /// * and an optional anchor, where `Some a` indicates the current /// value can't be too far from `a`. let permission (v:Type) = option perm & option v /// Non-zero permission is either a read or write permission let has_nonzero #v (p:permission v) = Some? (fst p) /// Has an anchor set let has_anchor #v (p:permission v) = Some? (snd p) /// Either an anchor or non-zero let has_some_ownership #v (p:permission v) = has_nonzero p || has_anchor p /// The anchoring value let anchor_of #v (p:permission v { has_anchor p }) : v = Some?.v (snd p) /// The anchoring relation: /// -- A binary relation on values /// -- refining the preorder /// -- and if x `anchors` z then it also anchors any `y` between `x` and `z` /// /// Explaining the third clause a bit: /// Think intuitively of anchoring relations as a kind of distance measure /// /// if `z` is close enough to `x` then if `z` is further than `y` /// (since it is ahead of `y` in the preorder) then `y` is also /// close enough to `x` let anchor_rel (#v:Type) (p:preorder v) = anchors:(v -> v -> prop) { (forall v0 v1. anchors v0 v1 ==> p v0 v1) /\ (forall x z. x `anchors` z ==> (forall y. p x y /\ p y z ==> x `anchors` y)) // } /// An implementation remark: We use Steel.Preorder here to /// generically transform any preorder into a PCM. That works by /// taking the value of the PCM to be a history of values related by /// the preorder. So, throughout, we'll be using the the [vhist p] /// from Steel.Preorder, the type of a non-empty history compatible /// with [p]. The details of the histories don't matter much for our /// purposes---we only care about the most recent value, for which /// we'll use [curval v]. /// If the anchor is set, then the current value is anchored by it let anchored (#v:Type) (#p:preorder v) (anchors:anchor_rel p) (pv:(permission v & vhist p)) = has_anchor (fst pv) ==> anchor_of (fst pv) `anchors` curval (snd pv) /// A value in our fractional anchored PCM is a pair of a permission /// and a p-compatible history, refined to ensure that if the anchor /// is set, then the current value is anchored by it. let avalue (#v:Type) (#p:preorder v) (anchors:anchor_rel p) = pv:(permission v & vhist p) { anchored anchors pv } /// initial_value: A utility to construct a value in the PCM #push-options "--fuel 1" let initial_value (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (value:v { anchors value value }) : avalue anchors = (Some full_perm, Some value), [value] #pop-options /// We add a unit element to [avalue], as needed for a PCM [@@erasable] noeq type knowledge (#v:Type) (#p:preorder v) (anchors:anchor_rel p) = | Owns : avalue anchors -> knowledge anchors | Nothing : knowledge anchors let b2p (b:bool) : prop = b == true /// Fractional permissions are composable when their sum <= 1.0 let perm_opt_composable (p0 p1:option perm) : prop = match p0, p1 with | None, None -> True | Some p, None | None, Some p -> b2p (p `lesser_equal_perm` full_perm) | Some p0, Some p1 -> b2p (sum_perm p0 p1 `lesser_equal_perm` full_perm) /// Composing them sums the permissions let compose_perm_opt (p0 p1:option perm) = match p0, p1 with | None, p | p, None -> p | Some p0, Some p1 -> Some (sum_perm p0 p1) /// Anchored permissions are composable when at most one of them has the anchor set let permission_composable #v (p0 p1 : permission v) : prop = let q0, s0 = p0 in let q1, s1 = p1 in perm_opt_composable q0 q1 /\ // some of fracs can't exceed 1 not (Some? s0 && Some? s1) // at most one can have an anchor /// Compose permissions component wise, keeping the anchor if set let compose_permissions (#v:_) (p0:permission v) (p1:permission v{permission_composable p0 p1}) : permission v = compose_perm_opt (fst p0) (fst p1), (match snd p0, snd p1 with | None, a | a, None -> a) /// This is the central definition of the PCM --- defining when two /// values are composable, or equivalently, when one thread's /// knowledge of [av0] is compatible with another thread's knowledge /// of [av1] /// /// This definition shows the interplay between fractions and anchors. /// It wasn't obvious to me how to factor this further, e.g., adding /// anchors to preorders and then separately adding fractions to it. let avalue_composable (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (av0 av1: avalue anchors) : prop = let (p0, v0) = av0 in let (p1, v1) = av1 in permission_composable p0 p1 /\ (if not (has_some_ownership p0) && not (has_some_ownership p1) then p_composable _ v0 v1 //neither has ownership, one history is older than the other else if not (has_some_ownership p0) && has_some_ownership p1 then ( if has_nonzero p1 then v1 `extends` v0 //the one with ownership is more recent else ( //this part is the most subtle assert (has_anchor p1); p_composable _ v0 v1 /\ (v0 `extends` v1 ==> //if v0 is a more recent snapshot than v1 //then v0 must still be anchored by v1's anchor anchor_of p1 `anchors` curval v0) ) ) else if has_some_ownership p0 && not (has_some_ownership p1) then ( //symmetric if has_nonzero p0 then v0 `extends` v1 else ( assert (has_anchor p0); p_composable _ v0 v1 /\ (v1 `extends` v0 ==> anchor_of p0 `anchors` curval v1) ) ) else ( assert (has_some_ownership p0 && has_some_ownership p1); if has_nonzero p0 && has_nonzero p1 then v0 == v1 //if both have non-zero perm, then they must both only have read permission and must agree on the value else if has_nonzero p0 && has_anchor p1 then ( assert (not (has_nonzero p1)); //The key part of the anchor semantics: v0 `extends` v1 /\ //v0 has advanceable ownership, so extends anchor_of p1 `anchors` curval v0 //but not beyond what is allowed by s ) else if has_anchor p0 && has_nonzero p1 //symmetric then ( assert (not (has_nonzero p0)); v1 `extends` v0 /\ anchor_of p0 `anchors` curval v1 //v1 extends, but not beyond what is allowed by s ) else (assert false; False) ) ) //exhaustive /// Lifting avalue comosability to knowledge, including the unit let composable #v (#p:preorder v) (#a:anchor_rel p) : symrel (knowledge a) = fun (k0 k1:knowledge a) -> match k0, k1 with | Nothing, _ | _, Nothing -> True | Owns m, Owns m' -> avalue_composable m m' /// Compose avalues by composing permissions and composing the values /// using the underlying preorder PCM let compose_avalue (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (m0:avalue anchors) (m1:avalue anchors { avalue_composable m0 m1 } ) : avalue anchors = let p0, v0 = m0 in let p1, v1 = m1 in let p12 = compose_permissions p0 p1 in let v12 = p_op _ v0 v1 in p12, v12 //////////////////////////////////////////////////////////////////////////////// (** avalue composition is associative and commutative **) let compose_avalue_comm (#v:Type) (#p:preorder v) (#anc:anchor_rel p) (m0: avalue anc) (m1: avalue anc{ avalue_composable m0 m1 }) : Lemma (compose_avalue m0 m1 == compose_avalue m1 m0) = () let avalue_composable_assoc_l (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (m0: avalue anchors) (m1: avalue anchors) (m2: avalue anchors { avalue_composable m1 m2 /\ avalue_composable m0 (compose_avalue m1 m2) }) : Lemma (avalue_composable m0 m1 /\ avalue_composable (compose_avalue m0 m1) m2) = () let compose_avalue_assoc_l (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m0: avalue s) (m1: avalue s) (m2: avalue s { avalue_composable m1 m2 /\ avalue_composable m0 (compose_avalue m1 m2) }) : Lemma (avalue_composable m0 m1 /\ avalue_composable (compose_avalue m0 m1) m2 /\ compose_avalue m0 (compose_avalue m1 m2) == compose_avalue (compose_avalue m0 m1) m2) = avalue_composable_assoc_l m0 m1 m2 let avalue_composable_assoc_r (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (m0: avalue anchors) (m1: avalue anchors) (m2: avalue anchors { avalue_composable m0 m1 /\ avalue_composable (compose_avalue m0 m1) m2 }) : Lemma (avalue_composable m1 m2 /\ avalue_composable m0 (compose_avalue m1 m2)) = ()
{ "checked_file": "/", "dependencies": [ "Steel.Preorder.fst.checked", "Steel.FractionalPermission.fst.checked", "prims.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked" ], "interface_file": false, "source_file": "Steel.FractionalAnchoredPreorder.fst" }
[ { "abbrev": false, "full_module": "Steel.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Steel.Preorder", "short_module": null }, { "abbrev": false, "full_module": "FStar.Preorder", "short_module": null }, { "abbrev": false, "full_module": "FStar.PCM", "short_module": null }, { "abbrev": false, "full_module": "Steel", "short_module": null }, { "abbrev": false, "full_module": "Steel", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
m0: Steel.FractionalAnchoredPreorder.avalue s -> m1: Steel.FractionalAnchoredPreorder.avalue s -> m2: Steel.FractionalAnchoredPreorder.avalue s { Steel.FractionalAnchoredPreorder.avalue_composable m0 m1 /\ Steel.FractionalAnchoredPreorder.avalue_composable (Steel.FractionalAnchoredPreorder.compose_avalue m0 m1) m2 } -> FStar.Pervasives.Lemma (ensures Steel.FractionalAnchoredPreorder.avalue_composable m1 m2 /\ Steel.FractionalAnchoredPreorder.avalue_composable m0 (Steel.FractionalAnchoredPreorder.compose_avalue m1 m2) /\ Steel.FractionalAnchoredPreorder.compose_avalue m0 (Steel.FractionalAnchoredPreorder.compose_avalue m1 m2) == Steel.FractionalAnchoredPreorder.compose_avalue (Steel.FractionalAnchoredPreorder.compose_avalue m0 m1) m2)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "FStar.Preorder.preorder", "Steel.FractionalAnchoredPreorder.anchor_rel", "Steel.FractionalAnchoredPreorder.avalue", "Prims.l_and", "Steel.FractionalAnchoredPreorder.avalue_composable", "Steel.FractionalAnchoredPreorder.compose_avalue", "Steel.FractionalAnchoredPreorder.avalue_composable_assoc_r", "Prims.unit", "Prims.l_True", "Prims.squash", "Prims.eq2", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
true
false
true
false
false
let compose_avalue_assoc_r (#v: Type) (#p: preorder v) (#s: anchor_rel p) (m0 m1: avalue s) (m2: avalue s {avalue_composable m0 m1 /\ avalue_composable (compose_avalue m0 m1) m2}) : Lemma (avalue_composable m1 m2 /\ avalue_composable m0 (compose_avalue m1 m2) /\ compose_avalue m0 (compose_avalue m1 m2) == compose_avalue (compose_avalue m0 m1) m2) =
avalue_composable_assoc_r m0 m1 m2
false
Vale.Arch.Types.fsti
Vale.Arch.Types.add_wrap64
val add_wrap64 (x y: nat64) : nat64
val add_wrap64 (x y: nat64) : nat64
let add_wrap64 (x:nat64) (y:nat64) : nat64 = add_wrap x y
{ "file_name": "vale/code/arch/Vale.Arch.Types.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 64, "end_line": 19, "start_col": 7, "start_line": 19 }
module Vale.Arch.Types open FStar.Mul open Vale.Def.Opaque_s open Vale.Def.Types_s open Vale.Lib.Seqs_s open Vale.Lib.Seqs open Vale.Def.Words_s open Vale.Def.Words.Four_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Seq open FStar.Seq open Vale.Def.Words.Two_s unfold let ( *^ ) = nat32_xor unfold let ( *^^ ) = quad32_xor
{ "checked_file": "/", "dependencies": [ "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Two_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Seq.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.Arch.Types.fsti" }
[ { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
x: Vale.Def.Words_s.nat64 -> y: Vale.Def.Words_s.nat64 -> Vale.Def.Words_s.nat64
Prims.Tot
[ "total" ]
[]
[ "Vale.Def.Words_s.nat64", "Vale.Def.Types_s.add_wrap", "Vale.Def.Words_s.pow2_64" ]
[]
false
false
false
true
false
let add_wrap64 (x y: nat64) : nat64 =
add_wrap x y
false
Vale.Arch.Types.fsti
Vale.Arch.Types.ior64
val ior64 (a b: nat64) : nat64
val ior64 (a b: nat64) : nat64
let ior64 (a:nat64) (b:nat64) : nat64 = ior a b
{ "file_name": "vale/code/arch/Vale.Arch.Types.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 54, "end_line": 32, "start_col": 7, "start_line": 32 }
module Vale.Arch.Types open FStar.Mul open Vale.Def.Opaque_s open Vale.Def.Types_s open Vale.Lib.Seqs_s open Vale.Lib.Seqs open Vale.Def.Words_s open Vale.Def.Words.Four_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Seq open FStar.Seq open Vale.Def.Words.Two_s unfold let ( *^ ) = nat32_xor unfold let ( *^^ ) = quad32_xor unfold let add_wrap32 (x:nat32) (y:nat32) : nat32 = add_wrap x y unfold let add_wrap64 (x:nat64) (y:nat64) : nat64 = add_wrap x y unfold let sub_wrap32 (x:nat32) (y:nat32) : nat32 = sub_wrap x y unfold let sub_wrap64 (x:nat64) (y:nat64) : nat64 = sub_wrap x y unfold let iand32 (a:nat32) (b:nat32) : nat32 = iand a b unfold let ixor32 (a:nat32) (b:nat32) : nat32 = ixor a b unfold let ior32 (a:nat32) (b:nat32) : nat32 = ior a b unfold let inot32 (a:nat32) : nat32 = inot a unfold let ishl32 (a:nat32) (s:int) : nat32 = ishl a s unfold let ishr32 (a:nat32) (s:int) : nat32 = ishr a s unfold let iand64 (a:nat64) (b:nat64) : nat64 = iand a b
{ "checked_file": "/", "dependencies": [ "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Two_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Seq.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.Arch.Types.fsti" }
[ { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Vale.Def.Words_s.nat64 -> b: Vale.Def.Words_s.nat64 -> Vale.Def.Words_s.nat64
Prims.Tot
[ "total" ]
[]
[ "Vale.Def.Words_s.nat64", "Vale.Def.Types_s.ior", "Vale.Def.Words_s.pow2_64" ]
[]
false
false
false
true
false
let ior64 (a b: nat64) : nat64 =
ior a b
false
Vale.Arch.Types.fsti
Vale.Arch.Types.ixor64
val ixor64 (a b: nat64) : nat64
val ixor64 (a b: nat64) : nat64
let ixor64 (a:nat64) (b:nat64) : nat64 = ixor a b
{ "file_name": "vale/code/arch/Vale.Arch.Types.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 56, "end_line": 31, "start_col": 7, "start_line": 31 }
module Vale.Arch.Types open FStar.Mul open Vale.Def.Opaque_s open Vale.Def.Types_s open Vale.Lib.Seqs_s open Vale.Lib.Seqs open Vale.Def.Words_s open Vale.Def.Words.Four_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Seq open FStar.Seq open Vale.Def.Words.Two_s unfold let ( *^ ) = nat32_xor unfold let ( *^^ ) = quad32_xor unfold let add_wrap32 (x:nat32) (y:nat32) : nat32 = add_wrap x y unfold let add_wrap64 (x:nat64) (y:nat64) : nat64 = add_wrap x y unfold let sub_wrap32 (x:nat32) (y:nat32) : nat32 = sub_wrap x y unfold let sub_wrap64 (x:nat64) (y:nat64) : nat64 = sub_wrap x y unfold let iand32 (a:nat32) (b:nat32) : nat32 = iand a b unfold let ixor32 (a:nat32) (b:nat32) : nat32 = ixor a b unfold let ior32 (a:nat32) (b:nat32) : nat32 = ior a b unfold let inot32 (a:nat32) : nat32 = inot a unfold let ishl32 (a:nat32) (s:int) : nat32 = ishl a s unfold let ishr32 (a:nat32) (s:int) : nat32 = ishr a s
{ "checked_file": "/", "dependencies": [ "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Two_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Seq.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.Arch.Types.fsti" }
[ { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Vale.Def.Words_s.nat64 -> b: Vale.Def.Words_s.nat64 -> Vale.Def.Words_s.nat64
Prims.Tot
[ "total" ]
[]
[ "Vale.Def.Words_s.nat64", "Vale.Def.Types_s.ixor", "Vale.Def.Words_s.pow2_64" ]
[]
false
false
false
true
false
let ixor64 (a b: nat64) : nat64 =
ixor a b
false
Steel.FractionalAnchoredPreorder.fst
Steel.FractionalAnchoredPreorder.avalue_update
val avalue_update (#v: Type) (#p: preorder v) (#s: anchor_rel p) (m: avalue s) (value: vhist p {s (curval value) (curval value)}) : avalue s
val avalue_update (#v: Type) (#p: preorder v) (#s: anchor_rel p) (m: avalue s) (value: vhist p {s (curval value) (curval value)}) : avalue s
let avalue_update (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) (value:vhist p { s (curval value) (curval value) }) : avalue s = let p, _ = avalue_perm m in let p' = p, Some (curval value) in (p', value)
{ "file_name": "lib/steel/Steel.FractionalAnchoredPreorder.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 15, "end_line": 430, "start_col": 0, "start_line": 422 }
(* Copyright 2021 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. Author: N. Swamy *) module Steel.FractionalAnchoredPreorder (** This module provides a partial commutative monoid (PCM) for use in the ghost state of a concurrent Steel program. Its goal is to facilitate a form of information-sharing between multiple threads including the following features: Fractions, Preorders, Snapshots, and Anchors --- Anchors are the most unusual. 1. Fractions: Ownership of the state is controlled by a fractional permission, so multiple threads may share read-only privileges on the state, but only one can have write permission. 2. Preorders: The ghost state is governed by a preorder p and all updates to the state must respect the preorder (a reflexive, transitive relation on the state) 3. Snapshots: Since the state always evolves by a preorder, it is possible to take a snapshot of the state. A snapshot does not confer any particular ownership on the state, except knowledge of a snapshot ensures that the current state is related to the snapshot by the preorder. 4. Anchors are a kind of refinement of the preorder. If a thread owns an anchored value [v], then no other thread, even a thread owning a full fractional permission, can advance the state "too far" from the anchor. In particular, the PCM is parameterized by a binary relation on values, [anchors:anchor_relation]. If a thread owns the anchor [v], then the current value `cur` of the state must be in relation [v `anchors` cur]. This can be used to ensure that the knowledge of one thread is never becomes too stale. For example, this allows one to model a shared monotonically increasing counter, where if one thread anchors knowledge of the counter at the value 5, no other thread can increase the value of the counter beyond, say, 10, (when the anchor relation is y - x <= 5), until the anchoring thread releases the anchor. Further, at any point, a thread can take a snapshot of the counter and rely on the fact that the value of the counter in the future will be >= the snapshot. *) open FStar.PCM open FStar.Preorder open Steel.Preorder open Steel.FractionalPermission #push-options "--fuel 0 --ifuel 2" /// A permission: is a pair of /// /// * an optional fractional permission; with `Some p` indicating /// some ownership, while `None` is an additional "0" permission /// value, to encode snapshots. /// /// * and an optional anchor, where `Some a` indicates the current /// value can't be too far from `a`. let permission (v:Type) = option perm & option v /// Non-zero permission is either a read or write permission let has_nonzero #v (p:permission v) = Some? (fst p) /// Has an anchor set let has_anchor #v (p:permission v) = Some? (snd p) /// Either an anchor or non-zero let has_some_ownership #v (p:permission v) = has_nonzero p || has_anchor p /// The anchoring value let anchor_of #v (p:permission v { has_anchor p }) : v = Some?.v (snd p) /// The anchoring relation: /// -- A binary relation on values /// -- refining the preorder /// -- and if x `anchors` z then it also anchors any `y` between `x` and `z` /// /// Explaining the third clause a bit: /// Think intuitively of anchoring relations as a kind of distance measure /// /// if `z` is close enough to `x` then if `z` is further than `y` /// (since it is ahead of `y` in the preorder) then `y` is also /// close enough to `x` let anchor_rel (#v:Type) (p:preorder v) = anchors:(v -> v -> prop) { (forall v0 v1. anchors v0 v1 ==> p v0 v1) /\ (forall x z. x `anchors` z ==> (forall y. p x y /\ p y z ==> x `anchors` y)) // } /// An implementation remark: We use Steel.Preorder here to /// generically transform any preorder into a PCM. That works by /// taking the value of the PCM to be a history of values related by /// the preorder. So, throughout, we'll be using the the [vhist p] /// from Steel.Preorder, the type of a non-empty history compatible /// with [p]. The details of the histories don't matter much for our /// purposes---we only care about the most recent value, for which /// we'll use [curval v]. /// If the anchor is set, then the current value is anchored by it let anchored (#v:Type) (#p:preorder v) (anchors:anchor_rel p) (pv:(permission v & vhist p)) = has_anchor (fst pv) ==> anchor_of (fst pv) `anchors` curval (snd pv) /// A value in our fractional anchored PCM is a pair of a permission /// and a p-compatible history, refined to ensure that if the anchor /// is set, then the current value is anchored by it. let avalue (#v:Type) (#p:preorder v) (anchors:anchor_rel p) = pv:(permission v & vhist p) { anchored anchors pv } /// initial_value: A utility to construct a value in the PCM #push-options "--fuel 1" let initial_value (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (value:v { anchors value value }) : avalue anchors = (Some full_perm, Some value), [value] #pop-options /// We add a unit element to [avalue], as needed for a PCM [@@erasable] noeq type knowledge (#v:Type) (#p:preorder v) (anchors:anchor_rel p) = | Owns : avalue anchors -> knowledge anchors | Nothing : knowledge anchors let b2p (b:bool) : prop = b == true /// Fractional permissions are composable when their sum <= 1.0 let perm_opt_composable (p0 p1:option perm) : prop = match p0, p1 with | None, None -> True | Some p, None | None, Some p -> b2p (p `lesser_equal_perm` full_perm) | Some p0, Some p1 -> b2p (sum_perm p0 p1 `lesser_equal_perm` full_perm) /// Composing them sums the permissions let compose_perm_opt (p0 p1:option perm) = match p0, p1 with | None, p | p, None -> p | Some p0, Some p1 -> Some (sum_perm p0 p1) /// Anchored permissions are composable when at most one of them has the anchor set let permission_composable #v (p0 p1 : permission v) : prop = let q0, s0 = p0 in let q1, s1 = p1 in perm_opt_composable q0 q1 /\ // some of fracs can't exceed 1 not (Some? s0 && Some? s1) // at most one can have an anchor /// Compose permissions component wise, keeping the anchor if set let compose_permissions (#v:_) (p0:permission v) (p1:permission v{permission_composable p0 p1}) : permission v = compose_perm_opt (fst p0) (fst p1), (match snd p0, snd p1 with | None, a | a, None -> a) /// This is the central definition of the PCM --- defining when two /// values are composable, or equivalently, when one thread's /// knowledge of [av0] is compatible with another thread's knowledge /// of [av1] /// /// This definition shows the interplay between fractions and anchors. /// It wasn't obvious to me how to factor this further, e.g., adding /// anchors to preorders and then separately adding fractions to it. let avalue_composable (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (av0 av1: avalue anchors) : prop = let (p0, v0) = av0 in let (p1, v1) = av1 in permission_composable p0 p1 /\ (if not (has_some_ownership p0) && not (has_some_ownership p1) then p_composable _ v0 v1 //neither has ownership, one history is older than the other else if not (has_some_ownership p0) && has_some_ownership p1 then ( if has_nonzero p1 then v1 `extends` v0 //the one with ownership is more recent else ( //this part is the most subtle assert (has_anchor p1); p_composable _ v0 v1 /\ (v0 `extends` v1 ==> //if v0 is a more recent snapshot than v1 //then v0 must still be anchored by v1's anchor anchor_of p1 `anchors` curval v0) ) ) else if has_some_ownership p0 && not (has_some_ownership p1) then ( //symmetric if has_nonzero p0 then v0 `extends` v1 else ( assert (has_anchor p0); p_composable _ v0 v1 /\ (v1 `extends` v0 ==> anchor_of p0 `anchors` curval v1) ) ) else ( assert (has_some_ownership p0 && has_some_ownership p1); if has_nonzero p0 && has_nonzero p1 then v0 == v1 //if both have non-zero perm, then they must both only have read permission and must agree on the value else if has_nonzero p0 && has_anchor p1 then ( assert (not (has_nonzero p1)); //The key part of the anchor semantics: v0 `extends` v1 /\ //v0 has advanceable ownership, so extends anchor_of p1 `anchors` curval v0 //but not beyond what is allowed by s ) else if has_anchor p0 && has_nonzero p1 //symmetric then ( assert (not (has_nonzero p0)); v1 `extends` v0 /\ anchor_of p0 `anchors` curval v1 //v1 extends, but not beyond what is allowed by s ) else (assert false; False) ) ) //exhaustive /// Lifting avalue comosability to knowledge, including the unit let composable #v (#p:preorder v) (#a:anchor_rel p) : symrel (knowledge a) = fun (k0 k1:knowledge a) -> match k0, k1 with | Nothing, _ | _, Nothing -> True | Owns m, Owns m' -> avalue_composable m m' /// Compose avalues by composing permissions and composing the values /// using the underlying preorder PCM let compose_avalue (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (m0:avalue anchors) (m1:avalue anchors { avalue_composable m0 m1 } ) : avalue anchors = let p0, v0 = m0 in let p1, v1 = m1 in let p12 = compose_permissions p0 p1 in let v12 = p_op _ v0 v1 in p12, v12 //////////////////////////////////////////////////////////////////////////////// (** avalue composition is associative and commutative **) let compose_avalue_comm (#v:Type) (#p:preorder v) (#anc:anchor_rel p) (m0: avalue anc) (m1: avalue anc{ avalue_composable m0 m1 }) : Lemma (compose_avalue m0 m1 == compose_avalue m1 m0) = () let avalue_composable_assoc_l (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (m0: avalue anchors) (m1: avalue anchors) (m2: avalue anchors { avalue_composable m1 m2 /\ avalue_composable m0 (compose_avalue m1 m2) }) : Lemma (avalue_composable m0 m1 /\ avalue_composable (compose_avalue m0 m1) m2) = () let compose_avalue_assoc_l (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m0: avalue s) (m1: avalue s) (m2: avalue s { avalue_composable m1 m2 /\ avalue_composable m0 (compose_avalue m1 m2) }) : Lemma (avalue_composable m0 m1 /\ avalue_composable (compose_avalue m0 m1) m2 /\ compose_avalue m0 (compose_avalue m1 m2) == compose_avalue (compose_avalue m0 m1) m2) = avalue_composable_assoc_l m0 m1 m2 let avalue_composable_assoc_r (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (m0: avalue anchors) (m1: avalue anchors) (m2: avalue anchors { avalue_composable m0 m1 /\ avalue_composable (compose_avalue m0 m1) m2 }) : Lemma (avalue_composable m1 m2 /\ avalue_composable m0 (compose_avalue m1 m2)) = () let compose_avalue_assoc_r (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m0: avalue s) (m1: avalue s) (m2: avalue s{ avalue_composable m0 m1 /\ avalue_composable (compose_avalue m0 m1) m2 }) : Lemma (avalue_composable m1 m2 /\ avalue_composable m0 (compose_avalue m1 m2) /\ compose_avalue m0 (compose_avalue m1 m2) == compose_avalue (compose_avalue m0 m1) m2) = avalue_composable_assoc_r m0 m1 m2 //////////////////////////////////////////////////////////////////////////////// /// lifting avalue composition to knowledge, including unit let compose (#v:Type) (#p:preorder v) (#s:anchor_rel p) (k0:knowledge s) (k1:knowledge s{ composable k0 k1 }) : knowledge s = match k0, k1 with | Nothing, k | k, Nothing -> k | Owns m, Owns m' -> Owns (compose_avalue m m') let composable_assoc_r #v (#p:preorder v) (#s:anchor_rel p) (k0 k1 k2: knowledge s) : Lemma (requires composable k0 k1 /\ composable (compose k0 k1) k2) (ensures composable k1 k2 /\ composable k0 (compose k1 k2) /\ compose k0 (compose k1 k2) == compose (compose k0 k1) k2 ) = match k0, k1, k2 with | Nothing, _, _ | _, Nothing, _ | _, _, Nothing -> () | Owns m0, Owns m1, Owns m2 -> compose_avalue_assoc_r m0 m1 m2 let composable_assoc_l #v (#p:preorder v) (#s:anchor_rel p) (k0 k1 k2: knowledge s) : Lemma (requires composable k1 k2 /\ composable k0 (compose k1 k2)) (ensures composable k0 k1 /\ composable (compose k0 k1) k2 /\ compose k0 (compose k1 k2) == compose (compose k0 k1) k2) = match k0, k1, k2 with | Nothing, _, _ | _, Nothing, _ | _, _, Nothing -> () | Owns m0, Owns m1, Owns m2 -> compose_avalue_assoc_l m0 m1 m2 /// Now, we can define our PCM /// The core of the PCM let p0 #v #p #s : pcm' (knowledge #v #p s) = { composable; op=compose; one=Nothing } let avalue_perm (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) = fst m /// A avalue represents full ownership when the fraction is full AND /// the anchor is set. This means that no knowledge held by any other /// thread can constrain this value meaningfully. let avalue_owns (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) : prop = fst (avalue_perm m) == Some full_perm /\ Some? (snd (avalue_perm m)) let full_knowledge #v #p #s (kn:knowledge #v #p s) : prop = match kn with | Nothing -> False | Owns km -> avalue_owns km /// The PCM itself, together with proofs of its properties let pcm #v #p #s : pcm (knowledge #v #p s) = { p = p0; comm = (fun k0 k1 -> match k0, k1 with | Nothing, _ | _, Nothing -> () | Owns m0, Owns m1 -> compose_avalue_comm m0 m1); assoc = (fun k0 k1 k2 -> composable_assoc_l k0 k1 k2); assoc_r = (fun k0 k1 k2 -> composable_assoc_r k0 k1 k2); is_unit = (fun _ -> ()); refine = full_knowledge; } /// Some utilities: The value of an avalue let avalue_val (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue #v #p s) = snd m /// Updating the value, in a full-ownership situation, also involves
{ "checked_file": "/", "dependencies": [ "Steel.Preorder.fst.checked", "Steel.FractionalPermission.fst.checked", "prims.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked" ], "interface_file": false, "source_file": "Steel.FractionalAnchoredPreorder.fst" }
[ { "abbrev": false, "full_module": "Steel.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Steel.Preorder", "short_module": null }, { "abbrev": false, "full_module": "FStar.Preorder", "short_module": null }, { "abbrev": false, "full_module": "FStar.PCM", "short_module": null }, { "abbrev": false, "full_module": "Steel", "short_module": null }, { "abbrev": false, "full_module": "Steel", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
m: Steel.FractionalAnchoredPreorder.avalue s -> value: Steel.Preorder.vhist p {s (Steel.Preorder.curval value) (Steel.Preorder.curval value)} -> Steel.FractionalAnchoredPreorder.avalue s
Prims.Tot
[ "total" ]
[]
[ "FStar.Preorder.preorder", "Steel.FractionalAnchoredPreorder.anchor_rel", "Steel.FractionalAnchoredPreorder.avalue", "Steel.Preorder.vhist", "Steel.Preorder.curval", "FStar.Pervasives.Native.option", "Steel.FractionalPermission.perm", "FStar.Pervasives.Native.Mktuple2", "Steel.FractionalAnchoredPreorder.permission", "FStar.Pervasives.Native.tuple2", "FStar.Pervasives.Native.Some", "Steel.FractionalAnchoredPreorder.avalue_perm" ]
[]
false
false
false
false
false
let avalue_update (#v: Type) (#p: preorder v) (#s: anchor_rel p) (m: avalue s) (value: vhist p {s (curval value) (curval value)}) : avalue s =
let p, _ = avalue_perm m in let p' = p, Some (curval value) in (p', value)
false
Steel.FractionalAnchoredPreorder.fst
Steel.FractionalAnchoredPreorder.snapshot
val snapshot (#v: Type0) (#p: preorder v) (#s: anchor_rel p) (a: avalue s) : avalue s
val snapshot (#v: Type0) (#p: preorder v) (#s: anchor_rel p) (a: avalue s) : avalue s
let snapshot (#v:Type0) (#p:preorder v) (#s:anchor_rel p) (a: avalue s) : avalue s = (None, None), avalue_val a
{ "file_name": "lib/steel/Steel.FractionalAnchoredPreorder.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 30, "end_line": 572, "start_col": 0, "start_line": 569 }
(* Copyright 2021 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. Author: N. Swamy *) module Steel.FractionalAnchoredPreorder (** This module provides a partial commutative monoid (PCM) for use in the ghost state of a concurrent Steel program. Its goal is to facilitate a form of information-sharing between multiple threads including the following features: Fractions, Preorders, Snapshots, and Anchors --- Anchors are the most unusual. 1. Fractions: Ownership of the state is controlled by a fractional permission, so multiple threads may share read-only privileges on the state, but only one can have write permission. 2. Preorders: The ghost state is governed by a preorder p and all updates to the state must respect the preorder (a reflexive, transitive relation on the state) 3. Snapshots: Since the state always evolves by a preorder, it is possible to take a snapshot of the state. A snapshot does not confer any particular ownership on the state, except knowledge of a snapshot ensures that the current state is related to the snapshot by the preorder. 4. Anchors are a kind of refinement of the preorder. If a thread owns an anchored value [v], then no other thread, even a thread owning a full fractional permission, can advance the state "too far" from the anchor. In particular, the PCM is parameterized by a binary relation on values, [anchors:anchor_relation]. If a thread owns the anchor [v], then the current value `cur` of the state must be in relation [v `anchors` cur]. This can be used to ensure that the knowledge of one thread is never becomes too stale. For example, this allows one to model a shared monotonically increasing counter, where if one thread anchors knowledge of the counter at the value 5, no other thread can increase the value of the counter beyond, say, 10, (when the anchor relation is y - x <= 5), until the anchoring thread releases the anchor. Further, at any point, a thread can take a snapshot of the counter and rely on the fact that the value of the counter in the future will be >= the snapshot. *) open FStar.PCM open FStar.Preorder open Steel.Preorder open Steel.FractionalPermission #push-options "--fuel 0 --ifuel 2" /// A permission: is a pair of /// /// * an optional fractional permission; with `Some p` indicating /// some ownership, while `None` is an additional "0" permission /// value, to encode snapshots. /// /// * and an optional anchor, where `Some a` indicates the current /// value can't be too far from `a`. let permission (v:Type) = option perm & option v /// Non-zero permission is either a read or write permission let has_nonzero #v (p:permission v) = Some? (fst p) /// Has an anchor set let has_anchor #v (p:permission v) = Some? (snd p) /// Either an anchor or non-zero let has_some_ownership #v (p:permission v) = has_nonzero p || has_anchor p /// The anchoring value let anchor_of #v (p:permission v { has_anchor p }) : v = Some?.v (snd p) /// The anchoring relation: /// -- A binary relation on values /// -- refining the preorder /// -- and if x `anchors` z then it also anchors any `y` between `x` and `z` /// /// Explaining the third clause a bit: /// Think intuitively of anchoring relations as a kind of distance measure /// /// if `z` is close enough to `x` then if `z` is further than `y` /// (since it is ahead of `y` in the preorder) then `y` is also /// close enough to `x` let anchor_rel (#v:Type) (p:preorder v) = anchors:(v -> v -> prop) { (forall v0 v1. anchors v0 v1 ==> p v0 v1) /\ (forall x z. x `anchors` z ==> (forall y. p x y /\ p y z ==> x `anchors` y)) // } /// An implementation remark: We use Steel.Preorder here to /// generically transform any preorder into a PCM. That works by /// taking the value of the PCM to be a history of values related by /// the preorder. So, throughout, we'll be using the the [vhist p] /// from Steel.Preorder, the type of a non-empty history compatible /// with [p]. The details of the histories don't matter much for our /// purposes---we only care about the most recent value, for which /// we'll use [curval v]. /// If the anchor is set, then the current value is anchored by it let anchored (#v:Type) (#p:preorder v) (anchors:anchor_rel p) (pv:(permission v & vhist p)) = has_anchor (fst pv) ==> anchor_of (fst pv) `anchors` curval (snd pv) /// A value in our fractional anchored PCM is a pair of a permission /// and a p-compatible history, refined to ensure that if the anchor /// is set, then the current value is anchored by it. let avalue (#v:Type) (#p:preorder v) (anchors:anchor_rel p) = pv:(permission v & vhist p) { anchored anchors pv } /// initial_value: A utility to construct a value in the PCM #push-options "--fuel 1" let initial_value (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (value:v { anchors value value }) : avalue anchors = (Some full_perm, Some value), [value] #pop-options /// We add a unit element to [avalue], as needed for a PCM [@@erasable] noeq type knowledge (#v:Type) (#p:preorder v) (anchors:anchor_rel p) = | Owns : avalue anchors -> knowledge anchors | Nothing : knowledge anchors let b2p (b:bool) : prop = b == true /// Fractional permissions are composable when their sum <= 1.0 let perm_opt_composable (p0 p1:option perm) : prop = match p0, p1 with | None, None -> True | Some p, None | None, Some p -> b2p (p `lesser_equal_perm` full_perm) | Some p0, Some p1 -> b2p (sum_perm p0 p1 `lesser_equal_perm` full_perm) /// Composing them sums the permissions let compose_perm_opt (p0 p1:option perm) = match p0, p1 with | None, p | p, None -> p | Some p0, Some p1 -> Some (sum_perm p0 p1) /// Anchored permissions are composable when at most one of them has the anchor set let permission_composable #v (p0 p1 : permission v) : prop = let q0, s0 = p0 in let q1, s1 = p1 in perm_opt_composable q0 q1 /\ // some of fracs can't exceed 1 not (Some? s0 && Some? s1) // at most one can have an anchor /// Compose permissions component wise, keeping the anchor if set let compose_permissions (#v:_) (p0:permission v) (p1:permission v{permission_composable p0 p1}) : permission v = compose_perm_opt (fst p0) (fst p1), (match snd p0, snd p1 with | None, a | a, None -> a) /// This is the central definition of the PCM --- defining when two /// values are composable, or equivalently, when one thread's /// knowledge of [av0] is compatible with another thread's knowledge /// of [av1] /// /// This definition shows the interplay between fractions and anchors. /// It wasn't obvious to me how to factor this further, e.g., adding /// anchors to preorders and then separately adding fractions to it. let avalue_composable (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (av0 av1: avalue anchors) : prop = let (p0, v0) = av0 in let (p1, v1) = av1 in permission_composable p0 p1 /\ (if not (has_some_ownership p0) && not (has_some_ownership p1) then p_composable _ v0 v1 //neither has ownership, one history is older than the other else if not (has_some_ownership p0) && has_some_ownership p1 then ( if has_nonzero p1 then v1 `extends` v0 //the one with ownership is more recent else ( //this part is the most subtle assert (has_anchor p1); p_composable _ v0 v1 /\ (v0 `extends` v1 ==> //if v0 is a more recent snapshot than v1 //then v0 must still be anchored by v1's anchor anchor_of p1 `anchors` curval v0) ) ) else if has_some_ownership p0 && not (has_some_ownership p1) then ( //symmetric if has_nonzero p0 then v0 `extends` v1 else ( assert (has_anchor p0); p_composable _ v0 v1 /\ (v1 `extends` v0 ==> anchor_of p0 `anchors` curval v1) ) ) else ( assert (has_some_ownership p0 && has_some_ownership p1); if has_nonzero p0 && has_nonzero p1 then v0 == v1 //if both have non-zero perm, then they must both only have read permission and must agree on the value else if has_nonzero p0 && has_anchor p1 then ( assert (not (has_nonzero p1)); //The key part of the anchor semantics: v0 `extends` v1 /\ //v0 has advanceable ownership, so extends anchor_of p1 `anchors` curval v0 //but not beyond what is allowed by s ) else if has_anchor p0 && has_nonzero p1 //symmetric then ( assert (not (has_nonzero p0)); v1 `extends` v0 /\ anchor_of p0 `anchors` curval v1 //v1 extends, but not beyond what is allowed by s ) else (assert false; False) ) ) //exhaustive /// Lifting avalue comosability to knowledge, including the unit let composable #v (#p:preorder v) (#a:anchor_rel p) : symrel (knowledge a) = fun (k0 k1:knowledge a) -> match k0, k1 with | Nothing, _ | _, Nothing -> True | Owns m, Owns m' -> avalue_composable m m' /// Compose avalues by composing permissions and composing the values /// using the underlying preorder PCM let compose_avalue (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (m0:avalue anchors) (m1:avalue anchors { avalue_composable m0 m1 } ) : avalue anchors = let p0, v0 = m0 in let p1, v1 = m1 in let p12 = compose_permissions p0 p1 in let v12 = p_op _ v0 v1 in p12, v12 //////////////////////////////////////////////////////////////////////////////// (** avalue composition is associative and commutative **) let compose_avalue_comm (#v:Type) (#p:preorder v) (#anc:anchor_rel p) (m0: avalue anc) (m1: avalue anc{ avalue_composable m0 m1 }) : Lemma (compose_avalue m0 m1 == compose_avalue m1 m0) = () let avalue_composable_assoc_l (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (m0: avalue anchors) (m1: avalue anchors) (m2: avalue anchors { avalue_composable m1 m2 /\ avalue_composable m0 (compose_avalue m1 m2) }) : Lemma (avalue_composable m0 m1 /\ avalue_composable (compose_avalue m0 m1) m2) = () let compose_avalue_assoc_l (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m0: avalue s) (m1: avalue s) (m2: avalue s { avalue_composable m1 m2 /\ avalue_composable m0 (compose_avalue m1 m2) }) : Lemma (avalue_composable m0 m1 /\ avalue_composable (compose_avalue m0 m1) m2 /\ compose_avalue m0 (compose_avalue m1 m2) == compose_avalue (compose_avalue m0 m1) m2) = avalue_composable_assoc_l m0 m1 m2 let avalue_composable_assoc_r (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (m0: avalue anchors) (m1: avalue anchors) (m2: avalue anchors { avalue_composable m0 m1 /\ avalue_composable (compose_avalue m0 m1) m2 }) : Lemma (avalue_composable m1 m2 /\ avalue_composable m0 (compose_avalue m1 m2)) = () let compose_avalue_assoc_r (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m0: avalue s) (m1: avalue s) (m2: avalue s{ avalue_composable m0 m1 /\ avalue_composable (compose_avalue m0 m1) m2 }) : Lemma (avalue_composable m1 m2 /\ avalue_composable m0 (compose_avalue m1 m2) /\ compose_avalue m0 (compose_avalue m1 m2) == compose_avalue (compose_avalue m0 m1) m2) = avalue_composable_assoc_r m0 m1 m2 //////////////////////////////////////////////////////////////////////////////// /// lifting avalue composition to knowledge, including unit let compose (#v:Type) (#p:preorder v) (#s:anchor_rel p) (k0:knowledge s) (k1:knowledge s{ composable k0 k1 }) : knowledge s = match k0, k1 with | Nothing, k | k, Nothing -> k | Owns m, Owns m' -> Owns (compose_avalue m m') let composable_assoc_r #v (#p:preorder v) (#s:anchor_rel p) (k0 k1 k2: knowledge s) : Lemma (requires composable k0 k1 /\ composable (compose k0 k1) k2) (ensures composable k1 k2 /\ composable k0 (compose k1 k2) /\ compose k0 (compose k1 k2) == compose (compose k0 k1) k2 ) = match k0, k1, k2 with | Nothing, _, _ | _, Nothing, _ | _, _, Nothing -> () | Owns m0, Owns m1, Owns m2 -> compose_avalue_assoc_r m0 m1 m2 let composable_assoc_l #v (#p:preorder v) (#s:anchor_rel p) (k0 k1 k2: knowledge s) : Lemma (requires composable k1 k2 /\ composable k0 (compose k1 k2)) (ensures composable k0 k1 /\ composable (compose k0 k1) k2 /\ compose k0 (compose k1 k2) == compose (compose k0 k1) k2) = match k0, k1, k2 with | Nothing, _, _ | _, Nothing, _ | _, _, Nothing -> () | Owns m0, Owns m1, Owns m2 -> compose_avalue_assoc_l m0 m1 m2 /// Now, we can define our PCM /// The core of the PCM let p0 #v #p #s : pcm' (knowledge #v #p s) = { composable; op=compose; one=Nothing } let avalue_perm (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) = fst m /// A avalue represents full ownership when the fraction is full AND /// the anchor is set. This means that no knowledge held by any other /// thread can constrain this value meaningfully. let avalue_owns (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) : prop = fst (avalue_perm m) == Some full_perm /\ Some? (snd (avalue_perm m)) let full_knowledge #v #p #s (kn:knowledge #v #p s) : prop = match kn with | Nothing -> False | Owns km -> avalue_owns km /// The PCM itself, together with proofs of its properties let pcm #v #p #s : pcm (knowledge #v #p s) = { p = p0; comm = (fun k0 k1 -> match k0, k1 with | Nothing, _ | _, Nothing -> () | Owns m0, Owns m1 -> compose_avalue_comm m0 m1); assoc = (fun k0 k1 k2 -> composable_assoc_l k0 k1 k2); assoc_r = (fun k0 k1 k2 -> composable_assoc_r k0 k1 k2); is_unit = (fun _ -> ()); refine = full_knowledge; } /// Some utilities: The value of an avalue let avalue_val (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue #v #p s) = snd m /// Updating the value, in a full-ownership situation, also involves /// updating the anchor let avalue_update (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) (value:vhist p { s (curval value) (curval value) }) : avalue s = let p, _ = avalue_perm m in let p' = p, Some (curval value) in (p', value) /// Our core frame-preserving update: /// /// If you fully own a value, you can update it so long as you /// respect the preorder, and prove that the new value is related /// to itself by the anchor (since we'll be setting the anchor to /// the new value) /// /// This is a building block: we'll define a derived version that /// on values rather than histories #push-options "--z3rlimit_factor 2" let update_hist (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) (v1:vhist p { avalue_owns m /\ v1 `extends` avalue_val m /\ s (curval v1) (curval v1) }) : frame_preserving_upd pcm (Owns m) (Owns (avalue_update m v1)) = fun full_v -> let Owns full_m = full_v in let m_res = avalue_update full_m v1 in Owns m_res #pop-options /// Updating with value, rather than a history let avalue_update_value (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) (value:v { curval (avalue_val m) `p` value /\ s value value }) : m':avalue s { curval (avalue_val m') == value /\ avalue_val m' `extends` avalue_val m } = let v = avalue_val m in avalue_update m (extend_history v value) /// A derived frame-preserving update for which one presents only a value let update_value (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) (v1:v { avalue_owns m /\ //if you have full ownership of key curval (avalue_val m) `p` v1 /\ //you can update it wrt the preorder only s v1 v1 //and it is related to itself by the anchor }) : frame_preserving_upd pcm (Owns m) (Owns (avalue_update_value m v1)) = coerce_eq () (update_hist m (extend_history (avalue_val m) v1)) //F* goes nuts and starts swallowing gobs of memory without the coerce_eq: TODO, debug /// Now for anchored updates /// Ownership of the whole fraction, but not the anchor let avalue_owns_anchored (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) = fst (avalue_perm m) == Some full_perm /\ None? (snd (avalue_perm m)) /// [v1] is compatible with (i.e., not too far from) any anchor of [v0] let compat_with_any_anchor_of (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (v1:v) (v0:avalue anchors) = forall (anchor:v). anchor `anchors` curval (avalue_val v0) ==> anchor `anchors` v1 /// An anchored update: Update the value, but leave the permission /// unchanged Only possible if the new value is compatible with any /// anchor of the old value let avalue_anchored_update (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) (value:vhist p { curval value `compat_with_any_anchor_of` m }) : avalue s = avalue_perm m, value /// A frame-preserving update for anchored values. /// Notice the additional precondition, refining the preorder let update_anchored_hist (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) (v1:vhist p { avalue_owns_anchored m /\ v1 `extends` avalue_val m /\ curval v1 `compat_with_any_anchor_of` m }) : frame_preserving_upd pcm (Owns m) (Owns (avalue_anchored_update m v1)) = fun full_v -> let Owns full_m = full_v in let m_res = avalue_anchored_update full_m v1 in Owns m_res /// A derived form without a history on the new value let avalue_update_anchored_value (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) (value:v { curval (avalue_val m) `p` value /\ value `compat_with_any_anchor_of` m }) : m':avalue s { curval (avalue_val m') == value /\ avalue_val m' `extends` avalue_val m } = let v = avalue_val m in avalue_anchored_update m (extend_history v value) /// Derived frame-preserving update let update_anchored_value (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) (v1:v { avalue_owns_anchored m /\ //if you own an anchored key, you can update if you respect curval (avalue_val m) `p` v1 /\ //the preorder v1 `compat_with_any_anchor_of` m //and respect any anchor of the current value }) : frame_preserving_upd pcm (Owns m) (Owns (avalue_update_anchored_value m v1)) = coerce_eq () (update_anchored_hist m (extend_history (avalue_val m) v1)) //////////////////////////////////////////////////////////////////////////////// /// Now for some lemmas about which kinds of knowledge are compatible /// with others and about snapshots
{ "checked_file": "/", "dependencies": [ "Steel.Preorder.fst.checked", "Steel.FractionalPermission.fst.checked", "prims.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked" ], "interface_file": false, "source_file": "Steel.FractionalAnchoredPreorder.fst" }
[ { "abbrev": false, "full_module": "Steel.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Steel.Preorder", "short_module": null }, { "abbrev": false, "full_module": "FStar.Preorder", "short_module": null }, { "abbrev": false, "full_module": "FStar.PCM", "short_module": null }, { "abbrev": false, "full_module": "Steel", "short_module": null }, { "abbrev": false, "full_module": "Steel", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Steel.FractionalAnchoredPreorder.avalue s -> Steel.FractionalAnchoredPreorder.avalue s
Prims.Tot
[ "total" ]
[]
[ "FStar.Preorder.preorder", "Steel.FractionalAnchoredPreorder.anchor_rel", "Steel.FractionalAnchoredPreorder.avalue", "FStar.Pervasives.Native.Mktuple2", "Steel.FractionalAnchoredPreorder.permission", "Steel.Preorder.vhist", "FStar.Pervasives.Native.option", "Steel.FractionalPermission.perm", "FStar.Pervasives.Native.None", "Steel.FractionalAnchoredPreorder.avalue_val" ]
[]
false
false
false
false
false
let snapshot (#v: Type0) (#p: preorder v) (#s: anchor_rel p) (a: avalue s) : avalue s =
(None, None), avalue_val a
false
Vale.Arch.Types.fsti
Vale.Arch.Types.ior32
val ior32 (a b: nat32) : nat32
val ior32 (a b: nat32) : nat32
let ior32 (a:nat32) (b:nat32) : nat32 = ior a b
{ "file_name": "vale/code/arch/Vale.Arch.Types.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 54, "end_line": 25, "start_col": 7, "start_line": 25 }
module Vale.Arch.Types open FStar.Mul open Vale.Def.Opaque_s open Vale.Def.Types_s open Vale.Lib.Seqs_s open Vale.Lib.Seqs open Vale.Def.Words_s open Vale.Def.Words.Four_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Seq open FStar.Seq open Vale.Def.Words.Two_s unfold let ( *^ ) = nat32_xor unfold let ( *^^ ) = quad32_xor unfold let add_wrap32 (x:nat32) (y:nat32) : nat32 = add_wrap x y unfold let add_wrap64 (x:nat64) (y:nat64) : nat64 = add_wrap x y unfold let sub_wrap32 (x:nat32) (y:nat32) : nat32 = sub_wrap x y unfold let sub_wrap64 (x:nat64) (y:nat64) : nat64 = sub_wrap x y unfold let iand32 (a:nat32) (b:nat32) : nat32 = iand a b
{ "checked_file": "/", "dependencies": [ "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Two_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Seq.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.Arch.Types.fsti" }
[ { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Vale.Def.Words_s.nat32 -> b: Vale.Def.Words_s.nat32 -> Vale.Def.Words_s.nat32
Prims.Tot
[ "total" ]
[]
[ "Vale.Def.Words_s.nat32", "Vale.Def.Types_s.ior", "Vale.Def.Words_s.pow2_32" ]
[]
false
false
false
true
false
let ior32 (a b: nat32) : nat32 =
ior a b
false
Vale.Arch.Types.fsti
Vale.Arch.Types.inot32
val inot32 (a: nat32) : nat32
val inot32 (a: nat32) : nat32
let inot32 (a:nat32) : nat32 = inot a
{ "file_name": "vale/code/arch/Vale.Arch.Types.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 44, "end_line": 26, "start_col": 7, "start_line": 26 }
module Vale.Arch.Types open FStar.Mul open Vale.Def.Opaque_s open Vale.Def.Types_s open Vale.Lib.Seqs_s open Vale.Lib.Seqs open Vale.Def.Words_s open Vale.Def.Words.Four_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Seq open FStar.Seq open Vale.Def.Words.Two_s unfold let ( *^ ) = nat32_xor unfold let ( *^^ ) = quad32_xor unfold let add_wrap32 (x:nat32) (y:nat32) : nat32 = add_wrap x y unfold let add_wrap64 (x:nat64) (y:nat64) : nat64 = add_wrap x y unfold let sub_wrap32 (x:nat32) (y:nat32) : nat32 = sub_wrap x y unfold let sub_wrap64 (x:nat64) (y:nat64) : nat64 = sub_wrap x y unfold let iand32 (a:nat32) (b:nat32) : nat32 = iand a b unfold let ixor32 (a:nat32) (b:nat32) : nat32 = ixor a b
{ "checked_file": "/", "dependencies": [ "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Two_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Seq.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.Arch.Types.fsti" }
[ { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Vale.Def.Words_s.nat32 -> Vale.Def.Words_s.nat32
Prims.Tot
[ "total" ]
[]
[ "Vale.Def.Words_s.nat32", "Vale.Def.Types_s.inot", "Vale.Def.Words_s.pow2_32" ]
[]
false
false
false
true
false
let inot32 (a: nat32) : nat32 =
inot a
false
Vale.Arch.Types.fsti
Vale.Arch.Types.ishl32
val ishl32 (a: nat32) (s: int) : nat32
val ishl32 (a: nat32) (s: int) : nat32
let ishl32 (a:nat32) (s:int) : nat32 = ishl a s
{ "file_name": "vale/code/arch/Vale.Arch.Types.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 54, "end_line": 27, "start_col": 7, "start_line": 27 }
module Vale.Arch.Types open FStar.Mul open Vale.Def.Opaque_s open Vale.Def.Types_s open Vale.Lib.Seqs_s open Vale.Lib.Seqs open Vale.Def.Words_s open Vale.Def.Words.Four_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Seq open FStar.Seq open Vale.Def.Words.Two_s unfold let ( *^ ) = nat32_xor unfold let ( *^^ ) = quad32_xor unfold let add_wrap32 (x:nat32) (y:nat32) : nat32 = add_wrap x y unfold let add_wrap64 (x:nat64) (y:nat64) : nat64 = add_wrap x y unfold let sub_wrap32 (x:nat32) (y:nat32) : nat32 = sub_wrap x y unfold let sub_wrap64 (x:nat64) (y:nat64) : nat64 = sub_wrap x y unfold let iand32 (a:nat32) (b:nat32) : nat32 = iand a b unfold let ixor32 (a:nat32) (b:nat32) : nat32 = ixor a b unfold let ior32 (a:nat32) (b:nat32) : nat32 = ior a b
{ "checked_file": "/", "dependencies": [ "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Two_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Seq.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.Arch.Types.fsti" }
[ { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Vale.Def.Words_s.nat32 -> s: Prims.int -> Vale.Def.Words_s.nat32
Prims.Tot
[ "total" ]
[]
[ "Vale.Def.Words_s.nat32", "Prims.int", "Vale.Def.Types_s.ishl", "Vale.Def.Words_s.pow2_32" ]
[]
false
false
false
true
false
let ishl32 (a: nat32) (s: int) : nat32 =
ishl a s
false
Vale.Arch.Types.fsti
Vale.Arch.Types.iand64
val iand64 (a b: nat64) : nat64
val iand64 (a b: nat64) : nat64
let iand64 (a:nat64) (b:nat64) : nat64 = iand a b
{ "file_name": "vale/code/arch/Vale.Arch.Types.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 56, "end_line": 30, "start_col": 7, "start_line": 30 }
module Vale.Arch.Types open FStar.Mul open Vale.Def.Opaque_s open Vale.Def.Types_s open Vale.Lib.Seqs_s open Vale.Lib.Seqs open Vale.Def.Words_s open Vale.Def.Words.Four_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Seq open FStar.Seq open Vale.Def.Words.Two_s unfold let ( *^ ) = nat32_xor unfold let ( *^^ ) = quad32_xor unfold let add_wrap32 (x:nat32) (y:nat32) : nat32 = add_wrap x y unfold let add_wrap64 (x:nat64) (y:nat64) : nat64 = add_wrap x y unfold let sub_wrap32 (x:nat32) (y:nat32) : nat32 = sub_wrap x y unfold let sub_wrap64 (x:nat64) (y:nat64) : nat64 = sub_wrap x y unfold let iand32 (a:nat32) (b:nat32) : nat32 = iand a b unfold let ixor32 (a:nat32) (b:nat32) : nat32 = ixor a b unfold let ior32 (a:nat32) (b:nat32) : nat32 = ior a b unfold let inot32 (a:nat32) : nat32 = inot a unfold let ishl32 (a:nat32) (s:int) : nat32 = ishl a s unfold let ishr32 (a:nat32) (s:int) : nat32 = ishr a s
{ "checked_file": "/", "dependencies": [ "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Two_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Seq.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.Arch.Types.fsti" }
[ { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Vale.Def.Words_s.nat64 -> b: Vale.Def.Words_s.nat64 -> Vale.Def.Words_s.nat64
Prims.Tot
[ "total" ]
[]
[ "Vale.Def.Words_s.nat64", "Vale.Def.Types_s.iand", "Vale.Def.Words_s.pow2_64" ]
[]
false
false
false
true
false
let iand64 (a b: nat64) : nat64 =
iand a b
false
Spec.Agile.HPKE.fst
Spec.Agile.HPKE.sealAuth
val sealAuth: cs:ciphersuite_not_export_only -> skE:key_dh_secret_s cs -> pkR:DH.serialized_point (kem_dh_of_cs cs) -> info:info_s cs -> aad:AEAD.ad (aead_alg_of cs) -> pt:AEAD.plain (aead_alg_of cs) -> skS:key_dh_secret_s cs -> Tot (option (key_dh_public_s cs & AEAD.encrypted #(aead_alg_of cs) pt))
val sealAuth: cs:ciphersuite_not_export_only -> skE:key_dh_secret_s cs -> pkR:DH.serialized_point (kem_dh_of_cs cs) -> info:info_s cs -> aad:AEAD.ad (aead_alg_of cs) -> pt:AEAD.plain (aead_alg_of cs) -> skS:key_dh_secret_s cs -> Tot (option (key_dh_public_s cs & AEAD.encrypted #(aead_alg_of cs) pt))
let sealAuth cs skE pkR info aad pt skS = match setupAuthS cs skE pkR info skS with | None -> None | Some (enc, ctx) -> match context_seal cs ctx aad pt with | None -> None | Some (_, ct) -> Some (enc, ct)
{ "file_name": "specs/Spec.Agile.HPKE.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 36, "end_line": 564, "start_col": 0, "start_line": 558 }
module Spec.Agile.HPKE open FStar.Mul open Lib.IntTypes open Lib.RawIntTypes open Lib.Sequence open Lib.ByteSequence module DH = Spec.Agile.DH module AEAD = Spec.Agile.AEAD module Hash = Spec.Agile.Hash module HKDF = Spec.Agile.HKDF let pow2_61 : _:unit{pow2 61 == 2305843009213693952} = assert_norm(pow2 61 == 2305843009213693952) let pow2_35_less_than_pow2_61 : _:unit{pow2 32 * pow2 3 <= pow2 61 - 1} = assert_norm(pow2 32 * pow2 3 <= pow2 61 - 1) let pow2_35_less_than_pow2_125 : _:unit{pow2 32 * pow2 3 <= pow2 125 - 1} = assert_norm(pow2 32 * pow2 3 <= pow2 125 - 1) #set-options "--z3rlimit 20 --fuel 0 --ifuel 1" /// Types val id_kem: cs:ciphersuite -> Tot (lbytes 2) let id_kem cs = let kem_dh, kem_hash, _, _ = cs in match kem_dh, kem_hash with | DH.DH_P256, Hash.SHA2_256 -> create 1 (u8 0) @| create 1 (u8 16) | DH.DH_Curve25519, Hash.SHA2_256 -> create 1 (u8 0) @| create 1 (u8 32) val id_kdf: cs:ciphersuite -> Tot (lbytes 2) let id_kdf cs = let _, _, _, h = cs in match h with | Hash.SHA2_256 -> create 1 (u8 0) @| create 1 (u8 1) | Hash.SHA2_384 -> create 1 (u8 0) @| create 1 (u8 2) | Hash.SHA2_512 -> create 1 (u8 0) @| create 1 (u8 3) val id_aead: cs:ciphersuite -> Tot (lbytes 2) let id_aead cs = let _, _, a, _ = cs in match a with | Seal AEAD.AES128_GCM -> create 1 (u8 0) @| create 1 (u8 1) | Seal AEAD.AES256_GCM -> create 1 (u8 0) @| create 1 (u8 2) | Seal AEAD.CHACHA20_POLY1305 -> create 1 (u8 0) @| create 1 (u8 3) | ExportOnly -> create 1 (u8 255) @| create 1 (u8 255) val suite_id_kem: cs:ciphersuite -> Tot (lbytes size_suite_id_kem) let suite_id_kem cs = Seq.append label_KEM (id_kem cs) val suite_id_hpke: cs:ciphersuite -> Tot (lbytes size_suite_id_hpke) let suite_id_hpke cs = Seq.append label_HPKE (id_kem cs @| id_kdf cs @| id_aead cs) val id_of_mode: m:mode -> Tot (lbytes size_mode_identifier) let id_of_mode m = match m with | Base -> create 1 (u8 0) | PSK -> create 1 (u8 1) | Auth -> create 1 (u8 2) | AuthPSK -> create 1 (u8 3) val labeled_extract: a:hash_algorithm -> suite_id:bytes -> salt:bytes -> label:bytes -> ikm:bytes -> Pure (lbytes (Spec.Hash.Definitions.hash_length a)) (requires Spec.Agile.HMAC.keysized a (Seq.length salt) /\ labeled_extract_ikm_length_pred a (Seq.length suite_id + Seq.length label + Seq.length ikm)) (ensures fun _ -> True) let labeled_extract a suite_id salt label ikm = let labeled_ikm1 = Seq.append label_version suite_id in let labeled_ikm2 = Seq.append labeled_ikm1 label in let labeled_ikm3 = Seq.append labeled_ikm2 ikm in HKDF.extract a salt labeled_ikm3 val labeled_expand: a:hash_algorithm -> suite_id:bytes -> prk:bytes -> label:bytes -> info:bytes -> l:size_nat -> Pure (lbytes l) (requires Spec.Hash.Definitions.hash_length a <= Seq.length prk /\ Spec.Agile.HMAC.keysized a (Seq.length prk) /\ labeled_expand_info_length_pred a (Seq.length suite_id + Seq.length label + Seq.length info) /\ HKDF.expand_output_length_pred a l) (ensures fun _ -> True) let labeled_expand a suite_id prk label info l = let labeled_info1 = nat_to_bytes_be 2 l in let labeled_info2 = Seq.append labeled_info1 label_version in let labeled_info3 = Seq.append labeled_info2 suite_id in let labeled_info4 = Seq.append labeled_info3 label in let labeled_info5 = Seq.append labeled_info4 info in HKDF.expand a prk labeled_info5 l let extract_and_expand_dh_pred (cs:ciphersuite) (dh_length:nat) = labeled_extract_ikm_length_pred (kem_hash_of_cs cs) (size_suite_id_kem + size_label_eae_prk + dh_length) let extract_and_expand_ctx_pred (cs:ciphersuite) (ctx_length:nat) = labeled_expand_info_length_pred (kem_hash_of_cs cs) (size_suite_id_kem + size_label_shared_secret + ctx_length) val extract_and_expand: cs:ciphersuite -> dh:bytes -> kem_context:bytes -> Pure (key_kem_s cs) (requires extract_and_expand_dh_pred cs (Seq.length dh) /\ extract_and_expand_ctx_pred cs (Seq.length kem_context)) (ensures fun _ -> True) let extract_and_expand cs dh kem_context = let eae_prk = labeled_extract (kem_hash_of_cs cs) (suite_id_kem cs) lbytes_empty label_eae_prk dh in labeled_expand (kem_hash_of_cs cs) (suite_id_kem cs) eae_prk label_shared_secret kem_context (size_kem_key cs) let deserialize_public_key cs pk = match kem_dh_of_cs cs with | DH.DH_Curve25519 -> pk // Extract the point coordinates by removing the first representation byte | DH.DH_P256 -> sub pk 1 64 let serialize_public_key cs pk = match kem_dh_of_cs cs with | DH.DH_Curve25519 -> pk // Add the first representation byte to the point coordinates | DH.DH_P256 -> create 1 (u8 4) @| pk val dkp_nist_p: cs:ciphersuite -> lbytes (size_kem_kdf cs) -> counter:uint8 -> Tot (option (key_dh_secret_s cs & key_dh_public_s cs)) (decreases 255 - v counter) let rec dkp_nist_p cs dkp_prk counter = let counterbyte = nat_to_intseq_be #U8 #SEC 1 (v counter) in let bytes = labeled_expand (kem_hash_of_cs cs) (suite_id_kem cs) dkp_prk label_candidate counterbyte (size_dh_key cs) in let bytes = Lib.Sequence.map2 (logand #U8 #SEC) bytes (Seq.create (size_dh_key cs) (u8 255)) in let sk = nat_from_intseq_be #U8 #SEC bytes in if sk = 0 || sk >= Spec.P256.prime then if (v counter) = 255 then None else dkp_nist_p cs dkp_prk (counter +! (u8 1)) else match DH.secret_to_public (kem_dh_of_cs cs) bytes with | Some pk -> Some (bytes, serialize_public_key cs pk) | None -> if (v counter) = 255 then None else dkp_nist_p cs dkp_prk (counter +! (u8 1)) let derive_key_pair cs ikm = match kem_dh_of_cs cs with | DH.DH_Curve25519 -> begin let dkp_prk = labeled_extract (kem_hash_of_cs cs) (suite_id_kem cs) lbytes_empty label_dkp_prk ikm in let sk = labeled_expand (kem_hash_of_cs cs) (suite_id_kem cs) dkp_prk label_sk lbytes_empty (size_dh_key cs) in match DH.secret_to_public (kem_dh_of_cs cs) sk with | Some pk -> Some (sk, serialize_public_key cs pk) end | DH.DH_P256 -> let dkp_prk = labeled_extract (kem_hash_of_cs cs) (suite_id_kem cs) lbytes_empty label_dkp_prk ikm in dkp_nist_p cs dkp_prk (u8 0) val prepare_dh: cs:ciphersuite -> DH.serialized_point (kem_dh_of_cs cs) -> Tot (lbytes 32) let prepare_dh cs dh = match (kem_dh_of_cs cs) with | DH.DH_Curve25519 -> serialize_public_key cs dh | DH.DH_P256 -> sub dh 0 32 val encap: cs:ciphersuite -> skE:key_dh_secret_s cs -> pkR:DH.serialized_point (kem_dh_of_cs cs) -> Tot (option (key_kem_s cs & key_dh_public_s cs)) #restart-solver #set-options "--z3rlimit 100 --fuel 0 --ifuel 0" let encap cs skE pkR = let _ = allow_inversion Spec.Agile.DH.algorithm in match DH.secret_to_public (kem_dh_of_cs cs) skE with | None -> None | Some pkE -> let enc = serialize_public_key cs pkE in match DH.dh (kem_dh_of_cs cs) skE pkR with | None -> None | Some dh -> let pkRm = serialize_public_key cs pkR in let kem_context = concat enc pkRm in let dhm = prepare_dh cs dh in assert (Seq.length kem_context = 2*size_dh_public cs); assert (extract_and_expand_ctx_pred cs (Seq.length kem_context)); let shared_secret:key_kem_s cs = extract_and_expand cs dhm kem_context in Some (shared_secret, enc) val decap: cs: ciphersuite -> enc: key_dh_public_s cs -> skR: key_dh_secret_s cs -> Tot (option (key_kem_s cs)) #set-options "--z3rlimit 100 --fuel 0 --ifuel 0" let decap cs enc skR = let _ = allow_inversion Spec.Agile.DH.algorithm in let _ = allow_inversion Spec.Agile.Hash.hash_alg in let pkE = deserialize_public_key cs enc in match DH.dh (kem_dh_of_cs cs) skR pkE with | None -> None | Some dh -> match DH.secret_to_public (kem_dh_of_cs cs) skR with | None -> None | Some pkR -> let pkRm = serialize_public_key cs pkR in let kem_context = concat enc pkRm in let dhm = prepare_dh cs dh in assert (Seq.length kem_context = 2*size_dh_public cs); assert (extract_and_expand_ctx_pred cs (Seq.length kem_context)); let shared_secret = extract_and_expand cs dhm kem_context in Some (shared_secret) val auth_encap: cs:ciphersuite -> skE:key_dh_secret_s cs -> pkR:DH.serialized_point (kem_dh_of_cs cs) -> skS:key_dh_secret_s cs -> Tot (option (key_kem_s cs & key_dh_public_s cs)) #set-options "--z3rlimit 100 --fuel 0 --ifuel 0" let auth_encap cs skE pkR skS = let _ = allow_inversion Spec.Agile.DH.algorithm in match DH.secret_to_public (kem_dh_of_cs cs) skE with | None -> None | Some pkE -> match DH.dh (kem_dh_of_cs cs) skE pkR with | None -> None | Some es -> match DH.dh (kem_dh_of_cs cs) skS pkR with | None -> None | Some ss -> let esm = prepare_dh cs es in let ssm = prepare_dh cs ss in // TODO Do not put 32 literally let dh = concat #uint8 #32 #32 esm ssm in let enc = serialize_public_key cs pkE in match DH.secret_to_public (kem_dh_of_cs cs) skS with | None -> None | Some pkS -> let pkSm = serialize_public_key cs pkS in let pkRm = serialize_public_key cs pkR in let kem_context = concat enc (concat pkRm pkSm) in assert (Seq.length kem_context = 3*size_dh_public cs); assert (labeled_expand_info_length_pred (kem_hash_of_cs cs) (size_suite_id_kem + size_label_shared_secret + Seq.length kem_context)); assert (extract_and_expand_ctx_pred cs (Seq.length kem_context)); // TODO Do not put 64 literally assert (Seq.length dh = 64); assert (labeled_extract_ikm_length_pred (kem_hash_of_cs cs) (size_suite_id_kem + size_label_eae_prk + Seq.length dh)); assert (extract_and_expand_dh_pred cs (Seq.length dh)); let shared_secret = extract_and_expand cs dh kem_context in Some (shared_secret, enc) #reset-options val auth_decap: cs: ciphersuite -> enc: key_dh_public_s cs -> skR: key_dh_secret_s cs -> pkS: DH.serialized_point (kem_dh_of_cs cs) -> Tot (option (key_kem_s cs)) #restart-solver #set-options "--z3rlimit 100 --fuel 0 --ifuel 0" let auth_decap cs enc skR pkS = let _ = allow_inversion Spec.Agile.DH.algorithm in let pkE = deserialize_public_key cs enc in match DH.dh (kem_dh_of_cs cs) skR pkE with | None -> None | Some es -> match DH.dh (kem_dh_of_cs cs) skR pkS with | None -> None | Some ss -> let esm = prepare_dh cs es in let ssm = prepare_dh cs ss in let dh = concat #uint8 #32 #32 esm ssm in match DH.secret_to_public (kem_dh_of_cs cs) skR with | None -> None | Some pkR -> let pkRm = serialize_public_key cs pkR in let pkSm = serialize_public_key cs pkS in let kem_context = concat enc (concat pkRm pkSm) in assert (Seq.length kem_context = 3*size_dh_public cs); assert (labeled_expand_info_length_pred (kem_hash_of_cs cs) (size_suite_id_kem + size_label_shared_secret + Seq.length kem_context)); assert (extract_and_expand_ctx_pred cs (Seq.length kem_context)); assert (Seq.length dh = 64); assert (labeled_extract_ikm_length_pred (kem_hash_of_cs cs) (size_suite_id_kem + size_label_eae_prk + Seq.length dh)); assert (extract_and_expand_dh_pred cs (Seq.length dh)); let shared_secret = extract_and_expand cs dh kem_context in Some (shared_secret) #reset-options let default_psk = lbytes_empty let default_psk_id = lbytes_empty val build_context: cs:ciphersuite -> m:mode -> psk_id_hash:lbytes (size_kdf cs) -> info_hash:lbytes (size_kdf cs) -> Tot (lbytes (size_ks_ctx cs)) let build_context cs m psk_id_hash info_hash = let context = id_of_mode m in let context = Seq.append context psk_id_hash in let context = Seq.append context info_hash in context let verify_psk_inputs (cs:ciphersuite) (m:mode) (opsk:option(psk_s cs & psk_id_s cs)) : bool = match (m, opsk) with | Base, None -> true | PSK, Some _ -> true | Auth, None -> true | AuthPSK, Some _ -> true | _, _ -> false // key and nonce are zero-length if AEAD is Export-Only let encryption_context (cs:ciphersuite) = key_aead_s cs & nonce_aead_s cs & seq_aead_s cs & exporter_secret_s cs val key_schedule: cs:ciphersuite -> m:mode -> shared_secret:key_kem_s cs -> info:info_s cs -> opsk:option (psk_s cs & psk_id_s cs) -> Pure (encryption_context cs) (requires verify_psk_inputs cs m opsk) (ensures fun _ -> True) #set-options "--z3rlimit 500 --fuel 0 --ifuel 2" let key_schedule_core (cs:ciphersuite) (m:mode) (shared_secret:key_kem_s cs) (info:info_s cs) (opsk:option (psk_s cs & psk_id_s cs)) : (lbytes (size_ks_ctx cs) & exporter_secret_s cs & (lbytes (Spec.Hash.Definitions.hash_length (hash_of_cs cs)))) = let (psk, psk_id) = match opsk with | None -> (default_psk, default_psk_id) | Some (psk, psk_id) -> (psk, psk_id) in let psk_id_hash = labeled_extract (hash_of_cs cs) (suite_id_hpke cs) lbytes_empty label_psk_id_hash psk_id in let info_hash = labeled_extract (hash_of_cs cs) (suite_id_hpke cs) lbytes_empty label_info_hash info in let context = build_context cs m psk_id_hash info_hash in let secret = labeled_extract (hash_of_cs cs) (suite_id_hpke cs) shared_secret label_secret psk in let exporter_secret = labeled_expand (hash_of_cs cs) (suite_id_hpke cs) secret label_exp context (size_kdf cs) in context, exporter_secret, secret let key_schedule_end (cs:ciphersuite) (m:mode) (context:lbytes (size_ks_ctx cs)) (exporter_secret:exporter_secret_s cs) (secret:(lbytes (Spec.Hash.Definitions.hash_length (hash_of_cs cs)))) : encryption_context cs = if is_valid_not_export_only_ciphersuite cs then ( let key = labeled_expand (hash_of_cs cs) (suite_id_hpke cs) secret label_key context (size_aead_key cs) in let base_nonce = labeled_expand (hash_of_cs cs) (suite_id_hpke cs) secret label_base_nonce context (size_aead_nonce cs) in (key, base_nonce, 0, exporter_secret) ) else ( (* if AEAD is Export-Only, then skip computation of key and base_nonce *) assert (size_aead_key cs = 0); assert (size_aead_nonce cs = 0); (lbytes_empty, lbytes_empty, 0, exporter_secret)) let key_schedule cs m shared_secret info opsk = let context, exporter_secret, secret = key_schedule_core cs m shared_secret info opsk in key_schedule_end cs m context exporter_secret secret let key_of_ctx (cs:ciphersuite) (ctx:encryption_context cs) = let key, _, _, _ = ctx in key let base_nonce_of_ctx (cs:ciphersuite) (ctx:encryption_context cs) = let _, base_nonce, _, _ = ctx in base_nonce let seq_of_ctx (cs:ciphersuite) (ctx:encryption_context cs) = let _, _, seq, _ = ctx in seq let exp_sec_of_ctx (cs:ciphersuite) (ctx:encryption_context cs) = let _, _, _, exp_sec = ctx in exp_sec let set_seq (cs:ciphersuite) (ctx:encryption_context cs) (seq:seq_aead_s cs) = let key, base_nonce, _, exp_sec = ctx in (key, base_nonce, seq, exp_sec) /// /// Encryption Context /// let context_export cs ctx exp_ctx l = let exp_sec = exp_sec_of_ctx cs ctx in labeled_expand (hash_of_cs cs) (suite_id_hpke cs) exp_sec label_sec exp_ctx l let context_compute_nonce cs ctx seq = let base_nonce = base_nonce_of_ctx cs ctx in let enc_seq = nat_to_bytes_be (size_aead_nonce cs) seq in Spec.Loops.seq_map2 logxor enc_seq base_nonce let context_increment_seq cs ctx = let seq = seq_of_ctx cs ctx in if seq = max_seq cs then None else Some (set_seq cs ctx (seq + 1)) let context_seal cs ctx aad pt = let key = key_of_ctx cs ctx in let seq = seq_of_ctx cs ctx in let nonce = context_compute_nonce cs ctx seq in let ct = AEAD.encrypt key nonce aad pt in match context_increment_seq cs ctx with | None -> None | Some new_ctx -> Some (new_ctx, ct) let context_open cs ctx aad ct = let key = key_of_ctx cs ctx in let seq = seq_of_ctx cs ctx in let nonce = context_compute_nonce cs ctx seq in match AEAD.decrypt key nonce aad ct with | None -> None | Some pt -> match context_increment_seq cs ctx with | None -> None | Some new_ctx -> Some (new_ctx, pt) /// /// Base Mode /// let setupBaseS cs skE pkR info = match encap cs skE pkR with | None -> None | Some (shared_secret, enc) -> let enc_ctx = key_schedule cs Base shared_secret info None in Some (enc, enc_ctx) let setupBaseR cs enc skR info = let pkR = DH.secret_to_public (kem_dh_of_cs cs) skR in let shared_secret = decap cs enc skR in match pkR, shared_secret with | Some pkR, Some shared_secret -> Some (key_schedule cs Base shared_secret info None) | _ -> None let sealBase cs skE pkR info aad pt = match setupBaseS cs skE pkR info with | None -> None | Some (enc, ctx) -> match context_seal cs ctx aad pt with | None -> None | Some (_, ct) -> Some (enc, ct) let openBase cs enc skR info aad ct = match setupBaseR cs enc skR info with | None -> None | Some ctx -> match context_open cs ctx aad ct with | None -> None | Some (_, pt) -> Some pt let sendExportBase cs skE pkR info exp_ctx l = match setupBaseS cs skE pkR info with | None -> None | Some (enc, ctx) -> Some (enc, context_export cs ctx exp_ctx l) let receiveExportBase cs enc skR info exp_ctx l = match setupBaseR cs enc skR info with | None -> None | Some ctx -> Some (context_export cs ctx exp_ctx l) /// /// PSK mode /// let setupPSKS cs skE pkR info psk psk_id = match encap cs skE pkR with | None -> None | Some (shared_secret, enc) -> assert (verify_psk_inputs cs PSK (Some (psk, psk_id))); let enc_ctx = key_schedule cs PSK shared_secret info (Some (psk, psk_id)) in Some (enc, enc_ctx) let setupPSKR cs enc skR info psk psk_id = let pkR = DH.secret_to_public (kem_dh_of_cs cs) skR in let shared_secret = decap cs enc skR in match pkR, shared_secret with | Some pkR, Some shared_secret -> Some (key_schedule cs PSK shared_secret info (Some (psk, psk_id))) | _ -> None let sealPSK cs skE pkR info aad pt psk psk_id = match setupPSKS cs skE pkR info psk psk_id with | None -> None | Some (enc, ctx) -> match context_seal cs ctx aad pt with | None -> None | Some (_, ct) -> Some (enc, ct) #restart-solver let openPSK cs enc skR info aad ct psk psk_id = match setupPSKR cs enc skR info psk psk_id with | None -> None | Some ctx -> match context_open cs ctx aad ct with | None -> None | Some (_, pt) -> Some pt let sendExportPSK cs skE pkR info exp_ctx l psk psk_id = match setupPSKS cs skE pkR info psk psk_id with | None -> None | Some (enc, ctx) -> Some (enc, context_export cs ctx exp_ctx l) let receiveExportPSK cs enc skR info exp_ctx l psk psk_id = match setupPSKR cs enc skR info psk psk_id with | None -> None | Some ctx -> Some (context_export cs ctx exp_ctx l) /// /// Auth mode /// let setupAuthS cs skE pkR info skS = match auth_encap cs skE pkR skS with | None -> None | Some (shared_secret, enc) -> let enc_ctx = key_schedule cs Auth shared_secret info None in Some (enc, enc_ctx) let setupAuthR cs enc skR info pkS = let pkR = DH.secret_to_public (kem_dh_of_cs cs) skR in let shared_secret = auth_decap cs enc skR pkS in match pkR, shared_secret with | Some pkR, Some shared_secret -> Some (key_schedule cs Auth shared_secret info None) | _ -> None
{ "checked_file": "/", "dependencies": [ "Spec.P256.fst.checked", "Spec.Loops.fst.checked", "Spec.Hash.Definitions.fst.checked", "Spec.Agile.HMAC.fsti.checked", "Spec.Agile.HKDF.fsti.checked", "Spec.Agile.Hash.fsti.checked", "Spec.Agile.DH.fst.checked", "Spec.Agile.AEAD.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.RawIntTypes.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Spec.Agile.HPKE.fst" }
[ { "abbrev": true, "full_module": "Spec.Agile.HKDF", "short_module": "HKDF" }, { "abbrev": true, "full_module": "Spec.Agile.Hash", "short_module": "Hash" }, { "abbrev": true, "full_module": "Spec.Agile.AEAD", "short_module": "AEAD" }, { "abbrev": true, "full_module": "Spec.Agile.DH", "short_module": "DH" }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.RawIntTypes", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Spec.Agile.HKDF", "short_module": "HKDF" }, { "abbrev": true, "full_module": "Spec.Agile.Hash", "short_module": "Hash" }, { "abbrev": true, "full_module": "Spec.Agile.AEAD", "short_module": "AEAD" }, { "abbrev": true, "full_module": "Spec.Agile.DH", "short_module": "DH" }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.RawIntTypes", "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.Agile", "short_module": null }, { "abbrev": false, "full_module": "Spec.Agile", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 500, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
cs: Spec.Agile.HPKE.ciphersuite_not_export_only -> skE: Spec.Agile.HPKE.key_dh_secret_s cs -> pkR: Spec.Agile.DH.serialized_point (Spec.Agile.HPKE.kem_dh_of_cs cs) -> info: Spec.Agile.HPKE.info_s cs -> aad: Spec.Agile.AEAD.ad (Spec.Agile.HPKE.aead_alg_of cs) -> pt: Spec.Agile.AEAD.plain (Spec.Agile.HPKE.aead_alg_of cs) -> skS: Spec.Agile.HPKE.key_dh_secret_s cs -> FStar.Pervasives.Native.option (Spec.Agile.HPKE.key_dh_public_s cs * Spec.Agile.AEAD.encrypted pt)
Prims.Tot
[ "total" ]
[]
[ "Spec.Agile.HPKE.ciphersuite_not_export_only", "Spec.Agile.HPKE.key_dh_secret_s", "Spec.Agile.DH.serialized_point", "Spec.Agile.HPKE.kem_dh_of_cs", "Spec.Agile.HPKE.info_s", "Spec.Agile.AEAD.ad", "Spec.Agile.HPKE.aead_alg_of", "Spec.Agile.AEAD.plain", "Spec.Agile.HPKE.setupAuthS", "FStar.Pervasives.Native.None", "FStar.Pervasives.Native.tuple2", "Spec.Agile.HPKE.key_dh_public_s", "Spec.Agile.AEAD.encrypted", "Spec.Agile.HPKE.encryption_context", "Spec.Agile.HPKE.context_seal", "Spec.Agile.AEAD.cipher", "FStar.Pervasives.Native.Some", "FStar.Pervasives.Native.Mktuple2", "FStar.Pervasives.Native.option" ]
[]
false
false
false
false
false
let sealAuth cs skE pkR info aad pt skS =
match setupAuthS cs skE pkR info skS with | None -> None | Some (enc, ctx) -> match context_seal cs ctx aad pt with | None -> None | Some (_, ct) -> Some (enc, ct)
false
Vale.Arch.Types.fsti
Vale.Arch.Types.ixor128
val ixor128 (a b: nat128) : nat128
val ixor128 (a b: nat128) : nat128
let ixor128 (a:nat128) (b:nat128) : nat128 = ixor a b
{ "file_name": "vale/code/arch/Vale.Arch.Types.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 60, "end_line": 38, "start_col": 7, "start_line": 38 }
module Vale.Arch.Types open FStar.Mul open Vale.Def.Opaque_s open Vale.Def.Types_s open Vale.Lib.Seqs_s open Vale.Lib.Seqs open Vale.Def.Words_s open Vale.Def.Words.Four_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Seq open FStar.Seq open Vale.Def.Words.Two_s unfold let ( *^ ) = nat32_xor unfold let ( *^^ ) = quad32_xor unfold let add_wrap32 (x:nat32) (y:nat32) : nat32 = add_wrap x y unfold let add_wrap64 (x:nat64) (y:nat64) : nat64 = add_wrap x y unfold let sub_wrap32 (x:nat32) (y:nat32) : nat32 = sub_wrap x y unfold let sub_wrap64 (x:nat64) (y:nat64) : nat64 = sub_wrap x y unfold let iand32 (a:nat32) (b:nat32) : nat32 = iand a b unfold let ixor32 (a:nat32) (b:nat32) : nat32 = ixor a b unfold let ior32 (a:nat32) (b:nat32) : nat32 = ior a b unfold let inot32 (a:nat32) : nat32 = inot a unfold let ishl32 (a:nat32) (s:int) : nat32 = ishl a s unfold let ishr32 (a:nat32) (s:int) : nat32 = ishr a s unfold let iand64 (a:nat64) (b:nat64) : nat64 = iand a b unfold let ixor64 (a:nat64) (b:nat64) : nat64 = ixor a b unfold let ior64 (a:nat64) (b:nat64) : nat64 = ior a b unfold let inot64 (a:nat64) : nat64 = inot a unfold let ishl64 (a:nat64) (s:int) : nat64 = ishl a s unfold let ishr64 (a:nat64) (s:int) : nat64 = ishr a s
{ "checked_file": "/", "dependencies": [ "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Two_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Seq.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.Arch.Types.fsti" }
[ { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Vale.Def.Words_s.nat128 -> b: Vale.Def.Words_s.nat128 -> Vale.Def.Words_s.nat128
Prims.Tot
[ "total" ]
[]
[ "Vale.Def.Words_s.nat128", "Vale.Def.Types_s.ixor", "Vale.Def.Words_s.pow2_128" ]
[]
false
false
false
true
false
let ixor128 (a b: nat128) : nat128 =
ixor a b
false
Vale.Arch.Types.fsti
Vale.Arch.Types.inot64
val inot64 (a: nat64) : nat64
val inot64 (a: nat64) : nat64
let inot64 (a:nat64) : nat64 = inot a
{ "file_name": "vale/code/arch/Vale.Arch.Types.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 44, "end_line": 33, "start_col": 7, "start_line": 33 }
module Vale.Arch.Types open FStar.Mul open Vale.Def.Opaque_s open Vale.Def.Types_s open Vale.Lib.Seqs_s open Vale.Lib.Seqs open Vale.Def.Words_s open Vale.Def.Words.Four_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Seq open FStar.Seq open Vale.Def.Words.Two_s unfold let ( *^ ) = nat32_xor unfold let ( *^^ ) = quad32_xor unfold let add_wrap32 (x:nat32) (y:nat32) : nat32 = add_wrap x y unfold let add_wrap64 (x:nat64) (y:nat64) : nat64 = add_wrap x y unfold let sub_wrap32 (x:nat32) (y:nat32) : nat32 = sub_wrap x y unfold let sub_wrap64 (x:nat64) (y:nat64) : nat64 = sub_wrap x y unfold let iand32 (a:nat32) (b:nat32) : nat32 = iand a b unfold let ixor32 (a:nat32) (b:nat32) : nat32 = ixor a b unfold let ior32 (a:nat32) (b:nat32) : nat32 = ior a b unfold let inot32 (a:nat32) : nat32 = inot a unfold let ishl32 (a:nat32) (s:int) : nat32 = ishl a s unfold let ishr32 (a:nat32) (s:int) : nat32 = ishr a s unfold let iand64 (a:nat64) (b:nat64) : nat64 = iand a b unfold let ixor64 (a:nat64) (b:nat64) : nat64 = ixor a b
{ "checked_file": "/", "dependencies": [ "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Two_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Seq.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.Arch.Types.fsti" }
[ { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Vale.Def.Words_s.nat64 -> Vale.Def.Words_s.nat64
Prims.Tot
[ "total" ]
[]
[ "Vale.Def.Words_s.nat64", "Vale.Def.Types_s.inot", "Vale.Def.Words_s.pow2_64" ]
[]
false
false
false
true
false
let inot64 (a: nat64) : nat64 =
inot a
false
Vale.Arch.Types.fsti
Vale.Arch.Types.ixor32
val ixor32 (a b: nat32) : nat32
val ixor32 (a b: nat32) : nat32
let ixor32 (a:nat32) (b:nat32) : nat32 = ixor a b
{ "file_name": "vale/code/arch/Vale.Arch.Types.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 56, "end_line": 24, "start_col": 7, "start_line": 24 }
module Vale.Arch.Types open FStar.Mul open Vale.Def.Opaque_s open Vale.Def.Types_s open Vale.Lib.Seqs_s open Vale.Lib.Seqs open Vale.Def.Words_s open Vale.Def.Words.Four_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Seq open FStar.Seq open Vale.Def.Words.Two_s unfold let ( *^ ) = nat32_xor unfold let ( *^^ ) = quad32_xor unfold let add_wrap32 (x:nat32) (y:nat32) : nat32 = add_wrap x y unfold let add_wrap64 (x:nat64) (y:nat64) : nat64 = add_wrap x y unfold let sub_wrap32 (x:nat32) (y:nat32) : nat32 = sub_wrap x y unfold let sub_wrap64 (x:nat64) (y:nat64) : nat64 = sub_wrap x y
{ "checked_file": "/", "dependencies": [ "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Two_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Seq.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.Arch.Types.fsti" }
[ { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Vale.Def.Words_s.nat32 -> b: Vale.Def.Words_s.nat32 -> Vale.Def.Words_s.nat32
Prims.Tot
[ "total" ]
[]
[ "Vale.Def.Words_s.nat32", "Vale.Def.Types_s.ixor", "Vale.Def.Words_s.pow2_32" ]
[]
false
false
false
true
false
let ixor32 (a b: nat32) : nat32 =
ixor a b
false
Vale.Arch.Types.fsti
Vale.Arch.Types.ior128
val ior128 (a b: nat128) : nat128
val ior128 (a b: nat128) : nat128
let ior128 (a:nat128) (b:nat128) : nat128 = ior a b
{ "file_name": "vale/code/arch/Vale.Arch.Types.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 58, "end_line": 39, "start_col": 7, "start_line": 39 }
module Vale.Arch.Types open FStar.Mul open Vale.Def.Opaque_s open Vale.Def.Types_s open Vale.Lib.Seqs_s open Vale.Lib.Seqs open Vale.Def.Words_s open Vale.Def.Words.Four_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Seq open FStar.Seq open Vale.Def.Words.Two_s unfold let ( *^ ) = nat32_xor unfold let ( *^^ ) = quad32_xor unfold let add_wrap32 (x:nat32) (y:nat32) : nat32 = add_wrap x y unfold let add_wrap64 (x:nat64) (y:nat64) : nat64 = add_wrap x y unfold let sub_wrap32 (x:nat32) (y:nat32) : nat32 = sub_wrap x y unfold let sub_wrap64 (x:nat64) (y:nat64) : nat64 = sub_wrap x y unfold let iand32 (a:nat32) (b:nat32) : nat32 = iand a b unfold let ixor32 (a:nat32) (b:nat32) : nat32 = ixor a b unfold let ior32 (a:nat32) (b:nat32) : nat32 = ior a b unfold let inot32 (a:nat32) : nat32 = inot a unfold let ishl32 (a:nat32) (s:int) : nat32 = ishl a s unfold let ishr32 (a:nat32) (s:int) : nat32 = ishr a s unfold let iand64 (a:nat64) (b:nat64) : nat64 = iand a b unfold let ixor64 (a:nat64) (b:nat64) : nat64 = ixor a b unfold let ior64 (a:nat64) (b:nat64) : nat64 = ior a b unfold let inot64 (a:nat64) : nat64 = inot a unfold let ishl64 (a:nat64) (s:int) : nat64 = ishl a s unfold let ishr64 (a:nat64) (s:int) : nat64 = ishr a s unfold let iand128 (a:nat128) (b:nat128) : nat128 = iand a b
{ "checked_file": "/", "dependencies": [ "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Two_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Seq.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.Arch.Types.fsti" }
[ { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Vale.Def.Words_s.nat128 -> b: Vale.Def.Words_s.nat128 -> Vale.Def.Words_s.nat128
Prims.Tot
[ "total" ]
[]
[ "Vale.Def.Words_s.nat128", "Vale.Def.Types_s.ior", "Vale.Def.Words_s.pow2_128" ]
[]
false
false
false
true
false
let ior128 (a b: nat128) : nat128 =
ior a b
false
Vale.Arch.Types.fsti
Vale.Arch.Types.iand128
val iand128 (a b: nat128) : nat128
val iand128 (a b: nat128) : nat128
let iand128 (a:nat128) (b:nat128) : nat128 = iand a b
{ "file_name": "vale/code/arch/Vale.Arch.Types.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 60, "end_line": 37, "start_col": 7, "start_line": 37 }
module Vale.Arch.Types open FStar.Mul open Vale.Def.Opaque_s open Vale.Def.Types_s open Vale.Lib.Seqs_s open Vale.Lib.Seqs open Vale.Def.Words_s open Vale.Def.Words.Four_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Seq open FStar.Seq open Vale.Def.Words.Two_s unfold let ( *^ ) = nat32_xor unfold let ( *^^ ) = quad32_xor unfold let add_wrap32 (x:nat32) (y:nat32) : nat32 = add_wrap x y unfold let add_wrap64 (x:nat64) (y:nat64) : nat64 = add_wrap x y unfold let sub_wrap32 (x:nat32) (y:nat32) : nat32 = sub_wrap x y unfold let sub_wrap64 (x:nat64) (y:nat64) : nat64 = sub_wrap x y unfold let iand32 (a:nat32) (b:nat32) : nat32 = iand a b unfold let ixor32 (a:nat32) (b:nat32) : nat32 = ixor a b unfold let ior32 (a:nat32) (b:nat32) : nat32 = ior a b unfold let inot32 (a:nat32) : nat32 = inot a unfold let ishl32 (a:nat32) (s:int) : nat32 = ishl a s unfold let ishr32 (a:nat32) (s:int) : nat32 = ishr a s unfold let iand64 (a:nat64) (b:nat64) : nat64 = iand a b unfold let ixor64 (a:nat64) (b:nat64) : nat64 = ixor a b unfold let ior64 (a:nat64) (b:nat64) : nat64 = ior a b unfold let inot64 (a:nat64) : nat64 = inot a unfold let ishl64 (a:nat64) (s:int) : nat64 = ishl a s unfold let ishr64 (a:nat64) (s:int) : nat64 = ishr a s
{ "checked_file": "/", "dependencies": [ "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Two_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Seq.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.Arch.Types.fsti" }
[ { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Vale.Def.Words_s.nat128 -> b: Vale.Def.Words_s.nat128 -> Vale.Def.Words_s.nat128
Prims.Tot
[ "total" ]
[]
[ "Vale.Def.Words_s.nat128", "Vale.Def.Types_s.iand", "Vale.Def.Words_s.pow2_128" ]
[]
false
false
false
true
false
let iand128 (a b: nat128) : nat128 =
iand a b
false
Vale.Arch.Types.fsti
Vale.Arch.Types.ishr32
val ishr32 (a: nat32) (s: int) : nat32
val ishr32 (a: nat32) (s: int) : nat32
let ishr32 (a:nat32) (s:int) : nat32 = ishr a s
{ "file_name": "vale/code/arch/Vale.Arch.Types.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 54, "end_line": 28, "start_col": 7, "start_line": 28 }
module Vale.Arch.Types open FStar.Mul open Vale.Def.Opaque_s open Vale.Def.Types_s open Vale.Lib.Seqs_s open Vale.Lib.Seqs open Vale.Def.Words_s open Vale.Def.Words.Four_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Seq open FStar.Seq open Vale.Def.Words.Two_s unfold let ( *^ ) = nat32_xor unfold let ( *^^ ) = quad32_xor unfold let add_wrap32 (x:nat32) (y:nat32) : nat32 = add_wrap x y unfold let add_wrap64 (x:nat64) (y:nat64) : nat64 = add_wrap x y unfold let sub_wrap32 (x:nat32) (y:nat32) : nat32 = sub_wrap x y unfold let sub_wrap64 (x:nat64) (y:nat64) : nat64 = sub_wrap x y unfold let iand32 (a:nat32) (b:nat32) : nat32 = iand a b unfold let ixor32 (a:nat32) (b:nat32) : nat32 = ixor a b unfold let ior32 (a:nat32) (b:nat32) : nat32 = ior a b unfold let inot32 (a:nat32) : nat32 = inot a
{ "checked_file": "/", "dependencies": [ "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Two_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Seq.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.Arch.Types.fsti" }
[ { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Vale.Def.Words_s.nat32 -> s: Prims.int -> Vale.Def.Words_s.nat32
Prims.Tot
[ "total" ]
[]
[ "Vale.Def.Words_s.nat32", "Prims.int", "Vale.Def.Types_s.ishr", "Vale.Def.Words_s.pow2_32" ]
[]
false
false
false
true
false
let ishr32 (a: nat32) (s: int) : nat32 =
ishr a s
false
Vale.Arch.Types.fsti
Vale.Arch.Types.ishl64
val ishl64 (a: nat64) (s: int) : nat64
val ishl64 (a: nat64) (s: int) : nat64
let ishl64 (a:nat64) (s:int) : nat64 = ishl a s
{ "file_name": "vale/code/arch/Vale.Arch.Types.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 54, "end_line": 34, "start_col": 7, "start_line": 34 }
module Vale.Arch.Types open FStar.Mul open Vale.Def.Opaque_s open Vale.Def.Types_s open Vale.Lib.Seqs_s open Vale.Lib.Seqs open Vale.Def.Words_s open Vale.Def.Words.Four_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Seq open FStar.Seq open Vale.Def.Words.Two_s unfold let ( *^ ) = nat32_xor unfold let ( *^^ ) = quad32_xor unfold let add_wrap32 (x:nat32) (y:nat32) : nat32 = add_wrap x y unfold let add_wrap64 (x:nat64) (y:nat64) : nat64 = add_wrap x y unfold let sub_wrap32 (x:nat32) (y:nat32) : nat32 = sub_wrap x y unfold let sub_wrap64 (x:nat64) (y:nat64) : nat64 = sub_wrap x y unfold let iand32 (a:nat32) (b:nat32) : nat32 = iand a b unfold let ixor32 (a:nat32) (b:nat32) : nat32 = ixor a b unfold let ior32 (a:nat32) (b:nat32) : nat32 = ior a b unfold let inot32 (a:nat32) : nat32 = inot a unfold let ishl32 (a:nat32) (s:int) : nat32 = ishl a s unfold let ishr32 (a:nat32) (s:int) : nat32 = ishr a s unfold let iand64 (a:nat64) (b:nat64) : nat64 = iand a b unfold let ixor64 (a:nat64) (b:nat64) : nat64 = ixor a b unfold let ior64 (a:nat64) (b:nat64) : nat64 = ior a b
{ "checked_file": "/", "dependencies": [ "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Two_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Seq.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.Arch.Types.fsti" }
[ { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Vale.Def.Words_s.nat64 -> s: Prims.int -> Vale.Def.Words_s.nat64
Prims.Tot
[ "total" ]
[]
[ "Vale.Def.Words_s.nat64", "Prims.int", "Vale.Def.Types_s.ishl", "Vale.Def.Words_s.pow2_64" ]
[]
false
false
false
true
false
let ishl64 (a: nat64) (s: int) : nat64 =
ishl a s
false
Vale.Arch.Types.fsti
Vale.Arch.Types.ishr64
val ishr64 (a: nat64) (s: int) : nat64
val ishr64 (a: nat64) (s: int) : nat64
let ishr64 (a:nat64) (s:int) : nat64 = ishr a s
{ "file_name": "vale/code/arch/Vale.Arch.Types.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 54, "end_line": 35, "start_col": 7, "start_line": 35 }
module Vale.Arch.Types open FStar.Mul open Vale.Def.Opaque_s open Vale.Def.Types_s open Vale.Lib.Seqs_s open Vale.Lib.Seqs open Vale.Def.Words_s open Vale.Def.Words.Four_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Seq open FStar.Seq open Vale.Def.Words.Two_s unfold let ( *^ ) = nat32_xor unfold let ( *^^ ) = quad32_xor unfold let add_wrap32 (x:nat32) (y:nat32) : nat32 = add_wrap x y unfold let add_wrap64 (x:nat64) (y:nat64) : nat64 = add_wrap x y unfold let sub_wrap32 (x:nat32) (y:nat32) : nat32 = sub_wrap x y unfold let sub_wrap64 (x:nat64) (y:nat64) : nat64 = sub_wrap x y unfold let iand32 (a:nat32) (b:nat32) : nat32 = iand a b unfold let ixor32 (a:nat32) (b:nat32) : nat32 = ixor a b unfold let ior32 (a:nat32) (b:nat32) : nat32 = ior a b unfold let inot32 (a:nat32) : nat32 = inot a unfold let ishl32 (a:nat32) (s:int) : nat32 = ishl a s unfold let ishr32 (a:nat32) (s:int) : nat32 = ishr a s unfold let iand64 (a:nat64) (b:nat64) : nat64 = iand a b unfold let ixor64 (a:nat64) (b:nat64) : nat64 = ixor a b unfold let ior64 (a:nat64) (b:nat64) : nat64 = ior a b unfold let inot64 (a:nat64) : nat64 = inot a
{ "checked_file": "/", "dependencies": [ "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Two_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Seq.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.Arch.Types.fsti" }
[ { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Vale.Def.Words_s.nat64 -> s: Prims.int -> Vale.Def.Words_s.nat64
Prims.Tot
[ "total" ]
[]
[ "Vale.Def.Words_s.nat64", "Prims.int", "Vale.Def.Types_s.ishr", "Vale.Def.Words_s.pow2_64" ]
[]
false
false
false
true
false
let ishr64 (a: nat64) (s: int) : nat64 =
ishr a s
false
Vale.Arch.Types.fsti
Vale.Arch.Types.add_wrap_quad32
val add_wrap_quad32 (q0 q1: quad32) : quad32
val add_wrap_quad32 (q0 q1: quad32) : quad32
let add_wrap_quad32 (q0 q1:quad32) : quad32 = let open Vale.Def.Words_s in Mkfour (add_wrap q0.lo0 q1.lo0) (add_wrap q0.lo1 q1.lo1) (add_wrap q0.hi2 q1.hi2) (add_wrap q0.hi3 q1.hi3)
{ "file_name": "vale/code/arch/Vale.Arch.Types.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 33, "end_line": 59, "start_col": 0, "start_line": 54 }
module Vale.Arch.Types open FStar.Mul open Vale.Def.Opaque_s open Vale.Def.Types_s open Vale.Lib.Seqs_s open Vale.Lib.Seqs open Vale.Def.Words_s open Vale.Def.Words.Four_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Seq open FStar.Seq open Vale.Def.Words.Two_s unfold let ( *^ ) = nat32_xor unfold let ( *^^ ) = quad32_xor unfold let add_wrap32 (x:nat32) (y:nat32) : nat32 = add_wrap x y unfold let add_wrap64 (x:nat64) (y:nat64) : nat64 = add_wrap x y unfold let sub_wrap32 (x:nat32) (y:nat32) : nat32 = sub_wrap x y unfold let sub_wrap64 (x:nat64) (y:nat64) : nat64 = sub_wrap x y unfold let iand32 (a:nat32) (b:nat32) : nat32 = iand a b unfold let ixor32 (a:nat32) (b:nat32) : nat32 = ixor a b unfold let ior32 (a:nat32) (b:nat32) : nat32 = ior a b unfold let inot32 (a:nat32) : nat32 = inot a unfold let ishl32 (a:nat32) (s:int) : nat32 = ishl a s unfold let ishr32 (a:nat32) (s:int) : nat32 = ishr a s unfold let iand64 (a:nat64) (b:nat64) : nat64 = iand a b unfold let ixor64 (a:nat64) (b:nat64) : nat64 = ixor a b unfold let ior64 (a:nat64) (b:nat64) : nat64 = ior a b unfold let inot64 (a:nat64) : nat64 = inot a unfold let ishl64 (a:nat64) (s:int) : nat64 = ishl a s unfold let ishr64 (a:nat64) (s:int) : nat64 = ishr a s unfold let iand128 (a:nat128) (b:nat128) : nat128 = iand a b unfold let ixor128 (a:nat128) (b:nat128) : nat128 = ixor a b unfold let ior128 (a:nat128) (b:nat128) : nat128 = ior a b unfold let inot128 (a:nat128) : nat128 = inot a unfold let ishl128 (a:nat128) (s:int) : nat128 = ishl a s unfold let ishr128 (a:nat128) (s:int) : nat128 = ishr a s unfold let two_to_nat32 (x:two nat32) : nat64 = two_to_nat 32 x val lemma_nat_to_two32 (_:unit) : Lemma (forall (x:nat64).{:pattern (nat_to_two 32 x)} nat_to_two 32 x == Mktwo (x % 0x100000000) (x / 0x100000000)) let quad32_shl32 (q:quad32) : quad32 = let Mkfour v0 v1 v2 v3 = q in Mkfour 0 v0 v1 v2
{ "checked_file": "/", "dependencies": [ "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Two_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Seq.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.Arch.Types.fsti" }
[ { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
q0: Vale.Def.Types_s.quad32 -> q1: Vale.Def.Types_s.quad32 -> Vale.Def.Types_s.quad32
Prims.Tot
[ "total" ]
[]
[ "Vale.Def.Types_s.quad32", "Vale.Def.Words_s.Mkfour", "Vale.Def.Types_s.nat32", "Vale.Def.Types_s.add_wrap", "Vale.Def.Words_s.pow2_32", "Vale.Def.Words_s.__proj__Mkfour__item__lo0", "Vale.Def.Words_s.__proj__Mkfour__item__lo1", "Vale.Def.Words_s.__proj__Mkfour__item__hi2", "Vale.Def.Words_s.__proj__Mkfour__item__hi3" ]
[]
false
false
false
true
false
let add_wrap_quad32 (q0 q1: quad32) : quad32 =
let open Vale.Def.Words_s in Mkfour (add_wrap q0.lo0 q1.lo0) (add_wrap q0.lo1 q1.lo1) (add_wrap q0.hi2 q1.hi2) (add_wrap q0.hi3 q1.hi3)
false
Steel.FractionalAnchoredPreorder.fst
Steel.FractionalAnchoredPreorder.avalue_update_anchored_value
val avalue_update_anchored_value (#v: Type) (#p: preorder v) (#s: anchor_rel p) (m: avalue s) (value: v{(curval (avalue_val m)) `p` value /\ value `compat_with_any_anchor_of` m}) : m': avalue s {curval (avalue_val m') == value /\ (avalue_val m') `extends` (avalue_val m)}
val avalue_update_anchored_value (#v: Type) (#p: preorder v) (#s: anchor_rel p) (m: avalue s) (value: v{(curval (avalue_val m)) `p` value /\ value `compat_with_any_anchor_of` m}) : m': avalue s {curval (avalue_val m') == value /\ (avalue_val m') `extends` (avalue_val m)}
let avalue_update_anchored_value (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) (value:v { curval (avalue_val m) `p` value /\ value `compat_with_any_anchor_of` m }) : m':avalue s { curval (avalue_val m') == value /\ avalue_val m' `extends` avalue_val m } = let v = avalue_val m in avalue_anchored_update m (extend_history v value)
{ "file_name": "lib/steel/Steel.FractionalAnchoredPreorder.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 53, "end_line": 548, "start_col": 0, "start_line": 537 }
(* Copyright 2021 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. Author: N. Swamy *) module Steel.FractionalAnchoredPreorder (** This module provides a partial commutative monoid (PCM) for use in the ghost state of a concurrent Steel program. Its goal is to facilitate a form of information-sharing between multiple threads including the following features: Fractions, Preorders, Snapshots, and Anchors --- Anchors are the most unusual. 1. Fractions: Ownership of the state is controlled by a fractional permission, so multiple threads may share read-only privileges on the state, but only one can have write permission. 2. Preorders: The ghost state is governed by a preorder p and all updates to the state must respect the preorder (a reflexive, transitive relation on the state) 3. Snapshots: Since the state always evolves by a preorder, it is possible to take a snapshot of the state. A snapshot does not confer any particular ownership on the state, except knowledge of a snapshot ensures that the current state is related to the snapshot by the preorder. 4. Anchors are a kind of refinement of the preorder. If a thread owns an anchored value [v], then no other thread, even a thread owning a full fractional permission, can advance the state "too far" from the anchor. In particular, the PCM is parameterized by a binary relation on values, [anchors:anchor_relation]. If a thread owns the anchor [v], then the current value `cur` of the state must be in relation [v `anchors` cur]. This can be used to ensure that the knowledge of one thread is never becomes too stale. For example, this allows one to model a shared monotonically increasing counter, where if one thread anchors knowledge of the counter at the value 5, no other thread can increase the value of the counter beyond, say, 10, (when the anchor relation is y - x <= 5), until the anchoring thread releases the anchor. Further, at any point, a thread can take a snapshot of the counter and rely on the fact that the value of the counter in the future will be >= the snapshot. *) open FStar.PCM open FStar.Preorder open Steel.Preorder open Steel.FractionalPermission #push-options "--fuel 0 --ifuel 2" /// A permission: is a pair of /// /// * an optional fractional permission; with `Some p` indicating /// some ownership, while `None` is an additional "0" permission /// value, to encode snapshots. /// /// * and an optional anchor, where `Some a` indicates the current /// value can't be too far from `a`. let permission (v:Type) = option perm & option v /// Non-zero permission is either a read or write permission let has_nonzero #v (p:permission v) = Some? (fst p) /// Has an anchor set let has_anchor #v (p:permission v) = Some? (snd p) /// Either an anchor or non-zero let has_some_ownership #v (p:permission v) = has_nonzero p || has_anchor p /// The anchoring value let anchor_of #v (p:permission v { has_anchor p }) : v = Some?.v (snd p) /// The anchoring relation: /// -- A binary relation on values /// -- refining the preorder /// -- and if x `anchors` z then it also anchors any `y` between `x` and `z` /// /// Explaining the third clause a bit: /// Think intuitively of anchoring relations as a kind of distance measure /// /// if `z` is close enough to `x` then if `z` is further than `y` /// (since it is ahead of `y` in the preorder) then `y` is also /// close enough to `x` let anchor_rel (#v:Type) (p:preorder v) = anchors:(v -> v -> prop) { (forall v0 v1. anchors v0 v1 ==> p v0 v1) /\ (forall x z. x `anchors` z ==> (forall y. p x y /\ p y z ==> x `anchors` y)) // } /// An implementation remark: We use Steel.Preorder here to /// generically transform any preorder into a PCM. That works by /// taking the value of the PCM to be a history of values related by /// the preorder. So, throughout, we'll be using the the [vhist p] /// from Steel.Preorder, the type of a non-empty history compatible /// with [p]. The details of the histories don't matter much for our /// purposes---we only care about the most recent value, for which /// we'll use [curval v]. /// If the anchor is set, then the current value is anchored by it let anchored (#v:Type) (#p:preorder v) (anchors:anchor_rel p) (pv:(permission v & vhist p)) = has_anchor (fst pv) ==> anchor_of (fst pv) `anchors` curval (snd pv) /// A value in our fractional anchored PCM is a pair of a permission /// and a p-compatible history, refined to ensure that if the anchor /// is set, then the current value is anchored by it. let avalue (#v:Type) (#p:preorder v) (anchors:anchor_rel p) = pv:(permission v & vhist p) { anchored anchors pv } /// initial_value: A utility to construct a value in the PCM #push-options "--fuel 1" let initial_value (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (value:v { anchors value value }) : avalue anchors = (Some full_perm, Some value), [value] #pop-options /// We add a unit element to [avalue], as needed for a PCM [@@erasable] noeq type knowledge (#v:Type) (#p:preorder v) (anchors:anchor_rel p) = | Owns : avalue anchors -> knowledge anchors | Nothing : knowledge anchors let b2p (b:bool) : prop = b == true /// Fractional permissions are composable when their sum <= 1.0 let perm_opt_composable (p0 p1:option perm) : prop = match p0, p1 with | None, None -> True | Some p, None | None, Some p -> b2p (p `lesser_equal_perm` full_perm) | Some p0, Some p1 -> b2p (sum_perm p0 p1 `lesser_equal_perm` full_perm) /// Composing them sums the permissions let compose_perm_opt (p0 p1:option perm) = match p0, p1 with | None, p | p, None -> p | Some p0, Some p1 -> Some (sum_perm p0 p1) /// Anchored permissions are composable when at most one of them has the anchor set let permission_composable #v (p0 p1 : permission v) : prop = let q0, s0 = p0 in let q1, s1 = p1 in perm_opt_composable q0 q1 /\ // some of fracs can't exceed 1 not (Some? s0 && Some? s1) // at most one can have an anchor /// Compose permissions component wise, keeping the anchor if set let compose_permissions (#v:_) (p0:permission v) (p1:permission v{permission_composable p0 p1}) : permission v = compose_perm_opt (fst p0) (fst p1), (match snd p0, snd p1 with | None, a | a, None -> a) /// This is the central definition of the PCM --- defining when two /// values are composable, or equivalently, when one thread's /// knowledge of [av0] is compatible with another thread's knowledge /// of [av1] /// /// This definition shows the interplay between fractions and anchors. /// It wasn't obvious to me how to factor this further, e.g., adding /// anchors to preorders and then separately adding fractions to it. let avalue_composable (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (av0 av1: avalue anchors) : prop = let (p0, v0) = av0 in let (p1, v1) = av1 in permission_composable p0 p1 /\ (if not (has_some_ownership p0) && not (has_some_ownership p1) then p_composable _ v0 v1 //neither has ownership, one history is older than the other else if not (has_some_ownership p0) && has_some_ownership p1 then ( if has_nonzero p1 then v1 `extends` v0 //the one with ownership is more recent else ( //this part is the most subtle assert (has_anchor p1); p_composable _ v0 v1 /\ (v0 `extends` v1 ==> //if v0 is a more recent snapshot than v1 //then v0 must still be anchored by v1's anchor anchor_of p1 `anchors` curval v0) ) ) else if has_some_ownership p0 && not (has_some_ownership p1) then ( //symmetric if has_nonzero p0 then v0 `extends` v1 else ( assert (has_anchor p0); p_composable _ v0 v1 /\ (v1 `extends` v0 ==> anchor_of p0 `anchors` curval v1) ) ) else ( assert (has_some_ownership p0 && has_some_ownership p1); if has_nonzero p0 && has_nonzero p1 then v0 == v1 //if both have non-zero perm, then they must both only have read permission and must agree on the value else if has_nonzero p0 && has_anchor p1 then ( assert (not (has_nonzero p1)); //The key part of the anchor semantics: v0 `extends` v1 /\ //v0 has advanceable ownership, so extends anchor_of p1 `anchors` curval v0 //but not beyond what is allowed by s ) else if has_anchor p0 && has_nonzero p1 //symmetric then ( assert (not (has_nonzero p0)); v1 `extends` v0 /\ anchor_of p0 `anchors` curval v1 //v1 extends, but not beyond what is allowed by s ) else (assert false; False) ) ) //exhaustive /// Lifting avalue comosability to knowledge, including the unit let composable #v (#p:preorder v) (#a:anchor_rel p) : symrel (knowledge a) = fun (k0 k1:knowledge a) -> match k0, k1 with | Nothing, _ | _, Nothing -> True | Owns m, Owns m' -> avalue_composable m m' /// Compose avalues by composing permissions and composing the values /// using the underlying preorder PCM let compose_avalue (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (m0:avalue anchors) (m1:avalue anchors { avalue_composable m0 m1 } ) : avalue anchors = let p0, v0 = m0 in let p1, v1 = m1 in let p12 = compose_permissions p0 p1 in let v12 = p_op _ v0 v1 in p12, v12 //////////////////////////////////////////////////////////////////////////////// (** avalue composition is associative and commutative **) let compose_avalue_comm (#v:Type) (#p:preorder v) (#anc:anchor_rel p) (m0: avalue anc) (m1: avalue anc{ avalue_composable m0 m1 }) : Lemma (compose_avalue m0 m1 == compose_avalue m1 m0) = () let avalue_composable_assoc_l (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (m0: avalue anchors) (m1: avalue anchors) (m2: avalue anchors { avalue_composable m1 m2 /\ avalue_composable m0 (compose_avalue m1 m2) }) : Lemma (avalue_composable m0 m1 /\ avalue_composable (compose_avalue m0 m1) m2) = () let compose_avalue_assoc_l (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m0: avalue s) (m1: avalue s) (m2: avalue s { avalue_composable m1 m2 /\ avalue_composable m0 (compose_avalue m1 m2) }) : Lemma (avalue_composable m0 m1 /\ avalue_composable (compose_avalue m0 m1) m2 /\ compose_avalue m0 (compose_avalue m1 m2) == compose_avalue (compose_avalue m0 m1) m2) = avalue_composable_assoc_l m0 m1 m2 let avalue_composable_assoc_r (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (m0: avalue anchors) (m1: avalue anchors) (m2: avalue anchors { avalue_composable m0 m1 /\ avalue_composable (compose_avalue m0 m1) m2 }) : Lemma (avalue_composable m1 m2 /\ avalue_composable m0 (compose_avalue m1 m2)) = () let compose_avalue_assoc_r (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m0: avalue s) (m1: avalue s) (m2: avalue s{ avalue_composable m0 m1 /\ avalue_composable (compose_avalue m0 m1) m2 }) : Lemma (avalue_composable m1 m2 /\ avalue_composable m0 (compose_avalue m1 m2) /\ compose_avalue m0 (compose_avalue m1 m2) == compose_avalue (compose_avalue m0 m1) m2) = avalue_composable_assoc_r m0 m1 m2 //////////////////////////////////////////////////////////////////////////////// /// lifting avalue composition to knowledge, including unit let compose (#v:Type) (#p:preorder v) (#s:anchor_rel p) (k0:knowledge s) (k1:knowledge s{ composable k0 k1 }) : knowledge s = match k0, k1 with | Nothing, k | k, Nothing -> k | Owns m, Owns m' -> Owns (compose_avalue m m') let composable_assoc_r #v (#p:preorder v) (#s:anchor_rel p) (k0 k1 k2: knowledge s) : Lemma (requires composable k0 k1 /\ composable (compose k0 k1) k2) (ensures composable k1 k2 /\ composable k0 (compose k1 k2) /\ compose k0 (compose k1 k2) == compose (compose k0 k1) k2 ) = match k0, k1, k2 with | Nothing, _, _ | _, Nothing, _ | _, _, Nothing -> () | Owns m0, Owns m1, Owns m2 -> compose_avalue_assoc_r m0 m1 m2 let composable_assoc_l #v (#p:preorder v) (#s:anchor_rel p) (k0 k1 k2: knowledge s) : Lemma (requires composable k1 k2 /\ composable k0 (compose k1 k2)) (ensures composable k0 k1 /\ composable (compose k0 k1) k2 /\ compose k0 (compose k1 k2) == compose (compose k0 k1) k2) = match k0, k1, k2 with | Nothing, _, _ | _, Nothing, _ | _, _, Nothing -> () | Owns m0, Owns m1, Owns m2 -> compose_avalue_assoc_l m0 m1 m2 /// Now, we can define our PCM /// The core of the PCM let p0 #v #p #s : pcm' (knowledge #v #p s) = { composable; op=compose; one=Nothing } let avalue_perm (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) = fst m /// A avalue represents full ownership when the fraction is full AND /// the anchor is set. This means that no knowledge held by any other /// thread can constrain this value meaningfully. let avalue_owns (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) : prop = fst (avalue_perm m) == Some full_perm /\ Some? (snd (avalue_perm m)) let full_knowledge #v #p #s (kn:knowledge #v #p s) : prop = match kn with | Nothing -> False | Owns km -> avalue_owns km /// The PCM itself, together with proofs of its properties let pcm #v #p #s : pcm (knowledge #v #p s) = { p = p0; comm = (fun k0 k1 -> match k0, k1 with | Nothing, _ | _, Nothing -> () | Owns m0, Owns m1 -> compose_avalue_comm m0 m1); assoc = (fun k0 k1 k2 -> composable_assoc_l k0 k1 k2); assoc_r = (fun k0 k1 k2 -> composable_assoc_r k0 k1 k2); is_unit = (fun _ -> ()); refine = full_knowledge; } /// Some utilities: The value of an avalue let avalue_val (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue #v #p s) = snd m /// Updating the value, in a full-ownership situation, also involves /// updating the anchor let avalue_update (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) (value:vhist p { s (curval value) (curval value) }) : avalue s = let p, _ = avalue_perm m in let p' = p, Some (curval value) in (p', value) /// Our core frame-preserving update: /// /// If you fully own a value, you can update it so long as you /// respect the preorder, and prove that the new value is related /// to itself by the anchor (since we'll be setting the anchor to /// the new value) /// /// This is a building block: we'll define a derived version that /// on values rather than histories #push-options "--z3rlimit_factor 2" let update_hist (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) (v1:vhist p { avalue_owns m /\ v1 `extends` avalue_val m /\ s (curval v1) (curval v1) }) : frame_preserving_upd pcm (Owns m) (Owns (avalue_update m v1)) = fun full_v -> let Owns full_m = full_v in let m_res = avalue_update full_m v1 in Owns m_res #pop-options /// Updating with value, rather than a history let avalue_update_value (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) (value:v { curval (avalue_val m) `p` value /\ s value value }) : m':avalue s { curval (avalue_val m') == value /\ avalue_val m' `extends` avalue_val m } = let v = avalue_val m in avalue_update m (extend_history v value) /// A derived frame-preserving update for which one presents only a value let update_value (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) (v1:v { avalue_owns m /\ //if you have full ownership of key curval (avalue_val m) `p` v1 /\ //you can update it wrt the preorder only s v1 v1 //and it is related to itself by the anchor }) : frame_preserving_upd pcm (Owns m) (Owns (avalue_update_value m v1)) = coerce_eq () (update_hist m (extend_history (avalue_val m) v1)) //F* goes nuts and starts swallowing gobs of memory without the coerce_eq: TODO, debug /// Now for anchored updates /// Ownership of the whole fraction, but not the anchor let avalue_owns_anchored (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) = fst (avalue_perm m) == Some full_perm /\ None? (snd (avalue_perm m)) /// [v1] is compatible with (i.e., not too far from) any anchor of [v0] let compat_with_any_anchor_of (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (v1:v) (v0:avalue anchors) = forall (anchor:v). anchor `anchors` curval (avalue_val v0) ==> anchor `anchors` v1 /// An anchored update: Update the value, but leave the permission /// unchanged Only possible if the new value is compatible with any /// anchor of the old value let avalue_anchored_update (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) (value:vhist p { curval value `compat_with_any_anchor_of` m }) : avalue s = avalue_perm m, value /// A frame-preserving update for anchored values. /// Notice the additional precondition, refining the preorder let update_anchored_hist (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) (v1:vhist p { avalue_owns_anchored m /\ v1 `extends` avalue_val m /\ curval v1 `compat_with_any_anchor_of` m }) : frame_preserving_upd pcm (Owns m) (Owns (avalue_anchored_update m v1)) = fun full_v -> let Owns full_m = full_v in let m_res = avalue_anchored_update full_m v1 in Owns m_res
{ "checked_file": "/", "dependencies": [ "Steel.Preorder.fst.checked", "Steel.FractionalPermission.fst.checked", "prims.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked" ], "interface_file": false, "source_file": "Steel.FractionalAnchoredPreorder.fst" }
[ { "abbrev": false, "full_module": "Steel.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Steel.Preorder", "short_module": null }, { "abbrev": false, "full_module": "FStar.Preorder", "short_module": null }, { "abbrev": false, "full_module": "FStar.PCM", "short_module": null }, { "abbrev": false, "full_module": "Steel", "short_module": null }, { "abbrev": false, "full_module": "Steel", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
m: Steel.FractionalAnchoredPreorder.avalue s -> value: v { p (Steel.Preorder.curval (Steel.FractionalAnchoredPreorder.avalue_val m)) value /\ Steel.FractionalAnchoredPreorder.compat_with_any_anchor_of value m } -> m': Steel.FractionalAnchoredPreorder.avalue s { Steel.Preorder.curval (Steel.FractionalAnchoredPreorder.avalue_val m') == value /\ Steel.Preorder.extends (Steel.FractionalAnchoredPreorder.avalue_val m') (Steel.FractionalAnchoredPreorder.avalue_val m) }
Prims.Tot
[ "total" ]
[]
[ "FStar.Preorder.preorder", "Steel.FractionalAnchoredPreorder.anchor_rel", "Steel.FractionalAnchoredPreorder.avalue", "Prims.l_and", "Steel.Preorder.curval", "Steel.FractionalAnchoredPreorder.avalue_val", "Steel.FractionalAnchoredPreorder.compat_with_any_anchor_of", "Steel.FractionalAnchoredPreorder.avalue_anchored_update", "Steel.Preorder.extend_history", "Steel.Preorder.vhist", "Prims.eq2", "Steel.Preorder.extends" ]
[]
false
false
false
false
false
let avalue_update_anchored_value (#v: Type) (#p: preorder v) (#s: anchor_rel p) (m: avalue s) (value: v{(curval (avalue_val m)) `p` value /\ value `compat_with_any_anchor_of` m}) : m': avalue s {curval (avalue_val m') == value /\ (avalue_val m') `extends` (avalue_val m)} =
let v = avalue_val m in avalue_anchored_update m (extend_history v value)
false
Vale.Arch.Types.fsti
Vale.Arch.Types.ishl128
val ishl128 (a: nat128) (s: int) : nat128
val ishl128 (a: nat128) (s: int) : nat128
let ishl128 (a:nat128) (s:int) : nat128 = ishl a s
{ "file_name": "vale/code/arch/Vale.Arch.Types.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 57, "end_line": 41, "start_col": 7, "start_line": 41 }
module Vale.Arch.Types open FStar.Mul open Vale.Def.Opaque_s open Vale.Def.Types_s open Vale.Lib.Seqs_s open Vale.Lib.Seqs open Vale.Def.Words_s open Vale.Def.Words.Four_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Seq open FStar.Seq open Vale.Def.Words.Two_s unfold let ( *^ ) = nat32_xor unfold let ( *^^ ) = quad32_xor unfold let add_wrap32 (x:nat32) (y:nat32) : nat32 = add_wrap x y unfold let add_wrap64 (x:nat64) (y:nat64) : nat64 = add_wrap x y unfold let sub_wrap32 (x:nat32) (y:nat32) : nat32 = sub_wrap x y unfold let sub_wrap64 (x:nat64) (y:nat64) : nat64 = sub_wrap x y unfold let iand32 (a:nat32) (b:nat32) : nat32 = iand a b unfold let ixor32 (a:nat32) (b:nat32) : nat32 = ixor a b unfold let ior32 (a:nat32) (b:nat32) : nat32 = ior a b unfold let inot32 (a:nat32) : nat32 = inot a unfold let ishl32 (a:nat32) (s:int) : nat32 = ishl a s unfold let ishr32 (a:nat32) (s:int) : nat32 = ishr a s unfold let iand64 (a:nat64) (b:nat64) : nat64 = iand a b unfold let ixor64 (a:nat64) (b:nat64) : nat64 = ixor a b unfold let ior64 (a:nat64) (b:nat64) : nat64 = ior a b unfold let inot64 (a:nat64) : nat64 = inot a unfold let ishl64 (a:nat64) (s:int) : nat64 = ishl a s unfold let ishr64 (a:nat64) (s:int) : nat64 = ishr a s unfold let iand128 (a:nat128) (b:nat128) : nat128 = iand a b unfold let ixor128 (a:nat128) (b:nat128) : nat128 = ixor a b unfold let ior128 (a:nat128) (b:nat128) : nat128 = ior a b
{ "checked_file": "/", "dependencies": [ "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Two_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Seq.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.Arch.Types.fsti" }
[ { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Vale.Def.Words_s.nat128 -> s: Prims.int -> Vale.Def.Words_s.nat128
Prims.Tot
[ "total" ]
[]
[ "Vale.Def.Words_s.nat128", "Prims.int", "Vale.Def.Types_s.ishl", "Vale.Def.Words_s.pow2_128" ]
[]
false
false
false
true
false
let ishl128 (a: nat128) (s: int) : nat128 =
ishl a s
false
Vale.Arch.Types.fsti
Vale.Arch.Types.inot128
val inot128 (a: nat128) : nat128
val inot128 (a: nat128) : nat128
let inot128 (a:nat128) : nat128 = inot a
{ "file_name": "vale/code/arch/Vale.Arch.Types.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 47, "end_line": 40, "start_col": 7, "start_line": 40 }
module Vale.Arch.Types open FStar.Mul open Vale.Def.Opaque_s open Vale.Def.Types_s open Vale.Lib.Seqs_s open Vale.Lib.Seqs open Vale.Def.Words_s open Vale.Def.Words.Four_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Seq open FStar.Seq open Vale.Def.Words.Two_s unfold let ( *^ ) = nat32_xor unfold let ( *^^ ) = quad32_xor unfold let add_wrap32 (x:nat32) (y:nat32) : nat32 = add_wrap x y unfold let add_wrap64 (x:nat64) (y:nat64) : nat64 = add_wrap x y unfold let sub_wrap32 (x:nat32) (y:nat32) : nat32 = sub_wrap x y unfold let sub_wrap64 (x:nat64) (y:nat64) : nat64 = sub_wrap x y unfold let iand32 (a:nat32) (b:nat32) : nat32 = iand a b unfold let ixor32 (a:nat32) (b:nat32) : nat32 = ixor a b unfold let ior32 (a:nat32) (b:nat32) : nat32 = ior a b unfold let inot32 (a:nat32) : nat32 = inot a unfold let ishl32 (a:nat32) (s:int) : nat32 = ishl a s unfold let ishr32 (a:nat32) (s:int) : nat32 = ishr a s unfold let iand64 (a:nat64) (b:nat64) : nat64 = iand a b unfold let ixor64 (a:nat64) (b:nat64) : nat64 = ixor a b unfold let ior64 (a:nat64) (b:nat64) : nat64 = ior a b unfold let inot64 (a:nat64) : nat64 = inot a unfold let ishl64 (a:nat64) (s:int) : nat64 = ishl a s unfold let ishr64 (a:nat64) (s:int) : nat64 = ishr a s unfold let iand128 (a:nat128) (b:nat128) : nat128 = iand a b unfold let ixor128 (a:nat128) (b:nat128) : nat128 = ixor a b
{ "checked_file": "/", "dependencies": [ "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Two_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Seq.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.Arch.Types.fsti" }
[ { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Vale.Def.Words_s.nat128 -> Vale.Def.Words_s.nat128
Prims.Tot
[ "total" ]
[]
[ "Vale.Def.Words_s.nat128", "Vale.Def.Types_s.inot", "Vale.Def.Words_s.pow2_128" ]
[]
false
false
false
true
false
let inot128 (a: nat128) : nat128 =
inot a
false
Vale.Arch.Types.fsti
Vale.Arch.Types.ishr128
val ishr128 (a: nat128) (s: int) : nat128
val ishr128 (a: nat128) (s: int) : nat128
let ishr128 (a:nat128) (s:int) : nat128 = ishr a s
{ "file_name": "vale/code/arch/Vale.Arch.Types.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 57, "end_line": 42, "start_col": 7, "start_line": 42 }
module Vale.Arch.Types open FStar.Mul open Vale.Def.Opaque_s open Vale.Def.Types_s open Vale.Lib.Seqs_s open Vale.Lib.Seqs open Vale.Def.Words_s open Vale.Def.Words.Four_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Seq open FStar.Seq open Vale.Def.Words.Two_s unfold let ( *^ ) = nat32_xor unfold let ( *^^ ) = quad32_xor unfold let add_wrap32 (x:nat32) (y:nat32) : nat32 = add_wrap x y unfold let add_wrap64 (x:nat64) (y:nat64) : nat64 = add_wrap x y unfold let sub_wrap32 (x:nat32) (y:nat32) : nat32 = sub_wrap x y unfold let sub_wrap64 (x:nat64) (y:nat64) : nat64 = sub_wrap x y unfold let iand32 (a:nat32) (b:nat32) : nat32 = iand a b unfold let ixor32 (a:nat32) (b:nat32) : nat32 = ixor a b unfold let ior32 (a:nat32) (b:nat32) : nat32 = ior a b unfold let inot32 (a:nat32) : nat32 = inot a unfold let ishl32 (a:nat32) (s:int) : nat32 = ishl a s unfold let ishr32 (a:nat32) (s:int) : nat32 = ishr a s unfold let iand64 (a:nat64) (b:nat64) : nat64 = iand a b unfold let ixor64 (a:nat64) (b:nat64) : nat64 = ixor a b unfold let ior64 (a:nat64) (b:nat64) : nat64 = ior a b unfold let inot64 (a:nat64) : nat64 = inot a unfold let ishl64 (a:nat64) (s:int) : nat64 = ishl a s unfold let ishr64 (a:nat64) (s:int) : nat64 = ishr a s unfold let iand128 (a:nat128) (b:nat128) : nat128 = iand a b unfold let ixor128 (a:nat128) (b:nat128) : nat128 = ixor a b unfold let ior128 (a:nat128) (b:nat128) : nat128 = ior a b unfold let inot128 (a:nat128) : nat128 = inot a
{ "checked_file": "/", "dependencies": [ "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Two_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Seq.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.Arch.Types.fsti" }
[ { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Vale.Def.Words_s.nat128 -> s: Prims.int -> Vale.Def.Words_s.nat128
Prims.Tot
[ "total" ]
[]
[ "Vale.Def.Words_s.nat128", "Prims.int", "Vale.Def.Types_s.ishr", "Vale.Def.Words_s.pow2_128" ]
[]
false
false
false
true
false
let ishr128 (a: nat128) (s: int) : nat128 =
ishr a s
false
Steel.FractionalAnchoredPreorder.fst
Steel.FractionalAnchoredPreorder.composable_assoc_l
val composable_assoc_l (#v: _) (#p: preorder v) (#s: anchor_rel p) (k0 k1 k2: knowledge s) : Lemma (requires composable k1 k2 /\ composable k0 (compose k1 k2)) (ensures composable k0 k1 /\ composable (compose k0 k1) k2 /\ compose k0 (compose k1 k2) == compose (compose k0 k1) k2)
val composable_assoc_l (#v: _) (#p: preorder v) (#s: anchor_rel p) (k0 k1 k2: knowledge s) : Lemma (requires composable k1 k2 /\ composable k0 (compose k1 k2)) (ensures composable k0 k1 /\ composable (compose k0 k1) k2 /\ compose k0 (compose k1 k2) == compose (compose k0 k1) k2)
let composable_assoc_l #v (#p:preorder v) (#s:anchor_rel p) (k0 k1 k2: knowledge s) : Lemma (requires composable k1 k2 /\ composable k0 (compose k1 k2)) (ensures composable k0 k1 /\ composable (compose k0 k1) k2 /\ compose k0 (compose k1 k2) == compose (compose k0 k1) k2) = match k0, k1, k2 with | Nothing, _, _ | _, Nothing, _ | _, _, Nothing -> () | Owns m0, Owns m1, Owns m2 -> compose_avalue_assoc_l m0 m1 m2
{ "file_name": "lib/steel/Steel.FractionalAnchoredPreorder.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 37, "end_line": 363, "start_col": 0, "start_line": 348 }
(* Copyright 2021 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. Author: N. Swamy *) module Steel.FractionalAnchoredPreorder (** This module provides a partial commutative monoid (PCM) for use in the ghost state of a concurrent Steel program. Its goal is to facilitate a form of information-sharing between multiple threads including the following features: Fractions, Preorders, Snapshots, and Anchors --- Anchors are the most unusual. 1. Fractions: Ownership of the state is controlled by a fractional permission, so multiple threads may share read-only privileges on the state, but only one can have write permission. 2. Preorders: The ghost state is governed by a preorder p and all updates to the state must respect the preorder (a reflexive, transitive relation on the state) 3. Snapshots: Since the state always evolves by a preorder, it is possible to take a snapshot of the state. A snapshot does not confer any particular ownership on the state, except knowledge of a snapshot ensures that the current state is related to the snapshot by the preorder. 4. Anchors are a kind of refinement of the preorder. If a thread owns an anchored value [v], then no other thread, even a thread owning a full fractional permission, can advance the state "too far" from the anchor. In particular, the PCM is parameterized by a binary relation on values, [anchors:anchor_relation]. If a thread owns the anchor [v], then the current value `cur` of the state must be in relation [v `anchors` cur]. This can be used to ensure that the knowledge of one thread is never becomes too stale. For example, this allows one to model a shared monotonically increasing counter, where if one thread anchors knowledge of the counter at the value 5, no other thread can increase the value of the counter beyond, say, 10, (when the anchor relation is y - x <= 5), until the anchoring thread releases the anchor. Further, at any point, a thread can take a snapshot of the counter and rely on the fact that the value of the counter in the future will be >= the snapshot. *) open FStar.PCM open FStar.Preorder open Steel.Preorder open Steel.FractionalPermission #push-options "--fuel 0 --ifuel 2" /// A permission: is a pair of /// /// * an optional fractional permission; with `Some p` indicating /// some ownership, while `None` is an additional "0" permission /// value, to encode snapshots. /// /// * and an optional anchor, where `Some a` indicates the current /// value can't be too far from `a`. let permission (v:Type) = option perm & option v /// Non-zero permission is either a read or write permission let has_nonzero #v (p:permission v) = Some? (fst p) /// Has an anchor set let has_anchor #v (p:permission v) = Some? (snd p) /// Either an anchor or non-zero let has_some_ownership #v (p:permission v) = has_nonzero p || has_anchor p /// The anchoring value let anchor_of #v (p:permission v { has_anchor p }) : v = Some?.v (snd p) /// The anchoring relation: /// -- A binary relation on values /// -- refining the preorder /// -- and if x `anchors` z then it also anchors any `y` between `x` and `z` /// /// Explaining the third clause a bit: /// Think intuitively of anchoring relations as a kind of distance measure /// /// if `z` is close enough to `x` then if `z` is further than `y` /// (since it is ahead of `y` in the preorder) then `y` is also /// close enough to `x` let anchor_rel (#v:Type) (p:preorder v) = anchors:(v -> v -> prop) { (forall v0 v1. anchors v0 v1 ==> p v0 v1) /\ (forall x z. x `anchors` z ==> (forall y. p x y /\ p y z ==> x `anchors` y)) // } /// An implementation remark: We use Steel.Preorder here to /// generically transform any preorder into a PCM. That works by /// taking the value of the PCM to be a history of values related by /// the preorder. So, throughout, we'll be using the the [vhist p] /// from Steel.Preorder, the type of a non-empty history compatible /// with [p]. The details of the histories don't matter much for our /// purposes---we only care about the most recent value, for which /// we'll use [curval v]. /// If the anchor is set, then the current value is anchored by it let anchored (#v:Type) (#p:preorder v) (anchors:anchor_rel p) (pv:(permission v & vhist p)) = has_anchor (fst pv) ==> anchor_of (fst pv) `anchors` curval (snd pv) /// A value in our fractional anchored PCM is a pair of a permission /// and a p-compatible history, refined to ensure that if the anchor /// is set, then the current value is anchored by it. let avalue (#v:Type) (#p:preorder v) (anchors:anchor_rel p) = pv:(permission v & vhist p) { anchored anchors pv } /// initial_value: A utility to construct a value in the PCM #push-options "--fuel 1" let initial_value (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (value:v { anchors value value }) : avalue anchors = (Some full_perm, Some value), [value] #pop-options /// We add a unit element to [avalue], as needed for a PCM [@@erasable] noeq type knowledge (#v:Type) (#p:preorder v) (anchors:anchor_rel p) = | Owns : avalue anchors -> knowledge anchors | Nothing : knowledge anchors let b2p (b:bool) : prop = b == true /// Fractional permissions are composable when their sum <= 1.0 let perm_opt_composable (p0 p1:option perm) : prop = match p0, p1 with | None, None -> True | Some p, None | None, Some p -> b2p (p `lesser_equal_perm` full_perm) | Some p0, Some p1 -> b2p (sum_perm p0 p1 `lesser_equal_perm` full_perm) /// Composing them sums the permissions let compose_perm_opt (p0 p1:option perm) = match p0, p1 with | None, p | p, None -> p | Some p0, Some p1 -> Some (sum_perm p0 p1) /// Anchored permissions are composable when at most one of them has the anchor set let permission_composable #v (p0 p1 : permission v) : prop = let q0, s0 = p0 in let q1, s1 = p1 in perm_opt_composable q0 q1 /\ // some of fracs can't exceed 1 not (Some? s0 && Some? s1) // at most one can have an anchor /// Compose permissions component wise, keeping the anchor if set let compose_permissions (#v:_) (p0:permission v) (p1:permission v{permission_composable p0 p1}) : permission v = compose_perm_opt (fst p0) (fst p1), (match snd p0, snd p1 with | None, a | a, None -> a) /// This is the central definition of the PCM --- defining when two /// values are composable, or equivalently, when one thread's /// knowledge of [av0] is compatible with another thread's knowledge /// of [av1] /// /// This definition shows the interplay between fractions and anchors. /// It wasn't obvious to me how to factor this further, e.g., adding /// anchors to preorders and then separately adding fractions to it. let avalue_composable (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (av0 av1: avalue anchors) : prop = let (p0, v0) = av0 in let (p1, v1) = av1 in permission_composable p0 p1 /\ (if not (has_some_ownership p0) && not (has_some_ownership p1) then p_composable _ v0 v1 //neither has ownership, one history is older than the other else if not (has_some_ownership p0) && has_some_ownership p1 then ( if has_nonzero p1 then v1 `extends` v0 //the one with ownership is more recent else ( //this part is the most subtle assert (has_anchor p1); p_composable _ v0 v1 /\ (v0 `extends` v1 ==> //if v0 is a more recent snapshot than v1 //then v0 must still be anchored by v1's anchor anchor_of p1 `anchors` curval v0) ) ) else if has_some_ownership p0 && not (has_some_ownership p1) then ( //symmetric if has_nonzero p0 then v0 `extends` v1 else ( assert (has_anchor p0); p_composable _ v0 v1 /\ (v1 `extends` v0 ==> anchor_of p0 `anchors` curval v1) ) ) else ( assert (has_some_ownership p0 && has_some_ownership p1); if has_nonzero p0 && has_nonzero p1 then v0 == v1 //if both have non-zero perm, then they must both only have read permission and must agree on the value else if has_nonzero p0 && has_anchor p1 then ( assert (not (has_nonzero p1)); //The key part of the anchor semantics: v0 `extends` v1 /\ //v0 has advanceable ownership, so extends anchor_of p1 `anchors` curval v0 //but not beyond what is allowed by s ) else if has_anchor p0 && has_nonzero p1 //symmetric then ( assert (not (has_nonzero p0)); v1 `extends` v0 /\ anchor_of p0 `anchors` curval v1 //v1 extends, but not beyond what is allowed by s ) else (assert false; False) ) ) //exhaustive /// Lifting avalue comosability to knowledge, including the unit let composable #v (#p:preorder v) (#a:anchor_rel p) : symrel (knowledge a) = fun (k0 k1:knowledge a) -> match k0, k1 with | Nothing, _ | _, Nothing -> True | Owns m, Owns m' -> avalue_composable m m' /// Compose avalues by composing permissions and composing the values /// using the underlying preorder PCM let compose_avalue (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (m0:avalue anchors) (m1:avalue anchors { avalue_composable m0 m1 } ) : avalue anchors = let p0, v0 = m0 in let p1, v1 = m1 in let p12 = compose_permissions p0 p1 in let v12 = p_op _ v0 v1 in p12, v12 //////////////////////////////////////////////////////////////////////////////// (** avalue composition is associative and commutative **) let compose_avalue_comm (#v:Type) (#p:preorder v) (#anc:anchor_rel p) (m0: avalue anc) (m1: avalue anc{ avalue_composable m0 m1 }) : Lemma (compose_avalue m0 m1 == compose_avalue m1 m0) = () let avalue_composable_assoc_l (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (m0: avalue anchors) (m1: avalue anchors) (m2: avalue anchors { avalue_composable m1 m2 /\ avalue_composable m0 (compose_avalue m1 m2) }) : Lemma (avalue_composable m0 m1 /\ avalue_composable (compose_avalue m0 m1) m2) = () let compose_avalue_assoc_l (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m0: avalue s) (m1: avalue s) (m2: avalue s { avalue_composable m1 m2 /\ avalue_composable m0 (compose_avalue m1 m2) }) : Lemma (avalue_composable m0 m1 /\ avalue_composable (compose_avalue m0 m1) m2 /\ compose_avalue m0 (compose_avalue m1 m2) == compose_avalue (compose_avalue m0 m1) m2) = avalue_composable_assoc_l m0 m1 m2 let avalue_composable_assoc_r (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (m0: avalue anchors) (m1: avalue anchors) (m2: avalue anchors { avalue_composable m0 m1 /\ avalue_composable (compose_avalue m0 m1) m2 }) : Lemma (avalue_composable m1 m2 /\ avalue_composable m0 (compose_avalue m1 m2)) = () let compose_avalue_assoc_r (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m0: avalue s) (m1: avalue s) (m2: avalue s{ avalue_composable m0 m1 /\ avalue_composable (compose_avalue m0 m1) m2 }) : Lemma (avalue_composable m1 m2 /\ avalue_composable m0 (compose_avalue m1 m2) /\ compose_avalue m0 (compose_avalue m1 m2) == compose_avalue (compose_avalue m0 m1) m2) = avalue_composable_assoc_r m0 m1 m2 //////////////////////////////////////////////////////////////////////////////// /// lifting avalue composition to knowledge, including unit let compose (#v:Type) (#p:preorder v) (#s:anchor_rel p) (k0:knowledge s) (k1:knowledge s{ composable k0 k1 }) : knowledge s = match k0, k1 with | Nothing, k | k, Nothing -> k | Owns m, Owns m' -> Owns (compose_avalue m m') let composable_assoc_r #v (#p:preorder v) (#s:anchor_rel p) (k0 k1 k2: knowledge s) : Lemma (requires composable k0 k1 /\ composable (compose k0 k1) k2) (ensures composable k1 k2 /\ composable k0 (compose k1 k2) /\ compose k0 (compose k1 k2) == compose (compose k0 k1) k2 ) = match k0, k1, k2 with | Nothing, _, _ | _, Nothing, _ | _, _, Nothing -> () | Owns m0, Owns m1, Owns m2 -> compose_avalue_assoc_r m0 m1 m2
{ "checked_file": "/", "dependencies": [ "Steel.Preorder.fst.checked", "Steel.FractionalPermission.fst.checked", "prims.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked" ], "interface_file": false, "source_file": "Steel.FractionalAnchoredPreorder.fst" }
[ { "abbrev": false, "full_module": "Steel.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Steel.Preorder", "short_module": null }, { "abbrev": false, "full_module": "FStar.Preorder", "short_module": null }, { "abbrev": false, "full_module": "FStar.PCM", "short_module": null }, { "abbrev": false, "full_module": "Steel", "short_module": null }, { "abbrev": false, "full_module": "Steel", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
k0: Steel.FractionalAnchoredPreorder.knowledge s -> k1: Steel.FractionalAnchoredPreorder.knowledge s -> k2: Steel.FractionalAnchoredPreorder.knowledge s -> FStar.Pervasives.Lemma (requires Steel.FractionalAnchoredPreorder.composable k1 k2 /\ Steel.FractionalAnchoredPreorder.composable k0 (Steel.FractionalAnchoredPreorder.compose k1 k2)) (ensures Steel.FractionalAnchoredPreorder.composable k0 k1 /\ Steel.FractionalAnchoredPreorder.composable (Steel.FractionalAnchoredPreorder.compose k0 k1) k2 /\ Steel.FractionalAnchoredPreorder.compose k0 (Steel.FractionalAnchoredPreorder.compose k1 k2) == Steel.FractionalAnchoredPreorder.compose (Steel.FractionalAnchoredPreorder.compose k0 k1) k2 )
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "FStar.Preorder.preorder", "Steel.FractionalAnchoredPreorder.anchor_rel", "Steel.FractionalAnchoredPreorder.knowledge", "FStar.Pervasives.Native.Mktuple3", "Steel.FractionalAnchoredPreorder.avalue", "Steel.FractionalAnchoredPreorder.compose_avalue_assoc_l", "Prims.unit", "Prims.l_and", "Steel.FractionalAnchoredPreorder.composable", "Steel.FractionalAnchoredPreorder.compose", "Prims.squash", "Prims.eq2", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let composable_assoc_l #v (#p: preorder v) (#s: anchor_rel p) (k0: knowledge s) (k1: knowledge s) (k2: knowledge s) : Lemma (requires composable k1 k2 /\ composable k0 (compose k1 k2)) (ensures composable k0 k1 /\ composable (compose k0 k1) k2 /\ compose k0 (compose k1 k2) == compose (compose k0 k1) k2) =
match k0, k1, k2 with | Nothing, _, _ | _, Nothing, _ | _, _, Nothing -> () | Owns m0, Owns m1, Owns m2 -> compose_avalue_assoc_l m0 m1 m2
false
Vale.Arch.Types.fsti
Vale.Arch.Types.quad32_shl32
val quad32_shl32 (q: quad32) : quad32
val quad32_shl32 (q: quad32) : quad32
let quad32_shl32 (q:quad32) : quad32 = let Mkfour v0 v1 v2 v3 = q in Mkfour 0 v0 v1 v2
{ "file_name": "vale/code/arch/Vale.Arch.Types.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 19, "end_line": 52, "start_col": 0, "start_line": 50 }
module Vale.Arch.Types open FStar.Mul open Vale.Def.Opaque_s open Vale.Def.Types_s open Vale.Lib.Seqs_s open Vale.Lib.Seqs open Vale.Def.Words_s open Vale.Def.Words.Four_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Seq open FStar.Seq open Vale.Def.Words.Two_s unfold let ( *^ ) = nat32_xor unfold let ( *^^ ) = quad32_xor unfold let add_wrap32 (x:nat32) (y:nat32) : nat32 = add_wrap x y unfold let add_wrap64 (x:nat64) (y:nat64) : nat64 = add_wrap x y unfold let sub_wrap32 (x:nat32) (y:nat32) : nat32 = sub_wrap x y unfold let sub_wrap64 (x:nat64) (y:nat64) : nat64 = sub_wrap x y unfold let iand32 (a:nat32) (b:nat32) : nat32 = iand a b unfold let ixor32 (a:nat32) (b:nat32) : nat32 = ixor a b unfold let ior32 (a:nat32) (b:nat32) : nat32 = ior a b unfold let inot32 (a:nat32) : nat32 = inot a unfold let ishl32 (a:nat32) (s:int) : nat32 = ishl a s unfold let ishr32 (a:nat32) (s:int) : nat32 = ishr a s unfold let iand64 (a:nat64) (b:nat64) : nat64 = iand a b unfold let ixor64 (a:nat64) (b:nat64) : nat64 = ixor a b unfold let ior64 (a:nat64) (b:nat64) : nat64 = ior a b unfold let inot64 (a:nat64) : nat64 = inot a unfold let ishl64 (a:nat64) (s:int) : nat64 = ishl a s unfold let ishr64 (a:nat64) (s:int) : nat64 = ishr a s unfold let iand128 (a:nat128) (b:nat128) : nat128 = iand a b unfold let ixor128 (a:nat128) (b:nat128) : nat128 = ixor a b unfold let ior128 (a:nat128) (b:nat128) : nat128 = ior a b unfold let inot128 (a:nat128) : nat128 = inot a unfold let ishl128 (a:nat128) (s:int) : nat128 = ishl a s unfold let ishr128 (a:nat128) (s:int) : nat128 = ishr a s unfold let two_to_nat32 (x:two nat32) : nat64 = two_to_nat 32 x val lemma_nat_to_two32 (_:unit) : Lemma (forall (x:nat64).{:pattern (nat_to_two 32 x)} nat_to_two 32 x == Mktwo (x % 0x100000000) (x / 0x100000000))
{ "checked_file": "/", "dependencies": [ "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Two_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Seq.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.Arch.Types.fsti" }
[ { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
q: Vale.Def.Types_s.quad32 -> Vale.Def.Types_s.quad32
Prims.Tot
[ "total" ]
[]
[ "Vale.Def.Types_s.quad32", "Vale.Def.Types_s.nat32", "Vale.Def.Words_s.Mkfour" ]
[]
false
false
false
true
false
let quad32_shl32 (q: quad32) : quad32 =
let Mkfour v0 v1 v2 v3 = q in Mkfour 0 v0 v1 v2
false
Hacl.Poly1305.Field32xN.Lemmas0.fst
Hacl.Poly1305.Field32xN.Lemmas0.precomp_r5_as_tup64
val precomp_r5_as_tup64: #w:lanes -> r:felem5 w{felem_fits5 r (2, 2, 2, 2, 2)} -> i:nat{i < w} -> Lemma (let r5 = precomp_r5 r in let (tr50, tr51, tr52, tr53, tr54) = as_tup64_i r5 i in let (tr0, tr1, tr2, tr3, tr4) = as_tup64_i r i in tr50 == tr0 *! u64 5 /\ tr51 == tr1 *! u64 5 /\ tr52 == tr2 *! u64 5 /\ tr53 == tr3 *! u64 5 /\ tr54 == tr4 *! u64 5)
val precomp_r5_as_tup64: #w:lanes -> r:felem5 w{felem_fits5 r (2, 2, 2, 2, 2)} -> i:nat{i < w} -> Lemma (let r5 = precomp_r5 r in let (tr50, tr51, tr52, tr53, tr54) = as_tup64_i r5 i in let (tr0, tr1, tr2, tr3, tr4) = as_tup64_i r i in tr50 == tr0 *! u64 5 /\ tr51 == tr1 *! u64 5 /\ tr52 == tr2 *! u64 5 /\ tr53 == tr3 *! u64 5 /\ tr54 == tr4 *! u64 5)
let precomp_r5_as_tup64 #w r i = let r5 = precomp_r5 r in let (r50, r51, r52, r53, r54) = r5 in let (r0, r1, r2, r3, r4) = r in let (tr50, tr51, tr52, tr53, tr54) = as_tup64_i r5 i in let (tr0, tr1, tr2, tr3, tr4) = as_tup64_i r i in assert_norm (max26 = pow2 26 - 1); FStar.Math.Lemmas.modulo_lemma (5 * v tr0) (pow2 64); FStar.Math.Lemmas.modulo_lemma (5 * v tr1) (pow2 64); FStar.Math.Lemmas.modulo_lemma (5 * v tr2) (pow2 64); FStar.Math.Lemmas.modulo_lemma (5 * v tr3) (pow2 64); FStar.Math.Lemmas.modulo_lemma (5 * v tr4) (pow2 64); assert (v tr50 == v (tr0 *! u64 5)); assert (v tr51 == v (tr1 *! u64 5)); assert (v tr52 == v (tr2 *! u64 5)); assert (v tr53 == v (tr3 *! u64 5)); assert (v tr54 == v (tr4 *! u64 5))
{ "file_name": "code/poly1305/Hacl.Poly1305.Field32xN.Lemmas0.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 37, "end_line": 686, "start_col": 0, "start_line": 670 }
module Hacl.Poly1305.Field32xN.Lemmas0 open Lib.IntTypes open Lib.IntVector open Lib.Sequence open FStar.Mul open FStar.Calc open Hacl.Spec.Poly1305.Vec include Hacl.Spec.Poly1305.Field32xN #reset-options "--z3rlimit 50 --using_facts_from '* -FStar.Seq' --max_fuel 0 --max_ifuel 0" val lemma_prime: unit -> Lemma (pow2 130 % prime = 5) let lemma_prime () = assert_norm (pow2 130 % prime = 5 % prime); assert_norm (5 < prime); FStar.Math.Lemmas.modulo_lemma 5 prime val lemma_mult_le: a:nat -> b:nat -> c:nat -> d:nat -> Lemma (requires a <= b /\ c <= d) (ensures a * c <= b * d) let lemma_mult_le a b c d = () val lemma_mul5_distr_l: a:nat -> b:nat -> c:nat -> d:nat -> e:nat -> f:nat -> Lemma (a * (b + c + d + e + f) == a * b + a * c + a * d + a * e + a * f) let lemma_mul5_distr_l a b c d e f = () val lemma_mul5_distr_r: a:nat -> b:nat -> c:nat -> d:nat -> e:nat -> f:nat -> Lemma ((a + b + c + d + e) * f == a * f + b * f + c * f + d * f + e * f) let lemma_mul5_distr_r a b c d e f = () val smul_mod_lemma: #m1:scale32 -> #m2:scale32 -> a:nat{a <= m1 * max26} -> b:nat{b <= m2 * max26} -> Lemma (a * b % pow2 64 == a * b) let smul_mod_lemma #m1 #m2 a b = lemma_mult_le a (m1 * max26) b (m2 * max26); assert (a * b <= m1 * m2 * max26 * max26); FStar.Math.Lemmas.modulo_lemma (a * b) (pow2 64) val smul_add_mod_lemma: #m1:scale32 -> #m2:scale32 -> #m3:scale64{m3 + m1 * m2 <= 4096} -> a:nat{a <= m1 * max26} -> b:nat{b <= m2 * max26} -> c:nat{c <= m3 * max26 * max26} -> Lemma ((c + a * b % pow2 64) % pow2 64 == c + a * b) let smul_add_mod_lemma #m1 #m2 #m3 a b c = assert_norm ((m3 + m1 * m2) * max26 * max26 < pow2 64); lemma_mult_le a (m1 * max26) b (m2 * max26); assert (c + a * b <= m3 * max26 * max26 + m1 * m2 * max26 * max26); FStar.Math.Lemmas.modulo_lemma (c + a * b) (pow2 64) val add5_lemma1: ma:scale64 -> mb:scale64 -> a:uint64 -> b:uint64 -> Lemma (requires v a <= ma * max26 /\ v b <= mb * max26 /\ ma + mb <= 64) (ensures v (a +. b) == v a + v b /\ v (a +. b) <= (ma + mb) * max26) let add5_lemma1 ma mb a b = assert (v a + v b <= (ma + mb) * max26); Math.Lemmas.lemma_mult_le_right max26 (ma + mb) 64; assert (v a + v b <= 64 * max26); assert_norm (64 * max26 < pow2 32); Math.Lemmas.small_mod (v a + v b) (pow2 32) #set-options "--ifuel 1" val fadd5_eval_lemma_i: #w:lanes -> f1:felem5 w{felem_fits5 f1 (2,2,2,2,2)} -> f2:felem5 w{felem_fits5 f2 (1,1,1,1,1)} -> i:nat{i < w} -> Lemma ((feval5 (fadd5 f1 f2)).[i] == pfadd (feval5 f1).[i] (feval5 f2).[i]) let fadd5_eval_lemma_i #w f1 f2 i = let o = fadd5 f1 f2 in let (f10, f11, f12, f13, f14) = as_tup64_i f1 i in let (f20, f21, f22, f23, f24) = as_tup64_i f2 i in let (o0, o1, o2, o3, o4) = as_tup64_i o i in add5_lemma1 2 1 f10 f20; add5_lemma1 2 1 f11 f21; add5_lemma1 2 1 f12 f22; add5_lemma1 2 1 f13 f23; add5_lemma1 2 1 f14 f24; assert (as_nat5 (o0, o1, o2, o3, o4) == as_nat5 (f10, f11, f12, f13, f14) + as_nat5 (f20, f21, f22, f23, f24)); FStar.Math.Lemmas.lemma_mod_plus_distr_l (as_nat5 (f10, f11, f12, f13, f14)) (as_nat5 (f20, f21, f22, f23, f24)) prime; FStar.Math.Lemmas.lemma_mod_plus_distr_r (as_nat5 (f10, f11, f12, f13, f14) % prime) (as_nat5 (f20, f21, f22, f23, f24)) prime val smul_felem5_fits_lemma_i: #w:lanes -> #m1:scale32 -> #m2:scale32 -> u1:uint64xN w{felem_fits1 u1 m1} -> f2:uint64xN w{felem_fits1 f2 m2} -> i:nat{i < w} -> Lemma ((uint64xN_v (vec_mul_mod f2 u1)).[i] <= m1 * m2 * max26 * max26) let smul_felem5_fits_lemma_i #w #m1 #m2 u1 f2 i = let o = vec_mul_mod f2 u1 in smul_mod_lemma #m1 #m2 (uint64xN_v u1).[i] (uint64xN_v f2).[i]; assert ((uint64xN_v o).[i] == (uint64xN_v u1).[i] * (uint64xN_v f2).[i]); lemma_mult_le (uint64xN_v u1).[i] (m1 * max26) (uint64xN_v f2).[i] (m2 * max26) val smul_felem5_eval_lemma_i: #w:lanes -> #m1:scale32 -> #m2:scale32_5 -> u1:uint64xN w{felem_fits1 u1 m1} -> f2:felem5 w{felem_fits5 f2 m2} -> i:nat{i < w} -> Lemma ((fas_nat5 (smul_felem5 #w u1 f2)).[i] == (uint64xN_v u1).[i] * (fas_nat5 f2).[i]) let smul_felem5_eval_lemma_i #w #m1 #m2 u1 f2 i = let o = smul_felem5 #w u1 f2 in let (m20, m21, m22, m23, m24) = m2 in let vu1 = (uint64xN_v u1).[i] in let (tf20, tf21, tf22, tf23, tf24) = as_tup64_i f2 i in let (to0, to1, to2, to3, to4) = as_tup64_i o i in smul_mod_lemma #m1 #m20 vu1 (v tf20); smul_mod_lemma #m1 #m21 vu1 (v tf21); smul_mod_lemma #m1 #m22 vu1 (v tf22); smul_mod_lemma #m1 #m23 vu1 (v tf23); smul_mod_lemma #m1 #m24 vu1 (v tf24); assert ((fas_nat5 o).[i] == vu1 * v tf20 + vu1 * v tf21 * pow26 + vu1 * v tf22 * pow52 + vu1 * v tf23 * pow78 + vu1 * v tf24 * pow104); calc (==) { vu1 * (fas_nat5 f2).[i]; (==) { } vu1 * (v tf20 + v tf21 * pow26 + v tf22 * pow52 + v tf23 * pow78 + v tf24 * pow104); (==) { lemma_mul5_distr_l vu1 (v tf20) (v tf21 * pow26) (v tf22 * pow52) (v tf23 * pow78) (v tf24 * pow104)} vu1 * v tf20 + vu1 * (v tf21 * pow26) + vu1 * (v tf22 * pow52) + vu1 * (v tf23 * pow78) + vu1 * (v tf24 * pow104); (==) { FStar.Math.Lemmas.paren_mul_right vu1 (v tf21) pow26; FStar.Math.Lemmas.paren_mul_right vu1 (v tf22) pow52; FStar.Math.Lemmas.paren_mul_right vu1 (v tf23) pow78; FStar.Math.Lemmas.paren_mul_right vu1 (v tf24) pow104} vu1 * v tf20 + vu1 * v tf21 * pow26 + vu1 * v tf22 * pow52 + vu1 * v tf23 * pow78 + vu1 * v tf24 * pow104; }; assert (vu1 * (fas_nat5 f2).[i] == (fas_nat5 o).[i]) val smul_felem5_fits_lemma1: #w:lanes -> #m1:scale32 -> #m2:scale32 -> u1:uint64xN w{felem_fits1 u1 m1} -> f2:uint64xN w{felem_fits1 f2 m2} -> Lemma (felem_wide_fits1 (vec_mul_mod f2 u1) (m1 * m2)) let smul_felem5_fits_lemma1 #w #m1 #m2 u1 f2 = match w with | 1 -> smul_felem5_fits_lemma_i #w #m1 #m2 u1 f2 0 | 2 -> smul_felem5_fits_lemma_i #w #m1 #m2 u1 f2 0; smul_felem5_fits_lemma_i #w #m1 #m2 u1 f2 1 | 4 -> smul_felem5_fits_lemma_i #w #m1 #m2 u1 f2 0; smul_felem5_fits_lemma_i #w #m1 #m2 u1 f2 1; smul_felem5_fits_lemma_i #w #m1 #m2 u1 f2 2; smul_felem5_fits_lemma_i #w #m1 #m2 u1 f2 3 val smul_felem5_fits_lemma: #w:lanes -> #m1:scale32 -> #m2:scale32_5 -> u1:uint64xN w{felem_fits1 u1 m1} -> f2:felem5 w{felem_fits5 f2 m2} -> Lemma (felem_wide_fits5 (smul_felem5 #w u1 f2) (m1 *^ m2)) let smul_felem5_fits_lemma #w #m1 #m2 u1 f2 = let (f20, f21, f22, f23, f24) = f2 in let (m20, m21, m22, m23, m24) = m2 in smul_felem5_fits_lemma1 #w #m1 #m20 u1 f20; smul_felem5_fits_lemma1 #w #m1 #m21 u1 f21; smul_felem5_fits_lemma1 #w #m1 #m22 u1 f22; smul_felem5_fits_lemma1 #w #m1 #m23 u1 f23; smul_felem5_fits_lemma1 #w #m1 #m24 u1 f24 val smul_felem5_eval_lemma: #w:lanes -> #m1:scale32 -> #m2:scale32_5 -> u1:uint64xN w{felem_fits1 u1 m1} -> f2:felem5 w{felem_fits5 f2 m2} -> Lemma (fas_nat5 (smul_felem5 #w u1 f2) == map2 #nat #nat #nat (fun a b -> a * b) (uint64xN_v u1) (fas_nat5 f2)) let smul_felem5_eval_lemma #w #m1 #m2 u1 f2 = FStar.Classical.forall_intro (smul_felem5_eval_lemma_i #w #m1 #m2 u1 f2); eq_intro (fas_nat5 (smul_felem5 #w u1 f2)) (map2 #nat #nat #nat (fun a b -> a * b) (uint64xN_v u1) (fas_nat5 f2)) val smul_add_felem5_fits_lemma_i: #w:lanes -> #m1:scale32 -> #m2:scale32 -> #m3:scale64{m3 + m1 * m2 <= 4096} -> u1:uint64xN w{felem_fits1 u1 m1} -> f2:uint64xN w{felem_fits1 f2 m2} -> acc1:uint64xN w{felem_wide_fits1 acc1 m3} -> i:nat{i < w} -> Lemma ((uint64xN_v (vec_add_mod acc1 (vec_mul_mod f2 u1))).[i] <= (m3 + m1 * m2) * max26 * max26) #push-options "--z3rlimit 200" let smul_add_felem5_fits_lemma_i #w #m1 #m2 #m3 u1 f2 acc1 i = let o = vec_add_mod acc1 (vec_mul_mod f2 u1) in smul_add_mod_lemma #m1 #m2 #m3 (uint64xN_v u1).[i] (uint64xN_v f2).[i] (uint64xN_v acc1).[i]; assert ((uint64xN_v o).[i] == (uint64xN_v acc1).[i] + (uint64xN_v u1).[i] * (uint64xN_v f2).[i]); lemma_mult_le (uint64xN_v u1).[i] (m1 * max26) (uint64xN_v f2).[i] (m2 * max26); assert ((uint64xN_v o).[i] <= m3 * max26 * max26 + m1 * m2 * max26 * max26) #pop-options val smul_add_felem5_eval_lemma_i: #w:lanes -> #m1:scale32 -> #m2:scale32_5 -> #m3:scale64_5{m3 +* m1 *^ m2 <=* s64x5 4096} -> u1:uint64xN w{felem_fits1 u1 m1} -> f2:felem5 w{felem_fits5 f2 m2} -> acc1:felem_wide5 w{felem_wide_fits5 acc1 m3} -> i:nat{i < w} -> Lemma ((fas_nat5 (smul_add_felem5 #w u1 f2 acc1)).[i] == (fas_nat5 acc1).[i] + (uint64xN_v u1).[i] * (fas_nat5 f2).[i]) let smul_add_felem5_eval_lemma_i #w #m1 #m2 #m3 u1 f2 acc1 i = let o = smul_add_felem5 #w u1 f2 acc1 in let (m20, m21, m22, m23, m24) = m2 in let (m30, m31, m32, m33, m34) = m3 in let vu1 = (uint64xN_v u1).[i] in let (tf20, tf21, tf22, tf23, tf24) = as_tup64_i f2 i in let (ta0, ta1, ta2, ta3, ta4) = as_tup64_i acc1 i in let (to0, to1, to2, to3, to4) = as_tup64_i o i in smul_add_mod_lemma #m1 #m20 #m30 vu1 (v tf20) (v ta0); smul_add_mod_lemma #m1 #m21 #m31 vu1 (v tf21) (v ta1); smul_add_mod_lemma #m1 #m22 #m32 vu1 (v tf22) (v ta2); smul_add_mod_lemma #m1 #m23 #m33 vu1 (v tf23) (v ta3); smul_add_mod_lemma #m1 #m24 #m34 vu1 (v tf24) (v ta4); calc (==) { (fas_nat5 o).[i]; (==) { } v ta0 + vu1 * v tf20 + (v ta1 + vu1 * v tf21) * pow26 + (v ta2 + vu1 * v tf22) * pow52 + (v ta3 + vu1 * v tf23) * pow78 + (v ta4 + vu1 * v tf24) * pow104; (==) { FStar.Math.Lemmas.distributivity_add_left (v ta1) (vu1 * v tf21) pow26; FStar.Math.Lemmas.distributivity_add_left (v ta2) (vu1 * v tf22) pow52; FStar.Math.Lemmas.distributivity_add_left (v ta3) (vu1 * v tf23) pow78; FStar.Math.Lemmas.distributivity_add_left (v ta1) (vu1 * v tf24) pow104 } v ta0 + v ta1 * pow26 + v ta2 * pow52 + v ta3 * pow78 + v ta4 * pow104 + vu1 * v tf20 + vu1 * v tf21 * pow26 + vu1 * v tf22 * pow52 + vu1 * v tf23 * pow78 + vu1 * v tf24 * pow104; (==) { } (fas_nat5 acc1).[i] + vu1 * v tf20 + vu1 * v tf21 * pow26 + vu1 * v tf22 * pow52 + vu1 * v tf23 * pow78 + vu1 * v tf24 * pow104; }; assert ((fas_nat5 o).[i] == (fas_nat5 acc1).[i] + vu1 * v tf20 + vu1 * v tf21 * pow26 + vu1 * v tf22 * pow52 + vu1 * v tf23 * pow78 + vu1 * v tf24 * pow104); calc (==) { vu1 * (fas_nat5 f2).[i]; (==) { } vu1 * (v tf20 + v tf21 * pow26 + v tf22 * pow52 + v tf23 * pow78 + v tf24 * pow104); (==) { lemma_mul5_distr_l vu1 (v tf20) (v tf21 * pow26) (v tf22 * pow52) (v tf23 * pow78) (v tf24 * pow104)} vu1 * v tf20 + vu1 * (v tf21 * pow26) + vu1 * (v tf22 * pow52) + vu1 * (v tf23 * pow78) + vu1 * (v tf24 * pow104); (==) { FStar.Math.Lemmas.paren_mul_right vu1 (v tf21) pow26; FStar.Math.Lemmas.paren_mul_right vu1 (v tf22) pow52; FStar.Math.Lemmas.paren_mul_right vu1 (v tf23) pow78; FStar.Math.Lemmas.paren_mul_right vu1 (v tf24) pow104} vu1 * v tf20 + vu1 * v tf21 * pow26 + vu1 * v tf22 * pow52 + vu1 * v tf23 * pow78 + vu1 * v tf24 * pow104; }; assert ((fas_nat5 o).[i] == (fas_nat5 acc1).[i] + vu1 * (fas_nat5 f2).[i]) val smul_add_felem5_fits_lemma1: #w:lanes -> #m1:scale32 -> #m2:scale32 -> #m3:scale64{m3 + m1 * m2 <= 4096} -> u1:uint64xN w{felem_fits1 u1 m1} -> f2:uint64xN w{felem_fits1 f2 m2} -> acc1:uint64xN w{felem_wide_fits1 acc1 m3} -> Lemma (felem_wide_fits1 (vec_add_mod acc1 (vec_mul_mod f2 u1)) (m3 + m1 * m2)) let smul_add_felem5_fits_lemma1 #w #m1 #m2 #m3 u1 f2 acc1 = match w with | 1 -> smul_add_felem5_fits_lemma_i #w #m1 #m2 #m3 u1 f2 acc1 0 | 2 -> smul_add_felem5_fits_lemma_i #w #m1 #m2 #m3 u1 f2 acc1 0; smul_add_felem5_fits_lemma_i #w #m1 #m2 #m3 u1 f2 acc1 1 | 4 -> smul_add_felem5_fits_lemma_i #w #m1 #m2 #m3 u1 f2 acc1 0; smul_add_felem5_fits_lemma_i #w #m1 #m2 #m3 u1 f2 acc1 1; smul_add_felem5_fits_lemma_i #w #m1 #m2 #m3 u1 f2 acc1 2; smul_add_felem5_fits_lemma_i #w #m1 #m2 #m3 u1 f2 acc1 3 val smul_add_felem5_fits_lemma: #w:lanes -> #m1:scale32 -> #m2:scale32_5 -> #m3:scale64_5{m3 +* m1 *^ m2 <=* s64x5 4096} -> u1:uint64xN w{felem_fits1 u1 m1} -> f2:felem5 w{felem_fits5 f2 m2} -> acc1:felem_wide5 w{felem_wide_fits5 acc1 m3} -> Lemma (felem_wide_fits5 (smul_add_felem5 #w u1 f2 acc1) (m3 +* m1 *^ m2)) let smul_add_felem5_fits_lemma #w #m1 #m2 #m3 u1 f2 acc1 = let (f20, f21, f22, f23, f24) = f2 in let (m20, m21, m22, m23, m24) = m2 in let (a0, a1, a2, a3, a4) = acc1 in let (m30, m31, m32, m33, m34) = m3 in smul_add_felem5_fits_lemma1 #w #m1 #m20 #m30 u1 f20 a0; smul_add_felem5_fits_lemma1 #w #m1 #m21 #m31 u1 f21 a1; smul_add_felem5_fits_lemma1 #w #m1 #m22 #m32 u1 f22 a2; smul_add_felem5_fits_lemma1 #w #m1 #m23 #m33 u1 f23 a3; smul_add_felem5_fits_lemma1 #w #m1 #m24 #m34 u1 f24 a4 val smul_add_felem5_eval_lemma: #w:lanes -> #m1:scale32 -> #m2:scale32_5 -> #m3:scale64_5{m3 +* m1 *^ m2 <=* s64x5 4096} -> u1:uint64xN w{felem_fits1 u1 m1} -> f2:felem5 w{felem_fits5 f2 m2} -> acc1:felem_wide5 w{felem_wide_fits5 acc1 m3} -> Lemma (fas_nat5 (smul_add_felem5 #w u1 f2 acc1) == map2 #nat #nat #nat (fun a b -> a + b) (fas_nat5 acc1) (map2 #nat #nat #nat (fun a b -> a * b) (uint64xN_v u1) (fas_nat5 f2))) let smul_add_felem5_eval_lemma #w #m1 #m2 #m3 u1 f2 acc1 = let tmp = map2 #nat #nat #nat (fun a b -> a + b) (fas_nat5 acc1) (map2 #nat #nat #nat (fun a b -> a * b) (uint64xN_v u1) (fas_nat5 f2)) in FStar.Classical.forall_intro (smul_add_felem5_eval_lemma_i #w #m1 #m2 #m3 u1 f2 acc1); eq_intro (fas_nat5 (smul_add_felem5 #w u1 f2 acc1)) tmp val lemma_fmul5_pow26: r:tup64_5 -> Lemma (requires (let (r0, r1, r2, r3, r4) = r in v r4 * 5 <= 10 * pow26)) (ensures (let (r0, r1, r2, r3, r4) = r in (pow26 * as_nat5 r) % prime == as_nat5 (r4 *! u64 5, r0, r1, r2, r3) % prime)) let lemma_fmul5_pow26 r = let (r0, r1, r2, r3, r4) = r in calc (==) { (pow26 * as_nat5 r) % prime; (==) { } (pow26 * (v r0 + v r1 * pow26 + v r2 * pow52 + v r3 * pow78 + v r4 * pow104)) % prime; (==) { lemma_mul5_distr_l pow26 (v r0) (v r1 * pow26) (v r2 * pow52) (v r3 * pow78) (v r4 * pow104) } (v r0 * pow26 + pow26 * v r1 * pow26 + pow26 * v r2 * pow52 + pow26 * v r3 * pow78 + pow26 * v r4 * pow104) % prime; (==) { } (v r0 * pow26 + v r1 * pow26 * pow26 + v r2 * pow26 * pow52 + v r3 * pow26 * pow78 + v r4 * pow26 * pow104) % prime; (==) { assert_norm (pow26 * pow26 = pow52); assert_norm (pow26 * pow52 = pow78); assert_norm (pow26 * pow78 = pow104); assert_norm (pow26 * pow104 = pow2 130) } (v r0 * pow26 + v r1 * pow52 + v r2 * pow78 + v r3 * pow104 + v r4 * pow2 130) % prime; (==) { FStar.Math.Lemmas.lemma_mod_plus_distr_r (v r0 * pow26 + v r1 * pow52 + v r2 * pow78 + v r3 * pow104) (v r4 * pow2 130) prime } (v r0 * pow26 + v r1 * pow52 + v r2 * pow78 + v r3 * pow104 + (v r4 * pow2 130) % prime) % prime; (==) { FStar.Math.Lemmas.lemma_mod_mul_distr_r (v r4) (pow2 130) prime } (v r0 * pow26 + v r1 * pow52 + v r2 * pow78 + v r3 * pow104 + (v r4 * (pow2 130 % prime)) % prime) % prime; (==) { lemma_prime () } (v r0 * pow26 + v r1 * pow52 + v r2 * pow78 + v r3 * pow104 + (v r4 * 5) % prime) % prime; (==) { FStar.Math.Lemmas.lemma_mod_plus_distr_r (v r0 * pow26 + v r1 * pow52 + v r2 * pow78 + v r3 * pow104) (v r4 * 5) prime } (v r0 * pow26 + v r1 * pow52 + v r2 * pow78 + v r3 * pow104 + v r4 * 5) % prime; }; assert ((pow26 * as_nat5 r) % prime == (v r0 * pow26 + v r1 * pow52 + v r2 * pow78 + v r3 * pow104 + v r4 * 5) % prime) val lemma_fmul5_pow52: r:tup64_5 -> Lemma (requires (let (r0, r1, r2, r3, r4) = r in v r4 * 5 <= 10 * pow26 /\ v r3 * 5 <= 10 * pow26)) (ensures (let (r0, r1, r2, r3, r4) = r in (pow52 * as_nat5 r) % prime == as_nat5 (r3 *! u64 5, r4 *! u64 5, r0, r1, r2) % prime)) let lemma_fmul5_pow52 r = let (r0, r1, r2, r3, r4) = r in calc (==) { (pow52 * as_nat5 r) % prime; (==) { assert_norm (pow52 == pow26 * pow26) } (pow26 * pow26 * as_nat5 r) % prime; (==) { FStar.Math.Lemmas.paren_mul_right pow26 pow26 (as_nat5 r); FStar.Math.Lemmas.lemma_mod_mul_distr_r pow26 (pow26 * as_nat5 r) prime } (pow26 * (pow26 * as_nat5 r % prime)) % prime; (==) { lemma_fmul5_pow26 r } (pow26 * (as_nat5 (r4 *! u64 5, r0, r1, r2, r3) % prime)) % prime; (==) { FStar.Math.Lemmas.lemma_mod_mul_distr_r pow26 (as_nat5 (r4 *! u64 5, r0, r1, r2, r3)) prime } (pow26 * as_nat5 (r4 *! u64 5, r0, r1, r2, r3)) % prime; (==) { lemma_fmul5_pow26 (r4 *! u64 5, r0, r1, r2, r3) } as_nat5 (r3 *! u64 5, r4 *! u64 5, r0, r1, r2) % prime; }; assert ((pow52 * as_nat5 r) % prime == as_nat5 (r3 *! u64 5, r4 *! u64 5, r0, r1, r2) % prime) val lemma_fmul5_pow78: r:tup64_5 -> Lemma (requires (let (r0, r1, r2, r3, r4) = r in v r4 * 5 <= 10 * pow26 /\ v r3 * 5 <= 10 * pow26 /\ v r2 * 5 <= 10 * pow26)) (ensures (let (r0, r1, r2, r3, r4) = r in (pow78 * as_nat5 r) % prime == as_nat5 (r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0, r1) % prime)) let lemma_fmul5_pow78 r = let (r0, r1, r2, r3, r4) = r in calc (==) { (pow78 * as_nat5 r) % prime; (==) { assert_norm (pow78 == pow26 * pow52) } (pow26 * pow52 * as_nat5 r) % prime; (==) { FStar.Math.Lemmas.paren_mul_right pow26 pow52 (as_nat5 r); FStar.Math.Lemmas.lemma_mod_mul_distr_r pow26 (pow52 * as_nat5 r) prime } (pow26 * (pow52 * as_nat5 r % prime)) % prime; (==) { lemma_fmul5_pow52 r } (pow26 * (as_nat5 (r3 *! u64 5, r4 *! u64 5, r0, r1, r2) % prime)) % prime; (==) { FStar.Math.Lemmas.lemma_mod_mul_distr_r pow26 (as_nat5 (r3 *! u64 5, r4 *! u64 5, r0, r1, r2)) prime } (pow26 * as_nat5 (r3 *! u64 5, r4 *! u64 5, r0, r1, r2)) % prime; (==) { lemma_fmul5_pow26 (r3 *! u64 5, r4 *! u64 5, r0, r1, r2) } as_nat5 (r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0, r1) % prime; }; assert ((pow78 * as_nat5 r) % prime == as_nat5 (r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0, r1) % prime) val lemma_fmul5_pow104: r:tup64_5 -> Lemma (requires (let (r0, r1, r2, r3, r4) = r in v r4 * 5 <= 10 * pow26 /\ v r3 * 5 <= 10 * pow26 /\ v r2 * 5 <= 10 * pow26 /\ v r1 * 5 <= 10 * pow26)) (ensures (let (r0, r1, r2, r3, r4) = r in (pow104 * as_nat5 r) % prime == as_nat5 (r1 *! u64 5, r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0) % prime)) let lemma_fmul5_pow104 r = let (r0, r1, r2, r3, r4) = r in calc (==) { (pow104 * as_nat5 r) % prime; (==) { assert_norm (pow104 == pow26 * pow78) } (pow26 * pow78 * as_nat5 r) % prime; (==) { FStar.Math.Lemmas.paren_mul_right pow26 pow78 (as_nat5 r); FStar.Math.Lemmas.lemma_mod_mul_distr_r pow26 (pow78 * as_nat5 r) prime } (pow26 * (pow78 * as_nat5 r % prime)) % prime; (==) { lemma_fmul5_pow78 r } (pow26 * (as_nat5 (r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0, r1) % prime)) % prime; (==) { FStar.Math.Lemmas.lemma_mod_mul_distr_r pow26 (as_nat5 (r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0, r1)) prime } (pow26 * as_nat5 (r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0, r1)) % prime; (==) { lemma_fmul5_pow26 (r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0, r1) } as_nat5 (r1 *! u64 5, r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0) % prime; }; assert ((pow104 * as_nat5 r) % prime == as_nat5 (r1 *! u64 5, r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0) % prime) val mul_felem5_lemma_1: f1:tup64_5{tup64_fits5 f1 (3, 3, 3, 3, 3)} -> r:tup64_5{tup64_fits5 r (2, 2, 2, 2, 2)} -> Lemma (let (f10, f11, f12, f13, f14) = f1 in let (r0, r1, r2, r3, r4) = r in (as_nat5 f1 * as_nat5 r) % prime == (v f10 * as_nat5 r + v f11 * as_nat5 (r4 *! u64 5, r0, r1, r2, r3) + v f12 * pow52 * as_nat5 r + v f13 * pow78 * as_nat5 r + v f14 * pow104 * as_nat5 r) % prime) let mul_felem5_lemma_1 f1 r = let (f10, f11, f12, f13, f14) = f1 in let (r0, r1, r2, r3, r4) = r in let tmp = v f10 * as_nat5 r + v f12 * pow52 * as_nat5 r + v f13 * pow78 * as_nat5 r + v f14 * pow104 * as_nat5 r in calc (==) { (as_nat5 f1 * as_nat5 r) % prime; (==) { } (v f10 + v f11 * pow26 + v f12 * pow52 + v f13 * pow78 + v f14 * pow104) * as_nat5 r % prime; (==) { lemma_mul5_distr_r (v f10) (v f11 * pow26) (v f12 * pow52) (v f13 * pow78) (v f14 * pow104) (as_nat5 r) } (v f10 * as_nat5 r + v f11 * pow26 * as_nat5 r + v f12 * pow52 * as_nat5 r + v f13 * pow78 * as_nat5 r + v f14 * pow104 * as_nat5 r) % prime; (==) { FStar.Math.Lemmas.lemma_mod_plus_distr_r tmp (v f11 * pow26 * as_nat5 r) prime } (tmp + (v f11 * pow26 * as_nat5 r) % prime) % prime; (==) { FStar.Math.Lemmas.paren_mul_right (v f11) pow26 (as_nat5 r); FStar.Math.Lemmas.lemma_mod_mul_distr_r (v f11) (pow26 * as_nat5 r) prime } (tmp + v f11 * (pow26 * as_nat5 r % prime) % prime) % prime; (==) { lemma_fmul5_pow26 r } (tmp + v f11 * (as_nat5 (r4 *! u64 5, r0, r1, r2, r3) % prime) % prime) % prime; (==) { FStar.Math.Lemmas.lemma_mod_mul_distr_r (v f11) (as_nat5 (r4 *! u64 5, r0, r1, r2, r3)) prime } (tmp + v f11 * as_nat5 (r4 *! u64 5, r0, r1, r2, r3) % prime) % prime; (==) { FStar.Math.Lemmas.lemma_mod_plus_distr_r tmp (v f11 * as_nat5 (r4 *! u64 5, r0, r1, r2, r3)) prime } (tmp + v f11 * as_nat5 (r4 *! u64 5, r0, r1, r2, r3)) % prime; }; assert ((as_nat5 f1 * as_nat5 r) % prime == (tmp + v f11 * as_nat5 (r4 *! u64 5, r0, r1, r2, r3)) % prime) val mul_felem5_lemma_2: f1:tup64_5{tup64_fits5 f1 (3, 3, 3, 3, 3)} -> r:tup64_5{tup64_fits5 r (2, 2, 2, 2, 2)} -> Lemma (let (f10, f11, f12, f13, f14) = f1 in let (r0, r1, r2, r3, r4) = r in (as_nat5 f1 * as_nat5 r) % prime == (v f10 * as_nat5 r + v f11 * as_nat5 (r4 *! u64 5, r0, r1, r2, r3) + v f12 * as_nat5 (r3 *! u64 5, r4 *! u64 5, r0, r1, r2) + v f13 * pow78 * as_nat5 r + v f14 * pow104 * as_nat5 r) % prime) let mul_felem5_lemma_2 f1 r = let (f10, f11, f12, f13, f14) = f1 in let (r0, r1, r2, r3, r4) = r in let tmp = v f10 * as_nat5 r + v f11 * as_nat5 (r4 *! u64 5, r0, r1, r2, r3) + v f13 * pow78 * as_nat5 r + v f14 * pow104 * as_nat5 r in calc (==) { (as_nat5 f1 * as_nat5 r) % prime; (==) { mul_felem5_lemma_1 f1 r } (tmp + v f12 * pow52 * as_nat5 r) % prime; (==) { FStar.Math.Lemmas.lemma_mod_plus_distr_r tmp (v f12 * pow52 * as_nat5 r) prime } (tmp + (v f12 * pow52 * as_nat5 r) % prime) % prime; (==) { FStar.Math.Lemmas.paren_mul_right (v f12) pow52 (as_nat5 r); FStar.Math.Lemmas.lemma_mod_mul_distr_r (v f12) (pow52 * as_nat5 r) prime } (tmp + v f12 * (pow52 * as_nat5 r % prime) % prime) % prime; (==) { lemma_fmul5_pow52 r } (tmp + v f12 * (as_nat5 (r3 *! u64 5, r4 *! u64 5, r0, r1, r2) % prime) % prime) % prime; (==) { FStar.Math.Lemmas.lemma_mod_mul_distr_r (v f12) (as_nat5 (r3 *! u64 5, r4 *! u64 5, r0, r1, r2)) prime } (tmp + v f12 * as_nat5 (r3 *! u64 5, r4 *! u64 5, r0, r1, r2) % prime) % prime; (==) { FStar.Math.Lemmas.lemma_mod_plus_distr_r tmp (v f12 * as_nat5 (r3 *! u64 5, r4 *! u64 5, r0, r1, r2)) prime } (tmp + v f12 * as_nat5 (r3 *! u64 5, r4 *! u64 5, r0, r1, r2)) % prime; }; assert ((as_nat5 f1 * as_nat5 r) % prime == (tmp + v f12 * as_nat5 (r3 *! u64 5, r4 *! u64 5, r0, r1, r2)) % prime) val mul_felem5_lemma_3: f1:tup64_5{tup64_fits5 f1 (3, 3, 3, 3, 3)} -> r:tup64_5{tup64_fits5 r (2, 2, 2, 2, 2)} -> Lemma (let (f10, f11, f12, f13, f14) = f1 in let (r0, r1, r2, r3, r4) = r in (as_nat5 f1 * as_nat5 r) % prime == (v f10 * as_nat5 r + v f11 * as_nat5 (r4 *! u64 5, r0, r1, r2, r3) + v f12 * as_nat5 (r3 *! u64 5, r4 *! u64 5, r0, r1, r2) + v f13 * as_nat5 (r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0, r1) + v f14 * pow104 * as_nat5 r) % prime) let mul_felem5_lemma_3 f1 r = let (f10, f11, f12, f13, f14) = f1 in let (r0, r1, r2, r3, r4) = r in let tmp = v f10 * as_nat5 r + v f11 * as_nat5 (r4 *! u64 5, r0, r1, r2, r3) + v f12 * as_nat5 (r3 *! u64 5, r4 *! u64 5, r0, r1, r2) + v f14 * pow104 * as_nat5 r in calc (==) { (as_nat5 f1 * as_nat5 r) % prime; (==) { mul_felem5_lemma_2 f1 r } (tmp + v f13 * pow78 * as_nat5 r) % prime; (==) { FStar.Math.Lemmas.lemma_mod_plus_distr_r tmp (v f13 * pow78 * as_nat5 r) prime } (tmp + (v f13 * pow78 * as_nat5 r) % prime) % prime; (==) { FStar.Math.Lemmas.paren_mul_right (v f13) pow78 (as_nat5 r); FStar.Math.Lemmas.lemma_mod_mul_distr_r (v f13) (pow78 * as_nat5 r) prime } (tmp + v f13 * (pow78 * as_nat5 r % prime) % prime) % prime; (==) { lemma_fmul5_pow78 r } (tmp + v f13 * (as_nat5 (r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0, r1) % prime) % prime) % prime; (==) { FStar.Math.Lemmas.lemma_mod_mul_distr_r (v f13) (as_nat5 (r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0, r1)) prime } (tmp + v f13 * as_nat5 (r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0, r1) % prime) % prime; (==) { FStar.Math.Lemmas.lemma_mod_plus_distr_r tmp (v f13 * as_nat5 (r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0, r1)) prime } (tmp + v f13 * as_nat5 (r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0, r1)) % prime; }; assert ((as_nat5 f1 * as_nat5 r) % prime == (tmp + v f13 * as_nat5 (r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0, r1)) % prime) val mul_felem5_lemma_4: f1:tup64_5{tup64_fits5 f1 (3, 3, 3, 3, 3)} -> r:tup64_5{tup64_fits5 r (2, 2, 2, 2, 2)} -> Lemma (let (f10, f11, f12, f13, f14) = f1 in let (r0, r1, r2, r3, r4) = r in (as_nat5 f1 * as_nat5 r) % prime == (v f10 * as_nat5 r + v f11 * as_nat5 (r4 *! u64 5, r0, r1, r2, r3) + v f12 * as_nat5 (r3 *! u64 5, r4 *! u64 5, r0, r1, r2) + v f13 * as_nat5 (r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0, r1) + v f14 * as_nat5 (r1 *! u64 5, r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0)) % prime) let mul_felem5_lemma_4 f1 r = let (f10, f11, f12, f13, f14) = f1 in let (r0, r1, r2, r3, r4) = r in let tmp = v f10 * as_nat5 r + v f11 * as_nat5 (r4 *! u64 5, r0, r1, r2, r3) + v f12 * as_nat5 (r3 *! u64 5, r4 *! u64 5, r0, r1, r2) + v f13 * as_nat5 (r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0, r1) in calc (==) { (as_nat5 f1 * as_nat5 r) % prime; (==) { mul_felem5_lemma_3 f1 r } (tmp + v f14 * pow104 * as_nat5 r) % prime; (==) { FStar.Math.Lemmas.lemma_mod_plus_distr_r tmp (v f14 * pow104 * as_nat5 r) prime } (tmp + (v f14 * pow104 * as_nat5 r) % prime) % prime; (==) { FStar.Math.Lemmas.paren_mul_right (v f14) pow104 (as_nat5 r); FStar.Math.Lemmas.lemma_mod_mul_distr_r (v f14) (pow104 * as_nat5 r) prime } (tmp + v f14 * (pow104 * as_nat5 r % prime) % prime) % prime; (==) { lemma_fmul5_pow104 r } (tmp + v f14 * (as_nat5 (r1 *! u64 5, r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0) % prime) % prime) % prime; (==) { FStar.Math.Lemmas.lemma_mod_mul_distr_r (v f14) (as_nat5 (r1 *! u64 5, r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0)) prime } (tmp + v f14 * as_nat5 (r1 *! u64 5, r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0) % prime) % prime; (==) { FStar.Math.Lemmas.lemma_mod_plus_distr_r tmp (v f14 * as_nat5 (r1 *! u64 5, r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0)) prime } (tmp + v f14 * as_nat5 (r1 *! u64 5, r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0)) % prime; }; assert ((as_nat5 f1 * as_nat5 r) % prime == (tmp + v f14 * as_nat5 (r1 *! u64 5, r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0)) % prime) val mul_felem5_lemma: f1:tup64_5{tup64_fits5 f1 (3, 3, 3, 3, 3)} -> r:tup64_5{tup64_fits5 r (2, 2, 2, 2, 2)} -> Lemma (let (f10, f11, f12, f13, f14) = f1 in let (r0, r1, r2, r3, r4) = r in (as_pfelem5 f1) `pfmul` (as_pfelem5 r) == (v f10 * as_nat5 (r0, r1, r2, r3, r4) + v f11 * as_nat5 (r4 *! u64 5, r0, r1, r2, r3) + v f12 * as_nat5 (r3 *! u64 5, r4 *! u64 5, r0, r1, r2) + v f13 * as_nat5 (r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0, r1) + v f14 * as_nat5 (r1 *! u64 5, r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0)) % prime) let mul_felem5_lemma f1 r = let (f10, f11, f12, f13, f14) = f1 in let (r0, r1, r2, r3, r4) = r in mul_felem5_lemma_4 f1 r; FStar.Math.Lemmas.lemma_mod_mul_distr_l (as_nat5 f1) (as_nat5 r) prime; FStar.Math.Lemmas.lemma_mod_mul_distr_r (as_nat5 f1 % prime) (as_nat5 r) prime val precomp_r5_as_tup64: #w:lanes -> r:felem5 w{felem_fits5 r (2, 2, 2, 2, 2)} -> i:nat{i < w} -> Lemma (let r5 = precomp_r5 r in let (tr50, tr51, tr52, tr53, tr54) = as_tup64_i r5 i in let (tr0, tr1, tr2, tr3, tr4) = as_tup64_i r i in tr50 == tr0 *! u64 5 /\ tr51 == tr1 *! u64 5 /\ tr52 == tr2 *! u64 5 /\ tr53 == tr3 *! u64 5 /\ tr54 == tr4 *! u64 5)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntVector.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Poly1305.Vec.fst.checked", "Hacl.Spec.Poly1305.Field32xN.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Poly1305.Field32xN.Lemmas0.fst" }
[ { "abbrev": false, "full_module": "Hacl.Spec.Poly1305.Field32xN", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Poly1305.Vec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntVector", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Poly1305.Field32xN", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Poly1305.Field32xN", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
r: Hacl.Spec.Poly1305.Field32xN.felem5 w {Hacl.Spec.Poly1305.Field32xN.felem_fits5 r (2, 2, 2, 2, 2)} -> i: Prims.nat{i < w} -> FStar.Pervasives.Lemma (ensures (let r5 = Hacl.Spec.Poly1305.Field32xN.precomp_r5 r in let _ = Hacl.Spec.Poly1305.Field32xN.as_tup64_i r5 i in (let FStar.Pervasives.Native.Mktuple5 #_ #_ #_ #_ #_ tr50 tr51 tr52 tr53 tr54 = _ in let _ = Hacl.Spec.Poly1305.Field32xN.as_tup64_i r i in (let FStar.Pervasives.Native.Mktuple5 #_ #_ #_ #_ #_ tr0 tr1 tr2 tr3 tr4 = _ in tr50 == tr0 *! Lib.IntTypes.u64 5 /\ tr51 == tr1 *! Lib.IntTypes.u64 5 /\ tr52 == tr2 *! Lib.IntTypes.u64 5 /\ tr53 == tr3 *! Lib.IntTypes.u64 5 /\ tr54 == tr4 *! Lib.IntTypes.u64 5) <: Type0) <: Type0))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Hacl.Spec.Poly1305.Field32xN.lanes", "Hacl.Spec.Poly1305.Field32xN.felem5", "Hacl.Spec.Poly1305.Field32xN.felem_fits5", "FStar.Pervasives.Native.Mktuple5", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Hacl.Spec.Poly1305.Field32xN.uint64xN", "Lib.IntTypes.uint64", "Prims._assert", "Prims.eq2", "Lib.IntTypes.range_t", "Lib.IntTypes.U64", "Lib.IntTypes.v", "Lib.IntTypes.SEC", "Lib.IntTypes.op_Star_Bang", "Lib.IntTypes.u64", "Prims.unit", "FStar.Math.Lemmas.modulo_lemma", "FStar.Mul.op_Star", "Prims.pow2", "FStar.Pervasives.assert_norm", "Prims.op_Equality", "Prims.int", "Hacl.Spec.Poly1305.Field32xN.max26", "Prims.op_Subtraction", "Hacl.Spec.Poly1305.Field32xN.tup64_5", "Hacl.Spec.Poly1305.Field32xN.as_tup64_i", "Hacl.Spec.Poly1305.Field32xN.precomp_r5" ]
[]
false
false
true
false
false
let precomp_r5_as_tup64 #w r i =
let r5 = precomp_r5 r in let r50, r51, r52, r53, r54 = r5 in let r0, r1, r2, r3, r4 = r in let tr50, tr51, tr52, tr53, tr54 = as_tup64_i r5 i in let tr0, tr1, tr2, tr3, tr4 = as_tup64_i r i in assert_norm (max26 = pow2 26 - 1); FStar.Math.Lemmas.modulo_lemma (5 * v tr0) (pow2 64); FStar.Math.Lemmas.modulo_lemma (5 * v tr1) (pow2 64); FStar.Math.Lemmas.modulo_lemma (5 * v tr2) (pow2 64); FStar.Math.Lemmas.modulo_lemma (5 * v tr3) (pow2 64); FStar.Math.Lemmas.modulo_lemma (5 * v tr4) (pow2 64); assert (v tr50 == v (tr0 *! u64 5)); assert (v tr51 == v (tr1 *! u64 5)); assert (v tr52 == v (tr2 *! u64 5)); assert (v tr53 == v (tr3 *! u64 5)); assert (v tr54 == v (tr4 *! u64 5))
false
Vale.Arch.Types.fsti
Vale.Arch.Types.quad32_to_seq
val quad32_to_seq (q: quad32) : seq nat32
val quad32_to_seq (q: quad32) : seq nat32
let quad32_to_seq (q:quad32) : seq nat32 = four_to_seq_LE q
{ "file_name": "vale/code/arch/Vale.Arch.Types.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 66, "end_line": 97, "start_col": 7, "start_line": 97 }
module Vale.Arch.Types open FStar.Mul open Vale.Def.Opaque_s open Vale.Def.Types_s open Vale.Lib.Seqs_s open Vale.Lib.Seqs open Vale.Def.Words_s open Vale.Def.Words.Four_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Seq open FStar.Seq open Vale.Def.Words.Two_s unfold let ( *^ ) = nat32_xor unfold let ( *^^ ) = quad32_xor unfold let add_wrap32 (x:nat32) (y:nat32) : nat32 = add_wrap x y unfold let add_wrap64 (x:nat64) (y:nat64) : nat64 = add_wrap x y unfold let sub_wrap32 (x:nat32) (y:nat32) : nat32 = sub_wrap x y unfold let sub_wrap64 (x:nat64) (y:nat64) : nat64 = sub_wrap x y unfold let iand32 (a:nat32) (b:nat32) : nat32 = iand a b unfold let ixor32 (a:nat32) (b:nat32) : nat32 = ixor a b unfold let ior32 (a:nat32) (b:nat32) : nat32 = ior a b unfold let inot32 (a:nat32) : nat32 = inot a unfold let ishl32 (a:nat32) (s:int) : nat32 = ishl a s unfold let ishr32 (a:nat32) (s:int) : nat32 = ishr a s unfold let iand64 (a:nat64) (b:nat64) : nat64 = iand a b unfold let ixor64 (a:nat64) (b:nat64) : nat64 = ixor a b unfold let ior64 (a:nat64) (b:nat64) : nat64 = ior a b unfold let inot64 (a:nat64) : nat64 = inot a unfold let ishl64 (a:nat64) (s:int) : nat64 = ishl a s unfold let ishr64 (a:nat64) (s:int) : nat64 = ishr a s unfold let iand128 (a:nat128) (b:nat128) : nat128 = iand a b unfold let ixor128 (a:nat128) (b:nat128) : nat128 = ixor a b unfold let ior128 (a:nat128) (b:nat128) : nat128 = ior a b unfold let inot128 (a:nat128) : nat128 = inot a unfold let ishl128 (a:nat128) (s:int) : nat128 = ishl a s unfold let ishr128 (a:nat128) (s:int) : nat128 = ishr a s unfold let two_to_nat32 (x:two nat32) : nat64 = two_to_nat 32 x val lemma_nat_to_two32 (_:unit) : Lemma (forall (x:nat64).{:pattern (nat_to_two 32 x)} nat_to_two 32 x == Mktwo (x % 0x100000000) (x / 0x100000000)) let quad32_shl32 (q:quad32) : quad32 = let Mkfour v0 v1 v2 v3 = q in Mkfour 0 v0 v1 v2 let add_wrap_quad32 (q0 q1:quad32) : quad32 = let open Vale.Def.Words_s in Mkfour (add_wrap q0.lo0 q1.lo0) (add_wrap q0.lo1 q1.lo1) (add_wrap q0.hi2 q1.hi2) (add_wrap q0.hi3 q1.hi3) val lemma_BitwiseXorCommutative (x y:nat32) : Lemma (x *^ y == y *^ x) val lemma_BitwiseXorWithZero (n:nat32) : Lemma (n *^ 0 == n) val lemma_BitwiseXorCancel (n:nat32) : Lemma (n *^ n == 0) val lemma_BitwiseXorCancel64 (n:nat64) : Lemma (ixor n n == 0) val lemma_BitwiseXorAssociative (x y z:nat32) : Lemma (x *^ (y *^ z) == (x *^ y) *^ z) val xor_lemmas (_:unit) : Lemma (ensures (forall (x y:nat32).{:pattern (x *^ y)} x *^ y == y *^ x) /\ (forall (n:nat32).{:pattern (n *^ 0)} n *^ 0 == n) /\ (forall (n:nat32).{:pattern (n *^ n)} n *^ n == 0) /\ (forall (n:nat64).{:pattern (ixor n n)} ixor n n == 0) /\ (forall (x y z:nat32).{:pattern (x *^ (y *^ z))} x *^ (y *^ z) == (x *^ y) *^ z) ) val lemma_quad32_xor (_:unit) : Lemma (forall q . {:pattern quad32_xor q q} quad32_xor q q == Mkfour 0 0 0 0) let quad32_double_lo (q:quad32) : double32 = (four_to_two_two q).lo let quad32_double_hi (q:quad32) : double32 = (four_to_two_two q).hi val lemma_reverse_reverse_bytes_nat32 (n:nat32) : Lemma (reverse_bytes_nat32 (reverse_bytes_nat32 n) == n) [SMTPat (reverse_bytes_nat32 (reverse_bytes_nat32 n))] val lemma_reverse_bytes_quad32 (q:quad32) : Lemma (reverse_bytes_quad32 (reverse_bytes_quad32 q) == q) [SMTPat (reverse_bytes_quad32 (reverse_bytes_quad32 q))] val lemma_reverse_bytes_quad32_zero (_:unit) : Lemma (let z = Mkfour 0 0 0 0 in reverse_bytes_quad32 z == z) val lemma_reverse_reverse_bytes_nat32_seq (s:seq nat32) : Lemma (reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s) == s) [SMTPat (reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s))]
{ "checked_file": "/", "dependencies": [ "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Two_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Seq.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.Arch.Types.fsti" }
[ { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
q: Vale.Def.Types_s.quad32 -> FStar.Seq.Base.seq Vale.Def.Words_s.nat32
Prims.Tot
[ "total" ]
[]
[ "Vale.Def.Types_s.quad32", "Vale.Def.Words.Seq_s.four_to_seq_LE", "Vale.Def.Types_s.nat32", "FStar.Seq.Base.seq", "Vale.Def.Words_s.nat32" ]
[]
false
false
false
true
false
let quad32_to_seq (q: quad32) : seq nat32 =
four_to_seq_LE q
false
Vale.Arch.Types.fsti
Vale.Arch.Types.quad32_double_hi
val quad32_double_hi (q: quad32) : double32
val quad32_double_hi (q: quad32) : double32
let quad32_double_hi (q:quad32) : double32 = (four_to_two_two q).hi
{ "file_name": "vale/code/arch/Vale.Arch.Types.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 67, "end_line": 79, "start_col": 0, "start_line": 79 }
module Vale.Arch.Types open FStar.Mul open Vale.Def.Opaque_s open Vale.Def.Types_s open Vale.Lib.Seqs_s open Vale.Lib.Seqs open Vale.Def.Words_s open Vale.Def.Words.Four_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Seq open FStar.Seq open Vale.Def.Words.Two_s unfold let ( *^ ) = nat32_xor unfold let ( *^^ ) = quad32_xor unfold let add_wrap32 (x:nat32) (y:nat32) : nat32 = add_wrap x y unfold let add_wrap64 (x:nat64) (y:nat64) : nat64 = add_wrap x y unfold let sub_wrap32 (x:nat32) (y:nat32) : nat32 = sub_wrap x y unfold let sub_wrap64 (x:nat64) (y:nat64) : nat64 = sub_wrap x y unfold let iand32 (a:nat32) (b:nat32) : nat32 = iand a b unfold let ixor32 (a:nat32) (b:nat32) : nat32 = ixor a b unfold let ior32 (a:nat32) (b:nat32) : nat32 = ior a b unfold let inot32 (a:nat32) : nat32 = inot a unfold let ishl32 (a:nat32) (s:int) : nat32 = ishl a s unfold let ishr32 (a:nat32) (s:int) : nat32 = ishr a s unfold let iand64 (a:nat64) (b:nat64) : nat64 = iand a b unfold let ixor64 (a:nat64) (b:nat64) : nat64 = ixor a b unfold let ior64 (a:nat64) (b:nat64) : nat64 = ior a b unfold let inot64 (a:nat64) : nat64 = inot a unfold let ishl64 (a:nat64) (s:int) : nat64 = ishl a s unfold let ishr64 (a:nat64) (s:int) : nat64 = ishr a s unfold let iand128 (a:nat128) (b:nat128) : nat128 = iand a b unfold let ixor128 (a:nat128) (b:nat128) : nat128 = ixor a b unfold let ior128 (a:nat128) (b:nat128) : nat128 = ior a b unfold let inot128 (a:nat128) : nat128 = inot a unfold let ishl128 (a:nat128) (s:int) : nat128 = ishl a s unfold let ishr128 (a:nat128) (s:int) : nat128 = ishr a s unfold let two_to_nat32 (x:two nat32) : nat64 = two_to_nat 32 x val lemma_nat_to_two32 (_:unit) : Lemma (forall (x:nat64).{:pattern (nat_to_two 32 x)} nat_to_two 32 x == Mktwo (x % 0x100000000) (x / 0x100000000)) let quad32_shl32 (q:quad32) : quad32 = let Mkfour v0 v1 v2 v3 = q in Mkfour 0 v0 v1 v2 let add_wrap_quad32 (q0 q1:quad32) : quad32 = let open Vale.Def.Words_s in Mkfour (add_wrap q0.lo0 q1.lo0) (add_wrap q0.lo1 q1.lo1) (add_wrap q0.hi2 q1.hi2) (add_wrap q0.hi3 q1.hi3) val lemma_BitwiseXorCommutative (x y:nat32) : Lemma (x *^ y == y *^ x) val lemma_BitwiseXorWithZero (n:nat32) : Lemma (n *^ 0 == n) val lemma_BitwiseXorCancel (n:nat32) : Lemma (n *^ n == 0) val lemma_BitwiseXorCancel64 (n:nat64) : Lemma (ixor n n == 0) val lemma_BitwiseXorAssociative (x y z:nat32) : Lemma (x *^ (y *^ z) == (x *^ y) *^ z) val xor_lemmas (_:unit) : Lemma (ensures (forall (x y:nat32).{:pattern (x *^ y)} x *^ y == y *^ x) /\ (forall (n:nat32).{:pattern (n *^ 0)} n *^ 0 == n) /\ (forall (n:nat32).{:pattern (n *^ n)} n *^ n == 0) /\ (forall (n:nat64).{:pattern (ixor n n)} ixor n n == 0) /\ (forall (x y z:nat32).{:pattern (x *^ (y *^ z))} x *^ (y *^ z) == (x *^ y) *^ z) ) val lemma_quad32_xor (_:unit) : Lemma (forall q . {:pattern quad32_xor q q} quad32_xor q q == Mkfour 0 0 0 0)
{ "checked_file": "/", "dependencies": [ "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Two_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Seq.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.Arch.Types.fsti" }
[ { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
q: Vale.Def.Types_s.quad32 -> Vale.Def.Types_s.double32
Prims.Tot
[ "total" ]
[]
[ "Vale.Def.Types_s.quad32", "Vale.Def.Words_s.__proj__Mktwo__item__hi", "Vale.Def.Words_s.two", "Vale.Def.Types_s.nat32", "Vale.Def.Words.Four_s.four_to_two_two", "Vale.Def.Types_s.double32" ]
[]
false
false
false
true
false
let quad32_double_hi (q: quad32) : double32 =
(four_to_two_two q).hi
false
Vale.Arch.Types.fsti
Vale.Arch.Types.quad32_double_lo
val quad32_double_lo (q: quad32) : double32
val quad32_double_lo (q: quad32) : double32
let quad32_double_lo (q:quad32) : double32 = (four_to_two_two q).lo
{ "file_name": "vale/code/arch/Vale.Arch.Types.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 67, "end_line": 78, "start_col": 0, "start_line": 78 }
module Vale.Arch.Types open FStar.Mul open Vale.Def.Opaque_s open Vale.Def.Types_s open Vale.Lib.Seqs_s open Vale.Lib.Seqs open Vale.Def.Words_s open Vale.Def.Words.Four_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Seq open FStar.Seq open Vale.Def.Words.Two_s unfold let ( *^ ) = nat32_xor unfold let ( *^^ ) = quad32_xor unfold let add_wrap32 (x:nat32) (y:nat32) : nat32 = add_wrap x y unfold let add_wrap64 (x:nat64) (y:nat64) : nat64 = add_wrap x y unfold let sub_wrap32 (x:nat32) (y:nat32) : nat32 = sub_wrap x y unfold let sub_wrap64 (x:nat64) (y:nat64) : nat64 = sub_wrap x y unfold let iand32 (a:nat32) (b:nat32) : nat32 = iand a b unfold let ixor32 (a:nat32) (b:nat32) : nat32 = ixor a b unfold let ior32 (a:nat32) (b:nat32) : nat32 = ior a b unfold let inot32 (a:nat32) : nat32 = inot a unfold let ishl32 (a:nat32) (s:int) : nat32 = ishl a s unfold let ishr32 (a:nat32) (s:int) : nat32 = ishr a s unfold let iand64 (a:nat64) (b:nat64) : nat64 = iand a b unfold let ixor64 (a:nat64) (b:nat64) : nat64 = ixor a b unfold let ior64 (a:nat64) (b:nat64) : nat64 = ior a b unfold let inot64 (a:nat64) : nat64 = inot a unfold let ishl64 (a:nat64) (s:int) : nat64 = ishl a s unfold let ishr64 (a:nat64) (s:int) : nat64 = ishr a s unfold let iand128 (a:nat128) (b:nat128) : nat128 = iand a b unfold let ixor128 (a:nat128) (b:nat128) : nat128 = ixor a b unfold let ior128 (a:nat128) (b:nat128) : nat128 = ior a b unfold let inot128 (a:nat128) : nat128 = inot a unfold let ishl128 (a:nat128) (s:int) : nat128 = ishl a s unfold let ishr128 (a:nat128) (s:int) : nat128 = ishr a s unfold let two_to_nat32 (x:two nat32) : nat64 = two_to_nat 32 x val lemma_nat_to_two32 (_:unit) : Lemma (forall (x:nat64).{:pattern (nat_to_two 32 x)} nat_to_two 32 x == Mktwo (x % 0x100000000) (x / 0x100000000)) let quad32_shl32 (q:quad32) : quad32 = let Mkfour v0 v1 v2 v3 = q in Mkfour 0 v0 v1 v2 let add_wrap_quad32 (q0 q1:quad32) : quad32 = let open Vale.Def.Words_s in Mkfour (add_wrap q0.lo0 q1.lo0) (add_wrap q0.lo1 q1.lo1) (add_wrap q0.hi2 q1.hi2) (add_wrap q0.hi3 q1.hi3) val lemma_BitwiseXorCommutative (x y:nat32) : Lemma (x *^ y == y *^ x) val lemma_BitwiseXorWithZero (n:nat32) : Lemma (n *^ 0 == n) val lemma_BitwiseXorCancel (n:nat32) : Lemma (n *^ n == 0) val lemma_BitwiseXorCancel64 (n:nat64) : Lemma (ixor n n == 0) val lemma_BitwiseXorAssociative (x y z:nat32) : Lemma (x *^ (y *^ z) == (x *^ y) *^ z) val xor_lemmas (_:unit) : Lemma (ensures (forall (x y:nat32).{:pattern (x *^ y)} x *^ y == y *^ x) /\ (forall (n:nat32).{:pattern (n *^ 0)} n *^ 0 == n) /\ (forall (n:nat32).{:pattern (n *^ n)} n *^ n == 0) /\ (forall (n:nat64).{:pattern (ixor n n)} ixor n n == 0) /\ (forall (x y z:nat32).{:pattern (x *^ (y *^ z))} x *^ (y *^ z) == (x *^ y) *^ z) ) val lemma_quad32_xor (_:unit) : Lemma (forall q . {:pattern quad32_xor q q} quad32_xor q q == Mkfour 0 0 0 0)
{ "checked_file": "/", "dependencies": [ "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Two_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Seq.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.Arch.Types.fsti" }
[ { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
q: Vale.Def.Types_s.quad32 -> Vale.Def.Types_s.double32
Prims.Tot
[ "total" ]
[]
[ "Vale.Def.Types_s.quad32", "Vale.Def.Words_s.__proj__Mktwo__item__lo", "Vale.Def.Words_s.two", "Vale.Def.Types_s.nat32", "Vale.Def.Words.Four_s.four_to_two_two", "Vale.Def.Types_s.double32" ]
[]
false
false
false
true
false
let quad32_double_lo (q: quad32) : double32 =
(four_to_two_two q).lo
false
Steel.FractionalAnchoredPreorder.fst
Steel.FractionalAnchoredPreorder.update_anchored_value
val update_anchored_value (#v: Type) (#p: preorder v) (#s: anchor_rel p) (m: avalue s) (v1: v { avalue_owns_anchored m /\ (curval (avalue_val m)) `p` v1 /\ v1 `compat_with_any_anchor_of` m }) : frame_preserving_upd pcm (Owns m) (Owns (avalue_update_anchored_value m v1))
val update_anchored_value (#v: Type) (#p: preorder v) (#s: anchor_rel p) (m: avalue s) (v1: v { avalue_owns_anchored m /\ (curval (avalue_val m)) `p` v1 /\ v1 `compat_with_any_anchor_of` m }) : frame_preserving_upd pcm (Owns m) (Owns (avalue_update_anchored_value m v1))
let update_anchored_value (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) (v1:v { avalue_owns_anchored m /\ //if you own an anchored key, you can update if you respect curval (avalue_val m) `p` v1 /\ //the preorder v1 `compat_with_any_anchor_of` m //and respect any anchor of the current value }) : frame_preserving_upd pcm (Owns m) (Owns (avalue_update_anchored_value m v1)) = coerce_eq () (update_anchored_hist m (extend_history (avalue_val m) v1))
{ "file_name": "lib/steel/Steel.FractionalAnchoredPreorder.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 76, "end_line": 561, "start_col": 0, "start_line": 551 }
(* Copyright 2021 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. Author: N. Swamy *) module Steel.FractionalAnchoredPreorder (** This module provides a partial commutative monoid (PCM) for use in the ghost state of a concurrent Steel program. Its goal is to facilitate a form of information-sharing between multiple threads including the following features: Fractions, Preorders, Snapshots, and Anchors --- Anchors are the most unusual. 1. Fractions: Ownership of the state is controlled by a fractional permission, so multiple threads may share read-only privileges on the state, but only one can have write permission. 2. Preorders: The ghost state is governed by a preorder p and all updates to the state must respect the preorder (a reflexive, transitive relation on the state) 3. Snapshots: Since the state always evolves by a preorder, it is possible to take a snapshot of the state. A snapshot does not confer any particular ownership on the state, except knowledge of a snapshot ensures that the current state is related to the snapshot by the preorder. 4. Anchors are a kind of refinement of the preorder. If a thread owns an anchored value [v], then no other thread, even a thread owning a full fractional permission, can advance the state "too far" from the anchor. In particular, the PCM is parameterized by a binary relation on values, [anchors:anchor_relation]. If a thread owns the anchor [v], then the current value `cur` of the state must be in relation [v `anchors` cur]. This can be used to ensure that the knowledge of one thread is never becomes too stale. For example, this allows one to model a shared monotonically increasing counter, where if one thread anchors knowledge of the counter at the value 5, no other thread can increase the value of the counter beyond, say, 10, (when the anchor relation is y - x <= 5), until the anchoring thread releases the anchor. Further, at any point, a thread can take a snapshot of the counter and rely on the fact that the value of the counter in the future will be >= the snapshot. *) open FStar.PCM open FStar.Preorder open Steel.Preorder open Steel.FractionalPermission #push-options "--fuel 0 --ifuel 2" /// A permission: is a pair of /// /// * an optional fractional permission; with `Some p` indicating /// some ownership, while `None` is an additional "0" permission /// value, to encode snapshots. /// /// * and an optional anchor, where `Some a` indicates the current /// value can't be too far from `a`. let permission (v:Type) = option perm & option v /// Non-zero permission is either a read or write permission let has_nonzero #v (p:permission v) = Some? (fst p) /// Has an anchor set let has_anchor #v (p:permission v) = Some? (snd p) /// Either an anchor or non-zero let has_some_ownership #v (p:permission v) = has_nonzero p || has_anchor p /// The anchoring value let anchor_of #v (p:permission v { has_anchor p }) : v = Some?.v (snd p) /// The anchoring relation: /// -- A binary relation on values /// -- refining the preorder /// -- and if x `anchors` z then it also anchors any `y` between `x` and `z` /// /// Explaining the third clause a bit: /// Think intuitively of anchoring relations as a kind of distance measure /// /// if `z` is close enough to `x` then if `z` is further than `y` /// (since it is ahead of `y` in the preorder) then `y` is also /// close enough to `x` let anchor_rel (#v:Type) (p:preorder v) = anchors:(v -> v -> prop) { (forall v0 v1. anchors v0 v1 ==> p v0 v1) /\ (forall x z. x `anchors` z ==> (forall y. p x y /\ p y z ==> x `anchors` y)) // } /// An implementation remark: We use Steel.Preorder here to /// generically transform any preorder into a PCM. That works by /// taking the value of the PCM to be a history of values related by /// the preorder. So, throughout, we'll be using the the [vhist p] /// from Steel.Preorder, the type of a non-empty history compatible /// with [p]. The details of the histories don't matter much for our /// purposes---we only care about the most recent value, for which /// we'll use [curval v]. /// If the anchor is set, then the current value is anchored by it let anchored (#v:Type) (#p:preorder v) (anchors:anchor_rel p) (pv:(permission v & vhist p)) = has_anchor (fst pv) ==> anchor_of (fst pv) `anchors` curval (snd pv) /// A value in our fractional anchored PCM is a pair of a permission /// and a p-compatible history, refined to ensure that if the anchor /// is set, then the current value is anchored by it. let avalue (#v:Type) (#p:preorder v) (anchors:anchor_rel p) = pv:(permission v & vhist p) { anchored anchors pv } /// initial_value: A utility to construct a value in the PCM #push-options "--fuel 1" let initial_value (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (value:v { anchors value value }) : avalue anchors = (Some full_perm, Some value), [value] #pop-options /// We add a unit element to [avalue], as needed for a PCM [@@erasable] noeq type knowledge (#v:Type) (#p:preorder v) (anchors:anchor_rel p) = | Owns : avalue anchors -> knowledge anchors | Nothing : knowledge anchors let b2p (b:bool) : prop = b == true /// Fractional permissions are composable when their sum <= 1.0 let perm_opt_composable (p0 p1:option perm) : prop = match p0, p1 with | None, None -> True | Some p, None | None, Some p -> b2p (p `lesser_equal_perm` full_perm) | Some p0, Some p1 -> b2p (sum_perm p0 p1 `lesser_equal_perm` full_perm) /// Composing them sums the permissions let compose_perm_opt (p0 p1:option perm) = match p0, p1 with | None, p | p, None -> p | Some p0, Some p1 -> Some (sum_perm p0 p1) /// Anchored permissions are composable when at most one of them has the anchor set let permission_composable #v (p0 p1 : permission v) : prop = let q0, s0 = p0 in let q1, s1 = p1 in perm_opt_composable q0 q1 /\ // some of fracs can't exceed 1 not (Some? s0 && Some? s1) // at most one can have an anchor /// Compose permissions component wise, keeping the anchor if set let compose_permissions (#v:_) (p0:permission v) (p1:permission v{permission_composable p0 p1}) : permission v = compose_perm_opt (fst p0) (fst p1), (match snd p0, snd p1 with | None, a | a, None -> a) /// This is the central definition of the PCM --- defining when two /// values are composable, or equivalently, when one thread's /// knowledge of [av0] is compatible with another thread's knowledge /// of [av1] /// /// This definition shows the interplay between fractions and anchors. /// It wasn't obvious to me how to factor this further, e.g., adding /// anchors to preorders and then separately adding fractions to it. let avalue_composable (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (av0 av1: avalue anchors) : prop = let (p0, v0) = av0 in let (p1, v1) = av1 in permission_composable p0 p1 /\ (if not (has_some_ownership p0) && not (has_some_ownership p1) then p_composable _ v0 v1 //neither has ownership, one history is older than the other else if not (has_some_ownership p0) && has_some_ownership p1 then ( if has_nonzero p1 then v1 `extends` v0 //the one with ownership is more recent else ( //this part is the most subtle assert (has_anchor p1); p_composable _ v0 v1 /\ (v0 `extends` v1 ==> //if v0 is a more recent snapshot than v1 //then v0 must still be anchored by v1's anchor anchor_of p1 `anchors` curval v0) ) ) else if has_some_ownership p0 && not (has_some_ownership p1) then ( //symmetric if has_nonzero p0 then v0 `extends` v1 else ( assert (has_anchor p0); p_composable _ v0 v1 /\ (v1 `extends` v0 ==> anchor_of p0 `anchors` curval v1) ) ) else ( assert (has_some_ownership p0 && has_some_ownership p1); if has_nonzero p0 && has_nonzero p1 then v0 == v1 //if both have non-zero perm, then they must both only have read permission and must agree on the value else if has_nonzero p0 && has_anchor p1 then ( assert (not (has_nonzero p1)); //The key part of the anchor semantics: v0 `extends` v1 /\ //v0 has advanceable ownership, so extends anchor_of p1 `anchors` curval v0 //but not beyond what is allowed by s ) else if has_anchor p0 && has_nonzero p1 //symmetric then ( assert (not (has_nonzero p0)); v1 `extends` v0 /\ anchor_of p0 `anchors` curval v1 //v1 extends, but not beyond what is allowed by s ) else (assert false; False) ) ) //exhaustive /// Lifting avalue comosability to knowledge, including the unit let composable #v (#p:preorder v) (#a:anchor_rel p) : symrel (knowledge a) = fun (k0 k1:knowledge a) -> match k0, k1 with | Nothing, _ | _, Nothing -> True | Owns m, Owns m' -> avalue_composable m m' /// Compose avalues by composing permissions and composing the values /// using the underlying preorder PCM let compose_avalue (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (m0:avalue anchors) (m1:avalue anchors { avalue_composable m0 m1 } ) : avalue anchors = let p0, v0 = m0 in let p1, v1 = m1 in let p12 = compose_permissions p0 p1 in let v12 = p_op _ v0 v1 in p12, v12 //////////////////////////////////////////////////////////////////////////////// (** avalue composition is associative and commutative **) let compose_avalue_comm (#v:Type) (#p:preorder v) (#anc:anchor_rel p) (m0: avalue anc) (m1: avalue anc{ avalue_composable m0 m1 }) : Lemma (compose_avalue m0 m1 == compose_avalue m1 m0) = () let avalue_composable_assoc_l (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (m0: avalue anchors) (m1: avalue anchors) (m2: avalue anchors { avalue_composable m1 m2 /\ avalue_composable m0 (compose_avalue m1 m2) }) : Lemma (avalue_composable m0 m1 /\ avalue_composable (compose_avalue m0 m1) m2) = () let compose_avalue_assoc_l (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m0: avalue s) (m1: avalue s) (m2: avalue s { avalue_composable m1 m2 /\ avalue_composable m0 (compose_avalue m1 m2) }) : Lemma (avalue_composable m0 m1 /\ avalue_composable (compose_avalue m0 m1) m2 /\ compose_avalue m0 (compose_avalue m1 m2) == compose_avalue (compose_avalue m0 m1) m2) = avalue_composable_assoc_l m0 m1 m2 let avalue_composable_assoc_r (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (m0: avalue anchors) (m1: avalue anchors) (m2: avalue anchors { avalue_composable m0 m1 /\ avalue_composable (compose_avalue m0 m1) m2 }) : Lemma (avalue_composable m1 m2 /\ avalue_composable m0 (compose_avalue m1 m2)) = () let compose_avalue_assoc_r (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m0: avalue s) (m1: avalue s) (m2: avalue s{ avalue_composable m0 m1 /\ avalue_composable (compose_avalue m0 m1) m2 }) : Lemma (avalue_composable m1 m2 /\ avalue_composable m0 (compose_avalue m1 m2) /\ compose_avalue m0 (compose_avalue m1 m2) == compose_avalue (compose_avalue m0 m1) m2) = avalue_composable_assoc_r m0 m1 m2 //////////////////////////////////////////////////////////////////////////////// /// lifting avalue composition to knowledge, including unit let compose (#v:Type) (#p:preorder v) (#s:anchor_rel p) (k0:knowledge s) (k1:knowledge s{ composable k0 k1 }) : knowledge s = match k0, k1 with | Nothing, k | k, Nothing -> k | Owns m, Owns m' -> Owns (compose_avalue m m') let composable_assoc_r #v (#p:preorder v) (#s:anchor_rel p) (k0 k1 k2: knowledge s) : Lemma (requires composable k0 k1 /\ composable (compose k0 k1) k2) (ensures composable k1 k2 /\ composable k0 (compose k1 k2) /\ compose k0 (compose k1 k2) == compose (compose k0 k1) k2 ) = match k0, k1, k2 with | Nothing, _, _ | _, Nothing, _ | _, _, Nothing -> () | Owns m0, Owns m1, Owns m2 -> compose_avalue_assoc_r m0 m1 m2 let composable_assoc_l #v (#p:preorder v) (#s:anchor_rel p) (k0 k1 k2: knowledge s) : Lemma (requires composable k1 k2 /\ composable k0 (compose k1 k2)) (ensures composable k0 k1 /\ composable (compose k0 k1) k2 /\ compose k0 (compose k1 k2) == compose (compose k0 k1) k2) = match k0, k1, k2 with | Nothing, _, _ | _, Nothing, _ | _, _, Nothing -> () | Owns m0, Owns m1, Owns m2 -> compose_avalue_assoc_l m0 m1 m2 /// Now, we can define our PCM /// The core of the PCM let p0 #v #p #s : pcm' (knowledge #v #p s) = { composable; op=compose; one=Nothing } let avalue_perm (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) = fst m /// A avalue represents full ownership when the fraction is full AND /// the anchor is set. This means that no knowledge held by any other /// thread can constrain this value meaningfully. let avalue_owns (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) : prop = fst (avalue_perm m) == Some full_perm /\ Some? (snd (avalue_perm m)) let full_knowledge #v #p #s (kn:knowledge #v #p s) : prop = match kn with | Nothing -> False | Owns km -> avalue_owns km /// The PCM itself, together with proofs of its properties let pcm #v #p #s : pcm (knowledge #v #p s) = { p = p0; comm = (fun k0 k1 -> match k0, k1 with | Nothing, _ | _, Nothing -> () | Owns m0, Owns m1 -> compose_avalue_comm m0 m1); assoc = (fun k0 k1 k2 -> composable_assoc_l k0 k1 k2); assoc_r = (fun k0 k1 k2 -> composable_assoc_r k0 k1 k2); is_unit = (fun _ -> ()); refine = full_knowledge; } /// Some utilities: The value of an avalue let avalue_val (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue #v #p s) = snd m /// Updating the value, in a full-ownership situation, also involves /// updating the anchor let avalue_update (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) (value:vhist p { s (curval value) (curval value) }) : avalue s = let p, _ = avalue_perm m in let p' = p, Some (curval value) in (p', value) /// Our core frame-preserving update: /// /// If you fully own a value, you can update it so long as you /// respect the preorder, and prove that the new value is related /// to itself by the anchor (since we'll be setting the anchor to /// the new value) /// /// This is a building block: we'll define a derived version that /// on values rather than histories #push-options "--z3rlimit_factor 2" let update_hist (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) (v1:vhist p { avalue_owns m /\ v1 `extends` avalue_val m /\ s (curval v1) (curval v1) }) : frame_preserving_upd pcm (Owns m) (Owns (avalue_update m v1)) = fun full_v -> let Owns full_m = full_v in let m_res = avalue_update full_m v1 in Owns m_res #pop-options /// Updating with value, rather than a history let avalue_update_value (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) (value:v { curval (avalue_val m) `p` value /\ s value value }) : m':avalue s { curval (avalue_val m') == value /\ avalue_val m' `extends` avalue_val m } = let v = avalue_val m in avalue_update m (extend_history v value) /// A derived frame-preserving update for which one presents only a value let update_value (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) (v1:v { avalue_owns m /\ //if you have full ownership of key curval (avalue_val m) `p` v1 /\ //you can update it wrt the preorder only s v1 v1 //and it is related to itself by the anchor }) : frame_preserving_upd pcm (Owns m) (Owns (avalue_update_value m v1)) = coerce_eq () (update_hist m (extend_history (avalue_val m) v1)) //F* goes nuts and starts swallowing gobs of memory without the coerce_eq: TODO, debug /// Now for anchored updates /// Ownership of the whole fraction, but not the anchor let avalue_owns_anchored (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) = fst (avalue_perm m) == Some full_perm /\ None? (snd (avalue_perm m)) /// [v1] is compatible with (i.e., not too far from) any anchor of [v0] let compat_with_any_anchor_of (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (v1:v) (v0:avalue anchors) = forall (anchor:v). anchor `anchors` curval (avalue_val v0) ==> anchor `anchors` v1 /// An anchored update: Update the value, but leave the permission /// unchanged Only possible if the new value is compatible with any /// anchor of the old value let avalue_anchored_update (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) (value:vhist p { curval value `compat_with_any_anchor_of` m }) : avalue s = avalue_perm m, value /// A frame-preserving update for anchored values. /// Notice the additional precondition, refining the preorder let update_anchored_hist (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) (v1:vhist p { avalue_owns_anchored m /\ v1 `extends` avalue_val m /\ curval v1 `compat_with_any_anchor_of` m }) : frame_preserving_upd pcm (Owns m) (Owns (avalue_anchored_update m v1)) = fun full_v -> let Owns full_m = full_v in let m_res = avalue_anchored_update full_m v1 in Owns m_res /// A derived form without a history on the new value let avalue_update_anchored_value (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) (value:v { curval (avalue_val m) `p` value /\ value `compat_with_any_anchor_of` m }) : m':avalue s { curval (avalue_val m') == value /\ avalue_val m' `extends` avalue_val m } = let v = avalue_val m in avalue_anchored_update m (extend_history v value)
{ "checked_file": "/", "dependencies": [ "Steel.Preorder.fst.checked", "Steel.FractionalPermission.fst.checked", "prims.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked" ], "interface_file": false, "source_file": "Steel.FractionalAnchoredPreorder.fst" }
[ { "abbrev": false, "full_module": "Steel.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Steel.Preorder", "short_module": null }, { "abbrev": false, "full_module": "FStar.Preorder", "short_module": null }, { "abbrev": false, "full_module": "FStar.PCM", "short_module": null }, { "abbrev": false, "full_module": "Steel", "short_module": null }, { "abbrev": false, "full_module": "Steel", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
m: Steel.FractionalAnchoredPreorder.avalue s -> v1: v { Steel.FractionalAnchoredPreorder.avalue_owns_anchored m /\ p (Steel.Preorder.curval (Steel.FractionalAnchoredPreorder.avalue_val m)) v1 /\ Steel.FractionalAnchoredPreorder.compat_with_any_anchor_of v1 m } -> FStar.PCM.frame_preserving_upd Steel.FractionalAnchoredPreorder.pcm (Steel.FractionalAnchoredPreorder.Owns m) (Steel.FractionalAnchoredPreorder.Owns (Steel.FractionalAnchoredPreorder.avalue_update_anchored_value m v1))
Prims.Tot
[ "total" ]
[]
[ "FStar.Preorder.preorder", "Steel.FractionalAnchoredPreorder.anchor_rel", "Steel.FractionalAnchoredPreorder.avalue", "Prims.l_and", "Steel.FractionalAnchoredPreorder.avalue_owns_anchored", "Steel.Preorder.curval", "Steel.FractionalAnchoredPreorder.avalue_val", "Steel.FractionalAnchoredPreorder.compat_with_any_anchor_of", "FStar.Pervasives.coerce_eq", "FStar.PCM.frame_preserving_upd", "Steel.FractionalAnchoredPreorder.knowledge", "Steel.FractionalAnchoredPreorder.pcm", "Steel.FractionalAnchoredPreorder.Owns", "Steel.FractionalAnchoredPreorder.avalue_anchored_update", "Steel.Preorder.extend_history", "Steel.FractionalAnchoredPreorder.avalue_update_anchored_value", "Steel.FractionalAnchoredPreorder.update_anchored_hist" ]
[]
false
false
false
false
false
let update_anchored_value (#v: Type) (#p: preorder v) (#s: anchor_rel p) (m: avalue s) (v1: v { avalue_owns_anchored m /\ (curval (avalue_val m)) `p` v1 /\ v1 `compat_with_any_anchor_of` m }) : frame_preserving_upd pcm (Owns m) (Owns (avalue_update_anchored_value m v1)) =
coerce_eq () (update_anchored_hist m (extend_history (avalue_val m) v1))
false
Vale.Arch.Types.fsti
Vale.Arch.Types.hi64_def
val hi64_def (q: quad32) : nat64
val hi64_def (q: quad32) : nat64
let hi64_def (q:quad32) : nat64 = two_to_nat 32 (two_select (four_to_two_two q) 1)
{ "file_name": "vale/code/arch/Vale.Arch.Types.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 82, "end_line": 118, "start_col": 0, "start_line": 118 }
module Vale.Arch.Types open FStar.Mul open Vale.Def.Opaque_s open Vale.Def.Types_s open Vale.Lib.Seqs_s open Vale.Lib.Seqs open Vale.Def.Words_s open Vale.Def.Words.Four_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Seq open FStar.Seq open Vale.Def.Words.Two_s unfold let ( *^ ) = nat32_xor unfold let ( *^^ ) = quad32_xor unfold let add_wrap32 (x:nat32) (y:nat32) : nat32 = add_wrap x y unfold let add_wrap64 (x:nat64) (y:nat64) : nat64 = add_wrap x y unfold let sub_wrap32 (x:nat32) (y:nat32) : nat32 = sub_wrap x y unfold let sub_wrap64 (x:nat64) (y:nat64) : nat64 = sub_wrap x y unfold let iand32 (a:nat32) (b:nat32) : nat32 = iand a b unfold let ixor32 (a:nat32) (b:nat32) : nat32 = ixor a b unfold let ior32 (a:nat32) (b:nat32) : nat32 = ior a b unfold let inot32 (a:nat32) : nat32 = inot a unfold let ishl32 (a:nat32) (s:int) : nat32 = ishl a s unfold let ishr32 (a:nat32) (s:int) : nat32 = ishr a s unfold let iand64 (a:nat64) (b:nat64) : nat64 = iand a b unfold let ixor64 (a:nat64) (b:nat64) : nat64 = ixor a b unfold let ior64 (a:nat64) (b:nat64) : nat64 = ior a b unfold let inot64 (a:nat64) : nat64 = inot a unfold let ishl64 (a:nat64) (s:int) : nat64 = ishl a s unfold let ishr64 (a:nat64) (s:int) : nat64 = ishr a s unfold let iand128 (a:nat128) (b:nat128) : nat128 = iand a b unfold let ixor128 (a:nat128) (b:nat128) : nat128 = ixor a b unfold let ior128 (a:nat128) (b:nat128) : nat128 = ior a b unfold let inot128 (a:nat128) : nat128 = inot a unfold let ishl128 (a:nat128) (s:int) : nat128 = ishl a s unfold let ishr128 (a:nat128) (s:int) : nat128 = ishr a s unfold let two_to_nat32 (x:two nat32) : nat64 = two_to_nat 32 x val lemma_nat_to_two32 (_:unit) : Lemma (forall (x:nat64).{:pattern (nat_to_two 32 x)} nat_to_two 32 x == Mktwo (x % 0x100000000) (x / 0x100000000)) let quad32_shl32 (q:quad32) : quad32 = let Mkfour v0 v1 v2 v3 = q in Mkfour 0 v0 v1 v2 let add_wrap_quad32 (q0 q1:quad32) : quad32 = let open Vale.Def.Words_s in Mkfour (add_wrap q0.lo0 q1.lo0) (add_wrap q0.lo1 q1.lo1) (add_wrap q0.hi2 q1.hi2) (add_wrap q0.hi3 q1.hi3) val lemma_BitwiseXorCommutative (x y:nat32) : Lemma (x *^ y == y *^ x) val lemma_BitwiseXorWithZero (n:nat32) : Lemma (n *^ 0 == n) val lemma_BitwiseXorCancel (n:nat32) : Lemma (n *^ n == 0) val lemma_BitwiseXorCancel64 (n:nat64) : Lemma (ixor n n == 0) val lemma_BitwiseXorAssociative (x y z:nat32) : Lemma (x *^ (y *^ z) == (x *^ y) *^ z) val xor_lemmas (_:unit) : Lemma (ensures (forall (x y:nat32).{:pattern (x *^ y)} x *^ y == y *^ x) /\ (forall (n:nat32).{:pattern (n *^ 0)} n *^ 0 == n) /\ (forall (n:nat32).{:pattern (n *^ n)} n *^ n == 0) /\ (forall (n:nat64).{:pattern (ixor n n)} ixor n n == 0) /\ (forall (x y z:nat32).{:pattern (x *^ (y *^ z))} x *^ (y *^ z) == (x *^ y) *^ z) ) val lemma_quad32_xor (_:unit) : Lemma (forall q . {:pattern quad32_xor q q} quad32_xor q q == Mkfour 0 0 0 0) let quad32_double_lo (q:quad32) : double32 = (four_to_two_two q).lo let quad32_double_hi (q:quad32) : double32 = (four_to_two_two q).hi val lemma_reverse_reverse_bytes_nat32 (n:nat32) : Lemma (reverse_bytes_nat32 (reverse_bytes_nat32 n) == n) [SMTPat (reverse_bytes_nat32 (reverse_bytes_nat32 n))] val lemma_reverse_bytes_quad32 (q:quad32) : Lemma (reverse_bytes_quad32 (reverse_bytes_quad32 q) == q) [SMTPat (reverse_bytes_quad32 (reverse_bytes_quad32 q))] val lemma_reverse_bytes_quad32_zero (_:unit) : Lemma (let z = Mkfour 0 0 0 0 in reverse_bytes_quad32 z == z) val lemma_reverse_reverse_bytes_nat32_seq (s:seq nat32) : Lemma (reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s) == s) [SMTPat (reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s))] unfold let quad32_to_seq (q:quad32) : seq nat32 = four_to_seq_LE q val lemma_insert_nat64_properties (q:quad32) (n:nat64) : Lemma ( (let q' = insert_nat64 q n 0 in q'.hi2 == q.hi2 /\ q'.hi3 == q.hi3) /\ (let q' = insert_nat64 q n 1 in q'.lo0 == q.lo0 /\ q'.lo1 == q.lo1)) [SMTPat (insert_nat64 q n)] val lemma_insert_nat64_nat32s (q:quad32) (n0 n1:nat32) : Lemma ( insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 0 == Mkfour n0 n1 q.hi2 q.hi3 /\ insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 1 == Mkfour q.lo0 q.lo1 n0 n1 ) let lo64_def (q:quad32) : nat64 = two_to_nat 32 (two_select (four_to_two_two q) 0) [@"opaque_to_smt"] let lo64 = opaque_make lo64_def irreducible let lo64_reveal = opaque_revealer (`%lo64) lo64 lo64_def
{ "checked_file": "/", "dependencies": [ "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Two_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Seq.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.Arch.Types.fsti" }
[ { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
q: Vale.Def.Types_s.quad32 -> Vale.Def.Words_s.nat64
Prims.Tot
[ "total" ]
[]
[ "Vale.Def.Types_s.quad32", "Vale.Def.Words.Two_s.two_to_nat", "Vale.Def.Words.Two_s.two_select", "Vale.Def.Words_s.two", "Vale.Def.Types_s.nat32", "Vale.Def.Words.Four_s.four_to_two_two", "Vale.Def.Words_s.nat64" ]
[]
false
false
false
true
false
let hi64_def (q: quad32) : nat64 =
two_to_nat 32 (two_select (four_to_two_two q) 1)
false
Vale.Arch.Types.fsti
Vale.Arch.Types.lo64
val lo64 : _: Vale.Def.Types_s.quad32 -> Vale.Def.Words_s.nat64
let lo64 = opaque_make lo64_def
{ "file_name": "vale/code/arch/Vale.Arch.Types.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 50, "end_line": 115, "start_col": 19, "start_line": 115 }
module Vale.Arch.Types open FStar.Mul open Vale.Def.Opaque_s open Vale.Def.Types_s open Vale.Lib.Seqs_s open Vale.Lib.Seqs open Vale.Def.Words_s open Vale.Def.Words.Four_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Seq open FStar.Seq open Vale.Def.Words.Two_s unfold let ( *^ ) = nat32_xor unfold let ( *^^ ) = quad32_xor unfold let add_wrap32 (x:nat32) (y:nat32) : nat32 = add_wrap x y unfold let add_wrap64 (x:nat64) (y:nat64) : nat64 = add_wrap x y unfold let sub_wrap32 (x:nat32) (y:nat32) : nat32 = sub_wrap x y unfold let sub_wrap64 (x:nat64) (y:nat64) : nat64 = sub_wrap x y unfold let iand32 (a:nat32) (b:nat32) : nat32 = iand a b unfold let ixor32 (a:nat32) (b:nat32) : nat32 = ixor a b unfold let ior32 (a:nat32) (b:nat32) : nat32 = ior a b unfold let inot32 (a:nat32) : nat32 = inot a unfold let ishl32 (a:nat32) (s:int) : nat32 = ishl a s unfold let ishr32 (a:nat32) (s:int) : nat32 = ishr a s unfold let iand64 (a:nat64) (b:nat64) : nat64 = iand a b unfold let ixor64 (a:nat64) (b:nat64) : nat64 = ixor a b unfold let ior64 (a:nat64) (b:nat64) : nat64 = ior a b unfold let inot64 (a:nat64) : nat64 = inot a unfold let ishl64 (a:nat64) (s:int) : nat64 = ishl a s unfold let ishr64 (a:nat64) (s:int) : nat64 = ishr a s unfold let iand128 (a:nat128) (b:nat128) : nat128 = iand a b unfold let ixor128 (a:nat128) (b:nat128) : nat128 = ixor a b unfold let ior128 (a:nat128) (b:nat128) : nat128 = ior a b unfold let inot128 (a:nat128) : nat128 = inot a unfold let ishl128 (a:nat128) (s:int) : nat128 = ishl a s unfold let ishr128 (a:nat128) (s:int) : nat128 = ishr a s unfold let two_to_nat32 (x:two nat32) : nat64 = two_to_nat 32 x val lemma_nat_to_two32 (_:unit) : Lemma (forall (x:nat64).{:pattern (nat_to_two 32 x)} nat_to_two 32 x == Mktwo (x % 0x100000000) (x / 0x100000000)) let quad32_shl32 (q:quad32) : quad32 = let Mkfour v0 v1 v2 v3 = q in Mkfour 0 v0 v1 v2 let add_wrap_quad32 (q0 q1:quad32) : quad32 = let open Vale.Def.Words_s in Mkfour (add_wrap q0.lo0 q1.lo0) (add_wrap q0.lo1 q1.lo1) (add_wrap q0.hi2 q1.hi2) (add_wrap q0.hi3 q1.hi3) val lemma_BitwiseXorCommutative (x y:nat32) : Lemma (x *^ y == y *^ x) val lemma_BitwiseXorWithZero (n:nat32) : Lemma (n *^ 0 == n) val lemma_BitwiseXorCancel (n:nat32) : Lemma (n *^ n == 0) val lemma_BitwiseXorCancel64 (n:nat64) : Lemma (ixor n n == 0) val lemma_BitwiseXorAssociative (x y z:nat32) : Lemma (x *^ (y *^ z) == (x *^ y) *^ z) val xor_lemmas (_:unit) : Lemma (ensures (forall (x y:nat32).{:pattern (x *^ y)} x *^ y == y *^ x) /\ (forall (n:nat32).{:pattern (n *^ 0)} n *^ 0 == n) /\ (forall (n:nat32).{:pattern (n *^ n)} n *^ n == 0) /\ (forall (n:nat64).{:pattern (ixor n n)} ixor n n == 0) /\ (forall (x y z:nat32).{:pattern (x *^ (y *^ z))} x *^ (y *^ z) == (x *^ y) *^ z) ) val lemma_quad32_xor (_:unit) : Lemma (forall q . {:pattern quad32_xor q q} quad32_xor q q == Mkfour 0 0 0 0) let quad32_double_lo (q:quad32) : double32 = (four_to_two_two q).lo let quad32_double_hi (q:quad32) : double32 = (four_to_two_two q).hi val lemma_reverse_reverse_bytes_nat32 (n:nat32) : Lemma (reverse_bytes_nat32 (reverse_bytes_nat32 n) == n) [SMTPat (reverse_bytes_nat32 (reverse_bytes_nat32 n))] val lemma_reverse_bytes_quad32 (q:quad32) : Lemma (reverse_bytes_quad32 (reverse_bytes_quad32 q) == q) [SMTPat (reverse_bytes_quad32 (reverse_bytes_quad32 q))] val lemma_reverse_bytes_quad32_zero (_:unit) : Lemma (let z = Mkfour 0 0 0 0 in reverse_bytes_quad32 z == z) val lemma_reverse_reverse_bytes_nat32_seq (s:seq nat32) : Lemma (reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s) == s) [SMTPat (reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s))] unfold let quad32_to_seq (q:quad32) : seq nat32 = four_to_seq_LE q val lemma_insert_nat64_properties (q:quad32) (n:nat64) : Lemma ( (let q' = insert_nat64 q n 0 in q'.hi2 == q.hi2 /\ q'.hi3 == q.hi3) /\ (let q' = insert_nat64 q n 1 in q'.lo0 == q.lo0 /\ q'.lo1 == q.lo1)) [SMTPat (insert_nat64 q n)] val lemma_insert_nat64_nat32s (q:quad32) (n0 n1:nat32) : Lemma ( insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 0 == Mkfour n0 n1 q.hi2 q.hi3 /\ insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 1 == Mkfour q.lo0 q.lo1 n0 n1 )
{ "checked_file": "/", "dependencies": [ "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Two_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Seq.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.Arch.Types.fsti" }
[ { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
_: Vale.Def.Types_s.quad32 -> Vale.Def.Words_s.nat64
Prims.Tot
[ "total" ]
[]
[ "Vale.Def.Opaque_s.opaque_make", "Vale.Def.Types_s.quad32", "Vale.Def.Words_s.nat64", "Vale.Arch.Types.lo64_def" ]
[]
false
false
false
true
false
let lo64 =
opaque_make lo64_def
false
Steel.FractionalAnchoredPreorder.fst
Steel.FractionalAnchoredPreorder.anchored_snapshot
val anchored_snapshot (#v: Type0) (#p: preorder v) (#s: anchor_rel p) (a: avalue s {s (curval (avalue_val a)) (curval (avalue_val a))}) : avalue s & avalue s
val anchored_snapshot (#v: Type0) (#p: preorder v) (#s: anchor_rel p) (a: avalue s {s (curval (avalue_val a)) (curval (avalue_val a))}) : avalue s & avalue s
let anchored_snapshot (#v:Type0) (#p:preorder v) (#s:anchor_rel p) (a: avalue s { s (curval (avalue_val a)) (curval (avalue_val a)) }) : avalue s & avalue s = let (p,a0), v = a in let a = match a0 with | None -> Some (curval v) | Some a -> Some a in ((p, None), v), ((None, a), v)
{ "file_name": "lib/steel/Steel.FractionalAnchoredPreorder.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 18, "end_line": 609, "start_col": 0, "start_line": 599 }
(* Copyright 2021 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. Author: N. Swamy *) module Steel.FractionalAnchoredPreorder (** This module provides a partial commutative monoid (PCM) for use in the ghost state of a concurrent Steel program. Its goal is to facilitate a form of information-sharing between multiple threads including the following features: Fractions, Preorders, Snapshots, and Anchors --- Anchors are the most unusual. 1. Fractions: Ownership of the state is controlled by a fractional permission, so multiple threads may share read-only privileges on the state, but only one can have write permission. 2. Preorders: The ghost state is governed by a preorder p and all updates to the state must respect the preorder (a reflexive, transitive relation on the state) 3. Snapshots: Since the state always evolves by a preorder, it is possible to take a snapshot of the state. A snapshot does not confer any particular ownership on the state, except knowledge of a snapshot ensures that the current state is related to the snapshot by the preorder. 4. Anchors are a kind of refinement of the preorder. If a thread owns an anchored value [v], then no other thread, even a thread owning a full fractional permission, can advance the state "too far" from the anchor. In particular, the PCM is parameterized by a binary relation on values, [anchors:anchor_relation]. If a thread owns the anchor [v], then the current value `cur` of the state must be in relation [v `anchors` cur]. This can be used to ensure that the knowledge of one thread is never becomes too stale. For example, this allows one to model a shared monotonically increasing counter, where if one thread anchors knowledge of the counter at the value 5, no other thread can increase the value of the counter beyond, say, 10, (when the anchor relation is y - x <= 5), until the anchoring thread releases the anchor. Further, at any point, a thread can take a snapshot of the counter and rely on the fact that the value of the counter in the future will be >= the snapshot. *) open FStar.PCM open FStar.Preorder open Steel.Preorder open Steel.FractionalPermission #push-options "--fuel 0 --ifuel 2" /// A permission: is a pair of /// /// * an optional fractional permission; with `Some p` indicating /// some ownership, while `None` is an additional "0" permission /// value, to encode snapshots. /// /// * and an optional anchor, where `Some a` indicates the current /// value can't be too far from `a`. let permission (v:Type) = option perm & option v /// Non-zero permission is either a read or write permission let has_nonzero #v (p:permission v) = Some? (fst p) /// Has an anchor set let has_anchor #v (p:permission v) = Some? (snd p) /// Either an anchor or non-zero let has_some_ownership #v (p:permission v) = has_nonzero p || has_anchor p /// The anchoring value let anchor_of #v (p:permission v { has_anchor p }) : v = Some?.v (snd p) /// The anchoring relation: /// -- A binary relation on values /// -- refining the preorder /// -- and if x `anchors` z then it also anchors any `y` between `x` and `z` /// /// Explaining the third clause a bit: /// Think intuitively of anchoring relations as a kind of distance measure /// /// if `z` is close enough to `x` then if `z` is further than `y` /// (since it is ahead of `y` in the preorder) then `y` is also /// close enough to `x` let anchor_rel (#v:Type) (p:preorder v) = anchors:(v -> v -> prop) { (forall v0 v1. anchors v0 v1 ==> p v0 v1) /\ (forall x z. x `anchors` z ==> (forall y. p x y /\ p y z ==> x `anchors` y)) // } /// An implementation remark: We use Steel.Preorder here to /// generically transform any preorder into a PCM. That works by /// taking the value of the PCM to be a history of values related by /// the preorder. So, throughout, we'll be using the the [vhist p] /// from Steel.Preorder, the type of a non-empty history compatible /// with [p]. The details of the histories don't matter much for our /// purposes---we only care about the most recent value, for which /// we'll use [curval v]. /// If the anchor is set, then the current value is anchored by it let anchored (#v:Type) (#p:preorder v) (anchors:anchor_rel p) (pv:(permission v & vhist p)) = has_anchor (fst pv) ==> anchor_of (fst pv) `anchors` curval (snd pv) /// A value in our fractional anchored PCM is a pair of a permission /// and a p-compatible history, refined to ensure that if the anchor /// is set, then the current value is anchored by it. let avalue (#v:Type) (#p:preorder v) (anchors:anchor_rel p) = pv:(permission v & vhist p) { anchored anchors pv } /// initial_value: A utility to construct a value in the PCM #push-options "--fuel 1" let initial_value (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (value:v { anchors value value }) : avalue anchors = (Some full_perm, Some value), [value] #pop-options /// We add a unit element to [avalue], as needed for a PCM [@@erasable] noeq type knowledge (#v:Type) (#p:preorder v) (anchors:anchor_rel p) = | Owns : avalue anchors -> knowledge anchors | Nothing : knowledge anchors let b2p (b:bool) : prop = b == true /// Fractional permissions are composable when their sum <= 1.0 let perm_opt_composable (p0 p1:option perm) : prop = match p0, p1 with | None, None -> True | Some p, None | None, Some p -> b2p (p `lesser_equal_perm` full_perm) | Some p0, Some p1 -> b2p (sum_perm p0 p1 `lesser_equal_perm` full_perm) /// Composing them sums the permissions let compose_perm_opt (p0 p1:option perm) = match p0, p1 with | None, p | p, None -> p | Some p0, Some p1 -> Some (sum_perm p0 p1) /// Anchored permissions are composable when at most one of them has the anchor set let permission_composable #v (p0 p1 : permission v) : prop = let q0, s0 = p0 in let q1, s1 = p1 in perm_opt_composable q0 q1 /\ // some of fracs can't exceed 1 not (Some? s0 && Some? s1) // at most one can have an anchor /// Compose permissions component wise, keeping the anchor if set let compose_permissions (#v:_) (p0:permission v) (p1:permission v{permission_composable p0 p1}) : permission v = compose_perm_opt (fst p0) (fst p1), (match snd p0, snd p1 with | None, a | a, None -> a) /// This is the central definition of the PCM --- defining when two /// values are composable, or equivalently, when one thread's /// knowledge of [av0] is compatible with another thread's knowledge /// of [av1] /// /// This definition shows the interplay between fractions and anchors. /// It wasn't obvious to me how to factor this further, e.g., adding /// anchors to preorders and then separately adding fractions to it. let avalue_composable (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (av0 av1: avalue anchors) : prop = let (p0, v0) = av0 in let (p1, v1) = av1 in permission_composable p0 p1 /\ (if not (has_some_ownership p0) && not (has_some_ownership p1) then p_composable _ v0 v1 //neither has ownership, one history is older than the other else if not (has_some_ownership p0) && has_some_ownership p1 then ( if has_nonzero p1 then v1 `extends` v0 //the one with ownership is more recent else ( //this part is the most subtle assert (has_anchor p1); p_composable _ v0 v1 /\ (v0 `extends` v1 ==> //if v0 is a more recent snapshot than v1 //then v0 must still be anchored by v1's anchor anchor_of p1 `anchors` curval v0) ) ) else if has_some_ownership p0 && not (has_some_ownership p1) then ( //symmetric if has_nonzero p0 then v0 `extends` v1 else ( assert (has_anchor p0); p_composable _ v0 v1 /\ (v1 `extends` v0 ==> anchor_of p0 `anchors` curval v1) ) ) else ( assert (has_some_ownership p0 && has_some_ownership p1); if has_nonzero p0 && has_nonzero p1 then v0 == v1 //if both have non-zero perm, then they must both only have read permission and must agree on the value else if has_nonzero p0 && has_anchor p1 then ( assert (not (has_nonzero p1)); //The key part of the anchor semantics: v0 `extends` v1 /\ //v0 has advanceable ownership, so extends anchor_of p1 `anchors` curval v0 //but not beyond what is allowed by s ) else if has_anchor p0 && has_nonzero p1 //symmetric then ( assert (not (has_nonzero p0)); v1 `extends` v0 /\ anchor_of p0 `anchors` curval v1 //v1 extends, but not beyond what is allowed by s ) else (assert false; False) ) ) //exhaustive /// Lifting avalue comosability to knowledge, including the unit let composable #v (#p:preorder v) (#a:anchor_rel p) : symrel (knowledge a) = fun (k0 k1:knowledge a) -> match k0, k1 with | Nothing, _ | _, Nothing -> True | Owns m, Owns m' -> avalue_composable m m' /// Compose avalues by composing permissions and composing the values /// using the underlying preorder PCM let compose_avalue (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (m0:avalue anchors) (m1:avalue anchors { avalue_composable m0 m1 } ) : avalue anchors = let p0, v0 = m0 in let p1, v1 = m1 in let p12 = compose_permissions p0 p1 in let v12 = p_op _ v0 v1 in p12, v12 //////////////////////////////////////////////////////////////////////////////// (** avalue composition is associative and commutative **) let compose_avalue_comm (#v:Type) (#p:preorder v) (#anc:anchor_rel p) (m0: avalue anc) (m1: avalue anc{ avalue_composable m0 m1 }) : Lemma (compose_avalue m0 m1 == compose_avalue m1 m0) = () let avalue_composable_assoc_l (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (m0: avalue anchors) (m1: avalue anchors) (m2: avalue anchors { avalue_composable m1 m2 /\ avalue_composable m0 (compose_avalue m1 m2) }) : Lemma (avalue_composable m0 m1 /\ avalue_composable (compose_avalue m0 m1) m2) = () let compose_avalue_assoc_l (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m0: avalue s) (m1: avalue s) (m2: avalue s { avalue_composable m1 m2 /\ avalue_composable m0 (compose_avalue m1 m2) }) : Lemma (avalue_composable m0 m1 /\ avalue_composable (compose_avalue m0 m1) m2 /\ compose_avalue m0 (compose_avalue m1 m2) == compose_avalue (compose_avalue m0 m1) m2) = avalue_composable_assoc_l m0 m1 m2 let avalue_composable_assoc_r (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (m0: avalue anchors) (m1: avalue anchors) (m2: avalue anchors { avalue_composable m0 m1 /\ avalue_composable (compose_avalue m0 m1) m2 }) : Lemma (avalue_composable m1 m2 /\ avalue_composable m0 (compose_avalue m1 m2)) = () let compose_avalue_assoc_r (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m0: avalue s) (m1: avalue s) (m2: avalue s{ avalue_composable m0 m1 /\ avalue_composable (compose_avalue m0 m1) m2 }) : Lemma (avalue_composable m1 m2 /\ avalue_composable m0 (compose_avalue m1 m2) /\ compose_avalue m0 (compose_avalue m1 m2) == compose_avalue (compose_avalue m0 m1) m2) = avalue_composable_assoc_r m0 m1 m2 //////////////////////////////////////////////////////////////////////////////// /// lifting avalue composition to knowledge, including unit let compose (#v:Type) (#p:preorder v) (#s:anchor_rel p) (k0:knowledge s) (k1:knowledge s{ composable k0 k1 }) : knowledge s = match k0, k1 with | Nothing, k | k, Nothing -> k | Owns m, Owns m' -> Owns (compose_avalue m m') let composable_assoc_r #v (#p:preorder v) (#s:anchor_rel p) (k0 k1 k2: knowledge s) : Lemma (requires composable k0 k1 /\ composable (compose k0 k1) k2) (ensures composable k1 k2 /\ composable k0 (compose k1 k2) /\ compose k0 (compose k1 k2) == compose (compose k0 k1) k2 ) = match k0, k1, k2 with | Nothing, _, _ | _, Nothing, _ | _, _, Nothing -> () | Owns m0, Owns m1, Owns m2 -> compose_avalue_assoc_r m0 m1 m2 let composable_assoc_l #v (#p:preorder v) (#s:anchor_rel p) (k0 k1 k2: knowledge s) : Lemma (requires composable k1 k2 /\ composable k0 (compose k1 k2)) (ensures composable k0 k1 /\ composable (compose k0 k1) k2 /\ compose k0 (compose k1 k2) == compose (compose k0 k1) k2) = match k0, k1, k2 with | Nothing, _, _ | _, Nothing, _ | _, _, Nothing -> () | Owns m0, Owns m1, Owns m2 -> compose_avalue_assoc_l m0 m1 m2 /// Now, we can define our PCM /// The core of the PCM let p0 #v #p #s : pcm' (knowledge #v #p s) = { composable; op=compose; one=Nothing } let avalue_perm (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) = fst m /// A avalue represents full ownership when the fraction is full AND /// the anchor is set. This means that no knowledge held by any other /// thread can constrain this value meaningfully. let avalue_owns (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) : prop = fst (avalue_perm m) == Some full_perm /\ Some? (snd (avalue_perm m)) let full_knowledge #v #p #s (kn:knowledge #v #p s) : prop = match kn with | Nothing -> False | Owns km -> avalue_owns km /// The PCM itself, together with proofs of its properties let pcm #v #p #s : pcm (knowledge #v #p s) = { p = p0; comm = (fun k0 k1 -> match k0, k1 with | Nothing, _ | _, Nothing -> () | Owns m0, Owns m1 -> compose_avalue_comm m0 m1); assoc = (fun k0 k1 k2 -> composable_assoc_l k0 k1 k2); assoc_r = (fun k0 k1 k2 -> composable_assoc_r k0 k1 k2); is_unit = (fun _ -> ()); refine = full_knowledge; } /// Some utilities: The value of an avalue let avalue_val (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue #v #p s) = snd m /// Updating the value, in a full-ownership situation, also involves /// updating the anchor let avalue_update (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) (value:vhist p { s (curval value) (curval value) }) : avalue s = let p, _ = avalue_perm m in let p' = p, Some (curval value) in (p', value) /// Our core frame-preserving update: /// /// If you fully own a value, you can update it so long as you /// respect the preorder, and prove that the new value is related /// to itself by the anchor (since we'll be setting the anchor to /// the new value) /// /// This is a building block: we'll define a derived version that /// on values rather than histories #push-options "--z3rlimit_factor 2" let update_hist (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) (v1:vhist p { avalue_owns m /\ v1 `extends` avalue_val m /\ s (curval v1) (curval v1) }) : frame_preserving_upd pcm (Owns m) (Owns (avalue_update m v1)) = fun full_v -> let Owns full_m = full_v in let m_res = avalue_update full_m v1 in Owns m_res #pop-options /// Updating with value, rather than a history let avalue_update_value (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) (value:v { curval (avalue_val m) `p` value /\ s value value }) : m':avalue s { curval (avalue_val m') == value /\ avalue_val m' `extends` avalue_val m } = let v = avalue_val m in avalue_update m (extend_history v value) /// A derived frame-preserving update for which one presents only a value let update_value (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) (v1:v { avalue_owns m /\ //if you have full ownership of key curval (avalue_val m) `p` v1 /\ //you can update it wrt the preorder only s v1 v1 //and it is related to itself by the anchor }) : frame_preserving_upd pcm (Owns m) (Owns (avalue_update_value m v1)) = coerce_eq () (update_hist m (extend_history (avalue_val m) v1)) //F* goes nuts and starts swallowing gobs of memory without the coerce_eq: TODO, debug /// Now for anchored updates /// Ownership of the whole fraction, but not the anchor let avalue_owns_anchored (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) = fst (avalue_perm m) == Some full_perm /\ None? (snd (avalue_perm m)) /// [v1] is compatible with (i.e., not too far from) any anchor of [v0] let compat_with_any_anchor_of (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (v1:v) (v0:avalue anchors) = forall (anchor:v). anchor `anchors` curval (avalue_val v0) ==> anchor `anchors` v1 /// An anchored update: Update the value, but leave the permission /// unchanged Only possible if the new value is compatible with any /// anchor of the old value let avalue_anchored_update (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) (value:vhist p { curval value `compat_with_any_anchor_of` m }) : avalue s = avalue_perm m, value /// A frame-preserving update for anchored values. /// Notice the additional precondition, refining the preorder let update_anchored_hist (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) (v1:vhist p { avalue_owns_anchored m /\ v1 `extends` avalue_val m /\ curval v1 `compat_with_any_anchor_of` m }) : frame_preserving_upd pcm (Owns m) (Owns (avalue_anchored_update m v1)) = fun full_v -> let Owns full_m = full_v in let m_res = avalue_anchored_update full_m v1 in Owns m_res /// A derived form without a history on the new value let avalue_update_anchored_value (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) (value:v { curval (avalue_val m) `p` value /\ value `compat_with_any_anchor_of` m }) : m':avalue s { curval (avalue_val m') == value /\ avalue_val m' `extends` avalue_val m } = let v = avalue_val m in avalue_anchored_update m (extend_history v value) /// Derived frame-preserving update let update_anchored_value (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) (v1:v { avalue_owns_anchored m /\ //if you own an anchored key, you can update if you respect curval (avalue_val m) `p` v1 /\ //the preorder v1 `compat_with_any_anchor_of` m //and respect any anchor of the current value }) : frame_preserving_upd pcm (Owns m) (Owns (avalue_update_anchored_value m v1)) = coerce_eq () (update_anchored_hist m (extend_history (avalue_val m) v1)) //////////////////////////////////////////////////////////////////////////////// /// Now for some lemmas about which kinds of knowledge are compatible /// with others and about snapshots /// A [snapshot] keeps the value, dropping all permissions let snapshot (#v:Type0) (#p:preorder v) (#s:anchor_rel p) (a: avalue s) : avalue s = (None, None), avalue_val a let perm_ok #v #p #s (a:avalue #v #p s) = perm_opt_composable (fst (avalue_perm a)) None /// You can take a snapshot of any knowledge /// - perm_ok is a side-condition. Any vprop defined on top of this /// will ensure that the permissions are always <= 1.0 let snapshot_lemma (#v:Type) (#p:preorder v) (#s:anchor_rel p) (a:avalue s) : Lemma (requires perm_ok a) (ensures Owns a `composable` Owns (snapshot a)) = () /// A snapshot is duplicable let snapshot_dup_lemma (#v:Type) (#p:preorder v) (#s:anchor_rel p) (a:avalue s) : Lemma (ensures Owns (snapshot a) `composable` Owns (snapshot a)) = () /// An anchored snapshot takes the current value, drops the fraction /// but keeps the anchor or takes the current value as the anchor, if
{ "checked_file": "/", "dependencies": [ "Steel.Preorder.fst.checked", "Steel.FractionalPermission.fst.checked", "prims.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked" ], "interface_file": false, "source_file": "Steel.FractionalAnchoredPreorder.fst" }
[ { "abbrev": false, "full_module": "Steel.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Steel.Preorder", "short_module": null }, { "abbrev": false, "full_module": "FStar.Preorder", "short_module": null }, { "abbrev": false, "full_module": "FStar.PCM", "short_module": null }, { "abbrev": false, "full_module": "Steel", "short_module": null }, { "abbrev": false, "full_module": "Steel", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Steel.FractionalAnchoredPreorder.avalue s { s (Steel.Preorder.curval (Steel.FractionalAnchoredPreorder.avalue_val a)) (Steel.Preorder.curval (Steel.FractionalAnchoredPreorder.avalue_val a)) } -> Steel.FractionalAnchoredPreorder.avalue s * Steel.FractionalAnchoredPreorder.avalue s
Prims.Tot
[ "total" ]
[]
[ "FStar.Preorder.preorder", "Steel.FractionalAnchoredPreorder.anchor_rel", "Steel.FractionalAnchoredPreorder.avalue", "Steel.Preorder.curval", "Steel.FractionalAnchoredPreorder.avalue_val", "FStar.Pervasives.Native.option", "Steel.FractionalPermission.perm", "Steel.Preorder.vhist", "FStar.Pervasives.Native.Mktuple2", "Steel.FractionalAnchoredPreorder.permission", "FStar.Pervasives.Native.None", "FStar.Pervasives.Native.Some", "FStar.Pervasives.Native.tuple2" ]
[]
false
false
false
false
false
let anchored_snapshot (#v: Type0) (#p: preorder v) (#s: anchor_rel p) (a: avalue s {s (curval (avalue_val a)) (curval (avalue_val a))}) : avalue s & avalue s =
let (p, a0), v = a in let a = match a0 with | None -> Some (curval v) | Some a -> Some a in ((p, None), v), ((None, a), v)
false
Vale.Arch.Types.fsti
Vale.Arch.Types.hi64_reveal
val hi64_reveal : _: Prims.unit -> FStar.Pervasives.Lemma (ensures Vale.Arch.Types.hi64 == Vale.Arch.Types.hi64_def)
let hi64_reveal = opaque_revealer (`%hi64) hi64 hi64_def
{ "file_name": "vale/code/arch/Vale.Arch.Types.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 68, "end_line": 120, "start_col": 12, "start_line": 120 }
module Vale.Arch.Types open FStar.Mul open Vale.Def.Opaque_s open Vale.Def.Types_s open Vale.Lib.Seqs_s open Vale.Lib.Seqs open Vale.Def.Words_s open Vale.Def.Words.Four_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Seq open FStar.Seq open Vale.Def.Words.Two_s unfold let ( *^ ) = nat32_xor unfold let ( *^^ ) = quad32_xor unfold let add_wrap32 (x:nat32) (y:nat32) : nat32 = add_wrap x y unfold let add_wrap64 (x:nat64) (y:nat64) : nat64 = add_wrap x y unfold let sub_wrap32 (x:nat32) (y:nat32) : nat32 = sub_wrap x y unfold let sub_wrap64 (x:nat64) (y:nat64) : nat64 = sub_wrap x y unfold let iand32 (a:nat32) (b:nat32) : nat32 = iand a b unfold let ixor32 (a:nat32) (b:nat32) : nat32 = ixor a b unfold let ior32 (a:nat32) (b:nat32) : nat32 = ior a b unfold let inot32 (a:nat32) : nat32 = inot a unfold let ishl32 (a:nat32) (s:int) : nat32 = ishl a s unfold let ishr32 (a:nat32) (s:int) : nat32 = ishr a s unfold let iand64 (a:nat64) (b:nat64) : nat64 = iand a b unfold let ixor64 (a:nat64) (b:nat64) : nat64 = ixor a b unfold let ior64 (a:nat64) (b:nat64) : nat64 = ior a b unfold let inot64 (a:nat64) : nat64 = inot a unfold let ishl64 (a:nat64) (s:int) : nat64 = ishl a s unfold let ishr64 (a:nat64) (s:int) : nat64 = ishr a s unfold let iand128 (a:nat128) (b:nat128) : nat128 = iand a b unfold let ixor128 (a:nat128) (b:nat128) : nat128 = ixor a b unfold let ior128 (a:nat128) (b:nat128) : nat128 = ior a b unfold let inot128 (a:nat128) : nat128 = inot a unfold let ishl128 (a:nat128) (s:int) : nat128 = ishl a s unfold let ishr128 (a:nat128) (s:int) : nat128 = ishr a s unfold let two_to_nat32 (x:two nat32) : nat64 = two_to_nat 32 x val lemma_nat_to_two32 (_:unit) : Lemma (forall (x:nat64).{:pattern (nat_to_two 32 x)} nat_to_two 32 x == Mktwo (x % 0x100000000) (x / 0x100000000)) let quad32_shl32 (q:quad32) : quad32 = let Mkfour v0 v1 v2 v3 = q in Mkfour 0 v0 v1 v2 let add_wrap_quad32 (q0 q1:quad32) : quad32 = let open Vale.Def.Words_s in Mkfour (add_wrap q0.lo0 q1.lo0) (add_wrap q0.lo1 q1.lo1) (add_wrap q0.hi2 q1.hi2) (add_wrap q0.hi3 q1.hi3) val lemma_BitwiseXorCommutative (x y:nat32) : Lemma (x *^ y == y *^ x) val lemma_BitwiseXorWithZero (n:nat32) : Lemma (n *^ 0 == n) val lemma_BitwiseXorCancel (n:nat32) : Lemma (n *^ n == 0) val lemma_BitwiseXorCancel64 (n:nat64) : Lemma (ixor n n == 0) val lemma_BitwiseXorAssociative (x y z:nat32) : Lemma (x *^ (y *^ z) == (x *^ y) *^ z) val xor_lemmas (_:unit) : Lemma (ensures (forall (x y:nat32).{:pattern (x *^ y)} x *^ y == y *^ x) /\ (forall (n:nat32).{:pattern (n *^ 0)} n *^ 0 == n) /\ (forall (n:nat32).{:pattern (n *^ n)} n *^ n == 0) /\ (forall (n:nat64).{:pattern (ixor n n)} ixor n n == 0) /\ (forall (x y z:nat32).{:pattern (x *^ (y *^ z))} x *^ (y *^ z) == (x *^ y) *^ z) ) val lemma_quad32_xor (_:unit) : Lemma (forall q . {:pattern quad32_xor q q} quad32_xor q q == Mkfour 0 0 0 0) let quad32_double_lo (q:quad32) : double32 = (four_to_two_two q).lo let quad32_double_hi (q:quad32) : double32 = (four_to_two_two q).hi val lemma_reverse_reverse_bytes_nat32 (n:nat32) : Lemma (reverse_bytes_nat32 (reverse_bytes_nat32 n) == n) [SMTPat (reverse_bytes_nat32 (reverse_bytes_nat32 n))] val lemma_reverse_bytes_quad32 (q:quad32) : Lemma (reverse_bytes_quad32 (reverse_bytes_quad32 q) == q) [SMTPat (reverse_bytes_quad32 (reverse_bytes_quad32 q))] val lemma_reverse_bytes_quad32_zero (_:unit) : Lemma (let z = Mkfour 0 0 0 0 in reverse_bytes_quad32 z == z) val lemma_reverse_reverse_bytes_nat32_seq (s:seq nat32) : Lemma (reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s) == s) [SMTPat (reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s))] unfold let quad32_to_seq (q:quad32) : seq nat32 = four_to_seq_LE q val lemma_insert_nat64_properties (q:quad32) (n:nat64) : Lemma ( (let q' = insert_nat64 q n 0 in q'.hi2 == q.hi2 /\ q'.hi3 == q.hi3) /\ (let q' = insert_nat64 q n 1 in q'.lo0 == q.lo0 /\ q'.lo1 == q.lo1)) [SMTPat (insert_nat64 q n)] val lemma_insert_nat64_nat32s (q:quad32) (n0 n1:nat32) : Lemma ( insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 0 == Mkfour n0 n1 q.hi2 q.hi3 /\ insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 1 == Mkfour q.lo0 q.lo1 n0 n1 ) let lo64_def (q:quad32) : nat64 = two_to_nat 32 (two_select (four_to_two_two q) 0) [@"opaque_to_smt"] let lo64 = opaque_make lo64_def irreducible let lo64_reveal = opaque_revealer (`%lo64) lo64 lo64_def let hi64_def (q:quad32) : nat64 = two_to_nat 32 (two_select (four_to_two_two q) 1)
{ "checked_file": "/", "dependencies": [ "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Two_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Seq.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.Arch.Types.fsti" }
[ { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
_: Prims.unit -> FStar.Pervasives.Lemma (ensures Vale.Arch.Types.hi64 == Vale.Arch.Types.hi64_def)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.Def.Opaque_s.opaque_revealer", "Vale.Def.Types_s.quad32", "Vale.Def.Words_s.nat64", "Vale.Arch.Types.hi64", "Vale.Arch.Types.hi64_def" ]
[]
true
false
true
false
false
let hi64_reveal =
opaque_revealer (`%hi64) hi64 hi64_def
false
Vale.Arch.Types.fsti
Vale.Arch.Types.lo64_reveal
val lo64_reveal : _: Prims.unit -> FStar.Pervasives.Lemma (ensures Vale.Arch.Types.lo64 == Vale.Arch.Types.lo64_def)
let lo64_reveal = opaque_revealer (`%lo64) lo64 lo64_def
{ "file_name": "vale/code/arch/Vale.Arch.Types.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 68, "end_line": 116, "start_col": 12, "start_line": 116 }
module Vale.Arch.Types open FStar.Mul open Vale.Def.Opaque_s open Vale.Def.Types_s open Vale.Lib.Seqs_s open Vale.Lib.Seqs open Vale.Def.Words_s open Vale.Def.Words.Four_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Seq open FStar.Seq open Vale.Def.Words.Two_s unfold let ( *^ ) = nat32_xor unfold let ( *^^ ) = quad32_xor unfold let add_wrap32 (x:nat32) (y:nat32) : nat32 = add_wrap x y unfold let add_wrap64 (x:nat64) (y:nat64) : nat64 = add_wrap x y unfold let sub_wrap32 (x:nat32) (y:nat32) : nat32 = sub_wrap x y unfold let sub_wrap64 (x:nat64) (y:nat64) : nat64 = sub_wrap x y unfold let iand32 (a:nat32) (b:nat32) : nat32 = iand a b unfold let ixor32 (a:nat32) (b:nat32) : nat32 = ixor a b unfold let ior32 (a:nat32) (b:nat32) : nat32 = ior a b unfold let inot32 (a:nat32) : nat32 = inot a unfold let ishl32 (a:nat32) (s:int) : nat32 = ishl a s unfold let ishr32 (a:nat32) (s:int) : nat32 = ishr a s unfold let iand64 (a:nat64) (b:nat64) : nat64 = iand a b unfold let ixor64 (a:nat64) (b:nat64) : nat64 = ixor a b unfold let ior64 (a:nat64) (b:nat64) : nat64 = ior a b unfold let inot64 (a:nat64) : nat64 = inot a unfold let ishl64 (a:nat64) (s:int) : nat64 = ishl a s unfold let ishr64 (a:nat64) (s:int) : nat64 = ishr a s unfold let iand128 (a:nat128) (b:nat128) : nat128 = iand a b unfold let ixor128 (a:nat128) (b:nat128) : nat128 = ixor a b unfold let ior128 (a:nat128) (b:nat128) : nat128 = ior a b unfold let inot128 (a:nat128) : nat128 = inot a unfold let ishl128 (a:nat128) (s:int) : nat128 = ishl a s unfold let ishr128 (a:nat128) (s:int) : nat128 = ishr a s unfold let two_to_nat32 (x:two nat32) : nat64 = two_to_nat 32 x val lemma_nat_to_two32 (_:unit) : Lemma (forall (x:nat64).{:pattern (nat_to_two 32 x)} nat_to_two 32 x == Mktwo (x % 0x100000000) (x / 0x100000000)) let quad32_shl32 (q:quad32) : quad32 = let Mkfour v0 v1 v2 v3 = q in Mkfour 0 v0 v1 v2 let add_wrap_quad32 (q0 q1:quad32) : quad32 = let open Vale.Def.Words_s in Mkfour (add_wrap q0.lo0 q1.lo0) (add_wrap q0.lo1 q1.lo1) (add_wrap q0.hi2 q1.hi2) (add_wrap q0.hi3 q1.hi3) val lemma_BitwiseXorCommutative (x y:nat32) : Lemma (x *^ y == y *^ x) val lemma_BitwiseXorWithZero (n:nat32) : Lemma (n *^ 0 == n) val lemma_BitwiseXorCancel (n:nat32) : Lemma (n *^ n == 0) val lemma_BitwiseXorCancel64 (n:nat64) : Lemma (ixor n n == 0) val lemma_BitwiseXorAssociative (x y z:nat32) : Lemma (x *^ (y *^ z) == (x *^ y) *^ z) val xor_lemmas (_:unit) : Lemma (ensures (forall (x y:nat32).{:pattern (x *^ y)} x *^ y == y *^ x) /\ (forall (n:nat32).{:pattern (n *^ 0)} n *^ 0 == n) /\ (forall (n:nat32).{:pattern (n *^ n)} n *^ n == 0) /\ (forall (n:nat64).{:pattern (ixor n n)} ixor n n == 0) /\ (forall (x y z:nat32).{:pattern (x *^ (y *^ z))} x *^ (y *^ z) == (x *^ y) *^ z) ) val lemma_quad32_xor (_:unit) : Lemma (forall q . {:pattern quad32_xor q q} quad32_xor q q == Mkfour 0 0 0 0) let quad32_double_lo (q:quad32) : double32 = (four_to_two_two q).lo let quad32_double_hi (q:quad32) : double32 = (four_to_two_two q).hi val lemma_reverse_reverse_bytes_nat32 (n:nat32) : Lemma (reverse_bytes_nat32 (reverse_bytes_nat32 n) == n) [SMTPat (reverse_bytes_nat32 (reverse_bytes_nat32 n))] val lemma_reverse_bytes_quad32 (q:quad32) : Lemma (reverse_bytes_quad32 (reverse_bytes_quad32 q) == q) [SMTPat (reverse_bytes_quad32 (reverse_bytes_quad32 q))] val lemma_reverse_bytes_quad32_zero (_:unit) : Lemma (let z = Mkfour 0 0 0 0 in reverse_bytes_quad32 z == z) val lemma_reverse_reverse_bytes_nat32_seq (s:seq nat32) : Lemma (reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s) == s) [SMTPat (reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s))] unfold let quad32_to_seq (q:quad32) : seq nat32 = four_to_seq_LE q val lemma_insert_nat64_properties (q:quad32) (n:nat64) : Lemma ( (let q' = insert_nat64 q n 0 in q'.hi2 == q.hi2 /\ q'.hi3 == q.hi3) /\ (let q' = insert_nat64 q n 1 in q'.lo0 == q.lo0 /\ q'.lo1 == q.lo1)) [SMTPat (insert_nat64 q n)] val lemma_insert_nat64_nat32s (q:quad32) (n0 n1:nat32) : Lemma ( insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 0 == Mkfour n0 n1 q.hi2 q.hi3 /\ insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 1 == Mkfour q.lo0 q.lo1 n0 n1 ) let lo64_def (q:quad32) : nat64 = two_to_nat 32 (two_select (four_to_two_two q) 0)
{ "checked_file": "/", "dependencies": [ "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Two_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Seq.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.Arch.Types.fsti" }
[ { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
_: Prims.unit -> FStar.Pervasives.Lemma (ensures Vale.Arch.Types.lo64 == Vale.Arch.Types.lo64_def)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.Def.Opaque_s.opaque_revealer", "Vale.Def.Types_s.quad32", "Vale.Def.Words_s.nat64", "Vale.Arch.Types.lo64", "Vale.Arch.Types.lo64_def" ]
[]
true
false
true
false
false
let lo64_reveal =
opaque_revealer (`%lo64) lo64 lo64_def
false
Vale.Arch.Types.fsti
Vale.Arch.Types.lo64_def
val lo64_def (q: quad32) : nat64
val lo64_def (q: quad32) : nat64
let lo64_def (q:quad32) : nat64 = two_to_nat 32 (two_select (four_to_two_two q) 0)
{ "file_name": "vale/code/arch/Vale.Arch.Types.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 82, "end_line": 114, "start_col": 0, "start_line": 114 }
module Vale.Arch.Types open FStar.Mul open Vale.Def.Opaque_s open Vale.Def.Types_s open Vale.Lib.Seqs_s open Vale.Lib.Seqs open Vale.Def.Words_s open Vale.Def.Words.Four_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Seq open FStar.Seq open Vale.Def.Words.Two_s unfold let ( *^ ) = nat32_xor unfold let ( *^^ ) = quad32_xor unfold let add_wrap32 (x:nat32) (y:nat32) : nat32 = add_wrap x y unfold let add_wrap64 (x:nat64) (y:nat64) : nat64 = add_wrap x y unfold let sub_wrap32 (x:nat32) (y:nat32) : nat32 = sub_wrap x y unfold let sub_wrap64 (x:nat64) (y:nat64) : nat64 = sub_wrap x y unfold let iand32 (a:nat32) (b:nat32) : nat32 = iand a b unfold let ixor32 (a:nat32) (b:nat32) : nat32 = ixor a b unfold let ior32 (a:nat32) (b:nat32) : nat32 = ior a b unfold let inot32 (a:nat32) : nat32 = inot a unfold let ishl32 (a:nat32) (s:int) : nat32 = ishl a s unfold let ishr32 (a:nat32) (s:int) : nat32 = ishr a s unfold let iand64 (a:nat64) (b:nat64) : nat64 = iand a b unfold let ixor64 (a:nat64) (b:nat64) : nat64 = ixor a b unfold let ior64 (a:nat64) (b:nat64) : nat64 = ior a b unfold let inot64 (a:nat64) : nat64 = inot a unfold let ishl64 (a:nat64) (s:int) : nat64 = ishl a s unfold let ishr64 (a:nat64) (s:int) : nat64 = ishr a s unfold let iand128 (a:nat128) (b:nat128) : nat128 = iand a b unfold let ixor128 (a:nat128) (b:nat128) : nat128 = ixor a b unfold let ior128 (a:nat128) (b:nat128) : nat128 = ior a b unfold let inot128 (a:nat128) : nat128 = inot a unfold let ishl128 (a:nat128) (s:int) : nat128 = ishl a s unfold let ishr128 (a:nat128) (s:int) : nat128 = ishr a s unfold let two_to_nat32 (x:two nat32) : nat64 = two_to_nat 32 x val lemma_nat_to_two32 (_:unit) : Lemma (forall (x:nat64).{:pattern (nat_to_two 32 x)} nat_to_two 32 x == Mktwo (x % 0x100000000) (x / 0x100000000)) let quad32_shl32 (q:quad32) : quad32 = let Mkfour v0 v1 v2 v3 = q in Mkfour 0 v0 v1 v2 let add_wrap_quad32 (q0 q1:quad32) : quad32 = let open Vale.Def.Words_s in Mkfour (add_wrap q0.lo0 q1.lo0) (add_wrap q0.lo1 q1.lo1) (add_wrap q0.hi2 q1.hi2) (add_wrap q0.hi3 q1.hi3) val lemma_BitwiseXorCommutative (x y:nat32) : Lemma (x *^ y == y *^ x) val lemma_BitwiseXorWithZero (n:nat32) : Lemma (n *^ 0 == n) val lemma_BitwiseXorCancel (n:nat32) : Lemma (n *^ n == 0) val lemma_BitwiseXorCancel64 (n:nat64) : Lemma (ixor n n == 0) val lemma_BitwiseXorAssociative (x y z:nat32) : Lemma (x *^ (y *^ z) == (x *^ y) *^ z) val xor_lemmas (_:unit) : Lemma (ensures (forall (x y:nat32).{:pattern (x *^ y)} x *^ y == y *^ x) /\ (forall (n:nat32).{:pattern (n *^ 0)} n *^ 0 == n) /\ (forall (n:nat32).{:pattern (n *^ n)} n *^ n == 0) /\ (forall (n:nat64).{:pattern (ixor n n)} ixor n n == 0) /\ (forall (x y z:nat32).{:pattern (x *^ (y *^ z))} x *^ (y *^ z) == (x *^ y) *^ z) ) val lemma_quad32_xor (_:unit) : Lemma (forall q . {:pattern quad32_xor q q} quad32_xor q q == Mkfour 0 0 0 0) let quad32_double_lo (q:quad32) : double32 = (four_to_two_two q).lo let quad32_double_hi (q:quad32) : double32 = (four_to_two_two q).hi val lemma_reverse_reverse_bytes_nat32 (n:nat32) : Lemma (reverse_bytes_nat32 (reverse_bytes_nat32 n) == n) [SMTPat (reverse_bytes_nat32 (reverse_bytes_nat32 n))] val lemma_reverse_bytes_quad32 (q:quad32) : Lemma (reverse_bytes_quad32 (reverse_bytes_quad32 q) == q) [SMTPat (reverse_bytes_quad32 (reverse_bytes_quad32 q))] val lemma_reverse_bytes_quad32_zero (_:unit) : Lemma (let z = Mkfour 0 0 0 0 in reverse_bytes_quad32 z == z) val lemma_reverse_reverse_bytes_nat32_seq (s:seq nat32) : Lemma (reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s) == s) [SMTPat (reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s))] unfold let quad32_to_seq (q:quad32) : seq nat32 = four_to_seq_LE q val lemma_insert_nat64_properties (q:quad32) (n:nat64) : Lemma ( (let q' = insert_nat64 q n 0 in q'.hi2 == q.hi2 /\ q'.hi3 == q.hi3) /\ (let q' = insert_nat64 q n 1 in q'.lo0 == q.lo0 /\ q'.lo1 == q.lo1)) [SMTPat (insert_nat64 q n)] val lemma_insert_nat64_nat32s (q:quad32) (n0 n1:nat32) : Lemma ( insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 0 == Mkfour n0 n1 q.hi2 q.hi3 /\ insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 1 == Mkfour q.lo0 q.lo1 n0 n1 )
{ "checked_file": "/", "dependencies": [ "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Two_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Seq.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.Arch.Types.fsti" }
[ { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
q: Vale.Def.Types_s.quad32 -> Vale.Def.Words_s.nat64
Prims.Tot
[ "total" ]
[]
[ "Vale.Def.Types_s.quad32", "Vale.Def.Words.Two_s.two_to_nat", "Vale.Def.Words.Two_s.two_select", "Vale.Def.Words_s.two", "Vale.Def.Types_s.nat32", "Vale.Def.Words.Four_s.four_to_two_two", "Vale.Def.Words_s.nat64" ]
[]
false
false
false
true
false
let lo64_def (q: quad32) : nat64 =
two_to_nat 32 (two_select (four_to_two_two q) 0)
false
Vale.Arch.Types.fsti
Vale.Arch.Types.two_to_nat32
val two_to_nat32 (x: two nat32) : nat64
val two_to_nat32 (x: two nat32) : nat64
let two_to_nat32 (x:two nat32) : nat64 = two_to_nat 32 x
{ "file_name": "vale/code/arch/Vale.Arch.Types.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 63, "end_line": 44, "start_col": 7, "start_line": 44 }
module Vale.Arch.Types open FStar.Mul open Vale.Def.Opaque_s open Vale.Def.Types_s open Vale.Lib.Seqs_s open Vale.Lib.Seqs open Vale.Def.Words_s open Vale.Def.Words.Four_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Seq open FStar.Seq open Vale.Def.Words.Two_s unfold let ( *^ ) = nat32_xor unfold let ( *^^ ) = quad32_xor unfold let add_wrap32 (x:nat32) (y:nat32) : nat32 = add_wrap x y unfold let add_wrap64 (x:nat64) (y:nat64) : nat64 = add_wrap x y unfold let sub_wrap32 (x:nat32) (y:nat32) : nat32 = sub_wrap x y unfold let sub_wrap64 (x:nat64) (y:nat64) : nat64 = sub_wrap x y unfold let iand32 (a:nat32) (b:nat32) : nat32 = iand a b unfold let ixor32 (a:nat32) (b:nat32) : nat32 = ixor a b unfold let ior32 (a:nat32) (b:nat32) : nat32 = ior a b unfold let inot32 (a:nat32) : nat32 = inot a unfold let ishl32 (a:nat32) (s:int) : nat32 = ishl a s unfold let ishr32 (a:nat32) (s:int) : nat32 = ishr a s unfold let iand64 (a:nat64) (b:nat64) : nat64 = iand a b unfold let ixor64 (a:nat64) (b:nat64) : nat64 = ixor a b unfold let ior64 (a:nat64) (b:nat64) : nat64 = ior a b unfold let inot64 (a:nat64) : nat64 = inot a unfold let ishl64 (a:nat64) (s:int) : nat64 = ishl a s unfold let ishr64 (a:nat64) (s:int) : nat64 = ishr a s unfold let iand128 (a:nat128) (b:nat128) : nat128 = iand a b unfold let ixor128 (a:nat128) (b:nat128) : nat128 = ixor a b unfold let ior128 (a:nat128) (b:nat128) : nat128 = ior a b unfold let inot128 (a:nat128) : nat128 = inot a unfold let ishl128 (a:nat128) (s:int) : nat128 = ishl a s unfold let ishr128 (a:nat128) (s:int) : nat128 = ishr a s
{ "checked_file": "/", "dependencies": [ "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Two_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Seq.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.Arch.Types.fsti" }
[ { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
x: Vale.Def.Words_s.two Vale.Def.Words_s.nat32 -> Vale.Def.Words_s.nat64
Prims.Tot
[ "total" ]
[]
[ "Vale.Def.Words_s.two", "Vale.Def.Words_s.nat32", "Vale.Def.Words.Two_s.two_to_nat", "Vale.Def.Words_s.nat64" ]
[]
false
false
false
true
false
let two_to_nat32 (x: two nat32) : nat64 =
two_to_nat 32 x
false
Vale.Arch.Types.fsti
Vale.Arch.Types.reverse_bytes_nat32_quad32_seq
val reverse_bytes_nat32_quad32_seq (q: seq quad32) : seq quad32
val reverse_bytes_nat32_quad32_seq (q: seq quad32) : seq quad32
let reverse_bytes_nat32_quad32_seq (q:seq quad32) : seq quad32 = seq_map reverse_bytes_nat32_quad32 q
{ "file_name": "vale/code/arch/Vale.Arch.Types.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 38, "end_line": 256, "start_col": 0, "start_line": 255 }
module Vale.Arch.Types open FStar.Mul open Vale.Def.Opaque_s open Vale.Def.Types_s open Vale.Lib.Seqs_s open Vale.Lib.Seqs open Vale.Def.Words_s open Vale.Def.Words.Four_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Seq open FStar.Seq open Vale.Def.Words.Two_s unfold let ( *^ ) = nat32_xor unfold let ( *^^ ) = quad32_xor unfold let add_wrap32 (x:nat32) (y:nat32) : nat32 = add_wrap x y unfold let add_wrap64 (x:nat64) (y:nat64) : nat64 = add_wrap x y unfold let sub_wrap32 (x:nat32) (y:nat32) : nat32 = sub_wrap x y unfold let sub_wrap64 (x:nat64) (y:nat64) : nat64 = sub_wrap x y unfold let iand32 (a:nat32) (b:nat32) : nat32 = iand a b unfold let ixor32 (a:nat32) (b:nat32) : nat32 = ixor a b unfold let ior32 (a:nat32) (b:nat32) : nat32 = ior a b unfold let inot32 (a:nat32) : nat32 = inot a unfold let ishl32 (a:nat32) (s:int) : nat32 = ishl a s unfold let ishr32 (a:nat32) (s:int) : nat32 = ishr a s unfold let iand64 (a:nat64) (b:nat64) : nat64 = iand a b unfold let ixor64 (a:nat64) (b:nat64) : nat64 = ixor a b unfold let ior64 (a:nat64) (b:nat64) : nat64 = ior a b unfold let inot64 (a:nat64) : nat64 = inot a unfold let ishl64 (a:nat64) (s:int) : nat64 = ishl a s unfold let ishr64 (a:nat64) (s:int) : nat64 = ishr a s unfold let iand128 (a:nat128) (b:nat128) : nat128 = iand a b unfold let ixor128 (a:nat128) (b:nat128) : nat128 = ixor a b unfold let ior128 (a:nat128) (b:nat128) : nat128 = ior a b unfold let inot128 (a:nat128) : nat128 = inot a unfold let ishl128 (a:nat128) (s:int) : nat128 = ishl a s unfold let ishr128 (a:nat128) (s:int) : nat128 = ishr a s unfold let two_to_nat32 (x:two nat32) : nat64 = two_to_nat 32 x val lemma_nat_to_two32 (_:unit) : Lemma (forall (x:nat64).{:pattern (nat_to_two 32 x)} nat_to_two 32 x == Mktwo (x % 0x100000000) (x / 0x100000000)) let quad32_shl32 (q:quad32) : quad32 = let Mkfour v0 v1 v2 v3 = q in Mkfour 0 v0 v1 v2 let add_wrap_quad32 (q0 q1:quad32) : quad32 = let open Vale.Def.Words_s in Mkfour (add_wrap q0.lo0 q1.lo0) (add_wrap q0.lo1 q1.lo1) (add_wrap q0.hi2 q1.hi2) (add_wrap q0.hi3 q1.hi3) val lemma_BitwiseXorCommutative (x y:nat32) : Lemma (x *^ y == y *^ x) val lemma_BitwiseXorWithZero (n:nat32) : Lemma (n *^ 0 == n) val lemma_BitwiseXorCancel (n:nat32) : Lemma (n *^ n == 0) val lemma_BitwiseXorCancel64 (n:nat64) : Lemma (ixor n n == 0) val lemma_BitwiseXorAssociative (x y z:nat32) : Lemma (x *^ (y *^ z) == (x *^ y) *^ z) val xor_lemmas (_:unit) : Lemma (ensures (forall (x y:nat32).{:pattern (x *^ y)} x *^ y == y *^ x) /\ (forall (n:nat32).{:pattern (n *^ 0)} n *^ 0 == n) /\ (forall (n:nat32).{:pattern (n *^ n)} n *^ n == 0) /\ (forall (n:nat64).{:pattern (ixor n n)} ixor n n == 0) /\ (forall (x y z:nat32).{:pattern (x *^ (y *^ z))} x *^ (y *^ z) == (x *^ y) *^ z) ) val lemma_quad32_xor (_:unit) : Lemma (forall q . {:pattern quad32_xor q q} quad32_xor q q == Mkfour 0 0 0 0) let quad32_double_lo (q:quad32) : double32 = (four_to_two_two q).lo let quad32_double_hi (q:quad32) : double32 = (four_to_two_two q).hi val lemma_reverse_reverse_bytes_nat32 (n:nat32) : Lemma (reverse_bytes_nat32 (reverse_bytes_nat32 n) == n) [SMTPat (reverse_bytes_nat32 (reverse_bytes_nat32 n))] val lemma_reverse_bytes_quad32 (q:quad32) : Lemma (reverse_bytes_quad32 (reverse_bytes_quad32 q) == q) [SMTPat (reverse_bytes_quad32 (reverse_bytes_quad32 q))] val lemma_reverse_bytes_quad32_zero (_:unit) : Lemma (let z = Mkfour 0 0 0 0 in reverse_bytes_quad32 z == z) val lemma_reverse_reverse_bytes_nat32_seq (s:seq nat32) : Lemma (reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s) == s) [SMTPat (reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s))] unfold let quad32_to_seq (q:quad32) : seq nat32 = four_to_seq_LE q val lemma_insert_nat64_properties (q:quad32) (n:nat64) : Lemma ( (let q' = insert_nat64 q n 0 in q'.hi2 == q.hi2 /\ q'.hi3 == q.hi3) /\ (let q' = insert_nat64 q n 1 in q'.lo0 == q.lo0 /\ q'.lo1 == q.lo1)) [SMTPat (insert_nat64 q n)] val lemma_insert_nat64_nat32s (q:quad32) (n0 n1:nat32) : Lemma ( insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 0 == Mkfour n0 n1 q.hi2 q.hi3 /\ insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 1 == Mkfour q.lo0 q.lo1 n0 n1 ) let lo64_def (q:quad32) : nat64 = two_to_nat 32 (two_select (four_to_two_two q) 0) [@"opaque_to_smt"] let lo64 = opaque_make lo64_def irreducible let lo64_reveal = opaque_revealer (`%lo64) lo64 lo64_def let hi64_def (q:quad32) : nat64 = two_to_nat 32 (two_select (four_to_two_two q) 1) [@"opaque_to_smt"] let hi64 = opaque_make hi64_def irreducible let hi64_reveal = opaque_revealer (`%hi64) hi64 hi64_def val lemma_lo64_properties (_:unit) : Lemma (forall (q0 q1:quad32).{:pattern lo64 q0; lo64 q1} (q0.lo0 == q1.lo0 /\ q0.lo1 == q1.lo1) <==> (lo64 q0 == lo64 q1)) val lemma_hi64_properties (_:unit) : Lemma (forall (q0 q1:quad32).{:pattern hi64 q0; hi64 q1} (q0.hi2 == q1.hi2 /\ q0.hi3 == q1.hi3) <==> (hi64 q0 == hi64 q1)) val lemma_reverse_bytes_quad32_64 (src orig final:quad32) : Lemma (requires final == insert_nat64 (insert_nat64 orig (reverse_bytes_nat64 (hi64 src)) 0) (reverse_bytes_nat64 (lo64 src)) 1) (ensures final == reverse_bytes_quad32 src) val lemma_equality_check_helper (q:quad32) : Lemma ((q.lo0 == 0 /\ q.lo1 == 0 ==> lo64 q == 0) /\ ((not (q.lo0 = 0) \/ not (q.lo1 = 0)) ==> not (lo64 q = 0)) /\ (q.hi2 == 0 /\ q.hi3 == 0 ==> hi64 q == 0) /\ ((~(q.hi2 = 0) \/ ~(q.hi3 = 0)) ==> ~(hi64 q = 0)) /\ (q.lo0 == 0xFFFFFFFF /\ q.lo1 == 0xFFFFFFFF <==> lo64 q == 0xFFFFFFFFFFFFFFFF) /\ (q.hi2 == 0xFFFFFFFF /\ q.hi3 == 0xFFFFFFFF <==> hi64 q == 0xFFFFFFFFFFFFFFFF) ) let lemma_equality_check_helper_2 (q1 q2 cmp:quad32) (tmp1 result1 tmp2 tmp3 result2:nat64) : Lemma (requires cmp == Mkfour (if q1.lo0 = q2.lo0 then 0xFFFFFFFF else 0) (if q1.lo1 = q2.lo1 then 0xFFFFFFFF else 0) (if q1.hi2 = q2.hi2 then 0xFFFFFFFF else 0) (if q1.hi3 = q2.hi3 then 0xFFFFFFFF else 0) /\ tmp1 = lo64 cmp /\ result1 = (if tmp1 = 0xFFFFFFFFFFFFFFFF then 0 else 1) /\ tmp2 = hi64 cmp /\ tmp3 = (if tmp2 = 0xFFFFFFFFFFFFFFFF then 0 else 1) /\ result2 = tmp3 + result1) (ensures (if q1 = q2 then result2 = 0 else result2 > 0)) = lemma_equality_check_helper cmp; () val push_pop_xmm (x y:quad32) : Lemma (let x' = insert_nat64 (insert_nat64 y (hi64 x) 1) (lo64 x) 0 in x == x') val lemma_insrq_extrq_relations (x y:quad32) : Lemma (let z = insert_nat64 x (lo64 y) 0 in z == Mkfour y.lo0 y.lo1 x.hi2 x.hi3 /\ (let z = insert_nat64 x (hi64 y) 1 in z == Mkfour x.lo0 x.lo1 y.hi2 y.hi3)) val le_bytes_to_nat64_to_bytes (s:nat64) : Lemma (le_bytes_to_nat64 (le_nat64_to_bytes s) == s) val le_nat64_to_bytes_to_nat64 (s:seq nat8 { length s == 8 }) : Lemma (le_nat64_to_bytes (le_bytes_to_nat64 s) == s) val le_bytes_to_seq_quad32_empty: unit -> Lemma (forall s . {:pattern (length (le_bytes_to_seq_quad32 s)) } length s == 0 ==> length (le_bytes_to_seq_quad32 s) == 0) val be_bytes_to_seq_quad32_empty: unit -> Lemma (forall s . {:pattern (length (be_bytes_to_seq_quad32 s)) } length s == 0 ==> length (be_bytes_to_seq_quad32 s) == 0) val le_bytes_to_seq_quad32_to_bytes_one_quad (b:quad32) : Lemma (le_bytes_to_seq_quad32 (le_quad32_to_bytes b) == create 1 b) let be_quad32_to_bytes (q:quad32) : seq16 nat8 = seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE q)) val be_bytes_to_seq_quad32_to_bytes_one_quad (b:quad32) : Lemma (be_bytes_to_seq_quad32 (be_quad32_to_bytes b) == create 1 b) val le_bytes_to_seq_quad32_to_bytes (s:seq quad32) : Lemma (le_bytes_to_seq_quad32 (le_seq_quad32_to_bytes s) == s) val be_bytes_to_seq_quad32_to_bytes (s:seq quad32) : Lemma (be_bytes_to_seq_quad32 (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) == s) val le_seq_quad32_to_bytes_to_seq_quad32 (s:seq nat8{length s % 16 = 0}) : Lemma (le_seq_quad32_to_bytes (le_bytes_to_seq_quad32 s) == s) val le_quad32_to_bytes_to_quad32 (s:seq nat8 { length s == 16 }) : Lemma(le_quad32_to_bytes (le_bytes_to_quad32 s) == s) val be_quad32_to_bytes_to_quad32 (s:seq nat8 { length s == 16 }) : Lemma(be_quad32_to_bytes (be_bytes_to_quad32 s) == s) val le_seq_quad32_to_bytes_of_singleton (q:quad32) : Lemma (le_quad32_to_bytes q == le_seq_quad32_to_bytes (create 1 q)) val be_seq_quad32_to_bytes_of_singleton (q:quad32) : Lemma (be_quad32_to_bytes q == seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (create 1 q))) val le_quad32_to_bytes_injective: unit -> Lemma (forall b b' . le_quad32_to_bytes b == le_quad32_to_bytes b' ==> b == b') val be_quad32_to_bytes_injective: unit -> Lemma (forall b b' . be_quad32_to_bytes b == be_quad32_to_bytes b' ==> b == b') val le_quad32_to_bytes_injective_specific (b b':quad32) : Lemma (le_quad32_to_bytes b == le_quad32_to_bytes b' ==> b == b') val be_quad32_to_bytes_injective_specific (b b':quad32) : Lemma (be_quad32_to_bytes b == be_quad32_to_bytes b' ==> b == b') val le_seq_quad32_to_bytes_injective (b b':Seq.seq quad32) : Lemma (requires Seq.equal (le_seq_quad32_to_bytes b) (le_seq_quad32_to_bytes b')) (ensures b == b') val seq_to_four_LE_is_seq_to_seq_four_LE (#a:Type) (s:seq4 a) : Lemma (create 1 (seq_to_four_LE s) == seq_to_seq_four_LE s) val seq_to_four_BE_is_seq_to_seq_four_BE (#a:Type) (s:seq4 a) : Lemma (create 1 (seq_to_four_BE s) == seq_to_seq_four_BE s) val le_bytes_to_seq_quad_of_singleton (q:quad32) (b:seq nat8 { length b == 16 }) : Lemma (requires q == le_bytes_to_quad32 b) (ensures create 1 q == le_bytes_to_seq_quad32 b) val be_bytes_to_seq_quad_of_singleton (q:quad32) (b:seq nat8 { length b == 16 }) : Lemma (requires q == be_bytes_to_quad32 b) (ensures create 1 q == be_bytes_to_seq_quad32 b) val le_bytes_to_quad32_to_bytes (q:quad32) : Lemma(le_bytes_to_quad32 (le_quad32_to_bytes q) == q) val be_bytes_to_quad32_to_bytes (q:quad32) : Lemma (be_bytes_to_quad32 (be_quad32_to_bytes q) == q) [SMTPat (be_bytes_to_quad32 (be_quad32_to_bytes q))] // Reverse each nat32 in the quad, but leave the nat32s in their original order let reverse_bytes_nat32_quad32 (q:quad32) : quad32 = Vale.Def.Words.Four_s.four_map reverse_bytes_nat32 q val lemma_reverse_reverse_bytes_nat32_quad32 (s:quad32) : Lemma (reverse_bytes_nat32_quad32 (reverse_bytes_nat32_quad32 s) == s) [SMTPat (reverse_bytes_nat32_quad32 (reverse_bytes_nat32_quad32 s))]
{ "checked_file": "/", "dependencies": [ "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Two_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Seq.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.Arch.Types.fsti" }
[ { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
q: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> FStar.Seq.Base.seq Vale.Def.Types_s.quad32
Prims.Tot
[ "total" ]
[]
[ "FStar.Seq.Base.seq", "Vale.Def.Types_s.quad32", "Vale.Lib.Seqs_s.seq_map", "Vale.Arch.Types.reverse_bytes_nat32_quad32" ]
[]
false
false
false
true
false
let reverse_bytes_nat32_quad32_seq (q: seq quad32) : seq quad32 =
seq_map reverse_bytes_nat32_quad32 q
false
Vale.Arch.Types.fsti
Vale.Arch.Types.hi64
val hi64 : _: Vale.Def.Types_s.quad32 -> Vale.Def.Words_s.nat64
let hi64 = opaque_make hi64_def
{ "file_name": "vale/code/arch/Vale.Arch.Types.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 50, "end_line": 119, "start_col": 19, "start_line": 119 }
module Vale.Arch.Types open FStar.Mul open Vale.Def.Opaque_s open Vale.Def.Types_s open Vale.Lib.Seqs_s open Vale.Lib.Seqs open Vale.Def.Words_s open Vale.Def.Words.Four_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Seq open FStar.Seq open Vale.Def.Words.Two_s unfold let ( *^ ) = nat32_xor unfold let ( *^^ ) = quad32_xor unfold let add_wrap32 (x:nat32) (y:nat32) : nat32 = add_wrap x y unfold let add_wrap64 (x:nat64) (y:nat64) : nat64 = add_wrap x y unfold let sub_wrap32 (x:nat32) (y:nat32) : nat32 = sub_wrap x y unfold let sub_wrap64 (x:nat64) (y:nat64) : nat64 = sub_wrap x y unfold let iand32 (a:nat32) (b:nat32) : nat32 = iand a b unfold let ixor32 (a:nat32) (b:nat32) : nat32 = ixor a b unfold let ior32 (a:nat32) (b:nat32) : nat32 = ior a b unfold let inot32 (a:nat32) : nat32 = inot a unfold let ishl32 (a:nat32) (s:int) : nat32 = ishl a s unfold let ishr32 (a:nat32) (s:int) : nat32 = ishr a s unfold let iand64 (a:nat64) (b:nat64) : nat64 = iand a b unfold let ixor64 (a:nat64) (b:nat64) : nat64 = ixor a b unfold let ior64 (a:nat64) (b:nat64) : nat64 = ior a b unfold let inot64 (a:nat64) : nat64 = inot a unfold let ishl64 (a:nat64) (s:int) : nat64 = ishl a s unfold let ishr64 (a:nat64) (s:int) : nat64 = ishr a s unfold let iand128 (a:nat128) (b:nat128) : nat128 = iand a b unfold let ixor128 (a:nat128) (b:nat128) : nat128 = ixor a b unfold let ior128 (a:nat128) (b:nat128) : nat128 = ior a b unfold let inot128 (a:nat128) : nat128 = inot a unfold let ishl128 (a:nat128) (s:int) : nat128 = ishl a s unfold let ishr128 (a:nat128) (s:int) : nat128 = ishr a s unfold let two_to_nat32 (x:two nat32) : nat64 = two_to_nat 32 x val lemma_nat_to_two32 (_:unit) : Lemma (forall (x:nat64).{:pattern (nat_to_two 32 x)} nat_to_two 32 x == Mktwo (x % 0x100000000) (x / 0x100000000)) let quad32_shl32 (q:quad32) : quad32 = let Mkfour v0 v1 v2 v3 = q in Mkfour 0 v0 v1 v2 let add_wrap_quad32 (q0 q1:quad32) : quad32 = let open Vale.Def.Words_s in Mkfour (add_wrap q0.lo0 q1.lo0) (add_wrap q0.lo1 q1.lo1) (add_wrap q0.hi2 q1.hi2) (add_wrap q0.hi3 q1.hi3) val lemma_BitwiseXorCommutative (x y:nat32) : Lemma (x *^ y == y *^ x) val lemma_BitwiseXorWithZero (n:nat32) : Lemma (n *^ 0 == n) val lemma_BitwiseXorCancel (n:nat32) : Lemma (n *^ n == 0) val lemma_BitwiseXorCancel64 (n:nat64) : Lemma (ixor n n == 0) val lemma_BitwiseXorAssociative (x y z:nat32) : Lemma (x *^ (y *^ z) == (x *^ y) *^ z) val xor_lemmas (_:unit) : Lemma (ensures (forall (x y:nat32).{:pattern (x *^ y)} x *^ y == y *^ x) /\ (forall (n:nat32).{:pattern (n *^ 0)} n *^ 0 == n) /\ (forall (n:nat32).{:pattern (n *^ n)} n *^ n == 0) /\ (forall (n:nat64).{:pattern (ixor n n)} ixor n n == 0) /\ (forall (x y z:nat32).{:pattern (x *^ (y *^ z))} x *^ (y *^ z) == (x *^ y) *^ z) ) val lemma_quad32_xor (_:unit) : Lemma (forall q . {:pattern quad32_xor q q} quad32_xor q q == Mkfour 0 0 0 0) let quad32_double_lo (q:quad32) : double32 = (four_to_two_two q).lo let quad32_double_hi (q:quad32) : double32 = (four_to_two_two q).hi val lemma_reverse_reverse_bytes_nat32 (n:nat32) : Lemma (reverse_bytes_nat32 (reverse_bytes_nat32 n) == n) [SMTPat (reverse_bytes_nat32 (reverse_bytes_nat32 n))] val lemma_reverse_bytes_quad32 (q:quad32) : Lemma (reverse_bytes_quad32 (reverse_bytes_quad32 q) == q) [SMTPat (reverse_bytes_quad32 (reverse_bytes_quad32 q))] val lemma_reverse_bytes_quad32_zero (_:unit) : Lemma (let z = Mkfour 0 0 0 0 in reverse_bytes_quad32 z == z) val lemma_reverse_reverse_bytes_nat32_seq (s:seq nat32) : Lemma (reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s) == s) [SMTPat (reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s))] unfold let quad32_to_seq (q:quad32) : seq nat32 = four_to_seq_LE q val lemma_insert_nat64_properties (q:quad32) (n:nat64) : Lemma ( (let q' = insert_nat64 q n 0 in q'.hi2 == q.hi2 /\ q'.hi3 == q.hi3) /\ (let q' = insert_nat64 q n 1 in q'.lo0 == q.lo0 /\ q'.lo1 == q.lo1)) [SMTPat (insert_nat64 q n)] val lemma_insert_nat64_nat32s (q:quad32) (n0 n1:nat32) : Lemma ( insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 0 == Mkfour n0 n1 q.hi2 q.hi3 /\ insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 1 == Mkfour q.lo0 q.lo1 n0 n1 ) let lo64_def (q:quad32) : nat64 = two_to_nat 32 (two_select (four_to_two_two q) 0) [@"opaque_to_smt"] let lo64 = opaque_make lo64_def irreducible let lo64_reveal = opaque_revealer (`%lo64) lo64 lo64_def
{ "checked_file": "/", "dependencies": [ "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Two_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Seq.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.Arch.Types.fsti" }
[ { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
_: Vale.Def.Types_s.quad32 -> Vale.Def.Words_s.nat64
Prims.Tot
[ "total" ]
[]
[ "Vale.Def.Opaque_s.opaque_make", "Vale.Def.Types_s.quad32", "Vale.Def.Words_s.nat64", "Vale.Arch.Types.hi64_def" ]
[]
false
false
false
true
false
let hi64 =
opaque_make hi64_def
false
Vale.Arch.Types.fsti
Vale.Arch.Types.reverse_bytes_quad32_seq
val reverse_bytes_quad32_seq (s: seq quad32) : seq quad32
val reverse_bytes_quad32_seq (s: seq quad32) : seq quad32
let reverse_bytes_quad32_seq (s:seq quad32) : seq quad32 = seq_map reverse_bytes_quad32 s
{ "file_name": "vale/code/arch/Vale.Arch.Types.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 32, "end_line": 263, "start_col": 0, "start_line": 262 }
module Vale.Arch.Types open FStar.Mul open Vale.Def.Opaque_s open Vale.Def.Types_s open Vale.Lib.Seqs_s open Vale.Lib.Seqs open Vale.Def.Words_s open Vale.Def.Words.Four_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Seq open FStar.Seq open Vale.Def.Words.Two_s unfold let ( *^ ) = nat32_xor unfold let ( *^^ ) = quad32_xor unfold let add_wrap32 (x:nat32) (y:nat32) : nat32 = add_wrap x y unfold let add_wrap64 (x:nat64) (y:nat64) : nat64 = add_wrap x y unfold let sub_wrap32 (x:nat32) (y:nat32) : nat32 = sub_wrap x y unfold let sub_wrap64 (x:nat64) (y:nat64) : nat64 = sub_wrap x y unfold let iand32 (a:nat32) (b:nat32) : nat32 = iand a b unfold let ixor32 (a:nat32) (b:nat32) : nat32 = ixor a b unfold let ior32 (a:nat32) (b:nat32) : nat32 = ior a b unfold let inot32 (a:nat32) : nat32 = inot a unfold let ishl32 (a:nat32) (s:int) : nat32 = ishl a s unfold let ishr32 (a:nat32) (s:int) : nat32 = ishr a s unfold let iand64 (a:nat64) (b:nat64) : nat64 = iand a b unfold let ixor64 (a:nat64) (b:nat64) : nat64 = ixor a b unfold let ior64 (a:nat64) (b:nat64) : nat64 = ior a b unfold let inot64 (a:nat64) : nat64 = inot a unfold let ishl64 (a:nat64) (s:int) : nat64 = ishl a s unfold let ishr64 (a:nat64) (s:int) : nat64 = ishr a s unfold let iand128 (a:nat128) (b:nat128) : nat128 = iand a b unfold let ixor128 (a:nat128) (b:nat128) : nat128 = ixor a b unfold let ior128 (a:nat128) (b:nat128) : nat128 = ior a b unfold let inot128 (a:nat128) : nat128 = inot a unfold let ishl128 (a:nat128) (s:int) : nat128 = ishl a s unfold let ishr128 (a:nat128) (s:int) : nat128 = ishr a s unfold let two_to_nat32 (x:two nat32) : nat64 = two_to_nat 32 x val lemma_nat_to_two32 (_:unit) : Lemma (forall (x:nat64).{:pattern (nat_to_two 32 x)} nat_to_two 32 x == Mktwo (x % 0x100000000) (x / 0x100000000)) let quad32_shl32 (q:quad32) : quad32 = let Mkfour v0 v1 v2 v3 = q in Mkfour 0 v0 v1 v2 let add_wrap_quad32 (q0 q1:quad32) : quad32 = let open Vale.Def.Words_s in Mkfour (add_wrap q0.lo0 q1.lo0) (add_wrap q0.lo1 q1.lo1) (add_wrap q0.hi2 q1.hi2) (add_wrap q0.hi3 q1.hi3) val lemma_BitwiseXorCommutative (x y:nat32) : Lemma (x *^ y == y *^ x) val lemma_BitwiseXorWithZero (n:nat32) : Lemma (n *^ 0 == n) val lemma_BitwiseXorCancel (n:nat32) : Lemma (n *^ n == 0) val lemma_BitwiseXorCancel64 (n:nat64) : Lemma (ixor n n == 0) val lemma_BitwiseXorAssociative (x y z:nat32) : Lemma (x *^ (y *^ z) == (x *^ y) *^ z) val xor_lemmas (_:unit) : Lemma (ensures (forall (x y:nat32).{:pattern (x *^ y)} x *^ y == y *^ x) /\ (forall (n:nat32).{:pattern (n *^ 0)} n *^ 0 == n) /\ (forall (n:nat32).{:pattern (n *^ n)} n *^ n == 0) /\ (forall (n:nat64).{:pattern (ixor n n)} ixor n n == 0) /\ (forall (x y z:nat32).{:pattern (x *^ (y *^ z))} x *^ (y *^ z) == (x *^ y) *^ z) ) val lemma_quad32_xor (_:unit) : Lemma (forall q . {:pattern quad32_xor q q} quad32_xor q q == Mkfour 0 0 0 0) let quad32_double_lo (q:quad32) : double32 = (four_to_two_two q).lo let quad32_double_hi (q:quad32) : double32 = (four_to_two_two q).hi val lemma_reverse_reverse_bytes_nat32 (n:nat32) : Lemma (reverse_bytes_nat32 (reverse_bytes_nat32 n) == n) [SMTPat (reverse_bytes_nat32 (reverse_bytes_nat32 n))] val lemma_reverse_bytes_quad32 (q:quad32) : Lemma (reverse_bytes_quad32 (reverse_bytes_quad32 q) == q) [SMTPat (reverse_bytes_quad32 (reverse_bytes_quad32 q))] val lemma_reverse_bytes_quad32_zero (_:unit) : Lemma (let z = Mkfour 0 0 0 0 in reverse_bytes_quad32 z == z) val lemma_reverse_reverse_bytes_nat32_seq (s:seq nat32) : Lemma (reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s) == s) [SMTPat (reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s))] unfold let quad32_to_seq (q:quad32) : seq nat32 = four_to_seq_LE q val lemma_insert_nat64_properties (q:quad32) (n:nat64) : Lemma ( (let q' = insert_nat64 q n 0 in q'.hi2 == q.hi2 /\ q'.hi3 == q.hi3) /\ (let q' = insert_nat64 q n 1 in q'.lo0 == q.lo0 /\ q'.lo1 == q.lo1)) [SMTPat (insert_nat64 q n)] val lemma_insert_nat64_nat32s (q:quad32) (n0 n1:nat32) : Lemma ( insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 0 == Mkfour n0 n1 q.hi2 q.hi3 /\ insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 1 == Mkfour q.lo0 q.lo1 n0 n1 ) let lo64_def (q:quad32) : nat64 = two_to_nat 32 (two_select (four_to_two_two q) 0) [@"opaque_to_smt"] let lo64 = opaque_make lo64_def irreducible let lo64_reveal = opaque_revealer (`%lo64) lo64 lo64_def let hi64_def (q:quad32) : nat64 = two_to_nat 32 (two_select (four_to_two_two q) 1) [@"opaque_to_smt"] let hi64 = opaque_make hi64_def irreducible let hi64_reveal = opaque_revealer (`%hi64) hi64 hi64_def val lemma_lo64_properties (_:unit) : Lemma (forall (q0 q1:quad32).{:pattern lo64 q0; lo64 q1} (q0.lo0 == q1.lo0 /\ q0.lo1 == q1.lo1) <==> (lo64 q0 == lo64 q1)) val lemma_hi64_properties (_:unit) : Lemma (forall (q0 q1:quad32).{:pattern hi64 q0; hi64 q1} (q0.hi2 == q1.hi2 /\ q0.hi3 == q1.hi3) <==> (hi64 q0 == hi64 q1)) val lemma_reverse_bytes_quad32_64 (src orig final:quad32) : Lemma (requires final == insert_nat64 (insert_nat64 orig (reverse_bytes_nat64 (hi64 src)) 0) (reverse_bytes_nat64 (lo64 src)) 1) (ensures final == reverse_bytes_quad32 src) val lemma_equality_check_helper (q:quad32) : Lemma ((q.lo0 == 0 /\ q.lo1 == 0 ==> lo64 q == 0) /\ ((not (q.lo0 = 0) \/ not (q.lo1 = 0)) ==> not (lo64 q = 0)) /\ (q.hi2 == 0 /\ q.hi3 == 0 ==> hi64 q == 0) /\ ((~(q.hi2 = 0) \/ ~(q.hi3 = 0)) ==> ~(hi64 q = 0)) /\ (q.lo0 == 0xFFFFFFFF /\ q.lo1 == 0xFFFFFFFF <==> lo64 q == 0xFFFFFFFFFFFFFFFF) /\ (q.hi2 == 0xFFFFFFFF /\ q.hi3 == 0xFFFFFFFF <==> hi64 q == 0xFFFFFFFFFFFFFFFF) ) let lemma_equality_check_helper_2 (q1 q2 cmp:quad32) (tmp1 result1 tmp2 tmp3 result2:nat64) : Lemma (requires cmp == Mkfour (if q1.lo0 = q2.lo0 then 0xFFFFFFFF else 0) (if q1.lo1 = q2.lo1 then 0xFFFFFFFF else 0) (if q1.hi2 = q2.hi2 then 0xFFFFFFFF else 0) (if q1.hi3 = q2.hi3 then 0xFFFFFFFF else 0) /\ tmp1 = lo64 cmp /\ result1 = (if tmp1 = 0xFFFFFFFFFFFFFFFF then 0 else 1) /\ tmp2 = hi64 cmp /\ tmp3 = (if tmp2 = 0xFFFFFFFFFFFFFFFF then 0 else 1) /\ result2 = tmp3 + result1) (ensures (if q1 = q2 then result2 = 0 else result2 > 0)) = lemma_equality_check_helper cmp; () val push_pop_xmm (x y:quad32) : Lemma (let x' = insert_nat64 (insert_nat64 y (hi64 x) 1) (lo64 x) 0 in x == x') val lemma_insrq_extrq_relations (x y:quad32) : Lemma (let z = insert_nat64 x (lo64 y) 0 in z == Mkfour y.lo0 y.lo1 x.hi2 x.hi3 /\ (let z = insert_nat64 x (hi64 y) 1 in z == Mkfour x.lo0 x.lo1 y.hi2 y.hi3)) val le_bytes_to_nat64_to_bytes (s:nat64) : Lemma (le_bytes_to_nat64 (le_nat64_to_bytes s) == s) val le_nat64_to_bytes_to_nat64 (s:seq nat8 { length s == 8 }) : Lemma (le_nat64_to_bytes (le_bytes_to_nat64 s) == s) val le_bytes_to_seq_quad32_empty: unit -> Lemma (forall s . {:pattern (length (le_bytes_to_seq_quad32 s)) } length s == 0 ==> length (le_bytes_to_seq_quad32 s) == 0) val be_bytes_to_seq_quad32_empty: unit -> Lemma (forall s . {:pattern (length (be_bytes_to_seq_quad32 s)) } length s == 0 ==> length (be_bytes_to_seq_quad32 s) == 0) val le_bytes_to_seq_quad32_to_bytes_one_quad (b:quad32) : Lemma (le_bytes_to_seq_quad32 (le_quad32_to_bytes b) == create 1 b) let be_quad32_to_bytes (q:quad32) : seq16 nat8 = seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE q)) val be_bytes_to_seq_quad32_to_bytes_one_quad (b:quad32) : Lemma (be_bytes_to_seq_quad32 (be_quad32_to_bytes b) == create 1 b) val le_bytes_to_seq_quad32_to_bytes (s:seq quad32) : Lemma (le_bytes_to_seq_quad32 (le_seq_quad32_to_bytes s) == s) val be_bytes_to_seq_quad32_to_bytes (s:seq quad32) : Lemma (be_bytes_to_seq_quad32 (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) == s) val le_seq_quad32_to_bytes_to_seq_quad32 (s:seq nat8{length s % 16 = 0}) : Lemma (le_seq_quad32_to_bytes (le_bytes_to_seq_quad32 s) == s) val le_quad32_to_bytes_to_quad32 (s:seq nat8 { length s == 16 }) : Lemma(le_quad32_to_bytes (le_bytes_to_quad32 s) == s) val be_quad32_to_bytes_to_quad32 (s:seq nat8 { length s == 16 }) : Lemma(be_quad32_to_bytes (be_bytes_to_quad32 s) == s) val le_seq_quad32_to_bytes_of_singleton (q:quad32) : Lemma (le_quad32_to_bytes q == le_seq_quad32_to_bytes (create 1 q)) val be_seq_quad32_to_bytes_of_singleton (q:quad32) : Lemma (be_quad32_to_bytes q == seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (create 1 q))) val le_quad32_to_bytes_injective: unit -> Lemma (forall b b' . le_quad32_to_bytes b == le_quad32_to_bytes b' ==> b == b') val be_quad32_to_bytes_injective: unit -> Lemma (forall b b' . be_quad32_to_bytes b == be_quad32_to_bytes b' ==> b == b') val le_quad32_to_bytes_injective_specific (b b':quad32) : Lemma (le_quad32_to_bytes b == le_quad32_to_bytes b' ==> b == b') val be_quad32_to_bytes_injective_specific (b b':quad32) : Lemma (be_quad32_to_bytes b == be_quad32_to_bytes b' ==> b == b') val le_seq_quad32_to_bytes_injective (b b':Seq.seq quad32) : Lemma (requires Seq.equal (le_seq_quad32_to_bytes b) (le_seq_quad32_to_bytes b')) (ensures b == b') val seq_to_four_LE_is_seq_to_seq_four_LE (#a:Type) (s:seq4 a) : Lemma (create 1 (seq_to_four_LE s) == seq_to_seq_four_LE s) val seq_to_four_BE_is_seq_to_seq_four_BE (#a:Type) (s:seq4 a) : Lemma (create 1 (seq_to_four_BE s) == seq_to_seq_four_BE s) val le_bytes_to_seq_quad_of_singleton (q:quad32) (b:seq nat8 { length b == 16 }) : Lemma (requires q == le_bytes_to_quad32 b) (ensures create 1 q == le_bytes_to_seq_quad32 b) val be_bytes_to_seq_quad_of_singleton (q:quad32) (b:seq nat8 { length b == 16 }) : Lemma (requires q == be_bytes_to_quad32 b) (ensures create 1 q == be_bytes_to_seq_quad32 b) val le_bytes_to_quad32_to_bytes (q:quad32) : Lemma(le_bytes_to_quad32 (le_quad32_to_bytes q) == q) val be_bytes_to_quad32_to_bytes (q:quad32) : Lemma (be_bytes_to_quad32 (be_quad32_to_bytes q) == q) [SMTPat (be_bytes_to_quad32 (be_quad32_to_bytes q))] // Reverse each nat32 in the quad, but leave the nat32s in their original order let reverse_bytes_nat32_quad32 (q:quad32) : quad32 = Vale.Def.Words.Four_s.four_map reverse_bytes_nat32 q val lemma_reverse_reverse_bytes_nat32_quad32 (s:quad32) : Lemma (reverse_bytes_nat32_quad32 (reverse_bytes_nat32_quad32 s) == s) [SMTPat (reverse_bytes_nat32_quad32 (reverse_bytes_nat32_quad32 s))] let reverse_bytes_nat32_quad32_seq (q:seq quad32) : seq quad32 = seq_map reverse_bytes_nat32_quad32 q val lemma_reverse_reverse_bytes_nat32_quad32_seq (s:seq quad32) : Lemma (reverse_bytes_nat32_quad32_seq (reverse_bytes_nat32_quad32_seq s) == s) [SMTPat (reverse_bytes_nat32_quad32_seq (reverse_bytes_nat32_quad32_seq s))]
{ "checked_file": "/", "dependencies": [ "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Two_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Seq.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.Arch.Types.fsti" }
[ { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
s: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> FStar.Seq.Base.seq Vale.Def.Types_s.quad32
Prims.Tot
[ "total" ]
[]
[ "FStar.Seq.Base.seq", "Vale.Def.Types_s.quad32", "Vale.Lib.Seqs_s.seq_map", "Vale.Def.Types_s.reverse_bytes_quad32" ]
[]
false
false
false
true
false
let reverse_bytes_quad32_seq (s: seq quad32) : seq quad32 =
seq_map reverse_bytes_quad32 s
false
Vale.Arch.Types.fsti
Vale.Arch.Types.reverse_bytes_nat32_quad32
val reverse_bytes_nat32_quad32 (q: quad32) : quad32
val reverse_bytes_nat32_quad32 (q: quad32) : quad32
let reverse_bytes_nat32_quad32 (q:quad32) : quad32 = Vale.Def.Words.Four_s.four_map reverse_bytes_nat32 q
{ "file_name": "vale/code/arch/Vale.Arch.Types.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 54, "end_line": 249, "start_col": 0, "start_line": 248 }
module Vale.Arch.Types open FStar.Mul open Vale.Def.Opaque_s open Vale.Def.Types_s open Vale.Lib.Seqs_s open Vale.Lib.Seqs open Vale.Def.Words_s open Vale.Def.Words.Four_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Seq open FStar.Seq open Vale.Def.Words.Two_s unfold let ( *^ ) = nat32_xor unfold let ( *^^ ) = quad32_xor unfold let add_wrap32 (x:nat32) (y:nat32) : nat32 = add_wrap x y unfold let add_wrap64 (x:nat64) (y:nat64) : nat64 = add_wrap x y unfold let sub_wrap32 (x:nat32) (y:nat32) : nat32 = sub_wrap x y unfold let sub_wrap64 (x:nat64) (y:nat64) : nat64 = sub_wrap x y unfold let iand32 (a:nat32) (b:nat32) : nat32 = iand a b unfold let ixor32 (a:nat32) (b:nat32) : nat32 = ixor a b unfold let ior32 (a:nat32) (b:nat32) : nat32 = ior a b unfold let inot32 (a:nat32) : nat32 = inot a unfold let ishl32 (a:nat32) (s:int) : nat32 = ishl a s unfold let ishr32 (a:nat32) (s:int) : nat32 = ishr a s unfold let iand64 (a:nat64) (b:nat64) : nat64 = iand a b unfold let ixor64 (a:nat64) (b:nat64) : nat64 = ixor a b unfold let ior64 (a:nat64) (b:nat64) : nat64 = ior a b unfold let inot64 (a:nat64) : nat64 = inot a unfold let ishl64 (a:nat64) (s:int) : nat64 = ishl a s unfold let ishr64 (a:nat64) (s:int) : nat64 = ishr a s unfold let iand128 (a:nat128) (b:nat128) : nat128 = iand a b unfold let ixor128 (a:nat128) (b:nat128) : nat128 = ixor a b unfold let ior128 (a:nat128) (b:nat128) : nat128 = ior a b unfold let inot128 (a:nat128) : nat128 = inot a unfold let ishl128 (a:nat128) (s:int) : nat128 = ishl a s unfold let ishr128 (a:nat128) (s:int) : nat128 = ishr a s unfold let two_to_nat32 (x:two nat32) : nat64 = two_to_nat 32 x val lemma_nat_to_two32 (_:unit) : Lemma (forall (x:nat64).{:pattern (nat_to_two 32 x)} nat_to_two 32 x == Mktwo (x % 0x100000000) (x / 0x100000000)) let quad32_shl32 (q:quad32) : quad32 = let Mkfour v0 v1 v2 v3 = q in Mkfour 0 v0 v1 v2 let add_wrap_quad32 (q0 q1:quad32) : quad32 = let open Vale.Def.Words_s in Mkfour (add_wrap q0.lo0 q1.lo0) (add_wrap q0.lo1 q1.lo1) (add_wrap q0.hi2 q1.hi2) (add_wrap q0.hi3 q1.hi3) val lemma_BitwiseXorCommutative (x y:nat32) : Lemma (x *^ y == y *^ x) val lemma_BitwiseXorWithZero (n:nat32) : Lemma (n *^ 0 == n) val lemma_BitwiseXorCancel (n:nat32) : Lemma (n *^ n == 0) val lemma_BitwiseXorCancel64 (n:nat64) : Lemma (ixor n n == 0) val lemma_BitwiseXorAssociative (x y z:nat32) : Lemma (x *^ (y *^ z) == (x *^ y) *^ z) val xor_lemmas (_:unit) : Lemma (ensures (forall (x y:nat32).{:pattern (x *^ y)} x *^ y == y *^ x) /\ (forall (n:nat32).{:pattern (n *^ 0)} n *^ 0 == n) /\ (forall (n:nat32).{:pattern (n *^ n)} n *^ n == 0) /\ (forall (n:nat64).{:pattern (ixor n n)} ixor n n == 0) /\ (forall (x y z:nat32).{:pattern (x *^ (y *^ z))} x *^ (y *^ z) == (x *^ y) *^ z) ) val lemma_quad32_xor (_:unit) : Lemma (forall q . {:pattern quad32_xor q q} quad32_xor q q == Mkfour 0 0 0 0) let quad32_double_lo (q:quad32) : double32 = (four_to_two_two q).lo let quad32_double_hi (q:quad32) : double32 = (four_to_two_two q).hi val lemma_reverse_reverse_bytes_nat32 (n:nat32) : Lemma (reverse_bytes_nat32 (reverse_bytes_nat32 n) == n) [SMTPat (reverse_bytes_nat32 (reverse_bytes_nat32 n))] val lemma_reverse_bytes_quad32 (q:quad32) : Lemma (reverse_bytes_quad32 (reverse_bytes_quad32 q) == q) [SMTPat (reverse_bytes_quad32 (reverse_bytes_quad32 q))] val lemma_reverse_bytes_quad32_zero (_:unit) : Lemma (let z = Mkfour 0 0 0 0 in reverse_bytes_quad32 z == z) val lemma_reverse_reverse_bytes_nat32_seq (s:seq nat32) : Lemma (reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s) == s) [SMTPat (reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s))] unfold let quad32_to_seq (q:quad32) : seq nat32 = four_to_seq_LE q val lemma_insert_nat64_properties (q:quad32) (n:nat64) : Lemma ( (let q' = insert_nat64 q n 0 in q'.hi2 == q.hi2 /\ q'.hi3 == q.hi3) /\ (let q' = insert_nat64 q n 1 in q'.lo0 == q.lo0 /\ q'.lo1 == q.lo1)) [SMTPat (insert_nat64 q n)] val lemma_insert_nat64_nat32s (q:quad32) (n0 n1:nat32) : Lemma ( insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 0 == Mkfour n0 n1 q.hi2 q.hi3 /\ insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 1 == Mkfour q.lo0 q.lo1 n0 n1 ) let lo64_def (q:quad32) : nat64 = two_to_nat 32 (two_select (four_to_two_two q) 0) [@"opaque_to_smt"] let lo64 = opaque_make lo64_def irreducible let lo64_reveal = opaque_revealer (`%lo64) lo64 lo64_def let hi64_def (q:quad32) : nat64 = two_to_nat 32 (two_select (four_to_two_two q) 1) [@"opaque_to_smt"] let hi64 = opaque_make hi64_def irreducible let hi64_reveal = opaque_revealer (`%hi64) hi64 hi64_def val lemma_lo64_properties (_:unit) : Lemma (forall (q0 q1:quad32).{:pattern lo64 q0; lo64 q1} (q0.lo0 == q1.lo0 /\ q0.lo1 == q1.lo1) <==> (lo64 q0 == lo64 q1)) val lemma_hi64_properties (_:unit) : Lemma (forall (q0 q1:quad32).{:pattern hi64 q0; hi64 q1} (q0.hi2 == q1.hi2 /\ q0.hi3 == q1.hi3) <==> (hi64 q0 == hi64 q1)) val lemma_reverse_bytes_quad32_64 (src orig final:quad32) : Lemma (requires final == insert_nat64 (insert_nat64 orig (reverse_bytes_nat64 (hi64 src)) 0) (reverse_bytes_nat64 (lo64 src)) 1) (ensures final == reverse_bytes_quad32 src) val lemma_equality_check_helper (q:quad32) : Lemma ((q.lo0 == 0 /\ q.lo1 == 0 ==> lo64 q == 0) /\ ((not (q.lo0 = 0) \/ not (q.lo1 = 0)) ==> not (lo64 q = 0)) /\ (q.hi2 == 0 /\ q.hi3 == 0 ==> hi64 q == 0) /\ ((~(q.hi2 = 0) \/ ~(q.hi3 = 0)) ==> ~(hi64 q = 0)) /\ (q.lo0 == 0xFFFFFFFF /\ q.lo1 == 0xFFFFFFFF <==> lo64 q == 0xFFFFFFFFFFFFFFFF) /\ (q.hi2 == 0xFFFFFFFF /\ q.hi3 == 0xFFFFFFFF <==> hi64 q == 0xFFFFFFFFFFFFFFFF) ) let lemma_equality_check_helper_2 (q1 q2 cmp:quad32) (tmp1 result1 tmp2 tmp3 result2:nat64) : Lemma (requires cmp == Mkfour (if q1.lo0 = q2.lo0 then 0xFFFFFFFF else 0) (if q1.lo1 = q2.lo1 then 0xFFFFFFFF else 0) (if q1.hi2 = q2.hi2 then 0xFFFFFFFF else 0) (if q1.hi3 = q2.hi3 then 0xFFFFFFFF else 0) /\ tmp1 = lo64 cmp /\ result1 = (if tmp1 = 0xFFFFFFFFFFFFFFFF then 0 else 1) /\ tmp2 = hi64 cmp /\ tmp3 = (if tmp2 = 0xFFFFFFFFFFFFFFFF then 0 else 1) /\ result2 = tmp3 + result1) (ensures (if q1 = q2 then result2 = 0 else result2 > 0)) = lemma_equality_check_helper cmp; () val push_pop_xmm (x y:quad32) : Lemma (let x' = insert_nat64 (insert_nat64 y (hi64 x) 1) (lo64 x) 0 in x == x') val lemma_insrq_extrq_relations (x y:quad32) : Lemma (let z = insert_nat64 x (lo64 y) 0 in z == Mkfour y.lo0 y.lo1 x.hi2 x.hi3 /\ (let z = insert_nat64 x (hi64 y) 1 in z == Mkfour x.lo0 x.lo1 y.hi2 y.hi3)) val le_bytes_to_nat64_to_bytes (s:nat64) : Lemma (le_bytes_to_nat64 (le_nat64_to_bytes s) == s) val le_nat64_to_bytes_to_nat64 (s:seq nat8 { length s == 8 }) : Lemma (le_nat64_to_bytes (le_bytes_to_nat64 s) == s) val le_bytes_to_seq_quad32_empty: unit -> Lemma (forall s . {:pattern (length (le_bytes_to_seq_quad32 s)) } length s == 0 ==> length (le_bytes_to_seq_quad32 s) == 0) val be_bytes_to_seq_quad32_empty: unit -> Lemma (forall s . {:pattern (length (be_bytes_to_seq_quad32 s)) } length s == 0 ==> length (be_bytes_to_seq_quad32 s) == 0) val le_bytes_to_seq_quad32_to_bytes_one_quad (b:quad32) : Lemma (le_bytes_to_seq_quad32 (le_quad32_to_bytes b) == create 1 b) let be_quad32_to_bytes (q:quad32) : seq16 nat8 = seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE q)) val be_bytes_to_seq_quad32_to_bytes_one_quad (b:quad32) : Lemma (be_bytes_to_seq_quad32 (be_quad32_to_bytes b) == create 1 b) val le_bytes_to_seq_quad32_to_bytes (s:seq quad32) : Lemma (le_bytes_to_seq_quad32 (le_seq_quad32_to_bytes s) == s) val be_bytes_to_seq_quad32_to_bytes (s:seq quad32) : Lemma (be_bytes_to_seq_quad32 (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) == s) val le_seq_quad32_to_bytes_to_seq_quad32 (s:seq nat8{length s % 16 = 0}) : Lemma (le_seq_quad32_to_bytes (le_bytes_to_seq_quad32 s) == s) val le_quad32_to_bytes_to_quad32 (s:seq nat8 { length s == 16 }) : Lemma(le_quad32_to_bytes (le_bytes_to_quad32 s) == s) val be_quad32_to_bytes_to_quad32 (s:seq nat8 { length s == 16 }) : Lemma(be_quad32_to_bytes (be_bytes_to_quad32 s) == s) val le_seq_quad32_to_bytes_of_singleton (q:quad32) : Lemma (le_quad32_to_bytes q == le_seq_quad32_to_bytes (create 1 q)) val be_seq_quad32_to_bytes_of_singleton (q:quad32) : Lemma (be_quad32_to_bytes q == seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (create 1 q))) val le_quad32_to_bytes_injective: unit -> Lemma (forall b b' . le_quad32_to_bytes b == le_quad32_to_bytes b' ==> b == b') val be_quad32_to_bytes_injective: unit -> Lemma (forall b b' . be_quad32_to_bytes b == be_quad32_to_bytes b' ==> b == b') val le_quad32_to_bytes_injective_specific (b b':quad32) : Lemma (le_quad32_to_bytes b == le_quad32_to_bytes b' ==> b == b') val be_quad32_to_bytes_injective_specific (b b':quad32) : Lemma (be_quad32_to_bytes b == be_quad32_to_bytes b' ==> b == b') val le_seq_quad32_to_bytes_injective (b b':Seq.seq quad32) : Lemma (requires Seq.equal (le_seq_quad32_to_bytes b) (le_seq_quad32_to_bytes b')) (ensures b == b') val seq_to_four_LE_is_seq_to_seq_four_LE (#a:Type) (s:seq4 a) : Lemma (create 1 (seq_to_four_LE s) == seq_to_seq_four_LE s) val seq_to_four_BE_is_seq_to_seq_four_BE (#a:Type) (s:seq4 a) : Lemma (create 1 (seq_to_four_BE s) == seq_to_seq_four_BE s) val le_bytes_to_seq_quad_of_singleton (q:quad32) (b:seq nat8 { length b == 16 }) : Lemma (requires q == le_bytes_to_quad32 b) (ensures create 1 q == le_bytes_to_seq_quad32 b) val be_bytes_to_seq_quad_of_singleton (q:quad32) (b:seq nat8 { length b == 16 }) : Lemma (requires q == be_bytes_to_quad32 b) (ensures create 1 q == be_bytes_to_seq_quad32 b) val le_bytes_to_quad32_to_bytes (q:quad32) : Lemma(le_bytes_to_quad32 (le_quad32_to_bytes q) == q) val be_bytes_to_quad32_to_bytes (q:quad32) : Lemma (be_bytes_to_quad32 (be_quad32_to_bytes q) == q) [SMTPat (be_bytes_to_quad32 (be_quad32_to_bytes q))]
{ "checked_file": "/", "dependencies": [ "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Two_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Seq.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.Arch.Types.fsti" }
[ { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
q: Vale.Def.Types_s.quad32 -> Vale.Def.Types_s.quad32
Prims.Tot
[ "total" ]
[]
[ "Vale.Def.Types_s.quad32", "Vale.Def.Words.Four_s.four_map", "Vale.Def.Types_s.nat32", "Vale.Def.Types_s.reverse_bytes_nat32" ]
[]
false
false
false
true
false
let reverse_bytes_nat32_quad32 (q: quad32) : quad32 =
Vale.Def.Words.Four_s.four_map reverse_bytes_nat32 q
false
Steel.FractionalAnchoredPreorder.fst
Steel.FractionalAnchoredPreorder.update_anchored_hist
val update_anchored_hist (#v: Type) (#p: preorder v) (#s: anchor_rel p) (m: avalue s) (v1: vhist p { avalue_owns_anchored m /\ v1 `extends` (avalue_val m) /\ (curval v1) `compat_with_any_anchor_of` m }) : frame_preserving_upd pcm (Owns m) (Owns (avalue_anchored_update m v1))
val update_anchored_hist (#v: Type) (#p: preorder v) (#s: anchor_rel p) (m: avalue s) (v1: vhist p { avalue_owns_anchored m /\ v1 `extends` (avalue_val m) /\ (curval v1) `compat_with_any_anchor_of` m }) : frame_preserving_upd pcm (Owns m) (Owns (avalue_anchored_update m v1))
let update_anchored_hist (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) (v1:vhist p { avalue_owns_anchored m /\ v1 `extends` avalue_val m /\ curval v1 `compat_with_any_anchor_of` m }) : frame_preserving_upd pcm (Owns m) (Owns (avalue_anchored_update m v1)) = fun full_v -> let Owns full_m = full_v in let m_res = avalue_anchored_update full_m v1 in Owns m_res
{ "file_name": "lib/steel/Steel.FractionalAnchoredPreorder.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 16, "end_line": 534, "start_col": 0, "start_line": 521 }
(* Copyright 2021 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. Author: N. Swamy *) module Steel.FractionalAnchoredPreorder (** This module provides a partial commutative monoid (PCM) for use in the ghost state of a concurrent Steel program. Its goal is to facilitate a form of information-sharing between multiple threads including the following features: Fractions, Preorders, Snapshots, and Anchors --- Anchors are the most unusual. 1. Fractions: Ownership of the state is controlled by a fractional permission, so multiple threads may share read-only privileges on the state, but only one can have write permission. 2. Preorders: The ghost state is governed by a preorder p and all updates to the state must respect the preorder (a reflexive, transitive relation on the state) 3. Snapshots: Since the state always evolves by a preorder, it is possible to take a snapshot of the state. A snapshot does not confer any particular ownership on the state, except knowledge of a snapshot ensures that the current state is related to the snapshot by the preorder. 4. Anchors are a kind of refinement of the preorder. If a thread owns an anchored value [v], then no other thread, even a thread owning a full fractional permission, can advance the state "too far" from the anchor. In particular, the PCM is parameterized by a binary relation on values, [anchors:anchor_relation]. If a thread owns the anchor [v], then the current value `cur` of the state must be in relation [v `anchors` cur]. This can be used to ensure that the knowledge of one thread is never becomes too stale. For example, this allows one to model a shared monotonically increasing counter, where if one thread anchors knowledge of the counter at the value 5, no other thread can increase the value of the counter beyond, say, 10, (when the anchor relation is y - x <= 5), until the anchoring thread releases the anchor. Further, at any point, a thread can take a snapshot of the counter and rely on the fact that the value of the counter in the future will be >= the snapshot. *) open FStar.PCM open FStar.Preorder open Steel.Preorder open Steel.FractionalPermission #push-options "--fuel 0 --ifuel 2" /// A permission: is a pair of /// /// * an optional fractional permission; with `Some p` indicating /// some ownership, while `None` is an additional "0" permission /// value, to encode snapshots. /// /// * and an optional anchor, where `Some a` indicates the current /// value can't be too far from `a`. let permission (v:Type) = option perm & option v /// Non-zero permission is either a read or write permission let has_nonzero #v (p:permission v) = Some? (fst p) /// Has an anchor set let has_anchor #v (p:permission v) = Some? (snd p) /// Either an anchor or non-zero let has_some_ownership #v (p:permission v) = has_nonzero p || has_anchor p /// The anchoring value let anchor_of #v (p:permission v { has_anchor p }) : v = Some?.v (snd p) /// The anchoring relation: /// -- A binary relation on values /// -- refining the preorder /// -- and if x `anchors` z then it also anchors any `y` between `x` and `z` /// /// Explaining the third clause a bit: /// Think intuitively of anchoring relations as a kind of distance measure /// /// if `z` is close enough to `x` then if `z` is further than `y` /// (since it is ahead of `y` in the preorder) then `y` is also /// close enough to `x` let anchor_rel (#v:Type) (p:preorder v) = anchors:(v -> v -> prop) { (forall v0 v1. anchors v0 v1 ==> p v0 v1) /\ (forall x z. x `anchors` z ==> (forall y. p x y /\ p y z ==> x `anchors` y)) // } /// An implementation remark: We use Steel.Preorder here to /// generically transform any preorder into a PCM. That works by /// taking the value of the PCM to be a history of values related by /// the preorder. So, throughout, we'll be using the the [vhist p] /// from Steel.Preorder, the type of a non-empty history compatible /// with [p]. The details of the histories don't matter much for our /// purposes---we only care about the most recent value, for which /// we'll use [curval v]. /// If the anchor is set, then the current value is anchored by it let anchored (#v:Type) (#p:preorder v) (anchors:anchor_rel p) (pv:(permission v & vhist p)) = has_anchor (fst pv) ==> anchor_of (fst pv) `anchors` curval (snd pv) /// A value in our fractional anchored PCM is a pair of a permission /// and a p-compatible history, refined to ensure that if the anchor /// is set, then the current value is anchored by it. let avalue (#v:Type) (#p:preorder v) (anchors:anchor_rel p) = pv:(permission v & vhist p) { anchored anchors pv } /// initial_value: A utility to construct a value in the PCM #push-options "--fuel 1" let initial_value (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (value:v { anchors value value }) : avalue anchors = (Some full_perm, Some value), [value] #pop-options /// We add a unit element to [avalue], as needed for a PCM [@@erasable] noeq type knowledge (#v:Type) (#p:preorder v) (anchors:anchor_rel p) = | Owns : avalue anchors -> knowledge anchors | Nothing : knowledge anchors let b2p (b:bool) : prop = b == true /// Fractional permissions are composable when their sum <= 1.0 let perm_opt_composable (p0 p1:option perm) : prop = match p0, p1 with | None, None -> True | Some p, None | None, Some p -> b2p (p `lesser_equal_perm` full_perm) | Some p0, Some p1 -> b2p (sum_perm p0 p1 `lesser_equal_perm` full_perm) /// Composing them sums the permissions let compose_perm_opt (p0 p1:option perm) = match p0, p1 with | None, p | p, None -> p | Some p0, Some p1 -> Some (sum_perm p0 p1) /// Anchored permissions are composable when at most one of them has the anchor set let permission_composable #v (p0 p1 : permission v) : prop = let q0, s0 = p0 in let q1, s1 = p1 in perm_opt_composable q0 q1 /\ // some of fracs can't exceed 1 not (Some? s0 && Some? s1) // at most one can have an anchor /// Compose permissions component wise, keeping the anchor if set let compose_permissions (#v:_) (p0:permission v) (p1:permission v{permission_composable p0 p1}) : permission v = compose_perm_opt (fst p0) (fst p1), (match snd p0, snd p1 with | None, a | a, None -> a) /// This is the central definition of the PCM --- defining when two /// values are composable, or equivalently, when one thread's /// knowledge of [av0] is compatible with another thread's knowledge /// of [av1] /// /// This definition shows the interplay between fractions and anchors. /// It wasn't obvious to me how to factor this further, e.g., adding /// anchors to preorders and then separately adding fractions to it. let avalue_composable (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (av0 av1: avalue anchors) : prop = let (p0, v0) = av0 in let (p1, v1) = av1 in permission_composable p0 p1 /\ (if not (has_some_ownership p0) && not (has_some_ownership p1) then p_composable _ v0 v1 //neither has ownership, one history is older than the other else if not (has_some_ownership p0) && has_some_ownership p1 then ( if has_nonzero p1 then v1 `extends` v0 //the one with ownership is more recent else ( //this part is the most subtle assert (has_anchor p1); p_composable _ v0 v1 /\ (v0 `extends` v1 ==> //if v0 is a more recent snapshot than v1 //then v0 must still be anchored by v1's anchor anchor_of p1 `anchors` curval v0) ) ) else if has_some_ownership p0 && not (has_some_ownership p1) then ( //symmetric if has_nonzero p0 then v0 `extends` v1 else ( assert (has_anchor p0); p_composable _ v0 v1 /\ (v1 `extends` v0 ==> anchor_of p0 `anchors` curval v1) ) ) else ( assert (has_some_ownership p0 && has_some_ownership p1); if has_nonzero p0 && has_nonzero p1 then v0 == v1 //if both have non-zero perm, then they must both only have read permission and must agree on the value else if has_nonzero p0 && has_anchor p1 then ( assert (not (has_nonzero p1)); //The key part of the anchor semantics: v0 `extends` v1 /\ //v0 has advanceable ownership, so extends anchor_of p1 `anchors` curval v0 //but not beyond what is allowed by s ) else if has_anchor p0 && has_nonzero p1 //symmetric then ( assert (not (has_nonzero p0)); v1 `extends` v0 /\ anchor_of p0 `anchors` curval v1 //v1 extends, but not beyond what is allowed by s ) else (assert false; False) ) ) //exhaustive /// Lifting avalue comosability to knowledge, including the unit let composable #v (#p:preorder v) (#a:anchor_rel p) : symrel (knowledge a) = fun (k0 k1:knowledge a) -> match k0, k1 with | Nothing, _ | _, Nothing -> True | Owns m, Owns m' -> avalue_composable m m' /// Compose avalues by composing permissions and composing the values /// using the underlying preorder PCM let compose_avalue (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (m0:avalue anchors) (m1:avalue anchors { avalue_composable m0 m1 } ) : avalue anchors = let p0, v0 = m0 in let p1, v1 = m1 in let p12 = compose_permissions p0 p1 in let v12 = p_op _ v0 v1 in p12, v12 //////////////////////////////////////////////////////////////////////////////// (** avalue composition is associative and commutative **) let compose_avalue_comm (#v:Type) (#p:preorder v) (#anc:anchor_rel p) (m0: avalue anc) (m1: avalue anc{ avalue_composable m0 m1 }) : Lemma (compose_avalue m0 m1 == compose_avalue m1 m0) = () let avalue_composable_assoc_l (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (m0: avalue anchors) (m1: avalue anchors) (m2: avalue anchors { avalue_composable m1 m2 /\ avalue_composable m0 (compose_avalue m1 m2) }) : Lemma (avalue_composable m0 m1 /\ avalue_composable (compose_avalue m0 m1) m2) = () let compose_avalue_assoc_l (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m0: avalue s) (m1: avalue s) (m2: avalue s { avalue_composable m1 m2 /\ avalue_composable m0 (compose_avalue m1 m2) }) : Lemma (avalue_composable m0 m1 /\ avalue_composable (compose_avalue m0 m1) m2 /\ compose_avalue m0 (compose_avalue m1 m2) == compose_avalue (compose_avalue m0 m1) m2) = avalue_composable_assoc_l m0 m1 m2 let avalue_composable_assoc_r (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (m0: avalue anchors) (m1: avalue anchors) (m2: avalue anchors { avalue_composable m0 m1 /\ avalue_composable (compose_avalue m0 m1) m2 }) : Lemma (avalue_composable m1 m2 /\ avalue_composable m0 (compose_avalue m1 m2)) = () let compose_avalue_assoc_r (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m0: avalue s) (m1: avalue s) (m2: avalue s{ avalue_composable m0 m1 /\ avalue_composable (compose_avalue m0 m1) m2 }) : Lemma (avalue_composable m1 m2 /\ avalue_composable m0 (compose_avalue m1 m2) /\ compose_avalue m0 (compose_avalue m1 m2) == compose_avalue (compose_avalue m0 m1) m2) = avalue_composable_assoc_r m0 m1 m2 //////////////////////////////////////////////////////////////////////////////// /// lifting avalue composition to knowledge, including unit let compose (#v:Type) (#p:preorder v) (#s:anchor_rel p) (k0:knowledge s) (k1:knowledge s{ composable k0 k1 }) : knowledge s = match k0, k1 with | Nothing, k | k, Nothing -> k | Owns m, Owns m' -> Owns (compose_avalue m m') let composable_assoc_r #v (#p:preorder v) (#s:anchor_rel p) (k0 k1 k2: knowledge s) : Lemma (requires composable k0 k1 /\ composable (compose k0 k1) k2) (ensures composable k1 k2 /\ composable k0 (compose k1 k2) /\ compose k0 (compose k1 k2) == compose (compose k0 k1) k2 ) = match k0, k1, k2 with | Nothing, _, _ | _, Nothing, _ | _, _, Nothing -> () | Owns m0, Owns m1, Owns m2 -> compose_avalue_assoc_r m0 m1 m2 let composable_assoc_l #v (#p:preorder v) (#s:anchor_rel p) (k0 k1 k2: knowledge s) : Lemma (requires composable k1 k2 /\ composable k0 (compose k1 k2)) (ensures composable k0 k1 /\ composable (compose k0 k1) k2 /\ compose k0 (compose k1 k2) == compose (compose k0 k1) k2) = match k0, k1, k2 with | Nothing, _, _ | _, Nothing, _ | _, _, Nothing -> () | Owns m0, Owns m1, Owns m2 -> compose_avalue_assoc_l m0 m1 m2 /// Now, we can define our PCM /// The core of the PCM let p0 #v #p #s : pcm' (knowledge #v #p s) = { composable; op=compose; one=Nothing } let avalue_perm (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) = fst m /// A avalue represents full ownership when the fraction is full AND /// the anchor is set. This means that no knowledge held by any other /// thread can constrain this value meaningfully. let avalue_owns (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) : prop = fst (avalue_perm m) == Some full_perm /\ Some? (snd (avalue_perm m)) let full_knowledge #v #p #s (kn:knowledge #v #p s) : prop = match kn with | Nothing -> False | Owns km -> avalue_owns km /// The PCM itself, together with proofs of its properties let pcm #v #p #s : pcm (knowledge #v #p s) = { p = p0; comm = (fun k0 k1 -> match k0, k1 with | Nothing, _ | _, Nothing -> () | Owns m0, Owns m1 -> compose_avalue_comm m0 m1); assoc = (fun k0 k1 k2 -> composable_assoc_l k0 k1 k2); assoc_r = (fun k0 k1 k2 -> composable_assoc_r k0 k1 k2); is_unit = (fun _ -> ()); refine = full_knowledge; } /// Some utilities: The value of an avalue let avalue_val (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue #v #p s) = snd m /// Updating the value, in a full-ownership situation, also involves /// updating the anchor let avalue_update (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) (value:vhist p { s (curval value) (curval value) }) : avalue s = let p, _ = avalue_perm m in let p' = p, Some (curval value) in (p', value) /// Our core frame-preserving update: /// /// If you fully own a value, you can update it so long as you /// respect the preorder, and prove that the new value is related /// to itself by the anchor (since we'll be setting the anchor to /// the new value) /// /// This is a building block: we'll define a derived version that /// on values rather than histories #push-options "--z3rlimit_factor 2" let update_hist (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) (v1:vhist p { avalue_owns m /\ v1 `extends` avalue_val m /\ s (curval v1) (curval v1) }) : frame_preserving_upd pcm (Owns m) (Owns (avalue_update m v1)) = fun full_v -> let Owns full_m = full_v in let m_res = avalue_update full_m v1 in Owns m_res #pop-options /// Updating with value, rather than a history let avalue_update_value (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) (value:v { curval (avalue_val m) `p` value /\ s value value }) : m':avalue s { curval (avalue_val m') == value /\ avalue_val m' `extends` avalue_val m } = let v = avalue_val m in avalue_update m (extend_history v value) /// A derived frame-preserving update for which one presents only a value let update_value (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) (v1:v { avalue_owns m /\ //if you have full ownership of key curval (avalue_val m) `p` v1 /\ //you can update it wrt the preorder only s v1 v1 //and it is related to itself by the anchor }) : frame_preserving_upd pcm (Owns m) (Owns (avalue_update_value m v1)) = coerce_eq () (update_hist m (extend_history (avalue_val m) v1)) //F* goes nuts and starts swallowing gobs of memory without the coerce_eq: TODO, debug /// Now for anchored updates /// Ownership of the whole fraction, but not the anchor let avalue_owns_anchored (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) = fst (avalue_perm m) == Some full_perm /\ None? (snd (avalue_perm m)) /// [v1] is compatible with (i.e., not too far from) any anchor of [v0] let compat_with_any_anchor_of (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (v1:v) (v0:avalue anchors) = forall (anchor:v). anchor `anchors` curval (avalue_val v0) ==> anchor `anchors` v1 /// An anchored update: Update the value, but leave the permission /// unchanged Only possible if the new value is compatible with any /// anchor of the old value let avalue_anchored_update (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) (value:vhist p { curval value `compat_with_any_anchor_of` m }) : avalue s = avalue_perm m, value /// A frame-preserving update for anchored values.
{ "checked_file": "/", "dependencies": [ "Steel.Preorder.fst.checked", "Steel.FractionalPermission.fst.checked", "prims.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked" ], "interface_file": false, "source_file": "Steel.FractionalAnchoredPreorder.fst" }
[ { "abbrev": false, "full_module": "Steel.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Steel.Preorder", "short_module": null }, { "abbrev": false, "full_module": "FStar.Preorder", "short_module": null }, { "abbrev": false, "full_module": "FStar.PCM", "short_module": null }, { "abbrev": false, "full_module": "Steel", "short_module": null }, { "abbrev": false, "full_module": "Steel", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
m: Steel.FractionalAnchoredPreorder.avalue s -> v1: Steel.Preorder.vhist p { Steel.FractionalAnchoredPreorder.avalue_owns_anchored m /\ Steel.Preorder.extends v1 (Steel.FractionalAnchoredPreorder.avalue_val m) /\ Steel.FractionalAnchoredPreorder.compat_with_any_anchor_of (Steel.Preorder.curval v1) m } -> FStar.PCM.frame_preserving_upd Steel.FractionalAnchoredPreorder.pcm (Steel.FractionalAnchoredPreorder.Owns m) (Steel.FractionalAnchoredPreorder.Owns (Steel.FractionalAnchoredPreorder.avalue_anchored_update m v1))
Prims.Tot
[ "total" ]
[]
[ "FStar.Preorder.preorder", "Steel.FractionalAnchoredPreorder.anchor_rel", "Steel.FractionalAnchoredPreorder.avalue", "Steel.Preorder.vhist", "Prims.l_and", "Steel.FractionalAnchoredPreorder.avalue_owns_anchored", "Steel.Preorder.extends", "Steel.FractionalAnchoredPreorder.avalue_val", "Steel.FractionalAnchoredPreorder.compat_with_any_anchor_of", "Steel.Preorder.curval", "Steel.FractionalAnchoredPreorder.knowledge", "FStar.PCM.__proj__Mkpcm__item__refine", "Steel.FractionalAnchoredPreorder.pcm", "FStar.PCM.compatible", "Steel.FractionalAnchoredPreorder.Owns", "Steel.FractionalAnchoredPreorder.avalue_anchored_update", "Prims.l_Forall", "FStar.PCM.composable", "Prims.l_imp", "Prims.eq2", "FStar.PCM.op", "FStar.PCM.frame_preserving_upd" ]
[]
false
false
false
false
false
let update_anchored_hist (#v: Type) (#p: preorder v) (#s: anchor_rel p) (m: avalue s) (v1: vhist p { avalue_owns_anchored m /\ v1 `extends` (avalue_val m) /\ (curval v1) `compat_with_any_anchor_of` m }) : frame_preserving_upd pcm (Owns m) (Owns (avalue_anchored_update m v1)) =
fun full_v -> let Owns full_m = full_v in let m_res = avalue_anchored_update full_m v1 in Owns m_res
false
Vale.Arch.Types.fsti
Vale.Arch.Types.be_quad32_to_bytes
val be_quad32_to_bytes (q: quad32) : seq16 nat8
val be_quad32_to_bytes (q: quad32) : seq16 nat8
let be_quad32_to_bytes (q:quad32) : seq16 nat8 = seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE q))
{ "file_name": "vale/code/arch/Vale.Arch.Types.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 65, "end_line": 184, "start_col": 0, "start_line": 183 }
module Vale.Arch.Types open FStar.Mul open Vale.Def.Opaque_s open Vale.Def.Types_s open Vale.Lib.Seqs_s open Vale.Lib.Seqs open Vale.Def.Words_s open Vale.Def.Words.Four_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Seq open FStar.Seq open Vale.Def.Words.Two_s unfold let ( *^ ) = nat32_xor unfold let ( *^^ ) = quad32_xor unfold let add_wrap32 (x:nat32) (y:nat32) : nat32 = add_wrap x y unfold let add_wrap64 (x:nat64) (y:nat64) : nat64 = add_wrap x y unfold let sub_wrap32 (x:nat32) (y:nat32) : nat32 = sub_wrap x y unfold let sub_wrap64 (x:nat64) (y:nat64) : nat64 = sub_wrap x y unfold let iand32 (a:nat32) (b:nat32) : nat32 = iand a b unfold let ixor32 (a:nat32) (b:nat32) : nat32 = ixor a b unfold let ior32 (a:nat32) (b:nat32) : nat32 = ior a b unfold let inot32 (a:nat32) : nat32 = inot a unfold let ishl32 (a:nat32) (s:int) : nat32 = ishl a s unfold let ishr32 (a:nat32) (s:int) : nat32 = ishr a s unfold let iand64 (a:nat64) (b:nat64) : nat64 = iand a b unfold let ixor64 (a:nat64) (b:nat64) : nat64 = ixor a b unfold let ior64 (a:nat64) (b:nat64) : nat64 = ior a b unfold let inot64 (a:nat64) : nat64 = inot a unfold let ishl64 (a:nat64) (s:int) : nat64 = ishl a s unfold let ishr64 (a:nat64) (s:int) : nat64 = ishr a s unfold let iand128 (a:nat128) (b:nat128) : nat128 = iand a b unfold let ixor128 (a:nat128) (b:nat128) : nat128 = ixor a b unfold let ior128 (a:nat128) (b:nat128) : nat128 = ior a b unfold let inot128 (a:nat128) : nat128 = inot a unfold let ishl128 (a:nat128) (s:int) : nat128 = ishl a s unfold let ishr128 (a:nat128) (s:int) : nat128 = ishr a s unfold let two_to_nat32 (x:two nat32) : nat64 = two_to_nat 32 x val lemma_nat_to_two32 (_:unit) : Lemma (forall (x:nat64).{:pattern (nat_to_two 32 x)} nat_to_two 32 x == Mktwo (x % 0x100000000) (x / 0x100000000)) let quad32_shl32 (q:quad32) : quad32 = let Mkfour v0 v1 v2 v3 = q in Mkfour 0 v0 v1 v2 let add_wrap_quad32 (q0 q1:quad32) : quad32 = let open Vale.Def.Words_s in Mkfour (add_wrap q0.lo0 q1.lo0) (add_wrap q0.lo1 q1.lo1) (add_wrap q0.hi2 q1.hi2) (add_wrap q0.hi3 q1.hi3) val lemma_BitwiseXorCommutative (x y:nat32) : Lemma (x *^ y == y *^ x) val lemma_BitwiseXorWithZero (n:nat32) : Lemma (n *^ 0 == n) val lemma_BitwiseXorCancel (n:nat32) : Lemma (n *^ n == 0) val lemma_BitwiseXorCancel64 (n:nat64) : Lemma (ixor n n == 0) val lemma_BitwiseXorAssociative (x y z:nat32) : Lemma (x *^ (y *^ z) == (x *^ y) *^ z) val xor_lemmas (_:unit) : Lemma (ensures (forall (x y:nat32).{:pattern (x *^ y)} x *^ y == y *^ x) /\ (forall (n:nat32).{:pattern (n *^ 0)} n *^ 0 == n) /\ (forall (n:nat32).{:pattern (n *^ n)} n *^ n == 0) /\ (forall (n:nat64).{:pattern (ixor n n)} ixor n n == 0) /\ (forall (x y z:nat32).{:pattern (x *^ (y *^ z))} x *^ (y *^ z) == (x *^ y) *^ z) ) val lemma_quad32_xor (_:unit) : Lemma (forall q . {:pattern quad32_xor q q} quad32_xor q q == Mkfour 0 0 0 0) let quad32_double_lo (q:quad32) : double32 = (four_to_two_two q).lo let quad32_double_hi (q:quad32) : double32 = (four_to_two_two q).hi val lemma_reverse_reverse_bytes_nat32 (n:nat32) : Lemma (reverse_bytes_nat32 (reverse_bytes_nat32 n) == n) [SMTPat (reverse_bytes_nat32 (reverse_bytes_nat32 n))] val lemma_reverse_bytes_quad32 (q:quad32) : Lemma (reverse_bytes_quad32 (reverse_bytes_quad32 q) == q) [SMTPat (reverse_bytes_quad32 (reverse_bytes_quad32 q))] val lemma_reverse_bytes_quad32_zero (_:unit) : Lemma (let z = Mkfour 0 0 0 0 in reverse_bytes_quad32 z == z) val lemma_reverse_reverse_bytes_nat32_seq (s:seq nat32) : Lemma (reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s) == s) [SMTPat (reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s))] unfold let quad32_to_seq (q:quad32) : seq nat32 = four_to_seq_LE q val lemma_insert_nat64_properties (q:quad32) (n:nat64) : Lemma ( (let q' = insert_nat64 q n 0 in q'.hi2 == q.hi2 /\ q'.hi3 == q.hi3) /\ (let q' = insert_nat64 q n 1 in q'.lo0 == q.lo0 /\ q'.lo1 == q.lo1)) [SMTPat (insert_nat64 q n)] val lemma_insert_nat64_nat32s (q:quad32) (n0 n1:nat32) : Lemma ( insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 0 == Mkfour n0 n1 q.hi2 q.hi3 /\ insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 1 == Mkfour q.lo0 q.lo1 n0 n1 ) let lo64_def (q:quad32) : nat64 = two_to_nat 32 (two_select (four_to_two_two q) 0) [@"opaque_to_smt"] let lo64 = opaque_make lo64_def irreducible let lo64_reveal = opaque_revealer (`%lo64) lo64 lo64_def let hi64_def (q:quad32) : nat64 = two_to_nat 32 (two_select (four_to_two_two q) 1) [@"opaque_to_smt"] let hi64 = opaque_make hi64_def irreducible let hi64_reveal = opaque_revealer (`%hi64) hi64 hi64_def val lemma_lo64_properties (_:unit) : Lemma (forall (q0 q1:quad32).{:pattern lo64 q0; lo64 q1} (q0.lo0 == q1.lo0 /\ q0.lo1 == q1.lo1) <==> (lo64 q0 == lo64 q1)) val lemma_hi64_properties (_:unit) : Lemma (forall (q0 q1:quad32).{:pattern hi64 q0; hi64 q1} (q0.hi2 == q1.hi2 /\ q0.hi3 == q1.hi3) <==> (hi64 q0 == hi64 q1)) val lemma_reverse_bytes_quad32_64 (src orig final:quad32) : Lemma (requires final == insert_nat64 (insert_nat64 orig (reverse_bytes_nat64 (hi64 src)) 0) (reverse_bytes_nat64 (lo64 src)) 1) (ensures final == reverse_bytes_quad32 src) val lemma_equality_check_helper (q:quad32) : Lemma ((q.lo0 == 0 /\ q.lo1 == 0 ==> lo64 q == 0) /\ ((not (q.lo0 = 0) \/ not (q.lo1 = 0)) ==> not (lo64 q = 0)) /\ (q.hi2 == 0 /\ q.hi3 == 0 ==> hi64 q == 0) /\ ((~(q.hi2 = 0) \/ ~(q.hi3 = 0)) ==> ~(hi64 q = 0)) /\ (q.lo0 == 0xFFFFFFFF /\ q.lo1 == 0xFFFFFFFF <==> lo64 q == 0xFFFFFFFFFFFFFFFF) /\ (q.hi2 == 0xFFFFFFFF /\ q.hi3 == 0xFFFFFFFF <==> hi64 q == 0xFFFFFFFFFFFFFFFF) ) let lemma_equality_check_helper_2 (q1 q2 cmp:quad32) (tmp1 result1 tmp2 tmp3 result2:nat64) : Lemma (requires cmp == Mkfour (if q1.lo0 = q2.lo0 then 0xFFFFFFFF else 0) (if q1.lo1 = q2.lo1 then 0xFFFFFFFF else 0) (if q1.hi2 = q2.hi2 then 0xFFFFFFFF else 0) (if q1.hi3 = q2.hi3 then 0xFFFFFFFF else 0) /\ tmp1 = lo64 cmp /\ result1 = (if tmp1 = 0xFFFFFFFFFFFFFFFF then 0 else 1) /\ tmp2 = hi64 cmp /\ tmp3 = (if tmp2 = 0xFFFFFFFFFFFFFFFF then 0 else 1) /\ result2 = tmp3 + result1) (ensures (if q1 = q2 then result2 = 0 else result2 > 0)) = lemma_equality_check_helper cmp; () val push_pop_xmm (x y:quad32) : Lemma (let x' = insert_nat64 (insert_nat64 y (hi64 x) 1) (lo64 x) 0 in x == x') val lemma_insrq_extrq_relations (x y:quad32) : Lemma (let z = insert_nat64 x (lo64 y) 0 in z == Mkfour y.lo0 y.lo1 x.hi2 x.hi3 /\ (let z = insert_nat64 x (hi64 y) 1 in z == Mkfour x.lo0 x.lo1 y.hi2 y.hi3)) val le_bytes_to_nat64_to_bytes (s:nat64) : Lemma (le_bytes_to_nat64 (le_nat64_to_bytes s) == s) val le_nat64_to_bytes_to_nat64 (s:seq nat8 { length s == 8 }) : Lemma (le_nat64_to_bytes (le_bytes_to_nat64 s) == s) val le_bytes_to_seq_quad32_empty: unit -> Lemma (forall s . {:pattern (length (le_bytes_to_seq_quad32 s)) } length s == 0 ==> length (le_bytes_to_seq_quad32 s) == 0) val be_bytes_to_seq_quad32_empty: unit -> Lemma (forall s . {:pattern (length (be_bytes_to_seq_quad32 s)) } length s == 0 ==> length (be_bytes_to_seq_quad32 s) == 0) val le_bytes_to_seq_quad32_to_bytes_one_quad (b:quad32) : Lemma (le_bytes_to_seq_quad32 (le_quad32_to_bytes b) == create 1 b)
{ "checked_file": "/", "dependencies": [ "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Two_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Seq.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.Arch.Types.fsti" }
[ { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
q: Vale.Def.Types_s.quad32 -> Vale.Def.Words.Seq_s.seq16 Vale.Def.Words_s.nat8
Prims.Tot
[ "total" ]
[]
[ "Vale.Def.Types_s.quad32", "Vale.Def.Words.Seq_s.seq_four_to_seq_BE", "Vale.Def.Words_s.nat8", "Vale.Lib.Seqs_s.seq_map", "Vale.Def.Types_s.nat32", "Vale.Def.Words_s.four", "Vale.Def.Words.Four_s.nat_to_four", "Vale.Def.Words.Seq_s.four_to_seq_BE", "Vale.Def.Words.Seq_s.seq16" ]
[]
false
false
false
true
false
let be_quad32_to_bytes (q: quad32) : seq16 nat8 =
seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE q))
false
Steel.FractionalAnchoredPreorder.fst
Steel.FractionalAnchoredPreorder.update_hist
val update_hist (#v: Type) (#p: preorder v) (#s: anchor_rel p) (m: avalue s) (v1: vhist p {avalue_owns m /\ v1 `extends` (avalue_val m) /\ s (curval v1) (curval v1)}) : frame_preserving_upd pcm (Owns m) (Owns (avalue_update m v1))
val update_hist (#v: Type) (#p: preorder v) (#s: anchor_rel p) (m: avalue s) (v1: vhist p {avalue_owns m /\ v1 `extends` (avalue_val m) /\ s (curval v1) (curval v1)}) : frame_preserving_upd pcm (Owns m) (Owns (avalue_update m v1))
let update_hist (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) (v1:vhist p { avalue_owns m /\ v1 `extends` avalue_val m /\ s (curval v1) (curval v1) }) : frame_preserving_upd pcm (Owns m) (Owns (avalue_update m v1)) = fun full_v -> let Owns full_m = full_v in let m_res = avalue_update full_m v1 in Owns m_res
{ "file_name": "lib/steel/Steel.FractionalAnchoredPreorder.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 16, "end_line": 455, "start_col": 0, "start_line": 442 }
(* Copyright 2021 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. Author: N. Swamy *) module Steel.FractionalAnchoredPreorder (** This module provides a partial commutative monoid (PCM) for use in the ghost state of a concurrent Steel program. Its goal is to facilitate a form of information-sharing between multiple threads including the following features: Fractions, Preorders, Snapshots, and Anchors --- Anchors are the most unusual. 1. Fractions: Ownership of the state is controlled by a fractional permission, so multiple threads may share read-only privileges on the state, but only one can have write permission. 2. Preorders: The ghost state is governed by a preorder p and all updates to the state must respect the preorder (a reflexive, transitive relation on the state) 3. Snapshots: Since the state always evolves by a preorder, it is possible to take a snapshot of the state. A snapshot does not confer any particular ownership on the state, except knowledge of a snapshot ensures that the current state is related to the snapshot by the preorder. 4. Anchors are a kind of refinement of the preorder. If a thread owns an anchored value [v], then no other thread, even a thread owning a full fractional permission, can advance the state "too far" from the anchor. In particular, the PCM is parameterized by a binary relation on values, [anchors:anchor_relation]. If a thread owns the anchor [v], then the current value `cur` of the state must be in relation [v `anchors` cur]. This can be used to ensure that the knowledge of one thread is never becomes too stale. For example, this allows one to model a shared monotonically increasing counter, where if one thread anchors knowledge of the counter at the value 5, no other thread can increase the value of the counter beyond, say, 10, (when the anchor relation is y - x <= 5), until the anchoring thread releases the anchor. Further, at any point, a thread can take a snapshot of the counter and rely on the fact that the value of the counter in the future will be >= the snapshot. *) open FStar.PCM open FStar.Preorder open Steel.Preorder open Steel.FractionalPermission #push-options "--fuel 0 --ifuel 2" /// A permission: is a pair of /// /// * an optional fractional permission; with `Some p` indicating /// some ownership, while `None` is an additional "0" permission /// value, to encode snapshots. /// /// * and an optional anchor, where `Some a` indicates the current /// value can't be too far from `a`. let permission (v:Type) = option perm & option v /// Non-zero permission is either a read or write permission let has_nonzero #v (p:permission v) = Some? (fst p) /// Has an anchor set let has_anchor #v (p:permission v) = Some? (snd p) /// Either an anchor or non-zero let has_some_ownership #v (p:permission v) = has_nonzero p || has_anchor p /// The anchoring value let anchor_of #v (p:permission v { has_anchor p }) : v = Some?.v (snd p) /// The anchoring relation: /// -- A binary relation on values /// -- refining the preorder /// -- and if x `anchors` z then it also anchors any `y` between `x` and `z` /// /// Explaining the third clause a bit: /// Think intuitively of anchoring relations as a kind of distance measure /// /// if `z` is close enough to `x` then if `z` is further than `y` /// (since it is ahead of `y` in the preorder) then `y` is also /// close enough to `x` let anchor_rel (#v:Type) (p:preorder v) = anchors:(v -> v -> prop) { (forall v0 v1. anchors v0 v1 ==> p v0 v1) /\ (forall x z. x `anchors` z ==> (forall y. p x y /\ p y z ==> x `anchors` y)) // } /// An implementation remark: We use Steel.Preorder here to /// generically transform any preorder into a PCM. That works by /// taking the value of the PCM to be a history of values related by /// the preorder. So, throughout, we'll be using the the [vhist p] /// from Steel.Preorder, the type of a non-empty history compatible /// with [p]. The details of the histories don't matter much for our /// purposes---we only care about the most recent value, for which /// we'll use [curval v]. /// If the anchor is set, then the current value is anchored by it let anchored (#v:Type) (#p:preorder v) (anchors:anchor_rel p) (pv:(permission v & vhist p)) = has_anchor (fst pv) ==> anchor_of (fst pv) `anchors` curval (snd pv) /// A value in our fractional anchored PCM is a pair of a permission /// and a p-compatible history, refined to ensure that if the anchor /// is set, then the current value is anchored by it. let avalue (#v:Type) (#p:preorder v) (anchors:anchor_rel p) = pv:(permission v & vhist p) { anchored anchors pv } /// initial_value: A utility to construct a value in the PCM #push-options "--fuel 1" let initial_value (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (value:v { anchors value value }) : avalue anchors = (Some full_perm, Some value), [value] #pop-options /// We add a unit element to [avalue], as needed for a PCM [@@erasable] noeq type knowledge (#v:Type) (#p:preorder v) (anchors:anchor_rel p) = | Owns : avalue anchors -> knowledge anchors | Nothing : knowledge anchors let b2p (b:bool) : prop = b == true /// Fractional permissions are composable when their sum <= 1.0 let perm_opt_composable (p0 p1:option perm) : prop = match p0, p1 with | None, None -> True | Some p, None | None, Some p -> b2p (p `lesser_equal_perm` full_perm) | Some p0, Some p1 -> b2p (sum_perm p0 p1 `lesser_equal_perm` full_perm) /// Composing them sums the permissions let compose_perm_opt (p0 p1:option perm) = match p0, p1 with | None, p | p, None -> p | Some p0, Some p1 -> Some (sum_perm p0 p1) /// Anchored permissions are composable when at most one of them has the anchor set let permission_composable #v (p0 p1 : permission v) : prop = let q0, s0 = p0 in let q1, s1 = p1 in perm_opt_composable q0 q1 /\ // some of fracs can't exceed 1 not (Some? s0 && Some? s1) // at most one can have an anchor /// Compose permissions component wise, keeping the anchor if set let compose_permissions (#v:_) (p0:permission v) (p1:permission v{permission_composable p0 p1}) : permission v = compose_perm_opt (fst p0) (fst p1), (match snd p0, snd p1 with | None, a | a, None -> a) /// This is the central definition of the PCM --- defining when two /// values are composable, or equivalently, when one thread's /// knowledge of [av0] is compatible with another thread's knowledge /// of [av1] /// /// This definition shows the interplay between fractions and anchors. /// It wasn't obvious to me how to factor this further, e.g., adding /// anchors to preorders and then separately adding fractions to it. let avalue_composable (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (av0 av1: avalue anchors) : prop = let (p0, v0) = av0 in let (p1, v1) = av1 in permission_composable p0 p1 /\ (if not (has_some_ownership p0) && not (has_some_ownership p1) then p_composable _ v0 v1 //neither has ownership, one history is older than the other else if not (has_some_ownership p0) && has_some_ownership p1 then ( if has_nonzero p1 then v1 `extends` v0 //the one with ownership is more recent else ( //this part is the most subtle assert (has_anchor p1); p_composable _ v0 v1 /\ (v0 `extends` v1 ==> //if v0 is a more recent snapshot than v1 //then v0 must still be anchored by v1's anchor anchor_of p1 `anchors` curval v0) ) ) else if has_some_ownership p0 && not (has_some_ownership p1) then ( //symmetric if has_nonzero p0 then v0 `extends` v1 else ( assert (has_anchor p0); p_composable _ v0 v1 /\ (v1 `extends` v0 ==> anchor_of p0 `anchors` curval v1) ) ) else ( assert (has_some_ownership p0 && has_some_ownership p1); if has_nonzero p0 && has_nonzero p1 then v0 == v1 //if both have non-zero perm, then they must both only have read permission and must agree on the value else if has_nonzero p0 && has_anchor p1 then ( assert (not (has_nonzero p1)); //The key part of the anchor semantics: v0 `extends` v1 /\ //v0 has advanceable ownership, so extends anchor_of p1 `anchors` curval v0 //but not beyond what is allowed by s ) else if has_anchor p0 && has_nonzero p1 //symmetric then ( assert (not (has_nonzero p0)); v1 `extends` v0 /\ anchor_of p0 `anchors` curval v1 //v1 extends, but not beyond what is allowed by s ) else (assert false; False) ) ) //exhaustive /// Lifting avalue comosability to knowledge, including the unit let composable #v (#p:preorder v) (#a:anchor_rel p) : symrel (knowledge a) = fun (k0 k1:knowledge a) -> match k0, k1 with | Nothing, _ | _, Nothing -> True | Owns m, Owns m' -> avalue_composable m m' /// Compose avalues by composing permissions and composing the values /// using the underlying preorder PCM let compose_avalue (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (m0:avalue anchors) (m1:avalue anchors { avalue_composable m0 m1 } ) : avalue anchors = let p0, v0 = m0 in let p1, v1 = m1 in let p12 = compose_permissions p0 p1 in let v12 = p_op _ v0 v1 in p12, v12 //////////////////////////////////////////////////////////////////////////////// (** avalue composition is associative and commutative **) let compose_avalue_comm (#v:Type) (#p:preorder v) (#anc:anchor_rel p) (m0: avalue anc) (m1: avalue anc{ avalue_composable m0 m1 }) : Lemma (compose_avalue m0 m1 == compose_avalue m1 m0) = () let avalue_composable_assoc_l (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (m0: avalue anchors) (m1: avalue anchors) (m2: avalue anchors { avalue_composable m1 m2 /\ avalue_composable m0 (compose_avalue m1 m2) }) : Lemma (avalue_composable m0 m1 /\ avalue_composable (compose_avalue m0 m1) m2) = () let compose_avalue_assoc_l (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m0: avalue s) (m1: avalue s) (m2: avalue s { avalue_composable m1 m2 /\ avalue_composable m0 (compose_avalue m1 m2) }) : Lemma (avalue_composable m0 m1 /\ avalue_composable (compose_avalue m0 m1) m2 /\ compose_avalue m0 (compose_avalue m1 m2) == compose_avalue (compose_avalue m0 m1) m2) = avalue_composable_assoc_l m0 m1 m2 let avalue_composable_assoc_r (#v:Type) (#p:preorder v) (#anchors:anchor_rel p) (m0: avalue anchors) (m1: avalue anchors) (m2: avalue anchors { avalue_composable m0 m1 /\ avalue_composable (compose_avalue m0 m1) m2 }) : Lemma (avalue_composable m1 m2 /\ avalue_composable m0 (compose_avalue m1 m2)) = () let compose_avalue_assoc_r (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m0: avalue s) (m1: avalue s) (m2: avalue s{ avalue_composable m0 m1 /\ avalue_composable (compose_avalue m0 m1) m2 }) : Lemma (avalue_composable m1 m2 /\ avalue_composable m0 (compose_avalue m1 m2) /\ compose_avalue m0 (compose_avalue m1 m2) == compose_avalue (compose_avalue m0 m1) m2) = avalue_composable_assoc_r m0 m1 m2 //////////////////////////////////////////////////////////////////////////////// /// lifting avalue composition to knowledge, including unit let compose (#v:Type) (#p:preorder v) (#s:anchor_rel p) (k0:knowledge s) (k1:knowledge s{ composable k0 k1 }) : knowledge s = match k0, k1 with | Nothing, k | k, Nothing -> k | Owns m, Owns m' -> Owns (compose_avalue m m') let composable_assoc_r #v (#p:preorder v) (#s:anchor_rel p) (k0 k1 k2: knowledge s) : Lemma (requires composable k0 k1 /\ composable (compose k0 k1) k2) (ensures composable k1 k2 /\ composable k0 (compose k1 k2) /\ compose k0 (compose k1 k2) == compose (compose k0 k1) k2 ) = match k0, k1, k2 with | Nothing, _, _ | _, Nothing, _ | _, _, Nothing -> () | Owns m0, Owns m1, Owns m2 -> compose_avalue_assoc_r m0 m1 m2 let composable_assoc_l #v (#p:preorder v) (#s:anchor_rel p) (k0 k1 k2: knowledge s) : Lemma (requires composable k1 k2 /\ composable k0 (compose k1 k2)) (ensures composable k0 k1 /\ composable (compose k0 k1) k2 /\ compose k0 (compose k1 k2) == compose (compose k0 k1) k2) = match k0, k1, k2 with | Nothing, _, _ | _, Nothing, _ | _, _, Nothing -> () | Owns m0, Owns m1, Owns m2 -> compose_avalue_assoc_l m0 m1 m2 /// Now, we can define our PCM /// The core of the PCM let p0 #v #p #s : pcm' (knowledge #v #p s) = { composable; op=compose; one=Nothing } let avalue_perm (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) = fst m /// A avalue represents full ownership when the fraction is full AND /// the anchor is set. This means that no knowledge held by any other /// thread can constrain this value meaningfully. let avalue_owns (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) : prop = fst (avalue_perm m) == Some full_perm /\ Some? (snd (avalue_perm m)) let full_knowledge #v #p #s (kn:knowledge #v #p s) : prop = match kn with | Nothing -> False | Owns km -> avalue_owns km /// The PCM itself, together with proofs of its properties let pcm #v #p #s : pcm (knowledge #v #p s) = { p = p0; comm = (fun k0 k1 -> match k0, k1 with | Nothing, _ | _, Nothing -> () | Owns m0, Owns m1 -> compose_avalue_comm m0 m1); assoc = (fun k0 k1 k2 -> composable_assoc_l k0 k1 k2); assoc_r = (fun k0 k1 k2 -> composable_assoc_r k0 k1 k2); is_unit = (fun _ -> ()); refine = full_knowledge; } /// Some utilities: The value of an avalue let avalue_val (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue #v #p s) = snd m /// Updating the value, in a full-ownership situation, also involves /// updating the anchor let avalue_update (#v:Type) (#p:preorder v) (#s:anchor_rel p) (m:avalue s) (value:vhist p { s (curval value) (curval value) }) : avalue s = let p, _ = avalue_perm m in let p' = p, Some (curval value) in (p', value) /// Our core frame-preserving update: /// /// If you fully own a value, you can update it so long as you /// respect the preorder, and prove that the new value is related /// to itself by the anchor (since we'll be setting the anchor to /// the new value) /// /// This is a building block: we'll define a derived version that /// on values rather than histories
{ "checked_file": "/", "dependencies": [ "Steel.Preorder.fst.checked", "Steel.FractionalPermission.fst.checked", "prims.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.PCM.fst.checked" ], "interface_file": false, "source_file": "Steel.FractionalAnchoredPreorder.fst" }
[ { "abbrev": false, "full_module": "Steel.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Steel.Preorder", "short_module": null }, { "abbrev": false, "full_module": "FStar.Preorder", "short_module": null }, { "abbrev": false, "full_module": "FStar.PCM", "short_module": null }, { "abbrev": false, "full_module": "Steel", "short_module": null }, { "abbrev": false, "full_module": "Steel", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 2, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
m: Steel.FractionalAnchoredPreorder.avalue s -> v1: Steel.Preorder.vhist p { Steel.FractionalAnchoredPreorder.avalue_owns m /\ Steel.Preorder.extends v1 (Steel.FractionalAnchoredPreorder.avalue_val m) /\ s (Steel.Preorder.curval v1) (Steel.Preorder.curval v1) } -> FStar.PCM.frame_preserving_upd Steel.FractionalAnchoredPreorder.pcm (Steel.FractionalAnchoredPreorder.Owns m) (Steel.FractionalAnchoredPreorder.Owns (Steel.FractionalAnchoredPreorder.avalue_update m v1))
Prims.Tot
[ "total" ]
[]
[ "FStar.Preorder.preorder", "Steel.FractionalAnchoredPreorder.anchor_rel", "Steel.FractionalAnchoredPreorder.avalue", "Steel.Preorder.vhist", "Prims.l_and", "Steel.FractionalAnchoredPreorder.avalue_owns", "Steel.Preorder.extends", "Steel.FractionalAnchoredPreorder.avalue_val", "Steel.Preorder.curval", "Steel.FractionalAnchoredPreorder.knowledge", "FStar.PCM.__proj__Mkpcm__item__refine", "Steel.FractionalAnchoredPreorder.pcm", "FStar.PCM.compatible", "Steel.FractionalAnchoredPreorder.Owns", "Steel.FractionalAnchoredPreorder.avalue_update", "Prims.l_Forall", "FStar.PCM.composable", "Prims.l_imp", "Prims.eq2", "FStar.PCM.op", "FStar.PCM.frame_preserving_upd" ]
[]
false
false
false
false
false
let update_hist (#v: Type) (#p: preorder v) (#s: anchor_rel p) (m: avalue s) (v1: vhist p {avalue_owns m /\ v1 `extends` (avalue_val m) /\ s (curval v1) (curval v1)}) : frame_preserving_upd pcm (Owns m) (Owns (avalue_update m v1)) =
fun full_v -> let Owns full_m = full_v in let m_res = avalue_update full_m v1 in Owns m_res
false
Vale.PPC64LE.Stack_Sems.fst
Vale.PPC64LE.Stack_Sems.stack_from_s
val stack_from_s (s:machine_stack) : vale_stack
val stack_from_s (s:machine_stack) : vale_stack
let stack_from_s s = s
{ "file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.Stack_Sems.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 22, "end_line": 7, "start_col": 0, "start_line": 7 }
module Vale.PPC64LE.Stack_Sems open FStar.Mul friend Vale.PPC64LE.Stack_i
{ "checked_file": "/", "dependencies": [ "Vale.PPC64LE.Stack_i.fst.checked", "Vale.Lib.Set.fsti.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Map.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.PPC64LE.Stack_Sems.fst" }
[ { "abbrev": true, "full_module": "Vale.PPC64LE.Semantics_s", "short_module": "S" }, { "abbrev": false, "full_module": "Vale.PPC64LE.Stack_i", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
s: Vale.PPC64LE.Machine_s.machine_stack -> Vale.PPC64LE.Stack_i.vale_stack
Prims.Tot
[ "total" ]
[]
[ "Vale.PPC64LE.Machine_s.machine_stack", "Vale.PPC64LE.Stack_i.vale_stack" ]
[]
false
false
false
true
false
let stack_from_s s =
s
false
Vale.PPC64LE.Stack_Sems.fst
Vale.PPC64LE.Stack_Sems.stack_to_s
val stack_to_s (s:vale_stack) : machine_stack
val stack_to_s (s:vale_stack) : machine_stack
let stack_to_s s = s
{ "file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.Stack_Sems.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 20, "end_line": 6, "start_col": 0, "start_line": 6 }
module Vale.PPC64LE.Stack_Sems open FStar.Mul friend Vale.PPC64LE.Stack_i
{ "checked_file": "/", "dependencies": [ "Vale.PPC64LE.Stack_i.fst.checked", "Vale.Lib.Set.fsti.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Map.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.PPC64LE.Stack_Sems.fst" }
[ { "abbrev": true, "full_module": "Vale.PPC64LE.Semantics_s", "short_module": "S" }, { "abbrev": false, "full_module": "Vale.PPC64LE.Stack_i", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
s: Vale.PPC64LE.Stack_i.vale_stack -> Vale.PPC64LE.Machine_s.machine_stack
Prims.Tot
[ "total" ]
[]
[ "Vale.PPC64LE.Stack_i.vale_stack", "Vale.PPC64LE.Machine_s.machine_stack" ]
[]
false
false
false
true
false
let stack_to_s s =
s
false
Hacl.Poly1305.Field32xN.Lemmas0.fst
Hacl.Poly1305.Field32xN.Lemmas0.mul_felem5_eval_as_tup64
val mul_felem5_eval_as_tup64: #w:lanes -> f1:felem5 w{felem_fits5 f1 (3, 3, 3, 3, 3)} -> r:felem5 w{felem_fits5 r (2, 2, 2, 2, 2)} -> r5:felem5 w{felem_fits5 r5 (10, 10, 10, 10, 10) /\ r5 == precomp_r5 r} -> i:nat{i < w} -> Lemma (let (r0, r1, r2, r3, r4) = r in let (f10, f11, f12, f13, f14) = f1 in let (r50, r51, r52, r53, r54) = r5 in let (tr0, tr1, tr2, tr3, tr4) = as_tup64_i r i in let (tf10, tf11, tf12, tf13, tf14) = as_tup64_i f1 i in (uint64xN_v f10).[i] * (fas_nat5 (r0,r1,r2,r3,r4)).[i] + (uint64xN_v f11).[i] * (fas_nat5 (r54,r0,r1,r2,r3)).[i] + (uint64xN_v f12).[i] * (fas_nat5 (r53,r54,r0,r1,r2)).[i] + (uint64xN_v f13).[i] * (fas_nat5 (r52,r53,r54,r0,r1)).[i] + (uint64xN_v f14).[i] * (fas_nat5 (r51,r52,r53,r54,r0)).[i] == (v tf10 * as_nat5 (tr0, tr1, tr2, tr3, tr4) + v tf11 * as_nat5 (tr4 *! u64 5, tr0, tr1, tr2, tr3) + v tf12 * as_nat5 (tr3 *! u64 5, tr4 *! u64 5, tr0, tr1, tr2) + v tf13 * as_nat5 (tr2 *! u64 5, tr3 *! u64 5, tr4 *! u64 5, tr0, tr1) + v tf14 * as_nat5 (tr1 *! u64 5, tr2 *! u64 5, tr3 *! u64 5, tr4 *! u64 5, tr0)))
val mul_felem5_eval_as_tup64: #w:lanes -> f1:felem5 w{felem_fits5 f1 (3, 3, 3, 3, 3)} -> r:felem5 w{felem_fits5 r (2, 2, 2, 2, 2)} -> r5:felem5 w{felem_fits5 r5 (10, 10, 10, 10, 10) /\ r5 == precomp_r5 r} -> i:nat{i < w} -> Lemma (let (r0, r1, r2, r3, r4) = r in let (f10, f11, f12, f13, f14) = f1 in let (r50, r51, r52, r53, r54) = r5 in let (tr0, tr1, tr2, tr3, tr4) = as_tup64_i r i in let (tf10, tf11, tf12, tf13, tf14) = as_tup64_i f1 i in (uint64xN_v f10).[i] * (fas_nat5 (r0,r1,r2,r3,r4)).[i] + (uint64xN_v f11).[i] * (fas_nat5 (r54,r0,r1,r2,r3)).[i] + (uint64xN_v f12).[i] * (fas_nat5 (r53,r54,r0,r1,r2)).[i] + (uint64xN_v f13).[i] * (fas_nat5 (r52,r53,r54,r0,r1)).[i] + (uint64xN_v f14).[i] * (fas_nat5 (r51,r52,r53,r54,r0)).[i] == (v tf10 * as_nat5 (tr0, tr1, tr2, tr3, tr4) + v tf11 * as_nat5 (tr4 *! u64 5, tr0, tr1, tr2, tr3) + v tf12 * as_nat5 (tr3 *! u64 5, tr4 *! u64 5, tr0, tr1, tr2) + v tf13 * as_nat5 (tr2 *! u64 5, tr3 *! u64 5, tr4 *! u64 5, tr0, tr1) + v tf14 * as_nat5 (tr1 *! u64 5, tr2 *! u64 5, tr3 *! u64 5, tr4 *! u64 5, tr0)))
let mul_felem5_eval_as_tup64 #w f1 r r5 i = let (r0, r1, r2, r3, r4) = r in let (f10, f11, f12, f13, f14) = f1 in let (r50, r51, r52, r53, r54) = r5 in let (tr0, tr1, tr2, tr3, tr4) = as_tup64_i r i in let (tf10, tf11, tf12, tf13, tf14) = as_tup64_i f1 i in let (tr50, tr51, tr52, tr53, tr54) = as_tup64_i r5 i in assert ( (uint64xN_v f10).[i] * (fas_nat5 (r0,r1,r2,r3,r4)).[i] + (uint64xN_v f11).[i] * (fas_nat5 (r54,r0,r1,r2,r3)).[i] + (uint64xN_v f12).[i] * (fas_nat5 (r53,r54,r0,r1,r2)).[i] + (uint64xN_v f13).[i] * (fas_nat5 (r52,r53,r54,r0,r1)).[i] + (uint64xN_v f14).[i] * (fas_nat5 (r51,r52,r53,r54,r0)).[i] == v tf10 * as_nat5 (tr0,tr1,tr2,tr3,tr4) + v tf11 * as_nat5 (tr54,tr0,tr1,tr2,tr3) + v tf12 * as_nat5 (tr53,tr54,tr0,tr1,tr2) + v tf13 * as_nat5 (tr52,tr53,tr54,tr0,tr1) + v tf14 * as_nat5 (tr51,tr52,tr53,tr54,tr0)); precomp_r5_as_tup64 #w r i
{ "file_name": "code/poly1305/Hacl.Poly1305.Field32xN.Lemmas0.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 28, "end_line": 730, "start_col": 0, "start_line": 712 }
module Hacl.Poly1305.Field32xN.Lemmas0 open Lib.IntTypes open Lib.IntVector open Lib.Sequence open FStar.Mul open FStar.Calc open Hacl.Spec.Poly1305.Vec include Hacl.Spec.Poly1305.Field32xN #reset-options "--z3rlimit 50 --using_facts_from '* -FStar.Seq' --max_fuel 0 --max_ifuel 0" val lemma_prime: unit -> Lemma (pow2 130 % prime = 5) let lemma_prime () = assert_norm (pow2 130 % prime = 5 % prime); assert_norm (5 < prime); FStar.Math.Lemmas.modulo_lemma 5 prime val lemma_mult_le: a:nat -> b:nat -> c:nat -> d:nat -> Lemma (requires a <= b /\ c <= d) (ensures a * c <= b * d) let lemma_mult_le a b c d = () val lemma_mul5_distr_l: a:nat -> b:nat -> c:nat -> d:nat -> e:nat -> f:nat -> Lemma (a * (b + c + d + e + f) == a * b + a * c + a * d + a * e + a * f) let lemma_mul5_distr_l a b c d e f = () val lemma_mul5_distr_r: a:nat -> b:nat -> c:nat -> d:nat -> e:nat -> f:nat -> Lemma ((a + b + c + d + e) * f == a * f + b * f + c * f + d * f + e * f) let lemma_mul5_distr_r a b c d e f = () val smul_mod_lemma: #m1:scale32 -> #m2:scale32 -> a:nat{a <= m1 * max26} -> b:nat{b <= m2 * max26} -> Lemma (a * b % pow2 64 == a * b) let smul_mod_lemma #m1 #m2 a b = lemma_mult_le a (m1 * max26) b (m2 * max26); assert (a * b <= m1 * m2 * max26 * max26); FStar.Math.Lemmas.modulo_lemma (a * b) (pow2 64) val smul_add_mod_lemma: #m1:scale32 -> #m2:scale32 -> #m3:scale64{m3 + m1 * m2 <= 4096} -> a:nat{a <= m1 * max26} -> b:nat{b <= m2 * max26} -> c:nat{c <= m3 * max26 * max26} -> Lemma ((c + a * b % pow2 64) % pow2 64 == c + a * b) let smul_add_mod_lemma #m1 #m2 #m3 a b c = assert_norm ((m3 + m1 * m2) * max26 * max26 < pow2 64); lemma_mult_le a (m1 * max26) b (m2 * max26); assert (c + a * b <= m3 * max26 * max26 + m1 * m2 * max26 * max26); FStar.Math.Lemmas.modulo_lemma (c + a * b) (pow2 64) val add5_lemma1: ma:scale64 -> mb:scale64 -> a:uint64 -> b:uint64 -> Lemma (requires v a <= ma * max26 /\ v b <= mb * max26 /\ ma + mb <= 64) (ensures v (a +. b) == v a + v b /\ v (a +. b) <= (ma + mb) * max26) let add5_lemma1 ma mb a b = assert (v a + v b <= (ma + mb) * max26); Math.Lemmas.lemma_mult_le_right max26 (ma + mb) 64; assert (v a + v b <= 64 * max26); assert_norm (64 * max26 < pow2 32); Math.Lemmas.small_mod (v a + v b) (pow2 32) #set-options "--ifuel 1" val fadd5_eval_lemma_i: #w:lanes -> f1:felem5 w{felem_fits5 f1 (2,2,2,2,2)} -> f2:felem5 w{felem_fits5 f2 (1,1,1,1,1)} -> i:nat{i < w} -> Lemma ((feval5 (fadd5 f1 f2)).[i] == pfadd (feval5 f1).[i] (feval5 f2).[i]) let fadd5_eval_lemma_i #w f1 f2 i = let o = fadd5 f1 f2 in let (f10, f11, f12, f13, f14) = as_tup64_i f1 i in let (f20, f21, f22, f23, f24) = as_tup64_i f2 i in let (o0, o1, o2, o3, o4) = as_tup64_i o i in add5_lemma1 2 1 f10 f20; add5_lemma1 2 1 f11 f21; add5_lemma1 2 1 f12 f22; add5_lemma1 2 1 f13 f23; add5_lemma1 2 1 f14 f24; assert (as_nat5 (o0, o1, o2, o3, o4) == as_nat5 (f10, f11, f12, f13, f14) + as_nat5 (f20, f21, f22, f23, f24)); FStar.Math.Lemmas.lemma_mod_plus_distr_l (as_nat5 (f10, f11, f12, f13, f14)) (as_nat5 (f20, f21, f22, f23, f24)) prime; FStar.Math.Lemmas.lemma_mod_plus_distr_r (as_nat5 (f10, f11, f12, f13, f14) % prime) (as_nat5 (f20, f21, f22, f23, f24)) prime val smul_felem5_fits_lemma_i: #w:lanes -> #m1:scale32 -> #m2:scale32 -> u1:uint64xN w{felem_fits1 u1 m1} -> f2:uint64xN w{felem_fits1 f2 m2} -> i:nat{i < w} -> Lemma ((uint64xN_v (vec_mul_mod f2 u1)).[i] <= m1 * m2 * max26 * max26) let smul_felem5_fits_lemma_i #w #m1 #m2 u1 f2 i = let o = vec_mul_mod f2 u1 in smul_mod_lemma #m1 #m2 (uint64xN_v u1).[i] (uint64xN_v f2).[i]; assert ((uint64xN_v o).[i] == (uint64xN_v u1).[i] * (uint64xN_v f2).[i]); lemma_mult_le (uint64xN_v u1).[i] (m1 * max26) (uint64xN_v f2).[i] (m2 * max26) val smul_felem5_eval_lemma_i: #w:lanes -> #m1:scale32 -> #m2:scale32_5 -> u1:uint64xN w{felem_fits1 u1 m1} -> f2:felem5 w{felem_fits5 f2 m2} -> i:nat{i < w} -> Lemma ((fas_nat5 (smul_felem5 #w u1 f2)).[i] == (uint64xN_v u1).[i] * (fas_nat5 f2).[i]) let smul_felem5_eval_lemma_i #w #m1 #m2 u1 f2 i = let o = smul_felem5 #w u1 f2 in let (m20, m21, m22, m23, m24) = m2 in let vu1 = (uint64xN_v u1).[i] in let (tf20, tf21, tf22, tf23, tf24) = as_tup64_i f2 i in let (to0, to1, to2, to3, to4) = as_tup64_i o i in smul_mod_lemma #m1 #m20 vu1 (v tf20); smul_mod_lemma #m1 #m21 vu1 (v tf21); smul_mod_lemma #m1 #m22 vu1 (v tf22); smul_mod_lemma #m1 #m23 vu1 (v tf23); smul_mod_lemma #m1 #m24 vu1 (v tf24); assert ((fas_nat5 o).[i] == vu1 * v tf20 + vu1 * v tf21 * pow26 + vu1 * v tf22 * pow52 + vu1 * v tf23 * pow78 + vu1 * v tf24 * pow104); calc (==) { vu1 * (fas_nat5 f2).[i]; (==) { } vu1 * (v tf20 + v tf21 * pow26 + v tf22 * pow52 + v tf23 * pow78 + v tf24 * pow104); (==) { lemma_mul5_distr_l vu1 (v tf20) (v tf21 * pow26) (v tf22 * pow52) (v tf23 * pow78) (v tf24 * pow104)} vu1 * v tf20 + vu1 * (v tf21 * pow26) + vu1 * (v tf22 * pow52) + vu1 * (v tf23 * pow78) + vu1 * (v tf24 * pow104); (==) { FStar.Math.Lemmas.paren_mul_right vu1 (v tf21) pow26; FStar.Math.Lemmas.paren_mul_right vu1 (v tf22) pow52; FStar.Math.Lemmas.paren_mul_right vu1 (v tf23) pow78; FStar.Math.Lemmas.paren_mul_right vu1 (v tf24) pow104} vu1 * v tf20 + vu1 * v tf21 * pow26 + vu1 * v tf22 * pow52 + vu1 * v tf23 * pow78 + vu1 * v tf24 * pow104; }; assert (vu1 * (fas_nat5 f2).[i] == (fas_nat5 o).[i]) val smul_felem5_fits_lemma1: #w:lanes -> #m1:scale32 -> #m2:scale32 -> u1:uint64xN w{felem_fits1 u1 m1} -> f2:uint64xN w{felem_fits1 f2 m2} -> Lemma (felem_wide_fits1 (vec_mul_mod f2 u1) (m1 * m2)) let smul_felem5_fits_lemma1 #w #m1 #m2 u1 f2 = match w with | 1 -> smul_felem5_fits_lemma_i #w #m1 #m2 u1 f2 0 | 2 -> smul_felem5_fits_lemma_i #w #m1 #m2 u1 f2 0; smul_felem5_fits_lemma_i #w #m1 #m2 u1 f2 1 | 4 -> smul_felem5_fits_lemma_i #w #m1 #m2 u1 f2 0; smul_felem5_fits_lemma_i #w #m1 #m2 u1 f2 1; smul_felem5_fits_lemma_i #w #m1 #m2 u1 f2 2; smul_felem5_fits_lemma_i #w #m1 #m2 u1 f2 3 val smul_felem5_fits_lemma: #w:lanes -> #m1:scale32 -> #m2:scale32_5 -> u1:uint64xN w{felem_fits1 u1 m1} -> f2:felem5 w{felem_fits5 f2 m2} -> Lemma (felem_wide_fits5 (smul_felem5 #w u1 f2) (m1 *^ m2)) let smul_felem5_fits_lemma #w #m1 #m2 u1 f2 = let (f20, f21, f22, f23, f24) = f2 in let (m20, m21, m22, m23, m24) = m2 in smul_felem5_fits_lemma1 #w #m1 #m20 u1 f20; smul_felem5_fits_lemma1 #w #m1 #m21 u1 f21; smul_felem5_fits_lemma1 #w #m1 #m22 u1 f22; smul_felem5_fits_lemma1 #w #m1 #m23 u1 f23; smul_felem5_fits_lemma1 #w #m1 #m24 u1 f24 val smul_felem5_eval_lemma: #w:lanes -> #m1:scale32 -> #m2:scale32_5 -> u1:uint64xN w{felem_fits1 u1 m1} -> f2:felem5 w{felem_fits5 f2 m2} -> Lemma (fas_nat5 (smul_felem5 #w u1 f2) == map2 #nat #nat #nat (fun a b -> a * b) (uint64xN_v u1) (fas_nat5 f2)) let smul_felem5_eval_lemma #w #m1 #m2 u1 f2 = FStar.Classical.forall_intro (smul_felem5_eval_lemma_i #w #m1 #m2 u1 f2); eq_intro (fas_nat5 (smul_felem5 #w u1 f2)) (map2 #nat #nat #nat (fun a b -> a * b) (uint64xN_v u1) (fas_nat5 f2)) val smul_add_felem5_fits_lemma_i: #w:lanes -> #m1:scale32 -> #m2:scale32 -> #m3:scale64{m3 + m1 * m2 <= 4096} -> u1:uint64xN w{felem_fits1 u1 m1} -> f2:uint64xN w{felem_fits1 f2 m2} -> acc1:uint64xN w{felem_wide_fits1 acc1 m3} -> i:nat{i < w} -> Lemma ((uint64xN_v (vec_add_mod acc1 (vec_mul_mod f2 u1))).[i] <= (m3 + m1 * m2) * max26 * max26) #push-options "--z3rlimit 200" let smul_add_felem5_fits_lemma_i #w #m1 #m2 #m3 u1 f2 acc1 i = let o = vec_add_mod acc1 (vec_mul_mod f2 u1) in smul_add_mod_lemma #m1 #m2 #m3 (uint64xN_v u1).[i] (uint64xN_v f2).[i] (uint64xN_v acc1).[i]; assert ((uint64xN_v o).[i] == (uint64xN_v acc1).[i] + (uint64xN_v u1).[i] * (uint64xN_v f2).[i]); lemma_mult_le (uint64xN_v u1).[i] (m1 * max26) (uint64xN_v f2).[i] (m2 * max26); assert ((uint64xN_v o).[i] <= m3 * max26 * max26 + m1 * m2 * max26 * max26) #pop-options val smul_add_felem5_eval_lemma_i: #w:lanes -> #m1:scale32 -> #m2:scale32_5 -> #m3:scale64_5{m3 +* m1 *^ m2 <=* s64x5 4096} -> u1:uint64xN w{felem_fits1 u1 m1} -> f2:felem5 w{felem_fits5 f2 m2} -> acc1:felem_wide5 w{felem_wide_fits5 acc1 m3} -> i:nat{i < w} -> Lemma ((fas_nat5 (smul_add_felem5 #w u1 f2 acc1)).[i] == (fas_nat5 acc1).[i] + (uint64xN_v u1).[i] * (fas_nat5 f2).[i]) let smul_add_felem5_eval_lemma_i #w #m1 #m2 #m3 u1 f2 acc1 i = let o = smul_add_felem5 #w u1 f2 acc1 in let (m20, m21, m22, m23, m24) = m2 in let (m30, m31, m32, m33, m34) = m3 in let vu1 = (uint64xN_v u1).[i] in let (tf20, tf21, tf22, tf23, tf24) = as_tup64_i f2 i in let (ta0, ta1, ta2, ta3, ta4) = as_tup64_i acc1 i in let (to0, to1, to2, to3, to4) = as_tup64_i o i in smul_add_mod_lemma #m1 #m20 #m30 vu1 (v tf20) (v ta0); smul_add_mod_lemma #m1 #m21 #m31 vu1 (v tf21) (v ta1); smul_add_mod_lemma #m1 #m22 #m32 vu1 (v tf22) (v ta2); smul_add_mod_lemma #m1 #m23 #m33 vu1 (v tf23) (v ta3); smul_add_mod_lemma #m1 #m24 #m34 vu1 (v tf24) (v ta4); calc (==) { (fas_nat5 o).[i]; (==) { } v ta0 + vu1 * v tf20 + (v ta1 + vu1 * v tf21) * pow26 + (v ta2 + vu1 * v tf22) * pow52 + (v ta3 + vu1 * v tf23) * pow78 + (v ta4 + vu1 * v tf24) * pow104; (==) { FStar.Math.Lemmas.distributivity_add_left (v ta1) (vu1 * v tf21) pow26; FStar.Math.Lemmas.distributivity_add_left (v ta2) (vu1 * v tf22) pow52; FStar.Math.Lemmas.distributivity_add_left (v ta3) (vu1 * v tf23) pow78; FStar.Math.Lemmas.distributivity_add_left (v ta1) (vu1 * v tf24) pow104 } v ta0 + v ta1 * pow26 + v ta2 * pow52 + v ta3 * pow78 + v ta4 * pow104 + vu1 * v tf20 + vu1 * v tf21 * pow26 + vu1 * v tf22 * pow52 + vu1 * v tf23 * pow78 + vu1 * v tf24 * pow104; (==) { } (fas_nat5 acc1).[i] + vu1 * v tf20 + vu1 * v tf21 * pow26 + vu1 * v tf22 * pow52 + vu1 * v tf23 * pow78 + vu1 * v tf24 * pow104; }; assert ((fas_nat5 o).[i] == (fas_nat5 acc1).[i] + vu1 * v tf20 + vu1 * v tf21 * pow26 + vu1 * v tf22 * pow52 + vu1 * v tf23 * pow78 + vu1 * v tf24 * pow104); calc (==) { vu1 * (fas_nat5 f2).[i]; (==) { } vu1 * (v tf20 + v tf21 * pow26 + v tf22 * pow52 + v tf23 * pow78 + v tf24 * pow104); (==) { lemma_mul5_distr_l vu1 (v tf20) (v tf21 * pow26) (v tf22 * pow52) (v tf23 * pow78) (v tf24 * pow104)} vu1 * v tf20 + vu1 * (v tf21 * pow26) + vu1 * (v tf22 * pow52) + vu1 * (v tf23 * pow78) + vu1 * (v tf24 * pow104); (==) { FStar.Math.Lemmas.paren_mul_right vu1 (v tf21) pow26; FStar.Math.Lemmas.paren_mul_right vu1 (v tf22) pow52; FStar.Math.Lemmas.paren_mul_right vu1 (v tf23) pow78; FStar.Math.Lemmas.paren_mul_right vu1 (v tf24) pow104} vu1 * v tf20 + vu1 * v tf21 * pow26 + vu1 * v tf22 * pow52 + vu1 * v tf23 * pow78 + vu1 * v tf24 * pow104; }; assert ((fas_nat5 o).[i] == (fas_nat5 acc1).[i] + vu1 * (fas_nat5 f2).[i]) val smul_add_felem5_fits_lemma1: #w:lanes -> #m1:scale32 -> #m2:scale32 -> #m3:scale64{m3 + m1 * m2 <= 4096} -> u1:uint64xN w{felem_fits1 u1 m1} -> f2:uint64xN w{felem_fits1 f2 m2} -> acc1:uint64xN w{felem_wide_fits1 acc1 m3} -> Lemma (felem_wide_fits1 (vec_add_mod acc1 (vec_mul_mod f2 u1)) (m3 + m1 * m2)) let smul_add_felem5_fits_lemma1 #w #m1 #m2 #m3 u1 f2 acc1 = match w with | 1 -> smul_add_felem5_fits_lemma_i #w #m1 #m2 #m3 u1 f2 acc1 0 | 2 -> smul_add_felem5_fits_lemma_i #w #m1 #m2 #m3 u1 f2 acc1 0; smul_add_felem5_fits_lemma_i #w #m1 #m2 #m3 u1 f2 acc1 1 | 4 -> smul_add_felem5_fits_lemma_i #w #m1 #m2 #m3 u1 f2 acc1 0; smul_add_felem5_fits_lemma_i #w #m1 #m2 #m3 u1 f2 acc1 1; smul_add_felem5_fits_lemma_i #w #m1 #m2 #m3 u1 f2 acc1 2; smul_add_felem5_fits_lemma_i #w #m1 #m2 #m3 u1 f2 acc1 3 val smul_add_felem5_fits_lemma: #w:lanes -> #m1:scale32 -> #m2:scale32_5 -> #m3:scale64_5{m3 +* m1 *^ m2 <=* s64x5 4096} -> u1:uint64xN w{felem_fits1 u1 m1} -> f2:felem5 w{felem_fits5 f2 m2} -> acc1:felem_wide5 w{felem_wide_fits5 acc1 m3} -> Lemma (felem_wide_fits5 (smul_add_felem5 #w u1 f2 acc1) (m3 +* m1 *^ m2)) let smul_add_felem5_fits_lemma #w #m1 #m2 #m3 u1 f2 acc1 = let (f20, f21, f22, f23, f24) = f2 in let (m20, m21, m22, m23, m24) = m2 in let (a0, a1, a2, a3, a4) = acc1 in let (m30, m31, m32, m33, m34) = m3 in smul_add_felem5_fits_lemma1 #w #m1 #m20 #m30 u1 f20 a0; smul_add_felem5_fits_lemma1 #w #m1 #m21 #m31 u1 f21 a1; smul_add_felem5_fits_lemma1 #w #m1 #m22 #m32 u1 f22 a2; smul_add_felem5_fits_lemma1 #w #m1 #m23 #m33 u1 f23 a3; smul_add_felem5_fits_lemma1 #w #m1 #m24 #m34 u1 f24 a4 val smul_add_felem5_eval_lemma: #w:lanes -> #m1:scale32 -> #m2:scale32_5 -> #m3:scale64_5{m3 +* m1 *^ m2 <=* s64x5 4096} -> u1:uint64xN w{felem_fits1 u1 m1} -> f2:felem5 w{felem_fits5 f2 m2} -> acc1:felem_wide5 w{felem_wide_fits5 acc1 m3} -> Lemma (fas_nat5 (smul_add_felem5 #w u1 f2 acc1) == map2 #nat #nat #nat (fun a b -> a + b) (fas_nat5 acc1) (map2 #nat #nat #nat (fun a b -> a * b) (uint64xN_v u1) (fas_nat5 f2))) let smul_add_felem5_eval_lemma #w #m1 #m2 #m3 u1 f2 acc1 = let tmp = map2 #nat #nat #nat (fun a b -> a + b) (fas_nat5 acc1) (map2 #nat #nat #nat (fun a b -> a * b) (uint64xN_v u1) (fas_nat5 f2)) in FStar.Classical.forall_intro (smul_add_felem5_eval_lemma_i #w #m1 #m2 #m3 u1 f2 acc1); eq_intro (fas_nat5 (smul_add_felem5 #w u1 f2 acc1)) tmp val lemma_fmul5_pow26: r:tup64_5 -> Lemma (requires (let (r0, r1, r2, r3, r4) = r in v r4 * 5 <= 10 * pow26)) (ensures (let (r0, r1, r2, r3, r4) = r in (pow26 * as_nat5 r) % prime == as_nat5 (r4 *! u64 5, r0, r1, r2, r3) % prime)) let lemma_fmul5_pow26 r = let (r0, r1, r2, r3, r4) = r in calc (==) { (pow26 * as_nat5 r) % prime; (==) { } (pow26 * (v r0 + v r1 * pow26 + v r2 * pow52 + v r3 * pow78 + v r4 * pow104)) % prime; (==) { lemma_mul5_distr_l pow26 (v r0) (v r1 * pow26) (v r2 * pow52) (v r3 * pow78) (v r4 * pow104) } (v r0 * pow26 + pow26 * v r1 * pow26 + pow26 * v r2 * pow52 + pow26 * v r3 * pow78 + pow26 * v r4 * pow104) % prime; (==) { } (v r0 * pow26 + v r1 * pow26 * pow26 + v r2 * pow26 * pow52 + v r3 * pow26 * pow78 + v r4 * pow26 * pow104) % prime; (==) { assert_norm (pow26 * pow26 = pow52); assert_norm (pow26 * pow52 = pow78); assert_norm (pow26 * pow78 = pow104); assert_norm (pow26 * pow104 = pow2 130) } (v r0 * pow26 + v r1 * pow52 + v r2 * pow78 + v r3 * pow104 + v r4 * pow2 130) % prime; (==) { FStar.Math.Lemmas.lemma_mod_plus_distr_r (v r0 * pow26 + v r1 * pow52 + v r2 * pow78 + v r3 * pow104) (v r4 * pow2 130) prime } (v r0 * pow26 + v r1 * pow52 + v r2 * pow78 + v r3 * pow104 + (v r4 * pow2 130) % prime) % prime; (==) { FStar.Math.Lemmas.lemma_mod_mul_distr_r (v r4) (pow2 130) prime } (v r0 * pow26 + v r1 * pow52 + v r2 * pow78 + v r3 * pow104 + (v r4 * (pow2 130 % prime)) % prime) % prime; (==) { lemma_prime () } (v r0 * pow26 + v r1 * pow52 + v r2 * pow78 + v r3 * pow104 + (v r4 * 5) % prime) % prime; (==) { FStar.Math.Lemmas.lemma_mod_plus_distr_r (v r0 * pow26 + v r1 * pow52 + v r2 * pow78 + v r3 * pow104) (v r4 * 5) prime } (v r0 * pow26 + v r1 * pow52 + v r2 * pow78 + v r3 * pow104 + v r4 * 5) % prime; }; assert ((pow26 * as_nat5 r) % prime == (v r0 * pow26 + v r1 * pow52 + v r2 * pow78 + v r3 * pow104 + v r4 * 5) % prime) val lemma_fmul5_pow52: r:tup64_5 -> Lemma (requires (let (r0, r1, r2, r3, r4) = r in v r4 * 5 <= 10 * pow26 /\ v r3 * 5 <= 10 * pow26)) (ensures (let (r0, r1, r2, r3, r4) = r in (pow52 * as_nat5 r) % prime == as_nat5 (r3 *! u64 5, r4 *! u64 5, r0, r1, r2) % prime)) let lemma_fmul5_pow52 r = let (r0, r1, r2, r3, r4) = r in calc (==) { (pow52 * as_nat5 r) % prime; (==) { assert_norm (pow52 == pow26 * pow26) } (pow26 * pow26 * as_nat5 r) % prime; (==) { FStar.Math.Lemmas.paren_mul_right pow26 pow26 (as_nat5 r); FStar.Math.Lemmas.lemma_mod_mul_distr_r pow26 (pow26 * as_nat5 r) prime } (pow26 * (pow26 * as_nat5 r % prime)) % prime; (==) { lemma_fmul5_pow26 r } (pow26 * (as_nat5 (r4 *! u64 5, r0, r1, r2, r3) % prime)) % prime; (==) { FStar.Math.Lemmas.lemma_mod_mul_distr_r pow26 (as_nat5 (r4 *! u64 5, r0, r1, r2, r3)) prime } (pow26 * as_nat5 (r4 *! u64 5, r0, r1, r2, r3)) % prime; (==) { lemma_fmul5_pow26 (r4 *! u64 5, r0, r1, r2, r3) } as_nat5 (r3 *! u64 5, r4 *! u64 5, r0, r1, r2) % prime; }; assert ((pow52 * as_nat5 r) % prime == as_nat5 (r3 *! u64 5, r4 *! u64 5, r0, r1, r2) % prime) val lemma_fmul5_pow78: r:tup64_5 -> Lemma (requires (let (r0, r1, r2, r3, r4) = r in v r4 * 5 <= 10 * pow26 /\ v r3 * 5 <= 10 * pow26 /\ v r2 * 5 <= 10 * pow26)) (ensures (let (r0, r1, r2, r3, r4) = r in (pow78 * as_nat5 r) % prime == as_nat5 (r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0, r1) % prime)) let lemma_fmul5_pow78 r = let (r0, r1, r2, r3, r4) = r in calc (==) { (pow78 * as_nat5 r) % prime; (==) { assert_norm (pow78 == pow26 * pow52) } (pow26 * pow52 * as_nat5 r) % prime; (==) { FStar.Math.Lemmas.paren_mul_right pow26 pow52 (as_nat5 r); FStar.Math.Lemmas.lemma_mod_mul_distr_r pow26 (pow52 * as_nat5 r) prime } (pow26 * (pow52 * as_nat5 r % prime)) % prime; (==) { lemma_fmul5_pow52 r } (pow26 * (as_nat5 (r3 *! u64 5, r4 *! u64 5, r0, r1, r2) % prime)) % prime; (==) { FStar.Math.Lemmas.lemma_mod_mul_distr_r pow26 (as_nat5 (r3 *! u64 5, r4 *! u64 5, r0, r1, r2)) prime } (pow26 * as_nat5 (r3 *! u64 5, r4 *! u64 5, r0, r1, r2)) % prime; (==) { lemma_fmul5_pow26 (r3 *! u64 5, r4 *! u64 5, r0, r1, r2) } as_nat5 (r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0, r1) % prime; }; assert ((pow78 * as_nat5 r) % prime == as_nat5 (r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0, r1) % prime) val lemma_fmul5_pow104: r:tup64_5 -> Lemma (requires (let (r0, r1, r2, r3, r4) = r in v r4 * 5 <= 10 * pow26 /\ v r3 * 5 <= 10 * pow26 /\ v r2 * 5 <= 10 * pow26 /\ v r1 * 5 <= 10 * pow26)) (ensures (let (r0, r1, r2, r3, r4) = r in (pow104 * as_nat5 r) % prime == as_nat5 (r1 *! u64 5, r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0) % prime)) let lemma_fmul5_pow104 r = let (r0, r1, r2, r3, r4) = r in calc (==) { (pow104 * as_nat5 r) % prime; (==) { assert_norm (pow104 == pow26 * pow78) } (pow26 * pow78 * as_nat5 r) % prime; (==) { FStar.Math.Lemmas.paren_mul_right pow26 pow78 (as_nat5 r); FStar.Math.Lemmas.lemma_mod_mul_distr_r pow26 (pow78 * as_nat5 r) prime } (pow26 * (pow78 * as_nat5 r % prime)) % prime; (==) { lemma_fmul5_pow78 r } (pow26 * (as_nat5 (r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0, r1) % prime)) % prime; (==) { FStar.Math.Lemmas.lemma_mod_mul_distr_r pow26 (as_nat5 (r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0, r1)) prime } (pow26 * as_nat5 (r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0, r1)) % prime; (==) { lemma_fmul5_pow26 (r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0, r1) } as_nat5 (r1 *! u64 5, r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0) % prime; }; assert ((pow104 * as_nat5 r) % prime == as_nat5 (r1 *! u64 5, r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0) % prime) val mul_felem5_lemma_1: f1:tup64_5{tup64_fits5 f1 (3, 3, 3, 3, 3)} -> r:tup64_5{tup64_fits5 r (2, 2, 2, 2, 2)} -> Lemma (let (f10, f11, f12, f13, f14) = f1 in let (r0, r1, r2, r3, r4) = r in (as_nat5 f1 * as_nat5 r) % prime == (v f10 * as_nat5 r + v f11 * as_nat5 (r4 *! u64 5, r0, r1, r2, r3) + v f12 * pow52 * as_nat5 r + v f13 * pow78 * as_nat5 r + v f14 * pow104 * as_nat5 r) % prime) let mul_felem5_lemma_1 f1 r = let (f10, f11, f12, f13, f14) = f1 in let (r0, r1, r2, r3, r4) = r in let tmp = v f10 * as_nat5 r + v f12 * pow52 * as_nat5 r + v f13 * pow78 * as_nat5 r + v f14 * pow104 * as_nat5 r in calc (==) { (as_nat5 f1 * as_nat5 r) % prime; (==) { } (v f10 + v f11 * pow26 + v f12 * pow52 + v f13 * pow78 + v f14 * pow104) * as_nat5 r % prime; (==) { lemma_mul5_distr_r (v f10) (v f11 * pow26) (v f12 * pow52) (v f13 * pow78) (v f14 * pow104) (as_nat5 r) } (v f10 * as_nat5 r + v f11 * pow26 * as_nat5 r + v f12 * pow52 * as_nat5 r + v f13 * pow78 * as_nat5 r + v f14 * pow104 * as_nat5 r) % prime; (==) { FStar.Math.Lemmas.lemma_mod_plus_distr_r tmp (v f11 * pow26 * as_nat5 r) prime } (tmp + (v f11 * pow26 * as_nat5 r) % prime) % prime; (==) { FStar.Math.Lemmas.paren_mul_right (v f11) pow26 (as_nat5 r); FStar.Math.Lemmas.lemma_mod_mul_distr_r (v f11) (pow26 * as_nat5 r) prime } (tmp + v f11 * (pow26 * as_nat5 r % prime) % prime) % prime; (==) { lemma_fmul5_pow26 r } (tmp + v f11 * (as_nat5 (r4 *! u64 5, r0, r1, r2, r3) % prime) % prime) % prime; (==) { FStar.Math.Lemmas.lemma_mod_mul_distr_r (v f11) (as_nat5 (r4 *! u64 5, r0, r1, r2, r3)) prime } (tmp + v f11 * as_nat5 (r4 *! u64 5, r0, r1, r2, r3) % prime) % prime; (==) { FStar.Math.Lemmas.lemma_mod_plus_distr_r tmp (v f11 * as_nat5 (r4 *! u64 5, r0, r1, r2, r3)) prime } (tmp + v f11 * as_nat5 (r4 *! u64 5, r0, r1, r2, r3)) % prime; }; assert ((as_nat5 f1 * as_nat5 r) % prime == (tmp + v f11 * as_nat5 (r4 *! u64 5, r0, r1, r2, r3)) % prime) val mul_felem5_lemma_2: f1:tup64_5{tup64_fits5 f1 (3, 3, 3, 3, 3)} -> r:tup64_5{tup64_fits5 r (2, 2, 2, 2, 2)} -> Lemma (let (f10, f11, f12, f13, f14) = f1 in let (r0, r1, r2, r3, r4) = r in (as_nat5 f1 * as_nat5 r) % prime == (v f10 * as_nat5 r + v f11 * as_nat5 (r4 *! u64 5, r0, r1, r2, r3) + v f12 * as_nat5 (r3 *! u64 5, r4 *! u64 5, r0, r1, r2) + v f13 * pow78 * as_nat5 r + v f14 * pow104 * as_nat5 r) % prime) let mul_felem5_lemma_2 f1 r = let (f10, f11, f12, f13, f14) = f1 in let (r0, r1, r2, r3, r4) = r in let tmp = v f10 * as_nat5 r + v f11 * as_nat5 (r4 *! u64 5, r0, r1, r2, r3) + v f13 * pow78 * as_nat5 r + v f14 * pow104 * as_nat5 r in calc (==) { (as_nat5 f1 * as_nat5 r) % prime; (==) { mul_felem5_lemma_1 f1 r } (tmp + v f12 * pow52 * as_nat5 r) % prime; (==) { FStar.Math.Lemmas.lemma_mod_plus_distr_r tmp (v f12 * pow52 * as_nat5 r) prime } (tmp + (v f12 * pow52 * as_nat5 r) % prime) % prime; (==) { FStar.Math.Lemmas.paren_mul_right (v f12) pow52 (as_nat5 r); FStar.Math.Lemmas.lemma_mod_mul_distr_r (v f12) (pow52 * as_nat5 r) prime } (tmp + v f12 * (pow52 * as_nat5 r % prime) % prime) % prime; (==) { lemma_fmul5_pow52 r } (tmp + v f12 * (as_nat5 (r3 *! u64 5, r4 *! u64 5, r0, r1, r2) % prime) % prime) % prime; (==) { FStar.Math.Lemmas.lemma_mod_mul_distr_r (v f12) (as_nat5 (r3 *! u64 5, r4 *! u64 5, r0, r1, r2)) prime } (tmp + v f12 * as_nat5 (r3 *! u64 5, r4 *! u64 5, r0, r1, r2) % prime) % prime; (==) { FStar.Math.Lemmas.lemma_mod_plus_distr_r tmp (v f12 * as_nat5 (r3 *! u64 5, r4 *! u64 5, r0, r1, r2)) prime } (tmp + v f12 * as_nat5 (r3 *! u64 5, r4 *! u64 5, r0, r1, r2)) % prime; }; assert ((as_nat5 f1 * as_nat5 r) % prime == (tmp + v f12 * as_nat5 (r3 *! u64 5, r4 *! u64 5, r0, r1, r2)) % prime) val mul_felem5_lemma_3: f1:tup64_5{tup64_fits5 f1 (3, 3, 3, 3, 3)} -> r:tup64_5{tup64_fits5 r (2, 2, 2, 2, 2)} -> Lemma (let (f10, f11, f12, f13, f14) = f1 in let (r0, r1, r2, r3, r4) = r in (as_nat5 f1 * as_nat5 r) % prime == (v f10 * as_nat5 r + v f11 * as_nat5 (r4 *! u64 5, r0, r1, r2, r3) + v f12 * as_nat5 (r3 *! u64 5, r4 *! u64 5, r0, r1, r2) + v f13 * as_nat5 (r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0, r1) + v f14 * pow104 * as_nat5 r) % prime) let mul_felem5_lemma_3 f1 r = let (f10, f11, f12, f13, f14) = f1 in let (r0, r1, r2, r3, r4) = r in let tmp = v f10 * as_nat5 r + v f11 * as_nat5 (r4 *! u64 5, r0, r1, r2, r3) + v f12 * as_nat5 (r3 *! u64 5, r4 *! u64 5, r0, r1, r2) + v f14 * pow104 * as_nat5 r in calc (==) { (as_nat5 f1 * as_nat5 r) % prime; (==) { mul_felem5_lemma_2 f1 r } (tmp + v f13 * pow78 * as_nat5 r) % prime; (==) { FStar.Math.Lemmas.lemma_mod_plus_distr_r tmp (v f13 * pow78 * as_nat5 r) prime } (tmp + (v f13 * pow78 * as_nat5 r) % prime) % prime; (==) { FStar.Math.Lemmas.paren_mul_right (v f13) pow78 (as_nat5 r); FStar.Math.Lemmas.lemma_mod_mul_distr_r (v f13) (pow78 * as_nat5 r) prime } (tmp + v f13 * (pow78 * as_nat5 r % prime) % prime) % prime; (==) { lemma_fmul5_pow78 r } (tmp + v f13 * (as_nat5 (r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0, r1) % prime) % prime) % prime; (==) { FStar.Math.Lemmas.lemma_mod_mul_distr_r (v f13) (as_nat5 (r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0, r1)) prime } (tmp + v f13 * as_nat5 (r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0, r1) % prime) % prime; (==) { FStar.Math.Lemmas.lemma_mod_plus_distr_r tmp (v f13 * as_nat5 (r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0, r1)) prime } (tmp + v f13 * as_nat5 (r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0, r1)) % prime; }; assert ((as_nat5 f1 * as_nat5 r) % prime == (tmp + v f13 * as_nat5 (r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0, r1)) % prime) val mul_felem5_lemma_4: f1:tup64_5{tup64_fits5 f1 (3, 3, 3, 3, 3)} -> r:tup64_5{tup64_fits5 r (2, 2, 2, 2, 2)} -> Lemma (let (f10, f11, f12, f13, f14) = f1 in let (r0, r1, r2, r3, r4) = r in (as_nat5 f1 * as_nat5 r) % prime == (v f10 * as_nat5 r + v f11 * as_nat5 (r4 *! u64 5, r0, r1, r2, r3) + v f12 * as_nat5 (r3 *! u64 5, r4 *! u64 5, r0, r1, r2) + v f13 * as_nat5 (r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0, r1) + v f14 * as_nat5 (r1 *! u64 5, r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0)) % prime) let mul_felem5_lemma_4 f1 r = let (f10, f11, f12, f13, f14) = f1 in let (r0, r1, r2, r3, r4) = r in let tmp = v f10 * as_nat5 r + v f11 * as_nat5 (r4 *! u64 5, r0, r1, r2, r3) + v f12 * as_nat5 (r3 *! u64 5, r4 *! u64 5, r0, r1, r2) + v f13 * as_nat5 (r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0, r1) in calc (==) { (as_nat5 f1 * as_nat5 r) % prime; (==) { mul_felem5_lemma_3 f1 r } (tmp + v f14 * pow104 * as_nat5 r) % prime; (==) { FStar.Math.Lemmas.lemma_mod_plus_distr_r tmp (v f14 * pow104 * as_nat5 r) prime } (tmp + (v f14 * pow104 * as_nat5 r) % prime) % prime; (==) { FStar.Math.Lemmas.paren_mul_right (v f14) pow104 (as_nat5 r); FStar.Math.Lemmas.lemma_mod_mul_distr_r (v f14) (pow104 * as_nat5 r) prime } (tmp + v f14 * (pow104 * as_nat5 r % prime) % prime) % prime; (==) { lemma_fmul5_pow104 r } (tmp + v f14 * (as_nat5 (r1 *! u64 5, r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0) % prime) % prime) % prime; (==) { FStar.Math.Lemmas.lemma_mod_mul_distr_r (v f14) (as_nat5 (r1 *! u64 5, r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0)) prime } (tmp + v f14 * as_nat5 (r1 *! u64 5, r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0) % prime) % prime; (==) { FStar.Math.Lemmas.lemma_mod_plus_distr_r tmp (v f14 * as_nat5 (r1 *! u64 5, r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0)) prime } (tmp + v f14 * as_nat5 (r1 *! u64 5, r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0)) % prime; }; assert ((as_nat5 f1 * as_nat5 r) % prime == (tmp + v f14 * as_nat5 (r1 *! u64 5, r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0)) % prime) val mul_felem5_lemma: f1:tup64_5{tup64_fits5 f1 (3, 3, 3, 3, 3)} -> r:tup64_5{tup64_fits5 r (2, 2, 2, 2, 2)} -> Lemma (let (f10, f11, f12, f13, f14) = f1 in let (r0, r1, r2, r3, r4) = r in (as_pfelem5 f1) `pfmul` (as_pfelem5 r) == (v f10 * as_nat5 (r0, r1, r2, r3, r4) + v f11 * as_nat5 (r4 *! u64 5, r0, r1, r2, r3) + v f12 * as_nat5 (r3 *! u64 5, r4 *! u64 5, r0, r1, r2) + v f13 * as_nat5 (r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0, r1) + v f14 * as_nat5 (r1 *! u64 5, r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0)) % prime) let mul_felem5_lemma f1 r = let (f10, f11, f12, f13, f14) = f1 in let (r0, r1, r2, r3, r4) = r in mul_felem5_lemma_4 f1 r; FStar.Math.Lemmas.lemma_mod_mul_distr_l (as_nat5 f1) (as_nat5 r) prime; FStar.Math.Lemmas.lemma_mod_mul_distr_r (as_nat5 f1 % prime) (as_nat5 r) prime val precomp_r5_as_tup64: #w:lanes -> r:felem5 w{felem_fits5 r (2, 2, 2, 2, 2)} -> i:nat{i < w} -> Lemma (let r5 = precomp_r5 r in let (tr50, tr51, tr52, tr53, tr54) = as_tup64_i r5 i in let (tr0, tr1, tr2, tr3, tr4) = as_tup64_i r i in tr50 == tr0 *! u64 5 /\ tr51 == tr1 *! u64 5 /\ tr52 == tr2 *! u64 5 /\ tr53 == tr3 *! u64 5 /\ tr54 == tr4 *! u64 5) let precomp_r5_as_tup64 #w r i = let r5 = precomp_r5 r in let (r50, r51, r52, r53, r54) = r5 in let (r0, r1, r2, r3, r4) = r in let (tr50, tr51, tr52, tr53, tr54) = as_tup64_i r5 i in let (tr0, tr1, tr2, tr3, tr4) = as_tup64_i r i in assert_norm (max26 = pow2 26 - 1); FStar.Math.Lemmas.modulo_lemma (5 * v tr0) (pow2 64); FStar.Math.Lemmas.modulo_lemma (5 * v tr1) (pow2 64); FStar.Math.Lemmas.modulo_lemma (5 * v tr2) (pow2 64); FStar.Math.Lemmas.modulo_lemma (5 * v tr3) (pow2 64); FStar.Math.Lemmas.modulo_lemma (5 * v tr4) (pow2 64); assert (v tr50 == v (tr0 *! u64 5)); assert (v tr51 == v (tr1 *! u64 5)); assert (v tr52 == v (tr2 *! u64 5)); assert (v tr53 == v (tr3 *! u64 5)); assert (v tr54 == v (tr4 *! u64 5)) val mul_felem5_eval_as_tup64: #w:lanes -> f1:felem5 w{felem_fits5 f1 (3, 3, 3, 3, 3)} -> r:felem5 w{felem_fits5 r (2, 2, 2, 2, 2)} -> r5:felem5 w{felem_fits5 r5 (10, 10, 10, 10, 10) /\ r5 == precomp_r5 r} -> i:nat{i < w} -> Lemma (let (r0, r1, r2, r3, r4) = r in let (f10, f11, f12, f13, f14) = f1 in let (r50, r51, r52, r53, r54) = r5 in let (tr0, tr1, tr2, tr3, tr4) = as_tup64_i r i in let (tf10, tf11, tf12, tf13, tf14) = as_tup64_i f1 i in (uint64xN_v f10).[i] * (fas_nat5 (r0,r1,r2,r3,r4)).[i] + (uint64xN_v f11).[i] * (fas_nat5 (r54,r0,r1,r2,r3)).[i] + (uint64xN_v f12).[i] * (fas_nat5 (r53,r54,r0,r1,r2)).[i] + (uint64xN_v f13).[i] * (fas_nat5 (r52,r53,r54,r0,r1)).[i] + (uint64xN_v f14).[i] * (fas_nat5 (r51,r52,r53,r54,r0)).[i] == (v tf10 * as_nat5 (tr0, tr1, tr2, tr3, tr4) + v tf11 * as_nat5 (tr4 *! u64 5, tr0, tr1, tr2, tr3) + v tf12 * as_nat5 (tr3 *! u64 5, tr4 *! u64 5, tr0, tr1, tr2) + v tf13 * as_nat5 (tr2 *! u64 5, tr3 *! u64 5, tr4 *! u64 5, tr0, tr1) + v tf14 * as_nat5 (tr1 *! u64 5, tr2 *! u64 5, tr3 *! u64 5, tr4 *! u64 5, tr0)))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntVector.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Poly1305.Vec.fst.checked", "Hacl.Spec.Poly1305.Field32xN.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Poly1305.Field32xN.Lemmas0.fst" }
[ { "abbrev": false, "full_module": "Hacl.Spec.Poly1305.Field32xN", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Poly1305.Vec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntVector", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Poly1305.Field32xN", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Poly1305.Field32xN", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
f1: Hacl.Spec.Poly1305.Field32xN.felem5 w {Hacl.Spec.Poly1305.Field32xN.felem_fits5 f1 (3, 3, 3, 3, 3)} -> r: Hacl.Spec.Poly1305.Field32xN.felem5 w {Hacl.Spec.Poly1305.Field32xN.felem_fits5 r (2, 2, 2, 2, 2)} -> r5: Hacl.Spec.Poly1305.Field32xN.felem5 w { Hacl.Spec.Poly1305.Field32xN.felem_fits5 r5 (10, 10, 10, 10, 10) /\ r5 == Hacl.Spec.Poly1305.Field32xN.precomp_r5 r } -> i: Prims.nat{i < w} -> FStar.Pervasives.Lemma (ensures (let _ = r in (let FStar.Pervasives.Native.Mktuple5 #_ #_ #_ #_ #_ r0 r1 r2 r3 r4 = _ in let _ = f1 in (let FStar.Pervasives.Native.Mktuple5 #_ #_ #_ #_ #_ f10 f11 f12 f13 f14 = _ in let _ = r5 in (let FStar.Pervasives.Native.Mktuple5 #_ #_ #_ #_ #_ _ r51 r52 r53 r54 = _ in let _ = Hacl.Spec.Poly1305.Field32xN.as_tup64_i r i in (let FStar.Pervasives.Native.Mktuple5 #_ #_ #_ #_ #_ tr0 tr1 tr2 tr3 tr4 = _ in let _ = Hacl.Spec.Poly1305.Field32xN.as_tup64_i f1 i in (let FStar.Pervasives.Native.Mktuple5 #_ #_ #_ #_ #_ tf10 tf11 tf12 tf13 tf14 = _ in (Hacl.Spec.Poly1305.Field32xN.uint64xN_v f10).[ i ] * (Hacl.Spec.Poly1305.Field32xN.fas_nat5 (r0, r1, r2, r3, r4)).[ i ] + (Hacl.Spec.Poly1305.Field32xN.uint64xN_v f11).[ i ] * (Hacl.Spec.Poly1305.Field32xN.fas_nat5 (r54, r0, r1, r2, r3)).[ i ] + (Hacl.Spec.Poly1305.Field32xN.uint64xN_v f12).[ i ] * (Hacl.Spec.Poly1305.Field32xN.fas_nat5 (r53, r54, r0, r1, r2)).[ i ] + (Hacl.Spec.Poly1305.Field32xN.uint64xN_v f13).[ i ] * (Hacl.Spec.Poly1305.Field32xN.fas_nat5 (r52, r53, r54, r0, r1)).[ i ] + (Hacl.Spec.Poly1305.Field32xN.uint64xN_v f14).[ i ] * (Hacl.Spec.Poly1305.Field32xN.fas_nat5 (r51, r52, r53, r54, r0)).[ i ] == Lib.IntTypes.v tf10 * Hacl.Spec.Poly1305.Field32xN.as_nat5 (tr0, tr1, tr2, tr3, tr4) + Lib.IntTypes.v tf11 * Hacl.Spec.Poly1305.Field32xN.as_nat5 (tr4 *! Lib.IntTypes.u64 5, tr0, tr1, tr2, tr3) + Lib.IntTypes.v tf12 * Hacl.Spec.Poly1305.Field32xN.as_nat5 (tr3 *! Lib.IntTypes.u64 5, tr4 *! Lib.IntTypes.u64 5, tr0, tr1, tr2) + Lib.IntTypes.v tf13 * Hacl.Spec.Poly1305.Field32xN.as_nat5 (tr2 *! Lib.IntTypes.u64 5, tr3 *! Lib.IntTypes.u64 5, tr4 *! Lib.IntTypes.u64 5, tr0, tr1) + Lib.IntTypes.v tf14 * Hacl.Spec.Poly1305.Field32xN.as_nat5 (tr1 *! Lib.IntTypes.u64 5, tr2 *! Lib.IntTypes.u64 5, tr3 *! Lib.IntTypes.u64 5, tr4 *! Lib.IntTypes.u64 5, tr0)) <: Type0) <: Type0) <: Type0) <: Type0) <: Type0))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Hacl.Spec.Poly1305.Field32xN.lanes", "Hacl.Spec.Poly1305.Field32xN.felem5", "Hacl.Spec.Poly1305.Field32xN.felem_fits5", "FStar.Pervasives.Native.Mktuple5", "Prims.nat", "Prims.l_and", "Prims.eq2", "Hacl.Spec.Poly1305.Field32xN.precomp_r5", "Prims.b2t", "Prims.op_LessThan", "Hacl.Spec.Poly1305.Field32xN.uint64xN", "Lib.IntTypes.uint64", "Hacl.Poly1305.Field32xN.Lemmas0.precomp_r5_as_tup64", "Prims.unit", "Prims._assert", "Prims.int", "Prims.op_Addition", "FStar.Mul.op_Star", "Lib.Sequence.op_String_Access", "Hacl.Spec.Poly1305.Field32xN.uint64xN_v", "Hacl.Spec.Poly1305.Field32xN.fas_nat5", "Lib.IntTypes.v", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "Hacl.Spec.Poly1305.Field32xN.as_nat5", "Hacl.Spec.Poly1305.Field32xN.tup64_5", "Hacl.Spec.Poly1305.Field32xN.as_tup64_i" ]
[]
false
false
true
false
false
let mul_felem5_eval_as_tup64 #w f1 r r5 i =
let r0, r1, r2, r3, r4 = r in let f10, f11, f12, f13, f14 = f1 in let r50, r51, r52, r53, r54 = r5 in let tr0, tr1, tr2, tr3, tr4 = as_tup64_i r i in let tf10, tf11, tf12, tf13, tf14 = as_tup64_i f1 i in let tr50, tr51, tr52, tr53, tr54 = as_tup64_i r5 i in assert ((uint64xN_v f10).[ i ] * (fas_nat5 (r0, r1, r2, r3, r4)).[ i ] + (uint64xN_v f11).[ i ] * (fas_nat5 (r54, r0, r1, r2, r3)).[ i ] + (uint64xN_v f12).[ i ] * (fas_nat5 (r53, r54, r0, r1, r2)).[ i ] + (uint64xN_v f13).[ i ] * (fas_nat5 (r52, r53, r54, r0, r1)).[ i ] + (uint64xN_v f14).[ i ] * (fas_nat5 (r51, r52, r53, r54, r0)).[ i ] == v tf10 * as_nat5 (tr0, tr1, tr2, tr3, tr4) + v tf11 * as_nat5 (tr54, tr0, tr1, tr2, tr3) + v tf12 * as_nat5 (tr53, tr54, tr0, tr1, tr2) + v tf13 * as_nat5 (tr52, tr53, tr54, tr0, tr1) + v tf14 * as_nat5 (tr51, tr52, tr53, tr54, tr0)); precomp_r5_as_tup64 #w r i
false
Vale.Arch.Types.fsti
Vale.Arch.Types.lemma_equality_check_helper_2
val lemma_equality_check_helper_2 (q1 q2 cmp: quad32) (tmp1 result1 tmp2 tmp3 result2: nat64) : Lemma (requires cmp == Mkfour (if q1.lo0 = q2.lo0 then 0xFFFFFFFF else 0) (if q1.lo1 = q2.lo1 then 0xFFFFFFFF else 0) (if q1.hi2 = q2.hi2 then 0xFFFFFFFF else 0) (if q1.hi3 = q2.hi3 then 0xFFFFFFFF else 0) /\ tmp1 = lo64 cmp /\ result1 = (if tmp1 = 0xFFFFFFFFFFFFFFFF then 0 else 1) /\ tmp2 = hi64 cmp /\ tmp3 = (if tmp2 = 0xFFFFFFFFFFFFFFFF then 0 else 1) /\ result2 = tmp3 + result1) (ensures (if q1 = q2 then result2 = 0 else result2 > 0))
val lemma_equality_check_helper_2 (q1 q2 cmp: quad32) (tmp1 result1 tmp2 tmp3 result2: nat64) : Lemma (requires cmp == Mkfour (if q1.lo0 = q2.lo0 then 0xFFFFFFFF else 0) (if q1.lo1 = q2.lo1 then 0xFFFFFFFF else 0) (if q1.hi2 = q2.hi2 then 0xFFFFFFFF else 0) (if q1.hi3 = q2.hi3 then 0xFFFFFFFF else 0) /\ tmp1 = lo64 cmp /\ result1 = (if tmp1 = 0xFFFFFFFFFFFFFFFF then 0 else 1) /\ tmp2 = hi64 cmp /\ tmp3 = (if tmp2 = 0xFFFFFFFFFFFFFFFF then 0 else 1) /\ result2 = tmp3 + result1) (ensures (if q1 = q2 then result2 = 0 else result2 > 0))
let lemma_equality_check_helper_2 (q1 q2 cmp:quad32) (tmp1 result1 tmp2 tmp3 result2:nat64) : Lemma (requires cmp == Mkfour (if q1.lo0 = q2.lo0 then 0xFFFFFFFF else 0) (if q1.lo1 = q2.lo1 then 0xFFFFFFFF else 0) (if q1.hi2 = q2.hi2 then 0xFFFFFFFF else 0) (if q1.hi3 = q2.hi3 then 0xFFFFFFFF else 0) /\ tmp1 = lo64 cmp /\ result1 = (if tmp1 = 0xFFFFFFFFFFFFFFFF then 0 else 1) /\ tmp2 = hi64 cmp /\ tmp3 = (if tmp2 = 0xFFFFFFFFFFFFFFFF then 0 else 1) /\ result2 = tmp3 + result1) (ensures (if q1 = q2 then result2 = 0 else result2 > 0)) = lemma_equality_check_helper cmp; ()
{ "file_name": "vale/code/arch/Vale.Arch.Types.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 4, "end_line": 156, "start_col": 0, "start_line": 143 }
module Vale.Arch.Types open FStar.Mul open Vale.Def.Opaque_s open Vale.Def.Types_s open Vale.Lib.Seqs_s open Vale.Lib.Seqs open Vale.Def.Words_s open Vale.Def.Words.Four_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Seq open FStar.Seq open Vale.Def.Words.Two_s unfold let ( *^ ) = nat32_xor unfold let ( *^^ ) = quad32_xor unfold let add_wrap32 (x:nat32) (y:nat32) : nat32 = add_wrap x y unfold let add_wrap64 (x:nat64) (y:nat64) : nat64 = add_wrap x y unfold let sub_wrap32 (x:nat32) (y:nat32) : nat32 = sub_wrap x y unfold let sub_wrap64 (x:nat64) (y:nat64) : nat64 = sub_wrap x y unfold let iand32 (a:nat32) (b:nat32) : nat32 = iand a b unfold let ixor32 (a:nat32) (b:nat32) : nat32 = ixor a b unfold let ior32 (a:nat32) (b:nat32) : nat32 = ior a b unfold let inot32 (a:nat32) : nat32 = inot a unfold let ishl32 (a:nat32) (s:int) : nat32 = ishl a s unfold let ishr32 (a:nat32) (s:int) : nat32 = ishr a s unfold let iand64 (a:nat64) (b:nat64) : nat64 = iand a b unfold let ixor64 (a:nat64) (b:nat64) : nat64 = ixor a b unfold let ior64 (a:nat64) (b:nat64) : nat64 = ior a b unfold let inot64 (a:nat64) : nat64 = inot a unfold let ishl64 (a:nat64) (s:int) : nat64 = ishl a s unfold let ishr64 (a:nat64) (s:int) : nat64 = ishr a s unfold let iand128 (a:nat128) (b:nat128) : nat128 = iand a b unfold let ixor128 (a:nat128) (b:nat128) : nat128 = ixor a b unfold let ior128 (a:nat128) (b:nat128) : nat128 = ior a b unfold let inot128 (a:nat128) : nat128 = inot a unfold let ishl128 (a:nat128) (s:int) : nat128 = ishl a s unfold let ishr128 (a:nat128) (s:int) : nat128 = ishr a s unfold let two_to_nat32 (x:two nat32) : nat64 = two_to_nat 32 x val lemma_nat_to_two32 (_:unit) : Lemma (forall (x:nat64).{:pattern (nat_to_two 32 x)} nat_to_two 32 x == Mktwo (x % 0x100000000) (x / 0x100000000)) let quad32_shl32 (q:quad32) : quad32 = let Mkfour v0 v1 v2 v3 = q in Mkfour 0 v0 v1 v2 let add_wrap_quad32 (q0 q1:quad32) : quad32 = let open Vale.Def.Words_s in Mkfour (add_wrap q0.lo0 q1.lo0) (add_wrap q0.lo1 q1.lo1) (add_wrap q0.hi2 q1.hi2) (add_wrap q0.hi3 q1.hi3) val lemma_BitwiseXorCommutative (x y:nat32) : Lemma (x *^ y == y *^ x) val lemma_BitwiseXorWithZero (n:nat32) : Lemma (n *^ 0 == n) val lemma_BitwiseXorCancel (n:nat32) : Lemma (n *^ n == 0) val lemma_BitwiseXorCancel64 (n:nat64) : Lemma (ixor n n == 0) val lemma_BitwiseXorAssociative (x y z:nat32) : Lemma (x *^ (y *^ z) == (x *^ y) *^ z) val xor_lemmas (_:unit) : Lemma (ensures (forall (x y:nat32).{:pattern (x *^ y)} x *^ y == y *^ x) /\ (forall (n:nat32).{:pattern (n *^ 0)} n *^ 0 == n) /\ (forall (n:nat32).{:pattern (n *^ n)} n *^ n == 0) /\ (forall (n:nat64).{:pattern (ixor n n)} ixor n n == 0) /\ (forall (x y z:nat32).{:pattern (x *^ (y *^ z))} x *^ (y *^ z) == (x *^ y) *^ z) ) val lemma_quad32_xor (_:unit) : Lemma (forall q . {:pattern quad32_xor q q} quad32_xor q q == Mkfour 0 0 0 0) let quad32_double_lo (q:quad32) : double32 = (four_to_two_two q).lo let quad32_double_hi (q:quad32) : double32 = (four_to_two_two q).hi val lemma_reverse_reverse_bytes_nat32 (n:nat32) : Lemma (reverse_bytes_nat32 (reverse_bytes_nat32 n) == n) [SMTPat (reverse_bytes_nat32 (reverse_bytes_nat32 n))] val lemma_reverse_bytes_quad32 (q:quad32) : Lemma (reverse_bytes_quad32 (reverse_bytes_quad32 q) == q) [SMTPat (reverse_bytes_quad32 (reverse_bytes_quad32 q))] val lemma_reverse_bytes_quad32_zero (_:unit) : Lemma (let z = Mkfour 0 0 0 0 in reverse_bytes_quad32 z == z) val lemma_reverse_reverse_bytes_nat32_seq (s:seq nat32) : Lemma (reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s) == s) [SMTPat (reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s))] unfold let quad32_to_seq (q:quad32) : seq nat32 = four_to_seq_LE q val lemma_insert_nat64_properties (q:quad32) (n:nat64) : Lemma ( (let q' = insert_nat64 q n 0 in q'.hi2 == q.hi2 /\ q'.hi3 == q.hi3) /\ (let q' = insert_nat64 q n 1 in q'.lo0 == q.lo0 /\ q'.lo1 == q.lo1)) [SMTPat (insert_nat64 q n)] val lemma_insert_nat64_nat32s (q:quad32) (n0 n1:nat32) : Lemma ( insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 0 == Mkfour n0 n1 q.hi2 q.hi3 /\ insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 1 == Mkfour q.lo0 q.lo1 n0 n1 ) let lo64_def (q:quad32) : nat64 = two_to_nat 32 (two_select (four_to_two_two q) 0) [@"opaque_to_smt"] let lo64 = opaque_make lo64_def irreducible let lo64_reveal = opaque_revealer (`%lo64) lo64 lo64_def let hi64_def (q:quad32) : nat64 = two_to_nat 32 (two_select (four_to_two_two q) 1) [@"opaque_to_smt"] let hi64 = opaque_make hi64_def irreducible let hi64_reveal = opaque_revealer (`%hi64) hi64 hi64_def val lemma_lo64_properties (_:unit) : Lemma (forall (q0 q1:quad32).{:pattern lo64 q0; lo64 q1} (q0.lo0 == q1.lo0 /\ q0.lo1 == q1.lo1) <==> (lo64 q0 == lo64 q1)) val lemma_hi64_properties (_:unit) : Lemma (forall (q0 q1:quad32).{:pattern hi64 q0; hi64 q1} (q0.hi2 == q1.hi2 /\ q0.hi3 == q1.hi3) <==> (hi64 q0 == hi64 q1)) val lemma_reverse_bytes_quad32_64 (src orig final:quad32) : Lemma (requires final == insert_nat64 (insert_nat64 orig (reverse_bytes_nat64 (hi64 src)) 0) (reverse_bytes_nat64 (lo64 src)) 1) (ensures final == reverse_bytes_quad32 src) val lemma_equality_check_helper (q:quad32) : Lemma ((q.lo0 == 0 /\ q.lo1 == 0 ==> lo64 q == 0) /\ ((not (q.lo0 = 0) \/ not (q.lo1 = 0)) ==> not (lo64 q = 0)) /\ (q.hi2 == 0 /\ q.hi3 == 0 ==> hi64 q == 0) /\ ((~(q.hi2 = 0) \/ ~(q.hi3 = 0)) ==> ~(hi64 q = 0)) /\ (q.lo0 == 0xFFFFFFFF /\ q.lo1 == 0xFFFFFFFF <==> lo64 q == 0xFFFFFFFFFFFFFFFF) /\ (q.hi2 == 0xFFFFFFFF /\ q.hi3 == 0xFFFFFFFF <==> hi64 q == 0xFFFFFFFFFFFFFFFF) )
{ "checked_file": "/", "dependencies": [ "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Two_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Seq.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.Arch.Types.fsti" }
[ { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
q1: Vale.Def.Types_s.quad32 -> q2: Vale.Def.Types_s.quad32 -> cmp: Vale.Def.Types_s.quad32 -> tmp1: Vale.Def.Words_s.nat64 -> result1: Vale.Def.Words_s.nat64 -> tmp2: Vale.Def.Words_s.nat64 -> tmp3: Vale.Def.Words_s.nat64 -> result2: Vale.Def.Words_s.nat64 -> FStar.Pervasives.Lemma (requires cmp == Vale.Def.Words_s.Mkfour (match Mkfour?.lo0 q1 = Mkfour?.lo0 q2 with | true -> 0xFFFFFFFF | _ -> 0) (match Mkfour?.lo1 q1 = Mkfour?.lo1 q2 with | true -> 0xFFFFFFFF | _ -> 0) (match Mkfour?.hi2 q1 = Mkfour?.hi2 q2 with | true -> 0xFFFFFFFF | _ -> 0) (match Mkfour?.hi3 q1 = Mkfour?.hi3 q2 with | true -> 0xFFFFFFFF | _ -> 0) /\ tmp1 = Vale.Arch.Types.lo64 cmp /\ result1 = (match tmp1 = 0xFFFFFFFFFFFFFFFF with | true -> 0 | _ -> 1) /\ tmp2 = Vale.Arch.Types.hi64 cmp /\ tmp3 = (match tmp2 = 0xFFFFFFFFFFFFFFFF with | true -> 0 | _ -> 1) /\ result2 = tmp3 + result1) (ensures ((match q1 = q2 with | true -> result2 = 0 | _ -> result2 > 0) <: Type0))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.Def.Types_s.quad32", "Vale.Def.Words_s.nat64", "Prims.unit", "Vale.Arch.Types.lemma_equality_check_helper", "Prims.l_and", "Prims.eq2", "Vale.Def.Words_s.four", "Vale.Def.Types_s.nat32", "Vale.Def.Words_s.Mkfour", "Prims.op_Equality", "Vale.Def.Words_s.__proj__Mkfour__item__lo0", "Prims.bool", "Vale.Def.Words_s.__proj__Mkfour__item__lo1", "Vale.Def.Words_s.__proj__Mkfour__item__hi2", "Vale.Def.Words_s.__proj__Mkfour__item__hi3", "Prims.b2t", "Vale.Arch.Types.lo64", "Prims.int", "Vale.Arch.Types.hi64", "Prims.op_Addition", "Prims.squash", "Prims.op_GreaterThan", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
true
false
true
false
false
let lemma_equality_check_helper_2 (q1 q2 cmp: quad32) (tmp1 result1 tmp2 tmp3 result2: nat64) : Lemma (requires cmp == Mkfour (if q1.lo0 = q2.lo0 then 0xFFFFFFFF else 0) (if q1.lo1 = q2.lo1 then 0xFFFFFFFF else 0) (if q1.hi2 = q2.hi2 then 0xFFFFFFFF else 0) (if q1.hi3 = q2.hi3 then 0xFFFFFFFF else 0) /\ tmp1 = lo64 cmp /\ result1 = (if tmp1 = 0xFFFFFFFFFFFFFFFF then 0 else 1) /\ tmp2 = hi64 cmp /\ tmp3 = (if tmp2 = 0xFFFFFFFFFFFFFFFF then 0 else 1) /\ result2 = tmp3 + result1) (ensures (if q1 = q2 then result2 = 0 else result2 > 0)) =
lemma_equality_check_helper cmp; ()
false
FStar.LexicographicOrdering.fsti
FStar.LexicographicOrdering.tuple_to_dep_tuple
val tuple_to_dep_tuple (#a #b: Type) (x: a & b) : dtuple2 a (fun _ -> b)
val tuple_to_dep_tuple (#a #b: Type) (x: a & b) : dtuple2 a (fun _ -> b)
let tuple_to_dep_tuple (#a #b:Type) (x:a & b) : dtuple2 a (fun _ -> b) = (| fst x, snd x |)
{ "file_name": "ulib/FStar.LexicographicOrdering.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 20, "end_line": 126, "start_col": 0, "start_line": 125 }
(* Copyright 2021 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 and Nikhil Swamy *) module FStar.LexicographicOrdering /// This module proves that lexicographic ordering is well-founded /// (i.e. every element is accessible) /// /// It defines the lex relation as an inductive, and prove its well-foundedness /// /// Since SMT proofs in F* are more amenable to squashed definitions, /// the module also defines a squashed version of the lex relation, /// and prove its well-foundedness, reusing the proof for the constructive version /// /// See tests/micro-benchmarks/Test.WellFoundedRecursion.fst for /// how we use squashed `lex` to prove termination for the ackermann function /// /// Finally, the module defines a non-dependent version of lex /// (in-terms of dependent lex), and uses it to prove well-foundedness of symmetric products too /// /// Some references: /// - https://github.com/coq/coq/blob/master/theories/Wellfounded/Lexicographic_Product.v /// - Constructing Recursion Operators in Type Theory, L. Paulson JSC (1986) 2, 325-355 open FStar.WellFounded /// Definition of lexicographic ordering as a relation over dependent tuples /// /// Two elements are related if: /// - Either their first components are related /// - Or, the first components are equal, and the second components are related noeq type lex_t (#a:Type u#a) (#b:a -> Type u#b) (r_a:binrel u#a u#ra a) (r_b:(x:a -> binrel u#b u#rb (b x))) : (x:a & b x) -> (x:a & b x) -> Type u#(max a b ra rb) = | Left_lex: x1:a -> x2:a -> y1:b x1 -> y2:b x2 -> r_a x1 x2 -> lex_t r_a r_b (| x1, y1 |) (| x2, y2 |) | Right_lex: x:a -> y1:b x -> y2:b x -> r_b x y1 y2 -> lex_t r_a r_b (| x, y1 |) (| x, y2 |) /// Given two well-founded relations `r_a` and `r_b`, /// their lexicographic ordering is also well-founded val lex_t_wf (#a:Type u#a) (#b:a -> Type u#b) (#r_a:binrel u#a u#ra a) (#r_b:(x:a -> binrel u#b u#rb (b x))) (wf_a:well_founded r_a) (wf_b:(x:a -> well_founded (r_b x))) : well_founded (lex_t r_a r_b) /// We can also define a squashed version of lex relation unfold let lex_aux (#a:Type u#a) (#b:a -> Type u#b) (r_a:binrel u#a u#ra a) (r_b:(x:a -> binrel u#b u#rb (b x))) : binrel u#(max a b) u#0 (x:a & b x) = fun (| x1, y1 |) (| x2, y2 |) -> (squash (r_a x1 x2)) \/ (x1 == x2 /\ squash ((r_b x1) y1 y2)) /// Provide a mapping from a point in lex_aux to a squashed point in lex val lex_to_lex_t (#a:Type u#a) (#b:a -> Type u#b) (r_a:binrel u#a u#ra a) (r_b:(x:a -> binrel u#b u#rb (b x))) (t1 t2:(x:a & b x)) (p:lex_aux r_a r_b t1 t2) : squash (lex_t r_a r_b t1 t2) /// And prove that is it is well-founded let lex_wf (#a:Type u#a) (#b:a -> Type u#b) (#r_a:binrel u#a u#ra a) (#r_b:(x:a -> binrel u#b u#rb (b x))) (wf_a:well_founded r_a) (wf_b:(x:a -> well_founded (r_b x))) : Lemma (is_well_founded (lex_aux r_a r_b)) = subrelation_squash_wf (lex_to_lex_t r_a r_b) (lex_t_wf wf_a wf_b) /// A user-friendly lex_wf that returns a well-founded relation unfold let lex (#a:Type u#a) (#b:a -> Type u#b) (#r_a:binrel u#a u#ra a) (#r_b:(x:a -> binrel u#b u#rb (b x))) (wf_a:well_founded r_a) (wf_b:(x:a -> well_founded (r_b x))) : well_founded_relation (x:a & b x) = lex_wf wf_a wf_b; lex_aux r_a r_b /// We can also define a non-dependent version of the lex ordering, /// in terms of the dependent lex tuple, /// and prove its well-foundedness
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.WellFounded.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "FStar.LexicographicOrdering.fsti" }
[ { "abbrev": false, "full_module": "FStar.WellFounded", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: (a * b) -> Prims.dtuple2 a (fun _ -> b)
Prims.Tot
[ "total" ]
[]
[ "FStar.Pervasives.Native.tuple2", "Prims.Mkdtuple2", "FStar.Pervasives.Native.fst", "FStar.Pervasives.Native.snd", "Prims.dtuple2" ]
[]
false
false
false
false
false
let tuple_to_dep_tuple (#a #b: Type) (x: a & b) : dtuple2 a (fun _ -> b) =
(| fst x, snd x |)
false
FStar.LexicographicOrdering.fsti
FStar.LexicographicOrdering.lex_t_non_dep
val lex_t_non_dep (#a: Type u#a) (#b: Type u#b) (r_a: binrel u#a u#ra a) (r_b: binrel u#b u#rb b) : binrel u#(max a b) u#(max a b ra rb) (a & b)
val lex_t_non_dep (#a: Type u#a) (#b: Type u#b) (r_a: binrel u#a u#ra a) (r_b: binrel u#b u#rb b) : binrel u#(max a b) u#(max a b ra rb) (a & b)
let lex_t_non_dep (#a:Type u#a) (#b:Type u#b) (r_a:binrel u#a u#ra a) (r_b:binrel u#b u#rb b) : binrel u#(max a b) u#(max a b ra rb) (a & b) = fun x y -> lex_t r_a (fun _ -> r_b) (tuple_to_dep_tuple x) (tuple_to_dep_tuple y)
{ "file_name": "ulib/FStar.LexicographicOrdering.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 76, "end_line": 138, "start_col": 0, "start_line": 132 }
(* Copyright 2021 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 and Nikhil Swamy *) module FStar.LexicographicOrdering /// This module proves that lexicographic ordering is well-founded /// (i.e. every element is accessible) /// /// It defines the lex relation as an inductive, and prove its well-foundedness /// /// Since SMT proofs in F* are more amenable to squashed definitions, /// the module also defines a squashed version of the lex relation, /// and prove its well-foundedness, reusing the proof for the constructive version /// /// See tests/micro-benchmarks/Test.WellFoundedRecursion.fst for /// how we use squashed `lex` to prove termination for the ackermann function /// /// Finally, the module defines a non-dependent version of lex /// (in-terms of dependent lex), and uses it to prove well-foundedness of symmetric products too /// /// Some references: /// - https://github.com/coq/coq/blob/master/theories/Wellfounded/Lexicographic_Product.v /// - Constructing Recursion Operators in Type Theory, L. Paulson JSC (1986) 2, 325-355 open FStar.WellFounded /// Definition of lexicographic ordering as a relation over dependent tuples /// /// Two elements are related if: /// - Either their first components are related /// - Or, the first components are equal, and the second components are related noeq type lex_t (#a:Type u#a) (#b:a -> Type u#b) (r_a:binrel u#a u#ra a) (r_b:(x:a -> binrel u#b u#rb (b x))) : (x:a & b x) -> (x:a & b x) -> Type u#(max a b ra rb) = | Left_lex: x1:a -> x2:a -> y1:b x1 -> y2:b x2 -> r_a x1 x2 -> lex_t r_a r_b (| x1, y1 |) (| x2, y2 |) | Right_lex: x:a -> y1:b x -> y2:b x -> r_b x y1 y2 -> lex_t r_a r_b (| x, y1 |) (| x, y2 |) /// Given two well-founded relations `r_a` and `r_b`, /// their lexicographic ordering is also well-founded val lex_t_wf (#a:Type u#a) (#b:a -> Type u#b) (#r_a:binrel u#a u#ra a) (#r_b:(x:a -> binrel u#b u#rb (b x))) (wf_a:well_founded r_a) (wf_b:(x:a -> well_founded (r_b x))) : well_founded (lex_t r_a r_b) /// We can also define a squashed version of lex relation unfold let lex_aux (#a:Type u#a) (#b:a -> Type u#b) (r_a:binrel u#a u#ra a) (r_b:(x:a -> binrel u#b u#rb (b x))) : binrel u#(max a b) u#0 (x:a & b x) = fun (| x1, y1 |) (| x2, y2 |) -> (squash (r_a x1 x2)) \/ (x1 == x2 /\ squash ((r_b x1) y1 y2)) /// Provide a mapping from a point in lex_aux to a squashed point in lex val lex_to_lex_t (#a:Type u#a) (#b:a -> Type u#b) (r_a:binrel u#a u#ra a) (r_b:(x:a -> binrel u#b u#rb (b x))) (t1 t2:(x:a & b x)) (p:lex_aux r_a r_b t1 t2) : squash (lex_t r_a r_b t1 t2) /// And prove that is it is well-founded let lex_wf (#a:Type u#a) (#b:a -> Type u#b) (#r_a:binrel u#a u#ra a) (#r_b:(x:a -> binrel u#b u#rb (b x))) (wf_a:well_founded r_a) (wf_b:(x:a -> well_founded (r_b x))) : Lemma (is_well_founded (lex_aux r_a r_b)) = subrelation_squash_wf (lex_to_lex_t r_a r_b) (lex_t_wf wf_a wf_b) /// A user-friendly lex_wf that returns a well-founded relation unfold let lex (#a:Type u#a) (#b:a -> Type u#b) (#r_a:binrel u#a u#ra a) (#r_b:(x:a -> binrel u#b u#rb (b x))) (wf_a:well_founded r_a) (wf_b:(x:a -> well_founded (r_b x))) : well_founded_relation (x:a & b x) = lex_wf wf_a wf_b; lex_aux r_a r_b /// We can also define a non-dependent version of the lex ordering, /// in terms of the dependent lex tuple, /// and prove its well-foundedness let tuple_to_dep_tuple (#a #b:Type) (x:a & b) : dtuple2 a (fun _ -> b) = (| fst x, snd x |) /// The non-dependent lexicographic ordering /// and its well-foundedness
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.WellFounded.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "FStar.LexicographicOrdering.fsti" }
[ { "abbrev": false, "full_module": "FStar.WellFounded", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_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_a: FStar.WellFounded.binrel a -> r_b: FStar.WellFounded.binrel b -> FStar.WellFounded.binrel (a * b)
Prims.Tot
[ "total" ]
[]
[ "FStar.WellFounded.binrel", "FStar.Pervasives.Native.tuple2", "FStar.LexicographicOrdering.lex_t", "FStar.LexicographicOrdering.tuple_to_dep_tuple" ]
[]
false
false
false
true
false
let lex_t_non_dep (#a: Type u#a) (#b: Type u#b) (r_a: binrel u#a u#ra a) (r_b: binrel u#b u#rb b) : binrel u#(max a b) u#(max a b ra rb) (a & b) =
fun x y -> lex_t r_a (fun _ -> r_b) (tuple_to_dep_tuple x) (tuple_to_dep_tuple y)
false
FStar.LexicographicOrdering.fsti
FStar.LexicographicOrdering.lex_aux
val lex_aux (#a: Type u#a) (#b: (a -> Type u#b)) (r_a: binrel u#a u#ra a) (r_b: (x: a -> binrel u#b u#rb (b x))) : binrel u#(max a b) u#0 (x: a & b x)
val lex_aux (#a: Type u#a) (#b: (a -> Type u#b)) (r_a: binrel u#a u#ra a) (r_b: (x: a -> binrel u#b u#rb (b x))) : binrel u#(max a b) u#0 (x: a & b x)
let lex_aux (#a:Type u#a) (#b:a -> Type u#b) (r_a:binrel u#a u#ra a) (r_b:(x:a -> binrel u#b u#rb (b x))) : binrel u#(max a b) u#0 (x:a & b x) = fun (| x1, y1 |) (| x2, y2 |) -> (squash (r_a x1 x2)) \/ (x1 == x2 /\ squash ((r_b x1) y1 y2))
{ "file_name": "ulib/FStar.LexicographicOrdering.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 41, "end_line": 85, "start_col": 0, "start_line": 79 }
(* Copyright 2021 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 and Nikhil Swamy *) module FStar.LexicographicOrdering /// This module proves that lexicographic ordering is well-founded /// (i.e. every element is accessible) /// /// It defines the lex relation as an inductive, and prove its well-foundedness /// /// Since SMT proofs in F* are more amenable to squashed definitions, /// the module also defines a squashed version of the lex relation, /// and prove its well-foundedness, reusing the proof for the constructive version /// /// See tests/micro-benchmarks/Test.WellFoundedRecursion.fst for /// how we use squashed `lex` to prove termination for the ackermann function /// /// Finally, the module defines a non-dependent version of lex /// (in-terms of dependent lex), and uses it to prove well-foundedness of symmetric products too /// /// Some references: /// - https://github.com/coq/coq/blob/master/theories/Wellfounded/Lexicographic_Product.v /// - Constructing Recursion Operators in Type Theory, L. Paulson JSC (1986) 2, 325-355 open FStar.WellFounded /// Definition of lexicographic ordering as a relation over dependent tuples /// /// Two elements are related if: /// - Either their first components are related /// - Or, the first components are equal, and the second components are related noeq type lex_t (#a:Type u#a) (#b:a -> Type u#b) (r_a:binrel u#a u#ra a) (r_b:(x:a -> binrel u#b u#rb (b x))) : (x:a & b x) -> (x:a & b x) -> Type u#(max a b ra rb) = | Left_lex: x1:a -> x2:a -> y1:b x1 -> y2:b x2 -> r_a x1 x2 -> lex_t r_a r_b (| x1, y1 |) (| x2, y2 |) | Right_lex: x:a -> y1:b x -> y2:b x -> r_b x y1 y2 -> lex_t r_a r_b (| x, y1 |) (| x, y2 |) /// Given two well-founded relations `r_a` and `r_b`, /// their lexicographic ordering is also well-founded val lex_t_wf (#a:Type u#a) (#b:a -> Type u#b) (#r_a:binrel u#a u#ra a) (#r_b:(x:a -> binrel u#b u#rb (b x))) (wf_a:well_founded r_a) (wf_b:(x:a -> well_founded (r_b x))) : well_founded (lex_t r_a r_b) /// We can also define a squashed version of lex relation
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.WellFounded.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "FStar.LexicographicOrdering.fsti" }
[ { "abbrev": false, "full_module": "FStar.WellFounded", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_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_a: FStar.WellFounded.binrel a -> r_b: (x: a -> FStar.WellFounded.binrel (b x)) -> FStar.WellFounded.binrel (Prims.dtuple2 a (fun x -> b x))
Prims.Tot
[ "total" ]
[]
[ "FStar.WellFounded.binrel", "Prims.dtuple2", "FStar.Pervasives.Native.Mktuple2", "Prims.l_or", "Prims.squash", "Prims.l_and", "Prims.eq2" ]
[]
false
false
false
false
false
let lex_aux (#a: Type u#a) (#b: (a -> Type u#b)) (r_a: binrel u#a u#ra a) (r_b: (x: a -> binrel u#b u#rb (b x))) : binrel u#(max a b) u#0 (x: a & b x) =
fun (| x1 , y1 |) (| x2 , y2 |) -> (squash (r_a x1 x2)) \/ (x1 == x2 /\ squash ((r_b x1) y1 y2))
false
FStar.LexicographicOrdering.fsti
FStar.LexicographicOrdering.lex
val lex (#a: Type u#a) (#b: (a -> Type u#b)) (#r_a: binrel u#a u#ra a) (#r_b: (x: a -> binrel u#b u#rb (b x))) (wf_a: well_founded r_a) (wf_b: (x: a -> well_founded (r_b x))) : well_founded_relation (x: a & b x)
val lex (#a: Type u#a) (#b: (a -> Type u#b)) (#r_a: binrel u#a u#ra a) (#r_b: (x: a -> binrel u#b u#rb (b x))) (wf_a: well_founded r_a) (wf_b: (x: a -> well_founded (r_b x))) : well_founded_relation (x: a & b x)
let lex (#a:Type u#a) (#b:a -> Type u#b) (#r_a:binrel u#a u#ra a) (#r_b:(x:a -> binrel u#b u#rb (b x))) (wf_a:well_founded r_a) (wf_b:(x:a -> well_founded (r_b x))) : well_founded_relation (x:a & b x) = lex_wf wf_a wf_b; lex_aux r_a r_b
{ "file_name": "ulib/FStar.LexicographicOrdering.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 19, "end_line": 118, "start_col": 0, "start_line": 111 }
(* Copyright 2021 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 and Nikhil Swamy *) module FStar.LexicographicOrdering /// This module proves that lexicographic ordering is well-founded /// (i.e. every element is accessible) /// /// It defines the lex relation as an inductive, and prove its well-foundedness /// /// Since SMT proofs in F* are more amenable to squashed definitions, /// the module also defines a squashed version of the lex relation, /// and prove its well-foundedness, reusing the proof for the constructive version /// /// See tests/micro-benchmarks/Test.WellFoundedRecursion.fst for /// how we use squashed `lex` to prove termination for the ackermann function /// /// Finally, the module defines a non-dependent version of lex /// (in-terms of dependent lex), and uses it to prove well-foundedness of symmetric products too /// /// Some references: /// - https://github.com/coq/coq/blob/master/theories/Wellfounded/Lexicographic_Product.v /// - Constructing Recursion Operators in Type Theory, L. Paulson JSC (1986) 2, 325-355 open FStar.WellFounded /// Definition of lexicographic ordering as a relation over dependent tuples /// /// Two elements are related if: /// - Either their first components are related /// - Or, the first components are equal, and the second components are related noeq type lex_t (#a:Type u#a) (#b:a -> Type u#b) (r_a:binrel u#a u#ra a) (r_b:(x:a -> binrel u#b u#rb (b x))) : (x:a & b x) -> (x:a & b x) -> Type u#(max a b ra rb) = | Left_lex: x1:a -> x2:a -> y1:b x1 -> y2:b x2 -> r_a x1 x2 -> lex_t r_a r_b (| x1, y1 |) (| x2, y2 |) | Right_lex: x:a -> y1:b x -> y2:b x -> r_b x y1 y2 -> lex_t r_a r_b (| x, y1 |) (| x, y2 |) /// Given two well-founded relations `r_a` and `r_b`, /// their lexicographic ordering is also well-founded val lex_t_wf (#a:Type u#a) (#b:a -> Type u#b) (#r_a:binrel u#a u#ra a) (#r_b:(x:a -> binrel u#b u#rb (b x))) (wf_a:well_founded r_a) (wf_b:(x:a -> well_founded (r_b x))) : well_founded (lex_t r_a r_b) /// We can also define a squashed version of lex relation unfold let lex_aux (#a:Type u#a) (#b:a -> Type u#b) (r_a:binrel u#a u#ra a) (r_b:(x:a -> binrel u#b u#rb (b x))) : binrel u#(max a b) u#0 (x:a & b x) = fun (| x1, y1 |) (| x2, y2 |) -> (squash (r_a x1 x2)) \/ (x1 == x2 /\ squash ((r_b x1) y1 y2)) /// Provide a mapping from a point in lex_aux to a squashed point in lex val lex_to_lex_t (#a:Type u#a) (#b:a -> Type u#b) (r_a:binrel u#a u#ra a) (r_b:(x:a -> binrel u#b u#rb (b x))) (t1 t2:(x:a & b x)) (p:lex_aux r_a r_b t1 t2) : squash (lex_t r_a r_b t1 t2) /// And prove that is it is well-founded let lex_wf (#a:Type u#a) (#b:a -> Type u#b) (#r_a:binrel u#a u#ra a) (#r_b:(x:a -> binrel u#b u#rb (b x))) (wf_a:well_founded r_a) (wf_b:(x:a -> well_founded (r_b x))) : Lemma (is_well_founded (lex_aux r_a r_b)) = subrelation_squash_wf (lex_to_lex_t r_a r_b) (lex_t_wf wf_a wf_b) /// A user-friendly lex_wf that returns a well-founded relation
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.WellFounded.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "FStar.LexicographicOrdering.fsti" }
[ { "abbrev": false, "full_module": "FStar.WellFounded", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_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
wf_a: FStar.WellFounded.well_founded r_a -> wf_b: (x: a -> FStar.WellFounded.well_founded (r_b x)) -> FStar.WellFounded.well_founded_relation (Prims.dtuple2 a (fun x -> b x))
Prims.Tot
[ "total" ]
[]
[ "FStar.WellFounded.binrel", "FStar.WellFounded.well_founded", "FStar.LexicographicOrdering.lex_aux", "Prims.unit", "FStar.LexicographicOrdering.lex_wf", "FStar.WellFounded.well_founded_relation", "Prims.dtuple2" ]
[]
false
false
false
false
false
let lex (#a: Type u#a) (#b: (a -> Type u#b)) (#r_a: binrel u#a u#ra a) (#r_b: (x: a -> binrel u#b u#rb (b x))) (wf_a: well_founded r_a) (wf_b: (x: a -> well_founded (r_b x))) : well_founded_relation (x: a & b x) =
lex_wf wf_a wf_b; lex_aux r_a r_b
false
FStar.LexicographicOrdering.fsti
FStar.LexicographicOrdering.lex_wf
val lex_wf (#a: Type u#a) (#b: (a -> Type u#b)) (#r_a: binrel u#a u#ra a) (#r_b: (x: a -> binrel u#b u#rb (b x))) (wf_a: well_founded r_a) (wf_b: (x: a -> well_founded (r_b x))) : Lemma (is_well_founded (lex_aux r_a r_b))
val lex_wf (#a: Type u#a) (#b: (a -> Type u#b)) (#r_a: binrel u#a u#ra a) (#r_b: (x: a -> binrel u#b u#rb (b x))) (wf_a: well_founded r_a) (wf_b: (x: a -> well_founded (r_b x))) : Lemma (is_well_founded (lex_aux r_a r_b))
let lex_wf (#a:Type u#a) (#b:a -> Type u#b) (#r_a:binrel u#a u#ra a) (#r_b:(x:a -> binrel u#b u#rb (b x))) (wf_a:well_founded r_a) (wf_b:(x:a -> well_founded (r_b x))) : Lemma (is_well_founded (lex_aux r_a r_b)) = subrelation_squash_wf (lex_to_lex_t r_a r_b) (lex_t_wf wf_a wf_b)
{ "file_name": "ulib/FStar.LexicographicOrdering.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 69, "end_line": 105, "start_col": 0, "start_line": 99 }
(* Copyright 2021 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 and Nikhil Swamy *) module FStar.LexicographicOrdering /// This module proves that lexicographic ordering is well-founded /// (i.e. every element is accessible) /// /// It defines the lex relation as an inductive, and prove its well-foundedness /// /// Since SMT proofs in F* are more amenable to squashed definitions, /// the module also defines a squashed version of the lex relation, /// and prove its well-foundedness, reusing the proof for the constructive version /// /// See tests/micro-benchmarks/Test.WellFoundedRecursion.fst for /// how we use squashed `lex` to prove termination for the ackermann function /// /// Finally, the module defines a non-dependent version of lex /// (in-terms of dependent lex), and uses it to prove well-foundedness of symmetric products too /// /// Some references: /// - https://github.com/coq/coq/blob/master/theories/Wellfounded/Lexicographic_Product.v /// - Constructing Recursion Operators in Type Theory, L. Paulson JSC (1986) 2, 325-355 open FStar.WellFounded /// Definition of lexicographic ordering as a relation over dependent tuples /// /// Two elements are related if: /// - Either their first components are related /// - Or, the first components are equal, and the second components are related noeq type lex_t (#a:Type u#a) (#b:a -> Type u#b) (r_a:binrel u#a u#ra a) (r_b:(x:a -> binrel u#b u#rb (b x))) : (x:a & b x) -> (x:a & b x) -> Type u#(max a b ra rb) = | Left_lex: x1:a -> x2:a -> y1:b x1 -> y2:b x2 -> r_a x1 x2 -> lex_t r_a r_b (| x1, y1 |) (| x2, y2 |) | Right_lex: x:a -> y1:b x -> y2:b x -> r_b x y1 y2 -> lex_t r_a r_b (| x, y1 |) (| x, y2 |) /// Given two well-founded relations `r_a` and `r_b`, /// their lexicographic ordering is also well-founded val lex_t_wf (#a:Type u#a) (#b:a -> Type u#b) (#r_a:binrel u#a u#ra a) (#r_b:(x:a -> binrel u#b u#rb (b x))) (wf_a:well_founded r_a) (wf_b:(x:a -> well_founded (r_b x))) : well_founded (lex_t r_a r_b) /// We can also define a squashed version of lex relation unfold let lex_aux (#a:Type u#a) (#b:a -> Type u#b) (r_a:binrel u#a u#ra a) (r_b:(x:a -> binrel u#b u#rb (b x))) : binrel u#(max a b) u#0 (x:a & b x) = fun (| x1, y1 |) (| x2, y2 |) -> (squash (r_a x1 x2)) \/ (x1 == x2 /\ squash ((r_b x1) y1 y2)) /// Provide a mapping from a point in lex_aux to a squashed point in lex val lex_to_lex_t (#a:Type u#a) (#b:a -> Type u#b) (r_a:binrel u#a u#ra a) (r_b:(x:a -> binrel u#b u#rb (b x))) (t1 t2:(x:a & b x)) (p:lex_aux r_a r_b t1 t2) : squash (lex_t r_a r_b t1 t2) /// And prove that is it is well-founded
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.WellFounded.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "FStar.LexicographicOrdering.fsti" }
[ { "abbrev": false, "full_module": "FStar.WellFounded", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_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
wf_a: FStar.WellFounded.well_founded r_a -> wf_b: (x: a -> FStar.WellFounded.well_founded (r_b x)) -> FStar.Pervasives.Lemma (ensures FStar.WellFounded.is_well_founded (FStar.LexicographicOrdering.lex_aux r_a r_b))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "FStar.WellFounded.binrel", "FStar.WellFounded.well_founded", "FStar.WellFounded.subrelation_squash_wf", "Prims.dtuple2", "FStar.LexicographicOrdering.lex_t", "FStar.LexicographicOrdering.lex_aux", "FStar.LexicographicOrdering.lex_to_lex_t", "FStar.LexicographicOrdering.lex_t_wf", "Prims.unit", "Prims.l_True", "Prims.squash", "FStar.WellFounded.is_well_founded", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let lex_wf (#a: Type u#a) (#b: (a -> Type u#b)) (#r_a: binrel u#a u#ra a) (#r_b: (x: a -> binrel u#b u#rb (b x))) (wf_a: well_founded r_a) (wf_b: (x: a -> well_founded (r_b x))) : Lemma (is_well_founded (lex_aux r_a r_b)) =
subrelation_squash_wf (lex_to_lex_t r_a r_b) (lex_t_wf wf_a wf_b)
false
FStar.LexicographicOrdering.fsti
FStar.LexicographicOrdering.sym_wf
val sym_wf (#a: Type u#a) (#b: Type u#b) (#r_a: binrel u#a u#ra a) (#r_b: binrel u#b u#rb b) (wf_a: well_founded r_a) (wf_b: well_founded r_b) : well_founded (sym r_a r_b)
val sym_wf (#a: Type u#a) (#b: Type u#b) (#r_a: binrel u#a u#ra a) (#r_b: binrel u#b u#rb b) (wf_a: well_founded r_a) (wf_b: well_founded r_b) : well_founded (sym r_a r_b)
let sym_wf (#a:Type u#a) (#b:Type u#b) (#r_a:binrel u#a u#ra a) (#r_b:binrel u#b u#rb b) (wf_a:well_founded r_a) (wf_b:well_founded r_b) : well_founded (sym r_a r_b) = subrelation_wf sym_sub_lex (lex_t_non_dep_wf wf_a wf_b)
{ "file_name": "ulib/FStar.LexicographicOrdering.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 59, "end_line": 194, "start_col": 0, "start_line": 187 }
(* Copyright 2021 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 and Nikhil Swamy *) module FStar.LexicographicOrdering /// This module proves that lexicographic ordering is well-founded /// (i.e. every element is accessible) /// /// It defines the lex relation as an inductive, and prove its well-foundedness /// /// Since SMT proofs in F* are more amenable to squashed definitions, /// the module also defines a squashed version of the lex relation, /// and prove its well-foundedness, reusing the proof for the constructive version /// /// See tests/micro-benchmarks/Test.WellFoundedRecursion.fst for /// how we use squashed `lex` to prove termination for the ackermann function /// /// Finally, the module defines a non-dependent version of lex /// (in-terms of dependent lex), and uses it to prove well-foundedness of symmetric products too /// /// Some references: /// - https://github.com/coq/coq/blob/master/theories/Wellfounded/Lexicographic_Product.v /// - Constructing Recursion Operators in Type Theory, L. Paulson JSC (1986) 2, 325-355 open FStar.WellFounded /// Definition of lexicographic ordering as a relation over dependent tuples /// /// Two elements are related if: /// - Either their first components are related /// - Or, the first components are equal, and the second components are related noeq type lex_t (#a:Type u#a) (#b:a -> Type u#b) (r_a:binrel u#a u#ra a) (r_b:(x:a -> binrel u#b u#rb (b x))) : (x:a & b x) -> (x:a & b x) -> Type u#(max a b ra rb) = | Left_lex: x1:a -> x2:a -> y1:b x1 -> y2:b x2 -> r_a x1 x2 -> lex_t r_a r_b (| x1, y1 |) (| x2, y2 |) | Right_lex: x:a -> y1:b x -> y2:b x -> r_b x y1 y2 -> lex_t r_a r_b (| x, y1 |) (| x, y2 |) /// Given two well-founded relations `r_a` and `r_b`, /// their lexicographic ordering is also well-founded val lex_t_wf (#a:Type u#a) (#b:a -> Type u#b) (#r_a:binrel u#a u#ra a) (#r_b:(x:a -> binrel u#b u#rb (b x))) (wf_a:well_founded r_a) (wf_b:(x:a -> well_founded (r_b x))) : well_founded (lex_t r_a r_b) /// We can also define a squashed version of lex relation unfold let lex_aux (#a:Type u#a) (#b:a -> Type u#b) (r_a:binrel u#a u#ra a) (r_b:(x:a -> binrel u#b u#rb (b x))) : binrel u#(max a b) u#0 (x:a & b x) = fun (| x1, y1 |) (| x2, y2 |) -> (squash (r_a x1 x2)) \/ (x1 == x2 /\ squash ((r_b x1) y1 y2)) /// Provide a mapping from a point in lex_aux to a squashed point in lex val lex_to_lex_t (#a:Type u#a) (#b:a -> Type u#b) (r_a:binrel u#a u#ra a) (r_b:(x:a -> binrel u#b u#rb (b x))) (t1 t2:(x:a & b x)) (p:lex_aux r_a r_b t1 t2) : squash (lex_t r_a r_b t1 t2) /// And prove that is it is well-founded let lex_wf (#a:Type u#a) (#b:a -> Type u#b) (#r_a:binrel u#a u#ra a) (#r_b:(x:a -> binrel u#b u#rb (b x))) (wf_a:well_founded r_a) (wf_b:(x:a -> well_founded (r_b x))) : Lemma (is_well_founded (lex_aux r_a r_b)) = subrelation_squash_wf (lex_to_lex_t r_a r_b) (lex_t_wf wf_a wf_b) /// A user-friendly lex_wf that returns a well-founded relation unfold let lex (#a:Type u#a) (#b:a -> Type u#b) (#r_a:binrel u#a u#ra a) (#r_b:(x:a -> binrel u#b u#rb (b x))) (wf_a:well_founded r_a) (wf_b:(x:a -> well_founded (r_b x))) : well_founded_relation (x:a & b x) = lex_wf wf_a wf_b; lex_aux r_a r_b /// We can also define a non-dependent version of the lex ordering, /// in terms of the dependent lex tuple, /// and prove its well-foundedness let tuple_to_dep_tuple (#a #b:Type) (x:a & b) : dtuple2 a (fun _ -> b) = (| fst x, snd x |) /// The non-dependent lexicographic ordering /// and its well-foundedness let lex_t_non_dep (#a:Type u#a) (#b:Type u#b) (r_a:binrel u#a u#ra a) (r_b:binrel u#b u#rb b) : binrel u#(max a b) u#(max a b ra rb) (a & b) = fun x y -> lex_t r_a (fun _ -> r_b) (tuple_to_dep_tuple x) (tuple_to_dep_tuple y) val lex_t_non_dep_wf (#a:Type u#a) (#b:Type u#b) (#r_a:binrel u#a u#ra a) (#r_b:binrel u#b u#rb b) (wf_a:well_founded r_a) (wf_b:well_founded r_b) : well_founded (lex_t_non_dep r_a r_b) /// Symmetric product relation /// we can prove its well-foundedness by showing that it is a subrelation of non-dep lex noeq type sym (#a:Type u#a) (#b:Type u#b) (r_a:binrel u#a u#ra a) (r_b:binrel u#b u#rb b) : (a & b) -> (a & b) -> Type u#(max a b ra rb) = | Left_sym: x1:a -> x2:a -> y:b -> r_a x1 x2 -> sym r_a r_b (x1, y) (x2, y) | Right_sym: x:a -> y1:b -> y2:b -> r_b y1 y2 -> sym r_a r_b (x, y1) (x, y2) /// sym is a subrelation of non-dependent lex let sym_sub_lex (#a:Type u#a) (#b:Type u#b) (#r_a:binrel u#a u#ra a) (#r_b:binrel u#b u#rb b) (t1 t2:a & b) (p:sym r_a r_b t1 t2) : lex_t_non_dep r_a r_b t1 t2 = match p with | Left_sym x1 x2 y p -> Left_lex #a #(fun _ -> b) #r_a #(fun _ -> r_b) x1 x2 y y p | Right_sym x y1 y2 p -> Right_lex #a #(fun _ -> b) #r_a #(fun _ -> r_b) x y1 y2 p /// Theorem for symmetric product
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.WellFounded.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "FStar.LexicographicOrdering.fsti" }
[ { "abbrev": false, "full_module": "FStar.WellFounded", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_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
wf_a: FStar.WellFounded.well_founded r_a -> wf_b: FStar.WellFounded.well_founded r_b -> FStar.WellFounded.well_founded (FStar.LexicographicOrdering.sym r_a r_b)
Prims.Tot
[ "total" ]
[]
[ "FStar.WellFounded.binrel", "FStar.WellFounded.well_founded", "FStar.WellFounded.subrelation_wf", "FStar.Pervasives.Native.tuple2", "FStar.LexicographicOrdering.lex_t_non_dep", "FStar.LexicographicOrdering.sym", "FStar.LexicographicOrdering.sym_sub_lex", "FStar.LexicographicOrdering.lex_t_non_dep_wf" ]
[]
false
false
false
false
false
let sym_wf (#a: Type u#a) (#b: Type u#b) (#r_a: binrel u#a u#ra a) (#r_b: binrel u#b u#rb b) (wf_a: well_founded r_a) (wf_b: well_founded r_b) : well_founded (sym r_a r_b) =
subrelation_wf sym_sub_lex (lex_t_non_dep_wf wf_a wf_b)
false
Vale.PPC64LE.Stack_Sems.fst
Vale.PPC64LE.Stack_Sems.free_stack_same_load128
val free_stack_same_load128 (start:int) (finish:int) (ptr:int) (h:machine_stack) : Lemma (requires S.valid_src_stack128 ptr h /\ (ptr >= finish \/ ptr + 16 <= start)) (ensures S.eval_stack128 ptr h == S.eval_stack128 ptr (S.free_stack' start finish h)) [SMTPat (S.eval_stack128 ptr (S.free_stack' start finish h))]
val free_stack_same_load128 (start:int) (finish:int) (ptr:int) (h:machine_stack) : Lemma (requires S.valid_src_stack128 ptr h /\ (ptr >= finish \/ ptr + 16 <= start)) (ensures S.eval_stack128 ptr h == S.eval_stack128 ptr (S.free_stack' start finish h)) [SMTPat (S.eval_stack128 ptr (S.free_stack' start finish h))]
let free_stack_same_load128 start finish ptr h = reveal_opaque (`%S.valid_addr128) S.valid_addr128; let Machine_stack _ mem = h in let Machine_stack _ mem' = S.free_stack' start finish h in Classical.forall_intro (Vale.Lib.Set.remove_between_reveal (Map.domain mem) start finish); S.get_heap_val128_reveal (); S.get_heap_val32_reveal ()
{ "file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.Stack_Sems.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 28, "end_line": 41, "start_col": 0, "start_line": 35 }
module Vale.PPC64LE.Stack_Sems open FStar.Mul friend Vale.PPC64LE.Stack_i let stack_to_s s = s let stack_from_s s = s let lemma_stack_from_to s = () let lemma_stack_to_from s = () let equiv_valid_src_stack64 ptr h = () let equiv_load_stack64 ptr h = () let free_stack_same_load start finish ptr h = reveal_opaque (`%S.valid_addr64) S.valid_addr64; let Machine_stack _ mem = h in let Machine_stack _ mem' = S.free_stack' start finish h in Classical.forall_intro (Vale.Lib.Set.remove_between_reveal (Map.domain mem) start finish); S.get_heap_val64_reveal () let equiv_store_stack64 ptr v h = () let store64_same_init_r1 ptr v h = () let equiv_init_r1 h = () let equiv_free_stack start finish h = () let equiv_valid_src_stack128 ptr h = () let equiv_load_stack128 ptr h = ()
{ "checked_file": "/", "dependencies": [ "Vale.PPC64LE.Stack_i.fst.checked", "Vale.Lib.Set.fsti.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Map.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.PPC64LE.Stack_Sems.fst" }
[ { "abbrev": true, "full_module": "Vale.PPC64LE.Semantics_s", "short_module": "S" }, { "abbrev": false, "full_module": "Vale.PPC64LE.Stack_i", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
start: Prims.int -> finish: Prims.int -> ptr: Prims.int -> h: Vale.PPC64LE.Machine_s.machine_stack -> FStar.Pervasives.Lemma (requires Vale.PPC64LE.Semantics_s.valid_src_stack128 ptr h /\ (ptr >= finish \/ ptr + 16 <= start)) (ensures Vale.PPC64LE.Semantics_s.eval_stack128 ptr h == Vale.PPC64LE.Semantics_s.eval_stack128 ptr (Vale.PPC64LE.Semantics_s.free_stack' start finish h)) [ SMTPat (Vale.PPC64LE.Semantics_s.eval_stack128 ptr (Vale.PPC64LE.Semantics_s.free_stack' start finish h)) ]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.int", "Vale.PPC64LE.Machine_s.machine_stack", "Vale.PPC64LE.Machine_s.nat64", "Prims.b2t", "Prims.op_GreaterThanOrEqual", "FStar.Map.t", "Vale.PPC64LE.Machine_s.nat8", "Vale.Arch.MachineHeap_s.get_heap_val32_reveal", "Prims.unit", "Vale.Arch.MachineHeap_s.get_heap_val128_reveal", "FStar.Classical.forall_intro", "Prims.l_and", "Prims.l_imp", "Prims.op_LessThanOrEqual", "Prims.op_LessThan", "Prims.op_Negation", "FStar.Set.mem", "Vale.Lib.Set.remove_between", "FStar.Map.domain", "Prims.l_or", "Prims.op_Equality", "Prims.bool", "Vale.Lib.Set.remove_between_reveal", "Vale.PPC64LE.Semantics_s.free_stack'", "FStar.Pervasives.reveal_opaque", "Vale.Arch.MachineHeap_s.machine_heap", "Vale.Arch.MachineHeap_s.valid_addr128" ]
[]
false
false
true
false
false
let free_stack_same_load128 start finish ptr h =
reveal_opaque (`%S.valid_addr128) S.valid_addr128; let Machine_stack _ mem = h in let Machine_stack _ mem' = S.free_stack' start finish h in Classical.forall_intro (Vale.Lib.Set.remove_between_reveal (Map.domain mem) start finish); S.get_heap_val128_reveal (); S.get_heap_val32_reveal ()
false
Hacl.Poly1305.Field32xN.Lemmas0.fst
Hacl.Poly1305.Field32xN.Lemmas0.smul_add_felem5_eval_lemma_i
val smul_add_felem5_eval_lemma_i: #w:lanes -> #m1:scale32 -> #m2:scale32_5 -> #m3:scale64_5{m3 +* m1 *^ m2 <=* s64x5 4096} -> u1:uint64xN w{felem_fits1 u1 m1} -> f2:felem5 w{felem_fits5 f2 m2} -> acc1:felem_wide5 w{felem_wide_fits5 acc1 m3} -> i:nat{i < w} -> Lemma ((fas_nat5 (smul_add_felem5 #w u1 f2 acc1)).[i] == (fas_nat5 acc1).[i] + (uint64xN_v u1).[i] * (fas_nat5 f2).[i])
val smul_add_felem5_eval_lemma_i: #w:lanes -> #m1:scale32 -> #m2:scale32_5 -> #m3:scale64_5{m3 +* m1 *^ m2 <=* s64x5 4096} -> u1:uint64xN w{felem_fits1 u1 m1} -> f2:felem5 w{felem_fits5 f2 m2} -> acc1:felem_wide5 w{felem_wide_fits5 acc1 m3} -> i:nat{i < w} -> Lemma ((fas_nat5 (smul_add_felem5 #w u1 f2 acc1)).[i] == (fas_nat5 acc1).[i] + (uint64xN_v u1).[i] * (fas_nat5 f2).[i])
let smul_add_felem5_eval_lemma_i #w #m1 #m2 #m3 u1 f2 acc1 i = let o = smul_add_felem5 #w u1 f2 acc1 in let (m20, m21, m22, m23, m24) = m2 in let (m30, m31, m32, m33, m34) = m3 in let vu1 = (uint64xN_v u1).[i] in let (tf20, tf21, tf22, tf23, tf24) = as_tup64_i f2 i in let (ta0, ta1, ta2, ta3, ta4) = as_tup64_i acc1 i in let (to0, to1, to2, to3, to4) = as_tup64_i o i in smul_add_mod_lemma #m1 #m20 #m30 vu1 (v tf20) (v ta0); smul_add_mod_lemma #m1 #m21 #m31 vu1 (v tf21) (v ta1); smul_add_mod_lemma #m1 #m22 #m32 vu1 (v tf22) (v ta2); smul_add_mod_lemma #m1 #m23 #m33 vu1 (v tf23) (v ta3); smul_add_mod_lemma #m1 #m24 #m34 vu1 (v tf24) (v ta4); calc (==) { (fas_nat5 o).[i]; (==) { } v ta0 + vu1 * v tf20 + (v ta1 + vu1 * v tf21) * pow26 + (v ta2 + vu1 * v tf22) * pow52 + (v ta3 + vu1 * v tf23) * pow78 + (v ta4 + vu1 * v tf24) * pow104; (==) { FStar.Math.Lemmas.distributivity_add_left (v ta1) (vu1 * v tf21) pow26; FStar.Math.Lemmas.distributivity_add_left (v ta2) (vu1 * v tf22) pow52; FStar.Math.Lemmas.distributivity_add_left (v ta3) (vu1 * v tf23) pow78; FStar.Math.Lemmas.distributivity_add_left (v ta1) (vu1 * v tf24) pow104 } v ta0 + v ta1 * pow26 + v ta2 * pow52 + v ta3 * pow78 + v ta4 * pow104 + vu1 * v tf20 + vu1 * v tf21 * pow26 + vu1 * v tf22 * pow52 + vu1 * v tf23 * pow78 + vu1 * v tf24 * pow104; (==) { } (fas_nat5 acc1).[i] + vu1 * v tf20 + vu1 * v tf21 * pow26 + vu1 * v tf22 * pow52 + vu1 * v tf23 * pow78 + vu1 * v tf24 * pow104; }; assert ((fas_nat5 o).[i] == (fas_nat5 acc1).[i] + vu1 * v tf20 + vu1 * v tf21 * pow26 + vu1 * v tf22 * pow52 + vu1 * v tf23 * pow78 + vu1 * v tf24 * pow104); calc (==) { vu1 * (fas_nat5 f2).[i]; (==) { } vu1 * (v tf20 + v tf21 * pow26 + v tf22 * pow52 + v tf23 * pow78 + v tf24 * pow104); (==) { lemma_mul5_distr_l vu1 (v tf20) (v tf21 * pow26) (v tf22 * pow52) (v tf23 * pow78) (v tf24 * pow104)} vu1 * v tf20 + vu1 * (v tf21 * pow26) + vu1 * (v tf22 * pow52) + vu1 * (v tf23 * pow78) + vu1 * (v tf24 * pow104); (==) { FStar.Math.Lemmas.paren_mul_right vu1 (v tf21) pow26; FStar.Math.Lemmas.paren_mul_right vu1 (v tf22) pow52; FStar.Math.Lemmas.paren_mul_right vu1 (v tf23) pow78; FStar.Math.Lemmas.paren_mul_right vu1 (v tf24) pow104} vu1 * v tf20 + vu1 * v tf21 * pow26 + vu1 * v tf22 * pow52 + vu1 * v tf23 * pow78 + vu1 * v tf24 * pow104; }; assert ((fas_nat5 o).[i] == (fas_nat5 acc1).[i] + vu1 * (fas_nat5 f2).[i])
{ "file_name": "code/poly1305/Hacl.Poly1305.Field32xN.Lemmas0.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 76, "end_line": 293, "start_col": 0, "start_line": 247 }
module Hacl.Poly1305.Field32xN.Lemmas0 open Lib.IntTypes open Lib.IntVector open Lib.Sequence open FStar.Mul open FStar.Calc open Hacl.Spec.Poly1305.Vec include Hacl.Spec.Poly1305.Field32xN #reset-options "--z3rlimit 50 --using_facts_from '* -FStar.Seq' --max_fuel 0 --max_ifuel 0" val lemma_prime: unit -> Lemma (pow2 130 % prime = 5) let lemma_prime () = assert_norm (pow2 130 % prime = 5 % prime); assert_norm (5 < prime); FStar.Math.Lemmas.modulo_lemma 5 prime val lemma_mult_le: a:nat -> b:nat -> c:nat -> d:nat -> Lemma (requires a <= b /\ c <= d) (ensures a * c <= b * d) let lemma_mult_le a b c d = () val lemma_mul5_distr_l: a:nat -> b:nat -> c:nat -> d:nat -> e:nat -> f:nat -> Lemma (a * (b + c + d + e + f) == a * b + a * c + a * d + a * e + a * f) let lemma_mul5_distr_l a b c d e f = () val lemma_mul5_distr_r: a:nat -> b:nat -> c:nat -> d:nat -> e:nat -> f:nat -> Lemma ((a + b + c + d + e) * f == a * f + b * f + c * f + d * f + e * f) let lemma_mul5_distr_r a b c d e f = () val smul_mod_lemma: #m1:scale32 -> #m2:scale32 -> a:nat{a <= m1 * max26} -> b:nat{b <= m2 * max26} -> Lemma (a * b % pow2 64 == a * b) let smul_mod_lemma #m1 #m2 a b = lemma_mult_le a (m1 * max26) b (m2 * max26); assert (a * b <= m1 * m2 * max26 * max26); FStar.Math.Lemmas.modulo_lemma (a * b) (pow2 64) val smul_add_mod_lemma: #m1:scale32 -> #m2:scale32 -> #m3:scale64{m3 + m1 * m2 <= 4096} -> a:nat{a <= m1 * max26} -> b:nat{b <= m2 * max26} -> c:nat{c <= m3 * max26 * max26} -> Lemma ((c + a * b % pow2 64) % pow2 64 == c + a * b) let smul_add_mod_lemma #m1 #m2 #m3 a b c = assert_norm ((m3 + m1 * m2) * max26 * max26 < pow2 64); lemma_mult_le a (m1 * max26) b (m2 * max26); assert (c + a * b <= m3 * max26 * max26 + m1 * m2 * max26 * max26); FStar.Math.Lemmas.modulo_lemma (c + a * b) (pow2 64) val add5_lemma1: ma:scale64 -> mb:scale64 -> a:uint64 -> b:uint64 -> Lemma (requires v a <= ma * max26 /\ v b <= mb * max26 /\ ma + mb <= 64) (ensures v (a +. b) == v a + v b /\ v (a +. b) <= (ma + mb) * max26) let add5_lemma1 ma mb a b = assert (v a + v b <= (ma + mb) * max26); Math.Lemmas.lemma_mult_le_right max26 (ma + mb) 64; assert (v a + v b <= 64 * max26); assert_norm (64 * max26 < pow2 32); Math.Lemmas.small_mod (v a + v b) (pow2 32) #set-options "--ifuel 1" val fadd5_eval_lemma_i: #w:lanes -> f1:felem5 w{felem_fits5 f1 (2,2,2,2,2)} -> f2:felem5 w{felem_fits5 f2 (1,1,1,1,1)} -> i:nat{i < w} -> Lemma ((feval5 (fadd5 f1 f2)).[i] == pfadd (feval5 f1).[i] (feval5 f2).[i]) let fadd5_eval_lemma_i #w f1 f2 i = let o = fadd5 f1 f2 in let (f10, f11, f12, f13, f14) = as_tup64_i f1 i in let (f20, f21, f22, f23, f24) = as_tup64_i f2 i in let (o0, o1, o2, o3, o4) = as_tup64_i o i in add5_lemma1 2 1 f10 f20; add5_lemma1 2 1 f11 f21; add5_lemma1 2 1 f12 f22; add5_lemma1 2 1 f13 f23; add5_lemma1 2 1 f14 f24; assert (as_nat5 (o0, o1, o2, o3, o4) == as_nat5 (f10, f11, f12, f13, f14) + as_nat5 (f20, f21, f22, f23, f24)); FStar.Math.Lemmas.lemma_mod_plus_distr_l (as_nat5 (f10, f11, f12, f13, f14)) (as_nat5 (f20, f21, f22, f23, f24)) prime; FStar.Math.Lemmas.lemma_mod_plus_distr_r (as_nat5 (f10, f11, f12, f13, f14) % prime) (as_nat5 (f20, f21, f22, f23, f24)) prime val smul_felem5_fits_lemma_i: #w:lanes -> #m1:scale32 -> #m2:scale32 -> u1:uint64xN w{felem_fits1 u1 m1} -> f2:uint64xN w{felem_fits1 f2 m2} -> i:nat{i < w} -> Lemma ((uint64xN_v (vec_mul_mod f2 u1)).[i] <= m1 * m2 * max26 * max26) let smul_felem5_fits_lemma_i #w #m1 #m2 u1 f2 i = let o = vec_mul_mod f2 u1 in smul_mod_lemma #m1 #m2 (uint64xN_v u1).[i] (uint64xN_v f2).[i]; assert ((uint64xN_v o).[i] == (uint64xN_v u1).[i] * (uint64xN_v f2).[i]); lemma_mult_le (uint64xN_v u1).[i] (m1 * max26) (uint64xN_v f2).[i] (m2 * max26) val smul_felem5_eval_lemma_i: #w:lanes -> #m1:scale32 -> #m2:scale32_5 -> u1:uint64xN w{felem_fits1 u1 m1} -> f2:felem5 w{felem_fits5 f2 m2} -> i:nat{i < w} -> Lemma ((fas_nat5 (smul_felem5 #w u1 f2)).[i] == (uint64xN_v u1).[i] * (fas_nat5 f2).[i]) let smul_felem5_eval_lemma_i #w #m1 #m2 u1 f2 i = let o = smul_felem5 #w u1 f2 in let (m20, m21, m22, m23, m24) = m2 in let vu1 = (uint64xN_v u1).[i] in let (tf20, tf21, tf22, tf23, tf24) = as_tup64_i f2 i in let (to0, to1, to2, to3, to4) = as_tup64_i o i in smul_mod_lemma #m1 #m20 vu1 (v tf20); smul_mod_lemma #m1 #m21 vu1 (v tf21); smul_mod_lemma #m1 #m22 vu1 (v tf22); smul_mod_lemma #m1 #m23 vu1 (v tf23); smul_mod_lemma #m1 #m24 vu1 (v tf24); assert ((fas_nat5 o).[i] == vu1 * v tf20 + vu1 * v tf21 * pow26 + vu1 * v tf22 * pow52 + vu1 * v tf23 * pow78 + vu1 * v tf24 * pow104); calc (==) { vu1 * (fas_nat5 f2).[i]; (==) { } vu1 * (v tf20 + v tf21 * pow26 + v tf22 * pow52 + v tf23 * pow78 + v tf24 * pow104); (==) { lemma_mul5_distr_l vu1 (v tf20) (v tf21 * pow26) (v tf22 * pow52) (v tf23 * pow78) (v tf24 * pow104)} vu1 * v tf20 + vu1 * (v tf21 * pow26) + vu1 * (v tf22 * pow52) + vu1 * (v tf23 * pow78) + vu1 * (v tf24 * pow104); (==) { FStar.Math.Lemmas.paren_mul_right vu1 (v tf21) pow26; FStar.Math.Lemmas.paren_mul_right vu1 (v tf22) pow52; FStar.Math.Lemmas.paren_mul_right vu1 (v tf23) pow78; FStar.Math.Lemmas.paren_mul_right vu1 (v tf24) pow104} vu1 * v tf20 + vu1 * v tf21 * pow26 + vu1 * v tf22 * pow52 + vu1 * v tf23 * pow78 + vu1 * v tf24 * pow104; }; assert (vu1 * (fas_nat5 f2).[i] == (fas_nat5 o).[i]) val smul_felem5_fits_lemma1: #w:lanes -> #m1:scale32 -> #m2:scale32 -> u1:uint64xN w{felem_fits1 u1 m1} -> f2:uint64xN w{felem_fits1 f2 m2} -> Lemma (felem_wide_fits1 (vec_mul_mod f2 u1) (m1 * m2)) let smul_felem5_fits_lemma1 #w #m1 #m2 u1 f2 = match w with | 1 -> smul_felem5_fits_lemma_i #w #m1 #m2 u1 f2 0 | 2 -> smul_felem5_fits_lemma_i #w #m1 #m2 u1 f2 0; smul_felem5_fits_lemma_i #w #m1 #m2 u1 f2 1 | 4 -> smul_felem5_fits_lemma_i #w #m1 #m2 u1 f2 0; smul_felem5_fits_lemma_i #w #m1 #m2 u1 f2 1; smul_felem5_fits_lemma_i #w #m1 #m2 u1 f2 2; smul_felem5_fits_lemma_i #w #m1 #m2 u1 f2 3 val smul_felem5_fits_lemma: #w:lanes -> #m1:scale32 -> #m2:scale32_5 -> u1:uint64xN w{felem_fits1 u1 m1} -> f2:felem5 w{felem_fits5 f2 m2} -> Lemma (felem_wide_fits5 (smul_felem5 #w u1 f2) (m1 *^ m2)) let smul_felem5_fits_lemma #w #m1 #m2 u1 f2 = let (f20, f21, f22, f23, f24) = f2 in let (m20, m21, m22, m23, m24) = m2 in smul_felem5_fits_lemma1 #w #m1 #m20 u1 f20; smul_felem5_fits_lemma1 #w #m1 #m21 u1 f21; smul_felem5_fits_lemma1 #w #m1 #m22 u1 f22; smul_felem5_fits_lemma1 #w #m1 #m23 u1 f23; smul_felem5_fits_lemma1 #w #m1 #m24 u1 f24 val smul_felem5_eval_lemma: #w:lanes -> #m1:scale32 -> #m2:scale32_5 -> u1:uint64xN w{felem_fits1 u1 m1} -> f2:felem5 w{felem_fits5 f2 m2} -> Lemma (fas_nat5 (smul_felem5 #w u1 f2) == map2 #nat #nat #nat (fun a b -> a * b) (uint64xN_v u1) (fas_nat5 f2)) let smul_felem5_eval_lemma #w #m1 #m2 u1 f2 = FStar.Classical.forall_intro (smul_felem5_eval_lemma_i #w #m1 #m2 u1 f2); eq_intro (fas_nat5 (smul_felem5 #w u1 f2)) (map2 #nat #nat #nat (fun a b -> a * b) (uint64xN_v u1) (fas_nat5 f2)) val smul_add_felem5_fits_lemma_i: #w:lanes -> #m1:scale32 -> #m2:scale32 -> #m3:scale64{m3 + m1 * m2 <= 4096} -> u1:uint64xN w{felem_fits1 u1 m1} -> f2:uint64xN w{felem_fits1 f2 m2} -> acc1:uint64xN w{felem_wide_fits1 acc1 m3} -> i:nat{i < w} -> Lemma ((uint64xN_v (vec_add_mod acc1 (vec_mul_mod f2 u1))).[i] <= (m3 + m1 * m2) * max26 * max26) #push-options "--z3rlimit 200" let smul_add_felem5_fits_lemma_i #w #m1 #m2 #m3 u1 f2 acc1 i = let o = vec_add_mod acc1 (vec_mul_mod f2 u1) in smul_add_mod_lemma #m1 #m2 #m3 (uint64xN_v u1).[i] (uint64xN_v f2).[i] (uint64xN_v acc1).[i]; assert ((uint64xN_v o).[i] == (uint64xN_v acc1).[i] + (uint64xN_v u1).[i] * (uint64xN_v f2).[i]); lemma_mult_le (uint64xN_v u1).[i] (m1 * max26) (uint64xN_v f2).[i] (m2 * max26); assert ((uint64xN_v o).[i] <= m3 * max26 * max26 + m1 * m2 * max26 * max26) #pop-options val smul_add_felem5_eval_lemma_i: #w:lanes -> #m1:scale32 -> #m2:scale32_5 -> #m3:scale64_5{m3 +* m1 *^ m2 <=* s64x5 4096} -> u1:uint64xN w{felem_fits1 u1 m1} -> f2:felem5 w{felem_fits5 f2 m2} -> acc1:felem_wide5 w{felem_wide_fits5 acc1 m3} -> i:nat{i < w} -> Lemma ((fas_nat5 (smul_add_felem5 #w u1 f2 acc1)).[i] == (fas_nat5 acc1).[i] + (uint64xN_v u1).[i] * (fas_nat5 f2).[i])
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntVector.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Poly1305.Vec.fst.checked", "Hacl.Spec.Poly1305.Field32xN.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Poly1305.Field32xN.Lemmas0.fst" }
[ { "abbrev": false, "full_module": "Hacl.Spec.Poly1305.Field32xN", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Poly1305.Vec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntVector", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Poly1305.Field32xN", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Poly1305.Field32xN", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
u1: Hacl.Spec.Poly1305.Field32xN.uint64xN w {Hacl.Spec.Poly1305.Field32xN.felem_fits1 u1 m1} -> f2: Hacl.Spec.Poly1305.Field32xN.felem5 w {Hacl.Spec.Poly1305.Field32xN.felem_fits5 f2 m2} -> acc1: Hacl.Spec.Poly1305.Field32xN.felem_wide5 w {Hacl.Spec.Poly1305.Field32xN.felem_wide_fits5 acc1 m3} -> i: Prims.nat{i < w} -> FStar.Pervasives.Lemma (ensures (Hacl.Spec.Poly1305.Field32xN.fas_nat5 (Hacl.Spec.Poly1305.Field32xN.smul_add_felem5 u1 f2 acc1)).[ i ] == (Hacl.Spec.Poly1305.Field32xN.fas_nat5 acc1).[ i ] + (Hacl.Spec.Poly1305.Field32xN.uint64xN_v u1).[ i ] * (Hacl.Spec.Poly1305.Field32xN.fas_nat5 f2).[ i ])
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Hacl.Spec.Poly1305.Field32xN.lanes", "Hacl.Spec.Poly1305.Field32xN.scale32", "Hacl.Spec.Poly1305.Field32xN.scale32_5", "Hacl.Spec.Poly1305.Field32xN.scale64_5", "Hacl.Spec.Poly1305.Field32xN.op_Less_Equals_Star", "Hacl.Spec.Poly1305.Field32xN.op_Plus_Star", "Hacl.Spec.Poly1305.Field32xN.op_Star_Hat", "Hacl.Spec.Poly1305.Field32xN.s64x5", "Hacl.Spec.Poly1305.Field32xN.uint64xN", "Hacl.Spec.Poly1305.Field32xN.felem_fits1", "Hacl.Spec.Poly1305.Field32xN.felem5", "Hacl.Spec.Poly1305.Field32xN.felem_fits5", "Hacl.Spec.Poly1305.Field32xN.felem_wide5", "Hacl.Spec.Poly1305.Field32xN.felem_wide_fits5", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Lib.IntTypes.uint64", "Prims._assert", "Prims.eq2", "Prims.int", "Lib.Sequence.op_String_Access", "Hacl.Spec.Poly1305.Field32xN.fas_nat5", "Prims.op_Addition", "FStar.Mul.op_Star", "Prims.unit", "FStar.Calc.calc_finish", "Lib.IntTypes.v", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "Hacl.Spec.Poly1305.Field32xN.pow26", "Hacl.Spec.Poly1305.Field32xN.pow52", "Hacl.Spec.Poly1305.Field32xN.pow78", "Hacl.Spec.Poly1305.Field32xN.pow104", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "FStar.Calc.calc_step", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "Prims.squash", "Hacl.Poly1305.Field32xN.Lemmas0.lemma_mul5_distr_l", "FStar.Math.Lemmas.paren_mul_right", "FStar.Seq.Base.index", "Lib.Sequence.to_seq", "FStar.Math.Lemmas.distributivity_add_left", "Hacl.Poly1305.Field32xN.Lemmas0.smul_add_mod_lemma", "Hacl.Spec.Poly1305.Field32xN.tup64_5", "Hacl.Spec.Poly1305.Field32xN.as_tup64_i", "Hacl.Spec.Poly1305.Field32xN.uint64xN_v", "Hacl.Spec.Poly1305.Field32xN.smul_add_felem5" ]
[]
false
false
true
false
false
let smul_add_felem5_eval_lemma_i #w #m1 #m2 #m3 u1 f2 acc1 i =
let o = smul_add_felem5 #w u1 f2 acc1 in let m20, m21, m22, m23, m24 = m2 in let m30, m31, m32, m33, m34 = m3 in let vu1 = (uint64xN_v u1).[ i ] in let tf20, tf21, tf22, tf23, tf24 = as_tup64_i f2 i in let ta0, ta1, ta2, ta3, ta4 = as_tup64_i acc1 i in let to0, to1, to2, to3, to4 = as_tup64_i o i in smul_add_mod_lemma #m1 #m20 #m30 vu1 (v tf20) (v ta0); smul_add_mod_lemma #m1 #m21 #m31 vu1 (v tf21) (v ta1); smul_add_mod_lemma #m1 #m22 #m32 vu1 (v tf22) (v ta2); smul_add_mod_lemma #m1 #m23 #m33 vu1 (v tf23) (v ta3); smul_add_mod_lemma #m1 #m24 #m34 vu1 (v tf24) (v ta4); calc ( == ) { (fas_nat5 o).[ i ]; ( == ) { () } v ta0 + vu1 * v tf20 + (v ta1 + vu1 * v tf21) * pow26 + (v ta2 + vu1 * v tf22) * pow52 + (v ta3 + vu1 * v tf23) * pow78 + (v ta4 + vu1 * v tf24) * pow104; ( == ) { (FStar.Math.Lemmas.distributivity_add_left (v ta1) (vu1 * v tf21) pow26; FStar.Math.Lemmas.distributivity_add_left (v ta2) (vu1 * v tf22) pow52; FStar.Math.Lemmas.distributivity_add_left (v ta3) (vu1 * v tf23) pow78; FStar.Math.Lemmas.distributivity_add_left (v ta1) (vu1 * v tf24) pow104) } v ta0 + v ta1 * pow26 + v ta2 * pow52 + v ta3 * pow78 + v ta4 * pow104 + vu1 * v tf20 + (vu1 * v tf21) * pow26 + (vu1 * v tf22) * pow52 + (vu1 * v tf23) * pow78 + (vu1 * v tf24) * pow104; ( == ) { () } (fas_nat5 acc1).[ i ] + vu1 * v tf20 + (vu1 * v tf21) * pow26 + (vu1 * v tf22) * pow52 + (vu1 * v tf23) * pow78 + (vu1 * v tf24) * pow104; }; assert ((fas_nat5 o).[ i ] == (fas_nat5 acc1).[ i ] + vu1 * v tf20 + (vu1 * v tf21) * pow26 + (vu1 * v tf22) * pow52 + (vu1 * v tf23) * pow78 + (vu1 * v tf24) * pow104); calc ( == ) { vu1 * (fas_nat5 f2).[ i ]; ( == ) { () } vu1 * (v tf20 + v tf21 * pow26 + v tf22 * pow52 + v tf23 * pow78 + v tf24 * pow104); ( == ) { lemma_mul5_distr_l vu1 (v tf20) (v tf21 * pow26) (v tf22 * pow52) (v tf23 * pow78) (v tf24 * pow104) } vu1 * v tf20 + vu1 * (v tf21 * pow26) + vu1 * (v tf22 * pow52) + vu1 * (v tf23 * pow78) + vu1 * (v tf24 * pow104); ( == ) { (FStar.Math.Lemmas.paren_mul_right vu1 (v tf21) pow26; FStar.Math.Lemmas.paren_mul_right vu1 (v tf22) pow52; FStar.Math.Lemmas.paren_mul_right vu1 (v tf23) pow78; FStar.Math.Lemmas.paren_mul_right vu1 (v tf24) pow104) } vu1 * v tf20 + (vu1 * v tf21) * pow26 + (vu1 * v tf22) * pow52 + (vu1 * v tf23) * pow78 + (vu1 * v tf24) * pow104; }; assert ((fas_nat5 o).[ i ] == (fas_nat5 acc1).[ i ] + vu1 * (fas_nat5 f2).[ i ])
false
FStar.LexicographicOrdering.fsti
FStar.LexicographicOrdering.sym_sub_lex
val sym_sub_lex (#a: Type u#a) (#b: Type u#b) (#r_a: binrel u#a u#ra a) (#r_b: binrel u#b u#rb b) (t1 t2: a & b) (p: sym r_a r_b t1 t2) : lex_t_non_dep r_a r_b t1 t2
val sym_sub_lex (#a: Type u#a) (#b: Type u#b) (#r_a: binrel u#a u#ra a) (#r_b: binrel u#b u#rb b) (t1 t2: a & b) (p: sym r_a r_b t1 t2) : lex_t_non_dep r_a r_b t1 t2
let sym_sub_lex (#a:Type u#a) (#b:Type u#b) (#r_a:binrel u#a u#ra a) (#r_b:binrel u#b u#rb b) (t1 t2:a & b) (p:sym r_a r_b t1 t2) : lex_t_non_dep r_a r_b t1 t2 = match p with | Left_sym x1 x2 y p -> Left_lex #a #(fun _ -> b) #r_a #(fun _ -> r_b) x1 x2 y y p | Right_sym x y1 y2 p -> Right_lex #a #(fun _ -> b) #r_a #(fun _ -> r_b) x y1 y2 p
{ "file_name": "ulib/FStar.LexicographicOrdering.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 63, "end_line": 182, "start_col": 0, "start_line": 171 }
(* Copyright 2021 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 and Nikhil Swamy *) module FStar.LexicographicOrdering /// This module proves that lexicographic ordering is well-founded /// (i.e. every element is accessible) /// /// It defines the lex relation as an inductive, and prove its well-foundedness /// /// Since SMT proofs in F* are more amenable to squashed definitions, /// the module also defines a squashed version of the lex relation, /// and prove its well-foundedness, reusing the proof for the constructive version /// /// See tests/micro-benchmarks/Test.WellFoundedRecursion.fst for /// how we use squashed `lex` to prove termination for the ackermann function /// /// Finally, the module defines a non-dependent version of lex /// (in-terms of dependent lex), and uses it to prove well-foundedness of symmetric products too /// /// Some references: /// - https://github.com/coq/coq/blob/master/theories/Wellfounded/Lexicographic_Product.v /// - Constructing Recursion Operators in Type Theory, L. Paulson JSC (1986) 2, 325-355 open FStar.WellFounded /// Definition of lexicographic ordering as a relation over dependent tuples /// /// Two elements are related if: /// - Either their first components are related /// - Or, the first components are equal, and the second components are related noeq type lex_t (#a:Type u#a) (#b:a -> Type u#b) (r_a:binrel u#a u#ra a) (r_b:(x:a -> binrel u#b u#rb (b x))) : (x:a & b x) -> (x:a & b x) -> Type u#(max a b ra rb) = | Left_lex: x1:a -> x2:a -> y1:b x1 -> y2:b x2 -> r_a x1 x2 -> lex_t r_a r_b (| x1, y1 |) (| x2, y2 |) | Right_lex: x:a -> y1:b x -> y2:b x -> r_b x y1 y2 -> lex_t r_a r_b (| x, y1 |) (| x, y2 |) /// Given two well-founded relations `r_a` and `r_b`, /// their lexicographic ordering is also well-founded val lex_t_wf (#a:Type u#a) (#b:a -> Type u#b) (#r_a:binrel u#a u#ra a) (#r_b:(x:a -> binrel u#b u#rb (b x))) (wf_a:well_founded r_a) (wf_b:(x:a -> well_founded (r_b x))) : well_founded (lex_t r_a r_b) /// We can also define a squashed version of lex relation unfold let lex_aux (#a:Type u#a) (#b:a -> Type u#b) (r_a:binrel u#a u#ra a) (r_b:(x:a -> binrel u#b u#rb (b x))) : binrel u#(max a b) u#0 (x:a & b x) = fun (| x1, y1 |) (| x2, y2 |) -> (squash (r_a x1 x2)) \/ (x1 == x2 /\ squash ((r_b x1) y1 y2)) /// Provide a mapping from a point in lex_aux to a squashed point in lex val lex_to_lex_t (#a:Type u#a) (#b:a -> Type u#b) (r_a:binrel u#a u#ra a) (r_b:(x:a -> binrel u#b u#rb (b x))) (t1 t2:(x:a & b x)) (p:lex_aux r_a r_b t1 t2) : squash (lex_t r_a r_b t1 t2) /// And prove that is it is well-founded let lex_wf (#a:Type u#a) (#b:a -> Type u#b) (#r_a:binrel u#a u#ra a) (#r_b:(x:a -> binrel u#b u#rb (b x))) (wf_a:well_founded r_a) (wf_b:(x:a -> well_founded (r_b x))) : Lemma (is_well_founded (lex_aux r_a r_b)) = subrelation_squash_wf (lex_to_lex_t r_a r_b) (lex_t_wf wf_a wf_b) /// A user-friendly lex_wf that returns a well-founded relation unfold let lex (#a:Type u#a) (#b:a -> Type u#b) (#r_a:binrel u#a u#ra a) (#r_b:(x:a -> binrel u#b u#rb (b x))) (wf_a:well_founded r_a) (wf_b:(x:a -> well_founded (r_b x))) : well_founded_relation (x:a & b x) = lex_wf wf_a wf_b; lex_aux r_a r_b /// We can also define a non-dependent version of the lex ordering, /// in terms of the dependent lex tuple, /// and prove its well-foundedness let tuple_to_dep_tuple (#a #b:Type) (x:a & b) : dtuple2 a (fun _ -> b) = (| fst x, snd x |) /// The non-dependent lexicographic ordering /// and its well-foundedness let lex_t_non_dep (#a:Type u#a) (#b:Type u#b) (r_a:binrel u#a u#ra a) (r_b:binrel u#b u#rb b) : binrel u#(max a b) u#(max a b ra rb) (a & b) = fun x y -> lex_t r_a (fun _ -> r_b) (tuple_to_dep_tuple x) (tuple_to_dep_tuple y) val lex_t_non_dep_wf (#a:Type u#a) (#b:Type u#b) (#r_a:binrel u#a u#ra a) (#r_b:binrel u#b u#rb b) (wf_a:well_founded r_a) (wf_b:well_founded r_b) : well_founded (lex_t_non_dep r_a r_b) /// Symmetric product relation /// we can prove its well-foundedness by showing that it is a subrelation of non-dep lex noeq type sym (#a:Type u#a) (#b:Type u#b) (r_a:binrel u#a u#ra a) (r_b:binrel u#b u#rb b) : (a & b) -> (a & b) -> Type u#(max a b ra rb) = | Left_sym: x1:a -> x2:a -> y:b -> r_a x1 x2 -> sym r_a r_b (x1, y) (x2, y) | Right_sym: x:a -> y1:b -> y2:b -> r_b y1 y2 -> sym r_a r_b (x, y1) (x, y2) /// sym is a subrelation of non-dependent lex
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.WellFounded.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "FStar.LexicographicOrdering.fsti" }
[ { "abbrev": false, "full_module": "FStar.WellFounded", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_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
t1: (a * b) -> t2: (a * b) -> p: FStar.LexicographicOrdering.sym r_a r_b t1 t2 -> FStar.LexicographicOrdering.lex_t_non_dep r_a r_b t1 t2
Prims.Tot
[ "total" ]
[]
[ "FStar.WellFounded.binrel", "FStar.Pervasives.Native.tuple2", "FStar.LexicographicOrdering.sym", "FStar.LexicographicOrdering.Left_lex", "FStar.LexicographicOrdering.Right_lex", "FStar.LexicographicOrdering.lex_t_non_dep" ]
[]
false
false
false
false
false
let sym_sub_lex (#a: Type u#a) (#b: Type u#b) (#r_a: binrel u#a u#ra a) (#r_b: binrel u#b u#rb b) (t1 t2: a & b) (p: sym r_a r_b t1 t2) : lex_t_non_dep r_a r_b t1 t2 =
match p with | Left_sym x1 x2 y p -> Left_lex #a #(fun _ -> b) #r_a #(fun _ -> r_b) x1 x2 y y p | Right_sym x y1 y2 p -> Right_lex #a #(fun _ -> b) #r_a #(fun _ -> r_b) x y1 y2 p
false
Vale.PPC64LE.Stack_Sems.fst
Vale.PPC64LE.Stack_Sems.free_stack_same_load
val free_stack_same_load (start:int) (finish:int) (ptr:int) (h:machine_stack) : Lemma (requires S.valid_src_stack64 ptr h /\ (ptr >= finish \/ ptr + 8 <= start)) (ensures S.eval_stack ptr h == S.eval_stack ptr (S.free_stack' start finish h)) [SMTPat (S.eval_stack ptr (S.free_stack' start finish h))]
val free_stack_same_load (start:int) (finish:int) (ptr:int) (h:machine_stack) : Lemma (requires S.valid_src_stack64 ptr h /\ (ptr >= finish \/ ptr + 8 <= start)) (ensures S.eval_stack ptr h == S.eval_stack ptr (S.free_stack' start finish h)) [SMTPat (S.eval_stack ptr (S.free_stack' start finish h))]
let free_stack_same_load start finish ptr h = reveal_opaque (`%S.valid_addr64) S.valid_addr64; let Machine_stack _ mem = h in let Machine_stack _ mem' = S.free_stack' start finish h in Classical.forall_intro (Vale.Lib.Set.remove_between_reveal (Map.domain mem) start finish); S.get_heap_val64_reveal ()
{ "file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.Stack_Sems.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 28, "end_line": 21, "start_col": 0, "start_line": 16 }
module Vale.PPC64LE.Stack_Sems open FStar.Mul friend Vale.PPC64LE.Stack_i let stack_to_s s = s let stack_from_s s = s let lemma_stack_from_to s = () let lemma_stack_to_from s = () let equiv_valid_src_stack64 ptr h = () let equiv_load_stack64 ptr h = ()
{ "checked_file": "/", "dependencies": [ "Vale.PPC64LE.Stack_i.fst.checked", "Vale.Lib.Set.fsti.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Map.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.PPC64LE.Stack_Sems.fst" }
[ { "abbrev": true, "full_module": "Vale.PPC64LE.Semantics_s", "short_module": "S" }, { "abbrev": false, "full_module": "Vale.PPC64LE.Stack_i", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
start: Prims.int -> finish: Prims.int -> ptr: Prims.int -> h: Vale.PPC64LE.Machine_s.machine_stack -> FStar.Pervasives.Lemma (requires Vale.PPC64LE.Semantics_s.valid_src_stack64 ptr h /\ (ptr >= finish \/ ptr + 8 <= start)) (ensures Vale.PPC64LE.Semantics_s.eval_stack ptr h == Vale.PPC64LE.Semantics_s.eval_stack ptr (Vale.PPC64LE.Semantics_s.free_stack' start finish h)) [ SMTPat (Vale.PPC64LE.Semantics_s.eval_stack ptr (Vale.PPC64LE.Semantics_s.free_stack' start finish h)) ]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.int", "Vale.PPC64LE.Machine_s.machine_stack", "Vale.PPC64LE.Machine_s.nat64", "Prims.b2t", "Prims.op_GreaterThanOrEqual", "FStar.Map.t", "Vale.PPC64LE.Machine_s.nat8", "Vale.Arch.MachineHeap_s.get_heap_val64_reveal", "Prims.unit", "FStar.Classical.forall_intro", "Prims.l_and", "Prims.l_imp", "Prims.op_LessThanOrEqual", "Prims.op_LessThan", "Prims.op_Negation", "FStar.Set.mem", "Vale.Lib.Set.remove_between", "FStar.Map.domain", "Prims.l_or", "Prims.op_Equality", "Prims.bool", "Vale.Lib.Set.remove_between_reveal", "Vale.PPC64LE.Semantics_s.free_stack'", "FStar.Pervasives.reveal_opaque", "Vale.Arch.MachineHeap_s.machine_heap", "Vale.Arch.MachineHeap_s.valid_addr64" ]
[]
false
false
true
false
false
let free_stack_same_load start finish ptr h =
reveal_opaque (`%S.valid_addr64) S.valid_addr64; let Machine_stack _ mem = h in let Machine_stack _ mem' = S.free_stack' start finish h in Classical.forall_intro (Vale.Lib.Set.remove_between_reveal (Map.domain mem) start finish); S.get_heap_val64_reveal ()
false
MerkleTree.New.High.Correct.Path.fst
MerkleTree.New.High.Correct.Path.mt_get_path_acc_consistent
val mt_get_path_acc_consistent: #hsz:pos -> #f:MTS.hash_fun_t -> lv:nat{lv <= 32} -> i:nat -> j:nat{i <= j /\ j < pow2 (32 - lv)} -> olds:hashess #hsz {S.length olds = 32 /\ mt_olds_inv #hsz lv i olds} -> hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} -> rhs:hashes #hsz {S.length rhs = 32} -> k:nat{i <= k && k <= j} -> actd:bool -> Lemma (requires True) (ensures (log2c_bound j (32 - lv); mt_olds_hs_lth_inv_ok #_ #f lv i j olds hs; mt_hashes_lth_inv_log_converted_ #_ #f lv j (merge_hs #_ #f olds hs); S.equal (mt_get_path_acc #_ #f j (S.slice (merge_hs #_ #f olds hs) lv (lv + log2c j)) (S.slice rhs lv (lv + log2c j)) k actd) (mt_get_path_ #_ lv hs rhs i j k S.empty actd))) (decreases j)
val mt_get_path_acc_consistent: #hsz:pos -> #f:MTS.hash_fun_t -> lv:nat{lv <= 32} -> i:nat -> j:nat{i <= j /\ j < pow2 (32 - lv)} -> olds:hashess #hsz {S.length olds = 32 /\ mt_olds_inv #hsz lv i olds} -> hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} -> rhs:hashes #hsz {S.length rhs = 32} -> k:nat{i <= k && k <= j} -> actd:bool -> Lemma (requires True) (ensures (log2c_bound j (32 - lv); mt_olds_hs_lth_inv_ok #_ #f lv i j olds hs; mt_hashes_lth_inv_log_converted_ #_ #f lv j (merge_hs #_ #f olds hs); S.equal (mt_get_path_acc #_ #f j (S.slice (merge_hs #_ #f olds hs) lv (lv + log2c j)) (S.slice rhs lv (lv + log2c j)) k actd) (mt_get_path_ #_ lv hs rhs i j k S.empty actd))) (decreases j)
let rec mt_get_path_acc_consistent #hsz #f lv i j olds hs rhs k actd = log2c_bound j (32 - lv); mt_olds_hs_lth_inv_ok #_ #f lv i j olds hs; mt_hashes_lth_inv_log_converted_ #_ #f lv j (merge_hs #_ #f olds hs); if j = 0 then () else begin let nactd = if j % 2 = 0 then actd else true in let nactd_ = actd || j % 2 = 1 in assert (nactd == nactd_); let pa = mt_get_path_acc #_ #f j (S.slice (merge_hs #_ #f olds hs) lv (lv + log2c j)) (S.slice rhs lv (lv + log2c j)) k actd in let p = mt_get_path_ lv hs rhs i j k S.empty actd in log2c_div j; log2c_bound (j / 2) (32 - (lv + 1)); assert (mt_hashes_lth_inv (lv + 1) (j / 2) (merge_hs #_ #f olds hs)); assert (mt_hashes_lth_inv_log #hsz (j / 2) (S.slice (merge_hs #_ #f olds hs) (lv + 1) (lv + 1 + log2c (j / 2)))); let npsa = mt_get_path_step_acc j (S.index (merge_hs #_ #f olds hs) lv) (S.index rhs lv) k actd in let npa = mt_get_path_acc #_ #f (j / 2) (S.slice (merge_hs #_ #f olds hs) (lv + 1) (lv + 1 + log2c (j / 2))) (S.slice rhs (lv + 1) (lv + 1 + log2c (j / 2))) (k / 2) nactd_ in let nps = mt_make_path_step lv hs rhs i j k S.empty actd in let np = mt_get_path_ (lv + 1) hs rhs (i / 2) (j / 2) (k / 2) nps nactd in let npe = mt_get_path_ (lv + 1) hs rhs (i / 2) (j / 2) (k / 2) S.empty nactd in mt_get_path_pull (lv + 1) hs rhs (i / 2) (j / 2) (k / 2) nps nactd; assert (S.equal p np); assert (S.equal np (S.append nps npe)); assert (S.equal p (S.append nps npe)); assert (S.equal pa (if Some? npsa then S.cons (Some?.v npsa) npa else npa)); mt_get_path_acc_consistent #_ #f (lv + 1) (i / 2) (j / 2) olds hs rhs (k / 2) nactd; assert (S.equal npa npe); mt_get_path_step_acc_consistent #_ #f lv i j olds hs rhs k actd; if Some? npsa then begin assert (S.equal nps (S.cons (Some?.v npsa) S.empty)); assert (S.equal p (S.append (S.cons (Some?.v npsa) S.empty) npa)); assert (S.equal pa (S.cons (Some?.v npsa) npa)); seq_cons_append (Some?.v npsa) npa; assert (S.equal pa p) end else begin assert (S.equal nps S.empty); S.append_empty_l npe; assert (S.equal p npe); assert (S.equal pa npa); assert (S.equal pa p) end end
{ "file_name": "src/MerkleTree.New.High.Correct.Path.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 5, "end_line": 192, "start_col": 0, "start_line": 136 }
module MerkleTree.New.High.Correct.Path open EverCrypt open EverCrypt.Helpers open MerkleTree.New.High.Correct.Base // Need to use some facts of `mt_get_root` open MerkleTree.New.High.Correct.Rhs open FStar.Classical open FStar.Ghost open FStar.Seq module List = FStar.List.Tot module S = FStar.Seq module U32 = FStar.UInt32 module U8 = FStar.UInt8 type uint32_t = U32.t type uint8_t = U8.t module EHS = EverCrypt.Hash module MTS = MerkleTree.Spec open MerkleTree.New.High #reset-options "--z3rlimit 20" /// Correctness of path generation val path_spec: #hsz:pos -> k:nat -> j:nat{k <= j} -> actd:bool -> p:path #hsz {S.length p = mt_path_length k j actd} -> GTot (sp:S.seq (MTS.padded_hash #hsz){S.length sp = log2c j}) (decreases j) let rec path_spec #hsz k j actd p = if j = 0 then S.empty else (if k % 2 = 0 then (if j = k || (j = k + 1 && not actd) then S.cons MTS.HPad (path_spec (k / 2) (j / 2) (actd || (j % 2 = 1)) p) else S.cons (MTS.HRaw #hsz (S.head p)) (path_spec (k / 2) (j / 2) (actd || (j % 2 = 1)) (S.tail p))) else S.cons (MTS.HRaw #hsz (S.head p)) (path_spec (k / 2) (j / 2) (actd || (j % 2 = 1)) (S.tail p))) val mt_get_path_step_acc: #hsz:pos -> j:nat{j > 0} -> chs:hashes #hsz {S.length chs = j} -> crh:hash #hsz -> k:nat{k <= j} -> actd:bool -> GTot (option (hash #hsz)) let mt_get_path_step_acc #hsz j chs crh k actd = if k % 2 = 1 then Some (S.index chs (k - 1)) else (if k = j then None else if k + 1 = j then (if actd then Some crh else None) else Some (S.index chs (k + 1))) val mt_get_path_acc: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat -> fhs:hashess #hsz {S.length fhs = log2c j /\ mt_hashes_lth_inv_log #hsz j fhs} -> rhs:hashes #hsz {S.length rhs = log2c j} -> k:nat{k <= j} -> actd:bool -> GTot (np:path #hsz {S.length np = mt_path_length k j actd}) (decreases j) let rec mt_get_path_acc #_ #f j fhs rhs k actd = if j = 0 then S.empty else (let sp = mt_get_path_step_acc #_ j (S.head fhs) (S.head rhs) k actd in let rp = mt_get_path_acc #_ #f (j / 2) (S.tail fhs) (S.tail rhs) (k / 2) (actd || j % 2 = 1) in if Some? sp then (S.cons (Some?.v sp) rp) else rp) val mt_get_path_step_acc_consistent: #hsz:pos -> #f:MTS.hash_fun_t -> lv:nat{lv <= 32} -> i:nat -> j:nat{i <= j /\ j < pow2 (32 - lv)} -> olds:hashess #hsz {S.length olds = 32 /\ mt_olds_inv #hsz lv i olds} -> hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} -> rhs:hashes #hsz {S.length rhs = 32} -> k:nat{i <= k && k <= j} -> actd:bool -> Lemma (requires (j <> 0)) (ensures (log2c_bound j (32 - lv); mt_olds_hs_lth_inv_ok #_ #f lv i j olds hs; mt_hashes_lth_inv_log_converted_ #_ #f lv j (merge_hs #_ #f olds hs); (match mt_get_path_step_acc j (S.index (merge_hs #_ #f olds hs) lv) (S.index rhs lv) k actd with | Some v -> S.equal (mt_make_path_step lv hs rhs i j k S.empty actd) (S.cons v S.empty) | None -> S.equal (mt_make_path_step lv hs rhs i j k S.empty actd) S.empty))) let mt_get_path_step_acc_consistent #_ #_ lv i j olds hs rhs k actd = () private val seq_cons_append: #a:Type -> hd:a -> tl:S.seq a -> Lemma (S.equal (S.append (S.cons hd S.empty) tl) (S.cons hd tl)) private let seq_cons_append #a hd tl = () val mt_get_path_acc_consistent: #hsz:pos -> #f:MTS.hash_fun_t -> lv:nat{lv <= 32} -> i:nat -> j:nat{i <= j /\ j < pow2 (32 - lv)} -> olds:hashess #hsz {S.length olds = 32 /\ mt_olds_inv #hsz lv i olds} -> hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} -> rhs:hashes #hsz {S.length rhs = 32} -> k:nat{i <= k && k <= j} -> actd:bool -> Lemma (requires True) (ensures (log2c_bound j (32 - lv); mt_olds_hs_lth_inv_ok #_ #f lv i j olds hs; mt_hashes_lth_inv_log_converted_ #_ #f lv j (merge_hs #_ #f olds hs); S.equal (mt_get_path_acc #_ #f j (S.slice (merge_hs #_ #f olds hs) lv (lv + log2c j)) (S.slice rhs lv (lv + log2c j)) k actd) (mt_get_path_ #_ lv hs rhs i j k S.empty actd))) (decreases j)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.Spec.fst.checked", "MerkleTree.New.High.Correct.Rhs.fst.checked", "MerkleTree.New.High.Correct.Base.fst.checked", "MerkleTree.New.High.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "EverCrypt.Helpers.fsti.checked", "EverCrypt.Hash.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.New.High.Correct.Path.fst" }
[ { "abbrev": false, "full_module": "MerkleTree.New.High", "short_module": null }, { "abbrev": true, "full_module": "MerkleTree.Spec", "short_module": "MTS" }, { "abbrev": true, "full_module": "EverCrypt.Hash", "short_module": "EHS" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "List" }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.Classical", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.New.High.Correct.Rhs", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.New.High.Correct.Base", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt.Helpers", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.New.High.Correct", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.New.High.Correct", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 1000, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
lv: Prims.nat{lv <= 32} -> i: Prims.nat -> j: Prims.nat{i <= j /\ j < Prims.pow2 (32 - lv)} -> olds: MerkleTree.New.High.hashess {FStar.Seq.Base.length olds = 32 /\ MerkleTree.New.High.Correct.Base.mt_olds_inv lv i olds} -> hs: MerkleTree.New.High.hashess {FStar.Seq.Base.length hs = 32 /\ MerkleTree.New.High.hs_wf_elts lv hs i j} -> rhs: MerkleTree.New.High.hashes{FStar.Seq.Base.length rhs = 32} -> k: Prims.nat{i <= k && k <= j} -> actd: Prims.bool -> FStar.Pervasives.Lemma (ensures (MerkleTree.New.High.Correct.Base.log2c_bound j (32 - lv); MerkleTree.New.High.Correct.Base.mt_olds_hs_lth_inv_ok lv i j olds hs; MerkleTree.New.High.Correct.Base.mt_hashes_lth_inv_log_converted_ lv j (MerkleTree.New.High.Correct.Base.merge_hs olds hs); FStar.Seq.Base.equal (MerkleTree.New.High.Correct.Path.mt_get_path_acc j (FStar.Seq.Base.slice (MerkleTree.New.High.Correct.Base.merge_hs olds hs) lv (lv + MerkleTree.New.High.Correct.Base.log2c j)) (FStar.Seq.Base.slice rhs lv (lv + MerkleTree.New.High.Correct.Base.log2c j)) k actd) (MerkleTree.New.High.mt_get_path_ lv hs rhs i j k FStar.Seq.Base.empty actd))) (decreases j)
FStar.Pervasives.Lemma
[ "lemma", "" ]
[]
[ "Prims.pos", "MerkleTree.Spec.hash_fun_t", "Prims.nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.l_and", "Prims.op_LessThan", "Prims.pow2", "Prims.op_Subtraction", "MerkleTree.New.High.hashess", "Prims.op_Equality", "Prims.int", "FStar.Seq.Base.length", "MerkleTree.New.High.hashes", "MerkleTree.New.High.Correct.Base.mt_olds_inv", "MerkleTree.New.High.hs_wf_elts", "MerkleTree.New.High.hash", "Prims.op_AmpAmp", "Prims.bool", "FStar.Pervasives.Native.uu___is_Some", "Prims._assert", "FStar.Seq.Base.equal", "Prims.unit", "MerkleTree.New.High.Correct.Path.seq_cons_append", "FStar.Pervasives.Native.__proj__Some__item__v", "FStar.Seq.Base.cons", "FStar.Seq.Base.append", "FStar.Seq.Base.empty", "FStar.Seq.Base.append_empty_l", "MerkleTree.New.High.Correct.Path.mt_get_path_step_acc_consistent", "MerkleTree.New.High.Correct.Path.mt_get_path_acc_consistent", "Prims.op_Addition", "Prims.op_Division", "FStar.Seq.Base.seq", "MerkleTree.New.High.mt_get_path_pull", "MerkleTree.New.High.path", "MerkleTree.New.High.mt_path_length", "MerkleTree.New.High.mt_get_path_", "MerkleTree.New.High.mt_make_path_step", "MerkleTree.New.High.Correct.Path.mt_get_path_acc", "FStar.Seq.Base.slice", "MerkleTree.New.High.Correct.Base.merge_hs", "MerkleTree.New.High.Correct.Base.log2c", "FStar.Pervasives.Native.option", "MerkleTree.New.High.Correct.Path.mt_get_path_step_acc", "FStar.Seq.Base.index", "MerkleTree.New.High.Correct.Base.mt_hashes_lth_inv_log", "MerkleTree.New.High.Correct.Base.mt_hashes_lth_inv", "MerkleTree.New.High.Correct.Base.log2c_bound", "MerkleTree.New.High.Correct.Base.log2c_div", "Prims.eq2", "Prims.op_BarBar", "Prims.op_Modulus", "Prims.precedes", "MerkleTree.New.High.Correct.Base.mt_hashes_lth_inv_log_converted_", "MerkleTree.New.High.Correct.Base.mt_olds_hs_lth_inv_ok" ]
[ "recursion" ]
false
false
true
false
false
let rec mt_get_path_acc_consistent #hsz #f lv i j olds hs rhs k actd =
log2c_bound j (32 - lv); mt_olds_hs_lth_inv_ok #_ #f lv i j olds hs; mt_hashes_lth_inv_log_converted_ #_ #f lv j (merge_hs #_ #f olds hs); if j = 0 then () else let nactd = if j % 2 = 0 then actd else true in let nactd_ = actd || j % 2 = 1 in assert (nactd == nactd_); let pa = mt_get_path_acc #_ #f j (S.slice (merge_hs #_ #f olds hs) lv (lv + log2c j)) (S.slice rhs lv (lv + log2c j)) k actd in let p = mt_get_path_ lv hs rhs i j k S.empty actd in log2c_div j; log2c_bound (j / 2) (32 - (lv + 1)); assert (mt_hashes_lth_inv (lv + 1) (j / 2) (merge_hs #_ #f olds hs)); assert (mt_hashes_lth_inv_log #hsz (j / 2) (S.slice (merge_hs #_ #f olds hs) (lv + 1) (lv + 1 + log2c (j / 2)))); let npsa = mt_get_path_step_acc j (S.index (merge_hs #_ #f olds hs) lv) (S.index rhs lv) k actd in let npa = mt_get_path_acc #_ #f (j / 2) (S.slice (merge_hs #_ #f olds hs) (lv + 1) (lv + 1 + log2c (j / 2))) (S.slice rhs (lv + 1) (lv + 1 + log2c (j / 2))) (k / 2) nactd_ in let nps = mt_make_path_step lv hs rhs i j k S.empty actd in let np = mt_get_path_ (lv + 1) hs rhs (i / 2) (j / 2) (k / 2) nps nactd in let npe = mt_get_path_ (lv + 1) hs rhs (i / 2) (j / 2) (k / 2) S.empty nactd in mt_get_path_pull (lv + 1) hs rhs (i / 2) (j / 2) (k / 2) nps nactd; assert (S.equal p np); assert (S.equal np (S.append nps npe)); assert (S.equal p (S.append nps npe)); assert (S.equal pa (if Some? npsa then S.cons (Some?.v npsa) npa else npa)); mt_get_path_acc_consistent #_ #f (lv + 1) (i / 2) (j / 2) olds hs rhs (k / 2) nactd; assert (S.equal npa npe); mt_get_path_step_acc_consistent #_ #f lv i j olds hs rhs k actd; if Some? npsa then (assert (S.equal nps (S.cons (Some?.v npsa) S.empty)); assert (S.equal p (S.append (S.cons (Some?.v npsa) S.empty) npa)); assert (S.equal pa (S.cons (Some?.v npsa) npa)); seq_cons_append (Some?.v npsa) npa; assert (S.equal pa p)) else (assert (S.equal nps S.empty); S.append_empty_l npe; assert (S.equal p npe); assert (S.equal pa npa); assert (S.equal pa p))
false
LowParse.Spec.ConstInt32.fst
LowParse.Spec.ConstInt32.parse_constint32le_kind
val parse_constint32le_kind:parser_kind
val parse_constint32le_kind:parser_kind
let parse_constint32le_kind : parser_kind = strong_parser_kind 4 4 None
{ "file_name": "src/lowparse/LowParse.Spec.ConstInt32.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 29, "end_line": 33, "start_col": 0, "start_line": 31 }
module LowParse.Spec.ConstInt32 (* LowParse specification module for parsing 32 bits = 4 bytes unsigned constants Examples: uint32 foo = 5 uint32_le foo = 7 *) (* TODO: support big endian constants *) include FStar.Endianness include LowParse.Spec.Base include LowParse.Spec.Combinators include LowParse.Spec.Int32le module U32 = FStar.UInt32 module U8 = FStar.UInt8 module Seq = FStar.Seq module M = LowParse.Math let constint32 (v: nat { 0 <= v /\ v < 4294967296 } ) : Tot Type = (u: U32.t { U32.v u == v } )
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Int32le.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.Base.fsti.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.ConstInt32.fst" }
[ { "abbrev": true, "full_module": "LowParse.Math", "short_module": "M" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Spec.Int32le", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Endianness", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
LowParse.Spec.Base.parser_kind
Prims.Tot
[ "total" ]
[]
[ "LowParse.Spec.Base.strong_parser_kind", "FStar.Pervasives.Native.None", "LowParse.Spec.Base.parser_kind_metadata_some" ]
[]
false
false
false
true
false
let parse_constint32le_kind:parser_kind =
strong_parser_kind 4 4 None
false
Hacl.Poly1305.Field32xN.Lemmas0.fst
Hacl.Poly1305.Field32xN.Lemmas0.lemma_fmul5_pow78
val lemma_fmul5_pow78: r:tup64_5 -> Lemma (requires (let (r0, r1, r2, r3, r4) = r in v r4 * 5 <= 10 * pow26 /\ v r3 * 5 <= 10 * pow26 /\ v r2 * 5 <= 10 * pow26)) (ensures (let (r0, r1, r2, r3, r4) = r in (pow78 * as_nat5 r) % prime == as_nat5 (r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0, r1) % prime))
val lemma_fmul5_pow78: r:tup64_5 -> Lemma (requires (let (r0, r1, r2, r3, r4) = r in v r4 * 5 <= 10 * pow26 /\ v r3 * 5 <= 10 * pow26 /\ v r2 * 5 <= 10 * pow26)) (ensures (let (r0, r1, r2, r3, r4) = r in (pow78 * as_nat5 r) % prime == as_nat5 (r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0, r1) % prime))
let lemma_fmul5_pow78 r = let (r0, r1, r2, r3, r4) = r in calc (==) { (pow78 * as_nat5 r) % prime; (==) { assert_norm (pow78 == pow26 * pow52) } (pow26 * pow52 * as_nat5 r) % prime; (==) { FStar.Math.Lemmas.paren_mul_right pow26 pow52 (as_nat5 r); FStar.Math.Lemmas.lemma_mod_mul_distr_r pow26 (pow52 * as_nat5 r) prime } (pow26 * (pow52 * as_nat5 r % prime)) % prime; (==) { lemma_fmul5_pow52 r } (pow26 * (as_nat5 (r3 *! u64 5, r4 *! u64 5, r0, r1, r2) % prime)) % prime; (==) { FStar.Math.Lemmas.lemma_mod_mul_distr_r pow26 (as_nat5 (r3 *! u64 5, r4 *! u64 5, r0, r1, r2)) prime } (pow26 * as_nat5 (r3 *! u64 5, r4 *! u64 5, r0, r1, r2)) % prime; (==) { lemma_fmul5_pow26 (r3 *! u64 5, r4 *! u64 5, r0, r1, r2) } as_nat5 (r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0, r1) % prime; }; assert ((pow78 * as_nat5 r) % prime == as_nat5 (r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0, r1) % prime)
{ "file_name": "code/poly1305/Hacl.Poly1305.Field32xN.Lemmas0.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 105, "end_line": 447, "start_col": 0, "start_line": 430 }
module Hacl.Poly1305.Field32xN.Lemmas0 open Lib.IntTypes open Lib.IntVector open Lib.Sequence open FStar.Mul open FStar.Calc open Hacl.Spec.Poly1305.Vec include Hacl.Spec.Poly1305.Field32xN #reset-options "--z3rlimit 50 --using_facts_from '* -FStar.Seq' --max_fuel 0 --max_ifuel 0" val lemma_prime: unit -> Lemma (pow2 130 % prime = 5) let lemma_prime () = assert_norm (pow2 130 % prime = 5 % prime); assert_norm (5 < prime); FStar.Math.Lemmas.modulo_lemma 5 prime val lemma_mult_le: a:nat -> b:nat -> c:nat -> d:nat -> Lemma (requires a <= b /\ c <= d) (ensures a * c <= b * d) let lemma_mult_le a b c d = () val lemma_mul5_distr_l: a:nat -> b:nat -> c:nat -> d:nat -> e:nat -> f:nat -> Lemma (a * (b + c + d + e + f) == a * b + a * c + a * d + a * e + a * f) let lemma_mul5_distr_l a b c d e f = () val lemma_mul5_distr_r: a:nat -> b:nat -> c:nat -> d:nat -> e:nat -> f:nat -> Lemma ((a + b + c + d + e) * f == a * f + b * f + c * f + d * f + e * f) let lemma_mul5_distr_r a b c d e f = () val smul_mod_lemma: #m1:scale32 -> #m2:scale32 -> a:nat{a <= m1 * max26} -> b:nat{b <= m2 * max26} -> Lemma (a * b % pow2 64 == a * b) let smul_mod_lemma #m1 #m2 a b = lemma_mult_le a (m1 * max26) b (m2 * max26); assert (a * b <= m1 * m2 * max26 * max26); FStar.Math.Lemmas.modulo_lemma (a * b) (pow2 64) val smul_add_mod_lemma: #m1:scale32 -> #m2:scale32 -> #m3:scale64{m3 + m1 * m2 <= 4096} -> a:nat{a <= m1 * max26} -> b:nat{b <= m2 * max26} -> c:nat{c <= m3 * max26 * max26} -> Lemma ((c + a * b % pow2 64) % pow2 64 == c + a * b) let smul_add_mod_lemma #m1 #m2 #m3 a b c = assert_norm ((m3 + m1 * m2) * max26 * max26 < pow2 64); lemma_mult_le a (m1 * max26) b (m2 * max26); assert (c + a * b <= m3 * max26 * max26 + m1 * m2 * max26 * max26); FStar.Math.Lemmas.modulo_lemma (c + a * b) (pow2 64) val add5_lemma1: ma:scale64 -> mb:scale64 -> a:uint64 -> b:uint64 -> Lemma (requires v a <= ma * max26 /\ v b <= mb * max26 /\ ma + mb <= 64) (ensures v (a +. b) == v a + v b /\ v (a +. b) <= (ma + mb) * max26) let add5_lemma1 ma mb a b = assert (v a + v b <= (ma + mb) * max26); Math.Lemmas.lemma_mult_le_right max26 (ma + mb) 64; assert (v a + v b <= 64 * max26); assert_norm (64 * max26 < pow2 32); Math.Lemmas.small_mod (v a + v b) (pow2 32) #set-options "--ifuel 1" val fadd5_eval_lemma_i: #w:lanes -> f1:felem5 w{felem_fits5 f1 (2,2,2,2,2)} -> f2:felem5 w{felem_fits5 f2 (1,1,1,1,1)} -> i:nat{i < w} -> Lemma ((feval5 (fadd5 f1 f2)).[i] == pfadd (feval5 f1).[i] (feval5 f2).[i]) let fadd5_eval_lemma_i #w f1 f2 i = let o = fadd5 f1 f2 in let (f10, f11, f12, f13, f14) = as_tup64_i f1 i in let (f20, f21, f22, f23, f24) = as_tup64_i f2 i in let (o0, o1, o2, o3, o4) = as_tup64_i o i in add5_lemma1 2 1 f10 f20; add5_lemma1 2 1 f11 f21; add5_lemma1 2 1 f12 f22; add5_lemma1 2 1 f13 f23; add5_lemma1 2 1 f14 f24; assert (as_nat5 (o0, o1, o2, o3, o4) == as_nat5 (f10, f11, f12, f13, f14) + as_nat5 (f20, f21, f22, f23, f24)); FStar.Math.Lemmas.lemma_mod_plus_distr_l (as_nat5 (f10, f11, f12, f13, f14)) (as_nat5 (f20, f21, f22, f23, f24)) prime; FStar.Math.Lemmas.lemma_mod_plus_distr_r (as_nat5 (f10, f11, f12, f13, f14) % prime) (as_nat5 (f20, f21, f22, f23, f24)) prime val smul_felem5_fits_lemma_i: #w:lanes -> #m1:scale32 -> #m2:scale32 -> u1:uint64xN w{felem_fits1 u1 m1} -> f2:uint64xN w{felem_fits1 f2 m2} -> i:nat{i < w} -> Lemma ((uint64xN_v (vec_mul_mod f2 u1)).[i] <= m1 * m2 * max26 * max26) let smul_felem5_fits_lemma_i #w #m1 #m2 u1 f2 i = let o = vec_mul_mod f2 u1 in smul_mod_lemma #m1 #m2 (uint64xN_v u1).[i] (uint64xN_v f2).[i]; assert ((uint64xN_v o).[i] == (uint64xN_v u1).[i] * (uint64xN_v f2).[i]); lemma_mult_le (uint64xN_v u1).[i] (m1 * max26) (uint64xN_v f2).[i] (m2 * max26) val smul_felem5_eval_lemma_i: #w:lanes -> #m1:scale32 -> #m2:scale32_5 -> u1:uint64xN w{felem_fits1 u1 m1} -> f2:felem5 w{felem_fits5 f2 m2} -> i:nat{i < w} -> Lemma ((fas_nat5 (smul_felem5 #w u1 f2)).[i] == (uint64xN_v u1).[i] * (fas_nat5 f2).[i]) let smul_felem5_eval_lemma_i #w #m1 #m2 u1 f2 i = let o = smul_felem5 #w u1 f2 in let (m20, m21, m22, m23, m24) = m2 in let vu1 = (uint64xN_v u1).[i] in let (tf20, tf21, tf22, tf23, tf24) = as_tup64_i f2 i in let (to0, to1, to2, to3, to4) = as_tup64_i o i in smul_mod_lemma #m1 #m20 vu1 (v tf20); smul_mod_lemma #m1 #m21 vu1 (v tf21); smul_mod_lemma #m1 #m22 vu1 (v tf22); smul_mod_lemma #m1 #m23 vu1 (v tf23); smul_mod_lemma #m1 #m24 vu1 (v tf24); assert ((fas_nat5 o).[i] == vu1 * v tf20 + vu1 * v tf21 * pow26 + vu1 * v tf22 * pow52 + vu1 * v tf23 * pow78 + vu1 * v tf24 * pow104); calc (==) { vu1 * (fas_nat5 f2).[i]; (==) { } vu1 * (v tf20 + v tf21 * pow26 + v tf22 * pow52 + v tf23 * pow78 + v tf24 * pow104); (==) { lemma_mul5_distr_l vu1 (v tf20) (v tf21 * pow26) (v tf22 * pow52) (v tf23 * pow78) (v tf24 * pow104)} vu1 * v tf20 + vu1 * (v tf21 * pow26) + vu1 * (v tf22 * pow52) + vu1 * (v tf23 * pow78) + vu1 * (v tf24 * pow104); (==) { FStar.Math.Lemmas.paren_mul_right vu1 (v tf21) pow26; FStar.Math.Lemmas.paren_mul_right vu1 (v tf22) pow52; FStar.Math.Lemmas.paren_mul_right vu1 (v tf23) pow78; FStar.Math.Lemmas.paren_mul_right vu1 (v tf24) pow104} vu1 * v tf20 + vu1 * v tf21 * pow26 + vu1 * v tf22 * pow52 + vu1 * v tf23 * pow78 + vu1 * v tf24 * pow104; }; assert (vu1 * (fas_nat5 f2).[i] == (fas_nat5 o).[i]) val smul_felem5_fits_lemma1: #w:lanes -> #m1:scale32 -> #m2:scale32 -> u1:uint64xN w{felem_fits1 u1 m1} -> f2:uint64xN w{felem_fits1 f2 m2} -> Lemma (felem_wide_fits1 (vec_mul_mod f2 u1) (m1 * m2)) let smul_felem5_fits_lemma1 #w #m1 #m2 u1 f2 = match w with | 1 -> smul_felem5_fits_lemma_i #w #m1 #m2 u1 f2 0 | 2 -> smul_felem5_fits_lemma_i #w #m1 #m2 u1 f2 0; smul_felem5_fits_lemma_i #w #m1 #m2 u1 f2 1 | 4 -> smul_felem5_fits_lemma_i #w #m1 #m2 u1 f2 0; smul_felem5_fits_lemma_i #w #m1 #m2 u1 f2 1; smul_felem5_fits_lemma_i #w #m1 #m2 u1 f2 2; smul_felem5_fits_lemma_i #w #m1 #m2 u1 f2 3 val smul_felem5_fits_lemma: #w:lanes -> #m1:scale32 -> #m2:scale32_5 -> u1:uint64xN w{felem_fits1 u1 m1} -> f2:felem5 w{felem_fits5 f2 m2} -> Lemma (felem_wide_fits5 (smul_felem5 #w u1 f2) (m1 *^ m2)) let smul_felem5_fits_lemma #w #m1 #m2 u1 f2 = let (f20, f21, f22, f23, f24) = f2 in let (m20, m21, m22, m23, m24) = m2 in smul_felem5_fits_lemma1 #w #m1 #m20 u1 f20; smul_felem5_fits_lemma1 #w #m1 #m21 u1 f21; smul_felem5_fits_lemma1 #w #m1 #m22 u1 f22; smul_felem5_fits_lemma1 #w #m1 #m23 u1 f23; smul_felem5_fits_lemma1 #w #m1 #m24 u1 f24 val smul_felem5_eval_lemma: #w:lanes -> #m1:scale32 -> #m2:scale32_5 -> u1:uint64xN w{felem_fits1 u1 m1} -> f2:felem5 w{felem_fits5 f2 m2} -> Lemma (fas_nat5 (smul_felem5 #w u1 f2) == map2 #nat #nat #nat (fun a b -> a * b) (uint64xN_v u1) (fas_nat5 f2)) let smul_felem5_eval_lemma #w #m1 #m2 u1 f2 = FStar.Classical.forall_intro (smul_felem5_eval_lemma_i #w #m1 #m2 u1 f2); eq_intro (fas_nat5 (smul_felem5 #w u1 f2)) (map2 #nat #nat #nat (fun a b -> a * b) (uint64xN_v u1) (fas_nat5 f2)) val smul_add_felem5_fits_lemma_i: #w:lanes -> #m1:scale32 -> #m2:scale32 -> #m3:scale64{m3 + m1 * m2 <= 4096} -> u1:uint64xN w{felem_fits1 u1 m1} -> f2:uint64xN w{felem_fits1 f2 m2} -> acc1:uint64xN w{felem_wide_fits1 acc1 m3} -> i:nat{i < w} -> Lemma ((uint64xN_v (vec_add_mod acc1 (vec_mul_mod f2 u1))).[i] <= (m3 + m1 * m2) * max26 * max26) #push-options "--z3rlimit 200" let smul_add_felem5_fits_lemma_i #w #m1 #m2 #m3 u1 f2 acc1 i = let o = vec_add_mod acc1 (vec_mul_mod f2 u1) in smul_add_mod_lemma #m1 #m2 #m3 (uint64xN_v u1).[i] (uint64xN_v f2).[i] (uint64xN_v acc1).[i]; assert ((uint64xN_v o).[i] == (uint64xN_v acc1).[i] + (uint64xN_v u1).[i] * (uint64xN_v f2).[i]); lemma_mult_le (uint64xN_v u1).[i] (m1 * max26) (uint64xN_v f2).[i] (m2 * max26); assert ((uint64xN_v o).[i] <= m3 * max26 * max26 + m1 * m2 * max26 * max26) #pop-options val smul_add_felem5_eval_lemma_i: #w:lanes -> #m1:scale32 -> #m2:scale32_5 -> #m3:scale64_5{m3 +* m1 *^ m2 <=* s64x5 4096} -> u1:uint64xN w{felem_fits1 u1 m1} -> f2:felem5 w{felem_fits5 f2 m2} -> acc1:felem_wide5 w{felem_wide_fits5 acc1 m3} -> i:nat{i < w} -> Lemma ((fas_nat5 (smul_add_felem5 #w u1 f2 acc1)).[i] == (fas_nat5 acc1).[i] + (uint64xN_v u1).[i] * (fas_nat5 f2).[i]) let smul_add_felem5_eval_lemma_i #w #m1 #m2 #m3 u1 f2 acc1 i = let o = smul_add_felem5 #w u1 f2 acc1 in let (m20, m21, m22, m23, m24) = m2 in let (m30, m31, m32, m33, m34) = m3 in let vu1 = (uint64xN_v u1).[i] in let (tf20, tf21, tf22, tf23, tf24) = as_tup64_i f2 i in let (ta0, ta1, ta2, ta3, ta4) = as_tup64_i acc1 i in let (to0, to1, to2, to3, to4) = as_tup64_i o i in smul_add_mod_lemma #m1 #m20 #m30 vu1 (v tf20) (v ta0); smul_add_mod_lemma #m1 #m21 #m31 vu1 (v tf21) (v ta1); smul_add_mod_lemma #m1 #m22 #m32 vu1 (v tf22) (v ta2); smul_add_mod_lemma #m1 #m23 #m33 vu1 (v tf23) (v ta3); smul_add_mod_lemma #m1 #m24 #m34 vu1 (v tf24) (v ta4); calc (==) { (fas_nat5 o).[i]; (==) { } v ta0 + vu1 * v tf20 + (v ta1 + vu1 * v tf21) * pow26 + (v ta2 + vu1 * v tf22) * pow52 + (v ta3 + vu1 * v tf23) * pow78 + (v ta4 + vu1 * v tf24) * pow104; (==) { FStar.Math.Lemmas.distributivity_add_left (v ta1) (vu1 * v tf21) pow26; FStar.Math.Lemmas.distributivity_add_left (v ta2) (vu1 * v tf22) pow52; FStar.Math.Lemmas.distributivity_add_left (v ta3) (vu1 * v tf23) pow78; FStar.Math.Lemmas.distributivity_add_left (v ta1) (vu1 * v tf24) pow104 } v ta0 + v ta1 * pow26 + v ta2 * pow52 + v ta3 * pow78 + v ta4 * pow104 + vu1 * v tf20 + vu1 * v tf21 * pow26 + vu1 * v tf22 * pow52 + vu1 * v tf23 * pow78 + vu1 * v tf24 * pow104; (==) { } (fas_nat5 acc1).[i] + vu1 * v tf20 + vu1 * v tf21 * pow26 + vu1 * v tf22 * pow52 + vu1 * v tf23 * pow78 + vu1 * v tf24 * pow104; }; assert ((fas_nat5 o).[i] == (fas_nat5 acc1).[i] + vu1 * v tf20 + vu1 * v tf21 * pow26 + vu1 * v tf22 * pow52 + vu1 * v tf23 * pow78 + vu1 * v tf24 * pow104); calc (==) { vu1 * (fas_nat5 f2).[i]; (==) { } vu1 * (v tf20 + v tf21 * pow26 + v tf22 * pow52 + v tf23 * pow78 + v tf24 * pow104); (==) { lemma_mul5_distr_l vu1 (v tf20) (v tf21 * pow26) (v tf22 * pow52) (v tf23 * pow78) (v tf24 * pow104)} vu1 * v tf20 + vu1 * (v tf21 * pow26) + vu1 * (v tf22 * pow52) + vu1 * (v tf23 * pow78) + vu1 * (v tf24 * pow104); (==) { FStar.Math.Lemmas.paren_mul_right vu1 (v tf21) pow26; FStar.Math.Lemmas.paren_mul_right vu1 (v tf22) pow52; FStar.Math.Lemmas.paren_mul_right vu1 (v tf23) pow78; FStar.Math.Lemmas.paren_mul_right vu1 (v tf24) pow104} vu1 * v tf20 + vu1 * v tf21 * pow26 + vu1 * v tf22 * pow52 + vu1 * v tf23 * pow78 + vu1 * v tf24 * pow104; }; assert ((fas_nat5 o).[i] == (fas_nat5 acc1).[i] + vu1 * (fas_nat5 f2).[i]) val smul_add_felem5_fits_lemma1: #w:lanes -> #m1:scale32 -> #m2:scale32 -> #m3:scale64{m3 + m1 * m2 <= 4096} -> u1:uint64xN w{felem_fits1 u1 m1} -> f2:uint64xN w{felem_fits1 f2 m2} -> acc1:uint64xN w{felem_wide_fits1 acc1 m3} -> Lemma (felem_wide_fits1 (vec_add_mod acc1 (vec_mul_mod f2 u1)) (m3 + m1 * m2)) let smul_add_felem5_fits_lemma1 #w #m1 #m2 #m3 u1 f2 acc1 = match w with | 1 -> smul_add_felem5_fits_lemma_i #w #m1 #m2 #m3 u1 f2 acc1 0 | 2 -> smul_add_felem5_fits_lemma_i #w #m1 #m2 #m3 u1 f2 acc1 0; smul_add_felem5_fits_lemma_i #w #m1 #m2 #m3 u1 f2 acc1 1 | 4 -> smul_add_felem5_fits_lemma_i #w #m1 #m2 #m3 u1 f2 acc1 0; smul_add_felem5_fits_lemma_i #w #m1 #m2 #m3 u1 f2 acc1 1; smul_add_felem5_fits_lemma_i #w #m1 #m2 #m3 u1 f2 acc1 2; smul_add_felem5_fits_lemma_i #w #m1 #m2 #m3 u1 f2 acc1 3 val smul_add_felem5_fits_lemma: #w:lanes -> #m1:scale32 -> #m2:scale32_5 -> #m3:scale64_5{m3 +* m1 *^ m2 <=* s64x5 4096} -> u1:uint64xN w{felem_fits1 u1 m1} -> f2:felem5 w{felem_fits5 f2 m2} -> acc1:felem_wide5 w{felem_wide_fits5 acc1 m3} -> Lemma (felem_wide_fits5 (smul_add_felem5 #w u1 f2 acc1) (m3 +* m1 *^ m2)) let smul_add_felem5_fits_lemma #w #m1 #m2 #m3 u1 f2 acc1 = let (f20, f21, f22, f23, f24) = f2 in let (m20, m21, m22, m23, m24) = m2 in let (a0, a1, a2, a3, a4) = acc1 in let (m30, m31, m32, m33, m34) = m3 in smul_add_felem5_fits_lemma1 #w #m1 #m20 #m30 u1 f20 a0; smul_add_felem5_fits_lemma1 #w #m1 #m21 #m31 u1 f21 a1; smul_add_felem5_fits_lemma1 #w #m1 #m22 #m32 u1 f22 a2; smul_add_felem5_fits_lemma1 #w #m1 #m23 #m33 u1 f23 a3; smul_add_felem5_fits_lemma1 #w #m1 #m24 #m34 u1 f24 a4 val smul_add_felem5_eval_lemma: #w:lanes -> #m1:scale32 -> #m2:scale32_5 -> #m3:scale64_5{m3 +* m1 *^ m2 <=* s64x5 4096} -> u1:uint64xN w{felem_fits1 u1 m1} -> f2:felem5 w{felem_fits5 f2 m2} -> acc1:felem_wide5 w{felem_wide_fits5 acc1 m3} -> Lemma (fas_nat5 (smul_add_felem5 #w u1 f2 acc1) == map2 #nat #nat #nat (fun a b -> a + b) (fas_nat5 acc1) (map2 #nat #nat #nat (fun a b -> a * b) (uint64xN_v u1) (fas_nat5 f2))) let smul_add_felem5_eval_lemma #w #m1 #m2 #m3 u1 f2 acc1 = let tmp = map2 #nat #nat #nat (fun a b -> a + b) (fas_nat5 acc1) (map2 #nat #nat #nat (fun a b -> a * b) (uint64xN_v u1) (fas_nat5 f2)) in FStar.Classical.forall_intro (smul_add_felem5_eval_lemma_i #w #m1 #m2 #m3 u1 f2 acc1); eq_intro (fas_nat5 (smul_add_felem5 #w u1 f2 acc1)) tmp val lemma_fmul5_pow26: r:tup64_5 -> Lemma (requires (let (r0, r1, r2, r3, r4) = r in v r4 * 5 <= 10 * pow26)) (ensures (let (r0, r1, r2, r3, r4) = r in (pow26 * as_nat5 r) % prime == as_nat5 (r4 *! u64 5, r0, r1, r2, r3) % prime)) let lemma_fmul5_pow26 r = let (r0, r1, r2, r3, r4) = r in calc (==) { (pow26 * as_nat5 r) % prime; (==) { } (pow26 * (v r0 + v r1 * pow26 + v r2 * pow52 + v r3 * pow78 + v r4 * pow104)) % prime; (==) { lemma_mul5_distr_l pow26 (v r0) (v r1 * pow26) (v r2 * pow52) (v r3 * pow78) (v r4 * pow104) } (v r0 * pow26 + pow26 * v r1 * pow26 + pow26 * v r2 * pow52 + pow26 * v r3 * pow78 + pow26 * v r4 * pow104) % prime; (==) { } (v r0 * pow26 + v r1 * pow26 * pow26 + v r2 * pow26 * pow52 + v r3 * pow26 * pow78 + v r4 * pow26 * pow104) % prime; (==) { assert_norm (pow26 * pow26 = pow52); assert_norm (pow26 * pow52 = pow78); assert_norm (pow26 * pow78 = pow104); assert_norm (pow26 * pow104 = pow2 130) } (v r0 * pow26 + v r1 * pow52 + v r2 * pow78 + v r3 * pow104 + v r4 * pow2 130) % prime; (==) { FStar.Math.Lemmas.lemma_mod_plus_distr_r (v r0 * pow26 + v r1 * pow52 + v r2 * pow78 + v r3 * pow104) (v r4 * pow2 130) prime } (v r0 * pow26 + v r1 * pow52 + v r2 * pow78 + v r3 * pow104 + (v r4 * pow2 130) % prime) % prime; (==) { FStar.Math.Lemmas.lemma_mod_mul_distr_r (v r4) (pow2 130) prime } (v r0 * pow26 + v r1 * pow52 + v r2 * pow78 + v r3 * pow104 + (v r4 * (pow2 130 % prime)) % prime) % prime; (==) { lemma_prime () } (v r0 * pow26 + v r1 * pow52 + v r2 * pow78 + v r3 * pow104 + (v r4 * 5) % prime) % prime; (==) { FStar.Math.Lemmas.lemma_mod_plus_distr_r (v r0 * pow26 + v r1 * pow52 + v r2 * pow78 + v r3 * pow104) (v r4 * 5) prime } (v r0 * pow26 + v r1 * pow52 + v r2 * pow78 + v r3 * pow104 + v r4 * 5) % prime; }; assert ((pow26 * as_nat5 r) % prime == (v r0 * pow26 + v r1 * pow52 + v r2 * pow78 + v r3 * pow104 + v r4 * 5) % prime) val lemma_fmul5_pow52: r:tup64_5 -> Lemma (requires (let (r0, r1, r2, r3, r4) = r in v r4 * 5 <= 10 * pow26 /\ v r3 * 5 <= 10 * pow26)) (ensures (let (r0, r1, r2, r3, r4) = r in (pow52 * as_nat5 r) % prime == as_nat5 (r3 *! u64 5, r4 *! u64 5, r0, r1, r2) % prime)) let lemma_fmul5_pow52 r = let (r0, r1, r2, r3, r4) = r in calc (==) { (pow52 * as_nat5 r) % prime; (==) { assert_norm (pow52 == pow26 * pow26) } (pow26 * pow26 * as_nat5 r) % prime; (==) { FStar.Math.Lemmas.paren_mul_right pow26 pow26 (as_nat5 r); FStar.Math.Lemmas.lemma_mod_mul_distr_r pow26 (pow26 * as_nat5 r) prime } (pow26 * (pow26 * as_nat5 r % prime)) % prime; (==) { lemma_fmul5_pow26 r } (pow26 * (as_nat5 (r4 *! u64 5, r0, r1, r2, r3) % prime)) % prime; (==) { FStar.Math.Lemmas.lemma_mod_mul_distr_r pow26 (as_nat5 (r4 *! u64 5, r0, r1, r2, r3)) prime } (pow26 * as_nat5 (r4 *! u64 5, r0, r1, r2, r3)) % prime; (==) { lemma_fmul5_pow26 (r4 *! u64 5, r0, r1, r2, r3) } as_nat5 (r3 *! u64 5, r4 *! u64 5, r0, r1, r2) % prime; }; assert ((pow52 * as_nat5 r) % prime == as_nat5 (r3 *! u64 5, r4 *! u64 5, r0, r1, r2) % prime) val lemma_fmul5_pow78: r:tup64_5 -> Lemma (requires (let (r0, r1, r2, r3, r4) = r in v r4 * 5 <= 10 * pow26 /\ v r3 * 5 <= 10 * pow26 /\ v r2 * 5 <= 10 * pow26)) (ensures (let (r0, r1, r2, r3, r4) = r in (pow78 * as_nat5 r) % prime == as_nat5 (r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0, r1) % prime))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntVector.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Poly1305.Vec.fst.checked", "Hacl.Spec.Poly1305.Field32xN.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Poly1305.Field32xN.Lemmas0.fst" }
[ { "abbrev": false, "full_module": "Hacl.Spec.Poly1305.Field32xN", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Poly1305.Vec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntVector", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Poly1305.Field32xN", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Poly1305.Field32xN", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
r: Hacl.Spec.Poly1305.Field32xN.tup64_5 -> FStar.Pervasives.Lemma (requires (let _ = r in (let FStar.Pervasives.Native.Mktuple5 #_ #_ #_ #_ #_ _ _ r2 r3 r4 = _ in Lib.IntTypes.v r4 * 5 <= 10 * Hacl.Spec.Poly1305.Field32xN.pow26 /\ Lib.IntTypes.v r3 * 5 <= 10 * Hacl.Spec.Poly1305.Field32xN.pow26 /\ Lib.IntTypes.v r2 * 5 <= 10 * Hacl.Spec.Poly1305.Field32xN.pow26) <: Type0)) (ensures (let _ = r in (let FStar.Pervasives.Native.Mktuple5 #_ #_ #_ #_ #_ r0 r1 r2 r3 r4 = _ in Hacl.Spec.Poly1305.Field32xN.pow78 * Hacl.Spec.Poly1305.Field32xN.as_nat5 r % Hacl.Spec.Poly1305.Vec.prime == Hacl.Spec.Poly1305.Field32xN.as_nat5 (r2 *! Lib.IntTypes.u64 5, r3 *! Lib.IntTypes.u64 5, r4 *! Lib.IntTypes.u64 5, r0, r1) % Hacl.Spec.Poly1305.Vec.prime) <: Type0))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Hacl.Spec.Poly1305.Field32xN.tup64_5", "Lib.IntTypes.uint64", "Prims._assert", "Prims.eq2", "Prims.int", "Prims.op_Modulus", "FStar.Mul.op_Star", "Hacl.Spec.Poly1305.Field32xN.pow78", "Hacl.Spec.Poly1305.Field32xN.as_nat5", "Hacl.Spec.Poly1305.Vec.prime", "FStar.Pervasives.Native.Mktuple5", "Lib.IntTypes.op_Star_Bang", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "Lib.IntTypes.u64", "Prims.unit", "FStar.Calc.calc_finish", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "FStar.Calc.calc_step", "Hacl.Spec.Poly1305.Field32xN.pow26", "Hacl.Spec.Poly1305.Field32xN.pow52", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "FStar.Pervasives.assert_norm", "Prims.squash", "FStar.Math.Lemmas.lemma_mod_mul_distr_r", "FStar.Math.Lemmas.paren_mul_right", "Hacl.Poly1305.Field32xN.Lemmas0.lemma_fmul5_pow52", "Hacl.Poly1305.Field32xN.Lemmas0.lemma_fmul5_pow26" ]
[]
false
false
true
false
false
let lemma_fmul5_pow78 r =
let r0, r1, r2, r3, r4 = r in calc ( == ) { (pow78 * as_nat5 r) % prime; ( == ) { assert_norm (pow78 == pow26 * pow52) } ((pow26 * pow52) * as_nat5 r) % prime; ( == ) { (FStar.Math.Lemmas.paren_mul_right pow26 pow52 (as_nat5 r); FStar.Math.Lemmas.lemma_mod_mul_distr_r pow26 (pow52 * as_nat5 r) prime) } (pow26 * (pow52 * as_nat5 r % prime)) % prime; ( == ) { lemma_fmul5_pow52 r } (pow26 * (as_nat5 (r3 *! u64 5, r4 *! u64 5, r0, r1, r2) % prime)) % prime; ( == ) { FStar.Math.Lemmas.lemma_mod_mul_distr_r pow26 (as_nat5 (r3 *! u64 5, r4 *! u64 5, r0, r1, r2)) prime } (pow26 * as_nat5 (r3 *! u64 5, r4 *! u64 5, r0, r1, r2)) % prime; ( == ) { lemma_fmul5_pow26 (r3 *! u64 5, r4 *! u64 5, r0, r1, r2) } as_nat5 (r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0, r1) % prime; }; assert ((pow78 * as_nat5 r) % prime == as_nat5 (r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0, r1) % prime)
false
Hacl.Poly1305.Field32xN.Lemmas0.fst
Hacl.Poly1305.Field32xN.Lemmas0.lemma_fmul5_pow52
val lemma_fmul5_pow52: r:tup64_5 -> Lemma (requires (let (r0, r1, r2, r3, r4) = r in v r4 * 5 <= 10 * pow26 /\ v r3 * 5 <= 10 * pow26)) (ensures (let (r0, r1, r2, r3, r4) = r in (pow52 * as_nat5 r) % prime == as_nat5 (r3 *! u64 5, r4 *! u64 5, r0, r1, r2) % prime))
val lemma_fmul5_pow52: r:tup64_5 -> Lemma (requires (let (r0, r1, r2, r3, r4) = r in v r4 * 5 <= 10 * pow26 /\ v r3 * 5 <= 10 * pow26)) (ensures (let (r0, r1, r2, r3, r4) = r in (pow52 * as_nat5 r) % prime == as_nat5 (r3 *! u64 5, r4 *! u64 5, r0, r1, r2) % prime))
let lemma_fmul5_pow52 r = let (r0, r1, r2, r3, r4) = r in calc (==) { (pow52 * as_nat5 r) % prime; (==) { assert_norm (pow52 == pow26 * pow26) } (pow26 * pow26 * as_nat5 r) % prime; (==) { FStar.Math.Lemmas.paren_mul_right pow26 pow26 (as_nat5 r); FStar.Math.Lemmas.lemma_mod_mul_distr_r pow26 (pow26 * as_nat5 r) prime } (pow26 * (pow26 * as_nat5 r % prime)) % prime; (==) { lemma_fmul5_pow26 r } (pow26 * (as_nat5 (r4 *! u64 5, r0, r1, r2, r3) % prime)) % prime; (==) { FStar.Math.Lemmas.lemma_mod_mul_distr_r pow26 (as_nat5 (r4 *! u64 5, r0, r1, r2, r3)) prime } (pow26 * as_nat5 (r4 *! u64 5, r0, r1, r2, r3)) % prime; (==) { lemma_fmul5_pow26 (r4 *! u64 5, r0, r1, r2, r3) } as_nat5 (r3 *! u64 5, r4 *! u64 5, r0, r1, r2) % prime; }; assert ((pow52 * as_nat5 r) % prime == as_nat5 (r3 *! u64 5, r4 *! u64 5, r0, r1, r2) % prime)
{ "file_name": "code/poly1305/Hacl.Poly1305.Field32xN.Lemmas0.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 96, "end_line": 421, "start_col": 0, "start_line": 404 }
module Hacl.Poly1305.Field32xN.Lemmas0 open Lib.IntTypes open Lib.IntVector open Lib.Sequence open FStar.Mul open FStar.Calc open Hacl.Spec.Poly1305.Vec include Hacl.Spec.Poly1305.Field32xN #reset-options "--z3rlimit 50 --using_facts_from '* -FStar.Seq' --max_fuel 0 --max_ifuel 0" val lemma_prime: unit -> Lemma (pow2 130 % prime = 5) let lemma_prime () = assert_norm (pow2 130 % prime = 5 % prime); assert_norm (5 < prime); FStar.Math.Lemmas.modulo_lemma 5 prime val lemma_mult_le: a:nat -> b:nat -> c:nat -> d:nat -> Lemma (requires a <= b /\ c <= d) (ensures a * c <= b * d) let lemma_mult_le a b c d = () val lemma_mul5_distr_l: a:nat -> b:nat -> c:nat -> d:nat -> e:nat -> f:nat -> Lemma (a * (b + c + d + e + f) == a * b + a * c + a * d + a * e + a * f) let lemma_mul5_distr_l a b c d e f = () val lemma_mul5_distr_r: a:nat -> b:nat -> c:nat -> d:nat -> e:nat -> f:nat -> Lemma ((a + b + c + d + e) * f == a * f + b * f + c * f + d * f + e * f) let lemma_mul5_distr_r a b c d e f = () val smul_mod_lemma: #m1:scale32 -> #m2:scale32 -> a:nat{a <= m1 * max26} -> b:nat{b <= m2 * max26} -> Lemma (a * b % pow2 64 == a * b) let smul_mod_lemma #m1 #m2 a b = lemma_mult_le a (m1 * max26) b (m2 * max26); assert (a * b <= m1 * m2 * max26 * max26); FStar.Math.Lemmas.modulo_lemma (a * b) (pow2 64) val smul_add_mod_lemma: #m1:scale32 -> #m2:scale32 -> #m3:scale64{m3 + m1 * m2 <= 4096} -> a:nat{a <= m1 * max26} -> b:nat{b <= m2 * max26} -> c:nat{c <= m3 * max26 * max26} -> Lemma ((c + a * b % pow2 64) % pow2 64 == c + a * b) let smul_add_mod_lemma #m1 #m2 #m3 a b c = assert_norm ((m3 + m1 * m2) * max26 * max26 < pow2 64); lemma_mult_le a (m1 * max26) b (m2 * max26); assert (c + a * b <= m3 * max26 * max26 + m1 * m2 * max26 * max26); FStar.Math.Lemmas.modulo_lemma (c + a * b) (pow2 64) val add5_lemma1: ma:scale64 -> mb:scale64 -> a:uint64 -> b:uint64 -> Lemma (requires v a <= ma * max26 /\ v b <= mb * max26 /\ ma + mb <= 64) (ensures v (a +. b) == v a + v b /\ v (a +. b) <= (ma + mb) * max26) let add5_lemma1 ma mb a b = assert (v a + v b <= (ma + mb) * max26); Math.Lemmas.lemma_mult_le_right max26 (ma + mb) 64; assert (v a + v b <= 64 * max26); assert_norm (64 * max26 < pow2 32); Math.Lemmas.small_mod (v a + v b) (pow2 32) #set-options "--ifuel 1" val fadd5_eval_lemma_i: #w:lanes -> f1:felem5 w{felem_fits5 f1 (2,2,2,2,2)} -> f2:felem5 w{felem_fits5 f2 (1,1,1,1,1)} -> i:nat{i < w} -> Lemma ((feval5 (fadd5 f1 f2)).[i] == pfadd (feval5 f1).[i] (feval5 f2).[i]) let fadd5_eval_lemma_i #w f1 f2 i = let o = fadd5 f1 f2 in let (f10, f11, f12, f13, f14) = as_tup64_i f1 i in let (f20, f21, f22, f23, f24) = as_tup64_i f2 i in let (o0, o1, o2, o3, o4) = as_tup64_i o i in add5_lemma1 2 1 f10 f20; add5_lemma1 2 1 f11 f21; add5_lemma1 2 1 f12 f22; add5_lemma1 2 1 f13 f23; add5_lemma1 2 1 f14 f24; assert (as_nat5 (o0, o1, o2, o3, o4) == as_nat5 (f10, f11, f12, f13, f14) + as_nat5 (f20, f21, f22, f23, f24)); FStar.Math.Lemmas.lemma_mod_plus_distr_l (as_nat5 (f10, f11, f12, f13, f14)) (as_nat5 (f20, f21, f22, f23, f24)) prime; FStar.Math.Lemmas.lemma_mod_plus_distr_r (as_nat5 (f10, f11, f12, f13, f14) % prime) (as_nat5 (f20, f21, f22, f23, f24)) prime val smul_felem5_fits_lemma_i: #w:lanes -> #m1:scale32 -> #m2:scale32 -> u1:uint64xN w{felem_fits1 u1 m1} -> f2:uint64xN w{felem_fits1 f2 m2} -> i:nat{i < w} -> Lemma ((uint64xN_v (vec_mul_mod f2 u1)).[i] <= m1 * m2 * max26 * max26) let smul_felem5_fits_lemma_i #w #m1 #m2 u1 f2 i = let o = vec_mul_mod f2 u1 in smul_mod_lemma #m1 #m2 (uint64xN_v u1).[i] (uint64xN_v f2).[i]; assert ((uint64xN_v o).[i] == (uint64xN_v u1).[i] * (uint64xN_v f2).[i]); lemma_mult_le (uint64xN_v u1).[i] (m1 * max26) (uint64xN_v f2).[i] (m2 * max26) val smul_felem5_eval_lemma_i: #w:lanes -> #m1:scale32 -> #m2:scale32_5 -> u1:uint64xN w{felem_fits1 u1 m1} -> f2:felem5 w{felem_fits5 f2 m2} -> i:nat{i < w} -> Lemma ((fas_nat5 (smul_felem5 #w u1 f2)).[i] == (uint64xN_v u1).[i] * (fas_nat5 f2).[i]) let smul_felem5_eval_lemma_i #w #m1 #m2 u1 f2 i = let o = smul_felem5 #w u1 f2 in let (m20, m21, m22, m23, m24) = m2 in let vu1 = (uint64xN_v u1).[i] in let (tf20, tf21, tf22, tf23, tf24) = as_tup64_i f2 i in let (to0, to1, to2, to3, to4) = as_tup64_i o i in smul_mod_lemma #m1 #m20 vu1 (v tf20); smul_mod_lemma #m1 #m21 vu1 (v tf21); smul_mod_lemma #m1 #m22 vu1 (v tf22); smul_mod_lemma #m1 #m23 vu1 (v tf23); smul_mod_lemma #m1 #m24 vu1 (v tf24); assert ((fas_nat5 o).[i] == vu1 * v tf20 + vu1 * v tf21 * pow26 + vu1 * v tf22 * pow52 + vu1 * v tf23 * pow78 + vu1 * v tf24 * pow104); calc (==) { vu1 * (fas_nat5 f2).[i]; (==) { } vu1 * (v tf20 + v tf21 * pow26 + v tf22 * pow52 + v tf23 * pow78 + v tf24 * pow104); (==) { lemma_mul5_distr_l vu1 (v tf20) (v tf21 * pow26) (v tf22 * pow52) (v tf23 * pow78) (v tf24 * pow104)} vu1 * v tf20 + vu1 * (v tf21 * pow26) + vu1 * (v tf22 * pow52) + vu1 * (v tf23 * pow78) + vu1 * (v tf24 * pow104); (==) { FStar.Math.Lemmas.paren_mul_right vu1 (v tf21) pow26; FStar.Math.Lemmas.paren_mul_right vu1 (v tf22) pow52; FStar.Math.Lemmas.paren_mul_right vu1 (v tf23) pow78; FStar.Math.Lemmas.paren_mul_right vu1 (v tf24) pow104} vu1 * v tf20 + vu1 * v tf21 * pow26 + vu1 * v tf22 * pow52 + vu1 * v tf23 * pow78 + vu1 * v tf24 * pow104; }; assert (vu1 * (fas_nat5 f2).[i] == (fas_nat5 o).[i]) val smul_felem5_fits_lemma1: #w:lanes -> #m1:scale32 -> #m2:scale32 -> u1:uint64xN w{felem_fits1 u1 m1} -> f2:uint64xN w{felem_fits1 f2 m2} -> Lemma (felem_wide_fits1 (vec_mul_mod f2 u1) (m1 * m2)) let smul_felem5_fits_lemma1 #w #m1 #m2 u1 f2 = match w with | 1 -> smul_felem5_fits_lemma_i #w #m1 #m2 u1 f2 0 | 2 -> smul_felem5_fits_lemma_i #w #m1 #m2 u1 f2 0; smul_felem5_fits_lemma_i #w #m1 #m2 u1 f2 1 | 4 -> smul_felem5_fits_lemma_i #w #m1 #m2 u1 f2 0; smul_felem5_fits_lemma_i #w #m1 #m2 u1 f2 1; smul_felem5_fits_lemma_i #w #m1 #m2 u1 f2 2; smul_felem5_fits_lemma_i #w #m1 #m2 u1 f2 3 val smul_felem5_fits_lemma: #w:lanes -> #m1:scale32 -> #m2:scale32_5 -> u1:uint64xN w{felem_fits1 u1 m1} -> f2:felem5 w{felem_fits5 f2 m2} -> Lemma (felem_wide_fits5 (smul_felem5 #w u1 f2) (m1 *^ m2)) let smul_felem5_fits_lemma #w #m1 #m2 u1 f2 = let (f20, f21, f22, f23, f24) = f2 in let (m20, m21, m22, m23, m24) = m2 in smul_felem5_fits_lemma1 #w #m1 #m20 u1 f20; smul_felem5_fits_lemma1 #w #m1 #m21 u1 f21; smul_felem5_fits_lemma1 #w #m1 #m22 u1 f22; smul_felem5_fits_lemma1 #w #m1 #m23 u1 f23; smul_felem5_fits_lemma1 #w #m1 #m24 u1 f24 val smul_felem5_eval_lemma: #w:lanes -> #m1:scale32 -> #m2:scale32_5 -> u1:uint64xN w{felem_fits1 u1 m1} -> f2:felem5 w{felem_fits5 f2 m2} -> Lemma (fas_nat5 (smul_felem5 #w u1 f2) == map2 #nat #nat #nat (fun a b -> a * b) (uint64xN_v u1) (fas_nat5 f2)) let smul_felem5_eval_lemma #w #m1 #m2 u1 f2 = FStar.Classical.forall_intro (smul_felem5_eval_lemma_i #w #m1 #m2 u1 f2); eq_intro (fas_nat5 (smul_felem5 #w u1 f2)) (map2 #nat #nat #nat (fun a b -> a * b) (uint64xN_v u1) (fas_nat5 f2)) val smul_add_felem5_fits_lemma_i: #w:lanes -> #m1:scale32 -> #m2:scale32 -> #m3:scale64{m3 + m1 * m2 <= 4096} -> u1:uint64xN w{felem_fits1 u1 m1} -> f2:uint64xN w{felem_fits1 f2 m2} -> acc1:uint64xN w{felem_wide_fits1 acc1 m3} -> i:nat{i < w} -> Lemma ((uint64xN_v (vec_add_mod acc1 (vec_mul_mod f2 u1))).[i] <= (m3 + m1 * m2) * max26 * max26) #push-options "--z3rlimit 200" let smul_add_felem5_fits_lemma_i #w #m1 #m2 #m3 u1 f2 acc1 i = let o = vec_add_mod acc1 (vec_mul_mod f2 u1) in smul_add_mod_lemma #m1 #m2 #m3 (uint64xN_v u1).[i] (uint64xN_v f2).[i] (uint64xN_v acc1).[i]; assert ((uint64xN_v o).[i] == (uint64xN_v acc1).[i] + (uint64xN_v u1).[i] * (uint64xN_v f2).[i]); lemma_mult_le (uint64xN_v u1).[i] (m1 * max26) (uint64xN_v f2).[i] (m2 * max26); assert ((uint64xN_v o).[i] <= m3 * max26 * max26 + m1 * m2 * max26 * max26) #pop-options val smul_add_felem5_eval_lemma_i: #w:lanes -> #m1:scale32 -> #m2:scale32_5 -> #m3:scale64_5{m3 +* m1 *^ m2 <=* s64x5 4096} -> u1:uint64xN w{felem_fits1 u1 m1} -> f2:felem5 w{felem_fits5 f2 m2} -> acc1:felem_wide5 w{felem_wide_fits5 acc1 m3} -> i:nat{i < w} -> Lemma ((fas_nat5 (smul_add_felem5 #w u1 f2 acc1)).[i] == (fas_nat5 acc1).[i] + (uint64xN_v u1).[i] * (fas_nat5 f2).[i]) let smul_add_felem5_eval_lemma_i #w #m1 #m2 #m3 u1 f2 acc1 i = let o = smul_add_felem5 #w u1 f2 acc1 in let (m20, m21, m22, m23, m24) = m2 in let (m30, m31, m32, m33, m34) = m3 in let vu1 = (uint64xN_v u1).[i] in let (tf20, tf21, tf22, tf23, tf24) = as_tup64_i f2 i in let (ta0, ta1, ta2, ta3, ta4) = as_tup64_i acc1 i in let (to0, to1, to2, to3, to4) = as_tup64_i o i in smul_add_mod_lemma #m1 #m20 #m30 vu1 (v tf20) (v ta0); smul_add_mod_lemma #m1 #m21 #m31 vu1 (v tf21) (v ta1); smul_add_mod_lemma #m1 #m22 #m32 vu1 (v tf22) (v ta2); smul_add_mod_lemma #m1 #m23 #m33 vu1 (v tf23) (v ta3); smul_add_mod_lemma #m1 #m24 #m34 vu1 (v tf24) (v ta4); calc (==) { (fas_nat5 o).[i]; (==) { } v ta0 + vu1 * v tf20 + (v ta1 + vu1 * v tf21) * pow26 + (v ta2 + vu1 * v tf22) * pow52 + (v ta3 + vu1 * v tf23) * pow78 + (v ta4 + vu1 * v tf24) * pow104; (==) { FStar.Math.Lemmas.distributivity_add_left (v ta1) (vu1 * v tf21) pow26; FStar.Math.Lemmas.distributivity_add_left (v ta2) (vu1 * v tf22) pow52; FStar.Math.Lemmas.distributivity_add_left (v ta3) (vu1 * v tf23) pow78; FStar.Math.Lemmas.distributivity_add_left (v ta1) (vu1 * v tf24) pow104 } v ta0 + v ta1 * pow26 + v ta2 * pow52 + v ta3 * pow78 + v ta4 * pow104 + vu1 * v tf20 + vu1 * v tf21 * pow26 + vu1 * v tf22 * pow52 + vu1 * v tf23 * pow78 + vu1 * v tf24 * pow104; (==) { } (fas_nat5 acc1).[i] + vu1 * v tf20 + vu1 * v tf21 * pow26 + vu1 * v tf22 * pow52 + vu1 * v tf23 * pow78 + vu1 * v tf24 * pow104; }; assert ((fas_nat5 o).[i] == (fas_nat5 acc1).[i] + vu1 * v tf20 + vu1 * v tf21 * pow26 + vu1 * v tf22 * pow52 + vu1 * v tf23 * pow78 + vu1 * v tf24 * pow104); calc (==) { vu1 * (fas_nat5 f2).[i]; (==) { } vu1 * (v tf20 + v tf21 * pow26 + v tf22 * pow52 + v tf23 * pow78 + v tf24 * pow104); (==) { lemma_mul5_distr_l vu1 (v tf20) (v tf21 * pow26) (v tf22 * pow52) (v tf23 * pow78) (v tf24 * pow104)} vu1 * v tf20 + vu1 * (v tf21 * pow26) + vu1 * (v tf22 * pow52) + vu1 * (v tf23 * pow78) + vu1 * (v tf24 * pow104); (==) { FStar.Math.Lemmas.paren_mul_right vu1 (v tf21) pow26; FStar.Math.Lemmas.paren_mul_right vu1 (v tf22) pow52; FStar.Math.Lemmas.paren_mul_right vu1 (v tf23) pow78; FStar.Math.Lemmas.paren_mul_right vu1 (v tf24) pow104} vu1 * v tf20 + vu1 * v tf21 * pow26 + vu1 * v tf22 * pow52 + vu1 * v tf23 * pow78 + vu1 * v tf24 * pow104; }; assert ((fas_nat5 o).[i] == (fas_nat5 acc1).[i] + vu1 * (fas_nat5 f2).[i]) val smul_add_felem5_fits_lemma1: #w:lanes -> #m1:scale32 -> #m2:scale32 -> #m3:scale64{m3 + m1 * m2 <= 4096} -> u1:uint64xN w{felem_fits1 u1 m1} -> f2:uint64xN w{felem_fits1 f2 m2} -> acc1:uint64xN w{felem_wide_fits1 acc1 m3} -> Lemma (felem_wide_fits1 (vec_add_mod acc1 (vec_mul_mod f2 u1)) (m3 + m1 * m2)) let smul_add_felem5_fits_lemma1 #w #m1 #m2 #m3 u1 f2 acc1 = match w with | 1 -> smul_add_felem5_fits_lemma_i #w #m1 #m2 #m3 u1 f2 acc1 0 | 2 -> smul_add_felem5_fits_lemma_i #w #m1 #m2 #m3 u1 f2 acc1 0; smul_add_felem5_fits_lemma_i #w #m1 #m2 #m3 u1 f2 acc1 1 | 4 -> smul_add_felem5_fits_lemma_i #w #m1 #m2 #m3 u1 f2 acc1 0; smul_add_felem5_fits_lemma_i #w #m1 #m2 #m3 u1 f2 acc1 1; smul_add_felem5_fits_lemma_i #w #m1 #m2 #m3 u1 f2 acc1 2; smul_add_felem5_fits_lemma_i #w #m1 #m2 #m3 u1 f2 acc1 3 val smul_add_felem5_fits_lemma: #w:lanes -> #m1:scale32 -> #m2:scale32_5 -> #m3:scale64_5{m3 +* m1 *^ m2 <=* s64x5 4096} -> u1:uint64xN w{felem_fits1 u1 m1} -> f2:felem5 w{felem_fits5 f2 m2} -> acc1:felem_wide5 w{felem_wide_fits5 acc1 m3} -> Lemma (felem_wide_fits5 (smul_add_felem5 #w u1 f2 acc1) (m3 +* m1 *^ m2)) let smul_add_felem5_fits_lemma #w #m1 #m2 #m3 u1 f2 acc1 = let (f20, f21, f22, f23, f24) = f2 in let (m20, m21, m22, m23, m24) = m2 in let (a0, a1, a2, a3, a4) = acc1 in let (m30, m31, m32, m33, m34) = m3 in smul_add_felem5_fits_lemma1 #w #m1 #m20 #m30 u1 f20 a0; smul_add_felem5_fits_lemma1 #w #m1 #m21 #m31 u1 f21 a1; smul_add_felem5_fits_lemma1 #w #m1 #m22 #m32 u1 f22 a2; smul_add_felem5_fits_lemma1 #w #m1 #m23 #m33 u1 f23 a3; smul_add_felem5_fits_lemma1 #w #m1 #m24 #m34 u1 f24 a4 val smul_add_felem5_eval_lemma: #w:lanes -> #m1:scale32 -> #m2:scale32_5 -> #m3:scale64_5{m3 +* m1 *^ m2 <=* s64x5 4096} -> u1:uint64xN w{felem_fits1 u1 m1} -> f2:felem5 w{felem_fits5 f2 m2} -> acc1:felem_wide5 w{felem_wide_fits5 acc1 m3} -> Lemma (fas_nat5 (smul_add_felem5 #w u1 f2 acc1) == map2 #nat #nat #nat (fun a b -> a + b) (fas_nat5 acc1) (map2 #nat #nat #nat (fun a b -> a * b) (uint64xN_v u1) (fas_nat5 f2))) let smul_add_felem5_eval_lemma #w #m1 #m2 #m3 u1 f2 acc1 = let tmp = map2 #nat #nat #nat (fun a b -> a + b) (fas_nat5 acc1) (map2 #nat #nat #nat (fun a b -> a * b) (uint64xN_v u1) (fas_nat5 f2)) in FStar.Classical.forall_intro (smul_add_felem5_eval_lemma_i #w #m1 #m2 #m3 u1 f2 acc1); eq_intro (fas_nat5 (smul_add_felem5 #w u1 f2 acc1)) tmp val lemma_fmul5_pow26: r:tup64_5 -> Lemma (requires (let (r0, r1, r2, r3, r4) = r in v r4 * 5 <= 10 * pow26)) (ensures (let (r0, r1, r2, r3, r4) = r in (pow26 * as_nat5 r) % prime == as_nat5 (r4 *! u64 5, r0, r1, r2, r3) % prime)) let lemma_fmul5_pow26 r = let (r0, r1, r2, r3, r4) = r in calc (==) { (pow26 * as_nat5 r) % prime; (==) { } (pow26 * (v r0 + v r1 * pow26 + v r2 * pow52 + v r3 * pow78 + v r4 * pow104)) % prime; (==) { lemma_mul5_distr_l pow26 (v r0) (v r1 * pow26) (v r2 * pow52) (v r3 * pow78) (v r4 * pow104) } (v r0 * pow26 + pow26 * v r1 * pow26 + pow26 * v r2 * pow52 + pow26 * v r3 * pow78 + pow26 * v r4 * pow104) % prime; (==) { } (v r0 * pow26 + v r1 * pow26 * pow26 + v r2 * pow26 * pow52 + v r3 * pow26 * pow78 + v r4 * pow26 * pow104) % prime; (==) { assert_norm (pow26 * pow26 = pow52); assert_norm (pow26 * pow52 = pow78); assert_norm (pow26 * pow78 = pow104); assert_norm (pow26 * pow104 = pow2 130) } (v r0 * pow26 + v r1 * pow52 + v r2 * pow78 + v r3 * pow104 + v r4 * pow2 130) % prime; (==) { FStar.Math.Lemmas.lemma_mod_plus_distr_r (v r0 * pow26 + v r1 * pow52 + v r2 * pow78 + v r3 * pow104) (v r4 * pow2 130) prime } (v r0 * pow26 + v r1 * pow52 + v r2 * pow78 + v r3 * pow104 + (v r4 * pow2 130) % prime) % prime; (==) { FStar.Math.Lemmas.lemma_mod_mul_distr_r (v r4) (pow2 130) prime } (v r0 * pow26 + v r1 * pow52 + v r2 * pow78 + v r3 * pow104 + (v r4 * (pow2 130 % prime)) % prime) % prime; (==) { lemma_prime () } (v r0 * pow26 + v r1 * pow52 + v r2 * pow78 + v r3 * pow104 + (v r4 * 5) % prime) % prime; (==) { FStar.Math.Lemmas.lemma_mod_plus_distr_r (v r0 * pow26 + v r1 * pow52 + v r2 * pow78 + v r3 * pow104) (v r4 * 5) prime } (v r0 * pow26 + v r1 * pow52 + v r2 * pow78 + v r3 * pow104 + v r4 * 5) % prime; }; assert ((pow26 * as_nat5 r) % prime == (v r0 * pow26 + v r1 * pow52 + v r2 * pow78 + v r3 * pow104 + v r4 * 5) % prime) val lemma_fmul5_pow52: r:tup64_5 -> Lemma (requires (let (r0, r1, r2, r3, r4) = r in v r4 * 5 <= 10 * pow26 /\ v r3 * 5 <= 10 * pow26)) (ensures (let (r0, r1, r2, r3, r4) = r in (pow52 * as_nat5 r) % prime == as_nat5 (r3 *! u64 5, r4 *! u64 5, r0, r1, r2) % prime))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntVector.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Poly1305.Vec.fst.checked", "Hacl.Spec.Poly1305.Field32xN.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Poly1305.Field32xN.Lemmas0.fst" }
[ { "abbrev": false, "full_module": "Hacl.Spec.Poly1305.Field32xN", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Poly1305.Vec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntVector", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Poly1305.Field32xN", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Poly1305.Field32xN", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
r: Hacl.Spec.Poly1305.Field32xN.tup64_5 -> FStar.Pervasives.Lemma (requires (let _ = r in (let FStar.Pervasives.Native.Mktuple5 #_ #_ #_ #_ #_ _ _ _ r3 r4 = _ in Lib.IntTypes.v r4 * 5 <= 10 * Hacl.Spec.Poly1305.Field32xN.pow26 /\ Lib.IntTypes.v r3 * 5 <= 10 * Hacl.Spec.Poly1305.Field32xN.pow26) <: Type0)) (ensures (let _ = r in (let FStar.Pervasives.Native.Mktuple5 #_ #_ #_ #_ #_ r0 r1 r2 r3 r4 = _ in Hacl.Spec.Poly1305.Field32xN.pow52 * Hacl.Spec.Poly1305.Field32xN.as_nat5 r % Hacl.Spec.Poly1305.Vec.prime == Hacl.Spec.Poly1305.Field32xN.as_nat5 (r3 *! Lib.IntTypes.u64 5, r4 *! Lib.IntTypes.u64 5, r0, r1, r2) % Hacl.Spec.Poly1305.Vec.prime) <: Type0))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Hacl.Spec.Poly1305.Field32xN.tup64_5", "Lib.IntTypes.uint64", "Prims._assert", "Prims.eq2", "Prims.int", "Prims.op_Modulus", "FStar.Mul.op_Star", "Hacl.Spec.Poly1305.Field32xN.pow52", "Hacl.Spec.Poly1305.Field32xN.as_nat5", "Hacl.Spec.Poly1305.Vec.prime", "FStar.Pervasives.Native.Mktuple5", "Lib.IntTypes.op_Star_Bang", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "Lib.IntTypes.u64", "Prims.unit", "FStar.Calc.calc_finish", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "FStar.Calc.calc_step", "Hacl.Spec.Poly1305.Field32xN.pow26", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "FStar.Pervasives.assert_norm", "Prims.squash", "FStar.Math.Lemmas.lemma_mod_mul_distr_r", "FStar.Math.Lemmas.paren_mul_right", "Hacl.Poly1305.Field32xN.Lemmas0.lemma_fmul5_pow26" ]
[]
false
false
true
false
false
let lemma_fmul5_pow52 r =
let r0, r1, r2, r3, r4 = r in calc ( == ) { (pow52 * as_nat5 r) % prime; ( == ) { assert_norm (pow52 == pow26 * pow26) } ((pow26 * pow26) * as_nat5 r) % prime; ( == ) { (FStar.Math.Lemmas.paren_mul_right pow26 pow26 (as_nat5 r); FStar.Math.Lemmas.lemma_mod_mul_distr_r pow26 (pow26 * as_nat5 r) prime) } (pow26 * (pow26 * as_nat5 r % prime)) % prime; ( == ) { lemma_fmul5_pow26 r } (pow26 * (as_nat5 (r4 *! u64 5, r0, r1, r2, r3) % prime)) % prime; ( == ) { FStar.Math.Lemmas.lemma_mod_mul_distr_r pow26 (as_nat5 (r4 *! u64 5, r0, r1, r2, r3)) prime } (pow26 * as_nat5 (r4 *! u64 5, r0, r1, r2, r3)) % prime; ( == ) { lemma_fmul5_pow26 (r4 *! u64 5, r0, r1, r2, r3) } as_nat5 (r3 *! u64 5, r4 *! u64 5, r0, r1, r2) % prime; }; assert ((pow52 * as_nat5 r) % prime == as_nat5 (r3 *! u64 5, r4 *! u64 5, r0, r1, r2) % prime)
false
Vale.Wrapper.X64.GCTR.fsti
Vale.Wrapper.X64.GCTR.uint64
val uint64 : Prims.eqtype
let uint64 = UInt64.t
{ "file_name": "vale/code/arch/x64/interop/Vale.Wrapper.X64.GCTR.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 21, "end_line": 20, "start_col": 0, "start_line": 20 }
module Vale.Wrapper.X64.GCTR open Vale.X64.CPU_Features_s open FStar.HyperStack.ST module B = LowStar.Buffer module HS = FStar.HyperStack module DV = LowStar.BufferView.Down module UV = LowStar.BufferView.Up open FStar.Mul open Vale.Def.Words_s open Vale.Def.Words.Seq_s open Vale.AES.AES_s open Vale.AES.GCTR open Vale.AES.GCTR_s open Vale.Interop.Base open Vale.Def.Types_s unfold
{ "checked_file": "/", "dependencies": [ "Vale.X64.CPU_Features_s.fst.checked", "Vale.Wrapper.X64.AES.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.GCTR.fsti.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Vale.Wrapper.X64.GCTR.fsti" }
[ { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.CPU_Features_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Wrapper.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.Wrapper.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Prims.eqtype
Prims.Tot
[ "total" ]
[]
[ "FStar.UInt64.t" ]
[]
false
false
false
true
false
let uint64 =
UInt64.t
false
Vale.Wrapper.X64.GCTR.fsti
Vale.Wrapper.X64.GCTR.uint8_p
val uint8_p : Type0
let uint8_p = B.buffer UInt8.t
{ "file_name": "vale/code/arch/x64/interop/Vale.Wrapper.X64.GCTR.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 30, "end_line": 19, "start_col": 0, "start_line": 19 }
module Vale.Wrapper.X64.GCTR open Vale.X64.CPU_Features_s open FStar.HyperStack.ST module B = LowStar.Buffer module HS = FStar.HyperStack module DV = LowStar.BufferView.Down module UV = LowStar.BufferView.Up open FStar.Mul open Vale.Def.Words_s open Vale.Def.Words.Seq_s open Vale.AES.AES_s open Vale.AES.GCTR open Vale.AES.GCTR_s open Vale.Interop.Base open Vale.Def.Types_s
{ "checked_file": "/", "dependencies": [ "Vale.X64.CPU_Features_s.fst.checked", "Vale.Wrapper.X64.AES.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.GCTR.fsti.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Vale.Wrapper.X64.GCTR.fsti" }
[ { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.CPU_Features_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Wrapper.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.Wrapper.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Type0
Prims.Tot
[ "total" ]
[]
[ "LowStar.Buffer.buffer", "FStar.UInt8.t" ]
[]
false
false
false
true
true
let uint8_p =
B.buffer UInt8.t
false
LowParse.Spec.ConstInt32.fst
LowParse.Spec.ConstInt32.decode_constint32le
val decode_constint32le (v: nat{0 <= v /\ v < 4294967296}) (b: bytes{Seq.length b == 4}) : Tot (option (constint32 v))
val decode_constint32le (v: nat{0 <= v /\ v < 4294967296}) (b: bytes{Seq.length b == 4}) : Tot (option (constint32 v))
let decode_constint32le (v: nat {0 <= v /\ v < 4294967296 } ) (b: bytes { Seq.length b == 4 } ) : Tot (option (constint32 v)) = let v' = decode_int32le b in if U32.v v' = v then Some v' else None
{ "file_name": "src/lowparse/LowParse.Spec.ConstInt32.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 10, "end_line": 43, "start_col": 0, "start_line": 35 }
module LowParse.Spec.ConstInt32 (* LowParse specification module for parsing 32 bits = 4 bytes unsigned constants Examples: uint32 foo = 5 uint32_le foo = 7 *) (* TODO: support big endian constants *) include FStar.Endianness include LowParse.Spec.Base include LowParse.Spec.Combinators include LowParse.Spec.Int32le module U32 = FStar.UInt32 module U8 = FStar.UInt8 module Seq = FStar.Seq module M = LowParse.Math let constint32 (v: nat { 0 <= v /\ v < 4294967296 } ) : Tot Type = (u: U32.t { U32.v u == v } ) inline_for_extraction let parse_constint32le_kind : parser_kind = strong_parser_kind 4 4 None
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Int32le.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.Base.fsti.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.ConstInt32.fst" }
[ { "abbrev": true, "full_module": "LowParse.Math", "short_module": "M" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Spec.Int32le", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Endianness", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
v: Prims.nat{0 <= v /\ v < 4294967296} -> b: LowParse.Bytes.bytes{FStar.Seq.Base.length b == 4} -> FStar.Pervasives.Native.option (LowParse.Spec.ConstInt32.constint32 v)
Prims.Tot
[ "total" ]
[]
[ "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_LessThan", "LowParse.Bytes.bytes", "Prims.eq2", "Prims.int", "FStar.Seq.Base.length", "LowParse.Bytes.byte", "Prims.op_Equality", "Prims.l_or", "Prims.op_GreaterThanOrEqual", "FStar.UInt.size", "FStar.UInt32.n", "FStar.UInt32.v", "FStar.Pervasives.Native.Some", "LowParse.Spec.ConstInt32.constint32", "Prims.bool", "FStar.Pervasives.Native.None", "FStar.Pervasives.Native.option", "FStar.UInt32.t", "LowParse.Spec.Int32le.decode_int32le" ]
[]
false
false
false
false
false
let decode_constint32le (v: nat{0 <= v /\ v < 4294967296}) (b: bytes{Seq.length b == 4}) : Tot (option (constint32 v)) =
let v' = decode_int32le b in if U32.v v' = v then Some v' else None
false
Hacl.Poly1305.Field32xN.Lemmas0.fst
Hacl.Poly1305.Field32xN.Lemmas0.lemma_fmul5_pow104
val lemma_fmul5_pow104: r:tup64_5 -> Lemma (requires (let (r0, r1, r2, r3, r4) = r in v r4 * 5 <= 10 * pow26 /\ v r3 * 5 <= 10 * pow26 /\ v r2 * 5 <= 10 * pow26 /\ v r1 * 5 <= 10 * pow26)) (ensures (let (r0, r1, r2, r3, r4) = r in (pow104 * as_nat5 r) % prime == as_nat5 (r1 *! u64 5, r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0) % prime))
val lemma_fmul5_pow104: r:tup64_5 -> Lemma (requires (let (r0, r1, r2, r3, r4) = r in v r4 * 5 <= 10 * pow26 /\ v r3 * 5 <= 10 * pow26 /\ v r2 * 5 <= 10 * pow26 /\ v r1 * 5 <= 10 * pow26)) (ensures (let (r0, r1, r2, r3, r4) = r in (pow104 * as_nat5 r) % prime == as_nat5 (r1 *! u64 5, r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0) % prime))
let lemma_fmul5_pow104 r = let (r0, r1, r2, r3, r4) = r in calc (==) { (pow104 * as_nat5 r) % prime; (==) { assert_norm (pow104 == pow26 * pow78) } (pow26 * pow78 * as_nat5 r) % prime; (==) { FStar.Math.Lemmas.paren_mul_right pow26 pow78 (as_nat5 r); FStar.Math.Lemmas.lemma_mod_mul_distr_r pow26 (pow78 * as_nat5 r) prime } (pow26 * (pow78 * as_nat5 r % prime)) % prime; (==) { lemma_fmul5_pow78 r } (pow26 * (as_nat5 (r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0, r1) % prime)) % prime; (==) { FStar.Math.Lemmas.lemma_mod_mul_distr_r pow26 (as_nat5 (r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0, r1)) prime } (pow26 * as_nat5 (r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0, r1)) % prime; (==) { lemma_fmul5_pow26 (r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0, r1) } as_nat5 (r1 *! u64 5, r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0) % prime; }; assert ((pow104 * as_nat5 r) % prime == as_nat5 (r1 *! u64 5, r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0) % prime)
{ "file_name": "code/poly1305/Hacl.Poly1305.Field32xN.Lemmas0.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 115, "end_line": 474, "start_col": 0, "start_line": 457 }
module Hacl.Poly1305.Field32xN.Lemmas0 open Lib.IntTypes open Lib.IntVector open Lib.Sequence open FStar.Mul open FStar.Calc open Hacl.Spec.Poly1305.Vec include Hacl.Spec.Poly1305.Field32xN #reset-options "--z3rlimit 50 --using_facts_from '* -FStar.Seq' --max_fuel 0 --max_ifuel 0" val lemma_prime: unit -> Lemma (pow2 130 % prime = 5) let lemma_prime () = assert_norm (pow2 130 % prime = 5 % prime); assert_norm (5 < prime); FStar.Math.Lemmas.modulo_lemma 5 prime val lemma_mult_le: a:nat -> b:nat -> c:nat -> d:nat -> Lemma (requires a <= b /\ c <= d) (ensures a * c <= b * d) let lemma_mult_le a b c d = () val lemma_mul5_distr_l: a:nat -> b:nat -> c:nat -> d:nat -> e:nat -> f:nat -> Lemma (a * (b + c + d + e + f) == a * b + a * c + a * d + a * e + a * f) let lemma_mul5_distr_l a b c d e f = () val lemma_mul5_distr_r: a:nat -> b:nat -> c:nat -> d:nat -> e:nat -> f:nat -> Lemma ((a + b + c + d + e) * f == a * f + b * f + c * f + d * f + e * f) let lemma_mul5_distr_r a b c d e f = () val smul_mod_lemma: #m1:scale32 -> #m2:scale32 -> a:nat{a <= m1 * max26} -> b:nat{b <= m2 * max26} -> Lemma (a * b % pow2 64 == a * b) let smul_mod_lemma #m1 #m2 a b = lemma_mult_le a (m1 * max26) b (m2 * max26); assert (a * b <= m1 * m2 * max26 * max26); FStar.Math.Lemmas.modulo_lemma (a * b) (pow2 64) val smul_add_mod_lemma: #m1:scale32 -> #m2:scale32 -> #m3:scale64{m3 + m1 * m2 <= 4096} -> a:nat{a <= m1 * max26} -> b:nat{b <= m2 * max26} -> c:nat{c <= m3 * max26 * max26} -> Lemma ((c + a * b % pow2 64) % pow2 64 == c + a * b) let smul_add_mod_lemma #m1 #m2 #m3 a b c = assert_norm ((m3 + m1 * m2) * max26 * max26 < pow2 64); lemma_mult_le a (m1 * max26) b (m2 * max26); assert (c + a * b <= m3 * max26 * max26 + m1 * m2 * max26 * max26); FStar.Math.Lemmas.modulo_lemma (c + a * b) (pow2 64) val add5_lemma1: ma:scale64 -> mb:scale64 -> a:uint64 -> b:uint64 -> Lemma (requires v a <= ma * max26 /\ v b <= mb * max26 /\ ma + mb <= 64) (ensures v (a +. b) == v a + v b /\ v (a +. b) <= (ma + mb) * max26) let add5_lemma1 ma mb a b = assert (v a + v b <= (ma + mb) * max26); Math.Lemmas.lemma_mult_le_right max26 (ma + mb) 64; assert (v a + v b <= 64 * max26); assert_norm (64 * max26 < pow2 32); Math.Lemmas.small_mod (v a + v b) (pow2 32) #set-options "--ifuel 1" val fadd5_eval_lemma_i: #w:lanes -> f1:felem5 w{felem_fits5 f1 (2,2,2,2,2)} -> f2:felem5 w{felem_fits5 f2 (1,1,1,1,1)} -> i:nat{i < w} -> Lemma ((feval5 (fadd5 f1 f2)).[i] == pfadd (feval5 f1).[i] (feval5 f2).[i]) let fadd5_eval_lemma_i #w f1 f2 i = let o = fadd5 f1 f2 in let (f10, f11, f12, f13, f14) = as_tup64_i f1 i in let (f20, f21, f22, f23, f24) = as_tup64_i f2 i in let (o0, o1, o2, o3, o4) = as_tup64_i o i in add5_lemma1 2 1 f10 f20; add5_lemma1 2 1 f11 f21; add5_lemma1 2 1 f12 f22; add5_lemma1 2 1 f13 f23; add5_lemma1 2 1 f14 f24; assert (as_nat5 (o0, o1, o2, o3, o4) == as_nat5 (f10, f11, f12, f13, f14) + as_nat5 (f20, f21, f22, f23, f24)); FStar.Math.Lemmas.lemma_mod_plus_distr_l (as_nat5 (f10, f11, f12, f13, f14)) (as_nat5 (f20, f21, f22, f23, f24)) prime; FStar.Math.Lemmas.lemma_mod_plus_distr_r (as_nat5 (f10, f11, f12, f13, f14) % prime) (as_nat5 (f20, f21, f22, f23, f24)) prime val smul_felem5_fits_lemma_i: #w:lanes -> #m1:scale32 -> #m2:scale32 -> u1:uint64xN w{felem_fits1 u1 m1} -> f2:uint64xN w{felem_fits1 f2 m2} -> i:nat{i < w} -> Lemma ((uint64xN_v (vec_mul_mod f2 u1)).[i] <= m1 * m2 * max26 * max26) let smul_felem5_fits_lemma_i #w #m1 #m2 u1 f2 i = let o = vec_mul_mod f2 u1 in smul_mod_lemma #m1 #m2 (uint64xN_v u1).[i] (uint64xN_v f2).[i]; assert ((uint64xN_v o).[i] == (uint64xN_v u1).[i] * (uint64xN_v f2).[i]); lemma_mult_le (uint64xN_v u1).[i] (m1 * max26) (uint64xN_v f2).[i] (m2 * max26) val smul_felem5_eval_lemma_i: #w:lanes -> #m1:scale32 -> #m2:scale32_5 -> u1:uint64xN w{felem_fits1 u1 m1} -> f2:felem5 w{felem_fits5 f2 m2} -> i:nat{i < w} -> Lemma ((fas_nat5 (smul_felem5 #w u1 f2)).[i] == (uint64xN_v u1).[i] * (fas_nat5 f2).[i]) let smul_felem5_eval_lemma_i #w #m1 #m2 u1 f2 i = let o = smul_felem5 #w u1 f2 in let (m20, m21, m22, m23, m24) = m2 in let vu1 = (uint64xN_v u1).[i] in let (tf20, tf21, tf22, tf23, tf24) = as_tup64_i f2 i in let (to0, to1, to2, to3, to4) = as_tup64_i o i in smul_mod_lemma #m1 #m20 vu1 (v tf20); smul_mod_lemma #m1 #m21 vu1 (v tf21); smul_mod_lemma #m1 #m22 vu1 (v tf22); smul_mod_lemma #m1 #m23 vu1 (v tf23); smul_mod_lemma #m1 #m24 vu1 (v tf24); assert ((fas_nat5 o).[i] == vu1 * v tf20 + vu1 * v tf21 * pow26 + vu1 * v tf22 * pow52 + vu1 * v tf23 * pow78 + vu1 * v tf24 * pow104); calc (==) { vu1 * (fas_nat5 f2).[i]; (==) { } vu1 * (v tf20 + v tf21 * pow26 + v tf22 * pow52 + v tf23 * pow78 + v tf24 * pow104); (==) { lemma_mul5_distr_l vu1 (v tf20) (v tf21 * pow26) (v tf22 * pow52) (v tf23 * pow78) (v tf24 * pow104)} vu1 * v tf20 + vu1 * (v tf21 * pow26) + vu1 * (v tf22 * pow52) + vu1 * (v tf23 * pow78) + vu1 * (v tf24 * pow104); (==) { FStar.Math.Lemmas.paren_mul_right vu1 (v tf21) pow26; FStar.Math.Lemmas.paren_mul_right vu1 (v tf22) pow52; FStar.Math.Lemmas.paren_mul_right vu1 (v tf23) pow78; FStar.Math.Lemmas.paren_mul_right vu1 (v tf24) pow104} vu1 * v tf20 + vu1 * v tf21 * pow26 + vu1 * v tf22 * pow52 + vu1 * v tf23 * pow78 + vu1 * v tf24 * pow104; }; assert (vu1 * (fas_nat5 f2).[i] == (fas_nat5 o).[i]) val smul_felem5_fits_lemma1: #w:lanes -> #m1:scale32 -> #m2:scale32 -> u1:uint64xN w{felem_fits1 u1 m1} -> f2:uint64xN w{felem_fits1 f2 m2} -> Lemma (felem_wide_fits1 (vec_mul_mod f2 u1) (m1 * m2)) let smul_felem5_fits_lemma1 #w #m1 #m2 u1 f2 = match w with | 1 -> smul_felem5_fits_lemma_i #w #m1 #m2 u1 f2 0 | 2 -> smul_felem5_fits_lemma_i #w #m1 #m2 u1 f2 0; smul_felem5_fits_lemma_i #w #m1 #m2 u1 f2 1 | 4 -> smul_felem5_fits_lemma_i #w #m1 #m2 u1 f2 0; smul_felem5_fits_lemma_i #w #m1 #m2 u1 f2 1; smul_felem5_fits_lemma_i #w #m1 #m2 u1 f2 2; smul_felem5_fits_lemma_i #w #m1 #m2 u1 f2 3 val smul_felem5_fits_lemma: #w:lanes -> #m1:scale32 -> #m2:scale32_5 -> u1:uint64xN w{felem_fits1 u1 m1} -> f2:felem5 w{felem_fits5 f2 m2} -> Lemma (felem_wide_fits5 (smul_felem5 #w u1 f2) (m1 *^ m2)) let smul_felem5_fits_lemma #w #m1 #m2 u1 f2 = let (f20, f21, f22, f23, f24) = f2 in let (m20, m21, m22, m23, m24) = m2 in smul_felem5_fits_lemma1 #w #m1 #m20 u1 f20; smul_felem5_fits_lemma1 #w #m1 #m21 u1 f21; smul_felem5_fits_lemma1 #w #m1 #m22 u1 f22; smul_felem5_fits_lemma1 #w #m1 #m23 u1 f23; smul_felem5_fits_lemma1 #w #m1 #m24 u1 f24 val smul_felem5_eval_lemma: #w:lanes -> #m1:scale32 -> #m2:scale32_5 -> u1:uint64xN w{felem_fits1 u1 m1} -> f2:felem5 w{felem_fits5 f2 m2} -> Lemma (fas_nat5 (smul_felem5 #w u1 f2) == map2 #nat #nat #nat (fun a b -> a * b) (uint64xN_v u1) (fas_nat5 f2)) let smul_felem5_eval_lemma #w #m1 #m2 u1 f2 = FStar.Classical.forall_intro (smul_felem5_eval_lemma_i #w #m1 #m2 u1 f2); eq_intro (fas_nat5 (smul_felem5 #w u1 f2)) (map2 #nat #nat #nat (fun a b -> a * b) (uint64xN_v u1) (fas_nat5 f2)) val smul_add_felem5_fits_lemma_i: #w:lanes -> #m1:scale32 -> #m2:scale32 -> #m3:scale64{m3 + m1 * m2 <= 4096} -> u1:uint64xN w{felem_fits1 u1 m1} -> f2:uint64xN w{felem_fits1 f2 m2} -> acc1:uint64xN w{felem_wide_fits1 acc1 m3} -> i:nat{i < w} -> Lemma ((uint64xN_v (vec_add_mod acc1 (vec_mul_mod f2 u1))).[i] <= (m3 + m1 * m2) * max26 * max26) #push-options "--z3rlimit 200" let smul_add_felem5_fits_lemma_i #w #m1 #m2 #m3 u1 f2 acc1 i = let o = vec_add_mod acc1 (vec_mul_mod f2 u1) in smul_add_mod_lemma #m1 #m2 #m3 (uint64xN_v u1).[i] (uint64xN_v f2).[i] (uint64xN_v acc1).[i]; assert ((uint64xN_v o).[i] == (uint64xN_v acc1).[i] + (uint64xN_v u1).[i] * (uint64xN_v f2).[i]); lemma_mult_le (uint64xN_v u1).[i] (m1 * max26) (uint64xN_v f2).[i] (m2 * max26); assert ((uint64xN_v o).[i] <= m3 * max26 * max26 + m1 * m2 * max26 * max26) #pop-options val smul_add_felem5_eval_lemma_i: #w:lanes -> #m1:scale32 -> #m2:scale32_5 -> #m3:scale64_5{m3 +* m1 *^ m2 <=* s64x5 4096} -> u1:uint64xN w{felem_fits1 u1 m1} -> f2:felem5 w{felem_fits5 f2 m2} -> acc1:felem_wide5 w{felem_wide_fits5 acc1 m3} -> i:nat{i < w} -> Lemma ((fas_nat5 (smul_add_felem5 #w u1 f2 acc1)).[i] == (fas_nat5 acc1).[i] + (uint64xN_v u1).[i] * (fas_nat5 f2).[i]) let smul_add_felem5_eval_lemma_i #w #m1 #m2 #m3 u1 f2 acc1 i = let o = smul_add_felem5 #w u1 f2 acc1 in let (m20, m21, m22, m23, m24) = m2 in let (m30, m31, m32, m33, m34) = m3 in let vu1 = (uint64xN_v u1).[i] in let (tf20, tf21, tf22, tf23, tf24) = as_tup64_i f2 i in let (ta0, ta1, ta2, ta3, ta4) = as_tup64_i acc1 i in let (to0, to1, to2, to3, to4) = as_tup64_i o i in smul_add_mod_lemma #m1 #m20 #m30 vu1 (v tf20) (v ta0); smul_add_mod_lemma #m1 #m21 #m31 vu1 (v tf21) (v ta1); smul_add_mod_lemma #m1 #m22 #m32 vu1 (v tf22) (v ta2); smul_add_mod_lemma #m1 #m23 #m33 vu1 (v tf23) (v ta3); smul_add_mod_lemma #m1 #m24 #m34 vu1 (v tf24) (v ta4); calc (==) { (fas_nat5 o).[i]; (==) { } v ta0 + vu1 * v tf20 + (v ta1 + vu1 * v tf21) * pow26 + (v ta2 + vu1 * v tf22) * pow52 + (v ta3 + vu1 * v tf23) * pow78 + (v ta4 + vu1 * v tf24) * pow104; (==) { FStar.Math.Lemmas.distributivity_add_left (v ta1) (vu1 * v tf21) pow26; FStar.Math.Lemmas.distributivity_add_left (v ta2) (vu1 * v tf22) pow52; FStar.Math.Lemmas.distributivity_add_left (v ta3) (vu1 * v tf23) pow78; FStar.Math.Lemmas.distributivity_add_left (v ta1) (vu1 * v tf24) pow104 } v ta0 + v ta1 * pow26 + v ta2 * pow52 + v ta3 * pow78 + v ta4 * pow104 + vu1 * v tf20 + vu1 * v tf21 * pow26 + vu1 * v tf22 * pow52 + vu1 * v tf23 * pow78 + vu1 * v tf24 * pow104; (==) { } (fas_nat5 acc1).[i] + vu1 * v tf20 + vu1 * v tf21 * pow26 + vu1 * v tf22 * pow52 + vu1 * v tf23 * pow78 + vu1 * v tf24 * pow104; }; assert ((fas_nat5 o).[i] == (fas_nat5 acc1).[i] + vu1 * v tf20 + vu1 * v tf21 * pow26 + vu1 * v tf22 * pow52 + vu1 * v tf23 * pow78 + vu1 * v tf24 * pow104); calc (==) { vu1 * (fas_nat5 f2).[i]; (==) { } vu1 * (v tf20 + v tf21 * pow26 + v tf22 * pow52 + v tf23 * pow78 + v tf24 * pow104); (==) { lemma_mul5_distr_l vu1 (v tf20) (v tf21 * pow26) (v tf22 * pow52) (v tf23 * pow78) (v tf24 * pow104)} vu1 * v tf20 + vu1 * (v tf21 * pow26) + vu1 * (v tf22 * pow52) + vu1 * (v tf23 * pow78) + vu1 * (v tf24 * pow104); (==) { FStar.Math.Lemmas.paren_mul_right vu1 (v tf21) pow26; FStar.Math.Lemmas.paren_mul_right vu1 (v tf22) pow52; FStar.Math.Lemmas.paren_mul_right vu1 (v tf23) pow78; FStar.Math.Lemmas.paren_mul_right vu1 (v tf24) pow104} vu1 * v tf20 + vu1 * v tf21 * pow26 + vu1 * v tf22 * pow52 + vu1 * v tf23 * pow78 + vu1 * v tf24 * pow104; }; assert ((fas_nat5 o).[i] == (fas_nat5 acc1).[i] + vu1 * (fas_nat5 f2).[i]) val smul_add_felem5_fits_lemma1: #w:lanes -> #m1:scale32 -> #m2:scale32 -> #m3:scale64{m3 + m1 * m2 <= 4096} -> u1:uint64xN w{felem_fits1 u1 m1} -> f2:uint64xN w{felem_fits1 f2 m2} -> acc1:uint64xN w{felem_wide_fits1 acc1 m3} -> Lemma (felem_wide_fits1 (vec_add_mod acc1 (vec_mul_mod f2 u1)) (m3 + m1 * m2)) let smul_add_felem5_fits_lemma1 #w #m1 #m2 #m3 u1 f2 acc1 = match w with | 1 -> smul_add_felem5_fits_lemma_i #w #m1 #m2 #m3 u1 f2 acc1 0 | 2 -> smul_add_felem5_fits_lemma_i #w #m1 #m2 #m3 u1 f2 acc1 0; smul_add_felem5_fits_lemma_i #w #m1 #m2 #m3 u1 f2 acc1 1 | 4 -> smul_add_felem5_fits_lemma_i #w #m1 #m2 #m3 u1 f2 acc1 0; smul_add_felem5_fits_lemma_i #w #m1 #m2 #m3 u1 f2 acc1 1; smul_add_felem5_fits_lemma_i #w #m1 #m2 #m3 u1 f2 acc1 2; smul_add_felem5_fits_lemma_i #w #m1 #m2 #m3 u1 f2 acc1 3 val smul_add_felem5_fits_lemma: #w:lanes -> #m1:scale32 -> #m2:scale32_5 -> #m3:scale64_5{m3 +* m1 *^ m2 <=* s64x5 4096} -> u1:uint64xN w{felem_fits1 u1 m1} -> f2:felem5 w{felem_fits5 f2 m2} -> acc1:felem_wide5 w{felem_wide_fits5 acc1 m3} -> Lemma (felem_wide_fits5 (smul_add_felem5 #w u1 f2 acc1) (m3 +* m1 *^ m2)) let smul_add_felem5_fits_lemma #w #m1 #m2 #m3 u1 f2 acc1 = let (f20, f21, f22, f23, f24) = f2 in let (m20, m21, m22, m23, m24) = m2 in let (a0, a1, a2, a3, a4) = acc1 in let (m30, m31, m32, m33, m34) = m3 in smul_add_felem5_fits_lemma1 #w #m1 #m20 #m30 u1 f20 a0; smul_add_felem5_fits_lemma1 #w #m1 #m21 #m31 u1 f21 a1; smul_add_felem5_fits_lemma1 #w #m1 #m22 #m32 u1 f22 a2; smul_add_felem5_fits_lemma1 #w #m1 #m23 #m33 u1 f23 a3; smul_add_felem5_fits_lemma1 #w #m1 #m24 #m34 u1 f24 a4 val smul_add_felem5_eval_lemma: #w:lanes -> #m1:scale32 -> #m2:scale32_5 -> #m3:scale64_5{m3 +* m1 *^ m2 <=* s64x5 4096} -> u1:uint64xN w{felem_fits1 u1 m1} -> f2:felem5 w{felem_fits5 f2 m2} -> acc1:felem_wide5 w{felem_wide_fits5 acc1 m3} -> Lemma (fas_nat5 (smul_add_felem5 #w u1 f2 acc1) == map2 #nat #nat #nat (fun a b -> a + b) (fas_nat5 acc1) (map2 #nat #nat #nat (fun a b -> a * b) (uint64xN_v u1) (fas_nat5 f2))) let smul_add_felem5_eval_lemma #w #m1 #m2 #m3 u1 f2 acc1 = let tmp = map2 #nat #nat #nat (fun a b -> a + b) (fas_nat5 acc1) (map2 #nat #nat #nat (fun a b -> a * b) (uint64xN_v u1) (fas_nat5 f2)) in FStar.Classical.forall_intro (smul_add_felem5_eval_lemma_i #w #m1 #m2 #m3 u1 f2 acc1); eq_intro (fas_nat5 (smul_add_felem5 #w u1 f2 acc1)) tmp val lemma_fmul5_pow26: r:tup64_5 -> Lemma (requires (let (r0, r1, r2, r3, r4) = r in v r4 * 5 <= 10 * pow26)) (ensures (let (r0, r1, r2, r3, r4) = r in (pow26 * as_nat5 r) % prime == as_nat5 (r4 *! u64 5, r0, r1, r2, r3) % prime)) let lemma_fmul5_pow26 r = let (r0, r1, r2, r3, r4) = r in calc (==) { (pow26 * as_nat5 r) % prime; (==) { } (pow26 * (v r0 + v r1 * pow26 + v r2 * pow52 + v r3 * pow78 + v r4 * pow104)) % prime; (==) { lemma_mul5_distr_l pow26 (v r0) (v r1 * pow26) (v r2 * pow52) (v r3 * pow78) (v r4 * pow104) } (v r0 * pow26 + pow26 * v r1 * pow26 + pow26 * v r2 * pow52 + pow26 * v r3 * pow78 + pow26 * v r4 * pow104) % prime; (==) { } (v r0 * pow26 + v r1 * pow26 * pow26 + v r2 * pow26 * pow52 + v r3 * pow26 * pow78 + v r4 * pow26 * pow104) % prime; (==) { assert_norm (pow26 * pow26 = pow52); assert_norm (pow26 * pow52 = pow78); assert_norm (pow26 * pow78 = pow104); assert_norm (pow26 * pow104 = pow2 130) } (v r0 * pow26 + v r1 * pow52 + v r2 * pow78 + v r3 * pow104 + v r4 * pow2 130) % prime; (==) { FStar.Math.Lemmas.lemma_mod_plus_distr_r (v r0 * pow26 + v r1 * pow52 + v r2 * pow78 + v r3 * pow104) (v r4 * pow2 130) prime } (v r0 * pow26 + v r1 * pow52 + v r2 * pow78 + v r3 * pow104 + (v r4 * pow2 130) % prime) % prime; (==) { FStar.Math.Lemmas.lemma_mod_mul_distr_r (v r4) (pow2 130) prime } (v r0 * pow26 + v r1 * pow52 + v r2 * pow78 + v r3 * pow104 + (v r4 * (pow2 130 % prime)) % prime) % prime; (==) { lemma_prime () } (v r0 * pow26 + v r1 * pow52 + v r2 * pow78 + v r3 * pow104 + (v r4 * 5) % prime) % prime; (==) { FStar.Math.Lemmas.lemma_mod_plus_distr_r (v r0 * pow26 + v r1 * pow52 + v r2 * pow78 + v r3 * pow104) (v r4 * 5) prime } (v r0 * pow26 + v r1 * pow52 + v r2 * pow78 + v r3 * pow104 + v r4 * 5) % prime; }; assert ((pow26 * as_nat5 r) % prime == (v r0 * pow26 + v r1 * pow52 + v r2 * pow78 + v r3 * pow104 + v r4 * 5) % prime) val lemma_fmul5_pow52: r:tup64_5 -> Lemma (requires (let (r0, r1, r2, r3, r4) = r in v r4 * 5 <= 10 * pow26 /\ v r3 * 5 <= 10 * pow26)) (ensures (let (r0, r1, r2, r3, r4) = r in (pow52 * as_nat5 r) % prime == as_nat5 (r3 *! u64 5, r4 *! u64 5, r0, r1, r2) % prime)) let lemma_fmul5_pow52 r = let (r0, r1, r2, r3, r4) = r in calc (==) { (pow52 * as_nat5 r) % prime; (==) { assert_norm (pow52 == pow26 * pow26) } (pow26 * pow26 * as_nat5 r) % prime; (==) { FStar.Math.Lemmas.paren_mul_right pow26 pow26 (as_nat5 r); FStar.Math.Lemmas.lemma_mod_mul_distr_r pow26 (pow26 * as_nat5 r) prime } (pow26 * (pow26 * as_nat5 r % prime)) % prime; (==) { lemma_fmul5_pow26 r } (pow26 * (as_nat5 (r4 *! u64 5, r0, r1, r2, r3) % prime)) % prime; (==) { FStar.Math.Lemmas.lemma_mod_mul_distr_r pow26 (as_nat5 (r4 *! u64 5, r0, r1, r2, r3)) prime } (pow26 * as_nat5 (r4 *! u64 5, r0, r1, r2, r3)) % prime; (==) { lemma_fmul5_pow26 (r4 *! u64 5, r0, r1, r2, r3) } as_nat5 (r3 *! u64 5, r4 *! u64 5, r0, r1, r2) % prime; }; assert ((pow52 * as_nat5 r) % prime == as_nat5 (r3 *! u64 5, r4 *! u64 5, r0, r1, r2) % prime) val lemma_fmul5_pow78: r:tup64_5 -> Lemma (requires (let (r0, r1, r2, r3, r4) = r in v r4 * 5 <= 10 * pow26 /\ v r3 * 5 <= 10 * pow26 /\ v r2 * 5 <= 10 * pow26)) (ensures (let (r0, r1, r2, r3, r4) = r in (pow78 * as_nat5 r) % prime == as_nat5 (r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0, r1) % prime)) let lemma_fmul5_pow78 r = let (r0, r1, r2, r3, r4) = r in calc (==) { (pow78 * as_nat5 r) % prime; (==) { assert_norm (pow78 == pow26 * pow52) } (pow26 * pow52 * as_nat5 r) % prime; (==) { FStar.Math.Lemmas.paren_mul_right pow26 pow52 (as_nat5 r); FStar.Math.Lemmas.lemma_mod_mul_distr_r pow26 (pow52 * as_nat5 r) prime } (pow26 * (pow52 * as_nat5 r % prime)) % prime; (==) { lemma_fmul5_pow52 r } (pow26 * (as_nat5 (r3 *! u64 5, r4 *! u64 5, r0, r1, r2) % prime)) % prime; (==) { FStar.Math.Lemmas.lemma_mod_mul_distr_r pow26 (as_nat5 (r3 *! u64 5, r4 *! u64 5, r0, r1, r2)) prime } (pow26 * as_nat5 (r3 *! u64 5, r4 *! u64 5, r0, r1, r2)) % prime; (==) { lemma_fmul5_pow26 (r3 *! u64 5, r4 *! u64 5, r0, r1, r2) } as_nat5 (r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0, r1) % prime; }; assert ((pow78 * as_nat5 r) % prime == as_nat5 (r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0, r1) % prime) val lemma_fmul5_pow104: r:tup64_5 -> Lemma (requires (let (r0, r1, r2, r3, r4) = r in v r4 * 5 <= 10 * pow26 /\ v r3 * 5 <= 10 * pow26 /\ v r2 * 5 <= 10 * pow26 /\ v r1 * 5 <= 10 * pow26)) (ensures (let (r0, r1, r2, r3, r4) = r in (pow104 * as_nat5 r) % prime == as_nat5 (r1 *! u64 5, r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0) % prime))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntVector.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Poly1305.Vec.fst.checked", "Hacl.Spec.Poly1305.Field32xN.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Poly1305.Field32xN.Lemmas0.fst" }
[ { "abbrev": false, "full_module": "Hacl.Spec.Poly1305.Field32xN", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Poly1305.Vec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntVector", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Poly1305.Field32xN", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Poly1305.Field32xN", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
r: Hacl.Spec.Poly1305.Field32xN.tup64_5 -> FStar.Pervasives.Lemma (requires (let _ = r in (let FStar.Pervasives.Native.Mktuple5 #_ #_ #_ #_ #_ _ r1 r2 r3 r4 = _ in Lib.IntTypes.v r4 * 5 <= 10 * Hacl.Spec.Poly1305.Field32xN.pow26 /\ Lib.IntTypes.v r3 * 5 <= 10 * Hacl.Spec.Poly1305.Field32xN.pow26 /\ Lib.IntTypes.v r2 * 5 <= 10 * Hacl.Spec.Poly1305.Field32xN.pow26 /\ Lib.IntTypes.v r1 * 5 <= 10 * Hacl.Spec.Poly1305.Field32xN.pow26) <: Type0)) (ensures (let _ = r in (let FStar.Pervasives.Native.Mktuple5 #_ #_ #_ #_ #_ r0 r1 r2 r3 r4 = _ in Hacl.Spec.Poly1305.Field32xN.pow104 * Hacl.Spec.Poly1305.Field32xN.as_nat5 r % Hacl.Spec.Poly1305.Vec.prime == Hacl.Spec.Poly1305.Field32xN.as_nat5 (r1 *! Lib.IntTypes.u64 5, r2 *! Lib.IntTypes.u64 5, r3 *! Lib.IntTypes.u64 5, r4 *! Lib.IntTypes.u64 5, r0) % Hacl.Spec.Poly1305.Vec.prime) <: Type0))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Hacl.Spec.Poly1305.Field32xN.tup64_5", "Lib.IntTypes.uint64", "Prims._assert", "Prims.eq2", "Prims.int", "Prims.op_Modulus", "FStar.Mul.op_Star", "Hacl.Spec.Poly1305.Field32xN.pow104", "Hacl.Spec.Poly1305.Field32xN.as_nat5", "Hacl.Spec.Poly1305.Vec.prime", "FStar.Pervasives.Native.Mktuple5", "Lib.IntTypes.op_Star_Bang", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "Lib.IntTypes.u64", "Prims.unit", "FStar.Calc.calc_finish", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "FStar.Calc.calc_step", "Hacl.Spec.Poly1305.Field32xN.pow26", "Hacl.Spec.Poly1305.Field32xN.pow78", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "FStar.Pervasives.assert_norm", "Prims.squash", "FStar.Math.Lemmas.lemma_mod_mul_distr_r", "FStar.Math.Lemmas.paren_mul_right", "Hacl.Poly1305.Field32xN.Lemmas0.lemma_fmul5_pow78", "Hacl.Poly1305.Field32xN.Lemmas0.lemma_fmul5_pow26" ]
[]
false
false
true
false
false
let lemma_fmul5_pow104 r =
let r0, r1, r2, r3, r4 = r in calc ( == ) { (pow104 * as_nat5 r) % prime; ( == ) { assert_norm (pow104 == pow26 * pow78) } ((pow26 * pow78) * as_nat5 r) % prime; ( == ) { (FStar.Math.Lemmas.paren_mul_right pow26 pow78 (as_nat5 r); FStar.Math.Lemmas.lemma_mod_mul_distr_r pow26 (pow78 * as_nat5 r) prime) } (pow26 * (pow78 * as_nat5 r % prime)) % prime; ( == ) { lemma_fmul5_pow78 r } (pow26 * (as_nat5 (r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0, r1) % prime)) % prime; ( == ) { FStar.Math.Lemmas.lemma_mod_mul_distr_r pow26 (as_nat5 (r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0, r1)) prime } (pow26 * as_nat5 (r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0, r1)) % prime; ( == ) { lemma_fmul5_pow26 (r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0, r1) } as_nat5 (r1 *! u64 5, r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0) % prime; }; assert ((pow104 * as_nat5 r) % prime == as_nat5 (r1 *! u64 5, r2 *! u64 5, r3 *! u64 5, r4 *! u64 5, r0) % prime)
false
MerkleTree.fsti
MerkleTree.hash_size_t
val hash_size_t : Type0
let hash_size_t = MTNLD.hash_size_t
{ "file_name": "src/MerkleTree.fsti", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 35, "end_line": 21, "start_col": 0, "start_line": 21 }
module MerkleTree module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module HH = FStar.Monotonic.HyperHeap module B = LowStar.Buffer module CB = LowStar.ConstBuffer module U32 = FStar.UInt32 module U64 = FStar.UInt64 module MTS = MerkleTree.Spec module MTNL = MerkleTree.Low module MTNLHF = MerkleTree.Low.Hashfunctions module MTNLE = MerkleTree.EverCrypt module MTNLD = MerkleTree.Low.Datastructures module MTNLS = MerkleTree.Low.Serialization
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.Spec.fst.checked", "MerkleTree.Low.Serialization.fst.checked", "MerkleTree.Low.Hashfunctions.fst.checked", "MerkleTree.Low.Datastructures.fst.checked", "MerkleTree.Low.fst.checked", "MerkleTree.EverCrypt.fsti.checked", "LowStar.ConstBuffer.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.HyperHeap.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.fsti" }
[ { "abbrev": true, "full_module": "MerkleTree.Low.Serialization", "short_module": "MTNLS" }, { "abbrev": true, "full_module": "MerkleTree.Low.Datastructures", "short_module": "MTNLD" }, { "abbrev": true, "full_module": "MerkleTree.EverCrypt", "short_module": "MTNLE" }, { "abbrev": true, "full_module": "MerkleTree.Low.Hashfunctions", "short_module": "MTNLHF" }, { "abbrev": true, "full_module": "MerkleTree.Low", "short_module": "MTNL" }, { "abbrev": true, "full_module": "MerkleTree.Spec", "short_module": "MTS" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "LowStar.ConstBuffer", "short_module": "CB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperHeap", "short_module": "HH" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Type0
Prims.Tot
[ "total" ]
[]
[ "MerkleTree.Low.Datastructures.hash_size_t" ]
[]
false
false
false
true
true
let hash_size_t =
MTNLD.hash_size_t
false
LowParse.Spec.ConstInt32.fst
LowParse.Spec.ConstInt32.decode_constint32le_injective
val decode_constint32le_injective (v: nat{0 <= v /\ v < 4294967296}) : Lemma (make_constant_size_parser_precond 4 (constint32 v) (decode_constint32le v))
val decode_constint32le_injective (v: nat{0 <= v /\ v < 4294967296}) : Lemma (make_constant_size_parser_precond 4 (constint32 v) (decode_constint32le v))
let decode_constint32le_injective (v: nat { 0 <= v /\ v < 4294967296 } ) : Lemma (make_constant_size_parser_precond 4 (constint32 v) (decode_constint32le v)) = Classical.forall_intro_2 (decode_constint32le_injective' v)
{ "file_name": "src/lowparse/LowParse.Spec.ConstInt32.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 61, "end_line": 70, "start_col": 0, "start_line": 66 }
module LowParse.Spec.ConstInt32 (* LowParse specification module for parsing 32 bits = 4 bytes unsigned constants Examples: uint32 foo = 5 uint32_le foo = 7 *) (* TODO: support big endian constants *) include FStar.Endianness include LowParse.Spec.Base include LowParse.Spec.Combinators include LowParse.Spec.Int32le module U32 = FStar.UInt32 module U8 = FStar.UInt8 module Seq = FStar.Seq module M = LowParse.Math let constint32 (v: nat { 0 <= v /\ v < 4294967296 } ) : Tot Type = (u: U32.t { U32.v u == v } ) inline_for_extraction let parse_constint32le_kind : parser_kind = strong_parser_kind 4 4 None let decode_constint32le (v: nat {0 <= v /\ v < 4294967296 } ) (b: bytes { Seq.length b == 4 } ) : Tot (option (constint32 v)) = let v' = decode_int32le b in if U32.v v' = v then Some v' else None let decode_constint32le_injective' (v: nat { 0 <= v /\ v < 4294967296 } ) (b1: bytes { Seq.length b1 == 4 } ) (b2: bytes { Seq.length b2 == 4 } ) : Lemma ((Some? (decode_constint32le v b1) \/ Some? (decode_constint32le v b2)) /\ (decode_constint32le v b1 == decode_constint32le v b2) ==> Seq.equal b1 b2) = let res1 = decode_constint32le v b1 in let res2 = decode_constint32le v b2 in match res1 with | Some v1 -> assert ( U32.v v1 == v ); (match res2 with | Some v2 -> assert ( U32.v v2 == v ); assert ( v1 == v2 ); decode_int32le_injective b1 b2 | None -> ()) | None -> ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Int32le.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.Base.fsti.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.ConstInt32.fst" }
[ { "abbrev": true, "full_module": "LowParse.Math", "short_module": "M" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Spec.Int32le", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Endianness", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
v: Prims.nat{0 <= v /\ v < 4294967296} -> FStar.Pervasives.Lemma (ensures LowParse.Spec.Combinators.make_constant_size_parser_precond 4 (LowParse.Spec.ConstInt32.constint32 v) (LowParse.Spec.ConstInt32.decode_constint32le v))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_LessThan", "FStar.Classical.forall_intro_2", "LowParse.Bytes.bytes", "Prims.eq2", "Prims.int", "FStar.Seq.Base.length", "LowParse.Bytes.byte", "Prims.l_imp", "Prims.l_or", "FStar.Pervasives.Native.uu___is_Some", "LowParse.Spec.ConstInt32.constint32", "LowParse.Spec.ConstInt32.decode_constint32le", "FStar.Pervasives.Native.option", "FStar.Seq.Base.equal", "LowParse.Spec.ConstInt32.decode_constint32le_injective'", "Prims.unit", "Prims.l_True", "Prims.squash", "LowParse.Spec.Combinators.make_constant_size_parser_precond", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let decode_constint32le_injective (v: nat{0 <= v /\ v < 4294967296}) : Lemma (make_constant_size_parser_precond 4 (constint32 v) (decode_constint32le v)) =
Classical.forall_intro_2 (decode_constint32le_injective' v)
false
MerkleTree.fsti
MerkleTree.offset_t
val offset_t : Prims.eqtype
let offset_t = MTNL.offset_t
{ "file_name": "src/MerkleTree.fsti", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 28, "end_line": 22, "start_col": 0, "start_line": 22 }
module MerkleTree module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module HH = FStar.Monotonic.HyperHeap module B = LowStar.Buffer module CB = LowStar.ConstBuffer module U32 = FStar.UInt32 module U64 = FStar.UInt64 module MTS = MerkleTree.Spec module MTNL = MerkleTree.Low module MTNLHF = MerkleTree.Low.Hashfunctions module MTNLE = MerkleTree.EverCrypt module MTNLD = MerkleTree.Low.Datastructures module MTNLS = MerkleTree.Low.Serialization
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.Spec.fst.checked", "MerkleTree.Low.Serialization.fst.checked", "MerkleTree.Low.Hashfunctions.fst.checked", "MerkleTree.Low.Datastructures.fst.checked", "MerkleTree.Low.fst.checked", "MerkleTree.EverCrypt.fsti.checked", "LowStar.ConstBuffer.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.HyperHeap.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.fsti" }
[ { "abbrev": true, "full_module": "MerkleTree.Low.Serialization", "short_module": "MTNLS" }, { "abbrev": true, "full_module": "MerkleTree.Low.Datastructures", "short_module": "MTNLD" }, { "abbrev": true, "full_module": "MerkleTree.EverCrypt", "short_module": "MTNLE" }, { "abbrev": true, "full_module": "MerkleTree.Low.Hashfunctions", "short_module": "MTNLHF" }, { "abbrev": true, "full_module": "MerkleTree.Low", "short_module": "MTNL" }, { "abbrev": true, "full_module": "MerkleTree.Spec", "short_module": "MTS" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "LowStar.ConstBuffer", "short_module": "CB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperHeap", "short_module": "HH" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Prims.eqtype
Prims.Tot
[ "total" ]
[]
[ "MerkleTree.Low.offset_t" ]
[]
false
false
false
true
false
let offset_t =
MTNL.offset_t
false
MerkleTree.fsti
MerkleTree.const_mt_p
val const_mt_p : Type0
let const_mt_p = MTNL.const_mt_p
{ "file_name": "src/MerkleTree.fsti", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 32, "end_line": 32, "start_col": 0, "start_line": 32 }
module MerkleTree module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module HH = FStar.Monotonic.HyperHeap module B = LowStar.Buffer module CB = LowStar.ConstBuffer module U32 = FStar.UInt32 module U64 = FStar.UInt64 module MTS = MerkleTree.Spec module MTNL = MerkleTree.Low module MTNLHF = MerkleTree.Low.Hashfunctions module MTNLE = MerkleTree.EverCrypt module MTNLD = MerkleTree.Low.Datastructures module MTNLS = MerkleTree.Low.Serialization let hash_size_t = MTNLD.hash_size_t let offset_t = MTNL.offset_t let index_t = MTNL.index_t let hash #hash_size = MTNLD.hash #hash_size type path = MTNL.path type path_p = B.pointer path type const_path_p = MTNL.const_pointer path let merkle_tree = MTNL.merkle_tree
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.Spec.fst.checked", "MerkleTree.Low.Serialization.fst.checked", "MerkleTree.Low.Hashfunctions.fst.checked", "MerkleTree.Low.Datastructures.fst.checked", "MerkleTree.Low.fst.checked", "MerkleTree.EverCrypt.fsti.checked", "LowStar.ConstBuffer.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.HyperHeap.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.fsti" }
[ { "abbrev": true, "full_module": "MerkleTree.Low.Serialization", "short_module": "MTNLS" }, { "abbrev": true, "full_module": "MerkleTree.Low.Datastructures", "short_module": "MTNLD" }, { "abbrev": true, "full_module": "MerkleTree.EverCrypt", "short_module": "MTNLE" }, { "abbrev": true, "full_module": "MerkleTree.Low.Hashfunctions", "short_module": "MTNLHF" }, { "abbrev": true, "full_module": "MerkleTree.Low", "short_module": "MTNL" }, { "abbrev": true, "full_module": "MerkleTree.Spec", "short_module": "MTS" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "LowStar.ConstBuffer", "short_module": "CB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperHeap", "short_module": "HH" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Type0
Prims.Tot
[ "total" ]
[]
[ "MerkleTree.Low.const_mt_p" ]
[]
false
false
false
true
true
let const_mt_p =
MTNL.const_mt_p
false
LowParse.Spec.ConstInt32.fst
LowParse.Spec.ConstInt32.serialize_constint32le'
val serialize_constint32le' (v: nat{0 <= v /\ v < 4294967296}) : Tot (bare_serializer (constint32 v))
val serialize_constint32le' (v: nat{0 <= v /\ v < 4294967296}) : Tot (bare_serializer (constint32 v))
let serialize_constint32le' (v: nat { 0 <= v /\ v < 4294967296 } ) : Tot (bare_serializer (constint32 v)) = fun (x: constint32 v) -> let res = n_to_le 4 v in res
{ "file_name": "src/lowparse/LowParse.Spec.ConstInt32.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 5, "end_line": 105, "start_col": 0, "start_line": 100 }
module LowParse.Spec.ConstInt32 (* LowParse specification module for parsing 32 bits = 4 bytes unsigned constants Examples: uint32 foo = 5 uint32_le foo = 7 *) (* TODO: support big endian constants *) include FStar.Endianness include LowParse.Spec.Base include LowParse.Spec.Combinators include LowParse.Spec.Int32le module U32 = FStar.UInt32 module U8 = FStar.UInt8 module Seq = FStar.Seq module M = LowParse.Math let constint32 (v: nat { 0 <= v /\ v < 4294967296 } ) : Tot Type = (u: U32.t { U32.v u == v } ) inline_for_extraction let parse_constint32le_kind : parser_kind = strong_parser_kind 4 4 None let decode_constint32le (v: nat {0 <= v /\ v < 4294967296 } ) (b: bytes { Seq.length b == 4 } ) : Tot (option (constint32 v)) = let v' = decode_int32le b in if U32.v v' = v then Some v' else None let decode_constint32le_injective' (v: nat { 0 <= v /\ v < 4294967296 } ) (b1: bytes { Seq.length b1 == 4 } ) (b2: bytes { Seq.length b2 == 4 } ) : Lemma ((Some? (decode_constint32le v b1) \/ Some? (decode_constint32le v b2)) /\ (decode_constint32le v b1 == decode_constint32le v b2) ==> Seq.equal b1 b2) = let res1 = decode_constint32le v b1 in let res2 = decode_constint32le v b2 in match res1 with | Some v1 -> assert ( U32.v v1 == v ); (match res2 with | Some v2 -> assert ( U32.v v2 == v ); assert ( v1 == v2 ); decode_int32le_injective b1 b2 | None -> ()) | None -> () let decode_constint32le_injective (v: nat { 0 <= v /\ v < 4294967296 } ) : Lemma (make_constant_size_parser_precond 4 (constint32 v) (decode_constint32le v)) = Classical.forall_intro_2 (decode_constint32le_injective' v) let parse_constint32le (v: nat { 0 <= v /\ v < 4294967296 } ) : Tot (parser parse_constint32le_kind (constint32 v)) = decode_constint32le_injective v; make_constant_size_parser 4 (constint32 v) (decode_constint32le v) let parse_constint32le_unfold (v: nat { 0 <= v /\ v < 4294967296 } ) (input: bytes) : Lemma (parse (parse_constint32le v) input == (let res = parse parse_int32le input in match res with | Some (x, consumed) -> if U32.v x = v && consumed = 4 then Some (x, consumed) else None | None -> None)) = let res = parse parse_int32le input in match res with | Some (x, consumed) -> if U32.v x = v && consumed = 4 then () else () | None -> ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Int32le.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.Base.fsti.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.ConstInt32.fst" }
[ { "abbrev": true, "full_module": "LowParse.Math", "short_module": "M" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Spec.Int32le", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Endianness", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
v: Prims.nat{0 <= v /\ v < 4294967296} -> LowParse.Spec.Base.bare_serializer (LowParse.Spec.ConstInt32.constint32 v)
Prims.Tot
[ "total" ]
[]
[ "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_LessThan", "LowParse.Spec.ConstInt32.constint32", "FStar.Endianness.bytes", "Prims.eq2", "FStar.Seq.Base.length", "FStar.UInt8.t", "FStar.Endianness.le_to_n", "FStar.Endianness.n_to_le", "LowParse.Bytes.bytes", "LowParse.Spec.Base.bare_serializer" ]
[]
false
false
false
false
false
let serialize_constint32le' (v: nat{0 <= v /\ v < 4294967296}) : Tot (bare_serializer (constint32 v)) =
fun (x: constint32 v) -> let res = n_to_le 4 v in res
false
MerkleTree.fsti
MerkleTree.index_t
val index_t : Prims.eqtype
let index_t = MTNL.index_t
{ "file_name": "src/MerkleTree.fsti", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 26, "end_line": 23, "start_col": 0, "start_line": 23 }
module MerkleTree module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module HH = FStar.Monotonic.HyperHeap module B = LowStar.Buffer module CB = LowStar.ConstBuffer module U32 = FStar.UInt32 module U64 = FStar.UInt64 module MTS = MerkleTree.Spec module MTNL = MerkleTree.Low module MTNLHF = MerkleTree.Low.Hashfunctions module MTNLE = MerkleTree.EverCrypt module MTNLD = MerkleTree.Low.Datastructures module MTNLS = MerkleTree.Low.Serialization let hash_size_t = MTNLD.hash_size_t
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.Spec.fst.checked", "MerkleTree.Low.Serialization.fst.checked", "MerkleTree.Low.Hashfunctions.fst.checked", "MerkleTree.Low.Datastructures.fst.checked", "MerkleTree.Low.fst.checked", "MerkleTree.EverCrypt.fsti.checked", "LowStar.ConstBuffer.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.HyperHeap.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.fsti" }
[ { "abbrev": true, "full_module": "MerkleTree.Low.Serialization", "short_module": "MTNLS" }, { "abbrev": true, "full_module": "MerkleTree.Low.Datastructures", "short_module": "MTNLD" }, { "abbrev": true, "full_module": "MerkleTree.EverCrypt", "short_module": "MTNLE" }, { "abbrev": true, "full_module": "MerkleTree.Low.Hashfunctions", "short_module": "MTNLHF" }, { "abbrev": true, "full_module": "MerkleTree.Low", "short_module": "MTNL" }, { "abbrev": true, "full_module": "MerkleTree.Spec", "short_module": "MTS" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "LowStar.ConstBuffer", "short_module": "CB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperHeap", "short_module": "HH" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Prims.eqtype
Prims.Tot
[ "total" ]
[]
[ "MerkleTree.Low.index_t" ]
[]
false
false
false
true
false
let index_t =
MTNL.index_t
false
MerkleTree.fsti
MerkleTree.pf
val pf : _: _ -> Prims.logical
let pf = fun _ -> False
{ "file_name": "src/MerkleTree.fsti", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 23, "end_line": 35, "start_col": 0, "start_line": 35 }
module MerkleTree module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module HH = FStar.Monotonic.HyperHeap module B = LowStar.Buffer module CB = LowStar.ConstBuffer module U32 = FStar.UInt32 module U64 = FStar.UInt64 module MTS = MerkleTree.Spec module MTNL = MerkleTree.Low module MTNLHF = MerkleTree.Low.Hashfunctions module MTNLE = MerkleTree.EverCrypt module MTNLD = MerkleTree.Low.Datastructures module MTNLS = MerkleTree.Low.Serialization let hash_size_t = MTNLD.hash_size_t let offset_t = MTNL.offset_t let index_t = MTNL.index_t let hash #hash_size = MTNLD.hash #hash_size type path = MTNL.path type path_p = B.pointer path type const_path_p = MTNL.const_pointer path let merkle_tree = MTNL.merkle_tree let mt_p = MTNL.mt_p let const_mt_p = MTNL.const_mt_p
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.Spec.fst.checked", "MerkleTree.Low.Serialization.fst.checked", "MerkleTree.Low.Hashfunctions.fst.checked", "MerkleTree.Low.Datastructures.fst.checked", "MerkleTree.Low.fst.checked", "MerkleTree.EverCrypt.fsti.checked", "LowStar.ConstBuffer.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.HyperHeap.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.fsti" }
[ { "abbrev": true, "full_module": "MerkleTree.Low.Serialization", "short_module": "MTNLS" }, { "abbrev": true, "full_module": "MerkleTree.Low.Datastructures", "short_module": "MTNLD" }, { "abbrev": true, "full_module": "MerkleTree.EverCrypt", "short_module": "MTNLE" }, { "abbrev": true, "full_module": "MerkleTree.Low.Hashfunctions", "short_module": "MTNLHF" }, { "abbrev": true, "full_module": "MerkleTree.Low", "short_module": "MTNL" }, { "abbrev": true, "full_module": "MerkleTree.Spec", "short_module": "MTS" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "LowStar.ConstBuffer", "short_module": "CB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperHeap", "short_module": "HH" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: _ -> Prims.logical
Prims.Tot
[ "total" ]
[]
[ "Prims.l_False", "Prims.logical" ]
[]
false
false
false
true
true
let pf =
fun _ -> False
false
LowParse.Spec.ConstInt32.fst
LowParse.Spec.ConstInt32.serialize_constint32le
val serialize_constint32le (v: nat{0 <= v /\ v < 4294967296}) : Tot (serializer (parse_constint32le v))
val serialize_constint32le (v: nat{0 <= v /\ v < 4294967296}) : Tot (serializer (parse_constint32le v))
let serialize_constint32le (v: nat { 0 <= v /\ v < 4294967296 } ) : Tot (serializer (parse_constint32le v)) = serialize_constint32le_correct v; serialize_constint32le' v
{ "file_name": "src/lowparse/LowParse.Spec.ConstInt32.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 27, "end_line": 124, "start_col": 0, "start_line": 120 }
module LowParse.Spec.ConstInt32 (* LowParse specification module for parsing 32 bits = 4 bytes unsigned constants Examples: uint32 foo = 5 uint32_le foo = 7 *) (* TODO: support big endian constants *) include FStar.Endianness include LowParse.Spec.Base include LowParse.Spec.Combinators include LowParse.Spec.Int32le module U32 = FStar.UInt32 module U8 = FStar.UInt8 module Seq = FStar.Seq module M = LowParse.Math let constint32 (v: nat { 0 <= v /\ v < 4294967296 } ) : Tot Type = (u: U32.t { U32.v u == v } ) inline_for_extraction let parse_constint32le_kind : parser_kind = strong_parser_kind 4 4 None let decode_constint32le (v: nat {0 <= v /\ v < 4294967296 } ) (b: bytes { Seq.length b == 4 } ) : Tot (option (constint32 v)) = let v' = decode_int32le b in if U32.v v' = v then Some v' else None let decode_constint32le_injective' (v: nat { 0 <= v /\ v < 4294967296 } ) (b1: bytes { Seq.length b1 == 4 } ) (b2: bytes { Seq.length b2 == 4 } ) : Lemma ((Some? (decode_constint32le v b1) \/ Some? (decode_constint32le v b2)) /\ (decode_constint32le v b1 == decode_constint32le v b2) ==> Seq.equal b1 b2) = let res1 = decode_constint32le v b1 in let res2 = decode_constint32le v b2 in match res1 with | Some v1 -> assert ( U32.v v1 == v ); (match res2 with | Some v2 -> assert ( U32.v v2 == v ); assert ( v1 == v2 ); decode_int32le_injective b1 b2 | None -> ()) | None -> () let decode_constint32le_injective (v: nat { 0 <= v /\ v < 4294967296 } ) : Lemma (make_constant_size_parser_precond 4 (constint32 v) (decode_constint32le v)) = Classical.forall_intro_2 (decode_constint32le_injective' v) let parse_constint32le (v: nat { 0 <= v /\ v < 4294967296 } ) : Tot (parser parse_constint32le_kind (constint32 v)) = decode_constint32le_injective v; make_constant_size_parser 4 (constint32 v) (decode_constint32le v) let parse_constint32le_unfold (v: nat { 0 <= v /\ v < 4294967296 } ) (input: bytes) : Lemma (parse (parse_constint32le v) input == (let res = parse parse_int32le input in match res with | Some (x, consumed) -> if U32.v x = v && consumed = 4 then Some (x, consumed) else None | None -> None)) = let res = parse parse_int32le input in match res with | Some (x, consumed) -> if U32.v x = v && consumed = 4 then () else () | None -> () let serialize_constint32le' (v: nat { 0 <= v /\ v < 4294967296 } ) : Tot (bare_serializer (constint32 v)) = fun (x: constint32 v) -> let res = n_to_le 4 v in res let serialize_constint32le_correct (v: nat { 0 <= v /\ v < 4294967296 } ) : Lemma (serializer_correct (parse_constint32le v) (serialize_constint32le' v)) = let prf (x: constint32 v) : Lemma (let res = n_to_le 4 v in U32.v x == v /\ Seq.length res == 4 /\ (parse (parse_constint32le v) res == Some (x, 4))) = () in Classical.forall_intro prf
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Int32le.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.Base.fsti.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.ConstInt32.fst" }
[ { "abbrev": true, "full_module": "LowParse.Math", "short_module": "M" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Spec.Int32le", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Endianness", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
v: Prims.nat{0 <= v /\ v < 4294967296} -> LowParse.Spec.Base.serializer (LowParse.Spec.ConstInt32.parse_constint32le v)
Prims.Tot
[ "total" ]
[]
[ "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_LessThan", "LowParse.Spec.ConstInt32.serialize_constint32le'", "Prims.unit", "LowParse.Spec.ConstInt32.serialize_constint32le_correct", "LowParse.Spec.Base.serializer", "LowParse.Spec.ConstInt32.parse_constint32le_kind", "LowParse.Spec.ConstInt32.constint32", "LowParse.Spec.ConstInt32.parse_constint32le" ]
[]
false
false
false
false
false
let serialize_constint32le (v: nat{0 <= v /\ v < 4294967296}) : Tot (serializer (parse_constint32le v)) =
serialize_constint32le_correct v; serialize_constint32le' v
false
LowParse.Spec.ConstInt32.fst
LowParse.Spec.ConstInt32.parse_constint32le
val parse_constint32le (v: nat{0 <= v /\ v < 4294967296}) : Tot (parser parse_constint32le_kind (constint32 v))
val parse_constint32le (v: nat{0 <= v /\ v < 4294967296}) : Tot (parser parse_constint32le_kind (constint32 v))
let parse_constint32le (v: nat { 0 <= v /\ v < 4294967296 } ) : Tot (parser parse_constint32le_kind (constint32 v)) = decode_constint32le_injective v; make_constant_size_parser 4 (constint32 v) (decode_constint32le v)
{ "file_name": "src/lowparse/LowParse.Spec.ConstInt32.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 68, "end_line": 76, "start_col": 0, "start_line": 72 }
module LowParse.Spec.ConstInt32 (* LowParse specification module for parsing 32 bits = 4 bytes unsigned constants Examples: uint32 foo = 5 uint32_le foo = 7 *) (* TODO: support big endian constants *) include FStar.Endianness include LowParse.Spec.Base include LowParse.Spec.Combinators include LowParse.Spec.Int32le module U32 = FStar.UInt32 module U8 = FStar.UInt8 module Seq = FStar.Seq module M = LowParse.Math let constint32 (v: nat { 0 <= v /\ v < 4294967296 } ) : Tot Type = (u: U32.t { U32.v u == v } ) inline_for_extraction let parse_constint32le_kind : parser_kind = strong_parser_kind 4 4 None let decode_constint32le (v: nat {0 <= v /\ v < 4294967296 } ) (b: bytes { Seq.length b == 4 } ) : Tot (option (constint32 v)) = let v' = decode_int32le b in if U32.v v' = v then Some v' else None let decode_constint32le_injective' (v: nat { 0 <= v /\ v < 4294967296 } ) (b1: bytes { Seq.length b1 == 4 } ) (b2: bytes { Seq.length b2 == 4 } ) : Lemma ((Some? (decode_constint32le v b1) \/ Some? (decode_constint32le v b2)) /\ (decode_constint32le v b1 == decode_constint32le v b2) ==> Seq.equal b1 b2) = let res1 = decode_constint32le v b1 in let res2 = decode_constint32le v b2 in match res1 with | Some v1 -> assert ( U32.v v1 == v ); (match res2 with | Some v2 -> assert ( U32.v v2 == v ); assert ( v1 == v2 ); decode_int32le_injective b1 b2 | None -> ()) | None -> () let decode_constint32le_injective (v: nat { 0 <= v /\ v < 4294967296 } ) : Lemma (make_constant_size_parser_precond 4 (constint32 v) (decode_constint32le v)) = Classical.forall_intro_2 (decode_constint32le_injective' v)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Int32le.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.Base.fsti.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.ConstInt32.fst" }
[ { "abbrev": true, "full_module": "LowParse.Math", "short_module": "M" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Spec.Int32le", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Endianness", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
v: Prims.nat{0 <= v /\ v < 4294967296} -> LowParse.Spec.Base.parser LowParse.Spec.ConstInt32.parse_constint32le_kind (LowParse.Spec.ConstInt32.constint32 v)
Prims.Tot
[ "total" ]
[]
[ "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_LessThan", "LowParse.Spec.Combinators.make_constant_size_parser", "LowParse.Spec.ConstInt32.constint32", "LowParse.Spec.ConstInt32.decode_constint32le", "Prims.unit", "LowParse.Spec.ConstInt32.decode_constint32le_injective", "LowParse.Spec.Base.parser", "LowParse.Spec.ConstInt32.parse_constint32le_kind" ]
[]
false
false
false
false
false
let parse_constint32le (v: nat{0 <= v /\ v < 4294967296}) : Tot (parser parse_constint32le_kind (constint32 v)) =
decode_constint32le_injective v; make_constant_size_parser 4 (constint32 v) (decode_constint32le v)
false
LowParse.Spec.ConstInt32.fst
LowParse.Spec.ConstInt32.decode_constint32le_injective'
val decode_constint32le_injective' (v: nat{0 <= v /\ v < 4294967296}) (b1: bytes{Seq.length b1 == 4}) (b2: bytes{Seq.length b2 == 4}) : Lemma ((Some? (decode_constint32le v b1) \/ Some? (decode_constint32le v b2)) /\ (decode_constint32le v b1 == decode_constint32le v b2) ==> Seq.equal b1 b2)
val decode_constint32le_injective' (v: nat{0 <= v /\ v < 4294967296}) (b1: bytes{Seq.length b1 == 4}) (b2: bytes{Seq.length b2 == 4}) : Lemma ((Some? (decode_constint32le v b1) \/ Some? (decode_constint32le v b2)) /\ (decode_constint32le v b1 == decode_constint32le v b2) ==> Seq.equal b1 b2)
let decode_constint32le_injective' (v: nat { 0 <= v /\ v < 4294967296 } ) (b1: bytes { Seq.length b1 == 4 } ) (b2: bytes { Seq.length b2 == 4 } ) : Lemma ((Some? (decode_constint32le v b1) \/ Some? (decode_constint32le v b2)) /\ (decode_constint32le v b1 == decode_constint32le v b2) ==> Seq.equal b1 b2) = let res1 = decode_constint32le v b1 in let res2 = decode_constint32le v b2 in match res1 with | Some v1 -> assert ( U32.v v1 == v ); (match res2 with | Some v2 -> assert ( U32.v v2 == v ); assert ( v1 == v2 ); decode_int32le_injective b1 b2 | None -> ()) | None -> ()
{ "file_name": "src/lowparse/LowParse.Spec.ConstInt32.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 14, "end_line": 64, "start_col": 0, "start_line": 45 }
module LowParse.Spec.ConstInt32 (* LowParse specification module for parsing 32 bits = 4 bytes unsigned constants Examples: uint32 foo = 5 uint32_le foo = 7 *) (* TODO: support big endian constants *) include FStar.Endianness include LowParse.Spec.Base include LowParse.Spec.Combinators include LowParse.Spec.Int32le module U32 = FStar.UInt32 module U8 = FStar.UInt8 module Seq = FStar.Seq module M = LowParse.Math let constint32 (v: nat { 0 <= v /\ v < 4294967296 } ) : Tot Type = (u: U32.t { U32.v u == v } ) inline_for_extraction let parse_constint32le_kind : parser_kind = strong_parser_kind 4 4 None let decode_constint32le (v: nat {0 <= v /\ v < 4294967296 } ) (b: bytes { Seq.length b == 4 } ) : Tot (option (constint32 v)) = let v' = decode_int32le b in if U32.v v' = v then Some v' else None
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Int32le.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.Base.fsti.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.ConstInt32.fst" }
[ { "abbrev": true, "full_module": "LowParse.Math", "short_module": "M" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Spec.Int32le", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Endianness", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
v: Prims.nat{0 <= v /\ v < 4294967296} -> b1: LowParse.Bytes.bytes{FStar.Seq.Base.length b1 == 4} -> b2: LowParse.Bytes.bytes{FStar.Seq.Base.length b2 == 4} -> FStar.Pervasives.Lemma (ensures (Some? (LowParse.Spec.ConstInt32.decode_constint32le v b1) \/ Some? (LowParse.Spec.ConstInt32.decode_constint32le v b2)) /\ LowParse.Spec.ConstInt32.decode_constint32le v b1 == LowParse.Spec.ConstInt32.decode_constint32le v b2 ==> FStar.Seq.Base.equal b1 b2)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_LessThan", "LowParse.Bytes.bytes", "Prims.eq2", "Prims.int", "FStar.Seq.Base.length", "LowParse.Bytes.byte", "LowParse.Spec.ConstInt32.constint32", "LowParse.Spec.Int32le.decode_int32le_injective", "Prims.unit", "Prims._assert", "Prims.l_or", "FStar.UInt.size", "FStar.UInt32.n", "Prims.op_GreaterThanOrEqual", "FStar.UInt32.v", "FStar.Pervasives.Native.option", "LowParse.Spec.ConstInt32.decode_constint32le", "Prims.l_True", "Prims.squash", "Prims.l_imp", "FStar.Pervasives.Native.uu___is_Some", "FStar.Seq.Base.equal", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let decode_constint32le_injective' (v: nat{0 <= v /\ v < 4294967296}) (b1: bytes{Seq.length b1 == 4}) (b2: bytes{Seq.length b2 == 4}) : Lemma ((Some? (decode_constint32le v b1) \/ Some? (decode_constint32le v b2)) /\ (decode_constint32le v b1 == decode_constint32le v b2) ==> Seq.equal b1 b2) =
let res1 = decode_constint32le v b1 in let res2 = decode_constint32le v b2 in match res1 with | Some v1 -> assert (U32.v v1 == v); (match res2 with | Some v2 -> assert (U32.v v2 == v); assert (v1 == v2); decode_int32le_injective b1 b2 | None -> ()) | None -> ()
false
LowParse.Spec.ConstInt32.fst
LowParse.Spec.ConstInt32.serialize_constint32le_correct
val serialize_constint32le_correct (v: nat{0 <= v /\ v < 4294967296}) : Lemma (serializer_correct (parse_constint32le v) (serialize_constint32le' v))
val serialize_constint32le_correct (v: nat{0 <= v /\ v < 4294967296}) : Lemma (serializer_correct (parse_constint32le v) (serialize_constint32le' v))
let serialize_constint32le_correct (v: nat { 0 <= v /\ v < 4294967296 } ) : Lemma (serializer_correct (parse_constint32le v) (serialize_constint32le' v)) = let prf (x: constint32 v) : Lemma (let res = n_to_le 4 v in U32.v x == v /\ Seq.length res == 4 /\ (parse (parse_constint32le v) res == Some (x, 4))) = () in Classical.forall_intro prf
{ "file_name": "src/lowparse/LowParse.Spec.ConstInt32.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 28, "end_line": 118, "start_col": 0, "start_line": 107 }
module LowParse.Spec.ConstInt32 (* LowParse specification module for parsing 32 bits = 4 bytes unsigned constants Examples: uint32 foo = 5 uint32_le foo = 7 *) (* TODO: support big endian constants *) include FStar.Endianness include LowParse.Spec.Base include LowParse.Spec.Combinators include LowParse.Spec.Int32le module U32 = FStar.UInt32 module U8 = FStar.UInt8 module Seq = FStar.Seq module M = LowParse.Math let constint32 (v: nat { 0 <= v /\ v < 4294967296 } ) : Tot Type = (u: U32.t { U32.v u == v } ) inline_for_extraction let parse_constint32le_kind : parser_kind = strong_parser_kind 4 4 None let decode_constint32le (v: nat {0 <= v /\ v < 4294967296 } ) (b: bytes { Seq.length b == 4 } ) : Tot (option (constint32 v)) = let v' = decode_int32le b in if U32.v v' = v then Some v' else None let decode_constint32le_injective' (v: nat { 0 <= v /\ v < 4294967296 } ) (b1: bytes { Seq.length b1 == 4 } ) (b2: bytes { Seq.length b2 == 4 } ) : Lemma ((Some? (decode_constint32le v b1) \/ Some? (decode_constint32le v b2)) /\ (decode_constint32le v b1 == decode_constint32le v b2) ==> Seq.equal b1 b2) = let res1 = decode_constint32le v b1 in let res2 = decode_constint32le v b2 in match res1 with | Some v1 -> assert ( U32.v v1 == v ); (match res2 with | Some v2 -> assert ( U32.v v2 == v ); assert ( v1 == v2 ); decode_int32le_injective b1 b2 | None -> ()) | None -> () let decode_constint32le_injective (v: nat { 0 <= v /\ v < 4294967296 } ) : Lemma (make_constant_size_parser_precond 4 (constint32 v) (decode_constint32le v)) = Classical.forall_intro_2 (decode_constint32le_injective' v) let parse_constint32le (v: nat { 0 <= v /\ v < 4294967296 } ) : Tot (parser parse_constint32le_kind (constint32 v)) = decode_constint32le_injective v; make_constant_size_parser 4 (constint32 v) (decode_constint32le v) let parse_constint32le_unfold (v: nat { 0 <= v /\ v < 4294967296 } ) (input: bytes) : Lemma (parse (parse_constint32le v) input == (let res = parse parse_int32le input in match res with | Some (x, consumed) -> if U32.v x = v && consumed = 4 then Some (x, consumed) else None | None -> None)) = let res = parse parse_int32le input in match res with | Some (x, consumed) -> if U32.v x = v && consumed = 4 then () else () | None -> () let serialize_constint32le' (v: nat { 0 <= v /\ v < 4294967296 } ) : Tot (bare_serializer (constint32 v)) = fun (x: constint32 v) -> let res = n_to_le 4 v in res
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Int32le.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.Base.fsti.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.ConstInt32.fst" }
[ { "abbrev": true, "full_module": "LowParse.Math", "short_module": "M" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Spec.Int32le", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Endianness", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
v: Prims.nat{0 <= v /\ v < 4294967296} -> FStar.Pervasives.Lemma (ensures LowParse.Spec.Base.serializer_correct (LowParse.Spec.ConstInt32.parse_constint32le v) (LowParse.Spec.ConstInt32.serialize_constint32le' v))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_LessThan", "FStar.Classical.forall_intro", "LowParse.Spec.ConstInt32.constint32", "Prims.eq2", "Prims.int", "Prims.l_or", "FStar.UInt.size", "FStar.UInt32.n", "Prims.op_GreaterThanOrEqual", "FStar.UInt32.v", "FStar.Seq.Base.length", "FStar.UInt8.t", "FStar.Endianness.n_to_le", "FStar.Pervasives.Native.option", "FStar.Pervasives.Native.tuple2", "LowParse.Spec.Base.consumed_length", "LowParse.Spec.Base.parse", "LowParse.Spec.ConstInt32.parse_constint32le", "FStar.Pervasives.Native.Some", "FStar.Pervasives.Native.Mktuple2", "Prims.unit", "Prims.l_True", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern", "FStar.Endianness.bytes", "FStar.Endianness.le_to_n", "LowParse.Spec.Base.serializer_correct", "LowParse.Spec.ConstInt32.parse_constint32le_kind", "LowParse.Spec.ConstInt32.serialize_constint32le'" ]
[]
false
false
true
false
false
let serialize_constint32le_correct (v: nat{0 <= v /\ v < 4294967296}) : Lemma (serializer_correct (parse_constint32le v) (serialize_constint32le' v)) =
let prf (x: constint32 v) : Lemma (let res = n_to_le 4 v in U32.v x == v /\ Seq.length res == 4 /\ (parse (parse_constint32le v) res == Some (x, 4))) = () in Classical.forall_intro prf
false