effect
stringclasses
48 values
original_source_type
stringlengths
0
23k
opens_and_abbrevs
listlengths
2
92
isa_cross_project_example
bool
1 class
source_definition
stringlengths
9
57.9k
partial_definition
stringlengths
7
23.3k
is_div
bool
2 classes
is_type
null
is_proof
bool
2 classes
completed_definiton
stringlengths
1
250k
dependencies
dict
effect_flags
sequencelengths
0
2
ideal_premises
sequencelengths
0
236
mutual_with
sequencelengths
0
11
file_context
stringlengths
0
407k
interleaved
bool
1 class
is_simply_typed
bool
2 classes
file_name
stringlengths
5
48
vconfig
dict
is_simple_lemma
null
source_type
stringlengths
10
23k
proof_features
sequencelengths
0
1
name
stringlengths
8
95
source
dict
verbose_type
stringlengths
1
7.42k
source_range
dict
Prims.Tot
val lookup (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b {mem key m}) : b
[ { "abbrev": true, "full_module": "FStar.FiniteSet.Base", "short_module": "FSet" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "FLT" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.FiniteMap", "short_module": null }, { "abbrev": false, "full_module": "FStar.FiniteMap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let lookup (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b{mem key m}) : b = Some?.v ((elements m) key)
val lookup (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b {mem key m}) : b let lookup (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b {mem key m}) : b =
false
null
false
Some?.v ((elements m) key)
{ "checked_file": "FStar.FiniteMap.Base.fsti.checked", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.FiniteSet.Base.fsti.checked" ], "interface_file": false, "source_file": "FStar.FiniteMap.Base.fsti" }
[ "total" ]
[ "Prims.eqtype", "FStar.FiniteMap.Base.map", "Prims.b2t", "FStar.FiniteMap.Base.mem", "FStar.Pervasives.Native.__proj__Some__item__v", "FStar.FiniteMap.Base.elements" ]
[]
(* Copyright 2008-2021 John Li, Jay Lorch, Rustan Leino, Alex Summers, Dan Rosen, Nikhil Swamy, Microsoft Research, and contributors to the Dafny Project 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. Includes material from the Dafny project (https://github.com/dafny-lang/dafny) which carries this license information: Created 9 February 2008 by Rustan Leino. Converted to Boogie 2 on 28 June 2008. Edited sequence axioms 20 October 2009 by Alex Summers. Modified 2014 by Dan Rosen. Copyright (c) 2008-2014, Microsoft. Copyright by the contributors to the Dafny Project SPDX-License-Identifier: MIT *) (** This module declares a type and functions used for modeling finite maps as they're modeled in Dafny. @summary Type and functions for modeling finite maps *) module FStar.FiniteMap.Base open FStar.FunctionalExtensionality module FLT = FStar.List.Tot module FSet = FStar.FiniteSet.Base type setfun_t (a: eqtype) (b: Type u#b) (s: FSet.set a) = f: (a ^-> option b){forall (key: a). FSet.mem key s == Some? (f key)} val map (a: eqtype) ([@@@ strictly_positive] b: Type u#b) : Type u#b (** We translate each Dafny sequence function prefixed with `Map#` into an F* function. **) /// We represent the Dafny function `Map#Domain` with `domain`: /// /// function Map#Domain<U,V>(Map U V) : Set U; val domain (#a: eqtype) (#b: Type u#b) (m: map a b) : FSet.set a /// We represent the Dafny function `Map#Elements` with `elements`: /// /// function Map#Elements<U,V>(Map U V) : [U]V; val elements (#a: eqtype) (#b: Type u#b) (m: map a b) : setfun_t a b (domain m) /// We represent the Dafny operator `in` on maps with `mem`: let mem (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b) = FSet.mem key (domain m) /// We can convert a map to a list of pairs with `map_as_list`: let rec key_in_item_list (#a: eqtype) (#b: Type u#b) (key: a) (items: list (a * b)) : bool = match items with | [] -> false | (k, v) :: tl -> key = k || key_in_item_list key tl let rec item_list_doesnt_repeat_keys (#a: eqtype) (#b: Type u#b) (items: list (a * b)) : bool = match items with | [] -> true | (k, v) :: tl -> not (key_in_item_list k tl) && item_list_doesnt_repeat_keys tl val map_as_list (#a: eqtype) (#b: Type u#b) (m: map a b) : GTot (items: list (a * b){item_list_doesnt_repeat_keys items /\ (forall key. key_in_item_list key items <==> mem key m)}) /// We represent the Dafny operator [] on maps with `lookup`: let lookup (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b{mem key m})
false
false
FStar.FiniteMap.Base.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val lookup (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b {mem key m}) : b
[]
FStar.FiniteMap.Base.lookup
{ "file_name": "ulib/FStar.FiniteMap.Base.fsti", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
key: a -> m: FStar.FiniteMap.Base.map a b {FStar.FiniteMap.Base.mem key m} -> b
{ "end_col": 28, "end_line": 94, "start_col": 2, "start_line": 94 }
Prims.Tot
[ { "abbrev": true, "full_module": "FStar.FiniteSet.Base", "short_module": "FSet" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "FLT" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.FiniteMap", "short_module": null }, { "abbrev": false, "full_module": "FStar.FiniteMap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let insert_member_cardinality_fact = forall (a: eqtype) (b: Type u#b) (m: map a b) (key: a) (value: b).{:pattern cardinality (insert key value m)} FSet.mem key (domain m) ==> cardinality (insert key value m) = cardinality m
let insert_member_cardinality_fact =
false
null
false
forall (a: eqtype) (b: Type u#b) (m: map a b) (key: a) (value: b). {:pattern cardinality (insert key value m)} FSet.mem key (domain m) ==> cardinality (insert key value m) = cardinality m
{ "checked_file": "FStar.FiniteMap.Base.fsti.checked", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.FiniteSet.Base.fsti.checked" ], "interface_file": false, "source_file": "FStar.FiniteMap.Base.fsti" }
[ "total" ]
[ "Prims.l_Forall", "Prims.eqtype", "FStar.FiniteMap.Base.map", "Prims.l_imp", "Prims.b2t", "FStar.FiniteSet.Base.mem", "FStar.FiniteMap.Base.domain", "Prims.op_Equality", "Prims.nat", "FStar.FiniteMap.Base.cardinality", "FStar.FiniteMap.Base.insert" ]
[]
(* Copyright 2008-2021 John Li, Jay Lorch, Rustan Leino, Alex Summers, Dan Rosen, Nikhil Swamy, Microsoft Research, and contributors to the Dafny Project 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. Includes material from the Dafny project (https://github.com/dafny-lang/dafny) which carries this license information: Created 9 February 2008 by Rustan Leino. Converted to Boogie 2 on 28 June 2008. Edited sequence axioms 20 October 2009 by Alex Summers. Modified 2014 by Dan Rosen. Copyright (c) 2008-2014, Microsoft. Copyright by the contributors to the Dafny Project SPDX-License-Identifier: MIT *) (** This module declares a type and functions used for modeling finite maps as they're modeled in Dafny. @summary Type and functions for modeling finite maps *) module FStar.FiniteMap.Base open FStar.FunctionalExtensionality module FLT = FStar.List.Tot module FSet = FStar.FiniteSet.Base type setfun_t (a: eqtype) (b: Type u#b) (s: FSet.set a) = f: (a ^-> option b){forall (key: a). FSet.mem key s == Some? (f key)} val map (a: eqtype) ([@@@ strictly_positive] b: Type u#b) : Type u#b (** We translate each Dafny sequence function prefixed with `Map#` into an F* function. **) /// We represent the Dafny function `Map#Domain` with `domain`: /// /// function Map#Domain<U,V>(Map U V) : Set U; val domain (#a: eqtype) (#b: Type u#b) (m: map a b) : FSet.set a /// We represent the Dafny function `Map#Elements` with `elements`: /// /// function Map#Elements<U,V>(Map U V) : [U]V; val elements (#a: eqtype) (#b: Type u#b) (m: map a b) : setfun_t a b (domain m) /// We represent the Dafny operator `in` on maps with `mem`: let mem (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b) = FSet.mem key (domain m) /// We can convert a map to a list of pairs with `map_as_list`: let rec key_in_item_list (#a: eqtype) (#b: Type u#b) (key: a) (items: list (a * b)) : bool = match items with | [] -> false | (k, v) :: tl -> key = k || key_in_item_list key tl let rec item_list_doesnt_repeat_keys (#a: eqtype) (#b: Type u#b) (items: list (a * b)) : bool = match items with | [] -> true | (k, v) :: tl -> not (key_in_item_list k tl) && item_list_doesnt_repeat_keys tl val map_as_list (#a: eqtype) (#b: Type u#b) (m: map a b) : GTot (items: list (a * b){item_list_doesnt_repeat_keys items /\ (forall key. key_in_item_list key items <==> mem key m)}) /// We represent the Dafny operator [] on maps with `lookup`: let lookup (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b{mem key m}) : b = Some?.v ((elements m) key) /// We represent the Dafny function `Map#Card` with `cardinality`: /// /// function Map#Card<U,V>(Map U V) : int; val cardinality (#a: eqtype) (#b: Type u#b) (m: map a b) : GTot nat /// We represent the Dafny function `Map#Values` with `values`: /// /// function Map#Values<U,V>(Map U V) : Set V; val values (#a: eqtype) (#b: Type u#b) (m: map a b) : GTot (b -> prop) /// We represent the Dafny function `Map#Items` with `items`: /// /// function Map#Items<U,V>(Map U V) : Set Box; val items (#a: eqtype) (#b: Type u#b) (m: map a b) : GTot ((a * b) -> prop) /// We represent the Dafny function `Map#Empty` with `emptymap`: /// /// function Map#Empty<U, V>(): Map U V; val emptymap (#a: eqtype) (#b: Type u#b) : map a b /// We represent the Dafny function `Map#Glue` with `glue`. /// /// function Map#Glue<U, V>([U]bool, [U]V, Ty): Map U V; val glue (#a: eqtype) (#b: Type u#b) (keys: FSet.set a) (f: setfun_t a b keys) : map a b /// We represent the Dafny function `Map#Build` with `insert`: /// /// function Map#Build<U, V>(Map U V, U, V): Map U V; val insert (#a: eqtype) (#b: Type u#b) (k: a) (v: b) (m: map a b) : map a b /// We represent the Dafny function `Map#Merge` with `merge`: /// /// function Map#Merge<U, V>(Map U V, Map U V): Map U V; val merge (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b) : map a b /// We represent the Dafny function `Map#Subtract` with `subtract`: /// /// function Map#Subtract<U, V>(Map U V, Set U): Map U V; val subtract (#a: eqtype) (#b: Type u#b) (m: map a b) (s: FSet.set a) : map a b /// We represent the Dafny function `Map#Equal` with `equal`: /// /// function Map#Equal<U, V>(Map U V, Map U V): bool; val equal (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b) : prop /// We represent the Dafny function `Map#Disjoint` with `disjoint`: /// /// function Map#Disjoint<U, V>(Map U V, Map U V): bool; val disjoint (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b) : prop /// We represent the Dafny choice operator by `choose`: /// /// var x: T :| x in s; val choose (#a: eqtype) (#b: Type u#b) (m: map a b{exists key. mem key m}) : GTot (key: a{mem key m}) /// We add the utility functions `remove` and `notin`: let remove (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b) : map a b = subtract m (FSet.singleton key) let notin (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b) : bool = not (mem key m) (** We translate each finite map axiom from the Dafny prelude into an F* predicate ending in `_fact`. **) /// We don't need the following axiom since we return a nat from cardinality: /// /// axiom (forall<U,V> m: Map U V :: { Map#Card(m) } 0 <= Map#Card(m)); /// We represent the following Dafny axiom with `cardinality_zero_iff_empty_fact`: /// /// axiom (forall<U, V> m: Map U V :: /// { Map#Card(m) } /// Map#Card(m) == 0 <==> m == Map#Empty()); let cardinality_zero_iff_empty_fact = forall (a: eqtype) (b:Type u#b) (m: map a b).{:pattern cardinality m} cardinality m = 0 <==> m == emptymap /// We represent the following Dafny axiom with `empty_or_domain_occupied_fact`: /// /// axiom (forall<U, V> m: Map U V :: /// { Map#Domain(m) } /// m == Map#Empty() || (exists k: U :: Map#Domain(m)[k])); let empty_or_domain_occupied_fact = forall (a: eqtype) (b: Type u#b) (m: map a b).{:pattern domain m} m == emptymap \/ (exists k.{:pattern mem k m} mem k m) /// We represent the following Dafny axiom with `empty_or_values_occupied_fact`: /// /// axiom (forall<U, V> m: Map U V :: /// { Map#Values(m) } /// m == Map#Empty() || (exists v: V :: Map#Values(m)[v])); let empty_or_values_occupied_fact = forall (a: eqtype) (b: Type u#b) (m: map a b).{:pattern values m} m == emptymap \/ (exists v. {:pattern values m v } (values m) v) /// We represent the following Dafny axiom with `empty_or_items_occupied_fact`: /// /// axiom (forall<U, V> m: Map U V :: /// { Map#Items(m) } /// m == Map#Empty() || (exists k, v: Box :: Map#Items(m)[$Box(#_System._tuple#2._#Make2(k, v))])); let empty_or_items_occupied_fact = forall (a: eqtype) (b:Type u#b) (m: map a b).{:pattern items m} m == emptymap \/ (exists item. {:pattern items m item } (items m) item) /// We represent the following Dafny axiom with `map_cardinality_matches_domain_fact`: /// /// axiom (forall<U, V> m: Map U V :: /// { Set#Card(Map#Domain(m)) } /// Set#Card(Map#Domain(m)) == Map#Card(m)); let map_cardinality_matches_domain_fact = forall (a: eqtype) (b: Type u#b) (m: map a b).{:pattern FSet.cardinality (domain m)} FSet.cardinality (domain m) = cardinality m /// We don't use the following Dafny axioms, which would require /// treating the values and items as finite sets, which we can't do /// because we want to allow non-eqtypes as values. /// /// axiom (forall<U, V> m: Map U V :: /// { Set#Card(Map#Values(m)) } /// Set#Card(Map#Values(m)) <= Map#Card(m)); /// axiom (forall<U, V> m: Map U V :: /// { Set#Card(Map#Items(m)) } /// Set#Card(Map#Items(m)) == Map#Card(m)); /// We represent the following Dafny axiom with `values_contains_fact`: /// /// axiom (forall<U,V> m: Map U V, v: V :: { Map#Values(m)[v] } /// Map#Values(m)[v] == /// (exists u: U :: { Map#Domain(m)[u] } { Map#Elements(m)[u] } /// Map#Domain(m)[u] && /// v == Map#Elements(m)[u])); let values_contains_fact = forall (a: eqtype) (b: Type u#b) (m: map a b) (v: b).{:pattern (values m) v} (values m) v <==> (exists (u: a).{:pattern FSet.mem u (domain m) \/ ((elements m) u)} FSet.mem u (domain m) /\ (elements m) u == Some v) /// We represent the following Dafny axiom with `items_contains_fact`: /// /// axiom (forall m: Map Box Box, item: Box :: { Map#Items(m)[item] } /// Map#Items(m)[item] <==> /// Map#Domain(m)[_System.Tuple2._0($Unbox(item))] && /// Map#Elements(m)[_System.Tuple2._0($Unbox(item))] == _System.Tuple2._1($Unbox(item))); let items_contains_fact = forall (a: eqtype) (b: Type u#b) (m: map a b) (item: a * b).{:pattern (items m) item} (items m) item <==> FSet.mem (fst item) (domain m) /\ (elements m) (fst item) == Some (snd item) /// We represent the following Dafny axiom with `empty_domain_empty_fact`: /// /// axiom (forall<U, V> u: U :: /// { Map#Domain(Map#Empty(): Map U V)[u] } /// !Map#Domain(Map#Empty(): Map U V)[u]); let empty_domain_empty_fact = forall (a: eqtype) (b: Type u#b) (u: a).{:pattern FSet.mem u (domain (emptymap #a #b))} not (FSet.mem u (domain (emptymap #a #b))) /// We represent the following Dafny axiom with `glue_domain_fact`: /// /// axiom (forall<U, V> a: [U]bool, b: [U]V, t: Ty :: /// { Map#Domain(Map#Glue(a, b, t)) } /// Map#Domain(Map#Glue(a, b, t)) == a); let glue_domain_fact = forall (a: eqtype) (b: Type u#b) (keys: FSet.set a) (f: setfun_t a b keys).{:pattern domain (glue keys f)} domain (glue keys f) == keys /// We represent the following Dafny axiom with `glue_elements_fact`. /// But we have to change it because our version of `Map#Elements` /// returns a map to an optional value. /// /// axiom (forall<U, V> a: [U]bool, b: [U]V, t: Ty :: /// { Map#Elements(Map#Glue(a, b, t)) } /// Map#Elements(Map#Glue(a, b, t)) == b); let glue_elements_fact = forall (a: eqtype) (b: Type u#b) (keys: FSet.set a) (f: setfun_t a b keys).{:pattern elements (glue keys f)} domain (glue keys f) == keys /\ elements (glue keys f) == f /// We don't need the following Dafny axiom since the type of `glue` implies it: /// /// axiom (forall a: [Box]bool, b: [Box]Box, t0, t1: Ty :: /// { Map#Glue(a, b, TMap(t0, t1)) } /// // In the following line, no trigger needed, since the quantifier only gets used in negative contexts /// (forall bx: Box :: a[bx] ==> $IsBox(bx, t0) && $IsBox(b[bx], t1)) /// ==> /// $Is(Map#Glue(a, b, TMap(t0, t1)), TMap(t0, t1))); /// We represent the following Dafny axiom with `insert_elements_fact`: /// /// axiom (forall<U, V> m: Map U V, u: U, u': U, v: V :: /// { Map#Domain(Map#Build(m, u, v))[u'] } { Map#Elements(Map#Build(m, u, v))[u'] } /// (u' == u ==> Map#Domain(Map#Build(m, u, v))[u'] && /// Map#Elements(Map#Build(m, u, v))[u'] == v) && /// (u' != u ==> Map#Domain(Map#Build(m, u, v))[u'] == Map#Domain(m)[u'] && /// Map#Elements(Map#Build(m, u, v))[u'] == Map#Elements(m)[u'])); let insert_elements_fact = forall (a: eqtype) (b: Type u#b) (m: map a b) (key: a) (key': a) (value: b). {:pattern FSet.mem key' (domain (insert key value m)) \/ ((elements (insert key value m)) key')} (key' = key ==> FSet.mem key' (domain (insert key value m)) /\ (elements (insert key value m)) key' == Some value) /\ (key' <> key ==> FSet.mem key' (domain (insert key value m)) = FSet.mem key' (domain m) /\ (elements (insert key value m)) key' == (elements m) key') /// We represent the following Dafny axiom with `insert_member_cardinality_fact`: /// /// axiom (forall<U, V> m: Map U V, u: U, v: V :: { Map#Card(Map#Build(m, u, v)) } /// Map#Domain(m)[u] ==> Map#Card(Map#Build(m, u, v)) == Map#Card(m));
false
true
FStar.FiniteMap.Base.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val insert_member_cardinality_fact : Prims.logical
[]
FStar.FiniteMap.Base.insert_member_cardinality_fact
{ "file_name": "ulib/FStar.FiniteMap.Base.fsti", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
Prims.logical
{ "end_col": 80, "end_line": 346, "start_col": 2, "start_line": 345 }
Prims.Tot
[ { "abbrev": true, "full_module": "FStar.FiniteSet.Base", "short_module": "FSet" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "FLT" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.FiniteMap", "short_module": null }, { "abbrev": false, "full_module": "FStar.FiniteMap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let map_cardinality_matches_domain_fact = forall (a: eqtype) (b: Type u#b) (m: map a b).{:pattern FSet.cardinality (domain m)} FSet.cardinality (domain m) = cardinality m
let map_cardinality_matches_domain_fact =
false
null
false
forall (a: eqtype) (b: Type u#b) (m: map a b). {:pattern FSet.cardinality (domain m)} FSet.cardinality (domain m) = cardinality m
{ "checked_file": "FStar.FiniteMap.Base.fsti.checked", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.FiniteSet.Base.fsti.checked" ], "interface_file": false, "source_file": "FStar.FiniteMap.Base.fsti" }
[ "total" ]
[ "Prims.l_Forall", "Prims.eqtype", "FStar.FiniteMap.Base.map", "Prims.b2t", "Prims.op_Equality", "Prims.nat", "FStar.FiniteSet.Base.cardinality", "FStar.FiniteMap.Base.domain", "FStar.FiniteMap.Base.cardinality" ]
[]
(* Copyright 2008-2021 John Li, Jay Lorch, Rustan Leino, Alex Summers, Dan Rosen, Nikhil Swamy, Microsoft Research, and contributors to the Dafny Project 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. Includes material from the Dafny project (https://github.com/dafny-lang/dafny) which carries this license information: Created 9 February 2008 by Rustan Leino. Converted to Boogie 2 on 28 June 2008. Edited sequence axioms 20 October 2009 by Alex Summers. Modified 2014 by Dan Rosen. Copyright (c) 2008-2014, Microsoft. Copyright by the contributors to the Dafny Project SPDX-License-Identifier: MIT *) (** This module declares a type and functions used for modeling finite maps as they're modeled in Dafny. @summary Type and functions for modeling finite maps *) module FStar.FiniteMap.Base open FStar.FunctionalExtensionality module FLT = FStar.List.Tot module FSet = FStar.FiniteSet.Base type setfun_t (a: eqtype) (b: Type u#b) (s: FSet.set a) = f: (a ^-> option b){forall (key: a). FSet.mem key s == Some? (f key)} val map (a: eqtype) ([@@@ strictly_positive] b: Type u#b) : Type u#b (** We translate each Dafny sequence function prefixed with `Map#` into an F* function. **) /// We represent the Dafny function `Map#Domain` with `domain`: /// /// function Map#Domain<U,V>(Map U V) : Set U; val domain (#a: eqtype) (#b: Type u#b) (m: map a b) : FSet.set a /// We represent the Dafny function `Map#Elements` with `elements`: /// /// function Map#Elements<U,V>(Map U V) : [U]V; val elements (#a: eqtype) (#b: Type u#b) (m: map a b) : setfun_t a b (domain m) /// We represent the Dafny operator `in` on maps with `mem`: let mem (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b) = FSet.mem key (domain m) /// We can convert a map to a list of pairs with `map_as_list`: let rec key_in_item_list (#a: eqtype) (#b: Type u#b) (key: a) (items: list (a * b)) : bool = match items with | [] -> false | (k, v) :: tl -> key = k || key_in_item_list key tl let rec item_list_doesnt_repeat_keys (#a: eqtype) (#b: Type u#b) (items: list (a * b)) : bool = match items with | [] -> true | (k, v) :: tl -> not (key_in_item_list k tl) && item_list_doesnt_repeat_keys tl val map_as_list (#a: eqtype) (#b: Type u#b) (m: map a b) : GTot (items: list (a * b){item_list_doesnt_repeat_keys items /\ (forall key. key_in_item_list key items <==> mem key m)}) /// We represent the Dafny operator [] on maps with `lookup`: let lookup (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b{mem key m}) : b = Some?.v ((elements m) key) /// We represent the Dafny function `Map#Card` with `cardinality`: /// /// function Map#Card<U,V>(Map U V) : int; val cardinality (#a: eqtype) (#b: Type u#b) (m: map a b) : GTot nat /// We represent the Dafny function `Map#Values` with `values`: /// /// function Map#Values<U,V>(Map U V) : Set V; val values (#a: eqtype) (#b: Type u#b) (m: map a b) : GTot (b -> prop) /// We represent the Dafny function `Map#Items` with `items`: /// /// function Map#Items<U,V>(Map U V) : Set Box; val items (#a: eqtype) (#b: Type u#b) (m: map a b) : GTot ((a * b) -> prop) /// We represent the Dafny function `Map#Empty` with `emptymap`: /// /// function Map#Empty<U, V>(): Map U V; val emptymap (#a: eqtype) (#b: Type u#b) : map a b /// We represent the Dafny function `Map#Glue` with `glue`. /// /// function Map#Glue<U, V>([U]bool, [U]V, Ty): Map U V; val glue (#a: eqtype) (#b: Type u#b) (keys: FSet.set a) (f: setfun_t a b keys) : map a b /// We represent the Dafny function `Map#Build` with `insert`: /// /// function Map#Build<U, V>(Map U V, U, V): Map U V; val insert (#a: eqtype) (#b: Type u#b) (k: a) (v: b) (m: map a b) : map a b /// We represent the Dafny function `Map#Merge` with `merge`: /// /// function Map#Merge<U, V>(Map U V, Map U V): Map U V; val merge (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b) : map a b /// We represent the Dafny function `Map#Subtract` with `subtract`: /// /// function Map#Subtract<U, V>(Map U V, Set U): Map U V; val subtract (#a: eqtype) (#b: Type u#b) (m: map a b) (s: FSet.set a) : map a b /// We represent the Dafny function `Map#Equal` with `equal`: /// /// function Map#Equal<U, V>(Map U V, Map U V): bool; val equal (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b) : prop /// We represent the Dafny function `Map#Disjoint` with `disjoint`: /// /// function Map#Disjoint<U, V>(Map U V, Map U V): bool; val disjoint (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b) : prop /// We represent the Dafny choice operator by `choose`: /// /// var x: T :| x in s; val choose (#a: eqtype) (#b: Type u#b) (m: map a b{exists key. mem key m}) : GTot (key: a{mem key m}) /// We add the utility functions `remove` and `notin`: let remove (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b) : map a b = subtract m (FSet.singleton key) let notin (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b) : bool = not (mem key m) (** We translate each finite map axiom from the Dafny prelude into an F* predicate ending in `_fact`. **) /// We don't need the following axiom since we return a nat from cardinality: /// /// axiom (forall<U,V> m: Map U V :: { Map#Card(m) } 0 <= Map#Card(m)); /// We represent the following Dafny axiom with `cardinality_zero_iff_empty_fact`: /// /// axiom (forall<U, V> m: Map U V :: /// { Map#Card(m) } /// Map#Card(m) == 0 <==> m == Map#Empty()); let cardinality_zero_iff_empty_fact = forall (a: eqtype) (b:Type u#b) (m: map a b).{:pattern cardinality m} cardinality m = 0 <==> m == emptymap /// We represent the following Dafny axiom with `empty_or_domain_occupied_fact`: /// /// axiom (forall<U, V> m: Map U V :: /// { Map#Domain(m) } /// m == Map#Empty() || (exists k: U :: Map#Domain(m)[k])); let empty_or_domain_occupied_fact = forall (a: eqtype) (b: Type u#b) (m: map a b).{:pattern domain m} m == emptymap \/ (exists k.{:pattern mem k m} mem k m) /// We represent the following Dafny axiom with `empty_or_values_occupied_fact`: /// /// axiom (forall<U, V> m: Map U V :: /// { Map#Values(m) } /// m == Map#Empty() || (exists v: V :: Map#Values(m)[v])); let empty_or_values_occupied_fact = forall (a: eqtype) (b: Type u#b) (m: map a b).{:pattern values m} m == emptymap \/ (exists v. {:pattern values m v } (values m) v) /// We represent the following Dafny axiom with `empty_or_items_occupied_fact`: /// /// axiom (forall<U, V> m: Map U V :: /// { Map#Items(m) } /// m == Map#Empty() || (exists k, v: Box :: Map#Items(m)[$Box(#_System._tuple#2._#Make2(k, v))])); let empty_or_items_occupied_fact = forall (a: eqtype) (b:Type u#b) (m: map a b).{:pattern items m} m == emptymap \/ (exists item. {:pattern items m item } (items m) item) /// We represent the following Dafny axiom with `map_cardinality_matches_domain_fact`: /// /// axiom (forall<U, V> m: Map U V :: /// { Set#Card(Map#Domain(m)) } /// Set#Card(Map#Domain(m)) == Map#Card(m));
false
true
FStar.FiniteMap.Base.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val map_cardinality_matches_domain_fact : Prims.logical
[]
FStar.FiniteMap.Base.map_cardinality_matches_domain_fact
{ "file_name": "ulib/FStar.FiniteMap.Base.fsti", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
Prims.logical
{ "end_col": 47, "end_line": 240, "start_col": 2, "start_line": 239 }
Prims.Tot
[ { "abbrev": true, "full_module": "FStar.FiniteSet.Base", "short_module": "FSet" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "FLT" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.FiniteMap", "short_module": null }, { "abbrev": false, "full_module": "FStar.FiniteMap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let glue_elements_fact = forall (a: eqtype) (b: Type u#b) (keys: FSet.set a) (f: setfun_t a b keys).{:pattern elements (glue keys f)} domain (glue keys f) == keys /\ elements (glue keys f) == f
let glue_elements_fact =
false
null
false
forall (a: eqtype) (b: Type u#b) (keys: FSet.set a) (f: setfun_t a b keys). {:pattern elements (glue keys f)} domain (glue keys f) == keys /\ elements (glue keys f) == f
{ "checked_file": "FStar.FiniteMap.Base.fsti.checked", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.FiniteSet.Base.fsti.checked" ], "interface_file": false, "source_file": "FStar.FiniteMap.Base.fsti" }
[ "total" ]
[ "Prims.l_Forall", "Prims.eqtype", "FStar.FiniteSet.Base.set", "FStar.FiniteMap.Base.setfun_t", "Prims.l_and", "Prims.eq2", "FStar.FiniteMap.Base.domain", "FStar.FiniteMap.Base.glue", "FStar.FunctionalExtensionality.op_Hat_Subtraction_Greater", "FStar.Pervasives.Native.option", "Prims.l_or", "Prims.bool", "FStar.FiniteSet.Base.mem", "FStar.Pervasives.Native.uu___is_Some", "FStar.FiniteMap.Base.elements" ]
[]
(* Copyright 2008-2021 John Li, Jay Lorch, Rustan Leino, Alex Summers, Dan Rosen, Nikhil Swamy, Microsoft Research, and contributors to the Dafny Project 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. Includes material from the Dafny project (https://github.com/dafny-lang/dafny) which carries this license information: Created 9 February 2008 by Rustan Leino. Converted to Boogie 2 on 28 June 2008. Edited sequence axioms 20 October 2009 by Alex Summers. Modified 2014 by Dan Rosen. Copyright (c) 2008-2014, Microsoft. Copyright by the contributors to the Dafny Project SPDX-License-Identifier: MIT *) (** This module declares a type and functions used for modeling finite maps as they're modeled in Dafny. @summary Type and functions for modeling finite maps *) module FStar.FiniteMap.Base open FStar.FunctionalExtensionality module FLT = FStar.List.Tot module FSet = FStar.FiniteSet.Base type setfun_t (a: eqtype) (b: Type u#b) (s: FSet.set a) = f: (a ^-> option b){forall (key: a). FSet.mem key s == Some? (f key)} val map (a: eqtype) ([@@@ strictly_positive] b: Type u#b) : Type u#b (** We translate each Dafny sequence function prefixed with `Map#` into an F* function. **) /// We represent the Dafny function `Map#Domain` with `domain`: /// /// function Map#Domain<U,V>(Map U V) : Set U; val domain (#a: eqtype) (#b: Type u#b) (m: map a b) : FSet.set a /// We represent the Dafny function `Map#Elements` with `elements`: /// /// function Map#Elements<U,V>(Map U V) : [U]V; val elements (#a: eqtype) (#b: Type u#b) (m: map a b) : setfun_t a b (domain m) /// We represent the Dafny operator `in` on maps with `mem`: let mem (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b) = FSet.mem key (domain m) /// We can convert a map to a list of pairs with `map_as_list`: let rec key_in_item_list (#a: eqtype) (#b: Type u#b) (key: a) (items: list (a * b)) : bool = match items with | [] -> false | (k, v) :: tl -> key = k || key_in_item_list key tl let rec item_list_doesnt_repeat_keys (#a: eqtype) (#b: Type u#b) (items: list (a * b)) : bool = match items with | [] -> true | (k, v) :: tl -> not (key_in_item_list k tl) && item_list_doesnt_repeat_keys tl val map_as_list (#a: eqtype) (#b: Type u#b) (m: map a b) : GTot (items: list (a * b){item_list_doesnt_repeat_keys items /\ (forall key. key_in_item_list key items <==> mem key m)}) /// We represent the Dafny operator [] on maps with `lookup`: let lookup (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b{mem key m}) : b = Some?.v ((elements m) key) /// We represent the Dafny function `Map#Card` with `cardinality`: /// /// function Map#Card<U,V>(Map U V) : int; val cardinality (#a: eqtype) (#b: Type u#b) (m: map a b) : GTot nat /// We represent the Dafny function `Map#Values` with `values`: /// /// function Map#Values<U,V>(Map U V) : Set V; val values (#a: eqtype) (#b: Type u#b) (m: map a b) : GTot (b -> prop) /// We represent the Dafny function `Map#Items` with `items`: /// /// function Map#Items<U,V>(Map U V) : Set Box; val items (#a: eqtype) (#b: Type u#b) (m: map a b) : GTot ((a * b) -> prop) /// We represent the Dafny function `Map#Empty` with `emptymap`: /// /// function Map#Empty<U, V>(): Map U V; val emptymap (#a: eqtype) (#b: Type u#b) : map a b /// We represent the Dafny function `Map#Glue` with `glue`. /// /// function Map#Glue<U, V>([U]bool, [U]V, Ty): Map U V; val glue (#a: eqtype) (#b: Type u#b) (keys: FSet.set a) (f: setfun_t a b keys) : map a b /// We represent the Dafny function `Map#Build` with `insert`: /// /// function Map#Build<U, V>(Map U V, U, V): Map U V; val insert (#a: eqtype) (#b: Type u#b) (k: a) (v: b) (m: map a b) : map a b /// We represent the Dafny function `Map#Merge` with `merge`: /// /// function Map#Merge<U, V>(Map U V, Map U V): Map U V; val merge (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b) : map a b /// We represent the Dafny function `Map#Subtract` with `subtract`: /// /// function Map#Subtract<U, V>(Map U V, Set U): Map U V; val subtract (#a: eqtype) (#b: Type u#b) (m: map a b) (s: FSet.set a) : map a b /// We represent the Dafny function `Map#Equal` with `equal`: /// /// function Map#Equal<U, V>(Map U V, Map U V): bool; val equal (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b) : prop /// We represent the Dafny function `Map#Disjoint` with `disjoint`: /// /// function Map#Disjoint<U, V>(Map U V, Map U V): bool; val disjoint (#a: eqtype) (#b: Type u#b) (m1: map a b) (m2: map a b) : prop /// We represent the Dafny choice operator by `choose`: /// /// var x: T :| x in s; val choose (#a: eqtype) (#b: Type u#b) (m: map a b{exists key. mem key m}) : GTot (key: a{mem key m}) /// We add the utility functions `remove` and `notin`: let remove (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b) : map a b = subtract m (FSet.singleton key) let notin (#a: eqtype) (#b: Type u#b) (key: a) (m: map a b) : bool = not (mem key m) (** We translate each finite map axiom from the Dafny prelude into an F* predicate ending in `_fact`. **) /// We don't need the following axiom since we return a nat from cardinality: /// /// axiom (forall<U,V> m: Map U V :: { Map#Card(m) } 0 <= Map#Card(m)); /// We represent the following Dafny axiom with `cardinality_zero_iff_empty_fact`: /// /// axiom (forall<U, V> m: Map U V :: /// { Map#Card(m) } /// Map#Card(m) == 0 <==> m == Map#Empty()); let cardinality_zero_iff_empty_fact = forall (a: eqtype) (b:Type u#b) (m: map a b).{:pattern cardinality m} cardinality m = 0 <==> m == emptymap /// We represent the following Dafny axiom with `empty_or_domain_occupied_fact`: /// /// axiom (forall<U, V> m: Map U V :: /// { Map#Domain(m) } /// m == Map#Empty() || (exists k: U :: Map#Domain(m)[k])); let empty_or_domain_occupied_fact = forall (a: eqtype) (b: Type u#b) (m: map a b).{:pattern domain m} m == emptymap \/ (exists k.{:pattern mem k m} mem k m) /// We represent the following Dafny axiom with `empty_or_values_occupied_fact`: /// /// axiom (forall<U, V> m: Map U V :: /// { Map#Values(m) } /// m == Map#Empty() || (exists v: V :: Map#Values(m)[v])); let empty_or_values_occupied_fact = forall (a: eqtype) (b: Type u#b) (m: map a b).{:pattern values m} m == emptymap \/ (exists v. {:pattern values m v } (values m) v) /// We represent the following Dafny axiom with `empty_or_items_occupied_fact`: /// /// axiom (forall<U, V> m: Map U V :: /// { Map#Items(m) } /// m == Map#Empty() || (exists k, v: Box :: Map#Items(m)[$Box(#_System._tuple#2._#Make2(k, v))])); let empty_or_items_occupied_fact = forall (a: eqtype) (b:Type u#b) (m: map a b).{:pattern items m} m == emptymap \/ (exists item. {:pattern items m item } (items m) item) /// We represent the following Dafny axiom with `map_cardinality_matches_domain_fact`: /// /// axiom (forall<U, V> m: Map U V :: /// { Set#Card(Map#Domain(m)) } /// Set#Card(Map#Domain(m)) == Map#Card(m)); let map_cardinality_matches_domain_fact = forall (a: eqtype) (b: Type u#b) (m: map a b).{:pattern FSet.cardinality (domain m)} FSet.cardinality (domain m) = cardinality m /// We don't use the following Dafny axioms, which would require /// treating the values and items as finite sets, which we can't do /// because we want to allow non-eqtypes as values. /// /// axiom (forall<U, V> m: Map U V :: /// { Set#Card(Map#Values(m)) } /// Set#Card(Map#Values(m)) <= Map#Card(m)); /// axiom (forall<U, V> m: Map U V :: /// { Set#Card(Map#Items(m)) } /// Set#Card(Map#Items(m)) == Map#Card(m)); /// We represent the following Dafny axiom with `values_contains_fact`: /// /// axiom (forall<U,V> m: Map U V, v: V :: { Map#Values(m)[v] } /// Map#Values(m)[v] == /// (exists u: U :: { Map#Domain(m)[u] } { Map#Elements(m)[u] } /// Map#Domain(m)[u] && /// v == Map#Elements(m)[u])); let values_contains_fact = forall (a: eqtype) (b: Type u#b) (m: map a b) (v: b).{:pattern (values m) v} (values m) v <==> (exists (u: a).{:pattern FSet.mem u (domain m) \/ ((elements m) u)} FSet.mem u (domain m) /\ (elements m) u == Some v) /// We represent the following Dafny axiom with `items_contains_fact`: /// /// axiom (forall m: Map Box Box, item: Box :: { Map#Items(m)[item] } /// Map#Items(m)[item] <==> /// Map#Domain(m)[_System.Tuple2._0($Unbox(item))] && /// Map#Elements(m)[_System.Tuple2._0($Unbox(item))] == _System.Tuple2._1($Unbox(item))); let items_contains_fact = forall (a: eqtype) (b: Type u#b) (m: map a b) (item: a * b).{:pattern (items m) item} (items m) item <==> FSet.mem (fst item) (domain m) /\ (elements m) (fst item) == Some (snd item) /// We represent the following Dafny axiom with `empty_domain_empty_fact`: /// /// axiom (forall<U, V> u: U :: /// { Map#Domain(Map#Empty(): Map U V)[u] } /// !Map#Domain(Map#Empty(): Map U V)[u]); let empty_domain_empty_fact = forall (a: eqtype) (b: Type u#b) (u: a).{:pattern FSet.mem u (domain (emptymap #a #b))} not (FSet.mem u (domain (emptymap #a #b))) /// We represent the following Dafny axiom with `glue_domain_fact`: /// /// axiom (forall<U, V> a: [U]bool, b: [U]V, t: Ty :: /// { Map#Domain(Map#Glue(a, b, t)) } /// Map#Domain(Map#Glue(a, b, t)) == a); let glue_domain_fact = forall (a: eqtype) (b: Type u#b) (keys: FSet.set a) (f: setfun_t a b keys).{:pattern domain (glue keys f)} domain (glue keys f) == keys /// We represent the following Dafny axiom with `glue_elements_fact`. /// But we have to change it because our version of `Map#Elements` /// returns a map to an optional value. /// /// axiom (forall<U, V> a: [U]bool, b: [U]V, t: Ty :: /// { Map#Elements(Map#Glue(a, b, t)) } /// Map#Elements(Map#Glue(a, b, t)) == b);
false
true
FStar.FiniteMap.Base.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val glue_elements_fact : Prims.logical
[]
FStar.FiniteMap.Base.glue_elements_fact
{ "file_name": "ulib/FStar.FiniteMap.Base.fsti", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
Prims.logical
{ "end_col": 34, "end_line": 311, "start_col": 2, "start_line": 309 }
FStar.Pervasives.Lemma
val emp_unit (p: vprop) : Lemma (((p `star` emp) `equiv` p) /\ ((emp `star` p) `equiv` p)) [SMTPatOr [[SMTPat (p `star` emp)]; [SMTPat (emp `star` p)]]]
[ { "abbrev": false, "full_module": "Steel.Reference", "short_module": null }, { "abbrev": false, "full_module": "Steel.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect.Atomic", "short_module": null }, { "abbrev": false, "full_module": "Steel.Memory", "short_module": null }, { "abbrev": false, "full_module": "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 } ]
false
let emp_unit (p:vprop) : Lemma (((p `star` emp) `equiv` p) /\ ((emp `star` p) `equiv` p)) [SMTPatOr [[SMTPat (p `star` emp)]; [SMTPat (emp `star` p)]]] = reveal_equiv (p `star` emp) p; reveal_equiv (emp `star` p) p; reveal_emp (); Steel.Memory.emp_unit (hp_of p); Steel.Memory.star_commutative Steel.Memory.emp (hp_of p)
val emp_unit (p: vprop) : Lemma (((p `star` emp) `equiv` p) /\ ((emp `star` p) `equiv` p)) [SMTPatOr [[SMTPat (p `star` emp)]; [SMTPat (emp `star` p)]]] let emp_unit (p: vprop) : Lemma (((p `star` emp) `equiv` p) /\ ((emp `star` p) `equiv` p)) [SMTPatOr [[SMTPat (p `star` emp)]; [SMTPat (emp `star` p)]]] =
false
null
true
reveal_equiv (p `star` emp) p; reveal_equiv (emp `star` p) p; reveal_emp (); Steel.Memory.emp_unit (hp_of p); Steel.Memory.star_commutative Steel.Memory.emp (hp_of p)
{ "checked_file": "Steel.Utils.fst.checked", "dependencies": [ "Steel.Reference.fsti.checked", "Steel.Memory.fsti.checked", "Steel.FractionalPermission.fst.checked", "Steel.Effect.Atomic.fsti.checked", "Steel.Effect.fsti.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Steel.Utils.fst" }
[ "lemma" ]
[ "Steel.Effect.Common.vprop", "Steel.Memory.star_commutative", "Steel.Memory.emp", "Steel.Effect.Common.hp_of", "Prims.unit", "Steel.Memory.emp_unit", "Steel.Effect.Common.reveal_emp", "Steel.Effect.Common.reveal_equiv", "Steel.Effect.Common.star", "Steel.Effect.Common.emp", "Prims.l_True", "Prims.squash", "Prims.l_and", "Steel.Effect.Common.equiv", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat_or", "Prims.list", "FStar.Pervasives.smt_pat", "Prims.Nil" ]
[]
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Utils open Steel.Memory open Steel.Effect.Atomic open Steel.Effect open Steel.FractionalPermission open Steel.Reference let pts_to_not_null (#a:Type) (#opened:inames) (#p:perm) (#v:FStar.Ghost.erased a) (r:ref a) : SteelGhost unit opened (pts_to r p v) (fun _ -> pts_to r p v) (fun _ -> True) (fun _ _ _ -> r =!= null) = extract_info_raw (pts_to r p v) (r =!= null) (fun m -> pts_to_not_null r p v m) let change_slprop_ens (p:vprop) (q:vprop) (r:prop) (f:(m:mem -> Lemma (requires interp (hp_of p) m) (ensures interp (hp_of q) m /\ r))) : Steel unit p (fun _ -> q) (requires fun _ -> True) (ensures fun _ _ _ -> r) = rewrite_slprop p (q `star` pure r) (fun m -> f m; Steel.Memory.emp_unit (hp_of q); Steel.Memory.pure_star_interp (hp_of q) r m); elim_pure r let pure_as_ens (#p:prop) () : Steel unit (pure p) (fun _ -> pure p) (fun _ -> True) (fun _ _ _ -> p) = change_slprop_ens (pure p) (pure p) p (Steel.Memory.pure_interp p) let rewrite #a (#p:a -> vprop) (x y:a) : Steel unit (p x) (fun _ -> p y) (requires fun _ -> x == y) (ensures fun _ _ _ -> True) = rewrite_slprop (p x) (p y) (fun _ -> ()) let extract_pure (p:prop) : Steel unit (pure p) (fun _ -> pure p) (fun _ -> True) (fun _ _ _ -> p) = elim_pure p; intro_pure p let dup_pure (p:prop) : SteelT unit (pure p) (fun _ -> pure p `star` pure p) = extract_pure p; intro_pure p let emp_unit (p:vprop) : Lemma (((p `star` emp) `equiv` p) /\ ((emp `star` p) `equiv` p)) [SMTPatOr [[SMTPat (p `star` emp)];
false
false
Steel.Utils.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val emp_unit (p: vprop) : Lemma (((p `star` emp) `equiv` p) /\ ((emp `star` p) `equiv` p)) [SMTPatOr [[SMTPat (p `star` emp)]; [SMTPat (emp `star` p)]]]
[]
Steel.Utils.emp_unit
{ "file_name": "lib/steel/Steel.Utils.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
p: Steel.Effect.Common.vprop -> FStar.Pervasives.Lemma (ensures Steel.Effect.Common.equiv (Steel.Effect.Common.star p Steel.Effect.Common.emp) p /\ Steel.Effect.Common.equiv (Steel.Effect.Common.star Steel.Effect.Common.emp p) p) [ SMTPatOr [ [SMTPat (Steel.Effect.Common.star p Steel.Effect.Common.emp)]; [SMTPat (Steel.Effect.Common.star Steel.Effect.Common.emp p)] ] ]
{ "end_col": 60, "end_line": 75, "start_col": 4, "start_line": 71 }
Steel.Effect.Steel
val pure_as_ens: #p: prop -> Prims.unit -> Steel unit (pure p) (fun _ -> pure p) (fun _ -> True) (fun _ _ _ -> p)
[ { "abbrev": false, "full_module": "Steel.Reference", "short_module": null }, { "abbrev": false, "full_module": "Steel.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect.Atomic", "short_module": null }, { "abbrev": false, "full_module": "Steel.Memory", "short_module": null }, { "abbrev": false, "full_module": "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 } ]
false
let pure_as_ens (#p:prop) () : Steel unit (pure p) (fun _ -> pure p) (fun _ -> True) (fun _ _ _ -> p) = change_slprop_ens (pure p) (pure p) p (Steel.Memory.pure_interp p)
val pure_as_ens: #p: prop -> Prims.unit -> Steel unit (pure p) (fun _ -> pure p) (fun _ -> True) (fun _ _ _ -> p) let pure_as_ens (#p: prop) () : Steel unit (pure p) (fun _ -> pure p) (fun _ -> True) (fun _ _ _ -> p) =
true
null
false
change_slprop_ens (pure p) (pure p) p (Steel.Memory.pure_interp p)
{ "checked_file": "Steel.Utils.fst.checked", "dependencies": [ "Steel.Reference.fsti.checked", "Steel.Memory.fsti.checked", "Steel.FractionalPermission.fst.checked", "Steel.Effect.Atomic.fsti.checked", "Steel.Effect.fsti.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Steel.Utils.fst" }
[]
[ "Prims.prop", "Prims.unit", "Steel.Utils.change_slprop_ens", "Steel.Effect.Common.pure", "Steel.Memory.pure_interp", "Steel.Effect.Common.vprop", "Steel.Effect.Common.rmem", "Prims.l_True" ]
[]
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Utils open Steel.Memory open Steel.Effect.Atomic open Steel.Effect open Steel.FractionalPermission open Steel.Reference let pts_to_not_null (#a:Type) (#opened:inames) (#p:perm) (#v:FStar.Ghost.erased a) (r:ref a) : SteelGhost unit opened (pts_to r p v) (fun _ -> pts_to r p v) (fun _ -> True) (fun _ _ _ -> r =!= null) = extract_info_raw (pts_to r p v) (r =!= null) (fun m -> pts_to_not_null r p v m) let change_slprop_ens (p:vprop) (q:vprop) (r:prop) (f:(m:mem -> Lemma (requires interp (hp_of p) m) (ensures interp (hp_of q) m /\ r))) : Steel unit p (fun _ -> q) (requires fun _ -> True) (ensures fun _ _ _ -> r) = rewrite_slprop p (q `star` pure r) (fun m -> f m; Steel.Memory.emp_unit (hp_of q); Steel.Memory.pure_star_interp (hp_of q) r m); elim_pure r let pure_as_ens (#p:prop) ()
false
false
Steel.Utils.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val pure_as_ens: #p: prop -> Prims.unit -> Steel unit (pure p) (fun _ -> pure p) (fun _ -> True) (fun _ _ _ -> p)
[]
Steel.Utils.pure_as_ens
{ "file_name": "lib/steel/Steel.Utils.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
_: Prims.unit -> Steel.Effect.Steel Prims.unit
{ "end_col": 70, "end_line": 48, "start_col": 4, "start_line": 48 }
Steel.Effect.Steel
val rewrite (#a: _) (#p: (a -> vprop)) (x y: a) : Steel unit (p x) (fun _ -> p y) (requires fun _ -> x == y) (ensures fun _ _ _ -> True)
[ { "abbrev": false, "full_module": "Steel.Reference", "short_module": null }, { "abbrev": false, "full_module": "Steel.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect.Atomic", "short_module": null }, { "abbrev": false, "full_module": "Steel.Memory", "short_module": null }, { "abbrev": false, "full_module": "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 } ]
false
let rewrite #a (#p:a -> vprop) (x y:a) : Steel unit (p x) (fun _ -> p y) (requires fun _ -> x == y) (ensures fun _ _ _ -> True) = rewrite_slprop (p x) (p y) (fun _ -> ())
val rewrite (#a: _) (#p: (a -> vprop)) (x y: a) : Steel unit (p x) (fun _ -> p y) (requires fun _ -> x == y) (ensures fun _ _ _ -> True) let rewrite #a (#p: (a -> vprop)) (x: a) (y: a) : Steel unit (p x) (fun _ -> p y) (requires fun _ -> x == y) (ensures fun _ _ _ -> True) =
true
null
false
rewrite_slprop (p x) (p y) (fun _ -> ())
{ "checked_file": "Steel.Utils.fst.checked", "dependencies": [ "Steel.Reference.fsti.checked", "Steel.Memory.fsti.checked", "Steel.FractionalPermission.fst.checked", "Steel.Effect.Atomic.fsti.checked", "Steel.Effect.fsti.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Steel.Utils.fst" }
[]
[ "Steel.Effect.Common.vprop", "Steel.Effect.Atomic.rewrite_slprop", "FStar.Ghost.hide", "FStar.Set.set", "Steel.Memory.iname", "FStar.Set.empty", "Steel.Memory.mem", "Prims.unit", "Steel.Effect.Common.rmem", "Prims.eq2", "Prims.l_True" ]
[]
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Utils open Steel.Memory open Steel.Effect.Atomic open Steel.Effect open Steel.FractionalPermission open Steel.Reference let pts_to_not_null (#a:Type) (#opened:inames) (#p:perm) (#v:FStar.Ghost.erased a) (r:ref a) : SteelGhost unit opened (pts_to r p v) (fun _ -> pts_to r p v) (fun _ -> True) (fun _ _ _ -> r =!= null) = extract_info_raw (pts_to r p v) (r =!= null) (fun m -> pts_to_not_null r p v m) let change_slprop_ens (p:vprop) (q:vprop) (r:prop) (f:(m:mem -> Lemma (requires interp (hp_of p) m) (ensures interp (hp_of q) m /\ r))) : Steel unit p (fun _ -> q) (requires fun _ -> True) (ensures fun _ _ _ -> r) = rewrite_slprop p (q `star` pure r) (fun m -> f m; Steel.Memory.emp_unit (hp_of q); Steel.Memory.pure_star_interp (hp_of q) r m); elim_pure r let pure_as_ens (#p:prop) () : Steel unit (pure p) (fun _ -> pure p) (fun _ -> True) (fun _ _ _ -> p) = change_slprop_ens (pure p) (pure p) p (Steel.Memory.pure_interp p) let rewrite #a (#p:a -> vprop) (x y:a) : Steel unit (p x) (fun _ -> p y) (requires fun _ -> x == y)
false
false
Steel.Utils.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val rewrite (#a: _) (#p: (a -> vprop)) (x y: a) : Steel unit (p x) (fun _ -> p y) (requires fun _ -> x == y) (ensures fun _ _ _ -> True)
[]
Steel.Utils.rewrite
{ "file_name": "lib/steel/Steel.Utils.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
x: a -> y: a -> Steel.Effect.Steel Prims.unit
{ "end_col": 44, "end_line": 54, "start_col": 4, "start_line": 54 }
Steel.Effect.Atomic.SteelGhost
val pts_to_not_null (#a: Type) (#opened: inames) (#p: perm) (#v: FStar.Ghost.erased a) (r: ref a) : SteelGhost unit opened (pts_to r p v) (fun _ -> pts_to r p v) (fun _ -> True) (fun _ _ _ -> r =!= null)
[ { "abbrev": false, "full_module": "Steel.Reference", "short_module": null }, { "abbrev": false, "full_module": "Steel.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect.Atomic", "short_module": null }, { "abbrev": false, "full_module": "Steel.Memory", "short_module": null }, { "abbrev": false, "full_module": "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 } ]
false
let pts_to_not_null (#a:Type) (#opened:inames) (#p:perm) (#v:FStar.Ghost.erased a) (r:ref a) : SteelGhost unit opened (pts_to r p v) (fun _ -> pts_to r p v) (fun _ -> True) (fun _ _ _ -> r =!= null) = extract_info_raw (pts_to r p v) (r =!= null) (fun m -> pts_to_not_null r p v m)
val pts_to_not_null (#a: Type) (#opened: inames) (#p: perm) (#v: FStar.Ghost.erased a) (r: ref a) : SteelGhost unit opened (pts_to r p v) (fun _ -> pts_to r p v) (fun _ -> True) (fun _ _ _ -> r =!= null) let pts_to_not_null (#a: Type) (#opened: inames) (#p: perm) (#v: FStar.Ghost.erased a) (r: ref a) : SteelGhost unit opened (pts_to r p v) (fun _ -> pts_to r p v) (fun _ -> True) (fun _ _ _ -> r =!= null) =
true
null
false
extract_info_raw (pts_to r p v) (r =!= null) (fun m -> pts_to_not_null r p v m)
{ "checked_file": "Steel.Utils.fst.checked", "dependencies": [ "Steel.Reference.fsti.checked", "Steel.Memory.fsti.checked", "Steel.FractionalPermission.fst.checked", "Steel.Effect.Atomic.fsti.checked", "Steel.Effect.fsti.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Steel.Utils.fst" }
[]
[ "Steel.Memory.inames", "Steel.FractionalPermission.perm", "FStar.Ghost.erased", "Steel.Reference.ref", "Steel.Effect.Atomic.extract_info_raw", "Steel.Reference.pts_to", "FStar.Ghost.reveal", "Prims.l_not", "Prims.eq2", "Steel.Reference.null", "Steel.Memory.mem", "Steel.Reference.pts_to_not_null", "Prims.unit", "Steel.Effect.Common.vprop", "Steel.Effect.Common.rmem", "Prims.l_True" ]
[]
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Utils open Steel.Memory open Steel.Effect.Atomic open Steel.Effect open Steel.FractionalPermission open Steel.Reference let pts_to_not_null (#a:Type) (#opened:inames) (#p:perm) (#v:FStar.Ghost.erased a) (r:ref a) : SteelGhost unit opened (pts_to r p v) (fun _ -> pts_to r p v) (fun _ -> True)
false
false
Steel.Utils.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val pts_to_not_null (#a: Type) (#opened: inames) (#p: perm) (#v: FStar.Ghost.erased a) (r: ref a) : SteelGhost unit opened (pts_to r p v) (fun _ -> pts_to r p v) (fun _ -> True) (fun _ _ _ -> r =!= null)
[]
Steel.Utils.pts_to_not_null
{ "file_name": "lib/steel/Steel.Utils.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
r: Steel.Reference.ref a -> Steel.Effect.Atomic.SteelGhost Prims.unit
{ "end_col": 40, "end_line": 35, "start_col": 4, "start_line": 34 }
Steel.Effect.Steel
val extract_pure (p: prop) : Steel unit (pure p) (fun _ -> pure p) (fun _ -> True) (fun _ _ _ -> p)
[ { "abbrev": false, "full_module": "Steel.Reference", "short_module": null }, { "abbrev": false, "full_module": "Steel.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect.Atomic", "short_module": null }, { "abbrev": false, "full_module": "Steel.Memory", "short_module": null }, { "abbrev": false, "full_module": "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 } ]
false
let extract_pure (p:prop) : Steel unit (pure p) (fun _ -> pure p) (fun _ -> True) (fun _ _ _ -> p) = elim_pure p; intro_pure p
val extract_pure (p: prop) : Steel unit (pure p) (fun _ -> pure p) (fun _ -> True) (fun _ _ _ -> p) let extract_pure (p: prop) : Steel unit (pure p) (fun _ -> pure p) (fun _ -> True) (fun _ _ _ -> p) =
true
null
false
elim_pure p; intro_pure p
{ "checked_file": "Steel.Utils.fst.checked", "dependencies": [ "Steel.Reference.fsti.checked", "Steel.Memory.fsti.checked", "Steel.FractionalPermission.fst.checked", "Steel.Effect.Atomic.fsti.checked", "Steel.Effect.fsti.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Steel.Utils.fst" }
[]
[ "Prims.prop", "Steel.Effect.Atomic.intro_pure", "FStar.Ghost.hide", "FStar.Set.set", "Steel.Memory.iname", "FStar.Set.empty", "Prims.unit", "Steel.Effect.Atomic.elim_pure", "Steel.Effect.Common.pure", "Steel.Effect.Common.vprop", "Steel.Effect.Common.rmem", "Prims.l_True" ]
[]
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Utils open Steel.Memory open Steel.Effect.Atomic open Steel.Effect open Steel.FractionalPermission open Steel.Reference let pts_to_not_null (#a:Type) (#opened:inames) (#p:perm) (#v:FStar.Ghost.erased a) (r:ref a) : SteelGhost unit opened (pts_to r p v) (fun _ -> pts_to r p v) (fun _ -> True) (fun _ _ _ -> r =!= null) = extract_info_raw (pts_to r p v) (r =!= null) (fun m -> pts_to_not_null r p v m) let change_slprop_ens (p:vprop) (q:vprop) (r:prop) (f:(m:mem -> Lemma (requires interp (hp_of p) m) (ensures interp (hp_of q) m /\ r))) : Steel unit p (fun _ -> q) (requires fun _ -> True) (ensures fun _ _ _ -> r) = rewrite_slprop p (q `star` pure r) (fun m -> f m; Steel.Memory.emp_unit (hp_of q); Steel.Memory.pure_star_interp (hp_of q) r m); elim_pure r let pure_as_ens (#p:prop) () : Steel unit (pure p) (fun _ -> pure p) (fun _ -> True) (fun _ _ _ -> p) = change_slprop_ens (pure p) (pure p) p (Steel.Memory.pure_interp p) let rewrite #a (#p:a -> vprop) (x y:a) : Steel unit (p x) (fun _ -> p y) (requires fun _ -> x == y) (ensures fun _ _ _ -> True) = rewrite_slprop (p x) (p y) (fun _ -> ()) let extract_pure (p:prop)
false
false
Steel.Utils.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val extract_pure (p: prop) : Steel unit (pure p) (fun _ -> pure p) (fun _ -> True) (fun _ _ _ -> p)
[]
Steel.Utils.extract_pure
{ "file_name": "lib/steel/Steel.Utils.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
p: Prims.prop -> Steel.Effect.Steel Prims.unit
{ "end_col": 16, "end_line": 59, "start_col": 4, "start_line": 58 }
Steel.Effect.SteelT
val dup_pure (p: prop) : SteelT unit (pure p) (fun _ -> (pure p) `star` (pure p))
[ { "abbrev": false, "full_module": "Steel.Reference", "short_module": null }, { "abbrev": false, "full_module": "Steel.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect.Atomic", "short_module": null }, { "abbrev": false, "full_module": "Steel.Memory", "short_module": null }, { "abbrev": false, "full_module": "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 } ]
false
let dup_pure (p:prop) : SteelT unit (pure p) (fun _ -> pure p `star` pure p) = extract_pure p; intro_pure p
val dup_pure (p: prop) : SteelT unit (pure p) (fun _ -> (pure p) `star` (pure p)) let dup_pure (p: prop) : SteelT unit (pure p) (fun _ -> (pure p) `star` (pure p)) =
true
null
false
extract_pure p; intro_pure p
{ "checked_file": "Steel.Utils.fst.checked", "dependencies": [ "Steel.Reference.fsti.checked", "Steel.Memory.fsti.checked", "Steel.FractionalPermission.fst.checked", "Steel.Effect.Atomic.fsti.checked", "Steel.Effect.fsti.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Steel.Utils.fst" }
[]
[ "Prims.prop", "Steel.Effect.Atomic.intro_pure", "FStar.Ghost.hide", "FStar.Set.set", "Steel.Memory.iname", "FStar.Set.empty", "Prims.unit", "Steel.Utils.extract_pure", "Steel.Effect.Common.pure", "Steel.Effect.Common.star", "Steel.Effect.Common.vprop" ]
[]
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Utils open Steel.Memory open Steel.Effect.Atomic open Steel.Effect open Steel.FractionalPermission open Steel.Reference let pts_to_not_null (#a:Type) (#opened:inames) (#p:perm) (#v:FStar.Ghost.erased a) (r:ref a) : SteelGhost unit opened (pts_to r p v) (fun _ -> pts_to r p v) (fun _ -> True) (fun _ _ _ -> r =!= null) = extract_info_raw (pts_to r p v) (r =!= null) (fun m -> pts_to_not_null r p v m) let change_slprop_ens (p:vprop) (q:vprop) (r:prop) (f:(m:mem -> Lemma (requires interp (hp_of p) m) (ensures interp (hp_of q) m /\ r))) : Steel unit p (fun _ -> q) (requires fun _ -> True) (ensures fun _ _ _ -> r) = rewrite_slprop p (q `star` pure r) (fun m -> f m; Steel.Memory.emp_unit (hp_of q); Steel.Memory.pure_star_interp (hp_of q) r m); elim_pure r let pure_as_ens (#p:prop) () : Steel unit (pure p) (fun _ -> pure p) (fun _ -> True) (fun _ _ _ -> p) = change_slprop_ens (pure p) (pure p) p (Steel.Memory.pure_interp p) let rewrite #a (#p:a -> vprop) (x y:a) : Steel unit (p x) (fun _ -> p y) (requires fun _ -> x == y) (ensures fun _ _ _ -> True) = rewrite_slprop (p x) (p y) (fun _ -> ()) let extract_pure (p:prop) : Steel unit (pure p) (fun _ -> pure p) (fun _ -> True) (fun _ _ _ -> p) = elim_pure p; intro_pure p let dup_pure (p:prop)
false
false
Steel.Utils.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val dup_pure (p: prop) : SteelT unit (pure p) (fun _ -> (pure p) `star` (pure p))
[]
Steel.Utils.dup_pure
{ "file_name": "lib/steel/Steel.Utils.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
p: Prims.prop -> Steel.Effect.SteelT Prims.unit
{ "end_col": 16, "end_line": 64, "start_col": 4, "start_line": 63 }
Steel.Effect.Steel
val change_slprop_ens (p q: vprop) (r: prop) (f: (m: mem -> Lemma (requires interp (hp_of p) m) (ensures interp (hp_of q) m /\ r))) : Steel unit p (fun _ -> q) (requires fun _ -> True) (ensures fun _ _ _ -> r)
[ { "abbrev": false, "full_module": "Steel.Reference", "short_module": null }, { "abbrev": false, "full_module": "Steel.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect.Atomic", "short_module": null }, { "abbrev": false, "full_module": "Steel.Memory", "short_module": null }, { "abbrev": false, "full_module": "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 } ]
false
let change_slprop_ens (p:vprop) (q:vprop) (r:prop) (f:(m:mem -> Lemma (requires interp (hp_of p) m) (ensures interp (hp_of q) m /\ r))) : Steel unit p (fun _ -> q) (requires fun _ -> True) (ensures fun _ _ _ -> r) = rewrite_slprop p (q `star` pure r) (fun m -> f m; Steel.Memory.emp_unit (hp_of q); Steel.Memory.pure_star_interp (hp_of q) r m); elim_pure r
val change_slprop_ens (p q: vprop) (r: prop) (f: (m: mem -> Lemma (requires interp (hp_of p) m) (ensures interp (hp_of q) m /\ r))) : Steel unit p (fun _ -> q) (requires fun _ -> True) (ensures fun _ _ _ -> r) let change_slprop_ens (p q: vprop) (r: prop) (f: (m: mem -> Lemma (requires interp (hp_of p) m) (ensures interp (hp_of q) m /\ r))) : Steel unit p (fun _ -> q) (requires fun _ -> True) (ensures fun _ _ _ -> r) =
true
null
false
rewrite_slprop p (q `star` (pure r)) (fun m -> f m; Steel.Memory.emp_unit (hp_of q); Steel.Memory.pure_star_interp (hp_of q) r m); elim_pure r
{ "checked_file": "Steel.Utils.fst.checked", "dependencies": [ "Steel.Reference.fsti.checked", "Steel.Memory.fsti.checked", "Steel.FractionalPermission.fst.checked", "Steel.Effect.Atomic.fsti.checked", "Steel.Effect.fsti.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Steel.Utils.fst" }
[]
[ "Steel.Effect.Common.vprop", "Prims.prop", "Steel.Memory.mem", "Prims.unit", "Steel.Memory.interp", "Steel.Effect.Common.hp_of", "Prims.squash", "Prims.l_and", "Prims.Nil", "FStar.Pervasives.pattern", "Steel.Effect.Atomic.elim_pure", "FStar.Ghost.hide", "FStar.Set.set", "Steel.Memory.iname", "FStar.Set.empty", "Steel.Effect.Atomic.rewrite_slprop", "Steel.Effect.Common.star", "Steel.Effect.Common.pure", "Steel.Memory.pure_star_interp", "Steel.Memory.emp_unit", "Steel.Effect.Common.rmem", "Prims.l_True" ]
[]
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Utils open Steel.Memory open Steel.Effect.Atomic open Steel.Effect open Steel.FractionalPermission open Steel.Reference let pts_to_not_null (#a:Type) (#opened:inames) (#p:perm) (#v:FStar.Ghost.erased a) (r:ref a) : SteelGhost unit opened (pts_to r p v) (fun _ -> pts_to r p v) (fun _ -> True) (fun _ _ _ -> r =!= null) = extract_info_raw (pts_to r p v) (r =!= null) (fun m -> pts_to_not_null r p v m) let change_slprop_ens (p:vprop) (q:vprop) (r:prop) (f:(m:mem -> Lemma (requires interp (hp_of p) m) (ensures interp (hp_of q) m /\ r)))
false
false
Steel.Utils.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val change_slprop_ens (p q: vprop) (r: prop) (f: (m: mem -> Lemma (requires interp (hp_of p) m) (ensures interp (hp_of q) m /\ r))) : Steel unit p (fun _ -> q) (requires fun _ -> True) (ensures fun _ _ _ -> r)
[]
Steel.Utils.change_slprop_ens
{ "file_name": "lib/steel/Steel.Utils.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
p: Steel.Effect.Common.vprop -> q: Steel.Effect.Common.vprop -> r: Prims.prop -> f: (m: Steel.Memory.mem -> FStar.Pervasives.Lemma (requires Steel.Memory.interp (Steel.Effect.Common.hp_of p) m) (ensures Steel.Memory.interp (Steel.Effect.Common.hp_of q) m /\ r)) -> Steel.Effect.Steel Prims.unit
{ "end_col": 15, "end_line": 44, "start_col": 4, "start_line": 40 }
Prims.Tot
[ { "abbrev": false, "full_module": "LowParse.Spec.Combinators // for parse_ret", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "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 } ]
false
let parse_bcvli_payload_kind = { parser_kind_low = 0; parser_kind_high = Some 4; parser_kind_subkind = Some ParserStrong; parser_kind_metadata = None; }
let parse_bcvli_payload_kind =
false
null
false
{ parser_kind_low = 0; parser_kind_high = Some 4; parser_kind_subkind = Some ParserStrong; parser_kind_metadata = None }
{ "checked_file": "LowParse.Spec.BCVLI.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Spec.BCVLI.fst" }
[ "total" ]
[ "LowParse.Spec.Base.Mkparser_kind'", "FStar.Pervasives.Native.Some", "Prims.nat", "LowParse.Spec.Base.parser_subkind", "LowParse.Spec.Base.ParserStrong", "FStar.Pervasives.Native.None", "LowParse.Spec.Base.parser_kind_metadata_some" ]
[]
module LowParse.Spec.BCVLI open LowParse.Spec.Combinators // for parse_ret module U32 = FStar.UInt32 module Seq = FStar.Seq inline_for_extraction
false
true
LowParse.Spec.BCVLI.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val parse_bcvli_payload_kind : LowParse.Spec.Base.parser_kind'
[]
LowParse.Spec.BCVLI.parse_bcvli_payload_kind
{ "file_name": "src/lowparse/LowParse.Spec.BCVLI.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
LowParse.Spec.Base.parser_kind'
{ "end_col": 30, "end_line": 12, "start_col": 2, "start_line": 9 }
Prims.Tot
val parse_bounded_bcvli (min: nat) (max: nat { min <= max }) : Tot (parser (parse_bounded_bcvli_kind min max) (bounded_int32 min max))
[ { "abbrev": false, "full_module": "LowParse.Spec.Combinators // for parse_ret", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "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 } ]
false
let parse_bounded_bcvli min max = parse_bounded_bcvli_kind_correct min max; strengthen (parse_bounded_bcvli_kind min max) (parse_bounded_bcvli' min max)
val parse_bounded_bcvli (min: nat) (max: nat { min <= max }) : Tot (parser (parse_bounded_bcvli_kind min max) (bounded_int32 min max)) let parse_bounded_bcvli min max =
false
null
false
parse_bounded_bcvli_kind_correct min max; strengthen (parse_bounded_bcvli_kind min max) (parse_bounded_bcvli' min max)
{ "checked_file": "LowParse.Spec.BCVLI.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Spec.BCVLI.fst" }
[ "total" ]
[ "Prims.nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "LowParse.Spec.Base.strengthen", "LowParse.Spec.BCVLI.parse_bounded_bcvli_kind", "LowParse.Spec.BoundedInt.bounded_int32", "LowParse.Spec.BCVLI.parse_bounded_bcvli'", "Prims.unit", "LowParse.Spec.BCVLI.parse_bounded_bcvli_kind_correct", "LowParse.Spec.Base.parser" ]
[]
module LowParse.Spec.BCVLI open LowParse.Spec.Combinators // for parse_ret module U32 = FStar.UInt32 module Seq = FStar.Seq inline_for_extraction let parse_bcvli_payload_kind = { parser_kind_low = 0; parser_kind_high = Some 4; parser_kind_subkind = Some ParserStrong; parser_kind_metadata = None; } let parse_bcvli_payload (x: bounded_integer 1) : Tot (parser parse_bcvli_payload_kind U32.t) = if U32.v x <= 252 then weaken parse_bcvli_payload_kind (parse_ret (x <: U32.t)) else if U32.v x = 253 then weaken parse_bcvli_payload_kind ((parse_bounded_integer_le 2 `parse_filter` (fun x -> U32.v x >= 253)) `parse_synth` (fun x -> (x <: U32.t))) else if U32.v x = 254 then weaken parse_bcvli_payload_kind ((parse_bounded_integer_le 4 `parse_filter` (fun x -> U32.v x >= 65536)) `parse_synth` (fun x -> (x <: U32.t))) else fail_parser parse_bcvli_payload_kind U32.t #push-options "--z3rlimit 32" let parse_bcvli_payload_and_then_cases_injective : squash (and_then_cases_injective parse_bcvli_payload) = and_then_cases_injective_intro parse_bcvli_payload (fun x1 x2 b1 b2 -> parse_synth_eq (parse_bounded_integer_le 2 `parse_filter` (fun x -> U32.v x >= 253)) (fun x -> (x <: U32.t)) b1; parse_synth_eq (parse_bounded_integer_le 2 `parse_filter` (fun x -> U32.v x >= 253)) (fun x -> (x <: U32.t)) b2; parse_synth_eq (parse_bounded_integer_le 4 `parse_filter` (fun x -> U32.v x >= 65536)) (fun x -> (x <: U32.t)) b1; parse_synth_eq (parse_bounded_integer_le 4 `parse_filter` (fun x -> U32.v x >= 65536)) (fun x -> (x <: U32.t)) b2 ) #pop-options let parse_bcvli : parser parse_bcvli_kind U32.t = parse_bounded_integer_le 1 `and_then` parse_bcvli_payload let parse_bcvli_eq b = and_then_eq (parse_bounded_integer_le 1) parse_bcvli_payload b; match parse (parse_bounded_integer_le 1) b with | None -> () | Some (x32, consumed_x) -> let b' = Seq.slice b consumed_x (Seq.length b) in parse_synth_eq (parse_bounded_integer_le 2 `parse_filter` (fun x -> U32.v x >= 253)) (fun x -> (x <: U32.t)) b'; parse_filter_eq (parse_bounded_integer_le 2) (fun x -> U32.v x >= 253) b'; parse_synth_eq (parse_bounded_integer_le 4 `parse_filter` (fun x -> U32.v x >= 65536)) (fun x -> (x <: U32.t)) b'; parse_filter_eq (parse_bounded_integer_le 4) (fun x -> U32.v x >= 65536) b' let bare_serialize_bcvli (x: U32.t) : GTot bytes = let c1 : bounded_integer 1 = if U32.v x <= 252 then x else if U32.v x <= 65535 then 253ul else 254ul in Seq.append (serialize (serialize_bounded_integer_le 1) c1) ( if U32.v c1 <= 252 then Seq.empty else if U32.v c1 = 253 then serialize (serialize_bounded_integer_le 2) x else serialize (serialize_bounded_integer_le 4) x ) #push-options "--z3rlimit 32" let bare_serialize_bcvli_correct : squash (serializer_correct parse_bcvli bare_serialize_bcvli) = let prf (x: U32.t) : Lemma (let y = bare_serialize_bcvli x in parse parse_bcvli y == Some (x, Seq.length y)) = let y = bare_serialize_bcvli x in let c1 : bounded_integer 1 = if U32.v x <= 252 then x else if U32.v x <= 65535 then 253ul else 254ul in let sc1 = serialize (serialize_bounded_integer_le 1) c1 in parse_strong_prefix (parse_bounded_integer_le 1) sc1 y; let y' = Seq.slice y (Seq.length sc1) (Seq.length y) in parse_bcvli_eq y; if U32.v c1 <= 252 then begin assert (y `Seq.equal` sc1) end else if U32.v c1 = 253 then begin assert (U32.v x <= 65535); assert (y' `Seq.equal` serialize (serialize_bounded_integer_le 2) x) end else begin assert (y' `Seq.equal` serialize (serialize_bounded_integer_le 4) x) end in Classical.forall_intro (Classical.move_requires prf) #pop-options let serialize_bcvli : serializer parse_bcvli = bare_serialize_bcvli let serialize_bcvli_eq x = () let parse_bounded_bcvli' (min: nat) (max: nat { min <= max }) : Tot (parser (parse_filter_kind parse_bcvli_kind) (bounded_int32 min max)) = parse_filter parse_bcvli (in_bounds min max) let parse_bounded_bcvli_size_correct (min: nat) (max: nat { min <= max }) : Lemma (parse_bounded_bcvli_size min `parses_at_least` parse_bounded_bcvli' min max /\ parse_bounded_bcvli_size max `parses_at_most` parse_bounded_bcvli' min max) = Classical.forall_intro (parse_filter_eq parse_bcvli (in_bounds min max)); Classical.forall_intro parse_bcvli_eq; parser_kind_prop_equiv (parse_bounded_integer_kind 1) (parse_bounded_integer_le 1); parser_kind_prop_equiv (parse_bounded_integer_kind 2) (parse_bounded_integer_le 2); parser_kind_prop_equiv (parse_bounded_integer_kind 4) (parse_bounded_integer_le 4) let parse_bounded_bcvli_kind_correct (min: nat) (max: nat { min <= max }) : Lemma (parser_kind_prop (parse_bounded_bcvli_kind min max) (parse_bounded_bcvli' min max)) = parse_bounded_bcvli_size_correct min max; parser_kind_prop_equiv (parse_filter_kind parse_bcvli_kind) (parse_bounded_bcvli' min max); parser_kind_prop_equiv (parse_bounded_bcvli_kind min max) (parse_bounded_bcvli' min max) let parse_bounded_bcvli
false
false
LowParse.Spec.BCVLI.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val parse_bounded_bcvli (min: nat) (max: nat { min <= max }) : Tot (parser (parse_bounded_bcvli_kind min max) (bounded_int32 min max))
[]
LowParse.Spec.BCVLI.parse_bounded_bcvli
{ "file_name": "src/lowparse/LowParse.Spec.BCVLI.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
min: Prims.nat -> max: Prims.nat{min <= max} -> LowParse.Spec.Base.parser (LowParse.Spec.BCVLI.parse_bounded_bcvli_kind min max) (LowParse.Spec.BoundedInt.bounded_int32 min max)
{ "end_col": 78, "end_line": 132, "start_col": 2, "start_line": 131 }
Prims.Tot
val serialize_bounded_bcvli (min: nat) (max: nat { min <= max }) : Tot (serializer (parse_bounded_bcvli min max))
[ { "abbrev": false, "full_module": "LowParse.Spec.Combinators // for parse_ret", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "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 } ]
false
let serialize_bounded_bcvli min max = assert_norm (parse_filter_refine (in_bounds min max) == bounded_int32 min max); serialize_ext _ (serialize_filter serialize_bcvli (in_bounds min max)) (parse_bounded_bcvli min max)
val serialize_bounded_bcvli (min: nat) (max: nat { min <= max }) : Tot (serializer (parse_bounded_bcvli min max)) let serialize_bounded_bcvli min max =
false
null
false
assert_norm (parse_filter_refine (in_bounds min max) == bounded_int32 min max); serialize_ext _ (serialize_filter serialize_bcvli (in_bounds min max)) (parse_bounded_bcvli min max)
{ "checked_file": "LowParse.Spec.BCVLI.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Spec.BCVLI.fst" }
[ "total" ]
[ "Prims.nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "LowParse.Spec.Base.serialize_ext", "LowParse.Spec.Combinators.parse_filter_kind", "LowParse.Spec.BCVLI.parse_bcvli_kind", "LowParse.Spec.Combinators.parse_filter_refine", "FStar.UInt32.t", "LowParse.Spec.BoundedInt.in_bounds", "LowParse.Spec.Combinators.parse_filter", "LowParse.Spec.BCVLI.parse_bcvli", "LowParse.Spec.Combinators.serialize_filter", "LowParse.Spec.BCVLI.serialize_bcvli", "LowParse.Spec.BCVLI.parse_bounded_bcvli_kind", "LowParse.Spec.BoundedInt.bounded_int32", "LowParse.Spec.BCVLI.parse_bounded_bcvli", "Prims.unit", "FStar.Pervasives.assert_norm", "Prims.eq2", "LowParse.Spec.Base.serializer" ]
[]
module LowParse.Spec.BCVLI open LowParse.Spec.Combinators // for parse_ret module U32 = FStar.UInt32 module Seq = FStar.Seq inline_for_extraction let parse_bcvli_payload_kind = { parser_kind_low = 0; parser_kind_high = Some 4; parser_kind_subkind = Some ParserStrong; parser_kind_metadata = None; } let parse_bcvli_payload (x: bounded_integer 1) : Tot (parser parse_bcvli_payload_kind U32.t) = if U32.v x <= 252 then weaken parse_bcvli_payload_kind (parse_ret (x <: U32.t)) else if U32.v x = 253 then weaken parse_bcvli_payload_kind ((parse_bounded_integer_le 2 `parse_filter` (fun x -> U32.v x >= 253)) `parse_synth` (fun x -> (x <: U32.t))) else if U32.v x = 254 then weaken parse_bcvli_payload_kind ((parse_bounded_integer_le 4 `parse_filter` (fun x -> U32.v x >= 65536)) `parse_synth` (fun x -> (x <: U32.t))) else fail_parser parse_bcvli_payload_kind U32.t #push-options "--z3rlimit 32" let parse_bcvli_payload_and_then_cases_injective : squash (and_then_cases_injective parse_bcvli_payload) = and_then_cases_injective_intro parse_bcvli_payload (fun x1 x2 b1 b2 -> parse_synth_eq (parse_bounded_integer_le 2 `parse_filter` (fun x -> U32.v x >= 253)) (fun x -> (x <: U32.t)) b1; parse_synth_eq (parse_bounded_integer_le 2 `parse_filter` (fun x -> U32.v x >= 253)) (fun x -> (x <: U32.t)) b2; parse_synth_eq (parse_bounded_integer_le 4 `parse_filter` (fun x -> U32.v x >= 65536)) (fun x -> (x <: U32.t)) b1; parse_synth_eq (parse_bounded_integer_le 4 `parse_filter` (fun x -> U32.v x >= 65536)) (fun x -> (x <: U32.t)) b2 ) #pop-options let parse_bcvli : parser parse_bcvli_kind U32.t = parse_bounded_integer_le 1 `and_then` parse_bcvli_payload let parse_bcvli_eq b = and_then_eq (parse_bounded_integer_le 1) parse_bcvli_payload b; match parse (parse_bounded_integer_le 1) b with | None -> () | Some (x32, consumed_x) -> let b' = Seq.slice b consumed_x (Seq.length b) in parse_synth_eq (parse_bounded_integer_le 2 `parse_filter` (fun x -> U32.v x >= 253)) (fun x -> (x <: U32.t)) b'; parse_filter_eq (parse_bounded_integer_le 2) (fun x -> U32.v x >= 253) b'; parse_synth_eq (parse_bounded_integer_le 4 `parse_filter` (fun x -> U32.v x >= 65536)) (fun x -> (x <: U32.t)) b'; parse_filter_eq (parse_bounded_integer_le 4) (fun x -> U32.v x >= 65536) b' let bare_serialize_bcvli (x: U32.t) : GTot bytes = let c1 : bounded_integer 1 = if U32.v x <= 252 then x else if U32.v x <= 65535 then 253ul else 254ul in Seq.append (serialize (serialize_bounded_integer_le 1) c1) ( if U32.v c1 <= 252 then Seq.empty else if U32.v c1 = 253 then serialize (serialize_bounded_integer_le 2) x else serialize (serialize_bounded_integer_le 4) x ) #push-options "--z3rlimit 32" let bare_serialize_bcvli_correct : squash (serializer_correct parse_bcvli bare_serialize_bcvli) = let prf (x: U32.t) : Lemma (let y = bare_serialize_bcvli x in parse parse_bcvli y == Some (x, Seq.length y)) = let y = bare_serialize_bcvli x in let c1 : bounded_integer 1 = if U32.v x <= 252 then x else if U32.v x <= 65535 then 253ul else 254ul in let sc1 = serialize (serialize_bounded_integer_le 1) c1 in parse_strong_prefix (parse_bounded_integer_le 1) sc1 y; let y' = Seq.slice y (Seq.length sc1) (Seq.length y) in parse_bcvli_eq y; if U32.v c1 <= 252 then begin assert (y `Seq.equal` sc1) end else if U32.v c1 = 253 then begin assert (U32.v x <= 65535); assert (y' `Seq.equal` serialize (serialize_bounded_integer_le 2) x) end else begin assert (y' `Seq.equal` serialize (serialize_bounded_integer_le 4) x) end in Classical.forall_intro (Classical.move_requires prf) #pop-options let serialize_bcvli : serializer parse_bcvli = bare_serialize_bcvli let serialize_bcvli_eq x = () let parse_bounded_bcvli' (min: nat) (max: nat { min <= max }) : Tot (parser (parse_filter_kind parse_bcvli_kind) (bounded_int32 min max)) = parse_filter parse_bcvli (in_bounds min max) let parse_bounded_bcvli_size_correct (min: nat) (max: nat { min <= max }) : Lemma (parse_bounded_bcvli_size min `parses_at_least` parse_bounded_bcvli' min max /\ parse_bounded_bcvli_size max `parses_at_most` parse_bounded_bcvli' min max) = Classical.forall_intro (parse_filter_eq parse_bcvli (in_bounds min max)); Classical.forall_intro parse_bcvli_eq; parser_kind_prop_equiv (parse_bounded_integer_kind 1) (parse_bounded_integer_le 1); parser_kind_prop_equiv (parse_bounded_integer_kind 2) (parse_bounded_integer_le 2); parser_kind_prop_equiv (parse_bounded_integer_kind 4) (parse_bounded_integer_le 4) let parse_bounded_bcvli_kind_correct (min: nat) (max: nat { min <= max }) : Lemma (parser_kind_prop (parse_bounded_bcvli_kind min max) (parse_bounded_bcvli' min max)) = parse_bounded_bcvli_size_correct min max; parser_kind_prop_equiv (parse_filter_kind parse_bcvli_kind) (parse_bounded_bcvli' min max); parser_kind_prop_equiv (parse_bounded_bcvli_kind min max) (parse_bounded_bcvli' min max) let parse_bounded_bcvli min max = parse_bounded_bcvli_kind_correct min max; strengthen (parse_bounded_bcvli_kind min max) (parse_bounded_bcvli' min max) let parse_bounded_bcvli_eq min max input = parse_filter_eq parse_bcvli (in_bounds min max) input; parse_bcvli_eq input let serialize_bounded_bcvli
false
false
LowParse.Spec.BCVLI.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val serialize_bounded_bcvli (min: nat) (max: nat { min <= max }) : Tot (serializer (parse_bounded_bcvli min max))
[]
LowParse.Spec.BCVLI.serialize_bounded_bcvli
{ "file_name": "src/lowparse/LowParse.Spec.BCVLI.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
min: Prims.nat -> max: Prims.nat{min <= max} -> LowParse.Spec.Base.serializer (LowParse.Spec.BCVLI.parse_bounded_bcvli min max)
{ "end_col": 33, "end_line": 145, "start_col": 2, "start_line": 141 }
FStar.Pervasives.Lemma
val parse_bounded_bcvli_kind_correct (min: nat) (max: nat{min <= max}) : Lemma (parser_kind_prop (parse_bounded_bcvli_kind min max) (parse_bounded_bcvli' min max))
[ { "abbrev": false, "full_module": "LowParse.Spec.Combinators // for parse_ret", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "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 } ]
false
let parse_bounded_bcvli_kind_correct (min: nat) (max: nat { min <= max }) : Lemma (parser_kind_prop (parse_bounded_bcvli_kind min max) (parse_bounded_bcvli' min max)) = parse_bounded_bcvli_size_correct min max; parser_kind_prop_equiv (parse_filter_kind parse_bcvli_kind) (parse_bounded_bcvli' min max); parser_kind_prop_equiv (parse_bounded_bcvli_kind min max) (parse_bounded_bcvli' min max)
val parse_bounded_bcvli_kind_correct (min: nat) (max: nat{min <= max}) : Lemma (parser_kind_prop (parse_bounded_bcvli_kind min max) (parse_bounded_bcvli' min max)) let parse_bounded_bcvli_kind_correct (min: nat) (max: nat{min <= max}) : Lemma (parser_kind_prop (parse_bounded_bcvli_kind min max) (parse_bounded_bcvli' min max)) =
false
null
true
parse_bounded_bcvli_size_correct min max; parser_kind_prop_equiv (parse_filter_kind parse_bcvli_kind) (parse_bounded_bcvli' min max); parser_kind_prop_equiv (parse_bounded_bcvli_kind min max) (parse_bounded_bcvli' min max)
{ "checked_file": "LowParse.Spec.BCVLI.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Spec.BCVLI.fst" }
[ "lemma" ]
[ "Prims.nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "LowParse.Spec.Base.parser_kind_prop_equiv", "LowParse.Spec.BoundedInt.bounded_int32", "LowParse.Spec.BCVLI.parse_bounded_bcvli_kind", "LowParse.Spec.BCVLI.parse_bounded_bcvli'", "Prims.unit", "LowParse.Spec.Combinators.parse_filter_kind", "LowParse.Spec.BCVLI.parse_bcvli_kind", "LowParse.Spec.BCVLI.parse_bounded_bcvli_size_correct", "Prims.l_True", "Prims.squash", "LowParse.Spec.Base.parser_kind_prop", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module LowParse.Spec.BCVLI open LowParse.Spec.Combinators // for parse_ret module U32 = FStar.UInt32 module Seq = FStar.Seq inline_for_extraction let parse_bcvli_payload_kind = { parser_kind_low = 0; parser_kind_high = Some 4; parser_kind_subkind = Some ParserStrong; parser_kind_metadata = None; } let parse_bcvli_payload (x: bounded_integer 1) : Tot (parser parse_bcvli_payload_kind U32.t) = if U32.v x <= 252 then weaken parse_bcvli_payload_kind (parse_ret (x <: U32.t)) else if U32.v x = 253 then weaken parse_bcvli_payload_kind ((parse_bounded_integer_le 2 `parse_filter` (fun x -> U32.v x >= 253)) `parse_synth` (fun x -> (x <: U32.t))) else if U32.v x = 254 then weaken parse_bcvli_payload_kind ((parse_bounded_integer_le 4 `parse_filter` (fun x -> U32.v x >= 65536)) `parse_synth` (fun x -> (x <: U32.t))) else fail_parser parse_bcvli_payload_kind U32.t #push-options "--z3rlimit 32" let parse_bcvli_payload_and_then_cases_injective : squash (and_then_cases_injective parse_bcvli_payload) = and_then_cases_injective_intro parse_bcvli_payload (fun x1 x2 b1 b2 -> parse_synth_eq (parse_bounded_integer_le 2 `parse_filter` (fun x -> U32.v x >= 253)) (fun x -> (x <: U32.t)) b1; parse_synth_eq (parse_bounded_integer_le 2 `parse_filter` (fun x -> U32.v x >= 253)) (fun x -> (x <: U32.t)) b2; parse_synth_eq (parse_bounded_integer_le 4 `parse_filter` (fun x -> U32.v x >= 65536)) (fun x -> (x <: U32.t)) b1; parse_synth_eq (parse_bounded_integer_le 4 `parse_filter` (fun x -> U32.v x >= 65536)) (fun x -> (x <: U32.t)) b2 ) #pop-options let parse_bcvli : parser parse_bcvli_kind U32.t = parse_bounded_integer_le 1 `and_then` parse_bcvli_payload let parse_bcvli_eq b = and_then_eq (parse_bounded_integer_le 1) parse_bcvli_payload b; match parse (parse_bounded_integer_le 1) b with | None -> () | Some (x32, consumed_x) -> let b' = Seq.slice b consumed_x (Seq.length b) in parse_synth_eq (parse_bounded_integer_le 2 `parse_filter` (fun x -> U32.v x >= 253)) (fun x -> (x <: U32.t)) b'; parse_filter_eq (parse_bounded_integer_le 2) (fun x -> U32.v x >= 253) b'; parse_synth_eq (parse_bounded_integer_le 4 `parse_filter` (fun x -> U32.v x >= 65536)) (fun x -> (x <: U32.t)) b'; parse_filter_eq (parse_bounded_integer_le 4) (fun x -> U32.v x >= 65536) b' let bare_serialize_bcvli (x: U32.t) : GTot bytes = let c1 : bounded_integer 1 = if U32.v x <= 252 then x else if U32.v x <= 65535 then 253ul else 254ul in Seq.append (serialize (serialize_bounded_integer_le 1) c1) ( if U32.v c1 <= 252 then Seq.empty else if U32.v c1 = 253 then serialize (serialize_bounded_integer_le 2) x else serialize (serialize_bounded_integer_le 4) x ) #push-options "--z3rlimit 32" let bare_serialize_bcvli_correct : squash (serializer_correct parse_bcvli bare_serialize_bcvli) = let prf (x: U32.t) : Lemma (let y = bare_serialize_bcvli x in parse parse_bcvli y == Some (x, Seq.length y)) = let y = bare_serialize_bcvli x in let c1 : bounded_integer 1 = if U32.v x <= 252 then x else if U32.v x <= 65535 then 253ul else 254ul in let sc1 = serialize (serialize_bounded_integer_le 1) c1 in parse_strong_prefix (parse_bounded_integer_le 1) sc1 y; let y' = Seq.slice y (Seq.length sc1) (Seq.length y) in parse_bcvli_eq y; if U32.v c1 <= 252 then begin assert (y `Seq.equal` sc1) end else if U32.v c1 = 253 then begin assert (U32.v x <= 65535); assert (y' `Seq.equal` serialize (serialize_bounded_integer_le 2) x) end else begin assert (y' `Seq.equal` serialize (serialize_bounded_integer_le 4) x) end in Classical.forall_intro (Classical.move_requires prf) #pop-options let serialize_bcvli : serializer parse_bcvli = bare_serialize_bcvli let serialize_bcvli_eq x = () let parse_bounded_bcvli' (min: nat) (max: nat { min <= max }) : Tot (parser (parse_filter_kind parse_bcvli_kind) (bounded_int32 min max)) = parse_filter parse_bcvli (in_bounds min max) let parse_bounded_bcvli_size_correct (min: nat) (max: nat { min <= max }) : Lemma (parse_bounded_bcvli_size min `parses_at_least` parse_bounded_bcvli' min max /\ parse_bounded_bcvli_size max `parses_at_most` parse_bounded_bcvli' min max) = Classical.forall_intro (parse_filter_eq parse_bcvli (in_bounds min max)); Classical.forall_intro parse_bcvli_eq; parser_kind_prop_equiv (parse_bounded_integer_kind 1) (parse_bounded_integer_le 1); parser_kind_prop_equiv (parse_bounded_integer_kind 2) (parse_bounded_integer_le 2); parser_kind_prop_equiv (parse_bounded_integer_kind 4) (parse_bounded_integer_le 4) let parse_bounded_bcvli_kind_correct (min: nat) (max: nat { min <= max }) : Lemma
false
false
LowParse.Spec.BCVLI.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val parse_bounded_bcvli_kind_correct (min: nat) (max: nat{min <= max}) : Lemma (parser_kind_prop (parse_bounded_bcvli_kind min max) (parse_bounded_bcvli' min max))
[]
LowParse.Spec.BCVLI.parse_bounded_bcvli_kind_correct
{ "file_name": "src/lowparse/LowParse.Spec.BCVLI.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
min: Prims.nat -> max: Prims.nat{min <= max} -> FStar.Pervasives.Lemma (ensures LowParse.Spec.Base.parser_kind_prop (LowParse.Spec.BCVLI.parse_bounded_bcvli_kind min max) (LowParse.Spec.BCVLI.parse_bounded_bcvli' min max))
{ "end_col": 90, "end_line": 127, "start_col": 2, "start_line": 125 }
Prims.GTot
val bare_serialize_bcvli (x: U32.t) : GTot bytes
[ { "abbrev": false, "full_module": "LowParse.Spec.Combinators // for parse_ret", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "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 } ]
false
let bare_serialize_bcvli (x: U32.t) : GTot bytes = let c1 : bounded_integer 1 = if U32.v x <= 252 then x else if U32.v x <= 65535 then 253ul else 254ul in Seq.append (serialize (serialize_bounded_integer_le 1) c1) ( if U32.v c1 <= 252 then Seq.empty else if U32.v c1 = 253 then serialize (serialize_bounded_integer_le 2) x else serialize (serialize_bounded_integer_le 4) x )
val bare_serialize_bcvli (x: U32.t) : GTot bytes let bare_serialize_bcvli (x: U32.t) : GTot bytes =
false
null
false
let c1:bounded_integer 1 = if U32.v x <= 252 then x else if U32.v x <= 65535 then 253ul else 254ul in Seq.append (serialize (serialize_bounded_integer_le 1) c1) (if U32.v c1 <= 252 then Seq.empty else if U32.v c1 = 253 then serialize (serialize_bounded_integer_le 2) x else serialize (serialize_bounded_integer_le 4) x)
{ "checked_file": "LowParse.Spec.BCVLI.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Spec.BCVLI.fst" }
[ "sometrivial" ]
[ "FStar.UInt32.t", "FStar.Seq.Base.append", "LowParse.Bytes.byte", "LowParse.Spec.Base.serialize", "LowParse.Spec.BoundedInt.parse_bounded_integer_kind", "LowParse.Spec.BoundedInt.bounded_integer", "LowParse.Spec.BoundedInt.parse_bounded_integer_le", "LowParse.Spec.BoundedInt.serialize_bounded_integer_le", "Prims.op_LessThanOrEqual", "FStar.UInt32.v", "FStar.Seq.Base.empty", "Prims.bool", "Prims.op_Equality", "Prims.int", "FStar.Seq.Base.seq", "FStar.UInt32.__uint_to_t", "LowParse.Bytes.bytes" ]
[]
module LowParse.Spec.BCVLI open LowParse.Spec.Combinators // for parse_ret module U32 = FStar.UInt32 module Seq = FStar.Seq inline_for_extraction let parse_bcvli_payload_kind = { parser_kind_low = 0; parser_kind_high = Some 4; parser_kind_subkind = Some ParserStrong; parser_kind_metadata = None; } let parse_bcvli_payload (x: bounded_integer 1) : Tot (parser parse_bcvli_payload_kind U32.t) = if U32.v x <= 252 then weaken parse_bcvli_payload_kind (parse_ret (x <: U32.t)) else if U32.v x = 253 then weaken parse_bcvli_payload_kind ((parse_bounded_integer_le 2 `parse_filter` (fun x -> U32.v x >= 253)) `parse_synth` (fun x -> (x <: U32.t))) else if U32.v x = 254 then weaken parse_bcvli_payload_kind ((parse_bounded_integer_le 4 `parse_filter` (fun x -> U32.v x >= 65536)) `parse_synth` (fun x -> (x <: U32.t))) else fail_parser parse_bcvli_payload_kind U32.t #push-options "--z3rlimit 32" let parse_bcvli_payload_and_then_cases_injective : squash (and_then_cases_injective parse_bcvli_payload) = and_then_cases_injective_intro parse_bcvli_payload (fun x1 x2 b1 b2 -> parse_synth_eq (parse_bounded_integer_le 2 `parse_filter` (fun x -> U32.v x >= 253)) (fun x -> (x <: U32.t)) b1; parse_synth_eq (parse_bounded_integer_le 2 `parse_filter` (fun x -> U32.v x >= 253)) (fun x -> (x <: U32.t)) b2; parse_synth_eq (parse_bounded_integer_le 4 `parse_filter` (fun x -> U32.v x >= 65536)) (fun x -> (x <: U32.t)) b1; parse_synth_eq (parse_bounded_integer_le 4 `parse_filter` (fun x -> U32.v x >= 65536)) (fun x -> (x <: U32.t)) b2 ) #pop-options let parse_bcvli : parser parse_bcvli_kind U32.t = parse_bounded_integer_le 1 `and_then` parse_bcvli_payload let parse_bcvli_eq b = and_then_eq (parse_bounded_integer_le 1) parse_bcvli_payload b; match parse (parse_bounded_integer_le 1) b with | None -> () | Some (x32, consumed_x) -> let b' = Seq.slice b consumed_x (Seq.length b) in parse_synth_eq (parse_bounded_integer_le 2 `parse_filter` (fun x -> U32.v x >= 253)) (fun x -> (x <: U32.t)) b'; parse_filter_eq (parse_bounded_integer_le 2) (fun x -> U32.v x >= 253) b'; parse_synth_eq (parse_bounded_integer_le 4 `parse_filter` (fun x -> U32.v x >= 65536)) (fun x -> (x <: U32.t)) b'; parse_filter_eq (parse_bounded_integer_le 4) (fun x -> U32.v x >= 65536) b'
false
false
LowParse.Spec.BCVLI.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val bare_serialize_bcvli (x: U32.t) : GTot bytes
[]
LowParse.Spec.BCVLI.bare_serialize_bcvli
{ "file_name": "src/lowparse/LowParse.Spec.BCVLI.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
x: FStar.UInt32.t -> Prims.GTot LowParse.Bytes.bytes
{ "end_col": 5, "end_line": 63, "start_col": 50, "start_line": 48 }
Prims.Tot
val serialize_bcvli : serializer parse_bcvli
[ { "abbrev": false, "full_module": "LowParse.Spec.Combinators // for parse_ret", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "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 } ]
false
let serialize_bcvli : serializer parse_bcvli = bare_serialize_bcvli
val serialize_bcvli : serializer parse_bcvli let serialize_bcvli:serializer parse_bcvli =
false
null
false
bare_serialize_bcvli
{ "checked_file": "LowParse.Spec.BCVLI.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Spec.BCVLI.fst" }
[ "total" ]
[ "LowParse.Spec.BCVLI.bare_serialize_bcvli", "LowParse.Spec.Base.serializer", "LowParse.Spec.BCVLI.parse_bcvli_kind", "FStar.UInt32.t", "LowParse.Spec.BCVLI.parse_bcvli" ]
[]
module LowParse.Spec.BCVLI open LowParse.Spec.Combinators // for parse_ret module U32 = FStar.UInt32 module Seq = FStar.Seq inline_for_extraction let parse_bcvli_payload_kind = { parser_kind_low = 0; parser_kind_high = Some 4; parser_kind_subkind = Some ParserStrong; parser_kind_metadata = None; } let parse_bcvli_payload (x: bounded_integer 1) : Tot (parser parse_bcvli_payload_kind U32.t) = if U32.v x <= 252 then weaken parse_bcvli_payload_kind (parse_ret (x <: U32.t)) else if U32.v x = 253 then weaken parse_bcvli_payload_kind ((parse_bounded_integer_le 2 `parse_filter` (fun x -> U32.v x >= 253)) `parse_synth` (fun x -> (x <: U32.t))) else if U32.v x = 254 then weaken parse_bcvli_payload_kind ((parse_bounded_integer_le 4 `parse_filter` (fun x -> U32.v x >= 65536)) `parse_synth` (fun x -> (x <: U32.t))) else fail_parser parse_bcvli_payload_kind U32.t #push-options "--z3rlimit 32" let parse_bcvli_payload_and_then_cases_injective : squash (and_then_cases_injective parse_bcvli_payload) = and_then_cases_injective_intro parse_bcvli_payload (fun x1 x2 b1 b2 -> parse_synth_eq (parse_bounded_integer_le 2 `parse_filter` (fun x -> U32.v x >= 253)) (fun x -> (x <: U32.t)) b1; parse_synth_eq (parse_bounded_integer_le 2 `parse_filter` (fun x -> U32.v x >= 253)) (fun x -> (x <: U32.t)) b2; parse_synth_eq (parse_bounded_integer_le 4 `parse_filter` (fun x -> U32.v x >= 65536)) (fun x -> (x <: U32.t)) b1; parse_synth_eq (parse_bounded_integer_le 4 `parse_filter` (fun x -> U32.v x >= 65536)) (fun x -> (x <: U32.t)) b2 ) #pop-options let parse_bcvli : parser parse_bcvli_kind U32.t = parse_bounded_integer_le 1 `and_then` parse_bcvli_payload let parse_bcvli_eq b = and_then_eq (parse_bounded_integer_le 1) parse_bcvli_payload b; match parse (parse_bounded_integer_le 1) b with | None -> () | Some (x32, consumed_x) -> let b' = Seq.slice b consumed_x (Seq.length b) in parse_synth_eq (parse_bounded_integer_le 2 `parse_filter` (fun x -> U32.v x >= 253)) (fun x -> (x <: U32.t)) b'; parse_filter_eq (parse_bounded_integer_le 2) (fun x -> U32.v x >= 253) b'; parse_synth_eq (parse_bounded_integer_le 4 `parse_filter` (fun x -> U32.v x >= 65536)) (fun x -> (x <: U32.t)) b'; parse_filter_eq (parse_bounded_integer_le 4) (fun x -> U32.v x >= 65536) b' let bare_serialize_bcvli (x: U32.t) : GTot bytes = let c1 : bounded_integer 1 = if U32.v x <= 252 then x else if U32.v x <= 65535 then 253ul else 254ul in Seq.append (serialize (serialize_bounded_integer_le 1) c1) ( if U32.v c1 <= 252 then Seq.empty else if U32.v c1 = 253 then serialize (serialize_bounded_integer_le 2) x else serialize (serialize_bounded_integer_le 4) x ) #push-options "--z3rlimit 32" let bare_serialize_bcvli_correct : squash (serializer_correct parse_bcvli bare_serialize_bcvli) = let prf (x: U32.t) : Lemma (let y = bare_serialize_bcvli x in parse parse_bcvli y == Some (x, Seq.length y)) = let y = bare_serialize_bcvli x in let c1 : bounded_integer 1 = if U32.v x <= 252 then x else if U32.v x <= 65535 then 253ul else 254ul in let sc1 = serialize (serialize_bounded_integer_le 1) c1 in parse_strong_prefix (parse_bounded_integer_le 1) sc1 y; let y' = Seq.slice y (Seq.length sc1) (Seq.length y) in parse_bcvli_eq y; if U32.v c1 <= 252 then begin assert (y `Seq.equal` sc1) end else if U32.v c1 = 253 then begin assert (U32.v x <= 65535); assert (y' `Seq.equal` serialize (serialize_bounded_integer_le 2) x) end else begin assert (y' `Seq.equal` serialize (serialize_bounded_integer_le 4) x) end in Classical.forall_intro (Classical.move_requires prf) #pop-options
false
true
LowParse.Spec.BCVLI.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val serialize_bcvli : serializer parse_bcvli
[]
LowParse.Spec.BCVLI.serialize_bcvli
{ "file_name": "src/lowparse/LowParse.Spec.BCVLI.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
LowParse.Spec.Base.serializer LowParse.Spec.BCVLI.parse_bcvli
{ "end_col": 67, "end_line": 98, "start_col": 47, "start_line": 98 }
Prims.Tot
val parse_bounded_bcvli' (min: nat) (max: nat{min <= max}) : Tot (parser (parse_filter_kind parse_bcvli_kind) (bounded_int32 min max))
[ { "abbrev": false, "full_module": "LowParse.Spec.Combinators // for parse_ret", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "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 } ]
false
let parse_bounded_bcvli' (min: nat) (max: nat { min <= max }) : Tot (parser (parse_filter_kind parse_bcvli_kind) (bounded_int32 min max)) = parse_filter parse_bcvli (in_bounds min max)
val parse_bounded_bcvli' (min: nat) (max: nat{min <= max}) : Tot (parser (parse_filter_kind parse_bcvli_kind) (bounded_int32 min max)) let parse_bounded_bcvli' (min: nat) (max: nat{min <= max}) : Tot (parser (parse_filter_kind parse_bcvli_kind) (bounded_int32 min max)) =
false
null
false
parse_filter parse_bcvli (in_bounds min max)
{ "checked_file": "LowParse.Spec.BCVLI.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Spec.BCVLI.fst" }
[ "total" ]
[ "Prims.nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "LowParse.Spec.Combinators.parse_filter", "LowParse.Spec.BCVLI.parse_bcvli_kind", "FStar.UInt32.t", "LowParse.Spec.BCVLI.parse_bcvli", "LowParse.Spec.BoundedInt.in_bounds", "LowParse.Spec.Base.parser", "LowParse.Spec.Combinators.parse_filter_kind", "LowParse.Spec.BoundedInt.bounded_int32" ]
[]
module LowParse.Spec.BCVLI open LowParse.Spec.Combinators // for parse_ret module U32 = FStar.UInt32 module Seq = FStar.Seq inline_for_extraction let parse_bcvli_payload_kind = { parser_kind_low = 0; parser_kind_high = Some 4; parser_kind_subkind = Some ParserStrong; parser_kind_metadata = None; } let parse_bcvli_payload (x: bounded_integer 1) : Tot (parser parse_bcvli_payload_kind U32.t) = if U32.v x <= 252 then weaken parse_bcvli_payload_kind (parse_ret (x <: U32.t)) else if U32.v x = 253 then weaken parse_bcvli_payload_kind ((parse_bounded_integer_le 2 `parse_filter` (fun x -> U32.v x >= 253)) `parse_synth` (fun x -> (x <: U32.t))) else if U32.v x = 254 then weaken parse_bcvli_payload_kind ((parse_bounded_integer_le 4 `parse_filter` (fun x -> U32.v x >= 65536)) `parse_synth` (fun x -> (x <: U32.t))) else fail_parser parse_bcvli_payload_kind U32.t #push-options "--z3rlimit 32" let parse_bcvli_payload_and_then_cases_injective : squash (and_then_cases_injective parse_bcvli_payload) = and_then_cases_injective_intro parse_bcvli_payload (fun x1 x2 b1 b2 -> parse_synth_eq (parse_bounded_integer_le 2 `parse_filter` (fun x -> U32.v x >= 253)) (fun x -> (x <: U32.t)) b1; parse_synth_eq (parse_bounded_integer_le 2 `parse_filter` (fun x -> U32.v x >= 253)) (fun x -> (x <: U32.t)) b2; parse_synth_eq (parse_bounded_integer_le 4 `parse_filter` (fun x -> U32.v x >= 65536)) (fun x -> (x <: U32.t)) b1; parse_synth_eq (parse_bounded_integer_le 4 `parse_filter` (fun x -> U32.v x >= 65536)) (fun x -> (x <: U32.t)) b2 ) #pop-options let parse_bcvli : parser parse_bcvli_kind U32.t = parse_bounded_integer_le 1 `and_then` parse_bcvli_payload let parse_bcvli_eq b = and_then_eq (parse_bounded_integer_le 1) parse_bcvli_payload b; match parse (parse_bounded_integer_le 1) b with | None -> () | Some (x32, consumed_x) -> let b' = Seq.slice b consumed_x (Seq.length b) in parse_synth_eq (parse_bounded_integer_le 2 `parse_filter` (fun x -> U32.v x >= 253)) (fun x -> (x <: U32.t)) b'; parse_filter_eq (parse_bounded_integer_le 2) (fun x -> U32.v x >= 253) b'; parse_synth_eq (parse_bounded_integer_le 4 `parse_filter` (fun x -> U32.v x >= 65536)) (fun x -> (x <: U32.t)) b'; parse_filter_eq (parse_bounded_integer_le 4) (fun x -> U32.v x >= 65536) b' let bare_serialize_bcvli (x: U32.t) : GTot bytes = let c1 : bounded_integer 1 = if U32.v x <= 252 then x else if U32.v x <= 65535 then 253ul else 254ul in Seq.append (serialize (serialize_bounded_integer_le 1) c1) ( if U32.v c1 <= 252 then Seq.empty else if U32.v c1 = 253 then serialize (serialize_bounded_integer_le 2) x else serialize (serialize_bounded_integer_le 4) x ) #push-options "--z3rlimit 32" let bare_serialize_bcvli_correct : squash (serializer_correct parse_bcvli bare_serialize_bcvli) = let prf (x: U32.t) : Lemma (let y = bare_serialize_bcvli x in parse parse_bcvli y == Some (x, Seq.length y)) = let y = bare_serialize_bcvli x in let c1 : bounded_integer 1 = if U32.v x <= 252 then x else if U32.v x <= 65535 then 253ul else 254ul in let sc1 = serialize (serialize_bounded_integer_le 1) c1 in parse_strong_prefix (parse_bounded_integer_le 1) sc1 y; let y' = Seq.slice y (Seq.length sc1) (Seq.length y) in parse_bcvli_eq y; if U32.v c1 <= 252 then begin assert (y `Seq.equal` sc1) end else if U32.v c1 = 253 then begin assert (U32.v x <= 65535); assert (y' `Seq.equal` serialize (serialize_bounded_integer_le 2) x) end else begin assert (y' `Seq.equal` serialize (serialize_bounded_integer_le 4) x) end in Classical.forall_intro (Classical.move_requires prf) #pop-options let serialize_bcvli : serializer parse_bcvli = bare_serialize_bcvli let serialize_bcvli_eq x = () let parse_bounded_bcvli' (min: nat) (max: nat { min <= max })
false
false
LowParse.Spec.BCVLI.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val parse_bounded_bcvli' (min: nat) (max: nat{min <= max}) : Tot (parser (parse_filter_kind parse_bcvli_kind) (bounded_int32 min max))
[]
LowParse.Spec.BCVLI.parse_bounded_bcvli'
{ "file_name": "src/lowparse/LowParse.Spec.BCVLI.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
min: Prims.nat -> max: Prims.nat{min <= max} -> LowParse.Spec.Base.parser (LowParse.Spec.Combinators.parse_filter_kind LowParse.Spec.BCVLI.parse_bcvli_kind ) (LowParse.Spec.BoundedInt.bounded_int32 min max)
{ "end_col": 46, "end_line": 106, "start_col": 2, "start_line": 106 }
FStar.Pervasives.Lemma
val parse_bounded_bcvli_eq (min: nat) (max: nat { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_bcvli min max) input == ( match parse parse_bcvli input with | Some (n, consumed) -> if in_bounds min max n then Some (n, consumed) else None | _ -> None ))
[ { "abbrev": false, "full_module": "LowParse.Spec.Combinators // for parse_ret", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "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 } ]
false
let parse_bounded_bcvli_eq min max input = parse_filter_eq parse_bcvli (in_bounds min max) input; parse_bcvli_eq input
val parse_bounded_bcvli_eq (min: nat) (max: nat { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_bcvli min max) input == ( match parse parse_bcvli input with | Some (n, consumed) -> if in_bounds min max n then Some (n, consumed) else None | _ -> None )) let parse_bounded_bcvli_eq min max input =
false
null
true
parse_filter_eq parse_bcvli (in_bounds min max) input; parse_bcvli_eq input
{ "checked_file": "LowParse.Spec.BCVLI.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Spec.BCVLI.fst" }
[ "lemma" ]
[ "Prims.nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "LowParse.Bytes.bytes", "LowParse.Spec.BCVLI.parse_bcvli_eq", "Prims.unit", "LowParse.Spec.Combinators.parse_filter_eq", "LowParse.Spec.BCVLI.parse_bcvli_kind", "FStar.UInt32.t", "LowParse.Spec.BCVLI.parse_bcvli", "LowParse.Spec.BoundedInt.in_bounds" ]
[]
module LowParse.Spec.BCVLI open LowParse.Spec.Combinators // for parse_ret module U32 = FStar.UInt32 module Seq = FStar.Seq inline_for_extraction let parse_bcvli_payload_kind = { parser_kind_low = 0; parser_kind_high = Some 4; parser_kind_subkind = Some ParserStrong; parser_kind_metadata = None; } let parse_bcvli_payload (x: bounded_integer 1) : Tot (parser parse_bcvli_payload_kind U32.t) = if U32.v x <= 252 then weaken parse_bcvli_payload_kind (parse_ret (x <: U32.t)) else if U32.v x = 253 then weaken parse_bcvli_payload_kind ((parse_bounded_integer_le 2 `parse_filter` (fun x -> U32.v x >= 253)) `parse_synth` (fun x -> (x <: U32.t))) else if U32.v x = 254 then weaken parse_bcvli_payload_kind ((parse_bounded_integer_le 4 `parse_filter` (fun x -> U32.v x >= 65536)) `parse_synth` (fun x -> (x <: U32.t))) else fail_parser parse_bcvli_payload_kind U32.t #push-options "--z3rlimit 32" let parse_bcvli_payload_and_then_cases_injective : squash (and_then_cases_injective parse_bcvli_payload) = and_then_cases_injective_intro parse_bcvli_payload (fun x1 x2 b1 b2 -> parse_synth_eq (parse_bounded_integer_le 2 `parse_filter` (fun x -> U32.v x >= 253)) (fun x -> (x <: U32.t)) b1; parse_synth_eq (parse_bounded_integer_le 2 `parse_filter` (fun x -> U32.v x >= 253)) (fun x -> (x <: U32.t)) b2; parse_synth_eq (parse_bounded_integer_le 4 `parse_filter` (fun x -> U32.v x >= 65536)) (fun x -> (x <: U32.t)) b1; parse_synth_eq (parse_bounded_integer_le 4 `parse_filter` (fun x -> U32.v x >= 65536)) (fun x -> (x <: U32.t)) b2 ) #pop-options let parse_bcvli : parser parse_bcvli_kind U32.t = parse_bounded_integer_le 1 `and_then` parse_bcvli_payload let parse_bcvli_eq b = and_then_eq (parse_bounded_integer_le 1) parse_bcvli_payload b; match parse (parse_bounded_integer_le 1) b with | None -> () | Some (x32, consumed_x) -> let b' = Seq.slice b consumed_x (Seq.length b) in parse_synth_eq (parse_bounded_integer_le 2 `parse_filter` (fun x -> U32.v x >= 253)) (fun x -> (x <: U32.t)) b'; parse_filter_eq (parse_bounded_integer_le 2) (fun x -> U32.v x >= 253) b'; parse_synth_eq (parse_bounded_integer_le 4 `parse_filter` (fun x -> U32.v x >= 65536)) (fun x -> (x <: U32.t)) b'; parse_filter_eq (parse_bounded_integer_le 4) (fun x -> U32.v x >= 65536) b' let bare_serialize_bcvli (x: U32.t) : GTot bytes = let c1 : bounded_integer 1 = if U32.v x <= 252 then x else if U32.v x <= 65535 then 253ul else 254ul in Seq.append (serialize (serialize_bounded_integer_le 1) c1) ( if U32.v c1 <= 252 then Seq.empty else if U32.v c1 = 253 then serialize (serialize_bounded_integer_le 2) x else serialize (serialize_bounded_integer_le 4) x ) #push-options "--z3rlimit 32" let bare_serialize_bcvli_correct : squash (serializer_correct parse_bcvli bare_serialize_bcvli) = let prf (x: U32.t) : Lemma (let y = bare_serialize_bcvli x in parse parse_bcvli y == Some (x, Seq.length y)) = let y = bare_serialize_bcvli x in let c1 : bounded_integer 1 = if U32.v x <= 252 then x else if U32.v x <= 65535 then 253ul else 254ul in let sc1 = serialize (serialize_bounded_integer_le 1) c1 in parse_strong_prefix (parse_bounded_integer_le 1) sc1 y; let y' = Seq.slice y (Seq.length sc1) (Seq.length y) in parse_bcvli_eq y; if U32.v c1 <= 252 then begin assert (y `Seq.equal` sc1) end else if U32.v c1 = 253 then begin assert (U32.v x <= 65535); assert (y' `Seq.equal` serialize (serialize_bounded_integer_le 2) x) end else begin assert (y' `Seq.equal` serialize (serialize_bounded_integer_le 4) x) end in Classical.forall_intro (Classical.move_requires prf) #pop-options let serialize_bcvli : serializer parse_bcvli = bare_serialize_bcvli let serialize_bcvli_eq x = () let parse_bounded_bcvli' (min: nat) (max: nat { min <= max }) : Tot (parser (parse_filter_kind parse_bcvli_kind) (bounded_int32 min max)) = parse_filter parse_bcvli (in_bounds min max) let parse_bounded_bcvli_size_correct (min: nat) (max: nat { min <= max }) : Lemma (parse_bounded_bcvli_size min `parses_at_least` parse_bounded_bcvli' min max /\ parse_bounded_bcvli_size max `parses_at_most` parse_bounded_bcvli' min max) = Classical.forall_intro (parse_filter_eq parse_bcvli (in_bounds min max)); Classical.forall_intro parse_bcvli_eq; parser_kind_prop_equiv (parse_bounded_integer_kind 1) (parse_bounded_integer_le 1); parser_kind_prop_equiv (parse_bounded_integer_kind 2) (parse_bounded_integer_le 2); parser_kind_prop_equiv (parse_bounded_integer_kind 4) (parse_bounded_integer_le 4) let parse_bounded_bcvli_kind_correct (min: nat) (max: nat { min <= max }) : Lemma (parser_kind_prop (parse_bounded_bcvli_kind min max) (parse_bounded_bcvli' min max)) = parse_bounded_bcvli_size_correct min max; parser_kind_prop_equiv (parse_filter_kind parse_bcvli_kind) (parse_bounded_bcvli' min max); parser_kind_prop_equiv (parse_bounded_bcvli_kind min max) (parse_bounded_bcvli' min max) let parse_bounded_bcvli min max = parse_bounded_bcvli_kind_correct min max; strengthen (parse_bounded_bcvli_kind min max) (parse_bounded_bcvli' min max) let parse_bounded_bcvli_eq
false
false
LowParse.Spec.BCVLI.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val parse_bounded_bcvli_eq (min: nat) (max: nat { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_bcvli min max) input == ( match parse parse_bcvli input with | Some (n, consumed) -> if in_bounds min max n then Some (n, consumed) else None | _ -> None ))
[]
LowParse.Spec.BCVLI.parse_bounded_bcvli_eq
{ "file_name": "src/lowparse/LowParse.Spec.BCVLI.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
min: Prims.nat -> max: Prims.nat{min <= max} -> input: LowParse.Bytes.bytes -> FStar.Pervasives.Lemma (ensures LowParse.Spec.Base.parse (LowParse.Spec.BCVLI.parse_bounded_bcvli min max) input == (match LowParse.Spec.Base.parse LowParse.Spec.BCVLI.parse_bcvli input with | FStar.Pervasives.Native.Some #_ (FStar.Pervasives.Native.Mktuple2 #_ #_ n consumed) -> (match LowParse.Spec.BoundedInt.in_bounds min max n with | true -> FStar.Pervasives.Native.Some (n, consumed) | _ -> FStar.Pervasives.Native.None) <: FStar.Pervasives.Native.option (LowParse.Spec.BoundedInt.bounded_int32 min max * LowParse.Spec.Base.consumed_length input) | _ -> FStar.Pervasives.Native.None))
{ "end_col": 22, "end_line": 137, "start_col": 2, "start_line": 136 }
Prims.Tot
val parse_bcvli : parser parse_bcvli_kind U32.t
[ { "abbrev": false, "full_module": "LowParse.Spec.Combinators // for parse_ret", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "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 } ]
false
let parse_bcvli : parser parse_bcvli_kind U32.t = parse_bounded_integer_le 1 `and_then` parse_bcvli_payload
val parse_bcvli : parser parse_bcvli_kind U32.t let parse_bcvli:parser parse_bcvli_kind U32.t =
false
null
false
(parse_bounded_integer_le 1) `and_then` parse_bcvli_payload
{ "checked_file": "LowParse.Spec.BCVLI.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Spec.BCVLI.fst" }
[ "total" ]
[ "LowParse.Spec.Combinators.and_then", "LowParse.Spec.BoundedInt.parse_bounded_integer_kind", "LowParse.Spec.BoundedInt.bounded_integer", "LowParse.Spec.BoundedInt.parse_bounded_integer_le", "LowParse.Spec.BCVLI.parse_bcvli_payload_kind", "FStar.UInt32.t", "LowParse.Spec.BCVLI.parse_bcvli_payload", "LowParse.Spec.Base.parser", "LowParse.Spec.BCVLI.parse_bcvli_kind" ]
[]
module LowParse.Spec.BCVLI open LowParse.Spec.Combinators // for parse_ret module U32 = FStar.UInt32 module Seq = FStar.Seq inline_for_extraction let parse_bcvli_payload_kind = { parser_kind_low = 0; parser_kind_high = Some 4; parser_kind_subkind = Some ParserStrong; parser_kind_metadata = None; } let parse_bcvli_payload (x: bounded_integer 1) : Tot (parser parse_bcvli_payload_kind U32.t) = if U32.v x <= 252 then weaken parse_bcvli_payload_kind (parse_ret (x <: U32.t)) else if U32.v x = 253 then weaken parse_bcvli_payload_kind ((parse_bounded_integer_le 2 `parse_filter` (fun x -> U32.v x >= 253)) `parse_synth` (fun x -> (x <: U32.t))) else if U32.v x = 254 then weaken parse_bcvli_payload_kind ((parse_bounded_integer_le 4 `parse_filter` (fun x -> U32.v x >= 65536)) `parse_synth` (fun x -> (x <: U32.t))) else fail_parser parse_bcvli_payload_kind U32.t #push-options "--z3rlimit 32" let parse_bcvli_payload_and_then_cases_injective : squash (and_then_cases_injective parse_bcvli_payload) = and_then_cases_injective_intro parse_bcvli_payload (fun x1 x2 b1 b2 -> parse_synth_eq (parse_bounded_integer_le 2 `parse_filter` (fun x -> U32.v x >= 253)) (fun x -> (x <: U32.t)) b1; parse_synth_eq (parse_bounded_integer_le 2 `parse_filter` (fun x -> U32.v x >= 253)) (fun x -> (x <: U32.t)) b2; parse_synth_eq (parse_bounded_integer_le 4 `parse_filter` (fun x -> U32.v x >= 65536)) (fun x -> (x <: U32.t)) b1; parse_synth_eq (parse_bounded_integer_le 4 `parse_filter` (fun x -> U32.v x >= 65536)) (fun x -> (x <: U32.t)) b2 ) #pop-options
false
true
LowParse.Spec.BCVLI.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val parse_bcvli : parser parse_bcvli_kind U32.t
[]
LowParse.Spec.BCVLI.parse_bcvli
{ "file_name": "src/lowparse/LowParse.Spec.BCVLI.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
LowParse.Spec.Base.parser LowParse.Spec.BCVLI.parse_bcvli_kind FStar.UInt32.t
{ "end_col": 59, "end_line": 34, "start_col": 2, "start_line": 34 }
Prims.Tot
val parse_bcvli_payload (x: bounded_integer 1) : Tot (parser parse_bcvli_payload_kind U32.t)
[ { "abbrev": false, "full_module": "LowParse.Spec.Combinators // for parse_ret", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "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 } ]
false
let parse_bcvli_payload (x: bounded_integer 1) : Tot (parser parse_bcvli_payload_kind U32.t) = if U32.v x <= 252 then weaken parse_bcvli_payload_kind (parse_ret (x <: U32.t)) else if U32.v x = 253 then weaken parse_bcvli_payload_kind ((parse_bounded_integer_le 2 `parse_filter` (fun x -> U32.v x >= 253)) `parse_synth` (fun x -> (x <: U32.t))) else if U32.v x = 254 then weaken parse_bcvli_payload_kind ((parse_bounded_integer_le 4 `parse_filter` (fun x -> U32.v x >= 65536)) `parse_synth` (fun x -> (x <: U32.t))) else fail_parser parse_bcvli_payload_kind U32.t
val parse_bcvli_payload (x: bounded_integer 1) : Tot (parser parse_bcvli_payload_kind U32.t) let parse_bcvli_payload (x: bounded_integer 1) : Tot (parser parse_bcvli_payload_kind U32.t) =
false
null
false
if U32.v x <= 252 then weaken parse_bcvli_payload_kind (parse_ret (x <: U32.t)) else if U32.v x = 253 then weaken parse_bcvli_payload_kind (((parse_bounded_integer_le 2) `parse_filter` (fun x -> U32.v x >= 253)) `parse_synth` (fun x -> (x <: U32.t))) else if U32.v x = 254 then weaken parse_bcvli_payload_kind (((parse_bounded_integer_le 4) `parse_filter` (fun x -> U32.v x >= 65536)) `parse_synth` (fun x -> (x <: U32.t))) else fail_parser parse_bcvli_payload_kind U32.t
{ "checked_file": "LowParse.Spec.BCVLI.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Spec.BCVLI.fst" }
[ "total" ]
[ "LowParse.Spec.BoundedInt.bounded_integer", "Prims.op_LessThanOrEqual", "FStar.UInt32.v", "LowParse.Spec.Base.weaken", "LowParse.Spec.BCVLI.parse_bcvli_payload_kind", "LowParse.Spec.Combinators.parse_ret_kind", "FStar.UInt32.t", "LowParse.Spec.Combinators.parse_ret", "Prims.bool", "Prims.op_Equality", "Prims.int", "LowParse.Spec.Combinators.parse_filter_kind", "LowParse.Spec.BoundedInt.parse_bounded_integer_kind", "LowParse.Spec.Combinators.parse_synth", "LowParse.Spec.Combinators.parse_filter_refine", "Prims.op_GreaterThanOrEqual", "LowParse.Spec.Combinators.parse_filter", "LowParse.Spec.BoundedInt.parse_bounded_integer_le", "LowParse.Spec.Combinators.fail_parser", "LowParse.Spec.Base.parser" ]
[]
module LowParse.Spec.BCVLI open LowParse.Spec.Combinators // for parse_ret module U32 = FStar.UInt32 module Seq = FStar.Seq inline_for_extraction let parse_bcvli_payload_kind = { parser_kind_low = 0; parser_kind_high = Some 4; parser_kind_subkind = Some ParserStrong; parser_kind_metadata = None; }
false
false
LowParse.Spec.BCVLI.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val parse_bcvli_payload (x: bounded_integer 1) : Tot (parser parse_bcvli_payload_kind U32.t)
[]
LowParse.Spec.BCVLI.parse_bcvli_payload
{ "file_name": "src/lowparse/LowParse.Spec.BCVLI.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
x: LowParse.Spec.BoundedInt.bounded_integer 1 -> LowParse.Spec.Base.parser LowParse.Spec.BCVLI.parse_bcvli_payload_kind FStar.UInt32.t
{ "end_col": 44, "end_line": 19, "start_col": 2, "start_line": 16 }
FStar.Pervasives.Lemma
val parse_bounded_bcvli_size_correct (min: nat) (max: nat{min <= max}) : Lemma ((parse_bounded_bcvli_size min) `parses_at_least` (parse_bounded_bcvli' min max) /\ (parse_bounded_bcvli_size max) `parses_at_most` (parse_bounded_bcvli' min max))
[ { "abbrev": false, "full_module": "LowParse.Spec.Combinators // for parse_ret", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "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 } ]
false
let parse_bounded_bcvli_size_correct (min: nat) (max: nat { min <= max }) : Lemma (parse_bounded_bcvli_size min `parses_at_least` parse_bounded_bcvli' min max /\ parse_bounded_bcvli_size max `parses_at_most` parse_bounded_bcvli' min max) = Classical.forall_intro (parse_filter_eq parse_bcvli (in_bounds min max)); Classical.forall_intro parse_bcvli_eq; parser_kind_prop_equiv (parse_bounded_integer_kind 1) (parse_bounded_integer_le 1); parser_kind_prop_equiv (parse_bounded_integer_kind 2) (parse_bounded_integer_le 2); parser_kind_prop_equiv (parse_bounded_integer_kind 4) (parse_bounded_integer_le 4)
val parse_bounded_bcvli_size_correct (min: nat) (max: nat{min <= max}) : Lemma ((parse_bounded_bcvli_size min) `parses_at_least` (parse_bounded_bcvli' min max) /\ (parse_bounded_bcvli_size max) `parses_at_most` (parse_bounded_bcvli' min max)) let parse_bounded_bcvli_size_correct (min: nat) (max: nat{min <= max}) : Lemma ((parse_bounded_bcvli_size min) `parses_at_least` (parse_bounded_bcvli' min max) /\ (parse_bounded_bcvli_size max) `parses_at_most` (parse_bounded_bcvli' min max)) =
false
null
true
Classical.forall_intro (parse_filter_eq parse_bcvli (in_bounds min max)); Classical.forall_intro parse_bcvli_eq; parser_kind_prop_equiv (parse_bounded_integer_kind 1) (parse_bounded_integer_le 1); parser_kind_prop_equiv (parse_bounded_integer_kind 2) (parse_bounded_integer_le 2); parser_kind_prop_equiv (parse_bounded_integer_kind 4) (parse_bounded_integer_le 4)
{ "checked_file": "LowParse.Spec.BCVLI.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Spec.BCVLI.fst" }
[ "lemma" ]
[ "Prims.nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "LowParse.Spec.Base.parser_kind_prop_equiv", "LowParse.Spec.BoundedInt.bounded_integer", "LowParse.Spec.BoundedInt.parse_bounded_integer_kind", "LowParse.Spec.BoundedInt.parse_bounded_integer_le", "Prims.unit", "FStar.Classical.forall_intro", "LowParse.Bytes.bytes", "Prims.eq2", "FStar.Pervasives.Native.option", "FStar.Pervasives.Native.tuple2", "FStar.UInt32.t", "LowParse.Spec.Base.consumed_length", "LowParse.Spec.Base.parse", "LowParse.Spec.BCVLI.parse_bcvli", "FStar.Pervasives.Native.None", "FStar.UInt32.v", "FStar.Pervasives.Native.Some", "FStar.Pervasives.Native.Mktuple2", "Prims.bool", "Prims.op_Equality", "Prims.int", "FStar.Seq.Base.slice", "LowParse.Bytes.byte", "FStar.Seq.Base.length", "Prims.op_LessThan", "Prims.op_Addition", "LowParse.Spec.BCVLI.parse_bcvli_eq", "LowParse.Spec.Combinators.parse_filter_refine", "LowParse.Spec.BoundedInt.in_bounds", "LowParse.Spec.Combinators.parse_filter", "LowParse.Spec.BCVLI.parse_bcvli_kind", "LowParse.Spec.Combinators.parse_filter_eq", "Prims.l_True", "Prims.squash", "Prims.l_and", "LowParse.Spec.Base.parses_at_least", "LowParse.Spec.BCVLI.parse_bounded_bcvli_size", "LowParse.Spec.BoundedInt.bounded_int32", "LowParse.Spec.BCVLI.parse_bounded_bcvli'", "LowParse.Spec.Base.parses_at_most", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module LowParse.Spec.BCVLI open LowParse.Spec.Combinators // for parse_ret module U32 = FStar.UInt32 module Seq = FStar.Seq inline_for_extraction let parse_bcvli_payload_kind = { parser_kind_low = 0; parser_kind_high = Some 4; parser_kind_subkind = Some ParserStrong; parser_kind_metadata = None; } let parse_bcvli_payload (x: bounded_integer 1) : Tot (parser parse_bcvli_payload_kind U32.t) = if U32.v x <= 252 then weaken parse_bcvli_payload_kind (parse_ret (x <: U32.t)) else if U32.v x = 253 then weaken parse_bcvli_payload_kind ((parse_bounded_integer_le 2 `parse_filter` (fun x -> U32.v x >= 253)) `parse_synth` (fun x -> (x <: U32.t))) else if U32.v x = 254 then weaken parse_bcvli_payload_kind ((parse_bounded_integer_le 4 `parse_filter` (fun x -> U32.v x >= 65536)) `parse_synth` (fun x -> (x <: U32.t))) else fail_parser parse_bcvli_payload_kind U32.t #push-options "--z3rlimit 32" let parse_bcvli_payload_and_then_cases_injective : squash (and_then_cases_injective parse_bcvli_payload) = and_then_cases_injective_intro parse_bcvli_payload (fun x1 x2 b1 b2 -> parse_synth_eq (parse_bounded_integer_le 2 `parse_filter` (fun x -> U32.v x >= 253)) (fun x -> (x <: U32.t)) b1; parse_synth_eq (parse_bounded_integer_le 2 `parse_filter` (fun x -> U32.v x >= 253)) (fun x -> (x <: U32.t)) b2; parse_synth_eq (parse_bounded_integer_le 4 `parse_filter` (fun x -> U32.v x >= 65536)) (fun x -> (x <: U32.t)) b1; parse_synth_eq (parse_bounded_integer_le 4 `parse_filter` (fun x -> U32.v x >= 65536)) (fun x -> (x <: U32.t)) b2 ) #pop-options let parse_bcvli : parser parse_bcvli_kind U32.t = parse_bounded_integer_le 1 `and_then` parse_bcvli_payload let parse_bcvli_eq b = and_then_eq (parse_bounded_integer_le 1) parse_bcvli_payload b; match parse (parse_bounded_integer_le 1) b with | None -> () | Some (x32, consumed_x) -> let b' = Seq.slice b consumed_x (Seq.length b) in parse_synth_eq (parse_bounded_integer_le 2 `parse_filter` (fun x -> U32.v x >= 253)) (fun x -> (x <: U32.t)) b'; parse_filter_eq (parse_bounded_integer_le 2) (fun x -> U32.v x >= 253) b'; parse_synth_eq (parse_bounded_integer_le 4 `parse_filter` (fun x -> U32.v x >= 65536)) (fun x -> (x <: U32.t)) b'; parse_filter_eq (parse_bounded_integer_le 4) (fun x -> U32.v x >= 65536) b' let bare_serialize_bcvli (x: U32.t) : GTot bytes = let c1 : bounded_integer 1 = if U32.v x <= 252 then x else if U32.v x <= 65535 then 253ul else 254ul in Seq.append (serialize (serialize_bounded_integer_le 1) c1) ( if U32.v c1 <= 252 then Seq.empty else if U32.v c1 = 253 then serialize (serialize_bounded_integer_le 2) x else serialize (serialize_bounded_integer_le 4) x ) #push-options "--z3rlimit 32" let bare_serialize_bcvli_correct : squash (serializer_correct parse_bcvli bare_serialize_bcvli) = let prf (x: U32.t) : Lemma (let y = bare_serialize_bcvli x in parse parse_bcvli y == Some (x, Seq.length y)) = let y = bare_serialize_bcvli x in let c1 : bounded_integer 1 = if U32.v x <= 252 then x else if U32.v x <= 65535 then 253ul else 254ul in let sc1 = serialize (serialize_bounded_integer_le 1) c1 in parse_strong_prefix (parse_bounded_integer_le 1) sc1 y; let y' = Seq.slice y (Seq.length sc1) (Seq.length y) in parse_bcvli_eq y; if U32.v c1 <= 252 then begin assert (y `Seq.equal` sc1) end else if U32.v c1 = 253 then begin assert (U32.v x <= 65535); assert (y' `Seq.equal` serialize (serialize_bounded_integer_le 2) x) end else begin assert (y' `Seq.equal` serialize (serialize_bounded_integer_le 4) x) end in Classical.forall_intro (Classical.move_requires prf) #pop-options let serialize_bcvli : serializer parse_bcvli = bare_serialize_bcvli let serialize_bcvli_eq x = () let parse_bounded_bcvli' (min: nat) (max: nat { min <= max }) : Tot (parser (parse_filter_kind parse_bcvli_kind) (bounded_int32 min max)) = parse_filter parse_bcvli (in_bounds min max) let parse_bounded_bcvli_size_correct (min: nat) (max: nat { min <= max }) : Lemma (parse_bounded_bcvli_size min `parses_at_least` parse_bounded_bcvli' min max /\
false
false
LowParse.Spec.BCVLI.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val parse_bounded_bcvli_size_correct (min: nat) (max: nat{min <= max}) : Lemma ((parse_bounded_bcvli_size min) `parses_at_least` (parse_bounded_bcvli' min max) /\ (parse_bounded_bcvli_size max) `parses_at_most` (parse_bounded_bcvli' min max))
[]
LowParse.Spec.BCVLI.parse_bounded_bcvli_size_correct
{ "file_name": "src/lowparse/LowParse.Spec.BCVLI.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
min: Prims.nat -> max: Prims.nat{min <= max} -> FStar.Pervasives.Lemma (ensures LowParse.Spec.Base.parses_at_least (LowParse.Spec.BCVLI.parse_bounded_bcvli_size min) (LowParse.Spec.BCVLI.parse_bounded_bcvli' min max) /\ LowParse.Spec.Base.parses_at_most (LowParse.Spec.BCVLI.parse_bounded_bcvli_size max) (LowParse.Spec.BCVLI.parse_bounded_bcvli' min max))
{ "end_col": 84, "end_line": 118, "start_col": 2, "start_line": 114 }
FStar.Pervasives.Lemma
val parse_bcvli_eq (b: bytes) : Lemma (parse parse_bcvli b == (match parse (parse_bounded_integer_le 1) b with | None -> None | Some (x32, consumed_x) -> let x = U32.v x32 in if x <= 252 then Some (x32, consumed_x) else let b' = Seq.slice b consumed_x (Seq.length b) in if x = 253 then match parse (parse_bounded_integer_le 2) b' with | None -> None | Some (y, consumed_y) -> if U32.v y < 253 then None (* redundant representations not supported, non-malleability *) else Some (y, consumed_x + consumed_y) else if x = 254 then match parse (parse_bounded_integer_le 4) b' with | None -> None | Some (y, consumed_y) -> if U32.v y < 65536 then None (* redundant representations not supported, non-malleability *) else Some (y, consumed_x + consumed_y) else None (* 64-bit integers not supported *) ))
[ { "abbrev": false, "full_module": "LowParse.Spec.Combinators // for parse_ret", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "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 } ]
false
let parse_bcvli_eq b = and_then_eq (parse_bounded_integer_le 1) parse_bcvli_payload b; match parse (parse_bounded_integer_le 1) b with | None -> () | Some (x32, consumed_x) -> let b' = Seq.slice b consumed_x (Seq.length b) in parse_synth_eq (parse_bounded_integer_le 2 `parse_filter` (fun x -> U32.v x >= 253)) (fun x -> (x <: U32.t)) b'; parse_filter_eq (parse_bounded_integer_le 2) (fun x -> U32.v x >= 253) b'; parse_synth_eq (parse_bounded_integer_le 4 `parse_filter` (fun x -> U32.v x >= 65536)) (fun x -> (x <: U32.t)) b'; parse_filter_eq (parse_bounded_integer_le 4) (fun x -> U32.v x >= 65536) b'
val parse_bcvli_eq (b: bytes) : Lemma (parse parse_bcvli b == (match parse (parse_bounded_integer_le 1) b with | None -> None | Some (x32, consumed_x) -> let x = U32.v x32 in if x <= 252 then Some (x32, consumed_x) else let b' = Seq.slice b consumed_x (Seq.length b) in if x = 253 then match parse (parse_bounded_integer_le 2) b' with | None -> None | Some (y, consumed_y) -> if U32.v y < 253 then None (* redundant representations not supported, non-malleability *) else Some (y, consumed_x + consumed_y) else if x = 254 then match parse (parse_bounded_integer_le 4) b' with | None -> None | Some (y, consumed_y) -> if U32.v y < 65536 then None (* redundant representations not supported, non-malleability *) else Some (y, consumed_x + consumed_y) else None (* 64-bit integers not supported *) )) let parse_bcvli_eq b =
false
null
true
and_then_eq (parse_bounded_integer_le 1) parse_bcvli_payload b; match parse (parse_bounded_integer_le 1) b with | None -> () | Some (x32, consumed_x) -> let b' = Seq.slice b consumed_x (Seq.length b) in parse_synth_eq ((parse_bounded_integer_le 2) `parse_filter` (fun x -> U32.v x >= 253)) (fun x -> (x <: U32.t)) b'; parse_filter_eq (parse_bounded_integer_le 2) (fun x -> U32.v x >= 253) b'; parse_synth_eq ((parse_bounded_integer_le 4) `parse_filter` (fun x -> U32.v x >= 65536)) (fun x -> (x <: U32.t)) b'; parse_filter_eq (parse_bounded_integer_le 4) (fun x -> U32.v x >= 65536) b'
{ "checked_file": "LowParse.Spec.BCVLI.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Spec.BCVLI.fst" }
[ "lemma" ]
[ "LowParse.Bytes.bytes", "LowParse.Spec.Base.parse", "LowParse.Spec.BoundedInt.bounded_integer", "LowParse.Spec.BoundedInt.parse_bounded_integer_le", "LowParse.Spec.Base.consumed_length", "LowParse.Spec.Combinators.parse_filter_eq", "LowParse.Spec.BoundedInt.parse_bounded_integer_kind", "Prims.op_GreaterThanOrEqual", "FStar.UInt32.v", "Prims.bool", "Prims.unit", "LowParse.Spec.Combinators.parse_synth_eq", "LowParse.Spec.Combinators.parse_filter_kind", "LowParse.Spec.Combinators.parse_filter_refine", "FStar.UInt32.t", "LowParse.Spec.Combinators.parse_filter", "FStar.Seq.Base.seq", "LowParse.Bytes.byte", "FStar.Seq.Base.slice", "FStar.Seq.Base.length", "LowParse.Spec.Combinators.and_then_eq", "LowParse.Spec.BCVLI.parse_bcvli_payload_kind", "LowParse.Spec.BCVLI.parse_bcvli_payload" ]
[]
module LowParse.Spec.BCVLI open LowParse.Spec.Combinators // for parse_ret module U32 = FStar.UInt32 module Seq = FStar.Seq inline_for_extraction let parse_bcvli_payload_kind = { parser_kind_low = 0; parser_kind_high = Some 4; parser_kind_subkind = Some ParserStrong; parser_kind_metadata = None; } let parse_bcvli_payload (x: bounded_integer 1) : Tot (parser parse_bcvli_payload_kind U32.t) = if U32.v x <= 252 then weaken parse_bcvli_payload_kind (parse_ret (x <: U32.t)) else if U32.v x = 253 then weaken parse_bcvli_payload_kind ((parse_bounded_integer_le 2 `parse_filter` (fun x -> U32.v x >= 253)) `parse_synth` (fun x -> (x <: U32.t))) else if U32.v x = 254 then weaken parse_bcvli_payload_kind ((parse_bounded_integer_le 4 `parse_filter` (fun x -> U32.v x >= 65536)) `parse_synth` (fun x -> (x <: U32.t))) else fail_parser parse_bcvli_payload_kind U32.t #push-options "--z3rlimit 32" let parse_bcvli_payload_and_then_cases_injective : squash (and_then_cases_injective parse_bcvli_payload) = and_then_cases_injective_intro parse_bcvli_payload (fun x1 x2 b1 b2 -> parse_synth_eq (parse_bounded_integer_le 2 `parse_filter` (fun x -> U32.v x >= 253)) (fun x -> (x <: U32.t)) b1; parse_synth_eq (parse_bounded_integer_le 2 `parse_filter` (fun x -> U32.v x >= 253)) (fun x -> (x <: U32.t)) b2; parse_synth_eq (parse_bounded_integer_le 4 `parse_filter` (fun x -> U32.v x >= 65536)) (fun x -> (x <: U32.t)) b1; parse_synth_eq (parse_bounded_integer_le 4 `parse_filter` (fun x -> U32.v x >= 65536)) (fun x -> (x <: U32.t)) b2 ) #pop-options let parse_bcvli : parser parse_bcvli_kind U32.t = parse_bounded_integer_le 1 `and_then` parse_bcvli_payload let parse_bcvli_eq
false
false
LowParse.Spec.BCVLI.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val parse_bcvli_eq (b: bytes) : Lemma (parse parse_bcvli b == (match parse (parse_bounded_integer_le 1) b with | None -> None | Some (x32, consumed_x) -> let x = U32.v x32 in if x <= 252 then Some (x32, consumed_x) else let b' = Seq.slice b consumed_x (Seq.length b) in if x = 253 then match parse (parse_bounded_integer_le 2) b' with | None -> None | Some (y, consumed_y) -> if U32.v y < 253 then None (* redundant representations not supported, non-malleability *) else Some (y, consumed_x + consumed_y) else if x = 254 then match parse (parse_bounded_integer_le 4) b' with | None -> None | Some (y, consumed_y) -> if U32.v y < 65536 then None (* redundant representations not supported, non-malleability *) else Some (y, consumed_x + consumed_y) else None (* 64-bit integers not supported *) ))
[]
LowParse.Spec.BCVLI.parse_bcvli_eq
{ "file_name": "src/lowparse/LowParse.Spec.BCVLI.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
b: LowParse.Bytes.bytes -> FStar.Pervasives.Lemma (ensures LowParse.Spec.Base.parse LowParse.Spec.BCVLI.parse_bcvli b == (match LowParse.Spec.Base.parse (LowParse.Spec.BoundedInt.parse_bounded_integer_le 1) b with | FStar.Pervasives.Native.None #_ -> FStar.Pervasives.Native.None | FStar.Pervasives.Native.Some #_ (FStar.Pervasives.Native.Mktuple2 #_ #_ x32 consumed_x) -> let x = FStar.UInt32.v x32 in (match x <= 252 with | true -> FStar.Pervasives.Native.Some (x32, consumed_x) | _ -> let b' = FStar.Seq.Base.slice b consumed_x (FStar.Seq.Base.length b) in (match x = 253 with | true -> (match LowParse.Spec.Base.parse (LowParse.Spec.BoundedInt.parse_bounded_integer_le 2) b' with | FStar.Pervasives.Native.None #_ -> FStar.Pervasives.Native.None | FStar.Pervasives.Native.Some #_ (FStar.Pervasives.Native.Mktuple2 #_ #_ y consumed_y) -> (match FStar.UInt32.v y < 253 with | true -> FStar.Pervasives.Native.None | _ -> FStar.Pervasives.Native.Some (y, consumed_x + consumed_y)) <: FStar.Pervasives.Native.option (FStar.UInt32.t * LowParse.Spec.Base.consumed_length b)) <: FStar.Pervasives.Native.option (FStar.UInt32.t * LowParse.Spec.Base.consumed_length b) | _ -> (match x = 254 with | true -> (match LowParse.Spec.Base.parse (LowParse.Spec.BoundedInt.parse_bounded_integer_le 4) b' with | FStar.Pervasives.Native.None #_ -> FStar.Pervasives.Native.None | FStar.Pervasives.Native.Some #_ (FStar.Pervasives.Native.Mktuple2 #_ #_ y consumed_y) -> (match FStar.UInt32.v y < 65536 with | true -> FStar.Pervasives.Native.None | _ -> FStar.Pervasives.Native.Some (y, consumed_x + consumed_y)) <: FStar.Pervasives.Native.option (FStar.UInt32.t * LowParse.Spec.Base.consumed_length b)) <: FStar.Pervasives.Native.option (FStar.UInt32.t * LowParse.Spec.Base.consumed_length b) | _ -> FStar.Pervasives.Native.None) <: FStar.Pervasives.Native.option (FStar.UInt32.t * LowParse.Spec.Base.consumed_length b)) <: FStar.Pervasives.Native.option (FStar.UInt32.t * LowParse.Spec.Base.consumed_length b) ) <: FStar.Pervasives.Native.option (FStar.UInt32.t * LowParse.Spec.Base.consumed_length b)))
{ "end_col": 79, "end_line": 46, "start_col": 2, "start_line": 38 }
Prims.Tot
val bare_serialize_bcvli_correct:squash (serializer_correct parse_bcvli bare_serialize_bcvli)
[ { "abbrev": false, "full_module": "LowParse.Spec.Combinators // for parse_ret", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "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 } ]
false
let bare_serialize_bcvli_correct : squash (serializer_correct parse_bcvli bare_serialize_bcvli) = let prf (x: U32.t) : Lemma (let y = bare_serialize_bcvli x in parse parse_bcvli y == Some (x, Seq.length y)) = let y = bare_serialize_bcvli x in let c1 : bounded_integer 1 = if U32.v x <= 252 then x else if U32.v x <= 65535 then 253ul else 254ul in let sc1 = serialize (serialize_bounded_integer_le 1) c1 in parse_strong_prefix (parse_bounded_integer_le 1) sc1 y; let y' = Seq.slice y (Seq.length sc1) (Seq.length y) in parse_bcvli_eq y; if U32.v c1 <= 252 then begin assert (y `Seq.equal` sc1) end else if U32.v c1 = 253 then begin assert (U32.v x <= 65535); assert (y' `Seq.equal` serialize (serialize_bounded_integer_le 2) x) end else begin assert (y' `Seq.equal` serialize (serialize_bounded_integer_le 4) x) end in Classical.forall_intro (Classical.move_requires prf)
val bare_serialize_bcvli_correct:squash (serializer_correct parse_bcvli bare_serialize_bcvli) let bare_serialize_bcvli_correct:squash (serializer_correct parse_bcvli bare_serialize_bcvli) =
false
null
true
let prf (x: U32.t) : Lemma (let y = bare_serialize_bcvli x in parse parse_bcvli y == Some (x, Seq.length y)) = let y = bare_serialize_bcvli x in let c1:bounded_integer 1 = if U32.v x <= 252 then x else if U32.v x <= 65535 then 253ul else 254ul in let sc1 = serialize (serialize_bounded_integer_le 1) c1 in parse_strong_prefix (parse_bounded_integer_le 1) sc1 y; let y' = Seq.slice y (Seq.length sc1) (Seq.length y) in parse_bcvli_eq y; if U32.v c1 <= 252 then assert (y `Seq.equal` sc1) else if U32.v c1 = 253 then (assert (U32.v x <= 65535); assert (y' `Seq.equal` (serialize (serialize_bounded_integer_le 2) x))) else assert (y' `Seq.equal` (serialize (serialize_bounded_integer_le 4) x)) in Classical.forall_intro (Classical.move_requires prf)
{ "checked_file": "LowParse.Spec.BCVLI.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Spec.BCVLI.fst" }
[ "total" ]
[ "FStar.Classical.forall_intro", "FStar.UInt32.t", "Prims.l_imp", "Prims.l_True", "Prims.eq2", "FStar.Pervasives.Native.option", "FStar.Pervasives.Native.tuple2", "LowParse.Spec.Base.consumed_length", "LowParse.Spec.BCVLI.bare_serialize_bcvli", "LowParse.Spec.Base.parse", "LowParse.Spec.BCVLI.parse_bcvli", "FStar.Pervasives.Native.Some", "FStar.Pervasives.Native.Mktuple2", "FStar.Seq.Base.length", "LowParse.Bytes.byte", "FStar.Classical.move_requires", "Prims.unit", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern", "Prims.op_LessThanOrEqual", "FStar.UInt32.v", "Prims._assert", "FStar.Seq.Base.equal", "Prims.bool", "Prims.op_Equality", "Prims.int", "LowParse.Spec.Base.serialize", "LowParse.Spec.BoundedInt.parse_bounded_integer_kind", "LowParse.Spec.BoundedInt.bounded_integer", "LowParse.Spec.BoundedInt.parse_bounded_integer_le", "LowParse.Spec.BoundedInt.serialize_bounded_integer_le", "Prims.b2t", "LowParse.Spec.BCVLI.parse_bcvli_eq", "FStar.Seq.Base.seq", "FStar.Seq.Base.slice", "LowParse.Spec.Base.parse_strong_prefix", "LowParse.Bytes.bytes", "FStar.UInt32.__uint_to_t" ]
[]
module LowParse.Spec.BCVLI open LowParse.Spec.Combinators // for parse_ret module U32 = FStar.UInt32 module Seq = FStar.Seq inline_for_extraction let parse_bcvli_payload_kind = { parser_kind_low = 0; parser_kind_high = Some 4; parser_kind_subkind = Some ParserStrong; parser_kind_metadata = None; } let parse_bcvli_payload (x: bounded_integer 1) : Tot (parser parse_bcvli_payload_kind U32.t) = if U32.v x <= 252 then weaken parse_bcvli_payload_kind (parse_ret (x <: U32.t)) else if U32.v x = 253 then weaken parse_bcvli_payload_kind ((parse_bounded_integer_le 2 `parse_filter` (fun x -> U32.v x >= 253)) `parse_synth` (fun x -> (x <: U32.t))) else if U32.v x = 254 then weaken parse_bcvli_payload_kind ((parse_bounded_integer_le 4 `parse_filter` (fun x -> U32.v x >= 65536)) `parse_synth` (fun x -> (x <: U32.t))) else fail_parser parse_bcvli_payload_kind U32.t #push-options "--z3rlimit 32" let parse_bcvli_payload_and_then_cases_injective : squash (and_then_cases_injective parse_bcvli_payload) = and_then_cases_injective_intro parse_bcvli_payload (fun x1 x2 b1 b2 -> parse_synth_eq (parse_bounded_integer_le 2 `parse_filter` (fun x -> U32.v x >= 253)) (fun x -> (x <: U32.t)) b1; parse_synth_eq (parse_bounded_integer_le 2 `parse_filter` (fun x -> U32.v x >= 253)) (fun x -> (x <: U32.t)) b2; parse_synth_eq (parse_bounded_integer_le 4 `parse_filter` (fun x -> U32.v x >= 65536)) (fun x -> (x <: U32.t)) b1; parse_synth_eq (parse_bounded_integer_le 4 `parse_filter` (fun x -> U32.v x >= 65536)) (fun x -> (x <: U32.t)) b2 ) #pop-options let parse_bcvli : parser parse_bcvli_kind U32.t = parse_bounded_integer_le 1 `and_then` parse_bcvli_payload let parse_bcvli_eq b = and_then_eq (parse_bounded_integer_le 1) parse_bcvli_payload b; match parse (parse_bounded_integer_le 1) b with | None -> () | Some (x32, consumed_x) -> let b' = Seq.slice b consumed_x (Seq.length b) in parse_synth_eq (parse_bounded_integer_le 2 `parse_filter` (fun x -> U32.v x >= 253)) (fun x -> (x <: U32.t)) b'; parse_filter_eq (parse_bounded_integer_le 2) (fun x -> U32.v x >= 253) b'; parse_synth_eq (parse_bounded_integer_le 4 `parse_filter` (fun x -> U32.v x >= 65536)) (fun x -> (x <: U32.t)) b'; parse_filter_eq (parse_bounded_integer_le 4) (fun x -> U32.v x >= 65536) b' let bare_serialize_bcvli (x: U32.t) : GTot bytes = let c1 : bounded_integer 1 = if U32.v x <= 252 then x else if U32.v x <= 65535 then 253ul else 254ul in Seq.append (serialize (serialize_bounded_integer_le 1) c1) ( if U32.v c1 <= 252 then Seq.empty else if U32.v c1 = 253 then serialize (serialize_bounded_integer_le 2) x else serialize (serialize_bounded_integer_le 4) x ) #push-options "--z3rlimit 32" let bare_serialize_bcvli_correct : squash
false
true
LowParse.Spec.BCVLI.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 32, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val bare_serialize_bcvli_correct:squash (serializer_correct parse_bcvli bare_serialize_bcvli)
[]
LowParse.Spec.BCVLI.bare_serialize_bcvli_correct
{ "file_name": "src/lowparse/LowParse.Spec.BCVLI.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
Prims.squash (LowParse.Spec.Base.serializer_correct LowParse.Spec.BCVLI.parse_bcvli LowParse.Spec.BCVLI.bare_serialize_bcvli)
{ "end_col": 54, "end_line": 94, "start_col": 1, "start_line": 69 }
Prims.Tot
val parse_bcvli_payload_and_then_cases_injective:squash (and_then_cases_injective parse_bcvli_payload )
[ { "abbrev": false, "full_module": "LowParse.Spec.Combinators // for parse_ret", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "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 } ]
false
let parse_bcvli_payload_and_then_cases_injective : squash (and_then_cases_injective parse_bcvli_payload) = and_then_cases_injective_intro parse_bcvli_payload (fun x1 x2 b1 b2 -> parse_synth_eq (parse_bounded_integer_le 2 `parse_filter` (fun x -> U32.v x >= 253)) (fun x -> (x <: U32.t)) b1; parse_synth_eq (parse_bounded_integer_le 2 `parse_filter` (fun x -> U32.v x >= 253)) (fun x -> (x <: U32.t)) b2; parse_synth_eq (parse_bounded_integer_le 4 `parse_filter` (fun x -> U32.v x >= 65536)) (fun x -> (x <: U32.t)) b1; parse_synth_eq (parse_bounded_integer_le 4 `parse_filter` (fun x -> U32.v x >= 65536)) (fun x -> (x <: U32.t)) b2 )
val parse_bcvli_payload_and_then_cases_injective:squash (and_then_cases_injective parse_bcvli_payload ) let parse_bcvli_payload_and_then_cases_injective:squash (and_then_cases_injective parse_bcvli_payload ) =
false
null
true
and_then_cases_injective_intro parse_bcvli_payload (fun x1 x2 b1 b2 -> parse_synth_eq ((parse_bounded_integer_le 2) `parse_filter` (fun x -> U32.v x >= 253)) (fun x -> (x <: U32.t)) b1; parse_synth_eq ((parse_bounded_integer_le 2) `parse_filter` (fun x -> U32.v x >= 253)) (fun x -> (x <: U32.t)) b2; parse_synth_eq ((parse_bounded_integer_le 4) `parse_filter` (fun x -> U32.v x >= 65536)) (fun x -> (x <: U32.t)) b1; parse_synth_eq ((parse_bounded_integer_le 4) `parse_filter` (fun x -> U32.v x >= 65536)) (fun x -> (x <: U32.t)) b2)
{ "checked_file": "LowParse.Spec.BCVLI.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Spec.BCVLI.fst" }
[ "total" ]
[ "LowParse.Spec.Combinators.and_then_cases_injective_intro", "LowParse.Spec.BoundedInt.bounded_integer", "FStar.UInt32.t", "LowParse.Spec.BCVLI.parse_bcvli_payload", "LowParse.Bytes.bytes", "LowParse.Spec.Combinators.parse_synth_eq", "LowParse.Spec.Combinators.parse_filter_kind", "LowParse.Spec.BoundedInt.parse_bounded_integer_kind", "LowParse.Spec.Combinators.parse_filter_refine", "Prims.op_GreaterThanOrEqual", "FStar.UInt32.v", "Prims.bool", "LowParse.Spec.Combinators.parse_filter", "LowParse.Spec.BoundedInt.parse_bounded_integer_le", "Prims.unit" ]
[]
module LowParse.Spec.BCVLI open LowParse.Spec.Combinators // for parse_ret module U32 = FStar.UInt32 module Seq = FStar.Seq inline_for_extraction let parse_bcvli_payload_kind = { parser_kind_low = 0; parser_kind_high = Some 4; parser_kind_subkind = Some ParserStrong; parser_kind_metadata = None; } let parse_bcvli_payload (x: bounded_integer 1) : Tot (parser parse_bcvli_payload_kind U32.t) = if U32.v x <= 252 then weaken parse_bcvli_payload_kind (parse_ret (x <: U32.t)) else if U32.v x = 253 then weaken parse_bcvli_payload_kind ((parse_bounded_integer_le 2 `parse_filter` (fun x -> U32.v x >= 253)) `parse_synth` (fun x -> (x <: U32.t))) else if U32.v x = 254 then weaken parse_bcvli_payload_kind ((parse_bounded_integer_le 4 `parse_filter` (fun x -> U32.v x >= 65536)) `parse_synth` (fun x -> (x <: U32.t))) else fail_parser parse_bcvli_payload_kind U32.t #push-options "--z3rlimit 32"
false
false
LowParse.Spec.BCVLI.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 32, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val parse_bcvli_payload_and_then_cases_injective:squash (and_then_cases_injective parse_bcvli_payload )
[]
LowParse.Spec.BCVLI.parse_bcvli_payload_and_then_cases_injective
{ "file_name": "src/lowparse/LowParse.Spec.BCVLI.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
Prims.squash (LowParse.Spec.Combinators.and_then_cases_injective LowParse.Spec.BCVLI.parse_bcvli_payload )
{ "end_col": 3, "end_line": 29, "start_col": 2, "start_line": 24 }
Prims.Tot
[ { "abbrev": true, "full_module": "Spec.Frodo.Lemmas", "short_module": "Lemmas" }, { "abbrev": true, "full_module": "Spec.Matrix", "short_module": "M" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let lbytes len = lbuffer uint8 len
let lbytes len =
false
null
false
lbuffer uint8 len
{ "checked_file": "Hacl.Impl.Matrix.fst.checked", "dependencies": [ "Spec.Matrix.fst.checked", "Spec.Frodo.Lemmas.fst.checked", "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.Loops.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Matrix.fst" }
[ "total" ]
[ "Lib.IntTypes.size_t", "Lib.Buffer.lbuffer", "Lib.IntTypes.uint8" ]
[]
module Hacl.Impl.Matrix open FStar.HyperStack.ST open FStar.Mul open LowStar.BufferOps open LowStar.Buffer open Lib.IntTypes open Lib.Buffer open Lib.ByteBuffer module HS = FStar.HyperStack module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module Loops = Lib.LoopCombinators module M = Spec.Matrix module Lemmas = Spec.Frodo.Lemmas #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" unfold let elem = uint16
false
true
Hacl.Impl.Matrix.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val lbytes : len: Lib.IntTypes.size_t -> Type0
[]
Hacl.Impl.Matrix.lbytes
{ "file_name": "code/frodo/Hacl.Impl.Matrix.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
len: Lib.IntTypes.size_t -> Type0
{ "end_col": 34, "end_line": 28, "start_col": 17, "start_line": 28 }
Prims.Tot
[ { "abbrev": true, "full_module": "Spec.Frodo.Lemmas", "short_module": "Lemmas" }, { "abbrev": true, "full_module": "Spec.Matrix", "short_module": "M" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let elem = uint16
let elem =
false
null
false
uint16
{ "checked_file": "Hacl.Impl.Matrix.fst.checked", "dependencies": [ "Spec.Matrix.fst.checked", "Spec.Frodo.Lemmas.fst.checked", "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.Loops.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Matrix.fst" }
[ "total" ]
[ "Lib.IntTypes.uint16" ]
[]
module Hacl.Impl.Matrix open FStar.HyperStack.ST open FStar.Mul open LowStar.BufferOps open LowStar.Buffer open Lib.IntTypes open Lib.Buffer open Lib.ByteBuffer module HS = FStar.HyperStack module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module Loops = Lib.LoopCombinators module M = Spec.Matrix module Lemmas = Spec.Frodo.Lemmas #set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
false
true
Hacl.Impl.Matrix.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val elem : Type0
[]
Hacl.Impl.Matrix.elem
{ "file_name": "code/frodo/Hacl.Impl.Matrix.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Type0
{ "end_col": 17, "end_line": 25, "start_col": 11, "start_line": 25 }
Prims.Tot
[ { "abbrev": true, "full_module": "Spec.Frodo.Lemmas", "short_module": "Lemmas" }, { "abbrev": true, "full_module": "Spec.Matrix", "short_module": "M" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let matrix_t (n1:size_t) (n2:size_t{v n1 * v n2 <= max_size_t}) = lbuffer elem (n1 *! n2)
let matrix_t (n1: size_t) (n2: size_t{v n1 * v n2 <= max_size_t}) =
false
null
false
lbuffer elem (n1 *! n2)
{ "checked_file": "Hacl.Impl.Matrix.fst.checked", "dependencies": [ "Spec.Matrix.fst.checked", "Spec.Frodo.Lemmas.fst.checked", "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.Loops.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Matrix.fst" }
[ "total" ]
[ "Lib.IntTypes.size_t", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.Mul.op_Star", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Lib.IntTypes.max_size_t", "Lib.Buffer.lbuffer", "Hacl.Impl.Matrix.elem", "Lib.IntTypes.op_Star_Bang" ]
[]
module Hacl.Impl.Matrix open FStar.HyperStack.ST open FStar.Mul open LowStar.BufferOps open LowStar.Buffer open Lib.IntTypes open Lib.Buffer open Lib.ByteBuffer module HS = FStar.HyperStack module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module Loops = Lib.LoopCombinators module M = Spec.Matrix module Lemmas = Spec.Frodo.Lemmas #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" unfold let elem = uint16 unfold let lbytes len = lbuffer uint8 len unfold
false
false
Hacl.Impl.Matrix.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val matrix_t : n1: Lib.IntTypes.size_t -> n2: Lib.IntTypes.size_t{Lib.IntTypes.v n1 * Lib.IntTypes.v n2 <= Lib.IntTypes.max_size_t} -> Type0
[]
Hacl.Impl.Matrix.matrix_t
{ "file_name": "code/frodo/Hacl.Impl.Matrix.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
n1: Lib.IntTypes.size_t -> n2: Lib.IntTypes.size_t{Lib.IntTypes.v n1 * Lib.IntTypes.v n2 <= Lib.IntTypes.max_size_t} -> Type0
{ "end_col": 25, "end_line": 32, "start_col": 2, "start_line": 32 }
Prims.GTot
[ { "abbrev": true, "full_module": "Spec.Frodo.Lemmas", "short_module": "Lemmas" }, { "abbrev": true, "full_module": "Spec.Matrix", "short_module": "M" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let get #n1 #n2 h (m:matrix_t n1 n2) i j = M.mget (as_matrix h m) i j
let get #n1 #n2 h (m: matrix_t n1 n2) i j =
false
null
false
M.mget (as_matrix h m) i j
{ "checked_file": "Hacl.Impl.Matrix.fst.checked", "dependencies": [ "Spec.Matrix.fst.checked", "Spec.Frodo.Lemmas.fst.checked", "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.Loops.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Matrix.fst" }
[ "sometrivial" ]
[ "Lib.IntTypes.size_t", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.Mul.op_Star", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Lib.IntTypes.max_size_t", "FStar.Monotonic.HyperStack.mem", "Hacl.Impl.Matrix.matrix_t", "Lib.IntTypes.size_nat", "Prims.op_LessThan", "Spec.Matrix.mget", "Hacl.Impl.Matrix.as_matrix", "Spec.Matrix.elem" ]
[]
module Hacl.Impl.Matrix open FStar.HyperStack.ST open FStar.Mul open LowStar.BufferOps open LowStar.Buffer open Lib.IntTypes open Lib.Buffer open Lib.ByteBuffer module HS = FStar.HyperStack module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module Loops = Lib.LoopCombinators module M = Spec.Matrix module Lemmas = Spec.Frodo.Lemmas #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" unfold let elem = uint16 unfold let lbytes len = lbuffer uint8 len unfold let matrix_t (n1:size_t) (n2:size_t{v n1 * v n2 <= max_size_t}) = lbuffer elem (n1 *! n2) unfold let as_matrix #n1 #n2 h (m:matrix_t n1 n2) : GTot (M.matrix (v n1) (v n2)) = as_seq h m inline_for_extraction noextract val matrix_create: n1:size_t -> n2:size_t{0 < v n1 * v n2 /\ v n1 * v n2 <= max_size_t} -> StackInline (matrix_t n1 n2) (requires fun h0 -> True) (ensures fun h0 a h1 -> stack_allocated a h0 h1 (as_matrix h1 a) /\ as_matrix h1 a == M.create (v n1) (v n2)) let matrix_create n1 n2 = [@inline_let] let len = size (normalize_term (v n1 * v n2)) in create len (u16 0) inline_for_extraction noextract val mget: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> Stack elem (requires fun h0 -> live h0 a) (ensures fun h0 x h1 -> modifies loc_none h0 h1 /\ x == M.mget (as_matrix h0 a) (v i) (v j)) let mget #n1 #n2 a i j = M.index_lt (v n1) (v n2) (v i) (v j); a.(i *! n2 +! j) inline_for_extraction noextract val mset: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> x:elem -> Stack unit (requires fun h0 -> live h0 a) (ensures fun h0 _ h1 -> modifies1 a h0 h1 /\ as_matrix h1 a == M.mset (as_matrix h0 a) (v i) (v j) x) let mset #n1 #n2 a i j x = M.index_lt (v n1) (v n2) (v i) (v j); a.(i *! n2 +! j) <- x noextract unfold val op_String_Access (#n1:size_t) (#n2:size_t{v n1 * v n2 <= max_size_t}) (m:matrix_t n1 n2) (ij:(size_t & size_t){let i, j = ij in v i < v n1 /\ v j < v n2}) : Stack elem (requires fun h0 -> live h0 m) (ensures fun h0 x h1 -> let i, j = ij in modifies loc_none h0 h1 /\ x == M.mget (as_matrix h0 m) (v i) (v j)) let op_String_Access #n1 #n2 m (i,j) = mget m i j noextract unfold val op_String_Assignment (#n1:size_t) (#n2:size_t{v n1 * v n2 <= max_size_t}) (m:matrix_t n1 n2) (ij:(size_t & size_t){let i, j = ij in v i < v n1 /\ v j < v n2}) (x:elem) : Stack unit (requires fun h0 -> live h0 m) (ensures fun h0 _ h1 -> let i, j = ij in modifies1 m h0 h1 /\ live h1 m /\ as_matrix h1 m == M.mset (as_matrix h0 m) (v i) (v j) x) let op_String_Assignment #n1 #n2 m (i,j) x = mset m i j x
false
false
Hacl.Impl.Matrix.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val get : h: FStar.Monotonic.HyperStack.mem -> m: Hacl.Impl.Matrix.matrix_t n1 n2 -> i: Lib.IntTypes.size_nat{i < Lib.IntTypes.v n1} -> j: Lib.IntTypes.size_nat{j < Lib.IntTypes.v n2} -> Prims.GTot Spec.Matrix.elem
[]
Hacl.Impl.Matrix.get
{ "file_name": "code/frodo/Hacl.Impl.Matrix.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
h: FStar.Monotonic.HyperStack.mem -> m: Hacl.Impl.Matrix.matrix_t n1 n2 -> i: Lib.IntTypes.size_nat{i < Lib.IntTypes.v n1} -> j: Lib.IntTypes.size_nat{j < Lib.IntTypes.v n2} -> Prims.GTot Spec.Matrix.elem
{ "end_col": 69, "end_line": 107, "start_col": 43, "start_line": 107 }
FStar.HyperStack.ST.Stack
val op_String_Access (#n1:size_t) (#n2:size_t{v n1 * v n2 <= max_size_t}) (m:matrix_t n1 n2) (ij:(size_t & size_t){let i, j = ij in v i < v n1 /\ v j < v n2}) : Stack elem (requires fun h0 -> live h0 m) (ensures fun h0 x h1 -> let i, j = ij in modifies loc_none h0 h1 /\ x == M.mget (as_matrix h0 m) (v i) (v j))
[ { "abbrev": true, "full_module": "Spec.Frodo.Lemmas", "short_module": "Lemmas" }, { "abbrev": true, "full_module": "Spec.Matrix", "short_module": "M" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let op_String_Access #n1 #n2 m (i,j) = mget m i j
val op_String_Access (#n1:size_t) (#n2:size_t{v n1 * v n2 <= max_size_t}) (m:matrix_t n1 n2) (ij:(size_t & size_t){let i, j = ij in v i < v n1 /\ v j < v n2}) : Stack elem (requires fun h0 -> live h0 m) (ensures fun h0 x h1 -> let i, j = ij in modifies loc_none h0 h1 /\ x == M.mget (as_matrix h0 m) (v i) (v j)) let op_String_Access #n1 #n2 m (i, j) =
true
null
false
mget m i j
{ "checked_file": "Hacl.Impl.Matrix.fst.checked", "dependencies": [ "Spec.Matrix.fst.checked", "Spec.Frodo.Lemmas.fst.checked", "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.Loops.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Matrix.fst" }
[]
[ "Lib.IntTypes.size_t", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.Mul.op_Star", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Lib.IntTypes.max_size_t", "Hacl.Impl.Matrix.matrix_t", "FStar.Pervasives.Native.tuple2", "Prims.l_and", "Prims.op_LessThan", "Lib.IntTypes.int_t", "Hacl.Impl.Matrix.mget", "Hacl.Impl.Matrix.elem" ]
[]
module Hacl.Impl.Matrix open FStar.HyperStack.ST open FStar.Mul open LowStar.BufferOps open LowStar.Buffer open Lib.IntTypes open Lib.Buffer open Lib.ByteBuffer module HS = FStar.HyperStack module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module Loops = Lib.LoopCombinators module M = Spec.Matrix module Lemmas = Spec.Frodo.Lemmas #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" unfold let elem = uint16 unfold let lbytes len = lbuffer uint8 len unfold let matrix_t (n1:size_t) (n2:size_t{v n1 * v n2 <= max_size_t}) = lbuffer elem (n1 *! n2) unfold let as_matrix #n1 #n2 h (m:matrix_t n1 n2) : GTot (M.matrix (v n1) (v n2)) = as_seq h m inline_for_extraction noextract val matrix_create: n1:size_t -> n2:size_t{0 < v n1 * v n2 /\ v n1 * v n2 <= max_size_t} -> StackInline (matrix_t n1 n2) (requires fun h0 -> True) (ensures fun h0 a h1 -> stack_allocated a h0 h1 (as_matrix h1 a) /\ as_matrix h1 a == M.create (v n1) (v n2)) let matrix_create n1 n2 = [@inline_let] let len = size (normalize_term (v n1 * v n2)) in create len (u16 0) inline_for_extraction noextract val mget: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> Stack elem (requires fun h0 -> live h0 a) (ensures fun h0 x h1 -> modifies loc_none h0 h1 /\ x == M.mget (as_matrix h0 a) (v i) (v j)) let mget #n1 #n2 a i j = M.index_lt (v n1) (v n2) (v i) (v j); a.(i *! n2 +! j) inline_for_extraction noextract val mset: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> x:elem -> Stack unit (requires fun h0 -> live h0 a) (ensures fun h0 _ h1 -> modifies1 a h0 h1 /\ as_matrix h1 a == M.mset (as_matrix h0 a) (v i) (v j) x) let mset #n1 #n2 a i j x = M.index_lt (v n1) (v n2) (v i) (v j); a.(i *! n2 +! j) <- x noextract unfold val op_String_Access (#n1:size_t) (#n2:size_t{v n1 * v n2 <= max_size_t}) (m:matrix_t n1 n2) (ij:(size_t & size_t){let i, j = ij in v i < v n1 /\ v j < v n2}) : Stack elem (requires fun h0 -> live h0 m)
false
false
Hacl.Impl.Matrix.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val op_String_Access (#n1:size_t) (#n2:size_t{v n1 * v n2 <= max_size_t}) (m:matrix_t n1 n2) (ij:(size_t & size_t){let i, j = ij in v i < v n1 /\ v j < v n2}) : Stack elem (requires fun h0 -> live h0 m) (ensures fun h0 x h1 -> let i, j = ij in modifies loc_none h0 h1 /\ x == M.mget (as_matrix h0 m) (v i) (v j))
[]
Hacl.Impl.Matrix.op_String_Access
{ "file_name": "code/frodo/Hacl.Impl.Matrix.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
m: Hacl.Impl.Matrix.matrix_t n1 n2 -> ij: (Lib.IntTypes.size_t * Lib.IntTypes.size_t) { let _ = ij in (let FStar.Pervasives.Native.Mktuple2 #_ #_ i j = _ in Lib.IntTypes.v i < Lib.IntTypes.v n1 /\ Lib.IntTypes.v j < Lib.IntTypes.v n2) <: Type0 } -> FStar.HyperStack.ST.Stack Hacl.Impl.Matrix.elem
{ "end_col": 49, "end_line": 95, "start_col": 39, "start_line": 95 }
Prims.Pure
val mod_pow2_felem: logq:size_t{0 < v logq /\ v logq < 16} -> a:uint16 -> Pure uint16 (requires True) (ensures fun r -> r == M.mod_pow2_felem (v logq) a)
[ { "abbrev": true, "full_module": "Spec.Frodo.Lemmas", "short_module": "Lemmas" }, { "abbrev": true, "full_module": "Spec.Matrix", "short_module": "M" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let mod_pow2_felem logq a = a &. ((u16 1 <<. logq) -. u16 1)
val mod_pow2_felem: logq:size_t{0 < v logq /\ v logq < 16} -> a:uint16 -> Pure uint16 (requires True) (ensures fun r -> r == M.mod_pow2_felem (v logq) a) let mod_pow2_felem logq a =
false
null
false
a &. ((u16 1 <<. logq) -. u16 1)
{ "checked_file": "Hacl.Impl.Matrix.fst.checked", "dependencies": [ "Spec.Matrix.fst.checked", "Spec.Frodo.Lemmas.fst.checked", "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.Loops.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Matrix.fst" }
[]
[ "Lib.IntTypes.size_t", "Prims.l_and", "Prims.b2t", "Prims.op_LessThan", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Lib.IntTypes.uint16", "Lib.IntTypes.op_Amp_Dot", "Lib.IntTypes.U16", "Lib.IntTypes.SEC", "Lib.IntTypes.op_Subtraction_Dot", "Lib.IntTypes.op_Less_Less_Dot", "Lib.IntTypes.u16" ]
[]
module Hacl.Impl.Matrix open FStar.HyperStack.ST open FStar.Mul open LowStar.BufferOps open LowStar.Buffer open Lib.IntTypes open Lib.Buffer open Lib.ByteBuffer module HS = FStar.HyperStack module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module Loops = Lib.LoopCombinators module M = Spec.Matrix module Lemmas = Spec.Frodo.Lemmas #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" unfold let elem = uint16 unfold let lbytes len = lbuffer uint8 len unfold let matrix_t (n1:size_t) (n2:size_t{v n1 * v n2 <= max_size_t}) = lbuffer elem (n1 *! n2) unfold let as_matrix #n1 #n2 h (m:matrix_t n1 n2) : GTot (M.matrix (v n1) (v n2)) = as_seq h m inline_for_extraction noextract val matrix_create: n1:size_t -> n2:size_t{0 < v n1 * v n2 /\ v n1 * v n2 <= max_size_t} -> StackInline (matrix_t n1 n2) (requires fun h0 -> True) (ensures fun h0 a h1 -> stack_allocated a h0 h1 (as_matrix h1 a) /\ as_matrix h1 a == M.create (v n1) (v n2)) let matrix_create n1 n2 = [@inline_let] let len = size (normalize_term (v n1 * v n2)) in create len (u16 0) inline_for_extraction noextract val mget: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> Stack elem (requires fun h0 -> live h0 a) (ensures fun h0 x h1 -> modifies loc_none h0 h1 /\ x == M.mget (as_matrix h0 a) (v i) (v j)) let mget #n1 #n2 a i j = M.index_lt (v n1) (v n2) (v i) (v j); a.(i *! n2 +! j) inline_for_extraction noextract val mset: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> x:elem -> Stack unit (requires fun h0 -> live h0 a) (ensures fun h0 _ h1 -> modifies1 a h0 h1 /\ as_matrix h1 a == M.mset (as_matrix h0 a) (v i) (v j) x) let mset #n1 #n2 a i j x = M.index_lt (v n1) (v n2) (v i) (v j); a.(i *! n2 +! j) <- x noextract unfold val op_String_Access (#n1:size_t) (#n2:size_t{v n1 * v n2 <= max_size_t}) (m:matrix_t n1 n2) (ij:(size_t & size_t){let i, j = ij in v i < v n1 /\ v j < v n2}) : Stack elem (requires fun h0 -> live h0 m) (ensures fun h0 x h1 -> let i, j = ij in modifies loc_none h0 h1 /\ x == M.mget (as_matrix h0 m) (v i) (v j)) let op_String_Access #n1 #n2 m (i,j) = mget m i j noextract unfold val op_String_Assignment (#n1:size_t) (#n2:size_t{v n1 * v n2 <= max_size_t}) (m:matrix_t n1 n2) (ij:(size_t & size_t){let i, j = ij in v i < v n1 /\ v j < v n2}) (x:elem) : Stack unit (requires fun h0 -> live h0 m) (ensures fun h0 _ h1 -> let i, j = ij in modifies1 m h0 h1 /\ live h1 m /\ as_matrix h1 m == M.mset (as_matrix h0 m) (v i) (v j) x) let op_String_Assignment #n1 #n2 m (i,j) x = mset m i j x unfold let get #n1 #n2 h (m:matrix_t n1 n2) i j = M.mget (as_matrix h m) i j private unfold val map_inner_inv: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> h2:HS.mem -> f:(elem -> elem) -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_nat -> Type0 let map_inner_inv #n1 #n2 h0 h1 h2 f a c i j = live h2 a /\ live h2 c /\ modifies1 c h1 h2 /\ j <= v n2 /\ (forall (i0:nat{i0 < v i}) (j:nat{j < v n2}). get h2 c i0 j == get h1 c i0 j) /\ (forall (j0:nat{j0 < j}). get h2 c (v i) j0 == f (get h0 a (v i) j0)) /\ (forall (j0:nat{j <= j0 /\ j0 < v n2}). get h2 c (v i) j0 == get h0 c (v i) j0) /\ (forall (i0:nat{v i < i0 /\ i0 < v n1}) (j:nat{j < v n2}). get h2 c i0 j == get h0 c i0 j) inline_for_extraction noextract private val map_inner: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> f:(elem -> elem) -> a:matrix_t n1 n2 -> c:matrix_t n1 n2{a == c} -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> Stack unit (requires fun h2 -> map_inner_inv h0 h1 h2 f a c i (v j)) (ensures fun _ _ h2 -> map_inner_inv h0 h1 h2 f a c i (v j + 1)) let map_inner #n1 #n2 h0 h1 f a c i j = c.[i,j] <- f a.[i,j] inline_for_extraction val map: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> f:(uint16 -> uint16) -> a:matrix_t n1 n2 -> c:matrix_t n1 n2 -> Stack unit (requires fun h0 -> live h0 a /\ live h0 c /\ a == c) (ensures fun h0 _ h1 -> modifies1 c h0 h1 /\ as_matrix h1 c == M.map #(v n1) #(v n2) f (as_matrix h0 a)) let map #n1 #n2 f a c = let h0 = ST.get () in Lib.Loops.for (size 0) n1 (fun h1 i -> live h1 a /\ live h1 c /\ modifies1 c h0 h1 /\ i <= v n1 /\ (forall (i0:nat{i0 < i}) (j:nat{j < v n2}). get h1 c i0 j == f (get h0 a i0 j)) /\ (forall (i0:nat{i <= i0 /\ i0 < v n1}) (j:nat{j < v n2}). get h1 c i0 j == get h0 c i0 j) ) (fun i -> let h1 = ST.get() in Lib.Loops.for (size 0) n2 (fun h2 j -> map_inner_inv h0 h1 h2 f a c i j) (fun j -> map_inner h0 h1 f a c i j) ); let h2 = ST.get () in M.extensionality (as_matrix h2 c) (M.map f (as_matrix h0 a)) inline_for_extraction noextract val mod_pow2_felem: logq:size_t{0 < v logq /\ v logq < 16} -> a:uint16 -> Pure uint16 (requires True) (ensures fun r -> r == M.mod_pow2_felem (v logq) a)
false
false
Hacl.Impl.Matrix.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val mod_pow2_felem: logq:size_t{0 < v logq /\ v logq < 16} -> a:uint16 -> Pure uint16 (requires True) (ensures fun r -> r == M.mod_pow2_felem (v logq) a)
[]
Hacl.Impl.Matrix.mod_pow2_felem
{ "file_name": "code/frodo/Hacl.Impl.Matrix.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
logq: Lib.IntTypes.size_t{0 < Lib.IntTypes.v logq /\ Lib.IntTypes.v logq < 16} -> a: Lib.IntTypes.uint16 -> Prims.Pure Lib.IntTypes.uint16
{ "end_col": 34, "end_line": 193, "start_col": 2, "start_line": 193 }
Prims.Tot
val map_inner_inv: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> h2:HS.mem -> f:(elem -> elem) -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_nat -> Type0
[ { "abbrev": true, "full_module": "Spec.Frodo.Lemmas", "short_module": "Lemmas" }, { "abbrev": true, "full_module": "Spec.Matrix", "short_module": "M" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let map_inner_inv #n1 #n2 h0 h1 h2 f a c i j = live h2 a /\ live h2 c /\ modifies1 c h1 h2 /\ j <= v n2 /\ (forall (i0:nat{i0 < v i}) (j:nat{j < v n2}). get h2 c i0 j == get h1 c i0 j) /\ (forall (j0:nat{j0 < j}). get h2 c (v i) j0 == f (get h0 a (v i) j0)) /\ (forall (j0:nat{j <= j0 /\ j0 < v n2}). get h2 c (v i) j0 == get h0 c (v i) j0) /\ (forall (i0:nat{v i < i0 /\ i0 < v n1}) (j:nat{j < v n2}). get h2 c i0 j == get h0 c i0 j)
val map_inner_inv: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> h2:HS.mem -> f:(elem -> elem) -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_nat -> Type0 let map_inner_inv #n1 #n2 h0 h1 h2 f a c i j =
false
null
false
live h2 a /\ live h2 c /\ modifies1 c h1 h2 /\ j <= v n2 /\ (forall (i0: nat{i0 < v i}) (j: nat{j < v n2}). get h2 c i0 j == get h1 c i0 j) /\ (forall (j0: nat{j0 < j}). get h2 c (v i) j0 == f (get h0 a (v i) j0)) /\ (forall (j0: nat{j <= j0 /\ j0 < v n2}). get h2 c (v i) j0 == get h0 c (v i) j0) /\ (forall (i0: nat{v i < i0 /\ i0 < v n1}) (j: nat{j < v n2}). get h2 c i0 j == get h0 c i0 j)
{ "checked_file": "Hacl.Impl.Matrix.fst.checked", "dependencies": [ "Spec.Matrix.fst.checked", "Spec.Frodo.Lemmas.fst.checked", "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.Loops.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Matrix.fst" }
[ "total" ]
[ "Lib.IntTypes.size_t", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.Mul.op_Star", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Lib.IntTypes.max_size_t", "FStar.Monotonic.HyperStack.mem", "Hacl.Impl.Matrix.elem", "Hacl.Impl.Matrix.matrix_t", "Prims.op_LessThan", "Lib.IntTypes.size_nat", "Prims.l_and", "Lib.Buffer.live", "Lib.Buffer.MUT", "Lib.Buffer.modifies1", "Prims.l_Forall", "Prims.nat", "Prims.eq2", "Spec.Matrix.elem", "Hacl.Impl.Matrix.get", "Lib.IntTypes.sec_int_t", "Lib.IntTypes.U16" ]
[]
module Hacl.Impl.Matrix open FStar.HyperStack.ST open FStar.Mul open LowStar.BufferOps open LowStar.Buffer open Lib.IntTypes open Lib.Buffer open Lib.ByteBuffer module HS = FStar.HyperStack module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module Loops = Lib.LoopCombinators module M = Spec.Matrix module Lemmas = Spec.Frodo.Lemmas #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" unfold let elem = uint16 unfold let lbytes len = lbuffer uint8 len unfold let matrix_t (n1:size_t) (n2:size_t{v n1 * v n2 <= max_size_t}) = lbuffer elem (n1 *! n2) unfold let as_matrix #n1 #n2 h (m:matrix_t n1 n2) : GTot (M.matrix (v n1) (v n2)) = as_seq h m inline_for_extraction noextract val matrix_create: n1:size_t -> n2:size_t{0 < v n1 * v n2 /\ v n1 * v n2 <= max_size_t} -> StackInline (matrix_t n1 n2) (requires fun h0 -> True) (ensures fun h0 a h1 -> stack_allocated a h0 h1 (as_matrix h1 a) /\ as_matrix h1 a == M.create (v n1) (v n2)) let matrix_create n1 n2 = [@inline_let] let len = size (normalize_term (v n1 * v n2)) in create len (u16 0) inline_for_extraction noextract val mget: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> Stack elem (requires fun h0 -> live h0 a) (ensures fun h0 x h1 -> modifies loc_none h0 h1 /\ x == M.mget (as_matrix h0 a) (v i) (v j)) let mget #n1 #n2 a i j = M.index_lt (v n1) (v n2) (v i) (v j); a.(i *! n2 +! j) inline_for_extraction noextract val mset: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> x:elem -> Stack unit (requires fun h0 -> live h0 a) (ensures fun h0 _ h1 -> modifies1 a h0 h1 /\ as_matrix h1 a == M.mset (as_matrix h0 a) (v i) (v j) x) let mset #n1 #n2 a i j x = M.index_lt (v n1) (v n2) (v i) (v j); a.(i *! n2 +! j) <- x noextract unfold val op_String_Access (#n1:size_t) (#n2:size_t{v n1 * v n2 <= max_size_t}) (m:matrix_t n1 n2) (ij:(size_t & size_t){let i, j = ij in v i < v n1 /\ v j < v n2}) : Stack elem (requires fun h0 -> live h0 m) (ensures fun h0 x h1 -> let i, j = ij in modifies loc_none h0 h1 /\ x == M.mget (as_matrix h0 m) (v i) (v j)) let op_String_Access #n1 #n2 m (i,j) = mget m i j noextract unfold val op_String_Assignment (#n1:size_t) (#n2:size_t{v n1 * v n2 <= max_size_t}) (m:matrix_t n1 n2) (ij:(size_t & size_t){let i, j = ij in v i < v n1 /\ v j < v n2}) (x:elem) : Stack unit (requires fun h0 -> live h0 m) (ensures fun h0 _ h1 -> let i, j = ij in modifies1 m h0 h1 /\ live h1 m /\ as_matrix h1 m == M.mset (as_matrix h0 m) (v i) (v j) x) let op_String_Assignment #n1 #n2 m (i,j) x = mset m i j x unfold let get #n1 #n2 h (m:matrix_t n1 n2) i j = M.mget (as_matrix h m) i j private unfold val map_inner_inv: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> h2:HS.mem -> f:(elem -> elem) -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_nat -> Type0
false
false
Hacl.Impl.Matrix.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val map_inner_inv: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> h2:HS.mem -> f:(elem -> elem) -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_nat -> Type0
[]
Hacl.Impl.Matrix.map_inner_inv
{ "file_name": "code/frodo/Hacl.Impl.Matrix.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
h0: FStar.Monotonic.HyperStack.mem -> h1: FStar.Monotonic.HyperStack.mem -> h2: FStar.Monotonic.HyperStack.mem -> f: (_: Hacl.Impl.Matrix.elem -> Hacl.Impl.Matrix.elem) -> a: Hacl.Impl.Matrix.matrix_t n1 n2 -> b: Hacl.Impl.Matrix.matrix_t n1 n2 -> i: Lib.IntTypes.size_t{Lib.IntTypes.v i < Lib.IntTypes.v n1} -> j: Lib.IntTypes.size_nat -> Type0
{ "end_col": 92, "end_line": 130, "start_col": 2, "start_line": 124 }
Prims.GTot
[ { "abbrev": true, "full_module": "Spec.Frodo.Lemmas", "short_module": "Lemmas" }, { "abbrev": true, "full_module": "Spec.Matrix", "short_module": "M" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let get_s #n1 #n2 h (m:matrix_t n1 n2) i j = M.mget_s (as_matrix h m) i j
let get_s #n1 #n2 h (m: matrix_t n1 n2) i j =
false
null
false
M.mget_s (as_matrix h m) i j
{ "checked_file": "Hacl.Impl.Matrix.fst.checked", "dependencies": [ "Spec.Matrix.fst.checked", "Spec.Frodo.Lemmas.fst.checked", "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.Loops.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Matrix.fst" }
[ "sometrivial" ]
[ "Lib.IntTypes.size_t", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.Mul.op_Star", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Lib.IntTypes.max_size_t", "FStar.Monotonic.HyperStack.mem", "Hacl.Impl.Matrix.matrix_t", "Lib.IntTypes.size_nat", "Prims.op_LessThan", "Spec.Matrix.mget_s", "Hacl.Impl.Matrix.as_matrix", "Spec.Matrix.elem" ]
[]
module Hacl.Impl.Matrix open FStar.HyperStack.ST open FStar.Mul open LowStar.BufferOps open LowStar.Buffer open Lib.IntTypes open Lib.Buffer open Lib.ByteBuffer module HS = FStar.HyperStack module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module Loops = Lib.LoopCombinators module M = Spec.Matrix module Lemmas = Spec.Frodo.Lemmas #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" unfold let elem = uint16 unfold let lbytes len = lbuffer uint8 len unfold let matrix_t (n1:size_t) (n2:size_t{v n1 * v n2 <= max_size_t}) = lbuffer elem (n1 *! n2) unfold let as_matrix #n1 #n2 h (m:matrix_t n1 n2) : GTot (M.matrix (v n1) (v n2)) = as_seq h m inline_for_extraction noextract val matrix_create: n1:size_t -> n2:size_t{0 < v n1 * v n2 /\ v n1 * v n2 <= max_size_t} -> StackInline (matrix_t n1 n2) (requires fun h0 -> True) (ensures fun h0 a h1 -> stack_allocated a h0 h1 (as_matrix h1 a) /\ as_matrix h1 a == M.create (v n1) (v n2)) let matrix_create n1 n2 = [@inline_let] let len = size (normalize_term (v n1 * v n2)) in create len (u16 0) inline_for_extraction noextract val mget: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> Stack elem (requires fun h0 -> live h0 a) (ensures fun h0 x h1 -> modifies loc_none h0 h1 /\ x == M.mget (as_matrix h0 a) (v i) (v j)) let mget #n1 #n2 a i j = M.index_lt (v n1) (v n2) (v i) (v j); a.(i *! n2 +! j) inline_for_extraction noextract val mset: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> x:elem -> Stack unit (requires fun h0 -> live h0 a) (ensures fun h0 _ h1 -> modifies1 a h0 h1 /\ as_matrix h1 a == M.mset (as_matrix h0 a) (v i) (v j) x) let mset #n1 #n2 a i j x = M.index_lt (v n1) (v n2) (v i) (v j); a.(i *! n2 +! j) <- x noextract unfold val op_String_Access (#n1:size_t) (#n2:size_t{v n1 * v n2 <= max_size_t}) (m:matrix_t n1 n2) (ij:(size_t & size_t){let i, j = ij in v i < v n1 /\ v j < v n2}) : Stack elem (requires fun h0 -> live h0 m) (ensures fun h0 x h1 -> let i, j = ij in modifies loc_none h0 h1 /\ x == M.mget (as_matrix h0 m) (v i) (v j)) let op_String_Access #n1 #n2 m (i,j) = mget m i j noextract unfold val op_String_Assignment (#n1:size_t) (#n2:size_t{v n1 * v n2 <= max_size_t}) (m:matrix_t n1 n2) (ij:(size_t & size_t){let i, j = ij in v i < v n1 /\ v j < v n2}) (x:elem) : Stack unit (requires fun h0 -> live h0 m) (ensures fun h0 _ h1 -> let i, j = ij in modifies1 m h0 h1 /\ live h1 m /\ as_matrix h1 m == M.mset (as_matrix h0 m) (v i) (v j) x) let op_String_Assignment #n1 #n2 m (i,j) x = mset m i j x unfold let get #n1 #n2 h (m:matrix_t n1 n2) i j = M.mget (as_matrix h m) i j private unfold val map_inner_inv: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> h2:HS.mem -> f:(elem -> elem) -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_nat -> Type0 let map_inner_inv #n1 #n2 h0 h1 h2 f a c i j = live h2 a /\ live h2 c /\ modifies1 c h1 h2 /\ j <= v n2 /\ (forall (i0:nat{i0 < v i}) (j:nat{j < v n2}). get h2 c i0 j == get h1 c i0 j) /\ (forall (j0:nat{j0 < j}). get h2 c (v i) j0 == f (get h0 a (v i) j0)) /\ (forall (j0:nat{j <= j0 /\ j0 < v n2}). get h2 c (v i) j0 == get h0 c (v i) j0) /\ (forall (i0:nat{v i < i0 /\ i0 < v n1}) (j:nat{j < v n2}). get h2 c i0 j == get h0 c i0 j) inline_for_extraction noextract private val map_inner: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> f:(elem -> elem) -> a:matrix_t n1 n2 -> c:matrix_t n1 n2{a == c} -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> Stack unit (requires fun h2 -> map_inner_inv h0 h1 h2 f a c i (v j)) (ensures fun _ _ h2 -> map_inner_inv h0 h1 h2 f a c i (v j + 1)) let map_inner #n1 #n2 h0 h1 f a c i j = c.[i,j] <- f a.[i,j] inline_for_extraction val map: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> f:(uint16 -> uint16) -> a:matrix_t n1 n2 -> c:matrix_t n1 n2 -> Stack unit (requires fun h0 -> live h0 a /\ live h0 c /\ a == c) (ensures fun h0 _ h1 -> modifies1 c h0 h1 /\ as_matrix h1 c == M.map #(v n1) #(v n2) f (as_matrix h0 a)) let map #n1 #n2 f a c = let h0 = ST.get () in Lib.Loops.for (size 0) n1 (fun h1 i -> live h1 a /\ live h1 c /\ modifies1 c h0 h1 /\ i <= v n1 /\ (forall (i0:nat{i0 < i}) (j:nat{j < v n2}). get h1 c i0 j == f (get h0 a i0 j)) /\ (forall (i0:nat{i <= i0 /\ i0 < v n1}) (j:nat{j < v n2}). get h1 c i0 j == get h0 c i0 j) ) (fun i -> let h1 = ST.get() in Lib.Loops.for (size 0) n2 (fun h2 j -> map_inner_inv h0 h1 h2 f a c i j) (fun j -> map_inner h0 h1 f a c i j) ); let h2 = ST.get () in M.extensionality (as_matrix h2 c) (M.map f (as_matrix h0 a)) inline_for_extraction noextract val mod_pow2_felem: logq:size_t{0 < v logq /\ v logq < 16} -> a:uint16 -> Pure uint16 (requires True) (ensures fun r -> r == M.mod_pow2_felem (v logq) a) let mod_pow2_felem logq a = a &. ((u16 1 <<. logq) -. u16 1) val mod_pow2: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> logq:size_t{0 < v logq /\ v logq <= 16} -> a:matrix_t n1 n2 -> Stack unit (requires fun h -> live h a) (ensures fun h0 _ h1 -> modifies1 a h0 h1 /\ as_matrix h1 a == M.mod_pow2 (v logq) (as_matrix h0 a)) [@"c_inline"] let mod_pow2 #n1 #n2 logq a = if logq <. 16ul then begin let h0 = ST.get () in map (mod_pow2_felem logq) a a; M.extensionality (M.map #(v n1) #(v n2) (mod_pow2_felem logq) (as_matrix h0 a)) (M.map #(v n1) #(v n2) (M.mod_pow2_felem (v logq)) (as_matrix h0 a)) end private unfold val map2_inner_inv: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> h2:HS.mem -> f:(elem -> elem -> elem) -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> c:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_nat -> Type0 let map2_inner_inv #n1 #n2 h0 h1 h2 f a b c i j = live h2 a /\ live h2 b /\ live h2 c /\ modifies1 c h1 h2 /\ j <= v n2 /\ (forall (i0:nat{i0 < v i}) (j:nat{j < v n2}). get h2 c i0 j == get h1 c i0 j) /\ (forall (j0:nat{j0 < j}). get h2 c (v i) j0 == f (get h0 a (v i) j0) (get h2 b (v i) j0)) /\ (forall (j0:nat{j <= j0 /\ j0 < v n2}). get h2 c (v i) j0 == get h0 c (v i) j0) /\ (forall (i0:nat{v i < i0 /\ i0 < v n1}) (j:nat{j < v n2}). get h2 c i0 j == get h0 c i0 j) inline_for_extraction noextract private val map2_inner: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> f:(elem -> elem -> elem) -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> c:matrix_t n1 n2{a == c /\ disjoint b c} -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> Stack unit (requires fun h2 -> map2_inner_inv h0 h1 h2 f a b c i (v j)) (ensures fun _ _ h2 -> map2_inner_inv h0 h1 h2 f a b c i (v j + 1)) let map2_inner #n1 #n2 h0 h1 f a b c i j = c.[i,j] <- f a.[i,j] b.[i,j] /// In-place [map2], a == map2 f a b /// /// A non in-place variant can be obtained by weakening the pre-condition to disjoint a c, /// or the two variants can be merged by requiring (a == c \/ disjoint a c) instead of a == c /// See commit 91916b8372fa3522061eff5a42d0ebd1d19a8a49 inline_for_extraction val map2: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> f:(uint16 -> uint16 -> uint16) -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> c:matrix_t n1 n2 -> Stack unit (requires fun h0 -> live h0 a /\ live h0 b /\ live h0 c /\ a == c /\ disjoint b c) (ensures fun h0 _ h1 -> modifies1 c h0 h1 /\ as_matrix h1 c == M.map2 #(v n1) #(v n2) f (as_matrix h0 a) (as_matrix h0 b)) let map2 #n1 #n2 f a b c = let h0 = ST.get () in Lib.Loops.for (size 0) n1 (fun h1 i -> live h1 a /\ live h1 b /\ live h1 c /\ modifies1 c h0 h1 /\ i <= v n1 /\ (forall (i0:nat{i0 < i}) (j:nat{j < v n2}). get h1 c i0 j == f (get h0 a i0 j) (get h0 b i0 j)) /\ (forall (i0:nat{i <= i0 /\ i0 < v n1}) (j:nat{j < v n2}). get h1 c i0 j == get h0 c i0 j) ) (fun i -> let h1 = ST.get() in Lib.Loops.for (size 0) n2 (fun h2 j -> map2_inner_inv h0 h1 h2 f a b c i j) (fun j -> map2_inner h0 h1 f a b c i j) ); let h2 = ST.get() in M.extensionality (as_matrix h2 c) (M.map2 f (as_matrix h0 a) (as_matrix h0 b)) val matrix_add: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> Stack unit (requires fun h -> live h a /\ live h b /\ disjoint a b) (ensures fun h0 r h1 -> modifies1 a h0 h1 /\ as_matrix h1 a == M.add (as_matrix h0 a) (as_matrix h0 b)) [@"c_inline"] let matrix_add #n1 #n2 a b = map2 add_mod a b a val matrix_sub: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> Stack unit (requires fun h -> live h a /\ live h b /\ disjoint a b) (ensures fun h0 r h1 -> modifies1 b h0 h1 /\ as_matrix h1 b == M.sub (as_matrix h0 a) (as_matrix h0 b)) [@"c_inline"] let matrix_sub #n1 #n2 a b = (* Use the in-place variant above by flipping the arguments of [sub_mod] *) (* Requires appplying extensionality *) let h0 = ST.get() in [@ inline_let ] let sub_mod_flipped x y = sub_mod y x in map2 sub_mod_flipped b a b; let h1 = ST.get() in M.extensionality (as_matrix h1 b) (M.sub (as_matrix h0 a) (as_matrix h0 b)) #push-options "--fuel 1" inline_for_extraction noextract private val mul_inner: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> #n3:size_t{v n2 * v n3 <= max_size_t /\ v n1 * v n3 <= max_size_t} -> a:matrix_t n1 n2 -> b:matrix_t n2 n3 -> i:size_t{v i < v n1} -> k:size_t{v k < v n3} -> Stack uint16 (requires fun h -> live h a /\ live h b) (ensures fun h0 r h1 -> modifies loc_none h0 h1 /\ r == M.mul_inner (as_matrix h0 a) (as_matrix h0 b) (v i) (v k)) let mul_inner #n1 #n2 #n3 a b i k = push_frame(); let h0 = ST.get() in [@ inline_let ] let f l = get h0 a (v i) l *. get h0 b l (v k) in let res = create #uint16 (size 1) (u16 0) in let h1 = ST.get() in Lib.Loops.for (size 0) n2 (fun h2 j -> live h1 res /\ live h2 res /\ modifies1 res h1 h2 /\ bget h2 res 0 == M.sum_ #(v n2) f j) (fun j -> let aij = a.[i,j] in let bjk = b.[j,k] in let res0 = res.(size 0) in res.(size 0) <- res0 +. aij *. bjk ); let res = res.(size 0) in M.sum_extensionality (v n2) f (fun l -> get h0 a (v i) l *. get h0 b l (v k)) (v n2); assert (res == M.mul_inner (as_matrix h0 a) (as_matrix h0 b) (v i) (v k)); pop_frame(); res #pop-options private unfold val mul_inner_inv: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> #n3:size_t{v n2 * v n3 <= max_size_t /\ v n1 * v n3 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> h2:HS.mem -> a:matrix_t n1 n2 -> b:matrix_t n2 n3 -> c:matrix_t n1 n3 -> f:(k:nat{k < v n3} -> GTot uint16) -> i:size_t{v i < v n1} -> k:size_nat -> Type0 let mul_inner_inv #n1 #n2 #n3 h0 h1 h2 a b c f i k = live h2 a /\ live h2 b /\ live h2 c /\ modifies1 c h1 h2 /\ k <= v n3 /\ (forall (i1:nat{i1 < v i}) (k:nat{k < v n3}). get h2 c i1 k == get h1 c i1 k) /\ (forall (k1:nat{k1 < k}). get h2 c (v i) k1 == f k1) /\ (forall (k1:nat{k <= k1 /\ k1 < v n3}). get h2 c (v i) k1 == get h0 c (v i) k1) /\ (forall (i1:nat{v i < i1 /\ i1 < v n1}) (k:nat{k < v n3}). get h2 c i1 k == get h0 c i1 k) /\ as_matrix h0 a == as_matrix h2 a /\ as_matrix h0 b == as_matrix h2 b inline_for_extraction noextract private val mul_inner1: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> #n3:size_t{v n2 * v n3 <= max_size_t /\ v n1 * v n3 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> a:matrix_t n1 n2 -> b:matrix_t n2 n3 -> c:matrix_t n1 n3{disjoint a c /\ disjoint b c} -> i:size_t{v i < v n1} -> k:size_t{v k < v n3} -> f:(k:nat{k < v n3} -> GTot (res:uint16{res == M.sum #(v n2) (fun l -> get h0 a (v i) l *. get h0 b l k)})) -> Stack unit (requires fun h2 -> mul_inner_inv h0 h1 h2 a b c f i (v k)) (ensures fun _ _ h2 -> mul_inner_inv h0 h1 h2 a b c f i (v k + 1)) let mul_inner1 #n1 #n2 #n3 h0 h1 a b c i k f = assert (M.mul_inner (as_matrix h0 a) (as_matrix h0 b) (v i) (v k) == M.sum #(v n2) (fun l -> get h0 a (v i) l *. get h0 b l (v k))); c.[i,k] <- mul_inner a b i k; let h2 = ST.get () in assert (get h2 c (v i) (v k) == f (v k)) private val onemore: p:(nat -> Type0) -> q:(i:nat{p i} -> Type0) -> b:nat{p b} -> Lemma (requires (forall (i:nat{p i /\ i < b}). q i) /\ q b) (ensures forall (i:nat{p i /\ i <= b}). q i) let onemore p q b = () val onemore1: #n1:size_nat -> #n3:size_nat{n1 * n3 <= max_size_t} -> c:M.matrix n1 n3 -> f:(i:nat{i < n1} -> k:nat{k < n3} -> GTot uint16) -> i:size_nat{i < n1} -> Lemma (requires ((forall (i1:nat{i1 < i}) (k:nat{k < n3}). M.mget c i1 k == f i1 k) /\ (forall (k:nat{k < n3}). M.mget c i k == f i k))) (ensures (forall (i1:nat{i1 <= i}) (k:nat{k < n3}). M.mget c i1 k == f i1 k)) let onemore1 #n1 #n3 c f i = () val matrix_mul: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> #n3:size_t{v n2 * v n3 <= max_size_t /\ v n1 * v n3 <= max_size_t} -> a:matrix_t n1 n2 -> b:matrix_t n2 n3 -> c:matrix_t n1 n3 -> Stack unit (requires fun h -> live h a /\ live h b /\ live h c /\ disjoint a c /\ disjoint b c) (ensures fun h0 _ h1 -> modifies1 c h0 h1 /\ as_matrix h1 c == M.mul (as_matrix h0 a) (as_matrix h0 b)) [@"c_inline"] let matrix_mul #n1 #n2 #n3 a b c = let h0 = ST.get () in let f (i:nat{i < v n1}) (k:nat{k < v n3}) : GTot (res:uint16{res == M.sum #(v n2) (fun l -> get h0 a i l *. get h0 b l k)}) = M.sum #(v n2) (fun l -> get h0 a i l *. get h0 b l k) in Lib.Loops.for (size 0) n1 (fun h1 i -> live h1 a /\ live h1 b /\ live h1 c /\ modifies1 c h0 h1 /\ i <= v n1 /\ (forall (i1:nat{i1 < i}) (k:nat{k < v n3}). get h1 c i1 k == f i1 k) /\ (forall (i1:nat{i <= i1 /\ i1 < v n1}) (k:nat{k < v n3}). get h1 c i1 k == get h0 c i1 k)) (fun i -> let h1 = ST.get() in Lib.Loops.for (size 0) n3 (fun h2 k -> mul_inner_inv h0 h1 h2 a b c (f (v i)) i k) (fun k -> mul_inner1 h0 h1 a b c i k (f (v i))); let h1 = ST.get() in let q i1 = forall (k:nat{k < v n3}). get h1 c i1 k == f i1 k in onemore (fun i1 -> i1 < v n1) q (v i); assert (forall (i1:nat{i1 < v n1 /\ i1 <= v i}) (k:nat{k < v n3}). get h1 c i1 k == f i1 k) ); let h2 = ST.get() in M.extensionality (as_matrix h2 c) (M.mul (as_matrix h0 a) (as_matrix h0 b)) (* Special case of matrix multiplication *) (* when we have a different way of accessing to entries of the matrix S *) inline_for_extraction noextract val mget_s: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> Stack elem (requires fun h0 -> live h0 a) (ensures fun h0 x h1 -> modifies0 h0 h1 /\ x == M.mget_s (as_matrix h0 a) (v i) (v j)) let mget_s #n1 #n2 a i j = M.index_lt (v n2) (v n1) (v j) (v i); a.(j *! n1 +! i)
false
false
Hacl.Impl.Matrix.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val get_s : h: FStar.Monotonic.HyperStack.mem -> m: Hacl.Impl.Matrix.matrix_t n1 n2 -> i: Lib.IntTypes.size_nat{i < Lib.IntTypes.v n1} -> j: Lib.IntTypes.size_nat{j < Lib.IntTypes.v n2} -> Prims.GTot Spec.Matrix.elem
[]
Hacl.Impl.Matrix.get_s
{ "file_name": "code/frodo/Hacl.Impl.Matrix.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
h: FStar.Monotonic.HyperStack.mem -> m: Hacl.Impl.Matrix.matrix_t n1 n2 -> i: Lib.IntTypes.size_nat{i < Lib.IntTypes.v n1} -> j: Lib.IntTypes.size_nat{j < Lib.IntTypes.v n2} -> Prims.GTot Spec.Matrix.elem
{ "end_col": 73, "end_line": 511, "start_col": 45, "start_line": 511 }
FStar.HyperStack.ST.Stack
val op_String_Assignment (#n1:size_t) (#n2:size_t{v n1 * v n2 <= max_size_t}) (m:matrix_t n1 n2) (ij:(size_t & size_t){let i, j = ij in v i < v n1 /\ v j < v n2}) (x:elem) : Stack unit (requires fun h0 -> live h0 m) (ensures fun h0 _ h1 -> let i, j = ij in modifies1 m h0 h1 /\ live h1 m /\ as_matrix h1 m == M.mset (as_matrix h0 m) (v i) (v j) x)
[ { "abbrev": true, "full_module": "Spec.Frodo.Lemmas", "short_module": "Lemmas" }, { "abbrev": true, "full_module": "Spec.Matrix", "short_module": "M" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let op_String_Assignment #n1 #n2 m (i,j) x = mset m i j x
val op_String_Assignment (#n1:size_t) (#n2:size_t{v n1 * v n2 <= max_size_t}) (m:matrix_t n1 n2) (ij:(size_t & size_t){let i, j = ij in v i < v n1 /\ v j < v n2}) (x:elem) : Stack unit (requires fun h0 -> live h0 m) (ensures fun h0 _ h1 -> let i, j = ij in modifies1 m h0 h1 /\ live h1 m /\ as_matrix h1 m == M.mset (as_matrix h0 m) (v i) (v j) x) let op_String_Assignment #n1 #n2 m (i, j) x =
true
null
false
mset m i j x
{ "checked_file": "Hacl.Impl.Matrix.fst.checked", "dependencies": [ "Spec.Matrix.fst.checked", "Spec.Frodo.Lemmas.fst.checked", "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.Loops.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Matrix.fst" }
[]
[ "Lib.IntTypes.size_t", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.Mul.op_Star", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Lib.IntTypes.max_size_t", "Hacl.Impl.Matrix.matrix_t", "FStar.Pervasives.Native.tuple2", "Prims.l_and", "Prims.op_LessThan", "Lib.IntTypes.int_t", "Hacl.Impl.Matrix.elem", "Hacl.Impl.Matrix.mset", "Prims.unit" ]
[]
module Hacl.Impl.Matrix open FStar.HyperStack.ST open FStar.Mul open LowStar.BufferOps open LowStar.Buffer open Lib.IntTypes open Lib.Buffer open Lib.ByteBuffer module HS = FStar.HyperStack module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module Loops = Lib.LoopCombinators module M = Spec.Matrix module Lemmas = Spec.Frodo.Lemmas #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" unfold let elem = uint16 unfold let lbytes len = lbuffer uint8 len unfold let matrix_t (n1:size_t) (n2:size_t{v n1 * v n2 <= max_size_t}) = lbuffer elem (n1 *! n2) unfold let as_matrix #n1 #n2 h (m:matrix_t n1 n2) : GTot (M.matrix (v n1) (v n2)) = as_seq h m inline_for_extraction noextract val matrix_create: n1:size_t -> n2:size_t{0 < v n1 * v n2 /\ v n1 * v n2 <= max_size_t} -> StackInline (matrix_t n1 n2) (requires fun h0 -> True) (ensures fun h0 a h1 -> stack_allocated a h0 h1 (as_matrix h1 a) /\ as_matrix h1 a == M.create (v n1) (v n2)) let matrix_create n1 n2 = [@inline_let] let len = size (normalize_term (v n1 * v n2)) in create len (u16 0) inline_for_extraction noextract val mget: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> Stack elem (requires fun h0 -> live h0 a) (ensures fun h0 x h1 -> modifies loc_none h0 h1 /\ x == M.mget (as_matrix h0 a) (v i) (v j)) let mget #n1 #n2 a i j = M.index_lt (v n1) (v n2) (v i) (v j); a.(i *! n2 +! j) inline_for_extraction noextract val mset: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> x:elem -> Stack unit (requires fun h0 -> live h0 a) (ensures fun h0 _ h1 -> modifies1 a h0 h1 /\ as_matrix h1 a == M.mset (as_matrix h0 a) (v i) (v j) x) let mset #n1 #n2 a i j x = M.index_lt (v n1) (v n2) (v i) (v j); a.(i *! n2 +! j) <- x noextract unfold val op_String_Access (#n1:size_t) (#n2:size_t{v n1 * v n2 <= max_size_t}) (m:matrix_t n1 n2) (ij:(size_t & size_t){let i, j = ij in v i < v n1 /\ v j < v n2}) : Stack elem (requires fun h0 -> live h0 m) (ensures fun h0 x h1 -> let i, j = ij in modifies loc_none h0 h1 /\ x == M.mget (as_matrix h0 m) (v i) (v j)) let op_String_Access #n1 #n2 m (i,j) = mget m i j noextract unfold val op_String_Assignment (#n1:size_t) (#n2:size_t{v n1 * v n2 <= max_size_t}) (m:matrix_t n1 n2) (ij:(size_t & size_t){let i, j = ij in v i < v n1 /\ v j < v n2}) (x:elem) : Stack unit (requires fun h0 -> live h0 m)
false
false
Hacl.Impl.Matrix.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val op_String_Assignment (#n1:size_t) (#n2:size_t{v n1 * v n2 <= max_size_t}) (m:matrix_t n1 n2) (ij:(size_t & size_t){let i, j = ij in v i < v n1 /\ v j < v n2}) (x:elem) : Stack unit (requires fun h0 -> live h0 m) (ensures fun h0 _ h1 -> let i, j = ij in modifies1 m h0 h1 /\ live h1 m /\ as_matrix h1 m == M.mset (as_matrix h0 m) (v i) (v j) x)
[]
Hacl.Impl.Matrix.op_String_Assignment
{ "file_name": "code/frodo/Hacl.Impl.Matrix.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
m: Hacl.Impl.Matrix.matrix_t n1 n2 -> ij: (Lib.IntTypes.size_t * Lib.IntTypes.size_t) { let _ = ij in (let FStar.Pervasives.Native.Mktuple2 #_ #_ i j = _ in Lib.IntTypes.v i < Lib.IntTypes.v n1 /\ Lib.IntTypes.v j < Lib.IntTypes.v n2) <: Type0 } -> x: Hacl.Impl.Matrix.elem -> FStar.HyperStack.ST.Stack Prims.unit
{ "end_col": 57, "end_line": 103, "start_col": 45, "start_line": 103 }
Prims.Tot
val map2_inner_inv: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> h2:HS.mem -> f:(elem -> elem -> elem) -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> c:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_nat -> Type0
[ { "abbrev": true, "full_module": "Spec.Frodo.Lemmas", "short_module": "Lemmas" }, { "abbrev": true, "full_module": "Spec.Matrix", "short_module": "M" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let map2_inner_inv #n1 #n2 h0 h1 h2 f a b c i j = live h2 a /\ live h2 b /\ live h2 c /\ modifies1 c h1 h2 /\ j <= v n2 /\ (forall (i0:nat{i0 < v i}) (j:nat{j < v n2}). get h2 c i0 j == get h1 c i0 j) /\ (forall (j0:nat{j0 < j}). get h2 c (v i) j0 == f (get h0 a (v i) j0) (get h2 b (v i) j0)) /\ (forall (j0:nat{j <= j0 /\ j0 < v n2}). get h2 c (v i) j0 == get h0 c (v i) j0) /\ (forall (i0:nat{v i < i0 /\ i0 < v n1}) (j:nat{j < v n2}). get h2 c i0 j == get h0 c i0 j)
val map2_inner_inv: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> h2:HS.mem -> f:(elem -> elem -> elem) -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> c:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_nat -> Type0 let map2_inner_inv #n1 #n2 h0 h1 h2 f a b c i j =
false
null
false
live h2 a /\ live h2 b /\ live h2 c /\ modifies1 c h1 h2 /\ j <= v n2 /\ (forall (i0: nat{i0 < v i}) (j: nat{j < v n2}). get h2 c i0 j == get h1 c i0 j) /\ (forall (j0: nat{j0 < j}). get h2 c (v i) j0 == f (get h0 a (v i) j0) (get h2 b (v i) j0)) /\ (forall (j0: nat{j <= j0 /\ j0 < v n2}). get h2 c (v i) j0 == get h0 c (v i) j0) /\ (forall (i0: nat{v i < i0 /\ i0 < v n1}) (j: nat{j < v n2}). get h2 c i0 j == get h0 c i0 j)
{ "checked_file": "Hacl.Impl.Matrix.fst.checked", "dependencies": [ "Spec.Matrix.fst.checked", "Spec.Frodo.Lemmas.fst.checked", "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.Loops.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Matrix.fst" }
[ "total" ]
[ "Lib.IntTypes.size_t", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.Mul.op_Star", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Lib.IntTypes.max_size_t", "FStar.Monotonic.HyperStack.mem", "Hacl.Impl.Matrix.elem", "Hacl.Impl.Matrix.matrix_t", "Prims.op_LessThan", "Lib.IntTypes.size_nat", "Prims.l_and", "Lib.Buffer.live", "Lib.Buffer.MUT", "Lib.Buffer.modifies1", "Prims.l_Forall", "Prims.nat", "Prims.eq2", "Spec.Matrix.elem", "Hacl.Impl.Matrix.get", "Lib.IntTypes.sec_int_t", "Lib.IntTypes.U16" ]
[]
module Hacl.Impl.Matrix open FStar.HyperStack.ST open FStar.Mul open LowStar.BufferOps open LowStar.Buffer open Lib.IntTypes open Lib.Buffer open Lib.ByteBuffer module HS = FStar.HyperStack module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module Loops = Lib.LoopCombinators module M = Spec.Matrix module Lemmas = Spec.Frodo.Lemmas #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" unfold let elem = uint16 unfold let lbytes len = lbuffer uint8 len unfold let matrix_t (n1:size_t) (n2:size_t{v n1 * v n2 <= max_size_t}) = lbuffer elem (n1 *! n2) unfold let as_matrix #n1 #n2 h (m:matrix_t n1 n2) : GTot (M.matrix (v n1) (v n2)) = as_seq h m inline_for_extraction noextract val matrix_create: n1:size_t -> n2:size_t{0 < v n1 * v n2 /\ v n1 * v n2 <= max_size_t} -> StackInline (matrix_t n1 n2) (requires fun h0 -> True) (ensures fun h0 a h1 -> stack_allocated a h0 h1 (as_matrix h1 a) /\ as_matrix h1 a == M.create (v n1) (v n2)) let matrix_create n1 n2 = [@inline_let] let len = size (normalize_term (v n1 * v n2)) in create len (u16 0) inline_for_extraction noextract val mget: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> Stack elem (requires fun h0 -> live h0 a) (ensures fun h0 x h1 -> modifies loc_none h0 h1 /\ x == M.mget (as_matrix h0 a) (v i) (v j)) let mget #n1 #n2 a i j = M.index_lt (v n1) (v n2) (v i) (v j); a.(i *! n2 +! j) inline_for_extraction noextract val mset: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> x:elem -> Stack unit (requires fun h0 -> live h0 a) (ensures fun h0 _ h1 -> modifies1 a h0 h1 /\ as_matrix h1 a == M.mset (as_matrix h0 a) (v i) (v j) x) let mset #n1 #n2 a i j x = M.index_lt (v n1) (v n2) (v i) (v j); a.(i *! n2 +! j) <- x noextract unfold val op_String_Access (#n1:size_t) (#n2:size_t{v n1 * v n2 <= max_size_t}) (m:matrix_t n1 n2) (ij:(size_t & size_t){let i, j = ij in v i < v n1 /\ v j < v n2}) : Stack elem (requires fun h0 -> live h0 m) (ensures fun h0 x h1 -> let i, j = ij in modifies loc_none h0 h1 /\ x == M.mget (as_matrix h0 m) (v i) (v j)) let op_String_Access #n1 #n2 m (i,j) = mget m i j noextract unfold val op_String_Assignment (#n1:size_t) (#n2:size_t{v n1 * v n2 <= max_size_t}) (m:matrix_t n1 n2) (ij:(size_t & size_t){let i, j = ij in v i < v n1 /\ v j < v n2}) (x:elem) : Stack unit (requires fun h0 -> live h0 m) (ensures fun h0 _ h1 -> let i, j = ij in modifies1 m h0 h1 /\ live h1 m /\ as_matrix h1 m == M.mset (as_matrix h0 m) (v i) (v j) x) let op_String_Assignment #n1 #n2 m (i,j) x = mset m i j x unfold let get #n1 #n2 h (m:matrix_t n1 n2) i j = M.mget (as_matrix h m) i j private unfold val map_inner_inv: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> h2:HS.mem -> f:(elem -> elem) -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_nat -> Type0 let map_inner_inv #n1 #n2 h0 h1 h2 f a c i j = live h2 a /\ live h2 c /\ modifies1 c h1 h2 /\ j <= v n2 /\ (forall (i0:nat{i0 < v i}) (j:nat{j < v n2}). get h2 c i0 j == get h1 c i0 j) /\ (forall (j0:nat{j0 < j}). get h2 c (v i) j0 == f (get h0 a (v i) j0)) /\ (forall (j0:nat{j <= j0 /\ j0 < v n2}). get h2 c (v i) j0 == get h0 c (v i) j0) /\ (forall (i0:nat{v i < i0 /\ i0 < v n1}) (j:nat{j < v n2}). get h2 c i0 j == get h0 c i0 j) inline_for_extraction noextract private val map_inner: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> f:(elem -> elem) -> a:matrix_t n1 n2 -> c:matrix_t n1 n2{a == c} -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> Stack unit (requires fun h2 -> map_inner_inv h0 h1 h2 f a c i (v j)) (ensures fun _ _ h2 -> map_inner_inv h0 h1 h2 f a c i (v j + 1)) let map_inner #n1 #n2 h0 h1 f a c i j = c.[i,j] <- f a.[i,j] inline_for_extraction val map: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> f:(uint16 -> uint16) -> a:matrix_t n1 n2 -> c:matrix_t n1 n2 -> Stack unit (requires fun h0 -> live h0 a /\ live h0 c /\ a == c) (ensures fun h0 _ h1 -> modifies1 c h0 h1 /\ as_matrix h1 c == M.map #(v n1) #(v n2) f (as_matrix h0 a)) let map #n1 #n2 f a c = let h0 = ST.get () in Lib.Loops.for (size 0) n1 (fun h1 i -> live h1 a /\ live h1 c /\ modifies1 c h0 h1 /\ i <= v n1 /\ (forall (i0:nat{i0 < i}) (j:nat{j < v n2}). get h1 c i0 j == f (get h0 a i0 j)) /\ (forall (i0:nat{i <= i0 /\ i0 < v n1}) (j:nat{j < v n2}). get h1 c i0 j == get h0 c i0 j) ) (fun i -> let h1 = ST.get() in Lib.Loops.for (size 0) n2 (fun h2 j -> map_inner_inv h0 h1 h2 f a c i j) (fun j -> map_inner h0 h1 f a c i j) ); let h2 = ST.get () in M.extensionality (as_matrix h2 c) (M.map f (as_matrix h0 a)) inline_for_extraction noextract val mod_pow2_felem: logq:size_t{0 < v logq /\ v logq < 16} -> a:uint16 -> Pure uint16 (requires True) (ensures fun r -> r == M.mod_pow2_felem (v logq) a) let mod_pow2_felem logq a = a &. ((u16 1 <<. logq) -. u16 1) val mod_pow2: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> logq:size_t{0 < v logq /\ v logq <= 16} -> a:matrix_t n1 n2 -> Stack unit (requires fun h -> live h a) (ensures fun h0 _ h1 -> modifies1 a h0 h1 /\ as_matrix h1 a == M.mod_pow2 (v logq) (as_matrix h0 a)) [@"c_inline"] let mod_pow2 #n1 #n2 logq a = if logq <. 16ul then begin let h0 = ST.get () in map (mod_pow2_felem logq) a a; M.extensionality (M.map #(v n1) #(v n2) (mod_pow2_felem logq) (as_matrix h0 a)) (M.map #(v n1) #(v n2) (M.mod_pow2_felem (v logq)) (as_matrix h0 a)) end private unfold val map2_inner_inv: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> h2:HS.mem -> f:(elem -> elem -> elem) -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> c:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_nat -> Type0
false
false
Hacl.Impl.Matrix.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val map2_inner_inv: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> h2:HS.mem -> f:(elem -> elem -> elem) -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> c:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_nat -> Type0
[]
Hacl.Impl.Matrix.map2_inner_inv
{ "file_name": "code/frodo/Hacl.Impl.Matrix.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
h0: FStar.Monotonic.HyperStack.mem -> h1: FStar.Monotonic.HyperStack.mem -> h2: FStar.Monotonic.HyperStack.mem -> f: (_: Hacl.Impl.Matrix.elem -> _: Hacl.Impl.Matrix.elem -> Hacl.Impl.Matrix.elem) -> a: Hacl.Impl.Matrix.matrix_t n1 n2 -> b: Hacl.Impl.Matrix.matrix_t n1 n2 -> c: Hacl.Impl.Matrix.matrix_t n1 n2 -> i: Lib.IntTypes.size_t{Lib.IntTypes.v i < Lib.IntTypes.v n1} -> j: Lib.IntTypes.size_nat -> Type0
{ "end_col": 92, "end_line": 238, "start_col": 2, "start_line": 232 }
FStar.HyperStack.ST.StackInline
val matrix_create: n1:size_t -> n2:size_t{0 < v n1 * v n2 /\ v n1 * v n2 <= max_size_t} -> StackInline (matrix_t n1 n2) (requires fun h0 -> True) (ensures fun h0 a h1 -> stack_allocated a h0 h1 (as_matrix h1 a) /\ as_matrix h1 a == M.create (v n1) (v n2))
[ { "abbrev": true, "full_module": "Spec.Frodo.Lemmas", "short_module": "Lemmas" }, { "abbrev": true, "full_module": "Spec.Matrix", "short_module": "M" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let matrix_create n1 n2 = [@inline_let] let len = size (normalize_term (v n1 * v n2)) in create len (u16 0)
val matrix_create: n1:size_t -> n2:size_t{0 < v n1 * v n2 /\ v n1 * v n2 <= max_size_t} -> StackInline (matrix_t n1 n2) (requires fun h0 -> True) (ensures fun h0 a h1 -> stack_allocated a h0 h1 (as_matrix h1 a) /\ as_matrix h1 a == M.create (v n1) (v n2)) let matrix_create n1 n2 =
true
null
false
[@@ inline_let ]let len = size (normalize_term (v n1 * v n2)) in create len (u16 0)
{ "checked_file": "Hacl.Impl.Matrix.fst.checked", "dependencies": [ "Spec.Matrix.fst.checked", "Spec.Frodo.Lemmas.fst.checked", "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.Loops.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Matrix.fst" }
[]
[ "Lib.IntTypes.size_t", "Prims.l_and", "Prims.b2t", "Prims.op_LessThan", "FStar.Mul.op_Star", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Prims.op_LessThanOrEqual", "Lib.IntTypes.max_size_t", "Lib.Buffer.create", "Hacl.Impl.Matrix.elem", "Lib.IntTypes.u16", "Lib.Buffer.lbuffer", "Lib.IntTypes.int_t", "Lib.IntTypes.size", "FStar.Pervasives.normalize_term", "Lib.IntTypes.size_nat", "Hacl.Impl.Matrix.matrix_t" ]
[]
module Hacl.Impl.Matrix open FStar.HyperStack.ST open FStar.Mul open LowStar.BufferOps open LowStar.Buffer open Lib.IntTypes open Lib.Buffer open Lib.ByteBuffer module HS = FStar.HyperStack module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module Loops = Lib.LoopCombinators module M = Spec.Matrix module Lemmas = Spec.Frodo.Lemmas #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" unfold let elem = uint16 unfold let lbytes len = lbuffer uint8 len unfold let matrix_t (n1:size_t) (n2:size_t{v n1 * v n2 <= max_size_t}) = lbuffer elem (n1 *! n2) unfold let as_matrix #n1 #n2 h (m:matrix_t n1 n2) : GTot (M.matrix (v n1) (v n2)) = as_seq h m inline_for_extraction noextract val matrix_create: n1:size_t -> n2:size_t{0 < v n1 * v n2 /\ v n1 * v n2 <= max_size_t} -> StackInline (matrix_t n1 n2) (requires fun h0 -> True) (ensures fun h0 a h1 -> stack_allocated a h0 h1 (as_matrix h1 a) /\ as_matrix h1 a == M.create (v n1) (v n2))
false
false
Hacl.Impl.Matrix.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val matrix_create: n1:size_t -> n2:size_t{0 < v n1 * v n2 /\ v n1 * v n2 <= max_size_t} -> StackInline (matrix_t n1 n2) (requires fun h0 -> True) (ensures fun h0 a h1 -> stack_allocated a h0 h1 (as_matrix h1 a) /\ as_matrix h1 a == M.create (v n1) (v n2))
[]
Hacl.Impl.Matrix.matrix_create
{ "file_name": "code/frodo/Hacl.Impl.Matrix.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
n1: Lib.IntTypes.size_t -> n2: Lib.IntTypes.size_t { 0 < Lib.IntTypes.v n1 * Lib.IntTypes.v n2 /\ Lib.IntTypes.v n1 * Lib.IntTypes.v n2 <= Lib.IntTypes.max_size_t } -> FStar.HyperStack.ST.StackInline (Hacl.Impl.Matrix.matrix_t n1 n2)
{ "end_col": 20, "end_line": 52, "start_col": 2, "start_line": 50 }
FStar.HyperStack.ST.Stack
val matrix_add: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> Stack unit (requires fun h -> live h a /\ live h b /\ disjoint a b) (ensures fun h0 r h1 -> modifies1 a h0 h1 /\ as_matrix h1 a == M.add (as_matrix h0 a) (as_matrix h0 b))
[ { "abbrev": true, "full_module": "Spec.Frodo.Lemmas", "short_module": "Lemmas" }, { "abbrev": true, "full_module": "Spec.Matrix", "short_module": "M" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let matrix_add #n1 #n2 a b = map2 add_mod a b a
val matrix_add: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> Stack unit (requires fun h -> live h a /\ live h b /\ disjoint a b) (ensures fun h0 r h1 -> modifies1 a h0 h1 /\ as_matrix h1 a == M.add (as_matrix h0 a) (as_matrix h0 b)) let matrix_add #n1 #n2 a b =
true
null
false
map2 add_mod a b a
{ "checked_file": "Hacl.Impl.Matrix.fst.checked", "dependencies": [ "Spec.Matrix.fst.checked", "Spec.Frodo.Lemmas.fst.checked", "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.Loops.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Matrix.fst" }
[]
[ "Lib.IntTypes.size_t", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.Mul.op_Star", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Lib.IntTypes.max_size_t", "Hacl.Impl.Matrix.matrix_t", "Hacl.Impl.Matrix.map2", "Lib.IntTypes.add_mod", "Lib.IntTypes.U16", "Lib.IntTypes.SEC", "Prims.unit" ]
[]
module Hacl.Impl.Matrix open FStar.HyperStack.ST open FStar.Mul open LowStar.BufferOps open LowStar.Buffer open Lib.IntTypes open Lib.Buffer open Lib.ByteBuffer module HS = FStar.HyperStack module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module Loops = Lib.LoopCombinators module M = Spec.Matrix module Lemmas = Spec.Frodo.Lemmas #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" unfold let elem = uint16 unfold let lbytes len = lbuffer uint8 len unfold let matrix_t (n1:size_t) (n2:size_t{v n1 * v n2 <= max_size_t}) = lbuffer elem (n1 *! n2) unfold let as_matrix #n1 #n2 h (m:matrix_t n1 n2) : GTot (M.matrix (v n1) (v n2)) = as_seq h m inline_for_extraction noextract val matrix_create: n1:size_t -> n2:size_t{0 < v n1 * v n2 /\ v n1 * v n2 <= max_size_t} -> StackInline (matrix_t n1 n2) (requires fun h0 -> True) (ensures fun h0 a h1 -> stack_allocated a h0 h1 (as_matrix h1 a) /\ as_matrix h1 a == M.create (v n1) (v n2)) let matrix_create n1 n2 = [@inline_let] let len = size (normalize_term (v n1 * v n2)) in create len (u16 0) inline_for_extraction noextract val mget: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> Stack elem (requires fun h0 -> live h0 a) (ensures fun h0 x h1 -> modifies loc_none h0 h1 /\ x == M.mget (as_matrix h0 a) (v i) (v j)) let mget #n1 #n2 a i j = M.index_lt (v n1) (v n2) (v i) (v j); a.(i *! n2 +! j) inline_for_extraction noextract val mset: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> x:elem -> Stack unit (requires fun h0 -> live h0 a) (ensures fun h0 _ h1 -> modifies1 a h0 h1 /\ as_matrix h1 a == M.mset (as_matrix h0 a) (v i) (v j) x) let mset #n1 #n2 a i j x = M.index_lt (v n1) (v n2) (v i) (v j); a.(i *! n2 +! j) <- x noextract unfold val op_String_Access (#n1:size_t) (#n2:size_t{v n1 * v n2 <= max_size_t}) (m:matrix_t n1 n2) (ij:(size_t & size_t){let i, j = ij in v i < v n1 /\ v j < v n2}) : Stack elem (requires fun h0 -> live h0 m) (ensures fun h0 x h1 -> let i, j = ij in modifies loc_none h0 h1 /\ x == M.mget (as_matrix h0 m) (v i) (v j)) let op_String_Access #n1 #n2 m (i,j) = mget m i j noextract unfold val op_String_Assignment (#n1:size_t) (#n2:size_t{v n1 * v n2 <= max_size_t}) (m:matrix_t n1 n2) (ij:(size_t & size_t){let i, j = ij in v i < v n1 /\ v j < v n2}) (x:elem) : Stack unit (requires fun h0 -> live h0 m) (ensures fun h0 _ h1 -> let i, j = ij in modifies1 m h0 h1 /\ live h1 m /\ as_matrix h1 m == M.mset (as_matrix h0 m) (v i) (v j) x) let op_String_Assignment #n1 #n2 m (i,j) x = mset m i j x unfold let get #n1 #n2 h (m:matrix_t n1 n2) i j = M.mget (as_matrix h m) i j private unfold val map_inner_inv: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> h2:HS.mem -> f:(elem -> elem) -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_nat -> Type0 let map_inner_inv #n1 #n2 h0 h1 h2 f a c i j = live h2 a /\ live h2 c /\ modifies1 c h1 h2 /\ j <= v n2 /\ (forall (i0:nat{i0 < v i}) (j:nat{j < v n2}). get h2 c i0 j == get h1 c i0 j) /\ (forall (j0:nat{j0 < j}). get h2 c (v i) j0 == f (get h0 a (v i) j0)) /\ (forall (j0:nat{j <= j0 /\ j0 < v n2}). get h2 c (v i) j0 == get h0 c (v i) j0) /\ (forall (i0:nat{v i < i0 /\ i0 < v n1}) (j:nat{j < v n2}). get h2 c i0 j == get h0 c i0 j) inline_for_extraction noextract private val map_inner: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> f:(elem -> elem) -> a:matrix_t n1 n2 -> c:matrix_t n1 n2{a == c} -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> Stack unit (requires fun h2 -> map_inner_inv h0 h1 h2 f a c i (v j)) (ensures fun _ _ h2 -> map_inner_inv h0 h1 h2 f a c i (v j + 1)) let map_inner #n1 #n2 h0 h1 f a c i j = c.[i,j] <- f a.[i,j] inline_for_extraction val map: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> f:(uint16 -> uint16) -> a:matrix_t n1 n2 -> c:matrix_t n1 n2 -> Stack unit (requires fun h0 -> live h0 a /\ live h0 c /\ a == c) (ensures fun h0 _ h1 -> modifies1 c h0 h1 /\ as_matrix h1 c == M.map #(v n1) #(v n2) f (as_matrix h0 a)) let map #n1 #n2 f a c = let h0 = ST.get () in Lib.Loops.for (size 0) n1 (fun h1 i -> live h1 a /\ live h1 c /\ modifies1 c h0 h1 /\ i <= v n1 /\ (forall (i0:nat{i0 < i}) (j:nat{j < v n2}). get h1 c i0 j == f (get h0 a i0 j)) /\ (forall (i0:nat{i <= i0 /\ i0 < v n1}) (j:nat{j < v n2}). get h1 c i0 j == get h0 c i0 j) ) (fun i -> let h1 = ST.get() in Lib.Loops.for (size 0) n2 (fun h2 j -> map_inner_inv h0 h1 h2 f a c i j) (fun j -> map_inner h0 h1 f a c i j) ); let h2 = ST.get () in M.extensionality (as_matrix h2 c) (M.map f (as_matrix h0 a)) inline_for_extraction noextract val mod_pow2_felem: logq:size_t{0 < v logq /\ v logq < 16} -> a:uint16 -> Pure uint16 (requires True) (ensures fun r -> r == M.mod_pow2_felem (v logq) a) let mod_pow2_felem logq a = a &. ((u16 1 <<. logq) -. u16 1) val mod_pow2: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> logq:size_t{0 < v logq /\ v logq <= 16} -> a:matrix_t n1 n2 -> Stack unit (requires fun h -> live h a) (ensures fun h0 _ h1 -> modifies1 a h0 h1 /\ as_matrix h1 a == M.mod_pow2 (v logq) (as_matrix h0 a)) [@"c_inline"] let mod_pow2 #n1 #n2 logq a = if logq <. 16ul then begin let h0 = ST.get () in map (mod_pow2_felem logq) a a; M.extensionality (M.map #(v n1) #(v n2) (mod_pow2_felem logq) (as_matrix h0 a)) (M.map #(v n1) #(v n2) (M.mod_pow2_felem (v logq)) (as_matrix h0 a)) end private unfold val map2_inner_inv: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> h2:HS.mem -> f:(elem -> elem -> elem) -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> c:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_nat -> Type0 let map2_inner_inv #n1 #n2 h0 h1 h2 f a b c i j = live h2 a /\ live h2 b /\ live h2 c /\ modifies1 c h1 h2 /\ j <= v n2 /\ (forall (i0:nat{i0 < v i}) (j:nat{j < v n2}). get h2 c i0 j == get h1 c i0 j) /\ (forall (j0:nat{j0 < j}). get h2 c (v i) j0 == f (get h0 a (v i) j0) (get h2 b (v i) j0)) /\ (forall (j0:nat{j <= j0 /\ j0 < v n2}). get h2 c (v i) j0 == get h0 c (v i) j0) /\ (forall (i0:nat{v i < i0 /\ i0 < v n1}) (j:nat{j < v n2}). get h2 c i0 j == get h0 c i0 j) inline_for_extraction noextract private val map2_inner: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> f:(elem -> elem -> elem) -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> c:matrix_t n1 n2{a == c /\ disjoint b c} -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> Stack unit (requires fun h2 -> map2_inner_inv h0 h1 h2 f a b c i (v j)) (ensures fun _ _ h2 -> map2_inner_inv h0 h1 h2 f a b c i (v j + 1)) let map2_inner #n1 #n2 h0 h1 f a b c i j = c.[i,j] <- f a.[i,j] b.[i,j] /// In-place [map2], a == map2 f a b /// /// A non in-place variant can be obtained by weakening the pre-condition to disjoint a c, /// or the two variants can be merged by requiring (a == c \/ disjoint a c) instead of a == c /// See commit 91916b8372fa3522061eff5a42d0ebd1d19a8a49 inline_for_extraction val map2: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> f:(uint16 -> uint16 -> uint16) -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> c:matrix_t n1 n2 -> Stack unit (requires fun h0 -> live h0 a /\ live h0 b /\ live h0 c /\ a == c /\ disjoint b c) (ensures fun h0 _ h1 -> modifies1 c h0 h1 /\ as_matrix h1 c == M.map2 #(v n1) #(v n2) f (as_matrix h0 a) (as_matrix h0 b)) let map2 #n1 #n2 f a b c = let h0 = ST.get () in Lib.Loops.for (size 0) n1 (fun h1 i -> live h1 a /\ live h1 b /\ live h1 c /\ modifies1 c h0 h1 /\ i <= v n1 /\ (forall (i0:nat{i0 < i}) (j:nat{j < v n2}). get h1 c i0 j == f (get h0 a i0 j) (get h0 b i0 j)) /\ (forall (i0:nat{i <= i0 /\ i0 < v n1}) (j:nat{j < v n2}). get h1 c i0 j == get h0 c i0 j) ) (fun i -> let h1 = ST.get() in Lib.Loops.for (size 0) n2 (fun h2 j -> map2_inner_inv h0 h1 h2 f a b c i j) (fun j -> map2_inner h0 h1 f a b c i j) ); let h2 = ST.get() in M.extensionality (as_matrix h2 c) (M.map2 f (as_matrix h0 a) (as_matrix h0 b)) val matrix_add: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> Stack unit (requires fun h -> live h a /\ live h b /\ disjoint a b) (ensures fun h0 r h1 -> modifies1 a h0 h1 /\ as_matrix h1 a == M.add (as_matrix h0 a) (as_matrix h0 b)) [@"c_inline"]
false
false
Hacl.Impl.Matrix.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val matrix_add: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> Stack unit (requires fun h -> live h a /\ live h b /\ disjoint a b) (ensures fun h0 r h1 -> modifies1 a h0 h1 /\ as_matrix h1 a == M.add (as_matrix h0 a) (as_matrix h0 b))
[]
Hacl.Impl.Matrix.matrix_add
{ "file_name": "code/frodo/Hacl.Impl.Matrix.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
a: Hacl.Impl.Matrix.matrix_t n1 n2 -> b: Hacl.Impl.Matrix.matrix_t n1 n2 -> FStar.HyperStack.ST.Stack Prims.unit
{ "end_col": 20, "end_line": 312, "start_col": 2, "start_line": 312 }
FStar.HyperStack.ST.Stack
val mset: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> x:elem -> Stack unit (requires fun h0 -> live h0 a) (ensures fun h0 _ h1 -> modifies1 a h0 h1 /\ as_matrix h1 a == M.mset (as_matrix h0 a) (v i) (v j) x)
[ { "abbrev": true, "full_module": "Spec.Frodo.Lemmas", "short_module": "Lemmas" }, { "abbrev": true, "full_module": "Spec.Matrix", "short_module": "M" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let mset #n1 #n2 a i j x = M.index_lt (v n1) (v n2) (v i) (v j); a.(i *! n2 +! j) <- x
val mset: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> x:elem -> Stack unit (requires fun h0 -> live h0 a) (ensures fun h0 _ h1 -> modifies1 a h0 h1 /\ as_matrix h1 a == M.mset (as_matrix h0 a) (v i) (v j) x) let mset #n1 #n2 a i j x =
true
null
false
M.index_lt (v n1) (v n2) (v i) (v j); a.(i *! n2 +! j) <- x
{ "checked_file": "Hacl.Impl.Matrix.fst.checked", "dependencies": [ "Spec.Matrix.fst.checked", "Spec.Frodo.Lemmas.fst.checked", "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.Loops.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Matrix.fst" }
[]
[ "Lib.IntTypes.size_t", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.Mul.op_Star", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Lib.IntTypes.max_size_t", "Hacl.Impl.Matrix.matrix_t", "Prims.op_LessThan", "Hacl.Impl.Matrix.elem", "Lib.Buffer.op_Array_Assignment", "Lib.IntTypes.op_Star_Bang", "Lib.IntTypes.op_Plus_Bang", "Prims.unit", "Spec.Matrix.index_lt" ]
[]
module Hacl.Impl.Matrix open FStar.HyperStack.ST open FStar.Mul open LowStar.BufferOps open LowStar.Buffer open Lib.IntTypes open Lib.Buffer open Lib.ByteBuffer module HS = FStar.HyperStack module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module Loops = Lib.LoopCombinators module M = Spec.Matrix module Lemmas = Spec.Frodo.Lemmas #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" unfold let elem = uint16 unfold let lbytes len = lbuffer uint8 len unfold let matrix_t (n1:size_t) (n2:size_t{v n1 * v n2 <= max_size_t}) = lbuffer elem (n1 *! n2) unfold let as_matrix #n1 #n2 h (m:matrix_t n1 n2) : GTot (M.matrix (v n1) (v n2)) = as_seq h m inline_for_extraction noextract val matrix_create: n1:size_t -> n2:size_t{0 < v n1 * v n2 /\ v n1 * v n2 <= max_size_t} -> StackInline (matrix_t n1 n2) (requires fun h0 -> True) (ensures fun h0 a h1 -> stack_allocated a h0 h1 (as_matrix h1 a) /\ as_matrix h1 a == M.create (v n1) (v n2)) let matrix_create n1 n2 = [@inline_let] let len = size (normalize_term (v n1 * v n2)) in create len (u16 0) inline_for_extraction noextract val mget: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> Stack elem (requires fun h0 -> live h0 a) (ensures fun h0 x h1 -> modifies loc_none h0 h1 /\ x == M.mget (as_matrix h0 a) (v i) (v j)) let mget #n1 #n2 a i j = M.index_lt (v n1) (v n2) (v i) (v j); a.(i *! n2 +! j) inline_for_extraction noextract val mset: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> x:elem -> Stack unit (requires fun h0 -> live h0 a) (ensures fun h0 _ h1 -> modifies1 a h0 h1 /\ as_matrix h1 a == M.mset (as_matrix h0 a) (v i) (v j) x)
false
false
Hacl.Impl.Matrix.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val mset: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> x:elem -> Stack unit (requires fun h0 -> live h0 a) (ensures fun h0 _ h1 -> modifies1 a h0 h1 /\ as_matrix h1 a == M.mset (as_matrix h0 a) (v i) (v j) x)
[]
Hacl.Impl.Matrix.mset
{ "file_name": "code/frodo/Hacl.Impl.Matrix.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
a: Hacl.Impl.Matrix.matrix_t n1 n2 -> i: Lib.IntTypes.size_t{Lib.IntTypes.v i < Lib.IntTypes.v n1} -> j: Lib.IntTypes.size_t{Lib.IntTypes.v j < Lib.IntTypes.v n2} -> x: Hacl.Impl.Matrix.elem -> FStar.HyperStack.ST.Stack Prims.unit
{ "end_col": 23, "end_line": 87, "start_col": 2, "start_line": 86 }
FStar.HyperStack.ST.Stack
val mget: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> Stack elem (requires fun h0 -> live h0 a) (ensures fun h0 x h1 -> modifies loc_none h0 h1 /\ x == M.mget (as_matrix h0 a) (v i) (v j))
[ { "abbrev": true, "full_module": "Spec.Frodo.Lemmas", "short_module": "Lemmas" }, { "abbrev": true, "full_module": "Spec.Matrix", "short_module": "M" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let mget #n1 #n2 a i j = M.index_lt (v n1) (v n2) (v i) (v j); a.(i *! n2 +! j)
val mget: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> Stack elem (requires fun h0 -> live h0 a) (ensures fun h0 x h1 -> modifies loc_none h0 h1 /\ x == M.mget (as_matrix h0 a) (v i) (v j)) let mget #n1 #n2 a i j =
true
null
false
M.index_lt (v n1) (v n2) (v i) (v j); a.(i *! n2 +! j)
{ "checked_file": "Hacl.Impl.Matrix.fst.checked", "dependencies": [ "Spec.Matrix.fst.checked", "Spec.Frodo.Lemmas.fst.checked", "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.Loops.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Matrix.fst" }
[]
[ "Lib.IntTypes.size_t", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.Mul.op_Star", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Lib.IntTypes.max_size_t", "Hacl.Impl.Matrix.matrix_t", "Prims.op_LessThan", "Lib.Buffer.op_Array_Access", "Lib.Buffer.MUT", "Hacl.Impl.Matrix.elem", "Lib.IntTypes.op_Star_Bang", "Lib.IntTypes.op_Plus_Bang", "Prims.unit", "Spec.Matrix.index_lt" ]
[]
module Hacl.Impl.Matrix open FStar.HyperStack.ST open FStar.Mul open LowStar.BufferOps open LowStar.Buffer open Lib.IntTypes open Lib.Buffer open Lib.ByteBuffer module HS = FStar.HyperStack module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module Loops = Lib.LoopCombinators module M = Spec.Matrix module Lemmas = Spec.Frodo.Lemmas #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" unfold let elem = uint16 unfold let lbytes len = lbuffer uint8 len unfold let matrix_t (n1:size_t) (n2:size_t{v n1 * v n2 <= max_size_t}) = lbuffer elem (n1 *! n2) unfold let as_matrix #n1 #n2 h (m:matrix_t n1 n2) : GTot (M.matrix (v n1) (v n2)) = as_seq h m inline_for_extraction noextract val matrix_create: n1:size_t -> n2:size_t{0 < v n1 * v n2 /\ v n1 * v n2 <= max_size_t} -> StackInline (matrix_t n1 n2) (requires fun h0 -> True) (ensures fun h0 a h1 -> stack_allocated a h0 h1 (as_matrix h1 a) /\ as_matrix h1 a == M.create (v n1) (v n2)) let matrix_create n1 n2 = [@inline_let] let len = size (normalize_term (v n1 * v n2)) in create len (u16 0) inline_for_extraction noextract val mget: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> Stack elem (requires fun h0 -> live h0 a) (ensures fun h0 x h1 -> modifies loc_none h0 h1 /\ x == M.mget (as_matrix h0 a) (v i) (v j))
false
false
Hacl.Impl.Matrix.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val mget: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> Stack elem (requires fun h0 -> live h0 a) (ensures fun h0 x h1 -> modifies loc_none h0 h1 /\ x == M.mget (as_matrix h0 a) (v i) (v j))
[]
Hacl.Impl.Matrix.mget
{ "file_name": "code/frodo/Hacl.Impl.Matrix.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
a: Hacl.Impl.Matrix.matrix_t n1 n2 -> i: Lib.IntTypes.size_t{Lib.IntTypes.v i < Lib.IntTypes.v n1} -> j: Lib.IntTypes.size_t{Lib.IntTypes.v j < Lib.IntTypes.v n2} -> FStar.HyperStack.ST.Stack Hacl.Impl.Matrix.elem
{ "end_col": 18, "end_line": 69, "start_col": 2, "start_line": 68 }
Prims.Tot
val mul_inner_inv: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> #n3:size_t{v n2 * v n3 <= max_size_t /\ v n1 * v n3 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> h2:HS.mem -> a:matrix_t n1 n2 -> b:matrix_t n2 n3 -> c:matrix_t n1 n3 -> f:(k:nat{k < v n3} -> GTot uint16) -> i:size_t{v i < v n1} -> k:size_nat -> Type0
[ { "abbrev": true, "full_module": "Spec.Frodo.Lemmas", "short_module": "Lemmas" }, { "abbrev": true, "full_module": "Spec.Matrix", "short_module": "M" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let mul_inner_inv #n1 #n2 #n3 h0 h1 h2 a b c f i k = live h2 a /\ live h2 b /\ live h2 c /\ modifies1 c h1 h2 /\ k <= v n3 /\ (forall (i1:nat{i1 < v i}) (k:nat{k < v n3}). get h2 c i1 k == get h1 c i1 k) /\ (forall (k1:nat{k1 < k}). get h2 c (v i) k1 == f k1) /\ (forall (k1:nat{k <= k1 /\ k1 < v n3}). get h2 c (v i) k1 == get h0 c (v i) k1) /\ (forall (i1:nat{v i < i1 /\ i1 < v n1}) (k:nat{k < v n3}). get h2 c i1 k == get h0 c i1 k) /\ as_matrix h0 a == as_matrix h2 a /\ as_matrix h0 b == as_matrix h2 b
val mul_inner_inv: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> #n3:size_t{v n2 * v n3 <= max_size_t /\ v n1 * v n3 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> h2:HS.mem -> a:matrix_t n1 n2 -> b:matrix_t n2 n3 -> c:matrix_t n1 n3 -> f:(k:nat{k < v n3} -> GTot uint16) -> i:size_t{v i < v n1} -> k:size_nat -> Type0 let mul_inner_inv #n1 #n2 #n3 h0 h1 h2 a b c f i k =
false
null
false
live h2 a /\ live h2 b /\ live h2 c /\ modifies1 c h1 h2 /\ k <= v n3 /\ (forall (i1: nat{i1 < v i}) (k: nat{k < v n3}). get h2 c i1 k == get h1 c i1 k) /\ (forall (k1: nat{k1 < k}). get h2 c (v i) k1 == f k1) /\ (forall (k1: nat{k <= k1 /\ k1 < v n3}). get h2 c (v i) k1 == get h0 c (v i) k1) /\ (forall (i1: nat{v i < i1 /\ i1 < v n1}) (k: nat{k < v n3}). get h2 c i1 k == get h0 c i1 k) /\ as_matrix h0 a == as_matrix h2 a /\ as_matrix h0 b == as_matrix h2 b
{ "checked_file": "Hacl.Impl.Matrix.fst.checked", "dependencies": [ "Spec.Matrix.fst.checked", "Spec.Frodo.Lemmas.fst.checked", "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.Loops.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Matrix.fst" }
[ "total" ]
[ "Lib.IntTypes.size_t", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.Mul.op_Star", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Lib.IntTypes.max_size_t", "Prims.l_and", "FStar.Monotonic.HyperStack.mem", "Hacl.Impl.Matrix.matrix_t", "Prims.nat", "Prims.op_LessThan", "Lib.IntTypes.uint16", "Lib.IntTypes.size_nat", "Lib.Buffer.live", "Lib.Buffer.MUT", "Hacl.Impl.Matrix.elem", "Lib.Buffer.modifies1", "Prims.l_Forall", "Prims.eq2", "Spec.Matrix.elem", "Hacl.Impl.Matrix.get", "Spec.Matrix.matrix", "Hacl.Impl.Matrix.as_matrix" ]
[]
module Hacl.Impl.Matrix open FStar.HyperStack.ST open FStar.Mul open LowStar.BufferOps open LowStar.Buffer open Lib.IntTypes open Lib.Buffer open Lib.ByteBuffer module HS = FStar.HyperStack module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module Loops = Lib.LoopCombinators module M = Spec.Matrix module Lemmas = Spec.Frodo.Lemmas #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" unfold let elem = uint16 unfold let lbytes len = lbuffer uint8 len unfold let matrix_t (n1:size_t) (n2:size_t{v n1 * v n2 <= max_size_t}) = lbuffer elem (n1 *! n2) unfold let as_matrix #n1 #n2 h (m:matrix_t n1 n2) : GTot (M.matrix (v n1) (v n2)) = as_seq h m inline_for_extraction noextract val matrix_create: n1:size_t -> n2:size_t{0 < v n1 * v n2 /\ v n1 * v n2 <= max_size_t} -> StackInline (matrix_t n1 n2) (requires fun h0 -> True) (ensures fun h0 a h1 -> stack_allocated a h0 h1 (as_matrix h1 a) /\ as_matrix h1 a == M.create (v n1) (v n2)) let matrix_create n1 n2 = [@inline_let] let len = size (normalize_term (v n1 * v n2)) in create len (u16 0) inline_for_extraction noextract val mget: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> Stack elem (requires fun h0 -> live h0 a) (ensures fun h0 x h1 -> modifies loc_none h0 h1 /\ x == M.mget (as_matrix h0 a) (v i) (v j)) let mget #n1 #n2 a i j = M.index_lt (v n1) (v n2) (v i) (v j); a.(i *! n2 +! j) inline_for_extraction noextract val mset: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> x:elem -> Stack unit (requires fun h0 -> live h0 a) (ensures fun h0 _ h1 -> modifies1 a h0 h1 /\ as_matrix h1 a == M.mset (as_matrix h0 a) (v i) (v j) x) let mset #n1 #n2 a i j x = M.index_lt (v n1) (v n2) (v i) (v j); a.(i *! n2 +! j) <- x noextract unfold val op_String_Access (#n1:size_t) (#n2:size_t{v n1 * v n2 <= max_size_t}) (m:matrix_t n1 n2) (ij:(size_t & size_t){let i, j = ij in v i < v n1 /\ v j < v n2}) : Stack elem (requires fun h0 -> live h0 m) (ensures fun h0 x h1 -> let i, j = ij in modifies loc_none h0 h1 /\ x == M.mget (as_matrix h0 m) (v i) (v j)) let op_String_Access #n1 #n2 m (i,j) = mget m i j noextract unfold val op_String_Assignment (#n1:size_t) (#n2:size_t{v n1 * v n2 <= max_size_t}) (m:matrix_t n1 n2) (ij:(size_t & size_t){let i, j = ij in v i < v n1 /\ v j < v n2}) (x:elem) : Stack unit (requires fun h0 -> live h0 m) (ensures fun h0 _ h1 -> let i, j = ij in modifies1 m h0 h1 /\ live h1 m /\ as_matrix h1 m == M.mset (as_matrix h0 m) (v i) (v j) x) let op_String_Assignment #n1 #n2 m (i,j) x = mset m i j x unfold let get #n1 #n2 h (m:matrix_t n1 n2) i j = M.mget (as_matrix h m) i j private unfold val map_inner_inv: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> h2:HS.mem -> f:(elem -> elem) -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_nat -> Type0 let map_inner_inv #n1 #n2 h0 h1 h2 f a c i j = live h2 a /\ live h2 c /\ modifies1 c h1 h2 /\ j <= v n2 /\ (forall (i0:nat{i0 < v i}) (j:nat{j < v n2}). get h2 c i0 j == get h1 c i0 j) /\ (forall (j0:nat{j0 < j}). get h2 c (v i) j0 == f (get h0 a (v i) j0)) /\ (forall (j0:nat{j <= j0 /\ j0 < v n2}). get h2 c (v i) j0 == get h0 c (v i) j0) /\ (forall (i0:nat{v i < i0 /\ i0 < v n1}) (j:nat{j < v n2}). get h2 c i0 j == get h0 c i0 j) inline_for_extraction noextract private val map_inner: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> f:(elem -> elem) -> a:matrix_t n1 n2 -> c:matrix_t n1 n2{a == c} -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> Stack unit (requires fun h2 -> map_inner_inv h0 h1 h2 f a c i (v j)) (ensures fun _ _ h2 -> map_inner_inv h0 h1 h2 f a c i (v j + 1)) let map_inner #n1 #n2 h0 h1 f a c i j = c.[i,j] <- f a.[i,j] inline_for_extraction val map: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> f:(uint16 -> uint16) -> a:matrix_t n1 n2 -> c:matrix_t n1 n2 -> Stack unit (requires fun h0 -> live h0 a /\ live h0 c /\ a == c) (ensures fun h0 _ h1 -> modifies1 c h0 h1 /\ as_matrix h1 c == M.map #(v n1) #(v n2) f (as_matrix h0 a)) let map #n1 #n2 f a c = let h0 = ST.get () in Lib.Loops.for (size 0) n1 (fun h1 i -> live h1 a /\ live h1 c /\ modifies1 c h0 h1 /\ i <= v n1 /\ (forall (i0:nat{i0 < i}) (j:nat{j < v n2}). get h1 c i0 j == f (get h0 a i0 j)) /\ (forall (i0:nat{i <= i0 /\ i0 < v n1}) (j:nat{j < v n2}). get h1 c i0 j == get h0 c i0 j) ) (fun i -> let h1 = ST.get() in Lib.Loops.for (size 0) n2 (fun h2 j -> map_inner_inv h0 h1 h2 f a c i j) (fun j -> map_inner h0 h1 f a c i j) ); let h2 = ST.get () in M.extensionality (as_matrix h2 c) (M.map f (as_matrix h0 a)) inline_for_extraction noextract val mod_pow2_felem: logq:size_t{0 < v logq /\ v logq < 16} -> a:uint16 -> Pure uint16 (requires True) (ensures fun r -> r == M.mod_pow2_felem (v logq) a) let mod_pow2_felem logq a = a &. ((u16 1 <<. logq) -. u16 1) val mod_pow2: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> logq:size_t{0 < v logq /\ v logq <= 16} -> a:matrix_t n1 n2 -> Stack unit (requires fun h -> live h a) (ensures fun h0 _ h1 -> modifies1 a h0 h1 /\ as_matrix h1 a == M.mod_pow2 (v logq) (as_matrix h0 a)) [@"c_inline"] let mod_pow2 #n1 #n2 logq a = if logq <. 16ul then begin let h0 = ST.get () in map (mod_pow2_felem logq) a a; M.extensionality (M.map #(v n1) #(v n2) (mod_pow2_felem logq) (as_matrix h0 a)) (M.map #(v n1) #(v n2) (M.mod_pow2_felem (v logq)) (as_matrix h0 a)) end private unfold val map2_inner_inv: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> h2:HS.mem -> f:(elem -> elem -> elem) -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> c:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_nat -> Type0 let map2_inner_inv #n1 #n2 h0 h1 h2 f a b c i j = live h2 a /\ live h2 b /\ live h2 c /\ modifies1 c h1 h2 /\ j <= v n2 /\ (forall (i0:nat{i0 < v i}) (j:nat{j < v n2}). get h2 c i0 j == get h1 c i0 j) /\ (forall (j0:nat{j0 < j}). get h2 c (v i) j0 == f (get h0 a (v i) j0) (get h2 b (v i) j0)) /\ (forall (j0:nat{j <= j0 /\ j0 < v n2}). get h2 c (v i) j0 == get h0 c (v i) j0) /\ (forall (i0:nat{v i < i0 /\ i0 < v n1}) (j:nat{j < v n2}). get h2 c i0 j == get h0 c i0 j) inline_for_extraction noextract private val map2_inner: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> f:(elem -> elem -> elem) -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> c:matrix_t n1 n2{a == c /\ disjoint b c} -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> Stack unit (requires fun h2 -> map2_inner_inv h0 h1 h2 f a b c i (v j)) (ensures fun _ _ h2 -> map2_inner_inv h0 h1 h2 f a b c i (v j + 1)) let map2_inner #n1 #n2 h0 h1 f a b c i j = c.[i,j] <- f a.[i,j] b.[i,j] /// In-place [map2], a == map2 f a b /// /// A non in-place variant can be obtained by weakening the pre-condition to disjoint a c, /// or the two variants can be merged by requiring (a == c \/ disjoint a c) instead of a == c /// See commit 91916b8372fa3522061eff5a42d0ebd1d19a8a49 inline_for_extraction val map2: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> f:(uint16 -> uint16 -> uint16) -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> c:matrix_t n1 n2 -> Stack unit (requires fun h0 -> live h0 a /\ live h0 b /\ live h0 c /\ a == c /\ disjoint b c) (ensures fun h0 _ h1 -> modifies1 c h0 h1 /\ as_matrix h1 c == M.map2 #(v n1) #(v n2) f (as_matrix h0 a) (as_matrix h0 b)) let map2 #n1 #n2 f a b c = let h0 = ST.get () in Lib.Loops.for (size 0) n1 (fun h1 i -> live h1 a /\ live h1 b /\ live h1 c /\ modifies1 c h0 h1 /\ i <= v n1 /\ (forall (i0:nat{i0 < i}) (j:nat{j < v n2}). get h1 c i0 j == f (get h0 a i0 j) (get h0 b i0 j)) /\ (forall (i0:nat{i <= i0 /\ i0 < v n1}) (j:nat{j < v n2}). get h1 c i0 j == get h0 c i0 j) ) (fun i -> let h1 = ST.get() in Lib.Loops.for (size 0) n2 (fun h2 j -> map2_inner_inv h0 h1 h2 f a b c i j) (fun j -> map2_inner h0 h1 f a b c i j) ); let h2 = ST.get() in M.extensionality (as_matrix h2 c) (M.map2 f (as_matrix h0 a) (as_matrix h0 b)) val matrix_add: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> Stack unit (requires fun h -> live h a /\ live h b /\ disjoint a b) (ensures fun h0 r h1 -> modifies1 a h0 h1 /\ as_matrix h1 a == M.add (as_matrix h0 a) (as_matrix h0 b)) [@"c_inline"] let matrix_add #n1 #n2 a b = map2 add_mod a b a val matrix_sub: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> Stack unit (requires fun h -> live h a /\ live h b /\ disjoint a b) (ensures fun h0 r h1 -> modifies1 b h0 h1 /\ as_matrix h1 b == M.sub (as_matrix h0 a) (as_matrix h0 b)) [@"c_inline"] let matrix_sub #n1 #n2 a b = (* Use the in-place variant above by flipping the arguments of [sub_mod] *) (* Requires appplying extensionality *) let h0 = ST.get() in [@ inline_let ] let sub_mod_flipped x y = sub_mod y x in map2 sub_mod_flipped b a b; let h1 = ST.get() in M.extensionality (as_matrix h1 b) (M.sub (as_matrix h0 a) (as_matrix h0 b)) #push-options "--fuel 1" inline_for_extraction noextract private val mul_inner: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> #n3:size_t{v n2 * v n3 <= max_size_t /\ v n1 * v n3 <= max_size_t} -> a:matrix_t n1 n2 -> b:matrix_t n2 n3 -> i:size_t{v i < v n1} -> k:size_t{v k < v n3} -> Stack uint16 (requires fun h -> live h a /\ live h b) (ensures fun h0 r h1 -> modifies loc_none h0 h1 /\ r == M.mul_inner (as_matrix h0 a) (as_matrix h0 b) (v i) (v k)) let mul_inner #n1 #n2 #n3 a b i k = push_frame(); let h0 = ST.get() in [@ inline_let ] let f l = get h0 a (v i) l *. get h0 b l (v k) in let res = create #uint16 (size 1) (u16 0) in let h1 = ST.get() in Lib.Loops.for (size 0) n2 (fun h2 j -> live h1 res /\ live h2 res /\ modifies1 res h1 h2 /\ bget h2 res 0 == M.sum_ #(v n2) f j) (fun j -> let aij = a.[i,j] in let bjk = b.[j,k] in let res0 = res.(size 0) in res.(size 0) <- res0 +. aij *. bjk ); let res = res.(size 0) in M.sum_extensionality (v n2) f (fun l -> get h0 a (v i) l *. get h0 b l (v k)) (v n2); assert (res == M.mul_inner (as_matrix h0 a) (as_matrix h0 b) (v i) (v k)); pop_frame(); res #pop-options private unfold val mul_inner_inv: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> #n3:size_t{v n2 * v n3 <= max_size_t /\ v n1 * v n3 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> h2:HS.mem -> a:matrix_t n1 n2 -> b:matrix_t n2 n3 -> c:matrix_t n1 n3 -> f:(k:nat{k < v n3} -> GTot uint16) -> i:size_t{v i < v n1} -> k:size_nat -> Type0
false
false
Hacl.Impl.Matrix.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val mul_inner_inv: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> #n3:size_t{v n2 * v n3 <= max_size_t /\ v n1 * v n3 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> h2:HS.mem -> a:matrix_t n1 n2 -> b:matrix_t n2 n3 -> c:matrix_t n1 n3 -> f:(k:nat{k < v n3} -> GTot uint16) -> i:size_t{v i < v n1} -> k:size_nat -> Type0
[]
Hacl.Impl.Matrix.mul_inner_inv
{ "file_name": "code/frodo/Hacl.Impl.Matrix.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
h0: FStar.Monotonic.HyperStack.mem -> h1: FStar.Monotonic.HyperStack.mem -> h2: FStar.Monotonic.HyperStack.mem -> a: Hacl.Impl.Matrix.matrix_t n1 n2 -> b: Hacl.Impl.Matrix.matrix_t n2 n3 -> c: Hacl.Impl.Matrix.matrix_t n1 n3 -> f: (k: Prims.nat{k < Lib.IntTypes.v n3} -> Prims.GTot Lib.IntTypes.uint16) -> i: Lib.IntTypes.size_t{Lib.IntTypes.v i < Lib.IntTypes.v n1} -> k: Lib.IntTypes.size_nat -> Type0
{ "end_col": 34, "end_line": 403, "start_col": 2, "start_line": 395 }
FStar.HyperStack.ST.Stack
val mget_s: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> Stack elem (requires fun h0 -> live h0 a) (ensures fun h0 x h1 -> modifies0 h0 h1 /\ x == M.mget_s (as_matrix h0 a) (v i) (v j))
[ { "abbrev": true, "full_module": "Spec.Frodo.Lemmas", "short_module": "Lemmas" }, { "abbrev": true, "full_module": "Spec.Matrix", "short_module": "M" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let mget_s #n1 #n2 a i j = M.index_lt (v n2) (v n1) (v j) (v i); a.(j *! n1 +! i)
val mget_s: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> Stack elem (requires fun h0 -> live h0 a) (ensures fun h0 x h1 -> modifies0 h0 h1 /\ x == M.mget_s (as_matrix h0 a) (v i) (v j)) let mget_s #n1 #n2 a i j =
true
null
false
M.index_lt (v n2) (v n1) (v j) (v i); a.(j *! n1 +! i)
{ "checked_file": "Hacl.Impl.Matrix.fst.checked", "dependencies": [ "Spec.Matrix.fst.checked", "Spec.Frodo.Lemmas.fst.checked", "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.Loops.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Matrix.fst" }
[]
[ "Lib.IntTypes.size_t", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.Mul.op_Star", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Lib.IntTypes.max_size_t", "Hacl.Impl.Matrix.matrix_t", "Prims.op_LessThan", "Lib.Buffer.op_Array_Access", "Lib.Buffer.MUT", "Hacl.Impl.Matrix.elem", "Lib.IntTypes.op_Star_Bang", "Lib.IntTypes.op_Plus_Bang", "Prims.unit", "Spec.Matrix.index_lt" ]
[]
module Hacl.Impl.Matrix open FStar.HyperStack.ST open FStar.Mul open LowStar.BufferOps open LowStar.Buffer open Lib.IntTypes open Lib.Buffer open Lib.ByteBuffer module HS = FStar.HyperStack module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module Loops = Lib.LoopCombinators module M = Spec.Matrix module Lemmas = Spec.Frodo.Lemmas #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" unfold let elem = uint16 unfold let lbytes len = lbuffer uint8 len unfold let matrix_t (n1:size_t) (n2:size_t{v n1 * v n2 <= max_size_t}) = lbuffer elem (n1 *! n2) unfold let as_matrix #n1 #n2 h (m:matrix_t n1 n2) : GTot (M.matrix (v n1) (v n2)) = as_seq h m inline_for_extraction noextract val matrix_create: n1:size_t -> n2:size_t{0 < v n1 * v n2 /\ v n1 * v n2 <= max_size_t} -> StackInline (matrix_t n1 n2) (requires fun h0 -> True) (ensures fun h0 a h1 -> stack_allocated a h0 h1 (as_matrix h1 a) /\ as_matrix h1 a == M.create (v n1) (v n2)) let matrix_create n1 n2 = [@inline_let] let len = size (normalize_term (v n1 * v n2)) in create len (u16 0) inline_for_extraction noextract val mget: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> Stack elem (requires fun h0 -> live h0 a) (ensures fun h0 x h1 -> modifies loc_none h0 h1 /\ x == M.mget (as_matrix h0 a) (v i) (v j)) let mget #n1 #n2 a i j = M.index_lt (v n1) (v n2) (v i) (v j); a.(i *! n2 +! j) inline_for_extraction noextract val mset: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> x:elem -> Stack unit (requires fun h0 -> live h0 a) (ensures fun h0 _ h1 -> modifies1 a h0 h1 /\ as_matrix h1 a == M.mset (as_matrix h0 a) (v i) (v j) x) let mset #n1 #n2 a i j x = M.index_lt (v n1) (v n2) (v i) (v j); a.(i *! n2 +! j) <- x noextract unfold val op_String_Access (#n1:size_t) (#n2:size_t{v n1 * v n2 <= max_size_t}) (m:matrix_t n1 n2) (ij:(size_t & size_t){let i, j = ij in v i < v n1 /\ v j < v n2}) : Stack elem (requires fun h0 -> live h0 m) (ensures fun h0 x h1 -> let i, j = ij in modifies loc_none h0 h1 /\ x == M.mget (as_matrix h0 m) (v i) (v j)) let op_String_Access #n1 #n2 m (i,j) = mget m i j noextract unfold val op_String_Assignment (#n1:size_t) (#n2:size_t{v n1 * v n2 <= max_size_t}) (m:matrix_t n1 n2) (ij:(size_t & size_t){let i, j = ij in v i < v n1 /\ v j < v n2}) (x:elem) : Stack unit (requires fun h0 -> live h0 m) (ensures fun h0 _ h1 -> let i, j = ij in modifies1 m h0 h1 /\ live h1 m /\ as_matrix h1 m == M.mset (as_matrix h0 m) (v i) (v j) x) let op_String_Assignment #n1 #n2 m (i,j) x = mset m i j x unfold let get #n1 #n2 h (m:matrix_t n1 n2) i j = M.mget (as_matrix h m) i j private unfold val map_inner_inv: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> h2:HS.mem -> f:(elem -> elem) -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_nat -> Type0 let map_inner_inv #n1 #n2 h0 h1 h2 f a c i j = live h2 a /\ live h2 c /\ modifies1 c h1 h2 /\ j <= v n2 /\ (forall (i0:nat{i0 < v i}) (j:nat{j < v n2}). get h2 c i0 j == get h1 c i0 j) /\ (forall (j0:nat{j0 < j}). get h2 c (v i) j0 == f (get h0 a (v i) j0)) /\ (forall (j0:nat{j <= j0 /\ j0 < v n2}). get h2 c (v i) j0 == get h0 c (v i) j0) /\ (forall (i0:nat{v i < i0 /\ i0 < v n1}) (j:nat{j < v n2}). get h2 c i0 j == get h0 c i0 j) inline_for_extraction noextract private val map_inner: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> f:(elem -> elem) -> a:matrix_t n1 n2 -> c:matrix_t n1 n2{a == c} -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> Stack unit (requires fun h2 -> map_inner_inv h0 h1 h2 f a c i (v j)) (ensures fun _ _ h2 -> map_inner_inv h0 h1 h2 f a c i (v j + 1)) let map_inner #n1 #n2 h0 h1 f a c i j = c.[i,j] <- f a.[i,j] inline_for_extraction val map: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> f:(uint16 -> uint16) -> a:matrix_t n1 n2 -> c:matrix_t n1 n2 -> Stack unit (requires fun h0 -> live h0 a /\ live h0 c /\ a == c) (ensures fun h0 _ h1 -> modifies1 c h0 h1 /\ as_matrix h1 c == M.map #(v n1) #(v n2) f (as_matrix h0 a)) let map #n1 #n2 f a c = let h0 = ST.get () in Lib.Loops.for (size 0) n1 (fun h1 i -> live h1 a /\ live h1 c /\ modifies1 c h0 h1 /\ i <= v n1 /\ (forall (i0:nat{i0 < i}) (j:nat{j < v n2}). get h1 c i0 j == f (get h0 a i0 j)) /\ (forall (i0:nat{i <= i0 /\ i0 < v n1}) (j:nat{j < v n2}). get h1 c i0 j == get h0 c i0 j) ) (fun i -> let h1 = ST.get() in Lib.Loops.for (size 0) n2 (fun h2 j -> map_inner_inv h0 h1 h2 f a c i j) (fun j -> map_inner h0 h1 f a c i j) ); let h2 = ST.get () in M.extensionality (as_matrix h2 c) (M.map f (as_matrix h0 a)) inline_for_extraction noextract val mod_pow2_felem: logq:size_t{0 < v logq /\ v logq < 16} -> a:uint16 -> Pure uint16 (requires True) (ensures fun r -> r == M.mod_pow2_felem (v logq) a) let mod_pow2_felem logq a = a &. ((u16 1 <<. logq) -. u16 1) val mod_pow2: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> logq:size_t{0 < v logq /\ v logq <= 16} -> a:matrix_t n1 n2 -> Stack unit (requires fun h -> live h a) (ensures fun h0 _ h1 -> modifies1 a h0 h1 /\ as_matrix h1 a == M.mod_pow2 (v logq) (as_matrix h0 a)) [@"c_inline"] let mod_pow2 #n1 #n2 logq a = if logq <. 16ul then begin let h0 = ST.get () in map (mod_pow2_felem logq) a a; M.extensionality (M.map #(v n1) #(v n2) (mod_pow2_felem logq) (as_matrix h0 a)) (M.map #(v n1) #(v n2) (M.mod_pow2_felem (v logq)) (as_matrix h0 a)) end private unfold val map2_inner_inv: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> h2:HS.mem -> f:(elem -> elem -> elem) -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> c:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_nat -> Type0 let map2_inner_inv #n1 #n2 h0 h1 h2 f a b c i j = live h2 a /\ live h2 b /\ live h2 c /\ modifies1 c h1 h2 /\ j <= v n2 /\ (forall (i0:nat{i0 < v i}) (j:nat{j < v n2}). get h2 c i0 j == get h1 c i0 j) /\ (forall (j0:nat{j0 < j}). get h2 c (v i) j0 == f (get h0 a (v i) j0) (get h2 b (v i) j0)) /\ (forall (j0:nat{j <= j0 /\ j0 < v n2}). get h2 c (v i) j0 == get h0 c (v i) j0) /\ (forall (i0:nat{v i < i0 /\ i0 < v n1}) (j:nat{j < v n2}). get h2 c i0 j == get h0 c i0 j) inline_for_extraction noextract private val map2_inner: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> f:(elem -> elem -> elem) -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> c:matrix_t n1 n2{a == c /\ disjoint b c} -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> Stack unit (requires fun h2 -> map2_inner_inv h0 h1 h2 f a b c i (v j)) (ensures fun _ _ h2 -> map2_inner_inv h0 h1 h2 f a b c i (v j + 1)) let map2_inner #n1 #n2 h0 h1 f a b c i j = c.[i,j] <- f a.[i,j] b.[i,j] /// In-place [map2], a == map2 f a b /// /// A non in-place variant can be obtained by weakening the pre-condition to disjoint a c, /// or the two variants can be merged by requiring (a == c \/ disjoint a c) instead of a == c /// See commit 91916b8372fa3522061eff5a42d0ebd1d19a8a49 inline_for_extraction val map2: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> f:(uint16 -> uint16 -> uint16) -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> c:matrix_t n1 n2 -> Stack unit (requires fun h0 -> live h0 a /\ live h0 b /\ live h0 c /\ a == c /\ disjoint b c) (ensures fun h0 _ h1 -> modifies1 c h0 h1 /\ as_matrix h1 c == M.map2 #(v n1) #(v n2) f (as_matrix h0 a) (as_matrix h0 b)) let map2 #n1 #n2 f a b c = let h0 = ST.get () in Lib.Loops.for (size 0) n1 (fun h1 i -> live h1 a /\ live h1 b /\ live h1 c /\ modifies1 c h0 h1 /\ i <= v n1 /\ (forall (i0:nat{i0 < i}) (j:nat{j < v n2}). get h1 c i0 j == f (get h0 a i0 j) (get h0 b i0 j)) /\ (forall (i0:nat{i <= i0 /\ i0 < v n1}) (j:nat{j < v n2}). get h1 c i0 j == get h0 c i0 j) ) (fun i -> let h1 = ST.get() in Lib.Loops.for (size 0) n2 (fun h2 j -> map2_inner_inv h0 h1 h2 f a b c i j) (fun j -> map2_inner h0 h1 f a b c i j) ); let h2 = ST.get() in M.extensionality (as_matrix h2 c) (M.map2 f (as_matrix h0 a) (as_matrix h0 b)) val matrix_add: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> Stack unit (requires fun h -> live h a /\ live h b /\ disjoint a b) (ensures fun h0 r h1 -> modifies1 a h0 h1 /\ as_matrix h1 a == M.add (as_matrix h0 a) (as_matrix h0 b)) [@"c_inline"] let matrix_add #n1 #n2 a b = map2 add_mod a b a val matrix_sub: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> Stack unit (requires fun h -> live h a /\ live h b /\ disjoint a b) (ensures fun h0 r h1 -> modifies1 b h0 h1 /\ as_matrix h1 b == M.sub (as_matrix h0 a) (as_matrix h0 b)) [@"c_inline"] let matrix_sub #n1 #n2 a b = (* Use the in-place variant above by flipping the arguments of [sub_mod] *) (* Requires appplying extensionality *) let h0 = ST.get() in [@ inline_let ] let sub_mod_flipped x y = sub_mod y x in map2 sub_mod_flipped b a b; let h1 = ST.get() in M.extensionality (as_matrix h1 b) (M.sub (as_matrix h0 a) (as_matrix h0 b)) #push-options "--fuel 1" inline_for_extraction noextract private val mul_inner: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> #n3:size_t{v n2 * v n3 <= max_size_t /\ v n1 * v n3 <= max_size_t} -> a:matrix_t n1 n2 -> b:matrix_t n2 n3 -> i:size_t{v i < v n1} -> k:size_t{v k < v n3} -> Stack uint16 (requires fun h -> live h a /\ live h b) (ensures fun h0 r h1 -> modifies loc_none h0 h1 /\ r == M.mul_inner (as_matrix h0 a) (as_matrix h0 b) (v i) (v k)) let mul_inner #n1 #n2 #n3 a b i k = push_frame(); let h0 = ST.get() in [@ inline_let ] let f l = get h0 a (v i) l *. get h0 b l (v k) in let res = create #uint16 (size 1) (u16 0) in let h1 = ST.get() in Lib.Loops.for (size 0) n2 (fun h2 j -> live h1 res /\ live h2 res /\ modifies1 res h1 h2 /\ bget h2 res 0 == M.sum_ #(v n2) f j) (fun j -> let aij = a.[i,j] in let bjk = b.[j,k] in let res0 = res.(size 0) in res.(size 0) <- res0 +. aij *. bjk ); let res = res.(size 0) in M.sum_extensionality (v n2) f (fun l -> get h0 a (v i) l *. get h0 b l (v k)) (v n2); assert (res == M.mul_inner (as_matrix h0 a) (as_matrix h0 b) (v i) (v k)); pop_frame(); res #pop-options private unfold val mul_inner_inv: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> #n3:size_t{v n2 * v n3 <= max_size_t /\ v n1 * v n3 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> h2:HS.mem -> a:matrix_t n1 n2 -> b:matrix_t n2 n3 -> c:matrix_t n1 n3 -> f:(k:nat{k < v n3} -> GTot uint16) -> i:size_t{v i < v n1} -> k:size_nat -> Type0 let mul_inner_inv #n1 #n2 #n3 h0 h1 h2 a b c f i k = live h2 a /\ live h2 b /\ live h2 c /\ modifies1 c h1 h2 /\ k <= v n3 /\ (forall (i1:nat{i1 < v i}) (k:nat{k < v n3}). get h2 c i1 k == get h1 c i1 k) /\ (forall (k1:nat{k1 < k}). get h2 c (v i) k1 == f k1) /\ (forall (k1:nat{k <= k1 /\ k1 < v n3}). get h2 c (v i) k1 == get h0 c (v i) k1) /\ (forall (i1:nat{v i < i1 /\ i1 < v n1}) (k:nat{k < v n3}). get h2 c i1 k == get h0 c i1 k) /\ as_matrix h0 a == as_matrix h2 a /\ as_matrix h0 b == as_matrix h2 b inline_for_extraction noextract private val mul_inner1: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> #n3:size_t{v n2 * v n3 <= max_size_t /\ v n1 * v n3 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> a:matrix_t n1 n2 -> b:matrix_t n2 n3 -> c:matrix_t n1 n3{disjoint a c /\ disjoint b c} -> i:size_t{v i < v n1} -> k:size_t{v k < v n3} -> f:(k:nat{k < v n3} -> GTot (res:uint16{res == M.sum #(v n2) (fun l -> get h0 a (v i) l *. get h0 b l k)})) -> Stack unit (requires fun h2 -> mul_inner_inv h0 h1 h2 a b c f i (v k)) (ensures fun _ _ h2 -> mul_inner_inv h0 h1 h2 a b c f i (v k + 1)) let mul_inner1 #n1 #n2 #n3 h0 h1 a b c i k f = assert (M.mul_inner (as_matrix h0 a) (as_matrix h0 b) (v i) (v k) == M.sum #(v n2) (fun l -> get h0 a (v i) l *. get h0 b l (v k))); c.[i,k] <- mul_inner a b i k; let h2 = ST.get () in assert (get h2 c (v i) (v k) == f (v k)) private val onemore: p:(nat -> Type0) -> q:(i:nat{p i} -> Type0) -> b:nat{p b} -> Lemma (requires (forall (i:nat{p i /\ i < b}). q i) /\ q b) (ensures forall (i:nat{p i /\ i <= b}). q i) let onemore p q b = () val onemore1: #n1:size_nat -> #n3:size_nat{n1 * n3 <= max_size_t} -> c:M.matrix n1 n3 -> f:(i:nat{i < n1} -> k:nat{k < n3} -> GTot uint16) -> i:size_nat{i < n1} -> Lemma (requires ((forall (i1:nat{i1 < i}) (k:nat{k < n3}). M.mget c i1 k == f i1 k) /\ (forall (k:nat{k < n3}). M.mget c i k == f i k))) (ensures (forall (i1:nat{i1 <= i}) (k:nat{k < n3}). M.mget c i1 k == f i1 k)) let onemore1 #n1 #n3 c f i = () val matrix_mul: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> #n3:size_t{v n2 * v n3 <= max_size_t /\ v n1 * v n3 <= max_size_t} -> a:matrix_t n1 n2 -> b:matrix_t n2 n3 -> c:matrix_t n1 n3 -> Stack unit (requires fun h -> live h a /\ live h b /\ live h c /\ disjoint a c /\ disjoint b c) (ensures fun h0 _ h1 -> modifies1 c h0 h1 /\ as_matrix h1 c == M.mul (as_matrix h0 a) (as_matrix h0 b)) [@"c_inline"] let matrix_mul #n1 #n2 #n3 a b c = let h0 = ST.get () in let f (i:nat{i < v n1}) (k:nat{k < v n3}) : GTot (res:uint16{res == M.sum #(v n2) (fun l -> get h0 a i l *. get h0 b l k)}) = M.sum #(v n2) (fun l -> get h0 a i l *. get h0 b l k) in Lib.Loops.for (size 0) n1 (fun h1 i -> live h1 a /\ live h1 b /\ live h1 c /\ modifies1 c h0 h1 /\ i <= v n1 /\ (forall (i1:nat{i1 < i}) (k:nat{k < v n3}). get h1 c i1 k == f i1 k) /\ (forall (i1:nat{i <= i1 /\ i1 < v n1}) (k:nat{k < v n3}). get h1 c i1 k == get h0 c i1 k)) (fun i -> let h1 = ST.get() in Lib.Loops.for (size 0) n3 (fun h2 k -> mul_inner_inv h0 h1 h2 a b c (f (v i)) i k) (fun k -> mul_inner1 h0 h1 a b c i k (f (v i))); let h1 = ST.get() in let q i1 = forall (k:nat{k < v n3}). get h1 c i1 k == f i1 k in onemore (fun i1 -> i1 < v n1) q (v i); assert (forall (i1:nat{i1 < v n1 /\ i1 <= v i}) (k:nat{k < v n3}). get h1 c i1 k == f i1 k) ); let h2 = ST.get() in M.extensionality (as_matrix h2 c) (M.mul (as_matrix h0 a) (as_matrix h0 b)) (* Special case of matrix multiplication *) (* when we have a different way of accessing to entries of the matrix S *) inline_for_extraction noextract val mget_s: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> Stack elem (requires fun h0 -> live h0 a) (ensures fun h0 x h1 -> modifies0 h0 h1 /\ x == M.mget_s (as_matrix h0 a) (v i) (v j))
false
false
Hacl.Impl.Matrix.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val mget_s: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> Stack elem (requires fun h0 -> live h0 a) (ensures fun h0 x h1 -> modifies0 h0 h1 /\ x == M.mget_s (as_matrix h0 a) (v i) (v j))
[]
Hacl.Impl.Matrix.mget_s
{ "file_name": "code/frodo/Hacl.Impl.Matrix.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
a: Hacl.Impl.Matrix.matrix_t n1 n2 -> i: Lib.IntTypes.size_t{Lib.IntTypes.v i < Lib.IntTypes.v n1} -> j: Lib.IntTypes.size_t{Lib.IntTypes.v j < Lib.IntTypes.v n2} -> FStar.HyperStack.ST.Stack Hacl.Impl.Matrix.elem
{ "end_col": 18, "end_line": 508, "start_col": 2, "start_line": 507 }
FStar.HyperStack.ST.Stack
val matrix_sub: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> Stack unit (requires fun h -> live h a /\ live h b /\ disjoint a b) (ensures fun h0 r h1 -> modifies1 b h0 h1 /\ as_matrix h1 b == M.sub (as_matrix h0 a) (as_matrix h0 b))
[ { "abbrev": true, "full_module": "Spec.Frodo.Lemmas", "short_module": "Lemmas" }, { "abbrev": true, "full_module": "Spec.Matrix", "short_module": "M" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let matrix_sub #n1 #n2 a b = (* Use the in-place variant above by flipping the arguments of [sub_mod] *) (* Requires appplying extensionality *) let h0 = ST.get() in [@ inline_let ] let sub_mod_flipped x y = sub_mod y x in map2 sub_mod_flipped b a b; let h1 = ST.get() in M.extensionality (as_matrix h1 b) (M.sub (as_matrix h0 a) (as_matrix h0 b))
val matrix_sub: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> Stack unit (requires fun h -> live h a /\ live h b /\ disjoint a b) (ensures fun h0 r h1 -> modifies1 b h0 h1 /\ as_matrix h1 b == M.sub (as_matrix h0 a) (as_matrix h0 b)) let matrix_sub #n1 #n2 a b =
true
null
false
let h0 = ST.get () in [@@ inline_let ]let sub_mod_flipped x y = sub_mod y x in map2 sub_mod_flipped b a b; let h1 = ST.get () in M.extensionality (as_matrix h1 b) (M.sub (as_matrix h0 a) (as_matrix h0 b))
{ "checked_file": "Hacl.Impl.Matrix.fst.checked", "dependencies": [ "Spec.Matrix.fst.checked", "Spec.Frodo.Lemmas.fst.checked", "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.Loops.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Matrix.fst" }
[]
[ "Lib.IntTypes.size_t", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.Mul.op_Star", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Lib.IntTypes.max_size_t", "Hacl.Impl.Matrix.matrix_t", "Spec.Matrix.extensionality", "Hacl.Impl.Matrix.as_matrix", "Spec.Matrix.sub", "Prims.unit", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "Hacl.Impl.Matrix.map2", "Lib.IntTypes.int_t", "Lib.IntTypes.U16", "Lib.IntTypes.SEC", "Lib.IntTypes.sub_mod" ]
[]
module Hacl.Impl.Matrix open FStar.HyperStack.ST open FStar.Mul open LowStar.BufferOps open LowStar.Buffer open Lib.IntTypes open Lib.Buffer open Lib.ByteBuffer module HS = FStar.HyperStack module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module Loops = Lib.LoopCombinators module M = Spec.Matrix module Lemmas = Spec.Frodo.Lemmas #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" unfold let elem = uint16 unfold let lbytes len = lbuffer uint8 len unfold let matrix_t (n1:size_t) (n2:size_t{v n1 * v n2 <= max_size_t}) = lbuffer elem (n1 *! n2) unfold let as_matrix #n1 #n2 h (m:matrix_t n1 n2) : GTot (M.matrix (v n1) (v n2)) = as_seq h m inline_for_extraction noextract val matrix_create: n1:size_t -> n2:size_t{0 < v n1 * v n2 /\ v n1 * v n2 <= max_size_t} -> StackInline (matrix_t n1 n2) (requires fun h0 -> True) (ensures fun h0 a h1 -> stack_allocated a h0 h1 (as_matrix h1 a) /\ as_matrix h1 a == M.create (v n1) (v n2)) let matrix_create n1 n2 = [@inline_let] let len = size (normalize_term (v n1 * v n2)) in create len (u16 0) inline_for_extraction noextract val mget: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> Stack elem (requires fun h0 -> live h0 a) (ensures fun h0 x h1 -> modifies loc_none h0 h1 /\ x == M.mget (as_matrix h0 a) (v i) (v j)) let mget #n1 #n2 a i j = M.index_lt (v n1) (v n2) (v i) (v j); a.(i *! n2 +! j) inline_for_extraction noextract val mset: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> x:elem -> Stack unit (requires fun h0 -> live h0 a) (ensures fun h0 _ h1 -> modifies1 a h0 h1 /\ as_matrix h1 a == M.mset (as_matrix h0 a) (v i) (v j) x) let mset #n1 #n2 a i j x = M.index_lt (v n1) (v n2) (v i) (v j); a.(i *! n2 +! j) <- x noextract unfold val op_String_Access (#n1:size_t) (#n2:size_t{v n1 * v n2 <= max_size_t}) (m:matrix_t n1 n2) (ij:(size_t & size_t){let i, j = ij in v i < v n1 /\ v j < v n2}) : Stack elem (requires fun h0 -> live h0 m) (ensures fun h0 x h1 -> let i, j = ij in modifies loc_none h0 h1 /\ x == M.mget (as_matrix h0 m) (v i) (v j)) let op_String_Access #n1 #n2 m (i,j) = mget m i j noextract unfold val op_String_Assignment (#n1:size_t) (#n2:size_t{v n1 * v n2 <= max_size_t}) (m:matrix_t n1 n2) (ij:(size_t & size_t){let i, j = ij in v i < v n1 /\ v j < v n2}) (x:elem) : Stack unit (requires fun h0 -> live h0 m) (ensures fun h0 _ h1 -> let i, j = ij in modifies1 m h0 h1 /\ live h1 m /\ as_matrix h1 m == M.mset (as_matrix h0 m) (v i) (v j) x) let op_String_Assignment #n1 #n2 m (i,j) x = mset m i j x unfold let get #n1 #n2 h (m:matrix_t n1 n2) i j = M.mget (as_matrix h m) i j private unfold val map_inner_inv: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> h2:HS.mem -> f:(elem -> elem) -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_nat -> Type0 let map_inner_inv #n1 #n2 h0 h1 h2 f a c i j = live h2 a /\ live h2 c /\ modifies1 c h1 h2 /\ j <= v n2 /\ (forall (i0:nat{i0 < v i}) (j:nat{j < v n2}). get h2 c i0 j == get h1 c i0 j) /\ (forall (j0:nat{j0 < j}). get h2 c (v i) j0 == f (get h0 a (v i) j0)) /\ (forall (j0:nat{j <= j0 /\ j0 < v n2}). get h2 c (v i) j0 == get h0 c (v i) j0) /\ (forall (i0:nat{v i < i0 /\ i0 < v n1}) (j:nat{j < v n2}). get h2 c i0 j == get h0 c i0 j) inline_for_extraction noextract private val map_inner: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> f:(elem -> elem) -> a:matrix_t n1 n2 -> c:matrix_t n1 n2{a == c} -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> Stack unit (requires fun h2 -> map_inner_inv h0 h1 h2 f a c i (v j)) (ensures fun _ _ h2 -> map_inner_inv h0 h1 h2 f a c i (v j + 1)) let map_inner #n1 #n2 h0 h1 f a c i j = c.[i,j] <- f a.[i,j] inline_for_extraction val map: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> f:(uint16 -> uint16) -> a:matrix_t n1 n2 -> c:matrix_t n1 n2 -> Stack unit (requires fun h0 -> live h0 a /\ live h0 c /\ a == c) (ensures fun h0 _ h1 -> modifies1 c h0 h1 /\ as_matrix h1 c == M.map #(v n1) #(v n2) f (as_matrix h0 a)) let map #n1 #n2 f a c = let h0 = ST.get () in Lib.Loops.for (size 0) n1 (fun h1 i -> live h1 a /\ live h1 c /\ modifies1 c h0 h1 /\ i <= v n1 /\ (forall (i0:nat{i0 < i}) (j:nat{j < v n2}). get h1 c i0 j == f (get h0 a i0 j)) /\ (forall (i0:nat{i <= i0 /\ i0 < v n1}) (j:nat{j < v n2}). get h1 c i0 j == get h0 c i0 j) ) (fun i -> let h1 = ST.get() in Lib.Loops.for (size 0) n2 (fun h2 j -> map_inner_inv h0 h1 h2 f a c i j) (fun j -> map_inner h0 h1 f a c i j) ); let h2 = ST.get () in M.extensionality (as_matrix h2 c) (M.map f (as_matrix h0 a)) inline_for_extraction noextract val mod_pow2_felem: logq:size_t{0 < v logq /\ v logq < 16} -> a:uint16 -> Pure uint16 (requires True) (ensures fun r -> r == M.mod_pow2_felem (v logq) a) let mod_pow2_felem logq a = a &. ((u16 1 <<. logq) -. u16 1) val mod_pow2: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> logq:size_t{0 < v logq /\ v logq <= 16} -> a:matrix_t n1 n2 -> Stack unit (requires fun h -> live h a) (ensures fun h0 _ h1 -> modifies1 a h0 h1 /\ as_matrix h1 a == M.mod_pow2 (v logq) (as_matrix h0 a)) [@"c_inline"] let mod_pow2 #n1 #n2 logq a = if logq <. 16ul then begin let h0 = ST.get () in map (mod_pow2_felem logq) a a; M.extensionality (M.map #(v n1) #(v n2) (mod_pow2_felem logq) (as_matrix h0 a)) (M.map #(v n1) #(v n2) (M.mod_pow2_felem (v logq)) (as_matrix h0 a)) end private unfold val map2_inner_inv: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> h2:HS.mem -> f:(elem -> elem -> elem) -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> c:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_nat -> Type0 let map2_inner_inv #n1 #n2 h0 h1 h2 f a b c i j = live h2 a /\ live h2 b /\ live h2 c /\ modifies1 c h1 h2 /\ j <= v n2 /\ (forall (i0:nat{i0 < v i}) (j:nat{j < v n2}). get h2 c i0 j == get h1 c i0 j) /\ (forall (j0:nat{j0 < j}). get h2 c (v i) j0 == f (get h0 a (v i) j0) (get h2 b (v i) j0)) /\ (forall (j0:nat{j <= j0 /\ j0 < v n2}). get h2 c (v i) j0 == get h0 c (v i) j0) /\ (forall (i0:nat{v i < i0 /\ i0 < v n1}) (j:nat{j < v n2}). get h2 c i0 j == get h0 c i0 j) inline_for_extraction noextract private val map2_inner: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> f:(elem -> elem -> elem) -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> c:matrix_t n1 n2{a == c /\ disjoint b c} -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> Stack unit (requires fun h2 -> map2_inner_inv h0 h1 h2 f a b c i (v j)) (ensures fun _ _ h2 -> map2_inner_inv h0 h1 h2 f a b c i (v j + 1)) let map2_inner #n1 #n2 h0 h1 f a b c i j = c.[i,j] <- f a.[i,j] b.[i,j] /// In-place [map2], a == map2 f a b /// /// A non in-place variant can be obtained by weakening the pre-condition to disjoint a c, /// or the two variants can be merged by requiring (a == c \/ disjoint a c) instead of a == c /// See commit 91916b8372fa3522061eff5a42d0ebd1d19a8a49 inline_for_extraction val map2: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> f:(uint16 -> uint16 -> uint16) -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> c:matrix_t n1 n2 -> Stack unit (requires fun h0 -> live h0 a /\ live h0 b /\ live h0 c /\ a == c /\ disjoint b c) (ensures fun h0 _ h1 -> modifies1 c h0 h1 /\ as_matrix h1 c == M.map2 #(v n1) #(v n2) f (as_matrix h0 a) (as_matrix h0 b)) let map2 #n1 #n2 f a b c = let h0 = ST.get () in Lib.Loops.for (size 0) n1 (fun h1 i -> live h1 a /\ live h1 b /\ live h1 c /\ modifies1 c h0 h1 /\ i <= v n1 /\ (forall (i0:nat{i0 < i}) (j:nat{j < v n2}). get h1 c i0 j == f (get h0 a i0 j) (get h0 b i0 j)) /\ (forall (i0:nat{i <= i0 /\ i0 < v n1}) (j:nat{j < v n2}). get h1 c i0 j == get h0 c i0 j) ) (fun i -> let h1 = ST.get() in Lib.Loops.for (size 0) n2 (fun h2 j -> map2_inner_inv h0 h1 h2 f a b c i j) (fun j -> map2_inner h0 h1 f a b c i j) ); let h2 = ST.get() in M.extensionality (as_matrix h2 c) (M.map2 f (as_matrix h0 a) (as_matrix h0 b)) val matrix_add: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> Stack unit (requires fun h -> live h a /\ live h b /\ disjoint a b) (ensures fun h0 r h1 -> modifies1 a h0 h1 /\ as_matrix h1 a == M.add (as_matrix h0 a) (as_matrix h0 b)) [@"c_inline"] let matrix_add #n1 #n2 a b = map2 add_mod a b a val matrix_sub: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> Stack unit (requires fun h -> live h a /\ live h b /\ disjoint a b) (ensures fun h0 r h1 -> modifies1 b h0 h1 /\ as_matrix h1 b == M.sub (as_matrix h0 a) (as_matrix h0 b))
false
false
Hacl.Impl.Matrix.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val matrix_sub: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> Stack unit (requires fun h -> live h a /\ live h b /\ disjoint a b) (ensures fun h0 r h1 -> modifies1 b h0 h1 /\ as_matrix h1 b == M.sub (as_matrix h0 a) (as_matrix h0 b))
[]
Hacl.Impl.Matrix.matrix_sub
{ "file_name": "code/frodo/Hacl.Impl.Matrix.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
a: Hacl.Impl.Matrix.matrix_t n1 n2 -> b: Hacl.Impl.Matrix.matrix_t n1 n2 -> FStar.HyperStack.ST.Stack Prims.unit
{ "end_col": 77, "end_line": 334, "start_col": 28, "start_line": 326 }
FStar.HyperStack.ST.Stack
val mod_pow2: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> logq:size_t{0 < v logq /\ v logq <= 16} -> a:matrix_t n1 n2 -> Stack unit (requires fun h -> live h a) (ensures fun h0 _ h1 -> modifies1 a h0 h1 /\ as_matrix h1 a == M.mod_pow2 (v logq) (as_matrix h0 a))
[ { "abbrev": true, "full_module": "Spec.Frodo.Lemmas", "short_module": "Lemmas" }, { "abbrev": true, "full_module": "Spec.Matrix", "short_module": "M" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let mod_pow2 #n1 #n2 logq a = if logq <. 16ul then begin let h0 = ST.get () in map (mod_pow2_felem logq) a a; M.extensionality (M.map #(v n1) #(v n2) (mod_pow2_felem logq) (as_matrix h0 a)) (M.map #(v n1) #(v n2) (M.mod_pow2_felem (v logq)) (as_matrix h0 a)) end
val mod_pow2: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> logq:size_t{0 < v logq /\ v logq <= 16} -> a:matrix_t n1 n2 -> Stack unit (requires fun h -> live h a) (ensures fun h0 _ h1 -> modifies1 a h0 h1 /\ as_matrix h1 a == M.mod_pow2 (v logq) (as_matrix h0 a)) let mod_pow2 #n1 #n2 logq a =
true
null
false
if logq <. 16ul then let h0 = ST.get () in map (mod_pow2_felem logq) a a; M.extensionality (M.map #(v n1) #(v n2) (mod_pow2_felem logq) (as_matrix h0 a)) (M.map #(v n1) #(v n2) (M.mod_pow2_felem (v logq)) (as_matrix h0 a))
{ "checked_file": "Hacl.Impl.Matrix.fst.checked", "dependencies": [ "Spec.Matrix.fst.checked", "Spec.Frodo.Lemmas.fst.checked", "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.Loops.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Matrix.fst" }
[]
[ "Lib.IntTypes.size_t", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.Mul.op_Star", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Lib.IntTypes.max_size_t", "Prims.l_and", "Prims.op_LessThan", "Hacl.Impl.Matrix.matrix_t", "Lib.IntTypes.op_Less_Dot", "FStar.UInt32.__uint_to_t", "Spec.Matrix.extensionality", "Spec.Matrix.map", "Hacl.Impl.Matrix.mod_pow2_felem", "Hacl.Impl.Matrix.as_matrix", "Spec.Matrix.mod_pow2_felem", "Prims.unit", "Hacl.Impl.Matrix.map", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "Prims.bool" ]
[]
module Hacl.Impl.Matrix open FStar.HyperStack.ST open FStar.Mul open LowStar.BufferOps open LowStar.Buffer open Lib.IntTypes open Lib.Buffer open Lib.ByteBuffer module HS = FStar.HyperStack module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module Loops = Lib.LoopCombinators module M = Spec.Matrix module Lemmas = Spec.Frodo.Lemmas #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" unfold let elem = uint16 unfold let lbytes len = lbuffer uint8 len unfold let matrix_t (n1:size_t) (n2:size_t{v n1 * v n2 <= max_size_t}) = lbuffer elem (n1 *! n2) unfold let as_matrix #n1 #n2 h (m:matrix_t n1 n2) : GTot (M.matrix (v n1) (v n2)) = as_seq h m inline_for_extraction noextract val matrix_create: n1:size_t -> n2:size_t{0 < v n1 * v n2 /\ v n1 * v n2 <= max_size_t} -> StackInline (matrix_t n1 n2) (requires fun h0 -> True) (ensures fun h0 a h1 -> stack_allocated a h0 h1 (as_matrix h1 a) /\ as_matrix h1 a == M.create (v n1) (v n2)) let matrix_create n1 n2 = [@inline_let] let len = size (normalize_term (v n1 * v n2)) in create len (u16 0) inline_for_extraction noextract val mget: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> Stack elem (requires fun h0 -> live h0 a) (ensures fun h0 x h1 -> modifies loc_none h0 h1 /\ x == M.mget (as_matrix h0 a) (v i) (v j)) let mget #n1 #n2 a i j = M.index_lt (v n1) (v n2) (v i) (v j); a.(i *! n2 +! j) inline_for_extraction noextract val mset: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> x:elem -> Stack unit (requires fun h0 -> live h0 a) (ensures fun h0 _ h1 -> modifies1 a h0 h1 /\ as_matrix h1 a == M.mset (as_matrix h0 a) (v i) (v j) x) let mset #n1 #n2 a i j x = M.index_lt (v n1) (v n2) (v i) (v j); a.(i *! n2 +! j) <- x noextract unfold val op_String_Access (#n1:size_t) (#n2:size_t{v n1 * v n2 <= max_size_t}) (m:matrix_t n1 n2) (ij:(size_t & size_t){let i, j = ij in v i < v n1 /\ v j < v n2}) : Stack elem (requires fun h0 -> live h0 m) (ensures fun h0 x h1 -> let i, j = ij in modifies loc_none h0 h1 /\ x == M.mget (as_matrix h0 m) (v i) (v j)) let op_String_Access #n1 #n2 m (i,j) = mget m i j noextract unfold val op_String_Assignment (#n1:size_t) (#n2:size_t{v n1 * v n2 <= max_size_t}) (m:matrix_t n1 n2) (ij:(size_t & size_t){let i, j = ij in v i < v n1 /\ v j < v n2}) (x:elem) : Stack unit (requires fun h0 -> live h0 m) (ensures fun h0 _ h1 -> let i, j = ij in modifies1 m h0 h1 /\ live h1 m /\ as_matrix h1 m == M.mset (as_matrix h0 m) (v i) (v j) x) let op_String_Assignment #n1 #n2 m (i,j) x = mset m i j x unfold let get #n1 #n2 h (m:matrix_t n1 n2) i j = M.mget (as_matrix h m) i j private unfold val map_inner_inv: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> h2:HS.mem -> f:(elem -> elem) -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_nat -> Type0 let map_inner_inv #n1 #n2 h0 h1 h2 f a c i j = live h2 a /\ live h2 c /\ modifies1 c h1 h2 /\ j <= v n2 /\ (forall (i0:nat{i0 < v i}) (j:nat{j < v n2}). get h2 c i0 j == get h1 c i0 j) /\ (forall (j0:nat{j0 < j}). get h2 c (v i) j0 == f (get h0 a (v i) j0)) /\ (forall (j0:nat{j <= j0 /\ j0 < v n2}). get h2 c (v i) j0 == get h0 c (v i) j0) /\ (forall (i0:nat{v i < i0 /\ i0 < v n1}) (j:nat{j < v n2}). get h2 c i0 j == get h0 c i0 j) inline_for_extraction noextract private val map_inner: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> f:(elem -> elem) -> a:matrix_t n1 n2 -> c:matrix_t n1 n2{a == c} -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> Stack unit (requires fun h2 -> map_inner_inv h0 h1 h2 f a c i (v j)) (ensures fun _ _ h2 -> map_inner_inv h0 h1 h2 f a c i (v j + 1)) let map_inner #n1 #n2 h0 h1 f a c i j = c.[i,j] <- f a.[i,j] inline_for_extraction val map: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> f:(uint16 -> uint16) -> a:matrix_t n1 n2 -> c:matrix_t n1 n2 -> Stack unit (requires fun h0 -> live h0 a /\ live h0 c /\ a == c) (ensures fun h0 _ h1 -> modifies1 c h0 h1 /\ as_matrix h1 c == M.map #(v n1) #(v n2) f (as_matrix h0 a)) let map #n1 #n2 f a c = let h0 = ST.get () in Lib.Loops.for (size 0) n1 (fun h1 i -> live h1 a /\ live h1 c /\ modifies1 c h0 h1 /\ i <= v n1 /\ (forall (i0:nat{i0 < i}) (j:nat{j < v n2}). get h1 c i0 j == f (get h0 a i0 j)) /\ (forall (i0:nat{i <= i0 /\ i0 < v n1}) (j:nat{j < v n2}). get h1 c i0 j == get h0 c i0 j) ) (fun i -> let h1 = ST.get() in Lib.Loops.for (size 0) n2 (fun h2 j -> map_inner_inv h0 h1 h2 f a c i j) (fun j -> map_inner h0 h1 f a c i j) ); let h2 = ST.get () in M.extensionality (as_matrix h2 c) (M.map f (as_matrix h0 a)) inline_for_extraction noextract val mod_pow2_felem: logq:size_t{0 < v logq /\ v logq < 16} -> a:uint16 -> Pure uint16 (requires True) (ensures fun r -> r == M.mod_pow2_felem (v logq) a) let mod_pow2_felem logq a = a &. ((u16 1 <<. logq) -. u16 1) val mod_pow2: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> logq:size_t{0 < v logq /\ v logq <= 16} -> a:matrix_t n1 n2 -> Stack unit (requires fun h -> live h a) (ensures fun h0 _ h1 -> modifies1 a h0 h1 /\ as_matrix h1 a == M.mod_pow2 (v logq) (as_matrix h0 a)) [@"c_inline"]
false
false
Hacl.Impl.Matrix.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val mod_pow2: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> logq:size_t{0 < v logq /\ v logq <= 16} -> a:matrix_t n1 n2 -> Stack unit (requires fun h -> live h a) (ensures fun h0 _ h1 -> modifies1 a h0 h1 /\ as_matrix h1 a == M.mod_pow2 (v logq) (as_matrix h0 a))
[]
Hacl.Impl.Matrix.mod_pow2
{ "file_name": "code/frodo/Hacl.Impl.Matrix.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
logq: Lib.IntTypes.size_t{0 < Lib.IntTypes.v logq /\ Lib.IntTypes.v logq <= 16} -> a: Hacl.Impl.Matrix.matrix_t n1 n2 -> FStar.HyperStack.ST.Stack Prims.unit
{ "end_col": 78, "end_line": 213, "start_col": 2, "start_line": 208 }
FStar.HyperStack.ST.Stack
val map_inner: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> f:(elem -> elem) -> a:matrix_t n1 n2 -> c:matrix_t n1 n2{a == c} -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> Stack unit (requires fun h2 -> map_inner_inv h0 h1 h2 f a c i (v j)) (ensures fun _ _ h2 -> map_inner_inv h0 h1 h2 f a c i (v j + 1))
[ { "abbrev": true, "full_module": "Spec.Frodo.Lemmas", "short_module": "Lemmas" }, { "abbrev": true, "full_module": "Spec.Matrix", "short_module": "M" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let map_inner #n1 #n2 h0 h1 f a c i j = c.[i,j] <- f a.[i,j]
val map_inner: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> f:(elem -> elem) -> a:matrix_t n1 n2 -> c:matrix_t n1 n2{a == c} -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> Stack unit (requires fun h2 -> map_inner_inv h0 h1 h2 f a c i (v j)) (ensures fun _ _ h2 -> map_inner_inv h0 h1 h2 f a c i (v j + 1)) let map_inner #n1 #n2 h0 h1 f a c i j =
true
null
false
c.[ i, j ] <- f a.[ i, j ]
{ "checked_file": "Hacl.Impl.Matrix.fst.checked", "dependencies": [ "Spec.Matrix.fst.checked", "Spec.Frodo.Lemmas.fst.checked", "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.Loops.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Matrix.fst" }
[]
[ "Lib.IntTypes.size_t", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.Mul.op_Star", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Lib.IntTypes.max_size_t", "FStar.Monotonic.HyperStack.mem", "Hacl.Impl.Matrix.elem", "Hacl.Impl.Matrix.matrix_t", "Prims.eq2", "Prims.op_LessThan", "Hacl.Impl.Matrix.op_String_Assignment", "FStar.Pervasives.Native.Mktuple2", "Prims.unit", "Lib.IntTypes.int_t", "Lib.IntTypes.U16", "Lib.IntTypes.SEC", "Hacl.Impl.Matrix.op_String_Access" ]
[]
module Hacl.Impl.Matrix open FStar.HyperStack.ST open FStar.Mul open LowStar.BufferOps open LowStar.Buffer open Lib.IntTypes open Lib.Buffer open Lib.ByteBuffer module HS = FStar.HyperStack module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module Loops = Lib.LoopCombinators module M = Spec.Matrix module Lemmas = Spec.Frodo.Lemmas #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" unfold let elem = uint16 unfold let lbytes len = lbuffer uint8 len unfold let matrix_t (n1:size_t) (n2:size_t{v n1 * v n2 <= max_size_t}) = lbuffer elem (n1 *! n2) unfold let as_matrix #n1 #n2 h (m:matrix_t n1 n2) : GTot (M.matrix (v n1) (v n2)) = as_seq h m inline_for_extraction noextract val matrix_create: n1:size_t -> n2:size_t{0 < v n1 * v n2 /\ v n1 * v n2 <= max_size_t} -> StackInline (matrix_t n1 n2) (requires fun h0 -> True) (ensures fun h0 a h1 -> stack_allocated a h0 h1 (as_matrix h1 a) /\ as_matrix h1 a == M.create (v n1) (v n2)) let matrix_create n1 n2 = [@inline_let] let len = size (normalize_term (v n1 * v n2)) in create len (u16 0) inline_for_extraction noextract val mget: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> Stack elem (requires fun h0 -> live h0 a) (ensures fun h0 x h1 -> modifies loc_none h0 h1 /\ x == M.mget (as_matrix h0 a) (v i) (v j)) let mget #n1 #n2 a i j = M.index_lt (v n1) (v n2) (v i) (v j); a.(i *! n2 +! j) inline_for_extraction noextract val mset: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> x:elem -> Stack unit (requires fun h0 -> live h0 a) (ensures fun h0 _ h1 -> modifies1 a h0 h1 /\ as_matrix h1 a == M.mset (as_matrix h0 a) (v i) (v j) x) let mset #n1 #n2 a i j x = M.index_lt (v n1) (v n2) (v i) (v j); a.(i *! n2 +! j) <- x noextract unfold val op_String_Access (#n1:size_t) (#n2:size_t{v n1 * v n2 <= max_size_t}) (m:matrix_t n1 n2) (ij:(size_t & size_t){let i, j = ij in v i < v n1 /\ v j < v n2}) : Stack elem (requires fun h0 -> live h0 m) (ensures fun h0 x h1 -> let i, j = ij in modifies loc_none h0 h1 /\ x == M.mget (as_matrix h0 m) (v i) (v j)) let op_String_Access #n1 #n2 m (i,j) = mget m i j noextract unfold val op_String_Assignment (#n1:size_t) (#n2:size_t{v n1 * v n2 <= max_size_t}) (m:matrix_t n1 n2) (ij:(size_t & size_t){let i, j = ij in v i < v n1 /\ v j < v n2}) (x:elem) : Stack unit (requires fun h0 -> live h0 m) (ensures fun h0 _ h1 -> let i, j = ij in modifies1 m h0 h1 /\ live h1 m /\ as_matrix h1 m == M.mset (as_matrix h0 m) (v i) (v j) x) let op_String_Assignment #n1 #n2 m (i,j) x = mset m i j x unfold let get #n1 #n2 h (m:matrix_t n1 n2) i j = M.mget (as_matrix h m) i j private unfold val map_inner_inv: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> h2:HS.mem -> f:(elem -> elem) -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_nat -> Type0 let map_inner_inv #n1 #n2 h0 h1 h2 f a c i j = live h2 a /\ live h2 c /\ modifies1 c h1 h2 /\ j <= v n2 /\ (forall (i0:nat{i0 < v i}) (j:nat{j < v n2}). get h2 c i0 j == get h1 c i0 j) /\ (forall (j0:nat{j0 < j}). get h2 c (v i) j0 == f (get h0 a (v i) j0)) /\ (forall (j0:nat{j <= j0 /\ j0 < v n2}). get h2 c (v i) j0 == get h0 c (v i) j0) /\ (forall (i0:nat{v i < i0 /\ i0 < v n1}) (j:nat{j < v n2}). get h2 c i0 j == get h0 c i0 j) inline_for_extraction noextract private val map_inner: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> f:(elem -> elem) -> a:matrix_t n1 n2 -> c:matrix_t n1 n2{a == c} -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> Stack unit (requires fun h2 -> map_inner_inv h0 h1 h2 f a c i (v j)) (ensures fun _ _ h2 -> map_inner_inv h0 h1 h2 f a c i (v j + 1))
false
false
Hacl.Impl.Matrix.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val map_inner: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> f:(elem -> elem) -> a:matrix_t n1 n2 -> c:matrix_t n1 n2{a == c} -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> Stack unit (requires fun h2 -> map_inner_inv h0 h1 h2 f a c i (v j)) (ensures fun _ _ h2 -> map_inner_inv h0 h1 h2 f a c i (v j + 1))
[]
Hacl.Impl.Matrix.map_inner
{ "file_name": "code/frodo/Hacl.Impl.Matrix.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
h0: FStar.Monotonic.HyperStack.mem -> h1: FStar.Monotonic.HyperStack.mem -> f: (_: Hacl.Impl.Matrix.elem -> Hacl.Impl.Matrix.elem) -> a: Hacl.Impl.Matrix.matrix_t n1 n2 -> c: Hacl.Impl.Matrix.matrix_t n1 n2 {a == c} -> i: Lib.IntTypes.size_t{Lib.IntTypes.v i < Lib.IntTypes.v n1} -> j: Lib.IntTypes.size_t{Lib.IntTypes.v j < Lib.IntTypes.v n2} -> FStar.HyperStack.ST.Stack Prims.unit
{ "end_col": 22, "end_line": 149, "start_col": 2, "start_line": 149 }
FStar.HyperStack.ST.Stack
val map2_inner: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> f:(elem -> elem -> elem) -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> c:matrix_t n1 n2{a == c /\ disjoint b c} -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> Stack unit (requires fun h2 -> map2_inner_inv h0 h1 h2 f a b c i (v j)) (ensures fun _ _ h2 -> map2_inner_inv h0 h1 h2 f a b c i (v j + 1))
[ { "abbrev": true, "full_module": "Spec.Frodo.Lemmas", "short_module": "Lemmas" }, { "abbrev": true, "full_module": "Spec.Matrix", "short_module": "M" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let map2_inner #n1 #n2 h0 h1 f a b c i j = c.[i,j] <- f a.[i,j] b.[i,j]
val map2_inner: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> f:(elem -> elem -> elem) -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> c:matrix_t n1 n2{a == c /\ disjoint b c} -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> Stack unit (requires fun h2 -> map2_inner_inv h0 h1 h2 f a b c i (v j)) (ensures fun _ _ h2 -> map2_inner_inv h0 h1 h2 f a b c i (v j + 1)) let map2_inner #n1 #n2 h0 h1 f a b c i j =
true
null
false
c.[ i, j ] <- f a.[ i, j ] b.[ i, j ]
{ "checked_file": "Hacl.Impl.Matrix.fst.checked", "dependencies": [ "Spec.Matrix.fst.checked", "Spec.Frodo.Lemmas.fst.checked", "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.Loops.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Matrix.fst" }
[]
[ "Lib.IntTypes.size_t", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.Mul.op_Star", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Lib.IntTypes.max_size_t", "FStar.Monotonic.HyperStack.mem", "Hacl.Impl.Matrix.elem", "Hacl.Impl.Matrix.matrix_t", "Prims.l_and", "Prims.eq2", "Lib.Buffer.disjoint", "Lib.Buffer.MUT", "Prims.op_LessThan", "Hacl.Impl.Matrix.op_String_Assignment", "FStar.Pervasives.Native.Mktuple2", "Prims.unit", "Lib.IntTypes.int_t", "Lib.IntTypes.U16", "Lib.IntTypes.SEC", "Hacl.Impl.Matrix.op_String_Access" ]
[]
module Hacl.Impl.Matrix open FStar.HyperStack.ST open FStar.Mul open LowStar.BufferOps open LowStar.Buffer open Lib.IntTypes open Lib.Buffer open Lib.ByteBuffer module HS = FStar.HyperStack module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module Loops = Lib.LoopCombinators module M = Spec.Matrix module Lemmas = Spec.Frodo.Lemmas #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" unfold let elem = uint16 unfold let lbytes len = lbuffer uint8 len unfold let matrix_t (n1:size_t) (n2:size_t{v n1 * v n2 <= max_size_t}) = lbuffer elem (n1 *! n2) unfold let as_matrix #n1 #n2 h (m:matrix_t n1 n2) : GTot (M.matrix (v n1) (v n2)) = as_seq h m inline_for_extraction noextract val matrix_create: n1:size_t -> n2:size_t{0 < v n1 * v n2 /\ v n1 * v n2 <= max_size_t} -> StackInline (matrix_t n1 n2) (requires fun h0 -> True) (ensures fun h0 a h1 -> stack_allocated a h0 h1 (as_matrix h1 a) /\ as_matrix h1 a == M.create (v n1) (v n2)) let matrix_create n1 n2 = [@inline_let] let len = size (normalize_term (v n1 * v n2)) in create len (u16 0) inline_for_extraction noextract val mget: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> Stack elem (requires fun h0 -> live h0 a) (ensures fun h0 x h1 -> modifies loc_none h0 h1 /\ x == M.mget (as_matrix h0 a) (v i) (v j)) let mget #n1 #n2 a i j = M.index_lt (v n1) (v n2) (v i) (v j); a.(i *! n2 +! j) inline_for_extraction noextract val mset: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> x:elem -> Stack unit (requires fun h0 -> live h0 a) (ensures fun h0 _ h1 -> modifies1 a h0 h1 /\ as_matrix h1 a == M.mset (as_matrix h0 a) (v i) (v j) x) let mset #n1 #n2 a i j x = M.index_lt (v n1) (v n2) (v i) (v j); a.(i *! n2 +! j) <- x noextract unfold val op_String_Access (#n1:size_t) (#n2:size_t{v n1 * v n2 <= max_size_t}) (m:matrix_t n1 n2) (ij:(size_t & size_t){let i, j = ij in v i < v n1 /\ v j < v n2}) : Stack elem (requires fun h0 -> live h0 m) (ensures fun h0 x h1 -> let i, j = ij in modifies loc_none h0 h1 /\ x == M.mget (as_matrix h0 m) (v i) (v j)) let op_String_Access #n1 #n2 m (i,j) = mget m i j noextract unfold val op_String_Assignment (#n1:size_t) (#n2:size_t{v n1 * v n2 <= max_size_t}) (m:matrix_t n1 n2) (ij:(size_t & size_t){let i, j = ij in v i < v n1 /\ v j < v n2}) (x:elem) : Stack unit (requires fun h0 -> live h0 m) (ensures fun h0 _ h1 -> let i, j = ij in modifies1 m h0 h1 /\ live h1 m /\ as_matrix h1 m == M.mset (as_matrix h0 m) (v i) (v j) x) let op_String_Assignment #n1 #n2 m (i,j) x = mset m i j x unfold let get #n1 #n2 h (m:matrix_t n1 n2) i j = M.mget (as_matrix h m) i j private unfold val map_inner_inv: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> h2:HS.mem -> f:(elem -> elem) -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_nat -> Type0 let map_inner_inv #n1 #n2 h0 h1 h2 f a c i j = live h2 a /\ live h2 c /\ modifies1 c h1 h2 /\ j <= v n2 /\ (forall (i0:nat{i0 < v i}) (j:nat{j < v n2}). get h2 c i0 j == get h1 c i0 j) /\ (forall (j0:nat{j0 < j}). get h2 c (v i) j0 == f (get h0 a (v i) j0)) /\ (forall (j0:nat{j <= j0 /\ j0 < v n2}). get h2 c (v i) j0 == get h0 c (v i) j0) /\ (forall (i0:nat{v i < i0 /\ i0 < v n1}) (j:nat{j < v n2}). get h2 c i0 j == get h0 c i0 j) inline_for_extraction noextract private val map_inner: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> f:(elem -> elem) -> a:matrix_t n1 n2 -> c:matrix_t n1 n2{a == c} -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> Stack unit (requires fun h2 -> map_inner_inv h0 h1 h2 f a c i (v j)) (ensures fun _ _ h2 -> map_inner_inv h0 h1 h2 f a c i (v j + 1)) let map_inner #n1 #n2 h0 h1 f a c i j = c.[i,j] <- f a.[i,j] inline_for_extraction val map: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> f:(uint16 -> uint16) -> a:matrix_t n1 n2 -> c:matrix_t n1 n2 -> Stack unit (requires fun h0 -> live h0 a /\ live h0 c /\ a == c) (ensures fun h0 _ h1 -> modifies1 c h0 h1 /\ as_matrix h1 c == M.map #(v n1) #(v n2) f (as_matrix h0 a)) let map #n1 #n2 f a c = let h0 = ST.get () in Lib.Loops.for (size 0) n1 (fun h1 i -> live h1 a /\ live h1 c /\ modifies1 c h0 h1 /\ i <= v n1 /\ (forall (i0:nat{i0 < i}) (j:nat{j < v n2}). get h1 c i0 j == f (get h0 a i0 j)) /\ (forall (i0:nat{i <= i0 /\ i0 < v n1}) (j:nat{j < v n2}). get h1 c i0 j == get h0 c i0 j) ) (fun i -> let h1 = ST.get() in Lib.Loops.for (size 0) n2 (fun h2 j -> map_inner_inv h0 h1 h2 f a c i j) (fun j -> map_inner h0 h1 f a c i j) ); let h2 = ST.get () in M.extensionality (as_matrix h2 c) (M.map f (as_matrix h0 a)) inline_for_extraction noextract val mod_pow2_felem: logq:size_t{0 < v logq /\ v logq < 16} -> a:uint16 -> Pure uint16 (requires True) (ensures fun r -> r == M.mod_pow2_felem (v logq) a) let mod_pow2_felem logq a = a &. ((u16 1 <<. logq) -. u16 1) val mod_pow2: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> logq:size_t{0 < v logq /\ v logq <= 16} -> a:matrix_t n1 n2 -> Stack unit (requires fun h -> live h a) (ensures fun h0 _ h1 -> modifies1 a h0 h1 /\ as_matrix h1 a == M.mod_pow2 (v logq) (as_matrix h0 a)) [@"c_inline"] let mod_pow2 #n1 #n2 logq a = if logq <. 16ul then begin let h0 = ST.get () in map (mod_pow2_felem logq) a a; M.extensionality (M.map #(v n1) #(v n2) (mod_pow2_felem logq) (as_matrix h0 a)) (M.map #(v n1) #(v n2) (M.mod_pow2_felem (v logq)) (as_matrix h0 a)) end private unfold val map2_inner_inv: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> h2:HS.mem -> f:(elem -> elem -> elem) -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> c:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_nat -> Type0 let map2_inner_inv #n1 #n2 h0 h1 h2 f a b c i j = live h2 a /\ live h2 b /\ live h2 c /\ modifies1 c h1 h2 /\ j <= v n2 /\ (forall (i0:nat{i0 < v i}) (j:nat{j < v n2}). get h2 c i0 j == get h1 c i0 j) /\ (forall (j0:nat{j0 < j}). get h2 c (v i) j0 == f (get h0 a (v i) j0) (get h2 b (v i) j0)) /\ (forall (j0:nat{j <= j0 /\ j0 < v n2}). get h2 c (v i) j0 == get h0 c (v i) j0) /\ (forall (i0:nat{v i < i0 /\ i0 < v n1}) (j:nat{j < v n2}). get h2 c i0 j == get h0 c i0 j) inline_for_extraction noextract private val map2_inner: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> f:(elem -> elem -> elem) -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> c:matrix_t n1 n2{a == c /\ disjoint b c} -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> Stack unit (requires fun h2 -> map2_inner_inv h0 h1 h2 f a b c i (v j)) (ensures fun _ _ h2 -> map2_inner_inv h0 h1 h2 f a b c i (v j + 1))
false
false
Hacl.Impl.Matrix.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val map2_inner: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> f:(elem -> elem -> elem) -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> c:matrix_t n1 n2{a == c /\ disjoint b c} -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> Stack unit (requires fun h2 -> map2_inner_inv h0 h1 h2 f a b c i (v j)) (ensures fun _ _ h2 -> map2_inner_inv h0 h1 h2 f a b c i (v j + 1))
[]
Hacl.Impl.Matrix.map2_inner
{ "file_name": "code/frodo/Hacl.Impl.Matrix.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
h0: FStar.Monotonic.HyperStack.mem -> h1: FStar.Monotonic.HyperStack.mem -> f: (_: Hacl.Impl.Matrix.elem -> _: Hacl.Impl.Matrix.elem -> Hacl.Impl.Matrix.elem) -> a: Hacl.Impl.Matrix.matrix_t n1 n2 -> b: Hacl.Impl.Matrix.matrix_t n1 n2 -> c: Hacl.Impl.Matrix.matrix_t n1 n2 {a == c /\ Lib.Buffer.disjoint b c} -> i: Lib.IntTypes.size_t{Lib.IntTypes.v i < Lib.IntTypes.v n1} -> j: Lib.IntTypes.size_t{Lib.IntTypes.v j < Lib.IntTypes.v n2} -> FStar.HyperStack.ST.Stack Prims.unit
{ "end_col": 30, "end_line": 258, "start_col": 2, "start_line": 258 }
FStar.HyperStack.ST.Stack
val map: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> f:(uint16 -> uint16) -> a:matrix_t n1 n2 -> c:matrix_t n1 n2 -> Stack unit (requires fun h0 -> live h0 a /\ live h0 c /\ a == c) (ensures fun h0 _ h1 -> modifies1 c h0 h1 /\ as_matrix h1 c == M.map #(v n1) #(v n2) f (as_matrix h0 a))
[ { "abbrev": true, "full_module": "Spec.Frodo.Lemmas", "short_module": "Lemmas" }, { "abbrev": true, "full_module": "Spec.Matrix", "short_module": "M" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let map #n1 #n2 f a c = let h0 = ST.get () in Lib.Loops.for (size 0) n1 (fun h1 i -> live h1 a /\ live h1 c /\ modifies1 c h0 h1 /\ i <= v n1 /\ (forall (i0:nat{i0 < i}) (j:nat{j < v n2}). get h1 c i0 j == f (get h0 a i0 j)) /\ (forall (i0:nat{i <= i0 /\ i0 < v n1}) (j:nat{j < v n2}). get h1 c i0 j == get h0 c i0 j) ) (fun i -> let h1 = ST.get() in Lib.Loops.for (size 0) n2 (fun h2 j -> map_inner_inv h0 h1 h2 f a c i j) (fun j -> map_inner h0 h1 f a c i j) ); let h2 = ST.get () in M.extensionality (as_matrix h2 c) (M.map f (as_matrix h0 a))
val map: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> f:(uint16 -> uint16) -> a:matrix_t n1 n2 -> c:matrix_t n1 n2 -> Stack unit (requires fun h0 -> live h0 a /\ live h0 c /\ a == c) (ensures fun h0 _ h1 -> modifies1 c h0 h1 /\ as_matrix h1 c == M.map #(v n1) #(v n2) f (as_matrix h0 a)) let map #n1 #n2 f a c =
true
null
false
let h0 = ST.get () in Lib.Loops.for (size 0) n1 (fun h1 i -> live h1 a /\ live h1 c /\ modifies1 c h0 h1 /\ i <= v n1 /\ (forall (i0: nat{i0 < i}) (j: nat{j < v n2}). get h1 c i0 j == f (get h0 a i0 j)) /\ (forall (i0: nat{i <= i0 /\ i0 < v n1}) (j: nat{j < v n2}). get h1 c i0 j == get h0 c i0 j)) (fun i -> let h1 = ST.get () in Lib.Loops.for (size 0) n2 (fun h2 j -> map_inner_inv h0 h1 h2 f a c i j) (fun j -> map_inner h0 h1 f a c i j)); let h2 = ST.get () in M.extensionality (as_matrix h2 c) (M.map f (as_matrix h0 a))
{ "checked_file": "Hacl.Impl.Matrix.fst.checked", "dependencies": [ "Spec.Matrix.fst.checked", "Spec.Frodo.Lemmas.fst.checked", "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.Loops.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Matrix.fst" }
[]
[ "Lib.IntTypes.size_t", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.Mul.op_Star", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Lib.IntTypes.max_size_t", "Lib.IntTypes.uint16", "Hacl.Impl.Matrix.matrix_t", "Spec.Matrix.extensionality", "Hacl.Impl.Matrix.as_matrix", "Spec.Matrix.map", "Prims.unit", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "Lib.Loops.for", "Lib.IntTypes.size", "Prims.nat", "Prims.l_and", "Lib.Buffer.live", "Lib.Buffer.MUT", "Hacl.Impl.Matrix.elem", "Lib.Buffer.modifies1", "Prims.l_Forall", "Prims.op_LessThan", "Prims.eq2", "Hacl.Impl.Matrix.get", "Spec.Matrix.elem", "Hacl.Impl.Matrix.map_inner_inv", "Hacl.Impl.Matrix.map_inner" ]
[]
module Hacl.Impl.Matrix open FStar.HyperStack.ST open FStar.Mul open LowStar.BufferOps open LowStar.Buffer open Lib.IntTypes open Lib.Buffer open Lib.ByteBuffer module HS = FStar.HyperStack module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module Loops = Lib.LoopCombinators module M = Spec.Matrix module Lemmas = Spec.Frodo.Lemmas #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" unfold let elem = uint16 unfold let lbytes len = lbuffer uint8 len unfold let matrix_t (n1:size_t) (n2:size_t{v n1 * v n2 <= max_size_t}) = lbuffer elem (n1 *! n2) unfold let as_matrix #n1 #n2 h (m:matrix_t n1 n2) : GTot (M.matrix (v n1) (v n2)) = as_seq h m inline_for_extraction noextract val matrix_create: n1:size_t -> n2:size_t{0 < v n1 * v n2 /\ v n1 * v n2 <= max_size_t} -> StackInline (matrix_t n1 n2) (requires fun h0 -> True) (ensures fun h0 a h1 -> stack_allocated a h0 h1 (as_matrix h1 a) /\ as_matrix h1 a == M.create (v n1) (v n2)) let matrix_create n1 n2 = [@inline_let] let len = size (normalize_term (v n1 * v n2)) in create len (u16 0) inline_for_extraction noextract val mget: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> Stack elem (requires fun h0 -> live h0 a) (ensures fun h0 x h1 -> modifies loc_none h0 h1 /\ x == M.mget (as_matrix h0 a) (v i) (v j)) let mget #n1 #n2 a i j = M.index_lt (v n1) (v n2) (v i) (v j); a.(i *! n2 +! j) inline_for_extraction noextract val mset: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> x:elem -> Stack unit (requires fun h0 -> live h0 a) (ensures fun h0 _ h1 -> modifies1 a h0 h1 /\ as_matrix h1 a == M.mset (as_matrix h0 a) (v i) (v j) x) let mset #n1 #n2 a i j x = M.index_lt (v n1) (v n2) (v i) (v j); a.(i *! n2 +! j) <- x noextract unfold val op_String_Access (#n1:size_t) (#n2:size_t{v n1 * v n2 <= max_size_t}) (m:matrix_t n1 n2) (ij:(size_t & size_t){let i, j = ij in v i < v n1 /\ v j < v n2}) : Stack elem (requires fun h0 -> live h0 m) (ensures fun h0 x h1 -> let i, j = ij in modifies loc_none h0 h1 /\ x == M.mget (as_matrix h0 m) (v i) (v j)) let op_String_Access #n1 #n2 m (i,j) = mget m i j noextract unfold val op_String_Assignment (#n1:size_t) (#n2:size_t{v n1 * v n2 <= max_size_t}) (m:matrix_t n1 n2) (ij:(size_t & size_t){let i, j = ij in v i < v n1 /\ v j < v n2}) (x:elem) : Stack unit (requires fun h0 -> live h0 m) (ensures fun h0 _ h1 -> let i, j = ij in modifies1 m h0 h1 /\ live h1 m /\ as_matrix h1 m == M.mset (as_matrix h0 m) (v i) (v j) x) let op_String_Assignment #n1 #n2 m (i,j) x = mset m i j x unfold let get #n1 #n2 h (m:matrix_t n1 n2) i j = M.mget (as_matrix h m) i j private unfold val map_inner_inv: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> h2:HS.mem -> f:(elem -> elem) -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_nat -> Type0 let map_inner_inv #n1 #n2 h0 h1 h2 f a c i j = live h2 a /\ live h2 c /\ modifies1 c h1 h2 /\ j <= v n2 /\ (forall (i0:nat{i0 < v i}) (j:nat{j < v n2}). get h2 c i0 j == get h1 c i0 j) /\ (forall (j0:nat{j0 < j}). get h2 c (v i) j0 == f (get h0 a (v i) j0)) /\ (forall (j0:nat{j <= j0 /\ j0 < v n2}). get h2 c (v i) j0 == get h0 c (v i) j0) /\ (forall (i0:nat{v i < i0 /\ i0 < v n1}) (j:nat{j < v n2}). get h2 c i0 j == get h0 c i0 j) inline_for_extraction noextract private val map_inner: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> f:(elem -> elem) -> a:matrix_t n1 n2 -> c:matrix_t n1 n2{a == c} -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> Stack unit (requires fun h2 -> map_inner_inv h0 h1 h2 f a c i (v j)) (ensures fun _ _ h2 -> map_inner_inv h0 h1 h2 f a c i (v j + 1)) let map_inner #n1 #n2 h0 h1 f a c i j = c.[i,j] <- f a.[i,j] inline_for_extraction val map: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> f:(uint16 -> uint16) -> a:matrix_t n1 n2 -> c:matrix_t n1 n2 -> Stack unit (requires fun h0 -> live h0 a /\ live h0 c /\ a == c) (ensures fun h0 _ h1 -> modifies1 c h0 h1 /\ as_matrix h1 c == M.map #(v n1) #(v n2) f (as_matrix h0 a))
false
false
Hacl.Impl.Matrix.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val map: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> f:(uint16 -> uint16) -> a:matrix_t n1 n2 -> c:matrix_t n1 n2 -> Stack unit (requires fun h0 -> live h0 a /\ live h0 c /\ a == c) (ensures fun h0 _ h1 -> modifies1 c h0 h1 /\ as_matrix h1 c == M.map #(v n1) #(v n2) f (as_matrix h0 a))
[]
Hacl.Impl.Matrix.map
{ "file_name": "code/frodo/Hacl.Impl.Matrix.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
f: (_: Lib.IntTypes.uint16 -> Lib.IntTypes.uint16) -> a: Hacl.Impl.Matrix.matrix_t n1 n2 -> c: Hacl.Impl.Matrix.matrix_t n1 n2 -> FStar.HyperStack.ST.Stack Prims.unit
{ "end_col": 64, "end_line": 181, "start_col": 23, "start_line": 165 }
FStar.HyperStack.ST.Stack
val map2: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> f:(uint16 -> uint16 -> uint16) -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> c:matrix_t n1 n2 -> Stack unit (requires fun h0 -> live h0 a /\ live h0 b /\ live h0 c /\ a == c /\ disjoint b c) (ensures fun h0 _ h1 -> modifies1 c h0 h1 /\ as_matrix h1 c == M.map2 #(v n1) #(v n2) f (as_matrix h0 a) (as_matrix h0 b))
[ { "abbrev": true, "full_module": "Spec.Frodo.Lemmas", "short_module": "Lemmas" }, { "abbrev": true, "full_module": "Spec.Matrix", "short_module": "M" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let map2 #n1 #n2 f a b c = let h0 = ST.get () in Lib.Loops.for (size 0) n1 (fun h1 i -> live h1 a /\ live h1 b /\ live h1 c /\ modifies1 c h0 h1 /\ i <= v n1 /\ (forall (i0:nat{i0 < i}) (j:nat{j < v n2}). get h1 c i0 j == f (get h0 a i0 j) (get h0 b i0 j)) /\ (forall (i0:nat{i <= i0 /\ i0 < v n1}) (j:nat{j < v n2}). get h1 c i0 j == get h0 c i0 j) ) (fun i -> let h1 = ST.get() in Lib.Loops.for (size 0) n2 (fun h2 j -> map2_inner_inv h0 h1 h2 f a b c i j) (fun j -> map2_inner h0 h1 f a b c i j) ); let h2 = ST.get() in M.extensionality (as_matrix h2 c) (M.map2 f (as_matrix h0 a) (as_matrix h0 b))
val map2: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> f:(uint16 -> uint16 -> uint16) -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> c:matrix_t n1 n2 -> Stack unit (requires fun h0 -> live h0 a /\ live h0 b /\ live h0 c /\ a == c /\ disjoint b c) (ensures fun h0 _ h1 -> modifies1 c h0 h1 /\ as_matrix h1 c == M.map2 #(v n1) #(v n2) f (as_matrix h0 a) (as_matrix h0 b)) let map2 #n1 #n2 f a b c =
true
null
false
let h0 = ST.get () in Lib.Loops.for (size 0) n1 (fun h1 i -> live h1 a /\ live h1 b /\ live h1 c /\ modifies1 c h0 h1 /\ i <= v n1 /\ (forall (i0: nat{i0 < i}) (j: nat{j < v n2}). get h1 c i0 j == f (get h0 a i0 j) (get h0 b i0 j)) /\ (forall (i0: nat{i <= i0 /\ i0 < v n1}) (j: nat{j < v n2}). get h1 c i0 j == get h0 c i0 j)) (fun i -> let h1 = ST.get () in Lib.Loops.for (size 0) n2 (fun h2 j -> map2_inner_inv h0 h1 h2 f a b c i j) (fun j -> map2_inner h0 h1 f a b c i j)); let h2 = ST.get () in M.extensionality (as_matrix h2 c) (M.map2 f (as_matrix h0 a) (as_matrix h0 b))
{ "checked_file": "Hacl.Impl.Matrix.fst.checked", "dependencies": [ "Spec.Matrix.fst.checked", "Spec.Frodo.Lemmas.fst.checked", "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.Loops.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Matrix.fst" }
[]
[ "Lib.IntTypes.size_t", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.Mul.op_Star", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Lib.IntTypes.max_size_t", "Lib.IntTypes.uint16", "Hacl.Impl.Matrix.matrix_t", "Spec.Matrix.extensionality", "Hacl.Impl.Matrix.as_matrix", "Spec.Matrix.map2", "Prims.unit", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "Lib.Loops.for", "Lib.IntTypes.size", "Prims.nat", "Prims.l_and", "Lib.Buffer.live", "Lib.Buffer.MUT", "Hacl.Impl.Matrix.elem", "Lib.Buffer.modifies1", "Prims.l_Forall", "Prims.op_LessThan", "Prims.eq2", "Hacl.Impl.Matrix.get", "Spec.Matrix.elem", "Hacl.Impl.Matrix.map2_inner_inv", "Hacl.Impl.Matrix.map2_inner" ]
[]
module Hacl.Impl.Matrix open FStar.HyperStack.ST open FStar.Mul open LowStar.BufferOps open LowStar.Buffer open Lib.IntTypes open Lib.Buffer open Lib.ByteBuffer module HS = FStar.HyperStack module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module Loops = Lib.LoopCombinators module M = Spec.Matrix module Lemmas = Spec.Frodo.Lemmas #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" unfold let elem = uint16 unfold let lbytes len = lbuffer uint8 len unfold let matrix_t (n1:size_t) (n2:size_t{v n1 * v n2 <= max_size_t}) = lbuffer elem (n1 *! n2) unfold let as_matrix #n1 #n2 h (m:matrix_t n1 n2) : GTot (M.matrix (v n1) (v n2)) = as_seq h m inline_for_extraction noextract val matrix_create: n1:size_t -> n2:size_t{0 < v n1 * v n2 /\ v n1 * v n2 <= max_size_t} -> StackInline (matrix_t n1 n2) (requires fun h0 -> True) (ensures fun h0 a h1 -> stack_allocated a h0 h1 (as_matrix h1 a) /\ as_matrix h1 a == M.create (v n1) (v n2)) let matrix_create n1 n2 = [@inline_let] let len = size (normalize_term (v n1 * v n2)) in create len (u16 0) inline_for_extraction noextract val mget: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> Stack elem (requires fun h0 -> live h0 a) (ensures fun h0 x h1 -> modifies loc_none h0 h1 /\ x == M.mget (as_matrix h0 a) (v i) (v j)) let mget #n1 #n2 a i j = M.index_lt (v n1) (v n2) (v i) (v j); a.(i *! n2 +! j) inline_for_extraction noextract val mset: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> x:elem -> Stack unit (requires fun h0 -> live h0 a) (ensures fun h0 _ h1 -> modifies1 a h0 h1 /\ as_matrix h1 a == M.mset (as_matrix h0 a) (v i) (v j) x) let mset #n1 #n2 a i j x = M.index_lt (v n1) (v n2) (v i) (v j); a.(i *! n2 +! j) <- x noextract unfold val op_String_Access (#n1:size_t) (#n2:size_t{v n1 * v n2 <= max_size_t}) (m:matrix_t n1 n2) (ij:(size_t & size_t){let i, j = ij in v i < v n1 /\ v j < v n2}) : Stack elem (requires fun h0 -> live h0 m) (ensures fun h0 x h1 -> let i, j = ij in modifies loc_none h0 h1 /\ x == M.mget (as_matrix h0 m) (v i) (v j)) let op_String_Access #n1 #n2 m (i,j) = mget m i j noextract unfold val op_String_Assignment (#n1:size_t) (#n2:size_t{v n1 * v n2 <= max_size_t}) (m:matrix_t n1 n2) (ij:(size_t & size_t){let i, j = ij in v i < v n1 /\ v j < v n2}) (x:elem) : Stack unit (requires fun h0 -> live h0 m) (ensures fun h0 _ h1 -> let i, j = ij in modifies1 m h0 h1 /\ live h1 m /\ as_matrix h1 m == M.mset (as_matrix h0 m) (v i) (v j) x) let op_String_Assignment #n1 #n2 m (i,j) x = mset m i j x unfold let get #n1 #n2 h (m:matrix_t n1 n2) i j = M.mget (as_matrix h m) i j private unfold val map_inner_inv: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> h2:HS.mem -> f:(elem -> elem) -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_nat -> Type0 let map_inner_inv #n1 #n2 h0 h1 h2 f a c i j = live h2 a /\ live h2 c /\ modifies1 c h1 h2 /\ j <= v n2 /\ (forall (i0:nat{i0 < v i}) (j:nat{j < v n2}). get h2 c i0 j == get h1 c i0 j) /\ (forall (j0:nat{j0 < j}). get h2 c (v i) j0 == f (get h0 a (v i) j0)) /\ (forall (j0:nat{j <= j0 /\ j0 < v n2}). get h2 c (v i) j0 == get h0 c (v i) j0) /\ (forall (i0:nat{v i < i0 /\ i0 < v n1}) (j:nat{j < v n2}). get h2 c i0 j == get h0 c i0 j) inline_for_extraction noextract private val map_inner: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> f:(elem -> elem) -> a:matrix_t n1 n2 -> c:matrix_t n1 n2{a == c} -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> Stack unit (requires fun h2 -> map_inner_inv h0 h1 h2 f a c i (v j)) (ensures fun _ _ h2 -> map_inner_inv h0 h1 h2 f a c i (v j + 1)) let map_inner #n1 #n2 h0 h1 f a c i j = c.[i,j] <- f a.[i,j] inline_for_extraction val map: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> f:(uint16 -> uint16) -> a:matrix_t n1 n2 -> c:matrix_t n1 n2 -> Stack unit (requires fun h0 -> live h0 a /\ live h0 c /\ a == c) (ensures fun h0 _ h1 -> modifies1 c h0 h1 /\ as_matrix h1 c == M.map #(v n1) #(v n2) f (as_matrix h0 a)) let map #n1 #n2 f a c = let h0 = ST.get () in Lib.Loops.for (size 0) n1 (fun h1 i -> live h1 a /\ live h1 c /\ modifies1 c h0 h1 /\ i <= v n1 /\ (forall (i0:nat{i0 < i}) (j:nat{j < v n2}). get h1 c i0 j == f (get h0 a i0 j)) /\ (forall (i0:nat{i <= i0 /\ i0 < v n1}) (j:nat{j < v n2}). get h1 c i0 j == get h0 c i0 j) ) (fun i -> let h1 = ST.get() in Lib.Loops.for (size 0) n2 (fun h2 j -> map_inner_inv h0 h1 h2 f a c i j) (fun j -> map_inner h0 h1 f a c i j) ); let h2 = ST.get () in M.extensionality (as_matrix h2 c) (M.map f (as_matrix h0 a)) inline_for_extraction noextract val mod_pow2_felem: logq:size_t{0 < v logq /\ v logq < 16} -> a:uint16 -> Pure uint16 (requires True) (ensures fun r -> r == M.mod_pow2_felem (v logq) a) let mod_pow2_felem logq a = a &. ((u16 1 <<. logq) -. u16 1) val mod_pow2: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> logq:size_t{0 < v logq /\ v logq <= 16} -> a:matrix_t n1 n2 -> Stack unit (requires fun h -> live h a) (ensures fun h0 _ h1 -> modifies1 a h0 h1 /\ as_matrix h1 a == M.mod_pow2 (v logq) (as_matrix h0 a)) [@"c_inline"] let mod_pow2 #n1 #n2 logq a = if logq <. 16ul then begin let h0 = ST.get () in map (mod_pow2_felem logq) a a; M.extensionality (M.map #(v n1) #(v n2) (mod_pow2_felem logq) (as_matrix h0 a)) (M.map #(v n1) #(v n2) (M.mod_pow2_felem (v logq)) (as_matrix h0 a)) end private unfold val map2_inner_inv: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> h2:HS.mem -> f:(elem -> elem -> elem) -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> c:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_nat -> Type0 let map2_inner_inv #n1 #n2 h0 h1 h2 f a b c i j = live h2 a /\ live h2 b /\ live h2 c /\ modifies1 c h1 h2 /\ j <= v n2 /\ (forall (i0:nat{i0 < v i}) (j:nat{j < v n2}). get h2 c i0 j == get h1 c i0 j) /\ (forall (j0:nat{j0 < j}). get h2 c (v i) j0 == f (get h0 a (v i) j0) (get h2 b (v i) j0)) /\ (forall (j0:nat{j <= j0 /\ j0 < v n2}). get h2 c (v i) j0 == get h0 c (v i) j0) /\ (forall (i0:nat{v i < i0 /\ i0 < v n1}) (j:nat{j < v n2}). get h2 c i0 j == get h0 c i0 j) inline_for_extraction noextract private val map2_inner: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> f:(elem -> elem -> elem) -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> c:matrix_t n1 n2{a == c /\ disjoint b c} -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> Stack unit (requires fun h2 -> map2_inner_inv h0 h1 h2 f a b c i (v j)) (ensures fun _ _ h2 -> map2_inner_inv h0 h1 h2 f a b c i (v j + 1)) let map2_inner #n1 #n2 h0 h1 f a b c i j = c.[i,j] <- f a.[i,j] b.[i,j] /// In-place [map2], a == map2 f a b /// /// A non in-place variant can be obtained by weakening the pre-condition to disjoint a c, /// or the two variants can be merged by requiring (a == c \/ disjoint a c) instead of a == c /// See commit 91916b8372fa3522061eff5a42d0ebd1d19a8a49 inline_for_extraction val map2: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> f:(uint16 -> uint16 -> uint16) -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> c:matrix_t n1 n2 -> Stack unit (requires fun h0 -> live h0 a /\ live h0 b /\ live h0 c /\ a == c /\ disjoint b c) (ensures fun h0 _ h1 -> modifies1 c h0 h1 /\ as_matrix h1 c == M.map2 #(v n1) #(v n2) f (as_matrix h0 a) (as_matrix h0 b))
false
false
Hacl.Impl.Matrix.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val map2: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> f:(uint16 -> uint16 -> uint16) -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> c:matrix_t n1 n2 -> Stack unit (requires fun h0 -> live h0 a /\ live h0 b /\ live h0 c /\ a == c /\ disjoint b c) (ensures fun h0 _ h1 -> modifies1 c h0 h1 /\ as_matrix h1 c == M.map2 #(v n1) #(v n2) f (as_matrix h0 a) (as_matrix h0 b))
[]
Hacl.Impl.Matrix.map2
{ "file_name": "code/frodo/Hacl.Impl.Matrix.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
f: (_: Lib.IntTypes.uint16 -> _: Lib.IntTypes.uint16 -> Lib.IntTypes.uint16) -> a: Hacl.Impl.Matrix.matrix_t n1 n2 -> b: Hacl.Impl.Matrix.matrix_t n1 n2 -> c: Hacl.Impl.Matrix.matrix_t n1 n2 -> FStar.HyperStack.ST.Stack Prims.unit
{ "end_col": 82, "end_line": 297, "start_col": 26, "start_line": 281 }
FStar.HyperStack.ST.Stack
val matrix_eq: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> Stack uint16 (requires fun h -> live h a /\ live h b) (ensures fun h0 r h1 -> modifies0 h0 h1 /\ r == M.matrix_eq #(v n1) #(v n2) (as_matrix h0 a) (as_matrix h0 b))
[ { "abbrev": true, "full_module": "Spec.Frodo.Lemmas", "short_module": "Lemmas" }, { "abbrev": true, "full_module": "Spec.Matrix", "short_module": "M" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let matrix_eq #n1 #n2 a b = push_frame(); let res = create 1ul (ones U16 SEC) in let r = buf_eq_mask a b (n1 *! n2) res in pop_frame (); r
val matrix_eq: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> Stack uint16 (requires fun h -> live h a /\ live h b) (ensures fun h0 r h1 -> modifies0 h0 h1 /\ r == M.matrix_eq #(v n1) #(v n2) (as_matrix h0 a) (as_matrix h0 b)) let matrix_eq #n1 #n2 a b =
true
null
false
push_frame (); let res = create 1ul (ones U16 SEC) in let r = buf_eq_mask a b (n1 *! n2) res in pop_frame (); r
{ "checked_file": "Hacl.Impl.Matrix.fst.checked", "dependencies": [ "Spec.Matrix.fst.checked", "Spec.Frodo.Lemmas.fst.checked", "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.Loops.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Matrix.fst" }
[]
[ "Lib.IntTypes.size_t", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.Mul.op_Star", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Lib.IntTypes.max_size_t", "Hacl.Impl.Matrix.matrix_t", "Lib.IntTypes.uint16", "Prims.unit", "FStar.HyperStack.ST.pop_frame", "Lib.IntTypes.int_t", "Lib.IntTypes.U16", "Lib.IntTypes.SEC", "Lib.ByteBuffer.buf_eq_mask", "Lib.IntTypes.op_Star_Bang", "Lib.Buffer.lbuffer_t", "Lib.Buffer.MUT", "FStar.UInt32.uint_to_t", "FStar.UInt32.t", "Lib.Buffer.create", "FStar.UInt32.__uint_to_t", "Lib.IntTypes.ones", "Lib.Buffer.lbuffer", "FStar.HyperStack.ST.push_frame" ]
[]
module Hacl.Impl.Matrix open FStar.HyperStack.ST open FStar.Mul open LowStar.BufferOps open LowStar.Buffer open Lib.IntTypes open Lib.Buffer open Lib.ByteBuffer module HS = FStar.HyperStack module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module Loops = Lib.LoopCombinators module M = Spec.Matrix module Lemmas = Spec.Frodo.Lemmas #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" unfold let elem = uint16 unfold let lbytes len = lbuffer uint8 len unfold let matrix_t (n1:size_t) (n2:size_t{v n1 * v n2 <= max_size_t}) = lbuffer elem (n1 *! n2) unfold let as_matrix #n1 #n2 h (m:matrix_t n1 n2) : GTot (M.matrix (v n1) (v n2)) = as_seq h m inline_for_extraction noextract val matrix_create: n1:size_t -> n2:size_t{0 < v n1 * v n2 /\ v n1 * v n2 <= max_size_t} -> StackInline (matrix_t n1 n2) (requires fun h0 -> True) (ensures fun h0 a h1 -> stack_allocated a h0 h1 (as_matrix h1 a) /\ as_matrix h1 a == M.create (v n1) (v n2)) let matrix_create n1 n2 = [@inline_let] let len = size (normalize_term (v n1 * v n2)) in create len (u16 0) inline_for_extraction noextract val mget: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> Stack elem (requires fun h0 -> live h0 a) (ensures fun h0 x h1 -> modifies loc_none h0 h1 /\ x == M.mget (as_matrix h0 a) (v i) (v j)) let mget #n1 #n2 a i j = M.index_lt (v n1) (v n2) (v i) (v j); a.(i *! n2 +! j) inline_for_extraction noextract val mset: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> x:elem -> Stack unit (requires fun h0 -> live h0 a) (ensures fun h0 _ h1 -> modifies1 a h0 h1 /\ as_matrix h1 a == M.mset (as_matrix h0 a) (v i) (v j) x) let mset #n1 #n2 a i j x = M.index_lt (v n1) (v n2) (v i) (v j); a.(i *! n2 +! j) <- x noextract unfold val op_String_Access (#n1:size_t) (#n2:size_t{v n1 * v n2 <= max_size_t}) (m:matrix_t n1 n2) (ij:(size_t & size_t){let i, j = ij in v i < v n1 /\ v j < v n2}) : Stack elem (requires fun h0 -> live h0 m) (ensures fun h0 x h1 -> let i, j = ij in modifies loc_none h0 h1 /\ x == M.mget (as_matrix h0 m) (v i) (v j)) let op_String_Access #n1 #n2 m (i,j) = mget m i j noextract unfold val op_String_Assignment (#n1:size_t) (#n2:size_t{v n1 * v n2 <= max_size_t}) (m:matrix_t n1 n2) (ij:(size_t & size_t){let i, j = ij in v i < v n1 /\ v j < v n2}) (x:elem) : Stack unit (requires fun h0 -> live h0 m) (ensures fun h0 _ h1 -> let i, j = ij in modifies1 m h0 h1 /\ live h1 m /\ as_matrix h1 m == M.mset (as_matrix h0 m) (v i) (v j) x) let op_String_Assignment #n1 #n2 m (i,j) x = mset m i j x unfold let get #n1 #n2 h (m:matrix_t n1 n2) i j = M.mget (as_matrix h m) i j private unfold val map_inner_inv: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> h2:HS.mem -> f:(elem -> elem) -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_nat -> Type0 let map_inner_inv #n1 #n2 h0 h1 h2 f a c i j = live h2 a /\ live h2 c /\ modifies1 c h1 h2 /\ j <= v n2 /\ (forall (i0:nat{i0 < v i}) (j:nat{j < v n2}). get h2 c i0 j == get h1 c i0 j) /\ (forall (j0:nat{j0 < j}). get h2 c (v i) j0 == f (get h0 a (v i) j0)) /\ (forall (j0:nat{j <= j0 /\ j0 < v n2}). get h2 c (v i) j0 == get h0 c (v i) j0) /\ (forall (i0:nat{v i < i0 /\ i0 < v n1}) (j:nat{j < v n2}). get h2 c i0 j == get h0 c i0 j) inline_for_extraction noextract private val map_inner: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> f:(elem -> elem) -> a:matrix_t n1 n2 -> c:matrix_t n1 n2{a == c} -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> Stack unit (requires fun h2 -> map_inner_inv h0 h1 h2 f a c i (v j)) (ensures fun _ _ h2 -> map_inner_inv h0 h1 h2 f a c i (v j + 1)) let map_inner #n1 #n2 h0 h1 f a c i j = c.[i,j] <- f a.[i,j] inline_for_extraction val map: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> f:(uint16 -> uint16) -> a:matrix_t n1 n2 -> c:matrix_t n1 n2 -> Stack unit (requires fun h0 -> live h0 a /\ live h0 c /\ a == c) (ensures fun h0 _ h1 -> modifies1 c h0 h1 /\ as_matrix h1 c == M.map #(v n1) #(v n2) f (as_matrix h0 a)) let map #n1 #n2 f a c = let h0 = ST.get () in Lib.Loops.for (size 0) n1 (fun h1 i -> live h1 a /\ live h1 c /\ modifies1 c h0 h1 /\ i <= v n1 /\ (forall (i0:nat{i0 < i}) (j:nat{j < v n2}). get h1 c i0 j == f (get h0 a i0 j)) /\ (forall (i0:nat{i <= i0 /\ i0 < v n1}) (j:nat{j < v n2}). get h1 c i0 j == get h0 c i0 j) ) (fun i -> let h1 = ST.get() in Lib.Loops.for (size 0) n2 (fun h2 j -> map_inner_inv h0 h1 h2 f a c i j) (fun j -> map_inner h0 h1 f a c i j) ); let h2 = ST.get () in M.extensionality (as_matrix h2 c) (M.map f (as_matrix h0 a)) inline_for_extraction noextract val mod_pow2_felem: logq:size_t{0 < v logq /\ v logq < 16} -> a:uint16 -> Pure uint16 (requires True) (ensures fun r -> r == M.mod_pow2_felem (v logq) a) let mod_pow2_felem logq a = a &. ((u16 1 <<. logq) -. u16 1) val mod_pow2: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> logq:size_t{0 < v logq /\ v logq <= 16} -> a:matrix_t n1 n2 -> Stack unit (requires fun h -> live h a) (ensures fun h0 _ h1 -> modifies1 a h0 h1 /\ as_matrix h1 a == M.mod_pow2 (v logq) (as_matrix h0 a)) [@"c_inline"] let mod_pow2 #n1 #n2 logq a = if logq <. 16ul then begin let h0 = ST.get () in map (mod_pow2_felem logq) a a; M.extensionality (M.map #(v n1) #(v n2) (mod_pow2_felem logq) (as_matrix h0 a)) (M.map #(v n1) #(v n2) (M.mod_pow2_felem (v logq)) (as_matrix h0 a)) end private unfold val map2_inner_inv: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> h2:HS.mem -> f:(elem -> elem -> elem) -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> c:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_nat -> Type0 let map2_inner_inv #n1 #n2 h0 h1 h2 f a b c i j = live h2 a /\ live h2 b /\ live h2 c /\ modifies1 c h1 h2 /\ j <= v n2 /\ (forall (i0:nat{i0 < v i}) (j:nat{j < v n2}). get h2 c i0 j == get h1 c i0 j) /\ (forall (j0:nat{j0 < j}). get h2 c (v i) j0 == f (get h0 a (v i) j0) (get h2 b (v i) j0)) /\ (forall (j0:nat{j <= j0 /\ j0 < v n2}). get h2 c (v i) j0 == get h0 c (v i) j0) /\ (forall (i0:nat{v i < i0 /\ i0 < v n1}) (j:nat{j < v n2}). get h2 c i0 j == get h0 c i0 j) inline_for_extraction noextract private val map2_inner: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> f:(elem -> elem -> elem) -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> c:matrix_t n1 n2{a == c /\ disjoint b c} -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> Stack unit (requires fun h2 -> map2_inner_inv h0 h1 h2 f a b c i (v j)) (ensures fun _ _ h2 -> map2_inner_inv h0 h1 h2 f a b c i (v j + 1)) let map2_inner #n1 #n2 h0 h1 f a b c i j = c.[i,j] <- f a.[i,j] b.[i,j] /// In-place [map2], a == map2 f a b /// /// A non in-place variant can be obtained by weakening the pre-condition to disjoint a c, /// or the two variants can be merged by requiring (a == c \/ disjoint a c) instead of a == c /// See commit 91916b8372fa3522061eff5a42d0ebd1d19a8a49 inline_for_extraction val map2: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> f:(uint16 -> uint16 -> uint16) -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> c:matrix_t n1 n2 -> Stack unit (requires fun h0 -> live h0 a /\ live h0 b /\ live h0 c /\ a == c /\ disjoint b c) (ensures fun h0 _ h1 -> modifies1 c h0 h1 /\ as_matrix h1 c == M.map2 #(v n1) #(v n2) f (as_matrix h0 a) (as_matrix h0 b)) let map2 #n1 #n2 f a b c = let h0 = ST.get () in Lib.Loops.for (size 0) n1 (fun h1 i -> live h1 a /\ live h1 b /\ live h1 c /\ modifies1 c h0 h1 /\ i <= v n1 /\ (forall (i0:nat{i0 < i}) (j:nat{j < v n2}). get h1 c i0 j == f (get h0 a i0 j) (get h0 b i0 j)) /\ (forall (i0:nat{i <= i0 /\ i0 < v n1}) (j:nat{j < v n2}). get h1 c i0 j == get h0 c i0 j) ) (fun i -> let h1 = ST.get() in Lib.Loops.for (size 0) n2 (fun h2 j -> map2_inner_inv h0 h1 h2 f a b c i j) (fun j -> map2_inner h0 h1 f a b c i j) ); let h2 = ST.get() in M.extensionality (as_matrix h2 c) (M.map2 f (as_matrix h0 a) (as_matrix h0 b)) val matrix_add: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> Stack unit (requires fun h -> live h a /\ live h b /\ disjoint a b) (ensures fun h0 r h1 -> modifies1 a h0 h1 /\ as_matrix h1 a == M.add (as_matrix h0 a) (as_matrix h0 b)) [@"c_inline"] let matrix_add #n1 #n2 a b = map2 add_mod a b a val matrix_sub: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> Stack unit (requires fun h -> live h a /\ live h b /\ disjoint a b) (ensures fun h0 r h1 -> modifies1 b h0 h1 /\ as_matrix h1 b == M.sub (as_matrix h0 a) (as_matrix h0 b)) [@"c_inline"] let matrix_sub #n1 #n2 a b = (* Use the in-place variant above by flipping the arguments of [sub_mod] *) (* Requires appplying extensionality *) let h0 = ST.get() in [@ inline_let ] let sub_mod_flipped x y = sub_mod y x in map2 sub_mod_flipped b a b; let h1 = ST.get() in M.extensionality (as_matrix h1 b) (M.sub (as_matrix h0 a) (as_matrix h0 b)) #push-options "--fuel 1" inline_for_extraction noextract private val mul_inner: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> #n3:size_t{v n2 * v n3 <= max_size_t /\ v n1 * v n3 <= max_size_t} -> a:matrix_t n1 n2 -> b:matrix_t n2 n3 -> i:size_t{v i < v n1} -> k:size_t{v k < v n3} -> Stack uint16 (requires fun h -> live h a /\ live h b) (ensures fun h0 r h1 -> modifies loc_none h0 h1 /\ r == M.mul_inner (as_matrix h0 a) (as_matrix h0 b) (v i) (v k)) let mul_inner #n1 #n2 #n3 a b i k = push_frame(); let h0 = ST.get() in [@ inline_let ] let f l = get h0 a (v i) l *. get h0 b l (v k) in let res = create #uint16 (size 1) (u16 0) in let h1 = ST.get() in Lib.Loops.for (size 0) n2 (fun h2 j -> live h1 res /\ live h2 res /\ modifies1 res h1 h2 /\ bget h2 res 0 == M.sum_ #(v n2) f j) (fun j -> let aij = a.[i,j] in let bjk = b.[j,k] in let res0 = res.(size 0) in res.(size 0) <- res0 +. aij *. bjk ); let res = res.(size 0) in M.sum_extensionality (v n2) f (fun l -> get h0 a (v i) l *. get h0 b l (v k)) (v n2); assert (res == M.mul_inner (as_matrix h0 a) (as_matrix h0 b) (v i) (v k)); pop_frame(); res #pop-options private unfold val mul_inner_inv: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> #n3:size_t{v n2 * v n3 <= max_size_t /\ v n1 * v n3 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> h2:HS.mem -> a:matrix_t n1 n2 -> b:matrix_t n2 n3 -> c:matrix_t n1 n3 -> f:(k:nat{k < v n3} -> GTot uint16) -> i:size_t{v i < v n1} -> k:size_nat -> Type0 let mul_inner_inv #n1 #n2 #n3 h0 h1 h2 a b c f i k = live h2 a /\ live h2 b /\ live h2 c /\ modifies1 c h1 h2 /\ k <= v n3 /\ (forall (i1:nat{i1 < v i}) (k:nat{k < v n3}). get h2 c i1 k == get h1 c i1 k) /\ (forall (k1:nat{k1 < k}). get h2 c (v i) k1 == f k1) /\ (forall (k1:nat{k <= k1 /\ k1 < v n3}). get h2 c (v i) k1 == get h0 c (v i) k1) /\ (forall (i1:nat{v i < i1 /\ i1 < v n1}) (k:nat{k < v n3}). get h2 c i1 k == get h0 c i1 k) /\ as_matrix h0 a == as_matrix h2 a /\ as_matrix h0 b == as_matrix h2 b inline_for_extraction noextract private val mul_inner1: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> #n3:size_t{v n2 * v n3 <= max_size_t /\ v n1 * v n3 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> a:matrix_t n1 n2 -> b:matrix_t n2 n3 -> c:matrix_t n1 n3{disjoint a c /\ disjoint b c} -> i:size_t{v i < v n1} -> k:size_t{v k < v n3} -> f:(k:nat{k < v n3} -> GTot (res:uint16{res == M.sum #(v n2) (fun l -> get h0 a (v i) l *. get h0 b l k)})) -> Stack unit (requires fun h2 -> mul_inner_inv h0 h1 h2 a b c f i (v k)) (ensures fun _ _ h2 -> mul_inner_inv h0 h1 h2 a b c f i (v k + 1)) let mul_inner1 #n1 #n2 #n3 h0 h1 a b c i k f = assert (M.mul_inner (as_matrix h0 a) (as_matrix h0 b) (v i) (v k) == M.sum #(v n2) (fun l -> get h0 a (v i) l *. get h0 b l (v k))); c.[i,k] <- mul_inner a b i k; let h2 = ST.get () in assert (get h2 c (v i) (v k) == f (v k)) private val onemore: p:(nat -> Type0) -> q:(i:nat{p i} -> Type0) -> b:nat{p b} -> Lemma (requires (forall (i:nat{p i /\ i < b}). q i) /\ q b) (ensures forall (i:nat{p i /\ i <= b}). q i) let onemore p q b = () val onemore1: #n1:size_nat -> #n3:size_nat{n1 * n3 <= max_size_t} -> c:M.matrix n1 n3 -> f:(i:nat{i < n1} -> k:nat{k < n3} -> GTot uint16) -> i:size_nat{i < n1} -> Lemma (requires ((forall (i1:nat{i1 < i}) (k:nat{k < n3}). M.mget c i1 k == f i1 k) /\ (forall (k:nat{k < n3}). M.mget c i k == f i k))) (ensures (forall (i1:nat{i1 <= i}) (k:nat{k < n3}). M.mget c i1 k == f i1 k)) let onemore1 #n1 #n3 c f i = () val matrix_mul: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> #n3:size_t{v n2 * v n3 <= max_size_t /\ v n1 * v n3 <= max_size_t} -> a:matrix_t n1 n2 -> b:matrix_t n2 n3 -> c:matrix_t n1 n3 -> Stack unit (requires fun h -> live h a /\ live h b /\ live h c /\ disjoint a c /\ disjoint b c) (ensures fun h0 _ h1 -> modifies1 c h0 h1 /\ as_matrix h1 c == M.mul (as_matrix h0 a) (as_matrix h0 b)) [@"c_inline"] let matrix_mul #n1 #n2 #n3 a b c = let h0 = ST.get () in let f (i:nat{i < v n1}) (k:nat{k < v n3}) : GTot (res:uint16{res == M.sum #(v n2) (fun l -> get h0 a i l *. get h0 b l k)}) = M.sum #(v n2) (fun l -> get h0 a i l *. get h0 b l k) in Lib.Loops.for (size 0) n1 (fun h1 i -> live h1 a /\ live h1 b /\ live h1 c /\ modifies1 c h0 h1 /\ i <= v n1 /\ (forall (i1:nat{i1 < i}) (k:nat{k < v n3}). get h1 c i1 k == f i1 k) /\ (forall (i1:nat{i <= i1 /\ i1 < v n1}) (k:nat{k < v n3}). get h1 c i1 k == get h0 c i1 k)) (fun i -> let h1 = ST.get() in Lib.Loops.for (size 0) n3 (fun h2 k -> mul_inner_inv h0 h1 h2 a b c (f (v i)) i k) (fun k -> mul_inner1 h0 h1 a b c i k (f (v i))); let h1 = ST.get() in let q i1 = forall (k:nat{k < v n3}). get h1 c i1 k == f i1 k in onemore (fun i1 -> i1 < v n1) q (v i); assert (forall (i1:nat{i1 < v n1 /\ i1 <= v i}) (k:nat{k < v n3}). get h1 c i1 k == f i1 k) ); let h2 = ST.get() in M.extensionality (as_matrix h2 c) (M.mul (as_matrix h0 a) (as_matrix h0 b)) (* Special case of matrix multiplication *) (* when we have a different way of accessing to entries of the matrix S *) inline_for_extraction noextract val mget_s: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> Stack elem (requires fun h0 -> live h0 a) (ensures fun h0 x h1 -> modifies0 h0 h1 /\ x == M.mget_s (as_matrix h0 a) (v i) (v j)) let mget_s #n1 #n2 a i j = M.index_lt (v n2) (v n1) (v j) (v i); a.(j *! n1 +! i) unfold let get_s #n1 #n2 h (m:matrix_t n1 n2) i j = M.mget_s (as_matrix h m) i j #push-options "--fuel 1" inline_for_extraction noextract private val mul_inner_s: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> #n3:size_t{v n2 * v n3 <= max_size_t /\ v n1 * v n3 <= max_size_t} -> a:matrix_t n1 n2 -> b:matrix_t n2 n3 -> i:size_t{v i < v n1} -> k:size_t{v k < v n3} -> Stack uint16 (requires fun h -> live h a /\ live h b) (ensures fun h0 r h1 -> modifies0 h0 h1 /\ r == M.mul_inner_s (as_matrix h0 a) (as_matrix h0 b) (v i) (v k)) let mul_inner_s #n1 #n2 #n3 a b i k = push_frame(); let h0 = ST.get() in [@ inline_let ] let f l = get h0 a (v i) l *. get_s h0 b l (v k) in let res = create #uint16 (size 1) (u16 0) in let h1 = ST.get() in Lib.Loops.for (size 0) n2 (fun h2 j -> live h1 res /\ live h2 res /\ modifies1 res h1 h2 /\ bget h2 res 0 == M.sum_ #(v n2) f j) (fun j -> let aij = mget a i j in let bjk = mget_s b j k in let res0 = res.(size 0) in res.(size 0) <- res0 +. aij *. bjk ); let res = res.(size 0) in M.sum_extensionality (v n2) f (fun l -> get h0 a (v i) l *. get_s h0 b l (v k)) (v n2); assert (res == M.mul_inner_s (as_matrix h0 a) (as_matrix h0 b) (v i) (v k)); pop_frame(); res #pop-options inline_for_extraction noextract private val mul_inner1_s: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> #n3:size_t{v n2 * v n3 <= max_size_t /\ v n1 * v n3 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> a:matrix_t n1 n2 -> b:matrix_t n2 n3 -> c:matrix_t n1 n3{disjoint a c /\ disjoint b c} -> i:size_t{v i < v n1} -> k:size_t{v k < v n3} -> f:(k:nat{k < v n3} -> GTot (res:uint16{res == M.sum #(v n2) (fun l -> get h0 a (v i) l *. get_s h0 b l k)})) -> Stack unit (requires fun h2 -> mul_inner_inv h0 h1 h2 a b c f i (v k)) (ensures fun _ _ h2 -> mul_inner_inv h0 h1 h2 a b c f i (v k + 1)) let mul_inner1_s #n1 #n2 #n3 h0 h1 a b c i k f = assert (M.mul_inner_s (as_matrix h0 a) (as_matrix h0 b) (v i) (v k) == M.sum #(v n2) (fun l -> get h0 a (v i) l *. get_s h0 b l (v k))); mset c i k (mul_inner_s a b i k); let h2 = ST.get () in assert (get h2 c (v i) (v k) == f (v k)) val matrix_mul_s: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> #n3:size_t{v n2 * v n3 <= max_size_t /\ v n1 * v n3 <= max_size_t} -> a:matrix_t n1 n2 -> b:matrix_t n2 n3 -> c:matrix_t n1 n3 -> Stack unit (requires fun h -> live h a /\ live h b /\ live h c /\ disjoint a c /\ disjoint b c) (ensures fun h0 _ h1 -> modifies1 c h0 h1 /\ as_matrix h1 c == M.mul_s (as_matrix h0 a) (as_matrix h0 b)) [@"c_inline"] let matrix_mul_s #n1 #n2 #n3 a b c = let h0 = ST.get () in let f (i:nat{i < v n1}) (k:nat{k < v n3}) : GTot (res:uint16{res == M.sum #(v n2) (fun l -> get h0 a i l *. get_s h0 b l k)}) = M.sum #(v n2) (fun l -> get h0 a i l *. get_s h0 b l k) in Lib.Loops.for (size 0) n1 (fun h1 i -> live h1 a /\ live h1 b /\ live h1 c /\ modifies1 c h0 h1 /\ i <= v n1 /\ (forall (i1:nat{i1 < i}) (k:nat{k < v n3}). get h1 c i1 k == f i1 k) /\ (forall (i1:nat{i <= i1 /\ i1 < v n1}) (k:nat{k < v n3}). get h1 c i1 k == get h0 c i1 k)) (fun i -> let h1 = ST.get() in Lib.Loops.for (size 0) n3 (fun h2 k -> mul_inner_inv h0 h1 h2 a b c (f (v i)) i k) (fun k -> mul_inner1_s h0 h1 a b c i k (f (v i))); let h1 = ST.get() in let q i1 = forall k. get h1 c i1 k == f i1 k in onemore (fun i1 -> i1 < v n1) q (v i); assert (forall (i1:nat{i1 < v n1 /\ i1 <= v i}) (k:nat{k < v n3}). get h1 c i1 k == f i1 k) ); let h2 = ST.get() in M.extensionality (as_matrix h2 c) (M.mul_s (as_matrix h0 a) (as_matrix h0 b)) (* the end of the special matrix multiplication *) val matrix_eq: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> Stack uint16 (requires fun h -> live h a /\ live h b) (ensures fun h0 r h1 -> modifies0 h0 h1 /\ r == M.matrix_eq #(v n1) #(v n2) (as_matrix h0 a) (as_matrix h0 b)) [@"c_inline"]
false
false
Hacl.Impl.Matrix.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val matrix_eq: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> Stack uint16 (requires fun h -> live h a /\ live h b) (ensures fun h0 r h1 -> modifies0 h0 h1 /\ r == M.matrix_eq #(v n1) #(v n2) (as_matrix h0 a) (as_matrix h0 b))
[]
Hacl.Impl.Matrix.matrix_eq
{ "file_name": "code/frodo/Hacl.Impl.Matrix.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
a: Hacl.Impl.Matrix.matrix_t n1 n2 -> b: Hacl.Impl.Matrix.matrix_t n1 n2 -> FStar.HyperStack.ST.Stack Lib.IntTypes.uint16
{ "end_col": 3, "end_line": 638, "start_col": 2, "start_line": 634 }
FStar.HyperStack.ST.Stack
val mul_inner1: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> #n3:size_t{v n2 * v n3 <= max_size_t /\ v n1 * v n3 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> a:matrix_t n1 n2 -> b:matrix_t n2 n3 -> c:matrix_t n1 n3{disjoint a c /\ disjoint b c} -> i:size_t{v i < v n1} -> k:size_t{v k < v n3} -> f:(k:nat{k < v n3} -> GTot (res:uint16{res == M.sum #(v n2) (fun l -> get h0 a (v i) l *. get h0 b l k)})) -> Stack unit (requires fun h2 -> mul_inner_inv h0 h1 h2 a b c f i (v k)) (ensures fun _ _ h2 -> mul_inner_inv h0 h1 h2 a b c f i (v k + 1))
[ { "abbrev": true, "full_module": "Spec.Frodo.Lemmas", "short_module": "Lemmas" }, { "abbrev": true, "full_module": "Spec.Matrix", "short_module": "M" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let mul_inner1 #n1 #n2 #n3 h0 h1 a b c i k f = assert (M.mul_inner (as_matrix h0 a) (as_matrix h0 b) (v i) (v k) == M.sum #(v n2) (fun l -> get h0 a (v i) l *. get h0 b l (v k))); c.[i,k] <- mul_inner a b i k; let h2 = ST.get () in assert (get h2 c (v i) (v k) == f (v k))
val mul_inner1: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> #n3:size_t{v n2 * v n3 <= max_size_t /\ v n1 * v n3 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> a:matrix_t n1 n2 -> b:matrix_t n2 n3 -> c:matrix_t n1 n3{disjoint a c /\ disjoint b c} -> i:size_t{v i < v n1} -> k:size_t{v k < v n3} -> f:(k:nat{k < v n3} -> GTot (res:uint16{res == M.sum #(v n2) (fun l -> get h0 a (v i) l *. get h0 b l k)})) -> Stack unit (requires fun h2 -> mul_inner_inv h0 h1 h2 a b c f i (v k)) (ensures fun _ _ h2 -> mul_inner_inv h0 h1 h2 a b c f i (v k + 1)) let mul_inner1 #n1 #n2 #n3 h0 h1 a b c i k f =
true
null
false
assert (M.mul_inner (as_matrix h0 a) (as_matrix h0 b) (v i) (v k) == M.sum #(v n2) (fun l -> get h0 a (v i) l *. get h0 b l (v k))); c.[ i, k ] <- mul_inner a b i k; let h2 = ST.get () in assert (get h2 c (v i) (v k) == f (v k))
{ "checked_file": "Hacl.Impl.Matrix.fst.checked", "dependencies": [ "Spec.Matrix.fst.checked", "Spec.Frodo.Lemmas.fst.checked", "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.Loops.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Matrix.fst" }
[]
[ "Lib.IntTypes.size_t", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.Mul.op_Star", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Lib.IntTypes.max_size_t", "Prims.l_and", "FStar.Monotonic.HyperStack.mem", "Hacl.Impl.Matrix.matrix_t", "Lib.Buffer.disjoint", "Lib.Buffer.MUT", "Hacl.Impl.Matrix.elem", "Prims.op_LessThan", "Prims.nat", "Lib.IntTypes.uint16", "Prims.eq2", "Spec.Matrix.sum", "Lib.IntTypes.size_nat", "Lib.IntTypes.op_Star_Dot", "Lib.IntTypes.U16", "Lib.IntTypes.SEC", "Hacl.Impl.Matrix.get", "Prims._assert", "Prims.unit", "FStar.HyperStack.ST.get", "Hacl.Impl.Matrix.op_String_Assignment", "FStar.Pervasives.Native.Mktuple2", "Lib.IntTypes.int_t", "Hacl.Impl.Matrix.mul_inner", "Spec.Matrix.mul_inner", "Hacl.Impl.Matrix.as_matrix" ]
[]
module Hacl.Impl.Matrix open FStar.HyperStack.ST open FStar.Mul open LowStar.BufferOps open LowStar.Buffer open Lib.IntTypes open Lib.Buffer open Lib.ByteBuffer module HS = FStar.HyperStack module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module Loops = Lib.LoopCombinators module M = Spec.Matrix module Lemmas = Spec.Frodo.Lemmas #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" unfold let elem = uint16 unfold let lbytes len = lbuffer uint8 len unfold let matrix_t (n1:size_t) (n2:size_t{v n1 * v n2 <= max_size_t}) = lbuffer elem (n1 *! n2) unfold let as_matrix #n1 #n2 h (m:matrix_t n1 n2) : GTot (M.matrix (v n1) (v n2)) = as_seq h m inline_for_extraction noextract val matrix_create: n1:size_t -> n2:size_t{0 < v n1 * v n2 /\ v n1 * v n2 <= max_size_t} -> StackInline (matrix_t n1 n2) (requires fun h0 -> True) (ensures fun h0 a h1 -> stack_allocated a h0 h1 (as_matrix h1 a) /\ as_matrix h1 a == M.create (v n1) (v n2)) let matrix_create n1 n2 = [@inline_let] let len = size (normalize_term (v n1 * v n2)) in create len (u16 0) inline_for_extraction noextract val mget: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> Stack elem (requires fun h0 -> live h0 a) (ensures fun h0 x h1 -> modifies loc_none h0 h1 /\ x == M.mget (as_matrix h0 a) (v i) (v j)) let mget #n1 #n2 a i j = M.index_lt (v n1) (v n2) (v i) (v j); a.(i *! n2 +! j) inline_for_extraction noextract val mset: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> x:elem -> Stack unit (requires fun h0 -> live h0 a) (ensures fun h0 _ h1 -> modifies1 a h0 h1 /\ as_matrix h1 a == M.mset (as_matrix h0 a) (v i) (v j) x) let mset #n1 #n2 a i j x = M.index_lt (v n1) (v n2) (v i) (v j); a.(i *! n2 +! j) <- x noextract unfold val op_String_Access (#n1:size_t) (#n2:size_t{v n1 * v n2 <= max_size_t}) (m:matrix_t n1 n2) (ij:(size_t & size_t){let i, j = ij in v i < v n1 /\ v j < v n2}) : Stack elem (requires fun h0 -> live h0 m) (ensures fun h0 x h1 -> let i, j = ij in modifies loc_none h0 h1 /\ x == M.mget (as_matrix h0 m) (v i) (v j)) let op_String_Access #n1 #n2 m (i,j) = mget m i j noextract unfold val op_String_Assignment (#n1:size_t) (#n2:size_t{v n1 * v n2 <= max_size_t}) (m:matrix_t n1 n2) (ij:(size_t & size_t){let i, j = ij in v i < v n1 /\ v j < v n2}) (x:elem) : Stack unit (requires fun h0 -> live h0 m) (ensures fun h0 _ h1 -> let i, j = ij in modifies1 m h0 h1 /\ live h1 m /\ as_matrix h1 m == M.mset (as_matrix h0 m) (v i) (v j) x) let op_String_Assignment #n1 #n2 m (i,j) x = mset m i j x unfold let get #n1 #n2 h (m:matrix_t n1 n2) i j = M.mget (as_matrix h m) i j private unfold val map_inner_inv: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> h2:HS.mem -> f:(elem -> elem) -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_nat -> Type0 let map_inner_inv #n1 #n2 h0 h1 h2 f a c i j = live h2 a /\ live h2 c /\ modifies1 c h1 h2 /\ j <= v n2 /\ (forall (i0:nat{i0 < v i}) (j:nat{j < v n2}). get h2 c i0 j == get h1 c i0 j) /\ (forall (j0:nat{j0 < j}). get h2 c (v i) j0 == f (get h0 a (v i) j0)) /\ (forall (j0:nat{j <= j0 /\ j0 < v n2}). get h2 c (v i) j0 == get h0 c (v i) j0) /\ (forall (i0:nat{v i < i0 /\ i0 < v n1}) (j:nat{j < v n2}). get h2 c i0 j == get h0 c i0 j) inline_for_extraction noextract private val map_inner: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> f:(elem -> elem) -> a:matrix_t n1 n2 -> c:matrix_t n1 n2{a == c} -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> Stack unit (requires fun h2 -> map_inner_inv h0 h1 h2 f a c i (v j)) (ensures fun _ _ h2 -> map_inner_inv h0 h1 h2 f a c i (v j + 1)) let map_inner #n1 #n2 h0 h1 f a c i j = c.[i,j] <- f a.[i,j] inline_for_extraction val map: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> f:(uint16 -> uint16) -> a:matrix_t n1 n2 -> c:matrix_t n1 n2 -> Stack unit (requires fun h0 -> live h0 a /\ live h0 c /\ a == c) (ensures fun h0 _ h1 -> modifies1 c h0 h1 /\ as_matrix h1 c == M.map #(v n1) #(v n2) f (as_matrix h0 a)) let map #n1 #n2 f a c = let h0 = ST.get () in Lib.Loops.for (size 0) n1 (fun h1 i -> live h1 a /\ live h1 c /\ modifies1 c h0 h1 /\ i <= v n1 /\ (forall (i0:nat{i0 < i}) (j:nat{j < v n2}). get h1 c i0 j == f (get h0 a i0 j)) /\ (forall (i0:nat{i <= i0 /\ i0 < v n1}) (j:nat{j < v n2}). get h1 c i0 j == get h0 c i0 j) ) (fun i -> let h1 = ST.get() in Lib.Loops.for (size 0) n2 (fun h2 j -> map_inner_inv h0 h1 h2 f a c i j) (fun j -> map_inner h0 h1 f a c i j) ); let h2 = ST.get () in M.extensionality (as_matrix h2 c) (M.map f (as_matrix h0 a)) inline_for_extraction noextract val mod_pow2_felem: logq:size_t{0 < v logq /\ v logq < 16} -> a:uint16 -> Pure uint16 (requires True) (ensures fun r -> r == M.mod_pow2_felem (v logq) a) let mod_pow2_felem logq a = a &. ((u16 1 <<. logq) -. u16 1) val mod_pow2: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> logq:size_t{0 < v logq /\ v logq <= 16} -> a:matrix_t n1 n2 -> Stack unit (requires fun h -> live h a) (ensures fun h0 _ h1 -> modifies1 a h0 h1 /\ as_matrix h1 a == M.mod_pow2 (v logq) (as_matrix h0 a)) [@"c_inline"] let mod_pow2 #n1 #n2 logq a = if logq <. 16ul then begin let h0 = ST.get () in map (mod_pow2_felem logq) a a; M.extensionality (M.map #(v n1) #(v n2) (mod_pow2_felem logq) (as_matrix h0 a)) (M.map #(v n1) #(v n2) (M.mod_pow2_felem (v logq)) (as_matrix h0 a)) end private unfold val map2_inner_inv: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> h2:HS.mem -> f:(elem -> elem -> elem) -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> c:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_nat -> Type0 let map2_inner_inv #n1 #n2 h0 h1 h2 f a b c i j = live h2 a /\ live h2 b /\ live h2 c /\ modifies1 c h1 h2 /\ j <= v n2 /\ (forall (i0:nat{i0 < v i}) (j:nat{j < v n2}). get h2 c i0 j == get h1 c i0 j) /\ (forall (j0:nat{j0 < j}). get h2 c (v i) j0 == f (get h0 a (v i) j0) (get h2 b (v i) j0)) /\ (forall (j0:nat{j <= j0 /\ j0 < v n2}). get h2 c (v i) j0 == get h0 c (v i) j0) /\ (forall (i0:nat{v i < i0 /\ i0 < v n1}) (j:nat{j < v n2}). get h2 c i0 j == get h0 c i0 j) inline_for_extraction noextract private val map2_inner: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> f:(elem -> elem -> elem) -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> c:matrix_t n1 n2{a == c /\ disjoint b c} -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> Stack unit (requires fun h2 -> map2_inner_inv h0 h1 h2 f a b c i (v j)) (ensures fun _ _ h2 -> map2_inner_inv h0 h1 h2 f a b c i (v j + 1)) let map2_inner #n1 #n2 h0 h1 f a b c i j = c.[i,j] <- f a.[i,j] b.[i,j] /// In-place [map2], a == map2 f a b /// /// A non in-place variant can be obtained by weakening the pre-condition to disjoint a c, /// or the two variants can be merged by requiring (a == c \/ disjoint a c) instead of a == c /// See commit 91916b8372fa3522061eff5a42d0ebd1d19a8a49 inline_for_extraction val map2: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> f:(uint16 -> uint16 -> uint16) -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> c:matrix_t n1 n2 -> Stack unit (requires fun h0 -> live h0 a /\ live h0 b /\ live h0 c /\ a == c /\ disjoint b c) (ensures fun h0 _ h1 -> modifies1 c h0 h1 /\ as_matrix h1 c == M.map2 #(v n1) #(v n2) f (as_matrix h0 a) (as_matrix h0 b)) let map2 #n1 #n2 f a b c = let h0 = ST.get () in Lib.Loops.for (size 0) n1 (fun h1 i -> live h1 a /\ live h1 b /\ live h1 c /\ modifies1 c h0 h1 /\ i <= v n1 /\ (forall (i0:nat{i0 < i}) (j:nat{j < v n2}). get h1 c i0 j == f (get h0 a i0 j) (get h0 b i0 j)) /\ (forall (i0:nat{i <= i0 /\ i0 < v n1}) (j:nat{j < v n2}). get h1 c i0 j == get h0 c i0 j) ) (fun i -> let h1 = ST.get() in Lib.Loops.for (size 0) n2 (fun h2 j -> map2_inner_inv h0 h1 h2 f a b c i j) (fun j -> map2_inner h0 h1 f a b c i j) ); let h2 = ST.get() in M.extensionality (as_matrix h2 c) (M.map2 f (as_matrix h0 a) (as_matrix h0 b)) val matrix_add: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> Stack unit (requires fun h -> live h a /\ live h b /\ disjoint a b) (ensures fun h0 r h1 -> modifies1 a h0 h1 /\ as_matrix h1 a == M.add (as_matrix h0 a) (as_matrix h0 b)) [@"c_inline"] let matrix_add #n1 #n2 a b = map2 add_mod a b a val matrix_sub: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> Stack unit (requires fun h -> live h a /\ live h b /\ disjoint a b) (ensures fun h0 r h1 -> modifies1 b h0 h1 /\ as_matrix h1 b == M.sub (as_matrix h0 a) (as_matrix h0 b)) [@"c_inline"] let matrix_sub #n1 #n2 a b = (* Use the in-place variant above by flipping the arguments of [sub_mod] *) (* Requires appplying extensionality *) let h0 = ST.get() in [@ inline_let ] let sub_mod_flipped x y = sub_mod y x in map2 sub_mod_flipped b a b; let h1 = ST.get() in M.extensionality (as_matrix h1 b) (M.sub (as_matrix h0 a) (as_matrix h0 b)) #push-options "--fuel 1" inline_for_extraction noextract private val mul_inner: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> #n3:size_t{v n2 * v n3 <= max_size_t /\ v n1 * v n3 <= max_size_t} -> a:matrix_t n1 n2 -> b:matrix_t n2 n3 -> i:size_t{v i < v n1} -> k:size_t{v k < v n3} -> Stack uint16 (requires fun h -> live h a /\ live h b) (ensures fun h0 r h1 -> modifies loc_none h0 h1 /\ r == M.mul_inner (as_matrix h0 a) (as_matrix h0 b) (v i) (v k)) let mul_inner #n1 #n2 #n3 a b i k = push_frame(); let h0 = ST.get() in [@ inline_let ] let f l = get h0 a (v i) l *. get h0 b l (v k) in let res = create #uint16 (size 1) (u16 0) in let h1 = ST.get() in Lib.Loops.for (size 0) n2 (fun h2 j -> live h1 res /\ live h2 res /\ modifies1 res h1 h2 /\ bget h2 res 0 == M.sum_ #(v n2) f j) (fun j -> let aij = a.[i,j] in let bjk = b.[j,k] in let res0 = res.(size 0) in res.(size 0) <- res0 +. aij *. bjk ); let res = res.(size 0) in M.sum_extensionality (v n2) f (fun l -> get h0 a (v i) l *. get h0 b l (v k)) (v n2); assert (res == M.mul_inner (as_matrix h0 a) (as_matrix h0 b) (v i) (v k)); pop_frame(); res #pop-options private unfold val mul_inner_inv: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> #n3:size_t{v n2 * v n3 <= max_size_t /\ v n1 * v n3 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> h2:HS.mem -> a:matrix_t n1 n2 -> b:matrix_t n2 n3 -> c:matrix_t n1 n3 -> f:(k:nat{k < v n3} -> GTot uint16) -> i:size_t{v i < v n1} -> k:size_nat -> Type0 let mul_inner_inv #n1 #n2 #n3 h0 h1 h2 a b c f i k = live h2 a /\ live h2 b /\ live h2 c /\ modifies1 c h1 h2 /\ k <= v n3 /\ (forall (i1:nat{i1 < v i}) (k:nat{k < v n3}). get h2 c i1 k == get h1 c i1 k) /\ (forall (k1:nat{k1 < k}). get h2 c (v i) k1 == f k1) /\ (forall (k1:nat{k <= k1 /\ k1 < v n3}). get h2 c (v i) k1 == get h0 c (v i) k1) /\ (forall (i1:nat{v i < i1 /\ i1 < v n1}) (k:nat{k < v n3}). get h2 c i1 k == get h0 c i1 k) /\ as_matrix h0 a == as_matrix h2 a /\ as_matrix h0 b == as_matrix h2 b inline_for_extraction noextract private val mul_inner1: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> #n3:size_t{v n2 * v n3 <= max_size_t /\ v n1 * v n3 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> a:matrix_t n1 n2 -> b:matrix_t n2 n3 -> c:matrix_t n1 n3{disjoint a c /\ disjoint b c} -> i:size_t{v i < v n1} -> k:size_t{v k < v n3} -> f:(k:nat{k < v n3} -> GTot (res:uint16{res == M.sum #(v n2) (fun l -> get h0 a (v i) l *. get h0 b l k)})) -> Stack unit (requires fun h2 -> mul_inner_inv h0 h1 h2 a b c f i (v k)) (ensures fun _ _ h2 -> mul_inner_inv h0 h1 h2 a b c f i (v k + 1))
false
false
Hacl.Impl.Matrix.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val mul_inner1: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> #n3:size_t{v n2 * v n3 <= max_size_t /\ v n1 * v n3 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> a:matrix_t n1 n2 -> b:matrix_t n2 n3 -> c:matrix_t n1 n3{disjoint a c /\ disjoint b c} -> i:size_t{v i < v n1} -> k:size_t{v k < v n3} -> f:(k:nat{k < v n3} -> GTot (res:uint16{res == M.sum #(v n2) (fun l -> get h0 a (v i) l *. get h0 b l k)})) -> Stack unit (requires fun h2 -> mul_inner_inv h0 h1 h2 a b c f i (v k)) (ensures fun _ _ h2 -> mul_inner_inv h0 h1 h2 a b c f i (v k + 1))
[]
Hacl.Impl.Matrix.mul_inner1
{ "file_name": "code/frodo/Hacl.Impl.Matrix.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
h0: FStar.Monotonic.HyperStack.mem -> h1: FStar.Monotonic.HyperStack.mem -> a: Hacl.Impl.Matrix.matrix_t n1 n2 -> b: Hacl.Impl.Matrix.matrix_t n2 n3 -> c: Hacl.Impl.Matrix.matrix_t n1 n3 {Lib.Buffer.disjoint a c /\ Lib.Buffer.disjoint b c} -> i: Lib.IntTypes.size_t{Lib.IntTypes.v i < Lib.IntTypes.v n1} -> k: Lib.IntTypes.size_t{Lib.IntTypes.v k < Lib.IntTypes.v n3} -> f: (k: Prims.nat{k < Lib.IntTypes.v n3} -> Prims.GTot (res: Lib.IntTypes.uint16 { res == Spec.Matrix.sum (fun l -> Hacl.Impl.Matrix.get h0 a (Lib.IntTypes.v i) l *. Hacl.Impl.Matrix.get h0 b l k) })) -> FStar.HyperStack.ST.Stack Prims.unit
{ "end_col": 42, "end_line": 429, "start_col": 2, "start_line": 425 }
FStar.HyperStack.ST.Stack
val matrix_from_lbytes: #n1:size_t -> #n2:size_t{2 * v n1 <= max_size_t /\ 2 * v n1 * v n2 <= max_size_t} -> b:lbytes (size 2 *! n1 *! n2) -> res:matrix_t n1 n2 -> Stack unit (requires fun h -> live h b /\ live h res /\ disjoint b res) (ensures fun h0 _ h1 -> modifies1 res h0 h1 /\ as_matrix h1 res == M.matrix_from_lbytes (v n1) (v n2) (as_seq h0 b))
[ { "abbrev": true, "full_module": "Spec.Frodo.Lemmas", "short_module": "Lemmas" }, { "abbrev": true, "full_module": "Spec.Matrix", "short_module": "M" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let matrix_from_lbytes #n1 #n2 b res = let h0 = ST.get () in assert (v n1 * v n2 <= max_size_t); fill h0 (n1 *! n2) res (fun h -> M.matrix_from_lbytes_f (v n1) (v n2) (as_seq h0 b)) (fun i -> assert (2 * v i + 2 <= 2 * v n1 * v n2); uint_from_bytes_le #U16 (sub b (2ul *! i) 2ul)); let h1 = ST.get () in M.extensionality (as_matrix h1 res) (M.matrix_from_lbytes (v n1) (v n2) (as_seq h0 b))
val matrix_from_lbytes: #n1:size_t -> #n2:size_t{2 * v n1 <= max_size_t /\ 2 * v n1 * v n2 <= max_size_t} -> b:lbytes (size 2 *! n1 *! n2) -> res:matrix_t n1 n2 -> Stack unit (requires fun h -> live h b /\ live h res /\ disjoint b res) (ensures fun h0 _ h1 -> modifies1 res h0 h1 /\ as_matrix h1 res == M.matrix_from_lbytes (v n1) (v n2) (as_seq h0 b)) let matrix_from_lbytes #n1 #n2 b res =
true
null
false
let h0 = ST.get () in assert (v n1 * v n2 <= max_size_t); fill h0 (n1 *! n2) res (fun h -> M.matrix_from_lbytes_f (v n1) (v n2) (as_seq h0 b)) (fun i -> assert (2 * v i + 2 <= (2 * v n1) * v n2); uint_from_bytes_le #U16 (sub b (2ul *! i) 2ul)); let h1 = ST.get () in M.extensionality (as_matrix h1 res) (M.matrix_from_lbytes (v n1) (v n2) (as_seq h0 b))
{ "checked_file": "Hacl.Impl.Matrix.fst.checked", "dependencies": [ "Spec.Matrix.fst.checked", "Spec.Frodo.Lemmas.fst.checked", "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.Loops.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Matrix.fst" }
[]
[ "Lib.IntTypes.size_t", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.Mul.op_Star", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Lib.IntTypes.max_size_t", "Hacl.Impl.Matrix.lbytes", "Lib.IntTypes.op_Star_Bang", "Lib.IntTypes.size", "Hacl.Impl.Matrix.matrix_t", "Spec.Matrix.extensionality", "Hacl.Impl.Matrix.as_matrix", "Spec.Matrix.matrix_from_lbytes", "Lib.Buffer.as_seq", "Lib.Buffer.MUT", "Lib.IntTypes.uint8", "Prims.unit", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "Lib.Buffer.fill", "Hacl.Impl.Matrix.elem", "Spec.Matrix.matrix_from_lbytes_f", "Lib.IntTypes.size_nat", "Prims.op_LessThan", "Lib.ByteBuffer.uint_from_bytes_le", "Lib.IntTypes.U16", "Lib.IntTypes.SEC", "Lib.IntTypes.uint_t", "Lib.Buffer.lbuffer_t", "Lib.IntTypes.int_t", "Lib.IntTypes.U8", "Lib.IntTypes.mk_int", "Lib.Buffer.sub", "FStar.UInt32.__uint_to_t", "Prims._assert", "Prims.op_Addition" ]
[]
module Hacl.Impl.Matrix open FStar.HyperStack.ST open FStar.Mul open LowStar.BufferOps open LowStar.Buffer open Lib.IntTypes open Lib.Buffer open Lib.ByteBuffer module HS = FStar.HyperStack module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module Loops = Lib.LoopCombinators module M = Spec.Matrix module Lemmas = Spec.Frodo.Lemmas #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" unfold let elem = uint16 unfold let lbytes len = lbuffer uint8 len unfold let matrix_t (n1:size_t) (n2:size_t{v n1 * v n2 <= max_size_t}) = lbuffer elem (n1 *! n2) unfold let as_matrix #n1 #n2 h (m:matrix_t n1 n2) : GTot (M.matrix (v n1) (v n2)) = as_seq h m inline_for_extraction noextract val matrix_create: n1:size_t -> n2:size_t{0 < v n1 * v n2 /\ v n1 * v n2 <= max_size_t} -> StackInline (matrix_t n1 n2) (requires fun h0 -> True) (ensures fun h0 a h1 -> stack_allocated a h0 h1 (as_matrix h1 a) /\ as_matrix h1 a == M.create (v n1) (v n2)) let matrix_create n1 n2 = [@inline_let] let len = size (normalize_term (v n1 * v n2)) in create len (u16 0) inline_for_extraction noextract val mget: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> Stack elem (requires fun h0 -> live h0 a) (ensures fun h0 x h1 -> modifies loc_none h0 h1 /\ x == M.mget (as_matrix h0 a) (v i) (v j)) let mget #n1 #n2 a i j = M.index_lt (v n1) (v n2) (v i) (v j); a.(i *! n2 +! j) inline_for_extraction noextract val mset: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> x:elem -> Stack unit (requires fun h0 -> live h0 a) (ensures fun h0 _ h1 -> modifies1 a h0 h1 /\ as_matrix h1 a == M.mset (as_matrix h0 a) (v i) (v j) x) let mset #n1 #n2 a i j x = M.index_lt (v n1) (v n2) (v i) (v j); a.(i *! n2 +! j) <- x noextract unfold val op_String_Access (#n1:size_t) (#n2:size_t{v n1 * v n2 <= max_size_t}) (m:matrix_t n1 n2) (ij:(size_t & size_t){let i, j = ij in v i < v n1 /\ v j < v n2}) : Stack elem (requires fun h0 -> live h0 m) (ensures fun h0 x h1 -> let i, j = ij in modifies loc_none h0 h1 /\ x == M.mget (as_matrix h0 m) (v i) (v j)) let op_String_Access #n1 #n2 m (i,j) = mget m i j noextract unfold val op_String_Assignment (#n1:size_t) (#n2:size_t{v n1 * v n2 <= max_size_t}) (m:matrix_t n1 n2) (ij:(size_t & size_t){let i, j = ij in v i < v n1 /\ v j < v n2}) (x:elem) : Stack unit (requires fun h0 -> live h0 m) (ensures fun h0 _ h1 -> let i, j = ij in modifies1 m h0 h1 /\ live h1 m /\ as_matrix h1 m == M.mset (as_matrix h0 m) (v i) (v j) x) let op_String_Assignment #n1 #n2 m (i,j) x = mset m i j x unfold let get #n1 #n2 h (m:matrix_t n1 n2) i j = M.mget (as_matrix h m) i j private unfold val map_inner_inv: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> h2:HS.mem -> f:(elem -> elem) -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_nat -> Type0 let map_inner_inv #n1 #n2 h0 h1 h2 f a c i j = live h2 a /\ live h2 c /\ modifies1 c h1 h2 /\ j <= v n2 /\ (forall (i0:nat{i0 < v i}) (j:nat{j < v n2}). get h2 c i0 j == get h1 c i0 j) /\ (forall (j0:nat{j0 < j}). get h2 c (v i) j0 == f (get h0 a (v i) j0)) /\ (forall (j0:nat{j <= j0 /\ j0 < v n2}). get h2 c (v i) j0 == get h0 c (v i) j0) /\ (forall (i0:nat{v i < i0 /\ i0 < v n1}) (j:nat{j < v n2}). get h2 c i0 j == get h0 c i0 j) inline_for_extraction noextract private val map_inner: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> f:(elem -> elem) -> a:matrix_t n1 n2 -> c:matrix_t n1 n2{a == c} -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> Stack unit (requires fun h2 -> map_inner_inv h0 h1 h2 f a c i (v j)) (ensures fun _ _ h2 -> map_inner_inv h0 h1 h2 f a c i (v j + 1)) let map_inner #n1 #n2 h0 h1 f a c i j = c.[i,j] <- f a.[i,j] inline_for_extraction val map: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> f:(uint16 -> uint16) -> a:matrix_t n1 n2 -> c:matrix_t n1 n2 -> Stack unit (requires fun h0 -> live h0 a /\ live h0 c /\ a == c) (ensures fun h0 _ h1 -> modifies1 c h0 h1 /\ as_matrix h1 c == M.map #(v n1) #(v n2) f (as_matrix h0 a)) let map #n1 #n2 f a c = let h0 = ST.get () in Lib.Loops.for (size 0) n1 (fun h1 i -> live h1 a /\ live h1 c /\ modifies1 c h0 h1 /\ i <= v n1 /\ (forall (i0:nat{i0 < i}) (j:nat{j < v n2}). get h1 c i0 j == f (get h0 a i0 j)) /\ (forall (i0:nat{i <= i0 /\ i0 < v n1}) (j:nat{j < v n2}). get h1 c i0 j == get h0 c i0 j) ) (fun i -> let h1 = ST.get() in Lib.Loops.for (size 0) n2 (fun h2 j -> map_inner_inv h0 h1 h2 f a c i j) (fun j -> map_inner h0 h1 f a c i j) ); let h2 = ST.get () in M.extensionality (as_matrix h2 c) (M.map f (as_matrix h0 a)) inline_for_extraction noextract val mod_pow2_felem: logq:size_t{0 < v logq /\ v logq < 16} -> a:uint16 -> Pure uint16 (requires True) (ensures fun r -> r == M.mod_pow2_felem (v logq) a) let mod_pow2_felem logq a = a &. ((u16 1 <<. logq) -. u16 1) val mod_pow2: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> logq:size_t{0 < v logq /\ v logq <= 16} -> a:matrix_t n1 n2 -> Stack unit (requires fun h -> live h a) (ensures fun h0 _ h1 -> modifies1 a h0 h1 /\ as_matrix h1 a == M.mod_pow2 (v logq) (as_matrix h0 a)) [@"c_inline"] let mod_pow2 #n1 #n2 logq a = if logq <. 16ul then begin let h0 = ST.get () in map (mod_pow2_felem logq) a a; M.extensionality (M.map #(v n1) #(v n2) (mod_pow2_felem logq) (as_matrix h0 a)) (M.map #(v n1) #(v n2) (M.mod_pow2_felem (v logq)) (as_matrix h0 a)) end private unfold val map2_inner_inv: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> h2:HS.mem -> f:(elem -> elem -> elem) -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> c:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_nat -> Type0 let map2_inner_inv #n1 #n2 h0 h1 h2 f a b c i j = live h2 a /\ live h2 b /\ live h2 c /\ modifies1 c h1 h2 /\ j <= v n2 /\ (forall (i0:nat{i0 < v i}) (j:nat{j < v n2}). get h2 c i0 j == get h1 c i0 j) /\ (forall (j0:nat{j0 < j}). get h2 c (v i) j0 == f (get h0 a (v i) j0) (get h2 b (v i) j0)) /\ (forall (j0:nat{j <= j0 /\ j0 < v n2}). get h2 c (v i) j0 == get h0 c (v i) j0) /\ (forall (i0:nat{v i < i0 /\ i0 < v n1}) (j:nat{j < v n2}). get h2 c i0 j == get h0 c i0 j) inline_for_extraction noextract private val map2_inner: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> f:(elem -> elem -> elem) -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> c:matrix_t n1 n2{a == c /\ disjoint b c} -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> Stack unit (requires fun h2 -> map2_inner_inv h0 h1 h2 f a b c i (v j)) (ensures fun _ _ h2 -> map2_inner_inv h0 h1 h2 f a b c i (v j + 1)) let map2_inner #n1 #n2 h0 h1 f a b c i j = c.[i,j] <- f a.[i,j] b.[i,j] /// In-place [map2], a == map2 f a b /// /// A non in-place variant can be obtained by weakening the pre-condition to disjoint a c, /// or the two variants can be merged by requiring (a == c \/ disjoint a c) instead of a == c /// See commit 91916b8372fa3522061eff5a42d0ebd1d19a8a49 inline_for_extraction val map2: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> f:(uint16 -> uint16 -> uint16) -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> c:matrix_t n1 n2 -> Stack unit (requires fun h0 -> live h0 a /\ live h0 b /\ live h0 c /\ a == c /\ disjoint b c) (ensures fun h0 _ h1 -> modifies1 c h0 h1 /\ as_matrix h1 c == M.map2 #(v n1) #(v n2) f (as_matrix h0 a) (as_matrix h0 b)) let map2 #n1 #n2 f a b c = let h0 = ST.get () in Lib.Loops.for (size 0) n1 (fun h1 i -> live h1 a /\ live h1 b /\ live h1 c /\ modifies1 c h0 h1 /\ i <= v n1 /\ (forall (i0:nat{i0 < i}) (j:nat{j < v n2}). get h1 c i0 j == f (get h0 a i0 j) (get h0 b i0 j)) /\ (forall (i0:nat{i <= i0 /\ i0 < v n1}) (j:nat{j < v n2}). get h1 c i0 j == get h0 c i0 j) ) (fun i -> let h1 = ST.get() in Lib.Loops.for (size 0) n2 (fun h2 j -> map2_inner_inv h0 h1 h2 f a b c i j) (fun j -> map2_inner h0 h1 f a b c i j) ); let h2 = ST.get() in M.extensionality (as_matrix h2 c) (M.map2 f (as_matrix h0 a) (as_matrix h0 b)) val matrix_add: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> Stack unit (requires fun h -> live h a /\ live h b /\ disjoint a b) (ensures fun h0 r h1 -> modifies1 a h0 h1 /\ as_matrix h1 a == M.add (as_matrix h0 a) (as_matrix h0 b)) [@"c_inline"] let matrix_add #n1 #n2 a b = map2 add_mod a b a val matrix_sub: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> Stack unit (requires fun h -> live h a /\ live h b /\ disjoint a b) (ensures fun h0 r h1 -> modifies1 b h0 h1 /\ as_matrix h1 b == M.sub (as_matrix h0 a) (as_matrix h0 b)) [@"c_inline"] let matrix_sub #n1 #n2 a b = (* Use the in-place variant above by flipping the arguments of [sub_mod] *) (* Requires appplying extensionality *) let h0 = ST.get() in [@ inline_let ] let sub_mod_flipped x y = sub_mod y x in map2 sub_mod_flipped b a b; let h1 = ST.get() in M.extensionality (as_matrix h1 b) (M.sub (as_matrix h0 a) (as_matrix h0 b)) #push-options "--fuel 1" inline_for_extraction noextract private val mul_inner: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> #n3:size_t{v n2 * v n3 <= max_size_t /\ v n1 * v n3 <= max_size_t} -> a:matrix_t n1 n2 -> b:matrix_t n2 n3 -> i:size_t{v i < v n1} -> k:size_t{v k < v n3} -> Stack uint16 (requires fun h -> live h a /\ live h b) (ensures fun h0 r h1 -> modifies loc_none h0 h1 /\ r == M.mul_inner (as_matrix h0 a) (as_matrix h0 b) (v i) (v k)) let mul_inner #n1 #n2 #n3 a b i k = push_frame(); let h0 = ST.get() in [@ inline_let ] let f l = get h0 a (v i) l *. get h0 b l (v k) in let res = create #uint16 (size 1) (u16 0) in let h1 = ST.get() in Lib.Loops.for (size 0) n2 (fun h2 j -> live h1 res /\ live h2 res /\ modifies1 res h1 h2 /\ bget h2 res 0 == M.sum_ #(v n2) f j) (fun j -> let aij = a.[i,j] in let bjk = b.[j,k] in let res0 = res.(size 0) in res.(size 0) <- res0 +. aij *. bjk ); let res = res.(size 0) in M.sum_extensionality (v n2) f (fun l -> get h0 a (v i) l *. get h0 b l (v k)) (v n2); assert (res == M.mul_inner (as_matrix h0 a) (as_matrix h0 b) (v i) (v k)); pop_frame(); res #pop-options private unfold val mul_inner_inv: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> #n3:size_t{v n2 * v n3 <= max_size_t /\ v n1 * v n3 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> h2:HS.mem -> a:matrix_t n1 n2 -> b:matrix_t n2 n3 -> c:matrix_t n1 n3 -> f:(k:nat{k < v n3} -> GTot uint16) -> i:size_t{v i < v n1} -> k:size_nat -> Type0 let mul_inner_inv #n1 #n2 #n3 h0 h1 h2 a b c f i k = live h2 a /\ live h2 b /\ live h2 c /\ modifies1 c h1 h2 /\ k <= v n3 /\ (forall (i1:nat{i1 < v i}) (k:nat{k < v n3}). get h2 c i1 k == get h1 c i1 k) /\ (forall (k1:nat{k1 < k}). get h2 c (v i) k1 == f k1) /\ (forall (k1:nat{k <= k1 /\ k1 < v n3}). get h2 c (v i) k1 == get h0 c (v i) k1) /\ (forall (i1:nat{v i < i1 /\ i1 < v n1}) (k:nat{k < v n3}). get h2 c i1 k == get h0 c i1 k) /\ as_matrix h0 a == as_matrix h2 a /\ as_matrix h0 b == as_matrix h2 b inline_for_extraction noextract private val mul_inner1: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> #n3:size_t{v n2 * v n3 <= max_size_t /\ v n1 * v n3 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> a:matrix_t n1 n2 -> b:matrix_t n2 n3 -> c:matrix_t n1 n3{disjoint a c /\ disjoint b c} -> i:size_t{v i < v n1} -> k:size_t{v k < v n3} -> f:(k:nat{k < v n3} -> GTot (res:uint16{res == M.sum #(v n2) (fun l -> get h0 a (v i) l *. get h0 b l k)})) -> Stack unit (requires fun h2 -> mul_inner_inv h0 h1 h2 a b c f i (v k)) (ensures fun _ _ h2 -> mul_inner_inv h0 h1 h2 a b c f i (v k + 1)) let mul_inner1 #n1 #n2 #n3 h0 h1 a b c i k f = assert (M.mul_inner (as_matrix h0 a) (as_matrix h0 b) (v i) (v k) == M.sum #(v n2) (fun l -> get h0 a (v i) l *. get h0 b l (v k))); c.[i,k] <- mul_inner a b i k; let h2 = ST.get () in assert (get h2 c (v i) (v k) == f (v k)) private val onemore: p:(nat -> Type0) -> q:(i:nat{p i} -> Type0) -> b:nat{p b} -> Lemma (requires (forall (i:nat{p i /\ i < b}). q i) /\ q b) (ensures forall (i:nat{p i /\ i <= b}). q i) let onemore p q b = () val onemore1: #n1:size_nat -> #n3:size_nat{n1 * n3 <= max_size_t} -> c:M.matrix n1 n3 -> f:(i:nat{i < n1} -> k:nat{k < n3} -> GTot uint16) -> i:size_nat{i < n1} -> Lemma (requires ((forall (i1:nat{i1 < i}) (k:nat{k < n3}). M.mget c i1 k == f i1 k) /\ (forall (k:nat{k < n3}). M.mget c i k == f i k))) (ensures (forall (i1:nat{i1 <= i}) (k:nat{k < n3}). M.mget c i1 k == f i1 k)) let onemore1 #n1 #n3 c f i = () val matrix_mul: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> #n3:size_t{v n2 * v n3 <= max_size_t /\ v n1 * v n3 <= max_size_t} -> a:matrix_t n1 n2 -> b:matrix_t n2 n3 -> c:matrix_t n1 n3 -> Stack unit (requires fun h -> live h a /\ live h b /\ live h c /\ disjoint a c /\ disjoint b c) (ensures fun h0 _ h1 -> modifies1 c h0 h1 /\ as_matrix h1 c == M.mul (as_matrix h0 a) (as_matrix h0 b)) [@"c_inline"] let matrix_mul #n1 #n2 #n3 a b c = let h0 = ST.get () in let f (i:nat{i < v n1}) (k:nat{k < v n3}) : GTot (res:uint16{res == M.sum #(v n2) (fun l -> get h0 a i l *. get h0 b l k)}) = M.sum #(v n2) (fun l -> get h0 a i l *. get h0 b l k) in Lib.Loops.for (size 0) n1 (fun h1 i -> live h1 a /\ live h1 b /\ live h1 c /\ modifies1 c h0 h1 /\ i <= v n1 /\ (forall (i1:nat{i1 < i}) (k:nat{k < v n3}). get h1 c i1 k == f i1 k) /\ (forall (i1:nat{i <= i1 /\ i1 < v n1}) (k:nat{k < v n3}). get h1 c i1 k == get h0 c i1 k)) (fun i -> let h1 = ST.get() in Lib.Loops.for (size 0) n3 (fun h2 k -> mul_inner_inv h0 h1 h2 a b c (f (v i)) i k) (fun k -> mul_inner1 h0 h1 a b c i k (f (v i))); let h1 = ST.get() in let q i1 = forall (k:nat{k < v n3}). get h1 c i1 k == f i1 k in onemore (fun i1 -> i1 < v n1) q (v i); assert (forall (i1:nat{i1 < v n1 /\ i1 <= v i}) (k:nat{k < v n3}). get h1 c i1 k == f i1 k) ); let h2 = ST.get() in M.extensionality (as_matrix h2 c) (M.mul (as_matrix h0 a) (as_matrix h0 b)) (* Special case of matrix multiplication *) (* when we have a different way of accessing to entries of the matrix S *) inline_for_extraction noextract val mget_s: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> Stack elem (requires fun h0 -> live h0 a) (ensures fun h0 x h1 -> modifies0 h0 h1 /\ x == M.mget_s (as_matrix h0 a) (v i) (v j)) let mget_s #n1 #n2 a i j = M.index_lt (v n2) (v n1) (v j) (v i); a.(j *! n1 +! i) unfold let get_s #n1 #n2 h (m:matrix_t n1 n2) i j = M.mget_s (as_matrix h m) i j #push-options "--fuel 1" inline_for_extraction noextract private val mul_inner_s: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> #n3:size_t{v n2 * v n3 <= max_size_t /\ v n1 * v n3 <= max_size_t} -> a:matrix_t n1 n2 -> b:matrix_t n2 n3 -> i:size_t{v i < v n1} -> k:size_t{v k < v n3} -> Stack uint16 (requires fun h -> live h a /\ live h b) (ensures fun h0 r h1 -> modifies0 h0 h1 /\ r == M.mul_inner_s (as_matrix h0 a) (as_matrix h0 b) (v i) (v k)) let mul_inner_s #n1 #n2 #n3 a b i k = push_frame(); let h0 = ST.get() in [@ inline_let ] let f l = get h0 a (v i) l *. get_s h0 b l (v k) in let res = create #uint16 (size 1) (u16 0) in let h1 = ST.get() in Lib.Loops.for (size 0) n2 (fun h2 j -> live h1 res /\ live h2 res /\ modifies1 res h1 h2 /\ bget h2 res 0 == M.sum_ #(v n2) f j) (fun j -> let aij = mget a i j in let bjk = mget_s b j k in let res0 = res.(size 0) in res.(size 0) <- res0 +. aij *. bjk ); let res = res.(size 0) in M.sum_extensionality (v n2) f (fun l -> get h0 a (v i) l *. get_s h0 b l (v k)) (v n2); assert (res == M.mul_inner_s (as_matrix h0 a) (as_matrix h0 b) (v i) (v k)); pop_frame(); res #pop-options inline_for_extraction noextract private val mul_inner1_s: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> #n3:size_t{v n2 * v n3 <= max_size_t /\ v n1 * v n3 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> a:matrix_t n1 n2 -> b:matrix_t n2 n3 -> c:matrix_t n1 n3{disjoint a c /\ disjoint b c} -> i:size_t{v i < v n1} -> k:size_t{v k < v n3} -> f:(k:nat{k < v n3} -> GTot (res:uint16{res == M.sum #(v n2) (fun l -> get h0 a (v i) l *. get_s h0 b l k)})) -> Stack unit (requires fun h2 -> mul_inner_inv h0 h1 h2 a b c f i (v k)) (ensures fun _ _ h2 -> mul_inner_inv h0 h1 h2 a b c f i (v k + 1)) let mul_inner1_s #n1 #n2 #n3 h0 h1 a b c i k f = assert (M.mul_inner_s (as_matrix h0 a) (as_matrix h0 b) (v i) (v k) == M.sum #(v n2) (fun l -> get h0 a (v i) l *. get_s h0 b l (v k))); mset c i k (mul_inner_s a b i k); let h2 = ST.get () in assert (get h2 c (v i) (v k) == f (v k)) val matrix_mul_s: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> #n3:size_t{v n2 * v n3 <= max_size_t /\ v n1 * v n3 <= max_size_t} -> a:matrix_t n1 n2 -> b:matrix_t n2 n3 -> c:matrix_t n1 n3 -> Stack unit (requires fun h -> live h a /\ live h b /\ live h c /\ disjoint a c /\ disjoint b c) (ensures fun h0 _ h1 -> modifies1 c h0 h1 /\ as_matrix h1 c == M.mul_s (as_matrix h0 a) (as_matrix h0 b)) [@"c_inline"] let matrix_mul_s #n1 #n2 #n3 a b c = let h0 = ST.get () in let f (i:nat{i < v n1}) (k:nat{k < v n3}) : GTot (res:uint16{res == M.sum #(v n2) (fun l -> get h0 a i l *. get_s h0 b l k)}) = M.sum #(v n2) (fun l -> get h0 a i l *. get_s h0 b l k) in Lib.Loops.for (size 0) n1 (fun h1 i -> live h1 a /\ live h1 b /\ live h1 c /\ modifies1 c h0 h1 /\ i <= v n1 /\ (forall (i1:nat{i1 < i}) (k:nat{k < v n3}). get h1 c i1 k == f i1 k) /\ (forall (i1:nat{i <= i1 /\ i1 < v n1}) (k:nat{k < v n3}). get h1 c i1 k == get h0 c i1 k)) (fun i -> let h1 = ST.get() in Lib.Loops.for (size 0) n3 (fun h2 k -> mul_inner_inv h0 h1 h2 a b c (f (v i)) i k) (fun k -> mul_inner1_s h0 h1 a b c i k (f (v i))); let h1 = ST.get() in let q i1 = forall k. get h1 c i1 k == f i1 k in onemore (fun i1 -> i1 < v n1) q (v i); assert (forall (i1:nat{i1 < v n1 /\ i1 <= v i}) (k:nat{k < v n3}). get h1 c i1 k == f i1 k) ); let h2 = ST.get() in M.extensionality (as_matrix h2 c) (M.mul_s (as_matrix h0 a) (as_matrix h0 b)) (* the end of the special matrix multiplication *) val matrix_eq: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> Stack uint16 (requires fun h -> live h a /\ live h b) (ensures fun h0 r h1 -> modifies0 h0 h1 /\ r == M.matrix_eq #(v n1) #(v n2) (as_matrix h0 a) (as_matrix h0 b)) [@"c_inline"] let matrix_eq #n1 #n2 a b = push_frame(); let res = create 1ul (ones U16 SEC) in let r = buf_eq_mask a b (n1 *! n2) res in pop_frame (); r val matrix_to_lbytes: #n1:size_t -> #n2:size_t{2 * v n1 <= max_size_t /\ 2 * v n1 * v n2 <= max_size_t} -> m:matrix_t n1 n2 -> res:lbytes (2ul *! n1 *! n2) -> Stack unit (requires fun h -> live h m /\ live h res /\ disjoint m res) (ensures fun h0 r h1 -> modifies1 res h0 h1 /\ as_seq h1 res == M.matrix_to_lbytes #(v n1) #(v n2) (as_matrix h0 m)) [@"c_inline"] let matrix_to_lbytes #n1 #n2 m res = let h0 = ST.get () in fill_blocks_simple h0 2ul (n1 *! n2) res (fun h -> M.matrix_to_lbytes_f #(v n1) #(v n2) (as_matrix h0 m)) (fun i -> uint_to_bytes_le (sub res (2ul *! i) 2ul) m.(i)) val matrix_from_lbytes: #n1:size_t -> #n2:size_t{2 * v n1 <= max_size_t /\ 2 * v n1 * v n2 <= max_size_t} -> b:lbytes (size 2 *! n1 *! n2) -> res:matrix_t n1 n2 -> Stack unit (requires fun h -> live h b /\ live h res /\ disjoint b res) (ensures fun h0 _ h1 -> modifies1 res h0 h1 /\ as_matrix h1 res == M.matrix_from_lbytes (v n1) (v n2) (as_seq h0 b))
false
false
Hacl.Impl.Matrix.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val matrix_from_lbytes: #n1:size_t -> #n2:size_t{2 * v n1 <= max_size_t /\ 2 * v n1 * v n2 <= max_size_t} -> b:lbytes (size 2 *! n1 *! n2) -> res:matrix_t n1 n2 -> Stack unit (requires fun h -> live h b /\ live h res /\ disjoint b res) (ensures fun h0 _ h1 -> modifies1 res h0 h1 /\ as_matrix h1 res == M.matrix_from_lbytes (v n1) (v n2) (as_seq h0 b))
[]
Hacl.Impl.Matrix.matrix_from_lbytes
{ "file_name": "code/frodo/Hacl.Impl.Matrix.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
b: Hacl.Impl.Matrix.lbytes (Lib.IntTypes.size 2 *! n1 *! n2) -> res: Hacl.Impl.Matrix.matrix_t n1 n2 -> FStar.HyperStack.ST.Stack Prims.unit
{ "end_col": 88, "end_line": 679, "start_col": 38, "start_line": 670 }
FStar.HyperStack.ST.Stack
val matrix_to_lbytes: #n1:size_t -> #n2:size_t{2 * v n1 <= max_size_t /\ 2 * v n1 * v n2 <= max_size_t} -> m:matrix_t n1 n2 -> res:lbytes (2ul *! n1 *! n2) -> Stack unit (requires fun h -> live h m /\ live h res /\ disjoint m res) (ensures fun h0 r h1 -> modifies1 res h0 h1 /\ as_seq h1 res == M.matrix_to_lbytes #(v n1) #(v n2) (as_matrix h0 m))
[ { "abbrev": true, "full_module": "Spec.Frodo.Lemmas", "short_module": "Lemmas" }, { "abbrev": true, "full_module": "Spec.Matrix", "short_module": "M" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let matrix_to_lbytes #n1 #n2 m res = let h0 = ST.get () in fill_blocks_simple h0 2ul (n1 *! n2) res (fun h -> M.matrix_to_lbytes_f #(v n1) #(v n2) (as_matrix h0 m)) (fun i -> uint_to_bytes_le (sub res (2ul *! i) 2ul) m.(i))
val matrix_to_lbytes: #n1:size_t -> #n2:size_t{2 * v n1 <= max_size_t /\ 2 * v n1 * v n2 <= max_size_t} -> m:matrix_t n1 n2 -> res:lbytes (2ul *! n1 *! n2) -> Stack unit (requires fun h -> live h m /\ live h res /\ disjoint m res) (ensures fun h0 r h1 -> modifies1 res h0 h1 /\ as_seq h1 res == M.matrix_to_lbytes #(v n1) #(v n2) (as_matrix h0 m)) let matrix_to_lbytes #n1 #n2 m res =
true
null
false
let h0 = ST.get () in fill_blocks_simple h0 2ul (n1 *! n2) res (fun h -> M.matrix_to_lbytes_f #(v n1) #(v n2) (as_matrix h0 m)) (fun i -> uint_to_bytes_le (sub res (2ul *! i) 2ul) m.(i))
{ "checked_file": "Hacl.Impl.Matrix.fst.checked", "dependencies": [ "Spec.Matrix.fst.checked", "Spec.Frodo.Lemmas.fst.checked", "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.Loops.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Matrix.fst" }
[]
[ "Lib.IntTypes.size_t", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.Mul.op_Star", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Lib.IntTypes.max_size_t", "Hacl.Impl.Matrix.matrix_t", "Hacl.Impl.Matrix.lbytes", "Lib.IntTypes.op_Star_Bang", "FStar.UInt32.__uint_to_t", "Lib.Buffer.fill_blocks_simple", "Lib.IntTypes.uint8", "FStar.Monotonic.HyperStack.mem", "Spec.Matrix.matrix_to_lbytes_f", "Hacl.Impl.Matrix.as_matrix", "Lib.IntTypes.size_nat", "Prims.op_LessThan", "Lib.Sequence.lseq", "Lib.ByteBuffer.uint_to_bytes_le", "Lib.IntTypes.U16", "Lib.IntTypes.SEC", "Prims.unit", "Lib.IntTypes.int_t", "Lib.Buffer.op_Array_Access", "Lib.Buffer.MUT", "Hacl.Impl.Matrix.elem", "Lib.Buffer.lbuffer_t", "Lib.IntTypes.U8", "Lib.IntTypes.mk_int", "Lib.Buffer.sub", "FStar.HyperStack.ST.get" ]
[]
module Hacl.Impl.Matrix open FStar.HyperStack.ST open FStar.Mul open LowStar.BufferOps open LowStar.Buffer open Lib.IntTypes open Lib.Buffer open Lib.ByteBuffer module HS = FStar.HyperStack module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module Loops = Lib.LoopCombinators module M = Spec.Matrix module Lemmas = Spec.Frodo.Lemmas #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" unfold let elem = uint16 unfold let lbytes len = lbuffer uint8 len unfold let matrix_t (n1:size_t) (n2:size_t{v n1 * v n2 <= max_size_t}) = lbuffer elem (n1 *! n2) unfold let as_matrix #n1 #n2 h (m:matrix_t n1 n2) : GTot (M.matrix (v n1) (v n2)) = as_seq h m inline_for_extraction noextract val matrix_create: n1:size_t -> n2:size_t{0 < v n1 * v n2 /\ v n1 * v n2 <= max_size_t} -> StackInline (matrix_t n1 n2) (requires fun h0 -> True) (ensures fun h0 a h1 -> stack_allocated a h0 h1 (as_matrix h1 a) /\ as_matrix h1 a == M.create (v n1) (v n2)) let matrix_create n1 n2 = [@inline_let] let len = size (normalize_term (v n1 * v n2)) in create len (u16 0) inline_for_extraction noextract val mget: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> Stack elem (requires fun h0 -> live h0 a) (ensures fun h0 x h1 -> modifies loc_none h0 h1 /\ x == M.mget (as_matrix h0 a) (v i) (v j)) let mget #n1 #n2 a i j = M.index_lt (v n1) (v n2) (v i) (v j); a.(i *! n2 +! j) inline_for_extraction noextract val mset: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> x:elem -> Stack unit (requires fun h0 -> live h0 a) (ensures fun h0 _ h1 -> modifies1 a h0 h1 /\ as_matrix h1 a == M.mset (as_matrix h0 a) (v i) (v j) x) let mset #n1 #n2 a i j x = M.index_lt (v n1) (v n2) (v i) (v j); a.(i *! n2 +! j) <- x noextract unfold val op_String_Access (#n1:size_t) (#n2:size_t{v n1 * v n2 <= max_size_t}) (m:matrix_t n1 n2) (ij:(size_t & size_t){let i, j = ij in v i < v n1 /\ v j < v n2}) : Stack elem (requires fun h0 -> live h0 m) (ensures fun h0 x h1 -> let i, j = ij in modifies loc_none h0 h1 /\ x == M.mget (as_matrix h0 m) (v i) (v j)) let op_String_Access #n1 #n2 m (i,j) = mget m i j noextract unfold val op_String_Assignment (#n1:size_t) (#n2:size_t{v n1 * v n2 <= max_size_t}) (m:matrix_t n1 n2) (ij:(size_t & size_t){let i, j = ij in v i < v n1 /\ v j < v n2}) (x:elem) : Stack unit (requires fun h0 -> live h0 m) (ensures fun h0 _ h1 -> let i, j = ij in modifies1 m h0 h1 /\ live h1 m /\ as_matrix h1 m == M.mset (as_matrix h0 m) (v i) (v j) x) let op_String_Assignment #n1 #n2 m (i,j) x = mset m i j x unfold let get #n1 #n2 h (m:matrix_t n1 n2) i j = M.mget (as_matrix h m) i j private unfold val map_inner_inv: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> h2:HS.mem -> f:(elem -> elem) -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_nat -> Type0 let map_inner_inv #n1 #n2 h0 h1 h2 f a c i j = live h2 a /\ live h2 c /\ modifies1 c h1 h2 /\ j <= v n2 /\ (forall (i0:nat{i0 < v i}) (j:nat{j < v n2}). get h2 c i0 j == get h1 c i0 j) /\ (forall (j0:nat{j0 < j}). get h2 c (v i) j0 == f (get h0 a (v i) j0)) /\ (forall (j0:nat{j <= j0 /\ j0 < v n2}). get h2 c (v i) j0 == get h0 c (v i) j0) /\ (forall (i0:nat{v i < i0 /\ i0 < v n1}) (j:nat{j < v n2}). get h2 c i0 j == get h0 c i0 j) inline_for_extraction noextract private val map_inner: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> f:(elem -> elem) -> a:matrix_t n1 n2 -> c:matrix_t n1 n2{a == c} -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> Stack unit (requires fun h2 -> map_inner_inv h0 h1 h2 f a c i (v j)) (ensures fun _ _ h2 -> map_inner_inv h0 h1 h2 f a c i (v j + 1)) let map_inner #n1 #n2 h0 h1 f a c i j = c.[i,j] <- f a.[i,j] inline_for_extraction val map: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> f:(uint16 -> uint16) -> a:matrix_t n1 n2 -> c:matrix_t n1 n2 -> Stack unit (requires fun h0 -> live h0 a /\ live h0 c /\ a == c) (ensures fun h0 _ h1 -> modifies1 c h0 h1 /\ as_matrix h1 c == M.map #(v n1) #(v n2) f (as_matrix h0 a)) let map #n1 #n2 f a c = let h0 = ST.get () in Lib.Loops.for (size 0) n1 (fun h1 i -> live h1 a /\ live h1 c /\ modifies1 c h0 h1 /\ i <= v n1 /\ (forall (i0:nat{i0 < i}) (j:nat{j < v n2}). get h1 c i0 j == f (get h0 a i0 j)) /\ (forall (i0:nat{i <= i0 /\ i0 < v n1}) (j:nat{j < v n2}). get h1 c i0 j == get h0 c i0 j) ) (fun i -> let h1 = ST.get() in Lib.Loops.for (size 0) n2 (fun h2 j -> map_inner_inv h0 h1 h2 f a c i j) (fun j -> map_inner h0 h1 f a c i j) ); let h2 = ST.get () in M.extensionality (as_matrix h2 c) (M.map f (as_matrix h0 a)) inline_for_extraction noextract val mod_pow2_felem: logq:size_t{0 < v logq /\ v logq < 16} -> a:uint16 -> Pure uint16 (requires True) (ensures fun r -> r == M.mod_pow2_felem (v logq) a) let mod_pow2_felem logq a = a &. ((u16 1 <<. logq) -. u16 1) val mod_pow2: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> logq:size_t{0 < v logq /\ v logq <= 16} -> a:matrix_t n1 n2 -> Stack unit (requires fun h -> live h a) (ensures fun h0 _ h1 -> modifies1 a h0 h1 /\ as_matrix h1 a == M.mod_pow2 (v logq) (as_matrix h0 a)) [@"c_inline"] let mod_pow2 #n1 #n2 logq a = if logq <. 16ul then begin let h0 = ST.get () in map (mod_pow2_felem logq) a a; M.extensionality (M.map #(v n1) #(v n2) (mod_pow2_felem logq) (as_matrix h0 a)) (M.map #(v n1) #(v n2) (M.mod_pow2_felem (v logq)) (as_matrix h0 a)) end private unfold val map2_inner_inv: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> h2:HS.mem -> f:(elem -> elem -> elem) -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> c:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_nat -> Type0 let map2_inner_inv #n1 #n2 h0 h1 h2 f a b c i j = live h2 a /\ live h2 b /\ live h2 c /\ modifies1 c h1 h2 /\ j <= v n2 /\ (forall (i0:nat{i0 < v i}) (j:nat{j < v n2}). get h2 c i0 j == get h1 c i0 j) /\ (forall (j0:nat{j0 < j}). get h2 c (v i) j0 == f (get h0 a (v i) j0) (get h2 b (v i) j0)) /\ (forall (j0:nat{j <= j0 /\ j0 < v n2}). get h2 c (v i) j0 == get h0 c (v i) j0) /\ (forall (i0:nat{v i < i0 /\ i0 < v n1}) (j:nat{j < v n2}). get h2 c i0 j == get h0 c i0 j) inline_for_extraction noextract private val map2_inner: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> f:(elem -> elem -> elem) -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> c:matrix_t n1 n2{a == c /\ disjoint b c} -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> Stack unit (requires fun h2 -> map2_inner_inv h0 h1 h2 f a b c i (v j)) (ensures fun _ _ h2 -> map2_inner_inv h0 h1 h2 f a b c i (v j + 1)) let map2_inner #n1 #n2 h0 h1 f a b c i j = c.[i,j] <- f a.[i,j] b.[i,j] /// In-place [map2], a == map2 f a b /// /// A non in-place variant can be obtained by weakening the pre-condition to disjoint a c, /// or the two variants can be merged by requiring (a == c \/ disjoint a c) instead of a == c /// See commit 91916b8372fa3522061eff5a42d0ebd1d19a8a49 inline_for_extraction val map2: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> f:(uint16 -> uint16 -> uint16) -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> c:matrix_t n1 n2 -> Stack unit (requires fun h0 -> live h0 a /\ live h0 b /\ live h0 c /\ a == c /\ disjoint b c) (ensures fun h0 _ h1 -> modifies1 c h0 h1 /\ as_matrix h1 c == M.map2 #(v n1) #(v n2) f (as_matrix h0 a) (as_matrix h0 b)) let map2 #n1 #n2 f a b c = let h0 = ST.get () in Lib.Loops.for (size 0) n1 (fun h1 i -> live h1 a /\ live h1 b /\ live h1 c /\ modifies1 c h0 h1 /\ i <= v n1 /\ (forall (i0:nat{i0 < i}) (j:nat{j < v n2}). get h1 c i0 j == f (get h0 a i0 j) (get h0 b i0 j)) /\ (forall (i0:nat{i <= i0 /\ i0 < v n1}) (j:nat{j < v n2}). get h1 c i0 j == get h0 c i0 j) ) (fun i -> let h1 = ST.get() in Lib.Loops.for (size 0) n2 (fun h2 j -> map2_inner_inv h0 h1 h2 f a b c i j) (fun j -> map2_inner h0 h1 f a b c i j) ); let h2 = ST.get() in M.extensionality (as_matrix h2 c) (M.map2 f (as_matrix h0 a) (as_matrix h0 b)) val matrix_add: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> Stack unit (requires fun h -> live h a /\ live h b /\ disjoint a b) (ensures fun h0 r h1 -> modifies1 a h0 h1 /\ as_matrix h1 a == M.add (as_matrix h0 a) (as_matrix h0 b)) [@"c_inline"] let matrix_add #n1 #n2 a b = map2 add_mod a b a val matrix_sub: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> Stack unit (requires fun h -> live h a /\ live h b /\ disjoint a b) (ensures fun h0 r h1 -> modifies1 b h0 h1 /\ as_matrix h1 b == M.sub (as_matrix h0 a) (as_matrix h0 b)) [@"c_inline"] let matrix_sub #n1 #n2 a b = (* Use the in-place variant above by flipping the arguments of [sub_mod] *) (* Requires appplying extensionality *) let h0 = ST.get() in [@ inline_let ] let sub_mod_flipped x y = sub_mod y x in map2 sub_mod_flipped b a b; let h1 = ST.get() in M.extensionality (as_matrix h1 b) (M.sub (as_matrix h0 a) (as_matrix h0 b)) #push-options "--fuel 1" inline_for_extraction noextract private val mul_inner: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> #n3:size_t{v n2 * v n3 <= max_size_t /\ v n1 * v n3 <= max_size_t} -> a:matrix_t n1 n2 -> b:matrix_t n2 n3 -> i:size_t{v i < v n1} -> k:size_t{v k < v n3} -> Stack uint16 (requires fun h -> live h a /\ live h b) (ensures fun h0 r h1 -> modifies loc_none h0 h1 /\ r == M.mul_inner (as_matrix h0 a) (as_matrix h0 b) (v i) (v k)) let mul_inner #n1 #n2 #n3 a b i k = push_frame(); let h0 = ST.get() in [@ inline_let ] let f l = get h0 a (v i) l *. get h0 b l (v k) in let res = create #uint16 (size 1) (u16 0) in let h1 = ST.get() in Lib.Loops.for (size 0) n2 (fun h2 j -> live h1 res /\ live h2 res /\ modifies1 res h1 h2 /\ bget h2 res 0 == M.sum_ #(v n2) f j) (fun j -> let aij = a.[i,j] in let bjk = b.[j,k] in let res0 = res.(size 0) in res.(size 0) <- res0 +. aij *. bjk ); let res = res.(size 0) in M.sum_extensionality (v n2) f (fun l -> get h0 a (v i) l *. get h0 b l (v k)) (v n2); assert (res == M.mul_inner (as_matrix h0 a) (as_matrix h0 b) (v i) (v k)); pop_frame(); res #pop-options private unfold val mul_inner_inv: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> #n3:size_t{v n2 * v n3 <= max_size_t /\ v n1 * v n3 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> h2:HS.mem -> a:matrix_t n1 n2 -> b:matrix_t n2 n3 -> c:matrix_t n1 n3 -> f:(k:nat{k < v n3} -> GTot uint16) -> i:size_t{v i < v n1} -> k:size_nat -> Type0 let mul_inner_inv #n1 #n2 #n3 h0 h1 h2 a b c f i k = live h2 a /\ live h2 b /\ live h2 c /\ modifies1 c h1 h2 /\ k <= v n3 /\ (forall (i1:nat{i1 < v i}) (k:nat{k < v n3}). get h2 c i1 k == get h1 c i1 k) /\ (forall (k1:nat{k1 < k}). get h2 c (v i) k1 == f k1) /\ (forall (k1:nat{k <= k1 /\ k1 < v n3}). get h2 c (v i) k1 == get h0 c (v i) k1) /\ (forall (i1:nat{v i < i1 /\ i1 < v n1}) (k:nat{k < v n3}). get h2 c i1 k == get h0 c i1 k) /\ as_matrix h0 a == as_matrix h2 a /\ as_matrix h0 b == as_matrix h2 b inline_for_extraction noextract private val mul_inner1: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> #n3:size_t{v n2 * v n3 <= max_size_t /\ v n1 * v n3 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> a:matrix_t n1 n2 -> b:matrix_t n2 n3 -> c:matrix_t n1 n3{disjoint a c /\ disjoint b c} -> i:size_t{v i < v n1} -> k:size_t{v k < v n3} -> f:(k:nat{k < v n3} -> GTot (res:uint16{res == M.sum #(v n2) (fun l -> get h0 a (v i) l *. get h0 b l k)})) -> Stack unit (requires fun h2 -> mul_inner_inv h0 h1 h2 a b c f i (v k)) (ensures fun _ _ h2 -> mul_inner_inv h0 h1 h2 a b c f i (v k + 1)) let mul_inner1 #n1 #n2 #n3 h0 h1 a b c i k f = assert (M.mul_inner (as_matrix h0 a) (as_matrix h0 b) (v i) (v k) == M.sum #(v n2) (fun l -> get h0 a (v i) l *. get h0 b l (v k))); c.[i,k] <- mul_inner a b i k; let h2 = ST.get () in assert (get h2 c (v i) (v k) == f (v k)) private val onemore: p:(nat -> Type0) -> q:(i:nat{p i} -> Type0) -> b:nat{p b} -> Lemma (requires (forall (i:nat{p i /\ i < b}). q i) /\ q b) (ensures forall (i:nat{p i /\ i <= b}). q i) let onemore p q b = () val onemore1: #n1:size_nat -> #n3:size_nat{n1 * n3 <= max_size_t} -> c:M.matrix n1 n3 -> f:(i:nat{i < n1} -> k:nat{k < n3} -> GTot uint16) -> i:size_nat{i < n1} -> Lemma (requires ((forall (i1:nat{i1 < i}) (k:nat{k < n3}). M.mget c i1 k == f i1 k) /\ (forall (k:nat{k < n3}). M.mget c i k == f i k))) (ensures (forall (i1:nat{i1 <= i}) (k:nat{k < n3}). M.mget c i1 k == f i1 k)) let onemore1 #n1 #n3 c f i = () val matrix_mul: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> #n3:size_t{v n2 * v n3 <= max_size_t /\ v n1 * v n3 <= max_size_t} -> a:matrix_t n1 n2 -> b:matrix_t n2 n3 -> c:matrix_t n1 n3 -> Stack unit (requires fun h -> live h a /\ live h b /\ live h c /\ disjoint a c /\ disjoint b c) (ensures fun h0 _ h1 -> modifies1 c h0 h1 /\ as_matrix h1 c == M.mul (as_matrix h0 a) (as_matrix h0 b)) [@"c_inline"] let matrix_mul #n1 #n2 #n3 a b c = let h0 = ST.get () in let f (i:nat{i < v n1}) (k:nat{k < v n3}) : GTot (res:uint16{res == M.sum #(v n2) (fun l -> get h0 a i l *. get h0 b l k)}) = M.sum #(v n2) (fun l -> get h0 a i l *. get h0 b l k) in Lib.Loops.for (size 0) n1 (fun h1 i -> live h1 a /\ live h1 b /\ live h1 c /\ modifies1 c h0 h1 /\ i <= v n1 /\ (forall (i1:nat{i1 < i}) (k:nat{k < v n3}). get h1 c i1 k == f i1 k) /\ (forall (i1:nat{i <= i1 /\ i1 < v n1}) (k:nat{k < v n3}). get h1 c i1 k == get h0 c i1 k)) (fun i -> let h1 = ST.get() in Lib.Loops.for (size 0) n3 (fun h2 k -> mul_inner_inv h0 h1 h2 a b c (f (v i)) i k) (fun k -> mul_inner1 h0 h1 a b c i k (f (v i))); let h1 = ST.get() in let q i1 = forall (k:nat{k < v n3}). get h1 c i1 k == f i1 k in onemore (fun i1 -> i1 < v n1) q (v i); assert (forall (i1:nat{i1 < v n1 /\ i1 <= v i}) (k:nat{k < v n3}). get h1 c i1 k == f i1 k) ); let h2 = ST.get() in M.extensionality (as_matrix h2 c) (M.mul (as_matrix h0 a) (as_matrix h0 b)) (* Special case of matrix multiplication *) (* when we have a different way of accessing to entries of the matrix S *) inline_for_extraction noextract val mget_s: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> Stack elem (requires fun h0 -> live h0 a) (ensures fun h0 x h1 -> modifies0 h0 h1 /\ x == M.mget_s (as_matrix h0 a) (v i) (v j)) let mget_s #n1 #n2 a i j = M.index_lt (v n2) (v n1) (v j) (v i); a.(j *! n1 +! i) unfold let get_s #n1 #n2 h (m:matrix_t n1 n2) i j = M.mget_s (as_matrix h m) i j #push-options "--fuel 1" inline_for_extraction noextract private val mul_inner_s: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> #n3:size_t{v n2 * v n3 <= max_size_t /\ v n1 * v n3 <= max_size_t} -> a:matrix_t n1 n2 -> b:matrix_t n2 n3 -> i:size_t{v i < v n1} -> k:size_t{v k < v n3} -> Stack uint16 (requires fun h -> live h a /\ live h b) (ensures fun h0 r h1 -> modifies0 h0 h1 /\ r == M.mul_inner_s (as_matrix h0 a) (as_matrix h0 b) (v i) (v k)) let mul_inner_s #n1 #n2 #n3 a b i k = push_frame(); let h0 = ST.get() in [@ inline_let ] let f l = get h0 a (v i) l *. get_s h0 b l (v k) in let res = create #uint16 (size 1) (u16 0) in let h1 = ST.get() in Lib.Loops.for (size 0) n2 (fun h2 j -> live h1 res /\ live h2 res /\ modifies1 res h1 h2 /\ bget h2 res 0 == M.sum_ #(v n2) f j) (fun j -> let aij = mget a i j in let bjk = mget_s b j k in let res0 = res.(size 0) in res.(size 0) <- res0 +. aij *. bjk ); let res = res.(size 0) in M.sum_extensionality (v n2) f (fun l -> get h0 a (v i) l *. get_s h0 b l (v k)) (v n2); assert (res == M.mul_inner_s (as_matrix h0 a) (as_matrix h0 b) (v i) (v k)); pop_frame(); res #pop-options inline_for_extraction noextract private val mul_inner1_s: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> #n3:size_t{v n2 * v n3 <= max_size_t /\ v n1 * v n3 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> a:matrix_t n1 n2 -> b:matrix_t n2 n3 -> c:matrix_t n1 n3{disjoint a c /\ disjoint b c} -> i:size_t{v i < v n1} -> k:size_t{v k < v n3} -> f:(k:nat{k < v n3} -> GTot (res:uint16{res == M.sum #(v n2) (fun l -> get h0 a (v i) l *. get_s h0 b l k)})) -> Stack unit (requires fun h2 -> mul_inner_inv h0 h1 h2 a b c f i (v k)) (ensures fun _ _ h2 -> mul_inner_inv h0 h1 h2 a b c f i (v k + 1)) let mul_inner1_s #n1 #n2 #n3 h0 h1 a b c i k f = assert (M.mul_inner_s (as_matrix h0 a) (as_matrix h0 b) (v i) (v k) == M.sum #(v n2) (fun l -> get h0 a (v i) l *. get_s h0 b l (v k))); mset c i k (mul_inner_s a b i k); let h2 = ST.get () in assert (get h2 c (v i) (v k) == f (v k)) val matrix_mul_s: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> #n3:size_t{v n2 * v n3 <= max_size_t /\ v n1 * v n3 <= max_size_t} -> a:matrix_t n1 n2 -> b:matrix_t n2 n3 -> c:matrix_t n1 n3 -> Stack unit (requires fun h -> live h a /\ live h b /\ live h c /\ disjoint a c /\ disjoint b c) (ensures fun h0 _ h1 -> modifies1 c h0 h1 /\ as_matrix h1 c == M.mul_s (as_matrix h0 a) (as_matrix h0 b)) [@"c_inline"] let matrix_mul_s #n1 #n2 #n3 a b c = let h0 = ST.get () in let f (i:nat{i < v n1}) (k:nat{k < v n3}) : GTot (res:uint16{res == M.sum #(v n2) (fun l -> get h0 a i l *. get_s h0 b l k)}) = M.sum #(v n2) (fun l -> get h0 a i l *. get_s h0 b l k) in Lib.Loops.for (size 0) n1 (fun h1 i -> live h1 a /\ live h1 b /\ live h1 c /\ modifies1 c h0 h1 /\ i <= v n1 /\ (forall (i1:nat{i1 < i}) (k:nat{k < v n3}). get h1 c i1 k == f i1 k) /\ (forall (i1:nat{i <= i1 /\ i1 < v n1}) (k:nat{k < v n3}). get h1 c i1 k == get h0 c i1 k)) (fun i -> let h1 = ST.get() in Lib.Loops.for (size 0) n3 (fun h2 k -> mul_inner_inv h0 h1 h2 a b c (f (v i)) i k) (fun k -> mul_inner1_s h0 h1 a b c i k (f (v i))); let h1 = ST.get() in let q i1 = forall k. get h1 c i1 k == f i1 k in onemore (fun i1 -> i1 < v n1) q (v i); assert (forall (i1:nat{i1 < v n1 /\ i1 <= v i}) (k:nat{k < v n3}). get h1 c i1 k == f i1 k) ); let h2 = ST.get() in M.extensionality (as_matrix h2 c) (M.mul_s (as_matrix h0 a) (as_matrix h0 b)) (* the end of the special matrix multiplication *) val matrix_eq: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> Stack uint16 (requires fun h -> live h a /\ live h b) (ensures fun h0 r h1 -> modifies0 h0 h1 /\ r == M.matrix_eq #(v n1) #(v n2) (as_matrix h0 a) (as_matrix h0 b)) [@"c_inline"] let matrix_eq #n1 #n2 a b = push_frame(); let res = create 1ul (ones U16 SEC) in let r = buf_eq_mask a b (n1 *! n2) res in pop_frame (); r val matrix_to_lbytes: #n1:size_t -> #n2:size_t{2 * v n1 <= max_size_t /\ 2 * v n1 * v n2 <= max_size_t} -> m:matrix_t n1 n2 -> res:lbytes (2ul *! n1 *! n2) -> Stack unit (requires fun h -> live h m /\ live h res /\ disjoint m res) (ensures fun h0 r h1 -> modifies1 res h0 h1 /\ as_seq h1 res == M.matrix_to_lbytes #(v n1) #(v n2) (as_matrix h0 m))
false
false
Hacl.Impl.Matrix.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val matrix_to_lbytes: #n1:size_t -> #n2:size_t{2 * v n1 <= max_size_t /\ 2 * v n1 * v n2 <= max_size_t} -> m:matrix_t n1 n2 -> res:lbytes (2ul *! n1 *! n2) -> Stack unit (requires fun h -> live h m /\ live h res /\ disjoint m res) (ensures fun h0 r h1 -> modifies1 res h0 h1 /\ as_seq h1 res == M.matrix_to_lbytes #(v n1) #(v n2) (as_matrix h0 m))
[]
Hacl.Impl.Matrix.matrix_to_lbytes
{ "file_name": "code/frodo/Hacl.Impl.Matrix.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
m: Hacl.Impl.Matrix.matrix_t n1 n2 -> res: Hacl.Impl.Matrix.lbytes (2ul *! n1 *! n2) -> FStar.HyperStack.ST.Stack Prims.unit
{ "end_col": 60, "end_line": 656, "start_col": 36, "start_line": 652 }
FStar.HyperStack.ST.Stack
val mul_inner1_s: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> #n3:size_t{v n2 * v n3 <= max_size_t /\ v n1 * v n3 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> a:matrix_t n1 n2 -> b:matrix_t n2 n3 -> c:matrix_t n1 n3{disjoint a c /\ disjoint b c} -> i:size_t{v i < v n1} -> k:size_t{v k < v n3} -> f:(k:nat{k < v n3} -> GTot (res:uint16{res == M.sum #(v n2) (fun l -> get h0 a (v i) l *. get_s h0 b l k)})) -> Stack unit (requires fun h2 -> mul_inner_inv h0 h1 h2 a b c f i (v k)) (ensures fun _ _ h2 -> mul_inner_inv h0 h1 h2 a b c f i (v k + 1))
[ { "abbrev": true, "full_module": "Spec.Frodo.Lemmas", "short_module": "Lemmas" }, { "abbrev": true, "full_module": "Spec.Matrix", "short_module": "M" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let mul_inner1_s #n1 #n2 #n3 h0 h1 a b c i k f = assert (M.mul_inner_s (as_matrix h0 a) (as_matrix h0 b) (v i) (v k) == M.sum #(v n2) (fun l -> get h0 a (v i) l *. get_s h0 b l (v k))); mset c i k (mul_inner_s a b i k); let h2 = ST.get () in assert (get h2 c (v i) (v k) == f (v k))
val mul_inner1_s: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> #n3:size_t{v n2 * v n3 <= max_size_t /\ v n1 * v n3 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> a:matrix_t n1 n2 -> b:matrix_t n2 n3 -> c:matrix_t n1 n3{disjoint a c /\ disjoint b c} -> i:size_t{v i < v n1} -> k:size_t{v k < v n3} -> f:(k:nat{k < v n3} -> GTot (res:uint16{res == M.sum #(v n2) (fun l -> get h0 a (v i) l *. get_s h0 b l k)})) -> Stack unit (requires fun h2 -> mul_inner_inv h0 h1 h2 a b c f i (v k)) (ensures fun _ _ h2 -> mul_inner_inv h0 h1 h2 a b c f i (v k + 1)) let mul_inner1_s #n1 #n2 #n3 h0 h1 a b c i k f =
true
null
false
assert (M.mul_inner_s (as_matrix h0 a) (as_matrix h0 b) (v i) (v k) == M.sum #(v n2) (fun l -> get h0 a (v i) l *. get_s h0 b l (v k))); mset c i k (mul_inner_s a b i k); let h2 = ST.get () in assert (get h2 c (v i) (v k) == f (v k))
{ "checked_file": "Hacl.Impl.Matrix.fst.checked", "dependencies": [ "Spec.Matrix.fst.checked", "Spec.Frodo.Lemmas.fst.checked", "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.Loops.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Matrix.fst" }
[]
[ "Lib.IntTypes.size_t", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.Mul.op_Star", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Lib.IntTypes.max_size_t", "Prims.l_and", "FStar.Monotonic.HyperStack.mem", "Hacl.Impl.Matrix.matrix_t", "Lib.Buffer.disjoint", "Lib.Buffer.MUT", "Hacl.Impl.Matrix.elem", "Prims.op_LessThan", "Prims.nat", "Lib.IntTypes.uint16", "Prims.eq2", "Spec.Matrix.sum", "Lib.IntTypes.size_nat", "Lib.IntTypes.op_Star_Dot", "Lib.IntTypes.U16", "Lib.IntTypes.SEC", "Hacl.Impl.Matrix.get", "Hacl.Impl.Matrix.get_s", "Prims._assert", "Prims.unit", "FStar.HyperStack.ST.get", "Hacl.Impl.Matrix.mset", "Lib.IntTypes.int_t", "Hacl.Impl.Matrix.mul_inner_s", "Spec.Matrix.mul_inner_s", "Hacl.Impl.Matrix.as_matrix" ]
[]
module Hacl.Impl.Matrix open FStar.HyperStack.ST open FStar.Mul open LowStar.BufferOps open LowStar.Buffer open Lib.IntTypes open Lib.Buffer open Lib.ByteBuffer module HS = FStar.HyperStack module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module Loops = Lib.LoopCombinators module M = Spec.Matrix module Lemmas = Spec.Frodo.Lemmas #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" unfold let elem = uint16 unfold let lbytes len = lbuffer uint8 len unfold let matrix_t (n1:size_t) (n2:size_t{v n1 * v n2 <= max_size_t}) = lbuffer elem (n1 *! n2) unfold let as_matrix #n1 #n2 h (m:matrix_t n1 n2) : GTot (M.matrix (v n1) (v n2)) = as_seq h m inline_for_extraction noextract val matrix_create: n1:size_t -> n2:size_t{0 < v n1 * v n2 /\ v n1 * v n2 <= max_size_t} -> StackInline (matrix_t n1 n2) (requires fun h0 -> True) (ensures fun h0 a h1 -> stack_allocated a h0 h1 (as_matrix h1 a) /\ as_matrix h1 a == M.create (v n1) (v n2)) let matrix_create n1 n2 = [@inline_let] let len = size (normalize_term (v n1 * v n2)) in create len (u16 0) inline_for_extraction noextract val mget: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> Stack elem (requires fun h0 -> live h0 a) (ensures fun h0 x h1 -> modifies loc_none h0 h1 /\ x == M.mget (as_matrix h0 a) (v i) (v j)) let mget #n1 #n2 a i j = M.index_lt (v n1) (v n2) (v i) (v j); a.(i *! n2 +! j) inline_for_extraction noextract val mset: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> x:elem -> Stack unit (requires fun h0 -> live h0 a) (ensures fun h0 _ h1 -> modifies1 a h0 h1 /\ as_matrix h1 a == M.mset (as_matrix h0 a) (v i) (v j) x) let mset #n1 #n2 a i j x = M.index_lt (v n1) (v n2) (v i) (v j); a.(i *! n2 +! j) <- x noextract unfold val op_String_Access (#n1:size_t) (#n2:size_t{v n1 * v n2 <= max_size_t}) (m:matrix_t n1 n2) (ij:(size_t & size_t){let i, j = ij in v i < v n1 /\ v j < v n2}) : Stack elem (requires fun h0 -> live h0 m) (ensures fun h0 x h1 -> let i, j = ij in modifies loc_none h0 h1 /\ x == M.mget (as_matrix h0 m) (v i) (v j)) let op_String_Access #n1 #n2 m (i,j) = mget m i j noextract unfold val op_String_Assignment (#n1:size_t) (#n2:size_t{v n1 * v n2 <= max_size_t}) (m:matrix_t n1 n2) (ij:(size_t & size_t){let i, j = ij in v i < v n1 /\ v j < v n2}) (x:elem) : Stack unit (requires fun h0 -> live h0 m) (ensures fun h0 _ h1 -> let i, j = ij in modifies1 m h0 h1 /\ live h1 m /\ as_matrix h1 m == M.mset (as_matrix h0 m) (v i) (v j) x) let op_String_Assignment #n1 #n2 m (i,j) x = mset m i j x unfold let get #n1 #n2 h (m:matrix_t n1 n2) i j = M.mget (as_matrix h m) i j private unfold val map_inner_inv: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> h2:HS.mem -> f:(elem -> elem) -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_nat -> Type0 let map_inner_inv #n1 #n2 h0 h1 h2 f a c i j = live h2 a /\ live h2 c /\ modifies1 c h1 h2 /\ j <= v n2 /\ (forall (i0:nat{i0 < v i}) (j:nat{j < v n2}). get h2 c i0 j == get h1 c i0 j) /\ (forall (j0:nat{j0 < j}). get h2 c (v i) j0 == f (get h0 a (v i) j0)) /\ (forall (j0:nat{j <= j0 /\ j0 < v n2}). get h2 c (v i) j0 == get h0 c (v i) j0) /\ (forall (i0:nat{v i < i0 /\ i0 < v n1}) (j:nat{j < v n2}). get h2 c i0 j == get h0 c i0 j) inline_for_extraction noextract private val map_inner: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> f:(elem -> elem) -> a:matrix_t n1 n2 -> c:matrix_t n1 n2{a == c} -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> Stack unit (requires fun h2 -> map_inner_inv h0 h1 h2 f a c i (v j)) (ensures fun _ _ h2 -> map_inner_inv h0 h1 h2 f a c i (v j + 1)) let map_inner #n1 #n2 h0 h1 f a c i j = c.[i,j] <- f a.[i,j] inline_for_extraction val map: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> f:(uint16 -> uint16) -> a:matrix_t n1 n2 -> c:matrix_t n1 n2 -> Stack unit (requires fun h0 -> live h0 a /\ live h0 c /\ a == c) (ensures fun h0 _ h1 -> modifies1 c h0 h1 /\ as_matrix h1 c == M.map #(v n1) #(v n2) f (as_matrix h0 a)) let map #n1 #n2 f a c = let h0 = ST.get () in Lib.Loops.for (size 0) n1 (fun h1 i -> live h1 a /\ live h1 c /\ modifies1 c h0 h1 /\ i <= v n1 /\ (forall (i0:nat{i0 < i}) (j:nat{j < v n2}). get h1 c i0 j == f (get h0 a i0 j)) /\ (forall (i0:nat{i <= i0 /\ i0 < v n1}) (j:nat{j < v n2}). get h1 c i0 j == get h0 c i0 j) ) (fun i -> let h1 = ST.get() in Lib.Loops.for (size 0) n2 (fun h2 j -> map_inner_inv h0 h1 h2 f a c i j) (fun j -> map_inner h0 h1 f a c i j) ); let h2 = ST.get () in M.extensionality (as_matrix h2 c) (M.map f (as_matrix h0 a)) inline_for_extraction noextract val mod_pow2_felem: logq:size_t{0 < v logq /\ v logq < 16} -> a:uint16 -> Pure uint16 (requires True) (ensures fun r -> r == M.mod_pow2_felem (v logq) a) let mod_pow2_felem logq a = a &. ((u16 1 <<. logq) -. u16 1) val mod_pow2: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> logq:size_t{0 < v logq /\ v logq <= 16} -> a:matrix_t n1 n2 -> Stack unit (requires fun h -> live h a) (ensures fun h0 _ h1 -> modifies1 a h0 h1 /\ as_matrix h1 a == M.mod_pow2 (v logq) (as_matrix h0 a)) [@"c_inline"] let mod_pow2 #n1 #n2 logq a = if logq <. 16ul then begin let h0 = ST.get () in map (mod_pow2_felem logq) a a; M.extensionality (M.map #(v n1) #(v n2) (mod_pow2_felem logq) (as_matrix h0 a)) (M.map #(v n1) #(v n2) (M.mod_pow2_felem (v logq)) (as_matrix h0 a)) end private unfold val map2_inner_inv: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> h2:HS.mem -> f:(elem -> elem -> elem) -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> c:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_nat -> Type0 let map2_inner_inv #n1 #n2 h0 h1 h2 f a b c i j = live h2 a /\ live h2 b /\ live h2 c /\ modifies1 c h1 h2 /\ j <= v n2 /\ (forall (i0:nat{i0 < v i}) (j:nat{j < v n2}). get h2 c i0 j == get h1 c i0 j) /\ (forall (j0:nat{j0 < j}). get h2 c (v i) j0 == f (get h0 a (v i) j0) (get h2 b (v i) j0)) /\ (forall (j0:nat{j <= j0 /\ j0 < v n2}). get h2 c (v i) j0 == get h0 c (v i) j0) /\ (forall (i0:nat{v i < i0 /\ i0 < v n1}) (j:nat{j < v n2}). get h2 c i0 j == get h0 c i0 j) inline_for_extraction noextract private val map2_inner: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> f:(elem -> elem -> elem) -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> c:matrix_t n1 n2{a == c /\ disjoint b c} -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> Stack unit (requires fun h2 -> map2_inner_inv h0 h1 h2 f a b c i (v j)) (ensures fun _ _ h2 -> map2_inner_inv h0 h1 h2 f a b c i (v j + 1)) let map2_inner #n1 #n2 h0 h1 f a b c i j = c.[i,j] <- f a.[i,j] b.[i,j] /// In-place [map2], a == map2 f a b /// /// A non in-place variant can be obtained by weakening the pre-condition to disjoint a c, /// or the two variants can be merged by requiring (a == c \/ disjoint a c) instead of a == c /// See commit 91916b8372fa3522061eff5a42d0ebd1d19a8a49 inline_for_extraction val map2: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> f:(uint16 -> uint16 -> uint16) -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> c:matrix_t n1 n2 -> Stack unit (requires fun h0 -> live h0 a /\ live h0 b /\ live h0 c /\ a == c /\ disjoint b c) (ensures fun h0 _ h1 -> modifies1 c h0 h1 /\ as_matrix h1 c == M.map2 #(v n1) #(v n2) f (as_matrix h0 a) (as_matrix h0 b)) let map2 #n1 #n2 f a b c = let h0 = ST.get () in Lib.Loops.for (size 0) n1 (fun h1 i -> live h1 a /\ live h1 b /\ live h1 c /\ modifies1 c h0 h1 /\ i <= v n1 /\ (forall (i0:nat{i0 < i}) (j:nat{j < v n2}). get h1 c i0 j == f (get h0 a i0 j) (get h0 b i0 j)) /\ (forall (i0:nat{i <= i0 /\ i0 < v n1}) (j:nat{j < v n2}). get h1 c i0 j == get h0 c i0 j) ) (fun i -> let h1 = ST.get() in Lib.Loops.for (size 0) n2 (fun h2 j -> map2_inner_inv h0 h1 h2 f a b c i j) (fun j -> map2_inner h0 h1 f a b c i j) ); let h2 = ST.get() in M.extensionality (as_matrix h2 c) (M.map2 f (as_matrix h0 a) (as_matrix h0 b)) val matrix_add: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> Stack unit (requires fun h -> live h a /\ live h b /\ disjoint a b) (ensures fun h0 r h1 -> modifies1 a h0 h1 /\ as_matrix h1 a == M.add (as_matrix h0 a) (as_matrix h0 b)) [@"c_inline"] let matrix_add #n1 #n2 a b = map2 add_mod a b a val matrix_sub: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> Stack unit (requires fun h -> live h a /\ live h b /\ disjoint a b) (ensures fun h0 r h1 -> modifies1 b h0 h1 /\ as_matrix h1 b == M.sub (as_matrix h0 a) (as_matrix h0 b)) [@"c_inline"] let matrix_sub #n1 #n2 a b = (* Use the in-place variant above by flipping the arguments of [sub_mod] *) (* Requires appplying extensionality *) let h0 = ST.get() in [@ inline_let ] let sub_mod_flipped x y = sub_mod y x in map2 sub_mod_flipped b a b; let h1 = ST.get() in M.extensionality (as_matrix h1 b) (M.sub (as_matrix h0 a) (as_matrix h0 b)) #push-options "--fuel 1" inline_for_extraction noextract private val mul_inner: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> #n3:size_t{v n2 * v n3 <= max_size_t /\ v n1 * v n3 <= max_size_t} -> a:matrix_t n1 n2 -> b:matrix_t n2 n3 -> i:size_t{v i < v n1} -> k:size_t{v k < v n3} -> Stack uint16 (requires fun h -> live h a /\ live h b) (ensures fun h0 r h1 -> modifies loc_none h0 h1 /\ r == M.mul_inner (as_matrix h0 a) (as_matrix h0 b) (v i) (v k)) let mul_inner #n1 #n2 #n3 a b i k = push_frame(); let h0 = ST.get() in [@ inline_let ] let f l = get h0 a (v i) l *. get h0 b l (v k) in let res = create #uint16 (size 1) (u16 0) in let h1 = ST.get() in Lib.Loops.for (size 0) n2 (fun h2 j -> live h1 res /\ live h2 res /\ modifies1 res h1 h2 /\ bget h2 res 0 == M.sum_ #(v n2) f j) (fun j -> let aij = a.[i,j] in let bjk = b.[j,k] in let res0 = res.(size 0) in res.(size 0) <- res0 +. aij *. bjk ); let res = res.(size 0) in M.sum_extensionality (v n2) f (fun l -> get h0 a (v i) l *. get h0 b l (v k)) (v n2); assert (res == M.mul_inner (as_matrix h0 a) (as_matrix h0 b) (v i) (v k)); pop_frame(); res #pop-options private unfold val mul_inner_inv: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> #n3:size_t{v n2 * v n3 <= max_size_t /\ v n1 * v n3 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> h2:HS.mem -> a:matrix_t n1 n2 -> b:matrix_t n2 n3 -> c:matrix_t n1 n3 -> f:(k:nat{k < v n3} -> GTot uint16) -> i:size_t{v i < v n1} -> k:size_nat -> Type0 let mul_inner_inv #n1 #n2 #n3 h0 h1 h2 a b c f i k = live h2 a /\ live h2 b /\ live h2 c /\ modifies1 c h1 h2 /\ k <= v n3 /\ (forall (i1:nat{i1 < v i}) (k:nat{k < v n3}). get h2 c i1 k == get h1 c i1 k) /\ (forall (k1:nat{k1 < k}). get h2 c (v i) k1 == f k1) /\ (forall (k1:nat{k <= k1 /\ k1 < v n3}). get h2 c (v i) k1 == get h0 c (v i) k1) /\ (forall (i1:nat{v i < i1 /\ i1 < v n1}) (k:nat{k < v n3}). get h2 c i1 k == get h0 c i1 k) /\ as_matrix h0 a == as_matrix h2 a /\ as_matrix h0 b == as_matrix h2 b inline_for_extraction noextract private val mul_inner1: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> #n3:size_t{v n2 * v n3 <= max_size_t /\ v n1 * v n3 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> a:matrix_t n1 n2 -> b:matrix_t n2 n3 -> c:matrix_t n1 n3{disjoint a c /\ disjoint b c} -> i:size_t{v i < v n1} -> k:size_t{v k < v n3} -> f:(k:nat{k < v n3} -> GTot (res:uint16{res == M.sum #(v n2) (fun l -> get h0 a (v i) l *. get h0 b l k)})) -> Stack unit (requires fun h2 -> mul_inner_inv h0 h1 h2 a b c f i (v k)) (ensures fun _ _ h2 -> mul_inner_inv h0 h1 h2 a b c f i (v k + 1)) let mul_inner1 #n1 #n2 #n3 h0 h1 a b c i k f = assert (M.mul_inner (as_matrix h0 a) (as_matrix h0 b) (v i) (v k) == M.sum #(v n2) (fun l -> get h0 a (v i) l *. get h0 b l (v k))); c.[i,k] <- mul_inner a b i k; let h2 = ST.get () in assert (get h2 c (v i) (v k) == f (v k)) private val onemore: p:(nat -> Type0) -> q:(i:nat{p i} -> Type0) -> b:nat{p b} -> Lemma (requires (forall (i:nat{p i /\ i < b}). q i) /\ q b) (ensures forall (i:nat{p i /\ i <= b}). q i) let onemore p q b = () val onemore1: #n1:size_nat -> #n3:size_nat{n1 * n3 <= max_size_t} -> c:M.matrix n1 n3 -> f:(i:nat{i < n1} -> k:nat{k < n3} -> GTot uint16) -> i:size_nat{i < n1} -> Lemma (requires ((forall (i1:nat{i1 < i}) (k:nat{k < n3}). M.mget c i1 k == f i1 k) /\ (forall (k:nat{k < n3}). M.mget c i k == f i k))) (ensures (forall (i1:nat{i1 <= i}) (k:nat{k < n3}). M.mget c i1 k == f i1 k)) let onemore1 #n1 #n3 c f i = () val matrix_mul: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> #n3:size_t{v n2 * v n3 <= max_size_t /\ v n1 * v n3 <= max_size_t} -> a:matrix_t n1 n2 -> b:matrix_t n2 n3 -> c:matrix_t n1 n3 -> Stack unit (requires fun h -> live h a /\ live h b /\ live h c /\ disjoint a c /\ disjoint b c) (ensures fun h0 _ h1 -> modifies1 c h0 h1 /\ as_matrix h1 c == M.mul (as_matrix h0 a) (as_matrix h0 b)) [@"c_inline"] let matrix_mul #n1 #n2 #n3 a b c = let h0 = ST.get () in let f (i:nat{i < v n1}) (k:nat{k < v n3}) : GTot (res:uint16{res == M.sum #(v n2) (fun l -> get h0 a i l *. get h0 b l k)}) = M.sum #(v n2) (fun l -> get h0 a i l *. get h0 b l k) in Lib.Loops.for (size 0) n1 (fun h1 i -> live h1 a /\ live h1 b /\ live h1 c /\ modifies1 c h0 h1 /\ i <= v n1 /\ (forall (i1:nat{i1 < i}) (k:nat{k < v n3}). get h1 c i1 k == f i1 k) /\ (forall (i1:nat{i <= i1 /\ i1 < v n1}) (k:nat{k < v n3}). get h1 c i1 k == get h0 c i1 k)) (fun i -> let h1 = ST.get() in Lib.Loops.for (size 0) n3 (fun h2 k -> mul_inner_inv h0 h1 h2 a b c (f (v i)) i k) (fun k -> mul_inner1 h0 h1 a b c i k (f (v i))); let h1 = ST.get() in let q i1 = forall (k:nat{k < v n3}). get h1 c i1 k == f i1 k in onemore (fun i1 -> i1 < v n1) q (v i); assert (forall (i1:nat{i1 < v n1 /\ i1 <= v i}) (k:nat{k < v n3}). get h1 c i1 k == f i1 k) ); let h2 = ST.get() in M.extensionality (as_matrix h2 c) (M.mul (as_matrix h0 a) (as_matrix h0 b)) (* Special case of matrix multiplication *) (* when we have a different way of accessing to entries of the matrix S *) inline_for_extraction noextract val mget_s: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> Stack elem (requires fun h0 -> live h0 a) (ensures fun h0 x h1 -> modifies0 h0 h1 /\ x == M.mget_s (as_matrix h0 a) (v i) (v j)) let mget_s #n1 #n2 a i j = M.index_lt (v n2) (v n1) (v j) (v i); a.(j *! n1 +! i) unfold let get_s #n1 #n2 h (m:matrix_t n1 n2) i j = M.mget_s (as_matrix h m) i j #push-options "--fuel 1" inline_for_extraction noextract private val mul_inner_s: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> #n3:size_t{v n2 * v n3 <= max_size_t /\ v n1 * v n3 <= max_size_t} -> a:matrix_t n1 n2 -> b:matrix_t n2 n3 -> i:size_t{v i < v n1} -> k:size_t{v k < v n3} -> Stack uint16 (requires fun h -> live h a /\ live h b) (ensures fun h0 r h1 -> modifies0 h0 h1 /\ r == M.mul_inner_s (as_matrix h0 a) (as_matrix h0 b) (v i) (v k)) let mul_inner_s #n1 #n2 #n3 a b i k = push_frame(); let h0 = ST.get() in [@ inline_let ] let f l = get h0 a (v i) l *. get_s h0 b l (v k) in let res = create #uint16 (size 1) (u16 0) in let h1 = ST.get() in Lib.Loops.for (size 0) n2 (fun h2 j -> live h1 res /\ live h2 res /\ modifies1 res h1 h2 /\ bget h2 res 0 == M.sum_ #(v n2) f j) (fun j -> let aij = mget a i j in let bjk = mget_s b j k in let res0 = res.(size 0) in res.(size 0) <- res0 +. aij *. bjk ); let res = res.(size 0) in M.sum_extensionality (v n2) f (fun l -> get h0 a (v i) l *. get_s h0 b l (v k)) (v n2); assert (res == M.mul_inner_s (as_matrix h0 a) (as_matrix h0 b) (v i) (v k)); pop_frame(); res #pop-options inline_for_extraction noextract private val mul_inner1_s: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> #n3:size_t{v n2 * v n3 <= max_size_t /\ v n1 * v n3 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> a:matrix_t n1 n2 -> b:matrix_t n2 n3 -> c:matrix_t n1 n3{disjoint a c /\ disjoint b c} -> i:size_t{v i < v n1} -> k:size_t{v k < v n3} -> f:(k:nat{k < v n3} -> GTot (res:uint16{res == M.sum #(v n2) (fun l -> get h0 a (v i) l *. get_s h0 b l k)})) -> Stack unit (requires fun h2 -> mul_inner_inv h0 h1 h2 a b c f i (v k)) (ensures fun _ _ h2 -> mul_inner_inv h0 h1 h2 a b c f i (v k + 1))
false
false
Hacl.Impl.Matrix.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val mul_inner1_s: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> #n3:size_t{v n2 * v n3 <= max_size_t /\ v n1 * v n3 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> a:matrix_t n1 n2 -> b:matrix_t n2 n3 -> c:matrix_t n1 n3{disjoint a c /\ disjoint b c} -> i:size_t{v i < v n1} -> k:size_t{v k < v n3} -> f:(k:nat{k < v n3} -> GTot (res:uint16{res == M.sum #(v n2) (fun l -> get h0 a (v i) l *. get_s h0 b l k)})) -> Stack unit (requires fun h2 -> mul_inner_inv h0 h1 h2 a b c f i (v k)) (ensures fun _ _ h2 -> mul_inner_inv h0 h1 h2 a b c f i (v k + 1))
[]
Hacl.Impl.Matrix.mul_inner1_s
{ "file_name": "code/frodo/Hacl.Impl.Matrix.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
h0: FStar.Monotonic.HyperStack.mem -> h1: FStar.Monotonic.HyperStack.mem -> a: Hacl.Impl.Matrix.matrix_t n1 n2 -> b: Hacl.Impl.Matrix.matrix_t n2 n3 -> c: Hacl.Impl.Matrix.matrix_t n1 n3 {Lib.Buffer.disjoint a c /\ Lib.Buffer.disjoint b c} -> i: Lib.IntTypes.size_t{Lib.IntTypes.v i < Lib.IntTypes.v n1} -> k: Lib.IntTypes.size_t{Lib.IntTypes.v k < Lib.IntTypes.v n3} -> f: (k: Prims.nat{k < Lib.IntTypes.v n3} -> Prims.GTot (res: Lib.IntTypes.uint16 { res == Spec.Matrix.sum (fun l -> Hacl.Impl.Matrix.get h0 a (Lib.IntTypes.v i) l *. Hacl.Impl.Matrix.get_s h0 b l k) })) -> FStar.HyperStack.ST.Stack Prims.unit
{ "end_col": 42, "end_line": 577, "start_col": 2, "start_line": 573 }
FStar.HyperStack.ST.Stack
val mul_inner_s: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> #n3:size_t{v n2 * v n3 <= max_size_t /\ v n1 * v n3 <= max_size_t} -> a:matrix_t n1 n2 -> b:matrix_t n2 n3 -> i:size_t{v i < v n1} -> k:size_t{v k < v n3} -> Stack uint16 (requires fun h -> live h a /\ live h b) (ensures fun h0 r h1 -> modifies0 h0 h1 /\ r == M.mul_inner_s (as_matrix h0 a) (as_matrix h0 b) (v i) (v k))
[ { "abbrev": true, "full_module": "Spec.Frodo.Lemmas", "short_module": "Lemmas" }, { "abbrev": true, "full_module": "Spec.Matrix", "short_module": "M" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let mul_inner_s #n1 #n2 #n3 a b i k = push_frame(); let h0 = ST.get() in [@ inline_let ] let f l = get h0 a (v i) l *. get_s h0 b l (v k) in let res = create #uint16 (size 1) (u16 0) in let h1 = ST.get() in Lib.Loops.for (size 0) n2 (fun h2 j -> live h1 res /\ live h2 res /\ modifies1 res h1 h2 /\ bget h2 res 0 == M.sum_ #(v n2) f j) (fun j -> let aij = mget a i j in let bjk = mget_s b j k in let res0 = res.(size 0) in res.(size 0) <- res0 +. aij *. bjk ); let res = res.(size 0) in M.sum_extensionality (v n2) f (fun l -> get h0 a (v i) l *. get_s h0 b l (v k)) (v n2); assert (res == M.mul_inner_s (as_matrix h0 a) (as_matrix h0 b) (v i) (v k)); pop_frame(); res
val mul_inner_s: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> #n3:size_t{v n2 * v n3 <= max_size_t /\ v n1 * v n3 <= max_size_t} -> a:matrix_t n1 n2 -> b:matrix_t n2 n3 -> i:size_t{v i < v n1} -> k:size_t{v k < v n3} -> Stack uint16 (requires fun h -> live h a /\ live h b) (ensures fun h0 r h1 -> modifies0 h0 h1 /\ r == M.mul_inner_s (as_matrix h0 a) (as_matrix h0 b) (v i) (v k)) let mul_inner_s #n1 #n2 #n3 a b i k =
true
null
false
push_frame (); let h0 = ST.get () in [@@ inline_let ]let f l = get h0 a (v i) l *. get_s h0 b l (v k) in let res = create #uint16 (size 1) (u16 0) in let h1 = ST.get () in Lib.Loops.for (size 0) n2 (fun h2 j -> live h1 res /\ live h2 res /\ modifies1 res h1 h2 /\ bget h2 res 0 == M.sum_ #(v n2) f j) (fun j -> let aij = mget a i j in let bjk = mget_s b j k in let res0 = res.(size 0) in res.(size 0) <- res0 +. aij *. bjk); let res = res.(size 0) in M.sum_extensionality (v n2) f (fun l -> get h0 a (v i) l *. get_s h0 b l (v k)) (v n2); assert (res == M.mul_inner_s (as_matrix h0 a) (as_matrix h0 b) (v i) (v k)); pop_frame (); res
{ "checked_file": "Hacl.Impl.Matrix.fst.checked", "dependencies": [ "Spec.Matrix.fst.checked", "Spec.Frodo.Lemmas.fst.checked", "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.Loops.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Matrix.fst" }
[]
[ "Lib.IntTypes.size_t", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.Mul.op_Star", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Lib.IntTypes.max_size_t", "Prims.l_and", "Hacl.Impl.Matrix.matrix_t", "Prims.op_LessThan", "Lib.IntTypes.uint16", "Prims.unit", "FStar.HyperStack.ST.pop_frame", "Prims._assert", "Prims.eq2", "Spec.Matrix.mul_inner_s", "Hacl.Impl.Matrix.as_matrix", "Spec.Matrix.sum_extensionality", "Lib.IntTypes.size_nat", "Lib.IntTypes.op_Star_Dot", "Lib.IntTypes.U16", "Lib.IntTypes.SEC", "Hacl.Impl.Matrix.get", "Hacl.Impl.Matrix.get_s", "Lib.IntTypes.int_t", "Lib.Buffer.op_Array_Access", "Lib.Buffer.MUT", "Lib.IntTypes.size", "Lib.Loops.for", "FStar.Monotonic.HyperStack.mem", "Prims.nat", "Lib.Buffer.live", "Lib.Buffer.modifies1", "Lib.Buffer.bget", "Spec.Matrix.sum_", "Lib.Buffer.op_Array_Assignment", "Lib.IntTypes.op_Plus_Dot", "Hacl.Impl.Matrix.mget_s", "Hacl.Impl.Matrix.elem", "Hacl.Impl.Matrix.mget", "FStar.HyperStack.ST.get", "Lib.Buffer.lbuffer_t", "Lib.IntTypes.mk_int", "Lib.Buffer.create", "Lib.IntTypes.u16", "Lib.Buffer.lbuffer", "Prims.op_Subtraction", "Prims.pow2", "FStar.HyperStack.ST.push_frame" ]
[]
module Hacl.Impl.Matrix open FStar.HyperStack.ST open FStar.Mul open LowStar.BufferOps open LowStar.Buffer open Lib.IntTypes open Lib.Buffer open Lib.ByteBuffer module HS = FStar.HyperStack module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module Loops = Lib.LoopCombinators module M = Spec.Matrix module Lemmas = Spec.Frodo.Lemmas #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" unfold let elem = uint16 unfold let lbytes len = lbuffer uint8 len unfold let matrix_t (n1:size_t) (n2:size_t{v n1 * v n2 <= max_size_t}) = lbuffer elem (n1 *! n2) unfold let as_matrix #n1 #n2 h (m:matrix_t n1 n2) : GTot (M.matrix (v n1) (v n2)) = as_seq h m inline_for_extraction noextract val matrix_create: n1:size_t -> n2:size_t{0 < v n1 * v n2 /\ v n1 * v n2 <= max_size_t} -> StackInline (matrix_t n1 n2) (requires fun h0 -> True) (ensures fun h0 a h1 -> stack_allocated a h0 h1 (as_matrix h1 a) /\ as_matrix h1 a == M.create (v n1) (v n2)) let matrix_create n1 n2 = [@inline_let] let len = size (normalize_term (v n1 * v n2)) in create len (u16 0) inline_for_extraction noextract val mget: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> Stack elem (requires fun h0 -> live h0 a) (ensures fun h0 x h1 -> modifies loc_none h0 h1 /\ x == M.mget (as_matrix h0 a) (v i) (v j)) let mget #n1 #n2 a i j = M.index_lt (v n1) (v n2) (v i) (v j); a.(i *! n2 +! j) inline_for_extraction noextract val mset: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> x:elem -> Stack unit (requires fun h0 -> live h0 a) (ensures fun h0 _ h1 -> modifies1 a h0 h1 /\ as_matrix h1 a == M.mset (as_matrix h0 a) (v i) (v j) x) let mset #n1 #n2 a i j x = M.index_lt (v n1) (v n2) (v i) (v j); a.(i *! n2 +! j) <- x noextract unfold val op_String_Access (#n1:size_t) (#n2:size_t{v n1 * v n2 <= max_size_t}) (m:matrix_t n1 n2) (ij:(size_t & size_t){let i, j = ij in v i < v n1 /\ v j < v n2}) : Stack elem (requires fun h0 -> live h0 m) (ensures fun h0 x h1 -> let i, j = ij in modifies loc_none h0 h1 /\ x == M.mget (as_matrix h0 m) (v i) (v j)) let op_String_Access #n1 #n2 m (i,j) = mget m i j noextract unfold val op_String_Assignment (#n1:size_t) (#n2:size_t{v n1 * v n2 <= max_size_t}) (m:matrix_t n1 n2) (ij:(size_t & size_t){let i, j = ij in v i < v n1 /\ v j < v n2}) (x:elem) : Stack unit (requires fun h0 -> live h0 m) (ensures fun h0 _ h1 -> let i, j = ij in modifies1 m h0 h1 /\ live h1 m /\ as_matrix h1 m == M.mset (as_matrix h0 m) (v i) (v j) x) let op_String_Assignment #n1 #n2 m (i,j) x = mset m i j x unfold let get #n1 #n2 h (m:matrix_t n1 n2) i j = M.mget (as_matrix h m) i j private unfold val map_inner_inv: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> h2:HS.mem -> f:(elem -> elem) -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_nat -> Type0 let map_inner_inv #n1 #n2 h0 h1 h2 f a c i j = live h2 a /\ live h2 c /\ modifies1 c h1 h2 /\ j <= v n2 /\ (forall (i0:nat{i0 < v i}) (j:nat{j < v n2}). get h2 c i0 j == get h1 c i0 j) /\ (forall (j0:nat{j0 < j}). get h2 c (v i) j0 == f (get h0 a (v i) j0)) /\ (forall (j0:nat{j <= j0 /\ j0 < v n2}). get h2 c (v i) j0 == get h0 c (v i) j0) /\ (forall (i0:nat{v i < i0 /\ i0 < v n1}) (j:nat{j < v n2}). get h2 c i0 j == get h0 c i0 j) inline_for_extraction noextract private val map_inner: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> f:(elem -> elem) -> a:matrix_t n1 n2 -> c:matrix_t n1 n2{a == c} -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> Stack unit (requires fun h2 -> map_inner_inv h0 h1 h2 f a c i (v j)) (ensures fun _ _ h2 -> map_inner_inv h0 h1 h2 f a c i (v j + 1)) let map_inner #n1 #n2 h0 h1 f a c i j = c.[i,j] <- f a.[i,j] inline_for_extraction val map: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> f:(uint16 -> uint16) -> a:matrix_t n1 n2 -> c:matrix_t n1 n2 -> Stack unit (requires fun h0 -> live h0 a /\ live h0 c /\ a == c) (ensures fun h0 _ h1 -> modifies1 c h0 h1 /\ as_matrix h1 c == M.map #(v n1) #(v n2) f (as_matrix h0 a)) let map #n1 #n2 f a c = let h0 = ST.get () in Lib.Loops.for (size 0) n1 (fun h1 i -> live h1 a /\ live h1 c /\ modifies1 c h0 h1 /\ i <= v n1 /\ (forall (i0:nat{i0 < i}) (j:nat{j < v n2}). get h1 c i0 j == f (get h0 a i0 j)) /\ (forall (i0:nat{i <= i0 /\ i0 < v n1}) (j:nat{j < v n2}). get h1 c i0 j == get h0 c i0 j) ) (fun i -> let h1 = ST.get() in Lib.Loops.for (size 0) n2 (fun h2 j -> map_inner_inv h0 h1 h2 f a c i j) (fun j -> map_inner h0 h1 f a c i j) ); let h2 = ST.get () in M.extensionality (as_matrix h2 c) (M.map f (as_matrix h0 a)) inline_for_extraction noextract val mod_pow2_felem: logq:size_t{0 < v logq /\ v logq < 16} -> a:uint16 -> Pure uint16 (requires True) (ensures fun r -> r == M.mod_pow2_felem (v logq) a) let mod_pow2_felem logq a = a &. ((u16 1 <<. logq) -. u16 1) val mod_pow2: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> logq:size_t{0 < v logq /\ v logq <= 16} -> a:matrix_t n1 n2 -> Stack unit (requires fun h -> live h a) (ensures fun h0 _ h1 -> modifies1 a h0 h1 /\ as_matrix h1 a == M.mod_pow2 (v logq) (as_matrix h0 a)) [@"c_inline"] let mod_pow2 #n1 #n2 logq a = if logq <. 16ul then begin let h0 = ST.get () in map (mod_pow2_felem logq) a a; M.extensionality (M.map #(v n1) #(v n2) (mod_pow2_felem logq) (as_matrix h0 a)) (M.map #(v n1) #(v n2) (M.mod_pow2_felem (v logq)) (as_matrix h0 a)) end private unfold val map2_inner_inv: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> h2:HS.mem -> f:(elem -> elem -> elem) -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> c:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_nat -> Type0 let map2_inner_inv #n1 #n2 h0 h1 h2 f a b c i j = live h2 a /\ live h2 b /\ live h2 c /\ modifies1 c h1 h2 /\ j <= v n2 /\ (forall (i0:nat{i0 < v i}) (j:nat{j < v n2}). get h2 c i0 j == get h1 c i0 j) /\ (forall (j0:nat{j0 < j}). get h2 c (v i) j0 == f (get h0 a (v i) j0) (get h2 b (v i) j0)) /\ (forall (j0:nat{j <= j0 /\ j0 < v n2}). get h2 c (v i) j0 == get h0 c (v i) j0) /\ (forall (i0:nat{v i < i0 /\ i0 < v n1}) (j:nat{j < v n2}). get h2 c i0 j == get h0 c i0 j) inline_for_extraction noextract private val map2_inner: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> f:(elem -> elem -> elem) -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> c:matrix_t n1 n2{a == c /\ disjoint b c} -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> Stack unit (requires fun h2 -> map2_inner_inv h0 h1 h2 f a b c i (v j)) (ensures fun _ _ h2 -> map2_inner_inv h0 h1 h2 f a b c i (v j + 1)) let map2_inner #n1 #n2 h0 h1 f a b c i j = c.[i,j] <- f a.[i,j] b.[i,j] /// In-place [map2], a == map2 f a b /// /// A non in-place variant can be obtained by weakening the pre-condition to disjoint a c, /// or the two variants can be merged by requiring (a == c \/ disjoint a c) instead of a == c /// See commit 91916b8372fa3522061eff5a42d0ebd1d19a8a49 inline_for_extraction val map2: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> f:(uint16 -> uint16 -> uint16) -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> c:matrix_t n1 n2 -> Stack unit (requires fun h0 -> live h0 a /\ live h0 b /\ live h0 c /\ a == c /\ disjoint b c) (ensures fun h0 _ h1 -> modifies1 c h0 h1 /\ as_matrix h1 c == M.map2 #(v n1) #(v n2) f (as_matrix h0 a) (as_matrix h0 b)) let map2 #n1 #n2 f a b c = let h0 = ST.get () in Lib.Loops.for (size 0) n1 (fun h1 i -> live h1 a /\ live h1 b /\ live h1 c /\ modifies1 c h0 h1 /\ i <= v n1 /\ (forall (i0:nat{i0 < i}) (j:nat{j < v n2}). get h1 c i0 j == f (get h0 a i0 j) (get h0 b i0 j)) /\ (forall (i0:nat{i <= i0 /\ i0 < v n1}) (j:nat{j < v n2}). get h1 c i0 j == get h0 c i0 j) ) (fun i -> let h1 = ST.get() in Lib.Loops.for (size 0) n2 (fun h2 j -> map2_inner_inv h0 h1 h2 f a b c i j) (fun j -> map2_inner h0 h1 f a b c i j) ); let h2 = ST.get() in M.extensionality (as_matrix h2 c) (M.map2 f (as_matrix h0 a) (as_matrix h0 b)) val matrix_add: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> Stack unit (requires fun h -> live h a /\ live h b /\ disjoint a b) (ensures fun h0 r h1 -> modifies1 a h0 h1 /\ as_matrix h1 a == M.add (as_matrix h0 a) (as_matrix h0 b)) [@"c_inline"] let matrix_add #n1 #n2 a b = map2 add_mod a b a val matrix_sub: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> Stack unit (requires fun h -> live h a /\ live h b /\ disjoint a b) (ensures fun h0 r h1 -> modifies1 b h0 h1 /\ as_matrix h1 b == M.sub (as_matrix h0 a) (as_matrix h0 b)) [@"c_inline"] let matrix_sub #n1 #n2 a b = (* Use the in-place variant above by flipping the arguments of [sub_mod] *) (* Requires appplying extensionality *) let h0 = ST.get() in [@ inline_let ] let sub_mod_flipped x y = sub_mod y x in map2 sub_mod_flipped b a b; let h1 = ST.get() in M.extensionality (as_matrix h1 b) (M.sub (as_matrix h0 a) (as_matrix h0 b)) #push-options "--fuel 1" inline_for_extraction noextract private val mul_inner: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> #n3:size_t{v n2 * v n3 <= max_size_t /\ v n1 * v n3 <= max_size_t} -> a:matrix_t n1 n2 -> b:matrix_t n2 n3 -> i:size_t{v i < v n1} -> k:size_t{v k < v n3} -> Stack uint16 (requires fun h -> live h a /\ live h b) (ensures fun h0 r h1 -> modifies loc_none h0 h1 /\ r == M.mul_inner (as_matrix h0 a) (as_matrix h0 b) (v i) (v k)) let mul_inner #n1 #n2 #n3 a b i k = push_frame(); let h0 = ST.get() in [@ inline_let ] let f l = get h0 a (v i) l *. get h0 b l (v k) in let res = create #uint16 (size 1) (u16 0) in let h1 = ST.get() in Lib.Loops.for (size 0) n2 (fun h2 j -> live h1 res /\ live h2 res /\ modifies1 res h1 h2 /\ bget h2 res 0 == M.sum_ #(v n2) f j) (fun j -> let aij = a.[i,j] in let bjk = b.[j,k] in let res0 = res.(size 0) in res.(size 0) <- res0 +. aij *. bjk ); let res = res.(size 0) in M.sum_extensionality (v n2) f (fun l -> get h0 a (v i) l *. get h0 b l (v k)) (v n2); assert (res == M.mul_inner (as_matrix h0 a) (as_matrix h0 b) (v i) (v k)); pop_frame(); res #pop-options private unfold val mul_inner_inv: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> #n3:size_t{v n2 * v n3 <= max_size_t /\ v n1 * v n3 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> h2:HS.mem -> a:matrix_t n1 n2 -> b:matrix_t n2 n3 -> c:matrix_t n1 n3 -> f:(k:nat{k < v n3} -> GTot uint16) -> i:size_t{v i < v n1} -> k:size_nat -> Type0 let mul_inner_inv #n1 #n2 #n3 h0 h1 h2 a b c f i k = live h2 a /\ live h2 b /\ live h2 c /\ modifies1 c h1 h2 /\ k <= v n3 /\ (forall (i1:nat{i1 < v i}) (k:nat{k < v n3}). get h2 c i1 k == get h1 c i1 k) /\ (forall (k1:nat{k1 < k}). get h2 c (v i) k1 == f k1) /\ (forall (k1:nat{k <= k1 /\ k1 < v n3}). get h2 c (v i) k1 == get h0 c (v i) k1) /\ (forall (i1:nat{v i < i1 /\ i1 < v n1}) (k:nat{k < v n3}). get h2 c i1 k == get h0 c i1 k) /\ as_matrix h0 a == as_matrix h2 a /\ as_matrix h0 b == as_matrix h2 b inline_for_extraction noextract private val mul_inner1: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> #n3:size_t{v n2 * v n3 <= max_size_t /\ v n1 * v n3 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> a:matrix_t n1 n2 -> b:matrix_t n2 n3 -> c:matrix_t n1 n3{disjoint a c /\ disjoint b c} -> i:size_t{v i < v n1} -> k:size_t{v k < v n3} -> f:(k:nat{k < v n3} -> GTot (res:uint16{res == M.sum #(v n2) (fun l -> get h0 a (v i) l *. get h0 b l k)})) -> Stack unit (requires fun h2 -> mul_inner_inv h0 h1 h2 a b c f i (v k)) (ensures fun _ _ h2 -> mul_inner_inv h0 h1 h2 a b c f i (v k + 1)) let mul_inner1 #n1 #n2 #n3 h0 h1 a b c i k f = assert (M.mul_inner (as_matrix h0 a) (as_matrix h0 b) (v i) (v k) == M.sum #(v n2) (fun l -> get h0 a (v i) l *. get h0 b l (v k))); c.[i,k] <- mul_inner a b i k; let h2 = ST.get () in assert (get h2 c (v i) (v k) == f (v k)) private val onemore: p:(nat -> Type0) -> q:(i:nat{p i} -> Type0) -> b:nat{p b} -> Lemma (requires (forall (i:nat{p i /\ i < b}). q i) /\ q b) (ensures forall (i:nat{p i /\ i <= b}). q i) let onemore p q b = () val onemore1: #n1:size_nat -> #n3:size_nat{n1 * n3 <= max_size_t} -> c:M.matrix n1 n3 -> f:(i:nat{i < n1} -> k:nat{k < n3} -> GTot uint16) -> i:size_nat{i < n1} -> Lemma (requires ((forall (i1:nat{i1 < i}) (k:nat{k < n3}). M.mget c i1 k == f i1 k) /\ (forall (k:nat{k < n3}). M.mget c i k == f i k))) (ensures (forall (i1:nat{i1 <= i}) (k:nat{k < n3}). M.mget c i1 k == f i1 k)) let onemore1 #n1 #n3 c f i = () val matrix_mul: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> #n3:size_t{v n2 * v n3 <= max_size_t /\ v n1 * v n3 <= max_size_t} -> a:matrix_t n1 n2 -> b:matrix_t n2 n3 -> c:matrix_t n1 n3 -> Stack unit (requires fun h -> live h a /\ live h b /\ live h c /\ disjoint a c /\ disjoint b c) (ensures fun h0 _ h1 -> modifies1 c h0 h1 /\ as_matrix h1 c == M.mul (as_matrix h0 a) (as_matrix h0 b)) [@"c_inline"] let matrix_mul #n1 #n2 #n3 a b c = let h0 = ST.get () in let f (i:nat{i < v n1}) (k:nat{k < v n3}) : GTot (res:uint16{res == M.sum #(v n2) (fun l -> get h0 a i l *. get h0 b l k)}) = M.sum #(v n2) (fun l -> get h0 a i l *. get h0 b l k) in Lib.Loops.for (size 0) n1 (fun h1 i -> live h1 a /\ live h1 b /\ live h1 c /\ modifies1 c h0 h1 /\ i <= v n1 /\ (forall (i1:nat{i1 < i}) (k:nat{k < v n3}). get h1 c i1 k == f i1 k) /\ (forall (i1:nat{i <= i1 /\ i1 < v n1}) (k:nat{k < v n3}). get h1 c i1 k == get h0 c i1 k)) (fun i -> let h1 = ST.get() in Lib.Loops.for (size 0) n3 (fun h2 k -> mul_inner_inv h0 h1 h2 a b c (f (v i)) i k) (fun k -> mul_inner1 h0 h1 a b c i k (f (v i))); let h1 = ST.get() in let q i1 = forall (k:nat{k < v n3}). get h1 c i1 k == f i1 k in onemore (fun i1 -> i1 < v n1) q (v i); assert (forall (i1:nat{i1 < v n1 /\ i1 <= v i}) (k:nat{k < v n3}). get h1 c i1 k == f i1 k) ); let h2 = ST.get() in M.extensionality (as_matrix h2 c) (M.mul (as_matrix h0 a) (as_matrix h0 b)) (* Special case of matrix multiplication *) (* when we have a different way of accessing to entries of the matrix S *) inline_for_extraction noextract val mget_s: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> Stack elem (requires fun h0 -> live h0 a) (ensures fun h0 x h1 -> modifies0 h0 h1 /\ x == M.mget_s (as_matrix h0 a) (v i) (v j)) let mget_s #n1 #n2 a i j = M.index_lt (v n2) (v n1) (v j) (v i); a.(j *! n1 +! i) unfold let get_s #n1 #n2 h (m:matrix_t n1 n2) i j = M.mget_s (as_matrix h m) i j #push-options "--fuel 1" inline_for_extraction noextract private val mul_inner_s: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> #n3:size_t{v n2 * v n3 <= max_size_t /\ v n1 * v n3 <= max_size_t} -> a:matrix_t n1 n2 -> b:matrix_t n2 n3 -> i:size_t{v i < v n1} -> k:size_t{v k < v n3} -> Stack uint16 (requires fun h -> live h a /\ live h b) (ensures fun h0 r h1 -> modifies0 h0 h1 /\ r == M.mul_inner_s (as_matrix h0 a) (as_matrix h0 b) (v i) (v k))
false
false
Hacl.Impl.Matrix.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "initial_ifuel": 0, "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": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val mul_inner_s: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> #n3:size_t{v n2 * v n3 <= max_size_t /\ v n1 * v n3 <= max_size_t} -> a:matrix_t n1 n2 -> b:matrix_t n2 n3 -> i:size_t{v i < v n1} -> k:size_t{v k < v n3} -> Stack uint16 (requires fun h -> live h a /\ live h b) (ensures fun h0 r h1 -> modifies0 h0 h1 /\ r == M.mul_inner_s (as_matrix h0 a) (as_matrix h0 b) (v i) (v k))
[]
Hacl.Impl.Matrix.mul_inner_s
{ "file_name": "code/frodo/Hacl.Impl.Matrix.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
a: Hacl.Impl.Matrix.matrix_t n1 n2 -> b: Hacl.Impl.Matrix.matrix_t n2 n3 -> i: Lib.IntTypes.size_t{Lib.IntTypes.v i < Lib.IntTypes.v n1} -> k: Lib.IntTypes.size_t{Lib.IntTypes.v k < Lib.IntTypes.v n3} -> FStar.HyperStack.ST.Stack Lib.IntTypes.uint16
{ "end_col": 5, "end_line": 550, "start_col": 2, "start_line": 530 }
FStar.HyperStack.ST.Stack
val mul_inner: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> #n3:size_t{v n2 * v n3 <= max_size_t /\ v n1 * v n3 <= max_size_t} -> a:matrix_t n1 n2 -> b:matrix_t n2 n3 -> i:size_t{v i < v n1} -> k:size_t{v k < v n3} -> Stack uint16 (requires fun h -> live h a /\ live h b) (ensures fun h0 r h1 -> modifies loc_none h0 h1 /\ r == M.mul_inner (as_matrix h0 a) (as_matrix h0 b) (v i) (v k))
[ { "abbrev": true, "full_module": "Spec.Frodo.Lemmas", "short_module": "Lemmas" }, { "abbrev": true, "full_module": "Spec.Matrix", "short_module": "M" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let mul_inner #n1 #n2 #n3 a b i k = push_frame(); let h0 = ST.get() in [@ inline_let ] let f l = get h0 a (v i) l *. get h0 b l (v k) in let res = create #uint16 (size 1) (u16 0) in let h1 = ST.get() in Lib.Loops.for (size 0) n2 (fun h2 j -> live h1 res /\ live h2 res /\ modifies1 res h1 h2 /\ bget h2 res 0 == M.sum_ #(v n2) f j) (fun j -> let aij = a.[i,j] in let bjk = b.[j,k] in let res0 = res.(size 0) in res.(size 0) <- res0 +. aij *. bjk ); let res = res.(size 0) in M.sum_extensionality (v n2) f (fun l -> get h0 a (v i) l *. get h0 b l (v k)) (v n2); assert (res == M.mul_inner (as_matrix h0 a) (as_matrix h0 b) (v i) (v k)); pop_frame(); res
val mul_inner: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> #n3:size_t{v n2 * v n3 <= max_size_t /\ v n1 * v n3 <= max_size_t} -> a:matrix_t n1 n2 -> b:matrix_t n2 n3 -> i:size_t{v i < v n1} -> k:size_t{v k < v n3} -> Stack uint16 (requires fun h -> live h a /\ live h b) (ensures fun h0 r h1 -> modifies loc_none h0 h1 /\ r == M.mul_inner (as_matrix h0 a) (as_matrix h0 b) (v i) (v k)) let mul_inner #n1 #n2 #n3 a b i k =
true
null
false
push_frame (); let h0 = ST.get () in [@@ inline_let ]let f l = get h0 a (v i) l *. get h0 b l (v k) in let res = create #uint16 (size 1) (u16 0) in let h1 = ST.get () in Lib.Loops.for (size 0) n2 (fun h2 j -> live h1 res /\ live h2 res /\ modifies1 res h1 h2 /\ bget h2 res 0 == M.sum_ #(v n2) f j) (fun j -> let aij = a.[ i, j ] in let bjk = b.[ j, k ] in let res0 = res.(size 0) in res.(size 0) <- res0 +. aij *. bjk); let res = res.(size 0) in M.sum_extensionality (v n2) f (fun l -> get h0 a (v i) l *. get h0 b l (v k)) (v n2); assert (res == M.mul_inner (as_matrix h0 a) (as_matrix h0 b) (v i) (v k)); pop_frame (); res
{ "checked_file": "Hacl.Impl.Matrix.fst.checked", "dependencies": [ "Spec.Matrix.fst.checked", "Spec.Frodo.Lemmas.fst.checked", "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.Loops.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Matrix.fst" }
[]
[ "Lib.IntTypes.size_t", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.Mul.op_Star", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Lib.IntTypes.max_size_t", "Prims.l_and", "Hacl.Impl.Matrix.matrix_t", "Prims.op_LessThan", "Lib.IntTypes.uint16", "Prims.unit", "FStar.HyperStack.ST.pop_frame", "Prims._assert", "Prims.eq2", "Spec.Matrix.mul_inner", "Hacl.Impl.Matrix.as_matrix", "Spec.Matrix.sum_extensionality", "Lib.IntTypes.size_nat", "Lib.IntTypes.op_Star_Dot", "Lib.IntTypes.U16", "Lib.IntTypes.SEC", "Hacl.Impl.Matrix.get", "Lib.IntTypes.int_t", "Lib.Buffer.op_Array_Access", "Lib.Buffer.MUT", "Lib.IntTypes.size", "Lib.Loops.for", "FStar.Monotonic.HyperStack.mem", "Prims.nat", "Lib.Buffer.live", "Lib.Buffer.modifies1", "Lib.Buffer.bget", "Spec.Matrix.sum_", "Lib.Buffer.op_Array_Assignment", "Lib.IntTypes.op_Plus_Dot", "Hacl.Impl.Matrix.op_String_Access", "FStar.Pervasives.Native.Mktuple2", "Hacl.Impl.Matrix.elem", "FStar.HyperStack.ST.get", "Lib.Buffer.lbuffer_t", "Lib.IntTypes.mk_int", "Lib.Buffer.create", "Lib.IntTypes.u16", "Lib.Buffer.lbuffer", "Prims.op_Subtraction", "Prims.pow2", "FStar.HyperStack.ST.push_frame" ]
[]
module Hacl.Impl.Matrix open FStar.HyperStack.ST open FStar.Mul open LowStar.BufferOps open LowStar.Buffer open Lib.IntTypes open Lib.Buffer open Lib.ByteBuffer module HS = FStar.HyperStack module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module Loops = Lib.LoopCombinators module M = Spec.Matrix module Lemmas = Spec.Frodo.Lemmas #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" unfold let elem = uint16 unfold let lbytes len = lbuffer uint8 len unfold let matrix_t (n1:size_t) (n2:size_t{v n1 * v n2 <= max_size_t}) = lbuffer elem (n1 *! n2) unfold let as_matrix #n1 #n2 h (m:matrix_t n1 n2) : GTot (M.matrix (v n1) (v n2)) = as_seq h m inline_for_extraction noextract val matrix_create: n1:size_t -> n2:size_t{0 < v n1 * v n2 /\ v n1 * v n2 <= max_size_t} -> StackInline (matrix_t n1 n2) (requires fun h0 -> True) (ensures fun h0 a h1 -> stack_allocated a h0 h1 (as_matrix h1 a) /\ as_matrix h1 a == M.create (v n1) (v n2)) let matrix_create n1 n2 = [@inline_let] let len = size (normalize_term (v n1 * v n2)) in create len (u16 0) inline_for_extraction noextract val mget: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> Stack elem (requires fun h0 -> live h0 a) (ensures fun h0 x h1 -> modifies loc_none h0 h1 /\ x == M.mget (as_matrix h0 a) (v i) (v j)) let mget #n1 #n2 a i j = M.index_lt (v n1) (v n2) (v i) (v j); a.(i *! n2 +! j) inline_for_extraction noextract val mset: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> x:elem -> Stack unit (requires fun h0 -> live h0 a) (ensures fun h0 _ h1 -> modifies1 a h0 h1 /\ as_matrix h1 a == M.mset (as_matrix h0 a) (v i) (v j) x) let mset #n1 #n2 a i j x = M.index_lt (v n1) (v n2) (v i) (v j); a.(i *! n2 +! j) <- x noextract unfold val op_String_Access (#n1:size_t) (#n2:size_t{v n1 * v n2 <= max_size_t}) (m:matrix_t n1 n2) (ij:(size_t & size_t){let i, j = ij in v i < v n1 /\ v j < v n2}) : Stack elem (requires fun h0 -> live h0 m) (ensures fun h0 x h1 -> let i, j = ij in modifies loc_none h0 h1 /\ x == M.mget (as_matrix h0 m) (v i) (v j)) let op_String_Access #n1 #n2 m (i,j) = mget m i j noextract unfold val op_String_Assignment (#n1:size_t) (#n2:size_t{v n1 * v n2 <= max_size_t}) (m:matrix_t n1 n2) (ij:(size_t & size_t){let i, j = ij in v i < v n1 /\ v j < v n2}) (x:elem) : Stack unit (requires fun h0 -> live h0 m) (ensures fun h0 _ h1 -> let i, j = ij in modifies1 m h0 h1 /\ live h1 m /\ as_matrix h1 m == M.mset (as_matrix h0 m) (v i) (v j) x) let op_String_Assignment #n1 #n2 m (i,j) x = mset m i j x unfold let get #n1 #n2 h (m:matrix_t n1 n2) i j = M.mget (as_matrix h m) i j private unfold val map_inner_inv: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> h2:HS.mem -> f:(elem -> elem) -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_nat -> Type0 let map_inner_inv #n1 #n2 h0 h1 h2 f a c i j = live h2 a /\ live h2 c /\ modifies1 c h1 h2 /\ j <= v n2 /\ (forall (i0:nat{i0 < v i}) (j:nat{j < v n2}). get h2 c i0 j == get h1 c i0 j) /\ (forall (j0:nat{j0 < j}). get h2 c (v i) j0 == f (get h0 a (v i) j0)) /\ (forall (j0:nat{j <= j0 /\ j0 < v n2}). get h2 c (v i) j0 == get h0 c (v i) j0) /\ (forall (i0:nat{v i < i0 /\ i0 < v n1}) (j:nat{j < v n2}). get h2 c i0 j == get h0 c i0 j) inline_for_extraction noextract private val map_inner: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> f:(elem -> elem) -> a:matrix_t n1 n2 -> c:matrix_t n1 n2{a == c} -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> Stack unit (requires fun h2 -> map_inner_inv h0 h1 h2 f a c i (v j)) (ensures fun _ _ h2 -> map_inner_inv h0 h1 h2 f a c i (v j + 1)) let map_inner #n1 #n2 h0 h1 f a c i j = c.[i,j] <- f a.[i,j] inline_for_extraction val map: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> f:(uint16 -> uint16) -> a:matrix_t n1 n2 -> c:matrix_t n1 n2 -> Stack unit (requires fun h0 -> live h0 a /\ live h0 c /\ a == c) (ensures fun h0 _ h1 -> modifies1 c h0 h1 /\ as_matrix h1 c == M.map #(v n1) #(v n2) f (as_matrix h0 a)) let map #n1 #n2 f a c = let h0 = ST.get () in Lib.Loops.for (size 0) n1 (fun h1 i -> live h1 a /\ live h1 c /\ modifies1 c h0 h1 /\ i <= v n1 /\ (forall (i0:nat{i0 < i}) (j:nat{j < v n2}). get h1 c i0 j == f (get h0 a i0 j)) /\ (forall (i0:nat{i <= i0 /\ i0 < v n1}) (j:nat{j < v n2}). get h1 c i0 j == get h0 c i0 j) ) (fun i -> let h1 = ST.get() in Lib.Loops.for (size 0) n2 (fun h2 j -> map_inner_inv h0 h1 h2 f a c i j) (fun j -> map_inner h0 h1 f a c i j) ); let h2 = ST.get () in M.extensionality (as_matrix h2 c) (M.map f (as_matrix h0 a)) inline_for_extraction noextract val mod_pow2_felem: logq:size_t{0 < v logq /\ v logq < 16} -> a:uint16 -> Pure uint16 (requires True) (ensures fun r -> r == M.mod_pow2_felem (v logq) a) let mod_pow2_felem logq a = a &. ((u16 1 <<. logq) -. u16 1) val mod_pow2: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> logq:size_t{0 < v logq /\ v logq <= 16} -> a:matrix_t n1 n2 -> Stack unit (requires fun h -> live h a) (ensures fun h0 _ h1 -> modifies1 a h0 h1 /\ as_matrix h1 a == M.mod_pow2 (v logq) (as_matrix h0 a)) [@"c_inline"] let mod_pow2 #n1 #n2 logq a = if logq <. 16ul then begin let h0 = ST.get () in map (mod_pow2_felem logq) a a; M.extensionality (M.map #(v n1) #(v n2) (mod_pow2_felem logq) (as_matrix h0 a)) (M.map #(v n1) #(v n2) (M.mod_pow2_felem (v logq)) (as_matrix h0 a)) end private unfold val map2_inner_inv: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> h2:HS.mem -> f:(elem -> elem -> elem) -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> c:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_nat -> Type0 let map2_inner_inv #n1 #n2 h0 h1 h2 f a b c i j = live h2 a /\ live h2 b /\ live h2 c /\ modifies1 c h1 h2 /\ j <= v n2 /\ (forall (i0:nat{i0 < v i}) (j:nat{j < v n2}). get h2 c i0 j == get h1 c i0 j) /\ (forall (j0:nat{j0 < j}). get h2 c (v i) j0 == f (get h0 a (v i) j0) (get h2 b (v i) j0)) /\ (forall (j0:nat{j <= j0 /\ j0 < v n2}). get h2 c (v i) j0 == get h0 c (v i) j0) /\ (forall (i0:nat{v i < i0 /\ i0 < v n1}) (j:nat{j < v n2}). get h2 c i0 j == get h0 c i0 j) inline_for_extraction noextract private val map2_inner: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> f:(elem -> elem -> elem) -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> c:matrix_t n1 n2{a == c /\ disjoint b c} -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> Stack unit (requires fun h2 -> map2_inner_inv h0 h1 h2 f a b c i (v j)) (ensures fun _ _ h2 -> map2_inner_inv h0 h1 h2 f a b c i (v j + 1)) let map2_inner #n1 #n2 h0 h1 f a b c i j = c.[i,j] <- f a.[i,j] b.[i,j] /// In-place [map2], a == map2 f a b /// /// A non in-place variant can be obtained by weakening the pre-condition to disjoint a c, /// or the two variants can be merged by requiring (a == c \/ disjoint a c) instead of a == c /// See commit 91916b8372fa3522061eff5a42d0ebd1d19a8a49 inline_for_extraction val map2: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> f:(uint16 -> uint16 -> uint16) -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> c:matrix_t n1 n2 -> Stack unit (requires fun h0 -> live h0 a /\ live h0 b /\ live h0 c /\ a == c /\ disjoint b c) (ensures fun h0 _ h1 -> modifies1 c h0 h1 /\ as_matrix h1 c == M.map2 #(v n1) #(v n2) f (as_matrix h0 a) (as_matrix h0 b)) let map2 #n1 #n2 f a b c = let h0 = ST.get () in Lib.Loops.for (size 0) n1 (fun h1 i -> live h1 a /\ live h1 b /\ live h1 c /\ modifies1 c h0 h1 /\ i <= v n1 /\ (forall (i0:nat{i0 < i}) (j:nat{j < v n2}). get h1 c i0 j == f (get h0 a i0 j) (get h0 b i0 j)) /\ (forall (i0:nat{i <= i0 /\ i0 < v n1}) (j:nat{j < v n2}). get h1 c i0 j == get h0 c i0 j) ) (fun i -> let h1 = ST.get() in Lib.Loops.for (size 0) n2 (fun h2 j -> map2_inner_inv h0 h1 h2 f a b c i j) (fun j -> map2_inner h0 h1 f a b c i j) ); let h2 = ST.get() in M.extensionality (as_matrix h2 c) (M.map2 f (as_matrix h0 a) (as_matrix h0 b)) val matrix_add: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> Stack unit (requires fun h -> live h a /\ live h b /\ disjoint a b) (ensures fun h0 r h1 -> modifies1 a h0 h1 /\ as_matrix h1 a == M.add (as_matrix h0 a) (as_matrix h0 b)) [@"c_inline"] let matrix_add #n1 #n2 a b = map2 add_mod a b a val matrix_sub: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> Stack unit (requires fun h -> live h a /\ live h b /\ disjoint a b) (ensures fun h0 r h1 -> modifies1 b h0 h1 /\ as_matrix h1 b == M.sub (as_matrix h0 a) (as_matrix h0 b)) [@"c_inline"] let matrix_sub #n1 #n2 a b = (* Use the in-place variant above by flipping the arguments of [sub_mod] *) (* Requires appplying extensionality *) let h0 = ST.get() in [@ inline_let ] let sub_mod_flipped x y = sub_mod y x in map2 sub_mod_flipped b a b; let h1 = ST.get() in M.extensionality (as_matrix h1 b) (M.sub (as_matrix h0 a) (as_matrix h0 b)) #push-options "--fuel 1" inline_for_extraction noextract private val mul_inner: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> #n3:size_t{v n2 * v n3 <= max_size_t /\ v n1 * v n3 <= max_size_t} -> a:matrix_t n1 n2 -> b:matrix_t n2 n3 -> i:size_t{v i < v n1} -> k:size_t{v k < v n3} -> Stack uint16 (requires fun h -> live h a /\ live h b) (ensures fun h0 r h1 -> modifies loc_none h0 h1 /\ r == M.mul_inner (as_matrix h0 a) (as_matrix h0 b) (v i) (v k))
false
false
Hacl.Impl.Matrix.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "initial_ifuel": 0, "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": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val mul_inner: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> #n3:size_t{v n2 * v n3 <= max_size_t /\ v n1 * v n3 <= max_size_t} -> a:matrix_t n1 n2 -> b:matrix_t n2 n3 -> i:size_t{v i < v n1} -> k:size_t{v k < v n3} -> Stack uint16 (requires fun h -> live h a /\ live h b) (ensures fun h0 r h1 -> modifies loc_none h0 h1 /\ r == M.mul_inner (as_matrix h0 a) (as_matrix h0 b) (v i) (v k))
[]
Hacl.Impl.Matrix.mul_inner
{ "file_name": "code/frodo/Hacl.Impl.Matrix.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
a: Hacl.Impl.Matrix.matrix_t n1 n2 -> b: Hacl.Impl.Matrix.matrix_t n2 n3 -> i: Lib.IntTypes.size_t{Lib.IntTypes.v i < Lib.IntTypes.v n1} -> k: Lib.IntTypes.size_t{Lib.IntTypes.v k < Lib.IntTypes.v n3} -> FStar.HyperStack.ST.Stack Lib.IntTypes.uint16
{ "end_col": 5, "end_line": 374, "start_col": 2, "start_line": 353 }
FStar.HyperStack.ST.Stack
val matrix_mul_s: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> #n3:size_t{v n2 * v n3 <= max_size_t /\ v n1 * v n3 <= max_size_t} -> a:matrix_t n1 n2 -> b:matrix_t n2 n3 -> c:matrix_t n1 n3 -> Stack unit (requires fun h -> live h a /\ live h b /\ live h c /\ disjoint a c /\ disjoint b c) (ensures fun h0 _ h1 -> modifies1 c h0 h1 /\ as_matrix h1 c == M.mul_s (as_matrix h0 a) (as_matrix h0 b))
[ { "abbrev": true, "full_module": "Spec.Frodo.Lemmas", "short_module": "Lemmas" }, { "abbrev": true, "full_module": "Spec.Matrix", "short_module": "M" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let matrix_mul_s #n1 #n2 #n3 a b c = let h0 = ST.get () in let f (i:nat{i < v n1}) (k:nat{k < v n3}) : GTot (res:uint16{res == M.sum #(v n2) (fun l -> get h0 a i l *. get_s h0 b l k)}) = M.sum #(v n2) (fun l -> get h0 a i l *. get_s h0 b l k) in Lib.Loops.for (size 0) n1 (fun h1 i -> live h1 a /\ live h1 b /\ live h1 c /\ modifies1 c h0 h1 /\ i <= v n1 /\ (forall (i1:nat{i1 < i}) (k:nat{k < v n3}). get h1 c i1 k == f i1 k) /\ (forall (i1:nat{i <= i1 /\ i1 < v n1}) (k:nat{k < v n3}). get h1 c i1 k == get h0 c i1 k)) (fun i -> let h1 = ST.get() in Lib.Loops.for (size 0) n3 (fun h2 k -> mul_inner_inv h0 h1 h2 a b c (f (v i)) i k) (fun k -> mul_inner1_s h0 h1 a b c i k (f (v i))); let h1 = ST.get() in let q i1 = forall k. get h1 c i1 k == f i1 k in onemore (fun i1 -> i1 < v n1) q (v i); assert (forall (i1:nat{i1 < v n1 /\ i1 <= v i}) (k:nat{k < v n3}). get h1 c i1 k == f i1 k) ); let h2 = ST.get() in M.extensionality (as_matrix h2 c) (M.mul_s (as_matrix h0 a) (as_matrix h0 b))
val matrix_mul_s: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> #n3:size_t{v n2 * v n3 <= max_size_t /\ v n1 * v n3 <= max_size_t} -> a:matrix_t n1 n2 -> b:matrix_t n2 n3 -> c:matrix_t n1 n3 -> Stack unit (requires fun h -> live h a /\ live h b /\ live h c /\ disjoint a c /\ disjoint b c) (ensures fun h0 _ h1 -> modifies1 c h0 h1 /\ as_matrix h1 c == M.mul_s (as_matrix h0 a) (as_matrix h0 b)) let matrix_mul_s #n1 #n2 #n3 a b c =
true
null
false
let h0 = ST.get () in let f (i: nat{i < v n1}) (k: nat{k < v n3}) : GTot (res: uint16{res == M.sum #(v n2) (fun l -> get h0 a i l *. get_s h0 b l k)}) = M.sum #(v n2) (fun l -> get h0 a i l *. get_s h0 b l k) in Lib.Loops.for (size 0) n1 (fun h1 i -> live h1 a /\ live h1 b /\ live h1 c /\ modifies1 c h0 h1 /\ i <= v n1 /\ (forall (i1: nat{i1 < i}) (k: nat{k < v n3}). get h1 c i1 k == f i1 k) /\ (forall (i1: nat{i <= i1 /\ i1 < v n1}) (k: nat{k < v n3}). get h1 c i1 k == get h0 c i1 k)) (fun i -> let h1 = ST.get () in Lib.Loops.for (size 0) n3 (fun h2 k -> mul_inner_inv h0 h1 h2 a b c (f (v i)) i k) (fun k -> mul_inner1_s h0 h1 a b c i k (f (v i))); let h1 = ST.get () in let q i1 = forall k. get h1 c i1 k == f i1 k in onemore (fun i1 -> i1 < v n1) q (v i); assert (forall (i1: nat{i1 < v n1 /\ i1 <= v i}) (k: nat{k < v n3}). get h1 c i1 k == f i1 k)); let h2 = ST.get () in M.extensionality (as_matrix h2 c) (M.mul_s (as_matrix h0 a) (as_matrix h0 b))
{ "checked_file": "Hacl.Impl.Matrix.fst.checked", "dependencies": [ "Spec.Matrix.fst.checked", "Spec.Frodo.Lemmas.fst.checked", "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.Loops.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Matrix.fst" }
[]
[ "Lib.IntTypes.size_t", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.Mul.op_Star", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Lib.IntTypes.max_size_t", "Prims.l_and", "Hacl.Impl.Matrix.matrix_t", "Spec.Matrix.extensionality", "Hacl.Impl.Matrix.as_matrix", "Spec.Matrix.mul_s", "Prims.unit", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "Lib.Loops.for", "Lib.IntTypes.size", "Prims.nat", "Lib.Buffer.live", "Lib.Buffer.MUT", "Hacl.Impl.Matrix.elem", "Lib.Buffer.modifies1", "Prims.l_Forall", "Prims.op_LessThan", "Prims.eq2", "Lib.IntTypes.uint16", "Hacl.Impl.Matrix.get", "Spec.Matrix.elem", "Prims._assert", "Hacl.Impl.Matrix.onemore", "Prims.op_Subtraction", "Prims.pow2", "Prims.logical", "Hacl.Impl.Matrix.mul_inner_inv", "Hacl.Impl.Matrix.mul_inner1_s", "Lib.IntTypes.int_t", "Lib.IntTypes.U16", "Lib.IntTypes.SEC", "Spec.Matrix.sum", "Lib.IntTypes.mul_mod", "Spec.Matrix.mget", "Lib.Buffer.as_seq", "Lib.IntTypes.mul", "Spec.Matrix.mget_s", "Lib.IntTypes.size_nat", "Lib.IntTypes.op_Star_Dot", "Hacl.Impl.Matrix.get_s" ]
[]
module Hacl.Impl.Matrix open FStar.HyperStack.ST open FStar.Mul open LowStar.BufferOps open LowStar.Buffer open Lib.IntTypes open Lib.Buffer open Lib.ByteBuffer module HS = FStar.HyperStack module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module Loops = Lib.LoopCombinators module M = Spec.Matrix module Lemmas = Spec.Frodo.Lemmas #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" unfold let elem = uint16 unfold let lbytes len = lbuffer uint8 len unfold let matrix_t (n1:size_t) (n2:size_t{v n1 * v n2 <= max_size_t}) = lbuffer elem (n1 *! n2) unfold let as_matrix #n1 #n2 h (m:matrix_t n1 n2) : GTot (M.matrix (v n1) (v n2)) = as_seq h m inline_for_extraction noextract val matrix_create: n1:size_t -> n2:size_t{0 < v n1 * v n2 /\ v n1 * v n2 <= max_size_t} -> StackInline (matrix_t n1 n2) (requires fun h0 -> True) (ensures fun h0 a h1 -> stack_allocated a h0 h1 (as_matrix h1 a) /\ as_matrix h1 a == M.create (v n1) (v n2)) let matrix_create n1 n2 = [@inline_let] let len = size (normalize_term (v n1 * v n2)) in create len (u16 0) inline_for_extraction noextract val mget: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> Stack elem (requires fun h0 -> live h0 a) (ensures fun h0 x h1 -> modifies loc_none h0 h1 /\ x == M.mget (as_matrix h0 a) (v i) (v j)) let mget #n1 #n2 a i j = M.index_lt (v n1) (v n2) (v i) (v j); a.(i *! n2 +! j) inline_for_extraction noextract val mset: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> x:elem -> Stack unit (requires fun h0 -> live h0 a) (ensures fun h0 _ h1 -> modifies1 a h0 h1 /\ as_matrix h1 a == M.mset (as_matrix h0 a) (v i) (v j) x) let mset #n1 #n2 a i j x = M.index_lt (v n1) (v n2) (v i) (v j); a.(i *! n2 +! j) <- x noextract unfold val op_String_Access (#n1:size_t) (#n2:size_t{v n1 * v n2 <= max_size_t}) (m:matrix_t n1 n2) (ij:(size_t & size_t){let i, j = ij in v i < v n1 /\ v j < v n2}) : Stack elem (requires fun h0 -> live h0 m) (ensures fun h0 x h1 -> let i, j = ij in modifies loc_none h0 h1 /\ x == M.mget (as_matrix h0 m) (v i) (v j)) let op_String_Access #n1 #n2 m (i,j) = mget m i j noextract unfold val op_String_Assignment (#n1:size_t) (#n2:size_t{v n1 * v n2 <= max_size_t}) (m:matrix_t n1 n2) (ij:(size_t & size_t){let i, j = ij in v i < v n1 /\ v j < v n2}) (x:elem) : Stack unit (requires fun h0 -> live h0 m) (ensures fun h0 _ h1 -> let i, j = ij in modifies1 m h0 h1 /\ live h1 m /\ as_matrix h1 m == M.mset (as_matrix h0 m) (v i) (v j) x) let op_String_Assignment #n1 #n2 m (i,j) x = mset m i j x unfold let get #n1 #n2 h (m:matrix_t n1 n2) i j = M.mget (as_matrix h m) i j private unfold val map_inner_inv: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> h2:HS.mem -> f:(elem -> elem) -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_nat -> Type0 let map_inner_inv #n1 #n2 h0 h1 h2 f a c i j = live h2 a /\ live h2 c /\ modifies1 c h1 h2 /\ j <= v n2 /\ (forall (i0:nat{i0 < v i}) (j:nat{j < v n2}). get h2 c i0 j == get h1 c i0 j) /\ (forall (j0:nat{j0 < j}). get h2 c (v i) j0 == f (get h0 a (v i) j0)) /\ (forall (j0:nat{j <= j0 /\ j0 < v n2}). get h2 c (v i) j0 == get h0 c (v i) j0) /\ (forall (i0:nat{v i < i0 /\ i0 < v n1}) (j:nat{j < v n2}). get h2 c i0 j == get h0 c i0 j) inline_for_extraction noextract private val map_inner: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> f:(elem -> elem) -> a:matrix_t n1 n2 -> c:matrix_t n1 n2{a == c} -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> Stack unit (requires fun h2 -> map_inner_inv h0 h1 h2 f a c i (v j)) (ensures fun _ _ h2 -> map_inner_inv h0 h1 h2 f a c i (v j + 1)) let map_inner #n1 #n2 h0 h1 f a c i j = c.[i,j] <- f a.[i,j] inline_for_extraction val map: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> f:(uint16 -> uint16) -> a:matrix_t n1 n2 -> c:matrix_t n1 n2 -> Stack unit (requires fun h0 -> live h0 a /\ live h0 c /\ a == c) (ensures fun h0 _ h1 -> modifies1 c h0 h1 /\ as_matrix h1 c == M.map #(v n1) #(v n2) f (as_matrix h0 a)) let map #n1 #n2 f a c = let h0 = ST.get () in Lib.Loops.for (size 0) n1 (fun h1 i -> live h1 a /\ live h1 c /\ modifies1 c h0 h1 /\ i <= v n1 /\ (forall (i0:nat{i0 < i}) (j:nat{j < v n2}). get h1 c i0 j == f (get h0 a i0 j)) /\ (forall (i0:nat{i <= i0 /\ i0 < v n1}) (j:nat{j < v n2}). get h1 c i0 j == get h0 c i0 j) ) (fun i -> let h1 = ST.get() in Lib.Loops.for (size 0) n2 (fun h2 j -> map_inner_inv h0 h1 h2 f a c i j) (fun j -> map_inner h0 h1 f a c i j) ); let h2 = ST.get () in M.extensionality (as_matrix h2 c) (M.map f (as_matrix h0 a)) inline_for_extraction noextract val mod_pow2_felem: logq:size_t{0 < v logq /\ v logq < 16} -> a:uint16 -> Pure uint16 (requires True) (ensures fun r -> r == M.mod_pow2_felem (v logq) a) let mod_pow2_felem logq a = a &. ((u16 1 <<. logq) -. u16 1) val mod_pow2: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> logq:size_t{0 < v logq /\ v logq <= 16} -> a:matrix_t n1 n2 -> Stack unit (requires fun h -> live h a) (ensures fun h0 _ h1 -> modifies1 a h0 h1 /\ as_matrix h1 a == M.mod_pow2 (v logq) (as_matrix h0 a)) [@"c_inline"] let mod_pow2 #n1 #n2 logq a = if logq <. 16ul then begin let h0 = ST.get () in map (mod_pow2_felem logq) a a; M.extensionality (M.map #(v n1) #(v n2) (mod_pow2_felem logq) (as_matrix h0 a)) (M.map #(v n1) #(v n2) (M.mod_pow2_felem (v logq)) (as_matrix h0 a)) end private unfold val map2_inner_inv: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> h2:HS.mem -> f:(elem -> elem -> elem) -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> c:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_nat -> Type0 let map2_inner_inv #n1 #n2 h0 h1 h2 f a b c i j = live h2 a /\ live h2 b /\ live h2 c /\ modifies1 c h1 h2 /\ j <= v n2 /\ (forall (i0:nat{i0 < v i}) (j:nat{j < v n2}). get h2 c i0 j == get h1 c i0 j) /\ (forall (j0:nat{j0 < j}). get h2 c (v i) j0 == f (get h0 a (v i) j0) (get h2 b (v i) j0)) /\ (forall (j0:nat{j <= j0 /\ j0 < v n2}). get h2 c (v i) j0 == get h0 c (v i) j0) /\ (forall (i0:nat{v i < i0 /\ i0 < v n1}) (j:nat{j < v n2}). get h2 c i0 j == get h0 c i0 j) inline_for_extraction noextract private val map2_inner: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> f:(elem -> elem -> elem) -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> c:matrix_t n1 n2{a == c /\ disjoint b c} -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> Stack unit (requires fun h2 -> map2_inner_inv h0 h1 h2 f a b c i (v j)) (ensures fun _ _ h2 -> map2_inner_inv h0 h1 h2 f a b c i (v j + 1)) let map2_inner #n1 #n2 h0 h1 f a b c i j = c.[i,j] <- f a.[i,j] b.[i,j] /// In-place [map2], a == map2 f a b /// /// A non in-place variant can be obtained by weakening the pre-condition to disjoint a c, /// or the two variants can be merged by requiring (a == c \/ disjoint a c) instead of a == c /// See commit 91916b8372fa3522061eff5a42d0ebd1d19a8a49 inline_for_extraction val map2: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> f:(uint16 -> uint16 -> uint16) -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> c:matrix_t n1 n2 -> Stack unit (requires fun h0 -> live h0 a /\ live h0 b /\ live h0 c /\ a == c /\ disjoint b c) (ensures fun h0 _ h1 -> modifies1 c h0 h1 /\ as_matrix h1 c == M.map2 #(v n1) #(v n2) f (as_matrix h0 a) (as_matrix h0 b)) let map2 #n1 #n2 f a b c = let h0 = ST.get () in Lib.Loops.for (size 0) n1 (fun h1 i -> live h1 a /\ live h1 b /\ live h1 c /\ modifies1 c h0 h1 /\ i <= v n1 /\ (forall (i0:nat{i0 < i}) (j:nat{j < v n2}). get h1 c i0 j == f (get h0 a i0 j) (get h0 b i0 j)) /\ (forall (i0:nat{i <= i0 /\ i0 < v n1}) (j:nat{j < v n2}). get h1 c i0 j == get h0 c i0 j) ) (fun i -> let h1 = ST.get() in Lib.Loops.for (size 0) n2 (fun h2 j -> map2_inner_inv h0 h1 h2 f a b c i j) (fun j -> map2_inner h0 h1 f a b c i j) ); let h2 = ST.get() in M.extensionality (as_matrix h2 c) (M.map2 f (as_matrix h0 a) (as_matrix h0 b)) val matrix_add: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> Stack unit (requires fun h -> live h a /\ live h b /\ disjoint a b) (ensures fun h0 r h1 -> modifies1 a h0 h1 /\ as_matrix h1 a == M.add (as_matrix h0 a) (as_matrix h0 b)) [@"c_inline"] let matrix_add #n1 #n2 a b = map2 add_mod a b a val matrix_sub: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> Stack unit (requires fun h -> live h a /\ live h b /\ disjoint a b) (ensures fun h0 r h1 -> modifies1 b h0 h1 /\ as_matrix h1 b == M.sub (as_matrix h0 a) (as_matrix h0 b)) [@"c_inline"] let matrix_sub #n1 #n2 a b = (* Use the in-place variant above by flipping the arguments of [sub_mod] *) (* Requires appplying extensionality *) let h0 = ST.get() in [@ inline_let ] let sub_mod_flipped x y = sub_mod y x in map2 sub_mod_flipped b a b; let h1 = ST.get() in M.extensionality (as_matrix h1 b) (M.sub (as_matrix h0 a) (as_matrix h0 b)) #push-options "--fuel 1" inline_for_extraction noextract private val mul_inner: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> #n3:size_t{v n2 * v n3 <= max_size_t /\ v n1 * v n3 <= max_size_t} -> a:matrix_t n1 n2 -> b:matrix_t n2 n3 -> i:size_t{v i < v n1} -> k:size_t{v k < v n3} -> Stack uint16 (requires fun h -> live h a /\ live h b) (ensures fun h0 r h1 -> modifies loc_none h0 h1 /\ r == M.mul_inner (as_matrix h0 a) (as_matrix h0 b) (v i) (v k)) let mul_inner #n1 #n2 #n3 a b i k = push_frame(); let h0 = ST.get() in [@ inline_let ] let f l = get h0 a (v i) l *. get h0 b l (v k) in let res = create #uint16 (size 1) (u16 0) in let h1 = ST.get() in Lib.Loops.for (size 0) n2 (fun h2 j -> live h1 res /\ live h2 res /\ modifies1 res h1 h2 /\ bget h2 res 0 == M.sum_ #(v n2) f j) (fun j -> let aij = a.[i,j] in let bjk = b.[j,k] in let res0 = res.(size 0) in res.(size 0) <- res0 +. aij *. bjk ); let res = res.(size 0) in M.sum_extensionality (v n2) f (fun l -> get h0 a (v i) l *. get h0 b l (v k)) (v n2); assert (res == M.mul_inner (as_matrix h0 a) (as_matrix h0 b) (v i) (v k)); pop_frame(); res #pop-options private unfold val mul_inner_inv: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> #n3:size_t{v n2 * v n3 <= max_size_t /\ v n1 * v n3 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> h2:HS.mem -> a:matrix_t n1 n2 -> b:matrix_t n2 n3 -> c:matrix_t n1 n3 -> f:(k:nat{k < v n3} -> GTot uint16) -> i:size_t{v i < v n1} -> k:size_nat -> Type0 let mul_inner_inv #n1 #n2 #n3 h0 h1 h2 a b c f i k = live h2 a /\ live h2 b /\ live h2 c /\ modifies1 c h1 h2 /\ k <= v n3 /\ (forall (i1:nat{i1 < v i}) (k:nat{k < v n3}). get h2 c i1 k == get h1 c i1 k) /\ (forall (k1:nat{k1 < k}). get h2 c (v i) k1 == f k1) /\ (forall (k1:nat{k <= k1 /\ k1 < v n3}). get h2 c (v i) k1 == get h0 c (v i) k1) /\ (forall (i1:nat{v i < i1 /\ i1 < v n1}) (k:nat{k < v n3}). get h2 c i1 k == get h0 c i1 k) /\ as_matrix h0 a == as_matrix h2 a /\ as_matrix h0 b == as_matrix h2 b inline_for_extraction noextract private val mul_inner1: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> #n3:size_t{v n2 * v n3 <= max_size_t /\ v n1 * v n3 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> a:matrix_t n1 n2 -> b:matrix_t n2 n3 -> c:matrix_t n1 n3{disjoint a c /\ disjoint b c} -> i:size_t{v i < v n1} -> k:size_t{v k < v n3} -> f:(k:nat{k < v n3} -> GTot (res:uint16{res == M.sum #(v n2) (fun l -> get h0 a (v i) l *. get h0 b l k)})) -> Stack unit (requires fun h2 -> mul_inner_inv h0 h1 h2 a b c f i (v k)) (ensures fun _ _ h2 -> mul_inner_inv h0 h1 h2 a b c f i (v k + 1)) let mul_inner1 #n1 #n2 #n3 h0 h1 a b c i k f = assert (M.mul_inner (as_matrix h0 a) (as_matrix h0 b) (v i) (v k) == M.sum #(v n2) (fun l -> get h0 a (v i) l *. get h0 b l (v k))); c.[i,k] <- mul_inner a b i k; let h2 = ST.get () in assert (get h2 c (v i) (v k) == f (v k)) private val onemore: p:(nat -> Type0) -> q:(i:nat{p i} -> Type0) -> b:nat{p b} -> Lemma (requires (forall (i:nat{p i /\ i < b}). q i) /\ q b) (ensures forall (i:nat{p i /\ i <= b}). q i) let onemore p q b = () val onemore1: #n1:size_nat -> #n3:size_nat{n1 * n3 <= max_size_t} -> c:M.matrix n1 n3 -> f:(i:nat{i < n1} -> k:nat{k < n3} -> GTot uint16) -> i:size_nat{i < n1} -> Lemma (requires ((forall (i1:nat{i1 < i}) (k:nat{k < n3}). M.mget c i1 k == f i1 k) /\ (forall (k:nat{k < n3}). M.mget c i k == f i k))) (ensures (forall (i1:nat{i1 <= i}) (k:nat{k < n3}). M.mget c i1 k == f i1 k)) let onemore1 #n1 #n3 c f i = () val matrix_mul: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> #n3:size_t{v n2 * v n3 <= max_size_t /\ v n1 * v n3 <= max_size_t} -> a:matrix_t n1 n2 -> b:matrix_t n2 n3 -> c:matrix_t n1 n3 -> Stack unit (requires fun h -> live h a /\ live h b /\ live h c /\ disjoint a c /\ disjoint b c) (ensures fun h0 _ h1 -> modifies1 c h0 h1 /\ as_matrix h1 c == M.mul (as_matrix h0 a) (as_matrix h0 b)) [@"c_inline"] let matrix_mul #n1 #n2 #n3 a b c = let h0 = ST.get () in let f (i:nat{i < v n1}) (k:nat{k < v n3}) : GTot (res:uint16{res == M.sum #(v n2) (fun l -> get h0 a i l *. get h0 b l k)}) = M.sum #(v n2) (fun l -> get h0 a i l *. get h0 b l k) in Lib.Loops.for (size 0) n1 (fun h1 i -> live h1 a /\ live h1 b /\ live h1 c /\ modifies1 c h0 h1 /\ i <= v n1 /\ (forall (i1:nat{i1 < i}) (k:nat{k < v n3}). get h1 c i1 k == f i1 k) /\ (forall (i1:nat{i <= i1 /\ i1 < v n1}) (k:nat{k < v n3}). get h1 c i1 k == get h0 c i1 k)) (fun i -> let h1 = ST.get() in Lib.Loops.for (size 0) n3 (fun h2 k -> mul_inner_inv h0 h1 h2 a b c (f (v i)) i k) (fun k -> mul_inner1 h0 h1 a b c i k (f (v i))); let h1 = ST.get() in let q i1 = forall (k:nat{k < v n3}). get h1 c i1 k == f i1 k in onemore (fun i1 -> i1 < v n1) q (v i); assert (forall (i1:nat{i1 < v n1 /\ i1 <= v i}) (k:nat{k < v n3}). get h1 c i1 k == f i1 k) ); let h2 = ST.get() in M.extensionality (as_matrix h2 c) (M.mul (as_matrix h0 a) (as_matrix h0 b)) (* Special case of matrix multiplication *) (* when we have a different way of accessing to entries of the matrix S *) inline_for_extraction noextract val mget_s: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> Stack elem (requires fun h0 -> live h0 a) (ensures fun h0 x h1 -> modifies0 h0 h1 /\ x == M.mget_s (as_matrix h0 a) (v i) (v j)) let mget_s #n1 #n2 a i j = M.index_lt (v n2) (v n1) (v j) (v i); a.(j *! n1 +! i) unfold let get_s #n1 #n2 h (m:matrix_t n1 n2) i j = M.mget_s (as_matrix h m) i j #push-options "--fuel 1" inline_for_extraction noextract private val mul_inner_s: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> #n3:size_t{v n2 * v n3 <= max_size_t /\ v n1 * v n3 <= max_size_t} -> a:matrix_t n1 n2 -> b:matrix_t n2 n3 -> i:size_t{v i < v n1} -> k:size_t{v k < v n3} -> Stack uint16 (requires fun h -> live h a /\ live h b) (ensures fun h0 r h1 -> modifies0 h0 h1 /\ r == M.mul_inner_s (as_matrix h0 a) (as_matrix h0 b) (v i) (v k)) let mul_inner_s #n1 #n2 #n3 a b i k = push_frame(); let h0 = ST.get() in [@ inline_let ] let f l = get h0 a (v i) l *. get_s h0 b l (v k) in let res = create #uint16 (size 1) (u16 0) in let h1 = ST.get() in Lib.Loops.for (size 0) n2 (fun h2 j -> live h1 res /\ live h2 res /\ modifies1 res h1 h2 /\ bget h2 res 0 == M.sum_ #(v n2) f j) (fun j -> let aij = mget a i j in let bjk = mget_s b j k in let res0 = res.(size 0) in res.(size 0) <- res0 +. aij *. bjk ); let res = res.(size 0) in M.sum_extensionality (v n2) f (fun l -> get h0 a (v i) l *. get_s h0 b l (v k)) (v n2); assert (res == M.mul_inner_s (as_matrix h0 a) (as_matrix h0 b) (v i) (v k)); pop_frame(); res #pop-options inline_for_extraction noextract private val mul_inner1_s: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> #n3:size_t{v n2 * v n3 <= max_size_t /\ v n1 * v n3 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> a:matrix_t n1 n2 -> b:matrix_t n2 n3 -> c:matrix_t n1 n3{disjoint a c /\ disjoint b c} -> i:size_t{v i < v n1} -> k:size_t{v k < v n3} -> f:(k:nat{k < v n3} -> GTot (res:uint16{res == M.sum #(v n2) (fun l -> get h0 a (v i) l *. get_s h0 b l k)})) -> Stack unit (requires fun h2 -> mul_inner_inv h0 h1 h2 a b c f i (v k)) (ensures fun _ _ h2 -> mul_inner_inv h0 h1 h2 a b c f i (v k + 1)) let mul_inner1_s #n1 #n2 #n3 h0 h1 a b c i k f = assert (M.mul_inner_s (as_matrix h0 a) (as_matrix h0 b) (v i) (v k) == M.sum #(v n2) (fun l -> get h0 a (v i) l *. get_s h0 b l (v k))); mset c i k (mul_inner_s a b i k); let h2 = ST.get () in assert (get h2 c (v i) (v k) == f (v k)) val matrix_mul_s: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> #n3:size_t{v n2 * v n3 <= max_size_t /\ v n1 * v n3 <= max_size_t} -> a:matrix_t n1 n2 -> b:matrix_t n2 n3 -> c:matrix_t n1 n3 -> Stack unit (requires fun h -> live h a /\ live h b /\ live h c /\ disjoint a c /\ disjoint b c) (ensures fun h0 _ h1 -> modifies1 c h0 h1 /\ as_matrix h1 c == M.mul_s (as_matrix h0 a) (as_matrix h0 b))
false
false
Hacl.Impl.Matrix.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val matrix_mul_s: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> #n3:size_t{v n2 * v n3 <= max_size_t /\ v n1 * v n3 <= max_size_t} -> a:matrix_t n1 n2 -> b:matrix_t n2 n3 -> c:matrix_t n1 n3 -> Stack unit (requires fun h -> live h a /\ live h b /\ live h c /\ disjoint a c /\ disjoint b c) (ensures fun h0 _ h1 -> modifies1 c h0 h1 /\ as_matrix h1 c == M.mul_s (as_matrix h0 a) (as_matrix h0 b))
[]
Hacl.Impl.Matrix.matrix_mul_s
{ "file_name": "code/frodo/Hacl.Impl.Matrix.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
a: Hacl.Impl.Matrix.matrix_t n1 n2 -> b: Hacl.Impl.Matrix.matrix_t n2 n3 -> c: Hacl.Impl.Matrix.matrix_t n1 n3 -> FStar.HyperStack.ST.Stack Prims.unit
{ "end_col": 79, "end_line": 618, "start_col": 36, "start_line": 595 }
FStar.HyperStack.ST.Stack
val matrix_mul: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> #n3:size_t{v n2 * v n3 <= max_size_t /\ v n1 * v n3 <= max_size_t} -> a:matrix_t n1 n2 -> b:matrix_t n2 n3 -> c:matrix_t n1 n3 -> Stack unit (requires fun h -> live h a /\ live h b /\ live h c /\ disjoint a c /\ disjoint b c) (ensures fun h0 _ h1 -> modifies1 c h0 h1 /\ as_matrix h1 c == M.mul (as_matrix h0 a) (as_matrix h0 b))
[ { "abbrev": true, "full_module": "Spec.Frodo.Lemmas", "short_module": "Lemmas" }, { "abbrev": true, "full_module": "Spec.Matrix", "short_module": "M" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let matrix_mul #n1 #n2 #n3 a b c = let h0 = ST.get () in let f (i:nat{i < v n1}) (k:nat{k < v n3}) : GTot (res:uint16{res == M.sum #(v n2) (fun l -> get h0 a i l *. get h0 b l k)}) = M.sum #(v n2) (fun l -> get h0 a i l *. get h0 b l k) in Lib.Loops.for (size 0) n1 (fun h1 i -> live h1 a /\ live h1 b /\ live h1 c /\ modifies1 c h0 h1 /\ i <= v n1 /\ (forall (i1:nat{i1 < i}) (k:nat{k < v n3}). get h1 c i1 k == f i1 k) /\ (forall (i1:nat{i <= i1 /\ i1 < v n1}) (k:nat{k < v n3}). get h1 c i1 k == get h0 c i1 k)) (fun i -> let h1 = ST.get() in Lib.Loops.for (size 0) n3 (fun h2 k -> mul_inner_inv h0 h1 h2 a b c (f (v i)) i k) (fun k -> mul_inner1 h0 h1 a b c i k (f (v i))); let h1 = ST.get() in let q i1 = forall (k:nat{k < v n3}). get h1 c i1 k == f i1 k in onemore (fun i1 -> i1 < v n1) q (v i); assert (forall (i1:nat{i1 < v n1 /\ i1 <= v i}) (k:nat{k < v n3}). get h1 c i1 k == f i1 k) ); let h2 = ST.get() in M.extensionality (as_matrix h2 c) (M.mul (as_matrix h0 a) (as_matrix h0 b))
val matrix_mul: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> #n3:size_t{v n2 * v n3 <= max_size_t /\ v n1 * v n3 <= max_size_t} -> a:matrix_t n1 n2 -> b:matrix_t n2 n3 -> c:matrix_t n1 n3 -> Stack unit (requires fun h -> live h a /\ live h b /\ live h c /\ disjoint a c /\ disjoint b c) (ensures fun h0 _ h1 -> modifies1 c h0 h1 /\ as_matrix h1 c == M.mul (as_matrix h0 a) (as_matrix h0 b)) let matrix_mul #n1 #n2 #n3 a b c =
true
null
false
let h0 = ST.get () in let f (i: nat{i < v n1}) (k: nat{k < v n3}) : GTot (res: uint16{res == M.sum #(v n2) (fun l -> get h0 a i l *. get h0 b l k)}) = M.sum #(v n2) (fun l -> get h0 a i l *. get h0 b l k) in Lib.Loops.for (size 0) n1 (fun h1 i -> live h1 a /\ live h1 b /\ live h1 c /\ modifies1 c h0 h1 /\ i <= v n1 /\ (forall (i1: nat{i1 < i}) (k: nat{k < v n3}). get h1 c i1 k == f i1 k) /\ (forall (i1: nat{i <= i1 /\ i1 < v n1}) (k: nat{k < v n3}). get h1 c i1 k == get h0 c i1 k)) (fun i -> let h1 = ST.get () in Lib.Loops.for (size 0) n3 (fun h2 k -> mul_inner_inv h0 h1 h2 a b c (f (v i)) i k) (fun k -> mul_inner1 h0 h1 a b c i k (f (v i))); let h1 = ST.get () in let q i1 = forall (k: nat{k < v n3}). get h1 c i1 k == f i1 k in onemore (fun i1 -> i1 < v n1) q (v i); assert (forall (i1: nat{i1 < v n1 /\ i1 <= v i}) (k: nat{k < v n3}). get h1 c i1 k == f i1 k)); let h2 = ST.get () in M.extensionality (as_matrix h2 c) (M.mul (as_matrix h0 a) (as_matrix h0 b))
{ "checked_file": "Hacl.Impl.Matrix.fst.checked", "dependencies": [ "Spec.Matrix.fst.checked", "Spec.Frodo.Lemmas.fst.checked", "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.Loops.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Matrix.fst" }
[]
[ "Lib.IntTypes.size_t", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.Mul.op_Star", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Lib.IntTypes.max_size_t", "Prims.l_and", "Hacl.Impl.Matrix.matrix_t", "Spec.Matrix.extensionality", "Hacl.Impl.Matrix.as_matrix", "Spec.Matrix.mul", "Prims.unit", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "Lib.Loops.for", "Lib.IntTypes.size", "Prims.nat", "Lib.Buffer.live", "Lib.Buffer.MUT", "Hacl.Impl.Matrix.elem", "Lib.Buffer.modifies1", "Prims.l_Forall", "Prims.op_LessThan", "Prims.eq2", "Lib.IntTypes.uint16", "Hacl.Impl.Matrix.get", "Spec.Matrix.elem", "Prims._assert", "Hacl.Impl.Matrix.onemore", "Prims.op_Subtraction", "Prims.pow2", "Prims.logical", "Hacl.Impl.Matrix.mul_inner_inv", "Hacl.Impl.Matrix.mul_inner1", "Lib.IntTypes.int_t", "Lib.IntTypes.U16", "Lib.IntTypes.SEC", "Spec.Matrix.sum", "Lib.IntTypes.mul_mod", "Spec.Matrix.mget", "Lib.Buffer.as_seq", "Lib.IntTypes.mul", "Lib.IntTypes.size_nat", "Lib.IntTypes.op_Star_Dot" ]
[]
module Hacl.Impl.Matrix open FStar.HyperStack.ST open FStar.Mul open LowStar.BufferOps open LowStar.Buffer open Lib.IntTypes open Lib.Buffer open Lib.ByteBuffer module HS = FStar.HyperStack module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module Loops = Lib.LoopCombinators module M = Spec.Matrix module Lemmas = Spec.Frodo.Lemmas #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" unfold let elem = uint16 unfold let lbytes len = lbuffer uint8 len unfold let matrix_t (n1:size_t) (n2:size_t{v n1 * v n2 <= max_size_t}) = lbuffer elem (n1 *! n2) unfold let as_matrix #n1 #n2 h (m:matrix_t n1 n2) : GTot (M.matrix (v n1) (v n2)) = as_seq h m inline_for_extraction noextract val matrix_create: n1:size_t -> n2:size_t{0 < v n1 * v n2 /\ v n1 * v n2 <= max_size_t} -> StackInline (matrix_t n1 n2) (requires fun h0 -> True) (ensures fun h0 a h1 -> stack_allocated a h0 h1 (as_matrix h1 a) /\ as_matrix h1 a == M.create (v n1) (v n2)) let matrix_create n1 n2 = [@inline_let] let len = size (normalize_term (v n1 * v n2)) in create len (u16 0) inline_for_extraction noextract val mget: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> Stack elem (requires fun h0 -> live h0 a) (ensures fun h0 x h1 -> modifies loc_none h0 h1 /\ x == M.mget (as_matrix h0 a) (v i) (v j)) let mget #n1 #n2 a i j = M.index_lt (v n1) (v n2) (v i) (v j); a.(i *! n2 +! j) inline_for_extraction noextract val mset: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> x:elem -> Stack unit (requires fun h0 -> live h0 a) (ensures fun h0 _ h1 -> modifies1 a h0 h1 /\ as_matrix h1 a == M.mset (as_matrix h0 a) (v i) (v j) x) let mset #n1 #n2 a i j x = M.index_lt (v n1) (v n2) (v i) (v j); a.(i *! n2 +! j) <- x noextract unfold val op_String_Access (#n1:size_t) (#n2:size_t{v n1 * v n2 <= max_size_t}) (m:matrix_t n1 n2) (ij:(size_t & size_t){let i, j = ij in v i < v n1 /\ v j < v n2}) : Stack elem (requires fun h0 -> live h0 m) (ensures fun h0 x h1 -> let i, j = ij in modifies loc_none h0 h1 /\ x == M.mget (as_matrix h0 m) (v i) (v j)) let op_String_Access #n1 #n2 m (i,j) = mget m i j noextract unfold val op_String_Assignment (#n1:size_t) (#n2:size_t{v n1 * v n2 <= max_size_t}) (m:matrix_t n1 n2) (ij:(size_t & size_t){let i, j = ij in v i < v n1 /\ v j < v n2}) (x:elem) : Stack unit (requires fun h0 -> live h0 m) (ensures fun h0 _ h1 -> let i, j = ij in modifies1 m h0 h1 /\ live h1 m /\ as_matrix h1 m == M.mset (as_matrix h0 m) (v i) (v j) x) let op_String_Assignment #n1 #n2 m (i,j) x = mset m i j x unfold let get #n1 #n2 h (m:matrix_t n1 n2) i j = M.mget (as_matrix h m) i j private unfold val map_inner_inv: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> h2:HS.mem -> f:(elem -> elem) -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_nat -> Type0 let map_inner_inv #n1 #n2 h0 h1 h2 f a c i j = live h2 a /\ live h2 c /\ modifies1 c h1 h2 /\ j <= v n2 /\ (forall (i0:nat{i0 < v i}) (j:nat{j < v n2}). get h2 c i0 j == get h1 c i0 j) /\ (forall (j0:nat{j0 < j}). get h2 c (v i) j0 == f (get h0 a (v i) j0)) /\ (forall (j0:nat{j <= j0 /\ j0 < v n2}). get h2 c (v i) j0 == get h0 c (v i) j0) /\ (forall (i0:nat{v i < i0 /\ i0 < v n1}) (j:nat{j < v n2}). get h2 c i0 j == get h0 c i0 j) inline_for_extraction noextract private val map_inner: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> f:(elem -> elem) -> a:matrix_t n1 n2 -> c:matrix_t n1 n2{a == c} -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> Stack unit (requires fun h2 -> map_inner_inv h0 h1 h2 f a c i (v j)) (ensures fun _ _ h2 -> map_inner_inv h0 h1 h2 f a c i (v j + 1)) let map_inner #n1 #n2 h0 h1 f a c i j = c.[i,j] <- f a.[i,j] inline_for_extraction val map: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> f:(uint16 -> uint16) -> a:matrix_t n1 n2 -> c:matrix_t n1 n2 -> Stack unit (requires fun h0 -> live h0 a /\ live h0 c /\ a == c) (ensures fun h0 _ h1 -> modifies1 c h0 h1 /\ as_matrix h1 c == M.map #(v n1) #(v n2) f (as_matrix h0 a)) let map #n1 #n2 f a c = let h0 = ST.get () in Lib.Loops.for (size 0) n1 (fun h1 i -> live h1 a /\ live h1 c /\ modifies1 c h0 h1 /\ i <= v n1 /\ (forall (i0:nat{i0 < i}) (j:nat{j < v n2}). get h1 c i0 j == f (get h0 a i0 j)) /\ (forall (i0:nat{i <= i0 /\ i0 < v n1}) (j:nat{j < v n2}). get h1 c i0 j == get h0 c i0 j) ) (fun i -> let h1 = ST.get() in Lib.Loops.for (size 0) n2 (fun h2 j -> map_inner_inv h0 h1 h2 f a c i j) (fun j -> map_inner h0 h1 f a c i j) ); let h2 = ST.get () in M.extensionality (as_matrix h2 c) (M.map f (as_matrix h0 a)) inline_for_extraction noextract val mod_pow2_felem: logq:size_t{0 < v logq /\ v logq < 16} -> a:uint16 -> Pure uint16 (requires True) (ensures fun r -> r == M.mod_pow2_felem (v logq) a) let mod_pow2_felem logq a = a &. ((u16 1 <<. logq) -. u16 1) val mod_pow2: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> logq:size_t{0 < v logq /\ v logq <= 16} -> a:matrix_t n1 n2 -> Stack unit (requires fun h -> live h a) (ensures fun h0 _ h1 -> modifies1 a h0 h1 /\ as_matrix h1 a == M.mod_pow2 (v logq) (as_matrix h0 a)) [@"c_inline"] let mod_pow2 #n1 #n2 logq a = if logq <. 16ul then begin let h0 = ST.get () in map (mod_pow2_felem logq) a a; M.extensionality (M.map #(v n1) #(v n2) (mod_pow2_felem logq) (as_matrix h0 a)) (M.map #(v n1) #(v n2) (M.mod_pow2_felem (v logq)) (as_matrix h0 a)) end private unfold val map2_inner_inv: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> h2:HS.mem -> f:(elem -> elem -> elem) -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> c:matrix_t n1 n2 -> i:size_t{v i < v n1} -> j:size_nat -> Type0 let map2_inner_inv #n1 #n2 h0 h1 h2 f a b c i j = live h2 a /\ live h2 b /\ live h2 c /\ modifies1 c h1 h2 /\ j <= v n2 /\ (forall (i0:nat{i0 < v i}) (j:nat{j < v n2}). get h2 c i0 j == get h1 c i0 j) /\ (forall (j0:nat{j0 < j}). get h2 c (v i) j0 == f (get h0 a (v i) j0) (get h2 b (v i) j0)) /\ (forall (j0:nat{j <= j0 /\ j0 < v n2}). get h2 c (v i) j0 == get h0 c (v i) j0) /\ (forall (i0:nat{v i < i0 /\ i0 < v n1}) (j:nat{j < v n2}). get h2 c i0 j == get h0 c i0 j) inline_for_extraction noextract private val map2_inner: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> f:(elem -> elem -> elem) -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> c:matrix_t n1 n2{a == c /\ disjoint b c} -> i:size_t{v i < v n1} -> j:size_t{v j < v n2} -> Stack unit (requires fun h2 -> map2_inner_inv h0 h1 h2 f a b c i (v j)) (ensures fun _ _ h2 -> map2_inner_inv h0 h1 h2 f a b c i (v j + 1)) let map2_inner #n1 #n2 h0 h1 f a b c i j = c.[i,j] <- f a.[i,j] b.[i,j] /// In-place [map2], a == map2 f a b /// /// A non in-place variant can be obtained by weakening the pre-condition to disjoint a c, /// or the two variants can be merged by requiring (a == c \/ disjoint a c) instead of a == c /// See commit 91916b8372fa3522061eff5a42d0ebd1d19a8a49 inline_for_extraction val map2: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> f:(uint16 -> uint16 -> uint16) -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> c:matrix_t n1 n2 -> Stack unit (requires fun h0 -> live h0 a /\ live h0 b /\ live h0 c /\ a == c /\ disjoint b c) (ensures fun h0 _ h1 -> modifies1 c h0 h1 /\ as_matrix h1 c == M.map2 #(v n1) #(v n2) f (as_matrix h0 a) (as_matrix h0 b)) let map2 #n1 #n2 f a b c = let h0 = ST.get () in Lib.Loops.for (size 0) n1 (fun h1 i -> live h1 a /\ live h1 b /\ live h1 c /\ modifies1 c h0 h1 /\ i <= v n1 /\ (forall (i0:nat{i0 < i}) (j:nat{j < v n2}). get h1 c i0 j == f (get h0 a i0 j) (get h0 b i0 j)) /\ (forall (i0:nat{i <= i0 /\ i0 < v n1}) (j:nat{j < v n2}). get h1 c i0 j == get h0 c i0 j) ) (fun i -> let h1 = ST.get() in Lib.Loops.for (size 0) n2 (fun h2 j -> map2_inner_inv h0 h1 h2 f a b c i j) (fun j -> map2_inner h0 h1 f a b c i j) ); let h2 = ST.get() in M.extensionality (as_matrix h2 c) (M.map2 f (as_matrix h0 a) (as_matrix h0 b)) val matrix_add: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> Stack unit (requires fun h -> live h a /\ live h b /\ disjoint a b) (ensures fun h0 r h1 -> modifies1 a h0 h1 /\ as_matrix h1 a == M.add (as_matrix h0 a) (as_matrix h0 b)) [@"c_inline"] let matrix_add #n1 #n2 a b = map2 add_mod a b a val matrix_sub: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> a:matrix_t n1 n2 -> b:matrix_t n1 n2 -> Stack unit (requires fun h -> live h a /\ live h b /\ disjoint a b) (ensures fun h0 r h1 -> modifies1 b h0 h1 /\ as_matrix h1 b == M.sub (as_matrix h0 a) (as_matrix h0 b)) [@"c_inline"] let matrix_sub #n1 #n2 a b = (* Use the in-place variant above by flipping the arguments of [sub_mod] *) (* Requires appplying extensionality *) let h0 = ST.get() in [@ inline_let ] let sub_mod_flipped x y = sub_mod y x in map2 sub_mod_flipped b a b; let h1 = ST.get() in M.extensionality (as_matrix h1 b) (M.sub (as_matrix h0 a) (as_matrix h0 b)) #push-options "--fuel 1" inline_for_extraction noextract private val mul_inner: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> #n3:size_t{v n2 * v n3 <= max_size_t /\ v n1 * v n3 <= max_size_t} -> a:matrix_t n1 n2 -> b:matrix_t n2 n3 -> i:size_t{v i < v n1} -> k:size_t{v k < v n3} -> Stack uint16 (requires fun h -> live h a /\ live h b) (ensures fun h0 r h1 -> modifies loc_none h0 h1 /\ r == M.mul_inner (as_matrix h0 a) (as_matrix h0 b) (v i) (v k)) let mul_inner #n1 #n2 #n3 a b i k = push_frame(); let h0 = ST.get() in [@ inline_let ] let f l = get h0 a (v i) l *. get h0 b l (v k) in let res = create #uint16 (size 1) (u16 0) in let h1 = ST.get() in Lib.Loops.for (size 0) n2 (fun h2 j -> live h1 res /\ live h2 res /\ modifies1 res h1 h2 /\ bget h2 res 0 == M.sum_ #(v n2) f j) (fun j -> let aij = a.[i,j] in let bjk = b.[j,k] in let res0 = res.(size 0) in res.(size 0) <- res0 +. aij *. bjk ); let res = res.(size 0) in M.sum_extensionality (v n2) f (fun l -> get h0 a (v i) l *. get h0 b l (v k)) (v n2); assert (res == M.mul_inner (as_matrix h0 a) (as_matrix h0 b) (v i) (v k)); pop_frame(); res #pop-options private unfold val mul_inner_inv: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> #n3:size_t{v n2 * v n3 <= max_size_t /\ v n1 * v n3 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> h2:HS.mem -> a:matrix_t n1 n2 -> b:matrix_t n2 n3 -> c:matrix_t n1 n3 -> f:(k:nat{k < v n3} -> GTot uint16) -> i:size_t{v i < v n1} -> k:size_nat -> Type0 let mul_inner_inv #n1 #n2 #n3 h0 h1 h2 a b c f i k = live h2 a /\ live h2 b /\ live h2 c /\ modifies1 c h1 h2 /\ k <= v n3 /\ (forall (i1:nat{i1 < v i}) (k:nat{k < v n3}). get h2 c i1 k == get h1 c i1 k) /\ (forall (k1:nat{k1 < k}). get h2 c (v i) k1 == f k1) /\ (forall (k1:nat{k <= k1 /\ k1 < v n3}). get h2 c (v i) k1 == get h0 c (v i) k1) /\ (forall (i1:nat{v i < i1 /\ i1 < v n1}) (k:nat{k < v n3}). get h2 c i1 k == get h0 c i1 k) /\ as_matrix h0 a == as_matrix h2 a /\ as_matrix h0 b == as_matrix h2 b inline_for_extraction noextract private val mul_inner1: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> #n3:size_t{v n2 * v n3 <= max_size_t /\ v n1 * v n3 <= max_size_t} -> h0:HS.mem -> h1:HS.mem -> a:matrix_t n1 n2 -> b:matrix_t n2 n3 -> c:matrix_t n1 n3{disjoint a c /\ disjoint b c} -> i:size_t{v i < v n1} -> k:size_t{v k < v n3} -> f:(k:nat{k < v n3} -> GTot (res:uint16{res == M.sum #(v n2) (fun l -> get h0 a (v i) l *. get h0 b l k)})) -> Stack unit (requires fun h2 -> mul_inner_inv h0 h1 h2 a b c f i (v k)) (ensures fun _ _ h2 -> mul_inner_inv h0 h1 h2 a b c f i (v k + 1)) let mul_inner1 #n1 #n2 #n3 h0 h1 a b c i k f = assert (M.mul_inner (as_matrix h0 a) (as_matrix h0 b) (v i) (v k) == M.sum #(v n2) (fun l -> get h0 a (v i) l *. get h0 b l (v k))); c.[i,k] <- mul_inner a b i k; let h2 = ST.get () in assert (get h2 c (v i) (v k) == f (v k)) private val onemore: p:(nat -> Type0) -> q:(i:nat{p i} -> Type0) -> b:nat{p b} -> Lemma (requires (forall (i:nat{p i /\ i < b}). q i) /\ q b) (ensures forall (i:nat{p i /\ i <= b}). q i) let onemore p q b = () val onemore1: #n1:size_nat -> #n3:size_nat{n1 * n3 <= max_size_t} -> c:M.matrix n1 n3 -> f:(i:nat{i < n1} -> k:nat{k < n3} -> GTot uint16) -> i:size_nat{i < n1} -> Lemma (requires ((forall (i1:nat{i1 < i}) (k:nat{k < n3}). M.mget c i1 k == f i1 k) /\ (forall (k:nat{k < n3}). M.mget c i k == f i k))) (ensures (forall (i1:nat{i1 <= i}) (k:nat{k < n3}). M.mget c i1 k == f i1 k)) let onemore1 #n1 #n3 c f i = () val matrix_mul: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> #n3:size_t{v n2 * v n3 <= max_size_t /\ v n1 * v n3 <= max_size_t} -> a:matrix_t n1 n2 -> b:matrix_t n2 n3 -> c:matrix_t n1 n3 -> Stack unit (requires fun h -> live h a /\ live h b /\ live h c /\ disjoint a c /\ disjoint b c) (ensures fun h0 _ h1 -> modifies1 c h0 h1 /\ as_matrix h1 c == M.mul (as_matrix h0 a) (as_matrix h0 b))
false
false
Hacl.Impl.Matrix.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val matrix_mul: #n1:size_t -> #n2:size_t{v n1 * v n2 <= max_size_t} -> #n3:size_t{v n2 * v n3 <= max_size_t /\ v n1 * v n3 <= max_size_t} -> a:matrix_t n1 n2 -> b:matrix_t n2 n3 -> c:matrix_t n1 n3 -> Stack unit (requires fun h -> live h a /\ live h b /\ live h c /\ disjoint a c /\ disjoint b c) (ensures fun h0 _ h1 -> modifies1 c h0 h1 /\ as_matrix h1 c == M.mul (as_matrix h0 a) (as_matrix h0 b))
[]
Hacl.Impl.Matrix.matrix_mul
{ "file_name": "code/frodo/Hacl.Impl.Matrix.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
a: Hacl.Impl.Matrix.matrix_t n1 n2 -> b: Hacl.Impl.Matrix.matrix_t n2 n3 -> c: Hacl.Impl.Matrix.matrix_t n1 n3 -> FStar.HyperStack.ST.Stack Prims.unit
{ "end_col": 77, "end_line": 489, "start_col": 34, "start_line": 466 }
FStar.HyperStack.ST.Stack
val point_double_: out:point -> p:point -> tmp:lbuffer uint64 20ul -> Stack unit (requires fun h -> live h out /\ live h p /\ live h tmp /\ eq_or_disjoint out p /\ disjoint tmp p /\ disjoint tmp out /\ F51.point_inv_t h p) (ensures fun h0 _ h1 -> modifies (loc out |+| loc tmp) h0 h1 /\ F51.point_inv_t h1 out /\ F51.point_eval h1 out == Spec.Ed25519.point_double (F51.point_eval h0 p))
[ { "abbrev": true, "full_module": "Spec.Curve25519", "short_module": "SC" }, { "abbrev": true, "full_module": "Hacl.Impl.Ed25519.Field51", "short_module": "F51" }, { "abbrev": false, "full_module": "Hacl.Bignum25519", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.Ed25519", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Ed25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let point_double_ out p tmp = point_double_step_1 p tmp; point_double_step_2 p tmp; let tmp_f = sub tmp 0ul 5ul in let tmp_e = sub tmp 5ul 5ul in let tmp_h = sub tmp 10ul 5ul in let tmp_g = sub tmp 15ul 5ul in let x3 = getx out in let y3 = gety out in let z3 = getz out in let t3 = gett out in fmul x3 tmp_e tmp_f; fmul y3 tmp_g tmp_h; fmul t3 tmp_e tmp_h; fmul z3 tmp_f tmp_g
val point_double_: out:point -> p:point -> tmp:lbuffer uint64 20ul -> Stack unit (requires fun h -> live h out /\ live h p /\ live h tmp /\ eq_or_disjoint out p /\ disjoint tmp p /\ disjoint tmp out /\ F51.point_inv_t h p) (ensures fun h0 _ h1 -> modifies (loc out |+| loc tmp) h0 h1 /\ F51.point_inv_t h1 out /\ F51.point_eval h1 out == Spec.Ed25519.point_double (F51.point_eval h0 p)) let point_double_ out p tmp =
true
null
false
point_double_step_1 p tmp; point_double_step_2 p tmp; let tmp_f = sub tmp 0ul 5ul in let tmp_e = sub tmp 5ul 5ul in let tmp_h = sub tmp 10ul 5ul in let tmp_g = sub tmp 15ul 5ul in let x3 = getx out in let y3 = gety out in let z3 = getz out in let t3 = gett out in fmul x3 tmp_e tmp_f; fmul y3 tmp_g tmp_h; fmul t3 tmp_e tmp_h; fmul z3 tmp_f tmp_g
{ "checked_file": "Hacl.Impl.Ed25519.PointDouble.fst.checked", "dependencies": [ "Spec.Ed25519.fst.checked", "Spec.Curve25519.fst.checked", "prims.fst.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Impl.Ed25519.Field51.fst.checked", "Hacl.Bignum25519.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Ed25519.PointDouble.fst" }
[]
[ "Hacl.Bignum25519.point", "Lib.Buffer.lbuffer", "Lib.IntTypes.uint64", "FStar.UInt32.__uint_to_t", "Hacl.Bignum25519.fmul", "Prims.unit", "Hacl.Bignum25519.felem", "Hacl.Bignum25519.gett", "Hacl.Bignum25519.getz", "Hacl.Bignum25519.gety", "Hacl.Bignum25519.getx", "Lib.Buffer.lbuffer_t", "Lib.Buffer.MUT", "Lib.IntTypes.int_t", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "FStar.UInt32.uint_to_t", "FStar.UInt32.t", "Lib.Buffer.sub", "Hacl.Impl.Ed25519.PointDouble.point_double_step_2", "Hacl.Impl.Ed25519.PointDouble.point_double_step_1" ]
[]
module Hacl.Impl.Ed25519.PointDouble module ST = FStar.HyperStack.ST open FStar.HyperStack.All open Lib.IntTypes open Lib.Buffer open Hacl.Bignum25519 module F51 = Hacl.Impl.Ed25519.Field51 module SC = Spec.Curve25519 #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" inline_for_extraction noextract val point_double_step_1: p:point -> tmp:lbuffer uint64 20ul -> Stack unit (requires fun h -> live h p /\ live h tmp /\ disjoint p tmp /\ F51.point_inv_t h p) (ensures fun h0 _ h1 -> modifies (loc tmp) h0 h1 /\ (let x1, y1, z1, t1 = F51.point_eval h0 p in let a = x1 `SC.fmul` x1 in let b = y1 `SC.fmul` y1 in let c = 2 `SC.fmul` (z1 `SC.fmul` z1) in let h = a `SC.fadd` b in let g = a `SC.fsub` b in F51.felem_fits h1 (gsub tmp 0ul 5ul) (2, 4, 2, 2, 2) /\ F51.felem_fits h1 (gsub tmp 10ul 5ul) (2, 4, 2, 2, 2) /\ F51.felem_fits h1 (gsub tmp 15ul 5ul) (9, 10, 9, 9, 9) /\ F51.fevalh h1 (gsub tmp 15ul 5ul) == g /\ F51.fevalh h1 (gsub tmp 10ul 5ul) == h /\ F51.fevalh h1 (gsub tmp 0ul 5ul) == c)) let point_double_step_1 p tmp = let tmp1 = sub tmp 0ul 5ul in // c let tmp2 = sub tmp 5ul 5ul in let tmp3 = sub tmp 10ul 5ul in // h let tmp4 = sub tmp 15ul 5ul in // g let x1 = getx p in let y1 = gety p in let z1 = getz p in fsquare tmp1 x1; // tmp1 = a fsquare tmp2 y1; // tmp2 = b fsum tmp3 tmp1 tmp2; // tmp3 = tmp1 + tmp2 = h fdifference tmp4 tmp1 tmp2; // tmp4 = tmp1 - tmp2 = g fsquare tmp1 z1; // tmp1 = z1 * z1 times_2 tmp1 tmp1 // tmp1 = 2 * tmp1 = c inline_for_extraction noextract val point_double_step_2: p:point -> tmp:lbuffer uint64 20ul -> Stack unit (requires fun h -> live h p /\ live h tmp /\ disjoint p tmp /\ F51.point_inv_t h p /\ F51.felem_fits h (gsub tmp 10ul 5ul) (9, 10, 9, 9, 9) /\ F51.felem_fits h (gsub tmp 15ul 5ul) (9, 10, 9, 9, 9) /\ F51.felem_fits h (gsub tmp 0ul 5ul) (2, 4, 2, 2, 2)) (ensures fun h0 _ h1 -> modifies (loc tmp) h0 h1 /\ (let x1, y1, z1, t1 = F51.point_eval h0 p in let c = F51.fevalh h0 (gsub tmp 0ul 5ul) in let h = F51.fevalh h0 (gsub tmp 10ul 5ul) in let g = F51.fevalh h0 (gsub tmp 15ul 5ul) in let e = h `SC.fsub` ((x1 `SC.fadd` y1) `SC.fmul` (x1 `SC.fadd` y1)) in let f = c `SC.fadd` g in F51.felem_fits h1 (gsub tmp 0ul 5ul) (9, 10, 9, 9, 9) /\ F51.felem_fits h1 (gsub tmp 5ul 5ul) (9, 10, 9, 9, 9) /\ F51.felem_fits h1 (gsub tmp 10ul 5ul) (9, 10, 9, 9, 9) /\ F51.felem_fits h1 (gsub tmp 15ul 5ul) (9, 10, 9, 9, 9) /\ F51.fevalh h1 (gsub tmp 0ul 5ul) == f /\ F51.fevalh h1 (gsub tmp 5ul 5ul) == e /\ F51.fevalh h1 (gsub tmp 10ul 5ul) == h /\ F51.fevalh h1 (gsub tmp 15ul 5ul) == g)) let point_double_step_2 p tmp = let tmp1 = sub tmp 0ul 5ul in // c, f let tmp2 = sub tmp 5ul 5ul in // e let tmp3 = sub tmp 10ul 5ul in // h let tmp4 = sub tmp 15ul 5ul in // g let x1 = getx p in let y1 = gety p in fsum tmp2 x1 y1; // tmp2 = x1 + y1 fsquare tmp2 tmp2; // tmp2 = (x1 + y1) ** 2 reduce_513 tmp3; fdifference tmp2 tmp3 tmp2; // tmp2 = tmp3 - tmp2 = h - (x1 + y1) ** 2 = e reduce_513 tmp1; reduce_513 tmp4; fsum tmp1 tmp1 tmp4 // tmp1 = c + g = tmp1 + tmp4 = f inline_for_extraction noextract val point_double_: out:point -> p:point -> tmp:lbuffer uint64 20ul -> Stack unit (requires fun h -> live h out /\ live h p /\ live h tmp /\ eq_or_disjoint out p /\ disjoint tmp p /\ disjoint tmp out /\ F51.point_inv_t h p) (ensures fun h0 _ h1 -> modifies (loc out |+| loc tmp) h0 h1 /\ F51.point_inv_t h1 out /\ F51.point_eval h1 out == Spec.Ed25519.point_double (F51.point_eval h0 p))
false
false
Hacl.Impl.Ed25519.PointDouble.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val point_double_: out:point -> p:point -> tmp:lbuffer uint64 20ul -> Stack unit (requires fun h -> live h out /\ live h p /\ live h tmp /\ eq_or_disjoint out p /\ disjoint tmp p /\ disjoint tmp out /\ F51.point_inv_t h p) (ensures fun h0 _ h1 -> modifies (loc out |+| loc tmp) h0 h1 /\ F51.point_inv_t h1 out /\ F51.point_eval h1 out == Spec.Ed25519.point_double (F51.point_eval h0 p))
[]
Hacl.Impl.Ed25519.PointDouble.point_double_
{ "file_name": "code/ed25519/Hacl.Impl.Ed25519.PointDouble.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
out: Hacl.Bignum25519.point -> p: Hacl.Bignum25519.point -> tmp: Lib.Buffer.lbuffer Lib.IntTypes.uint64 20ul -> FStar.HyperStack.ST.Stack Prims.unit
{ "end_col": 21, "end_line": 119, "start_col": 2, "start_line": 106 }
FStar.HyperStack.ST.Stack
val point_double: out:point -> p:point -> Stack unit (requires fun h -> live h out /\ live h p /\ eq_or_disjoint out p /\ F51.point_inv_t h p) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ F51.point_inv_t h1 out /\ F51.point_eval h1 out == Spec.Ed25519.point_double (F51.point_eval h0 p))
[ { "abbrev": true, "full_module": "Spec.Curve25519", "short_module": "SC" }, { "abbrev": true, "full_module": "Hacl.Impl.Ed25519.Field51", "short_module": "F51" }, { "abbrev": false, "full_module": "Hacl.Bignum25519", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.Ed25519", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Ed25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let point_double out p = push_frame(); let tmp = create 20ul (u64 0) in point_double_ out p tmp; pop_frame()
val point_double: out:point -> p:point -> Stack unit (requires fun h -> live h out /\ live h p /\ eq_or_disjoint out p /\ F51.point_inv_t h p) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ F51.point_inv_t h1 out /\ F51.point_eval h1 out == Spec.Ed25519.point_double (F51.point_eval h0 p)) let point_double out p =
true
null
false
push_frame (); let tmp = create 20ul (u64 0) in point_double_ out p tmp; pop_frame ()
{ "checked_file": "Hacl.Impl.Ed25519.PointDouble.fst.checked", "dependencies": [ "Spec.Ed25519.fst.checked", "Spec.Curve25519.fst.checked", "prims.fst.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Impl.Ed25519.Field51.fst.checked", "Hacl.Bignum25519.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Ed25519.PointDouble.fst" }
[]
[ "Hacl.Bignum25519.point", "FStar.HyperStack.ST.pop_frame", "Prims.unit", "Hacl.Impl.Ed25519.PointDouble.point_double_", "Lib.Buffer.lbuffer_t", "Lib.Buffer.MUT", "Lib.IntTypes.int_t", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "FStar.UInt32.uint_to_t", "FStar.UInt32.t", "Lib.Buffer.create", "Lib.IntTypes.uint64", "FStar.UInt32.__uint_to_t", "Lib.IntTypes.u64", "Lib.Buffer.lbuffer", "FStar.HyperStack.ST.push_frame" ]
[]
module Hacl.Impl.Ed25519.PointDouble module ST = FStar.HyperStack.ST open FStar.HyperStack.All open Lib.IntTypes open Lib.Buffer open Hacl.Bignum25519 module F51 = Hacl.Impl.Ed25519.Field51 module SC = Spec.Curve25519 #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" inline_for_extraction noextract val point_double_step_1: p:point -> tmp:lbuffer uint64 20ul -> Stack unit (requires fun h -> live h p /\ live h tmp /\ disjoint p tmp /\ F51.point_inv_t h p) (ensures fun h0 _ h1 -> modifies (loc tmp) h0 h1 /\ (let x1, y1, z1, t1 = F51.point_eval h0 p in let a = x1 `SC.fmul` x1 in let b = y1 `SC.fmul` y1 in let c = 2 `SC.fmul` (z1 `SC.fmul` z1) in let h = a `SC.fadd` b in let g = a `SC.fsub` b in F51.felem_fits h1 (gsub tmp 0ul 5ul) (2, 4, 2, 2, 2) /\ F51.felem_fits h1 (gsub tmp 10ul 5ul) (2, 4, 2, 2, 2) /\ F51.felem_fits h1 (gsub tmp 15ul 5ul) (9, 10, 9, 9, 9) /\ F51.fevalh h1 (gsub tmp 15ul 5ul) == g /\ F51.fevalh h1 (gsub tmp 10ul 5ul) == h /\ F51.fevalh h1 (gsub tmp 0ul 5ul) == c)) let point_double_step_1 p tmp = let tmp1 = sub tmp 0ul 5ul in // c let tmp2 = sub tmp 5ul 5ul in let tmp3 = sub tmp 10ul 5ul in // h let tmp4 = sub tmp 15ul 5ul in // g let x1 = getx p in let y1 = gety p in let z1 = getz p in fsquare tmp1 x1; // tmp1 = a fsquare tmp2 y1; // tmp2 = b fsum tmp3 tmp1 tmp2; // tmp3 = tmp1 + tmp2 = h fdifference tmp4 tmp1 tmp2; // tmp4 = tmp1 - tmp2 = g fsquare tmp1 z1; // tmp1 = z1 * z1 times_2 tmp1 tmp1 // tmp1 = 2 * tmp1 = c inline_for_extraction noextract val point_double_step_2: p:point -> tmp:lbuffer uint64 20ul -> Stack unit (requires fun h -> live h p /\ live h tmp /\ disjoint p tmp /\ F51.point_inv_t h p /\ F51.felem_fits h (gsub tmp 10ul 5ul) (9, 10, 9, 9, 9) /\ F51.felem_fits h (gsub tmp 15ul 5ul) (9, 10, 9, 9, 9) /\ F51.felem_fits h (gsub tmp 0ul 5ul) (2, 4, 2, 2, 2)) (ensures fun h0 _ h1 -> modifies (loc tmp) h0 h1 /\ (let x1, y1, z1, t1 = F51.point_eval h0 p in let c = F51.fevalh h0 (gsub tmp 0ul 5ul) in let h = F51.fevalh h0 (gsub tmp 10ul 5ul) in let g = F51.fevalh h0 (gsub tmp 15ul 5ul) in let e = h `SC.fsub` ((x1 `SC.fadd` y1) `SC.fmul` (x1 `SC.fadd` y1)) in let f = c `SC.fadd` g in F51.felem_fits h1 (gsub tmp 0ul 5ul) (9, 10, 9, 9, 9) /\ F51.felem_fits h1 (gsub tmp 5ul 5ul) (9, 10, 9, 9, 9) /\ F51.felem_fits h1 (gsub tmp 10ul 5ul) (9, 10, 9, 9, 9) /\ F51.felem_fits h1 (gsub tmp 15ul 5ul) (9, 10, 9, 9, 9) /\ F51.fevalh h1 (gsub tmp 0ul 5ul) == f /\ F51.fevalh h1 (gsub tmp 5ul 5ul) == e /\ F51.fevalh h1 (gsub tmp 10ul 5ul) == h /\ F51.fevalh h1 (gsub tmp 15ul 5ul) == g)) let point_double_step_2 p tmp = let tmp1 = sub tmp 0ul 5ul in // c, f let tmp2 = sub tmp 5ul 5ul in // e let tmp3 = sub tmp 10ul 5ul in // h let tmp4 = sub tmp 15ul 5ul in // g let x1 = getx p in let y1 = gety p in fsum tmp2 x1 y1; // tmp2 = x1 + y1 fsquare tmp2 tmp2; // tmp2 = (x1 + y1) ** 2 reduce_513 tmp3; fdifference tmp2 tmp3 tmp2; // tmp2 = tmp3 - tmp2 = h - (x1 + y1) ** 2 = e reduce_513 tmp1; reduce_513 tmp4; fsum tmp1 tmp1 tmp4 // tmp1 = c + g = tmp1 + tmp4 = f inline_for_extraction noextract val point_double_: out:point -> p:point -> tmp:lbuffer uint64 20ul -> Stack unit (requires fun h -> live h out /\ live h p /\ live h tmp /\ eq_or_disjoint out p /\ disjoint tmp p /\ disjoint tmp out /\ F51.point_inv_t h p) (ensures fun h0 _ h1 -> modifies (loc out |+| loc tmp) h0 h1 /\ F51.point_inv_t h1 out /\ F51.point_eval h1 out == Spec.Ed25519.point_double (F51.point_eval h0 p)) let point_double_ out p tmp = point_double_step_1 p tmp; point_double_step_2 p tmp; let tmp_f = sub tmp 0ul 5ul in let tmp_e = sub tmp 5ul 5ul in let tmp_h = sub tmp 10ul 5ul in let tmp_g = sub tmp 15ul 5ul in let x3 = getx out in let y3 = gety out in let z3 = getz out in let t3 = gett out in fmul x3 tmp_e tmp_f; fmul y3 tmp_g tmp_h; fmul t3 tmp_e tmp_h; fmul z3 tmp_f tmp_g val point_double: out:point -> p:point -> Stack unit (requires fun h -> live h out /\ live h p /\ eq_or_disjoint out p /\ F51.point_inv_t h p) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ F51.point_inv_t h1 out /\ F51.point_eval h1 out == Spec.Ed25519.point_double (F51.point_eval h0 p))
false
false
Hacl.Impl.Ed25519.PointDouble.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val point_double: out:point -> p:point -> Stack unit (requires fun h -> live h out /\ live h p /\ eq_or_disjoint out p /\ F51.point_inv_t h p) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ F51.point_inv_t h1 out /\ F51.point_eval h1 out == Spec.Ed25519.point_double (F51.point_eval h0 p))
[]
Hacl.Impl.Ed25519.PointDouble.point_double
{ "file_name": "code/ed25519/Hacl.Impl.Ed25519.PointDouble.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
out: Hacl.Bignum25519.point -> p: Hacl.Bignum25519.point -> FStar.HyperStack.ST.Stack Prims.unit
{ "end_col": 13, "end_line": 134, "start_col": 2, "start_line": 131 }
FStar.HyperStack.ST.Stack
val point_double_step_1: p:point -> tmp:lbuffer uint64 20ul -> Stack unit (requires fun h -> live h p /\ live h tmp /\ disjoint p tmp /\ F51.point_inv_t h p) (ensures fun h0 _ h1 -> modifies (loc tmp) h0 h1 /\ (let x1, y1, z1, t1 = F51.point_eval h0 p in let a = x1 `SC.fmul` x1 in let b = y1 `SC.fmul` y1 in let c = 2 `SC.fmul` (z1 `SC.fmul` z1) in let h = a `SC.fadd` b in let g = a `SC.fsub` b in F51.felem_fits h1 (gsub tmp 0ul 5ul) (2, 4, 2, 2, 2) /\ F51.felem_fits h1 (gsub tmp 10ul 5ul) (2, 4, 2, 2, 2) /\ F51.felem_fits h1 (gsub tmp 15ul 5ul) (9, 10, 9, 9, 9) /\ F51.fevalh h1 (gsub tmp 15ul 5ul) == g /\ F51.fevalh h1 (gsub tmp 10ul 5ul) == h /\ F51.fevalh h1 (gsub tmp 0ul 5ul) == c))
[ { "abbrev": true, "full_module": "Spec.Curve25519", "short_module": "SC" }, { "abbrev": true, "full_module": "Hacl.Impl.Ed25519.Field51", "short_module": "F51" }, { "abbrev": false, "full_module": "Hacl.Bignum25519", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.Ed25519", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Ed25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let point_double_step_1 p tmp = let tmp1 = sub tmp 0ul 5ul in // c let tmp2 = sub tmp 5ul 5ul in let tmp3 = sub tmp 10ul 5ul in // h let tmp4 = sub tmp 15ul 5ul in // g let x1 = getx p in let y1 = gety p in let z1 = getz p in fsquare tmp1 x1; // tmp1 = a fsquare tmp2 y1; // tmp2 = b fsum tmp3 tmp1 tmp2; // tmp3 = tmp1 + tmp2 = h fdifference tmp4 tmp1 tmp2; // tmp4 = tmp1 - tmp2 = g fsquare tmp1 z1; // tmp1 = z1 * z1 times_2 tmp1 tmp1
val point_double_step_1: p:point -> tmp:lbuffer uint64 20ul -> Stack unit (requires fun h -> live h p /\ live h tmp /\ disjoint p tmp /\ F51.point_inv_t h p) (ensures fun h0 _ h1 -> modifies (loc tmp) h0 h1 /\ (let x1, y1, z1, t1 = F51.point_eval h0 p in let a = x1 `SC.fmul` x1 in let b = y1 `SC.fmul` y1 in let c = 2 `SC.fmul` (z1 `SC.fmul` z1) in let h = a `SC.fadd` b in let g = a `SC.fsub` b in F51.felem_fits h1 (gsub tmp 0ul 5ul) (2, 4, 2, 2, 2) /\ F51.felem_fits h1 (gsub tmp 10ul 5ul) (2, 4, 2, 2, 2) /\ F51.felem_fits h1 (gsub tmp 15ul 5ul) (9, 10, 9, 9, 9) /\ F51.fevalh h1 (gsub tmp 15ul 5ul) == g /\ F51.fevalh h1 (gsub tmp 10ul 5ul) == h /\ F51.fevalh h1 (gsub tmp 0ul 5ul) == c)) let point_double_step_1 p tmp =
true
null
false
let tmp1 = sub tmp 0ul 5ul in let tmp2 = sub tmp 5ul 5ul in let tmp3 = sub tmp 10ul 5ul in let tmp4 = sub tmp 15ul 5ul in let x1 = getx p in let y1 = gety p in let z1 = getz p in fsquare tmp1 x1; fsquare tmp2 y1; fsum tmp3 tmp1 tmp2; fdifference tmp4 tmp1 tmp2; fsquare tmp1 z1; times_2 tmp1 tmp1
{ "checked_file": "Hacl.Impl.Ed25519.PointDouble.fst.checked", "dependencies": [ "Spec.Ed25519.fst.checked", "Spec.Curve25519.fst.checked", "prims.fst.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Impl.Ed25519.Field51.fst.checked", "Hacl.Bignum25519.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Ed25519.PointDouble.fst" }
[]
[ "Hacl.Bignum25519.point", "Lib.Buffer.lbuffer", "Lib.IntTypes.uint64", "FStar.UInt32.__uint_to_t", "Hacl.Bignum25519.times_2", "Prims.unit", "Hacl.Bignum25519.fsquare", "Hacl.Bignum25519.fdifference", "Hacl.Bignum25519.fsum", "Hacl.Bignum25519.felem", "Hacl.Bignum25519.getz", "Hacl.Bignum25519.gety", "Hacl.Bignum25519.getx", "Lib.Buffer.lbuffer_t", "Lib.Buffer.MUT", "Lib.IntTypes.int_t", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "FStar.UInt32.uint_to_t", "FStar.UInt32.t", "Lib.Buffer.sub" ]
[]
module Hacl.Impl.Ed25519.PointDouble module ST = FStar.HyperStack.ST open FStar.HyperStack.All open Lib.IntTypes open Lib.Buffer open Hacl.Bignum25519 module F51 = Hacl.Impl.Ed25519.Field51 module SC = Spec.Curve25519 #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" inline_for_extraction noextract val point_double_step_1: p:point -> tmp:lbuffer uint64 20ul -> Stack unit (requires fun h -> live h p /\ live h tmp /\ disjoint p tmp /\ F51.point_inv_t h p) (ensures fun h0 _ h1 -> modifies (loc tmp) h0 h1 /\ (let x1, y1, z1, t1 = F51.point_eval h0 p in let a = x1 `SC.fmul` x1 in let b = y1 `SC.fmul` y1 in let c = 2 `SC.fmul` (z1 `SC.fmul` z1) in let h = a `SC.fadd` b in let g = a `SC.fsub` b in F51.felem_fits h1 (gsub tmp 0ul 5ul) (2, 4, 2, 2, 2) /\ F51.felem_fits h1 (gsub tmp 10ul 5ul) (2, 4, 2, 2, 2) /\ F51.felem_fits h1 (gsub tmp 15ul 5ul) (9, 10, 9, 9, 9) /\ F51.fevalh h1 (gsub tmp 15ul 5ul) == g /\ F51.fevalh h1 (gsub tmp 10ul 5ul) == h /\ F51.fevalh h1 (gsub tmp 0ul 5ul) == c))
false
false
Hacl.Impl.Ed25519.PointDouble.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val point_double_step_1: p:point -> tmp:lbuffer uint64 20ul -> Stack unit (requires fun h -> live h p /\ live h tmp /\ disjoint p tmp /\ F51.point_inv_t h p) (ensures fun h0 _ h1 -> modifies (loc tmp) h0 h1 /\ (let x1, y1, z1, t1 = F51.point_eval h0 p in let a = x1 `SC.fmul` x1 in let b = y1 `SC.fmul` y1 in let c = 2 `SC.fmul` (z1 `SC.fmul` z1) in let h = a `SC.fadd` b in let g = a `SC.fsub` b in F51.felem_fits h1 (gsub tmp 0ul 5ul) (2, 4, 2, 2, 2) /\ F51.felem_fits h1 (gsub tmp 10ul 5ul) (2, 4, 2, 2, 2) /\ F51.felem_fits h1 (gsub tmp 15ul 5ul) (9, 10, 9, 9, 9) /\ F51.fevalh h1 (gsub tmp 15ul 5ul) == g /\ F51.fevalh h1 (gsub tmp 10ul 5ul) == h /\ F51.fevalh h1 (gsub tmp 0ul 5ul) == c))
[]
Hacl.Impl.Ed25519.PointDouble.point_double_step_1
{ "file_name": "code/ed25519/Hacl.Impl.Ed25519.PointDouble.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
p: Hacl.Bignum25519.point -> tmp: Lib.Buffer.lbuffer Lib.IntTypes.uint64 20ul -> FStar.HyperStack.ST.Stack Prims.unit
{ "end_col": 19, "end_line": 50, "start_col": 31, "start_line": 35 }
FStar.HyperStack.ST.Stack
val point_double_step_2: p:point -> tmp:lbuffer uint64 20ul -> Stack unit (requires fun h -> live h p /\ live h tmp /\ disjoint p tmp /\ F51.point_inv_t h p /\ F51.felem_fits h (gsub tmp 10ul 5ul) (9, 10, 9, 9, 9) /\ F51.felem_fits h (gsub tmp 15ul 5ul) (9, 10, 9, 9, 9) /\ F51.felem_fits h (gsub tmp 0ul 5ul) (2, 4, 2, 2, 2)) (ensures fun h0 _ h1 -> modifies (loc tmp) h0 h1 /\ (let x1, y1, z1, t1 = F51.point_eval h0 p in let c = F51.fevalh h0 (gsub tmp 0ul 5ul) in let h = F51.fevalh h0 (gsub tmp 10ul 5ul) in let g = F51.fevalh h0 (gsub tmp 15ul 5ul) in let e = h `SC.fsub` ((x1 `SC.fadd` y1) `SC.fmul` (x1 `SC.fadd` y1)) in let f = c `SC.fadd` g in F51.felem_fits h1 (gsub tmp 0ul 5ul) (9, 10, 9, 9, 9) /\ F51.felem_fits h1 (gsub tmp 5ul 5ul) (9, 10, 9, 9, 9) /\ F51.felem_fits h1 (gsub tmp 10ul 5ul) (9, 10, 9, 9, 9) /\ F51.felem_fits h1 (gsub tmp 15ul 5ul) (9, 10, 9, 9, 9) /\ F51.fevalh h1 (gsub tmp 0ul 5ul) == f /\ F51.fevalh h1 (gsub tmp 5ul 5ul) == e /\ F51.fevalh h1 (gsub tmp 10ul 5ul) == h /\ F51.fevalh h1 (gsub tmp 15ul 5ul) == g))
[ { "abbrev": true, "full_module": "Spec.Curve25519", "short_module": "SC" }, { "abbrev": true, "full_module": "Hacl.Impl.Ed25519.Field51", "short_module": "F51" }, { "abbrev": false, "full_module": "Hacl.Bignum25519", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.Ed25519", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Ed25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let point_double_step_2 p tmp = let tmp1 = sub tmp 0ul 5ul in // c, f let tmp2 = sub tmp 5ul 5ul in // e let tmp3 = sub tmp 10ul 5ul in // h let tmp4 = sub tmp 15ul 5ul in // g let x1 = getx p in let y1 = gety p in fsum tmp2 x1 y1; // tmp2 = x1 + y1 fsquare tmp2 tmp2; // tmp2 = (x1 + y1) ** 2 reduce_513 tmp3; fdifference tmp2 tmp3 tmp2; // tmp2 = tmp3 - tmp2 = h - (x1 + y1) ** 2 = e reduce_513 tmp1; reduce_513 tmp4; fsum tmp1 tmp1 tmp4
val point_double_step_2: p:point -> tmp:lbuffer uint64 20ul -> Stack unit (requires fun h -> live h p /\ live h tmp /\ disjoint p tmp /\ F51.point_inv_t h p /\ F51.felem_fits h (gsub tmp 10ul 5ul) (9, 10, 9, 9, 9) /\ F51.felem_fits h (gsub tmp 15ul 5ul) (9, 10, 9, 9, 9) /\ F51.felem_fits h (gsub tmp 0ul 5ul) (2, 4, 2, 2, 2)) (ensures fun h0 _ h1 -> modifies (loc tmp) h0 h1 /\ (let x1, y1, z1, t1 = F51.point_eval h0 p in let c = F51.fevalh h0 (gsub tmp 0ul 5ul) in let h = F51.fevalh h0 (gsub tmp 10ul 5ul) in let g = F51.fevalh h0 (gsub tmp 15ul 5ul) in let e = h `SC.fsub` ((x1 `SC.fadd` y1) `SC.fmul` (x1 `SC.fadd` y1)) in let f = c `SC.fadd` g in F51.felem_fits h1 (gsub tmp 0ul 5ul) (9, 10, 9, 9, 9) /\ F51.felem_fits h1 (gsub tmp 5ul 5ul) (9, 10, 9, 9, 9) /\ F51.felem_fits h1 (gsub tmp 10ul 5ul) (9, 10, 9, 9, 9) /\ F51.felem_fits h1 (gsub tmp 15ul 5ul) (9, 10, 9, 9, 9) /\ F51.fevalh h1 (gsub tmp 0ul 5ul) == f /\ F51.fevalh h1 (gsub tmp 5ul 5ul) == e /\ F51.fevalh h1 (gsub tmp 10ul 5ul) == h /\ F51.fevalh h1 (gsub tmp 15ul 5ul) == g)) let point_double_step_2 p tmp =
true
null
false
let tmp1 = sub tmp 0ul 5ul in let tmp2 = sub tmp 5ul 5ul in let tmp3 = sub tmp 10ul 5ul in let tmp4 = sub tmp 15ul 5ul in let x1 = getx p in let y1 = gety p in fsum tmp2 x1 y1; fsquare tmp2 tmp2; reduce_513 tmp3; fdifference tmp2 tmp3 tmp2; reduce_513 tmp1; reduce_513 tmp4; fsum tmp1 tmp1 tmp4
{ "checked_file": "Hacl.Impl.Ed25519.PointDouble.fst.checked", "dependencies": [ "Spec.Ed25519.fst.checked", "Spec.Curve25519.fst.checked", "prims.fst.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Impl.Ed25519.Field51.fst.checked", "Hacl.Bignum25519.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Ed25519.PointDouble.fst" }
[]
[ "Hacl.Bignum25519.point", "Lib.Buffer.lbuffer", "Lib.IntTypes.uint64", "FStar.UInt32.__uint_to_t", "Hacl.Bignum25519.fsum", "Prims.unit", "Hacl.Bignum25519.reduce_513", "Hacl.Bignum25519.fdifference", "Hacl.Bignum25519.fsquare", "Hacl.Bignum25519.felem", "Hacl.Bignum25519.gety", "Hacl.Bignum25519.getx", "Lib.Buffer.lbuffer_t", "Lib.Buffer.MUT", "Lib.IntTypes.int_t", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "FStar.UInt32.uint_to_t", "FStar.UInt32.t", "Lib.Buffer.sub" ]
[]
module Hacl.Impl.Ed25519.PointDouble module ST = FStar.HyperStack.ST open FStar.HyperStack.All open Lib.IntTypes open Lib.Buffer open Hacl.Bignum25519 module F51 = Hacl.Impl.Ed25519.Field51 module SC = Spec.Curve25519 #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" inline_for_extraction noextract val point_double_step_1: p:point -> tmp:lbuffer uint64 20ul -> Stack unit (requires fun h -> live h p /\ live h tmp /\ disjoint p tmp /\ F51.point_inv_t h p) (ensures fun h0 _ h1 -> modifies (loc tmp) h0 h1 /\ (let x1, y1, z1, t1 = F51.point_eval h0 p in let a = x1 `SC.fmul` x1 in let b = y1 `SC.fmul` y1 in let c = 2 `SC.fmul` (z1 `SC.fmul` z1) in let h = a `SC.fadd` b in let g = a `SC.fsub` b in F51.felem_fits h1 (gsub tmp 0ul 5ul) (2, 4, 2, 2, 2) /\ F51.felem_fits h1 (gsub tmp 10ul 5ul) (2, 4, 2, 2, 2) /\ F51.felem_fits h1 (gsub tmp 15ul 5ul) (9, 10, 9, 9, 9) /\ F51.fevalh h1 (gsub tmp 15ul 5ul) == g /\ F51.fevalh h1 (gsub tmp 10ul 5ul) == h /\ F51.fevalh h1 (gsub tmp 0ul 5ul) == c)) let point_double_step_1 p tmp = let tmp1 = sub tmp 0ul 5ul in // c let tmp2 = sub tmp 5ul 5ul in let tmp3 = sub tmp 10ul 5ul in // h let tmp4 = sub tmp 15ul 5ul in // g let x1 = getx p in let y1 = gety p in let z1 = getz p in fsquare tmp1 x1; // tmp1 = a fsquare tmp2 y1; // tmp2 = b fsum tmp3 tmp1 tmp2; // tmp3 = tmp1 + tmp2 = h fdifference tmp4 tmp1 tmp2; // tmp4 = tmp1 - tmp2 = g fsquare tmp1 z1; // tmp1 = z1 * z1 times_2 tmp1 tmp1 // tmp1 = 2 * tmp1 = c inline_for_extraction noextract val point_double_step_2: p:point -> tmp:lbuffer uint64 20ul -> Stack unit (requires fun h -> live h p /\ live h tmp /\ disjoint p tmp /\ F51.point_inv_t h p /\ F51.felem_fits h (gsub tmp 10ul 5ul) (9, 10, 9, 9, 9) /\ F51.felem_fits h (gsub tmp 15ul 5ul) (9, 10, 9, 9, 9) /\ F51.felem_fits h (gsub tmp 0ul 5ul) (2, 4, 2, 2, 2)) (ensures fun h0 _ h1 -> modifies (loc tmp) h0 h1 /\ (let x1, y1, z1, t1 = F51.point_eval h0 p in let c = F51.fevalh h0 (gsub tmp 0ul 5ul) in let h = F51.fevalh h0 (gsub tmp 10ul 5ul) in let g = F51.fevalh h0 (gsub tmp 15ul 5ul) in let e = h `SC.fsub` ((x1 `SC.fadd` y1) `SC.fmul` (x1 `SC.fadd` y1)) in let f = c `SC.fadd` g in F51.felem_fits h1 (gsub tmp 0ul 5ul) (9, 10, 9, 9, 9) /\ F51.felem_fits h1 (gsub tmp 5ul 5ul) (9, 10, 9, 9, 9) /\ F51.felem_fits h1 (gsub tmp 10ul 5ul) (9, 10, 9, 9, 9) /\ F51.felem_fits h1 (gsub tmp 15ul 5ul) (9, 10, 9, 9, 9) /\ F51.fevalh h1 (gsub tmp 0ul 5ul) == f /\ F51.fevalh h1 (gsub tmp 5ul 5ul) == e /\ F51.fevalh h1 (gsub tmp 10ul 5ul) == h /\ F51.fevalh h1 (gsub tmp 15ul 5ul) == g))
false
false
Hacl.Impl.Ed25519.PointDouble.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val point_double_step_2: p:point -> tmp:lbuffer uint64 20ul -> Stack unit (requires fun h -> live h p /\ live h tmp /\ disjoint p tmp /\ F51.point_inv_t h p /\ F51.felem_fits h (gsub tmp 10ul 5ul) (9, 10, 9, 9, 9) /\ F51.felem_fits h (gsub tmp 15ul 5ul) (9, 10, 9, 9, 9) /\ F51.felem_fits h (gsub tmp 0ul 5ul) (2, 4, 2, 2, 2)) (ensures fun h0 _ h1 -> modifies (loc tmp) h0 h1 /\ (let x1, y1, z1, t1 = F51.point_eval h0 p in let c = F51.fevalh h0 (gsub tmp 0ul 5ul) in let h = F51.fevalh h0 (gsub tmp 10ul 5ul) in let g = F51.fevalh h0 (gsub tmp 15ul 5ul) in let e = h `SC.fsub` ((x1 `SC.fadd` y1) `SC.fmul` (x1 `SC.fadd` y1)) in let f = c `SC.fadd` g in F51.felem_fits h1 (gsub tmp 0ul 5ul) (9, 10, 9, 9, 9) /\ F51.felem_fits h1 (gsub tmp 5ul 5ul) (9, 10, 9, 9, 9) /\ F51.felem_fits h1 (gsub tmp 10ul 5ul) (9, 10, 9, 9, 9) /\ F51.felem_fits h1 (gsub tmp 15ul 5ul) (9, 10, 9, 9, 9) /\ F51.fevalh h1 (gsub tmp 0ul 5ul) == f /\ F51.fevalh h1 (gsub tmp 5ul 5ul) == e /\ F51.fevalh h1 (gsub tmp 10ul 5ul) == h /\ F51.fevalh h1 (gsub tmp 15ul 5ul) == g))
[]
Hacl.Impl.Ed25519.PointDouble.point_double_step_2
{ "file_name": "code/ed25519/Hacl.Impl.Ed25519.PointDouble.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
p: Hacl.Bignum25519.point -> tmp: Lib.Buffer.lbuffer Lib.IntTypes.uint64 20ul -> FStar.HyperStack.ST.Stack Prims.unit
{ "end_col": 21, "end_line": 92, "start_col": 31, "start_line": 77 }
FStar.HyperStack.ST.Stack
val add_modq: z:qelemB -> x:qelemB -> y:qelemB -> Stack unit (requires fun h -> live h z /\ live h x /\ live h y /\ qelem_fits h x (1, 1, 1, 1, 1) /\ qelem_fits h y (1, 1, 1, 1, 1) /\ as_nat h x < S.q /\ as_nat h y < S.q) (ensures fun h0 _ h1 -> modifies (loc z) h0 h1 /\ qelem_fits h1 z (1, 1, 1, 1, 1) /\ as_nat h1 z == (as_nat h0 x + as_nat h0 y) % S.q)
[ { "abbrev": true, "full_module": "Spec.Ed25519", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Spec.BignumQ.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.BignumQ", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.BignumQ", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let add_modq out x y = let (x0, x1, x2, x3, x4) = (x.(0ul), x.(1ul), x.(2ul), x.(3ul), x.(4ul)) in let (y0, y1, y2, y3, y4) = (y.(0ul), y.(1ul), y.(2ul), y.(3ul), y.(4ul)) in let (z0, z1, z2, z3, z4) = add_modq5 (x0, x1, x2, x3, x4) (y0, y1, y2, y3, y4) in out.(0ul) <- z0; out.(1ul) <- z1; out.(2ul) <- z2; out.(3ul) <- z3; out.(4ul) <- z4
val add_modq: z:qelemB -> x:qelemB -> y:qelemB -> Stack unit (requires fun h -> live h z /\ live h x /\ live h y /\ qelem_fits h x (1, 1, 1, 1, 1) /\ qelem_fits h y (1, 1, 1, 1, 1) /\ as_nat h x < S.q /\ as_nat h y < S.q) (ensures fun h0 _ h1 -> modifies (loc z) h0 h1 /\ qelem_fits h1 z (1, 1, 1, 1, 1) /\ as_nat h1 z == (as_nat h0 x + as_nat h0 y) % S.q) let add_modq out x y =
true
null
false
let x0, x1, x2, x3, x4 = (x.(0ul), x.(1ul), x.(2ul), x.(3ul), x.(4ul)) in let y0, y1, y2, y3, y4 = (y.(0ul), y.(1ul), y.(2ul), y.(3ul), y.(4ul)) in let z0, z1, z2, z3, z4 = add_modq5 (x0, x1, x2, x3, x4) (y0, y1, y2, y3, y4) in out.(0ul) <- z0; out.(1ul) <- z1; out.(2ul) <- z2; out.(3ul) <- z3; out.(4ul) <- z4
{ "checked_file": "Hacl.Impl.BignumQ.Mul.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.BignumQ.Mul.fst.checked", "Hacl.Spec.BignumQ.Lemmas.fst.checked", "Hacl.Bignum25519.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked" ], "interface_file": true, "source_file": "Hacl.Impl.BignumQ.Mul.fst" }
[]
[ "Hacl.Impl.BignumQ.Mul.qelemB", "Lib.IntTypes.uint64", "Lib.Buffer.op_Array_Assignment", "FStar.UInt32.__uint_to_t", "Prims.unit", "Hacl.Spec.BignumQ.Definitions.qelem5", "Hacl.Spec.BignumQ.Mul.add_modq5", "FStar.Pervasives.Native.Mktuple5", "FStar.Pervasives.Native.tuple5", "Lib.IntTypes.int_t", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "Lib.Buffer.op_Array_Access", "Lib.Buffer.MUT" ]
[]
module Hacl.Impl.BignumQ.Mul module ST = FStar.HyperStack.ST open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer include Hacl.Spec.BignumQ.Mul #set-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0" [@CInline] let barrett_reduction z t = let (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) = (t.(0ul), t.(1ul), t.(2ul), t.(3ul), t.(4ul), t.(5ul), t.(6ul), t.(7ul), t.(8ul), t.(9ul)) in let (z0, z1, z2, z3, z4)= barrett_reduction5 (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) in z.(0ul) <- z0; z.(1ul) <- z1; z.(2ul) <- z2; z.(3ul) <- z3; z.(4ul) <- z4 [@CInline] let mul_modq out x y = push_frame (); let tmp = create 10ul (u64 0) in let (x0, x1, x2, x3, x4) = (x.(0ul), x.(1ul), x.(2ul), x.(3ul), x.(4ul)) in let (y0, y1, y2, y3, y4) = (y.(0ul), y.(1ul), y.(2ul), y.(3ul), y.(4ul)) in let (z0, z1, z2, z3, z4, z5, z6, z7, z8, z9) = mul_5 (x0, x1, x2, x3, x4) (y0, y1, y2, y3, y4) in Hacl.Spec.BignumQ.Lemmas.lemma_mul_lt (as_nat5 (x0, x1, x2, x3, x4)) (pow2 256) (as_nat5 (y0, y1, y2, y3, y4)) (pow2 256); assert_norm (pow2 256 * pow2 256 = pow2 512); Hacl.Bignum25519.make_u64_10 tmp z0 z1 z2 z3 z4 z5 z6 z7 z8 z9; barrett_reduction out tmp; pop_frame ()
false
false
Hacl.Impl.BignumQ.Mul.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val add_modq: z:qelemB -> x:qelemB -> y:qelemB -> Stack unit (requires fun h -> live h z /\ live h x /\ live h y /\ qelem_fits h x (1, 1, 1, 1, 1) /\ qelem_fits h y (1, 1, 1, 1, 1) /\ as_nat h x < S.q /\ as_nat h y < S.q) (ensures fun h0 _ h1 -> modifies (loc z) h0 h1 /\ qelem_fits h1 z (1, 1, 1, 1, 1) /\ as_nat h1 z == (as_nat h0 x + as_nat h0 y) % S.q)
[]
Hacl.Impl.BignumQ.Mul.add_modq
{ "file_name": "code/ed25519/Hacl.Impl.BignumQ.Mul.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
z: Hacl.Impl.BignumQ.Mul.qelemB -> x: Hacl.Impl.BignumQ.Mul.qelemB -> y: Hacl.Impl.BignumQ.Mul.qelemB -> FStar.HyperStack.ST.Stack Prims.unit
{ "end_col": 17, "end_line": 49, "start_col": 22, "start_line": 41 }
FStar.HyperStack.ST.Stack
val mul_modq: z:qelemB -> x:qelemB -> y:qelemB -> Stack unit (requires fun h -> live h z /\ live h x /\ live h y /\ qelem_fits h x (1, 1, 1, 1, 1) /\ qelem_fits h y (1, 1, 1, 1, 1) /\ as_nat h x < pow2 256 /\ as_nat h y < pow2 256) (ensures fun h0 _ h1 -> modifies (loc z) h0 h1 /\ qelem_fits h1 z (1, 1, 1, 1, 1) /\ as_nat h1 z == (as_nat h0 x * as_nat h0 y) % S.q)
[ { "abbrev": true, "full_module": "Spec.Ed25519", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Spec.BignumQ.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.BignumQ", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.BignumQ", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let mul_modq out x y = push_frame (); let tmp = create 10ul (u64 0) in let (x0, x1, x2, x3, x4) = (x.(0ul), x.(1ul), x.(2ul), x.(3ul), x.(4ul)) in let (y0, y1, y2, y3, y4) = (y.(0ul), y.(1ul), y.(2ul), y.(3ul), y.(4ul)) in let (z0, z1, z2, z3, z4, z5, z6, z7, z8, z9) = mul_5 (x0, x1, x2, x3, x4) (y0, y1, y2, y3, y4) in Hacl.Spec.BignumQ.Lemmas.lemma_mul_lt (as_nat5 (x0, x1, x2, x3, x4)) (pow2 256) (as_nat5 (y0, y1, y2, y3, y4)) (pow2 256); assert_norm (pow2 256 * pow2 256 = pow2 512); Hacl.Bignum25519.make_u64_10 tmp z0 z1 z2 z3 z4 z5 z6 z7 z8 z9; barrett_reduction out tmp; pop_frame ()
val mul_modq: z:qelemB -> x:qelemB -> y:qelemB -> Stack unit (requires fun h -> live h z /\ live h x /\ live h y /\ qelem_fits h x (1, 1, 1, 1, 1) /\ qelem_fits h y (1, 1, 1, 1, 1) /\ as_nat h x < pow2 256 /\ as_nat h y < pow2 256) (ensures fun h0 _ h1 -> modifies (loc z) h0 h1 /\ qelem_fits h1 z (1, 1, 1, 1, 1) /\ as_nat h1 z == (as_nat h0 x * as_nat h0 y) % S.q) let mul_modq out x y =
true
null
false
push_frame (); let tmp = create 10ul (u64 0) in let x0, x1, x2, x3, x4 = (x.(0ul), x.(1ul), x.(2ul), x.(3ul), x.(4ul)) in let y0, y1, y2, y3, y4 = (y.(0ul), y.(1ul), y.(2ul), y.(3ul), y.(4ul)) in let z0, z1, z2, z3, z4, z5, z6, z7, z8, z9 = mul_5 (x0, x1, x2, x3, x4) (y0, y1, y2, y3, y4) in Hacl.Spec.BignumQ.Lemmas.lemma_mul_lt (as_nat5 (x0, x1, x2, x3, x4)) (pow2 256) (as_nat5 (y0, y1, y2, y3, y4)) (pow2 256); assert_norm (pow2 256 * pow2 256 = pow2 512); Hacl.Bignum25519.make_u64_10 tmp z0 z1 z2 z3 z4 z5 z6 z7 z8 z9; barrett_reduction out tmp; pop_frame ()
{ "checked_file": "Hacl.Impl.BignumQ.Mul.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.BignumQ.Mul.fst.checked", "Hacl.Spec.BignumQ.Lemmas.fst.checked", "Hacl.Bignum25519.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked" ], "interface_file": true, "source_file": "Hacl.Impl.BignumQ.Mul.fst" }
[]
[ "Hacl.Impl.BignumQ.Mul.qelemB", "Lib.IntTypes.uint64", "FStar.HyperStack.ST.pop_frame", "Prims.unit", "Hacl.Impl.BignumQ.Mul.barrett_reduction", "Hacl.Bignum25519.make_u64_10", "FStar.Pervasives.assert_norm", "Prims.b2t", "Prims.op_Equality", "Prims.int", "FStar.Mul.op_Star", "Prims.pow2", "Hacl.Spec.BignumQ.Lemmas.lemma_mul_lt", "Hacl.Spec.BignumQ.Definitions.as_nat5", "FStar.Pervasives.Native.Mktuple5", "Hacl.Spec.BignumQ.Definitions.qelem_wide5", "Hacl.Spec.BignumQ.Mul.mul_5", "FStar.Pervasives.Native.tuple5", "Lib.IntTypes.int_t", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "Lib.Buffer.op_Array_Access", "Lib.Buffer.MUT", "FStar.UInt32.__uint_to_t", "Lib.Buffer.lbuffer_t", "FStar.UInt32.uint_to_t", "FStar.UInt32.t", "Lib.Buffer.create", "Lib.IntTypes.u64", "Lib.Buffer.lbuffer", "FStar.HyperStack.ST.push_frame" ]
[]
module Hacl.Impl.BignumQ.Mul module ST = FStar.HyperStack.ST open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer include Hacl.Spec.BignumQ.Mul #set-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0" [@CInline] let barrett_reduction z t = let (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) = (t.(0ul), t.(1ul), t.(2ul), t.(3ul), t.(4ul), t.(5ul), t.(6ul), t.(7ul), t.(8ul), t.(9ul)) in let (z0, z1, z2, z3, z4)= barrett_reduction5 (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) in z.(0ul) <- z0; z.(1ul) <- z1; z.(2ul) <- z2; z.(3ul) <- z3; z.(4ul) <- z4 [@CInline]
false
false
Hacl.Impl.BignumQ.Mul.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val mul_modq: z:qelemB -> x:qelemB -> y:qelemB -> Stack unit (requires fun h -> live h z /\ live h x /\ live h y /\ qelem_fits h x (1, 1, 1, 1, 1) /\ qelem_fits h y (1, 1, 1, 1, 1) /\ as_nat h x < pow2 256 /\ as_nat h y < pow2 256) (ensures fun h0 _ h1 -> modifies (loc z) h0 h1 /\ qelem_fits h1 z (1, 1, 1, 1, 1) /\ as_nat h1 z == (as_nat h0 x * as_nat h0 y) % S.q)
[]
Hacl.Impl.BignumQ.Mul.mul_modq
{ "file_name": "code/ed25519/Hacl.Impl.BignumQ.Mul.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
z: Hacl.Impl.BignumQ.Mul.qelemB -> x: Hacl.Impl.BignumQ.Mul.qelemB -> y: Hacl.Impl.BignumQ.Mul.qelemB -> FStar.HyperStack.ST.Stack Prims.unit
{ "end_col": 14, "end_line": 37, "start_col": 2, "start_line": 28 }
FStar.HyperStack.ST.Stack
val barrett_reduction: z:qelemB -> t:qelem_wide -> Stack unit (requires fun h -> live h z /\ live h t /\ qelem_wide_fits h t (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\ wide_as_nat h t < pow2 512) (ensures fun h0 _ h1 -> modifies (loc z) h0 h1 /\ qelem_fits h1 z (1, 1, 1, 1, 1) /\ as_nat h1 z == wide_as_nat h0 t % S.q)
[ { "abbrev": true, "full_module": "Spec.Ed25519", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Spec.BignumQ.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.BignumQ", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.BignumQ", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let barrett_reduction z t = let (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) = (t.(0ul), t.(1ul), t.(2ul), t.(3ul), t.(4ul), t.(5ul), t.(6ul), t.(7ul), t.(8ul), t.(9ul)) in let (z0, z1, z2, z3, z4)= barrett_reduction5 (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) in z.(0ul) <- z0; z.(1ul) <- z1; z.(2ul) <- z2; z.(3ul) <- z3; z.(4ul) <- z4
val barrett_reduction: z:qelemB -> t:qelem_wide -> Stack unit (requires fun h -> live h z /\ live h t /\ qelem_wide_fits h t (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\ wide_as_nat h t < pow2 512) (ensures fun h0 _ h1 -> modifies (loc z) h0 h1 /\ qelem_fits h1 z (1, 1, 1, 1, 1) /\ as_nat h1 z == wide_as_nat h0 t % S.q) let barrett_reduction z t =
true
null
false
let t0, t1, t2, t3, t4, t5, t6, t7, t8, t9 = (t.(0ul), t.(1ul), t.(2ul), t.(3ul), t.(4ul), t.(5ul), t.(6ul), t.(7ul), t.(8ul), t.(9ul)) in let z0, z1, z2, z3, z4 = barrett_reduction5 (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) in z.(0ul) <- z0; z.(1ul) <- z1; z.(2ul) <- z2; z.(3ul) <- z3; z.(4ul) <- z4
{ "checked_file": "Hacl.Impl.BignumQ.Mul.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.BignumQ.Mul.fst.checked", "Hacl.Spec.BignumQ.Lemmas.fst.checked", "Hacl.Bignum25519.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked" ], "interface_file": true, "source_file": "Hacl.Impl.BignumQ.Mul.fst" }
[]
[ "Hacl.Impl.BignumQ.Mul.qelemB", "Hacl.Impl.BignumQ.Mul.qelem_wide", "Lib.IntTypes.uint64", "Lib.Buffer.op_Array_Assignment", "FStar.UInt32.__uint_to_t", "Prims.unit", "Hacl.Spec.BignumQ.Definitions.qelem5", "Hacl.Spec.BignumQ.Mul.barrett_reduction5", "FStar.Pervasives.Native.Mktuple10", "FStar.Pervasives.Native.tuple10", "Lib.IntTypes.int_t", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "Lib.Buffer.op_Array_Access", "Lib.Buffer.MUT" ]
[]
module Hacl.Impl.BignumQ.Mul module ST = FStar.HyperStack.ST open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer include Hacl.Spec.BignumQ.Mul #set-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0"
false
false
Hacl.Impl.BignumQ.Mul.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val barrett_reduction: z:qelemB -> t:qelem_wide -> Stack unit (requires fun h -> live h z /\ live h t /\ qelem_wide_fits h t (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\ wide_as_nat h t < pow2 512) (ensures fun h0 _ h1 -> modifies (loc z) h0 h1 /\ qelem_fits h1 z (1, 1, 1, 1, 1) /\ as_nat h1 z == wide_as_nat h0 t % S.q)
[]
Hacl.Impl.BignumQ.Mul.barrett_reduction
{ "file_name": "code/ed25519/Hacl.Impl.BignumQ.Mul.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
z: Hacl.Impl.BignumQ.Mul.qelemB -> t: Hacl.Impl.BignumQ.Mul.qelem_wide -> FStar.HyperStack.ST.Stack Prims.unit
{ "end_col": 15, "end_line": 23, "start_col": 27, "start_line": 15 }
Prims.Tot
[ { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.BitVector", "short_module": "BV" }, { "abbrev": false, "full_module": "FStar.Mul", "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 } ]
false
let parse_bv8_kind = parse_u8_kind
let parse_bv8_kind =
false
null
false
parse_u8_kind
{ "checked_file": "LowParse.Spec.BitVector.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Int.fsti.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.BoundedInt.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "LowParse.Spec.BitVector.fst" }
[ "total" ]
[ "LowParse.Spec.Int.parse_u8_kind" ]
[]
module LowParse.Spec.BitVector open FStar.Mul module BV = FStar.BitVector module U8 = FStar.UInt8 module Seq = FStar.Seq (* Big-endian conversion of a bit vector to a UInt8 *) let rec to_uint8 (#n: nat { n <= 8 }) (x: BV.bv_t n) : Tot (y: U8.t { U8.v y < pow2 n }) = if n = 0 then 0uy else let hi = to_uint8 #(n - 1) (Seq.slice x 0 (n - 1)) in let hi' = hi `U8.mul` 2uy in let (r: U8.t { U8.v r < 2 }) = if Seq.index x (n - 1) then 1uy else 0uy in hi' `U8.add` r let rec of_uint8 (n: nat { n <= 8 }) (x: U8.t { U8.v x < pow2 n }) : Tot (BV.bv_t n) = if n = 0 then Seq.empty else let hi = of_uint8 (n - 1) (x `U8.div` 2uy) in Seq.snoc hi (x `U8.rem` 2uy = 1uy) #push-options "--z3rlimit 32" let rec to_uint8_of_uint8 (n: nat { n <= 8 }) (x: U8.t { U8.v x < pow2 n }) : Lemma (to_uint8 (of_uint8 n x) == x) = if n = 0 then () else begin assert (Seq.slice (of_uint8 n x) 0 (n - 1) `Seq.equal` of_uint8 (n - 1) (x `U8.div` 2uy)); to_uint8_of_uint8 (n - 1) (x `U8.div` 2uy) end let rec of_uint8_to_uint8 (#n: nat {n <= 8}) (x: BV.bv_t n) : Lemma (of_uint8 n (to_uint8 x) `Seq.equal` x) = if n = 0 then () else begin let x' = Seq.slice x 0 (n - 1) in of_uint8_to_uint8 #(n - 1) x' ; assert ( U8.v (to_uint8 #(n - 1) x') * 2 == U8.v (to_uint8 x) \/ U8.v (to_uint8 #(n - 1) x') * 2 + 1 == U8.v (to_uint8 x) ); assert (to_uint8 #(n - 1) x' == to_uint8 x `U8.div` 2uy); () end #pop-options (* parse a 8-bit vector *) open LowParse.Spec.Combinators open LowParse.Spec.Int let synth_bv8 (x: U8.t) : Tot (BV.bv_t 8) = of_uint8 8 x let synth_bv8_recip (x: BV.bv_t 8) : Tot U8.t = to_uint8 x let synth_bv8_injective : squash (synth_injective synth_bv8) = synth_inverse_intro' synth_bv8_recip synth_bv8 (fun x -> to_uint8_of_uint8 8 x ) let synth_bv8_inverse : squash (synth_inverse synth_bv8 synth_bv8_recip) = synth_inverse_intro' synth_bv8 synth_bv8_recip (fun x -> of_uint8_to_uint8 x )
false
true
LowParse.Spec.BitVector.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val parse_bv8_kind : LowParse.Spec.Base.parser_kind
[]
LowParse.Spec.BitVector.parse_bv8_kind
{ "file_name": "src/lowparse/LowParse.Spec.BitVector.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
LowParse.Spec.Base.parser_kind
{ "end_col": 34, "end_line": 87, "start_col": 21, "start_line": 87 }
Prims.Tot
val synth_bv8_recip (x: BV.bv_t 8) : Tot U8.t
[ { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.BitVector", "short_module": "BV" }, { "abbrev": false, "full_module": "FStar.Mul", "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 } ]
false
let synth_bv8_recip (x: BV.bv_t 8) : Tot U8.t = to_uint8 x
val synth_bv8_recip (x: BV.bv_t 8) : Tot U8.t let synth_bv8_recip (x: BV.bv_t 8) : Tot U8.t =
false
null
false
to_uint8 x
{ "checked_file": "LowParse.Spec.BitVector.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Int.fsti.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.BoundedInt.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "LowParse.Spec.BitVector.fst" }
[ "total" ]
[ "FStar.BitVector.bv_t", "LowParse.Spec.BitVector.to_uint8", "FStar.UInt8.t" ]
[]
module LowParse.Spec.BitVector open FStar.Mul module BV = FStar.BitVector module U8 = FStar.UInt8 module Seq = FStar.Seq (* Big-endian conversion of a bit vector to a UInt8 *) let rec to_uint8 (#n: nat { n <= 8 }) (x: BV.bv_t n) : Tot (y: U8.t { U8.v y < pow2 n }) = if n = 0 then 0uy else let hi = to_uint8 #(n - 1) (Seq.slice x 0 (n - 1)) in let hi' = hi `U8.mul` 2uy in let (r: U8.t { U8.v r < 2 }) = if Seq.index x (n - 1) then 1uy else 0uy in hi' `U8.add` r let rec of_uint8 (n: nat { n <= 8 }) (x: U8.t { U8.v x < pow2 n }) : Tot (BV.bv_t n) = if n = 0 then Seq.empty else let hi = of_uint8 (n - 1) (x `U8.div` 2uy) in Seq.snoc hi (x `U8.rem` 2uy = 1uy) #push-options "--z3rlimit 32" let rec to_uint8_of_uint8 (n: nat { n <= 8 }) (x: U8.t { U8.v x < pow2 n }) : Lemma (to_uint8 (of_uint8 n x) == x) = if n = 0 then () else begin assert (Seq.slice (of_uint8 n x) 0 (n - 1) `Seq.equal` of_uint8 (n - 1) (x `U8.div` 2uy)); to_uint8_of_uint8 (n - 1) (x `U8.div` 2uy) end let rec of_uint8_to_uint8 (#n: nat {n <= 8}) (x: BV.bv_t n) : Lemma (of_uint8 n (to_uint8 x) `Seq.equal` x) = if n = 0 then () else begin let x' = Seq.slice x 0 (n - 1) in of_uint8_to_uint8 #(n - 1) x' ; assert ( U8.v (to_uint8 #(n - 1) x') * 2 == U8.v (to_uint8 x) \/ U8.v (to_uint8 #(n - 1) x') * 2 + 1 == U8.v (to_uint8 x) ); assert (to_uint8 #(n - 1) x' == to_uint8 x `U8.div` 2uy); () end #pop-options (* parse a 8-bit vector *) open LowParse.Spec.Combinators open LowParse.Spec.Int let synth_bv8 (x: U8.t) : Tot (BV.bv_t 8) = of_uint8 8 x
false
false
LowParse.Spec.BitVector.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val synth_bv8_recip (x: BV.bv_t 8) : Tot U8.t
[]
LowParse.Spec.BitVector.synth_bv8_recip
{ "file_name": "src/lowparse/LowParse.Spec.BitVector.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
x: FStar.BitVector.bv_t 8 -> FStar.UInt8.t
{ "end_col": 12, "end_line": 75, "start_col": 2, "start_line": 75 }
Prims.Tot
val parse_extra_bv8_kind (n: nat) : Tot parser_kind
[ { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.BitVector", "short_module": "BV" }, { "abbrev": false, "full_module": "FStar.Mul", "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 } ]
false
let parse_extra_bv8_kind (n: nat) : Tot parser_kind = parse_filter_kind parse_u8_kind
val parse_extra_bv8_kind (n: nat) : Tot parser_kind let parse_extra_bv8_kind (n: nat) : Tot parser_kind =
false
null
false
parse_filter_kind parse_u8_kind
{ "checked_file": "LowParse.Spec.BitVector.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Int.fsti.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.BoundedInt.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "LowParse.Spec.BitVector.fst" }
[ "total" ]
[ "Prims.nat", "LowParse.Spec.Combinators.parse_filter_kind", "LowParse.Spec.Int.parse_u8_kind", "LowParse.Spec.Base.parser_kind" ]
[]
module LowParse.Spec.BitVector open FStar.Mul module BV = FStar.BitVector module U8 = FStar.UInt8 module Seq = FStar.Seq (* Big-endian conversion of a bit vector to a UInt8 *) let rec to_uint8 (#n: nat { n <= 8 }) (x: BV.bv_t n) : Tot (y: U8.t { U8.v y < pow2 n }) = if n = 0 then 0uy else let hi = to_uint8 #(n - 1) (Seq.slice x 0 (n - 1)) in let hi' = hi `U8.mul` 2uy in let (r: U8.t { U8.v r < 2 }) = if Seq.index x (n - 1) then 1uy else 0uy in hi' `U8.add` r let rec of_uint8 (n: nat { n <= 8 }) (x: U8.t { U8.v x < pow2 n }) : Tot (BV.bv_t n) = if n = 0 then Seq.empty else let hi = of_uint8 (n - 1) (x `U8.div` 2uy) in Seq.snoc hi (x `U8.rem` 2uy = 1uy) #push-options "--z3rlimit 32" let rec to_uint8_of_uint8 (n: nat { n <= 8 }) (x: U8.t { U8.v x < pow2 n }) : Lemma (to_uint8 (of_uint8 n x) == x) = if n = 0 then () else begin assert (Seq.slice (of_uint8 n x) 0 (n - 1) `Seq.equal` of_uint8 (n - 1) (x `U8.div` 2uy)); to_uint8_of_uint8 (n - 1) (x `U8.div` 2uy) end let rec of_uint8_to_uint8 (#n: nat {n <= 8}) (x: BV.bv_t n) : Lemma (of_uint8 n (to_uint8 x) `Seq.equal` x) = if n = 0 then () else begin let x' = Seq.slice x 0 (n - 1) in of_uint8_to_uint8 #(n - 1) x' ; assert ( U8.v (to_uint8 #(n - 1) x') * 2 == U8.v (to_uint8 x) \/ U8.v (to_uint8 #(n - 1) x') * 2 + 1 == U8.v (to_uint8 x) ); assert (to_uint8 #(n - 1) x' == to_uint8 x `U8.div` 2uy); () end #pop-options (* parse a 8-bit vector *) open LowParse.Spec.Combinators open LowParse.Spec.Int let synth_bv8 (x: U8.t) : Tot (BV.bv_t 8) = of_uint8 8 x let synth_bv8_recip (x: BV.bv_t 8) : Tot U8.t = to_uint8 x let synth_bv8_injective : squash (synth_injective synth_bv8) = synth_inverse_intro' synth_bv8_recip synth_bv8 (fun x -> to_uint8_of_uint8 8 x ) let synth_bv8_inverse : squash (synth_inverse synth_bv8 synth_bv8_recip) = synth_inverse_intro' synth_bv8 synth_bv8_recip (fun x -> of_uint8_to_uint8 x ) let parse_bv8_kind = parse_u8_kind let parse_bv8 : parser parse_bv8_kind (BV.bv_t 8) = parse_u8 `parse_synth` synth_bv8 let serialize_bv8 : serializer parse_bv8 = serialize_synth parse_u8 synth_bv8 serialize_u8 synth_bv8_recip () (* parse a 8*n bit vector *) let synth_byte_bv (n: nat) (x: (BV.bv_t 8 & BV.bv_t (8 * n))) : Tot (BV.bv_t (8 * (1 + n))) = Seq.append (fst x) (snd x) let synth_byte_bv_recip (n: nat) (x: BV.bv_t (8 * (1 + n))) : Tot (BV.bv_t 8 & BV.bv_t (8 * n)) = Seq.slice x 0 8, Seq.slice x 8 (Seq.length x) let synth_byte_bv_injective (n: nat) : Lemma (synth_injective (synth_byte_bv n)) [SMTPat (synth_injective (synth_byte_bv n))] = synth_inverse_intro' (synth_byte_bv_recip n) (synth_byte_bv n) (fun x -> let (hd, tl) = x in let (hd', tl') = synth_byte_bv_recip n (synth_byte_bv n x) in assert (hd `Seq.equal` hd'); assert (tl `Seq.equal` tl') ) let synth_byte_bv_inverse (n: nat) : Lemma (synth_inverse (synth_byte_bv n) (synth_byte_bv_recip n)) [SMTPat (synth_inverse (synth_byte_bv n) (synth_byte_bv_recip n))] = synth_inverse_intro' (synth_byte_bv n) (synth_byte_bv_recip n) (fun x -> assert (synth_byte_bv n (synth_byte_bv_recip n x) `Seq.equal` x) ) let rec parse_byte_bv_kind' (n: nat) : Tot parser_kind = if n = 0 then parse_ret_kind else parse_bv8_kind `and_then_kind` parse_byte_bv_kind' (n - 1) let parse_byte_bv_kind (n: nat) : Tot parser_kind = strong_parser_kind n n (Some ParserKindMetadataTotal) let rec parse_byte_bv_kind_eq (n: nat) : Lemma (parse_byte_bv_kind n == parse_byte_bv_kind' n) = if n = 0 then () else parse_byte_bv_kind_eq (n - 1) let rec parse_byte_bv (n: nat) : Tot (parser (parse_byte_bv_kind n) (BV.bv_t (8 * n))) = parse_byte_bv_kind_eq n; if n = 0 then parse_ret Seq.empty else (parse_bv8 `nondep_then` parse_byte_bv (n - 1)) `parse_synth` synth_byte_bv (n - 1) let rec serialize_byte_bv (n: nat) : Tot (serializer (parse_byte_bv n)) = parse_byte_bv_kind_eq n; if n = 0 then serialize_ret Seq.empty (fun (x: BV.bv_t 0) -> assert (x `Seq.equal` Seq.empty)) else serialize_synth (parse_bv8 `nondep_then` parse_byte_bv (n - 1)) (synth_byte_bv (n - 1)) (serialize_bv8 `serialize_nondep_then` serialize_byte_bv (n - 1)) (synth_byte_bv_recip (n - 1)) () (* parse extra bits (big-endian with the first bits equal to 0) *) let extra_bytes_prop (n: nat) (x: U8.t) : Tot bool = U8.v x < pow2 (n % 8) let synth_extra_bv8 (n: nat) (x: parse_filter_refine (extra_bytes_prop n)) : Tot (BV.bv_t (n % 8)) = of_uint8 (n % 8) x let synth_extra_bv8_recip (n: nat) (x: BV.bv_t (n % 8)) : Tot (parse_filter_refine (extra_bytes_prop n)) = to_uint8 x let synth_extra_bv8_injective (n: nat) : Lemma (synth_injective (synth_extra_bv8 n)) [SMTPat (synth_injective (synth_extra_bv8 n))] = synth_inverse_intro' (synth_extra_bv8_recip n) (synth_extra_bv8 n) (fun x -> to_uint8_of_uint8 (n % 8) x ) let synth_extra_bv8_inverse (n: nat) : Lemma (synth_inverse (synth_extra_bv8 n) (synth_extra_bv8_recip n)) [SMTPat (synth_inverse (synth_extra_bv8 n) (synth_extra_bv8_recip n))] = synth_inverse_intro' (synth_extra_bv8 n) (synth_extra_bv8_recip n) (fun x -> of_uint8_to_uint8 x )
false
true
LowParse.Spec.BitVector.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val parse_extra_bv8_kind (n: nat) : Tot parser_kind
[]
LowParse.Spec.BitVector.parse_extra_bv8_kind
{ "file_name": "src/lowparse/LowParse.Spec.BitVector.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
n: Prims.nat -> LowParse.Spec.Base.parser_kind
{ "end_col": 33, "end_line": 187, "start_col": 2, "start_line": 187 }
Prims.Tot
val parse_bounded_bv_kind (min: nat) (max: nat{min <= max}) (hk: parser_kind) : Tot parser_kind
[ { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.BitVector", "short_module": "BV" }, { "abbrev": false, "full_module": "FStar.Mul", "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 } ]
false
let parse_bounded_bv_kind (min: nat) (max: nat { min <= max }) (hk: parser_kind) : Tot parser_kind = hk `and_then_kind` parse_bounded_bv_payload_kind min max
val parse_bounded_bv_kind (min: nat) (max: nat{min <= max}) (hk: parser_kind) : Tot parser_kind let parse_bounded_bv_kind (min: nat) (max: nat{min <= max}) (hk: parser_kind) : Tot parser_kind =
false
null
false
hk `and_then_kind` (parse_bounded_bv_payload_kind min max)
{ "checked_file": "LowParse.Spec.BitVector.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Int.fsti.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.BoundedInt.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "LowParse.Spec.BitVector.fst" }
[ "total" ]
[ "Prims.nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Combinators.and_then_kind", "LowParse.Spec.BitVector.parse_bounded_bv_payload_kind" ]
[]
module LowParse.Spec.BitVector open FStar.Mul module BV = FStar.BitVector module U8 = FStar.UInt8 module Seq = FStar.Seq (* Big-endian conversion of a bit vector to a UInt8 *) let rec to_uint8 (#n: nat { n <= 8 }) (x: BV.bv_t n) : Tot (y: U8.t { U8.v y < pow2 n }) = if n = 0 then 0uy else let hi = to_uint8 #(n - 1) (Seq.slice x 0 (n - 1)) in let hi' = hi `U8.mul` 2uy in let (r: U8.t { U8.v r < 2 }) = if Seq.index x (n - 1) then 1uy else 0uy in hi' `U8.add` r let rec of_uint8 (n: nat { n <= 8 }) (x: U8.t { U8.v x < pow2 n }) : Tot (BV.bv_t n) = if n = 0 then Seq.empty else let hi = of_uint8 (n - 1) (x `U8.div` 2uy) in Seq.snoc hi (x `U8.rem` 2uy = 1uy) #push-options "--z3rlimit 32" let rec to_uint8_of_uint8 (n: nat { n <= 8 }) (x: U8.t { U8.v x < pow2 n }) : Lemma (to_uint8 (of_uint8 n x) == x) = if n = 0 then () else begin assert (Seq.slice (of_uint8 n x) 0 (n - 1) `Seq.equal` of_uint8 (n - 1) (x `U8.div` 2uy)); to_uint8_of_uint8 (n - 1) (x `U8.div` 2uy) end let rec of_uint8_to_uint8 (#n: nat {n <= 8}) (x: BV.bv_t n) : Lemma (of_uint8 n (to_uint8 x) `Seq.equal` x) = if n = 0 then () else begin let x' = Seq.slice x 0 (n - 1) in of_uint8_to_uint8 #(n - 1) x' ; assert ( U8.v (to_uint8 #(n - 1) x') * 2 == U8.v (to_uint8 x) \/ U8.v (to_uint8 #(n - 1) x') * 2 + 1 == U8.v (to_uint8 x) ); assert (to_uint8 #(n - 1) x' == to_uint8 x `U8.div` 2uy); () end #pop-options (* parse a 8-bit vector *) open LowParse.Spec.Combinators open LowParse.Spec.Int let synth_bv8 (x: U8.t) : Tot (BV.bv_t 8) = of_uint8 8 x let synth_bv8_recip (x: BV.bv_t 8) : Tot U8.t = to_uint8 x let synth_bv8_injective : squash (synth_injective synth_bv8) = synth_inverse_intro' synth_bv8_recip synth_bv8 (fun x -> to_uint8_of_uint8 8 x ) let synth_bv8_inverse : squash (synth_inverse synth_bv8 synth_bv8_recip) = synth_inverse_intro' synth_bv8 synth_bv8_recip (fun x -> of_uint8_to_uint8 x ) let parse_bv8_kind = parse_u8_kind let parse_bv8 : parser parse_bv8_kind (BV.bv_t 8) = parse_u8 `parse_synth` synth_bv8 let serialize_bv8 : serializer parse_bv8 = serialize_synth parse_u8 synth_bv8 serialize_u8 synth_bv8_recip () (* parse a 8*n bit vector *) let synth_byte_bv (n: nat) (x: (BV.bv_t 8 & BV.bv_t (8 * n))) : Tot (BV.bv_t (8 * (1 + n))) = Seq.append (fst x) (snd x) let synth_byte_bv_recip (n: nat) (x: BV.bv_t (8 * (1 + n))) : Tot (BV.bv_t 8 & BV.bv_t (8 * n)) = Seq.slice x 0 8, Seq.slice x 8 (Seq.length x) let synth_byte_bv_injective (n: nat) : Lemma (synth_injective (synth_byte_bv n)) [SMTPat (synth_injective (synth_byte_bv n))] = synth_inverse_intro' (synth_byte_bv_recip n) (synth_byte_bv n) (fun x -> let (hd, tl) = x in let (hd', tl') = synth_byte_bv_recip n (synth_byte_bv n x) in assert (hd `Seq.equal` hd'); assert (tl `Seq.equal` tl') ) let synth_byte_bv_inverse (n: nat) : Lemma (synth_inverse (synth_byte_bv n) (synth_byte_bv_recip n)) [SMTPat (synth_inverse (synth_byte_bv n) (synth_byte_bv_recip n))] = synth_inverse_intro' (synth_byte_bv n) (synth_byte_bv_recip n) (fun x -> assert (synth_byte_bv n (synth_byte_bv_recip n x) `Seq.equal` x) ) let rec parse_byte_bv_kind' (n: nat) : Tot parser_kind = if n = 0 then parse_ret_kind else parse_bv8_kind `and_then_kind` parse_byte_bv_kind' (n - 1) let parse_byte_bv_kind (n: nat) : Tot parser_kind = strong_parser_kind n n (Some ParserKindMetadataTotal) let rec parse_byte_bv_kind_eq (n: nat) : Lemma (parse_byte_bv_kind n == parse_byte_bv_kind' n) = if n = 0 then () else parse_byte_bv_kind_eq (n - 1) let rec parse_byte_bv (n: nat) : Tot (parser (parse_byte_bv_kind n) (BV.bv_t (8 * n))) = parse_byte_bv_kind_eq n; if n = 0 then parse_ret Seq.empty else (parse_bv8 `nondep_then` parse_byte_bv (n - 1)) `parse_synth` synth_byte_bv (n - 1) let rec serialize_byte_bv (n: nat) : Tot (serializer (parse_byte_bv n)) = parse_byte_bv_kind_eq n; if n = 0 then serialize_ret Seq.empty (fun (x: BV.bv_t 0) -> assert (x `Seq.equal` Seq.empty)) else serialize_synth (parse_bv8 `nondep_then` parse_byte_bv (n - 1)) (synth_byte_bv (n - 1)) (serialize_bv8 `serialize_nondep_then` serialize_byte_bv (n - 1)) (synth_byte_bv_recip (n - 1)) () (* parse extra bits (big-endian with the first bits equal to 0) *) let extra_bytes_prop (n: nat) (x: U8.t) : Tot bool = U8.v x < pow2 (n % 8) let synth_extra_bv8 (n: nat) (x: parse_filter_refine (extra_bytes_prop n)) : Tot (BV.bv_t (n % 8)) = of_uint8 (n % 8) x let synth_extra_bv8_recip (n: nat) (x: BV.bv_t (n % 8)) : Tot (parse_filter_refine (extra_bytes_prop n)) = to_uint8 x let synth_extra_bv8_injective (n: nat) : Lemma (synth_injective (synth_extra_bv8 n)) [SMTPat (synth_injective (synth_extra_bv8 n))] = synth_inverse_intro' (synth_extra_bv8_recip n) (synth_extra_bv8 n) (fun x -> to_uint8_of_uint8 (n % 8) x ) let synth_extra_bv8_inverse (n: nat) : Lemma (synth_inverse (synth_extra_bv8 n) (synth_extra_bv8_recip n)) [SMTPat (synth_inverse (synth_extra_bv8 n) (synth_extra_bv8_recip n))] = synth_inverse_intro' (synth_extra_bv8 n) (synth_extra_bv8_recip n) (fun x -> of_uint8_to_uint8 x ) let parse_extra_bv8_kind (n: nat) : Tot parser_kind = parse_filter_kind parse_u8_kind let parse_extra_bv8 (n: nat) : Tot (parser (parse_extra_bv8_kind n) (BV.bv_t (n % 8))) = (parse_u8 `parse_filter` extra_bytes_prop n) `parse_synth` synth_extra_bv8 n let serialize_extra_bv8 (n: nat) : Tot (serializer (parse_extra_bv8 n)) = serialize_synth _ (synth_extra_bv8 n) (serialize_filter serialize_u8 (extra_bytes_prop n)) (synth_extra_bv8_recip n) () (* parse a bitvector, general *) let synth_bv (n: nat) (x: (BV.bv_t (n % 8) & BV.bv_t (8 * (n / 8)))) : Tot (BV.bv_t n) = Seq.append (fst x) (snd x) let synth_bv_recip (n: nat) (x: BV.bv_t n) : Tot (BV.bv_t (n % 8) & BV.bv_t (8 * (n / 8))) = Seq.slice x 0 (n % 8), Seq.slice x (n % 8) (Seq.length x) let synth_bv_injective (n: nat) : Lemma (synth_injective (synth_bv n)) [SMTPat (synth_injective (synth_bv n))] = synth_inverse_intro' (synth_bv_recip n) (synth_bv n) (fun x -> let (hd, tl) = x in let (hd', tl') = synth_bv_recip n (synth_bv n x) in assert (hd `Seq.equal` hd'); assert (tl `Seq.equal` tl') ) let synth_bv_inverse (n: nat) : Lemma (synth_inverse (synth_bv n) (synth_bv_recip n)) [SMTPat (synth_inverse (synth_bv n) (synth_bv_recip n))] = synth_inverse_intro' (synth_bv n) (synth_bv_recip n) (fun x -> assert (synth_bv n (synth_bv_recip n x) `Seq.equal` x) ) let parse_bv_kind (n: nat) : Tot parser_kind = if n % 8 = 0 then strong_parser_kind (n / 8) (n / 8) (Some ParserKindMetadataTotal) else strong_parser_kind (1 + n / 8) (1 + n / 8) None let parse_bv (n: nat) : Tot (parser (parse_bv_kind n) (BV.bv_t n)) = if n % 8 = 0 then parse_byte_bv (n / 8) else ((parse_extra_bv8 n `nondep_then` parse_byte_bv (n / 8)) `parse_synth` synth_bv n) let serialize_bv (n: nat) : Tot (serializer (parse_bv n)) = if n % 8 = 0 then serialize_byte_bv (n / 8) else serialize_synth _ (synth_bv n) (serialize_extra_bv8 n `serialize_nondep_then` serialize_byte_bv (n / 8)) (synth_bv_recip n) () (* parse a bounded bit vector *) module U32 = FStar.UInt32 open LowParse.Spec.BoundedInt inline_for_extraction let bounded_bv_t (min: nat) (max: nat { min <= max }) : Tot Type = (bitsize: bounded_int32 min max & BV.bv_t (U32.v bitsize)) let parse_bounded_bv_payload_kind (min: nat) (max: nat { min <= max }) : Tot parser_kind = strong_parser_kind (if min % 8 = 0 then min / 8 else 1 + min / 8) (if max % 8 = 0 then max / 8 else 1 + max / 8) None let parse_bounded_bv_payload_kind_is_weaker_than_parse_bv_kind (min: nat) (max: nat) (n: nat) : Lemma (requires (min <= n /\ n <= max)) (ensures ( min <= n /\ n <= max /\ parse_bounded_bv_payload_kind min max `is_weaker_than` parse_bv_kind n )) [SMTPat (parse_bounded_bv_payload_kind min max `is_weaker_than` parse_bv_kind n)] = () let parse_bounded_bv_kind (min: nat) (max: nat { min <= max }) (hk: parser_kind)
false
false
LowParse.Spec.BitVector.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val parse_bounded_bv_kind (min: nat) (max: nat{min <= max}) (hk: parser_kind) : Tot parser_kind
[]
LowParse.Spec.BitVector.parse_bounded_bv_kind
{ "file_name": "src/lowparse/LowParse.Spec.BitVector.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
min: Prims.nat -> max: Prims.nat{min <= max} -> hk: LowParse.Spec.Base.parser_kind -> LowParse.Spec.Base.parser_kind
{ "end_col": 58, "end_line": 285, "start_col": 2, "start_line": 285 }
Prims.Tot
val parse_byte_bv_kind (n: nat) : Tot parser_kind
[ { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.BitVector", "short_module": "BV" }, { "abbrev": false, "full_module": "FStar.Mul", "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 } ]
false
let parse_byte_bv_kind (n: nat) : Tot parser_kind = strong_parser_kind n n (Some ParserKindMetadataTotal)
val parse_byte_bv_kind (n: nat) : Tot parser_kind let parse_byte_bv_kind (n: nat) : Tot parser_kind =
false
null
false
strong_parser_kind n n (Some ParserKindMetadataTotal)
{ "checked_file": "LowParse.Spec.BitVector.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Int.fsti.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.BoundedInt.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "LowParse.Spec.BitVector.fst" }
[ "total" ]
[ "Prims.nat", "LowParse.Spec.Base.strong_parser_kind", "FStar.Pervasives.Native.Some", "LowParse.Spec.Base.parser_kind_metadata_some", "LowParse.Spec.Base.ParserKindMetadataTotal", "LowParse.Spec.Base.parser_kind" ]
[]
module LowParse.Spec.BitVector open FStar.Mul module BV = FStar.BitVector module U8 = FStar.UInt8 module Seq = FStar.Seq (* Big-endian conversion of a bit vector to a UInt8 *) let rec to_uint8 (#n: nat { n <= 8 }) (x: BV.bv_t n) : Tot (y: U8.t { U8.v y < pow2 n }) = if n = 0 then 0uy else let hi = to_uint8 #(n - 1) (Seq.slice x 0 (n - 1)) in let hi' = hi `U8.mul` 2uy in let (r: U8.t { U8.v r < 2 }) = if Seq.index x (n - 1) then 1uy else 0uy in hi' `U8.add` r let rec of_uint8 (n: nat { n <= 8 }) (x: U8.t { U8.v x < pow2 n }) : Tot (BV.bv_t n) = if n = 0 then Seq.empty else let hi = of_uint8 (n - 1) (x `U8.div` 2uy) in Seq.snoc hi (x `U8.rem` 2uy = 1uy) #push-options "--z3rlimit 32" let rec to_uint8_of_uint8 (n: nat { n <= 8 }) (x: U8.t { U8.v x < pow2 n }) : Lemma (to_uint8 (of_uint8 n x) == x) = if n = 0 then () else begin assert (Seq.slice (of_uint8 n x) 0 (n - 1) `Seq.equal` of_uint8 (n - 1) (x `U8.div` 2uy)); to_uint8_of_uint8 (n - 1) (x `U8.div` 2uy) end let rec of_uint8_to_uint8 (#n: nat {n <= 8}) (x: BV.bv_t n) : Lemma (of_uint8 n (to_uint8 x) `Seq.equal` x) = if n = 0 then () else begin let x' = Seq.slice x 0 (n - 1) in of_uint8_to_uint8 #(n - 1) x' ; assert ( U8.v (to_uint8 #(n - 1) x') * 2 == U8.v (to_uint8 x) \/ U8.v (to_uint8 #(n - 1) x') * 2 + 1 == U8.v (to_uint8 x) ); assert (to_uint8 #(n - 1) x' == to_uint8 x `U8.div` 2uy); () end #pop-options (* parse a 8-bit vector *) open LowParse.Spec.Combinators open LowParse.Spec.Int let synth_bv8 (x: U8.t) : Tot (BV.bv_t 8) = of_uint8 8 x let synth_bv8_recip (x: BV.bv_t 8) : Tot U8.t = to_uint8 x let synth_bv8_injective : squash (synth_injective synth_bv8) = synth_inverse_intro' synth_bv8_recip synth_bv8 (fun x -> to_uint8_of_uint8 8 x ) let synth_bv8_inverse : squash (synth_inverse synth_bv8 synth_bv8_recip) = synth_inverse_intro' synth_bv8 synth_bv8_recip (fun x -> of_uint8_to_uint8 x ) let parse_bv8_kind = parse_u8_kind let parse_bv8 : parser parse_bv8_kind (BV.bv_t 8) = parse_u8 `parse_synth` synth_bv8 let serialize_bv8 : serializer parse_bv8 = serialize_synth parse_u8 synth_bv8 serialize_u8 synth_bv8_recip () (* parse a 8*n bit vector *) let synth_byte_bv (n: nat) (x: (BV.bv_t 8 & BV.bv_t (8 * n))) : Tot (BV.bv_t (8 * (1 + n))) = Seq.append (fst x) (snd x) let synth_byte_bv_recip (n: nat) (x: BV.bv_t (8 * (1 + n))) : Tot (BV.bv_t 8 & BV.bv_t (8 * n)) = Seq.slice x 0 8, Seq.slice x 8 (Seq.length x) let synth_byte_bv_injective (n: nat) : Lemma (synth_injective (synth_byte_bv n)) [SMTPat (synth_injective (synth_byte_bv n))] = synth_inverse_intro' (synth_byte_bv_recip n) (synth_byte_bv n) (fun x -> let (hd, tl) = x in let (hd', tl') = synth_byte_bv_recip n (synth_byte_bv n x) in assert (hd `Seq.equal` hd'); assert (tl `Seq.equal` tl') ) let synth_byte_bv_inverse (n: nat) : Lemma (synth_inverse (synth_byte_bv n) (synth_byte_bv_recip n)) [SMTPat (synth_inverse (synth_byte_bv n) (synth_byte_bv_recip n))] = synth_inverse_intro' (synth_byte_bv n) (synth_byte_bv_recip n) (fun x -> assert (synth_byte_bv n (synth_byte_bv_recip n x) `Seq.equal` x) ) let rec parse_byte_bv_kind' (n: nat) : Tot parser_kind = if n = 0 then parse_ret_kind else parse_bv8_kind `and_then_kind` parse_byte_bv_kind' (n - 1)
false
true
LowParse.Spec.BitVector.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val parse_byte_bv_kind (n: nat) : Tot parser_kind
[]
LowParse.Spec.BitVector.parse_byte_bv_kind
{ "file_name": "src/lowparse/LowParse.Spec.BitVector.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
n: Prims.nat -> LowParse.Spec.Base.parser_kind
{ "end_col": 55, "end_line": 132, "start_col": 2, "start_line": 132 }
Prims.Tot
val extra_bytes_prop (n: nat) (x: U8.t) : Tot bool
[ { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.BitVector", "short_module": "BV" }, { "abbrev": false, "full_module": "FStar.Mul", "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 } ]
false
let extra_bytes_prop (n: nat) (x: U8.t) : Tot bool = U8.v x < pow2 (n % 8)
val extra_bytes_prop (n: nat) (x: U8.t) : Tot bool let extra_bytes_prop (n: nat) (x: U8.t) : Tot bool =
false
null
false
U8.v x < pow2 (n % 8)
{ "checked_file": "LowParse.Spec.BitVector.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Int.fsti.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.BoundedInt.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "LowParse.Spec.BitVector.fst" }
[ "total" ]
[ "Prims.nat", "FStar.UInt8.t", "Prims.op_LessThan", "FStar.UInt8.v", "Prims.pow2", "Prims.op_Modulus", "Prims.bool" ]
[]
module LowParse.Spec.BitVector open FStar.Mul module BV = FStar.BitVector module U8 = FStar.UInt8 module Seq = FStar.Seq (* Big-endian conversion of a bit vector to a UInt8 *) let rec to_uint8 (#n: nat { n <= 8 }) (x: BV.bv_t n) : Tot (y: U8.t { U8.v y < pow2 n }) = if n = 0 then 0uy else let hi = to_uint8 #(n - 1) (Seq.slice x 0 (n - 1)) in let hi' = hi `U8.mul` 2uy in let (r: U8.t { U8.v r < 2 }) = if Seq.index x (n - 1) then 1uy else 0uy in hi' `U8.add` r let rec of_uint8 (n: nat { n <= 8 }) (x: U8.t { U8.v x < pow2 n }) : Tot (BV.bv_t n) = if n = 0 then Seq.empty else let hi = of_uint8 (n - 1) (x `U8.div` 2uy) in Seq.snoc hi (x `U8.rem` 2uy = 1uy) #push-options "--z3rlimit 32" let rec to_uint8_of_uint8 (n: nat { n <= 8 }) (x: U8.t { U8.v x < pow2 n }) : Lemma (to_uint8 (of_uint8 n x) == x) = if n = 0 then () else begin assert (Seq.slice (of_uint8 n x) 0 (n - 1) `Seq.equal` of_uint8 (n - 1) (x `U8.div` 2uy)); to_uint8_of_uint8 (n - 1) (x `U8.div` 2uy) end let rec of_uint8_to_uint8 (#n: nat {n <= 8}) (x: BV.bv_t n) : Lemma (of_uint8 n (to_uint8 x) `Seq.equal` x) = if n = 0 then () else begin let x' = Seq.slice x 0 (n - 1) in of_uint8_to_uint8 #(n - 1) x' ; assert ( U8.v (to_uint8 #(n - 1) x') * 2 == U8.v (to_uint8 x) \/ U8.v (to_uint8 #(n - 1) x') * 2 + 1 == U8.v (to_uint8 x) ); assert (to_uint8 #(n - 1) x' == to_uint8 x `U8.div` 2uy); () end #pop-options (* parse a 8-bit vector *) open LowParse.Spec.Combinators open LowParse.Spec.Int let synth_bv8 (x: U8.t) : Tot (BV.bv_t 8) = of_uint8 8 x let synth_bv8_recip (x: BV.bv_t 8) : Tot U8.t = to_uint8 x let synth_bv8_injective : squash (synth_injective synth_bv8) = synth_inverse_intro' synth_bv8_recip synth_bv8 (fun x -> to_uint8_of_uint8 8 x ) let synth_bv8_inverse : squash (synth_inverse synth_bv8 synth_bv8_recip) = synth_inverse_intro' synth_bv8 synth_bv8_recip (fun x -> of_uint8_to_uint8 x ) let parse_bv8_kind = parse_u8_kind let parse_bv8 : parser parse_bv8_kind (BV.bv_t 8) = parse_u8 `parse_synth` synth_bv8 let serialize_bv8 : serializer parse_bv8 = serialize_synth parse_u8 synth_bv8 serialize_u8 synth_bv8_recip () (* parse a 8*n bit vector *) let synth_byte_bv (n: nat) (x: (BV.bv_t 8 & BV.bv_t (8 * n))) : Tot (BV.bv_t (8 * (1 + n))) = Seq.append (fst x) (snd x) let synth_byte_bv_recip (n: nat) (x: BV.bv_t (8 * (1 + n))) : Tot (BV.bv_t 8 & BV.bv_t (8 * n)) = Seq.slice x 0 8, Seq.slice x 8 (Seq.length x) let synth_byte_bv_injective (n: nat) : Lemma (synth_injective (synth_byte_bv n)) [SMTPat (synth_injective (synth_byte_bv n))] = synth_inverse_intro' (synth_byte_bv_recip n) (synth_byte_bv n) (fun x -> let (hd, tl) = x in let (hd', tl') = synth_byte_bv_recip n (synth_byte_bv n x) in assert (hd `Seq.equal` hd'); assert (tl `Seq.equal` tl') ) let synth_byte_bv_inverse (n: nat) : Lemma (synth_inverse (synth_byte_bv n) (synth_byte_bv_recip n)) [SMTPat (synth_inverse (synth_byte_bv n) (synth_byte_bv_recip n))] = synth_inverse_intro' (synth_byte_bv n) (synth_byte_bv_recip n) (fun x -> assert (synth_byte_bv n (synth_byte_bv_recip n x) `Seq.equal` x) ) let rec parse_byte_bv_kind' (n: nat) : Tot parser_kind = if n = 0 then parse_ret_kind else parse_bv8_kind `and_then_kind` parse_byte_bv_kind' (n - 1) let parse_byte_bv_kind (n: nat) : Tot parser_kind = strong_parser_kind n n (Some ParserKindMetadataTotal) let rec parse_byte_bv_kind_eq (n: nat) : Lemma (parse_byte_bv_kind n == parse_byte_bv_kind' n) = if n = 0 then () else parse_byte_bv_kind_eq (n - 1) let rec parse_byte_bv (n: nat) : Tot (parser (parse_byte_bv_kind n) (BV.bv_t (8 * n))) = parse_byte_bv_kind_eq n; if n = 0 then parse_ret Seq.empty else (parse_bv8 `nondep_then` parse_byte_bv (n - 1)) `parse_synth` synth_byte_bv (n - 1) let rec serialize_byte_bv (n: nat) : Tot (serializer (parse_byte_bv n)) = parse_byte_bv_kind_eq n; if n = 0 then serialize_ret Seq.empty (fun (x: BV.bv_t 0) -> assert (x `Seq.equal` Seq.empty)) else serialize_synth (parse_bv8 `nondep_then` parse_byte_bv (n - 1)) (synth_byte_bv (n - 1)) (serialize_bv8 `serialize_nondep_then` serialize_byte_bv (n - 1)) (synth_byte_bv_recip (n - 1)) () (* parse extra bits (big-endian with the first bits equal to 0) *)
false
true
LowParse.Spec.BitVector.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val extra_bytes_prop (n: nat) (x: U8.t) : Tot bool
[]
LowParse.Spec.BitVector.extra_bytes_prop
{ "file_name": "src/lowparse/LowParse.Spec.BitVector.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
n: Prims.nat -> x: FStar.UInt8.t -> Prims.bool
{ "end_col": 23, "end_line": 164, "start_col": 2, "start_line": 164 }
Prims.Tot
val synth_bv8_inverse:squash (synth_inverse synth_bv8 synth_bv8_recip)
[ { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.BitVector", "short_module": "BV" }, { "abbrev": false, "full_module": "FStar.Mul", "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 } ]
false
let synth_bv8_inverse : squash (synth_inverse synth_bv8 synth_bv8_recip) = synth_inverse_intro' synth_bv8 synth_bv8_recip (fun x -> of_uint8_to_uint8 x )
val synth_bv8_inverse:squash (synth_inverse synth_bv8 synth_bv8_recip) let synth_bv8_inverse:squash (synth_inverse synth_bv8 synth_bv8_recip) =
false
null
true
synth_inverse_intro' synth_bv8 synth_bv8_recip (fun x -> of_uint8_to_uint8 x)
{ "checked_file": "LowParse.Spec.BitVector.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Int.fsti.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.BoundedInt.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "LowParse.Spec.BitVector.fst" }
[ "total" ]
[ "LowParse.Spec.Combinators.synth_inverse_intro'", "FStar.UInt8.t", "FStar.BitVector.bv_t", "LowParse.Spec.BitVector.synth_bv8", "LowParse.Spec.BitVector.synth_bv8_recip", "LowParse.Spec.BitVector.of_uint8_to_uint8", "Prims.unit" ]
[]
module LowParse.Spec.BitVector open FStar.Mul module BV = FStar.BitVector module U8 = FStar.UInt8 module Seq = FStar.Seq (* Big-endian conversion of a bit vector to a UInt8 *) let rec to_uint8 (#n: nat { n <= 8 }) (x: BV.bv_t n) : Tot (y: U8.t { U8.v y < pow2 n }) = if n = 0 then 0uy else let hi = to_uint8 #(n - 1) (Seq.slice x 0 (n - 1)) in let hi' = hi `U8.mul` 2uy in let (r: U8.t { U8.v r < 2 }) = if Seq.index x (n - 1) then 1uy else 0uy in hi' `U8.add` r let rec of_uint8 (n: nat { n <= 8 }) (x: U8.t { U8.v x < pow2 n }) : Tot (BV.bv_t n) = if n = 0 then Seq.empty else let hi = of_uint8 (n - 1) (x `U8.div` 2uy) in Seq.snoc hi (x `U8.rem` 2uy = 1uy) #push-options "--z3rlimit 32" let rec to_uint8_of_uint8 (n: nat { n <= 8 }) (x: U8.t { U8.v x < pow2 n }) : Lemma (to_uint8 (of_uint8 n x) == x) = if n = 0 then () else begin assert (Seq.slice (of_uint8 n x) 0 (n - 1) `Seq.equal` of_uint8 (n - 1) (x `U8.div` 2uy)); to_uint8_of_uint8 (n - 1) (x `U8.div` 2uy) end let rec of_uint8_to_uint8 (#n: nat {n <= 8}) (x: BV.bv_t n) : Lemma (of_uint8 n (to_uint8 x) `Seq.equal` x) = if n = 0 then () else begin let x' = Seq.slice x 0 (n - 1) in of_uint8_to_uint8 #(n - 1) x' ; assert ( U8.v (to_uint8 #(n - 1) x') * 2 == U8.v (to_uint8 x) \/ U8.v (to_uint8 #(n - 1) x') * 2 + 1 == U8.v (to_uint8 x) ); assert (to_uint8 #(n - 1) x' == to_uint8 x `U8.div` 2uy); () end #pop-options (* parse a 8-bit vector *) open LowParse.Spec.Combinators open LowParse.Spec.Int let synth_bv8 (x: U8.t) : Tot (BV.bv_t 8) = of_uint8 8 x let synth_bv8_recip (x: BV.bv_t 8) : Tot U8.t = to_uint8 x let synth_bv8_injective : squash (synth_injective synth_bv8) = synth_inverse_intro' synth_bv8_recip synth_bv8 (fun x -> to_uint8_of_uint8 8 x )
false
false
LowParse.Spec.BitVector.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val synth_bv8_inverse:squash (synth_inverse synth_bv8 synth_bv8_recip)
[]
LowParse.Spec.BitVector.synth_bv8_inverse
{ "file_name": "src/lowparse/LowParse.Spec.BitVector.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
Prims.squash (LowParse.Spec.Combinators.synth_inverse LowParse.Spec.BitVector.synth_bv8 LowParse.Spec.BitVector.synth_bv8_recip)
{ "end_col": 3, "end_line": 85, "start_col": 2, "start_line": 83 }
Prims.Tot
val serialize_bv8:serializer parse_bv8
[ { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.BitVector", "short_module": "BV" }, { "abbrev": false, "full_module": "FStar.Mul", "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 } ]
false
let serialize_bv8 : serializer parse_bv8 = serialize_synth parse_u8 synth_bv8 serialize_u8 synth_bv8_recip ()
val serialize_bv8:serializer parse_bv8 let serialize_bv8:serializer parse_bv8 =
false
null
false
serialize_synth parse_u8 synth_bv8 serialize_u8 synth_bv8_recip ()
{ "checked_file": "LowParse.Spec.BitVector.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Int.fsti.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.BoundedInt.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "LowParse.Spec.BitVector.fst" }
[ "total" ]
[ "LowParse.Spec.Combinators.serialize_synth", "LowParse.Spec.Int.parse_u8_kind", "FStar.UInt8.t", "FStar.BitVector.bv_t", "LowParse.Spec.Int.parse_u8", "LowParse.Spec.BitVector.synth_bv8", "LowParse.Spec.Int.serialize_u8", "LowParse.Spec.BitVector.synth_bv8_recip" ]
[]
module LowParse.Spec.BitVector open FStar.Mul module BV = FStar.BitVector module U8 = FStar.UInt8 module Seq = FStar.Seq (* Big-endian conversion of a bit vector to a UInt8 *) let rec to_uint8 (#n: nat { n <= 8 }) (x: BV.bv_t n) : Tot (y: U8.t { U8.v y < pow2 n }) = if n = 0 then 0uy else let hi = to_uint8 #(n - 1) (Seq.slice x 0 (n - 1)) in let hi' = hi `U8.mul` 2uy in let (r: U8.t { U8.v r < 2 }) = if Seq.index x (n - 1) then 1uy else 0uy in hi' `U8.add` r let rec of_uint8 (n: nat { n <= 8 }) (x: U8.t { U8.v x < pow2 n }) : Tot (BV.bv_t n) = if n = 0 then Seq.empty else let hi = of_uint8 (n - 1) (x `U8.div` 2uy) in Seq.snoc hi (x `U8.rem` 2uy = 1uy) #push-options "--z3rlimit 32" let rec to_uint8_of_uint8 (n: nat { n <= 8 }) (x: U8.t { U8.v x < pow2 n }) : Lemma (to_uint8 (of_uint8 n x) == x) = if n = 0 then () else begin assert (Seq.slice (of_uint8 n x) 0 (n - 1) `Seq.equal` of_uint8 (n - 1) (x `U8.div` 2uy)); to_uint8_of_uint8 (n - 1) (x `U8.div` 2uy) end let rec of_uint8_to_uint8 (#n: nat {n <= 8}) (x: BV.bv_t n) : Lemma (of_uint8 n (to_uint8 x) `Seq.equal` x) = if n = 0 then () else begin let x' = Seq.slice x 0 (n - 1) in of_uint8_to_uint8 #(n - 1) x' ; assert ( U8.v (to_uint8 #(n - 1) x') * 2 == U8.v (to_uint8 x) \/ U8.v (to_uint8 #(n - 1) x') * 2 + 1 == U8.v (to_uint8 x) ); assert (to_uint8 #(n - 1) x' == to_uint8 x `U8.div` 2uy); () end #pop-options (* parse a 8-bit vector *) open LowParse.Spec.Combinators open LowParse.Spec.Int let synth_bv8 (x: U8.t) : Tot (BV.bv_t 8) = of_uint8 8 x let synth_bv8_recip (x: BV.bv_t 8) : Tot U8.t = to_uint8 x let synth_bv8_injective : squash (synth_injective synth_bv8) = synth_inverse_intro' synth_bv8_recip synth_bv8 (fun x -> to_uint8_of_uint8 8 x ) let synth_bv8_inverse : squash (synth_inverse synth_bv8 synth_bv8_recip) = synth_inverse_intro' synth_bv8 synth_bv8_recip (fun x -> of_uint8_to_uint8 x ) let parse_bv8_kind = parse_u8_kind let parse_bv8 : parser parse_bv8_kind (BV.bv_t 8) = parse_u8 `parse_synth` synth_bv8
false
false
LowParse.Spec.BitVector.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val serialize_bv8:serializer parse_bv8
[]
LowParse.Spec.BitVector.serialize_bv8
{ "file_name": "src/lowparse/LowParse.Spec.BitVector.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
LowParse.Spec.Base.serializer LowParse.Spec.BitVector.parse_bv8
{ "end_col": 6, "end_line": 98, "start_col": 2, "start_line": 93 }
Prims.Tot
val parse_bv8:parser parse_bv8_kind (BV.bv_t 8)
[ { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.BitVector", "short_module": "BV" }, { "abbrev": false, "full_module": "FStar.Mul", "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 } ]
false
let parse_bv8 : parser parse_bv8_kind (BV.bv_t 8) = parse_u8 `parse_synth` synth_bv8
val parse_bv8:parser parse_bv8_kind (BV.bv_t 8) let parse_bv8:parser parse_bv8_kind (BV.bv_t 8) =
false
null
false
parse_u8 `parse_synth` synth_bv8
{ "checked_file": "LowParse.Spec.BitVector.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Int.fsti.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.BoundedInt.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "LowParse.Spec.BitVector.fst" }
[ "total" ]
[ "LowParse.Spec.Combinators.parse_synth", "LowParse.Spec.Int.parse_u8_kind", "FStar.UInt8.t", "FStar.BitVector.bv_t", "LowParse.Spec.Int.parse_u8", "LowParse.Spec.BitVector.synth_bv8" ]
[]
module LowParse.Spec.BitVector open FStar.Mul module BV = FStar.BitVector module U8 = FStar.UInt8 module Seq = FStar.Seq (* Big-endian conversion of a bit vector to a UInt8 *) let rec to_uint8 (#n: nat { n <= 8 }) (x: BV.bv_t n) : Tot (y: U8.t { U8.v y < pow2 n }) = if n = 0 then 0uy else let hi = to_uint8 #(n - 1) (Seq.slice x 0 (n - 1)) in let hi' = hi `U8.mul` 2uy in let (r: U8.t { U8.v r < 2 }) = if Seq.index x (n - 1) then 1uy else 0uy in hi' `U8.add` r let rec of_uint8 (n: nat { n <= 8 }) (x: U8.t { U8.v x < pow2 n }) : Tot (BV.bv_t n) = if n = 0 then Seq.empty else let hi = of_uint8 (n - 1) (x `U8.div` 2uy) in Seq.snoc hi (x `U8.rem` 2uy = 1uy) #push-options "--z3rlimit 32" let rec to_uint8_of_uint8 (n: nat { n <= 8 }) (x: U8.t { U8.v x < pow2 n }) : Lemma (to_uint8 (of_uint8 n x) == x) = if n = 0 then () else begin assert (Seq.slice (of_uint8 n x) 0 (n - 1) `Seq.equal` of_uint8 (n - 1) (x `U8.div` 2uy)); to_uint8_of_uint8 (n - 1) (x `U8.div` 2uy) end let rec of_uint8_to_uint8 (#n: nat {n <= 8}) (x: BV.bv_t n) : Lemma (of_uint8 n (to_uint8 x) `Seq.equal` x) = if n = 0 then () else begin let x' = Seq.slice x 0 (n - 1) in of_uint8_to_uint8 #(n - 1) x' ; assert ( U8.v (to_uint8 #(n - 1) x') * 2 == U8.v (to_uint8 x) \/ U8.v (to_uint8 #(n - 1) x') * 2 + 1 == U8.v (to_uint8 x) ); assert (to_uint8 #(n - 1) x' == to_uint8 x `U8.div` 2uy); () end #pop-options (* parse a 8-bit vector *) open LowParse.Spec.Combinators open LowParse.Spec.Int let synth_bv8 (x: U8.t) : Tot (BV.bv_t 8) = of_uint8 8 x let synth_bv8_recip (x: BV.bv_t 8) : Tot U8.t = to_uint8 x let synth_bv8_injective : squash (synth_injective synth_bv8) = synth_inverse_intro' synth_bv8_recip synth_bv8 (fun x -> to_uint8_of_uint8 8 x ) let synth_bv8_inverse : squash (synth_inverse synth_bv8 synth_bv8_recip) = synth_inverse_intro' synth_bv8 synth_bv8_recip (fun x -> of_uint8_to_uint8 x ) let parse_bv8_kind = parse_u8_kind
false
false
LowParse.Spec.BitVector.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val parse_bv8:parser parse_bv8_kind (BV.bv_t 8)
[]
LowParse.Spec.BitVector.parse_bv8
{ "file_name": "src/lowparse/LowParse.Spec.BitVector.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
LowParse.Spec.Base.parser LowParse.Spec.BitVector.parse_bv8_kind (FStar.BitVector.bv_t 8)
{ "end_col": 34, "end_line": 90, "start_col": 2, "start_line": 90 }
Prims.Tot
val of_uint8 (n: nat{n <= 8}) (x: U8.t{U8.v x < pow2 n}) : Tot (BV.bv_t n)
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.BitVector", "short_module": "BV" }, { "abbrev": false, "full_module": "FStar.Mul", "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 } ]
false
let rec of_uint8 (n: nat { n <= 8 }) (x: U8.t { U8.v x < pow2 n }) : Tot (BV.bv_t n) = if n = 0 then Seq.empty else let hi = of_uint8 (n - 1) (x `U8.div` 2uy) in Seq.snoc hi (x `U8.rem` 2uy = 1uy)
val of_uint8 (n: nat{n <= 8}) (x: U8.t{U8.v x < pow2 n}) : Tot (BV.bv_t n) let rec of_uint8 (n: nat{n <= 8}) (x: U8.t{U8.v x < pow2 n}) : Tot (BV.bv_t n) =
false
null
false
if n = 0 then Seq.empty else let hi = of_uint8 (n - 1) (x `U8.div` 2uy) in Seq.snoc hi (x `U8.rem` 2uy = 1uy)
{ "checked_file": "LowParse.Spec.BitVector.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Int.fsti.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.BoundedInt.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "LowParse.Spec.BitVector.fst" }
[ "total" ]
[ "Prims.nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.UInt8.t", "Prims.op_LessThan", "FStar.UInt8.v", "Prims.pow2", "Prims.op_Equality", "Prims.int", "FStar.Seq.Base.empty", "Prims.bool", "FStar.Seq.Properties.snoc", "FStar.UInt8.rem", "FStar.UInt8.__uint_to_t", "FStar.BitVector.bv_t", "Prims.op_Subtraction", "LowParse.Spec.BitVector.of_uint8", "FStar.UInt8.div" ]
[]
module LowParse.Spec.BitVector open FStar.Mul module BV = FStar.BitVector module U8 = FStar.UInt8 module Seq = FStar.Seq (* Big-endian conversion of a bit vector to a UInt8 *) let rec to_uint8 (#n: nat { n <= 8 }) (x: BV.bv_t n) : Tot (y: U8.t { U8.v y < pow2 n }) = if n = 0 then 0uy else let hi = to_uint8 #(n - 1) (Seq.slice x 0 (n - 1)) in let hi' = hi `U8.mul` 2uy in let (r: U8.t { U8.v r < 2 }) = if Seq.index x (n - 1) then 1uy else 0uy in hi' `U8.add` r let rec of_uint8 (n: nat { n <= 8 }) (x: U8.t { U8.v x < pow2 n })
false
false
LowParse.Spec.BitVector.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val of_uint8 (n: nat{n <= 8}) (x: U8.t{U8.v x < pow2 n}) : Tot (BV.bv_t n)
[ "recursion" ]
LowParse.Spec.BitVector.of_uint8
{ "file_name": "src/lowparse/LowParse.Spec.BitVector.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
n: Prims.nat{n <= 8} -> x: FStar.UInt8.t{FStar.UInt8.v x < Prims.pow2 n} -> FStar.BitVector.bv_t n
{ "end_col": 38, "end_line": 30, "start_col": 2, "start_line": 26 }
Prims.Tot
val synth_bv8 (x: U8.t) : Tot (BV.bv_t 8)
[ { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.BitVector", "short_module": "BV" }, { "abbrev": false, "full_module": "FStar.Mul", "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 } ]
false
let synth_bv8 (x: U8.t) : Tot (BV.bv_t 8) = of_uint8 8 x
val synth_bv8 (x: U8.t) : Tot (BV.bv_t 8) let synth_bv8 (x: U8.t) : Tot (BV.bv_t 8) =
false
null
false
of_uint8 8 x
{ "checked_file": "LowParse.Spec.BitVector.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Int.fsti.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.BoundedInt.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "LowParse.Spec.BitVector.fst" }
[ "total" ]
[ "FStar.UInt8.t", "LowParse.Spec.BitVector.of_uint8", "FStar.BitVector.bv_t" ]
[]
module LowParse.Spec.BitVector open FStar.Mul module BV = FStar.BitVector module U8 = FStar.UInt8 module Seq = FStar.Seq (* Big-endian conversion of a bit vector to a UInt8 *) let rec to_uint8 (#n: nat { n <= 8 }) (x: BV.bv_t n) : Tot (y: U8.t { U8.v y < pow2 n }) = if n = 0 then 0uy else let hi = to_uint8 #(n - 1) (Seq.slice x 0 (n - 1)) in let hi' = hi `U8.mul` 2uy in let (r: U8.t { U8.v r < 2 }) = if Seq.index x (n - 1) then 1uy else 0uy in hi' `U8.add` r let rec of_uint8 (n: nat { n <= 8 }) (x: U8.t { U8.v x < pow2 n }) : Tot (BV.bv_t n) = if n = 0 then Seq.empty else let hi = of_uint8 (n - 1) (x `U8.div` 2uy) in Seq.snoc hi (x `U8.rem` 2uy = 1uy) #push-options "--z3rlimit 32" let rec to_uint8_of_uint8 (n: nat { n <= 8 }) (x: U8.t { U8.v x < pow2 n }) : Lemma (to_uint8 (of_uint8 n x) == x) = if n = 0 then () else begin assert (Seq.slice (of_uint8 n x) 0 (n - 1) `Seq.equal` of_uint8 (n - 1) (x `U8.div` 2uy)); to_uint8_of_uint8 (n - 1) (x `U8.div` 2uy) end let rec of_uint8_to_uint8 (#n: nat {n <= 8}) (x: BV.bv_t n) : Lemma (of_uint8 n (to_uint8 x) `Seq.equal` x) = if n = 0 then () else begin let x' = Seq.slice x 0 (n - 1) in of_uint8_to_uint8 #(n - 1) x' ; assert ( U8.v (to_uint8 #(n - 1) x') * 2 == U8.v (to_uint8 x) \/ U8.v (to_uint8 #(n - 1) x') * 2 + 1 == U8.v (to_uint8 x) ); assert (to_uint8 #(n - 1) x' == to_uint8 x `U8.div` 2uy); () end #pop-options (* parse a 8-bit vector *) open LowParse.Spec.Combinators open LowParse.Spec.Int
false
false
LowParse.Spec.BitVector.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val synth_bv8 (x: U8.t) : Tot (BV.bv_t 8)
[]
LowParse.Spec.BitVector.synth_bv8
{ "file_name": "src/lowparse/LowParse.Spec.BitVector.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
x: FStar.UInt8.t -> FStar.BitVector.bv_t 8
{ "end_col": 14, "end_line": 72, "start_col": 2, "start_line": 72 }
Prims.Tot
val synth_bv8_injective:squash (synth_injective synth_bv8)
[ { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.BitVector", "short_module": "BV" }, { "abbrev": false, "full_module": "FStar.Mul", "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 } ]
false
let synth_bv8_injective : squash (synth_injective synth_bv8) = synth_inverse_intro' synth_bv8_recip synth_bv8 (fun x -> to_uint8_of_uint8 8 x )
val synth_bv8_injective:squash (synth_injective synth_bv8) let synth_bv8_injective:squash (synth_injective synth_bv8) =
false
null
true
synth_inverse_intro' synth_bv8_recip synth_bv8 (fun x -> to_uint8_of_uint8 8 x)
{ "checked_file": "LowParse.Spec.BitVector.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Int.fsti.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.BoundedInt.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "LowParse.Spec.BitVector.fst" }
[ "total" ]
[ "LowParse.Spec.Combinators.synth_inverse_intro'", "FStar.BitVector.bv_t", "FStar.UInt8.t", "Prims.b2t", "Prims.op_LessThan", "FStar.UInt8.v", "Prims.pow2", "LowParse.Spec.BitVector.synth_bv8_recip", "LowParse.Spec.BitVector.synth_bv8", "LowParse.Spec.BitVector.to_uint8_of_uint8", "Prims.unit" ]
[]
module LowParse.Spec.BitVector open FStar.Mul module BV = FStar.BitVector module U8 = FStar.UInt8 module Seq = FStar.Seq (* Big-endian conversion of a bit vector to a UInt8 *) let rec to_uint8 (#n: nat { n <= 8 }) (x: BV.bv_t n) : Tot (y: U8.t { U8.v y < pow2 n }) = if n = 0 then 0uy else let hi = to_uint8 #(n - 1) (Seq.slice x 0 (n - 1)) in let hi' = hi `U8.mul` 2uy in let (r: U8.t { U8.v r < 2 }) = if Seq.index x (n - 1) then 1uy else 0uy in hi' `U8.add` r let rec of_uint8 (n: nat { n <= 8 }) (x: U8.t { U8.v x < pow2 n }) : Tot (BV.bv_t n) = if n = 0 then Seq.empty else let hi = of_uint8 (n - 1) (x `U8.div` 2uy) in Seq.snoc hi (x `U8.rem` 2uy = 1uy) #push-options "--z3rlimit 32" let rec to_uint8_of_uint8 (n: nat { n <= 8 }) (x: U8.t { U8.v x < pow2 n }) : Lemma (to_uint8 (of_uint8 n x) == x) = if n = 0 then () else begin assert (Seq.slice (of_uint8 n x) 0 (n - 1) `Seq.equal` of_uint8 (n - 1) (x `U8.div` 2uy)); to_uint8_of_uint8 (n - 1) (x `U8.div` 2uy) end let rec of_uint8_to_uint8 (#n: nat {n <= 8}) (x: BV.bv_t n) : Lemma (of_uint8 n (to_uint8 x) `Seq.equal` x) = if n = 0 then () else begin let x' = Seq.slice x 0 (n - 1) in of_uint8_to_uint8 #(n - 1) x' ; assert ( U8.v (to_uint8 #(n - 1) x') * 2 == U8.v (to_uint8 x) \/ U8.v (to_uint8 #(n - 1) x') * 2 + 1 == U8.v (to_uint8 x) ); assert (to_uint8 #(n - 1) x' == to_uint8 x `U8.div` 2uy); () end #pop-options (* parse a 8-bit vector *) open LowParse.Spec.Combinators open LowParse.Spec.Int let synth_bv8 (x: U8.t) : Tot (BV.bv_t 8) = of_uint8 8 x let synth_bv8_recip (x: BV.bv_t 8) : Tot U8.t = to_uint8 x
false
false
LowParse.Spec.BitVector.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val synth_bv8_injective:squash (synth_injective synth_bv8)
[]
LowParse.Spec.BitVector.synth_bv8_injective
{ "file_name": "src/lowparse/LowParse.Spec.BitVector.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
Prims.squash (LowParse.Spec.Combinators.synth_injective LowParse.Spec.BitVector.synth_bv8)
{ "end_col": 3, "end_line": 80, "start_col": 2, "start_line": 78 }
Prims.Tot
val parse_byte_bv_kind' (n: nat) : Tot parser_kind
[ { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.BitVector", "short_module": "BV" }, { "abbrev": false, "full_module": "FStar.Mul", "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 } ]
false
let rec parse_byte_bv_kind' (n: nat) : Tot parser_kind = if n = 0 then parse_ret_kind else parse_bv8_kind `and_then_kind` parse_byte_bv_kind' (n - 1)
val parse_byte_bv_kind' (n: nat) : Tot parser_kind let rec parse_byte_bv_kind' (n: nat) : Tot parser_kind =
false
null
false
if n = 0 then parse_ret_kind else parse_bv8_kind `and_then_kind` (parse_byte_bv_kind' (n - 1))
{ "checked_file": "LowParse.Spec.BitVector.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Int.fsti.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.BoundedInt.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "LowParse.Spec.BitVector.fst" }
[ "total" ]
[ "Prims.nat", "Prims.op_Equality", "Prims.int", "LowParse.Spec.Combinators.parse_ret_kind", "Prims.bool", "LowParse.Spec.Combinators.and_then_kind", "LowParse.Spec.BitVector.parse_bv8_kind", "LowParse.Spec.BitVector.parse_byte_bv_kind'", "Prims.op_Subtraction", "LowParse.Spec.Base.parser_kind" ]
[]
module LowParse.Spec.BitVector open FStar.Mul module BV = FStar.BitVector module U8 = FStar.UInt8 module Seq = FStar.Seq (* Big-endian conversion of a bit vector to a UInt8 *) let rec to_uint8 (#n: nat { n <= 8 }) (x: BV.bv_t n) : Tot (y: U8.t { U8.v y < pow2 n }) = if n = 0 then 0uy else let hi = to_uint8 #(n - 1) (Seq.slice x 0 (n - 1)) in let hi' = hi `U8.mul` 2uy in let (r: U8.t { U8.v r < 2 }) = if Seq.index x (n - 1) then 1uy else 0uy in hi' `U8.add` r let rec of_uint8 (n: nat { n <= 8 }) (x: U8.t { U8.v x < pow2 n }) : Tot (BV.bv_t n) = if n = 0 then Seq.empty else let hi = of_uint8 (n - 1) (x `U8.div` 2uy) in Seq.snoc hi (x `U8.rem` 2uy = 1uy) #push-options "--z3rlimit 32" let rec to_uint8_of_uint8 (n: nat { n <= 8 }) (x: U8.t { U8.v x < pow2 n }) : Lemma (to_uint8 (of_uint8 n x) == x) = if n = 0 then () else begin assert (Seq.slice (of_uint8 n x) 0 (n - 1) `Seq.equal` of_uint8 (n - 1) (x `U8.div` 2uy)); to_uint8_of_uint8 (n - 1) (x `U8.div` 2uy) end let rec of_uint8_to_uint8 (#n: nat {n <= 8}) (x: BV.bv_t n) : Lemma (of_uint8 n (to_uint8 x) `Seq.equal` x) = if n = 0 then () else begin let x' = Seq.slice x 0 (n - 1) in of_uint8_to_uint8 #(n - 1) x' ; assert ( U8.v (to_uint8 #(n - 1) x') * 2 == U8.v (to_uint8 x) \/ U8.v (to_uint8 #(n - 1) x') * 2 + 1 == U8.v (to_uint8 x) ); assert (to_uint8 #(n - 1) x' == to_uint8 x `U8.div` 2uy); () end #pop-options (* parse a 8-bit vector *) open LowParse.Spec.Combinators open LowParse.Spec.Int let synth_bv8 (x: U8.t) : Tot (BV.bv_t 8) = of_uint8 8 x let synth_bv8_recip (x: BV.bv_t 8) : Tot U8.t = to_uint8 x let synth_bv8_injective : squash (synth_injective synth_bv8) = synth_inverse_intro' synth_bv8_recip synth_bv8 (fun x -> to_uint8_of_uint8 8 x ) let synth_bv8_inverse : squash (synth_inverse synth_bv8 synth_bv8_recip) = synth_inverse_intro' synth_bv8 synth_bv8_recip (fun x -> of_uint8_to_uint8 x ) let parse_bv8_kind = parse_u8_kind let parse_bv8 : parser parse_bv8_kind (BV.bv_t 8) = parse_u8 `parse_synth` synth_bv8 let serialize_bv8 : serializer parse_bv8 = serialize_synth parse_u8 synth_bv8 serialize_u8 synth_bv8_recip () (* parse a 8*n bit vector *) let synth_byte_bv (n: nat) (x: (BV.bv_t 8 & BV.bv_t (8 * n))) : Tot (BV.bv_t (8 * (1 + n))) = Seq.append (fst x) (snd x) let synth_byte_bv_recip (n: nat) (x: BV.bv_t (8 * (1 + n))) : Tot (BV.bv_t 8 & BV.bv_t (8 * n)) = Seq.slice x 0 8, Seq.slice x 8 (Seq.length x) let synth_byte_bv_injective (n: nat) : Lemma (synth_injective (synth_byte_bv n)) [SMTPat (synth_injective (synth_byte_bv n))] = synth_inverse_intro' (synth_byte_bv_recip n) (synth_byte_bv n) (fun x -> let (hd, tl) = x in let (hd', tl') = synth_byte_bv_recip n (synth_byte_bv n x) in assert (hd `Seq.equal` hd'); assert (tl `Seq.equal` tl') ) let synth_byte_bv_inverse (n: nat) : Lemma (synth_inverse (synth_byte_bv n) (synth_byte_bv_recip n)) [SMTPat (synth_inverse (synth_byte_bv n) (synth_byte_bv_recip n))] = synth_inverse_intro' (synth_byte_bv n) (synth_byte_bv_recip n) (fun x -> assert (synth_byte_bv n (synth_byte_bv_recip n x) `Seq.equal` x) )
false
true
LowParse.Spec.BitVector.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val parse_byte_bv_kind' (n: nat) : Tot parser_kind
[ "recursion" ]
LowParse.Spec.BitVector.parse_byte_bv_kind'
{ "file_name": "src/lowparse/LowParse.Spec.BitVector.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
n: Prims.nat -> LowParse.Spec.Base.parser_kind
{ "end_col": 65, "end_line": 129, "start_col": 2, "start_line": 127 }
FStar.Pervasives.Lemma
val parse_byte_bv_kind_eq (n: nat) : Lemma (parse_byte_bv_kind n == parse_byte_bv_kind' n)
[ { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.BitVector", "short_module": "BV" }, { "abbrev": false, "full_module": "FStar.Mul", "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 } ]
false
let rec parse_byte_bv_kind_eq (n: nat) : Lemma (parse_byte_bv_kind n == parse_byte_bv_kind' n) = if n = 0 then () else parse_byte_bv_kind_eq (n - 1)
val parse_byte_bv_kind_eq (n: nat) : Lemma (parse_byte_bv_kind n == parse_byte_bv_kind' n) let rec parse_byte_bv_kind_eq (n: nat) : Lemma (parse_byte_bv_kind n == parse_byte_bv_kind' n) =
false
null
true
if n = 0 then () else parse_byte_bv_kind_eq (n - 1)
{ "checked_file": "LowParse.Spec.BitVector.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Int.fsti.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.BoundedInt.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "LowParse.Spec.BitVector.fst" }
[ "lemma" ]
[ "Prims.nat", "Prims.op_Equality", "Prims.int", "Prims.bool", "LowParse.Spec.BitVector.parse_byte_bv_kind_eq", "Prims.op_Subtraction", "Prims.unit", "Prims.l_True", "Prims.squash", "Prims.eq2", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.BitVector.parse_byte_bv_kind", "LowParse.Spec.BitVector.parse_byte_bv_kind'", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module LowParse.Spec.BitVector open FStar.Mul module BV = FStar.BitVector module U8 = FStar.UInt8 module Seq = FStar.Seq (* Big-endian conversion of a bit vector to a UInt8 *) let rec to_uint8 (#n: nat { n <= 8 }) (x: BV.bv_t n) : Tot (y: U8.t { U8.v y < pow2 n }) = if n = 0 then 0uy else let hi = to_uint8 #(n - 1) (Seq.slice x 0 (n - 1)) in let hi' = hi `U8.mul` 2uy in let (r: U8.t { U8.v r < 2 }) = if Seq.index x (n - 1) then 1uy else 0uy in hi' `U8.add` r let rec of_uint8 (n: nat { n <= 8 }) (x: U8.t { U8.v x < pow2 n }) : Tot (BV.bv_t n) = if n = 0 then Seq.empty else let hi = of_uint8 (n - 1) (x `U8.div` 2uy) in Seq.snoc hi (x `U8.rem` 2uy = 1uy) #push-options "--z3rlimit 32" let rec to_uint8_of_uint8 (n: nat { n <= 8 }) (x: U8.t { U8.v x < pow2 n }) : Lemma (to_uint8 (of_uint8 n x) == x) = if n = 0 then () else begin assert (Seq.slice (of_uint8 n x) 0 (n - 1) `Seq.equal` of_uint8 (n - 1) (x `U8.div` 2uy)); to_uint8_of_uint8 (n - 1) (x `U8.div` 2uy) end let rec of_uint8_to_uint8 (#n: nat {n <= 8}) (x: BV.bv_t n) : Lemma (of_uint8 n (to_uint8 x) `Seq.equal` x) = if n = 0 then () else begin let x' = Seq.slice x 0 (n - 1) in of_uint8_to_uint8 #(n - 1) x' ; assert ( U8.v (to_uint8 #(n - 1) x') * 2 == U8.v (to_uint8 x) \/ U8.v (to_uint8 #(n - 1) x') * 2 + 1 == U8.v (to_uint8 x) ); assert (to_uint8 #(n - 1) x' == to_uint8 x `U8.div` 2uy); () end #pop-options (* parse a 8-bit vector *) open LowParse.Spec.Combinators open LowParse.Spec.Int let synth_bv8 (x: U8.t) : Tot (BV.bv_t 8) = of_uint8 8 x let synth_bv8_recip (x: BV.bv_t 8) : Tot U8.t = to_uint8 x let synth_bv8_injective : squash (synth_injective synth_bv8) = synth_inverse_intro' synth_bv8_recip synth_bv8 (fun x -> to_uint8_of_uint8 8 x ) let synth_bv8_inverse : squash (synth_inverse synth_bv8 synth_bv8_recip) = synth_inverse_intro' synth_bv8 synth_bv8_recip (fun x -> of_uint8_to_uint8 x ) let parse_bv8_kind = parse_u8_kind let parse_bv8 : parser parse_bv8_kind (BV.bv_t 8) = parse_u8 `parse_synth` synth_bv8 let serialize_bv8 : serializer parse_bv8 = serialize_synth parse_u8 synth_bv8 serialize_u8 synth_bv8_recip () (* parse a 8*n bit vector *) let synth_byte_bv (n: nat) (x: (BV.bv_t 8 & BV.bv_t (8 * n))) : Tot (BV.bv_t (8 * (1 + n))) = Seq.append (fst x) (snd x) let synth_byte_bv_recip (n: nat) (x: BV.bv_t (8 * (1 + n))) : Tot (BV.bv_t 8 & BV.bv_t (8 * n)) = Seq.slice x 0 8, Seq.slice x 8 (Seq.length x) let synth_byte_bv_injective (n: nat) : Lemma (synth_injective (synth_byte_bv n)) [SMTPat (synth_injective (synth_byte_bv n))] = synth_inverse_intro' (synth_byte_bv_recip n) (synth_byte_bv n) (fun x -> let (hd, tl) = x in let (hd', tl') = synth_byte_bv_recip n (synth_byte_bv n x) in assert (hd `Seq.equal` hd'); assert (tl `Seq.equal` tl') ) let synth_byte_bv_inverse (n: nat) : Lemma (synth_inverse (synth_byte_bv n) (synth_byte_bv_recip n)) [SMTPat (synth_inverse (synth_byte_bv n) (synth_byte_bv_recip n))] = synth_inverse_intro' (synth_byte_bv n) (synth_byte_bv_recip n) (fun x -> assert (synth_byte_bv n (synth_byte_bv_recip n x) `Seq.equal` x) ) let rec parse_byte_bv_kind' (n: nat) : Tot parser_kind = if n = 0 then parse_ret_kind else parse_bv8_kind `and_then_kind` parse_byte_bv_kind' (n - 1) let parse_byte_bv_kind (n: nat) : Tot parser_kind = strong_parser_kind n n (Some ParserKindMetadataTotal) let rec parse_byte_bv_kind_eq (n: nat) : Lemma
false
false
LowParse.Spec.BitVector.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val parse_byte_bv_kind_eq (n: nat) : Lemma (parse_byte_bv_kind n == parse_byte_bv_kind' n)
[ "recursion" ]
LowParse.Spec.BitVector.parse_byte_bv_kind_eq
{ "file_name": "src/lowparse/LowParse.Spec.BitVector.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
n: Prims.nat -> FStar.Pervasives.Lemma (ensures LowParse.Spec.BitVector.parse_byte_bv_kind n == LowParse.Spec.BitVector.parse_byte_bv_kind' n)
{ "end_col": 36, "end_line": 138, "start_col": 2, "start_line": 136 }
Prims.Tot
val parse_bv_kind (n: nat) : Tot parser_kind
[ { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.BitVector", "short_module": "BV" }, { "abbrev": false, "full_module": "FStar.Mul", "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 } ]
false
let parse_bv_kind (n: nat) : Tot parser_kind = if n % 8 = 0 then strong_parser_kind (n / 8) (n / 8) (Some ParserKindMetadataTotal) else strong_parser_kind (1 + n / 8) (1 + n / 8) None
val parse_bv_kind (n: nat) : Tot parser_kind let parse_bv_kind (n: nat) : Tot parser_kind =
false
null
false
if n % 8 = 0 then strong_parser_kind (n / 8) (n / 8) (Some ParserKindMetadataTotal) else strong_parser_kind (1 + n / 8) (1 + n / 8) None
{ "checked_file": "LowParse.Spec.BitVector.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Int.fsti.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.BoundedInt.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "LowParse.Spec.BitVector.fst" }
[ "total" ]
[ "Prims.nat", "Prims.op_Equality", "Prims.int", "Prims.op_Modulus", "LowParse.Spec.Base.strong_parser_kind", "Prims.op_Division", "FStar.Pervasives.Native.Some", "LowParse.Spec.Base.parser_kind_metadata_some", "LowParse.Spec.Base.ParserKindMetadataTotal", "Prims.bool", "Prims.op_Addition", "FStar.Pervasives.Native.None", "LowParse.Spec.Base.parser_kind" ]
[]
module LowParse.Spec.BitVector open FStar.Mul module BV = FStar.BitVector module U8 = FStar.UInt8 module Seq = FStar.Seq (* Big-endian conversion of a bit vector to a UInt8 *) let rec to_uint8 (#n: nat { n <= 8 }) (x: BV.bv_t n) : Tot (y: U8.t { U8.v y < pow2 n }) = if n = 0 then 0uy else let hi = to_uint8 #(n - 1) (Seq.slice x 0 (n - 1)) in let hi' = hi `U8.mul` 2uy in let (r: U8.t { U8.v r < 2 }) = if Seq.index x (n - 1) then 1uy else 0uy in hi' `U8.add` r let rec of_uint8 (n: nat { n <= 8 }) (x: U8.t { U8.v x < pow2 n }) : Tot (BV.bv_t n) = if n = 0 then Seq.empty else let hi = of_uint8 (n - 1) (x `U8.div` 2uy) in Seq.snoc hi (x `U8.rem` 2uy = 1uy) #push-options "--z3rlimit 32" let rec to_uint8_of_uint8 (n: nat { n <= 8 }) (x: U8.t { U8.v x < pow2 n }) : Lemma (to_uint8 (of_uint8 n x) == x) = if n = 0 then () else begin assert (Seq.slice (of_uint8 n x) 0 (n - 1) `Seq.equal` of_uint8 (n - 1) (x `U8.div` 2uy)); to_uint8_of_uint8 (n - 1) (x `U8.div` 2uy) end let rec of_uint8_to_uint8 (#n: nat {n <= 8}) (x: BV.bv_t n) : Lemma (of_uint8 n (to_uint8 x) `Seq.equal` x) = if n = 0 then () else begin let x' = Seq.slice x 0 (n - 1) in of_uint8_to_uint8 #(n - 1) x' ; assert ( U8.v (to_uint8 #(n - 1) x') * 2 == U8.v (to_uint8 x) \/ U8.v (to_uint8 #(n - 1) x') * 2 + 1 == U8.v (to_uint8 x) ); assert (to_uint8 #(n - 1) x' == to_uint8 x `U8.div` 2uy); () end #pop-options (* parse a 8-bit vector *) open LowParse.Spec.Combinators open LowParse.Spec.Int let synth_bv8 (x: U8.t) : Tot (BV.bv_t 8) = of_uint8 8 x let synth_bv8_recip (x: BV.bv_t 8) : Tot U8.t = to_uint8 x let synth_bv8_injective : squash (synth_injective synth_bv8) = synth_inverse_intro' synth_bv8_recip synth_bv8 (fun x -> to_uint8_of_uint8 8 x ) let synth_bv8_inverse : squash (synth_inverse synth_bv8 synth_bv8_recip) = synth_inverse_intro' synth_bv8 synth_bv8_recip (fun x -> of_uint8_to_uint8 x ) let parse_bv8_kind = parse_u8_kind let parse_bv8 : parser parse_bv8_kind (BV.bv_t 8) = parse_u8 `parse_synth` synth_bv8 let serialize_bv8 : serializer parse_bv8 = serialize_synth parse_u8 synth_bv8 serialize_u8 synth_bv8_recip () (* parse a 8*n bit vector *) let synth_byte_bv (n: nat) (x: (BV.bv_t 8 & BV.bv_t (8 * n))) : Tot (BV.bv_t (8 * (1 + n))) = Seq.append (fst x) (snd x) let synth_byte_bv_recip (n: nat) (x: BV.bv_t (8 * (1 + n))) : Tot (BV.bv_t 8 & BV.bv_t (8 * n)) = Seq.slice x 0 8, Seq.slice x 8 (Seq.length x) let synth_byte_bv_injective (n: nat) : Lemma (synth_injective (synth_byte_bv n)) [SMTPat (synth_injective (synth_byte_bv n))] = synth_inverse_intro' (synth_byte_bv_recip n) (synth_byte_bv n) (fun x -> let (hd, tl) = x in let (hd', tl') = synth_byte_bv_recip n (synth_byte_bv n x) in assert (hd `Seq.equal` hd'); assert (tl `Seq.equal` tl') ) let synth_byte_bv_inverse (n: nat) : Lemma (synth_inverse (synth_byte_bv n) (synth_byte_bv_recip n)) [SMTPat (synth_inverse (synth_byte_bv n) (synth_byte_bv_recip n))] = synth_inverse_intro' (synth_byte_bv n) (synth_byte_bv_recip n) (fun x -> assert (synth_byte_bv n (synth_byte_bv_recip n x) `Seq.equal` x) ) let rec parse_byte_bv_kind' (n: nat) : Tot parser_kind = if n = 0 then parse_ret_kind else parse_bv8_kind `and_then_kind` parse_byte_bv_kind' (n - 1) let parse_byte_bv_kind (n: nat) : Tot parser_kind = strong_parser_kind n n (Some ParserKindMetadataTotal) let rec parse_byte_bv_kind_eq (n: nat) : Lemma (parse_byte_bv_kind n == parse_byte_bv_kind' n) = if n = 0 then () else parse_byte_bv_kind_eq (n - 1) let rec parse_byte_bv (n: nat) : Tot (parser (parse_byte_bv_kind n) (BV.bv_t (8 * n))) = parse_byte_bv_kind_eq n; if n = 0 then parse_ret Seq.empty else (parse_bv8 `nondep_then` parse_byte_bv (n - 1)) `parse_synth` synth_byte_bv (n - 1) let rec serialize_byte_bv (n: nat) : Tot (serializer (parse_byte_bv n)) = parse_byte_bv_kind_eq n; if n = 0 then serialize_ret Seq.empty (fun (x: BV.bv_t 0) -> assert (x `Seq.equal` Seq.empty)) else serialize_synth (parse_bv8 `nondep_then` parse_byte_bv (n - 1)) (synth_byte_bv (n - 1)) (serialize_bv8 `serialize_nondep_then` serialize_byte_bv (n - 1)) (synth_byte_bv_recip (n - 1)) () (* parse extra bits (big-endian with the first bits equal to 0) *) let extra_bytes_prop (n: nat) (x: U8.t) : Tot bool = U8.v x < pow2 (n % 8) let synth_extra_bv8 (n: nat) (x: parse_filter_refine (extra_bytes_prop n)) : Tot (BV.bv_t (n % 8)) = of_uint8 (n % 8) x let synth_extra_bv8_recip (n: nat) (x: BV.bv_t (n % 8)) : Tot (parse_filter_refine (extra_bytes_prop n)) = to_uint8 x let synth_extra_bv8_injective (n: nat) : Lemma (synth_injective (synth_extra_bv8 n)) [SMTPat (synth_injective (synth_extra_bv8 n))] = synth_inverse_intro' (synth_extra_bv8_recip n) (synth_extra_bv8 n) (fun x -> to_uint8_of_uint8 (n % 8) x ) let synth_extra_bv8_inverse (n: nat) : Lemma (synth_inverse (synth_extra_bv8 n) (synth_extra_bv8_recip n)) [SMTPat (synth_inverse (synth_extra_bv8 n) (synth_extra_bv8_recip n))] = synth_inverse_intro' (synth_extra_bv8 n) (synth_extra_bv8_recip n) (fun x -> of_uint8_to_uint8 x ) let parse_extra_bv8_kind (n: nat) : Tot parser_kind = parse_filter_kind parse_u8_kind let parse_extra_bv8 (n: nat) : Tot (parser (parse_extra_bv8_kind n) (BV.bv_t (n % 8))) = (parse_u8 `parse_filter` extra_bytes_prop n) `parse_synth` synth_extra_bv8 n let serialize_extra_bv8 (n: nat) : Tot (serializer (parse_extra_bv8 n)) = serialize_synth _ (synth_extra_bv8 n) (serialize_filter serialize_u8 (extra_bytes_prop n)) (synth_extra_bv8_recip n) () (* parse a bitvector, general *) let synth_bv (n: nat) (x: (BV.bv_t (n % 8) & BV.bv_t (8 * (n / 8)))) : Tot (BV.bv_t n) = Seq.append (fst x) (snd x) let synth_bv_recip (n: nat) (x: BV.bv_t n) : Tot (BV.bv_t (n % 8) & BV.bv_t (8 * (n / 8))) = Seq.slice x 0 (n % 8), Seq.slice x (n % 8) (Seq.length x) let synth_bv_injective (n: nat) : Lemma (synth_injective (synth_bv n)) [SMTPat (synth_injective (synth_bv n))] = synth_inverse_intro' (synth_bv_recip n) (synth_bv n) (fun x -> let (hd, tl) = x in let (hd', tl') = synth_bv_recip n (synth_bv n x) in assert (hd `Seq.equal` hd'); assert (tl `Seq.equal` tl') ) let synth_bv_inverse (n: nat) : Lemma (synth_inverse (synth_bv n) (synth_bv_recip n)) [SMTPat (synth_inverse (synth_bv n) (synth_bv_recip n))] = synth_inverse_intro' (synth_bv n) (synth_bv_recip n) (fun x -> assert (synth_bv n (synth_bv_recip n x) `Seq.equal` x) )
false
true
LowParse.Spec.BitVector.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val parse_bv_kind (n: nat) : Tot parser_kind
[]
LowParse.Spec.BitVector.parse_bv_kind
{ "file_name": "src/lowparse/LowParse.Spec.BitVector.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
n: Prims.nat -> LowParse.Spec.Base.parser_kind
{ "end_col": 54, "end_line": 228, "start_col": 2, "start_line": 226 }
Prims.Tot
val parse_bounded_bv_payload_kind (min: nat) (max: nat{min <= max}) : Tot parser_kind
[ { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.BitVector", "short_module": "BV" }, { "abbrev": false, "full_module": "FStar.Mul", "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 } ]
false
let parse_bounded_bv_payload_kind (min: nat) (max: nat { min <= max }) : Tot parser_kind = strong_parser_kind (if min % 8 = 0 then min / 8 else 1 + min / 8) (if max % 8 = 0 then max / 8 else 1 + max / 8) None
val parse_bounded_bv_payload_kind (min: nat) (max: nat{min <= max}) : Tot parser_kind let parse_bounded_bv_payload_kind (min: nat) (max: nat{min <= max}) : Tot parser_kind =
false
null
false
strong_parser_kind (if min % 8 = 0 then min / 8 else 1 + min / 8) (if max % 8 = 0 then max / 8 else 1 + max / 8) None
{ "checked_file": "LowParse.Spec.BitVector.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Int.fsti.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.BoundedInt.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "LowParse.Spec.BitVector.fst" }
[ "total" ]
[ "Prims.nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "LowParse.Spec.Base.strong_parser_kind", "Prims.op_Equality", "Prims.int", "Prims.op_Modulus", "Prims.op_Division", "Prims.bool", "Prims.op_Addition", "FStar.Pervasives.Native.None", "LowParse.Spec.Base.parser_kind_metadata_some", "LowParse.Spec.Base.parser_kind" ]
[]
module LowParse.Spec.BitVector open FStar.Mul module BV = FStar.BitVector module U8 = FStar.UInt8 module Seq = FStar.Seq (* Big-endian conversion of a bit vector to a UInt8 *) let rec to_uint8 (#n: nat { n <= 8 }) (x: BV.bv_t n) : Tot (y: U8.t { U8.v y < pow2 n }) = if n = 0 then 0uy else let hi = to_uint8 #(n - 1) (Seq.slice x 0 (n - 1)) in let hi' = hi `U8.mul` 2uy in let (r: U8.t { U8.v r < 2 }) = if Seq.index x (n - 1) then 1uy else 0uy in hi' `U8.add` r let rec of_uint8 (n: nat { n <= 8 }) (x: U8.t { U8.v x < pow2 n }) : Tot (BV.bv_t n) = if n = 0 then Seq.empty else let hi = of_uint8 (n - 1) (x `U8.div` 2uy) in Seq.snoc hi (x `U8.rem` 2uy = 1uy) #push-options "--z3rlimit 32" let rec to_uint8_of_uint8 (n: nat { n <= 8 }) (x: U8.t { U8.v x < pow2 n }) : Lemma (to_uint8 (of_uint8 n x) == x) = if n = 0 then () else begin assert (Seq.slice (of_uint8 n x) 0 (n - 1) `Seq.equal` of_uint8 (n - 1) (x `U8.div` 2uy)); to_uint8_of_uint8 (n - 1) (x `U8.div` 2uy) end let rec of_uint8_to_uint8 (#n: nat {n <= 8}) (x: BV.bv_t n) : Lemma (of_uint8 n (to_uint8 x) `Seq.equal` x) = if n = 0 then () else begin let x' = Seq.slice x 0 (n - 1) in of_uint8_to_uint8 #(n - 1) x' ; assert ( U8.v (to_uint8 #(n - 1) x') * 2 == U8.v (to_uint8 x) \/ U8.v (to_uint8 #(n - 1) x') * 2 + 1 == U8.v (to_uint8 x) ); assert (to_uint8 #(n - 1) x' == to_uint8 x `U8.div` 2uy); () end #pop-options (* parse a 8-bit vector *) open LowParse.Spec.Combinators open LowParse.Spec.Int let synth_bv8 (x: U8.t) : Tot (BV.bv_t 8) = of_uint8 8 x let synth_bv8_recip (x: BV.bv_t 8) : Tot U8.t = to_uint8 x let synth_bv8_injective : squash (synth_injective synth_bv8) = synth_inverse_intro' synth_bv8_recip synth_bv8 (fun x -> to_uint8_of_uint8 8 x ) let synth_bv8_inverse : squash (synth_inverse synth_bv8 synth_bv8_recip) = synth_inverse_intro' synth_bv8 synth_bv8_recip (fun x -> of_uint8_to_uint8 x ) let parse_bv8_kind = parse_u8_kind let parse_bv8 : parser parse_bv8_kind (BV.bv_t 8) = parse_u8 `parse_synth` synth_bv8 let serialize_bv8 : serializer parse_bv8 = serialize_synth parse_u8 synth_bv8 serialize_u8 synth_bv8_recip () (* parse a 8*n bit vector *) let synth_byte_bv (n: nat) (x: (BV.bv_t 8 & BV.bv_t (8 * n))) : Tot (BV.bv_t (8 * (1 + n))) = Seq.append (fst x) (snd x) let synth_byte_bv_recip (n: nat) (x: BV.bv_t (8 * (1 + n))) : Tot (BV.bv_t 8 & BV.bv_t (8 * n)) = Seq.slice x 0 8, Seq.slice x 8 (Seq.length x) let synth_byte_bv_injective (n: nat) : Lemma (synth_injective (synth_byte_bv n)) [SMTPat (synth_injective (synth_byte_bv n))] = synth_inverse_intro' (synth_byte_bv_recip n) (synth_byte_bv n) (fun x -> let (hd, tl) = x in let (hd', tl') = synth_byte_bv_recip n (synth_byte_bv n x) in assert (hd `Seq.equal` hd'); assert (tl `Seq.equal` tl') ) let synth_byte_bv_inverse (n: nat) : Lemma (synth_inverse (synth_byte_bv n) (synth_byte_bv_recip n)) [SMTPat (synth_inverse (synth_byte_bv n) (synth_byte_bv_recip n))] = synth_inverse_intro' (synth_byte_bv n) (synth_byte_bv_recip n) (fun x -> assert (synth_byte_bv n (synth_byte_bv_recip n x) `Seq.equal` x) ) let rec parse_byte_bv_kind' (n: nat) : Tot parser_kind = if n = 0 then parse_ret_kind else parse_bv8_kind `and_then_kind` parse_byte_bv_kind' (n - 1) let parse_byte_bv_kind (n: nat) : Tot parser_kind = strong_parser_kind n n (Some ParserKindMetadataTotal) let rec parse_byte_bv_kind_eq (n: nat) : Lemma (parse_byte_bv_kind n == parse_byte_bv_kind' n) = if n = 0 then () else parse_byte_bv_kind_eq (n - 1) let rec parse_byte_bv (n: nat) : Tot (parser (parse_byte_bv_kind n) (BV.bv_t (8 * n))) = parse_byte_bv_kind_eq n; if n = 0 then parse_ret Seq.empty else (parse_bv8 `nondep_then` parse_byte_bv (n - 1)) `parse_synth` synth_byte_bv (n - 1) let rec serialize_byte_bv (n: nat) : Tot (serializer (parse_byte_bv n)) = parse_byte_bv_kind_eq n; if n = 0 then serialize_ret Seq.empty (fun (x: BV.bv_t 0) -> assert (x `Seq.equal` Seq.empty)) else serialize_synth (parse_bv8 `nondep_then` parse_byte_bv (n - 1)) (synth_byte_bv (n - 1)) (serialize_bv8 `serialize_nondep_then` serialize_byte_bv (n - 1)) (synth_byte_bv_recip (n - 1)) () (* parse extra bits (big-endian with the first bits equal to 0) *) let extra_bytes_prop (n: nat) (x: U8.t) : Tot bool = U8.v x < pow2 (n % 8) let synth_extra_bv8 (n: nat) (x: parse_filter_refine (extra_bytes_prop n)) : Tot (BV.bv_t (n % 8)) = of_uint8 (n % 8) x let synth_extra_bv8_recip (n: nat) (x: BV.bv_t (n % 8)) : Tot (parse_filter_refine (extra_bytes_prop n)) = to_uint8 x let synth_extra_bv8_injective (n: nat) : Lemma (synth_injective (synth_extra_bv8 n)) [SMTPat (synth_injective (synth_extra_bv8 n))] = synth_inverse_intro' (synth_extra_bv8_recip n) (synth_extra_bv8 n) (fun x -> to_uint8_of_uint8 (n % 8) x ) let synth_extra_bv8_inverse (n: nat) : Lemma (synth_inverse (synth_extra_bv8 n) (synth_extra_bv8_recip n)) [SMTPat (synth_inverse (synth_extra_bv8 n) (synth_extra_bv8_recip n))] = synth_inverse_intro' (synth_extra_bv8 n) (synth_extra_bv8_recip n) (fun x -> of_uint8_to_uint8 x ) let parse_extra_bv8_kind (n: nat) : Tot parser_kind = parse_filter_kind parse_u8_kind let parse_extra_bv8 (n: nat) : Tot (parser (parse_extra_bv8_kind n) (BV.bv_t (n % 8))) = (parse_u8 `parse_filter` extra_bytes_prop n) `parse_synth` synth_extra_bv8 n let serialize_extra_bv8 (n: nat) : Tot (serializer (parse_extra_bv8 n)) = serialize_synth _ (synth_extra_bv8 n) (serialize_filter serialize_u8 (extra_bytes_prop n)) (synth_extra_bv8_recip n) () (* parse a bitvector, general *) let synth_bv (n: nat) (x: (BV.bv_t (n % 8) & BV.bv_t (8 * (n / 8)))) : Tot (BV.bv_t n) = Seq.append (fst x) (snd x) let synth_bv_recip (n: nat) (x: BV.bv_t n) : Tot (BV.bv_t (n % 8) & BV.bv_t (8 * (n / 8))) = Seq.slice x 0 (n % 8), Seq.slice x (n % 8) (Seq.length x) let synth_bv_injective (n: nat) : Lemma (synth_injective (synth_bv n)) [SMTPat (synth_injective (synth_bv n))] = synth_inverse_intro' (synth_bv_recip n) (synth_bv n) (fun x -> let (hd, tl) = x in let (hd', tl') = synth_bv_recip n (synth_bv n x) in assert (hd `Seq.equal` hd'); assert (tl `Seq.equal` tl') ) let synth_bv_inverse (n: nat) : Lemma (synth_inverse (synth_bv n) (synth_bv_recip n)) [SMTPat (synth_inverse (synth_bv n) (synth_bv_recip n))] = synth_inverse_intro' (synth_bv n) (synth_bv_recip n) (fun x -> assert (synth_bv n (synth_bv_recip n x) `Seq.equal` x) ) let parse_bv_kind (n: nat) : Tot parser_kind = if n % 8 = 0 then strong_parser_kind (n / 8) (n / 8) (Some ParserKindMetadataTotal) else strong_parser_kind (1 + n / 8) (1 + n / 8) None let parse_bv (n: nat) : Tot (parser (parse_bv_kind n) (BV.bv_t n)) = if n % 8 = 0 then parse_byte_bv (n / 8) else ((parse_extra_bv8 n `nondep_then` parse_byte_bv (n / 8)) `parse_synth` synth_bv n) let serialize_bv (n: nat) : Tot (serializer (parse_bv n)) = if n % 8 = 0 then serialize_byte_bv (n / 8) else serialize_synth _ (synth_bv n) (serialize_extra_bv8 n `serialize_nondep_then` serialize_byte_bv (n / 8)) (synth_bv_recip n) () (* parse a bounded bit vector *) module U32 = FStar.UInt32 open LowParse.Spec.BoundedInt inline_for_extraction let bounded_bv_t (min: nat) (max: nat { min <= max }) : Tot Type = (bitsize: bounded_int32 min max & BV.bv_t (U32.v bitsize)) let parse_bounded_bv_payload_kind (min: nat) (max: nat { min <= max })
false
false
LowParse.Spec.BitVector.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val parse_bounded_bv_payload_kind (min: nat) (max: nat{min <= max}) : Tot parser_kind
[]
LowParse.Spec.BitVector.parse_bounded_bv_payload_kind
{ "file_name": "src/lowparse/LowParse.Spec.BitVector.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
min: Prims.nat -> max: Prims.nat{min <= max} -> LowParse.Spec.Base.parser_kind
{ "end_col": 8, "end_line": 264, "start_col": 2, "start_line": 261 }
Prims.Tot
val parse_bounded_bv (min: nat) (max: nat{min <= max}) (#hk: parser_kind) (hp: parser hk (bounded_int32 min max)) : Tot (parser (parse_bounded_bv_kind min max hk) (bounded_bv_t min max))
[ { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.BitVector", "short_module": "BV" }, { "abbrev": false, "full_module": "FStar.Mul", "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 } ]
false
let parse_bounded_bv (min: nat) (max: nat { min <= max }) (#hk: parser_kind) (hp: parser hk (bounded_int32 min max)) : Tot (parser (parse_bounded_bv_kind min max hk) (bounded_bv_t min max)) = parse_dtuple2 hp (fun (sz: bounded_int32 min max) -> weaken (parse_bounded_bv_payload_kind min max) (parse_bv (U32.v sz)))
val parse_bounded_bv (min: nat) (max: nat{min <= max}) (#hk: parser_kind) (hp: parser hk (bounded_int32 min max)) : Tot (parser (parse_bounded_bv_kind min max hk) (bounded_bv_t min max)) let parse_bounded_bv (min: nat) (max: nat{min <= max}) (#hk: parser_kind) (hp: parser hk (bounded_int32 min max)) : Tot (parser (parse_bounded_bv_kind min max hk) (bounded_bv_t min max)) =
false
null
false
parse_dtuple2 hp (fun (sz: bounded_int32 min max) -> weaken (parse_bounded_bv_payload_kind min max) (parse_bv (U32.v sz)))
{ "checked_file": "LowParse.Spec.BitVector.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Int.fsti.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.BoundedInt.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "LowParse.Spec.BitVector.fst" }
[ "total" ]
[ "Prims.nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Spec.BoundedInt.bounded_int32", "LowParse.Spec.Combinators.parse_dtuple2", "LowParse.Spec.BitVector.parse_bounded_bv_payload_kind", "FStar.BitVector.bv_t", "FStar.UInt32.v", "LowParse.Spec.Base.weaken", "LowParse.Spec.BitVector.parse_bv_kind", "LowParse.Spec.BitVector.parse_bv", "LowParse.Spec.BitVector.parse_bounded_bv_kind", "LowParse.Spec.BitVector.bounded_bv_t" ]
[]
module LowParse.Spec.BitVector open FStar.Mul module BV = FStar.BitVector module U8 = FStar.UInt8 module Seq = FStar.Seq (* Big-endian conversion of a bit vector to a UInt8 *) let rec to_uint8 (#n: nat { n <= 8 }) (x: BV.bv_t n) : Tot (y: U8.t { U8.v y < pow2 n }) = if n = 0 then 0uy else let hi = to_uint8 #(n - 1) (Seq.slice x 0 (n - 1)) in let hi' = hi `U8.mul` 2uy in let (r: U8.t { U8.v r < 2 }) = if Seq.index x (n - 1) then 1uy else 0uy in hi' `U8.add` r let rec of_uint8 (n: nat { n <= 8 }) (x: U8.t { U8.v x < pow2 n }) : Tot (BV.bv_t n) = if n = 0 then Seq.empty else let hi = of_uint8 (n - 1) (x `U8.div` 2uy) in Seq.snoc hi (x `U8.rem` 2uy = 1uy) #push-options "--z3rlimit 32" let rec to_uint8_of_uint8 (n: nat { n <= 8 }) (x: U8.t { U8.v x < pow2 n }) : Lemma (to_uint8 (of_uint8 n x) == x) = if n = 0 then () else begin assert (Seq.slice (of_uint8 n x) 0 (n - 1) `Seq.equal` of_uint8 (n - 1) (x `U8.div` 2uy)); to_uint8_of_uint8 (n - 1) (x `U8.div` 2uy) end let rec of_uint8_to_uint8 (#n: nat {n <= 8}) (x: BV.bv_t n) : Lemma (of_uint8 n (to_uint8 x) `Seq.equal` x) = if n = 0 then () else begin let x' = Seq.slice x 0 (n - 1) in of_uint8_to_uint8 #(n - 1) x' ; assert ( U8.v (to_uint8 #(n - 1) x') * 2 == U8.v (to_uint8 x) \/ U8.v (to_uint8 #(n - 1) x') * 2 + 1 == U8.v (to_uint8 x) ); assert (to_uint8 #(n - 1) x' == to_uint8 x `U8.div` 2uy); () end #pop-options (* parse a 8-bit vector *) open LowParse.Spec.Combinators open LowParse.Spec.Int let synth_bv8 (x: U8.t) : Tot (BV.bv_t 8) = of_uint8 8 x let synth_bv8_recip (x: BV.bv_t 8) : Tot U8.t = to_uint8 x let synth_bv8_injective : squash (synth_injective synth_bv8) = synth_inverse_intro' synth_bv8_recip synth_bv8 (fun x -> to_uint8_of_uint8 8 x ) let synth_bv8_inverse : squash (synth_inverse synth_bv8 synth_bv8_recip) = synth_inverse_intro' synth_bv8 synth_bv8_recip (fun x -> of_uint8_to_uint8 x ) let parse_bv8_kind = parse_u8_kind let parse_bv8 : parser parse_bv8_kind (BV.bv_t 8) = parse_u8 `parse_synth` synth_bv8 let serialize_bv8 : serializer parse_bv8 = serialize_synth parse_u8 synth_bv8 serialize_u8 synth_bv8_recip () (* parse a 8*n bit vector *) let synth_byte_bv (n: nat) (x: (BV.bv_t 8 & BV.bv_t (8 * n))) : Tot (BV.bv_t (8 * (1 + n))) = Seq.append (fst x) (snd x) let synth_byte_bv_recip (n: nat) (x: BV.bv_t (8 * (1 + n))) : Tot (BV.bv_t 8 & BV.bv_t (8 * n)) = Seq.slice x 0 8, Seq.slice x 8 (Seq.length x) let synth_byte_bv_injective (n: nat) : Lemma (synth_injective (synth_byte_bv n)) [SMTPat (synth_injective (synth_byte_bv n))] = synth_inverse_intro' (synth_byte_bv_recip n) (synth_byte_bv n) (fun x -> let (hd, tl) = x in let (hd', tl') = synth_byte_bv_recip n (synth_byte_bv n x) in assert (hd `Seq.equal` hd'); assert (tl `Seq.equal` tl') ) let synth_byte_bv_inverse (n: nat) : Lemma (synth_inverse (synth_byte_bv n) (synth_byte_bv_recip n)) [SMTPat (synth_inverse (synth_byte_bv n) (synth_byte_bv_recip n))] = synth_inverse_intro' (synth_byte_bv n) (synth_byte_bv_recip n) (fun x -> assert (synth_byte_bv n (synth_byte_bv_recip n x) `Seq.equal` x) ) let rec parse_byte_bv_kind' (n: nat) : Tot parser_kind = if n = 0 then parse_ret_kind else parse_bv8_kind `and_then_kind` parse_byte_bv_kind' (n - 1) let parse_byte_bv_kind (n: nat) : Tot parser_kind = strong_parser_kind n n (Some ParserKindMetadataTotal) let rec parse_byte_bv_kind_eq (n: nat) : Lemma (parse_byte_bv_kind n == parse_byte_bv_kind' n) = if n = 0 then () else parse_byte_bv_kind_eq (n - 1) let rec parse_byte_bv (n: nat) : Tot (parser (parse_byte_bv_kind n) (BV.bv_t (8 * n))) = parse_byte_bv_kind_eq n; if n = 0 then parse_ret Seq.empty else (parse_bv8 `nondep_then` parse_byte_bv (n - 1)) `parse_synth` synth_byte_bv (n - 1) let rec serialize_byte_bv (n: nat) : Tot (serializer (parse_byte_bv n)) = parse_byte_bv_kind_eq n; if n = 0 then serialize_ret Seq.empty (fun (x: BV.bv_t 0) -> assert (x `Seq.equal` Seq.empty)) else serialize_synth (parse_bv8 `nondep_then` parse_byte_bv (n - 1)) (synth_byte_bv (n - 1)) (serialize_bv8 `serialize_nondep_then` serialize_byte_bv (n - 1)) (synth_byte_bv_recip (n - 1)) () (* parse extra bits (big-endian with the first bits equal to 0) *) let extra_bytes_prop (n: nat) (x: U8.t) : Tot bool = U8.v x < pow2 (n % 8) let synth_extra_bv8 (n: nat) (x: parse_filter_refine (extra_bytes_prop n)) : Tot (BV.bv_t (n % 8)) = of_uint8 (n % 8) x let synth_extra_bv8_recip (n: nat) (x: BV.bv_t (n % 8)) : Tot (parse_filter_refine (extra_bytes_prop n)) = to_uint8 x let synth_extra_bv8_injective (n: nat) : Lemma (synth_injective (synth_extra_bv8 n)) [SMTPat (synth_injective (synth_extra_bv8 n))] = synth_inverse_intro' (synth_extra_bv8_recip n) (synth_extra_bv8 n) (fun x -> to_uint8_of_uint8 (n % 8) x ) let synth_extra_bv8_inverse (n: nat) : Lemma (synth_inverse (synth_extra_bv8 n) (synth_extra_bv8_recip n)) [SMTPat (synth_inverse (synth_extra_bv8 n) (synth_extra_bv8_recip n))] = synth_inverse_intro' (synth_extra_bv8 n) (synth_extra_bv8_recip n) (fun x -> of_uint8_to_uint8 x ) let parse_extra_bv8_kind (n: nat) : Tot parser_kind = parse_filter_kind parse_u8_kind let parse_extra_bv8 (n: nat) : Tot (parser (parse_extra_bv8_kind n) (BV.bv_t (n % 8))) = (parse_u8 `parse_filter` extra_bytes_prop n) `parse_synth` synth_extra_bv8 n let serialize_extra_bv8 (n: nat) : Tot (serializer (parse_extra_bv8 n)) = serialize_synth _ (synth_extra_bv8 n) (serialize_filter serialize_u8 (extra_bytes_prop n)) (synth_extra_bv8_recip n) () (* parse a bitvector, general *) let synth_bv (n: nat) (x: (BV.bv_t (n % 8) & BV.bv_t (8 * (n / 8)))) : Tot (BV.bv_t n) = Seq.append (fst x) (snd x) let synth_bv_recip (n: nat) (x: BV.bv_t n) : Tot (BV.bv_t (n % 8) & BV.bv_t (8 * (n / 8))) = Seq.slice x 0 (n % 8), Seq.slice x (n % 8) (Seq.length x) let synth_bv_injective (n: nat) : Lemma (synth_injective (synth_bv n)) [SMTPat (synth_injective (synth_bv n))] = synth_inverse_intro' (synth_bv_recip n) (synth_bv n) (fun x -> let (hd, tl) = x in let (hd', tl') = synth_bv_recip n (synth_bv n x) in assert (hd `Seq.equal` hd'); assert (tl `Seq.equal` tl') ) let synth_bv_inverse (n: nat) : Lemma (synth_inverse (synth_bv n) (synth_bv_recip n)) [SMTPat (synth_inverse (synth_bv n) (synth_bv_recip n))] = synth_inverse_intro' (synth_bv n) (synth_bv_recip n) (fun x -> assert (synth_bv n (synth_bv_recip n x) `Seq.equal` x) ) let parse_bv_kind (n: nat) : Tot parser_kind = if n % 8 = 0 then strong_parser_kind (n / 8) (n / 8) (Some ParserKindMetadataTotal) else strong_parser_kind (1 + n / 8) (1 + n / 8) None let parse_bv (n: nat) : Tot (parser (parse_bv_kind n) (BV.bv_t n)) = if n % 8 = 0 then parse_byte_bv (n / 8) else ((parse_extra_bv8 n `nondep_then` parse_byte_bv (n / 8)) `parse_synth` synth_bv n) let serialize_bv (n: nat) : Tot (serializer (parse_bv n)) = if n % 8 = 0 then serialize_byte_bv (n / 8) else serialize_synth _ (synth_bv n) (serialize_extra_bv8 n `serialize_nondep_then` serialize_byte_bv (n / 8)) (synth_bv_recip n) () (* parse a bounded bit vector *) module U32 = FStar.UInt32 open LowParse.Spec.BoundedInt inline_for_extraction let bounded_bv_t (min: nat) (max: nat { min <= max }) : Tot Type = (bitsize: bounded_int32 min max & BV.bv_t (U32.v bitsize)) let parse_bounded_bv_payload_kind (min: nat) (max: nat { min <= max }) : Tot parser_kind = strong_parser_kind (if min % 8 = 0 then min / 8 else 1 + min / 8) (if max % 8 = 0 then max / 8 else 1 + max / 8) None let parse_bounded_bv_payload_kind_is_weaker_than_parse_bv_kind (min: nat) (max: nat) (n: nat) : Lemma (requires (min <= n /\ n <= max)) (ensures ( min <= n /\ n <= max /\ parse_bounded_bv_payload_kind min max `is_weaker_than` parse_bv_kind n )) [SMTPat (parse_bounded_bv_payload_kind min max `is_weaker_than` parse_bv_kind n)] = () let parse_bounded_bv_kind (min: nat) (max: nat { min <= max }) (hk: parser_kind) : Tot parser_kind = hk `and_then_kind` parse_bounded_bv_payload_kind min max let parse_bounded_bv (min: nat) (max: nat { min <= max }) (#hk: parser_kind) (hp: parser hk (bounded_int32 min max))
false
false
LowParse.Spec.BitVector.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val parse_bounded_bv (min: nat) (max: nat{min <= max}) (#hk: parser_kind) (hp: parser hk (bounded_int32 min max)) : Tot (parser (parse_bounded_bv_kind min max hk) (bounded_bv_t min max))
[]
LowParse.Spec.BitVector.parse_bounded_bv
{ "file_name": "src/lowparse/LowParse.Spec.BitVector.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
min: Prims.nat -> max: Prims.nat{min <= max} -> hp: LowParse.Spec.Base.parser hk (LowParse.Spec.BoundedInt.bounded_int32 min max) -> LowParse.Spec.Base.parser (LowParse.Spec.BitVector.parse_bounded_bv_kind min max hk) (LowParse.Spec.BitVector.bounded_bv_t min max)
{ "end_col": 109, "end_line": 295, "start_col": 2, "start_line": 293 }
FStar.Pervasives.Lemma
val synth_extra_bv8_injective (n: nat) : Lemma (synth_injective (synth_extra_bv8 n)) [SMTPat (synth_injective (synth_extra_bv8 n))]
[ { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.BitVector", "short_module": "BV" }, { "abbrev": false, "full_module": "FStar.Mul", "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 } ]
false
let synth_extra_bv8_injective (n: nat) : Lemma (synth_injective (synth_extra_bv8 n)) [SMTPat (synth_injective (synth_extra_bv8 n))] = synth_inverse_intro' (synth_extra_bv8_recip n) (synth_extra_bv8 n) (fun x -> to_uint8_of_uint8 (n % 8) x )
val synth_extra_bv8_injective (n: nat) : Lemma (synth_injective (synth_extra_bv8 n)) [SMTPat (synth_injective (synth_extra_bv8 n))] let synth_extra_bv8_injective (n: nat) : Lemma (synth_injective (synth_extra_bv8 n)) [SMTPat (synth_injective (synth_extra_bv8 n))] =
false
null
true
synth_inverse_intro' (synth_extra_bv8_recip n) (synth_extra_bv8 n) (fun x -> to_uint8_of_uint8 (n % 8) x)
{ "checked_file": "LowParse.Spec.BitVector.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Int.fsti.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.BoundedInt.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "LowParse.Spec.BitVector.fst" }
[ "lemma" ]
[ "Prims.nat", "LowParse.Spec.Combinators.synth_inverse_intro'", "FStar.BitVector.bv_t", "Prims.op_Modulus", "FStar.UInt8.t", "Prims.b2t", "Prims.op_LessThan", "FStar.UInt8.v", "Prims.pow2", "LowParse.Spec.BitVector.synth_extra_bv8_recip", "LowParse.Spec.BitVector.synth_extra_bv8", "LowParse.Spec.BitVector.to_uint8_of_uint8", "Prims.unit", "Prims.l_True", "Prims.squash", "LowParse.Spec.Combinators.synth_injective", "LowParse.Spec.Combinators.parse_filter_refine", "LowParse.Spec.BitVector.extra_bytes_prop", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat", "Prims.Nil" ]
[]
module LowParse.Spec.BitVector open FStar.Mul module BV = FStar.BitVector module U8 = FStar.UInt8 module Seq = FStar.Seq (* Big-endian conversion of a bit vector to a UInt8 *) let rec to_uint8 (#n: nat { n <= 8 }) (x: BV.bv_t n) : Tot (y: U8.t { U8.v y < pow2 n }) = if n = 0 then 0uy else let hi = to_uint8 #(n - 1) (Seq.slice x 0 (n - 1)) in let hi' = hi `U8.mul` 2uy in let (r: U8.t { U8.v r < 2 }) = if Seq.index x (n - 1) then 1uy else 0uy in hi' `U8.add` r let rec of_uint8 (n: nat { n <= 8 }) (x: U8.t { U8.v x < pow2 n }) : Tot (BV.bv_t n) = if n = 0 then Seq.empty else let hi = of_uint8 (n - 1) (x `U8.div` 2uy) in Seq.snoc hi (x `U8.rem` 2uy = 1uy) #push-options "--z3rlimit 32" let rec to_uint8_of_uint8 (n: nat { n <= 8 }) (x: U8.t { U8.v x < pow2 n }) : Lemma (to_uint8 (of_uint8 n x) == x) = if n = 0 then () else begin assert (Seq.slice (of_uint8 n x) 0 (n - 1) `Seq.equal` of_uint8 (n - 1) (x `U8.div` 2uy)); to_uint8_of_uint8 (n - 1) (x `U8.div` 2uy) end let rec of_uint8_to_uint8 (#n: nat {n <= 8}) (x: BV.bv_t n) : Lemma (of_uint8 n (to_uint8 x) `Seq.equal` x) = if n = 0 then () else begin let x' = Seq.slice x 0 (n - 1) in of_uint8_to_uint8 #(n - 1) x' ; assert ( U8.v (to_uint8 #(n - 1) x') * 2 == U8.v (to_uint8 x) \/ U8.v (to_uint8 #(n - 1) x') * 2 + 1 == U8.v (to_uint8 x) ); assert (to_uint8 #(n - 1) x' == to_uint8 x `U8.div` 2uy); () end #pop-options (* parse a 8-bit vector *) open LowParse.Spec.Combinators open LowParse.Spec.Int let synth_bv8 (x: U8.t) : Tot (BV.bv_t 8) = of_uint8 8 x let synth_bv8_recip (x: BV.bv_t 8) : Tot U8.t = to_uint8 x let synth_bv8_injective : squash (synth_injective synth_bv8) = synth_inverse_intro' synth_bv8_recip synth_bv8 (fun x -> to_uint8_of_uint8 8 x ) let synth_bv8_inverse : squash (synth_inverse synth_bv8 synth_bv8_recip) = synth_inverse_intro' synth_bv8 synth_bv8_recip (fun x -> of_uint8_to_uint8 x ) let parse_bv8_kind = parse_u8_kind let parse_bv8 : parser parse_bv8_kind (BV.bv_t 8) = parse_u8 `parse_synth` synth_bv8 let serialize_bv8 : serializer parse_bv8 = serialize_synth parse_u8 synth_bv8 serialize_u8 synth_bv8_recip () (* parse a 8*n bit vector *) let synth_byte_bv (n: nat) (x: (BV.bv_t 8 & BV.bv_t (8 * n))) : Tot (BV.bv_t (8 * (1 + n))) = Seq.append (fst x) (snd x) let synth_byte_bv_recip (n: nat) (x: BV.bv_t (8 * (1 + n))) : Tot (BV.bv_t 8 & BV.bv_t (8 * n)) = Seq.slice x 0 8, Seq.slice x 8 (Seq.length x) let synth_byte_bv_injective (n: nat) : Lemma (synth_injective (synth_byte_bv n)) [SMTPat (synth_injective (synth_byte_bv n))] = synth_inverse_intro' (synth_byte_bv_recip n) (synth_byte_bv n) (fun x -> let (hd, tl) = x in let (hd', tl') = synth_byte_bv_recip n (synth_byte_bv n x) in assert (hd `Seq.equal` hd'); assert (tl `Seq.equal` tl') ) let synth_byte_bv_inverse (n: nat) : Lemma (synth_inverse (synth_byte_bv n) (synth_byte_bv_recip n)) [SMTPat (synth_inverse (synth_byte_bv n) (synth_byte_bv_recip n))] = synth_inverse_intro' (synth_byte_bv n) (synth_byte_bv_recip n) (fun x -> assert (synth_byte_bv n (synth_byte_bv_recip n x) `Seq.equal` x) ) let rec parse_byte_bv_kind' (n: nat) : Tot parser_kind = if n = 0 then parse_ret_kind else parse_bv8_kind `and_then_kind` parse_byte_bv_kind' (n - 1) let parse_byte_bv_kind (n: nat) : Tot parser_kind = strong_parser_kind n n (Some ParserKindMetadataTotal) let rec parse_byte_bv_kind_eq (n: nat) : Lemma (parse_byte_bv_kind n == parse_byte_bv_kind' n) = if n = 0 then () else parse_byte_bv_kind_eq (n - 1) let rec parse_byte_bv (n: nat) : Tot (parser (parse_byte_bv_kind n) (BV.bv_t (8 * n))) = parse_byte_bv_kind_eq n; if n = 0 then parse_ret Seq.empty else (parse_bv8 `nondep_then` parse_byte_bv (n - 1)) `parse_synth` synth_byte_bv (n - 1) let rec serialize_byte_bv (n: nat) : Tot (serializer (parse_byte_bv n)) = parse_byte_bv_kind_eq n; if n = 0 then serialize_ret Seq.empty (fun (x: BV.bv_t 0) -> assert (x `Seq.equal` Seq.empty)) else serialize_synth (parse_bv8 `nondep_then` parse_byte_bv (n - 1)) (synth_byte_bv (n - 1)) (serialize_bv8 `serialize_nondep_then` serialize_byte_bv (n - 1)) (synth_byte_bv_recip (n - 1)) () (* parse extra bits (big-endian with the first bits equal to 0) *) let extra_bytes_prop (n: nat) (x: U8.t) : Tot bool = U8.v x < pow2 (n % 8) let synth_extra_bv8 (n: nat) (x: parse_filter_refine (extra_bytes_prop n)) : Tot (BV.bv_t (n % 8)) = of_uint8 (n % 8) x let synth_extra_bv8_recip (n: nat) (x: BV.bv_t (n % 8)) : Tot (parse_filter_refine (extra_bytes_prop n)) = to_uint8 x let synth_extra_bv8_injective (n: nat) : Lemma (synth_injective (synth_extra_bv8 n)) [SMTPat (synth_injective (synth_extra_bv8 n))]
false
false
LowParse.Spec.BitVector.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val synth_extra_bv8_injective (n: nat) : Lemma (synth_injective (synth_extra_bv8 n)) [SMTPat (synth_injective (synth_extra_bv8 n))]
[]
LowParse.Spec.BitVector.synth_extra_bv8_injective
{ "file_name": "src/lowparse/LowParse.Spec.BitVector.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
n: Prims.nat -> FStar.Pervasives.Lemma (ensures LowParse.Spec.Combinators.synth_injective (LowParse.Spec.BitVector.synth_extra_bv8 n) ) [ SMTPat (LowParse.Spec.Combinators.synth_injective (LowParse.Spec.BitVector.synth_extra_bv8 n )) ]
{ "end_col": 3, "end_line": 177, "start_col": 2, "start_line": 175 }
Prims.Tot
val serialize_extra_bv8 (n: nat) : Tot (serializer (parse_extra_bv8 n))
[ { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.BitVector", "short_module": "BV" }, { "abbrev": false, "full_module": "FStar.Mul", "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 } ]
false
let serialize_extra_bv8 (n: nat) : Tot (serializer (parse_extra_bv8 n)) = serialize_synth _ (synth_extra_bv8 n) (serialize_filter serialize_u8 (extra_bytes_prop n)) (synth_extra_bv8_recip n) ()
val serialize_extra_bv8 (n: nat) : Tot (serializer (parse_extra_bv8 n)) let serialize_extra_bv8 (n: nat) : Tot (serializer (parse_extra_bv8 n)) =
false
null
false
serialize_synth _ (synth_extra_bv8 n) (serialize_filter serialize_u8 (extra_bytes_prop n)) (synth_extra_bv8_recip n) ()
{ "checked_file": "LowParse.Spec.BitVector.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Int.fsti.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.BoundedInt.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "LowParse.Spec.BitVector.fst" }
[ "total" ]
[ "Prims.nat", "LowParse.Spec.Combinators.serialize_synth", "LowParse.Spec.Combinators.parse_filter_kind", "LowParse.Spec.Int.parse_u8_kind", "LowParse.Spec.Combinators.parse_filter_refine", "FStar.UInt8.t", "LowParse.Spec.BitVector.extra_bytes_prop", "FStar.BitVector.bv_t", "Prims.op_Modulus", "LowParse.Spec.Combinators.parse_filter", "LowParse.Spec.Int.parse_u8", "LowParse.Spec.BitVector.synth_extra_bv8", "LowParse.Spec.Combinators.serialize_filter", "LowParse.Spec.Int.serialize_u8", "LowParse.Spec.BitVector.synth_extra_bv8_recip", "LowParse.Spec.Base.serializer", "LowParse.Spec.BitVector.parse_extra_bv8_kind", "LowParse.Spec.BitVector.parse_extra_bv8" ]
[]
module LowParse.Spec.BitVector open FStar.Mul module BV = FStar.BitVector module U8 = FStar.UInt8 module Seq = FStar.Seq (* Big-endian conversion of a bit vector to a UInt8 *) let rec to_uint8 (#n: nat { n <= 8 }) (x: BV.bv_t n) : Tot (y: U8.t { U8.v y < pow2 n }) = if n = 0 then 0uy else let hi = to_uint8 #(n - 1) (Seq.slice x 0 (n - 1)) in let hi' = hi `U8.mul` 2uy in let (r: U8.t { U8.v r < 2 }) = if Seq.index x (n - 1) then 1uy else 0uy in hi' `U8.add` r let rec of_uint8 (n: nat { n <= 8 }) (x: U8.t { U8.v x < pow2 n }) : Tot (BV.bv_t n) = if n = 0 then Seq.empty else let hi = of_uint8 (n - 1) (x `U8.div` 2uy) in Seq.snoc hi (x `U8.rem` 2uy = 1uy) #push-options "--z3rlimit 32" let rec to_uint8_of_uint8 (n: nat { n <= 8 }) (x: U8.t { U8.v x < pow2 n }) : Lemma (to_uint8 (of_uint8 n x) == x) = if n = 0 then () else begin assert (Seq.slice (of_uint8 n x) 0 (n - 1) `Seq.equal` of_uint8 (n - 1) (x `U8.div` 2uy)); to_uint8_of_uint8 (n - 1) (x `U8.div` 2uy) end let rec of_uint8_to_uint8 (#n: nat {n <= 8}) (x: BV.bv_t n) : Lemma (of_uint8 n (to_uint8 x) `Seq.equal` x) = if n = 0 then () else begin let x' = Seq.slice x 0 (n - 1) in of_uint8_to_uint8 #(n - 1) x' ; assert ( U8.v (to_uint8 #(n - 1) x') * 2 == U8.v (to_uint8 x) \/ U8.v (to_uint8 #(n - 1) x') * 2 + 1 == U8.v (to_uint8 x) ); assert (to_uint8 #(n - 1) x' == to_uint8 x `U8.div` 2uy); () end #pop-options (* parse a 8-bit vector *) open LowParse.Spec.Combinators open LowParse.Spec.Int let synth_bv8 (x: U8.t) : Tot (BV.bv_t 8) = of_uint8 8 x let synth_bv8_recip (x: BV.bv_t 8) : Tot U8.t = to_uint8 x let synth_bv8_injective : squash (synth_injective synth_bv8) = synth_inverse_intro' synth_bv8_recip synth_bv8 (fun x -> to_uint8_of_uint8 8 x ) let synth_bv8_inverse : squash (synth_inverse synth_bv8 synth_bv8_recip) = synth_inverse_intro' synth_bv8 synth_bv8_recip (fun x -> of_uint8_to_uint8 x ) let parse_bv8_kind = parse_u8_kind let parse_bv8 : parser parse_bv8_kind (BV.bv_t 8) = parse_u8 `parse_synth` synth_bv8 let serialize_bv8 : serializer parse_bv8 = serialize_synth parse_u8 synth_bv8 serialize_u8 synth_bv8_recip () (* parse a 8*n bit vector *) let synth_byte_bv (n: nat) (x: (BV.bv_t 8 & BV.bv_t (8 * n))) : Tot (BV.bv_t (8 * (1 + n))) = Seq.append (fst x) (snd x) let synth_byte_bv_recip (n: nat) (x: BV.bv_t (8 * (1 + n))) : Tot (BV.bv_t 8 & BV.bv_t (8 * n)) = Seq.slice x 0 8, Seq.slice x 8 (Seq.length x) let synth_byte_bv_injective (n: nat) : Lemma (synth_injective (synth_byte_bv n)) [SMTPat (synth_injective (synth_byte_bv n))] = synth_inverse_intro' (synth_byte_bv_recip n) (synth_byte_bv n) (fun x -> let (hd, tl) = x in let (hd', tl') = synth_byte_bv_recip n (synth_byte_bv n x) in assert (hd `Seq.equal` hd'); assert (tl `Seq.equal` tl') ) let synth_byte_bv_inverse (n: nat) : Lemma (synth_inverse (synth_byte_bv n) (synth_byte_bv_recip n)) [SMTPat (synth_inverse (synth_byte_bv n) (synth_byte_bv_recip n))] = synth_inverse_intro' (synth_byte_bv n) (synth_byte_bv_recip n) (fun x -> assert (synth_byte_bv n (synth_byte_bv_recip n x) `Seq.equal` x) ) let rec parse_byte_bv_kind' (n: nat) : Tot parser_kind = if n = 0 then parse_ret_kind else parse_bv8_kind `and_then_kind` parse_byte_bv_kind' (n - 1) let parse_byte_bv_kind (n: nat) : Tot parser_kind = strong_parser_kind n n (Some ParserKindMetadataTotal) let rec parse_byte_bv_kind_eq (n: nat) : Lemma (parse_byte_bv_kind n == parse_byte_bv_kind' n) = if n = 0 then () else parse_byte_bv_kind_eq (n - 1) let rec parse_byte_bv (n: nat) : Tot (parser (parse_byte_bv_kind n) (BV.bv_t (8 * n))) = parse_byte_bv_kind_eq n; if n = 0 then parse_ret Seq.empty else (parse_bv8 `nondep_then` parse_byte_bv (n - 1)) `parse_synth` synth_byte_bv (n - 1) let rec serialize_byte_bv (n: nat) : Tot (serializer (parse_byte_bv n)) = parse_byte_bv_kind_eq n; if n = 0 then serialize_ret Seq.empty (fun (x: BV.bv_t 0) -> assert (x `Seq.equal` Seq.empty)) else serialize_synth (parse_bv8 `nondep_then` parse_byte_bv (n - 1)) (synth_byte_bv (n - 1)) (serialize_bv8 `serialize_nondep_then` serialize_byte_bv (n - 1)) (synth_byte_bv_recip (n - 1)) () (* parse extra bits (big-endian with the first bits equal to 0) *) let extra_bytes_prop (n: nat) (x: U8.t) : Tot bool = U8.v x < pow2 (n % 8) let synth_extra_bv8 (n: nat) (x: parse_filter_refine (extra_bytes_prop n)) : Tot (BV.bv_t (n % 8)) = of_uint8 (n % 8) x let synth_extra_bv8_recip (n: nat) (x: BV.bv_t (n % 8)) : Tot (parse_filter_refine (extra_bytes_prop n)) = to_uint8 x let synth_extra_bv8_injective (n: nat) : Lemma (synth_injective (synth_extra_bv8 n)) [SMTPat (synth_injective (synth_extra_bv8 n))] = synth_inverse_intro' (synth_extra_bv8_recip n) (synth_extra_bv8 n) (fun x -> to_uint8_of_uint8 (n % 8) x ) let synth_extra_bv8_inverse (n: nat) : Lemma (synth_inverse (synth_extra_bv8 n) (synth_extra_bv8_recip n)) [SMTPat (synth_inverse (synth_extra_bv8 n) (synth_extra_bv8_recip n))] = synth_inverse_intro' (synth_extra_bv8 n) (synth_extra_bv8_recip n) (fun x -> of_uint8_to_uint8 x ) let parse_extra_bv8_kind (n: nat) : Tot parser_kind = parse_filter_kind parse_u8_kind let parse_extra_bv8 (n: nat) : Tot (parser (parse_extra_bv8_kind n) (BV.bv_t (n % 8))) = (parse_u8 `parse_filter` extra_bytes_prop n) `parse_synth` synth_extra_bv8 n
false
false
LowParse.Spec.BitVector.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val serialize_extra_bv8 (n: nat) : Tot (serializer (parse_extra_bv8 n))
[]
LowParse.Spec.BitVector.serialize_extra_bv8
{ "file_name": "src/lowparse/LowParse.Spec.BitVector.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
n: Prims.nat -> LowParse.Spec.Base.serializer (LowParse.Spec.BitVector.parse_extra_bv8 n)
{ "end_col": 6, "end_line": 198, "start_col": 2, "start_line": 193 }
Prims.Tot
val synth_extra_bv8 (n: nat) (x: parse_filter_refine (extra_bytes_prop n)) : Tot (BV.bv_t (n % 8))
[ { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.BitVector", "short_module": "BV" }, { "abbrev": false, "full_module": "FStar.Mul", "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 } ]
false
let synth_extra_bv8 (n: nat) (x: parse_filter_refine (extra_bytes_prop n)) : Tot (BV.bv_t (n % 8)) = of_uint8 (n % 8) x
val synth_extra_bv8 (n: nat) (x: parse_filter_refine (extra_bytes_prop n)) : Tot (BV.bv_t (n % 8)) let synth_extra_bv8 (n: nat) (x: parse_filter_refine (extra_bytes_prop n)) : Tot (BV.bv_t (n % 8)) =
false
null
false
of_uint8 (n % 8) x
{ "checked_file": "LowParse.Spec.BitVector.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Int.fsti.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.BoundedInt.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "LowParse.Spec.BitVector.fst" }
[ "total" ]
[ "Prims.nat", "LowParse.Spec.Combinators.parse_filter_refine", "FStar.UInt8.t", "LowParse.Spec.BitVector.extra_bytes_prop", "LowParse.Spec.BitVector.of_uint8", "Prims.op_Modulus", "FStar.BitVector.bv_t" ]
[]
module LowParse.Spec.BitVector open FStar.Mul module BV = FStar.BitVector module U8 = FStar.UInt8 module Seq = FStar.Seq (* Big-endian conversion of a bit vector to a UInt8 *) let rec to_uint8 (#n: nat { n <= 8 }) (x: BV.bv_t n) : Tot (y: U8.t { U8.v y < pow2 n }) = if n = 0 then 0uy else let hi = to_uint8 #(n - 1) (Seq.slice x 0 (n - 1)) in let hi' = hi `U8.mul` 2uy in let (r: U8.t { U8.v r < 2 }) = if Seq.index x (n - 1) then 1uy else 0uy in hi' `U8.add` r let rec of_uint8 (n: nat { n <= 8 }) (x: U8.t { U8.v x < pow2 n }) : Tot (BV.bv_t n) = if n = 0 then Seq.empty else let hi = of_uint8 (n - 1) (x `U8.div` 2uy) in Seq.snoc hi (x `U8.rem` 2uy = 1uy) #push-options "--z3rlimit 32" let rec to_uint8_of_uint8 (n: nat { n <= 8 }) (x: U8.t { U8.v x < pow2 n }) : Lemma (to_uint8 (of_uint8 n x) == x) = if n = 0 then () else begin assert (Seq.slice (of_uint8 n x) 0 (n - 1) `Seq.equal` of_uint8 (n - 1) (x `U8.div` 2uy)); to_uint8_of_uint8 (n - 1) (x `U8.div` 2uy) end let rec of_uint8_to_uint8 (#n: nat {n <= 8}) (x: BV.bv_t n) : Lemma (of_uint8 n (to_uint8 x) `Seq.equal` x) = if n = 0 then () else begin let x' = Seq.slice x 0 (n - 1) in of_uint8_to_uint8 #(n - 1) x' ; assert ( U8.v (to_uint8 #(n - 1) x') * 2 == U8.v (to_uint8 x) \/ U8.v (to_uint8 #(n - 1) x') * 2 + 1 == U8.v (to_uint8 x) ); assert (to_uint8 #(n - 1) x' == to_uint8 x `U8.div` 2uy); () end #pop-options (* parse a 8-bit vector *) open LowParse.Spec.Combinators open LowParse.Spec.Int let synth_bv8 (x: U8.t) : Tot (BV.bv_t 8) = of_uint8 8 x let synth_bv8_recip (x: BV.bv_t 8) : Tot U8.t = to_uint8 x let synth_bv8_injective : squash (synth_injective synth_bv8) = synth_inverse_intro' synth_bv8_recip synth_bv8 (fun x -> to_uint8_of_uint8 8 x ) let synth_bv8_inverse : squash (synth_inverse synth_bv8 synth_bv8_recip) = synth_inverse_intro' synth_bv8 synth_bv8_recip (fun x -> of_uint8_to_uint8 x ) let parse_bv8_kind = parse_u8_kind let parse_bv8 : parser parse_bv8_kind (BV.bv_t 8) = parse_u8 `parse_synth` synth_bv8 let serialize_bv8 : serializer parse_bv8 = serialize_synth parse_u8 synth_bv8 serialize_u8 synth_bv8_recip () (* parse a 8*n bit vector *) let synth_byte_bv (n: nat) (x: (BV.bv_t 8 & BV.bv_t (8 * n))) : Tot (BV.bv_t (8 * (1 + n))) = Seq.append (fst x) (snd x) let synth_byte_bv_recip (n: nat) (x: BV.bv_t (8 * (1 + n))) : Tot (BV.bv_t 8 & BV.bv_t (8 * n)) = Seq.slice x 0 8, Seq.slice x 8 (Seq.length x) let synth_byte_bv_injective (n: nat) : Lemma (synth_injective (synth_byte_bv n)) [SMTPat (synth_injective (synth_byte_bv n))] = synth_inverse_intro' (synth_byte_bv_recip n) (synth_byte_bv n) (fun x -> let (hd, tl) = x in let (hd', tl') = synth_byte_bv_recip n (synth_byte_bv n x) in assert (hd `Seq.equal` hd'); assert (tl `Seq.equal` tl') ) let synth_byte_bv_inverse (n: nat) : Lemma (synth_inverse (synth_byte_bv n) (synth_byte_bv_recip n)) [SMTPat (synth_inverse (synth_byte_bv n) (synth_byte_bv_recip n))] = synth_inverse_intro' (synth_byte_bv n) (synth_byte_bv_recip n) (fun x -> assert (synth_byte_bv n (synth_byte_bv_recip n x) `Seq.equal` x) ) let rec parse_byte_bv_kind' (n: nat) : Tot parser_kind = if n = 0 then parse_ret_kind else parse_bv8_kind `and_then_kind` parse_byte_bv_kind' (n - 1) let parse_byte_bv_kind (n: nat) : Tot parser_kind = strong_parser_kind n n (Some ParserKindMetadataTotal) let rec parse_byte_bv_kind_eq (n: nat) : Lemma (parse_byte_bv_kind n == parse_byte_bv_kind' n) = if n = 0 then () else parse_byte_bv_kind_eq (n - 1) let rec parse_byte_bv (n: nat) : Tot (parser (parse_byte_bv_kind n) (BV.bv_t (8 * n))) = parse_byte_bv_kind_eq n; if n = 0 then parse_ret Seq.empty else (parse_bv8 `nondep_then` parse_byte_bv (n - 1)) `parse_synth` synth_byte_bv (n - 1) let rec serialize_byte_bv (n: nat) : Tot (serializer (parse_byte_bv n)) = parse_byte_bv_kind_eq n; if n = 0 then serialize_ret Seq.empty (fun (x: BV.bv_t 0) -> assert (x `Seq.equal` Seq.empty)) else serialize_synth (parse_bv8 `nondep_then` parse_byte_bv (n - 1)) (synth_byte_bv (n - 1)) (serialize_bv8 `serialize_nondep_then` serialize_byte_bv (n - 1)) (synth_byte_bv_recip (n - 1)) () (* parse extra bits (big-endian with the first bits equal to 0) *) let extra_bytes_prop (n: nat) (x: U8.t) : Tot bool = U8.v x < pow2 (n % 8)
false
false
LowParse.Spec.BitVector.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val synth_extra_bv8 (n: nat) (x: parse_filter_refine (extra_bytes_prop n)) : Tot (BV.bv_t (n % 8))
[]
LowParse.Spec.BitVector.synth_extra_bv8
{ "file_name": "src/lowparse/LowParse.Spec.BitVector.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
n: Prims.nat -> x: LowParse.Spec.Combinators.parse_filter_refine (LowParse.Spec.BitVector.extra_bytes_prop n) -> FStar.BitVector.bv_t (n % 8)
{ "end_col": 20, "end_line": 167, "start_col": 2, "start_line": 167 }
Prims.Tot
val serialize_bounded_bv (min: nat) (max: nat{min <= max}) (#hk: parser_kind) (#hp: parser hk (bounded_int32 min max)) (hs: serializer hp {hk.parser_kind_subkind == Some ParserStrong}) : Tot (serializer (parse_bounded_bv min max hp))
[ { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.BitVector", "short_module": "BV" }, { "abbrev": false, "full_module": "FStar.Mul", "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 } ]
false
let serialize_bounded_bv (min: nat) (max: nat { min <= max }) (#hk: parser_kind) (#hp: parser hk (bounded_int32 min max)) (hs: serializer hp { hk.parser_kind_subkind == Some ParserStrong }) : Tot (serializer (parse_bounded_bv min max hp)) = serialize_dtuple2 hs (fun (sz: bounded_int32 min max) -> serialize_weaken (parse_bounded_bv_payload_kind min max) (serialize_bv (U32.v sz)))
val serialize_bounded_bv (min: nat) (max: nat{min <= max}) (#hk: parser_kind) (#hp: parser hk (bounded_int32 min max)) (hs: serializer hp {hk.parser_kind_subkind == Some ParserStrong}) : Tot (serializer (parse_bounded_bv min max hp)) let serialize_bounded_bv (min: nat) (max: nat{min <= max}) (#hk: parser_kind) (#hp: parser hk (bounded_int32 min max)) (hs: serializer hp {hk.parser_kind_subkind == Some ParserStrong}) : Tot (serializer (parse_bounded_bv min max hp)) =
false
null
false
serialize_dtuple2 hs (fun (sz: bounded_int32 min max) -> serialize_weaken (parse_bounded_bv_payload_kind min max) (serialize_bv (U32.v sz)))
{ "checked_file": "LowParse.Spec.BitVector.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Int.fsti.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.BoundedInt.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "LowParse.Spec.BitVector.fst" }
[ "total" ]
[ "Prims.nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Spec.BoundedInt.bounded_int32", "LowParse.Spec.Base.serializer", "Prims.eq2", "FStar.Pervasives.Native.option", "LowParse.Spec.Base.parser_subkind", "LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_subkind", "FStar.Pervasives.Native.Some", "LowParse.Spec.Base.ParserStrong", "LowParse.Spec.Combinators.serialize_dtuple2", "LowParse.Spec.BitVector.parse_bounded_bv_payload_kind", "FStar.BitVector.bv_t", "FStar.UInt32.v", "LowParse.Spec.Base.weaken", "LowParse.Spec.BitVector.parse_bv_kind", "LowParse.Spec.BitVector.parse_bv", "LowParse.Spec.Combinators.serialize_weaken", "LowParse.Spec.BitVector.serialize_bv", "LowParse.Spec.BitVector.parse_bounded_bv_kind", "LowParse.Spec.BitVector.bounded_bv_t", "LowParse.Spec.BitVector.parse_bounded_bv" ]
[]
module LowParse.Spec.BitVector open FStar.Mul module BV = FStar.BitVector module U8 = FStar.UInt8 module Seq = FStar.Seq (* Big-endian conversion of a bit vector to a UInt8 *) let rec to_uint8 (#n: nat { n <= 8 }) (x: BV.bv_t n) : Tot (y: U8.t { U8.v y < pow2 n }) = if n = 0 then 0uy else let hi = to_uint8 #(n - 1) (Seq.slice x 0 (n - 1)) in let hi' = hi `U8.mul` 2uy in let (r: U8.t { U8.v r < 2 }) = if Seq.index x (n - 1) then 1uy else 0uy in hi' `U8.add` r let rec of_uint8 (n: nat { n <= 8 }) (x: U8.t { U8.v x < pow2 n }) : Tot (BV.bv_t n) = if n = 0 then Seq.empty else let hi = of_uint8 (n - 1) (x `U8.div` 2uy) in Seq.snoc hi (x `U8.rem` 2uy = 1uy) #push-options "--z3rlimit 32" let rec to_uint8_of_uint8 (n: nat { n <= 8 }) (x: U8.t { U8.v x < pow2 n }) : Lemma (to_uint8 (of_uint8 n x) == x) = if n = 0 then () else begin assert (Seq.slice (of_uint8 n x) 0 (n - 1) `Seq.equal` of_uint8 (n - 1) (x `U8.div` 2uy)); to_uint8_of_uint8 (n - 1) (x `U8.div` 2uy) end let rec of_uint8_to_uint8 (#n: nat {n <= 8}) (x: BV.bv_t n) : Lemma (of_uint8 n (to_uint8 x) `Seq.equal` x) = if n = 0 then () else begin let x' = Seq.slice x 0 (n - 1) in of_uint8_to_uint8 #(n - 1) x' ; assert ( U8.v (to_uint8 #(n - 1) x') * 2 == U8.v (to_uint8 x) \/ U8.v (to_uint8 #(n - 1) x') * 2 + 1 == U8.v (to_uint8 x) ); assert (to_uint8 #(n - 1) x' == to_uint8 x `U8.div` 2uy); () end #pop-options (* parse a 8-bit vector *) open LowParse.Spec.Combinators open LowParse.Spec.Int let synth_bv8 (x: U8.t) : Tot (BV.bv_t 8) = of_uint8 8 x let synth_bv8_recip (x: BV.bv_t 8) : Tot U8.t = to_uint8 x let synth_bv8_injective : squash (synth_injective synth_bv8) = synth_inverse_intro' synth_bv8_recip synth_bv8 (fun x -> to_uint8_of_uint8 8 x ) let synth_bv8_inverse : squash (synth_inverse synth_bv8 synth_bv8_recip) = synth_inverse_intro' synth_bv8 synth_bv8_recip (fun x -> of_uint8_to_uint8 x ) let parse_bv8_kind = parse_u8_kind let parse_bv8 : parser parse_bv8_kind (BV.bv_t 8) = parse_u8 `parse_synth` synth_bv8 let serialize_bv8 : serializer parse_bv8 = serialize_synth parse_u8 synth_bv8 serialize_u8 synth_bv8_recip () (* parse a 8*n bit vector *) let synth_byte_bv (n: nat) (x: (BV.bv_t 8 & BV.bv_t (8 * n))) : Tot (BV.bv_t (8 * (1 + n))) = Seq.append (fst x) (snd x) let synth_byte_bv_recip (n: nat) (x: BV.bv_t (8 * (1 + n))) : Tot (BV.bv_t 8 & BV.bv_t (8 * n)) = Seq.slice x 0 8, Seq.slice x 8 (Seq.length x) let synth_byte_bv_injective (n: nat) : Lemma (synth_injective (synth_byte_bv n)) [SMTPat (synth_injective (synth_byte_bv n))] = synth_inverse_intro' (synth_byte_bv_recip n) (synth_byte_bv n) (fun x -> let (hd, tl) = x in let (hd', tl') = synth_byte_bv_recip n (synth_byte_bv n x) in assert (hd `Seq.equal` hd'); assert (tl `Seq.equal` tl') ) let synth_byte_bv_inverse (n: nat) : Lemma (synth_inverse (synth_byte_bv n) (synth_byte_bv_recip n)) [SMTPat (synth_inverse (synth_byte_bv n) (synth_byte_bv_recip n))] = synth_inverse_intro' (synth_byte_bv n) (synth_byte_bv_recip n) (fun x -> assert (synth_byte_bv n (synth_byte_bv_recip n x) `Seq.equal` x) ) let rec parse_byte_bv_kind' (n: nat) : Tot parser_kind = if n = 0 then parse_ret_kind else parse_bv8_kind `and_then_kind` parse_byte_bv_kind' (n - 1) let parse_byte_bv_kind (n: nat) : Tot parser_kind = strong_parser_kind n n (Some ParserKindMetadataTotal) let rec parse_byte_bv_kind_eq (n: nat) : Lemma (parse_byte_bv_kind n == parse_byte_bv_kind' n) = if n = 0 then () else parse_byte_bv_kind_eq (n - 1) let rec parse_byte_bv (n: nat) : Tot (parser (parse_byte_bv_kind n) (BV.bv_t (8 * n))) = parse_byte_bv_kind_eq n; if n = 0 then parse_ret Seq.empty else (parse_bv8 `nondep_then` parse_byte_bv (n - 1)) `parse_synth` synth_byte_bv (n - 1) let rec serialize_byte_bv (n: nat) : Tot (serializer (parse_byte_bv n)) = parse_byte_bv_kind_eq n; if n = 0 then serialize_ret Seq.empty (fun (x: BV.bv_t 0) -> assert (x `Seq.equal` Seq.empty)) else serialize_synth (parse_bv8 `nondep_then` parse_byte_bv (n - 1)) (synth_byte_bv (n - 1)) (serialize_bv8 `serialize_nondep_then` serialize_byte_bv (n - 1)) (synth_byte_bv_recip (n - 1)) () (* parse extra bits (big-endian with the first bits equal to 0) *) let extra_bytes_prop (n: nat) (x: U8.t) : Tot bool = U8.v x < pow2 (n % 8) let synth_extra_bv8 (n: nat) (x: parse_filter_refine (extra_bytes_prop n)) : Tot (BV.bv_t (n % 8)) = of_uint8 (n % 8) x let synth_extra_bv8_recip (n: nat) (x: BV.bv_t (n % 8)) : Tot (parse_filter_refine (extra_bytes_prop n)) = to_uint8 x let synth_extra_bv8_injective (n: nat) : Lemma (synth_injective (synth_extra_bv8 n)) [SMTPat (synth_injective (synth_extra_bv8 n))] = synth_inverse_intro' (synth_extra_bv8_recip n) (synth_extra_bv8 n) (fun x -> to_uint8_of_uint8 (n % 8) x ) let synth_extra_bv8_inverse (n: nat) : Lemma (synth_inverse (synth_extra_bv8 n) (synth_extra_bv8_recip n)) [SMTPat (synth_inverse (synth_extra_bv8 n) (synth_extra_bv8_recip n))] = synth_inverse_intro' (synth_extra_bv8 n) (synth_extra_bv8_recip n) (fun x -> of_uint8_to_uint8 x ) let parse_extra_bv8_kind (n: nat) : Tot parser_kind = parse_filter_kind parse_u8_kind let parse_extra_bv8 (n: nat) : Tot (parser (parse_extra_bv8_kind n) (BV.bv_t (n % 8))) = (parse_u8 `parse_filter` extra_bytes_prop n) `parse_synth` synth_extra_bv8 n let serialize_extra_bv8 (n: nat) : Tot (serializer (parse_extra_bv8 n)) = serialize_synth _ (synth_extra_bv8 n) (serialize_filter serialize_u8 (extra_bytes_prop n)) (synth_extra_bv8_recip n) () (* parse a bitvector, general *) let synth_bv (n: nat) (x: (BV.bv_t (n % 8) & BV.bv_t (8 * (n / 8)))) : Tot (BV.bv_t n) = Seq.append (fst x) (snd x) let synth_bv_recip (n: nat) (x: BV.bv_t n) : Tot (BV.bv_t (n % 8) & BV.bv_t (8 * (n / 8))) = Seq.slice x 0 (n % 8), Seq.slice x (n % 8) (Seq.length x) let synth_bv_injective (n: nat) : Lemma (synth_injective (synth_bv n)) [SMTPat (synth_injective (synth_bv n))] = synth_inverse_intro' (synth_bv_recip n) (synth_bv n) (fun x -> let (hd, tl) = x in let (hd', tl') = synth_bv_recip n (synth_bv n x) in assert (hd `Seq.equal` hd'); assert (tl `Seq.equal` tl') ) let synth_bv_inverse (n: nat) : Lemma (synth_inverse (synth_bv n) (synth_bv_recip n)) [SMTPat (synth_inverse (synth_bv n) (synth_bv_recip n))] = synth_inverse_intro' (synth_bv n) (synth_bv_recip n) (fun x -> assert (synth_bv n (synth_bv_recip n x) `Seq.equal` x) ) let parse_bv_kind (n: nat) : Tot parser_kind = if n % 8 = 0 then strong_parser_kind (n / 8) (n / 8) (Some ParserKindMetadataTotal) else strong_parser_kind (1 + n / 8) (1 + n / 8) None let parse_bv (n: nat) : Tot (parser (parse_bv_kind n) (BV.bv_t n)) = if n % 8 = 0 then parse_byte_bv (n / 8) else ((parse_extra_bv8 n `nondep_then` parse_byte_bv (n / 8)) `parse_synth` synth_bv n) let serialize_bv (n: nat) : Tot (serializer (parse_bv n)) = if n % 8 = 0 then serialize_byte_bv (n / 8) else serialize_synth _ (synth_bv n) (serialize_extra_bv8 n `serialize_nondep_then` serialize_byte_bv (n / 8)) (synth_bv_recip n) () (* parse a bounded bit vector *) module U32 = FStar.UInt32 open LowParse.Spec.BoundedInt inline_for_extraction let bounded_bv_t (min: nat) (max: nat { min <= max }) : Tot Type = (bitsize: bounded_int32 min max & BV.bv_t (U32.v bitsize)) let parse_bounded_bv_payload_kind (min: nat) (max: nat { min <= max }) : Tot parser_kind = strong_parser_kind (if min % 8 = 0 then min / 8 else 1 + min / 8) (if max % 8 = 0 then max / 8 else 1 + max / 8) None let parse_bounded_bv_payload_kind_is_weaker_than_parse_bv_kind (min: nat) (max: nat) (n: nat) : Lemma (requires (min <= n /\ n <= max)) (ensures ( min <= n /\ n <= max /\ parse_bounded_bv_payload_kind min max `is_weaker_than` parse_bv_kind n )) [SMTPat (parse_bounded_bv_payload_kind min max `is_weaker_than` parse_bv_kind n)] = () let parse_bounded_bv_kind (min: nat) (max: nat { min <= max }) (hk: parser_kind) : Tot parser_kind = hk `and_then_kind` parse_bounded_bv_payload_kind min max let parse_bounded_bv (min: nat) (max: nat { min <= max }) (#hk: parser_kind) (hp: parser hk (bounded_int32 min max)) : Tot (parser (parse_bounded_bv_kind min max hk) (bounded_bv_t min max)) = parse_dtuple2 hp (fun (sz: bounded_int32 min max) -> weaken (parse_bounded_bv_payload_kind min max) (parse_bv (U32.v sz))) let serialize_bounded_bv (min: nat) (max: nat { min <= max }) (#hk: parser_kind) (#hp: parser hk (bounded_int32 min max)) (hs: serializer hp { hk.parser_kind_subkind == Some ParserStrong })
false
false
LowParse.Spec.BitVector.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val serialize_bounded_bv (min: nat) (max: nat{min <= max}) (#hk: parser_kind) (#hp: parser hk (bounded_int32 min max)) (hs: serializer hp {hk.parser_kind_subkind == Some ParserStrong}) : Tot (serializer (parse_bounded_bv min max hp))
[]
LowParse.Spec.BitVector.serialize_bounded_bv
{ "file_name": "src/lowparse/LowParse.Spec.BitVector.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
min: Prims.nat -> max: Prims.nat{min <= max} -> hs: LowParse.Spec.Base.serializer hp { Mkparser_kind'?.parser_kind_subkind hk == FStar.Pervasives.Native.Some LowParse.Spec.Base.ParserStrong } -> LowParse.Spec.Base.serializer (LowParse.Spec.BitVector.parse_bounded_bv min max hp)
{ "end_col": 123, "end_line": 306, "start_col": 2, "start_line": 304 }
Prims.Tot
val parse_extra_bv8 (n: nat) : Tot (parser (parse_extra_bv8_kind n) (BV.bv_t (n % 8)))
[ { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.BitVector", "short_module": "BV" }, { "abbrev": false, "full_module": "FStar.Mul", "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 } ]
false
let parse_extra_bv8 (n: nat) : Tot (parser (parse_extra_bv8_kind n) (BV.bv_t (n % 8))) = (parse_u8 `parse_filter` extra_bytes_prop n) `parse_synth` synth_extra_bv8 n
val parse_extra_bv8 (n: nat) : Tot (parser (parse_extra_bv8_kind n) (BV.bv_t (n % 8))) let parse_extra_bv8 (n: nat) : Tot (parser (parse_extra_bv8_kind n) (BV.bv_t (n % 8))) =
false
null
false
(parse_u8 `parse_filter` (extra_bytes_prop n)) `parse_synth` (synth_extra_bv8 n)
{ "checked_file": "LowParse.Spec.BitVector.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Int.fsti.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.BoundedInt.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "LowParse.Spec.BitVector.fst" }
[ "total" ]
[ "Prims.nat", "LowParse.Spec.Combinators.parse_synth", "LowParse.Spec.Combinators.parse_filter_kind", "LowParse.Spec.Int.parse_u8_kind", "LowParse.Spec.Combinators.parse_filter_refine", "FStar.UInt8.t", "LowParse.Spec.BitVector.extra_bytes_prop", "FStar.BitVector.bv_t", "Prims.op_Modulus", "LowParse.Spec.Combinators.parse_filter", "LowParse.Spec.Int.parse_u8", "LowParse.Spec.BitVector.synth_extra_bv8", "LowParse.Spec.Base.parser", "LowParse.Spec.BitVector.parse_extra_bv8_kind" ]
[]
module LowParse.Spec.BitVector open FStar.Mul module BV = FStar.BitVector module U8 = FStar.UInt8 module Seq = FStar.Seq (* Big-endian conversion of a bit vector to a UInt8 *) let rec to_uint8 (#n: nat { n <= 8 }) (x: BV.bv_t n) : Tot (y: U8.t { U8.v y < pow2 n }) = if n = 0 then 0uy else let hi = to_uint8 #(n - 1) (Seq.slice x 0 (n - 1)) in let hi' = hi `U8.mul` 2uy in let (r: U8.t { U8.v r < 2 }) = if Seq.index x (n - 1) then 1uy else 0uy in hi' `U8.add` r let rec of_uint8 (n: nat { n <= 8 }) (x: U8.t { U8.v x < pow2 n }) : Tot (BV.bv_t n) = if n = 0 then Seq.empty else let hi = of_uint8 (n - 1) (x `U8.div` 2uy) in Seq.snoc hi (x `U8.rem` 2uy = 1uy) #push-options "--z3rlimit 32" let rec to_uint8_of_uint8 (n: nat { n <= 8 }) (x: U8.t { U8.v x < pow2 n }) : Lemma (to_uint8 (of_uint8 n x) == x) = if n = 0 then () else begin assert (Seq.slice (of_uint8 n x) 0 (n - 1) `Seq.equal` of_uint8 (n - 1) (x `U8.div` 2uy)); to_uint8_of_uint8 (n - 1) (x `U8.div` 2uy) end let rec of_uint8_to_uint8 (#n: nat {n <= 8}) (x: BV.bv_t n) : Lemma (of_uint8 n (to_uint8 x) `Seq.equal` x) = if n = 0 then () else begin let x' = Seq.slice x 0 (n - 1) in of_uint8_to_uint8 #(n - 1) x' ; assert ( U8.v (to_uint8 #(n - 1) x') * 2 == U8.v (to_uint8 x) \/ U8.v (to_uint8 #(n - 1) x') * 2 + 1 == U8.v (to_uint8 x) ); assert (to_uint8 #(n - 1) x' == to_uint8 x `U8.div` 2uy); () end #pop-options (* parse a 8-bit vector *) open LowParse.Spec.Combinators open LowParse.Spec.Int let synth_bv8 (x: U8.t) : Tot (BV.bv_t 8) = of_uint8 8 x let synth_bv8_recip (x: BV.bv_t 8) : Tot U8.t = to_uint8 x let synth_bv8_injective : squash (synth_injective synth_bv8) = synth_inverse_intro' synth_bv8_recip synth_bv8 (fun x -> to_uint8_of_uint8 8 x ) let synth_bv8_inverse : squash (synth_inverse synth_bv8 synth_bv8_recip) = synth_inverse_intro' synth_bv8 synth_bv8_recip (fun x -> of_uint8_to_uint8 x ) let parse_bv8_kind = parse_u8_kind let parse_bv8 : parser parse_bv8_kind (BV.bv_t 8) = parse_u8 `parse_synth` synth_bv8 let serialize_bv8 : serializer parse_bv8 = serialize_synth parse_u8 synth_bv8 serialize_u8 synth_bv8_recip () (* parse a 8*n bit vector *) let synth_byte_bv (n: nat) (x: (BV.bv_t 8 & BV.bv_t (8 * n))) : Tot (BV.bv_t (8 * (1 + n))) = Seq.append (fst x) (snd x) let synth_byte_bv_recip (n: nat) (x: BV.bv_t (8 * (1 + n))) : Tot (BV.bv_t 8 & BV.bv_t (8 * n)) = Seq.slice x 0 8, Seq.slice x 8 (Seq.length x) let synth_byte_bv_injective (n: nat) : Lemma (synth_injective (synth_byte_bv n)) [SMTPat (synth_injective (synth_byte_bv n))] = synth_inverse_intro' (synth_byte_bv_recip n) (synth_byte_bv n) (fun x -> let (hd, tl) = x in let (hd', tl') = synth_byte_bv_recip n (synth_byte_bv n x) in assert (hd `Seq.equal` hd'); assert (tl `Seq.equal` tl') ) let synth_byte_bv_inverse (n: nat) : Lemma (synth_inverse (synth_byte_bv n) (synth_byte_bv_recip n)) [SMTPat (synth_inverse (synth_byte_bv n) (synth_byte_bv_recip n))] = synth_inverse_intro' (synth_byte_bv n) (synth_byte_bv_recip n) (fun x -> assert (synth_byte_bv n (synth_byte_bv_recip n x) `Seq.equal` x) ) let rec parse_byte_bv_kind' (n: nat) : Tot parser_kind = if n = 0 then parse_ret_kind else parse_bv8_kind `and_then_kind` parse_byte_bv_kind' (n - 1) let parse_byte_bv_kind (n: nat) : Tot parser_kind = strong_parser_kind n n (Some ParserKindMetadataTotal) let rec parse_byte_bv_kind_eq (n: nat) : Lemma (parse_byte_bv_kind n == parse_byte_bv_kind' n) = if n = 0 then () else parse_byte_bv_kind_eq (n - 1) let rec parse_byte_bv (n: nat) : Tot (parser (parse_byte_bv_kind n) (BV.bv_t (8 * n))) = parse_byte_bv_kind_eq n; if n = 0 then parse_ret Seq.empty else (parse_bv8 `nondep_then` parse_byte_bv (n - 1)) `parse_synth` synth_byte_bv (n - 1) let rec serialize_byte_bv (n: nat) : Tot (serializer (parse_byte_bv n)) = parse_byte_bv_kind_eq n; if n = 0 then serialize_ret Seq.empty (fun (x: BV.bv_t 0) -> assert (x `Seq.equal` Seq.empty)) else serialize_synth (parse_bv8 `nondep_then` parse_byte_bv (n - 1)) (synth_byte_bv (n - 1)) (serialize_bv8 `serialize_nondep_then` serialize_byte_bv (n - 1)) (synth_byte_bv_recip (n - 1)) () (* parse extra bits (big-endian with the first bits equal to 0) *) let extra_bytes_prop (n: nat) (x: U8.t) : Tot bool = U8.v x < pow2 (n % 8) let synth_extra_bv8 (n: nat) (x: parse_filter_refine (extra_bytes_prop n)) : Tot (BV.bv_t (n % 8)) = of_uint8 (n % 8) x let synth_extra_bv8_recip (n: nat) (x: BV.bv_t (n % 8)) : Tot (parse_filter_refine (extra_bytes_prop n)) = to_uint8 x let synth_extra_bv8_injective (n: nat) : Lemma (synth_injective (synth_extra_bv8 n)) [SMTPat (synth_injective (synth_extra_bv8 n))] = synth_inverse_intro' (synth_extra_bv8_recip n) (synth_extra_bv8 n) (fun x -> to_uint8_of_uint8 (n % 8) x ) let synth_extra_bv8_inverse (n: nat) : Lemma (synth_inverse (synth_extra_bv8 n) (synth_extra_bv8_recip n)) [SMTPat (synth_inverse (synth_extra_bv8 n) (synth_extra_bv8_recip n))] = synth_inverse_intro' (synth_extra_bv8 n) (synth_extra_bv8_recip n) (fun x -> of_uint8_to_uint8 x ) let parse_extra_bv8_kind (n: nat) : Tot parser_kind = parse_filter_kind parse_u8_kind
false
false
LowParse.Spec.BitVector.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val parse_extra_bv8 (n: nat) : Tot (parser (parse_extra_bv8_kind n) (BV.bv_t (n % 8)))
[]
LowParse.Spec.BitVector.parse_extra_bv8
{ "file_name": "src/lowparse/LowParse.Spec.BitVector.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
n: Prims.nat -> LowParse.Spec.Base.parser (LowParse.Spec.BitVector.parse_extra_bv8_kind n) (FStar.BitVector.bv_t (n % 8))
{ "end_col": 78, "end_line": 190, "start_col": 2, "start_line": 190 }
Prims.Tot
val parse_bv (n: nat) : Tot (parser (parse_bv_kind n) (BV.bv_t n))
[ { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.BitVector", "short_module": "BV" }, { "abbrev": false, "full_module": "FStar.Mul", "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 } ]
false
let parse_bv (n: nat) : Tot (parser (parse_bv_kind n) (BV.bv_t n)) = if n % 8 = 0 then parse_byte_bv (n / 8) else ((parse_extra_bv8 n `nondep_then` parse_byte_bv (n / 8)) `parse_synth` synth_bv n)
val parse_bv (n: nat) : Tot (parser (parse_bv_kind n) (BV.bv_t n)) let parse_bv (n: nat) : Tot (parser (parse_bv_kind n) (BV.bv_t n)) =
false
null
false
if n % 8 = 0 then parse_byte_bv (n / 8) else (((parse_extra_bv8 n) `nondep_then` (parse_byte_bv (n / 8))) `parse_synth` (synth_bv n))
{ "checked_file": "LowParse.Spec.BitVector.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Int.fsti.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.BoundedInt.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "LowParse.Spec.BitVector.fst" }
[ "total" ]
[ "Prims.nat", "Prims.op_Equality", "Prims.int", "Prims.op_Modulus", "LowParse.Spec.BitVector.parse_byte_bv", "Prims.op_Division", "Prims.bool", "LowParse.Spec.Combinators.parse_synth", "LowParse.Spec.Combinators.and_then_kind", "LowParse.Spec.BitVector.parse_extra_bv8_kind", "LowParse.Spec.BitVector.parse_byte_bv_kind", "FStar.Pervasives.Native.tuple2", "FStar.BitVector.bv_t", "FStar.Mul.op_Star", "LowParse.Spec.Combinators.nondep_then", "LowParse.Spec.BitVector.parse_extra_bv8", "LowParse.Spec.BitVector.synth_bv", "LowParse.Spec.Base.parser", "LowParse.Spec.BitVector.parse_bv_kind" ]
[]
module LowParse.Spec.BitVector open FStar.Mul module BV = FStar.BitVector module U8 = FStar.UInt8 module Seq = FStar.Seq (* Big-endian conversion of a bit vector to a UInt8 *) let rec to_uint8 (#n: nat { n <= 8 }) (x: BV.bv_t n) : Tot (y: U8.t { U8.v y < pow2 n }) = if n = 0 then 0uy else let hi = to_uint8 #(n - 1) (Seq.slice x 0 (n - 1)) in let hi' = hi `U8.mul` 2uy in let (r: U8.t { U8.v r < 2 }) = if Seq.index x (n - 1) then 1uy else 0uy in hi' `U8.add` r let rec of_uint8 (n: nat { n <= 8 }) (x: U8.t { U8.v x < pow2 n }) : Tot (BV.bv_t n) = if n = 0 then Seq.empty else let hi = of_uint8 (n - 1) (x `U8.div` 2uy) in Seq.snoc hi (x `U8.rem` 2uy = 1uy) #push-options "--z3rlimit 32" let rec to_uint8_of_uint8 (n: nat { n <= 8 }) (x: U8.t { U8.v x < pow2 n }) : Lemma (to_uint8 (of_uint8 n x) == x) = if n = 0 then () else begin assert (Seq.slice (of_uint8 n x) 0 (n - 1) `Seq.equal` of_uint8 (n - 1) (x `U8.div` 2uy)); to_uint8_of_uint8 (n - 1) (x `U8.div` 2uy) end let rec of_uint8_to_uint8 (#n: nat {n <= 8}) (x: BV.bv_t n) : Lemma (of_uint8 n (to_uint8 x) `Seq.equal` x) = if n = 0 then () else begin let x' = Seq.slice x 0 (n - 1) in of_uint8_to_uint8 #(n - 1) x' ; assert ( U8.v (to_uint8 #(n - 1) x') * 2 == U8.v (to_uint8 x) \/ U8.v (to_uint8 #(n - 1) x') * 2 + 1 == U8.v (to_uint8 x) ); assert (to_uint8 #(n - 1) x' == to_uint8 x `U8.div` 2uy); () end #pop-options (* parse a 8-bit vector *) open LowParse.Spec.Combinators open LowParse.Spec.Int let synth_bv8 (x: U8.t) : Tot (BV.bv_t 8) = of_uint8 8 x let synth_bv8_recip (x: BV.bv_t 8) : Tot U8.t = to_uint8 x let synth_bv8_injective : squash (synth_injective synth_bv8) = synth_inverse_intro' synth_bv8_recip synth_bv8 (fun x -> to_uint8_of_uint8 8 x ) let synth_bv8_inverse : squash (synth_inverse synth_bv8 synth_bv8_recip) = synth_inverse_intro' synth_bv8 synth_bv8_recip (fun x -> of_uint8_to_uint8 x ) let parse_bv8_kind = parse_u8_kind let parse_bv8 : parser parse_bv8_kind (BV.bv_t 8) = parse_u8 `parse_synth` synth_bv8 let serialize_bv8 : serializer parse_bv8 = serialize_synth parse_u8 synth_bv8 serialize_u8 synth_bv8_recip () (* parse a 8*n bit vector *) let synth_byte_bv (n: nat) (x: (BV.bv_t 8 & BV.bv_t (8 * n))) : Tot (BV.bv_t (8 * (1 + n))) = Seq.append (fst x) (snd x) let synth_byte_bv_recip (n: nat) (x: BV.bv_t (8 * (1 + n))) : Tot (BV.bv_t 8 & BV.bv_t (8 * n)) = Seq.slice x 0 8, Seq.slice x 8 (Seq.length x) let synth_byte_bv_injective (n: nat) : Lemma (synth_injective (synth_byte_bv n)) [SMTPat (synth_injective (synth_byte_bv n))] = synth_inverse_intro' (synth_byte_bv_recip n) (synth_byte_bv n) (fun x -> let (hd, tl) = x in let (hd', tl') = synth_byte_bv_recip n (synth_byte_bv n x) in assert (hd `Seq.equal` hd'); assert (tl `Seq.equal` tl') ) let synth_byte_bv_inverse (n: nat) : Lemma (synth_inverse (synth_byte_bv n) (synth_byte_bv_recip n)) [SMTPat (synth_inverse (synth_byte_bv n) (synth_byte_bv_recip n))] = synth_inverse_intro' (synth_byte_bv n) (synth_byte_bv_recip n) (fun x -> assert (synth_byte_bv n (synth_byte_bv_recip n x) `Seq.equal` x) ) let rec parse_byte_bv_kind' (n: nat) : Tot parser_kind = if n = 0 then parse_ret_kind else parse_bv8_kind `and_then_kind` parse_byte_bv_kind' (n - 1) let parse_byte_bv_kind (n: nat) : Tot parser_kind = strong_parser_kind n n (Some ParserKindMetadataTotal) let rec parse_byte_bv_kind_eq (n: nat) : Lemma (parse_byte_bv_kind n == parse_byte_bv_kind' n) = if n = 0 then () else parse_byte_bv_kind_eq (n - 1) let rec parse_byte_bv (n: nat) : Tot (parser (parse_byte_bv_kind n) (BV.bv_t (8 * n))) = parse_byte_bv_kind_eq n; if n = 0 then parse_ret Seq.empty else (parse_bv8 `nondep_then` parse_byte_bv (n - 1)) `parse_synth` synth_byte_bv (n - 1) let rec serialize_byte_bv (n: nat) : Tot (serializer (parse_byte_bv n)) = parse_byte_bv_kind_eq n; if n = 0 then serialize_ret Seq.empty (fun (x: BV.bv_t 0) -> assert (x `Seq.equal` Seq.empty)) else serialize_synth (parse_bv8 `nondep_then` parse_byte_bv (n - 1)) (synth_byte_bv (n - 1)) (serialize_bv8 `serialize_nondep_then` serialize_byte_bv (n - 1)) (synth_byte_bv_recip (n - 1)) () (* parse extra bits (big-endian with the first bits equal to 0) *) let extra_bytes_prop (n: nat) (x: U8.t) : Tot bool = U8.v x < pow2 (n % 8) let synth_extra_bv8 (n: nat) (x: parse_filter_refine (extra_bytes_prop n)) : Tot (BV.bv_t (n % 8)) = of_uint8 (n % 8) x let synth_extra_bv8_recip (n: nat) (x: BV.bv_t (n % 8)) : Tot (parse_filter_refine (extra_bytes_prop n)) = to_uint8 x let synth_extra_bv8_injective (n: nat) : Lemma (synth_injective (synth_extra_bv8 n)) [SMTPat (synth_injective (synth_extra_bv8 n))] = synth_inverse_intro' (synth_extra_bv8_recip n) (synth_extra_bv8 n) (fun x -> to_uint8_of_uint8 (n % 8) x ) let synth_extra_bv8_inverse (n: nat) : Lemma (synth_inverse (synth_extra_bv8 n) (synth_extra_bv8_recip n)) [SMTPat (synth_inverse (synth_extra_bv8 n) (synth_extra_bv8_recip n))] = synth_inverse_intro' (synth_extra_bv8 n) (synth_extra_bv8_recip n) (fun x -> of_uint8_to_uint8 x ) let parse_extra_bv8_kind (n: nat) : Tot parser_kind = parse_filter_kind parse_u8_kind let parse_extra_bv8 (n: nat) : Tot (parser (parse_extra_bv8_kind n) (BV.bv_t (n % 8))) = (parse_u8 `parse_filter` extra_bytes_prop n) `parse_synth` synth_extra_bv8 n let serialize_extra_bv8 (n: nat) : Tot (serializer (parse_extra_bv8 n)) = serialize_synth _ (synth_extra_bv8 n) (serialize_filter serialize_u8 (extra_bytes_prop n)) (synth_extra_bv8_recip n) () (* parse a bitvector, general *) let synth_bv (n: nat) (x: (BV.bv_t (n % 8) & BV.bv_t (8 * (n / 8)))) : Tot (BV.bv_t n) = Seq.append (fst x) (snd x) let synth_bv_recip (n: nat) (x: BV.bv_t n) : Tot (BV.bv_t (n % 8) & BV.bv_t (8 * (n / 8))) = Seq.slice x 0 (n % 8), Seq.slice x (n % 8) (Seq.length x) let synth_bv_injective (n: nat) : Lemma (synth_injective (synth_bv n)) [SMTPat (synth_injective (synth_bv n))] = synth_inverse_intro' (synth_bv_recip n) (synth_bv n) (fun x -> let (hd, tl) = x in let (hd', tl') = synth_bv_recip n (synth_bv n x) in assert (hd `Seq.equal` hd'); assert (tl `Seq.equal` tl') ) let synth_bv_inverse (n: nat) : Lemma (synth_inverse (synth_bv n) (synth_bv_recip n)) [SMTPat (synth_inverse (synth_bv n) (synth_bv_recip n))] = synth_inverse_intro' (synth_bv n) (synth_bv_recip n) (fun x -> assert (synth_bv n (synth_bv_recip n x) `Seq.equal` x) ) let parse_bv_kind (n: nat) : Tot parser_kind = if n % 8 = 0 then strong_parser_kind (n / 8) (n / 8) (Some ParserKindMetadataTotal) else strong_parser_kind (1 + n / 8) (1 + n / 8) None
false
false
LowParse.Spec.BitVector.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val parse_bv (n: nat) : Tot (parser (parse_bv_kind n) (BV.bv_t n))
[]
LowParse.Spec.BitVector.parse_bv
{ "file_name": "src/lowparse/LowParse.Spec.BitVector.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
n: Prims.nat -> LowParse.Spec.Base.parser (LowParse.Spec.BitVector.parse_bv_kind n) (FStar.BitVector.bv_t n)
{ "end_col": 129, "end_line": 231, "start_col": 2, "start_line": 231 }
Prims.Tot
val synth_bv_recip (n: nat) (x: BV.bv_t n) : Tot (BV.bv_t (n % 8) & BV.bv_t (8 * (n / 8)))
[ { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.BitVector", "short_module": "BV" }, { "abbrev": false, "full_module": "FStar.Mul", "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 } ]
false
let synth_bv_recip (n: nat) (x: BV.bv_t n) : Tot (BV.bv_t (n % 8) & BV.bv_t (8 * (n / 8))) = Seq.slice x 0 (n % 8), Seq.slice x (n % 8) (Seq.length x)
val synth_bv_recip (n: nat) (x: BV.bv_t n) : Tot (BV.bv_t (n % 8) & BV.bv_t (8 * (n / 8))) let synth_bv_recip (n: nat) (x: BV.bv_t n) : Tot (BV.bv_t (n % 8) & BV.bv_t (8 * (n / 8))) =
false
null
false
Seq.slice x 0 (n % 8), Seq.slice x (n % 8) (Seq.length x)
{ "checked_file": "LowParse.Spec.BitVector.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Int.fsti.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.BoundedInt.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "LowParse.Spec.BitVector.fst" }
[ "total" ]
[ "Prims.nat", "FStar.BitVector.bv_t", "FStar.Pervasives.Native.Mktuple2", "Prims.op_Modulus", "FStar.Mul.op_Star", "Prims.op_Division", "FStar.Seq.Base.slice", "Prims.bool", "FStar.Seq.Base.length", "FStar.Pervasives.Native.tuple2" ]
[]
module LowParse.Spec.BitVector open FStar.Mul module BV = FStar.BitVector module U8 = FStar.UInt8 module Seq = FStar.Seq (* Big-endian conversion of a bit vector to a UInt8 *) let rec to_uint8 (#n: nat { n <= 8 }) (x: BV.bv_t n) : Tot (y: U8.t { U8.v y < pow2 n }) = if n = 0 then 0uy else let hi = to_uint8 #(n - 1) (Seq.slice x 0 (n - 1)) in let hi' = hi `U8.mul` 2uy in let (r: U8.t { U8.v r < 2 }) = if Seq.index x (n - 1) then 1uy else 0uy in hi' `U8.add` r let rec of_uint8 (n: nat { n <= 8 }) (x: U8.t { U8.v x < pow2 n }) : Tot (BV.bv_t n) = if n = 0 then Seq.empty else let hi = of_uint8 (n - 1) (x `U8.div` 2uy) in Seq.snoc hi (x `U8.rem` 2uy = 1uy) #push-options "--z3rlimit 32" let rec to_uint8_of_uint8 (n: nat { n <= 8 }) (x: U8.t { U8.v x < pow2 n }) : Lemma (to_uint8 (of_uint8 n x) == x) = if n = 0 then () else begin assert (Seq.slice (of_uint8 n x) 0 (n - 1) `Seq.equal` of_uint8 (n - 1) (x `U8.div` 2uy)); to_uint8_of_uint8 (n - 1) (x `U8.div` 2uy) end let rec of_uint8_to_uint8 (#n: nat {n <= 8}) (x: BV.bv_t n) : Lemma (of_uint8 n (to_uint8 x) `Seq.equal` x) = if n = 0 then () else begin let x' = Seq.slice x 0 (n - 1) in of_uint8_to_uint8 #(n - 1) x' ; assert ( U8.v (to_uint8 #(n - 1) x') * 2 == U8.v (to_uint8 x) \/ U8.v (to_uint8 #(n - 1) x') * 2 + 1 == U8.v (to_uint8 x) ); assert (to_uint8 #(n - 1) x' == to_uint8 x `U8.div` 2uy); () end #pop-options (* parse a 8-bit vector *) open LowParse.Spec.Combinators open LowParse.Spec.Int let synth_bv8 (x: U8.t) : Tot (BV.bv_t 8) = of_uint8 8 x let synth_bv8_recip (x: BV.bv_t 8) : Tot U8.t = to_uint8 x let synth_bv8_injective : squash (synth_injective synth_bv8) = synth_inverse_intro' synth_bv8_recip synth_bv8 (fun x -> to_uint8_of_uint8 8 x ) let synth_bv8_inverse : squash (synth_inverse synth_bv8 synth_bv8_recip) = synth_inverse_intro' synth_bv8 synth_bv8_recip (fun x -> of_uint8_to_uint8 x ) let parse_bv8_kind = parse_u8_kind let parse_bv8 : parser parse_bv8_kind (BV.bv_t 8) = parse_u8 `parse_synth` synth_bv8 let serialize_bv8 : serializer parse_bv8 = serialize_synth parse_u8 synth_bv8 serialize_u8 synth_bv8_recip () (* parse a 8*n bit vector *) let synth_byte_bv (n: nat) (x: (BV.bv_t 8 & BV.bv_t (8 * n))) : Tot (BV.bv_t (8 * (1 + n))) = Seq.append (fst x) (snd x) let synth_byte_bv_recip (n: nat) (x: BV.bv_t (8 * (1 + n))) : Tot (BV.bv_t 8 & BV.bv_t (8 * n)) = Seq.slice x 0 8, Seq.slice x 8 (Seq.length x) let synth_byte_bv_injective (n: nat) : Lemma (synth_injective (synth_byte_bv n)) [SMTPat (synth_injective (synth_byte_bv n))] = synth_inverse_intro' (synth_byte_bv_recip n) (synth_byte_bv n) (fun x -> let (hd, tl) = x in let (hd', tl') = synth_byte_bv_recip n (synth_byte_bv n x) in assert (hd `Seq.equal` hd'); assert (tl `Seq.equal` tl') ) let synth_byte_bv_inverse (n: nat) : Lemma (synth_inverse (synth_byte_bv n) (synth_byte_bv_recip n)) [SMTPat (synth_inverse (synth_byte_bv n) (synth_byte_bv_recip n))] = synth_inverse_intro' (synth_byte_bv n) (synth_byte_bv_recip n) (fun x -> assert (synth_byte_bv n (synth_byte_bv_recip n x) `Seq.equal` x) ) let rec parse_byte_bv_kind' (n: nat) : Tot parser_kind = if n = 0 then parse_ret_kind else parse_bv8_kind `and_then_kind` parse_byte_bv_kind' (n - 1) let parse_byte_bv_kind (n: nat) : Tot parser_kind = strong_parser_kind n n (Some ParserKindMetadataTotal) let rec parse_byte_bv_kind_eq (n: nat) : Lemma (parse_byte_bv_kind n == parse_byte_bv_kind' n) = if n = 0 then () else parse_byte_bv_kind_eq (n - 1) let rec parse_byte_bv (n: nat) : Tot (parser (parse_byte_bv_kind n) (BV.bv_t (8 * n))) = parse_byte_bv_kind_eq n; if n = 0 then parse_ret Seq.empty else (parse_bv8 `nondep_then` parse_byte_bv (n - 1)) `parse_synth` synth_byte_bv (n - 1) let rec serialize_byte_bv (n: nat) : Tot (serializer (parse_byte_bv n)) = parse_byte_bv_kind_eq n; if n = 0 then serialize_ret Seq.empty (fun (x: BV.bv_t 0) -> assert (x `Seq.equal` Seq.empty)) else serialize_synth (parse_bv8 `nondep_then` parse_byte_bv (n - 1)) (synth_byte_bv (n - 1)) (serialize_bv8 `serialize_nondep_then` serialize_byte_bv (n - 1)) (synth_byte_bv_recip (n - 1)) () (* parse extra bits (big-endian with the first bits equal to 0) *) let extra_bytes_prop (n: nat) (x: U8.t) : Tot bool = U8.v x < pow2 (n % 8) let synth_extra_bv8 (n: nat) (x: parse_filter_refine (extra_bytes_prop n)) : Tot (BV.bv_t (n % 8)) = of_uint8 (n % 8) x let synth_extra_bv8_recip (n: nat) (x: BV.bv_t (n % 8)) : Tot (parse_filter_refine (extra_bytes_prop n)) = to_uint8 x let synth_extra_bv8_injective (n: nat) : Lemma (synth_injective (synth_extra_bv8 n)) [SMTPat (synth_injective (synth_extra_bv8 n))] = synth_inverse_intro' (synth_extra_bv8_recip n) (synth_extra_bv8 n) (fun x -> to_uint8_of_uint8 (n % 8) x ) let synth_extra_bv8_inverse (n: nat) : Lemma (synth_inverse (synth_extra_bv8 n) (synth_extra_bv8_recip n)) [SMTPat (synth_inverse (synth_extra_bv8 n) (synth_extra_bv8_recip n))] = synth_inverse_intro' (synth_extra_bv8 n) (synth_extra_bv8_recip n) (fun x -> of_uint8_to_uint8 x ) let parse_extra_bv8_kind (n: nat) : Tot parser_kind = parse_filter_kind parse_u8_kind let parse_extra_bv8 (n: nat) : Tot (parser (parse_extra_bv8_kind n) (BV.bv_t (n % 8))) = (parse_u8 `parse_filter` extra_bytes_prop n) `parse_synth` synth_extra_bv8 n let serialize_extra_bv8 (n: nat) : Tot (serializer (parse_extra_bv8 n)) = serialize_synth _ (synth_extra_bv8 n) (serialize_filter serialize_u8 (extra_bytes_prop n)) (synth_extra_bv8_recip n) () (* parse a bitvector, general *) let synth_bv (n: nat) (x: (BV.bv_t (n % 8) & BV.bv_t (8 * (n / 8)))) : Tot (BV.bv_t n) = Seq.append (fst x) (snd x)
false
false
LowParse.Spec.BitVector.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val synth_bv_recip (n: nat) (x: BV.bv_t n) : Tot (BV.bv_t (n % 8) & BV.bv_t (8 * (n / 8)))
[]
LowParse.Spec.BitVector.synth_bv_recip
{ "file_name": "src/lowparse/LowParse.Spec.BitVector.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
n: Prims.nat -> x: FStar.BitVector.bv_t n -> FStar.BitVector.bv_t (n % 8) * FStar.BitVector.bv_t (8 * (n / 8))
{ "end_col": 59, "end_line": 206, "start_col": 2, "start_line": 206 }
FStar.Pervasives.Lemma
val synth_byte_bv_injective (n: nat) : Lemma (synth_injective (synth_byte_bv n)) [SMTPat (synth_injective (synth_byte_bv n))]
[ { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.BitVector", "short_module": "BV" }, { "abbrev": false, "full_module": "FStar.Mul", "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 } ]
false
let synth_byte_bv_injective (n: nat) : Lemma (synth_injective (synth_byte_bv n)) [SMTPat (synth_injective (synth_byte_bv n))] = synth_inverse_intro' (synth_byte_bv_recip n) (synth_byte_bv n) (fun x -> let (hd, tl) = x in let (hd', tl') = synth_byte_bv_recip n (synth_byte_bv n x) in assert (hd `Seq.equal` hd'); assert (tl `Seq.equal` tl') )
val synth_byte_bv_injective (n: nat) : Lemma (synth_injective (synth_byte_bv n)) [SMTPat (synth_injective (synth_byte_bv n))] let synth_byte_bv_injective (n: nat) : Lemma (synth_injective (synth_byte_bv n)) [SMTPat (synth_injective (synth_byte_bv n))] =
false
null
true
synth_inverse_intro' (synth_byte_bv_recip n) (synth_byte_bv n) (fun x -> let hd, tl = x in let hd', tl' = synth_byte_bv_recip n (synth_byte_bv n x) in assert (hd `Seq.equal` hd'); assert (tl `Seq.equal` tl'))
{ "checked_file": "LowParse.Spec.BitVector.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Int.fsti.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.BoundedInt.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "LowParse.Spec.BitVector.fst" }
[ "lemma" ]
[ "Prims.nat", "LowParse.Spec.Combinators.synth_inverse_intro'", "FStar.BitVector.bv_t", "FStar.Mul.op_Star", "Prims.op_Addition", "FStar.Pervasives.Native.tuple2", "LowParse.Spec.BitVector.synth_byte_bv_recip", "LowParse.Spec.BitVector.synth_byte_bv", "Prims._assert", "FStar.Seq.Base.equal", "Prims.bool", "Prims.unit", "Prims.op_Multiply", "Prims.l_True", "Prims.squash", "LowParse.Spec.Combinators.synth_injective", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat", "Prims.Nil" ]
[]
module LowParse.Spec.BitVector open FStar.Mul module BV = FStar.BitVector module U8 = FStar.UInt8 module Seq = FStar.Seq (* Big-endian conversion of a bit vector to a UInt8 *) let rec to_uint8 (#n: nat { n <= 8 }) (x: BV.bv_t n) : Tot (y: U8.t { U8.v y < pow2 n }) = if n = 0 then 0uy else let hi = to_uint8 #(n - 1) (Seq.slice x 0 (n - 1)) in let hi' = hi `U8.mul` 2uy in let (r: U8.t { U8.v r < 2 }) = if Seq.index x (n - 1) then 1uy else 0uy in hi' `U8.add` r let rec of_uint8 (n: nat { n <= 8 }) (x: U8.t { U8.v x < pow2 n }) : Tot (BV.bv_t n) = if n = 0 then Seq.empty else let hi = of_uint8 (n - 1) (x `U8.div` 2uy) in Seq.snoc hi (x `U8.rem` 2uy = 1uy) #push-options "--z3rlimit 32" let rec to_uint8_of_uint8 (n: nat { n <= 8 }) (x: U8.t { U8.v x < pow2 n }) : Lemma (to_uint8 (of_uint8 n x) == x) = if n = 0 then () else begin assert (Seq.slice (of_uint8 n x) 0 (n - 1) `Seq.equal` of_uint8 (n - 1) (x `U8.div` 2uy)); to_uint8_of_uint8 (n - 1) (x `U8.div` 2uy) end let rec of_uint8_to_uint8 (#n: nat {n <= 8}) (x: BV.bv_t n) : Lemma (of_uint8 n (to_uint8 x) `Seq.equal` x) = if n = 0 then () else begin let x' = Seq.slice x 0 (n - 1) in of_uint8_to_uint8 #(n - 1) x' ; assert ( U8.v (to_uint8 #(n - 1) x') * 2 == U8.v (to_uint8 x) \/ U8.v (to_uint8 #(n - 1) x') * 2 + 1 == U8.v (to_uint8 x) ); assert (to_uint8 #(n - 1) x' == to_uint8 x `U8.div` 2uy); () end #pop-options (* parse a 8-bit vector *) open LowParse.Spec.Combinators open LowParse.Spec.Int let synth_bv8 (x: U8.t) : Tot (BV.bv_t 8) = of_uint8 8 x let synth_bv8_recip (x: BV.bv_t 8) : Tot U8.t = to_uint8 x let synth_bv8_injective : squash (synth_injective synth_bv8) = synth_inverse_intro' synth_bv8_recip synth_bv8 (fun x -> to_uint8_of_uint8 8 x ) let synth_bv8_inverse : squash (synth_inverse synth_bv8 synth_bv8_recip) = synth_inverse_intro' synth_bv8 synth_bv8_recip (fun x -> of_uint8_to_uint8 x ) let parse_bv8_kind = parse_u8_kind let parse_bv8 : parser parse_bv8_kind (BV.bv_t 8) = parse_u8 `parse_synth` synth_bv8 let serialize_bv8 : serializer parse_bv8 = serialize_synth parse_u8 synth_bv8 serialize_u8 synth_bv8_recip () (* parse a 8*n bit vector *) let synth_byte_bv (n: nat) (x: (BV.bv_t 8 & BV.bv_t (8 * n))) : Tot (BV.bv_t (8 * (1 + n))) = Seq.append (fst x) (snd x) let synth_byte_bv_recip (n: nat) (x: BV.bv_t (8 * (1 + n))) : Tot (BV.bv_t 8 & BV.bv_t (8 * n)) = Seq.slice x 0 8, Seq.slice x 8 (Seq.length x) let synth_byte_bv_injective (n: nat) : Lemma (synth_injective (synth_byte_bv n))
false
false
LowParse.Spec.BitVector.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val synth_byte_bv_injective (n: nat) : Lemma (synth_injective (synth_byte_bv n)) [SMTPat (synth_injective (synth_byte_bv n))]
[]
LowParse.Spec.BitVector.synth_byte_bv_injective
{ "file_name": "src/lowparse/LowParse.Spec.BitVector.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
n: Prims.nat -> FStar.Pervasives.Lemma (ensures LowParse.Spec.Combinators.synth_injective (LowParse.Spec.BitVector.synth_byte_bv n)) [SMTPat (LowParse.Spec.Combinators.synth_injective (LowParse.Spec.BitVector.synth_byte_bv n))]
{ "end_col": 3, "end_line": 117, "start_col": 2, "start_line": 112 }
FStar.Pervasives.Lemma
val synth_byte_bv_inverse (n: nat) : Lemma (synth_inverse (synth_byte_bv n) (synth_byte_bv_recip n)) [SMTPat (synth_inverse (synth_byte_bv n) (synth_byte_bv_recip n))]
[ { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.BitVector", "short_module": "BV" }, { "abbrev": false, "full_module": "FStar.Mul", "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 } ]
false
let synth_byte_bv_inverse (n: nat) : Lemma (synth_inverse (synth_byte_bv n) (synth_byte_bv_recip n)) [SMTPat (synth_inverse (synth_byte_bv n) (synth_byte_bv_recip n))] = synth_inverse_intro' (synth_byte_bv n) (synth_byte_bv_recip n) (fun x -> assert (synth_byte_bv n (synth_byte_bv_recip n x) `Seq.equal` x) )
val synth_byte_bv_inverse (n: nat) : Lemma (synth_inverse (synth_byte_bv n) (synth_byte_bv_recip n)) [SMTPat (synth_inverse (synth_byte_bv n) (synth_byte_bv_recip n))] let synth_byte_bv_inverse (n: nat) : Lemma (synth_inverse (synth_byte_bv n) (synth_byte_bv_recip n)) [SMTPat (synth_inverse (synth_byte_bv n) (synth_byte_bv_recip n))] =
false
null
true
synth_inverse_intro' (synth_byte_bv n) (synth_byte_bv_recip n) (fun x -> assert ((synth_byte_bv n (synth_byte_bv_recip n x)) `Seq.equal` x))
{ "checked_file": "LowParse.Spec.BitVector.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Int.fsti.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.BoundedInt.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "LowParse.Spec.BitVector.fst" }
[ "lemma" ]
[ "Prims.nat", "LowParse.Spec.Combinators.synth_inverse_intro'", "FStar.Pervasives.Native.tuple2", "FStar.BitVector.bv_t", "FStar.Mul.op_Star", "FStar.Seq.Base.seq", "Prims.bool", "Prims.b2t", "Prims.op_Equality", "FStar.Seq.Base.length", "Prims.op_Addition", "LowParse.Spec.BitVector.synth_byte_bv", "LowParse.Spec.BitVector.synth_byte_bv_recip", "Prims._assert", "FStar.Seq.Base.equal", "Prims.unit", "Prims.l_True", "Prims.squash", "LowParse.Spec.Combinators.synth_inverse", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat", "Prims.Nil" ]
[]
module LowParse.Spec.BitVector open FStar.Mul module BV = FStar.BitVector module U8 = FStar.UInt8 module Seq = FStar.Seq (* Big-endian conversion of a bit vector to a UInt8 *) let rec to_uint8 (#n: nat { n <= 8 }) (x: BV.bv_t n) : Tot (y: U8.t { U8.v y < pow2 n }) = if n = 0 then 0uy else let hi = to_uint8 #(n - 1) (Seq.slice x 0 (n - 1)) in let hi' = hi `U8.mul` 2uy in let (r: U8.t { U8.v r < 2 }) = if Seq.index x (n - 1) then 1uy else 0uy in hi' `U8.add` r let rec of_uint8 (n: nat { n <= 8 }) (x: U8.t { U8.v x < pow2 n }) : Tot (BV.bv_t n) = if n = 0 then Seq.empty else let hi = of_uint8 (n - 1) (x `U8.div` 2uy) in Seq.snoc hi (x `U8.rem` 2uy = 1uy) #push-options "--z3rlimit 32" let rec to_uint8_of_uint8 (n: nat { n <= 8 }) (x: U8.t { U8.v x < pow2 n }) : Lemma (to_uint8 (of_uint8 n x) == x) = if n = 0 then () else begin assert (Seq.slice (of_uint8 n x) 0 (n - 1) `Seq.equal` of_uint8 (n - 1) (x `U8.div` 2uy)); to_uint8_of_uint8 (n - 1) (x `U8.div` 2uy) end let rec of_uint8_to_uint8 (#n: nat {n <= 8}) (x: BV.bv_t n) : Lemma (of_uint8 n (to_uint8 x) `Seq.equal` x) = if n = 0 then () else begin let x' = Seq.slice x 0 (n - 1) in of_uint8_to_uint8 #(n - 1) x' ; assert ( U8.v (to_uint8 #(n - 1) x') * 2 == U8.v (to_uint8 x) \/ U8.v (to_uint8 #(n - 1) x') * 2 + 1 == U8.v (to_uint8 x) ); assert (to_uint8 #(n - 1) x' == to_uint8 x `U8.div` 2uy); () end #pop-options (* parse a 8-bit vector *) open LowParse.Spec.Combinators open LowParse.Spec.Int let synth_bv8 (x: U8.t) : Tot (BV.bv_t 8) = of_uint8 8 x let synth_bv8_recip (x: BV.bv_t 8) : Tot U8.t = to_uint8 x let synth_bv8_injective : squash (synth_injective synth_bv8) = synth_inverse_intro' synth_bv8_recip synth_bv8 (fun x -> to_uint8_of_uint8 8 x ) let synth_bv8_inverse : squash (synth_inverse synth_bv8 synth_bv8_recip) = synth_inverse_intro' synth_bv8 synth_bv8_recip (fun x -> of_uint8_to_uint8 x ) let parse_bv8_kind = parse_u8_kind let parse_bv8 : parser parse_bv8_kind (BV.bv_t 8) = parse_u8 `parse_synth` synth_bv8 let serialize_bv8 : serializer parse_bv8 = serialize_synth parse_u8 synth_bv8 serialize_u8 synth_bv8_recip () (* parse a 8*n bit vector *) let synth_byte_bv (n: nat) (x: (BV.bv_t 8 & BV.bv_t (8 * n))) : Tot (BV.bv_t (8 * (1 + n))) = Seq.append (fst x) (snd x) let synth_byte_bv_recip (n: nat) (x: BV.bv_t (8 * (1 + n))) : Tot (BV.bv_t 8 & BV.bv_t (8 * n)) = Seq.slice x 0 8, Seq.slice x 8 (Seq.length x) let synth_byte_bv_injective (n: nat) : Lemma (synth_injective (synth_byte_bv n)) [SMTPat (synth_injective (synth_byte_bv n))] = synth_inverse_intro' (synth_byte_bv_recip n) (synth_byte_bv n) (fun x -> let (hd, tl) = x in let (hd', tl') = synth_byte_bv_recip n (synth_byte_bv n x) in assert (hd `Seq.equal` hd'); assert (tl `Seq.equal` tl') ) let synth_byte_bv_inverse (n: nat) : Lemma (synth_inverse (synth_byte_bv n) (synth_byte_bv_recip n))
false
false
LowParse.Spec.BitVector.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val synth_byte_bv_inverse (n: nat) : Lemma (synth_inverse (synth_byte_bv n) (synth_byte_bv_recip n)) [SMTPat (synth_inverse (synth_byte_bv n) (synth_byte_bv_recip n))]
[]
LowParse.Spec.BitVector.synth_byte_bv_inverse
{ "file_name": "src/lowparse/LowParse.Spec.BitVector.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
n: Prims.nat -> FStar.Pervasives.Lemma (ensures LowParse.Spec.Combinators.synth_inverse (LowParse.Spec.BitVector.synth_byte_bv n) (LowParse.Spec.BitVector.synth_byte_bv_recip n)) [ SMTPat (LowParse.Spec.Combinators.synth_inverse (LowParse.Spec.BitVector.synth_byte_bv n) (LowParse.Spec.BitVector.synth_byte_bv_recip n)) ]
{ "end_col": 3, "end_line": 124, "start_col": 2, "start_line": 122 }
FStar.Pervasives.Lemma
val synth_bv_injective (n: nat) : Lemma (synth_injective (synth_bv n)) [SMTPat (synth_injective (synth_bv n))]
[ { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.BitVector", "short_module": "BV" }, { "abbrev": false, "full_module": "FStar.Mul", "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 } ]
false
let synth_bv_injective (n: nat) : Lemma (synth_injective (synth_bv n)) [SMTPat (synth_injective (synth_bv n))] = synth_inverse_intro' (synth_bv_recip n) (synth_bv n) (fun x -> let (hd, tl) = x in let (hd', tl') = synth_bv_recip n (synth_bv n x) in assert (hd `Seq.equal` hd'); assert (tl `Seq.equal` tl') )
val synth_bv_injective (n: nat) : Lemma (synth_injective (synth_bv n)) [SMTPat (synth_injective (synth_bv n))] let synth_bv_injective (n: nat) : Lemma (synth_injective (synth_bv n)) [SMTPat (synth_injective (synth_bv n))] =
false
null
true
synth_inverse_intro' (synth_bv_recip n) (synth_bv n) (fun x -> let hd, tl = x in let hd', tl' = synth_bv_recip n (synth_bv n x) in assert (hd `Seq.equal` hd'); assert (tl `Seq.equal` tl'))
{ "checked_file": "LowParse.Spec.BitVector.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Int.fsti.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.BoundedInt.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "LowParse.Spec.BitVector.fst" }
[ "lemma" ]
[ "Prims.nat", "LowParse.Spec.Combinators.synth_inverse_intro'", "FStar.BitVector.bv_t", "FStar.Pervasives.Native.tuple2", "Prims.op_Modulus", "FStar.Mul.op_Star", "Prims.op_Division", "LowParse.Spec.BitVector.synth_bv_recip", "LowParse.Spec.BitVector.synth_bv", "Prims._assert", "FStar.Seq.Base.equal", "Prims.bool", "Prims.unit", "Prims.op_Multiply", "Prims.l_True", "Prims.squash", "LowParse.Spec.Combinators.synth_injective", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat", "Prims.Nil" ]
[]
module LowParse.Spec.BitVector open FStar.Mul module BV = FStar.BitVector module U8 = FStar.UInt8 module Seq = FStar.Seq (* Big-endian conversion of a bit vector to a UInt8 *) let rec to_uint8 (#n: nat { n <= 8 }) (x: BV.bv_t n) : Tot (y: U8.t { U8.v y < pow2 n }) = if n = 0 then 0uy else let hi = to_uint8 #(n - 1) (Seq.slice x 0 (n - 1)) in let hi' = hi `U8.mul` 2uy in let (r: U8.t { U8.v r < 2 }) = if Seq.index x (n - 1) then 1uy else 0uy in hi' `U8.add` r let rec of_uint8 (n: nat { n <= 8 }) (x: U8.t { U8.v x < pow2 n }) : Tot (BV.bv_t n) = if n = 0 then Seq.empty else let hi = of_uint8 (n - 1) (x `U8.div` 2uy) in Seq.snoc hi (x `U8.rem` 2uy = 1uy) #push-options "--z3rlimit 32" let rec to_uint8_of_uint8 (n: nat { n <= 8 }) (x: U8.t { U8.v x < pow2 n }) : Lemma (to_uint8 (of_uint8 n x) == x) = if n = 0 then () else begin assert (Seq.slice (of_uint8 n x) 0 (n - 1) `Seq.equal` of_uint8 (n - 1) (x `U8.div` 2uy)); to_uint8_of_uint8 (n - 1) (x `U8.div` 2uy) end let rec of_uint8_to_uint8 (#n: nat {n <= 8}) (x: BV.bv_t n) : Lemma (of_uint8 n (to_uint8 x) `Seq.equal` x) = if n = 0 then () else begin let x' = Seq.slice x 0 (n - 1) in of_uint8_to_uint8 #(n - 1) x' ; assert ( U8.v (to_uint8 #(n - 1) x') * 2 == U8.v (to_uint8 x) \/ U8.v (to_uint8 #(n - 1) x') * 2 + 1 == U8.v (to_uint8 x) ); assert (to_uint8 #(n - 1) x' == to_uint8 x `U8.div` 2uy); () end #pop-options (* parse a 8-bit vector *) open LowParse.Spec.Combinators open LowParse.Spec.Int let synth_bv8 (x: U8.t) : Tot (BV.bv_t 8) = of_uint8 8 x let synth_bv8_recip (x: BV.bv_t 8) : Tot U8.t = to_uint8 x let synth_bv8_injective : squash (synth_injective synth_bv8) = synth_inverse_intro' synth_bv8_recip synth_bv8 (fun x -> to_uint8_of_uint8 8 x ) let synth_bv8_inverse : squash (synth_inverse synth_bv8 synth_bv8_recip) = synth_inverse_intro' synth_bv8 synth_bv8_recip (fun x -> of_uint8_to_uint8 x ) let parse_bv8_kind = parse_u8_kind let parse_bv8 : parser parse_bv8_kind (BV.bv_t 8) = parse_u8 `parse_synth` synth_bv8 let serialize_bv8 : serializer parse_bv8 = serialize_synth parse_u8 synth_bv8 serialize_u8 synth_bv8_recip () (* parse a 8*n bit vector *) let synth_byte_bv (n: nat) (x: (BV.bv_t 8 & BV.bv_t (8 * n))) : Tot (BV.bv_t (8 * (1 + n))) = Seq.append (fst x) (snd x) let synth_byte_bv_recip (n: nat) (x: BV.bv_t (8 * (1 + n))) : Tot (BV.bv_t 8 & BV.bv_t (8 * n)) = Seq.slice x 0 8, Seq.slice x 8 (Seq.length x) let synth_byte_bv_injective (n: nat) : Lemma (synth_injective (synth_byte_bv n)) [SMTPat (synth_injective (synth_byte_bv n))] = synth_inverse_intro' (synth_byte_bv_recip n) (synth_byte_bv n) (fun x -> let (hd, tl) = x in let (hd', tl') = synth_byte_bv_recip n (synth_byte_bv n x) in assert (hd `Seq.equal` hd'); assert (tl `Seq.equal` tl') ) let synth_byte_bv_inverse (n: nat) : Lemma (synth_inverse (synth_byte_bv n) (synth_byte_bv_recip n)) [SMTPat (synth_inverse (synth_byte_bv n) (synth_byte_bv_recip n))] = synth_inverse_intro' (synth_byte_bv n) (synth_byte_bv_recip n) (fun x -> assert (synth_byte_bv n (synth_byte_bv_recip n x) `Seq.equal` x) ) let rec parse_byte_bv_kind' (n: nat) : Tot parser_kind = if n = 0 then parse_ret_kind else parse_bv8_kind `and_then_kind` parse_byte_bv_kind' (n - 1) let parse_byte_bv_kind (n: nat) : Tot parser_kind = strong_parser_kind n n (Some ParserKindMetadataTotal) let rec parse_byte_bv_kind_eq (n: nat) : Lemma (parse_byte_bv_kind n == parse_byte_bv_kind' n) = if n = 0 then () else parse_byte_bv_kind_eq (n - 1) let rec parse_byte_bv (n: nat) : Tot (parser (parse_byte_bv_kind n) (BV.bv_t (8 * n))) = parse_byte_bv_kind_eq n; if n = 0 then parse_ret Seq.empty else (parse_bv8 `nondep_then` parse_byte_bv (n - 1)) `parse_synth` synth_byte_bv (n - 1) let rec serialize_byte_bv (n: nat) : Tot (serializer (parse_byte_bv n)) = parse_byte_bv_kind_eq n; if n = 0 then serialize_ret Seq.empty (fun (x: BV.bv_t 0) -> assert (x `Seq.equal` Seq.empty)) else serialize_synth (parse_bv8 `nondep_then` parse_byte_bv (n - 1)) (synth_byte_bv (n - 1)) (serialize_bv8 `serialize_nondep_then` serialize_byte_bv (n - 1)) (synth_byte_bv_recip (n - 1)) () (* parse extra bits (big-endian with the first bits equal to 0) *) let extra_bytes_prop (n: nat) (x: U8.t) : Tot bool = U8.v x < pow2 (n % 8) let synth_extra_bv8 (n: nat) (x: parse_filter_refine (extra_bytes_prop n)) : Tot (BV.bv_t (n % 8)) = of_uint8 (n % 8) x let synth_extra_bv8_recip (n: nat) (x: BV.bv_t (n % 8)) : Tot (parse_filter_refine (extra_bytes_prop n)) = to_uint8 x let synth_extra_bv8_injective (n: nat) : Lemma (synth_injective (synth_extra_bv8 n)) [SMTPat (synth_injective (synth_extra_bv8 n))] = synth_inverse_intro' (synth_extra_bv8_recip n) (synth_extra_bv8 n) (fun x -> to_uint8_of_uint8 (n % 8) x ) let synth_extra_bv8_inverse (n: nat) : Lemma (synth_inverse (synth_extra_bv8 n) (synth_extra_bv8_recip n)) [SMTPat (synth_inverse (synth_extra_bv8 n) (synth_extra_bv8_recip n))] = synth_inverse_intro' (synth_extra_bv8 n) (synth_extra_bv8_recip n) (fun x -> of_uint8_to_uint8 x ) let parse_extra_bv8_kind (n: nat) : Tot parser_kind = parse_filter_kind parse_u8_kind let parse_extra_bv8 (n: nat) : Tot (parser (parse_extra_bv8_kind n) (BV.bv_t (n % 8))) = (parse_u8 `parse_filter` extra_bytes_prop n) `parse_synth` synth_extra_bv8 n let serialize_extra_bv8 (n: nat) : Tot (serializer (parse_extra_bv8 n)) = serialize_synth _ (synth_extra_bv8 n) (serialize_filter serialize_u8 (extra_bytes_prop n)) (synth_extra_bv8_recip n) () (* parse a bitvector, general *) let synth_bv (n: nat) (x: (BV.bv_t (n % 8) & BV.bv_t (8 * (n / 8)))) : Tot (BV.bv_t n) = Seq.append (fst x) (snd x) let synth_bv_recip (n: nat) (x: BV.bv_t n) : Tot (BV.bv_t (n % 8) & BV.bv_t (8 * (n / 8))) = Seq.slice x 0 (n % 8), Seq.slice x (n % 8) (Seq.length x) let synth_bv_injective (n: nat) : Lemma (synth_injective (synth_bv n))
false
false
LowParse.Spec.BitVector.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val synth_bv_injective (n: nat) : Lemma (synth_injective (synth_bv n)) [SMTPat (synth_injective (synth_bv n))]
[]
LowParse.Spec.BitVector.synth_bv_injective
{ "file_name": "src/lowparse/LowParse.Spec.BitVector.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
n: Prims.nat -> FStar.Pervasives.Lemma (ensures LowParse.Spec.Combinators.synth_injective (LowParse.Spec.BitVector.synth_bv n)) [SMTPat (LowParse.Spec.Combinators.synth_injective (LowParse.Spec.BitVector.synth_bv n))]
{ "end_col": 3, "end_line": 216, "start_col": 2, "start_line": 211 }
FStar.Pervasives.Lemma
val synth_extra_bv8_inverse (n: nat) : Lemma (synth_inverse (synth_extra_bv8 n) (synth_extra_bv8_recip n)) [SMTPat (synth_inverse (synth_extra_bv8 n) (synth_extra_bv8_recip n))]
[ { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.BitVector", "short_module": "BV" }, { "abbrev": false, "full_module": "FStar.Mul", "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 } ]
false
let synth_extra_bv8_inverse (n: nat) : Lemma (synth_inverse (synth_extra_bv8 n) (synth_extra_bv8_recip n)) [SMTPat (synth_inverse (synth_extra_bv8 n) (synth_extra_bv8_recip n))] = synth_inverse_intro' (synth_extra_bv8 n) (synth_extra_bv8_recip n) (fun x -> of_uint8_to_uint8 x )
val synth_extra_bv8_inverse (n: nat) : Lemma (synth_inverse (synth_extra_bv8 n) (synth_extra_bv8_recip n)) [SMTPat (synth_inverse (synth_extra_bv8 n) (synth_extra_bv8_recip n))] let synth_extra_bv8_inverse (n: nat) : Lemma (synth_inverse (synth_extra_bv8 n) (synth_extra_bv8_recip n)) [SMTPat (synth_inverse (synth_extra_bv8 n) (synth_extra_bv8_recip n))] =
false
null
true
synth_inverse_intro' (synth_extra_bv8 n) (synth_extra_bv8_recip n) (fun x -> of_uint8_to_uint8 x)
{ "checked_file": "LowParse.Spec.BitVector.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Int.fsti.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.BoundedInt.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "LowParse.Spec.BitVector.fst" }
[ "lemma" ]
[ "Prims.nat", "LowParse.Spec.Combinators.synth_inverse_intro'", "LowParse.Spec.Combinators.parse_filter_refine", "FStar.UInt8.t", "LowParse.Spec.BitVector.extra_bytes_prop", "FStar.BitVector.bv_t", "Prims.op_Modulus", "LowParse.Spec.BitVector.synth_extra_bv8", "LowParse.Spec.BitVector.synth_extra_bv8_recip", "LowParse.Spec.BitVector.of_uint8_to_uint8", "Prims.unit", "Prims.l_True", "Prims.squash", "LowParse.Spec.Combinators.synth_inverse", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat", "Prims.Nil" ]
[]
module LowParse.Spec.BitVector open FStar.Mul module BV = FStar.BitVector module U8 = FStar.UInt8 module Seq = FStar.Seq (* Big-endian conversion of a bit vector to a UInt8 *) let rec to_uint8 (#n: nat { n <= 8 }) (x: BV.bv_t n) : Tot (y: U8.t { U8.v y < pow2 n }) = if n = 0 then 0uy else let hi = to_uint8 #(n - 1) (Seq.slice x 0 (n - 1)) in let hi' = hi `U8.mul` 2uy in let (r: U8.t { U8.v r < 2 }) = if Seq.index x (n - 1) then 1uy else 0uy in hi' `U8.add` r let rec of_uint8 (n: nat { n <= 8 }) (x: U8.t { U8.v x < pow2 n }) : Tot (BV.bv_t n) = if n = 0 then Seq.empty else let hi = of_uint8 (n - 1) (x `U8.div` 2uy) in Seq.snoc hi (x `U8.rem` 2uy = 1uy) #push-options "--z3rlimit 32" let rec to_uint8_of_uint8 (n: nat { n <= 8 }) (x: U8.t { U8.v x < pow2 n }) : Lemma (to_uint8 (of_uint8 n x) == x) = if n = 0 then () else begin assert (Seq.slice (of_uint8 n x) 0 (n - 1) `Seq.equal` of_uint8 (n - 1) (x `U8.div` 2uy)); to_uint8_of_uint8 (n - 1) (x `U8.div` 2uy) end let rec of_uint8_to_uint8 (#n: nat {n <= 8}) (x: BV.bv_t n) : Lemma (of_uint8 n (to_uint8 x) `Seq.equal` x) = if n = 0 then () else begin let x' = Seq.slice x 0 (n - 1) in of_uint8_to_uint8 #(n - 1) x' ; assert ( U8.v (to_uint8 #(n - 1) x') * 2 == U8.v (to_uint8 x) \/ U8.v (to_uint8 #(n - 1) x') * 2 + 1 == U8.v (to_uint8 x) ); assert (to_uint8 #(n - 1) x' == to_uint8 x `U8.div` 2uy); () end #pop-options (* parse a 8-bit vector *) open LowParse.Spec.Combinators open LowParse.Spec.Int let synth_bv8 (x: U8.t) : Tot (BV.bv_t 8) = of_uint8 8 x let synth_bv8_recip (x: BV.bv_t 8) : Tot U8.t = to_uint8 x let synth_bv8_injective : squash (synth_injective synth_bv8) = synth_inverse_intro' synth_bv8_recip synth_bv8 (fun x -> to_uint8_of_uint8 8 x ) let synth_bv8_inverse : squash (synth_inverse synth_bv8 synth_bv8_recip) = synth_inverse_intro' synth_bv8 synth_bv8_recip (fun x -> of_uint8_to_uint8 x ) let parse_bv8_kind = parse_u8_kind let parse_bv8 : parser parse_bv8_kind (BV.bv_t 8) = parse_u8 `parse_synth` synth_bv8 let serialize_bv8 : serializer parse_bv8 = serialize_synth parse_u8 synth_bv8 serialize_u8 synth_bv8_recip () (* parse a 8*n bit vector *) let synth_byte_bv (n: nat) (x: (BV.bv_t 8 & BV.bv_t (8 * n))) : Tot (BV.bv_t (8 * (1 + n))) = Seq.append (fst x) (snd x) let synth_byte_bv_recip (n: nat) (x: BV.bv_t (8 * (1 + n))) : Tot (BV.bv_t 8 & BV.bv_t (8 * n)) = Seq.slice x 0 8, Seq.slice x 8 (Seq.length x) let synth_byte_bv_injective (n: nat) : Lemma (synth_injective (synth_byte_bv n)) [SMTPat (synth_injective (synth_byte_bv n))] = synth_inverse_intro' (synth_byte_bv_recip n) (synth_byte_bv n) (fun x -> let (hd, tl) = x in let (hd', tl') = synth_byte_bv_recip n (synth_byte_bv n x) in assert (hd `Seq.equal` hd'); assert (tl `Seq.equal` tl') ) let synth_byte_bv_inverse (n: nat) : Lemma (synth_inverse (synth_byte_bv n) (synth_byte_bv_recip n)) [SMTPat (synth_inverse (synth_byte_bv n) (synth_byte_bv_recip n))] = synth_inverse_intro' (synth_byte_bv n) (synth_byte_bv_recip n) (fun x -> assert (synth_byte_bv n (synth_byte_bv_recip n x) `Seq.equal` x) ) let rec parse_byte_bv_kind' (n: nat) : Tot parser_kind = if n = 0 then parse_ret_kind else parse_bv8_kind `and_then_kind` parse_byte_bv_kind' (n - 1) let parse_byte_bv_kind (n: nat) : Tot parser_kind = strong_parser_kind n n (Some ParserKindMetadataTotal) let rec parse_byte_bv_kind_eq (n: nat) : Lemma (parse_byte_bv_kind n == parse_byte_bv_kind' n) = if n = 0 then () else parse_byte_bv_kind_eq (n - 1) let rec parse_byte_bv (n: nat) : Tot (parser (parse_byte_bv_kind n) (BV.bv_t (8 * n))) = parse_byte_bv_kind_eq n; if n = 0 then parse_ret Seq.empty else (parse_bv8 `nondep_then` parse_byte_bv (n - 1)) `parse_synth` synth_byte_bv (n - 1) let rec serialize_byte_bv (n: nat) : Tot (serializer (parse_byte_bv n)) = parse_byte_bv_kind_eq n; if n = 0 then serialize_ret Seq.empty (fun (x: BV.bv_t 0) -> assert (x `Seq.equal` Seq.empty)) else serialize_synth (parse_bv8 `nondep_then` parse_byte_bv (n - 1)) (synth_byte_bv (n - 1)) (serialize_bv8 `serialize_nondep_then` serialize_byte_bv (n - 1)) (synth_byte_bv_recip (n - 1)) () (* parse extra bits (big-endian with the first bits equal to 0) *) let extra_bytes_prop (n: nat) (x: U8.t) : Tot bool = U8.v x < pow2 (n % 8) let synth_extra_bv8 (n: nat) (x: parse_filter_refine (extra_bytes_prop n)) : Tot (BV.bv_t (n % 8)) = of_uint8 (n % 8) x let synth_extra_bv8_recip (n: nat) (x: BV.bv_t (n % 8)) : Tot (parse_filter_refine (extra_bytes_prop n)) = to_uint8 x let synth_extra_bv8_injective (n: nat) : Lemma (synth_injective (synth_extra_bv8 n)) [SMTPat (synth_injective (synth_extra_bv8 n))] = synth_inverse_intro' (synth_extra_bv8_recip n) (synth_extra_bv8 n) (fun x -> to_uint8_of_uint8 (n % 8) x ) let synth_extra_bv8_inverse (n: nat) : Lemma (synth_inverse (synth_extra_bv8 n) (synth_extra_bv8_recip n)) [SMTPat (synth_inverse (synth_extra_bv8 n) (synth_extra_bv8_recip n))]
false
false
LowParse.Spec.BitVector.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val synth_extra_bv8_inverse (n: nat) : Lemma (synth_inverse (synth_extra_bv8 n) (synth_extra_bv8_recip n)) [SMTPat (synth_inverse (synth_extra_bv8 n) (synth_extra_bv8_recip n))]
[]
LowParse.Spec.BitVector.synth_extra_bv8_inverse
{ "file_name": "src/lowparse/LowParse.Spec.BitVector.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
n: Prims.nat -> FStar.Pervasives.Lemma (ensures LowParse.Spec.Combinators.synth_inverse (LowParse.Spec.BitVector.synth_extra_bv8 n) (LowParse.Spec.BitVector.synth_extra_bv8_recip n)) [ SMTPat (LowParse.Spec.Combinators.synth_inverse (LowParse.Spec.BitVector.synth_extra_bv8 n) (LowParse.Spec.BitVector.synth_extra_bv8_recip n)) ]
{ "end_col": 3, "end_line": 184, "start_col": 2, "start_line": 182 }
Prims.Tot
val synth_byte_bv (n: nat) (x: (BV.bv_t 8 & BV.bv_t (8 * n))) : Tot (BV.bv_t (8 * (1 + n)))
[ { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.BitVector", "short_module": "BV" }, { "abbrev": false, "full_module": "FStar.Mul", "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 } ]
false
let synth_byte_bv (n: nat) (x: (BV.bv_t 8 & BV.bv_t (8 * n))) : Tot (BV.bv_t (8 * (1 + n))) = Seq.append (fst x) (snd x)
val synth_byte_bv (n: nat) (x: (BV.bv_t 8 & BV.bv_t (8 * n))) : Tot (BV.bv_t (8 * (1 + n))) let synth_byte_bv (n: nat) (x: (BV.bv_t 8 & BV.bv_t (8 * n))) : Tot (BV.bv_t (8 * (1 + n))) =
false
null
false
Seq.append (fst x) (snd x)
{ "checked_file": "LowParse.Spec.BitVector.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Int.fsti.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.BoundedInt.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "LowParse.Spec.BitVector.fst" }
[ "total" ]
[ "Prims.nat", "FStar.Pervasives.Native.tuple2", "FStar.BitVector.bv_t", "FStar.Mul.op_Star", "FStar.Seq.Base.append", "Prims.bool", "FStar.Pervasives.Native.fst", "FStar.Pervasives.Native.snd", "Prims.op_Addition" ]
[]
module LowParse.Spec.BitVector open FStar.Mul module BV = FStar.BitVector module U8 = FStar.UInt8 module Seq = FStar.Seq (* Big-endian conversion of a bit vector to a UInt8 *) let rec to_uint8 (#n: nat { n <= 8 }) (x: BV.bv_t n) : Tot (y: U8.t { U8.v y < pow2 n }) = if n = 0 then 0uy else let hi = to_uint8 #(n - 1) (Seq.slice x 0 (n - 1)) in let hi' = hi `U8.mul` 2uy in let (r: U8.t { U8.v r < 2 }) = if Seq.index x (n - 1) then 1uy else 0uy in hi' `U8.add` r let rec of_uint8 (n: nat { n <= 8 }) (x: U8.t { U8.v x < pow2 n }) : Tot (BV.bv_t n) = if n = 0 then Seq.empty else let hi = of_uint8 (n - 1) (x `U8.div` 2uy) in Seq.snoc hi (x `U8.rem` 2uy = 1uy) #push-options "--z3rlimit 32" let rec to_uint8_of_uint8 (n: nat { n <= 8 }) (x: U8.t { U8.v x < pow2 n }) : Lemma (to_uint8 (of_uint8 n x) == x) = if n = 0 then () else begin assert (Seq.slice (of_uint8 n x) 0 (n - 1) `Seq.equal` of_uint8 (n - 1) (x `U8.div` 2uy)); to_uint8_of_uint8 (n - 1) (x `U8.div` 2uy) end let rec of_uint8_to_uint8 (#n: nat {n <= 8}) (x: BV.bv_t n) : Lemma (of_uint8 n (to_uint8 x) `Seq.equal` x) = if n = 0 then () else begin let x' = Seq.slice x 0 (n - 1) in of_uint8_to_uint8 #(n - 1) x' ; assert ( U8.v (to_uint8 #(n - 1) x') * 2 == U8.v (to_uint8 x) \/ U8.v (to_uint8 #(n - 1) x') * 2 + 1 == U8.v (to_uint8 x) ); assert (to_uint8 #(n - 1) x' == to_uint8 x `U8.div` 2uy); () end #pop-options (* parse a 8-bit vector *) open LowParse.Spec.Combinators open LowParse.Spec.Int let synth_bv8 (x: U8.t) : Tot (BV.bv_t 8) = of_uint8 8 x let synth_bv8_recip (x: BV.bv_t 8) : Tot U8.t = to_uint8 x let synth_bv8_injective : squash (synth_injective synth_bv8) = synth_inverse_intro' synth_bv8_recip synth_bv8 (fun x -> to_uint8_of_uint8 8 x ) let synth_bv8_inverse : squash (synth_inverse synth_bv8 synth_bv8_recip) = synth_inverse_intro' synth_bv8 synth_bv8_recip (fun x -> of_uint8_to_uint8 x ) let parse_bv8_kind = parse_u8_kind let parse_bv8 : parser parse_bv8_kind (BV.bv_t 8) = parse_u8 `parse_synth` synth_bv8 let serialize_bv8 : serializer parse_bv8 = serialize_synth parse_u8 synth_bv8 serialize_u8 synth_bv8_recip () (* parse a 8*n bit vector *)
false
false
LowParse.Spec.BitVector.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val synth_byte_bv (n: nat) (x: (BV.bv_t 8 & BV.bv_t (8 * n))) : Tot (BV.bv_t (8 * (1 + n)))
[]
LowParse.Spec.BitVector.synth_byte_bv
{ "file_name": "src/lowparse/LowParse.Spec.BitVector.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
n: Prims.nat -> x: (FStar.BitVector.bv_t 8 * FStar.BitVector.bv_t (8 * n)) -> FStar.BitVector.bv_t (8 * (1 + n))
{ "end_col": 28, "end_line": 104, "start_col": 2, "start_line": 104 }
Prims.Tot
val serialize_bv (n: nat) : Tot (serializer (parse_bv n))
[ { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.BitVector", "short_module": "BV" }, { "abbrev": false, "full_module": "FStar.Mul", "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 } ]
false
let serialize_bv (n: nat) : Tot (serializer (parse_bv n)) = if n % 8 = 0 then serialize_byte_bv (n / 8) else serialize_synth _ (synth_bv n) (serialize_extra_bv8 n `serialize_nondep_then` serialize_byte_bv (n / 8)) (synth_bv_recip n) ()
val serialize_bv (n: nat) : Tot (serializer (parse_bv n)) let serialize_bv (n: nat) : Tot (serializer (parse_bv n)) =
false
null
false
if n % 8 = 0 then serialize_byte_bv (n / 8) else serialize_synth _ (synth_bv n) ((serialize_extra_bv8 n) `serialize_nondep_then` (serialize_byte_bv (n / 8))) (synth_bv_recip n) ()
{ "checked_file": "LowParse.Spec.BitVector.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Int.fsti.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.BoundedInt.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "LowParse.Spec.BitVector.fst" }
[ "total" ]
[ "Prims.nat", "Prims.op_Equality", "Prims.int", "Prims.op_Modulus", "LowParse.Spec.BitVector.serialize_byte_bv", "Prims.op_Division", "Prims.bool", "LowParse.Spec.Combinators.serialize_synth", "LowParse.Spec.Combinators.and_then_kind", "LowParse.Spec.BitVector.parse_extra_bv8_kind", "LowParse.Spec.BitVector.parse_byte_bv_kind", "FStar.Pervasives.Native.tuple2", "FStar.BitVector.bv_t", "FStar.Mul.op_Star", "LowParse.Spec.Combinators.nondep_then", "LowParse.Spec.BitVector.parse_extra_bv8", "LowParse.Spec.BitVector.parse_byte_bv", "LowParse.Spec.BitVector.synth_bv", "LowParse.Spec.Combinators.serialize_nondep_then", "LowParse.Spec.BitVector.serialize_extra_bv8", "LowParse.Spec.BitVector.synth_bv_recip", "LowParse.Spec.Base.serializer", "LowParse.Spec.BitVector.parse_bv_kind", "LowParse.Spec.BitVector.parse_bv" ]
[]
module LowParse.Spec.BitVector open FStar.Mul module BV = FStar.BitVector module U8 = FStar.UInt8 module Seq = FStar.Seq (* Big-endian conversion of a bit vector to a UInt8 *) let rec to_uint8 (#n: nat { n <= 8 }) (x: BV.bv_t n) : Tot (y: U8.t { U8.v y < pow2 n }) = if n = 0 then 0uy else let hi = to_uint8 #(n - 1) (Seq.slice x 0 (n - 1)) in let hi' = hi `U8.mul` 2uy in let (r: U8.t { U8.v r < 2 }) = if Seq.index x (n - 1) then 1uy else 0uy in hi' `U8.add` r let rec of_uint8 (n: nat { n <= 8 }) (x: U8.t { U8.v x < pow2 n }) : Tot (BV.bv_t n) = if n = 0 then Seq.empty else let hi = of_uint8 (n - 1) (x `U8.div` 2uy) in Seq.snoc hi (x `U8.rem` 2uy = 1uy) #push-options "--z3rlimit 32" let rec to_uint8_of_uint8 (n: nat { n <= 8 }) (x: U8.t { U8.v x < pow2 n }) : Lemma (to_uint8 (of_uint8 n x) == x) = if n = 0 then () else begin assert (Seq.slice (of_uint8 n x) 0 (n - 1) `Seq.equal` of_uint8 (n - 1) (x `U8.div` 2uy)); to_uint8_of_uint8 (n - 1) (x `U8.div` 2uy) end let rec of_uint8_to_uint8 (#n: nat {n <= 8}) (x: BV.bv_t n) : Lemma (of_uint8 n (to_uint8 x) `Seq.equal` x) = if n = 0 then () else begin let x' = Seq.slice x 0 (n - 1) in of_uint8_to_uint8 #(n - 1) x' ; assert ( U8.v (to_uint8 #(n - 1) x') * 2 == U8.v (to_uint8 x) \/ U8.v (to_uint8 #(n - 1) x') * 2 + 1 == U8.v (to_uint8 x) ); assert (to_uint8 #(n - 1) x' == to_uint8 x `U8.div` 2uy); () end #pop-options (* parse a 8-bit vector *) open LowParse.Spec.Combinators open LowParse.Spec.Int let synth_bv8 (x: U8.t) : Tot (BV.bv_t 8) = of_uint8 8 x let synth_bv8_recip (x: BV.bv_t 8) : Tot U8.t = to_uint8 x let synth_bv8_injective : squash (synth_injective synth_bv8) = synth_inverse_intro' synth_bv8_recip synth_bv8 (fun x -> to_uint8_of_uint8 8 x ) let synth_bv8_inverse : squash (synth_inverse synth_bv8 synth_bv8_recip) = synth_inverse_intro' synth_bv8 synth_bv8_recip (fun x -> of_uint8_to_uint8 x ) let parse_bv8_kind = parse_u8_kind let parse_bv8 : parser parse_bv8_kind (BV.bv_t 8) = parse_u8 `parse_synth` synth_bv8 let serialize_bv8 : serializer parse_bv8 = serialize_synth parse_u8 synth_bv8 serialize_u8 synth_bv8_recip () (* parse a 8*n bit vector *) let synth_byte_bv (n: nat) (x: (BV.bv_t 8 & BV.bv_t (8 * n))) : Tot (BV.bv_t (8 * (1 + n))) = Seq.append (fst x) (snd x) let synth_byte_bv_recip (n: nat) (x: BV.bv_t (8 * (1 + n))) : Tot (BV.bv_t 8 & BV.bv_t (8 * n)) = Seq.slice x 0 8, Seq.slice x 8 (Seq.length x) let synth_byte_bv_injective (n: nat) : Lemma (synth_injective (synth_byte_bv n)) [SMTPat (synth_injective (synth_byte_bv n))] = synth_inverse_intro' (synth_byte_bv_recip n) (synth_byte_bv n) (fun x -> let (hd, tl) = x in let (hd', tl') = synth_byte_bv_recip n (synth_byte_bv n x) in assert (hd `Seq.equal` hd'); assert (tl `Seq.equal` tl') ) let synth_byte_bv_inverse (n: nat) : Lemma (synth_inverse (synth_byte_bv n) (synth_byte_bv_recip n)) [SMTPat (synth_inverse (synth_byte_bv n) (synth_byte_bv_recip n))] = synth_inverse_intro' (synth_byte_bv n) (synth_byte_bv_recip n) (fun x -> assert (synth_byte_bv n (synth_byte_bv_recip n x) `Seq.equal` x) ) let rec parse_byte_bv_kind' (n: nat) : Tot parser_kind = if n = 0 then parse_ret_kind else parse_bv8_kind `and_then_kind` parse_byte_bv_kind' (n - 1) let parse_byte_bv_kind (n: nat) : Tot parser_kind = strong_parser_kind n n (Some ParserKindMetadataTotal) let rec parse_byte_bv_kind_eq (n: nat) : Lemma (parse_byte_bv_kind n == parse_byte_bv_kind' n) = if n = 0 then () else parse_byte_bv_kind_eq (n - 1) let rec parse_byte_bv (n: nat) : Tot (parser (parse_byte_bv_kind n) (BV.bv_t (8 * n))) = parse_byte_bv_kind_eq n; if n = 0 then parse_ret Seq.empty else (parse_bv8 `nondep_then` parse_byte_bv (n - 1)) `parse_synth` synth_byte_bv (n - 1) let rec serialize_byte_bv (n: nat) : Tot (serializer (parse_byte_bv n)) = parse_byte_bv_kind_eq n; if n = 0 then serialize_ret Seq.empty (fun (x: BV.bv_t 0) -> assert (x `Seq.equal` Seq.empty)) else serialize_synth (parse_bv8 `nondep_then` parse_byte_bv (n - 1)) (synth_byte_bv (n - 1)) (serialize_bv8 `serialize_nondep_then` serialize_byte_bv (n - 1)) (synth_byte_bv_recip (n - 1)) () (* parse extra bits (big-endian with the first bits equal to 0) *) let extra_bytes_prop (n: nat) (x: U8.t) : Tot bool = U8.v x < pow2 (n % 8) let synth_extra_bv8 (n: nat) (x: parse_filter_refine (extra_bytes_prop n)) : Tot (BV.bv_t (n % 8)) = of_uint8 (n % 8) x let synth_extra_bv8_recip (n: nat) (x: BV.bv_t (n % 8)) : Tot (parse_filter_refine (extra_bytes_prop n)) = to_uint8 x let synth_extra_bv8_injective (n: nat) : Lemma (synth_injective (synth_extra_bv8 n)) [SMTPat (synth_injective (synth_extra_bv8 n))] = synth_inverse_intro' (synth_extra_bv8_recip n) (synth_extra_bv8 n) (fun x -> to_uint8_of_uint8 (n % 8) x ) let synth_extra_bv8_inverse (n: nat) : Lemma (synth_inverse (synth_extra_bv8 n) (synth_extra_bv8_recip n)) [SMTPat (synth_inverse (synth_extra_bv8 n) (synth_extra_bv8_recip n))] = synth_inverse_intro' (synth_extra_bv8 n) (synth_extra_bv8_recip n) (fun x -> of_uint8_to_uint8 x ) let parse_extra_bv8_kind (n: nat) : Tot parser_kind = parse_filter_kind parse_u8_kind let parse_extra_bv8 (n: nat) : Tot (parser (parse_extra_bv8_kind n) (BV.bv_t (n % 8))) = (parse_u8 `parse_filter` extra_bytes_prop n) `parse_synth` synth_extra_bv8 n let serialize_extra_bv8 (n: nat) : Tot (serializer (parse_extra_bv8 n)) = serialize_synth _ (synth_extra_bv8 n) (serialize_filter serialize_u8 (extra_bytes_prop n)) (synth_extra_bv8_recip n) () (* parse a bitvector, general *) let synth_bv (n: nat) (x: (BV.bv_t (n % 8) & BV.bv_t (8 * (n / 8)))) : Tot (BV.bv_t n) = Seq.append (fst x) (snd x) let synth_bv_recip (n: nat) (x: BV.bv_t n) : Tot (BV.bv_t (n % 8) & BV.bv_t (8 * (n / 8))) = Seq.slice x 0 (n % 8), Seq.slice x (n % 8) (Seq.length x) let synth_bv_injective (n: nat) : Lemma (synth_injective (synth_bv n)) [SMTPat (synth_injective (synth_bv n))] = synth_inverse_intro' (synth_bv_recip n) (synth_bv n) (fun x -> let (hd, tl) = x in let (hd', tl') = synth_bv_recip n (synth_bv n x) in assert (hd `Seq.equal` hd'); assert (tl `Seq.equal` tl') ) let synth_bv_inverse (n: nat) : Lemma (synth_inverse (synth_bv n) (synth_bv_recip n)) [SMTPat (synth_inverse (synth_bv n) (synth_bv_recip n))] = synth_inverse_intro' (synth_bv n) (synth_bv_recip n) (fun x -> assert (synth_bv n (synth_bv_recip n x) `Seq.equal` x) ) let parse_bv_kind (n: nat) : Tot parser_kind = if n % 8 = 0 then strong_parser_kind (n / 8) (n / 8) (Some ParserKindMetadataTotal) else strong_parser_kind (1 + n / 8) (1 + n / 8) None let parse_bv (n: nat) : Tot (parser (parse_bv_kind n) (BV.bv_t n)) = if n % 8 = 0 then parse_byte_bv (n / 8) else ((parse_extra_bv8 n `nondep_then` parse_byte_bv (n / 8)) `parse_synth` synth_bv n)
false
false
LowParse.Spec.BitVector.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val serialize_bv (n: nat) : Tot (serializer (parse_bv n))
[]
LowParse.Spec.BitVector.serialize_bv
{ "file_name": "src/lowparse/LowParse.Spec.BitVector.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
n: Prims.nat -> LowParse.Spec.Base.serializer (LowParse.Spec.BitVector.parse_bv n)
{ "end_col": 8, "end_line": 242, "start_col": 2, "start_line": 234 }
Prims.Tot
val synth_byte_bv_recip (n: nat) (x: BV.bv_t (8 * (1 + n))) : Tot (BV.bv_t 8 & BV.bv_t (8 * n))
[ { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.BitVector", "short_module": "BV" }, { "abbrev": false, "full_module": "FStar.Mul", "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 } ]
false
let synth_byte_bv_recip (n: nat) (x: BV.bv_t (8 * (1 + n))) : Tot (BV.bv_t 8 & BV.bv_t (8 * n)) = Seq.slice x 0 8, Seq.slice x 8 (Seq.length x)
val synth_byte_bv_recip (n: nat) (x: BV.bv_t (8 * (1 + n))) : Tot (BV.bv_t 8 & BV.bv_t (8 * n)) let synth_byte_bv_recip (n: nat) (x: BV.bv_t (8 * (1 + n))) : Tot (BV.bv_t 8 & BV.bv_t (8 * n)) =
false
null
false
Seq.slice x 0 8, Seq.slice x 8 (Seq.length x)
{ "checked_file": "LowParse.Spec.BitVector.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Int.fsti.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.BoundedInt.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "LowParse.Spec.BitVector.fst" }
[ "total" ]
[ "Prims.nat", "FStar.BitVector.bv_t", "FStar.Mul.op_Star", "Prims.op_Addition", "FStar.Pervasives.Native.Mktuple2", "FStar.Seq.Base.slice", "Prims.bool", "FStar.Seq.Base.length", "FStar.Pervasives.Native.tuple2" ]
[]
module LowParse.Spec.BitVector open FStar.Mul module BV = FStar.BitVector module U8 = FStar.UInt8 module Seq = FStar.Seq (* Big-endian conversion of a bit vector to a UInt8 *) let rec to_uint8 (#n: nat { n <= 8 }) (x: BV.bv_t n) : Tot (y: U8.t { U8.v y < pow2 n }) = if n = 0 then 0uy else let hi = to_uint8 #(n - 1) (Seq.slice x 0 (n - 1)) in let hi' = hi `U8.mul` 2uy in let (r: U8.t { U8.v r < 2 }) = if Seq.index x (n - 1) then 1uy else 0uy in hi' `U8.add` r let rec of_uint8 (n: nat { n <= 8 }) (x: U8.t { U8.v x < pow2 n }) : Tot (BV.bv_t n) = if n = 0 then Seq.empty else let hi = of_uint8 (n - 1) (x `U8.div` 2uy) in Seq.snoc hi (x `U8.rem` 2uy = 1uy) #push-options "--z3rlimit 32" let rec to_uint8_of_uint8 (n: nat { n <= 8 }) (x: U8.t { U8.v x < pow2 n }) : Lemma (to_uint8 (of_uint8 n x) == x) = if n = 0 then () else begin assert (Seq.slice (of_uint8 n x) 0 (n - 1) `Seq.equal` of_uint8 (n - 1) (x `U8.div` 2uy)); to_uint8_of_uint8 (n - 1) (x `U8.div` 2uy) end let rec of_uint8_to_uint8 (#n: nat {n <= 8}) (x: BV.bv_t n) : Lemma (of_uint8 n (to_uint8 x) `Seq.equal` x) = if n = 0 then () else begin let x' = Seq.slice x 0 (n - 1) in of_uint8_to_uint8 #(n - 1) x' ; assert ( U8.v (to_uint8 #(n - 1) x') * 2 == U8.v (to_uint8 x) \/ U8.v (to_uint8 #(n - 1) x') * 2 + 1 == U8.v (to_uint8 x) ); assert (to_uint8 #(n - 1) x' == to_uint8 x `U8.div` 2uy); () end #pop-options (* parse a 8-bit vector *) open LowParse.Spec.Combinators open LowParse.Spec.Int let synth_bv8 (x: U8.t) : Tot (BV.bv_t 8) = of_uint8 8 x let synth_bv8_recip (x: BV.bv_t 8) : Tot U8.t = to_uint8 x let synth_bv8_injective : squash (synth_injective synth_bv8) = synth_inverse_intro' synth_bv8_recip synth_bv8 (fun x -> to_uint8_of_uint8 8 x ) let synth_bv8_inverse : squash (synth_inverse synth_bv8 synth_bv8_recip) = synth_inverse_intro' synth_bv8 synth_bv8_recip (fun x -> of_uint8_to_uint8 x ) let parse_bv8_kind = parse_u8_kind let parse_bv8 : parser parse_bv8_kind (BV.bv_t 8) = parse_u8 `parse_synth` synth_bv8 let serialize_bv8 : serializer parse_bv8 = serialize_synth parse_u8 synth_bv8 serialize_u8 synth_bv8_recip () (* parse a 8*n bit vector *) let synth_byte_bv (n: nat) (x: (BV.bv_t 8 & BV.bv_t (8 * n))) : Tot (BV.bv_t (8 * (1 + n))) = Seq.append (fst x) (snd x)
false
false
LowParse.Spec.BitVector.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val synth_byte_bv_recip (n: nat) (x: BV.bv_t (8 * (1 + n))) : Tot (BV.bv_t 8 & BV.bv_t (8 * n))
[]
LowParse.Spec.BitVector.synth_byte_bv_recip
{ "file_name": "src/lowparse/LowParse.Spec.BitVector.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
n: Prims.nat -> x: FStar.BitVector.bv_t (8 * (1 + n)) -> FStar.BitVector.bv_t 8 * FStar.BitVector.bv_t (8 * n)
{ "end_col": 47, "end_line": 107, "start_col": 2, "start_line": 107 }
FStar.Pervasives.Lemma
val synth_bv_inverse (n: nat) : Lemma (synth_inverse (synth_bv n) (synth_bv_recip n)) [SMTPat (synth_inverse (synth_bv n) (synth_bv_recip n))]
[ { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.BitVector", "short_module": "BV" }, { "abbrev": false, "full_module": "FStar.Mul", "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 } ]
false
let synth_bv_inverse (n: nat) : Lemma (synth_inverse (synth_bv n) (synth_bv_recip n)) [SMTPat (synth_inverse (synth_bv n) (synth_bv_recip n))] = synth_inverse_intro' (synth_bv n) (synth_bv_recip n) (fun x -> assert (synth_bv n (synth_bv_recip n x) `Seq.equal` x) )
val synth_bv_inverse (n: nat) : Lemma (synth_inverse (synth_bv n) (synth_bv_recip n)) [SMTPat (synth_inverse (synth_bv n) (synth_bv_recip n))] let synth_bv_inverse (n: nat) : Lemma (synth_inverse (synth_bv n) (synth_bv_recip n)) [SMTPat (synth_inverse (synth_bv n) (synth_bv_recip n))] =
false
null
true
synth_inverse_intro' (synth_bv n) (synth_bv_recip n) (fun x -> assert ((synth_bv n (synth_bv_recip n x)) `Seq.equal` x))
{ "checked_file": "LowParse.Spec.BitVector.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Int.fsti.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.BoundedInt.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "LowParse.Spec.BitVector.fst" }
[ "lemma" ]
[ "Prims.nat", "LowParse.Spec.Combinators.synth_inverse_intro'", "FStar.Pervasives.Native.tuple2", "FStar.BitVector.bv_t", "Prims.op_Modulus", "FStar.Mul.op_Star", "Prims.op_Division", "FStar.Seq.Base.seq", "Prims.bool", "Prims.b2t", "Prims.op_Equality", "FStar.Seq.Base.length", "LowParse.Spec.BitVector.synth_bv", "LowParse.Spec.BitVector.synth_bv_recip", "Prims._assert", "FStar.Seq.Base.equal", "Prims.unit", "Prims.l_True", "Prims.squash", "LowParse.Spec.Combinators.synth_inverse", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat", "Prims.Nil" ]
[]
module LowParse.Spec.BitVector open FStar.Mul module BV = FStar.BitVector module U8 = FStar.UInt8 module Seq = FStar.Seq (* Big-endian conversion of a bit vector to a UInt8 *) let rec to_uint8 (#n: nat { n <= 8 }) (x: BV.bv_t n) : Tot (y: U8.t { U8.v y < pow2 n }) = if n = 0 then 0uy else let hi = to_uint8 #(n - 1) (Seq.slice x 0 (n - 1)) in let hi' = hi `U8.mul` 2uy in let (r: U8.t { U8.v r < 2 }) = if Seq.index x (n - 1) then 1uy else 0uy in hi' `U8.add` r let rec of_uint8 (n: nat { n <= 8 }) (x: U8.t { U8.v x < pow2 n }) : Tot (BV.bv_t n) = if n = 0 then Seq.empty else let hi = of_uint8 (n - 1) (x `U8.div` 2uy) in Seq.snoc hi (x `U8.rem` 2uy = 1uy) #push-options "--z3rlimit 32" let rec to_uint8_of_uint8 (n: nat { n <= 8 }) (x: U8.t { U8.v x < pow2 n }) : Lemma (to_uint8 (of_uint8 n x) == x) = if n = 0 then () else begin assert (Seq.slice (of_uint8 n x) 0 (n - 1) `Seq.equal` of_uint8 (n - 1) (x `U8.div` 2uy)); to_uint8_of_uint8 (n - 1) (x `U8.div` 2uy) end let rec of_uint8_to_uint8 (#n: nat {n <= 8}) (x: BV.bv_t n) : Lemma (of_uint8 n (to_uint8 x) `Seq.equal` x) = if n = 0 then () else begin let x' = Seq.slice x 0 (n - 1) in of_uint8_to_uint8 #(n - 1) x' ; assert ( U8.v (to_uint8 #(n - 1) x') * 2 == U8.v (to_uint8 x) \/ U8.v (to_uint8 #(n - 1) x') * 2 + 1 == U8.v (to_uint8 x) ); assert (to_uint8 #(n - 1) x' == to_uint8 x `U8.div` 2uy); () end #pop-options (* parse a 8-bit vector *) open LowParse.Spec.Combinators open LowParse.Spec.Int let synth_bv8 (x: U8.t) : Tot (BV.bv_t 8) = of_uint8 8 x let synth_bv8_recip (x: BV.bv_t 8) : Tot U8.t = to_uint8 x let synth_bv8_injective : squash (synth_injective synth_bv8) = synth_inverse_intro' synth_bv8_recip synth_bv8 (fun x -> to_uint8_of_uint8 8 x ) let synth_bv8_inverse : squash (synth_inverse synth_bv8 synth_bv8_recip) = synth_inverse_intro' synth_bv8 synth_bv8_recip (fun x -> of_uint8_to_uint8 x ) let parse_bv8_kind = parse_u8_kind let parse_bv8 : parser parse_bv8_kind (BV.bv_t 8) = parse_u8 `parse_synth` synth_bv8 let serialize_bv8 : serializer parse_bv8 = serialize_synth parse_u8 synth_bv8 serialize_u8 synth_bv8_recip () (* parse a 8*n bit vector *) let synth_byte_bv (n: nat) (x: (BV.bv_t 8 & BV.bv_t (8 * n))) : Tot (BV.bv_t (8 * (1 + n))) = Seq.append (fst x) (snd x) let synth_byte_bv_recip (n: nat) (x: BV.bv_t (8 * (1 + n))) : Tot (BV.bv_t 8 & BV.bv_t (8 * n)) = Seq.slice x 0 8, Seq.slice x 8 (Seq.length x) let synth_byte_bv_injective (n: nat) : Lemma (synth_injective (synth_byte_bv n)) [SMTPat (synth_injective (synth_byte_bv n))] = synth_inverse_intro' (synth_byte_bv_recip n) (synth_byte_bv n) (fun x -> let (hd, tl) = x in let (hd', tl') = synth_byte_bv_recip n (synth_byte_bv n x) in assert (hd `Seq.equal` hd'); assert (tl `Seq.equal` tl') ) let synth_byte_bv_inverse (n: nat) : Lemma (synth_inverse (synth_byte_bv n) (synth_byte_bv_recip n)) [SMTPat (synth_inverse (synth_byte_bv n) (synth_byte_bv_recip n))] = synth_inverse_intro' (synth_byte_bv n) (synth_byte_bv_recip n) (fun x -> assert (synth_byte_bv n (synth_byte_bv_recip n x) `Seq.equal` x) ) let rec parse_byte_bv_kind' (n: nat) : Tot parser_kind = if n = 0 then parse_ret_kind else parse_bv8_kind `and_then_kind` parse_byte_bv_kind' (n - 1) let parse_byte_bv_kind (n: nat) : Tot parser_kind = strong_parser_kind n n (Some ParserKindMetadataTotal) let rec parse_byte_bv_kind_eq (n: nat) : Lemma (parse_byte_bv_kind n == parse_byte_bv_kind' n) = if n = 0 then () else parse_byte_bv_kind_eq (n - 1) let rec parse_byte_bv (n: nat) : Tot (parser (parse_byte_bv_kind n) (BV.bv_t (8 * n))) = parse_byte_bv_kind_eq n; if n = 0 then parse_ret Seq.empty else (parse_bv8 `nondep_then` parse_byte_bv (n - 1)) `parse_synth` synth_byte_bv (n - 1) let rec serialize_byte_bv (n: nat) : Tot (serializer (parse_byte_bv n)) = parse_byte_bv_kind_eq n; if n = 0 then serialize_ret Seq.empty (fun (x: BV.bv_t 0) -> assert (x `Seq.equal` Seq.empty)) else serialize_synth (parse_bv8 `nondep_then` parse_byte_bv (n - 1)) (synth_byte_bv (n - 1)) (serialize_bv8 `serialize_nondep_then` serialize_byte_bv (n - 1)) (synth_byte_bv_recip (n - 1)) () (* parse extra bits (big-endian with the first bits equal to 0) *) let extra_bytes_prop (n: nat) (x: U8.t) : Tot bool = U8.v x < pow2 (n % 8) let synth_extra_bv8 (n: nat) (x: parse_filter_refine (extra_bytes_prop n)) : Tot (BV.bv_t (n % 8)) = of_uint8 (n % 8) x let synth_extra_bv8_recip (n: nat) (x: BV.bv_t (n % 8)) : Tot (parse_filter_refine (extra_bytes_prop n)) = to_uint8 x let synth_extra_bv8_injective (n: nat) : Lemma (synth_injective (synth_extra_bv8 n)) [SMTPat (synth_injective (synth_extra_bv8 n))] = synth_inverse_intro' (synth_extra_bv8_recip n) (synth_extra_bv8 n) (fun x -> to_uint8_of_uint8 (n % 8) x ) let synth_extra_bv8_inverse (n: nat) : Lemma (synth_inverse (synth_extra_bv8 n) (synth_extra_bv8_recip n)) [SMTPat (synth_inverse (synth_extra_bv8 n) (synth_extra_bv8_recip n))] = synth_inverse_intro' (synth_extra_bv8 n) (synth_extra_bv8_recip n) (fun x -> of_uint8_to_uint8 x ) let parse_extra_bv8_kind (n: nat) : Tot parser_kind = parse_filter_kind parse_u8_kind let parse_extra_bv8 (n: nat) : Tot (parser (parse_extra_bv8_kind n) (BV.bv_t (n % 8))) = (parse_u8 `parse_filter` extra_bytes_prop n) `parse_synth` synth_extra_bv8 n let serialize_extra_bv8 (n: nat) : Tot (serializer (parse_extra_bv8 n)) = serialize_synth _ (synth_extra_bv8 n) (serialize_filter serialize_u8 (extra_bytes_prop n)) (synth_extra_bv8_recip n) () (* parse a bitvector, general *) let synth_bv (n: nat) (x: (BV.bv_t (n % 8) & BV.bv_t (8 * (n / 8)))) : Tot (BV.bv_t n) = Seq.append (fst x) (snd x) let synth_bv_recip (n: nat) (x: BV.bv_t n) : Tot (BV.bv_t (n % 8) & BV.bv_t (8 * (n / 8))) = Seq.slice x 0 (n % 8), Seq.slice x (n % 8) (Seq.length x) let synth_bv_injective (n: nat) : Lemma (synth_injective (synth_bv n)) [SMTPat (synth_injective (synth_bv n))] = synth_inverse_intro' (synth_bv_recip n) (synth_bv n) (fun x -> let (hd, tl) = x in let (hd', tl') = synth_bv_recip n (synth_bv n x) in assert (hd `Seq.equal` hd'); assert (tl `Seq.equal` tl') ) let synth_bv_inverse (n: nat) : Lemma (synth_inverse (synth_bv n) (synth_bv_recip n))
false
false
LowParse.Spec.BitVector.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val synth_bv_inverse (n: nat) : Lemma (synth_inverse (synth_bv n) (synth_bv_recip n)) [SMTPat (synth_inverse (synth_bv n) (synth_bv_recip n))]
[]
LowParse.Spec.BitVector.synth_bv_inverse
{ "file_name": "src/lowparse/LowParse.Spec.BitVector.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
n: Prims.nat -> FStar.Pervasives.Lemma (ensures LowParse.Spec.Combinators.synth_inverse (LowParse.Spec.BitVector.synth_bv n) (LowParse.Spec.BitVector.synth_bv_recip n)) [ SMTPat (LowParse.Spec.Combinators.synth_inverse (LowParse.Spec.BitVector.synth_bv n) (LowParse.Spec.BitVector.synth_bv_recip n)) ]
{ "end_col": 3, "end_line": 223, "start_col": 2, "start_line": 221 }
Prims.Tot
val parse_byte_bv (n: nat) : Tot (parser (parse_byte_bv_kind n) (BV.bv_t (8 * n)))
[ { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.BitVector", "short_module": "BV" }, { "abbrev": false, "full_module": "FStar.Mul", "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 } ]
false
let rec parse_byte_bv (n: nat) : Tot (parser (parse_byte_bv_kind n) (BV.bv_t (8 * n))) = parse_byte_bv_kind_eq n; if n = 0 then parse_ret Seq.empty else (parse_bv8 `nondep_then` parse_byte_bv (n - 1)) `parse_synth` synth_byte_bv (n - 1)
val parse_byte_bv (n: nat) : Tot (parser (parse_byte_bv_kind n) (BV.bv_t (8 * n))) let rec parse_byte_bv (n: nat) : Tot (parser (parse_byte_bv_kind n) (BV.bv_t (8 * n))) =
false
null
false
parse_byte_bv_kind_eq n; if n = 0 then parse_ret Seq.empty else (parse_bv8 `nondep_then` (parse_byte_bv (n - 1))) `parse_synth` (synth_byte_bv (n - 1))
{ "checked_file": "LowParse.Spec.BitVector.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Int.fsti.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.BoundedInt.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "LowParse.Spec.BitVector.fst" }
[ "total" ]
[ "Prims.nat", "Prims.op_Equality", "Prims.int", "LowParse.Spec.Combinators.parse_ret", "FStar.BitVector.bv_t", "FStar.Mul.op_Star", "FStar.Seq.Base.empty", "Prims.bool", "LowParse.Spec.Combinators.parse_synth", "LowParse.Spec.Combinators.and_then_kind", "LowParse.Spec.BitVector.parse_bv8_kind", "LowParse.Spec.BitVector.parse_byte_bv_kind", "Prims.op_Subtraction", "FStar.Pervasives.Native.tuple2", "LowParse.Spec.Combinators.nondep_then", "LowParse.Spec.BitVector.parse_bv8", "LowParse.Spec.BitVector.parse_byte_bv", "LowParse.Spec.BitVector.synth_byte_bv", "LowParse.Spec.Base.parser", "Prims.unit", "LowParse.Spec.BitVector.parse_byte_bv_kind_eq" ]
[]
module LowParse.Spec.BitVector open FStar.Mul module BV = FStar.BitVector module U8 = FStar.UInt8 module Seq = FStar.Seq (* Big-endian conversion of a bit vector to a UInt8 *) let rec to_uint8 (#n: nat { n <= 8 }) (x: BV.bv_t n) : Tot (y: U8.t { U8.v y < pow2 n }) = if n = 0 then 0uy else let hi = to_uint8 #(n - 1) (Seq.slice x 0 (n - 1)) in let hi' = hi `U8.mul` 2uy in let (r: U8.t { U8.v r < 2 }) = if Seq.index x (n - 1) then 1uy else 0uy in hi' `U8.add` r let rec of_uint8 (n: nat { n <= 8 }) (x: U8.t { U8.v x < pow2 n }) : Tot (BV.bv_t n) = if n = 0 then Seq.empty else let hi = of_uint8 (n - 1) (x `U8.div` 2uy) in Seq.snoc hi (x `U8.rem` 2uy = 1uy) #push-options "--z3rlimit 32" let rec to_uint8_of_uint8 (n: nat { n <= 8 }) (x: U8.t { U8.v x < pow2 n }) : Lemma (to_uint8 (of_uint8 n x) == x) = if n = 0 then () else begin assert (Seq.slice (of_uint8 n x) 0 (n - 1) `Seq.equal` of_uint8 (n - 1) (x `U8.div` 2uy)); to_uint8_of_uint8 (n - 1) (x `U8.div` 2uy) end let rec of_uint8_to_uint8 (#n: nat {n <= 8}) (x: BV.bv_t n) : Lemma (of_uint8 n (to_uint8 x) `Seq.equal` x) = if n = 0 then () else begin let x' = Seq.slice x 0 (n - 1) in of_uint8_to_uint8 #(n - 1) x' ; assert ( U8.v (to_uint8 #(n - 1) x') * 2 == U8.v (to_uint8 x) \/ U8.v (to_uint8 #(n - 1) x') * 2 + 1 == U8.v (to_uint8 x) ); assert (to_uint8 #(n - 1) x' == to_uint8 x `U8.div` 2uy); () end #pop-options (* parse a 8-bit vector *) open LowParse.Spec.Combinators open LowParse.Spec.Int let synth_bv8 (x: U8.t) : Tot (BV.bv_t 8) = of_uint8 8 x let synth_bv8_recip (x: BV.bv_t 8) : Tot U8.t = to_uint8 x let synth_bv8_injective : squash (synth_injective synth_bv8) = synth_inverse_intro' synth_bv8_recip synth_bv8 (fun x -> to_uint8_of_uint8 8 x ) let synth_bv8_inverse : squash (synth_inverse synth_bv8 synth_bv8_recip) = synth_inverse_intro' synth_bv8 synth_bv8_recip (fun x -> of_uint8_to_uint8 x ) let parse_bv8_kind = parse_u8_kind let parse_bv8 : parser parse_bv8_kind (BV.bv_t 8) = parse_u8 `parse_synth` synth_bv8 let serialize_bv8 : serializer parse_bv8 = serialize_synth parse_u8 synth_bv8 serialize_u8 synth_bv8_recip () (* parse a 8*n bit vector *) let synth_byte_bv (n: nat) (x: (BV.bv_t 8 & BV.bv_t (8 * n))) : Tot (BV.bv_t (8 * (1 + n))) = Seq.append (fst x) (snd x) let synth_byte_bv_recip (n: nat) (x: BV.bv_t (8 * (1 + n))) : Tot (BV.bv_t 8 & BV.bv_t (8 * n)) = Seq.slice x 0 8, Seq.slice x 8 (Seq.length x) let synth_byte_bv_injective (n: nat) : Lemma (synth_injective (synth_byte_bv n)) [SMTPat (synth_injective (synth_byte_bv n))] = synth_inverse_intro' (synth_byte_bv_recip n) (synth_byte_bv n) (fun x -> let (hd, tl) = x in let (hd', tl') = synth_byte_bv_recip n (synth_byte_bv n x) in assert (hd `Seq.equal` hd'); assert (tl `Seq.equal` tl') ) let synth_byte_bv_inverse (n: nat) : Lemma (synth_inverse (synth_byte_bv n) (synth_byte_bv_recip n)) [SMTPat (synth_inverse (synth_byte_bv n) (synth_byte_bv_recip n))] = synth_inverse_intro' (synth_byte_bv n) (synth_byte_bv_recip n) (fun x -> assert (synth_byte_bv n (synth_byte_bv_recip n x) `Seq.equal` x) ) let rec parse_byte_bv_kind' (n: nat) : Tot parser_kind = if n = 0 then parse_ret_kind else parse_bv8_kind `and_then_kind` parse_byte_bv_kind' (n - 1) let parse_byte_bv_kind (n: nat) : Tot parser_kind = strong_parser_kind n n (Some ParserKindMetadataTotal) let rec parse_byte_bv_kind_eq (n: nat) : Lemma (parse_byte_bv_kind n == parse_byte_bv_kind' n) = if n = 0 then () else parse_byte_bv_kind_eq (n - 1)
false
false
LowParse.Spec.BitVector.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val parse_byte_bv (n: nat) : Tot (parser (parse_byte_bv_kind n) (BV.bv_t (8 * n)))
[ "recursion" ]
LowParse.Spec.BitVector.parse_byte_bv
{ "file_name": "src/lowparse/LowParse.Spec.BitVector.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
n: Prims.nat -> LowParse.Spec.Base.parser (LowParse.Spec.BitVector.parse_byte_bv_kind n) (FStar.BitVector.bv_t (8 * n))
{ "end_col": 87, "end_line": 146, "start_col": 2, "start_line": 141 }
Prims.Tot
val synth_extra_bv8_recip (n: nat) (x: BV.bv_t (n % 8)) : Tot (parse_filter_refine (extra_bytes_prop n))
[ { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.BitVector", "short_module": "BV" }, { "abbrev": false, "full_module": "FStar.Mul", "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 } ]
false
let synth_extra_bv8_recip (n: nat) (x: BV.bv_t (n % 8)) : Tot (parse_filter_refine (extra_bytes_prop n)) = to_uint8 x
val synth_extra_bv8_recip (n: nat) (x: BV.bv_t (n % 8)) : Tot (parse_filter_refine (extra_bytes_prop n)) let synth_extra_bv8_recip (n: nat) (x: BV.bv_t (n % 8)) : Tot (parse_filter_refine (extra_bytes_prop n)) =
false
null
false
to_uint8 x
{ "checked_file": "LowParse.Spec.BitVector.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Int.fsti.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.BoundedInt.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "LowParse.Spec.BitVector.fst" }
[ "total" ]
[ "Prims.nat", "FStar.BitVector.bv_t", "Prims.op_Modulus", "LowParse.Spec.BitVector.to_uint8", "LowParse.Spec.Combinators.parse_filter_refine", "FStar.UInt8.t", "LowParse.Spec.BitVector.extra_bytes_prop" ]
[]
module LowParse.Spec.BitVector open FStar.Mul module BV = FStar.BitVector module U8 = FStar.UInt8 module Seq = FStar.Seq (* Big-endian conversion of a bit vector to a UInt8 *) let rec to_uint8 (#n: nat { n <= 8 }) (x: BV.bv_t n) : Tot (y: U8.t { U8.v y < pow2 n }) = if n = 0 then 0uy else let hi = to_uint8 #(n - 1) (Seq.slice x 0 (n - 1)) in let hi' = hi `U8.mul` 2uy in let (r: U8.t { U8.v r < 2 }) = if Seq.index x (n - 1) then 1uy else 0uy in hi' `U8.add` r let rec of_uint8 (n: nat { n <= 8 }) (x: U8.t { U8.v x < pow2 n }) : Tot (BV.bv_t n) = if n = 0 then Seq.empty else let hi = of_uint8 (n - 1) (x `U8.div` 2uy) in Seq.snoc hi (x `U8.rem` 2uy = 1uy) #push-options "--z3rlimit 32" let rec to_uint8_of_uint8 (n: nat { n <= 8 }) (x: U8.t { U8.v x < pow2 n }) : Lemma (to_uint8 (of_uint8 n x) == x) = if n = 0 then () else begin assert (Seq.slice (of_uint8 n x) 0 (n - 1) `Seq.equal` of_uint8 (n - 1) (x `U8.div` 2uy)); to_uint8_of_uint8 (n - 1) (x `U8.div` 2uy) end let rec of_uint8_to_uint8 (#n: nat {n <= 8}) (x: BV.bv_t n) : Lemma (of_uint8 n (to_uint8 x) `Seq.equal` x) = if n = 0 then () else begin let x' = Seq.slice x 0 (n - 1) in of_uint8_to_uint8 #(n - 1) x' ; assert ( U8.v (to_uint8 #(n - 1) x') * 2 == U8.v (to_uint8 x) \/ U8.v (to_uint8 #(n - 1) x') * 2 + 1 == U8.v (to_uint8 x) ); assert (to_uint8 #(n - 1) x' == to_uint8 x `U8.div` 2uy); () end #pop-options (* parse a 8-bit vector *) open LowParse.Spec.Combinators open LowParse.Spec.Int let synth_bv8 (x: U8.t) : Tot (BV.bv_t 8) = of_uint8 8 x let synth_bv8_recip (x: BV.bv_t 8) : Tot U8.t = to_uint8 x let synth_bv8_injective : squash (synth_injective synth_bv8) = synth_inverse_intro' synth_bv8_recip synth_bv8 (fun x -> to_uint8_of_uint8 8 x ) let synth_bv8_inverse : squash (synth_inverse synth_bv8 synth_bv8_recip) = synth_inverse_intro' synth_bv8 synth_bv8_recip (fun x -> of_uint8_to_uint8 x ) let parse_bv8_kind = parse_u8_kind let parse_bv8 : parser parse_bv8_kind (BV.bv_t 8) = parse_u8 `parse_synth` synth_bv8 let serialize_bv8 : serializer parse_bv8 = serialize_synth parse_u8 synth_bv8 serialize_u8 synth_bv8_recip () (* parse a 8*n bit vector *) let synth_byte_bv (n: nat) (x: (BV.bv_t 8 & BV.bv_t (8 * n))) : Tot (BV.bv_t (8 * (1 + n))) = Seq.append (fst x) (snd x) let synth_byte_bv_recip (n: nat) (x: BV.bv_t (8 * (1 + n))) : Tot (BV.bv_t 8 & BV.bv_t (8 * n)) = Seq.slice x 0 8, Seq.slice x 8 (Seq.length x) let synth_byte_bv_injective (n: nat) : Lemma (synth_injective (synth_byte_bv n)) [SMTPat (synth_injective (synth_byte_bv n))] = synth_inverse_intro' (synth_byte_bv_recip n) (synth_byte_bv n) (fun x -> let (hd, tl) = x in let (hd', tl') = synth_byte_bv_recip n (synth_byte_bv n x) in assert (hd `Seq.equal` hd'); assert (tl `Seq.equal` tl') ) let synth_byte_bv_inverse (n: nat) : Lemma (synth_inverse (synth_byte_bv n) (synth_byte_bv_recip n)) [SMTPat (synth_inverse (synth_byte_bv n) (synth_byte_bv_recip n))] = synth_inverse_intro' (synth_byte_bv n) (synth_byte_bv_recip n) (fun x -> assert (synth_byte_bv n (synth_byte_bv_recip n x) `Seq.equal` x) ) let rec parse_byte_bv_kind' (n: nat) : Tot parser_kind = if n = 0 then parse_ret_kind else parse_bv8_kind `and_then_kind` parse_byte_bv_kind' (n - 1) let parse_byte_bv_kind (n: nat) : Tot parser_kind = strong_parser_kind n n (Some ParserKindMetadataTotal) let rec parse_byte_bv_kind_eq (n: nat) : Lemma (parse_byte_bv_kind n == parse_byte_bv_kind' n) = if n = 0 then () else parse_byte_bv_kind_eq (n - 1) let rec parse_byte_bv (n: nat) : Tot (parser (parse_byte_bv_kind n) (BV.bv_t (8 * n))) = parse_byte_bv_kind_eq n; if n = 0 then parse_ret Seq.empty else (parse_bv8 `nondep_then` parse_byte_bv (n - 1)) `parse_synth` synth_byte_bv (n - 1) let rec serialize_byte_bv (n: nat) : Tot (serializer (parse_byte_bv n)) = parse_byte_bv_kind_eq n; if n = 0 then serialize_ret Seq.empty (fun (x: BV.bv_t 0) -> assert (x `Seq.equal` Seq.empty)) else serialize_synth (parse_bv8 `nondep_then` parse_byte_bv (n - 1)) (synth_byte_bv (n - 1)) (serialize_bv8 `serialize_nondep_then` serialize_byte_bv (n - 1)) (synth_byte_bv_recip (n - 1)) () (* parse extra bits (big-endian with the first bits equal to 0) *) let extra_bytes_prop (n: nat) (x: U8.t) : Tot bool = U8.v x < pow2 (n % 8) let synth_extra_bv8 (n: nat) (x: parse_filter_refine (extra_bytes_prop n)) : Tot (BV.bv_t (n % 8)) = of_uint8 (n % 8) x
false
false
LowParse.Spec.BitVector.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val synth_extra_bv8_recip (n: nat) (x: BV.bv_t (n % 8)) : Tot (parse_filter_refine (extra_bytes_prop n))
[]
LowParse.Spec.BitVector.synth_extra_bv8_recip
{ "file_name": "src/lowparse/LowParse.Spec.BitVector.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
n: Prims.nat -> x: FStar.BitVector.bv_t (n % 8) -> LowParse.Spec.Combinators.parse_filter_refine (LowParse.Spec.BitVector.extra_bytes_prop n)
{ "end_col": 12, "end_line": 170, "start_col": 2, "start_line": 170 }
Prims.Tot
val synth_bv (n: nat) (x: (BV.bv_t (n % 8) & BV.bv_t (8 * (n / 8)))) : Tot (BV.bv_t n)
[ { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.BitVector", "short_module": "BV" }, { "abbrev": false, "full_module": "FStar.Mul", "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 } ]
false
let synth_bv (n: nat) (x: (BV.bv_t (n % 8) & BV.bv_t (8 * (n / 8)))) : Tot (BV.bv_t n) = Seq.append (fst x) (snd x)
val synth_bv (n: nat) (x: (BV.bv_t (n % 8) & BV.bv_t (8 * (n / 8)))) : Tot (BV.bv_t n) let synth_bv (n: nat) (x: (BV.bv_t (n % 8) & BV.bv_t (8 * (n / 8)))) : Tot (BV.bv_t n) =
false
null
false
Seq.append (fst x) (snd x)
{ "checked_file": "LowParse.Spec.BitVector.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Int.fsti.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.BoundedInt.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "LowParse.Spec.BitVector.fst" }
[ "total" ]
[ "Prims.nat", "FStar.Pervasives.Native.tuple2", "FStar.BitVector.bv_t", "Prims.op_Modulus", "FStar.Mul.op_Star", "Prims.op_Division", "FStar.Seq.Base.append", "Prims.bool", "FStar.Pervasives.Native.fst", "FStar.Pervasives.Native.snd" ]
[]
module LowParse.Spec.BitVector open FStar.Mul module BV = FStar.BitVector module U8 = FStar.UInt8 module Seq = FStar.Seq (* Big-endian conversion of a bit vector to a UInt8 *) let rec to_uint8 (#n: nat { n <= 8 }) (x: BV.bv_t n) : Tot (y: U8.t { U8.v y < pow2 n }) = if n = 0 then 0uy else let hi = to_uint8 #(n - 1) (Seq.slice x 0 (n - 1)) in let hi' = hi `U8.mul` 2uy in let (r: U8.t { U8.v r < 2 }) = if Seq.index x (n - 1) then 1uy else 0uy in hi' `U8.add` r let rec of_uint8 (n: nat { n <= 8 }) (x: U8.t { U8.v x < pow2 n }) : Tot (BV.bv_t n) = if n = 0 then Seq.empty else let hi = of_uint8 (n - 1) (x `U8.div` 2uy) in Seq.snoc hi (x `U8.rem` 2uy = 1uy) #push-options "--z3rlimit 32" let rec to_uint8_of_uint8 (n: nat { n <= 8 }) (x: U8.t { U8.v x < pow2 n }) : Lemma (to_uint8 (of_uint8 n x) == x) = if n = 0 then () else begin assert (Seq.slice (of_uint8 n x) 0 (n - 1) `Seq.equal` of_uint8 (n - 1) (x `U8.div` 2uy)); to_uint8_of_uint8 (n - 1) (x `U8.div` 2uy) end let rec of_uint8_to_uint8 (#n: nat {n <= 8}) (x: BV.bv_t n) : Lemma (of_uint8 n (to_uint8 x) `Seq.equal` x) = if n = 0 then () else begin let x' = Seq.slice x 0 (n - 1) in of_uint8_to_uint8 #(n - 1) x' ; assert ( U8.v (to_uint8 #(n - 1) x') * 2 == U8.v (to_uint8 x) \/ U8.v (to_uint8 #(n - 1) x') * 2 + 1 == U8.v (to_uint8 x) ); assert (to_uint8 #(n - 1) x' == to_uint8 x `U8.div` 2uy); () end #pop-options (* parse a 8-bit vector *) open LowParse.Spec.Combinators open LowParse.Spec.Int let synth_bv8 (x: U8.t) : Tot (BV.bv_t 8) = of_uint8 8 x let synth_bv8_recip (x: BV.bv_t 8) : Tot U8.t = to_uint8 x let synth_bv8_injective : squash (synth_injective synth_bv8) = synth_inverse_intro' synth_bv8_recip synth_bv8 (fun x -> to_uint8_of_uint8 8 x ) let synth_bv8_inverse : squash (synth_inverse synth_bv8 synth_bv8_recip) = synth_inverse_intro' synth_bv8 synth_bv8_recip (fun x -> of_uint8_to_uint8 x ) let parse_bv8_kind = parse_u8_kind let parse_bv8 : parser parse_bv8_kind (BV.bv_t 8) = parse_u8 `parse_synth` synth_bv8 let serialize_bv8 : serializer parse_bv8 = serialize_synth parse_u8 synth_bv8 serialize_u8 synth_bv8_recip () (* parse a 8*n bit vector *) let synth_byte_bv (n: nat) (x: (BV.bv_t 8 & BV.bv_t (8 * n))) : Tot (BV.bv_t (8 * (1 + n))) = Seq.append (fst x) (snd x) let synth_byte_bv_recip (n: nat) (x: BV.bv_t (8 * (1 + n))) : Tot (BV.bv_t 8 & BV.bv_t (8 * n)) = Seq.slice x 0 8, Seq.slice x 8 (Seq.length x) let synth_byte_bv_injective (n: nat) : Lemma (synth_injective (synth_byte_bv n)) [SMTPat (synth_injective (synth_byte_bv n))] = synth_inverse_intro' (synth_byte_bv_recip n) (synth_byte_bv n) (fun x -> let (hd, tl) = x in let (hd', tl') = synth_byte_bv_recip n (synth_byte_bv n x) in assert (hd `Seq.equal` hd'); assert (tl `Seq.equal` tl') ) let synth_byte_bv_inverse (n: nat) : Lemma (synth_inverse (synth_byte_bv n) (synth_byte_bv_recip n)) [SMTPat (synth_inverse (synth_byte_bv n) (synth_byte_bv_recip n))] = synth_inverse_intro' (synth_byte_bv n) (synth_byte_bv_recip n) (fun x -> assert (synth_byte_bv n (synth_byte_bv_recip n x) `Seq.equal` x) ) let rec parse_byte_bv_kind' (n: nat) : Tot parser_kind = if n = 0 then parse_ret_kind else parse_bv8_kind `and_then_kind` parse_byte_bv_kind' (n - 1) let parse_byte_bv_kind (n: nat) : Tot parser_kind = strong_parser_kind n n (Some ParserKindMetadataTotal) let rec parse_byte_bv_kind_eq (n: nat) : Lemma (parse_byte_bv_kind n == parse_byte_bv_kind' n) = if n = 0 then () else parse_byte_bv_kind_eq (n - 1) let rec parse_byte_bv (n: nat) : Tot (parser (parse_byte_bv_kind n) (BV.bv_t (8 * n))) = parse_byte_bv_kind_eq n; if n = 0 then parse_ret Seq.empty else (parse_bv8 `nondep_then` parse_byte_bv (n - 1)) `parse_synth` synth_byte_bv (n - 1) let rec serialize_byte_bv (n: nat) : Tot (serializer (parse_byte_bv n)) = parse_byte_bv_kind_eq n; if n = 0 then serialize_ret Seq.empty (fun (x: BV.bv_t 0) -> assert (x `Seq.equal` Seq.empty)) else serialize_synth (parse_bv8 `nondep_then` parse_byte_bv (n - 1)) (synth_byte_bv (n - 1)) (serialize_bv8 `serialize_nondep_then` serialize_byte_bv (n - 1)) (synth_byte_bv_recip (n - 1)) () (* parse extra bits (big-endian with the first bits equal to 0) *) let extra_bytes_prop (n: nat) (x: U8.t) : Tot bool = U8.v x < pow2 (n % 8) let synth_extra_bv8 (n: nat) (x: parse_filter_refine (extra_bytes_prop n)) : Tot (BV.bv_t (n % 8)) = of_uint8 (n % 8) x let synth_extra_bv8_recip (n: nat) (x: BV.bv_t (n % 8)) : Tot (parse_filter_refine (extra_bytes_prop n)) = to_uint8 x let synth_extra_bv8_injective (n: nat) : Lemma (synth_injective (synth_extra_bv8 n)) [SMTPat (synth_injective (synth_extra_bv8 n))] = synth_inverse_intro' (synth_extra_bv8_recip n) (synth_extra_bv8 n) (fun x -> to_uint8_of_uint8 (n % 8) x ) let synth_extra_bv8_inverse (n: nat) : Lemma (synth_inverse (synth_extra_bv8 n) (synth_extra_bv8_recip n)) [SMTPat (synth_inverse (synth_extra_bv8 n) (synth_extra_bv8_recip n))] = synth_inverse_intro' (synth_extra_bv8 n) (synth_extra_bv8_recip n) (fun x -> of_uint8_to_uint8 x ) let parse_extra_bv8_kind (n: nat) : Tot parser_kind = parse_filter_kind parse_u8_kind let parse_extra_bv8 (n: nat) : Tot (parser (parse_extra_bv8_kind n) (BV.bv_t (n % 8))) = (parse_u8 `parse_filter` extra_bytes_prop n) `parse_synth` synth_extra_bv8 n let serialize_extra_bv8 (n: nat) : Tot (serializer (parse_extra_bv8 n)) = serialize_synth _ (synth_extra_bv8 n) (serialize_filter serialize_u8 (extra_bytes_prop n)) (synth_extra_bv8_recip n) () (* parse a bitvector, general *)
false
false
LowParse.Spec.BitVector.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val synth_bv (n: nat) (x: (BV.bv_t (n % 8) & BV.bv_t (8 * (n / 8)))) : Tot (BV.bv_t n)
[]
LowParse.Spec.BitVector.synth_bv
{ "file_name": "src/lowparse/LowParse.Spec.BitVector.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
n: Prims.nat -> x: (FStar.BitVector.bv_t (n % 8) * FStar.BitVector.bv_t (8 * (n / 8))) -> FStar.BitVector.bv_t n
{ "end_col": 28, "end_line": 203, "start_col": 2, "start_line": 203 }
Prims.Tot
val serialize_byte_bv (n: nat) : Tot (serializer (parse_byte_bv n))
[ { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.BitVector", "short_module": "BV" }, { "abbrev": false, "full_module": "FStar.Mul", "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 } ]
false
let rec serialize_byte_bv (n: nat) : Tot (serializer (parse_byte_bv n)) = parse_byte_bv_kind_eq n; if n = 0 then serialize_ret Seq.empty (fun (x: BV.bv_t 0) -> assert (x `Seq.equal` Seq.empty)) else serialize_synth (parse_bv8 `nondep_then` parse_byte_bv (n - 1)) (synth_byte_bv (n - 1)) (serialize_bv8 `serialize_nondep_then` serialize_byte_bv (n - 1)) (synth_byte_bv_recip (n - 1)) ()
val serialize_byte_bv (n: nat) : Tot (serializer (parse_byte_bv n)) let rec serialize_byte_bv (n: nat) : Tot (serializer (parse_byte_bv n)) =
false
null
false
parse_byte_bv_kind_eq n; if n = 0 then serialize_ret Seq.empty (fun (x: BV.bv_t 0) -> assert (x `Seq.equal` Seq.empty)) else serialize_synth (parse_bv8 `nondep_then` (parse_byte_bv (n - 1))) (synth_byte_bv (n - 1)) (serialize_bv8 `serialize_nondep_then` (serialize_byte_bv (n - 1))) (synth_byte_bv_recip (n - 1)) ()
{ "checked_file": "LowParse.Spec.BitVector.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Int.fsti.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.BoundedInt.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "LowParse.Spec.BitVector.fst" }
[ "total" ]
[ "Prims.nat", "Prims.op_Equality", "Prims.int", "LowParse.Spec.Combinators.serialize_ret", "FStar.BitVector.bv_t", "FStar.Seq.Base.empty", "Prims.bool", "Prims._assert", "FStar.Seq.Base.equal", "Prims.unit", "LowParse.Spec.Combinators.serialize_synth", "LowParse.Spec.Combinators.and_then_kind", "LowParse.Spec.BitVector.parse_bv8_kind", "LowParse.Spec.BitVector.parse_byte_bv_kind", "Prims.op_Subtraction", "FStar.Pervasives.Native.tuple2", "FStar.Mul.op_Star", "LowParse.Spec.Combinators.nondep_then", "LowParse.Spec.BitVector.parse_bv8", "LowParse.Spec.BitVector.parse_byte_bv", "LowParse.Spec.BitVector.synth_byte_bv", "LowParse.Spec.Combinators.serialize_nondep_then", "LowParse.Spec.BitVector.serialize_bv8", "LowParse.Spec.BitVector.serialize_byte_bv", "LowParse.Spec.BitVector.synth_byte_bv_recip", "LowParse.Spec.Base.serializer", "LowParse.Spec.BitVector.parse_byte_bv_kind_eq" ]
[]
module LowParse.Spec.BitVector open FStar.Mul module BV = FStar.BitVector module U8 = FStar.UInt8 module Seq = FStar.Seq (* Big-endian conversion of a bit vector to a UInt8 *) let rec to_uint8 (#n: nat { n <= 8 }) (x: BV.bv_t n) : Tot (y: U8.t { U8.v y < pow2 n }) = if n = 0 then 0uy else let hi = to_uint8 #(n - 1) (Seq.slice x 0 (n - 1)) in let hi' = hi `U8.mul` 2uy in let (r: U8.t { U8.v r < 2 }) = if Seq.index x (n - 1) then 1uy else 0uy in hi' `U8.add` r let rec of_uint8 (n: nat { n <= 8 }) (x: U8.t { U8.v x < pow2 n }) : Tot (BV.bv_t n) = if n = 0 then Seq.empty else let hi = of_uint8 (n - 1) (x `U8.div` 2uy) in Seq.snoc hi (x `U8.rem` 2uy = 1uy) #push-options "--z3rlimit 32" let rec to_uint8_of_uint8 (n: nat { n <= 8 }) (x: U8.t { U8.v x < pow2 n }) : Lemma (to_uint8 (of_uint8 n x) == x) = if n = 0 then () else begin assert (Seq.slice (of_uint8 n x) 0 (n - 1) `Seq.equal` of_uint8 (n - 1) (x `U8.div` 2uy)); to_uint8_of_uint8 (n - 1) (x `U8.div` 2uy) end let rec of_uint8_to_uint8 (#n: nat {n <= 8}) (x: BV.bv_t n) : Lemma (of_uint8 n (to_uint8 x) `Seq.equal` x) = if n = 0 then () else begin let x' = Seq.slice x 0 (n - 1) in of_uint8_to_uint8 #(n - 1) x' ; assert ( U8.v (to_uint8 #(n - 1) x') * 2 == U8.v (to_uint8 x) \/ U8.v (to_uint8 #(n - 1) x') * 2 + 1 == U8.v (to_uint8 x) ); assert (to_uint8 #(n - 1) x' == to_uint8 x `U8.div` 2uy); () end #pop-options (* parse a 8-bit vector *) open LowParse.Spec.Combinators open LowParse.Spec.Int let synth_bv8 (x: U8.t) : Tot (BV.bv_t 8) = of_uint8 8 x let synth_bv8_recip (x: BV.bv_t 8) : Tot U8.t = to_uint8 x let synth_bv8_injective : squash (synth_injective synth_bv8) = synth_inverse_intro' synth_bv8_recip synth_bv8 (fun x -> to_uint8_of_uint8 8 x ) let synth_bv8_inverse : squash (synth_inverse synth_bv8 synth_bv8_recip) = synth_inverse_intro' synth_bv8 synth_bv8_recip (fun x -> of_uint8_to_uint8 x ) let parse_bv8_kind = parse_u8_kind let parse_bv8 : parser parse_bv8_kind (BV.bv_t 8) = parse_u8 `parse_synth` synth_bv8 let serialize_bv8 : serializer parse_bv8 = serialize_synth parse_u8 synth_bv8 serialize_u8 synth_bv8_recip () (* parse a 8*n bit vector *) let synth_byte_bv (n: nat) (x: (BV.bv_t 8 & BV.bv_t (8 * n))) : Tot (BV.bv_t (8 * (1 + n))) = Seq.append (fst x) (snd x) let synth_byte_bv_recip (n: nat) (x: BV.bv_t (8 * (1 + n))) : Tot (BV.bv_t 8 & BV.bv_t (8 * n)) = Seq.slice x 0 8, Seq.slice x 8 (Seq.length x) let synth_byte_bv_injective (n: nat) : Lemma (synth_injective (synth_byte_bv n)) [SMTPat (synth_injective (synth_byte_bv n))] = synth_inverse_intro' (synth_byte_bv_recip n) (synth_byte_bv n) (fun x -> let (hd, tl) = x in let (hd', tl') = synth_byte_bv_recip n (synth_byte_bv n x) in assert (hd `Seq.equal` hd'); assert (tl `Seq.equal` tl') ) let synth_byte_bv_inverse (n: nat) : Lemma (synth_inverse (synth_byte_bv n) (synth_byte_bv_recip n)) [SMTPat (synth_inverse (synth_byte_bv n) (synth_byte_bv_recip n))] = synth_inverse_intro' (synth_byte_bv n) (synth_byte_bv_recip n) (fun x -> assert (synth_byte_bv n (synth_byte_bv_recip n x) `Seq.equal` x) ) let rec parse_byte_bv_kind' (n: nat) : Tot parser_kind = if n = 0 then parse_ret_kind else parse_bv8_kind `and_then_kind` parse_byte_bv_kind' (n - 1) let parse_byte_bv_kind (n: nat) : Tot parser_kind = strong_parser_kind n n (Some ParserKindMetadataTotal) let rec parse_byte_bv_kind_eq (n: nat) : Lemma (parse_byte_bv_kind n == parse_byte_bv_kind' n) = if n = 0 then () else parse_byte_bv_kind_eq (n - 1) let rec parse_byte_bv (n: nat) : Tot (parser (parse_byte_bv_kind n) (BV.bv_t (8 * n))) = parse_byte_bv_kind_eq n; if n = 0 then parse_ret Seq.empty else (parse_bv8 `nondep_then` parse_byte_bv (n - 1)) `parse_synth` synth_byte_bv (n - 1)
false
false
LowParse.Spec.BitVector.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val serialize_byte_bv (n: nat) : Tot (serializer (parse_byte_bv n))
[ "recursion" ]
LowParse.Spec.BitVector.serialize_byte_bv
{ "file_name": "src/lowparse/LowParse.Spec.BitVector.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
n: Prims.nat -> LowParse.Spec.Base.serializer (LowParse.Spec.BitVector.parse_byte_bv n)
{ "end_col": 8, "end_line": 159, "start_col": 2, "start_line": 149 }
FStar.Pervasives.Lemma
val of_uint8_to_uint8 (#n: nat{n <= 8}) (x: BV.bv_t n) : Lemma ((of_uint8 n (to_uint8 x)) `Seq.equal` x)
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.BitVector", "short_module": "BV" }, { "abbrev": false, "full_module": "FStar.Mul", "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 } ]
false
let rec of_uint8_to_uint8 (#n: nat {n <= 8}) (x: BV.bv_t n) : Lemma (of_uint8 n (to_uint8 x) `Seq.equal` x) = if n = 0 then () else begin let x' = Seq.slice x 0 (n - 1) in of_uint8_to_uint8 #(n - 1) x' ; assert ( U8.v (to_uint8 #(n - 1) x') * 2 == U8.v (to_uint8 x) \/ U8.v (to_uint8 #(n - 1) x') * 2 + 1 == U8.v (to_uint8 x) ); assert (to_uint8 #(n - 1) x' == to_uint8 x `U8.div` 2uy); () end
val of_uint8_to_uint8 (#n: nat{n <= 8}) (x: BV.bv_t n) : Lemma ((of_uint8 n (to_uint8 x)) `Seq.equal` x) let rec of_uint8_to_uint8 (#n: nat{n <= 8}) (x: BV.bv_t n) : Lemma ((of_uint8 n (to_uint8 x)) `Seq.equal` x) =
false
null
true
if n = 0 then () else let x' = Seq.slice x 0 (n - 1) in of_uint8_to_uint8 #(n - 1) x'; assert (U8.v (to_uint8 #(n - 1) x') * 2 == U8.v (to_uint8 x) \/ U8.v (to_uint8 #(n - 1) x') * 2 + 1 == U8.v (to_uint8 x)); assert (to_uint8 #(n - 1) x' == (to_uint8 x) `U8.div` 2uy); ()
{ "checked_file": "LowParse.Spec.BitVector.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Int.fsti.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.BoundedInt.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "LowParse.Spec.BitVector.fst" }
[ "lemma" ]
[ "Prims.nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.BitVector.bv_t", "Prims.op_Equality", "Prims.int", "Prims.bool", "Prims.unit", "Prims._assert", "Prims.eq2", "FStar.UInt8.t", "LowParse.Spec.BitVector.to_uint8", "Prims.op_Subtraction", "FStar.UInt8.div", "FStar.UInt8.__uint_to_t", "Prims.l_or", "FStar.Mul.op_Star", "FStar.UInt8.v", "Prims.op_Addition", "LowParse.Spec.BitVector.of_uint8_to_uint8", "FStar.Seq.Base.seq", "FStar.Seq.Base.slice", "Prims.l_True", "Prims.squash", "FStar.Seq.Base.equal", "LowParse.Spec.BitVector.of_uint8", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module LowParse.Spec.BitVector open FStar.Mul module BV = FStar.BitVector module U8 = FStar.UInt8 module Seq = FStar.Seq (* Big-endian conversion of a bit vector to a UInt8 *) let rec to_uint8 (#n: nat { n <= 8 }) (x: BV.bv_t n) : Tot (y: U8.t { U8.v y < pow2 n }) = if n = 0 then 0uy else let hi = to_uint8 #(n - 1) (Seq.slice x 0 (n - 1)) in let hi' = hi `U8.mul` 2uy in let (r: U8.t { U8.v r < 2 }) = if Seq.index x (n - 1) then 1uy else 0uy in hi' `U8.add` r let rec of_uint8 (n: nat { n <= 8 }) (x: U8.t { U8.v x < pow2 n }) : Tot (BV.bv_t n) = if n = 0 then Seq.empty else let hi = of_uint8 (n - 1) (x `U8.div` 2uy) in Seq.snoc hi (x `U8.rem` 2uy = 1uy) #push-options "--z3rlimit 32" let rec to_uint8_of_uint8 (n: nat { n <= 8 }) (x: U8.t { U8.v x < pow2 n }) : Lemma (to_uint8 (of_uint8 n x) == x) = if n = 0 then () else begin assert (Seq.slice (of_uint8 n x) 0 (n - 1) `Seq.equal` of_uint8 (n - 1) (x `U8.div` 2uy)); to_uint8_of_uint8 (n - 1) (x `U8.div` 2uy) end let rec of_uint8_to_uint8 (#n: nat {n <= 8}) (x: BV.bv_t n) : Lemma
false
false
LowParse.Spec.BitVector.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 32, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val of_uint8_to_uint8 (#n: nat{n <= 8}) (x: BV.bv_t n) : Lemma ((of_uint8 n (to_uint8 x)) `Seq.equal` x)
[ "recursion" ]
LowParse.Spec.BitVector.of_uint8_to_uint8
{ "file_name": "src/lowparse/LowParse.Spec.BitVector.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
x: FStar.BitVector.bv_t n -> FStar.Pervasives.Lemma (ensures FStar.Seq.Base.equal (LowParse.Spec.BitVector.of_uint8 n (LowParse.Spec.BitVector.to_uint8 x)) x)
{ "end_col": 5, "end_line": 62, "start_col": 2, "start_line": 51 }