file_name
stringlengths 5
52
| name
stringlengths 4
95
| original_source_type
stringlengths 0
23k
| source_type
stringlengths 9
23k
| source_definition
stringlengths 9
57.9k
| source
dict | source_range
dict | file_context
stringlengths 0
721k
| dependencies
dict | opens_and_abbrevs
listlengths 2
94
| vconfig
dict | interleaved
bool 1
class | verbose_type
stringlengths 1
7.42k
| effect
stringclasses 118
values | effect_flags
sequencelengths 0
2
| mutual_with
sequencelengths 0
11
| ideal_premises
sequencelengths 0
236
| proof_features
sequencelengths 0
1
| is_simple_lemma
bool 2
classes | is_div
bool 2
classes | is_proof
bool 2
classes | is_simply_typed
bool 2
classes | is_type
bool 2
classes | partial_definition
stringlengths 5
3.99k
| completed_definiton
stringlengths 1
1.63M
| isa_cross_project_example
bool 1
class |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
LowStar.Printf.fst | LowStar.Printf.intro_normal_f | val intro_normal_f (#a: Type) (b: (a -> Type)) (f: (x: a -> b x)) : (x: (normal a) -> normal (b x)) | val intro_normal_f (#a: Type) (b: (a -> Type)) (f: (x: a -> b x)) : (x: (normal a) -> normal (b x)) | let intro_normal_f (#a:Type) (b: (a -> Type)) (f:(x:a -> b x))
: (x:(normal a) -> normal (b x))
= f | {
"file_name": "ulib/LowStar.Printf.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 5,
"end_line": 470,
"start_col": 0,
"start_line": 468
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LowStar.Printf
/// This module provides imperative printing functions for several
/// primitive Low* types, including
/// -- booleans (%b)
/// -- characters (%c)
/// -- strings (%s)
/// -- machine integers
/// (UInt8.t as %uy, UInt16.t as %us, UInt32.t as %ul, and UInt64.t as %uL;
/// Int8.t as %y, Int16.t as %i, Int32.t as %l , and Int64.t as %L)
/// -- and arrays (aka buffers) of these base types formatted
/// as %xN, where N is the format specifier for the array element type
/// e.g., %xuy for buffers of UInt8.t
/// The main function of this module is `printf`
/// There are a few main differences relative to C printf
/// -- The format specifiers are different (see above)
///
/// -- For technical reasons explained below, an extra dummy
/// argument `done` has to be provided at the end for the
/// computation to have any effect.
///
/// E.g., one must write
/// `printf "%b %c" true 'c' done`
/// rather than just
/// `printf "%b %c" true 'c'`
///
/// -- When printing arrays, two arguments must be passed; the
/// length of the array fragment to be formatted and the array
/// itself
///
/// -- When extracted, rather than producing a C `printf` (which
/// does not, e.g., support printing of dynamically sized
/// arrays), our `printf` is specialized to a sequence of calls
/// to primitive printers for each supported type
///
/// Before diving into the technical details of how this module works,
/// you might want to see a sample usage at the very end of this file.
open FStar.Char
open FStar.String
open FStar.HyperStack.ST
module L = FStar.List.Tot
module LB = LowStar.Monotonic.Buffer
/// `lmbuffer a r s l` is
/// - a monotonic buffer of `a`
/// - governed by preorders `r` and `s`
/// - with length `l`
let lmbuffer a r s l =
b:LB.mbuffer a r s{
LB.len b == l
}
/// `StTrivial`: A effect abbreviation for a stateful computation
/// with no precondition, and which does not change the state
effect StTrivial (a:Type) =
Stack a
(requires fun h -> True)
(ensures fun h0 _ h1 -> h0==h1)
/// `StBuf a b`: A effect abbreviation for a stateful computation
/// that may read `b` does not change the state
effect StBuf (a:Type) #t #r #s #l (b:lmbuffer t r s l) =
Stack a
(requires fun h -> LB.live h b)
(ensures (fun h0 _ h1 -> h0 == h1))
/// Primitive printers for all the types supported by this module
assume val print_string: string -> StTrivial unit
assume val print_char : char -> StTrivial unit
assume val print_u8 : UInt8.t -> StTrivial unit
assume val print_u16 : UInt16.t -> StTrivial unit
assume val print_u32 : UInt32.t -> StTrivial unit
assume val print_u64 : UInt64.t -> StTrivial unit
assume val print_i8 : Int8.t -> StTrivial unit
assume val print_i16 : Int16.t -> StTrivial unit
assume val print_i32 : Int32.t -> StTrivial unit
assume val print_i64 : Int64.t -> StTrivial unit
assume val print_bool : bool -> StTrivial unit
assume val print_lmbuffer_bool (l:_) (#r:_) (#s:_) (b:lmbuffer bool r s l) : StBuf unit b
assume val print_lmbuffer_char (l:_) (#r:_) (#s:_) (b:lmbuffer char r s l) : StBuf unit b
assume val print_lmbuffer_string (l:_) (#r:_) (#s:_) (b:lmbuffer string r s l) : StBuf unit b
assume val print_lmbuffer_u8 (l:_) (#r:_) (#s:_) (b:lmbuffer UInt8.t r s l) : StBuf unit b
assume val print_lmbuffer_u16 (l:_) (#r:_) (#s:_) (b:lmbuffer UInt16.t r s l) : StBuf unit b
assume val print_lmbuffer_u32 (l:_) (#r:_) (#s:_) (b:lmbuffer UInt32.t r s l) : StBuf unit b
assume val print_lmbuffer_u64 (l:_) (#r:_) (#s:_) (b:lmbuffer UInt64.t r s l) : StBuf unit b
assume val print_lmbuffer_i8 (l:_) (#r:_) (#s:_) (b:lmbuffer Int8.t r s l) : StBuf unit b
assume val print_lmbuffer_i16 (l:_) (#r:_) (#s:_) (b:lmbuffer Int16.t r s l) : StBuf unit b
assume val print_lmbuffer_i32 (l:_) (#r:_) (#s:_) (b:lmbuffer Int32.t r s l) : StBuf unit b
assume val print_lmbuffer_i64 (l:_) (#r:_) (#s:_) (b:lmbuffer Int64.t r s l) : StBuf unit b
/// An attribute to control reduction
noextract irreducible
let __reduce__ = unit
/// Base types supported so far
noextract
type base_typ =
| Bool
| Char
| String
| U8
| U16
| U32
| U64
| I8
| I16
| I32
| I64
/// Argument types are base types and arrays thereof
/// Or polymorphic arguments specified by "%a"
noextract
type arg =
| Base of base_typ
| Array of base_typ
| Any
/// Interpreting a `base_typ` as a type
[@@__reduce__]
noextract
let base_typ_as_type (b:base_typ) : Type0 =
match b with
| Bool -> bool
| Char -> char
| String -> string
| U8 -> FStar.UInt8.t
| U16 -> FStar.UInt16.t
| U32 -> FStar.UInt32.t
| U64 -> FStar.UInt64.t
| I8 -> FStar.Int8.t
| I16 -> FStar.Int16.t
| I32 -> FStar.Int32.t
| I64 -> FStar.Int64.t
/// `fragment`: A format string is parsed into a list of fragments of
/// string literals and other arguments that need to be spliced in
/// (interpolated)
noextract
type fragment =
| Frag of string
| Interpolate of arg
noextract
let fragments = list fragment
/// `parse_format s`:
/// Parses a list of characters in a format string into a list of fragments
/// Or None, in case the format string is invalid
[@@__reduce__]
noextract inline_for_extraction
let rec parse_format
(s:list char)
: Tot (option fragments)
(decreases (L.length s))
= let add_dir (d:arg) (ods : option fragments)
= match ods with
| None -> None
| Some ds -> Some (Interpolate d::ds)
in
let head_buffer (ods:option fragments)
= match ods with
| Some (Interpolate (Base t) :: rest) -> Some (Interpolate (Array t) :: rest)
| _ -> None
in
let cons_frag (c:char) (ods:option fragments)
= match ods with
| Some (Frag s::rest) -> Some (Frag (string_of_list (c :: list_of_string s)) :: rest)
| Some rest -> Some (Frag (string_of_list [c]) :: rest)
| _ -> None
in
match s with
| [] -> Some []
| ['%'] -> None
// %a... polymorphic arguments and preceded by their printers
| '%' :: 'a' :: s' ->
add_dir Any (parse_format s')
// %x... arrays of base types
| '%' :: 'x' :: s' ->
head_buffer (parse_format ('%' :: s'))
// %u ... Unsigned integers
| '%' :: 'u' :: s' -> begin
match s' with
| 'y' :: s'' -> add_dir (Base U8) (parse_format s'')
| 's' :: s'' -> add_dir (Base U16) (parse_format s'')
| 'l' :: s'' -> add_dir (Base U32) (parse_format s'')
| 'L' :: s'' -> add_dir (Base U64) (parse_format s'')
| _ -> None
end
| '%' :: c :: s' -> begin
match c with
| '%' -> cons_frag '%' (parse_format s')
| 'b' -> add_dir (Base Bool) (parse_format s')
| 'c' -> add_dir (Base Char) (parse_format s')
| 's' -> add_dir (Base String) (parse_format s')
| 'y' -> add_dir (Base I8) (parse_format s')
| 'i' -> add_dir (Base I16) (parse_format s')
| 'l' -> add_dir (Base I32) (parse_format s')
| 'L' -> add_dir (Base I64) (parse_format s')
| _ -> None
end
| c :: s' ->
cons_frag c (parse_format s')
/// `parse_format_string`: a wrapper around `parse_format`
[@@__reduce__]
noextract inline_for_extraction
let parse_format_string
(s:string)
: option fragments
= parse_format (list_of_string s)
/// `lift a` lifts the type `a` to a higher universe
noextract
type lift (a:Type u#a) : Type u#(max a b) =
| Lift : a -> lift a
/// `done` is a `unit` in universe 1
noextract
let done : lift unit = Lift u#0 u#1 ()
/// `arg_t`: interpreting an argument as a type
/// (in universe 1) since it is polymorphic in the preorders of a buffer
/// GM: Somehow, this needs to be a `let rec` (even if it not really recursive)
/// or print_frags fails to verify. I don't know why; the generated
/// VC and its encoding seem identical (modulo hash consing in the
/// latter).
[@@__reduce__]
noextract
let rec arg_t (a:arg) : Type u#1 =
match a with
| Base t -> lift (base_typ_as_type t)
| Array t -> (l:UInt32.t & r:_ & s:_ & lmbuffer (base_typ_as_type t) r s l)
| Any -> (a:Type0 & (a -> StTrivial unit) & a)
/// `frag_t`: a fragment is either a string literal or a argument to be interpolated
noextract
let frag_t = either string (a:arg & arg_t a)
/// `live_frags h l` is a liveness predicate on all the buffers in `l`
[@@__reduce__]
noextract
let rec live_frags (h:_) (l:list frag_t) : prop =
match l with
| [] -> True
| Inl _ :: rest -> live_frags h rest
| Inr a :: rest ->
(match a with
| (| Base _, _ |) -> live_frags h rest
| (| Any, _ |) -> live_frags h rest
| (| Array _, (| _, _, _, b |) |) -> LB.live h b /\ live_frags h rest)
/// `interpret_frags` interprets a list of fragments as a Low* function type
/// Note `l` is the fragments in L-to-R order (i.e., parsing order)
/// `acc` accumulates the fragment values in reverse order
[@@__reduce__]
noextract
let rec interpret_frags (l:fragments) (acc:list frag_t) : Type u#1 =
match l with
| [] ->
// Always a dummy argument at the end
// Ensures that all cases of this match
// have the same universe, i.e., u#1
lift u#0 u#1 unit
-> Stack unit
(requires fun h0 -> live_frags h0 acc)
(ensures fun h0 _ h1 -> h0 == h1)
| Interpolate (Base t) :: args ->
// Base types are simple: we just take one more argument
x:base_typ_as_type t ->
interpret_frags args (Inr (| Base t, Lift x |) :: acc)
| Interpolate (Array t) :: args ->
// Arrays are implicitly polymorphic in their preorders `r` and `s`
// which is what forces us to be in universe 1
// Note, the length `l` is explicit
l:UInt32.t ->
#r:LB.srel (base_typ_as_type t) ->
#s:LB.srel (base_typ_as_type t) ->
b:lmbuffer (base_typ_as_type t) r s l ->
interpret_frags args (Inr (| Array t, (| l, r, s, b |) |) :: acc)
| Interpolate Any :: args ->
#a:Type0 ->
p:(a -> StTrivial unit) ->
x:a ->
interpret_frags args (Inr (| Any, (| a, p, x |) |) :: acc)
| Frag s :: args ->
// Literal fragments do not incur an additional argument
// We just accumulate them and recur
interpret_frags args (Inl s :: acc)
/// `normal` A normalization marker with very specific steps enabled
noextract unfold
let normal (#a:Type) (x:a) : a =
FStar.Pervasives.norm
[iota;
zeta;
delta_attr [`%__reduce__; `%BigOps.__reduce__];
delta_only [`%Base?; `%Array?; `%Some?; `%Some?.v; `%list_of_string];
primops;
simplify]
x
/// `coerce`: A utility to trigger extensional equality of types
noextract
let coerce (x:'a{'a == 'b}) : 'b = x
/// `fragment_printer`: The type of a printer of fragments
noextract
let fragment_printer =
(acc:list frag_t)
-> Stack unit
(requires fun h0 -> live_frags h0 acc)
(ensures fun h0 _ h1 -> h0 == h1)
/// `print_frags`: Having accumulated all the pieces of a format
/// string and the arguments to the printed (i.e., the `list frag_t`),
/// this function does the actual work of printing them all using the
/// primitive printers
noextract inline_for_extraction
let rec print_frags (acc:list frag_t)
: Stack unit
(requires fun h0 -> live_frags h0 acc)
(ensures fun h0 _ h1 -> h0 == h1)
= match acc with
| [] -> ()
| hd::tl ->
print_frags tl;
(match hd with
| Inl s -> print_string s
| Inr (| Base t, Lift value |) ->
(match t with
| Bool -> print_bool value
| Char -> print_char value
| String -> print_string value
| U8 -> print_u8 value
| U16 -> print_u16 value
| U32 -> print_u32 value
| U64 -> print_u64 value
| I8 -> print_i8 value
| I16 -> print_i16 value
| I32 -> print_i32 value
| I64 -> print_i64 value)
| Inr (| Array t, (| l, r, s, value |) |) ->
(match t with
| Bool -> print_lmbuffer_bool l value
| Char -> print_lmbuffer_char l value
| String -> print_lmbuffer_string l value
| U8 -> print_lmbuffer_u8 l value
| U16 -> print_lmbuffer_u16 l value
| U32 -> print_lmbuffer_u32 l value
| U64 -> print_lmbuffer_u64 l value
| I8 -> print_lmbuffer_i8 l value
| I16 -> print_lmbuffer_i16 l value
| I32 -> print_lmbuffer_i32 l value
| I64 -> print_lmbuffer_i64 l value)
| Inr (| Any, (| _, printer, value |) |) ->
printer value)
[@@__reduce__]
let no_inst #a (#b:a -> Type) (f: (#x:a -> b x)) : unit -> #x:a -> b x = fun () -> f
[@@__reduce__]
let elim_unit_arrow #t (f:unit -> t) : t = f ()
// let test2 (f: (#a:Type -> a -> a)) : id_t 0 = test f ()
// let coerce #a (#b: (a -> Type)) ($f: (#x:a -> b x)) (t:Type{norm t == (#x:a -> b x)})
/// `aux frags acc`: This is the main workhorse which interprets a
/// parsed format string (`frags`) as a variadic, stateful function
[@@__reduce__]
noextract inline_for_extraction
let rec aux (frags:fragments) (acc:list frag_t) (fp: fragment_printer) : interpret_frags frags acc =
match frags with
| [] ->
let f (l:lift u#0 u#1 unit)
: Stack unit
(requires fun h0 -> live_frags h0 acc)
(ensures fun h0 _ h1 -> h0 == h1)
= fp acc
in
(f <: interpret_frags [] acc)
| Frag s :: rest ->
coerce (aux rest (Inl s :: acc) fp)
| Interpolate (Base t) :: args ->
let f (x:base_typ_as_type t)
: interpret_frags args (Inr (| Base t, Lift x |) :: acc)
= aux args (Inr (| Base t, Lift x |) :: acc) fp
in
f
| Interpolate (Array t) :: rest ->
let f :
l:UInt32.t
-> #r:LB.srel (base_typ_as_type t)
-> #s:LB.srel (base_typ_as_type t)
-> b:lmbuffer (base_typ_as_type t) r s l
-> interpret_frags rest (Inr (| Array t, (| l, r, s, b |) |) :: acc)
= fun l #r #s b -> aux rest (Inr (| Array t, (| l, r, s, b |) |) :: acc) fp
in
f <: interpret_frags (Interpolate (Array t) :: rest) acc
| Interpolate Any :: rest ->
let f :
unit
-> #a:Type
-> p:(a -> StTrivial unit)
-> x:a
-> interpret_frags rest (Inr (| Any, (| a, p, x |) |) :: acc)
= fun () #a p x -> aux rest (Inr (| Any, (| a, p, x |) |) :: acc) fp
in
elim_unit_arrow (no_inst (f ()) <: (unit -> interpret_frags (Interpolate Any :: rest) acc))
/// `format_string` : A valid format string is one that can be successfully parsed
[@@__reduce__]
noextract
let format_string = s:string{normal #bool (Some? (parse_format_string s))}
/// `interpret_format_string` parses a string into fragments and then
/// interprets it as a type
[@@__reduce__]
noextract
let interpret_format_string (s:format_string) : Type =
interpret_frags (Some?.v (parse_format_string s)) []
/// `printf'`: Almost there ... this has a variadic type
/// and calls the actual printers for all its arguments.
///
/// Note, the `normalize_term` in its body is crucial. It's what
/// allows the term to be specialized at extraction time.
noextract inline_for_extraction
let printf' (s:format_string) : interpret_format_string s =
normalize_term
(match parse_format_string s with
| Some frags -> aux frags [] print_frags)
/// `intro_normal_f`: a technical gadget to introduce
/// implicit normalization in the domain and co-domain of a function type | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.Printf.fst"
} | [
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "LB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.String",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Char",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | b: (_: a -> Type) -> f: (x: a -> b x) -> x: LowStar.Printf.normal a -> LowStar.Printf.normal (b x) | Prims.Tot | [
"total"
] | [] | [
"LowStar.Printf.normal"
] | [] | false | false | false | false | false | let intro_normal_f (#a: Type) (b: (a -> Type)) (f: (x: a -> b x)) : (x: (normal a) -> normal (b x)) =
| f | false |
AllocSTwHeaps.fst | AllocSTwHeaps.ist_witnessed | val ist_witnessed : p:
FStar.Preorder.predicate FStar.Monotonic.Heap.heap
{FStar.Preorder.stable p AllocSTwHeaps.heap_rel}
-> Type0 | let ist_witnessed (p:predicate FStar.Heap.heap{stable p heap_rel}) = witnessed heap_rel p | {
"file_name": "examples/preorders/AllocSTwHeaps.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 89,
"end_line": 80,
"start_col": 0,
"start_line": 80
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module AllocSTwHeaps
open FStar.ST
open FStar.Preorder
open FStar.Monotonic.Witnessed
//giving ourselves two non-ghost versions of the heap sel/upd functions
assume val sel: h:FStar.Heap.heap -> r:ref 'a -> Tot (x:'a{x == FStar.Heap.sel h r})
assume val upd: h:FStar.Heap.heap -> r:ref 'a -> v:'a -> Tot (h':FStar.Heap.heap{h' == FStar.Heap.upd h r v})
(* The preorder on heaps for recalling that allocated
references remain allocated in all future heaps. *)
//NB: needed to restrict a:Type0, so that IST doesn't become
// too universe polymorphic. This restriction is probably ok in practice ...
// ... i don't imagine storing things beyond Type0 in the heap
// Besides, if we allow that, then we may need to account for non-termination
let heap_rel (h0:FStar.Heap.heap) (h1:FStar.Heap.heap) =
forall (a:Type0) (r:ref a) . FStar.Heap.contains h0 r ==> FStar.Heap.contains h1 r
(* *************************************************** *)
(*
A temporary definition of preorder-indexed state
monads specialized to the allocated references
instance, in order to make sub-effecting to work.
Using (FStar.Heap.heap) and (heap_rel) for the
statespace and the relation on it, which otherwise
would be given by parameters.
*)
(* Preconditions, postconditions and WPs for the preorder-indexed state monad. *)
let ist_pre (state:Type) = state -> Type0
let ist_post (state:Type) (a:Type) = a -> state -> Type0
let ist_wp (state:Type) (a:Type) = ist_post state a -> Tot (ist_pre state)
(* A WP-style preorder-indexed state monad specialised for the allocated references instance. *)
new_effect ISTATE = STATE_h FStar.Heap.heap
(* DIV is a sub-effect/sub-monad of the allocated references instance of the preorder-indexed monad. *)
unfold let lift_div_istate (state:Type) (rel:preorder state)
(a:Type) (wp:pure_wp a) (p:ist_post state a) (s:state) = wp (fun x -> p x s)
sub_effect DIV ~> ISTATE = lift_div_istate FStar.Heap.heap heap_rel
(*A pre- and postcondition version of this preorder-indexed state monad. *)
effect IST (a:Type)
(pre:ist_pre FStar.Heap.heap)
(post:(FStar.Heap.heap -> Tot (ist_post FStar.Heap.heap a)))
=
ISTATE a (fun p s0 -> pre s0 /\ (forall x s1 . pre s0 /\ post s0 x s1 ==> p x s1))
(* A box-like modality for witnessed stable predicates for IST. *) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.ST.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Witnessed.fsti.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "AllocSTwHeaps.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Monotonic.Witnessed",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
p:
FStar.Preorder.predicate FStar.Monotonic.Heap.heap
{FStar.Preorder.stable p AllocSTwHeaps.heap_rel}
-> Type0 | Prims.Tot | [
"total"
] | [] | [
"FStar.Preorder.predicate",
"FStar.Monotonic.Heap.heap",
"FStar.Preorder.stable",
"AllocSTwHeaps.heap_rel",
"FStar.Monotonic.Witnessed.witnessed"
] | [] | false | false | false | false | true | let ist_witnessed (p: predicate FStar.Heap.heap {stable p heap_rel}) =
| witnessed heap_rel p | false |
|
AllocSTwHeaps.fst | AllocSTwHeaps.alloc | val alloc : #a:Type ->
x:a ->
AllocST (ref a) (fun _ -> True)
(fun h0 r h1 -> r `Heap.unused_in` h0 /\
FStar.Heap.contains h1 r /\
h1 == FStar.Heap.upd h0 r x) | val alloc : #a:Type ->
x:a ->
AllocST (ref a) (fun _ -> True)
(fun h0 r h1 -> r `Heap.unused_in` h0 /\
FStar.Heap.contains h1 r /\
h1 == FStar.Heap.upd h0 r x) | let alloc #a x =
let h = ist_get () in
let r = gen_ref h in
ist_put (upd h r x);
ist_witness (contains r);
r | {
"file_name": "examples/preorders/AllocSTwHeaps.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 3,
"end_line": 157,
"start_col": 0,
"start_line": 152
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module AllocSTwHeaps
open FStar.ST
open FStar.Preorder
open FStar.Monotonic.Witnessed
//giving ourselves two non-ghost versions of the heap sel/upd functions
assume val sel: h:FStar.Heap.heap -> r:ref 'a -> Tot (x:'a{x == FStar.Heap.sel h r})
assume val upd: h:FStar.Heap.heap -> r:ref 'a -> v:'a -> Tot (h':FStar.Heap.heap{h' == FStar.Heap.upd h r v})
(* The preorder on heaps for recalling that allocated
references remain allocated in all future heaps. *)
//NB: needed to restrict a:Type0, so that IST doesn't become
// too universe polymorphic. This restriction is probably ok in practice ...
// ... i don't imagine storing things beyond Type0 in the heap
// Besides, if we allow that, then we may need to account for non-termination
let heap_rel (h0:FStar.Heap.heap) (h1:FStar.Heap.heap) =
forall (a:Type0) (r:ref a) . FStar.Heap.contains h0 r ==> FStar.Heap.contains h1 r
(* *************************************************** *)
(*
A temporary definition of preorder-indexed state
monads specialized to the allocated references
instance, in order to make sub-effecting to work.
Using (FStar.Heap.heap) and (heap_rel) for the
statespace and the relation on it, which otherwise
would be given by parameters.
*)
(* Preconditions, postconditions and WPs for the preorder-indexed state monad. *)
let ist_pre (state:Type) = state -> Type0
let ist_post (state:Type) (a:Type) = a -> state -> Type0
let ist_wp (state:Type) (a:Type) = ist_post state a -> Tot (ist_pre state)
(* A WP-style preorder-indexed state monad specialised for the allocated references instance. *)
new_effect ISTATE = STATE_h FStar.Heap.heap
(* DIV is a sub-effect/sub-monad of the allocated references instance of the preorder-indexed monad. *)
unfold let lift_div_istate (state:Type) (rel:preorder state)
(a:Type) (wp:pure_wp a) (p:ist_post state a) (s:state) = wp (fun x -> p x s)
sub_effect DIV ~> ISTATE = lift_div_istate FStar.Heap.heap heap_rel
(*A pre- and postcondition version of this preorder-indexed state monad. *)
effect IST (a:Type)
(pre:ist_pre FStar.Heap.heap)
(post:(FStar.Heap.heap -> Tot (ist_post FStar.Heap.heap a)))
=
ISTATE a (fun p s0 -> pre s0 /\ (forall x s1 . pre s0 /\ post s0 x s1 ==> p x s1))
(* A box-like modality for witnessed stable predicates for IST. *)
let ist_witnessed (p:predicate FStar.Heap.heap{stable p heap_rel}) = witnessed heap_rel p
(* Generic effects (operations) for IST. *)
assume val ist_get : unit -> IST FStar.Heap.heap (fun s0 -> True) (fun s0 s s1 -> s0 == s /\ s == s1)
assume val ist_put : x:FStar.Heap.heap ->
IST unit (fun s0 -> heap_rel s0 x) (fun s0 _ s1 -> s1 == x)
assume val ist_witness : p:predicate FStar.Heap.heap{stable p heap_rel} ->
IST unit (fun s0 -> p s0) (fun s0 _ s1 -> s0 == s1 /\ ist_witnessed p)
assume val ist_recall : p:predicate FStar.Heap.heap{stable p heap_rel} ->
IST unit (fun _ -> ist_witnessed p) (fun s0 _ s1 -> s0 == s1 /\ p s1)
(* *************************************************** *)
(* Swapping the reference and heap arguments of (FStar.Heap.contains)
to use it in point-free style in (witness) and (recall). *)
let contains (#a:Type) (r:ref a) (h:FStar.Heap.heap) =
b2t (FStar.StrongExcludedMiddle.strong_excluded_middle (FStar.Heap.contains h r))
val contains_lemma : #a:Type ->
h:FStar.Heap.heap ->
r:ref a ->
Lemma (requires (contains r h))
(ensures (FStar.Heap.contains h r))
[SMTPat (contains r h)]
let contains_lemma #a h r = ()
(* Type of references that refines the standard notion of references by
witnessing that the given reference is allocated in every future heap. *)
type ref a = r:ref a{ist_witnessed (contains r)}
(* Assuming a source of freshness for references for a given heap. *)
assume val gen_ref : #a:Type ->
h:FStar.Heap.heap ->
Tot (r:ref a{r `Heap.unused_in` h})
(* Pre- and postconditions for the allocated references instance of IST. *)
let st_pre = FStar.Heap.heap -> Type0
let st_post (a:Type) = a -> FStar.Heap.heap -> Type0
let st_wp (a:Type) = st_post a -> Tot st_pre
(* The allocated references instance of IST. *)
effect AllocST (a:Type)
(pre:st_pre)
(post:FStar.Heap.heap -> Tot (st_post a))
=
IST a pre post
(* Allocation, reading and writing operations. *)
val alloc : #a:Type ->
x:a ->
AllocST (ref a) (fun _ -> True)
(fun h0 r h1 -> r `Heap.unused_in` h0 /\
FStar.Heap.contains h1 r /\ | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.ST.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Witnessed.fsti.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "AllocSTwHeaps.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Monotonic.Witnessed",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: a -> AllocSTwHeaps.AllocST (AllocSTwHeaps.ref a) | AllocSTwHeaps.AllocST | [] | [] | [
"AllocSTwHeaps.ref",
"Prims.unit",
"AllocSTwHeaps.ist_witness",
"AllocSTwHeaps.contains",
"AllocSTwHeaps.ist_put",
"AllocSTwHeaps.upd",
"FStar.Monotonic.Heap.unused_in",
"FStar.Heap.trivial_preorder",
"AllocSTwHeaps.gen_ref",
"FStar.Monotonic.Heap.heap",
"AllocSTwHeaps.ist_get"
] | [] | false | true | false | false | false | let alloc #a x =
| let h = ist_get () in
let r = gen_ref h in
ist_put (upd h r x);
ist_witness (contains r);
r | false |
AllocSTwHeaps.fst | AllocSTwHeaps.precise_write | val precise_write : #a:Type ->
r:ref a ->
x:a ->
AllocST unit (fun h0 -> FStar.Heap.contains h0 r)
(fun h0 _ h1 -> h1 == FStar.Heap.upd h0 r x) | val precise_write : #a:Type ->
r:ref a ->
x:a ->
AllocST unit (fun h0 -> FStar.Heap.contains h0 r)
(fun h0 _ h1 -> h1 == FStar.Heap.upd h0 r x) | let precise_write #a r x =
let h = ist_get () in
ist_put (upd h r x) | {
"file_name": "examples/preorders/AllocSTwHeaps.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 21,
"end_line": 189,
"start_col": 0,
"start_line": 187
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module AllocSTwHeaps
open FStar.ST
open FStar.Preorder
open FStar.Monotonic.Witnessed
//giving ourselves two non-ghost versions of the heap sel/upd functions
assume val sel: h:FStar.Heap.heap -> r:ref 'a -> Tot (x:'a{x == FStar.Heap.sel h r})
assume val upd: h:FStar.Heap.heap -> r:ref 'a -> v:'a -> Tot (h':FStar.Heap.heap{h' == FStar.Heap.upd h r v})
(* The preorder on heaps for recalling that allocated
references remain allocated in all future heaps. *)
//NB: needed to restrict a:Type0, so that IST doesn't become
// too universe polymorphic. This restriction is probably ok in practice ...
// ... i don't imagine storing things beyond Type0 in the heap
// Besides, if we allow that, then we may need to account for non-termination
let heap_rel (h0:FStar.Heap.heap) (h1:FStar.Heap.heap) =
forall (a:Type0) (r:ref a) . FStar.Heap.contains h0 r ==> FStar.Heap.contains h1 r
(* *************************************************** *)
(*
A temporary definition of preorder-indexed state
monads specialized to the allocated references
instance, in order to make sub-effecting to work.
Using (FStar.Heap.heap) and (heap_rel) for the
statespace and the relation on it, which otherwise
would be given by parameters.
*)
(* Preconditions, postconditions and WPs for the preorder-indexed state monad. *)
let ist_pre (state:Type) = state -> Type0
let ist_post (state:Type) (a:Type) = a -> state -> Type0
let ist_wp (state:Type) (a:Type) = ist_post state a -> Tot (ist_pre state)
(* A WP-style preorder-indexed state monad specialised for the allocated references instance. *)
new_effect ISTATE = STATE_h FStar.Heap.heap
(* DIV is a sub-effect/sub-monad of the allocated references instance of the preorder-indexed monad. *)
unfold let lift_div_istate (state:Type) (rel:preorder state)
(a:Type) (wp:pure_wp a) (p:ist_post state a) (s:state) = wp (fun x -> p x s)
sub_effect DIV ~> ISTATE = lift_div_istate FStar.Heap.heap heap_rel
(*A pre- and postcondition version of this preorder-indexed state monad. *)
effect IST (a:Type)
(pre:ist_pre FStar.Heap.heap)
(post:(FStar.Heap.heap -> Tot (ist_post FStar.Heap.heap a)))
=
ISTATE a (fun p s0 -> pre s0 /\ (forall x s1 . pre s0 /\ post s0 x s1 ==> p x s1))
(* A box-like modality for witnessed stable predicates for IST. *)
let ist_witnessed (p:predicate FStar.Heap.heap{stable p heap_rel}) = witnessed heap_rel p
(* Generic effects (operations) for IST. *)
assume val ist_get : unit -> IST FStar.Heap.heap (fun s0 -> True) (fun s0 s s1 -> s0 == s /\ s == s1)
assume val ist_put : x:FStar.Heap.heap ->
IST unit (fun s0 -> heap_rel s0 x) (fun s0 _ s1 -> s1 == x)
assume val ist_witness : p:predicate FStar.Heap.heap{stable p heap_rel} ->
IST unit (fun s0 -> p s0) (fun s0 _ s1 -> s0 == s1 /\ ist_witnessed p)
assume val ist_recall : p:predicate FStar.Heap.heap{stable p heap_rel} ->
IST unit (fun _ -> ist_witnessed p) (fun s0 _ s1 -> s0 == s1 /\ p s1)
(* *************************************************** *)
(* Swapping the reference and heap arguments of (FStar.Heap.contains)
to use it in point-free style in (witness) and (recall). *)
let contains (#a:Type) (r:ref a) (h:FStar.Heap.heap) =
b2t (FStar.StrongExcludedMiddle.strong_excluded_middle (FStar.Heap.contains h r))
val contains_lemma : #a:Type ->
h:FStar.Heap.heap ->
r:ref a ->
Lemma (requires (contains r h))
(ensures (FStar.Heap.contains h r))
[SMTPat (contains r h)]
let contains_lemma #a h r = ()
(* Type of references that refines the standard notion of references by
witnessing that the given reference is allocated in every future heap. *)
type ref a = r:ref a{ist_witnessed (contains r)}
(* Assuming a source of freshness for references for a given heap. *)
assume val gen_ref : #a:Type ->
h:FStar.Heap.heap ->
Tot (r:ref a{r `Heap.unused_in` h})
(* Pre- and postconditions for the allocated references instance of IST. *)
let st_pre = FStar.Heap.heap -> Type0
let st_post (a:Type) = a -> FStar.Heap.heap -> Type0
let st_wp (a:Type) = st_post a -> Tot st_pre
(* The allocated references instance of IST. *)
effect AllocST (a:Type)
(pre:st_pre)
(post:FStar.Heap.heap -> Tot (st_post a))
=
IST a pre post
(* Allocation, reading and writing operations. *)
val alloc : #a:Type ->
x:a ->
AllocST (ref a) (fun _ -> True)
(fun h0 r h1 -> r `Heap.unused_in` h0 /\
FStar.Heap.contains h1 r /\
h1 == FStar.Heap.upd h0 r x)
let alloc #a x =
let h = ist_get () in
let r = gen_ref h in
ist_put (upd h r x);
ist_witness (contains r);
r
val read : #a:Type ->
r:ref a ->
AllocST a (fun _ -> True)
(fun h0 x h1 -> h0 == h1 /\
x == FStar.Heap.sel h1 r)
let read #a r =
let h = ist_get () in
sel h r
val write : #a:Type ->
r:ref a ->
x:a ->
AllocST unit (fun h0 -> FStar.Heap.contains h0 r)
(fun h0 _ h1 -> h1 == FStar.Heap.upd h0 r x)
let write #a r x =
let h = ist_get () in
ist_put (upd h r x)
(* Write operation with a more precise type. *)
val precise_write : #a:Type ->
r:ref a ->
x:a ->
AllocST unit (fun h0 -> FStar.Heap.contains h0 r) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.ST.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Witnessed.fsti.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "AllocSTwHeaps.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Monotonic.Witnessed",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | r: AllocSTwHeaps.ref a -> x: a -> AllocSTwHeaps.AllocST Prims.unit | AllocSTwHeaps.AllocST | [] | [] | [
"AllocSTwHeaps.ref",
"AllocSTwHeaps.ist_put",
"AllocSTwHeaps.upd",
"Prims.unit",
"FStar.Monotonic.Heap.heap",
"AllocSTwHeaps.ist_get"
] | [] | false | true | false | false | false | let precise_write #a r x =
| let h = ist_get () in
ist_put (upd h r x) | false |
AllocSTwHeaps.fst | AllocSTwHeaps.recall | val recall : #a:Type ->
r:ref a ->
AllocST unit (fun h0 -> True)
(fun h0 _ h1 -> h0 == h1 /\
FStar.Heap.contains h1 r) | val recall : #a:Type ->
r:ref a ->
AllocST unit (fun h0 -> True)
(fun h0 _ h1 -> h0 == h1 /\
FStar.Heap.contains h1 r) | let recall #a r =
ist_recall (contains r) | {
"file_name": "examples/preorders/AllocSTwHeaps.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 25,
"end_line": 200,
"start_col": 0,
"start_line": 199
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module AllocSTwHeaps
open FStar.ST
open FStar.Preorder
open FStar.Monotonic.Witnessed
//giving ourselves two non-ghost versions of the heap sel/upd functions
assume val sel: h:FStar.Heap.heap -> r:ref 'a -> Tot (x:'a{x == FStar.Heap.sel h r})
assume val upd: h:FStar.Heap.heap -> r:ref 'a -> v:'a -> Tot (h':FStar.Heap.heap{h' == FStar.Heap.upd h r v})
(* The preorder on heaps for recalling that allocated
references remain allocated in all future heaps. *)
//NB: needed to restrict a:Type0, so that IST doesn't become
// too universe polymorphic. This restriction is probably ok in practice ...
// ... i don't imagine storing things beyond Type0 in the heap
// Besides, if we allow that, then we may need to account for non-termination
let heap_rel (h0:FStar.Heap.heap) (h1:FStar.Heap.heap) =
forall (a:Type0) (r:ref a) . FStar.Heap.contains h0 r ==> FStar.Heap.contains h1 r
(* *************************************************** *)
(*
A temporary definition of preorder-indexed state
monads specialized to the allocated references
instance, in order to make sub-effecting to work.
Using (FStar.Heap.heap) and (heap_rel) for the
statespace and the relation on it, which otherwise
would be given by parameters.
*)
(* Preconditions, postconditions and WPs for the preorder-indexed state monad. *)
let ist_pre (state:Type) = state -> Type0
let ist_post (state:Type) (a:Type) = a -> state -> Type0
let ist_wp (state:Type) (a:Type) = ist_post state a -> Tot (ist_pre state)
(* A WP-style preorder-indexed state monad specialised for the allocated references instance. *)
new_effect ISTATE = STATE_h FStar.Heap.heap
(* DIV is a sub-effect/sub-monad of the allocated references instance of the preorder-indexed monad. *)
unfold let lift_div_istate (state:Type) (rel:preorder state)
(a:Type) (wp:pure_wp a) (p:ist_post state a) (s:state) = wp (fun x -> p x s)
sub_effect DIV ~> ISTATE = lift_div_istate FStar.Heap.heap heap_rel
(*A pre- and postcondition version of this preorder-indexed state monad. *)
effect IST (a:Type)
(pre:ist_pre FStar.Heap.heap)
(post:(FStar.Heap.heap -> Tot (ist_post FStar.Heap.heap a)))
=
ISTATE a (fun p s0 -> pre s0 /\ (forall x s1 . pre s0 /\ post s0 x s1 ==> p x s1))
(* A box-like modality for witnessed stable predicates for IST. *)
let ist_witnessed (p:predicate FStar.Heap.heap{stable p heap_rel}) = witnessed heap_rel p
(* Generic effects (operations) for IST. *)
assume val ist_get : unit -> IST FStar.Heap.heap (fun s0 -> True) (fun s0 s s1 -> s0 == s /\ s == s1)
assume val ist_put : x:FStar.Heap.heap ->
IST unit (fun s0 -> heap_rel s0 x) (fun s0 _ s1 -> s1 == x)
assume val ist_witness : p:predicate FStar.Heap.heap{stable p heap_rel} ->
IST unit (fun s0 -> p s0) (fun s0 _ s1 -> s0 == s1 /\ ist_witnessed p)
assume val ist_recall : p:predicate FStar.Heap.heap{stable p heap_rel} ->
IST unit (fun _ -> ist_witnessed p) (fun s0 _ s1 -> s0 == s1 /\ p s1)
(* *************************************************** *)
(* Swapping the reference and heap arguments of (FStar.Heap.contains)
to use it in point-free style in (witness) and (recall). *)
let contains (#a:Type) (r:ref a) (h:FStar.Heap.heap) =
b2t (FStar.StrongExcludedMiddle.strong_excluded_middle (FStar.Heap.contains h r))
val contains_lemma : #a:Type ->
h:FStar.Heap.heap ->
r:ref a ->
Lemma (requires (contains r h))
(ensures (FStar.Heap.contains h r))
[SMTPat (contains r h)]
let contains_lemma #a h r = ()
(* Type of references that refines the standard notion of references by
witnessing that the given reference is allocated in every future heap. *)
type ref a = r:ref a{ist_witnessed (contains r)}
(* Assuming a source of freshness for references for a given heap. *)
assume val gen_ref : #a:Type ->
h:FStar.Heap.heap ->
Tot (r:ref a{r `Heap.unused_in` h})
(* Pre- and postconditions for the allocated references instance of IST. *)
let st_pre = FStar.Heap.heap -> Type0
let st_post (a:Type) = a -> FStar.Heap.heap -> Type0
let st_wp (a:Type) = st_post a -> Tot st_pre
(* The allocated references instance of IST. *)
effect AllocST (a:Type)
(pre:st_pre)
(post:FStar.Heap.heap -> Tot (st_post a))
=
IST a pre post
(* Allocation, reading and writing operations. *)
val alloc : #a:Type ->
x:a ->
AllocST (ref a) (fun _ -> True)
(fun h0 r h1 -> r `Heap.unused_in` h0 /\
FStar.Heap.contains h1 r /\
h1 == FStar.Heap.upd h0 r x)
let alloc #a x =
let h = ist_get () in
let r = gen_ref h in
ist_put (upd h r x);
ist_witness (contains r);
r
val read : #a:Type ->
r:ref a ->
AllocST a (fun _ -> True)
(fun h0 x h1 -> h0 == h1 /\
x == FStar.Heap.sel h1 r)
let read #a r =
let h = ist_get () in
sel h r
val write : #a:Type ->
r:ref a ->
x:a ->
AllocST unit (fun h0 -> FStar.Heap.contains h0 r)
(fun h0 _ h1 -> h1 == FStar.Heap.upd h0 r x)
let write #a r x =
let h = ist_get () in
ist_put (upd h r x)
(* Write operation with a more precise type. *)
val precise_write : #a:Type ->
r:ref a ->
x:a ->
AllocST unit (fun h0 -> FStar.Heap.contains h0 r)
(fun h0 _ h1 -> h1 == FStar.Heap.upd h0 r x)
let precise_write #a r x =
let h = ist_get () in
ist_put (upd h r x)
(* Operation for recalling that the current heap contains any reference we can apply this operation to. *)
val recall : #a:Type ->
r:ref a ->
AllocST unit (fun h0 -> True)
(fun h0 _ h1 -> h0 == h1 /\ | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.ST.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Witnessed.fsti.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "AllocSTwHeaps.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Monotonic.Witnessed",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | r: AllocSTwHeaps.ref a -> AllocSTwHeaps.AllocST Prims.unit | AllocSTwHeaps.AllocST | [] | [] | [
"AllocSTwHeaps.ref",
"AllocSTwHeaps.ist_recall",
"AllocSTwHeaps.contains",
"Prims.unit"
] | [] | false | true | false | false | false | let recall #a r =
| ist_recall (contains r) | false |
AllocSTwHeaps.fst | AllocSTwHeaps.read | val read : #a:Type ->
r:ref a ->
AllocST a (fun _ -> True)
(fun h0 x h1 -> h0 == h1 /\
x == FStar.Heap.sel h1 r) | val read : #a:Type ->
r:ref a ->
AllocST a (fun _ -> True)
(fun h0 x h1 -> h0 == h1 /\
x == FStar.Heap.sel h1 r) | let read #a r =
let h = ist_get () in
sel h r | {
"file_name": "examples/preorders/AllocSTwHeaps.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 9,
"end_line": 167,
"start_col": 0,
"start_line": 165
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module AllocSTwHeaps
open FStar.ST
open FStar.Preorder
open FStar.Monotonic.Witnessed
//giving ourselves two non-ghost versions of the heap sel/upd functions
assume val sel: h:FStar.Heap.heap -> r:ref 'a -> Tot (x:'a{x == FStar.Heap.sel h r})
assume val upd: h:FStar.Heap.heap -> r:ref 'a -> v:'a -> Tot (h':FStar.Heap.heap{h' == FStar.Heap.upd h r v})
(* The preorder on heaps for recalling that allocated
references remain allocated in all future heaps. *)
//NB: needed to restrict a:Type0, so that IST doesn't become
// too universe polymorphic. This restriction is probably ok in practice ...
// ... i don't imagine storing things beyond Type0 in the heap
// Besides, if we allow that, then we may need to account for non-termination
let heap_rel (h0:FStar.Heap.heap) (h1:FStar.Heap.heap) =
forall (a:Type0) (r:ref a) . FStar.Heap.contains h0 r ==> FStar.Heap.contains h1 r
(* *************************************************** *)
(*
A temporary definition of preorder-indexed state
monads specialized to the allocated references
instance, in order to make sub-effecting to work.
Using (FStar.Heap.heap) and (heap_rel) for the
statespace and the relation on it, which otherwise
would be given by parameters.
*)
(* Preconditions, postconditions and WPs for the preorder-indexed state monad. *)
let ist_pre (state:Type) = state -> Type0
let ist_post (state:Type) (a:Type) = a -> state -> Type0
let ist_wp (state:Type) (a:Type) = ist_post state a -> Tot (ist_pre state)
(* A WP-style preorder-indexed state monad specialised for the allocated references instance. *)
new_effect ISTATE = STATE_h FStar.Heap.heap
(* DIV is a sub-effect/sub-monad of the allocated references instance of the preorder-indexed monad. *)
unfold let lift_div_istate (state:Type) (rel:preorder state)
(a:Type) (wp:pure_wp a) (p:ist_post state a) (s:state) = wp (fun x -> p x s)
sub_effect DIV ~> ISTATE = lift_div_istate FStar.Heap.heap heap_rel
(*A pre- and postcondition version of this preorder-indexed state monad. *)
effect IST (a:Type)
(pre:ist_pre FStar.Heap.heap)
(post:(FStar.Heap.heap -> Tot (ist_post FStar.Heap.heap a)))
=
ISTATE a (fun p s0 -> pre s0 /\ (forall x s1 . pre s0 /\ post s0 x s1 ==> p x s1))
(* A box-like modality for witnessed stable predicates for IST. *)
let ist_witnessed (p:predicate FStar.Heap.heap{stable p heap_rel}) = witnessed heap_rel p
(* Generic effects (operations) for IST. *)
assume val ist_get : unit -> IST FStar.Heap.heap (fun s0 -> True) (fun s0 s s1 -> s0 == s /\ s == s1)
assume val ist_put : x:FStar.Heap.heap ->
IST unit (fun s0 -> heap_rel s0 x) (fun s0 _ s1 -> s1 == x)
assume val ist_witness : p:predicate FStar.Heap.heap{stable p heap_rel} ->
IST unit (fun s0 -> p s0) (fun s0 _ s1 -> s0 == s1 /\ ist_witnessed p)
assume val ist_recall : p:predicate FStar.Heap.heap{stable p heap_rel} ->
IST unit (fun _ -> ist_witnessed p) (fun s0 _ s1 -> s0 == s1 /\ p s1)
(* *************************************************** *)
(* Swapping the reference and heap arguments of (FStar.Heap.contains)
to use it in point-free style in (witness) and (recall). *)
let contains (#a:Type) (r:ref a) (h:FStar.Heap.heap) =
b2t (FStar.StrongExcludedMiddle.strong_excluded_middle (FStar.Heap.contains h r))
val contains_lemma : #a:Type ->
h:FStar.Heap.heap ->
r:ref a ->
Lemma (requires (contains r h))
(ensures (FStar.Heap.contains h r))
[SMTPat (contains r h)]
let contains_lemma #a h r = ()
(* Type of references that refines the standard notion of references by
witnessing that the given reference is allocated in every future heap. *)
type ref a = r:ref a{ist_witnessed (contains r)}
(* Assuming a source of freshness for references for a given heap. *)
assume val gen_ref : #a:Type ->
h:FStar.Heap.heap ->
Tot (r:ref a{r `Heap.unused_in` h})
(* Pre- and postconditions for the allocated references instance of IST. *)
let st_pre = FStar.Heap.heap -> Type0
let st_post (a:Type) = a -> FStar.Heap.heap -> Type0
let st_wp (a:Type) = st_post a -> Tot st_pre
(* The allocated references instance of IST. *)
effect AllocST (a:Type)
(pre:st_pre)
(post:FStar.Heap.heap -> Tot (st_post a))
=
IST a pre post
(* Allocation, reading and writing operations. *)
val alloc : #a:Type ->
x:a ->
AllocST (ref a) (fun _ -> True)
(fun h0 r h1 -> r `Heap.unused_in` h0 /\
FStar.Heap.contains h1 r /\
h1 == FStar.Heap.upd h0 r x)
let alloc #a x =
let h = ist_get () in
let r = gen_ref h in
ist_put (upd h r x);
ist_witness (contains r);
r
val read : #a:Type ->
r:ref a ->
AllocST a (fun _ -> True)
(fun h0 x h1 -> h0 == h1 /\ | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.ST.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Witnessed.fsti.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "AllocSTwHeaps.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Monotonic.Witnessed",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | r: AllocSTwHeaps.ref a -> AllocSTwHeaps.AllocST a | AllocSTwHeaps.AllocST | [] | [] | [
"AllocSTwHeaps.ref",
"AllocSTwHeaps.sel",
"FStar.Monotonic.Heap.heap",
"AllocSTwHeaps.ist_get"
] | [] | false | true | false | false | false | let read #a r =
| let h = ist_get () in
sel h r | false |
AllocSTwHeaps.fst | AllocSTwHeaps.write | val write : #a:Type ->
r:ref a ->
x:a ->
AllocST unit (fun h0 -> FStar.Heap.contains h0 r)
(fun h0 _ h1 -> h1 == FStar.Heap.upd h0 r x) | val write : #a:Type ->
r:ref a ->
x:a ->
AllocST unit (fun h0 -> FStar.Heap.contains h0 r)
(fun h0 _ h1 -> h1 == FStar.Heap.upd h0 r x) | let write #a r x =
let h = ist_get () in
ist_put (upd h r x) | {
"file_name": "examples/preorders/AllocSTwHeaps.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 21,
"end_line": 177,
"start_col": 0,
"start_line": 175
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module AllocSTwHeaps
open FStar.ST
open FStar.Preorder
open FStar.Monotonic.Witnessed
//giving ourselves two non-ghost versions of the heap sel/upd functions
assume val sel: h:FStar.Heap.heap -> r:ref 'a -> Tot (x:'a{x == FStar.Heap.sel h r})
assume val upd: h:FStar.Heap.heap -> r:ref 'a -> v:'a -> Tot (h':FStar.Heap.heap{h' == FStar.Heap.upd h r v})
(* The preorder on heaps for recalling that allocated
references remain allocated in all future heaps. *)
//NB: needed to restrict a:Type0, so that IST doesn't become
// too universe polymorphic. This restriction is probably ok in practice ...
// ... i don't imagine storing things beyond Type0 in the heap
// Besides, if we allow that, then we may need to account for non-termination
let heap_rel (h0:FStar.Heap.heap) (h1:FStar.Heap.heap) =
forall (a:Type0) (r:ref a) . FStar.Heap.contains h0 r ==> FStar.Heap.contains h1 r
(* *************************************************** *)
(*
A temporary definition of preorder-indexed state
monads specialized to the allocated references
instance, in order to make sub-effecting to work.
Using (FStar.Heap.heap) and (heap_rel) for the
statespace and the relation on it, which otherwise
would be given by parameters.
*)
(* Preconditions, postconditions and WPs for the preorder-indexed state monad. *)
let ist_pre (state:Type) = state -> Type0
let ist_post (state:Type) (a:Type) = a -> state -> Type0
let ist_wp (state:Type) (a:Type) = ist_post state a -> Tot (ist_pre state)
(* A WP-style preorder-indexed state monad specialised for the allocated references instance. *)
new_effect ISTATE = STATE_h FStar.Heap.heap
(* DIV is a sub-effect/sub-monad of the allocated references instance of the preorder-indexed monad. *)
unfold let lift_div_istate (state:Type) (rel:preorder state)
(a:Type) (wp:pure_wp a) (p:ist_post state a) (s:state) = wp (fun x -> p x s)
sub_effect DIV ~> ISTATE = lift_div_istate FStar.Heap.heap heap_rel
(*A pre- and postcondition version of this preorder-indexed state monad. *)
effect IST (a:Type)
(pre:ist_pre FStar.Heap.heap)
(post:(FStar.Heap.heap -> Tot (ist_post FStar.Heap.heap a)))
=
ISTATE a (fun p s0 -> pre s0 /\ (forall x s1 . pre s0 /\ post s0 x s1 ==> p x s1))
(* A box-like modality for witnessed stable predicates for IST. *)
let ist_witnessed (p:predicate FStar.Heap.heap{stable p heap_rel}) = witnessed heap_rel p
(* Generic effects (operations) for IST. *)
assume val ist_get : unit -> IST FStar.Heap.heap (fun s0 -> True) (fun s0 s s1 -> s0 == s /\ s == s1)
assume val ist_put : x:FStar.Heap.heap ->
IST unit (fun s0 -> heap_rel s0 x) (fun s0 _ s1 -> s1 == x)
assume val ist_witness : p:predicate FStar.Heap.heap{stable p heap_rel} ->
IST unit (fun s0 -> p s0) (fun s0 _ s1 -> s0 == s1 /\ ist_witnessed p)
assume val ist_recall : p:predicate FStar.Heap.heap{stable p heap_rel} ->
IST unit (fun _ -> ist_witnessed p) (fun s0 _ s1 -> s0 == s1 /\ p s1)
(* *************************************************** *)
(* Swapping the reference and heap arguments of (FStar.Heap.contains)
to use it in point-free style in (witness) and (recall). *)
let contains (#a:Type) (r:ref a) (h:FStar.Heap.heap) =
b2t (FStar.StrongExcludedMiddle.strong_excluded_middle (FStar.Heap.contains h r))
val contains_lemma : #a:Type ->
h:FStar.Heap.heap ->
r:ref a ->
Lemma (requires (contains r h))
(ensures (FStar.Heap.contains h r))
[SMTPat (contains r h)]
let contains_lemma #a h r = ()
(* Type of references that refines the standard notion of references by
witnessing that the given reference is allocated in every future heap. *)
type ref a = r:ref a{ist_witnessed (contains r)}
(* Assuming a source of freshness for references for a given heap. *)
assume val gen_ref : #a:Type ->
h:FStar.Heap.heap ->
Tot (r:ref a{r `Heap.unused_in` h})
(* Pre- and postconditions for the allocated references instance of IST. *)
let st_pre = FStar.Heap.heap -> Type0
let st_post (a:Type) = a -> FStar.Heap.heap -> Type0
let st_wp (a:Type) = st_post a -> Tot st_pre
(* The allocated references instance of IST. *)
effect AllocST (a:Type)
(pre:st_pre)
(post:FStar.Heap.heap -> Tot (st_post a))
=
IST a pre post
(* Allocation, reading and writing operations. *)
val alloc : #a:Type ->
x:a ->
AllocST (ref a) (fun _ -> True)
(fun h0 r h1 -> r `Heap.unused_in` h0 /\
FStar.Heap.contains h1 r /\
h1 == FStar.Heap.upd h0 r x)
let alloc #a x =
let h = ist_get () in
let r = gen_ref h in
ist_put (upd h r x);
ist_witness (contains r);
r
val read : #a:Type ->
r:ref a ->
AllocST a (fun _ -> True)
(fun h0 x h1 -> h0 == h1 /\
x == FStar.Heap.sel h1 r)
let read #a r =
let h = ist_get () in
sel h r
val write : #a:Type ->
r:ref a ->
x:a ->
AllocST unit (fun h0 -> FStar.Heap.contains h0 r) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.ST.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.Witnessed.fsti.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "AllocSTwHeaps.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Monotonic.Witnessed",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | r: AllocSTwHeaps.ref a -> x: a -> AllocSTwHeaps.AllocST Prims.unit | AllocSTwHeaps.AllocST | [] | [] | [
"AllocSTwHeaps.ref",
"AllocSTwHeaps.ist_put",
"AllocSTwHeaps.upd",
"Prims.unit",
"FStar.Monotonic.Heap.heap",
"AllocSTwHeaps.ist_get"
] | [] | false | true | false | false | false | let write #a r x =
| let h = ist_get () in
ist_put (upd h r x) | false |
LowStar.Printf.fst | LowStar.Printf.skip' | val skip' (s: format_string) : interpret_format_string s | val skip' (s: format_string) : interpret_format_string s | let skip' (s:format_string) : interpret_format_string s =
normalize_term
(match parse_format_string s with
| Some frags -> aux frags [] (fun _ -> ())) | {
"file_name": "ulib/LowStar.Printf.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 47,
"end_line": 492,
"start_col": 0,
"start_line": 489
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LowStar.Printf
/// This module provides imperative printing functions for several
/// primitive Low* types, including
/// -- booleans (%b)
/// -- characters (%c)
/// -- strings (%s)
/// -- machine integers
/// (UInt8.t as %uy, UInt16.t as %us, UInt32.t as %ul, and UInt64.t as %uL;
/// Int8.t as %y, Int16.t as %i, Int32.t as %l , and Int64.t as %L)
/// -- and arrays (aka buffers) of these base types formatted
/// as %xN, where N is the format specifier for the array element type
/// e.g., %xuy for buffers of UInt8.t
/// The main function of this module is `printf`
/// There are a few main differences relative to C printf
/// -- The format specifiers are different (see above)
///
/// -- For technical reasons explained below, an extra dummy
/// argument `done` has to be provided at the end for the
/// computation to have any effect.
///
/// E.g., one must write
/// `printf "%b %c" true 'c' done`
/// rather than just
/// `printf "%b %c" true 'c'`
///
/// -- When printing arrays, two arguments must be passed; the
/// length of the array fragment to be formatted and the array
/// itself
///
/// -- When extracted, rather than producing a C `printf` (which
/// does not, e.g., support printing of dynamically sized
/// arrays), our `printf` is specialized to a sequence of calls
/// to primitive printers for each supported type
///
/// Before diving into the technical details of how this module works,
/// you might want to see a sample usage at the very end of this file.
open FStar.Char
open FStar.String
open FStar.HyperStack.ST
module L = FStar.List.Tot
module LB = LowStar.Monotonic.Buffer
/// `lmbuffer a r s l` is
/// - a monotonic buffer of `a`
/// - governed by preorders `r` and `s`
/// - with length `l`
let lmbuffer a r s l =
b:LB.mbuffer a r s{
LB.len b == l
}
/// `StTrivial`: A effect abbreviation for a stateful computation
/// with no precondition, and which does not change the state
effect StTrivial (a:Type) =
Stack a
(requires fun h -> True)
(ensures fun h0 _ h1 -> h0==h1)
/// `StBuf a b`: A effect abbreviation for a stateful computation
/// that may read `b` does not change the state
effect StBuf (a:Type) #t #r #s #l (b:lmbuffer t r s l) =
Stack a
(requires fun h -> LB.live h b)
(ensures (fun h0 _ h1 -> h0 == h1))
/// Primitive printers for all the types supported by this module
assume val print_string: string -> StTrivial unit
assume val print_char : char -> StTrivial unit
assume val print_u8 : UInt8.t -> StTrivial unit
assume val print_u16 : UInt16.t -> StTrivial unit
assume val print_u32 : UInt32.t -> StTrivial unit
assume val print_u64 : UInt64.t -> StTrivial unit
assume val print_i8 : Int8.t -> StTrivial unit
assume val print_i16 : Int16.t -> StTrivial unit
assume val print_i32 : Int32.t -> StTrivial unit
assume val print_i64 : Int64.t -> StTrivial unit
assume val print_bool : bool -> StTrivial unit
assume val print_lmbuffer_bool (l:_) (#r:_) (#s:_) (b:lmbuffer bool r s l) : StBuf unit b
assume val print_lmbuffer_char (l:_) (#r:_) (#s:_) (b:lmbuffer char r s l) : StBuf unit b
assume val print_lmbuffer_string (l:_) (#r:_) (#s:_) (b:lmbuffer string r s l) : StBuf unit b
assume val print_lmbuffer_u8 (l:_) (#r:_) (#s:_) (b:lmbuffer UInt8.t r s l) : StBuf unit b
assume val print_lmbuffer_u16 (l:_) (#r:_) (#s:_) (b:lmbuffer UInt16.t r s l) : StBuf unit b
assume val print_lmbuffer_u32 (l:_) (#r:_) (#s:_) (b:lmbuffer UInt32.t r s l) : StBuf unit b
assume val print_lmbuffer_u64 (l:_) (#r:_) (#s:_) (b:lmbuffer UInt64.t r s l) : StBuf unit b
assume val print_lmbuffer_i8 (l:_) (#r:_) (#s:_) (b:lmbuffer Int8.t r s l) : StBuf unit b
assume val print_lmbuffer_i16 (l:_) (#r:_) (#s:_) (b:lmbuffer Int16.t r s l) : StBuf unit b
assume val print_lmbuffer_i32 (l:_) (#r:_) (#s:_) (b:lmbuffer Int32.t r s l) : StBuf unit b
assume val print_lmbuffer_i64 (l:_) (#r:_) (#s:_) (b:lmbuffer Int64.t r s l) : StBuf unit b
/// An attribute to control reduction
noextract irreducible
let __reduce__ = unit
/// Base types supported so far
noextract
type base_typ =
| Bool
| Char
| String
| U8
| U16
| U32
| U64
| I8
| I16
| I32
| I64
/// Argument types are base types and arrays thereof
/// Or polymorphic arguments specified by "%a"
noextract
type arg =
| Base of base_typ
| Array of base_typ
| Any
/// Interpreting a `base_typ` as a type
[@@__reduce__]
noextract
let base_typ_as_type (b:base_typ) : Type0 =
match b with
| Bool -> bool
| Char -> char
| String -> string
| U8 -> FStar.UInt8.t
| U16 -> FStar.UInt16.t
| U32 -> FStar.UInt32.t
| U64 -> FStar.UInt64.t
| I8 -> FStar.Int8.t
| I16 -> FStar.Int16.t
| I32 -> FStar.Int32.t
| I64 -> FStar.Int64.t
/// `fragment`: A format string is parsed into a list of fragments of
/// string literals and other arguments that need to be spliced in
/// (interpolated)
noextract
type fragment =
| Frag of string
| Interpolate of arg
noextract
let fragments = list fragment
/// `parse_format s`:
/// Parses a list of characters in a format string into a list of fragments
/// Or None, in case the format string is invalid
[@@__reduce__]
noextract inline_for_extraction
let rec parse_format
(s:list char)
: Tot (option fragments)
(decreases (L.length s))
= let add_dir (d:arg) (ods : option fragments)
= match ods with
| None -> None
| Some ds -> Some (Interpolate d::ds)
in
let head_buffer (ods:option fragments)
= match ods with
| Some (Interpolate (Base t) :: rest) -> Some (Interpolate (Array t) :: rest)
| _ -> None
in
let cons_frag (c:char) (ods:option fragments)
= match ods with
| Some (Frag s::rest) -> Some (Frag (string_of_list (c :: list_of_string s)) :: rest)
| Some rest -> Some (Frag (string_of_list [c]) :: rest)
| _ -> None
in
match s with
| [] -> Some []
| ['%'] -> None
// %a... polymorphic arguments and preceded by their printers
| '%' :: 'a' :: s' ->
add_dir Any (parse_format s')
// %x... arrays of base types
| '%' :: 'x' :: s' ->
head_buffer (parse_format ('%' :: s'))
// %u ... Unsigned integers
| '%' :: 'u' :: s' -> begin
match s' with
| 'y' :: s'' -> add_dir (Base U8) (parse_format s'')
| 's' :: s'' -> add_dir (Base U16) (parse_format s'')
| 'l' :: s'' -> add_dir (Base U32) (parse_format s'')
| 'L' :: s'' -> add_dir (Base U64) (parse_format s'')
| _ -> None
end
| '%' :: c :: s' -> begin
match c with
| '%' -> cons_frag '%' (parse_format s')
| 'b' -> add_dir (Base Bool) (parse_format s')
| 'c' -> add_dir (Base Char) (parse_format s')
| 's' -> add_dir (Base String) (parse_format s')
| 'y' -> add_dir (Base I8) (parse_format s')
| 'i' -> add_dir (Base I16) (parse_format s')
| 'l' -> add_dir (Base I32) (parse_format s')
| 'L' -> add_dir (Base I64) (parse_format s')
| _ -> None
end
| c :: s' ->
cons_frag c (parse_format s')
/// `parse_format_string`: a wrapper around `parse_format`
[@@__reduce__]
noextract inline_for_extraction
let parse_format_string
(s:string)
: option fragments
= parse_format (list_of_string s)
/// `lift a` lifts the type `a` to a higher universe
noextract
type lift (a:Type u#a) : Type u#(max a b) =
| Lift : a -> lift a
/// `done` is a `unit` in universe 1
noextract
let done : lift unit = Lift u#0 u#1 ()
/// `arg_t`: interpreting an argument as a type
/// (in universe 1) since it is polymorphic in the preorders of a buffer
/// GM: Somehow, this needs to be a `let rec` (even if it not really recursive)
/// or print_frags fails to verify. I don't know why; the generated
/// VC and its encoding seem identical (modulo hash consing in the
/// latter).
[@@__reduce__]
noextract
let rec arg_t (a:arg) : Type u#1 =
match a with
| Base t -> lift (base_typ_as_type t)
| Array t -> (l:UInt32.t & r:_ & s:_ & lmbuffer (base_typ_as_type t) r s l)
| Any -> (a:Type0 & (a -> StTrivial unit) & a)
/// `frag_t`: a fragment is either a string literal or a argument to be interpolated
noextract
let frag_t = either string (a:arg & arg_t a)
/// `live_frags h l` is a liveness predicate on all the buffers in `l`
[@@__reduce__]
noextract
let rec live_frags (h:_) (l:list frag_t) : prop =
match l with
| [] -> True
| Inl _ :: rest -> live_frags h rest
| Inr a :: rest ->
(match a with
| (| Base _, _ |) -> live_frags h rest
| (| Any, _ |) -> live_frags h rest
| (| Array _, (| _, _, _, b |) |) -> LB.live h b /\ live_frags h rest)
/// `interpret_frags` interprets a list of fragments as a Low* function type
/// Note `l` is the fragments in L-to-R order (i.e., parsing order)
/// `acc` accumulates the fragment values in reverse order
[@@__reduce__]
noextract
let rec interpret_frags (l:fragments) (acc:list frag_t) : Type u#1 =
match l with
| [] ->
// Always a dummy argument at the end
// Ensures that all cases of this match
// have the same universe, i.e., u#1
lift u#0 u#1 unit
-> Stack unit
(requires fun h0 -> live_frags h0 acc)
(ensures fun h0 _ h1 -> h0 == h1)
| Interpolate (Base t) :: args ->
// Base types are simple: we just take one more argument
x:base_typ_as_type t ->
interpret_frags args (Inr (| Base t, Lift x |) :: acc)
| Interpolate (Array t) :: args ->
// Arrays are implicitly polymorphic in their preorders `r` and `s`
// which is what forces us to be in universe 1
// Note, the length `l` is explicit
l:UInt32.t ->
#r:LB.srel (base_typ_as_type t) ->
#s:LB.srel (base_typ_as_type t) ->
b:lmbuffer (base_typ_as_type t) r s l ->
interpret_frags args (Inr (| Array t, (| l, r, s, b |) |) :: acc)
| Interpolate Any :: args ->
#a:Type0 ->
p:(a -> StTrivial unit) ->
x:a ->
interpret_frags args (Inr (| Any, (| a, p, x |) |) :: acc)
| Frag s :: args ->
// Literal fragments do not incur an additional argument
// We just accumulate them and recur
interpret_frags args (Inl s :: acc)
/// `normal` A normalization marker with very specific steps enabled
noextract unfold
let normal (#a:Type) (x:a) : a =
FStar.Pervasives.norm
[iota;
zeta;
delta_attr [`%__reduce__; `%BigOps.__reduce__];
delta_only [`%Base?; `%Array?; `%Some?; `%Some?.v; `%list_of_string];
primops;
simplify]
x
/// `coerce`: A utility to trigger extensional equality of types
noextract
let coerce (x:'a{'a == 'b}) : 'b = x
/// `fragment_printer`: The type of a printer of fragments
noextract
let fragment_printer =
(acc:list frag_t)
-> Stack unit
(requires fun h0 -> live_frags h0 acc)
(ensures fun h0 _ h1 -> h0 == h1)
/// `print_frags`: Having accumulated all the pieces of a format
/// string and the arguments to the printed (i.e., the `list frag_t`),
/// this function does the actual work of printing them all using the
/// primitive printers
noextract inline_for_extraction
let rec print_frags (acc:list frag_t)
: Stack unit
(requires fun h0 -> live_frags h0 acc)
(ensures fun h0 _ h1 -> h0 == h1)
= match acc with
| [] -> ()
| hd::tl ->
print_frags tl;
(match hd with
| Inl s -> print_string s
| Inr (| Base t, Lift value |) ->
(match t with
| Bool -> print_bool value
| Char -> print_char value
| String -> print_string value
| U8 -> print_u8 value
| U16 -> print_u16 value
| U32 -> print_u32 value
| U64 -> print_u64 value
| I8 -> print_i8 value
| I16 -> print_i16 value
| I32 -> print_i32 value
| I64 -> print_i64 value)
| Inr (| Array t, (| l, r, s, value |) |) ->
(match t with
| Bool -> print_lmbuffer_bool l value
| Char -> print_lmbuffer_char l value
| String -> print_lmbuffer_string l value
| U8 -> print_lmbuffer_u8 l value
| U16 -> print_lmbuffer_u16 l value
| U32 -> print_lmbuffer_u32 l value
| U64 -> print_lmbuffer_u64 l value
| I8 -> print_lmbuffer_i8 l value
| I16 -> print_lmbuffer_i16 l value
| I32 -> print_lmbuffer_i32 l value
| I64 -> print_lmbuffer_i64 l value)
| Inr (| Any, (| _, printer, value |) |) ->
printer value)
[@@__reduce__]
let no_inst #a (#b:a -> Type) (f: (#x:a -> b x)) : unit -> #x:a -> b x = fun () -> f
[@@__reduce__]
let elim_unit_arrow #t (f:unit -> t) : t = f ()
// let test2 (f: (#a:Type -> a -> a)) : id_t 0 = test f ()
// let coerce #a (#b: (a -> Type)) ($f: (#x:a -> b x)) (t:Type{norm t == (#x:a -> b x)})
/// `aux frags acc`: This is the main workhorse which interprets a
/// parsed format string (`frags`) as a variadic, stateful function
[@@__reduce__]
noextract inline_for_extraction
let rec aux (frags:fragments) (acc:list frag_t) (fp: fragment_printer) : interpret_frags frags acc =
match frags with
| [] ->
let f (l:lift u#0 u#1 unit)
: Stack unit
(requires fun h0 -> live_frags h0 acc)
(ensures fun h0 _ h1 -> h0 == h1)
= fp acc
in
(f <: interpret_frags [] acc)
| Frag s :: rest ->
coerce (aux rest (Inl s :: acc) fp)
| Interpolate (Base t) :: args ->
let f (x:base_typ_as_type t)
: interpret_frags args (Inr (| Base t, Lift x |) :: acc)
= aux args (Inr (| Base t, Lift x |) :: acc) fp
in
f
| Interpolate (Array t) :: rest ->
let f :
l:UInt32.t
-> #r:LB.srel (base_typ_as_type t)
-> #s:LB.srel (base_typ_as_type t)
-> b:lmbuffer (base_typ_as_type t) r s l
-> interpret_frags rest (Inr (| Array t, (| l, r, s, b |) |) :: acc)
= fun l #r #s b -> aux rest (Inr (| Array t, (| l, r, s, b |) |) :: acc) fp
in
f <: interpret_frags (Interpolate (Array t) :: rest) acc
| Interpolate Any :: rest ->
let f :
unit
-> #a:Type
-> p:(a -> StTrivial unit)
-> x:a
-> interpret_frags rest (Inr (| Any, (| a, p, x |) |) :: acc)
= fun () #a p x -> aux rest (Inr (| Any, (| a, p, x |) |) :: acc) fp
in
elim_unit_arrow (no_inst (f ()) <: (unit -> interpret_frags (Interpolate Any :: rest) acc))
/// `format_string` : A valid format string is one that can be successfully parsed
[@@__reduce__]
noextract
let format_string = s:string{normal #bool (Some? (parse_format_string s))}
/// `interpret_format_string` parses a string into fragments and then
/// interprets it as a type
[@@__reduce__]
noextract
let interpret_format_string (s:format_string) : Type =
interpret_frags (Some?.v (parse_format_string s)) []
/// `printf'`: Almost there ... this has a variadic type
/// and calls the actual printers for all its arguments.
///
/// Note, the `normalize_term` in its body is crucial. It's what
/// allows the term to be specialized at extraction time.
noextract inline_for_extraction
let printf' (s:format_string) : interpret_format_string s =
normalize_term
(match parse_format_string s with
| Some frags -> aux frags [] print_frags)
/// `intro_normal_f`: a technical gadget to introduce
/// implicit normalization in the domain and co-domain of a function type
noextract inline_for_extraction
let intro_normal_f (#a:Type) (b: (a -> Type)) (f:(x:a -> b x))
: (x:(normal a) -> normal (b x))
= f
/// `printf`: The main function has type
/// `s:normal format_string -> normal (interpret_format_string s)`
/// Note:
/// This is the type F* infers for it and it is best to leave it that way
/// rather then writing it down and asking F* to re-check what it inferred.
///
/// Annotating it results in a needless additional proof obligation to
/// equate types after they are partially reduced, which is pointless.
noextract inline_for_extraction
val printf : s:normal format_string -> normal (interpret_format_string s)
let printf = intro_normal_f #format_string interpret_format_string printf'
/// `skip`: We also provide `skip`, a function that has the same type as printf
/// but normalizes to `()`, i.e., it prints nothing. This is useful for conditional
/// printing in debug code, for instance. | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.Printf.fst"
} | [
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "LB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.String",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Char",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: LowStar.Printf.format_string -> LowStar.Printf.interpret_format_string s | Prims.Tot | [
"total"
] | [] | [
"LowStar.Printf.format_string",
"FStar.Pervasives.normalize_term",
"LowStar.Printf.interpret_format_string",
"LowStar.Printf.parse_format_string",
"LowStar.Printf.fragments",
"LowStar.Printf.aux",
"Prims.Nil",
"LowStar.Printf.frag_t",
"Prims.list",
"Prims.unit"
] | [] | false | false | false | false | false | let skip' (s: format_string) : interpret_format_string s =
| normalize_term (match parse_format_string s with | Some frags -> aux frags [] (fun _ -> ())) | false |
LowStar.Printf.fst | LowStar.Printf.test2 | val test2 (x: (int * int)) (print_pair: ((int * int) -> StTrivial unit))
: Stack unit (requires (fun h0 -> True)) (ensures (fun h0 _ h1 -> h0 == h1)) | val test2 (x: (int * int)) (print_pair: ((int * int) -> StTrivial unit))
: Stack unit (requires (fun h0 -> True)) (ensures (fun h0 _ h1 -> h0 == h1)) | let test2 (x:(int * int)) (print_pair:(int * int) -> StTrivial unit)
: Stack unit
(requires (fun h0 -> True))
(ensures (fun h0 _ h1 -> h0 == h1))
= printf "Hello pair %a" print_pair x done | {
"file_name": "ulib/LowStar.Printf.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 44,
"end_line": 527,
"start_col": 0,
"start_line": 523
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LowStar.Printf
/// This module provides imperative printing functions for several
/// primitive Low* types, including
/// -- booleans (%b)
/// -- characters (%c)
/// -- strings (%s)
/// -- machine integers
/// (UInt8.t as %uy, UInt16.t as %us, UInt32.t as %ul, and UInt64.t as %uL;
/// Int8.t as %y, Int16.t as %i, Int32.t as %l , and Int64.t as %L)
/// -- and arrays (aka buffers) of these base types formatted
/// as %xN, where N is the format specifier for the array element type
/// e.g., %xuy for buffers of UInt8.t
/// The main function of this module is `printf`
/// There are a few main differences relative to C printf
/// -- The format specifiers are different (see above)
///
/// -- For technical reasons explained below, an extra dummy
/// argument `done` has to be provided at the end for the
/// computation to have any effect.
///
/// E.g., one must write
/// `printf "%b %c" true 'c' done`
/// rather than just
/// `printf "%b %c" true 'c'`
///
/// -- When printing arrays, two arguments must be passed; the
/// length of the array fragment to be formatted and the array
/// itself
///
/// -- When extracted, rather than producing a C `printf` (which
/// does not, e.g., support printing of dynamically sized
/// arrays), our `printf` is specialized to a sequence of calls
/// to primitive printers for each supported type
///
/// Before diving into the technical details of how this module works,
/// you might want to see a sample usage at the very end of this file.
open FStar.Char
open FStar.String
open FStar.HyperStack.ST
module L = FStar.List.Tot
module LB = LowStar.Monotonic.Buffer
/// `lmbuffer a r s l` is
/// - a monotonic buffer of `a`
/// - governed by preorders `r` and `s`
/// - with length `l`
let lmbuffer a r s l =
b:LB.mbuffer a r s{
LB.len b == l
}
/// `StTrivial`: A effect abbreviation for a stateful computation
/// with no precondition, and which does not change the state
effect StTrivial (a:Type) =
Stack a
(requires fun h -> True)
(ensures fun h0 _ h1 -> h0==h1)
/// `StBuf a b`: A effect abbreviation for a stateful computation
/// that may read `b` does not change the state
effect StBuf (a:Type) #t #r #s #l (b:lmbuffer t r s l) =
Stack a
(requires fun h -> LB.live h b)
(ensures (fun h0 _ h1 -> h0 == h1))
/// Primitive printers for all the types supported by this module
assume val print_string: string -> StTrivial unit
assume val print_char : char -> StTrivial unit
assume val print_u8 : UInt8.t -> StTrivial unit
assume val print_u16 : UInt16.t -> StTrivial unit
assume val print_u32 : UInt32.t -> StTrivial unit
assume val print_u64 : UInt64.t -> StTrivial unit
assume val print_i8 : Int8.t -> StTrivial unit
assume val print_i16 : Int16.t -> StTrivial unit
assume val print_i32 : Int32.t -> StTrivial unit
assume val print_i64 : Int64.t -> StTrivial unit
assume val print_bool : bool -> StTrivial unit
assume val print_lmbuffer_bool (l:_) (#r:_) (#s:_) (b:lmbuffer bool r s l) : StBuf unit b
assume val print_lmbuffer_char (l:_) (#r:_) (#s:_) (b:lmbuffer char r s l) : StBuf unit b
assume val print_lmbuffer_string (l:_) (#r:_) (#s:_) (b:lmbuffer string r s l) : StBuf unit b
assume val print_lmbuffer_u8 (l:_) (#r:_) (#s:_) (b:lmbuffer UInt8.t r s l) : StBuf unit b
assume val print_lmbuffer_u16 (l:_) (#r:_) (#s:_) (b:lmbuffer UInt16.t r s l) : StBuf unit b
assume val print_lmbuffer_u32 (l:_) (#r:_) (#s:_) (b:lmbuffer UInt32.t r s l) : StBuf unit b
assume val print_lmbuffer_u64 (l:_) (#r:_) (#s:_) (b:lmbuffer UInt64.t r s l) : StBuf unit b
assume val print_lmbuffer_i8 (l:_) (#r:_) (#s:_) (b:lmbuffer Int8.t r s l) : StBuf unit b
assume val print_lmbuffer_i16 (l:_) (#r:_) (#s:_) (b:lmbuffer Int16.t r s l) : StBuf unit b
assume val print_lmbuffer_i32 (l:_) (#r:_) (#s:_) (b:lmbuffer Int32.t r s l) : StBuf unit b
assume val print_lmbuffer_i64 (l:_) (#r:_) (#s:_) (b:lmbuffer Int64.t r s l) : StBuf unit b
/// An attribute to control reduction
noextract irreducible
let __reduce__ = unit
/// Base types supported so far
noextract
type base_typ =
| Bool
| Char
| String
| U8
| U16
| U32
| U64
| I8
| I16
| I32
| I64
/// Argument types are base types and arrays thereof
/// Or polymorphic arguments specified by "%a"
noextract
type arg =
| Base of base_typ
| Array of base_typ
| Any
/// Interpreting a `base_typ` as a type
[@@__reduce__]
noextract
let base_typ_as_type (b:base_typ) : Type0 =
match b with
| Bool -> bool
| Char -> char
| String -> string
| U8 -> FStar.UInt8.t
| U16 -> FStar.UInt16.t
| U32 -> FStar.UInt32.t
| U64 -> FStar.UInt64.t
| I8 -> FStar.Int8.t
| I16 -> FStar.Int16.t
| I32 -> FStar.Int32.t
| I64 -> FStar.Int64.t
/// `fragment`: A format string is parsed into a list of fragments of
/// string literals and other arguments that need to be spliced in
/// (interpolated)
noextract
type fragment =
| Frag of string
| Interpolate of arg
noextract
let fragments = list fragment
/// `parse_format s`:
/// Parses a list of characters in a format string into a list of fragments
/// Or None, in case the format string is invalid
[@@__reduce__]
noextract inline_for_extraction
let rec parse_format
(s:list char)
: Tot (option fragments)
(decreases (L.length s))
= let add_dir (d:arg) (ods : option fragments)
= match ods with
| None -> None
| Some ds -> Some (Interpolate d::ds)
in
let head_buffer (ods:option fragments)
= match ods with
| Some (Interpolate (Base t) :: rest) -> Some (Interpolate (Array t) :: rest)
| _ -> None
in
let cons_frag (c:char) (ods:option fragments)
= match ods with
| Some (Frag s::rest) -> Some (Frag (string_of_list (c :: list_of_string s)) :: rest)
| Some rest -> Some (Frag (string_of_list [c]) :: rest)
| _ -> None
in
match s with
| [] -> Some []
| ['%'] -> None
// %a... polymorphic arguments and preceded by their printers
| '%' :: 'a' :: s' ->
add_dir Any (parse_format s')
// %x... arrays of base types
| '%' :: 'x' :: s' ->
head_buffer (parse_format ('%' :: s'))
// %u ... Unsigned integers
| '%' :: 'u' :: s' -> begin
match s' with
| 'y' :: s'' -> add_dir (Base U8) (parse_format s'')
| 's' :: s'' -> add_dir (Base U16) (parse_format s'')
| 'l' :: s'' -> add_dir (Base U32) (parse_format s'')
| 'L' :: s'' -> add_dir (Base U64) (parse_format s'')
| _ -> None
end
| '%' :: c :: s' -> begin
match c with
| '%' -> cons_frag '%' (parse_format s')
| 'b' -> add_dir (Base Bool) (parse_format s')
| 'c' -> add_dir (Base Char) (parse_format s')
| 's' -> add_dir (Base String) (parse_format s')
| 'y' -> add_dir (Base I8) (parse_format s')
| 'i' -> add_dir (Base I16) (parse_format s')
| 'l' -> add_dir (Base I32) (parse_format s')
| 'L' -> add_dir (Base I64) (parse_format s')
| _ -> None
end
| c :: s' ->
cons_frag c (parse_format s')
/// `parse_format_string`: a wrapper around `parse_format`
[@@__reduce__]
noextract inline_for_extraction
let parse_format_string
(s:string)
: option fragments
= parse_format (list_of_string s)
/// `lift a` lifts the type `a` to a higher universe
noextract
type lift (a:Type u#a) : Type u#(max a b) =
| Lift : a -> lift a
/// `done` is a `unit` in universe 1
noextract
let done : lift unit = Lift u#0 u#1 ()
/// `arg_t`: interpreting an argument as a type
/// (in universe 1) since it is polymorphic in the preorders of a buffer
/// GM: Somehow, this needs to be a `let rec` (even if it not really recursive)
/// or print_frags fails to verify. I don't know why; the generated
/// VC and its encoding seem identical (modulo hash consing in the
/// latter).
[@@__reduce__]
noextract
let rec arg_t (a:arg) : Type u#1 =
match a with
| Base t -> lift (base_typ_as_type t)
| Array t -> (l:UInt32.t & r:_ & s:_ & lmbuffer (base_typ_as_type t) r s l)
| Any -> (a:Type0 & (a -> StTrivial unit) & a)
/// `frag_t`: a fragment is either a string literal or a argument to be interpolated
noextract
let frag_t = either string (a:arg & arg_t a)
/// `live_frags h l` is a liveness predicate on all the buffers in `l`
[@@__reduce__]
noextract
let rec live_frags (h:_) (l:list frag_t) : prop =
match l with
| [] -> True
| Inl _ :: rest -> live_frags h rest
| Inr a :: rest ->
(match a with
| (| Base _, _ |) -> live_frags h rest
| (| Any, _ |) -> live_frags h rest
| (| Array _, (| _, _, _, b |) |) -> LB.live h b /\ live_frags h rest)
/// `interpret_frags` interprets a list of fragments as a Low* function type
/// Note `l` is the fragments in L-to-R order (i.e., parsing order)
/// `acc` accumulates the fragment values in reverse order
[@@__reduce__]
noextract
let rec interpret_frags (l:fragments) (acc:list frag_t) : Type u#1 =
match l with
| [] ->
// Always a dummy argument at the end
// Ensures that all cases of this match
// have the same universe, i.e., u#1
lift u#0 u#1 unit
-> Stack unit
(requires fun h0 -> live_frags h0 acc)
(ensures fun h0 _ h1 -> h0 == h1)
| Interpolate (Base t) :: args ->
// Base types are simple: we just take one more argument
x:base_typ_as_type t ->
interpret_frags args (Inr (| Base t, Lift x |) :: acc)
| Interpolate (Array t) :: args ->
// Arrays are implicitly polymorphic in their preorders `r` and `s`
// which is what forces us to be in universe 1
// Note, the length `l` is explicit
l:UInt32.t ->
#r:LB.srel (base_typ_as_type t) ->
#s:LB.srel (base_typ_as_type t) ->
b:lmbuffer (base_typ_as_type t) r s l ->
interpret_frags args (Inr (| Array t, (| l, r, s, b |) |) :: acc)
| Interpolate Any :: args ->
#a:Type0 ->
p:(a -> StTrivial unit) ->
x:a ->
interpret_frags args (Inr (| Any, (| a, p, x |) |) :: acc)
| Frag s :: args ->
// Literal fragments do not incur an additional argument
// We just accumulate them and recur
interpret_frags args (Inl s :: acc)
/// `normal` A normalization marker with very specific steps enabled
noextract unfold
let normal (#a:Type) (x:a) : a =
FStar.Pervasives.norm
[iota;
zeta;
delta_attr [`%__reduce__; `%BigOps.__reduce__];
delta_only [`%Base?; `%Array?; `%Some?; `%Some?.v; `%list_of_string];
primops;
simplify]
x
/// `coerce`: A utility to trigger extensional equality of types
noextract
let coerce (x:'a{'a == 'b}) : 'b = x
/// `fragment_printer`: The type of a printer of fragments
noextract
let fragment_printer =
(acc:list frag_t)
-> Stack unit
(requires fun h0 -> live_frags h0 acc)
(ensures fun h0 _ h1 -> h0 == h1)
/// `print_frags`: Having accumulated all the pieces of a format
/// string and the arguments to the printed (i.e., the `list frag_t`),
/// this function does the actual work of printing them all using the
/// primitive printers
noextract inline_for_extraction
let rec print_frags (acc:list frag_t)
: Stack unit
(requires fun h0 -> live_frags h0 acc)
(ensures fun h0 _ h1 -> h0 == h1)
= match acc with
| [] -> ()
| hd::tl ->
print_frags tl;
(match hd with
| Inl s -> print_string s
| Inr (| Base t, Lift value |) ->
(match t with
| Bool -> print_bool value
| Char -> print_char value
| String -> print_string value
| U8 -> print_u8 value
| U16 -> print_u16 value
| U32 -> print_u32 value
| U64 -> print_u64 value
| I8 -> print_i8 value
| I16 -> print_i16 value
| I32 -> print_i32 value
| I64 -> print_i64 value)
| Inr (| Array t, (| l, r, s, value |) |) ->
(match t with
| Bool -> print_lmbuffer_bool l value
| Char -> print_lmbuffer_char l value
| String -> print_lmbuffer_string l value
| U8 -> print_lmbuffer_u8 l value
| U16 -> print_lmbuffer_u16 l value
| U32 -> print_lmbuffer_u32 l value
| U64 -> print_lmbuffer_u64 l value
| I8 -> print_lmbuffer_i8 l value
| I16 -> print_lmbuffer_i16 l value
| I32 -> print_lmbuffer_i32 l value
| I64 -> print_lmbuffer_i64 l value)
| Inr (| Any, (| _, printer, value |) |) ->
printer value)
[@@__reduce__]
let no_inst #a (#b:a -> Type) (f: (#x:a -> b x)) : unit -> #x:a -> b x = fun () -> f
[@@__reduce__]
let elim_unit_arrow #t (f:unit -> t) : t = f ()
// let test2 (f: (#a:Type -> a -> a)) : id_t 0 = test f ()
// let coerce #a (#b: (a -> Type)) ($f: (#x:a -> b x)) (t:Type{norm t == (#x:a -> b x)})
/// `aux frags acc`: This is the main workhorse which interprets a
/// parsed format string (`frags`) as a variadic, stateful function
[@@__reduce__]
noextract inline_for_extraction
let rec aux (frags:fragments) (acc:list frag_t) (fp: fragment_printer) : interpret_frags frags acc =
match frags with
| [] ->
let f (l:lift u#0 u#1 unit)
: Stack unit
(requires fun h0 -> live_frags h0 acc)
(ensures fun h0 _ h1 -> h0 == h1)
= fp acc
in
(f <: interpret_frags [] acc)
| Frag s :: rest ->
coerce (aux rest (Inl s :: acc) fp)
| Interpolate (Base t) :: args ->
let f (x:base_typ_as_type t)
: interpret_frags args (Inr (| Base t, Lift x |) :: acc)
= aux args (Inr (| Base t, Lift x |) :: acc) fp
in
f
| Interpolate (Array t) :: rest ->
let f :
l:UInt32.t
-> #r:LB.srel (base_typ_as_type t)
-> #s:LB.srel (base_typ_as_type t)
-> b:lmbuffer (base_typ_as_type t) r s l
-> interpret_frags rest (Inr (| Array t, (| l, r, s, b |) |) :: acc)
= fun l #r #s b -> aux rest (Inr (| Array t, (| l, r, s, b |) |) :: acc) fp
in
f <: interpret_frags (Interpolate (Array t) :: rest) acc
| Interpolate Any :: rest ->
let f :
unit
-> #a:Type
-> p:(a -> StTrivial unit)
-> x:a
-> interpret_frags rest (Inr (| Any, (| a, p, x |) |) :: acc)
= fun () #a p x -> aux rest (Inr (| Any, (| a, p, x |) |) :: acc) fp
in
elim_unit_arrow (no_inst (f ()) <: (unit -> interpret_frags (Interpolate Any :: rest) acc))
/// `format_string` : A valid format string is one that can be successfully parsed
[@@__reduce__]
noextract
let format_string = s:string{normal #bool (Some? (parse_format_string s))}
/// `interpret_format_string` parses a string into fragments and then
/// interprets it as a type
[@@__reduce__]
noextract
let interpret_format_string (s:format_string) : Type =
interpret_frags (Some?.v (parse_format_string s)) []
/// `printf'`: Almost there ... this has a variadic type
/// and calls the actual printers for all its arguments.
///
/// Note, the `normalize_term` in its body is crucial. It's what
/// allows the term to be specialized at extraction time.
noextract inline_for_extraction
let printf' (s:format_string) : interpret_format_string s =
normalize_term
(match parse_format_string s with
| Some frags -> aux frags [] print_frags)
/// `intro_normal_f`: a technical gadget to introduce
/// implicit normalization in the domain and co-domain of a function type
noextract inline_for_extraction
let intro_normal_f (#a:Type) (b: (a -> Type)) (f:(x:a -> b x))
: (x:(normal a) -> normal (b x))
= f
/// `printf`: The main function has type
/// `s:normal format_string -> normal (interpret_format_string s)`
/// Note:
/// This is the type F* infers for it and it is best to leave it that way
/// rather then writing it down and asking F* to re-check what it inferred.
///
/// Annotating it results in a needless additional proof obligation to
/// equate types after they are partially reduced, which is pointless.
noextract inline_for_extraction
val printf : s:normal format_string -> normal (interpret_format_string s)
let printf = intro_normal_f #format_string interpret_format_string printf'
/// `skip`: We also provide `skip`, a function that has the same type as printf
/// but normalizes to `()`, i.e., it prints nothing. This is useful for conditional
/// printing in debug code, for instance.
noextract inline_for_extraction
let skip' (s:format_string) : interpret_format_string s =
normalize_term
(match parse_format_string s with
| Some frags -> aux frags [] (fun _ -> ()))
noextract inline_for_extraction
val skip : s:normal format_string -> normal (interpret_format_string s)
let skip = intro_normal_f #format_string interpret_format_string skip'
/// `test`: A small test function
/// Running `fstar --codegen OCaml LowStar.Printf.fst --extract LowStar.Printf`
/// produces the following for the body of this function
/// ```
/// print_string "Hello ";
/// print_bool true;
/// print_string " Low* ";
/// print_u64 m;
/// print_string " Printf ";
/// print_lmbuffer_bool l () () x;
/// print_string " ";
/// print_string "bye"
/// ```
let test (m:UInt64.t) (l:UInt32.t) (#r:_) (#s:_) (x:LB.mbuffer bool r s{LB.len x = l})
: Stack unit
(requires (fun h0 -> LB.live h0 x))
(ensures (fun h0 _ h1 -> h0 == h1))
= printf "Hello %b Low* %uL Printf %xb %s"
true //%b boolean
m //%uL u64
l x //%xb (buffer bool)
"bye"
done //dummy universe coercion | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.Printf.fst"
} | [
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "LB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.String",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Char",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
x: (Prims.int * Prims.int) ->
print_pair: (_: (Prims.int * Prims.int) -> LowStar.Printf.StTrivial Prims.unit)
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"FStar.Pervasives.Native.tuple2",
"Prims.int",
"Prims.unit",
"LowStar.Printf.printf",
"LowStar.Printf.done",
"FStar.Monotonic.HyperStack.mem",
"Prims.l_True",
"Prims.eq2"
] | [] | false | true | false | false | false | let test2 (x: (int * int)) (print_pair: ((int * int) -> StTrivial unit))
: Stack unit (requires (fun h0 -> True)) (ensures (fun h0 _ h1 -> h0 == h1)) =
| printf "Hello pair %a" print_pair x done | false |
LowStar.Printf.fst | LowStar.Printf.printf' | val printf' (s: format_string) : interpret_format_string s | val printf' (s: format_string) : interpret_format_string s | let printf' (s:format_string) : interpret_format_string s =
normalize_term
(match parse_format_string s with
| Some frags -> aux frags [] print_frags) | {
"file_name": "ulib/LowStar.Printf.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 45,
"end_line": 463,
"start_col": 0,
"start_line": 460
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LowStar.Printf
/// This module provides imperative printing functions for several
/// primitive Low* types, including
/// -- booleans (%b)
/// -- characters (%c)
/// -- strings (%s)
/// -- machine integers
/// (UInt8.t as %uy, UInt16.t as %us, UInt32.t as %ul, and UInt64.t as %uL;
/// Int8.t as %y, Int16.t as %i, Int32.t as %l , and Int64.t as %L)
/// -- and arrays (aka buffers) of these base types formatted
/// as %xN, where N is the format specifier for the array element type
/// e.g., %xuy for buffers of UInt8.t
/// The main function of this module is `printf`
/// There are a few main differences relative to C printf
/// -- The format specifiers are different (see above)
///
/// -- For technical reasons explained below, an extra dummy
/// argument `done` has to be provided at the end for the
/// computation to have any effect.
///
/// E.g., one must write
/// `printf "%b %c" true 'c' done`
/// rather than just
/// `printf "%b %c" true 'c'`
///
/// -- When printing arrays, two arguments must be passed; the
/// length of the array fragment to be formatted and the array
/// itself
///
/// -- When extracted, rather than producing a C `printf` (which
/// does not, e.g., support printing of dynamically sized
/// arrays), our `printf` is specialized to a sequence of calls
/// to primitive printers for each supported type
///
/// Before diving into the technical details of how this module works,
/// you might want to see a sample usage at the very end of this file.
open FStar.Char
open FStar.String
open FStar.HyperStack.ST
module L = FStar.List.Tot
module LB = LowStar.Monotonic.Buffer
/// `lmbuffer a r s l` is
/// - a monotonic buffer of `a`
/// - governed by preorders `r` and `s`
/// - with length `l`
let lmbuffer a r s l =
b:LB.mbuffer a r s{
LB.len b == l
}
/// `StTrivial`: A effect abbreviation for a stateful computation
/// with no precondition, and which does not change the state
effect StTrivial (a:Type) =
Stack a
(requires fun h -> True)
(ensures fun h0 _ h1 -> h0==h1)
/// `StBuf a b`: A effect abbreviation for a stateful computation
/// that may read `b` does not change the state
effect StBuf (a:Type) #t #r #s #l (b:lmbuffer t r s l) =
Stack a
(requires fun h -> LB.live h b)
(ensures (fun h0 _ h1 -> h0 == h1))
/// Primitive printers for all the types supported by this module
assume val print_string: string -> StTrivial unit
assume val print_char : char -> StTrivial unit
assume val print_u8 : UInt8.t -> StTrivial unit
assume val print_u16 : UInt16.t -> StTrivial unit
assume val print_u32 : UInt32.t -> StTrivial unit
assume val print_u64 : UInt64.t -> StTrivial unit
assume val print_i8 : Int8.t -> StTrivial unit
assume val print_i16 : Int16.t -> StTrivial unit
assume val print_i32 : Int32.t -> StTrivial unit
assume val print_i64 : Int64.t -> StTrivial unit
assume val print_bool : bool -> StTrivial unit
assume val print_lmbuffer_bool (l:_) (#r:_) (#s:_) (b:lmbuffer bool r s l) : StBuf unit b
assume val print_lmbuffer_char (l:_) (#r:_) (#s:_) (b:lmbuffer char r s l) : StBuf unit b
assume val print_lmbuffer_string (l:_) (#r:_) (#s:_) (b:lmbuffer string r s l) : StBuf unit b
assume val print_lmbuffer_u8 (l:_) (#r:_) (#s:_) (b:lmbuffer UInt8.t r s l) : StBuf unit b
assume val print_lmbuffer_u16 (l:_) (#r:_) (#s:_) (b:lmbuffer UInt16.t r s l) : StBuf unit b
assume val print_lmbuffer_u32 (l:_) (#r:_) (#s:_) (b:lmbuffer UInt32.t r s l) : StBuf unit b
assume val print_lmbuffer_u64 (l:_) (#r:_) (#s:_) (b:lmbuffer UInt64.t r s l) : StBuf unit b
assume val print_lmbuffer_i8 (l:_) (#r:_) (#s:_) (b:lmbuffer Int8.t r s l) : StBuf unit b
assume val print_lmbuffer_i16 (l:_) (#r:_) (#s:_) (b:lmbuffer Int16.t r s l) : StBuf unit b
assume val print_lmbuffer_i32 (l:_) (#r:_) (#s:_) (b:lmbuffer Int32.t r s l) : StBuf unit b
assume val print_lmbuffer_i64 (l:_) (#r:_) (#s:_) (b:lmbuffer Int64.t r s l) : StBuf unit b
/// An attribute to control reduction
noextract irreducible
let __reduce__ = unit
/// Base types supported so far
noextract
type base_typ =
| Bool
| Char
| String
| U8
| U16
| U32
| U64
| I8
| I16
| I32
| I64
/// Argument types are base types and arrays thereof
/// Or polymorphic arguments specified by "%a"
noextract
type arg =
| Base of base_typ
| Array of base_typ
| Any
/// Interpreting a `base_typ` as a type
[@@__reduce__]
noextract
let base_typ_as_type (b:base_typ) : Type0 =
match b with
| Bool -> bool
| Char -> char
| String -> string
| U8 -> FStar.UInt8.t
| U16 -> FStar.UInt16.t
| U32 -> FStar.UInt32.t
| U64 -> FStar.UInt64.t
| I8 -> FStar.Int8.t
| I16 -> FStar.Int16.t
| I32 -> FStar.Int32.t
| I64 -> FStar.Int64.t
/// `fragment`: A format string is parsed into a list of fragments of
/// string literals and other arguments that need to be spliced in
/// (interpolated)
noextract
type fragment =
| Frag of string
| Interpolate of arg
noextract
let fragments = list fragment
/// `parse_format s`:
/// Parses a list of characters in a format string into a list of fragments
/// Or None, in case the format string is invalid
[@@__reduce__]
noextract inline_for_extraction
let rec parse_format
(s:list char)
: Tot (option fragments)
(decreases (L.length s))
= let add_dir (d:arg) (ods : option fragments)
= match ods with
| None -> None
| Some ds -> Some (Interpolate d::ds)
in
let head_buffer (ods:option fragments)
= match ods with
| Some (Interpolate (Base t) :: rest) -> Some (Interpolate (Array t) :: rest)
| _ -> None
in
let cons_frag (c:char) (ods:option fragments)
= match ods with
| Some (Frag s::rest) -> Some (Frag (string_of_list (c :: list_of_string s)) :: rest)
| Some rest -> Some (Frag (string_of_list [c]) :: rest)
| _ -> None
in
match s with
| [] -> Some []
| ['%'] -> None
// %a... polymorphic arguments and preceded by their printers
| '%' :: 'a' :: s' ->
add_dir Any (parse_format s')
// %x... arrays of base types
| '%' :: 'x' :: s' ->
head_buffer (parse_format ('%' :: s'))
// %u ... Unsigned integers
| '%' :: 'u' :: s' -> begin
match s' with
| 'y' :: s'' -> add_dir (Base U8) (parse_format s'')
| 's' :: s'' -> add_dir (Base U16) (parse_format s'')
| 'l' :: s'' -> add_dir (Base U32) (parse_format s'')
| 'L' :: s'' -> add_dir (Base U64) (parse_format s'')
| _ -> None
end
| '%' :: c :: s' -> begin
match c with
| '%' -> cons_frag '%' (parse_format s')
| 'b' -> add_dir (Base Bool) (parse_format s')
| 'c' -> add_dir (Base Char) (parse_format s')
| 's' -> add_dir (Base String) (parse_format s')
| 'y' -> add_dir (Base I8) (parse_format s')
| 'i' -> add_dir (Base I16) (parse_format s')
| 'l' -> add_dir (Base I32) (parse_format s')
| 'L' -> add_dir (Base I64) (parse_format s')
| _ -> None
end
| c :: s' ->
cons_frag c (parse_format s')
/// `parse_format_string`: a wrapper around `parse_format`
[@@__reduce__]
noextract inline_for_extraction
let parse_format_string
(s:string)
: option fragments
= parse_format (list_of_string s)
/// `lift a` lifts the type `a` to a higher universe
noextract
type lift (a:Type u#a) : Type u#(max a b) =
| Lift : a -> lift a
/// `done` is a `unit` in universe 1
noextract
let done : lift unit = Lift u#0 u#1 ()
/// `arg_t`: interpreting an argument as a type
/// (in universe 1) since it is polymorphic in the preorders of a buffer
/// GM: Somehow, this needs to be a `let rec` (even if it not really recursive)
/// or print_frags fails to verify. I don't know why; the generated
/// VC and its encoding seem identical (modulo hash consing in the
/// latter).
[@@__reduce__]
noextract
let rec arg_t (a:arg) : Type u#1 =
match a with
| Base t -> lift (base_typ_as_type t)
| Array t -> (l:UInt32.t & r:_ & s:_ & lmbuffer (base_typ_as_type t) r s l)
| Any -> (a:Type0 & (a -> StTrivial unit) & a)
/// `frag_t`: a fragment is either a string literal or a argument to be interpolated
noextract
let frag_t = either string (a:arg & arg_t a)
/// `live_frags h l` is a liveness predicate on all the buffers in `l`
[@@__reduce__]
noextract
let rec live_frags (h:_) (l:list frag_t) : prop =
match l with
| [] -> True
| Inl _ :: rest -> live_frags h rest
| Inr a :: rest ->
(match a with
| (| Base _, _ |) -> live_frags h rest
| (| Any, _ |) -> live_frags h rest
| (| Array _, (| _, _, _, b |) |) -> LB.live h b /\ live_frags h rest)
/// `interpret_frags` interprets a list of fragments as a Low* function type
/// Note `l` is the fragments in L-to-R order (i.e., parsing order)
/// `acc` accumulates the fragment values in reverse order
[@@__reduce__]
noextract
let rec interpret_frags (l:fragments) (acc:list frag_t) : Type u#1 =
match l with
| [] ->
// Always a dummy argument at the end
// Ensures that all cases of this match
// have the same universe, i.e., u#1
lift u#0 u#1 unit
-> Stack unit
(requires fun h0 -> live_frags h0 acc)
(ensures fun h0 _ h1 -> h0 == h1)
| Interpolate (Base t) :: args ->
// Base types are simple: we just take one more argument
x:base_typ_as_type t ->
interpret_frags args (Inr (| Base t, Lift x |) :: acc)
| Interpolate (Array t) :: args ->
// Arrays are implicitly polymorphic in their preorders `r` and `s`
// which is what forces us to be in universe 1
// Note, the length `l` is explicit
l:UInt32.t ->
#r:LB.srel (base_typ_as_type t) ->
#s:LB.srel (base_typ_as_type t) ->
b:lmbuffer (base_typ_as_type t) r s l ->
interpret_frags args (Inr (| Array t, (| l, r, s, b |) |) :: acc)
| Interpolate Any :: args ->
#a:Type0 ->
p:(a -> StTrivial unit) ->
x:a ->
interpret_frags args (Inr (| Any, (| a, p, x |) |) :: acc)
| Frag s :: args ->
// Literal fragments do not incur an additional argument
// We just accumulate them and recur
interpret_frags args (Inl s :: acc)
/// `normal` A normalization marker with very specific steps enabled
noextract unfold
let normal (#a:Type) (x:a) : a =
FStar.Pervasives.norm
[iota;
zeta;
delta_attr [`%__reduce__; `%BigOps.__reduce__];
delta_only [`%Base?; `%Array?; `%Some?; `%Some?.v; `%list_of_string];
primops;
simplify]
x
/// `coerce`: A utility to trigger extensional equality of types
noextract
let coerce (x:'a{'a == 'b}) : 'b = x
/// `fragment_printer`: The type of a printer of fragments
noextract
let fragment_printer =
(acc:list frag_t)
-> Stack unit
(requires fun h0 -> live_frags h0 acc)
(ensures fun h0 _ h1 -> h0 == h1)
/// `print_frags`: Having accumulated all the pieces of a format
/// string and the arguments to the printed (i.e., the `list frag_t`),
/// this function does the actual work of printing them all using the
/// primitive printers
noextract inline_for_extraction
let rec print_frags (acc:list frag_t)
: Stack unit
(requires fun h0 -> live_frags h0 acc)
(ensures fun h0 _ h1 -> h0 == h1)
= match acc with
| [] -> ()
| hd::tl ->
print_frags tl;
(match hd with
| Inl s -> print_string s
| Inr (| Base t, Lift value |) ->
(match t with
| Bool -> print_bool value
| Char -> print_char value
| String -> print_string value
| U8 -> print_u8 value
| U16 -> print_u16 value
| U32 -> print_u32 value
| U64 -> print_u64 value
| I8 -> print_i8 value
| I16 -> print_i16 value
| I32 -> print_i32 value
| I64 -> print_i64 value)
| Inr (| Array t, (| l, r, s, value |) |) ->
(match t with
| Bool -> print_lmbuffer_bool l value
| Char -> print_lmbuffer_char l value
| String -> print_lmbuffer_string l value
| U8 -> print_lmbuffer_u8 l value
| U16 -> print_lmbuffer_u16 l value
| U32 -> print_lmbuffer_u32 l value
| U64 -> print_lmbuffer_u64 l value
| I8 -> print_lmbuffer_i8 l value
| I16 -> print_lmbuffer_i16 l value
| I32 -> print_lmbuffer_i32 l value
| I64 -> print_lmbuffer_i64 l value)
| Inr (| Any, (| _, printer, value |) |) ->
printer value)
[@@__reduce__]
let no_inst #a (#b:a -> Type) (f: (#x:a -> b x)) : unit -> #x:a -> b x = fun () -> f
[@@__reduce__]
let elim_unit_arrow #t (f:unit -> t) : t = f ()
// let test2 (f: (#a:Type -> a -> a)) : id_t 0 = test f ()
// let coerce #a (#b: (a -> Type)) ($f: (#x:a -> b x)) (t:Type{norm t == (#x:a -> b x)})
/// `aux frags acc`: This is the main workhorse which interprets a
/// parsed format string (`frags`) as a variadic, stateful function
[@@__reduce__]
noextract inline_for_extraction
let rec aux (frags:fragments) (acc:list frag_t) (fp: fragment_printer) : interpret_frags frags acc =
match frags with
| [] ->
let f (l:lift u#0 u#1 unit)
: Stack unit
(requires fun h0 -> live_frags h0 acc)
(ensures fun h0 _ h1 -> h0 == h1)
= fp acc
in
(f <: interpret_frags [] acc)
| Frag s :: rest ->
coerce (aux rest (Inl s :: acc) fp)
| Interpolate (Base t) :: args ->
let f (x:base_typ_as_type t)
: interpret_frags args (Inr (| Base t, Lift x |) :: acc)
= aux args (Inr (| Base t, Lift x |) :: acc) fp
in
f
| Interpolate (Array t) :: rest ->
let f :
l:UInt32.t
-> #r:LB.srel (base_typ_as_type t)
-> #s:LB.srel (base_typ_as_type t)
-> b:lmbuffer (base_typ_as_type t) r s l
-> interpret_frags rest (Inr (| Array t, (| l, r, s, b |) |) :: acc)
= fun l #r #s b -> aux rest (Inr (| Array t, (| l, r, s, b |) |) :: acc) fp
in
f <: interpret_frags (Interpolate (Array t) :: rest) acc
| Interpolate Any :: rest ->
let f :
unit
-> #a:Type
-> p:(a -> StTrivial unit)
-> x:a
-> interpret_frags rest (Inr (| Any, (| a, p, x |) |) :: acc)
= fun () #a p x -> aux rest (Inr (| Any, (| a, p, x |) |) :: acc) fp
in
elim_unit_arrow (no_inst (f ()) <: (unit -> interpret_frags (Interpolate Any :: rest) acc))
/// `format_string` : A valid format string is one that can be successfully parsed
[@@__reduce__]
noextract
let format_string = s:string{normal #bool (Some? (parse_format_string s))}
/// `interpret_format_string` parses a string into fragments and then
/// interprets it as a type
[@@__reduce__]
noextract
let interpret_format_string (s:format_string) : Type =
interpret_frags (Some?.v (parse_format_string s)) []
/// `printf'`: Almost there ... this has a variadic type
/// and calls the actual printers for all its arguments.
///
/// Note, the `normalize_term` in its body is crucial. It's what
/// allows the term to be specialized at extraction time. | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.Printf.fst"
} | [
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "LB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.String",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Char",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: LowStar.Printf.format_string -> LowStar.Printf.interpret_format_string s | Prims.Tot | [
"total"
] | [] | [
"LowStar.Printf.format_string",
"FStar.Pervasives.normalize_term",
"LowStar.Printf.interpret_format_string",
"LowStar.Printf.parse_format_string",
"LowStar.Printf.fragments",
"LowStar.Printf.aux",
"Prims.Nil",
"LowStar.Printf.frag_t",
"LowStar.Printf.print_frags"
] | [] | false | false | false | false | false | let printf' (s: format_string) : interpret_format_string s =
| normalize_term (match parse_format_string s with | Some frags -> aux frags [] print_frags) | false |
LowStar.Printf.fst | LowStar.Printf.test3 | val test3 (m: UInt64.t) (l: UInt32.t) (#r #s: _) (x: LB.mbuffer bool r s {LB.len x = l})
: Stack unit (requires (fun h0 -> LB.live h0 x)) (ensures (fun h0 _ h1 -> h0 == h1)) | val test3 (m: UInt64.t) (l: UInt32.t) (#r #s: _) (x: LB.mbuffer bool r s {LB.len x = l})
: Stack unit (requires (fun h0 -> LB.live h0 x)) (ensures (fun h0 _ h1 -> h0 == h1)) | let test3 (m:UInt64.t) (l:UInt32.t) (#r:_) (#s:_) (x:LB.mbuffer bool r s{LB.len x = l})
: Stack unit
(requires (fun h0 -> LB.live h0 x))
(ensures (fun h0 _ h1 -> h0 == h1))
= skip "Hello %b Low* %uL Printf %xb %s"
true //%b boolean
m //%uL u64
l x //%xb (buffer bool)
"bye"
done | {
"file_name": "ulib/LowStar.Printf.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 18,
"end_line": 538,
"start_col": 0,
"start_line": 529
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LowStar.Printf
/// This module provides imperative printing functions for several
/// primitive Low* types, including
/// -- booleans (%b)
/// -- characters (%c)
/// -- strings (%s)
/// -- machine integers
/// (UInt8.t as %uy, UInt16.t as %us, UInt32.t as %ul, and UInt64.t as %uL;
/// Int8.t as %y, Int16.t as %i, Int32.t as %l , and Int64.t as %L)
/// -- and arrays (aka buffers) of these base types formatted
/// as %xN, where N is the format specifier for the array element type
/// e.g., %xuy for buffers of UInt8.t
/// The main function of this module is `printf`
/// There are a few main differences relative to C printf
/// -- The format specifiers are different (see above)
///
/// -- For technical reasons explained below, an extra dummy
/// argument `done` has to be provided at the end for the
/// computation to have any effect.
///
/// E.g., one must write
/// `printf "%b %c" true 'c' done`
/// rather than just
/// `printf "%b %c" true 'c'`
///
/// -- When printing arrays, two arguments must be passed; the
/// length of the array fragment to be formatted and the array
/// itself
///
/// -- When extracted, rather than producing a C `printf` (which
/// does not, e.g., support printing of dynamically sized
/// arrays), our `printf` is specialized to a sequence of calls
/// to primitive printers for each supported type
///
/// Before diving into the technical details of how this module works,
/// you might want to see a sample usage at the very end of this file.
open FStar.Char
open FStar.String
open FStar.HyperStack.ST
module L = FStar.List.Tot
module LB = LowStar.Monotonic.Buffer
/// `lmbuffer a r s l` is
/// - a monotonic buffer of `a`
/// - governed by preorders `r` and `s`
/// - with length `l`
let lmbuffer a r s l =
b:LB.mbuffer a r s{
LB.len b == l
}
/// `StTrivial`: A effect abbreviation for a stateful computation
/// with no precondition, and which does not change the state
effect StTrivial (a:Type) =
Stack a
(requires fun h -> True)
(ensures fun h0 _ h1 -> h0==h1)
/// `StBuf a b`: A effect abbreviation for a stateful computation
/// that may read `b` does not change the state
effect StBuf (a:Type) #t #r #s #l (b:lmbuffer t r s l) =
Stack a
(requires fun h -> LB.live h b)
(ensures (fun h0 _ h1 -> h0 == h1))
/// Primitive printers for all the types supported by this module
assume val print_string: string -> StTrivial unit
assume val print_char : char -> StTrivial unit
assume val print_u8 : UInt8.t -> StTrivial unit
assume val print_u16 : UInt16.t -> StTrivial unit
assume val print_u32 : UInt32.t -> StTrivial unit
assume val print_u64 : UInt64.t -> StTrivial unit
assume val print_i8 : Int8.t -> StTrivial unit
assume val print_i16 : Int16.t -> StTrivial unit
assume val print_i32 : Int32.t -> StTrivial unit
assume val print_i64 : Int64.t -> StTrivial unit
assume val print_bool : bool -> StTrivial unit
assume val print_lmbuffer_bool (l:_) (#r:_) (#s:_) (b:lmbuffer bool r s l) : StBuf unit b
assume val print_lmbuffer_char (l:_) (#r:_) (#s:_) (b:lmbuffer char r s l) : StBuf unit b
assume val print_lmbuffer_string (l:_) (#r:_) (#s:_) (b:lmbuffer string r s l) : StBuf unit b
assume val print_lmbuffer_u8 (l:_) (#r:_) (#s:_) (b:lmbuffer UInt8.t r s l) : StBuf unit b
assume val print_lmbuffer_u16 (l:_) (#r:_) (#s:_) (b:lmbuffer UInt16.t r s l) : StBuf unit b
assume val print_lmbuffer_u32 (l:_) (#r:_) (#s:_) (b:lmbuffer UInt32.t r s l) : StBuf unit b
assume val print_lmbuffer_u64 (l:_) (#r:_) (#s:_) (b:lmbuffer UInt64.t r s l) : StBuf unit b
assume val print_lmbuffer_i8 (l:_) (#r:_) (#s:_) (b:lmbuffer Int8.t r s l) : StBuf unit b
assume val print_lmbuffer_i16 (l:_) (#r:_) (#s:_) (b:lmbuffer Int16.t r s l) : StBuf unit b
assume val print_lmbuffer_i32 (l:_) (#r:_) (#s:_) (b:lmbuffer Int32.t r s l) : StBuf unit b
assume val print_lmbuffer_i64 (l:_) (#r:_) (#s:_) (b:lmbuffer Int64.t r s l) : StBuf unit b
/// An attribute to control reduction
noextract irreducible
let __reduce__ = unit
/// Base types supported so far
noextract
type base_typ =
| Bool
| Char
| String
| U8
| U16
| U32
| U64
| I8
| I16
| I32
| I64
/// Argument types are base types and arrays thereof
/// Or polymorphic arguments specified by "%a"
noextract
type arg =
| Base of base_typ
| Array of base_typ
| Any
/// Interpreting a `base_typ` as a type
[@@__reduce__]
noextract
let base_typ_as_type (b:base_typ) : Type0 =
match b with
| Bool -> bool
| Char -> char
| String -> string
| U8 -> FStar.UInt8.t
| U16 -> FStar.UInt16.t
| U32 -> FStar.UInt32.t
| U64 -> FStar.UInt64.t
| I8 -> FStar.Int8.t
| I16 -> FStar.Int16.t
| I32 -> FStar.Int32.t
| I64 -> FStar.Int64.t
/// `fragment`: A format string is parsed into a list of fragments of
/// string literals and other arguments that need to be spliced in
/// (interpolated)
noextract
type fragment =
| Frag of string
| Interpolate of arg
noextract
let fragments = list fragment
/// `parse_format s`:
/// Parses a list of characters in a format string into a list of fragments
/// Or None, in case the format string is invalid
[@@__reduce__]
noextract inline_for_extraction
let rec parse_format
(s:list char)
: Tot (option fragments)
(decreases (L.length s))
= let add_dir (d:arg) (ods : option fragments)
= match ods with
| None -> None
| Some ds -> Some (Interpolate d::ds)
in
let head_buffer (ods:option fragments)
= match ods with
| Some (Interpolate (Base t) :: rest) -> Some (Interpolate (Array t) :: rest)
| _ -> None
in
let cons_frag (c:char) (ods:option fragments)
= match ods with
| Some (Frag s::rest) -> Some (Frag (string_of_list (c :: list_of_string s)) :: rest)
| Some rest -> Some (Frag (string_of_list [c]) :: rest)
| _ -> None
in
match s with
| [] -> Some []
| ['%'] -> None
// %a... polymorphic arguments and preceded by their printers
| '%' :: 'a' :: s' ->
add_dir Any (parse_format s')
// %x... arrays of base types
| '%' :: 'x' :: s' ->
head_buffer (parse_format ('%' :: s'))
// %u ... Unsigned integers
| '%' :: 'u' :: s' -> begin
match s' with
| 'y' :: s'' -> add_dir (Base U8) (parse_format s'')
| 's' :: s'' -> add_dir (Base U16) (parse_format s'')
| 'l' :: s'' -> add_dir (Base U32) (parse_format s'')
| 'L' :: s'' -> add_dir (Base U64) (parse_format s'')
| _ -> None
end
| '%' :: c :: s' -> begin
match c with
| '%' -> cons_frag '%' (parse_format s')
| 'b' -> add_dir (Base Bool) (parse_format s')
| 'c' -> add_dir (Base Char) (parse_format s')
| 's' -> add_dir (Base String) (parse_format s')
| 'y' -> add_dir (Base I8) (parse_format s')
| 'i' -> add_dir (Base I16) (parse_format s')
| 'l' -> add_dir (Base I32) (parse_format s')
| 'L' -> add_dir (Base I64) (parse_format s')
| _ -> None
end
| c :: s' ->
cons_frag c (parse_format s')
/// `parse_format_string`: a wrapper around `parse_format`
[@@__reduce__]
noextract inline_for_extraction
let parse_format_string
(s:string)
: option fragments
= parse_format (list_of_string s)
/// `lift a` lifts the type `a` to a higher universe
noextract
type lift (a:Type u#a) : Type u#(max a b) =
| Lift : a -> lift a
/// `done` is a `unit` in universe 1
noextract
let done : lift unit = Lift u#0 u#1 ()
/// `arg_t`: interpreting an argument as a type
/// (in universe 1) since it is polymorphic in the preorders of a buffer
/// GM: Somehow, this needs to be a `let rec` (even if it not really recursive)
/// or print_frags fails to verify. I don't know why; the generated
/// VC and its encoding seem identical (modulo hash consing in the
/// latter).
[@@__reduce__]
noextract
let rec arg_t (a:arg) : Type u#1 =
match a with
| Base t -> lift (base_typ_as_type t)
| Array t -> (l:UInt32.t & r:_ & s:_ & lmbuffer (base_typ_as_type t) r s l)
| Any -> (a:Type0 & (a -> StTrivial unit) & a)
/// `frag_t`: a fragment is either a string literal or a argument to be interpolated
noextract
let frag_t = either string (a:arg & arg_t a)
/// `live_frags h l` is a liveness predicate on all the buffers in `l`
[@@__reduce__]
noextract
let rec live_frags (h:_) (l:list frag_t) : prop =
match l with
| [] -> True
| Inl _ :: rest -> live_frags h rest
| Inr a :: rest ->
(match a with
| (| Base _, _ |) -> live_frags h rest
| (| Any, _ |) -> live_frags h rest
| (| Array _, (| _, _, _, b |) |) -> LB.live h b /\ live_frags h rest)
/// `interpret_frags` interprets a list of fragments as a Low* function type
/// Note `l` is the fragments in L-to-R order (i.e., parsing order)
/// `acc` accumulates the fragment values in reverse order
[@@__reduce__]
noextract
let rec interpret_frags (l:fragments) (acc:list frag_t) : Type u#1 =
match l with
| [] ->
// Always a dummy argument at the end
// Ensures that all cases of this match
// have the same universe, i.e., u#1
lift u#0 u#1 unit
-> Stack unit
(requires fun h0 -> live_frags h0 acc)
(ensures fun h0 _ h1 -> h0 == h1)
| Interpolate (Base t) :: args ->
// Base types are simple: we just take one more argument
x:base_typ_as_type t ->
interpret_frags args (Inr (| Base t, Lift x |) :: acc)
| Interpolate (Array t) :: args ->
// Arrays are implicitly polymorphic in their preorders `r` and `s`
// which is what forces us to be in universe 1
// Note, the length `l` is explicit
l:UInt32.t ->
#r:LB.srel (base_typ_as_type t) ->
#s:LB.srel (base_typ_as_type t) ->
b:lmbuffer (base_typ_as_type t) r s l ->
interpret_frags args (Inr (| Array t, (| l, r, s, b |) |) :: acc)
| Interpolate Any :: args ->
#a:Type0 ->
p:(a -> StTrivial unit) ->
x:a ->
interpret_frags args (Inr (| Any, (| a, p, x |) |) :: acc)
| Frag s :: args ->
// Literal fragments do not incur an additional argument
// We just accumulate them and recur
interpret_frags args (Inl s :: acc)
/// `normal` A normalization marker with very specific steps enabled
noextract unfold
let normal (#a:Type) (x:a) : a =
FStar.Pervasives.norm
[iota;
zeta;
delta_attr [`%__reduce__; `%BigOps.__reduce__];
delta_only [`%Base?; `%Array?; `%Some?; `%Some?.v; `%list_of_string];
primops;
simplify]
x
/// `coerce`: A utility to trigger extensional equality of types
noextract
let coerce (x:'a{'a == 'b}) : 'b = x
/// `fragment_printer`: The type of a printer of fragments
noextract
let fragment_printer =
(acc:list frag_t)
-> Stack unit
(requires fun h0 -> live_frags h0 acc)
(ensures fun h0 _ h1 -> h0 == h1)
/// `print_frags`: Having accumulated all the pieces of a format
/// string and the arguments to the printed (i.e., the `list frag_t`),
/// this function does the actual work of printing them all using the
/// primitive printers
noextract inline_for_extraction
let rec print_frags (acc:list frag_t)
: Stack unit
(requires fun h0 -> live_frags h0 acc)
(ensures fun h0 _ h1 -> h0 == h1)
= match acc with
| [] -> ()
| hd::tl ->
print_frags tl;
(match hd with
| Inl s -> print_string s
| Inr (| Base t, Lift value |) ->
(match t with
| Bool -> print_bool value
| Char -> print_char value
| String -> print_string value
| U8 -> print_u8 value
| U16 -> print_u16 value
| U32 -> print_u32 value
| U64 -> print_u64 value
| I8 -> print_i8 value
| I16 -> print_i16 value
| I32 -> print_i32 value
| I64 -> print_i64 value)
| Inr (| Array t, (| l, r, s, value |) |) ->
(match t with
| Bool -> print_lmbuffer_bool l value
| Char -> print_lmbuffer_char l value
| String -> print_lmbuffer_string l value
| U8 -> print_lmbuffer_u8 l value
| U16 -> print_lmbuffer_u16 l value
| U32 -> print_lmbuffer_u32 l value
| U64 -> print_lmbuffer_u64 l value
| I8 -> print_lmbuffer_i8 l value
| I16 -> print_lmbuffer_i16 l value
| I32 -> print_lmbuffer_i32 l value
| I64 -> print_lmbuffer_i64 l value)
| Inr (| Any, (| _, printer, value |) |) ->
printer value)
[@@__reduce__]
let no_inst #a (#b:a -> Type) (f: (#x:a -> b x)) : unit -> #x:a -> b x = fun () -> f
[@@__reduce__]
let elim_unit_arrow #t (f:unit -> t) : t = f ()
// let test2 (f: (#a:Type -> a -> a)) : id_t 0 = test f ()
// let coerce #a (#b: (a -> Type)) ($f: (#x:a -> b x)) (t:Type{norm t == (#x:a -> b x)})
/// `aux frags acc`: This is the main workhorse which interprets a
/// parsed format string (`frags`) as a variadic, stateful function
[@@__reduce__]
noextract inline_for_extraction
let rec aux (frags:fragments) (acc:list frag_t) (fp: fragment_printer) : interpret_frags frags acc =
match frags with
| [] ->
let f (l:lift u#0 u#1 unit)
: Stack unit
(requires fun h0 -> live_frags h0 acc)
(ensures fun h0 _ h1 -> h0 == h1)
= fp acc
in
(f <: interpret_frags [] acc)
| Frag s :: rest ->
coerce (aux rest (Inl s :: acc) fp)
| Interpolate (Base t) :: args ->
let f (x:base_typ_as_type t)
: interpret_frags args (Inr (| Base t, Lift x |) :: acc)
= aux args (Inr (| Base t, Lift x |) :: acc) fp
in
f
| Interpolate (Array t) :: rest ->
let f :
l:UInt32.t
-> #r:LB.srel (base_typ_as_type t)
-> #s:LB.srel (base_typ_as_type t)
-> b:lmbuffer (base_typ_as_type t) r s l
-> interpret_frags rest (Inr (| Array t, (| l, r, s, b |) |) :: acc)
= fun l #r #s b -> aux rest (Inr (| Array t, (| l, r, s, b |) |) :: acc) fp
in
f <: interpret_frags (Interpolate (Array t) :: rest) acc
| Interpolate Any :: rest ->
let f :
unit
-> #a:Type
-> p:(a -> StTrivial unit)
-> x:a
-> interpret_frags rest (Inr (| Any, (| a, p, x |) |) :: acc)
= fun () #a p x -> aux rest (Inr (| Any, (| a, p, x |) |) :: acc) fp
in
elim_unit_arrow (no_inst (f ()) <: (unit -> interpret_frags (Interpolate Any :: rest) acc))
/// `format_string` : A valid format string is one that can be successfully parsed
[@@__reduce__]
noextract
let format_string = s:string{normal #bool (Some? (parse_format_string s))}
/// `interpret_format_string` parses a string into fragments and then
/// interprets it as a type
[@@__reduce__]
noextract
let interpret_format_string (s:format_string) : Type =
interpret_frags (Some?.v (parse_format_string s)) []
/// `printf'`: Almost there ... this has a variadic type
/// and calls the actual printers for all its arguments.
///
/// Note, the `normalize_term` in its body is crucial. It's what
/// allows the term to be specialized at extraction time.
noextract inline_for_extraction
let printf' (s:format_string) : interpret_format_string s =
normalize_term
(match parse_format_string s with
| Some frags -> aux frags [] print_frags)
/// `intro_normal_f`: a technical gadget to introduce
/// implicit normalization in the domain and co-domain of a function type
noextract inline_for_extraction
let intro_normal_f (#a:Type) (b: (a -> Type)) (f:(x:a -> b x))
: (x:(normal a) -> normal (b x))
= f
/// `printf`: The main function has type
/// `s:normal format_string -> normal (interpret_format_string s)`
/// Note:
/// This is the type F* infers for it and it is best to leave it that way
/// rather then writing it down and asking F* to re-check what it inferred.
///
/// Annotating it results in a needless additional proof obligation to
/// equate types after they are partially reduced, which is pointless.
noextract inline_for_extraction
val printf : s:normal format_string -> normal (interpret_format_string s)
let printf = intro_normal_f #format_string interpret_format_string printf'
/// `skip`: We also provide `skip`, a function that has the same type as printf
/// but normalizes to `()`, i.e., it prints nothing. This is useful for conditional
/// printing in debug code, for instance.
noextract inline_for_extraction
let skip' (s:format_string) : interpret_format_string s =
normalize_term
(match parse_format_string s with
| Some frags -> aux frags [] (fun _ -> ()))
noextract inline_for_extraction
val skip : s:normal format_string -> normal (interpret_format_string s)
let skip = intro_normal_f #format_string interpret_format_string skip'
/// `test`: A small test function
/// Running `fstar --codegen OCaml LowStar.Printf.fst --extract LowStar.Printf`
/// produces the following for the body of this function
/// ```
/// print_string "Hello ";
/// print_bool true;
/// print_string " Low* ";
/// print_u64 m;
/// print_string " Printf ";
/// print_lmbuffer_bool l () () x;
/// print_string " ";
/// print_string "bye"
/// ```
let test (m:UInt64.t) (l:UInt32.t) (#r:_) (#s:_) (x:LB.mbuffer bool r s{LB.len x = l})
: Stack unit
(requires (fun h0 -> LB.live h0 x))
(ensures (fun h0 _ h1 -> h0 == h1))
= printf "Hello %b Low* %uL Printf %xb %s"
true //%b boolean
m //%uL u64
l x //%xb (buffer bool)
"bye"
done //dummy universe coercion
let test2 (x:(int * int)) (print_pair:(int * int) -> StTrivial unit)
: Stack unit
(requires (fun h0 -> True))
(ensures (fun h0 _ h1 -> h0 == h1))
= printf "Hello pair %a" print_pair x done | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.Printf.fst"
} | [
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "LB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.String",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Char",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
m: FStar.UInt64.t ->
l: FStar.UInt32.t ->
x: LowStar.Monotonic.Buffer.mbuffer Prims.bool r s {LowStar.Monotonic.Buffer.len x = l}
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"FStar.UInt64.t",
"FStar.UInt32.t",
"LowStar.Monotonic.Buffer.srel",
"Prims.bool",
"LowStar.Monotonic.Buffer.mbuffer",
"Prims.b2t",
"Prims.op_Equality",
"LowStar.Monotonic.Buffer.len",
"LowStar.Printf.skip",
"LowStar.Printf.done",
"Prims.unit",
"FStar.Monotonic.HyperStack.mem",
"LowStar.Monotonic.Buffer.live",
"Prims.eq2"
] | [] | false | true | false | false | false | let test3 (m: UInt64.t) (l: UInt32.t) (#r #s: _) (x: LB.mbuffer bool r s {LB.len x = l})
: Stack unit (requires (fun h0 -> LB.live h0 x)) (ensures (fun h0 _ h1 -> h0 == h1)) =
| skip "Hello %b Low* %uL Printf %xb %s" true m l x "bye" done | false |
LowStar.Printf.fst | LowStar.Printf.aux | val aux (frags: fragments) (acc: list frag_t) (fp: fragment_printer) : interpret_frags frags acc | val aux (frags: fragments) (acc: list frag_t) (fp: fragment_printer) : interpret_frags frags acc | let rec aux (frags:fragments) (acc:list frag_t) (fp: fragment_printer) : interpret_frags frags acc =
match frags with
| [] ->
let f (l:lift u#0 u#1 unit)
: Stack unit
(requires fun h0 -> live_frags h0 acc)
(ensures fun h0 _ h1 -> h0 == h1)
= fp acc
in
(f <: interpret_frags [] acc)
| Frag s :: rest ->
coerce (aux rest (Inl s :: acc) fp)
| Interpolate (Base t) :: args ->
let f (x:base_typ_as_type t)
: interpret_frags args (Inr (| Base t, Lift x |) :: acc)
= aux args (Inr (| Base t, Lift x |) :: acc) fp
in
f
| Interpolate (Array t) :: rest ->
let f :
l:UInt32.t
-> #r:LB.srel (base_typ_as_type t)
-> #s:LB.srel (base_typ_as_type t)
-> b:lmbuffer (base_typ_as_type t) r s l
-> interpret_frags rest (Inr (| Array t, (| l, r, s, b |) |) :: acc)
= fun l #r #s b -> aux rest (Inr (| Array t, (| l, r, s, b |) |) :: acc) fp
in
f <: interpret_frags (Interpolate (Array t) :: rest) acc
| Interpolate Any :: rest ->
let f :
unit
-> #a:Type
-> p:(a -> StTrivial unit)
-> x:a
-> interpret_frags rest (Inr (| Any, (| a, p, x |) |) :: acc)
= fun () #a p x -> aux rest (Inr (| Any, (| a, p, x |) |) :: acc) fp
in
elim_unit_arrow (no_inst (f ()) <: (unit -> interpret_frags (Interpolate Any :: rest) acc)) | {
"file_name": "ulib/LowStar.Printf.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 95,
"end_line": 440,
"start_col": 0,
"start_line": 399
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LowStar.Printf
/// This module provides imperative printing functions for several
/// primitive Low* types, including
/// -- booleans (%b)
/// -- characters (%c)
/// -- strings (%s)
/// -- machine integers
/// (UInt8.t as %uy, UInt16.t as %us, UInt32.t as %ul, and UInt64.t as %uL;
/// Int8.t as %y, Int16.t as %i, Int32.t as %l , and Int64.t as %L)
/// -- and arrays (aka buffers) of these base types formatted
/// as %xN, where N is the format specifier for the array element type
/// e.g., %xuy for buffers of UInt8.t
/// The main function of this module is `printf`
/// There are a few main differences relative to C printf
/// -- The format specifiers are different (see above)
///
/// -- For technical reasons explained below, an extra dummy
/// argument `done` has to be provided at the end for the
/// computation to have any effect.
///
/// E.g., one must write
/// `printf "%b %c" true 'c' done`
/// rather than just
/// `printf "%b %c" true 'c'`
///
/// -- When printing arrays, two arguments must be passed; the
/// length of the array fragment to be formatted and the array
/// itself
///
/// -- When extracted, rather than producing a C `printf` (which
/// does not, e.g., support printing of dynamically sized
/// arrays), our `printf` is specialized to a sequence of calls
/// to primitive printers for each supported type
///
/// Before diving into the technical details of how this module works,
/// you might want to see a sample usage at the very end of this file.
open FStar.Char
open FStar.String
open FStar.HyperStack.ST
module L = FStar.List.Tot
module LB = LowStar.Monotonic.Buffer
/// `lmbuffer a r s l` is
/// - a monotonic buffer of `a`
/// - governed by preorders `r` and `s`
/// - with length `l`
let lmbuffer a r s l =
b:LB.mbuffer a r s{
LB.len b == l
}
/// `StTrivial`: A effect abbreviation for a stateful computation
/// with no precondition, and which does not change the state
effect StTrivial (a:Type) =
Stack a
(requires fun h -> True)
(ensures fun h0 _ h1 -> h0==h1)
/// `StBuf a b`: A effect abbreviation for a stateful computation
/// that may read `b` does not change the state
effect StBuf (a:Type) #t #r #s #l (b:lmbuffer t r s l) =
Stack a
(requires fun h -> LB.live h b)
(ensures (fun h0 _ h1 -> h0 == h1))
/// Primitive printers for all the types supported by this module
assume val print_string: string -> StTrivial unit
assume val print_char : char -> StTrivial unit
assume val print_u8 : UInt8.t -> StTrivial unit
assume val print_u16 : UInt16.t -> StTrivial unit
assume val print_u32 : UInt32.t -> StTrivial unit
assume val print_u64 : UInt64.t -> StTrivial unit
assume val print_i8 : Int8.t -> StTrivial unit
assume val print_i16 : Int16.t -> StTrivial unit
assume val print_i32 : Int32.t -> StTrivial unit
assume val print_i64 : Int64.t -> StTrivial unit
assume val print_bool : bool -> StTrivial unit
assume val print_lmbuffer_bool (l:_) (#r:_) (#s:_) (b:lmbuffer bool r s l) : StBuf unit b
assume val print_lmbuffer_char (l:_) (#r:_) (#s:_) (b:lmbuffer char r s l) : StBuf unit b
assume val print_lmbuffer_string (l:_) (#r:_) (#s:_) (b:lmbuffer string r s l) : StBuf unit b
assume val print_lmbuffer_u8 (l:_) (#r:_) (#s:_) (b:lmbuffer UInt8.t r s l) : StBuf unit b
assume val print_lmbuffer_u16 (l:_) (#r:_) (#s:_) (b:lmbuffer UInt16.t r s l) : StBuf unit b
assume val print_lmbuffer_u32 (l:_) (#r:_) (#s:_) (b:lmbuffer UInt32.t r s l) : StBuf unit b
assume val print_lmbuffer_u64 (l:_) (#r:_) (#s:_) (b:lmbuffer UInt64.t r s l) : StBuf unit b
assume val print_lmbuffer_i8 (l:_) (#r:_) (#s:_) (b:lmbuffer Int8.t r s l) : StBuf unit b
assume val print_lmbuffer_i16 (l:_) (#r:_) (#s:_) (b:lmbuffer Int16.t r s l) : StBuf unit b
assume val print_lmbuffer_i32 (l:_) (#r:_) (#s:_) (b:lmbuffer Int32.t r s l) : StBuf unit b
assume val print_lmbuffer_i64 (l:_) (#r:_) (#s:_) (b:lmbuffer Int64.t r s l) : StBuf unit b
/// An attribute to control reduction
noextract irreducible
let __reduce__ = unit
/// Base types supported so far
noextract
type base_typ =
| Bool
| Char
| String
| U8
| U16
| U32
| U64
| I8
| I16
| I32
| I64
/// Argument types are base types and arrays thereof
/// Or polymorphic arguments specified by "%a"
noextract
type arg =
| Base of base_typ
| Array of base_typ
| Any
/// Interpreting a `base_typ` as a type
[@@__reduce__]
noextract
let base_typ_as_type (b:base_typ) : Type0 =
match b with
| Bool -> bool
| Char -> char
| String -> string
| U8 -> FStar.UInt8.t
| U16 -> FStar.UInt16.t
| U32 -> FStar.UInt32.t
| U64 -> FStar.UInt64.t
| I8 -> FStar.Int8.t
| I16 -> FStar.Int16.t
| I32 -> FStar.Int32.t
| I64 -> FStar.Int64.t
/// `fragment`: A format string is parsed into a list of fragments of
/// string literals and other arguments that need to be spliced in
/// (interpolated)
noextract
type fragment =
| Frag of string
| Interpolate of arg
noextract
let fragments = list fragment
/// `parse_format s`:
/// Parses a list of characters in a format string into a list of fragments
/// Or None, in case the format string is invalid
[@@__reduce__]
noextract inline_for_extraction
let rec parse_format
(s:list char)
: Tot (option fragments)
(decreases (L.length s))
= let add_dir (d:arg) (ods : option fragments)
= match ods with
| None -> None
| Some ds -> Some (Interpolate d::ds)
in
let head_buffer (ods:option fragments)
= match ods with
| Some (Interpolate (Base t) :: rest) -> Some (Interpolate (Array t) :: rest)
| _ -> None
in
let cons_frag (c:char) (ods:option fragments)
= match ods with
| Some (Frag s::rest) -> Some (Frag (string_of_list (c :: list_of_string s)) :: rest)
| Some rest -> Some (Frag (string_of_list [c]) :: rest)
| _ -> None
in
match s with
| [] -> Some []
| ['%'] -> None
// %a... polymorphic arguments and preceded by their printers
| '%' :: 'a' :: s' ->
add_dir Any (parse_format s')
// %x... arrays of base types
| '%' :: 'x' :: s' ->
head_buffer (parse_format ('%' :: s'))
// %u ... Unsigned integers
| '%' :: 'u' :: s' -> begin
match s' with
| 'y' :: s'' -> add_dir (Base U8) (parse_format s'')
| 's' :: s'' -> add_dir (Base U16) (parse_format s'')
| 'l' :: s'' -> add_dir (Base U32) (parse_format s'')
| 'L' :: s'' -> add_dir (Base U64) (parse_format s'')
| _ -> None
end
| '%' :: c :: s' -> begin
match c with
| '%' -> cons_frag '%' (parse_format s')
| 'b' -> add_dir (Base Bool) (parse_format s')
| 'c' -> add_dir (Base Char) (parse_format s')
| 's' -> add_dir (Base String) (parse_format s')
| 'y' -> add_dir (Base I8) (parse_format s')
| 'i' -> add_dir (Base I16) (parse_format s')
| 'l' -> add_dir (Base I32) (parse_format s')
| 'L' -> add_dir (Base I64) (parse_format s')
| _ -> None
end
| c :: s' ->
cons_frag c (parse_format s')
/// `parse_format_string`: a wrapper around `parse_format`
[@@__reduce__]
noextract inline_for_extraction
let parse_format_string
(s:string)
: option fragments
= parse_format (list_of_string s)
/// `lift a` lifts the type `a` to a higher universe
noextract
type lift (a:Type u#a) : Type u#(max a b) =
| Lift : a -> lift a
/// `done` is a `unit` in universe 1
noextract
let done : lift unit = Lift u#0 u#1 ()
/// `arg_t`: interpreting an argument as a type
/// (in universe 1) since it is polymorphic in the preorders of a buffer
/// GM: Somehow, this needs to be a `let rec` (even if it not really recursive)
/// or print_frags fails to verify. I don't know why; the generated
/// VC and its encoding seem identical (modulo hash consing in the
/// latter).
[@@__reduce__]
noextract
let rec arg_t (a:arg) : Type u#1 =
match a with
| Base t -> lift (base_typ_as_type t)
| Array t -> (l:UInt32.t & r:_ & s:_ & lmbuffer (base_typ_as_type t) r s l)
| Any -> (a:Type0 & (a -> StTrivial unit) & a)
/// `frag_t`: a fragment is either a string literal or a argument to be interpolated
noextract
let frag_t = either string (a:arg & arg_t a)
/// `live_frags h l` is a liveness predicate on all the buffers in `l`
[@@__reduce__]
noextract
let rec live_frags (h:_) (l:list frag_t) : prop =
match l with
| [] -> True
| Inl _ :: rest -> live_frags h rest
| Inr a :: rest ->
(match a with
| (| Base _, _ |) -> live_frags h rest
| (| Any, _ |) -> live_frags h rest
| (| Array _, (| _, _, _, b |) |) -> LB.live h b /\ live_frags h rest)
/// `interpret_frags` interprets a list of fragments as a Low* function type
/// Note `l` is the fragments in L-to-R order (i.e., parsing order)
/// `acc` accumulates the fragment values in reverse order
[@@__reduce__]
noextract
let rec interpret_frags (l:fragments) (acc:list frag_t) : Type u#1 =
match l with
| [] ->
// Always a dummy argument at the end
// Ensures that all cases of this match
// have the same universe, i.e., u#1
lift u#0 u#1 unit
-> Stack unit
(requires fun h0 -> live_frags h0 acc)
(ensures fun h0 _ h1 -> h0 == h1)
| Interpolate (Base t) :: args ->
// Base types are simple: we just take one more argument
x:base_typ_as_type t ->
interpret_frags args (Inr (| Base t, Lift x |) :: acc)
| Interpolate (Array t) :: args ->
// Arrays are implicitly polymorphic in their preorders `r` and `s`
// which is what forces us to be in universe 1
// Note, the length `l` is explicit
l:UInt32.t ->
#r:LB.srel (base_typ_as_type t) ->
#s:LB.srel (base_typ_as_type t) ->
b:lmbuffer (base_typ_as_type t) r s l ->
interpret_frags args (Inr (| Array t, (| l, r, s, b |) |) :: acc)
| Interpolate Any :: args ->
#a:Type0 ->
p:(a -> StTrivial unit) ->
x:a ->
interpret_frags args (Inr (| Any, (| a, p, x |) |) :: acc)
| Frag s :: args ->
// Literal fragments do not incur an additional argument
// We just accumulate them and recur
interpret_frags args (Inl s :: acc)
/// `normal` A normalization marker with very specific steps enabled
noextract unfold
let normal (#a:Type) (x:a) : a =
FStar.Pervasives.norm
[iota;
zeta;
delta_attr [`%__reduce__; `%BigOps.__reduce__];
delta_only [`%Base?; `%Array?; `%Some?; `%Some?.v; `%list_of_string];
primops;
simplify]
x
/// `coerce`: A utility to trigger extensional equality of types
noextract
let coerce (x:'a{'a == 'b}) : 'b = x
/// `fragment_printer`: The type of a printer of fragments
noextract
let fragment_printer =
(acc:list frag_t)
-> Stack unit
(requires fun h0 -> live_frags h0 acc)
(ensures fun h0 _ h1 -> h0 == h1)
/// `print_frags`: Having accumulated all the pieces of a format
/// string and the arguments to the printed (i.e., the `list frag_t`),
/// this function does the actual work of printing them all using the
/// primitive printers
noextract inline_for_extraction
let rec print_frags (acc:list frag_t)
: Stack unit
(requires fun h0 -> live_frags h0 acc)
(ensures fun h0 _ h1 -> h0 == h1)
= match acc with
| [] -> ()
| hd::tl ->
print_frags tl;
(match hd with
| Inl s -> print_string s
| Inr (| Base t, Lift value |) ->
(match t with
| Bool -> print_bool value
| Char -> print_char value
| String -> print_string value
| U8 -> print_u8 value
| U16 -> print_u16 value
| U32 -> print_u32 value
| U64 -> print_u64 value
| I8 -> print_i8 value
| I16 -> print_i16 value
| I32 -> print_i32 value
| I64 -> print_i64 value)
| Inr (| Array t, (| l, r, s, value |) |) ->
(match t with
| Bool -> print_lmbuffer_bool l value
| Char -> print_lmbuffer_char l value
| String -> print_lmbuffer_string l value
| U8 -> print_lmbuffer_u8 l value
| U16 -> print_lmbuffer_u16 l value
| U32 -> print_lmbuffer_u32 l value
| U64 -> print_lmbuffer_u64 l value
| I8 -> print_lmbuffer_i8 l value
| I16 -> print_lmbuffer_i16 l value
| I32 -> print_lmbuffer_i32 l value
| I64 -> print_lmbuffer_i64 l value)
| Inr (| Any, (| _, printer, value |) |) ->
printer value)
[@@__reduce__]
let no_inst #a (#b:a -> Type) (f: (#x:a -> b x)) : unit -> #x:a -> b x = fun () -> f
[@@__reduce__]
let elim_unit_arrow #t (f:unit -> t) : t = f ()
// let test2 (f: (#a:Type -> a -> a)) : id_t 0 = test f ()
// let coerce #a (#b: (a -> Type)) ($f: (#x:a -> b x)) (t:Type{norm t == (#x:a -> b x)})
/// `aux frags acc`: This is the main workhorse which interprets a
/// parsed format string (`frags`) as a variadic, stateful function
[@@__reduce__] | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.Printf.fst"
} | [
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "LB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.String",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Char",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
frags: LowStar.Printf.fragments ->
acc: Prims.list LowStar.Printf.frag_t ->
fp: LowStar.Printf.fragment_printer
-> LowStar.Printf.interpret_frags frags acc | Prims.Tot | [
"total"
] | [] | [
"LowStar.Printf.fragments",
"Prims.list",
"LowStar.Printf.frag_t",
"LowStar.Printf.fragment_printer",
"LowStar.Printf.interpret_frags",
"Prims.Nil",
"LowStar.Printf.fragment",
"LowStar.Printf.lift",
"Prims.unit",
"FStar.Monotonic.HyperStack.mem",
"LowStar.Printf.live_frags",
"Prims.eq2",
"Prims.string",
"LowStar.Printf.coerce",
"Prims.Cons",
"FStar.Pervasives.Inl",
"Prims.dtuple2",
"LowStar.Printf.arg",
"LowStar.Printf.arg_t",
"LowStar.Printf.aux",
"LowStar.Printf.base_typ",
"LowStar.Printf.base_typ_as_type",
"FStar.Pervasives.Inr",
"Prims.Mkdtuple2",
"LowStar.Printf.Base",
"LowStar.Printf.Lift",
"LowStar.Printf.Interpolate",
"LowStar.Printf.Array",
"FStar.UInt32.t",
"FStar.Preorder.preorder",
"FStar.Seq.Base.seq",
"LowStar.Printf.lmbuffer",
"FStar.Pervasives.Mkdtuple4",
"LowStar.Printf.elim_unit_arrow",
"LowStar.Printf.no_inst",
"LowStar.Printf.Any",
"FStar.Pervasives.Mkdtuple3"
] | [
"recursion"
] | false | false | false | false | false | let rec aux (frags: fragments) (acc: list frag_t) (fp: fragment_printer) : interpret_frags frags acc =
| match frags with
| [] ->
let f (l: lift u#0 u#1 unit)
: Stack unit (requires fun h0 -> live_frags h0 acc) (ensures fun h0 _ h1 -> h0 == h1) =
fp acc
in
(f <: interpret_frags [] acc)
| Frag s :: rest -> coerce (aux rest (Inl s :: acc) fp)
| Interpolate (Base t) :: args ->
let f (x: base_typ_as_type t) : interpret_frags args (Inr (| Base t, Lift x |) :: acc) =
aux args (Inr (| Base t, Lift x |) :: acc) fp
in
f
| Interpolate (Array t) :: rest ->
let f:
l: UInt32.t ->
#r: LB.srel (base_typ_as_type t) ->
#s: LB.srel (base_typ_as_type t) ->
b: lmbuffer (base_typ_as_type t) r s l
-> interpret_frags rest (Inr (| Array t, (| l, r, s, b |) |) :: acc) =
fun l #r #s b -> aux rest (Inr (| Array t, (| l, r, s, b |) |) :: acc) fp
in
f <: interpret_frags (Interpolate (Array t) :: rest) acc
| Interpolate Any :: rest ->
let f: unit -> #a: Type -> p: (a -> StTrivial unit) -> x: a
-> interpret_frags rest (Inr (| Any, (| a, p, x |) |) :: acc) =
fun () #a p x -> aux rest (Inr (| Any, (| a, p, x |) |) :: acc) fp
in
elim_unit_arrow (no_inst (f ()) <: (unit -> interpret_frags (Interpolate Any :: rest) acc)) | false |
LowStar.Printf.fst | LowStar.Printf.test | val test (m: UInt64.t) (l: UInt32.t) (#r #s: _) (x: LB.mbuffer bool r s {LB.len x = l})
: Stack unit (requires (fun h0 -> LB.live h0 x)) (ensures (fun h0 _ h1 -> h0 == h1)) | val test (m: UInt64.t) (l: UInt32.t) (#r #s: _) (x: LB.mbuffer bool r s {LB.len x = l})
: Stack unit (requires (fun h0 -> LB.live h0 x)) (ensures (fun h0 _ h1 -> h0 == h1)) | let test (m:UInt64.t) (l:UInt32.t) (#r:_) (#s:_) (x:LB.mbuffer bool r s{LB.len x = l})
: Stack unit
(requires (fun h0 -> LB.live h0 x))
(ensures (fun h0 _ h1 -> h0 == h1))
= printf "Hello %b Low* %uL Printf %xb %s"
true //%b boolean
m //%uL u64
l x //%xb (buffer bool)
"bye"
done | {
"file_name": "ulib/LowStar.Printf.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 18,
"end_line": 521,
"start_col": 0,
"start_line": 512
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LowStar.Printf
/// This module provides imperative printing functions for several
/// primitive Low* types, including
/// -- booleans (%b)
/// -- characters (%c)
/// -- strings (%s)
/// -- machine integers
/// (UInt8.t as %uy, UInt16.t as %us, UInt32.t as %ul, and UInt64.t as %uL;
/// Int8.t as %y, Int16.t as %i, Int32.t as %l , and Int64.t as %L)
/// -- and arrays (aka buffers) of these base types formatted
/// as %xN, where N is the format specifier for the array element type
/// e.g., %xuy for buffers of UInt8.t
/// The main function of this module is `printf`
/// There are a few main differences relative to C printf
/// -- The format specifiers are different (see above)
///
/// -- For technical reasons explained below, an extra dummy
/// argument `done` has to be provided at the end for the
/// computation to have any effect.
///
/// E.g., one must write
/// `printf "%b %c" true 'c' done`
/// rather than just
/// `printf "%b %c" true 'c'`
///
/// -- When printing arrays, two arguments must be passed; the
/// length of the array fragment to be formatted and the array
/// itself
///
/// -- When extracted, rather than producing a C `printf` (which
/// does not, e.g., support printing of dynamically sized
/// arrays), our `printf` is specialized to a sequence of calls
/// to primitive printers for each supported type
///
/// Before diving into the technical details of how this module works,
/// you might want to see a sample usage at the very end of this file.
open FStar.Char
open FStar.String
open FStar.HyperStack.ST
module L = FStar.List.Tot
module LB = LowStar.Monotonic.Buffer
/// `lmbuffer a r s l` is
/// - a monotonic buffer of `a`
/// - governed by preorders `r` and `s`
/// - with length `l`
let lmbuffer a r s l =
b:LB.mbuffer a r s{
LB.len b == l
}
/// `StTrivial`: A effect abbreviation for a stateful computation
/// with no precondition, and which does not change the state
effect StTrivial (a:Type) =
Stack a
(requires fun h -> True)
(ensures fun h0 _ h1 -> h0==h1)
/// `StBuf a b`: A effect abbreviation for a stateful computation
/// that may read `b` does not change the state
effect StBuf (a:Type) #t #r #s #l (b:lmbuffer t r s l) =
Stack a
(requires fun h -> LB.live h b)
(ensures (fun h0 _ h1 -> h0 == h1))
/// Primitive printers for all the types supported by this module
assume val print_string: string -> StTrivial unit
assume val print_char : char -> StTrivial unit
assume val print_u8 : UInt8.t -> StTrivial unit
assume val print_u16 : UInt16.t -> StTrivial unit
assume val print_u32 : UInt32.t -> StTrivial unit
assume val print_u64 : UInt64.t -> StTrivial unit
assume val print_i8 : Int8.t -> StTrivial unit
assume val print_i16 : Int16.t -> StTrivial unit
assume val print_i32 : Int32.t -> StTrivial unit
assume val print_i64 : Int64.t -> StTrivial unit
assume val print_bool : bool -> StTrivial unit
assume val print_lmbuffer_bool (l:_) (#r:_) (#s:_) (b:lmbuffer bool r s l) : StBuf unit b
assume val print_lmbuffer_char (l:_) (#r:_) (#s:_) (b:lmbuffer char r s l) : StBuf unit b
assume val print_lmbuffer_string (l:_) (#r:_) (#s:_) (b:lmbuffer string r s l) : StBuf unit b
assume val print_lmbuffer_u8 (l:_) (#r:_) (#s:_) (b:lmbuffer UInt8.t r s l) : StBuf unit b
assume val print_lmbuffer_u16 (l:_) (#r:_) (#s:_) (b:lmbuffer UInt16.t r s l) : StBuf unit b
assume val print_lmbuffer_u32 (l:_) (#r:_) (#s:_) (b:lmbuffer UInt32.t r s l) : StBuf unit b
assume val print_lmbuffer_u64 (l:_) (#r:_) (#s:_) (b:lmbuffer UInt64.t r s l) : StBuf unit b
assume val print_lmbuffer_i8 (l:_) (#r:_) (#s:_) (b:lmbuffer Int8.t r s l) : StBuf unit b
assume val print_lmbuffer_i16 (l:_) (#r:_) (#s:_) (b:lmbuffer Int16.t r s l) : StBuf unit b
assume val print_lmbuffer_i32 (l:_) (#r:_) (#s:_) (b:lmbuffer Int32.t r s l) : StBuf unit b
assume val print_lmbuffer_i64 (l:_) (#r:_) (#s:_) (b:lmbuffer Int64.t r s l) : StBuf unit b
/// An attribute to control reduction
noextract irreducible
let __reduce__ = unit
/// Base types supported so far
noextract
type base_typ =
| Bool
| Char
| String
| U8
| U16
| U32
| U64
| I8
| I16
| I32
| I64
/// Argument types are base types and arrays thereof
/// Or polymorphic arguments specified by "%a"
noextract
type arg =
| Base of base_typ
| Array of base_typ
| Any
/// Interpreting a `base_typ` as a type
[@@__reduce__]
noextract
let base_typ_as_type (b:base_typ) : Type0 =
match b with
| Bool -> bool
| Char -> char
| String -> string
| U8 -> FStar.UInt8.t
| U16 -> FStar.UInt16.t
| U32 -> FStar.UInt32.t
| U64 -> FStar.UInt64.t
| I8 -> FStar.Int8.t
| I16 -> FStar.Int16.t
| I32 -> FStar.Int32.t
| I64 -> FStar.Int64.t
/// `fragment`: A format string is parsed into a list of fragments of
/// string literals and other arguments that need to be spliced in
/// (interpolated)
noextract
type fragment =
| Frag of string
| Interpolate of arg
noextract
let fragments = list fragment
/// `parse_format s`:
/// Parses a list of characters in a format string into a list of fragments
/// Or None, in case the format string is invalid
[@@__reduce__]
noextract inline_for_extraction
let rec parse_format
(s:list char)
: Tot (option fragments)
(decreases (L.length s))
= let add_dir (d:arg) (ods : option fragments)
= match ods with
| None -> None
| Some ds -> Some (Interpolate d::ds)
in
let head_buffer (ods:option fragments)
= match ods with
| Some (Interpolate (Base t) :: rest) -> Some (Interpolate (Array t) :: rest)
| _ -> None
in
let cons_frag (c:char) (ods:option fragments)
= match ods with
| Some (Frag s::rest) -> Some (Frag (string_of_list (c :: list_of_string s)) :: rest)
| Some rest -> Some (Frag (string_of_list [c]) :: rest)
| _ -> None
in
match s with
| [] -> Some []
| ['%'] -> None
// %a... polymorphic arguments and preceded by their printers
| '%' :: 'a' :: s' ->
add_dir Any (parse_format s')
// %x... arrays of base types
| '%' :: 'x' :: s' ->
head_buffer (parse_format ('%' :: s'))
// %u ... Unsigned integers
| '%' :: 'u' :: s' -> begin
match s' with
| 'y' :: s'' -> add_dir (Base U8) (parse_format s'')
| 's' :: s'' -> add_dir (Base U16) (parse_format s'')
| 'l' :: s'' -> add_dir (Base U32) (parse_format s'')
| 'L' :: s'' -> add_dir (Base U64) (parse_format s'')
| _ -> None
end
| '%' :: c :: s' -> begin
match c with
| '%' -> cons_frag '%' (parse_format s')
| 'b' -> add_dir (Base Bool) (parse_format s')
| 'c' -> add_dir (Base Char) (parse_format s')
| 's' -> add_dir (Base String) (parse_format s')
| 'y' -> add_dir (Base I8) (parse_format s')
| 'i' -> add_dir (Base I16) (parse_format s')
| 'l' -> add_dir (Base I32) (parse_format s')
| 'L' -> add_dir (Base I64) (parse_format s')
| _ -> None
end
| c :: s' ->
cons_frag c (parse_format s')
/// `parse_format_string`: a wrapper around `parse_format`
[@@__reduce__]
noextract inline_for_extraction
let parse_format_string
(s:string)
: option fragments
= parse_format (list_of_string s)
/// `lift a` lifts the type `a` to a higher universe
noextract
type lift (a:Type u#a) : Type u#(max a b) =
| Lift : a -> lift a
/// `done` is a `unit` in universe 1
noextract
let done : lift unit = Lift u#0 u#1 ()
/// `arg_t`: interpreting an argument as a type
/// (in universe 1) since it is polymorphic in the preorders of a buffer
/// GM: Somehow, this needs to be a `let rec` (even if it not really recursive)
/// or print_frags fails to verify. I don't know why; the generated
/// VC and its encoding seem identical (modulo hash consing in the
/// latter).
[@@__reduce__]
noextract
let rec arg_t (a:arg) : Type u#1 =
match a with
| Base t -> lift (base_typ_as_type t)
| Array t -> (l:UInt32.t & r:_ & s:_ & lmbuffer (base_typ_as_type t) r s l)
| Any -> (a:Type0 & (a -> StTrivial unit) & a)
/// `frag_t`: a fragment is either a string literal or a argument to be interpolated
noextract
let frag_t = either string (a:arg & arg_t a)
/// `live_frags h l` is a liveness predicate on all the buffers in `l`
[@@__reduce__]
noextract
let rec live_frags (h:_) (l:list frag_t) : prop =
match l with
| [] -> True
| Inl _ :: rest -> live_frags h rest
| Inr a :: rest ->
(match a with
| (| Base _, _ |) -> live_frags h rest
| (| Any, _ |) -> live_frags h rest
| (| Array _, (| _, _, _, b |) |) -> LB.live h b /\ live_frags h rest)
/// `interpret_frags` interprets a list of fragments as a Low* function type
/// Note `l` is the fragments in L-to-R order (i.e., parsing order)
/// `acc` accumulates the fragment values in reverse order
[@@__reduce__]
noextract
let rec interpret_frags (l:fragments) (acc:list frag_t) : Type u#1 =
match l with
| [] ->
// Always a dummy argument at the end
// Ensures that all cases of this match
// have the same universe, i.e., u#1
lift u#0 u#1 unit
-> Stack unit
(requires fun h0 -> live_frags h0 acc)
(ensures fun h0 _ h1 -> h0 == h1)
| Interpolate (Base t) :: args ->
// Base types are simple: we just take one more argument
x:base_typ_as_type t ->
interpret_frags args (Inr (| Base t, Lift x |) :: acc)
| Interpolate (Array t) :: args ->
// Arrays are implicitly polymorphic in their preorders `r` and `s`
// which is what forces us to be in universe 1
// Note, the length `l` is explicit
l:UInt32.t ->
#r:LB.srel (base_typ_as_type t) ->
#s:LB.srel (base_typ_as_type t) ->
b:lmbuffer (base_typ_as_type t) r s l ->
interpret_frags args (Inr (| Array t, (| l, r, s, b |) |) :: acc)
| Interpolate Any :: args ->
#a:Type0 ->
p:(a -> StTrivial unit) ->
x:a ->
interpret_frags args (Inr (| Any, (| a, p, x |) |) :: acc)
| Frag s :: args ->
// Literal fragments do not incur an additional argument
// We just accumulate them and recur
interpret_frags args (Inl s :: acc)
/// `normal` A normalization marker with very specific steps enabled
noextract unfold
let normal (#a:Type) (x:a) : a =
FStar.Pervasives.norm
[iota;
zeta;
delta_attr [`%__reduce__; `%BigOps.__reduce__];
delta_only [`%Base?; `%Array?; `%Some?; `%Some?.v; `%list_of_string];
primops;
simplify]
x
/// `coerce`: A utility to trigger extensional equality of types
noextract
let coerce (x:'a{'a == 'b}) : 'b = x
/// `fragment_printer`: The type of a printer of fragments
noextract
let fragment_printer =
(acc:list frag_t)
-> Stack unit
(requires fun h0 -> live_frags h0 acc)
(ensures fun h0 _ h1 -> h0 == h1)
/// `print_frags`: Having accumulated all the pieces of a format
/// string and the arguments to the printed (i.e., the `list frag_t`),
/// this function does the actual work of printing them all using the
/// primitive printers
noextract inline_for_extraction
let rec print_frags (acc:list frag_t)
: Stack unit
(requires fun h0 -> live_frags h0 acc)
(ensures fun h0 _ h1 -> h0 == h1)
= match acc with
| [] -> ()
| hd::tl ->
print_frags tl;
(match hd with
| Inl s -> print_string s
| Inr (| Base t, Lift value |) ->
(match t with
| Bool -> print_bool value
| Char -> print_char value
| String -> print_string value
| U8 -> print_u8 value
| U16 -> print_u16 value
| U32 -> print_u32 value
| U64 -> print_u64 value
| I8 -> print_i8 value
| I16 -> print_i16 value
| I32 -> print_i32 value
| I64 -> print_i64 value)
| Inr (| Array t, (| l, r, s, value |) |) ->
(match t with
| Bool -> print_lmbuffer_bool l value
| Char -> print_lmbuffer_char l value
| String -> print_lmbuffer_string l value
| U8 -> print_lmbuffer_u8 l value
| U16 -> print_lmbuffer_u16 l value
| U32 -> print_lmbuffer_u32 l value
| U64 -> print_lmbuffer_u64 l value
| I8 -> print_lmbuffer_i8 l value
| I16 -> print_lmbuffer_i16 l value
| I32 -> print_lmbuffer_i32 l value
| I64 -> print_lmbuffer_i64 l value)
| Inr (| Any, (| _, printer, value |) |) ->
printer value)
[@@__reduce__]
let no_inst #a (#b:a -> Type) (f: (#x:a -> b x)) : unit -> #x:a -> b x = fun () -> f
[@@__reduce__]
let elim_unit_arrow #t (f:unit -> t) : t = f ()
// let test2 (f: (#a:Type -> a -> a)) : id_t 0 = test f ()
// let coerce #a (#b: (a -> Type)) ($f: (#x:a -> b x)) (t:Type{norm t == (#x:a -> b x)})
/// `aux frags acc`: This is the main workhorse which interprets a
/// parsed format string (`frags`) as a variadic, stateful function
[@@__reduce__]
noextract inline_for_extraction
let rec aux (frags:fragments) (acc:list frag_t) (fp: fragment_printer) : interpret_frags frags acc =
match frags with
| [] ->
let f (l:lift u#0 u#1 unit)
: Stack unit
(requires fun h0 -> live_frags h0 acc)
(ensures fun h0 _ h1 -> h0 == h1)
= fp acc
in
(f <: interpret_frags [] acc)
| Frag s :: rest ->
coerce (aux rest (Inl s :: acc) fp)
| Interpolate (Base t) :: args ->
let f (x:base_typ_as_type t)
: interpret_frags args (Inr (| Base t, Lift x |) :: acc)
= aux args (Inr (| Base t, Lift x |) :: acc) fp
in
f
| Interpolate (Array t) :: rest ->
let f :
l:UInt32.t
-> #r:LB.srel (base_typ_as_type t)
-> #s:LB.srel (base_typ_as_type t)
-> b:lmbuffer (base_typ_as_type t) r s l
-> interpret_frags rest (Inr (| Array t, (| l, r, s, b |) |) :: acc)
= fun l #r #s b -> aux rest (Inr (| Array t, (| l, r, s, b |) |) :: acc) fp
in
f <: interpret_frags (Interpolate (Array t) :: rest) acc
| Interpolate Any :: rest ->
let f :
unit
-> #a:Type
-> p:(a -> StTrivial unit)
-> x:a
-> interpret_frags rest (Inr (| Any, (| a, p, x |) |) :: acc)
= fun () #a p x -> aux rest (Inr (| Any, (| a, p, x |) |) :: acc) fp
in
elim_unit_arrow (no_inst (f ()) <: (unit -> interpret_frags (Interpolate Any :: rest) acc))
/// `format_string` : A valid format string is one that can be successfully parsed
[@@__reduce__]
noextract
let format_string = s:string{normal #bool (Some? (parse_format_string s))}
/// `interpret_format_string` parses a string into fragments and then
/// interprets it as a type
[@@__reduce__]
noextract
let interpret_format_string (s:format_string) : Type =
interpret_frags (Some?.v (parse_format_string s)) []
/// `printf'`: Almost there ... this has a variadic type
/// and calls the actual printers for all its arguments.
///
/// Note, the `normalize_term` in its body is crucial. It's what
/// allows the term to be specialized at extraction time.
noextract inline_for_extraction
let printf' (s:format_string) : interpret_format_string s =
normalize_term
(match parse_format_string s with
| Some frags -> aux frags [] print_frags)
/// `intro_normal_f`: a technical gadget to introduce
/// implicit normalization in the domain and co-domain of a function type
noextract inline_for_extraction
let intro_normal_f (#a:Type) (b: (a -> Type)) (f:(x:a -> b x))
: (x:(normal a) -> normal (b x))
= f
/// `printf`: The main function has type
/// `s:normal format_string -> normal (interpret_format_string s)`
/// Note:
/// This is the type F* infers for it and it is best to leave it that way
/// rather then writing it down and asking F* to re-check what it inferred.
///
/// Annotating it results in a needless additional proof obligation to
/// equate types after they are partially reduced, which is pointless.
noextract inline_for_extraction
val printf : s:normal format_string -> normal (interpret_format_string s)
let printf = intro_normal_f #format_string interpret_format_string printf'
/// `skip`: We also provide `skip`, a function that has the same type as printf
/// but normalizes to `()`, i.e., it prints nothing. This is useful for conditional
/// printing in debug code, for instance.
noextract inline_for_extraction
let skip' (s:format_string) : interpret_format_string s =
normalize_term
(match parse_format_string s with
| Some frags -> aux frags [] (fun _ -> ()))
noextract inline_for_extraction
val skip : s:normal format_string -> normal (interpret_format_string s)
let skip = intro_normal_f #format_string interpret_format_string skip'
/// `test`: A small test function
/// Running `fstar --codegen OCaml LowStar.Printf.fst --extract LowStar.Printf`
/// produces the following for the body of this function
/// ```
/// print_string "Hello ";
/// print_bool true;
/// print_string " Low* ";
/// print_u64 m;
/// print_string " Printf ";
/// print_lmbuffer_bool l () () x;
/// print_string " ";
/// print_string "bye" | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.Printf.fst"
} | [
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "LB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.String",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Char",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
m: FStar.UInt64.t ->
l: FStar.UInt32.t ->
x: LowStar.Monotonic.Buffer.mbuffer Prims.bool r s {LowStar.Monotonic.Buffer.len x = l}
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"FStar.UInt64.t",
"FStar.UInt32.t",
"LowStar.Monotonic.Buffer.srel",
"Prims.bool",
"LowStar.Monotonic.Buffer.mbuffer",
"Prims.b2t",
"Prims.op_Equality",
"LowStar.Monotonic.Buffer.len",
"LowStar.Printf.printf",
"LowStar.Printf.done",
"Prims.unit",
"FStar.Monotonic.HyperStack.mem",
"LowStar.Monotonic.Buffer.live",
"Prims.eq2"
] | [] | false | true | false | false | false | let test (m: UInt64.t) (l: UInt32.t) (#r #s: _) (x: LB.mbuffer bool r s {LB.len x = l})
: Stack unit (requires (fun h0 -> LB.live h0 x)) (ensures (fun h0 _ h1 -> h0 == h1)) =
| printf "Hello %b Low* %uL Printf %xb %s" true m l x "bye" done | false |
LowStar.Printf.fst | LowStar.Printf.print_frags | val print_frags (acc: list frag_t)
: Stack unit (requires fun h0 -> live_frags h0 acc) (ensures fun h0 _ h1 -> h0 == h1) | val print_frags (acc: list frag_t)
: Stack unit (requires fun h0 -> live_frags h0 acc) (ensures fun h0 _ h1 -> h0 == h1) | let rec print_frags (acc:list frag_t)
: Stack unit
(requires fun h0 -> live_frags h0 acc)
(ensures fun h0 _ h1 -> h0 == h1)
= match acc with
| [] -> ()
| hd::tl ->
print_frags tl;
(match hd with
| Inl s -> print_string s
| Inr (| Base t, Lift value |) ->
(match t with
| Bool -> print_bool value
| Char -> print_char value
| String -> print_string value
| U8 -> print_u8 value
| U16 -> print_u16 value
| U32 -> print_u32 value
| U64 -> print_u64 value
| I8 -> print_i8 value
| I16 -> print_i16 value
| I32 -> print_i32 value
| I64 -> print_i64 value)
| Inr (| Array t, (| l, r, s, value |) |) ->
(match t with
| Bool -> print_lmbuffer_bool l value
| Char -> print_lmbuffer_char l value
| String -> print_lmbuffer_string l value
| U8 -> print_lmbuffer_u8 l value
| U16 -> print_lmbuffer_u16 l value
| U32 -> print_lmbuffer_u32 l value
| U64 -> print_lmbuffer_u64 l value
| I8 -> print_lmbuffer_i8 l value
| I16 -> print_lmbuffer_i16 l value
| I32 -> print_lmbuffer_i32 l value
| I64 -> print_lmbuffer_i64 l value)
| Inr (| Any, (| _, printer, value |) |) ->
printer value) | {
"file_name": "ulib/LowStar.Printf.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 23,
"end_line": 386,
"start_col": 0,
"start_line": 349
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LowStar.Printf
/// This module provides imperative printing functions for several
/// primitive Low* types, including
/// -- booleans (%b)
/// -- characters (%c)
/// -- strings (%s)
/// -- machine integers
/// (UInt8.t as %uy, UInt16.t as %us, UInt32.t as %ul, and UInt64.t as %uL;
/// Int8.t as %y, Int16.t as %i, Int32.t as %l , and Int64.t as %L)
/// -- and arrays (aka buffers) of these base types formatted
/// as %xN, where N is the format specifier for the array element type
/// e.g., %xuy for buffers of UInt8.t
/// The main function of this module is `printf`
/// There are a few main differences relative to C printf
/// -- The format specifiers are different (see above)
///
/// -- For technical reasons explained below, an extra dummy
/// argument `done` has to be provided at the end for the
/// computation to have any effect.
///
/// E.g., one must write
/// `printf "%b %c" true 'c' done`
/// rather than just
/// `printf "%b %c" true 'c'`
///
/// -- When printing arrays, two arguments must be passed; the
/// length of the array fragment to be formatted and the array
/// itself
///
/// -- When extracted, rather than producing a C `printf` (which
/// does not, e.g., support printing of dynamically sized
/// arrays), our `printf` is specialized to a sequence of calls
/// to primitive printers for each supported type
///
/// Before diving into the technical details of how this module works,
/// you might want to see a sample usage at the very end of this file.
open FStar.Char
open FStar.String
open FStar.HyperStack.ST
module L = FStar.List.Tot
module LB = LowStar.Monotonic.Buffer
/// `lmbuffer a r s l` is
/// - a monotonic buffer of `a`
/// - governed by preorders `r` and `s`
/// - with length `l`
let lmbuffer a r s l =
b:LB.mbuffer a r s{
LB.len b == l
}
/// `StTrivial`: A effect abbreviation for a stateful computation
/// with no precondition, and which does not change the state
effect StTrivial (a:Type) =
Stack a
(requires fun h -> True)
(ensures fun h0 _ h1 -> h0==h1)
/// `StBuf a b`: A effect abbreviation for a stateful computation
/// that may read `b` does not change the state
effect StBuf (a:Type) #t #r #s #l (b:lmbuffer t r s l) =
Stack a
(requires fun h -> LB.live h b)
(ensures (fun h0 _ h1 -> h0 == h1))
/// Primitive printers for all the types supported by this module
assume val print_string: string -> StTrivial unit
assume val print_char : char -> StTrivial unit
assume val print_u8 : UInt8.t -> StTrivial unit
assume val print_u16 : UInt16.t -> StTrivial unit
assume val print_u32 : UInt32.t -> StTrivial unit
assume val print_u64 : UInt64.t -> StTrivial unit
assume val print_i8 : Int8.t -> StTrivial unit
assume val print_i16 : Int16.t -> StTrivial unit
assume val print_i32 : Int32.t -> StTrivial unit
assume val print_i64 : Int64.t -> StTrivial unit
assume val print_bool : bool -> StTrivial unit
assume val print_lmbuffer_bool (l:_) (#r:_) (#s:_) (b:lmbuffer bool r s l) : StBuf unit b
assume val print_lmbuffer_char (l:_) (#r:_) (#s:_) (b:lmbuffer char r s l) : StBuf unit b
assume val print_lmbuffer_string (l:_) (#r:_) (#s:_) (b:lmbuffer string r s l) : StBuf unit b
assume val print_lmbuffer_u8 (l:_) (#r:_) (#s:_) (b:lmbuffer UInt8.t r s l) : StBuf unit b
assume val print_lmbuffer_u16 (l:_) (#r:_) (#s:_) (b:lmbuffer UInt16.t r s l) : StBuf unit b
assume val print_lmbuffer_u32 (l:_) (#r:_) (#s:_) (b:lmbuffer UInt32.t r s l) : StBuf unit b
assume val print_lmbuffer_u64 (l:_) (#r:_) (#s:_) (b:lmbuffer UInt64.t r s l) : StBuf unit b
assume val print_lmbuffer_i8 (l:_) (#r:_) (#s:_) (b:lmbuffer Int8.t r s l) : StBuf unit b
assume val print_lmbuffer_i16 (l:_) (#r:_) (#s:_) (b:lmbuffer Int16.t r s l) : StBuf unit b
assume val print_lmbuffer_i32 (l:_) (#r:_) (#s:_) (b:lmbuffer Int32.t r s l) : StBuf unit b
assume val print_lmbuffer_i64 (l:_) (#r:_) (#s:_) (b:lmbuffer Int64.t r s l) : StBuf unit b
/// An attribute to control reduction
noextract irreducible
let __reduce__ = unit
/// Base types supported so far
noextract
type base_typ =
| Bool
| Char
| String
| U8
| U16
| U32
| U64
| I8
| I16
| I32
| I64
/// Argument types are base types and arrays thereof
/// Or polymorphic arguments specified by "%a"
noextract
type arg =
| Base of base_typ
| Array of base_typ
| Any
/// Interpreting a `base_typ` as a type
[@@__reduce__]
noextract
let base_typ_as_type (b:base_typ) : Type0 =
match b with
| Bool -> bool
| Char -> char
| String -> string
| U8 -> FStar.UInt8.t
| U16 -> FStar.UInt16.t
| U32 -> FStar.UInt32.t
| U64 -> FStar.UInt64.t
| I8 -> FStar.Int8.t
| I16 -> FStar.Int16.t
| I32 -> FStar.Int32.t
| I64 -> FStar.Int64.t
/// `fragment`: A format string is parsed into a list of fragments of
/// string literals and other arguments that need to be spliced in
/// (interpolated)
noextract
type fragment =
| Frag of string
| Interpolate of arg
noextract
let fragments = list fragment
/// `parse_format s`:
/// Parses a list of characters in a format string into a list of fragments
/// Or None, in case the format string is invalid
[@@__reduce__]
noextract inline_for_extraction
let rec parse_format
(s:list char)
: Tot (option fragments)
(decreases (L.length s))
= let add_dir (d:arg) (ods : option fragments)
= match ods with
| None -> None
| Some ds -> Some (Interpolate d::ds)
in
let head_buffer (ods:option fragments)
= match ods with
| Some (Interpolate (Base t) :: rest) -> Some (Interpolate (Array t) :: rest)
| _ -> None
in
let cons_frag (c:char) (ods:option fragments)
= match ods with
| Some (Frag s::rest) -> Some (Frag (string_of_list (c :: list_of_string s)) :: rest)
| Some rest -> Some (Frag (string_of_list [c]) :: rest)
| _ -> None
in
match s with
| [] -> Some []
| ['%'] -> None
// %a... polymorphic arguments and preceded by their printers
| '%' :: 'a' :: s' ->
add_dir Any (parse_format s')
// %x... arrays of base types
| '%' :: 'x' :: s' ->
head_buffer (parse_format ('%' :: s'))
// %u ... Unsigned integers
| '%' :: 'u' :: s' -> begin
match s' with
| 'y' :: s'' -> add_dir (Base U8) (parse_format s'')
| 's' :: s'' -> add_dir (Base U16) (parse_format s'')
| 'l' :: s'' -> add_dir (Base U32) (parse_format s'')
| 'L' :: s'' -> add_dir (Base U64) (parse_format s'')
| _ -> None
end
| '%' :: c :: s' -> begin
match c with
| '%' -> cons_frag '%' (parse_format s')
| 'b' -> add_dir (Base Bool) (parse_format s')
| 'c' -> add_dir (Base Char) (parse_format s')
| 's' -> add_dir (Base String) (parse_format s')
| 'y' -> add_dir (Base I8) (parse_format s')
| 'i' -> add_dir (Base I16) (parse_format s')
| 'l' -> add_dir (Base I32) (parse_format s')
| 'L' -> add_dir (Base I64) (parse_format s')
| _ -> None
end
| c :: s' ->
cons_frag c (parse_format s')
/// `parse_format_string`: a wrapper around `parse_format`
[@@__reduce__]
noextract inline_for_extraction
let parse_format_string
(s:string)
: option fragments
= parse_format (list_of_string s)
/// `lift a` lifts the type `a` to a higher universe
noextract
type lift (a:Type u#a) : Type u#(max a b) =
| Lift : a -> lift a
/// `done` is a `unit` in universe 1
noextract
let done : lift unit = Lift u#0 u#1 ()
/// `arg_t`: interpreting an argument as a type
/// (in universe 1) since it is polymorphic in the preorders of a buffer
/// GM: Somehow, this needs to be a `let rec` (even if it not really recursive)
/// or print_frags fails to verify. I don't know why; the generated
/// VC and its encoding seem identical (modulo hash consing in the
/// latter).
[@@__reduce__]
noextract
let rec arg_t (a:arg) : Type u#1 =
match a with
| Base t -> lift (base_typ_as_type t)
| Array t -> (l:UInt32.t & r:_ & s:_ & lmbuffer (base_typ_as_type t) r s l)
| Any -> (a:Type0 & (a -> StTrivial unit) & a)
/// `frag_t`: a fragment is either a string literal or a argument to be interpolated
noextract
let frag_t = either string (a:arg & arg_t a)
/// `live_frags h l` is a liveness predicate on all the buffers in `l`
[@@__reduce__]
noextract
let rec live_frags (h:_) (l:list frag_t) : prop =
match l with
| [] -> True
| Inl _ :: rest -> live_frags h rest
| Inr a :: rest ->
(match a with
| (| Base _, _ |) -> live_frags h rest
| (| Any, _ |) -> live_frags h rest
| (| Array _, (| _, _, _, b |) |) -> LB.live h b /\ live_frags h rest)
/// `interpret_frags` interprets a list of fragments as a Low* function type
/// Note `l` is the fragments in L-to-R order (i.e., parsing order)
/// `acc` accumulates the fragment values in reverse order
[@@__reduce__]
noextract
let rec interpret_frags (l:fragments) (acc:list frag_t) : Type u#1 =
match l with
| [] ->
// Always a dummy argument at the end
// Ensures that all cases of this match
// have the same universe, i.e., u#1
lift u#0 u#1 unit
-> Stack unit
(requires fun h0 -> live_frags h0 acc)
(ensures fun h0 _ h1 -> h0 == h1)
| Interpolate (Base t) :: args ->
// Base types are simple: we just take one more argument
x:base_typ_as_type t ->
interpret_frags args (Inr (| Base t, Lift x |) :: acc)
| Interpolate (Array t) :: args ->
// Arrays are implicitly polymorphic in their preorders `r` and `s`
// which is what forces us to be in universe 1
// Note, the length `l` is explicit
l:UInt32.t ->
#r:LB.srel (base_typ_as_type t) ->
#s:LB.srel (base_typ_as_type t) ->
b:lmbuffer (base_typ_as_type t) r s l ->
interpret_frags args (Inr (| Array t, (| l, r, s, b |) |) :: acc)
| Interpolate Any :: args ->
#a:Type0 ->
p:(a -> StTrivial unit) ->
x:a ->
interpret_frags args (Inr (| Any, (| a, p, x |) |) :: acc)
| Frag s :: args ->
// Literal fragments do not incur an additional argument
// We just accumulate them and recur
interpret_frags args (Inl s :: acc)
/// `normal` A normalization marker with very specific steps enabled
noextract unfold
let normal (#a:Type) (x:a) : a =
FStar.Pervasives.norm
[iota;
zeta;
delta_attr [`%__reduce__; `%BigOps.__reduce__];
delta_only [`%Base?; `%Array?; `%Some?; `%Some?.v; `%list_of_string];
primops;
simplify]
x
/// `coerce`: A utility to trigger extensional equality of types
noextract
let coerce (x:'a{'a == 'b}) : 'b = x
/// `fragment_printer`: The type of a printer of fragments
noextract
let fragment_printer =
(acc:list frag_t)
-> Stack unit
(requires fun h0 -> live_frags h0 acc)
(ensures fun h0 _ h1 -> h0 == h1)
/// `print_frags`: Having accumulated all the pieces of a format
/// string and the arguments to the printed (i.e., the `list frag_t`),
/// this function does the actual work of printing them all using the
/// primitive printers | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.Printf.fst"
} | [
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "LB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.String",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Char",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | acc: Prims.list LowStar.Printf.frag_t -> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"Prims.list",
"LowStar.Printf.frag_t",
"Prims.unit",
"Prims.string",
"LowStar.Printf.print_string",
"LowStar.Printf.base_typ",
"LowStar.Printf.base_typ_as_type",
"LowStar.Printf.print_bool",
"LowStar.Printf.print_char",
"LowStar.Printf.print_u8",
"LowStar.Printf.print_u16",
"LowStar.Printf.print_u32",
"LowStar.Printf.print_u64",
"LowStar.Printf.print_i8",
"LowStar.Printf.print_i16",
"LowStar.Printf.print_i32",
"LowStar.Printf.print_i64",
"FStar.UInt32.t",
"LowStar.Monotonic.Buffer.srel",
"LowStar.Printf.lmbuffer",
"LowStar.Printf.print_lmbuffer_bool",
"LowStar.Printf.print_lmbuffer_char",
"LowStar.Printf.print_lmbuffer_string",
"LowStar.Printf.print_lmbuffer_u8",
"LowStar.Printf.print_lmbuffer_u16",
"LowStar.Printf.print_lmbuffer_u32",
"LowStar.Printf.print_lmbuffer_u64",
"LowStar.Printf.print_lmbuffer_i8",
"LowStar.Printf.print_lmbuffer_i16",
"LowStar.Printf.print_lmbuffer_i32",
"LowStar.Printf.print_lmbuffer_i64",
"LowStar.Printf.print_frags",
"FStar.Monotonic.HyperStack.mem",
"LowStar.Printf.live_frags",
"Prims.eq2"
] | [
"recursion"
] | false | true | false | false | false | let rec print_frags (acc: list frag_t)
: Stack unit (requires fun h0 -> live_frags h0 acc) (ensures fun h0 _ h1 -> h0 == h1) =
| match acc with
| [] -> ()
| hd :: tl ->
print_frags tl;
(match hd with
| Inl s -> print_string s
| Inr (| Base t , Lift value |) ->
(match t with
| Bool -> print_bool value
| Char -> print_char value
| String -> print_string value
| U8 -> print_u8 value
| U16 -> print_u16 value
| U32 -> print_u32 value
| U64 -> print_u64 value
| I8 -> print_i8 value
| I16 -> print_i16 value
| I32 -> print_i32 value
| I64 -> print_i64 value)
| Inr (| Array t , (| l , r , s , value |) |) ->
(match t with
| Bool -> print_lmbuffer_bool l value
| Char -> print_lmbuffer_char l value
| String -> print_lmbuffer_string l value
| U8 -> print_lmbuffer_u8 l value
| U16 -> print_lmbuffer_u16 l value
| U32 -> print_lmbuffer_u32 l value
| U64 -> print_lmbuffer_u64 l value
| I8 -> print_lmbuffer_i8 l value
| I16 -> print_lmbuffer_i16 l value
| I32 -> print_lmbuffer_i32 l value
| I64 -> print_lmbuffer_i64 l value)
| Inr (| Any , (| _ , printer , value |) |) -> printer value) | false |
LowStar.Printf.fst | LowStar.Printf.parse_format | val parse_format (s: list char) : Tot (option fragments) (decreases (L.length s)) | val parse_format (s: list char) : Tot (option fragments) (decreases (L.length s)) | let rec parse_format
(s:list char)
: Tot (option fragments)
(decreases (L.length s))
= let add_dir (d:arg) (ods : option fragments)
= match ods with
| None -> None
| Some ds -> Some (Interpolate d::ds)
in
let head_buffer (ods:option fragments)
= match ods with
| Some (Interpolate (Base t) :: rest) -> Some (Interpolate (Array t) :: rest)
| _ -> None
in
let cons_frag (c:char) (ods:option fragments)
= match ods with
| Some (Frag s::rest) -> Some (Frag (string_of_list (c :: list_of_string s)) :: rest)
| Some rest -> Some (Frag (string_of_list [c]) :: rest)
| _ -> None
in
match s with
| [] -> Some []
| ['%'] -> None
// %a... polymorphic arguments and preceded by their printers
| '%' :: 'a' :: s' ->
add_dir Any (parse_format s')
// %x... arrays of base types
| '%' :: 'x' :: s' ->
head_buffer (parse_format ('%' :: s'))
// %u ... Unsigned integers
| '%' :: 'u' :: s' -> begin
match s' with
| 'y' :: s'' -> add_dir (Base U8) (parse_format s'')
| 's' :: s'' -> add_dir (Base U16) (parse_format s'')
| 'l' :: s'' -> add_dir (Base U32) (parse_format s'')
| 'L' :: s'' -> add_dir (Base U64) (parse_format s'')
| _ -> None
end
| '%' :: c :: s' -> begin
match c with
| '%' -> cons_frag '%' (parse_format s')
| 'b' -> add_dir (Base Bool) (parse_format s')
| 'c' -> add_dir (Base Char) (parse_format s')
| 's' -> add_dir (Base String) (parse_format s')
| 'y' -> add_dir (Base I8) (parse_format s')
| 'i' -> add_dir (Base I16) (parse_format s')
| 'l' -> add_dir (Base I32) (parse_format s')
| 'L' -> add_dir (Base I64) (parse_format s')
| _ -> None
end
| c :: s' ->
cons_frag c (parse_format s') | {
"file_name": "ulib/LowStar.Printf.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 34,
"end_line": 225,
"start_col": 0,
"start_line": 169
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LowStar.Printf
/// This module provides imperative printing functions for several
/// primitive Low* types, including
/// -- booleans (%b)
/// -- characters (%c)
/// -- strings (%s)
/// -- machine integers
/// (UInt8.t as %uy, UInt16.t as %us, UInt32.t as %ul, and UInt64.t as %uL;
/// Int8.t as %y, Int16.t as %i, Int32.t as %l , and Int64.t as %L)
/// -- and arrays (aka buffers) of these base types formatted
/// as %xN, where N is the format specifier for the array element type
/// e.g., %xuy for buffers of UInt8.t
/// The main function of this module is `printf`
/// There are a few main differences relative to C printf
/// -- The format specifiers are different (see above)
///
/// -- For technical reasons explained below, an extra dummy
/// argument `done` has to be provided at the end for the
/// computation to have any effect.
///
/// E.g., one must write
/// `printf "%b %c" true 'c' done`
/// rather than just
/// `printf "%b %c" true 'c'`
///
/// -- When printing arrays, two arguments must be passed; the
/// length of the array fragment to be formatted and the array
/// itself
///
/// -- When extracted, rather than producing a C `printf` (which
/// does not, e.g., support printing of dynamically sized
/// arrays), our `printf` is specialized to a sequence of calls
/// to primitive printers for each supported type
///
/// Before diving into the technical details of how this module works,
/// you might want to see a sample usage at the very end of this file.
open FStar.Char
open FStar.String
open FStar.HyperStack.ST
module L = FStar.List.Tot
module LB = LowStar.Monotonic.Buffer
/// `lmbuffer a r s l` is
/// - a monotonic buffer of `a`
/// - governed by preorders `r` and `s`
/// - with length `l`
let lmbuffer a r s l =
b:LB.mbuffer a r s{
LB.len b == l
}
/// `StTrivial`: A effect abbreviation for a stateful computation
/// with no precondition, and which does not change the state
effect StTrivial (a:Type) =
Stack a
(requires fun h -> True)
(ensures fun h0 _ h1 -> h0==h1)
/// `StBuf a b`: A effect abbreviation for a stateful computation
/// that may read `b` does not change the state
effect StBuf (a:Type) #t #r #s #l (b:lmbuffer t r s l) =
Stack a
(requires fun h -> LB.live h b)
(ensures (fun h0 _ h1 -> h0 == h1))
/// Primitive printers for all the types supported by this module
assume val print_string: string -> StTrivial unit
assume val print_char : char -> StTrivial unit
assume val print_u8 : UInt8.t -> StTrivial unit
assume val print_u16 : UInt16.t -> StTrivial unit
assume val print_u32 : UInt32.t -> StTrivial unit
assume val print_u64 : UInt64.t -> StTrivial unit
assume val print_i8 : Int8.t -> StTrivial unit
assume val print_i16 : Int16.t -> StTrivial unit
assume val print_i32 : Int32.t -> StTrivial unit
assume val print_i64 : Int64.t -> StTrivial unit
assume val print_bool : bool -> StTrivial unit
assume val print_lmbuffer_bool (l:_) (#r:_) (#s:_) (b:lmbuffer bool r s l) : StBuf unit b
assume val print_lmbuffer_char (l:_) (#r:_) (#s:_) (b:lmbuffer char r s l) : StBuf unit b
assume val print_lmbuffer_string (l:_) (#r:_) (#s:_) (b:lmbuffer string r s l) : StBuf unit b
assume val print_lmbuffer_u8 (l:_) (#r:_) (#s:_) (b:lmbuffer UInt8.t r s l) : StBuf unit b
assume val print_lmbuffer_u16 (l:_) (#r:_) (#s:_) (b:lmbuffer UInt16.t r s l) : StBuf unit b
assume val print_lmbuffer_u32 (l:_) (#r:_) (#s:_) (b:lmbuffer UInt32.t r s l) : StBuf unit b
assume val print_lmbuffer_u64 (l:_) (#r:_) (#s:_) (b:lmbuffer UInt64.t r s l) : StBuf unit b
assume val print_lmbuffer_i8 (l:_) (#r:_) (#s:_) (b:lmbuffer Int8.t r s l) : StBuf unit b
assume val print_lmbuffer_i16 (l:_) (#r:_) (#s:_) (b:lmbuffer Int16.t r s l) : StBuf unit b
assume val print_lmbuffer_i32 (l:_) (#r:_) (#s:_) (b:lmbuffer Int32.t r s l) : StBuf unit b
assume val print_lmbuffer_i64 (l:_) (#r:_) (#s:_) (b:lmbuffer Int64.t r s l) : StBuf unit b
/// An attribute to control reduction
noextract irreducible
let __reduce__ = unit
/// Base types supported so far
noextract
type base_typ =
| Bool
| Char
| String
| U8
| U16
| U32
| U64
| I8
| I16
| I32
| I64
/// Argument types are base types and arrays thereof
/// Or polymorphic arguments specified by "%a"
noextract
type arg =
| Base of base_typ
| Array of base_typ
| Any
/// Interpreting a `base_typ` as a type
[@@__reduce__]
noextract
let base_typ_as_type (b:base_typ) : Type0 =
match b with
| Bool -> bool
| Char -> char
| String -> string
| U8 -> FStar.UInt8.t
| U16 -> FStar.UInt16.t
| U32 -> FStar.UInt32.t
| U64 -> FStar.UInt64.t
| I8 -> FStar.Int8.t
| I16 -> FStar.Int16.t
| I32 -> FStar.Int32.t
| I64 -> FStar.Int64.t
/// `fragment`: A format string is parsed into a list of fragments of
/// string literals and other arguments that need to be spliced in
/// (interpolated)
noextract
type fragment =
| Frag of string
| Interpolate of arg
noextract
let fragments = list fragment
/// `parse_format s`:
/// Parses a list of characters in a format string into a list of fragments
/// Or None, in case the format string is invalid
[@@__reduce__] | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.Printf.fst"
} | [
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "LB"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.String",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Char",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: Prims.list FStar.String.char
-> Prims.Tot (FStar.Pervasives.Native.option LowStar.Printf.fragments) | Prims.Tot | [
"total",
""
] | [] | [
"Prims.list",
"FStar.String.char",
"FStar.Pervasives.Native.Some",
"LowStar.Printf.fragments",
"Prims.Nil",
"LowStar.Printf.fragment",
"FStar.Pervasives.Native.None",
"LowStar.Printf.Any",
"LowStar.Printf.parse_format",
"Prims.Cons",
"LowStar.Printf.Base",
"LowStar.Printf.U8",
"LowStar.Printf.U16",
"LowStar.Printf.U32",
"LowStar.Printf.U64",
"FStar.Pervasives.Native.option",
"LowStar.Printf.Bool",
"LowStar.Printf.Char",
"LowStar.Printf.String",
"LowStar.Printf.I8",
"LowStar.Printf.I16",
"LowStar.Printf.I32",
"LowStar.Printf.I64",
"FStar.Char.char",
"Prims.string",
"LowStar.Printf.Frag",
"FStar.String.string_of_list",
"FStar.String.list_of_string",
"LowStar.Printf.base_typ",
"LowStar.Printf.Interpolate",
"LowStar.Printf.Array",
"LowStar.Printf.arg"
] | [
"recursion"
] | false | false | false | true | false | let rec parse_format (s: list char) : Tot (option fragments) (decreases (L.length s)) =
| let add_dir (d: arg) (ods: option fragments) =
match ods with
| None -> None
| Some ds -> Some (Interpolate d :: ds)
in
let head_buffer (ods: option fragments) =
match ods with
| Some (Interpolate (Base t) :: rest) -> Some (Interpolate (Array t) :: rest)
| _ -> None
in
let cons_frag (c: char) (ods: option fragments) =
match ods with
| Some (Frag s :: rest) -> Some (Frag (string_of_list (c :: list_of_string s)) :: rest)
| Some rest -> Some (Frag (string_of_list [c]) :: rest)
| _ -> None
in
match s with
| [] -> Some []
| ['%'] -> None
| '%' :: 'a' :: s' -> add_dir Any (parse_format s')
| '%' :: 'x' :: s' -> head_buffer (parse_format ('%' :: s'))
| '%' :: 'u' :: s' ->
(match s' with
| 'y' :: s'' -> add_dir (Base U8) (parse_format s'')
| 's' :: s'' -> add_dir (Base U16) (parse_format s'')
| 'l' :: s'' -> add_dir (Base U32) (parse_format s'')
| 'L' :: s'' -> add_dir (Base U64) (parse_format s'')
| _ -> None)
| '%' :: c :: s' ->
(match c with
| '%' -> cons_frag '%' (parse_format s')
| 'b' -> add_dir (Base Bool) (parse_format s')
| 'c' -> add_dir (Base Char) (parse_format s')
| 's' -> add_dir (Base String) (parse_format s')
| 'y' -> add_dir (Base I8) (parse_format s')
| 'i' -> add_dir (Base I16) (parse_format s')
| 'l' -> add_dir (Base I32) (parse_format s')
| 'L' -> add_dir (Base I64) (parse_format s')
| _ -> None)
| c :: s' -> cons_frag c (parse_format s') | false |
FStar.Pure.BreakVC.fst | FStar.Pure.BreakVC.mono_lem | val mono_lem () : Lemma (pure_wp_monotonic unit break_wp') | val mono_lem () : Lemma (pure_wp_monotonic unit break_wp') | let mono_lem () : Lemma (pure_wp_monotonic unit break_wp') =
assert (pure_wp_monotonic unit break_wp') by begin
norm [delta];
l_to_r [`spinoff_eq]
end | {
"file_name": "ulib/FStar.Pure.BreakVC.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 5,
"end_line": 9,
"start_col": 0,
"start_line": 5
} | module FStar.Pure.BreakVC
open FStar.Tactics.V2 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Pure.BreakVC.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pure",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pure",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit
-> FStar.Pervasives.Lemma
(ensures Prims.pure_wp_monotonic Prims.unit FStar.Pure.BreakVC.break_wp') | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.unit",
"FStar.Tactics.Effect.assert_by_tactic",
"Prims.pure_wp_monotonic",
"FStar.Pure.BreakVC.break_wp'",
"FStar.Tactics.V2.Derived.l_to_r",
"Prims.Cons",
"FStar.Tactics.NamedView.term",
"Prims.Nil",
"FStar.Stubs.Tactics.V2.Builtins.norm",
"FStar.Pervasives.norm_step",
"FStar.Pervasives.delta",
"Prims.l_True",
"Prims.squash",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let mono_lem () : Lemma (pure_wp_monotonic unit break_wp') =
| FStar.Tactics.Effect.assert_by_tactic (pure_wp_monotonic unit break_wp')
(fun _ ->
();
norm [delta];
l_to_r [`spinoff_eq]) | false |
Steel.ST.Array.Util.fst | Steel.ST.Array.Util.array_literal_inv | val array_literal_inv:
#a: Type0 ->
n: US.t ->
arr: A.array a ->
f: (i: US.t{US.v i < US.v n} -> a) ->
i: Loops.nat_at_most n ->
Seq.seq a
-> vprop | val array_literal_inv:
#a: Type0 ->
n: US.t ->
arr: A.array a ->
f: (i: US.t{US.v i < US.v n} -> a) ->
i: Loops.nat_at_most n ->
Seq.seq a
-> vprop | let array_literal_inv
(#a:Type0)
(n:US.t)
(arr:A.array a)
(f:(i:US.t{US.v i < US.v n} -> a))
(i:Loops.nat_at_most n)
: Seq.seq a -> vprop
= fun s ->
A.pts_to arr full_perm s
`star`
pure (array_literal_inv_pure n f i s) | {
"file_name": "lib/steel/Steel.ST.Array.Util.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 41,
"end_line": 54,
"start_col": 0,
"start_line": 44
} | (*
Copyright 2021 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.ST.Array.Util
module G = FStar.Ghost
module US = FStar.SizeT
module R = Steel.ST.Reference
module A = Steel.ST.Array
module Loops = Steel.ST.Loops
open Steel.FractionalPermission
open Steel.ST.Effect
open Steel.ST.Util
/// Implementation of array_literal using a for loop
let array_literal_inv_pure
(#a:Type0)
(n:US.t)
(f:(i:US.t{US.v i < US.v n} -> a))
(i:Loops.nat_at_most n)
(s:Seq.seq a)
: prop
= forall (j:nat).
(j < i /\ j < Seq.length s) ==> Seq.index s j == f (US.uint_to_t j) | {
"checked_file": "/",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"Steel.ST.Reference.fsti.checked",
"Steel.ST.Loops.fsti.checked",
"Steel.ST.Effect.fsti.checked",
"Steel.ST.Array.fsti.checked",
"Steel.FractionalPermission.fst.checked",
"prims.fst.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.ST.Array.Util.fst"
} | [
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.ST.Loops",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "Steel.ST.Reference",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "US"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "US"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": false,
"full_module": "Steel.ST.Array",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.Array",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
n: FStar.SizeT.t ->
arr: Steel.ST.Array.array a ->
f: (i: FStar.SizeT.t{FStar.SizeT.v i < FStar.SizeT.v n} -> a) ->
i: Steel.ST.Loops.nat_at_most n ->
_: FStar.Seq.Base.seq a
-> Steel.Effect.Common.vprop | Prims.Tot | [
"total"
] | [] | [
"FStar.SizeT.t",
"Steel.ST.Array.array",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.SizeT.v",
"Steel.ST.Loops.nat_at_most",
"FStar.Seq.Base.seq",
"Steel.Effect.Common.star",
"Steel.ST.Array.pts_to",
"Steel.FractionalPermission.full_perm",
"Steel.ST.Util.pure",
"Steel.ST.Array.Util.array_literal_inv_pure",
"Steel.Effect.Common.vprop"
] | [] | false | false | false | false | false | let array_literal_inv
(#a: Type0)
(n: US.t)
(arr: A.array a)
(f: (i: US.t{US.v i < US.v n} -> a))
(i: Loops.nat_at_most n)
: Seq.seq a -> vprop =
| fun s -> (A.pts_to arr full_perm s) `star` (pure (array_literal_inv_pure n f i s)) | false |
Steel.ST.Array.Util.fst | Steel.ST.Array.Util.forall_pure_inv_b | val forall_pure_inv_b:
#a: Type0 ->
n: US.t ->
p: (a -> bool) ->
s: Seq.seq a ->
squash (Seq.length s == US.v n) ->
i: US.t ->
b: bool
-> prop | val forall_pure_inv_b:
#a: Type0 ->
n: US.t ->
p: (a -> bool) ->
s: Seq.seq a ->
squash (Seq.length s == US.v n) ->
i: US.t ->
b: bool
-> prop | let forall_pure_inv_b
(#a:Type0)
(n:US.t)
(p:a -> bool)
(s:Seq.seq a)
(_:squash (Seq.length s == US.v n))
(i:US.t)
(b:bool)
: prop
= b == (i `US.lt` n && p (Seq.index s (US.v i))) | {
"file_name": "lib/steel/Steel.ST.Array.Util.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 50,
"end_line": 124,
"start_col": 0,
"start_line": 115
} | (*
Copyright 2021 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.ST.Array.Util
module G = FStar.Ghost
module US = FStar.SizeT
module R = Steel.ST.Reference
module A = Steel.ST.Array
module Loops = Steel.ST.Loops
open Steel.FractionalPermission
open Steel.ST.Effect
open Steel.ST.Util
/// Implementation of array_literal using a for loop
let array_literal_inv_pure
(#a:Type0)
(n:US.t)
(f:(i:US.t{US.v i < US.v n} -> a))
(i:Loops.nat_at_most n)
(s:Seq.seq a)
: prop
= forall (j:nat).
(j < i /\ j < Seq.length s) ==> Seq.index s j == f (US.uint_to_t j)
[@@ __reduce__]
let array_literal_inv
(#a:Type0)
(n:US.t)
(arr:A.array a)
(f:(i:US.t{US.v i < US.v n} -> a))
(i:Loops.nat_at_most n)
: Seq.seq a -> vprop
= fun s ->
A.pts_to arr full_perm s
`star`
pure (array_literal_inv_pure n f i s)
inline_for_extraction
let array_literal_loop_body
(#a:Type0)
(n:US.t)
(arr:A.array a{A.length arr == US.v n})
(f:(i:US.t{US.v i < US.v n} -> a))
: i:Loops.u32_between 0sz n ->
STT unit
(exists_ (array_literal_inv n arr f (US.v i)))
(fun _ -> exists_ (array_literal_inv n arr f (US.v i + 1)))
= fun i ->
let s = elim_exists () in
();
A.pts_to_length arr s;
elim_pure (array_literal_inv_pure n f (US.v i) s);
A.write arr i (f i);
intro_pure
(array_literal_inv_pure n f (US.v i + 1) (Seq.upd s (US.v i) (f i)));
intro_exists
(Seq.upd s (US.v i) (f i))
(array_literal_inv n arr f (US.v i + 1))
let array_literal #a n f =
let arr = A.alloc (f 0sz) n in
intro_pure
(array_literal_inv_pure n f 1 (Seq.create (US.v n) (f 0sz)));
intro_exists
(Seq.create (US.v n) (f 0sz))
(array_literal_inv n arr f 1);
Loops.for_loop
1sz
n
(fun i -> exists_ (array_literal_inv n arr f i))
(array_literal_loop_body n arr f);
let s = elim_exists () in
A.pts_to_length arr s;
elim_pure (array_literal_inv_pure n f (US.v n) s);
assert (Seq.equal s (Seq.init (US.v n) (fun i -> f (US.uint_to_t i))));
rewrite (A.pts_to arr full_perm s) _;
return arr
/// Implementation of for_all using a while loop
let forall_pure_inv
(#a:Type0)
(n:US.t)
(p:a -> bool)
(s:Seq.seq a)
(_:squash (Seq.length s == US.v n))
(i:US.t)
: prop
= i `US.lte` n /\ (forall (j:nat). j < US.v i ==> p (Seq.index s j)) | {
"checked_file": "/",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"Steel.ST.Reference.fsti.checked",
"Steel.ST.Loops.fsti.checked",
"Steel.ST.Effect.fsti.checked",
"Steel.ST.Array.fsti.checked",
"Steel.FractionalPermission.fst.checked",
"prims.fst.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.ST.Array.Util.fst"
} | [
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.ST.Loops",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "Steel.ST.Reference",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "US"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "US"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": false,
"full_module": "Steel.ST.Array",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.Array",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
n: FStar.SizeT.t ->
p: (_: a -> Prims.bool) ->
s: FStar.Seq.Base.seq a ->
_: Prims.squash (FStar.Seq.Base.length s == FStar.SizeT.v n) ->
i: FStar.SizeT.t ->
b: Prims.bool
-> Prims.prop | Prims.Tot | [
"total"
] | [] | [
"FStar.SizeT.t",
"Prims.bool",
"FStar.Seq.Base.seq",
"Prims.squash",
"Prims.eq2",
"Prims.nat",
"FStar.Seq.Base.length",
"FStar.SizeT.v",
"Prims.op_AmpAmp",
"FStar.SizeT.lt",
"FStar.Seq.Base.index",
"Prims.prop"
] | [] | false | false | false | false | true | let forall_pure_inv_b
(#a: Type0)
(n: US.t)
(p: (a -> bool))
(s: Seq.seq a)
(_: squash (Seq.length s == US.v n))
(i: US.t)
(b: bool)
: prop =
| b == (i `US.lt` n && p (Seq.index s (US.v i))) | false |
Steel.ST.Array.Util.fst | Steel.ST.Array.Util.forall_pred | val forall_pred:
#a: Type0 ->
n: US.t ->
arr: A.array a ->
p: (a -> bool) ->
r: R.ref US.t ->
perm: perm ->
s: Seq.seq a ->
squash (Seq.length s == US.v n) ->
b: bool ->
US.t
-> vprop | val forall_pred:
#a: Type0 ->
n: US.t ->
arr: A.array a ->
p: (a -> bool) ->
r: R.ref US.t ->
perm: perm ->
s: Seq.seq a ->
squash (Seq.length s == US.v n) ->
b: bool ->
US.t
-> vprop | let forall_pred
(#a:Type0)
(n:US.t)
(arr:A.array a)
(p:a -> bool)
(r:R.ref US.t)
(perm:perm)
(s:Seq.seq a)
(_:squash (Seq.length s == US.v n))
(b:bool)
: US.t -> vprop
= fun i ->
A.pts_to arr perm s
`star`
R.pts_to r full_perm i
`star`
pure (forall_pure_inv n p s () i)
`star`
pure (forall_pure_inv_b n p s () i b) | {
"file_name": "lib/steel/Steel.ST.Array.Util.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 41,
"end_line": 145,
"start_col": 0,
"start_line": 127
} | (*
Copyright 2021 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.ST.Array.Util
module G = FStar.Ghost
module US = FStar.SizeT
module R = Steel.ST.Reference
module A = Steel.ST.Array
module Loops = Steel.ST.Loops
open Steel.FractionalPermission
open Steel.ST.Effect
open Steel.ST.Util
/// Implementation of array_literal using a for loop
let array_literal_inv_pure
(#a:Type0)
(n:US.t)
(f:(i:US.t{US.v i < US.v n} -> a))
(i:Loops.nat_at_most n)
(s:Seq.seq a)
: prop
= forall (j:nat).
(j < i /\ j < Seq.length s) ==> Seq.index s j == f (US.uint_to_t j)
[@@ __reduce__]
let array_literal_inv
(#a:Type0)
(n:US.t)
(arr:A.array a)
(f:(i:US.t{US.v i < US.v n} -> a))
(i:Loops.nat_at_most n)
: Seq.seq a -> vprop
= fun s ->
A.pts_to arr full_perm s
`star`
pure (array_literal_inv_pure n f i s)
inline_for_extraction
let array_literal_loop_body
(#a:Type0)
(n:US.t)
(arr:A.array a{A.length arr == US.v n})
(f:(i:US.t{US.v i < US.v n} -> a))
: i:Loops.u32_between 0sz n ->
STT unit
(exists_ (array_literal_inv n arr f (US.v i)))
(fun _ -> exists_ (array_literal_inv n arr f (US.v i + 1)))
= fun i ->
let s = elim_exists () in
();
A.pts_to_length arr s;
elim_pure (array_literal_inv_pure n f (US.v i) s);
A.write arr i (f i);
intro_pure
(array_literal_inv_pure n f (US.v i + 1) (Seq.upd s (US.v i) (f i)));
intro_exists
(Seq.upd s (US.v i) (f i))
(array_literal_inv n arr f (US.v i + 1))
let array_literal #a n f =
let arr = A.alloc (f 0sz) n in
intro_pure
(array_literal_inv_pure n f 1 (Seq.create (US.v n) (f 0sz)));
intro_exists
(Seq.create (US.v n) (f 0sz))
(array_literal_inv n arr f 1);
Loops.for_loop
1sz
n
(fun i -> exists_ (array_literal_inv n arr f i))
(array_literal_loop_body n arr f);
let s = elim_exists () in
A.pts_to_length arr s;
elim_pure (array_literal_inv_pure n f (US.v n) s);
assert (Seq.equal s (Seq.init (US.v n) (fun i -> f (US.uint_to_t i))));
rewrite (A.pts_to arr full_perm s) _;
return arr
/// Implementation of for_all using a while loop
let forall_pure_inv
(#a:Type0)
(n:US.t)
(p:a -> bool)
(s:Seq.seq a)
(_:squash (Seq.length s == US.v n))
(i:US.t)
: prop
= i `US.lte` n /\ (forall (j:nat). j < US.v i ==> p (Seq.index s j))
let forall_pure_inv_b
(#a:Type0)
(n:US.t)
(p:a -> bool)
(s:Seq.seq a)
(_:squash (Seq.length s == US.v n))
(i:US.t)
(b:bool)
: prop
= b == (i `US.lt` n && p (Seq.index s (US.v i))) | {
"checked_file": "/",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"Steel.ST.Reference.fsti.checked",
"Steel.ST.Loops.fsti.checked",
"Steel.ST.Effect.fsti.checked",
"Steel.ST.Array.fsti.checked",
"Steel.FractionalPermission.fst.checked",
"prims.fst.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.ST.Array.Util.fst"
} | [
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.ST.Loops",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "Steel.ST.Reference",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "US"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "US"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": false,
"full_module": "Steel.ST.Array",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.Array",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
n: FStar.SizeT.t ->
arr: Steel.ST.Array.array a ->
p: (_: a -> Prims.bool) ->
r: Steel.ST.Reference.ref FStar.SizeT.t ->
perm: Steel.FractionalPermission.perm ->
s: FStar.Seq.Base.seq a ->
_: Prims.squash (FStar.Seq.Base.length s == FStar.SizeT.v n) ->
b: Prims.bool ->
_: FStar.SizeT.t
-> Steel.Effect.Common.vprop | Prims.Tot | [
"total"
] | [] | [
"FStar.SizeT.t",
"Steel.ST.Array.array",
"Prims.bool",
"Steel.ST.Reference.ref",
"Steel.FractionalPermission.perm",
"FStar.Seq.Base.seq",
"Prims.squash",
"Prims.eq2",
"Prims.nat",
"FStar.Seq.Base.length",
"FStar.SizeT.v",
"Steel.Effect.Common.star",
"Steel.ST.Array.pts_to",
"Steel.ST.Reference.pts_to",
"Steel.FractionalPermission.full_perm",
"Steel.ST.Util.pure",
"Steel.ST.Array.Util.forall_pure_inv",
"Steel.ST.Array.Util.forall_pure_inv_b",
"Steel.Effect.Common.vprop"
] | [] | false | false | false | false | false | let forall_pred
(#a: Type0)
(n: US.t)
(arr: A.array a)
(p: (a -> bool))
(r: R.ref US.t)
(perm: perm)
(s: Seq.seq a)
(_: squash (Seq.length s == US.v n))
(b: bool)
: US.t -> vprop =
| fun i ->
(((A.pts_to arr perm s) `star` (R.pts_to r full_perm i))
`star`
(pure (forall_pure_inv n p s () i)))
`star`
(pure (forall_pure_inv_b n p s () i b)) | false |
Steel.ST.Array.Util.fst | Steel.ST.Array.Util.forall2_pure_inv_b | val forall2_pure_inv_b:
#a: Type0 ->
#b: Type0 ->
n: US.t ->
p: (a -> b -> bool) ->
s0: Seq.seq a ->
s1: Seq.seq b ->
squash (Seq.length s0 == US.v n /\ Seq.length s0 == Seq.length s1) ->
i: US.t ->
g: bool
-> prop | val forall2_pure_inv_b:
#a: Type0 ->
#b: Type0 ->
n: US.t ->
p: (a -> b -> bool) ->
s0: Seq.seq a ->
s1: Seq.seq b ->
squash (Seq.length s0 == US.v n /\ Seq.length s0 == Seq.length s1) ->
i: US.t ->
g: bool
-> prop | let forall2_pure_inv_b
(#a #b:Type0)
(n:US.t)
(p:a -> b -> bool)
(s0:Seq.seq a)
(s1:Seq.seq b)
(_:squash (Seq.length s0 == US.v n /\ Seq.length s0 == Seq.length s1))
(i:US.t)
(g:bool)
: prop
= g == (i `US.lt` n && p (Seq.index s0 (US.v i)) (Seq.index s1 (US.v i))) | {
"file_name": "lib/steel/Steel.ST.Array.Util.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 75,
"end_line": 289,
"start_col": 0,
"start_line": 279
} | (*
Copyright 2021 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.ST.Array.Util
module G = FStar.Ghost
module US = FStar.SizeT
module R = Steel.ST.Reference
module A = Steel.ST.Array
module Loops = Steel.ST.Loops
open Steel.FractionalPermission
open Steel.ST.Effect
open Steel.ST.Util
/// Implementation of array_literal using a for loop
let array_literal_inv_pure
(#a:Type0)
(n:US.t)
(f:(i:US.t{US.v i < US.v n} -> a))
(i:Loops.nat_at_most n)
(s:Seq.seq a)
: prop
= forall (j:nat).
(j < i /\ j < Seq.length s) ==> Seq.index s j == f (US.uint_to_t j)
[@@ __reduce__]
let array_literal_inv
(#a:Type0)
(n:US.t)
(arr:A.array a)
(f:(i:US.t{US.v i < US.v n} -> a))
(i:Loops.nat_at_most n)
: Seq.seq a -> vprop
= fun s ->
A.pts_to arr full_perm s
`star`
pure (array_literal_inv_pure n f i s)
inline_for_extraction
let array_literal_loop_body
(#a:Type0)
(n:US.t)
(arr:A.array a{A.length arr == US.v n})
(f:(i:US.t{US.v i < US.v n} -> a))
: i:Loops.u32_between 0sz n ->
STT unit
(exists_ (array_literal_inv n arr f (US.v i)))
(fun _ -> exists_ (array_literal_inv n arr f (US.v i + 1)))
= fun i ->
let s = elim_exists () in
();
A.pts_to_length arr s;
elim_pure (array_literal_inv_pure n f (US.v i) s);
A.write arr i (f i);
intro_pure
(array_literal_inv_pure n f (US.v i + 1) (Seq.upd s (US.v i) (f i)));
intro_exists
(Seq.upd s (US.v i) (f i))
(array_literal_inv n arr f (US.v i + 1))
let array_literal #a n f =
let arr = A.alloc (f 0sz) n in
intro_pure
(array_literal_inv_pure n f 1 (Seq.create (US.v n) (f 0sz)));
intro_exists
(Seq.create (US.v n) (f 0sz))
(array_literal_inv n arr f 1);
Loops.for_loop
1sz
n
(fun i -> exists_ (array_literal_inv n arr f i))
(array_literal_loop_body n arr f);
let s = elim_exists () in
A.pts_to_length arr s;
elim_pure (array_literal_inv_pure n f (US.v n) s);
assert (Seq.equal s (Seq.init (US.v n) (fun i -> f (US.uint_to_t i))));
rewrite (A.pts_to arr full_perm s) _;
return arr
/// Implementation of for_all using a while loop
let forall_pure_inv
(#a:Type0)
(n:US.t)
(p:a -> bool)
(s:Seq.seq a)
(_:squash (Seq.length s == US.v n))
(i:US.t)
: prop
= i `US.lte` n /\ (forall (j:nat). j < US.v i ==> p (Seq.index s j))
let forall_pure_inv_b
(#a:Type0)
(n:US.t)
(p:a -> bool)
(s:Seq.seq a)
(_:squash (Seq.length s == US.v n))
(i:US.t)
(b:bool)
: prop
= b == (i `US.lt` n && p (Seq.index s (US.v i)))
[@@ __reduce__]
let forall_pred
(#a:Type0)
(n:US.t)
(arr:A.array a)
(p:a -> bool)
(r:R.ref US.t)
(perm:perm)
(s:Seq.seq a)
(_:squash (Seq.length s == US.v n))
(b:bool)
: US.t -> vprop
= fun i ->
A.pts_to arr perm s
`star`
R.pts_to r full_perm i
`star`
pure (forall_pure_inv n p s () i)
`star`
pure (forall_pure_inv_b n p s () i b)
[@@ __reduce__]
let forall_inv
(#a:Type0)
(n:US.t)
(arr:A.array a)
(p:a -> bool)
(r:R.ref US.t)
(perm:perm)
(s:Seq.seq a)
(_:squash (Seq.length s == US.v n))
: bool -> vprop
= fun b -> exists_ (forall_pred n arr p r perm s () b)
inline_for_extraction
let forall_cond
(#a:Type0)
(n:US.t)
(arr:A.array a)
(p:a -> bool)
(r:R.ref US.t)
(perm:perm)
(s:G.erased (Seq.seq a))
(_:squash (Seq.length s == US.v n))
: unit ->
STT bool
(exists_ (forall_inv n arr p r perm s ()))
(forall_inv n arr p r perm s ())
= fun _ ->
let _ = elim_exists () in
let _ = elim_exists () in
elim_pure _;
elim_pure _;
let i = R.read r in
let b = i = n in
let res =
if b then return false
else let elt = A.read arr i in
return (p elt) in
intro_pure (forall_pure_inv n p s () i);
intro_pure (forall_pure_inv_b n p s () i res);
intro_exists i (forall_pred n arr p r perm s () res);
return res
inline_for_extraction
let forall_body
(#a:Type0)
(n:US.t)
(arr:A.array a)
(p:a -> bool)
(r:R.ref US.t)
(perm:perm)
(s:G.erased (Seq.seq a))
(_:squash (Seq.length s == US.v n))
: unit ->
STT unit
(forall_inv n arr p r perm s () true)
(fun _ -> exists_ (forall_inv n arr p r perm s ()))
= fun _ ->
let _ = elim_exists () in
elim_pure _;
elim_pure _;
//atomic increment?
let i = R.read r in
R.write r (US.add i 1sz);
intro_pure (forall_pure_inv n p s () (US.add i 1sz));
intro_pure (forall_pure_inv_b n p s ()
(US.add i 1sz)
((US.add i 1sz) `US.lt` n && p (Seq.index s (US.v (US.add i 1sz)))));
intro_exists
(US.add i 1sz)
(forall_pred n arr p r perm s ()
((US.add i 1sz) `US.lt` n && p (Seq.index s (US.v (US.add i 1sz)))));
intro_exists
((US.add i 1sz) `US.lt` n && p (Seq.index s (US.v (US.add i 1sz))))
(forall_inv n arr p r perm s ())
let for_all #a #perm #s n arr p =
A.pts_to_length arr s;
let b = n = 0sz in
if b then return true
else begin
//This could be stack allocated
let r = R.alloc 0sz in
intro_pure (forall_pure_inv n p s () 0sz);
intro_pure
(forall_pure_inv_b n p s () 0sz
(0sz `US.lt` n && p (Seq.index s (US.v 0sz))));
intro_exists 0sz
(forall_pred n arr p r perm s ()
(0sz `US.lt` n && p (Seq.index s (US.v 0sz))));
intro_exists
(0sz `US.lt` n && p (Seq.index s (US.v 0sz)))
(forall_inv n arr p r perm s ());
Loops.while_loop
(forall_inv n arr p r perm s ())
(forall_cond n arr p r perm s ())
(forall_body n arr p r perm s ());
let _ = elim_exists () in
let _ = elim_pure _ in
let _ = elim_pure _ in
let i = R.read r in
//This free would go away if we had stack allocations
R.free r;
return (i = n)
end
/// Implementation of for_all2 using a while loop
let forall2_pure_inv
(#a #b:Type0)
(n:US.t)
(p:a -> b -> bool)
(s0:Seq.seq a)
(s1:Seq.seq b)
(_:squash (Seq.length s0 == US.v n /\ Seq.length s0 == Seq.length s1))
(i:US.t)
: prop
= i `US.lte` n /\ (forall (j:nat). j < US.v i ==> p (Seq.index s0 j) (Seq.index s1 j)) | {
"checked_file": "/",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"Steel.ST.Reference.fsti.checked",
"Steel.ST.Loops.fsti.checked",
"Steel.ST.Effect.fsti.checked",
"Steel.ST.Array.fsti.checked",
"Steel.FractionalPermission.fst.checked",
"prims.fst.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.ST.Array.Util.fst"
} | [
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.ST.Loops",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "Steel.ST.Reference",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "US"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "US"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": false,
"full_module": "Steel.ST.Array",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.Array",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
n: FStar.SizeT.t ->
p: (_: a -> _: b -> Prims.bool) ->
s0: FStar.Seq.Base.seq a ->
s1: FStar.Seq.Base.seq b ->
_:
Prims.squash (FStar.Seq.Base.length s0 == FStar.SizeT.v n /\
FStar.Seq.Base.length s0 == FStar.Seq.Base.length s1) ->
i: FStar.SizeT.t ->
g: Prims.bool
-> Prims.prop | Prims.Tot | [
"total"
] | [] | [
"FStar.SizeT.t",
"Prims.bool",
"FStar.Seq.Base.seq",
"Prims.squash",
"Prims.l_and",
"Prims.eq2",
"Prims.nat",
"FStar.Seq.Base.length",
"FStar.SizeT.v",
"Prims.op_AmpAmp",
"FStar.SizeT.lt",
"FStar.Seq.Base.index",
"Prims.prop"
] | [] | false | false | false | false | true | let forall2_pure_inv_b
(#a: Type0)
(#b: Type0)
(n: US.t)
(p: (a -> b -> bool))
(s0: Seq.seq a)
(s1: Seq.seq b)
(_: squash (Seq.length s0 == US.v n /\ Seq.length s0 == Seq.length s1))
(i: US.t)
(g: bool)
: prop =
| g == (i `US.lt` n && p (Seq.index s0 (US.v i)) (Seq.index s1 (US.v i))) | false |
Steel.ST.Array.Util.fst | Steel.ST.Array.Util.forall_pure_inv | val forall_pure_inv:
#a: Type0 ->
n: US.t ->
p: (a -> bool) ->
s: Seq.seq a ->
squash (Seq.length s == US.v n) ->
i: US.t
-> prop | val forall_pure_inv:
#a: Type0 ->
n: US.t ->
p: (a -> bool) ->
s: Seq.seq a ->
squash (Seq.length s == US.v n) ->
i: US.t
-> prop | let forall_pure_inv
(#a:Type0)
(n:US.t)
(p:a -> bool)
(s:Seq.seq a)
(_:squash (Seq.length s == US.v n))
(i:US.t)
: prop
= i `US.lte` n /\ (forall (j:nat). j < US.v i ==> p (Seq.index s j)) | {
"file_name": "lib/steel/Steel.ST.Array.Util.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 70,
"end_line": 113,
"start_col": 0,
"start_line": 105
} | (*
Copyright 2021 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.ST.Array.Util
module G = FStar.Ghost
module US = FStar.SizeT
module R = Steel.ST.Reference
module A = Steel.ST.Array
module Loops = Steel.ST.Loops
open Steel.FractionalPermission
open Steel.ST.Effect
open Steel.ST.Util
/// Implementation of array_literal using a for loop
let array_literal_inv_pure
(#a:Type0)
(n:US.t)
(f:(i:US.t{US.v i < US.v n} -> a))
(i:Loops.nat_at_most n)
(s:Seq.seq a)
: prop
= forall (j:nat).
(j < i /\ j < Seq.length s) ==> Seq.index s j == f (US.uint_to_t j)
[@@ __reduce__]
let array_literal_inv
(#a:Type0)
(n:US.t)
(arr:A.array a)
(f:(i:US.t{US.v i < US.v n} -> a))
(i:Loops.nat_at_most n)
: Seq.seq a -> vprop
= fun s ->
A.pts_to arr full_perm s
`star`
pure (array_literal_inv_pure n f i s)
inline_for_extraction
let array_literal_loop_body
(#a:Type0)
(n:US.t)
(arr:A.array a{A.length arr == US.v n})
(f:(i:US.t{US.v i < US.v n} -> a))
: i:Loops.u32_between 0sz n ->
STT unit
(exists_ (array_literal_inv n arr f (US.v i)))
(fun _ -> exists_ (array_literal_inv n arr f (US.v i + 1)))
= fun i ->
let s = elim_exists () in
();
A.pts_to_length arr s;
elim_pure (array_literal_inv_pure n f (US.v i) s);
A.write arr i (f i);
intro_pure
(array_literal_inv_pure n f (US.v i + 1) (Seq.upd s (US.v i) (f i)));
intro_exists
(Seq.upd s (US.v i) (f i))
(array_literal_inv n arr f (US.v i + 1))
let array_literal #a n f =
let arr = A.alloc (f 0sz) n in
intro_pure
(array_literal_inv_pure n f 1 (Seq.create (US.v n) (f 0sz)));
intro_exists
(Seq.create (US.v n) (f 0sz))
(array_literal_inv n arr f 1);
Loops.for_loop
1sz
n
(fun i -> exists_ (array_literal_inv n arr f i))
(array_literal_loop_body n arr f);
let s = elim_exists () in
A.pts_to_length arr s;
elim_pure (array_literal_inv_pure n f (US.v n) s);
assert (Seq.equal s (Seq.init (US.v n) (fun i -> f (US.uint_to_t i))));
rewrite (A.pts_to arr full_perm s) _;
return arr
/// Implementation of for_all using a while loop | {
"checked_file": "/",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"Steel.ST.Reference.fsti.checked",
"Steel.ST.Loops.fsti.checked",
"Steel.ST.Effect.fsti.checked",
"Steel.ST.Array.fsti.checked",
"Steel.FractionalPermission.fst.checked",
"prims.fst.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.ST.Array.Util.fst"
} | [
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.ST.Loops",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "Steel.ST.Reference",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "US"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "US"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": false,
"full_module": "Steel.ST.Array",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.Array",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
n: FStar.SizeT.t ->
p: (_: a -> Prims.bool) ->
s: FStar.Seq.Base.seq a ->
_: Prims.squash (FStar.Seq.Base.length s == FStar.SizeT.v n) ->
i: FStar.SizeT.t
-> Prims.prop | Prims.Tot | [
"total"
] | [] | [
"FStar.SizeT.t",
"Prims.bool",
"FStar.Seq.Base.seq",
"Prims.squash",
"Prims.eq2",
"Prims.nat",
"FStar.Seq.Base.length",
"FStar.SizeT.v",
"Prims.l_and",
"Prims.b2t",
"FStar.SizeT.lte",
"Prims.l_Forall",
"Prims.l_imp",
"Prims.op_LessThan",
"FStar.Seq.Base.index",
"Prims.prop"
] | [] | false | false | false | false | true | let forall_pure_inv
(#a: Type0)
(n: US.t)
(p: (a -> bool))
(s: Seq.seq a)
(_: squash (Seq.length s == US.v n))
(i: US.t)
: prop =
| i `US.lte` n /\ (forall (j: nat). j < US.v i ==> p (Seq.index s j)) | false |
Steel.ST.Array.Util.fst | Steel.ST.Array.Util.forall2_inv | val forall2_inv:
#a: Type0 ->
#b: Type0 ->
n: US.t ->
a0: A.array a ->
a1: A.array b ->
p: (a -> b -> bool) ->
r: R.ref US.t ->
p0: perm ->
p1: perm ->
s0: Seq.seq a ->
s1: Seq.seq b ->
squash (Seq.length s0 == US.v n /\ Seq.length s0 == Seq.length s1) ->
bool
-> vprop | val forall2_inv:
#a: Type0 ->
#b: Type0 ->
n: US.t ->
a0: A.array a ->
a1: A.array b ->
p: (a -> b -> bool) ->
r: R.ref US.t ->
p0: perm ->
p1: perm ->
s0: Seq.seq a ->
s1: Seq.seq b ->
squash (Seq.length s0 == US.v n /\ Seq.length s0 == Seq.length s1) ->
bool
-> vprop | let forall2_inv
(#a #b:Type0)
(n:US.t)
(a0:A.array a)
(a1:A.array b)
(p:a -> b -> bool)
(r:R.ref US.t)
(p0 p1:perm)
(s0:Seq.seq a)
(s1:Seq.seq b)
(_:squash (Seq.length s0 == US.v n /\ Seq.length s0 == Seq.length s1))
: bool -> vprop
= fun g -> exists_ (forall2_pred n a0 a1 p r p0 p1 s0 s1 () g) | {
"file_name": "lib/steel/Steel.ST.Array.Util.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 64,
"end_line": 329,
"start_col": 0,
"start_line": 317
} | (*
Copyright 2021 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.ST.Array.Util
module G = FStar.Ghost
module US = FStar.SizeT
module R = Steel.ST.Reference
module A = Steel.ST.Array
module Loops = Steel.ST.Loops
open Steel.FractionalPermission
open Steel.ST.Effect
open Steel.ST.Util
/// Implementation of array_literal using a for loop
let array_literal_inv_pure
(#a:Type0)
(n:US.t)
(f:(i:US.t{US.v i < US.v n} -> a))
(i:Loops.nat_at_most n)
(s:Seq.seq a)
: prop
= forall (j:nat).
(j < i /\ j < Seq.length s) ==> Seq.index s j == f (US.uint_to_t j)
[@@ __reduce__]
let array_literal_inv
(#a:Type0)
(n:US.t)
(arr:A.array a)
(f:(i:US.t{US.v i < US.v n} -> a))
(i:Loops.nat_at_most n)
: Seq.seq a -> vprop
= fun s ->
A.pts_to arr full_perm s
`star`
pure (array_literal_inv_pure n f i s)
inline_for_extraction
let array_literal_loop_body
(#a:Type0)
(n:US.t)
(arr:A.array a{A.length arr == US.v n})
(f:(i:US.t{US.v i < US.v n} -> a))
: i:Loops.u32_between 0sz n ->
STT unit
(exists_ (array_literal_inv n arr f (US.v i)))
(fun _ -> exists_ (array_literal_inv n arr f (US.v i + 1)))
= fun i ->
let s = elim_exists () in
();
A.pts_to_length arr s;
elim_pure (array_literal_inv_pure n f (US.v i) s);
A.write arr i (f i);
intro_pure
(array_literal_inv_pure n f (US.v i + 1) (Seq.upd s (US.v i) (f i)));
intro_exists
(Seq.upd s (US.v i) (f i))
(array_literal_inv n arr f (US.v i + 1))
let array_literal #a n f =
let arr = A.alloc (f 0sz) n in
intro_pure
(array_literal_inv_pure n f 1 (Seq.create (US.v n) (f 0sz)));
intro_exists
(Seq.create (US.v n) (f 0sz))
(array_literal_inv n arr f 1);
Loops.for_loop
1sz
n
(fun i -> exists_ (array_literal_inv n arr f i))
(array_literal_loop_body n arr f);
let s = elim_exists () in
A.pts_to_length arr s;
elim_pure (array_literal_inv_pure n f (US.v n) s);
assert (Seq.equal s (Seq.init (US.v n) (fun i -> f (US.uint_to_t i))));
rewrite (A.pts_to arr full_perm s) _;
return arr
/// Implementation of for_all using a while loop
let forall_pure_inv
(#a:Type0)
(n:US.t)
(p:a -> bool)
(s:Seq.seq a)
(_:squash (Seq.length s == US.v n))
(i:US.t)
: prop
= i `US.lte` n /\ (forall (j:nat). j < US.v i ==> p (Seq.index s j))
let forall_pure_inv_b
(#a:Type0)
(n:US.t)
(p:a -> bool)
(s:Seq.seq a)
(_:squash (Seq.length s == US.v n))
(i:US.t)
(b:bool)
: prop
= b == (i `US.lt` n && p (Seq.index s (US.v i)))
[@@ __reduce__]
let forall_pred
(#a:Type0)
(n:US.t)
(arr:A.array a)
(p:a -> bool)
(r:R.ref US.t)
(perm:perm)
(s:Seq.seq a)
(_:squash (Seq.length s == US.v n))
(b:bool)
: US.t -> vprop
= fun i ->
A.pts_to arr perm s
`star`
R.pts_to r full_perm i
`star`
pure (forall_pure_inv n p s () i)
`star`
pure (forall_pure_inv_b n p s () i b)
[@@ __reduce__]
let forall_inv
(#a:Type0)
(n:US.t)
(arr:A.array a)
(p:a -> bool)
(r:R.ref US.t)
(perm:perm)
(s:Seq.seq a)
(_:squash (Seq.length s == US.v n))
: bool -> vprop
= fun b -> exists_ (forall_pred n arr p r perm s () b)
inline_for_extraction
let forall_cond
(#a:Type0)
(n:US.t)
(arr:A.array a)
(p:a -> bool)
(r:R.ref US.t)
(perm:perm)
(s:G.erased (Seq.seq a))
(_:squash (Seq.length s == US.v n))
: unit ->
STT bool
(exists_ (forall_inv n arr p r perm s ()))
(forall_inv n arr p r perm s ())
= fun _ ->
let _ = elim_exists () in
let _ = elim_exists () in
elim_pure _;
elim_pure _;
let i = R.read r in
let b = i = n in
let res =
if b then return false
else let elt = A.read arr i in
return (p elt) in
intro_pure (forall_pure_inv n p s () i);
intro_pure (forall_pure_inv_b n p s () i res);
intro_exists i (forall_pred n arr p r perm s () res);
return res
inline_for_extraction
let forall_body
(#a:Type0)
(n:US.t)
(arr:A.array a)
(p:a -> bool)
(r:R.ref US.t)
(perm:perm)
(s:G.erased (Seq.seq a))
(_:squash (Seq.length s == US.v n))
: unit ->
STT unit
(forall_inv n arr p r perm s () true)
(fun _ -> exists_ (forall_inv n arr p r perm s ()))
= fun _ ->
let _ = elim_exists () in
elim_pure _;
elim_pure _;
//atomic increment?
let i = R.read r in
R.write r (US.add i 1sz);
intro_pure (forall_pure_inv n p s () (US.add i 1sz));
intro_pure (forall_pure_inv_b n p s ()
(US.add i 1sz)
((US.add i 1sz) `US.lt` n && p (Seq.index s (US.v (US.add i 1sz)))));
intro_exists
(US.add i 1sz)
(forall_pred n arr p r perm s ()
((US.add i 1sz) `US.lt` n && p (Seq.index s (US.v (US.add i 1sz)))));
intro_exists
((US.add i 1sz) `US.lt` n && p (Seq.index s (US.v (US.add i 1sz))))
(forall_inv n arr p r perm s ())
let for_all #a #perm #s n arr p =
A.pts_to_length arr s;
let b = n = 0sz in
if b then return true
else begin
//This could be stack allocated
let r = R.alloc 0sz in
intro_pure (forall_pure_inv n p s () 0sz);
intro_pure
(forall_pure_inv_b n p s () 0sz
(0sz `US.lt` n && p (Seq.index s (US.v 0sz))));
intro_exists 0sz
(forall_pred n arr p r perm s ()
(0sz `US.lt` n && p (Seq.index s (US.v 0sz))));
intro_exists
(0sz `US.lt` n && p (Seq.index s (US.v 0sz)))
(forall_inv n arr p r perm s ());
Loops.while_loop
(forall_inv n arr p r perm s ())
(forall_cond n arr p r perm s ())
(forall_body n arr p r perm s ());
let _ = elim_exists () in
let _ = elim_pure _ in
let _ = elim_pure _ in
let i = R.read r in
//This free would go away if we had stack allocations
R.free r;
return (i = n)
end
/// Implementation of for_all2 using a while loop
let forall2_pure_inv
(#a #b:Type0)
(n:US.t)
(p:a -> b -> bool)
(s0:Seq.seq a)
(s1:Seq.seq b)
(_:squash (Seq.length s0 == US.v n /\ Seq.length s0 == Seq.length s1))
(i:US.t)
: prop
= i `US.lte` n /\ (forall (j:nat). j < US.v i ==> p (Seq.index s0 j) (Seq.index s1 j))
let forall2_pure_inv_b
(#a #b:Type0)
(n:US.t)
(p:a -> b -> bool)
(s0:Seq.seq a)
(s1:Seq.seq b)
(_:squash (Seq.length s0 == US.v n /\ Seq.length s0 == Seq.length s1))
(i:US.t)
(g:bool)
: prop
= g == (i `US.lt` n && p (Seq.index s0 (US.v i)) (Seq.index s1 (US.v i)))
[@@ __reduce__]
let forall2_pred
(#a #b:Type0)
(n:US.t)
(a0:A.array a)
(a1:A.array b)
(p:a -> b -> bool)
(r:R.ref US.t)
(p0 p1:perm)
(s0:Seq.seq a)
(s1:Seq.seq b)
(_:squash (Seq.length s0 == US.v n /\ Seq.length s0 == Seq.length s1))
(g:bool)
: US.t -> vprop
= fun i ->
A.pts_to a0 p0 s0
`star`
A.pts_to a1 p1 s1
`star`
R.pts_to r full_perm i
`star`
pure (forall2_pure_inv n p s0 s1 () i)
`star`
pure (forall2_pure_inv_b n p s0 s1 () i g) | {
"checked_file": "/",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"Steel.ST.Reference.fsti.checked",
"Steel.ST.Loops.fsti.checked",
"Steel.ST.Effect.fsti.checked",
"Steel.ST.Array.fsti.checked",
"Steel.FractionalPermission.fst.checked",
"prims.fst.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.ST.Array.Util.fst"
} | [
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.ST.Loops",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "Steel.ST.Reference",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "US"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "US"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": false,
"full_module": "Steel.ST.Array",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.Array",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
n: FStar.SizeT.t ->
a0: Steel.ST.Array.array a ->
a1: Steel.ST.Array.array b ->
p: (_: a -> _: b -> Prims.bool) ->
r: Steel.ST.Reference.ref FStar.SizeT.t ->
p0: Steel.FractionalPermission.perm ->
p1: Steel.FractionalPermission.perm ->
s0: FStar.Seq.Base.seq a ->
s1: FStar.Seq.Base.seq b ->
_:
Prims.squash (FStar.Seq.Base.length s0 == FStar.SizeT.v n /\
FStar.Seq.Base.length s0 == FStar.Seq.Base.length s1) ->
_: Prims.bool
-> Steel.Effect.Common.vprop | Prims.Tot | [
"total"
] | [] | [
"FStar.SizeT.t",
"Steel.ST.Array.array",
"Prims.bool",
"Steel.ST.Reference.ref",
"Steel.FractionalPermission.perm",
"FStar.Seq.Base.seq",
"Prims.squash",
"Prims.l_and",
"Prims.eq2",
"Prims.nat",
"FStar.Seq.Base.length",
"FStar.SizeT.v",
"Steel.ST.Util.exists_",
"Steel.ST.Array.Util.forall2_pred",
"Steel.Effect.Common.vprop"
] | [] | false | false | false | false | false | let forall2_inv
(#a: Type0)
(#b: Type0)
(n: US.t)
(a0: A.array a)
(a1: A.array b)
(p: (a -> b -> bool))
(r: R.ref US.t)
(p0: perm)
(p1: perm)
(s0: Seq.seq a)
(s1: Seq.seq b)
(_: squash (Seq.length s0 == US.v n /\ Seq.length s0 == Seq.length s1))
: bool -> vprop =
| fun g -> exists_ (forall2_pred n a0 a1 p r p0 p1 s0 s1 () g) | false |
Steel.ST.Array.Util.fst | Steel.ST.Array.Util.forall2_pure_inv | val forall2_pure_inv:
#a: Type0 ->
#b: Type0 ->
n: US.t ->
p: (a -> b -> bool) ->
s0: Seq.seq a ->
s1: Seq.seq b ->
squash (Seq.length s0 == US.v n /\ Seq.length s0 == Seq.length s1) ->
i: US.t
-> prop | val forall2_pure_inv:
#a: Type0 ->
#b: Type0 ->
n: US.t ->
p: (a -> b -> bool) ->
s0: Seq.seq a ->
s1: Seq.seq b ->
squash (Seq.length s0 == US.v n /\ Seq.length s0 == Seq.length s1) ->
i: US.t
-> prop | let forall2_pure_inv
(#a #b:Type0)
(n:US.t)
(p:a -> b -> bool)
(s0:Seq.seq a)
(s1:Seq.seq b)
(_:squash (Seq.length s0 == US.v n /\ Seq.length s0 == Seq.length s1))
(i:US.t)
: prop
= i `US.lte` n /\ (forall (j:nat). j < US.v i ==> p (Seq.index s0 j) (Seq.index s1 j)) | {
"file_name": "lib/steel/Steel.ST.Array.Util.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 88,
"end_line": 277,
"start_col": 0,
"start_line": 268
} | (*
Copyright 2021 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.ST.Array.Util
module G = FStar.Ghost
module US = FStar.SizeT
module R = Steel.ST.Reference
module A = Steel.ST.Array
module Loops = Steel.ST.Loops
open Steel.FractionalPermission
open Steel.ST.Effect
open Steel.ST.Util
/// Implementation of array_literal using a for loop
let array_literal_inv_pure
(#a:Type0)
(n:US.t)
(f:(i:US.t{US.v i < US.v n} -> a))
(i:Loops.nat_at_most n)
(s:Seq.seq a)
: prop
= forall (j:nat).
(j < i /\ j < Seq.length s) ==> Seq.index s j == f (US.uint_to_t j)
[@@ __reduce__]
let array_literal_inv
(#a:Type0)
(n:US.t)
(arr:A.array a)
(f:(i:US.t{US.v i < US.v n} -> a))
(i:Loops.nat_at_most n)
: Seq.seq a -> vprop
= fun s ->
A.pts_to arr full_perm s
`star`
pure (array_literal_inv_pure n f i s)
inline_for_extraction
let array_literal_loop_body
(#a:Type0)
(n:US.t)
(arr:A.array a{A.length arr == US.v n})
(f:(i:US.t{US.v i < US.v n} -> a))
: i:Loops.u32_between 0sz n ->
STT unit
(exists_ (array_literal_inv n arr f (US.v i)))
(fun _ -> exists_ (array_literal_inv n arr f (US.v i + 1)))
= fun i ->
let s = elim_exists () in
();
A.pts_to_length arr s;
elim_pure (array_literal_inv_pure n f (US.v i) s);
A.write arr i (f i);
intro_pure
(array_literal_inv_pure n f (US.v i + 1) (Seq.upd s (US.v i) (f i)));
intro_exists
(Seq.upd s (US.v i) (f i))
(array_literal_inv n arr f (US.v i + 1))
let array_literal #a n f =
let arr = A.alloc (f 0sz) n in
intro_pure
(array_literal_inv_pure n f 1 (Seq.create (US.v n) (f 0sz)));
intro_exists
(Seq.create (US.v n) (f 0sz))
(array_literal_inv n arr f 1);
Loops.for_loop
1sz
n
(fun i -> exists_ (array_literal_inv n arr f i))
(array_literal_loop_body n arr f);
let s = elim_exists () in
A.pts_to_length arr s;
elim_pure (array_literal_inv_pure n f (US.v n) s);
assert (Seq.equal s (Seq.init (US.v n) (fun i -> f (US.uint_to_t i))));
rewrite (A.pts_to arr full_perm s) _;
return arr
/// Implementation of for_all using a while loop
let forall_pure_inv
(#a:Type0)
(n:US.t)
(p:a -> bool)
(s:Seq.seq a)
(_:squash (Seq.length s == US.v n))
(i:US.t)
: prop
= i `US.lte` n /\ (forall (j:nat). j < US.v i ==> p (Seq.index s j))
let forall_pure_inv_b
(#a:Type0)
(n:US.t)
(p:a -> bool)
(s:Seq.seq a)
(_:squash (Seq.length s == US.v n))
(i:US.t)
(b:bool)
: prop
= b == (i `US.lt` n && p (Seq.index s (US.v i)))
[@@ __reduce__]
let forall_pred
(#a:Type0)
(n:US.t)
(arr:A.array a)
(p:a -> bool)
(r:R.ref US.t)
(perm:perm)
(s:Seq.seq a)
(_:squash (Seq.length s == US.v n))
(b:bool)
: US.t -> vprop
= fun i ->
A.pts_to arr perm s
`star`
R.pts_to r full_perm i
`star`
pure (forall_pure_inv n p s () i)
`star`
pure (forall_pure_inv_b n p s () i b)
[@@ __reduce__]
let forall_inv
(#a:Type0)
(n:US.t)
(arr:A.array a)
(p:a -> bool)
(r:R.ref US.t)
(perm:perm)
(s:Seq.seq a)
(_:squash (Seq.length s == US.v n))
: bool -> vprop
= fun b -> exists_ (forall_pred n arr p r perm s () b)
inline_for_extraction
let forall_cond
(#a:Type0)
(n:US.t)
(arr:A.array a)
(p:a -> bool)
(r:R.ref US.t)
(perm:perm)
(s:G.erased (Seq.seq a))
(_:squash (Seq.length s == US.v n))
: unit ->
STT bool
(exists_ (forall_inv n arr p r perm s ()))
(forall_inv n arr p r perm s ())
= fun _ ->
let _ = elim_exists () in
let _ = elim_exists () in
elim_pure _;
elim_pure _;
let i = R.read r in
let b = i = n in
let res =
if b then return false
else let elt = A.read arr i in
return (p elt) in
intro_pure (forall_pure_inv n p s () i);
intro_pure (forall_pure_inv_b n p s () i res);
intro_exists i (forall_pred n arr p r perm s () res);
return res
inline_for_extraction
let forall_body
(#a:Type0)
(n:US.t)
(arr:A.array a)
(p:a -> bool)
(r:R.ref US.t)
(perm:perm)
(s:G.erased (Seq.seq a))
(_:squash (Seq.length s == US.v n))
: unit ->
STT unit
(forall_inv n arr p r perm s () true)
(fun _ -> exists_ (forall_inv n arr p r perm s ()))
= fun _ ->
let _ = elim_exists () in
elim_pure _;
elim_pure _;
//atomic increment?
let i = R.read r in
R.write r (US.add i 1sz);
intro_pure (forall_pure_inv n p s () (US.add i 1sz));
intro_pure (forall_pure_inv_b n p s ()
(US.add i 1sz)
((US.add i 1sz) `US.lt` n && p (Seq.index s (US.v (US.add i 1sz)))));
intro_exists
(US.add i 1sz)
(forall_pred n arr p r perm s ()
((US.add i 1sz) `US.lt` n && p (Seq.index s (US.v (US.add i 1sz)))));
intro_exists
((US.add i 1sz) `US.lt` n && p (Seq.index s (US.v (US.add i 1sz))))
(forall_inv n arr p r perm s ())
let for_all #a #perm #s n arr p =
A.pts_to_length arr s;
let b = n = 0sz in
if b then return true
else begin
//This could be stack allocated
let r = R.alloc 0sz in
intro_pure (forall_pure_inv n p s () 0sz);
intro_pure
(forall_pure_inv_b n p s () 0sz
(0sz `US.lt` n && p (Seq.index s (US.v 0sz))));
intro_exists 0sz
(forall_pred n arr p r perm s ()
(0sz `US.lt` n && p (Seq.index s (US.v 0sz))));
intro_exists
(0sz `US.lt` n && p (Seq.index s (US.v 0sz)))
(forall_inv n arr p r perm s ());
Loops.while_loop
(forall_inv n arr p r perm s ())
(forall_cond n arr p r perm s ())
(forall_body n arr p r perm s ());
let _ = elim_exists () in
let _ = elim_pure _ in
let _ = elim_pure _ in
let i = R.read r in
//This free would go away if we had stack allocations
R.free r;
return (i = n)
end
/// Implementation of for_all2 using a while loop | {
"checked_file": "/",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"Steel.ST.Reference.fsti.checked",
"Steel.ST.Loops.fsti.checked",
"Steel.ST.Effect.fsti.checked",
"Steel.ST.Array.fsti.checked",
"Steel.FractionalPermission.fst.checked",
"prims.fst.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.ST.Array.Util.fst"
} | [
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.ST.Loops",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "Steel.ST.Reference",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "US"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "US"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": false,
"full_module": "Steel.ST.Array",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.Array",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
n: FStar.SizeT.t ->
p: (_: a -> _: b -> Prims.bool) ->
s0: FStar.Seq.Base.seq a ->
s1: FStar.Seq.Base.seq b ->
_:
Prims.squash (FStar.Seq.Base.length s0 == FStar.SizeT.v n /\
FStar.Seq.Base.length s0 == FStar.Seq.Base.length s1) ->
i: FStar.SizeT.t
-> Prims.prop | Prims.Tot | [
"total"
] | [] | [
"FStar.SizeT.t",
"Prims.bool",
"FStar.Seq.Base.seq",
"Prims.squash",
"Prims.l_and",
"Prims.eq2",
"Prims.nat",
"FStar.Seq.Base.length",
"FStar.SizeT.v",
"Prims.b2t",
"FStar.SizeT.lte",
"Prims.l_Forall",
"Prims.l_imp",
"Prims.op_LessThan",
"FStar.Seq.Base.index",
"Prims.prop"
] | [] | false | false | false | false | true | let forall2_pure_inv
(#a: Type0)
(#b: Type0)
(n: US.t)
(p: (a -> b -> bool))
(s0: Seq.seq a)
(s1: Seq.seq b)
(_: squash (Seq.length s0 == US.v n /\ Seq.length s0 == Seq.length s1))
(i: US.t)
: prop =
| i `US.lte` n /\ (forall (j: nat). j < US.v i ==> p (Seq.index s0 j) (Seq.index s1 j)) | false |
Steel.ST.Array.Util.fst | Steel.ST.Array.Util.forall_inv | val forall_inv:
#a: Type0 ->
n: US.t ->
arr: A.array a ->
p: (a -> bool) ->
r: R.ref US.t ->
perm: perm ->
s: Seq.seq a ->
squash (Seq.length s == US.v n) ->
bool
-> vprop | val forall_inv:
#a: Type0 ->
n: US.t ->
arr: A.array a ->
p: (a -> bool) ->
r: R.ref US.t ->
perm: perm ->
s: Seq.seq a ->
squash (Seq.length s == US.v n) ->
bool
-> vprop | let forall_inv
(#a:Type0)
(n:US.t)
(arr:A.array a)
(p:a -> bool)
(r:R.ref US.t)
(perm:perm)
(s:Seq.seq a)
(_:squash (Seq.length s == US.v n))
: bool -> vprop
= fun b -> exists_ (forall_pred n arr p r perm s () b) | {
"file_name": "lib/steel/Steel.ST.Array.Util.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 56,
"end_line": 158,
"start_col": 0,
"start_line": 148
} | (*
Copyright 2021 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.ST.Array.Util
module G = FStar.Ghost
module US = FStar.SizeT
module R = Steel.ST.Reference
module A = Steel.ST.Array
module Loops = Steel.ST.Loops
open Steel.FractionalPermission
open Steel.ST.Effect
open Steel.ST.Util
/// Implementation of array_literal using a for loop
let array_literal_inv_pure
(#a:Type0)
(n:US.t)
(f:(i:US.t{US.v i < US.v n} -> a))
(i:Loops.nat_at_most n)
(s:Seq.seq a)
: prop
= forall (j:nat).
(j < i /\ j < Seq.length s) ==> Seq.index s j == f (US.uint_to_t j)
[@@ __reduce__]
let array_literal_inv
(#a:Type0)
(n:US.t)
(arr:A.array a)
(f:(i:US.t{US.v i < US.v n} -> a))
(i:Loops.nat_at_most n)
: Seq.seq a -> vprop
= fun s ->
A.pts_to arr full_perm s
`star`
pure (array_literal_inv_pure n f i s)
inline_for_extraction
let array_literal_loop_body
(#a:Type0)
(n:US.t)
(arr:A.array a{A.length arr == US.v n})
(f:(i:US.t{US.v i < US.v n} -> a))
: i:Loops.u32_between 0sz n ->
STT unit
(exists_ (array_literal_inv n arr f (US.v i)))
(fun _ -> exists_ (array_literal_inv n arr f (US.v i + 1)))
= fun i ->
let s = elim_exists () in
();
A.pts_to_length arr s;
elim_pure (array_literal_inv_pure n f (US.v i) s);
A.write arr i (f i);
intro_pure
(array_literal_inv_pure n f (US.v i + 1) (Seq.upd s (US.v i) (f i)));
intro_exists
(Seq.upd s (US.v i) (f i))
(array_literal_inv n arr f (US.v i + 1))
let array_literal #a n f =
let arr = A.alloc (f 0sz) n in
intro_pure
(array_literal_inv_pure n f 1 (Seq.create (US.v n) (f 0sz)));
intro_exists
(Seq.create (US.v n) (f 0sz))
(array_literal_inv n arr f 1);
Loops.for_loop
1sz
n
(fun i -> exists_ (array_literal_inv n arr f i))
(array_literal_loop_body n arr f);
let s = elim_exists () in
A.pts_to_length arr s;
elim_pure (array_literal_inv_pure n f (US.v n) s);
assert (Seq.equal s (Seq.init (US.v n) (fun i -> f (US.uint_to_t i))));
rewrite (A.pts_to arr full_perm s) _;
return arr
/// Implementation of for_all using a while loop
let forall_pure_inv
(#a:Type0)
(n:US.t)
(p:a -> bool)
(s:Seq.seq a)
(_:squash (Seq.length s == US.v n))
(i:US.t)
: prop
= i `US.lte` n /\ (forall (j:nat). j < US.v i ==> p (Seq.index s j))
let forall_pure_inv_b
(#a:Type0)
(n:US.t)
(p:a -> bool)
(s:Seq.seq a)
(_:squash (Seq.length s == US.v n))
(i:US.t)
(b:bool)
: prop
= b == (i `US.lt` n && p (Seq.index s (US.v i)))
[@@ __reduce__]
let forall_pred
(#a:Type0)
(n:US.t)
(arr:A.array a)
(p:a -> bool)
(r:R.ref US.t)
(perm:perm)
(s:Seq.seq a)
(_:squash (Seq.length s == US.v n))
(b:bool)
: US.t -> vprop
= fun i ->
A.pts_to arr perm s
`star`
R.pts_to r full_perm i
`star`
pure (forall_pure_inv n p s () i)
`star`
pure (forall_pure_inv_b n p s () i b) | {
"checked_file": "/",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"Steel.ST.Reference.fsti.checked",
"Steel.ST.Loops.fsti.checked",
"Steel.ST.Effect.fsti.checked",
"Steel.ST.Array.fsti.checked",
"Steel.FractionalPermission.fst.checked",
"prims.fst.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.ST.Array.Util.fst"
} | [
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.ST.Loops",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "Steel.ST.Reference",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "US"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "US"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": false,
"full_module": "Steel.ST.Array",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.Array",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
n: FStar.SizeT.t ->
arr: Steel.ST.Array.array a ->
p: (_: a -> Prims.bool) ->
r: Steel.ST.Reference.ref FStar.SizeT.t ->
perm: Steel.FractionalPermission.perm ->
s: FStar.Seq.Base.seq a ->
_: Prims.squash (FStar.Seq.Base.length s == FStar.SizeT.v n) ->
_: Prims.bool
-> Steel.Effect.Common.vprop | Prims.Tot | [
"total"
] | [] | [
"FStar.SizeT.t",
"Steel.ST.Array.array",
"Prims.bool",
"Steel.ST.Reference.ref",
"Steel.FractionalPermission.perm",
"FStar.Seq.Base.seq",
"Prims.squash",
"Prims.eq2",
"Prims.nat",
"FStar.Seq.Base.length",
"FStar.SizeT.v",
"Steel.ST.Util.exists_",
"Steel.ST.Array.Util.forall_pred",
"Steel.Effect.Common.vprop"
] | [] | false | false | false | false | false | let forall_inv
(#a: Type0)
(n: US.t)
(arr: A.array a)
(p: (a -> bool))
(r: R.ref US.t)
(perm: perm)
(s: Seq.seq a)
(_: squash (Seq.length s == US.v n))
: bool -> vprop =
| fun b -> exists_ (forall_pred n arr p r perm s () b) | false |
Steel.ST.Array.Util.fst | Steel.ST.Array.Util.forall2_pred | val forall2_pred:
#a: Type0 ->
#b: Type0 ->
n: US.t ->
a0: A.array a ->
a1: A.array b ->
p: (a -> b -> bool) ->
r: R.ref US.t ->
p0: perm ->
p1: perm ->
s0: Seq.seq a ->
s1: Seq.seq b ->
squash (Seq.length s0 == US.v n /\ Seq.length s0 == Seq.length s1) ->
g: bool ->
US.t
-> vprop | val forall2_pred:
#a: Type0 ->
#b: Type0 ->
n: US.t ->
a0: A.array a ->
a1: A.array b ->
p: (a -> b -> bool) ->
r: R.ref US.t ->
p0: perm ->
p1: perm ->
s0: Seq.seq a ->
s1: Seq.seq b ->
squash (Seq.length s0 == US.v n /\ Seq.length s0 == Seq.length s1) ->
g: bool ->
US.t
-> vprop | let forall2_pred
(#a #b:Type0)
(n:US.t)
(a0:A.array a)
(a1:A.array b)
(p:a -> b -> bool)
(r:R.ref US.t)
(p0 p1:perm)
(s0:Seq.seq a)
(s1:Seq.seq b)
(_:squash (Seq.length s0 == US.v n /\ Seq.length s0 == Seq.length s1))
(g:bool)
: US.t -> vprop
= fun i ->
A.pts_to a0 p0 s0
`star`
A.pts_to a1 p1 s1
`star`
R.pts_to r full_perm i
`star`
pure (forall2_pure_inv n p s0 s1 () i)
`star`
pure (forall2_pure_inv_b n p s0 s1 () i g) | {
"file_name": "lib/steel/Steel.ST.Array.Util.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 46,
"end_line": 314,
"start_col": 0,
"start_line": 292
} | (*
Copyright 2021 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.ST.Array.Util
module G = FStar.Ghost
module US = FStar.SizeT
module R = Steel.ST.Reference
module A = Steel.ST.Array
module Loops = Steel.ST.Loops
open Steel.FractionalPermission
open Steel.ST.Effect
open Steel.ST.Util
/// Implementation of array_literal using a for loop
let array_literal_inv_pure
(#a:Type0)
(n:US.t)
(f:(i:US.t{US.v i < US.v n} -> a))
(i:Loops.nat_at_most n)
(s:Seq.seq a)
: prop
= forall (j:nat).
(j < i /\ j < Seq.length s) ==> Seq.index s j == f (US.uint_to_t j)
[@@ __reduce__]
let array_literal_inv
(#a:Type0)
(n:US.t)
(arr:A.array a)
(f:(i:US.t{US.v i < US.v n} -> a))
(i:Loops.nat_at_most n)
: Seq.seq a -> vprop
= fun s ->
A.pts_to arr full_perm s
`star`
pure (array_literal_inv_pure n f i s)
inline_for_extraction
let array_literal_loop_body
(#a:Type0)
(n:US.t)
(arr:A.array a{A.length arr == US.v n})
(f:(i:US.t{US.v i < US.v n} -> a))
: i:Loops.u32_between 0sz n ->
STT unit
(exists_ (array_literal_inv n arr f (US.v i)))
(fun _ -> exists_ (array_literal_inv n arr f (US.v i + 1)))
= fun i ->
let s = elim_exists () in
();
A.pts_to_length arr s;
elim_pure (array_literal_inv_pure n f (US.v i) s);
A.write arr i (f i);
intro_pure
(array_literal_inv_pure n f (US.v i + 1) (Seq.upd s (US.v i) (f i)));
intro_exists
(Seq.upd s (US.v i) (f i))
(array_literal_inv n arr f (US.v i + 1))
let array_literal #a n f =
let arr = A.alloc (f 0sz) n in
intro_pure
(array_literal_inv_pure n f 1 (Seq.create (US.v n) (f 0sz)));
intro_exists
(Seq.create (US.v n) (f 0sz))
(array_literal_inv n arr f 1);
Loops.for_loop
1sz
n
(fun i -> exists_ (array_literal_inv n arr f i))
(array_literal_loop_body n arr f);
let s = elim_exists () in
A.pts_to_length arr s;
elim_pure (array_literal_inv_pure n f (US.v n) s);
assert (Seq.equal s (Seq.init (US.v n) (fun i -> f (US.uint_to_t i))));
rewrite (A.pts_to arr full_perm s) _;
return arr
/// Implementation of for_all using a while loop
let forall_pure_inv
(#a:Type0)
(n:US.t)
(p:a -> bool)
(s:Seq.seq a)
(_:squash (Seq.length s == US.v n))
(i:US.t)
: prop
= i `US.lte` n /\ (forall (j:nat). j < US.v i ==> p (Seq.index s j))
let forall_pure_inv_b
(#a:Type0)
(n:US.t)
(p:a -> bool)
(s:Seq.seq a)
(_:squash (Seq.length s == US.v n))
(i:US.t)
(b:bool)
: prop
= b == (i `US.lt` n && p (Seq.index s (US.v i)))
[@@ __reduce__]
let forall_pred
(#a:Type0)
(n:US.t)
(arr:A.array a)
(p:a -> bool)
(r:R.ref US.t)
(perm:perm)
(s:Seq.seq a)
(_:squash (Seq.length s == US.v n))
(b:bool)
: US.t -> vprop
= fun i ->
A.pts_to arr perm s
`star`
R.pts_to r full_perm i
`star`
pure (forall_pure_inv n p s () i)
`star`
pure (forall_pure_inv_b n p s () i b)
[@@ __reduce__]
let forall_inv
(#a:Type0)
(n:US.t)
(arr:A.array a)
(p:a -> bool)
(r:R.ref US.t)
(perm:perm)
(s:Seq.seq a)
(_:squash (Seq.length s == US.v n))
: bool -> vprop
= fun b -> exists_ (forall_pred n arr p r perm s () b)
inline_for_extraction
let forall_cond
(#a:Type0)
(n:US.t)
(arr:A.array a)
(p:a -> bool)
(r:R.ref US.t)
(perm:perm)
(s:G.erased (Seq.seq a))
(_:squash (Seq.length s == US.v n))
: unit ->
STT bool
(exists_ (forall_inv n arr p r perm s ()))
(forall_inv n arr p r perm s ())
= fun _ ->
let _ = elim_exists () in
let _ = elim_exists () in
elim_pure _;
elim_pure _;
let i = R.read r in
let b = i = n in
let res =
if b then return false
else let elt = A.read arr i in
return (p elt) in
intro_pure (forall_pure_inv n p s () i);
intro_pure (forall_pure_inv_b n p s () i res);
intro_exists i (forall_pred n arr p r perm s () res);
return res
inline_for_extraction
let forall_body
(#a:Type0)
(n:US.t)
(arr:A.array a)
(p:a -> bool)
(r:R.ref US.t)
(perm:perm)
(s:G.erased (Seq.seq a))
(_:squash (Seq.length s == US.v n))
: unit ->
STT unit
(forall_inv n arr p r perm s () true)
(fun _ -> exists_ (forall_inv n arr p r perm s ()))
= fun _ ->
let _ = elim_exists () in
elim_pure _;
elim_pure _;
//atomic increment?
let i = R.read r in
R.write r (US.add i 1sz);
intro_pure (forall_pure_inv n p s () (US.add i 1sz));
intro_pure (forall_pure_inv_b n p s ()
(US.add i 1sz)
((US.add i 1sz) `US.lt` n && p (Seq.index s (US.v (US.add i 1sz)))));
intro_exists
(US.add i 1sz)
(forall_pred n arr p r perm s ()
((US.add i 1sz) `US.lt` n && p (Seq.index s (US.v (US.add i 1sz)))));
intro_exists
((US.add i 1sz) `US.lt` n && p (Seq.index s (US.v (US.add i 1sz))))
(forall_inv n arr p r perm s ())
let for_all #a #perm #s n arr p =
A.pts_to_length arr s;
let b = n = 0sz in
if b then return true
else begin
//This could be stack allocated
let r = R.alloc 0sz in
intro_pure (forall_pure_inv n p s () 0sz);
intro_pure
(forall_pure_inv_b n p s () 0sz
(0sz `US.lt` n && p (Seq.index s (US.v 0sz))));
intro_exists 0sz
(forall_pred n arr p r perm s ()
(0sz `US.lt` n && p (Seq.index s (US.v 0sz))));
intro_exists
(0sz `US.lt` n && p (Seq.index s (US.v 0sz)))
(forall_inv n arr p r perm s ());
Loops.while_loop
(forall_inv n arr p r perm s ())
(forall_cond n arr p r perm s ())
(forall_body n arr p r perm s ());
let _ = elim_exists () in
let _ = elim_pure _ in
let _ = elim_pure _ in
let i = R.read r in
//This free would go away if we had stack allocations
R.free r;
return (i = n)
end
/// Implementation of for_all2 using a while loop
let forall2_pure_inv
(#a #b:Type0)
(n:US.t)
(p:a -> b -> bool)
(s0:Seq.seq a)
(s1:Seq.seq b)
(_:squash (Seq.length s0 == US.v n /\ Seq.length s0 == Seq.length s1))
(i:US.t)
: prop
= i `US.lte` n /\ (forall (j:nat). j < US.v i ==> p (Seq.index s0 j) (Seq.index s1 j))
let forall2_pure_inv_b
(#a #b:Type0)
(n:US.t)
(p:a -> b -> bool)
(s0:Seq.seq a)
(s1:Seq.seq b)
(_:squash (Seq.length s0 == US.v n /\ Seq.length s0 == Seq.length s1))
(i:US.t)
(g:bool)
: prop
= g == (i `US.lt` n && p (Seq.index s0 (US.v i)) (Seq.index s1 (US.v i))) | {
"checked_file": "/",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"Steel.ST.Reference.fsti.checked",
"Steel.ST.Loops.fsti.checked",
"Steel.ST.Effect.fsti.checked",
"Steel.ST.Array.fsti.checked",
"Steel.FractionalPermission.fst.checked",
"prims.fst.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.ST.Array.Util.fst"
} | [
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.ST.Loops",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "Steel.ST.Reference",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "US"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "US"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": false,
"full_module": "Steel.ST.Array",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.Array",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
n: FStar.SizeT.t ->
a0: Steel.ST.Array.array a ->
a1: Steel.ST.Array.array b ->
p: (_: a -> _: b -> Prims.bool) ->
r: Steel.ST.Reference.ref FStar.SizeT.t ->
p0: Steel.FractionalPermission.perm ->
p1: Steel.FractionalPermission.perm ->
s0: FStar.Seq.Base.seq a ->
s1: FStar.Seq.Base.seq b ->
_:
Prims.squash (FStar.Seq.Base.length s0 == FStar.SizeT.v n /\
FStar.Seq.Base.length s0 == FStar.Seq.Base.length s1) ->
g: Prims.bool ->
_: FStar.SizeT.t
-> Steel.Effect.Common.vprop | Prims.Tot | [
"total"
] | [] | [
"FStar.SizeT.t",
"Steel.ST.Array.array",
"Prims.bool",
"Steel.ST.Reference.ref",
"Steel.FractionalPermission.perm",
"FStar.Seq.Base.seq",
"Prims.squash",
"Prims.l_and",
"Prims.eq2",
"Prims.nat",
"FStar.Seq.Base.length",
"FStar.SizeT.v",
"Steel.Effect.Common.star",
"Steel.ST.Array.pts_to",
"Steel.ST.Reference.pts_to",
"Steel.FractionalPermission.full_perm",
"Steel.ST.Util.pure",
"Steel.ST.Array.Util.forall2_pure_inv",
"Steel.ST.Array.Util.forall2_pure_inv_b",
"Steel.Effect.Common.vprop"
] | [] | false | false | false | false | false | let forall2_pred
(#a: Type0)
(#b: Type0)
(n: US.t)
(a0: A.array a)
(a1: A.array b)
(p: (a -> b -> bool))
(r: R.ref US.t)
(p0: perm)
(p1: perm)
(s0: Seq.seq a)
(s1: Seq.seq b)
(_: squash (Seq.length s0 == US.v n /\ Seq.length s0 == Seq.length s1))
(g: bool)
: US.t -> vprop =
| fun i ->
((((A.pts_to a0 p0 s0) `star` (A.pts_to a1 p1 s1)) `star` (R.pts_to r full_perm i))
`star`
(pure (forall2_pure_inv n p s0 s1 () i)))
`star`
(pure (forall2_pure_inv_b n p s0 s1 () i g)) | false |
Steel.ST.Array.Util.fst | Steel.ST.Array.Util.array_literal_inv_pure | val array_literal_inv_pure
(#a: Type0)
(n: US.t)
(f: (i: US.t{US.v i < US.v n} -> a))
(i: Loops.nat_at_most n)
(s: Seq.seq a)
: prop | val array_literal_inv_pure
(#a: Type0)
(n: US.t)
(f: (i: US.t{US.v i < US.v n} -> a))
(i: Loops.nat_at_most n)
(s: Seq.seq a)
: prop | let array_literal_inv_pure
(#a:Type0)
(n:US.t)
(f:(i:US.t{US.v i < US.v n} -> a))
(i:Loops.nat_at_most n)
(s:Seq.seq a)
: prop
= forall (j:nat).
(j < i /\ j < Seq.length s) ==> Seq.index s j == f (US.uint_to_t j) | {
"file_name": "lib/steel/Steel.ST.Array.Util.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 73,
"end_line": 41,
"start_col": 0,
"start_line": 33
} | (*
Copyright 2021 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.ST.Array.Util
module G = FStar.Ghost
module US = FStar.SizeT
module R = Steel.ST.Reference
module A = Steel.ST.Array
module Loops = Steel.ST.Loops
open Steel.FractionalPermission
open Steel.ST.Effect
open Steel.ST.Util
/// Implementation of array_literal using a for loop | {
"checked_file": "/",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"Steel.ST.Reference.fsti.checked",
"Steel.ST.Loops.fsti.checked",
"Steel.ST.Effect.fsti.checked",
"Steel.ST.Array.fsti.checked",
"Steel.FractionalPermission.fst.checked",
"prims.fst.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.ST.Array.Util.fst"
} | [
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.ST.Loops",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "Steel.ST.Reference",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "US"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "US"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": false,
"full_module": "Steel.ST.Array",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.Array",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
n: FStar.SizeT.t ->
f: (i: FStar.SizeT.t{FStar.SizeT.v i < FStar.SizeT.v n} -> a) ->
i: Steel.ST.Loops.nat_at_most n ->
s: FStar.Seq.Base.seq a
-> Prims.prop | Prims.Tot | [
"total"
] | [] | [
"FStar.SizeT.t",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.SizeT.v",
"Steel.ST.Loops.nat_at_most",
"FStar.Seq.Base.seq",
"Prims.l_Forall",
"Prims.nat",
"Prims.l_imp",
"Prims.l_and",
"FStar.Seq.Base.length",
"Prims.eq2",
"FStar.Seq.Base.index",
"FStar.SizeT.uint_to_t",
"Prims.prop"
] | [] | false | false | false | false | true | let array_literal_inv_pure
(#a: Type0)
(n: US.t)
(f: (i: US.t{US.v i < US.v n} -> a))
(i: Loops.nat_at_most n)
(s: Seq.seq a)
: prop =
| forall (j: nat). (j < i /\ j < Seq.length s) ==> Seq.index s j == f (US.uint_to_t j) | false |
Wasm11.fst | Wasm11.main | val main: Prims.unit -> SteelT Int32.t emp (fun _ -> emp) | val main: Prims.unit -> SteelT Int32.t emp (fun _ -> emp) | let main () : SteelT Int32.t emp (fun _ -> emp) =
let res1 = test1 () in
let res2 = test2 () in
if res1 && res2 then 0l else 1l | {
"file_name": "share/steel/tests/krml/Wasm11.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 33,
"end_line": 54,
"start_col": 0,
"start_line": 51
} | module Wasm11
open FStar.SizeT
open FStar.PtrdiffT
open FStar.UInt64
open Steel.Effect.Atomic
open Steel.Effect
open Steel.Array
(* WASM tests for pointer subtraction *)
let test1 () : SteelT bool emp (fun _ -> emp) =
let r = malloc 0uL 8sz in
ghost_split r 4sz;
let r1 = split_l r 4sz in
let r2 = split_r r 4sz in
change_equal_slprop (varray (split_l r 4sz)) (varray r1);
change_equal_slprop (varray (split_r r 4sz)) (varray r2);
let _ = mk 4s in
let b = ptrdiff r2 r1 in
ghost_join r1 r2 ();
change_equal_slprop
(varray (merge r1 r2))
(varray r);
// Free not supported in Wasm
drop (varray r);
return (b = mk 4s)
type t = { foo: UInt32.t; bar: UInt16.t }
inline_for_extraction noextract
let def_t : t = { foo = 0ul; bar = 0us }
let test2 () : SteelT bool emp (fun _ -> emp) =
let r = malloc def_t 8sz in
ghost_split r 4sz;
let r1 = split_l r 4sz in
let r2 = split_r r 4sz in
change_equal_slprop (varray (split_l r 4sz)) (varray r1);
change_equal_slprop (varray (split_r r 4sz)) (varray r2);
let _ = mk 4s in
let b = ptrdiff r2 r1 in
ghost_join r1 r2 ();
change_equal_slprop
(varray (merge r1 r2))
(varray r);
// Free not supported in wasm
drop (varray r);
return (b = mk 4s) | {
"checked_file": "/",
"dependencies": [
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"Steel.Array.fsti.checked",
"prims.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.SizeT.fsti.checked",
"FStar.PtrdiffT.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked"
],
"interface_file": false,
"source_file": "Wasm11.fst"
} | [
{
"abbrev": false,
"full_module": "Steel.Array",
"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": "FStar.UInt64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.PtrdiffT",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.SizeT",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit -> Steel.Effect.SteelT FStar.Int32.t | Steel.Effect.SteelT | [] | [] | [
"Prims.unit",
"Prims.op_AmpAmp",
"FStar.Int32.__int_to_t",
"Prims.bool",
"FStar.Int32.t",
"Wasm11.test2",
"Wasm11.test1",
"Steel.Effect.Common.emp",
"Steel.Effect.Common.vprop"
] | [] | false | true | false | false | false | let main () : SteelT Int32.t emp (fun _ -> emp) =
| let res1 = test1 () in
let res2 = test2 () in
if res1 && res2 then 0l else 1l | false |
CQueue.fst | CQueue.elim_queue_head | val elim_queue_head
(#opened: _)
(#a: Type)
(x: t a)
(l: Ghost.erased (list a))
: SteelGhost (Ghost.erased (ccell_ptrvalue a)) opened
(queue_head x l)
(fun hd -> vptr (cllist_head x) `star` llist_fragment_head l (cllist_head x) hd `star` vptr (cllist_tail x))
(fun _ -> True)
(fun _ hd h -> (
let frag = (sel_llist_fragment_head l (cllist_head x) hd) h in
sel (cllist_head x) h == Ghost.reveal hd /\
sel (cllist_tail x) h == fst frag /\
ccell_ptrvalue_is_null (snd frag) == true
)) | val elim_queue_head
(#opened: _)
(#a: Type)
(x: t a)
(l: Ghost.erased (list a))
: SteelGhost (Ghost.erased (ccell_ptrvalue a)) opened
(queue_head x l)
(fun hd -> vptr (cllist_head x) `star` llist_fragment_head l (cllist_head x) hd `star` vptr (cllist_tail x))
(fun _ -> True)
(fun _ hd h -> (
let frag = (sel_llist_fragment_head l (cllist_head x) hd) h in
sel (cllist_head x) h == Ghost.reveal hd /\
sel (cllist_tail x) h == fst frag /\
ccell_ptrvalue_is_null (snd frag) == true
)) | let elim_queue_head
#_ #a x l
=
let hd = elim_vdep
(vptr (cllist_head x))
(queue_head_dep2 x l)
in
let ptl = elim_vdep
(llist_fragment_head l (cllist_head x) hd)
(queue_head_dep1 x l hd)
in
elim_vrefine
(vptr (cllist_tail x))
(queue_head_refine x l hd ptl);
hd | {
"file_name": "share/steel/examples/steel/CQueue.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 4,
"end_line": 1257,
"start_col": 0,
"start_line": 1243
} | module CQueue
open CQueue.LList
#set-options "--ide_id_info_off"
//Re-define squash, since this module explicitly
//replies on proving equalities of the form `t_of v == squash p`
//which are delicate in the presence of optimizations that
//unfold `Prims.squash (p /\ q)`to _:unit{p /\ q}
//See Issue #2496
let squash (p:Type u#a) : Type0 = squash p
(* BEGIN library *)
let intro_vrewrite_no_norm (#opened:inames)
(v: vprop) (#t: Type) (f: (t_of v) -> GTot t)
: SteelGhost unit opened v (fun _ -> vrewrite v f)
(fun _ -> True) (fun h _ h' -> h' (vrewrite v f) == f (h v))
=
intro_vrewrite v f
let elim_vrewrite_no_norm (#opened:inames)
(v: vprop)
(#t: Type)
(f: ((t_of v) -> GTot t))
: SteelGhost unit opened (vrewrite v f) (fun _ -> v)
(fun _ -> True)
(fun h _ h' -> h (vrewrite v f) == f (h' v))
=
elim_vrewrite v f
let vconst_sel
(#a: Type)
(x: a)
: Tot (selector a (hp_of emp))
= fun _ -> x
[@@ __steel_reduce__]
let vconst'
(#a: Type)
(x: a)
: GTot vprop'
= {
hp = hp_of emp;
t = a;
sel = vconst_sel x;
}
[@@ __steel_reduce__]
let vconst (#a: Type) (x: a) : Tot vprop = VUnit (vconst' x)
let intro_vconst
(#opened: _)
(#a: Type)
(x: a)
: SteelGhost unit opened
emp
(fun _ -> vconst x)
(fun _ -> True)
(fun _ _ h' -> h' (vconst x) == x)
=
change_slprop_rel
emp
(vconst x)
(fun _ y -> y == x)
(fun _ -> ())
let elim_vconst
(#opened: _)
(#a: Type)
(x: a)
: SteelGhost unit opened
(vconst x)
(fun _ -> emp)
(fun _ -> True)
(fun h _ _ -> h (vconst x) == x)
=
change_slprop_rel
(vconst x)
emp
(fun y _ -> y == x)
(fun _ -> ())
let vpure_sel'
(p: prop)
: Tot (selector' (squash p) (Steel.Memory.pure p))
= fun (m: Steel.Memory.hmem (Steel.Memory.pure p)) -> pure_interp p m
let vpure_sel
(p: prop)
: Tot (selector (squash p) (Steel.Memory.pure p))
= vpure_sel' p
[@@ __steel_reduce__]
let vpure'
(p: prop)
: GTot vprop'
= {
hp = Steel.Memory.pure p;
t = squash p;
sel = vpure_sel p;
}
[@@ __steel_reduce__]
let vpure (p: prop) : Tot vprop = VUnit (vpure' p)
let intro_vpure
(#opened: _)
(p: prop)
: SteelGhost unit opened
emp
(fun _ -> vpure p)
(fun _ -> p)
(fun _ _ h' -> p)
=
change_slprop_rel
emp
(vpure p)
(fun _ _ -> p)
(fun m -> pure_interp p m)
let elim_vpure
(#opened: _)
(p: prop)
: SteelGhost unit opened
(vpure p)
(fun _ -> emp)
(fun _ -> True)
(fun _ _ _ -> p)
=
change_slprop_rel
(vpure p)
emp
(fun _ _ -> p)
(fun m -> pure_interp p m; reveal_emp (); intro_emp m)
val intro_vdep2 (#opened:inames)
(v: vprop)
(q: vprop)
(x: t_of v)
(p: (t_of v -> Tot vprop))
: SteelGhost unit opened
(v `star` q)
(fun _ -> vdep v p)
(requires (fun h ->
q == p x /\
x == h v
))
(ensures (fun h _ h' ->
let x2 = h' (vdep v p) in
q == p (h v) /\
dfst x2 == (h v) /\
dsnd x2 == (h q)
))
let intro_vdep2
v q x p
=
intro_vdep v q p
let vbind0_payload
(a: vprop)
(t: Type0)
(b: (t_of a -> Tot vprop))
(x: t_of a)
: Tot vprop
= vpure (t == t_of (b x)) `star` b x
let vbind0_rewrite
(a: vprop)
(t: Type0)
(b: (t_of a -> Tot vprop))
(x: normal (t_of (vdep a (vbind0_payload a t b))))
: Tot t
= snd (dsnd x)
[@@__steel_reduce__; __reduce__]
let vbind0
(a: vprop)
(t: Type0)
(b: (t_of a -> Tot vprop))
: Tot vprop
= a `vdep` vbind0_payload a t b `vrewrite` vbind0_rewrite a t b
let vbind_hp // necessary to hide the attribute on hp_of
(a: vprop)
(t: Type0)
(b: (t_of a -> Tot vprop))
: Tot (slprop u#1)
= hp_of (vbind0 a t b)
let vbind_sel // same for hp_sel
(a: vprop)
(t: Type0)
(b: (t_of a -> Tot vprop))
: GTot (selector t (vbind_hp a t b))
= sel_of (vbind0 a t b)
[@@__steel_reduce__]
let vbind'
(a: vprop)
(t: Type0)
(b: (t_of a -> Tot vprop))
: GTot vprop'
= {
hp = vbind_hp a t b;
t = t;
sel = vbind_sel a t b;
}
[@@__steel_reduce__]
let vbind
(a: vprop)
(t: Type0)
(b: (t_of a -> Tot vprop))
: Tot vprop
= VUnit (vbind' a t b)
let intro_vbind
(#opened: _)
(a: vprop)
(b' : vprop)
(t: Type0)
(b: (t_of a -> Tot vprop))
: SteelGhost unit opened
(a `star` b')
(fun _ -> vbind a t b)
(fun h -> t_of b' == t /\ b' == b (h a))
(fun h _ h' ->
t_of b' == t /\
b' == b (h a) /\
h' (vbind a t b) == h b'
)
=
intro_vpure (t == t_of b');
intro_vdep
a
(vpure (t == t_of b') `star` b')
(vbind0_payload a t b);
intro_vrewrite
(a `vdep` vbind0_payload a t b)
(vbind0_rewrite a t b);
change_slprop_rel
(vbind0 a t b)
(vbind a t b)
(fun x y -> x == y)
(fun _ -> ())
let elim_vbind
(#opened: _)
(a: vprop)
(t: Type0)
(b: (t_of a -> Tot vprop))
: SteelGhost (Ghost.erased (t_of a)) opened
(vbind a t b)
(fun res -> a `star` b (Ghost.reveal res))
(fun h -> True)
(fun h res h' ->
h' a == Ghost.reveal res /\
t == t_of (b (Ghost.reveal res)) /\
h' (b (Ghost.reveal res)) == h (vbind a t b)
)
=
change_slprop_rel
(vbind a t b)
(vbind0 a t b)
(fun x y -> x == y)
(fun _ -> ());
elim_vrewrite
(a `vdep` vbind0_payload a t b)
(vbind0_rewrite a t b);
let res = elim_vdep a (vbind0_payload a t b) in
change_equal_slprop
(vbind0_payload a t b (Ghost.reveal res))
(vpure (t == t_of (b (Ghost.reveal res))) `star` b (Ghost.reveal res));
elim_vpure (t == t_of (b (Ghost.reveal res)));
res
let (==) (#a:_) (x y: a) : prop = x == y
let snoc_inj (#a: Type) (hd1 hd2: list a) (tl1 tl2: a) : Lemma
(requires (hd1 `L.append` [tl1] == hd2 `L.append` [tl2]))
(ensures (hd1 == hd2 /\ tl1 == tl2))
[SMTPat (hd1 `L.append` [tl1]); SMTPat (hd2 `L.append` [tl2])]
= L.lemma_snoc_unsnoc (hd1, tl1);
L.lemma_snoc_unsnoc (hd2, tl2)
[@"opaque_to_smt"]
let unsnoc (#a: Type) (l: list a) : Pure (list a & a)
(requires (Cons? l))
(ensures (fun (hd, tl) -> l == hd `L.append` [tl] /\ L.length hd < L.length l))
=
L.lemma_unsnoc_snoc l;
L.append_length (fst (L.unsnoc l)) [snd (L.unsnoc l)];
L.unsnoc l
let unsnoc_hd (#a: Type) (l: list a) : Pure (list a) (requires (Cons? l)) (ensures (fun l' -> L.length l' <
L.length l)) = fst (unsnoc l)
let unsnoc_tl (#a: Type) (l: list a) : Pure (a) (requires (Cons? l)) (ensures (fun _ -> True)) = snd (unsnoc l)
[@@"opaque_to_smt"]
let snoc (#a: Type) (l: list a) (x: a) : Pure (list a)
(requires True)
(ensures (fun l' ->
Cons? l' /\
unsnoc_hd l' == l /\
unsnoc_tl l' == x
))
=
let l' = L.snoc (l, x) in
L.append_length l [x];
snoc_inj l (unsnoc_hd l') x (unsnoc_tl l');
l'
let snoc_unsnoc
(#a: Type)
(l: list a)
: Lemma
(requires (Cons? l))
(ensures (snoc (unsnoc_hd l) (unsnoc_tl l) == l))
= ()
unfold
let coerce
(#a: Type)
(x: a)
(b: Type)
: Pure b
(requires (a == b))
(ensures (fun y -> a == b /\ x == y))
= x
(* END library *)
let t a = cllist_lvalue a
let v (a: Type0) = list a
let datas
(#a: Type0)
(l: v a)
: Tot (list a)
= l
(* view from the tail *)
let llist_fragment_tail_cons_data_refine
(#a: Type)
(l: Ghost.erased (list a) { Cons? (Ghost.reveal l) })
(d: a)
: Tot prop
= d == unsnoc_tl (Ghost.reveal l)
[@@ __steel_reduce__]
let llist_fragment_tail_cons_lvalue_payload
(#a: Type)
(l: Ghost.erased (list a) { Cons? (Ghost.reveal l) })
(c: ccell_lvalue a)
: Tot vprop
= vptr (ccell_data c) `vrefine` llist_fragment_tail_cons_data_refine l
let ccell_is_lvalue_refine
(a: Type)
(c: ccell_ptrvalue a)
: Tot prop
= ccell_ptrvalue_is_null c == false
[@@ __steel_reduce__ ]
let llist_fragment_tail_cons_next_payload
(#a: Type)
(l: Ghost.erased (list a) { Cons? (Ghost.reveal l) })
(ptail: ref (ccell_ptrvalue a))
: Tot vprop
= vptr ptail `vrefine` ccell_is_lvalue_refine a `vdep` llist_fragment_tail_cons_lvalue_payload l
[@@ __steel_reduce__ ]
let llist_fragment_tail_cons_rewrite
(#a: Type)
(l: Ghost.erased (list a) { Cons? (Ghost.reveal l) })
(llist_fragment_tail: vprop { t_of llist_fragment_tail == ref (ccell_ptrvalue a) })
(x: normal (t_of (llist_fragment_tail `vdep` (llist_fragment_tail_cons_next_payload l))))
: Tot (ref (ccell_ptrvalue a))
= let (| _, (| c, _ |) |) = x in
ccell_next c
let rec llist_fragment_tail (#a: Type) (l: Ghost.erased (list a)) (phead: ref (ccell_ptrvalue a)) : Pure vprop
(requires True)
(ensures (fun v -> t_of v == ref (ccell_ptrvalue a)))
(decreases (Ghost.reveal (L.length l)))
= if Nil? l
then vconst phead
else llist_fragment_tail (Ghost.hide (unsnoc_hd (Ghost.reveal l))) phead `vdep` llist_fragment_tail_cons_next_payload l `vrewrite` llist_fragment_tail_cons_rewrite l (llist_fragment_tail (Ghost.hide (unsnoc_hd (Ghost.reveal l))) phead)
let llist_fragment_tail_eq
(#a: Type) (l: Ghost.erased (list a)) (phead: ref (ccell_ptrvalue a))
: Lemma
(llist_fragment_tail l phead == (
if Nil? l
then vconst phead
else llist_fragment_tail (Ghost.hide (unsnoc_hd (Ghost.reveal l))) phead `vdep` llist_fragment_tail_cons_next_payload l `vrewrite` llist_fragment_tail_cons_rewrite l (llist_fragment_tail (Ghost.hide (unsnoc_hd (Ghost.reveal l))) phead)
))
= assert_norm
(llist_fragment_tail l phead == (
if Nil? l
then vconst phead
else llist_fragment_tail (Ghost.hide (unsnoc_hd (Ghost.reveal l))) phead `vdep` llist_fragment_tail_cons_next_payload l `vrewrite` llist_fragment_tail_cons_rewrite l (llist_fragment_tail (Ghost.hide (unsnoc_hd (Ghost.reveal l))) phead)
))
let llist_fragment_tail_eq_cons
(#a: Type) (l: Ghost.erased (list a)) (phead: ref (ccell_ptrvalue a))
: Lemma
(requires (Cons? l))
(ensures (Cons? l /\
llist_fragment_tail l phead == (
llist_fragment_tail (Ghost.hide (unsnoc_hd (Ghost.reveal l))) phead `vdep` llist_fragment_tail_cons_next_payload l `vrewrite` llist_fragment_tail_cons_rewrite l (llist_fragment_tail (Ghost.hide (unsnoc_hd (Ghost.reveal l))) phead)
)))
= llist_fragment_tail_eq l phead
unfold
let sel_llist_fragment_tail
(#a:Type) (#p:vprop)
(l: Ghost.erased (list a)) (phead: ref (ccell_ptrvalue a))
(h: rmem p { FStar.Tactics.with_tactic selector_tactic (can_be_split p (llist_fragment_tail l phead) /\ True) })
: GTot (ref (ccell_ptrvalue a))
=
coerce (h (llist_fragment_tail l phead)) (ref (ccell_ptrvalue a))
val intro_llist_fragment_tail_nil
(#opened: _)
(#a: Type)
(l: Ghost.erased (list a))
(phead: ref (ccell_ptrvalue a))
: SteelGhost unit opened
emp
(fun _ -> llist_fragment_tail l phead)
(fun _ -> Nil? l)
(fun _ _ h' -> sel_llist_fragment_tail l phead h' == phead)
let intro_llist_fragment_tail_nil
l phead
=
intro_vconst phead;
change_equal_slprop
(vconst phead)
(llist_fragment_tail l phead)
val elim_llist_fragment_tail_nil
(#opened: _)
(#a: Type)
(l: Ghost.erased (list a))
(phead: ref (ccell_ptrvalue a))
: SteelGhost unit opened
(llist_fragment_tail l phead)
(fun _ -> emp)
(fun _ -> Nil? l)
(fun h _ _ -> sel_llist_fragment_tail l phead h == phead)
let elim_llist_fragment_tail_nil
l phead
=
change_equal_slprop
(llist_fragment_tail l phead)
(vconst phead);
elim_vconst phead
val intro_llist_fragment_tail_snoc
(#opened: _)
(#a: Type)
(l: Ghost.erased (list a))
(phead: ref (ccell_ptrvalue a))
(ptail: Ghost.erased (ref (ccell_ptrvalue a)))
(tail: Ghost.erased (ccell_lvalue a))
: SteelGhost (Ghost.erased (list a)) opened
(llist_fragment_tail l phead `star` vptr ptail `star` vptr (ccell_data tail))
(fun res -> llist_fragment_tail res phead)
(fun h ->
sel_llist_fragment_tail l phead h == Ghost.reveal ptail /\
sel ptail h == Ghost.reveal tail
)
(fun h res h' ->
Ghost.reveal res == snoc (Ghost.reveal l) (sel (ccell_data tail) h) /\
sel_llist_fragment_tail res phead h' == ccell_next tail
)
#push-options "--z3rlimit 16"
let intro_llist_fragment_tail_snoc
#_ #a l phead ptail tail
=
let d = gget (vptr (ccell_data tail)) in
let l' : (l' : Ghost.erased (list a) { Cons? (Ghost.reveal l') }) = Ghost.hide (snoc (Ghost.reveal l) (Ghost.reveal d)) in
intro_vrefine (vptr (ccell_data tail)) (llist_fragment_tail_cons_data_refine l');
intro_vrefine (vptr ptail) (ccell_is_lvalue_refine a);
intro_vdep
(vptr ptail `vrefine` ccell_is_lvalue_refine a)
(vptr (ccell_data tail) `vrefine` llist_fragment_tail_cons_data_refine l')
(llist_fragment_tail_cons_lvalue_payload l');
change_equal_slprop
(llist_fragment_tail l phead)
(llist_fragment_tail (Ghost.hide (unsnoc_hd l')) phead);
intro_vdep
(llist_fragment_tail (Ghost.hide (unsnoc_hd l')) phead)
(vptr ptail `vrefine` ccell_is_lvalue_refine a `vdep` llist_fragment_tail_cons_lvalue_payload l')
(llist_fragment_tail_cons_next_payload l');
intro_vrewrite_no_norm
(llist_fragment_tail (Ghost.hide (unsnoc_hd l')) phead `vdep` llist_fragment_tail_cons_next_payload l')
(llist_fragment_tail_cons_rewrite l' (llist_fragment_tail (Ghost.hide (unsnoc_hd l')) phead));
llist_fragment_tail_eq_cons l' phead;
change_equal_slprop
(llist_fragment_tail (Ghost.hide (unsnoc_hd l')) phead `vdep` llist_fragment_tail_cons_next_payload l' `vrewrite` llist_fragment_tail_cons_rewrite l' (llist_fragment_tail (Ghost.hide (unsnoc_hd l')) phead))
(llist_fragment_tail l' phead);
let g' = gget (llist_fragment_tail l' phead) in
assert (Ghost.reveal g' == ccell_next tail);
noop ();
l'
#pop-options
[@@erasable]
noeq
type ll_unsnoc_t (a: Type) = {
ll_unsnoc_l: list a;
ll_unsnoc_ptail: ref (ccell_ptrvalue a);
ll_unsnoc_tail: ccell_lvalue a;
}
val elim_llist_fragment_tail_snoc
(#opened: _)
(#a: Type)
(l: Ghost.erased (list a))
(phead: ref (ccell_ptrvalue a))
: SteelGhost (ll_unsnoc_t a) opened
(llist_fragment_tail l phead)
(fun res -> llist_fragment_tail res.ll_unsnoc_l phead `star` vptr res.ll_unsnoc_ptail `star` vptr (ccell_data res.ll_unsnoc_tail))
(fun _ -> Cons? l)
(fun h res h' ->
Cons? l /\
Ghost.reveal res.ll_unsnoc_l == unsnoc_hd l /\
sel res.ll_unsnoc_ptail h' == res.ll_unsnoc_tail /\
sel (ccell_data res.ll_unsnoc_tail) h'== unsnoc_tl l /\
sel_llist_fragment_tail res.ll_unsnoc_l phead h' == res.ll_unsnoc_ptail /\
sel_llist_fragment_tail l phead h == (ccell_next res.ll_unsnoc_tail)
)
#push-options "--z3rlimit 32"
#restart-solver
let elim_llist_fragment_tail_snoc
#_ #a l phead
=
let l0 : (l0: Ghost.erased (list a) { Cons? l0 }) = Ghost.hide (Ghost.reveal l) in
llist_fragment_tail_eq_cons l0 phead;
change_equal_slprop
(llist_fragment_tail l phead)
(llist_fragment_tail (Ghost.hide (unsnoc_hd l0)) phead `vdep` llist_fragment_tail_cons_next_payload l0 `vrewrite` llist_fragment_tail_cons_rewrite l0 (llist_fragment_tail (Ghost.hide (unsnoc_hd l0)) phead));
elim_vrewrite_no_norm
(llist_fragment_tail (Ghost.hide (unsnoc_hd l0)) phead `vdep` llist_fragment_tail_cons_next_payload l0)
(llist_fragment_tail_cons_rewrite l0 (llist_fragment_tail (Ghost.hide (unsnoc_hd l0)) phead));
let ptail = elim_vdep
(llist_fragment_tail (Ghost.hide (unsnoc_hd l0)) phead)
(llist_fragment_tail_cons_next_payload l0)
in
let ptail0 : Ghost.erased (ref (ccell_ptrvalue a)) = ptail in
change_equal_slprop
(llist_fragment_tail_cons_next_payload l0 (Ghost.reveal ptail))
(vptr (Ghost.reveal ptail0) `vrefine` ccell_is_lvalue_refine a `vdep` llist_fragment_tail_cons_lvalue_payload l0);
let tail = elim_vdep
(vptr (Ghost.reveal ptail0) `vrefine` ccell_is_lvalue_refine a)
(llist_fragment_tail_cons_lvalue_payload l0)
in
elim_vrefine (vptr (Ghost.reveal ptail0)) (ccell_is_lvalue_refine a);
let res = {
ll_unsnoc_l = unsnoc_hd l0;
ll_unsnoc_ptail = Ghost.reveal ptail0;
ll_unsnoc_tail = Ghost.reveal tail;
} in
change_equal_slprop
(vptr (Ghost.reveal ptail0))
(vptr res.ll_unsnoc_ptail);
change_equal_slprop
(llist_fragment_tail_cons_lvalue_payload l0 (Ghost.reveal tail))
(vptr (ccell_data res.ll_unsnoc_tail) `vrefine` llist_fragment_tail_cons_data_refine l0);
elim_vrefine
(vptr (ccell_data res.ll_unsnoc_tail))
(llist_fragment_tail_cons_data_refine l0);
change_equal_slprop
(llist_fragment_tail (Ghost.hide (unsnoc_hd l0)) phead)
(llist_fragment_tail res.ll_unsnoc_l phead);
res
#pop-options
let rec llist_fragment_tail_append
(#opened: _)
(#a: Type)
(phead0: ref (ccell_ptrvalue a))
(l1: Ghost.erased (list a))
(phead1: Ghost.erased (ref (ccell_ptrvalue a)))
(l2: Ghost.erased (list a))
: SteelGhost (Ghost.erased (list a)) opened
(llist_fragment_tail l1 phead0 `star` llist_fragment_tail l2 phead1)
(fun res -> llist_fragment_tail res phead0)
(fun h ->
Ghost.reveal phead1 == (sel_llist_fragment_tail l1 phead0) h
)
(fun h res h' ->
Ghost.reveal res == Ghost.reveal l1 `L.append` Ghost.reveal l2 /\
(sel_llist_fragment_tail res phead0) h' == (sel_llist_fragment_tail l2 phead1) h
)
(decreases (L.length (Ghost.reveal l2)))
=
let g1 = gget (llist_fragment_tail l1 phead0) in
assert (Ghost.reveal phead1 == Ghost.reveal g1);
if Nil? l2
then begin
L.append_l_nil (Ghost.reveal l1);
elim_llist_fragment_tail_nil l2 phead1;
l1
end else begin
let res = elim_llist_fragment_tail_snoc l2 (Ghost.reveal phead1) in
let d = gget (vptr (ccell_data res.ll_unsnoc_tail)) in
L.append_assoc (Ghost.reveal l1) (Ghost.reveal res.ll_unsnoc_l) [Ghost.reveal d];
let l3 = llist_fragment_tail_append phead0 l1 phead1 res.ll_unsnoc_l in
intro_llist_fragment_tail_snoc l3 phead0 res.ll_unsnoc_ptail res.ll_unsnoc_tail
end
let queue_tail_refine
(#a: Type)
(tail1: ref (ccell_ptrvalue a))
(tail2: ref (ccell_ptrvalue a))
(tl: normal (t_of (vptr tail2)))
: Tot prop
= ccell_ptrvalue_is_null tl == true /\ tail1 == tail2
[@@__steel_reduce__]
let queue_tail_dep2
(#a: Type)
(x: t a)
(l: Ghost.erased (list a))
(tail1: t_of (llist_fragment_tail l (cllist_head x)))
(tail2: ref (ccell_ptrvalue a))
: Tot vprop
= vptr tail2 `vrefine` queue_tail_refine tail1 tail2
[@@__steel_reduce__]
let queue_tail_dep1
(#a: Type)
(x: t a)
(l: Ghost.erased (list a))
(tail1: t_of (llist_fragment_tail l (cllist_head x)))
: Tot vprop
= vptr (cllist_tail x) `vdep` queue_tail_dep2 x l tail1
[@@__steel_reduce__; __reduce__]
let queue_tail
(#a: Type)
(x: t a)
(l: Ghost.erased (list a))
: Tot vprop
=
llist_fragment_tail l (cllist_head x) `vdep` queue_tail_dep1 x l
val intro_queue_tail
(#opened: _)
(#a: Type)
(x: t a)
(l: Ghost.erased (list a))
(tail: ref (ccell_ptrvalue a))
: SteelGhost unit opened
(llist_fragment_tail l (cllist_head x) `star` vptr (cllist_tail x) `star` vptr tail)
(fun _ -> queue_tail x l)
(fun h ->
sel_llist_fragment_tail l (cllist_head x) h == tail /\
sel (cllist_tail x) h == tail /\
ccell_ptrvalue_is_null (sel tail h)
)
(fun _ _ _ -> True)
let intro_queue_tail
x l tail
=
intro_vrefine (vptr tail) (queue_tail_refine tail tail);
intro_vdep2
(vptr (cllist_tail x))
(vptr tail `vrefine` queue_tail_refine tail tail)
tail
(queue_tail_dep2 x l tail);
intro_vdep2
(llist_fragment_tail l (cllist_head x))
(vptr (cllist_tail x) `vdep` queue_tail_dep2 x l tail)
tail
(queue_tail_dep1 x l)
val elim_queue_tail
(#opened: _)
(#a: Type)
(x: t a)
(l: Ghost.erased (list a))
: SteelGhost (Ghost.erased (ref (ccell_ptrvalue a))) opened
(queue_tail x l)
(fun tail -> llist_fragment_tail l (cllist_head x) `star` vptr (cllist_tail x) `star` vptr tail)
(fun h -> True)
(fun _ tail h ->
sel_llist_fragment_tail l (cllist_head x) h == Ghost.reveal tail /\
sel (cllist_tail x) h == Ghost.reveal tail /\
ccell_ptrvalue_is_null (h (vptr tail))
)
let elim_queue_tail
#_ #a x l
=
let tail0 = elim_vdep
(llist_fragment_tail l (cllist_head x))
(queue_tail_dep1 x l)
in
let tail : Ghost.erased (ref (ccell_ptrvalue a)) = tail0 in
change_equal_slprop
(queue_tail_dep1 x l (Ghost.reveal tail0))
(vptr (cllist_tail x) `vdep` queue_tail_dep2 x l tail0);
let tail2 = elim_vdep
(vptr (cllist_tail x))
(queue_tail_dep2 x l tail0)
in
let tail3 : Ghost.erased (ref (ccell_ptrvalue a)) = tail2 in
change_equal_slprop
(queue_tail_dep2 x l tail0 (Ghost.reveal tail2))
(vptr tail3 `vrefine` queue_tail_refine tail0 tail3);
elim_vrefine (vptr tail3) (queue_tail_refine tail0 tail3);
change_equal_slprop
(vptr tail3)
(vptr tail);
tail
(* view from the head *)
let llist_fragment_head_data_refine
(#a: Type)
(d: a)
(c: vcell a)
: Tot prop
= c.vcell_data == d
let llist_fragment_head_payload
(#a: Type)
(head: ccell_ptrvalue a)
(d: a)
(llist_fragment_head: (ref (ccell_ptrvalue a) -> ccell_ptrvalue a -> Tot vprop))
(x: t_of (ccell_is_lvalue head `star` (ccell head `vrefine` llist_fragment_head_data_refine d)))
: Tot vprop
=
llist_fragment_head (ccell_next (fst x)) (snd x).vcell_next
let rec llist_fragment_head (#a: Type) (l: Ghost.erased (list a)) (phead: ref (ccell_ptrvalue a)) (head: ccell_ptrvalue a) : Tot vprop
(decreases (Ghost.reveal l))
=
if Nil? l
then vconst (phead, head)
else
vbind
(ccell_is_lvalue head `star` (ccell head `vrefine` llist_fragment_head_data_refine (L.hd (Ghost.reveal l))))
(ref (ccell_ptrvalue a) & ccell_ptrvalue a)
(llist_fragment_head_payload head (L.hd (Ghost.reveal l)) (llist_fragment_head (L.tl (Ghost.reveal l))))
let t_of_llist_fragment_head
(#a: Type) (l: Ghost.erased (list a)) (phead: ref (ccell_ptrvalue a)) (head: ccell_ptrvalue a)
: Lemma
(t_of (llist_fragment_head l phead head) == ref (ccell_ptrvalue a) & ccell_ptrvalue a)
= ()
unfold
let sel_llist_fragment_head
(#a:Type) (#p:vprop)
(l: Ghost.erased (list a)) (phead: ref (ccell_ptrvalue a)) (head: ccell_ptrvalue a)
(h: rmem p { FStar.Tactics.with_tactic selector_tactic (can_be_split p (llist_fragment_head l phead head) /\ True) })
: GTot (ref (ccell_ptrvalue a) & ccell_ptrvalue a)
=
coerce (h (llist_fragment_head l phead head)) (ref (ccell_ptrvalue a) & ccell_ptrvalue a)
val intro_llist_fragment_head_nil
(#opened: _)
(#a: Type)
(l: Ghost.erased (list a))
(phead: ref (ccell_ptrvalue a))
(head: ccell_ptrvalue a)
: SteelGhost unit opened
emp
(fun _ -> llist_fragment_head l phead head)
(fun _ -> Nil? l)
(fun _ _ h' -> sel_llist_fragment_head l phead head h' == (phead, head))
let intro_llist_fragment_head_nil
l phead head
=
intro_vconst (phead, head);
change_equal_slprop
(vconst (phead, head))
(llist_fragment_head l phead head)
val elim_llist_fragment_head_nil
(#opened: _)
(#a: Type)
(l: Ghost.erased (list a))
(phead: ref (ccell_ptrvalue a))
(head: ccell_ptrvalue a)
: SteelGhost unit opened
(llist_fragment_head l phead head)
(fun _ -> emp)
(fun _ -> Nil? l)
(fun h _ _ -> sel_llist_fragment_head l phead head h == (phead, head))
let elim_llist_fragment_head_nil
l phead head
=
change_equal_slprop
(llist_fragment_head l phead head)
(vconst (phead, head));
elim_vconst (phead, head)
let llist_fragment_head_eq_cons
(#a: Type) (l: Ghost.erased (list a)) (phead: ref (ccell_ptrvalue a)) (head: ccell_ptrvalue a)
: Lemma
(requires (Cons? (Ghost.reveal l)))
(ensures (
llist_fragment_head l phead head ==
vbind
(ccell_is_lvalue head `star` (ccell head `vrefine` llist_fragment_head_data_refine (L.hd (Ghost.reveal l))))
(ref (ccell_ptrvalue a) & ccell_ptrvalue a)
(llist_fragment_head_payload head (L.hd (Ghost.reveal l)) (llist_fragment_head (L.tl (Ghost.reveal l))))
))
= assert_norm
(llist_fragment_head l phead head == (
if Nil? l
then vconst (phead, head)
else
vbind
(ccell_is_lvalue head `star` (ccell head `vrefine` llist_fragment_head_data_refine (L.hd (Ghost.reveal l))))
(ref (ccell_ptrvalue a) & ccell_ptrvalue a)
(llist_fragment_head_payload head (L.hd (Ghost.reveal l)) (llist_fragment_head (L.tl (Ghost.reveal l))))
))
val intro_llist_fragment_head_cons
(#opened: _)
(#a: Type) (phead: ref (ccell_ptrvalue a)) (head: ccell_lvalue a) (next: (ccell_ptrvalue a)) (tl: Ghost.erased (list a))
: SteelGhost (Ghost.erased (list a)) opened
(ccell head `star` llist_fragment_head tl (ccell_next head) next)
(fun res -> llist_fragment_head res phead head)
(fun h -> (h (ccell head)).vcell_next == next)
(fun h res h' ->
Ghost.reveal res == (h (ccell head)).vcell_data :: Ghost.reveal tl /\
h' (llist_fragment_head res phead head) == h (llist_fragment_head tl (ccell_next head) next)
)
let intro_llist_fragment_head_cons
#_ #a phead head next tl
=
let vc = gget (ccell head) in
let l' : (l' : Ghost.erased (list a) { Cons? l' }) = Ghost.hide (vc.vcell_data :: tl) in
intro_ccell_is_lvalue head;
intro_vrefine (ccell head) (llist_fragment_head_data_refine (L.hd l'));
intro_vbind
(ccell_is_lvalue head `star` (ccell head `vrefine` llist_fragment_head_data_refine (L.hd l')))
(llist_fragment_head tl (ccell_next head) next)
(ref (ccell_ptrvalue a) & ccell_ptrvalue a)
(llist_fragment_head_payload head (L.hd l') (llist_fragment_head (L.tl l')));
llist_fragment_head_eq_cons l' phead head;
change_equal_slprop
(vbind
(ccell_is_lvalue head `star` (ccell head `vrefine` llist_fragment_head_data_refine (L.hd l')))
(ref (ccell_ptrvalue a) & ccell_ptrvalue a)
(llist_fragment_head_payload head (L.hd l') (llist_fragment_head (L.tl l'))))
(llist_fragment_head l' phead head);
l'
[@@erasable]
noeq
type ll_uncons_t
(a: Type)
= {
ll_uncons_pnext: Ghost.erased (ref (ccell_ptrvalue a));
ll_uncons_next: Ghost.erased (ccell_ptrvalue a);
ll_uncons_tl: Ghost.erased (list a);
}
val elim_llist_fragment_head_cons
(#opened: _)
(#a: Type)
(l: Ghost.erased (list a))
(phead: ref (ccell_ptrvalue a))
(head: ccell_ptrvalue a)
: SteelGhost (ll_uncons_t a) opened
(llist_fragment_head l phead head)
(fun res -> ccell head `star` llist_fragment_head res.ll_uncons_tl res.ll_uncons_pnext res.ll_uncons_next)
(fun _ -> Cons? (Ghost.reveal l))
(fun h res h' ->
ccell_ptrvalue_is_null head == false /\
Ghost.reveal l == (h' (ccell head)).vcell_data :: Ghost.reveal res.ll_uncons_tl /\
Ghost.reveal res.ll_uncons_pnext == ccell_next head /\
Ghost.reveal res.ll_uncons_next == (h' (ccell head)).vcell_next /\
h' (llist_fragment_head res.ll_uncons_tl res.ll_uncons_pnext res.ll_uncons_next) == h (llist_fragment_head l phead head)
)
let elim_llist_fragment_head_cons
#_ #a l0 phead head
=
let l : (l : Ghost.erased (list a) { Cons? l }) = l0 in
change_equal_slprop
(llist_fragment_head l0 phead head)
(llist_fragment_head l phead head);
llist_fragment_head_eq_cons l phead head;
change_equal_slprop
(llist_fragment_head l phead head)
(vbind
(ccell_is_lvalue head `star` (ccell head `vrefine` llist_fragment_head_data_refine (L.hd l)))
(ref (ccell_ptrvalue a) & ccell_ptrvalue a)
(llist_fragment_head_payload head (L.hd l) (llist_fragment_head (L.tl l))));
let x = elim_vbind
(ccell_is_lvalue head `star` (ccell head `vrefine` llist_fragment_head_data_refine (L.hd l)))
(ref (ccell_ptrvalue a) & ccell_ptrvalue a)
(llist_fragment_head_payload head (L.hd l) (llist_fragment_head (L.tl l)))
in
let head2 = gget (ccell_is_lvalue head) in
elim_ccell_is_lvalue head;
elim_vrefine (ccell head) (llist_fragment_head_data_refine (L.hd l));
let vhead2 = gget (ccell head) in
let res = {
ll_uncons_pnext = ccell_next head2;
ll_uncons_next = vhead2.vcell_next;
ll_uncons_tl = L.tl l;
} in
change_equal_slprop
(llist_fragment_head_payload head (L.hd l) (llist_fragment_head (L.tl l)) (Ghost.reveal x))
(llist_fragment_head res.ll_uncons_tl res.ll_uncons_pnext res.ll_uncons_next);
res
let rec llist_fragment_head_append
(#opened: _)
(#a: Type)
(l1: Ghost.erased (list a))
(phead1: ref (ccell_ptrvalue a))
(head1: ccell_ptrvalue a)
(l2: Ghost.erased (list a))
(phead2: ref (ccell_ptrvalue a))
(head2: ccell_ptrvalue a)
: SteelGhost (Ghost.erased (list a)) opened
(llist_fragment_head l1 phead1 head1 `star` llist_fragment_head l2 phead2 head2)
(fun l -> llist_fragment_head l phead1 head1)
(fun h -> sel_llist_fragment_head l1 phead1 head1 h == (Ghost.reveal phead2, Ghost.reveal head2))
(fun h l h' ->
Ghost.reveal l == Ghost.reveal l1 `L.append` Ghost.reveal l2 /\
h' (llist_fragment_head l phead1 head1) == h (llist_fragment_head l2 phead2 head2)
)
(decreases (Ghost.reveal l1))
=
if Nil? l1
then begin
elim_llist_fragment_head_nil l1 phead1 head1;
change_equal_slprop
(llist_fragment_head l2 phead2 head2)
(llist_fragment_head l2 phead1 head1);
l2
end else begin
let u = elim_llist_fragment_head_cons l1 phead1 head1 in
let head1' : Ghost.erased (ccell_lvalue a) = head1 in
let l3 = llist_fragment_head_append u.ll_uncons_tl u.ll_uncons_pnext u.ll_uncons_next l2 phead2 head2 in
change_equal_slprop
(llist_fragment_head l3 u.ll_uncons_pnext u.ll_uncons_next)
(llist_fragment_head l3 (ccell_next head1') u.ll_uncons_next);
change_equal_slprop
(ccell head1)
(ccell head1');
let l4 = intro_llist_fragment_head_cons phead1 head1' u.ll_uncons_next l3 in
change_equal_slprop
(llist_fragment_head l4 phead1 head1')
(llist_fragment_head l4 phead1 head1);
l4
end
let rec llist_fragment_head_to_tail
(#opened: _)
(#a: Type)
(l: Ghost.erased (list a))
(phead: ref (ccell_ptrvalue a))
(head: ccell_ptrvalue a)
: SteelGhost (Ghost.erased (ref (ccell_ptrvalue a))) opened
(vptr phead `star` llist_fragment_head l phead head)
(fun res -> llist_fragment_tail l phead `star` vptr res)
(fun h -> h (vptr phead) == head)
(fun h res h' ->
let v = sel_llist_fragment_head l phead head h in
fst v == Ghost.reveal res /\
fst v == sel_llist_fragment_tail l phead h' /\
snd v == h' (vptr res)
)
(decreases (L.length (Ghost.reveal l)))
=
if Nil? l
then begin
let ptail = Ghost.hide phead in
let gh = gget (vptr phead) in
assert (Ghost.reveal gh == head);
elim_llist_fragment_head_nil l phead head;
intro_llist_fragment_tail_nil l phead;
change_equal_slprop
(vptr phead)
(vptr ptail);
ptail
end else begin
intro_llist_fragment_tail_nil [] phead;
change_equal_slprop
(vptr phead)
(vptr (Ghost.reveal (Ghost.hide phead)));
let uc = elim_llist_fragment_head_cons l phead head in
let head' = elim_ccell_ghost head in
change_equal_slprop
(vptr (ccell_next head'))
(vptr uc.ll_uncons_pnext);
let lc = intro_llist_fragment_tail_snoc [] phead phead head' in
let ptail = llist_fragment_head_to_tail
uc.ll_uncons_tl
uc.ll_uncons_pnext
uc.ll_uncons_next
in
let l' = llist_fragment_tail_append phead lc uc.ll_uncons_pnext uc.ll_uncons_tl in
change_equal_slprop
(llist_fragment_tail l' phead)
(llist_fragment_tail l phead);
ptail
end
#push-options "--z3rlimit 16"
#restart-solver
let rec llist_fragment_tail_to_head
(#opened: _)
(#a: Type)
(l: Ghost.erased (list a))
(phead: ref (ccell_ptrvalue a))
(ptail: ref (ccell_ptrvalue a))
: SteelGhost (Ghost.erased (ccell_ptrvalue a)) opened
(llist_fragment_tail l phead `star` vptr ptail)
(fun head -> vptr phead `star` llist_fragment_head l phead (Ghost.reveal head))
(fun h -> Ghost.reveal ptail == sel_llist_fragment_tail l phead h)
(fun h head h' ->
let v = sel_llist_fragment_head l phead head h' in
fst v == ptail /\
snd v == h (vptr ptail) /\
h' (vptr phead) == Ghost.reveal head
)
(decreases (L.length (Ghost.reveal l)))
=
if Nil? l
then begin
let g = gget (llist_fragment_tail l phead) in
assert (Ghost.reveal g == ptail);
elim_llist_fragment_tail_nil l phead;
change_equal_slprop
(vptr ptail)
(vptr phead);
let head = gget (vptr phead) in
intro_llist_fragment_head_nil l phead head;
head
end else begin
let us = elim_llist_fragment_tail_snoc l phead in
let tail = gget (vptr ptail) in
assert (ccell_next us.ll_unsnoc_tail == ptail);
intro_llist_fragment_head_nil [] (ccell_next us.ll_unsnoc_tail) tail;
change_equal_slprop
(vptr ptail)
(vptr (ccell_next us.ll_unsnoc_tail));
intro_ccell us.ll_unsnoc_tail;
let lc = intro_llist_fragment_head_cons us.ll_unsnoc_ptail us.ll_unsnoc_tail tail [] in
let head = llist_fragment_tail_to_head us.ll_unsnoc_l phead us.ll_unsnoc_ptail in
let g = gget (llist_fragment_head us.ll_unsnoc_l phead head) in
let g : Ghost.erased (ref (ccell_ptrvalue a) & ccell_ptrvalue a) = Ghost.hide (Ghost.reveal g) in
assert (Ghost.reveal g == (Ghost.reveal us.ll_unsnoc_ptail, Ghost.reveal us.ll_unsnoc_tail));
let l' = llist_fragment_head_append us.ll_unsnoc_l phead head lc us.ll_unsnoc_ptail us.ll_unsnoc_tail in
change_equal_slprop
(llist_fragment_head l' phead head)
(llist_fragment_head l phead head);
head
end
#pop-options
val llist_fragment_head_is_nil
(#opened: _)
(#a: Type)
(l: Ghost.erased (list a))
(phead: ref (ccell_ptrvalue a))
(head: ccell_ptrvalue a)
: SteelGhost unit opened
(llist_fragment_head l phead head)
(fun _ -> llist_fragment_head l phead head)
(fun h -> ccell_ptrvalue_is_null (snd (sel_llist_fragment_head l phead head h)) == true)
(fun h _ h' ->
Nil? l == ccell_ptrvalue_is_null head /\
h' (llist_fragment_head l phead head) == h (llist_fragment_head l phead head)
)
let llist_fragment_head_is_nil
l phead head
=
if Nil? l
then begin
elim_llist_fragment_head_nil l phead head;
assert (ccell_ptrvalue_is_null head == true);
intro_llist_fragment_head_nil l phead head
end else begin
let r = elim_llist_fragment_head_cons l phead head in
let head2 : ccell_lvalue _ = head in
change_equal_slprop
(llist_fragment_head r.ll_uncons_tl r.ll_uncons_pnext r.ll_uncons_next)
(llist_fragment_head r.ll_uncons_tl (ccell_next head2) r.ll_uncons_next);
change_equal_slprop
(ccell head)
(ccell head2);
let l' = intro_llist_fragment_head_cons phead head2 r.ll_uncons_next r.ll_uncons_tl in
change_equal_slprop
(llist_fragment_head l' phead head2)
(llist_fragment_head l phead head)
end
val llist_fragment_head_cons_change_phead
(#opened: _)
(#a: Type)
(l: Ghost.erased (list a))
(phead: ref (ccell_ptrvalue a))
(head: ccell_ptrvalue a)
(phead' : ref (ccell_ptrvalue a))
: SteelGhost unit opened
(llist_fragment_head l phead head)
(fun _ -> llist_fragment_head l phead' head)
(fun _ -> Cons? l)
(fun h _ h' -> h' (llist_fragment_head l phead' head) == h (llist_fragment_head l phead head))
let llist_fragment_head_cons_change_phead
l phead head phead'
=
let u = elim_llist_fragment_head_cons l phead head in
let head2 : ccell_lvalue _ = head in
change_equal_slprop
(ccell head)
(ccell head2);
change_equal_slprop
(llist_fragment_head u.ll_uncons_tl u.ll_uncons_pnext u.ll_uncons_next)
(llist_fragment_head u.ll_uncons_tl (ccell_next head2) u.ll_uncons_next);
let l' = intro_llist_fragment_head_cons phead' head2 u.ll_uncons_next u.ll_uncons_tl in
change_equal_slprop
(llist_fragment_head l' phead' head2)
(llist_fragment_head l phead' head)
let queue_head_refine
(#a: Type)
(x: t a)
(l: Ghost.erased (list a))
(hd: ccell_ptrvalue a)
(ptl: t_of (llist_fragment_head l (cllist_head x) hd))
(tl: ref (ccell_ptrvalue a))
: Tot prop
= let ptl : (ref (ccell_ptrvalue a) & ccell_ptrvalue a) = ptl in
tl == fst ptl /\ ccell_ptrvalue_is_null (snd ptl) == true
let queue_head_dep1
(#a: Type)
(x: t a)
(l: Ghost.erased (list a))
(hd: ccell_ptrvalue a)
(ptl: t_of (llist_fragment_head l (cllist_head x) hd))
: Tot vprop
= vptr (cllist_tail x) `vrefine` queue_head_refine x l hd ptl
let queue_head_dep2
(#a: Type)
(x: t a)
(l: Ghost.erased (list a))
(hd: ccell_ptrvalue a)
: Tot vprop
= llist_fragment_head l (cllist_head x) hd `vdep` queue_head_dep1 x l hd
[@@__reduce__]
let queue_head
(#a: Type)
(x: t a)
(l: Ghost.erased (list a))
: Tot vprop
= vptr (cllist_head x) `vdep` queue_head_dep2 x l
val intro_queue_head
(#opened: _)
(#a: Type)
(x: t a)
(l: Ghost.erased (list a))
(hd: Ghost.erased (ccell_ptrvalue a))
: SteelGhost unit opened
(vptr (cllist_head x) `star` llist_fragment_head l (cllist_head x) hd `star` vptr (cllist_tail x))
(fun _ -> queue_head x l)
(fun h -> (
let frag = (sel_llist_fragment_head l (cllist_head x) hd) h in
sel (cllist_head x) h == Ghost.reveal hd /\
sel (cllist_tail x) h == fst frag /\
ccell_ptrvalue_is_null (snd frag) == true
))
(fun _ _ _ -> True)
let intro_queue_head
#_ #a x l hd
=
let ptl = gget (llist_fragment_head l (cllist_head x) hd) in
intro_vrefine
(vptr (cllist_tail x))
(queue_head_refine x l hd ptl);
assert_norm (vptr (cllist_tail x) `vrefine` queue_head_refine x l hd ptl == queue_head_dep1 x l hd ptl);
intro_vdep
(llist_fragment_head l (cllist_head x) hd)
(vptr (cllist_tail x) `vrefine` queue_head_refine x l hd ptl)
(queue_head_dep1 x l hd);
intro_vdep
(vptr (cllist_head x))
(llist_fragment_head l (cllist_head x) hd `vdep` queue_head_dep1 x l hd)
(queue_head_dep2 x l)
val elim_queue_head
(#opened: _)
(#a: Type)
(x: t a)
(l: Ghost.erased (list a))
: SteelGhost (Ghost.erased (ccell_ptrvalue a)) opened
(queue_head x l)
(fun hd -> vptr (cllist_head x) `star` llist_fragment_head l (cllist_head x) hd `star` vptr (cllist_tail x))
(fun _ -> True)
(fun _ hd h -> (
let frag = (sel_llist_fragment_head l (cllist_head x) hd) h in
sel (cllist_head x) h == Ghost.reveal hd /\
sel (cllist_tail x) h == fst frag /\
ccell_ptrvalue_is_null (snd frag) == true
)) | {
"checked_file": "/",
"dependencies": [
"Steel.Memory.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"CQueue.LList.fsti.checked"
],
"interface_file": true,
"source_file": "CQueue.fst"
} | [
{
"abbrev": false,
"full_module": "CQueue.LList",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"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": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: CQueue.t a -> l: FStar.Ghost.erased (Prims.list a)
-> Steel.Effect.Atomic.SteelGhost (FStar.Ghost.erased (CQueue.Cell.ccell_ptrvalue a)) | Steel.Effect.Atomic.SteelGhost | [] | [] | [
"Steel.Memory.inames",
"CQueue.t",
"FStar.Ghost.erased",
"Prims.list",
"CQueue.Cell.ccell_ptrvalue",
"Prims.unit",
"Steel.Effect.Atomic.elim_vrefine",
"Steel.Reference.vptr",
"Steel.Reference.ref",
"CQueue.LList.cllist_tail",
"CQueue.queue_head_refine",
"FStar.Ghost.reveal",
"Steel.Effect.Common.t_of",
"CQueue.LList.cllist_head",
"CQueue.llist_fragment_head",
"Steel.Effect.Common.VUnit",
"Steel.Reference.vptr'",
"Steel.FractionalPermission.full_perm",
"Steel.Effect.Atomic.elim_vdep",
"CQueue.queue_head_dep1",
"CQueue.queue_head_dep2"
] | [] | false | true | false | false | false | let elim_queue_head #_ #a x l =
| let hd = elim_vdep (vptr (cllist_head x)) (queue_head_dep2 x l) in
let ptl = elim_vdep (llist_fragment_head l (cllist_head x) hd) (queue_head_dep1 x l hd) in
elim_vrefine (vptr (cllist_tail x)) (queue_head_refine x l hd ptl);
hd | false |
Steel.ST.Array.fst | Steel.ST.Array.pts_to_range_split | val pts_to_range_split
(#opened: _)
(#elt: Type0)
(#p: P.perm)
(#s: Seq.seq elt)
(a: array elt)
(i m j: nat)
: STGhost unit opened
(pts_to_range a i j p s)
(fun _ -> exists_ (fun s1 -> exists_ (fun s2 ->
pts_to_range a i m p s1 `star`
pts_to_range a m j p s2 `star`
pure (
i <= m /\ m <= j /\ j <= length a /\
Seq.length s == j - i /\
s1 == Seq.slice s 0 (m - i) /\
s2 == Seq.slice s (m - i) (Seq.length s) /\
s == Seq.append s1 s2
))))
(i <= m /\ m <= j)
(fun _ -> True) | val pts_to_range_split
(#opened: _)
(#elt: Type0)
(#p: P.perm)
(#s: Seq.seq elt)
(a: array elt)
(i m j: nat)
: STGhost unit opened
(pts_to_range a i j p s)
(fun _ -> exists_ (fun s1 -> exists_ (fun s2 ->
pts_to_range a i m p s1 `star`
pts_to_range a m j p s2 `star`
pure (
i <= m /\ m <= j /\ j <= length a /\
Seq.length s == j - i /\
s1 == Seq.slice s 0 (m - i) /\
s2 == Seq.slice s (m - i) (Seq.length s) /\
s == Seq.append s1 s2
))))
(i <= m /\ m <= j)
(fun _ -> True) | let pts_to_range_split
#_ #_ #p #s a i m j
= length_fits a;
pts_to_range_prop a i j p s;
let a' = pts_to_range_elim' a i j p s in
let mi = US.uint_to_t (m - i) in
ptr_shift_add (ptr_of a) (US.uint_to_t i) mi;
let _ = ghost_split a' mi in
pts_to_range_intro' a m j p (split_r a' mi) _;
pts_to_range_intro' a i m p (split_l a' mi) _;
noop () | {
"file_name": "lib/steel/Steel.ST.Array.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 9,
"end_line": 645,
"start_col": 0,
"start_line": 635
} | (*
Copyright 2020, 2021, 2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.ST.Array
module US = FStar.SizeT
/// Lifting a value of universe 0 to universe 1. We use
/// FStar.Universe, since FStar.Extraction.Krml is set to extract
/// those functions to identity.
inline_for_extraction
[@@ noextract_to "krml"]
let raise_t (t: Type0) : Type u#1 = FStar.Universe.raise_t t
inline_for_extraction
[@@noextract_to "krml"]
let raise (#t: Type) (x: t) : Tot (raise_t t) =
FStar.Universe.raise_val x
inline_for_extraction
[@@noextract_to "krml"]
let lower (#t: Type) (x: raise_t t) : Tot t =
FStar.Universe.downgrade_val x
/// A map operation on sequences. Here we only need Ghost versions,
/// because such sequences are only used in vprops or with their
/// selectors.
let rec seq_map
(#t: Type u#a)
(#t' : Type u#b)
(f: (t -> GTot t'))
(s: Seq.seq t)
: Ghost (Seq.seq t')
(requires True)
(ensures (fun s' ->
Seq.length s' == Seq.length s /\
(forall i . {:pattern (Seq.index s' i)} Seq.index s' i == f (Seq.index s i))
))
(decreases (Seq.length s))
= if Seq.length s = 0
then Seq.empty
else Seq.cons (f (Seq.index s 0)) (seq_map f (Seq.slice s 1 (Seq.length s)))
let seq_map_append
(#t: Type u#a)
(#t': Type u#b)
(f: (t -> GTot t'))
(s1 s2: Seq.seq t)
: Lemma
(seq_map f (s1 `Seq.append` s2) `Seq.equal` (seq_map f s1 `Seq.append` seq_map f s2))
= ()
let seq_map_raise_inj
(#elt: Type0)
(s1 s2: Seq.seq elt)
: Lemma
(requires (seq_map raise s1 == seq_map raise s2))
(ensures (s1 == s2))
[SMTPat (seq_map raise s1); SMTPat (seq_map raise s2)]
= assert (seq_map lower (seq_map raise s1) `Seq.equal` s1);
assert (seq_map lower (seq_map raise s2) `Seq.equal` s2)
/// Implementation of the interface
/// base, ptr, array, pts_to
module H = Steel.ST.HigherArray
let base_t elt = H.base_t (raise_t elt)
let base_len b = H.base_len b
let ptr elt = H.ptr (raise_t elt)
let null_ptr elt = H.null_ptr (raise_t elt)
let is_null_ptr p = H.is_null_ptr p
let base p = H.base p
let offset p = H.offset p
let ptr_base_offset_inj p1 p2 = H.ptr_base_offset_inj p1 p2
let base_len_null_ptr elt = H.base_len_null_ptr (raise_t elt)
let length_fits a = H.length_fits a
let pts_to a p s = H.pts_to a p (seq_map raise s)
let pts_to_length a s =
H.pts_to_length a _
let h_array_eq'
(#t: Type u#1)
(a1 a2: H.array t)
: Lemma
(requires (
dfst a1 == dfst a2 /\
(Ghost.reveal (dsnd a1) <: nat) == Ghost.reveal (dsnd a2)
))
(ensures (
a1 == a2
))
= ()
let pts_to_not_null #_ #t #p a s =
let _ = H.pts_to_not_null #_ #_ #p a (seq_map raise s) in
assert (a =!= H.null #(raise_t t));
Classical.move_requires (h_array_eq' a) (H.null #(raise_t t));
noop ()
let pts_to_inj a p1 s1 p2 s2 =
H.pts_to_inj a p1 (seq_map raise s1) p2 (seq_map raise s2)
/// Non-selector operations.
let malloc x n =
let res = H.malloc (raise x) n in
assert (seq_map raise (Seq.create (US.v n) x) `Seq.equal` Seq.create (US.v n) (raise x));
rewrite
(H.pts_to res _ _)
(pts_to res _ _);
return res
let free #_ x =
let s = elim_exists () in
rewrite
(pts_to x _ _)
(H.pts_to x P.full_perm (seq_map raise s));
H.free x
let share
#_ #_ #x a p p1 p2
= rewrite
(pts_to a _ _)
(H.pts_to a p (seq_map raise x));
H.share a p p1 p2;
rewrite
(H.pts_to a p1 _)
(pts_to a p1 x);
rewrite
(H.pts_to a p2 _)
(pts_to a p2 x)
let gather
#_ #_ a #x1 p1 #x2 p2
= rewrite
(pts_to a p1 _)
(H.pts_to a p1 (seq_map raise x1));
rewrite
(pts_to a p2 _)
(H.pts_to a p2 (seq_map raise x2));
H.gather a p1 p2;
rewrite
(H.pts_to a _ _)
(pts_to _ _ _)
let index #_ #p a #s i =
rewrite
(pts_to a _ _)
(H.pts_to a p (seq_map raise s));
let res = H.index a i in
rewrite
(H.pts_to _ _ _)
(pts_to _ _ _);
return (lower res)
let upd #_ a #s i v =
rewrite
(pts_to a _ _)
(H.pts_to a P.full_perm (seq_map raise s));
H.upd a i (raise v);
assert (seq_map raise (Seq.upd s (US.v i) v) `Seq.equal` Seq.upd (seq_map raise s) (US.v i) (raise v));
rewrite
(H.pts_to _ _ _)
(pts_to _ _ _)
let ghost_join
#_ #_ #x1 #x2 #p a1 a2 h
= rewrite
(pts_to a1 _ _)
(H.pts_to a1 p (seq_map raise x1));
rewrite
(pts_to a2 _ _)
(H.pts_to a2 p (seq_map raise x2));
H.ghost_join a1 a2 h;
assert (seq_map raise (x1 `Seq.append` x2) `Seq.equal` (seq_map raise x1 `Seq.append` seq_map raise x2));
rewrite
(H.pts_to _ _ _)
(H.pts_to (merge a1 a2) p (seq_map raise (x1 `Seq.append` x2)));
rewrite
(H.pts_to _ _ _)
(pts_to (merge a1 a2) _ _)
let ptr_shift p off = H.ptr_shift p off
let ghost_split
#_ #_ #x #p a i
=
rewrite
(pts_to a _ _)
(H.pts_to a p (seq_map raise x));
let _ = H.ghost_split a i in
//H.ghost_split a i;
assert (seq_map raise (Seq.slice x 0 (US.v i)) `Seq.equal` Seq.slice (seq_map raise x) 0 (US.v i));
rewrite
(H.pts_to (H.split_l a i) _ _)
(H.pts_to (split_l a i) p (seq_map raise (Seq.slice x 0 (US.v i))));
rewrite
(H.pts_to (split_l a i) _ _)
(pts_to (split_l a i) _ _);
assert (seq_map raise (Seq.slice x (US.v i) (Seq.length x)) `Seq.equal` Seq.slice (seq_map raise x) (US.v i) (Seq.length (seq_map raise x)));
Seq.lemma_split x (US.v i);
rewrite
(H.pts_to (H.split_r a i) _ _)
(H.pts_to (split_r a i) p (seq_map raise (Seq.slice x (US.v i) (Seq.length x))));
rewrite
(H.pts_to (split_r a i) _ _)
(pts_to (split_r a i) _ _)
let memcpy
a0 a1 l
=
H.memcpy a0 a1 l
////////////////////////////////////////////////////////////////////////////////
// compare
////////////////////////////////////////////////////////////////////////////////
module R = Steel.ST.Reference
#push-options "--fuel 0 --ifuel 1 --z3rlimit_factor 2"
let equal_up_to #t
(s0: Seq.seq t)
(s1: Seq.seq t)
(v : option US.t) : prop =
Seq.length s0 = Seq.length s1 /\
(match v with
| None -> Ghost.reveal s0 =!= Ghost.reveal s1
| Some v -> US.v v <= Seq.length s0 /\ Seq.slice s0 0 (US.v v) `Seq.equal` Seq.slice s1 0 (US.v v))
let within_bounds (x:option US.t) (l:US.t) (b:Ghost.erased bool) : prop =
if b then Some? x /\ US.(Some?.v x <^ l)
else None? x \/ US.(Some?.v x >=^ l)
let compare_inv (#t:eqtype) (#p0 #p1:perm)
(a0 a1:array t)
(s0: Seq.seq t)
(s1: Seq.seq t)
(l:US.t)
(ctr : R.ref (option US.t))
(b: bool) =
pts_to a0 p0 s0 `star`
pts_to a1 p1 s1 `star`
exists_ (fun (x:option US.t) ->
R.pts_to ctr Steel.FractionalPermission.full_perm x `star`
pure (equal_up_to s0 s1 x) `star`
pure (within_bounds x l b))
let elim_compare_inv #o
(#t:eqtype)
(#p0 #p1:perm)
(a0 a1:array t)
(#s0: Seq.seq t)
(#s1: Seq.seq t)
(l:US.t)
(ctr : R.ref (option US.t))
(b: bool)
: STGhostT (Ghost.erased (option US.t)) o
(compare_inv a0 a1 s0 s1 l ctr b)
(fun x ->
let open US in
pts_to a0 p0 s0 `star`
pts_to a1 p1 s1 `star`
R.pts_to ctr Steel.FractionalPermission.full_perm x `star`
pure (equal_up_to s0 s1 x) `star`
pure (within_bounds x l b))
= let open US in
assert_spinoff
((compare_inv #_ #p0 #p1 a0 a1 s0 s1 l ctr b) ==
(pts_to a0 p0 s0 `star`
pts_to a1 p1 s1 `star`
exists_ (fun (v:option US.t) ->
R.pts_to ctr Steel.FractionalPermission.full_perm v `star`
pure (equal_up_to s0 s1 v) `star`
pure (within_bounds v l b))));
rewrite
(compare_inv #_ #p0 #p1 a0 a1 s0 s1 l ctr b)
(pts_to a0 p0 s0 `star`
pts_to a1 p1 s1 `star`
exists_ (fun (v:option US.t) ->
R.pts_to ctr Steel.FractionalPermission.full_perm v `star`
pure (equal_up_to s0 s1 v) `star`
pure (within_bounds v l b)));
let _v = elim_exists () in
_v
let intro_compare_inv #o
(#t:eqtype)
(#p0 #p1:perm)
(a0 a1:array t)
(#s0: Seq.seq t)
(#s1: Seq.seq t)
(l:US.t)
(ctr : R.ref (option US.t))
(x: Ghost.erased (option US.t))
(b:bool { within_bounds x l b })
: STGhostT unit o
(let open US in
pts_to a0 p0 s0 `star`
pts_to a1 p1 s1 `star`
R.pts_to ctr Steel.FractionalPermission.full_perm x `star`
pure (equal_up_to s0 s1 x))
(fun _ -> compare_inv a0 a1 s0 s1 l ctr (Ghost.hide b))
= let open US in
intro_pure (within_bounds x l (Ghost.hide b));
intro_exists_erased x (fun (x:option US.t) ->
R.pts_to ctr Steel.FractionalPermission.full_perm x `star`
pure (equal_up_to s0 s1 x) `star`
pure (within_bounds x l (Ghost.hide b)));
assert_norm
((compare_inv #_ #p0 #p1 a0 a1 s0 s1 l ctr (Ghost.hide b)) ==
(pts_to a0 p0 s0 `star`
pts_to a1 p1 s1 `star`
exists_ (fun (v:option US.t) ->
R.pts_to ctr Steel.FractionalPermission.full_perm v `star`
pure (equal_up_to s0 s1 v) `star`
pure (within_bounds v l (Ghost.hide b)))));
rewrite
(pts_to a0 p0 s0 `star`
pts_to a1 p1 s1 `star`
exists_ (fun (v:option US.t) ->
R.pts_to ctr Steel.FractionalPermission.full_perm v `star`
pure (equal_up_to s0 s1 v) `star`
pure (within_bounds v l (Ghost.hide b))))
(compare_inv #_ #p0 #p1 a0 a1 s0 s1 l ctr (Ghost.hide b))
let intro_exists_compare_inv #o
(#t:eqtype)
(#p0 #p1:perm)
(a0 a1:array t)
(#s0: Seq.seq t)
(#s1: Seq.seq t)
(l:US.t)
(ctr : R.ref (option US.t))
(x: Ghost.erased (option US.t))
: STGhostT unit o
(let open US in
pts_to a0 p0 s0 `star`
pts_to a1 p1 s1 `star`
R.pts_to ctr Steel.FractionalPermission.full_perm x `star`
pure (equal_up_to s0 s1 x))
(fun _ -> exists_ (compare_inv #_ #p0 #p1 a0 a1 s0 s1 l ctr))
= let b : bool =
match Ghost.reveal x with
| None -> false
| Some x -> US.(x <^ l)
in
assert (within_bounds x l b);
intro_compare_inv #_ #_ #p0 #p1 a0 a1 #s0 #s1 l ctr x b;
intro_exists _ (compare_inv #_ #p0 #p1 a0 a1 s0 s1 l ctr)
let extend_equal_up_to_lemma (#t:Type0)
(s0:Seq.seq t)
(s1:Seq.seq t)
(i:nat{ i < Seq.length s0 /\ Seq.length s0 == Seq.length s1 })
: Lemma
(requires
Seq.equal (Seq.slice s0 0 i) (Seq.slice s1 0 i) /\
Seq.index s0 i == Seq.index s1 i)
(ensures
Seq.equal (Seq.slice s0 0 (i + 1)) (Seq.slice s1 0 (i + 1)))
= assert (forall k. k < i ==> Seq.index s0 k == Seq.index (Seq.slice s0 0 i) k /\
Seq.index s1 k == Seq.index (Seq.slice s1 0 i) k)
let extend_equal_up_to (#o:_)
(#t:Type0)
(#s0:Seq.seq t)
(#s1:Seq.seq t)
(len:US.t)
(i:US.t{ Seq.length s0 == Seq.length s1 /\ US.(i <^ len) /\ US.v len == Seq.length s0 } )
: STGhost unit o
(pure (equal_up_to s0 s1 (Some i)))
(fun _ -> pure (equal_up_to s0 s1 (Some US.(i +^ 1sz))))
(requires
Seq.index s0 (US.v i) == Seq.index s1 (US.v i))
(ensures fun _ -> True)
= elim_pure _;
extend_equal_up_to_lemma s0 s1 (US.v i);
intro_pure (equal_up_to s0 s1 (Some US.(i +^ 1sz)))
let extend_equal_up_to_neg (#o:_)
(#t:Type0)
(#s0:Seq.seq t)
(#s1:Seq.seq t)
(len:US.t)
(i:US.t{ Seq.length s0 == Seq.length s1 /\ US.(i <^ len) /\ US.v len == Seq.length s0 } )
: STGhost unit o
(pure (equal_up_to s0 s1 (Some i)))
(fun _ -> pure (equal_up_to s0 s1 None))
(requires
Seq.index s0 (US.v i) =!= Seq.index s1 (US.v i))
(ensures fun _ -> True)
= elim_pure _;
intro_pure _
let init_compare_inv #o
(#t:eqtype)
(#p0 #p1:perm)
(a0 a1:array t)
(#s0: Seq.seq t)
(#s1: Seq.seq t)
(l:US.t)
(ctr : R.ref (option US.t))
: STGhost unit o
(let open US in
pts_to a0 p0 s0 `star`
pts_to a1 p1 s1 `star`
R.pts_to ctr Steel.FractionalPermission.full_perm (Some 0sz))
(fun _ -> exists_ (compare_inv #_ #p0 #p1 a0 a1 s0 s1 l ctr))
(requires (
length a0 > 0 /\
length a0 == length a1 /\
US.v l == length a0
))
(ensures (fun _ -> True))
= pts_to_length a0 _;
pts_to_length a1 _;
intro_pure (equal_up_to s0 s1 (Ghost.hide (Some 0sz)));
rewrite
(R.pts_to ctr Steel.FractionalPermission.full_perm (Some 0sz))
(R.pts_to ctr Steel.FractionalPermission.full_perm (Ghost.hide (Some 0sz)));
intro_exists_compare_inv a0 a1 l ctr (Ghost.hide (Some 0sz))
let compare_pts
(#t:eqtype)
(#p0 #p1:perm)
(a0 a1:array t)
(#s0: Ghost.erased (Seq.seq t))
(#s1: Ghost.erased (Seq.seq t))
(l:US.t)
: ST bool
(pts_to a0 p0 s0 `star` pts_to a1 p1 s1)
(fun _ -> pts_to a0 p0 s0 `star` pts_to a1 p1 s1)
(requires
length a0 > 0 /\ length a0 == length a1 /\ US.v l == length a0
)
(ensures fun b ->
b = (Ghost.reveal s0 = Ghost.reveal s1))
=
pts_to_length a0 _;
pts_to_length a1 _;
let ctr = R.alloc (Some 0sz) in
let cond ()
: STT bool
(exists_ (compare_inv #_ #p0 #p1 a0 a1 s0 s1 l ctr))
(fun b -> compare_inv #_ #p0 #p1 a0 a1 s0 s1 l ctr (Ghost.hide b))
= let _b = elim_exists () in
let _ = elim_compare_inv _ _ _ _ _ in
let x = R.read ctr in
elim_pure (within_bounds _ _ _);
match x with
| None ->
intro_compare_inv #_ #_ #p0 #p1 a0 a1 l ctr _ false;
return false
| Some x ->
let res = US.(x <^ l) in
intro_compare_inv #_ #_ #p0 #p1 a0 a1 l ctr _ res;
return res
in
let body ()
: STT unit
(compare_inv #_ #p0 #p1 a0 a1 s0 s1 l ctr (Ghost.hide true))
(fun _ -> exists_ (compare_inv #_ #p0 #p1 a0 a1 s0 s1 l ctr))
= let _i = elim_compare_inv _ _ _ _ _ in
elim_pure (within_bounds _ _ _);
let Some i = R.read ctr in
assert_spinoff
((pure (equal_up_to s0 s1 _i)) ==
(pure (equal_up_to s0 s1 (Some i))));
rewrite
(pure (equal_up_to s0 s1 _i))
(pure (equal_up_to s0 s1 (Some i)));
let v0 = index a0 i in
let v1 = index a1 i in
if v0 = v1
then (
R.write ctr (Some US.(i +^ 1sz));
extend_equal_up_to l i;
intro_exists_compare_inv #_ #_ #p0 #p1 a0 a1 l ctr (Ghost.hide (Some (US.(i +^ 1sz))))
)
else (
R.write ctr None;
extend_equal_up_to_neg l i;
intro_exists_compare_inv #_ #_ #p0 #p1 a0 a1 l ctr (Ghost.hide None)
)
in
init_compare_inv a0 a1 l ctr;
Steel.ST.Loops.while_loop (compare_inv #_ #p0 #p1 a0 a1 s0 s1 l ctr)
cond
body;
let _ = elim_compare_inv _ _ _ _ _ in
elim_pure (equal_up_to _ _ _);
let v = R.read ctr in
R.free ctr;
elim_pure (within_bounds _ _ _);
match v with
| None -> return false
| Some _ -> return true
let compare
#t #p0 #p1 a0 a1 #s0 #s1 l
=
pts_to_length a0 _;
pts_to_length a1 _;
if l = 0sz
then (
assert (Seq.equal s0 s1);
return true
)
else (
compare_pts a0 a1 l
)
#pop-options
let intro_fits_u32 () = H.intro_fits_u32 ()
let intro_fits_u64 () = H.intro_fits_u64 ()
let intro_fits_ptrdiff32 () = H.intro_fits_ptrdiff32 ()
let intro_fits_ptrdiff64 () = H.intro_fits_ptrdiff64 ()
let ptrdiff #_ #p0 #p1 #s0 #s1 a0 a1 =
rewrite
(pts_to a0 _ _)
(H.pts_to a0 p0 (seq_map raise s0));
rewrite
(pts_to a1 _ _)
(H.pts_to a1 p1 (seq_map raise s1));
let res = H.ptrdiff a0 a1 in
rewrite
(H.pts_to a1 _ _)
(pts_to a1 _ _);
rewrite
(H.pts_to a0 _ _)
(pts_to a0 _ _);
return res
let array_slice
(#elt: Type0)
(a: array elt)
(i j: nat)
(sq: squash (i <= j /\ j <= length a))
: Ghost (array elt)
(requires True)
(ensures (fun a' -> length a' == j - i))
= length_fits a;
split_l (split_r a (US.uint_to_t i)) (US.uint_to_t (j - i))
[@@__reduce__]
let pts_to_range_body
(#elt: Type0) (a: array elt) (i j: nat)
(p: P.perm)
(s: Seq.seq elt)
(sq: squash (i <= j /\ j <= length a))
: Tot vprop
= pts_to (array_slice a i j sq) p s
let pts_to_range
(#elt: Type0) (a: array elt) (i j: nat)
(p: P.perm)
([@@@ smt_fallback ] s: Seq.seq elt)
: Tot vprop
= exists_ (pts_to_range_body a i j p s)
let pts_to_range_intro'
(#opened: _)
(#elt: Type0) (a: array elt) (i j: nat)
(p: P.perm)
(a': array elt)
(s: Seq.seq elt)
: STGhost unit opened
(pts_to a' p s)
(fun _ -> pts_to_range a i j p s)
(i <= j /\ j <= length a /\
a' == array_slice a i j ()
)
(fun _ -> True)
= let sq : squash (i <= j /\ j <= length a) = () in
rewrite (pts_to a' p s) (pts_to (array_slice a i j sq) p s);
rewrite (exists_ (pts_to_range_body a i j p s)) (pts_to_range a i j p s)
let pts_to_range_elim'
(#opened: _)
(#elt: Type0) (a: array elt) (i j: nat)
(p: P.perm)
(s: Seq.seq elt)
: STGhost (Ghost.erased (array elt)) opened
(pts_to_range a i j p s)
(fun a' -> pts_to a' p s)
True
(fun a' -> i <= j /\ j <= length a /\
Ghost.reveal a' == array_slice a i j ()
)
= rewrite (pts_to_range a i j p s) (exists_ (pts_to_range_body a i j p s));
let _ = elim_exists () in
vpattern_replace_erased (fun a' -> pts_to a' p s)
let pts_to_range_prop
a i j p s
= let a' = pts_to_range_elim' a i j p s in
pts_to_length a' s;
pts_to_range_intro' a i j p a' s
let pts_to_range_intro
a p s
= ptr_shift_zero (ptr_of a);
pts_to_range_intro' a 0 (length a) p a s
let pts_to_range_elim
a p s
= ptr_shift_zero (ptr_of a);
let a' = pts_to_range_elim' a 0 (length a) p s in
vpattern_rewrite (fun a' -> pts_to a' _ _) a | {
"checked_file": "/",
"dependencies": [
"Steel.ST.Reference.fsti.checked",
"Steel.ST.Loops.fsti.checked",
"Steel.ST.HigherArray.fsti.checked",
"Steel.FractionalPermission.fst.checked",
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.ST.Array.fst"
} | [
{
"abbrev": true,
"full_module": "Steel.ST.Reference",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "Steel.ST.HigherArray",
"short_module": "H"
},
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "US"
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.PtrdiffT",
"short_module": "UP"
},
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "US"
},
{
"abbrev": true,
"full_module": "Steel.FractionalPermission",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Steel.ST.Array.array elt -> i: Prims.nat -> m: Prims.nat -> j: Prims.nat
-> Steel.ST.Effect.Ghost.STGhost Prims.unit | Steel.ST.Effect.Ghost.STGhost | [] | [] | [
"Steel.Memory.inames",
"Steel.FractionalPermission.perm",
"FStar.Seq.Base.seq",
"Steel.ST.Array.array",
"Prims.nat",
"Steel.ST.Util.noop",
"Prims.unit",
"Steel.ST.Array.pts_to_range_intro'",
"Steel.ST.Array.split_l",
"FStar.Ghost.reveal",
"FStar.Ghost.hide",
"FStar.SizeT.t",
"FStar.Seq.Base.slice",
"FStar.SizeT.v",
"Steel.ST.Array.split_r",
"FStar.Seq.Base.length",
"Prims.squash",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Steel.ST.Array.length",
"Steel.ST.Array.ghost_split",
"Steel.ST.Array.ptr_shift_add",
"Steel.ST.Array.ptr_of",
"FStar.SizeT.uint_to_t",
"Prims.op_Subtraction",
"FStar.Ghost.erased",
"Steel.ST.Array.pts_to_range_elim'",
"Steel.ST.Array.pts_to_range_prop",
"Steel.ST.Array.length_fits"
] | [] | false | true | false | false | false | let pts_to_range_split #_ #_ #p #s a i m j =
| length_fits a;
pts_to_range_prop a i j p s;
let a' = pts_to_range_elim' a i j p s in
let mi = US.uint_to_t (m - i) in
ptr_shift_add (ptr_of a) (US.uint_to_t i) mi;
let _ = ghost_split a' mi in
pts_to_range_intro' a m j p (split_r a' mi) _;
pts_to_range_intro' a i m p (split_l a' mi) _;
noop () | false |
Vale.Poly1305.Bitvectors.fst | Vale.Poly1305.Bitvectors.bv128_64_64 | val bv128_64_64: x1:bv_t 64 -> x0:bv_t 64 -> Tot (bv_t 128) | val bv128_64_64: x1:bv_t 64 -> x0:bv_t 64 -> Tot (bv_t 128) | let bv128_64_64 x0 x1 = bvor (bvshl (bv_uext #64 #64 x1) 64) (bv_uext #64 #64 x0) | {
"file_name": "vale/code/crypto/poly1305/x64/Vale.Poly1305.Bitvectors.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 81,
"end_line": 77,
"start_col": 0,
"start_line": 77
} | module Vale.Poly1305.Bitvectors
open FStar.BV
open FStar.Tactics
open FStar.Tactics.Derived
open FStar.Tactics.BV
open FStar.Mul
open FStar.UInt
open FStar.Math.Lemmas
open Vale.Lib.Tactics
open Vale.Lib.Bv_s
open Vale.Math.Bits
// tweak options?
#reset-options "--smtencoding.elim_box true"
//NOTE: Using the split tactic seems to slowdown execution by a lot.
let lemma_shr2 x =
assert_by_tactic (shift_right #64 x 2 == udiv #64 x 4) bv_tac
let lemma_shr4 x =
assert_by_tactic (shift_right #64 x 4 == udiv #64 x 16) bv_tac
let lemma_and_mod_n x =
assert_by_tactic (logand #64 x 3 == mod #64 x 4) (bv_tac);
assert_by_tactic (logand #64 x 15 == mod #64 x 16) (bv_tac)
let lemma_clear_lower_2 x =
assert_by_tactic
(logand #64 x 0xfffffffffffffffc == mul_mod #64 (udiv #64 x 4) 4)
bv_tac
let lemma_and_constants x =
assert_by_tactic (logand #64 x 0 == (0 <: uint_t 64)) bv_tac;
assert_by_tactic (logand #64 x 0xffffffffffffffff == x) bv_tac
let lemma_poly_constants x =
// using split in this seems to hang execution.
assert_by_tactic
(logand #64 x 0x0ffffffc0fffffff < (0x1000000000000000 <: uint_t 64))
(fun () -> bv_tac_lt 64);
assert_by_tactic
(logand #64 x 0x0ffffffc0ffffffc < (0x1000000000000000 <: uint_t 64))
(fun () -> bv_tac_lt 64);
assert_by_tactic
(mod #64 (logand #64 x 0x0ffffffc0ffffffc) 4 == (0 <: uint_t 64))
(fun () -> bv_tac ())
let lemma_and_commutes x y =
assert_by_tactic
(logand #64 x y == logand #64 y x)
bv_tac
let lemma_bv128_64_64_and_helper' (x0:bv_t 64) (x1:bv_t 64) (y0:bv_t 64) (y1:bv_t 64) :
Lemma (requires True)
(ensures ((bvor #128 (bvshl #128 (bv_uext #64 #64 (bvand #64 x1 y1)) 64)
(bv_uext #64 #64 (bvand #64 x0 y0))) ==
bvand #128 (bvor #128 (bvshl #128 (bv_uext #64 #64 x1) 64)
(bv_uext #64 #64 x0))
(bvor #128 (bvshl #128 (bv_uext #64 #64 y1) 64)
(bv_uext #64 #64 y0)))) = ()
// Rewrite all equalities and then the goal is trivial for Z3.
// Without rewriting this does not go through.
// I believe the reason is related to a previously reported issue with the way
// Z3 bit-blasts through the Boxing/Unboxing functions. I thought this was fixed
// but it may not be the case. Notice that by rewriting with tactics the solver
// only gets to see one big term without any boxing or unboxing inside it.
let lemma_bv128_64_64_and_helper x x0 x1 y y0 y1 z z0 z1 =
lemma_bv128_64_64_and_helper' x0 x1 y0 y1;
assert_by_tactic (z == bvand #128 x y)
(fun () -> destruct_conj ();
rewrite_eqs_from_context ()) | {
"checked_file": "/",
"dependencies": [
"Vale.Math.Bits.fsti.checked",
"Vale.Lib.Tactics.fst.checked",
"Vale.Lib.Bv_s.fst.checked",
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Tactics.Derived.fst.checked",
"FStar.Tactics.BV.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.BV.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Poly1305.Bitvectors.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Math.Bits",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Bv_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x1: FStar.BV.bv_t 64 -> x0: FStar.BV.bv_t 64 -> FStar.BV.bv_t 128 | Prims.Tot | [
"total"
] | [] | [
"FStar.BV.bv_t",
"FStar.BV.bvor",
"FStar.BV.bvshl",
"FStar.BV.bv_uext"
] | [] | false | false | false | false | false | let bv128_64_64 x0 x1 =
| bvor (bvshl (bv_uext #64 #64 x1) 64) (bv_uext #64 #64 x0) | false |
Vale.Poly1305.Bitvectors.fst | Vale.Poly1305.Bitvectors.lemma_and_commutes | val lemma_and_commutes: x:uint_t 64 -> y:uint_t 64 ->
Lemma (logand #64 x y == logand #64 y x) | val lemma_and_commutes: x:uint_t 64 -> y:uint_t 64 ->
Lemma (logand #64 x y == logand #64 y x) | let lemma_and_commutes x y =
assert_by_tactic
(logand #64 x y == logand #64 y x)
bv_tac | {
"file_name": "vale/code/crypto/poly1305/x64/Vale.Poly1305.Bitvectors.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 10,
"end_line": 54,
"start_col": 0,
"start_line": 51
} | module Vale.Poly1305.Bitvectors
open FStar.BV
open FStar.Tactics
open FStar.Tactics.Derived
open FStar.Tactics.BV
open FStar.Mul
open FStar.UInt
open FStar.Math.Lemmas
open Vale.Lib.Tactics
open Vale.Lib.Bv_s
open Vale.Math.Bits
// tweak options?
#reset-options "--smtencoding.elim_box true"
//NOTE: Using the split tactic seems to slowdown execution by a lot.
let lemma_shr2 x =
assert_by_tactic (shift_right #64 x 2 == udiv #64 x 4) bv_tac
let lemma_shr4 x =
assert_by_tactic (shift_right #64 x 4 == udiv #64 x 16) bv_tac
let lemma_and_mod_n x =
assert_by_tactic (logand #64 x 3 == mod #64 x 4) (bv_tac);
assert_by_tactic (logand #64 x 15 == mod #64 x 16) (bv_tac)
let lemma_clear_lower_2 x =
assert_by_tactic
(logand #64 x 0xfffffffffffffffc == mul_mod #64 (udiv #64 x 4) 4)
bv_tac
let lemma_and_constants x =
assert_by_tactic (logand #64 x 0 == (0 <: uint_t 64)) bv_tac;
assert_by_tactic (logand #64 x 0xffffffffffffffff == x) bv_tac
let lemma_poly_constants x =
// using split in this seems to hang execution.
assert_by_tactic
(logand #64 x 0x0ffffffc0fffffff < (0x1000000000000000 <: uint_t 64))
(fun () -> bv_tac_lt 64);
assert_by_tactic
(logand #64 x 0x0ffffffc0ffffffc < (0x1000000000000000 <: uint_t 64))
(fun () -> bv_tac_lt 64);
assert_by_tactic
(mod #64 (logand #64 x 0x0ffffffc0ffffffc) 4 == (0 <: uint_t 64))
(fun () -> bv_tac ()) | {
"checked_file": "/",
"dependencies": [
"Vale.Math.Bits.fsti.checked",
"Vale.Lib.Tactics.fst.checked",
"Vale.Lib.Bv_s.fst.checked",
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Tactics.Derived.fst.checked",
"FStar.Tactics.BV.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.BV.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Poly1305.Bitvectors.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Math.Bits",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Bv_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: FStar.UInt.uint_t 64 -> y: FStar.UInt.uint_t 64
-> FStar.Pervasives.Lemma (ensures FStar.UInt.logand x y == FStar.UInt.logand y x) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.UInt.uint_t",
"FStar.Tactics.Effect.assert_by_tactic",
"Prims.eq2",
"FStar.UInt.logand",
"FStar.Tactics.BV.bv_tac",
"Prims.unit"
] | [] | true | false | true | false | false | let lemma_and_commutes x y =
| assert_by_tactic (logand #64 x y == logand #64 y x) bv_tac | false |
Vale.Poly1305.Bitvectors.fst | Vale.Poly1305.Bitvectors.uint_to_nat | val uint_to_nat (#n: nat) (x: uint_t n) : r: nat{r = x} | val uint_to_nat (#n: nat) (x: uint_t n) : r: nat{r = x} | let uint_to_nat (#n:nat) (x:uint_t n) : r:nat{r = x} =
assert (x < pow2 n);
modulo_lemma x (pow2 n);
x | {
"file_name": "vale/code/crypto/poly1305/x64/Vale.Poly1305.Bitvectors.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 2,
"end_line": 82,
"start_col": 7,
"start_line": 79
} | module Vale.Poly1305.Bitvectors
open FStar.BV
open FStar.Tactics
open FStar.Tactics.Derived
open FStar.Tactics.BV
open FStar.Mul
open FStar.UInt
open FStar.Math.Lemmas
open Vale.Lib.Tactics
open Vale.Lib.Bv_s
open Vale.Math.Bits
// tweak options?
#reset-options "--smtencoding.elim_box true"
//NOTE: Using the split tactic seems to slowdown execution by a lot.
let lemma_shr2 x =
assert_by_tactic (shift_right #64 x 2 == udiv #64 x 4) bv_tac
let lemma_shr4 x =
assert_by_tactic (shift_right #64 x 4 == udiv #64 x 16) bv_tac
let lemma_and_mod_n x =
assert_by_tactic (logand #64 x 3 == mod #64 x 4) (bv_tac);
assert_by_tactic (logand #64 x 15 == mod #64 x 16) (bv_tac)
let lemma_clear_lower_2 x =
assert_by_tactic
(logand #64 x 0xfffffffffffffffc == mul_mod #64 (udiv #64 x 4) 4)
bv_tac
let lemma_and_constants x =
assert_by_tactic (logand #64 x 0 == (0 <: uint_t 64)) bv_tac;
assert_by_tactic (logand #64 x 0xffffffffffffffff == x) bv_tac
let lemma_poly_constants x =
// using split in this seems to hang execution.
assert_by_tactic
(logand #64 x 0x0ffffffc0fffffff < (0x1000000000000000 <: uint_t 64))
(fun () -> bv_tac_lt 64);
assert_by_tactic
(logand #64 x 0x0ffffffc0ffffffc < (0x1000000000000000 <: uint_t 64))
(fun () -> bv_tac_lt 64);
assert_by_tactic
(mod #64 (logand #64 x 0x0ffffffc0ffffffc) 4 == (0 <: uint_t 64))
(fun () -> bv_tac ())
let lemma_and_commutes x y =
assert_by_tactic
(logand #64 x y == logand #64 y x)
bv_tac
let lemma_bv128_64_64_and_helper' (x0:bv_t 64) (x1:bv_t 64) (y0:bv_t 64) (y1:bv_t 64) :
Lemma (requires True)
(ensures ((bvor #128 (bvshl #128 (bv_uext #64 #64 (bvand #64 x1 y1)) 64)
(bv_uext #64 #64 (bvand #64 x0 y0))) ==
bvand #128 (bvor #128 (bvshl #128 (bv_uext #64 #64 x1) 64)
(bv_uext #64 #64 x0))
(bvor #128 (bvshl #128 (bv_uext #64 #64 y1) 64)
(bv_uext #64 #64 y0)))) = ()
// Rewrite all equalities and then the goal is trivial for Z3.
// Without rewriting this does not go through.
// I believe the reason is related to a previously reported issue with the way
// Z3 bit-blasts through the Boxing/Unboxing functions. I thought this was fixed
// but it may not be the case. Notice that by rewriting with tactics the solver
// only gets to see one big term without any boxing or unboxing inside it.
let lemma_bv128_64_64_and_helper x x0 x1 y y0 y1 z z0 z1 =
lemma_bv128_64_64_and_helper' x0 x1 y0 y1;
assert_by_tactic (z == bvand #128 x y)
(fun () -> destruct_conj ();
rewrite_eqs_from_context ())
let bv128_64_64 x0 x1 = bvor (bvshl (bv_uext #64 #64 x1) 64) (bv_uext #64 #64 x0) | {
"checked_file": "/",
"dependencies": [
"Vale.Math.Bits.fsti.checked",
"Vale.Lib.Tactics.fst.checked",
"Vale.Lib.Bv_s.fst.checked",
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Tactics.Derived.fst.checked",
"FStar.Tactics.BV.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.BV.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Poly1305.Bitvectors.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Math.Bits",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Bv_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: FStar.UInt.uint_t n -> r: Prims.nat{r = x} | Prims.Tot | [
"total"
] | [] | [
"Prims.nat",
"FStar.UInt.uint_t",
"Prims.unit",
"FStar.Math.Lemmas.modulo_lemma",
"Prims.pow2",
"Prims._assert",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.op_Equality",
"Prims.int",
"Prims.l_or",
"Prims.op_GreaterThanOrEqual",
"FStar.UInt.size"
] | [] | false | false | false | false | false | let uint_to_nat (#n: nat) (x: uint_t n) : r: nat{r = x} =
| assert (x < pow2 n);
modulo_lemma x (pow2 n);
x | false |
Vale.Poly1305.Bitvectors.fst | Vale.Poly1305.Bitvectors.lemma_bv128_64_64_and_helper | val lemma_bv128_64_64_and_helper: x:bv_t 128 -> x0:bv_t 64 -> x1:bv_t 64 ->
y:bv_t 128 -> y0:bv_t 64 -> y1:bv_t 64 ->
z:bv_t 128 -> z0:bv_t 64 -> z1:bv_t 64 ->
Lemma (requires (z0 == bvand #64 x0 y0 /\
z1 == bvand #64 x1 y1 /\
x == bvor #128 (bvshl #128 (bv_uext #64 #64 x1) 64)
(bv_uext #64 #64 x0) /\
y == bvor #128 (bvshl #128 (bv_uext #64 #64 y1) 64)
(bv_uext #64 #64 y0) /\
z == bvor #128 (bvshl #128 (bv_uext #64 #64 z1) 64)
(bv_uext #64 #64 z0)))
(ensures (z == bvand #128 x y)) | val lemma_bv128_64_64_and_helper: x:bv_t 128 -> x0:bv_t 64 -> x1:bv_t 64 ->
y:bv_t 128 -> y0:bv_t 64 -> y1:bv_t 64 ->
z:bv_t 128 -> z0:bv_t 64 -> z1:bv_t 64 ->
Lemma (requires (z0 == bvand #64 x0 y0 /\
z1 == bvand #64 x1 y1 /\
x == bvor #128 (bvshl #128 (bv_uext #64 #64 x1) 64)
(bv_uext #64 #64 x0) /\
y == bvor #128 (bvshl #128 (bv_uext #64 #64 y1) 64)
(bv_uext #64 #64 y0) /\
z == bvor #128 (bvshl #128 (bv_uext #64 #64 z1) 64)
(bv_uext #64 #64 z0)))
(ensures (z == bvand #128 x y)) | let lemma_bv128_64_64_and_helper x x0 x1 y y0 y1 z z0 z1 =
lemma_bv128_64_64_and_helper' x0 x1 y0 y1;
assert_by_tactic (z == bvand #128 x y)
(fun () -> destruct_conj ();
rewrite_eqs_from_context ()) | {
"file_name": "vale/code/crypto/poly1305/x64/Vale.Poly1305.Bitvectors.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 55,
"end_line": 75,
"start_col": 0,
"start_line": 71
} | module Vale.Poly1305.Bitvectors
open FStar.BV
open FStar.Tactics
open FStar.Tactics.Derived
open FStar.Tactics.BV
open FStar.Mul
open FStar.UInt
open FStar.Math.Lemmas
open Vale.Lib.Tactics
open Vale.Lib.Bv_s
open Vale.Math.Bits
// tweak options?
#reset-options "--smtencoding.elim_box true"
//NOTE: Using the split tactic seems to slowdown execution by a lot.
let lemma_shr2 x =
assert_by_tactic (shift_right #64 x 2 == udiv #64 x 4) bv_tac
let lemma_shr4 x =
assert_by_tactic (shift_right #64 x 4 == udiv #64 x 16) bv_tac
let lemma_and_mod_n x =
assert_by_tactic (logand #64 x 3 == mod #64 x 4) (bv_tac);
assert_by_tactic (logand #64 x 15 == mod #64 x 16) (bv_tac)
let lemma_clear_lower_2 x =
assert_by_tactic
(logand #64 x 0xfffffffffffffffc == mul_mod #64 (udiv #64 x 4) 4)
bv_tac
let lemma_and_constants x =
assert_by_tactic (logand #64 x 0 == (0 <: uint_t 64)) bv_tac;
assert_by_tactic (logand #64 x 0xffffffffffffffff == x) bv_tac
let lemma_poly_constants x =
// using split in this seems to hang execution.
assert_by_tactic
(logand #64 x 0x0ffffffc0fffffff < (0x1000000000000000 <: uint_t 64))
(fun () -> bv_tac_lt 64);
assert_by_tactic
(logand #64 x 0x0ffffffc0ffffffc < (0x1000000000000000 <: uint_t 64))
(fun () -> bv_tac_lt 64);
assert_by_tactic
(mod #64 (logand #64 x 0x0ffffffc0ffffffc) 4 == (0 <: uint_t 64))
(fun () -> bv_tac ())
let lemma_and_commutes x y =
assert_by_tactic
(logand #64 x y == logand #64 y x)
bv_tac
let lemma_bv128_64_64_and_helper' (x0:bv_t 64) (x1:bv_t 64) (y0:bv_t 64) (y1:bv_t 64) :
Lemma (requires True)
(ensures ((bvor #128 (bvshl #128 (bv_uext #64 #64 (bvand #64 x1 y1)) 64)
(bv_uext #64 #64 (bvand #64 x0 y0))) ==
bvand #128 (bvor #128 (bvshl #128 (bv_uext #64 #64 x1) 64)
(bv_uext #64 #64 x0))
(bvor #128 (bvshl #128 (bv_uext #64 #64 y1) 64)
(bv_uext #64 #64 y0)))) = ()
// Rewrite all equalities and then the goal is trivial for Z3.
// Without rewriting this does not go through.
// I believe the reason is related to a previously reported issue with the way
// Z3 bit-blasts through the Boxing/Unboxing functions. I thought this was fixed
// but it may not be the case. Notice that by rewriting with tactics the solver | {
"checked_file": "/",
"dependencies": [
"Vale.Math.Bits.fsti.checked",
"Vale.Lib.Tactics.fst.checked",
"Vale.Lib.Bv_s.fst.checked",
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Tactics.Derived.fst.checked",
"FStar.Tactics.BV.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.BV.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Poly1305.Bitvectors.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Math.Bits",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Bv_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
x: FStar.BV.bv_t 128 ->
x0: FStar.BV.bv_t 64 ->
x1: FStar.BV.bv_t 64 ->
y: FStar.BV.bv_t 128 ->
y0: FStar.BV.bv_t 64 ->
y1: FStar.BV.bv_t 64 ->
z: FStar.BV.bv_t 128 ->
z0: FStar.BV.bv_t 64 ->
z1: FStar.BV.bv_t 64
-> FStar.Pervasives.Lemma
(requires
z0 == FStar.BV.bvand x0 y0 /\ z1 == FStar.BV.bvand x1 y1 /\
x == FStar.BV.bvor (FStar.BV.bvshl (FStar.BV.bv_uext x1) 64) (FStar.BV.bv_uext x0) /\
y == FStar.BV.bvor (FStar.BV.bvshl (FStar.BV.bv_uext y1) 64) (FStar.BV.bv_uext y0) /\
z == FStar.BV.bvor (FStar.BV.bvshl (FStar.BV.bv_uext z1) 64) (FStar.BV.bv_uext z0))
(ensures z == FStar.BV.bvand x y) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.BV.bv_t",
"FStar.Tactics.Effect.assert_by_tactic",
"Prims.eq2",
"FStar.BV.bvand",
"Prims.unit",
"FStar.Tactics.V1.Derived.rewrite_eqs_from_context",
"Vale.Lib.Tactics.destruct_conj",
"Vale.Poly1305.Bitvectors.lemma_bv128_64_64_and_helper'"
] | [] | false | false | true | false | false | let lemma_bv128_64_64_and_helper x x0 x1 y y0 y1 z z0 z1 =
| lemma_bv128_64_64_and_helper' x0 x1 y0 y1;
assert_by_tactic (z == bvand #128 x y)
(fun () ->
destruct_conj ();
rewrite_eqs_from_context ()) | false |
Vale.SHA.PPC64LE.Rounds.Core.fst | Vale.SHA.PPC64LE.Rounds.Core.va_lemma_Loop_rounds_0_63_body | val va_lemma_Loop_rounds_0_63_body : va_b0:va_code -> va_s0:va_state -> i:nat ->
msg:va_operand_vec_opr -> a_vec:va_operand_vec_opr -> b_vec:va_operand_vec_opr ->
c_vec:va_operand_vec_opr -> d_vec:va_operand_vec_opr -> e_vec:va_operand_vec_opr ->
f_vec:va_operand_vec_opr -> g_vec:va_operand_vec_opr -> h_vec:va_operand_vec_opr -> k_b:buffer128
-> block:block_w -> hash_orig:hash256
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_Loop_rounds_0_63_body i msg a_vec b_vec c_vec d_vec
e_vec f_vec g_vec h_vec) va_s0 /\ va_is_src_vec_opr msg va_s0 /\ va_is_src_vec_opr a_vec va_s0
/\ va_is_src_vec_opr b_vec va_s0 /\ va_is_src_vec_opr c_vec va_s0 /\ va_is_dst_vec_opr d_vec
va_s0 /\ va_is_src_vec_opr e_vec va_s0 /\ va_is_src_vec_opr f_vec va_s0 /\ va_is_dst_vec_opr
g_vec va_s0 /\ va_is_dst_vec_opr h_vec va_s0 /\ va_get_ok va_s0 /\ (l_and (0 <= i) (i < 64) /\
msg == i `op_Modulus` 16 /\ (i `op_Modulus` 8 == 0 ==> a_vec == 16 /\ b_vec == 17 /\ c_vec ==
18 /\ d_vec == 19 /\ e_vec == 20 /\ f_vec == 21 /\ g_vec == 22 /\ h_vec == 23) /\ (i
`op_Modulus` 8 == 1 ==> a_vec == 23 /\ b_vec == 16 /\ c_vec == 17 /\ d_vec == 18 /\ e_vec == 19
/\ f_vec == 20 /\ g_vec == 21 /\ h_vec == 22) /\ (i `op_Modulus` 8 == 2 ==> a_vec == 22 /\
b_vec == 23 /\ c_vec == 16 /\ d_vec == 17 /\ e_vec == 18 /\ f_vec == 19 /\ g_vec == 20 /\ h_vec
== 21) /\ (i `op_Modulus` 8 == 3 ==> a_vec == 21 /\ b_vec == 22 /\ c_vec == 23 /\ d_vec == 16
/\ e_vec == 17 /\ f_vec == 18 /\ g_vec == 19 /\ h_vec == 20) /\ (i `op_Modulus` 8 == 4 ==>
a_vec == 20 /\ b_vec == 21 /\ c_vec == 22 /\ d_vec == 23 /\ e_vec == 16 /\ f_vec == 17 /\ g_vec
== 18 /\ h_vec == 19) /\ (i `op_Modulus` 8 == 5 ==> a_vec == 19 /\ b_vec == 20 /\ c_vec == 21
/\ d_vec == 22 /\ e_vec == 23 /\ f_vec == 16 /\ g_vec == 17 /\ h_vec == 18) /\ (i `op_Modulus`
8 == 6 ==> a_vec == 18 /\ b_vec == 19 /\ c_vec == 20 /\ d_vec == 21 /\ e_vec == 22 /\ f_vec ==
23 /\ g_vec == 16 /\ h_vec == 17) /\ (i `op_Modulus` 8 == 7 ==> a_vec == 17 /\ b_vec == 18 /\
c_vec == 19 /\ d_vec == 20 /\ e_vec == 21 /\ f_vec == 22 /\ g_vec == 23 /\ h_vec == 16) /\ (let
ks = Vale.PPC64LE.Decls.buffer128_as_seq (va_get_mem_heaplet 0 va_s0) k_b in
Vale.SHA.PPC64LE.SHA_helpers.k_reqs ks /\ (let hash =
Vale.SHA.PPC64LE.SHA_helpers.repeat_range_vale i block hash_orig in
Vale.Def.Words_s.__proj__Mkfour__item__hi3 (va_eval_vec_opr va_s0 a_vec) ==
Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32 (FStar.Seq.Base.index
#Vale.SHA.PPC64LE.SHA_helpers.word hash 0) /\ Vale.Def.Words_s.__proj__Mkfour__item__hi3
(va_eval_vec_opr va_s0 b_vec) == Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32
(FStar.Seq.Base.index #Vale.SHA.PPC64LE.SHA_helpers.word hash 1) /\
Vale.Def.Words_s.__proj__Mkfour__item__hi3 (va_eval_vec_opr va_s0 c_vec) ==
Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32 (FStar.Seq.Base.index
#Vale.SHA.PPC64LE.SHA_helpers.word hash 2) /\ Vale.Def.Words_s.__proj__Mkfour__item__hi3
(va_eval_vec_opr va_s0 d_vec) == Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32
(FStar.Seq.Base.index #Vale.SHA.PPC64LE.SHA_helpers.word hash 3) /\
Vale.Def.Words_s.__proj__Mkfour__item__hi3 (va_eval_vec_opr va_s0 e_vec) ==
Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32 (FStar.Seq.Base.index
#Vale.SHA.PPC64LE.SHA_helpers.word hash 4) /\ Vale.Def.Words_s.__proj__Mkfour__item__hi3
(va_eval_vec_opr va_s0 f_vec) == Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32
(FStar.Seq.Base.index #Vale.SHA.PPC64LE.SHA_helpers.word hash 5) /\
Vale.Def.Words_s.__proj__Mkfour__item__hi3 (va_eval_vec_opr va_s0 g_vec) ==
Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32 (FStar.Seq.Base.index
#Vale.SHA.PPC64LE.SHA_helpers.word hash 6) /\ Vale.Def.Words_s.__proj__Mkfour__item__hi3
(va_eval_vec_opr va_s0 h_vec) == Vale.Arch.Types.add_wrap32
(Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32 (FStar.Seq.Base.index
#Vale.SHA.PPC64LE.SHA_helpers.word hash 7)) (Vale.SHA.PPC64LE.SHA_helpers.k_index ks i) /\
Vale.Def.Words_s.__proj__Mkfour__item__hi3 (va_eval_vec_opr va_s0 msg) ==
Vale.SHA.PPC64LE.SHA_helpers.ws_opaque block i /\ (i =!= 63 ==> (va_get_vec 24 va_s0).hi3 ==
Vale.SHA.PPC64LE.SHA_helpers.k_index ks (i + 1)))))))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
(let ks = Vale.PPC64LE.Decls.buffer128_as_seq (va_get_mem_heaplet 0 va_sM) k_b in let hash =
Vale.SHA.PPC64LE.SHA_helpers.repeat_range_vale i block hash_orig in let h_k =
Vale.Arch.Types.add_wrap32 (Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32 (FStar.Seq.Base.index
#Vale.SHA.PPC64LE.SHA_helpers.word hash 7)) (Vale.SHA.PPC64LE.SHA_helpers.k_index ks i) in let
ch = Vale.SHA.PPC64LE.SHA_helpers.ch_256 (Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32
(FStar.Seq.Base.index #Vale.SHA.PPC64LE.SHA_helpers.word hash 4))
(Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32 (FStar.Seq.Base.index
#Vale.SHA.PPC64LE.SHA_helpers.word hash 5)) (Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32
(FStar.Seq.Base.index #Vale.SHA.PPC64LE.SHA_helpers.word hash 6)) in let sigma1 =
Vale.SHA2.Wrapper.sigma256_1_1 (Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32
(FStar.Seq.Base.index #Vale.SHA.PPC64LE.SHA_helpers.word hash 4)) in let sigma0 =
Vale.SHA2.Wrapper.sigma256_1_0 (Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32
(FStar.Seq.Base.index #Vale.SHA.PPC64LE.SHA_helpers.word hash 0)) in let maj =
Vale.SHA.PPC64LE.SHA_helpers.maj_256 (Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32
(FStar.Seq.Base.index #Vale.SHA.PPC64LE.SHA_helpers.word hash 0))
(Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32 (FStar.Seq.Base.index
#Vale.SHA.PPC64LE.SHA_helpers.word hash 1)) (Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32
(FStar.Seq.Base.index #Vale.SHA.PPC64LE.SHA_helpers.word hash 2)) in let sigma0_maj =
Vale.Arch.Types.add_wrap32 sigma0 maj in Vale.Def.Words_s.__proj__Mkfour__item__hi3
(va_eval_vec_opr va_sM d_vec) == Vale.Arch.Types.add_wrap32
(Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32 (FStar.Seq.Base.index
#Vale.SHA.PPC64LE.SHA_helpers.word hash 3)) (Vale.Arch.Types.add_wrap32
(Vale.Arch.Types.add_wrap32 (Vale.Arch.Types.add_wrap32 h_k
(Vale.SHA.PPC64LE.SHA_helpers.ws_opaque block i)) ch) sigma1) /\
Vale.Def.Words_s.__proj__Mkfour__item__hi3 (va_eval_vec_opr va_sM h_vec) ==
Vale.Arch.Types.add_wrap32 (Vale.Arch.Types.add_wrap32 (Vale.Arch.Types.add_wrap32
(Vale.Arch.Types.add_wrap32 h_k (Vale.SHA.PPC64LE.SHA_helpers.ws_opaque block i)) ch) sigma1)
sigma0_maj /\ (i =!= 63 ==> Vale.Def.Words_s.__proj__Mkfour__item__hi3 (va_eval_vec_opr va_sM
g_vec) == Vale.Arch.Types.add_wrap32 (Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32
(FStar.Seq.Base.index #Vale.SHA.PPC64LE.SHA_helpers.word hash 6))
(Vale.SHA.PPC64LE.SHA_helpers.k_index ks (i + 1))) /\ (i =!= 63 ==> (let next_hash =
Vale.SHA.PPC64LE.SHA_helpers.repeat_range_vale (i + 1) block hash_orig in l_and (l_and (l_and
(l_and (l_and (l_and (l_and (Vale.Def.Words_s.__proj__Mkfour__item__hi3 (va_eval_vec_opr va_sM
a_vec) == Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32 (FStar.Seq.Base.index
#Vale.SHA.PPC64LE.SHA_helpers.word next_hash 1)) (Vale.Def.Words_s.__proj__Mkfour__item__hi3
(va_eval_vec_opr va_sM b_vec) == Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32
(FStar.Seq.Base.index #Vale.SHA.PPC64LE.SHA_helpers.word next_hash 2)))
(Vale.Def.Words_s.__proj__Mkfour__item__hi3 (va_eval_vec_opr va_sM c_vec) ==
Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32 (FStar.Seq.Base.index
#Vale.SHA.PPC64LE.SHA_helpers.word next_hash 3))) (Vale.Def.Words_s.__proj__Mkfour__item__hi3
(va_eval_vec_opr va_sM d_vec) == Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32
(FStar.Seq.Base.index #Vale.SHA.PPC64LE.SHA_helpers.word next_hash 4)))
(Vale.Def.Words_s.__proj__Mkfour__item__hi3 (va_eval_vec_opr va_sM e_vec) ==
Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32 (FStar.Seq.Base.index
#Vale.SHA.PPC64LE.SHA_helpers.word next_hash 5))) (Vale.Def.Words_s.__proj__Mkfour__item__hi3
(va_eval_vec_opr va_sM f_vec) == Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32
(FStar.Seq.Base.index #Vale.SHA.PPC64LE.SHA_helpers.word next_hash 6)))
(Vale.Def.Words_s.__proj__Mkfour__item__hi3 (va_eval_vec_opr va_sM g_vec) ==
Vale.Arch.Types.add_wrap32 (Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32 (FStar.Seq.Base.index
#Vale.SHA.PPC64LE.SHA_helpers.word next_hash 7)) (Vale.SHA.PPC64LE.SHA_helpers.k_index ks (i +
1)))) (Vale.Def.Words_s.__proj__Mkfour__item__hi3 (va_eval_vec_opr va_sM h_vec) ==
Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32 (FStar.Seq.Base.index
#Vale.SHA.PPC64LE.SHA_helpers.word next_hash 0)))) /\ (i == 63 ==>
Vale.SHA.PPC64LE.SHA_helpers.make_seperated_hash_quad32 (va_eval_vec_opr va_sM h_vec)
(va_eval_vec_opr va_sM a_vec) (va_eval_vec_opr va_sM b_vec) (va_eval_vec_opr va_sM c_vec)
(va_eval_vec_opr va_sM d_vec) (va_eval_vec_opr va_sM e_vec) (va_eval_vec_opr va_sM f_vec)
(va_eval_vec_opr va_sM g_vec) == Vale.SHA.PPC64LE.SHA_helpers.repeat_range_vale_64 block
hash_orig)) /\ va_state_eq va_sM (va_update_vec 26 va_sM (va_update_vec 25 va_sM (va_update_ok
va_sM (va_update_operand_vec_opr h_vec va_sM (va_update_operand_vec_opr g_vec va_sM
(va_update_operand_vec_opr d_vec va_sM va_s0)))))))) | val va_lemma_Loop_rounds_0_63_body : va_b0:va_code -> va_s0:va_state -> i:nat ->
msg:va_operand_vec_opr -> a_vec:va_operand_vec_opr -> b_vec:va_operand_vec_opr ->
c_vec:va_operand_vec_opr -> d_vec:va_operand_vec_opr -> e_vec:va_operand_vec_opr ->
f_vec:va_operand_vec_opr -> g_vec:va_operand_vec_opr -> h_vec:va_operand_vec_opr -> k_b:buffer128
-> block:block_w -> hash_orig:hash256
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_Loop_rounds_0_63_body i msg a_vec b_vec c_vec d_vec
e_vec f_vec g_vec h_vec) va_s0 /\ va_is_src_vec_opr msg va_s0 /\ va_is_src_vec_opr a_vec va_s0
/\ va_is_src_vec_opr b_vec va_s0 /\ va_is_src_vec_opr c_vec va_s0 /\ va_is_dst_vec_opr d_vec
va_s0 /\ va_is_src_vec_opr e_vec va_s0 /\ va_is_src_vec_opr f_vec va_s0 /\ va_is_dst_vec_opr
g_vec va_s0 /\ va_is_dst_vec_opr h_vec va_s0 /\ va_get_ok va_s0 /\ (l_and (0 <= i) (i < 64) /\
msg == i `op_Modulus` 16 /\ (i `op_Modulus` 8 == 0 ==> a_vec == 16 /\ b_vec == 17 /\ c_vec ==
18 /\ d_vec == 19 /\ e_vec == 20 /\ f_vec == 21 /\ g_vec == 22 /\ h_vec == 23) /\ (i
`op_Modulus` 8 == 1 ==> a_vec == 23 /\ b_vec == 16 /\ c_vec == 17 /\ d_vec == 18 /\ e_vec == 19
/\ f_vec == 20 /\ g_vec == 21 /\ h_vec == 22) /\ (i `op_Modulus` 8 == 2 ==> a_vec == 22 /\
b_vec == 23 /\ c_vec == 16 /\ d_vec == 17 /\ e_vec == 18 /\ f_vec == 19 /\ g_vec == 20 /\ h_vec
== 21) /\ (i `op_Modulus` 8 == 3 ==> a_vec == 21 /\ b_vec == 22 /\ c_vec == 23 /\ d_vec == 16
/\ e_vec == 17 /\ f_vec == 18 /\ g_vec == 19 /\ h_vec == 20) /\ (i `op_Modulus` 8 == 4 ==>
a_vec == 20 /\ b_vec == 21 /\ c_vec == 22 /\ d_vec == 23 /\ e_vec == 16 /\ f_vec == 17 /\ g_vec
== 18 /\ h_vec == 19) /\ (i `op_Modulus` 8 == 5 ==> a_vec == 19 /\ b_vec == 20 /\ c_vec == 21
/\ d_vec == 22 /\ e_vec == 23 /\ f_vec == 16 /\ g_vec == 17 /\ h_vec == 18) /\ (i `op_Modulus`
8 == 6 ==> a_vec == 18 /\ b_vec == 19 /\ c_vec == 20 /\ d_vec == 21 /\ e_vec == 22 /\ f_vec ==
23 /\ g_vec == 16 /\ h_vec == 17) /\ (i `op_Modulus` 8 == 7 ==> a_vec == 17 /\ b_vec == 18 /\
c_vec == 19 /\ d_vec == 20 /\ e_vec == 21 /\ f_vec == 22 /\ g_vec == 23 /\ h_vec == 16) /\ (let
ks = Vale.PPC64LE.Decls.buffer128_as_seq (va_get_mem_heaplet 0 va_s0) k_b in
Vale.SHA.PPC64LE.SHA_helpers.k_reqs ks /\ (let hash =
Vale.SHA.PPC64LE.SHA_helpers.repeat_range_vale i block hash_orig in
Vale.Def.Words_s.__proj__Mkfour__item__hi3 (va_eval_vec_opr va_s0 a_vec) ==
Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32 (FStar.Seq.Base.index
#Vale.SHA.PPC64LE.SHA_helpers.word hash 0) /\ Vale.Def.Words_s.__proj__Mkfour__item__hi3
(va_eval_vec_opr va_s0 b_vec) == Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32
(FStar.Seq.Base.index #Vale.SHA.PPC64LE.SHA_helpers.word hash 1) /\
Vale.Def.Words_s.__proj__Mkfour__item__hi3 (va_eval_vec_opr va_s0 c_vec) ==
Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32 (FStar.Seq.Base.index
#Vale.SHA.PPC64LE.SHA_helpers.word hash 2) /\ Vale.Def.Words_s.__proj__Mkfour__item__hi3
(va_eval_vec_opr va_s0 d_vec) == Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32
(FStar.Seq.Base.index #Vale.SHA.PPC64LE.SHA_helpers.word hash 3) /\
Vale.Def.Words_s.__proj__Mkfour__item__hi3 (va_eval_vec_opr va_s0 e_vec) ==
Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32 (FStar.Seq.Base.index
#Vale.SHA.PPC64LE.SHA_helpers.word hash 4) /\ Vale.Def.Words_s.__proj__Mkfour__item__hi3
(va_eval_vec_opr va_s0 f_vec) == Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32
(FStar.Seq.Base.index #Vale.SHA.PPC64LE.SHA_helpers.word hash 5) /\
Vale.Def.Words_s.__proj__Mkfour__item__hi3 (va_eval_vec_opr va_s0 g_vec) ==
Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32 (FStar.Seq.Base.index
#Vale.SHA.PPC64LE.SHA_helpers.word hash 6) /\ Vale.Def.Words_s.__proj__Mkfour__item__hi3
(va_eval_vec_opr va_s0 h_vec) == Vale.Arch.Types.add_wrap32
(Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32 (FStar.Seq.Base.index
#Vale.SHA.PPC64LE.SHA_helpers.word hash 7)) (Vale.SHA.PPC64LE.SHA_helpers.k_index ks i) /\
Vale.Def.Words_s.__proj__Mkfour__item__hi3 (va_eval_vec_opr va_s0 msg) ==
Vale.SHA.PPC64LE.SHA_helpers.ws_opaque block i /\ (i =!= 63 ==> (va_get_vec 24 va_s0).hi3 ==
Vale.SHA.PPC64LE.SHA_helpers.k_index ks (i + 1)))))))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
(let ks = Vale.PPC64LE.Decls.buffer128_as_seq (va_get_mem_heaplet 0 va_sM) k_b in let hash =
Vale.SHA.PPC64LE.SHA_helpers.repeat_range_vale i block hash_orig in let h_k =
Vale.Arch.Types.add_wrap32 (Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32 (FStar.Seq.Base.index
#Vale.SHA.PPC64LE.SHA_helpers.word hash 7)) (Vale.SHA.PPC64LE.SHA_helpers.k_index ks i) in let
ch = Vale.SHA.PPC64LE.SHA_helpers.ch_256 (Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32
(FStar.Seq.Base.index #Vale.SHA.PPC64LE.SHA_helpers.word hash 4))
(Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32 (FStar.Seq.Base.index
#Vale.SHA.PPC64LE.SHA_helpers.word hash 5)) (Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32
(FStar.Seq.Base.index #Vale.SHA.PPC64LE.SHA_helpers.word hash 6)) in let sigma1 =
Vale.SHA2.Wrapper.sigma256_1_1 (Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32
(FStar.Seq.Base.index #Vale.SHA.PPC64LE.SHA_helpers.word hash 4)) in let sigma0 =
Vale.SHA2.Wrapper.sigma256_1_0 (Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32
(FStar.Seq.Base.index #Vale.SHA.PPC64LE.SHA_helpers.word hash 0)) in let maj =
Vale.SHA.PPC64LE.SHA_helpers.maj_256 (Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32
(FStar.Seq.Base.index #Vale.SHA.PPC64LE.SHA_helpers.word hash 0))
(Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32 (FStar.Seq.Base.index
#Vale.SHA.PPC64LE.SHA_helpers.word hash 1)) (Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32
(FStar.Seq.Base.index #Vale.SHA.PPC64LE.SHA_helpers.word hash 2)) in let sigma0_maj =
Vale.Arch.Types.add_wrap32 sigma0 maj in Vale.Def.Words_s.__proj__Mkfour__item__hi3
(va_eval_vec_opr va_sM d_vec) == Vale.Arch.Types.add_wrap32
(Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32 (FStar.Seq.Base.index
#Vale.SHA.PPC64LE.SHA_helpers.word hash 3)) (Vale.Arch.Types.add_wrap32
(Vale.Arch.Types.add_wrap32 (Vale.Arch.Types.add_wrap32 h_k
(Vale.SHA.PPC64LE.SHA_helpers.ws_opaque block i)) ch) sigma1) /\
Vale.Def.Words_s.__proj__Mkfour__item__hi3 (va_eval_vec_opr va_sM h_vec) ==
Vale.Arch.Types.add_wrap32 (Vale.Arch.Types.add_wrap32 (Vale.Arch.Types.add_wrap32
(Vale.Arch.Types.add_wrap32 h_k (Vale.SHA.PPC64LE.SHA_helpers.ws_opaque block i)) ch) sigma1)
sigma0_maj /\ (i =!= 63 ==> Vale.Def.Words_s.__proj__Mkfour__item__hi3 (va_eval_vec_opr va_sM
g_vec) == Vale.Arch.Types.add_wrap32 (Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32
(FStar.Seq.Base.index #Vale.SHA.PPC64LE.SHA_helpers.word hash 6))
(Vale.SHA.PPC64LE.SHA_helpers.k_index ks (i + 1))) /\ (i =!= 63 ==> (let next_hash =
Vale.SHA.PPC64LE.SHA_helpers.repeat_range_vale (i + 1) block hash_orig in l_and (l_and (l_and
(l_and (l_and (l_and (l_and (Vale.Def.Words_s.__proj__Mkfour__item__hi3 (va_eval_vec_opr va_sM
a_vec) == Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32 (FStar.Seq.Base.index
#Vale.SHA.PPC64LE.SHA_helpers.word next_hash 1)) (Vale.Def.Words_s.__proj__Mkfour__item__hi3
(va_eval_vec_opr va_sM b_vec) == Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32
(FStar.Seq.Base.index #Vale.SHA.PPC64LE.SHA_helpers.word next_hash 2)))
(Vale.Def.Words_s.__proj__Mkfour__item__hi3 (va_eval_vec_opr va_sM c_vec) ==
Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32 (FStar.Seq.Base.index
#Vale.SHA.PPC64LE.SHA_helpers.word next_hash 3))) (Vale.Def.Words_s.__proj__Mkfour__item__hi3
(va_eval_vec_opr va_sM d_vec) == Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32
(FStar.Seq.Base.index #Vale.SHA.PPC64LE.SHA_helpers.word next_hash 4)))
(Vale.Def.Words_s.__proj__Mkfour__item__hi3 (va_eval_vec_opr va_sM e_vec) ==
Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32 (FStar.Seq.Base.index
#Vale.SHA.PPC64LE.SHA_helpers.word next_hash 5))) (Vale.Def.Words_s.__proj__Mkfour__item__hi3
(va_eval_vec_opr va_sM f_vec) == Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32
(FStar.Seq.Base.index #Vale.SHA.PPC64LE.SHA_helpers.word next_hash 6)))
(Vale.Def.Words_s.__proj__Mkfour__item__hi3 (va_eval_vec_opr va_sM g_vec) ==
Vale.Arch.Types.add_wrap32 (Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32 (FStar.Seq.Base.index
#Vale.SHA.PPC64LE.SHA_helpers.word next_hash 7)) (Vale.SHA.PPC64LE.SHA_helpers.k_index ks (i +
1)))) (Vale.Def.Words_s.__proj__Mkfour__item__hi3 (va_eval_vec_opr va_sM h_vec) ==
Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32 (FStar.Seq.Base.index
#Vale.SHA.PPC64LE.SHA_helpers.word next_hash 0)))) /\ (i == 63 ==>
Vale.SHA.PPC64LE.SHA_helpers.make_seperated_hash_quad32 (va_eval_vec_opr va_sM h_vec)
(va_eval_vec_opr va_sM a_vec) (va_eval_vec_opr va_sM b_vec) (va_eval_vec_opr va_sM c_vec)
(va_eval_vec_opr va_sM d_vec) (va_eval_vec_opr va_sM e_vec) (va_eval_vec_opr va_sM f_vec)
(va_eval_vec_opr va_sM g_vec) == Vale.SHA.PPC64LE.SHA_helpers.repeat_range_vale_64 block
hash_orig)) /\ va_state_eq va_sM (va_update_vec 26 va_sM (va_update_vec 25 va_sM (va_update_ok
va_sM (va_update_operand_vec_opr h_vec va_sM (va_update_operand_vec_opr g_vec va_sM
(va_update_operand_vec_opr d_vec va_sM va_s0)))))))) | let va_lemma_Loop_rounds_0_63_body va_b0 va_s0 i msg a_vec b_vec c_vec d_vec e_vec f_vec g_vec
h_vec k_b block hash_orig =
let (va_mods:va_mods_t) = [va_Mod_vec 26; va_Mod_vec 25; va_Mod_ok; va_mod_vec_opr h_vec;
va_mod_vec_opr g_vec; va_mod_vec_opr d_vec] in
let va_qc = va_qcode_Loop_rounds_0_63_body va_mods i msg a_vec b_vec c_vec d_vec e_vec f_vec
g_vec h_vec k_b block hash_orig in
let (va_sM, va_fM, va_g) = va_wp_sound_code_norm (va_code_Loop_rounds_0_63_body i msg a_vec b_vec
c_vec d_vec e_vec f_vec g_vec h_vec) va_qc va_s0 (fun va_s0 va_sM va_g -> let () = va_g in
label va_range1
"***** POSTCONDITION NOT MET AT line 155 column 1 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/sha/Vale.SHA.PPC64LE.Rounds.Core.vaf *****"
(va_get_ok va_sM) /\ label va_range1
"***** POSTCONDITION NOT MET AT line 205 column 9 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/sha/Vale.SHA.PPC64LE.Rounds.Core.vaf *****"
(let ks = Vale.PPC64LE.Decls.buffer128_as_seq (va_get_mem_heaplet 0 va_sM) k_b in label
va_range1
"***** POSTCONDITION NOT MET AT line 206 column 9 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/sha/Vale.SHA.PPC64LE.Rounds.Core.vaf *****"
(let hash = Vale.SHA.PPC64LE.SHA_helpers.repeat_range_vale i block hash_orig in label va_range1
"***** POSTCONDITION NOT MET AT line 207 column 9 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/sha/Vale.SHA.PPC64LE.Rounds.Core.vaf *****"
(let h_k = Vale.Arch.Types.add_wrap32 (Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32
(FStar.Seq.Base.index #Vale.SHA.PPC64LE.SHA_helpers.word hash 7))
(Vale.SHA.PPC64LE.SHA_helpers.k_index ks i) in label va_range1
"***** POSTCONDITION NOT MET AT line 208 column 9 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/sha/Vale.SHA.PPC64LE.Rounds.Core.vaf *****"
(let ch = Vale.SHA.PPC64LE.SHA_helpers.ch_256 (Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32
(FStar.Seq.Base.index #Vale.SHA.PPC64LE.SHA_helpers.word hash 4))
(Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32 (FStar.Seq.Base.index
#Vale.SHA.PPC64LE.SHA_helpers.word hash 5)) (Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32
(FStar.Seq.Base.index #Vale.SHA.PPC64LE.SHA_helpers.word hash 6)) in label va_range1
"***** POSTCONDITION NOT MET AT line 209 column 9 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/sha/Vale.SHA.PPC64LE.Rounds.Core.vaf *****"
(let sigma1 = Vale.SHA2.Wrapper.sigma256_1_1 (Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32
(FStar.Seq.Base.index #Vale.SHA.PPC64LE.SHA_helpers.word hash 4)) in label va_range1
"***** POSTCONDITION NOT MET AT line 210 column 9 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/sha/Vale.SHA.PPC64LE.Rounds.Core.vaf *****"
(let sigma0 = Vale.SHA2.Wrapper.sigma256_1_0 (Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32
(FStar.Seq.Base.index #Vale.SHA.PPC64LE.SHA_helpers.word hash 0)) in label va_range1
"***** POSTCONDITION NOT MET AT line 211 column 9 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/sha/Vale.SHA.PPC64LE.Rounds.Core.vaf *****"
(let maj = Vale.SHA.PPC64LE.SHA_helpers.maj_256 (Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32
(FStar.Seq.Base.index #Vale.SHA.PPC64LE.SHA_helpers.word hash 0))
(Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32 (FStar.Seq.Base.index
#Vale.SHA.PPC64LE.SHA_helpers.word hash 1)) (Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32
(FStar.Seq.Base.index #Vale.SHA.PPC64LE.SHA_helpers.word hash 2)) in label va_range1
"***** POSTCONDITION NOT MET AT line 212 column 9 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/sha/Vale.SHA.PPC64LE.Rounds.Core.vaf *****"
(let sigma0_maj = Vale.Arch.Types.add_wrap32 sigma0 maj in label va_range1
"***** POSTCONDITION NOT MET AT line 213 column 137 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/sha/Vale.SHA.PPC64LE.Rounds.Core.vaf *****"
(Vale.Def.Words_s.__proj__Mkfour__item__hi3 (va_eval_vec_opr va_sM d_vec) ==
Vale.Arch.Types.add_wrap32 (Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32 (FStar.Seq.Base.index
#Vale.SHA.PPC64LE.SHA_helpers.word hash 3)) (Vale.Arch.Types.add_wrap32
(Vale.Arch.Types.add_wrap32 (Vale.Arch.Types.add_wrap32 h_k
(Vale.SHA.PPC64LE.SHA_helpers.ws_opaque block i)) ch) sigma1)) /\ label va_range1
"***** POSTCONDITION NOT MET AT line 214 column 118 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/sha/Vale.SHA.PPC64LE.Rounds.Core.vaf *****"
(Vale.Def.Words_s.__proj__Mkfour__item__hi3 (va_eval_vec_opr va_sM h_vec) ==
Vale.Arch.Types.add_wrap32 (Vale.Arch.Types.add_wrap32 (Vale.Arch.Types.add_wrap32
(Vale.Arch.Types.add_wrap32 h_k (Vale.SHA.PPC64LE.SHA_helpers.ws_opaque block i)) ch) sigma1)
sigma0_maj) /\ label va_range1
"***** POSTCONDITION NOT MET AT line 215 column 93 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/sha/Vale.SHA.PPC64LE.Rounds.Core.vaf *****"
(i =!= 63 ==> Vale.Def.Words_s.__proj__Mkfour__item__hi3 (va_eval_vec_opr va_sM g_vec) ==
Vale.Arch.Types.add_wrap32 (Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32 (FStar.Seq.Base.index
#Vale.SHA.PPC64LE.SHA_helpers.word hash 6)) (Vale.SHA.PPC64LE.SHA_helpers.k_index ks (i + 1)))
/\ label va_range1
"***** POSTCONDITION NOT MET AT line 224 column 61 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/sha/Vale.SHA.PPC64LE.Rounds.Core.vaf *****"
(i =!= 63 ==> (let next_hash = Vale.SHA.PPC64LE.SHA_helpers.repeat_range_vale (i + 1) block
hash_orig in l_and (l_and (l_and (l_and (l_and (l_and (l_and
(Vale.Def.Words_s.__proj__Mkfour__item__hi3 (va_eval_vec_opr va_sM a_vec) ==
Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32 (FStar.Seq.Base.index
#Vale.SHA.PPC64LE.SHA_helpers.word next_hash 1)) (Vale.Def.Words_s.__proj__Mkfour__item__hi3
(va_eval_vec_opr va_sM b_vec) == Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32
(FStar.Seq.Base.index #Vale.SHA.PPC64LE.SHA_helpers.word next_hash 2)))
(Vale.Def.Words_s.__proj__Mkfour__item__hi3 (va_eval_vec_opr va_sM c_vec) ==
Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32 (FStar.Seq.Base.index
#Vale.SHA.PPC64LE.SHA_helpers.word next_hash 3))) (Vale.Def.Words_s.__proj__Mkfour__item__hi3
(va_eval_vec_opr va_sM d_vec) == Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32
(FStar.Seq.Base.index #Vale.SHA.PPC64LE.SHA_helpers.word next_hash 4)))
(Vale.Def.Words_s.__proj__Mkfour__item__hi3 (va_eval_vec_opr va_sM e_vec) ==
Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32 (FStar.Seq.Base.index
#Vale.SHA.PPC64LE.SHA_helpers.word next_hash 5))) (Vale.Def.Words_s.__proj__Mkfour__item__hi3
(va_eval_vec_opr va_sM f_vec) == Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32
(FStar.Seq.Base.index #Vale.SHA.PPC64LE.SHA_helpers.word next_hash 6)))
(Vale.Def.Words_s.__proj__Mkfour__item__hi3 (va_eval_vec_opr va_sM g_vec) ==
Vale.Arch.Types.add_wrap32 (Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32 (FStar.Seq.Base.index
#Vale.SHA.PPC64LE.SHA_helpers.word next_hash 7)) (Vale.SHA.PPC64LE.SHA_helpers.k_index ks (i +
1)))) (Vale.Def.Words_s.__proj__Mkfour__item__hi3 (va_eval_vec_opr va_sM h_vec) ==
Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32 (FStar.Seq.Base.index
#Vale.SHA.PPC64LE.SHA_helpers.word next_hash 0)))) /\ label va_range1
"***** POSTCONDITION NOT MET AT line 225 column 145 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/sha/Vale.SHA.PPC64LE.Rounds.Core.vaf *****"
(i == 63 ==> Vale.SHA.PPC64LE.SHA_helpers.make_seperated_hash_quad32 (va_eval_vec_opr va_sM
h_vec) (va_eval_vec_opr va_sM a_vec) (va_eval_vec_opr va_sM b_vec) (va_eval_vec_opr va_sM
c_vec) (va_eval_vec_opr va_sM d_vec) (va_eval_vec_opr va_sM e_vec) (va_eval_vec_opr va_sM
f_vec) (va_eval_vec_opr va_sM g_vec) == Vale.SHA.PPC64LE.SHA_helpers.repeat_range_vale_64 block
hash_orig)))))))))) in
assert_norm (va_qc.mods == va_mods);
va_lemma_norm_mods ([va_Mod_vec 26; va_Mod_vec 25; va_Mod_ok; va_mod_vec_opr h_vec;
va_mod_vec_opr g_vec; va_mod_vec_opr d_vec]) va_sM va_s0;
(va_sM, va_fM) | {
"file_name": "obj/Vale.SHA.PPC64LE.Rounds.Core.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 16,
"end_line": 612,
"start_col": 0,
"start_line": 523
} | module Vale.SHA.PPC64LE.Rounds.Core
open Vale.Def.Opaque_s
open Vale.Def.Types_s
open Vale.Def.Words_s
open Vale.Def.Words.Seq_s
open FStar.Seq
open Vale.Arch.Types
open Vale.Arch.HeapImpl
open Vale.PPC64LE.Machine_s
open Vale.PPC64LE.Memory
open Vale.PPC64LE.Stack_i
open Vale.PPC64LE.State
open Vale.PPC64LE.Decls
open Vale.PPC64LE.QuickCode
open Vale.PPC64LE.QuickCodes
open Vale.PPC64LE.InsBasic
open Vale.PPC64LE.InsMem
open Vale.PPC64LE.InsStack
open Vale.PPC64LE.InsVector
open Vale.SHA.PPC64LE.SHA_helpers
open Spec.SHA2
open Spec.Agile.Hash
open Spec.Hash.Definitions
open Spec.Loops
open Vale.SHA2.Wrapper
#reset-options "--z3rlimit 2000"
//-- Loop_rounds_3_7_11_body
[@ "opaque_to_smt" va_qattr]
let va_code_Loop_rounds_3_7_11_body i msg =
(va_Block (va_CCons (va_code_Load128_byte16_buffer (va_op_heaplet_mem_heaplet 0) msg
(va_op_reg_opr_reg 4) Secret) (va_CCons (va_code_AddImm (va_op_reg_opr_reg 4)
(va_op_reg_opr_reg 4) 16) (va_CNil ()))))
[@ "opaque_to_smt" va_qattr]
let va_codegen_success_Loop_rounds_3_7_11_body i msg =
(va_pbool_and (va_codegen_success_Load128_byte16_buffer (va_op_heaplet_mem_heaplet 0) msg
(va_op_reg_opr_reg 4) Secret) (va_pbool_and (va_codegen_success_AddImm (va_op_reg_opr_reg 4)
(va_op_reg_opr_reg 4) 16) (va_ttrue ())))
[@ "opaque_to_smt" va_qattr]
let va_qcode_Loop_rounds_3_7_11_body (va_mods:va_mods_t) (i:nat) (msg:vec_opr) (in_b:buffer128)
(offset:nat) : (va_quickCode unit (va_code_Loop_rounds_3_7_11_body i msg)) =
(qblock va_mods (fun (va_s:va_state) -> let (va_old_s:va_state) = va_s in va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 79 column 26 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/sha/Vale.SHA.PPC64LE.Rounds.Core.vaf *****"
(va_quick_Load128_byte16_buffer (va_op_heaplet_mem_heaplet 0) msg (va_op_reg_opr_reg 4) Secret
in_b offset) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 80 column 11 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/sha/Vale.SHA.PPC64LE.Rounds.Core.vaf *****"
(va_quick_AddImm (va_op_reg_opr_reg 4) (va_op_reg_opr_reg 4) 16) (va_QEmpty (())))))
[@"opaque_to_smt"]
let va_lemma_Loop_rounds_3_7_11_body va_b0 va_s0 i msg in_b offset =
let (va_mods:va_mods_t) = [va_Mod_reg 4; va_Mod_ok; va_mod_vec_opr msg] in
let va_qc = va_qcode_Loop_rounds_3_7_11_body va_mods i msg in_b offset in
let (va_sM, va_fM, va_g) = va_wp_sound_code_norm (va_code_Loop_rounds_3_7_11_body i msg) va_qc
va_s0 (fun va_s0 va_sM va_g -> let () = va_g in label va_range1
"***** POSTCONDITION NOT MET AT line 55 column 1 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/sha/Vale.SHA.PPC64LE.Rounds.Core.vaf *****"
(va_get_ok va_sM) /\ (label va_range1
"***** POSTCONDITION NOT MET AT line 76 column 73 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/sha/Vale.SHA.PPC64LE.Rounds.Core.vaf *****"
(va_eval_vec_opr va_sM msg == Vale.Def.Types_s.reverse_bytes_quad32
(Vale.PPC64LE.Decls.buffer128_read in_b offset (va_get_mem_heaplet 0 va_sM))) /\ label
va_range1
"***** POSTCONDITION NOT MET AT line 77 column 29 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/sha/Vale.SHA.PPC64LE.Rounds.Core.vaf *****"
(va_get_reg 4 va_sM == va_get_reg 4 va_s0 + 16))) in
assert_norm (va_qc.mods == va_mods);
va_lemma_norm_mods ([va_Mod_reg 4; va_Mod_ok; va_mod_vec_opr msg]) va_sM va_s0;
(va_sM, va_fM)
[@"opaque_to_smt"]
let va_wpProof_Loop_rounds_3_7_11_body i msg in_b offset va_s0 va_k =
let (va_sM, va_f0) = va_lemma_Loop_rounds_3_7_11_body (va_code_Loop_rounds_3_7_11_body i msg)
va_s0 i msg in_b offset in
va_lemma_upd_update va_sM;
assert (va_state_eq va_sM (va_update_reg 4 va_sM (va_update_ok va_sM (va_update_operand_vec_opr
msg va_sM va_s0))));
va_lemma_norm_mods ([va_Mod_reg 4; va_mod_vec_opr msg]) va_sM va_s0;
let va_g = () in
(va_sM, va_f0, va_g)
//--
//-- Loop_rounds_1_15_shift_body
val va_code_Loop_rounds_1_15_shift_body : i:nat -> msg0:va_operand_vec_opr ->
msg1:va_operand_vec_opr -> Tot va_code
[@ "opaque_to_smt" va_qattr]
let va_code_Loop_rounds_1_15_shift_body i msg0 msg1 =
(va_Block (va_CCons (if (i `op_Modulus` 4 = 1) then va_Block (va_CCons (va_code_Vsldoi msg0 msg1
msg1 4) (va_CNil ())) else va_Block (va_CCons (if (i `op_Modulus` 4 = 2) then va_Block
(va_CCons (va_code_Vsldoi msg0 msg1 msg1 8) (va_CNil ())) else va_Block (va_CCons (if (i
`op_Modulus` 4 = 3) then va_Block (va_CCons (va_code_Vsldoi msg0 msg1 msg1 12) (va_CNil ()))
else va_Block (va_CNil ())) (va_CNil ()))) (va_CNil ()))) (va_CNil ())))
val va_codegen_success_Loop_rounds_1_15_shift_body : i:nat -> msg0:va_operand_vec_opr ->
msg1:va_operand_vec_opr -> Tot va_pbool
[@ "opaque_to_smt" va_qattr]
let va_codegen_success_Loop_rounds_1_15_shift_body i msg0 msg1 =
(va_pbool_and (if (i `op_Modulus` 4 = 1) then va_pbool_and (va_codegen_success_Vsldoi msg0 msg1
msg1 4) (va_ttrue ()) else va_pbool_and (if (i `op_Modulus` 4 = 2) then va_pbool_and
(va_codegen_success_Vsldoi msg0 msg1 msg1 8) (va_ttrue ()) else va_pbool_and (if (i
`op_Modulus` 4 = 3) then va_pbool_and (va_codegen_success_Vsldoi msg0 msg1 msg1 12) (va_ttrue
()) else va_ttrue ()) (va_ttrue ())) (va_ttrue ())) (va_ttrue ()))
[@ "opaque_to_smt" va_qattr]
let va_qcode_Loop_rounds_1_15_shift_body (va_mods:va_mods_t) (i:nat) (msg0:vec_opr) (msg1:vec_opr)
(block:block_w) : (va_quickCode unit (va_code_Loop_rounds_1_15_shift_body i msg0 msg1)) =
(qblock va_mods (fun (va_s:va_state) -> let (va_old_s:va_state) = va_s in va_QBind va_range1
"***** PRECONDITION NOT MET AT line 100 column 15 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/sha/Vale.SHA.PPC64LE.Rounds.Core.vaf *****"
(va_qInlineIf va_mods (i `op_Modulus` 4 = 1) (qblock va_mods (fun (va_s:va_state) -> va_QSeq
va_range1
"***** PRECONDITION NOT MET AT line 102 column 15 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/sha/Vale.SHA.PPC64LE.Rounds.Core.vaf *****"
(va_quick_Vsldoi msg0 msg1 msg1 4) (va_QEmpty (())))) (qblock va_mods (fun (va_s:va_state) ->
va_QBind va_range1
"***** PRECONDITION NOT MET AT line 104 column 13 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/sha/Vale.SHA.PPC64LE.Rounds.Core.vaf *****"
(va_qInlineIf va_mods (i `op_Modulus` 4 = 2) (qblock va_mods (fun (va_s:va_state) -> va_QSeq
va_range1
"***** PRECONDITION NOT MET AT line 106 column 15 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/sha/Vale.SHA.PPC64LE.Rounds.Core.vaf *****"
(va_quick_Vsldoi msg0 msg1 msg1 8) (va_QEmpty (())))) (qblock va_mods (fun (va_s:va_state) ->
va_QBind va_range1
"***** PRECONDITION NOT MET AT line 108 column 13 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/sha/Vale.SHA.PPC64LE.Rounds.Core.vaf *****"
(va_qInlineIf va_mods (i `op_Modulus` 4 = 3) (qblock va_mods (fun (va_s:va_state) -> va_QSeq
va_range1
"***** PRECONDITION NOT MET AT line 110 column 15 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/sha/Vale.SHA.PPC64LE.Rounds.Core.vaf *****"
(va_quick_Vsldoi msg0 msg1 msg1 12) (va_QEmpty (())))) (qblock va_mods (fun (va_s:va_state) ->
va_QEmpty (())))) (fun (va_s:va_state) va_g -> va_QEmpty (()))))) (fun (va_s:va_state) va_g ->
va_QEmpty (()))))) (fun (va_s:va_state) va_g -> va_QEmpty (()))))
val va_lemma_Loop_rounds_1_15_shift_body : va_b0:va_code -> va_s0:va_state -> i:nat ->
msg0:va_operand_vec_opr -> msg1:va_operand_vec_opr -> block:block_w
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_Loop_rounds_1_15_shift_body i msg0 msg1) va_s0 /\
va_is_dst_vec_opr msg0 va_s0 /\ va_is_src_vec_opr msg1 va_s0 /\ va_get_ok va_s0 /\ l_and (l_and
(0 <= i) (i < 16)) (i `op_Modulus` 4 =!= 0) /\ msg0 == i /\ msg1 == i - i `op_Modulus` 4 /\ (i
`op_Modulus` 4 == 1 ==> Vale.Def.Words_s.__proj__Mkfour__item__hi2 (va_eval_vec_opr va_s0 msg1)
== Vale.SHA.PPC64LE.SHA_helpers.ws_opaque block i) /\ (i `op_Modulus` 4 == 2 ==>
Vale.Def.Words_s.__proj__Mkfour__item__lo1 (va_eval_vec_opr va_s0 msg1) ==
Vale.SHA.PPC64LE.SHA_helpers.ws_opaque block i) /\ (i `op_Modulus` 4 == 3 ==>
Vale.Def.Words_s.__proj__Mkfour__item__lo0 (va_eval_vec_opr va_s0 msg1) ==
Vale.SHA.PPC64LE.SHA_helpers.ws_opaque block i)))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
Vale.Def.Words_s.__proj__Mkfour__item__hi3 (va_eval_vec_opr va_sM msg0) ==
Vale.SHA.PPC64LE.SHA_helpers.ws_opaque block i /\ va_state_eq va_sM (va_update_ok va_sM
(va_update_operand_vec_opr msg0 va_sM va_s0))))
[@"opaque_to_smt"]
let va_lemma_Loop_rounds_1_15_shift_body va_b0 va_s0 i msg0 msg1 block =
let (va_mods:va_mods_t) = [va_Mod_ok; va_mod_vec_opr msg0] in
let va_qc = va_qcode_Loop_rounds_1_15_shift_body va_mods i msg0 msg1 block in
let (va_sM, va_fM, va_g) = va_wp_sound_code_norm (va_code_Loop_rounds_1_15_shift_body i msg0
msg1) va_qc va_s0 (fun va_s0 va_sM va_g -> let () = va_g in label va_range1
"***** POSTCONDITION NOT MET AT line 83 column 1 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/sha/Vale.SHA.PPC64LE.Rounds.Core.vaf *****"
(va_get_ok va_sM) /\ label va_range1
"***** POSTCONDITION NOT MET AT line 98 column 40 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/sha/Vale.SHA.PPC64LE.Rounds.Core.vaf *****"
(Vale.Def.Words_s.__proj__Mkfour__item__hi3 (va_eval_vec_opr va_sM msg0) ==
Vale.SHA.PPC64LE.SHA_helpers.ws_opaque block i)) in
assert_norm (va_qc.mods == va_mods);
va_lemma_norm_mods ([va_Mod_ok; va_mod_vec_opr msg0]) va_sM va_s0;
(va_sM, va_fM)
[@ va_qattr]
let va_wp_Loop_rounds_1_15_shift_body (i:nat) (msg0:va_operand_vec_opr) (msg1:va_operand_vec_opr)
(block:block_w) (va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 =
(va_is_dst_vec_opr msg0 va_s0 /\ va_is_src_vec_opr msg1 va_s0 /\ va_get_ok va_s0 /\ l_and (l_and
(0 <= i) (i < 16)) (i `op_Modulus` 4 =!= 0) /\ msg0 == i /\ msg1 == i - i `op_Modulus` 4 /\ (i
`op_Modulus` 4 == 1 ==> Vale.Def.Words_s.__proj__Mkfour__item__hi2 (va_eval_vec_opr va_s0 msg1)
== Vale.SHA.PPC64LE.SHA_helpers.ws_opaque block i) /\ (i `op_Modulus` 4 == 2 ==>
Vale.Def.Words_s.__proj__Mkfour__item__lo1 (va_eval_vec_opr va_s0 msg1) ==
Vale.SHA.PPC64LE.SHA_helpers.ws_opaque block i) /\ (i `op_Modulus` 4 == 3 ==>
Vale.Def.Words_s.__proj__Mkfour__item__lo0 (va_eval_vec_opr va_s0 msg1) ==
Vale.SHA.PPC64LE.SHA_helpers.ws_opaque block i) /\ (forall (va_x_msg0:va_value_vec_opr) . let
va_sM = va_upd_operand_vec_opr msg0 va_x_msg0 va_s0 in va_get_ok va_sM /\
Vale.Def.Words_s.__proj__Mkfour__item__hi3 (va_eval_vec_opr va_sM msg0) ==
Vale.SHA.PPC64LE.SHA_helpers.ws_opaque block i ==> va_k va_sM (())))
val va_wpProof_Loop_rounds_1_15_shift_body : i:nat -> msg0:va_operand_vec_opr ->
msg1:va_operand_vec_opr -> block:block_w -> va_s0:va_state -> va_k:(va_state -> unit -> Type0)
-> Ghost (va_state & va_fuel & unit)
(requires (va_t_require va_s0 /\ va_wp_Loop_rounds_1_15_shift_body i msg0 msg1 block va_s0 va_k))
(ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_Loop_rounds_1_15_shift_body i msg0
msg1) ([va_mod_vec_opr msg0]) va_s0 va_k ((va_sM, va_f0, va_g))))
[@"opaque_to_smt"]
let va_wpProof_Loop_rounds_1_15_shift_body i msg0 msg1 block va_s0 va_k =
let (va_sM, va_f0) = va_lemma_Loop_rounds_1_15_shift_body (va_code_Loop_rounds_1_15_shift_body i
msg0 msg1) va_s0 i msg0 msg1 block in
va_lemma_upd_update va_sM;
assert (va_state_eq va_sM (va_update_ok va_sM (va_update_operand_vec_opr msg0 va_sM va_s0)));
va_lemma_norm_mods ([va_mod_vec_opr msg0]) va_sM va_s0;
let va_g = () in
(va_sM, va_f0, va_g)
[@ "opaque_to_smt" va_qattr]
let va_quick_Loop_rounds_1_15_shift_body (i:nat) (msg0:va_operand_vec_opr)
(msg1:va_operand_vec_opr) (block:block_w) : (va_quickCode unit
(va_code_Loop_rounds_1_15_shift_body i msg0 msg1)) =
(va_QProc (va_code_Loop_rounds_1_15_shift_body i msg0 msg1) ([va_mod_vec_opr msg0])
(va_wp_Loop_rounds_1_15_shift_body i msg0 msg1 block) (va_wpProof_Loop_rounds_1_15_shift_body i
msg0 msg1 block))
//--
//-- Loop_rounds_16_63_body
[@ "opaque_to_smt" va_qattr]
let va_code_Loop_rounds_16_63_body i msg0 msg1 msg2 msg3 =
(va_Block (va_CCons (va_code_SHA256_sigma0 (va_op_vec_opr_vec 25) msg1) (va_CCons
(va_code_Vadduwm msg0 msg0 (va_op_vec_opr_vec 25)) (va_CCons (va_code_SHA256_sigma1
(va_op_vec_opr_vec 26) msg3) (va_CCons (va_code_Vadduwm msg0 msg0 (va_op_vec_opr_vec 26))
(va_CCons (va_code_Vadduwm msg0 msg0 msg2) (va_CNil ())))))))
[@ "opaque_to_smt" va_qattr]
let va_codegen_success_Loop_rounds_16_63_body i msg0 msg1 msg2 msg3 =
(va_pbool_and (va_pbool_and (va_codegen_success_SHA256_sigma0 (va_op_vec_opr_vec 25) msg1)
(va_codegen_success_SHA256_sigma0 (va_op_vec_opr_vec 25) msg1)) (va_pbool_and (va_pbool_and
(va_codegen_success_Vadduwm msg0 msg0 (va_op_vec_opr_vec 25)) (va_codegen_success_Vadduwm msg0
msg0 (va_op_vec_opr_vec 25))) (va_pbool_and (va_pbool_and (va_codegen_success_SHA256_sigma1
(va_op_vec_opr_vec 26) msg3) (va_codegen_success_SHA256_sigma1 (va_op_vec_opr_vec 26) msg3))
(va_pbool_and (va_pbool_and (va_codegen_success_Vadduwm msg0 msg0 (va_op_vec_opr_vec 26))
(va_codegen_success_Vadduwm msg0 msg0 (va_op_vec_opr_vec 26))) (va_pbool_and (va_pbool_and
(va_codegen_success_Vadduwm msg0 msg0 msg2) (va_codegen_success_Vadduwm msg0 msg0 msg2))
(va_ttrue ()))))))
[@ "opaque_to_smt" va_qattr]
let va_qcode_Loop_rounds_16_63_body (va_mods:va_mods_t) (i:nat) (msg0:vec_opr) (msg1:vec_opr)
(msg2:vec_opr) (msg3:vec_opr) (block:block_w) : (va_quickCode unit
(va_code_Loop_rounds_16_63_body i msg0 msg1 msg2 msg3)) =
(qblock va_mods (fun (va_s:va_state) -> let (va_old_s:va_state) = va_s in va_QBind va_range1
"***** PRECONDITION NOT MET AT line 145 column 18 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/sha/Vale.SHA.PPC64LE.Rounds.Core.vaf *****"
(va_quick_SHA256_sigma0 (va_op_vec_opr_vec 25) msg1 i block) (fun (va_s:va_state) _ -> va_qPURE
va_range1
"***** PRECONDITION NOT MET AT line 146 column 28 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/sha/Vale.SHA.PPC64LE.Rounds.Core.vaf *****"
(fun (_:unit) -> lemma_sigma_0_0_partial i block) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 147 column 12 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/sha/Vale.SHA.PPC64LE.Rounds.Core.vaf *****"
(va_quick_Vadduwm msg0 msg0 (va_op_vec_opr_vec 25)) (va_QBind va_range1
"***** PRECONDITION NOT MET AT line 148 column 18 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/sha/Vale.SHA.PPC64LE.Rounds.Core.vaf *****"
(va_quick_SHA256_sigma1 (va_op_vec_opr_vec 26) msg3 i block) (fun (va_s:va_state) _ -> va_qPURE
va_range1
"***** PRECONDITION NOT MET AT line 149 column 28 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/sha/Vale.SHA.PPC64LE.Rounds.Core.vaf *****"
(fun (_:unit) -> lemma_sigma_0_1_partial i block) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 150 column 12 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/sha/Vale.SHA.PPC64LE.Rounds.Core.vaf *****"
(va_quick_Vadduwm msg0 msg0 (va_op_vec_opr_vec 26)) (va_QBind va_range1
"***** PRECONDITION NOT MET AT line 151 column 12 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/sha/Vale.SHA.PPC64LE.Rounds.Core.vaf *****"
(va_quick_Vadduwm msg0 msg0 msg2) (fun (va_s:va_state) _ -> va_qPURE va_range1
"***** PRECONDITION NOT MET AT line 152 column 20 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/sha/Vale.SHA.PPC64LE.Rounds.Core.vaf *****"
(fun (_:unit) -> lemma_ws_opaque block i) (va_QEmpty (())))))))))))
[@"opaque_to_smt"]
let va_lemma_Loop_rounds_16_63_body va_b0 va_s0 i msg0 msg1 msg2 msg3 block =
let (va_mods:va_mods_t) = [va_Mod_vec 26; va_Mod_vec 25; va_Mod_ok; va_mod_vec_opr msg0] in
let va_qc = va_qcode_Loop_rounds_16_63_body va_mods i msg0 msg1 msg2 msg3 block in
let (va_sM, va_fM, va_g) = va_wp_sound_code_norm (va_code_Loop_rounds_16_63_body i msg0 msg1 msg2
msg3) va_qc va_s0 (fun va_s0 va_sM va_g -> let () = va_g in label va_range1
"***** POSTCONDITION NOT MET AT line 114 column 1 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/sha/Vale.SHA.PPC64LE.Rounds.Core.vaf *****"
(va_get_ok va_sM) /\ label va_range1
"***** POSTCONDITION NOT MET AT line 140 column 9 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/sha/Vale.SHA.PPC64LE.Rounds.Core.vaf *****"
(let sigma0 = sigma256_0_0 (ws_opaque block (i - 15)) in label va_range1
"***** POSTCONDITION NOT MET AT line 141 column 9 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/sha/Vale.SHA.PPC64LE.Rounds.Core.vaf *****"
(let sigma1 = sigma256_0_1 (ws_opaque block (i - 2)) in label va_range1
"***** POSTCONDITION NOT MET AT line 142 column 118 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/sha/Vale.SHA.PPC64LE.Rounds.Core.vaf *****"
((va_eval_vec_opr va_sM msg0).hi3 == add_wrap32 (add_wrap32 (add_wrap32 (ws_opaque block (i -
16)) sigma0) sigma1) (ws_opaque block (i - 7))) /\ label va_range1
"***** POSTCONDITION NOT MET AT line 143 column 40 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/sha/Vale.SHA.PPC64LE.Rounds.Core.vaf *****"
((va_eval_vec_opr va_sM msg0).hi3 == ws_opaque block i)))) in
assert_norm (va_qc.mods == va_mods);
va_lemma_norm_mods ([va_Mod_vec 26; va_Mod_vec 25; va_Mod_ok; va_mod_vec_opr msg0]) va_sM va_s0;
(va_sM, va_fM)
[@"opaque_to_smt"]
let va_wpProof_Loop_rounds_16_63_body i msg0 msg1 msg2 msg3 block va_s0 va_k =
let (va_sM, va_f0) = va_lemma_Loop_rounds_16_63_body (va_code_Loop_rounds_16_63_body i msg0 msg1
msg2 msg3) va_s0 i msg0 msg1 msg2 msg3 block in
va_lemma_upd_update va_sM;
assert (va_state_eq va_sM (va_update_vec 26 va_sM (va_update_vec 25 va_sM (va_update_ok va_sM
(va_update_operand_vec_opr msg0 va_sM va_s0)))));
va_lemma_norm_mods ([va_Mod_vec 26; va_Mod_vec 25; va_mod_vec_opr msg0]) va_sM va_s0;
let va_g = () in
(va_sM, va_f0, va_g)
//--
//-- Loop_rounds_0_63_body
val va_code_Loop_rounds_0_63_body : i:nat -> msg:va_operand_vec_opr -> a_vec:va_operand_vec_opr ->
b_vec:va_operand_vec_opr -> c_vec:va_operand_vec_opr -> d_vec:va_operand_vec_opr ->
e_vec:va_operand_vec_opr -> f_vec:va_operand_vec_opr -> g_vec:va_operand_vec_opr ->
h_vec:va_operand_vec_opr -> Tot va_code
[@ "opaque_to_smt" va_qattr]
let va_code_Loop_rounds_0_63_body i msg a_vec b_vec c_vec d_vec e_vec f_vec g_vec h_vec =
(va_Block (va_CCons (va_code_Vadduwm h_vec h_vec msg) (va_CCons (va_code_Vsel (va_op_vec_opr_vec
25) g_vec f_vec e_vec) (va_CCons (if op_disEquality i 63 then va_Block (va_CCons
(va_code_Vadduwm g_vec g_vec (va_op_vec_opr_vec 24)) (va_CNil ())) else va_Block (va_CNil ()))
(va_CCons (va_code_Vadduwm h_vec h_vec (va_op_vec_opr_vec 25)) (va_CCons (va_code_SHA256_Sigma1
(va_op_vec_opr_vec 26) e_vec) (va_CCons (va_code_Vadduwm h_vec h_vec (va_op_vec_opr_vec 26))
(va_CCons (va_code_Vxor (va_op_vec_opr_vec 25) a_vec b_vec) (va_CCons (va_code_Vsel
(va_op_vec_opr_vec 25) b_vec c_vec (va_op_vec_opr_vec 25)) (va_CCons (va_code_Vadduwm d_vec
d_vec h_vec) (va_CCons (va_code_SHA256_Sigma0 (va_op_vec_opr_vec 26) a_vec) (va_CCons
(va_code_Vadduwm (va_op_vec_opr_vec 26) (va_op_vec_opr_vec 26) (va_op_vec_opr_vec 25))
(va_CCons (va_code_Vadduwm h_vec h_vec (va_op_vec_opr_vec 26)) (va_CCons (if (i = 63) then
va_Block (va_CNil ()) else va_Block (va_CNil ())) (va_CNil ())))))))))))))))
val va_codegen_success_Loop_rounds_0_63_body : i:nat -> msg:va_operand_vec_opr ->
a_vec:va_operand_vec_opr -> b_vec:va_operand_vec_opr -> c_vec:va_operand_vec_opr ->
d_vec:va_operand_vec_opr -> e_vec:va_operand_vec_opr -> f_vec:va_operand_vec_opr ->
g_vec:va_operand_vec_opr -> h_vec:va_operand_vec_opr -> Tot va_pbool
[@ "opaque_to_smt" va_qattr]
let va_codegen_success_Loop_rounds_0_63_body i msg a_vec b_vec c_vec d_vec e_vec f_vec g_vec h_vec =
(va_pbool_and (va_codegen_success_Vadduwm h_vec h_vec msg) (va_pbool_and (va_codegen_success_Vsel
(va_op_vec_opr_vec 25) g_vec f_vec e_vec) (va_pbool_and (if op_disEquality i 63 then
va_pbool_and (va_codegen_success_Vadduwm g_vec g_vec (va_op_vec_opr_vec 24)) (va_ttrue ()) else
va_ttrue ()) (va_pbool_and (va_codegen_success_Vadduwm h_vec h_vec (va_op_vec_opr_vec 25))
(va_pbool_and (va_codegen_success_SHA256_Sigma1 (va_op_vec_opr_vec 26) e_vec) (va_pbool_and
(va_codegen_success_Vadduwm h_vec h_vec (va_op_vec_opr_vec 26)) (va_pbool_and
(va_codegen_success_Vxor (va_op_vec_opr_vec 25) a_vec b_vec) (va_pbool_and
(va_codegen_success_Vsel (va_op_vec_opr_vec 25) b_vec c_vec (va_op_vec_opr_vec 25))
(va_pbool_and (va_codegen_success_Vadduwm d_vec d_vec h_vec) (va_pbool_and
(va_codegen_success_SHA256_Sigma0 (va_op_vec_opr_vec 26) a_vec) (va_pbool_and
(va_codegen_success_Vadduwm (va_op_vec_opr_vec 26) (va_op_vec_opr_vec 26) (va_op_vec_opr_vec
25)) (va_pbool_and (va_codegen_success_Vadduwm h_vec h_vec (va_op_vec_opr_vec 26))
(va_pbool_and (if (i = 63) then va_ttrue () else va_ttrue ()) (va_ttrue ()))))))))))))))
[@ "opaque_to_smt" va_qattr]
let va_qcode_Loop_rounds_0_63_body (va_mods:va_mods_t) (i:nat) (msg:vec_opr) (a_vec:vec_opr)
(b_vec:vec_opr) (c_vec:vec_opr) (d_vec:vec_opr) (e_vec:vec_opr) (f_vec:vec_opr) (g_vec:vec_opr)
(h_vec:vec_opr) (k_b:buffer128) (block:block_w) (hash_orig:hash256) : (va_quickCode unit
(va_code_Loop_rounds_0_63_body i msg a_vec b_vec c_vec d_vec e_vec f_vec g_vec h_vec)) =
(qblock va_mods (fun (va_s:va_state) -> let (va_old_s:va_state) = va_s in va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 227 column 12 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/sha/Vale.SHA.PPC64LE.Rounds.Core.vaf *****"
(va_quick_Vadduwm h_vec h_vec msg) (va_QBind va_range1
"***** PRECONDITION NOT MET AT line 228 column 9 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/sha/Vale.SHA.PPC64LE.Rounds.Core.vaf *****"
(va_quick_Vsel (va_op_vec_opr_vec 25) g_vec f_vec e_vec) (fun (va_s:va_state) _ -> let
(va_arg53:Vale.Def.Words_s.nat32) = Vale.Def.Words_s.__proj__Mkfour__item__hi3 (va_eval_vec_opr
va_old_s e_vec) in let (va_arg52:Vale.Def.Words_s.nat32) =
Vale.Def.Words_s.__proj__Mkfour__item__hi3 (va_eval_vec_opr va_old_s g_vec) in let
(va_arg51:Vale.Def.Words_s.nat32) = Vale.Def.Words_s.__proj__Mkfour__item__hi3 (va_eval_vec_opr
va_old_s f_vec) in va_qPURE va_range1
"***** PRECONDITION NOT MET AT line 229 column 17 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/sha/Vale.SHA.PPC64LE.Rounds.Core.vaf *****"
(fun (_:unit) -> Vale.SHA.PPC64LE.SHA_helpers.lemma_vsel32 va_arg51 va_arg52 va_arg53)
(va_QBind va_range1
"***** PRECONDITION NOT MET AT line 230 column 15 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/sha/Vale.SHA.PPC64LE.Rounds.Core.vaf *****"
(va_qInlineIf va_mods (op_disEquality i 63) (qblock va_mods (fun (va_s:va_state) -> va_QSeq
va_range1
"***** PRECONDITION NOT MET AT line 232 column 16 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/sha/Vale.SHA.PPC64LE.Rounds.Core.vaf *****"
(va_quick_Vadduwm g_vec g_vec (va_op_vec_opr_vec 24)) (va_QEmpty (())))) (qblock va_mods (fun
(va_s:va_state) -> va_QEmpty (())))) (fun (va_s:va_state) va_g -> va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 234 column 12 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/sha/Vale.SHA.PPC64LE.Rounds.Core.vaf *****"
(va_quick_Vadduwm h_vec h_vec (va_op_vec_opr_vec 25)) (va_QBind va_range1
"***** PRECONDITION NOT MET AT line 235 column 18 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/sha/Vale.SHA.PPC64LE.Rounds.Core.vaf *****"
(va_quick_SHA256_Sigma1 (va_op_vec_opr_vec 26) e_vec i block hash_orig) (fun (va_s:va_state) _
-> let (va_arg50:Vale.SHA.PPC64LE.SHA_helpers.hash256) = hash_orig in let
(va_arg49:Vale.SHA.PPC64LE.SHA_helpers.block_w) = block in let
(va_arg48:Vale.SHA.PPC64LE.SHA_helpers.counter) = i in va_qPURE va_range1
"***** PRECONDITION NOT MET AT line 236 column 28 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/sha/Vale.SHA.PPC64LE.Rounds.Core.vaf *****"
(fun (_:unit) -> Vale.SHA.PPC64LE.SHA_helpers.lemma_sigma_1_1_partial va_arg48 va_arg49
va_arg50) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 237 column 12 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/sha/Vale.SHA.PPC64LE.Rounds.Core.vaf *****"
(va_quick_Vadduwm h_vec h_vec (va_op_vec_opr_vec 26)) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 238 column 9 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/sha/Vale.SHA.PPC64LE.Rounds.Core.vaf *****"
(va_quick_Vxor (va_op_vec_opr_vec 25) a_vec b_vec) (va_QBind va_range1
"***** PRECONDITION NOT MET AT line 239 column 9 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/sha/Vale.SHA.PPC64LE.Rounds.Core.vaf *****"
(va_quick_Vsel (va_op_vec_opr_vec 25) b_vec c_vec (va_op_vec_opr_vec 25)) (fun (va_s:va_state)
_ -> va_qPURE va_range1
"***** PRECONDITION NOT MET AT line 240 column 22 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/sha/Vale.SHA.PPC64LE.Rounds.Core.vaf *****"
(fun (_:unit) -> Vale.Def.Types_s.quad32_xor_reveal ()) (let (va_arg47:Vale.Def.Words_s.nat32)
= Vale.Def.Words_s.__proj__Mkfour__item__hi3 (va_eval_vec_opr va_old_s c_vec) in let
(va_arg46:Vale.Def.Words_s.nat32) = Vale.Def.Words_s.__proj__Mkfour__item__hi3 (va_eval_vec_opr
va_old_s b_vec) in let (va_arg45:Vale.Def.Words_s.nat32) =
Vale.Def.Words_s.__proj__Mkfour__item__hi3 (va_eval_vec_opr va_old_s a_vec) in va_qPURE
va_range1
"***** PRECONDITION NOT MET AT line 241 column 25 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/sha/Vale.SHA.PPC64LE.Rounds.Core.vaf *****"
(fun (_:unit) -> Vale.SHA.PPC64LE.SHA_helpers.lemma_eq_maj_xvsel32 va_arg45 va_arg46 va_arg47)
(va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 242 column 12 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/sha/Vale.SHA.PPC64LE.Rounds.Core.vaf *****"
(va_quick_Vadduwm d_vec d_vec h_vec) (va_QBind va_range1
"***** PRECONDITION NOT MET AT line 243 column 18 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/sha/Vale.SHA.PPC64LE.Rounds.Core.vaf *****"
(va_quick_SHA256_Sigma0 (va_op_vec_opr_vec 26) a_vec i block hash_orig) (fun (va_s:va_state) _
-> let (va_arg44:Vale.SHA.PPC64LE.SHA_helpers.hash256) = hash_orig in let
(va_arg43:Vale.SHA.PPC64LE.SHA_helpers.block_w) = block in let
(va_arg42:Vale.SHA.PPC64LE.SHA_helpers.counter) = i in va_qPURE va_range1
"***** PRECONDITION NOT MET AT line 244 column 28 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/sha/Vale.SHA.PPC64LE.Rounds.Core.vaf *****"
(fun (_:unit) -> Vale.SHA.PPC64LE.SHA_helpers.lemma_sigma_1_0_partial va_arg42 va_arg43
va_arg44) (va_QSeq va_range1
"***** PRECONDITION NOT MET AT line 245 column 12 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/sha/Vale.SHA.PPC64LE.Rounds.Core.vaf *****"
(va_quick_Vadduwm (va_op_vec_opr_vec 26) (va_op_vec_opr_vec 26) (va_op_vec_opr_vec 25))
(va_QBind va_range1
"***** PRECONDITION NOT MET AT line 246 column 12 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/sha/Vale.SHA.PPC64LE.Rounds.Core.vaf *****"
(va_quick_Vadduwm h_vec h_vec (va_op_vec_opr_vec 26)) (fun (va_s:va_state) _ -> let
(va_arg41:Vale.SHA.PPC64LE.SHA_helpers.hash256) = hash_orig in let
(va_arg40:Vale.SHA.PPC64LE.SHA_helpers.block_w) = block in let
(va_arg39:Vale.SHA.PPC64LE.SHA_helpers.counter) = i in va_qPURE va_range1
"***** PRECONDITION NOT MET AT line 247 column 34 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/sha/Vale.SHA.PPC64LE.Rounds.Core.vaf *****"
(fun (_:unit) -> Vale.SHA.PPC64LE.SHA_helpers.lemma_shuffle_core_properties va_arg39 va_arg40
va_arg41) (va_QBind va_range1
"***** PRECONDITION NOT MET AT line 248 column 15 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/sha/Vale.SHA.PPC64LE.Rounds.Core.vaf *****"
(va_qInlineIf va_mods (i = 63) (qblock va_mods (fun (va_s:va_state) -> let
(va_arg38:Vale.Def.Types_s.quad32) = va_eval_vec_opr va_s g_vec in let
(va_arg37:Vale.Def.Types_s.quad32) = va_eval_vec_opr va_s f_vec in let
(va_arg36:Vale.Def.Types_s.quad32) = va_eval_vec_opr va_s e_vec in let
(va_arg35:Vale.Def.Types_s.quad32) = va_eval_vec_opr va_s d_vec in let
(va_arg34:Vale.Def.Types_s.quad32) = va_eval_vec_opr va_s c_vec in let
(va_arg33:Vale.Def.Types_s.quad32) = va_eval_vec_opr va_s b_vec in let
(va_arg32:Vale.Def.Types_s.quad32) = va_eval_vec_opr va_s a_vec in let
(va_arg31:Vale.Def.Types_s.quad32) = va_eval_vec_opr va_s h_vec in let
(va_arg30:Vale.SHA.PPC64LE.SHA_helpers.hash256) =
Vale.SHA.PPC64LE.SHA_helpers.repeat_range_vale_64 block hash_orig in va_qPURE va_range1
"***** PRECONDITION NOT MET AT line 250 column 34 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/sha/Vale.SHA.PPC64LE.Rounds.Core.vaf *****"
(fun (_:unit) -> Vale.SHA.PPC64LE.SHA_helpers.lemma_make_seperated_hash va_arg30 va_arg31
va_arg32 va_arg33 va_arg34 va_arg35 va_arg36 va_arg37 va_arg38) (va_QEmpty (())))) (qblock
va_mods (fun (va_s:va_state) -> va_QEmpty (())))) (fun (va_s:va_state) va_g -> va_QEmpty
(()))))))))))))))))))))))
val va_lemma_Loop_rounds_0_63_body : va_b0:va_code -> va_s0:va_state -> i:nat ->
msg:va_operand_vec_opr -> a_vec:va_operand_vec_opr -> b_vec:va_operand_vec_opr ->
c_vec:va_operand_vec_opr -> d_vec:va_operand_vec_opr -> e_vec:va_operand_vec_opr ->
f_vec:va_operand_vec_opr -> g_vec:va_operand_vec_opr -> h_vec:va_operand_vec_opr -> k_b:buffer128
-> block:block_w -> hash_orig:hash256
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_Loop_rounds_0_63_body i msg a_vec b_vec c_vec d_vec
e_vec f_vec g_vec h_vec) va_s0 /\ va_is_src_vec_opr msg va_s0 /\ va_is_src_vec_opr a_vec va_s0
/\ va_is_src_vec_opr b_vec va_s0 /\ va_is_src_vec_opr c_vec va_s0 /\ va_is_dst_vec_opr d_vec
va_s0 /\ va_is_src_vec_opr e_vec va_s0 /\ va_is_src_vec_opr f_vec va_s0 /\ va_is_dst_vec_opr
g_vec va_s0 /\ va_is_dst_vec_opr h_vec va_s0 /\ va_get_ok va_s0 /\ (l_and (0 <= i) (i < 64) /\
msg == i `op_Modulus` 16 /\ (i `op_Modulus` 8 == 0 ==> a_vec == 16 /\ b_vec == 17 /\ c_vec ==
18 /\ d_vec == 19 /\ e_vec == 20 /\ f_vec == 21 /\ g_vec == 22 /\ h_vec == 23) /\ (i
`op_Modulus` 8 == 1 ==> a_vec == 23 /\ b_vec == 16 /\ c_vec == 17 /\ d_vec == 18 /\ e_vec == 19
/\ f_vec == 20 /\ g_vec == 21 /\ h_vec == 22) /\ (i `op_Modulus` 8 == 2 ==> a_vec == 22 /\
b_vec == 23 /\ c_vec == 16 /\ d_vec == 17 /\ e_vec == 18 /\ f_vec == 19 /\ g_vec == 20 /\ h_vec
== 21) /\ (i `op_Modulus` 8 == 3 ==> a_vec == 21 /\ b_vec == 22 /\ c_vec == 23 /\ d_vec == 16
/\ e_vec == 17 /\ f_vec == 18 /\ g_vec == 19 /\ h_vec == 20) /\ (i `op_Modulus` 8 == 4 ==>
a_vec == 20 /\ b_vec == 21 /\ c_vec == 22 /\ d_vec == 23 /\ e_vec == 16 /\ f_vec == 17 /\ g_vec
== 18 /\ h_vec == 19) /\ (i `op_Modulus` 8 == 5 ==> a_vec == 19 /\ b_vec == 20 /\ c_vec == 21
/\ d_vec == 22 /\ e_vec == 23 /\ f_vec == 16 /\ g_vec == 17 /\ h_vec == 18) /\ (i `op_Modulus`
8 == 6 ==> a_vec == 18 /\ b_vec == 19 /\ c_vec == 20 /\ d_vec == 21 /\ e_vec == 22 /\ f_vec ==
23 /\ g_vec == 16 /\ h_vec == 17) /\ (i `op_Modulus` 8 == 7 ==> a_vec == 17 /\ b_vec == 18 /\
c_vec == 19 /\ d_vec == 20 /\ e_vec == 21 /\ f_vec == 22 /\ g_vec == 23 /\ h_vec == 16) /\ (let
ks = Vale.PPC64LE.Decls.buffer128_as_seq (va_get_mem_heaplet 0 va_s0) k_b in
Vale.SHA.PPC64LE.SHA_helpers.k_reqs ks /\ (let hash =
Vale.SHA.PPC64LE.SHA_helpers.repeat_range_vale i block hash_orig in
Vale.Def.Words_s.__proj__Mkfour__item__hi3 (va_eval_vec_opr va_s0 a_vec) ==
Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32 (FStar.Seq.Base.index
#Vale.SHA.PPC64LE.SHA_helpers.word hash 0) /\ Vale.Def.Words_s.__proj__Mkfour__item__hi3
(va_eval_vec_opr va_s0 b_vec) == Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32
(FStar.Seq.Base.index #Vale.SHA.PPC64LE.SHA_helpers.word hash 1) /\
Vale.Def.Words_s.__proj__Mkfour__item__hi3 (va_eval_vec_opr va_s0 c_vec) ==
Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32 (FStar.Seq.Base.index
#Vale.SHA.PPC64LE.SHA_helpers.word hash 2) /\ Vale.Def.Words_s.__proj__Mkfour__item__hi3
(va_eval_vec_opr va_s0 d_vec) == Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32
(FStar.Seq.Base.index #Vale.SHA.PPC64LE.SHA_helpers.word hash 3) /\
Vale.Def.Words_s.__proj__Mkfour__item__hi3 (va_eval_vec_opr va_s0 e_vec) ==
Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32 (FStar.Seq.Base.index
#Vale.SHA.PPC64LE.SHA_helpers.word hash 4) /\ Vale.Def.Words_s.__proj__Mkfour__item__hi3
(va_eval_vec_opr va_s0 f_vec) == Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32
(FStar.Seq.Base.index #Vale.SHA.PPC64LE.SHA_helpers.word hash 5) /\
Vale.Def.Words_s.__proj__Mkfour__item__hi3 (va_eval_vec_opr va_s0 g_vec) ==
Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32 (FStar.Seq.Base.index
#Vale.SHA.PPC64LE.SHA_helpers.word hash 6) /\ Vale.Def.Words_s.__proj__Mkfour__item__hi3
(va_eval_vec_opr va_s0 h_vec) == Vale.Arch.Types.add_wrap32
(Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32 (FStar.Seq.Base.index
#Vale.SHA.PPC64LE.SHA_helpers.word hash 7)) (Vale.SHA.PPC64LE.SHA_helpers.k_index ks i) /\
Vale.Def.Words_s.__proj__Mkfour__item__hi3 (va_eval_vec_opr va_s0 msg) ==
Vale.SHA.PPC64LE.SHA_helpers.ws_opaque block i /\ (i =!= 63 ==> (va_get_vec 24 va_s0).hi3 ==
Vale.SHA.PPC64LE.SHA_helpers.k_index ks (i + 1)))))))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
(let ks = Vale.PPC64LE.Decls.buffer128_as_seq (va_get_mem_heaplet 0 va_sM) k_b in let hash =
Vale.SHA.PPC64LE.SHA_helpers.repeat_range_vale i block hash_orig in let h_k =
Vale.Arch.Types.add_wrap32 (Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32 (FStar.Seq.Base.index
#Vale.SHA.PPC64LE.SHA_helpers.word hash 7)) (Vale.SHA.PPC64LE.SHA_helpers.k_index ks i) in let
ch = Vale.SHA.PPC64LE.SHA_helpers.ch_256 (Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32
(FStar.Seq.Base.index #Vale.SHA.PPC64LE.SHA_helpers.word hash 4))
(Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32 (FStar.Seq.Base.index
#Vale.SHA.PPC64LE.SHA_helpers.word hash 5)) (Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32
(FStar.Seq.Base.index #Vale.SHA.PPC64LE.SHA_helpers.word hash 6)) in let sigma1 =
Vale.SHA2.Wrapper.sigma256_1_1 (Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32
(FStar.Seq.Base.index #Vale.SHA.PPC64LE.SHA_helpers.word hash 4)) in let sigma0 =
Vale.SHA2.Wrapper.sigma256_1_0 (Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32
(FStar.Seq.Base.index #Vale.SHA.PPC64LE.SHA_helpers.word hash 0)) in let maj =
Vale.SHA.PPC64LE.SHA_helpers.maj_256 (Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32
(FStar.Seq.Base.index #Vale.SHA.PPC64LE.SHA_helpers.word hash 0))
(Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32 (FStar.Seq.Base.index
#Vale.SHA.PPC64LE.SHA_helpers.word hash 1)) (Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32
(FStar.Seq.Base.index #Vale.SHA.PPC64LE.SHA_helpers.word hash 2)) in let sigma0_maj =
Vale.Arch.Types.add_wrap32 sigma0 maj in Vale.Def.Words_s.__proj__Mkfour__item__hi3
(va_eval_vec_opr va_sM d_vec) == Vale.Arch.Types.add_wrap32
(Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32 (FStar.Seq.Base.index
#Vale.SHA.PPC64LE.SHA_helpers.word hash 3)) (Vale.Arch.Types.add_wrap32
(Vale.Arch.Types.add_wrap32 (Vale.Arch.Types.add_wrap32 h_k
(Vale.SHA.PPC64LE.SHA_helpers.ws_opaque block i)) ch) sigma1) /\
Vale.Def.Words_s.__proj__Mkfour__item__hi3 (va_eval_vec_opr va_sM h_vec) ==
Vale.Arch.Types.add_wrap32 (Vale.Arch.Types.add_wrap32 (Vale.Arch.Types.add_wrap32
(Vale.Arch.Types.add_wrap32 h_k (Vale.SHA.PPC64LE.SHA_helpers.ws_opaque block i)) ch) sigma1)
sigma0_maj /\ (i =!= 63 ==> Vale.Def.Words_s.__proj__Mkfour__item__hi3 (va_eval_vec_opr va_sM
g_vec) == Vale.Arch.Types.add_wrap32 (Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32
(FStar.Seq.Base.index #Vale.SHA.PPC64LE.SHA_helpers.word hash 6))
(Vale.SHA.PPC64LE.SHA_helpers.k_index ks (i + 1))) /\ (i =!= 63 ==> (let next_hash =
Vale.SHA.PPC64LE.SHA_helpers.repeat_range_vale (i + 1) block hash_orig in l_and (l_and (l_and
(l_and (l_and (l_and (l_and (Vale.Def.Words_s.__proj__Mkfour__item__hi3 (va_eval_vec_opr va_sM
a_vec) == Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32 (FStar.Seq.Base.index
#Vale.SHA.PPC64LE.SHA_helpers.word next_hash 1)) (Vale.Def.Words_s.__proj__Mkfour__item__hi3
(va_eval_vec_opr va_sM b_vec) == Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32
(FStar.Seq.Base.index #Vale.SHA.PPC64LE.SHA_helpers.word next_hash 2)))
(Vale.Def.Words_s.__proj__Mkfour__item__hi3 (va_eval_vec_opr va_sM c_vec) ==
Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32 (FStar.Seq.Base.index
#Vale.SHA.PPC64LE.SHA_helpers.word next_hash 3))) (Vale.Def.Words_s.__proj__Mkfour__item__hi3
(va_eval_vec_opr va_sM d_vec) == Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32
(FStar.Seq.Base.index #Vale.SHA.PPC64LE.SHA_helpers.word next_hash 4)))
(Vale.Def.Words_s.__proj__Mkfour__item__hi3 (va_eval_vec_opr va_sM e_vec) ==
Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32 (FStar.Seq.Base.index
#Vale.SHA.PPC64LE.SHA_helpers.word next_hash 5))) (Vale.Def.Words_s.__proj__Mkfour__item__hi3
(va_eval_vec_opr va_sM f_vec) == Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32
(FStar.Seq.Base.index #Vale.SHA.PPC64LE.SHA_helpers.word next_hash 6)))
(Vale.Def.Words_s.__proj__Mkfour__item__hi3 (va_eval_vec_opr va_sM g_vec) ==
Vale.Arch.Types.add_wrap32 (Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32 (FStar.Seq.Base.index
#Vale.SHA.PPC64LE.SHA_helpers.word next_hash 7)) (Vale.SHA.PPC64LE.SHA_helpers.k_index ks (i +
1)))) (Vale.Def.Words_s.__proj__Mkfour__item__hi3 (va_eval_vec_opr va_sM h_vec) ==
Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32 (FStar.Seq.Base.index
#Vale.SHA.PPC64LE.SHA_helpers.word next_hash 0)))) /\ (i == 63 ==>
Vale.SHA.PPC64LE.SHA_helpers.make_seperated_hash_quad32 (va_eval_vec_opr va_sM h_vec)
(va_eval_vec_opr va_sM a_vec) (va_eval_vec_opr va_sM b_vec) (va_eval_vec_opr va_sM c_vec)
(va_eval_vec_opr va_sM d_vec) (va_eval_vec_opr va_sM e_vec) (va_eval_vec_opr va_sM f_vec)
(va_eval_vec_opr va_sM g_vec) == Vale.SHA.PPC64LE.SHA_helpers.repeat_range_vale_64 block
hash_orig)) /\ va_state_eq va_sM (va_update_vec 26 va_sM (va_update_vec 25 va_sM (va_update_ok
va_sM (va_update_operand_vec_opr h_vec va_sM (va_update_operand_vec_opr g_vec va_sM
(va_update_operand_vec_opr d_vec va_sM va_s0)))))))) | {
"checked_file": "/",
"dependencies": [
"Vale.SHA2.Wrapper.fsti.checked",
"Vale.SHA.PPC64LE.SHA_helpers.fsti.checked",
"Vale.PPC64LE.State.fsti.checked",
"Vale.PPC64LE.Stack_i.fsti.checked",
"Vale.PPC64LE.QuickCodes.fsti.checked",
"Vale.PPC64LE.QuickCode.fst.checked",
"Vale.PPC64LE.Memory.fsti.checked",
"Vale.PPC64LE.Machine_s.fst.checked",
"Vale.PPC64LE.InsVector.fsti.checked",
"Vale.PPC64LE.InsStack.fsti.checked",
"Vale.PPC64LE.InsMem.fsti.checked",
"Vale.PPC64LE.InsBasic.fsti.checked",
"Vale.PPC64LE.Decls.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Spec.SHA2.fsti.checked",
"Spec.Loops.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.SHA.PPC64LE.Rounds.Core.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.SHA2.Wrapper",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Loops",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA.PPC64LE.SHA_helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.InsVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.InsStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.InsMem",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.InsBasic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.QuickCodes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Stack_i",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA2.Wrapper",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Loops",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA.PPC64LE.SHA_helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.InsVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.InsStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.InsMem",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.InsBasic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.QuickCodes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Stack_i",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA.PPC64LE.Rounds",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA.PPC64LE.Rounds",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 2000,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
va_b0: Vale.PPC64LE.Decls.va_code ->
va_s0: Vale.PPC64LE.Decls.va_state ->
i: Prims.nat ->
msg: Vale.PPC64LE.Decls.va_operand_vec_opr ->
a_vec: Vale.PPC64LE.Decls.va_operand_vec_opr ->
b_vec: Vale.PPC64LE.Decls.va_operand_vec_opr ->
c_vec: Vale.PPC64LE.Decls.va_operand_vec_opr ->
d_vec: Vale.PPC64LE.Decls.va_operand_vec_opr ->
e_vec: Vale.PPC64LE.Decls.va_operand_vec_opr ->
f_vec: Vale.PPC64LE.Decls.va_operand_vec_opr ->
g_vec: Vale.PPC64LE.Decls.va_operand_vec_opr ->
h_vec: Vale.PPC64LE.Decls.va_operand_vec_opr ->
k_b: Vale.PPC64LE.Memory.buffer128 ->
block: Vale.SHA.PPC64LE.SHA_helpers.block_w ->
hash_orig: Vale.SHA.PPC64LE.SHA_helpers.hash256
-> Prims.Ghost (Vale.PPC64LE.Decls.va_state * Vale.PPC64LE.Decls.va_fuel) | Prims.Ghost | [] | [] | [
"Vale.PPC64LE.Decls.va_code",
"Vale.PPC64LE.Decls.va_state",
"Prims.nat",
"Vale.PPC64LE.Decls.va_operand_vec_opr",
"Vale.PPC64LE.Memory.buffer128",
"Vale.SHA.PPC64LE.SHA_helpers.block_w",
"Vale.SHA.PPC64LE.SHA_helpers.hash256",
"Vale.PPC64LE.QuickCodes.fuel",
"Prims.unit",
"FStar.Pervasives.Native.Mktuple2",
"Vale.PPC64LE.Decls.va_fuel",
"Vale.PPC64LE.QuickCode.va_lemma_norm_mods",
"Prims.Cons",
"Vale.PPC64LE.QuickCode.mod_t",
"Vale.PPC64LE.QuickCode.va_Mod_vec",
"Vale.PPC64LE.QuickCode.va_Mod_ok",
"Vale.PPC64LE.QuickCode.va_mod_vec_opr",
"Prims.Nil",
"FStar.Pervasives.assert_norm",
"Prims.eq2",
"Prims.list",
"Vale.PPC64LE.QuickCode.__proj__QProc__item__mods",
"Vale.SHA.PPC64LE.Rounds.Core.va_code_Loop_rounds_0_63_body",
"FStar.Pervasives.Native.tuple2",
"FStar.Pervasives.Native.tuple3",
"Vale.PPC64LE.Machine_s.state",
"Vale.PPC64LE.QuickCodes.va_wp_sound_code_norm",
"Prims.l_and",
"Vale.PPC64LE.QuickCodes.label",
"Vale.PPC64LE.QuickCodes.va_range1",
"Prims.b2t",
"Vale.PPC64LE.Decls.va_get_ok",
"Vale.Def.Words_s.nat32",
"Vale.Def.Words_s.__proj__Mkfour__item__hi3",
"Vale.Def.Types_s.nat32",
"Vale.PPC64LE.Decls.va_eval_vec_opr",
"Vale.Arch.Types.add_wrap32",
"Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32",
"FStar.Seq.Base.index",
"Vale.SHA.PPC64LE.SHA_helpers.word",
"Vale.SHA.PPC64LE.SHA_helpers.ws_opaque",
"Prims.l_imp",
"Prims.l_not",
"Prims.int",
"Vale.SHA.PPC64LE.SHA_helpers.k_index",
"Prims.op_Addition",
"Vale.SHA.PPC64LE.SHA_helpers.repeat_range_vale",
"Vale.SHA.PPC64LE.SHA_helpers.make_seperated_hash_quad32",
"Vale.SHA.PPC64LE.SHA_helpers.repeat_range_vale_64",
"Vale.SHA.PPC64LE.SHA_helpers.maj_256",
"Vale.SHA2.Wrapper.sigma256_1_0",
"Vale.SHA2.Wrapper.sigma256_1_1",
"Vale.SHA.PPC64LE.SHA_helpers.ch_256",
"FStar.Seq.Base.seq",
"Vale.Def.Types_s.quad32",
"Vale.PPC64LE.Decls.buffer128_as_seq",
"Vale.PPC64LE.Decls.va_get_mem_heaplet",
"Vale.PPC64LE.QuickCode.quickCode",
"Vale.SHA.PPC64LE.Rounds.Core.va_qcode_Loop_rounds_0_63_body"
] | [] | false | false | false | false | false | let va_lemma_Loop_rounds_0_63_body
va_b0
va_s0
i
msg
a_vec
b_vec
c_vec
d_vec
e_vec
f_vec
g_vec
h_vec
k_b
block
hash_orig
=
| let va_mods:va_mods_t =
[
va_Mod_vec 26;
va_Mod_vec 25;
va_Mod_ok;
va_mod_vec_opr h_vec;
va_mod_vec_opr g_vec;
va_mod_vec_opr d_vec
]
in
let va_qc =
va_qcode_Loop_rounds_0_63_body va_mods i msg a_vec b_vec c_vec d_vec e_vec f_vec g_vec h_vec k_b
block hash_orig
in
let va_sM, va_fM, va_g =
va_wp_sound_code_norm (va_code_Loop_rounds_0_63_body i msg a_vec b_vec c_vec d_vec e_vec f_vec
g_vec h_vec)
va_qc
va_s0
(fun va_s0 va_sM va_g ->
let () = va_g in
label va_range1
"***** POSTCONDITION NOT MET AT line 155 column 1 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/sha/Vale.SHA.PPC64LE.Rounds.Core.vaf *****"
(va_get_ok va_sM) /\
label va_range1
"***** POSTCONDITION NOT MET AT line 205 column 9 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/sha/Vale.SHA.PPC64LE.Rounds.Core.vaf *****"
(let ks = Vale.PPC64LE.Decls.buffer128_as_seq (va_get_mem_heaplet 0 va_sM) k_b in
label va_range1
"***** POSTCONDITION NOT MET AT line 206 column 9 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/sha/Vale.SHA.PPC64LE.Rounds.Core.vaf *****"
(let hash = Vale.SHA.PPC64LE.SHA_helpers.repeat_range_vale i block hash_orig in
label va_range1
"***** POSTCONDITION NOT MET AT line 207 column 9 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/sha/Vale.SHA.PPC64LE.Rounds.Core.vaf *****"
(let h_k =
Vale.Arch.Types.add_wrap32 (Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32 (FStar.Seq.Base.index
#Vale.SHA.PPC64LE.SHA_helpers.word
hash
7))
(Vale.SHA.PPC64LE.SHA_helpers.k_index ks i)
in
label va_range1
"***** POSTCONDITION NOT MET AT line 208 column 9 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/sha/Vale.SHA.PPC64LE.Rounds.Core.vaf *****"
(let ch =
Vale.SHA.PPC64LE.SHA_helpers.ch_256 (Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32
(FStar.Seq.Base.index #Vale.SHA.PPC64LE.SHA_helpers.word hash 4))
(Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32 (FStar.Seq.Base.index #Vale.SHA.PPC64LE.SHA_helpers.word
hash
5))
(Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32 (FStar.Seq.Base.index #Vale.SHA.PPC64LE.SHA_helpers.word
hash
6))
in
label va_range1
"***** POSTCONDITION NOT MET AT line 209 column 9 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/sha/Vale.SHA.PPC64LE.Rounds.Core.vaf *****"
(let sigma1 =
Vale.SHA2.Wrapper.sigma256_1_1 (Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32
(FStar.Seq.Base.index #Vale.SHA.PPC64LE.SHA_helpers.word hash 4)
)
in
label va_range1
"***** POSTCONDITION NOT MET AT line 210 column 9 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/sha/Vale.SHA.PPC64LE.Rounds.Core.vaf *****"
(let sigma0 =
Vale.SHA2.Wrapper.sigma256_1_0 (Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32
(FStar.Seq.Base.index #Vale.SHA.PPC64LE.SHA_helpers.word
hash
0))
in
label va_range1
"***** POSTCONDITION NOT MET AT line 211 column 9 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/sha/Vale.SHA.PPC64LE.Rounds.Core.vaf *****"
(let maj =
Vale.SHA.PPC64LE.SHA_helpers.maj_256 (Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32
(FStar.Seq.Base.index #Vale.SHA.PPC64LE.SHA_helpers.word
hash
0))
(Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32 (FStar.Seq.Base.index
#Vale.SHA.PPC64LE.SHA_helpers.word
hash
1))
(Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32 (FStar.Seq.Base.index
#Vale.SHA.PPC64LE.SHA_helpers.word
hash
2))
in
label va_range1
"***** POSTCONDITION NOT MET AT line 212 column 9 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/sha/Vale.SHA.PPC64LE.Rounds.Core.vaf *****"
(let sigma0_maj = Vale.Arch.Types.add_wrap32 sigma0 maj in
label va_range1
"***** POSTCONDITION NOT MET AT line 213 column 137 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/sha/Vale.SHA.PPC64LE.Rounds.Core.vaf *****"
(Vale.Def.Words_s.__proj__Mkfour__item__hi3 (va_eval_vec_opr
va_sM
d_vec) ==
Vale.Arch.Types.add_wrap32 (Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32
(FStar.Seq.Base.index #Vale.SHA.PPC64LE.SHA_helpers.word
hash
3))
(Vale.Arch.Types.add_wrap32 (Vale.Arch.Types.add_wrap32
(Vale.Arch.Types.add_wrap32 h_k
(Vale.SHA.PPC64LE.SHA_helpers.ws_opaque block
i))
ch)
sigma1)) /\
label va_range1
"***** POSTCONDITION NOT MET AT line 214 column 118 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/sha/Vale.SHA.PPC64LE.Rounds.Core.vaf *****"
(Vale.Def.Words_s.__proj__Mkfour__item__hi3 (va_eval_vec_opr
va_sM
h_vec) ==
Vale.Arch.Types.add_wrap32 (Vale.Arch.Types.add_wrap32 (Vale.Arch.Types.add_wrap32
(Vale.Arch.Types.add_wrap32 h_k
(Vale.SHA.PPC64LE.SHA_helpers.ws_opaque block
i))
ch)
sigma1)
sigma0_maj) /\
label va_range1
"***** POSTCONDITION NOT MET AT line 215 column 93 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/sha/Vale.SHA.PPC64LE.Rounds.Core.vaf *****"
(i =!= 63 ==>
Vale.Def.Words_s.__proj__Mkfour__item__hi3 (va_eval_vec_opr
va_sM
g_vec) ==
Vale.Arch.Types.add_wrap32 (Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32
(FStar.Seq.Base.index #Vale.SHA.PPC64LE.SHA_helpers.word
hash
6))
(Vale.SHA.PPC64LE.SHA_helpers.k_index ks (i + 1))) /\
label va_range1
"***** POSTCONDITION NOT MET AT line 224 column 61 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/sha/Vale.SHA.PPC64LE.Rounds.Core.vaf *****"
(i =!= 63 ==>
(let next_hash =
Vale.SHA.PPC64LE.SHA_helpers.repeat_range_vale (i +
1)
block
hash_orig
in
l_and (l_and (l_and (l_and (l_and (l_and (l_and (Vale.Def.Words_s.__proj__Mkfour__item__hi3
(va_eval_vec_opr va_sM
a_vec) ==
Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32
(FStar.Seq.Base.index #Vale.SHA.PPC64LE.SHA_helpers.word
next_hash
1))
(Vale.Def.Words_s.__proj__Mkfour__item__hi3
(va_eval_vec_opr va_sM
b_vec) ==
Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32
(FStar.Seq.Base.index #Vale.SHA.PPC64LE.SHA_helpers.word
next_hash
2)))
(Vale.Def.Words_s.__proj__Mkfour__item__hi3
(va_eval_vec_opr va_sM c_vec
) ==
Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32
(FStar.Seq.Base.index #Vale.SHA.PPC64LE.SHA_helpers.word
next_hash
3)))
(Vale.Def.Words_s.__proj__Mkfour__item__hi3
(va_eval_vec_opr va_sM d_vec) ==
Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32
(FStar.Seq.Base.index #Vale.SHA.PPC64LE.SHA_helpers.word
next_hash
4)))
(Vale.Def.Words_s.__proj__Mkfour__item__hi3
(va_eval_vec_opr va_sM e_vec) ==
Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32
(FStar.Seq.Base.index #Vale.SHA.PPC64LE.SHA_helpers.word
next_hash
5)))
(Vale.Def.Words_s.__proj__Mkfour__item__hi3 (
va_eval_vec_opr va_sM f_vec) ==
Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32
(FStar.Seq.Base.index #Vale.SHA.PPC64LE.SHA_helpers.word
next_hash
6)))
(Vale.Def.Words_s.__proj__Mkfour__item__hi3 (va_eval_vec_opr
va_sM
g_vec) ==
Vale.Arch.Types.add_wrap32 (Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32
(FStar.Seq.Base.index #Vale.SHA.PPC64LE.SHA_helpers.word
next_hash
7))
(Vale.SHA.PPC64LE.SHA_helpers.k_index ks
(i + 1))))
(Vale.Def.Words_s.__proj__Mkfour__item__hi3 (va_eval_vec_opr
va_sM
h_vec) ==
Vale.SHA.PPC64LE.SHA_helpers.word_to_nat32 (FStar.Seq.Base.index
#Vale.SHA.PPC64LE.SHA_helpers.word
next_hash
0)))) /\
label va_range1
"***** POSTCONDITION NOT MET AT line 225 column 145 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/thirdPartyPorts/OpenSSL/sha/Vale.SHA.PPC64LE.Rounds.Core.vaf *****"
(i == 63 ==>
Vale.SHA.PPC64LE.SHA_helpers.make_seperated_hash_quad32 (
va_eval_vec_opr va_sM h_vec)
(va_eval_vec_opr va_sM a_vec)
(va_eval_vec_opr va_sM b_vec)
(va_eval_vec_opr va_sM c_vec)
(va_eval_vec_opr va_sM d_vec)
(va_eval_vec_opr va_sM e_vec)
(va_eval_vec_opr va_sM f_vec)
(va_eval_vec_opr va_sM g_vec) ==
Vale.SHA.PPC64LE.SHA_helpers.repeat_range_vale_64 block
hash_orig))))))))))
in
assert_norm (va_qc.mods == va_mods);
va_lemma_norm_mods ([
va_Mod_vec 26;
va_Mod_vec 25;
va_Mod_ok;
va_mod_vec_opr h_vec;
va_mod_vec_opr g_vec;
va_mod_vec_opr d_vec
])
va_sM
va_s0;
(va_sM, va_fM) | false |
Vale.Poly1305.Bitvectors.fst | Vale.Poly1305.Bitvectors.uint_ext | val uint_ext (#n: nat) (#m: nat{n <= m}) (x: uint_t n)
: r: (uint_t m){uint_to_nat r = uint_to_nat x} | val uint_ext (#n: nat) (#m: nat{n <= m}) (x: uint_t n)
: r: (uint_t m){uint_to_nat r = uint_to_nat x} | let uint_ext (#n : nat) (#m : nat{n <= m}) (x : uint_t n) : r:(uint_t m){uint_to_nat r = uint_to_nat x} =
assert_norm(fits x n);
pow2_le_compat m n;
assert_norm(fits x m);
modulo_lemma x (pow2 m);
to_uint_t m x | {
"file_name": "vale/code/crypto/poly1305/x64/Vale.Poly1305.Bitvectors.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 15,
"end_line": 89,
"start_col": 0,
"start_line": 84
} | module Vale.Poly1305.Bitvectors
open FStar.BV
open FStar.Tactics
open FStar.Tactics.Derived
open FStar.Tactics.BV
open FStar.Mul
open FStar.UInt
open FStar.Math.Lemmas
open Vale.Lib.Tactics
open Vale.Lib.Bv_s
open Vale.Math.Bits
// tweak options?
#reset-options "--smtencoding.elim_box true"
//NOTE: Using the split tactic seems to slowdown execution by a lot.
let lemma_shr2 x =
assert_by_tactic (shift_right #64 x 2 == udiv #64 x 4) bv_tac
let lemma_shr4 x =
assert_by_tactic (shift_right #64 x 4 == udiv #64 x 16) bv_tac
let lemma_and_mod_n x =
assert_by_tactic (logand #64 x 3 == mod #64 x 4) (bv_tac);
assert_by_tactic (logand #64 x 15 == mod #64 x 16) (bv_tac)
let lemma_clear_lower_2 x =
assert_by_tactic
(logand #64 x 0xfffffffffffffffc == mul_mod #64 (udiv #64 x 4) 4)
bv_tac
let lemma_and_constants x =
assert_by_tactic (logand #64 x 0 == (0 <: uint_t 64)) bv_tac;
assert_by_tactic (logand #64 x 0xffffffffffffffff == x) bv_tac
let lemma_poly_constants x =
// using split in this seems to hang execution.
assert_by_tactic
(logand #64 x 0x0ffffffc0fffffff < (0x1000000000000000 <: uint_t 64))
(fun () -> bv_tac_lt 64);
assert_by_tactic
(logand #64 x 0x0ffffffc0ffffffc < (0x1000000000000000 <: uint_t 64))
(fun () -> bv_tac_lt 64);
assert_by_tactic
(mod #64 (logand #64 x 0x0ffffffc0ffffffc) 4 == (0 <: uint_t 64))
(fun () -> bv_tac ())
let lemma_and_commutes x y =
assert_by_tactic
(logand #64 x y == logand #64 y x)
bv_tac
let lemma_bv128_64_64_and_helper' (x0:bv_t 64) (x1:bv_t 64) (y0:bv_t 64) (y1:bv_t 64) :
Lemma (requires True)
(ensures ((bvor #128 (bvshl #128 (bv_uext #64 #64 (bvand #64 x1 y1)) 64)
(bv_uext #64 #64 (bvand #64 x0 y0))) ==
bvand #128 (bvor #128 (bvshl #128 (bv_uext #64 #64 x1) 64)
(bv_uext #64 #64 x0))
(bvor #128 (bvshl #128 (bv_uext #64 #64 y1) 64)
(bv_uext #64 #64 y0)))) = ()
// Rewrite all equalities and then the goal is trivial for Z3.
// Without rewriting this does not go through.
// I believe the reason is related to a previously reported issue with the way
// Z3 bit-blasts through the Boxing/Unboxing functions. I thought this was fixed
// but it may not be the case. Notice that by rewriting with tactics the solver
// only gets to see one big term without any boxing or unboxing inside it.
let lemma_bv128_64_64_and_helper x x0 x1 y y0 y1 z z0 z1 =
lemma_bv128_64_64_and_helper' x0 x1 y0 y1;
assert_by_tactic (z == bvand #128 x y)
(fun () -> destruct_conj ();
rewrite_eqs_from_context ())
let bv128_64_64 x0 x1 = bvor (bvshl (bv_uext #64 #64 x1) 64) (bv_uext #64 #64 x0)
unfold let uint_to_nat (#n:nat) (x:uint_t n) : r:nat{r = x} =
assert (x < pow2 n);
modulo_lemma x (pow2 n);
x | {
"checked_file": "/",
"dependencies": [
"Vale.Math.Bits.fsti.checked",
"Vale.Lib.Tactics.fst.checked",
"Vale.Lib.Bv_s.fst.checked",
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Tactics.Derived.fst.checked",
"FStar.Tactics.BV.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.BV.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Poly1305.Bitvectors.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Math.Bits",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Bv_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: FStar.UInt.uint_t n
-> r:
FStar.UInt.uint_t m
{Vale.Poly1305.Bitvectors.uint_to_nat r = Vale.Poly1305.Bitvectors.uint_to_nat x} | Prims.Tot | [
"total"
] | [] | [
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.UInt.uint_t",
"FStar.UInt.to_uint_t",
"Prims.unit",
"FStar.Math.Lemmas.modulo_lemma",
"Prims.pow2",
"FStar.Pervasives.assert_norm",
"FStar.UInt.fits",
"FStar.Math.Lemmas.pow2_le_compat",
"Prims.op_Equality",
"Prims.l_or",
"Prims.int",
"Prims.op_GreaterThanOrEqual",
"FStar.UInt.size",
"Vale.Poly1305.Bitvectors.uint_to_nat"
] | [] | false | false | false | false | false | let uint_ext (#n: nat) (#m: nat{n <= m}) (x: uint_t n)
: r: (uint_t m){uint_to_nat r = uint_to_nat x} =
| assert_norm (fits x n);
pow2_le_compat m n;
assert_norm (fits x m);
modulo_lemma x (pow2 m);
to_uint_t m x | false |
FStar.Tactics.MkProjectors.fst | FStar.Tactics.MkProjectors.mk_one_method | val mk_one_method (proj:string) (np:nat) : Tac unit | val mk_one_method (proj:string) (np:nat) : Tac unit | let mk_one_method (proj:string) (np:nat) : Tac unit =
debug (fun () -> dump "ENTRY mk_one_method"; "");
let nm = explode_qn proj in
let params = repeatn np (fun () -> let b : binding = intro () in
(binding_to_term b, Q_Implicit)) in
let thing : binding = intro () in
let proj = pack (Tv_FVar (pack_fv nm)) in
exact (mk_app proj (params @ [(binding_to_term thing, Q_Explicit)])) | {
"file_name": "ulib/FStar.Tactics.MkProjectors.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 70,
"end_line": 58,
"start_col": 0,
"start_line": 51
} | module FStar.Tactics.MkProjectors
(* NB: We cannot use typeclasses here, or any module that depends on
them, since they use the tactics defined here. So we must be careful
with our includes. *)
open FStar.List.Tot
open FStar.Reflection.V2
open FStar.Tactics.Effect
open FStar.Stubs.Tactics.V2.Builtins
open FStar.Stubs.Syntax.Syntax
open FStar.Tactics.V2.SyntaxCoercions
open FStar.Tactics.V2.SyntaxHelpers
open FStar.Tactics.V2.Derived
open FStar.Tactics.Util
open FStar.Tactics.NamedView
exception NotFound
let meta_projectors = ()
(* Thunked version of debug *)
let debug (f : unit -> Tac string) : Tac unit =
if debugging () then
print (f ())
[@@plugin]
let mk_one_projector (unf:list string) (np:nat) (i:nat) : Tac unit =
debug (fun () -> dump "ENTRY mk_one_projector"; "");
let _params = repeatn np intro in
let thing : binding = intro () in
let r = t_destruct thing in
match r with
| [(cons, arity)] -> begin
if (i >= arity) then
fail "proj: bad index in mk_one_projector";
let _ = repeatn i intro in
let the_b = intro () in
let _ = repeatn (arity-i-1) intro in
let eq_b : binding = intro () in
rewrite eq_b;
norm [iota; delta_only unf; zeta_full];
(* NB: ^ zeta_full above so we reduce under matches too. Since
we are not unfolding anything but the projectors, which are
not, recursive, this should not bring about any divergence. An
alternative is to use NBE. *)
exact the_b
end
| _ -> fail "proj: more than one case?" | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.SyntaxHelpers.fst.checked",
"FStar.Tactics.V2.SyntaxCoercions.fst.checked",
"FStar.Tactics.V2.Derived.fst.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Typeclasses.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Stubs.Tactics.V2.Builtins.fsti.checked",
"FStar.Stubs.Syntax.Syntax.fsti.checked",
"FStar.Reflection.V2.TermEq.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Tactics.MkProjectors.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.NamedView",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.SyntaxHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.SyntaxCoercions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Syntax.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Reflection.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | proj: Prims.string -> np: Prims.nat -> FStar.Tactics.Effect.Tac Prims.unit | FStar.Tactics.Effect.Tac | [] | [] | [
"Prims.string",
"Prims.nat",
"FStar.Tactics.V2.Derived.exact",
"FStar.Reflection.V2.Derived.mk_app",
"FStar.List.Tot.Base.op_At",
"FStar.Pervasives.Native.tuple2",
"FStar.Tactics.NamedView.term",
"FStar.Stubs.Reflection.V2.Data.aqualv",
"Prims.Cons",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Tactics.V2.SyntaxCoercions.binding_to_term",
"FStar.Stubs.Reflection.V2.Data.Q_Explicit",
"Prims.Nil",
"Prims.unit",
"FStar.Tactics.NamedView.pack",
"FStar.Tactics.NamedView.Tv_FVar",
"FStar.Stubs.Reflection.V2.Builtins.pack_fv",
"FStar.Tactics.NamedView.binding",
"FStar.Stubs.Tactics.V2.Builtins.intro",
"FStar.Stubs.Reflection.V2.Data.binding",
"Prims.list",
"Prims.l_or",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.eq2",
"Prims.int",
"FStar.List.Tot.Base.length",
"FStar.Tactics.Util.repeatn",
"FStar.Stubs.Reflection.V2.Data.Q_Implicit",
"FStar.Stubs.Reflection.V2.Builtins.explode_qn",
"FStar.Tactics.MkProjectors.debug",
"FStar.Stubs.Tactics.V2.Builtins.dump"
] | [] | false | true | false | false | false | let mk_one_method (proj: string) (np: nat) : Tac unit =
| debug (fun () ->
dump "ENTRY mk_one_method";
"");
let nm = explode_qn proj in
let params =
repeatn np
(fun () ->
let b:binding = intro () in
(binding_to_term b, Q_Implicit))
in
let thing:binding = intro () in
let proj = pack (Tv_FVar (pack_fv nm)) in
exact (mk_app proj (params @ [(binding_to_term thing, Q_Explicit)])) | false |
FStar.Tactics.MkProjectors.fst | FStar.Tactics.MkProjectors.debug | val debug (f: (unit -> Tac string)) : Tac unit | val debug (f: (unit -> Tac string)) : Tac unit | let debug (f : unit -> Tac string) : Tac unit =
if debugging () then
print (f ()) | {
"file_name": "ulib/FStar.Tactics.MkProjectors.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 16,
"end_line": 24,
"start_col": 0,
"start_line": 22
} | module FStar.Tactics.MkProjectors
(* NB: We cannot use typeclasses here, or any module that depends on
them, since they use the tactics defined here. So we must be careful
with our includes. *)
open FStar.List.Tot
open FStar.Reflection.V2
open FStar.Tactics.Effect
open FStar.Stubs.Tactics.V2.Builtins
open FStar.Stubs.Syntax.Syntax
open FStar.Tactics.V2.SyntaxCoercions
open FStar.Tactics.V2.SyntaxHelpers
open FStar.Tactics.V2.Derived
open FStar.Tactics.Util
open FStar.Tactics.NamedView
exception NotFound
let meta_projectors = () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.SyntaxHelpers.fst.checked",
"FStar.Tactics.V2.SyntaxCoercions.fst.checked",
"FStar.Tactics.V2.Derived.fst.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Typeclasses.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Stubs.Tactics.V2.Builtins.fsti.checked",
"FStar.Stubs.Syntax.Syntax.fsti.checked",
"FStar.Reflection.V2.TermEq.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Tactics.MkProjectors.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.NamedView",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.SyntaxHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.SyntaxCoercions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Syntax.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Reflection.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | f: (_: Prims.unit -> FStar.Tactics.Effect.Tac Prims.string) -> FStar.Tactics.Effect.Tac Prims.unit | FStar.Tactics.Effect.Tac | [] | [] | [
"Prims.unit",
"Prims.string",
"FStar.Stubs.Tactics.V2.Builtins.print",
"Prims.bool",
"FStar.Stubs.Tactics.V2.Builtins.debugging"
] | [] | false | true | false | false | false | let debug (f: (unit -> Tac string)) : Tac unit =
| if debugging () then print (f ()) | false |
Vale.Poly1305.Bitvectors.fst | Vale.Poly1305.Bitvectors.lowerUpper128m | val lowerUpper128m (l u: uint_t 64) : uint_t 128 | val lowerUpper128m (l u: uint_t 64) : uint_t 128 | let lowerUpper128m (l:uint_t 64) (u:uint_t 64) : uint_t 128 =
add_hide #128 (mul_hide #128 (uext #64 #64 u) 0x10000000000000000) (uext #64 #64 l) | {
"file_name": "vale/code/crypto/poly1305/x64/Vale.Poly1305.Bitvectors.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 85,
"end_line": 133,
"start_col": 0,
"start_line": 132
} | module Vale.Poly1305.Bitvectors
open FStar.BV
open FStar.Tactics
open FStar.Tactics.Derived
open FStar.Tactics.BV
open FStar.Mul
open FStar.UInt
open FStar.Math.Lemmas
open Vale.Lib.Tactics
open Vale.Lib.Bv_s
open Vale.Math.Bits
// tweak options?
#reset-options "--smtencoding.elim_box true"
//NOTE: Using the split tactic seems to slowdown execution by a lot.
let lemma_shr2 x =
assert_by_tactic (shift_right #64 x 2 == udiv #64 x 4) bv_tac
let lemma_shr4 x =
assert_by_tactic (shift_right #64 x 4 == udiv #64 x 16) bv_tac
let lemma_and_mod_n x =
assert_by_tactic (logand #64 x 3 == mod #64 x 4) (bv_tac);
assert_by_tactic (logand #64 x 15 == mod #64 x 16) (bv_tac)
let lemma_clear_lower_2 x =
assert_by_tactic
(logand #64 x 0xfffffffffffffffc == mul_mod #64 (udiv #64 x 4) 4)
bv_tac
let lemma_and_constants x =
assert_by_tactic (logand #64 x 0 == (0 <: uint_t 64)) bv_tac;
assert_by_tactic (logand #64 x 0xffffffffffffffff == x) bv_tac
let lemma_poly_constants x =
// using split in this seems to hang execution.
assert_by_tactic
(logand #64 x 0x0ffffffc0fffffff < (0x1000000000000000 <: uint_t 64))
(fun () -> bv_tac_lt 64);
assert_by_tactic
(logand #64 x 0x0ffffffc0ffffffc < (0x1000000000000000 <: uint_t 64))
(fun () -> bv_tac_lt 64);
assert_by_tactic
(mod #64 (logand #64 x 0x0ffffffc0ffffffc) 4 == (0 <: uint_t 64))
(fun () -> bv_tac ())
let lemma_and_commutes x y =
assert_by_tactic
(logand #64 x y == logand #64 y x)
bv_tac
let lemma_bv128_64_64_and_helper' (x0:bv_t 64) (x1:bv_t 64) (y0:bv_t 64) (y1:bv_t 64) :
Lemma (requires True)
(ensures ((bvor #128 (bvshl #128 (bv_uext #64 #64 (bvand #64 x1 y1)) 64)
(bv_uext #64 #64 (bvand #64 x0 y0))) ==
bvand #128 (bvor #128 (bvshl #128 (bv_uext #64 #64 x1) 64)
(bv_uext #64 #64 x0))
(bvor #128 (bvshl #128 (bv_uext #64 #64 y1) 64)
(bv_uext #64 #64 y0)))) = ()
// Rewrite all equalities and then the goal is trivial for Z3.
// Without rewriting this does not go through.
// I believe the reason is related to a previously reported issue with the way
// Z3 bit-blasts through the Boxing/Unboxing functions. I thought this was fixed
// but it may not be the case. Notice that by rewriting with tactics the solver
// only gets to see one big term without any boxing or unboxing inside it.
let lemma_bv128_64_64_and_helper x x0 x1 y y0 y1 z z0 z1 =
lemma_bv128_64_64_and_helper' x0 x1 y0 y1;
assert_by_tactic (z == bvand #128 x y)
(fun () -> destruct_conj ();
rewrite_eqs_from_context ())
let bv128_64_64 x0 x1 = bvor (bvshl (bv_uext #64 #64 x1) 64) (bv_uext #64 #64 x0)
unfold let uint_to_nat (#n:nat) (x:uint_t n) : r:nat{r = x} =
assert (x < pow2 n);
modulo_lemma x (pow2 n);
x
let uint_ext (#n : nat) (#m : nat{n <= m}) (x : uint_t n) : r:(uint_t m){uint_to_nat r = uint_to_nat x} =
assert_norm(fits x n);
pow2_le_compat m n;
assert_norm(fits x m);
modulo_lemma x (pow2 m);
to_uint_t m x
#reset-options "--smtencoding.elim_box true --smtencoding.l_arith_repr boxwrap --smtencoding.nl_arith_repr boxwrap"
let mul_bvshl (u:uint_t 64) :
Lemma (0x10000000000000000 * u < pow2 128 /\
(int2bv #128 (0x10000000000000000 * u) ==
bvshl (bv_uext #64 #64 (int2bv u)) 64)) =
assert_norm ( 0x10000000000000000 * pow2 63 < pow2 128);
modulo_lemma (0x10000000000000000 * u) (pow2 128);
assert_by_tactic
(int2bv #128 (mul_mod #128 0x10000000000000000 (uint_ext #64 #128 u)) ==
bvmul #128 (int2bv #128 0x10000000000000000) (uint_ext #64 #128 u))
(fun () -> mapply (`trans); arith_to_bv_tac (); trefl ())
#reset-options "--smtencoding.elim_box true"
let plus_bvor (u h:bv_t 128) :
Lemma (bvand u h = bv_zero ==> bvadd u h == bvor u h) = ()
let lemma_bv128_64_64_and x x0 x1 y y0 y1 z z0 z1 =
assert_by_tactic (z == bvand #128 x y)
(fun () -> destruct_conj ();
rewrite_eqs_from_context ();
norm[delta])
#reset-options "--smtencoding.elim_box true --z3refresh --z3rlimit 20 --max_ifuel 1 --max_fuel 1"
let int2bv_uext_64_128 (x1 : nat) :
Lemma (requires (FStar.UInt.size x1 64))
(ensures (bv_uext #64 #64 (int2bv #64 x1) == int2bv #128 x1)) =
assert (64 <= 128);
pow2_le_compat 128 64;
assert (x1 < pow2 128);
modulo_lemma x1 (pow2 128); // x1 % pow2 128 = x1
assert (FStar.UInt.size x1 128);
assert_by_tactic (bv_uext #64 #64 (int2bv #64 x1) == int2bv #128 x1)
(fun () -> dump "..";
norm[delta_only [`%uint_ext; `%FStar.UInt.to_uint_t]];
// grewrite (quote (x1 % pow2 128)) (quote x1);
dump "After norm"; smt ())
#reset-options "--smtencoding.l_arith_repr native --smtencoding.nl_arith_repr wrapped --smtencoding.elim_box true --z3cliopt smt.arith.nl=false --max_fuel 1 --max_ifuel 0" | {
"checked_file": "/",
"dependencies": [
"Vale.Math.Bits.fsti.checked",
"Vale.Lib.Tactics.fst.checked",
"Vale.Lib.Bv_s.fst.checked",
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Tactics.Derived.fst.checked",
"FStar.Tactics.BV.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.BV.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Poly1305.Bitvectors.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Math.Bits",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Bv_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3",
"smt.arith.nl=false"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | l: FStar.UInt.uint_t 64 -> u153: FStar.UInt.uint_t 64 -> FStar.UInt.uint_t 128 | Prims.Tot | [
"total"
] | [] | [
"FStar.UInt.uint_t",
"Vale.Math.Bits.add_hide",
"Vale.Math.Bits.mul_hide",
"Vale.Math.Bits.uext"
] | [] | false | false | false | false | false | let lowerUpper128m (l u: uint_t 64) : uint_t 128 =
| add_hide #128 (mul_hide #128 (uext #64 #64 u) 0x10000000000000000) (uext #64 #64 l) | false |
Vale.Poly1305.Bitvectors.fst | Vale.Poly1305.Bitvectors.lowerUpper128b | val lowerUpper128b (l u: bv_t 64) : bv_t 128 | val lowerUpper128b (l u: bv_t 64) : bv_t 128 | let lowerUpper128b (l:bv_t 64) (u:bv_t 64) : bv_t 128 =
b_add #128 (b_mul #128 (b_uext #64 #64 u) 0x10000000000000000) (b_uext #64 #64 l) | {
"file_name": "vale/code/crypto/poly1305/x64/Vale.Poly1305.Bitvectors.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 83,
"end_line": 136,
"start_col": 0,
"start_line": 135
} | module Vale.Poly1305.Bitvectors
open FStar.BV
open FStar.Tactics
open FStar.Tactics.Derived
open FStar.Tactics.BV
open FStar.Mul
open FStar.UInt
open FStar.Math.Lemmas
open Vale.Lib.Tactics
open Vale.Lib.Bv_s
open Vale.Math.Bits
// tweak options?
#reset-options "--smtencoding.elim_box true"
//NOTE: Using the split tactic seems to slowdown execution by a lot.
let lemma_shr2 x =
assert_by_tactic (shift_right #64 x 2 == udiv #64 x 4) bv_tac
let lemma_shr4 x =
assert_by_tactic (shift_right #64 x 4 == udiv #64 x 16) bv_tac
let lemma_and_mod_n x =
assert_by_tactic (logand #64 x 3 == mod #64 x 4) (bv_tac);
assert_by_tactic (logand #64 x 15 == mod #64 x 16) (bv_tac)
let lemma_clear_lower_2 x =
assert_by_tactic
(logand #64 x 0xfffffffffffffffc == mul_mod #64 (udiv #64 x 4) 4)
bv_tac
let lemma_and_constants x =
assert_by_tactic (logand #64 x 0 == (0 <: uint_t 64)) bv_tac;
assert_by_tactic (logand #64 x 0xffffffffffffffff == x) bv_tac
let lemma_poly_constants x =
// using split in this seems to hang execution.
assert_by_tactic
(logand #64 x 0x0ffffffc0fffffff < (0x1000000000000000 <: uint_t 64))
(fun () -> bv_tac_lt 64);
assert_by_tactic
(logand #64 x 0x0ffffffc0ffffffc < (0x1000000000000000 <: uint_t 64))
(fun () -> bv_tac_lt 64);
assert_by_tactic
(mod #64 (logand #64 x 0x0ffffffc0ffffffc) 4 == (0 <: uint_t 64))
(fun () -> bv_tac ())
let lemma_and_commutes x y =
assert_by_tactic
(logand #64 x y == logand #64 y x)
bv_tac
let lemma_bv128_64_64_and_helper' (x0:bv_t 64) (x1:bv_t 64) (y0:bv_t 64) (y1:bv_t 64) :
Lemma (requires True)
(ensures ((bvor #128 (bvshl #128 (bv_uext #64 #64 (bvand #64 x1 y1)) 64)
(bv_uext #64 #64 (bvand #64 x0 y0))) ==
bvand #128 (bvor #128 (bvshl #128 (bv_uext #64 #64 x1) 64)
(bv_uext #64 #64 x0))
(bvor #128 (bvshl #128 (bv_uext #64 #64 y1) 64)
(bv_uext #64 #64 y0)))) = ()
// Rewrite all equalities and then the goal is trivial for Z3.
// Without rewriting this does not go through.
// I believe the reason is related to a previously reported issue with the way
// Z3 bit-blasts through the Boxing/Unboxing functions. I thought this was fixed
// but it may not be the case. Notice that by rewriting with tactics the solver
// only gets to see one big term without any boxing or unboxing inside it.
let lemma_bv128_64_64_and_helper x x0 x1 y y0 y1 z z0 z1 =
lemma_bv128_64_64_and_helper' x0 x1 y0 y1;
assert_by_tactic (z == bvand #128 x y)
(fun () -> destruct_conj ();
rewrite_eqs_from_context ())
let bv128_64_64 x0 x1 = bvor (bvshl (bv_uext #64 #64 x1) 64) (bv_uext #64 #64 x0)
unfold let uint_to_nat (#n:nat) (x:uint_t n) : r:nat{r = x} =
assert (x < pow2 n);
modulo_lemma x (pow2 n);
x
let uint_ext (#n : nat) (#m : nat{n <= m}) (x : uint_t n) : r:(uint_t m){uint_to_nat r = uint_to_nat x} =
assert_norm(fits x n);
pow2_le_compat m n;
assert_norm(fits x m);
modulo_lemma x (pow2 m);
to_uint_t m x
#reset-options "--smtencoding.elim_box true --smtencoding.l_arith_repr boxwrap --smtencoding.nl_arith_repr boxwrap"
let mul_bvshl (u:uint_t 64) :
Lemma (0x10000000000000000 * u < pow2 128 /\
(int2bv #128 (0x10000000000000000 * u) ==
bvshl (bv_uext #64 #64 (int2bv u)) 64)) =
assert_norm ( 0x10000000000000000 * pow2 63 < pow2 128);
modulo_lemma (0x10000000000000000 * u) (pow2 128);
assert_by_tactic
(int2bv #128 (mul_mod #128 0x10000000000000000 (uint_ext #64 #128 u)) ==
bvmul #128 (int2bv #128 0x10000000000000000) (uint_ext #64 #128 u))
(fun () -> mapply (`trans); arith_to_bv_tac (); trefl ())
#reset-options "--smtencoding.elim_box true"
let plus_bvor (u h:bv_t 128) :
Lemma (bvand u h = bv_zero ==> bvadd u h == bvor u h) = ()
let lemma_bv128_64_64_and x x0 x1 y y0 y1 z z0 z1 =
assert_by_tactic (z == bvand #128 x y)
(fun () -> destruct_conj ();
rewrite_eqs_from_context ();
norm[delta])
#reset-options "--smtencoding.elim_box true --z3refresh --z3rlimit 20 --max_ifuel 1 --max_fuel 1"
let int2bv_uext_64_128 (x1 : nat) :
Lemma (requires (FStar.UInt.size x1 64))
(ensures (bv_uext #64 #64 (int2bv #64 x1) == int2bv #128 x1)) =
assert (64 <= 128);
pow2_le_compat 128 64;
assert (x1 < pow2 128);
modulo_lemma x1 (pow2 128); // x1 % pow2 128 = x1
assert (FStar.UInt.size x1 128);
assert_by_tactic (bv_uext #64 #64 (int2bv #64 x1) == int2bv #128 x1)
(fun () -> dump "..";
norm[delta_only [`%uint_ext; `%FStar.UInt.to_uint_t]];
// grewrite (quote (x1 % pow2 128)) (quote x1);
dump "After norm"; smt ())
#reset-options "--smtencoding.l_arith_repr native --smtencoding.nl_arith_repr wrapped --smtencoding.elim_box true --z3cliopt smt.arith.nl=false --max_fuel 1 --max_ifuel 0"
let lowerUpper128m (l:uint_t 64) (u:uint_t 64) : uint_t 128 =
add_hide #128 (mul_hide #128 (uext #64 #64 u) 0x10000000000000000) (uext #64 #64 l) | {
"checked_file": "/",
"dependencies": [
"Vale.Math.Bits.fsti.checked",
"Vale.Lib.Tactics.fst.checked",
"Vale.Lib.Bv_s.fst.checked",
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Tactics.Derived.fst.checked",
"FStar.Tactics.BV.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.BV.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Poly1305.Bitvectors.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Math.Bits",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Bv_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3",
"smt.arith.nl=false"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | l: FStar.BV.bv_t 64 -> u157: FStar.BV.bv_t 64 -> FStar.BV.bv_t 128 | Prims.Tot | [
"total"
] | [] | [
"FStar.BV.bv_t",
"Vale.Math.Bits.b_add",
"Vale.Math.Bits.b_mul",
"Vale.Math.Bits.b_uext"
] | [] | false | false | false | false | false | let lowerUpper128b (l u: bv_t 64) : bv_t 128 =
| b_add #128 (b_mul #128 (b_uext #64 #64 u) 0x10000000000000000) (b_uext #64 #64 l) | false |
FStar.Tactics.MkProjectors.fst | FStar.Tactics.MkProjectors.binder_mk_implicit | val binder_mk_implicit (b: binder) : binder | val binder_mk_implicit (b: binder) : binder | let binder_mk_implicit (b:binder) : binder =
let q =
match b.qual with
| Q_Explicit -> Q_Implicit
| q -> q (* keep Q_Meta as it is *)
in
{ b with qual = q } | {
"file_name": "ulib/FStar.Tactics.MkProjectors.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 21,
"end_line": 70,
"start_col": 0,
"start_line": 64
} | module FStar.Tactics.MkProjectors
(* NB: We cannot use typeclasses here, or any module that depends on
them, since they use the tactics defined here. So we must be careful
with our includes. *)
open FStar.List.Tot
open FStar.Reflection.V2
open FStar.Tactics.Effect
open FStar.Stubs.Tactics.V2.Builtins
open FStar.Stubs.Syntax.Syntax
open FStar.Tactics.V2.SyntaxCoercions
open FStar.Tactics.V2.SyntaxHelpers
open FStar.Tactics.V2.Derived
open FStar.Tactics.Util
open FStar.Tactics.NamedView
exception NotFound
let meta_projectors = ()
(* Thunked version of debug *)
let debug (f : unit -> Tac string) : Tac unit =
if debugging () then
print (f ())
[@@plugin]
let mk_one_projector (unf:list string) (np:nat) (i:nat) : Tac unit =
debug (fun () -> dump "ENTRY mk_one_projector"; "");
let _params = repeatn np intro in
let thing : binding = intro () in
let r = t_destruct thing in
match r with
| [(cons, arity)] -> begin
if (i >= arity) then
fail "proj: bad index in mk_one_projector";
let _ = repeatn i intro in
let the_b = intro () in
let _ = repeatn (arity-i-1) intro in
let eq_b : binding = intro () in
rewrite eq_b;
norm [iota; delta_only unf; zeta_full];
(* NB: ^ zeta_full above so we reduce under matches too. Since
we are not unfolding anything but the projectors, which are
not, recursive, this should not bring about any divergence. An
alternative is to use NBE. *)
exact the_b
end
| _ -> fail "proj: more than one case?"
[@@plugin]
let mk_one_method (proj:string) (np:nat) : Tac unit =
debug (fun () -> dump "ENTRY mk_one_method"; "");
let nm = explode_qn proj in
let params = repeatn np (fun () -> let b : binding = intro () in
(binding_to_term b, Q_Implicit)) in
let thing : binding = intro () in
let proj = pack (Tv_FVar (pack_fv nm)) in
exact (mk_app proj (params @ [(binding_to_term thing, Q_Explicit)]))
let subst_map (ss : list (namedv * fv)) (r:term) (t : term) : Tac term =
let subst = List.Tot.map (fun (x, fv) -> NT (Reflection.V2.pack_namedv x) (mk_e_app (Tv_FVar fv) [r])) ss in
subst_term subst t | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.SyntaxHelpers.fst.checked",
"FStar.Tactics.V2.SyntaxCoercions.fst.checked",
"FStar.Tactics.V2.Derived.fst.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Typeclasses.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Stubs.Tactics.V2.Builtins.fsti.checked",
"FStar.Stubs.Syntax.Syntax.fsti.checked",
"FStar.Reflection.V2.TermEq.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Tactics.MkProjectors.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.NamedView",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.SyntaxHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.SyntaxCoercions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Syntax.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Reflection.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | b: FStar.Tactics.NamedView.binder -> FStar.Tactics.NamedView.binder | Prims.Tot | [
"total"
] | [] | [
"FStar.Tactics.NamedView.binder",
"FStar.Tactics.NamedView.Mkbinder",
"FStar.Tactics.NamedView.__proj__Mkbinder__item__uniq",
"FStar.Tactics.NamedView.__proj__Mkbinder__item__ppname",
"FStar.Tactics.NamedView.__proj__Mkbinder__item__sort",
"FStar.Tactics.NamedView.__proj__Mkbinder__item__attrs",
"FStar.Stubs.Reflection.V2.Data.aqualv",
"FStar.Tactics.NamedView.__proj__Mkbinder__item__qual",
"FStar.Stubs.Reflection.V2.Data.Q_Implicit"
] | [] | false | false | false | true | false | let binder_mk_implicit (b: binder) : binder =
| let q =
match b.qual with
| Q_Explicit -> Q_Implicit
| q -> q
in
{ b with qual = q } | false |
FStar.Tactics.MkProjectors.fst | FStar.Tactics.MkProjectors.subst_map | val subst_map (ss: list (namedv * fv)) (r t: term) : Tac term | val subst_map (ss: list (namedv * fv)) (r t: term) : Tac term | let subst_map (ss : list (namedv * fv)) (r:term) (t : term) : Tac term =
let subst = List.Tot.map (fun (x, fv) -> NT (Reflection.V2.pack_namedv x) (mk_e_app (Tv_FVar fv) [r])) ss in
subst_term subst t | {
"file_name": "ulib/FStar.Tactics.MkProjectors.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 20,
"end_line": 62,
"start_col": 0,
"start_line": 60
} | module FStar.Tactics.MkProjectors
(* NB: We cannot use typeclasses here, or any module that depends on
them, since they use the tactics defined here. So we must be careful
with our includes. *)
open FStar.List.Tot
open FStar.Reflection.V2
open FStar.Tactics.Effect
open FStar.Stubs.Tactics.V2.Builtins
open FStar.Stubs.Syntax.Syntax
open FStar.Tactics.V2.SyntaxCoercions
open FStar.Tactics.V2.SyntaxHelpers
open FStar.Tactics.V2.Derived
open FStar.Tactics.Util
open FStar.Tactics.NamedView
exception NotFound
let meta_projectors = ()
(* Thunked version of debug *)
let debug (f : unit -> Tac string) : Tac unit =
if debugging () then
print (f ())
[@@plugin]
let mk_one_projector (unf:list string) (np:nat) (i:nat) : Tac unit =
debug (fun () -> dump "ENTRY mk_one_projector"; "");
let _params = repeatn np intro in
let thing : binding = intro () in
let r = t_destruct thing in
match r with
| [(cons, arity)] -> begin
if (i >= arity) then
fail "proj: bad index in mk_one_projector";
let _ = repeatn i intro in
let the_b = intro () in
let _ = repeatn (arity-i-1) intro in
let eq_b : binding = intro () in
rewrite eq_b;
norm [iota; delta_only unf; zeta_full];
(* NB: ^ zeta_full above so we reduce under matches too. Since
we are not unfolding anything but the projectors, which are
not, recursive, this should not bring about any divergence. An
alternative is to use NBE. *)
exact the_b
end
| _ -> fail "proj: more than one case?"
[@@plugin]
let mk_one_method (proj:string) (np:nat) : Tac unit =
debug (fun () -> dump "ENTRY mk_one_method"; "");
let nm = explode_qn proj in
let params = repeatn np (fun () -> let b : binding = intro () in
(binding_to_term b, Q_Implicit)) in
let thing : binding = intro () in
let proj = pack (Tv_FVar (pack_fv nm)) in
exact (mk_app proj (params @ [(binding_to_term thing, Q_Explicit)])) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.SyntaxHelpers.fst.checked",
"FStar.Tactics.V2.SyntaxCoercions.fst.checked",
"FStar.Tactics.V2.Derived.fst.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Typeclasses.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Stubs.Tactics.V2.Builtins.fsti.checked",
"FStar.Stubs.Syntax.Syntax.fsti.checked",
"FStar.Reflection.V2.TermEq.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Tactics.MkProjectors.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.NamedView",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.SyntaxHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.SyntaxCoercions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Syntax.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Reflection.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
ss: Prims.list (FStar.Tactics.NamedView.namedv * FStar.Stubs.Reflection.Types.fv) ->
r: FStar.Tactics.NamedView.term ->
t: FStar.Tactics.NamedView.term
-> FStar.Tactics.Effect.Tac FStar.Tactics.NamedView.term | FStar.Tactics.Effect.Tac | [] | [] | [
"Prims.list",
"FStar.Pervasives.Native.tuple2",
"FStar.Tactics.NamedView.namedv",
"FStar.Stubs.Reflection.Types.fv",
"FStar.Tactics.NamedView.term",
"FStar.Stubs.Reflection.V2.Builtins.subst_term",
"FStar.Stubs.Syntax.Syntax.subst_elt",
"FStar.List.Tot.Base.map",
"FStar.Stubs.Reflection.V2.Data.namedv_view",
"FStar.Stubs.Syntax.Syntax.NT",
"FStar.Stubs.Reflection.V2.Builtins.pack_namedv",
"FStar.Reflection.V2.Derived.mk_e_app",
"FStar.Tactics.NamedView.pack",
"FStar.Tactics.NamedView.Tv_FVar",
"Prims.Cons",
"FStar.Stubs.Reflection.Types.term",
"Prims.Nil"
] | [] | false | true | false | false | false | let subst_map (ss: list (namedv * fv)) (r t: term) : Tac term =
| let subst =
List.Tot.map (fun (x, fv) -> NT (Reflection.V2.pack_namedv x) (mk_e_app (Tv_FVar fv) [r])) ss
in
subst_term subst t | false |
FStar.Tactics.MkProjectors.fst | FStar.Tactics.MkProjectors.mk_one_projector | val mk_one_projector (unf:list string) (np:nat) (i:nat) : Tac unit | val mk_one_projector (unf:list string) (np:nat) (i:nat) : Tac unit | let mk_one_projector (unf:list string) (np:nat) (i:nat) : Tac unit =
debug (fun () -> dump "ENTRY mk_one_projector"; "");
let _params = repeatn np intro in
let thing : binding = intro () in
let r = t_destruct thing in
match r with
| [(cons, arity)] -> begin
if (i >= arity) then
fail "proj: bad index in mk_one_projector";
let _ = repeatn i intro in
let the_b = intro () in
let _ = repeatn (arity-i-1) intro in
let eq_b : binding = intro () in
rewrite eq_b;
norm [iota; delta_only unf; zeta_full];
(* NB: ^ zeta_full above so we reduce under matches too. Since
we are not unfolding anything but the projectors, which are
not, recursive, this should not bring about any divergence. An
alternative is to use NBE. *)
exact the_b
end
| _ -> fail "proj: more than one case?" | {
"file_name": "ulib/FStar.Tactics.MkProjectors.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 41,
"end_line": 48,
"start_col": 0,
"start_line": 27
} | module FStar.Tactics.MkProjectors
(* NB: We cannot use typeclasses here, or any module that depends on
them, since they use the tactics defined here. So we must be careful
with our includes. *)
open FStar.List.Tot
open FStar.Reflection.V2
open FStar.Tactics.Effect
open FStar.Stubs.Tactics.V2.Builtins
open FStar.Stubs.Syntax.Syntax
open FStar.Tactics.V2.SyntaxCoercions
open FStar.Tactics.V2.SyntaxHelpers
open FStar.Tactics.V2.Derived
open FStar.Tactics.Util
open FStar.Tactics.NamedView
exception NotFound
let meta_projectors = ()
(* Thunked version of debug *)
let debug (f : unit -> Tac string) : Tac unit =
if debugging () then
print (f ()) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.SyntaxHelpers.fst.checked",
"FStar.Tactics.V2.SyntaxCoercions.fst.checked",
"FStar.Tactics.V2.Derived.fst.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Typeclasses.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Stubs.Tactics.V2.Builtins.fsti.checked",
"FStar.Stubs.Syntax.Syntax.fsti.checked",
"FStar.Reflection.V2.TermEq.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Tactics.MkProjectors.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.NamedView",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.SyntaxHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.SyntaxCoercions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Syntax.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Reflection.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | unf: Prims.list Prims.string -> np: Prims.nat -> i: Prims.nat -> FStar.Tactics.Effect.Tac Prims.unit | FStar.Tactics.Effect.Tac | [] | [] | [
"Prims.list",
"Prims.string",
"Prims.nat",
"FStar.Stubs.Reflection.Types.fv",
"FStar.Tactics.V2.Derived.exact",
"FStar.Tactics.V2.SyntaxCoercions.binding_to_term",
"Prims.unit",
"FStar.Stubs.Tactics.V2.Builtins.norm",
"Prims.Cons",
"FStar.Pervasives.norm_step",
"FStar.Pervasives.iota",
"FStar.Pervasives.delta_only",
"FStar.Pervasives.zeta_full",
"Prims.Nil",
"FStar.Stubs.Tactics.V2.Builtins.rewrite",
"FStar.Tactics.NamedView.binding",
"FStar.Stubs.Tactics.V2.Builtins.intro",
"FStar.Stubs.Reflection.V2.Data.binding",
"Prims.l_or",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.op_Subtraction",
"Prims.eq2",
"Prims.int",
"FStar.List.Tot.Base.length",
"FStar.Tactics.Util.repeatn",
"Prims.op_GreaterThanOrEqual",
"FStar.Tactics.V2.Derived.fail",
"Prims.bool",
"FStar.Pervasives.Native.tuple2",
"FStar.Stubs.Tactics.V2.Builtins.t_destruct",
"FStar.Tactics.MkProjectors.debug",
"FStar.Stubs.Tactics.V2.Builtins.dump"
] | [] | false | true | false | false | false | let mk_one_projector (unf: list string) (np i: nat) : Tac unit =
| debug (fun () ->
dump "ENTRY mk_one_projector";
"");
let _params = repeatn np intro in
let thing:binding = intro () in
let r = t_destruct thing in
match r with
| [cons, arity] ->
if (i >= arity) then fail "proj: bad index in mk_one_projector";
let _ = repeatn i intro in
let the_b = intro () in
let _ = repeatn (arity - i - 1) intro in
let eq_b:binding = intro () in
rewrite eq_b;
norm [iota; delta_only unf; zeta_full];
exact the_b
| _ -> fail "proj: more than one case?" | false |
Vale.Poly1305.Bitvectors.fst | Vale.Poly1305.Bitvectors.lemma_shr4 | val lemma_shr4: x:uint_t 64 -> Lemma (shift_right #64 x 4 == udiv #64 x 16)
[SMTPat (shift_right #64 x 4)] | val lemma_shr4: x:uint_t 64 -> Lemma (shift_right #64 x 4 == udiv #64 x 16)
[SMTPat (shift_right #64 x 4)] | let lemma_shr4 x =
assert_by_tactic (shift_right #64 x 4 == udiv #64 x 16) bv_tac | {
"file_name": "vale/code/crypto/poly1305/x64/Vale.Poly1305.Bitvectors.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 64,
"end_line": 22,
"start_col": 0,
"start_line": 21
} | module Vale.Poly1305.Bitvectors
open FStar.BV
open FStar.Tactics
open FStar.Tactics.Derived
open FStar.Tactics.BV
open FStar.Mul
open FStar.UInt
open FStar.Math.Lemmas
open Vale.Lib.Tactics
open Vale.Lib.Bv_s
open Vale.Math.Bits
// tweak options?
#reset-options "--smtencoding.elim_box true"
//NOTE: Using the split tactic seems to slowdown execution by a lot.
let lemma_shr2 x =
assert_by_tactic (shift_right #64 x 2 == udiv #64 x 4) bv_tac | {
"checked_file": "/",
"dependencies": [
"Vale.Math.Bits.fsti.checked",
"Vale.Lib.Tactics.fst.checked",
"Vale.Lib.Bv_s.fst.checked",
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Tactics.Derived.fst.checked",
"FStar.Tactics.BV.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.BV.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Poly1305.Bitvectors.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Math.Bits",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Bv_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: FStar.UInt.uint_t 64
-> FStar.Pervasives.Lemma (ensures FStar.UInt.shift_right x 4 == FStar.UInt.udiv x 16)
[SMTPat (FStar.UInt.shift_right x 4)] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.UInt.uint_t",
"FStar.Tactics.Effect.assert_by_tactic",
"Prims.eq2",
"FStar.UInt.shift_right",
"FStar.UInt.udiv",
"FStar.Tactics.BV.bv_tac",
"Prims.unit"
] | [] | true | false | true | false | false | let lemma_shr4 x =
| assert_by_tactic (shift_right #64 x 4 == udiv #64 x 16) bv_tac | false |
FStar.Tactics.MkProjectors.fst | FStar.Tactics.MkProjectors.binder_to_term | val binder_to_term (b: binder) : Tot term | val binder_to_term (b: binder) : Tot term | let binder_to_term (b:binder) : Tot term =
pack (Tv_Var (binder_to_namedv b)) | {
"file_name": "ulib/FStar.Tactics.MkProjectors.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 36,
"end_line": 73,
"start_col": 0,
"start_line": 72
} | module FStar.Tactics.MkProjectors
(* NB: We cannot use typeclasses here, or any module that depends on
them, since they use the tactics defined here. So we must be careful
with our includes. *)
open FStar.List.Tot
open FStar.Reflection.V2
open FStar.Tactics.Effect
open FStar.Stubs.Tactics.V2.Builtins
open FStar.Stubs.Syntax.Syntax
open FStar.Tactics.V2.SyntaxCoercions
open FStar.Tactics.V2.SyntaxHelpers
open FStar.Tactics.V2.Derived
open FStar.Tactics.Util
open FStar.Tactics.NamedView
exception NotFound
let meta_projectors = ()
(* Thunked version of debug *)
let debug (f : unit -> Tac string) : Tac unit =
if debugging () then
print (f ())
[@@plugin]
let mk_one_projector (unf:list string) (np:nat) (i:nat) : Tac unit =
debug (fun () -> dump "ENTRY mk_one_projector"; "");
let _params = repeatn np intro in
let thing : binding = intro () in
let r = t_destruct thing in
match r with
| [(cons, arity)] -> begin
if (i >= arity) then
fail "proj: bad index in mk_one_projector";
let _ = repeatn i intro in
let the_b = intro () in
let _ = repeatn (arity-i-1) intro in
let eq_b : binding = intro () in
rewrite eq_b;
norm [iota; delta_only unf; zeta_full];
(* NB: ^ zeta_full above so we reduce under matches too. Since
we are not unfolding anything but the projectors, which are
not, recursive, this should not bring about any divergence. An
alternative is to use NBE. *)
exact the_b
end
| _ -> fail "proj: more than one case?"
[@@plugin]
let mk_one_method (proj:string) (np:nat) : Tac unit =
debug (fun () -> dump "ENTRY mk_one_method"; "");
let nm = explode_qn proj in
let params = repeatn np (fun () -> let b : binding = intro () in
(binding_to_term b, Q_Implicit)) in
let thing : binding = intro () in
let proj = pack (Tv_FVar (pack_fv nm)) in
exact (mk_app proj (params @ [(binding_to_term thing, Q_Explicit)]))
let subst_map (ss : list (namedv * fv)) (r:term) (t : term) : Tac term =
let subst = List.Tot.map (fun (x, fv) -> NT (Reflection.V2.pack_namedv x) (mk_e_app (Tv_FVar fv) [r])) ss in
subst_term subst t
let binder_mk_implicit (b:binder) : binder =
let q =
match b.qual with
| Q_Explicit -> Q_Implicit
| q -> q (* keep Q_Meta as it is *)
in
{ b with qual = q } | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.SyntaxHelpers.fst.checked",
"FStar.Tactics.V2.SyntaxCoercions.fst.checked",
"FStar.Tactics.V2.Derived.fst.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Typeclasses.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Stubs.Tactics.V2.Builtins.fsti.checked",
"FStar.Stubs.Syntax.Syntax.fsti.checked",
"FStar.Reflection.V2.TermEq.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Tactics.MkProjectors.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.NamedView",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.SyntaxHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.SyntaxCoercions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Syntax.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Reflection.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | b: FStar.Tactics.NamedView.binder -> FStar.Tactics.NamedView.term | Prims.Tot | [
"total"
] | [] | [
"FStar.Tactics.NamedView.binder",
"FStar.Tactics.NamedView.pack",
"FStar.Tactics.NamedView.Tv_Var",
"FStar.Tactics.V2.SyntaxCoercions.binder_to_namedv",
"FStar.Tactics.NamedView.term"
] | [] | false | false | false | true | false | let binder_to_term (b: binder) : Tot term =
| pack (Tv_Var (binder_to_namedv b)) | false |
FStar.Tactics.MkProjectors.fst | FStar.Tactics.MkProjectors.binder_argv | val binder_argv (b: binder) : Tot argv | val binder_argv (b: binder) : Tot argv | let binder_argv (b:binder) : Tot argv =
let q =
match b.qual with
| Q_Meta _ -> Q_Implicit
| q -> q
in
(binder_to_term b, q) | {
"file_name": "ulib/FStar.Tactics.MkProjectors.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 23,
"end_line": 81,
"start_col": 0,
"start_line": 75
} | module FStar.Tactics.MkProjectors
(* NB: We cannot use typeclasses here, or any module that depends on
them, since they use the tactics defined here. So we must be careful
with our includes. *)
open FStar.List.Tot
open FStar.Reflection.V2
open FStar.Tactics.Effect
open FStar.Stubs.Tactics.V2.Builtins
open FStar.Stubs.Syntax.Syntax
open FStar.Tactics.V2.SyntaxCoercions
open FStar.Tactics.V2.SyntaxHelpers
open FStar.Tactics.V2.Derived
open FStar.Tactics.Util
open FStar.Tactics.NamedView
exception NotFound
let meta_projectors = ()
(* Thunked version of debug *)
let debug (f : unit -> Tac string) : Tac unit =
if debugging () then
print (f ())
[@@plugin]
let mk_one_projector (unf:list string) (np:nat) (i:nat) : Tac unit =
debug (fun () -> dump "ENTRY mk_one_projector"; "");
let _params = repeatn np intro in
let thing : binding = intro () in
let r = t_destruct thing in
match r with
| [(cons, arity)] -> begin
if (i >= arity) then
fail "proj: bad index in mk_one_projector";
let _ = repeatn i intro in
let the_b = intro () in
let _ = repeatn (arity-i-1) intro in
let eq_b : binding = intro () in
rewrite eq_b;
norm [iota; delta_only unf; zeta_full];
(* NB: ^ zeta_full above so we reduce under matches too. Since
we are not unfolding anything but the projectors, which are
not, recursive, this should not bring about any divergence. An
alternative is to use NBE. *)
exact the_b
end
| _ -> fail "proj: more than one case?"
[@@plugin]
let mk_one_method (proj:string) (np:nat) : Tac unit =
debug (fun () -> dump "ENTRY mk_one_method"; "");
let nm = explode_qn proj in
let params = repeatn np (fun () -> let b : binding = intro () in
(binding_to_term b, Q_Implicit)) in
let thing : binding = intro () in
let proj = pack (Tv_FVar (pack_fv nm)) in
exact (mk_app proj (params @ [(binding_to_term thing, Q_Explicit)]))
let subst_map (ss : list (namedv * fv)) (r:term) (t : term) : Tac term =
let subst = List.Tot.map (fun (x, fv) -> NT (Reflection.V2.pack_namedv x) (mk_e_app (Tv_FVar fv) [r])) ss in
subst_term subst t
let binder_mk_implicit (b:binder) : binder =
let q =
match b.qual with
| Q_Explicit -> Q_Implicit
| q -> q (* keep Q_Meta as it is *)
in
{ b with qual = q }
let binder_to_term (b:binder) : Tot term =
pack (Tv_Var (binder_to_namedv b)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.SyntaxHelpers.fst.checked",
"FStar.Tactics.V2.SyntaxCoercions.fst.checked",
"FStar.Tactics.V2.Derived.fst.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Typeclasses.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Stubs.Tactics.V2.Builtins.fsti.checked",
"FStar.Stubs.Syntax.Syntax.fsti.checked",
"FStar.Reflection.V2.TermEq.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Tactics.MkProjectors.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.NamedView",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.SyntaxHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.SyntaxCoercions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Syntax.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Reflection.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | b: FStar.Tactics.NamedView.binder -> FStar.Stubs.Reflection.V2.Data.argv | Prims.Tot | [
"total"
] | [] | [
"FStar.Tactics.NamedView.binder",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Stubs.Reflection.Types.term",
"FStar.Stubs.Reflection.V2.Data.aqualv",
"FStar.Tactics.MkProjectors.binder_to_term",
"FStar.Tactics.NamedView.__proj__Mkbinder__item__qual",
"FStar.Stubs.Reflection.V2.Data.Q_Implicit",
"FStar.Stubs.Reflection.V2.Data.argv"
] | [] | false | false | false | true | false | let binder_argv (b: binder) : Tot argv =
| let q =
match b.qual with
| Q_Meta _ -> Q_Implicit
| q -> q
in
(binder_to_term b, q) | false |
FStar.Tactics.MkProjectors.fst | FStar.Tactics.MkProjectors.embed_int | val embed_int (i: int) : term | val embed_int (i: int) : term | let embed_int (i:int) : term =
let open FStar.Reflection.V2 in
pack_ln (Tv_Const (C_Int i)) | {
"file_name": "ulib/FStar.Tactics.MkProjectors.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 30,
"end_line": 91,
"start_col": 0,
"start_line": 89
} | module FStar.Tactics.MkProjectors
(* NB: We cannot use typeclasses here, or any module that depends on
them, since they use the tactics defined here. So we must be careful
with our includes. *)
open FStar.List.Tot
open FStar.Reflection.V2
open FStar.Tactics.Effect
open FStar.Stubs.Tactics.V2.Builtins
open FStar.Stubs.Syntax.Syntax
open FStar.Tactics.V2.SyntaxCoercions
open FStar.Tactics.V2.SyntaxHelpers
open FStar.Tactics.V2.Derived
open FStar.Tactics.Util
open FStar.Tactics.NamedView
exception NotFound
let meta_projectors = ()
(* Thunked version of debug *)
let debug (f : unit -> Tac string) : Tac unit =
if debugging () then
print (f ())
[@@plugin]
let mk_one_projector (unf:list string) (np:nat) (i:nat) : Tac unit =
debug (fun () -> dump "ENTRY mk_one_projector"; "");
let _params = repeatn np intro in
let thing : binding = intro () in
let r = t_destruct thing in
match r with
| [(cons, arity)] -> begin
if (i >= arity) then
fail "proj: bad index in mk_one_projector";
let _ = repeatn i intro in
let the_b = intro () in
let _ = repeatn (arity-i-1) intro in
let eq_b : binding = intro () in
rewrite eq_b;
norm [iota; delta_only unf; zeta_full];
(* NB: ^ zeta_full above so we reduce under matches too. Since
we are not unfolding anything but the projectors, which are
not, recursive, this should not bring about any divergence. An
alternative is to use NBE. *)
exact the_b
end
| _ -> fail "proj: more than one case?"
[@@plugin]
let mk_one_method (proj:string) (np:nat) : Tac unit =
debug (fun () -> dump "ENTRY mk_one_method"; "");
let nm = explode_qn proj in
let params = repeatn np (fun () -> let b : binding = intro () in
(binding_to_term b, Q_Implicit)) in
let thing : binding = intro () in
let proj = pack (Tv_FVar (pack_fv nm)) in
exact (mk_app proj (params @ [(binding_to_term thing, Q_Explicit)]))
let subst_map (ss : list (namedv * fv)) (r:term) (t : term) : Tac term =
let subst = List.Tot.map (fun (x, fv) -> NT (Reflection.V2.pack_namedv x) (mk_e_app (Tv_FVar fv) [r])) ss in
subst_term subst t
let binder_mk_implicit (b:binder) : binder =
let q =
match b.qual with
| Q_Explicit -> Q_Implicit
| q -> q (* keep Q_Meta as it is *)
in
{ b with qual = q }
let binder_to_term (b:binder) : Tot term =
pack (Tv_Var (binder_to_namedv b))
let binder_argv (b:binder) : Tot argv =
let q =
match b.qual with
| Q_Meta _ -> Q_Implicit
| q -> q
in
(binder_to_term b, q)
let rec list_last #a (xs : list a) : Tac a =
match xs with
| [] -> fail "list_last: empty"
| [x] -> x
| _::xs -> list_last xs | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.SyntaxHelpers.fst.checked",
"FStar.Tactics.V2.SyntaxCoercions.fst.checked",
"FStar.Tactics.V2.Derived.fst.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Typeclasses.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Stubs.Tactics.V2.Builtins.fsti.checked",
"FStar.Stubs.Syntax.Syntax.fsti.checked",
"FStar.Reflection.V2.TermEq.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Tactics.MkProjectors.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.NamedView",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.SyntaxHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.SyntaxCoercions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Syntax.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Reflection.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | i: Prims.int -> FStar.Tactics.NamedView.term | Prims.Tot | [
"total"
] | [] | [
"Prims.int",
"FStar.Stubs.Reflection.V2.Builtins.pack_ln",
"FStar.Stubs.Reflection.V2.Data.Tv_Const",
"FStar.Stubs.Reflection.V2.Data.C_Int",
"FStar.Tactics.NamedView.term"
] | [] | false | false | false | true | false | let embed_int (i: int) : term =
| let open FStar.Reflection.V2 in pack_ln (Tv_Const (C_Int i)) | false |
Vale.Poly1305.Bitvectors.fst | Vale.Poly1305.Bitvectors.lemma_shr2 | val lemma_shr2: (x:uint_t 64) -> Lemma
((shift_right #64 x 2 == udiv #64 x 4))
[SMTPat (shift_right #64 x 2)] | val lemma_shr2: (x:uint_t 64) -> Lemma
((shift_right #64 x 2 == udiv #64 x 4))
[SMTPat (shift_right #64 x 2)] | let lemma_shr2 x =
assert_by_tactic (shift_right #64 x 2 == udiv #64 x 4) bv_tac | {
"file_name": "vale/code/crypto/poly1305/x64/Vale.Poly1305.Bitvectors.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 63,
"end_line": 19,
"start_col": 0,
"start_line": 18
} | module Vale.Poly1305.Bitvectors
open FStar.BV
open FStar.Tactics
open FStar.Tactics.Derived
open FStar.Tactics.BV
open FStar.Mul
open FStar.UInt
open FStar.Math.Lemmas
open Vale.Lib.Tactics
open Vale.Lib.Bv_s
open Vale.Math.Bits
// tweak options?
#reset-options "--smtencoding.elim_box true"
//NOTE: Using the split tactic seems to slowdown execution by a lot. | {
"checked_file": "/",
"dependencies": [
"Vale.Math.Bits.fsti.checked",
"Vale.Lib.Tactics.fst.checked",
"Vale.Lib.Bv_s.fst.checked",
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Tactics.Derived.fst.checked",
"FStar.Tactics.BV.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.BV.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Poly1305.Bitvectors.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Math.Bits",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Bv_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: FStar.UInt.uint_t 64
-> FStar.Pervasives.Lemma (ensures FStar.UInt.shift_right x 2 == FStar.UInt.udiv x 4)
[SMTPat (FStar.UInt.shift_right x 2)] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.UInt.uint_t",
"FStar.Tactics.Effect.assert_by_tactic",
"Prims.eq2",
"FStar.UInt.shift_right",
"FStar.UInt.udiv",
"FStar.Tactics.BV.bv_tac",
"Prims.unit"
] | [] | true | false | true | false | false | let lemma_shr2 x =
| assert_by_tactic (shift_right #64 x 2 == udiv #64 x 4) bv_tac | false |
FStar.Tactics.MkProjectors.fst | FStar.Tactics.MkProjectors.embed_string | val embed_string (s: string) : term | val embed_string (s: string) : term | let embed_string (s:string) : term =
let open FStar.Reflection.V2 in
pack_ln (Tv_Const (C_String s)) | {
"file_name": "ulib/FStar.Tactics.MkProjectors.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 33,
"end_line": 95,
"start_col": 0,
"start_line": 93
} | module FStar.Tactics.MkProjectors
(* NB: We cannot use typeclasses here, or any module that depends on
them, since they use the tactics defined here. So we must be careful
with our includes. *)
open FStar.List.Tot
open FStar.Reflection.V2
open FStar.Tactics.Effect
open FStar.Stubs.Tactics.V2.Builtins
open FStar.Stubs.Syntax.Syntax
open FStar.Tactics.V2.SyntaxCoercions
open FStar.Tactics.V2.SyntaxHelpers
open FStar.Tactics.V2.Derived
open FStar.Tactics.Util
open FStar.Tactics.NamedView
exception NotFound
let meta_projectors = ()
(* Thunked version of debug *)
let debug (f : unit -> Tac string) : Tac unit =
if debugging () then
print (f ())
[@@plugin]
let mk_one_projector (unf:list string) (np:nat) (i:nat) : Tac unit =
debug (fun () -> dump "ENTRY mk_one_projector"; "");
let _params = repeatn np intro in
let thing : binding = intro () in
let r = t_destruct thing in
match r with
| [(cons, arity)] -> begin
if (i >= arity) then
fail "proj: bad index in mk_one_projector";
let _ = repeatn i intro in
let the_b = intro () in
let _ = repeatn (arity-i-1) intro in
let eq_b : binding = intro () in
rewrite eq_b;
norm [iota; delta_only unf; zeta_full];
(* NB: ^ zeta_full above so we reduce under matches too. Since
we are not unfolding anything but the projectors, which are
not, recursive, this should not bring about any divergence. An
alternative is to use NBE. *)
exact the_b
end
| _ -> fail "proj: more than one case?"
[@@plugin]
let mk_one_method (proj:string) (np:nat) : Tac unit =
debug (fun () -> dump "ENTRY mk_one_method"; "");
let nm = explode_qn proj in
let params = repeatn np (fun () -> let b : binding = intro () in
(binding_to_term b, Q_Implicit)) in
let thing : binding = intro () in
let proj = pack (Tv_FVar (pack_fv nm)) in
exact (mk_app proj (params @ [(binding_to_term thing, Q_Explicit)]))
let subst_map (ss : list (namedv * fv)) (r:term) (t : term) : Tac term =
let subst = List.Tot.map (fun (x, fv) -> NT (Reflection.V2.pack_namedv x) (mk_e_app (Tv_FVar fv) [r])) ss in
subst_term subst t
let binder_mk_implicit (b:binder) : binder =
let q =
match b.qual with
| Q_Explicit -> Q_Implicit
| q -> q (* keep Q_Meta as it is *)
in
{ b with qual = q }
let binder_to_term (b:binder) : Tot term =
pack (Tv_Var (binder_to_namedv b))
let binder_argv (b:binder) : Tot argv =
let q =
match b.qual with
| Q_Meta _ -> Q_Implicit
| q -> q
in
(binder_to_term b, q)
let rec list_last #a (xs : list a) : Tac a =
match xs with
| [] -> fail "list_last: empty"
| [x] -> x
| _::xs -> list_last xs
let embed_int (i:int) : term =
let open FStar.Reflection.V2 in
pack_ln (Tv_Const (C_Int i)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.SyntaxHelpers.fst.checked",
"FStar.Tactics.V2.SyntaxCoercions.fst.checked",
"FStar.Tactics.V2.Derived.fst.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Typeclasses.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Stubs.Tactics.V2.Builtins.fsti.checked",
"FStar.Stubs.Syntax.Syntax.fsti.checked",
"FStar.Reflection.V2.TermEq.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Tactics.MkProjectors.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.NamedView",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.SyntaxHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.SyntaxCoercions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Syntax.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Reflection.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: Prims.string -> FStar.Tactics.NamedView.term | Prims.Tot | [
"total"
] | [] | [
"Prims.string",
"FStar.Stubs.Reflection.V2.Builtins.pack_ln",
"FStar.Stubs.Reflection.V2.Data.Tv_Const",
"FStar.Stubs.Reflection.V2.Data.C_String",
"FStar.Tactics.NamedView.term"
] | [] | false | false | false | true | false | let embed_string (s: string) : term =
| let open FStar.Reflection.V2 in pack_ln (Tv_Const (C_String s)) | false |
Vale.Poly1305.Bitvectors.fst | Vale.Poly1305.Bitvectors.lemma_bytes_power2 | val lemma_bytes_power2: unit ->
Lemma (ensures (pow2 0 == 0x1 /\
pow2 8 == 0x100 /\
pow2 16 == 0x10000 /\
pow2 24 == 0x1000000 /\
pow2 32 == 0x100000000 /\
pow2 40 == 0x10000000000 /\
pow2 48 == 0x1000000000000 /\
pow2 56 == 0x100000000000000)) | val lemma_bytes_power2: unit ->
Lemma (ensures (pow2 0 == 0x1 /\
pow2 8 == 0x100 /\
pow2 16 == 0x10000 /\
pow2 24 == 0x1000000 /\
pow2 32 == 0x100000000 /\
pow2 40 == 0x10000000000 /\
pow2 48 == 0x1000000000000 /\
pow2 56 == 0x100000000000000)) | let lemma_bytes_power2 () =
assert_norm (pow2 0 == 0x1);
assert_norm (pow2 8 == 0x100);
assert_norm (pow2 16 == 0x10000);
assert_norm (pow2 24 == 0x1000000);
assert_norm (pow2 32 == 0x100000000);
assert_norm (pow2 40 == 0x10000000000);
assert_norm (pow2 48 == 0x1000000000000);
assert_norm (pow2 56 == 0x100000000000000);
() | {
"file_name": "vale/code/crypto/poly1305/x64/Vale.Poly1305.Bitvectors.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 4,
"end_line": 253,
"start_col": 0,
"start_line": 244
} | module Vale.Poly1305.Bitvectors
open FStar.BV
open FStar.Tactics
open FStar.Tactics.Derived
open FStar.Tactics.BV
open FStar.Mul
open FStar.UInt
open FStar.Math.Lemmas
open Vale.Lib.Tactics
open Vale.Lib.Bv_s
open Vale.Math.Bits
// tweak options?
#reset-options "--smtencoding.elim_box true"
//NOTE: Using the split tactic seems to slowdown execution by a lot.
let lemma_shr2 x =
assert_by_tactic (shift_right #64 x 2 == udiv #64 x 4) bv_tac
let lemma_shr4 x =
assert_by_tactic (shift_right #64 x 4 == udiv #64 x 16) bv_tac
let lemma_and_mod_n x =
assert_by_tactic (logand #64 x 3 == mod #64 x 4) (bv_tac);
assert_by_tactic (logand #64 x 15 == mod #64 x 16) (bv_tac)
let lemma_clear_lower_2 x =
assert_by_tactic
(logand #64 x 0xfffffffffffffffc == mul_mod #64 (udiv #64 x 4) 4)
bv_tac
let lemma_and_constants x =
assert_by_tactic (logand #64 x 0 == (0 <: uint_t 64)) bv_tac;
assert_by_tactic (logand #64 x 0xffffffffffffffff == x) bv_tac
let lemma_poly_constants x =
// using split in this seems to hang execution.
assert_by_tactic
(logand #64 x 0x0ffffffc0fffffff < (0x1000000000000000 <: uint_t 64))
(fun () -> bv_tac_lt 64);
assert_by_tactic
(logand #64 x 0x0ffffffc0ffffffc < (0x1000000000000000 <: uint_t 64))
(fun () -> bv_tac_lt 64);
assert_by_tactic
(mod #64 (logand #64 x 0x0ffffffc0ffffffc) 4 == (0 <: uint_t 64))
(fun () -> bv_tac ())
let lemma_and_commutes x y =
assert_by_tactic
(logand #64 x y == logand #64 y x)
bv_tac
let lemma_bv128_64_64_and_helper' (x0:bv_t 64) (x1:bv_t 64) (y0:bv_t 64) (y1:bv_t 64) :
Lemma (requires True)
(ensures ((bvor #128 (bvshl #128 (bv_uext #64 #64 (bvand #64 x1 y1)) 64)
(bv_uext #64 #64 (bvand #64 x0 y0))) ==
bvand #128 (bvor #128 (bvshl #128 (bv_uext #64 #64 x1) 64)
(bv_uext #64 #64 x0))
(bvor #128 (bvshl #128 (bv_uext #64 #64 y1) 64)
(bv_uext #64 #64 y0)))) = ()
// Rewrite all equalities and then the goal is trivial for Z3.
// Without rewriting this does not go through.
// I believe the reason is related to a previously reported issue with the way
// Z3 bit-blasts through the Boxing/Unboxing functions. I thought this was fixed
// but it may not be the case. Notice that by rewriting with tactics the solver
// only gets to see one big term without any boxing or unboxing inside it.
let lemma_bv128_64_64_and_helper x x0 x1 y y0 y1 z z0 z1 =
lemma_bv128_64_64_and_helper' x0 x1 y0 y1;
assert_by_tactic (z == bvand #128 x y)
(fun () -> destruct_conj ();
rewrite_eqs_from_context ())
let bv128_64_64 x0 x1 = bvor (bvshl (bv_uext #64 #64 x1) 64) (bv_uext #64 #64 x0)
unfold let uint_to_nat (#n:nat) (x:uint_t n) : r:nat{r = x} =
assert (x < pow2 n);
modulo_lemma x (pow2 n);
x
let uint_ext (#n : nat) (#m : nat{n <= m}) (x : uint_t n) : r:(uint_t m){uint_to_nat r = uint_to_nat x} =
assert_norm(fits x n);
pow2_le_compat m n;
assert_norm(fits x m);
modulo_lemma x (pow2 m);
to_uint_t m x
#reset-options "--smtencoding.elim_box true --smtencoding.l_arith_repr boxwrap --smtencoding.nl_arith_repr boxwrap"
let mul_bvshl (u:uint_t 64) :
Lemma (0x10000000000000000 * u < pow2 128 /\
(int2bv #128 (0x10000000000000000 * u) ==
bvshl (bv_uext #64 #64 (int2bv u)) 64)) =
assert_norm ( 0x10000000000000000 * pow2 63 < pow2 128);
modulo_lemma (0x10000000000000000 * u) (pow2 128);
assert_by_tactic
(int2bv #128 (mul_mod #128 0x10000000000000000 (uint_ext #64 #128 u)) ==
bvmul #128 (int2bv #128 0x10000000000000000) (uint_ext #64 #128 u))
(fun () -> mapply (`trans); arith_to_bv_tac (); trefl ())
#reset-options "--smtencoding.elim_box true"
let plus_bvor (u h:bv_t 128) :
Lemma (bvand u h = bv_zero ==> bvadd u h == bvor u h) = ()
let lemma_bv128_64_64_and x x0 x1 y y0 y1 z z0 z1 =
assert_by_tactic (z == bvand #128 x y)
(fun () -> destruct_conj ();
rewrite_eqs_from_context ();
norm[delta])
#reset-options "--smtencoding.elim_box true --z3refresh --z3rlimit 20 --max_ifuel 1 --max_fuel 1"
let int2bv_uext_64_128 (x1 : nat) :
Lemma (requires (FStar.UInt.size x1 64))
(ensures (bv_uext #64 #64 (int2bv #64 x1) == int2bv #128 x1)) =
assert (64 <= 128);
pow2_le_compat 128 64;
assert (x1 < pow2 128);
modulo_lemma x1 (pow2 128); // x1 % pow2 128 = x1
assert (FStar.UInt.size x1 128);
assert_by_tactic (bv_uext #64 #64 (int2bv #64 x1) == int2bv #128 x1)
(fun () -> dump "..";
norm[delta_only [`%uint_ext; `%FStar.UInt.to_uint_t]];
// grewrite (quote (x1 % pow2 128)) (quote x1);
dump "After norm"; smt ())
#reset-options "--smtencoding.l_arith_repr native --smtencoding.nl_arith_repr wrapped --smtencoding.elim_box true --z3cliopt smt.arith.nl=false --max_fuel 1 --max_ifuel 0"
let lowerUpper128m (l:uint_t 64) (u:uint_t 64) : uint_t 128 =
add_hide #128 (mul_hide #128 (uext #64 #64 u) 0x10000000000000000) (uext #64 #64 l)
let lowerUpper128b (l:bv_t 64) (u:bv_t 64) : bv_t 128 =
b_add #128 (b_mul #128 (b_uext #64 #64 u) 0x10000000000000000) (b_uext #64 #64 l)
//this was so flaky, new options helped.
#reset-options "--smtencoding.elim_box true --z3refresh --z3rlimit 40 --max_ifuel 1 --max_fuel 1"
let lemma_lowerUpper128_andu
(x:uint_t 128) (x0:uint_t 64) (x1:uint_t 64) (y:uint_t 128)
(y0:uint_t 64) (y1:uint_t 64) (z:uint_t 128) (z0:uint_t 64) (z1:uint_t 64) :
Lemma
(requires
z0 == logand #64 x0 y0 /\
z1 == logand #64 x1 y1 /\
x == lowerUpper128u x0 x1 /\
y == lowerUpper128u y0 y1 /\
z == lowerUpper128u z0 z1)
(ensures z == logand #128 x y)
=
let bx0 = b_i2b x0 in
let bx1 = b_i2b x1 in
let by0 = b_i2b y0 in
let by1 = b_i2b y1 in
assert_norm (
lowerUpper128b (b_and bx0 by0) (b_and bx1 by1) ==
b_and (lowerUpper128b bx0 bx1) (lowerUpper128b by0 by1));
lemma_i2b_equal
(lowerUpper128m (logand x0 y0) (logand x1 y1))
(logand (lowerUpper128m x0 x1) (lowerUpper128m y0 y1));
assert_norm (lowerUpper128m x0 x1 == lowerUpper128u x0 x1);
assert_norm (lowerUpper128m y0 y1 == lowerUpper128u y0 y1);
assert_norm (lowerUpper128m z0 z1 == lowerUpper128u z0 z1);
()
#reset-options "--smtencoding.elim_box true --z3cliopt smt.case_split=3"
let lemma_bytes_shift_constants0 x =
assert_by_tactic (shift_left #64 0 3 == (0 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 0 == (0x1 <: uint_t 64)) bv_tac
let lemma_bytes_shift_constants1 x =
assert_by_tactic (shift_left #64 1 3 == (8 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 8 == (0x100 <: uint_t 64)) bv_tac
let lemma_bytes_shift_constants2 x =
assert_by_tactic (shift_left #64 2 3 == (16 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 16 == (0x10000 <: uint_t 64)) bv_tac
let lemma_bytes_shift_constants3 x =
assert_by_tactic (shift_left #64 3 3 == (24 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 24 == (0x1000000 <: uint_t 64)) bv_tac
let lemma_bytes_shift_constants4 x =
assert_by_tactic (shift_left #64 4 3 == (32 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 32 == (0x100000000 <: uint_t 64)) bv_tac
let lemma_bytes_shift_constants5 x =
assert_by_tactic (shift_left #64 5 3 == (40 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 40 == (0x10000000000 <: uint_t 64)) bv_tac
let lemma_bytes_shift_constants6 x =
assert_by_tactic (shift_left #64 6 3 == (48 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 48 == (0x1000000000000 <: uint_t 64)) bv_tac
let lemma_bytes_shift_constants7 x =
assert_by_tactic (shift_left #64 7 3 == (56 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 56 == (0x100000000000000 <: uint_t 64)) bv_tac
let lemma_bytes_and_mod0 x =
assert_by_tactic (logand #64 x (0x1 - 1) == mod #64 x 0x1) bv_tac
let lemma_bytes_and_mod1 x =
assert_by_tactic (logand #64 x (0x100 - 1) == mod #64 x 0x100) bv_tac
let lemma_bytes_and_mod2 x =
assert_by_tactic (logand #64 x (0x10000 - 1) == mod #64 x 0x10000) bv_tac
let lemma_bytes_and_mod3 x =
assert_by_tactic (logand #64 x (0x1000000 - 1) == mod #64 x 0x1000000) bv_tac
let lemma_bytes_and_mod4 x =
assert_by_tactic (logand #64 x (0x100000000 - 1) == mod #64 x 0x100000000) bv_tac
let lemma_bytes_and_mod5 x =
assert_by_tactic (logand #64 x (0x10000000000 - 1) == mod #64 x 0x10000000000) bv_tac
let lemma_bytes_and_mod6 x =
assert_by_tactic (logand #64 x (0x1000000000000 - 1) == mod #64 x 0x1000000000000) bv_tac
let lemma_bytes_and_mod7 x =
assert_by_tactic (logand #64 x (0x100000000000000 - 1) == mod #64 x 0x100000000000000) bv_tac
let lemma_bytes_and_mod x y =
match y with
| 0 ->
lemma_bytes_shift_constants0 ();
lemma_bytes_and_mod0 x
| 1 ->
lemma_bytes_shift_constants1 ();
lemma_bytes_and_mod1 x
| 2 ->
lemma_bytes_shift_constants2 ();
lemma_bytes_and_mod2 x
| 3 ->
lemma_bytes_shift_constants3 ();
lemma_bytes_and_mod3 x
| 4 ->
lemma_bytes_shift_constants4 ();
lemma_bytes_and_mod4 x
| 5 ->
lemma_bytes_shift_constants5 ();
lemma_bytes_and_mod5 x
| 6 ->
lemma_bytes_shift_constants6 ();
lemma_bytes_and_mod6 x
| 7 ->
lemma_bytes_shift_constants7 ();
lemma_bytes_and_mod7 x
| _ -> magic () | {
"checked_file": "/",
"dependencies": [
"Vale.Math.Bits.fsti.checked",
"Vale.Lib.Tactics.fst.checked",
"Vale.Lib.Bv_s.fst.checked",
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Tactics.Derived.fst.checked",
"FStar.Tactics.BV.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.BV.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Poly1305.Bitvectors.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Math.Bits",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Bv_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3",
"smt.case_split=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit
-> FStar.Pervasives.Lemma
(ensures
Prims.pow2 0 == 0x1 /\ Prims.pow2 8 == 0x100 /\ Prims.pow2 16 == 0x10000 /\
Prims.pow2 24 == 0x1000000 /\ Prims.pow2 32 == 0x100000000 /\ Prims.pow2 40 == 0x10000000000 /\
Prims.pow2 48 == 0x1000000000000 /\ Prims.pow2 56 == 0x100000000000000) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.unit",
"FStar.Pervasives.assert_norm",
"Prims.eq2",
"Prims.int",
"Prims.pow2"
] | [] | true | false | true | false | false | let lemma_bytes_power2 () =
| assert_norm (pow2 0 == 0x1);
assert_norm (pow2 8 == 0x100);
assert_norm (pow2 16 == 0x10000);
assert_norm (pow2 24 == 0x1000000);
assert_norm (pow2 32 == 0x100000000);
assert_norm (pow2 40 == 0x10000000000);
assert_norm (pow2 48 == 0x1000000000000);
assert_norm (pow2 56 == 0x100000000000000);
() | false |
FStar.WellFoundedRelation.fsti | FStar.WellFoundedRelation.default_relation | val default_relation (#a: Type u#a) (x1 x2: a) : Type0 | val default_relation (#a: Type u#a) (x1 x2: a) : Type0 | let default_relation (#a: Type u#a) (x1: a) (x2: a) : Type0 = x1 << x2 | {
"file_name": "ulib/FStar.WellFoundedRelation.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 70,
"end_line": 122,
"start_col": 0,
"start_line": 122
} | (*
Copyright 2022 Jay Lorch and Nikhil Swamy, 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.
*)
(* This library is intended to simplify using well-founded relations
in decreases clauses.
The key data structure is `wfr_t a`, which encapsulates a
well-founded relation on `a`. Specifically, the predicate
`wfr.relation x1 x2` means that `x1` precedes `x2` in the
well-founded relation described by `wfr`.
You can then use this relatedness to show that a function is
decreasing in a certain term. Whenever `wfr.relation x1 x2` holds,
`wfr.decreaser x1 << wfr.decreaser x2` also holds. The library has
an ambient lemma triggered by seeing two instances of
`wfr.decreaser`, so you can use `wfr.decreaser x` in your decreases
clause. For example:
// Define `nat_nat_wfr` to represent the lexicographically-precedes
// relation between two elements of type `nat * nat`. That is,
// `(x1, y1)` is related to `(x2, y2)` if
// `x1 < x2 \/ (x1 == x2 /\ y1 < y2)`.
let nat_nat_wfr = lex_nondep_wfr (default_wfr nat) (default_wfr nat)
// To show that `f` is well-defined, we use the decreases clause
// `nat_nat_wfr.decreaser (x, y)`. We then need to show, on each
// recursive call, that the parameters x2 and y2 to the nested
// call satisfy `nat_nat_wfr.relation (x2, y2) (x, y)`.
let rec f (x: nat) (y: nat)
: Tot nat (decreases (nat_nat_wfr.decreaser (x, y))) =
if x = 0 then
0
else if y = 0 then (
// This assertion isn't necessary; it's just for illustration
assert (nat_nat_wfr.relation (x - 1, 100) (x, y));
f (x - 1) 100
)
else (
// This assertion isn't necessary; it's just for illustration
assert (nat_nat_wfr.relation (x, y - 1) (x, y));
f x (y - 1)
)
One way `wfr_t` can be useful is that it simplifies debugging when
the SMT solver can't verify termination. You can assert the
relation explicitly (as in the examples above), and if the assertion
doesn't hold you can try to prove it. If you instead use something
like `decreases %[x, y]`, it's harder to debug because you can't
`assert (%[x2, y2] << %[x, y])`.
But where `wfr_t` is most useful is in writing a function that takes
a well-founded relation as input. Here's an illustrative example:
let rec count_steps_to_none
(#a: Type)
(wfr: wfr_t a)
(stepper: (x: a) -> (y: option a{Some? y ==> wfr.relation (Some?.v y) x}))
(start: option a)
: Tot nat (decreases (option_wfr wfr).decreaser start) =
match start with
| None -> 0
| Some x -> 1 + count_steps_to_none wfr stepper (stepper x)
`wfr_t` is also useful when composing a well-founded relation
produced using `acc` (from the FStar.WellFounded library) with one
or more other well-founded relations.
There are a few ways to build a `wfr_t`, described in more detail in
comments throughout this file. Those ways are:
`default_wfr a`
`empty_wfr a`
`acc_to_wfr r f`
`subrelation_to_wfr r wfr`
`inverse_image_to_wfr r f wfr`
`lex_nondep_wfr wfr_a wfr_b`
`lex_dep_wfr wfr_a a_to_wfr_b`
`bool_wfr`
`option_wfr wfr`
*)
module FStar.WellFoundedRelation
noeq type acc_classical (#a: Type u#a) (r: a -> a -> Type0) (x: a) : Type u#a =
| AccClassicalIntro : access_smaller:(y: a{r y x} -> acc_classical r y) -> acc_classical r x
noeq type wfr_t (a: Type u#a) : Type u#(a + 1) =
{
relation: a -> a -> Type0;
decreaser: (x: a -> acc_classical relation x);
proof: (x1: a) -> (x2: a) ->
Lemma (requires relation x1 x2) (ensures decreaser x1 << decreaser x2);
}
let ambient_wfr_lemma (#a: Type u#a) (wfr: wfr_t a) (x1: a) (x2: a)
: Lemma (requires wfr.relation x1 x2)
(ensures wfr.decreaser x1 << wfr.decreaser x2)
[SMTPat (wfr.decreaser x1); SMTPat (wfr.decreaser x2)] =
wfr.proof x1 x2
/// `default_wfr a` is the well-founded relation built into F* for
/// type `a`. For instance, for `nat` it's the less-than relation.
/// For an inductive type it's the sub-term ordering.
///
/// `(default_wfr a).relation` is `default_relation` as defined below. | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.WellFounded.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.WellFoundedRelation.fsti"
} | [
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x1: a -> x2: a -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Prims.precedes"
] | [] | false | false | false | true | true | let default_relation (#a: Type u#a) (x1 x2: a) : Type0 =
| x1 << x2 | false |
FStar.WellFoundedRelation.fsti | FStar.WellFoundedRelation.ambient_wfr_lemma | val ambient_wfr_lemma (#a: Type u#a) (wfr: wfr_t a) (x1 x2: a)
: Lemma (requires wfr.relation x1 x2)
(ensures wfr.decreaser x1 << wfr.decreaser x2)
[SMTPat (wfr.decreaser x1); SMTPat (wfr.decreaser x2)] | val ambient_wfr_lemma (#a: Type u#a) (wfr: wfr_t a) (x1 x2: a)
: Lemma (requires wfr.relation x1 x2)
(ensures wfr.decreaser x1 << wfr.decreaser x2)
[SMTPat (wfr.decreaser x1); SMTPat (wfr.decreaser x2)] | let ambient_wfr_lemma (#a: Type u#a) (wfr: wfr_t a) (x1: a) (x2: a)
: Lemma (requires wfr.relation x1 x2)
(ensures wfr.decreaser x1 << wfr.decreaser x2)
[SMTPat (wfr.decreaser x1); SMTPat (wfr.decreaser x2)] =
wfr.proof x1 x2 | {
"file_name": "ulib/FStar.WellFoundedRelation.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 17,
"end_line": 114,
"start_col": 0,
"start_line": 110
} | (*
Copyright 2022 Jay Lorch and Nikhil Swamy, 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.
*)
(* This library is intended to simplify using well-founded relations
in decreases clauses.
The key data structure is `wfr_t a`, which encapsulates a
well-founded relation on `a`. Specifically, the predicate
`wfr.relation x1 x2` means that `x1` precedes `x2` in the
well-founded relation described by `wfr`.
You can then use this relatedness to show that a function is
decreasing in a certain term. Whenever `wfr.relation x1 x2` holds,
`wfr.decreaser x1 << wfr.decreaser x2` also holds. The library has
an ambient lemma triggered by seeing two instances of
`wfr.decreaser`, so you can use `wfr.decreaser x` in your decreases
clause. For example:
// Define `nat_nat_wfr` to represent the lexicographically-precedes
// relation between two elements of type `nat * nat`. That is,
// `(x1, y1)` is related to `(x2, y2)` if
// `x1 < x2 \/ (x1 == x2 /\ y1 < y2)`.
let nat_nat_wfr = lex_nondep_wfr (default_wfr nat) (default_wfr nat)
// To show that `f` is well-defined, we use the decreases clause
// `nat_nat_wfr.decreaser (x, y)`. We then need to show, on each
// recursive call, that the parameters x2 and y2 to the nested
// call satisfy `nat_nat_wfr.relation (x2, y2) (x, y)`.
let rec f (x: nat) (y: nat)
: Tot nat (decreases (nat_nat_wfr.decreaser (x, y))) =
if x = 0 then
0
else if y = 0 then (
// This assertion isn't necessary; it's just for illustration
assert (nat_nat_wfr.relation (x - 1, 100) (x, y));
f (x - 1) 100
)
else (
// This assertion isn't necessary; it's just for illustration
assert (nat_nat_wfr.relation (x, y - 1) (x, y));
f x (y - 1)
)
One way `wfr_t` can be useful is that it simplifies debugging when
the SMT solver can't verify termination. You can assert the
relation explicitly (as in the examples above), and if the assertion
doesn't hold you can try to prove it. If you instead use something
like `decreases %[x, y]`, it's harder to debug because you can't
`assert (%[x2, y2] << %[x, y])`.
But where `wfr_t` is most useful is in writing a function that takes
a well-founded relation as input. Here's an illustrative example:
let rec count_steps_to_none
(#a: Type)
(wfr: wfr_t a)
(stepper: (x: a) -> (y: option a{Some? y ==> wfr.relation (Some?.v y) x}))
(start: option a)
: Tot nat (decreases (option_wfr wfr).decreaser start) =
match start with
| None -> 0
| Some x -> 1 + count_steps_to_none wfr stepper (stepper x)
`wfr_t` is also useful when composing a well-founded relation
produced using `acc` (from the FStar.WellFounded library) with one
or more other well-founded relations.
There are a few ways to build a `wfr_t`, described in more detail in
comments throughout this file. Those ways are:
`default_wfr a`
`empty_wfr a`
`acc_to_wfr r f`
`subrelation_to_wfr r wfr`
`inverse_image_to_wfr r f wfr`
`lex_nondep_wfr wfr_a wfr_b`
`lex_dep_wfr wfr_a a_to_wfr_b`
`bool_wfr`
`option_wfr wfr`
*)
module FStar.WellFoundedRelation
noeq type acc_classical (#a: Type u#a) (r: a -> a -> Type0) (x: a) : Type u#a =
| AccClassicalIntro : access_smaller:(y: a{r y x} -> acc_classical r y) -> acc_classical r x
noeq type wfr_t (a: Type u#a) : Type u#(a + 1) =
{
relation: a -> a -> Type0;
decreaser: (x: a -> acc_classical relation x);
proof: (x1: a) -> (x2: a) ->
Lemma (requires relation x1 x2) (ensures decreaser x1 << decreaser x2);
} | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.WellFounded.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.WellFoundedRelation.fsti"
} | [
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | wfr: FStar.WellFoundedRelation.wfr_t a -> x1: a -> x2: a
-> FStar.Pervasives.Lemma (requires Mkwfr_t?.relation wfr x1 x2)
(ensures Mkwfr_t?.decreaser wfr x1 << Mkwfr_t?.decreaser wfr x2)
[SMTPat (Mkwfr_t?.decreaser wfr x1); SMTPat (Mkwfr_t?.decreaser wfr x2)] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.WellFoundedRelation.wfr_t",
"FStar.WellFoundedRelation.__proj__Mkwfr_t__item__proof",
"Prims.unit",
"FStar.WellFoundedRelation.__proj__Mkwfr_t__item__relation",
"Prims.squash",
"Prims.precedes",
"FStar.WellFoundedRelation.acc_classical",
"FStar.WellFoundedRelation.__proj__Mkwfr_t__item__decreaser",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"Prims.Nil"
] | [] | true | false | true | false | false | let ambient_wfr_lemma (#a: Type u#a) (wfr: wfr_t a) (x1 x2: a)
: Lemma (requires wfr.relation x1 x2)
(ensures wfr.decreaser x1 << wfr.decreaser x2)
[SMTPat (wfr.decreaser x1); SMTPat (wfr.decreaser x2)] =
| wfr.proof x1 x2 | false |
Vale.Poly1305.Bitvectors.fst | Vale.Poly1305.Bitvectors.lemma_poly_constants | val lemma_poly_constants: x:uint_t 64 ->
Lemma (logand #64 x 0x0ffffffc0fffffff < 0x1000000000000000 /\
logand #64 x 0x0ffffffc0ffffffc < 0x1000000000000000 /\
mod #64 (logand #64 x 0x0ffffffc0ffffffc) 4 == 0)
[SMTPat (logand #64 x 0x0ffffffc0fffffff);
SMTPat (logand #64 x 0x0ffffffc0ffffffc);
SMTPat (logand #64 x 0x0ffffffc0ffffffc)] | val lemma_poly_constants: x:uint_t 64 ->
Lemma (logand #64 x 0x0ffffffc0fffffff < 0x1000000000000000 /\
logand #64 x 0x0ffffffc0ffffffc < 0x1000000000000000 /\
mod #64 (logand #64 x 0x0ffffffc0ffffffc) 4 == 0)
[SMTPat (logand #64 x 0x0ffffffc0fffffff);
SMTPat (logand #64 x 0x0ffffffc0ffffffc);
SMTPat (logand #64 x 0x0ffffffc0ffffffc)] | let lemma_poly_constants x =
// using split in this seems to hang execution.
assert_by_tactic
(logand #64 x 0x0ffffffc0fffffff < (0x1000000000000000 <: uint_t 64))
(fun () -> bv_tac_lt 64);
assert_by_tactic
(logand #64 x 0x0ffffffc0ffffffc < (0x1000000000000000 <: uint_t 64))
(fun () -> bv_tac_lt 64);
assert_by_tactic
(mod #64 (logand #64 x 0x0ffffffc0ffffffc) 4 == (0 <: uint_t 64))
(fun () -> bv_tac ()) | {
"file_name": "vale/code/crypto/poly1305/x64/Vale.Poly1305.Bitvectors.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 27,
"end_line": 49,
"start_col": 0,
"start_line": 39
} | module Vale.Poly1305.Bitvectors
open FStar.BV
open FStar.Tactics
open FStar.Tactics.Derived
open FStar.Tactics.BV
open FStar.Mul
open FStar.UInt
open FStar.Math.Lemmas
open Vale.Lib.Tactics
open Vale.Lib.Bv_s
open Vale.Math.Bits
// tweak options?
#reset-options "--smtencoding.elim_box true"
//NOTE: Using the split tactic seems to slowdown execution by a lot.
let lemma_shr2 x =
assert_by_tactic (shift_right #64 x 2 == udiv #64 x 4) bv_tac
let lemma_shr4 x =
assert_by_tactic (shift_right #64 x 4 == udiv #64 x 16) bv_tac
let lemma_and_mod_n x =
assert_by_tactic (logand #64 x 3 == mod #64 x 4) (bv_tac);
assert_by_tactic (logand #64 x 15 == mod #64 x 16) (bv_tac)
let lemma_clear_lower_2 x =
assert_by_tactic
(logand #64 x 0xfffffffffffffffc == mul_mod #64 (udiv #64 x 4) 4)
bv_tac
let lemma_and_constants x =
assert_by_tactic (logand #64 x 0 == (0 <: uint_t 64)) bv_tac;
assert_by_tactic (logand #64 x 0xffffffffffffffff == x) bv_tac | {
"checked_file": "/",
"dependencies": [
"Vale.Math.Bits.fsti.checked",
"Vale.Lib.Tactics.fst.checked",
"Vale.Lib.Bv_s.fst.checked",
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Tactics.Derived.fst.checked",
"FStar.Tactics.BV.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.BV.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Poly1305.Bitvectors.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Math.Bits",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Bv_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: FStar.UInt.uint_t 64
-> FStar.Pervasives.Lemma
(ensures
FStar.UInt.logand x 0x0ffffffc0fffffff < 0x1000000000000000 /\
FStar.UInt.logand x 0x0ffffffc0ffffffc < 0x1000000000000000 /\
FStar.UInt.mod (FStar.UInt.logand x 0x0ffffffc0ffffffc) 4 == 0)
[
SMTPat (FStar.UInt.logand x 0x0ffffffc0fffffff);
SMTPat (FStar.UInt.logand x 0x0ffffffc0ffffffc);
SMTPat (FStar.UInt.logand x 0x0ffffffc0ffffffc)
] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.UInt.uint_t",
"FStar.Tactics.Effect.assert_by_tactic",
"Prims.eq2",
"FStar.UInt.mod",
"FStar.UInt.logand",
"Prims.unit",
"FStar.Tactics.BV.bv_tac",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Tactics.BV.bv_tac_lt"
] | [] | false | false | true | false | false | let lemma_poly_constants x =
| assert_by_tactic (logand #64 x 0x0ffffffc0fffffff < (0x1000000000000000 <: uint_t 64))
(fun () -> bv_tac_lt 64);
assert_by_tactic (logand #64 x 0x0ffffffc0ffffffc < (0x1000000000000000 <: uint_t 64))
(fun () -> bv_tac_lt 64);
assert_by_tactic (mod #64 (logand #64 x 0x0ffffffc0ffffffc) 4 == (0 <: uint_t 64))
(fun () -> bv_tac ()) | false |
FStar.WellFoundedRelation.fsti | FStar.WellFoundedRelation.empty_relation | val empty_relation (#a: Type u#a) (x1 x2: a) : Type0 | val empty_relation (#a: Type u#a) (x1 x2: a) : Type0 | let empty_relation (#a: Type u#a) (x1: a) (x2: a) : Type0 = False | {
"file_name": "ulib/FStar.WellFoundedRelation.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 65,
"end_line": 131,
"start_col": 0,
"start_line": 131
} | (*
Copyright 2022 Jay Lorch and Nikhil Swamy, 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.
*)
(* This library is intended to simplify using well-founded relations
in decreases clauses.
The key data structure is `wfr_t a`, which encapsulates a
well-founded relation on `a`. Specifically, the predicate
`wfr.relation x1 x2` means that `x1` precedes `x2` in the
well-founded relation described by `wfr`.
You can then use this relatedness to show that a function is
decreasing in a certain term. Whenever `wfr.relation x1 x2` holds,
`wfr.decreaser x1 << wfr.decreaser x2` also holds. The library has
an ambient lemma triggered by seeing two instances of
`wfr.decreaser`, so you can use `wfr.decreaser x` in your decreases
clause. For example:
// Define `nat_nat_wfr` to represent the lexicographically-precedes
// relation between two elements of type `nat * nat`. That is,
// `(x1, y1)` is related to `(x2, y2)` if
// `x1 < x2 \/ (x1 == x2 /\ y1 < y2)`.
let nat_nat_wfr = lex_nondep_wfr (default_wfr nat) (default_wfr nat)
// To show that `f` is well-defined, we use the decreases clause
// `nat_nat_wfr.decreaser (x, y)`. We then need to show, on each
// recursive call, that the parameters x2 and y2 to the nested
// call satisfy `nat_nat_wfr.relation (x2, y2) (x, y)`.
let rec f (x: nat) (y: nat)
: Tot nat (decreases (nat_nat_wfr.decreaser (x, y))) =
if x = 0 then
0
else if y = 0 then (
// This assertion isn't necessary; it's just for illustration
assert (nat_nat_wfr.relation (x - 1, 100) (x, y));
f (x - 1) 100
)
else (
// This assertion isn't necessary; it's just for illustration
assert (nat_nat_wfr.relation (x, y - 1) (x, y));
f x (y - 1)
)
One way `wfr_t` can be useful is that it simplifies debugging when
the SMT solver can't verify termination. You can assert the
relation explicitly (as in the examples above), and if the assertion
doesn't hold you can try to prove it. If you instead use something
like `decreases %[x, y]`, it's harder to debug because you can't
`assert (%[x2, y2] << %[x, y])`.
But where `wfr_t` is most useful is in writing a function that takes
a well-founded relation as input. Here's an illustrative example:
let rec count_steps_to_none
(#a: Type)
(wfr: wfr_t a)
(stepper: (x: a) -> (y: option a{Some? y ==> wfr.relation (Some?.v y) x}))
(start: option a)
: Tot nat (decreases (option_wfr wfr).decreaser start) =
match start with
| None -> 0
| Some x -> 1 + count_steps_to_none wfr stepper (stepper x)
`wfr_t` is also useful when composing a well-founded relation
produced using `acc` (from the FStar.WellFounded library) with one
or more other well-founded relations.
There are a few ways to build a `wfr_t`, described in more detail in
comments throughout this file. Those ways are:
`default_wfr a`
`empty_wfr a`
`acc_to_wfr r f`
`subrelation_to_wfr r wfr`
`inverse_image_to_wfr r f wfr`
`lex_nondep_wfr wfr_a wfr_b`
`lex_dep_wfr wfr_a a_to_wfr_b`
`bool_wfr`
`option_wfr wfr`
*)
module FStar.WellFoundedRelation
noeq type acc_classical (#a: Type u#a) (r: a -> a -> Type0) (x: a) : Type u#a =
| AccClassicalIntro : access_smaller:(y: a{r y x} -> acc_classical r y) -> acc_classical r x
noeq type wfr_t (a: Type u#a) : Type u#(a + 1) =
{
relation: a -> a -> Type0;
decreaser: (x: a -> acc_classical relation x);
proof: (x1: a) -> (x2: a) ->
Lemma (requires relation x1 x2) (ensures decreaser x1 << decreaser x2);
}
let ambient_wfr_lemma (#a: Type u#a) (wfr: wfr_t a) (x1: a) (x2: a)
: Lemma (requires wfr.relation x1 x2)
(ensures wfr.decreaser x1 << wfr.decreaser x2)
[SMTPat (wfr.decreaser x1); SMTPat (wfr.decreaser x2)] =
wfr.proof x1 x2
/// `default_wfr a` is the well-founded relation built into F* for
/// type `a`. For instance, for `nat` it's the less-than relation.
/// For an inductive type it's the sub-term ordering.
///
/// `(default_wfr a).relation` is `default_relation` as defined below.
let default_relation (#a: Type u#a) (x1: a) (x2: a) : Type0 = x1 << x2
val default_wfr (a: Type u#a) : (wfr: wfr_t a{wfr.relation == default_relation})
/// `empty_wfr a` is the empty well-founded relation, which doesn't relate any
/// pair of values.
///
/// `(empty_wfr a).relation` is `empty_relation` as defined below. | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.WellFounded.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.WellFoundedRelation.fsti"
} | [
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x1: a -> x2: a -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Prims.l_False"
] | [] | false | false | false | true | true | let empty_relation (#a: Type u#a) (x1 x2: a) : Type0 =
| False | false |
FStar.WellFoundedRelation.fsti | FStar.WellFoundedRelation.acc_relation | val acc_relation (#a: Type u#a) (r: (a -> a -> Type0)) (x1 x2: a) : Type0 | val acc_relation (#a: Type u#a) (r: (a -> a -> Type0)) (x1 x2: a) : Type0 | let acc_relation (#a: Type u#a) (r: a -> a -> Type0) (x1: a) (x2: a) : Type0 = exists (p: r x1 x2). True | {
"file_name": "ulib/FStar.WellFoundedRelation.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 104,
"end_line": 142,
"start_col": 0,
"start_line": 142
} | (*
Copyright 2022 Jay Lorch and Nikhil Swamy, 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.
*)
(* This library is intended to simplify using well-founded relations
in decreases clauses.
The key data structure is `wfr_t a`, which encapsulates a
well-founded relation on `a`. Specifically, the predicate
`wfr.relation x1 x2` means that `x1` precedes `x2` in the
well-founded relation described by `wfr`.
You can then use this relatedness to show that a function is
decreasing in a certain term. Whenever `wfr.relation x1 x2` holds,
`wfr.decreaser x1 << wfr.decreaser x2` also holds. The library has
an ambient lemma triggered by seeing two instances of
`wfr.decreaser`, so you can use `wfr.decreaser x` in your decreases
clause. For example:
// Define `nat_nat_wfr` to represent the lexicographically-precedes
// relation between two elements of type `nat * nat`. That is,
// `(x1, y1)` is related to `(x2, y2)` if
// `x1 < x2 \/ (x1 == x2 /\ y1 < y2)`.
let nat_nat_wfr = lex_nondep_wfr (default_wfr nat) (default_wfr nat)
// To show that `f` is well-defined, we use the decreases clause
// `nat_nat_wfr.decreaser (x, y)`. We then need to show, on each
// recursive call, that the parameters x2 and y2 to the nested
// call satisfy `nat_nat_wfr.relation (x2, y2) (x, y)`.
let rec f (x: nat) (y: nat)
: Tot nat (decreases (nat_nat_wfr.decreaser (x, y))) =
if x = 0 then
0
else if y = 0 then (
// This assertion isn't necessary; it's just for illustration
assert (nat_nat_wfr.relation (x - 1, 100) (x, y));
f (x - 1) 100
)
else (
// This assertion isn't necessary; it's just for illustration
assert (nat_nat_wfr.relation (x, y - 1) (x, y));
f x (y - 1)
)
One way `wfr_t` can be useful is that it simplifies debugging when
the SMT solver can't verify termination. You can assert the
relation explicitly (as in the examples above), and if the assertion
doesn't hold you can try to prove it. If you instead use something
like `decreases %[x, y]`, it's harder to debug because you can't
`assert (%[x2, y2] << %[x, y])`.
But where `wfr_t` is most useful is in writing a function that takes
a well-founded relation as input. Here's an illustrative example:
let rec count_steps_to_none
(#a: Type)
(wfr: wfr_t a)
(stepper: (x: a) -> (y: option a{Some? y ==> wfr.relation (Some?.v y) x}))
(start: option a)
: Tot nat (decreases (option_wfr wfr).decreaser start) =
match start with
| None -> 0
| Some x -> 1 + count_steps_to_none wfr stepper (stepper x)
`wfr_t` is also useful when composing a well-founded relation
produced using `acc` (from the FStar.WellFounded library) with one
or more other well-founded relations.
There are a few ways to build a `wfr_t`, described in more detail in
comments throughout this file. Those ways are:
`default_wfr a`
`empty_wfr a`
`acc_to_wfr r f`
`subrelation_to_wfr r wfr`
`inverse_image_to_wfr r f wfr`
`lex_nondep_wfr wfr_a wfr_b`
`lex_dep_wfr wfr_a a_to_wfr_b`
`bool_wfr`
`option_wfr wfr`
*)
module FStar.WellFoundedRelation
noeq type acc_classical (#a: Type u#a) (r: a -> a -> Type0) (x: a) : Type u#a =
| AccClassicalIntro : access_smaller:(y: a{r y x} -> acc_classical r y) -> acc_classical r x
noeq type wfr_t (a: Type u#a) : Type u#(a + 1) =
{
relation: a -> a -> Type0;
decreaser: (x: a -> acc_classical relation x);
proof: (x1: a) -> (x2: a) ->
Lemma (requires relation x1 x2) (ensures decreaser x1 << decreaser x2);
}
let ambient_wfr_lemma (#a: Type u#a) (wfr: wfr_t a) (x1: a) (x2: a)
: Lemma (requires wfr.relation x1 x2)
(ensures wfr.decreaser x1 << wfr.decreaser x2)
[SMTPat (wfr.decreaser x1); SMTPat (wfr.decreaser x2)] =
wfr.proof x1 x2
/// `default_wfr a` is the well-founded relation built into F* for
/// type `a`. For instance, for `nat` it's the less-than relation.
/// For an inductive type it's the sub-term ordering.
///
/// `(default_wfr a).relation` is `default_relation` as defined below.
let default_relation (#a: Type u#a) (x1: a) (x2: a) : Type0 = x1 << x2
val default_wfr (a: Type u#a) : (wfr: wfr_t a{wfr.relation == default_relation})
/// `empty_wfr a` is the empty well-founded relation, which doesn't relate any
/// pair of values.
///
/// `(empty_wfr a).relation` is `empty_relation` as defined below.
let empty_relation (#a: Type u#a) (x1: a) (x2: a) : Type0 = False
val empty_wfr (a: Type u#a) : (wfr: wfr_t a{wfr.relation == empty_relation})
/// `acc_to_wfr r f` is a `wfr_t` built from a relation `r` and a
/// function `f: well-founded r`. Such a function demonstrates that
/// `r` is well-founded using the accessibility type `acc` described
/// in FStar.WellFounded.fst.
///
/// `(acc_to_wfr r f).relation` is `acc_relation r` as defined below. | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.WellFounded.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.WellFoundedRelation.fsti"
} | [
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | r: (_: a -> _: a -> Type0) -> x1: a -> x2: a -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Prims.l_Exists",
"Prims.l_True"
] | [] | false | false | false | true | true | let acc_relation (#a: Type u#a) (r: (a -> a -> Type0)) (x1 x2: a) : Type0 =
| exists (p: r x1 x2). True | false |
FStar.WellFoundedRelation.fsti | FStar.WellFoundedRelation.lex_nondep_relation | val lex_nondep_relation
(#a: Type u#a)
(#b: Type u#b)
(wfr_a: wfr_t a)
(wfr_b: wfr_t b)
(xy1 xy2: (a * b))
: Type0 | val lex_nondep_relation
(#a: Type u#a)
(#b: Type u#b)
(wfr_a: wfr_t a)
(wfr_b: wfr_t b)
(xy1 xy2: (a * b))
: Type0 | let lex_nondep_relation (#a: Type u#a) (#b: Type u#b) (wfr_a: wfr_t a) (wfr_b: wfr_t b)
(xy1: a * b) (xy2: a * b)
: Type0 =
let (x1, y1), (x2, y2) = xy1, xy2 in
wfr_a.relation x1 x2 \/ (x1 == x2 /\ wfr_b.relation y1 y2) | {
"file_name": "ulib/FStar.WellFoundedRelation.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 60,
"end_line": 186,
"start_col": 0,
"start_line": 182
} | (*
Copyright 2022 Jay Lorch and Nikhil Swamy, 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.
*)
(* This library is intended to simplify using well-founded relations
in decreases clauses.
The key data structure is `wfr_t a`, which encapsulates a
well-founded relation on `a`. Specifically, the predicate
`wfr.relation x1 x2` means that `x1` precedes `x2` in the
well-founded relation described by `wfr`.
You can then use this relatedness to show that a function is
decreasing in a certain term. Whenever `wfr.relation x1 x2` holds,
`wfr.decreaser x1 << wfr.decreaser x2` also holds. The library has
an ambient lemma triggered by seeing two instances of
`wfr.decreaser`, so you can use `wfr.decreaser x` in your decreases
clause. For example:
// Define `nat_nat_wfr` to represent the lexicographically-precedes
// relation between two elements of type `nat * nat`. That is,
// `(x1, y1)` is related to `(x2, y2)` if
// `x1 < x2 \/ (x1 == x2 /\ y1 < y2)`.
let nat_nat_wfr = lex_nondep_wfr (default_wfr nat) (default_wfr nat)
// To show that `f` is well-defined, we use the decreases clause
// `nat_nat_wfr.decreaser (x, y)`. We then need to show, on each
// recursive call, that the parameters x2 and y2 to the nested
// call satisfy `nat_nat_wfr.relation (x2, y2) (x, y)`.
let rec f (x: nat) (y: nat)
: Tot nat (decreases (nat_nat_wfr.decreaser (x, y))) =
if x = 0 then
0
else if y = 0 then (
// This assertion isn't necessary; it's just for illustration
assert (nat_nat_wfr.relation (x - 1, 100) (x, y));
f (x - 1) 100
)
else (
// This assertion isn't necessary; it's just for illustration
assert (nat_nat_wfr.relation (x, y - 1) (x, y));
f x (y - 1)
)
One way `wfr_t` can be useful is that it simplifies debugging when
the SMT solver can't verify termination. You can assert the
relation explicitly (as in the examples above), and if the assertion
doesn't hold you can try to prove it. If you instead use something
like `decreases %[x, y]`, it's harder to debug because you can't
`assert (%[x2, y2] << %[x, y])`.
But where `wfr_t` is most useful is in writing a function that takes
a well-founded relation as input. Here's an illustrative example:
let rec count_steps_to_none
(#a: Type)
(wfr: wfr_t a)
(stepper: (x: a) -> (y: option a{Some? y ==> wfr.relation (Some?.v y) x}))
(start: option a)
: Tot nat (decreases (option_wfr wfr).decreaser start) =
match start with
| None -> 0
| Some x -> 1 + count_steps_to_none wfr stepper (stepper x)
`wfr_t` is also useful when composing a well-founded relation
produced using `acc` (from the FStar.WellFounded library) with one
or more other well-founded relations.
There are a few ways to build a `wfr_t`, described in more detail in
comments throughout this file. Those ways are:
`default_wfr a`
`empty_wfr a`
`acc_to_wfr r f`
`subrelation_to_wfr r wfr`
`inverse_image_to_wfr r f wfr`
`lex_nondep_wfr wfr_a wfr_b`
`lex_dep_wfr wfr_a a_to_wfr_b`
`bool_wfr`
`option_wfr wfr`
*)
module FStar.WellFoundedRelation
noeq type acc_classical (#a: Type u#a) (r: a -> a -> Type0) (x: a) : Type u#a =
| AccClassicalIntro : access_smaller:(y: a{r y x} -> acc_classical r y) -> acc_classical r x
noeq type wfr_t (a: Type u#a) : Type u#(a + 1) =
{
relation: a -> a -> Type0;
decreaser: (x: a -> acc_classical relation x);
proof: (x1: a) -> (x2: a) ->
Lemma (requires relation x1 x2) (ensures decreaser x1 << decreaser x2);
}
let ambient_wfr_lemma (#a: Type u#a) (wfr: wfr_t a) (x1: a) (x2: a)
: Lemma (requires wfr.relation x1 x2)
(ensures wfr.decreaser x1 << wfr.decreaser x2)
[SMTPat (wfr.decreaser x1); SMTPat (wfr.decreaser x2)] =
wfr.proof x1 x2
/// `default_wfr a` is the well-founded relation built into F* for
/// type `a`. For instance, for `nat` it's the less-than relation.
/// For an inductive type it's the sub-term ordering.
///
/// `(default_wfr a).relation` is `default_relation` as defined below.
let default_relation (#a: Type u#a) (x1: a) (x2: a) : Type0 = x1 << x2
val default_wfr (a: Type u#a) : (wfr: wfr_t a{wfr.relation == default_relation})
/// `empty_wfr a` is the empty well-founded relation, which doesn't relate any
/// pair of values.
///
/// `(empty_wfr a).relation` is `empty_relation` as defined below.
let empty_relation (#a: Type u#a) (x1: a) (x2: a) : Type0 = False
val empty_wfr (a: Type u#a) : (wfr: wfr_t a{wfr.relation == empty_relation})
/// `acc_to_wfr r f` is a `wfr_t` built from a relation `r` and a
/// function `f: well-founded r`. Such a function demonstrates that
/// `r` is well-founded using the accessibility type `acc` described
/// in FStar.WellFounded.fst.
///
/// `(acc_to_wfr r f).relation` is `acc_relation r` as defined below.
let acc_relation (#a: Type u#a) (r: a -> a -> Type0) (x1: a) (x2: a) : Type0 = exists (p: r x1 x2). True
val acc_to_wfr (#a: Type u#a) (r: a -> a -> Type0) (f: FStar.WellFounded.well_founded r)
: (wfr: wfr_t a{wfr.relation == acc_relation r})
/// `subrelation_to_wfr r wfr` is a `wfr_t` built from a relation `r`
/// that's a subrelation of an existing well-founded relation `wfr`.
/// By "subrelation" we mean that any pair related by `r` is also
/// related by `wfr`.
///
/// `(subrelation_to_wfr r wfr).relation` is the parameter `r`.
val subrelation_to_wfr (#a: Type u#a) (r: a -> a -> Type0)
(wfr: wfr_t a{forall x1 x2. r x1 x2 ==> wfr.relation x1 x2})
: (wfr': wfr_t a{wfr'.relation == r})
/// `inverse_image_to_wfr r f wfr` is a `wfr_t` built from a relation
/// `r: a -> a -> Type0`, a function `f: a -> b`, and an existing
/// well-founded relation `wfr` on `b`. The relation `r` must be an
/// "inverse image" of `wfr` using the mapping function `f`, meaning
/// that `forall x1 x2. r x1 x2 ==> wfr.relation (f x1) (f x2)`.
///
/// `(inverse_image_to_wfr r f wfr).relation` is the parameter `r`.
val inverse_image_to_wfr
(#a: Type u#a)
(#b: Type u#b)
(r: a -> a -> Type0)
(f: a -> b)
(wfr: wfr_t b{forall x1 x2. r x1 x2 ==> wfr.relation (f x1) (f x2)})
: (wfr': wfr_t a{wfr'.relation == r})
/// `lex_nondep_wfr wfr_a wfr_b` is a `wfr_t` describing lexicographic
/// precedence for non-dependent tuples of some type `a * b`. It's
/// built from two well-founded relations: a `wfr_t a` and a `wfr_t
/// b`.
///
/// `(lex_nondep_wfr wfr_a wfr_b).relation` is `lex_nondep_relation
/// wfr_a wfr_b` as defined below. | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.WellFounded.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.WellFoundedRelation.fsti"
} | [
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
wfr_a: FStar.WellFoundedRelation.wfr_t a ->
wfr_b: FStar.WellFoundedRelation.wfr_t b ->
xy1: (a * b) ->
xy2: (a * b)
-> Type0 | Prims.Tot | [
"total"
] | [] | [
"FStar.WellFoundedRelation.wfr_t",
"FStar.Pervasives.Native.tuple2",
"Prims.l_or",
"FStar.WellFoundedRelation.__proj__Mkwfr_t__item__relation",
"Prims.l_and",
"Prims.eq2",
"FStar.Pervasives.Native.Mktuple2"
] | [] | false | false | false | true | true | let lex_nondep_relation
(#a: Type u#a)
(#b: Type u#b)
(wfr_a: wfr_t a)
(wfr_b: wfr_t b)
(xy1 xy2: a * b)
: Type0 =
| let (x1, y1), (x2, y2) = xy1, xy2 in
wfr_a.relation x1 x2 \/ (x1 == x2 /\ wfr_b.relation y1 y2) | false |
FStar.Tactics.MkProjectors.fst | FStar.Tactics.MkProjectors.list_last | val list_last (#a: _) (xs: list a) : Tac a | val list_last (#a: _) (xs: list a) : Tac a | let rec list_last #a (xs : list a) : Tac a =
match xs with
| [] -> fail "list_last: empty"
| [x] -> x
| _::xs -> list_last xs | {
"file_name": "ulib/FStar.Tactics.MkProjectors.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 25,
"end_line": 87,
"start_col": 0,
"start_line": 83
} | module FStar.Tactics.MkProjectors
(* NB: We cannot use typeclasses here, or any module that depends on
them, since they use the tactics defined here. So we must be careful
with our includes. *)
open FStar.List.Tot
open FStar.Reflection.V2
open FStar.Tactics.Effect
open FStar.Stubs.Tactics.V2.Builtins
open FStar.Stubs.Syntax.Syntax
open FStar.Tactics.V2.SyntaxCoercions
open FStar.Tactics.V2.SyntaxHelpers
open FStar.Tactics.V2.Derived
open FStar.Tactics.Util
open FStar.Tactics.NamedView
exception NotFound
let meta_projectors = ()
(* Thunked version of debug *)
let debug (f : unit -> Tac string) : Tac unit =
if debugging () then
print (f ())
[@@plugin]
let mk_one_projector (unf:list string) (np:nat) (i:nat) : Tac unit =
debug (fun () -> dump "ENTRY mk_one_projector"; "");
let _params = repeatn np intro in
let thing : binding = intro () in
let r = t_destruct thing in
match r with
| [(cons, arity)] -> begin
if (i >= arity) then
fail "proj: bad index in mk_one_projector";
let _ = repeatn i intro in
let the_b = intro () in
let _ = repeatn (arity-i-1) intro in
let eq_b : binding = intro () in
rewrite eq_b;
norm [iota; delta_only unf; zeta_full];
(* NB: ^ zeta_full above so we reduce under matches too. Since
we are not unfolding anything but the projectors, which are
not, recursive, this should not bring about any divergence. An
alternative is to use NBE. *)
exact the_b
end
| _ -> fail "proj: more than one case?"
[@@plugin]
let mk_one_method (proj:string) (np:nat) : Tac unit =
debug (fun () -> dump "ENTRY mk_one_method"; "");
let nm = explode_qn proj in
let params = repeatn np (fun () -> let b : binding = intro () in
(binding_to_term b, Q_Implicit)) in
let thing : binding = intro () in
let proj = pack (Tv_FVar (pack_fv nm)) in
exact (mk_app proj (params @ [(binding_to_term thing, Q_Explicit)]))
let subst_map (ss : list (namedv * fv)) (r:term) (t : term) : Tac term =
let subst = List.Tot.map (fun (x, fv) -> NT (Reflection.V2.pack_namedv x) (mk_e_app (Tv_FVar fv) [r])) ss in
subst_term subst t
let binder_mk_implicit (b:binder) : binder =
let q =
match b.qual with
| Q_Explicit -> Q_Implicit
| q -> q (* keep Q_Meta as it is *)
in
{ b with qual = q }
let binder_to_term (b:binder) : Tot term =
pack (Tv_Var (binder_to_namedv b))
let binder_argv (b:binder) : Tot argv =
let q =
match b.qual with
| Q_Meta _ -> Q_Implicit
| q -> q
in
(binder_to_term b, q) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.SyntaxHelpers.fst.checked",
"FStar.Tactics.V2.SyntaxCoercions.fst.checked",
"FStar.Tactics.V2.Derived.fst.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Typeclasses.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Stubs.Tactics.V2.Builtins.fsti.checked",
"FStar.Stubs.Syntax.Syntax.fsti.checked",
"FStar.Reflection.V2.TermEq.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Tactics.MkProjectors.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.NamedView",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.SyntaxHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.SyntaxCoercions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Syntax.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Reflection.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | xs: Prims.list a -> FStar.Tactics.Effect.Tac a | FStar.Tactics.Effect.Tac | [] | [] | [
"Prims.list",
"FStar.Tactics.V2.Derived.fail",
"FStar.Tactics.MkProjectors.list_last"
] | [
"recursion"
] | false | true | false | false | false | let rec list_last #a (xs: list a) : Tac a =
| match xs with
| [] -> fail "list_last: empty"
| [x] -> x
| _ :: xs -> list_last xs | false |
FStar.WellFoundedRelation.fsti | FStar.WellFoundedRelation.bool_relation | val bool_relation (x1 x2: bool) : Type0 | val bool_relation (x1 x2: bool) : Type0 | let bool_relation (x1: bool) (x2: bool) : Type0 = x1 == false /\ x2 == true | {
"file_name": "ulib/FStar.WellFoundedRelation.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 75,
"end_line": 215,
"start_col": 0,
"start_line": 215
} | (*
Copyright 2022 Jay Lorch and Nikhil Swamy, 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.
*)
(* This library is intended to simplify using well-founded relations
in decreases clauses.
The key data structure is `wfr_t a`, which encapsulates a
well-founded relation on `a`. Specifically, the predicate
`wfr.relation x1 x2` means that `x1` precedes `x2` in the
well-founded relation described by `wfr`.
You can then use this relatedness to show that a function is
decreasing in a certain term. Whenever `wfr.relation x1 x2` holds,
`wfr.decreaser x1 << wfr.decreaser x2` also holds. The library has
an ambient lemma triggered by seeing two instances of
`wfr.decreaser`, so you can use `wfr.decreaser x` in your decreases
clause. For example:
// Define `nat_nat_wfr` to represent the lexicographically-precedes
// relation between two elements of type `nat * nat`. That is,
// `(x1, y1)` is related to `(x2, y2)` if
// `x1 < x2 \/ (x1 == x2 /\ y1 < y2)`.
let nat_nat_wfr = lex_nondep_wfr (default_wfr nat) (default_wfr nat)
// To show that `f` is well-defined, we use the decreases clause
// `nat_nat_wfr.decreaser (x, y)`. We then need to show, on each
// recursive call, that the parameters x2 and y2 to the nested
// call satisfy `nat_nat_wfr.relation (x2, y2) (x, y)`.
let rec f (x: nat) (y: nat)
: Tot nat (decreases (nat_nat_wfr.decreaser (x, y))) =
if x = 0 then
0
else if y = 0 then (
// This assertion isn't necessary; it's just for illustration
assert (nat_nat_wfr.relation (x - 1, 100) (x, y));
f (x - 1) 100
)
else (
// This assertion isn't necessary; it's just for illustration
assert (nat_nat_wfr.relation (x, y - 1) (x, y));
f x (y - 1)
)
One way `wfr_t` can be useful is that it simplifies debugging when
the SMT solver can't verify termination. You can assert the
relation explicitly (as in the examples above), and if the assertion
doesn't hold you can try to prove it. If you instead use something
like `decreases %[x, y]`, it's harder to debug because you can't
`assert (%[x2, y2] << %[x, y])`.
But where `wfr_t` is most useful is in writing a function that takes
a well-founded relation as input. Here's an illustrative example:
let rec count_steps_to_none
(#a: Type)
(wfr: wfr_t a)
(stepper: (x: a) -> (y: option a{Some? y ==> wfr.relation (Some?.v y) x}))
(start: option a)
: Tot nat (decreases (option_wfr wfr).decreaser start) =
match start with
| None -> 0
| Some x -> 1 + count_steps_to_none wfr stepper (stepper x)
`wfr_t` is also useful when composing a well-founded relation
produced using `acc` (from the FStar.WellFounded library) with one
or more other well-founded relations.
There are a few ways to build a `wfr_t`, described in more detail in
comments throughout this file. Those ways are:
`default_wfr a`
`empty_wfr a`
`acc_to_wfr r f`
`subrelation_to_wfr r wfr`
`inverse_image_to_wfr r f wfr`
`lex_nondep_wfr wfr_a wfr_b`
`lex_dep_wfr wfr_a a_to_wfr_b`
`bool_wfr`
`option_wfr wfr`
*)
module FStar.WellFoundedRelation
noeq type acc_classical (#a: Type u#a) (r: a -> a -> Type0) (x: a) : Type u#a =
| AccClassicalIntro : access_smaller:(y: a{r y x} -> acc_classical r y) -> acc_classical r x
noeq type wfr_t (a: Type u#a) : Type u#(a + 1) =
{
relation: a -> a -> Type0;
decreaser: (x: a -> acc_classical relation x);
proof: (x1: a) -> (x2: a) ->
Lemma (requires relation x1 x2) (ensures decreaser x1 << decreaser x2);
}
let ambient_wfr_lemma (#a: Type u#a) (wfr: wfr_t a) (x1: a) (x2: a)
: Lemma (requires wfr.relation x1 x2)
(ensures wfr.decreaser x1 << wfr.decreaser x2)
[SMTPat (wfr.decreaser x1); SMTPat (wfr.decreaser x2)] =
wfr.proof x1 x2
/// `default_wfr a` is the well-founded relation built into F* for
/// type `a`. For instance, for `nat` it's the less-than relation.
/// For an inductive type it's the sub-term ordering.
///
/// `(default_wfr a).relation` is `default_relation` as defined below.
let default_relation (#a: Type u#a) (x1: a) (x2: a) : Type0 = x1 << x2
val default_wfr (a: Type u#a) : (wfr: wfr_t a{wfr.relation == default_relation})
/// `empty_wfr a` is the empty well-founded relation, which doesn't relate any
/// pair of values.
///
/// `(empty_wfr a).relation` is `empty_relation` as defined below.
let empty_relation (#a: Type u#a) (x1: a) (x2: a) : Type0 = False
val empty_wfr (a: Type u#a) : (wfr: wfr_t a{wfr.relation == empty_relation})
/// `acc_to_wfr r f` is a `wfr_t` built from a relation `r` and a
/// function `f: well-founded r`. Such a function demonstrates that
/// `r` is well-founded using the accessibility type `acc` described
/// in FStar.WellFounded.fst.
///
/// `(acc_to_wfr r f).relation` is `acc_relation r` as defined below.
let acc_relation (#a: Type u#a) (r: a -> a -> Type0) (x1: a) (x2: a) : Type0 = exists (p: r x1 x2). True
val acc_to_wfr (#a: Type u#a) (r: a -> a -> Type0) (f: FStar.WellFounded.well_founded r)
: (wfr: wfr_t a{wfr.relation == acc_relation r})
/// `subrelation_to_wfr r wfr` is a `wfr_t` built from a relation `r`
/// that's a subrelation of an existing well-founded relation `wfr`.
/// By "subrelation" we mean that any pair related by `r` is also
/// related by `wfr`.
///
/// `(subrelation_to_wfr r wfr).relation` is the parameter `r`.
val subrelation_to_wfr (#a: Type u#a) (r: a -> a -> Type0)
(wfr: wfr_t a{forall x1 x2. r x1 x2 ==> wfr.relation x1 x2})
: (wfr': wfr_t a{wfr'.relation == r})
/// `inverse_image_to_wfr r f wfr` is a `wfr_t` built from a relation
/// `r: a -> a -> Type0`, a function `f: a -> b`, and an existing
/// well-founded relation `wfr` on `b`. The relation `r` must be an
/// "inverse image" of `wfr` using the mapping function `f`, meaning
/// that `forall x1 x2. r x1 x2 ==> wfr.relation (f x1) (f x2)`.
///
/// `(inverse_image_to_wfr r f wfr).relation` is the parameter `r`.
val inverse_image_to_wfr
(#a: Type u#a)
(#b: Type u#b)
(r: a -> a -> Type0)
(f: a -> b)
(wfr: wfr_t b{forall x1 x2. r x1 x2 ==> wfr.relation (f x1) (f x2)})
: (wfr': wfr_t a{wfr'.relation == r})
/// `lex_nondep_wfr wfr_a wfr_b` is a `wfr_t` describing lexicographic
/// precedence for non-dependent tuples of some type `a * b`. It's
/// built from two well-founded relations: a `wfr_t a` and a `wfr_t
/// b`.
///
/// `(lex_nondep_wfr wfr_a wfr_b).relation` is `lex_nondep_relation
/// wfr_a wfr_b` as defined below.
let lex_nondep_relation (#a: Type u#a) (#b: Type u#b) (wfr_a: wfr_t a) (wfr_b: wfr_t b)
(xy1: a * b) (xy2: a * b)
: Type0 =
let (x1, y1), (x2, y2) = xy1, xy2 in
wfr_a.relation x1 x2 \/ (x1 == x2 /\ wfr_b.relation y1 y2)
val lex_nondep_wfr (#a: Type u#a) (#b: Type u#b) (wfr_a: wfr_t a) (wfr_b: wfr_t b)
: wfr: wfr_t (a * b){wfr.relation == lex_nondep_relation wfr_a wfr_b}
/// `lex_dep_wfr wfr_a a_to_wfr_b` is a `wfr_t` describing
/// lexicographic precedence for dependent tuples of type `(x: a & b
/// x)`. It's built from a well-founded relation of type `wfr_t a`
/// and a function `a_to_wfr_b` that maps each `x: a` to a `wfr_t (b
/// x)`.
///
/// `(lex_dep_wfr wfr_a a_to_wfr_b).relation` is `lex_dep_relation
/// wfr_a a_to_wfr_b` as defined below.
let lex_dep_relation (#a: Type u#a) (#b: a -> Type u#b) (wfr_a: wfr_t a)
(a_to_wfr_b: (x: a -> wfr_t (b x))) (xy1: (x: a & b x)) (xy2: (x: a & b x))
: Type0 =
let (| x1, y1 |), (| x2, y2 |) = xy1, xy2 in
wfr_a.relation x1 x2 \/ (x1 == x2 /\ (a_to_wfr_b x1).relation y1 y2)
val lex_dep_wfr (#a: Type u#a) (#b: a -> Type u#b) (wfr_a: wfr_t a)
(a_to_wfr_b: (x: a -> wfr_t (b x)))
: wfr: wfr_t (x: a & b x){wfr.relation == lex_dep_relation wfr_a a_to_wfr_b}
/// `bool_wfr` is the well-founded relation on booleans that has false
/// preceding true.
///
/// `bool_wfr.relation` is `bool_relation`, as defined below. | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.WellFounded.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.WellFoundedRelation.fsti"
} | [
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x1: Prims.bool -> x2: Prims.bool -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Prims.bool",
"Prims.l_and",
"Prims.eq2"
] | [] | false | false | false | true | true | let bool_relation (x1 x2: bool) : Type0 =
| x1 == false /\ x2 == true | false |
Vale.Poly1305.Bitvectors.fst | Vale.Poly1305.Bitvectors.lemma_bytes_shift_power2 | val lemma_bytes_shift_power2: y:uint_t 64 ->
Lemma (requires (y < 8))
(ensures (shift_left #64 y 3 < 64 /\
y * 8 == shift_left #64 y 3 /\
pow2 (shift_left #64 y 3) == shift_left #64 1 (shift_left #64 y 3))) | val lemma_bytes_shift_power2: y:uint_t 64 ->
Lemma (requires (y < 8))
(ensures (shift_left #64 y 3 < 64 /\
y * 8 == shift_left #64 y 3 /\
pow2 (shift_left #64 y 3) == shift_left #64 1 (shift_left #64 y 3))) | let lemma_bytes_shift_power2 y =
(match y with
| 0 ->
lemma_bytes_shift_constants0 ()
| 1 ->
lemma_bytes_shift_constants1 ()
| 2 ->
lemma_bytes_shift_constants2 ()
| 3 ->
lemma_bytes_shift_constants3 ()
| 4 ->
lemma_bytes_shift_constants4 ()
| 5 ->
lemma_bytes_shift_constants5 ()
| 6 ->
lemma_bytes_shift_constants6 ()
| 7 ->
lemma_bytes_shift_constants7 ()
| _ -> ());
lemma_bytes_power2 () | {
"file_name": "vale/code/crypto/poly1305/x64/Vale.Poly1305.Bitvectors.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 23,
"end_line": 274,
"start_col": 0,
"start_line": 255
} | module Vale.Poly1305.Bitvectors
open FStar.BV
open FStar.Tactics
open FStar.Tactics.Derived
open FStar.Tactics.BV
open FStar.Mul
open FStar.UInt
open FStar.Math.Lemmas
open Vale.Lib.Tactics
open Vale.Lib.Bv_s
open Vale.Math.Bits
// tweak options?
#reset-options "--smtencoding.elim_box true"
//NOTE: Using the split tactic seems to slowdown execution by a lot.
let lemma_shr2 x =
assert_by_tactic (shift_right #64 x 2 == udiv #64 x 4) bv_tac
let lemma_shr4 x =
assert_by_tactic (shift_right #64 x 4 == udiv #64 x 16) bv_tac
let lemma_and_mod_n x =
assert_by_tactic (logand #64 x 3 == mod #64 x 4) (bv_tac);
assert_by_tactic (logand #64 x 15 == mod #64 x 16) (bv_tac)
let lemma_clear_lower_2 x =
assert_by_tactic
(logand #64 x 0xfffffffffffffffc == mul_mod #64 (udiv #64 x 4) 4)
bv_tac
let lemma_and_constants x =
assert_by_tactic (logand #64 x 0 == (0 <: uint_t 64)) bv_tac;
assert_by_tactic (logand #64 x 0xffffffffffffffff == x) bv_tac
let lemma_poly_constants x =
// using split in this seems to hang execution.
assert_by_tactic
(logand #64 x 0x0ffffffc0fffffff < (0x1000000000000000 <: uint_t 64))
(fun () -> bv_tac_lt 64);
assert_by_tactic
(logand #64 x 0x0ffffffc0ffffffc < (0x1000000000000000 <: uint_t 64))
(fun () -> bv_tac_lt 64);
assert_by_tactic
(mod #64 (logand #64 x 0x0ffffffc0ffffffc) 4 == (0 <: uint_t 64))
(fun () -> bv_tac ())
let lemma_and_commutes x y =
assert_by_tactic
(logand #64 x y == logand #64 y x)
bv_tac
let lemma_bv128_64_64_and_helper' (x0:bv_t 64) (x1:bv_t 64) (y0:bv_t 64) (y1:bv_t 64) :
Lemma (requires True)
(ensures ((bvor #128 (bvshl #128 (bv_uext #64 #64 (bvand #64 x1 y1)) 64)
(bv_uext #64 #64 (bvand #64 x0 y0))) ==
bvand #128 (bvor #128 (bvshl #128 (bv_uext #64 #64 x1) 64)
(bv_uext #64 #64 x0))
(bvor #128 (bvshl #128 (bv_uext #64 #64 y1) 64)
(bv_uext #64 #64 y0)))) = ()
// Rewrite all equalities and then the goal is trivial for Z3.
// Without rewriting this does not go through.
// I believe the reason is related to a previously reported issue with the way
// Z3 bit-blasts through the Boxing/Unboxing functions. I thought this was fixed
// but it may not be the case. Notice that by rewriting with tactics the solver
// only gets to see one big term without any boxing or unboxing inside it.
let lemma_bv128_64_64_and_helper x x0 x1 y y0 y1 z z0 z1 =
lemma_bv128_64_64_and_helper' x0 x1 y0 y1;
assert_by_tactic (z == bvand #128 x y)
(fun () -> destruct_conj ();
rewrite_eqs_from_context ())
let bv128_64_64 x0 x1 = bvor (bvshl (bv_uext #64 #64 x1) 64) (bv_uext #64 #64 x0)
unfold let uint_to_nat (#n:nat) (x:uint_t n) : r:nat{r = x} =
assert (x < pow2 n);
modulo_lemma x (pow2 n);
x
let uint_ext (#n : nat) (#m : nat{n <= m}) (x : uint_t n) : r:(uint_t m){uint_to_nat r = uint_to_nat x} =
assert_norm(fits x n);
pow2_le_compat m n;
assert_norm(fits x m);
modulo_lemma x (pow2 m);
to_uint_t m x
#reset-options "--smtencoding.elim_box true --smtencoding.l_arith_repr boxwrap --smtencoding.nl_arith_repr boxwrap"
let mul_bvshl (u:uint_t 64) :
Lemma (0x10000000000000000 * u < pow2 128 /\
(int2bv #128 (0x10000000000000000 * u) ==
bvshl (bv_uext #64 #64 (int2bv u)) 64)) =
assert_norm ( 0x10000000000000000 * pow2 63 < pow2 128);
modulo_lemma (0x10000000000000000 * u) (pow2 128);
assert_by_tactic
(int2bv #128 (mul_mod #128 0x10000000000000000 (uint_ext #64 #128 u)) ==
bvmul #128 (int2bv #128 0x10000000000000000) (uint_ext #64 #128 u))
(fun () -> mapply (`trans); arith_to_bv_tac (); trefl ())
#reset-options "--smtencoding.elim_box true"
let plus_bvor (u h:bv_t 128) :
Lemma (bvand u h = bv_zero ==> bvadd u h == bvor u h) = ()
let lemma_bv128_64_64_and x x0 x1 y y0 y1 z z0 z1 =
assert_by_tactic (z == bvand #128 x y)
(fun () -> destruct_conj ();
rewrite_eqs_from_context ();
norm[delta])
#reset-options "--smtencoding.elim_box true --z3refresh --z3rlimit 20 --max_ifuel 1 --max_fuel 1"
let int2bv_uext_64_128 (x1 : nat) :
Lemma (requires (FStar.UInt.size x1 64))
(ensures (bv_uext #64 #64 (int2bv #64 x1) == int2bv #128 x1)) =
assert (64 <= 128);
pow2_le_compat 128 64;
assert (x1 < pow2 128);
modulo_lemma x1 (pow2 128); // x1 % pow2 128 = x1
assert (FStar.UInt.size x1 128);
assert_by_tactic (bv_uext #64 #64 (int2bv #64 x1) == int2bv #128 x1)
(fun () -> dump "..";
norm[delta_only [`%uint_ext; `%FStar.UInt.to_uint_t]];
// grewrite (quote (x1 % pow2 128)) (quote x1);
dump "After norm"; smt ())
#reset-options "--smtencoding.l_arith_repr native --smtencoding.nl_arith_repr wrapped --smtencoding.elim_box true --z3cliopt smt.arith.nl=false --max_fuel 1 --max_ifuel 0"
let lowerUpper128m (l:uint_t 64) (u:uint_t 64) : uint_t 128 =
add_hide #128 (mul_hide #128 (uext #64 #64 u) 0x10000000000000000) (uext #64 #64 l)
let lowerUpper128b (l:bv_t 64) (u:bv_t 64) : bv_t 128 =
b_add #128 (b_mul #128 (b_uext #64 #64 u) 0x10000000000000000) (b_uext #64 #64 l)
//this was so flaky, new options helped.
#reset-options "--smtencoding.elim_box true --z3refresh --z3rlimit 40 --max_ifuel 1 --max_fuel 1"
let lemma_lowerUpper128_andu
(x:uint_t 128) (x0:uint_t 64) (x1:uint_t 64) (y:uint_t 128)
(y0:uint_t 64) (y1:uint_t 64) (z:uint_t 128) (z0:uint_t 64) (z1:uint_t 64) :
Lemma
(requires
z0 == logand #64 x0 y0 /\
z1 == logand #64 x1 y1 /\
x == lowerUpper128u x0 x1 /\
y == lowerUpper128u y0 y1 /\
z == lowerUpper128u z0 z1)
(ensures z == logand #128 x y)
=
let bx0 = b_i2b x0 in
let bx1 = b_i2b x1 in
let by0 = b_i2b y0 in
let by1 = b_i2b y1 in
assert_norm (
lowerUpper128b (b_and bx0 by0) (b_and bx1 by1) ==
b_and (lowerUpper128b bx0 bx1) (lowerUpper128b by0 by1));
lemma_i2b_equal
(lowerUpper128m (logand x0 y0) (logand x1 y1))
(logand (lowerUpper128m x0 x1) (lowerUpper128m y0 y1));
assert_norm (lowerUpper128m x0 x1 == lowerUpper128u x0 x1);
assert_norm (lowerUpper128m y0 y1 == lowerUpper128u y0 y1);
assert_norm (lowerUpper128m z0 z1 == lowerUpper128u z0 z1);
()
#reset-options "--smtencoding.elim_box true --z3cliopt smt.case_split=3"
let lemma_bytes_shift_constants0 x =
assert_by_tactic (shift_left #64 0 3 == (0 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 0 == (0x1 <: uint_t 64)) bv_tac
let lemma_bytes_shift_constants1 x =
assert_by_tactic (shift_left #64 1 3 == (8 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 8 == (0x100 <: uint_t 64)) bv_tac
let lemma_bytes_shift_constants2 x =
assert_by_tactic (shift_left #64 2 3 == (16 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 16 == (0x10000 <: uint_t 64)) bv_tac
let lemma_bytes_shift_constants3 x =
assert_by_tactic (shift_left #64 3 3 == (24 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 24 == (0x1000000 <: uint_t 64)) bv_tac
let lemma_bytes_shift_constants4 x =
assert_by_tactic (shift_left #64 4 3 == (32 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 32 == (0x100000000 <: uint_t 64)) bv_tac
let lemma_bytes_shift_constants5 x =
assert_by_tactic (shift_left #64 5 3 == (40 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 40 == (0x10000000000 <: uint_t 64)) bv_tac
let lemma_bytes_shift_constants6 x =
assert_by_tactic (shift_left #64 6 3 == (48 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 48 == (0x1000000000000 <: uint_t 64)) bv_tac
let lemma_bytes_shift_constants7 x =
assert_by_tactic (shift_left #64 7 3 == (56 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 56 == (0x100000000000000 <: uint_t 64)) bv_tac
let lemma_bytes_and_mod0 x =
assert_by_tactic (logand #64 x (0x1 - 1) == mod #64 x 0x1) bv_tac
let lemma_bytes_and_mod1 x =
assert_by_tactic (logand #64 x (0x100 - 1) == mod #64 x 0x100) bv_tac
let lemma_bytes_and_mod2 x =
assert_by_tactic (logand #64 x (0x10000 - 1) == mod #64 x 0x10000) bv_tac
let lemma_bytes_and_mod3 x =
assert_by_tactic (logand #64 x (0x1000000 - 1) == mod #64 x 0x1000000) bv_tac
let lemma_bytes_and_mod4 x =
assert_by_tactic (logand #64 x (0x100000000 - 1) == mod #64 x 0x100000000) bv_tac
let lemma_bytes_and_mod5 x =
assert_by_tactic (logand #64 x (0x10000000000 - 1) == mod #64 x 0x10000000000) bv_tac
let lemma_bytes_and_mod6 x =
assert_by_tactic (logand #64 x (0x1000000000000 - 1) == mod #64 x 0x1000000000000) bv_tac
let lemma_bytes_and_mod7 x =
assert_by_tactic (logand #64 x (0x100000000000000 - 1) == mod #64 x 0x100000000000000) bv_tac
let lemma_bytes_and_mod x y =
match y with
| 0 ->
lemma_bytes_shift_constants0 ();
lemma_bytes_and_mod0 x
| 1 ->
lemma_bytes_shift_constants1 ();
lemma_bytes_and_mod1 x
| 2 ->
lemma_bytes_shift_constants2 ();
lemma_bytes_and_mod2 x
| 3 ->
lemma_bytes_shift_constants3 ();
lemma_bytes_and_mod3 x
| 4 ->
lemma_bytes_shift_constants4 ();
lemma_bytes_and_mod4 x
| 5 ->
lemma_bytes_shift_constants5 ();
lemma_bytes_and_mod5 x
| 6 ->
lemma_bytes_shift_constants6 ();
lemma_bytes_and_mod6 x
| 7 ->
lemma_bytes_shift_constants7 ();
lemma_bytes_and_mod7 x
| _ -> magic ()
let lemma_bytes_power2 () =
assert_norm (pow2 0 == 0x1);
assert_norm (pow2 8 == 0x100);
assert_norm (pow2 16 == 0x10000);
assert_norm (pow2 24 == 0x1000000);
assert_norm (pow2 32 == 0x100000000);
assert_norm (pow2 40 == 0x10000000000);
assert_norm (pow2 48 == 0x1000000000000);
assert_norm (pow2 56 == 0x100000000000000);
() | {
"checked_file": "/",
"dependencies": [
"Vale.Math.Bits.fsti.checked",
"Vale.Lib.Tactics.fst.checked",
"Vale.Lib.Bv_s.fst.checked",
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Tactics.Derived.fst.checked",
"FStar.Tactics.BV.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.BV.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Poly1305.Bitvectors.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Math.Bits",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Bv_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3",
"smt.case_split=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | y: FStar.UInt.uint_t 64
-> FStar.Pervasives.Lemma (requires y < 8)
(ensures
FStar.UInt.shift_left y 3 < 64 /\ y * 8 == FStar.UInt.shift_left y 3 /\
Prims.pow2 (FStar.UInt.shift_left y 3) ==
FStar.UInt.shift_left 1 (FStar.UInt.shift_left y 3)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.UInt.uint_t",
"Vale.Poly1305.Bitvectors.lemma_bytes_power2",
"Prims.unit",
"Vale.Poly1305.Bitvectors.lemma_bytes_shift_constants0",
"Vale.Poly1305.Bitvectors.lemma_bytes_shift_constants1",
"Vale.Poly1305.Bitvectors.lemma_bytes_shift_constants2",
"Vale.Poly1305.Bitvectors.lemma_bytes_shift_constants3",
"Vale.Poly1305.Bitvectors.lemma_bytes_shift_constants4",
"Vale.Poly1305.Bitvectors.lemma_bytes_shift_constants5",
"Vale.Poly1305.Bitvectors.lemma_bytes_shift_constants6",
"Vale.Poly1305.Bitvectors.lemma_bytes_shift_constants7",
"Prims.int"
] | [] | false | false | true | false | false | let lemma_bytes_shift_power2 y =
| (match y with
| 0 -> lemma_bytes_shift_constants0 ()
| 1 -> lemma_bytes_shift_constants1 ()
| 2 -> lemma_bytes_shift_constants2 ()
| 3 -> lemma_bytes_shift_constants3 ()
| 4 -> lemma_bytes_shift_constants4 ()
| 5 -> lemma_bytes_shift_constants5 ()
| 6 -> lemma_bytes_shift_constants6 ()
| 7 -> lemma_bytes_shift_constants7 ()
| _ -> ());
lemma_bytes_power2 () | false |
Vale.Poly1305.Bitvectors.fst | Vale.Poly1305.Bitvectors.lemma_and_constants | val lemma_and_constants: x:uint_t 64 ->
Lemma (logand #64 x 0 == 0 /\ logand #64 x 0xffffffffffffffff == x)
[SMTPat (logand #64 x 0); SMTPat (logand #64 x 0xffffffffffffffff)] | val lemma_and_constants: x:uint_t 64 ->
Lemma (logand #64 x 0 == 0 /\ logand #64 x 0xffffffffffffffff == x)
[SMTPat (logand #64 x 0); SMTPat (logand #64 x 0xffffffffffffffff)] | let lemma_and_constants x =
assert_by_tactic (logand #64 x 0 == (0 <: uint_t 64)) bv_tac;
assert_by_tactic (logand #64 x 0xffffffffffffffff == x) bv_tac | {
"file_name": "vale/code/crypto/poly1305/x64/Vale.Poly1305.Bitvectors.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 63,
"end_line": 36,
"start_col": 0,
"start_line": 34
} | module Vale.Poly1305.Bitvectors
open FStar.BV
open FStar.Tactics
open FStar.Tactics.Derived
open FStar.Tactics.BV
open FStar.Mul
open FStar.UInt
open FStar.Math.Lemmas
open Vale.Lib.Tactics
open Vale.Lib.Bv_s
open Vale.Math.Bits
// tweak options?
#reset-options "--smtencoding.elim_box true"
//NOTE: Using the split tactic seems to slowdown execution by a lot.
let lemma_shr2 x =
assert_by_tactic (shift_right #64 x 2 == udiv #64 x 4) bv_tac
let lemma_shr4 x =
assert_by_tactic (shift_right #64 x 4 == udiv #64 x 16) bv_tac
let lemma_and_mod_n x =
assert_by_tactic (logand #64 x 3 == mod #64 x 4) (bv_tac);
assert_by_tactic (logand #64 x 15 == mod #64 x 16) (bv_tac)
let lemma_clear_lower_2 x =
assert_by_tactic
(logand #64 x 0xfffffffffffffffc == mul_mod #64 (udiv #64 x 4) 4)
bv_tac | {
"checked_file": "/",
"dependencies": [
"Vale.Math.Bits.fsti.checked",
"Vale.Lib.Tactics.fst.checked",
"Vale.Lib.Bv_s.fst.checked",
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Tactics.Derived.fst.checked",
"FStar.Tactics.BV.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.BV.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Poly1305.Bitvectors.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Math.Bits",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Bv_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: FStar.UInt.uint_t 64
-> FStar.Pervasives.Lemma
(ensures FStar.UInt.logand x 0 == 0 /\ FStar.UInt.logand x 0xffffffffffffffff == x)
[SMTPat (FStar.UInt.logand x 0); SMTPat (FStar.UInt.logand x 0xffffffffffffffff)] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.UInt.uint_t",
"FStar.Tactics.Effect.assert_by_tactic",
"Prims.eq2",
"FStar.UInt.logand",
"FStar.Tactics.BV.bv_tac",
"Prims.unit"
] | [] | true | false | true | false | false | let lemma_and_constants x =
| assert_by_tactic (logand #64 x 0 == (0 <: uint_t 64)) bv_tac;
assert_by_tactic (logand #64 x 0xffffffffffffffff == x) bv_tac | false |
Vale.Poly1305.Bitvectors.fst | Vale.Poly1305.Bitvectors.lemma_clear_lower_2 | val lemma_clear_lower_2: x:uint_t 64 ->
Lemma (logand #64 x 0xfffffffffffffffc == mul_mod #64 (udiv #64 x 4) 4)
[SMTPat (logand #64 x 0xfffffffffffffffc)] | val lemma_clear_lower_2: x:uint_t 64 ->
Lemma (logand #64 x 0xfffffffffffffffc == mul_mod #64 (udiv #64 x 4) 4)
[SMTPat (logand #64 x 0xfffffffffffffffc)] | let lemma_clear_lower_2 x =
assert_by_tactic
(logand #64 x 0xfffffffffffffffc == mul_mod #64 (udiv #64 x 4) 4)
bv_tac | {
"file_name": "vale/code/crypto/poly1305/x64/Vale.Poly1305.Bitvectors.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 8,
"end_line": 31,
"start_col": 0,
"start_line": 28
} | module Vale.Poly1305.Bitvectors
open FStar.BV
open FStar.Tactics
open FStar.Tactics.Derived
open FStar.Tactics.BV
open FStar.Mul
open FStar.UInt
open FStar.Math.Lemmas
open Vale.Lib.Tactics
open Vale.Lib.Bv_s
open Vale.Math.Bits
// tweak options?
#reset-options "--smtencoding.elim_box true"
//NOTE: Using the split tactic seems to slowdown execution by a lot.
let lemma_shr2 x =
assert_by_tactic (shift_right #64 x 2 == udiv #64 x 4) bv_tac
let lemma_shr4 x =
assert_by_tactic (shift_right #64 x 4 == udiv #64 x 16) bv_tac
let lemma_and_mod_n x =
assert_by_tactic (logand #64 x 3 == mod #64 x 4) (bv_tac);
assert_by_tactic (logand #64 x 15 == mod #64 x 16) (bv_tac) | {
"checked_file": "/",
"dependencies": [
"Vale.Math.Bits.fsti.checked",
"Vale.Lib.Tactics.fst.checked",
"Vale.Lib.Bv_s.fst.checked",
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Tactics.Derived.fst.checked",
"FStar.Tactics.BV.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.BV.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Poly1305.Bitvectors.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Math.Bits",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Bv_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: FStar.UInt.uint_t 64
-> FStar.Pervasives.Lemma
(ensures FStar.UInt.logand x 0xfffffffffffffffc == FStar.UInt.mul_mod (FStar.UInt.udiv x 4) 4)
[SMTPat (FStar.UInt.logand x 0xfffffffffffffffc)] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.UInt.uint_t",
"FStar.Tactics.Effect.assert_by_tactic",
"Prims.eq2",
"FStar.UInt.logand",
"FStar.UInt.mul_mod",
"FStar.UInt.udiv",
"FStar.Tactics.BV.bv_tac",
"Prims.unit"
] | [] | true | false | true | false | false | let lemma_clear_lower_2 x =
| assert_by_tactic (logand #64 x 0xfffffffffffffffc == mul_mod #64 (udiv #64 x 4) 4) bv_tac | false |
Vale.Poly1305.Bitvectors.fst | Vale.Poly1305.Bitvectors.lemma_bytes_and_mod0 | val lemma_bytes_and_mod0: x: uint_t 64 ->
Lemma (logand #64 x (0x1 - 1) == mod #64 x 0x1) | val lemma_bytes_and_mod0: x: uint_t 64 ->
Lemma (logand #64 x (0x1 - 1) == mod #64 x 0x1) | let lemma_bytes_and_mod0 x =
assert_by_tactic (logand #64 x (0x1 - 1) == mod #64 x 0x1) bv_tac | {
"file_name": "vale/code/crypto/poly1305/x64/Vale.Poly1305.Bitvectors.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 67,
"end_line": 194,
"start_col": 0,
"start_line": 193
} | module Vale.Poly1305.Bitvectors
open FStar.BV
open FStar.Tactics
open FStar.Tactics.Derived
open FStar.Tactics.BV
open FStar.Mul
open FStar.UInt
open FStar.Math.Lemmas
open Vale.Lib.Tactics
open Vale.Lib.Bv_s
open Vale.Math.Bits
// tweak options?
#reset-options "--smtencoding.elim_box true"
//NOTE: Using the split tactic seems to slowdown execution by a lot.
let lemma_shr2 x =
assert_by_tactic (shift_right #64 x 2 == udiv #64 x 4) bv_tac
let lemma_shr4 x =
assert_by_tactic (shift_right #64 x 4 == udiv #64 x 16) bv_tac
let lemma_and_mod_n x =
assert_by_tactic (logand #64 x 3 == mod #64 x 4) (bv_tac);
assert_by_tactic (logand #64 x 15 == mod #64 x 16) (bv_tac)
let lemma_clear_lower_2 x =
assert_by_tactic
(logand #64 x 0xfffffffffffffffc == mul_mod #64 (udiv #64 x 4) 4)
bv_tac
let lemma_and_constants x =
assert_by_tactic (logand #64 x 0 == (0 <: uint_t 64)) bv_tac;
assert_by_tactic (logand #64 x 0xffffffffffffffff == x) bv_tac
let lemma_poly_constants x =
// using split in this seems to hang execution.
assert_by_tactic
(logand #64 x 0x0ffffffc0fffffff < (0x1000000000000000 <: uint_t 64))
(fun () -> bv_tac_lt 64);
assert_by_tactic
(logand #64 x 0x0ffffffc0ffffffc < (0x1000000000000000 <: uint_t 64))
(fun () -> bv_tac_lt 64);
assert_by_tactic
(mod #64 (logand #64 x 0x0ffffffc0ffffffc) 4 == (0 <: uint_t 64))
(fun () -> bv_tac ())
let lemma_and_commutes x y =
assert_by_tactic
(logand #64 x y == logand #64 y x)
bv_tac
let lemma_bv128_64_64_and_helper' (x0:bv_t 64) (x1:bv_t 64) (y0:bv_t 64) (y1:bv_t 64) :
Lemma (requires True)
(ensures ((bvor #128 (bvshl #128 (bv_uext #64 #64 (bvand #64 x1 y1)) 64)
(bv_uext #64 #64 (bvand #64 x0 y0))) ==
bvand #128 (bvor #128 (bvshl #128 (bv_uext #64 #64 x1) 64)
(bv_uext #64 #64 x0))
(bvor #128 (bvshl #128 (bv_uext #64 #64 y1) 64)
(bv_uext #64 #64 y0)))) = ()
// Rewrite all equalities and then the goal is trivial for Z3.
// Without rewriting this does not go through.
// I believe the reason is related to a previously reported issue with the way
// Z3 bit-blasts through the Boxing/Unboxing functions. I thought this was fixed
// but it may not be the case. Notice that by rewriting with tactics the solver
// only gets to see one big term without any boxing or unboxing inside it.
let lemma_bv128_64_64_and_helper x x0 x1 y y0 y1 z z0 z1 =
lemma_bv128_64_64_and_helper' x0 x1 y0 y1;
assert_by_tactic (z == bvand #128 x y)
(fun () -> destruct_conj ();
rewrite_eqs_from_context ())
let bv128_64_64 x0 x1 = bvor (bvshl (bv_uext #64 #64 x1) 64) (bv_uext #64 #64 x0)
unfold let uint_to_nat (#n:nat) (x:uint_t n) : r:nat{r = x} =
assert (x < pow2 n);
modulo_lemma x (pow2 n);
x
let uint_ext (#n : nat) (#m : nat{n <= m}) (x : uint_t n) : r:(uint_t m){uint_to_nat r = uint_to_nat x} =
assert_norm(fits x n);
pow2_le_compat m n;
assert_norm(fits x m);
modulo_lemma x (pow2 m);
to_uint_t m x
#reset-options "--smtencoding.elim_box true --smtencoding.l_arith_repr boxwrap --smtencoding.nl_arith_repr boxwrap"
let mul_bvshl (u:uint_t 64) :
Lemma (0x10000000000000000 * u < pow2 128 /\
(int2bv #128 (0x10000000000000000 * u) ==
bvshl (bv_uext #64 #64 (int2bv u)) 64)) =
assert_norm ( 0x10000000000000000 * pow2 63 < pow2 128);
modulo_lemma (0x10000000000000000 * u) (pow2 128);
assert_by_tactic
(int2bv #128 (mul_mod #128 0x10000000000000000 (uint_ext #64 #128 u)) ==
bvmul #128 (int2bv #128 0x10000000000000000) (uint_ext #64 #128 u))
(fun () -> mapply (`trans); arith_to_bv_tac (); trefl ())
#reset-options "--smtencoding.elim_box true"
let plus_bvor (u h:bv_t 128) :
Lemma (bvand u h = bv_zero ==> bvadd u h == bvor u h) = ()
let lemma_bv128_64_64_and x x0 x1 y y0 y1 z z0 z1 =
assert_by_tactic (z == bvand #128 x y)
(fun () -> destruct_conj ();
rewrite_eqs_from_context ();
norm[delta])
#reset-options "--smtencoding.elim_box true --z3refresh --z3rlimit 20 --max_ifuel 1 --max_fuel 1"
let int2bv_uext_64_128 (x1 : nat) :
Lemma (requires (FStar.UInt.size x1 64))
(ensures (bv_uext #64 #64 (int2bv #64 x1) == int2bv #128 x1)) =
assert (64 <= 128);
pow2_le_compat 128 64;
assert (x1 < pow2 128);
modulo_lemma x1 (pow2 128); // x1 % pow2 128 = x1
assert (FStar.UInt.size x1 128);
assert_by_tactic (bv_uext #64 #64 (int2bv #64 x1) == int2bv #128 x1)
(fun () -> dump "..";
norm[delta_only [`%uint_ext; `%FStar.UInt.to_uint_t]];
// grewrite (quote (x1 % pow2 128)) (quote x1);
dump "After norm"; smt ())
#reset-options "--smtencoding.l_arith_repr native --smtencoding.nl_arith_repr wrapped --smtencoding.elim_box true --z3cliopt smt.arith.nl=false --max_fuel 1 --max_ifuel 0"
let lowerUpper128m (l:uint_t 64) (u:uint_t 64) : uint_t 128 =
add_hide #128 (mul_hide #128 (uext #64 #64 u) 0x10000000000000000) (uext #64 #64 l)
let lowerUpper128b (l:bv_t 64) (u:bv_t 64) : bv_t 128 =
b_add #128 (b_mul #128 (b_uext #64 #64 u) 0x10000000000000000) (b_uext #64 #64 l)
//this was so flaky, new options helped.
#reset-options "--smtencoding.elim_box true --z3refresh --z3rlimit 40 --max_ifuel 1 --max_fuel 1"
let lemma_lowerUpper128_andu
(x:uint_t 128) (x0:uint_t 64) (x1:uint_t 64) (y:uint_t 128)
(y0:uint_t 64) (y1:uint_t 64) (z:uint_t 128) (z0:uint_t 64) (z1:uint_t 64) :
Lemma
(requires
z0 == logand #64 x0 y0 /\
z1 == logand #64 x1 y1 /\
x == lowerUpper128u x0 x1 /\
y == lowerUpper128u y0 y1 /\
z == lowerUpper128u z0 z1)
(ensures z == logand #128 x y)
=
let bx0 = b_i2b x0 in
let bx1 = b_i2b x1 in
let by0 = b_i2b y0 in
let by1 = b_i2b y1 in
assert_norm (
lowerUpper128b (b_and bx0 by0) (b_and bx1 by1) ==
b_and (lowerUpper128b bx0 bx1) (lowerUpper128b by0 by1));
lemma_i2b_equal
(lowerUpper128m (logand x0 y0) (logand x1 y1))
(logand (lowerUpper128m x0 x1) (lowerUpper128m y0 y1));
assert_norm (lowerUpper128m x0 x1 == lowerUpper128u x0 x1);
assert_norm (lowerUpper128m y0 y1 == lowerUpper128u y0 y1);
assert_norm (lowerUpper128m z0 z1 == lowerUpper128u z0 z1);
()
#reset-options "--smtencoding.elim_box true --z3cliopt smt.case_split=3"
let lemma_bytes_shift_constants0 x =
assert_by_tactic (shift_left #64 0 3 == (0 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 0 == (0x1 <: uint_t 64)) bv_tac
let lemma_bytes_shift_constants1 x =
assert_by_tactic (shift_left #64 1 3 == (8 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 8 == (0x100 <: uint_t 64)) bv_tac
let lemma_bytes_shift_constants2 x =
assert_by_tactic (shift_left #64 2 3 == (16 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 16 == (0x10000 <: uint_t 64)) bv_tac
let lemma_bytes_shift_constants3 x =
assert_by_tactic (shift_left #64 3 3 == (24 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 24 == (0x1000000 <: uint_t 64)) bv_tac
let lemma_bytes_shift_constants4 x =
assert_by_tactic (shift_left #64 4 3 == (32 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 32 == (0x100000000 <: uint_t 64)) bv_tac
let lemma_bytes_shift_constants5 x =
assert_by_tactic (shift_left #64 5 3 == (40 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 40 == (0x10000000000 <: uint_t 64)) bv_tac
let lemma_bytes_shift_constants6 x =
assert_by_tactic (shift_left #64 6 3 == (48 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 48 == (0x1000000000000 <: uint_t 64)) bv_tac
let lemma_bytes_shift_constants7 x =
assert_by_tactic (shift_left #64 7 3 == (56 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 56 == (0x100000000000000 <: uint_t 64)) bv_tac | {
"checked_file": "/",
"dependencies": [
"Vale.Math.Bits.fsti.checked",
"Vale.Lib.Tactics.fst.checked",
"Vale.Lib.Bv_s.fst.checked",
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Tactics.Derived.fst.checked",
"FStar.Tactics.BV.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.BV.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Poly1305.Bitvectors.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Math.Bits",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Bv_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3",
"smt.case_split=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: FStar.UInt.uint_t 64
-> FStar.Pervasives.Lemma (ensures FStar.UInt.logand x (0x1 - 1) == FStar.UInt.mod x 0x1) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.UInt.uint_t",
"FStar.Tactics.Effect.assert_by_tactic",
"Prims.eq2",
"FStar.UInt.logand",
"Prims.op_Subtraction",
"FStar.UInt.mod",
"FStar.Tactics.BV.bv_tac",
"Prims.unit"
] | [] | true | false | true | false | false | let lemma_bytes_and_mod0 x =
| assert_by_tactic (logand #64 x (0x1 - 1) == mod #64 x 0x1) bv_tac | false |
FStar.WellFoundedRelation.fsti | FStar.WellFoundedRelation.lex_dep_relation | val lex_dep_relation
(#a: Type u#a)
(#b: (a -> Type u#b))
(wfr_a: wfr_t a)
(a_to_wfr_b: (x: a -> wfr_t (b x)))
(xy1 xy2: (x: a & b x))
: Type0 | val lex_dep_relation
(#a: Type u#a)
(#b: (a -> Type u#b))
(wfr_a: wfr_t a)
(a_to_wfr_b: (x: a -> wfr_t (b x)))
(xy1 xy2: (x: a & b x))
: Type0 | let lex_dep_relation (#a: Type u#a) (#b: a -> Type u#b) (wfr_a: wfr_t a)
(a_to_wfr_b: (x: a -> wfr_t (b x))) (xy1: (x: a & b x)) (xy2: (x: a & b x))
: Type0 =
let (| x1, y1 |), (| x2, y2 |) = xy1, xy2 in
wfr_a.relation x1 x2 \/ (x1 == x2 /\ (a_to_wfr_b x1).relation y1 y2) | {
"file_name": "ulib/FStar.WellFoundedRelation.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 70,
"end_line": 204,
"start_col": 0,
"start_line": 200
} | (*
Copyright 2022 Jay Lorch and Nikhil Swamy, 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.
*)
(* This library is intended to simplify using well-founded relations
in decreases clauses.
The key data structure is `wfr_t a`, which encapsulates a
well-founded relation on `a`. Specifically, the predicate
`wfr.relation x1 x2` means that `x1` precedes `x2` in the
well-founded relation described by `wfr`.
You can then use this relatedness to show that a function is
decreasing in a certain term. Whenever `wfr.relation x1 x2` holds,
`wfr.decreaser x1 << wfr.decreaser x2` also holds. The library has
an ambient lemma triggered by seeing two instances of
`wfr.decreaser`, so you can use `wfr.decreaser x` in your decreases
clause. For example:
// Define `nat_nat_wfr` to represent the lexicographically-precedes
// relation between two elements of type `nat * nat`. That is,
// `(x1, y1)` is related to `(x2, y2)` if
// `x1 < x2 \/ (x1 == x2 /\ y1 < y2)`.
let nat_nat_wfr = lex_nondep_wfr (default_wfr nat) (default_wfr nat)
// To show that `f` is well-defined, we use the decreases clause
// `nat_nat_wfr.decreaser (x, y)`. We then need to show, on each
// recursive call, that the parameters x2 and y2 to the nested
// call satisfy `nat_nat_wfr.relation (x2, y2) (x, y)`.
let rec f (x: nat) (y: nat)
: Tot nat (decreases (nat_nat_wfr.decreaser (x, y))) =
if x = 0 then
0
else if y = 0 then (
// This assertion isn't necessary; it's just for illustration
assert (nat_nat_wfr.relation (x - 1, 100) (x, y));
f (x - 1) 100
)
else (
// This assertion isn't necessary; it's just for illustration
assert (nat_nat_wfr.relation (x, y - 1) (x, y));
f x (y - 1)
)
One way `wfr_t` can be useful is that it simplifies debugging when
the SMT solver can't verify termination. You can assert the
relation explicitly (as in the examples above), and if the assertion
doesn't hold you can try to prove it. If you instead use something
like `decreases %[x, y]`, it's harder to debug because you can't
`assert (%[x2, y2] << %[x, y])`.
But where `wfr_t` is most useful is in writing a function that takes
a well-founded relation as input. Here's an illustrative example:
let rec count_steps_to_none
(#a: Type)
(wfr: wfr_t a)
(stepper: (x: a) -> (y: option a{Some? y ==> wfr.relation (Some?.v y) x}))
(start: option a)
: Tot nat (decreases (option_wfr wfr).decreaser start) =
match start with
| None -> 0
| Some x -> 1 + count_steps_to_none wfr stepper (stepper x)
`wfr_t` is also useful when composing a well-founded relation
produced using `acc` (from the FStar.WellFounded library) with one
or more other well-founded relations.
There are a few ways to build a `wfr_t`, described in more detail in
comments throughout this file. Those ways are:
`default_wfr a`
`empty_wfr a`
`acc_to_wfr r f`
`subrelation_to_wfr r wfr`
`inverse_image_to_wfr r f wfr`
`lex_nondep_wfr wfr_a wfr_b`
`lex_dep_wfr wfr_a a_to_wfr_b`
`bool_wfr`
`option_wfr wfr`
*)
module FStar.WellFoundedRelation
noeq type acc_classical (#a: Type u#a) (r: a -> a -> Type0) (x: a) : Type u#a =
| AccClassicalIntro : access_smaller:(y: a{r y x} -> acc_classical r y) -> acc_classical r x
noeq type wfr_t (a: Type u#a) : Type u#(a + 1) =
{
relation: a -> a -> Type0;
decreaser: (x: a -> acc_classical relation x);
proof: (x1: a) -> (x2: a) ->
Lemma (requires relation x1 x2) (ensures decreaser x1 << decreaser x2);
}
let ambient_wfr_lemma (#a: Type u#a) (wfr: wfr_t a) (x1: a) (x2: a)
: Lemma (requires wfr.relation x1 x2)
(ensures wfr.decreaser x1 << wfr.decreaser x2)
[SMTPat (wfr.decreaser x1); SMTPat (wfr.decreaser x2)] =
wfr.proof x1 x2
/// `default_wfr a` is the well-founded relation built into F* for
/// type `a`. For instance, for `nat` it's the less-than relation.
/// For an inductive type it's the sub-term ordering.
///
/// `(default_wfr a).relation` is `default_relation` as defined below.
let default_relation (#a: Type u#a) (x1: a) (x2: a) : Type0 = x1 << x2
val default_wfr (a: Type u#a) : (wfr: wfr_t a{wfr.relation == default_relation})
/// `empty_wfr a` is the empty well-founded relation, which doesn't relate any
/// pair of values.
///
/// `(empty_wfr a).relation` is `empty_relation` as defined below.
let empty_relation (#a: Type u#a) (x1: a) (x2: a) : Type0 = False
val empty_wfr (a: Type u#a) : (wfr: wfr_t a{wfr.relation == empty_relation})
/// `acc_to_wfr r f` is a `wfr_t` built from a relation `r` and a
/// function `f: well-founded r`. Such a function demonstrates that
/// `r` is well-founded using the accessibility type `acc` described
/// in FStar.WellFounded.fst.
///
/// `(acc_to_wfr r f).relation` is `acc_relation r` as defined below.
let acc_relation (#a: Type u#a) (r: a -> a -> Type0) (x1: a) (x2: a) : Type0 = exists (p: r x1 x2). True
val acc_to_wfr (#a: Type u#a) (r: a -> a -> Type0) (f: FStar.WellFounded.well_founded r)
: (wfr: wfr_t a{wfr.relation == acc_relation r})
/// `subrelation_to_wfr r wfr` is a `wfr_t` built from a relation `r`
/// that's a subrelation of an existing well-founded relation `wfr`.
/// By "subrelation" we mean that any pair related by `r` is also
/// related by `wfr`.
///
/// `(subrelation_to_wfr r wfr).relation` is the parameter `r`.
val subrelation_to_wfr (#a: Type u#a) (r: a -> a -> Type0)
(wfr: wfr_t a{forall x1 x2. r x1 x2 ==> wfr.relation x1 x2})
: (wfr': wfr_t a{wfr'.relation == r})
/// `inverse_image_to_wfr r f wfr` is a `wfr_t` built from a relation
/// `r: a -> a -> Type0`, a function `f: a -> b`, and an existing
/// well-founded relation `wfr` on `b`. The relation `r` must be an
/// "inverse image" of `wfr` using the mapping function `f`, meaning
/// that `forall x1 x2. r x1 x2 ==> wfr.relation (f x1) (f x2)`.
///
/// `(inverse_image_to_wfr r f wfr).relation` is the parameter `r`.
val inverse_image_to_wfr
(#a: Type u#a)
(#b: Type u#b)
(r: a -> a -> Type0)
(f: a -> b)
(wfr: wfr_t b{forall x1 x2. r x1 x2 ==> wfr.relation (f x1) (f x2)})
: (wfr': wfr_t a{wfr'.relation == r})
/// `lex_nondep_wfr wfr_a wfr_b` is a `wfr_t` describing lexicographic
/// precedence for non-dependent tuples of some type `a * b`. It's
/// built from two well-founded relations: a `wfr_t a` and a `wfr_t
/// b`.
///
/// `(lex_nondep_wfr wfr_a wfr_b).relation` is `lex_nondep_relation
/// wfr_a wfr_b` as defined below.
let lex_nondep_relation (#a: Type u#a) (#b: Type u#b) (wfr_a: wfr_t a) (wfr_b: wfr_t b)
(xy1: a * b) (xy2: a * b)
: Type0 =
let (x1, y1), (x2, y2) = xy1, xy2 in
wfr_a.relation x1 x2 \/ (x1 == x2 /\ wfr_b.relation y1 y2)
val lex_nondep_wfr (#a: Type u#a) (#b: Type u#b) (wfr_a: wfr_t a) (wfr_b: wfr_t b)
: wfr: wfr_t (a * b){wfr.relation == lex_nondep_relation wfr_a wfr_b}
/// `lex_dep_wfr wfr_a a_to_wfr_b` is a `wfr_t` describing
/// lexicographic precedence for dependent tuples of type `(x: a & b
/// x)`. It's built from a well-founded relation of type `wfr_t a`
/// and a function `a_to_wfr_b` that maps each `x: a` to a `wfr_t (b
/// x)`.
///
/// `(lex_dep_wfr wfr_a a_to_wfr_b).relation` is `lex_dep_relation
/// wfr_a a_to_wfr_b` as defined below. | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.WellFounded.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.WellFoundedRelation.fsti"
} | [
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
wfr_a: FStar.WellFoundedRelation.wfr_t a ->
a_to_wfr_b: (x: a -> FStar.WellFoundedRelation.wfr_t (b x)) ->
xy1: Prims.dtuple2 a (fun x -> b x) ->
xy2: Prims.dtuple2 a (fun x -> b x)
-> Type0 | Prims.Tot | [
"total"
] | [] | [
"FStar.WellFoundedRelation.wfr_t",
"Prims.dtuple2",
"Prims.l_or",
"FStar.WellFoundedRelation.__proj__Mkwfr_t__item__relation",
"Prims.l_and",
"Prims.eq2",
"FStar.Pervasives.Native.tuple2",
"FStar.Pervasives.Native.Mktuple2"
] | [] | false | false | false | false | true | let lex_dep_relation
(#a: Type u#a)
(#b: (a -> Type u#b))
(wfr_a: wfr_t a)
(a_to_wfr_b: (x: a -> wfr_t (b x)))
(xy1 xy2: (x: a & b x))
: Type0 =
| let (| x1 , y1 |), (| x2 , y2 |) = xy1, xy2 in
wfr_a.relation x1 x2 \/ (x1 == x2 /\ (a_to_wfr_b x1).relation y1 y2) | false |
FStar.WellFoundedRelation.fsti | FStar.WellFoundedRelation.option_relation | val option_relation (#a: Type u#a) (wfr: wfr_t a) (opt1 opt2: option a) : Type0 | val option_relation (#a: Type u#a) (wfr: wfr_t a) (opt1 opt2: option a) : Type0 | let option_relation (#a: Type u#a) (wfr: wfr_t a) (opt1: option a) (opt2: option a) : Type0 =
Some? opt2 /\ (None? opt1 \/ wfr.relation (Some?.v opt1) (Some?.v opt2)) | {
"file_name": "ulib/FStar.WellFoundedRelation.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 74,
"end_line": 227,
"start_col": 0,
"start_line": 226
} | (*
Copyright 2022 Jay Lorch and Nikhil Swamy, 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.
*)
(* This library is intended to simplify using well-founded relations
in decreases clauses.
The key data structure is `wfr_t a`, which encapsulates a
well-founded relation on `a`. Specifically, the predicate
`wfr.relation x1 x2` means that `x1` precedes `x2` in the
well-founded relation described by `wfr`.
You can then use this relatedness to show that a function is
decreasing in a certain term. Whenever `wfr.relation x1 x2` holds,
`wfr.decreaser x1 << wfr.decreaser x2` also holds. The library has
an ambient lemma triggered by seeing two instances of
`wfr.decreaser`, so you can use `wfr.decreaser x` in your decreases
clause. For example:
// Define `nat_nat_wfr` to represent the lexicographically-precedes
// relation between two elements of type `nat * nat`. That is,
// `(x1, y1)` is related to `(x2, y2)` if
// `x1 < x2 \/ (x1 == x2 /\ y1 < y2)`.
let nat_nat_wfr = lex_nondep_wfr (default_wfr nat) (default_wfr nat)
// To show that `f` is well-defined, we use the decreases clause
// `nat_nat_wfr.decreaser (x, y)`. We then need to show, on each
// recursive call, that the parameters x2 and y2 to the nested
// call satisfy `nat_nat_wfr.relation (x2, y2) (x, y)`.
let rec f (x: nat) (y: nat)
: Tot nat (decreases (nat_nat_wfr.decreaser (x, y))) =
if x = 0 then
0
else if y = 0 then (
// This assertion isn't necessary; it's just for illustration
assert (nat_nat_wfr.relation (x - 1, 100) (x, y));
f (x - 1) 100
)
else (
// This assertion isn't necessary; it's just for illustration
assert (nat_nat_wfr.relation (x, y - 1) (x, y));
f x (y - 1)
)
One way `wfr_t` can be useful is that it simplifies debugging when
the SMT solver can't verify termination. You can assert the
relation explicitly (as in the examples above), and if the assertion
doesn't hold you can try to prove it. If you instead use something
like `decreases %[x, y]`, it's harder to debug because you can't
`assert (%[x2, y2] << %[x, y])`.
But where `wfr_t` is most useful is in writing a function that takes
a well-founded relation as input. Here's an illustrative example:
let rec count_steps_to_none
(#a: Type)
(wfr: wfr_t a)
(stepper: (x: a) -> (y: option a{Some? y ==> wfr.relation (Some?.v y) x}))
(start: option a)
: Tot nat (decreases (option_wfr wfr).decreaser start) =
match start with
| None -> 0
| Some x -> 1 + count_steps_to_none wfr stepper (stepper x)
`wfr_t` is also useful when composing a well-founded relation
produced using `acc` (from the FStar.WellFounded library) with one
or more other well-founded relations.
There are a few ways to build a `wfr_t`, described in more detail in
comments throughout this file. Those ways are:
`default_wfr a`
`empty_wfr a`
`acc_to_wfr r f`
`subrelation_to_wfr r wfr`
`inverse_image_to_wfr r f wfr`
`lex_nondep_wfr wfr_a wfr_b`
`lex_dep_wfr wfr_a a_to_wfr_b`
`bool_wfr`
`option_wfr wfr`
*)
module FStar.WellFoundedRelation
noeq type acc_classical (#a: Type u#a) (r: a -> a -> Type0) (x: a) : Type u#a =
| AccClassicalIntro : access_smaller:(y: a{r y x} -> acc_classical r y) -> acc_classical r x
noeq type wfr_t (a: Type u#a) : Type u#(a + 1) =
{
relation: a -> a -> Type0;
decreaser: (x: a -> acc_classical relation x);
proof: (x1: a) -> (x2: a) ->
Lemma (requires relation x1 x2) (ensures decreaser x1 << decreaser x2);
}
let ambient_wfr_lemma (#a: Type u#a) (wfr: wfr_t a) (x1: a) (x2: a)
: Lemma (requires wfr.relation x1 x2)
(ensures wfr.decreaser x1 << wfr.decreaser x2)
[SMTPat (wfr.decreaser x1); SMTPat (wfr.decreaser x2)] =
wfr.proof x1 x2
/// `default_wfr a` is the well-founded relation built into F* for
/// type `a`. For instance, for `nat` it's the less-than relation.
/// For an inductive type it's the sub-term ordering.
///
/// `(default_wfr a).relation` is `default_relation` as defined below.
let default_relation (#a: Type u#a) (x1: a) (x2: a) : Type0 = x1 << x2
val default_wfr (a: Type u#a) : (wfr: wfr_t a{wfr.relation == default_relation})
/// `empty_wfr a` is the empty well-founded relation, which doesn't relate any
/// pair of values.
///
/// `(empty_wfr a).relation` is `empty_relation` as defined below.
let empty_relation (#a: Type u#a) (x1: a) (x2: a) : Type0 = False
val empty_wfr (a: Type u#a) : (wfr: wfr_t a{wfr.relation == empty_relation})
/// `acc_to_wfr r f` is a `wfr_t` built from a relation `r` and a
/// function `f: well-founded r`. Such a function demonstrates that
/// `r` is well-founded using the accessibility type `acc` described
/// in FStar.WellFounded.fst.
///
/// `(acc_to_wfr r f).relation` is `acc_relation r` as defined below.
let acc_relation (#a: Type u#a) (r: a -> a -> Type0) (x1: a) (x2: a) : Type0 = exists (p: r x1 x2). True
val acc_to_wfr (#a: Type u#a) (r: a -> a -> Type0) (f: FStar.WellFounded.well_founded r)
: (wfr: wfr_t a{wfr.relation == acc_relation r})
/// `subrelation_to_wfr r wfr` is a `wfr_t` built from a relation `r`
/// that's a subrelation of an existing well-founded relation `wfr`.
/// By "subrelation" we mean that any pair related by `r` is also
/// related by `wfr`.
///
/// `(subrelation_to_wfr r wfr).relation` is the parameter `r`.
val subrelation_to_wfr (#a: Type u#a) (r: a -> a -> Type0)
(wfr: wfr_t a{forall x1 x2. r x1 x2 ==> wfr.relation x1 x2})
: (wfr': wfr_t a{wfr'.relation == r})
/// `inverse_image_to_wfr r f wfr` is a `wfr_t` built from a relation
/// `r: a -> a -> Type0`, a function `f: a -> b`, and an existing
/// well-founded relation `wfr` on `b`. The relation `r` must be an
/// "inverse image" of `wfr` using the mapping function `f`, meaning
/// that `forall x1 x2. r x1 x2 ==> wfr.relation (f x1) (f x2)`.
///
/// `(inverse_image_to_wfr r f wfr).relation` is the parameter `r`.
val inverse_image_to_wfr
(#a: Type u#a)
(#b: Type u#b)
(r: a -> a -> Type0)
(f: a -> b)
(wfr: wfr_t b{forall x1 x2. r x1 x2 ==> wfr.relation (f x1) (f x2)})
: (wfr': wfr_t a{wfr'.relation == r})
/// `lex_nondep_wfr wfr_a wfr_b` is a `wfr_t` describing lexicographic
/// precedence for non-dependent tuples of some type `a * b`. It's
/// built from two well-founded relations: a `wfr_t a` and a `wfr_t
/// b`.
///
/// `(lex_nondep_wfr wfr_a wfr_b).relation` is `lex_nondep_relation
/// wfr_a wfr_b` as defined below.
let lex_nondep_relation (#a: Type u#a) (#b: Type u#b) (wfr_a: wfr_t a) (wfr_b: wfr_t b)
(xy1: a * b) (xy2: a * b)
: Type0 =
let (x1, y1), (x2, y2) = xy1, xy2 in
wfr_a.relation x1 x2 \/ (x1 == x2 /\ wfr_b.relation y1 y2)
val lex_nondep_wfr (#a: Type u#a) (#b: Type u#b) (wfr_a: wfr_t a) (wfr_b: wfr_t b)
: wfr: wfr_t (a * b){wfr.relation == lex_nondep_relation wfr_a wfr_b}
/// `lex_dep_wfr wfr_a a_to_wfr_b` is a `wfr_t` describing
/// lexicographic precedence for dependent tuples of type `(x: a & b
/// x)`. It's built from a well-founded relation of type `wfr_t a`
/// and a function `a_to_wfr_b` that maps each `x: a` to a `wfr_t (b
/// x)`.
///
/// `(lex_dep_wfr wfr_a a_to_wfr_b).relation` is `lex_dep_relation
/// wfr_a a_to_wfr_b` as defined below.
let lex_dep_relation (#a: Type u#a) (#b: a -> Type u#b) (wfr_a: wfr_t a)
(a_to_wfr_b: (x: a -> wfr_t (b x))) (xy1: (x: a & b x)) (xy2: (x: a & b x))
: Type0 =
let (| x1, y1 |), (| x2, y2 |) = xy1, xy2 in
wfr_a.relation x1 x2 \/ (x1 == x2 /\ (a_to_wfr_b x1).relation y1 y2)
val lex_dep_wfr (#a: Type u#a) (#b: a -> Type u#b) (wfr_a: wfr_t a)
(a_to_wfr_b: (x: a -> wfr_t (b x)))
: wfr: wfr_t (x: a & b x){wfr.relation == lex_dep_relation wfr_a a_to_wfr_b}
/// `bool_wfr` is the well-founded relation on booleans that has false
/// preceding true.
///
/// `bool_wfr.relation` is `bool_relation`, as defined below.
let bool_relation (x1: bool) (x2: bool) : Type0 = x1 == false /\ x2 == true
val bool_wfr: (wfr: wfr_t bool{wfr.relation == bool_relation})
/// `option_wfr wfr` is a `wfr_t` describing precedence for an `option
/// a`. It's built from a well-founded relation `wfr` on `a`. It has
/// `None` precede any `Some x`, and has `Some x1` precede `Some x2`
/// if `x1` precedes `x2` according to `wfr`.
///
/// `(option_wfr wfr).relation` is `option_relation wfr` as defined below. | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.WellFounded.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.WellFoundedRelation.fsti"
} | [
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
wfr: FStar.WellFoundedRelation.wfr_t a ->
opt1: FStar.Pervasives.Native.option a ->
opt2: FStar.Pervasives.Native.option a
-> Type0 | Prims.Tot | [
"total"
] | [] | [
"FStar.WellFoundedRelation.wfr_t",
"FStar.Pervasives.Native.option",
"Prims.l_and",
"Prims.b2t",
"FStar.Pervasives.Native.uu___is_Some",
"Prims.l_or",
"FStar.Pervasives.Native.uu___is_None",
"FStar.WellFoundedRelation.__proj__Mkwfr_t__item__relation",
"FStar.Pervasives.Native.__proj__Some__item__v"
] | [] | false | false | false | true | true | let option_relation (#a: Type u#a) (wfr: wfr_t a) (opt1 opt2: option a) : Type0 =
| Some? opt2 /\ (None? opt1 \/ wfr.relation (Some?.v opt1) (Some?.v opt2)) | false |
FStar.Tactics.MkProjectors.fst | FStar.Tactics.MkProjectors.mk_projs | val mk_projs (is_class:bool) (tyname:string) : Tac (list sigelt) | val mk_projs (is_class:bool) (tyname:string) : Tac (list sigelt) | let mk_projs (is_class:bool) (tyname:string) : Tac decls =
print ("!! mk_projs tactic called on: " ^ tyname);
let tyqn = explode_qn tyname in
match lookup_typ (top_env ()) tyqn with
| None ->
raise NotFound
| Some se ->
match inspect_sigelt se with
| Sg_Inductive {nm; univs; params; typ; ctors} ->
if (length ctors <> 1) then
fail "Expected an inductive with one constructor";
let indices = fst (collect_arr_bs typ) in
if Cons? indices then
fail "Inductive indices nonempty?";
let [(ctorname, ctor_t)] = ctors in
(* dump ("ityp = " ^ term_to_string typ); *)
(* dump ("ctor_t = " ^ term_to_string ctor_t); *)
let (fields, _) = collect_arr_bs ctor_t in
let unfold_names_tm = `(Nil #string) in
let (decls, _, _, _) =
fold_left (fun (decls, smap, unfold_names_tm, idx) (field : binder) ->
let (ds, fv) = mk_proj_decl is_class tyqn ctorname univs params idx field unfold_names_tm smap in
(decls @ ds,
(binder_to_namedv field, fv)::smap,
(`(Cons #string (`#(embed_string (implode_qn (inspect_fv fv)))) (`#unfold_names_tm))),
idx+1))
([], [], unfold_names_tm, 0)
fields
in
decls
| _ ->
fail "not an inductive" | {
"file_name": "ulib/FStar.Tactics.MkProjectors.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 29,
"end_line": 224,
"start_col": 0,
"start_line": 193
} | module FStar.Tactics.MkProjectors
(* NB: We cannot use typeclasses here, or any module that depends on
them, since they use the tactics defined here. So we must be careful
with our includes. *)
open FStar.List.Tot
open FStar.Reflection.V2
open FStar.Tactics.Effect
open FStar.Stubs.Tactics.V2.Builtins
open FStar.Stubs.Syntax.Syntax
open FStar.Tactics.V2.SyntaxCoercions
open FStar.Tactics.V2.SyntaxHelpers
open FStar.Tactics.V2.Derived
open FStar.Tactics.Util
open FStar.Tactics.NamedView
exception NotFound
let meta_projectors = ()
(* Thunked version of debug *)
let debug (f : unit -> Tac string) : Tac unit =
if debugging () then
print (f ())
[@@plugin]
let mk_one_projector (unf:list string) (np:nat) (i:nat) : Tac unit =
debug (fun () -> dump "ENTRY mk_one_projector"; "");
let _params = repeatn np intro in
let thing : binding = intro () in
let r = t_destruct thing in
match r with
| [(cons, arity)] -> begin
if (i >= arity) then
fail "proj: bad index in mk_one_projector";
let _ = repeatn i intro in
let the_b = intro () in
let _ = repeatn (arity-i-1) intro in
let eq_b : binding = intro () in
rewrite eq_b;
norm [iota; delta_only unf; zeta_full];
(* NB: ^ zeta_full above so we reduce under matches too. Since
we are not unfolding anything but the projectors, which are
not, recursive, this should not bring about any divergence. An
alternative is to use NBE. *)
exact the_b
end
| _ -> fail "proj: more than one case?"
[@@plugin]
let mk_one_method (proj:string) (np:nat) : Tac unit =
debug (fun () -> dump "ENTRY mk_one_method"; "");
let nm = explode_qn proj in
let params = repeatn np (fun () -> let b : binding = intro () in
(binding_to_term b, Q_Implicit)) in
let thing : binding = intro () in
let proj = pack (Tv_FVar (pack_fv nm)) in
exact (mk_app proj (params @ [(binding_to_term thing, Q_Explicit)]))
let subst_map (ss : list (namedv * fv)) (r:term) (t : term) : Tac term =
let subst = List.Tot.map (fun (x, fv) -> NT (Reflection.V2.pack_namedv x) (mk_e_app (Tv_FVar fv) [r])) ss in
subst_term subst t
let binder_mk_implicit (b:binder) : binder =
let q =
match b.qual with
| Q_Explicit -> Q_Implicit
| q -> q (* keep Q_Meta as it is *)
in
{ b with qual = q }
let binder_to_term (b:binder) : Tot term =
pack (Tv_Var (binder_to_namedv b))
let binder_argv (b:binder) : Tot argv =
let q =
match b.qual with
| Q_Meta _ -> Q_Implicit
| q -> q
in
(binder_to_term b, q)
let rec list_last #a (xs : list a) : Tac a =
match xs with
| [] -> fail "list_last: empty"
| [x] -> x
| _::xs -> list_last xs
let embed_int (i:int) : term =
let open FStar.Reflection.V2 in
pack_ln (Tv_Const (C_Int i))
let embed_string (s:string) : term =
let open FStar.Reflection.V2 in
pack_ln (Tv_Const (C_String s))
let mk_proj_decl (is_method:bool)
(tyqn:name) ctorname
(univs : list univ_name)
(params : list binder)
(idx:nat)
(field : binder)
(unfold_names_tm : term)
(smap : list (namedv & fv))
: Tac (list sigelt & fv)
=
debug (fun () -> "Processing field " ^ unseal field.ppname);
debug (fun () -> "Field typ = " ^ term_to_string field.sort);
let np = length params in
let tyfv = pack_fv tyqn in
let nm : name = cur_module () @ ["__proj__" ^ list_last ctorname ^ "__item__" ^ unseal field.ppname] in
let fv = pack_fv nm in
let rty : term =
let hd = pack (Tv_UInst tyfv (List.Tot.map (fun un -> pack_universe (Uv_Name un)) univs)) in
mk_app hd (List.Tot.map binder_argv params)
in
let rb : binder = fresh_binder rty in
let projty = mk_tot_arr (List.Tot.map binder_mk_implicit params
@ [rb])
(subst_map smap (binder_to_term rb) field.sort)
in
debug (fun () -> "Proj typ = " ^ term_to_string projty);
let se_proj = pack_sigelt <|
Sg_Let {
isrec = false;
lbs = [{
lb_fv = fv;
lb_us = univs;
lb_typ = projty;
lb_def =
(* NB: the definition of the projector is again a tactic
invocation, so this whole thing has two phases. *)
(`(_ by (mk_one_projector
(`#unfold_names_tm)
(`#(embed_int np))
(`#(embed_int idx)))))
}]}
in
let maybe_se_method : list sigelt =
if not is_method then [] else
if List.existsb (Reflection.V2.TermEq.term_eq (`Typeclasses.no_method)) field.attrs then [] else
let meth_fv = pack_fv (cur_module () @ [unseal field.ppname]) in
let rb = { rb with qual = Q_Meta (`Typeclasses.tcresolve) } in
let projty = mk_tot_arr (List.Tot.map binder_mk_implicit params
@ [rb])
(subst_map smap (binder_to_term rb) field.sort)
in
(* The method is just defined based on the projector. *)
let lb_def =
(`(_ by (mk_one_method
(`#(embed_string (implode_qn nm)))
(`#(embed_int np)))))
(* NB: if we wanted a 'direct' definition of the method,
using a match instead of calling the projector, the following
will do. The same mk_one_projector tactic should handle it
well.
(`(_ by (mk_one_projector
(`#unfold_names_tm)
(`#(embed_int np))
(`#(embed_int idx)))))
*)
in
(* dump ("returning se with name " ^ unseal field.ppname); *)
(* dump ("def = " ^ term_to_string lb_def); *)
[pack_sigelt <| Sg_Let {
isrec = false;
lbs = [{
lb_fv = meth_fv;
lb_us = univs;
lb_typ = projty;
lb_def = lb_def;
}]}]
in
(* Propagate binder attributes, i.e. attributes in the field
decl, to the method itself. *)
let se_proj = set_sigelt_attrs (field.attrs @ sigelt_attrs se_proj) se_proj in
(* Do we need to set the sigelt's Projector qual? If so,
here is how to do it, but F* currently rejects tactics
trying to generate "internal" qualifiers like Projector. However,
it does not seem to make a difference. *)
(* In fact, it seems to trip the encoding as soon as a field
has more binders, since the encoding has some primitive treatment
for projectors/discriminators. *)
//let se_proj = set_sigelt_quals (
// Projector (ctorname, pack_ident (unseal field.ppname, range_0)) ::
// sigelt_quals se_proj) se_proj
//in
(se_proj :: maybe_se_method , fv) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.SyntaxHelpers.fst.checked",
"FStar.Tactics.V2.SyntaxCoercions.fst.checked",
"FStar.Tactics.V2.Derived.fst.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.Typeclasses.fsti.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Stubs.Tactics.V2.Builtins.fsti.checked",
"FStar.Stubs.Syntax.Syntax.fsti.checked",
"FStar.Reflection.V2.TermEq.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Tactics.MkProjectors.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.NamedView",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.SyntaxHelpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.SyntaxCoercions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Syntax.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Reflection.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | is_class: Prims.bool -> tyname: Prims.string
-> FStar.Tactics.Effect.Tac (Prims.list FStar.Stubs.Reflection.Types.sigelt) | FStar.Tactics.Effect.Tac | [] | [] | [
"Prims.bool",
"Prims.string",
"FStar.Tactics.Effect.raise",
"FStar.Stubs.Reflection.Types.decls",
"FStar.Tactics.MkProjectors.NotFound",
"FStar.Stubs.Reflection.Types.sigelt",
"FStar.Stubs.Reflection.Types.name",
"Prims.list",
"FStar.Tactics.NamedView.univ_name",
"FStar.Tactics.NamedView.binders",
"FStar.Stubs.Reflection.Types.typ",
"FStar.Stubs.Reflection.V2.Data.ctor",
"FStar.Tactics.NamedView.binder",
"FStar.Tactics.NamedView.comp",
"FStar.Pervasives.Native.tuple2",
"FStar.Tactics.NamedView.namedv",
"FStar.Stubs.Reflection.Types.fv",
"FStar.Stubs.Reflection.Types.term",
"Prims.int",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"FStar.Pervasives.Native.tuple4",
"FStar.Tactics.Util.fold_left",
"FStar.Pervasives.Native.Mktuple4",
"FStar.List.Tot.Base.op_At",
"Prims.Cons",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Tactics.V2.SyntaxCoercions.binder_to_namedv",
"FStar.Tactics.MkProjectors.embed_string",
"FStar.Stubs.Reflection.V2.Builtins.implode_qn",
"FStar.Stubs.Reflection.V2.Builtins.inspect_fv",
"Prims.op_Addition",
"FStar.Tactics.MkProjectors.mk_proj_decl",
"Prims.Nil",
"FStar.Tactics.V2.SyntaxHelpers.collect_arr_bs",
"Prims.unit",
"Prims.uu___is_Cons",
"FStar.Tactics.V2.Derived.fail",
"FStar.Pervasives.Native.fst",
"Prims.op_disEquality",
"FStar.List.Tot.Base.length",
"FStar.Tactics.NamedView.named_sigelt_view",
"FStar.Tactics.NamedView.inspect_sigelt",
"FStar.Pervasives.Native.option",
"FStar.Stubs.Reflection.V2.Builtins.lookup_typ",
"FStar.Stubs.Reflection.Types.env",
"FStar.Stubs.Tactics.V2.Builtins.top_env",
"FStar.Stubs.Reflection.V2.Builtins.explode_qn",
"FStar.Stubs.Tactics.V2.Builtins.print",
"Prims.op_Hat"
] | [] | false | true | false | false | false | let mk_projs (is_class: bool) (tyname: string) : Tac decls =
| print ("!! mk_projs tactic called on: " ^ tyname);
let tyqn = explode_qn tyname in
match lookup_typ (top_env ()) tyqn with
| None -> raise NotFound
| Some se ->
match inspect_sigelt se with
| Sg_Inductive { nm = nm ; univs = univs ; params = params ; typ = typ ; ctors = ctors } ->
if (length ctors <> 1) then fail "Expected an inductive with one constructor";
let indices = fst (collect_arr_bs typ) in
if Cons? indices then fail "Inductive indices nonempty?";
let [ctorname, ctor_t] = ctors in
let fields, _ = collect_arr_bs ctor_t in
let unfold_names_tm = `(Nil #string) in
let decls, _, _, _ =
fold_left (fun (decls, smap, unfold_names_tm, idx) (field: binder) ->
let ds, fv =
mk_proj_decl is_class tyqn ctorname univs params idx field unfold_names_tm smap
in
(decls @ ds,
(binder_to_namedv field, fv) :: smap,
(`(Cons #string (`#(embed_string (implode_qn (inspect_fv fv)))) (`#unfold_names_tm))),
idx + 1))
([], [], unfold_names_tm, 0)
fields
in
decls
| _ -> fail "not an inductive" | false |
Vale.Poly1305.Bitvectors.fst | Vale.Poly1305.Bitvectors.lemma_bytes_and_mod2 | val lemma_bytes_and_mod2: x: uint_t 64 ->
Lemma (logand #64 x (0x10000 - 1) == mod #64 x 0x10000) | val lemma_bytes_and_mod2: x: uint_t 64 ->
Lemma (logand #64 x (0x10000 - 1) == mod #64 x 0x10000) | let lemma_bytes_and_mod2 x =
assert_by_tactic (logand #64 x (0x10000 - 1) == mod #64 x 0x10000) bv_tac | {
"file_name": "vale/code/crypto/poly1305/x64/Vale.Poly1305.Bitvectors.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 75,
"end_line": 200,
"start_col": 0,
"start_line": 199
} | module Vale.Poly1305.Bitvectors
open FStar.BV
open FStar.Tactics
open FStar.Tactics.Derived
open FStar.Tactics.BV
open FStar.Mul
open FStar.UInt
open FStar.Math.Lemmas
open Vale.Lib.Tactics
open Vale.Lib.Bv_s
open Vale.Math.Bits
// tweak options?
#reset-options "--smtencoding.elim_box true"
//NOTE: Using the split tactic seems to slowdown execution by a lot.
let lemma_shr2 x =
assert_by_tactic (shift_right #64 x 2 == udiv #64 x 4) bv_tac
let lemma_shr4 x =
assert_by_tactic (shift_right #64 x 4 == udiv #64 x 16) bv_tac
let lemma_and_mod_n x =
assert_by_tactic (logand #64 x 3 == mod #64 x 4) (bv_tac);
assert_by_tactic (logand #64 x 15 == mod #64 x 16) (bv_tac)
let lemma_clear_lower_2 x =
assert_by_tactic
(logand #64 x 0xfffffffffffffffc == mul_mod #64 (udiv #64 x 4) 4)
bv_tac
let lemma_and_constants x =
assert_by_tactic (logand #64 x 0 == (0 <: uint_t 64)) bv_tac;
assert_by_tactic (logand #64 x 0xffffffffffffffff == x) bv_tac
let lemma_poly_constants x =
// using split in this seems to hang execution.
assert_by_tactic
(logand #64 x 0x0ffffffc0fffffff < (0x1000000000000000 <: uint_t 64))
(fun () -> bv_tac_lt 64);
assert_by_tactic
(logand #64 x 0x0ffffffc0ffffffc < (0x1000000000000000 <: uint_t 64))
(fun () -> bv_tac_lt 64);
assert_by_tactic
(mod #64 (logand #64 x 0x0ffffffc0ffffffc) 4 == (0 <: uint_t 64))
(fun () -> bv_tac ())
let lemma_and_commutes x y =
assert_by_tactic
(logand #64 x y == logand #64 y x)
bv_tac
let lemma_bv128_64_64_and_helper' (x0:bv_t 64) (x1:bv_t 64) (y0:bv_t 64) (y1:bv_t 64) :
Lemma (requires True)
(ensures ((bvor #128 (bvshl #128 (bv_uext #64 #64 (bvand #64 x1 y1)) 64)
(bv_uext #64 #64 (bvand #64 x0 y0))) ==
bvand #128 (bvor #128 (bvshl #128 (bv_uext #64 #64 x1) 64)
(bv_uext #64 #64 x0))
(bvor #128 (bvshl #128 (bv_uext #64 #64 y1) 64)
(bv_uext #64 #64 y0)))) = ()
// Rewrite all equalities and then the goal is trivial for Z3.
// Without rewriting this does not go through.
// I believe the reason is related to a previously reported issue with the way
// Z3 bit-blasts through the Boxing/Unboxing functions. I thought this was fixed
// but it may not be the case. Notice that by rewriting with tactics the solver
// only gets to see one big term without any boxing or unboxing inside it.
let lemma_bv128_64_64_and_helper x x0 x1 y y0 y1 z z0 z1 =
lemma_bv128_64_64_and_helper' x0 x1 y0 y1;
assert_by_tactic (z == bvand #128 x y)
(fun () -> destruct_conj ();
rewrite_eqs_from_context ())
let bv128_64_64 x0 x1 = bvor (bvshl (bv_uext #64 #64 x1) 64) (bv_uext #64 #64 x0)
unfold let uint_to_nat (#n:nat) (x:uint_t n) : r:nat{r = x} =
assert (x < pow2 n);
modulo_lemma x (pow2 n);
x
let uint_ext (#n : nat) (#m : nat{n <= m}) (x : uint_t n) : r:(uint_t m){uint_to_nat r = uint_to_nat x} =
assert_norm(fits x n);
pow2_le_compat m n;
assert_norm(fits x m);
modulo_lemma x (pow2 m);
to_uint_t m x
#reset-options "--smtencoding.elim_box true --smtencoding.l_arith_repr boxwrap --smtencoding.nl_arith_repr boxwrap"
let mul_bvshl (u:uint_t 64) :
Lemma (0x10000000000000000 * u < pow2 128 /\
(int2bv #128 (0x10000000000000000 * u) ==
bvshl (bv_uext #64 #64 (int2bv u)) 64)) =
assert_norm ( 0x10000000000000000 * pow2 63 < pow2 128);
modulo_lemma (0x10000000000000000 * u) (pow2 128);
assert_by_tactic
(int2bv #128 (mul_mod #128 0x10000000000000000 (uint_ext #64 #128 u)) ==
bvmul #128 (int2bv #128 0x10000000000000000) (uint_ext #64 #128 u))
(fun () -> mapply (`trans); arith_to_bv_tac (); trefl ())
#reset-options "--smtencoding.elim_box true"
let plus_bvor (u h:bv_t 128) :
Lemma (bvand u h = bv_zero ==> bvadd u h == bvor u h) = ()
let lemma_bv128_64_64_and x x0 x1 y y0 y1 z z0 z1 =
assert_by_tactic (z == bvand #128 x y)
(fun () -> destruct_conj ();
rewrite_eqs_from_context ();
norm[delta])
#reset-options "--smtencoding.elim_box true --z3refresh --z3rlimit 20 --max_ifuel 1 --max_fuel 1"
let int2bv_uext_64_128 (x1 : nat) :
Lemma (requires (FStar.UInt.size x1 64))
(ensures (bv_uext #64 #64 (int2bv #64 x1) == int2bv #128 x1)) =
assert (64 <= 128);
pow2_le_compat 128 64;
assert (x1 < pow2 128);
modulo_lemma x1 (pow2 128); // x1 % pow2 128 = x1
assert (FStar.UInt.size x1 128);
assert_by_tactic (bv_uext #64 #64 (int2bv #64 x1) == int2bv #128 x1)
(fun () -> dump "..";
norm[delta_only [`%uint_ext; `%FStar.UInt.to_uint_t]];
// grewrite (quote (x1 % pow2 128)) (quote x1);
dump "After norm"; smt ())
#reset-options "--smtencoding.l_arith_repr native --smtencoding.nl_arith_repr wrapped --smtencoding.elim_box true --z3cliopt smt.arith.nl=false --max_fuel 1 --max_ifuel 0"
let lowerUpper128m (l:uint_t 64) (u:uint_t 64) : uint_t 128 =
add_hide #128 (mul_hide #128 (uext #64 #64 u) 0x10000000000000000) (uext #64 #64 l)
let lowerUpper128b (l:bv_t 64) (u:bv_t 64) : bv_t 128 =
b_add #128 (b_mul #128 (b_uext #64 #64 u) 0x10000000000000000) (b_uext #64 #64 l)
//this was so flaky, new options helped.
#reset-options "--smtencoding.elim_box true --z3refresh --z3rlimit 40 --max_ifuel 1 --max_fuel 1"
let lemma_lowerUpper128_andu
(x:uint_t 128) (x0:uint_t 64) (x1:uint_t 64) (y:uint_t 128)
(y0:uint_t 64) (y1:uint_t 64) (z:uint_t 128) (z0:uint_t 64) (z1:uint_t 64) :
Lemma
(requires
z0 == logand #64 x0 y0 /\
z1 == logand #64 x1 y1 /\
x == lowerUpper128u x0 x1 /\
y == lowerUpper128u y0 y1 /\
z == lowerUpper128u z0 z1)
(ensures z == logand #128 x y)
=
let bx0 = b_i2b x0 in
let bx1 = b_i2b x1 in
let by0 = b_i2b y0 in
let by1 = b_i2b y1 in
assert_norm (
lowerUpper128b (b_and bx0 by0) (b_and bx1 by1) ==
b_and (lowerUpper128b bx0 bx1) (lowerUpper128b by0 by1));
lemma_i2b_equal
(lowerUpper128m (logand x0 y0) (logand x1 y1))
(logand (lowerUpper128m x0 x1) (lowerUpper128m y0 y1));
assert_norm (lowerUpper128m x0 x1 == lowerUpper128u x0 x1);
assert_norm (lowerUpper128m y0 y1 == lowerUpper128u y0 y1);
assert_norm (lowerUpper128m z0 z1 == lowerUpper128u z0 z1);
()
#reset-options "--smtencoding.elim_box true --z3cliopt smt.case_split=3"
let lemma_bytes_shift_constants0 x =
assert_by_tactic (shift_left #64 0 3 == (0 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 0 == (0x1 <: uint_t 64)) bv_tac
let lemma_bytes_shift_constants1 x =
assert_by_tactic (shift_left #64 1 3 == (8 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 8 == (0x100 <: uint_t 64)) bv_tac
let lemma_bytes_shift_constants2 x =
assert_by_tactic (shift_left #64 2 3 == (16 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 16 == (0x10000 <: uint_t 64)) bv_tac
let lemma_bytes_shift_constants3 x =
assert_by_tactic (shift_left #64 3 3 == (24 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 24 == (0x1000000 <: uint_t 64)) bv_tac
let lemma_bytes_shift_constants4 x =
assert_by_tactic (shift_left #64 4 3 == (32 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 32 == (0x100000000 <: uint_t 64)) bv_tac
let lemma_bytes_shift_constants5 x =
assert_by_tactic (shift_left #64 5 3 == (40 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 40 == (0x10000000000 <: uint_t 64)) bv_tac
let lemma_bytes_shift_constants6 x =
assert_by_tactic (shift_left #64 6 3 == (48 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 48 == (0x1000000000000 <: uint_t 64)) bv_tac
let lemma_bytes_shift_constants7 x =
assert_by_tactic (shift_left #64 7 3 == (56 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 56 == (0x100000000000000 <: uint_t 64)) bv_tac
let lemma_bytes_and_mod0 x =
assert_by_tactic (logand #64 x (0x1 - 1) == mod #64 x 0x1) bv_tac
let lemma_bytes_and_mod1 x =
assert_by_tactic (logand #64 x (0x100 - 1) == mod #64 x 0x100) bv_tac | {
"checked_file": "/",
"dependencies": [
"Vale.Math.Bits.fsti.checked",
"Vale.Lib.Tactics.fst.checked",
"Vale.Lib.Bv_s.fst.checked",
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Tactics.Derived.fst.checked",
"FStar.Tactics.BV.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.BV.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Poly1305.Bitvectors.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Math.Bits",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Bv_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3",
"smt.case_split=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: FStar.UInt.uint_t 64
-> FStar.Pervasives.Lemma (ensures FStar.UInt.logand x (0x10000 - 1) == FStar.UInt.mod x 0x10000) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.UInt.uint_t",
"FStar.Tactics.Effect.assert_by_tactic",
"Prims.eq2",
"FStar.UInt.logand",
"Prims.op_Subtraction",
"FStar.UInt.mod",
"FStar.Tactics.BV.bv_tac",
"Prims.unit"
] | [] | true | false | true | false | false | let lemma_bytes_and_mod2 x =
| assert_by_tactic (logand #64 x (0x10000 - 1) == mod #64 x 0x10000) bv_tac | false |
Vale.Poly1305.Bitvectors.fst | Vale.Poly1305.Bitvectors.lemma_bytes_and_mod1 | val lemma_bytes_and_mod1: x: uint_t 64 ->
Lemma (logand #64 x (0x100 - 1) == mod #64 x 0x100) | val lemma_bytes_and_mod1: x: uint_t 64 ->
Lemma (logand #64 x (0x100 - 1) == mod #64 x 0x100) | let lemma_bytes_and_mod1 x =
assert_by_tactic (logand #64 x (0x100 - 1) == mod #64 x 0x100) bv_tac | {
"file_name": "vale/code/crypto/poly1305/x64/Vale.Poly1305.Bitvectors.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 71,
"end_line": 197,
"start_col": 0,
"start_line": 196
} | module Vale.Poly1305.Bitvectors
open FStar.BV
open FStar.Tactics
open FStar.Tactics.Derived
open FStar.Tactics.BV
open FStar.Mul
open FStar.UInt
open FStar.Math.Lemmas
open Vale.Lib.Tactics
open Vale.Lib.Bv_s
open Vale.Math.Bits
// tweak options?
#reset-options "--smtencoding.elim_box true"
//NOTE: Using the split tactic seems to slowdown execution by a lot.
let lemma_shr2 x =
assert_by_tactic (shift_right #64 x 2 == udiv #64 x 4) bv_tac
let lemma_shr4 x =
assert_by_tactic (shift_right #64 x 4 == udiv #64 x 16) bv_tac
let lemma_and_mod_n x =
assert_by_tactic (logand #64 x 3 == mod #64 x 4) (bv_tac);
assert_by_tactic (logand #64 x 15 == mod #64 x 16) (bv_tac)
let lemma_clear_lower_2 x =
assert_by_tactic
(logand #64 x 0xfffffffffffffffc == mul_mod #64 (udiv #64 x 4) 4)
bv_tac
let lemma_and_constants x =
assert_by_tactic (logand #64 x 0 == (0 <: uint_t 64)) bv_tac;
assert_by_tactic (logand #64 x 0xffffffffffffffff == x) bv_tac
let lemma_poly_constants x =
// using split in this seems to hang execution.
assert_by_tactic
(logand #64 x 0x0ffffffc0fffffff < (0x1000000000000000 <: uint_t 64))
(fun () -> bv_tac_lt 64);
assert_by_tactic
(logand #64 x 0x0ffffffc0ffffffc < (0x1000000000000000 <: uint_t 64))
(fun () -> bv_tac_lt 64);
assert_by_tactic
(mod #64 (logand #64 x 0x0ffffffc0ffffffc) 4 == (0 <: uint_t 64))
(fun () -> bv_tac ())
let lemma_and_commutes x y =
assert_by_tactic
(logand #64 x y == logand #64 y x)
bv_tac
let lemma_bv128_64_64_and_helper' (x0:bv_t 64) (x1:bv_t 64) (y0:bv_t 64) (y1:bv_t 64) :
Lemma (requires True)
(ensures ((bvor #128 (bvshl #128 (bv_uext #64 #64 (bvand #64 x1 y1)) 64)
(bv_uext #64 #64 (bvand #64 x0 y0))) ==
bvand #128 (bvor #128 (bvshl #128 (bv_uext #64 #64 x1) 64)
(bv_uext #64 #64 x0))
(bvor #128 (bvshl #128 (bv_uext #64 #64 y1) 64)
(bv_uext #64 #64 y0)))) = ()
// Rewrite all equalities and then the goal is trivial for Z3.
// Without rewriting this does not go through.
// I believe the reason is related to a previously reported issue with the way
// Z3 bit-blasts through the Boxing/Unboxing functions. I thought this was fixed
// but it may not be the case. Notice that by rewriting with tactics the solver
// only gets to see one big term without any boxing or unboxing inside it.
let lemma_bv128_64_64_and_helper x x0 x1 y y0 y1 z z0 z1 =
lemma_bv128_64_64_and_helper' x0 x1 y0 y1;
assert_by_tactic (z == bvand #128 x y)
(fun () -> destruct_conj ();
rewrite_eqs_from_context ())
let bv128_64_64 x0 x1 = bvor (bvshl (bv_uext #64 #64 x1) 64) (bv_uext #64 #64 x0)
unfold let uint_to_nat (#n:nat) (x:uint_t n) : r:nat{r = x} =
assert (x < pow2 n);
modulo_lemma x (pow2 n);
x
let uint_ext (#n : nat) (#m : nat{n <= m}) (x : uint_t n) : r:(uint_t m){uint_to_nat r = uint_to_nat x} =
assert_norm(fits x n);
pow2_le_compat m n;
assert_norm(fits x m);
modulo_lemma x (pow2 m);
to_uint_t m x
#reset-options "--smtencoding.elim_box true --smtencoding.l_arith_repr boxwrap --smtencoding.nl_arith_repr boxwrap"
let mul_bvshl (u:uint_t 64) :
Lemma (0x10000000000000000 * u < pow2 128 /\
(int2bv #128 (0x10000000000000000 * u) ==
bvshl (bv_uext #64 #64 (int2bv u)) 64)) =
assert_norm ( 0x10000000000000000 * pow2 63 < pow2 128);
modulo_lemma (0x10000000000000000 * u) (pow2 128);
assert_by_tactic
(int2bv #128 (mul_mod #128 0x10000000000000000 (uint_ext #64 #128 u)) ==
bvmul #128 (int2bv #128 0x10000000000000000) (uint_ext #64 #128 u))
(fun () -> mapply (`trans); arith_to_bv_tac (); trefl ())
#reset-options "--smtencoding.elim_box true"
let plus_bvor (u h:bv_t 128) :
Lemma (bvand u h = bv_zero ==> bvadd u h == bvor u h) = ()
let lemma_bv128_64_64_and x x0 x1 y y0 y1 z z0 z1 =
assert_by_tactic (z == bvand #128 x y)
(fun () -> destruct_conj ();
rewrite_eqs_from_context ();
norm[delta])
#reset-options "--smtencoding.elim_box true --z3refresh --z3rlimit 20 --max_ifuel 1 --max_fuel 1"
let int2bv_uext_64_128 (x1 : nat) :
Lemma (requires (FStar.UInt.size x1 64))
(ensures (bv_uext #64 #64 (int2bv #64 x1) == int2bv #128 x1)) =
assert (64 <= 128);
pow2_le_compat 128 64;
assert (x1 < pow2 128);
modulo_lemma x1 (pow2 128); // x1 % pow2 128 = x1
assert (FStar.UInt.size x1 128);
assert_by_tactic (bv_uext #64 #64 (int2bv #64 x1) == int2bv #128 x1)
(fun () -> dump "..";
norm[delta_only [`%uint_ext; `%FStar.UInt.to_uint_t]];
// grewrite (quote (x1 % pow2 128)) (quote x1);
dump "After norm"; smt ())
#reset-options "--smtencoding.l_arith_repr native --smtencoding.nl_arith_repr wrapped --smtencoding.elim_box true --z3cliopt smt.arith.nl=false --max_fuel 1 --max_ifuel 0"
let lowerUpper128m (l:uint_t 64) (u:uint_t 64) : uint_t 128 =
add_hide #128 (mul_hide #128 (uext #64 #64 u) 0x10000000000000000) (uext #64 #64 l)
let lowerUpper128b (l:bv_t 64) (u:bv_t 64) : bv_t 128 =
b_add #128 (b_mul #128 (b_uext #64 #64 u) 0x10000000000000000) (b_uext #64 #64 l)
//this was so flaky, new options helped.
#reset-options "--smtencoding.elim_box true --z3refresh --z3rlimit 40 --max_ifuel 1 --max_fuel 1"
let lemma_lowerUpper128_andu
(x:uint_t 128) (x0:uint_t 64) (x1:uint_t 64) (y:uint_t 128)
(y0:uint_t 64) (y1:uint_t 64) (z:uint_t 128) (z0:uint_t 64) (z1:uint_t 64) :
Lemma
(requires
z0 == logand #64 x0 y0 /\
z1 == logand #64 x1 y1 /\
x == lowerUpper128u x0 x1 /\
y == lowerUpper128u y0 y1 /\
z == lowerUpper128u z0 z1)
(ensures z == logand #128 x y)
=
let bx0 = b_i2b x0 in
let bx1 = b_i2b x1 in
let by0 = b_i2b y0 in
let by1 = b_i2b y1 in
assert_norm (
lowerUpper128b (b_and bx0 by0) (b_and bx1 by1) ==
b_and (lowerUpper128b bx0 bx1) (lowerUpper128b by0 by1));
lemma_i2b_equal
(lowerUpper128m (logand x0 y0) (logand x1 y1))
(logand (lowerUpper128m x0 x1) (lowerUpper128m y0 y1));
assert_norm (lowerUpper128m x0 x1 == lowerUpper128u x0 x1);
assert_norm (lowerUpper128m y0 y1 == lowerUpper128u y0 y1);
assert_norm (lowerUpper128m z0 z1 == lowerUpper128u z0 z1);
()
#reset-options "--smtencoding.elim_box true --z3cliopt smt.case_split=3"
let lemma_bytes_shift_constants0 x =
assert_by_tactic (shift_left #64 0 3 == (0 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 0 == (0x1 <: uint_t 64)) bv_tac
let lemma_bytes_shift_constants1 x =
assert_by_tactic (shift_left #64 1 3 == (8 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 8 == (0x100 <: uint_t 64)) bv_tac
let lemma_bytes_shift_constants2 x =
assert_by_tactic (shift_left #64 2 3 == (16 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 16 == (0x10000 <: uint_t 64)) bv_tac
let lemma_bytes_shift_constants3 x =
assert_by_tactic (shift_left #64 3 3 == (24 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 24 == (0x1000000 <: uint_t 64)) bv_tac
let lemma_bytes_shift_constants4 x =
assert_by_tactic (shift_left #64 4 3 == (32 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 32 == (0x100000000 <: uint_t 64)) bv_tac
let lemma_bytes_shift_constants5 x =
assert_by_tactic (shift_left #64 5 3 == (40 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 40 == (0x10000000000 <: uint_t 64)) bv_tac
let lemma_bytes_shift_constants6 x =
assert_by_tactic (shift_left #64 6 3 == (48 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 48 == (0x1000000000000 <: uint_t 64)) bv_tac
let lemma_bytes_shift_constants7 x =
assert_by_tactic (shift_left #64 7 3 == (56 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 56 == (0x100000000000000 <: uint_t 64)) bv_tac
let lemma_bytes_and_mod0 x =
assert_by_tactic (logand #64 x (0x1 - 1) == mod #64 x 0x1) bv_tac | {
"checked_file": "/",
"dependencies": [
"Vale.Math.Bits.fsti.checked",
"Vale.Lib.Tactics.fst.checked",
"Vale.Lib.Bv_s.fst.checked",
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Tactics.Derived.fst.checked",
"FStar.Tactics.BV.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.BV.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Poly1305.Bitvectors.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Math.Bits",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Bv_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3",
"smt.case_split=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: FStar.UInt.uint_t 64
-> FStar.Pervasives.Lemma (ensures FStar.UInt.logand x (0x100 - 1) == FStar.UInt.mod x 0x100) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.UInt.uint_t",
"FStar.Tactics.Effect.assert_by_tactic",
"Prims.eq2",
"FStar.UInt.logand",
"Prims.op_Subtraction",
"FStar.UInt.mod",
"FStar.Tactics.BV.bv_tac",
"Prims.unit"
] | [] | true | false | true | false | false | let lemma_bytes_and_mod1 x =
| assert_by_tactic (logand #64 x (0x100 - 1) == mod #64 x 0x100) bv_tac | false |
Vale.Poly1305.Bitvectors.fst | Vale.Poly1305.Bitvectors.lemma_bytes_and_mod4 | val lemma_bytes_and_mod4: x: uint_t 64 ->
Lemma (logand #64 x (0x100000000 - 1) == mod #64 x 0x100000000) | val lemma_bytes_and_mod4: x: uint_t 64 ->
Lemma (logand #64 x (0x100000000 - 1) == mod #64 x 0x100000000) | let lemma_bytes_and_mod4 x =
assert_by_tactic (logand #64 x (0x100000000 - 1) == mod #64 x 0x100000000) bv_tac | {
"file_name": "vale/code/crypto/poly1305/x64/Vale.Poly1305.Bitvectors.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 83,
"end_line": 205,
"start_col": 0,
"start_line": 204
} | module Vale.Poly1305.Bitvectors
open FStar.BV
open FStar.Tactics
open FStar.Tactics.Derived
open FStar.Tactics.BV
open FStar.Mul
open FStar.UInt
open FStar.Math.Lemmas
open Vale.Lib.Tactics
open Vale.Lib.Bv_s
open Vale.Math.Bits
// tweak options?
#reset-options "--smtencoding.elim_box true"
//NOTE: Using the split tactic seems to slowdown execution by a lot.
let lemma_shr2 x =
assert_by_tactic (shift_right #64 x 2 == udiv #64 x 4) bv_tac
let lemma_shr4 x =
assert_by_tactic (shift_right #64 x 4 == udiv #64 x 16) bv_tac
let lemma_and_mod_n x =
assert_by_tactic (logand #64 x 3 == mod #64 x 4) (bv_tac);
assert_by_tactic (logand #64 x 15 == mod #64 x 16) (bv_tac)
let lemma_clear_lower_2 x =
assert_by_tactic
(logand #64 x 0xfffffffffffffffc == mul_mod #64 (udiv #64 x 4) 4)
bv_tac
let lemma_and_constants x =
assert_by_tactic (logand #64 x 0 == (0 <: uint_t 64)) bv_tac;
assert_by_tactic (logand #64 x 0xffffffffffffffff == x) bv_tac
let lemma_poly_constants x =
// using split in this seems to hang execution.
assert_by_tactic
(logand #64 x 0x0ffffffc0fffffff < (0x1000000000000000 <: uint_t 64))
(fun () -> bv_tac_lt 64);
assert_by_tactic
(logand #64 x 0x0ffffffc0ffffffc < (0x1000000000000000 <: uint_t 64))
(fun () -> bv_tac_lt 64);
assert_by_tactic
(mod #64 (logand #64 x 0x0ffffffc0ffffffc) 4 == (0 <: uint_t 64))
(fun () -> bv_tac ())
let lemma_and_commutes x y =
assert_by_tactic
(logand #64 x y == logand #64 y x)
bv_tac
let lemma_bv128_64_64_and_helper' (x0:bv_t 64) (x1:bv_t 64) (y0:bv_t 64) (y1:bv_t 64) :
Lemma (requires True)
(ensures ((bvor #128 (bvshl #128 (bv_uext #64 #64 (bvand #64 x1 y1)) 64)
(bv_uext #64 #64 (bvand #64 x0 y0))) ==
bvand #128 (bvor #128 (bvshl #128 (bv_uext #64 #64 x1) 64)
(bv_uext #64 #64 x0))
(bvor #128 (bvshl #128 (bv_uext #64 #64 y1) 64)
(bv_uext #64 #64 y0)))) = ()
// Rewrite all equalities and then the goal is trivial for Z3.
// Without rewriting this does not go through.
// I believe the reason is related to a previously reported issue with the way
// Z3 bit-blasts through the Boxing/Unboxing functions. I thought this was fixed
// but it may not be the case. Notice that by rewriting with tactics the solver
// only gets to see one big term without any boxing or unboxing inside it.
let lemma_bv128_64_64_and_helper x x0 x1 y y0 y1 z z0 z1 =
lemma_bv128_64_64_and_helper' x0 x1 y0 y1;
assert_by_tactic (z == bvand #128 x y)
(fun () -> destruct_conj ();
rewrite_eqs_from_context ())
let bv128_64_64 x0 x1 = bvor (bvshl (bv_uext #64 #64 x1) 64) (bv_uext #64 #64 x0)
unfold let uint_to_nat (#n:nat) (x:uint_t n) : r:nat{r = x} =
assert (x < pow2 n);
modulo_lemma x (pow2 n);
x
let uint_ext (#n : nat) (#m : nat{n <= m}) (x : uint_t n) : r:(uint_t m){uint_to_nat r = uint_to_nat x} =
assert_norm(fits x n);
pow2_le_compat m n;
assert_norm(fits x m);
modulo_lemma x (pow2 m);
to_uint_t m x
#reset-options "--smtencoding.elim_box true --smtencoding.l_arith_repr boxwrap --smtencoding.nl_arith_repr boxwrap"
let mul_bvshl (u:uint_t 64) :
Lemma (0x10000000000000000 * u < pow2 128 /\
(int2bv #128 (0x10000000000000000 * u) ==
bvshl (bv_uext #64 #64 (int2bv u)) 64)) =
assert_norm ( 0x10000000000000000 * pow2 63 < pow2 128);
modulo_lemma (0x10000000000000000 * u) (pow2 128);
assert_by_tactic
(int2bv #128 (mul_mod #128 0x10000000000000000 (uint_ext #64 #128 u)) ==
bvmul #128 (int2bv #128 0x10000000000000000) (uint_ext #64 #128 u))
(fun () -> mapply (`trans); arith_to_bv_tac (); trefl ())
#reset-options "--smtencoding.elim_box true"
let plus_bvor (u h:bv_t 128) :
Lemma (bvand u h = bv_zero ==> bvadd u h == bvor u h) = ()
let lemma_bv128_64_64_and x x0 x1 y y0 y1 z z0 z1 =
assert_by_tactic (z == bvand #128 x y)
(fun () -> destruct_conj ();
rewrite_eqs_from_context ();
norm[delta])
#reset-options "--smtencoding.elim_box true --z3refresh --z3rlimit 20 --max_ifuel 1 --max_fuel 1"
let int2bv_uext_64_128 (x1 : nat) :
Lemma (requires (FStar.UInt.size x1 64))
(ensures (bv_uext #64 #64 (int2bv #64 x1) == int2bv #128 x1)) =
assert (64 <= 128);
pow2_le_compat 128 64;
assert (x1 < pow2 128);
modulo_lemma x1 (pow2 128); // x1 % pow2 128 = x1
assert (FStar.UInt.size x1 128);
assert_by_tactic (bv_uext #64 #64 (int2bv #64 x1) == int2bv #128 x1)
(fun () -> dump "..";
norm[delta_only [`%uint_ext; `%FStar.UInt.to_uint_t]];
// grewrite (quote (x1 % pow2 128)) (quote x1);
dump "After norm"; smt ())
#reset-options "--smtencoding.l_arith_repr native --smtencoding.nl_arith_repr wrapped --smtencoding.elim_box true --z3cliopt smt.arith.nl=false --max_fuel 1 --max_ifuel 0"
let lowerUpper128m (l:uint_t 64) (u:uint_t 64) : uint_t 128 =
add_hide #128 (mul_hide #128 (uext #64 #64 u) 0x10000000000000000) (uext #64 #64 l)
let lowerUpper128b (l:bv_t 64) (u:bv_t 64) : bv_t 128 =
b_add #128 (b_mul #128 (b_uext #64 #64 u) 0x10000000000000000) (b_uext #64 #64 l)
//this was so flaky, new options helped.
#reset-options "--smtencoding.elim_box true --z3refresh --z3rlimit 40 --max_ifuel 1 --max_fuel 1"
let lemma_lowerUpper128_andu
(x:uint_t 128) (x0:uint_t 64) (x1:uint_t 64) (y:uint_t 128)
(y0:uint_t 64) (y1:uint_t 64) (z:uint_t 128) (z0:uint_t 64) (z1:uint_t 64) :
Lemma
(requires
z0 == logand #64 x0 y0 /\
z1 == logand #64 x1 y1 /\
x == lowerUpper128u x0 x1 /\
y == lowerUpper128u y0 y1 /\
z == lowerUpper128u z0 z1)
(ensures z == logand #128 x y)
=
let bx0 = b_i2b x0 in
let bx1 = b_i2b x1 in
let by0 = b_i2b y0 in
let by1 = b_i2b y1 in
assert_norm (
lowerUpper128b (b_and bx0 by0) (b_and bx1 by1) ==
b_and (lowerUpper128b bx0 bx1) (lowerUpper128b by0 by1));
lemma_i2b_equal
(lowerUpper128m (logand x0 y0) (logand x1 y1))
(logand (lowerUpper128m x0 x1) (lowerUpper128m y0 y1));
assert_norm (lowerUpper128m x0 x1 == lowerUpper128u x0 x1);
assert_norm (lowerUpper128m y0 y1 == lowerUpper128u y0 y1);
assert_norm (lowerUpper128m z0 z1 == lowerUpper128u z0 z1);
()
#reset-options "--smtencoding.elim_box true --z3cliopt smt.case_split=3"
let lemma_bytes_shift_constants0 x =
assert_by_tactic (shift_left #64 0 3 == (0 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 0 == (0x1 <: uint_t 64)) bv_tac
let lemma_bytes_shift_constants1 x =
assert_by_tactic (shift_left #64 1 3 == (8 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 8 == (0x100 <: uint_t 64)) bv_tac
let lemma_bytes_shift_constants2 x =
assert_by_tactic (shift_left #64 2 3 == (16 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 16 == (0x10000 <: uint_t 64)) bv_tac
let lemma_bytes_shift_constants3 x =
assert_by_tactic (shift_left #64 3 3 == (24 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 24 == (0x1000000 <: uint_t 64)) bv_tac
let lemma_bytes_shift_constants4 x =
assert_by_tactic (shift_left #64 4 3 == (32 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 32 == (0x100000000 <: uint_t 64)) bv_tac
let lemma_bytes_shift_constants5 x =
assert_by_tactic (shift_left #64 5 3 == (40 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 40 == (0x10000000000 <: uint_t 64)) bv_tac
let lemma_bytes_shift_constants6 x =
assert_by_tactic (shift_left #64 6 3 == (48 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 48 == (0x1000000000000 <: uint_t 64)) bv_tac
let lemma_bytes_shift_constants7 x =
assert_by_tactic (shift_left #64 7 3 == (56 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 56 == (0x100000000000000 <: uint_t 64)) bv_tac
let lemma_bytes_and_mod0 x =
assert_by_tactic (logand #64 x (0x1 - 1) == mod #64 x 0x1) bv_tac
let lemma_bytes_and_mod1 x =
assert_by_tactic (logand #64 x (0x100 - 1) == mod #64 x 0x100) bv_tac
let lemma_bytes_and_mod2 x =
assert_by_tactic (logand #64 x (0x10000 - 1) == mod #64 x 0x10000) bv_tac
let lemma_bytes_and_mod3 x =
assert_by_tactic (logand #64 x (0x1000000 - 1) == mod #64 x 0x1000000) bv_tac | {
"checked_file": "/",
"dependencies": [
"Vale.Math.Bits.fsti.checked",
"Vale.Lib.Tactics.fst.checked",
"Vale.Lib.Bv_s.fst.checked",
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Tactics.Derived.fst.checked",
"FStar.Tactics.BV.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.BV.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Poly1305.Bitvectors.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Math.Bits",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Bv_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3",
"smt.case_split=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: FStar.UInt.uint_t 64
-> FStar.Pervasives.Lemma
(ensures FStar.UInt.logand x (0x100000000 - 1) == FStar.UInt.mod x 0x100000000) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.UInt.uint_t",
"FStar.Tactics.Effect.assert_by_tactic",
"Prims.eq2",
"FStar.UInt.logand",
"Prims.op_Subtraction",
"FStar.UInt.mod",
"FStar.Tactics.BV.bv_tac",
"Prims.unit"
] | [] | true | false | true | false | false | let lemma_bytes_and_mod4 x =
| assert_by_tactic (logand #64 x (0x100000000 - 1) == mod #64 x 0x100000000) bv_tac | false |
Vale.Poly1305.Bitvectors.fst | Vale.Poly1305.Bitvectors.lemma_bytes_and_mod5 | val lemma_bytes_and_mod5: x: uint_t 64 ->
Lemma (logand #64 x (0x10000000000 - 1) == mod #64 x 0x10000000000) | val lemma_bytes_and_mod5: x: uint_t 64 ->
Lemma (logand #64 x (0x10000000000 - 1) == mod #64 x 0x10000000000) | let lemma_bytes_and_mod5 x =
assert_by_tactic (logand #64 x (0x10000000000 - 1) == mod #64 x 0x10000000000) bv_tac | {
"file_name": "vale/code/crypto/poly1305/x64/Vale.Poly1305.Bitvectors.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 87,
"end_line": 208,
"start_col": 0,
"start_line": 207
} | module Vale.Poly1305.Bitvectors
open FStar.BV
open FStar.Tactics
open FStar.Tactics.Derived
open FStar.Tactics.BV
open FStar.Mul
open FStar.UInt
open FStar.Math.Lemmas
open Vale.Lib.Tactics
open Vale.Lib.Bv_s
open Vale.Math.Bits
// tweak options?
#reset-options "--smtencoding.elim_box true"
//NOTE: Using the split tactic seems to slowdown execution by a lot.
let lemma_shr2 x =
assert_by_tactic (shift_right #64 x 2 == udiv #64 x 4) bv_tac
let lemma_shr4 x =
assert_by_tactic (shift_right #64 x 4 == udiv #64 x 16) bv_tac
let lemma_and_mod_n x =
assert_by_tactic (logand #64 x 3 == mod #64 x 4) (bv_tac);
assert_by_tactic (logand #64 x 15 == mod #64 x 16) (bv_tac)
let lemma_clear_lower_2 x =
assert_by_tactic
(logand #64 x 0xfffffffffffffffc == mul_mod #64 (udiv #64 x 4) 4)
bv_tac
let lemma_and_constants x =
assert_by_tactic (logand #64 x 0 == (0 <: uint_t 64)) bv_tac;
assert_by_tactic (logand #64 x 0xffffffffffffffff == x) bv_tac
let lemma_poly_constants x =
// using split in this seems to hang execution.
assert_by_tactic
(logand #64 x 0x0ffffffc0fffffff < (0x1000000000000000 <: uint_t 64))
(fun () -> bv_tac_lt 64);
assert_by_tactic
(logand #64 x 0x0ffffffc0ffffffc < (0x1000000000000000 <: uint_t 64))
(fun () -> bv_tac_lt 64);
assert_by_tactic
(mod #64 (logand #64 x 0x0ffffffc0ffffffc) 4 == (0 <: uint_t 64))
(fun () -> bv_tac ())
let lemma_and_commutes x y =
assert_by_tactic
(logand #64 x y == logand #64 y x)
bv_tac
let lemma_bv128_64_64_and_helper' (x0:bv_t 64) (x1:bv_t 64) (y0:bv_t 64) (y1:bv_t 64) :
Lemma (requires True)
(ensures ((bvor #128 (bvshl #128 (bv_uext #64 #64 (bvand #64 x1 y1)) 64)
(bv_uext #64 #64 (bvand #64 x0 y0))) ==
bvand #128 (bvor #128 (bvshl #128 (bv_uext #64 #64 x1) 64)
(bv_uext #64 #64 x0))
(bvor #128 (bvshl #128 (bv_uext #64 #64 y1) 64)
(bv_uext #64 #64 y0)))) = ()
// Rewrite all equalities and then the goal is trivial for Z3.
// Without rewriting this does not go through.
// I believe the reason is related to a previously reported issue with the way
// Z3 bit-blasts through the Boxing/Unboxing functions. I thought this was fixed
// but it may not be the case. Notice that by rewriting with tactics the solver
// only gets to see one big term without any boxing or unboxing inside it.
let lemma_bv128_64_64_and_helper x x0 x1 y y0 y1 z z0 z1 =
lemma_bv128_64_64_and_helper' x0 x1 y0 y1;
assert_by_tactic (z == bvand #128 x y)
(fun () -> destruct_conj ();
rewrite_eqs_from_context ())
let bv128_64_64 x0 x1 = bvor (bvshl (bv_uext #64 #64 x1) 64) (bv_uext #64 #64 x0)
unfold let uint_to_nat (#n:nat) (x:uint_t n) : r:nat{r = x} =
assert (x < pow2 n);
modulo_lemma x (pow2 n);
x
let uint_ext (#n : nat) (#m : nat{n <= m}) (x : uint_t n) : r:(uint_t m){uint_to_nat r = uint_to_nat x} =
assert_norm(fits x n);
pow2_le_compat m n;
assert_norm(fits x m);
modulo_lemma x (pow2 m);
to_uint_t m x
#reset-options "--smtencoding.elim_box true --smtencoding.l_arith_repr boxwrap --smtencoding.nl_arith_repr boxwrap"
let mul_bvshl (u:uint_t 64) :
Lemma (0x10000000000000000 * u < pow2 128 /\
(int2bv #128 (0x10000000000000000 * u) ==
bvshl (bv_uext #64 #64 (int2bv u)) 64)) =
assert_norm ( 0x10000000000000000 * pow2 63 < pow2 128);
modulo_lemma (0x10000000000000000 * u) (pow2 128);
assert_by_tactic
(int2bv #128 (mul_mod #128 0x10000000000000000 (uint_ext #64 #128 u)) ==
bvmul #128 (int2bv #128 0x10000000000000000) (uint_ext #64 #128 u))
(fun () -> mapply (`trans); arith_to_bv_tac (); trefl ())
#reset-options "--smtencoding.elim_box true"
let plus_bvor (u h:bv_t 128) :
Lemma (bvand u h = bv_zero ==> bvadd u h == bvor u h) = ()
let lemma_bv128_64_64_and x x0 x1 y y0 y1 z z0 z1 =
assert_by_tactic (z == bvand #128 x y)
(fun () -> destruct_conj ();
rewrite_eqs_from_context ();
norm[delta])
#reset-options "--smtencoding.elim_box true --z3refresh --z3rlimit 20 --max_ifuel 1 --max_fuel 1"
let int2bv_uext_64_128 (x1 : nat) :
Lemma (requires (FStar.UInt.size x1 64))
(ensures (bv_uext #64 #64 (int2bv #64 x1) == int2bv #128 x1)) =
assert (64 <= 128);
pow2_le_compat 128 64;
assert (x1 < pow2 128);
modulo_lemma x1 (pow2 128); // x1 % pow2 128 = x1
assert (FStar.UInt.size x1 128);
assert_by_tactic (bv_uext #64 #64 (int2bv #64 x1) == int2bv #128 x1)
(fun () -> dump "..";
norm[delta_only [`%uint_ext; `%FStar.UInt.to_uint_t]];
// grewrite (quote (x1 % pow2 128)) (quote x1);
dump "After norm"; smt ())
#reset-options "--smtencoding.l_arith_repr native --smtencoding.nl_arith_repr wrapped --smtencoding.elim_box true --z3cliopt smt.arith.nl=false --max_fuel 1 --max_ifuel 0"
let lowerUpper128m (l:uint_t 64) (u:uint_t 64) : uint_t 128 =
add_hide #128 (mul_hide #128 (uext #64 #64 u) 0x10000000000000000) (uext #64 #64 l)
let lowerUpper128b (l:bv_t 64) (u:bv_t 64) : bv_t 128 =
b_add #128 (b_mul #128 (b_uext #64 #64 u) 0x10000000000000000) (b_uext #64 #64 l)
//this was so flaky, new options helped.
#reset-options "--smtencoding.elim_box true --z3refresh --z3rlimit 40 --max_ifuel 1 --max_fuel 1"
let lemma_lowerUpper128_andu
(x:uint_t 128) (x0:uint_t 64) (x1:uint_t 64) (y:uint_t 128)
(y0:uint_t 64) (y1:uint_t 64) (z:uint_t 128) (z0:uint_t 64) (z1:uint_t 64) :
Lemma
(requires
z0 == logand #64 x0 y0 /\
z1 == logand #64 x1 y1 /\
x == lowerUpper128u x0 x1 /\
y == lowerUpper128u y0 y1 /\
z == lowerUpper128u z0 z1)
(ensures z == logand #128 x y)
=
let bx0 = b_i2b x0 in
let bx1 = b_i2b x1 in
let by0 = b_i2b y0 in
let by1 = b_i2b y1 in
assert_norm (
lowerUpper128b (b_and bx0 by0) (b_and bx1 by1) ==
b_and (lowerUpper128b bx0 bx1) (lowerUpper128b by0 by1));
lemma_i2b_equal
(lowerUpper128m (logand x0 y0) (logand x1 y1))
(logand (lowerUpper128m x0 x1) (lowerUpper128m y0 y1));
assert_norm (lowerUpper128m x0 x1 == lowerUpper128u x0 x1);
assert_norm (lowerUpper128m y0 y1 == lowerUpper128u y0 y1);
assert_norm (lowerUpper128m z0 z1 == lowerUpper128u z0 z1);
()
#reset-options "--smtencoding.elim_box true --z3cliopt smt.case_split=3"
let lemma_bytes_shift_constants0 x =
assert_by_tactic (shift_left #64 0 3 == (0 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 0 == (0x1 <: uint_t 64)) bv_tac
let lemma_bytes_shift_constants1 x =
assert_by_tactic (shift_left #64 1 3 == (8 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 8 == (0x100 <: uint_t 64)) bv_tac
let lemma_bytes_shift_constants2 x =
assert_by_tactic (shift_left #64 2 3 == (16 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 16 == (0x10000 <: uint_t 64)) bv_tac
let lemma_bytes_shift_constants3 x =
assert_by_tactic (shift_left #64 3 3 == (24 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 24 == (0x1000000 <: uint_t 64)) bv_tac
let lemma_bytes_shift_constants4 x =
assert_by_tactic (shift_left #64 4 3 == (32 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 32 == (0x100000000 <: uint_t 64)) bv_tac
let lemma_bytes_shift_constants5 x =
assert_by_tactic (shift_left #64 5 3 == (40 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 40 == (0x10000000000 <: uint_t 64)) bv_tac
let lemma_bytes_shift_constants6 x =
assert_by_tactic (shift_left #64 6 3 == (48 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 48 == (0x1000000000000 <: uint_t 64)) bv_tac
let lemma_bytes_shift_constants7 x =
assert_by_tactic (shift_left #64 7 3 == (56 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 56 == (0x100000000000000 <: uint_t 64)) bv_tac
let lemma_bytes_and_mod0 x =
assert_by_tactic (logand #64 x (0x1 - 1) == mod #64 x 0x1) bv_tac
let lemma_bytes_and_mod1 x =
assert_by_tactic (logand #64 x (0x100 - 1) == mod #64 x 0x100) bv_tac
let lemma_bytes_and_mod2 x =
assert_by_tactic (logand #64 x (0x10000 - 1) == mod #64 x 0x10000) bv_tac
let lemma_bytes_and_mod3 x =
assert_by_tactic (logand #64 x (0x1000000 - 1) == mod #64 x 0x1000000) bv_tac
let lemma_bytes_and_mod4 x =
assert_by_tactic (logand #64 x (0x100000000 - 1) == mod #64 x 0x100000000) bv_tac | {
"checked_file": "/",
"dependencies": [
"Vale.Math.Bits.fsti.checked",
"Vale.Lib.Tactics.fst.checked",
"Vale.Lib.Bv_s.fst.checked",
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Tactics.Derived.fst.checked",
"FStar.Tactics.BV.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.BV.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Poly1305.Bitvectors.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Math.Bits",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Bv_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3",
"smt.case_split=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: FStar.UInt.uint_t 64
-> FStar.Pervasives.Lemma
(ensures FStar.UInt.logand x (0x10000000000 - 1) == FStar.UInt.mod x 0x10000000000) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.UInt.uint_t",
"FStar.Tactics.Effect.assert_by_tactic",
"Prims.eq2",
"FStar.UInt.logand",
"Prims.op_Subtraction",
"FStar.UInt.mod",
"FStar.Tactics.BV.bv_tac",
"Prims.unit"
] | [] | true | false | true | false | false | let lemma_bytes_and_mod5 x =
| assert_by_tactic (logand #64 x (0x10000000000 - 1) == mod #64 x 0x10000000000) bv_tac | false |
Vale.Poly1305.Bitvectors.fst | Vale.Poly1305.Bitvectors.lemma_bytes_and_mod6 | val lemma_bytes_and_mod6: x: uint_t 64 ->
Lemma (logand #64 x (0x1000000000000 - 1) == mod #64 x 0x1000000000000) | val lemma_bytes_and_mod6: x: uint_t 64 ->
Lemma (logand #64 x (0x1000000000000 - 1) == mod #64 x 0x1000000000000) | let lemma_bytes_and_mod6 x =
assert_by_tactic (logand #64 x (0x1000000000000 - 1) == mod #64 x 0x1000000000000) bv_tac | {
"file_name": "vale/code/crypto/poly1305/x64/Vale.Poly1305.Bitvectors.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 91,
"end_line": 211,
"start_col": 0,
"start_line": 210
} | module Vale.Poly1305.Bitvectors
open FStar.BV
open FStar.Tactics
open FStar.Tactics.Derived
open FStar.Tactics.BV
open FStar.Mul
open FStar.UInt
open FStar.Math.Lemmas
open Vale.Lib.Tactics
open Vale.Lib.Bv_s
open Vale.Math.Bits
// tweak options?
#reset-options "--smtencoding.elim_box true"
//NOTE: Using the split tactic seems to slowdown execution by a lot.
let lemma_shr2 x =
assert_by_tactic (shift_right #64 x 2 == udiv #64 x 4) bv_tac
let lemma_shr4 x =
assert_by_tactic (shift_right #64 x 4 == udiv #64 x 16) bv_tac
let lemma_and_mod_n x =
assert_by_tactic (logand #64 x 3 == mod #64 x 4) (bv_tac);
assert_by_tactic (logand #64 x 15 == mod #64 x 16) (bv_tac)
let lemma_clear_lower_2 x =
assert_by_tactic
(logand #64 x 0xfffffffffffffffc == mul_mod #64 (udiv #64 x 4) 4)
bv_tac
let lemma_and_constants x =
assert_by_tactic (logand #64 x 0 == (0 <: uint_t 64)) bv_tac;
assert_by_tactic (logand #64 x 0xffffffffffffffff == x) bv_tac
let lemma_poly_constants x =
// using split in this seems to hang execution.
assert_by_tactic
(logand #64 x 0x0ffffffc0fffffff < (0x1000000000000000 <: uint_t 64))
(fun () -> bv_tac_lt 64);
assert_by_tactic
(logand #64 x 0x0ffffffc0ffffffc < (0x1000000000000000 <: uint_t 64))
(fun () -> bv_tac_lt 64);
assert_by_tactic
(mod #64 (logand #64 x 0x0ffffffc0ffffffc) 4 == (0 <: uint_t 64))
(fun () -> bv_tac ())
let lemma_and_commutes x y =
assert_by_tactic
(logand #64 x y == logand #64 y x)
bv_tac
let lemma_bv128_64_64_and_helper' (x0:bv_t 64) (x1:bv_t 64) (y0:bv_t 64) (y1:bv_t 64) :
Lemma (requires True)
(ensures ((bvor #128 (bvshl #128 (bv_uext #64 #64 (bvand #64 x1 y1)) 64)
(bv_uext #64 #64 (bvand #64 x0 y0))) ==
bvand #128 (bvor #128 (bvshl #128 (bv_uext #64 #64 x1) 64)
(bv_uext #64 #64 x0))
(bvor #128 (bvshl #128 (bv_uext #64 #64 y1) 64)
(bv_uext #64 #64 y0)))) = ()
// Rewrite all equalities and then the goal is trivial for Z3.
// Without rewriting this does not go through.
// I believe the reason is related to a previously reported issue with the way
// Z3 bit-blasts through the Boxing/Unboxing functions. I thought this was fixed
// but it may not be the case. Notice that by rewriting with tactics the solver
// only gets to see one big term without any boxing or unboxing inside it.
let lemma_bv128_64_64_and_helper x x0 x1 y y0 y1 z z0 z1 =
lemma_bv128_64_64_and_helper' x0 x1 y0 y1;
assert_by_tactic (z == bvand #128 x y)
(fun () -> destruct_conj ();
rewrite_eqs_from_context ())
let bv128_64_64 x0 x1 = bvor (bvshl (bv_uext #64 #64 x1) 64) (bv_uext #64 #64 x0)
unfold let uint_to_nat (#n:nat) (x:uint_t n) : r:nat{r = x} =
assert (x < pow2 n);
modulo_lemma x (pow2 n);
x
let uint_ext (#n : nat) (#m : nat{n <= m}) (x : uint_t n) : r:(uint_t m){uint_to_nat r = uint_to_nat x} =
assert_norm(fits x n);
pow2_le_compat m n;
assert_norm(fits x m);
modulo_lemma x (pow2 m);
to_uint_t m x
#reset-options "--smtencoding.elim_box true --smtencoding.l_arith_repr boxwrap --smtencoding.nl_arith_repr boxwrap"
let mul_bvshl (u:uint_t 64) :
Lemma (0x10000000000000000 * u < pow2 128 /\
(int2bv #128 (0x10000000000000000 * u) ==
bvshl (bv_uext #64 #64 (int2bv u)) 64)) =
assert_norm ( 0x10000000000000000 * pow2 63 < pow2 128);
modulo_lemma (0x10000000000000000 * u) (pow2 128);
assert_by_tactic
(int2bv #128 (mul_mod #128 0x10000000000000000 (uint_ext #64 #128 u)) ==
bvmul #128 (int2bv #128 0x10000000000000000) (uint_ext #64 #128 u))
(fun () -> mapply (`trans); arith_to_bv_tac (); trefl ())
#reset-options "--smtencoding.elim_box true"
let plus_bvor (u h:bv_t 128) :
Lemma (bvand u h = bv_zero ==> bvadd u h == bvor u h) = ()
let lemma_bv128_64_64_and x x0 x1 y y0 y1 z z0 z1 =
assert_by_tactic (z == bvand #128 x y)
(fun () -> destruct_conj ();
rewrite_eqs_from_context ();
norm[delta])
#reset-options "--smtencoding.elim_box true --z3refresh --z3rlimit 20 --max_ifuel 1 --max_fuel 1"
let int2bv_uext_64_128 (x1 : nat) :
Lemma (requires (FStar.UInt.size x1 64))
(ensures (bv_uext #64 #64 (int2bv #64 x1) == int2bv #128 x1)) =
assert (64 <= 128);
pow2_le_compat 128 64;
assert (x1 < pow2 128);
modulo_lemma x1 (pow2 128); // x1 % pow2 128 = x1
assert (FStar.UInt.size x1 128);
assert_by_tactic (bv_uext #64 #64 (int2bv #64 x1) == int2bv #128 x1)
(fun () -> dump "..";
norm[delta_only [`%uint_ext; `%FStar.UInt.to_uint_t]];
// grewrite (quote (x1 % pow2 128)) (quote x1);
dump "After norm"; smt ())
#reset-options "--smtencoding.l_arith_repr native --smtencoding.nl_arith_repr wrapped --smtencoding.elim_box true --z3cliopt smt.arith.nl=false --max_fuel 1 --max_ifuel 0"
let lowerUpper128m (l:uint_t 64) (u:uint_t 64) : uint_t 128 =
add_hide #128 (mul_hide #128 (uext #64 #64 u) 0x10000000000000000) (uext #64 #64 l)
let lowerUpper128b (l:bv_t 64) (u:bv_t 64) : bv_t 128 =
b_add #128 (b_mul #128 (b_uext #64 #64 u) 0x10000000000000000) (b_uext #64 #64 l)
//this was so flaky, new options helped.
#reset-options "--smtencoding.elim_box true --z3refresh --z3rlimit 40 --max_ifuel 1 --max_fuel 1"
let lemma_lowerUpper128_andu
(x:uint_t 128) (x0:uint_t 64) (x1:uint_t 64) (y:uint_t 128)
(y0:uint_t 64) (y1:uint_t 64) (z:uint_t 128) (z0:uint_t 64) (z1:uint_t 64) :
Lemma
(requires
z0 == logand #64 x0 y0 /\
z1 == logand #64 x1 y1 /\
x == lowerUpper128u x0 x1 /\
y == lowerUpper128u y0 y1 /\
z == lowerUpper128u z0 z1)
(ensures z == logand #128 x y)
=
let bx0 = b_i2b x0 in
let bx1 = b_i2b x1 in
let by0 = b_i2b y0 in
let by1 = b_i2b y1 in
assert_norm (
lowerUpper128b (b_and bx0 by0) (b_and bx1 by1) ==
b_and (lowerUpper128b bx0 bx1) (lowerUpper128b by0 by1));
lemma_i2b_equal
(lowerUpper128m (logand x0 y0) (logand x1 y1))
(logand (lowerUpper128m x0 x1) (lowerUpper128m y0 y1));
assert_norm (lowerUpper128m x0 x1 == lowerUpper128u x0 x1);
assert_norm (lowerUpper128m y0 y1 == lowerUpper128u y0 y1);
assert_norm (lowerUpper128m z0 z1 == lowerUpper128u z0 z1);
()
#reset-options "--smtencoding.elim_box true --z3cliopt smt.case_split=3"
let lemma_bytes_shift_constants0 x =
assert_by_tactic (shift_left #64 0 3 == (0 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 0 == (0x1 <: uint_t 64)) bv_tac
let lemma_bytes_shift_constants1 x =
assert_by_tactic (shift_left #64 1 3 == (8 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 8 == (0x100 <: uint_t 64)) bv_tac
let lemma_bytes_shift_constants2 x =
assert_by_tactic (shift_left #64 2 3 == (16 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 16 == (0x10000 <: uint_t 64)) bv_tac
let lemma_bytes_shift_constants3 x =
assert_by_tactic (shift_left #64 3 3 == (24 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 24 == (0x1000000 <: uint_t 64)) bv_tac
let lemma_bytes_shift_constants4 x =
assert_by_tactic (shift_left #64 4 3 == (32 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 32 == (0x100000000 <: uint_t 64)) bv_tac
let lemma_bytes_shift_constants5 x =
assert_by_tactic (shift_left #64 5 3 == (40 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 40 == (0x10000000000 <: uint_t 64)) bv_tac
let lemma_bytes_shift_constants6 x =
assert_by_tactic (shift_left #64 6 3 == (48 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 48 == (0x1000000000000 <: uint_t 64)) bv_tac
let lemma_bytes_shift_constants7 x =
assert_by_tactic (shift_left #64 7 3 == (56 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 56 == (0x100000000000000 <: uint_t 64)) bv_tac
let lemma_bytes_and_mod0 x =
assert_by_tactic (logand #64 x (0x1 - 1) == mod #64 x 0x1) bv_tac
let lemma_bytes_and_mod1 x =
assert_by_tactic (logand #64 x (0x100 - 1) == mod #64 x 0x100) bv_tac
let lemma_bytes_and_mod2 x =
assert_by_tactic (logand #64 x (0x10000 - 1) == mod #64 x 0x10000) bv_tac
let lemma_bytes_and_mod3 x =
assert_by_tactic (logand #64 x (0x1000000 - 1) == mod #64 x 0x1000000) bv_tac
let lemma_bytes_and_mod4 x =
assert_by_tactic (logand #64 x (0x100000000 - 1) == mod #64 x 0x100000000) bv_tac
let lemma_bytes_and_mod5 x =
assert_by_tactic (logand #64 x (0x10000000000 - 1) == mod #64 x 0x10000000000) bv_tac | {
"checked_file": "/",
"dependencies": [
"Vale.Math.Bits.fsti.checked",
"Vale.Lib.Tactics.fst.checked",
"Vale.Lib.Bv_s.fst.checked",
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Tactics.Derived.fst.checked",
"FStar.Tactics.BV.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.BV.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Poly1305.Bitvectors.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Math.Bits",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Bv_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3",
"smt.case_split=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: FStar.UInt.uint_t 64
-> FStar.Pervasives.Lemma
(ensures FStar.UInt.logand x (0x1000000000000 - 1) == FStar.UInt.mod x 0x1000000000000) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.UInt.uint_t",
"FStar.Tactics.Effect.assert_by_tactic",
"Prims.eq2",
"FStar.UInt.logand",
"Prims.op_Subtraction",
"FStar.UInt.mod",
"FStar.Tactics.BV.bv_tac",
"Prims.unit"
] | [] | true | false | true | false | false | let lemma_bytes_and_mod6 x =
| assert_by_tactic (logand #64 x (0x1000000000000 - 1) == mod #64 x 0x1000000000000) bv_tac | false |
Vale.Poly1305.Bitvectors.fst | Vale.Poly1305.Bitvectors.lemma_bytes_and_mod3 | val lemma_bytes_and_mod3: x: uint_t 64 ->
Lemma (logand #64 x (0x1000000 - 1) == mod #64 x 0x1000000) | val lemma_bytes_and_mod3: x: uint_t 64 ->
Lemma (logand #64 x (0x1000000 - 1) == mod #64 x 0x1000000) | let lemma_bytes_and_mod3 x =
assert_by_tactic (logand #64 x (0x1000000 - 1) == mod #64 x 0x1000000) bv_tac | {
"file_name": "vale/code/crypto/poly1305/x64/Vale.Poly1305.Bitvectors.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 79,
"end_line": 202,
"start_col": 0,
"start_line": 201
} | module Vale.Poly1305.Bitvectors
open FStar.BV
open FStar.Tactics
open FStar.Tactics.Derived
open FStar.Tactics.BV
open FStar.Mul
open FStar.UInt
open FStar.Math.Lemmas
open Vale.Lib.Tactics
open Vale.Lib.Bv_s
open Vale.Math.Bits
// tweak options?
#reset-options "--smtencoding.elim_box true"
//NOTE: Using the split tactic seems to slowdown execution by a lot.
let lemma_shr2 x =
assert_by_tactic (shift_right #64 x 2 == udiv #64 x 4) bv_tac
let lemma_shr4 x =
assert_by_tactic (shift_right #64 x 4 == udiv #64 x 16) bv_tac
let lemma_and_mod_n x =
assert_by_tactic (logand #64 x 3 == mod #64 x 4) (bv_tac);
assert_by_tactic (logand #64 x 15 == mod #64 x 16) (bv_tac)
let lemma_clear_lower_2 x =
assert_by_tactic
(logand #64 x 0xfffffffffffffffc == mul_mod #64 (udiv #64 x 4) 4)
bv_tac
let lemma_and_constants x =
assert_by_tactic (logand #64 x 0 == (0 <: uint_t 64)) bv_tac;
assert_by_tactic (logand #64 x 0xffffffffffffffff == x) bv_tac
let lemma_poly_constants x =
// using split in this seems to hang execution.
assert_by_tactic
(logand #64 x 0x0ffffffc0fffffff < (0x1000000000000000 <: uint_t 64))
(fun () -> bv_tac_lt 64);
assert_by_tactic
(logand #64 x 0x0ffffffc0ffffffc < (0x1000000000000000 <: uint_t 64))
(fun () -> bv_tac_lt 64);
assert_by_tactic
(mod #64 (logand #64 x 0x0ffffffc0ffffffc) 4 == (0 <: uint_t 64))
(fun () -> bv_tac ())
let lemma_and_commutes x y =
assert_by_tactic
(logand #64 x y == logand #64 y x)
bv_tac
let lemma_bv128_64_64_and_helper' (x0:bv_t 64) (x1:bv_t 64) (y0:bv_t 64) (y1:bv_t 64) :
Lemma (requires True)
(ensures ((bvor #128 (bvshl #128 (bv_uext #64 #64 (bvand #64 x1 y1)) 64)
(bv_uext #64 #64 (bvand #64 x0 y0))) ==
bvand #128 (bvor #128 (bvshl #128 (bv_uext #64 #64 x1) 64)
(bv_uext #64 #64 x0))
(bvor #128 (bvshl #128 (bv_uext #64 #64 y1) 64)
(bv_uext #64 #64 y0)))) = ()
// Rewrite all equalities and then the goal is trivial for Z3.
// Without rewriting this does not go through.
// I believe the reason is related to a previously reported issue with the way
// Z3 bit-blasts through the Boxing/Unboxing functions. I thought this was fixed
// but it may not be the case. Notice that by rewriting with tactics the solver
// only gets to see one big term without any boxing or unboxing inside it.
let lemma_bv128_64_64_and_helper x x0 x1 y y0 y1 z z0 z1 =
lemma_bv128_64_64_and_helper' x0 x1 y0 y1;
assert_by_tactic (z == bvand #128 x y)
(fun () -> destruct_conj ();
rewrite_eqs_from_context ())
let bv128_64_64 x0 x1 = bvor (bvshl (bv_uext #64 #64 x1) 64) (bv_uext #64 #64 x0)
unfold let uint_to_nat (#n:nat) (x:uint_t n) : r:nat{r = x} =
assert (x < pow2 n);
modulo_lemma x (pow2 n);
x
let uint_ext (#n : nat) (#m : nat{n <= m}) (x : uint_t n) : r:(uint_t m){uint_to_nat r = uint_to_nat x} =
assert_norm(fits x n);
pow2_le_compat m n;
assert_norm(fits x m);
modulo_lemma x (pow2 m);
to_uint_t m x
#reset-options "--smtencoding.elim_box true --smtencoding.l_arith_repr boxwrap --smtencoding.nl_arith_repr boxwrap"
let mul_bvshl (u:uint_t 64) :
Lemma (0x10000000000000000 * u < pow2 128 /\
(int2bv #128 (0x10000000000000000 * u) ==
bvshl (bv_uext #64 #64 (int2bv u)) 64)) =
assert_norm ( 0x10000000000000000 * pow2 63 < pow2 128);
modulo_lemma (0x10000000000000000 * u) (pow2 128);
assert_by_tactic
(int2bv #128 (mul_mod #128 0x10000000000000000 (uint_ext #64 #128 u)) ==
bvmul #128 (int2bv #128 0x10000000000000000) (uint_ext #64 #128 u))
(fun () -> mapply (`trans); arith_to_bv_tac (); trefl ())
#reset-options "--smtencoding.elim_box true"
let plus_bvor (u h:bv_t 128) :
Lemma (bvand u h = bv_zero ==> bvadd u h == bvor u h) = ()
let lemma_bv128_64_64_and x x0 x1 y y0 y1 z z0 z1 =
assert_by_tactic (z == bvand #128 x y)
(fun () -> destruct_conj ();
rewrite_eqs_from_context ();
norm[delta])
#reset-options "--smtencoding.elim_box true --z3refresh --z3rlimit 20 --max_ifuel 1 --max_fuel 1"
let int2bv_uext_64_128 (x1 : nat) :
Lemma (requires (FStar.UInt.size x1 64))
(ensures (bv_uext #64 #64 (int2bv #64 x1) == int2bv #128 x1)) =
assert (64 <= 128);
pow2_le_compat 128 64;
assert (x1 < pow2 128);
modulo_lemma x1 (pow2 128); // x1 % pow2 128 = x1
assert (FStar.UInt.size x1 128);
assert_by_tactic (bv_uext #64 #64 (int2bv #64 x1) == int2bv #128 x1)
(fun () -> dump "..";
norm[delta_only [`%uint_ext; `%FStar.UInt.to_uint_t]];
// grewrite (quote (x1 % pow2 128)) (quote x1);
dump "After norm"; smt ())
#reset-options "--smtencoding.l_arith_repr native --smtencoding.nl_arith_repr wrapped --smtencoding.elim_box true --z3cliopt smt.arith.nl=false --max_fuel 1 --max_ifuel 0"
let lowerUpper128m (l:uint_t 64) (u:uint_t 64) : uint_t 128 =
add_hide #128 (mul_hide #128 (uext #64 #64 u) 0x10000000000000000) (uext #64 #64 l)
let lowerUpper128b (l:bv_t 64) (u:bv_t 64) : bv_t 128 =
b_add #128 (b_mul #128 (b_uext #64 #64 u) 0x10000000000000000) (b_uext #64 #64 l)
//this was so flaky, new options helped.
#reset-options "--smtencoding.elim_box true --z3refresh --z3rlimit 40 --max_ifuel 1 --max_fuel 1"
let lemma_lowerUpper128_andu
(x:uint_t 128) (x0:uint_t 64) (x1:uint_t 64) (y:uint_t 128)
(y0:uint_t 64) (y1:uint_t 64) (z:uint_t 128) (z0:uint_t 64) (z1:uint_t 64) :
Lemma
(requires
z0 == logand #64 x0 y0 /\
z1 == logand #64 x1 y1 /\
x == lowerUpper128u x0 x1 /\
y == lowerUpper128u y0 y1 /\
z == lowerUpper128u z0 z1)
(ensures z == logand #128 x y)
=
let bx0 = b_i2b x0 in
let bx1 = b_i2b x1 in
let by0 = b_i2b y0 in
let by1 = b_i2b y1 in
assert_norm (
lowerUpper128b (b_and bx0 by0) (b_and bx1 by1) ==
b_and (lowerUpper128b bx0 bx1) (lowerUpper128b by0 by1));
lemma_i2b_equal
(lowerUpper128m (logand x0 y0) (logand x1 y1))
(logand (lowerUpper128m x0 x1) (lowerUpper128m y0 y1));
assert_norm (lowerUpper128m x0 x1 == lowerUpper128u x0 x1);
assert_norm (lowerUpper128m y0 y1 == lowerUpper128u y0 y1);
assert_norm (lowerUpper128m z0 z1 == lowerUpper128u z0 z1);
()
#reset-options "--smtencoding.elim_box true --z3cliopt smt.case_split=3"
let lemma_bytes_shift_constants0 x =
assert_by_tactic (shift_left #64 0 3 == (0 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 0 == (0x1 <: uint_t 64)) bv_tac
let lemma_bytes_shift_constants1 x =
assert_by_tactic (shift_left #64 1 3 == (8 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 8 == (0x100 <: uint_t 64)) bv_tac
let lemma_bytes_shift_constants2 x =
assert_by_tactic (shift_left #64 2 3 == (16 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 16 == (0x10000 <: uint_t 64)) bv_tac
let lemma_bytes_shift_constants3 x =
assert_by_tactic (shift_left #64 3 3 == (24 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 24 == (0x1000000 <: uint_t 64)) bv_tac
let lemma_bytes_shift_constants4 x =
assert_by_tactic (shift_left #64 4 3 == (32 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 32 == (0x100000000 <: uint_t 64)) bv_tac
let lemma_bytes_shift_constants5 x =
assert_by_tactic (shift_left #64 5 3 == (40 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 40 == (0x10000000000 <: uint_t 64)) bv_tac
let lemma_bytes_shift_constants6 x =
assert_by_tactic (shift_left #64 6 3 == (48 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 48 == (0x1000000000000 <: uint_t 64)) bv_tac
let lemma_bytes_shift_constants7 x =
assert_by_tactic (shift_left #64 7 3 == (56 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 56 == (0x100000000000000 <: uint_t 64)) bv_tac
let lemma_bytes_and_mod0 x =
assert_by_tactic (logand #64 x (0x1 - 1) == mod #64 x 0x1) bv_tac
let lemma_bytes_and_mod1 x =
assert_by_tactic (logand #64 x (0x100 - 1) == mod #64 x 0x100) bv_tac
let lemma_bytes_and_mod2 x = | {
"checked_file": "/",
"dependencies": [
"Vale.Math.Bits.fsti.checked",
"Vale.Lib.Tactics.fst.checked",
"Vale.Lib.Bv_s.fst.checked",
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Tactics.Derived.fst.checked",
"FStar.Tactics.BV.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.BV.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Poly1305.Bitvectors.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Math.Bits",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Bv_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3",
"smt.case_split=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: FStar.UInt.uint_t 64
-> FStar.Pervasives.Lemma
(ensures FStar.UInt.logand x (0x1000000 - 1) == FStar.UInt.mod x 0x1000000) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.UInt.uint_t",
"FStar.Tactics.Effect.assert_by_tactic",
"Prims.eq2",
"FStar.UInt.logand",
"Prims.op_Subtraction",
"FStar.UInt.mod",
"FStar.Tactics.BV.bv_tac",
"Prims.unit"
] | [] | true | false | true | false | false | let lemma_bytes_and_mod3 x =
| assert_by_tactic (logand #64 x (0x1000000 - 1) == mod #64 x 0x1000000) bv_tac | false |
Vale.Poly1305.Bitvectors.fst | Vale.Poly1305.Bitvectors.mul_bvshl | val mul_bvshl (u: uint_t 64)
: Lemma
(0x10000000000000000 * u < pow2 128 /\
(int2bv #128 (0x10000000000000000 * u) == bvshl (bv_uext #64 #64 (int2bv u)) 64)) | val mul_bvshl (u: uint_t 64)
: Lemma
(0x10000000000000000 * u < pow2 128 /\
(int2bv #128 (0x10000000000000000 * u) == bvshl (bv_uext #64 #64 (int2bv u)) 64)) | let mul_bvshl (u:uint_t 64) :
Lemma (0x10000000000000000 * u < pow2 128 /\
(int2bv #128 (0x10000000000000000 * u) ==
bvshl (bv_uext #64 #64 (int2bv u)) 64)) =
assert_norm ( 0x10000000000000000 * pow2 63 < pow2 128);
modulo_lemma (0x10000000000000000 * u) (pow2 128);
assert_by_tactic
(int2bv #128 (mul_mod #128 0x10000000000000000 (uint_ext #64 #128 u)) ==
bvmul #128 (int2bv #128 0x10000000000000000) (uint_ext #64 #128 u))
(fun () -> mapply (`trans); arith_to_bv_tac (); trefl ()) | {
"file_name": "vale/code/crypto/poly1305/x64/Vale.Poly1305.Bitvectors.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 61,
"end_line": 101,
"start_col": 0,
"start_line": 92
} | module Vale.Poly1305.Bitvectors
open FStar.BV
open FStar.Tactics
open FStar.Tactics.Derived
open FStar.Tactics.BV
open FStar.Mul
open FStar.UInt
open FStar.Math.Lemmas
open Vale.Lib.Tactics
open Vale.Lib.Bv_s
open Vale.Math.Bits
// tweak options?
#reset-options "--smtencoding.elim_box true"
//NOTE: Using the split tactic seems to slowdown execution by a lot.
let lemma_shr2 x =
assert_by_tactic (shift_right #64 x 2 == udiv #64 x 4) bv_tac
let lemma_shr4 x =
assert_by_tactic (shift_right #64 x 4 == udiv #64 x 16) bv_tac
let lemma_and_mod_n x =
assert_by_tactic (logand #64 x 3 == mod #64 x 4) (bv_tac);
assert_by_tactic (logand #64 x 15 == mod #64 x 16) (bv_tac)
let lemma_clear_lower_2 x =
assert_by_tactic
(logand #64 x 0xfffffffffffffffc == mul_mod #64 (udiv #64 x 4) 4)
bv_tac
let lemma_and_constants x =
assert_by_tactic (logand #64 x 0 == (0 <: uint_t 64)) bv_tac;
assert_by_tactic (logand #64 x 0xffffffffffffffff == x) bv_tac
let lemma_poly_constants x =
// using split in this seems to hang execution.
assert_by_tactic
(logand #64 x 0x0ffffffc0fffffff < (0x1000000000000000 <: uint_t 64))
(fun () -> bv_tac_lt 64);
assert_by_tactic
(logand #64 x 0x0ffffffc0ffffffc < (0x1000000000000000 <: uint_t 64))
(fun () -> bv_tac_lt 64);
assert_by_tactic
(mod #64 (logand #64 x 0x0ffffffc0ffffffc) 4 == (0 <: uint_t 64))
(fun () -> bv_tac ())
let lemma_and_commutes x y =
assert_by_tactic
(logand #64 x y == logand #64 y x)
bv_tac
let lemma_bv128_64_64_and_helper' (x0:bv_t 64) (x1:bv_t 64) (y0:bv_t 64) (y1:bv_t 64) :
Lemma (requires True)
(ensures ((bvor #128 (bvshl #128 (bv_uext #64 #64 (bvand #64 x1 y1)) 64)
(bv_uext #64 #64 (bvand #64 x0 y0))) ==
bvand #128 (bvor #128 (bvshl #128 (bv_uext #64 #64 x1) 64)
(bv_uext #64 #64 x0))
(bvor #128 (bvshl #128 (bv_uext #64 #64 y1) 64)
(bv_uext #64 #64 y0)))) = ()
// Rewrite all equalities and then the goal is trivial for Z3.
// Without rewriting this does not go through.
// I believe the reason is related to a previously reported issue with the way
// Z3 bit-blasts through the Boxing/Unboxing functions. I thought this was fixed
// but it may not be the case. Notice that by rewriting with tactics the solver
// only gets to see one big term without any boxing or unboxing inside it.
let lemma_bv128_64_64_and_helper x x0 x1 y y0 y1 z z0 z1 =
lemma_bv128_64_64_and_helper' x0 x1 y0 y1;
assert_by_tactic (z == bvand #128 x y)
(fun () -> destruct_conj ();
rewrite_eqs_from_context ())
let bv128_64_64 x0 x1 = bvor (bvshl (bv_uext #64 #64 x1) 64) (bv_uext #64 #64 x0)
unfold let uint_to_nat (#n:nat) (x:uint_t n) : r:nat{r = x} =
assert (x < pow2 n);
modulo_lemma x (pow2 n);
x
let uint_ext (#n : nat) (#m : nat{n <= m}) (x : uint_t n) : r:(uint_t m){uint_to_nat r = uint_to_nat x} =
assert_norm(fits x n);
pow2_le_compat m n;
assert_norm(fits x m);
modulo_lemma x (pow2 m);
to_uint_t m x | {
"checked_file": "/",
"dependencies": [
"Vale.Math.Bits.fsti.checked",
"Vale.Lib.Tactics.fst.checked",
"Vale.Lib.Bv_s.fst.checked",
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Tactics.Derived.fst.checked",
"FStar.Tactics.BV.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.BV.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Poly1305.Bitvectors.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Math.Bits",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Bv_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | u99: FStar.UInt.uint_t 64
-> FStar.Pervasives.Lemma
(ensures
0x10000000000000000 * u99 < Prims.pow2 128 /\
FStar.BV.int2bv (0x10000000000000000 * u99) ==
FStar.BV.bvshl (FStar.BV.bv_uext (FStar.BV.int2bv u99)) 64) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.UInt.uint_t",
"FStar.Tactics.Effect.assert_by_tactic",
"Prims.eq2",
"FStar.BV.bv_t",
"FStar.BV.int2bv",
"FStar.UInt.mul_mod",
"Vale.Poly1305.Bitvectors.uint_ext",
"FStar.BV.bvmul",
"Prims.unit",
"FStar.Tactics.V1.Derived.trefl",
"FStar.Tactics.BV.arith_to_bv_tac",
"FStar.Tactics.V1.Derived.mapply",
"FStar.Math.Lemmas.modulo_lemma",
"FStar.Mul.op_Star",
"Prims.pow2",
"FStar.Pervasives.assert_norm",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.l_True",
"Prims.squash",
"Prims.l_and",
"FStar.BV.bvshl",
"FStar.BV.bv_uext",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let mul_bvshl (u: uint_t 64)
: Lemma
(0x10000000000000000 * u < pow2 128 /\
(int2bv #128 (0x10000000000000000 * u) == bvshl (bv_uext #64 #64 (int2bv u)) 64)) =
| assert_norm (0x10000000000000000 * pow2 63 < pow2 128);
modulo_lemma (0x10000000000000000 * u) (pow2 128);
assert_by_tactic (int2bv #128 (mul_mod #128 0x10000000000000000 (uint_ext #64 #128 u)) ==
bvmul #128 (int2bv #128 0x10000000000000000) (uint_ext #64 #128 u))
(fun () ->
mapply (`trans);
arith_to_bv_tac ();
trefl ()) | false |
CQueue.fst | CQueue.elim_vbind | val elim_vbind (#opened: _) (a: vprop) (t: Type0) (b: (t_of a -> Tot vprop))
: SteelGhost (Ghost.erased (t_of a))
opened
(vbind a t b)
(fun res -> a `star` (b (Ghost.reveal res)))
(fun h -> True)
(fun h res h' ->
h' a == Ghost.reveal res /\ t == t_of (b (Ghost.reveal res)) /\
h' (b (Ghost.reveal res)) == h (vbind a t b)) | val elim_vbind (#opened: _) (a: vprop) (t: Type0) (b: (t_of a -> Tot vprop))
: SteelGhost (Ghost.erased (t_of a))
opened
(vbind a t b)
(fun res -> a `star` (b (Ghost.reveal res)))
(fun h -> True)
(fun h res h' ->
h' a == Ghost.reveal res /\ t == t_of (b (Ghost.reveal res)) /\
h' (b (Ghost.reveal res)) == h (vbind a t b)) | let elim_vbind
(#opened: _)
(a: vprop)
(t: Type0)
(b: (t_of a -> Tot vprop))
: SteelGhost (Ghost.erased (t_of a)) opened
(vbind a t b)
(fun res -> a `star` b (Ghost.reveal res))
(fun h -> True)
(fun h res h' ->
h' a == Ghost.reveal res /\
t == t_of (b (Ghost.reveal res)) /\
h' (b (Ghost.reveal res)) == h (vbind a t b)
)
=
change_slprop_rel
(vbind a t b)
(vbind0 a t b)
(fun x y -> x == y)
(fun _ -> ());
elim_vrewrite
(a `vdep` vbind0_payload a t b)
(vbind0_rewrite a t b);
let res = elim_vdep a (vbind0_payload a t b) in
change_equal_slprop
(vbind0_payload a t b (Ghost.reveal res))
(vpure (t == t_of (b (Ghost.reveal res))) `star` b (Ghost.reveal res));
elim_vpure (t == t_of (b (Ghost.reveal res)));
res | {
"file_name": "share/steel/examples/steel/CQueue.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 5,
"end_line": 277,
"start_col": 0,
"start_line": 249
} | module CQueue
open CQueue.LList
#set-options "--ide_id_info_off"
//Re-define squash, since this module explicitly
//replies on proving equalities of the form `t_of v == squash p`
//which are delicate in the presence of optimizations that
//unfold `Prims.squash (p /\ q)`to _:unit{p /\ q}
//See Issue #2496
let squash (p:Type u#a) : Type0 = squash p
(* BEGIN library *)
let intro_vrewrite_no_norm (#opened:inames)
(v: vprop) (#t: Type) (f: (t_of v) -> GTot t)
: SteelGhost unit opened v (fun _ -> vrewrite v f)
(fun _ -> True) (fun h _ h' -> h' (vrewrite v f) == f (h v))
=
intro_vrewrite v f
let elim_vrewrite_no_norm (#opened:inames)
(v: vprop)
(#t: Type)
(f: ((t_of v) -> GTot t))
: SteelGhost unit opened (vrewrite v f) (fun _ -> v)
(fun _ -> True)
(fun h _ h' -> h (vrewrite v f) == f (h' v))
=
elim_vrewrite v f
let vconst_sel
(#a: Type)
(x: a)
: Tot (selector a (hp_of emp))
= fun _ -> x
[@@ __steel_reduce__]
let vconst'
(#a: Type)
(x: a)
: GTot vprop'
= {
hp = hp_of emp;
t = a;
sel = vconst_sel x;
}
[@@ __steel_reduce__]
let vconst (#a: Type) (x: a) : Tot vprop = VUnit (vconst' x)
let intro_vconst
(#opened: _)
(#a: Type)
(x: a)
: SteelGhost unit opened
emp
(fun _ -> vconst x)
(fun _ -> True)
(fun _ _ h' -> h' (vconst x) == x)
=
change_slprop_rel
emp
(vconst x)
(fun _ y -> y == x)
(fun _ -> ())
let elim_vconst
(#opened: _)
(#a: Type)
(x: a)
: SteelGhost unit opened
(vconst x)
(fun _ -> emp)
(fun _ -> True)
(fun h _ _ -> h (vconst x) == x)
=
change_slprop_rel
(vconst x)
emp
(fun y _ -> y == x)
(fun _ -> ())
let vpure_sel'
(p: prop)
: Tot (selector' (squash p) (Steel.Memory.pure p))
= fun (m: Steel.Memory.hmem (Steel.Memory.pure p)) -> pure_interp p m
let vpure_sel
(p: prop)
: Tot (selector (squash p) (Steel.Memory.pure p))
= vpure_sel' p
[@@ __steel_reduce__]
let vpure'
(p: prop)
: GTot vprop'
= {
hp = Steel.Memory.pure p;
t = squash p;
sel = vpure_sel p;
}
[@@ __steel_reduce__]
let vpure (p: prop) : Tot vprop = VUnit (vpure' p)
let intro_vpure
(#opened: _)
(p: prop)
: SteelGhost unit opened
emp
(fun _ -> vpure p)
(fun _ -> p)
(fun _ _ h' -> p)
=
change_slprop_rel
emp
(vpure p)
(fun _ _ -> p)
(fun m -> pure_interp p m)
let elim_vpure
(#opened: _)
(p: prop)
: SteelGhost unit opened
(vpure p)
(fun _ -> emp)
(fun _ -> True)
(fun _ _ _ -> p)
=
change_slprop_rel
(vpure p)
emp
(fun _ _ -> p)
(fun m -> pure_interp p m; reveal_emp (); intro_emp m)
val intro_vdep2 (#opened:inames)
(v: vprop)
(q: vprop)
(x: t_of v)
(p: (t_of v -> Tot vprop))
: SteelGhost unit opened
(v `star` q)
(fun _ -> vdep v p)
(requires (fun h ->
q == p x /\
x == h v
))
(ensures (fun h _ h' ->
let x2 = h' (vdep v p) in
q == p (h v) /\
dfst x2 == (h v) /\
dsnd x2 == (h q)
))
let intro_vdep2
v q x p
=
intro_vdep v q p
let vbind0_payload
(a: vprop)
(t: Type0)
(b: (t_of a -> Tot vprop))
(x: t_of a)
: Tot vprop
= vpure (t == t_of (b x)) `star` b x
let vbind0_rewrite
(a: vprop)
(t: Type0)
(b: (t_of a -> Tot vprop))
(x: normal (t_of (vdep a (vbind0_payload a t b))))
: Tot t
= snd (dsnd x)
[@@__steel_reduce__; __reduce__]
let vbind0
(a: vprop)
(t: Type0)
(b: (t_of a -> Tot vprop))
: Tot vprop
= a `vdep` vbind0_payload a t b `vrewrite` vbind0_rewrite a t b
let vbind_hp // necessary to hide the attribute on hp_of
(a: vprop)
(t: Type0)
(b: (t_of a -> Tot vprop))
: Tot (slprop u#1)
= hp_of (vbind0 a t b)
let vbind_sel // same for hp_sel
(a: vprop)
(t: Type0)
(b: (t_of a -> Tot vprop))
: GTot (selector t (vbind_hp a t b))
= sel_of (vbind0 a t b)
[@@__steel_reduce__]
let vbind'
(a: vprop)
(t: Type0)
(b: (t_of a -> Tot vprop))
: GTot vprop'
= {
hp = vbind_hp a t b;
t = t;
sel = vbind_sel a t b;
}
[@@__steel_reduce__]
let vbind
(a: vprop)
(t: Type0)
(b: (t_of a -> Tot vprop))
: Tot vprop
= VUnit (vbind' a t b)
let intro_vbind
(#opened: _)
(a: vprop)
(b' : vprop)
(t: Type0)
(b: (t_of a -> Tot vprop))
: SteelGhost unit opened
(a `star` b')
(fun _ -> vbind a t b)
(fun h -> t_of b' == t /\ b' == b (h a))
(fun h _ h' ->
t_of b' == t /\
b' == b (h a) /\
h' (vbind a t b) == h b'
)
=
intro_vpure (t == t_of b');
intro_vdep
a
(vpure (t == t_of b') `star` b')
(vbind0_payload a t b);
intro_vrewrite
(a `vdep` vbind0_payload a t b)
(vbind0_rewrite a t b);
change_slprop_rel
(vbind0 a t b)
(vbind a t b)
(fun x y -> x == y)
(fun _ -> ()) | {
"checked_file": "/",
"dependencies": [
"Steel.Memory.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"CQueue.LList.fsti.checked"
],
"interface_file": true,
"source_file": "CQueue.fst"
} | [
{
"abbrev": false,
"full_module": "CQueue.LList",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"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": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
a: Steel.Effect.Common.vprop ->
t: Type0 ->
b: (_: Steel.Effect.Common.t_of a -> Steel.Effect.Common.vprop)
-> Steel.Effect.Atomic.SteelGhost (FStar.Ghost.erased (Steel.Effect.Common.t_of a)) | Steel.Effect.Atomic.SteelGhost | [] | [] | [
"Steel.Memory.inames",
"Steel.Effect.Common.vprop",
"Steel.Effect.Common.t_of",
"FStar.Ghost.erased",
"Prims.unit",
"CQueue.elim_vpure",
"Prims.eq2",
"FStar.Ghost.reveal",
"Steel.Effect.Atomic.change_equal_slprop",
"CQueue.vbind0_payload",
"Steel.Effect.Common.star",
"CQueue.vpure",
"Steel.Effect.Atomic.elim_vdep",
"Steel.Effect.Atomic.elim_vrewrite",
"Steel.Effect.Common.vdep",
"CQueue.vbind0_rewrite",
"Steel.Effect.Atomic.change_slprop_rel",
"CQueue.vbind",
"CQueue.vbind0",
"Steel.Effect.Common.normal",
"Prims.prop",
"Steel.Memory.mem",
"Steel.Effect.Common.rmem",
"Prims.l_True",
"Prims.l_and"
] | [] | false | true | false | false | false | let elim_vbind (#opened: _) (a: vprop) (t: Type0) (b: (t_of a -> Tot vprop))
: SteelGhost (Ghost.erased (t_of a))
opened
(vbind a t b)
(fun res -> a `star` (b (Ghost.reveal res)))
(fun h -> True)
(fun h res h' ->
h' a == Ghost.reveal res /\ t == t_of (b (Ghost.reveal res)) /\
h' (b (Ghost.reveal res)) == h (vbind a t b)) =
| change_slprop_rel (vbind a t b) (vbind0 a t b) (fun x y -> x == y) (fun _ -> ());
elim_vrewrite (a `vdep` (vbind0_payload a t b)) (vbind0_rewrite a t b);
let res = elim_vdep a (vbind0_payload a t b) in
change_equal_slprop (vbind0_payload a t b (Ghost.reveal res))
((vpure (t == t_of (b (Ghost.reveal res)))) `star` (b (Ghost.reveal res)));
elim_vpure (t == t_of (b (Ghost.reveal res)));
res | false |
Vale.Poly1305.Bitvectors.fst | Vale.Poly1305.Bitvectors.lemma_bytes_shift_constants0 | val lemma_bytes_shift_constants0: unit -> Lemma
(shift_left #64 0 3 == 0 /\
shift_left #64 1 (shift_left #64 0 3) == 0x1) | val lemma_bytes_shift_constants0: unit -> Lemma
(shift_left #64 0 3 == 0 /\
shift_left #64 1 (shift_left #64 0 3) == 0x1) | let lemma_bytes_shift_constants0 x =
assert_by_tactic (shift_left #64 0 3 == (0 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 0 == (0x1 <: uint_t 64)) bv_tac | {
"file_name": "vale/code/crypto/poly1305/x64/Vale.Poly1305.Bitvectors.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 68,
"end_line": 170,
"start_col": 0,
"start_line": 168
} | module Vale.Poly1305.Bitvectors
open FStar.BV
open FStar.Tactics
open FStar.Tactics.Derived
open FStar.Tactics.BV
open FStar.Mul
open FStar.UInt
open FStar.Math.Lemmas
open Vale.Lib.Tactics
open Vale.Lib.Bv_s
open Vale.Math.Bits
// tweak options?
#reset-options "--smtencoding.elim_box true"
//NOTE: Using the split tactic seems to slowdown execution by a lot.
let lemma_shr2 x =
assert_by_tactic (shift_right #64 x 2 == udiv #64 x 4) bv_tac
let lemma_shr4 x =
assert_by_tactic (shift_right #64 x 4 == udiv #64 x 16) bv_tac
let lemma_and_mod_n x =
assert_by_tactic (logand #64 x 3 == mod #64 x 4) (bv_tac);
assert_by_tactic (logand #64 x 15 == mod #64 x 16) (bv_tac)
let lemma_clear_lower_2 x =
assert_by_tactic
(logand #64 x 0xfffffffffffffffc == mul_mod #64 (udiv #64 x 4) 4)
bv_tac
let lemma_and_constants x =
assert_by_tactic (logand #64 x 0 == (0 <: uint_t 64)) bv_tac;
assert_by_tactic (logand #64 x 0xffffffffffffffff == x) bv_tac
let lemma_poly_constants x =
// using split in this seems to hang execution.
assert_by_tactic
(logand #64 x 0x0ffffffc0fffffff < (0x1000000000000000 <: uint_t 64))
(fun () -> bv_tac_lt 64);
assert_by_tactic
(logand #64 x 0x0ffffffc0ffffffc < (0x1000000000000000 <: uint_t 64))
(fun () -> bv_tac_lt 64);
assert_by_tactic
(mod #64 (logand #64 x 0x0ffffffc0ffffffc) 4 == (0 <: uint_t 64))
(fun () -> bv_tac ())
let lemma_and_commutes x y =
assert_by_tactic
(logand #64 x y == logand #64 y x)
bv_tac
let lemma_bv128_64_64_and_helper' (x0:bv_t 64) (x1:bv_t 64) (y0:bv_t 64) (y1:bv_t 64) :
Lemma (requires True)
(ensures ((bvor #128 (bvshl #128 (bv_uext #64 #64 (bvand #64 x1 y1)) 64)
(bv_uext #64 #64 (bvand #64 x0 y0))) ==
bvand #128 (bvor #128 (bvshl #128 (bv_uext #64 #64 x1) 64)
(bv_uext #64 #64 x0))
(bvor #128 (bvshl #128 (bv_uext #64 #64 y1) 64)
(bv_uext #64 #64 y0)))) = ()
// Rewrite all equalities and then the goal is trivial for Z3.
// Without rewriting this does not go through.
// I believe the reason is related to a previously reported issue with the way
// Z3 bit-blasts through the Boxing/Unboxing functions. I thought this was fixed
// but it may not be the case. Notice that by rewriting with tactics the solver
// only gets to see one big term without any boxing or unboxing inside it.
let lemma_bv128_64_64_and_helper x x0 x1 y y0 y1 z z0 z1 =
lemma_bv128_64_64_and_helper' x0 x1 y0 y1;
assert_by_tactic (z == bvand #128 x y)
(fun () -> destruct_conj ();
rewrite_eqs_from_context ())
let bv128_64_64 x0 x1 = bvor (bvshl (bv_uext #64 #64 x1) 64) (bv_uext #64 #64 x0)
unfold let uint_to_nat (#n:nat) (x:uint_t n) : r:nat{r = x} =
assert (x < pow2 n);
modulo_lemma x (pow2 n);
x
let uint_ext (#n : nat) (#m : nat{n <= m}) (x : uint_t n) : r:(uint_t m){uint_to_nat r = uint_to_nat x} =
assert_norm(fits x n);
pow2_le_compat m n;
assert_norm(fits x m);
modulo_lemma x (pow2 m);
to_uint_t m x
#reset-options "--smtencoding.elim_box true --smtencoding.l_arith_repr boxwrap --smtencoding.nl_arith_repr boxwrap"
let mul_bvshl (u:uint_t 64) :
Lemma (0x10000000000000000 * u < pow2 128 /\
(int2bv #128 (0x10000000000000000 * u) ==
bvshl (bv_uext #64 #64 (int2bv u)) 64)) =
assert_norm ( 0x10000000000000000 * pow2 63 < pow2 128);
modulo_lemma (0x10000000000000000 * u) (pow2 128);
assert_by_tactic
(int2bv #128 (mul_mod #128 0x10000000000000000 (uint_ext #64 #128 u)) ==
bvmul #128 (int2bv #128 0x10000000000000000) (uint_ext #64 #128 u))
(fun () -> mapply (`trans); arith_to_bv_tac (); trefl ())
#reset-options "--smtencoding.elim_box true"
let plus_bvor (u h:bv_t 128) :
Lemma (bvand u h = bv_zero ==> bvadd u h == bvor u h) = ()
let lemma_bv128_64_64_and x x0 x1 y y0 y1 z z0 z1 =
assert_by_tactic (z == bvand #128 x y)
(fun () -> destruct_conj ();
rewrite_eqs_from_context ();
norm[delta])
#reset-options "--smtencoding.elim_box true --z3refresh --z3rlimit 20 --max_ifuel 1 --max_fuel 1"
let int2bv_uext_64_128 (x1 : nat) :
Lemma (requires (FStar.UInt.size x1 64))
(ensures (bv_uext #64 #64 (int2bv #64 x1) == int2bv #128 x1)) =
assert (64 <= 128);
pow2_le_compat 128 64;
assert (x1 < pow2 128);
modulo_lemma x1 (pow2 128); // x1 % pow2 128 = x1
assert (FStar.UInt.size x1 128);
assert_by_tactic (bv_uext #64 #64 (int2bv #64 x1) == int2bv #128 x1)
(fun () -> dump "..";
norm[delta_only [`%uint_ext; `%FStar.UInt.to_uint_t]];
// grewrite (quote (x1 % pow2 128)) (quote x1);
dump "After norm"; smt ())
#reset-options "--smtencoding.l_arith_repr native --smtencoding.nl_arith_repr wrapped --smtencoding.elim_box true --z3cliopt smt.arith.nl=false --max_fuel 1 --max_ifuel 0"
let lowerUpper128m (l:uint_t 64) (u:uint_t 64) : uint_t 128 =
add_hide #128 (mul_hide #128 (uext #64 #64 u) 0x10000000000000000) (uext #64 #64 l)
let lowerUpper128b (l:bv_t 64) (u:bv_t 64) : bv_t 128 =
b_add #128 (b_mul #128 (b_uext #64 #64 u) 0x10000000000000000) (b_uext #64 #64 l)
//this was so flaky, new options helped.
#reset-options "--smtencoding.elim_box true --z3refresh --z3rlimit 40 --max_ifuel 1 --max_fuel 1"
let lemma_lowerUpper128_andu
(x:uint_t 128) (x0:uint_t 64) (x1:uint_t 64) (y:uint_t 128)
(y0:uint_t 64) (y1:uint_t 64) (z:uint_t 128) (z0:uint_t 64) (z1:uint_t 64) :
Lemma
(requires
z0 == logand #64 x0 y0 /\
z1 == logand #64 x1 y1 /\
x == lowerUpper128u x0 x1 /\
y == lowerUpper128u y0 y1 /\
z == lowerUpper128u z0 z1)
(ensures z == logand #128 x y)
=
let bx0 = b_i2b x0 in
let bx1 = b_i2b x1 in
let by0 = b_i2b y0 in
let by1 = b_i2b y1 in
assert_norm (
lowerUpper128b (b_and bx0 by0) (b_and bx1 by1) ==
b_and (lowerUpper128b bx0 bx1) (lowerUpper128b by0 by1));
lemma_i2b_equal
(lowerUpper128m (logand x0 y0) (logand x1 y1))
(logand (lowerUpper128m x0 x1) (lowerUpper128m y0 y1));
assert_norm (lowerUpper128m x0 x1 == lowerUpper128u x0 x1);
assert_norm (lowerUpper128m y0 y1 == lowerUpper128u y0 y1);
assert_norm (lowerUpper128m z0 z1 == lowerUpper128u z0 z1);
() | {
"checked_file": "/",
"dependencies": [
"Vale.Math.Bits.fsti.checked",
"Vale.Lib.Tactics.fst.checked",
"Vale.Lib.Bv_s.fst.checked",
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Tactics.Derived.fst.checked",
"FStar.Tactics.BV.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.BV.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Poly1305.Bitvectors.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Math.Bits",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Bv_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3",
"smt.case_split=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: Prims.unit
-> FStar.Pervasives.Lemma
(ensures
FStar.UInt.shift_left 0 3 == 0 /\ FStar.UInt.shift_left 1 (FStar.UInt.shift_left 0 3) == 0x1) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.unit",
"FStar.Tactics.Effect.assert_by_tactic",
"Prims.eq2",
"FStar.UInt.uint_t",
"FStar.UInt.shift_left",
"FStar.Tactics.BV.bv_tac"
] | [] | true | false | true | false | false | let lemma_bytes_shift_constants0 x =
| assert_by_tactic (shift_left #64 0 3 == (0 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 0 == (0x1 <: uint_t 64)) bv_tac | false |
Steel.Effect.Common.fst | Steel.Effect.Common.can_be_split | val can_be_split (p q:pre_t) : Type0 | val can_be_split (p q:pre_t) : Type0 | let can_be_split (p q:vprop) : prop = Mem.slimp (hp_of p) (hp_of q) | {
"file_name": "lib/steel/Steel.Effect.Common.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 67,
"end_line": 25,
"start_col": 0,
"start_line": 25
} | (*
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.Effect.Common
module Sem = Steel.Semantics.Hoare.MST
module Mem = Steel.Memory
open Steel.Semantics.Instantiate
module FExt = FStar.FunctionalExtensionality
let h_exists #a f = VUnit ({hp = Mem.h_exists (fun x -> hp_of (f x)); t = unit; sel = fun _ -> ()}) | {
"checked_file": "/",
"dependencies": [
"Steel.Semantics.Instantiate.fsti.checked",
"Steel.Semantics.Hoare.MST.fst.checked",
"Steel.Memory.fsti.checked",
"prims.fst.checked",
"FStar.PropositionalExtensionality.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Effect.Common.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "FExt"
},
{
"abbrev": false,
"full_module": "Steel.Semantics.Instantiate",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": true,
"full_module": "Steel.Semantics.Hoare.MST",
"short_module": "Sem"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "FExt"
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | p: Steel.Effect.Common.pre_t -> q: Steel.Effect.Common.pre_t -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Steel.Effect.Common.vprop",
"Steel.Memory.slimp",
"Steel.Effect.Common.hp_of",
"Prims.prop"
] | [] | false | false | false | true | true | let can_be_split (p q: vprop) : prop =
| Mem.slimp (hp_of p) (hp_of q) | false |
Vale.Poly1305.Bitvectors.fst | Vale.Poly1305.Bitvectors.int2bv_uext_64_128 | val int2bv_uext_64_128 (x1: nat)
: Lemma (requires (FStar.UInt.size x1 64))
(ensures (bv_uext #64 #64 (int2bv #64 x1) == int2bv #128 x1)) | val int2bv_uext_64_128 (x1: nat)
: Lemma (requires (FStar.UInt.size x1 64))
(ensures (bv_uext #64 #64 (int2bv #64 x1) == int2bv #128 x1)) | let int2bv_uext_64_128 (x1 : nat) :
Lemma (requires (FStar.UInt.size x1 64))
(ensures (bv_uext #64 #64 (int2bv #64 x1) == int2bv #128 x1)) =
assert (64 <= 128);
pow2_le_compat 128 64;
assert (x1 < pow2 128);
modulo_lemma x1 (pow2 128); // x1 % pow2 128 = x1
assert (FStar.UInt.size x1 128);
assert_by_tactic (bv_uext #64 #64 (int2bv #64 x1) == int2bv #128 x1)
(fun () -> dump "..";
norm[delta_only [`%uint_ext; `%FStar.UInt.to_uint_t]];
// grewrite (quote (x1 % pow2 128)) (quote x1);
dump "After norm"; smt ()) | {
"file_name": "vale/code/crypto/poly1305/x64/Vale.Poly1305.Bitvectors.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 42,
"end_line": 127,
"start_col": 0,
"start_line": 115
} | module Vale.Poly1305.Bitvectors
open FStar.BV
open FStar.Tactics
open FStar.Tactics.Derived
open FStar.Tactics.BV
open FStar.Mul
open FStar.UInt
open FStar.Math.Lemmas
open Vale.Lib.Tactics
open Vale.Lib.Bv_s
open Vale.Math.Bits
// tweak options?
#reset-options "--smtencoding.elim_box true"
//NOTE: Using the split tactic seems to slowdown execution by a lot.
let lemma_shr2 x =
assert_by_tactic (shift_right #64 x 2 == udiv #64 x 4) bv_tac
let lemma_shr4 x =
assert_by_tactic (shift_right #64 x 4 == udiv #64 x 16) bv_tac
let lemma_and_mod_n x =
assert_by_tactic (logand #64 x 3 == mod #64 x 4) (bv_tac);
assert_by_tactic (logand #64 x 15 == mod #64 x 16) (bv_tac)
let lemma_clear_lower_2 x =
assert_by_tactic
(logand #64 x 0xfffffffffffffffc == mul_mod #64 (udiv #64 x 4) 4)
bv_tac
let lemma_and_constants x =
assert_by_tactic (logand #64 x 0 == (0 <: uint_t 64)) bv_tac;
assert_by_tactic (logand #64 x 0xffffffffffffffff == x) bv_tac
let lemma_poly_constants x =
// using split in this seems to hang execution.
assert_by_tactic
(logand #64 x 0x0ffffffc0fffffff < (0x1000000000000000 <: uint_t 64))
(fun () -> bv_tac_lt 64);
assert_by_tactic
(logand #64 x 0x0ffffffc0ffffffc < (0x1000000000000000 <: uint_t 64))
(fun () -> bv_tac_lt 64);
assert_by_tactic
(mod #64 (logand #64 x 0x0ffffffc0ffffffc) 4 == (0 <: uint_t 64))
(fun () -> bv_tac ())
let lemma_and_commutes x y =
assert_by_tactic
(logand #64 x y == logand #64 y x)
bv_tac
let lemma_bv128_64_64_and_helper' (x0:bv_t 64) (x1:bv_t 64) (y0:bv_t 64) (y1:bv_t 64) :
Lemma (requires True)
(ensures ((bvor #128 (bvshl #128 (bv_uext #64 #64 (bvand #64 x1 y1)) 64)
(bv_uext #64 #64 (bvand #64 x0 y0))) ==
bvand #128 (bvor #128 (bvshl #128 (bv_uext #64 #64 x1) 64)
(bv_uext #64 #64 x0))
(bvor #128 (bvshl #128 (bv_uext #64 #64 y1) 64)
(bv_uext #64 #64 y0)))) = ()
// Rewrite all equalities and then the goal is trivial for Z3.
// Without rewriting this does not go through.
// I believe the reason is related to a previously reported issue with the way
// Z3 bit-blasts through the Boxing/Unboxing functions. I thought this was fixed
// but it may not be the case. Notice that by rewriting with tactics the solver
// only gets to see one big term without any boxing or unboxing inside it.
let lemma_bv128_64_64_and_helper x x0 x1 y y0 y1 z z0 z1 =
lemma_bv128_64_64_and_helper' x0 x1 y0 y1;
assert_by_tactic (z == bvand #128 x y)
(fun () -> destruct_conj ();
rewrite_eqs_from_context ())
let bv128_64_64 x0 x1 = bvor (bvshl (bv_uext #64 #64 x1) 64) (bv_uext #64 #64 x0)
unfold let uint_to_nat (#n:nat) (x:uint_t n) : r:nat{r = x} =
assert (x < pow2 n);
modulo_lemma x (pow2 n);
x
let uint_ext (#n : nat) (#m : nat{n <= m}) (x : uint_t n) : r:(uint_t m){uint_to_nat r = uint_to_nat x} =
assert_norm(fits x n);
pow2_le_compat m n;
assert_norm(fits x m);
modulo_lemma x (pow2 m);
to_uint_t m x
#reset-options "--smtencoding.elim_box true --smtencoding.l_arith_repr boxwrap --smtencoding.nl_arith_repr boxwrap"
let mul_bvshl (u:uint_t 64) :
Lemma (0x10000000000000000 * u < pow2 128 /\
(int2bv #128 (0x10000000000000000 * u) ==
bvshl (bv_uext #64 #64 (int2bv u)) 64)) =
assert_norm ( 0x10000000000000000 * pow2 63 < pow2 128);
modulo_lemma (0x10000000000000000 * u) (pow2 128);
assert_by_tactic
(int2bv #128 (mul_mod #128 0x10000000000000000 (uint_ext #64 #128 u)) ==
bvmul #128 (int2bv #128 0x10000000000000000) (uint_ext #64 #128 u))
(fun () -> mapply (`trans); arith_to_bv_tac (); trefl ())
#reset-options "--smtencoding.elim_box true"
let plus_bvor (u h:bv_t 128) :
Lemma (bvand u h = bv_zero ==> bvadd u h == bvor u h) = ()
let lemma_bv128_64_64_and x x0 x1 y y0 y1 z z0 z1 =
assert_by_tactic (z == bvand #128 x y)
(fun () -> destruct_conj ();
rewrite_eqs_from_context ();
norm[delta]) | {
"checked_file": "/",
"dependencies": [
"Vale.Math.Bits.fsti.checked",
"Vale.Lib.Tactics.fst.checked",
"Vale.Lib.Bv_s.fst.checked",
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Tactics.Derived.fst.checked",
"FStar.Tactics.BV.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.BV.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Poly1305.Bitvectors.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Math.Bits",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Bv_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": true,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x1: Prims.nat
-> FStar.Pervasives.Lemma (requires FStar.UInt.size x1 64)
(ensures FStar.BV.bv_uext (FStar.BV.int2bv x1) == FStar.BV.int2bv x1) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.nat",
"FStar.Tactics.Effect.assert_by_tactic",
"Prims.eq2",
"FStar.BV.bv_t",
"FStar.BV.bv_uext",
"FStar.BV.int2bv",
"Prims.unit",
"FStar.Tactics.V1.Derived.smt",
"FStar.Stubs.Tactics.V1.Builtins.dump",
"FStar.Stubs.Tactics.V1.Builtins.norm",
"Prims.Cons",
"FStar.Pervasives.norm_step",
"FStar.Pervasives.delta_only",
"Prims.string",
"Prims.Nil",
"Prims._assert",
"FStar.UInt.size",
"FStar.Math.Lemmas.modulo_lemma",
"Prims.pow2",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Math.Lemmas.pow2_le_compat",
"Prims.op_LessThanOrEqual",
"Prims.squash",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let int2bv_uext_64_128 (x1: nat)
: Lemma (requires (FStar.UInt.size x1 64))
(ensures (bv_uext #64 #64 (int2bv #64 x1) == int2bv #128 x1)) =
| assert (64 <= 128);
pow2_le_compat 128 64;
assert (x1 < pow2 128);
modulo_lemma x1 (pow2 128);
assert (FStar.UInt.size x1 128);
assert_by_tactic (bv_uext #64 #64 (int2bv #64 x1) == int2bv #128 x1)
(fun () ->
dump "..";
norm [delta_only [`%uint_ext; `%FStar.UInt.to_uint_t]];
dump "After norm";
smt ()) | false |
Vale.Poly1305.Bitvectors.fst | Vale.Poly1305.Bitvectors.lemma_lowerUpper128_andu | val lemma_lowerUpper128_andu : x:uint_t 128 -> x0:uint_t 64 -> x1:uint_t 64 -> y:uint_t 128 ->
y0:uint_t 64 -> y1:uint_t 64 -> z:uint_t 128 -> z0:uint_t 64 ->
z1:uint_t 64 -> Lemma
(requires z0 == logand #64 x0 y0 /\
z1 == logand #64 x1 y1 /\
x == lowerUpper128u x0 x1 /\
y == lowerUpper128u y0 y1 /\
z == lowerUpper128u z0 z1)
(ensures z == logand #128 x y) | val lemma_lowerUpper128_andu : x:uint_t 128 -> x0:uint_t 64 -> x1:uint_t 64 -> y:uint_t 128 ->
y0:uint_t 64 -> y1:uint_t 64 -> z:uint_t 128 -> z0:uint_t 64 ->
z1:uint_t 64 -> Lemma
(requires z0 == logand #64 x0 y0 /\
z1 == logand #64 x1 y1 /\
x == lowerUpper128u x0 x1 /\
y == lowerUpper128u y0 y1 /\
z == lowerUpper128u z0 z1)
(ensures z == logand #128 x y) | let lemma_lowerUpper128_andu
(x:uint_t 128) (x0:uint_t 64) (x1:uint_t 64) (y:uint_t 128)
(y0:uint_t 64) (y1:uint_t 64) (z:uint_t 128) (z0:uint_t 64) (z1:uint_t 64) :
Lemma
(requires
z0 == logand #64 x0 y0 /\
z1 == logand #64 x1 y1 /\
x == lowerUpper128u x0 x1 /\
y == lowerUpper128u y0 y1 /\
z == lowerUpper128u z0 z1)
(ensures z == logand #128 x y)
=
let bx0 = b_i2b x0 in
let bx1 = b_i2b x1 in
let by0 = b_i2b y0 in
let by1 = b_i2b y1 in
assert_norm (
lowerUpper128b (b_and bx0 by0) (b_and bx1 by1) ==
b_and (lowerUpper128b bx0 bx1) (lowerUpper128b by0 by1));
lemma_i2b_equal
(lowerUpper128m (logand x0 y0) (logand x1 y1))
(logand (lowerUpper128m x0 x1) (lowerUpper128m y0 y1));
assert_norm (lowerUpper128m x0 x1 == lowerUpper128u x0 x1);
assert_norm (lowerUpper128m y0 y1 == lowerUpper128u y0 y1);
assert_norm (lowerUpper128m z0 z1 == lowerUpper128u z0 z1);
() | {
"file_name": "vale/code/crypto/poly1305/x64/Vale.Poly1305.Bitvectors.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 4,
"end_line": 165,
"start_col": 0,
"start_line": 140
} | module Vale.Poly1305.Bitvectors
open FStar.BV
open FStar.Tactics
open FStar.Tactics.Derived
open FStar.Tactics.BV
open FStar.Mul
open FStar.UInt
open FStar.Math.Lemmas
open Vale.Lib.Tactics
open Vale.Lib.Bv_s
open Vale.Math.Bits
// tweak options?
#reset-options "--smtencoding.elim_box true"
//NOTE: Using the split tactic seems to slowdown execution by a lot.
let lemma_shr2 x =
assert_by_tactic (shift_right #64 x 2 == udiv #64 x 4) bv_tac
let lemma_shr4 x =
assert_by_tactic (shift_right #64 x 4 == udiv #64 x 16) bv_tac
let lemma_and_mod_n x =
assert_by_tactic (logand #64 x 3 == mod #64 x 4) (bv_tac);
assert_by_tactic (logand #64 x 15 == mod #64 x 16) (bv_tac)
let lemma_clear_lower_2 x =
assert_by_tactic
(logand #64 x 0xfffffffffffffffc == mul_mod #64 (udiv #64 x 4) 4)
bv_tac
let lemma_and_constants x =
assert_by_tactic (logand #64 x 0 == (0 <: uint_t 64)) bv_tac;
assert_by_tactic (logand #64 x 0xffffffffffffffff == x) bv_tac
let lemma_poly_constants x =
// using split in this seems to hang execution.
assert_by_tactic
(logand #64 x 0x0ffffffc0fffffff < (0x1000000000000000 <: uint_t 64))
(fun () -> bv_tac_lt 64);
assert_by_tactic
(logand #64 x 0x0ffffffc0ffffffc < (0x1000000000000000 <: uint_t 64))
(fun () -> bv_tac_lt 64);
assert_by_tactic
(mod #64 (logand #64 x 0x0ffffffc0ffffffc) 4 == (0 <: uint_t 64))
(fun () -> bv_tac ())
let lemma_and_commutes x y =
assert_by_tactic
(logand #64 x y == logand #64 y x)
bv_tac
let lemma_bv128_64_64_and_helper' (x0:bv_t 64) (x1:bv_t 64) (y0:bv_t 64) (y1:bv_t 64) :
Lemma (requires True)
(ensures ((bvor #128 (bvshl #128 (bv_uext #64 #64 (bvand #64 x1 y1)) 64)
(bv_uext #64 #64 (bvand #64 x0 y0))) ==
bvand #128 (bvor #128 (bvshl #128 (bv_uext #64 #64 x1) 64)
(bv_uext #64 #64 x0))
(bvor #128 (bvshl #128 (bv_uext #64 #64 y1) 64)
(bv_uext #64 #64 y0)))) = ()
// Rewrite all equalities and then the goal is trivial for Z3.
// Without rewriting this does not go through.
// I believe the reason is related to a previously reported issue with the way
// Z3 bit-blasts through the Boxing/Unboxing functions. I thought this was fixed
// but it may not be the case. Notice that by rewriting with tactics the solver
// only gets to see one big term without any boxing or unboxing inside it.
let lemma_bv128_64_64_and_helper x x0 x1 y y0 y1 z z0 z1 =
lemma_bv128_64_64_and_helper' x0 x1 y0 y1;
assert_by_tactic (z == bvand #128 x y)
(fun () -> destruct_conj ();
rewrite_eqs_from_context ())
let bv128_64_64 x0 x1 = bvor (bvshl (bv_uext #64 #64 x1) 64) (bv_uext #64 #64 x0)
unfold let uint_to_nat (#n:nat) (x:uint_t n) : r:nat{r = x} =
assert (x < pow2 n);
modulo_lemma x (pow2 n);
x
let uint_ext (#n : nat) (#m : nat{n <= m}) (x : uint_t n) : r:(uint_t m){uint_to_nat r = uint_to_nat x} =
assert_norm(fits x n);
pow2_le_compat m n;
assert_norm(fits x m);
modulo_lemma x (pow2 m);
to_uint_t m x
#reset-options "--smtencoding.elim_box true --smtencoding.l_arith_repr boxwrap --smtencoding.nl_arith_repr boxwrap"
let mul_bvshl (u:uint_t 64) :
Lemma (0x10000000000000000 * u < pow2 128 /\
(int2bv #128 (0x10000000000000000 * u) ==
bvshl (bv_uext #64 #64 (int2bv u)) 64)) =
assert_norm ( 0x10000000000000000 * pow2 63 < pow2 128);
modulo_lemma (0x10000000000000000 * u) (pow2 128);
assert_by_tactic
(int2bv #128 (mul_mod #128 0x10000000000000000 (uint_ext #64 #128 u)) ==
bvmul #128 (int2bv #128 0x10000000000000000) (uint_ext #64 #128 u))
(fun () -> mapply (`trans); arith_to_bv_tac (); trefl ())
#reset-options "--smtencoding.elim_box true"
let plus_bvor (u h:bv_t 128) :
Lemma (bvand u h = bv_zero ==> bvadd u h == bvor u h) = ()
let lemma_bv128_64_64_and x x0 x1 y y0 y1 z z0 z1 =
assert_by_tactic (z == bvand #128 x y)
(fun () -> destruct_conj ();
rewrite_eqs_from_context ();
norm[delta])
#reset-options "--smtencoding.elim_box true --z3refresh --z3rlimit 20 --max_ifuel 1 --max_fuel 1"
let int2bv_uext_64_128 (x1 : nat) :
Lemma (requires (FStar.UInt.size x1 64))
(ensures (bv_uext #64 #64 (int2bv #64 x1) == int2bv #128 x1)) =
assert (64 <= 128);
pow2_le_compat 128 64;
assert (x1 < pow2 128);
modulo_lemma x1 (pow2 128); // x1 % pow2 128 = x1
assert (FStar.UInt.size x1 128);
assert_by_tactic (bv_uext #64 #64 (int2bv #64 x1) == int2bv #128 x1)
(fun () -> dump "..";
norm[delta_only [`%uint_ext; `%FStar.UInt.to_uint_t]];
// grewrite (quote (x1 % pow2 128)) (quote x1);
dump "After norm"; smt ())
#reset-options "--smtencoding.l_arith_repr native --smtencoding.nl_arith_repr wrapped --smtencoding.elim_box true --z3cliopt smt.arith.nl=false --max_fuel 1 --max_ifuel 0"
let lowerUpper128m (l:uint_t 64) (u:uint_t 64) : uint_t 128 =
add_hide #128 (mul_hide #128 (uext #64 #64 u) 0x10000000000000000) (uext #64 #64 l)
let lowerUpper128b (l:bv_t 64) (u:bv_t 64) : bv_t 128 =
b_add #128 (b_mul #128 (b_uext #64 #64 u) 0x10000000000000000) (b_uext #64 #64 l)
//this was so flaky, new options helped. | {
"checked_file": "/",
"dependencies": [
"Vale.Math.Bits.fsti.checked",
"Vale.Lib.Tactics.fst.checked",
"Vale.Lib.Bv_s.fst.checked",
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Tactics.Derived.fst.checked",
"FStar.Tactics.BV.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.BV.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Poly1305.Bitvectors.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Math.Bits",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Bv_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": true,
"z3rlimit": 40,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
x: FStar.UInt.uint_t 128 ->
x0: FStar.UInt.uint_t 64 ->
x1: FStar.UInt.uint_t 64 ->
y: FStar.UInt.uint_t 128 ->
y0: FStar.UInt.uint_t 64 ->
y1: FStar.UInt.uint_t 64 ->
z: FStar.UInt.uint_t 128 ->
z0: FStar.UInt.uint_t 64 ->
z1: FStar.UInt.uint_t 64
-> FStar.Pervasives.Lemma
(requires
z0 == FStar.UInt.logand x0 y0 /\ z1 == FStar.UInt.logand x1 y1 /\
x == Vale.Poly1305.Bitvectors.lowerUpper128u x0 x1 /\
y == Vale.Poly1305.Bitvectors.lowerUpper128u y0 y1 /\
z == Vale.Poly1305.Bitvectors.lowerUpper128u z0 z1) (ensures z == FStar.UInt.logand x y) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.UInt.uint_t",
"Prims.unit",
"FStar.Pervasives.assert_norm",
"Prims.eq2",
"Vale.Poly1305.Bitvectors.lowerUpper128m",
"Vale.Poly1305.Bitvectors.lowerUpper128u",
"Vale.Math.Bits.lemma_i2b_equal",
"FStar.UInt.logand",
"FStar.BV.bv_t",
"Vale.Poly1305.Bitvectors.lowerUpper128b",
"Vale.Math.Bits.b_and",
"Vale.Math.Bits.b_i2b",
"Prims.l_and",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let lemma_lowerUpper128_andu
(x: uint_t 128)
(x0 x1: uint_t 64)
(y: uint_t 128)
(y0 y1: uint_t 64)
(z: uint_t 128)
(z0 z1: uint_t 64)
: Lemma
(requires
z0 == logand #64 x0 y0 /\ z1 == logand #64 x1 y1 /\ x == lowerUpper128u x0 x1 /\
y == lowerUpper128u y0 y1 /\ z == lowerUpper128u z0 z1) (ensures z == logand #128 x y) =
| let bx0 = b_i2b x0 in
let bx1 = b_i2b x1 in
let by0 = b_i2b y0 in
let by1 = b_i2b y1 in
assert_norm (lowerUpper128b (b_and bx0 by0) (b_and bx1 by1) ==
b_and (lowerUpper128b bx0 bx1) (lowerUpper128b by0 by1));
lemma_i2b_equal (lowerUpper128m (logand x0 y0) (logand x1 y1))
(logand (lowerUpper128m x0 x1) (lowerUpper128m y0 y1));
assert_norm (lowerUpper128m x0 x1 == lowerUpper128u x0 x1);
assert_norm (lowerUpper128m y0 y1 == lowerUpper128u y0 y1);
assert_norm (lowerUpper128m z0 z1 == lowerUpper128u z0 z1);
() | false |
Vale.Poly1305.Bitvectors.fst | Vale.Poly1305.Bitvectors.lemma_bytes_shift_constants4 | val lemma_bytes_shift_constants4: unit -> Lemma
(shift_left #64 4 3 == 32 /\
shift_left #64 1 (shift_left #64 4 3) == 0x100000000) | val lemma_bytes_shift_constants4: unit -> Lemma
(shift_left #64 4 3 == 32 /\
shift_left #64 1 (shift_left #64 4 3) == 0x100000000) | let lemma_bytes_shift_constants4 x =
assert_by_tactic (shift_left #64 4 3 == (32 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 32 == (0x100000000 <: uint_t 64)) bv_tac | {
"file_name": "vale/code/crypto/poly1305/x64/Vale.Poly1305.Bitvectors.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 77,
"end_line": 182,
"start_col": 0,
"start_line": 180
} | module Vale.Poly1305.Bitvectors
open FStar.BV
open FStar.Tactics
open FStar.Tactics.Derived
open FStar.Tactics.BV
open FStar.Mul
open FStar.UInt
open FStar.Math.Lemmas
open Vale.Lib.Tactics
open Vale.Lib.Bv_s
open Vale.Math.Bits
// tweak options?
#reset-options "--smtencoding.elim_box true"
//NOTE: Using the split tactic seems to slowdown execution by a lot.
let lemma_shr2 x =
assert_by_tactic (shift_right #64 x 2 == udiv #64 x 4) bv_tac
let lemma_shr4 x =
assert_by_tactic (shift_right #64 x 4 == udiv #64 x 16) bv_tac
let lemma_and_mod_n x =
assert_by_tactic (logand #64 x 3 == mod #64 x 4) (bv_tac);
assert_by_tactic (logand #64 x 15 == mod #64 x 16) (bv_tac)
let lemma_clear_lower_2 x =
assert_by_tactic
(logand #64 x 0xfffffffffffffffc == mul_mod #64 (udiv #64 x 4) 4)
bv_tac
let lemma_and_constants x =
assert_by_tactic (logand #64 x 0 == (0 <: uint_t 64)) bv_tac;
assert_by_tactic (logand #64 x 0xffffffffffffffff == x) bv_tac
let lemma_poly_constants x =
// using split in this seems to hang execution.
assert_by_tactic
(logand #64 x 0x0ffffffc0fffffff < (0x1000000000000000 <: uint_t 64))
(fun () -> bv_tac_lt 64);
assert_by_tactic
(logand #64 x 0x0ffffffc0ffffffc < (0x1000000000000000 <: uint_t 64))
(fun () -> bv_tac_lt 64);
assert_by_tactic
(mod #64 (logand #64 x 0x0ffffffc0ffffffc) 4 == (0 <: uint_t 64))
(fun () -> bv_tac ())
let lemma_and_commutes x y =
assert_by_tactic
(logand #64 x y == logand #64 y x)
bv_tac
let lemma_bv128_64_64_and_helper' (x0:bv_t 64) (x1:bv_t 64) (y0:bv_t 64) (y1:bv_t 64) :
Lemma (requires True)
(ensures ((bvor #128 (bvshl #128 (bv_uext #64 #64 (bvand #64 x1 y1)) 64)
(bv_uext #64 #64 (bvand #64 x0 y0))) ==
bvand #128 (bvor #128 (bvshl #128 (bv_uext #64 #64 x1) 64)
(bv_uext #64 #64 x0))
(bvor #128 (bvshl #128 (bv_uext #64 #64 y1) 64)
(bv_uext #64 #64 y0)))) = ()
// Rewrite all equalities and then the goal is trivial for Z3.
// Without rewriting this does not go through.
// I believe the reason is related to a previously reported issue with the way
// Z3 bit-blasts through the Boxing/Unboxing functions. I thought this was fixed
// but it may not be the case. Notice that by rewriting with tactics the solver
// only gets to see one big term without any boxing or unboxing inside it.
let lemma_bv128_64_64_and_helper x x0 x1 y y0 y1 z z0 z1 =
lemma_bv128_64_64_and_helper' x0 x1 y0 y1;
assert_by_tactic (z == bvand #128 x y)
(fun () -> destruct_conj ();
rewrite_eqs_from_context ())
let bv128_64_64 x0 x1 = bvor (bvshl (bv_uext #64 #64 x1) 64) (bv_uext #64 #64 x0)
unfold let uint_to_nat (#n:nat) (x:uint_t n) : r:nat{r = x} =
assert (x < pow2 n);
modulo_lemma x (pow2 n);
x
let uint_ext (#n : nat) (#m : nat{n <= m}) (x : uint_t n) : r:(uint_t m){uint_to_nat r = uint_to_nat x} =
assert_norm(fits x n);
pow2_le_compat m n;
assert_norm(fits x m);
modulo_lemma x (pow2 m);
to_uint_t m x
#reset-options "--smtencoding.elim_box true --smtencoding.l_arith_repr boxwrap --smtencoding.nl_arith_repr boxwrap"
let mul_bvshl (u:uint_t 64) :
Lemma (0x10000000000000000 * u < pow2 128 /\
(int2bv #128 (0x10000000000000000 * u) ==
bvshl (bv_uext #64 #64 (int2bv u)) 64)) =
assert_norm ( 0x10000000000000000 * pow2 63 < pow2 128);
modulo_lemma (0x10000000000000000 * u) (pow2 128);
assert_by_tactic
(int2bv #128 (mul_mod #128 0x10000000000000000 (uint_ext #64 #128 u)) ==
bvmul #128 (int2bv #128 0x10000000000000000) (uint_ext #64 #128 u))
(fun () -> mapply (`trans); arith_to_bv_tac (); trefl ())
#reset-options "--smtencoding.elim_box true"
let plus_bvor (u h:bv_t 128) :
Lemma (bvand u h = bv_zero ==> bvadd u h == bvor u h) = ()
let lemma_bv128_64_64_and x x0 x1 y y0 y1 z z0 z1 =
assert_by_tactic (z == bvand #128 x y)
(fun () -> destruct_conj ();
rewrite_eqs_from_context ();
norm[delta])
#reset-options "--smtencoding.elim_box true --z3refresh --z3rlimit 20 --max_ifuel 1 --max_fuel 1"
let int2bv_uext_64_128 (x1 : nat) :
Lemma (requires (FStar.UInt.size x1 64))
(ensures (bv_uext #64 #64 (int2bv #64 x1) == int2bv #128 x1)) =
assert (64 <= 128);
pow2_le_compat 128 64;
assert (x1 < pow2 128);
modulo_lemma x1 (pow2 128); // x1 % pow2 128 = x1
assert (FStar.UInt.size x1 128);
assert_by_tactic (bv_uext #64 #64 (int2bv #64 x1) == int2bv #128 x1)
(fun () -> dump "..";
norm[delta_only [`%uint_ext; `%FStar.UInt.to_uint_t]];
// grewrite (quote (x1 % pow2 128)) (quote x1);
dump "After norm"; smt ())
#reset-options "--smtencoding.l_arith_repr native --smtencoding.nl_arith_repr wrapped --smtencoding.elim_box true --z3cliopt smt.arith.nl=false --max_fuel 1 --max_ifuel 0"
let lowerUpper128m (l:uint_t 64) (u:uint_t 64) : uint_t 128 =
add_hide #128 (mul_hide #128 (uext #64 #64 u) 0x10000000000000000) (uext #64 #64 l)
let lowerUpper128b (l:bv_t 64) (u:bv_t 64) : bv_t 128 =
b_add #128 (b_mul #128 (b_uext #64 #64 u) 0x10000000000000000) (b_uext #64 #64 l)
//this was so flaky, new options helped.
#reset-options "--smtencoding.elim_box true --z3refresh --z3rlimit 40 --max_ifuel 1 --max_fuel 1"
let lemma_lowerUpper128_andu
(x:uint_t 128) (x0:uint_t 64) (x1:uint_t 64) (y:uint_t 128)
(y0:uint_t 64) (y1:uint_t 64) (z:uint_t 128) (z0:uint_t 64) (z1:uint_t 64) :
Lemma
(requires
z0 == logand #64 x0 y0 /\
z1 == logand #64 x1 y1 /\
x == lowerUpper128u x0 x1 /\
y == lowerUpper128u y0 y1 /\
z == lowerUpper128u z0 z1)
(ensures z == logand #128 x y)
=
let bx0 = b_i2b x0 in
let bx1 = b_i2b x1 in
let by0 = b_i2b y0 in
let by1 = b_i2b y1 in
assert_norm (
lowerUpper128b (b_and bx0 by0) (b_and bx1 by1) ==
b_and (lowerUpper128b bx0 bx1) (lowerUpper128b by0 by1));
lemma_i2b_equal
(lowerUpper128m (logand x0 y0) (logand x1 y1))
(logand (lowerUpper128m x0 x1) (lowerUpper128m y0 y1));
assert_norm (lowerUpper128m x0 x1 == lowerUpper128u x0 x1);
assert_norm (lowerUpper128m y0 y1 == lowerUpper128u y0 y1);
assert_norm (lowerUpper128m z0 z1 == lowerUpper128u z0 z1);
()
#reset-options "--smtencoding.elim_box true --z3cliopt smt.case_split=3"
let lemma_bytes_shift_constants0 x =
assert_by_tactic (shift_left #64 0 3 == (0 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 0 == (0x1 <: uint_t 64)) bv_tac
let lemma_bytes_shift_constants1 x =
assert_by_tactic (shift_left #64 1 3 == (8 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 8 == (0x100 <: uint_t 64)) bv_tac
let lemma_bytes_shift_constants2 x =
assert_by_tactic (shift_left #64 2 3 == (16 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 16 == (0x10000 <: uint_t 64)) bv_tac
let lemma_bytes_shift_constants3 x =
assert_by_tactic (shift_left #64 3 3 == (24 <: uint_t 64)) bv_tac; | {
"checked_file": "/",
"dependencies": [
"Vale.Math.Bits.fsti.checked",
"Vale.Lib.Tactics.fst.checked",
"Vale.Lib.Bv_s.fst.checked",
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Tactics.Derived.fst.checked",
"FStar.Tactics.BV.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.BV.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Poly1305.Bitvectors.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Math.Bits",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Bv_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3",
"smt.case_split=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: Prims.unit
-> FStar.Pervasives.Lemma
(ensures
FStar.UInt.shift_left 4 3 == 32 /\
FStar.UInt.shift_left 1 (FStar.UInt.shift_left 4 3) == 0x100000000) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.unit",
"FStar.Tactics.Effect.assert_by_tactic",
"Prims.eq2",
"FStar.UInt.uint_t",
"FStar.UInt.shift_left",
"FStar.Tactics.BV.bv_tac"
] | [] | true | false | true | false | false | let lemma_bytes_shift_constants4 x =
| assert_by_tactic (shift_left #64 4 3 == (32 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 32 == (0x100000000 <: uint_t 64)) bv_tac | false |
Vale.Poly1305.Bitvectors.fst | Vale.Poly1305.Bitvectors.lemma_bytes_shift_constants6 | val lemma_bytes_shift_constants6: unit -> Lemma
(shift_left #64 6 3 == 48 /\
shift_left #64 1 (shift_left #64 6 3) == 0x1000000000000) | val lemma_bytes_shift_constants6: unit -> Lemma
(shift_left #64 6 3 == 48 /\
shift_left #64 1 (shift_left #64 6 3) == 0x1000000000000) | let lemma_bytes_shift_constants6 x =
assert_by_tactic (shift_left #64 6 3 == (48 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 48 == (0x1000000000000 <: uint_t 64)) bv_tac | {
"file_name": "vale/code/crypto/poly1305/x64/Vale.Poly1305.Bitvectors.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 81,
"end_line": 188,
"start_col": 0,
"start_line": 186
} | module Vale.Poly1305.Bitvectors
open FStar.BV
open FStar.Tactics
open FStar.Tactics.Derived
open FStar.Tactics.BV
open FStar.Mul
open FStar.UInt
open FStar.Math.Lemmas
open Vale.Lib.Tactics
open Vale.Lib.Bv_s
open Vale.Math.Bits
// tweak options?
#reset-options "--smtencoding.elim_box true"
//NOTE: Using the split tactic seems to slowdown execution by a lot.
let lemma_shr2 x =
assert_by_tactic (shift_right #64 x 2 == udiv #64 x 4) bv_tac
let lemma_shr4 x =
assert_by_tactic (shift_right #64 x 4 == udiv #64 x 16) bv_tac
let lemma_and_mod_n x =
assert_by_tactic (logand #64 x 3 == mod #64 x 4) (bv_tac);
assert_by_tactic (logand #64 x 15 == mod #64 x 16) (bv_tac)
let lemma_clear_lower_2 x =
assert_by_tactic
(logand #64 x 0xfffffffffffffffc == mul_mod #64 (udiv #64 x 4) 4)
bv_tac
let lemma_and_constants x =
assert_by_tactic (logand #64 x 0 == (0 <: uint_t 64)) bv_tac;
assert_by_tactic (logand #64 x 0xffffffffffffffff == x) bv_tac
let lemma_poly_constants x =
// using split in this seems to hang execution.
assert_by_tactic
(logand #64 x 0x0ffffffc0fffffff < (0x1000000000000000 <: uint_t 64))
(fun () -> bv_tac_lt 64);
assert_by_tactic
(logand #64 x 0x0ffffffc0ffffffc < (0x1000000000000000 <: uint_t 64))
(fun () -> bv_tac_lt 64);
assert_by_tactic
(mod #64 (logand #64 x 0x0ffffffc0ffffffc) 4 == (0 <: uint_t 64))
(fun () -> bv_tac ())
let lemma_and_commutes x y =
assert_by_tactic
(logand #64 x y == logand #64 y x)
bv_tac
let lemma_bv128_64_64_and_helper' (x0:bv_t 64) (x1:bv_t 64) (y0:bv_t 64) (y1:bv_t 64) :
Lemma (requires True)
(ensures ((bvor #128 (bvshl #128 (bv_uext #64 #64 (bvand #64 x1 y1)) 64)
(bv_uext #64 #64 (bvand #64 x0 y0))) ==
bvand #128 (bvor #128 (bvshl #128 (bv_uext #64 #64 x1) 64)
(bv_uext #64 #64 x0))
(bvor #128 (bvshl #128 (bv_uext #64 #64 y1) 64)
(bv_uext #64 #64 y0)))) = ()
// Rewrite all equalities and then the goal is trivial for Z3.
// Without rewriting this does not go through.
// I believe the reason is related to a previously reported issue with the way
// Z3 bit-blasts through the Boxing/Unboxing functions. I thought this was fixed
// but it may not be the case. Notice that by rewriting with tactics the solver
// only gets to see one big term without any boxing or unboxing inside it.
let lemma_bv128_64_64_and_helper x x0 x1 y y0 y1 z z0 z1 =
lemma_bv128_64_64_and_helper' x0 x1 y0 y1;
assert_by_tactic (z == bvand #128 x y)
(fun () -> destruct_conj ();
rewrite_eqs_from_context ())
let bv128_64_64 x0 x1 = bvor (bvshl (bv_uext #64 #64 x1) 64) (bv_uext #64 #64 x0)
unfold let uint_to_nat (#n:nat) (x:uint_t n) : r:nat{r = x} =
assert (x < pow2 n);
modulo_lemma x (pow2 n);
x
let uint_ext (#n : nat) (#m : nat{n <= m}) (x : uint_t n) : r:(uint_t m){uint_to_nat r = uint_to_nat x} =
assert_norm(fits x n);
pow2_le_compat m n;
assert_norm(fits x m);
modulo_lemma x (pow2 m);
to_uint_t m x
#reset-options "--smtencoding.elim_box true --smtencoding.l_arith_repr boxwrap --smtencoding.nl_arith_repr boxwrap"
let mul_bvshl (u:uint_t 64) :
Lemma (0x10000000000000000 * u < pow2 128 /\
(int2bv #128 (0x10000000000000000 * u) ==
bvshl (bv_uext #64 #64 (int2bv u)) 64)) =
assert_norm ( 0x10000000000000000 * pow2 63 < pow2 128);
modulo_lemma (0x10000000000000000 * u) (pow2 128);
assert_by_tactic
(int2bv #128 (mul_mod #128 0x10000000000000000 (uint_ext #64 #128 u)) ==
bvmul #128 (int2bv #128 0x10000000000000000) (uint_ext #64 #128 u))
(fun () -> mapply (`trans); arith_to_bv_tac (); trefl ())
#reset-options "--smtencoding.elim_box true"
let plus_bvor (u h:bv_t 128) :
Lemma (bvand u h = bv_zero ==> bvadd u h == bvor u h) = ()
let lemma_bv128_64_64_and x x0 x1 y y0 y1 z z0 z1 =
assert_by_tactic (z == bvand #128 x y)
(fun () -> destruct_conj ();
rewrite_eqs_from_context ();
norm[delta])
#reset-options "--smtencoding.elim_box true --z3refresh --z3rlimit 20 --max_ifuel 1 --max_fuel 1"
let int2bv_uext_64_128 (x1 : nat) :
Lemma (requires (FStar.UInt.size x1 64))
(ensures (bv_uext #64 #64 (int2bv #64 x1) == int2bv #128 x1)) =
assert (64 <= 128);
pow2_le_compat 128 64;
assert (x1 < pow2 128);
modulo_lemma x1 (pow2 128); // x1 % pow2 128 = x1
assert (FStar.UInt.size x1 128);
assert_by_tactic (bv_uext #64 #64 (int2bv #64 x1) == int2bv #128 x1)
(fun () -> dump "..";
norm[delta_only [`%uint_ext; `%FStar.UInt.to_uint_t]];
// grewrite (quote (x1 % pow2 128)) (quote x1);
dump "After norm"; smt ())
#reset-options "--smtencoding.l_arith_repr native --smtencoding.nl_arith_repr wrapped --smtencoding.elim_box true --z3cliopt smt.arith.nl=false --max_fuel 1 --max_ifuel 0"
let lowerUpper128m (l:uint_t 64) (u:uint_t 64) : uint_t 128 =
add_hide #128 (mul_hide #128 (uext #64 #64 u) 0x10000000000000000) (uext #64 #64 l)
let lowerUpper128b (l:bv_t 64) (u:bv_t 64) : bv_t 128 =
b_add #128 (b_mul #128 (b_uext #64 #64 u) 0x10000000000000000) (b_uext #64 #64 l)
//this was so flaky, new options helped.
#reset-options "--smtencoding.elim_box true --z3refresh --z3rlimit 40 --max_ifuel 1 --max_fuel 1"
let lemma_lowerUpper128_andu
(x:uint_t 128) (x0:uint_t 64) (x1:uint_t 64) (y:uint_t 128)
(y0:uint_t 64) (y1:uint_t 64) (z:uint_t 128) (z0:uint_t 64) (z1:uint_t 64) :
Lemma
(requires
z0 == logand #64 x0 y0 /\
z1 == logand #64 x1 y1 /\
x == lowerUpper128u x0 x1 /\
y == lowerUpper128u y0 y1 /\
z == lowerUpper128u z0 z1)
(ensures z == logand #128 x y)
=
let bx0 = b_i2b x0 in
let bx1 = b_i2b x1 in
let by0 = b_i2b y0 in
let by1 = b_i2b y1 in
assert_norm (
lowerUpper128b (b_and bx0 by0) (b_and bx1 by1) ==
b_and (lowerUpper128b bx0 bx1) (lowerUpper128b by0 by1));
lemma_i2b_equal
(lowerUpper128m (logand x0 y0) (logand x1 y1))
(logand (lowerUpper128m x0 x1) (lowerUpper128m y0 y1));
assert_norm (lowerUpper128m x0 x1 == lowerUpper128u x0 x1);
assert_norm (lowerUpper128m y0 y1 == lowerUpper128u y0 y1);
assert_norm (lowerUpper128m z0 z1 == lowerUpper128u z0 z1);
()
#reset-options "--smtencoding.elim_box true --z3cliopt smt.case_split=3"
let lemma_bytes_shift_constants0 x =
assert_by_tactic (shift_left #64 0 3 == (0 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 0 == (0x1 <: uint_t 64)) bv_tac
let lemma_bytes_shift_constants1 x =
assert_by_tactic (shift_left #64 1 3 == (8 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 8 == (0x100 <: uint_t 64)) bv_tac
let lemma_bytes_shift_constants2 x =
assert_by_tactic (shift_left #64 2 3 == (16 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 16 == (0x10000 <: uint_t 64)) bv_tac
let lemma_bytes_shift_constants3 x =
assert_by_tactic (shift_left #64 3 3 == (24 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 24 == (0x1000000 <: uint_t 64)) bv_tac
let lemma_bytes_shift_constants4 x =
assert_by_tactic (shift_left #64 4 3 == (32 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 32 == (0x100000000 <: uint_t 64)) bv_tac
let lemma_bytes_shift_constants5 x =
assert_by_tactic (shift_left #64 5 3 == (40 <: uint_t 64)) bv_tac; | {
"checked_file": "/",
"dependencies": [
"Vale.Math.Bits.fsti.checked",
"Vale.Lib.Tactics.fst.checked",
"Vale.Lib.Bv_s.fst.checked",
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Tactics.Derived.fst.checked",
"FStar.Tactics.BV.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.BV.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Poly1305.Bitvectors.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Math.Bits",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Bv_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3",
"smt.case_split=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: Prims.unit
-> FStar.Pervasives.Lemma
(ensures
FStar.UInt.shift_left 6 3 == 48 /\
FStar.UInt.shift_left 1 (FStar.UInt.shift_left 6 3) == 0x1000000000000) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.unit",
"FStar.Tactics.Effect.assert_by_tactic",
"Prims.eq2",
"FStar.UInt.uint_t",
"FStar.UInt.shift_left",
"FStar.Tactics.BV.bv_tac"
] | [] | true | false | true | false | false | let lemma_bytes_shift_constants6 x =
| assert_by_tactic (shift_left #64 6 3 == (48 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 48 == (0x1000000000000 <: uint_t 64)) bv_tac | false |
Vale.Poly1305.Bitvectors.fst | Vale.Poly1305.Bitvectors.lemma_bytes_shift_constants2 | val lemma_bytes_shift_constants2: unit -> Lemma
(shift_left #64 2 3 == 16 /\
shift_left #64 1 (shift_left #64 2 3) == 0x10000) | val lemma_bytes_shift_constants2: unit -> Lemma
(shift_left #64 2 3 == 16 /\
shift_left #64 1 (shift_left #64 2 3) == 0x10000) | let lemma_bytes_shift_constants2 x =
assert_by_tactic (shift_left #64 2 3 == (16 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 16 == (0x10000 <: uint_t 64)) bv_tac | {
"file_name": "vale/code/crypto/poly1305/x64/Vale.Poly1305.Bitvectors.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 73,
"end_line": 176,
"start_col": 0,
"start_line": 174
} | module Vale.Poly1305.Bitvectors
open FStar.BV
open FStar.Tactics
open FStar.Tactics.Derived
open FStar.Tactics.BV
open FStar.Mul
open FStar.UInt
open FStar.Math.Lemmas
open Vale.Lib.Tactics
open Vale.Lib.Bv_s
open Vale.Math.Bits
// tweak options?
#reset-options "--smtencoding.elim_box true"
//NOTE: Using the split tactic seems to slowdown execution by a lot.
let lemma_shr2 x =
assert_by_tactic (shift_right #64 x 2 == udiv #64 x 4) bv_tac
let lemma_shr4 x =
assert_by_tactic (shift_right #64 x 4 == udiv #64 x 16) bv_tac
let lemma_and_mod_n x =
assert_by_tactic (logand #64 x 3 == mod #64 x 4) (bv_tac);
assert_by_tactic (logand #64 x 15 == mod #64 x 16) (bv_tac)
let lemma_clear_lower_2 x =
assert_by_tactic
(logand #64 x 0xfffffffffffffffc == mul_mod #64 (udiv #64 x 4) 4)
bv_tac
let lemma_and_constants x =
assert_by_tactic (logand #64 x 0 == (0 <: uint_t 64)) bv_tac;
assert_by_tactic (logand #64 x 0xffffffffffffffff == x) bv_tac
let lemma_poly_constants x =
// using split in this seems to hang execution.
assert_by_tactic
(logand #64 x 0x0ffffffc0fffffff < (0x1000000000000000 <: uint_t 64))
(fun () -> bv_tac_lt 64);
assert_by_tactic
(logand #64 x 0x0ffffffc0ffffffc < (0x1000000000000000 <: uint_t 64))
(fun () -> bv_tac_lt 64);
assert_by_tactic
(mod #64 (logand #64 x 0x0ffffffc0ffffffc) 4 == (0 <: uint_t 64))
(fun () -> bv_tac ())
let lemma_and_commutes x y =
assert_by_tactic
(logand #64 x y == logand #64 y x)
bv_tac
let lemma_bv128_64_64_and_helper' (x0:bv_t 64) (x1:bv_t 64) (y0:bv_t 64) (y1:bv_t 64) :
Lemma (requires True)
(ensures ((bvor #128 (bvshl #128 (bv_uext #64 #64 (bvand #64 x1 y1)) 64)
(bv_uext #64 #64 (bvand #64 x0 y0))) ==
bvand #128 (bvor #128 (bvshl #128 (bv_uext #64 #64 x1) 64)
(bv_uext #64 #64 x0))
(bvor #128 (bvshl #128 (bv_uext #64 #64 y1) 64)
(bv_uext #64 #64 y0)))) = ()
// Rewrite all equalities and then the goal is trivial for Z3.
// Without rewriting this does not go through.
// I believe the reason is related to a previously reported issue with the way
// Z3 bit-blasts through the Boxing/Unboxing functions. I thought this was fixed
// but it may not be the case. Notice that by rewriting with tactics the solver
// only gets to see one big term without any boxing or unboxing inside it.
let lemma_bv128_64_64_and_helper x x0 x1 y y0 y1 z z0 z1 =
lemma_bv128_64_64_and_helper' x0 x1 y0 y1;
assert_by_tactic (z == bvand #128 x y)
(fun () -> destruct_conj ();
rewrite_eqs_from_context ())
let bv128_64_64 x0 x1 = bvor (bvshl (bv_uext #64 #64 x1) 64) (bv_uext #64 #64 x0)
unfold let uint_to_nat (#n:nat) (x:uint_t n) : r:nat{r = x} =
assert (x < pow2 n);
modulo_lemma x (pow2 n);
x
let uint_ext (#n : nat) (#m : nat{n <= m}) (x : uint_t n) : r:(uint_t m){uint_to_nat r = uint_to_nat x} =
assert_norm(fits x n);
pow2_le_compat m n;
assert_norm(fits x m);
modulo_lemma x (pow2 m);
to_uint_t m x
#reset-options "--smtencoding.elim_box true --smtencoding.l_arith_repr boxwrap --smtencoding.nl_arith_repr boxwrap"
let mul_bvshl (u:uint_t 64) :
Lemma (0x10000000000000000 * u < pow2 128 /\
(int2bv #128 (0x10000000000000000 * u) ==
bvshl (bv_uext #64 #64 (int2bv u)) 64)) =
assert_norm ( 0x10000000000000000 * pow2 63 < pow2 128);
modulo_lemma (0x10000000000000000 * u) (pow2 128);
assert_by_tactic
(int2bv #128 (mul_mod #128 0x10000000000000000 (uint_ext #64 #128 u)) ==
bvmul #128 (int2bv #128 0x10000000000000000) (uint_ext #64 #128 u))
(fun () -> mapply (`trans); arith_to_bv_tac (); trefl ())
#reset-options "--smtencoding.elim_box true"
let plus_bvor (u h:bv_t 128) :
Lemma (bvand u h = bv_zero ==> bvadd u h == bvor u h) = ()
let lemma_bv128_64_64_and x x0 x1 y y0 y1 z z0 z1 =
assert_by_tactic (z == bvand #128 x y)
(fun () -> destruct_conj ();
rewrite_eqs_from_context ();
norm[delta])
#reset-options "--smtencoding.elim_box true --z3refresh --z3rlimit 20 --max_ifuel 1 --max_fuel 1"
let int2bv_uext_64_128 (x1 : nat) :
Lemma (requires (FStar.UInt.size x1 64))
(ensures (bv_uext #64 #64 (int2bv #64 x1) == int2bv #128 x1)) =
assert (64 <= 128);
pow2_le_compat 128 64;
assert (x1 < pow2 128);
modulo_lemma x1 (pow2 128); // x1 % pow2 128 = x1
assert (FStar.UInt.size x1 128);
assert_by_tactic (bv_uext #64 #64 (int2bv #64 x1) == int2bv #128 x1)
(fun () -> dump "..";
norm[delta_only [`%uint_ext; `%FStar.UInt.to_uint_t]];
// grewrite (quote (x1 % pow2 128)) (quote x1);
dump "After norm"; smt ())
#reset-options "--smtencoding.l_arith_repr native --smtencoding.nl_arith_repr wrapped --smtencoding.elim_box true --z3cliopt smt.arith.nl=false --max_fuel 1 --max_ifuel 0"
let lowerUpper128m (l:uint_t 64) (u:uint_t 64) : uint_t 128 =
add_hide #128 (mul_hide #128 (uext #64 #64 u) 0x10000000000000000) (uext #64 #64 l)
let lowerUpper128b (l:bv_t 64) (u:bv_t 64) : bv_t 128 =
b_add #128 (b_mul #128 (b_uext #64 #64 u) 0x10000000000000000) (b_uext #64 #64 l)
//this was so flaky, new options helped.
#reset-options "--smtencoding.elim_box true --z3refresh --z3rlimit 40 --max_ifuel 1 --max_fuel 1"
let lemma_lowerUpper128_andu
(x:uint_t 128) (x0:uint_t 64) (x1:uint_t 64) (y:uint_t 128)
(y0:uint_t 64) (y1:uint_t 64) (z:uint_t 128) (z0:uint_t 64) (z1:uint_t 64) :
Lemma
(requires
z0 == logand #64 x0 y0 /\
z1 == logand #64 x1 y1 /\
x == lowerUpper128u x0 x1 /\
y == lowerUpper128u y0 y1 /\
z == lowerUpper128u z0 z1)
(ensures z == logand #128 x y)
=
let bx0 = b_i2b x0 in
let bx1 = b_i2b x1 in
let by0 = b_i2b y0 in
let by1 = b_i2b y1 in
assert_norm (
lowerUpper128b (b_and bx0 by0) (b_and bx1 by1) ==
b_and (lowerUpper128b bx0 bx1) (lowerUpper128b by0 by1));
lemma_i2b_equal
(lowerUpper128m (logand x0 y0) (logand x1 y1))
(logand (lowerUpper128m x0 x1) (lowerUpper128m y0 y1));
assert_norm (lowerUpper128m x0 x1 == lowerUpper128u x0 x1);
assert_norm (lowerUpper128m y0 y1 == lowerUpper128u y0 y1);
assert_norm (lowerUpper128m z0 z1 == lowerUpper128u z0 z1);
()
#reset-options "--smtencoding.elim_box true --z3cliopt smt.case_split=3"
let lemma_bytes_shift_constants0 x =
assert_by_tactic (shift_left #64 0 3 == (0 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 0 == (0x1 <: uint_t 64)) bv_tac
let lemma_bytes_shift_constants1 x =
assert_by_tactic (shift_left #64 1 3 == (8 <: uint_t 64)) bv_tac; | {
"checked_file": "/",
"dependencies": [
"Vale.Math.Bits.fsti.checked",
"Vale.Lib.Tactics.fst.checked",
"Vale.Lib.Bv_s.fst.checked",
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Tactics.Derived.fst.checked",
"FStar.Tactics.BV.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.BV.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Poly1305.Bitvectors.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Math.Bits",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Bv_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3",
"smt.case_split=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: Prims.unit
-> FStar.Pervasives.Lemma
(ensures
FStar.UInt.shift_left 2 3 == 16 /\
FStar.UInt.shift_left 1 (FStar.UInt.shift_left 2 3) == 0x10000) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.unit",
"FStar.Tactics.Effect.assert_by_tactic",
"Prims.eq2",
"FStar.UInt.uint_t",
"FStar.UInt.shift_left",
"FStar.Tactics.BV.bv_tac"
] | [] | true | false | true | false | false | let lemma_bytes_shift_constants2 x =
| assert_by_tactic (shift_left #64 2 3 == (16 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 16 == (0x10000 <: uint_t 64)) bv_tac | false |
Steel.Effect.Common.fst | Steel.Effect.Common.equiv | val equiv (p q:vprop) : prop | val equiv (p q:vprop) : prop | let equiv (p q:vprop) : prop = Mem.equiv (hp_of p) (hp_of q) /\ True | {
"file_name": "lib/steel/Steel.Effect.Common.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 68,
"end_line": 44,
"start_col": 0,
"start_line": 44
} | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Effect.Common
module Sem = Steel.Semantics.Hoare.MST
module Mem = Steel.Memory
open Steel.Semantics.Instantiate
module FExt = FStar.FunctionalExtensionality
let h_exists #a f = VUnit ({hp = Mem.h_exists (fun x -> hp_of (f x)); t = unit; sel = fun _ -> ()})
let can_be_split (p q:vprop) : prop = Mem.slimp (hp_of p) (hp_of q)
let reveal_can_be_split () = ()
let can_be_split_interp r r' h = ()
let can_be_split_trans p q r = ()
let can_be_split_star_l p q = ()
let can_be_split_star_r p q = ()
let can_be_split_refl p = ()
let can_be_split_congr_l p q r =
Classical.forall_intro (interp_star (hp_of p) (hp_of r));
Classical.forall_intro (interp_star (hp_of q) (hp_of r))
let can_be_split_congr_r p q r =
Classical.forall_intro (interp_star (hp_of r) (hp_of p));
Classical.forall_intro (interp_star (hp_of r) (hp_of q)) | {
"checked_file": "/",
"dependencies": [
"Steel.Semantics.Instantiate.fsti.checked",
"Steel.Semantics.Hoare.MST.fst.checked",
"Steel.Memory.fsti.checked",
"prims.fst.checked",
"FStar.PropositionalExtensionality.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Effect.Common.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "FExt"
},
{
"abbrev": false,
"full_module": "Steel.Semantics.Instantiate",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": true,
"full_module": "Steel.Semantics.Hoare.MST",
"short_module": "Sem"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "FExt"
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | p: Steel.Effect.Common.vprop -> q: Steel.Effect.Common.vprop -> Prims.prop | Prims.Tot | [
"total"
] | [] | [
"Steel.Effect.Common.vprop",
"Prims.l_and",
"Steel.Memory.equiv",
"Steel.Effect.Common.hp_of",
"Prims.l_True",
"Prims.prop"
] | [] | false | false | false | true | true | let equiv (p q: vprop) : prop =
| Mem.equiv (hp_of p) (hp_of q) /\ True | false |
Vale.Poly1305.Bitvectors.fst | Vale.Poly1305.Bitvectors.lemma_bytes_shift_constants7 | val lemma_bytes_shift_constants7: unit -> Lemma
(shift_left #64 7 3 == 56 /\
shift_left #64 1 (shift_left #64 7 3) == 0x100000000000000) | val lemma_bytes_shift_constants7: unit -> Lemma
(shift_left #64 7 3 == 56 /\
shift_left #64 1 (shift_left #64 7 3) == 0x100000000000000) | let lemma_bytes_shift_constants7 x =
assert_by_tactic (shift_left #64 7 3 == (56 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 56 == (0x100000000000000 <: uint_t 64)) bv_tac | {
"file_name": "vale/code/crypto/poly1305/x64/Vale.Poly1305.Bitvectors.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 83,
"end_line": 191,
"start_col": 0,
"start_line": 189
} | module Vale.Poly1305.Bitvectors
open FStar.BV
open FStar.Tactics
open FStar.Tactics.Derived
open FStar.Tactics.BV
open FStar.Mul
open FStar.UInt
open FStar.Math.Lemmas
open Vale.Lib.Tactics
open Vale.Lib.Bv_s
open Vale.Math.Bits
// tweak options?
#reset-options "--smtencoding.elim_box true"
//NOTE: Using the split tactic seems to slowdown execution by a lot.
let lemma_shr2 x =
assert_by_tactic (shift_right #64 x 2 == udiv #64 x 4) bv_tac
let lemma_shr4 x =
assert_by_tactic (shift_right #64 x 4 == udiv #64 x 16) bv_tac
let lemma_and_mod_n x =
assert_by_tactic (logand #64 x 3 == mod #64 x 4) (bv_tac);
assert_by_tactic (logand #64 x 15 == mod #64 x 16) (bv_tac)
let lemma_clear_lower_2 x =
assert_by_tactic
(logand #64 x 0xfffffffffffffffc == mul_mod #64 (udiv #64 x 4) 4)
bv_tac
let lemma_and_constants x =
assert_by_tactic (logand #64 x 0 == (0 <: uint_t 64)) bv_tac;
assert_by_tactic (logand #64 x 0xffffffffffffffff == x) bv_tac
let lemma_poly_constants x =
// using split in this seems to hang execution.
assert_by_tactic
(logand #64 x 0x0ffffffc0fffffff < (0x1000000000000000 <: uint_t 64))
(fun () -> bv_tac_lt 64);
assert_by_tactic
(logand #64 x 0x0ffffffc0ffffffc < (0x1000000000000000 <: uint_t 64))
(fun () -> bv_tac_lt 64);
assert_by_tactic
(mod #64 (logand #64 x 0x0ffffffc0ffffffc) 4 == (0 <: uint_t 64))
(fun () -> bv_tac ())
let lemma_and_commutes x y =
assert_by_tactic
(logand #64 x y == logand #64 y x)
bv_tac
let lemma_bv128_64_64_and_helper' (x0:bv_t 64) (x1:bv_t 64) (y0:bv_t 64) (y1:bv_t 64) :
Lemma (requires True)
(ensures ((bvor #128 (bvshl #128 (bv_uext #64 #64 (bvand #64 x1 y1)) 64)
(bv_uext #64 #64 (bvand #64 x0 y0))) ==
bvand #128 (bvor #128 (bvshl #128 (bv_uext #64 #64 x1) 64)
(bv_uext #64 #64 x0))
(bvor #128 (bvshl #128 (bv_uext #64 #64 y1) 64)
(bv_uext #64 #64 y0)))) = ()
// Rewrite all equalities and then the goal is trivial for Z3.
// Without rewriting this does not go through.
// I believe the reason is related to a previously reported issue with the way
// Z3 bit-blasts through the Boxing/Unboxing functions. I thought this was fixed
// but it may not be the case. Notice that by rewriting with tactics the solver
// only gets to see one big term without any boxing or unboxing inside it.
let lemma_bv128_64_64_and_helper x x0 x1 y y0 y1 z z0 z1 =
lemma_bv128_64_64_and_helper' x0 x1 y0 y1;
assert_by_tactic (z == bvand #128 x y)
(fun () -> destruct_conj ();
rewrite_eqs_from_context ())
let bv128_64_64 x0 x1 = bvor (bvshl (bv_uext #64 #64 x1) 64) (bv_uext #64 #64 x0)
unfold let uint_to_nat (#n:nat) (x:uint_t n) : r:nat{r = x} =
assert (x < pow2 n);
modulo_lemma x (pow2 n);
x
let uint_ext (#n : nat) (#m : nat{n <= m}) (x : uint_t n) : r:(uint_t m){uint_to_nat r = uint_to_nat x} =
assert_norm(fits x n);
pow2_le_compat m n;
assert_norm(fits x m);
modulo_lemma x (pow2 m);
to_uint_t m x
#reset-options "--smtencoding.elim_box true --smtencoding.l_arith_repr boxwrap --smtencoding.nl_arith_repr boxwrap"
let mul_bvshl (u:uint_t 64) :
Lemma (0x10000000000000000 * u < pow2 128 /\
(int2bv #128 (0x10000000000000000 * u) ==
bvshl (bv_uext #64 #64 (int2bv u)) 64)) =
assert_norm ( 0x10000000000000000 * pow2 63 < pow2 128);
modulo_lemma (0x10000000000000000 * u) (pow2 128);
assert_by_tactic
(int2bv #128 (mul_mod #128 0x10000000000000000 (uint_ext #64 #128 u)) ==
bvmul #128 (int2bv #128 0x10000000000000000) (uint_ext #64 #128 u))
(fun () -> mapply (`trans); arith_to_bv_tac (); trefl ())
#reset-options "--smtencoding.elim_box true"
let plus_bvor (u h:bv_t 128) :
Lemma (bvand u h = bv_zero ==> bvadd u h == bvor u h) = ()
let lemma_bv128_64_64_and x x0 x1 y y0 y1 z z0 z1 =
assert_by_tactic (z == bvand #128 x y)
(fun () -> destruct_conj ();
rewrite_eqs_from_context ();
norm[delta])
#reset-options "--smtencoding.elim_box true --z3refresh --z3rlimit 20 --max_ifuel 1 --max_fuel 1"
let int2bv_uext_64_128 (x1 : nat) :
Lemma (requires (FStar.UInt.size x1 64))
(ensures (bv_uext #64 #64 (int2bv #64 x1) == int2bv #128 x1)) =
assert (64 <= 128);
pow2_le_compat 128 64;
assert (x1 < pow2 128);
modulo_lemma x1 (pow2 128); // x1 % pow2 128 = x1
assert (FStar.UInt.size x1 128);
assert_by_tactic (bv_uext #64 #64 (int2bv #64 x1) == int2bv #128 x1)
(fun () -> dump "..";
norm[delta_only [`%uint_ext; `%FStar.UInt.to_uint_t]];
// grewrite (quote (x1 % pow2 128)) (quote x1);
dump "After norm"; smt ())
#reset-options "--smtencoding.l_arith_repr native --smtencoding.nl_arith_repr wrapped --smtencoding.elim_box true --z3cliopt smt.arith.nl=false --max_fuel 1 --max_ifuel 0"
let lowerUpper128m (l:uint_t 64) (u:uint_t 64) : uint_t 128 =
add_hide #128 (mul_hide #128 (uext #64 #64 u) 0x10000000000000000) (uext #64 #64 l)
let lowerUpper128b (l:bv_t 64) (u:bv_t 64) : bv_t 128 =
b_add #128 (b_mul #128 (b_uext #64 #64 u) 0x10000000000000000) (b_uext #64 #64 l)
//this was so flaky, new options helped.
#reset-options "--smtencoding.elim_box true --z3refresh --z3rlimit 40 --max_ifuel 1 --max_fuel 1"
let lemma_lowerUpper128_andu
(x:uint_t 128) (x0:uint_t 64) (x1:uint_t 64) (y:uint_t 128)
(y0:uint_t 64) (y1:uint_t 64) (z:uint_t 128) (z0:uint_t 64) (z1:uint_t 64) :
Lemma
(requires
z0 == logand #64 x0 y0 /\
z1 == logand #64 x1 y1 /\
x == lowerUpper128u x0 x1 /\
y == lowerUpper128u y0 y1 /\
z == lowerUpper128u z0 z1)
(ensures z == logand #128 x y)
=
let bx0 = b_i2b x0 in
let bx1 = b_i2b x1 in
let by0 = b_i2b y0 in
let by1 = b_i2b y1 in
assert_norm (
lowerUpper128b (b_and bx0 by0) (b_and bx1 by1) ==
b_and (lowerUpper128b bx0 bx1) (lowerUpper128b by0 by1));
lemma_i2b_equal
(lowerUpper128m (logand x0 y0) (logand x1 y1))
(logand (lowerUpper128m x0 x1) (lowerUpper128m y0 y1));
assert_norm (lowerUpper128m x0 x1 == lowerUpper128u x0 x1);
assert_norm (lowerUpper128m y0 y1 == lowerUpper128u y0 y1);
assert_norm (lowerUpper128m z0 z1 == lowerUpper128u z0 z1);
()
#reset-options "--smtencoding.elim_box true --z3cliopt smt.case_split=3"
let lemma_bytes_shift_constants0 x =
assert_by_tactic (shift_left #64 0 3 == (0 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 0 == (0x1 <: uint_t 64)) bv_tac
let lemma_bytes_shift_constants1 x =
assert_by_tactic (shift_left #64 1 3 == (8 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 8 == (0x100 <: uint_t 64)) bv_tac
let lemma_bytes_shift_constants2 x =
assert_by_tactic (shift_left #64 2 3 == (16 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 16 == (0x10000 <: uint_t 64)) bv_tac
let lemma_bytes_shift_constants3 x =
assert_by_tactic (shift_left #64 3 3 == (24 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 24 == (0x1000000 <: uint_t 64)) bv_tac
let lemma_bytes_shift_constants4 x =
assert_by_tactic (shift_left #64 4 3 == (32 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 32 == (0x100000000 <: uint_t 64)) bv_tac
let lemma_bytes_shift_constants5 x =
assert_by_tactic (shift_left #64 5 3 == (40 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 40 == (0x10000000000 <: uint_t 64)) bv_tac
let lemma_bytes_shift_constants6 x =
assert_by_tactic (shift_left #64 6 3 == (48 <: uint_t 64)) bv_tac; | {
"checked_file": "/",
"dependencies": [
"Vale.Math.Bits.fsti.checked",
"Vale.Lib.Tactics.fst.checked",
"Vale.Lib.Bv_s.fst.checked",
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Tactics.Derived.fst.checked",
"FStar.Tactics.BV.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.BV.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Poly1305.Bitvectors.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Math.Bits",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Bv_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3",
"smt.case_split=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: Prims.unit
-> FStar.Pervasives.Lemma
(ensures
FStar.UInt.shift_left 7 3 == 56 /\
FStar.UInt.shift_left 1 (FStar.UInt.shift_left 7 3) == 0x100000000000000) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.unit",
"FStar.Tactics.Effect.assert_by_tactic",
"Prims.eq2",
"FStar.UInt.uint_t",
"FStar.UInt.shift_left",
"FStar.Tactics.BV.bv_tac"
] | [] | true | false | true | false | false | let lemma_bytes_shift_constants7 x =
| assert_by_tactic (shift_left #64 7 3 == (56 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 56 == (0x100000000000000 <: uint_t 64)) bv_tac | false |
Vale.Poly1305.Bitvectors.fst | Vale.Poly1305.Bitvectors.lemma_bytes_and_mod7 | val lemma_bytes_and_mod7: x: uint_t 64 ->
Lemma (logand #64 x (0x100000000000000 - 1) == mod #64 x 0x100000000000000) | val lemma_bytes_and_mod7: x: uint_t 64 ->
Lemma (logand #64 x (0x100000000000000 - 1) == mod #64 x 0x100000000000000) | let lemma_bytes_and_mod7 x =
assert_by_tactic (logand #64 x (0x100000000000000 - 1) == mod #64 x 0x100000000000000) bv_tac | {
"file_name": "vale/code/crypto/poly1305/x64/Vale.Poly1305.Bitvectors.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 95,
"end_line": 214,
"start_col": 0,
"start_line": 213
} | module Vale.Poly1305.Bitvectors
open FStar.BV
open FStar.Tactics
open FStar.Tactics.Derived
open FStar.Tactics.BV
open FStar.Mul
open FStar.UInt
open FStar.Math.Lemmas
open Vale.Lib.Tactics
open Vale.Lib.Bv_s
open Vale.Math.Bits
// tweak options?
#reset-options "--smtencoding.elim_box true"
//NOTE: Using the split tactic seems to slowdown execution by a lot.
let lemma_shr2 x =
assert_by_tactic (shift_right #64 x 2 == udiv #64 x 4) bv_tac
let lemma_shr4 x =
assert_by_tactic (shift_right #64 x 4 == udiv #64 x 16) bv_tac
let lemma_and_mod_n x =
assert_by_tactic (logand #64 x 3 == mod #64 x 4) (bv_tac);
assert_by_tactic (logand #64 x 15 == mod #64 x 16) (bv_tac)
let lemma_clear_lower_2 x =
assert_by_tactic
(logand #64 x 0xfffffffffffffffc == mul_mod #64 (udiv #64 x 4) 4)
bv_tac
let lemma_and_constants x =
assert_by_tactic (logand #64 x 0 == (0 <: uint_t 64)) bv_tac;
assert_by_tactic (logand #64 x 0xffffffffffffffff == x) bv_tac
let lemma_poly_constants x =
// using split in this seems to hang execution.
assert_by_tactic
(logand #64 x 0x0ffffffc0fffffff < (0x1000000000000000 <: uint_t 64))
(fun () -> bv_tac_lt 64);
assert_by_tactic
(logand #64 x 0x0ffffffc0ffffffc < (0x1000000000000000 <: uint_t 64))
(fun () -> bv_tac_lt 64);
assert_by_tactic
(mod #64 (logand #64 x 0x0ffffffc0ffffffc) 4 == (0 <: uint_t 64))
(fun () -> bv_tac ())
let lemma_and_commutes x y =
assert_by_tactic
(logand #64 x y == logand #64 y x)
bv_tac
let lemma_bv128_64_64_and_helper' (x0:bv_t 64) (x1:bv_t 64) (y0:bv_t 64) (y1:bv_t 64) :
Lemma (requires True)
(ensures ((bvor #128 (bvshl #128 (bv_uext #64 #64 (bvand #64 x1 y1)) 64)
(bv_uext #64 #64 (bvand #64 x0 y0))) ==
bvand #128 (bvor #128 (bvshl #128 (bv_uext #64 #64 x1) 64)
(bv_uext #64 #64 x0))
(bvor #128 (bvshl #128 (bv_uext #64 #64 y1) 64)
(bv_uext #64 #64 y0)))) = ()
// Rewrite all equalities and then the goal is trivial for Z3.
// Without rewriting this does not go through.
// I believe the reason is related to a previously reported issue with the way
// Z3 bit-blasts through the Boxing/Unboxing functions. I thought this was fixed
// but it may not be the case. Notice that by rewriting with tactics the solver
// only gets to see one big term without any boxing or unboxing inside it.
let lemma_bv128_64_64_and_helper x x0 x1 y y0 y1 z z0 z1 =
lemma_bv128_64_64_and_helper' x0 x1 y0 y1;
assert_by_tactic (z == bvand #128 x y)
(fun () -> destruct_conj ();
rewrite_eqs_from_context ())
let bv128_64_64 x0 x1 = bvor (bvshl (bv_uext #64 #64 x1) 64) (bv_uext #64 #64 x0)
unfold let uint_to_nat (#n:nat) (x:uint_t n) : r:nat{r = x} =
assert (x < pow2 n);
modulo_lemma x (pow2 n);
x
let uint_ext (#n : nat) (#m : nat{n <= m}) (x : uint_t n) : r:(uint_t m){uint_to_nat r = uint_to_nat x} =
assert_norm(fits x n);
pow2_le_compat m n;
assert_norm(fits x m);
modulo_lemma x (pow2 m);
to_uint_t m x
#reset-options "--smtencoding.elim_box true --smtencoding.l_arith_repr boxwrap --smtencoding.nl_arith_repr boxwrap"
let mul_bvshl (u:uint_t 64) :
Lemma (0x10000000000000000 * u < pow2 128 /\
(int2bv #128 (0x10000000000000000 * u) ==
bvshl (bv_uext #64 #64 (int2bv u)) 64)) =
assert_norm ( 0x10000000000000000 * pow2 63 < pow2 128);
modulo_lemma (0x10000000000000000 * u) (pow2 128);
assert_by_tactic
(int2bv #128 (mul_mod #128 0x10000000000000000 (uint_ext #64 #128 u)) ==
bvmul #128 (int2bv #128 0x10000000000000000) (uint_ext #64 #128 u))
(fun () -> mapply (`trans); arith_to_bv_tac (); trefl ())
#reset-options "--smtencoding.elim_box true"
let plus_bvor (u h:bv_t 128) :
Lemma (bvand u h = bv_zero ==> bvadd u h == bvor u h) = ()
let lemma_bv128_64_64_and x x0 x1 y y0 y1 z z0 z1 =
assert_by_tactic (z == bvand #128 x y)
(fun () -> destruct_conj ();
rewrite_eqs_from_context ();
norm[delta])
#reset-options "--smtencoding.elim_box true --z3refresh --z3rlimit 20 --max_ifuel 1 --max_fuel 1"
let int2bv_uext_64_128 (x1 : nat) :
Lemma (requires (FStar.UInt.size x1 64))
(ensures (bv_uext #64 #64 (int2bv #64 x1) == int2bv #128 x1)) =
assert (64 <= 128);
pow2_le_compat 128 64;
assert (x1 < pow2 128);
modulo_lemma x1 (pow2 128); // x1 % pow2 128 = x1
assert (FStar.UInt.size x1 128);
assert_by_tactic (bv_uext #64 #64 (int2bv #64 x1) == int2bv #128 x1)
(fun () -> dump "..";
norm[delta_only [`%uint_ext; `%FStar.UInt.to_uint_t]];
// grewrite (quote (x1 % pow2 128)) (quote x1);
dump "After norm"; smt ())
#reset-options "--smtencoding.l_arith_repr native --smtencoding.nl_arith_repr wrapped --smtencoding.elim_box true --z3cliopt smt.arith.nl=false --max_fuel 1 --max_ifuel 0"
let lowerUpper128m (l:uint_t 64) (u:uint_t 64) : uint_t 128 =
add_hide #128 (mul_hide #128 (uext #64 #64 u) 0x10000000000000000) (uext #64 #64 l)
let lowerUpper128b (l:bv_t 64) (u:bv_t 64) : bv_t 128 =
b_add #128 (b_mul #128 (b_uext #64 #64 u) 0x10000000000000000) (b_uext #64 #64 l)
//this was so flaky, new options helped.
#reset-options "--smtencoding.elim_box true --z3refresh --z3rlimit 40 --max_ifuel 1 --max_fuel 1"
let lemma_lowerUpper128_andu
(x:uint_t 128) (x0:uint_t 64) (x1:uint_t 64) (y:uint_t 128)
(y0:uint_t 64) (y1:uint_t 64) (z:uint_t 128) (z0:uint_t 64) (z1:uint_t 64) :
Lemma
(requires
z0 == logand #64 x0 y0 /\
z1 == logand #64 x1 y1 /\
x == lowerUpper128u x0 x1 /\
y == lowerUpper128u y0 y1 /\
z == lowerUpper128u z0 z1)
(ensures z == logand #128 x y)
=
let bx0 = b_i2b x0 in
let bx1 = b_i2b x1 in
let by0 = b_i2b y0 in
let by1 = b_i2b y1 in
assert_norm (
lowerUpper128b (b_and bx0 by0) (b_and bx1 by1) ==
b_and (lowerUpper128b bx0 bx1) (lowerUpper128b by0 by1));
lemma_i2b_equal
(lowerUpper128m (logand x0 y0) (logand x1 y1))
(logand (lowerUpper128m x0 x1) (lowerUpper128m y0 y1));
assert_norm (lowerUpper128m x0 x1 == lowerUpper128u x0 x1);
assert_norm (lowerUpper128m y0 y1 == lowerUpper128u y0 y1);
assert_norm (lowerUpper128m z0 z1 == lowerUpper128u z0 z1);
()
#reset-options "--smtencoding.elim_box true --z3cliopt smt.case_split=3"
let lemma_bytes_shift_constants0 x =
assert_by_tactic (shift_left #64 0 3 == (0 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 0 == (0x1 <: uint_t 64)) bv_tac
let lemma_bytes_shift_constants1 x =
assert_by_tactic (shift_left #64 1 3 == (8 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 8 == (0x100 <: uint_t 64)) bv_tac
let lemma_bytes_shift_constants2 x =
assert_by_tactic (shift_left #64 2 3 == (16 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 16 == (0x10000 <: uint_t 64)) bv_tac
let lemma_bytes_shift_constants3 x =
assert_by_tactic (shift_left #64 3 3 == (24 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 24 == (0x1000000 <: uint_t 64)) bv_tac
let lemma_bytes_shift_constants4 x =
assert_by_tactic (shift_left #64 4 3 == (32 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 32 == (0x100000000 <: uint_t 64)) bv_tac
let lemma_bytes_shift_constants5 x =
assert_by_tactic (shift_left #64 5 3 == (40 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 40 == (0x10000000000 <: uint_t 64)) bv_tac
let lemma_bytes_shift_constants6 x =
assert_by_tactic (shift_left #64 6 3 == (48 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 48 == (0x1000000000000 <: uint_t 64)) bv_tac
let lemma_bytes_shift_constants7 x =
assert_by_tactic (shift_left #64 7 3 == (56 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 56 == (0x100000000000000 <: uint_t 64)) bv_tac
let lemma_bytes_and_mod0 x =
assert_by_tactic (logand #64 x (0x1 - 1) == mod #64 x 0x1) bv_tac
let lemma_bytes_and_mod1 x =
assert_by_tactic (logand #64 x (0x100 - 1) == mod #64 x 0x100) bv_tac
let lemma_bytes_and_mod2 x =
assert_by_tactic (logand #64 x (0x10000 - 1) == mod #64 x 0x10000) bv_tac
let lemma_bytes_and_mod3 x =
assert_by_tactic (logand #64 x (0x1000000 - 1) == mod #64 x 0x1000000) bv_tac
let lemma_bytes_and_mod4 x =
assert_by_tactic (logand #64 x (0x100000000 - 1) == mod #64 x 0x100000000) bv_tac
let lemma_bytes_and_mod5 x =
assert_by_tactic (logand #64 x (0x10000000000 - 1) == mod #64 x 0x10000000000) bv_tac
let lemma_bytes_and_mod6 x =
assert_by_tactic (logand #64 x (0x1000000000000 - 1) == mod #64 x 0x1000000000000) bv_tac | {
"checked_file": "/",
"dependencies": [
"Vale.Math.Bits.fsti.checked",
"Vale.Lib.Tactics.fst.checked",
"Vale.Lib.Bv_s.fst.checked",
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Tactics.Derived.fst.checked",
"FStar.Tactics.BV.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.BV.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Poly1305.Bitvectors.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Math.Bits",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Bv_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3",
"smt.case_split=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: FStar.UInt.uint_t 64
-> FStar.Pervasives.Lemma
(ensures FStar.UInt.logand x (0x100000000000000 - 1) == FStar.UInt.mod x 0x100000000000000) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.UInt.uint_t",
"FStar.Tactics.Effect.assert_by_tactic",
"Prims.eq2",
"FStar.UInt.logand",
"Prims.op_Subtraction",
"FStar.UInt.mod",
"FStar.Tactics.BV.bv_tac",
"Prims.unit"
] | [] | true | false | true | false | false | let lemma_bytes_and_mod7 x =
| assert_by_tactic (logand #64 x (0x100000000000000 - 1) == mod #64 x 0x100000000000000) bv_tac | false |
Vale.Poly1305.Bitvectors.fst | Vale.Poly1305.Bitvectors.lemma_and_mod_n | val lemma_and_mod_n: x:uint_t 64 -> Lemma (logand #64 x 3 == mod #64 x 4 /\
logand #64 x 15 == mod #64 x 16)
[SMTPat (logand #64 x 3);
SMTPat (logand #64 x 15)] | val lemma_and_mod_n: x:uint_t 64 -> Lemma (logand #64 x 3 == mod #64 x 4 /\
logand #64 x 15 == mod #64 x 16)
[SMTPat (logand #64 x 3);
SMTPat (logand #64 x 15)] | let lemma_and_mod_n x =
assert_by_tactic (logand #64 x 3 == mod #64 x 4) (bv_tac);
assert_by_tactic (logand #64 x 15 == mod #64 x 16) (bv_tac) | {
"file_name": "vale/code/crypto/poly1305/x64/Vale.Poly1305.Bitvectors.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 61,
"end_line": 26,
"start_col": 0,
"start_line": 24
} | module Vale.Poly1305.Bitvectors
open FStar.BV
open FStar.Tactics
open FStar.Tactics.Derived
open FStar.Tactics.BV
open FStar.Mul
open FStar.UInt
open FStar.Math.Lemmas
open Vale.Lib.Tactics
open Vale.Lib.Bv_s
open Vale.Math.Bits
// tweak options?
#reset-options "--smtencoding.elim_box true"
//NOTE: Using the split tactic seems to slowdown execution by a lot.
let lemma_shr2 x =
assert_by_tactic (shift_right #64 x 2 == udiv #64 x 4) bv_tac
let lemma_shr4 x =
assert_by_tactic (shift_right #64 x 4 == udiv #64 x 16) bv_tac | {
"checked_file": "/",
"dependencies": [
"Vale.Math.Bits.fsti.checked",
"Vale.Lib.Tactics.fst.checked",
"Vale.Lib.Bv_s.fst.checked",
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Tactics.Derived.fst.checked",
"FStar.Tactics.BV.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.BV.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Poly1305.Bitvectors.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Math.Bits",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Bv_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: FStar.UInt.uint_t 64
-> FStar.Pervasives.Lemma
(ensures
FStar.UInt.logand x 3 == FStar.UInt.mod x 4 /\ FStar.UInt.logand x 15 == FStar.UInt.mod x 16
) [SMTPat (FStar.UInt.logand x 3); SMTPat (FStar.UInt.logand x 15)] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.UInt.uint_t",
"FStar.Tactics.Effect.assert_by_tactic",
"Prims.eq2",
"FStar.UInt.logand",
"FStar.UInt.mod",
"FStar.Tactics.BV.bv_tac",
"Prims.unit"
] | [] | true | false | true | false | false | let lemma_and_mod_n x =
| assert_by_tactic (logand #64 x 3 == mod #64 x 4) (bv_tac);
assert_by_tactic (logand #64 x 15 == mod #64 x 16) (bv_tac) | false |
Vale.Poly1305.Bitvectors.fst | Vale.Poly1305.Bitvectors.lemma_bytes_shift_constants3 | val lemma_bytes_shift_constants3: unit -> Lemma
(shift_left #64 3 3 == 24 /\
shift_left #64 1 (shift_left #64 3 3) == 0x1000000) | val lemma_bytes_shift_constants3: unit -> Lemma
(shift_left #64 3 3 == 24 /\
shift_left #64 1 (shift_left #64 3 3) == 0x1000000) | let lemma_bytes_shift_constants3 x =
assert_by_tactic (shift_left #64 3 3 == (24 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 24 == (0x1000000 <: uint_t 64)) bv_tac | {
"file_name": "vale/code/crypto/poly1305/x64/Vale.Poly1305.Bitvectors.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 75,
"end_line": 179,
"start_col": 0,
"start_line": 177
} | module Vale.Poly1305.Bitvectors
open FStar.BV
open FStar.Tactics
open FStar.Tactics.Derived
open FStar.Tactics.BV
open FStar.Mul
open FStar.UInt
open FStar.Math.Lemmas
open Vale.Lib.Tactics
open Vale.Lib.Bv_s
open Vale.Math.Bits
// tweak options?
#reset-options "--smtencoding.elim_box true"
//NOTE: Using the split tactic seems to slowdown execution by a lot.
let lemma_shr2 x =
assert_by_tactic (shift_right #64 x 2 == udiv #64 x 4) bv_tac
let lemma_shr4 x =
assert_by_tactic (shift_right #64 x 4 == udiv #64 x 16) bv_tac
let lemma_and_mod_n x =
assert_by_tactic (logand #64 x 3 == mod #64 x 4) (bv_tac);
assert_by_tactic (logand #64 x 15 == mod #64 x 16) (bv_tac)
let lemma_clear_lower_2 x =
assert_by_tactic
(logand #64 x 0xfffffffffffffffc == mul_mod #64 (udiv #64 x 4) 4)
bv_tac
let lemma_and_constants x =
assert_by_tactic (logand #64 x 0 == (0 <: uint_t 64)) bv_tac;
assert_by_tactic (logand #64 x 0xffffffffffffffff == x) bv_tac
let lemma_poly_constants x =
// using split in this seems to hang execution.
assert_by_tactic
(logand #64 x 0x0ffffffc0fffffff < (0x1000000000000000 <: uint_t 64))
(fun () -> bv_tac_lt 64);
assert_by_tactic
(logand #64 x 0x0ffffffc0ffffffc < (0x1000000000000000 <: uint_t 64))
(fun () -> bv_tac_lt 64);
assert_by_tactic
(mod #64 (logand #64 x 0x0ffffffc0ffffffc) 4 == (0 <: uint_t 64))
(fun () -> bv_tac ())
let lemma_and_commutes x y =
assert_by_tactic
(logand #64 x y == logand #64 y x)
bv_tac
let lemma_bv128_64_64_and_helper' (x0:bv_t 64) (x1:bv_t 64) (y0:bv_t 64) (y1:bv_t 64) :
Lemma (requires True)
(ensures ((bvor #128 (bvshl #128 (bv_uext #64 #64 (bvand #64 x1 y1)) 64)
(bv_uext #64 #64 (bvand #64 x0 y0))) ==
bvand #128 (bvor #128 (bvshl #128 (bv_uext #64 #64 x1) 64)
(bv_uext #64 #64 x0))
(bvor #128 (bvshl #128 (bv_uext #64 #64 y1) 64)
(bv_uext #64 #64 y0)))) = ()
// Rewrite all equalities and then the goal is trivial for Z3.
// Without rewriting this does not go through.
// I believe the reason is related to a previously reported issue with the way
// Z3 bit-blasts through the Boxing/Unboxing functions. I thought this was fixed
// but it may not be the case. Notice that by rewriting with tactics the solver
// only gets to see one big term without any boxing or unboxing inside it.
let lemma_bv128_64_64_and_helper x x0 x1 y y0 y1 z z0 z1 =
lemma_bv128_64_64_and_helper' x0 x1 y0 y1;
assert_by_tactic (z == bvand #128 x y)
(fun () -> destruct_conj ();
rewrite_eqs_from_context ())
let bv128_64_64 x0 x1 = bvor (bvshl (bv_uext #64 #64 x1) 64) (bv_uext #64 #64 x0)
unfold let uint_to_nat (#n:nat) (x:uint_t n) : r:nat{r = x} =
assert (x < pow2 n);
modulo_lemma x (pow2 n);
x
let uint_ext (#n : nat) (#m : nat{n <= m}) (x : uint_t n) : r:(uint_t m){uint_to_nat r = uint_to_nat x} =
assert_norm(fits x n);
pow2_le_compat m n;
assert_norm(fits x m);
modulo_lemma x (pow2 m);
to_uint_t m x
#reset-options "--smtencoding.elim_box true --smtencoding.l_arith_repr boxwrap --smtencoding.nl_arith_repr boxwrap"
let mul_bvshl (u:uint_t 64) :
Lemma (0x10000000000000000 * u < pow2 128 /\
(int2bv #128 (0x10000000000000000 * u) ==
bvshl (bv_uext #64 #64 (int2bv u)) 64)) =
assert_norm ( 0x10000000000000000 * pow2 63 < pow2 128);
modulo_lemma (0x10000000000000000 * u) (pow2 128);
assert_by_tactic
(int2bv #128 (mul_mod #128 0x10000000000000000 (uint_ext #64 #128 u)) ==
bvmul #128 (int2bv #128 0x10000000000000000) (uint_ext #64 #128 u))
(fun () -> mapply (`trans); arith_to_bv_tac (); trefl ())
#reset-options "--smtencoding.elim_box true"
let plus_bvor (u h:bv_t 128) :
Lemma (bvand u h = bv_zero ==> bvadd u h == bvor u h) = ()
let lemma_bv128_64_64_and x x0 x1 y y0 y1 z z0 z1 =
assert_by_tactic (z == bvand #128 x y)
(fun () -> destruct_conj ();
rewrite_eqs_from_context ();
norm[delta])
#reset-options "--smtencoding.elim_box true --z3refresh --z3rlimit 20 --max_ifuel 1 --max_fuel 1"
let int2bv_uext_64_128 (x1 : nat) :
Lemma (requires (FStar.UInt.size x1 64))
(ensures (bv_uext #64 #64 (int2bv #64 x1) == int2bv #128 x1)) =
assert (64 <= 128);
pow2_le_compat 128 64;
assert (x1 < pow2 128);
modulo_lemma x1 (pow2 128); // x1 % pow2 128 = x1
assert (FStar.UInt.size x1 128);
assert_by_tactic (bv_uext #64 #64 (int2bv #64 x1) == int2bv #128 x1)
(fun () -> dump "..";
norm[delta_only [`%uint_ext; `%FStar.UInt.to_uint_t]];
// grewrite (quote (x1 % pow2 128)) (quote x1);
dump "After norm"; smt ())
#reset-options "--smtencoding.l_arith_repr native --smtencoding.nl_arith_repr wrapped --smtencoding.elim_box true --z3cliopt smt.arith.nl=false --max_fuel 1 --max_ifuel 0"
let lowerUpper128m (l:uint_t 64) (u:uint_t 64) : uint_t 128 =
add_hide #128 (mul_hide #128 (uext #64 #64 u) 0x10000000000000000) (uext #64 #64 l)
let lowerUpper128b (l:bv_t 64) (u:bv_t 64) : bv_t 128 =
b_add #128 (b_mul #128 (b_uext #64 #64 u) 0x10000000000000000) (b_uext #64 #64 l)
//this was so flaky, new options helped.
#reset-options "--smtencoding.elim_box true --z3refresh --z3rlimit 40 --max_ifuel 1 --max_fuel 1"
let lemma_lowerUpper128_andu
(x:uint_t 128) (x0:uint_t 64) (x1:uint_t 64) (y:uint_t 128)
(y0:uint_t 64) (y1:uint_t 64) (z:uint_t 128) (z0:uint_t 64) (z1:uint_t 64) :
Lemma
(requires
z0 == logand #64 x0 y0 /\
z1 == logand #64 x1 y1 /\
x == lowerUpper128u x0 x1 /\
y == lowerUpper128u y0 y1 /\
z == lowerUpper128u z0 z1)
(ensures z == logand #128 x y)
=
let bx0 = b_i2b x0 in
let bx1 = b_i2b x1 in
let by0 = b_i2b y0 in
let by1 = b_i2b y1 in
assert_norm (
lowerUpper128b (b_and bx0 by0) (b_and bx1 by1) ==
b_and (lowerUpper128b bx0 bx1) (lowerUpper128b by0 by1));
lemma_i2b_equal
(lowerUpper128m (logand x0 y0) (logand x1 y1))
(logand (lowerUpper128m x0 x1) (lowerUpper128m y0 y1));
assert_norm (lowerUpper128m x0 x1 == lowerUpper128u x0 x1);
assert_norm (lowerUpper128m y0 y1 == lowerUpper128u y0 y1);
assert_norm (lowerUpper128m z0 z1 == lowerUpper128u z0 z1);
()
#reset-options "--smtencoding.elim_box true --z3cliopt smt.case_split=3"
let lemma_bytes_shift_constants0 x =
assert_by_tactic (shift_left #64 0 3 == (0 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 0 == (0x1 <: uint_t 64)) bv_tac
let lemma_bytes_shift_constants1 x =
assert_by_tactic (shift_left #64 1 3 == (8 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 8 == (0x100 <: uint_t 64)) bv_tac
let lemma_bytes_shift_constants2 x =
assert_by_tactic (shift_left #64 2 3 == (16 <: uint_t 64)) bv_tac; | {
"checked_file": "/",
"dependencies": [
"Vale.Math.Bits.fsti.checked",
"Vale.Lib.Tactics.fst.checked",
"Vale.Lib.Bv_s.fst.checked",
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Tactics.Derived.fst.checked",
"FStar.Tactics.BV.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.BV.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Poly1305.Bitvectors.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Math.Bits",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Bv_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3",
"smt.case_split=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: Prims.unit
-> FStar.Pervasives.Lemma
(ensures
FStar.UInt.shift_left 3 3 == 24 /\
FStar.UInt.shift_left 1 (FStar.UInt.shift_left 3 3) == 0x1000000) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.unit",
"FStar.Tactics.Effect.assert_by_tactic",
"Prims.eq2",
"FStar.UInt.uint_t",
"FStar.UInt.shift_left",
"FStar.Tactics.BV.bv_tac"
] | [] | true | false | true | false | false | let lemma_bytes_shift_constants3 x =
| assert_by_tactic (shift_left #64 3 3 == (24 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 24 == (0x1000000 <: uint_t 64)) bv_tac | false |
Steel.Effect.Common.fst | Steel.Effect.Common.emp | val emp : vprop | val emp : vprop | let emp = VUnit emp' | {
"file_name": "lib/steel/Steel.Effect.Common.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 20,
"end_line": 61,
"start_col": 0,
"start_line": 61
} | (*
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.Effect.Common
module Sem = Steel.Semantics.Hoare.MST
module Mem = Steel.Memory
open Steel.Semantics.Instantiate
module FExt = FStar.FunctionalExtensionality
let h_exists #a f = VUnit ({hp = Mem.h_exists (fun x -> hp_of (f x)); t = unit; sel = fun _ -> ()})
let can_be_split (p q:vprop) : prop = Mem.slimp (hp_of p) (hp_of q)
let reveal_can_be_split () = ()
let can_be_split_interp r r' h = ()
let can_be_split_trans p q r = ()
let can_be_split_star_l p q = ()
let can_be_split_star_r p q = ()
let can_be_split_refl p = ()
let can_be_split_congr_l p q r =
Classical.forall_intro (interp_star (hp_of p) (hp_of r));
Classical.forall_intro (interp_star (hp_of q) (hp_of r))
let can_be_split_congr_r p q r =
Classical.forall_intro (interp_star (hp_of r) (hp_of p));
Classical.forall_intro (interp_star (hp_of r) (hp_of q))
let equiv (p q:vprop) : prop = Mem.equiv (hp_of p) (hp_of q) /\ True
let reveal_equiv p q = ()
let valid_rmem (#frame:vprop) (h:rmem' frame) : prop =
forall (p p1 p2:vprop). can_be_split frame p /\ p == VStar p1 p2 ==>
(h p1, h p2) == h (VStar p1 p2)
let lemma_valid_mk_rmem (r:vprop) (h:hmem r) = ()
let reveal_mk_rmem (r:vprop) (h:hmem r) (r0:vprop{r `can_be_split` r0})
: Lemma ((mk_rmem r h) r0 == sel_of r0 h)
= FExt.feq_on_domain_g (unrestricted_mk_rmem r h)
let emp':vprop' =
{ hp = emp;
t = unit; | {
"checked_file": "/",
"dependencies": [
"Steel.Semantics.Instantiate.fsti.checked",
"Steel.Semantics.Hoare.MST.fst.checked",
"Steel.Memory.fsti.checked",
"prims.fst.checked",
"FStar.PropositionalExtensionality.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Effect.Common.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "FExt"
},
{
"abbrev": false,
"full_module": "Steel.Semantics.Instantiate",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": true,
"full_module": "Steel.Semantics.Hoare.MST",
"short_module": "Sem"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "FExt"
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Steel.Effect.Common.vprop | Prims.Tot | [
"total"
] | [] | [
"Steel.Effect.Common.VUnit",
"Steel.Effect.Common.emp'"
] | [] | false | false | false | true | false | let emp =
| VUnit emp' | false |
Vale.Poly1305.Bitvectors.fst | Vale.Poly1305.Bitvectors.lemma_bytes_shift_constants5 | val lemma_bytes_shift_constants5: unit -> Lemma
(shift_left #64 5 3 == 40 /\
shift_left #64 1 (shift_left #64 5 3) == 0x10000000000) | val lemma_bytes_shift_constants5: unit -> Lemma
(shift_left #64 5 3 == 40 /\
shift_left #64 1 (shift_left #64 5 3) == 0x10000000000) | let lemma_bytes_shift_constants5 x =
assert_by_tactic (shift_left #64 5 3 == (40 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 40 == (0x10000000000 <: uint_t 64)) bv_tac | {
"file_name": "vale/code/crypto/poly1305/x64/Vale.Poly1305.Bitvectors.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 79,
"end_line": 185,
"start_col": 0,
"start_line": 183
} | module Vale.Poly1305.Bitvectors
open FStar.BV
open FStar.Tactics
open FStar.Tactics.Derived
open FStar.Tactics.BV
open FStar.Mul
open FStar.UInt
open FStar.Math.Lemmas
open Vale.Lib.Tactics
open Vale.Lib.Bv_s
open Vale.Math.Bits
// tweak options?
#reset-options "--smtencoding.elim_box true"
//NOTE: Using the split tactic seems to slowdown execution by a lot.
let lemma_shr2 x =
assert_by_tactic (shift_right #64 x 2 == udiv #64 x 4) bv_tac
let lemma_shr4 x =
assert_by_tactic (shift_right #64 x 4 == udiv #64 x 16) bv_tac
let lemma_and_mod_n x =
assert_by_tactic (logand #64 x 3 == mod #64 x 4) (bv_tac);
assert_by_tactic (logand #64 x 15 == mod #64 x 16) (bv_tac)
let lemma_clear_lower_2 x =
assert_by_tactic
(logand #64 x 0xfffffffffffffffc == mul_mod #64 (udiv #64 x 4) 4)
bv_tac
let lemma_and_constants x =
assert_by_tactic (logand #64 x 0 == (0 <: uint_t 64)) bv_tac;
assert_by_tactic (logand #64 x 0xffffffffffffffff == x) bv_tac
let lemma_poly_constants x =
// using split in this seems to hang execution.
assert_by_tactic
(logand #64 x 0x0ffffffc0fffffff < (0x1000000000000000 <: uint_t 64))
(fun () -> bv_tac_lt 64);
assert_by_tactic
(logand #64 x 0x0ffffffc0ffffffc < (0x1000000000000000 <: uint_t 64))
(fun () -> bv_tac_lt 64);
assert_by_tactic
(mod #64 (logand #64 x 0x0ffffffc0ffffffc) 4 == (0 <: uint_t 64))
(fun () -> bv_tac ())
let lemma_and_commutes x y =
assert_by_tactic
(logand #64 x y == logand #64 y x)
bv_tac
let lemma_bv128_64_64_and_helper' (x0:bv_t 64) (x1:bv_t 64) (y0:bv_t 64) (y1:bv_t 64) :
Lemma (requires True)
(ensures ((bvor #128 (bvshl #128 (bv_uext #64 #64 (bvand #64 x1 y1)) 64)
(bv_uext #64 #64 (bvand #64 x0 y0))) ==
bvand #128 (bvor #128 (bvshl #128 (bv_uext #64 #64 x1) 64)
(bv_uext #64 #64 x0))
(bvor #128 (bvshl #128 (bv_uext #64 #64 y1) 64)
(bv_uext #64 #64 y0)))) = ()
// Rewrite all equalities and then the goal is trivial for Z3.
// Without rewriting this does not go through.
// I believe the reason is related to a previously reported issue with the way
// Z3 bit-blasts through the Boxing/Unboxing functions. I thought this was fixed
// but it may not be the case. Notice that by rewriting with tactics the solver
// only gets to see one big term without any boxing or unboxing inside it.
let lemma_bv128_64_64_and_helper x x0 x1 y y0 y1 z z0 z1 =
lemma_bv128_64_64_and_helper' x0 x1 y0 y1;
assert_by_tactic (z == bvand #128 x y)
(fun () -> destruct_conj ();
rewrite_eqs_from_context ())
let bv128_64_64 x0 x1 = bvor (bvshl (bv_uext #64 #64 x1) 64) (bv_uext #64 #64 x0)
unfold let uint_to_nat (#n:nat) (x:uint_t n) : r:nat{r = x} =
assert (x < pow2 n);
modulo_lemma x (pow2 n);
x
let uint_ext (#n : nat) (#m : nat{n <= m}) (x : uint_t n) : r:(uint_t m){uint_to_nat r = uint_to_nat x} =
assert_norm(fits x n);
pow2_le_compat m n;
assert_norm(fits x m);
modulo_lemma x (pow2 m);
to_uint_t m x
#reset-options "--smtencoding.elim_box true --smtencoding.l_arith_repr boxwrap --smtencoding.nl_arith_repr boxwrap"
let mul_bvshl (u:uint_t 64) :
Lemma (0x10000000000000000 * u < pow2 128 /\
(int2bv #128 (0x10000000000000000 * u) ==
bvshl (bv_uext #64 #64 (int2bv u)) 64)) =
assert_norm ( 0x10000000000000000 * pow2 63 < pow2 128);
modulo_lemma (0x10000000000000000 * u) (pow2 128);
assert_by_tactic
(int2bv #128 (mul_mod #128 0x10000000000000000 (uint_ext #64 #128 u)) ==
bvmul #128 (int2bv #128 0x10000000000000000) (uint_ext #64 #128 u))
(fun () -> mapply (`trans); arith_to_bv_tac (); trefl ())
#reset-options "--smtencoding.elim_box true"
let plus_bvor (u h:bv_t 128) :
Lemma (bvand u h = bv_zero ==> bvadd u h == bvor u h) = ()
let lemma_bv128_64_64_and x x0 x1 y y0 y1 z z0 z1 =
assert_by_tactic (z == bvand #128 x y)
(fun () -> destruct_conj ();
rewrite_eqs_from_context ();
norm[delta])
#reset-options "--smtencoding.elim_box true --z3refresh --z3rlimit 20 --max_ifuel 1 --max_fuel 1"
let int2bv_uext_64_128 (x1 : nat) :
Lemma (requires (FStar.UInt.size x1 64))
(ensures (bv_uext #64 #64 (int2bv #64 x1) == int2bv #128 x1)) =
assert (64 <= 128);
pow2_le_compat 128 64;
assert (x1 < pow2 128);
modulo_lemma x1 (pow2 128); // x1 % pow2 128 = x1
assert (FStar.UInt.size x1 128);
assert_by_tactic (bv_uext #64 #64 (int2bv #64 x1) == int2bv #128 x1)
(fun () -> dump "..";
norm[delta_only [`%uint_ext; `%FStar.UInt.to_uint_t]];
// grewrite (quote (x1 % pow2 128)) (quote x1);
dump "After norm"; smt ())
#reset-options "--smtencoding.l_arith_repr native --smtencoding.nl_arith_repr wrapped --smtencoding.elim_box true --z3cliopt smt.arith.nl=false --max_fuel 1 --max_ifuel 0"
let lowerUpper128m (l:uint_t 64) (u:uint_t 64) : uint_t 128 =
add_hide #128 (mul_hide #128 (uext #64 #64 u) 0x10000000000000000) (uext #64 #64 l)
let lowerUpper128b (l:bv_t 64) (u:bv_t 64) : bv_t 128 =
b_add #128 (b_mul #128 (b_uext #64 #64 u) 0x10000000000000000) (b_uext #64 #64 l)
//this was so flaky, new options helped.
#reset-options "--smtencoding.elim_box true --z3refresh --z3rlimit 40 --max_ifuel 1 --max_fuel 1"
let lemma_lowerUpper128_andu
(x:uint_t 128) (x0:uint_t 64) (x1:uint_t 64) (y:uint_t 128)
(y0:uint_t 64) (y1:uint_t 64) (z:uint_t 128) (z0:uint_t 64) (z1:uint_t 64) :
Lemma
(requires
z0 == logand #64 x0 y0 /\
z1 == logand #64 x1 y1 /\
x == lowerUpper128u x0 x1 /\
y == lowerUpper128u y0 y1 /\
z == lowerUpper128u z0 z1)
(ensures z == logand #128 x y)
=
let bx0 = b_i2b x0 in
let bx1 = b_i2b x1 in
let by0 = b_i2b y0 in
let by1 = b_i2b y1 in
assert_norm (
lowerUpper128b (b_and bx0 by0) (b_and bx1 by1) ==
b_and (lowerUpper128b bx0 bx1) (lowerUpper128b by0 by1));
lemma_i2b_equal
(lowerUpper128m (logand x0 y0) (logand x1 y1))
(logand (lowerUpper128m x0 x1) (lowerUpper128m y0 y1));
assert_norm (lowerUpper128m x0 x1 == lowerUpper128u x0 x1);
assert_norm (lowerUpper128m y0 y1 == lowerUpper128u y0 y1);
assert_norm (lowerUpper128m z0 z1 == lowerUpper128u z0 z1);
()
#reset-options "--smtencoding.elim_box true --z3cliopt smt.case_split=3"
let lemma_bytes_shift_constants0 x =
assert_by_tactic (shift_left #64 0 3 == (0 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 0 == (0x1 <: uint_t 64)) bv_tac
let lemma_bytes_shift_constants1 x =
assert_by_tactic (shift_left #64 1 3 == (8 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 8 == (0x100 <: uint_t 64)) bv_tac
let lemma_bytes_shift_constants2 x =
assert_by_tactic (shift_left #64 2 3 == (16 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 16 == (0x10000 <: uint_t 64)) bv_tac
let lemma_bytes_shift_constants3 x =
assert_by_tactic (shift_left #64 3 3 == (24 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 24 == (0x1000000 <: uint_t 64)) bv_tac
let lemma_bytes_shift_constants4 x =
assert_by_tactic (shift_left #64 4 3 == (32 <: uint_t 64)) bv_tac; | {
"checked_file": "/",
"dependencies": [
"Vale.Math.Bits.fsti.checked",
"Vale.Lib.Tactics.fst.checked",
"Vale.Lib.Bv_s.fst.checked",
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Tactics.Derived.fst.checked",
"FStar.Tactics.BV.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.BV.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Poly1305.Bitvectors.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Math.Bits",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Bv_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3",
"smt.case_split=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: Prims.unit
-> FStar.Pervasives.Lemma
(ensures
FStar.UInt.shift_left 5 3 == 40 /\
FStar.UInt.shift_left 1 (FStar.UInt.shift_left 5 3) == 0x10000000000) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.unit",
"FStar.Tactics.Effect.assert_by_tactic",
"Prims.eq2",
"FStar.UInt.uint_t",
"FStar.UInt.shift_left",
"FStar.Tactics.BV.bv_tac"
] | [] | true | false | true | false | false | let lemma_bytes_shift_constants5 x =
| assert_by_tactic (shift_left #64 5 3 == (40 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 40 == (0x10000000000 <: uint_t 64)) bv_tac | false |
Steel.Effect.Common.fst | Steel.Effect.Common.h_exists | val h_exists : f: (_: _ -> Steel.Effect.Common.vprop) -> Steel.Effect.Common.vprop | let h_exists #a f = VUnit ({hp = Mem.h_exists (fun x -> hp_of (f x)); t = unit; sel = fun _ -> ()}) | {
"file_name": "lib/steel/Steel.Effect.Common.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 99,
"end_line": 23,
"start_col": 0,
"start_line": 23
} | (*
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.Effect.Common
module Sem = Steel.Semantics.Hoare.MST
module Mem = Steel.Memory
open Steel.Semantics.Instantiate
module FExt = FStar.FunctionalExtensionality | {
"checked_file": "/",
"dependencies": [
"Steel.Semantics.Instantiate.fsti.checked",
"Steel.Semantics.Hoare.MST.fst.checked",
"Steel.Memory.fsti.checked",
"prims.fst.checked",
"FStar.PropositionalExtensionality.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Effect.Common.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "FExt"
},
{
"abbrev": false,
"full_module": "Steel.Semantics.Instantiate",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": true,
"full_module": "Steel.Semantics.Hoare.MST",
"short_module": "Sem"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "FExt"
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | f: (_: _ -> Steel.Effect.Common.vprop) -> Steel.Effect.Common.vprop | Prims.Tot | [
"total"
] | [] | [
"Steel.Effect.Common.vprop",
"Steel.Effect.Common.VUnit",
"Steel.Effect.Common.Mkvprop'",
"Steel.Memory.h_exists",
"Steel.Effect.Common.hp_of",
"Steel.Memory.slprop",
"Prims.unit",
"Steel.Memory.hmem"
] | [] | false | false | false | true | false | let h_exists #a f =
| VUnit ({ hp = Mem.h_exists (fun x -> hp_of (f x)); t = unit; sel = fun _ -> () }) | false |
|
Vale.Poly1305.Bitvectors.fst | Vale.Poly1305.Bitvectors.lemma_bytes_shift_constants1 | val lemma_bytes_shift_constants1: unit -> Lemma
(shift_left #64 1 3 == 8 /\
shift_left #64 1 (shift_left #64 1 3) == 0x100) | val lemma_bytes_shift_constants1: unit -> Lemma
(shift_left #64 1 3 == 8 /\
shift_left #64 1 (shift_left #64 1 3) == 0x100) | let lemma_bytes_shift_constants1 x =
assert_by_tactic (shift_left #64 1 3 == (8 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 8 == (0x100 <: uint_t 64)) bv_tac | {
"file_name": "vale/code/crypto/poly1305/x64/Vale.Poly1305.Bitvectors.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 70,
"end_line": 173,
"start_col": 0,
"start_line": 171
} | module Vale.Poly1305.Bitvectors
open FStar.BV
open FStar.Tactics
open FStar.Tactics.Derived
open FStar.Tactics.BV
open FStar.Mul
open FStar.UInt
open FStar.Math.Lemmas
open Vale.Lib.Tactics
open Vale.Lib.Bv_s
open Vale.Math.Bits
// tweak options?
#reset-options "--smtencoding.elim_box true"
//NOTE: Using the split tactic seems to slowdown execution by a lot.
let lemma_shr2 x =
assert_by_tactic (shift_right #64 x 2 == udiv #64 x 4) bv_tac
let lemma_shr4 x =
assert_by_tactic (shift_right #64 x 4 == udiv #64 x 16) bv_tac
let lemma_and_mod_n x =
assert_by_tactic (logand #64 x 3 == mod #64 x 4) (bv_tac);
assert_by_tactic (logand #64 x 15 == mod #64 x 16) (bv_tac)
let lemma_clear_lower_2 x =
assert_by_tactic
(logand #64 x 0xfffffffffffffffc == mul_mod #64 (udiv #64 x 4) 4)
bv_tac
let lemma_and_constants x =
assert_by_tactic (logand #64 x 0 == (0 <: uint_t 64)) bv_tac;
assert_by_tactic (logand #64 x 0xffffffffffffffff == x) bv_tac
let lemma_poly_constants x =
// using split in this seems to hang execution.
assert_by_tactic
(logand #64 x 0x0ffffffc0fffffff < (0x1000000000000000 <: uint_t 64))
(fun () -> bv_tac_lt 64);
assert_by_tactic
(logand #64 x 0x0ffffffc0ffffffc < (0x1000000000000000 <: uint_t 64))
(fun () -> bv_tac_lt 64);
assert_by_tactic
(mod #64 (logand #64 x 0x0ffffffc0ffffffc) 4 == (0 <: uint_t 64))
(fun () -> bv_tac ())
let lemma_and_commutes x y =
assert_by_tactic
(logand #64 x y == logand #64 y x)
bv_tac
let lemma_bv128_64_64_and_helper' (x0:bv_t 64) (x1:bv_t 64) (y0:bv_t 64) (y1:bv_t 64) :
Lemma (requires True)
(ensures ((bvor #128 (bvshl #128 (bv_uext #64 #64 (bvand #64 x1 y1)) 64)
(bv_uext #64 #64 (bvand #64 x0 y0))) ==
bvand #128 (bvor #128 (bvshl #128 (bv_uext #64 #64 x1) 64)
(bv_uext #64 #64 x0))
(bvor #128 (bvshl #128 (bv_uext #64 #64 y1) 64)
(bv_uext #64 #64 y0)))) = ()
// Rewrite all equalities and then the goal is trivial for Z3.
// Without rewriting this does not go through.
// I believe the reason is related to a previously reported issue with the way
// Z3 bit-blasts through the Boxing/Unboxing functions. I thought this was fixed
// but it may not be the case. Notice that by rewriting with tactics the solver
// only gets to see one big term without any boxing or unboxing inside it.
let lemma_bv128_64_64_and_helper x x0 x1 y y0 y1 z z0 z1 =
lemma_bv128_64_64_and_helper' x0 x1 y0 y1;
assert_by_tactic (z == bvand #128 x y)
(fun () -> destruct_conj ();
rewrite_eqs_from_context ())
let bv128_64_64 x0 x1 = bvor (bvshl (bv_uext #64 #64 x1) 64) (bv_uext #64 #64 x0)
unfold let uint_to_nat (#n:nat) (x:uint_t n) : r:nat{r = x} =
assert (x < pow2 n);
modulo_lemma x (pow2 n);
x
let uint_ext (#n : nat) (#m : nat{n <= m}) (x : uint_t n) : r:(uint_t m){uint_to_nat r = uint_to_nat x} =
assert_norm(fits x n);
pow2_le_compat m n;
assert_norm(fits x m);
modulo_lemma x (pow2 m);
to_uint_t m x
#reset-options "--smtencoding.elim_box true --smtencoding.l_arith_repr boxwrap --smtencoding.nl_arith_repr boxwrap"
let mul_bvshl (u:uint_t 64) :
Lemma (0x10000000000000000 * u < pow2 128 /\
(int2bv #128 (0x10000000000000000 * u) ==
bvshl (bv_uext #64 #64 (int2bv u)) 64)) =
assert_norm ( 0x10000000000000000 * pow2 63 < pow2 128);
modulo_lemma (0x10000000000000000 * u) (pow2 128);
assert_by_tactic
(int2bv #128 (mul_mod #128 0x10000000000000000 (uint_ext #64 #128 u)) ==
bvmul #128 (int2bv #128 0x10000000000000000) (uint_ext #64 #128 u))
(fun () -> mapply (`trans); arith_to_bv_tac (); trefl ())
#reset-options "--smtencoding.elim_box true"
let plus_bvor (u h:bv_t 128) :
Lemma (bvand u h = bv_zero ==> bvadd u h == bvor u h) = ()
let lemma_bv128_64_64_and x x0 x1 y y0 y1 z z0 z1 =
assert_by_tactic (z == bvand #128 x y)
(fun () -> destruct_conj ();
rewrite_eqs_from_context ();
norm[delta])
#reset-options "--smtencoding.elim_box true --z3refresh --z3rlimit 20 --max_ifuel 1 --max_fuel 1"
let int2bv_uext_64_128 (x1 : nat) :
Lemma (requires (FStar.UInt.size x1 64))
(ensures (bv_uext #64 #64 (int2bv #64 x1) == int2bv #128 x1)) =
assert (64 <= 128);
pow2_le_compat 128 64;
assert (x1 < pow2 128);
modulo_lemma x1 (pow2 128); // x1 % pow2 128 = x1
assert (FStar.UInt.size x1 128);
assert_by_tactic (bv_uext #64 #64 (int2bv #64 x1) == int2bv #128 x1)
(fun () -> dump "..";
norm[delta_only [`%uint_ext; `%FStar.UInt.to_uint_t]];
// grewrite (quote (x1 % pow2 128)) (quote x1);
dump "After norm"; smt ())
#reset-options "--smtencoding.l_arith_repr native --smtencoding.nl_arith_repr wrapped --smtencoding.elim_box true --z3cliopt smt.arith.nl=false --max_fuel 1 --max_ifuel 0"
let lowerUpper128m (l:uint_t 64) (u:uint_t 64) : uint_t 128 =
add_hide #128 (mul_hide #128 (uext #64 #64 u) 0x10000000000000000) (uext #64 #64 l)
let lowerUpper128b (l:bv_t 64) (u:bv_t 64) : bv_t 128 =
b_add #128 (b_mul #128 (b_uext #64 #64 u) 0x10000000000000000) (b_uext #64 #64 l)
//this was so flaky, new options helped.
#reset-options "--smtencoding.elim_box true --z3refresh --z3rlimit 40 --max_ifuel 1 --max_fuel 1"
let lemma_lowerUpper128_andu
(x:uint_t 128) (x0:uint_t 64) (x1:uint_t 64) (y:uint_t 128)
(y0:uint_t 64) (y1:uint_t 64) (z:uint_t 128) (z0:uint_t 64) (z1:uint_t 64) :
Lemma
(requires
z0 == logand #64 x0 y0 /\
z1 == logand #64 x1 y1 /\
x == lowerUpper128u x0 x1 /\
y == lowerUpper128u y0 y1 /\
z == lowerUpper128u z0 z1)
(ensures z == logand #128 x y)
=
let bx0 = b_i2b x0 in
let bx1 = b_i2b x1 in
let by0 = b_i2b y0 in
let by1 = b_i2b y1 in
assert_norm (
lowerUpper128b (b_and bx0 by0) (b_and bx1 by1) ==
b_and (lowerUpper128b bx0 bx1) (lowerUpper128b by0 by1));
lemma_i2b_equal
(lowerUpper128m (logand x0 y0) (logand x1 y1))
(logand (lowerUpper128m x0 x1) (lowerUpper128m y0 y1));
assert_norm (lowerUpper128m x0 x1 == lowerUpper128u x0 x1);
assert_norm (lowerUpper128m y0 y1 == lowerUpper128u y0 y1);
assert_norm (lowerUpper128m z0 z1 == lowerUpper128u z0 z1);
()
#reset-options "--smtencoding.elim_box true --z3cliopt smt.case_split=3"
let lemma_bytes_shift_constants0 x =
assert_by_tactic (shift_left #64 0 3 == (0 <: uint_t 64)) bv_tac; | {
"checked_file": "/",
"dependencies": [
"Vale.Math.Bits.fsti.checked",
"Vale.Lib.Tactics.fst.checked",
"Vale.Lib.Bv_s.fst.checked",
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Tactics.Derived.fst.checked",
"FStar.Tactics.BV.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.BV.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Poly1305.Bitvectors.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Math.Bits",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Bv_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3",
"smt.case_split=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: Prims.unit
-> FStar.Pervasives.Lemma
(ensures
FStar.UInt.shift_left 1 3 == 8 /\ FStar.UInt.shift_left 1 (FStar.UInt.shift_left 1 3) == 0x100
) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.unit",
"FStar.Tactics.Effect.assert_by_tactic",
"Prims.eq2",
"FStar.UInt.uint_t",
"FStar.UInt.shift_left",
"FStar.Tactics.BV.bv_tac"
] | [] | true | false | true | false | false | let lemma_bytes_shift_constants1 x =
| assert_by_tactic (shift_left #64 1 3 == (8 <: uint_t 64)) bv_tac;
assert_by_tactic (shift_left #64 1 8 == (0x100 <: uint_t 64)) bv_tac | false |
Steel.Effect.Common.fst | Steel.Effect.Common.can_be_split_congr_l | val can_be_split_congr_l
(p q r: vprop)
: Lemma
(requires (p `can_be_split` q))
(ensures ((p `star` r) `can_be_split` (q `star` r))) | val can_be_split_congr_l
(p q r: vprop)
: Lemma
(requires (p `can_be_split` q))
(ensures ((p `star` r) `can_be_split` (q `star` r))) | let can_be_split_congr_l p q r =
Classical.forall_intro (interp_star (hp_of p) (hp_of r));
Classical.forall_intro (interp_star (hp_of q) (hp_of r)) | {
"file_name": "lib/steel/Steel.Effect.Common.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 58,
"end_line": 38,
"start_col": 0,
"start_line": 36
} | (*
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.Effect.Common
module Sem = Steel.Semantics.Hoare.MST
module Mem = Steel.Memory
open Steel.Semantics.Instantiate
module FExt = FStar.FunctionalExtensionality
let h_exists #a f = VUnit ({hp = Mem.h_exists (fun x -> hp_of (f x)); t = unit; sel = fun _ -> ()})
let can_be_split (p q:vprop) : prop = Mem.slimp (hp_of p) (hp_of q)
let reveal_can_be_split () = ()
let can_be_split_interp r r' h = ()
let can_be_split_trans p q r = ()
let can_be_split_star_l p q = ()
let can_be_split_star_r p q = ()
let can_be_split_refl p = () | {
"checked_file": "/",
"dependencies": [
"Steel.Semantics.Instantiate.fsti.checked",
"Steel.Semantics.Hoare.MST.fst.checked",
"Steel.Memory.fsti.checked",
"prims.fst.checked",
"FStar.PropositionalExtensionality.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Effect.Common.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "FExt"
},
{
"abbrev": false,
"full_module": "Steel.Semantics.Instantiate",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": true,
"full_module": "Steel.Semantics.Hoare.MST",
"short_module": "Sem"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "FExt"
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | p: Steel.Effect.Common.vprop -> q: Steel.Effect.Common.vprop -> r: Steel.Effect.Common.vprop
-> FStar.Pervasives.Lemma (requires Steel.Effect.Common.can_be_split p q)
(ensures
Steel.Effect.Common.can_be_split (Steel.Effect.Common.star p r)
(Steel.Effect.Common.star q r)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Steel.Effect.Common.vprop",
"FStar.Classical.forall_intro",
"Steel.Memory.mem",
"Prims.l_iff",
"Steel.Memory.interp",
"Steel.Memory.star",
"Steel.Effect.Common.hp_of",
"Prims.l_Exists",
"Prims.l_and",
"Steel.Memory.disjoint",
"Prims.eq2",
"Steel.Memory.join",
"Steel.Memory.interp_star",
"Prims.unit"
] | [] | false | false | true | false | false | let can_be_split_congr_l p q r =
| Classical.forall_intro (interp_star (hp_of p) (hp_of r));
Classical.forall_intro (interp_star (hp_of q) (hp_of r)) | false |
Steel.Effect.Common.fst | Steel.Effect.Common.can_be_split_congr_r | val can_be_split_congr_r
(p q r: vprop)
: Lemma
(requires (p `can_be_split` q))
(ensures ((r `star` p) `can_be_split` (r `star` q))) | val can_be_split_congr_r
(p q r: vprop)
: Lemma
(requires (p `can_be_split` q))
(ensures ((r `star` p) `can_be_split` (r `star` q))) | let can_be_split_congr_r p q r =
Classical.forall_intro (interp_star (hp_of r) (hp_of p));
Classical.forall_intro (interp_star (hp_of r) (hp_of q)) | {
"file_name": "lib/steel/Steel.Effect.Common.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 58,
"end_line": 42,
"start_col": 0,
"start_line": 40
} | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Effect.Common
module Sem = Steel.Semantics.Hoare.MST
module Mem = Steel.Memory
open Steel.Semantics.Instantiate
module FExt = FStar.FunctionalExtensionality
let h_exists #a f = VUnit ({hp = Mem.h_exists (fun x -> hp_of (f x)); t = unit; sel = fun _ -> ()})
let can_be_split (p q:vprop) : prop = Mem.slimp (hp_of p) (hp_of q)
let reveal_can_be_split () = ()
let can_be_split_interp r r' h = ()
let can_be_split_trans p q r = ()
let can_be_split_star_l p q = ()
let can_be_split_star_r p q = ()
let can_be_split_refl p = ()
let can_be_split_congr_l p q r =
Classical.forall_intro (interp_star (hp_of p) (hp_of r));
Classical.forall_intro (interp_star (hp_of q) (hp_of r)) | {
"checked_file": "/",
"dependencies": [
"Steel.Semantics.Instantiate.fsti.checked",
"Steel.Semantics.Hoare.MST.fst.checked",
"Steel.Memory.fsti.checked",
"prims.fst.checked",
"FStar.PropositionalExtensionality.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Effect.Common.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "FExt"
},
{
"abbrev": false,
"full_module": "Steel.Semantics.Instantiate",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": true,
"full_module": "Steel.Semantics.Hoare.MST",
"short_module": "Sem"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "FExt"
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | p: Steel.Effect.Common.vprop -> q: Steel.Effect.Common.vprop -> r: Steel.Effect.Common.vprop
-> FStar.Pervasives.Lemma (requires Steel.Effect.Common.can_be_split p q)
(ensures
Steel.Effect.Common.can_be_split (Steel.Effect.Common.star r p)
(Steel.Effect.Common.star r q)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Steel.Effect.Common.vprop",
"FStar.Classical.forall_intro",
"Steel.Memory.mem",
"Prims.l_iff",
"Steel.Memory.interp",
"Steel.Memory.star",
"Steel.Effect.Common.hp_of",
"Prims.l_Exists",
"Prims.l_and",
"Steel.Memory.disjoint",
"Prims.eq2",
"Steel.Memory.join",
"Steel.Memory.interp_star",
"Prims.unit"
] | [] | false | false | true | false | false | let can_be_split_congr_r p q r =
| Classical.forall_intro (interp_star (hp_of r) (hp_of p));
Classical.forall_intro (interp_star (hp_of r) (hp_of q)) | false |
Steel.Effect.Common.fst | Steel.Effect.Common.vdep_hp | val vdep_hp (v: vprop) (p: ( (t_of v) -> Tot vprop)) : Tot (slprop u#1) | val vdep_hp (v: vprop) (p: ( (t_of v) -> Tot vprop)) : Tot (slprop u#1) | let vdep_hp
v p
=
sdep (hp_of v) (vdep_hp_payload v p) | {
"file_name": "lib/steel/Steel.Effect.Common.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 38,
"end_line": 151,
"start_col": 0,
"start_line": 148
} | (*
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.Effect.Common
module Sem = Steel.Semantics.Hoare.MST
module Mem = Steel.Memory
open Steel.Semantics.Instantiate
module FExt = FStar.FunctionalExtensionality
let h_exists #a f = VUnit ({hp = Mem.h_exists (fun x -> hp_of (f x)); t = unit; sel = fun _ -> ()})
let can_be_split (p q:vprop) : prop = Mem.slimp (hp_of p) (hp_of q)
let reveal_can_be_split () = ()
let can_be_split_interp r r' h = ()
let can_be_split_trans p q r = ()
let can_be_split_star_l p q = ()
let can_be_split_star_r p q = ()
let can_be_split_refl p = ()
let can_be_split_congr_l p q r =
Classical.forall_intro (interp_star (hp_of p) (hp_of r));
Classical.forall_intro (interp_star (hp_of q) (hp_of r))
let can_be_split_congr_r p q r =
Classical.forall_intro (interp_star (hp_of r) (hp_of p));
Classical.forall_intro (interp_star (hp_of r) (hp_of q))
let equiv (p q:vprop) : prop = Mem.equiv (hp_of p) (hp_of q) /\ True
let reveal_equiv p q = ()
let valid_rmem (#frame:vprop) (h:rmem' frame) : prop =
forall (p p1 p2:vprop). can_be_split frame p /\ p == VStar p1 p2 ==>
(h p1, h p2) == h (VStar p1 p2)
let lemma_valid_mk_rmem (r:vprop) (h:hmem r) = ()
let reveal_mk_rmem (r:vprop) (h:hmem r) (r0:vprop{r `can_be_split` r0})
: Lemma ((mk_rmem r h) r0 == sel_of r0 h)
= FExt.feq_on_domain_g (unrestricted_mk_rmem r h)
let emp':vprop' =
{ hp = emp;
t = unit;
sel = fun _ -> ()}
let emp = VUnit emp'
let reveal_emp () = ()
let lemma_valid_focus_rmem #r h r0 =
Classical.forall_intro (Classical.move_requires (can_be_split_trans r r0))
let rec lemma_frame_refl' (frame:vprop) (h0:rmem frame) (h1:rmem frame)
: Lemma ((h0 frame == h1 frame) <==> frame_equalities' frame h0 h1)
= match frame with
| VUnit _ -> ()
| VStar p1 p2 ->
can_be_split_star_l p1 p2;
can_be_split_star_r p1 p2;
let h01 : rmem p1 = focus_rmem h0 p1 in
let h11 : rmem p1 = focus_rmem h1 p1 in
let h02 = focus_rmem h0 p2 in
let h12 = focus_rmem h1 p2 in
lemma_frame_refl' p1 h01 h11;
lemma_frame_refl' p2 h02 h12
let lemma_frame_equalities frame h0 h1 p =
let p1 : prop = h0 frame == h1 frame in
let p2 : prop = frame_equalities' frame h0 h1 in
lemma_frame_refl' frame h0 h1;
FStar.PropositionalExtensionality.apply p1 p2
let lemma_frame_emp h0 h1 p =
FStar.PropositionalExtensionality.apply True (h0 (VUnit emp') == h1 (VUnit emp'))
let elim_conjunction p1 p1' p2 p2' = ()
let can_be_split_dep_refl p = ()
let equiv_can_be_split p1 p2 = ()
let intro_can_be_split_frame p q frame = ()
let can_be_split_post_elim t1 t2 = ()
let equiv_forall_refl t = ()
let equiv_forall_elim t1 t2 = ()
let equiv_refl x = ()
let equiv_sym x y = ()
let equiv_trans x y z = ()
let cm_identity x =
Mem.emp_unit (hp_of x);
Mem.star_commutative (hp_of x) Mem.emp
let star_commutative p1 p2 = Mem.star_commutative (hp_of p1) (hp_of p2)
let star_associative p1 p2 p3 = Mem.star_associative (hp_of p1) (hp_of p2) (hp_of p3)
let star_congruence p1 p2 p3 p4 = Mem.star_congruence (hp_of p1) (hp_of p2) (hp_of p3) (hp_of p4)
let vrefine_am (v: vprop) (p: (t_of v -> Tot prop)) : Tot (a_mem_prop (hp_of v)) =
fun h -> p (sel_of v h)
let vrefine_hp
v p
= refine_slprop (hp_of v) (vrefine_am v p)
let interp_vrefine_hp
v p m
= ()
let vrefine_sel' (v: vprop) (p: (t_of v -> Tot prop)) : Tot (selector' (vrefine_t v p) (vrefine_hp v p))
=
fun (h: Mem.hmem (vrefine_hp v p)) ->
interp_refine_slprop (hp_of v) (vrefine_am v p) h;
sel_of v h
let vrefine_sel
v p
= assert (sel_depends_only_on (vrefine_sel' v p));
assert (sel_depends_only_on_core (vrefine_sel' v p));
vrefine_sel' v p
let vrefine_sel_eq
v p m
= ()
let vdep_hp_payload
(v: vprop)
(p: (t_of v -> Tot vprop))
(h: Mem.hmem (hp_of v))
: Tot slprop
= hp_of (p (sel_of v h)) | {
"checked_file": "/",
"dependencies": [
"Steel.Semantics.Instantiate.fsti.checked",
"Steel.Semantics.Hoare.MST.fst.checked",
"Steel.Memory.fsti.checked",
"prims.fst.checked",
"FStar.PropositionalExtensionality.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Effect.Common.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Algebra.CommMonoid.Equiv",
"short_module": "CE"
},
{
"abbrev": false,
"full_module": "FStar.Tactics.CanonCommMonoidSimple.Equiv",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "FExt"
},
{
"abbrev": false,
"full_module": "Steel.Semantics.Instantiate",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": true,
"full_module": "Steel.Semantics.Hoare.MST",
"short_module": "Sem"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "FExt"
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | v: Steel.Effect.Common.vprop -> p: (_: Steel.Effect.Common.t_of v -> Steel.Effect.Common.vprop)
-> Steel.Memory.slprop | Prims.Tot | [
"total"
] | [] | [
"Steel.Effect.Common.vprop",
"Steel.Effect.Common.t_of",
"Steel.Memory.sdep",
"Steel.Effect.Common.hp_of",
"Steel.Effect.Common.vdep_hp_payload",
"Steel.Memory.slprop"
] | [] | false | false | false | false | false | let vdep_hp v p =
| sdep (hp_of v) (vdep_hp_payload v p) | false |
Steel.Effect.Common.fst | Steel.Effect.Common.emp' | val emp':vprop' | val emp':vprop' | let emp':vprop' =
{ hp = emp;
t = unit;
sel = fun _ -> ()} | {
"file_name": "lib/steel/Steel.Effect.Common.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 22,
"end_line": 60,
"start_col": 0,
"start_line": 57
} | (*
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.Effect.Common
module Sem = Steel.Semantics.Hoare.MST
module Mem = Steel.Memory
open Steel.Semantics.Instantiate
module FExt = FStar.FunctionalExtensionality
let h_exists #a f = VUnit ({hp = Mem.h_exists (fun x -> hp_of (f x)); t = unit; sel = fun _ -> ()})
let can_be_split (p q:vprop) : prop = Mem.slimp (hp_of p) (hp_of q)
let reveal_can_be_split () = ()
let can_be_split_interp r r' h = ()
let can_be_split_trans p q r = ()
let can_be_split_star_l p q = ()
let can_be_split_star_r p q = ()
let can_be_split_refl p = ()
let can_be_split_congr_l p q r =
Classical.forall_intro (interp_star (hp_of p) (hp_of r));
Classical.forall_intro (interp_star (hp_of q) (hp_of r))
let can_be_split_congr_r p q r =
Classical.forall_intro (interp_star (hp_of r) (hp_of p));
Classical.forall_intro (interp_star (hp_of r) (hp_of q))
let equiv (p q:vprop) : prop = Mem.equiv (hp_of p) (hp_of q) /\ True
let reveal_equiv p q = ()
let valid_rmem (#frame:vprop) (h:rmem' frame) : prop =
forall (p p1 p2:vprop). can_be_split frame p /\ p == VStar p1 p2 ==>
(h p1, h p2) == h (VStar p1 p2)
let lemma_valid_mk_rmem (r:vprop) (h:hmem r) = ()
let reveal_mk_rmem (r:vprop) (h:hmem r) (r0:vprop{r `can_be_split` r0})
: Lemma ((mk_rmem r h) r0 == sel_of r0 h)
= FExt.feq_on_domain_g (unrestricted_mk_rmem r h) | {
"checked_file": "/",
"dependencies": [
"Steel.Semantics.Instantiate.fsti.checked",
"Steel.Semantics.Hoare.MST.fst.checked",
"Steel.Memory.fsti.checked",
"prims.fst.checked",
"FStar.PropositionalExtensionality.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Effect.Common.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "FExt"
},
{
"abbrev": false,
"full_module": "Steel.Semantics.Instantiate",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": true,
"full_module": "Steel.Semantics.Hoare.MST",
"short_module": "Sem"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "FExt"
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Steel.Effect.Common.vprop' | Prims.Tot | [
"total"
] | [] | [
"Steel.Effect.Common.Mkvprop'",
"Steel.Memory.emp",
"Prims.unit",
"Steel.Memory.hmem"
] | [] | false | false | false | true | false | let emp':vprop' =
| { hp = emp; t = unit; sel = fun _ -> () } | false |
Steel.Effect.Common.fst | Steel.Effect.Common.reveal_mk_rmem | val reveal_mk_rmem (r:vprop) (h:hmem r) (r0:vprop{r `can_be_split` r0})
: Lemma (ensures reveal_can_be_split(); (mk_rmem r h) r0 == sel_of r0 h) | val reveal_mk_rmem (r:vprop) (h:hmem r) (r0:vprop{r `can_be_split` r0})
: Lemma (ensures reveal_can_be_split(); (mk_rmem r h) r0 == sel_of r0 h) | let reveal_mk_rmem (r:vprop) (h:hmem r) (r0:vprop{r `can_be_split` r0})
: Lemma ((mk_rmem r h) r0 == sel_of r0 h)
= FExt.feq_on_domain_g (unrestricted_mk_rmem r h) | {
"file_name": "lib/steel/Steel.Effect.Common.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 51,
"end_line": 55,
"start_col": 0,
"start_line": 53
} | (*
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.Effect.Common
module Sem = Steel.Semantics.Hoare.MST
module Mem = Steel.Memory
open Steel.Semantics.Instantiate
module FExt = FStar.FunctionalExtensionality
let h_exists #a f = VUnit ({hp = Mem.h_exists (fun x -> hp_of (f x)); t = unit; sel = fun _ -> ()})
let can_be_split (p q:vprop) : prop = Mem.slimp (hp_of p) (hp_of q)
let reveal_can_be_split () = ()
let can_be_split_interp r r' h = ()
let can_be_split_trans p q r = ()
let can_be_split_star_l p q = ()
let can_be_split_star_r p q = ()
let can_be_split_refl p = ()
let can_be_split_congr_l p q r =
Classical.forall_intro (interp_star (hp_of p) (hp_of r));
Classical.forall_intro (interp_star (hp_of q) (hp_of r))
let can_be_split_congr_r p q r =
Classical.forall_intro (interp_star (hp_of r) (hp_of p));
Classical.forall_intro (interp_star (hp_of r) (hp_of q))
let equiv (p q:vprop) : prop = Mem.equiv (hp_of p) (hp_of q) /\ True
let reveal_equiv p q = ()
let valid_rmem (#frame:vprop) (h:rmem' frame) : prop =
forall (p p1 p2:vprop). can_be_split frame p /\ p == VStar p1 p2 ==>
(h p1, h p2) == h (VStar p1 p2)
let lemma_valid_mk_rmem (r:vprop) (h:hmem r) = () | {
"checked_file": "/",
"dependencies": [
"Steel.Semantics.Instantiate.fsti.checked",
"Steel.Semantics.Hoare.MST.fst.checked",
"Steel.Memory.fsti.checked",
"prims.fst.checked",
"FStar.PropositionalExtensionality.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Effect.Common.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "FExt"
},
{
"abbrev": false,
"full_module": "Steel.Semantics.Instantiate",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": true,
"full_module": "Steel.Semantics.Hoare.MST",
"short_module": "Sem"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "FExt"
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
r: Steel.Effect.Common.vprop ->
h: Steel.Effect.Common.hmem r ->
r0: Steel.Effect.Common.vprop{Steel.Effect.Common.can_be_split r r0}
-> FStar.Pervasives.Lemma
(ensures
(Steel.Effect.Common.reveal_can_be_split ();
Steel.Effect.Common.mk_rmem r h r0 == Steel.Effect.Common.sel_of r0 h)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Steel.Effect.Common.vprop",
"Steel.Effect.Common.hmem",
"Steel.Effect.Common.can_be_split",
"FStar.FunctionalExtensionality.feq_on_domain_g",
"Steel.Effect.Common.t_of",
"Steel.Effect.Common.unrestricted_mk_rmem",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Prims.eq2",
"Steel.Effect.Common.normal",
"Steel.Effect.Common.mk_rmem",
"Steel.Effect.Common.sel_of",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let reveal_mk_rmem (r: vprop) (h: hmem r) (r0: vprop{r `can_be_split` r0})
: Lemma ((mk_rmem r h) r0 == sel_of r0 h) =
| FExt.feq_on_domain_g (unrestricted_mk_rmem r h) | false |
Steel.Effect.Common.fst | Steel.Effect.Common.lemma_valid_focus_rmem | val lemma_valid_focus_rmem (#r:vprop) (h:rmem r) (r0:vprop{r `can_be_split` r0})
: Lemma (valid_rmem (focus_rmem' h r0)) | val lemma_valid_focus_rmem (#r:vprop) (h:rmem r) (r0:vprop{r `can_be_split` r0})
: Lemma (valid_rmem (focus_rmem' h r0)) | let lemma_valid_focus_rmem #r h r0 =
Classical.forall_intro (Classical.move_requires (can_be_split_trans r r0)) | {
"file_name": "lib/steel/Steel.Effect.Common.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 76,
"end_line": 66,
"start_col": 0,
"start_line": 65
} | (*
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.Effect.Common
module Sem = Steel.Semantics.Hoare.MST
module Mem = Steel.Memory
open Steel.Semantics.Instantiate
module FExt = FStar.FunctionalExtensionality
let h_exists #a f = VUnit ({hp = Mem.h_exists (fun x -> hp_of (f x)); t = unit; sel = fun _ -> ()})
let can_be_split (p q:vprop) : prop = Mem.slimp (hp_of p) (hp_of q)
let reveal_can_be_split () = ()
let can_be_split_interp r r' h = ()
let can_be_split_trans p q r = ()
let can_be_split_star_l p q = ()
let can_be_split_star_r p q = ()
let can_be_split_refl p = ()
let can_be_split_congr_l p q r =
Classical.forall_intro (interp_star (hp_of p) (hp_of r));
Classical.forall_intro (interp_star (hp_of q) (hp_of r))
let can_be_split_congr_r p q r =
Classical.forall_intro (interp_star (hp_of r) (hp_of p));
Classical.forall_intro (interp_star (hp_of r) (hp_of q))
let equiv (p q:vprop) : prop = Mem.equiv (hp_of p) (hp_of q) /\ True
let reveal_equiv p q = ()
let valid_rmem (#frame:vprop) (h:rmem' frame) : prop =
forall (p p1 p2:vprop). can_be_split frame p /\ p == VStar p1 p2 ==>
(h p1, h p2) == h (VStar p1 p2)
let lemma_valid_mk_rmem (r:vprop) (h:hmem r) = ()
let reveal_mk_rmem (r:vprop) (h:hmem r) (r0:vprop{r `can_be_split` r0})
: Lemma ((mk_rmem r h) r0 == sel_of r0 h)
= FExt.feq_on_domain_g (unrestricted_mk_rmem r h)
let emp':vprop' =
{ hp = emp;
t = unit;
sel = fun _ -> ()}
let emp = VUnit emp'
let reveal_emp () = () | {
"checked_file": "/",
"dependencies": [
"Steel.Semantics.Instantiate.fsti.checked",
"Steel.Semantics.Hoare.MST.fst.checked",
"Steel.Memory.fsti.checked",
"prims.fst.checked",
"FStar.PropositionalExtensionality.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Effect.Common.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "FExt"
},
{
"abbrev": false,
"full_module": "Steel.Semantics.Instantiate",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": true,
"full_module": "Steel.Semantics.Hoare.MST",
"short_module": "Sem"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "FExt"
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
h: Steel.Effect.Common.rmem r ->
r0: Steel.Effect.Common.vprop{Steel.Effect.Common.can_be_split r r0}
-> FStar.Pervasives.Lemma
(ensures Steel.Effect.Common.valid_rmem (Steel.Effect.Common.focus_rmem' h r0)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Steel.Effect.Common.vprop",
"Steel.Effect.Common.rmem",
"Steel.Effect.Common.can_be_split",
"FStar.Classical.forall_intro",
"Prims.l_imp",
"Prims.l_and",
"FStar.Classical.move_requires",
"Steel.Effect.Common.can_be_split_trans",
"Prims.unit"
] | [] | false | false | true | false | false | let lemma_valid_focus_rmem #r h r0 =
| Classical.forall_intro (Classical.move_requires (can_be_split_trans r r0)) | false |
Steel.Effect.Common.fst | Steel.Effect.Common.valid_rmem | val valid_rmem (#frame:vprop) (h:rmem' frame) : prop | val valid_rmem (#frame:vprop) (h:rmem' frame) : prop | let valid_rmem (#frame:vprop) (h:rmem' frame) : prop =
forall (p p1 p2:vprop). can_be_split frame p /\ p == VStar p1 p2 ==>
(h p1, h p2) == h (VStar p1 p2) | {
"file_name": "lib/steel/Steel.Effect.Common.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 36,
"end_line": 49,
"start_col": 0,
"start_line": 47
} | (*
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.Effect.Common
module Sem = Steel.Semantics.Hoare.MST
module Mem = Steel.Memory
open Steel.Semantics.Instantiate
module FExt = FStar.FunctionalExtensionality
let h_exists #a f = VUnit ({hp = Mem.h_exists (fun x -> hp_of (f x)); t = unit; sel = fun _ -> ()})
let can_be_split (p q:vprop) : prop = Mem.slimp (hp_of p) (hp_of q)
let reveal_can_be_split () = ()
let can_be_split_interp r r' h = ()
let can_be_split_trans p q r = ()
let can_be_split_star_l p q = ()
let can_be_split_star_r p q = ()
let can_be_split_refl p = ()
let can_be_split_congr_l p q r =
Classical.forall_intro (interp_star (hp_of p) (hp_of r));
Classical.forall_intro (interp_star (hp_of q) (hp_of r))
let can_be_split_congr_r p q r =
Classical.forall_intro (interp_star (hp_of r) (hp_of p));
Classical.forall_intro (interp_star (hp_of r) (hp_of q))
let equiv (p q:vprop) : prop = Mem.equiv (hp_of p) (hp_of q) /\ True
let reveal_equiv p q = () | {
"checked_file": "/",
"dependencies": [
"Steel.Semantics.Instantiate.fsti.checked",
"Steel.Semantics.Hoare.MST.fst.checked",
"Steel.Memory.fsti.checked",
"prims.fst.checked",
"FStar.PropositionalExtensionality.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Effect.Common.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "FExt"
},
{
"abbrev": false,
"full_module": "Steel.Semantics.Instantiate",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": true,
"full_module": "Steel.Semantics.Hoare.MST",
"short_module": "Sem"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "FExt"
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | h: Steel.Effect.Common.rmem' frame -> Prims.prop | Prims.Tot | [
"total"
] | [] | [
"Steel.Effect.Common.vprop",
"Steel.Effect.Common.rmem'",
"Prims.l_Forall",
"Prims.l_imp",
"Prims.l_and",
"Steel.Effect.Common.can_be_split",
"Prims.eq2",
"Steel.Effect.Common.VStar",
"FStar.Pervasives.Native.tuple2",
"Steel.Effect.Common.vprop'",
"Steel.Effect.Common.__proj__Mkvprop'__item__t",
"Steel.Effect.Common.t_of",
"FStar.Pervasives.Native.Mktuple2",
"Prims.prop"
] | [] | false | false | false | false | true | let valid_rmem (#frame: vprop) (h: rmem' frame) : prop =
| forall (p: vprop) (p1: vprop) (p2: vprop).
can_be_split frame p /\ p == VStar p1 p2 ==> (h p1, h p2) == h (VStar p1 p2) | false |
Steel.Effect.Common.fst | Steel.Effect.Common.star_associative | val star_associative (p1 p2 p3:vprop)
: Lemma (((p1 `star` p2) `star` p3)
`equiv`
(p1 `star` (p2 `star` p3))) | val star_associative (p1 p2 p3:vprop)
: Lemma (((p1 `star` p2) `star` p3)
`equiv`
(p1 `star` (p2 `star` p3))) | let star_associative p1 p2 p3 = Mem.star_associative (hp_of p1) (hp_of p2) (hp_of p3) | {
"file_name": "lib/steel/Steel.Effect.Common.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 85,
"end_line": 111,
"start_col": 0,
"start_line": 111
} | (*
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.Effect.Common
module Sem = Steel.Semantics.Hoare.MST
module Mem = Steel.Memory
open Steel.Semantics.Instantiate
module FExt = FStar.FunctionalExtensionality
let h_exists #a f = VUnit ({hp = Mem.h_exists (fun x -> hp_of (f x)); t = unit; sel = fun _ -> ()})
let can_be_split (p q:vprop) : prop = Mem.slimp (hp_of p) (hp_of q)
let reveal_can_be_split () = ()
let can_be_split_interp r r' h = ()
let can_be_split_trans p q r = ()
let can_be_split_star_l p q = ()
let can_be_split_star_r p q = ()
let can_be_split_refl p = ()
let can_be_split_congr_l p q r =
Classical.forall_intro (interp_star (hp_of p) (hp_of r));
Classical.forall_intro (interp_star (hp_of q) (hp_of r))
let can_be_split_congr_r p q r =
Classical.forall_intro (interp_star (hp_of r) (hp_of p));
Classical.forall_intro (interp_star (hp_of r) (hp_of q))
let equiv (p q:vprop) : prop = Mem.equiv (hp_of p) (hp_of q) /\ True
let reveal_equiv p q = ()
let valid_rmem (#frame:vprop) (h:rmem' frame) : prop =
forall (p p1 p2:vprop). can_be_split frame p /\ p == VStar p1 p2 ==>
(h p1, h p2) == h (VStar p1 p2)
let lemma_valid_mk_rmem (r:vprop) (h:hmem r) = ()
let reveal_mk_rmem (r:vprop) (h:hmem r) (r0:vprop{r `can_be_split` r0})
: Lemma ((mk_rmem r h) r0 == sel_of r0 h)
= FExt.feq_on_domain_g (unrestricted_mk_rmem r h)
let emp':vprop' =
{ hp = emp;
t = unit;
sel = fun _ -> ()}
let emp = VUnit emp'
let reveal_emp () = ()
let lemma_valid_focus_rmem #r h r0 =
Classical.forall_intro (Classical.move_requires (can_be_split_trans r r0))
let rec lemma_frame_refl' (frame:vprop) (h0:rmem frame) (h1:rmem frame)
: Lemma ((h0 frame == h1 frame) <==> frame_equalities' frame h0 h1)
= match frame with
| VUnit _ -> ()
| VStar p1 p2 ->
can_be_split_star_l p1 p2;
can_be_split_star_r p1 p2;
let h01 : rmem p1 = focus_rmem h0 p1 in
let h11 : rmem p1 = focus_rmem h1 p1 in
let h02 = focus_rmem h0 p2 in
let h12 = focus_rmem h1 p2 in
lemma_frame_refl' p1 h01 h11;
lemma_frame_refl' p2 h02 h12
let lemma_frame_equalities frame h0 h1 p =
let p1 : prop = h0 frame == h1 frame in
let p2 : prop = frame_equalities' frame h0 h1 in
lemma_frame_refl' frame h0 h1;
FStar.PropositionalExtensionality.apply p1 p2
let lemma_frame_emp h0 h1 p =
FStar.PropositionalExtensionality.apply True (h0 (VUnit emp') == h1 (VUnit emp'))
let elim_conjunction p1 p1' p2 p2' = ()
let can_be_split_dep_refl p = ()
let equiv_can_be_split p1 p2 = ()
let intro_can_be_split_frame p q frame = ()
let can_be_split_post_elim t1 t2 = ()
let equiv_forall_refl t = ()
let equiv_forall_elim t1 t2 = ()
let equiv_refl x = ()
let equiv_sym x y = ()
let equiv_trans x y z = ()
let cm_identity x =
Mem.emp_unit (hp_of x);
Mem.star_commutative (hp_of x) Mem.emp | {
"checked_file": "/",
"dependencies": [
"Steel.Semantics.Instantiate.fsti.checked",
"Steel.Semantics.Hoare.MST.fst.checked",
"Steel.Memory.fsti.checked",
"prims.fst.checked",
"FStar.PropositionalExtensionality.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Effect.Common.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Algebra.CommMonoid.Equiv",
"short_module": "CE"
},
{
"abbrev": false,
"full_module": "FStar.Tactics.CanonCommMonoidSimple.Equiv",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "FExt"
},
{
"abbrev": false,
"full_module": "Steel.Semantics.Instantiate",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": true,
"full_module": "Steel.Semantics.Hoare.MST",
"short_module": "Sem"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "FExt"
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | p1: Steel.Effect.Common.vprop -> p2: Steel.Effect.Common.vprop -> p3: Steel.Effect.Common.vprop
-> FStar.Pervasives.Lemma
(ensures
Steel.Effect.Common.equiv (Steel.Effect.Common.star (Steel.Effect.Common.star p1 p2) p3)
(Steel.Effect.Common.star p1 (Steel.Effect.Common.star p2 p3))) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Steel.Effect.Common.vprop",
"Steel.Memory.star_associative",
"Steel.Effect.Common.hp_of",
"Prims.unit"
] | [] | true | false | true | false | false | let star_associative p1 p2 p3 =
| Mem.star_associative (hp_of p1) (hp_of p2) (hp_of p3) | false |
Steel.Effect.Common.fst | Steel.Effect.Common.lemma_frame_emp | val lemma_frame_emp (h0:rmem emp) (h1:rmem emp) (p:Type0)
: Lemma (requires True == p)
(ensures frame_equalities' emp h0 h1 == p) | val lemma_frame_emp (h0:rmem emp) (h1:rmem emp) (p:Type0)
: Lemma (requires True == p)
(ensures frame_equalities' emp h0 h1 == p) | let lemma_frame_emp h0 h1 p =
FStar.PropositionalExtensionality.apply True (h0 (VUnit emp') == h1 (VUnit emp')) | {
"file_name": "lib/steel/Steel.Effect.Common.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 83,
"end_line": 92,
"start_col": 0,
"start_line": 91
} | (*
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.Effect.Common
module Sem = Steel.Semantics.Hoare.MST
module Mem = Steel.Memory
open Steel.Semantics.Instantiate
module FExt = FStar.FunctionalExtensionality
let h_exists #a f = VUnit ({hp = Mem.h_exists (fun x -> hp_of (f x)); t = unit; sel = fun _ -> ()})
let can_be_split (p q:vprop) : prop = Mem.slimp (hp_of p) (hp_of q)
let reveal_can_be_split () = ()
let can_be_split_interp r r' h = ()
let can_be_split_trans p q r = ()
let can_be_split_star_l p q = ()
let can_be_split_star_r p q = ()
let can_be_split_refl p = ()
let can_be_split_congr_l p q r =
Classical.forall_intro (interp_star (hp_of p) (hp_of r));
Classical.forall_intro (interp_star (hp_of q) (hp_of r))
let can_be_split_congr_r p q r =
Classical.forall_intro (interp_star (hp_of r) (hp_of p));
Classical.forall_intro (interp_star (hp_of r) (hp_of q))
let equiv (p q:vprop) : prop = Mem.equiv (hp_of p) (hp_of q) /\ True
let reveal_equiv p q = ()
let valid_rmem (#frame:vprop) (h:rmem' frame) : prop =
forall (p p1 p2:vprop). can_be_split frame p /\ p == VStar p1 p2 ==>
(h p1, h p2) == h (VStar p1 p2)
let lemma_valid_mk_rmem (r:vprop) (h:hmem r) = ()
let reveal_mk_rmem (r:vprop) (h:hmem r) (r0:vprop{r `can_be_split` r0})
: Lemma ((mk_rmem r h) r0 == sel_of r0 h)
= FExt.feq_on_domain_g (unrestricted_mk_rmem r h)
let emp':vprop' =
{ hp = emp;
t = unit;
sel = fun _ -> ()}
let emp = VUnit emp'
let reveal_emp () = ()
let lemma_valid_focus_rmem #r h r0 =
Classical.forall_intro (Classical.move_requires (can_be_split_trans r r0))
let rec lemma_frame_refl' (frame:vprop) (h0:rmem frame) (h1:rmem frame)
: Lemma ((h0 frame == h1 frame) <==> frame_equalities' frame h0 h1)
= match frame with
| VUnit _ -> ()
| VStar p1 p2 ->
can_be_split_star_l p1 p2;
can_be_split_star_r p1 p2;
let h01 : rmem p1 = focus_rmem h0 p1 in
let h11 : rmem p1 = focus_rmem h1 p1 in
let h02 = focus_rmem h0 p2 in
let h12 = focus_rmem h1 p2 in
lemma_frame_refl' p1 h01 h11;
lemma_frame_refl' p2 h02 h12
let lemma_frame_equalities frame h0 h1 p =
let p1 : prop = h0 frame == h1 frame in
let p2 : prop = frame_equalities' frame h0 h1 in
lemma_frame_refl' frame h0 h1;
FStar.PropositionalExtensionality.apply p1 p2 | {
"checked_file": "/",
"dependencies": [
"Steel.Semantics.Instantiate.fsti.checked",
"Steel.Semantics.Hoare.MST.fst.checked",
"Steel.Memory.fsti.checked",
"prims.fst.checked",
"FStar.PropositionalExtensionality.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Effect.Common.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "FExt"
},
{
"abbrev": false,
"full_module": "Steel.Semantics.Instantiate",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": true,
"full_module": "Steel.Semantics.Hoare.MST",
"short_module": "Sem"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "FExt"
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
h0: Steel.Effect.Common.rmem Steel.Effect.Common.emp ->
h1: Steel.Effect.Common.rmem Steel.Effect.Common.emp ->
p: Type0
-> FStar.Pervasives.Lemma (requires Prims.l_True == p)
(ensures Steel.Effect.Common.frame_equalities' Steel.Effect.Common.emp h0 h1 == p) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Steel.Effect.Common.rmem",
"Steel.Effect.Common.emp",
"FStar.PropositionalExtensionality.apply",
"Prims.l_True",
"Prims.eq2",
"Steel.Effect.Common.normal",
"Steel.Effect.Common.t_of",
"Steel.Effect.Common.VUnit",
"Steel.Effect.Common.emp'",
"Prims.unit"
] | [] | true | false | true | false | false | let lemma_frame_emp h0 h1 p =
| FStar.PropositionalExtensionality.apply True (h0 (VUnit emp') == h1 (VUnit emp')) | false |
Steel.Effect.Common.fst | Steel.Effect.Common.lemma_frame_refl' | val lemma_frame_refl' (frame: vprop) (h0 h1: rmem frame)
: Lemma ((h0 frame == h1 frame) <==> frame_equalities' frame h0 h1) | val lemma_frame_refl' (frame: vprop) (h0 h1: rmem frame)
: Lemma ((h0 frame == h1 frame) <==> frame_equalities' frame h0 h1) | let rec lemma_frame_refl' (frame:vprop) (h0:rmem frame) (h1:rmem frame)
: Lemma ((h0 frame == h1 frame) <==> frame_equalities' frame h0 h1)
= match frame with
| VUnit _ -> ()
| VStar p1 p2 ->
can_be_split_star_l p1 p2;
can_be_split_star_r p1 p2;
let h01 : rmem p1 = focus_rmem h0 p1 in
let h11 : rmem p1 = focus_rmem h1 p1 in
let h02 = focus_rmem h0 p2 in
let h12 = focus_rmem h1 p2 in
lemma_frame_refl' p1 h01 h11;
lemma_frame_refl' p2 h02 h12 | {
"file_name": "lib/steel/Steel.Effect.Common.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 34,
"end_line": 83,
"start_col": 0,
"start_line": 68
} | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Effect.Common
module Sem = Steel.Semantics.Hoare.MST
module Mem = Steel.Memory
open Steel.Semantics.Instantiate
module FExt = FStar.FunctionalExtensionality
let h_exists #a f = VUnit ({hp = Mem.h_exists (fun x -> hp_of (f x)); t = unit; sel = fun _ -> ()})
let can_be_split (p q:vprop) : prop = Mem.slimp (hp_of p) (hp_of q)
let reveal_can_be_split () = ()
let can_be_split_interp r r' h = ()
let can_be_split_trans p q r = ()
let can_be_split_star_l p q = ()
let can_be_split_star_r p q = ()
let can_be_split_refl p = ()
let can_be_split_congr_l p q r =
Classical.forall_intro (interp_star (hp_of p) (hp_of r));
Classical.forall_intro (interp_star (hp_of q) (hp_of r))
let can_be_split_congr_r p q r =
Classical.forall_intro (interp_star (hp_of r) (hp_of p));
Classical.forall_intro (interp_star (hp_of r) (hp_of q))
let equiv (p q:vprop) : prop = Mem.equiv (hp_of p) (hp_of q) /\ True
let reveal_equiv p q = ()
let valid_rmem (#frame:vprop) (h:rmem' frame) : prop =
forall (p p1 p2:vprop). can_be_split frame p /\ p == VStar p1 p2 ==>
(h p1, h p2) == h (VStar p1 p2)
let lemma_valid_mk_rmem (r:vprop) (h:hmem r) = ()
let reveal_mk_rmem (r:vprop) (h:hmem r) (r0:vprop{r `can_be_split` r0})
: Lemma ((mk_rmem r h) r0 == sel_of r0 h)
= FExt.feq_on_domain_g (unrestricted_mk_rmem r h)
let emp':vprop' =
{ hp = emp;
t = unit;
sel = fun _ -> ()}
let emp = VUnit emp'
let reveal_emp () = ()
let lemma_valid_focus_rmem #r h r0 =
Classical.forall_intro (Classical.move_requires (can_be_split_trans r r0)) | {
"checked_file": "/",
"dependencies": [
"Steel.Semantics.Instantiate.fsti.checked",
"Steel.Semantics.Hoare.MST.fst.checked",
"Steel.Memory.fsti.checked",
"prims.fst.checked",
"FStar.PropositionalExtensionality.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Effect.Common.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "FExt"
},
{
"abbrev": false,
"full_module": "Steel.Semantics.Instantiate",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": true,
"full_module": "Steel.Semantics.Hoare.MST",
"short_module": "Sem"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "FExt"
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
frame: Steel.Effect.Common.vprop ->
h0: Steel.Effect.Common.rmem frame ->
h1: Steel.Effect.Common.rmem frame
-> FStar.Pervasives.Lemma
(ensures h0 frame == h1 frame <==> Steel.Effect.Common.frame_equalities' frame h0 h1) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Steel.Effect.Common.vprop",
"Steel.Effect.Common.rmem",
"Steel.Effect.Common.vprop'",
"Steel.Effect.Common.lemma_frame_refl'",
"Prims.unit",
"Steel.Effect.Common.rmem'",
"Steel.Effect.Common.valid_rmem",
"Steel.Effect.Common.focus_rmem",
"Steel.Effect.Common.can_be_split_star_r",
"Steel.Effect.Common.can_be_split_star_l",
"Prims.l_True",
"Prims.squash",
"Prims.l_iff",
"Prims.eq2",
"Steel.Effect.Common.normal",
"Steel.Effect.Common.t_of",
"Steel.Effect.Common.frame_equalities'",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [
"recursion"
] | false | false | true | false | false | let rec lemma_frame_refl' (frame: vprop) (h0 h1: rmem frame)
: Lemma ((h0 frame == h1 frame) <==> frame_equalities' frame h0 h1) =
| match frame with
| VUnit _ -> ()
| VStar p1 p2 ->
can_be_split_star_l p1 p2;
can_be_split_star_r p1 p2;
let h01:rmem p1 = focus_rmem h0 p1 in
let h11:rmem p1 = focus_rmem h1 p1 in
let h02 = focus_rmem h0 p2 in
let h12 = focus_rmem h1 p2 in
lemma_frame_refl' p1 h01 h11;
lemma_frame_refl' p2 h02 h12 | false |
Steel.Effect.Common.fst | Steel.Effect.Common.lemma_frame_equalities | val lemma_frame_equalities (frame:vprop) (h0:rmem frame) (h1:rmem frame) (p:Type0)
: Lemma
(requires (h0 frame == h1 frame) == p)
(ensures frame_equalities' frame h0 h1 == p) | val lemma_frame_equalities (frame:vprop) (h0:rmem frame) (h1:rmem frame) (p:Type0)
: Lemma
(requires (h0 frame == h1 frame) == p)
(ensures frame_equalities' frame h0 h1 == p) | let lemma_frame_equalities frame h0 h1 p =
let p1 : prop = h0 frame == h1 frame in
let p2 : prop = frame_equalities' frame h0 h1 in
lemma_frame_refl' frame h0 h1;
FStar.PropositionalExtensionality.apply p1 p2 | {
"file_name": "lib/steel/Steel.Effect.Common.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 47,
"end_line": 89,
"start_col": 0,
"start_line": 85
} | (*
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.Effect.Common
module Sem = Steel.Semantics.Hoare.MST
module Mem = Steel.Memory
open Steel.Semantics.Instantiate
module FExt = FStar.FunctionalExtensionality
let h_exists #a f = VUnit ({hp = Mem.h_exists (fun x -> hp_of (f x)); t = unit; sel = fun _ -> ()})
let can_be_split (p q:vprop) : prop = Mem.slimp (hp_of p) (hp_of q)
let reveal_can_be_split () = ()
let can_be_split_interp r r' h = ()
let can_be_split_trans p q r = ()
let can_be_split_star_l p q = ()
let can_be_split_star_r p q = ()
let can_be_split_refl p = ()
let can_be_split_congr_l p q r =
Classical.forall_intro (interp_star (hp_of p) (hp_of r));
Classical.forall_intro (interp_star (hp_of q) (hp_of r))
let can_be_split_congr_r p q r =
Classical.forall_intro (interp_star (hp_of r) (hp_of p));
Classical.forall_intro (interp_star (hp_of r) (hp_of q))
let equiv (p q:vprop) : prop = Mem.equiv (hp_of p) (hp_of q) /\ True
let reveal_equiv p q = ()
let valid_rmem (#frame:vprop) (h:rmem' frame) : prop =
forall (p p1 p2:vprop). can_be_split frame p /\ p == VStar p1 p2 ==>
(h p1, h p2) == h (VStar p1 p2)
let lemma_valid_mk_rmem (r:vprop) (h:hmem r) = ()
let reveal_mk_rmem (r:vprop) (h:hmem r) (r0:vprop{r `can_be_split` r0})
: Lemma ((mk_rmem r h) r0 == sel_of r0 h)
= FExt.feq_on_domain_g (unrestricted_mk_rmem r h)
let emp':vprop' =
{ hp = emp;
t = unit;
sel = fun _ -> ()}
let emp = VUnit emp'
let reveal_emp () = ()
let lemma_valid_focus_rmem #r h r0 =
Classical.forall_intro (Classical.move_requires (can_be_split_trans r r0))
let rec lemma_frame_refl' (frame:vprop) (h0:rmem frame) (h1:rmem frame)
: Lemma ((h0 frame == h1 frame) <==> frame_equalities' frame h0 h1)
= match frame with
| VUnit _ -> ()
| VStar p1 p2 ->
can_be_split_star_l p1 p2;
can_be_split_star_r p1 p2;
let h01 : rmem p1 = focus_rmem h0 p1 in
let h11 : rmem p1 = focus_rmem h1 p1 in
let h02 = focus_rmem h0 p2 in
let h12 = focus_rmem h1 p2 in
lemma_frame_refl' p1 h01 h11;
lemma_frame_refl' p2 h02 h12 | {
"checked_file": "/",
"dependencies": [
"Steel.Semantics.Instantiate.fsti.checked",
"Steel.Semantics.Hoare.MST.fst.checked",
"Steel.Memory.fsti.checked",
"prims.fst.checked",
"FStar.PropositionalExtensionality.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Effect.Common.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "FExt"
},
{
"abbrev": false,
"full_module": "Steel.Semantics.Instantiate",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": true,
"full_module": "Steel.Semantics.Hoare.MST",
"short_module": "Sem"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "FExt"
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
frame: Steel.Effect.Common.vprop ->
h0: Steel.Effect.Common.rmem frame ->
h1: Steel.Effect.Common.rmem frame ->
p: Type0
-> FStar.Pervasives.Lemma (requires h0 frame == h1 frame == p)
(ensures Steel.Effect.Common.frame_equalities' frame h0 h1 == p) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Steel.Effect.Common.vprop",
"Steel.Effect.Common.rmem",
"FStar.PropositionalExtensionality.apply",
"Prims.unit",
"Steel.Effect.Common.lemma_frame_refl'",
"Prims.prop",
"Steel.Effect.Common.frame_equalities'",
"Prims.eq2",
"Steel.Effect.Common.normal",
"Steel.Effect.Common.t_of"
] | [] | true | false | true | false | false | let lemma_frame_equalities frame h0 h1 p =
| let p1:prop = h0 frame == h1 frame in
let p2:prop = frame_equalities' frame h0 h1 in
lemma_frame_refl' frame h0 h1;
FStar.PropositionalExtensionality.apply p1 p2 | false |
Steel.Effect.Common.fst | Steel.Effect.Common.star_commutative | val star_commutative (p1 p2:vprop)
: Lemma ((p1 `star` p2) `equiv` (p2 `star` p1)) | val star_commutative (p1 p2:vprop)
: Lemma ((p1 `star` p2) `equiv` (p2 `star` p1)) | let star_commutative p1 p2 = Mem.star_commutative (hp_of p1) (hp_of p2) | {
"file_name": "lib/steel/Steel.Effect.Common.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 71,
"end_line": 110,
"start_col": 0,
"start_line": 110
} | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Effect.Common
module Sem = Steel.Semantics.Hoare.MST
module Mem = Steel.Memory
open Steel.Semantics.Instantiate
module FExt = FStar.FunctionalExtensionality
let h_exists #a f = VUnit ({hp = Mem.h_exists (fun x -> hp_of (f x)); t = unit; sel = fun _ -> ()})
let can_be_split (p q:vprop) : prop = Mem.slimp (hp_of p) (hp_of q)
let reveal_can_be_split () = ()
let can_be_split_interp r r' h = ()
let can_be_split_trans p q r = ()
let can_be_split_star_l p q = ()
let can_be_split_star_r p q = ()
let can_be_split_refl p = ()
let can_be_split_congr_l p q r =
Classical.forall_intro (interp_star (hp_of p) (hp_of r));
Classical.forall_intro (interp_star (hp_of q) (hp_of r))
let can_be_split_congr_r p q r =
Classical.forall_intro (interp_star (hp_of r) (hp_of p));
Classical.forall_intro (interp_star (hp_of r) (hp_of q))
let equiv (p q:vprop) : prop = Mem.equiv (hp_of p) (hp_of q) /\ True
let reveal_equiv p q = ()
let valid_rmem (#frame:vprop) (h:rmem' frame) : prop =
forall (p p1 p2:vprop). can_be_split frame p /\ p == VStar p1 p2 ==>
(h p1, h p2) == h (VStar p1 p2)
let lemma_valid_mk_rmem (r:vprop) (h:hmem r) = ()
let reveal_mk_rmem (r:vprop) (h:hmem r) (r0:vprop{r `can_be_split` r0})
: Lemma ((mk_rmem r h) r0 == sel_of r0 h)
= FExt.feq_on_domain_g (unrestricted_mk_rmem r h)
let emp':vprop' =
{ hp = emp;
t = unit;
sel = fun _ -> ()}
let emp = VUnit emp'
let reveal_emp () = ()
let lemma_valid_focus_rmem #r h r0 =
Classical.forall_intro (Classical.move_requires (can_be_split_trans r r0))
let rec lemma_frame_refl' (frame:vprop) (h0:rmem frame) (h1:rmem frame)
: Lemma ((h0 frame == h1 frame) <==> frame_equalities' frame h0 h1)
= match frame with
| VUnit _ -> ()
| VStar p1 p2 ->
can_be_split_star_l p1 p2;
can_be_split_star_r p1 p2;
let h01 : rmem p1 = focus_rmem h0 p1 in
let h11 : rmem p1 = focus_rmem h1 p1 in
let h02 = focus_rmem h0 p2 in
let h12 = focus_rmem h1 p2 in
lemma_frame_refl' p1 h01 h11;
lemma_frame_refl' p2 h02 h12
let lemma_frame_equalities frame h0 h1 p =
let p1 : prop = h0 frame == h1 frame in
let p2 : prop = frame_equalities' frame h0 h1 in
lemma_frame_refl' frame h0 h1;
FStar.PropositionalExtensionality.apply p1 p2
let lemma_frame_emp h0 h1 p =
FStar.PropositionalExtensionality.apply True (h0 (VUnit emp') == h1 (VUnit emp'))
let elim_conjunction p1 p1' p2 p2' = ()
let can_be_split_dep_refl p = ()
let equiv_can_be_split p1 p2 = ()
let intro_can_be_split_frame p q frame = ()
let can_be_split_post_elim t1 t2 = ()
let equiv_forall_refl t = ()
let equiv_forall_elim t1 t2 = ()
let equiv_refl x = ()
let equiv_sym x y = ()
let equiv_trans x y z = ()
let cm_identity x =
Mem.emp_unit (hp_of x); | {
"checked_file": "/",
"dependencies": [
"Steel.Semantics.Instantiate.fsti.checked",
"Steel.Semantics.Hoare.MST.fst.checked",
"Steel.Memory.fsti.checked",
"prims.fst.checked",
"FStar.PropositionalExtensionality.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Effect.Common.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Algebra.CommMonoid.Equiv",
"short_module": "CE"
},
{
"abbrev": false,
"full_module": "FStar.Tactics.CanonCommMonoidSimple.Equiv",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "FExt"
},
{
"abbrev": false,
"full_module": "Steel.Semantics.Instantiate",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": true,
"full_module": "Steel.Semantics.Hoare.MST",
"short_module": "Sem"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "FExt"
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | p1: Steel.Effect.Common.vprop -> p2: Steel.Effect.Common.vprop
-> FStar.Pervasives.Lemma
(ensures
Steel.Effect.Common.equiv (Steel.Effect.Common.star p1 p2) (Steel.Effect.Common.star p2 p1)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Steel.Effect.Common.vprop",
"Steel.Memory.star_commutative",
"Steel.Effect.Common.hp_of",
"Prims.unit"
] | [] | true | false | true | false | false | let star_commutative p1 p2 =
| Mem.star_commutative (hp_of p1) (hp_of p2) | false |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.